@logto/client 3.0.3 → 3.1.1

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/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![Build Status](https://github.com/logto-io/js/actions/workflows/main.yml/badge.svg)](https://github.com/logto-io/js/actions/workflows/main.yml)
4
4
  [![Codecov](https://img.shields.io/codecov/c/github/logto-io/js)](https://app.codecov.io/gh/logto-io/js?branch=master)
5
5
 
6
- The Logto JavaScript Client SDK written in TypeScript. Check out our [docs](https://docs.logto.io/sdk/JavaScript/client/) for more information.
6
+ The Logto JavaScript Client SDK written in TypeScript.
7
7
 
8
8
  ## Installation
9
9
 
@@ -42,7 +42,7 @@ To implement a platform-specific SDK, you should implement the following adapter
42
42
  5. generateCodeVerifier: generate code verifier.
43
43
  6. generateCodeChallenge: generate code challenge.
44
44
 
45
- See the [adapters.ts](./src/adapter.ts) for more information.
45
+ See the [adapters](./src/adapter/index.ts) for more information.
46
46
 
47
47
  ## Resources
48
48
 
package/lib/client.d.ts CHANGED
@@ -17,6 +17,10 @@ export type SignInOptions = {
17
17
  * Note: If specified, it will override the prompt value in Logto configs.
18
18
  */
19
19
  prompt?: SignInUriParameters['prompt'];
20
+ /**
21
+ * Clear cached tokens from storage before sign-in. Defaults to: `true`
22
+ */
23
+ clearTokens?: boolean;
20
24
  } & Pick<SignInUriParameters, 'interactionMode' | 'firstScreen' | 'identifiers' | 'loginHint' | 'directSignIn' | 'extraParams'>;
21
25
  /**
22
26
  * The Logto base client class that provides the essential methods for
package/lib/client.js CHANGED
@@ -115,7 +115,7 @@ class StandardLogtoClient {
115
115
  async getIdTokenClaims() {
116
116
  const idToken = await this.getIdToken();
117
117
  if (!idToken) {
118
- throw new LogtoClientError('not_authenticated');
118
+ throw new LogtoClientError('not_authenticated', 'ID token not found');
119
119
  }
120
120
  return decodeIdToken(idToken);
121
121
  }
@@ -158,7 +158,7 @@ class StandardLogtoClient {
158
158
  return fetchUserInfo(userinfoEndpoint, accessToken, this.adapter.requester);
159
159
  }
160
160
  async signIn(options, mode, hint) {
161
- const { redirectUri: redirectUriUrl, postRedirectUri: postRedirectUriUrl, firstScreen, identifiers, interactionMode, loginHint, directSignIn, extraParams, prompt, } = typeof options === 'string' || options instanceof URL
161
+ const { redirectUri: redirectUriUrl, postRedirectUri: postRedirectUriUrl, firstScreen, identifiers, interactionMode, loginHint, directSignIn, extraParams, prompt, clearTokens, } = typeof options === 'string' || options instanceof URL
162
162
  ? {
163
163
  redirectUri: options,
164
164
  postRedirectUri: undefined,
@@ -169,6 +169,7 @@ class StandardLogtoClient {
169
169
  directSignIn: undefined,
170
170
  extraParams: undefined,
171
171
  prompt: undefined,
172
+ clearTokens: true,
172
173
  }
173
174
  : options;
174
175
  const redirectUri = redirectUriUrl.toString();
@@ -198,7 +199,7 @@ class StandardLogtoClient {
198
199
  });
199
200
  await Promise.all([
200
201
  this.setSignInSession({ redirectUri, postRedirectUri, codeVerifier, state }),
201
- this.clearAllTokens(),
202
+ clearTokens === false ? undefined : this.clearAllTokens(),
202
203
  ]);
203
204
  await this.adapter.navigate(signInUri, { redirectUri, for: 'sign-in' });
204
205
  }
@@ -272,7 +273,7 @@ class StandardLogtoClient {
272
273
  async getAccessTokenByRefreshToken(resource, organizationId) {
273
274
  const currentRefreshToken = await this.getRefreshToken();
274
275
  if (!currentRefreshToken) {
275
- throw new LogtoClientError('not_authenticated');
276
+ throw new LogtoClientError('not_authenticated', 'Refresh token not found');
276
277
  }
277
278
  const accessTokenKey = buildAccessTokenKey(resource, organizationId);
278
279
  const { appId: clientId } = this.logtoConfig;
package/lib/mock.d.ts CHANGED
@@ -36,22 +36,22 @@ export declare const accessToken = "access_token_value";
36
36
  export declare const refreshToken = "new_refresh_token_value";
37
37
  export declare const idToken = "id_token_value";
38
38
  export declare const currentUnixTimeStamp: number;
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>;
39
+ export declare const mockFetchOidcConfig: (delay?: number) => Mock<() => Promise<OidcConfigResponse>>;
40
+ export declare const fetchOidcConfig: Mock<() => Promise<OidcConfigResponse>>;
41
+ export declare const requester: Mock<(...args: any[]) => any>;
42
+ export declare const failingRequester: Mock<(...args: any[]) => any>;
43
+ export declare const navigate: Mock<(...args: any[]) => any>;
44
+ export declare const generateCodeChallenge: Mock<() => Promise<string>>;
45
+ export declare const generateCodeVerifier: Mock<() => string>;
46
+ export declare const generateState: Mock<() => string>;
47
47
  export declare const createAdapters: (withCache?: boolean) => {
48
- requester: Mock<any, any>;
48
+ requester: Mock<(...args: any[]) => any>;
49
49
  storage: MockedStorage;
50
50
  unstable_cache: import("@silverhand/essentials").Optional<MockedStorage>;
51
- navigate: Mock<any, any>;
52
- generateCodeChallenge: Mock<[], Promise<string>>;
53
- generateCodeVerifier: Mock<[], string>;
54
- generateState: Mock<[], string>;
51
+ navigate: Mock<(...args: any[]) => any>;
52
+ generateCodeChallenge: Mock<() => Promise<string>>;
53
+ generateCodeVerifier: Mock<() => string>;
54
+ generateState: Mock<() => string>;
55
55
  };
56
56
  export declare const createClient: (prompt?: Prompt, storage?: MockedStorage, withCache?: boolean, scopes?: string[]) => LogtoClientWithAccessors;
57
57
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logto/client",
3
- "version": "3.0.3",
3
+ "version": "3.1.1",
4
4
  "type": "module",
5
5
  "module": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -24,20 +24,20 @@
24
24
  "@silverhand/essentials": "^2.9.2",
25
25
  "camelcase-keys": "^9.1.3",
26
26
  "jose": "^5.2.2",
27
- "@logto/js": "^5.0.2"
27
+ "@logto/js": "^5.1.0"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@silverhand/eslint-config": "^6.0.1",
31
31
  "@silverhand/ts-config": "^6.0.0",
32
32
  "@types/node": "^22.0.0",
33
- "@vitest/coverage-v8": "^1.6.0",
33
+ "@vitest/coverage-v8": "^2.1.9",
34
34
  "eslint": "^8.57.0",
35
- "happy-dom": "^15.10.2",
35
+ "happy-dom": "^16.0.0",
36
36
  "lint-staged": "^15.0.0",
37
37
  "nock": "14.0.0-beta.19",
38
38
  "prettier": "^3.0.0",
39
39
  "typescript": "^5.3.3",
40
- "vitest": "^1.6.0"
40
+ "vitest": "^2.1.9"
41
41
  },
42
42
  "eslintConfig": {
43
43
  "extends": "@silverhand"