@strivacity/sdk-vue 3.0.2 → 4.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -18
- package/README.md +1402 -419
- package/dist/composables.cjs +2 -2
- package/dist/composables.cjs.map +1 -1
- package/dist/composables.d.ts +23 -8
- package/dist/composables.mjs +2 -2
- package/dist/composables.mjs.map +1 -1
- package/dist/errors.cjs +1 -0
- package/dist/errors.d.ts +1 -0
- package/dist/errors.mjs +1 -0
- package/dist/index.cjs +1 -2
- package/dist/index.d.ts +9 -31
- package/dist/index.mjs +1 -2
- package/dist/plugin.cjs +2 -0
- package/dist/plugin.cjs.map +1 -0
- package/dist/plugin.d.ts +8 -0
- package/dist/plugin.mjs +2 -0
- package/dist/plugin.mjs.map +1 -0
- package/dist/storages.cjs +1 -0
- package/dist/storages.d.ts +1 -0
- package/dist/storages.mjs +1 -0
- package/dist/types.cjs +1 -2
- package/dist/types.d.ts +106 -118
- package/dist/types.mjs +1 -2
- package/dist/utils.cjs +1 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.mjs +1 -0
- package/eslint.config.mjs +3 -0
- package/package.json +45 -8
- package/project.json +46 -0
- package/src/composables.ts +219 -0
- package/src/env.d.ts +8 -0
- package/src/errors.ts +1 -0
- package/src/index.ts +9 -0
- package/src/plugin.ts +89 -0
- package/src/storages.ts +1 -0
- package/src/types.ts +220 -0
- package/src/utils.ts +1 -0
- package/testing/tests/composables.spec.ts +328 -0
- package/testing/tests/errors.spec.ts +10 -0
- package/testing/tests/index.spec.ts +105 -0
- package/testing/tests/plugin.spec.ts +129 -0
- package/testing/tests/storages.spec.ts +10 -0
- package/testing/tests/utils.spec.ts +10 -0
- package/testing/utils/common.ts +53 -0
- package/tsconfig.app.json +4 -0
- package/tsconfig.json +3 -0
- package/vite.config.mts +53 -0
- package/dist/assets/login-renderer.vue_vue_type_script_setup_true_lang.cjs +0 -2
- package/dist/assets/login-renderer.vue_vue_type_script_setup_true_lang.cjs.map +0 -1
- package/dist/assets/login-renderer.vue_vue_type_script_setup_true_lang.mjs +0 -2
- package/dist/assets/login-renderer.vue_vue_type_script_setup_true_lang.mjs.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/login-renderer.cjs +0 -2
- package/dist/login-renderer.cjs.map +0 -1
- package/dist/login-renderer.mjs +0 -2
- package/dist/login-renderer.mjs.map +0 -1
- package/dist/login-renderer.vue.d.ts +0 -37
- package/dist/types.cjs.map +0 -1
- package/dist/types.mjs.map +0 -1
package/dist/composables.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=composables.cjs.map
|
|
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){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
|
package/dist/composables.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"composables.cjs","sources":["../src/composables.ts"],"sourcesContent":["import {
|
|
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 { 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) {\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,qBAAqB,EAGtC,OAAO,CACR,EAQa,MAA4C,CACxD,IAAM,GAAA,EAAU,EAAA,OAAA,CAAqB,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,GAAA,EAAU,EAAA,IAAA,CAAa,EAAI,EAC3B,GAAA,EAAQ,EAAA,IAAA,CAA6C,CAAC,CAAC,EACvD,GAAA,EAAW,EAAA,IAAA,CAAuD,CAAC,CAAC,EACpE,GAAA,EAAQ,EAAA,IA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,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"}
|
package/dist/composables.d.ts
CHANGED
|
@@ -1,13 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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>;
|
|
3
6
|
/**
|
|
4
|
-
*
|
|
7
|
+
* A composable to access the Strivacity SDK context.
|
|
5
8
|
*
|
|
6
|
-
* @template T The type of
|
|
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.
|
|
7
16
|
*
|
|
8
|
-
* @
|
|
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.
|
|
9
23
|
*
|
|
10
|
-
* @
|
|
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.
|
|
11
27
|
*/
|
|
12
|
-
export declare
|
|
13
|
-
export { STRIVACITY_SDK };
|
|
28
|
+
export declare function useNativeLogin(options?: UseNativeLoginOptions): ReturnType<typeof useNativeLoginContext>;
|
package/dist/composables.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{inject as
|
|
2
|
-
//# sourceMappingURL=composables.mjs.map
|
|
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{unflattenObject as o}from"@strivacity/sdk-core/utils";var s=Symbol(`strivacity-sdk`),c=Symbol(`strivacity-login-context`),l=()=>{let t=e(s);if(!t)throw Error(`Missing SDK context`);return t},u=()=>{let t=e(c);if(!t)throw Error(`Missing SDK native login context`);return t};function d(e={}){let s=new AbortController,{sdk:u}=l(),d=i(!0),f=i({}),p=i({}),m=i({});t(async()=>{await u.init();try{await g(e.params)}catch(t){if(t instanceof DOMException&&t.name===`AbortError`)return;u.logging?.error(`Error fetching authorization URI`,t),e.onError?.(t),d.value=!1}}),n(()=>s.abort());function h(t){if(u.session){e.onLogin?.(u.session);return}let n={hostedUrl:t?.hostedUrl??m.value.hostedUrl,finalizeUrl:t?.finalizeUrl??m.value.finalizeUrl,screen:t?.screen??m.value.screen,forms:t?.forms??m.value.forms,layout:t?.layout??m.value.layout,messages:t?.messages??{},branding:t?.branding??m.value.branding};if(n.screen!==m.value.screen){f.value={},p.value={};for(let e of n.forms??[])f.value[e.id]={},p.value[e.id]={}}else u.logging?.info(`Updating screen: ${n.screen}`);for(let t of Object.keys(n.messages??{}))t===`global`?e.onGlobalMessage?.(n.messages?.global):p.value[t]=n.messages[t]??{};m.value=n,n.finalizeUrl||(d.value=!1)}async function g(t={}){try{d.value=!0;let e=await u.startSession(t);e&&h(e)}catch(t){t instanceof a?(u.logging?.error(`Fallback error occurred`,t),e.onFallback?.(t)):(u.logging?.error(`Error starting session`,t),e.onError?.(t))}}function _(t){if(u.logging?.warn(t?`Triggering fallback due to: ${t}`:`Triggering fallback`),!m.value.hostedUrl){let e=Error(`No hosted URL provided`);throw u.logging?.error(`Fallback error`,e),e}e.onFallback?.(new a(new URL(m.value.hostedUrl)))}function v(){u.logging?.debug(`Triggering close`),e.onClose?.()}async function y(t,n){try{d.value=!0;let e=await u.submitForm(t,n??o(f.value[t]??{}));e&&h(e)}catch(t){t instanceof a?(u.logging?.error(`Fallback error occurred`,t),e.onFallback?.(t)):(u.logging?.error(`Error submitting form`,t),e.onError?.(t))}}function b(e,t,n){f.value[e]===void 0&&(f.value[e]={}),f.value[e][t]=n===``?null:n}function x(e,t,n){p.value[e]===void 0&&(p.value[e]={}),p.value[e][t]=n}return r(c,{loading:d,forms:f,messages:p,state:m,triggerFallback:_,triggerClose:v,submitForm:y,setFormValue:b,setMessage:x}),{loading:d,forms:f,messages:p,state:m,triggerFallback:_,triggerClose:v,submitForm:y,setFormValue:b,setMessage:x}}export{c as STRIVACITY_LOGIN_CONTEXT,s as STRIVACITY_SDK,d as useNativeLogin,u as useNativeLoginContext,l as useStrivacity};
|
|
2
|
+
//# sourceMappingURL=composables.mjs.map
|
package/dist/composables.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"composables.mjs","sources":["../src/composables.ts"],"sourcesContent":["import {
|
|
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 { 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) {\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":"kNAOA,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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dk-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
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@strivacity/sdk-core/utils/errors';
|
package/dist/errors.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"@strivacity/sdk-core/utils/errors";
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=index.cjs.map
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./composables.cjs");require("./errors.cjs");const t=require("./plugin.cjs");require("./storages.cjs"),require("./types.cjs"),require("./utils.cjs"),exports.STRIVACITY_LOGIN_CONTEXT=e.STRIVACITY_LOGIN_CONTEXT,exports.STRIVACITY_SDK=e.STRIVACITY_SDK,exports.createStrivacitySDK=t.createStrivacitySDK,exports.useNativeLogin=e.useNativeLogin,exports.useNativeLoginContext=e.useNativeLoginContext,exports.useStrivacity=e.useStrivacity;var n=require("@strivacity/sdk-core/flows");Object.keys(n).forEach(function(e){e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:function(){return n[e]}})});var r=require("@strivacity/sdk-core/handlers");Object.keys(r).forEach(function(e){e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:function(){return r[e]}})});var i=require("@strivacity/sdk-core/utils");Object.keys(i).forEach(function(e){e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:function(){return i[e]}})});var a=require("@strivacity/sdk-core/utils/errors");Object.keys(a).forEach(function(e){e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:function(){return a[e]}})});var o=require("@strivacity/sdk-core/storages");Object.keys(o).forEach(function(e){e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:function(){return o[e]}})});var s=require("@strivacity/sdk-core/types");Object.keys(s).forEach(function(e){e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:function(){return s[e]}})});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,31 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import { useStrivacity } from './composables';
|
|
11
|
-
export * from '@strivacity/sdk-core';
|
|
12
|
-
export { createCredential, getCredential } from '@strivacity/sdk-core/utils/credentials';
|
|
13
|
-
export type * from './types';
|
|
14
|
-
export type { PopupFlow, RedirectFlow, NativeFlow };
|
|
15
|
-
export { HttpClient, DefaultLogging, LocalStorage, SessionStorage, useStrivacity };
|
|
16
|
-
/**
|
|
17
|
-
* Checks if the user is authenticated.
|
|
18
|
-
*
|
|
19
|
-
* @returns {Promise<boolean>} A promise that resolves to `true` if the user is authenticated, otherwise `false`.
|
|
20
|
-
*/
|
|
21
|
-
export declare let isAuthenticated: () => Promise<boolean>;
|
|
22
|
-
/**
|
|
23
|
-
* Creates a Strivacity SDK plugin for Vue.
|
|
24
|
-
*
|
|
25
|
-
* @param {SDKOptions} options - The options used to configure the SDK.
|
|
26
|
-
*
|
|
27
|
-
* @returns {Plugin} A Vue plugin that can be installed in the application.
|
|
28
|
-
*/
|
|
29
|
-
export declare const createStrivacitySDK: (options: SDKOptions) => {
|
|
30
|
-
install: (app: App) => void;
|
|
31
|
-
};
|
|
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
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import{
|
|
2
|
-
//# sourceMappingURL=index.mjs.map
|
|
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
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,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,E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
|
|
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
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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: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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"}
|
|
@@ -0,0 +1 @@
|
|
|
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]}})});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@strivacity/sdk-core/storages';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"@strivacity/sdk-core/storages";
|
package/dist/types.cjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=types.cjs.map
|
|
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
CHANGED
|
@@ -1,183 +1,171 @@
|
|
|
1
1
|
import { Ref } from 'vue';
|
|
2
|
-
import { IdTokenClaims,
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
*/
|
|
9
|
-
export type Session = {
|
|
10
|
-
/**
|
|
11
|
-
* Reactive reference to the loading state of the session.
|
|
12
|
-
* `true` when the session is initializing, otherwise `false`.
|
|
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.
|
|
13
8
|
*/
|
|
14
|
-
|
|
9
|
+
readonly sdk: Flow;
|
|
15
10
|
/**
|
|
16
|
-
*
|
|
11
|
+
* A boolean indicating whether the SDK is still loading.
|
|
17
12
|
*/
|
|
18
|
-
|
|
13
|
+
readonly loading: Ref<boolean>;
|
|
19
14
|
/**
|
|
20
|
-
*
|
|
21
|
-
* `true` if the user is authenticated, otherwise `false`.
|
|
15
|
+
* BCP 47 language code representing the current language of the SDK.
|
|
22
16
|
*/
|
|
23
|
-
|
|
17
|
+
readonly language: Ref<string>;
|
|
24
18
|
/**
|
|
25
|
-
*
|
|
26
|
-
* Contains user identity and other information, or `null` if not authenticated.
|
|
19
|
+
* A boolean ref indicating whether the user is authenticated.
|
|
27
20
|
*/
|
|
28
|
-
|
|
21
|
+
readonly isAuthenticated: Ref<boolean>;
|
|
29
22
|
/**
|
|
30
|
-
*
|
|
31
|
-
* `null` if the user is not authenticated or the token is unavailable.
|
|
23
|
+
* The claims from the ID token, if available.
|
|
32
24
|
*/
|
|
33
|
-
|
|
25
|
+
readonly idTokenClaims: Ref<IdTokenClaims | null>;
|
|
34
26
|
/**
|
|
35
|
-
*
|
|
36
|
-
* `null` if the user is not authenticated or the refresh token is unavailable.
|
|
27
|
+
* The access token, if available.
|
|
37
28
|
*/
|
|
38
|
-
|
|
29
|
+
readonly accessToken: Ref<string | null>;
|
|
39
30
|
/**
|
|
40
|
-
*
|
|
41
|
-
* `true` if expired, otherwise `false`.
|
|
31
|
+
* The refresh token, if available.
|
|
42
32
|
*/
|
|
43
|
-
|
|
33
|
+
readonly refreshToken: Ref<string | null>;
|
|
44
34
|
/**
|
|
45
|
-
*
|
|
46
|
-
* `null` if no token is available or the session is not authenticated.
|
|
35
|
+
* A boolean ref indicating whether the access token has expired.
|
|
47
36
|
*/
|
|
48
|
-
|
|
49
|
-
};
|
|
50
|
-
/**
|
|
51
|
-
* Represents the available authentication flows and operations for Popup-based interactions.
|
|
52
|
-
*/
|
|
53
|
-
export type PopupSDK = {
|
|
37
|
+
readonly accessTokenExpired: Ref<boolean>;
|
|
54
38
|
/**
|
|
55
|
-
*
|
|
39
|
+
* The expiration date of the access token, if available.
|
|
56
40
|
*/
|
|
57
|
-
|
|
41
|
+
readonly accessTokenExpirationDate: Ref<number | null>;
|
|
58
42
|
/**
|
|
59
|
-
*
|
|
43
|
+
* Subscribes to a specific SDK event.
|
|
60
44
|
*/
|
|
61
|
-
|
|
45
|
+
subscribeToEvent: Flow['subscribeToEvent'];
|
|
62
46
|
/**
|
|
63
|
-
*
|
|
47
|
+
* Subscribes to all SDK events.
|
|
64
48
|
*/
|
|
65
|
-
|
|
49
|
+
subscribeToAllEvents: Flow['subscribeToAllEvents'];
|
|
66
50
|
/**
|
|
67
|
-
*
|
|
51
|
+
* Checks whether the user is currently authenticated, optionally triggering a token refresh.
|
|
68
52
|
*/
|
|
69
|
-
|
|
53
|
+
checkAuthentication: Flow['checkAuthentication'];
|
|
70
54
|
/**
|
|
71
|
-
*
|
|
55
|
+
* Initializes the SDK, loading metadata and restoring any persisted session.
|
|
72
56
|
*/
|
|
73
|
-
|
|
57
|
+
init: Flow['init'];
|
|
74
58
|
/**
|
|
75
|
-
*
|
|
59
|
+
* Performs a token exchange using the provided parameters.
|
|
76
60
|
*/
|
|
77
|
-
|
|
61
|
+
tokenExchange: Flow['tokenExchange'];
|
|
78
62
|
/**
|
|
79
|
-
*
|
|
63
|
+
* Handles the authentication callback by parsing the response from the given URL.
|
|
80
64
|
*/
|
|
81
|
-
|
|
65
|
+
handleCallback: Flow['handleCallback'];
|
|
82
66
|
/**
|
|
83
|
-
*
|
|
67
|
+
* Refreshes the current access token using the refresh token.
|
|
84
68
|
*/
|
|
85
|
-
|
|
86
|
-
};
|
|
87
|
-
/**
|
|
88
|
-
* Represents the available authentication flows and operations for Redirect-based interactions.
|
|
89
|
-
*/
|
|
90
|
-
export type RedirectSDK = {
|
|
69
|
+
refresh: Flow['refresh'];
|
|
91
70
|
/**
|
|
92
|
-
*
|
|
71
|
+
* Revokes the current tokens.
|
|
93
72
|
*/
|
|
94
|
-
|
|
73
|
+
revoke: Flow['revoke'];
|
|
95
74
|
/**
|
|
96
|
-
*
|
|
75
|
+
* Logs the user out and optionally redirects to a post-logout URI.
|
|
97
76
|
*/
|
|
98
|
-
|
|
77
|
+
logout: Flow['logout'];
|
|
99
78
|
/**
|
|
100
|
-
*
|
|
79
|
+
* Initiates the login flow.
|
|
101
80
|
*/
|
|
102
|
-
|
|
81
|
+
login: Flow['login'];
|
|
103
82
|
/**
|
|
104
|
-
* Initiates the
|
|
83
|
+
* Initiates the registration flow.
|
|
105
84
|
*/
|
|
106
|
-
|
|
85
|
+
register: Flow['register'];
|
|
107
86
|
/**
|
|
108
|
-
*
|
|
87
|
+
* Handles the entry point URL of the authentication flow, typically used for embedded or native modes.
|
|
109
88
|
*/
|
|
110
|
-
|
|
89
|
+
entry: Flow['entry'];
|
|
90
|
+
};
|
|
91
|
+
export type SDKInstance = ReturnType<typeof initFlow>;
|
|
92
|
+
export type LoginContext = {
|
|
111
93
|
/**
|
|
112
|
-
*
|
|
94
|
+
* Whether a form submission or session initialization is in progress.
|
|
113
95
|
*/
|
|
114
|
-
|
|
96
|
+
loading: Ref<boolean>;
|
|
115
97
|
/**
|
|
116
|
-
*
|
|
98
|
+
* Current form field values, keyed by form ID then widget ID.
|
|
117
99
|
*/
|
|
118
|
-
|
|
100
|
+
forms: Ref<Record<string, Record<string, unknown>>>;
|
|
119
101
|
/**
|
|
120
|
-
*
|
|
102
|
+
* Current validation and info messages, keyed by form ID then widget ID.
|
|
121
103
|
*/
|
|
122
|
-
|
|
123
|
-
};
|
|
124
|
-
/**
|
|
125
|
-
* Represents the available authentication flows and operations for Native-based interactions.
|
|
126
|
-
*/
|
|
127
|
-
export type NativeSDK = {
|
|
104
|
+
messages: Ref<Record<string, Record<string, NativeFlowMessage>>>;
|
|
128
105
|
/**
|
|
129
|
-
*
|
|
106
|
+
* The current login flow state returned by the backend.
|
|
130
107
|
*/
|
|
131
|
-
|
|
108
|
+
state: Ref<Partial<NativeFlowState>>;
|
|
132
109
|
/**
|
|
133
|
-
*
|
|
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.
|
|
134
115
|
*/
|
|
135
|
-
|
|
116
|
+
submitForm: (formId: string, customBody?: Record<string, unknown>) => Promise<void>;
|
|
136
117
|
/**
|
|
137
|
-
*
|
|
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.
|
|
138
122
|
*/
|
|
139
|
-
|
|
123
|
+
triggerFallback: (message?: string) => void;
|
|
140
124
|
/**
|
|
141
|
-
*
|
|
125
|
+
* Signals that the login flow was closed by the user.
|
|
142
126
|
*/
|
|
143
|
-
|
|
127
|
+
triggerClose: () => void;
|
|
144
128
|
/**
|
|
145
|
-
*
|
|
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.
|
|
146
134
|
*/
|
|
147
|
-
|
|
135
|
+
setFormValue: (formId: string, widgetId: string, value: unknown) => void;
|
|
148
136
|
/**
|
|
149
|
-
*
|
|
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.
|
|
150
142
|
*/
|
|
151
|
-
|
|
143
|
+
setMessage: (formId: string, widgetId: string, value: NativeFlowMessage) => void;
|
|
144
|
+
};
|
|
145
|
+
export type UseNativeLoginOptions = {
|
|
152
146
|
/**
|
|
153
|
-
*
|
|
147
|
+
* Optional parameters to be passed to the login session request. These parameters will be sent to the `authorizationUri` endpoint.
|
|
154
148
|
*/
|
|
155
|
-
|
|
149
|
+
params?: NativeParams;
|
|
156
150
|
/**
|
|
157
|
-
*
|
|
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`.
|
|
158
153
|
*/
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
messages: Ref<Record<string, Record<string, LoginFlowMessage>>>;
|
|
177
|
-
state: Ref<Partial<LoginFlowState>>;
|
|
178
|
-
submitForm: (formId: string) => Promise<void>;
|
|
179
|
-
triggerFallback: (hostedUrl?: string) => void;
|
|
180
|
-
triggerClose: () => void;
|
|
181
|
-
setFormValue: (formId: string, widgetId: string, value: unknown) => void;
|
|
182
|
-
setMessage: (formId: string, widgetId: string, value: LoginFlowMessage) => void;
|
|
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>;
|
|
183
171
|
};
|
package/dist/types.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=types.mjs.map
|
|
1
|
+
export*from"@strivacity/sdk-core/types";
|
package/dist/utils.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
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
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@strivacity/sdk-core/utils';
|
package/dist/utils.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"@strivacity/sdk-core/utils";
|