@strivacity/sdk-vue 3.0.1 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +59 -1
- package/dist/assets/login-renderer.vue_vue_type_script_setup_true_lang.cjs +1 -1
- package/dist/assets/login-renderer.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/assets/login-renderer.vue_vue_type_script_setup_true_lang.mjs +1 -1
- package/dist/assets/login-renderer.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/login-renderer.vue.d.ts +4 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
## 3.0.2 (2026-05-12)
|
|
2
|
+
|
|
3
|
+
### 🩹 Fixes
|
|
4
|
+
|
|
5
|
+
- language parameter added to the login renderer component ([c8f18d9](https://github.com/Strivacity/sdk-js/commit/c8f18d9))
|
|
6
|
+
|
|
7
|
+
### 🧱 Updated Dependencies
|
|
8
|
+
|
|
9
|
+
- Updated sdk-core to 3.0.2
|
|
10
|
+
|
|
1
11
|
## 3.0.1 (2026-04-20)
|
|
2
12
|
|
|
3
13
|
### 🩹 Fixes
|
package/README.md
CHANGED
|
@@ -245,7 +245,7 @@ export const widgets = {
|
|
|
245
245
|
|
|
246
246
|
#### Login page example
|
|
247
247
|
|
|
248
|
-
The login page extracts `session_id`, `short_app_id`, and optionally `language` from the URL on load, cleans up the URL, and passes them to the renderer. When a `session_id` is present the renderer calls `startSession(sessionId)` to resume the existing flow instead of starting a new one. When a `language` parameter is present it
|
|
248
|
+
The login page extracts `session_id`, `short_app_id`, and optionally `language` from the URL on load, cleans up the URL, and passes them to the renderer. When a `session_id` is present the renderer calls `startSession(sessionId)` to resume the existing flow instead of starting a new one. When a `language` parameter is present it is passed to the renderer which uses it for the authentication UI and emits the resolved language back via `v-model:language`.
|
|
249
249
|
|
|
250
250
|
```vue
|
|
251
251
|
<script setup lang="ts">
|
|
@@ -256,10 +256,16 @@ import { widgets } from './components/widgets';
|
|
|
256
256
|
|
|
257
257
|
const router = useRouter();
|
|
258
258
|
const sessionId = ref<string | null>(null);
|
|
259
|
+
const language = ref<string | null>(null);
|
|
259
260
|
|
|
260
261
|
if (window.location.search !== '') {
|
|
261
262
|
const url = new URL(window.location.href);
|
|
262
263
|
sessionId.value = url.searchParams.get('session_id');
|
|
264
|
+
|
|
265
|
+
if (url.searchParams.has('language')) {
|
|
266
|
+
language.value = url.searchParams.get('language');
|
|
267
|
+
}
|
|
268
|
+
|
|
263
269
|
url.search = '';
|
|
264
270
|
history.replaceState({}, '', url.toString());
|
|
265
271
|
}
|
|
@@ -292,6 +298,7 @@ const onBlockReady = ({ previousState, state }: { previousState: LoginFlowState;
|
|
|
292
298
|
|
|
293
299
|
<template>
|
|
294
300
|
<StyLoginRenderer
|
|
301
|
+
v-model:language="language"
|
|
295
302
|
:widgets="widgets"
|
|
296
303
|
:session-id="sessionId"
|
|
297
304
|
@fallback="onFallback"
|
|
@@ -529,6 +536,55 @@ const sdk = createStrivacitySDK({
|
|
|
529
536
|
|
|
530
537
|
The `SDKLogging` interface requires `debug`, `info`, `warn`, and `error` methods. The optional `xEventId` property, when set by the SDK, provides a correlation ID to trace related log messages across the authentication flow.
|
|
531
538
|
|
|
539
|
+
## HTTP Client
|
|
540
|
+
|
|
541
|
+
The SDK uses a built-in `fetch`-based HTTP client for all requests. You can replace it with your own implementation by extending `SDKHttpClient` and passing your class via the `httpClient` option. This is useful when you need to attach custom headers (e.g. `x-sty-app-id`) to every outgoing request or route traffic through a proxy.
|
|
542
|
+
|
|
543
|
+
### Adding custom headers to every request
|
|
544
|
+
|
|
545
|
+
```typescript
|
|
546
|
+
import { createStrivacitySDK, SDKHttpClient, type HttpClientResponse } from '@strivacity/sdk-vue';
|
|
547
|
+
|
|
548
|
+
class CustomHttpClient extends SDKHttpClient {
|
|
549
|
+
async request<T>(url: string, options?: RequestInit): Promise<HttpClientResponse<T>> {
|
|
550
|
+
const mergedOptions: RequestInit = {
|
|
551
|
+
...options,
|
|
552
|
+
headers: {
|
|
553
|
+
'x-sty-app-id': 'my-app',
|
|
554
|
+
...(options?.headers as Record<string, string>),
|
|
555
|
+
},
|
|
556
|
+
};
|
|
557
|
+
|
|
558
|
+
const response = await fetch(url, mergedOptions);
|
|
559
|
+
|
|
560
|
+
return {
|
|
561
|
+
headers: response.headers,
|
|
562
|
+
ok: response.ok,
|
|
563
|
+
status: response.status,
|
|
564
|
+
statusText: response.statusText,
|
|
565
|
+
url: response.url,
|
|
566
|
+
json: async () => (await response.json()) as T,
|
|
567
|
+
text: async () => await response.text(),
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
const sdk = createStrivacitySDK({
|
|
573
|
+
// ...other options
|
|
574
|
+
httpClient: CustomHttpClient,
|
|
575
|
+
});
|
|
576
|
+
```
|
|
577
|
+
|
|
578
|
+
Any header you add inside `request()` is automatically included in every SDK request
|
|
579
|
+
|
|
580
|
+
### CORS configuration
|
|
581
|
+
|
|
582
|
+
For custom request headers to reach the Strivacity cluster, the cluster must be configured to explicitly allow them. Add the header name(s) to the **Access-Control-Allow-Headers** list in the cluster settings. Without this, browsers will block the preflight `OPTIONS` request and the SDK call will fail with a CORS error.
|
|
583
|
+
|
|
584
|
+
```
|
|
585
|
+
Access-Control-Allow-Headers: x-sty-app-id, <any other custom headers>
|
|
586
|
+
```
|
|
587
|
+
|
|
532
588
|
## API Documentation
|
|
533
589
|
|
|
534
590
|
### `useStrivacity` composable
|
|
@@ -598,6 +654,7 @@ Used in `native` mode to render the authentication UI with your own widget compo
|
|
|
598
654
|
- **`params?: NativeParams`**: Additional parameters for the native login flow.
|
|
599
655
|
- **`widgets?: PartialRecord<WidgetType, Vue.Component>`**: Custom Vue components for each widget type used in the flow.
|
|
600
656
|
- **`sessionId?: string | null`**: Session ID for resuming an existing authentication session. Typically extracted from URL parameters when returning from an external identity provider.
|
|
657
|
+
- **`language?: string | null`**: Language tag (e.g. `"en-US"`) for the authentication UI. Defaults to `navigator.language`. Supports two-way binding via `v-model:language` — after the session starts the component emits the resolved language back to the parent. See the [Translations](https://docs.strivacity.com/docs/translations) page to learn about language precedence implemented by the product.
|
|
601
658
|
|
|
602
659
|
**Events**
|
|
603
660
|
|
|
@@ -606,6 +663,7 @@ Used in `native` mode to render the authentication UI with your own widget compo
|
|
|
606
663
|
- **`@error`**: Emitted when an error occurs during authentication.
|
|
607
664
|
- **`@global-message`**: Emitted when the flow wants to display a global message (e.g. account lockout warning).
|
|
608
665
|
- **`@block-ready`**: Emitted on flow state transitions. Receives `{ previousState: LoginFlowState; state: LoginFlowState }`. Useful for analytics and custom logging.
|
|
666
|
+
- **`@update:language`**: Emitted after the session starts with the resolved language string. Used automatically by `v-model:language`.
|
|
609
667
|
|
|
610
668
|
## Vulnerability Reporting
|
|
611
669
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const o=require("vue"),
|
|
1
|
+
"use strict";const o=require("vue"),y=require("@strivacity/sdk-core"),N=require("@strivacity/sdk-core/utils/object"),S=require("../composables.cjs"),I={class:"login-renderer"},O=o.defineComponent({__name:"login-renderer",props:{params:{default:()=>({})},widgets:{default:()=>({})},language:{default:navigator.language},sessionId:{default:null}},emits:["login","fallback","close","error","globalMessage","blockReady","update:language"],setup(d,{emit:k}){const{sdk:u}=S.useStrivacity(),g=d,r=k,w=o.defineComponent({props:{items:{type:Array,default:()=>[]},widgets:{type:Object,default:()=>({})}},setup:e=>()=>e.items.map(t=>{if(t.type==="widget"){const n=a.value?.forms?.find(v=>v.id===t.formId),l=n?.widgets.find(v=>v.id===t.widgetId);if(!n||!l)return c(void 0,`Unable to find form or widget for item: formId=${t.formId}, widgetId=${t.widgetId}`),null;const b=e.widgets[l.type];return b?o.h(b,{key:`${n.id}.${l.id}`,formId:n.id,config:l}):(c(void 0,`No component found for widget type ${l.type}`),null)}else return t.type==="vertical"||t.type==="horizontal"?e.widgets.layout?o.h(e.widgets.layout,{formId:t.items[0].formId,type:t.type},()=>o.h(w,{items:t.items,widgets:e.widgets})):(c(void 0,"No layout component provided"),null):(c(void 0,"Unknown item type in layout"),null)})}),f=u.login(g.params),m=o.ref(!1),s=o.ref({}),i=o.ref({}),a=o.ref({});o.provide("nativeFlowContext",{loading:m,forms:s,messages:i,state:a,submitForm:F,triggerFallback:c,triggerClose:h,setFormValue:U,setMessage:C}),o.onMounted(async()=>{try{const e=await f.startSession(g.sessionId,g.language);r("update:language",f.language),e&&await p(e)}catch(e){e instanceof y.FallbackError?r("fallback",e):r("error",e)}});function c(e,t){const n=e||a.value.hostedUrl;if(u.logging?.warn(t?`Triggering fallback due to: ${t}`:"Triggering fallback"),!n){const l=new Error("No hosted URL provided");throw u.logging?.error("Fallback error",l),l}r("fallback",new y.FallbackError(new URL(n)))}function h(){r("close")}function U(e,t,n){n===""&&(n=null),s.value[e]===void 0&&(s.value[e]={}),s.value[e][t]=n}function C(e,t,n){i.value[e]===void 0&&(i.value[e]={}),i.value[e][t]=n}async function F(e){try{m.value=!0;const t=await f.submitForm(e,N.unflattenObject(s.value[e]));await p(t),m.value=!1}catch(t){t instanceof y.FallbackError?r("fallback",t):r("error",t)}}async function p(e){if(await u.isAuthenticated)r("login",u.idTokenClaims);else{const t=JSON.parse(JSON.stringify(a.value)),n={hostedUrl:e?.hostedUrl??a.value.hostedUrl,finalizeUrl:e?.finalizeUrl??a.value.finalizeUrl,screen:e?.screen??a.value.screen,forms:e?.forms??a.value.forms,layout:e?.layout??a.value.layout,messages:e?.messages??{},branding:e?.branding??a.value.branding};if(n.screen!=a.value.screen){s.value={},i.value={};for(const l of n.forms??[])s.value[l.id]={},i.value[l.id]={}}else u.logging?.info(`Updating screen: ${n.screen}`);Object.keys(n.messages??{}).forEach(l=>{l==="global"?r("globalMessage",n.messages?.global?.text??""):i.value[l]=n.messages[l]}),a.value=n,setTimeout(()=>{r("blockReady",{previousState:t,state:JSON.parse(JSON.stringify(a.value))})})}}return(e,t)=>(o.openBlock(),o.createElementBlock("div",I,[a.value.screen?(o.openBlock(),o.createBlock(o.resolveDynamicComponent(d.widgets.layout),{key:0,formId:(a.value.layout?.items[0]).formId,type:a.value.layout?.type,tag:"form"},{default:o.withCtx(()=>[o.createVNode(o.unref(w),{items:a.value.layout?.items,widgets:d.widgets},null,8,["items","widgets"])]),_:1},8,["formId","type"])):(o.openBlock(),o.createBlock(o.resolveDynamicComponent(d.widgets.loading),{key:1}))]))}});exports._sfc_main=O;
|
|
2
2
|
//# sourceMappingURL=login-renderer.vue_vue_type_script_setup_true_lang.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login-renderer.vue_vue_type_script_setup_true_lang.cjs","sources":["../../src/login-renderer.vue"],"sourcesContent":["<!-- eslint-disable no-console -->\n<script lang=\"ts\" setup>\nimport type { VNode, Component, PropType } from 'vue';\nimport type { PartialRecord, NativeParams, WidgetType, LayoutWidget, LoginFlowState, Widget, IdTokenClaims, LoginFlowMessage } from '@strivacity/sdk-core';\nimport type { NativeContext, NativeFlowContextValue } from './types';\nimport { defineComponent, provide, ref, h, onMounted } from 'vue';\nimport { FallbackError } from '@strivacity/sdk-core';\nimport { unflattenObject } from '@strivacity/sdk-core/utils/object';\nimport { useStrivacity } from './composables';\n\nconst { sdk } = useStrivacity<NativeContext>();\n\nconst props = withDefaults(\n\tdefineProps<{\n\t\tparams?: NativeParams;\n\t\twidgets?: PartialRecord<WidgetType, Component>;\n\t\tsessionId?: string | null;\n\t}>(),\n\t{\n\t\tparams: () => ({}),\n\t\twidgets: () => ({}),\n\t\tsessionId: null,\n\t},\n);\nconst emit = defineEmits<{\n\tlogin: [IdTokenClaims | null | undefined];\n\tfallback: [FallbackError];\n\tclose: [];\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\terror: [any];\n\tglobalMessage: [string];\n\tblockReady: [{ previousState: LoginFlowState; state: LoginFlowState }];\n}>();\n\nconst WidgetRenderer = defineComponent({\n\tprops: {\n\t\titems: {\n\t\t\ttype: Array as PropType<LayoutWidget['items']>,\n\t\t\tdefault: () => [],\n\t\t},\n\t\twidgets: {\n\t\t\ttype: Object as PropType<PartialRecord<WidgetType, Component>>,\n\t\t\tdefault: () => ({}),\n\t\t},\n\t},\n\tsetup: (props) => () =>\n\t\tprops.items.map((item): VNode | null => {\n\t\t\tif (item.type === 'widget') {\n\t\t\t\tconst form = state.value?.forms?.find((form) => form.id === item.formId);\n\t\t\t\tconst widget = form?.widgets.find((widget) => widget.id === item.widgetId);\n\n\t\t\t\tif (!form || !widget) {\n\t\t\t\t\ttriggerFallback(undefined, `Unable to find form or widget for item: formId=${item.formId}, widgetId=${item.widgetId}`);\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\tconst component = props.widgets[widget.type];\n\n\t\t\t\tif (!component) {\n\t\t\t\t\ttriggerFallback(undefined, `No component found for widget type ${widget.type}`);\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\treturn h(component, { key: `${form.id}.${widget.id}`, formId: form.id, config: widget });\n\t\t\t} else if (item.type === 'vertical' || item.type === 'horizontal') {\n\t\t\t\tif (!props.widgets.layout) {\n\t\t\t\t\ttriggerFallback(undefined, 'No layout component provided');\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\treturn h(props.widgets.layout, { formId: (item.items[0] as Widget).formId, type: item.type }, () =>\n\t\t\t\t\th(WidgetRenderer, { items: item.items, widgets: props.widgets }),\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\ttriggerFallback(undefined, 'Unknown item type in layout');\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}),\n});\n\nconst loginHandler = sdk.login(props.params);\nconst loading = ref<boolean>(false);\nconst forms = ref<Record<string, Record<string, unknown>>>({});\nconst messages = ref<Record<string, Record<string, LoginFlowMessage>>>({});\nconst state = ref<LoginFlowState>({});\n\nprovide<NativeFlowContextValue>('nativeFlowContext', {\n\tloading,\n\tforms,\n\tmessages,\n\tstate,\n\tsubmitForm,\n\ttriggerFallback,\n\ttriggerClose,\n\tsetFormValue,\n\tsetMessage,\n});\n\nonMounted(async () => {\n\ttry {\n\t\tconst data = await loginHandler.startSession(props.sessionId);\n\n\t\tif (data) {\n\t\t\tawait handleResponse(data);\n\t\t}\n\t} catch (error) {\n\t\tif (error instanceof FallbackError) {\n\t\t\temit('fallback', error);\n\t\t} else {\n\t\t\temit('error', error);\n\t\t}\n\t}\n});\n\nfunction triggerFallback(hostedUrl?: string, message?: string): void {\n\tconst url = hostedUrl || state.value.hostedUrl;\n\n\tsdk.logging?.warn(message ? `Triggering fallback due to: ${message}` : 'Triggering fallback');\n\n\tif (!url) {\n\t\tconst error = new Error('No hosted URL provided');\n\t\tsdk.logging?.error('Fallback error', error);\n\t\tthrow error;\n\t}\n\n\temit('fallback', new FallbackError(new URL(url)));\n}\n\nfunction triggerClose(): void {\n\temit('close');\n}\n\nfunction setFormValue(formId: string, widgetId: string, value: unknown) {\n\tif (value === '') {\n\t\tvalue = null;\n\t}\n\n\tif (forms.value[formId] === undefined) {\n\t\tforms.value[formId] = {};\n\t}\n\n\tforms.value[formId][widgetId] = value;\n}\n\nfunction setMessage(formId: string, widgetId: string, value: LoginFlowMessage) {\n\tif (messages.value[formId] === undefined) {\n\t\tmessages.value[formId] = {};\n\t}\n\n\tmessages.value[formId][widgetId] = value;\n}\n\nasync function submitForm(formId: string): Promise<void> {\n\ttry {\n\t\tloading.value = true;\n\n\t\tconst data = await loginHandler.submitForm(formId, unflattenObject(forms.value[formId]));\n\t\tawait handleResponse(data);\n\n\t\tloading.value = false;\n\t} catch (error) {\n\t\tif (error instanceof FallbackError) {\n\t\t\temit('fallback', error);\n\t\t} else {\n\t\t\temit('error', error);\n\t\t}\n\t}\n}\n\nasync function handleResponse(data?: LoginFlowState) {\n\tif (await sdk.isAuthenticated) {\n\t\temit('login', sdk.idTokenClaims);\n\t} else {\n\t\tconst previousState = JSON.parse(JSON.stringify(state.value));\n\t\tconst newState: LoginFlowState = {\n\t\t\thostedUrl: data?.hostedUrl ?? state.value.hostedUrl,\n\t\t\tfinalizeUrl: data?.finalizeUrl ?? state.value.finalizeUrl,\n\t\t\tscreen: data?.screen ?? state.value.screen,\n\t\t\tforms: data?.forms ?? state.value.forms,\n\t\t\tlayout: data?.layout ?? state.value.layout,\n\t\t\tmessages: data?.messages ?? {},\n\t\t\tbranding: data?.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\tObject.keys(newState.messages ?? {}).forEach((formId) => {\n\t\t\tif (formId === 'global') {\n\t\t\t\temit('globalMessage', newState.messages?.global?.text ?? '');\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\tsetTimeout(() => {\n\t\t\temit('blockReady', { previousState, state: JSON.parse(JSON.stringify(state.value)) });\n\t\t});\n\t}\n}\n</script>\n\n<template>\n\t<div class=\"login-renderer\">\n\t\t<component :is=\"widgets.layout\" v-if=\"state.screen\" :formId=\"(state.layout?.items[0] as Widget).formId\" :type=\"state.layout?.type\" tag=\"form\">\n\t\t\t<WidgetRenderer :items=\"state.layout?.items\" :widgets=\"widgets\" />\n\t\t</component>\n\t\t<component :is=\"widgets.loading\" v-else />\n\t</div>\n</template>\n"],"names":["sdk","useStrivacity","props","__props","emit","__emit","WidgetRenderer","defineComponent","item","form","state","widget","triggerFallback","component","h","loginHandler","loading","ref","forms","messages","provide","submitForm","triggerClose","setFormValue","setMessage","onMounted","data","handleResponse","error","FallbackError","hostedUrl","message","url","formId","widgetId","value","unflattenObject","previous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AAW,CACpDA,IAAW,SACd7B,EAAK,gBAAiBkC,EAAS,UAAU,QAAQ,MAAQ,EAAE,EAE3DnB,EAAS,MAAMc,CAAM,EAAIK,EAAS,SAAUL,CAAM,CAEpD,CAAC,EAEDvB,EAAM,MAAQ4B,EAEd,WAAW,IAAM,CAChBlC,EAAK,aAAc,CAAE,cAAAiC,EAAe,MAAO,KAAK,MAAM,KAAK,UAAU3B,EAAM,KAAK,CAAC,CAAA,CAAG,CACrF,CAAC,CACF,CACD,eAIC6B,YAAA,EAAAC,qBAKM,MALNC,EAKM,CAJiC/B,EAAA,MAAM,sBAA5CgC,cAEYC,EAAAA,wBAFIxC,EAAA,QAAQ,MAAM,EAAA,OAAuB,QAASO,EAAA,MAAM,QAAQ,UAAoB,OAAS,KAAMA,EAAA,MAAM,QAAQ,KAAM,IAAI,MAAA,qBACtI,IAAkE,CAAlEkC,cAAkEC,EAAAA,MAAAvC,CAAA,EAAA,CAAjD,MAAOI,EAAA,MAAM,QAAQ,MAAQ,QAASP,EAAA,OAAA,0EAExDuC,EAAAA,YAA0CC,EAAAA,wBAA1BxC,EAAA,QAAQ,OAAO,EAAA,CAAA,IAAA,EAAA,EAAA"}
|
|
1
|
+
{"version":3,"file":"login-renderer.vue_vue_type_script_setup_true_lang.cjs","sources":["../../src/login-renderer.vue"],"sourcesContent":["<!-- eslint-disable no-console -->\n<script lang=\"ts\" setup>\nimport type { VNode, Component, PropType } from 'vue';\nimport type { PartialRecord, NativeParams, WidgetType, LayoutWidget, LoginFlowState, Widget, IdTokenClaims, LoginFlowMessage } from '@strivacity/sdk-core';\nimport type { NativeContext, NativeFlowContextValue } from './types';\nimport { defineComponent, provide, ref, h, onMounted } from 'vue';\nimport { FallbackError } from '@strivacity/sdk-core';\nimport { unflattenObject } from '@strivacity/sdk-core/utils/object';\nimport { useStrivacity } from './composables';\n\nconst { sdk } = useStrivacity<NativeContext>();\n\nconst props = withDefaults(\n\tdefineProps<{\n\t\tparams?: NativeParams;\n\t\twidgets?: PartialRecord<WidgetType, Component>;\n\t\tlanguage?: string | null;\n\t\tsessionId?: string | null;\n\t}>(),\n\t{\n\t\tparams: () => ({}),\n\t\twidgets: () => ({}),\n\t\tlanguage: navigator.language,\n\t\tsessionId: null,\n\t},\n);\nconst emit = defineEmits<{\n\tlogin: [IdTokenClaims | null | undefined];\n\tfallback: [FallbackError];\n\tclose: [];\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\terror: [any];\n\tglobalMessage: [string];\n\tblockReady: [{ previousState: LoginFlowState; state: LoginFlowState }];\n\t'update:language': [string | null];\n}>();\n\nconst WidgetRenderer = defineComponent({\n\tprops: {\n\t\titems: {\n\t\t\ttype: Array as PropType<LayoutWidget['items']>,\n\t\t\tdefault: () => [],\n\t\t},\n\t\twidgets: {\n\t\t\ttype: Object as PropType<PartialRecord<WidgetType, Component>>,\n\t\t\tdefault: () => ({}),\n\t\t},\n\t},\n\tsetup: (props) => () =>\n\t\tprops.items.map((item): VNode | null => {\n\t\t\tif (item.type === 'widget') {\n\t\t\t\tconst form = state.value?.forms?.find((form) => form.id === item.formId);\n\t\t\t\tconst widget = form?.widgets.find((widget) => widget.id === item.widgetId);\n\n\t\t\t\tif (!form || !widget) {\n\t\t\t\t\ttriggerFallback(undefined, `Unable to find form or widget for item: formId=${item.formId}, widgetId=${item.widgetId}`);\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\tconst component = props.widgets[widget.type];\n\n\t\t\t\tif (!component) {\n\t\t\t\t\ttriggerFallback(undefined, `No component found for widget type ${widget.type}`);\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\treturn h(component, { key: `${form.id}.${widget.id}`, formId: form.id, config: widget });\n\t\t\t} else if (item.type === 'vertical' || item.type === 'horizontal') {\n\t\t\t\tif (!props.widgets.layout) {\n\t\t\t\t\ttriggerFallback(undefined, 'No layout component provided');\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\treturn h(props.widgets.layout, { formId: (item.items[0] as Widget).formId, type: item.type }, () =>\n\t\t\t\t\th(WidgetRenderer, { items: item.items, widgets: props.widgets }),\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\ttriggerFallback(undefined, 'Unknown item type in layout');\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}),\n});\n\nconst loginHandler = sdk.login(props.params);\nconst loading = ref<boolean>(false);\nconst forms = ref<Record<string, Record<string, unknown>>>({});\nconst messages = ref<Record<string, Record<string, LoginFlowMessage>>>({});\nconst state = ref<LoginFlowState>({});\n\nprovide<NativeFlowContextValue>('nativeFlowContext', {\n\tloading,\n\tforms,\n\tmessages,\n\tstate,\n\tsubmitForm,\n\ttriggerFallback,\n\ttriggerClose,\n\tsetFormValue,\n\tsetMessage,\n});\n\nonMounted(async () => {\n\ttry {\n\t\tconst data = await loginHandler.startSession(props.sessionId, props.language);\n\t\temit('update:language', loginHandler.language);\n\n\t\tif (data) {\n\t\t\tawait handleResponse(data);\n\t\t}\n\t} catch (error) {\n\t\tif (error instanceof FallbackError) {\n\t\t\temit('fallback', error);\n\t\t} else {\n\t\t\temit('error', error);\n\t\t}\n\t}\n});\n\nfunction triggerFallback(hostedUrl?: string, message?: string): void {\n\tconst url = hostedUrl || state.value.hostedUrl;\n\n\tsdk.logging?.warn(message ? `Triggering fallback due to: ${message}` : 'Triggering fallback');\n\n\tif (!url) {\n\t\tconst error = new Error('No hosted URL provided');\n\t\tsdk.logging?.error('Fallback error', error);\n\t\tthrow error;\n\t}\n\n\temit('fallback', new FallbackError(new URL(url)));\n}\n\nfunction triggerClose(): void {\n\temit('close');\n}\n\nfunction setFormValue(formId: string, widgetId: string, value: unknown) {\n\tif (value === '') {\n\t\tvalue = null;\n\t}\n\n\tif (forms.value[formId] === undefined) {\n\t\tforms.value[formId] = {};\n\t}\n\n\tforms.value[formId][widgetId] = value;\n}\n\nfunction setMessage(formId: string, widgetId: string, value: LoginFlowMessage) {\n\tif (messages.value[formId] === undefined) {\n\t\tmessages.value[formId] = {};\n\t}\n\n\tmessages.value[formId][widgetId] = value;\n}\n\nasync function submitForm(formId: string): Promise<void> {\n\ttry {\n\t\tloading.value = true;\n\n\t\tconst data = await loginHandler.submitForm(formId, unflattenObject(forms.value[formId]));\n\t\tawait handleResponse(data);\n\n\t\tloading.value = false;\n\t} catch (error) {\n\t\tif (error instanceof FallbackError) {\n\t\t\temit('fallback', error);\n\t\t} else {\n\t\t\temit('error', error);\n\t\t}\n\t}\n}\n\nasync function handleResponse(data?: LoginFlowState) {\n\tif (await sdk.isAuthenticated) {\n\t\temit('login', sdk.idTokenClaims);\n\t} else {\n\t\tconst previousState = JSON.parse(JSON.stringify(state.value));\n\t\tconst newState: LoginFlowState = {\n\t\t\thostedUrl: data?.hostedUrl ?? state.value.hostedUrl,\n\t\t\tfinalizeUrl: data?.finalizeUrl ?? state.value.finalizeUrl,\n\t\t\tscreen: data?.screen ?? state.value.screen,\n\t\t\tforms: data?.forms ?? state.value.forms,\n\t\t\tlayout: data?.layout ?? state.value.layout,\n\t\t\tmessages: data?.messages ?? {},\n\t\t\tbranding: data?.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\tObject.keys(newState.messages ?? {}).forEach((formId) => {\n\t\t\tif (formId === 'global') {\n\t\t\t\temit('globalMessage', newState.messages?.global?.text ?? '');\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\tsetTimeout(() => {\n\t\t\temit('blockReady', { previousState, state: JSON.parse(JSON.stringify(state.value)) });\n\t\t});\n\t}\n}\n</script>\n\n<template>\n\t<div class=\"login-renderer\">\n\t\t<component :is=\"widgets.layout\" v-if=\"state.screen\" :formId=\"(state.layout?.items[0] as Widget).formId\" :type=\"state.layout?.type\" tag=\"form\">\n\t\t\t<WidgetRenderer :items=\"state.layout?.items\" :widgets=\"widgets\" />\n\t\t</component>\n\t\t<component :is=\"widgets.loading\" v-else />\n\t</div>\n</template>\n"],"names":["sdk","useStrivacity","props","__props","emit","__emit","WidgetRenderer","defineComponent","item","form","state","widget","triggerFallback","component","h","loginHandler","loading","ref","forms","messages","provide","submitForm","triggerClose","setFormValue","setMessage","onMounted","data","handleResponse","error","FallbackError","hostedUrl","message","url","formId","widgetId","value","unflattenObject","previousState","newState","_openBlock","_createElementBlock","_hoisted_1","_createBlock","_resolveDynamicComponent","_createVNode","_unref"],"mappings":"qcAUA,KAAM,CAAE,IAAAA,CAAA,EAAQC,gBAAA,EAEVC,EAAQC,EAcRC,EAAOC,EAWPC,EAAiBC,EAAAA,gBAAgB,CACtC,MAAO,CACN,MAAO,CACN,KAAM,MACN,QAAS,IAAM,CAAA,CAAC,EAEjB,QAAS,CACR,KAAM,OACN,QAAS,KAAO,CAAA,EAAC,CAClB,EAED,MAAQL,GAAU,IACjBA,EAAM,MAAM,IAAKM,GAAuB,CACvC,GAAIA,EAAK,OAAS,SAAU,CAC3B,MAAMC,EAAOC,EAAM,OAAO,OAAO,KAAMD,GAASA,EAAK,KAAOD,EAAK,MAAM,EACjEG,EAASF,GAAM,QAAQ,KAAME,GAAWA,EAAO,KAAOH,EAAK,QAAQ,EAEzE,GAAI,CAACC,GAAQ,CAACE,EACb,OAAAC,EAAgB,OAAW,kDAAkDJ,EAAK,MAAM,cAAcA,EAAK,QAAQ,EAAE,EAC9G,KAGR,MAAMK,EAAYX,EAAM,QAAQS,EAAO,IAAI,EAE3C,OAAKE,EAKEC,EAAAA,EAAED,EAAW,CAAE,IAAK,GAAGJ,EAAK,EAAE,IAAIE,EAAO,EAAE,GAAI,OAAQF,EAAK,GAAI,OAAQE,EAAQ,GAJtF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{defineComponent as U,ref as
|
|
1
|
+
import{defineComponent as U,ref as g,h as y,provide as R,onMounted as x,createElementBlock as z,openBlock as w,createBlock as N,resolveDynamicComponent as S,withCtx as E,createVNode as J,unref as M}from"vue";import{FallbackError as p}from"@strivacity/sdk-core";import{unflattenObject as T}from"@strivacity/sdk-core/utils/object";import{useStrivacity as _}from"../composables.mjs";const j={class:"login-renderer"},D=U({__name:"login-renderer",props:{params:{default:()=>({})},widgets:{default:()=>({})},language:{default:navigator.language},sessionId:{default:null}},emits:["login","fallback","close","error","globalMessage","blockReady","update:language"],setup(d,{emit:F}){const{sdk:i}=_(),c=d,l=F,b=U({props:{items:{type:Array,default:()=>[]},widgets:{type:Object,default:()=>({})}},setup:e=>()=>e.items.map(t=>{if(t.type==="widget"){const o=a.value?.forms?.find(v=>v.id===t.formId),n=o?.widgets.find(v=>v.id===t.widgetId);if(!o||!n)return u(void 0,`Unable to find form or widget for item: formId=${t.formId}, widgetId=${t.widgetId}`),null;const h=e.widgets[n.type];return h?y(h,{key:`${o.id}.${n.id}`,formId:o.id,config:n}):(u(void 0,`No component found for widget type ${n.type}`),null)}else return t.type==="vertical"||t.type==="horizontal"?e.widgets.layout?y(e.widgets.layout,{formId:t.items[0].formId,type:t.type},()=>y(b,{items:t.items,widgets:e.widgets})):(u(void 0,"No layout component provided"),null):(u(void 0,"Unknown item type in layout"),null)})}),f=i.login(c.params),m=g(!1),s=g({}),r=g({}),a=g({});R("nativeFlowContext",{loading:m,forms:s,messages:r,state:a,submitForm:C,triggerFallback:u,triggerClose:I,setFormValue:O,setMessage:$}),x(async()=>{try{const e=await f.startSession(c.sessionId,c.language);l("update:language",f.language),e&&await k(e)}catch(e){e instanceof p?l("fallback",e):l("error",e)}});function u(e,t){const o=e||a.value.hostedUrl;if(i.logging?.warn(t?`Triggering fallback due to: ${t}`:"Triggering fallback"),!o){const n=new Error("No hosted URL provided");throw i.logging?.error("Fallback error",n),n}l("fallback",new p(new URL(o)))}function I(){l("close")}function O(e,t,o){o===""&&(o=null),s.value[e]===void 0&&(s.value[e]={}),s.value[e][t]=o}function $(e,t,o){r.value[e]===void 0&&(r.value[e]={}),r.value[e][t]=o}async function C(e){try{m.value=!0;const t=await f.submitForm(e,T(s.value[e]));await k(t),m.value=!1}catch(t){t instanceof p?l("fallback",t):l("error",t)}}async function k(e){if(await i.isAuthenticated)l("login",i.idTokenClaims);else{const t=JSON.parse(JSON.stringify(a.value)),o={hostedUrl:e?.hostedUrl??a.value.hostedUrl,finalizeUrl:e?.finalizeUrl??a.value.finalizeUrl,screen:e?.screen??a.value.screen,forms:e?.forms??a.value.forms,layout:e?.layout??a.value.layout,messages:e?.messages??{},branding:e?.branding??a.value.branding};if(o.screen!=a.value.screen){s.value={},r.value={};for(const n of o.forms??[])s.value[n.id]={},r.value[n.id]={}}else i.logging?.info(`Updating screen: ${o.screen}`);Object.keys(o.messages??{}).forEach(n=>{n==="global"?l("globalMessage",o.messages?.global?.text??""):r.value[n]=o.messages[n]}),a.value=o,setTimeout(()=>{l("blockReady",{previousState:t,state:JSON.parse(JSON.stringify(a.value))})})}}return(e,t)=>(w(),z("div",j,[a.value.screen?(w(),N(S(d.widgets.layout),{key:0,formId:(a.value.layout?.items[0]).formId,type:a.value.layout?.type,tag:"form"},{default:E(()=>[J(M(b),{items:a.value.layout?.items,widgets:d.widgets},null,8,["items","widgets"])]),_:1},8,["formId","type"])):(w(),N(S(d.widgets.loading),{key:1}))]))}});export{D as _};
|
|
2
2
|
//# sourceMappingURL=login-renderer.vue_vue_type_script_setup_true_lang.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login-renderer.vue_vue_type_script_setup_true_lang.mjs","sources":["../../src/login-renderer.vue"],"sourcesContent":["<!-- eslint-disable no-console -->\n<script lang=\"ts\" setup>\nimport type { VNode, Component, PropType } from 'vue';\nimport type { PartialRecord, NativeParams, WidgetType, LayoutWidget, LoginFlowState, Widget, IdTokenClaims, LoginFlowMessage } from '@strivacity/sdk-core';\nimport type { NativeContext, NativeFlowContextValue } from './types';\nimport { defineComponent, provide, ref, h, onMounted } from 'vue';\nimport { FallbackError } from '@strivacity/sdk-core';\nimport { unflattenObject } from '@strivacity/sdk-core/utils/object';\nimport { useStrivacity } from './composables';\n\nconst { sdk } = useStrivacity<NativeContext>();\n\nconst props = withDefaults(\n\tdefineProps<{\n\t\tparams?: NativeParams;\n\t\twidgets?: PartialRecord<WidgetType, Component>;\n\t\tsessionId?: string | null;\n\t}>(),\n\t{\n\t\tparams: () => ({}),\n\t\twidgets: () => ({}),\n\t\tsessionId: null,\n\t},\n);\nconst emit = defineEmits<{\n\tlogin: [IdTokenClaims | null | undefined];\n\tfallback: [FallbackError];\n\tclose: [];\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\terror: [any];\n\tglobalMessage: [string];\n\tblockReady: [{ previousState: LoginFlowState; state: LoginFlowState }];\n}>();\n\nconst WidgetRenderer = defineComponent({\n\tprops: {\n\t\titems: {\n\t\t\ttype: Array as PropType<LayoutWidget['items']>,\n\t\t\tdefault: () => [],\n\t\t},\n\t\twidgets: {\n\t\t\ttype: Object as PropType<PartialRecord<WidgetType, Component>>,\n\t\t\tdefault: () => ({}),\n\t\t},\n\t},\n\tsetup: (props) => () =>\n\t\tprops.items.map((item): VNode | null => {\n\t\t\tif (item.type === 'widget') {\n\t\t\t\tconst form = state.value?.forms?.find((form) => form.id === item.formId);\n\t\t\t\tconst widget = form?.widgets.find((widget) => widget.id === item.widgetId);\n\n\t\t\t\tif (!form || !widget) {\n\t\t\t\t\ttriggerFallback(undefined, `Unable to find form or widget for item: formId=${item.formId}, widgetId=${item.widgetId}`);\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\tconst component = props.widgets[widget.type];\n\n\t\t\t\tif (!component) {\n\t\t\t\t\ttriggerFallback(undefined, `No component found for widget type ${widget.type}`);\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\treturn h(component, { key: `${form.id}.${widget.id}`, formId: form.id, config: widget });\n\t\t\t} else if (item.type === 'vertical' || item.type === 'horizontal') {\n\t\t\t\tif (!props.widgets.layout) {\n\t\t\t\t\ttriggerFallback(undefined, 'No layout component provided');\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\treturn h(props.widgets.layout, { formId: (item.items[0] as Widget).formId, type: item.type }, () =>\n\t\t\t\t\th(WidgetRenderer, { items: item.items, widgets: props.widgets }),\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\ttriggerFallback(undefined, 'Unknown item type in layout');\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}),\n});\n\nconst loginHandler = sdk.login(props.params);\nconst loading = ref<boolean>(false);\nconst forms = ref<Record<string, Record<string, unknown>>>({});\nconst messages = ref<Record<string, Record<string, LoginFlowMessage>>>({});\nconst state = ref<LoginFlowState>({});\n\nprovide<NativeFlowContextValue>('nativeFlowContext', {\n\tloading,\n\tforms,\n\tmessages,\n\tstate,\n\tsubmitForm,\n\ttriggerFallback,\n\ttriggerClose,\n\tsetFormValue,\n\tsetMessage,\n});\n\nonMounted(async () => {\n\ttry {\n\t\tconst data = await loginHandler.startSession(props.sessionId);\n\n\t\tif (data) {\n\t\t\tawait handleResponse(data);\n\t\t}\n\t} catch (error) {\n\t\tif (error instanceof FallbackError) {\n\t\t\temit('fallback', error);\n\t\t} else {\n\t\t\temit('error', error);\n\t\t}\n\t}\n});\n\nfunction triggerFallback(hostedUrl?: string, message?: string): void {\n\tconst url = hostedUrl || state.value.hostedUrl;\n\n\tsdk.logging?.warn(message ? `Triggering fallback due to: ${message}` : 'Triggering fallback');\n\n\tif (!url) {\n\t\tconst error = new Error('No hosted URL provided');\n\t\tsdk.logging?.error('Fallback error', error);\n\t\tthrow error;\n\t}\n\n\temit('fallback', new FallbackError(new URL(url)));\n}\n\nfunction triggerClose(): void {\n\temit('close');\n}\n\nfunction setFormValue(formId: string, widgetId: string, value: unknown) {\n\tif (value === '') {\n\t\tvalue = null;\n\t}\n\n\tif (forms.value[formId] === undefined) {\n\t\tforms.value[formId] = {};\n\t}\n\n\tforms.value[formId][widgetId] = value;\n}\n\nfunction setMessage(formId: string, widgetId: string, value: LoginFlowMessage) {\n\tif (messages.value[formId] === undefined) {\n\t\tmessages.value[formId] = {};\n\t}\n\n\tmessages.value[formId][widgetId] = value;\n}\n\nasync function submitForm(formId: string): Promise<void> {\n\ttry {\n\t\tloading.value = true;\n\n\t\tconst data = await loginHandler.submitForm(formId, unflattenObject(forms.value[formId]));\n\t\tawait handleResponse(data);\n\n\t\tloading.value = false;\n\t} catch (error) {\n\t\tif (error instanceof FallbackError) {\n\t\t\temit('fallback', error);\n\t\t} else {\n\t\t\temit('error', error);\n\t\t}\n\t}\n}\n\nasync function handleResponse(data?: LoginFlowState) {\n\tif (await sdk.isAuthenticated) {\n\t\temit('login', sdk.idTokenClaims);\n\t} else {\n\t\tconst previousState = JSON.parse(JSON.stringify(state.value));\n\t\tconst newState: LoginFlowState = {\n\t\t\thostedUrl: data?.hostedUrl ?? state.value.hostedUrl,\n\t\t\tfinalizeUrl: data?.finalizeUrl ?? state.value.finalizeUrl,\n\t\t\tscreen: data?.screen ?? state.value.screen,\n\t\t\tforms: data?.forms ?? state.value.forms,\n\t\t\tlayout: data?.layout ?? state.value.layout,\n\t\t\tmessages: data?.messages ?? {},\n\t\t\tbranding: data?.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\tObject.keys(newState.messages ?? {}).forEach((formId) => {\n\t\t\tif (formId === 'global') {\n\t\t\t\temit('globalMessage', newState.messages?.global?.text ?? '');\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\tsetTimeout(() => {\n\t\t\temit('blockReady', { previousState, state: JSON.parse(JSON.stringify(state.value)) });\n\t\t});\n\t}\n}\n</script>\n\n<template>\n\t<div class=\"login-renderer\">\n\t\t<component :is=\"widgets.layout\" v-if=\"state.screen\" :formId=\"(state.layout?.items[0] as Widget).formId\" :type=\"state.layout?.type\" tag=\"form\">\n\t\t\t<WidgetRenderer :items=\"state.layout?.items\" :widgets=\"widgets\" />\n\t\t</component>\n\t\t<component :is=\"widgets.loading\" v-else />\n\t</div>\n</template>\n"],"names":["sdk","useStrivacity","props","__props","emit","__emit","WidgetRenderer","defineComponent","item","form","state","widget","triggerFallback","component","h","loginHandler","loading","ref","forms","messages","provide","submitForm","triggerClose","setFormValue","setMessage","onMounted","data","handleResponse","error","FallbackError","hostedUrl","message","url","formId","widgetId","value","unflattenObject","previousState","newState","_openBlock","_createElementBlock","_hoisted_1","_createBlock","_resolveDynamicComponent","_createVNode","_unref"],"mappings":"0mBAUA,KAAM,CAAE,IAAAA,CAAA,EAAQC,EAAA,EAEVC,EAAQC,EAYRC,EAAOC,EAUPC,EAAiBC,EAAgB,CACtC,MAAO,CACN,MAAO,CACN,KAAM,MACN,QAAS,IAAM,CAAA,CAAC,EAEjB,QAAS,CACR,KAAM,OACN,QAAS,KAAO,CAAA,EAAC,CAClB,EAED,MAAQL,GAAU,IACjBA,EAAM,MAAM,IAAKM,GAAuB,CACvC,GAAIA,EAAK,OAAS,SAAU,CAC3B,MAAMC,EAAOC,EAAM,OAAO,OAAO,KAAMD,GAASA,EAAK,KAAOD,EAAK,MAAM,EACjEG,EAASF,GAAM,QAAQ,KAAME,GAAWA,EAAO,KAAOH,EAAK,QAAQ,EAEzE,GAAI,CAACC,GAAQ,CAACE,EACb,OAAAC,EAAgB,OAAW,kDAAkDJ,EAAK,MAAM,cAAcA,EAAK,QAAQ,EAAE,EAC9G,KAGR,MAAMK,EAAYX,EAAM,QAA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login-renderer.vue"],"sourcesContent":["<!-- eslint-disable no-console -->\n<script lang=\"ts\" setup>\nimport type { VNode, Component, PropType } from 'vue';\nimport type { PartialRecord, NativeParams, WidgetType, LayoutWidget, LoginFlowState, Widget, IdTokenClaims, LoginFlowMessage } from '@strivacity/sdk-core';\nimport type { NativeContext, NativeFlowContextValue } from './types';\nimport { defineComponent, provide, ref, h, onMounted } from 'vue';\nimport { FallbackError } from '@strivacity/sdk-core';\nimport { unflattenObject } from '@strivacity/sdk-core/utils/object';\nimport { useStrivacity } from './composables';\n\nconst { sdk } = useStrivacity<NativeContext>();\n\nconst props = withDefaults(\n\tdefineProps<{\n\t\tparams?: NativeParams;\n\t\twidgets?: PartialRecord<WidgetType, Component>;\n\t\tlanguage?: string | null;\n\t\tsessionId?: string | null;\n\t}>(),\n\t{\n\t\tparams: () => ({}),\n\t\twidgets: () => ({}),\n\t\tlanguage: navigator.language,\n\t\tsessionId: null,\n\t},\n);\nconst emit = defineEmits<{\n\tlogin: [IdTokenClaims | null | undefined];\n\tfallback: [FallbackError];\n\tclose: [];\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\terror: [any];\n\tglobalMessage: [string];\n\tblockReady: [{ previousState: LoginFlowState; state: LoginFlowState }];\n\t'update:language': [string | null];\n}>();\n\nconst WidgetRenderer = defineComponent({\n\tprops: {\n\t\titems: {\n\t\t\ttype: Array as PropType<LayoutWidget['items']>,\n\t\t\tdefault: () => [],\n\t\t},\n\t\twidgets: {\n\t\t\ttype: Object as PropType<PartialRecord<WidgetType, Component>>,\n\t\t\tdefault: () => ({}),\n\t\t},\n\t},\n\tsetup: (props) => () =>\n\t\tprops.items.map((item): VNode | null => {\n\t\t\tif (item.type === 'widget') {\n\t\t\t\tconst form = state.value?.forms?.find((form) => form.id === item.formId);\n\t\t\t\tconst widget = form?.widgets.find((widget) => widget.id === item.widgetId);\n\n\t\t\t\tif (!form || !widget) {\n\t\t\t\t\ttriggerFallback(undefined, `Unable to find form or widget for item: formId=${item.formId}, widgetId=${item.widgetId}`);\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\tconst component = props.widgets[widget.type];\n\n\t\t\t\tif (!component) {\n\t\t\t\t\ttriggerFallback(undefined, `No component found for widget type ${widget.type}`);\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\treturn h(component, { key: `${form.id}.${widget.id}`, formId: form.id, config: widget });\n\t\t\t} else if (item.type === 'vertical' || item.type === 'horizontal') {\n\t\t\t\tif (!props.widgets.layout) {\n\t\t\t\t\ttriggerFallback(undefined, 'No layout component provided');\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\treturn h(props.widgets.layout, { formId: (item.items[0] as Widget).formId, type: item.type }, () =>\n\t\t\t\t\th(WidgetRenderer, { items: item.items, widgets: props.widgets }),\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\ttriggerFallback(undefined, 'Unknown item type in layout');\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}),\n});\n\nconst loginHandler = sdk.login(props.params);\nconst loading = ref<boolean>(false);\nconst forms = ref<Record<string, Record<string, unknown>>>({});\nconst messages = ref<Record<string, Record<string, LoginFlowMessage>>>({});\nconst state = ref<LoginFlowState>({});\n\nprovide<NativeFlowContextValue>('nativeFlowContext', {\n\tloading,\n\tforms,\n\tmessages,\n\tstate,\n\tsubmitForm,\n\ttriggerFallback,\n\ttriggerClose,\n\tsetFormValue,\n\tsetMessage,\n});\n\nonMounted(async () => {\n\ttry {\n\t\tconst data = await loginHandler.startSession(props.sessionId, props.language);\n\t\temit('update:language', loginHandler.language);\n\n\t\tif (data) {\n\t\t\tawait handleResponse(data);\n\t\t}\n\t} catch (error) {\n\t\tif (error instanceof FallbackError) {\n\t\t\temit('fallback', error);\n\t\t} else {\n\t\t\temit('error', error);\n\t\t}\n\t}\n});\n\nfunction triggerFallback(hostedUrl?: string, message?: string): void {\n\tconst url = hostedUrl || state.value.hostedUrl;\n\n\tsdk.logging?.warn(message ? `Triggering fallback due to: ${message}` : 'Triggering fallback');\n\n\tif (!url) {\n\t\tconst error = new Error('No hosted URL provided');\n\t\tsdk.logging?.error('Fallback error', error);\n\t\tthrow error;\n\t}\n\n\temit('fallback', new FallbackError(new URL(url)));\n}\n\nfunction triggerClose(): void {\n\temit('close');\n}\n\nfunction setFormValue(formId: string, widgetId: string, value: unknown) {\n\tif (value === '') {\n\t\tvalue = null;\n\t}\n\n\tif (forms.value[formId] === undefined) {\n\t\tforms.value[formId] = {};\n\t}\n\n\tforms.value[formId][widgetId] = value;\n}\n\nfunction setMessage(formId: string, widgetId: string, value: LoginFlowMessage) {\n\tif (messages.value[formId] === undefined) {\n\t\tmessages.value[formId] = {};\n\t}\n\n\tmessages.value[formId][widgetId] = value;\n}\n\nasync function submitForm(formId: string): Promise<void> {\n\ttry {\n\t\tloading.value = true;\n\n\t\tconst data = await loginHandler.submitForm(formId, unflattenObject(forms.value[formId]));\n\t\tawait handleResponse(data);\n\n\t\tloading.value = false;\n\t} catch (error) {\n\t\tif (error instanceof FallbackError) {\n\t\t\temit('fallback', error);\n\t\t} else {\n\t\t\temit('error', error);\n\t\t}\n\t}\n}\n\nasync function handleResponse(data?: LoginFlowState) {\n\tif (await sdk.isAuthenticated) {\n\t\temit('login', sdk.idTokenClaims);\n\t} else {\n\t\tconst previousState = JSON.parse(JSON.stringify(state.value));\n\t\tconst newState: LoginFlowState = {\n\t\t\thostedUrl: data?.hostedUrl ?? state.value.hostedUrl,\n\t\t\tfinalizeUrl: data?.finalizeUrl ?? state.value.finalizeUrl,\n\t\t\tscreen: data?.screen ?? state.value.screen,\n\t\t\tforms: data?.forms ?? state.value.forms,\n\t\t\tlayout: data?.layout ?? state.value.layout,\n\t\t\tmessages: data?.messages ?? {},\n\t\t\tbranding: data?.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\tObject.keys(newState.messages ?? {}).forEach((formId) => {\n\t\t\tif (formId === 'global') {\n\t\t\t\temit('globalMessage', newState.messages?.global?.text ?? '');\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\tsetTimeout(() => {\n\t\t\temit('blockReady', { previousState, state: JSON.parse(JSON.stringify(state.value)) });\n\t\t});\n\t}\n}\n</script>\n\n<template>\n\t<div class=\"login-renderer\">\n\t\t<component :is=\"widgets.layout\" v-if=\"state.screen\" :formId=\"(state.layout?.items[0] as Widget).formId\" :type=\"state.layout?.type\" tag=\"form\">\n\t\t\t<WidgetRenderer :items=\"state.layout?.items\" :widgets=\"widgets\" />\n\t\t</component>\n\t\t<component :is=\"widgets.loading\" v-else />\n\t</div>\n</template>\n"],"names":["sdk","useStrivacity","props","__props","emit","__emit","WidgetRenderer","defineComponent","item","form","state","widget","triggerFallback","component","h","loginHandler","loading","ref","forms","messages","provide","submitForm","triggerClose","setFormValue","setMessage","onMounted","data","handleResponse","error","FallbackError","hostedUrl","message","url","formId","widgetId","value","unflattenObject","previousState","newState","_openBlock","_createElementBlock","_hoisted_1","_createBlock","_resolveDynamicComponent","_createVNode","_unref"],"mappings":"kqBAUA,KAAM,CAAE,IAAAA,CAAA,EAAQC,EAAA,EAEVC,EAAQC,EAcRC,EAAOC,EAWPC,EAAiBC,EAAgB,CACtC,MAAO,CACN,MAAO,CACN,KAAM,MACN,QAAS,IAAM,CAAA,CAAC,EAEjB,QAAS,CACR,KAAM,OACN,QAAS,KAAO,CAAA,EAAC,CAClB,EAED,MAAQL,GAAU,IACjBA,EAAM,MAAM,IAAKM,GAAuB,CACvC,GAAIA,EAAK,OAAS,SAAU,CAC3B,MAAMC,EAAOC,EA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,UAAoB,OAAS,KAAMA,EAAA,MAAM,QAAQ,KAAM,IAAI,MAAA,aACtI,IAAkE,CAAlEkC,EAAkEC,EAAAvC,CAAA,EAAA,CAAjD,MAAOI,EAAA,MAAM,QAAQ,MAAQ,QAASP,EAAA,OAAA,gEAExDuC,EAA0CC,EAA1BxC,EAAA,QAAQ,OAAO,EAAA,CAAA,IAAA,EAAA,EAAA"}
|
|
@@ -3,6 +3,7 @@ import { PartialRecord, NativeParams, WidgetType, LoginFlowState, IdTokenClaims,
|
|
|
3
3
|
type __VLS_Props = {
|
|
4
4
|
params?: NativeParams;
|
|
5
5
|
widgets?: PartialRecord<WidgetType, Component>;
|
|
6
|
+
language?: string | null;
|
|
6
7
|
sessionId?: string | null;
|
|
7
8
|
};
|
|
8
9
|
declare const _default: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
@@ -15,6 +16,7 @@ declare const _default: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {
|
|
|
15
16
|
previousState: LoginFlowState;
|
|
16
17
|
state: LoginFlowState;
|
|
17
18
|
}) => any;
|
|
19
|
+
"update:language": (args_0: string | null) => any;
|
|
18
20
|
}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
19
21
|
onLogin?: ((args_0: IdTokenClaims | null | undefined) => any) | undefined;
|
|
20
22
|
onClose?: (() => any) | undefined;
|
|
@@ -25,9 +27,11 @@ declare const _default: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {
|
|
|
25
27
|
previousState: LoginFlowState;
|
|
26
28
|
state: LoginFlowState;
|
|
27
29
|
}) => any) | undefined;
|
|
30
|
+
"onUpdate:language"?: ((args_0: string | null) => any) | undefined;
|
|
28
31
|
}>, {
|
|
29
32
|
params: NativeParams;
|
|
30
33
|
widgets: PartialRecord<WidgetType, Component>;
|
|
34
|
+
language: string | null;
|
|
31
35
|
sessionId: string | null;
|
|
32
36
|
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, HTMLDivElement>;
|
|
33
37
|
export default _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strivacity/sdk-vue",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Strivacity Vue.js SDK client",
|
|
6
6
|
"author": "strivacity <opensource@strivacity.com>",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"url": "https://github.com/Strivacity/sdk-js"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@strivacity/sdk-core": "3.0.
|
|
12
|
+
"@strivacity/sdk-core": "3.0.2"
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
15
|
"vue": ">=3"
|