# @edlink/typescript 中文文档

规范地址：https://npmcn.com/package/%40edlink/typescript/

版本：2\.0\.6
npm 元数据更新时间：2026-11-03T20:27:06.453Z
中文译文更新时间：2026-11-13T07:09:24.850Z
软件包许可：Unlicense

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40edlink/typescript
原文对照：https://npmcn.com/package/%40edlink/typescript/?lang=original
项目主页：https://github.com/edlink/edlink-node-sdk#readme
源码仓库：https://github.com/edlink/edlink-node-sdk

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：322 kB，92 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=10
- 运行依赖：0 个
- 首次发布：2022-09-22T23:51:44.789Z
- 最新版本发布：2026-11-03T20:27:06.281Z
- 近 30 天下载量：73285（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：23（近 12 个月 3 个）

## 中文简介

这个Edlink JavaScript & TypeScript SDK是Edlink API的节点JS包装器.

## 安装

```sh
npm install @edlink/typescript
```

也可以使用：`pnpm add @edlink/typescript`、`yarn add @edlink/typescript`、`bun add @edlink/typescript`

## README

# 埃德林克节点 SDK [![CI](https://github.com/edlink/edlink-node-sdk/actions/workflows/analyze.yml/badge.svg)](https://github.com/edlink/edlink-node-sdk/actions/workflows/analyze.yml)

这个Edlink JavaScript & TypeScript SDK是Edlink API的节点JS包装器.

> 你可以找到关于 [编辑 SDK 文档](https://ed.link/docs/api/v2.0/sdk/typescript/get-started)。 。 。 .

# 开始

## 安装

安装 `@edlink/typescript` 使用软件包 `npm` 或者说 `yarn`。 。 。 .

```
yarn add @edlink/typescript
```

```typescript
// Initialize with your Edlink application
// Your credentials can be found on the Edlink Dashboard
import { Edlink } from '@edlink/typescript';

const edlink = new Edlink({
    version: 2,
    client_id: '3a95a779-0ed1-499b-a352-9ea30d0bd5ea',
    client_secret: '[...]'
});

Edlink.up().then(console.log); // Ok
```

## 授权

```typescript
// TokenSets are required to access protected resources
// Integration tokens do not expire and therefore dont have a `refresh_token`
// However be sure to store the the `refresh_token` for person token sets
// You are required to provide both when making requests on behalf of a person

export type TokenSet {
    access_token: string;
    refresh_token?: string;
    expires_in?: number;
    type: TokenSetType;
}

export enum TokenSetType = {
    Integration = 'integration',
    Person = 'person'
}
```

## 图表 API

```typescript
// Graph requests are even easier, just build a TokenSet from the values
// in the Edlink Dashboard

const integration_token_set = {
    access_token: '[...]'
};

const district = await edlink.use(integration_token_set).districts.fetch('3a95a779-0ed1-499b-a352-9ea30d0bd5ea');

for await (const district of edlink.use(integration_token_set).districts.list()) {
    console.log(district);
}
```

## 用户认证

```typescript
// Authenticate a user
// First build your login url to provide to the user.
// This URL doesnt change and can be hardcoded if desired
/**
 * https://ed.link/sso/login
 * ?client_id=[...]
 * &redirect_uri=[...]
 * &state=[...]
 * &response_type=code
 */
// Optionally you may provide a state parameter for Endlink to
// passback to you upon authentication of the user

edlink.loginUrl({ redirect_uri: 'https://oauthdebugger.com/debug' });
```

```typescript
// When the user returns to your site you will be provided with a code
// e.g. https://oauthdebugger.com/debug?code=[...]
// Provide this code with the matching `redirect_uri` to recieve a token set

// Store this entire object securely
// You will require more than just the access_token
const person_token_set = await edlink.auth.grant({
    code: '[...]'.
    redirect_uri: 'https://oauthdebugger.com/debug'
});

// You can now make requests on behalf of this user
const profile = await edlink.use(person_token_set).my.profile();
```

## 常见问题

### @edlink/typescript 是什么？

这个Edlink JavaScript & TypeScript SDK是Edlink API的节点JS包装器\.

### 如何安装 @edlink/typescript？

在项目目录运行 npm install @edlink/typescript，或使用 pnpm add / yarn add / bun add。

### @edlink/typescript 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @edlink/typescript 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @edlink/typescript 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=10。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @edlink/typescript 可以商用吗？

@edlink/typescript 使用 Unlicense 许可。作者将代码贡献到公共领域，可不受限制地使用。以上为概括，不构成法律意见，请以许可原文为准。

### @edlink/typescript 的下载量有多少？

根据 npm 官方下载统计，@edlink/typescript 在 2026/10/13 – 2026/11/11 这 30 天内被下载 73,285 次，日均约 2,443 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @edlink/typescript 还在维护吗？

最新版本 2\.0\.6 发布于 2026/11/04（9 天前）；至今共发布 23 个版本，其中过去 12 个月发布了 3 个；首次发布于 2022/09/23。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

