@logto/js 4.1.2 → 4.1.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/lib/index.cjs +1 -0
- package/lib/index.js +1 -1
- package/lib/utils/errors.cjs +14 -1
- package/lib/utils/errors.d.ts +11 -3
- package/lib/utils/errors.js +14 -2
- package/package.json +1 -1
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';
|
package/lib/utils/errors.cjs
CHANGED
|
@@ -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;
|
package/lib/utils/errors.d.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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 {};
|
package/lib/utils/errors.js
CHANGED
|
@@ -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 };
|