@arkyc/widget 1.2.8 → 1.2.10
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/dist/arkyc-widget.iife.global.js +1 -1
- package/dist/arkyc-widget.iife.global.js.map +1 -1
- package/dist/controller.d.mts +2 -0
- package/dist/controller.d.mts.map +1 -1
- package/dist/controller.mjs +15 -7
- package/dist/controller.mjs.map +1 -1
- package/dist/theme.d.mts.map +1 -1
- package/dist/theme.mjs.map +1 -1
- package/package.json +2 -2
package/dist/controller.d.mts
CHANGED
|
@@ -172,6 +172,8 @@ declare class WidgetController {
|
|
|
172
172
|
/** Run an async step, routing any failure to the error screen. */
|
|
173
173
|
private run;
|
|
174
174
|
private fail;
|
|
175
|
+
/** Event payload for a failure: the message plus the stable key/status when it's a typed API error. */
|
|
176
|
+
private errorData;
|
|
175
177
|
private finishResult;
|
|
176
178
|
private finishClose;
|
|
177
179
|
/** Stop any active session watch + disconnect the push transport. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.d.mts","names":[],"sources":["../src/controller.ts"],"mappings":";;;cAoEa,gBAAA;EAAA,iBAmDkB,MAAA;EAAA,iBAlDZ,MAAA;EAAA,iBACA,IAAA;EAAA,iBACA,GAAA;EAAA,iBACA,GAAA;EAAA,iBACA,YAAA;EAAA,iBACA,SAAA;EAAA,iBACA,WAAA;EAAA,iBACA,MAAA;EAAA,iBACA,QAAA;EAAA,iBACA,eAAA;EARA;EAAA,QAWT,aAAA;EAAA,QACA,YAAA;EAAA,QACA,aAAA;EATS;EAAA,QAYT,SAAA;EAAA,QACA,cAAA;EAAA,QACA,QAAA;EAAA,QACA,UAAA;EARA;EAAA,QAUA,UAAA;EARA;EAAA,QAUA,SAAA;EANA;EAAA,QAQA,SAAA;EAAA,QAEA,IAAA;EAAA,QACA,YAAA;EAAA,QACA,OAAA;EAAA,QACA,MAAA;EAAA,QACA,YAAA;EAHA;EAAA,QAKA,YAAA;EA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QAEA,QAAA;EAAA,QACA,MAAA;EAEA;EAAA,QAAA,cAAA;EAGA;EAAA,QADA,gBAAA;EAAA,QACA,YAAA;EAAA,QACA,OAAA;cAEqB,MAAA,EAAQ,sBAAA;EAkCjC;EAAA,IAAA,OAAA,IAAW,WAAA;EAKf;EAAA,KAAA;EAWA;EALA,OAAA;EAaG;EARH,KAAA;EAQkB;;;;EAAlB,EAAA,CAAG,KAAA,UAAe,QAAA,EAAU,mBAAA;EAiEd;EAAA,QAxDN,WAAA;EAuHM;;;;;EAAA,QA3GN,QAAA;EAkQA;EAAA,QA1PA,IAAA;EAmSM;EAAA,QA/QN,OAAA;EAyUA;;;;;EAAA,QAzTM,eAAA;EAAA,QAuBN,QAAA;EAyYA;;;;;EAAA,QAjWM,SAAA;EAuaN;EAAA,QA5YA,aAAA;EA+ZA;EAAA,QA1ZM,YAAA;EA0ZF;;;;;EAAA,QA5YJ,eAAA;;;;;;;UAWM,WAAA;;;;;;;;;;;;UA8CN,SAAA;;;;;;UAgDA,eAAA;EAAA,QAWM,OAAA;;;;;;;UA8BA,KAAA;;;;;UAwCA,IAAA;EAAA,QAkBN,UAAA;;;;;;UAWA,YAAA;EAAA,QAOA,MAAA;;;;;;;UAwBM,SAAA;;UAYA,aAAA;;;;;;UAWA,aAAA;;;;;;;;UAyBN,SAAA;EAAA,QAaA,IAAA;EAAA,QAQA,KAAA;;UAKM,GAAA;EAAA,QAQN,IAAA;;UAwBA,SAAA;EAAA,QAMA,YAAA;EAAA,QAmBA,WAAA;;UAaA,gBAAA;EAAA,QAMA,IAAA;AAAA"}
|
package/dist/controller.mjs
CHANGED
|
@@ -586,25 +586,33 @@ var WidgetController = class {
|
|
|
586
586
|
}
|
|
587
587
|
}
|
|
588
588
|
fail(error) {
|
|
589
|
-
if (this.settled) return;
|
|
589
|
+
if (this.settled || this.pendingError) return;
|
|
590
590
|
const err = error instanceof Error ? error : new Error(String(error));
|
|
591
|
+
this.pendingError = err;
|
|
591
592
|
this.step = "result";
|
|
592
593
|
this.view.render({
|
|
593
594
|
step: "result",
|
|
594
595
|
documentType: this.documentType,
|
|
595
596
|
errorMessage: err.message
|
|
596
597
|
});
|
|
597
|
-
this.
|
|
598
|
+
this.dispatch("error", this.errorData(err));
|
|
599
|
+
this.config.onError?.(err);
|
|
600
|
+
}
|
|
601
|
+
/** Event payload for a failure: the message plus the stable key/status when it's a typed API error. */
|
|
602
|
+
errorData(err) {
|
|
603
|
+
if (err instanceof WidgetApiError) return {
|
|
604
|
+
message: err.message,
|
|
605
|
+
status: err.status,
|
|
606
|
+
error: err.error
|
|
607
|
+
};
|
|
608
|
+
return { message: err.message };
|
|
598
609
|
}
|
|
599
610
|
finishResult() {
|
|
600
611
|
if (this.settled) return;
|
|
601
612
|
this.settled = true;
|
|
602
613
|
this.teardownRealtime();
|
|
603
|
-
if (this.pendingError) {
|
|
604
|
-
|
|
605
|
-
this.dispatch("error", { message: this.pendingError.message });
|
|
606
|
-
this.config.onError?.(this.pendingError);
|
|
607
|
-
} else if (this.result) {
|
|
614
|
+
if (this.pendingError) this.post("arkyc:error", { error: serializeError(this.pendingError) });
|
|
615
|
+
else if (this.result) {
|
|
608
616
|
this.post("arkyc:complete", { payload: this.result });
|
|
609
617
|
this.dispatch("complete", this.result);
|
|
610
618
|
this.config.onComplete?.(this.result);
|
package/dist/controller.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.mjs","names":[],"sources":["../src/controller.ts"],"sourcesContent":["import type {\n DocumentType,\n LivenessChallenge,\n LivenessMode,\n SessionTransitionEvent,\n VerificationStatus,\n WidgetResult,\n WidgetStep,\n WorkflowConfig,\n} from '@arkyc/types'\nimport { REALTIME_EVENT, workflowAddressConfig } from '@arkyc/types'\nimport { ArkycClient, type ClientHandoff, type ClientRealtime, type ClientSession, WidgetApiError } from './client'\nimport { Flow } from './flow'\nimport { Theme } from './theme'\nimport { WidgetView, type AddressFormData } from './ui'\nimport { isDesktopDevice } from './device'\nimport { renderQrSvg } from './qr'\nimport { createWidgetRealtimeClient, type WidgetRealtimeClient } from './realtime'\nimport type { BaseWidgetOptions, ViewHandlers, WidgetControllerConfig, WidgetEventListener } from './types'\n\n/** Per-step lead-in copy shown before each capture/liveness step. */\nconst STEP_INSTRUCTIONS: Partial<Record<WidgetStep, { title: string; body: string; cta?: string }>> = {\n front_capture: {\n title: 'Front of your document',\n body: 'Place the front of your ID flat and fully inside the frame. We’ll capture it automatically.',\n },\n back_capture: {\n title: 'Back of your document',\n body: 'Now turn your ID over and show the back, fully inside the frame.',\n },\n selfie_capture: {\n title: 'Take a selfie',\n body: 'Look straight at the camera in good light and hold still — we’ll capture it automatically.',\n },\n active_liveness: {\n title: 'Quick liveness check',\n body: 'Follow the on-screen prompts (such as turn your head, blink or smile). This confirms you’re really here.',\n },\n}\n\n/**\n * Drives the full verification flow: renders each screen via {@link WidgetView},\n * advances through {@link flow}, and calls the Client API at each step. Cosmetic\n * processing screens auto-advance; capture screens wait for an image. On a\n * terminal result it surfaces the outcome and (in hosted mode) posts\n * `arkyc:complete` / `arkyc:error` / `arkyc:close` to the parent window.\n */\n/**\n * Re-base the server-resolved project logo onto the API origin the widget is\n * actually talking to. The stored `logo_url` carries the API's own host, which a\n * handed-off phone cannot reach — it reaches the API through the absolute\n * `baseUrl` passed in the handoff link. Rewriting the origin (keeping the path)\n * makes the logo load on whatever device runs the widget. Only applied when\n * `baseUrl` is absolute; the integrator's own branding is never re-based.\n */\nfunction rebaseBrandingLogo<T extends { logo_url?: string | null }>(branding: T, baseUrl: string | undefined): T {\n const logo = branding.logo_url\n if (!logo || !baseUrl || !/^https?:\\/\\//i.test(baseUrl)) return branding\n try {\n const base = new URL(baseUrl)\n const resolved = new URL(logo, base)\n if (resolved.origin === base.origin) return branding\n return { ...branding, logo_url: `${base.origin}${resolved.pathname}${resolved.search}${resolved.hash}` }\n } catch {\n return branding\n }\n}\n\nexport class WidgetController {\n private readonly client: ArkycClient\n private readonly view: WidgetView\n private readonly win: Window\n private readonly nav: Navigator\n private readonly postToParent: boolean\n private readonly scheduler: (fn: () => void, ms: number) => void\n private readonly transientMs: number\n private readonly pollMs: number\n private readonly maxPolls: number\n private readonly maxHandoffPolls: number\n\n /** Cross-device handoff: project config + whether the offer/QR is showing. */\n private handoffConfig: ClientHandoff = { enabled: false, allow_desktop: true, url: '' }\n private handoffReady = false\n private handoffActive = false\n\n /** This session's id + how to watch it live (push transport vs. polling). */\n private sessionId = ''\n private realtimeConfig: ClientRealtime | null = null\n private rtClient: WidgetRealtimeClient | null = null\n private rtResolved = false\n /** The last status observed, so a transition only emits once per change. */\n private lastStatus: VerificationStatus | null = null\n /** Per-name event listeners registered via {@link on}. */\n private listeners = new Map<string, Set<WidgetEventListener>>()\n /** Cancels the active session watch (e.g. continue-on-this-device). */\n private stopWatch: (() => void) | undefined\n\n private step: WidgetStep = 'welcome'\n private documentType: DocumentType | null = null\n private country: string | null = null\n private selfie: Blob | null = null\n private livenessMode: LivenessMode = 'passive'\n /** The session's capture model; `active` mandates a live camera (no fallback). */\n private captureModel: 'passive' | 'active' | 'both' = 'passive'\n private livenessChallenges: LivenessChallenge[] = []\n /** The address-entry form data, captured before the address submission. */\n private addressData: AddressFormData | null = null\n /** Device coordinates resolved on the address step (when the user opts in). */\n private addressCoords: { latitude: number; longitude: number } | null = null\n /** The applied workflow (orders/toggles stages, skip_ocr), or null for the default flow. */\n private workflow: WorkflowConfig | null = null\n private result: WidgetResult | null = null\n /** The session was already terminal when the widget loaded (show a close-only notice). */\n private terminalOnLoad = false\n /** Whether the current step's instruction interstitial has been acknowledged. */\n private instructionAcked = false\n private pendingError: Error | null = null\n private settled = false\n\n constructor(private readonly config: WidgetControllerConfig) {\n const doc = config.doc ?? globalThis.document\n const win = config.win ?? globalThis.window\n if (!doc || !win) throw new Error('The Arkyc widget must run in a browser environment.')\n this.win = win\n this.nav = config.nav ?? globalThis.navigator\n\n this.client = new ArkycClient({\n token: config.token,\n baseUrl: config.baseUrl,\n fetch: config.fetch,\n })\n const theme = new Theme(config.branding)\n this.view = new WidgetView(\n doc,\n theme,\n this.handlers(),\n config.nav ?? globalThis.navigator,\n config.faceAnalyzer,\n config.faceTuning,\n config.documentAnalyzer,\n config.documentTuning,\n )\n\n this.postToParent = config.postToParent ?? (!!win.parent && win.parent !== win)\n this.scheduler = config.scheduler ?? ((fn, ms) => setTimeout(fn, ms))\n this.transientMs = config.transientMs ?? 700\n this.pollMs = config.pollMs ?? 1500\n this.maxPolls = config.maxPolls ?? 40\n // A handed-off session is bounded by its TTL (~15 min); poll generously.\n this.maxHandoffPolls = config.maxHandoffPolls ?? 600\n }\n\n /** The widget's root element — append it to an overlay or inline container. */\n get element(): HTMLElement {\n return this.view.element\n }\n\n /** Connect to the session, then route to the result, the QR, or the welcome flow. */\n start(): void {\n this.view.renderLoading()\n void this.run(() => this.bootstrap())\n }\n\n /** Tear down the view and release the camera (does not fire callbacks). */\n destroy(): void {\n this.view.destroy()\n }\n\n /** Close the widget as if the user dismissed it (fires `onClose`/`onSettle`). */\n close(): void {\n this.finishClose()\n }\n\n /**\n * Subscribe to a named widget event; returns an unsubscribe function. Having a\n * listener (here or via `onEvent`) is what activates the event stream.\n */\n on(event: string, listener: WidgetEventListener): () => void {\n const set = this.listeners.get(event) ?? new Set<WidgetEventListener>()\n set.add(listener)\n this.listeners.set(event, set)\n\n return () => set.delete(listener)\n }\n\n /** Whether anyone is listening for `name` (the firehose or a named listener). */\n private hasListener(name: string): boolean {\n if (this.config.onEvent) return true\n const set = this.listeners.get(name)\n\n return !!set && set.size > 0\n }\n\n /**\n * Surface an event: to local listeners (firehose + `on`), and — in hosted\n * iframe mode — to the embedding parent as `arkyc:event` so the SDK's\n * `handle.on(...)` works across the frame.\n */\n private dispatch(name: string, data?: unknown): void {\n this.emit(name, data)\n // The parent window is the consumer in iframe mode, so forwarding there isn't\n // gated on a local listener (post() already no-ops when not embedding).\n this.post('arkyc:event', { name, data })\n }\n\n /** Emit an event to the firehose + named listeners — but only if one is active. */\n private emit(name: string, data?: unknown): void {\n if (!this.hasListener(name)) return\n try {\n this.config.onEvent?.({ name, data })\n } catch {\n // A consumer callback threw — never let it break the flow.\n }\n const set = this.listeners.get(name)\n if (set) {\n for (const listener of [...set]) {\n try {\n listener(data)\n } catch {\n // ditto\n }\n }\n }\n }\n\n /** Record an observed status, emitting `session.transition` on a real change. */\n private observe(status: VerificationStatus): void {\n if (status === this.lastStatus) return\n const previous = this.lastStatus\n this.lastStatus = status\n this.dispatch(REALTIME_EVENT.sessionTransition, {\n session_id: this.sessionId,\n status,\n previous_status: previous,\n } satisfies Partial<SessionTransitionEvent>)\n }\n\n /**\n * Lazily connect the push transport for this session (once). Returns null for\n * `polling`/`off`/`memory` or when the transport SDK can't load — the caller\n * then polls instead.\n */\n private async resolveRealtime(): Promise<WidgetRealtimeClient | null> {\n if (this.rtResolved) return this.rtClient\n this.rtResolved = true\n const cfg = this.realtimeConfig\n if (!cfg || cfg.transport === 'polling' || cfg.transport === 'off' || cfg.transport === 'memory') return null\n\n const factory = this.config.realtimeFactory ?? createWidgetRealtimeClient\n // Build from the client's *resolved* base (absolute/proxy value, or the\n // hosted default when `baseUrl` was omitted) — never the raw option, which\n // is empty in the zero-config case and would resolve against the page origin.\n const apiBase = this.client.base\n try {\n this.rtClient = await factory(cfg, {\n authEndpoint: `${apiBase}/realtime/auth`,\n token: this.config.token,\n })\n } catch {\n this.rtClient = null\n }\n\n return this.rtClient\n }\n\n private handlers(): ViewHandlers {\n return {\n onClose: () => this.finishClose(),\n // The session was already fetched + resolved during bootstrap; just advance.\n onStart: () => void this.run(() => this.enter(this.next())),\n onDocumentSelected: (type, country) => {\n this.documentType = type\n this.country = country || null\n void this.run(() => this.enter('front_capture'))\n },\n onImage: (blob) => void this.run(() => this.onImage(blob)),\n onActiveLiveness: (video, performed, selfie) =>\n void this.run(async () => {\n await this.client.submitLiveness({\n selfie,\n video,\n mode: 'active',\n challenges: performed,\n signals: this.config.signals,\n })\n await this.enter(this.next())\n }),\n onAddress: (data) => void this.run(() => this.onAddress(data)),\n onShareLocation: () => this.shareLocation(),\n onAcknowledge: () => this.finishResult(),\n onUsePhone: () => void this.run(() => this.startHandoff()),\n onContinueHere: () => {\n this.handoffActive = false\n this.stopWatch?.()\n this.step = 'welcome'\n this.render()\n },\n }\n }\n\n /**\n * Fetch the session and route: an already-terminal session (e.g. a stale handoff\n * link, or one finished on another device) shows a close-only notice; on a\n * desktop with handoff enabled we lead with the QR; otherwise the welcome flow.\n */\n private async bootstrap(): Promise<void> {\n if (this.settled) return\n const session = await this.client.getSession()\n if (this.settled) return\n this.sessionId = session.id\n this.realtimeConfig = session.realtime ?? null\n this.workflow = session.workflow ?? null\n // Theme from the project's branding (server-resolved) unless the integrator\n // passed branding explicitly — their value wins.\n if (this.config.branding == null && session.branding)\n this.view.applyBranding(rebaseBrandingLogo(session.branding, this.config.baseUrl))\n this.observe(session.status)\n if (Flow.isTerminal(session.status)) return this.showTerminal(session.status)\n this.resolveLiveness(session)\n if (session.handoff) this.handoffConfig = session.handoff\n const canHandoff =\n this.config.handoff !== false && isDesktopDevice(this.nav) && this.handoffConfig.enabled && !!this.handoffTarget()\n if (canHandoff) {\n this.handoffReady = true\n await this.startHandoff()\n } else {\n this.step = 'welcome'\n this.render()\n }\n }\n\n /** The hosted handoff page URL: a consumer override, else the server-provided one. */\n private handoffTarget(): string {\n return (this.config.handoffUrl ?? this.handoffConfig.url ?? '').trim()\n }\n\n /** Render the QR for this session and wait for the other device to finish. */\n private async startHandoff(): Promise<void> {\n const target = this.handoffTarget()\n if (!target) return\n this.handoffActive = true\n // Offer \"continue on this device\" only when the project permits it.\n this.view.renderHandoff(renderQrSvg(this.buildHandoffUrl(target)), this.handoffConfig.allow_desktop)\n await this.pollHandoff()\n }\n\n /** Build the hosted-page URL the QR encodes (carries the session token).\n *\n * @param target\n * @returns\n */\n private buildHandoffUrl(target: string): string {\n const pageOrigin = this.win.location?.origin ?? globalThis.location?.origin ?? ''\n return composeHandoffUrl(target, this.config.token, this.client.base, pageOrigin)\n }\n\n /**\n * Watch the session while the user verifies on the other\n * device; mirror the result.\n *\n * @returns\n */\n private async pollHandoff(): Promise<void> {\n const rt = await this.resolveRealtime()\n if (rt) {\n const status = await this.pushWatch(rt, this.maxHandoffPolls, () => this.handoffActive && !this.settled)\n if (status) {\n this.handoffActive = false\n return this.showResult(status)\n }\n\n return // cancelled (continue here) or budget elapsed → the QR persists\n }\n\n let errors = 0\n for (let i = 0; i < this.maxHandoffPolls && this.handoffActive && !this.settled; i++) {\n await this.delay(this.pollMs)\n if (!this.handoffActive || this.settled) return\n try {\n const session = await this.client.getSession()\n errors = 0\n this.observe(session.status)\n if (Flow.isTerminal(session.status)) {\n this.handoffActive = false\n return this.showResult(session.status)\n }\n } catch (error) {\n // The session/token can expire mid-wait (401) — stop and reflect that.\n if (error instanceof WidgetApiError && error.status === 401) {\n this.handoffActive = false\n return this.showResult('expired')\n }\n if (++errors >= 5) return\n }\n }\n }\n\n /**\n * Await a terminal status over the push transport. Resolves to the terminal\n * status, or null if `active()` went false or the tick budget elapsed (push can\n * miss events / disconnect; the budget bounds the wait). An initial fetch\n * catches a session that finished before we subscribed.\n *\n * @param rt\n * @param budget\n * @param active\n * @returns\n */\n private pushWatch(\n rt: WidgetRealtimeClient,\n budget: number,\n active: () => boolean,\n ): Promise<VerificationStatus | null> {\n return new Promise((resolve) => {\n let done = false\n const finish = (status: VerificationStatus | null) => {\n if (done) return\n done = true\n this.stopWatch = undefined\n unsubscribe()\n resolve(status)\n }\n const channel = this.realtimeConfig!.channel\n const unsubscribe = rt.subscribe(channel, (event, data) => {\n if (event !== REALTIME_EVENT.sessionTransition) return\n const status = (data as SessionTransitionEvent).status\n this.observe(status)\n if (Flow.isTerminal(status)) finish(status)\n })\n this.stopWatch = () => finish(null)\n // Catch a race where the session already finished before we subscribed.\n void this.client\n .getSession()\n .then((session) => {\n this.observe(session.status)\n if (Flow.isTerminal(session.status)) finish(session.status)\n })\n .catch((error) => {\n if (error instanceof WidgetApiError && error.status === 401) finish('expired')\n })\n // Bound the wait by the same tick budget the poller would use.\n const countdown = async (n: number): Promise<void> => {\n if (done) return\n if (!active() || n >= budget) return finish(null)\n await this.delay(this.pollMs)\n void countdown(n + 1)\n }\n void countdown(0)\n })\n }\n\n /**\n * Resolve which liveness flow to run from the session's capture model.\n *\n * @param session\n */\n private resolveLiveness(session: ClientSession): void {\n this.livenessChallenges = session.liveness_challenges ?? []\n const model = session.capture_model ?? 'passive'\n this.captureModel = model\n const wantsActive = model === 'active' || model === 'both'\n // `active` is honoured even without a live camera — the active-liveness\n // screen then shows the device as unsupported (no fallback). `both` falls\n // back to passive when the camera/recorder isn't available.\n this.livenessMode = wantsActive && (model === 'active' || this.view.cameraSupported) ? 'active' : 'passive'\n }\n\n private async onImage(blob: Blob | null): Promise<void> {\n const signals = this.config.signals\n switch (this.step) {\n case 'front_capture':\n await this.client.submitDocumentFront({\n image: blob,\n country: this.country,\n documentType: this.documentType,\n signals,\n })\n return this.enter(this.next())\n case 'back_capture':\n await this.client.submitDocumentBack({\n image: blob,\n country: this.country,\n documentType: this.documentType,\n })\n return this.enter('ocr_processing')\n case 'selfie_capture':\n this.selfie = blob\n return this.enter('passive_liveness')\n }\n }\n\n /**\n * Enter a step: render it, and drive any automatic (processing) work.\n *\n * @param step\n * @returns\n */\n private async enter(step: WidgetStep): Promise<void> {\n if (this.settled) return\n this.step = step\n\n // Lead each capture/liveness step with an instruction screen so the user\n // knows what's next and starts it deliberately. The Continue button re-enters\n // the same step with the instruction acknowledged.\n const instruction = STEP_INSTRUCTIONS[step]\n if (instruction && !this.instructionAcked) {\n this.view.renderInstruction(step, instruction.title, instruction.body, instruction.cta ?? 'Continue', () => {\n this.instructionAcked = true\n void this.run(() => this.enter(step))\n })\n return\n }\n this.instructionAcked = false\n this.render()\n\n switch (step) {\n case 'ocr_processing':\n await this.delay(this.transientMs)\n return this.enter(this.next())\n case 'address_processing':\n await this.submitAddress()\n return this.enter(this.next())\n case 'passive_liveness':\n await this.client.submitLiveness({ selfie: this.selfie, signals: this.config.signals })\n return this.enter(this.next())\n case 'face_match':\n await this.client.complete({ signals: this.config.signals })\n return this.enter(this.next())\n case 'processing':\n return this.poll()\n }\n }\n\n /** Watch the session until it reaches a terminal status (then show the result).\n *\n * @returns\n */\n private async poll(): Promise<void> {\n const rt = await this.resolveRealtime()\n if (rt) {\n const status = await this.pushWatch(rt, this.maxPolls, () => !this.settled)\n\n return this.showResult(status ?? 'requires_review')\n }\n\n for (let i = 0; i < this.maxPolls && !this.settled; i++) {\n const session = await this.client.getSession()\n this.observe(session.status)\n if (Flow.isTerminal(session.status)) return this.showResult(session.status)\n await this.delay(this.pollMs)\n }\n // Still processing after the poll budget — surface as pending review.\n this.showResult('requires_review')\n }\n\n private showResult(status: VerificationStatus): void {\n this.result = { status, decision: Flow.statusToDecision(status) }\n this.step = 'result'\n this.render()\n }\n\n /**\n * A session that was already terminal on load: a notice with only a Close button.\n *\n * @param status\n */\n private showTerminal(status: VerificationStatus): void {\n this.result = { status, decision: Flow.statusToDecision(status) }\n this.step = 'result'\n this.terminalOnLoad = true\n this.render()\n }\n\n private render(): void {\n this.view.render({\n step: this.step,\n documentType: this.documentType,\n decision: this.result?.decision,\n status: this.result?.status,\n terminalNotice: this.terminalOnLoad,\n allowSkip: !!this.config.signals,\n livenessChallenges: this.livenessChallenges,\n requireLiveCamera: this.captureModel === 'active',\n // The active flow is strict end-to-end: documents must be detected, not\n // manually waved through.\n strictCapture: this.livenessMode === 'active',\n handoffAvailable: this.handoffReady,\n addressMethods: workflowAddressConfig(this.workflow)?.methods ?? [],\n })\n }\n\n /**\n * Store the entered address, resolve device location if opted in, then verify.\n *\n * @param data\n * @returns\n */\n private async onAddress(data: AddressFormData): Promise<void> {\n this.addressData = data\n // Coordinates are normally resolved up front by `shareLocation` when the user\n // ticks \"use my location\" (so the prompt is immediate); geolocate here only as\n // a fallback, and clear them if they opted out.\n if (!data.useLocation) this.addressCoords = null\n else if (!this.addressCoords) this.addressCoords = await this.geolocate()\n\n return this.enter('address_processing')\n }\n\n /** Request the device's location (from the address-entry \"use my location\" opt-in). */\n private async shareLocation(): Promise<boolean> {\n this.addressCoords = await this.geolocate()\n\n return !!this.addressCoords\n }\n\n /**\n * Submit the captured address evidence to the Client API.\n *\n * @returns\n */\n private async submitAddress(): Promise<void> {\n const data = this.addressData\n if (!data) return\n\n await this.client.submitAddress({\n line1: data.line1,\n line2: data.line2,\n city: data.city,\n region: data.region,\n postalCode: data.postalCode,\n country: data.country,\n poa: data.poa,\n latitude: this.addressCoords?.latitude ?? null,\n longitude: this.addressCoords?.longitude ?? null,\n signals: this.config.signals,\n })\n }\n\n /**\n * Resolve the device's coordinates via the Geolocation API. Resolves to `null`\n * on denial/unavailability/timeout — the `device_location` method then simply\n * has no coordinates to check (routing the session to review).\n *\n * @returns\n */\n private geolocate(): Promise<{ latitude: number; longitude: number } | null> {\n const geo = this.nav?.geolocation\n if (!geo) return Promise.resolve(null)\n\n return new Promise((resolve) => {\n geo.getCurrentPosition(\n (pos) => resolve({ latitude: pos.coords.latitude, longitude: pos.coords.longitude }),\n () => resolve(null),\n { enableHighAccuracy: false, timeout: 10_000, maximumAge: 60_000 },\n )\n })\n }\n\n private next(): WidgetStep {\n return Flow.nextStep(this.step, {\n documentType: this.documentType,\n livenessMode: this.livenessMode,\n workflow: this.workflow,\n })\n }\n\n private delay(ms: number): Promise<void> {\n return new Promise((resolve) => this.scheduler(resolve, ms))\n }\n\n /** Run an async step, routing any failure to the error screen. */\n private async run(fn: () => Promise<void> | void): Promise<void> {\n try {\n await fn()\n } catch (error) {\n this.fail(error)\n }\n }\n\n private fail(error: unknown): void {\n if (this.settled) return\n const err = error instanceof Error ? error : new Error(String(error))\n this.step = 'result'\n\n this.view.render({\n step: 'result',\n documentType: this.documentType,\n errorMessage: err.message,\n })\n\n this.pendingError = err\n }\n\n private finishResult(): void {\n if (this.settled) return\n this.settled = true\n this.teardownRealtime()\n\n if (this.pendingError) {\n this.post('arkyc:error', { error: serializeError(this.pendingError) })\n this.dispatch('error', { message: this.pendingError.message })\n this.config.onError?.(this.pendingError)\n } else if (this.result) {\n this.post('arkyc:complete', { payload: this.result })\n this.dispatch('complete', this.result)\n this.config.onComplete?.(this.result)\n }\n\n this.destroy()\n this.config.onSettle?.()\n }\n\n private finishClose(): void {\n if (this.settled) return\n\n this.settled = true\n this.teardownRealtime()\n this.post('arkyc:close', {})\n this.dispatch('close')\n this.config.onClose?.()\n this.destroy()\n this.config.onSettle?.()\n }\n\n /** Stop any active session watch + disconnect the push transport. */\n private teardownRealtime(): void {\n this.stopWatch?.()\n this.rtClient?.disconnect()\n this.rtClient = null\n }\n\n private post(type: string, extra: Record<string, unknown>): void {\n if (!this.postToParent) return\n try {\n this.win.parent?.postMessage({ type, ...extra }, '*')\n } catch {\n // Cross-origin parent without access — nothing more we can do.\n }\n }\n}\n\nfunction serializeError(error: Error): { message: string; name: string } {\n return { message: error.message, name: error.name }\n}\n\n/** The origin of an absolute URL, or '' when it can't be parsed. */\nfunction originOf(url: string): string {\n try {\n return new URL(url).origin\n } catch {\n return ''\n }\n}\n\n/**\n * Build the hosted-page URL the handoff QR encodes: always the `target` page\n * plus the session `token`, and the API base **only when the phone can actually\n * reach it** — i.e. a genuine cross-origin base. `apiBase` is the widget's\n * resolved Client API base (always origin-qualified), so a relative proxy\n * resolves to the desktop's own `pageOrigin` and is skipped (the hosted page\n * then falls back to its own default base instead of a URL the phone can't use).\n */\nexport const composeHandoffUrl = (target: string, token: string, apiBase: string, pageOrigin: string): string => {\n const sep = target.includes('?') ? '&' : '?'\n let url = `${target}${sep}token=${encodeURIComponent(token)}`\n const baseOrigin = originOf(apiBase)\n if (baseOrigin && baseOrigin !== pageOrigin) url += `&baseUrl=${encodeURIComponent(apiBase)}`\n return url\n}\n\nexport const resolveContainer = (container: string | HTMLElement, doc: Document): HTMLElement => {\n const el = typeof container === 'string' ? doc.querySelector<HTMLElement>(container) : container\n if (!el) throw new Error(`ArkycWidget.mount: container \"${String(container)}\" not found.`)\n return el\n}\n\n/**\n * Make an inline mount point a reliable host for the widget, so `mount()` renders\n * predictably regardless of the page layout — a static or zero-height container,\n * or one sharing the viewport with an app root that would otherwise paint over it.\n *\n * The widget gives the host its own stacking context and lifts it above sibling\n * app content, the way `open()` owns its overlay. Each property is only set when\n * the host hasn't already committed to one (checked against computed style where\n * available, else inline style), so an embed that wants normal flow or a specific\n * layer can still override it with its own CSS.\n */\nexport const adoptContainer = (container: HTMLElement, doc: Document): void => {\n const computed = doc.defaultView?.getComputedStyle?.(container)\n const position = computed?.position ?? container.style.position\n if (!position || position === 'static') container.style.position = 'relative'\n\n const zIndex = computed?.zIndex ?? container.style.zIndex\n if (!zIndex || zIndex === 'auto') container.style.zIndex = '1'\n\n // A self-contained stacking context keeps the widget's layers from bleeding\n // into (or being clipped by) the surrounding page.\n if (!container.style.isolation) container.style.isolation = 'isolate'\n}\n\nexport const buildController = (options: BaseWidgetOptions, onSettle: () => void): WidgetController => {\n if (!options.token) throw new Error('ArkycWidget requires a client `token`.')\n return new WidgetController({\n token: options.token,\n baseUrl: options.baseUrl,\n handoff: options.handoff,\n handoffUrl: options.handoffUrl,\n branding: options.branding,\n signals: options.signals,\n onComplete: options.onComplete,\n onError: options.onError,\n onClose: options.onClose,\n onEvent: options.onEvent,\n onSettle,\n fetch: options.fetch,\n doc: options.doc,\n win: options.win,\n nav: options.nav,\n faceAnalyzer: options.faceAnalyzer,\n faceTuning: options.faceTuning,\n documentAnalyzer: options.documentAnalyzer,\n documentTuning: options.documentTuning,\n })\n}\n"],"mappings":";;;;;;;;;;AAqBA,MAAM,oBAAgG;CACpG,eAAe;EACb,OAAO;EACP,MAAM;CACR;CACA,cAAc;EACZ,OAAO;EACP,MAAM;CACR;CACA,gBAAgB;EACd,OAAO;EACP,MAAM;CACR;CACA,iBAAiB;EACf,OAAO;EACP,MAAM;CACR;AACF;;;;;;;;;;;;;;;;AAiBA,SAAS,mBAA2D,UAAa,SAA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LivenessMode,\n SessionTransitionEvent,\n VerificationStatus,\n WidgetResult,\n WidgetStep,\n WorkflowConfig,\n} from '@arkyc/types'\nimport { REALTIME_EVENT, workflowAddressConfig } from '@arkyc/types'\nimport { ArkycClient, type ClientHandoff, type ClientRealtime, type ClientSession, WidgetApiError } from './client'\nimport { Flow } from './flow'\nimport { Theme } from './theme'\nimport { WidgetView, type AddressFormData } from './ui'\nimport { isDesktopDevice } from './device'\nimport { renderQrSvg } from './qr'\nimport { createWidgetRealtimeClient, type WidgetRealtimeClient } from './realtime'\nimport type { BaseWidgetOptions, ViewHandlers, WidgetControllerConfig, WidgetEventListener } from './types'\n\n/** Per-step lead-in copy shown before each capture/liveness step. */\nconst STEP_INSTRUCTIONS: Partial<Record<WidgetStep, { title: string; body: string; cta?: string }>> = {\n front_capture: {\n title: 'Front of your document',\n body: 'Place the front of your ID flat and fully inside the frame. We’ll capture it automatically.',\n },\n back_capture: {\n title: 'Back of your document',\n body: 'Now turn your ID over and show the back, fully inside the frame.',\n },\n selfie_capture: {\n title: 'Take a selfie',\n body: 'Look straight at the camera in good light and hold still — we’ll capture it automatically.',\n },\n active_liveness: {\n title: 'Quick liveness check',\n body: 'Follow the on-screen prompts (such as turn your head, blink or smile). This confirms you’re really here.',\n },\n}\n\n/**\n * Drives the full verification flow: renders each screen via {@link WidgetView},\n * advances through {@link flow}, and calls the Client API at each step. Cosmetic\n * processing screens auto-advance; capture screens wait for an image. On a\n * terminal result it surfaces the outcome and (in hosted mode) posts\n * `arkyc:complete` / `arkyc:error` / `arkyc:close` to the parent window.\n */\n/**\n * Re-base the server-resolved project logo onto the API origin the widget is\n * actually talking to. The stored `logo_url` carries the API's own host, which a\n * handed-off phone cannot reach — it reaches the API through the absolute\n * `baseUrl` passed in the handoff link. Rewriting the origin (keeping the path)\n * makes the logo load on whatever device runs the widget. Only applied when\n * `baseUrl` is absolute; the integrator's own branding is never re-based.\n */\nfunction rebaseBrandingLogo<T extends { logo_url?: string | null }>(branding: T, baseUrl: string | undefined): T {\n const logo = branding.logo_url\n if (!logo || !baseUrl || !/^https?:\\/\\//i.test(baseUrl)) return branding\n try {\n const base = new URL(baseUrl)\n const resolved = new URL(logo, base)\n if (resolved.origin === base.origin) return branding\n return { ...branding, logo_url: `${base.origin}${resolved.pathname}${resolved.search}${resolved.hash}` }\n } catch {\n return branding\n }\n}\n\nexport class WidgetController {\n private readonly client: ArkycClient\n private readonly view: WidgetView\n private readonly win: Window\n private readonly nav: Navigator\n private readonly postToParent: boolean\n private readonly scheduler: (fn: () => void, ms: number) => void\n private readonly transientMs: number\n private readonly pollMs: number\n private readonly maxPolls: number\n private readonly maxHandoffPolls: number\n\n /** Cross-device handoff: project config + whether the offer/QR is showing. */\n private handoffConfig: ClientHandoff = { enabled: false, allow_desktop: true, url: '' }\n private handoffReady = false\n private handoffActive = false\n\n /** This session's id + how to watch it live (push transport vs. polling). */\n private sessionId = ''\n private realtimeConfig: ClientRealtime | null = null\n private rtClient: WidgetRealtimeClient | null = null\n private rtResolved = false\n /** The last status observed, so a transition only emits once per change. */\n private lastStatus: VerificationStatus | null = null\n /** Per-name event listeners registered via {@link on}. */\n private listeners = new Map<string, Set<WidgetEventListener>>()\n /** Cancels the active session watch (e.g. continue-on-this-device). */\n private stopWatch: (() => void) | undefined\n\n private step: WidgetStep = 'welcome'\n private documentType: DocumentType | null = null\n private country: string | null = null\n private selfie: Blob | null = null\n private livenessMode: LivenessMode = 'passive'\n /** The session's capture model; `active` mandates a live camera (no fallback). */\n private captureModel: 'passive' | 'active' | 'both' = 'passive'\n private livenessChallenges: LivenessChallenge[] = []\n /** The address-entry form data, captured before the address submission. */\n private addressData: AddressFormData | null = null\n /** Device coordinates resolved on the address step (when the user opts in). */\n private addressCoords: { latitude: number; longitude: number } | null = null\n /** The applied workflow (orders/toggles stages, skip_ocr), or null for the default flow. */\n private workflow: WorkflowConfig | null = null\n private result: WidgetResult | null = null\n /** The session was already terminal when the widget loaded (show a close-only notice). */\n private terminalOnLoad = false\n /** Whether the current step's instruction interstitial has been acknowledged. */\n private instructionAcked = false\n private pendingError: Error | null = null\n private settled = false\n\n constructor(private readonly config: WidgetControllerConfig) {\n const doc = config.doc ?? globalThis.document\n const win = config.win ?? globalThis.window\n if (!doc || !win) throw new Error('The Arkyc widget must run in a browser environment.')\n this.win = win\n this.nav = config.nav ?? globalThis.navigator\n\n this.client = new ArkycClient({\n token: config.token,\n baseUrl: config.baseUrl,\n fetch: config.fetch,\n })\n const theme = new Theme(config.branding)\n this.view = new WidgetView(\n doc,\n theme,\n this.handlers(),\n config.nav ?? globalThis.navigator,\n config.faceAnalyzer,\n config.faceTuning,\n config.documentAnalyzer,\n config.documentTuning,\n )\n\n this.postToParent = config.postToParent ?? (!!win.parent && win.parent !== win)\n this.scheduler = config.scheduler ?? ((fn, ms) => setTimeout(fn, ms))\n this.transientMs = config.transientMs ?? 700\n this.pollMs = config.pollMs ?? 1500\n this.maxPolls = config.maxPolls ?? 40\n // A handed-off session is bounded by its TTL (~15 min); poll generously.\n this.maxHandoffPolls = config.maxHandoffPolls ?? 600\n }\n\n /** The widget's root element — append it to an overlay or inline container. */\n get element(): HTMLElement {\n return this.view.element\n }\n\n /** Connect to the session, then route to the result, the QR, or the welcome flow. */\n start(): void {\n this.view.renderLoading()\n void this.run(() => this.bootstrap())\n }\n\n /** Tear down the view and release the camera (does not fire callbacks). */\n destroy(): void {\n this.view.destroy()\n }\n\n /** Close the widget as if the user dismissed it (fires `onClose`/`onSettle`). */\n close(): void {\n this.finishClose()\n }\n\n /**\n * Subscribe to a named widget event; returns an unsubscribe function. Having a\n * listener (here or via `onEvent`) is what activates the event stream.\n */\n on(event: string, listener: WidgetEventListener): () => void {\n const set = this.listeners.get(event) ?? new Set<WidgetEventListener>()\n set.add(listener)\n this.listeners.set(event, set)\n\n return () => set.delete(listener)\n }\n\n /** Whether anyone is listening for `name` (the firehose or a named listener). */\n private hasListener(name: string): boolean {\n if (this.config.onEvent) return true\n const set = this.listeners.get(name)\n\n return !!set && set.size > 0\n }\n\n /**\n * Surface an event: to local listeners (firehose + `on`), and — in hosted\n * iframe mode — to the embedding parent as `arkyc:event` so the SDK's\n * `handle.on(...)` works across the frame.\n */\n private dispatch(name: string, data?: unknown): void {\n this.emit(name, data)\n // The parent window is the consumer in iframe mode, so forwarding there isn't\n // gated on a local listener (post() already no-ops when not embedding).\n this.post('arkyc:event', { name, data })\n }\n\n /** Emit an event to the firehose + named listeners — but only if one is active. */\n private emit(name: string, data?: unknown): void {\n if (!this.hasListener(name)) return\n try {\n this.config.onEvent?.({ name, data })\n } catch {\n // A consumer callback threw — never let it break the flow.\n }\n const set = this.listeners.get(name)\n if (set) {\n for (const listener of [...set]) {\n try {\n listener(data)\n } catch {\n // ditto\n }\n }\n }\n }\n\n /** Record an observed status, emitting `session.transition` on a real change. */\n private observe(status: VerificationStatus): void {\n if (status === this.lastStatus) return\n const previous = this.lastStatus\n this.lastStatus = status\n this.dispatch(REALTIME_EVENT.sessionTransition, {\n session_id: this.sessionId,\n status,\n previous_status: previous,\n } satisfies Partial<SessionTransitionEvent>)\n }\n\n /**\n * Lazily connect the push transport for this session (once). Returns null for\n * `polling`/`off`/`memory` or when the transport SDK can't load — the caller\n * then polls instead.\n */\n private async resolveRealtime(): Promise<WidgetRealtimeClient | null> {\n if (this.rtResolved) return this.rtClient\n this.rtResolved = true\n const cfg = this.realtimeConfig\n if (!cfg || cfg.transport === 'polling' || cfg.transport === 'off' || cfg.transport === 'memory') return null\n\n const factory = this.config.realtimeFactory ?? createWidgetRealtimeClient\n // Build from the client's *resolved* base (absolute/proxy value, or the\n // hosted default when `baseUrl` was omitted) — never the raw option, which\n // is empty in the zero-config case and would resolve against the page origin.\n const apiBase = this.client.base\n try {\n this.rtClient = await factory(cfg, {\n authEndpoint: `${apiBase}/realtime/auth`,\n token: this.config.token,\n })\n } catch {\n this.rtClient = null\n }\n\n return this.rtClient\n }\n\n private handlers(): ViewHandlers {\n return {\n onClose: () => this.finishClose(),\n // The session was already fetched + resolved during bootstrap; just advance.\n onStart: () => void this.run(() => this.enter(this.next())),\n onDocumentSelected: (type, country) => {\n this.documentType = type\n this.country = country || null\n void this.run(() => this.enter('front_capture'))\n },\n onImage: (blob) => void this.run(() => this.onImage(blob)),\n onActiveLiveness: (video, performed, selfie) =>\n void this.run(async () => {\n await this.client.submitLiveness({\n selfie,\n video,\n mode: 'active',\n challenges: performed,\n signals: this.config.signals,\n })\n await this.enter(this.next())\n }),\n onAddress: (data) => void this.run(() => this.onAddress(data)),\n onShareLocation: () => this.shareLocation(),\n onAcknowledge: () => this.finishResult(),\n onUsePhone: () => void this.run(() => this.startHandoff()),\n onContinueHere: () => {\n this.handoffActive = false\n this.stopWatch?.()\n this.step = 'welcome'\n this.render()\n },\n }\n }\n\n /**\n * Fetch the session and route: an already-terminal session (e.g. a stale handoff\n * link, or one finished on another device) shows a close-only notice; on a\n * desktop with handoff enabled we lead with the QR; otherwise the welcome flow.\n */\n private async bootstrap(): Promise<void> {\n if (this.settled) return\n const session = await this.client.getSession()\n if (this.settled) return\n this.sessionId = session.id\n this.realtimeConfig = session.realtime ?? null\n this.workflow = session.workflow ?? null\n // Theme from the project's branding (server-resolved) unless the integrator\n // passed branding explicitly — their value wins.\n if (this.config.branding == null && session.branding)\n this.view.applyBranding(rebaseBrandingLogo(session.branding, this.config.baseUrl))\n this.observe(session.status)\n if (Flow.isTerminal(session.status)) return this.showTerminal(session.status)\n this.resolveLiveness(session)\n if (session.handoff) this.handoffConfig = session.handoff\n const canHandoff =\n this.config.handoff !== false && isDesktopDevice(this.nav) && this.handoffConfig.enabled && !!this.handoffTarget()\n if (canHandoff) {\n this.handoffReady = true\n await this.startHandoff()\n } else {\n this.step = 'welcome'\n this.render()\n }\n }\n\n /** The hosted handoff page URL: a consumer override, else the server-provided one. */\n private handoffTarget(): string {\n return (this.config.handoffUrl ?? this.handoffConfig.url ?? '').trim()\n }\n\n /** Render the QR for this session and wait for the other device to finish. */\n private async startHandoff(): Promise<void> {\n const target = this.handoffTarget()\n if (!target) return\n this.handoffActive = true\n // Offer \"continue on this device\" only when the project permits it.\n this.view.renderHandoff(renderQrSvg(this.buildHandoffUrl(target)), this.handoffConfig.allow_desktop)\n await this.pollHandoff()\n }\n\n /** Build the hosted-page URL the QR encodes (carries the session token).\n *\n * @param target\n * @returns\n */\n private buildHandoffUrl(target: string): string {\n const pageOrigin = this.win.location?.origin ?? globalThis.location?.origin ?? ''\n return composeHandoffUrl(target, this.config.token, this.client.base, pageOrigin)\n }\n\n /**\n * Watch the session while the user verifies on the other\n * device; mirror the result.\n *\n * @returns\n */\n private async pollHandoff(): Promise<void> {\n const rt = await this.resolveRealtime()\n if (rt) {\n const status = await this.pushWatch(rt, this.maxHandoffPolls, () => this.handoffActive && !this.settled)\n if (status) {\n this.handoffActive = false\n return this.showResult(status)\n }\n\n return // cancelled (continue here) or budget elapsed → the QR persists\n }\n\n let errors = 0\n for (let i = 0; i < this.maxHandoffPolls && this.handoffActive && !this.settled; i++) {\n await this.delay(this.pollMs)\n if (!this.handoffActive || this.settled) return\n try {\n const session = await this.client.getSession()\n errors = 0\n this.observe(session.status)\n if (Flow.isTerminal(session.status)) {\n this.handoffActive = false\n return this.showResult(session.status)\n }\n } catch (error) {\n // The session/token can expire mid-wait (401) — stop and reflect that.\n if (error instanceof WidgetApiError && error.status === 401) {\n this.handoffActive = false\n return this.showResult('expired')\n }\n if (++errors >= 5) return\n }\n }\n }\n\n /**\n * Await a terminal status over the push transport. Resolves to the terminal\n * status, or null if `active()` went false or the tick budget elapsed (push can\n * miss events / disconnect; the budget bounds the wait). An initial fetch\n * catches a session that finished before we subscribed.\n *\n * @param rt\n * @param budget\n * @param active\n * @returns\n */\n private pushWatch(\n rt: WidgetRealtimeClient,\n budget: number,\n active: () => boolean,\n ): Promise<VerificationStatus | null> {\n return new Promise((resolve) => {\n let done = false\n const finish = (status: VerificationStatus | null) => {\n if (done) return\n done = true\n this.stopWatch = undefined\n unsubscribe()\n resolve(status)\n }\n const channel = this.realtimeConfig!.channel\n const unsubscribe = rt.subscribe(channel, (event, data) => {\n if (event !== REALTIME_EVENT.sessionTransition) return\n const status = (data as SessionTransitionEvent).status\n this.observe(status)\n if (Flow.isTerminal(status)) finish(status)\n })\n this.stopWatch = () => finish(null)\n // Catch a race where the session already finished before we subscribed.\n void this.client\n .getSession()\n .then((session) => {\n this.observe(session.status)\n if (Flow.isTerminal(session.status)) finish(session.status)\n })\n .catch((error) => {\n if (error instanceof WidgetApiError && error.status === 401) finish('expired')\n })\n // Bound the wait by the same tick budget the poller would use.\n const countdown = async (n: number): Promise<void> => {\n if (done) return\n if (!active() || n >= budget) return finish(null)\n await this.delay(this.pollMs)\n void countdown(n + 1)\n }\n void countdown(0)\n })\n }\n\n /**\n * Resolve which liveness flow to run from the session's capture model.\n *\n * @param session\n */\n private resolveLiveness(session: ClientSession): void {\n this.livenessChallenges = session.liveness_challenges ?? []\n const model = session.capture_model ?? 'passive'\n this.captureModel = model\n const wantsActive = model === 'active' || model === 'both'\n // `active` is honoured even without a live camera — the active-liveness\n // screen then shows the device as unsupported (no fallback). `both` falls\n // back to passive when the camera/recorder isn't available.\n this.livenessMode = wantsActive && (model === 'active' || this.view.cameraSupported) ? 'active' : 'passive'\n }\n\n private async onImage(blob: Blob | null): Promise<void> {\n const signals = this.config.signals\n switch (this.step) {\n case 'front_capture':\n await this.client.submitDocumentFront({\n image: blob,\n country: this.country,\n documentType: this.documentType,\n signals,\n })\n return this.enter(this.next())\n case 'back_capture':\n await this.client.submitDocumentBack({\n image: blob,\n country: this.country,\n documentType: this.documentType,\n })\n return this.enter('ocr_processing')\n case 'selfie_capture':\n this.selfie = blob\n return this.enter('passive_liveness')\n }\n }\n\n /**\n * Enter a step: render it, and drive any automatic (processing) work.\n *\n * @param step\n * @returns\n */\n private async enter(step: WidgetStep): Promise<void> {\n if (this.settled) return\n this.step = step\n\n // Lead each capture/liveness step with an instruction screen so the user\n // knows what's next and starts it deliberately. The Continue button re-enters\n // the same step with the instruction acknowledged.\n const instruction = STEP_INSTRUCTIONS[step]\n if (instruction && !this.instructionAcked) {\n this.view.renderInstruction(step, instruction.title, instruction.body, instruction.cta ?? 'Continue', () => {\n this.instructionAcked = true\n void this.run(() => this.enter(step))\n })\n return\n }\n this.instructionAcked = false\n this.render()\n\n switch (step) {\n case 'ocr_processing':\n await this.delay(this.transientMs)\n return this.enter(this.next())\n case 'address_processing':\n await this.submitAddress()\n return this.enter(this.next())\n case 'passive_liveness':\n await this.client.submitLiveness({ selfie: this.selfie, signals: this.config.signals })\n return this.enter(this.next())\n case 'face_match':\n await this.client.complete({ signals: this.config.signals })\n return this.enter(this.next())\n case 'processing':\n return this.poll()\n }\n }\n\n /** Watch the session until it reaches a terminal status (then show the result).\n *\n * @returns\n */\n private async poll(): Promise<void> {\n const rt = await this.resolveRealtime()\n if (rt) {\n const status = await this.pushWatch(rt, this.maxPolls, () => !this.settled)\n\n return this.showResult(status ?? 'requires_review')\n }\n\n for (let i = 0; i < this.maxPolls && !this.settled; i++) {\n const session = await this.client.getSession()\n this.observe(session.status)\n if (Flow.isTerminal(session.status)) return this.showResult(session.status)\n await this.delay(this.pollMs)\n }\n // Still processing after the poll budget — surface as pending review.\n this.showResult('requires_review')\n }\n\n private showResult(status: VerificationStatus): void {\n this.result = { status, decision: Flow.statusToDecision(status) }\n this.step = 'result'\n this.render()\n }\n\n /**\n * A session that was already terminal on load: a notice with only a Close button.\n *\n * @param status\n */\n private showTerminal(status: VerificationStatus): void {\n this.result = { status, decision: Flow.statusToDecision(status) }\n this.step = 'result'\n this.terminalOnLoad = true\n this.render()\n }\n\n private render(): void {\n this.view.render({\n step: this.step,\n documentType: this.documentType,\n decision: this.result?.decision,\n status: this.result?.status,\n terminalNotice: this.terminalOnLoad,\n allowSkip: !!this.config.signals,\n livenessChallenges: this.livenessChallenges,\n requireLiveCamera: this.captureModel === 'active',\n // The active flow is strict end-to-end: documents must be detected, not\n // manually waved through.\n strictCapture: this.livenessMode === 'active',\n handoffAvailable: this.handoffReady,\n addressMethods: workflowAddressConfig(this.workflow)?.methods ?? [],\n })\n }\n\n /**\n * Store the entered address, resolve device location if opted in, then verify.\n *\n * @param data\n * @returns\n */\n private async onAddress(data: AddressFormData): Promise<void> {\n this.addressData = data\n // Coordinates are normally resolved up front by `shareLocation` when the user\n // ticks \"use my location\" (so the prompt is immediate); geolocate here only as\n // a fallback, and clear them if they opted out.\n if (!data.useLocation) this.addressCoords = null\n else if (!this.addressCoords) this.addressCoords = await this.geolocate()\n\n return this.enter('address_processing')\n }\n\n /** Request the device's location (from the address-entry \"use my location\" opt-in). */\n private async shareLocation(): Promise<boolean> {\n this.addressCoords = await this.geolocate()\n\n return !!this.addressCoords\n }\n\n /**\n * Submit the captured address evidence to the Client API.\n *\n * @returns\n */\n private async submitAddress(): Promise<void> {\n const data = this.addressData\n if (!data) return\n\n await this.client.submitAddress({\n line1: data.line1,\n line2: data.line2,\n city: data.city,\n region: data.region,\n postalCode: data.postalCode,\n country: data.country,\n poa: data.poa,\n latitude: this.addressCoords?.latitude ?? null,\n longitude: this.addressCoords?.longitude ?? null,\n signals: this.config.signals,\n })\n }\n\n /**\n * Resolve the device's coordinates via the Geolocation API. Resolves to `null`\n * on denial/unavailability/timeout — the `device_location` method then simply\n * has no coordinates to check (routing the session to review).\n *\n * @returns\n */\n private geolocate(): Promise<{ latitude: number; longitude: number } | null> {\n const geo = this.nav?.geolocation\n if (!geo) return Promise.resolve(null)\n\n return new Promise((resolve) => {\n geo.getCurrentPosition(\n (pos) => resolve({ latitude: pos.coords.latitude, longitude: pos.coords.longitude }),\n () => resolve(null),\n { enableHighAccuracy: false, timeout: 10_000, maximumAge: 60_000 },\n )\n })\n }\n\n private next(): WidgetStep {\n return Flow.nextStep(this.step, {\n documentType: this.documentType,\n livenessMode: this.livenessMode,\n workflow: this.workflow,\n })\n }\n\n private delay(ms: number): Promise<void> {\n return new Promise((resolve) => this.scheduler(resolve, ms))\n }\n\n /** Run an async step, routing any failure to the error screen. */\n private async run(fn: () => Promise<void> | void): Promise<void> {\n try {\n await fn()\n } catch (error) {\n this.fail(error)\n }\n }\n\n private fail(error: unknown): void {\n // Notify once, on the first failure. `pendingError` is the guard so a repeat\n // (or a later close) doesn't re-fire.\n if (this.settled || this.pendingError) return\n const err = error instanceof Error ? error : new Error(String(error))\n this.pendingError = err\n this.step = 'result'\n\n this.view.render({\n step: 'result',\n documentType: this.documentType,\n errorMessage: err.message,\n })\n\n // Surface the failure to the integrator immediately, not when the user\n // eventually dismisses the screen (they may never), so an expired session or\n // token is knowable programmatically. `dispatch` also forwards a non-closing\n // `error` event to an embedding parent; the terminal `arkyc:error` (which\n // tears the overlay down) is posted from `finishResult` on dismissal.\n this.dispatch('error', this.errorData(err))\n this.config.onError?.(err)\n }\n\n /** Event payload for a failure: the message plus the stable key/status when it's a typed API error. */\n private errorData(err: Error): { message: string; status?: number; error?: string } {\n if (err instanceof WidgetApiError) return { message: err.message, status: err.status, error: err.error }\n\n return { message: err.message }\n }\n\n private finishResult(): void {\n if (this.settled) return\n this.settled = true\n this.teardownRealtime()\n\n if (this.pendingError) {\n // `onError` + the `error` event already fired at failure time; only relay\n // the terminal error to an embedding parent (closing its overlay) here.\n this.post('arkyc:error', { error: serializeError(this.pendingError) })\n } else if (this.result) {\n this.post('arkyc:complete', { payload: this.result })\n this.dispatch('complete', this.result)\n this.config.onComplete?.(this.result)\n }\n\n this.destroy()\n this.config.onSettle?.()\n }\n\n private finishClose(): void {\n if (this.settled) return\n\n this.settled = true\n this.teardownRealtime()\n this.post('arkyc:close', {})\n this.dispatch('close')\n this.config.onClose?.()\n this.destroy()\n this.config.onSettle?.()\n }\n\n /** Stop any active session watch + disconnect the push transport. */\n private teardownRealtime(): void {\n this.stopWatch?.()\n this.rtClient?.disconnect()\n this.rtClient = null\n }\n\n private post(type: string, extra: Record<string, unknown>): void {\n if (!this.postToParent) return\n try {\n this.win.parent?.postMessage({ type, ...extra }, '*')\n } catch {\n // Cross-origin parent without access — nothing more we can do.\n }\n }\n}\n\nfunction serializeError(error: Error): { message: string; name: string } {\n return { message: error.message, name: error.name }\n}\n\n/** The origin of an absolute URL, or '' when it can't be parsed. */\nfunction originOf(url: string): string {\n try {\n return new URL(url).origin\n } catch {\n return ''\n }\n}\n\n/**\n * Build the hosted-page URL the handoff QR encodes: always the `target` page\n * plus the session `token`, and the API base **only when the phone can actually\n * reach it** — i.e. a genuine cross-origin base. `apiBase` is the widget's\n * resolved Client API base (always origin-qualified), so a relative proxy\n * resolves to the desktop's own `pageOrigin` and is skipped (the hosted page\n * then falls back to its own default base instead of a URL the phone can't use).\n */\nexport const composeHandoffUrl = (target: string, token: string, apiBase: string, pageOrigin: string): string => {\n const sep = target.includes('?') ? '&' : '?'\n let url = `${target}${sep}token=${encodeURIComponent(token)}`\n const baseOrigin = originOf(apiBase)\n if (baseOrigin && baseOrigin !== pageOrigin) url += `&baseUrl=${encodeURIComponent(apiBase)}`\n return url\n}\n\nexport const resolveContainer = (container: string | HTMLElement, doc: Document): HTMLElement => {\n const el = typeof container === 'string' ? doc.querySelector<HTMLElement>(container) : container\n if (!el) throw new Error(`ArkycWidget.mount: container \"${String(container)}\" not found.`)\n return el\n}\n\n/**\n * Make an inline mount point a reliable host for the widget, so `mount()` renders\n * predictably regardless of the page layout — a static or zero-height container,\n * or one sharing the viewport with an app root that would otherwise paint over it.\n *\n * The widget gives the host its own stacking context and lifts it above sibling\n * app content, the way `open()` owns its overlay. Each property is only set when\n * the host hasn't already committed to one (checked against computed style where\n * available, else inline style), so an embed that wants normal flow or a specific\n * layer can still override it with its own CSS.\n */\nexport const adoptContainer = (container: HTMLElement, doc: Document): void => {\n const computed = doc.defaultView?.getComputedStyle?.(container)\n const position = computed?.position ?? container.style.position\n if (!position || position === 'static') container.style.position = 'relative'\n\n const zIndex = computed?.zIndex ?? container.style.zIndex\n if (!zIndex || zIndex === 'auto') container.style.zIndex = '1'\n\n // A self-contained stacking context keeps the widget's layers from bleeding\n // into (or being clipped by) the surrounding page.\n if (!container.style.isolation) container.style.isolation = 'isolate'\n}\n\nexport const buildController = (options: BaseWidgetOptions, onSettle: () => void): WidgetController => {\n if (!options.token) throw new Error('ArkycWidget requires a client `token`.')\n return new WidgetController({\n token: options.token,\n baseUrl: options.baseUrl,\n handoff: options.handoff,\n handoffUrl: options.handoffUrl,\n branding: options.branding,\n signals: options.signals,\n onComplete: options.onComplete,\n onError: options.onError,\n onClose: options.onClose,\n onEvent: options.onEvent,\n onSettle,\n fetch: options.fetch,\n doc: options.doc,\n win: options.win,\n nav: options.nav,\n faceAnalyzer: options.faceAnalyzer,\n faceTuning: options.faceTuning,\n documentAnalyzer: options.documentAnalyzer,\n documentTuning: options.documentTuning,\n })\n}\n"],"mappings":";;;;;;;;;;AAqBA,MAAM,oBAAgG;CACpG,eAAe;EACb,OAAO;EACP,MAAM;CACR;CACA,cAAc;EACZ,OAAO;EACP,MAAM;CACR;CACA,gBAAgB;EACd,OAAO;EACP,MAAM;CACR;CACA,iBAAiB;EACf,OAAO;EACP,MAAM;CACR;AACF;;;;;;;;;;;;;;;;AAiBA,SAAS,mBAA2D,UAAa,SAAgC;CAC/G,MAAM,OAAO,SAAS;CACtB,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,gBAAgB,KAAK,OAAO,GAAG,OAAO;CAChE,IAAI;EACF,MAAM,OAAO,IAAI,IAAI,OAAO;EAC5B,MAAM,WAAW,IAAI,IAAI,MAAM,IAAI;EACnC,IAAI,SAAS,WAAW,KAAK,QAAQ,OAAO;EAC5C,OAAO;GAAE,GAAG;GAAU,UAAU,GAAG,KAAK,SAAS,SAAS,WAAW,SAAS,SAAS,SAAS;EAAO;CACzG,QAAQ;EACN,OAAO;CACT;AACF;AAEA,IAAa,mBAAb,MAA8B;CAmDC;CAlD7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;CAGA,gBAAuC;EAAE,SAAS;EAAO,eAAe;EAAM,KAAK;CAAG;CACtF,eAAuB;CACvB,gBAAwB;;CAGxB,YAAo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W,UAAU,YAAY,UAAU,MAAM;CACvD,IAAI,CAAC,YAAY,aAAa,UAAU,UAAU,MAAM,WAAW;CAEnE,MAAM,SAAS,UAAU,UAAU,UAAU,MAAM;CACnD,IAAI,CAAC,UAAU,WAAW,QAAQ,UAAU,MAAM,SAAS;CAI3D,IAAI,CAAC,UAAU,MAAM,WAAW,UAAU,MAAM,YAAY;AAC9D;AAEA,MAAa,mBAAmB,SAA4B,aAA2C;CACrG,IAAI,CAAC,QAAQ,OAAO,MAAM,IAAI,MAAM,wCAAwC;CAC5E,OAAO,IAAI,iBAAiB;EAC1B,OAAO,QAAQ;EACf,SAAS,QAAQ;EACjB,SAAS,QAAQ;EACjB,YAAY,QAAQ;EACpB,UAAU,QAAQ;EAClB,SAAS,QAAQ;EACjB,YAAY,QAAQ;EACpB,SAAS,QAAQ;EACjB,SAAS,QAAQ;EACjB,SAAS,QAAQ;EACjB;EACA,OAAO,QAAQ;EACf,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,cAAc,QAAQ;EACtB,YAAY,QAAQ;EACpB,kBAAkB,QAAQ;EAC1B,gBAAgB,QAAQ;CAC1B,CAAC;AACH"}
|
package/dist/theme.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.d.mts","names":[],"sources":["../src/theme.ts"],"mappings":";;;;;;AAuBA;;;cAAa,KAAA;EAAA,SACF,YAAA;EAAA,SACA,YAAA;EAAA,SACA,IAAA;EAAA,SACA,OAAA;EAHA;EAAA,SAKA,IAAA;EAHA;EAAA,SAKA,YAAA;EAFA;EAAA,SAIA,UAAA;EAAA;EAAA,SAEA,UAAA;EAEA;EAAA,SAAA,KAAA;;WAEA,MAAA;cAEG,QAAA,GAAW,eAAA;EAmBvB;;;;;EAAA,SAAA;
|
|
1
|
+
{"version":3,"file":"theme.d.mts","names":[],"sources":["../src/theme.ts"],"mappings":";;;;;;AAuBA;;;cAAa,KAAA;EAAA,SACF,YAAA;EAAA,SACA,YAAA;EAAA,SACA,IAAA;EAAA,SACA,OAAA;EAHA;EAAA,SAKA,IAAA;EAHA;EAAA,SAKA,YAAA;EAFA;EAAA,SAIA,UAAA;EAAA;EAAA,SAEA,UAAA;EAEA;EAAA,SAAA,KAAA;;WAEA,MAAA;cAEG,QAAA,GAAW,eAAA;EAmBvB;;;;;EAAA,SAAA;EA+BA;;;;;EAfA,UAAA;EAAA,OAIO,GAAA,CAAI,CAAA;IAAK,YAAA;EAAA,IAAyB,OAAA;EAWzC,GAAA,CAAI,CAAA;IAAK,YAAA;EAAA,IAAyB,OAAA;AAAA"}
|
package/dist/theme.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.mjs","names":["themeCss"],"sources":["../src/theme.ts"],"sourcesContent":["import type { ProjectBranding } from '@arkyc/types'\nimport type { RgbData } from './types'\nimport themeCss from 'virtual:arkyc-theme-css'\n\nconst LIGHT = {\n background: '#ffffff',\n foreground: '#0f172a',\n muted: '#64748b',\n border: '#e2e8f0',\n}\n\nconst DARK = {\n background: '#0f172a',\n foreground: '#f8fafc',\n muted: '#94a3b8',\n border: '#1e293b',\n}\n\n/**\n * Resolves project branding into a concrete theme and renders its CSS. One class\n * owns the whole \"theme\" concern: defaulted colour/logo/radius values plus the\n * CSS-variable block and stylesheet derived from them.\n */\nexport class Theme {\n readonly primaryColor: string\n readonly borderRadius: number\n readonly mode: 'light' | 'dark'\n readonly logoUrl: string | null\n /** Project/company display name shown in the header (when branding is shown). */\n readonly name: string | null\n /** Whether to show the project name/logo in the header (white-label off → false). */\n readonly showBranding: boolean\n /** Surface (card) background. */\n readonly background: string\n /** Primary text colour. */\n readonly foreground: string\n /** Muted text colour. */\n readonly muted: string\n /** Subtle border colour. */\n readonly border: string\n\n constructor(branding?: ProjectBranding | null) {\n this.mode = branding?.theme === 'dark' ? 'dark' : 'light'\n const palette = this.mode === 'dark' ? DARK : LIGHT\n this.primaryColor = branding?.primary_color ?? '#b8860b'\n this.borderRadius = branding?.border_radius ?? 12\n this.logoUrl = branding?.logo_url ?? null\n this.name = branding?.name ?? null\n this.showBranding = branding?.show_branding !== false\n this.background = palette.background\n this.foreground = palette.foreground\n this.muted = palette.muted\n this.border = palette.border\n }\n\n /**\n * The CSS-variable declaration block for this theme.\n *\n * @returns\n */\n variables(): string {\n return [\n `--arkyc-primary:${this.primaryColor}`,\n `--arkyc-radius:${this.borderRadius}px`,\n `--arkyc-bg:${this.background}`,\n `--arkyc-fg:${this.foreground}`,\n `--arkyc-muted:${this.muted}`,\n `--arkyc-border:${this.border}`,\n ].join(';')\n }\n\n /**\n * The widget stylesheet, parameterised by this theme's variables.\n *\n * @returns\n */\n stylesheet(): string {\n return themeCss.replace('/* {variables} */', `${this.variables()};`).trim()\n }\n\n static rgb(p: { primaryColor: string }): RgbData {\n const obj: RgbData['obj'] = Object.fromEntries(
|
|
1
|
+
{"version":3,"file":"theme.mjs","names":["themeCss"],"sources":["../src/theme.ts"],"sourcesContent":["import type { ProjectBranding } from '@arkyc/types'\nimport type { RgbData } from './types'\nimport themeCss from 'virtual:arkyc-theme-css'\n\nconst LIGHT = {\n background: '#ffffff',\n foreground: '#0f172a',\n muted: '#64748b',\n border: '#e2e8f0',\n}\n\nconst DARK = {\n background: '#0f172a',\n foreground: '#f8fafc',\n muted: '#94a3b8',\n border: '#1e293b',\n}\n\n/**\n * Resolves project branding into a concrete theme and renders its CSS. One class\n * owns the whole \"theme\" concern: defaulted colour/logo/radius values plus the\n * CSS-variable block and stylesheet derived from them.\n */\nexport class Theme {\n readonly primaryColor: string\n readonly borderRadius: number\n readonly mode: 'light' | 'dark'\n readonly logoUrl: string | null\n /** Project/company display name shown in the header (when branding is shown). */\n readonly name: string | null\n /** Whether to show the project name/logo in the header (white-label off → false). */\n readonly showBranding: boolean\n /** Surface (card) background. */\n readonly background: string\n /** Primary text colour. */\n readonly foreground: string\n /** Muted text colour. */\n readonly muted: string\n /** Subtle border colour. */\n readonly border: string\n\n constructor(branding?: ProjectBranding | null) {\n this.mode = branding?.theme === 'dark' ? 'dark' : 'light'\n const palette = this.mode === 'dark' ? DARK : LIGHT\n this.primaryColor = branding?.primary_color ?? '#b8860b'\n this.borderRadius = branding?.border_radius ?? 12\n this.logoUrl = branding?.logo_url ?? null\n this.name = branding?.name ?? null\n this.showBranding = branding?.show_branding !== false\n this.background = palette.background\n this.foreground = palette.foreground\n this.muted = palette.muted\n this.border = palette.border\n }\n\n /**\n * The CSS-variable declaration block for this theme.\n *\n * @returns\n */\n variables(): string {\n return [\n `--arkyc-primary:${this.primaryColor}`,\n `--arkyc-radius:${this.borderRadius}px`,\n `--arkyc-bg:${this.background}`,\n `--arkyc-fg:${this.foreground}`,\n `--arkyc-muted:${this.muted}`,\n `--arkyc-border:${this.border}`,\n ].join(';')\n }\n\n /**\n * The widget stylesheet, parameterised by this theme's variables.\n *\n * @returns\n */\n stylesheet(): string {\n return themeCss.replace('/* {variables} */', `${this.variables()};`).trim()\n }\n\n static rgb(p: { primaryColor: string }): RgbData {\n const obj: RgbData['obj'] = Object.fromEntries(\n p.primaryColor.match(/\\d+/g)?.map((v, i) => [['r', 'g', 'b'][i], Number(v)]) ?? [],\n ) ?? { r: 50, g: 100, b: 150 }\n\n return {\n obj,\n str: `rgb(${[obj.r, obj.g, obj.b].join(',')})`,\n }\n }\n\n rgb(p: { primaryColor: string }): RgbData {\n return Theme.rgb(p)\n }\n}\n"],"mappings":";;AAIA,MAAM,QAAQ;CACZ,YAAY;CACZ,YAAY;CACZ,OAAO;CACP,QAAQ;AACV;AAEA,MAAM,OAAO;CACX,YAAY;CACZ,YAAY;CACZ,OAAO;CACP,QAAQ;AACV;;;;;;AAOA,IAAa,QAAb,MAAa,MAAM;CACjB;CACA;CACA;CACA;;CAEA;;CAEA;;CAEA;;CAEA;;CAEA;;CAEA;CAEA,YAAY,UAAmC;EAC7C,KAAK,OAAO,UAAU,UAAU,SAAS,SAAS;EAClD,MAAM,UAAU,KAAK,SAAS,SAAS,OAAO;EAC9C,KAAK,eAAe,UAAU,iBAAiB;EAC/C,KAAK,eAAe,UAAU,iBAAiB;EAC/C,KAAK,UAAU,UAAU,YAAY;EACrC,KAAK,OAAO,UAAU,QAAQ;EAC9B,KAAK,eAAe,UAAU,kBAAkB;EAChD,KAAK,aAAa,QAAQ;EAC1B,KAAK,aAAa,QAAQ;EAC1B,KAAK,QAAQ,QAAQ;EACrB,KAAK,SAAS,QAAQ;CACxB;;;;;;CAOA,YAAoB;EAClB,OAAO;GACL,mBAAmB,KAAK;GACxB,kBAAkB,KAAK,aAAa;GACpC,cAAc,KAAK;GACnB,cAAc,KAAK;GACnB,iBAAiB,KAAK;GACtB,kBAAkB,KAAK;EACzB,CAAC,CAAC,KAAK,GAAG;CACZ;;;;;;CAOA,aAAqB;EACnB,OAAOA,iCAAS,QAAQ,qBAAqB,GAAG,KAAK,UAAU,EAAE,EAAE,CAAC,CAAC,KAAK;CAC5E;CAEA,OAAO,IAAI,GAAsC;EAC/C,MAAM,MAAsB,OAAO,YACjC,EAAE,aAAa,MAAM,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;GAAC;GAAK;GAAK;EAAG,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CACnF,KAAK;GAAE,GAAG;GAAI,GAAG;GAAK,GAAG;EAAI;EAE7B,OAAO;GACL;GACA,KAAK,OAAO;IAAC,IAAI;IAAG,IAAI;IAAG,IAAI;GAAC,CAAC,CAAC,KAAK,GAAG,EAAE;EAC9C;CACF;CAEA,IAAI,GAAsC;EACxC,OAAO,MAAM,IAAI,CAAC;CACpB;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkyc/widget",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.10",
|
|
4
4
|
"description": "Embeddable, framework-agnostic Arkyc identity-verification widget",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"qrcode-generator": "^1.4.4",
|
|
43
|
-
"@arkyc/types": "^1.2.
|
|
43
|
+
"@arkyc/types": "^1.2.10"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"firebase": "^11.0.0",
|