@logto/capacitor 1.1.1 → 1.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 CHANGED
@@ -44,38 +44,10 @@ class CapacitorLogtoClient extends LogtoBaseClient__default.default {
44
44
  },
45
45
  };
46
46
  }
47
- /**
48
- * Start the sign-in flow with the specified redirect URI. The URI must be
49
- * registered in the Logto Console.
50
- *
51
- * Remember to configure the correct [scheme or universal links](https://capacitorjs.com/docs/guides/deep-links)
52
- * to ensure the app can be opened from the redirect URI.
53
- *
54
- * @param redirectUri The redirect URI that the user will be redirected to after the sign-in flow is completed.
55
- * @param interactionMode The interaction mode to be used for the authorization request. Note it's not
56
- * a part of the OIDC standard, but a Logto-specific extension. Defaults to `signIn`.
57
- * @throws {@link LogtoClientError} If error happens during the sign-in flow or the user cancels the sign-in.
58
- *
59
- * @example
60
- * ```ts
61
- * const client = new CapacitorLogtoClient({
62
- * endpoint: 'https://your.logto.endpoint',
63
- * appId: 'your-app-id',
64
- * });
65
- *
66
- * await client.signIn('io.logto.example://callback'); // throws if error happens
67
- * console.log(await client.getIdTokenClaims()); // { sub: '123', ... }
68
- * ```
69
- *
70
- * @remarks
71
- * The user will be redirected to that URI after the sign-in flow is completed,
72
- * and the client will be able to get the authorization code from the URI.
73
- * {@link handleSignInCallback} will be called after the user is redirected.
74
- *
75
- * @see {@link https://docs.logto.io/docs/recipes/integrate-logto/vanilla-js/#sign-in | Sign in} for more information.
76
- * @see {@link InteractionMode}
77
- */
78
47
  async signIn(redirectUri, interactionMode) {
48
+ if (typeof redirectUri === 'object' && !(redirectUri instanceof URL)) {
49
+ throw new TypeError('The first argument must be a string or a URL.');
50
+ }
79
51
  return new Promise((resolve, reject) => {
80
52
  const run = async () => {
81
53
  const [browserHandle, appHandle] = await Promise.all([
@@ -87,7 +59,7 @@ class CapacitorLogtoClient extends LogtoBaseClient__default.default {
87
59
  // Handle the case where the user completes the sign-in and is redirected
88
60
  // back to the app.
89
61
  app.App.addListener('appUrlOpen', async ({ url }) => {
90
- if (!url.startsWith(redirectUri)) {
62
+ if (!url.startsWith(redirectUri.toString())) {
91
63
  return;
92
64
  }
93
65
  await Promise.all([
@@ -152,51 +124,51 @@ class CapacitorLogtoClient extends LogtoBaseClient__default.default {
152
124
  }
153
125
  }
154
126
 
155
- Object.defineProperty(exports, 'LogtoClientError', {
127
+ Object.defineProperty(exports, "LogtoClientError", {
156
128
  enumerable: true,
157
129
  get: function () { return LogtoBaseClient.LogtoClientError; }
158
130
  });
159
- Object.defineProperty(exports, 'LogtoError', {
131
+ Object.defineProperty(exports, "LogtoError", {
160
132
  enumerable: true,
161
133
  get: function () { return LogtoBaseClient.LogtoError; }
162
134
  });
163
- Object.defineProperty(exports, 'LogtoRequestError', {
135
+ Object.defineProperty(exports, "LogtoRequestError", {
164
136
  enumerable: true,
165
137
  get: function () { return LogtoBaseClient.LogtoRequestError; }
166
138
  });
167
- Object.defineProperty(exports, 'OidcError', {
139
+ Object.defineProperty(exports, "OidcError", {
168
140
  enumerable: true,
169
141
  get: function () { return LogtoBaseClient.OidcError; }
170
142
  });
171
- Object.defineProperty(exports, 'PersistKey', {
143
+ Object.defineProperty(exports, "PersistKey", {
172
144
  enumerable: true,
173
145
  get: function () { return LogtoBaseClient.PersistKey; }
174
146
  });
175
- Object.defineProperty(exports, 'Prompt', {
147
+ Object.defineProperty(exports, "Prompt", {
176
148
  enumerable: true,
177
149
  get: function () { return LogtoBaseClient.Prompt; }
178
150
  });
179
- Object.defineProperty(exports, 'ReservedResource', {
151
+ Object.defineProperty(exports, "ReservedResource", {
180
152
  enumerable: true,
181
153
  get: function () { return LogtoBaseClient.ReservedResource; }
182
154
  });
183
- Object.defineProperty(exports, 'ReservedScope', {
155
+ Object.defineProperty(exports, "ReservedScope", {
184
156
  enumerable: true,
185
157
  get: function () { return LogtoBaseClient.ReservedScope; }
186
158
  });
187
- Object.defineProperty(exports, 'UserScope', {
159
+ Object.defineProperty(exports, "UserScope", {
188
160
  enumerable: true,
189
161
  get: function () { return LogtoBaseClient.UserScope; }
190
162
  });
191
- Object.defineProperty(exports, 'buildOrganizationUrn', {
163
+ Object.defineProperty(exports, "buildOrganizationUrn", {
192
164
  enumerable: true,
193
165
  get: function () { return LogtoBaseClient.buildOrganizationUrn; }
194
166
  });
195
- Object.defineProperty(exports, 'getOrganizationIdFromUrn', {
167
+ Object.defineProperty(exports, "getOrganizationIdFromUrn", {
196
168
  enumerable: true,
197
169
  get: function () { return LogtoBaseClient.getOrganizationIdFromUrn; }
198
170
  });
199
- Object.defineProperty(exports, 'organizationUrnPrefix', {
171
+ Object.defineProperty(exports, "organizationUrnPrefix", {
200
172
  enumerable: true,
201
173
  get: function () { return LogtoBaseClient.organizationUrnPrefix; }
202
174
  });
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type OpenOptions } from '@capacitor/browser';
2
- import LogtoBaseClient, { type InteractionMode, type LogtoConfig } from '@logto/browser';
2
+ import LogtoBaseClient, { type InteractionMode, type LogtoConfig, type SignInOptions } from '@logto/browser';
3
3
  export { LogtoError, LogtoRequestError, LogtoClientError, OidcError, Prompt, ReservedScope, ReservedResource, UserScope, organizationUrnPrefix, buildOrganizationUrn, getOrganizationIdFromUrn, PersistKey, } from '@logto/browser';
4
4
  export type CapacitorConfig = {
5
5
  /**
@@ -10,6 +10,10 @@ export type CapacitorConfig = {
10
10
  };
11
11
  export default class CapacitorLogtoClient extends LogtoBaseClient {
12
12
  constructor(config: LogtoConfig, capacitorConfig?: CapacitorConfig);
13
+ /**
14
+ * **NOTE: Capacitor does not support this method signature, use the other overloads.**
15
+ */
16
+ signIn(options: SignInOptions): Promise<void>;
13
17
  /**
14
18
  * Start the sign-in flow with the specified redirect URI. The URI must be
15
19
  * registered in the Logto Console.
@@ -20,7 +24,7 @@ export default class CapacitorLogtoClient extends LogtoBaseClient {
20
24
  * @param redirectUri The redirect URI that the user will be redirected to after the sign-in flow is completed.
21
25
  * @param interactionMode The interaction mode to be used for the authorization request. Note it's not
22
26
  * a part of the OIDC standard, but a Logto-specific extension. Defaults to `signIn`.
23
- * @throws {@link LogtoClientError} If error happens during the sign-in flow or the user cancels the sign-in.
27
+ * @throws `LogtoClientError` If error happens during the sign-in flow or the user cancels the sign-in.
24
28
  *
25
29
  * @example
26
30
  * ```ts
package/lib/index.js CHANGED
@@ -37,38 +37,10 @@ class CapacitorLogtoClient extends LogtoBaseClient {
37
37
  },
38
38
  };
39
39
  }
40
- /**
41
- * Start the sign-in flow with the specified redirect URI. The URI must be
42
- * registered in the Logto Console.
43
- *
44
- * Remember to configure the correct [scheme or universal links](https://capacitorjs.com/docs/guides/deep-links)
45
- * to ensure the app can be opened from the redirect URI.
46
- *
47
- * @param redirectUri The redirect URI that the user will be redirected to after the sign-in flow is completed.
48
- * @param interactionMode The interaction mode to be used for the authorization request. Note it's not
49
- * a part of the OIDC standard, but a Logto-specific extension. Defaults to `signIn`.
50
- * @throws {@link LogtoClientError} If error happens during the sign-in flow or the user cancels the sign-in.
51
- *
52
- * @example
53
- * ```ts
54
- * const client = new CapacitorLogtoClient({
55
- * endpoint: 'https://your.logto.endpoint',
56
- * appId: 'your-app-id',
57
- * });
58
- *
59
- * await client.signIn('io.logto.example://callback'); // throws if error happens
60
- * console.log(await client.getIdTokenClaims()); // { sub: '123', ... }
61
- * ```
62
- *
63
- * @remarks
64
- * The user will be redirected to that URI after the sign-in flow is completed,
65
- * and the client will be able to get the authorization code from the URI.
66
- * {@link handleSignInCallback} will be called after the user is redirected.
67
- *
68
- * @see {@link https://docs.logto.io/docs/recipes/integrate-logto/vanilla-js/#sign-in | Sign in} for more information.
69
- * @see {@link InteractionMode}
70
- */
71
40
  async signIn(redirectUri, interactionMode) {
41
+ if (typeof redirectUri === 'object' && !(redirectUri instanceof URL)) {
42
+ throw new TypeError('The first argument must be a string or a URL.');
43
+ }
72
44
  return new Promise((resolve, reject) => {
73
45
  const run = async () => {
74
46
  const [browserHandle, appHandle] = await Promise.all([
@@ -80,7 +52,7 @@ class CapacitorLogtoClient extends LogtoBaseClient {
80
52
  // Handle the case where the user completes the sign-in and is redirected
81
53
  // back to the app.
82
54
  App.addListener('appUrlOpen', async ({ url }) => {
83
- if (!url.startsWith(redirectUri)) {
55
+ if (!url.startsWith(redirectUri.toString())) {
84
56
  return;
85
57
  }
86
58
  await Promise.all([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logto/capacitor",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "type": "module",
5
5
  "main": "./lib/index.cjs",
6
6
  "module": "./lib/index.js",
@@ -21,14 +21,14 @@
21
21
  "directory": "packages/capacitor"
22
22
  },
23
23
  "dependencies": {
24
- "@logto/browser": "^2.2.1"
24
+ "@logto/browser": "^2.2.4"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@capacitor/app": "^5.0.6",
28
28
  "@capacitor/browser": "^5.0.6",
29
29
  "@capacitor/preferences": "^5.0.6",
30
- "@silverhand/eslint-config": "^4.0.1",
31
- "@silverhand/ts-config": "^4.0.0",
30
+ "@silverhand/eslint-config": "^5.0.0",
31
+ "@silverhand/ts-config": "^5.0.0",
32
32
  "@swc/core": "^1.3.50",
33
33
  "@swc/jest": "^0.2.24",
34
34
  "@types/jest": "^29.5.0",
@@ -39,7 +39,7 @@
39
39
  "lint-staged": "^15.0.0",
40
40
  "prettier": "^3.0.0",
41
41
  "text-encoder": "^0.0.4",
42
- "typescript": "^5.0.0"
42
+ "typescript": "^5.3.3"
43
43
  },
44
44
  "eslintConfig": {
45
45
  "extends": "@silverhand"