@descope/core-js-sdk

中文文档
2.78.0发布于 2026/11/08MITTypeScriptESM + CJS近 30 天下载 338.3万

Descope JavaScript core SDK

原始使用文档
文档目录8 节
  1. Usage
  2. Install the package
  3. Use it
  4. Enchanted Link over SMS
  5. Outbound Connect
  6. Basic Usage
  7. Using External Identifier
  8. Tenant-Specific Connections

@descope/core-js-sdk

Descope JavaScript core SDK

Usage

Install the package

npm install @descope/core-js-sdk

Use it

import createSdk from '@descope/core-js-sdk';

const projectId = '<project-id>';

const sdk = createSdk({ projectId });

const loginId = 'loginId';

sdk.otp.signIn.email(loginId);

The enchanted link can be delivered by SMS instead of email, using signInWithPhone, signUpWithPhone, signUpOrInWithPhone and update.phone.sms. The login ID is a phone number, and the response is a PhoneEnchantedLinkResponse, which carries maskedPhone instead of maskedEmail. Unlike the email message, the text message contains only the correct link, so the user has nothing to choose. Polling with waitForSession and verification are unchanged.

const { data } = await sdk.enchantedLink.signUpOrInWithPhone(
  '+11234567890',
  'https://myapp.com/verify-enchanted-link',
);
const jwt = await sdk.enchantedLink.waitForSession(data.pendingRef);

Outbound Connect

Connect to outbound applications (e.g., Google, Microsoft) to access user data from external services.

Basic Usage

// Connect to an outbound application
const response = await sdk.outbound.connect('app-id', {
  redirectUrl: 'https://your-app.com/callback',
  scopes: ['email', 'profile'],
});

// Redirect user to the returned URL
window.location.href = response.data.url;

Using External Identifier

You can pass an external identifier to map the outbound connection to an external user:

const response = await sdk.outbound.connect('app-id', {
  redirectUrl: 'https://your-app.com/callback',
  scopes: ['email', 'profile'],
  externalIdentifier: 'external-user-id-123',
});

Tenant-Specific Connections

For multi-tenant applications, you can specify tenant-level connections:

const response = await sdk.outbound.connect(
  'app-id',
  {
    redirectUrl: 'https://your-app.com/callback',
    scopes: ['email', 'profile'],
    externalIdentifier: 'external-user-id-123',
    tenantId: 'tenant-123',
    tenantLevel: true,
  },
  'user-session-token',
);

版本与发布记录

@descope/core-js-sdk 共发布 353 个版本,首次发布于 2022/08/16;过去 12 个月发布了 74 个版本。

版本发布日期距今
2.78.0latest2026/11/083 天前
0.0.0-next-8d9f5c5a-20261108next2026/11/083 天前
0.0.0-next-44302ad2-202610222026/10/2320 天前
0.0.0-next-80ee28b7-202610222026/10/2320 天前
0.0.0-next-5e656c1f-202610222026/10/2320 天前
0.0.0-next-6793a5a1-202610222026/10/2220 天前

其他发布通道:alpha → 1.9.2-alpha.0,next → 0.0.0-next-8d9f5c5a-20261108。

关于 @descope/core-js-sdk 的常见问题

@descope/core-js-sdk 是什么?

Descope JavaScript core SDK

如何安装 @descope/core-js-sdk?

在项目目录运行 npm install @descope/core-js-sdk,或使用 pnpm add / yarn add / bun add。

@descope/core-js-sdk 支持 TypeScript 吗?

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

@descope/core-js-sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@descope/core-js-sdk 可以商用吗?

@descope/core-js-sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@descope/core-js-sdk 的下载量有多少?

根据 npm 官方下载统计,@descope/core-js-sdk 在 2026/10/12 – 2026/11/10 这 30 天内被下载 3,383,403 次,日均约 112,780 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@descope/core-js-sdk 还在维护吗?

最新版本 2.78.0 发布于 2026/11/08(3 天前);至今共发布 353 个版本,其中过去 12 个月发布了 74 个;首次发布于 2022/08/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。