@incodetech/web 2.0.0-alpha.5 → 2.0.0-alpha.7

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.
@@ -1,9 +1,539 @@
1
- import "../button-DeMZ_34N.js";
2
- import "@incodetech/core/flow";
3
- import "../vendor-preact-CK0WeTOR.js";
4
- import "../title-ng7q7YDh.js";
5
- import { I as i, p as a } from "../flow-ZK6OBsa3.js";
1
+ import { c as D, u as i, L as W, S as E, B as j, r as H, a as B } from "../incodeModule-Dv8Qllrv.js";
2
+ import { createOrchestratedFlowManager as O, getRequiredWasmPipelines as R } from "@incodetech/core/flow";
3
+ import { k as F, A as I, d as x, y as M } from "../vendor-preact-CK0WeTOR.js";
4
+ import "../instance-B-q0ZREN.js";
5
+ import { T as K, u as $ } from "../title-BfO5Dlzk.js";
6
+ import { api as z, warmupWasm as q } from "@incodetech/core";
7
+ import { emailMachine as _ } from "@incodetech/core/email";
8
+ import { phoneMachine as V } from "@incodetech/core/phone";
9
+ import { selfieMachine as Y } from "@incodetech/core/selfie";
10
+ import { s as Z } from "../setup-wNL83jmW.js";
11
+ import { s as y } from "../uiConfig-CQ1W9cUD.js";
12
+ const G = {
13
+ small: 24,
14
+ medium: 48,
15
+ large: 64
16
+ }, b = ({
17
+ title: e,
18
+ subtitle: t,
19
+ size: n = "medium",
20
+ fullScreen: s = !0,
21
+ className: r
22
+ }) => {
23
+ const a = G[n], o = D(
24
+ "IncodeSpinner",
25
+ s && "IncodeSpinnerFullScreen",
26
+ r
27
+ );
28
+ return /* @__PURE__ */ i(
29
+ "div",
30
+ {
31
+ class: o,
32
+ "data-testid": "spinner",
33
+ "data-title": e,
34
+ "data-subtitle": t,
35
+ "data-size": n,
36
+ children: /* @__PURE__ */ i("div", { class: "IncodeSpinnerContent", children: [
37
+ /* @__PURE__ */ i(W, { size: a }),
38
+ (e || t) && /* @__PURE__ */ i(F, { children: [
39
+ /* @__PURE__ */ i(E, { size: 16 }),
40
+ /* @__PURE__ */ i("div", { class: "IncodeSpinnerText", children: [
41
+ e && /* @__PURE__ */ i(K, { className: "IncodeSpinnerTitle", children: e }),
42
+ t && /* @__PURE__ */ i(F, { children: [
43
+ e && /* @__PURE__ */ i(E, { size: 12 }),
44
+ /* @__PURE__ */ i("p", { class: "IncodeSpinnerSubtitle", children: t })
45
+ ] })
46
+ ] })
47
+ ] })
48
+ ] })
49
+ }
50
+ );
51
+ };
52
+ function J(e) {
53
+ let t = e.replace("#", "");
54
+ t.length === 3 && (t = t.split("").map((u) => u + u).join(""));
55
+ const n = /^([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);
56
+ if (!n) return null;
57
+ const s = Number.parseInt(n[1], 16) / 255, r = Number.parseInt(n[2], 16) / 255, a = Number.parseInt(n[3], 16) / 255, o = Math.max(s, r, a), l = Math.min(s, r, a);
58
+ let c = 0, p = 0;
59
+ const d = (o + l) / 2;
60
+ if (o !== l) {
61
+ const u = o - l;
62
+ switch (p = d > 0.5 ? u / (2 - o - l) : u / (o + l), o) {
63
+ case s:
64
+ c = ((r - a) / u + (r < a ? 6 : 0)) / 6;
65
+ break;
66
+ case r:
67
+ c = ((a - s) / u + 2) / 6;
68
+ break;
69
+ case a:
70
+ c = ((s - r) / u + 4) / 6;
71
+ break;
72
+ }
73
+ }
74
+ return { h: c * 360, s: p * 100, l: d * 100 };
75
+ }
76
+ function w(e, t, n) {
77
+ const s = e / 360, r = t / 100, a = n / 100;
78
+ let o, l, c;
79
+ if (r === 0)
80
+ o = l = c = a;
81
+ else {
82
+ const d = (h, C, m) => (m < 0 && (m += 1), m > 1 && (m -= 1), m < 0.16666666666666666 ? h + (C - h) * 6 * m : m < 0.5 ? C : m < 0.6666666666666666 ? h + (C - h) * (0.6666666666666666 - m) * 6 : h), u = a < 0.5 ? a * (1 + r) : a + r - a * r, f = 2 * a - u;
83
+ o = d(f, u, s + 1 / 3), l = d(f, u, s), c = d(f, u, s - 1 / 3);
84
+ }
85
+ const p = (d) => {
86
+ const u = Math.round(d * 255).toString(16);
87
+ return u.length === 1 ? `0${u}` : u;
88
+ };
89
+ return `#${p(o)}${p(l)}${p(c)}`;
90
+ }
91
+ function Q(e) {
92
+ const t = J(e);
93
+ if (!t)
94
+ throw new Error(`Invalid color format: ${e}`);
95
+ return {
96
+ 50: w(t.h, t.s, 95),
97
+ 200: w(t.h, t.s, 80),
98
+ 300: w(t.h, t.s, 65),
99
+ 400: w(t.h, t.s, Math.min(100, t.l + 10)),
100
+ 500: e,
101
+ 600: w(t.h, t.s, Math.max(0, t.l - 10)),
102
+ 900: w(t.h, t.s, 20)
103
+ };
104
+ }
105
+ function X(e, t) {
106
+ if (typeof document > "u")
107
+ return;
108
+ const n = Q(e);
109
+ let s = document.getElementById(
110
+ "incode-theme"
111
+ );
112
+ s || (s = document.createElement("style"), s.id = "incode-theme", document.head.appendChild(s));
113
+ const r = t || "#ffffff", a = `
114
+ :root,
115
+ :host {
116
+ --primitive-color-brand-50: ${n[50]};
117
+ --primitive-color-brand-200: ${n[200]};
118
+ --primitive-color-brand-300: ${n[300]};
119
+ --primitive-color-brand-400: ${n[400]};
120
+ --primitive-color-brand-500: ${n[500]};
121
+ --primitive-color-brand-600: ${n[600]};
122
+ --primitive-color-brand-900: ${n[900]};
123
+ --button-primary-text-default: ${r};
124
+ }
125
+ `;
126
+ s.textContent = a;
127
+ }
128
+ async function ee() {
129
+ return (await z.get("/omni/asset/fetch-all")).data;
130
+ }
131
+ const L = /* @__PURE__ */ new Map();
132
+ async function te(e) {
133
+ if (e.startsWith("data:"))
134
+ return e;
135
+ const t = L.get(e);
136
+ if (t)
137
+ return t;
138
+ const s = await (await fetch(e)).blob(), r = await new Promise((a, o) => {
139
+ const l = new FileReader();
140
+ l.onloadend = () => a(l.result), l.onerror = o, l.readAsDataURL(s);
141
+ });
142
+ return L.set(e, r), r;
143
+ }
144
+ async function re() {
145
+ const e = await ee();
146
+ if (!e.theme)
147
+ throw new Error("Theme URL not found in assets response");
148
+ const t = e.theme, n = t.startsWith("http://") || t.startsWith("https://");
149
+ let s;
150
+ if (n) {
151
+ const o = await fetch(t);
152
+ if (!o.ok)
153
+ throw new Error(`Failed to fetch theme: ${o.statusText}`);
154
+ s = await o.json();
155
+ } else
156
+ s = (await z.get(t)).data;
157
+ const r = e["logo.png"] || e["logo.svg"] || e["logo.jpg"] || e["logo.jpeg"] || e["logo.webp"] || s.logo;
158
+ let a = r;
159
+ return r && (a = await te(r)), {
160
+ ...s,
161
+ logo: a
162
+ };
163
+ }
164
+ async function ne() {
165
+ const e = await re();
166
+ return e.main && X(e.main, e.buttonColor), e;
167
+ }
168
+ const S = {
169
+ PHONE: () => import("../phone/phone.es.js").then((e) => e.Phone),
170
+ EMAIL: () => import("../email/email.es.js").then((e) => e.Email),
171
+ SELFIE: () => import("../selfie/selfie.es.js").then((e) => e.Selfie)
172
+ };
173
+ function T() {
174
+ return O({
175
+ modules: {
176
+ PHONE: V,
177
+ EMAIL: _,
178
+ SELFIE: Y
179
+ }
180
+ });
181
+ }
182
+ async function N(e) {
183
+ await Z({
184
+ apiURL: e.apiURL,
185
+ token: e.token,
186
+ i18n: { lang: e.lang ?? "en" }
187
+ });
188
+ }
189
+ async function k() {
190
+ try {
191
+ const e = await ne(), t = {
192
+ logoSrc: e.logo,
193
+ hideFooterBranding: e.hideFooterBranding
194
+ };
195
+ return y(t), { theme: e, uiConfig: t };
196
+ } catch (e) {
197
+ return console.warn("Failed to fetch dashboard theme:", e), {};
198
+ }
199
+ }
200
+ function A(e, t) {
201
+ const n = R(e.flow);
202
+ n.length > 0 && q({
203
+ ...t,
204
+ pipelines: n
205
+ }).catch((s) => {
206
+ console.error("WASM warmup failed:", s);
207
+ });
208
+ }
209
+ function oe(e) {
210
+ const t = e.currentStep;
211
+ if (t) {
212
+ const n = S[t];
213
+ n && n().catch(() => {
214
+ });
215
+ }
216
+ }
217
+ const se = ({
218
+ moduleKey: e,
219
+ onNext: t
220
+ }) => {
221
+ const { t: n } = $();
222
+ return /* @__PURE__ */ i("section", { class: "IncodeUnsupportedModule", "aria-live": "polite", children: /* @__PURE__ */ i("div", { class: "IncodeUnsupportedModuleContent", children: [
223
+ /* @__PURE__ */ i("h2", { class: "IncodeUnsupportedModuleTitle", children: n("unsupportedModule.title", "Module not available") }),
224
+ /* @__PURE__ */ i("p", { class: "IncodeUnsupportedModuleMessage", children: n(
225
+ "unsupportedModule.message",
226
+ `The "${e}" module is not yet supported in this version.`
227
+ ) }),
228
+ /* @__PURE__ */ i(
229
+ j,
230
+ {
231
+ onClick: t,
232
+ class: "IncodeUnsupportedModuleButton",
233
+ "data-testid": "unsupported-module-next-button",
234
+ children: n("unsupportedModule.next", "Next")
235
+ }
236
+ )
237
+ ] }) });
238
+ }, g = /* @__PURE__ */ new Map();
239
+ function U(e) {
240
+ const t = g.get(e);
241
+ if (!t)
242
+ throw new Error("Preload state not found");
243
+ return {
244
+ get isReady() {
245
+ return t.status === "ready";
246
+ },
247
+ get error() {
248
+ return t.status === "error" ? t.error ?? null : null;
249
+ },
250
+ async waitUntilReady() {
251
+ if (t.status !== "ready") {
252
+ if (t.status === "error")
253
+ throw new Error(t.error ?? "Preload failed");
254
+ return t.readyPromise;
255
+ }
256
+ },
257
+ cancel() {
258
+ t.status === "loading" && (t.unsubscribe && t.unsubscribe(), t.flowManager.stop(), t.readyReject(new Error("Preload cancelled")), g.delete(e));
259
+ }
260
+ };
261
+ }
262
+ function Ie(e) {
263
+ const { token: t } = e;
264
+ if (g.has(t))
265
+ return U(t);
266
+ let n, s;
267
+ const r = new Promise((c, p) => {
268
+ n = c, s = p;
269
+ }), a = T(), o = {
270
+ status: "loading",
271
+ flowManager: a,
272
+ config: e,
273
+ readyPromise: r,
274
+ readyResolve: n,
275
+ readyReject: s
276
+ };
277
+ return g.set(t, o), (async () => {
278
+ try {
279
+ await N({
280
+ apiURL: e.apiURL,
281
+ token: e.token,
282
+ lang: e.lang
283
+ });
284
+ const c = e.disableDashboardTheme ? Promise.resolve({}) : k().then((d) => {
285
+ o.theme = d.theme, o.uiConfig = d.uiConfig;
286
+ }), p = a.subscribe((d) => {
287
+ if (d.status === "ready") {
288
+ const u = d;
289
+ e.wasmConfig && A(u, e.wasmConfig), oe(u), o.unsubscribe?.(), o.unsubscribe = void 0, o.status = "ready", o.readyResolve();
290
+ } else d.status === "error" && (o.unsubscribe?.(), o.unsubscribe = void 0, o.status = "error", o.error = d.error, o.readyReject(new Error(d.error)));
291
+ });
292
+ o.unsubscribe = p, a.load(), await c;
293
+ } catch (c) {
294
+ o.status = "error", o.error = c instanceof Error ? c.message : "Failed to preload", o.readyReject(
295
+ c instanceof Error ? c : new Error("Failed to preload")
296
+ ), g.delete(t);
297
+ }
298
+ })(), U(t);
299
+ }
300
+ function v(e) {
301
+ return g.get(e) ?? null;
302
+ }
303
+ function P(e) {
304
+ const t = v(e);
305
+ return t && g.delete(e), t;
306
+ }
307
+ function ie(e) {
308
+ const { apiURL: t, token: n, lang: s, disableDashboardTheme: r, onError: a } = e, o = I(null), [l, c] = x(() => {
309
+ const d = v(n);
310
+ if (d?.status === "ready") {
311
+ const f = P(n);
312
+ if (f)
313
+ return o.current = f.flowManager, f.uiConfig && y(f.uiConfig), { status: "ready", flowManager: f.flowManager };
314
+ }
315
+ const u = T();
316
+ return o.current = u, d?.status === "error" ? {
317
+ status: "error",
318
+ error: d.error ?? "Preload failed",
319
+ flowManager: u
320
+ } : { status: "initializing", flowManager: u };
321
+ }), p = I(!1);
322
+ return M(() => {
323
+ if (l.status !== "initializing")
324
+ return;
325
+ const d = v(n);
326
+ if (d?.status === "loading") {
327
+ d.readyPromise.then(() => {
328
+ const f = P(n);
329
+ f && (o.current = f.flowManager, f.uiConfig && y(f.uiConfig), c({ status: "ready", flowManager: f.flowManager }));
330
+ }).catch((f) => {
331
+ const h = f instanceof Error ? f.message : "Preload failed";
332
+ c({
333
+ status: "error",
334
+ error: h,
335
+ flowManager: l.flowManager
336
+ }), a?.(h);
337
+ });
338
+ return;
339
+ }
340
+ if (p.current)
341
+ return;
342
+ p.current = !0, (async () => {
343
+ try {
344
+ await N({ apiURL: t, token: n, lang: s });
345
+ const f = r ? Promise.resolve() : k().then((h) => {
346
+ h.uiConfig && y(h.uiConfig);
347
+ });
348
+ l.flowManager.load(), await f, c({ status: "ready", flowManager: l.flowManager });
349
+ } catch (f) {
350
+ const h = f instanceof Error ? f.message : "Failed to initialize SDK";
351
+ c({
352
+ status: "error",
353
+ error: h,
354
+ flowManager: l.flowManager
355
+ }), a?.(h);
356
+ }
357
+ })();
358
+ }, [t, n, s, r, a, l]), l;
359
+ }
360
+ function ae(e) {
361
+ const { moduleKey: t, onModuleLoading: n, onModuleLoaded: s, onError: r } = e, [a, o] = x({ status: "idle" });
362
+ return M(() => {
363
+ if (!t) {
364
+ o({ status: "idle" });
365
+ return;
366
+ }
367
+ const l = S[t];
368
+ if (!l) {
369
+ o({ status: "unsupported", moduleKey: t });
370
+ return;
371
+ }
372
+ o({ status: "loading", moduleKey: t }), n?.(t);
373
+ let c = !1;
374
+ return l().then((p) => {
375
+ c || (o({ status: "loaded", moduleKey: t, Component: p }), s?.(t));
376
+ }).catch((p) => {
377
+ if (!c) {
378
+ const d = p instanceof Error ? p.message : "Failed to load module";
379
+ o({ status: "error", moduleKey: t, error: d }), r?.(`Failed to load ${t}: ${d}`);
380
+ }
381
+ }), () => {
382
+ c = !0;
383
+ };
384
+ }, [t, n, s, r]), a;
385
+ }
386
+ function le(e, t) {
387
+ const n = I(/* @__PURE__ */ new Set());
388
+ M(() => {
389
+ if (t < e.length - 1) {
390
+ const s = e[t + 1];
391
+ if (s && !n.current.has(s)) {
392
+ n.current.add(s);
393
+ const r = S[s];
394
+ r && r().catch(() => {
395
+ n.current.delete(s);
396
+ });
397
+ }
398
+ }
399
+ }, [e, t]);
400
+ }
401
+ const de = ({ config: e, onError: t }) => {
402
+ const { t: n } = $(), s = ie({
403
+ apiURL: e.apiURL,
404
+ token: e.token,
405
+ lang: e.lang,
406
+ disableDashboardTheme: e.disableDashboardTheme,
407
+ onError: t
408
+ }), [r, a] = B(() => s.flowManager, {
409
+ autoLoad: !1
410
+ }), o = ae({
411
+ moduleKey: r?.status === "ready" ? r.currentStep : void 0,
412
+ onModuleLoading: e.onModuleLoading,
413
+ onModuleLoaded: e.onModuleLoaded,
414
+ onError: t
415
+ });
416
+ if (le(
417
+ r?.status === "ready" ? r.steps : [],
418
+ r?.status === "ready" ? r.currentStepIndex : -1
419
+ ), M(() => {
420
+ if (r?.status === "ready" && e.wasmConfig) {
421
+ const l = r, c = R(l.flow);
422
+ c.length > 0 && (e.onWasmWarmup?.(c), A(l, e.wasmConfig));
423
+ }
424
+ }, [r, e]), M(() => {
425
+ r?.status === "finished" && e.onComplete(r.finishStatus);
426
+ }, [r?.status, e, r]), M(() => {
427
+ r?.status === "error" && t && t(r.error);
428
+ }, [r?.status, t, r]), s.status === "error")
429
+ return /* @__PURE__ */ i("div", { class: "IncodeFlow", children: /* @__PURE__ */ i("div", { children: [
430
+ "Error: ",
431
+ s.error
432
+ ] }) });
433
+ if (s.status === "initializing")
434
+ return /* @__PURE__ */ i("div", { class: "IncodeFlow", children: /* @__PURE__ */ i(
435
+ b,
436
+ {
437
+ title: e.spinnerConfig?.title ?? n("home.settingUp"),
438
+ subtitle: e.spinnerConfig?.subtitle,
439
+ size: e.spinnerConfig?.size,
440
+ fullScreen: !0
441
+ }
442
+ ) });
443
+ if (!r || r.status === "idle" || r.status === "loading")
444
+ return /* @__PURE__ */ i("div", { class: "IncodeFlow", children: /* @__PURE__ */ i(
445
+ b,
446
+ {
447
+ title: e.spinnerConfig?.title ?? n("home.settingUp"),
448
+ subtitle: e.spinnerConfig?.subtitle,
449
+ size: e.spinnerConfig?.size,
450
+ fullScreen: !0
451
+ }
452
+ ) });
453
+ if (r.status === "error")
454
+ return /* @__PURE__ */ i("div", { class: "IncodeFlow", children: /* @__PURE__ */ i("div", { children: [
455
+ "Error: ",
456
+ r.error
457
+ ] }) });
458
+ if (r.status === "finished")
459
+ return null;
460
+ if (r.status === "ready") {
461
+ const { currentStep: l, config: c } = r;
462
+ if (!l || !c)
463
+ return /* @__PURE__ */ i("div", { class: "IncodeFlow", children: /* @__PURE__ */ i(
464
+ b,
465
+ {
466
+ title: e.spinnerConfig?.title ?? n("loadingCircle.hangOn"),
467
+ subtitle: e.spinnerConfig?.subtitle ?? n("loadingCircle.validating"),
468
+ size: e.spinnerConfig?.size,
469
+ fullScreen: !0
470
+ }
471
+ ) });
472
+ if (o.status === "unsupported")
473
+ return /* @__PURE__ */ i("div", { class: "IncodeFlow", children: /* @__PURE__ */ i(
474
+ se,
475
+ {
476
+ moduleKey: l,
477
+ onNext: () => a.completeModule()
478
+ }
479
+ ) });
480
+ if (o.status === "idle" || o.status === "loading" || o.status === "error")
481
+ return /* @__PURE__ */ i("div", { class: "IncodeFlow", children: /* @__PURE__ */ i(
482
+ b,
483
+ {
484
+ title: e.spinnerConfig?.title ?? n("loadingCircle.hangOn"),
485
+ subtitle: e.spinnerConfig?.subtitle ?? n("loadingCircle.validating"),
486
+ size: e.spinnerConfig?.size,
487
+ fullScreen: !0
488
+ }
489
+ ) });
490
+ const { Component: p } = o;
491
+ if (l === "SELFIE")
492
+ return /* @__PURE__ */ i("div", { class: "IncodeFlow", children: /* @__PURE__ */ i(
493
+ p,
494
+ {
495
+ config: c,
496
+ onFinish: () => a.completeModule(),
497
+ onError: (u) => {
498
+ t?.(u ?? "Selfie verification error");
499
+ }
500
+ },
501
+ `selfie-${r.currentStepIndex}`
502
+ ) });
503
+ if (l === "PHONE")
504
+ return /* @__PURE__ */ i("div", { class: "IncodeFlow", children: /* @__PURE__ */ i(
505
+ p,
506
+ {
507
+ config: c,
508
+ onFinish: () => a.completeModule(),
509
+ onError: (u) => {
510
+ t?.(u ?? "Phone verification error");
511
+ }
512
+ },
513
+ `phone-${r.currentStepIndex}`
514
+ ) });
515
+ if (l === "EMAIL") {
516
+ const d = c;
517
+ return !d || typeof d.otpVerification != "boolean" || typeof d.otpExpirationInMinutes != "number" ? /* @__PURE__ */ i("div", { class: "IncodeFlow", children: /* @__PURE__ */ i("div", { children: "Error: Invalid email configuration" }) }) : /* @__PURE__ */ i("div", { class: "IncodeFlow", children: /* @__PURE__ */ i(
518
+ p,
519
+ {
520
+ config: {
521
+ ...d,
522
+ prefill: d.prefill ?? !1
523
+ },
524
+ onFinish: () => a.completeModule(),
525
+ onError: (u) => {
526
+ t?.(u ?? "Email verification error");
527
+ }
528
+ },
529
+ `email-${r.currentStepIndex}`
530
+ ) });
531
+ }
532
+ }
533
+ return null;
534
+ }, ce = ({ config: e, onError: t }) => /* @__PURE__ */ i("div", { class: "IncodeComponent", children: e ? /* @__PURE__ */ i(de, { config: e, onError: t }) : null });
535
+ H(ce, "incode-flow");
6
536
  export {
7
- i as IncodeFlow,
8
- a as preloadIncodeFlow
537
+ ce as IncodeFlow,
538
+ Ie as preloadIncodeFlow
9
539
  };