@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.
Files changed (61) hide show
  1. package/CHANGELOG.md +20 -18
  2. package/README.md +1402 -419
  3. package/dist/composables.cjs +2 -2
  4. package/dist/composables.cjs.map +1 -1
  5. package/dist/composables.d.ts +23 -8
  6. package/dist/composables.mjs +2 -2
  7. package/dist/composables.mjs.map +1 -1
  8. package/dist/errors.cjs +1 -0
  9. package/dist/errors.d.ts +1 -0
  10. package/dist/errors.mjs +1 -0
  11. package/dist/index.cjs +1 -2
  12. package/dist/index.d.ts +9 -31
  13. package/dist/index.mjs +1 -2
  14. package/dist/plugin.cjs +2 -0
  15. package/dist/plugin.cjs.map +1 -0
  16. package/dist/plugin.d.ts +8 -0
  17. package/dist/plugin.mjs +2 -0
  18. package/dist/plugin.mjs.map +1 -0
  19. package/dist/storages.cjs +1 -0
  20. package/dist/storages.d.ts +1 -0
  21. package/dist/storages.mjs +1 -0
  22. package/dist/types.cjs +1 -2
  23. package/dist/types.d.ts +106 -118
  24. package/dist/types.mjs +1 -2
  25. package/dist/utils.cjs +1 -0
  26. package/dist/utils.d.ts +1 -0
  27. package/dist/utils.mjs +1 -0
  28. package/eslint.config.mjs +3 -0
  29. package/package.json +45 -8
  30. package/project.json +46 -0
  31. package/src/composables.ts +219 -0
  32. package/src/env.d.ts +8 -0
  33. package/src/errors.ts +1 -0
  34. package/src/index.ts +9 -0
  35. package/src/plugin.ts +89 -0
  36. package/src/storages.ts +1 -0
  37. package/src/types.ts +220 -0
  38. package/src/utils.ts +1 -0
  39. package/testing/tests/composables.spec.ts +328 -0
  40. package/testing/tests/errors.spec.ts +10 -0
  41. package/testing/tests/index.spec.ts +105 -0
  42. package/testing/tests/plugin.spec.ts +129 -0
  43. package/testing/tests/storages.spec.ts +10 -0
  44. package/testing/tests/utils.spec.ts +10 -0
  45. package/testing/utils/common.ts +53 -0
  46. package/tsconfig.app.json +4 -0
  47. package/tsconfig.json +3 -0
  48. package/vite.config.mts +53 -0
  49. package/dist/assets/login-renderer.vue_vue_type_script_setup_true_lang.cjs +0 -2
  50. package/dist/assets/login-renderer.vue_vue_type_script_setup_true_lang.cjs.map +0 -1
  51. package/dist/assets/login-renderer.vue_vue_type_script_setup_true_lang.mjs +0 -2
  52. package/dist/assets/login-renderer.vue_vue_type_script_setup_true_lang.mjs.map +0 -1
  53. package/dist/index.cjs.map +0 -1
  54. package/dist/index.mjs.map +0 -1
  55. package/dist/login-renderer.cjs +0 -2
  56. package/dist/login-renderer.cjs.map +0 -1
  57. package/dist/login-renderer.mjs +0 -2
  58. package/dist/login-renderer.mjs.map +0 -1
  59. package/dist/login-renderer.vue.d.ts +0 -37
  60. package/dist/types.cjs.map +0 -1
  61. package/dist/types.mjs.map +0 -1
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("vue"),e=Symbol("sty"),i=()=>{const t=r.inject(e);if(!t)throw new Error("Missing Strivacity SDK context");return t};exports.STRIVACITY_SDK=e;exports.useStrivacity=i;
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
@@ -1 +1 @@
1
- {"version":3,"file":"composables.cjs","sources":["../src/composables.ts"],"sourcesContent":["import { inject } from 'vue';\nimport type { PopupContext, RedirectContext, NativeContext } from './types';\n\nconst STRIVACITY_SDK = Symbol('sty');\n\n/**\n * Retrieves the Strivacity SDK context for Popup or Redirect flows.\n *\n * @template T The type of context, either PopupContext, RedirectContext or NativeContext.\n *\n * @throws {Error} If the Strivacity SDK context is not found.\n *\n * @returns {T} The Strivacity SDK context, typed as either PopupContext, RedirectContext or NativeContext.\n */\nexport const useStrivacity = <T extends PopupContext | RedirectContext | NativeContext>() => {\n\tconst context = inject(STRIVACITY_SDK);\n\n\tif (!context) {\n\t\tthrow new Error('Missing Strivacity SDK context');\n\t}\n\n\treturn context as T;\n};\n\nexport { STRIVACITY_SDK };\n"],"names":["STRIVACITY_SDK","useStrivacity","context","inject"],"mappings":"uGAGMA,EAAiB,OAAO,KAAK,EAWtBC,EAAgB,IAAgE,CAC5F,MAAMC,EAAUC,EAAAA,OAAOH,CAAc,EAErC,GAAI,CAACE,EACJ,MAAM,IAAI,MAAM,gCAAgC,EAGjD,OAAOA,CACR"}
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,IAAA,CAA8B,CAAC,CAAC,GAE9C,EAAA,EAAA,UAAA,CAAU,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,GAED,EAAA,EAAA,YAAA,KAAkB,EAAgB,MAAM,CAAC,EAEzC,SAAS,EAAe,EAAqC,CAC5D,GAAI,EAAI,QAAS,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,IAAM,EAAY,MAAM,wBAAwB,EAEhD,MADA,EAAI,SAAS,MAAM,iBAAkB,CAAK,EACpC,CACP,CAEA,EAAa,aAAa,IAAI,EAAA,cAAc,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,IAAA,EAAc,EAAA,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,13 +1,28 @@
1
- import { PopupContext, RedirectContext, NativeContext } from './types';
2
- declare const STRIVACITY_SDK: unique symbol;
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
- * Retrieves the Strivacity SDK context for Popup or Redirect flows.
7
+ * A composable to access the Strivacity SDK context.
5
8
  *
6
- * @template T The type of context, either PopupContext, RedirectContext or NativeContext.
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
- * @throws {Error} If the Strivacity SDK context is not found.
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
- * @returns {T} The Strivacity SDK context, typed as either PopupContext, RedirectContext or NativeContext.
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 const useStrivacity: <T extends PopupContext | RedirectContext | NativeContext>() => T;
13
- export { STRIVACITY_SDK };
28
+ export declare function useNativeLogin(options?: UseNativeLoginOptions): ReturnType<typeof useNativeLoginContext>;
@@ -1,2 +1,2 @@
1
- import{inject as o}from"vue";const r=Symbol("sty"),n=()=>{const t=o(r);if(!t)throw new Error("Missing Strivacity SDK context");return t};export{r as STRIVACITY_SDK,n as useStrivacity};
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
@@ -1 +1 @@
1
- {"version":3,"file":"composables.mjs","sources":["../src/composables.ts"],"sourcesContent":["import { inject } from 'vue';\nimport type { PopupContext, RedirectContext, NativeContext } from './types';\n\nconst STRIVACITY_SDK = Symbol('sty');\n\n/**\n * Retrieves the Strivacity SDK context for Popup or Redirect flows.\n *\n * @template T The type of context, either PopupContext, RedirectContext or NativeContext.\n *\n * @throws {Error} If the Strivacity SDK context is not found.\n *\n * @returns {T} The Strivacity SDK context, typed as either PopupContext, RedirectContext or NativeContext.\n */\nexport const useStrivacity = <T extends PopupContext | RedirectContext | NativeContext>() => {\n\tconst context = inject(STRIVACITY_SDK);\n\n\tif (!context) {\n\t\tthrow new Error('Missing Strivacity SDK context');\n\t}\n\n\treturn context as T;\n};\n\nexport { STRIVACITY_SDK };\n"],"names":["STRIVACITY_SDK","useStrivacity","context","inject"],"mappings":"6BAGA,MAAMA,EAAiB,OAAO,KAAK,EAWtBC,EAAgB,IAAgE,CAC5F,MAAMC,EAAUC,EAAOH,CAAc,EAErC,GAAI,CAACE,EACJ,MAAM,IAAI,MAAM,gCAAgC,EAGjD,OAAOA,CACR"}
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,EAE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ACA,eACA,aACA,eACA,YACD,CAAC,EAEM,CACN,UACA,QACA,WACA,QACA,kBACA,eACA,aACA,eACA,YACD,CACD"}
@@ -0,0 +1 @@
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]}})});
@@ -0,0 +1 @@
1
+ export * from '@strivacity/sdk-core/utils/errors';
@@ -0,0 +1 @@
1
+ export*from"@strivacity/sdk-core/utils/errors";
package/dist/index.cjs CHANGED
@@ -1,2 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("vue"),o=require("@strivacity/sdk-core"),y=require("@strivacity/sdk-core/utils/HttpClient"),T=require("@strivacity/sdk-core/utils/Logging"),k=require("@strivacity/sdk-core/storages/LocalStorage"),S=require("@strivacity/sdk-core/storages/SessionStorage"),b=require("./composables.cjs"),h=require("./assets/login-renderer.vue_vue_type_script_setup_true_lang.cjs"),v=require("@strivacity/sdk-core/utils/credentials");require("@strivacity/sdk-core/utils/object");exports.isAuthenticated=()=>Promise.resolve(!1);const m=i=>{const e=o.initFlow(i);return{install:s=>{const a=r.ref(!0),p=r.ref(e.options),c=r.ref(!1),l=r.ref(null),u=r.ref(null),d=r.ref(null),g=r.ref(!0),f=r.ref(null),t=async()=>{c.value=await e.isAuthenticated,l.value=e.idTokenClaims||null,u.value=e.accessToken||null,d.value=e.refreshToken||null,g.value=e.accessTokenExpired,f.value=e.accessTokenExpirationDate||null,a.value&&(a.value=!1)};exports.isAuthenticated=()=>e.isAuthenticated,e.subscribeToEvent("init",t),e.subscribeToEvent("loggedIn",t),e.subscribeToEvent("sessionLoaded",t),e.subscribeToEvent("tokenRefreshed",t),e.subscribeToEvent("tokenRefreshFailed",t),e.subscribeToEvent("logoutInitiated",t),e.subscribeToEvent("tokenRevoked",t),e.subscribeToEvent("tokenRevokeFailed",t),s.component("StyLoginRenderer",h._sfc_main),s.provide(b.STRIVACITY_SDK,{sdk:e,loading:a,options:p,isAuthenticated:c,idTokenClaims:l,accessToken:u,refreshToken:d,accessTokenExpired:g,accessTokenExpirationDate:f,login:async n=>{if(e.options.mode==="native")return e.login(n);await e.login(n),await t()},register:async n=>{if(e.options.mode==="native")return e.register(n);await e.register(n),await t()},entry:async n=>await e.entry(n),refresh:async()=>{await e.refresh(),await t()},revoke:async()=>{await e.revoke(),await t()},logout:async n=>{await e.logout(n),await t()},handleCallback:async n=>{await e.handleCallback(n),await t()}})}}};Object.defineProperty(exports,"HttpClient",{enumerable:!0,get:()=>y.HttpClient});Object.defineProperty(exports,"DefaultLogging",{enumerable:!0,get:()=>T.DefaultLogging});Object.defineProperty(exports,"LocalStorage",{enumerable:!0,get:()=>k.LocalStorage});Object.defineProperty(exports,"SessionStorage",{enumerable:!0,get:()=>S.SessionStorage});exports.useStrivacity=b.useStrivacity;Object.defineProperty(exports,"createCredential",{enumerable:!0,get:()=>v.createCredential});Object.defineProperty(exports,"getCredential",{enumerable:!0,get:()=>v.getCredential});exports.createStrivacitySDK=m;Object.keys(o).forEach(i=>{i!=="default"&&!Object.prototype.hasOwnProperty.call(exports,i)&&Object.defineProperty(exports,i,{enumerable:!0,get:()=>o[i]})});
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
- import { SDKOptions } from '@strivacity/sdk-core';
2
- import { PopupFlow } from '@strivacity/sdk-core/flows/PopupFlow';
3
- import { RedirectFlow } from '@strivacity/sdk-core/flows/RedirectFlow';
4
- import { NativeFlow } from '@strivacity/sdk-core/flows/NativeFlow';
5
- import { App } from 'vue';
6
- import { HttpClient } from '@strivacity/sdk-core/utils/HttpClient';
7
- import { DefaultLogging } from '@strivacity/sdk-core/utils/Logging';
8
- import { LocalStorage } from '@strivacity/sdk-core/storages/LocalStorage';
9
- import { SessionStorage } from '@strivacity/sdk-core/storages/SessionStorage';
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{ref as n}from"vue";import{initFlow as p}from"@strivacity/sdk-core";export*from"@strivacity/sdk-core";import{HttpClient as A}from"@strivacity/sdk-core/utils/HttpClient";import{DefaultLogging as I}from"@strivacity/sdk-core/utils/Logging";import{LocalStorage as _}from"@strivacity/sdk-core/storages/LocalStorage";import{SessionStorage as K}from"@strivacity/sdk-core/storages/SessionStorage";import{STRIVACITY_SDK as v}from"./composables.mjs";import{useStrivacity as P}from"./composables.mjs";import{_ as T}from"./assets/login-renderer.vue_vue_type_script_setup_true_lang.mjs";import{createCredential as Y,getCredential as j}from"@strivacity/sdk-core/utils/credentials";import"@strivacity/sdk-core/utils/object";let m=()=>Promise.resolve(!1);const R=d=>{const e=p(d);return{install:i=>{const a=n(!0),k=n(e.options),s=n(!1),r=n(null),c=n(null),l=n(null),u=n(!0),f=n(null),t=async()=>{s.value=await e.isAuthenticated,r.value=e.idTokenClaims||null,c.value=e.accessToken||null,l.value=e.refreshToken||null,u.value=e.accessTokenExpired,f.value=e.accessTokenExpirationDate||null,a.value&&(a.value=!1)};m=()=>e.isAuthenticated,e.subscribeToEvent("init",t),e.subscribeToEvent("loggedIn",t),e.subscribeToEvent("sessionLoaded",t),e.subscribeToEvent("tokenRefreshed",t),e.subscribeToEvent("tokenRefreshFailed",t),e.subscribeToEvent("logoutInitiated",t),e.subscribeToEvent("tokenRevoked",t),e.subscribeToEvent("tokenRevokeFailed",t),i.component("StyLoginRenderer",T),i.provide(v,{sdk:e,loading:a,options:k,isAuthenticated:s,idTokenClaims:r,accessToken:c,refreshToken:l,accessTokenExpired:u,accessTokenExpirationDate:f,login:async o=>{if(e.options.mode==="native")return e.login(o);await e.login(o),await t()},register:async o=>{if(e.options.mode==="native")return e.register(o);await e.register(o),await t()},entry:async o=>await e.entry(o),refresh:async()=>{await e.refresh(),await t()},revoke:async()=>{await e.revoke(),await t()},logout:async o=>{await e.logout(o),await t()},handleCallback:async o=>{await e.handleCallback(o),await t()}})}}};export{I as DefaultLogging,A as HttpClient,_ as LocalStorage,K as SessionStorage,Y as createCredential,R as createStrivacitySDK,j as getCredential,m as isAuthenticated,P as useStrivacity};
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};
@@ -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,IAA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AAI,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,8 @@
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;
@@ -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: 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"}
@@ -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
- "use strict";
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, LoginFlowMessage, LoginFlowState, SDKOptions } from '@strivacity/sdk-core';
3
- import { PopupFlow } from '@strivacity/sdk-core/flows/PopupFlow';
4
- import { RedirectFlow } from '@strivacity/sdk-core/flows/RedirectFlow';
5
- import { NativeFlow } from '@strivacity/sdk-core/flows/NativeFlow';
6
- /**
7
- * Represents the session state, including authentication details and token information.
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
- loading: Ref<boolean>;
9
+ readonly sdk: Flow;
15
10
  /**
16
- * The SDK options used to configure the session.
11
+ * A boolean indicating whether the SDK is still loading.
17
12
  */
18
- options: Ref<SDKOptions>;
13
+ readonly loading: Ref<boolean>;
19
14
  /**
20
- * Reactive reference to the user's authentication status.
21
- * `true` if the user is authenticated, otherwise `false`.
15
+ * BCP 47 language code representing the current language of the SDK.
22
16
  */
23
- isAuthenticated: Ref<boolean>;
17
+ readonly language: Ref<string>;
24
18
  /**
25
- * Reactive reference to the claims contained in the ID token.
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
- idTokenClaims: Ref<IdTokenClaims | null>;
21
+ readonly isAuthenticated: Ref<boolean>;
29
22
  /**
30
- * Reactive reference to the current access token for API authorization.
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
- accessToken: Ref<string | null>;
25
+ readonly idTokenClaims: Ref<IdTokenClaims | null>;
34
26
  /**
35
- * Reactive reference to the refresh token, used to refresh the access token.
36
- * `null` if the user is not authenticated or the refresh token is unavailable.
27
+ * The access token, if available.
37
28
  */
38
- refreshToken: Ref<string | null>;
29
+ readonly accessToken: Ref<string | null>;
39
30
  /**
40
- * Reactive reference indicating if the access token has expired.
41
- * `true` if expired, otherwise `false`.
31
+ * The refresh token, if available.
42
32
  */
43
- accessTokenExpired: Ref<boolean>;
33
+ readonly refreshToken: Ref<string | null>;
44
34
  /**
45
- * Reactive reference to the expiration date of the access token in Unix time (milliseconds).
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
- accessTokenExpirationDate: Ref<number | null>;
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
- * Represents the SDK instance.
39
+ * The expiration date of the access token, if available.
56
40
  */
57
- sdk: InstanceType<typeof PopupFlow>;
41
+ readonly accessTokenExpirationDate: Ref<number | null>;
58
42
  /**
59
- * Initiates the login process.
43
+ * Subscribes to a specific SDK event.
60
44
  */
61
- login: InstanceType<typeof PopupFlow>['login'];
45
+ subscribeToEvent: Flow['subscribeToEvent'];
62
46
  /**
63
- * Registers a new user.
47
+ * Subscribes to all SDK events.
64
48
  */
65
- register: InstanceType<typeof PopupFlow>['register'];
49
+ subscribeToAllEvents: Flow['subscribeToAllEvents'];
66
50
  /**
67
- * Initiates the entry process.
51
+ * Checks whether the user is currently authenticated, optionally triggering a token refresh.
68
52
  */
69
- entry: InstanceType<typeof PopupFlow>['entry'];
53
+ checkAuthentication: Flow['checkAuthentication'];
70
54
  /**
71
- * Refreshes the user's session.
55
+ * Initializes the SDK, loading metadata and restoring any persisted session.
72
56
  */
73
- refresh: InstanceType<typeof PopupFlow>['refresh'];
57
+ init: Flow['init'];
74
58
  /**
75
- * Revokes the current session tokens.
59
+ * Performs a token exchange using the provided parameters.
76
60
  */
77
- revoke: InstanceType<typeof PopupFlow>['revoke'];
61
+ tokenExchange: Flow['tokenExchange'];
78
62
  /**
79
- * Logs out the user.
63
+ * Handles the authentication callback by parsing the response from the given URL.
80
64
  */
81
- logout: InstanceType<typeof PopupFlow>['logout'];
65
+ handleCallback: Flow['handleCallback'];
82
66
  /**
83
- * Handles the callback after authentication or token exchange.
67
+ * Refreshes the current access token using the refresh token.
84
68
  */
85
- handleCallback: InstanceType<typeof PopupFlow>['handleCallback'];
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
- * Represents the SDK instance.
71
+ * Revokes the current tokens.
93
72
  */
94
- sdk: InstanceType<typeof RedirectFlow>;
73
+ revoke: Flow['revoke'];
95
74
  /**
96
- * Initiates the login process.
75
+ * Logs the user out and optionally redirects to a post-logout URI.
97
76
  */
98
- login: InstanceType<typeof RedirectFlow>['login'];
77
+ logout: Flow['logout'];
99
78
  /**
100
- * Registers a new user.
79
+ * Initiates the login flow.
101
80
  */
102
- register: InstanceType<typeof RedirectFlow>['register'];
81
+ login: Flow['login'];
103
82
  /**
104
- * Initiates the entry process.
83
+ * Initiates the registration flow.
105
84
  */
106
- entry: InstanceType<typeof RedirectFlow>['entry'];
85
+ register: Flow['register'];
107
86
  /**
108
- * Refreshes the user's session.
87
+ * Handles the entry point URL of the authentication flow, typically used for embedded or native modes.
109
88
  */
110
- refresh: InstanceType<typeof RedirectFlow>['refresh'];
89
+ entry: Flow['entry'];
90
+ };
91
+ export type SDKInstance = ReturnType<typeof initFlow>;
92
+ export type LoginContext = {
111
93
  /**
112
- * Revokes the current session tokens.
94
+ * Whether a form submission or session initialization is in progress.
113
95
  */
114
- revoke: InstanceType<typeof RedirectFlow>['revoke'];
96
+ loading: Ref<boolean>;
115
97
  /**
116
- * Logs out the user.
98
+ * Current form field values, keyed by form ID then widget ID.
117
99
  */
118
- logout: InstanceType<typeof RedirectFlow>['logout'];
100
+ forms: Ref<Record<string, Record<string, unknown>>>;
119
101
  /**
120
- * Handles the callback after authentication or token exchange.
102
+ * Current validation and info messages, keyed by form ID then widget ID.
121
103
  */
122
- handleCallback: InstanceType<typeof RedirectFlow>['handleCallback'];
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
- * Represents the SDK instance.
106
+ * The current login flow state returned by the backend.
130
107
  */
131
- sdk: InstanceType<typeof NativeFlow>;
108
+ state: Ref<Partial<NativeFlowState>>;
132
109
  /**
133
- * Initiates the login process.
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
- login: InstanceType<typeof NativeFlow>['login'];
116
+ submitForm: (formId: string, customBody?: Record<string, unknown>) => Promise<void>;
136
117
  /**
137
- * Registers a new user.
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
- register: InstanceType<typeof NativeFlow>['register'];
123
+ triggerFallback: (message?: string) => void;
140
124
  /**
141
- * Initiates the entry process.
125
+ * Signals that the login flow was closed by the user.
142
126
  */
143
- entry: InstanceType<typeof NativeFlow>['entry'];
127
+ triggerClose: () => void;
144
128
  /**
145
- * Refreshes the user's session.
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
- refresh: InstanceType<typeof NativeFlow>['refresh'];
135
+ setFormValue: (formId: string, widgetId: string, value: unknown) => void;
148
136
  /**
149
- * Revokes the current session tokens.
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
- revoke: InstanceType<typeof NativeFlow>['revoke'];
143
+ setMessage: (formId: string, widgetId: string, value: NativeFlowMessage) => void;
144
+ };
145
+ export type UseNativeLoginOptions = {
152
146
  /**
153
- * Logs out the user.
147
+ * Optional parameters to be passed to the login session request. These parameters will be sent to the `authorizationUri` endpoint.
154
148
  */
155
- logout: InstanceType<typeof NativeFlow>['logout'];
149
+ params?: NativeParams;
156
150
  /**
157
- * Handles the callback after authentication or token exchange.
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
- handleCallback: InstanceType<typeof NativeFlow>['handleCallback'];
160
- };
161
- /**
162
- * Represents a combined context for Popup-based flows, containing both the Popup SDK and the session state.
163
- */
164
- export type PopupContext = PopupSDK & Session;
165
- /**
166
- * Represents a combined context for Redirect-based flows, containing both the Redirect SDK and the session state.
167
- */
168
- export type RedirectContext = RedirectSDK & Session;
169
- /**
170
- * Represents a combined context for Redirect-based flows, containing both the Redirect SDK and the session state.
171
- */
172
- export type NativeContext = NativeSDK & Session;
173
- export type NativeFlowContextValue = {
174
- loading: Ref<boolean>;
175
- forms: Ref<Record<string, Record<string, unknown>>>;
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]}})});
@@ -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";
@@ -0,0 +1,3 @@
1
+ import { defineVueConfig, vitestConfig } from '../../eslint.config.base.mjs';
2
+
3
+ export default defineVueConfig(vitestConfig);