@logto/capacitor 2.0.4 → 3.0.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.
Files changed (2) hide show
  1. package/package.json +5 -7
  2. package/lib/index.cjs +0 -175
package/package.json CHANGED
@@ -1,13 +1,11 @@
1
1
  {
2
2
  "name": "@logto/capacitor",
3
- "version": "2.0.4",
3
+ "version": "3.0.4",
4
4
  "type": "module",
5
- "main": "./lib/index.cjs",
6
5
  "module": "./lib/index.js",
7
6
  "types": "./lib/index.d.ts",
8
7
  "exports": {
9
8
  "types": "./lib/index.d.ts",
10
- "require": "./lib/index.cjs",
11
9
  "import": "./lib/index.js",
12
10
  "default": "./lib/index.js"
13
11
  },
@@ -21,7 +19,7 @@
21
19
  "directory": "packages/capacitor"
22
20
  },
23
21
  "dependencies": {
24
- "@logto/browser": "^2.2.18"
22
+ "@logto/browser": "^3.0.4"
25
23
  },
26
24
  "devDependencies": {
27
25
  "@capacitor/app": "^6.0.0",
@@ -29,13 +27,13 @@
29
27
  "@capacitor/preferences": "^6.0.0",
30
28
  "@silverhand/eslint-config": "^6.0.1",
31
29
  "@silverhand/ts-config": "^6.0.0",
32
- "@vitest/coverage-v8": "^1.6.0",
30
+ "@vitest/coverage-v8": "^2.1.9",
33
31
  "eslint": "^8.57.0",
34
- "happy-dom": "^14.0.0",
32
+ "happy-dom": "^16.0.0",
35
33
  "lint-staged": "^15.0.0",
36
34
  "prettier": "^3.0.0",
37
35
  "typescript": "^5.3.3",
38
- "vitest": "^1.6.0"
36
+ "vitest": "^2.1.9"
39
37
  },
40
38
  "eslintConfig": {
41
39
  "extends": "@silverhand"
package/lib/index.cjs DELETED
@@ -1,175 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var app = require('@capacitor/app');
6
- var browser = require('@capacitor/browser');
7
- var preferences = require('@capacitor/preferences');
8
- var LogtoBaseClient = require('@logto/browser');
9
-
10
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
-
12
- var LogtoBaseClient__default = /*#__PURE__*/_interopDefault(LogtoBaseClient);
13
-
14
- class CapacitorLogtoClient extends LogtoBaseClient__default.default {
15
- constructor(config, capacitorConfig = {}) {
16
- const { openOptions } = capacitorConfig;
17
- super(config);
18
- // Use the Capacitor Browser plugin to open the sign-in and sign-out pages
19
- // since the default location assignment method will open the pages in a
20
- // system browser. We need to open an in-app browser to be able to handle
21
- // the redirects back to the app.
22
- // https://capacitorjs.com/docs/apis/browser
23
- this.adapter.navigate = async (url) => {
24
- return browser.Browser.open({
25
- url,
26
- windowName: '_self',
27
- presentationStyle: 'popover',
28
- ...openOptions,
29
- });
30
- };
31
- // Use the Capacitor Preferences plugin to store the tokens, which will
32
- // fallback to localStorage for web builds.
33
- // https://capacitorjs.com/docs/apis/preferences
34
- this.adapter.storage = {
35
- getItem: async (key) => {
36
- const { value } = await preferences.Preferences.get({ key });
37
- return value;
38
- },
39
- setItem: async (key, value) => {
40
- await preferences.Preferences.set({ key, value });
41
- },
42
- removeItem: async (key) => {
43
- await preferences.Preferences.remove({ key });
44
- },
45
- };
46
- }
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
- }
51
- return new Promise((resolve, reject) => {
52
- const run = async () => {
53
- const [browserHandle, appHandle] = await Promise.all([
54
- // Handle the case where the user closes the browser during the sign-in.
55
- browser.Browser.addListener('browserFinished', async () => {
56
- await Promise.all([browserHandle.remove(), appHandle.remove()]);
57
- reject(new LogtoBaseClient.LogtoClientError('user_cancelled'));
58
- }),
59
- // Handle the case where the user completes the sign-in and is redirected
60
- // back to the app.
61
- app.App.addListener('appUrlOpen', async ({ url }) => {
62
- if (!url.startsWith(redirectUri.toString())) {
63
- return;
64
- }
65
- await Promise.all([
66
- // One last step of the sign-in flow
67
- this.handleSignInCallback(url),
68
- // Close the browser and remove the listeners
69
- browser.Browser.close(),
70
- browserHandle.remove(),
71
- appHandle.remove(),
72
- ]);
73
- resolve();
74
- }),
75
- // Open the in-app browser to start the sign-in flow
76
- super.signIn(redirectUri, interactionMode),
77
- ]);
78
- };
79
- void run();
80
- });
81
- }
82
- /**
83
- * Start the sign-out flow with the specified redirect URI. The URI must be
84
- * registered in the Logto Console.
85
- *
86
- * It will also revoke all the tokens and clean up the storage.
87
- *
88
- * - If the `postLogoutRedirectUri` is not specified, the user will see a default
89
- * page after the sign-out flow is completed, they need to close the browser
90
- * manually to return to the app.
91
- * - If the `postLogoutRedirectUri` is specified, the user will be redirected to
92
- * that URI after the sign-out flow is completed. Remember to configure the correct
93
- * [scheme or universal links](https://capacitorjs.com/docs/guides/deep-links)
94
- * to ensure the app can be opened from the redirect URI.
95
- *
96
- * @param postLogoutRedirectUri The URI that the user will be redirected to after the sign-out flow is completed.
97
- *
98
- * @example
99
- * ```ts
100
- * await client.signOut('io.logto.example://callback');
101
- * ```
102
- */
103
- async signOut(postLogoutRedirectUri) {
104
- return new Promise((resolve) => {
105
- const run = async () => {
106
- const [handle] = await Promise.all([
107
- postLogoutRedirectUri
108
- ? app.App.addListener('appUrlOpen', async ({ url }) => {
109
- if (postLogoutRedirectUri && !url.startsWith(postLogoutRedirectUri)) {
110
- return;
111
- }
112
- await Promise.all([browser.Browser.close(), handle.remove()]);
113
- resolve();
114
- })
115
- : browser.Browser.addListener('browserFinished', async () => {
116
- await handle.remove();
117
- resolve();
118
- }),
119
- super.signOut(postLogoutRedirectUri),
120
- ]);
121
- };
122
- void run();
123
- });
124
- }
125
- }
126
-
127
- Object.defineProperty(exports, "LogtoClientError", {
128
- enumerable: true,
129
- get: function () { return LogtoBaseClient.LogtoClientError; }
130
- });
131
- Object.defineProperty(exports, "LogtoError", {
132
- enumerable: true,
133
- get: function () { return LogtoBaseClient.LogtoError; }
134
- });
135
- Object.defineProperty(exports, "LogtoRequestError", {
136
- enumerable: true,
137
- get: function () { return LogtoBaseClient.LogtoRequestError; }
138
- });
139
- Object.defineProperty(exports, "OidcError", {
140
- enumerable: true,
141
- get: function () { return LogtoBaseClient.OidcError; }
142
- });
143
- Object.defineProperty(exports, "PersistKey", {
144
- enumerable: true,
145
- get: function () { return LogtoBaseClient.PersistKey; }
146
- });
147
- Object.defineProperty(exports, "Prompt", {
148
- enumerable: true,
149
- get: function () { return LogtoBaseClient.Prompt; }
150
- });
151
- Object.defineProperty(exports, "ReservedResource", {
152
- enumerable: true,
153
- get: function () { return LogtoBaseClient.ReservedResource; }
154
- });
155
- Object.defineProperty(exports, "ReservedScope", {
156
- enumerable: true,
157
- get: function () { return LogtoBaseClient.ReservedScope; }
158
- });
159
- Object.defineProperty(exports, "UserScope", {
160
- enumerable: true,
161
- get: function () { return LogtoBaseClient.UserScope; }
162
- });
163
- Object.defineProperty(exports, "buildOrganizationUrn", {
164
- enumerable: true,
165
- get: function () { return LogtoBaseClient.buildOrganizationUrn; }
166
- });
167
- Object.defineProperty(exports, "getOrganizationIdFromUrn", {
168
- enumerable: true,
169
- get: function () { return LogtoBaseClient.getOrganizationIdFromUrn; }
170
- });
171
- Object.defineProperty(exports, "organizationUrnPrefix", {
172
- enumerable: true,
173
- get: function () { return LogtoBaseClient.organizationUrnPrefix; }
174
- });
175
- exports.default = CapacitorLogtoClient;