@logto/js 4.1.2 → 4.1.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.
@@ -1,11 +1,10 @@
1
1
  import { Prompt } from '../consts/index.js';
2
2
  import type { FirstScreen, InteractionMode } from '../types/index.js';
3
- /** @experimental Don't use this type as it's under development. */
4
3
  export type DirectSignInOptions = {
5
4
  /**
6
5
  * The method to be used for the direct sign-in.
7
6
  */
8
- method: 'social';
7
+ method: 'social' | 'sso';
9
8
  /**
10
9
  * The target to be used for the direct sign-in.
11
10
  *
@@ -24,8 +23,6 @@ export type SignInUriParameters = {
24
23
  prompt?: Prompt | Prompt[];
25
24
  /**
26
25
  * The first screen to be shown in the sign-in experience.
27
- *
28
- * @experimental Don't use this field as it's under development.
29
26
  */
30
27
  firstScreen?: FirstScreen;
31
28
  /** The first screen to be shown in the sign-in experience. */
@@ -39,7 +36,7 @@ export type SignInUriParameters = {
39
36
  /**
40
37
  * Parameters for direct sign-in.
41
38
  *
42
- * @experimental Don't use this field as it's under development.
39
+ * @see {@link https://docs.logto.io/docs/references/openid-connect/authentication-parameters/#direct-sign-in Direct sign-in} for more information.
43
40
  */
44
41
  directSignIn?: DirectSignInOptions;
45
42
  /**
package/lib/index.cjs CHANGED
@@ -32,6 +32,7 @@ exports.LogtoError = errors.LogtoError;
32
32
  exports.LogtoRequestError = errors.LogtoRequestError;
33
33
  exports.OidcError = errors.OidcError;
34
34
  exports.isLogtoRequestError = errors.isLogtoRequestError;
35
+ exports.isLogtoRequestErrorJson = errors.isLogtoRequestErrorJson;
35
36
  exports.decodeIdToken = idToken.decodeIdToken;
36
37
  exports.decodeAccessToken = accessToken.decodeAccessToken;
37
38
  exports.withDefaultScopes = scopes.withDefaultScopes;
package/lib/index.js CHANGED
@@ -5,7 +5,7 @@ export { generateSignInUri } from './core/sign-in.js';
5
5
  export { generateSignOutUri } from './core/sign-out.js';
6
6
  export { fetchUserInfo } from './core/user-info.js';
7
7
  export { parseUriParameters, verifyAndParseCodeFromCallbackUri } from './utils/callback-uri.js';
8
- export { LogtoError, LogtoRequestError, OidcError, isLogtoRequestError } from './utils/errors.js';
8
+ export { LogtoError, LogtoRequestError, OidcError, isLogtoRequestError, isLogtoRequestErrorJson } from './utils/errors.js';
9
9
  export { decodeIdToken } from './utils/id-token.js';
10
10
  export { decodeAccessToken } from './utils/access-token.js';
11
11
  export { withDefaultScopes, withReservedScopes } from './utils/scopes.js';
@@ -18,24 +18,36 @@ class LogtoError extends Error {
18
18
  super(logtoErrorCodes[code]);
19
19
  this.code = code;
20
20
  this.data = data;
21
+ this.name = 'LogtoError';
21
22
  }
22
23
  }
23
24
  const isLogtoRequestError = (data) => {
25
+ if (!arbitraryObject.isArbitraryObject(data)) {
26
+ return false;
27
+ }
28
+ return data instanceof Error && data.name === 'LogtoRequestError';
29
+ };
30
+ const isLogtoRequestErrorJson = (data) => {
24
31
  if (!arbitraryObject.isArbitraryObject(data)) {
25
32
  return false;
26
33
  }
27
34
  return typeof data.code === 'string' && typeof data.message === 'string';
28
35
  };
29
36
  class LogtoRequestError extends Error {
30
- constructor(code, message) {
37
+ constructor(code, message,
38
+ /** The original response object from the server. */
39
+ cause) {
31
40
  super(message);
32
41
  this.code = code;
42
+ this.cause = cause;
43
+ this.name = 'LogtoRequestError';
33
44
  }
34
45
  }
35
46
  class OidcError {
36
47
  constructor(error, errorDescription) {
37
48
  this.error = error;
38
49
  this.errorDescription = errorDescription;
50
+ this.name = 'OidcError';
39
51
  }
40
52
  }
41
53
 
@@ -43,3 +55,4 @@ exports.LogtoError = LogtoError;
43
55
  exports.LogtoRequestError = LogtoRequestError;
44
56
  exports.OidcError = OidcError;
45
57
  exports.isLogtoRequestError = isLogtoRequestError;
58
+ exports.isLogtoRequestErrorJson = isLogtoRequestErrorJson;
@@ -12,20 +12,28 @@ declare const logtoErrorCodes: Readonly<{
12
12
  export type LogtoErrorCode = keyof typeof logtoErrorCodes;
13
13
  export declare class LogtoError extends Error {
14
14
  code: LogtoErrorCode;
15
- data: unknown;
15
+ data?: unknown;
16
+ name: string;
16
17
  constructor(code: LogtoErrorCode, data?: unknown);
17
18
  }
18
- export declare const isLogtoRequestError: (data: unknown) => data is {
19
+ export declare const isLogtoRequestError: (data: unknown) => data is LogtoRequestError;
20
+ export declare const isLogtoRequestErrorJson: (data: unknown) => data is {
19
21
  code: string;
20
22
  message: string;
21
23
  };
22
24
  export declare class LogtoRequestError extends Error {
23
25
  code: string;
24
- constructor(code: string, message: string);
26
+ /** The original response object from the server. */
27
+ cause?: Response | undefined;
28
+ name: string;
29
+ constructor(code: string, message: string,
30
+ /** The original response object from the server. */
31
+ cause?: Response | undefined);
25
32
  }
26
33
  export declare class OidcError {
27
34
  error: string;
28
35
  errorDescription?: string | undefined;
36
+ name: string;
29
37
  constructor(error: string, errorDescription?: string | undefined);
30
38
  }
31
39
  export {};
@@ -16,25 +16,37 @@ class LogtoError extends Error {
16
16
  super(logtoErrorCodes[code]);
17
17
  this.code = code;
18
18
  this.data = data;
19
+ this.name = 'LogtoError';
19
20
  }
20
21
  }
21
22
  const isLogtoRequestError = (data) => {
23
+ if (!isArbitraryObject(data)) {
24
+ return false;
25
+ }
26
+ return data instanceof Error && data.name === 'LogtoRequestError';
27
+ };
28
+ const isLogtoRequestErrorJson = (data) => {
22
29
  if (!isArbitraryObject(data)) {
23
30
  return false;
24
31
  }
25
32
  return typeof data.code === 'string' && typeof data.message === 'string';
26
33
  };
27
34
  class LogtoRequestError extends Error {
28
- constructor(code, message) {
35
+ constructor(code, message,
36
+ /** The original response object from the server. */
37
+ cause) {
29
38
  super(message);
30
39
  this.code = code;
40
+ this.cause = cause;
41
+ this.name = 'LogtoRequestError';
31
42
  }
32
43
  }
33
44
  class OidcError {
34
45
  constructor(error, errorDescription) {
35
46
  this.error = error;
36
47
  this.errorDescription = errorDescription;
48
+ this.name = 'OidcError';
37
49
  }
38
50
  }
39
51
 
40
- export { LogtoError, LogtoRequestError, OidcError, isLogtoRequestError };
52
+ export { LogtoError, LogtoRequestError, OidcError, isLogtoRequestError, isLogtoRequestErrorJson };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logto/js",
3
- "version": "4.1.2",
3
+ "version": "4.1.4",
4
4
  "type": "module",
5
5
  "main": "./lib/index.cjs",
6
6
  "module": "./lib/index.js",
@@ -27,7 +27,7 @@
27
27
  "@silverhand/eslint-config": "^6.0.1",
28
28
  "@silverhand/ts-config": "^6.0.0",
29
29
  "@types/node": "^20.11.19",
30
- "@vitest/coverage-v8": "^1.4.0",
30
+ "@vitest/coverage-v8": "^1.6.0",
31
31
  "angular-auth-oidc-client": "^17.0.0",
32
32
  "eslint": "^8.57.0",
33
33
  "happy-dom": "^14.0.0",
@@ -36,7 +36,7 @@
36
36
  "prettier": "^3.0.0",
37
37
  "rollup": "^4.0.0",
38
38
  "typescript": "^5.3.3",
39
- "vitest": "^1.4.0"
39
+ "vitest": "^1.6.0"
40
40
  },
41
41
  "eslintConfig": {
42
42
  "extends": "@silverhand"