@logto/js 2.1.0 → 2.1.2

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.
@@ -32,9 +32,19 @@ exports.QueryKey = void 0;
32
32
  // Need to align with the OIDC extraParams settings in core
33
33
  QueryKey["InteractionMode"] = "interaction_mode";
34
34
  })(exports.QueryKey || (exports.QueryKey = {}));
35
+ /** The prompt parameter to be used for the authorization request. */
35
36
  exports.Prompt = void 0;
36
37
  (function (Prompt) {
38
+ /**
39
+ * The Authorization Server MUST prompt the End-User for consent
40
+ * before returning information to the Client.
41
+ */
37
42
  Prompt["Consent"] = "consent";
43
+ /**
44
+ * The Authorization Server MUST prompt the End-User for re-authentication,
45
+ * forcing the user to log in again. Note the there'll be no Refresh Token
46
+ * returned in this case.
47
+ */
38
48
  Prompt["Login"] = "login";
39
49
  })(exports.Prompt || (exports.Prompt = {}));
40
50
  // TODO: @sijie @charles find a proper way to sync scopes constants with core
@@ -29,8 +29,18 @@ export declare enum QueryKey {
29
29
  Token = "token",
30
30
  InteractionMode = "interaction_mode"
31
31
  }
32
+ /** The prompt parameter to be used for the authorization request. */
32
33
  export declare enum Prompt {
34
+ /**
35
+ * The Authorization Server MUST prompt the End-User for consent
36
+ * before returning information to the Client.
37
+ */
33
38
  Consent = "consent",
39
+ /**
40
+ * The Authorization Server MUST prompt the End-User for re-authentication,
41
+ * forcing the user to log in again. Note the there'll be no Refresh Token
42
+ * returned in this case.
43
+ */
34
44
  Login = "login"
35
45
  }
36
46
  export declare enum ReservedScope {
@@ -30,9 +30,19 @@ var QueryKey;
30
30
  // Need to align with the OIDC extraParams settings in core
31
31
  QueryKey["InteractionMode"] = "interaction_mode";
32
32
  })(QueryKey || (QueryKey = {}));
33
+ /** The prompt parameter to be used for the authorization request. */
33
34
  var Prompt;
34
35
  (function (Prompt) {
36
+ /**
37
+ * The Authorization Server MUST prompt the End-User for consent
38
+ * before returning information to the Client.
39
+ */
35
40
  Prompt["Consent"] = "consent";
41
+ /**
42
+ * The Authorization Server MUST prompt the End-User for re-authentication,
43
+ * forcing the user to log in again. Note the there'll be no Refresh Token
44
+ * returned in this case.
45
+ */
36
46
  Prompt["Login"] = "login";
37
47
  })(Prompt || (Prompt = {}));
38
48
  // TODO: @sijie @charles find a proper way to sync scopes constants with core
@@ -2,5 +2,16 @@ export type LogtoRequestErrorBody = {
2
2
  code: string;
3
3
  message: string;
4
4
  };
5
+ /**
6
+ * A request function that accepts a `fetch`-like function parameters and returns
7
+ * a promise with the parsed response body.
8
+ */
5
9
  export type Requester = <T>(...args: Parameters<typeof fetch>) => Promise<T>;
10
+ /**
11
+ * The interaction mode to be used for the authorization request. Note it's not
12
+ * a part of the OIDC standard, but a Logto-specific extension.
13
+ *
14
+ * - `signIn`: The authorization request will be initiated with a sign-in page.
15
+ * - `signUp`: The authorization request will be initiated with a sign-up page.
16
+ */
6
17
  export type InteractionMode = 'signIn' | 'signUp';
@@ -2,7 +2,6 @@
2
2
 
3
3
  var essentials = require('@silverhand/essentials');
4
4
  var arbitraryObject = require('./arbitrary-object.cjs');
5
- var errors = require('./errors.cjs');
6
5
 
7
6
  // https://docs.logto.io/docs/recipes/protect-your-api/
8
7
  function assertAccessTokenClaims(data) {
@@ -29,7 +28,8 @@ function assertAccessTokenClaims(data) {
29
28
  const decodeAccessToken = (accessToken) => {
30
29
  const { 1: encodedPayload } = accessToken.split('.');
31
30
  if (!encodedPayload) {
32
- throw new errors.LogtoError('access_token.invalid_token');
31
+ // Non-JWT format token string
32
+ return {};
33
33
  }
34
34
  const json = essentials.urlSafeBase64.decode(encodedPayload);
35
35
  const accessTokenClaims = JSON.parse(json);
@@ -1,6 +1,5 @@
1
1
  import { urlSafeBase64 } from '@silverhand/essentials';
2
2
  import { isArbitraryObject } from './arbitrary-object.js';
3
- import { LogtoError } from './errors.js';
4
3
 
5
4
  // https://docs.logto.io/docs/recipes/protect-your-api/
6
5
  function assertAccessTokenClaims(data) {
@@ -27,7 +26,8 @@ function assertAccessTokenClaims(data) {
27
26
  const decodeAccessToken = (accessToken) => {
28
27
  const { 1: encodedPayload } = accessToken.split('.');
29
28
  if (!encodedPayload) {
30
- throw new LogtoError('access_token.invalid_token');
29
+ // Non-JWT format token string
30
+ return {};
31
31
  }
32
32
  const json = urlSafeBase64.decode(encodedPayload);
33
33
  const accessTokenClaims = JSON.parse(json);
@@ -12,7 +12,6 @@ const logtoErrorCodes = Object.freeze({
12
12
  'callback_uri_verification.missing_code': 'Missing code in the callback URI',
13
13
  crypto_subtle_unavailable: 'Crypto.subtle is unavailable in insecure contexts (non-HTTPS).',
14
14
  unexpected_response_error: 'Unexpected response error from the server.',
15
- 'access_token.invalid_token': 'Invalid access token',
16
15
  });
17
16
  class LogtoError extends Error {
18
17
  constructor(code, data) {
@@ -8,7 +8,6 @@ declare const logtoErrorCodes: Readonly<{
8
8
  'callback_uri_verification.missing_code': "Missing code in the callback URI";
9
9
  crypto_subtle_unavailable: "Crypto.subtle is unavailable in insecure contexts (non-HTTPS).";
10
10
  unexpected_response_error: "Unexpected response error from the server.";
11
- 'access_token.invalid_token': "Invalid access token";
12
11
  }>;
13
12
  export type LogtoErrorCode = keyof typeof logtoErrorCodes;
14
13
  export declare class LogtoError extends Error {
@@ -10,7 +10,6 @@ const logtoErrorCodes = Object.freeze({
10
10
  'callback_uri_verification.missing_code': 'Missing code in the callback URI',
11
11
  crypto_subtle_unavailable: 'Crypto.subtle is unavailable in insecure contexts (non-HTTPS).',
12
12
  unexpected_response_error: 'Unexpected response error from the server.',
13
- 'access_token.invalid_token': 'Invalid access token',
14
13
  });
15
14
  class LogtoError extends Error {
16
15
  constructor(code, data) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logto/js",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "type": "module",
5
5
  "main": "./lib/index.cjs",
6
6
  "module": "./lib/index.js",
@@ -25,19 +25,19 @@
25
25
  "jose": "^4.13.2"
26
26
  },
27
27
  "devDependencies": {
28
- "@silverhand/eslint-config": "^3.0.1",
29
- "@silverhand/ts-config": "^3.0.0",
28
+ "@silverhand/eslint-config": "^4.0.1",
29
+ "@silverhand/ts-config": "^4.0.0",
30
30
  "@swc/core": "^1.3.50",
31
31
  "@swc/jest": "^0.2.24",
32
32
  "@types/jest": "^29.5.1",
33
33
  "@types/node": "^18.0.0",
34
- "eslint": "^8.38.0",
34
+ "eslint": "^8.44.0",
35
35
  "jest": "^29.5.0",
36
36
  "jest-environment-jsdom": "^29.5.0",
37
37
  "jest-matcher-specific-error": "^1.0.0",
38
38
  "lint-staged": "^13.0.0",
39
39
  "nock": "^13.3.0",
40
- "prettier": "^2.8.7",
40
+ "prettier": "^3.0.0",
41
41
  "rollup": "^3.20.2",
42
42
  "text-encoder": "^0.0.4",
43
43
  "type-fest": "^3.0.0",