@logto/client 3.0.0-alpha.2 → 3.0.3

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/package.json CHANGED
@@ -1,23 +1,15 @@
1
1
  {
2
2
  "name": "@logto/client",
3
- "version": "3.0.0-alpha.2",
3
+ "version": "3.0.3",
4
4
  "type": "module",
5
- "main": "./lib/index.cjs",
6
5
  "module": "./lib/index.js",
7
6
  "types": "./lib/index.d.ts",
7
+ "react-native": "./lib/shim.js",
8
8
  "exports": {
9
- ".": {
10
- "types": "./lib/index.d.ts",
11
- "require": "./lib/index.cjs",
12
- "import": "./lib/index.js",
13
- "default": "./lib/index.js"
14
- },
15
- "./shim": {
16
- "types": "./lib/shim.d.ts",
17
- "require": "./lib/shim.cjs",
18
- "import": "./lib/shim.js",
19
- "default": "./lib/shim.js"
20
- }
9
+ "types": "./lib/index.d.ts",
10
+ "react-native": "./lib/shim.js",
11
+ "import": "./lib/index.js",
12
+ "default": "./lib/index.js"
21
13
  },
22
14
  "files": [
23
15
  "lib"
@@ -29,27 +21,23 @@
29
21
  "directory": "packages/client"
30
22
  },
31
23
  "dependencies": {
32
- "@logto/js": "^4.0.0-alpha.2",
33
- "@silverhand/essentials": "^2.8.7",
34
- "camelcase-keys": "^7.0.1",
35
- "jose": "^5.0.0"
24
+ "@silverhand/essentials": "^2.9.2",
25
+ "camelcase-keys": "^9.1.3",
26
+ "jose": "^5.2.2",
27
+ "@logto/js": "^5.0.2"
36
28
  },
37
29
  "devDependencies": {
38
- "@silverhand/eslint-config": "^5.0.0",
39
- "@silverhand/ts-config": "^5.0.0",
40
- "@swc/core": "^1.3.50",
41
- "@swc/jest": "^0.2.24",
42
- "@types/jest": "^29.5.0",
43
- "@types/node": "^20.0.0",
44
- "eslint": "^8.44.0",
45
- "jest": "^29.5.0",
46
- "jest-matcher-specific-error": "^1.0.0",
30
+ "@silverhand/eslint-config": "^6.0.1",
31
+ "@silverhand/ts-config": "^6.0.0",
32
+ "@types/node": "^22.0.0",
33
+ "@vitest/coverage-v8": "^1.6.0",
34
+ "eslint": "^8.57.0",
35
+ "happy-dom": "^15.10.2",
47
36
  "lint-staged": "^15.0.0",
48
- "nock": "^13.3.0",
37
+ "nock": "14.0.0-beta.19",
49
38
  "prettier": "^3.0.0",
50
- "text-encoder": "^0.0.4",
51
- "type-fest": "^4.0.0",
52
- "typescript": "^5.0.0"
39
+ "typescript": "^5.3.3",
40
+ "vitest": "^1.6.0"
53
41
  },
54
42
  "eslintConfig": {
55
43
  "extends": "@silverhand"
@@ -64,7 +52,8 @@
64
52
  "check": "tsc --noEmit",
65
53
  "build": "rm -rf lib/ && tsc -p tsconfig.build.json --noEmit && rollup -c",
66
54
  "lint": "eslint --ext .ts src",
67
- "test": "jest",
68
- "test:coverage": "jest --silent --env=jsdom && jest --silent --coverage"
55
+ "test": "vitest",
56
+ "test:dom": "vitest --config=vitest.config.dom.ts",
57
+ "test:coverage": "pnpm test:dom --silent --no-watch && pnpm run test --no-watch --silent --coverage"
69
58
  }
70
59
  }
@@ -1,28 +0,0 @@
1
- 'use strict';
2
-
3
- var js = require('@logto/js');
4
- var jose = require('jose');
5
-
6
- const issuedAtTimeTolerance = 300; // 5 minutes
7
- const verifyIdToken = async (idToken, clientId, issuer, jwks) => {
8
- const result = await jose.jwtVerify(idToken, jwks, { audience: clientId, issuer });
9
- if (Math.abs((result.payload.iat ?? 0) - Date.now() / 1000) > issuedAtTimeTolerance) {
10
- throw new js.LogtoError('id_token.invalid_iat');
11
- }
12
- };
13
- class DefaultJwtVerifier {
14
- constructor(client) {
15
- this.client = client;
16
- }
17
- async verifyIdToken(idToken) {
18
- const { appId } = this.client.logtoConfig;
19
- const { issuer, jwksUri } = await this.client.getOidcConfig();
20
- if (!this.getJwtVerifyGetKey) {
21
- this.getJwtVerifyGetKey = jose.createRemoteJWKSet(new URL(jwksUri));
22
- }
23
- await verifyIdToken(idToken, appId, issuer, this.getJwtVerifyGetKey);
24
- }
25
- }
26
-
27
- exports.DefaultJwtVerifier = DefaultJwtVerifier;
28
- exports.verifyIdToken = verifyIdToken;
@@ -1,63 +0,0 @@
1
- 'use strict';
2
-
3
- var essentials = require('@silverhand/essentials');
4
- var types = require('./types.cjs');
5
-
6
- class ClientAdapterInstance {
7
- /* END OF IMPLEMENTATION */
8
- constructor(adapter) {
9
- // eslint-disable-next-line @silverhand/fp/no-mutating-assign
10
- Object.assign(this, adapter);
11
- }
12
- async setStorageItem(key, value) {
13
- if (!value) {
14
- await this.storage.removeItem(key);
15
- return;
16
- }
17
- await this.storage.setItem(key, value);
18
- }
19
- /**
20
- * Try to get the string value from the cache and parse as JSON.
21
- * Return the parsed value if it is an object, return `undefined` otherwise.
22
- *
23
- * @param key The cache key to get value from.
24
- */
25
- async getCachedObject(key) {
26
- const cached = await essentials.trySafe(async () => {
27
- const data = await this.unstable_cache?.getItem(key);
28
- // It's actually `unknown`
29
- // eslint-disable-next-line no-restricted-syntax
30
- return essentials.conditional(data && JSON.parse(data));
31
- });
32
- if (cached && typeof cached === 'object') {
33
- // Trust cache for now
34
- // eslint-disable-next-line no-restricted-syntax
35
- return cached;
36
- }
37
- }
38
- /**
39
- * Try to get the value from the cache first, if it doesn't exist in cache,
40
- * run the getter function and store the result into cache.
41
- *
42
- * @param key The cache key to get value from.
43
- */
44
- async getWithCache(key, getter) {
45
- const cached = await this.getCachedObject(key);
46
- if (cached) {
47
- return cached;
48
- }
49
- const result = await getter();
50
- await this.unstable_cache?.setItem(key, JSON.stringify(result));
51
- return result;
52
- }
53
- }
54
-
55
- Object.defineProperty(exports, "CacheKey", {
56
- enumerable: true,
57
- get: function () { return types.CacheKey; }
58
- });
59
- Object.defineProperty(exports, "PersistKey", {
60
- enumerable: true,
61
- get: function () { return types.PersistKey; }
62
- });
63
- exports.ClientAdapterInstance = ClientAdapterInstance;
@@ -1,24 +0,0 @@
1
- 'use strict';
2
-
3
- exports.PersistKey = void 0;
4
- (function (PersistKey) {
5
- PersistKey["IdToken"] = "idToken";
6
- PersistKey["RefreshToken"] = "refreshToken";
7
- PersistKey["AccessToken"] = "accessToken";
8
- PersistKey["SignInSession"] = "signInSession";
9
- })(exports.PersistKey || (exports.PersistKey = {}));
10
- exports.CacheKey = void 0;
11
- (function (CacheKey) {
12
- /**
13
- * OpenID Configuration endpoint response.
14
- *
15
- * @see {@link https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfigurationResponse | OpenID Connect Discovery 1.0}
16
- */
17
- CacheKey["OpenidConfig"] = "openidConfiguration";
18
- /**
19
- * The content of OpenID Provider's `jwks_uri` (JSON Web Key Set).
20
- *
21
- * @see {@link https://openid.net/specs/openid-connect-discovery-1_0-21.html#ProviderMetadata | OpenID Connect Discovery 1.0}
22
- */
23
- CacheKey["Jwks"] = "jwks";
24
- })(exports.CacheKey || (exports.CacheKey = {}));
package/lib/client.cjs DELETED
@@ -1,383 +0,0 @@
1
- 'use strict';
2
-
3
- var js = require('@logto/js');
4
- var index$1 = require('./adapter/index.cjs');
5
- var errors = require('./errors.cjs');
6
- var index = require('./types/index.cjs');
7
- var index$2 = require('./utils/index.cjs');
8
- var memoize = require('./utils/memoize.cjs');
9
- var once = require('./utils/once.cjs');
10
- var types = require('./adapter/types.cjs');
11
-
12
- /**
13
- * The Logto base client class that provides the essential methods for
14
- * interacting with the Logto server.
15
- *
16
- * It also provides an adapter object that allows the customizations of the
17
- * client behavior for different environments.
18
- *
19
- * NOTE: Usually, you would use the `LogtoClient` class instead of `StandardLogtoClient` since it
20
- * provides the default JWT verifier. However, if you want to avoid the use of `jose` package
21
- * which is useful for certain environments that don't support native modules like `crypto`, you
22
- * can use `StandardLogtoClient` and provide your own JWT verifier.
23
- */
24
- class StandardLogtoClient {
25
- constructor(logtoConfig, adapter, buildJwtVerifier) {
26
- /**
27
- * Get the OIDC configuration from the discovery endpoint. This method will
28
- * only fetch the configuration once and cache the result.
29
- */
30
- this.getOidcConfig = once.once(this.#getOidcConfig);
31
- /**
32
- * Get the access token from the storage with refresh strategy.
33
- *
34
- * - If the access token has expired, it will try to fetch a new one using the Refresh Token.
35
- * - If there's an ongoing Promise to fetch the access token, it will return the Promise.
36
- *
37
- * If you want to get the access token claims, use {@link getAccessTokenClaims} instead.
38
- *
39
- * @param resource The resource that the access token is granted for. If not
40
- * specified, the access token will be used for OpenID Connect or the default
41
- * resource, as specified in the Logto Console.
42
- * @returns The access token string.
43
- * @throws LogtoClientError if the user is not authenticated.
44
- */
45
- this.getAccessToken = memoize.memoize(this.#getAccessToken);
46
- /**
47
- * Get the access token for the specified organization from the storage with refresh strategy.
48
- *
49
- * Scope {@link UserScope.Organizations} is required in the config to use organization-related
50
- * methods.
51
- *
52
- * @param organizationId The ID of the organization that the access token is granted for.
53
- * @returns The access token string.
54
- * @throws LogtoClientError if the user is not authenticated.
55
- * @remarks
56
- * It uses the same refresh strategy as {@link getAccessToken}.
57
- */
58
- this.getOrganizationToken = memoize.memoize(this.#getOrganizationToken);
59
- /**
60
- * Handle the sign-in callback by parsing the authorization code from the
61
- * callback URI and exchanging it for the tokens.
62
- *
63
- * @param callbackUri The callback URI, including the search params, that the user is redirected to after the sign-in flow is completed.
64
- * The origin and pathname of this URI must match the origin and pathname of the redirect URI specified in {@link signIn}.
65
- * In many cases you'll probably end up passing `window.location.href` as the argument to this function.
66
- * @throws LogtoClientError if the sign-in session is not found.
67
- */
68
- this.handleSignInCallback = memoize.memoize(this.#handleSignInCallback);
69
- this.accessTokenMap = new Map();
70
- this.logtoConfig = index.normalizeLogtoConfig(logtoConfig);
71
- this.adapter = new index$1.ClientAdapterInstance(adapter);
72
- this.jwtVerifier = buildJwtVerifier(this);
73
- void this.loadAccessTokenMap();
74
- }
75
- /**
76
- * Check if the user is authenticated by checking if the ID token exists.
77
- */
78
- async isAuthenticated() {
79
- return Boolean(await this.getIdToken());
80
- }
81
- /**
82
- * Get the Refresh Token from the storage.
83
- */
84
- async getRefreshToken() {
85
- return this.adapter.storage.getItem('refreshToken');
86
- }
87
- /**
88
- * Get the ID Token from the storage. If you want to get the ID Token claims,
89
- * use {@link getIdTokenClaims} instead.
90
- */
91
- async getIdToken() {
92
- return this.adapter.storage.getItem('idToken');
93
- }
94
- /**
95
- * Get the ID Token claims.
96
- */
97
- async getIdTokenClaims() {
98
- const idToken = await this.getIdToken();
99
- if (!idToken) {
100
- throw new errors.LogtoClientError('not_authenticated');
101
- }
102
- return js.decodeIdToken(idToken);
103
- }
104
- /**
105
- * Get the access token claims for the specified resource.
106
- *
107
- * @param resource The resource that the access token is granted for. If not
108
- * specified, the access token will be used for OpenID Connect or the default
109
- * resource, as specified in the Logto Console.
110
- */
111
- async getAccessTokenClaims(resource) {
112
- const accessToken = await this.getAccessToken(resource);
113
- return js.decodeAccessToken(accessToken);
114
- }
115
- /**
116
- * Get the organization token claims for the specified organization.
117
- *
118
- * @param organizationId The ID of the organization that the access token is granted for.
119
- */
120
- async getOrganizationTokenClaims(organizationId) {
121
- const accessToken = await this.getOrganizationToken(organizationId);
122
- return js.decodeAccessToken(accessToken);
123
- }
124
- /**
125
- * Get the user information from the Userinfo Endpoint.
126
- *
127
- * Note the Userinfo Endpoint will return more claims than the ID Token. See
128
- * {@link https://docs.logto.io/docs/recipes/integrate-logto/vanilla-js/#fetch-user-information | Fetch user information}
129
- * for more information.
130
- *
131
- * @returns The user information.
132
- * @throws LogtoClientError if the user is not authenticated.
133
- */
134
- async fetchUserInfo() {
135
- const { userinfoEndpoint } = await this.getOidcConfig();
136
- const accessToken = await this.getAccessToken();
137
- if (!accessToken) {
138
- throw new errors.LogtoClientError('fetch_user_info_failed');
139
- }
140
- return js.fetchUserInfo(userinfoEndpoint, accessToken, this.adapter.requester);
141
- }
142
- /**
143
- * Start the sign-in flow with the specified redirect URI. The URI must be
144
- * registered in the Logto Console.
145
- *
146
- * The user will be redirected to that URI after the sign-in flow is completed,
147
- * and the client will be able to get the authorization code from the URI.
148
- * To fetch the tokens from the authorization code, use {@link handleSignInCallback}
149
- * after the user is redirected in the callback URI.
150
- *
151
- * @param redirectUri The redirect URI that the user will be redirected to after the sign-in flow is completed.
152
- * @param interactionMode The interaction mode to be used for the authorization request. Note it's not
153
- * a part of the OIDC standard, but a Logto-specific extension. Defaults to `signIn`.
154
- *
155
- * @see {@link https://docs.logto.io/docs/recipes/integrate-logto/vanilla-js/#sign-in | Sign in} for more information.
156
- * @see {@link InteractionMode}
157
- */
158
- async signIn(redirectUri, interactionMode) {
159
- const { appId: clientId, prompt, resources, scopes } = this.logtoConfig;
160
- const { authorizationEndpoint } = await this.getOidcConfig();
161
- const [codeVerifier, state] = await Promise.all([
162
- this.adapter.generateCodeVerifier(),
163
- this.adapter.generateState(),
164
- ]);
165
- const codeChallenge = await this.adapter.generateCodeChallenge(codeVerifier);
166
- const signInUri = js.generateSignInUri({
167
- authorizationEndpoint,
168
- clientId,
169
- redirectUri,
170
- codeChallenge,
171
- state,
172
- scopes,
173
- resources,
174
- prompt,
175
- interactionMode,
176
- });
177
- await Promise.all([
178
- this.setSignInSession({ redirectUri, codeVerifier, state }),
179
- this.setRefreshToken(null),
180
- this.setIdToken(null),
181
- ]);
182
- await this.adapter.navigate(signInUri, { redirectUri, for: 'sign-in' });
183
- }
184
- /**
185
- * Check if the user is redirected from the sign-in page by checking if the
186
- * current URL matches the redirect URI in the sign-in session.
187
- *
188
- * If there's no sign-in session, it will return `false`.
189
- *
190
- * @param url The current URL.
191
- */
192
- async isSignInRedirected(url) {
193
- const signInSession = await this.getSignInSession();
194
- if (!signInSession) {
195
- return false;
196
- }
197
- const { redirectUri } = signInSession;
198
- const { origin, pathname } = new URL(url);
199
- return `${origin}${pathname}` === redirectUri;
200
- }
201
- /**
202
- * Start the sign-out flow with the specified redirect URI. The URI must be
203
- * registered in the Logto Console.
204
- *
205
- * It will also revoke all the tokens and clean up the storage.
206
- *
207
- * The user will be redirected that URI after the sign-out flow is completed.
208
- * If the `postLogoutRedirectUri` is not specified, the user will be redirected
209
- * to a default page.
210
- */
211
- async signOut(postLogoutRedirectUri) {
212
- const { appId: clientId } = this.logtoConfig;
213
- const { endSessionEndpoint, revocationEndpoint } = await this.getOidcConfig();
214
- const refreshToken = await this.getRefreshToken();
215
- if (refreshToken) {
216
- try {
217
- await js.revoke(revocationEndpoint, clientId, refreshToken, this.adapter.requester);
218
- }
219
- catch {
220
- // Do nothing at this point, as we don't want to break the sign-out flow even if the revocation is failed
221
- }
222
- }
223
- const url = js.generateSignOutUri({
224
- endSessionEndpoint,
225
- postLogoutRedirectUri,
226
- clientId,
227
- });
228
- this.accessTokenMap.clear();
229
- await Promise.all([
230
- this.setRefreshToken(null),
231
- this.setIdToken(null),
232
- this.adapter.storage.removeItem('accessToken'),
233
- ]);
234
- await this.adapter.navigate(url, { redirectUri: postLogoutRedirectUri, for: 'sign-out' });
235
- }
236
- async getSignInSession() {
237
- const jsonItem = await this.adapter.storage.getItem('signInSession');
238
- if (!jsonItem) {
239
- return null;
240
- }
241
- const item = JSON.parse(jsonItem);
242
- if (!index.isLogtoSignInSessionItem(item)) {
243
- throw new errors.LogtoClientError('sign_in_session.invalid');
244
- }
245
- return item;
246
- }
247
- async setSignInSession(value) {
248
- return this.adapter.setStorageItem(types.PersistKey.SignInSession, value && JSON.stringify(value));
249
- }
250
- async setIdToken(value) {
251
- return this.adapter.setStorageItem(types.PersistKey.IdToken, value);
252
- }
253
- async setRefreshToken(value) {
254
- return this.adapter.setStorageItem(types.PersistKey.RefreshToken, value);
255
- }
256
- async getAccessTokenByRefreshToken(resource, organizationId) {
257
- const currentRefreshToken = await this.getRefreshToken();
258
- if (!currentRefreshToken) {
259
- throw new errors.LogtoClientError('not_authenticated');
260
- }
261
- const accessTokenKey = index$2.buildAccessTokenKey(resource, organizationId);
262
- const { appId: clientId } = this.logtoConfig;
263
- const { tokenEndpoint } = await this.getOidcConfig();
264
- const requestedAt = Math.round(Date.now() / 1000);
265
- const { accessToken, refreshToken, idToken, scope, expiresIn } = await js.fetchTokenByRefreshToken({
266
- clientId,
267
- tokenEndpoint,
268
- refreshToken: currentRefreshToken,
269
- resource,
270
- organizationId,
271
- }, this.adapter.requester);
272
- this.accessTokenMap.set(accessTokenKey, {
273
- token: accessToken,
274
- scope,
275
- /** The `expiresAt` variable provides an approximate estimation of the actual `exp` property
276
- * in the token claims. It is utilized by the client to determine if the cached access token
277
- * has expired and when a new access token should be requested.
278
- */
279
- expiresAt: requestedAt + expiresIn,
280
- });
281
- await this.saveAccessTokenMap();
282
- if (refreshToken) {
283
- await this.setRefreshToken(refreshToken);
284
- }
285
- if (idToken) {
286
- await this.jwtVerifier.verifyIdToken(idToken);
287
- await this.setIdToken(idToken);
288
- }
289
- return accessToken;
290
- }
291
- async saveAccessTokenMap() {
292
- const data = {};
293
- for (const [key, accessToken] of this.accessTokenMap.entries()) {
294
- // eslint-disable-next-line @silverhand/fp/no-mutation
295
- data[key] = accessToken;
296
- }
297
- await this.adapter.storage.setItem('accessToken', JSON.stringify(data));
298
- }
299
- async loadAccessTokenMap() {
300
- const raw = await this.adapter.storage.getItem('accessToken');
301
- if (!raw) {
302
- return;
303
- }
304
- try {
305
- const json = JSON.parse(raw);
306
- if (!index.isLogtoAccessTokenMap(json)) {
307
- return;
308
- }
309
- this.accessTokenMap.clear();
310
- for (const [key, accessToken] of Object.entries(json)) {
311
- this.accessTokenMap.set(key, accessToken);
312
- }
313
- }
314
- catch (error) {
315
- console.warn(error);
316
- }
317
- }
318
- async #getOidcConfig() {
319
- return this.adapter.getWithCache(types.CacheKey.OpenidConfig, async () => {
320
- return js.fetchOidcConfig(index$2.getDiscoveryEndpoint(this.logtoConfig.endpoint), this.adapter.requester);
321
- });
322
- }
323
- async #getAccessToken(resource, organizationId) {
324
- if (!(await this.isAuthenticated())) {
325
- throw new errors.LogtoClientError('not_authenticated');
326
- }
327
- const accessTokenKey = index$2.buildAccessTokenKey(resource, organizationId);
328
- const accessToken = this.accessTokenMap.get(accessTokenKey);
329
- if (accessToken && accessToken.expiresAt > Date.now() / 1000) {
330
- return accessToken.token;
331
- }
332
- // Since the access token has expired, delete it from the map.
333
- if (accessToken) {
334
- this.accessTokenMap.delete(accessTokenKey);
335
- }
336
- /**
337
- * Need to fetch a new access token using refresh token.
338
- */
339
- return this.getAccessTokenByRefreshToken(resource, organizationId);
340
- }
341
- async #getOrganizationToken(organizationId) {
342
- if (!this.logtoConfig.scopes?.includes(js.UserScope.Organizations)) {
343
- throw new errors.LogtoClientError('missing_scope_organizations');
344
- }
345
- return this.getAccessToken(undefined, organizationId);
346
- }
347
- async #handleSignInCallback(callbackUri) {
348
- const signInSession = await this.getSignInSession();
349
- if (!signInSession) {
350
- throw new errors.LogtoClientError('sign_in_session.not_found');
351
- }
352
- const { redirectUri, state, codeVerifier } = signInSession;
353
- const code = js.verifyAndParseCodeFromCallbackUri(callbackUri, redirectUri, state);
354
- // NOTE: Will add scope to accessTokenKey when needed. (Linear issue LOG-1589)
355
- const accessTokenKey = index$2.buildAccessTokenKey();
356
- const { appId: clientId } = this.logtoConfig;
357
- const { tokenEndpoint } = await this.getOidcConfig();
358
- const requestedAt = Math.round(Date.now() / 1000);
359
- const { idToken, refreshToken, accessToken, scope, expiresIn } = await js.fetchTokenByAuthorizationCode({
360
- clientId,
361
- tokenEndpoint,
362
- redirectUri,
363
- codeVerifier,
364
- code,
365
- }, this.adapter.requester);
366
- await this.jwtVerifier.verifyIdToken(idToken);
367
- await this.setRefreshToken(refreshToken ?? null);
368
- await this.setIdToken(idToken);
369
- this.accessTokenMap.set(accessTokenKey, {
370
- token: accessToken,
371
- scope,
372
- /** The `expiresAt` variable provides an approximate estimation of the actual `exp` property
373
- * in the token claims. It is utilized by the client to determine if the cached access token
374
- * has expired and when a new access token should be requested.
375
- */
376
- expiresAt: requestedAt + expiresIn,
377
- });
378
- await this.saveAccessTokenMap();
379
- await this.setSignInSession(null);
380
- }
381
- }
382
-
383
- exports.StandardLogtoClient = StandardLogtoClient;
package/lib/errors.cjs DELETED
@@ -1,22 +0,0 @@
1
- 'use strict';
2
-
3
- var js = require('@logto/js');
4
-
5
- const logtoClientErrorCodes = Object.freeze({
6
- 'sign_in_session.invalid': 'Invalid sign-in session.',
7
- 'sign_in_session.not_found': 'Sign-in session not found.',
8
- not_authenticated: 'Not authenticated.',
9
- fetch_user_info_failed: 'Unable to fetch user info. The access token may be invalid.',
10
- user_cancelled: 'The user cancelled the action.',
11
- missing_scope_organizations: `The \`${js.UserScope.Organizations}\` scope is required`,
12
- });
13
- class LogtoClientError extends Error {
14
- constructor(code, data) {
15
- super(logtoClientErrorCodes[code]);
16
- this.name = 'LogtoClientError';
17
- this.code = code;
18
- this.data = data;
19
- }
20
- }
21
-
22
- exports.LogtoClientError = LogtoClientError;