@soliton-id/web-sdk 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/README.md +52 -2
- package/dist/core.d.ts +49 -0
- package/dist/hostedUrl.d.ts +7 -12
- package/dist/index.cjs +293 -69
- package/dist/index.d.ts +6 -0
- package/dist/index.mjs +293 -69
- package/dist/overlay.d.ts +18 -2
- package/dist/theme.d.ts +61 -0
- package/dist/types.d.ts +18 -2
- package/dist/urlCheck.d.ts +23 -0
- package/dist/white-label.cjs +541 -0
- package/dist/white-label.d.ts +80 -0
- package/dist/white-label.mjs +521 -0
- package/package.json +6 -1
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
|
|
21
|
+
// sdk/src/theme.ts
|
|
22
|
+
var MAX_THEME_PARAM_LENGTH = 4096;
|
|
23
|
+
var COLOR_KEYS = {
|
|
24
|
+
background: true,
|
|
25
|
+
surface: true,
|
|
26
|
+
surfaceMuted: true,
|
|
27
|
+
text: true,
|
|
28
|
+
textMuted: true,
|
|
29
|
+
border: true,
|
|
30
|
+
primary: true,
|
|
31
|
+
primaryPressed: true,
|
|
32
|
+
onPrimary: true,
|
|
33
|
+
accent: true,
|
|
34
|
+
progress: true,
|
|
35
|
+
success: true,
|
|
36
|
+
warning: true,
|
|
37
|
+
error: true,
|
|
38
|
+
illustration: true,
|
|
39
|
+
overlay: true,
|
|
40
|
+
cameraBackground: true,
|
|
41
|
+
oval: true,
|
|
42
|
+
ovalProgress: true,
|
|
43
|
+
closeButton: true
|
|
44
|
+
};
|
|
45
|
+
var COLOR_KEY_ORDER = Object.keys(COLOR_KEYS);
|
|
46
|
+
var COLOR_SCHEMES = ["auto", "light", "dark"];
|
|
47
|
+
var HEX_COLOR_RE = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;
|
|
48
|
+
var MAX_LISTED = 20;
|
|
49
|
+
var MAX_LISTED_NAME = 40;
|
|
50
|
+
var hasOwn = (object, key) => Object.prototype.hasOwnProperty.call(object, key);
|
|
51
|
+
function isRecord(value) {
|
|
52
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
53
|
+
}
|
|
54
|
+
function isUnset(value) {
|
|
55
|
+
return value === void 0 || value === null;
|
|
56
|
+
}
|
|
57
|
+
function isHexColor(value) {
|
|
58
|
+
return typeof value === "string" && value.length <= 7 && HEX_COLOR_RE.test(value);
|
|
59
|
+
}
|
|
60
|
+
function filterPalette(value, path, ignored) {
|
|
61
|
+
if (!isRecord(value)) {
|
|
62
|
+
ignored.push(path);
|
|
63
|
+
return void 0;
|
|
64
|
+
}
|
|
65
|
+
const valid = {};
|
|
66
|
+
for (const key of Object.keys(value)) {
|
|
67
|
+
const color = value[key];
|
|
68
|
+
if (isUnset(color)) continue;
|
|
69
|
+
if (hasOwn(COLOR_KEYS, key) && isHexColor(color)) {
|
|
70
|
+
valid[key] = color;
|
|
71
|
+
} else {
|
|
72
|
+
ignored.push(`${path}.${key}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const out = {};
|
|
76
|
+
let kept = false;
|
|
77
|
+
for (const key of COLOR_KEY_ORDER) {
|
|
78
|
+
const color = valid[key];
|
|
79
|
+
if (color !== void 0) {
|
|
80
|
+
out[key] = color;
|
|
81
|
+
kept = true;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return kept ? out : void 0;
|
|
85
|
+
}
|
|
86
|
+
function filterTheme(input, ignored) {
|
|
87
|
+
let colorScheme;
|
|
88
|
+
let colors;
|
|
89
|
+
let darkColors;
|
|
90
|
+
for (const key of Object.keys(input)) {
|
|
91
|
+
const value = input[key];
|
|
92
|
+
if (isUnset(value)) continue;
|
|
93
|
+
if (key === "colorScheme") {
|
|
94
|
+
if (typeof value === "string" && COLOR_SCHEMES.indexOf(value) !== -1) {
|
|
95
|
+
colorScheme = value;
|
|
96
|
+
} else {
|
|
97
|
+
ignored.push(key);
|
|
98
|
+
}
|
|
99
|
+
} else if (key === "colors") {
|
|
100
|
+
colors = filterPalette(value, key, ignored);
|
|
101
|
+
} else if (key === "darkColors") {
|
|
102
|
+
darkColors = filterPalette(value, key, ignored);
|
|
103
|
+
} else {
|
|
104
|
+
ignored.push(key);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (colorScheme === void 0 && colors === void 0 && darkColors === void 0) {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
const theme = {};
|
|
111
|
+
if (colorScheme !== void 0) theme.colorScheme = colorScheme;
|
|
112
|
+
if (colors !== void 0) theme.colors = colors;
|
|
113
|
+
if (darkColors !== void 0) theme.darkColors = darkColors;
|
|
114
|
+
return theme;
|
|
115
|
+
}
|
|
116
|
+
function listNames(names) {
|
|
117
|
+
const shown = names.slice(0, MAX_LISTED).map((name) => name.length > MAX_LISTED_NAME ? `${name.slice(0, MAX_LISTED_NAME)}...` : name);
|
|
118
|
+
const more = names.length - shown.length;
|
|
119
|
+
return shown.join(", ") + (more > 0 ? ` and ${more} more` : "");
|
|
120
|
+
}
|
|
121
|
+
function warn(message) {
|
|
122
|
+
try {
|
|
123
|
+
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
124
|
+
console.warn(message);
|
|
125
|
+
}
|
|
126
|
+
} catch (e) {
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function prepareTheme(source, warnPrefix, maxLength = MAX_THEME_PARAM_LENGTH) {
|
|
130
|
+
const ignored = [];
|
|
131
|
+
let theme = null;
|
|
132
|
+
let whole = "";
|
|
133
|
+
try {
|
|
134
|
+
const input = source.theme;
|
|
135
|
+
if (isUnset(input)) return { theme: null, param: null };
|
|
136
|
+
if (isRecord(input)) {
|
|
137
|
+
theme = filterTheme(input, ignored);
|
|
138
|
+
} else {
|
|
139
|
+
whole = "it is not an object";
|
|
140
|
+
}
|
|
141
|
+
} catch (e) {
|
|
142
|
+
theme = null;
|
|
143
|
+
whole = "it could not be read";
|
|
144
|
+
}
|
|
145
|
+
let param = null;
|
|
146
|
+
if (theme !== null) {
|
|
147
|
+
const json = JSON.stringify(theme);
|
|
148
|
+
if (json.length > maxLength) {
|
|
149
|
+
theme = null;
|
|
150
|
+
whole = `it is longer than ${maxLength} characters`;
|
|
151
|
+
} else {
|
|
152
|
+
param = json;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (whole !== "") {
|
|
156
|
+
warn(`${warnPrefix} theme ignored: ${whole}.`);
|
|
157
|
+
} else if (ignored.length > 0) {
|
|
158
|
+
warn(
|
|
159
|
+
`${warnPrefix} theme: ignored ${listNames(ignored)}. Colors must be "#rgb" or "#rrggbb" and colorScheme "auto", "light" or "dark".`
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
return { theme, param };
|
|
163
|
+
}
|
|
164
|
+
function prefersDark() {
|
|
165
|
+
try {
|
|
166
|
+
return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-color-scheme: dark)").matches === true;
|
|
167
|
+
} catch (e) {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function activePalette(theme) {
|
|
172
|
+
var _a;
|
|
173
|
+
if (theme === null) return void 0;
|
|
174
|
+
const scheme = (_a = theme.colorScheme) != null ? _a : "auto";
|
|
175
|
+
const dark = scheme === "dark" || scheme === "auto" && prefersDark();
|
|
176
|
+
return dark ? theme.darkColors : theme.colors;
|
|
177
|
+
}
|
|
178
|
+
function relativeLuminance(hex) {
|
|
179
|
+
const digits = hex.length === 4 ? hex.slice(1).split("").map((digit) => digit + digit).join("") : hex.slice(1);
|
|
180
|
+
const channel = (offset) => {
|
|
181
|
+
const value = parseInt(digits.slice(offset, offset + 2), 16) / 255;
|
|
182
|
+
return value <= 0.04045 ? value / 12.92 : Math.pow((value + 0.055) / 1.055, 2.4);
|
|
183
|
+
};
|
|
184
|
+
return 0.2126 * channel(0) + 0.7152 * channel(2) + 0.0722 * channel(4);
|
|
185
|
+
}
|
|
186
|
+
function contrastRatio(a, b) {
|
|
187
|
+
const la = relativeLuminance(a);
|
|
188
|
+
const lb = relativeLuminance(b);
|
|
189
|
+
return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// sdk/src/overlay.ts
|
|
193
|
+
var MAX_Z_INDEX = "2147483647";
|
|
194
|
+
var DEFAULT_BACKDROP = "#0f110b";
|
|
195
|
+
var DEFAULT_CLOSE_FILL = "rgba(0,0,0,0.45)";
|
|
196
|
+
var LIGHT_INK = { hex: "#ffffff", rgb: "255,255,255" };
|
|
197
|
+
var DARK_INK = { hex: DEFAULT_BACKDROP, rgb: "15,17,11" };
|
|
198
|
+
function inkOn(backdrop) {
|
|
199
|
+
return contrastRatio(DARK_INK.hex, backdrop) > contrastRatio(LIGHT_INK.hex, backdrop) ? DARK_INK.rgb : LIGHT_INK.rgb;
|
|
200
|
+
}
|
|
201
|
+
var openOverlayCount = 0;
|
|
202
|
+
var savedBodyOverflow = "";
|
|
203
|
+
function createOverlay(iframeSrc, onCloseClick, names, backdrop, closeFill) {
|
|
204
|
+
const background = backdrop != null ? backdrop : DEFAULT_BACKDROP;
|
|
205
|
+
const ink = backdrop === void 0 ? LIGHT_INK.rgb : inkOn(backdrop);
|
|
206
|
+
const closeInk = closeFill === void 0 ? LIGHT_INK.rgb : inkOn(closeFill);
|
|
207
|
+
const doc = document;
|
|
208
|
+
const container = doc.createElement("div");
|
|
209
|
+
container.setAttribute(names.marker, "overlay");
|
|
210
|
+
container.style.cssText = [
|
|
211
|
+
"position:fixed",
|
|
212
|
+
"inset:0",
|
|
213
|
+
`z-index:${MAX_Z_INDEX}`,
|
|
214
|
+
`background:${background}`,
|
|
215
|
+
"display:block"
|
|
216
|
+
].join(";");
|
|
217
|
+
const style = doc.createElement("style");
|
|
218
|
+
style.textContent = `@keyframes ${names.animation}{to{transform:rotate(360deg)}}`;
|
|
219
|
+
container.appendChild(style);
|
|
220
|
+
const loading = doc.createElement("div");
|
|
221
|
+
loading.setAttribute(names.marker, "loading");
|
|
222
|
+
loading.style.cssText = [
|
|
223
|
+
"position:absolute",
|
|
224
|
+
"inset:0",
|
|
225
|
+
"display:flex",
|
|
226
|
+
"flex-direction:column",
|
|
227
|
+
"align-items:center",
|
|
228
|
+
"justify-content:center",
|
|
229
|
+
"gap:14px",
|
|
230
|
+
`color:rgba(${ink},0.75)`,
|
|
231
|
+
"font:14px/1.4 -apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif"
|
|
232
|
+
].join(";");
|
|
233
|
+
const spinner = doc.createElement("div");
|
|
234
|
+
spinner.style.cssText = [
|
|
235
|
+
"width:22px",
|
|
236
|
+
"height:22px",
|
|
237
|
+
"border-radius:999px",
|
|
238
|
+
`border:2px solid rgba(${ink},0.25)`,
|
|
239
|
+
`border-top-color:rgba(${ink},0.9)`,
|
|
240
|
+
`animation:${names.animation} 0.8s linear infinite`
|
|
241
|
+
].join(";");
|
|
242
|
+
const loadingText = doc.createElement("div");
|
|
243
|
+
loadingText.textContent = "Loading secure verification...";
|
|
244
|
+
loading.appendChild(spinner);
|
|
245
|
+
loading.appendChild(loadingText);
|
|
246
|
+
container.appendChild(loading);
|
|
247
|
+
const iframe = doc.createElement("iframe");
|
|
248
|
+
iframe.setAttribute("allow", "camera; microphone; fullscreen; autoplay");
|
|
249
|
+
iframe.setAttribute("title", names.title);
|
|
250
|
+
iframe.style.cssText = [
|
|
251
|
+
"position:absolute",
|
|
252
|
+
"inset:0",
|
|
253
|
+
"width:100%",
|
|
254
|
+
"height:100%",
|
|
255
|
+
"border:0",
|
|
256
|
+
"display:block"
|
|
257
|
+
].join(";");
|
|
258
|
+
iframe.src = iframeSrc;
|
|
259
|
+
container.appendChild(iframe);
|
|
260
|
+
const closeButton = doc.createElement("button");
|
|
261
|
+
closeButton.type = "button";
|
|
262
|
+
closeButton.setAttribute("aria-label", "Close verification");
|
|
263
|
+
closeButton.textContent = "\xD7";
|
|
264
|
+
closeButton.style.cssText = [
|
|
265
|
+
"position:absolute",
|
|
266
|
+
"top:14px",
|
|
267
|
+
"right:14px",
|
|
268
|
+
"width:36px",
|
|
269
|
+
"height:36px",
|
|
270
|
+
"border-radius:999px",
|
|
271
|
+
`border:1px solid rgba(${closeInk},0.3)`,
|
|
272
|
+
`background:${closeFill != null ? closeFill : DEFAULT_CLOSE_FILL}`,
|
|
273
|
+
`color:rgba(${closeInk},0.85)`,
|
|
274
|
+
"font:20px/1 -apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif",
|
|
275
|
+
"cursor:pointer",
|
|
276
|
+
"padding:0"
|
|
277
|
+
].join(";");
|
|
278
|
+
closeButton.addEventListener("click", onCloseClick);
|
|
279
|
+
container.appendChild(closeButton);
|
|
280
|
+
if (openOverlayCount === 0) {
|
|
281
|
+
savedBodyOverflow = doc.body.style.overflow;
|
|
282
|
+
}
|
|
283
|
+
openOverlayCount += 1;
|
|
284
|
+
doc.body.style.overflow = "hidden";
|
|
285
|
+
doc.body.appendChild(container);
|
|
286
|
+
let destroyed = false;
|
|
287
|
+
return {
|
|
288
|
+
iframe,
|
|
289
|
+
markReady() {
|
|
290
|
+
loading.style.display = "none";
|
|
291
|
+
},
|
|
292
|
+
destroy() {
|
|
293
|
+
if (destroyed) return;
|
|
294
|
+
destroyed = true;
|
|
295
|
+
openOverlayCount -= 1;
|
|
296
|
+
if (openOverlayCount === 0) {
|
|
297
|
+
doc.body.style.overflow = savedBodyOverflow;
|
|
298
|
+
}
|
|
299
|
+
if (container.parentNode) container.parentNode.removeChild(container);
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// sdk/src/core.ts
|
|
305
|
+
var AUTO_CLOSE_DELAY_MS = 250;
|
|
306
|
+
var HELLO_INTERVAL_MS = 250;
|
|
307
|
+
var HELLO_MAX_PINGS = 40;
|
|
308
|
+
var READY_TIMEOUT_MS = 3e4;
|
|
309
|
+
function openOverlay(options, names, parseUrl) {
|
|
310
|
+
var _a;
|
|
311
|
+
if (!options || typeof options.url !== "string") {
|
|
312
|
+
throw new Error(`${names.errorPrefix} open() requires an options object with a "url"`);
|
|
313
|
+
}
|
|
314
|
+
if (typeof options.onComplete !== "function") {
|
|
315
|
+
throw new Error(`${names.errorPrefix} open() requires an onComplete callback`);
|
|
316
|
+
}
|
|
317
|
+
const { url, hostedOrigin } = parseUrl(options.url, options.verificationOrigin);
|
|
318
|
+
const src = new URL(url.toString());
|
|
319
|
+
src.searchParams.set("mode", "embed");
|
|
320
|
+
src.searchParams.set("sdk", "1");
|
|
321
|
+
for (const [key, value] of (_a = names.params) != null ? _a : []) src.searchParams.set(key, value);
|
|
322
|
+
if (options.locale) src.searchParams.set("locale", options.locale);
|
|
323
|
+
const theme = prepareTheme(options, names.errorPrefix);
|
|
324
|
+
if (theme.param !== null) src.searchParams.set("theme", theme.param);
|
|
325
|
+
let closed = false;
|
|
326
|
+
let terminalDelivered = false;
|
|
327
|
+
let loadTimedOut = false;
|
|
328
|
+
let autoCloseTimer = null;
|
|
329
|
+
let readyTimer = null;
|
|
330
|
+
const palette = activePalette(theme.theme);
|
|
331
|
+
const overlay = createOverlay(
|
|
332
|
+
src.toString(),
|
|
333
|
+
() => close(),
|
|
334
|
+
names.overlay,
|
|
335
|
+
palette == null ? void 0 : palette.overlay,
|
|
336
|
+
palette == null ? void 0 : palette.closeButton
|
|
337
|
+
);
|
|
338
|
+
let helloPings = 0;
|
|
339
|
+
const postHello = () => {
|
|
340
|
+
var _a2;
|
|
341
|
+
helloPings += 1;
|
|
342
|
+
if (helloPings > HELLO_MAX_PINGS) {
|
|
343
|
+
stopHello();
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
try {
|
|
347
|
+
(_a2 = overlay.iframe.contentWindow) == null ? void 0 : _a2.postMessage(
|
|
348
|
+
{ protocol: names.protocol, type: names.hello },
|
|
349
|
+
hostedOrigin
|
|
350
|
+
);
|
|
351
|
+
} catch (e) {
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
const helloTimer = setInterval(postHello, HELLO_INTERVAL_MS);
|
|
355
|
+
const onIframeLoad = () => postHello();
|
|
356
|
+
overlay.iframe.addEventListener("load", onIframeLoad);
|
|
357
|
+
function stopHello() {
|
|
358
|
+
clearInterval(helloTimer);
|
|
359
|
+
overlay.iframe.removeEventListener("load", onIframeLoad);
|
|
360
|
+
}
|
|
361
|
+
function stopReadyWait() {
|
|
362
|
+
if (readyTimer !== null) clearTimeout(readyTimer);
|
|
363
|
+
readyTimer = null;
|
|
364
|
+
}
|
|
365
|
+
const onMessage = (event) => {
|
|
366
|
+
var _a2;
|
|
367
|
+
if (closed || loadTimedOut || terminalDelivered) return;
|
|
368
|
+
if (event.origin !== hostedOrigin) return;
|
|
369
|
+
if (!overlay.iframe.contentWindow || event.source !== overlay.iframe.contentWindow) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
const data = event.data;
|
|
373
|
+
if (!data || typeof data !== "object" || data.protocol !== names.protocol) {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
stopHello();
|
|
377
|
+
switch (data.type) {
|
|
378
|
+
case names.ready:
|
|
379
|
+
stopReadyWait();
|
|
380
|
+
overlay.markReady();
|
|
381
|
+
break;
|
|
382
|
+
case names.complete: {
|
|
383
|
+
if (terminalDelivered) break;
|
|
384
|
+
stopReadyWait();
|
|
385
|
+
terminalDelivered = true;
|
|
386
|
+
autoCloseTimer = setTimeout(() => close(), AUTO_CLOSE_DELAY_MS);
|
|
387
|
+
options.onComplete({
|
|
388
|
+
verificationId: typeof data.verificationId === "string" ? data.verificationId : ""
|
|
389
|
+
});
|
|
390
|
+
break;
|
|
391
|
+
}
|
|
392
|
+
case names.error:
|
|
393
|
+
stopReadyWait();
|
|
394
|
+
(_a2 = options.onError) == null ? void 0 : _a2.call(options, {
|
|
395
|
+
code: typeof data.code === "string" ? data.code : "internal",
|
|
396
|
+
message: typeof data.message === "string" ? data.message : ""
|
|
397
|
+
});
|
|
398
|
+
break;
|
|
399
|
+
case names.close:
|
|
400
|
+
close();
|
|
401
|
+
break;
|
|
402
|
+
default:
|
|
403
|
+
break;
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
window.addEventListener("message", onMessage);
|
|
407
|
+
readyTimer = setTimeout(() => {
|
|
408
|
+
var _a2;
|
|
409
|
+
if (readyTimer === null || closed || terminalDelivered) return;
|
|
410
|
+
loadTimedOut = true;
|
|
411
|
+
try {
|
|
412
|
+
(_a2 = options.onError) == null ? void 0 : _a2.call(options, {
|
|
413
|
+
code: "load_timeout",
|
|
414
|
+
message: "Verification did not load. Please try again."
|
|
415
|
+
});
|
|
416
|
+
} finally {
|
|
417
|
+
close();
|
|
418
|
+
}
|
|
419
|
+
}, READY_TIMEOUT_MS);
|
|
420
|
+
function close() {
|
|
421
|
+
var _a2;
|
|
422
|
+
if (closed) return;
|
|
423
|
+
closed = true;
|
|
424
|
+
if (autoCloseTimer !== null) clearTimeout(autoCloseTimer);
|
|
425
|
+
stopReadyWait();
|
|
426
|
+
stopHello();
|
|
427
|
+
window.removeEventListener("message", onMessage);
|
|
428
|
+
overlay.destroy();
|
|
429
|
+
if (!terminalDelivered) (_a2 = options.onClose) == null ? void 0 : _a2.call(options);
|
|
430
|
+
}
|
|
431
|
+
return { close };
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// sdk/src/trustedOrigin.ts
|
|
435
|
+
function trustedOrigin(value) {
|
|
436
|
+
const url = new URL(value);
|
|
437
|
+
const local = ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
|
|
438
|
+
if (url.origin !== value || url.username || url.password || value.includes("*") || url.protocol !== "https:" && !(url.protocol === "http:" && local)) {
|
|
439
|
+
throw new Error("Use an exact HTTPS origin (HTTP loopback is allowed for development)");
|
|
440
|
+
}
|
|
441
|
+
return url.origin;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
// sdk/src/urlCheck.ts
|
|
445
|
+
var HOSTED_PATH_RE = /^\/v\/[0-9a-f]{32}$/;
|
|
446
|
+
function checkHostedUrl(raw, prefix, configuredOrigin, checkUnconfigured) {
|
|
447
|
+
let url;
|
|
448
|
+
try {
|
|
449
|
+
url = new URL(raw);
|
|
450
|
+
} catch (e) {
|
|
451
|
+
throw new Error(`${prefix} "url" is not a valid absolute URL`);
|
|
452
|
+
}
|
|
453
|
+
if (configuredOrigin !== void 0) {
|
|
454
|
+
if (url.origin !== configuredOrigin) {
|
|
455
|
+
throw new Error(`${prefix} "url" does not match the configured verificationOrigin`);
|
|
456
|
+
}
|
|
457
|
+
} else if (checkUnconfigured) {
|
|
458
|
+
checkUnconfigured(url);
|
|
459
|
+
} else {
|
|
460
|
+
throw new Error(`${prefix} open() requires "verificationOrigin"`);
|
|
461
|
+
}
|
|
462
|
+
if (url.username || url.password) {
|
|
463
|
+
throw new Error(`${prefix} "url" must not embed credentials`);
|
|
464
|
+
}
|
|
465
|
+
if (!HOSTED_PATH_RE.test(url.pathname)) {
|
|
466
|
+
throw new Error(
|
|
467
|
+
`${prefix} "url" does not look like a hosted verification URL (/v/{token})`
|
|
468
|
+
);
|
|
469
|
+
}
|
|
470
|
+
return { url, hostedOrigin: url.origin };
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
// sdk/src/white-label.ts
|
|
474
|
+
var ERROR_PREFIX = "Verification SDK:";
|
|
475
|
+
var DEFAULT_TITLE = "Identity verification";
|
|
476
|
+
var PROTOCOL = "idv-v1";
|
|
477
|
+
var NAMES = {
|
|
478
|
+
protocol: PROTOCOL,
|
|
479
|
+
hello: "idv:hello",
|
|
480
|
+
ready: "idv:ready",
|
|
481
|
+
complete: "idv:complete",
|
|
482
|
+
error: "idv:error",
|
|
483
|
+
close: "idv:close",
|
|
484
|
+
errorPrefix: ERROR_PREFIX,
|
|
485
|
+
overlay: {
|
|
486
|
+
marker: "data-idv-sdk",
|
|
487
|
+
animation: "idv-sdk-spin",
|
|
488
|
+
title: DEFAULT_TITLE
|
|
489
|
+
},
|
|
490
|
+
params: [["embed_protocol", PROTOCOL]]
|
|
491
|
+
};
|
|
492
|
+
function parseVerificationUrl(raw, verificationOrigin) {
|
|
493
|
+
if (typeof verificationOrigin !== "string" || verificationOrigin === "") {
|
|
494
|
+
throw new Error(
|
|
495
|
+
`${ERROR_PREFIX} open() requires "verificationOrigin", the exact origin of your verification host (for example https://verify.example.com)`
|
|
496
|
+
);
|
|
497
|
+
}
|
|
498
|
+
let configuredOrigin;
|
|
499
|
+
try {
|
|
500
|
+
configuredOrigin = trustedOrigin(verificationOrigin);
|
|
501
|
+
} catch (e) {
|
|
502
|
+
throw new Error(
|
|
503
|
+
`${ERROR_PREFIX} "verificationOrigin" must be an exact HTTPS origin such as https://verify.example.com (HTTP loopback is allowed for development)`
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
return checkHostedUrl(raw, ERROR_PREFIX, configuredOrigin);
|
|
507
|
+
}
|
|
508
|
+
function open(options) {
|
|
509
|
+
const title = options && typeof options.title === "string" && options.title.trim() !== "" ? options.title : DEFAULT_TITLE;
|
|
510
|
+
return openOverlay(
|
|
511
|
+
options,
|
|
512
|
+
__spreadProps(__spreadValues({}, NAMES), { overlay: __spreadProps(__spreadValues({}, NAMES.overlay), { title }) }),
|
|
513
|
+
parseVerificationUrl
|
|
514
|
+
);
|
|
515
|
+
}
|
|
516
|
+
var verification = { open };
|
|
517
|
+
var white_label_default = verification;
|
|
518
|
+
export {
|
|
519
|
+
white_label_default as default,
|
|
520
|
+
open
|
|
521
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"//": "Publishable manifest for the npm Web SDK. No devDependencies and no own node_modules by design: every build runs from the front-end repository root with its existing toolchain (npm run build:sdk), so the lockfile never grows for packaging. dist/ is rebuilt automatically by the prepack hook and is not committed.",
|
|
3
3
|
"name": "@soliton-id/web-sdk",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.4.0",
|
|
5
5
|
"description": "Soliton identity verification for the browser: opens the hosted verification flow in a full-viewport overlay iframe on your page and reports lifecycle events. Verdicts and portraits are fetched by your backend, never exposed in the browser.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "Soliton",
|
|
@@ -28,6 +28,11 @@
|
|
|
28
28
|
"import": "./dist/index.mjs",
|
|
29
29
|
"require": "./dist/index.cjs"
|
|
30
30
|
},
|
|
31
|
+
"./white-label": {
|
|
32
|
+
"types": "./dist/white-label.d.ts",
|
|
33
|
+
"import": "./dist/white-label.mjs",
|
|
34
|
+
"require": "./dist/white-label.cjs"
|
|
35
|
+
},
|
|
31
36
|
"./server": {
|
|
32
37
|
"types": "./dist/server.d.ts",
|
|
33
38
|
"browser": null,
|