@strivacity/sdk-nuxt 3.0.2 → 4.0.0-beta.0
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/.nuxt/app-component.mjs +1 -1
- package/.nuxt/app.config.mjs +21 -0
- package/.nuxt/component-names.mjs +1 -1
- package/.nuxt/components.d.ts +48 -48
- package/.nuxt/components.islands.mjs +6 -2
- package/.nuxt/error-component.mjs +1 -1
- package/.nuxt/fetch.d.ts +1 -0
- package/.nuxt/fetch.mjs +4 -3
- package/.nuxt/imports.d.ts +15 -5
- package/.nuxt/imports.mjs +15 -5
- package/.nuxt/island-renderer.mjs +2 -0
- package/.nuxt/middleware.mjs +3 -1
- package/.nuxt/nuxt.config.mjs +103 -0
- package/.nuxt/nuxt.d.ts +3 -4
- package/.nuxt/nuxt.node.d.ts +4 -4
- package/.nuxt/nuxt.shared.d.ts +3 -1
- package/.nuxt/plugins.client.mjs +10 -14
- package/.nuxt/plugins.server.mjs +6 -6
- package/.nuxt/root-component.mjs +1 -1
- package/.nuxt/route-rules.mjs +22 -0
- package/.nuxt/test-component-wrapper.mjs +1 -1
- package/.nuxt/tsconfig.app.json +211 -0
- package/.nuxt/tsconfig.json +212 -0
- package/.nuxt/tsconfig.node.json +117 -0
- package/.nuxt/tsconfig.server.json +161 -0
- package/.nuxt/tsconfig.shared.json +165 -0
- package/.nuxt/types/app.config.d.ts +35 -0
- package/.nuxt/types/components.d.ts +48 -48
- package/.nuxt/types/imports.d.ts +1 -1
- package/.nuxt/types/layouts.d.ts +16 -0
- package/.nuxt/types/modules.d.ts +20 -20
- package/.nuxt/types/nitro-imports.d.ts +9 -4
- package/.nuxt/types/nitro-layouts.d.ts +17 -0
- package/.nuxt/types/nitro-nuxt.d.ts +19 -5
- package/.nuxt/types/nitro-routes.d.ts +25 -1
- package/.nuxt/types/plugins.d.ts +8 -9
- package/.nuxt/types/runtime-config.d.ts +6 -12
- package/.nuxt/types/shared-app.config.d.ts +28 -0
- package/.nuxt/types/shared-imports.d.ts +2 -0
- package/.nuxt/unhead-options.mjs +2 -1
- package/.nuxt/unhead.config.mjs +1 -0
- package/CHANGELOG.md +16 -14
- package/README.md +1577 -406
- package/build.config.ts +5 -0
- package/dist/module.d.mts +3 -193
- package/dist/module.json +2 -2
- package/dist/module.mjs +78 -57
- package/dist/module.mjs.map +1 -1
- package/dist/runtime/composables/use-native-login-context.d.ts +10 -0
- package/dist/runtime/composables/use-native-login-context.js +9 -0
- package/dist/runtime/composables/use-native-login.d.ts +10 -0
- package/dist/runtime/composables/use-native-login.js +143 -0
- package/dist/runtime/composables/use-session.d.ts +8 -0
- package/dist/runtime/composables/use-session.js +2 -0
- package/dist/runtime/composables/use-strivacity.d.ts +9 -0
- package/dist/runtime/composables/use-strivacity.js +77 -0
- package/dist/runtime/middleware/auth.server.d.ts +2 -0
- package/dist/runtime/middleware/auth.server.js +12 -0
- package/dist/runtime/server/api/auth/backchannel-logout.get.d.ts +2 -0
- package/dist/runtime/server/api/auth/backchannel-logout.get.js +2 -0
- package/dist/runtime/server/api/auth/callback.get.d.ts +2 -0
- package/dist/runtime/server/api/auth/callback.get.js +2 -0
- package/dist/runtime/server/api/auth/entry.get.d.ts +2 -0
- package/dist/runtime/server/api/auth/entry.get.js +2 -0
- package/dist/runtime/server/api/auth/login.get.d.ts +2 -0
- package/dist/runtime/server/api/auth/login.get.js +2 -0
- package/dist/runtime/server/api/auth/logout.get.d.ts +2 -0
- package/dist/runtime/server/api/auth/logout.get.js +2 -0
- package/dist/runtime/server/api/auth/refresh.get.d.ts +2 -0
- package/dist/runtime/server/api/auth/refresh.get.js +2 -0
- package/dist/runtime/server/api/auth/register.get.d.ts +2 -0
- package/dist/runtime/server/api/auth/register.get.js +2 -0
- package/dist/runtime/server/api/auth/revoke.get.d.ts +2 -0
- package/dist/runtime/server/api/auth/revoke.get.js +2 -0
- package/dist/runtime/server/composables/use-strivacity.d.ts +2 -0
- package/dist/runtime/server/composables/use-strivacity.js +9 -0
- package/dist/runtime/server/plugins/auth.server.d.ts +10 -0
- package/dist/runtime/server/plugins/auth.server.js +66 -0
- package/dist/runtime/server/utils/helpers.d.ts +18 -0
- package/dist/runtime/server/utils/helpers.js +39 -0
- package/dist/runtime/storages/core.d.ts +1 -0
- package/dist/runtime/storages/core.js +13 -0
- package/dist/runtime/storages/default.d.ts +21 -0
- package/dist/runtime/storages/default.js +71 -0
- package/dist/runtime/types.d.ts +219 -0
- package/dist/runtime/types.js +1 -0
- package/dist/runtime/utils/core.d.ts +1 -0
- package/dist/runtime/utils/core.js +64 -0
- package/dist/runtime/utils/noop.d.ts +1 -0
- package/dist/runtime/utils/noop.js +3 -0
- package/dist/types.d.mts +4 -16
- package/eslint.config.mjs +5 -0
- package/nuxt.config.ts +5 -0
- package/package.json +31 -5
- package/project.json +44 -0
- package/src/module.ts +107 -0
- package/src/runtime/composables/use-native-login-context.ts +20 -0
- package/src/runtime/composables/use-native-login.ts +182 -0
- package/src/runtime/composables/use-session.ts +10 -0
- package/src/runtime/composables/use-strivacity.ts +95 -0
- package/src/runtime/middleware/auth.server.ts +16 -0
- package/src/runtime/server/api/auth/backchannel-logout.get.ts +3 -0
- package/src/runtime/server/api/auth/callback.get.ts +3 -0
- package/src/runtime/server/api/auth/entry.get.ts +3 -0
- package/src/runtime/server/api/auth/login.get.ts +3 -0
- package/src/runtime/server/api/auth/logout.get.ts +3 -0
- package/src/runtime/server/api/auth/refresh.get.ts +3 -0
- package/src/runtime/server/api/auth/register.get.ts +3 -0
- package/src/runtime/server/api/auth/revoke.get.ts +3 -0
- package/src/runtime/server/composables/use-strivacity.ts +13 -0
- package/src/runtime/server/plugins/auth.server.ts +84 -0
- package/src/runtime/server/utils/helpers.ts +67 -0
- package/src/runtime/storages/core.ts +13 -0
- package/src/runtime/storages/default.ts +111 -0
- package/src/runtime/types.ts +289 -0
- package/src/runtime/utils/core.ts +64 -0
- package/src/runtime/utils/noop.ts +3 -0
- package/testing/stubs/app.ts +6 -0
- package/testing/stubs/imports.ts +19 -0
- package/testing/stubs/options-httpClient.ts +8 -0
- package/testing/stubs/options-logging.ts +8 -0
- package/testing/stubs/options-stateStorage.ts +8 -0
- package/testing/stubs/options-storage.ts +8 -0
- package/testing/tests/composables.spec.ts +512 -0
- package/testing/tests/server/helpers.spec.ts +86 -0
- package/testing/tests/server/plugin.spec.ts +138 -0
- package/testing/tests/server/routes.spec.ts +34 -0
- package/testing/tests/server/use-strivacity.spec.ts +22 -0
- package/testing/tests/storages-default.spec.ts +151 -0
- package/testing/tests/storages.spec.ts +16 -0
- package/testing/tests/utils.spec.ts +10 -0
- package/testing/utils/common.ts +33 -0
- package/testing/utils/http.ts +58 -0
- package/tsconfig.json +3 -0
- package/vite.config.mts +20 -0
- package/.nuxt/strivacity-sdk-logging.d.ts +0 -13
- package/.nuxt/strivacity-sdk-logging.mjs +0 -1
- package/.nuxt/strivacity-sdk-storage.d.ts +0 -10
- package/.nuxt/strivacity-sdk-storage.mjs +0 -1
- package/dist/runtime/composables.d.ts +0 -12
- package/dist/runtime/composables.js +0 -83
- package/dist/runtime/login-renderer.vue +0 -174
- package/dist/runtime/login-renderer.vue.d.ts +0 -39
- /package/.nuxt/manifest/meta/{b47927c0-b36b-4d2c-b650-8d55c5ec676a.json → cb11df97-b0c9-4a91-9d4b-60c25c918599.json} +0 -0
package/build.config.ts
ADDED
package/dist/module.d.mts
CHANGED
|
@@ -1,197 +1,7 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
-
import {
|
|
3
|
-
export * from '
|
|
4
|
-
import { PopupFlow } from '@strivacity/sdk-core/flows/PopupFlow';
|
|
5
|
-
export { PopupFlow } from '@strivacity/sdk-core/flows/PopupFlow';
|
|
6
|
-
import { RedirectFlow } from '@strivacity/sdk-core/flows/RedirectFlow';
|
|
7
|
-
export { RedirectFlow } from '@strivacity/sdk-core/flows/RedirectFlow';
|
|
8
|
-
import { NativeFlow } from '@strivacity/sdk-core/flows/NativeFlow';
|
|
9
|
-
export { NativeFlow } from '@strivacity/sdk-core/flows/NativeFlow';
|
|
10
|
-
export { HttpClient } from '@strivacity/sdk-core/utils/HttpClient';
|
|
11
|
-
export { DefaultLogging } from '@strivacity/sdk-core/utils/Logging';
|
|
12
|
-
export { LocalStorage } from '@strivacity/sdk-core/storages/LocalStorage';
|
|
13
|
-
export { SessionStorage } from '@strivacity/sdk-core/storages/SessionStorage';
|
|
14
|
-
export { createCredential, getCredential } from '@strivacity/sdk-core/utils/credentials';
|
|
15
|
-
import { Ref } from 'vue';
|
|
2
|
+
import { NuxtServerSDKInitConfig } from '../dist/runtime/types.js';
|
|
3
|
+
export * from '../dist/runtime/types.js';
|
|
16
4
|
|
|
17
|
-
|
|
18
|
-
* Represents the session state, including authentication details and token information.
|
|
19
|
-
*/
|
|
20
|
-
type Session = {
|
|
21
|
-
/**
|
|
22
|
-
* Reactive reference to the loading state of the session.
|
|
23
|
-
* `true` when the session is initializing, otherwise `false`.
|
|
24
|
-
*/
|
|
25
|
-
loading: Ref<boolean>;
|
|
26
|
-
/**
|
|
27
|
-
* The SDK options used to configure the session.
|
|
28
|
-
*/
|
|
29
|
-
options: Ref<SDKOptions>;
|
|
30
|
-
/**
|
|
31
|
-
* Reactive reference to the user's authentication status.
|
|
32
|
-
* `true` if the user is authenticated, otherwise `false`.
|
|
33
|
-
*/
|
|
34
|
-
isAuthenticated: Ref<boolean>;
|
|
35
|
-
/**
|
|
36
|
-
* Reactive reference to the claims contained in the ID token.
|
|
37
|
-
* Contains user identity and other information, or `null` if not authenticated.
|
|
38
|
-
*/
|
|
39
|
-
idTokenClaims: Ref<IdTokenClaims | null>;
|
|
40
|
-
/**
|
|
41
|
-
* Reactive reference to the current access token for API authorization.
|
|
42
|
-
* `null` if the user is not authenticated or the token is unavailable.
|
|
43
|
-
*/
|
|
44
|
-
accessToken: Ref<string | null>;
|
|
45
|
-
/**
|
|
46
|
-
* Reactive reference to the refresh token, used to refresh the access token.
|
|
47
|
-
* `null` if the user is not authenticated or the refresh token is unavailable.
|
|
48
|
-
*/
|
|
49
|
-
refreshToken: Ref<string | null>;
|
|
50
|
-
/**
|
|
51
|
-
* Reactive reference indicating if the access token has expired.
|
|
52
|
-
* `true` if expired, otherwise `false`.
|
|
53
|
-
*/
|
|
54
|
-
accessTokenExpired: Ref<boolean>;
|
|
55
|
-
/**
|
|
56
|
-
* Reactive reference to the expiration date of the access token in Unix time (milliseconds).
|
|
57
|
-
* `null` if no token is available or the session is not authenticated.
|
|
58
|
-
*/
|
|
59
|
-
accessTokenExpirationDate: Ref<number | null>;
|
|
60
|
-
};
|
|
61
|
-
/**
|
|
62
|
-
* Represents the available authentication flows and operations for Popup-based interactions.
|
|
63
|
-
*/
|
|
64
|
-
type PopupSDK = {
|
|
65
|
-
sdk: InstanceType<typeof PopupFlow>;
|
|
66
|
-
/**
|
|
67
|
-
* Initiates the login process.
|
|
68
|
-
*/
|
|
69
|
-
login: InstanceType<typeof PopupFlow>['login'];
|
|
70
|
-
/**
|
|
71
|
-
* Registers a new user.
|
|
72
|
-
*/
|
|
73
|
-
register: InstanceType<typeof PopupFlow>['register'];
|
|
74
|
-
/**
|
|
75
|
-
* Initiates the entry process.
|
|
76
|
-
*/
|
|
77
|
-
entry: InstanceType<typeof PopupFlow>['entry'];
|
|
78
|
-
/**
|
|
79
|
-
* Refreshes the user's session.
|
|
80
|
-
*/
|
|
81
|
-
refresh: InstanceType<typeof PopupFlow>['refresh'];
|
|
82
|
-
/**
|
|
83
|
-
* Revokes the current session tokens.
|
|
84
|
-
*/
|
|
85
|
-
revoke: InstanceType<typeof PopupFlow>['revoke'];
|
|
86
|
-
/**
|
|
87
|
-
* Logs out the user.
|
|
88
|
-
*/
|
|
89
|
-
logout: InstanceType<typeof PopupFlow>['logout'];
|
|
90
|
-
/**
|
|
91
|
-
* Handles the callback after authentication or token exchange.
|
|
92
|
-
*/
|
|
93
|
-
handleCallback: InstanceType<typeof PopupFlow>['handleCallback'];
|
|
94
|
-
};
|
|
95
|
-
/**
|
|
96
|
-
* Represents the available authentication flows and operations for Redirect-based interactions.
|
|
97
|
-
*/
|
|
98
|
-
type RedirectSDK = {
|
|
99
|
-
sdk: InstanceType<typeof RedirectFlow>;
|
|
100
|
-
/**
|
|
101
|
-
* Initiates the login process.
|
|
102
|
-
*/
|
|
103
|
-
login: InstanceType<typeof RedirectFlow>['login'];
|
|
104
|
-
/**
|
|
105
|
-
* Registers a new user.
|
|
106
|
-
*/
|
|
107
|
-
register: InstanceType<typeof RedirectFlow>['register'];
|
|
108
|
-
/**
|
|
109
|
-
* Initiates the entry process.
|
|
110
|
-
*/
|
|
111
|
-
entry: InstanceType<typeof RedirectFlow>['entry'];
|
|
112
|
-
/**
|
|
113
|
-
* Refreshes the user's session.
|
|
114
|
-
*/
|
|
115
|
-
refresh: InstanceType<typeof RedirectFlow>['refresh'];
|
|
116
|
-
/**
|
|
117
|
-
* Revokes the current session tokens.
|
|
118
|
-
*/
|
|
119
|
-
revoke: InstanceType<typeof RedirectFlow>['revoke'];
|
|
120
|
-
/**
|
|
121
|
-
* Logs out the user.
|
|
122
|
-
*/
|
|
123
|
-
logout: InstanceType<typeof RedirectFlow>['logout'];
|
|
124
|
-
/**
|
|
125
|
-
* Handles the callback after authentication or token exchange.
|
|
126
|
-
*/
|
|
127
|
-
handleCallback: InstanceType<typeof RedirectFlow>['handleCallback'];
|
|
128
|
-
};
|
|
129
|
-
/**
|
|
130
|
-
* Represents the available authentication flows and operations for Native-based interactions.
|
|
131
|
-
*/
|
|
132
|
-
type NativeSDK = {
|
|
133
|
-
sdk: InstanceType<typeof NativeFlow>;
|
|
134
|
-
/**
|
|
135
|
-
* Initiates the login process.
|
|
136
|
-
*/
|
|
137
|
-
login: InstanceType<typeof NativeFlow>['login'];
|
|
138
|
-
/**
|
|
139
|
-
* Registers a new user.
|
|
140
|
-
*/
|
|
141
|
-
register: InstanceType<typeof NativeFlow>['register'];
|
|
142
|
-
/**
|
|
143
|
-
* Initiates the entry process.
|
|
144
|
-
*/
|
|
145
|
-
entry: InstanceType<typeof NativeFlow>['entry'];
|
|
146
|
-
/**
|
|
147
|
-
* Refreshes the user's session.
|
|
148
|
-
*/
|
|
149
|
-
refresh: InstanceType<typeof NativeFlow>['refresh'];
|
|
150
|
-
/**
|
|
151
|
-
* Revokes the current session tokens.
|
|
152
|
-
*/
|
|
153
|
-
revoke: InstanceType<typeof NativeFlow>['revoke'];
|
|
154
|
-
/**
|
|
155
|
-
* Logs out the user.
|
|
156
|
-
*/
|
|
157
|
-
logout: InstanceType<typeof NativeFlow>['logout'];
|
|
158
|
-
/**
|
|
159
|
-
* Handles the callback after authentication or token exchange.
|
|
160
|
-
*/
|
|
161
|
-
handleCallback: InstanceType<typeof NativeFlow>['handleCallback'];
|
|
162
|
-
};
|
|
163
|
-
/**
|
|
164
|
-
* Represents a combined context for Popup-based flows, containing both the Popup SDK and the session state.
|
|
165
|
-
*/
|
|
166
|
-
type PopupContext = PopupSDK & Session;
|
|
167
|
-
/**
|
|
168
|
-
* Represents a combined context for Redirect-based flows, containing both the Redirect SDK and the session state.
|
|
169
|
-
*/
|
|
170
|
-
type RedirectContext = RedirectSDK & Session;
|
|
171
|
-
/**
|
|
172
|
-
* Represents a combined context for Redirect-based flows, containing both the Redirect SDK and the session state.
|
|
173
|
-
*/
|
|
174
|
-
type NativeContext = NativeSDK & Session;
|
|
175
|
-
type NativeFlowContextValue = {
|
|
176
|
-
loading: Ref<boolean>;
|
|
177
|
-
forms: Ref<Record<string, Record<string, unknown>>>;
|
|
178
|
-
messages: Ref<Record<string, Record<string, LoginFlowMessage>>>;
|
|
179
|
-
state: Ref<Partial<LoginFlowState>>;
|
|
180
|
-
submitForm: (formId: string) => Promise<void>;
|
|
181
|
-
triggerFallback: (hostedUrl?: string) => void;
|
|
182
|
-
triggerClose: () => void;
|
|
183
|
-
setFormValue: (formId: string, widgetId: string, value: unknown) => void;
|
|
184
|
-
setMessage: (formId: string, widgetId: string, value: LoginFlowMessage) => void;
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
declare module '@nuxt/schema' {
|
|
188
|
-
interface PublicRuntimeConfig {
|
|
189
|
-
strivacity: SDKOptions;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
type ModuleOptions = SDKOptions;
|
|
193
|
-
|
|
194
|
-
declare const _default: _nuxt_schema.NuxtModule<SDKOptions, SDKOptions, false>;
|
|
5
|
+
declare const _default: _nuxt_schema.NuxtModule<NuxtServerSDKInitConfig, NuxtServerSDKInitConfig, false>;
|
|
195
6
|
|
|
196
7
|
export { _default as default };
|
|
197
|
-
export type { ModuleOptions, NativeContext, NativeFlowContextValue, NativeSDK, PopupContext, PopupSDK, RedirectContext, RedirectSDK, Session };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,67 +1,88 @@
|
|
|
1
|
-
import { defineNuxtModule, createResolver,
|
|
2
|
-
export { HttpClient } from '@strivacity/sdk-core/utils/HttpClient';
|
|
3
|
-
export { DefaultLogging } from '@strivacity/sdk-core/utils/Logging';
|
|
4
|
-
import { LocalStorage } from '@strivacity/sdk-core/storages/LocalStorage';
|
|
5
|
-
export { LocalStorage } from '@strivacity/sdk-core/storages/LocalStorage';
|
|
6
|
-
export { SessionStorage } from '@strivacity/sdk-core/storages/SessionStorage';
|
|
7
|
-
export * from '@strivacity/sdk-core';
|
|
8
|
-
export { createCredential, getCredential } from '@strivacity/sdk-core/utils/credentials';
|
|
1
|
+
import { defineNuxtModule, createResolver, resolvePath, addImportsDir, addServerImportsDir, addServerPlugin, addRouteMiddleware, addServerHandler } from '@nuxt/kit';
|
|
9
2
|
|
|
10
|
-
const module = defineNuxtModule({
|
|
3
|
+
const module$1 = defineNuxtModule({
|
|
11
4
|
meta: {
|
|
12
5
|
name: "@strivacity/sdk-nuxt",
|
|
13
6
|
configKey: "strivacity"
|
|
14
7
|
},
|
|
15
|
-
|
|
16
|
-
setup(options, nuxt) {
|
|
8
|
+
setup: async (options, nuxt) => {
|
|
17
9
|
const resolver = createResolver(import.meta.url);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
10
|
+
if (!options.authUrlPrefix) {
|
|
11
|
+
options.authUrlPrefix = "/auth";
|
|
12
|
+
}
|
|
13
|
+
if (typeof options.serverSessionUri === "undefined") {
|
|
14
|
+
options.serverSessionUri = `${options.authUrlPrefix}/login`;
|
|
15
|
+
}
|
|
16
|
+
const { secret, storageFactoryPath, stateStorageFactoryPath, loggingFactoryPath, httpClientFactoryPath, ...publicOptions } = options;
|
|
17
|
+
const noop = resolver.resolve("./runtime/utils/noop");
|
|
18
|
+
nuxt.options.runtimeConfig.strivacity = options;
|
|
19
|
+
nuxt.options.runtimeConfig.public.strivacity = publicOptions;
|
|
20
|
+
nuxt.options.alias = nuxt.options.alias || {};
|
|
21
|
+
nuxt.options.nitro.alias = nuxt.options.nitro.alias || {};
|
|
22
|
+
const loggingPath = options.loggingFactoryPath ? await resolvePath(options.loggingFactoryPath) : noop;
|
|
23
|
+
const httpClientPath = options.httpClientFactoryPath ? await resolvePath(options.httpClientFactoryPath) : noop;
|
|
24
|
+
const storagePath = options.storageFactoryPath ? await resolvePath(options.storageFactoryPath) : noop;
|
|
25
|
+
const stateStoragePath = options.stateStorageFactoryPath ? await resolvePath(options.stateStorageFactoryPath) : noop;
|
|
26
|
+
nuxt.options.alias["#strivacity-options-logging"] = loggingPath;
|
|
27
|
+
nuxt.options.alias["#strivacity-options-httpClient"] = httpClientPath;
|
|
28
|
+
nuxt.options.alias["#strivacity-options-storage"] = storagePath;
|
|
29
|
+
nuxt.options.alias["#strivacity-options-stateStorage"] = stateStoragePath;
|
|
30
|
+
nuxt.options.nitro.alias["#strivacity-options-logging"] = loggingPath;
|
|
31
|
+
nuxt.options.nitro.alias["#strivacity-options-httpClient"] = httpClientPath;
|
|
32
|
+
nuxt.options.nitro.alias["#strivacity-options-storage"] = storagePath;
|
|
33
|
+
nuxt.options.nitro.alias["#strivacity-options-stateStorage"] = stateStoragePath;
|
|
34
|
+
addImportsDir(resolver.resolve("./runtime/composables"));
|
|
35
|
+
addImportsDir(resolver.resolve("./runtime/storages"));
|
|
36
|
+
addImportsDir(resolver.resolve("./runtime/utils"));
|
|
37
|
+
if (options.serverSessionUri) {
|
|
38
|
+
addServerImportsDir(resolver.resolve("./runtime/server/composables"));
|
|
39
|
+
addServerImportsDir(resolver.resolve("./runtime/server/utils"));
|
|
40
|
+
addServerImportsDir(resolver.resolve("./runtime/storages"));
|
|
41
|
+
addServerPlugin(resolver.resolve("./runtime/server/plugins/auth.server"));
|
|
42
|
+
addRouteMiddleware({ name: "strivacity", path: resolver.resolve("./runtime/middleware/auth.server"), global: true });
|
|
43
|
+
addServerHandler({
|
|
44
|
+
method: "get",
|
|
45
|
+
route: `${options.authUrlPrefix}/login`,
|
|
46
|
+
handler: resolver.resolve("./runtime/server/api/auth/login.get")
|
|
47
|
+
});
|
|
48
|
+
addServerHandler({
|
|
49
|
+
method: "get",
|
|
50
|
+
route: `${options.authUrlPrefix}/register`,
|
|
51
|
+
handler: resolver.resolve("./runtime/server/api/auth/register.get")
|
|
52
|
+
});
|
|
53
|
+
addServerHandler({
|
|
54
|
+
method: "get",
|
|
55
|
+
route: `${options.authUrlPrefix}/callback`,
|
|
56
|
+
handler: resolver.resolve("./runtime/server/api/auth/callback.get")
|
|
57
|
+
});
|
|
58
|
+
addServerHandler({
|
|
59
|
+
method: "get",
|
|
60
|
+
route: `${options.authUrlPrefix}/refresh`,
|
|
61
|
+
handler: resolver.resolve("./runtime/server/api/auth/refresh.get")
|
|
62
|
+
});
|
|
63
|
+
addServerHandler({
|
|
64
|
+
method: "get",
|
|
65
|
+
route: `${options.authUrlPrefix}/revoke`,
|
|
66
|
+
handler: resolver.resolve("./runtime/server/api/auth/revoke.get")
|
|
67
|
+
});
|
|
68
|
+
addServerHandler({
|
|
69
|
+
method: "get",
|
|
70
|
+
route: `${options.authUrlPrefix}/entry`,
|
|
71
|
+
handler: resolver.resolve("./runtime/server/api/auth/entry.get")
|
|
72
|
+
});
|
|
73
|
+
addServerHandler({
|
|
74
|
+
method: "get",
|
|
75
|
+
route: `${options.authUrlPrefix}/logout`,
|
|
76
|
+
handler: resolver.resolve("./runtime/server/api/auth/logout.get")
|
|
77
|
+
});
|
|
78
|
+
addServerHandler({
|
|
79
|
+
method: "get",
|
|
80
|
+
route: `${options.authUrlPrefix}/backchannel-logout`,
|
|
81
|
+
handler: resolver.resolve("./runtime/server/api/auth/backchannel-logout.get")
|
|
82
|
+
});
|
|
83
|
+
}
|
|
63
84
|
}
|
|
64
85
|
});
|
|
65
86
|
|
|
66
|
-
export { module as default };
|
|
87
|
+
export { module$1 as default };
|
|
67
88
|
//# sourceMappingURL=module.mjs.map
|
package/dist/module.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.mjs","sources":["../src/module.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"module.mjs","sources":["../src/module.ts"],"sourcesContent":["import type { NuxtServerSDKInitConfig } from './runtime/types';\nimport {\n\tdefineNuxtModule,\n\tresolvePath,\n\tcreateResolver,\n\taddImportsDir,\n\taddServerImportsDir,\n\taddServerHandler,\n\taddServerPlugin,\n\taddRouteMiddleware,\n} from '@nuxt/kit';\n\nexport type * from './runtime/types';\n\nexport default defineNuxtModule<NuxtServerSDKInitConfig>({\n\tmeta: {\n\t\tname: '@strivacity/sdk-nuxt',\n\t\tconfigKey: 'strivacity',\n\t},\n\tsetup: async (options, nuxt) => {\n\t\tconst resolver = createResolver(import.meta.url);\n\n\t\tif (!options.authUrlPrefix) {\n\t\t\toptions.authUrlPrefix = '/auth';\n\t\t}\n\t\tif (typeof options.serverSessionUri === 'undefined') {\n\t\t\toptions.serverSessionUri = `${options.authUrlPrefix}/login`;\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t\tconst { secret, storageFactoryPath, stateStorageFactoryPath, loggingFactoryPath, httpClientFactoryPath, ...publicOptions } = options;\n\t\tconst noop = resolver.resolve('./runtime/utils/noop');\n\n\t\tnuxt.options.runtimeConfig.strivacity = options;\n\t\tnuxt.options.runtimeConfig.public.strivacity = publicOptions;\n\t\tnuxt.options.alias = nuxt.options.alias || {};\n\t\tnuxt.options.nitro.alias = nuxt.options.nitro.alias || {};\n\n\t\tconst loggingPath = options.loggingFactoryPath ? await resolvePath(options.loggingFactoryPath) : noop;\n\t\tconst httpClientPath = options.httpClientFactoryPath ? await resolvePath(options.httpClientFactoryPath) : noop;\n\t\tconst storagePath = options.storageFactoryPath ? await resolvePath(options.storageFactoryPath) : noop;\n\t\tconst stateStoragePath = options.stateStorageFactoryPath ? await resolvePath(options.stateStorageFactoryPath) : noop;\n\n\t\tnuxt.options.alias['#strivacity-options-logging'] = loggingPath;\n\t\tnuxt.options.alias['#strivacity-options-httpClient'] = httpClientPath;\n\t\tnuxt.options.alias['#strivacity-options-storage'] = storagePath;\n\t\tnuxt.options.alias['#strivacity-options-stateStorage'] = stateStoragePath;\n\t\tnuxt.options.nitro.alias['#strivacity-options-logging'] = loggingPath;\n\t\tnuxt.options.nitro.alias['#strivacity-options-httpClient'] = httpClientPath;\n\t\tnuxt.options.nitro.alias['#strivacity-options-storage'] = storagePath;\n\t\tnuxt.options.nitro.alias['#strivacity-options-stateStorage'] = stateStoragePath;\n\n\t\taddImportsDir(resolver.resolve('./runtime/composables'));\n\t\taddImportsDir(resolver.resolve('./runtime/storages'));\n\t\taddImportsDir(resolver.resolve('./runtime/utils'));\n\n\t\tif (options.serverSessionUri) {\n\t\t\taddServerImportsDir(resolver.resolve('./runtime/server/composables'));\n\t\t\taddServerImportsDir(resolver.resolve('./runtime/server/utils'));\n\t\t\taddServerImportsDir(resolver.resolve('./runtime/storages'));\n\n\t\t\taddServerPlugin(resolver.resolve('./runtime/server/plugins/auth.server'));\n\t\t\taddRouteMiddleware({ name: 'strivacity', path: resolver.resolve('./runtime/middleware/auth.server'), global: true });\n\n\t\t\taddServerHandler({\n\t\t\t\tmethod: 'get',\n\t\t\t\troute: `${options.authUrlPrefix}/login`,\n\t\t\t\thandler: resolver.resolve('./runtime/server/api/auth/login.get'),\n\t\t\t});\n\t\t\taddServerHandler({\n\t\t\t\tmethod: 'get',\n\t\t\t\troute: `${options.authUrlPrefix}/register`,\n\t\t\t\thandler: resolver.resolve('./runtime/server/api/auth/register.get'),\n\t\t\t});\n\t\t\taddServerHandler({\n\t\t\t\tmethod: 'get',\n\t\t\t\troute: `${options.authUrlPrefix}/callback`,\n\t\t\t\thandler: resolver.resolve('./runtime/server/api/auth/callback.get'),\n\t\t\t});\n\t\t\taddServerHandler({\n\t\t\t\tmethod: 'get',\n\t\t\t\troute: `${options.authUrlPrefix}/refresh`,\n\t\t\t\thandler: resolver.resolve('./runtime/server/api/auth/refresh.get'),\n\t\t\t});\n\t\t\taddServerHandler({\n\t\t\t\tmethod: 'get',\n\t\t\t\troute: `${options.authUrlPrefix}/revoke`,\n\t\t\t\thandler: resolver.resolve('./runtime/server/api/auth/revoke.get'),\n\t\t\t});\n\t\t\taddServerHandler({\n\t\t\t\tmethod: 'get',\n\t\t\t\troute: `${options.authUrlPrefix}/entry`,\n\t\t\t\thandler: resolver.resolve('./runtime/server/api/auth/entry.get'),\n\t\t\t});\n\t\t\taddServerHandler({\n\t\t\t\tmethod: 'get',\n\t\t\t\troute: `${options.authUrlPrefix}/logout`,\n\t\t\t\thandler: resolver.resolve('./runtime/server/api/auth/logout.get'),\n\t\t\t});\n\t\t\taddServerHandler({\n\t\t\t\tmethod: 'get',\n\t\t\t\troute: `${options.authUrlPrefix}/backchannel-logout`,\n\t\t\t\thandler: resolver.resolve('./runtime/server/api/auth/backchannel-logout.get'),\n\t\t\t});\n\t\t}\n\t},\n});\n"],"names":[],"mappings":";;AAcA,iBAAe,gBAAA,CAA0C;AAAA,EACxD,IAAA,EAAM;AAAA,IACL,IAAA,EAAM,sBAAA;AAAA,IACN,SAAA,EAAW;AAAA,GACZ;AAAA,EACA,KAAA,EAAO,OAAO,OAAA,EAAS,IAAA,KAAS;AAC/B,IAAA,MAAM,QAAA,GAAW,cAAA,CAAe,MAAA,CAAA,IAAA,CAAY,GAAG,CAAA;AAE/C,IAAA,IAAI,CAAC,QAAQ,aAAA,EAAe;AAC3B,MAAA,OAAA,CAAQ,aAAA,GAAgB,OAAA;AAAA,IACzB;AACA,IAAA,IAAI,OAAO,OAAA,CAAQ,gBAAA,KAAqB,WAAA,EAAa;AACpD,MAAA,OAAA,CAAQ,gBAAA,GAAmB,CAAA,EAAG,OAAA,CAAQ,aAAa,CAAA,MAAA,CAAA;AAAA,IACpD;AAGA,IAAA,MAAM,EAAE,QAAQ,kBAAA,EAAoB,uBAAA,EAAyB,oBAAoB,qBAAA,EAAuB,GAAG,eAAc,GAAI,OAAA;AAC7H,IAAA,MAAM,IAAA,GAAO,QAAA,CAAS,OAAA,CAAQ,sBAAsB,CAAA;AAEpD,IAAA,IAAA,CAAK,OAAA,CAAQ,cAAc,UAAA,GAAa,OAAA;AACxC,IAAA,IAAA,CAAK,OAAA,CAAQ,aAAA,CAAc,MAAA,CAAO,UAAA,GAAa,aAAA;AAC/C,IAAA,IAAA,CAAK,OAAA,CAAQ,KAA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2
|
+
import type { LoginContext } from '../types.js';
|
|
3
|
+
export declare const STRIVACITY_LOGIN_CONTEXT: InjectionKey<LoginContext>;
|
|
4
|
+
/**
|
|
5
|
+
* A composable to access the Strivacity SDK context specifically for native login flow.
|
|
6
|
+
*
|
|
7
|
+
* @returns {LoginContext} - The native flow context.
|
|
8
|
+
* @throws {Error} - If the Strivacity SDK context is not found.
|
|
9
|
+
*/
|
|
10
|
+
export declare const useNativeLoginContext: () => LoginContext;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { inject } from "vue";
|
|
2
|
+
export const STRIVACITY_LOGIN_CONTEXT = Symbol("strivacity-login-context");
|
|
3
|
+
export const useNativeLoginContext = () => {
|
|
4
|
+
const context = inject(STRIVACITY_LOGIN_CONTEXT);
|
|
5
|
+
if (!context) {
|
|
6
|
+
throw new Error("Missing SDK native login context");
|
|
7
|
+
}
|
|
8
|
+
return context;
|
|
9
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { UseNativeLoginOptions } from '../types.js';
|
|
2
|
+
import { type useNativeLoginContext } from './use-native-login-context.js';
|
|
3
|
+
/**
|
|
4
|
+
* A composable that manages a native login flow session.
|
|
5
|
+
*
|
|
6
|
+
* @param {UseNativeLoginOptions} [options] - Optional options for the login session.
|
|
7
|
+
* @returns {LoginContext} - The native flow context.
|
|
8
|
+
* @throws {Error} - If the Strivacity SDK context is not found.
|
|
9
|
+
*/
|
|
10
|
+
export declare function useNativeLogin(options?: UseNativeLoginOptions): ReturnType<typeof useNativeLoginContext>;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { STRIVACITY_LOGIN_CONTEXT } from "./use-native-login-context.js";
|
|
2
|
+
import { provide, ref, onMounted, onUnmounted } from "vue";
|
|
3
|
+
import { FallbackError } from "@strivacity/sdk-core/utils/errors";
|
|
4
|
+
import { unflattenObject } from "@strivacity/sdk-core/utils";
|
|
5
|
+
import { useStrivacity } from "./use-strivacity.js";
|
|
6
|
+
export function useNativeLogin(options = {}) {
|
|
7
|
+
const abortController = new AbortController();
|
|
8
|
+
const { sdk } = useStrivacity();
|
|
9
|
+
const loading = ref(true);
|
|
10
|
+
const forms = ref({});
|
|
11
|
+
const messages = ref({});
|
|
12
|
+
const state = ref({});
|
|
13
|
+
onMounted(async () => {
|
|
14
|
+
await sdk.init();
|
|
15
|
+
try {
|
|
16
|
+
await startSession(options.params);
|
|
17
|
+
} catch (error) {
|
|
18
|
+
if (error instanceof DOMException && error.name === "AbortError") {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
sdk.logging?.error("Error fetching authorization URI", error);
|
|
22
|
+
void options.onError?.(error);
|
|
23
|
+
loading.value = false;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
onUnmounted(() => abortController.abort());
|
|
27
|
+
function handleResponse(nextState) {
|
|
28
|
+
if (sdk.session) {
|
|
29
|
+
return void options.onLogin?.(sdk.session);
|
|
30
|
+
}
|
|
31
|
+
const newState = {
|
|
32
|
+
hostedUrl: nextState?.hostedUrl ?? state.value.hostedUrl,
|
|
33
|
+
finalizeUrl: nextState?.finalizeUrl ?? state.value.finalizeUrl,
|
|
34
|
+
screen: nextState?.screen ?? state.value.screen,
|
|
35
|
+
forms: nextState?.forms ?? state.value.forms,
|
|
36
|
+
layout: nextState?.layout ?? state.value.layout,
|
|
37
|
+
messages: nextState?.messages ?? {},
|
|
38
|
+
branding: nextState?.branding ?? state.value.branding
|
|
39
|
+
};
|
|
40
|
+
if (newState.screen !== state.value.screen) {
|
|
41
|
+
forms.value = {};
|
|
42
|
+
messages.value = {};
|
|
43
|
+
for (const form of newState.forms ?? []) {
|
|
44
|
+
forms.value[form.id] = {};
|
|
45
|
+
messages.value[form.id] = {};
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
sdk.logging?.info(`Updating screen: ${newState.screen}`);
|
|
49
|
+
}
|
|
50
|
+
for (const formId of Object.keys(newState.messages ?? {})) {
|
|
51
|
+
if (formId === "global") {
|
|
52
|
+
void options.onGlobalMessage?.(newState.messages?.global);
|
|
53
|
+
} else {
|
|
54
|
+
messages.value[formId] = newState.messages[formId] ?? {};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
state.value = newState;
|
|
58
|
+
if (!newState.finalizeUrl) {
|
|
59
|
+
loading.value = false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async function startSession(loginParams = {}) {
|
|
63
|
+
try {
|
|
64
|
+
loading.value = true;
|
|
65
|
+
const nextState = await sdk.startSession(loginParams);
|
|
66
|
+
if (nextState) {
|
|
67
|
+
handleResponse(nextState);
|
|
68
|
+
}
|
|
69
|
+
} catch (error) {
|
|
70
|
+
if (error instanceof FallbackError) {
|
|
71
|
+
sdk.logging?.error("Fallback error occurred", error);
|
|
72
|
+
void options.onFallback?.(error);
|
|
73
|
+
} else {
|
|
74
|
+
sdk.logging?.error("Error starting session", error);
|
|
75
|
+
void options.onError?.(error);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function triggerFallback(message) {
|
|
80
|
+
sdk.logging?.warn(message ? `Triggering fallback due to: ${message}` : "Triggering fallback");
|
|
81
|
+
if (!state.value.hostedUrl) {
|
|
82
|
+
const error = new Error("No hosted URL provided");
|
|
83
|
+
sdk.logging?.error("Fallback error", error);
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
void options.onFallback?.(new FallbackError(new URL(state.value.hostedUrl)));
|
|
87
|
+
}
|
|
88
|
+
function triggerClose() {
|
|
89
|
+
sdk.logging?.debug("Triggering close");
|
|
90
|
+
void options.onClose?.();
|
|
91
|
+
}
|
|
92
|
+
async function submitForm(formId, customBody) {
|
|
93
|
+
try {
|
|
94
|
+
loading.value = true;
|
|
95
|
+
const nextState = await sdk.submitForm(formId, customBody ?? unflattenObject(forms.value[formId] ?? {}));
|
|
96
|
+
if (nextState) {
|
|
97
|
+
handleResponse(nextState);
|
|
98
|
+
}
|
|
99
|
+
} catch (error) {
|
|
100
|
+
if (error instanceof FallbackError) {
|
|
101
|
+
sdk.logging?.error("Fallback error occurred", error);
|
|
102
|
+
void options.onFallback?.(error);
|
|
103
|
+
} else {
|
|
104
|
+
sdk.logging?.error("Error submitting form", error);
|
|
105
|
+
void options.onError?.(error);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function setFormValue(formId, widgetId, value) {
|
|
110
|
+
if (forms.value[formId] === void 0) {
|
|
111
|
+
forms.value[formId] = {};
|
|
112
|
+
}
|
|
113
|
+
forms.value[formId][widgetId] = value === "" ? null : value;
|
|
114
|
+
}
|
|
115
|
+
function setMessage(formId, widgetId, value) {
|
|
116
|
+
if (messages.value[formId] === void 0) {
|
|
117
|
+
messages.value[formId] = {};
|
|
118
|
+
}
|
|
119
|
+
messages.value[formId][widgetId] = value;
|
|
120
|
+
}
|
|
121
|
+
provide(STRIVACITY_LOGIN_CONTEXT, {
|
|
122
|
+
loading,
|
|
123
|
+
forms,
|
|
124
|
+
messages,
|
|
125
|
+
state,
|
|
126
|
+
triggerFallback,
|
|
127
|
+
triggerClose,
|
|
128
|
+
submitForm,
|
|
129
|
+
setFormValue,
|
|
130
|
+
setMessage
|
|
131
|
+
});
|
|
132
|
+
return {
|
|
133
|
+
loading,
|
|
134
|
+
forms,
|
|
135
|
+
messages,
|
|
136
|
+
state,
|
|
137
|
+
triggerFallback,
|
|
138
|
+
triggerClose,
|
|
139
|
+
submitForm,
|
|
140
|
+
setFormValue,
|
|
141
|
+
setMessage
|
|
142
|
+
};
|
|
143
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { SessionData } from '@strivacity/sdk-core/types';
|
|
2
|
+
import type { Ref } from '#imports';
|
|
3
|
+
/**
|
|
4
|
+
* A composable to access the Strivacity SDK session data.
|
|
5
|
+
*
|
|
6
|
+
* @returns {Ref<SessionData | undefined>} A ref containing the Strivacity SDK session data or undefined if not available.
|
|
7
|
+
*/
|
|
8
|
+
export declare const useSession: () => Ref<SessionData | undefined>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { EmbeddedFlow, NativeFlow, PopupFlow, RedirectFlow } from '@strivacity/sdk-core/types';
|
|
2
|
+
import type { SDKContext } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* A composable to access the Strivacity SDK context.
|
|
5
|
+
*
|
|
6
|
+
* @template T - The type of the Strivacity SDK flow (RedirectFlow, PopupFlow, NativeFlow, or EmbeddedFlow).
|
|
7
|
+
* @returns {SDKContext<T>} The Strivacity SDK context.
|
|
8
|
+
*/
|
|
9
|
+
export declare const useStrivacity: <T extends RedirectFlow | PopupFlow | NativeFlow | EmbeddedFlow = RedirectFlow | PopupFlow | NativeFlow | EmbeddedFlow>() => SDKContext<T>;
|