@logto/vue 2.2.17 → 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.
package/package.json CHANGED
@@ -1,13 +1,11 @@
1
1
  {
2
2
  "name": "@logto/vue",
3
- "version": "2.2.17",
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,21 +19,21 @@
21
19
  "directory": "packages/vue"
22
20
  },
23
21
  "dependencies": {
24
- "@silverhand/essentials": "^2.8.7",
25
- "@logto/browser": "^2.2.18"
22
+ "@silverhand/essentials": "^2.9.2",
23
+ "@logto/browser": "^3.0.4"
26
24
  },
27
25
  "devDependencies": {
28
26
  "@silverhand/eslint-config": "^6.0.1",
29
27
  "@silverhand/ts-config": "^6.0.0",
30
- "@vitest/coverage-v8": "^1.6.0",
28
+ "@vitest/coverage-v8": "^2.1.9",
31
29
  "eslint": "^8.57.0",
32
- "happy-dom": "^14.0.0",
30
+ "happy-dom": "^16.0.0",
33
31
  "lint-staged": "^15.0.0",
34
32
  "postcss": "^8.4.31",
35
33
  "prettier": "^3.0.0",
36
- "stylelint": "^15.0.0",
34
+ "stylelint": "^16.0.0",
37
35
  "typescript": "^5.3.3",
38
- "vitest": "^1.6.0",
36
+ "vitest": "^2.1.9",
39
37
  "vue": "^3.4.19"
40
38
  },
41
39
  "peerDependencies": {
package/lib/consts.cjs DELETED
@@ -1,7 +0,0 @@
1
- 'use strict';
2
-
3
- const logtoInjectionKey = '@logto/vue';
4
- const contextInjectionKey = '@logto/vue:context';
5
-
6
- exports.contextInjectionKey = contextInjectionKey;
7
- exports.logtoInjectionKey = logtoInjectionKey;
package/lib/context.cjs DELETED
@@ -1,48 +0,0 @@
1
- 'use strict';
2
-
3
- var vue = require('vue');
4
-
5
- const createContext = (client) => {
6
- const context = vue.toRefs(vue.reactive({
7
- logtoClient: client,
8
- isAuthenticated: false,
9
- loadingCount: 1,
10
- error: undefined,
11
- }));
12
- const { isAuthenticated, loadingCount, error } = context;
13
- const isLoading = vue.computed(() => loadingCount.value > 0);
14
- /* eslint-disable @silverhand/fp/no-mutation */
15
- const setError = (_error, fallbackErrorMessage) => {
16
- if (_error instanceof Error) {
17
- error.value = _error;
18
- }
19
- else if (fallbackErrorMessage) {
20
- error.value = new Error(fallbackErrorMessage);
21
- }
22
- console.error(error);
23
- };
24
- const setLoading = (isLoading) => {
25
- if (isLoading) {
26
- loadingCount.value += 1;
27
- }
28
- else {
29
- loadingCount.value = Math.max(0, loadingCount.value - 1);
30
- }
31
- };
32
- const setIsAuthenticated = (_isAuthenticated) => {
33
- isAuthenticated.value = _isAuthenticated;
34
- };
35
- /* eslint-enable @silverhand/fp/no-mutation */
36
- (async () => {
37
- const isAuthenticated = await client.isAuthenticated();
38
- setIsAuthenticated(isAuthenticated);
39
- setLoading(false);
40
- })();
41
- return { ...context, isLoading, setError, setLoading, setIsAuthenticated };
42
- };
43
- const throwContextError = () => {
44
- throw new Error('Must install Logto plugin first.');
45
- };
46
-
47
- exports.createContext = createContext;
48
- exports.throwContextError = throwContextError;
package/lib/index.cjs DELETED
@@ -1,164 +0,0 @@
1
- 'use strict';
2
-
3
- var LogtoClient = require('@logto/browser');
4
- var vue = require('vue');
5
- var consts = require('./consts.cjs');
6
- var context = require('./context.cjs');
7
- var plugin = require('./plugin.cjs');
8
-
9
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
-
11
- var LogtoClient__default = /*#__PURE__*/_interopDefault(LogtoClient);
12
-
13
- /**
14
- * Creates the Logto Vue plugin
15
- *
16
- * ```ts
17
- * import { createApp } from 'vue';
18
- * import { createLogto } from '@logto/vue';
19
- *
20
- * const app = createApp(App);
21
- * const app.use(createLogto, {
22
- * appId: '<your-app-id>',
23
- * endpoint: '<your-oidc-endpoint-domain>',
24
- * });
25
- *
26
- * app.mount('#app');
27
- * ```
28
- *
29
- * Use this in your Vue root component to register the plugin
30
- */
31
- const createLogto = {
32
- install(app, config) {
33
- const client = new LogtoClient__default.default(config);
34
- const context$1 = context.createContext(client);
35
- const pluginMethods = plugin.createPluginMethods(context$1);
36
- const { isAuthenticated, isLoading, error } = context$1;
37
- app.provide(consts.contextInjectionKey, context$1);
38
- app.provide(consts.logtoInjectionKey, {
39
- isAuthenticated: vue.readonly(isAuthenticated),
40
- isLoading: vue.readonly(isLoading),
41
- error: vue.readonly(error),
42
- ...pluginMethods,
43
- });
44
- },
45
- };
46
- /**
47
- * A Vue composable method that provides the Logto reactive refs and auth methods.
48
- *
49
- * ```ts
50
- * import { useLogto } from '@logto/vue';
51
- *
52
- * export default {
53
- * setup() {
54
- * const { isAuthenticated, signIn } = useLogto();
55
- *
56
- * return {
57
- * isAuthenticated,
58
- * onClickSignIn: () => {
59
- * signIn('<your-redirect-uri>');
60
- * },
61
- * }
62
- * }
63
- * }
64
- * ```
65
- *
66
- * Use this composable in the setup script of your Vue component to make sure the injection works
67
- */
68
- const useLogto = () => {
69
- const logto = vue.inject(consts.logtoInjectionKey);
70
- if (!logto) {
71
- return context.throwContextError();
72
- }
73
- return logto;
74
- };
75
- /**
76
- * A Vue composable method that watches browser navigation and automatically handles the sign-in callback
77
- *
78
- * ```ts
79
- * import { useLogto } from '@logto/vue';
80
- * import { useHandleSignInCallback } from '@logto/vue';
81
- *
82
- * export default {
83
- * setup() {
84
- * useHandleSignInCallback();
85
- * }
86
- * }
87
- * ```
88
- *
89
- * Use this in the setup script of your Callback page to make sure the injection works
90
- */
91
- const useHandleSignInCallback = (callback) => {
92
- const context$1 = vue.inject(consts.contextInjectionKey);
93
- if (!context$1) {
94
- return context.throwContextError();
95
- }
96
- const { isAuthenticated, isLoading, logtoClient, error } = context$1;
97
- const { handleSignInCallback } = plugin.createPluginMethods(context$1);
98
- vue.watchEffect(async () => {
99
- if (!logtoClient.value) {
100
- return;
101
- }
102
- const currentPageUrl = window.location.href;
103
- const isAuthenticated = await logtoClient.value.isAuthenticated();
104
- const isRedirected = await logtoClient.value.isSignInRedirected(currentPageUrl);
105
- console.log('isAuthenticated', isAuthenticated);
106
- console.log('isRedirected', isRedirected);
107
- if (!isAuthenticated && isRedirected) {
108
- void handleSignInCallback(currentPageUrl, callback);
109
- }
110
- });
111
- return {
112
- isLoading: vue.readonly(isLoading),
113
- isAuthenticated: vue.readonly(isAuthenticated),
114
- error: vue.readonly(error),
115
- };
116
- };
117
-
118
- Object.defineProperty(exports, "LogtoClientError", {
119
- enumerable: true,
120
- get: function () { return LogtoClient.LogtoClientError; }
121
- });
122
- Object.defineProperty(exports, "LogtoError", {
123
- enumerable: true,
124
- get: function () { return LogtoClient.LogtoError; }
125
- });
126
- Object.defineProperty(exports, "LogtoRequestError", {
127
- enumerable: true,
128
- get: function () { return LogtoClient.LogtoRequestError; }
129
- });
130
- Object.defineProperty(exports, "OidcError", {
131
- enumerable: true,
132
- get: function () { return LogtoClient.OidcError; }
133
- });
134
- Object.defineProperty(exports, "PersistKey", {
135
- enumerable: true,
136
- get: function () { return LogtoClient.PersistKey; }
137
- });
138
- Object.defineProperty(exports, "Prompt", {
139
- enumerable: true,
140
- get: function () { return LogtoClient.Prompt; }
141
- });
142
- Object.defineProperty(exports, "ReservedScope", {
143
- enumerable: true,
144
- get: function () { return LogtoClient.ReservedScope; }
145
- });
146
- Object.defineProperty(exports, "UserScope", {
147
- enumerable: true,
148
- get: function () { return LogtoClient.UserScope; }
149
- });
150
- Object.defineProperty(exports, "buildOrganizationUrn", {
151
- enumerable: true,
152
- get: function () { return LogtoClient.buildOrganizationUrn; }
153
- });
154
- Object.defineProperty(exports, "getOrganizationIdFromUrn", {
155
- enumerable: true,
156
- get: function () { return LogtoClient.getOrganizationIdFromUrn; }
157
- });
158
- Object.defineProperty(exports, "organizationUrnPrefix", {
159
- enumerable: true,
160
- get: function () { return LogtoClient.organizationUrnPrefix; }
161
- });
162
- exports.createLogto = createLogto;
163
- exports.useHandleSignInCallback = useHandleSignInCallback;
164
- exports.useLogto = useLogto;
package/lib/plugin.cjs DELETED
@@ -1,67 +0,0 @@
1
- 'use strict';
2
-
3
- var context = require('./context.cjs');
4
-
5
- const createPluginMethods = (context$1) => {
6
- const { logtoClient, setLoading, setError, setIsAuthenticated } = context$1;
7
- const client = logtoClient.value ?? context.throwContextError();
8
- const proxy = (run, resetLoadingState = true) => {
9
- return async (...args) => {
10
- try {
11
- setLoading(true);
12
- return await run(...args);
13
- }
14
- catch (error) {
15
- setError(error, `Unexpected error occurred while calling ${run.name}.`);
16
- }
17
- finally {
18
- if (resetLoadingState) {
19
- setLoading(false);
20
- }
21
- }
22
- };
23
- };
24
- const methods = {
25
- getRefreshToken: proxy(client.getRefreshToken.bind(client)),
26
- getAccessToken: proxy(client.getAccessToken.bind(client)),
27
- getAccessTokenClaims: proxy(client.getAccessTokenClaims.bind(client)),
28
- getOrganizationToken: proxy(client.getOrganizationToken.bind(client)),
29
- getOrganizationTokenClaims: proxy(client.getOrganizationTokenClaims.bind(client)),
30
- getIdToken: proxy(client.getIdToken.bind(client)),
31
- getIdTokenClaims: proxy(client.getIdTokenClaims.bind(client)),
32
- // eslint-disable-next-line no-restricted-syntax
33
- signIn: proxy(client.signIn.bind(client), false),
34
- // We deliberately do NOT set isAuthenticated to false in the function below, because the app state
35
- // may change immediately even before navigating to the oidc end session endpoint, which might cause
36
- // rendering problems.
37
- // Moreover, since the location will be redirected, the isAuthenticated state will not matter any more.
38
- signOut: proxy(client.signOut.bind(client)),
39
- fetchUserInfo: proxy(client.fetchUserInfo.bind(client)),
40
- clearAccessToken: proxy(client.clearAccessToken.bind(client)),
41
- clearAllTokens: proxy(client.clearAllTokens.bind(client)),
42
- };
43
- const handleSignInCallback = async (callbackUri, callbackFunction) => {
44
- if (!logtoClient.value) {
45
- return context.throwContextError();
46
- }
47
- try {
48
- setLoading(true);
49
- console.log('handleSignInCallback');
50
- await logtoClient.value.handleSignInCallback(callbackUri);
51
- setIsAuthenticated(true);
52
- callbackFunction?.();
53
- }
54
- catch (error) {
55
- setError(error, 'Unexpected error occurred while handling sign in callback.');
56
- }
57
- finally {
58
- setLoading(false);
59
- }
60
- };
61
- return {
62
- ...methods,
63
- handleSignInCallback,
64
- };
65
- };
66
-
67
- exports.createPluginMethods = createPluginMethods;