@strivacity/sdk-nuxt 4.0.0-beta.1 → 4.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/README.md +171 -101
  2. package/dist/module.mjs +5 -4
  3. package/package.json +2 -2
  4. package/project.json +3 -0
  5. package/src/module.ts +7 -3
  6. package/src/runtime/composables/use-native-login.ts +27 -159
  7. package/src/runtime/composables/use-strivacity.ts +217 -67
  8. package/src/runtime/middleware/auth.server.ts +10 -1
  9. package/src/runtime/plugins/strivacity.client.ts +17 -0
  10. package/src/runtime/server/plugins/auth.server.ts +66 -30
  11. package/src/runtime/storages/default.ts +22 -67
  12. package/src/runtime/types.ts +7 -36
  13. package/src/runtime/utils/core.ts +2 -0
  14. package/testing/stubs/app.ts +8 -0
  15. package/testing/tests/composables.spec.ts +104 -3
  16. package/testing/tests/module.spec.ts +46 -0
  17. package/testing/tests/server/plugin.spec.ts +48 -10
  18. package/testing/tests/server/routes.spec.ts +2 -2
  19. package/.nuxt/app-component.mjs +0 -1
  20. package/.nuxt/app.config.mjs +0 -21
  21. package/.nuxt/component-chunk.mjs +0 -1
  22. package/.nuxt/component-names.mjs +0 -1
  23. package/.nuxt/components.d.ts +0 -66
  24. package/.nuxt/components.islands.mjs +0 -8
  25. package/.nuxt/components.plugin.mjs +0 -5
  26. package/.nuxt/css.mjs +0 -0
  27. package/.nuxt/error-component.mjs +0 -1
  28. package/.nuxt/fetch.d.ts +0 -1
  29. package/.nuxt/fetch.mjs +0 -8
  30. package/.nuxt/global-polyfills.mjs +0 -4
  31. package/.nuxt/imports.d.ts +0 -41
  32. package/.nuxt/imports.mjs +0 -42
  33. package/.nuxt/island-renderer.mjs +0 -2
  34. package/.nuxt/layouts.mjs +0 -2
  35. package/.nuxt/manifest/meta/b2d6b125-90fd-44d4-9916-0898f71676da.json +0 -1
  36. package/.nuxt/middleware.mjs +0 -7
  37. package/.nuxt/nitro.client.mjs +0 -2
  38. package/.nuxt/nuxt.config.mjs +0 -103
  39. package/.nuxt/nuxt.d.ts +0 -19
  40. package/.nuxt/nuxt.node.d.ts +0 -13
  41. package/.nuxt/nuxt.shared.d.ts +0 -7
  42. package/.nuxt/pages.mjs +0 -2
  43. package/.nuxt/paths.mjs +0 -15
  44. package/.nuxt/plugins.client.mjs +0 -14
  45. package/.nuxt/plugins.server.mjs +0 -10
  46. package/.nuxt/root-component.mjs +0 -1
  47. package/.nuxt/route-rules.mjs +0 -22
  48. package/.nuxt/router.options.mjs +0 -2
  49. package/.nuxt/schema/nuxt.schema.d.ts +0 -17
  50. package/.nuxt/schema/nuxt.schema.json +0 -3
  51. package/.nuxt/test-component-wrapper.mjs +0 -1
  52. package/.nuxt/tsconfig.app.json +0 -211
  53. package/.nuxt/tsconfig.json +0 -212
  54. package/.nuxt/tsconfig.node.json +0 -117
  55. package/.nuxt/tsconfig.server.json +0 -161
  56. package/.nuxt/tsconfig.shared.json +0 -165
  57. package/.nuxt/types/app.config.d.ts +0 -35
  58. package/.nuxt/types/build.d.ts +0 -0
  59. package/.nuxt/types/builder-env.d.ts +0 -1
  60. package/.nuxt/types/components.d.ts +0 -71
  61. package/.nuxt/types/imports.d.ts +0 -2
  62. package/.nuxt/types/layouts.d.ts +0 -16
  63. package/.nuxt/types/middleware.d.ts +0 -11
  64. package/.nuxt/types/modules.d.ts +0 -59
  65. package/.nuxt/types/nitro-config.d.ts +0 -14
  66. package/.nuxt/types/nitro-imports.d.ts +0 -20
  67. package/.nuxt/types/nitro-layouts.d.ts +0 -17
  68. package/.nuxt/types/nitro-nuxt.d.ts +0 -75
  69. package/.nuxt/types/nitro-routes.d.ts +0 -38
  70. package/.nuxt/types/nitro.d.ts +0 -3
  71. package/.nuxt/types/plugins.d.ts +0 -30
  72. package/.nuxt/types/runtime-config.d.ts +0 -38
  73. package/.nuxt/types/shared-app.config.d.ts +0 -28
  74. package/.nuxt/types/shared-imports.d.ts +0 -2
  75. package/.nuxt/types/vue-shim.d.ts +0 -0
  76. package/.nuxt/unhead-options.mjs +0 -5
  77. package/.nuxt/unhead.config.mjs +0 -1
  78. package/dist/module.d.mts +0 -7
  79. package/dist/module.json +0 -9
  80. package/dist/module.mjs.map +0 -1
  81. package/dist/runtime/composables/use-native-login-context.d.ts +0 -10
  82. package/dist/runtime/composables/use-native-login-context.js +0 -9
  83. package/dist/runtime/composables/use-native-login.d.ts +0 -10
  84. package/dist/runtime/composables/use-native-login.js +0 -143
  85. package/dist/runtime/composables/use-session.d.ts +0 -8
  86. package/dist/runtime/composables/use-session.js +0 -2
  87. package/dist/runtime/composables/use-strivacity.d.ts +0 -9
  88. package/dist/runtime/composables/use-strivacity.js +0 -77
  89. package/dist/runtime/middleware/auth.server.d.ts +0 -2
  90. package/dist/runtime/middleware/auth.server.js +0 -12
  91. package/dist/runtime/server/api/auth/backchannel-logout.get.d.ts +0 -2
  92. package/dist/runtime/server/api/auth/backchannel-logout.get.js +0 -2
  93. package/dist/runtime/server/api/auth/callback.get.d.ts +0 -2
  94. package/dist/runtime/server/api/auth/callback.get.js +0 -2
  95. package/dist/runtime/server/api/auth/entry.get.d.ts +0 -2
  96. package/dist/runtime/server/api/auth/entry.get.js +0 -2
  97. package/dist/runtime/server/api/auth/login.get.d.ts +0 -2
  98. package/dist/runtime/server/api/auth/login.get.js +0 -2
  99. package/dist/runtime/server/api/auth/logout.get.d.ts +0 -2
  100. package/dist/runtime/server/api/auth/logout.get.js +0 -2
  101. package/dist/runtime/server/api/auth/refresh.get.d.ts +0 -2
  102. package/dist/runtime/server/api/auth/refresh.get.js +0 -2
  103. package/dist/runtime/server/api/auth/register.get.d.ts +0 -2
  104. package/dist/runtime/server/api/auth/register.get.js +0 -2
  105. package/dist/runtime/server/api/auth/revoke.get.d.ts +0 -2
  106. package/dist/runtime/server/api/auth/revoke.get.js +0 -2
  107. package/dist/runtime/server/composables/use-strivacity.d.ts +0 -2
  108. package/dist/runtime/server/composables/use-strivacity.js +0 -9
  109. package/dist/runtime/server/plugins/auth.server.d.ts +0 -10
  110. package/dist/runtime/server/plugins/auth.server.js +0 -66
  111. package/dist/runtime/server/utils/helpers.d.ts +0 -18
  112. package/dist/runtime/server/utils/helpers.js +0 -39
  113. package/dist/runtime/storages/core.d.ts +0 -1
  114. package/dist/runtime/storages/core.js +0 -13
  115. package/dist/runtime/storages/default.d.ts +0 -21
  116. package/dist/runtime/storages/default.js +0 -71
  117. package/dist/runtime/types.d.ts +0 -219
  118. package/dist/runtime/types.js +0 -1
  119. package/dist/runtime/utils/core.d.ts +0 -1
  120. package/dist/runtime/utils/core.js +0 -64
  121. package/dist/runtime/utils/noop.d.ts +0 -1
  122. package/dist/runtime/utils/noop.js +0 -3
  123. package/dist/types.d.mts +0 -9
  124. /package/src/runtime/server/api/auth/{backchannel-logout.get.ts → backchannel-logout.post.ts} +0 -0
@@ -1,143 +0,0 @@
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 { isSessionExpired, 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 && !isSessionExpired(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
- }
@@ -1,8 +0,0 @@
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>;
@@ -1,2 +0,0 @@
1
- import { useState } from "#imports";
2
- export const useSession = () => useState("strivacity_session", () => void 0);
@@ -1,9 +0,0 @@
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>;
@@ -1,77 +0,0 @@
1
- import { ref } from "vue";
2
- import { initFlow } from "@strivacity/sdk-core";
3
- import { useRuntimeConfig } from "#app";
4
- import { useSession } from "./use-session.js";
5
- import createLogging from "#strivacity-options-logging";
6
- import createHttpClient from "#strivacity-options-httpClient";
7
- let sdk;
8
- const loadingRef = ref(true);
9
- const languageRef = ref(globalThis.navigator?.language ?? "en-US");
10
- const isAuthenticatedRef = ref(false);
11
- const idTokenClaimsRef = ref(null);
12
- const accessTokenRef = ref(null);
13
- const refreshTokenRef = ref(null);
14
- const accessTokenExpiredRef = ref(true);
15
- const accessTokenExpirationDateRef = ref(null);
16
- const updateSession = async () => {
17
- const authenticated = await sdk.isAuthenticated;
18
- if (loadingRef.value) {
19
- loadingRef.value = false;
20
- }
21
- if (sdk.language !== languageRef.value) {
22
- languageRef.value = sdk.language;
23
- }
24
- if (authenticated !== isAuthenticatedRef.value) {
25
- isAuthenticatedRef.value = authenticated;
26
- }
27
- if (sdk.idTokenClaims !== idTokenClaimsRef.value) {
28
- idTokenClaimsRef.value = sdk.idTokenClaims || null;
29
- }
30
- if (sdk.accessToken !== accessTokenRef.value) {
31
- accessTokenRef.value = sdk.accessToken || null;
32
- }
33
- if (sdk.refreshToken !== refreshTokenRef.value) {
34
- refreshTokenRef.value = sdk.refreshToken || null;
35
- }
36
- if (sdk.accessTokenExpired !== accessTokenExpiredRef.value) {
37
- accessTokenExpiredRef.value = sdk.accessTokenExpired;
38
- }
39
- if (sdk.accessTokenExpirationDate !== accessTokenExpirationDateRef.value) {
40
- accessTokenExpirationDateRef.value = sdk.accessTokenExpirationDate || null;
41
- }
42
- };
43
- export const useStrivacity = () => {
44
- if (!sdk) {
45
- sdk = initFlow({
46
- ...useRuntimeConfig().public.strivacity,
47
- logging: createLogging ? createLogging() : void 0,
48
- httpClient: createHttpClient ? createHttpClient() : void 0
49
- });
50
- sdk.subscribeToAllEvents(updateSession);
51
- sdk.session = useSession().value;
52
- void updateSession();
53
- }
54
- return {
55
- sdk,
56
- loading: loadingRef,
57
- language: languageRef,
58
- isAuthenticated: isAuthenticatedRef,
59
- idTokenClaims: idTokenClaimsRef,
60
- accessToken: accessTokenRef,
61
- refreshToken: refreshTokenRef,
62
- accessTokenExpired: accessTokenExpiredRef,
63
- accessTokenExpirationDate: accessTokenExpirationDateRef,
64
- init: () => sdk.init(),
65
- subscribeToEvent: ((...args) => sdk.subscribeToEvent(...args)),
66
- subscribeToAllEvents: (...args) => sdk.subscribeToAllEvents(...args),
67
- checkAuthentication: (...args) => sdk.checkAuthentication(...args),
68
- tokenExchange: (...args) => sdk.tokenExchange(...args),
69
- handleCallback: (...args) => sdk.handleCallback(...args),
70
- refresh: () => sdk.refresh(),
71
- revoke: () => sdk.revoke(),
72
- logout: (...args) => sdk.logout(...args),
73
- login: (...args) => sdk.login(...args),
74
- register: (...args) => sdk.register(...args),
75
- entry: (...args) => sdk.entry(...args)
76
- };
77
- };
@@ -1,2 +0,0 @@
1
- declare const _default: import("nuxt/app").RouteMiddleware;
2
- export default _default;
@@ -1,12 +0,0 @@
1
- import { defineNuxtRouteMiddleware, useNuxtApp } from "#imports";
2
- import { useSession } from "../composables/use-session.js";
3
- export default defineNuxtRouteMiddleware(async () => {
4
- if (!import.meta.server) {
5
- return;
6
- }
7
- const app = useNuxtApp();
8
- const h3Event = app.ssrContext.event;
9
- const { useStrivacity } = await import("../server/composables/use-strivacity.js");
10
- const sdk = useStrivacity(h3Event);
11
- useSession().value = await sdk.getSession() ?? void 0;
12
- });
@@ -1,2 +0,0 @@
1
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<Response>>;
2
- export default _default;
@@ -1,2 +0,0 @@
1
- import { defineEventHandler } from "h3";
2
- export default defineEventHandler((event) => event.context.strivacity.sdk.handleBackChannelLogout(event));
@@ -1,2 +0,0 @@
1
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<Response>>;
2
- export default _default;
@@ -1,2 +0,0 @@
1
- import { defineEventHandler } from "h3";
2
- export default defineEventHandler((event) => event.context.strivacity.sdk.handleCallback(event));
@@ -1,2 +0,0 @@
1
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<Response>>;
2
- export default _default;
@@ -1,2 +0,0 @@
1
- import { defineEventHandler } from "h3";
2
- export default defineEventHandler((event) => event.context.strivacity.sdk.handleEntry(event));
@@ -1,2 +0,0 @@
1
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<Response>>;
2
- export default _default;
@@ -1,2 +0,0 @@
1
- import { defineEventHandler } from "h3";
2
- export default defineEventHandler((event) => event.context.strivacity.sdk.handleLogin(event));
@@ -1,2 +0,0 @@
1
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<Response>>;
2
- export default _default;
@@ -1,2 +0,0 @@
1
- import { defineEventHandler } from "h3";
2
- export default defineEventHandler((event) => event.context.strivacity.sdk.handleLogout(event));
@@ -1,2 +0,0 @@
1
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<Response>>;
2
- export default _default;
@@ -1,2 +0,0 @@
1
- import { defineEventHandler } from "h3";
2
- export default defineEventHandler((event) => event.context.strivacity.sdk.handleRefresh(event));
@@ -1,2 +0,0 @@
1
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<Response>>;
2
- export default _default;
@@ -1,2 +0,0 @@
1
- import { defineEventHandler } from "h3";
2
- export default defineEventHandler((event) => event.context.strivacity.sdk.handleRegister(event));
@@ -1,2 +0,0 @@
1
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<Response>>;
2
- export default _default;
@@ -1,2 +0,0 @@
1
- import { defineEventHandler } from "h3";
2
- export default defineEventHandler((event) => event.context.strivacity.sdk.handleRevoke(event));
@@ -1,2 +0,0 @@
1
- import type { H3Event } from 'h3';
2
- export declare const useStrivacity: (event: H3Event) => import("../../types.js").NuxtServerSDK;
@@ -1,9 +0,0 @@
1
- export const useStrivacity = (event) => {
2
- if (import.meta.client) {
3
- throw new Error('The "useStrivacity" composable should only be used on the server.');
4
- }
5
- if (!event) {
6
- throw new Error("useStrivacity() can not be called without passing an H3Event instance.");
7
- }
8
- return event.context.strivacity.sdk;
9
- };
@@ -1,10 +0,0 @@
1
- import type { NuxtServerSDK } from '../../types.js';
2
- declare module 'h3' {
3
- interface H3EventContext {
4
- strivacity: {
5
- sdk: NuxtServerSDK;
6
- };
7
- }
8
- }
9
- declare const _default: import("nitropack").NitroAppPlugin;
10
- export default _default;
@@ -1,66 +0,0 @@
1
- import { toWebRequest } from "h3";
2
- import { useRuntimeConfig } from "#imports";
3
- import { defineNitroPlugin } from "nitropack/dist/runtime/plugin";
4
- import { createBaseServerSDK } from "@strivacity/sdk-core/server";
5
- import { ConfigurationError } from "@strivacity/sdk-core/utils";
6
- import { createEncryptedCookieStorage } from "../../storages/default.js";
7
- export default defineNitroPlugin((nitroApp) => {
8
- void setupAuthPlugin(nitroApp);
9
- });
10
- async function setupAuthPlugin(nitroApp) {
11
- const config = useRuntimeConfig();
12
- const initConfig = { ...config.strivacity };
13
- const customStorage = (await import("#strivacity-options-storage")).default();
14
- const customStateStorage = (await import("#strivacity-options-stateStorage")).default();
15
- const customLogging = (await import("#strivacity-options-logging")).default();
16
- const customHttpClient = (await import("#strivacity-options-httpClient")).default();
17
- if (customStorage) {
18
- initConfig.storage = customStorage;
19
- }
20
- if (customStateStorage) {
21
- initConfig.stateStorage = customStateStorage;
22
- }
23
- if (customLogging) {
24
- initConfig.logging = customLogging;
25
- }
26
- if (customHttpClient) {
27
- initConfig.httpClient = customHttpClient;
28
- }
29
- if (!initConfig.storage) {
30
- if (!initConfig.secret) {
31
- throw new ConfigurationError("Secret is required for encrypted cookie storage");
32
- }
33
- initConfig.cookieMaxAge ??= 30 * 24 * 60 * 60;
34
- initConfig.storage = createEncryptedCookieStorage(initConfig.secret, { defaultCookieOptions: { maxAge: initConfig.cookieMaxAge } });
35
- }
36
- const base = createBaseServerSDK(
37
- {
38
- toRequest: (event) => toWebRequest(event)
39
- },
40
- initConfig
41
- );
42
- nitroApp.hooks.hook("request", (event) => {
43
- event.context.strivacity ??= {};
44
- event.context.strivacity.sdk ??= {
45
- get options() {
46
- return base.options;
47
- },
48
- getSession: () => base.getSession(event),
49
- updateSession: (session) => base.updateSession(session, event),
50
- refreshSession: () => base.refreshSession(event),
51
- revokeSession: () => base.revokeSession(event),
52
- getEntrySession: (entryUrl) => base.getEntrySession(entryUrl),
53
- completeLogin: (params) => base.completeLogin(params, event),
54
- logout: (postLogoutRedirectUri) => base.logout(postLogoutRedirectUri, event),
55
- handleLogin: (evt) => base.handleLogin(evt),
56
- handleRegister: (evt) => base.handleRegister(evt),
57
- handleCallback: (evt) => base.handleCallback(evt),
58
- handleRefresh: (evt) => base.handleRefresh(evt),
59
- handleRevoke: (evt) => base.handleRevoke(evt),
60
- handleEntry: (evt) => base.handleEntry(evt),
61
- handleLogout: (evt) => base.handleLogout(evt),
62
- handleBackChannelLogout: (evt) => base.handleBackChannelLogout(evt),
63
- handler: (evt) => base.handler(evt)
64
- };
65
- });
66
- }
@@ -1,18 +0,0 @@
1
- import type { H3Event } from 'h3';
2
- import type { HttpClientResponse } from '@strivacity/sdk-core/types';
3
- /**
4
- * Proxies an HttpClientResponse to a Web Response, preserving headers and status code.
5
- */
6
- export declare function proxyResponse<T = unknown>(response: HttpClientResponse<T>): Response;
7
- /**
8
- * Extracts the accept-language locale from the event's request headers.
9
- */
10
- export declare function getLocaleFromEvent(event: H3Event): string | undefined;
11
- /**
12
- * Returns a safe absolute redirect URL only if it shares the same origin as safeBaseUrl, preventing open redirects.
13
- *
14
- * @param dangerousRedirect - The untrusted redirect path or URL.
15
- * @param safeBaseUrl - The trusted base URL whose origin is used as the allowed origin.
16
- * @returns The resolved URL string if safe, or undefined.
17
- */
18
- export declare function toSafeRedirect(dangerousRedirect: string | undefined | null, safeBaseUrl: string): string | null;
@@ -1,39 +0,0 @@
1
- import { DISALLOWED_PROXY_HEADERS } from "@strivacity/sdk-core/utils";
2
- export function proxyResponse(response) {
3
- const proxyHeaders = new Headers();
4
- for (const [key, value] of response.headers.entries()) {
5
- if (key.toLowerCase() === "set-cookie") continue;
6
- if (!DISALLOWED_PROXY_HEADERS.has(key.toLowerCase())) {
7
- proxyHeaders.set(key, value);
8
- }
9
- }
10
- const setCookie = response.headers.get("set-cookie");
11
- if (setCookie) {
12
- proxyHeaders.set("set-cookie", setCookie);
13
- }
14
- return new Response(response.body ?? null, {
15
- status: response.status,
16
- headers: proxyHeaders
17
- });
18
- }
19
- export function getLocaleFromEvent(event) {
20
- const acceptLanguage = event.headers.get("accept-language");
21
- if (!acceptLanguage) return void 0;
22
- return acceptLanguage.split(",")[0]?.split(";")[0]?.trim();
23
- }
24
- export function toSafeRedirect(dangerousRedirect, safeBaseUrl) {
25
- let url;
26
- if (!dangerousRedirect) {
27
- return null;
28
- }
29
- try {
30
- safeBaseUrl = new URL(safeBaseUrl).origin;
31
- url = new URL(dangerousRedirect?.startsWith("/") ? dangerousRedirect.slice(1) : dangerousRedirect, safeBaseUrl);
32
- } catch {
33
- return null;
34
- }
35
- if (url.origin === new URL(safeBaseUrl).origin) {
36
- return url.toString();
37
- }
38
- return null;
39
- }
@@ -1 +0,0 @@
1
- export { COOKIE_CONTEXT, COOKIE_CHUNK_SIZE, createCacheAPIStorage, createIndexedDBStorage, createLocalStorage, createMemoryStorage, createServerMemoryStorage, createSessionStorage, createWorkerStorage, handleWorkerStorageRequests, createServerStateStorage, } from '@strivacity/sdk-core/storages';
@@ -1,13 +0,0 @@
1
- export {
2
- COOKIE_CONTEXT,
3
- COOKIE_CHUNK_SIZE,
4
- createCacheAPIStorage,
5
- createIndexedDBStorage,
6
- createLocalStorage,
7
- createMemoryStorage,
8
- createServerMemoryStorage,
9
- createSessionStorage,
10
- createWorkerStorage,
11
- handleWorkerStorageRequests,
12
- createServerStateStorage
13
- } from "@strivacity/sdk-core/storages";
@@ -1,21 +0,0 @@
1
- import type { H3Event } from 'h3';
2
- import type { EncryptedCookieStorageOptions, ServerStorage, SessionIdCookieStorageOptions } from '@strivacity/sdk-core/types';
3
- import type { NuxtServerStorage } from '../types.js';
4
- /**
5
- * Creates a session storage that puts a random unique id value cookie on the client and keeping the actual session data in the given `storage`.
6
- *
7
- * @param {SDKStorage} storage - The storage used to persist session data, keyed by a randomly generated session id.
8
- * @param {SessionIdCookieStorageOptions} [options] - Options for configuring the session-id cookie storage.
9
- * @returns {ServerStorage} An object implementing the ServerStorage interface for managing sessions indexed by a session-id cookie.
10
- */
11
- export declare function createSessionIdCookieStorage(storage: ServerStorage, options?: SessionIdCookieStorageOptions): ServerStorage<H3Event<import("h3").EventHandlerRequest>>;
12
- /**
13
- * Creates an encrypted cookie session storage.
14
- * Only callable in server-side contexts.
15
- *
16
- * @param secret - The secret key used for encryption and decryption.
17
- * @param {EncryptedCookieStorageOptions} [options] - Options for configuring the encrypted cookie storage.
18
- * @param {Partial<ServerCookieOptions>} [options.defaultCookieOptions] - Default cookie attributes for the encrypted cookie.
19
- * @returns An object implementing the NuxtServerStorage interface for managing encrypted cookies in Nuxt.
20
- */
21
- export declare function createEncryptedCookieStorage(secret: string, options?: EncryptedCookieStorageOptions): NuxtServerStorage;
@@ -1,71 +0,0 @@
1
- import { getCookie, setCookie, deleteCookie, toWebRequest } from "h3";
2
- import { encryptString, decryptString } from "@strivacity/sdk-core/utils/crypto";
3
- import { COOKIE_CONTEXT, COOKIE_CHUNK_SIZE } from "@strivacity/sdk-core/server";
4
- import { createSessionIdCookieStorage as createSessionIdCookieStorageBase } from "@strivacity/sdk-core/storages/server";
5
- export function createSessionIdCookieStorage(storage, options) {
6
- return createSessionIdCookieStorageBase(
7
- {
8
- toRequest: (event) => toWebRequest(event)
9
- },
10
- storage,
11
- options
12
- );
13
- }
14
- export function createEncryptedCookieStorage(secret, options) {
15
- const defaultCookieOptions = {
16
- httpOnly: true,
17
- secure: true,
18
- path: "/",
19
- sameSite: "lax",
20
- ...options?.defaultCookieOptions
21
- };
22
- const storage = {
23
- async get(key, event) {
24
- if (!event) {
25
- return null;
26
- }
27
- const cookie = getCookie(event, key) ?? null;
28
- if (cookie) {
29
- return await decryptString(cookie, secret, COOKIE_CONTEXT);
30
- }
31
- const cookieChunks = [];
32
- for (let i = 0; ; i++) {
33
- const chunk = getCookie(event, `${key}.${i}`);
34
- if (!chunk) {
35
- break;
36
- }
37
- cookieChunks.push(chunk);
38
- }
39
- if (cookieChunks.length === 0) {
40
- return null;
41
- }
42
- return await decryptString(cookieChunks.join(""), secret, COOKIE_CONTEXT);
43
- },
44
- async set(key, value, event, cookieOptions = {}) {
45
- if (!event) {
46
- return;
47
- }
48
- cookieOptions = { ...defaultCookieOptions, ...cookieOptions };
49
- await storage.delete(key, event, cookieOptions);
50
- const encrypted = await encryptString(value, secret, COOKIE_CONTEXT);
51
- if (encrypted.length <= COOKIE_CHUNK_SIZE) {
52
- setCookie(event, key, encrypted, cookieOptions);
53
- } else {
54
- for (let i = 0; i * COOKIE_CHUNK_SIZE < encrypted.length; i++) {
55
- setCookie(event, `${key}.${i}`, encrypted.slice(i * COOKIE_CHUNK_SIZE, (i + 1) * COOKIE_CHUNK_SIZE), cookieOptions);
56
- }
57
- }
58
- },
59
- async delete(key, event, cookieOptions = {}) {
60
- if (!event) {
61
- return;
62
- }
63
- deleteCookie(event, key, cookieOptions);
64
- for (let i = 0; getCookie(event, `${key}.${i}`); i++) {
65
- deleteCookie(event, `${key}.${i}`, cookieOptions);
66
- }
67
- return Promise.resolve();
68
- }
69
- };
70
- return storage;
71
- }