@logto/client 2.6.6 → 2.6.8

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.
@@ -17,9 +17,7 @@ class DefaultJwtVerifier {
17
17
  async verifyIdToken(idToken) {
18
18
  const { appId } = this.client.logtoConfig;
19
19
  const { issuer, jwksUri } = await this.client.getOidcConfig();
20
- if (!this.getJwtVerifyGetKey) {
21
- this.getJwtVerifyGetKey = jose.createRemoteJWKSet(new URL(jwksUri));
22
- }
20
+ this.getJwtVerifyGetKey ||= jose.createRemoteJWKSet(new URL(jwksUri));
23
21
  await verifyIdToken(idToken, appId, issuer, this.getJwtVerifyGetKey);
24
22
  }
25
23
  }
@@ -15,9 +15,7 @@ class DefaultJwtVerifier {
15
15
  async verifyIdToken(idToken) {
16
16
  const { appId } = this.client.logtoConfig;
17
17
  const { issuer, jwksUri } = await this.client.getOidcConfig();
18
- if (!this.getJwtVerifyGetKey) {
19
- this.getJwtVerifyGetKey = createRemoteJWKSet(new URL(jwksUri));
20
- }
18
+ this.getJwtVerifyGetKey ||= createRemoteJWKSet(new URL(jwksUri));
21
19
  await verifyIdToken(idToken, appId, issuer, this.getJwtVerifyGetKey);
22
20
  }
23
21
  }
package/lib/mock.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- /// <reference types="jest" />
2
1
  import { type OidcConfigResponse, Prompt } from '@logto/js';
3
2
  import { type Nullable } from '@silverhand/essentials';
3
+ import nock from 'nock';
4
+ import { type Mock } from 'vitest';
4
5
  import type { Storage } from './adapter/index.js';
5
6
  import type { AccessToken, LogtoConfig, LogtoSignInSessionItem } from './index.js';
6
7
  import LogtoClient from './index.js';
@@ -35,38 +36,22 @@ export declare const accessToken = "access_token_value";
35
36
  export declare const refreshToken = "new_refresh_token_value";
36
37
  export declare const idToken = "id_token_value";
37
38
  export declare const currentUnixTimeStamp: number;
38
- export declare const mockFetchOidcConfig: (delay?: number) => jest.Mock<Promise<{
39
- authorizationEndpoint: string;
40
- tokenEndpoint: string;
41
- userinfoEndpoint: string;
42
- endSessionEndpoint: string;
43
- revocationEndpoint: string;
44
- jwksUri: string;
45
- issuer: string;
46
- }>, [], any>;
47
- export declare const fetchOidcConfig: jest.Mock<Promise<{
48
- authorizationEndpoint: string;
49
- tokenEndpoint: string;
50
- userinfoEndpoint: string;
51
- endSessionEndpoint: string;
52
- revocationEndpoint: string;
53
- jwksUri: string;
54
- issuer: string;
55
- }>, [], any>;
56
- export declare const requester: jest.Mock<any, any, any>;
57
- export declare const failingRequester: jest.Mock<any, any, any>;
58
- export declare const navigate: jest.Mock<any, any, any>;
59
- export declare const generateCodeChallenge: jest.Mock<Promise<string>, [], any>;
60
- export declare const generateCodeVerifier: jest.Mock<string, [], any>;
61
- export declare const generateState: jest.Mock<string, [], any>;
39
+ export declare const mockFetchOidcConfig: (delay?: number) => Mock<unknown[], Promise<OidcConfigResponse>>;
40
+ export declare const fetchOidcConfig: Mock<unknown[], Promise<OidcConfigResponse>>;
41
+ export declare const requester: Mock<any, any>;
42
+ export declare const failingRequester: Mock<any, any>;
43
+ export declare const navigate: Mock<any, any>;
44
+ export declare const generateCodeChallenge: Mock<[], Promise<string>>;
45
+ export declare const generateCodeVerifier: Mock<[], string>;
46
+ export declare const generateState: Mock<[], string>;
62
47
  export declare const createAdapters: (withCache?: boolean) => {
63
- requester: jest.Mock<any, any, any>;
48
+ requester: Mock<any, any>;
64
49
  storage: MockedStorage;
65
50
  unstable_cache: import("@silverhand/essentials").Optional<MockedStorage>;
66
- navigate: jest.Mock<any, any, any>;
67
- generateCodeChallenge: jest.Mock<Promise<string>, [], any>;
68
- generateCodeVerifier: jest.Mock<string, [], any>;
69
- generateState: jest.Mock<string, [], any>;
51
+ navigate: Mock<any, any>;
52
+ generateCodeChallenge: Mock<[], Promise<string>>;
53
+ generateCodeVerifier: Mock<[], string>;
54
+ generateState: Mock<[], string>;
70
55
  };
71
56
  export declare const createClient: (prompt?: Prompt, storage?: MockedStorage, withCache?: boolean, scopes?: string[]) => LogtoClientWithAccessors;
72
57
  /**
@@ -79,3 +64,4 @@ export declare class LogtoClientWithAccessors extends LogtoClient {
79
64
  setSignInSessionItem(item: Nullable<LogtoSignInSessionItem>): Promise<void>;
80
65
  getAccessTokenMap(): Map<string, AccessToken>;
81
66
  }
67
+ export declare const nocked: nock.Scope;
@@ -6,18 +6,21 @@ var essentials = require('@silverhand/essentials');
6
6
  /**
7
7
  * Normalize the Logto client configuration per the following rules:
8
8
  *
9
- * - Add default scopes (`openid`, `offline_access` and `profile`) if not provided.
10
- * - Add {@link ReservedResource.Organization} to resources if {@link UserScope.Organizations} is included in scopes.
9
+ * - Add default scopes (`openid`, `offline_access` and `profile`) if not provided and
10
+ * `includeReservedScopes` is `true`.
11
+ * - Add {@link ReservedResource.Organization} to resources if {@link UserScope.Organizations} is
12
+ * included in scopes.
11
13
  *
12
14
  * @param config The Logto client configuration to be normalized.
13
15
  * @returns The normalized Logto client configuration.
14
16
  */
15
17
  const normalizeLogtoConfig = (config) => {
16
18
  const { prompt = js.Prompt.Consent, scopes = [], resources, ...rest } = config;
19
+ const includeReservedScopes = config.includeReservedScopes ?? true;
17
20
  return {
18
21
  ...rest,
19
22
  prompt,
20
- scopes: js.withDefaultScopes(scopes).split(' '),
23
+ scopes: includeReservedScopes ? js.withReservedScopes(scopes).split(' ') : scopes,
21
24
  resources: scopes.includes(js.UserScope.Organizations)
22
25
  ? essentials.deduplicate([...(resources ?? []), js.ReservedResource.Organization])
23
26
  : resources,
@@ -39,12 +39,20 @@ export type LogtoConfig = {
39
39
  * The prompt parameter to be used for the authorization request.
40
40
  */
41
41
  prompt?: Prompt | Prompt[];
42
+ /**
43
+ * Whether to include reserved scopes (`openid`, `offline_access` and `profile`) in the scopes.
44
+ *
45
+ * @default true
46
+ */
47
+ includeReservedScopes?: boolean;
42
48
  };
43
49
  /**
44
50
  * Normalize the Logto client configuration per the following rules:
45
51
  *
46
- * - Add default scopes (`openid`, `offline_access` and `profile`) if not provided.
47
- * - Add {@link ReservedResource.Organization} to resources if {@link UserScope.Organizations} is included in scopes.
52
+ * - Add default scopes (`openid`, `offline_access` and `profile`) if not provided and
53
+ * `includeReservedScopes` is `true`.
54
+ * - Add {@link ReservedResource.Organization} to resources if {@link UserScope.Organizations} is
55
+ * included in scopes.
48
56
  *
49
57
  * @param config The Logto client configuration to be normalized.
50
58
  * @returns The normalized Logto client configuration.
@@ -1,21 +1,24 @@
1
- import { Prompt, withDefaultScopes, UserScope, ReservedResource, isArbitraryObject } from '@logto/js';
1
+ import { Prompt, withReservedScopes, UserScope, ReservedResource, isArbitraryObject } from '@logto/js';
2
2
  import { deduplicate } from '@silverhand/essentials';
3
3
 
4
4
  /**
5
5
  * Normalize the Logto client configuration per the following rules:
6
6
  *
7
- * - Add default scopes (`openid`, `offline_access` and `profile`) if not provided.
8
- * - Add {@link ReservedResource.Organization} to resources if {@link UserScope.Organizations} is included in scopes.
7
+ * - Add default scopes (`openid`, `offline_access` and `profile`) if not provided and
8
+ * `includeReservedScopes` is `true`.
9
+ * - Add {@link ReservedResource.Organization} to resources if {@link UserScope.Organizations} is
10
+ * included in scopes.
9
11
  *
10
12
  * @param config The Logto client configuration to be normalized.
11
13
  * @returns The normalized Logto client configuration.
12
14
  */
13
15
  const normalizeLogtoConfig = (config) => {
14
16
  const { prompt = Prompt.Consent, scopes = [], resources, ...rest } = config;
17
+ const includeReservedScopes = config.includeReservedScopes ?? true;
15
18
  return {
16
19
  ...rest,
17
20
  prompt,
18
- scopes: withDefaultScopes(scopes).split(' '),
21
+ scopes: includeReservedScopes ? withReservedScopes(scopes).split(' ') : scopes,
19
22
  resources: scopes.includes(UserScope.Organizations)
20
23
  ? deduplicate([...(resources ?? []), ReservedResource.Organization])
21
24
  : resources,
@@ -3,7 +3,7 @@
3
3
  function memoize(run) {
4
4
  const promiseCache = new Map();
5
5
  const memoized = async function (...args) {
6
- const promiseKey = args[0];
6
+ const promiseKey = JSON.stringify(args);
7
7
  const cachedPromise = promiseCache.get(promiseKey);
8
8
  if (cachedPromise) {
9
9
  return cachedPromise;
@@ -1,7 +1,7 @@
1
1
  function memoize(run) {
2
2
  const promiseCache = new Map();
3
3
  const memoized = async function (...args) {
4
- const promiseKey = args[0];
4
+ const promiseKey = JSON.stringify(args);
5
5
  const cachedPromise = promiseCache.get(promiseKey);
6
6
  if (cachedPromise) {
7
7
  return cachedPromise;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logto/client",
3
- "version": "2.6.6",
3
+ "version": "2.6.8",
4
4
  "type": "module",
5
5
  "main": "./lib/index.cjs",
6
6
  "module": "./lib/index.js",
@@ -32,25 +32,20 @@
32
32
  "@silverhand/essentials": "^2.8.7",
33
33
  "camelcase-keys": "^7.0.1",
34
34
  "jose": "^5.2.2",
35
- "@logto/js": "^4.1.1"
35
+ "@logto/js": "^4.1.2"
36
36
  },
37
37
  "devDependencies": {
38
- "@peculiar/webcrypto": "^1.4.5",
39
- "@silverhand/eslint-config": "^5.0.0",
40
- "@silverhand/ts-config": "^5.0.0",
41
- "@swc/core": "^1.3.50",
42
- "@swc/jest": "^0.2.24",
43
- "@types/jest": "^29.5.0",
38
+ "@silverhand/eslint-config": "^6.0.1",
39
+ "@silverhand/ts-config": "^6.0.0",
44
40
  "@types/node": "^20.11.19",
41
+ "@vitest/coverage-v8": "^1.4.0",
45
42
  "eslint": "^8.57.0",
46
- "jest": "^29.5.0",
47
- "jest-matcher-specific-error": "^1.0.0",
43
+ "happy-dom": "^14.0.0",
48
44
  "lint-staged": "^15.0.0",
49
- "nock": "^13.3.0",
45
+ "nock": "14.0.0-beta.5",
50
46
  "prettier": "^3.0.0",
51
- "text-encoder": "^0.0.4",
52
- "type-fest": "^4.0.0",
53
- "typescript": "^5.3.3"
47
+ "typescript": "^5.3.3",
48
+ "vitest": "^1.4.0"
54
49
  },
55
50
  "eslintConfig": {
56
51
  "extends": "@silverhand"
@@ -65,7 +60,8 @@
65
60
  "check": "tsc --noEmit",
66
61
  "build": "rm -rf lib/ && tsc -p tsconfig.build.json --noEmit && rollup -c",
67
62
  "lint": "eslint --ext .ts src",
68
- "test": "jest",
69
- "test:coverage": "jest --silent --env=jsdom && jest --silent --coverage"
63
+ "test": "vitest",
64
+ "test:dom": "vitest --config=vitest.config.dom.ts",
65
+ "test:coverage": "pnpm test:dom --silent --no-watch && pnpm run test --no-watch --silent --coverage"
70
66
  }
71
67
  }