@descope/node-sdk 1.0.4-alpha.8 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -3,22 +3,87 @@ import _descope_core_js_sdk__default, { SdkResponse, ExchangeAccessKeyResponse }
3
3
  export { DeliveryMethod, OAuthProvider } from '@descope/core-js-sdk';
4
4
  import { JWTHeaderParameters, KeyLike } from 'jose';
5
5
 
6
- /** Represents a tenant association for a User. The tenantId is required to denote
7
- * which tenant the user belongs to. The roleNames array is an optional list of
8
- * roles for the user in this specific tenant.
6
+ /** Represents a tenant association for a User or Access Key. The tenantId is required to denote
7
+ * which tenant the user or access key belongs to. The roleNames array is an optional list of
8
+ * roles for the user or access key in this specific tenant.
9
9
  */
10
- declare type UserTenant = {
10
+ declare type AssociatedTenant = {
11
11
  tenantId: string;
12
12
  roleNames: string[];
13
13
  };
14
14
  /** The tenantId of a newly created tenant */
15
15
  declare type CreateTenantResponse = {
16
- tenantId: string;
16
+ id: string;
17
+ };
18
+ /** An access key that can be used to access descope */
19
+ declare type AccessKey = {
20
+ id: string;
21
+ name: string;
22
+ expiredTime: number;
23
+ roleNames: string[];
24
+ keyTenants?: AssociatedTenant[];
25
+ status: string;
26
+ createdTime: number;
27
+ expiresTime: number;
28
+ createdBy: string;
29
+ };
30
+ /** Access Key extended details including created key cleartext */
31
+ declare type CreatedAccessKeyResponse = {
32
+ key: AccessKey;
33
+ cleartext: string;
34
+ };
35
+ /** Represents a mapping between a set of groups of users and a role that will be assigned to them */
36
+ declare type RoleMapping = {
37
+ groups: string[];
38
+ role: string;
39
+ };
40
+ /** Represents a mapping between Descope and IDP user attributes */
41
+ declare type AttributeMapping = {
42
+ name?: string;
43
+ email?: string;
44
+ phoneNumber?: string;
45
+ group?: string;
17
46
  };
18
47
  /** UpdateJWT response with a new JWT value with the added custom claims */
19
48
  declare type UpdateJWTResponse = {
20
49
  jwt: string;
21
50
  };
51
+ /** Represents a tenant in a project. It has an id, a name and an array of
52
+ * self provisioning domains used to associate users with that tenant.
53
+ */
54
+ declare type Tenant = {
55
+ id: string;
56
+ name: string;
57
+ selfProvisioningDomains: string[];
58
+ };
59
+ /** Represents a permission in a project. It has a name and optionally a description.
60
+ * It also has a flag indicating whether it is system default or not.
61
+ */
62
+ declare type Permission = {
63
+ name: string;
64
+ description?: string;
65
+ systemDefault: boolean;
66
+ };
67
+ /** Represents a role in a project. It has a name and optionally a description and
68
+ * a list of permissions it grants.
69
+ */
70
+ declare type Role = {
71
+ name: string;
72
+ description?: string;
73
+ permissionNames: string[];
74
+ };
75
+ /** Represents a group in a project. It has an id and display name and a list of group members. */
76
+ declare type Group = {
77
+ id: string;
78
+ display: string;
79
+ members?: GroupMember[];
80
+ };
81
+ /** Represents a group member. It has loginId, userId and display. */
82
+ declare type GroupMember = {
83
+ loginId: string;
84
+ userId: string;
85
+ display: string;
86
+ };
22
87
 
23
88
  /** Parsed JWT token */
24
89
  interface Token {
@@ -34,354 +99,409 @@ interface AuthenticationInfo {
34
99
  cookies?: string[];
35
100
  }
36
101
 
37
- /** Refresh JWT cookie name */
38
- declare const refreshTokenCookieName = "DSR";
39
- /** Session JWT cookie name */
40
- declare const sessionTokenCookieName = "DS";
41
-
42
102
  /** Configuration arguments which include the Descope core SDK args and an optional management key */
43
103
  declare type NodeSdkArgs = Parameters<typeof _descope_core_js_sdk__default>[0] & {
44
104
  managementKey?: string;
45
105
  };
46
- /** Descope SDK client with delivery methods enum.
47
- *
48
- * Please see full documentation at {@link https://docs.descope.com/guides Descope Docs}
49
- * @example Usage
50
- *
51
- * ```js
52
- * import descopeSdk from '@descope/node-sdk';
53
- *
54
- * const myProjectId = 'xxx';
55
- * const sdk = descopeSdk({ projectId: myProjectId });
56
- *
57
- * const userIdentifier = 'identifier';
58
- * sdk.otp.signIn.email(userIdentifier);
59
- * const jwtResponse = sdk.otp.verify.email(userIdentifier, codeFromEmail);
60
- * ```
61
- */
62
- declare const sdkWithAttributes: ((args: NodeSdkArgs) => {
63
- /**
64
- * Provides various APIs for managing a Descope project programmatically. A management key must
65
- * be provided as an argument when initializing the SDK to use these APIs. Management keys can be
66
- * generated in the Descope console.
67
- */
68
- management: {
69
- user: {
70
- create: (identifier: string, email?: string, phone?: string, displayName?: string, roleNames?: string[], userTenants?: UserTenant[]) => Promise<SdkResponse<_descope_core_js_sdk.UserResponse>>;
71
- update: (identifier: string, email?: string, phone?: string, displayName?: string, roleNames?: string[], userTenants?: UserTenant[]) => Promise<SdkResponse<_descope_core_js_sdk.UserResponse>>;
72
- delete: (identifier: string) => Promise<SdkResponse<never>>;
73
- load: (identifier: string) => Promise<SdkResponse<_descope_core_js_sdk.UserResponse>>;
74
- searchAll: (tenantIds?: string[], roleNames?: string[], limit?: number) => Promise<SdkResponse<_descope_core_js_sdk.UserResponse[]>>;
75
- };
76
- tenant: {
77
- create: (name: string, selfProvisioningDomains?: string[]) => Promise<SdkResponse<CreateTenantResponse>>;
78
- createWithId: (tenantId: string, name: string, selfProvisioningDomains?: string[]) => Promise<SdkResponse<never>>;
79
- update: (tenantId: string, name: string, selfProvisioningDomains?: string[]) => Promise<SdkResponse<never>>;
80
- delete: (tenantId: string) => Promise<SdkResponse<never>>;
81
- };
82
- jwt: {
83
- update: (jwt: string, customClaims?: Record<string, any>) => Promise<SdkResponse<UpdateJWTResponse>>;
84
- };
85
- };
86
- /** Get the key that can validate the given JWT KID in the header. Can retrieve the public key from local cache or from Descope. */
87
- getKey(header: JWTHeaderParameters): Promise<KeyLike | Uint8Array>;
88
- /**
89
- * Validate the given JWT with the right key and make sure the issuer is correct
90
- * @param jwt the JWT string to parse and validate
91
- * @returns AuthenticationInfo with the parsed token and JWT. Will throw an error if validation fails.
92
- */
93
- validateJwt(jwt: string): Promise<AuthenticationInfo>;
94
- /**
95
- * Validate session based on at least one of session and refresh JWTs. You must provide at least one of them.
96
- *
97
- * @param sessionToken session JWT
98
- * @param refreshToken refresh JWT
99
- * @returns AuthenticationInfo promise or throws Error if there is an issue with JWTs
100
- */
101
- validateSession(sessionToken?: string, refreshToken?: string): Promise<AuthenticationInfo>;
102
- /**
103
- * Exchange API key (access key) for a session key
104
- * @param accessKey access key to exchange for a session JWT
105
- * @returns AuthneticationInfo with session JWT data
106
- */
107
- exchangeAccessKey(accessKey: string): Promise<AuthenticationInfo>;
108
- /**
109
- * Make sure that all given permissions exist on the parsed JWT top level claims
110
- * @param authInfo JWT parsed info
111
- * @param permissions list of permissions to make sure they exist on te JWT claims
112
- * @returns true if all permissions exist, false otherwise
113
- */
114
- validatePermissions(authInfo: AuthenticationInfo, permissions: string[]): boolean;
115
- /**
116
- * Make sure that all given permissions exist on the parsed JWT tenant claims
117
- * @param authInfo JWT parsed info
118
- * @param permissions list of permissions to make sure they exist on te JWT claims
119
- * @returns true if all permissions exist, false otherwise
120
- */
121
- validateTenantPermissions(authInfo: AuthenticationInfo, tenant: string, permissions: string[]): boolean;
122
- /**
123
- * Make sure that all given roles exist on the parsed JWT top level claims
124
- * @param authInfo JWT parsed info
125
- * @param roles list of roles to make sure they exist on te JWT claims
126
- * @returns true if all roles exist, false otherwise
127
- */
128
- validateRoles(authInfo: AuthenticationInfo, roles: string[]): boolean;
129
- /**
130
- * Make sure that all given roles exist on the parsed JWT tenant claims
131
- * @param authInfo JWT parsed info
132
- * @param roles list of roles to make sure they exist on te JWT claims
133
- * @returns true if all roles exist, false otherwise
134
- */
135
- validateTenantRoles(authInfo: AuthenticationInfo, tenant: string, roles: string[]): boolean;
136
- accessKey: {
137
- exchange: (accessKey: string) => Promise<SdkResponse<ExchangeAccessKeyResponse>>;
138
- };
139
- otp: {
140
- verify: {
141
- email: (identifier: string, code: string) => Promise<SdkResponse<_descope_core_js_sdk.JWTResponse>>;
142
- sms: (identifier: string, code: string) => Promise<SdkResponse<_descope_core_js_sdk.JWTResponse>>;
143
- whatsapp: (identifier: string, code: string) => Promise<SdkResponse<_descope_core_js_sdk.JWTResponse>>;
144
- };
145
- signIn: {
146
- email: (identifier: string) => Promise<SdkResponse<never>>;
147
- sms: (identifier: string) => Promise<SdkResponse<never>>;
148
- whatsapp: (identifier: string) => Promise<SdkResponse<never>>;
149
- };
150
- signUp: {
151
- email: (identifier: string, user?: {
152
- email?: string;
153
- name?: string;
154
- phone?: string;
155
- }) => Promise<SdkResponse<never>>;
156
- sms: (identifier: string, user?: {
157
- email?: string;
158
- name?: string;
159
- phone?: string;
160
- }) => Promise<SdkResponse<never>>;
161
- whatsapp: (identifier: string, user?: {
162
- email?: string;
163
- name?: string;
164
- phone?: string;
165
- }) => Promise<SdkResponse<never>>;
106
+ declare const nodeSdk: {
107
+ ({ managementKey, ...config }: NodeSdkArgs): {
108
+ management: {
109
+ user: {
110
+ create: (loginId: string, email?: string, phone?: string, displayName?: string, roles?: string[], userTenants?: AssociatedTenant[]) => Promise<SdkResponse<_descope_core_js_sdk.UserResponse>>;
111
+ update: (loginId: string, email?: string, phone?: string, displayName?: string, roles?: string[], userTenants?: AssociatedTenant[]) => Promise<SdkResponse<_descope_core_js_sdk.UserResponse>>;
112
+ delete: (loginId: string) => Promise<SdkResponse<never>>;
113
+ load: (loginId: string) => Promise<SdkResponse<_descope_core_js_sdk.UserResponse>>;
114
+ loadByUserId: (userId: string) => Promise<SdkResponse<_descope_core_js_sdk.UserResponse>>;
115
+ searchAll: (tenantIds?: string[], roles?: string[], limit?: number) => Promise<SdkResponse<_descope_core_js_sdk.UserResponse[]>>;
116
+ activate: (loginId: string) => Promise<SdkResponse<_descope_core_js_sdk.UserResponse>>;
117
+ deactivate: (loginId: string) => Promise<SdkResponse<_descope_core_js_sdk.UserResponse>>;
118
+ updateEmail: (loginId: string, email: string, isVerified: boolean) => Promise<SdkResponse<_descope_core_js_sdk.UserResponse>>;
119
+ updatePhone: (loginId: string, phone: string, isVerified: boolean) => Promise<SdkResponse<_descope_core_js_sdk.UserResponse>>;
120
+ updateDisplayName: (loginId: string, displayName: string) => Promise<SdkResponse<_descope_core_js_sdk.UserResponse>>;
121
+ addRoles: (loginId: string, roles: string[]) => Promise<SdkResponse<_descope_core_js_sdk.UserResponse>>;
122
+ removeRoles: (loginId: string, roles: string[]) => Promise<SdkResponse<_descope_core_js_sdk.UserResponse>>;
123
+ addTenant: (loginId: string, tenantId: string) => Promise<SdkResponse<_descope_core_js_sdk.UserResponse>>;
124
+ removeTenant: (loginId: string, tenantId: string) => Promise<SdkResponse<_descope_core_js_sdk.UserResponse>>;
125
+ addTenantRoles: (loginId: string, tenantId: string, roles: string[]) => Promise<SdkResponse<_descope_core_js_sdk.UserResponse>>;
126
+ removeTenantRoles: (loginId: string, tenantId: string, roles: string[]) => Promise<SdkResponse<_descope_core_js_sdk.UserResponse>>;
127
+ };
128
+ accessKey: {
129
+ create: (name: string, expireTime: number, roles?: string[], keyTenants?: AssociatedTenant[]) => Promise<SdkResponse<CreatedAccessKeyResponse>>;
130
+ load: (id: string) => Promise<SdkResponse<AccessKey>>;
131
+ searchAll: (tenantIds?: string[]) => Promise<SdkResponse<AccessKey[]>>;
132
+ update: (id: string, name: string) => Promise<SdkResponse<AccessKey>>;
133
+ deactivate: (id: string) => Promise<SdkResponse<never>>;
134
+ activate: (id: string) => Promise<SdkResponse<never>>;
135
+ delete: (id: string) => Promise<SdkResponse<never>>;
136
+ };
137
+ tenant: {
138
+ create: (name: string, selfProvisioningDomains?: string[]) => Promise<SdkResponse<CreateTenantResponse>>;
139
+ createWithId: (id: string, name: string, selfProvisioningDomains?: string[]) => Promise<SdkResponse<never>>;
140
+ update: (id: string, name: string, selfProvisioningDomains?: string[]) => Promise<SdkResponse<never>>;
141
+ delete: (id: string) => Promise<SdkResponse<never>>;
142
+ loadAll: () => Promise<SdkResponse<Tenant[]>>;
143
+ };
144
+ sso: {
145
+ configureSettings: (tenantId: string, idpURL: string, idpCert: string, entityId: string, redirectURL?: string) => Promise<SdkResponse<never>>;
146
+ configureMetadata: (tenantId: string, idpMetadataURL: string) => Promise<SdkResponse<never>>;
147
+ configureMapping: (tenantId: string, roleMapping?: RoleMapping, attributeMapping?: AttributeMapping) => Promise<SdkResponse<never>>;
148
+ };
149
+ jwt: {
150
+ update: (jwt: string, customClaims?: Record<string, any>) => Promise<SdkResponse<UpdateJWTResponse>>;
151
+ };
152
+ permission: {
153
+ create: (name: string, description?: string) => Promise<SdkResponse<never>>;
154
+ update: (name: string, newName: string, description?: string) => Promise<SdkResponse<never>>;
155
+ delete: (name: string) => Promise<SdkResponse<never>>;
156
+ loadAll: () => Promise<SdkResponse<Permission[]>>;
157
+ };
158
+ role: {
159
+ create: (name: string, description?: string, permissionNames?: string[]) => Promise<SdkResponse<never>>;
160
+ update: (name: string, newName: string, description?: string, permissionNames?: string[]) => Promise<SdkResponse<never>>;
161
+ delete: (name: string) => Promise<SdkResponse<never>>;
162
+ loadAll: () => Promise<SdkResponse<Role[]>>;
163
+ };
164
+ group: {
165
+ loadAllGroups: (tenantId: string) => Promise<SdkResponse<Group[]>>;
166
+ loadAllGroupsForMember: (tenantId: string, userIds: string[], loginIds: string[]) => Promise<SdkResponse<Group[]>>;
167
+ loadAllGroupMembers: (tenantId: string, groupId: string) => Promise<SdkResponse<Group[]>>;
168
+ };
166
169
  };
167
- signUpOrIn: {
168
- email: (identifier: string) => Promise<SdkResponse<never>>;
169
- sms: (identifier: string) => Promise<SdkResponse<never>>;
170
- whatsapp: (identifier: string) => Promise<SdkResponse<never>>;
170
+ getKey: (header: JWTHeaderParameters) => Promise<KeyLike | Uint8Array>;
171
+ validateJwt: (jwt: string) => Promise<AuthenticationInfo>;
172
+ validateSession: (sessionToken: string) => Promise<AuthenticationInfo>;
173
+ refreshSession: (refreshToken: string) => Promise<AuthenticationInfo>;
174
+ validateAndRefreshSession: (sessionToken?: string, refreshToken?: string) => Promise<AuthenticationInfo>;
175
+ exchangeAccessKey: (accessKey: string) => Promise<AuthenticationInfo>;
176
+ validatePermissions: (authInfo: AuthenticationInfo, permissions: string[]) => boolean;
177
+ validateTenantPermissions: (authInfo: AuthenticationInfo, tenant: string, permissions: string[]) => boolean;
178
+ validateRoles: (authInfo: AuthenticationInfo, roles: string[]) => boolean;
179
+ validateTenantRoles: (authInfo: AuthenticationInfo, tenant: string, roles: string[]) => boolean;
180
+ accessKey: {
181
+ exchange: (accessKey: string) => Promise<SdkResponse<ExchangeAccessKeyResponse>>;
171
182
  };
172
- update: {
173
- email: (identifier: string, email: string, token?: string) => Promise<SdkResponse<never>>;
174
- phone: {
175
- email: (identifier: string, phone: string) => Promise<SdkResponse<never>>;
176
- sms: (identifier: string, phone: string) => Promise<SdkResponse<never>>;
177
- whatsapp: (identifier: string, phone: string) => Promise<SdkResponse<never>>;
183
+ otp: {
184
+ verify: {
185
+ email: (loginId: string, code: string) => Promise<SdkResponse<_descope_core_js_sdk.JWTResponse & {
186
+ refreshJwt?: string;
187
+ cookies?: string[];
188
+ }>>;
189
+ sms: (loginId: string, code: string) => Promise<SdkResponse<_descope_core_js_sdk.JWTResponse & {
190
+ refreshJwt?: string;
191
+ cookies?: string[];
192
+ }>>;
193
+ whatsapp: (loginId: string, code: string) => Promise<SdkResponse<_descope_core_js_sdk.JWTResponse & {
194
+ refreshJwt?: string;
195
+ cookies?: string[];
196
+ }>>;
197
+ };
198
+ signIn: {
199
+ email: (loginId: string) => Promise<SdkResponse<never>>;
200
+ sms: (loginId: string) => Promise<SdkResponse<never>>;
201
+ whatsapp: (loginId: string) => Promise<SdkResponse<never>>;
202
+ };
203
+ signUp: {
204
+ email: (loginId: string, user?: {
205
+ email?: string;
206
+ name?: string;
207
+ phone?: string;
208
+ }) => Promise<SdkResponse<never>>;
209
+ sms: (loginId: string, user?: {
210
+ email?: string;
211
+ name?: string;
212
+ phone?: string;
213
+ }) => Promise<SdkResponse<never>>;
214
+ whatsapp: (loginId: string, user?: {
215
+ email?: string;
216
+ name?: string;
217
+ phone?: string;
218
+ }) => Promise<SdkResponse<never>>;
219
+ };
220
+ signUpOrIn: {
221
+ email: (loginId: string) => Promise<SdkResponse<never>>;
222
+ sms: (loginId: string) => Promise<SdkResponse<never>>;
223
+ whatsapp: (loginId: string) => Promise<SdkResponse<never>>;
224
+ };
225
+ update: {
226
+ email: (loginId: string, email: string, token?: string) => Promise<SdkResponse<never>>;
227
+ phone: {
228
+ email: (loginId: string, phone: string) => Promise<SdkResponse<never>>;
229
+ sms: (loginId: string, phone: string) => Promise<SdkResponse<never>>;
230
+ whatsapp: (loginId: string, phone: string) => Promise<SdkResponse<never>>;
231
+ };
178
232
  };
179
233
  };
180
- };
181
- magicLink: {
182
- verify: (token: string) => Promise<SdkResponse<_descope_core_js_sdk.JWTResponse>>;
183
- signIn: {
184
- email: (identifier: string, uri: string) => Promise<SdkResponse<_descope_core_js_sdk.PendingRefResponse>>;
185
- sms: (identifier: string, uri: string) => Promise<SdkResponse<_descope_core_js_sdk.PendingRefResponse>>;
186
- whatsapp: (identifier: string, uri: string) => Promise<SdkResponse<_descope_core_js_sdk.PendingRefResponse>>;
234
+ magicLink: {
235
+ verify: (token: string) => Promise<SdkResponse<_descope_core_js_sdk.JWTResponse & {
236
+ refreshJwt?: string;
237
+ cookies?: string[];
238
+ }>>;
239
+ signIn: {
240
+ email: (loginId: string, uri: string) => Promise<SdkResponse<never>>;
241
+ sms: (loginId: string, uri: string) => Promise<SdkResponse<never>>;
242
+ whatsapp: (loginId: string, uri: string) => Promise<SdkResponse<never>>;
243
+ };
244
+ signUp: {
245
+ email: (loginId: string, uri: string, user?: {
246
+ email?: string;
247
+ name?: string;
248
+ phone?: string;
249
+ }) => Promise<SdkResponse<never>>;
250
+ sms: (loginId: string, uri: string, user?: {
251
+ email?: string;
252
+ name?: string;
253
+ phone?: string;
254
+ }) => Promise<SdkResponse<never>>;
255
+ whatsapp: (loginId: string, uri: string, user?: {
256
+ email?: string;
257
+ name?: string;
258
+ phone?: string;
259
+ }) => Promise<SdkResponse<never>>;
260
+ };
261
+ signUpOrIn: {
262
+ email: (loginId: string, uri: string) => Promise<SdkResponse<never>>;
263
+ sms: (loginId: string, uri: string) => Promise<SdkResponse<never>>;
264
+ whatsapp: (loginId: string, uri: string) => Promise<SdkResponse<never>>;
265
+ };
266
+ update: {
267
+ email: (loginId: string, email: string, URI?: string, token?: string) => Promise<SdkResponse<never>>;
268
+ phone: {
269
+ email: (loginId: string, phone: string) => Promise<SdkResponse<never>>;
270
+ sms: (loginId: string, phone: string) => Promise<SdkResponse<never>>;
271
+ whatsapp: (loginId: string, phone: string) => Promise<SdkResponse<never>>;
272
+ };
273
+ };
187
274
  };
188
- signUp: {
189
- email: (identifier: string, uri: string, user?: {
190
- email?: string;
191
- name?: string;
192
- phone?: string;
193
- }) => Promise<SdkResponse<_descope_core_js_sdk.PendingRefResponse>>;
194
- sms: (identifier: string, uri: string, user?: {
195
- email?: string;
196
- name?: string;
197
- phone?: string;
198
- }) => Promise<SdkResponse<_descope_core_js_sdk.PendingRefResponse>>;
199
- whatsapp: (identifier: string, uri: string, user?: {
275
+ enchantedLink: {
276
+ verify: (token: string) => Promise<SdkResponse<never>>;
277
+ signIn: (loginId: string, uri: string) => Promise<SdkResponse<_descope_core_js_sdk.EnchantedLinkResponse & {
278
+ refreshJwt?: string;
279
+ cookies?: string[];
280
+ }>>;
281
+ signUpOrIn: (loginId: string, uri: string) => Promise<SdkResponse<_descope_core_js_sdk.EnchantedLinkResponse>>;
282
+ signUp: (loginId: string, uri: string, user?: {
200
283
  email?: string;
201
284
  name?: string;
202
285
  phone?: string;
203
- }) => Promise<SdkResponse<_descope_core_js_sdk.PendingRefResponse>>;
204
- };
205
- signUpOrIn: {
206
- email: (identifier: string, uri: string) => Promise<SdkResponse<_descope_core_js_sdk.PendingRefResponse>>;
207
- sms: (identifier: string, uri: string) => Promise<SdkResponse<_descope_core_js_sdk.PendingRefResponse>>;
208
- whatsapp: (identifier: string, uri: string) => Promise<SdkResponse<_descope_core_js_sdk.PendingRefResponse>>;
209
- };
210
- update: {
211
- email: (identifier: string, email: string, uri: string, token?: string) => Promise<SdkResponse<never>>;
212
- phone: {
213
- email: (identifier: string, phone: string) => Promise<SdkResponse<never>>;
214
- sms: (identifier: string, phone: string) => Promise<SdkResponse<never>>;
215
- whatsapp: (identifier: string, phone: string) => Promise<SdkResponse<never>>;
286
+ }) => Promise<SdkResponse<_descope_core_js_sdk.EnchantedLinkResponse & {
287
+ refreshJwt?: string;
288
+ cookies?: string[];
289
+ }>>;
290
+ waitForSession: (pendingRef: string, config?: {
291
+ /**
292
+ * Validate session and refresh it if it expired
293
+ * @param sessionToken session JWT
294
+ * @param refreshToken refresh JWT
295
+ * @returns AuthenticationInfo promise or throws Error if there is an issue with JWTs
296
+ */
297
+ pollingIntervalMs: number;
298
+ timeoutMs: number;
299
+ }) => Promise<SdkResponse<_descope_core_js_sdk.JWTResponse>>;
300
+ update: {
301
+ email: (loginId: string, email: string, URI?: string, token?: string) => Promise<SdkResponse<_descope_core_js_sdk.EnchantedLinkResponse>>;
216
302
  };
217
303
  };
218
- };
219
- enchantedLink: {
220
- verify: (token: string) => Promise<SdkResponse<never>>;
221
- signIn: (identifier: string, uri: string) => Promise<SdkResponse<_descope_core_js_sdk.PendingRefResponse>>;
222
- signUpOrIn: (identifier: string, uri: string) => Promise<SdkResponse<_descope_core_js_sdk.PendingRefResponse>>;
223
- signUp: (identifier: string, uri: string, user?: {
224
- email?: string;
225
- name?: string;
226
- phone?: string;
227
- }) => Promise<SdkResponse<_descope_core_js_sdk.PendingRefResponse>>;
228
- waitForSession: (pendingRef: string, config?: {
229
- pollingIntervalMs: number;
230
- timeoutMs: number;
231
- }) => Promise<SdkResponse<_descope_core_js_sdk.JWTResponse>>;
232
- update: {
233
- email: (identifier: string, email: string, uri: string, token?: string) => Promise<SdkResponse<_descope_core_js_sdk.PendingRefResponse>>;
304
+ oauth: {
305
+ start: {
306
+ facebook: <B extends {
307
+ redirect: boolean;
308
+ }>(redirectURL?: string, config?: B) => Promise<B extends {
309
+ redirect: true;
310
+ } ? undefined : SdkResponse<_descope_core_js_sdk.URLResponse>>;
311
+ github: <B_1 extends {
312
+ redirect: boolean;
313
+ }>(redirectURL?: string, config?: B_1) => Promise<B_1 extends {
314
+ redirect: true;
315
+ } ? undefined : SdkResponse<_descope_core_js_sdk.URLResponse>>;
316
+ google: <B_2 extends {
317
+ redirect: boolean;
318
+ }>(redirectURL?: string, config?: B_2) => Promise<B_2 extends {
319
+ redirect: true;
320
+ } ? undefined : SdkResponse<_descope_core_js_sdk.URLResponse>>;
321
+ microsoft: <B_3 extends {
322
+ redirect: boolean;
323
+ }>(redirectURL?: string, config?: B_3) => Promise<B_3 extends {
324
+ redirect: true;
325
+ } ? undefined : SdkResponse<_descope_core_js_sdk.URLResponse>>;
326
+ gitlab: <B_4 extends {
327
+ redirect: boolean;
328
+ }>(redirectURL?: string, config?: B_4) => Promise<B_4 extends {
329
+ redirect: true;
330
+ } ? undefined : SdkResponse<_descope_core_js_sdk.URLResponse>>;
331
+ apple: <B_5 extends {
332
+ redirect: boolean;
333
+ }>(redirectURL?: string, config?: B_5) => Promise<B_5 extends {
334
+ redirect: true;
335
+ } ? undefined : SdkResponse<_descope_core_js_sdk.URLResponse>>;
336
+ discord: <B_6 extends {
337
+ redirect: boolean;
338
+ }>(redirectURL?: string, config?: B_6) => Promise<B_6 extends {
339
+ redirect: true;
340
+ } ? undefined : SdkResponse<_descope_core_js_sdk.URLResponse>>;
341
+ linkedin: <B_7 extends {
342
+ redirect: boolean;
343
+ }>(redirectURL?: string, config?: B_7) => Promise<B_7 extends {
344
+ redirect: true;
345
+ } ? undefined : SdkResponse<_descope_core_js_sdk.URLResponse>>;
346
+ };
347
+ exchange: (code: string) => Promise<SdkResponse<_descope_core_js_sdk.JWTResponse & {
348
+ refreshJwt?: string;
349
+ cookies?: string[];
350
+ }>>;
234
351
  };
235
- };
236
- oauth: {
237
- start: {
238
- facebook: <B extends {
239
- redirect: boolean;
240
- }>(redirectURL?: string, config?: B) => Promise<B extends {
241
- redirect: true;
242
- } ? undefined : SdkResponse<_descope_core_js_sdk.URLResponse>>;
243
- github: <B_1 extends {
352
+ saml: {
353
+ start: <B_1 extends {
244
354
  redirect: boolean;
245
- }>(redirectURL?: string, config?: B_1) => Promise<B_1 extends {
355
+ }>(tenantNameOrEmail: string, config?: B_1) => Promise<B_1 extends {
246
356
  redirect: true;
247
357
  } ? undefined : SdkResponse<_descope_core_js_sdk.URLResponse>>;
248
- google: <B_2 extends {
249
- redirect: boolean;
250
- }>(redirectURL?: string, config?: B_2) => Promise<B_2 extends {
251
- redirect: true;
252
- } ? undefined : SdkResponse<_descope_core_js_sdk.URLResponse>>;
253
- microsoft: <B_3 extends {
254
- redirect: boolean;
255
- }>(redirectURL?: string, config?: B_3) => Promise<B_3 extends {
256
- redirect: true;
257
- } ? undefined : SdkResponse<_descope_core_js_sdk.URLResponse>>;
258
- gitlab: <B_4 extends {
259
- redirect: boolean;
260
- }>(redirectURL?: string, config?: B_4) => Promise<B_4 extends {
261
- redirect: true;
262
- } ? undefined : SdkResponse<_descope_core_js_sdk.URLResponse>>;
263
- apple: <B_5 extends {
264
- redirect: boolean;
265
- }>(redirectURL?: string, config?: B_5) => Promise<B_5 extends {
266
- redirect: true;
267
- } ? undefined : SdkResponse<_descope_core_js_sdk.URLResponse>>;
268
- };
269
- exchange: (code: string) => Promise<SdkResponse<_descope_core_js_sdk.JWTResponse>>;
270
- };
271
- saml: {
272
- start: <B_1 extends {
273
- redirect: boolean;
274
- }>(tenantNameOrEmail: string, config?: B_1) => Promise<B_1 extends {
275
- redirect: true;
276
- } ? undefined : SdkResponse<_descope_core_js_sdk.URLResponse>>;
277
- exchange: (code: string) => Promise<SdkResponse<_descope_core_js_sdk.JWTResponse>>;
278
- };
279
- totp: {
280
- signUp: (identifier: string, user?: {
281
- email?: string;
282
- name?: string;
283
- phone?: string;
284
- }) => Promise<SdkResponse<_descope_core_js_sdk.TOTPResponse>>;
285
- verify: (identifier: string, code: string, loginOptions?: {
286
- stepup?: boolean;
287
- mfa?: boolean;
288
- customClaims?: Record<string, any>;
289
- }, token?: string) => Promise<SdkResponse<_descope_core_js_sdk.JWTResponse>>;
290
- update: (identifier: string, token?: string) => Promise<SdkResponse<_descope_core_js_sdk.TOTPResponse>>;
291
- };
292
- webauthn: {
293
- signUp: {
294
- start: (identifier: string, origin: string, name: string) => Promise<SdkResponse<{
295
- transactionId: string;
296
- options: string;
297
- create: boolean;
358
+ exchange: (code: string) => Promise<SdkResponse<_descope_core_js_sdk.JWTResponse & {
359
+ refreshJwt?: string;
360
+ cookies?: string[];
298
361
  }>>;
299
- finish: (transactionId: string, response: string) => Promise<SdkResponse<_descope_core_js_sdk.JWTResponse>>;
300
362
  };
301
- signIn: {
302
- start: (identifier: string, origin: string, loginOptions?: {
363
+ totp: {
364
+ signUp: (loginId: string, user?: {
365
+ email?: string;
366
+ name?: string;
367
+ phone?: string;
368
+ }) => Promise<SdkResponse<_descope_core_js_sdk.TOTPResponse>>;
369
+ verify: (loginId: string, code: string, loginOptions?: {
303
370
  stepup?: boolean;
304
371
  mfa?: boolean;
305
372
  customClaims?: Record<string, any>;
306
- }, token?: string) => Promise<SdkResponse<{
307
- transactionId: string;
308
- options: string;
309
- create: boolean;
310
- }>>;
311
- finish: (transactionId: string, response: string) => Promise<SdkResponse<_descope_core_js_sdk.JWTResponse>>;
312
- };
313
- signUpOrIn: {
314
- start: (identifier: string, origin: string) => Promise<SdkResponse<{
315
- transactionId: string;
316
- options: string;
317
- create: boolean;
373
+ }, token?: string) => Promise<SdkResponse<_descope_core_js_sdk.JWTResponse & {
374
+ refreshJwt?: string;
375
+ cookies?: string[];
318
376
  }>>;
377
+ update: (loginId: string, token?: string) => Promise<SdkResponse<_descope_core_js_sdk.TOTPResponse>>;
319
378
  };
320
- update: {
321
- start: (identifier: string, origin: string, token: string) => Promise<SdkResponse<{
322
- transactionId: string;
323
- options: string;
324
- create: boolean;
325
- }>>;
326
- finish: (transactionId: string, response: string) => Promise<SdkResponse<_descope_core_js_sdk.ResponseData>>;
327
- };
328
- };
329
- flow: {
330
- start: (flowId: string, options?: {
331
- redirectUrl?: string;
332
- tenant?: string;
333
- deviceInfo?: {
334
- webAuthnSupport?: boolean;
379
+ webauthn: {
380
+ signUp: {
381
+ start: (loginId: string, origin: string, name: string) => Promise<SdkResponse<{
382
+ transactionId: string;
383
+ options: string;
384
+ create: boolean;
385
+ }>>;
386
+ finish: (transactionId: string, response: string) => Promise<SdkResponse<_descope_core_js_sdk.JWTResponse & {
387
+ refreshJwt?: string;
388
+ cookies?: string[];
389
+ }>>;
335
390
  };
336
- lastUser?: {
337
- authMethod?: "otp" | "totp" | "webauthn" | "magiclink" | "social" | "sso";
338
- oauthProvider?: string;
339
- externalId?: string;
391
+ signIn: {
392
+ start: (loginId: string, origin: string, loginOptions?: {
393
+ stepup?: boolean;
394
+ mfa?: boolean;
395
+ customClaims?: Record<string, any>;
396
+ }, token?: string) => Promise<SdkResponse<{
397
+ transactionId: string;
398
+ options: string;
399
+ create: boolean;
400
+ }>>;
401
+ finish: (transactionId: string, response: string) => Promise<SdkResponse<_descope_core_js_sdk.JWTResponse & {
402
+ refreshJwt?: string;
403
+ cookies?: string[];
404
+ }>>;
340
405
  };
341
- }) => Promise<SdkResponse<_descope_core_js_sdk.FlowResponse>>;
342
- next: (executionId: string, stepId: string, interactionId: string, input?: Record<string, FormDataEntryValue>) => Promise<SdkResponse<_descope_core_js_sdk.FlowResponse>>;
343
- };
344
- refresh: (token?: string) => Promise<SdkResponse<_descope_core_js_sdk.JWTResponse>>;
345
- logout: (token?: string) => Promise<SdkResponse<never>>;
346
- logoutAll: (token?: string) => Promise<SdkResponse<never>>;
347
- me: (token?: string) => Promise<SdkResponse<_descope_core_js_sdk.UserResponse>>;
348
- isJwtExpired: (token: string) => boolean;
349
- getJwtPermissions: (token: string, tenant?: string) => string[];
350
- getJwtRoles: (token: string, tenant?: string) => string[];
351
- httpClient: {
352
- get: (path: string, config?: {
353
- headers?: HeadersInit;
354
- queryParams?: {
355
- [key: string]: string;
406
+ signUpOrIn: {
407
+ start: (loginId: string, origin: string) => Promise<SdkResponse<{
408
+ transactionId: string;
409
+ options: string;
410
+ create: boolean;
411
+ }>>;
356
412
  };
357
- token?: string;
358
- }) => Promise<globalThis.Response>;
359
- post: (path: string, body?: any, config?: {
360
- headers?: HeadersInit;
361
- queryParams?: {
362
- [key: string]: string;
413
+ update: {
414
+ start: (loginId: string, origin: string, token: string) => Promise<SdkResponse<{
415
+ transactionId: string;
416
+ options: string;
417
+ create: boolean;
418
+ }>>;
419
+ finish: (transactionId: string, response: string) => Promise<SdkResponse<_descope_core_js_sdk.ResponseData>>;
363
420
  };
364
- token?: string;
365
- }) => Promise<globalThis.Response>;
366
- put: (path: string, body?: any, config?: {
367
- headers?: HeadersInit;
368
- queryParams?: {
369
- [key: string]: string;
370
- };
371
- token?: string;
372
- }) => Promise<globalThis.Response>;
373
- delete: (path: string, body?: any, config?: {
374
- headers?: HeadersInit;
375
- queryParams?: {
376
- [key: string]: string;
421
+ };
422
+ flow: {
423
+ start: (flowId: string, options?: {
424
+ redirectUrl?: string;
425
+ tenant?: string;
426
+ deviceInfo?: {
427
+ webAuthnSupport?: boolean;
428
+ };
429
+ lastAuth?: {
430
+ authMethod?: "otp" | "oauth" | "saml" | "totp" | "webauthn" | "magiclink" | "enchantedlink";
431
+ oauthProvider?: string;
432
+ name?: string;
433
+ loginId?: string;
434
+ };
435
+ }, conditionInteractionId?: string, interactionId?: string, input?: {
436
+ [x: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | any)[])[])[])[])[])[])[])[])[])[])[];
437
+ }) => Promise<SdkResponse<_descope_core_js_sdk.FlowResponse>>;
438
+ next: (executionId: string, stepId: string, interactionId: string, input?: {
439
+ [x: string]: string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | (string | number | boolean | any)[])[])[])[])[])[])[])[])[])[])[];
440
+ }) => Promise<SdkResponse<_descope_core_js_sdk.FlowResponse>>;
441
+ };
442
+ refresh: (token?: string) => Promise<SdkResponse<_descope_core_js_sdk.JWTResponse & {
443
+ refreshJwt?: string;
444
+ cookies?: string[];
445
+ }>>;
446
+ logout: (token?: string) => Promise<SdkResponse<never>>;
447
+ logoutAll: (token?: string) => Promise<SdkResponse<never>>;
448
+ me: (token?: string) => Promise<SdkResponse<_descope_core_js_sdk.UserResponse>>;
449
+ isJwtExpired: (token: string) => boolean;
450
+ getJwtPermissions: (token: string, tenant?: string) => string[];
451
+ getJwtRoles: (token: string, tenant?: string) => string[];
452
+ httpClient: {
453
+ get: (path: string, config?: {
454
+ headers?: HeadersInit;
455
+ queryParams?: {
456
+ [key: string]: string;
457
+ };
458
+ token?: string;
459
+ }) => Promise<Response>;
460
+ post: (path: string, body?: any, config?: {
461
+ headers?: HeadersInit;
462
+ queryParams?: {
463
+ [key: string]: string;
464
+ };
465
+ token?: string;
466
+ }) => Promise<Response>;
467
+ put: (path: string, body?: any, config?: {
468
+ headers?: HeadersInit;
469
+ queryParams?: {
470
+ [key: string]: string;
471
+ };
472
+ token?: string;
473
+ }) => Promise<Response>;
474
+ delete: (path: string, body?: any, config?: {
475
+ headers?: HeadersInit;
476
+ queryParams?: {
477
+ [key: string]: string;
478
+ };
479
+ token?: string;
480
+ }) => Promise<Response>;
481
+ hooks?: {
482
+ beforeRequest?: (config: _descope_core_js_sdk.RequestConfig) => _descope_core_js_sdk.RequestConfig;
483
+ afterRequest?: (req: _descope_core_js_sdk.RequestConfig, res: Response) => void | Promise<void>;
377
484
  };
378
- token?: string;
379
- }) => Promise<globalThis.Response>;
485
+ };
380
486
  };
381
- }) & {
382
- DeliveryMethods: typeof _descope_core_js_sdk__default.DeliveryMethods;
383
- RefreshTokenCookieName: typeof refreshTokenCookieName;
384
- SessionTokenCookieName: typeof sessionTokenCookieName;
487
+ /** Descope SDK client with delivery methods enum.
488
+ *
489
+ * Please see full documentation at {@link https://docs.descope.com/guides Descope Docs}
490
+ * @example Usage
491
+ *
492
+ * ```js
493
+ * import descopeSdk from '@descope/node-sdk';
494
+ *
495
+ * const myProjectId = 'xxx';
496
+ * const sdk = descopeSdk({ projectId: myProjectId });
497
+ *
498
+ * const userLoginId = 'loginId';
499
+ * sdk.otp.signIn.email(userLoginId);
500
+ * const jwtResponse = sdk.otp.verify.email(userLoginId, codeFromEmail);
501
+ * ```
502
+ */
503
+ RefreshTokenCookieName: string;
504
+ SessionTokenCookieName: string;
385
505
  };
386
506
 
387
- export { NodeSdkArgs, sdkWithAttributes as default };
507
+ export { nodeSdk as default };