@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
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export {
|
|
2
|
+
FallbackError,
|
|
3
|
+
PopupBlockedError,
|
|
4
|
+
PopupClosedError,
|
|
5
|
+
UnsupportedFlowError,
|
|
6
|
+
SessionExpiredError,
|
|
7
|
+
NetworkError,
|
|
8
|
+
ServerError,
|
|
9
|
+
OidcError,
|
|
10
|
+
ProtocolError,
|
|
11
|
+
ConfigurationError,
|
|
12
|
+
InternalError,
|
|
13
|
+
throwTokenEndpointError,
|
|
14
|
+
throwHttpError,
|
|
15
|
+
assertWebAuthnCredential,
|
|
16
|
+
buildAuthorizationUrl,
|
|
17
|
+
buildCookieString,
|
|
18
|
+
buildEndSessionUrl,
|
|
19
|
+
createDefaultLogging,
|
|
20
|
+
createHttpClient,
|
|
21
|
+
createSession,
|
|
22
|
+
createState,
|
|
23
|
+
createWebAuthnCredential,
|
|
24
|
+
decodeBase64URL,
|
|
25
|
+
decodeJwt,
|
|
26
|
+
decryptString,
|
|
27
|
+
defaultOptions,
|
|
28
|
+
encodeBase64URL,
|
|
29
|
+
encryptString,
|
|
30
|
+
exchangeCode,
|
|
31
|
+
fetchFlowEntry,
|
|
32
|
+
finalizeLoginSession,
|
|
33
|
+
generateCodeChallenge,
|
|
34
|
+
generateCodeVerifier,
|
|
35
|
+
generateJwt,
|
|
36
|
+
generateRandomHex,
|
|
37
|
+
getDefaultFlowState,
|
|
38
|
+
getDiscoveryDocument,
|
|
39
|
+
getSDKOptions,
|
|
40
|
+
getServerSDKOptions,
|
|
41
|
+
injectScript,
|
|
42
|
+
isSessionExpired,
|
|
43
|
+
loadSession,
|
|
44
|
+
parseCookieHeader,
|
|
45
|
+
parseState,
|
|
46
|
+
proxyResponse,
|
|
47
|
+
pushSetCookie,
|
|
48
|
+
flushSetCookies,
|
|
49
|
+
refreshToken,
|
|
50
|
+
revokeToken,
|
|
51
|
+
serializeCookie,
|
|
52
|
+
serializeSession,
|
|
53
|
+
serializeState,
|
|
54
|
+
submitLoginForm,
|
|
55
|
+
timestamp,
|
|
56
|
+
toSafeRedirect,
|
|
57
|
+
unflattenObject,
|
|
58
|
+
verifyIdToken,
|
|
59
|
+
verifyJwt,
|
|
60
|
+
DISALLOWED_PROXY_HEADERS,
|
|
61
|
+
RETURN_TO_COOKIE,
|
|
62
|
+
BACKCHANNEL_LOGOUT_EVENT,
|
|
63
|
+
DEFAULT_COOKIE_MAX_AGE
|
|
64
|
+
} from "@strivacity/sdk-core/utils";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function (): undefined;
|
package/dist/types.d.mts
CHANGED
|
@@ -1,21 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import type { NuxtModule } from '@nuxt/schema'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import type { default as Module } from './module.mjs'
|
|
4
4
|
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
export { type HttpClient } from '@strivacity/sdk-core/utils/HttpClient'
|
|
8
|
-
|
|
9
|
-
export { type DefaultLogging } from '@strivacity/sdk-core/utils/Logging'
|
|
10
|
-
|
|
11
|
-
export { type LocalStorage } from '@strivacity/sdk-core/storages/LocalStorage'
|
|
12
|
-
|
|
13
|
-
export { type SessionStorage } from '@strivacity/sdk-core/storages/SessionStorage'
|
|
14
|
-
|
|
15
|
-
export { type createCredential, type getCredential } from '@strivacity/sdk-core/utils/credentials'
|
|
5
|
+
export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
|
|
16
6
|
|
|
17
7
|
export { default } from './module.mjs'
|
|
18
8
|
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
export * from '@strivacity/sdk-core'
|
|
9
|
+
export * from '../dist/runtime/types.js'
|
package/nuxt.config.ts
ADDED
package/package.json
CHANGED
|
@@ -1,24 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strivacity/sdk-nuxt",
|
|
3
|
-
"version": "
|
|
4
|
-
"license": "MIT",
|
|
3
|
+
"version": "4.0.0-beta.0",
|
|
5
4
|
"description": "Strivacity Nuxt SDK client",
|
|
5
|
+
"license": "MIT",
|
|
6
6
|
"author": "strivacity <opensource@strivacity.com>",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "https://github.com/Strivacity/sdk-js"
|
|
10
10
|
},
|
|
11
11
|
"type": "module",
|
|
12
|
-
"
|
|
13
|
-
"@strivacity/sdk-core": "3.0.2"
|
|
14
|
-
},
|
|
12
|
+
"sideEffects": false,
|
|
15
13
|
"main": "./dist/module.mjs",
|
|
16
14
|
"types": "./dist/types.d.mts",
|
|
15
|
+
"typesVersions": {
|
|
16
|
+
"*": {
|
|
17
|
+
".": [
|
|
18
|
+
"./dist/types.d.mts"
|
|
19
|
+
]
|
|
20
|
+
}
|
|
21
|
+
},
|
|
17
22
|
"exports": {
|
|
18
23
|
".": {
|
|
19
24
|
"types": "./dist/types.d.mts",
|
|
20
25
|
"import": "./dist/module.mjs",
|
|
21
26
|
"default": "./dist/module.mjs"
|
|
27
|
+
},
|
|
28
|
+
"./types": {
|
|
29
|
+
"types": "./dist/types.d.mts",
|
|
30
|
+
"import": "./dist/module.mjs",
|
|
31
|
+
"default": "./dist/module.mjs"
|
|
32
|
+
},
|
|
33
|
+
"./storages": {
|
|
34
|
+
"types": "./dist/runtime/storages/core.d.ts",
|
|
35
|
+
"import": "./dist/runtime/storages/core.js",
|
|
36
|
+
"default": "./dist/runtime/storages/core.js"
|
|
37
|
+
},
|
|
38
|
+
"./utils": {
|
|
39
|
+
"types": "./dist/runtime/utils/core.d.ts",
|
|
40
|
+
"import": "./dist/runtime/utils/core.js",
|
|
41
|
+
"default": "./dist/runtime/utils/core.js"
|
|
22
42
|
}
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@strivacity/sdk-core": "4.0.0-beta.0"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"nuxt": ">=4.0"
|
|
23
49
|
}
|
|
24
50
|
}
|
package/project.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
3
|
+
"name": "sdk-nuxt",
|
|
4
|
+
"projectType": "library",
|
|
5
|
+
"sourceRoot": "packages/sdk-nuxt/src",
|
|
6
|
+
"targets": {
|
|
7
|
+
"prepare": {
|
|
8
|
+
"executor": "nx:run-commands",
|
|
9
|
+
"options": {
|
|
10
|
+
"commands": [
|
|
11
|
+
{
|
|
12
|
+
"command": "nuxt-module-build build --stub --cwd packages/sdk-nuxt",
|
|
13
|
+
"forwardAllArgs": false
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"command": "nuxt-module-build prepare --cwd packages/sdk-nuxt",
|
|
17
|
+
"forwardAllArgs": false
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"parallel": false
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"build": {
|
|
24
|
+
"executor": "nx:run-commands",
|
|
25
|
+
"dependsOn": ["sdk-core:build", "prepare"],
|
|
26
|
+
"options": {
|
|
27
|
+
"commands": [
|
|
28
|
+
{
|
|
29
|
+
"command": "nuxt-module-build build --sourcemap --cwd packages/sdk-nuxt",
|
|
30
|
+
"forwardAllArgs": false
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"test": {
|
|
36
|
+
"executor": "nx:run-commands",
|
|
37
|
+
"dependsOn": ["build"],
|
|
38
|
+
"options": {
|
|
39
|
+
"cwd": "packages/sdk-nuxt",
|
|
40
|
+
"command": "vitest"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/module.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { NuxtServerSDKInitConfig } from './runtime/types';
|
|
2
|
+
import {
|
|
3
|
+
defineNuxtModule,
|
|
4
|
+
resolvePath,
|
|
5
|
+
createResolver,
|
|
6
|
+
addImportsDir,
|
|
7
|
+
addServerImportsDir,
|
|
8
|
+
addServerHandler,
|
|
9
|
+
addServerPlugin,
|
|
10
|
+
addRouteMiddleware,
|
|
11
|
+
} from '@nuxt/kit';
|
|
12
|
+
|
|
13
|
+
export type * from './runtime/types';
|
|
14
|
+
|
|
15
|
+
export default defineNuxtModule<NuxtServerSDKInitConfig>({
|
|
16
|
+
meta: {
|
|
17
|
+
name: '@strivacity/sdk-nuxt',
|
|
18
|
+
configKey: 'strivacity',
|
|
19
|
+
},
|
|
20
|
+
setup: async (options, nuxt) => {
|
|
21
|
+
const resolver = createResolver(import.meta.url);
|
|
22
|
+
|
|
23
|
+
if (!options.authUrlPrefix) {
|
|
24
|
+
options.authUrlPrefix = '/auth';
|
|
25
|
+
}
|
|
26
|
+
if (typeof options.serverSessionUri === 'undefined') {
|
|
27
|
+
options.serverSessionUri = `${options.authUrlPrefix}/login`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
31
|
+
const { secret, storageFactoryPath, stateStorageFactoryPath, loggingFactoryPath, httpClientFactoryPath, ...publicOptions } = options;
|
|
32
|
+
const noop = resolver.resolve('./runtime/utils/noop');
|
|
33
|
+
|
|
34
|
+
nuxt.options.runtimeConfig.strivacity = options;
|
|
35
|
+
nuxt.options.runtimeConfig.public.strivacity = publicOptions;
|
|
36
|
+
nuxt.options.alias = nuxt.options.alias || {};
|
|
37
|
+
nuxt.options.nitro.alias = nuxt.options.nitro.alias || {};
|
|
38
|
+
|
|
39
|
+
const loggingPath = options.loggingFactoryPath ? await resolvePath(options.loggingFactoryPath) : noop;
|
|
40
|
+
const httpClientPath = options.httpClientFactoryPath ? await resolvePath(options.httpClientFactoryPath) : noop;
|
|
41
|
+
const storagePath = options.storageFactoryPath ? await resolvePath(options.storageFactoryPath) : noop;
|
|
42
|
+
const stateStoragePath = options.stateStorageFactoryPath ? await resolvePath(options.stateStorageFactoryPath) : noop;
|
|
43
|
+
|
|
44
|
+
nuxt.options.alias['#strivacity-options-logging'] = loggingPath;
|
|
45
|
+
nuxt.options.alias['#strivacity-options-httpClient'] = httpClientPath;
|
|
46
|
+
nuxt.options.alias['#strivacity-options-storage'] = storagePath;
|
|
47
|
+
nuxt.options.alias['#strivacity-options-stateStorage'] = stateStoragePath;
|
|
48
|
+
nuxt.options.nitro.alias['#strivacity-options-logging'] = loggingPath;
|
|
49
|
+
nuxt.options.nitro.alias['#strivacity-options-httpClient'] = httpClientPath;
|
|
50
|
+
nuxt.options.nitro.alias['#strivacity-options-storage'] = storagePath;
|
|
51
|
+
nuxt.options.nitro.alias['#strivacity-options-stateStorage'] = stateStoragePath;
|
|
52
|
+
|
|
53
|
+
addImportsDir(resolver.resolve('./runtime/composables'));
|
|
54
|
+
addImportsDir(resolver.resolve('./runtime/storages'));
|
|
55
|
+
addImportsDir(resolver.resolve('./runtime/utils'));
|
|
56
|
+
|
|
57
|
+
if (options.serverSessionUri) {
|
|
58
|
+
addServerImportsDir(resolver.resolve('./runtime/server/composables'));
|
|
59
|
+
addServerImportsDir(resolver.resolve('./runtime/server/utils'));
|
|
60
|
+
addServerImportsDir(resolver.resolve('./runtime/storages'));
|
|
61
|
+
|
|
62
|
+
addServerPlugin(resolver.resolve('./runtime/server/plugins/auth.server'));
|
|
63
|
+
addRouteMiddleware({ name: 'strivacity', path: resolver.resolve('./runtime/middleware/auth.server'), global: true });
|
|
64
|
+
|
|
65
|
+
addServerHandler({
|
|
66
|
+
method: 'get',
|
|
67
|
+
route: `${options.authUrlPrefix}/login`,
|
|
68
|
+
handler: resolver.resolve('./runtime/server/api/auth/login.get'),
|
|
69
|
+
});
|
|
70
|
+
addServerHandler({
|
|
71
|
+
method: 'get',
|
|
72
|
+
route: `${options.authUrlPrefix}/register`,
|
|
73
|
+
handler: resolver.resolve('./runtime/server/api/auth/register.get'),
|
|
74
|
+
});
|
|
75
|
+
addServerHandler({
|
|
76
|
+
method: 'get',
|
|
77
|
+
route: `${options.authUrlPrefix}/callback`,
|
|
78
|
+
handler: resolver.resolve('./runtime/server/api/auth/callback.get'),
|
|
79
|
+
});
|
|
80
|
+
addServerHandler({
|
|
81
|
+
method: 'get',
|
|
82
|
+
route: `${options.authUrlPrefix}/refresh`,
|
|
83
|
+
handler: resolver.resolve('./runtime/server/api/auth/refresh.get'),
|
|
84
|
+
});
|
|
85
|
+
addServerHandler({
|
|
86
|
+
method: 'get',
|
|
87
|
+
route: `${options.authUrlPrefix}/revoke`,
|
|
88
|
+
handler: resolver.resolve('./runtime/server/api/auth/revoke.get'),
|
|
89
|
+
});
|
|
90
|
+
addServerHandler({
|
|
91
|
+
method: 'get',
|
|
92
|
+
route: `${options.authUrlPrefix}/entry`,
|
|
93
|
+
handler: resolver.resolve('./runtime/server/api/auth/entry.get'),
|
|
94
|
+
});
|
|
95
|
+
addServerHandler({
|
|
96
|
+
method: 'get',
|
|
97
|
+
route: `${options.authUrlPrefix}/logout`,
|
|
98
|
+
handler: resolver.resolve('./runtime/server/api/auth/logout.get'),
|
|
99
|
+
});
|
|
100
|
+
addServerHandler({
|
|
101
|
+
method: 'get',
|
|
102
|
+
route: `${options.authUrlPrefix}/backchannel-logout`,
|
|
103
|
+
handler: resolver.resolve('./runtime/server/api/auth/backchannel-logout.get'),
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { inject, type InjectionKey } from 'vue';
|
|
2
|
+
import type { LoginContext } from '../types';
|
|
3
|
+
|
|
4
|
+
export const STRIVACITY_LOGIN_CONTEXT: InjectionKey<LoginContext> = Symbol('strivacity-login-context');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A composable to access the Strivacity SDK context specifically for native login flow.
|
|
8
|
+
*
|
|
9
|
+
* @returns {LoginContext} - The native flow context.
|
|
10
|
+
* @throws {Error} - If the Strivacity SDK context is not found.
|
|
11
|
+
*/
|
|
12
|
+
export const useNativeLoginContext = (): LoginContext => {
|
|
13
|
+
const context = inject<LoginContext>(STRIVACITY_LOGIN_CONTEXT);
|
|
14
|
+
|
|
15
|
+
if (!context) {
|
|
16
|
+
throw new Error('Missing SDK native login context');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return context;
|
|
20
|
+
};
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import type { NativeFlow, NativeParams, NativeFlowState, NativeFlowMessage } from '@strivacity/sdk-core/types';
|
|
2
|
+
import type { LoginContext, UseNativeLoginOptions } from '../types';
|
|
3
|
+
import { STRIVACITY_LOGIN_CONTEXT, type useNativeLoginContext } from './use-native-login-context';
|
|
4
|
+
import { provide, ref, onMounted, onUnmounted } from 'vue';
|
|
5
|
+
import { FallbackError } from '@strivacity/sdk-core/utils/errors';
|
|
6
|
+
import { unflattenObject } from '@strivacity/sdk-core/utils';
|
|
7
|
+
import { useStrivacity } from './use-strivacity';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A composable that manages a native login flow session.
|
|
11
|
+
*
|
|
12
|
+
* @param {UseNativeLoginOptions} [options] - Optional options for the login session.
|
|
13
|
+
* @returns {LoginContext} - The native flow context.
|
|
14
|
+
* @throws {Error} - If the Strivacity SDK context is not found.
|
|
15
|
+
*/
|
|
16
|
+
export function useNativeLogin(options: UseNativeLoginOptions = {}): ReturnType<typeof useNativeLoginContext> {
|
|
17
|
+
const abortController = new AbortController();
|
|
18
|
+
const { sdk } = useStrivacity<NativeFlow>();
|
|
19
|
+
|
|
20
|
+
const loading = ref<boolean>(true);
|
|
21
|
+
const forms = ref<Record<string, Record<string, unknown>>>({});
|
|
22
|
+
const messages = ref<Record<string, Record<string, NativeFlowMessage>>>({});
|
|
23
|
+
const state = ref<Partial<NativeFlowState>>({});
|
|
24
|
+
|
|
25
|
+
onMounted(async () => {
|
|
26
|
+
await sdk.init();
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
await startSession(options.params);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
if (error instanceof DOMException && error.name === 'AbortError') {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
sdk.logging?.error('Error fetching authorization URI', error as Error);
|
|
36
|
+
void options.onError?.(error as Error);
|
|
37
|
+
loading.value = false;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
onUnmounted(() => abortController.abort());
|
|
42
|
+
|
|
43
|
+
function handleResponse(nextState: Partial<NativeFlowState>) {
|
|
44
|
+
if (sdk.session) {
|
|
45
|
+
return void options.onLogin?.(sdk.session);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const newState: NativeFlowState = {
|
|
49
|
+
hostedUrl: nextState?.hostedUrl ?? state.value.hostedUrl,
|
|
50
|
+
finalizeUrl: nextState?.finalizeUrl ?? state.value.finalizeUrl,
|
|
51
|
+
screen: nextState?.screen ?? state.value.screen,
|
|
52
|
+
forms: nextState?.forms ?? state.value.forms,
|
|
53
|
+
layout: nextState?.layout ?? state.value.layout,
|
|
54
|
+
messages: nextState?.messages ?? {},
|
|
55
|
+
branding: nextState?.branding ?? state.value.branding,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
if (newState.screen !== state.value.screen) {
|
|
59
|
+
forms.value = {};
|
|
60
|
+
messages.value = {};
|
|
61
|
+
|
|
62
|
+
for (const form of newState.forms ?? []) {
|
|
63
|
+
forms.value[form.id] = {};
|
|
64
|
+
messages.value[form.id] = {};
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
sdk.logging?.info(`Updating screen: ${newState.screen}`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
for (const formId of Object.keys(newState.messages ?? {})) {
|
|
71
|
+
if (formId === 'global') {
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
|
|
73
|
+
void options.onGlobalMessage?.(newState.messages?.global!);
|
|
74
|
+
} else {
|
|
75
|
+
messages.value[formId] = newState.messages![formId] ?? {};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
state.value = newState;
|
|
80
|
+
|
|
81
|
+
if (!newState.finalizeUrl) {
|
|
82
|
+
loading.value = false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function startSession(loginParams: NativeParams = {}) {
|
|
87
|
+
try {
|
|
88
|
+
loading.value = true;
|
|
89
|
+
|
|
90
|
+
const nextState = await sdk.startSession(loginParams);
|
|
91
|
+
|
|
92
|
+
if (nextState) {
|
|
93
|
+
handleResponse(nextState);
|
|
94
|
+
}
|
|
95
|
+
} catch (error) {
|
|
96
|
+
if (error instanceof FallbackError) {
|
|
97
|
+
sdk.logging?.error('Fallback error occurred', error);
|
|
98
|
+
void options.onFallback?.(error);
|
|
99
|
+
} else {
|
|
100
|
+
sdk.logging?.error('Error starting session', error as Error);
|
|
101
|
+
void options.onError?.(error as Error);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function triggerFallback(message?: string) {
|
|
107
|
+
sdk.logging?.warn(message ? `Triggering fallback due to: ${message}` : 'Triggering fallback');
|
|
108
|
+
|
|
109
|
+
if (!state.value.hostedUrl) {
|
|
110
|
+
const error = new Error('No hosted URL provided');
|
|
111
|
+
sdk.logging?.error('Fallback error', error);
|
|
112
|
+
throw error;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
void options.onFallback?.(new FallbackError(new URL(state.value.hostedUrl)));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function triggerClose() {
|
|
119
|
+
sdk.logging?.debug('Triggering close');
|
|
120
|
+
void options.onClose?.();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async function submitForm(formId: string, customBody?: Record<string, unknown>) {
|
|
124
|
+
try {
|
|
125
|
+
loading.value = true;
|
|
126
|
+
|
|
127
|
+
const nextState = await sdk.submitForm(formId, customBody ?? unflattenObject(forms.value[formId] ?? {}));
|
|
128
|
+
|
|
129
|
+
if (nextState) {
|
|
130
|
+
handleResponse(nextState);
|
|
131
|
+
}
|
|
132
|
+
} catch (error) {
|
|
133
|
+
if (error instanceof FallbackError) {
|
|
134
|
+
sdk.logging?.error('Fallback error occurred', error);
|
|
135
|
+
void options.onFallback?.(error);
|
|
136
|
+
} else {
|
|
137
|
+
sdk.logging?.error('Error submitting form', error as Error);
|
|
138
|
+
void options.onError?.(error as Error);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function setFormValue(formId: string, widgetId: string, value: unknown) {
|
|
144
|
+
if (forms.value[formId] === undefined) {
|
|
145
|
+
forms.value[formId] = {};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
forms.value[formId][widgetId] = value === '' ? null : value;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function setMessage(formId: string, widgetId: string, value: NativeFlowMessage) {
|
|
152
|
+
if (messages.value[formId] === undefined) {
|
|
153
|
+
messages.value[formId] = {};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
messages.value[formId][widgetId] = value;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
provide<LoginContext>(STRIVACITY_LOGIN_CONTEXT, {
|
|
160
|
+
loading,
|
|
161
|
+
forms,
|
|
162
|
+
messages,
|
|
163
|
+
state,
|
|
164
|
+
triggerFallback,
|
|
165
|
+
triggerClose,
|
|
166
|
+
submitForm,
|
|
167
|
+
setFormValue,
|
|
168
|
+
setMessage,
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
loading,
|
|
173
|
+
forms,
|
|
174
|
+
messages,
|
|
175
|
+
state,
|
|
176
|
+
triggerFallback,
|
|
177
|
+
triggerClose,
|
|
178
|
+
submitForm,
|
|
179
|
+
setFormValue,
|
|
180
|
+
setMessage,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SessionData } from '@strivacity/sdk-core/types';
|
|
2
|
+
import type { Ref } from '#imports';
|
|
3
|
+
import { useState } from '#imports';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A composable to access the Strivacity SDK session data.
|
|
7
|
+
*
|
|
8
|
+
* @returns {Ref<SessionData | undefined>} A ref containing the Strivacity SDK session data or undefined if not available.
|
|
9
|
+
*/
|
|
10
|
+
export const useSession = (): Ref<SessionData | undefined> => useState<SessionData | undefined>('strivacity_session', () => undefined);
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { EmbeddedFlow, IdTokenClaims, NativeFlow, PopupFlow, RedirectFlow } from '@strivacity/sdk-core/types';
|
|
2
|
+
import type { SDKContext } from '../types';
|
|
3
|
+
import { ref } from 'vue';
|
|
4
|
+
import { initFlow } from '@strivacity/sdk-core';
|
|
5
|
+
import { useRuntimeConfig } from '#app';
|
|
6
|
+
import { useSession } from './use-session';
|
|
7
|
+
import createLogging from '#strivacity-options-logging';
|
|
8
|
+
import createHttpClient from '#strivacity-options-httpClient';
|
|
9
|
+
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
+
let sdk: any;
|
|
12
|
+
|
|
13
|
+
const loadingRef = ref<boolean>(true);
|
|
14
|
+
const languageRef = ref<string>(globalThis.navigator?.language ?? 'en-US');
|
|
15
|
+
const isAuthenticatedRef = ref<boolean>(false);
|
|
16
|
+
const idTokenClaimsRef = ref<IdTokenClaims | null>(null);
|
|
17
|
+
const accessTokenRef = ref<string | null>(null);
|
|
18
|
+
const refreshTokenRef = ref<string | null>(null);
|
|
19
|
+
const accessTokenExpiredRef = ref<boolean>(true);
|
|
20
|
+
const accessTokenExpirationDateRef = ref<number | null>(null);
|
|
21
|
+
|
|
22
|
+
const updateSession = async () => {
|
|
23
|
+
const authenticated = await sdk.isAuthenticated;
|
|
24
|
+
|
|
25
|
+
if (loadingRef.value) {
|
|
26
|
+
loadingRef.value = false;
|
|
27
|
+
}
|
|
28
|
+
if (sdk.language !== languageRef.value) {
|
|
29
|
+
languageRef.value = sdk.language;
|
|
30
|
+
}
|
|
31
|
+
if (authenticated !== isAuthenticatedRef.value) {
|
|
32
|
+
isAuthenticatedRef.value = authenticated;
|
|
33
|
+
}
|
|
34
|
+
if (sdk.idTokenClaims !== idTokenClaimsRef.value) {
|
|
35
|
+
idTokenClaimsRef.value = sdk.idTokenClaims || null;
|
|
36
|
+
}
|
|
37
|
+
if (sdk.accessToken !== accessTokenRef.value) {
|
|
38
|
+
accessTokenRef.value = sdk.accessToken || null;
|
|
39
|
+
}
|
|
40
|
+
if (sdk.refreshToken !== refreshTokenRef.value) {
|
|
41
|
+
refreshTokenRef.value = sdk.refreshToken || null;
|
|
42
|
+
}
|
|
43
|
+
if (sdk.accessTokenExpired !== accessTokenExpiredRef.value) {
|
|
44
|
+
accessTokenExpiredRef.value = sdk.accessTokenExpired;
|
|
45
|
+
}
|
|
46
|
+
if (sdk.accessTokenExpirationDate !== accessTokenExpirationDateRef.value) {
|
|
47
|
+
accessTokenExpirationDateRef.value = sdk.accessTokenExpirationDate || null;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* A composable to access the Strivacity SDK context.
|
|
53
|
+
*
|
|
54
|
+
* @template T - The type of the Strivacity SDK flow (RedirectFlow, PopupFlow, NativeFlow, or EmbeddedFlow).
|
|
55
|
+
* @returns {SDKContext<T>} The Strivacity SDK context.
|
|
56
|
+
*/
|
|
57
|
+
export const useStrivacity = <
|
|
58
|
+
T extends RedirectFlow | PopupFlow | NativeFlow | EmbeddedFlow = RedirectFlow | PopupFlow | NativeFlow | EmbeddedFlow,
|
|
59
|
+
>(): SDKContext<T> => {
|
|
60
|
+
if (!sdk) {
|
|
61
|
+
sdk = initFlow({
|
|
62
|
+
...useRuntimeConfig().public.strivacity,
|
|
63
|
+
logging: createLogging ? createLogging() : undefined,
|
|
64
|
+
httpClient: createHttpClient ? createHttpClient() : undefined,
|
|
65
|
+
});
|
|
66
|
+
sdk.subscribeToAllEvents(updateSession);
|
|
67
|
+
|
|
68
|
+
sdk.session = useSession().value;
|
|
69
|
+
void updateSession();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
sdk,
|
|
74
|
+
loading: loadingRef,
|
|
75
|
+
language: languageRef,
|
|
76
|
+
isAuthenticated: isAuthenticatedRef,
|
|
77
|
+
idTokenClaims: idTokenClaimsRef,
|
|
78
|
+
accessToken: accessTokenRef,
|
|
79
|
+
refreshToken: refreshTokenRef,
|
|
80
|
+
accessTokenExpired: accessTokenExpiredRef,
|
|
81
|
+
accessTokenExpirationDate: accessTokenExpirationDateRef,
|
|
82
|
+
init: () => sdk.init(),
|
|
83
|
+
subscribeToEvent: ((...args: Parameters<typeof sdk.subscribeToEvent>) => sdk.subscribeToEvent(...args)) as typeof sdk.subscribeToEvent,
|
|
84
|
+
subscribeToAllEvents: (...args: Parameters<typeof sdk.subscribeToAllEvents>) => sdk.subscribeToAllEvents(...args),
|
|
85
|
+
checkAuthentication: (...args: Parameters<typeof sdk.checkAuthentication>) => sdk.checkAuthentication(...args),
|
|
86
|
+
tokenExchange: (...args: Parameters<typeof sdk.tokenExchange>) => sdk.tokenExchange(...args),
|
|
87
|
+
handleCallback: (...args: Parameters<typeof sdk.handleCallback>) => sdk.handleCallback(...args),
|
|
88
|
+
refresh: () => sdk.refresh(),
|
|
89
|
+
revoke: () => sdk.revoke(),
|
|
90
|
+
logout: (...args: Parameters<typeof sdk.logout>) => sdk.logout(...args),
|
|
91
|
+
login: (...args: Parameters<typeof sdk.login>) => sdk.login(...args),
|
|
92
|
+
register: (...args: Parameters<typeof sdk.register>) => sdk.register(...args),
|
|
93
|
+
entry: (...args: Parameters<typeof sdk.entry>) => sdk.entry(...args),
|
|
94
|
+
};
|
|
95
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineNuxtRouteMiddleware, useNuxtApp } from '#imports';
|
|
2
|
+
import { useSession } from '../composables/use-session';
|
|
3
|
+
|
|
4
|
+
export default defineNuxtRouteMiddleware(async () => {
|
|
5
|
+
if (!import.meta.server) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const app = useNuxtApp();
|
|
10
|
+
const h3Event = app.ssrContext!.event;
|
|
11
|
+
|
|
12
|
+
const { useStrivacity } = await import('../server/composables/use-strivacity');
|
|
13
|
+
const sdk = useStrivacity(h3Event);
|
|
14
|
+
|
|
15
|
+
useSession().value = (await sdk.getSession()) ?? undefined;
|
|
16
|
+
});
|