@strivacity/sdk-vue 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.
package/README.md CHANGED
@@ -377,7 +377,29 @@ onMounted(async () => {
377
377
 
378
378
  #### Handle the callback
379
379
 
380
- The popup resolves automatically - no callback page is needed. Token exchange happens inside the popup and the result is posted back to the opener window.
380
+ The pop-up still navigates to your `redirectUri`, so you still need a callback page there - without it nothing posts the result back to the opener. Call `handleCallback()` on that page; in popup mode it never resolves (the opener closes the pop-up once it receives the result), so don't rely on code after it running:
381
+
382
+ ```vue
383
+ <!-- pages/Callback.vue -->
384
+ <script setup lang="ts">
385
+ import { useStrivacity } from '@strivacity/sdk-vue';
386
+ import { onMounted } from 'vue';
387
+
388
+ const { handleCallback } = useStrivacity();
389
+
390
+ onMounted(() => {
391
+ void handleCallback();
392
+ });
393
+ </script>
394
+
395
+ <template>
396
+ <section>
397
+ <h1>Logging in...</h1>
398
+ </section>
399
+ </template>
400
+ ```
401
+
402
+ `login()` resolves in the opener once the result has been received and, for client-managed sessions, the tokens have been exchanged.
381
403
 
382
404
  #### Registration
383
405
 
@@ -975,7 +997,6 @@ const { state, forms, messages, loading, submitForm } = useNativeLogin({
975
997
  params: {
976
998
  prompt: 'login', // use 'create' to open the registration flow instead
977
999
  language: 'en-US', // set the UI language (BCP 47 language tag)
978
- sdk: 'web-minimal', // rendering mode: 'web-minimal' for simplified rendering (see below), 'web' (default) for full rendering hints and branding
979
1000
  sessionId: null, // pass a session ID to resume an existing flow
980
1001
  },
981
1002
  onLogin: async () => {
@@ -1260,23 +1281,31 @@ const ctx = useStrivacity<RedirectFlow>();
1260
1281
  ```ts
1261
1282
  {
1262
1283
  // SDK instance (access any SDK method)
1263
- sdk: RedirectFlow | PopupFlow | EmbeddedFlow | NativeFlow;
1284
+ readonly sdk: RedirectFlow | PopupFlow | EmbeddedFlow | NativeFlow;
1264
1285
 
1265
1286
  // Reactive state
1266
- loading: Ref<boolean>; // True during initialization
1267
- isAuthenticated: Ref<boolean>; // True if user has valid session
1268
- idTokenClaims: Ref<IdTokenClaims | null>; // Decoded ID token claims
1269
- accessToken: Ref<string | null>; // Current access token
1270
- refreshToken: Ref<string | null>; // Current refresh token
1271
-
1272
- // Methods (all are async)
1273
- login(params?: LoginParams): Promise<void>; // Start login flow
1274
- register(params?: LoginParams): Promise<void>; // Start registration flow
1275
- handleCallback(url?: string): Promise<void>; // Handle OAuth callback
1287
+ readonly loading: Ref<boolean>; // True during initialization
1288
+ readonly language: Ref<string>; // Current BCP 47 language code
1289
+ readonly isAuthenticated: Ref<boolean>; // True if user has valid session
1290
+ readonly idTokenClaims: Ref<IdTokenClaims | null>; // Decoded ID token claims
1291
+ readonly accessToken: Ref<string | null>; // Current access token
1292
+ readonly refreshToken: Ref<string | null>; // Current refresh token
1293
+ readonly accessTokenExpired: Ref<boolean>; // True once the access token has expired
1294
+ readonly accessTokenExpirationDate: Ref<number | null>; // Access token expiration timestamp
1295
+
1296
+ // Methods (same signatures as the underlying flow's methods)
1297
+ init(): Promise<void>; // Initialize the SDK (load metadata, restore a persisted session)
1298
+ checkAuthentication(params?: { autoRefresh: boolean }): Promise<boolean>; // Check the session, optionally refreshing the token (never when serverSessionUri is set)
1299
+ login(params?: RedirectParams | PopupParams): Promise<void>; // Start login flow (redirect: `returnTo` sets where handleCallback() sends the user) (embedded/native: returns an EmbeddedLoginFlow/NativeLoginFlow instead)
1300
+ register(params?: RedirectParams | PopupParams): Promise<void>; // Start registration flow (embedded/native: returns an EmbeddedLoginFlow/NativeLoginFlow instead)
1301
+ handleCallback(url?: string | URL): Promise<{ returnTo?: string }>; // Handle OAuth callback; resolves to the `returnTo` given to login()
1276
1302
  logout(params?: LogoutParams): Promise<void>; // End session
1277
- refresh(): Promise<void>; // Refresh access token
1303
+ refresh(params?: { returnTo?: string }): Promise<void>; // Refresh access token (server-managed: navigates to the server's refresh route, `${authUrlPrefix}/refresh`, instead; `returnTo` sets where it returns, default: the current URL)
1278
1304
  revoke(): Promise<void>; // Revoke tokens
1279
- entry(): Promise<EntryData>; // Handle external entry (embedded/native only)
1305
+ tokenExchange(params?: Record<string, string>): Promise<void>; // Perform a token exchange
1306
+ entry(url?: string | URL, params?: RedirectOptions): Promise<void | EntryResponse>; // Handle external entry (resolves to EntryResponse in embedded/native mode)
1307
+ subscribeToEvent<T extends keyof EventFunctions>(eventName: T, callbackFn: (...params: Parameters<EventFunctions[T]>) => Promise<void> | void): { dispose: () => void }; // Subscribe to a single SDK event
1308
+ subscribeToAllEvents(callbackFn: (...params: Array<unknown>) => Promise<void> | void): { dispose: () => void }; // Subscribe to all SDK events
1280
1309
  }
1281
1310
  ```
1282
1311
 
@@ -1301,11 +1330,11 @@ const ctx = useNativeLogin({
1301
1330
  ```ts
1302
1331
  {
1303
1332
  params?: NativeParams; // Initial flow parameters
1304
- onLogin?: (session: Session) => void; // Called on successful login
1305
- onClose?: () => void; // Called when user closes the flow
1306
- onError?: (error: unknown) => void; // Called on error
1307
- onFallback?: (error: FallbackError) => void; // Called when fallback needed
1308
- onGlobalMessage?: (message: NativeFlowMessage) => void; // Called for global messages
1333
+ onLogin?: (session: SessionData) => void | Promise<void>; // Called on successful login
1334
+ onClose?: () => void | Promise<void>; // Called when user closes the flow
1335
+ onError?: (error: Error) => void | Promise<void>; // Called on error
1336
+ onFallback?: (error: FallbackError) => void | Promise<void>; // Called when fallback needed
1337
+ onGlobalMessage?: (message: NativeFlowMessage) => void | Promise<void>; // Called for global messages
1309
1338
  }
1310
1339
  ```
1311
1340
 
@@ -1315,16 +1344,29 @@ const ctx = useNativeLogin({
1315
1344
  {
1316
1345
  // Reactive state
1317
1346
  loading: Ref<boolean>; // True while fetching next screen
1318
- state: Ref<NativeFlowState>; // Current flow state (screen, forms, layout, etc.)
1347
+ state: Ref<Partial<NativeFlowState>>; // Current flow state (screen, forms, layout, etc.)
1319
1348
  forms: Ref<Record<string, Record<string, unknown>>>; // Form data by form ID
1320
1349
  messages: Ref<Record<string, Record<string, NativeFlowMessage>>>; // Validation messages
1321
1350
 
1322
1351
  // Methods
1323
- submitForm(formId: string): Promise<void>; // Submit a form and advance to next screen
1352
+ submitForm(formId: string, customBody?: Record<string, unknown>): Promise<void>; // Submit a form and advance to next screen
1353
+ setFormValue(formId: string, widgetId: string, value: unknown): void; // Update a single field value before submission
1354
+ setMessage(formId: string, widgetId: string, value: NativeFlowMessage): void; // Set a validation/info message on a widget
1324
1355
  triggerFallback(message?: string): void; // Manually trigger fallback to hosted journey
1356
+ triggerClose(): void; // Signal that the login flow was closed by the user
1325
1357
  }
1326
1358
  ```
1327
1359
 
1360
+ ### useNativeLoginContext
1361
+
1362
+ Returns the same login context as `useNativeLogin()` from inside descendant components (e.g. your own widget components). `useNativeLogin()` provides the context to its component's subtree; calling `useNativeLoginContext()` outside that subtree throws `Missing SDK native login context`.
1363
+
1364
+ ```ts
1365
+ import { useNativeLoginContext } from '@strivacity/sdk-vue';
1366
+
1367
+ const { forms, messages, setFormValue, submitForm } = useNativeLoginContext();
1368
+ ```
1369
+
1328
1370
  ---
1329
1371
 
1330
1372
  ## Route guards
@@ -1549,10 +1591,15 @@ app.use(
1549
1591
  redirectUri: 'https://your-app.example.com/callback',
1550
1592
  scopes: ['openid', 'profile', 'email'],
1551
1593
  serverSessionUri: '/api/auth/login', // Requests are routed through your server; tokens are NOT written to client storage
1594
+ authUrlPrefix: '/api/auth', // Where your server serves the auth routes: refresh() and the guards use `${authUrlPrefix}/refresh`
1552
1595
  }),
1553
1596
  );
1554
1597
  ```
1555
1598
 
1599
+ In this mode `logout()` doesn't clear the server session cookie. Navigate the browser to your server's logout route instead (e.g. `/api/auth/logout`, optionally with a same-origin `?returnTo=`), which clears the server session and redirects to the IDP end-session endpoint. See [Logging out](../sdk-core/README.md#logging-out) in the core SDK README for the `returnTo` rules.
1600
+
1601
+ The browser never refreshes tokens in this mode (`autoRefresh` is ignored). `sdk.refresh()` navigates the browser to your server's refresh route, `${authUrlPrefix}/refresh` (default `/auth`; set `authUrlPrefix` when your server uses another prefix) (a full-page navigation, also in `popup` mode) with `returnTo` set to the current URL - or pass your own with `sdk.refresh({ returnTo: '/profile' })`; the server rotates the session cookie and redirects back. In a [route guard](#route-guards), you can do this for an expired session (`sdk.session` set but `isAuthenticated` false) with `await sdk.refresh({ returnTo: to.fullPath })` and cancel the navigation (`return false`) instead of redirecting to the login page. See [Refreshing the session](../sdk-core/README.md#refreshing-the-session) in the core SDK README.
1602
+
1556
1603
  See [`apps/vue`](../../apps/vue) paired with [`apps/backend`](../../apps/backend) for a working example. See also [Using the backend app with SPA apps](../../README.md#using-the-backend-app-with-spa-apps) in the root README.
1557
1604
 
1558
1605
  ---
@@ -1561,7 +1608,7 @@ See [`apps/vue`](../../apps/vue) paired with [`apps/backend`](../../apps/backend
1561
1608
 
1562
1609
  ### Migrating to v4.0
1563
1610
 
1564
- v4 replaces the SDK's class-based flow architecture with function-based architecture, and adds first-class support for server-managed (BFF) sessions. `createStrivacitySDK()`, `useStrivacity()`, `useNativeLogin()`, and the built-in `redirect`/`popup`/`embedded`/`native` modes are unchanged - only apps that used `mode: 'custom'` or drove `native` mode through the old `NativeFlowHandler` need to update their code.
1611
+ v4 replaces the SDK's class-based flow architecture with function-based architecture, and adds first-class support for server-managed (BFF) sessions. `createStrivacitySDK()`, `useStrivacity()`, and the built-in `redirect`/`popup`/`embedded`/`native` modes are unchanged (`useStrivacity()` no longer exposes `options` - use `sdk.options`). `useNativeLogin()` is new in v4: it replaces v3's `<StyLoginRenderer>` component, so `native` mode now renders your own widget components driven by [`useNativeLogin()`](#usenativelogin) and [`useNativeLoginContext()`](#usenativelogincontext). Apps that rendered `<StyLoginRenderer>`, used `mode: 'custom'`, or drove `native` mode through the old `NativeFlowHandler` need to update their code.
1565
1612
 
1566
1613
  #### Class-based flows replaced by functions
1567
1614
 
@@ -1588,7 +1635,7 @@ import type { SDKInitConfig, SDKOptions } from '@strivacity/sdk-core/types';
1588
1635
 
1589
1636
  export function createCustomFlow(initConfig: SDKInitConfig) {
1590
1637
  const state = getDefaultFlowState();
1591
- const options = getSDKOptions<SDKOptions>(state, initConfig);
1638
+ const options = getSDKOptions<SDKOptions>(initConfig);
1592
1639
  const base = createBaseFlow(state, options);
1593
1640
 
1594
1641
  async function refresh(): Promise<void> {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strivacity/sdk-vue",
3
- "version": "4.0.0-beta.1",
3
+ "version": "4.0.0-beta.2",
4
4
  "description": "Strivacity Vue SDK client",
5
5
  "license": "MIT",
6
6
  "author": "strivacity <opensource@strivacity.com>",
@@ -56,7 +56,7 @@
56
56
  }
57
57
  },
58
58
  "dependencies": {
59
- "@strivacity/sdk-core": "4.0.0-beta.1"
59
+ "@strivacity/sdk-core": "4.0.0-beta.2"
60
60
  },
61
61
  "peerDependencies": {
62
62
  "vue": ">=3.3"
@@ -1,9 +1,8 @@
1
1
  import type { InjectionKey } from 'vue';
2
- import type { RedirectFlow, PopupFlow, EmbeddedFlow, NativeFlow, NativeParams, NativeFlowState, NativeFlowMessage } from '@strivacity/sdk-core/types';
2
+ import type { RedirectFlow, PopupFlow, EmbeddedFlow, NativeFlow, NativeFlowState, NativeFlowMessage } from '@strivacity/sdk-core/types';
3
3
  import type { LoginContext, SDKContext, UseNativeLoginOptions } from './types';
4
4
  import { provide, inject, ref, onMounted, onUnmounted } from 'vue';
5
- import { FallbackError } from '@strivacity/sdk-core/utils/errors';
6
- import { isSessionExpired, unflattenObject } from '@strivacity/sdk-core/utils';
5
+ import { createNativeLoginController } from '@strivacity/sdk-core/utils';
7
6
 
8
7
  export const STRIVACITY_SDK: InjectionKey<SDKContext<RedirectFlow | PopupFlow | NativeFlow | EmbeddedFlow>> = Symbol('strivacity-sdk');
9
8
  export const STRIVACITY_LOGIN_CONTEXT: InjectionKey<LoginContext> = Symbol('strivacity-login-context');
@@ -51,169 +50,38 @@ export const useNativeLoginContext = (): LoginContext => {
51
50
  * @throws {Error} - If the Strivacity SDK context is not found.
52
51
  */
53
52
  export function useNativeLogin(options: UseNativeLoginOptions = {}): ReturnType<typeof useNativeLoginContext> {
54
- const abortController = new AbortController();
55
53
  const { sdk } = useStrivacity<NativeFlow>();
56
-
57
- const loading = ref<boolean>(true);
58
- const forms = ref<Record<string, Record<string, unknown>>>({});
59
- const messages = ref<Record<string, Record<string, NativeFlowMessage>>>({});
60
- const state = ref<Partial<NativeFlowState>>({});
61
-
62
- onMounted(async () => {
63
- await sdk.init();
64
-
65
- try {
66
- await startSession(options.params);
67
- } catch (error) {
68
- if (error instanceof DOMException && error.name === 'AbortError') {
69
- return;
70
- }
71
-
72
- sdk.logging?.error('Error fetching authorization URI', error);
73
- void options.onError?.(error);
74
- loading.value = false;
75
- }
54
+ const controller = createNativeLoginController(() => sdk, options);
55
+ const snapshot = controller.getSnapshot();
56
+
57
+ const loading = ref<boolean>(snapshot.loading);
58
+ const forms = ref<Record<string, Record<string, unknown>>>(snapshot.forms);
59
+ const messages = ref<Record<string, Record<string, NativeFlowMessage>>>(snapshot.messages);
60
+ const state = ref<Partial<NativeFlowState>>(snapshot.state);
61
+
62
+ const unsubscribe = controller.subscribe((next) => {
63
+ loading.value = next.loading;
64
+ forms.value = next.forms;
65
+ messages.value = next.messages;
66
+ state.value = next.state;
76
67
  });
77
68
 
78
- onUnmounted(() => abortController.abort());
79
-
80
- function handleResponse(nextState: Partial<NativeFlowState>) {
81
- if (sdk.session && !isSessionExpired(sdk.session)) {
82
- return void options.onLogin?.(sdk.session);
83
- }
84
-
85
- const newState: NativeFlowState = {
86
- hostedUrl: nextState?.hostedUrl ?? state.value.hostedUrl,
87
- finalizeUrl: nextState?.finalizeUrl ?? state.value.finalizeUrl,
88
- screen: nextState?.screen ?? state.value.screen,
89
- forms: nextState?.forms ?? state.value.forms,
90
- layout: nextState?.layout ?? state.value.layout,
91
- messages: nextState?.messages ?? {},
92
- branding: nextState?.branding ?? state.value.branding,
93
- };
69
+ onMounted(() => controller.start());
70
+ onUnmounted(unsubscribe);
94
71
 
95
- if (newState.screen !== state.value.screen) {
96
- forms.value = {};
97
- messages.value = {};
98
-
99
- for (const form of newState.forms ?? []) {
100
- forms.value[form.id] = {};
101
- messages.value[form.id] = {};
102
- }
103
- } else {
104
- sdk.logging?.info(`Updating screen: ${newState.screen}`);
105
- }
106
-
107
- for (const formId of Object.keys(newState.messages ?? {})) {
108
- if (formId === 'global') {
109
- // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
110
- void options.onGlobalMessage?.(newState.messages?.global!);
111
- } else {
112
- messages.value[formId] = newState.messages![formId] ?? {};
113
- }
114
- }
115
-
116
- state.value = newState;
117
-
118
- if (!newState.finalizeUrl) {
119
- loading.value = false;
120
- }
121
- }
122
-
123
- async function startSession(loginParams: NativeParams = {}) {
124
- try {
125
- loading.value = true;
126
-
127
- const nextState = await sdk.startSession(loginParams);
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 starting session', error);
138
- void options.onError?.(error);
139
- }
140
- }
141
- }
142
-
143
- function triggerFallback(message?: string) {
144
- sdk.logging?.warn(message ? `Triggering fallback due to: ${message}` : 'Triggering fallback');
145
-
146
- if (!state.value.hostedUrl) {
147
- const error = new Error('No hosted URL provided');
148
- sdk.logging?.error('Fallback error', error);
149
- throw error;
150
- }
151
-
152
- void options.onFallback?.(new FallbackError(new URL(state.value.hostedUrl)));
153
- }
154
-
155
- function triggerClose() {
156
- sdk.logging?.debug('Triggering close');
157
- void options.onClose?.();
158
- }
159
-
160
- async function submitForm(formId: string, customBody?: Record<string, unknown>) {
161
- try {
162
- loading.value = true;
163
-
164
- const nextState = await sdk.submitForm(formId, customBody ?? unflattenObject(forms.value[formId] ?? {}));
165
-
166
- if (nextState) {
167
- handleResponse(nextState);
168
- }
169
- } catch (error) {
170
- if (error instanceof FallbackError) {
171
- sdk.logging?.error('Fallback error occurred', error);
172
- void options.onFallback?.(error);
173
- } else {
174
- sdk.logging?.error('Error submitting form', error);
175
- void options.onError?.(error);
176
- }
177
- }
178
- }
179
-
180
- function setFormValue(formId: string, widgetId: string, value: unknown) {
181
- if (forms.value[formId] === undefined) {
182
- forms.value[formId] = {};
183
- }
184
-
185
- forms.value[formId][widgetId] = value === '' ? null : value;
186
- }
187
-
188
- function setMessage(formId: string, widgetId: string, value: NativeFlowMessage) {
189
- if (messages.value[formId] === undefined) {
190
- messages.value[formId] = {};
191
- }
192
-
193
- messages.value[formId][widgetId] = value;
194
- }
195
-
196
- provide<LoginContext>(STRIVACITY_LOGIN_CONTEXT, {
197
- loading,
198
- forms,
199
- messages,
200
- state,
201
- triggerFallback,
202
- triggerClose,
203
- submitForm,
204
- setFormValue,
205
- setMessage,
206
- });
207
-
208
- return {
72
+ const context: LoginContext = {
209
73
  loading,
210
74
  forms,
211
75
  messages,
212
76
  state,
213
- triggerFallback,
214
- triggerClose,
215
- submitForm,
216
- setFormValue,
217
- setMessage,
77
+ triggerFallback: controller.triggerFallback,
78
+ triggerClose: controller.triggerClose,
79
+ submitForm: controller.submitForm,
80
+ setFormValue: controller.setFormValue,
81
+ setMessage: controller.setMessage,
218
82
  };
83
+
84
+ provide<LoginContext>(STRIVACITY_LOGIN_CONTEXT, context);
85
+
86
+ return context;
219
87
  }
package/src/plugin.ts CHANGED
@@ -75,7 +75,7 @@ export const createStrivacitySDK = (options: SDKInitConfig): Plugin => {
75
75
  checkAuthentication: (...args: Parameters<typeof sdk.checkAuthentication>) => sdk.checkAuthentication(...args),
76
76
  tokenExchange: (...args: Parameters<typeof sdk.tokenExchange>) => sdk.tokenExchange(...args),
77
77
  handleCallback: (...args: Parameters<typeof sdk.handleCallback>) => sdk.handleCallback(...args),
78
- refresh: () => sdk.refresh(),
78
+ refresh: (...args: Parameters<typeof sdk.refresh>) => sdk.refresh(...args),
79
79
  revoke: () => sdk.revoke(),
80
80
  logout: (...args: Parameters<typeof sdk.logout>) => sdk.logout(...args),
81
81
  login: (...args: Parameters<typeof sdk.login>) => sdk.login(...args),
package/src/types.ts CHANGED
@@ -6,12 +6,10 @@ import type {
6
6
  NativeFlow,
7
7
  EmbeddedFlow,
8
8
  initFlow,
9
- NativeParams,
10
9
  NativeFlowState,
11
- SessionData,
12
10
  NativeFlowMessage,
11
+ NativeLoginControllerOptions,
13
12
  } from '@strivacity/sdk-core';
14
- import type { FallbackError } from '@strivacity/sdk-core/utils';
15
13
 
16
14
  export * from '@strivacity/sdk-core/types';
17
15
 
@@ -186,35 +184,7 @@ export type LoginContext = {
186
184
  setMessage: (formId: string, widgetId: string, value: NativeFlowMessage) => void;
187
185
  };
188
186
 
189
- export type UseNativeLoginOptions = {
190
- /**
191
- * Optional parameters to be passed to the login session request. These parameters will be sent to the `authorizationUri` endpoint.
192
- */
193
- params?: NativeParams;
194
-
195
- /**
196
- * A render function called when the user successfully completes the login flow.
197
- * This can be used to perform any necessary actions after a successful login, such as redirecting the user or updating the application state. Defaults to `null`.
198
- */
199
- onLogin?: (session: SessionData) => void | Promise<void>;
200
-
201
- /**
202
- * Called when the fallback flow is triggered, typically due to an error or unsupported environment. Receives a `FallbackError` object containing the hosted URL to redirect to.
203
- */
204
- onFallback?: (error: FallbackError) => void | Promise<void>;
205
-
206
- /**
207
- * Called when the login flow is closed by the user. This can be used to perform any necessary cleanup or state updates in the application. Defaults to `null`.
208
- */
209
- onClose?: () => void | Promise<void>;
210
-
211
- /**
212
- * Called when an error occurs during the login session initialization or flow. Receives an `Error` object describing the issue.
213
- */
214
- onError?: (error: Error) => void | Promise<void>;
215
-
216
- /**
217
- * Called when a global message is received during the login flow. This can be used to display messages to the user or log them for debugging purposes.
218
- */
219
- onGlobalMessage?: (message: NativeFlowMessage) => void | Promise<void>;
220
- };
187
+ /**
188
+ * Callbacks and parameters of the native login flow. See `NativeLoginControllerOptions` in `@strivacity/sdk-core`.
189
+ */
190
+ export type UseNativeLoginOptions = NativeLoginControllerOptions;
@@ -33,6 +33,7 @@ test('should export the correct things', () => {
33
33
  'buildEndSessionUrl',
34
34
  'createDefaultLogging',
35
35
  'createHttpClient',
36
+ 'createNativeLoginController',
36
37
  'createSession',
37
38
  'createState',
38
39
  'createWebAuthnCredential',
@@ -70,6 +71,7 @@ test('should export the correct things', () => {
70
71
  'throwHttpError',
71
72
  'throwTokenEndpointError',
72
73
  'timestamp',
74
+ 'toClientSession',
73
75
  'toSafeRedirect',
74
76
  'unflattenObject',
75
77
  'verifyIdToken',
@@ -92,7 +94,10 @@ test('should export the correct things', () => {
92
94
  'createSessionIdCookieStorage',
93
95
  'createSessionStorage',
94
96
  'createWorkerStorage',
97
+ 'deleteEncryptedCookie',
95
98
  'handleWorkerStorageRequests',
99
+ 'readEncryptedCookie',
100
+ 'writeEncryptedCookie',
96
101
  'AlgorithmTypeList',
97
102
  'GrantTypeList',
98
103
  'ResponseModeList',
@@ -50,7 +50,7 @@ describe('createStrivacitySDK', () => {
50
50
  ['checkAuthentication', [{ autoRefresh: false }], true],
51
51
  ['tokenExchange', [{ code: 'abc' }], undefined],
52
52
  ['handleCallback', ['https://brandtegrity.io/callback?code=abc'], undefined],
53
- ['refresh', [], undefined],
53
+ ['refresh', [{ returnTo: '/orders' }], undefined],
54
54
  ['revoke', [], undefined],
55
55
  ['logout', [{ postLogoutRedirectUri: 'https://brandtegrity.io' }], undefined],
56
56
  ['login', [{ scopes: ['openid'] }], undefined],
@@ -1,2 +0,0 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("vue"),t=require("@strivacity/sdk-core/utils/errors"),n=require("@strivacity/sdk-core/utils");var r=Symbol(`strivacity-sdk`),i=Symbol(`strivacity-login-context`),a=()=>{let t=(0,e.inject)(r);if(!t)throw Error(`Missing SDK context`);return t},o=()=>{let t=(0,e.inject)(i);if(!t)throw Error(`Missing SDK native login context`);return t};function s(r={}){let o=new AbortController,{sdk:s}=a(),c=(0,e.ref)(!0),l=(0,e.ref)({}),u=(0,e.ref)({}),d=(0,e.ref)({});(0,e.onMounted)(async()=>{await s.init();try{await p(r.params)}catch(e){if(e instanceof DOMException&&e.name===`AbortError`)return;s.logging?.error(`Error fetching authorization URI`,e),r.onError?.(e),c.value=!1}}),(0,e.onUnmounted)(()=>o.abort());function f(e){if(s.session&&!(0,n.isSessionExpired)(s.session)){r.onLogin?.(s.session);return}let t={hostedUrl:e?.hostedUrl??d.value.hostedUrl,finalizeUrl:e?.finalizeUrl??d.value.finalizeUrl,screen:e?.screen??d.value.screen,forms:e?.forms??d.value.forms,layout:e?.layout??d.value.layout,messages:e?.messages??{},branding:e?.branding??d.value.branding};if(t.screen!==d.value.screen){l.value={},u.value={};for(let e of t.forms??[])l.value[e.id]={},u.value[e.id]={}}else s.logging?.info(`Updating screen: ${t.screen}`);for(let e of Object.keys(t.messages??{}))e===`global`?r.onGlobalMessage?.(t.messages?.global):u.value[e]=t.messages[e]??{};d.value=t,t.finalizeUrl||(c.value=!1)}async function p(e={}){try{c.value=!0;let t=await s.startSession(e);t&&f(t)}catch(e){e instanceof t.FallbackError?(s.logging?.error(`Fallback error occurred`,e),r.onFallback?.(e)):(s.logging?.error(`Error starting session`,e),r.onError?.(e))}}function m(e){if(s.logging?.warn(e?`Triggering fallback due to: ${e}`:`Triggering fallback`),!d.value.hostedUrl){let e=Error(`No hosted URL provided`);throw s.logging?.error(`Fallback error`,e),e}r.onFallback?.(new t.FallbackError(new URL(d.value.hostedUrl)))}function h(){s.logging?.debug(`Triggering close`),r.onClose?.()}async function g(e,i){try{c.value=!0;let t=await s.submitForm(e,i??(0,n.unflattenObject)(l.value[e]??{}));t&&f(t)}catch(e){e instanceof t.FallbackError?(s.logging?.error(`Fallback error occurred`,e),r.onFallback?.(e)):(s.logging?.error(`Error submitting form`,e),r.onError?.(e))}}function _(e,t,n){l.value[e]===void 0&&(l.value[e]={}),l.value[e][t]=n===``?null:n}function v(e,t,n){u.value[e]===void 0&&(u.value[e]={}),u.value[e][t]=n}return(0,e.provide)(i,{loading:c,forms:l,messages:u,state:d,triggerFallback:m,triggerClose:h,submitForm:g,setFormValue:_,setMessage:v}),{loading:c,forms:l,messages:u,state:d,triggerFallback:m,triggerClose:h,submitForm:g,setFormValue:_,setMessage:v}}exports.STRIVACITY_LOGIN_CONTEXT=i,exports.STRIVACITY_SDK=r,exports.useNativeLogin=s,exports.useNativeLoginContext=o,exports.useStrivacity=a;
2
- //# sourceMappingURL=composables.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"composables.cjs","names":[],"sources":["../src/composables.ts"],"sourcesContent":["import type { InjectionKey } from 'vue';\nimport type { RedirectFlow, PopupFlow, EmbeddedFlow, NativeFlow, NativeParams, NativeFlowState, NativeFlowMessage } from '@strivacity/sdk-core/types';\nimport type { LoginContext, SDKContext, UseNativeLoginOptions } from './types';\nimport { provide, inject, ref, onMounted, onUnmounted } from 'vue';\nimport { FallbackError } from '@strivacity/sdk-core/utils/errors';\nimport { isSessionExpired, unflattenObject } from '@strivacity/sdk-core/utils';\n\nexport const STRIVACITY_SDK: InjectionKey<SDKContext<RedirectFlow | PopupFlow | NativeFlow | EmbeddedFlow>> = Symbol('strivacity-sdk');\nexport const STRIVACITY_LOGIN_CONTEXT: InjectionKey<LoginContext> = Symbol('strivacity-login-context');\n\n/**\n * A composable to access the Strivacity SDK context.\n *\n * @template T - The type of the Strivacity SDK flow (RedirectFlow, PopupFlow, NativeFlow, or EmbeddedFlow).\n * @returns {SDKContext<T>} - The Strivacity SDK context.\n * @throws {Error} - If the Strivacity SDK context is not found.\n */\nexport const useStrivacity = <\n\tT extends RedirectFlow | PopupFlow | NativeFlow | EmbeddedFlow = RedirectFlow | PopupFlow | NativeFlow | EmbeddedFlow,\n>(): SDKContext<T> => {\n\tconst context = inject<SDKContext<T>>(STRIVACITY_SDK);\n\n\tif (!context) {\n\t\tthrow new Error('Missing SDK context');\n\t}\n\n\treturn context;\n};\n\n/**\n * A composable to access the Strivacity SDK context specifically for native login flow.\n *\n * @returns {LoginContext} - The native flow context.\n * @throws {Error} - If the Strivacity SDK context is not found.\n */\nexport const useNativeLoginContext = (): LoginContext => {\n\tconst context = inject<LoginContext>(STRIVACITY_LOGIN_CONTEXT);\n\n\tif (!context) {\n\t\tthrow new Error('Missing SDK native login context');\n\t}\n\n\treturn context;\n};\n\n/**\n * A composable that manages a native login flow session.\n *\n * @param {UseNativeLoginOptions} [options] - Optional options for the login session.\n * @returns {LoginContext} - The native flow context.\n * @throws {Error} - If the Strivacity SDK context is not found.\n */\nexport function useNativeLogin(options: UseNativeLoginOptions = {}): ReturnType<typeof useNativeLoginContext> {\n\tconst abortController = new AbortController();\n\tconst { sdk } = useStrivacity<NativeFlow>();\n\n\tconst loading = ref<boolean>(true);\n\tconst forms = ref<Record<string, Record<string, unknown>>>({});\n\tconst messages = ref<Record<string, Record<string, NativeFlowMessage>>>({});\n\tconst state = ref<Partial<NativeFlowState>>({});\n\n\tonMounted(async () => {\n\t\tawait sdk.init();\n\n\t\ttry {\n\t\t\tawait startSession(options.params);\n\t\t} catch (error) {\n\t\t\tif (error instanceof DOMException && error.name === 'AbortError') {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tsdk.logging?.error('Error fetching authorization URI', error);\n\t\t\tvoid options.onError?.(error);\n\t\t\tloading.value = false;\n\t\t}\n\t});\n\n\tonUnmounted(() => abortController.abort());\n\n\tfunction handleResponse(nextState: Partial<NativeFlowState>) {\n\t\tif (sdk.session && !isSessionExpired(sdk.session)) {\n\t\t\treturn void options.onLogin?.(sdk.session);\n\t\t}\n\n\t\tconst newState: NativeFlowState = {\n\t\t\thostedUrl: nextState?.hostedUrl ?? state.value.hostedUrl,\n\t\t\tfinalizeUrl: nextState?.finalizeUrl ?? state.value.finalizeUrl,\n\t\t\tscreen: nextState?.screen ?? state.value.screen,\n\t\t\tforms: nextState?.forms ?? state.value.forms,\n\t\t\tlayout: nextState?.layout ?? state.value.layout,\n\t\t\tmessages: nextState?.messages ?? {},\n\t\t\tbranding: nextState?.branding ?? state.value.branding,\n\t\t};\n\n\t\tif (newState.screen !== state.value.screen) {\n\t\t\tforms.value = {};\n\t\t\tmessages.value = {};\n\n\t\t\tfor (const form of newState.forms ?? []) {\n\t\t\t\tforms.value[form.id] = {};\n\t\t\t\tmessages.value[form.id] = {};\n\t\t\t}\n\t\t} else {\n\t\t\tsdk.logging?.info(`Updating screen: ${newState.screen}`);\n\t\t}\n\n\t\tfor (const formId of Object.keys(newState.messages ?? {})) {\n\t\t\tif (formId === 'global') {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain\n\t\t\t\tvoid options.onGlobalMessage?.(newState.messages?.global!);\n\t\t\t} else {\n\t\t\t\tmessages.value[formId] = newState.messages![formId] ?? {};\n\t\t\t}\n\t\t}\n\n\t\tstate.value = newState;\n\n\t\tif (!newState.finalizeUrl) {\n\t\t\tloading.value = false;\n\t\t}\n\t}\n\n\tasync function startSession(loginParams: NativeParams = {}) {\n\t\ttry {\n\t\t\tloading.value = true;\n\n\t\t\tconst nextState = await sdk.startSession(loginParams);\n\n\t\t\tif (nextState) {\n\t\t\t\thandleResponse(nextState);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (error instanceof FallbackError) {\n\t\t\t\tsdk.logging?.error('Fallback error occurred', error);\n\t\t\t\tvoid options.onFallback?.(error);\n\t\t\t} else {\n\t\t\t\tsdk.logging?.error('Error starting session', error);\n\t\t\t\tvoid options.onError?.(error);\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction triggerFallback(message?: string) {\n\t\tsdk.logging?.warn(message ? `Triggering fallback due to: ${message}` : 'Triggering fallback');\n\n\t\tif (!state.value.hostedUrl) {\n\t\t\tconst error = new Error('No hosted URL provided');\n\t\t\tsdk.logging?.error('Fallback error', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tvoid options.onFallback?.(new FallbackError(new URL(state.value.hostedUrl)));\n\t}\n\n\tfunction triggerClose() {\n\t\tsdk.logging?.debug('Triggering close');\n\t\tvoid options.onClose?.();\n\t}\n\n\tasync function submitForm(formId: string, customBody?: Record<string, unknown>) {\n\t\ttry {\n\t\t\tloading.value = true;\n\n\t\t\tconst nextState = await sdk.submitForm(formId, customBody ?? unflattenObject(forms.value[formId] ?? {}));\n\n\t\t\tif (nextState) {\n\t\t\t\thandleResponse(nextState);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (error instanceof FallbackError) {\n\t\t\t\tsdk.logging?.error('Fallback error occurred', error);\n\t\t\t\tvoid options.onFallback?.(error);\n\t\t\t} else {\n\t\t\t\tsdk.logging?.error('Error submitting form', error);\n\t\t\t\tvoid options.onError?.(error);\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction setFormValue(formId: string, widgetId: string, value: unknown) {\n\t\tif (forms.value[formId] === undefined) {\n\t\t\tforms.value[formId] = {};\n\t\t}\n\n\t\tforms.value[formId][widgetId] = value === '' ? null : value;\n\t}\n\n\tfunction setMessage(formId: string, widgetId: string, value: NativeFlowMessage) {\n\t\tif (messages.value[formId] === undefined) {\n\t\t\tmessages.value[formId] = {};\n\t\t}\n\n\t\tmessages.value[formId][widgetId] = value;\n\t}\n\n\tprovide<LoginContext>(STRIVACITY_LOGIN_CONTEXT, {\n\t\tloading,\n\t\tforms,\n\t\tmessages,\n\t\tstate,\n\t\ttriggerFallback,\n\t\ttriggerClose,\n\t\tsubmitForm,\n\t\tsetFormValue,\n\t\tsetMessage,\n\t});\n\n\treturn {\n\t\tloading,\n\t\tforms,\n\t\tmessages,\n\t\tstate,\n\t\ttriggerFallback,\n\t\ttriggerClose,\n\t\tsubmitForm,\n\t\tsetFormValue,\n\t\tsetMessage,\n\t};\n}\n"],"mappings":"+KAOA,IAAa,EAAiG,OAAO,gBAAgB,EACxH,EAAuD,OAAO,0BAA0B,EASxF,MAES,CACrB,IAAM,GAAA,EAAU,EAAA,OAAA,CAAsB,CAAc,EAEpD,GAAI,CAAC,EACJ,MAAU,MAAM,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,gBAAA,CAAgB,EAAM,MAAM,IAAW,CAAC,CAAC,CAAC,EAEnG,GACH,EAAe,CAAS,CAE1B,OAAS,EAAO,CACX,aAAiB,EAAA,eACpB,EAAI,SAAS,MAAM,0BAA2B,CAAK,EACnD,EAAa,aAAa,CAAK,IAE/B,EAAI,SAAS,MAAM,wBAAyB,CAAK,EACjD,EAAa,UAAU,CAAK,EAE9B,CACD,CAEA,SAAS,EAAa,EAAgB,EAAkB,EAAgB,CACnE,EAAM,MAAM,KAAY,IAAA,KAC3B,EAAM,MAAM,GAAU,CAAC,GAGxB,EAAM,MAAM,EAAO,CAAC,GAAY,IAAU,GAAK,KAAO,CACvD,CAEA,SAAS,EAAW,EAAgB,EAAkB,EAA0B,CAC3E,EAAS,MAAM,KAAY,IAAA,KAC9B,EAAS,MAAM,GAAU,CAAC,GAG3B,EAAS,MAAM,EAAO,CAAC,GAAY,CACpC,CAcA,OAZA,EAAA,EAAA,QAAA,CAAsB,EAA0B,CAC/C,UACA,QACA,WACA,QACA,kBACA,eACA,aACA,eACA,YACD,CAAC,EAEM,CACN,UACA,QACA,WACA,QACA,kBACA,eACA,aACA,eACA,YACD,CACD"}
@@ -1,28 +0,0 @@
1
- import { InjectionKey } from 'vue';
2
- import { RedirectFlow, PopupFlow, EmbeddedFlow, NativeFlow } from '@strivacity/sdk-core/types';
3
- import { LoginContext, SDKContext, UseNativeLoginOptions } from './types';
4
- export declare const STRIVACITY_SDK: InjectionKey<SDKContext<RedirectFlow | PopupFlow | NativeFlow | EmbeddedFlow>>;
5
- export declare const STRIVACITY_LOGIN_CONTEXT: InjectionKey<LoginContext>;
6
- /**
7
- * A composable to access the Strivacity SDK context.
8
- *
9
- * @template T - The type of the Strivacity SDK flow (RedirectFlow, PopupFlow, NativeFlow, or EmbeddedFlow).
10
- * @returns {SDKContext<T>} - The Strivacity SDK context.
11
- * @throws {Error} - If the Strivacity SDK context is not found.
12
- */
13
- export declare const useStrivacity: <T extends RedirectFlow | PopupFlow | NativeFlow | EmbeddedFlow = RedirectFlow | PopupFlow | NativeFlow | EmbeddedFlow>() => SDKContext<T>;
14
- /**
15
- * A composable to access the Strivacity SDK context specifically for native login flow.
16
- *
17
- * @returns {LoginContext} - The native flow context.
18
- * @throws {Error} - If the Strivacity SDK context is not found.
19
- */
20
- export declare const useNativeLoginContext: () => LoginContext;
21
- /**
22
- * A composable that manages a native login flow session.
23
- *
24
- * @param {UseNativeLoginOptions} [options] - Optional options for the login session.
25
- * @returns {LoginContext} - The native flow context.
26
- * @throws {Error} - If the Strivacity SDK context is not found.
27
- */
28
- export declare function useNativeLogin(options?: UseNativeLoginOptions): ReturnType<typeof useNativeLoginContext>;
@@ -1,2 +0,0 @@
1
- import{inject as e,onMounted as t,onUnmounted as n,provide as r,ref as i}from"vue";import{FallbackError as a}from"@strivacity/sdk-core/utils/errors";import{isSessionExpired as o,unflattenObject as s}from"@strivacity/sdk-core/utils";var c=Symbol(`strivacity-sdk`),l=Symbol(`strivacity-login-context`),u=()=>{let t=e(c);if(!t)throw Error(`Missing SDK context`);return t},d=()=>{let t=e(l);if(!t)throw Error(`Missing SDK native login context`);return t};function f(e={}){let c=new AbortController,{sdk:d}=u(),f=i(!0),p=i({}),m=i({}),h=i({});t(async()=>{await d.init();try{await _(e.params)}catch(t){if(t instanceof DOMException&&t.name===`AbortError`)return;d.logging?.error(`Error fetching authorization URI`,t),e.onError?.(t),f.value=!1}}),n(()=>c.abort());function g(t){if(d.session&&!o(d.session)){e.onLogin?.(d.session);return}let n={hostedUrl:t?.hostedUrl??h.value.hostedUrl,finalizeUrl:t?.finalizeUrl??h.value.finalizeUrl,screen:t?.screen??h.value.screen,forms:t?.forms??h.value.forms,layout:t?.layout??h.value.layout,messages:t?.messages??{},branding:t?.branding??h.value.branding};if(n.screen!==h.value.screen){p.value={},m.value={};for(let e of n.forms??[])p.value[e.id]={},m.value[e.id]={}}else d.logging?.info(`Updating screen: ${n.screen}`);for(let t of Object.keys(n.messages??{}))t===`global`?e.onGlobalMessage?.(n.messages?.global):m.value[t]=n.messages[t]??{};h.value=n,n.finalizeUrl||(f.value=!1)}async function _(t={}){try{f.value=!0;let e=await d.startSession(t);e&&g(e)}catch(t){t instanceof a?(d.logging?.error(`Fallback error occurred`,t),e.onFallback?.(t)):(d.logging?.error(`Error starting session`,t),e.onError?.(t))}}function v(t){if(d.logging?.warn(t?`Triggering fallback due to: ${t}`:`Triggering fallback`),!h.value.hostedUrl){let e=Error(`No hosted URL provided`);throw d.logging?.error(`Fallback error`,e),e}e.onFallback?.(new a(new URL(h.value.hostedUrl)))}function y(){d.logging?.debug(`Triggering close`),e.onClose?.()}async function b(t,n){try{f.value=!0;let e=await d.submitForm(t,n??s(p.value[t]??{}));e&&g(e)}catch(t){t instanceof a?(d.logging?.error(`Fallback error occurred`,t),e.onFallback?.(t)):(d.logging?.error(`Error submitting form`,t),e.onError?.(t))}}function x(e,t,n){p.value[e]===void 0&&(p.value[e]={}),p.value[e][t]=n===``?null:n}function S(e,t,n){m.value[e]===void 0&&(m.value[e]={}),m.value[e][t]=n}return r(l,{loading:f,forms:p,messages:m,state:h,triggerFallback:v,triggerClose:y,submitForm:b,setFormValue:x,setMessage:S}),{loading:f,forms:p,messages:m,state:h,triggerFallback:v,triggerClose:y,submitForm:b,setFormValue:x,setMessage:S}}export{l as STRIVACITY_LOGIN_CONTEXT,c as STRIVACITY_SDK,f as useNativeLogin,d as useNativeLoginContext,u as useStrivacity};
2
- //# sourceMappingURL=composables.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"composables.mjs","names":[],"sources":["../src/composables.ts"],"sourcesContent":["import type { InjectionKey } from 'vue';\nimport type { RedirectFlow, PopupFlow, EmbeddedFlow, NativeFlow, NativeParams, NativeFlowState, NativeFlowMessage } from '@strivacity/sdk-core/types';\nimport type { LoginContext, SDKContext, UseNativeLoginOptions } from './types';\nimport { provide, inject, ref, onMounted, onUnmounted } from 'vue';\nimport { FallbackError } from '@strivacity/sdk-core/utils/errors';\nimport { isSessionExpired, unflattenObject } from '@strivacity/sdk-core/utils';\n\nexport const STRIVACITY_SDK: InjectionKey<SDKContext<RedirectFlow | PopupFlow | NativeFlow | EmbeddedFlow>> = Symbol('strivacity-sdk');\nexport const STRIVACITY_LOGIN_CONTEXT: InjectionKey<LoginContext> = Symbol('strivacity-login-context');\n\n/**\n * A composable to access the Strivacity SDK context.\n *\n * @template T - The type of the Strivacity SDK flow (RedirectFlow, PopupFlow, NativeFlow, or EmbeddedFlow).\n * @returns {SDKContext<T>} - The Strivacity SDK context.\n * @throws {Error} - If the Strivacity SDK context is not found.\n */\nexport const useStrivacity = <\n\tT extends RedirectFlow | PopupFlow | NativeFlow | EmbeddedFlow = RedirectFlow | PopupFlow | NativeFlow | EmbeddedFlow,\n>(): SDKContext<T> => {\n\tconst context = inject<SDKContext<T>>(STRIVACITY_SDK);\n\n\tif (!context) {\n\t\tthrow new Error('Missing SDK context');\n\t}\n\n\treturn context;\n};\n\n/**\n * A composable to access the Strivacity SDK context specifically for native login flow.\n *\n * @returns {LoginContext} - The native flow context.\n * @throws {Error} - If the Strivacity SDK context is not found.\n */\nexport const useNativeLoginContext = (): LoginContext => {\n\tconst context = inject<LoginContext>(STRIVACITY_LOGIN_CONTEXT);\n\n\tif (!context) {\n\t\tthrow new Error('Missing SDK native login context');\n\t}\n\n\treturn context;\n};\n\n/**\n * A composable that manages a native login flow session.\n *\n * @param {UseNativeLoginOptions} [options] - Optional options for the login session.\n * @returns {LoginContext} - The native flow context.\n * @throws {Error} - If the Strivacity SDK context is not found.\n */\nexport function useNativeLogin(options: UseNativeLoginOptions = {}): ReturnType<typeof useNativeLoginContext> {\n\tconst abortController = new AbortController();\n\tconst { sdk } = useStrivacity<NativeFlow>();\n\n\tconst loading = ref<boolean>(true);\n\tconst forms = ref<Record<string, Record<string, unknown>>>({});\n\tconst messages = ref<Record<string, Record<string, NativeFlowMessage>>>({});\n\tconst state = ref<Partial<NativeFlowState>>({});\n\n\tonMounted(async () => {\n\t\tawait sdk.init();\n\n\t\ttry {\n\t\t\tawait startSession(options.params);\n\t\t} catch (error) {\n\t\t\tif (error instanceof DOMException && error.name === 'AbortError') {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tsdk.logging?.error('Error fetching authorization URI', error);\n\t\t\tvoid options.onError?.(error);\n\t\t\tloading.value = false;\n\t\t}\n\t});\n\n\tonUnmounted(() => abortController.abort());\n\n\tfunction handleResponse(nextState: Partial<NativeFlowState>) {\n\t\tif (sdk.session && !isSessionExpired(sdk.session)) {\n\t\t\treturn void options.onLogin?.(sdk.session);\n\t\t}\n\n\t\tconst newState: NativeFlowState = {\n\t\t\thostedUrl: nextState?.hostedUrl ?? state.value.hostedUrl,\n\t\t\tfinalizeUrl: nextState?.finalizeUrl ?? state.value.finalizeUrl,\n\t\t\tscreen: nextState?.screen ?? state.value.screen,\n\t\t\tforms: nextState?.forms ?? state.value.forms,\n\t\t\tlayout: nextState?.layout ?? state.value.layout,\n\t\t\tmessages: nextState?.messages ?? {},\n\t\t\tbranding: nextState?.branding ?? state.value.branding,\n\t\t};\n\n\t\tif (newState.screen !== state.value.screen) {\n\t\t\tforms.value = {};\n\t\t\tmessages.value = {};\n\n\t\t\tfor (const form of newState.forms ?? []) {\n\t\t\t\tforms.value[form.id] = {};\n\t\t\t\tmessages.value[form.id] = {};\n\t\t\t}\n\t\t} else {\n\t\t\tsdk.logging?.info(`Updating screen: ${newState.screen}`);\n\t\t}\n\n\t\tfor (const formId of Object.keys(newState.messages ?? {})) {\n\t\t\tif (formId === 'global') {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain\n\t\t\t\tvoid options.onGlobalMessage?.(newState.messages?.global!);\n\t\t\t} else {\n\t\t\t\tmessages.value[formId] = newState.messages![formId] ?? {};\n\t\t\t}\n\t\t}\n\n\t\tstate.value = newState;\n\n\t\tif (!newState.finalizeUrl) {\n\t\t\tloading.value = false;\n\t\t}\n\t}\n\n\tasync function startSession(loginParams: NativeParams = {}) {\n\t\ttry {\n\t\t\tloading.value = true;\n\n\t\t\tconst nextState = await sdk.startSession(loginParams);\n\n\t\t\tif (nextState) {\n\t\t\t\thandleResponse(nextState);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (error instanceof FallbackError) {\n\t\t\t\tsdk.logging?.error('Fallback error occurred', error);\n\t\t\t\tvoid options.onFallback?.(error);\n\t\t\t} else {\n\t\t\t\tsdk.logging?.error('Error starting session', error);\n\t\t\t\tvoid options.onError?.(error);\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction triggerFallback(message?: string) {\n\t\tsdk.logging?.warn(message ? `Triggering fallback due to: ${message}` : 'Triggering fallback');\n\n\t\tif (!state.value.hostedUrl) {\n\t\t\tconst error = new Error('No hosted URL provided');\n\t\t\tsdk.logging?.error('Fallback error', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\tvoid options.onFallback?.(new FallbackError(new URL(state.value.hostedUrl)));\n\t}\n\n\tfunction triggerClose() {\n\t\tsdk.logging?.debug('Triggering close');\n\t\tvoid options.onClose?.();\n\t}\n\n\tasync function submitForm(formId: string, customBody?: Record<string, unknown>) {\n\t\ttry {\n\t\t\tloading.value = true;\n\n\t\t\tconst nextState = await sdk.submitForm(formId, customBody ?? unflattenObject(forms.value[formId] ?? {}));\n\n\t\t\tif (nextState) {\n\t\t\t\thandleResponse(nextState);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (error instanceof FallbackError) {\n\t\t\t\tsdk.logging?.error('Fallback error occurred', error);\n\t\t\t\tvoid options.onFallback?.(error);\n\t\t\t} else {\n\t\t\t\tsdk.logging?.error('Error submitting form', error);\n\t\t\t\tvoid options.onError?.(error);\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction setFormValue(formId: string, widgetId: string, value: unknown) {\n\t\tif (forms.value[formId] === undefined) {\n\t\t\tforms.value[formId] = {};\n\t\t}\n\n\t\tforms.value[formId][widgetId] = value === '' ? null : value;\n\t}\n\n\tfunction setMessage(formId: string, widgetId: string, value: NativeFlowMessage) {\n\t\tif (messages.value[formId] === undefined) {\n\t\t\tmessages.value[formId] = {};\n\t\t}\n\n\t\tmessages.value[formId][widgetId] = value;\n\t}\n\n\tprovide<LoginContext>(STRIVACITY_LOGIN_CONTEXT, {\n\t\tloading,\n\t\tforms,\n\t\tmessages,\n\t\tstate,\n\t\ttriggerFallback,\n\t\ttriggerClose,\n\t\tsubmitForm,\n\t\tsetFormValue,\n\t\tsetMessage,\n\t});\n\n\treturn {\n\t\tloading,\n\t\tforms,\n\t\tmessages,\n\t\tstate,\n\t\ttriggerFallback,\n\t\ttriggerClose,\n\t\tsubmitForm,\n\t\tsetFormValue,\n\t\tsetMessage,\n\t};\n}\n"],"mappings":"wOAOA,IAAa,EAAiG,OAAO,gBAAgB,EACxH,EAAuD,OAAO,0BAA0B,EASxF,MAES,CACrB,IAAM,EAAU,EAAsB,CAAc,EAEpD,GAAI,CAAC,EACJ,MAAU,MAAM,qBAAqB,EAGtC,OAAO,CACR,EAQa,MAA4C,CACxD,IAAM,EAAU,EAAqB,CAAwB,EAE7D,GAAI,CAAC,EACJ,MAAU,MAAM,kCAAkC,EAGnD,OAAO,CACR,EASA,SAAgB,EAAe,EAAiC,CAAC,EAA6C,CAC7G,IAAM,EAAkB,IAAI,gBACtB,CAAE,OAAQ,EAA0B,EAEpC,EAAU,EAAa,EAAI,EAC3B,EAAQ,EAA6C,CAAC,CAAC,EACvD,EAAW,EAAuD,CAAC,CAAC,EACpE,EAAQ,EAA8B,CAAC,CAAC,EAE9C,EAAU,SAAY,CACrB,MAAM,EAAI,KAAK,EAEf,GAAI,CACH,MAAM,EAAa,EAAQ,MAAM,CAClC,OAAS,EAAO,CACf,GAAI,aAAiB,cAAgB,EAAM,OAAS,aACnD,OAGD,EAAI,SAAS,MAAM,mCAAoC,CAAK,EAC5D,EAAa,UAAU,CAAK,EAC5B,EAAQ,MAAQ,EACjB,CACD,CAAC,EAED,MAAkB,EAAgB,MAAM,CAAC,EAEzC,SAAS,EAAe,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,+BAA+B,IAAY,qBAAqB,EAExF,CAAC,EAAM,MAAM,UAAW,CAC3B,IAAM,EAAY,MAAM,wBAAwB,EAEhD,MADA,EAAI,SAAS,MAAM,iBAAkB,CAAK,EACpC,CACP,CAEA,EAAa,aAAa,IAAI,EAAc,IAAI,IAAI,EAAM,MAAM,SAAS,CAAC,CAAC,CAC5E,CAEA,SAAS,GAAe,CACvB,EAAI,SAAS,MAAM,kBAAkB,EACrC,EAAa,UAAU,CACxB,CAEA,eAAe,EAAW,EAAgB,EAAsC,CAC/E,GAAI,CACH,EAAQ,MAAQ,GAEhB,IAAM,EAAY,MAAM,EAAI,WAAW,EAAQ,GAAc,EAAgB,EAAM,MAAM,IAAW,CAAC,CAAC,CAAC,EAEnG,GACH,EAAe,CAAS,CAE1B,OAAS,EAAO,CACX,aAAiB,GACpB,EAAI,SAAS,MAAM,0BAA2B,CAAK,EACnD,EAAa,aAAa,CAAK,IAE/B,EAAI,SAAS,MAAM,wBAAyB,CAAK,EACjD,EAAa,UAAU,CAAK,EAE9B,CACD,CAEA,SAAS,EAAa,EAAgB,EAAkB,EAAgB,CACnE,EAAM,MAAM,KAAY,IAAA,KAC3B,EAAM,MAAM,GAAU,CAAC,GAGxB,EAAM,MAAM,EAAO,CAAC,GAAY,IAAU,GAAK,KAAO,CACvD,CAEA,SAAS,EAAW,EAAgB,EAAkB,EAA0B,CAC3E,EAAS,MAAM,KAAY,IAAA,KAC9B,EAAS,MAAM,GAAU,CAAC,GAG3B,EAAS,MAAM,EAAO,CAAC,GAAY,CACpC,CAcA,OAZA,EAAsB,EAA0B,CAC/C,UACA,QACA,WACA,QACA,kBACA,eACA,aACA,eACA,YACD,CAAC,EAEM,CACN,UACA,QACA,WACA,QACA,kBACA,eACA,aACA,eACA,YACD,CACD"}
package/dist/errors.cjs DELETED
@@ -1 +0,0 @@
1
- var e=require("@strivacity/sdk-core/utils/errors");Object.keys(e).forEach(function(t){t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:function(){return e[t]}})});
package/dist/errors.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from '@strivacity/sdk-core/utils/errors';
package/dist/errors.mjs DELETED
@@ -1 +0,0 @@
1
- export*from"@strivacity/sdk-core/utils/errors";
package/dist/index.d.ts DELETED
@@ -1,9 +0,0 @@
1
- export * from '@strivacity/sdk-core/flows';
2
- export * from '@strivacity/sdk-core/handlers';
3
- export * from '@strivacity/sdk-core/utils';
4
- export * from './composables';
5
- export * from './errors';
6
- export * from './plugin';
7
- export * from './storages';
8
- export * from './types';
9
- export * from './utils';
package/dist/index.mjs DELETED
@@ -1 +0,0 @@
1
- import{STRIVACITY_LOGIN_CONTEXT as e,STRIVACITY_SDK as t,useNativeLogin as n,useNativeLoginContext as r,useStrivacity as i}from"./composables.mjs";import"./errors.mjs";import{createStrivacitySDK as a}from"./plugin.mjs";import"./storages.mjs";import"./types.mjs";import"./utils.mjs";export*from"@strivacity/sdk-core/utils/errors";export*from"@strivacity/sdk-core/utils";export*from"@strivacity/sdk-core/flows";export*from"@strivacity/sdk-core/handlers";export*from"@strivacity/sdk-core/storages";export*from"@strivacity/sdk-core/types";export{e as STRIVACITY_LOGIN_CONTEXT,t as STRIVACITY_SDK,a as createStrivacitySDK,n as useNativeLogin,r as useNativeLoginContext,i as useStrivacity};
package/dist/plugin.cjs DELETED
@@ -1,2 +0,0 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./composables.cjs");let t=require("vue"),n=require("@strivacity/sdk-core");var r,i=i=>{let a=(0,t.ref)(!0),o=(0,t.ref)(globalThis.navigator?.language??`en-US`),s=(0,t.ref)(!1),c=(0,t.ref)(null),l=(0,t.ref)(null),u=(0,t.ref)(null),d=(0,t.ref)(!0),f=(0,t.ref)(null),p=async()=>{let e=await r.isAuthenticated;a.value&&=!1,r.language!==o.value&&(o.value=r.language),e!==s.value&&(s.value=e),r.idTokenClaims!==c.value&&(c.value=r.idTokenClaims||null),r.accessToken!==l.value&&(l.value=r.accessToken||null),r.refreshToken!==u.value&&(u.value=r.refreshToken||null),r.accessTokenExpired!==d.value&&(d.value=r.accessTokenExpired),r.accessTokenExpirationDate!==f.value&&(f.value=r.accessTokenExpirationDate||null)};return{install:t=>{r=(0,n.initFlow)(i);let m=r.subscribeToAllEvents(p);p(),t.onUnmount(()=>m.dispose()),t.provide(e.STRIVACITY_SDK,{sdk:r,loading:a,language:o,isAuthenticated:s,idTokenClaims:c,accessToken:l,refreshToken:u,accessTokenExpired:d,accessTokenExpirationDate:f,init:()=>r.init(),subscribeToEvent:((...e)=>r.subscribeToEvent(...e)),subscribeToAllEvents:(...e)=>r.subscribeToAllEvents(...e),checkAuthentication:(...e)=>r.checkAuthentication(...e),tokenExchange:(...e)=>r.tokenExchange(...e),handleCallback:(...e)=>r.handleCallback(...e),refresh:()=>r.refresh(),revoke:()=>r.revoke(),logout:(...e)=>r.logout(...e),login:(...e)=>r.login(...e),register:(...e)=>r.register(...e),entry:(...e)=>r.entry(...e)})}}};exports.createStrivacitySDK=i;
2
- //# sourceMappingURL=plugin.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"plugin.cjs","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import type { IdTokenClaims, SDKInitConfig } from '@strivacity/sdk-core/types';\nimport type { SDKInstance } from './types';\nimport { type App, type Plugin, ref } from 'vue';\nimport { initFlow } from '@strivacity/sdk-core';\nimport { STRIVACITY_SDK } from './composables';\n\nlet sdk: SDKInstance;\n\n/**\n * Creates a Strivacity SDK plugin for Vue.\n *\n * @param {SDKOptions} options - The options used to configure the SDK.\n */\nexport const createStrivacitySDK = (options: SDKInitConfig): Plugin => {\n\tconst loadingRef = ref<boolean>(true);\n\tconst languageRef = ref<string>(globalThis.navigator?.language ?? 'en-US');\n\tconst isAuthenticatedRef = ref<boolean>(false);\n\tconst idTokenClaimsRef = ref<IdTokenClaims | null>(null);\n\tconst accessTokenRef = ref<string | null>(null);\n\tconst refreshTokenRef = ref<string | null>(null);\n\tconst accessTokenExpiredRef = ref<boolean>(true);\n\tconst accessTokenExpirationDateRef = ref<number | null>(null);\n\n\tconst updateSession = async () => {\n\t\tconst authenticated = await sdk.isAuthenticated;\n\n\t\tif (loadingRef.value) {\n\t\t\tloadingRef.value = false;\n\t\t}\n\t\tif (sdk.language !== languageRef.value) {\n\t\t\tlanguageRef.value = sdk.language;\n\t\t}\n\t\tif (authenticated !== isAuthenticatedRef.value) {\n\t\t\tisAuthenticatedRef.value = authenticated;\n\t\t}\n\t\tif (sdk.idTokenClaims !== idTokenClaimsRef.value) {\n\t\t\tidTokenClaimsRef.value = sdk.idTokenClaims || null;\n\t\t}\n\t\tif (sdk.accessToken !== accessTokenRef.value) {\n\t\t\taccessTokenRef.value = sdk.accessToken || null;\n\t\t}\n\t\tif (sdk.refreshToken !== refreshTokenRef.value) {\n\t\t\trefreshTokenRef.value = sdk.refreshToken || null;\n\t\t}\n\t\tif (sdk.accessTokenExpired !== accessTokenExpiredRef.value) {\n\t\t\taccessTokenExpiredRef.value = sdk.accessTokenExpired;\n\t\t}\n\t\tif (sdk.accessTokenExpirationDate !== accessTokenExpirationDateRef.value) {\n\t\t\taccessTokenExpirationDateRef.value = sdk.accessTokenExpirationDate || null;\n\t\t}\n\t};\n\n\tconst plugin = {\n\t\tinstall: (app: App) => {\n\t\t\tsdk = initFlow(options as never);\n\t\t\tconst sdkEvents = sdk.subscribeToAllEvents(updateSession);\n\n\t\t\tvoid updateSession();\n\n\t\t\tapp.onUnmount(() => sdkEvents.dispose());\n\n\t\t\tapp.provide(STRIVACITY_SDK, {\n\t\t\t\tsdk,\n\t\t\t\tloading: loadingRef,\n\t\t\t\tlanguage: languageRef,\n\t\t\t\tisAuthenticated: isAuthenticatedRef,\n\t\t\t\tidTokenClaims: idTokenClaimsRef,\n\t\t\t\taccessToken: accessTokenRef,\n\t\t\t\trefreshToken: refreshTokenRef,\n\t\t\t\taccessTokenExpired: accessTokenExpiredRef,\n\t\t\t\taccessTokenExpirationDate: accessTokenExpirationDateRef,\n\t\t\t\tinit: () => sdk.init(),\n\t\t\t\tsubscribeToEvent: ((...args: Parameters<typeof sdk.subscribeToEvent>) => sdk.subscribeToEvent(...args)) as typeof sdk.subscribeToEvent,\n\t\t\t\tsubscribeToAllEvents: (...args: Parameters<typeof sdk.subscribeToAllEvents>) => sdk.subscribeToAllEvents(...args),\n\t\t\t\tcheckAuthentication: (...args: Parameters<typeof sdk.checkAuthentication>) => sdk.checkAuthentication(...args),\n\t\t\t\ttokenExchange: (...args: Parameters<typeof sdk.tokenExchange>) => sdk.tokenExchange(...args),\n\t\t\t\thandleCallback: (...args: Parameters<typeof sdk.handleCallback>) => sdk.handleCallback(...args),\n\t\t\t\trefresh: () => sdk.refresh(),\n\t\t\t\trevoke: () => sdk.revoke(),\n\t\t\t\tlogout: (...args: Parameters<typeof sdk.logout>) => sdk.logout(...args),\n\t\t\t\tlogin: (...args: Parameters<typeof sdk.login>) => sdk.login(...args),\n\t\t\t\tregister: (...args: Parameters<typeof sdk.register>) => sdk.register(...args),\n\t\t\t\tentry: (...args: Parameters<typeof sdk.entry>) => sdk.entry(...args),\n\t\t\t});\n\t\t},\n\t};\n\n\treturn plugin;\n};\n"],"mappings":"+JAMA,IAAI,EAOS,EAAuB,GAAmC,CACtE,IAAM,GAAA,EAAa,EAAA,IAAA,CAAa,EAAI,EAC9B,GAAA,EAAc,EAAA,IAAA,CAAY,WAAW,WAAW,UAAY,OAAO,EACnE,GAAA,EAAqB,EAAA,IAAA,CAAa,EAAK,EACvC,GAAA,EAAmB,EAAA,IAAA,CAA0B,IAAI,EACjD,GAAA,EAAiB,EAAA,IAAA,CAAmB,IAAI,EACxC,GAAA,EAAkB,EAAA,IAAA,CAAmB,IAAI,EACzC,GAAA,EAAwB,EAAA,IAAA,CAAa,EAAI,EACzC,GAAA,EAA+B,EAAA,IAAA,CAAmB,IAAI,EAEtD,EAAgB,SAAY,CACjC,IAAM,EAAgB,MAAM,E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C5E,OAAQ,GAAG,IAAuC,EAAI,MAAM,GAAG,CAAI,CACpE,CAAC,CACF,CAGM,CACR"}
package/dist/plugin.d.ts DELETED
@@ -1,8 +0,0 @@
1
- import { SDKInitConfig } from '@strivacity/sdk-core/types';
2
- import { Plugin } from 'vue';
3
- /**
4
- * Creates a Strivacity SDK plugin for Vue.
5
- *
6
- * @param {SDKOptions} options - The options used to configure the SDK.
7
- */
8
- export declare const createStrivacitySDK: (options: SDKInitConfig) => Plugin;
package/dist/plugin.mjs DELETED
@@ -1,2 +0,0 @@
1
- import{STRIVACITY_SDK as e}from"./composables.mjs";import{ref as t}from"vue";import{initFlow as n}from"@strivacity/sdk-core";var r,i=i=>{let a=t(!0),o=t(globalThis.navigator?.language??`en-US`),s=t(!1),c=t(null),l=t(null),u=t(null),d=t(!0),f=t(null),p=async()=>{let e=await r.isAuthenticated;a.value&&=!1,r.language!==o.value&&(o.value=r.language),e!==s.value&&(s.value=e),r.idTokenClaims!==c.value&&(c.value=r.idTokenClaims||null),r.accessToken!==l.value&&(l.value=r.accessToken||null),r.refreshToken!==u.value&&(u.value=r.refreshToken||null),r.accessTokenExpired!==d.value&&(d.value=r.accessTokenExpired),r.accessTokenExpirationDate!==f.value&&(f.value=r.accessTokenExpirationDate||null)};return{install:t=>{r=n(i);let m=r.subscribeToAllEvents(p);p(),t.onUnmount(()=>m.dispose()),t.provide(e,{sdk:r,loading:a,language:o,isAuthenticated:s,idTokenClaims:c,accessToken:l,refreshToken:u,accessTokenExpired:d,accessTokenExpirationDate:f,init:()=>r.init(),subscribeToEvent:((...e)=>r.subscribeToEvent(...e)),subscribeToAllEvents:(...e)=>r.subscribeToAllEvents(...e),checkAuthentication:(...e)=>r.checkAuthentication(...e),tokenExchange:(...e)=>r.tokenExchange(...e),handleCallback:(...e)=>r.handleCallback(...e),refresh:()=>r.refresh(),revoke:()=>r.revoke(),logout:(...e)=>r.logout(...e),login:(...e)=>r.login(...e),register:(...e)=>r.register(...e),entry:(...e)=>r.entry(...e)})}}};export{i as createStrivacitySDK};
2
- //# sourceMappingURL=plugin.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"plugin.mjs","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import type { IdTokenClaims, SDKInitConfig } from '@strivacity/sdk-core/types';\nimport type { SDKInstance } from './types';\nimport { type App, type Plugin, ref } from 'vue';\nimport { initFlow } from '@strivacity/sdk-core';\nimport { STRIVACITY_SDK } from './composables';\n\nlet sdk: SDKInstance;\n\n/**\n * Creates a Strivacity SDK plugin for Vue.\n *\n * @param {SDKOptions} options - The options used to configure the SDK.\n */\nexport const createStrivacitySDK = (options: SDKInitConfig): Plugin => {\n\tconst loadingRef = ref<boolean>(true);\n\tconst languageRef = ref<string>(globalThis.navigator?.language ?? 'en-US');\n\tconst isAuthenticatedRef = ref<boolean>(false);\n\tconst idTokenClaimsRef = ref<IdTokenClaims | null>(null);\n\tconst accessTokenRef = ref<string | null>(null);\n\tconst refreshTokenRef = ref<string | null>(null);\n\tconst accessTokenExpiredRef = ref<boolean>(true);\n\tconst accessTokenExpirationDateRef = ref<number | null>(null);\n\n\tconst updateSession = async () => {\n\t\tconst authenticated = await sdk.isAuthenticated;\n\n\t\tif (loadingRef.value) {\n\t\t\tloadingRef.value = false;\n\t\t}\n\t\tif (sdk.language !== languageRef.value) {\n\t\t\tlanguageRef.value = sdk.language;\n\t\t}\n\t\tif (authenticated !== isAuthenticatedRef.value) {\n\t\t\tisAuthenticatedRef.value = authenticated;\n\t\t}\n\t\tif (sdk.idTokenClaims !== idTokenClaimsRef.value) {\n\t\t\tidTokenClaimsRef.value = sdk.idTokenClaims || null;\n\t\t}\n\t\tif (sdk.accessToken !== accessTokenRef.value) {\n\t\t\taccessTokenRef.value = sdk.accessToken || null;\n\t\t}\n\t\tif (sdk.refreshToken !== refreshTokenRef.value) {\n\t\t\trefreshTokenRef.value = sdk.refreshToken || null;\n\t\t}\n\t\tif (sdk.accessTokenExpired !== accessTokenExpiredRef.value) {\n\t\t\taccessTokenExpiredRef.value = sdk.accessTokenExpired;\n\t\t}\n\t\tif (sdk.accessTokenExpirationDate !== accessTokenExpirationDateRef.value) {\n\t\t\taccessTokenExpirationDateRef.value = sdk.accessTokenExpirationDate || null;\n\t\t}\n\t};\n\n\tconst plugin = {\n\t\tinstall: (app: App) => {\n\t\t\tsdk = initFlow(options as never);\n\t\t\tconst sdkEvents = sdk.subscribeToAllEvents(updateSession);\n\n\t\t\tvoid updateSession();\n\n\t\t\tapp.onUnmount(() => sdkEvents.dispose());\n\n\t\t\tapp.provide(STRIVACITY_SDK, {\n\t\t\t\tsdk,\n\t\t\t\tloading: loadingRef,\n\t\t\t\tlanguage: languageRef,\n\t\t\t\tisAuthenticated: isAuthenticatedRef,\n\t\t\t\tidTokenClaims: idTokenClaimsRef,\n\t\t\t\taccessToken: accessTokenRef,\n\t\t\t\trefreshToken: refreshTokenRef,\n\t\t\t\taccessTokenExpired: accessTokenExpiredRef,\n\t\t\t\taccessTokenExpirationDate: accessTokenExpirationDateRef,\n\t\t\t\tinit: () => sdk.init(),\n\t\t\t\tsubscribeToEvent: ((...args: Parameters<typeof sdk.subscribeToEvent>) => sdk.subscribeToEvent(...args)) as typeof sdk.subscribeToEvent,\n\t\t\t\tsubscribeToAllEvents: (...args: Parameters<typeof sdk.subscribeToAllEvents>) => sdk.subscribeToAllEvents(...args),\n\t\t\t\tcheckAuthentication: (...args: Parameters<typeof sdk.checkAuthentication>) => sdk.checkAuthentication(...args),\n\t\t\t\ttokenExchange: (...args: Parameters<typeof sdk.tokenExchange>) => sdk.tokenExchange(...args),\n\t\t\t\thandleCallback: (...args: Parameters<typeof sdk.handleCallback>) => sdk.handleCallback(...args),\n\t\t\t\trefresh: () => sdk.refresh(),\n\t\t\t\trevoke: () => sdk.revoke(),\n\t\t\t\tlogout: (...args: Parameters<typeof sdk.logout>) => sdk.logout(...args),\n\t\t\t\tlogin: (...args: Parameters<typeof sdk.login>) => sdk.login(...args),\n\t\t\t\tregister: (...args: Parameters<typeof sdk.register>) => sdk.register(...args),\n\t\t\t\tentry: (...args: Parameters<typeof sdk.entry>) => sdk.entry(...args),\n\t\t\t});\n\t\t},\n\t};\n\n\treturn plugin;\n};\n"],"mappings":"6HAMA,IAAI,EAOS,EAAuB,GAAmC,CACtE,IAAM,EAAa,EAAa,EAAI,EAC9B,EAAc,EAAY,WAAW,WAAW,UAAY,OAAO,EACnE,EAAqB,EAAa,EAAK,EACvC,EAAmB,EAA0B,IAAI,EACjD,EAAiB,EAAmB,IAAI,EACxC,EAAkB,EAAmB,IAAI,EACzC,EAAwB,EAAa,EAAI,EACzC,EAA+B,EAAmB,IAAI,EAEtD,EAAgB,SAAY,CACjC,IAAM,EAAgB,MAAM,EAAI,gBAEhC,AACC,EAAW,QAAQ,GAEhB,EAAI,WAAa,EAAY,QAChC,EAAY,MAAQ,EAAI,UAErB,IAAkB,EAAmB,QACxC,EAAmB,MAAQ,GAExB,EAAI,gBAAkB,EAAiB,QAC1C,EAAiB,MAAQ,EAAI,eAAiB,MAE3C,EAAI,cAAgB,EAAe,QACtC,EAAe,MAAQ,EAAI,aAAe,MAEvC,EAAI,eAAiB,EAAgB,QACxC,EAAgB,MAAQ,EAAI,cAAgB,MAEzC,EAAI,qBAAuB,EAAsB,QACpD,EAAsB,MAAQ,EAAI,oBAE/B,EAAI,4BAA8B,EAA6B,QAClE,EAA6B,MAAQ,EAAI,2BAA6B,KAExE,EAqCA,MAAO,CAlCN,QAAU,GAAa,CACtB,EAAM,EAAS,CAAgB,EAC/B,IAAM,EAAY,EAAI,qBAAqB,CAAa,EAExD,EAAmB,EAEnB,EAAI,cAAgB,EAAU,QAAQ,CAAC,EAEvC,EAAI,QAAQ,EAAgB,CAC3B,MACA,QAAS,EACT,SAAU,EACV,gBAAiB,EACjB,cAAe,EACf,YAAa,EACb,aAAc,EACd,mBAAoB,EACpB,0BAA2B,EAC3B,SAAY,EAAI,KAAK,EACrB,mBAAoB,GAAG,IAAkD,EAAI,iBAAiB,GAAG,CAAI,GACrG,sBAAuB,GAAG,IAAsD,EAAI,qBAAqB,GAAG,CAAI,EAChH,qBAAsB,GAAG,IAAqD,EAAI,oBAAoB,GAAG,CAAI,EAC7G,eAAgB,GAAG,IAA+C,EAAI,cAAc,GAAG,CAAI,EAC3F,gBAAiB,GAAG,IAAgD,EAAI,eAAe,GAAG,CAAI,EAC9F,YAAe,EAAI,QAAQ,EAC3B,WAAc,EAAI,OAAO,EACzB,QAAS,GAAG,IAAwC,EAAI,OAAO,GAAG,CAAI,EACtE,OAAQ,GAAG,IAAuC,EAAI,MAAM,GAAG,CAAI,EACnE,UAAW,GAAG,IAA0C,EAAI,SAAS,GAAG,CAAI,EAC5E,OAAQ,GAAG,IAAuC,EAAI,MAAM,GAAG,CAAI,CACpE,CAAC,CACF,CAGM,CACR"}
package/dist/storages.cjs DELETED
@@ -1 +0,0 @@
1
- var e=require("@strivacity/sdk-core/storages");Object.keys(e).forEach(function(t){t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:function(){return e[t]}})});
@@ -1 +0,0 @@
1
- export * from '@strivacity/sdk-core/storages';
package/dist/storages.mjs DELETED
@@ -1 +0,0 @@
1
- export*from"@strivacity/sdk-core/storages";
package/dist/types.cjs DELETED
@@ -1 +0,0 @@
1
- var e=require("@strivacity/sdk-core/types");Object.keys(e).forEach(function(t){t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:function(){return e[t]}})});
package/dist/types.d.ts DELETED
@@ -1,171 +0,0 @@
1
- import { Ref } from 'vue';
2
- import { IdTokenClaims, RedirectFlow, PopupFlow, NativeFlow, EmbeddedFlow, initFlow, NativeParams, NativeFlowState, SessionData, NativeFlowMessage } from '@strivacity/sdk-core';
3
- import { FallbackError } from '@strivacity/sdk-core/utils';
4
- export * from '@strivacity/sdk-core/types';
5
- export type SDKContext<Flow extends RedirectFlow | PopupFlow | NativeFlow | EmbeddedFlow> = {
6
- /**
7
- * The underlying Strivacity SDK flow instance.
8
- */
9
- readonly sdk: Flow;
10
- /**
11
- * A boolean indicating whether the SDK is still loading.
12
- */
13
- readonly loading: Ref<boolean>;
14
- /**
15
- * BCP 47 language code representing the current language of the SDK.
16
- */
17
- readonly language: Ref<string>;
18
- /**
19
- * A boolean ref indicating whether the user is authenticated.
20
- */
21
- readonly isAuthenticated: Ref<boolean>;
22
- /**
23
- * The claims from the ID token, if available.
24
- */
25
- readonly idTokenClaims: Ref<IdTokenClaims | null>;
26
- /**
27
- * The access token, if available.
28
- */
29
- readonly accessToken: Ref<string | null>;
30
- /**
31
- * The refresh token, if available.
32
- */
33
- readonly refreshToken: Ref<string | null>;
34
- /**
35
- * A boolean ref indicating whether the access token has expired.
36
- */
37
- readonly accessTokenExpired: Ref<boolean>;
38
- /**
39
- * The expiration date of the access token, if available.
40
- */
41
- readonly accessTokenExpirationDate: Ref<number | null>;
42
- /**
43
- * Subscribes to a specific SDK event.
44
- */
45
- subscribeToEvent: Flow['subscribeToEvent'];
46
- /**
47
- * Subscribes to all SDK events.
48
- */
49
- subscribeToAllEvents: Flow['subscribeToAllEvents'];
50
- /**
51
- * Checks whether the user is currently authenticated, optionally triggering a token refresh.
52
- */
53
- checkAuthentication: Flow['checkAuthentication'];
54
- /**
55
- * Initializes the SDK, loading metadata and restoring any persisted session.
56
- */
57
- init: Flow['init'];
58
- /**
59
- * Performs a token exchange using the provided parameters.
60
- */
61
- tokenExchange: Flow['tokenExchange'];
62
- /**
63
- * Handles the authentication callback by parsing the response from the given URL.
64
- */
65
- handleCallback: Flow['handleCallback'];
66
- /**
67
- * Refreshes the current access token using the refresh token.
68
- */
69
- refresh: Flow['refresh'];
70
- /**
71
- * Revokes the current tokens.
72
- */
73
- revoke: Flow['revoke'];
74
- /**
75
- * Logs the user out and optionally redirects to a post-logout URI.
76
- */
77
- logout: Flow['logout'];
78
- /**
79
- * Initiates the login flow.
80
- */
81
- login: Flow['login'];
82
- /**
83
- * Initiates the registration flow.
84
- */
85
- register: Flow['register'];
86
- /**
87
- * Handles the entry point URL of the authentication flow, typically used for embedded or native modes.
88
- */
89
- entry: Flow['entry'];
90
- };
91
- export type SDKInstance = ReturnType<typeof initFlow>;
92
- export type LoginContext = {
93
- /**
94
- * Whether a form submission or session initialization is in progress.
95
- */
96
- loading: Ref<boolean>;
97
- /**
98
- * Current form field values, keyed by form ID then widget ID.
99
- */
100
- forms: Ref<Record<string, Record<string, unknown>>>;
101
- /**
102
- * Current validation and info messages, keyed by form ID then widget ID.
103
- */
104
- messages: Ref<Record<string, Record<string, NativeFlowMessage>>>;
105
- /**
106
- * The current login flow state returned by the backend.
107
- */
108
- state: Ref<Partial<NativeFlowState>>;
109
- /**
110
- * Submits the form with the given ID and advances the login flow.
111
- *
112
- * @param formId - The ID of the form to submit.
113
- * @param customBody - Optional custom body to send with the form submission. If not provided, the current form values will be used.
114
- * @returns A promise that resolves when the form submission is complete.
115
- */
116
- submitForm: (formId: string, customBody?: Record<string, unknown>) => Promise<void>;
117
- /**
118
- * Redirects to the hosted login UI.
119
- *
120
- * @param message - Optional message to log before redirecting.
121
- * @returns A promise that resolves when the redirect is initiated.
122
- */
123
- triggerFallback: (message?: string) => void;
124
- /**
125
- * Signals that the login flow was closed by the user.
126
- */
127
- triggerClose: () => void;
128
- /**
129
- * Updates a single field value within a form before submission.
130
- *
131
- * @param formId - The ID of the form containing the field.
132
- * @param widgetId - The ID of the widget (field) to update.
133
- * @param value - The new value to set for the field.
134
- */
135
- setFormValue: (formId: string, widgetId: string, value: unknown) => void;
136
- /**
137
- * Sets a validation or info message on a specific widget.
138
- *
139
- * @param formId - The ID of the form containing the widget.
140
- * @param widgetId - The ID of the widget to set the message for.
141
- * @param value - The message to set, which can be a string or a structured NativeFlowMessage.
142
- */
143
- setMessage: (formId: string, widgetId: string, value: NativeFlowMessage) => void;
144
- };
145
- export type UseNativeLoginOptions = {
146
- /**
147
- * Optional parameters to be passed to the login session request. These parameters will be sent to the `authorizationUri` endpoint.
148
- */
149
- params?: NativeParams;
150
- /**
151
- * A render function called when the user successfully completes the login flow.
152
- * This can be used to perform any necessary actions after a successful login, such as redirecting the user or updating the application state. Defaults to `null`.
153
- */
154
- onLogin?: (session: SessionData) => void | Promise<void>;
155
- /**
156
- * Called when the fallback flow is triggered, typically due to an error or unsupported environment. Receives a `FallbackError` object containing the hosted URL to redirect to.
157
- */
158
- onFallback?: (error: FallbackError) => void | Promise<void>;
159
- /**
160
- * Called when the login flow is closed by the user. This can be used to perform any necessary cleanup or state updates in the application. Defaults to `null`.
161
- */
162
- onClose?: () => void | Promise<void>;
163
- /**
164
- * Called when an error occurs during the login session initialization or flow. Receives an `Error` object describing the issue.
165
- */
166
- onError?: (error: Error) => void | Promise<void>;
167
- /**
168
- * Called when a global message is received during the login flow. This can be used to display messages to the user or log them for debugging purposes.
169
- */
170
- onGlobalMessage?: (message: NativeFlowMessage) => void | Promise<void>;
171
- };
package/dist/types.mjs DELETED
@@ -1 +0,0 @@
1
- export*from"@strivacity/sdk-core/types";
package/dist/utils.cjs DELETED
@@ -1 +0,0 @@
1
- var e=require("@strivacity/sdk-core/utils");Object.keys(e).forEach(function(t){t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:function(){return e[t]}})});
package/dist/utils.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from '@strivacity/sdk-core/utils';
package/dist/utils.mjs DELETED
@@ -1 +0,0 @@
1
- export*from"@strivacity/sdk-core/utils";