@logto/vue 2.1.1 → 2.2.1
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 +11 -11
- package/lib/index.d.ts +7 -7
- package/lib/plugin.cjs +32 -74
- package/lib/plugin.js +32 -74
- package/package.json +9 -7
- package/lib/plugin.d.ts +0 -10
package/lib/index.cjs
CHANGED
|
@@ -113,47 +113,47 @@ const useHandleSignInCallback = (callback) => {
|
|
|
113
113
|
};
|
|
114
114
|
};
|
|
115
115
|
|
|
116
|
-
Object.defineProperty(exports,
|
|
116
|
+
Object.defineProperty(exports, "LogtoClientError", {
|
|
117
117
|
enumerable: true,
|
|
118
118
|
get: function () { return LogtoClient.LogtoClientError; }
|
|
119
119
|
});
|
|
120
|
-
Object.defineProperty(exports,
|
|
120
|
+
Object.defineProperty(exports, "LogtoError", {
|
|
121
121
|
enumerable: true,
|
|
122
122
|
get: function () { return LogtoClient.LogtoError; }
|
|
123
123
|
});
|
|
124
|
-
Object.defineProperty(exports,
|
|
124
|
+
Object.defineProperty(exports, "LogtoRequestError", {
|
|
125
125
|
enumerable: true,
|
|
126
126
|
get: function () { return LogtoClient.LogtoRequestError; }
|
|
127
127
|
});
|
|
128
|
-
Object.defineProperty(exports,
|
|
128
|
+
Object.defineProperty(exports, "OidcError", {
|
|
129
129
|
enumerable: true,
|
|
130
130
|
get: function () { return LogtoClient.OidcError; }
|
|
131
131
|
});
|
|
132
|
-
Object.defineProperty(exports,
|
|
132
|
+
Object.defineProperty(exports, "PersistKey", {
|
|
133
133
|
enumerable: true,
|
|
134
134
|
get: function () { return LogtoClient.PersistKey; }
|
|
135
135
|
});
|
|
136
|
-
Object.defineProperty(exports,
|
|
136
|
+
Object.defineProperty(exports, "Prompt", {
|
|
137
137
|
enumerable: true,
|
|
138
138
|
get: function () { return LogtoClient.Prompt; }
|
|
139
139
|
});
|
|
140
|
-
Object.defineProperty(exports,
|
|
140
|
+
Object.defineProperty(exports, "ReservedScope", {
|
|
141
141
|
enumerable: true,
|
|
142
142
|
get: function () { return LogtoClient.ReservedScope; }
|
|
143
143
|
});
|
|
144
|
-
Object.defineProperty(exports,
|
|
144
|
+
Object.defineProperty(exports, "UserScope", {
|
|
145
145
|
enumerable: true,
|
|
146
146
|
get: function () { return LogtoClient.UserScope; }
|
|
147
147
|
});
|
|
148
|
-
Object.defineProperty(exports,
|
|
148
|
+
Object.defineProperty(exports, "buildOrganizationUrn", {
|
|
149
149
|
enumerable: true,
|
|
150
150
|
get: function () { return LogtoClient.buildOrganizationUrn; }
|
|
151
151
|
});
|
|
152
|
-
Object.defineProperty(exports,
|
|
152
|
+
Object.defineProperty(exports, "getOrganizationIdFromUrn", {
|
|
153
153
|
enumerable: true,
|
|
154
154
|
get: function () { return LogtoClient.getOrganizationIdFromUrn; }
|
|
155
155
|
});
|
|
156
|
-
Object.defineProperty(exports,
|
|
156
|
+
Object.defineProperty(exports, "organizationUrnPrefix", {
|
|
157
157
|
enumerable: true,
|
|
158
158
|
get: function () { return LogtoClient.organizationUrnPrefix; }
|
|
159
159
|
});
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LogtoConfig } from '@logto/browser';
|
|
2
|
+
import LogtoClient from '@logto/browser';
|
|
3
|
+
import { type Optional } from '@silverhand/essentials';
|
|
2
4
|
import type { App, Ref } from 'vue';
|
|
3
5
|
export type { LogtoConfig, IdTokenClaims, UserInfoResponse, LogtoErrorCode, LogtoClientErrorCode, InteractionMode, } from '@logto/browser';
|
|
4
6
|
export { LogtoError, LogtoRequestError, LogtoClientError, OidcError, Prompt, ReservedScope, UserScope, organizationUrnPrefix, buildOrganizationUrn, getOrganizationIdFromUrn, PersistKey, } from '@logto/browser';
|
|
7
|
+
type OptionalPromiseReturn<T> = {
|
|
8
|
+
[K in keyof T]: T[K] extends (...args: infer A) => Promise<infer R> ? (...args: A) => Promise<Optional<R>> : T[K];
|
|
9
|
+
};
|
|
5
10
|
type LogtoVuePlugin = {
|
|
6
11
|
install: (app: App, config: LogtoConfig) => void;
|
|
7
12
|
};
|
|
@@ -9,12 +14,7 @@ type Logto = {
|
|
|
9
14
|
isAuthenticated: Readonly<Ref<boolean>>;
|
|
10
15
|
isLoading: Readonly<Ref<boolean>>;
|
|
11
16
|
error: Readonly<Ref<Error | undefined>>;
|
|
12
|
-
|
|
13
|
-
getAccessToken: (resource?: string) => Promise<string | undefined>;
|
|
14
|
-
getIdTokenClaims: () => Promise<IdTokenClaims | undefined>;
|
|
15
|
-
signIn: (redirectUri: string) => Promise<void>;
|
|
16
|
-
signOut: (postLogoutRedirectUri?: string) => Promise<void>;
|
|
17
|
-
};
|
|
17
|
+
} & OptionalPromiseReturn<Pick<LogtoClient, 'getRefreshToken' | 'getAccessToken' | 'getAccessTokenClaims' | 'getOrganizationToken' | 'getOrganizationTokenClaims' | 'getIdToken' | 'getIdTokenClaims' | 'signIn' | 'signOut' | 'fetchUserInfo'>>;
|
|
18
18
|
/**
|
|
19
19
|
* Creates the Logto Vue plugin
|
|
20
20
|
*
|
package/lib/plugin.cjs
CHANGED
|
@@ -4,76 +4,38 @@ var context = require('./context.cjs');
|
|
|
4
4
|
|
|
5
5
|
const createPluginMethods = (context$1) => {
|
|
6
6
|
const { logtoClient, setLoading, setError, setIsAuthenticated } = context$1;
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
try {
|
|
24
|
-
setLoading(true);
|
|
25
|
-
await logtoClient.value.signOut(postLogoutRedirectUri);
|
|
26
|
-
// We deliberately do NOT set isAuthenticated to false here, because the app state may change immediately
|
|
27
|
-
// even before navigating to the oidc end session endpoint, which might cause rendering problems.
|
|
28
|
-
// Moreover, since the location will be redirected, the isAuthenticated state will not matter any more.
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
setError(error, 'Unexpected error occurred while signing out.');
|
|
32
|
-
}
|
|
33
|
-
finally {
|
|
34
|
-
setLoading(false);
|
|
35
|
-
}
|
|
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
|
+
};
|
|
36
23
|
};
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const getAccessToken = async (resource) => {
|
|
53
|
-
if (!logtoClient.value) {
|
|
54
|
-
return context.throwContextError();
|
|
55
|
-
}
|
|
56
|
-
try {
|
|
57
|
-
setLoading(true);
|
|
58
|
-
return await logtoClient.value.getAccessToken(resource);
|
|
59
|
-
}
|
|
60
|
-
catch (error) {
|
|
61
|
-
setError(error, 'Unexpected error occurred while getting access token.');
|
|
62
|
-
}
|
|
63
|
-
finally {
|
|
64
|
-
setLoading(false);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
const getIdTokenClaims = async () => {
|
|
68
|
-
if (!logtoClient.value) {
|
|
69
|
-
return context.throwContextError();
|
|
70
|
-
}
|
|
71
|
-
try {
|
|
72
|
-
return await logtoClient.value.getIdTokenClaims();
|
|
73
|
-
}
|
|
74
|
-
catch (error) {
|
|
75
|
-
setError(error, 'Unexpected error occurred while getting id token claims.');
|
|
76
|
-
}
|
|
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
|
+
signIn: proxy(client.signIn.bind(client), false),
|
|
33
|
+
// We deliberately do NOT set isAuthenticated to false in the function below, because the app state
|
|
34
|
+
// may change immediately even before navigating to the oidc end session endpoint, which might cause
|
|
35
|
+
// rendering problems.
|
|
36
|
+
// Moreover, since the location will be redirected, the isAuthenticated state will not matter any more.
|
|
37
|
+
signOut: proxy(client.signOut.bind(client)),
|
|
38
|
+
fetchUserInfo: proxy(client.fetchUserInfo.bind(client)),
|
|
77
39
|
};
|
|
78
40
|
const handleSignInCallback = async (callbackUri, callbackFunction) => {
|
|
79
41
|
if (!logtoClient.value) {
|
|
@@ -93,11 +55,7 @@ const createPluginMethods = (context$1) => {
|
|
|
93
55
|
}
|
|
94
56
|
};
|
|
95
57
|
return {
|
|
96
|
-
|
|
97
|
-
signOut,
|
|
98
|
-
fetchUserInfo,
|
|
99
|
-
getAccessToken,
|
|
100
|
-
getIdTokenClaims,
|
|
58
|
+
...methods,
|
|
101
59
|
handleSignInCallback,
|
|
102
60
|
};
|
|
103
61
|
};
|
package/lib/plugin.js
CHANGED
|
@@ -2,76 +2,38 @@ import { throwContextError } from './context.js';
|
|
|
2
2
|
|
|
3
3
|
const createPluginMethods = (context) => {
|
|
4
4
|
const { logtoClient, setLoading, setError, setIsAuthenticated } = context;
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
try {
|
|
22
|
-
setLoading(true);
|
|
23
|
-
await logtoClient.value.signOut(postLogoutRedirectUri);
|
|
24
|
-
// We deliberately do NOT set isAuthenticated to false here, because the app state may change immediately
|
|
25
|
-
// even before navigating to the oidc end session endpoint, which might cause rendering problems.
|
|
26
|
-
// Moreover, since the location will be redirected, the isAuthenticated state will not matter any more.
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
setError(error, 'Unexpected error occurred while signing out.');
|
|
30
|
-
}
|
|
31
|
-
finally {
|
|
32
|
-
setLoading(false);
|
|
33
|
-
}
|
|
5
|
+
const client = logtoClient.value ?? throwContextError();
|
|
6
|
+
const proxy = (run, resetLoadingState = true) => {
|
|
7
|
+
return async (...args) => {
|
|
8
|
+
try {
|
|
9
|
+
setLoading(true);
|
|
10
|
+
return await run(...args);
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
setError(error, `Unexpected error occurred while calling ${run.name}.`);
|
|
14
|
+
}
|
|
15
|
+
finally {
|
|
16
|
+
if (resetLoadingState) {
|
|
17
|
+
setLoading(false);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
34
21
|
};
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const getAccessToken = async (resource) => {
|
|
51
|
-
if (!logtoClient.value) {
|
|
52
|
-
return throwContextError();
|
|
53
|
-
}
|
|
54
|
-
try {
|
|
55
|
-
setLoading(true);
|
|
56
|
-
return await logtoClient.value.getAccessToken(resource);
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
setError(error, 'Unexpected error occurred while getting access token.');
|
|
60
|
-
}
|
|
61
|
-
finally {
|
|
62
|
-
setLoading(false);
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
const getIdTokenClaims = async () => {
|
|
66
|
-
if (!logtoClient.value) {
|
|
67
|
-
return throwContextError();
|
|
68
|
-
}
|
|
69
|
-
try {
|
|
70
|
-
return await logtoClient.value.getIdTokenClaims();
|
|
71
|
-
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
setError(error, 'Unexpected error occurred while getting id token claims.');
|
|
74
|
-
}
|
|
22
|
+
const methods = {
|
|
23
|
+
getRefreshToken: proxy(client.getRefreshToken.bind(client)),
|
|
24
|
+
getAccessToken: proxy(client.getAccessToken.bind(client)),
|
|
25
|
+
getAccessTokenClaims: proxy(client.getAccessTokenClaims.bind(client)),
|
|
26
|
+
getOrganizationToken: proxy(client.getOrganizationToken.bind(client)),
|
|
27
|
+
getOrganizationTokenClaims: proxy(client.getOrganizationTokenClaims.bind(client)),
|
|
28
|
+
getIdToken: proxy(client.getIdToken.bind(client)),
|
|
29
|
+
getIdTokenClaims: proxy(client.getIdTokenClaims.bind(client)),
|
|
30
|
+
signIn: proxy(client.signIn.bind(client), false),
|
|
31
|
+
// We deliberately do NOT set isAuthenticated to false in the function below, because the app state
|
|
32
|
+
// may change immediately even before navigating to the oidc end session endpoint, which might cause
|
|
33
|
+
// rendering problems.
|
|
34
|
+
// Moreover, since the location will be redirected, the isAuthenticated state will not matter any more.
|
|
35
|
+
signOut: proxy(client.signOut.bind(client)),
|
|
36
|
+
fetchUserInfo: proxy(client.fetchUserInfo.bind(client)),
|
|
75
37
|
};
|
|
76
38
|
const handleSignInCallback = async (callbackUri, callbackFunction) => {
|
|
77
39
|
if (!logtoClient.value) {
|
|
@@ -91,11 +53,7 @@ const createPluginMethods = (context) => {
|
|
|
91
53
|
}
|
|
92
54
|
};
|
|
93
55
|
return {
|
|
94
|
-
|
|
95
|
-
signOut,
|
|
96
|
-
fetchUserInfo,
|
|
97
|
-
getAccessToken,
|
|
98
|
-
getIdTokenClaims,
|
|
56
|
+
...methods,
|
|
99
57
|
handleSignInCallback,
|
|
100
58
|
};
|
|
101
59
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logto/vue",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./lib/index.cjs",
|
|
6
6
|
"module": "./lib/index.js",
|
|
@@ -21,11 +21,12 @@
|
|
|
21
21
|
"directory": "packages/vue"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@logto/browser": "^2.2.
|
|
24
|
+
"@logto/browser": "^2.2.2",
|
|
25
|
+
"@silverhand/essentials": "^2.8.7"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
|
-
"@silverhand/eslint-config": "^
|
|
28
|
-
"@silverhand/ts-config": "^
|
|
28
|
+
"@silverhand/eslint-config": "^5.0.0",
|
|
29
|
+
"@silverhand/ts-config": "^5.0.0",
|
|
29
30
|
"@swc/core": "^1.3.50",
|
|
30
31
|
"@swc/jest": "^0.2.24",
|
|
31
32
|
"@types/jest": "^29.5.0",
|
|
@@ -34,9 +35,9 @@
|
|
|
34
35
|
"lint-staged": "^15.0.0",
|
|
35
36
|
"postcss": "^8.4.31",
|
|
36
37
|
"prettier": "^3.0.0",
|
|
37
|
-
"stylelint": "^
|
|
38
|
+
"stylelint": "^16.0.0",
|
|
38
39
|
"typescript": "^5.0.0",
|
|
39
|
-
"vue": "^3.
|
|
40
|
+
"vue": "^3.3.13"
|
|
40
41
|
},
|
|
41
42
|
"peerDependencies": {
|
|
42
43
|
"vue": ">=3.0.0"
|
|
@@ -48,7 +49,8 @@
|
|
|
48
49
|
"error",
|
|
49
50
|
{
|
|
50
51
|
"replacements": {
|
|
51
|
-
"ref": false
|
|
52
|
+
"ref": false,
|
|
53
|
+
"args": false
|
|
52
54
|
}
|
|
53
55
|
}
|
|
54
56
|
]
|
package/lib/plugin.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { InteractionMode } from '@logto/browser';
|
|
2
|
-
import type { Context } from './context.js';
|
|
3
|
-
export declare const createPluginMethods: (context: Context) => {
|
|
4
|
-
signIn: (redirectUri: string, interactionMode?: InteractionMode) => Promise<undefined>;
|
|
5
|
-
signOut: (postLogoutRedirectUri?: string) => Promise<undefined>;
|
|
6
|
-
fetchUserInfo: () => Promise<import("@logto/browser").UserInfoResponse | undefined>;
|
|
7
|
-
getAccessToken: (resource?: string) => Promise<string | undefined>;
|
|
8
|
-
getIdTokenClaims: () => Promise<import("@logto/browser").IdTokenClaims | undefined>;
|
|
9
|
-
handleSignInCallback: (callbackUri: string, callbackFunction?: () => void) => Promise<undefined>;
|
|
10
|
-
};
|