@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
package/dist/index.cjs
CHANGED
|
@@ -27,70 +27,207 @@ __export(index_exports, {
|
|
|
27
27
|
});
|
|
28
28
|
module.exports = __toCommonJS(index_exports);
|
|
29
29
|
|
|
30
|
-
// sdk/src/
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
// sdk/src/theme.ts
|
|
31
|
+
var MAX_THEME_PARAM_LENGTH = 4096;
|
|
32
|
+
var COLOR_KEYS = {
|
|
33
|
+
background: true,
|
|
34
|
+
surface: true,
|
|
35
|
+
surfaceMuted: true,
|
|
36
|
+
text: true,
|
|
37
|
+
textMuted: true,
|
|
38
|
+
border: true,
|
|
39
|
+
primary: true,
|
|
40
|
+
primaryPressed: true,
|
|
41
|
+
onPrimary: true,
|
|
42
|
+
accent: true,
|
|
43
|
+
progress: true,
|
|
44
|
+
success: true,
|
|
45
|
+
warning: true,
|
|
46
|
+
error: true,
|
|
47
|
+
illustration: true,
|
|
48
|
+
overlay: true,
|
|
49
|
+
cameraBackground: true,
|
|
50
|
+
oval: true,
|
|
51
|
+
ovalProgress: true,
|
|
52
|
+
closeButton: true
|
|
53
|
+
};
|
|
54
|
+
var COLOR_KEY_ORDER = Object.keys(COLOR_KEYS);
|
|
55
|
+
var COLOR_SCHEMES = ["auto", "light", "dark"];
|
|
56
|
+
var HEX_COLOR_RE = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;
|
|
57
|
+
var MAX_LISTED = 20;
|
|
58
|
+
var MAX_LISTED_NAME = 40;
|
|
59
|
+
var hasOwn = (object, key) => Object.prototype.hasOwnProperty.call(object, key);
|
|
60
|
+
function isRecord(value) {
|
|
61
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
62
|
+
}
|
|
63
|
+
function isUnset(value) {
|
|
64
|
+
return value === void 0 || value === null;
|
|
65
|
+
}
|
|
66
|
+
function isHexColor(value) {
|
|
67
|
+
return typeof value === "string" && value.length <= 7 && HEX_COLOR_RE.test(value);
|
|
68
|
+
}
|
|
69
|
+
function filterPalette(value, path, ignored) {
|
|
70
|
+
if (!isRecord(value)) {
|
|
71
|
+
ignored.push(path);
|
|
72
|
+
return void 0;
|
|
36
73
|
}
|
|
37
|
-
|
|
74
|
+
const valid = {};
|
|
75
|
+
for (const key of Object.keys(value)) {
|
|
76
|
+
const color = value[key];
|
|
77
|
+
if (isUnset(color)) continue;
|
|
78
|
+
if (hasOwn(COLOR_KEYS, key) && isHexColor(color)) {
|
|
79
|
+
valid[key] = color;
|
|
80
|
+
} else {
|
|
81
|
+
ignored.push(`${path}.${key}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const out = {};
|
|
85
|
+
let kept = false;
|
|
86
|
+
for (const key of COLOR_KEY_ORDER) {
|
|
87
|
+
const color = valid[key];
|
|
88
|
+
if (color !== void 0) {
|
|
89
|
+
out[key] = color;
|
|
90
|
+
kept = true;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return kept ? out : void 0;
|
|
38
94
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
95
|
+
function filterTheme(input, ignored) {
|
|
96
|
+
let colorScheme;
|
|
97
|
+
let colors;
|
|
98
|
+
let darkColors;
|
|
99
|
+
for (const key of Object.keys(input)) {
|
|
100
|
+
const value = input[key];
|
|
101
|
+
if (isUnset(value)) continue;
|
|
102
|
+
if (key === "colorScheme") {
|
|
103
|
+
if (typeof value === "string" && COLOR_SCHEMES.indexOf(value) !== -1) {
|
|
104
|
+
colorScheme = value;
|
|
105
|
+
} else {
|
|
106
|
+
ignored.push(key);
|
|
107
|
+
}
|
|
108
|
+
} else if (key === "colors") {
|
|
109
|
+
colors = filterPalette(value, key, ignored);
|
|
110
|
+
} else if (key === "darkColors") {
|
|
111
|
+
darkColors = filterPalette(value, key, ignored);
|
|
112
|
+
} else {
|
|
113
|
+
ignored.push(key);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (colorScheme === void 0 && colors === void 0 && darkColors === void 0) {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
const theme = {};
|
|
120
|
+
if (colorScheme !== void 0) theme.colorScheme = colorScheme;
|
|
121
|
+
if (colors !== void 0) theme.colors = colors;
|
|
122
|
+
if (darkColors !== void 0) theme.darkColors = darkColors;
|
|
123
|
+
return theme;
|
|
124
|
+
}
|
|
125
|
+
function listNames(names) {
|
|
126
|
+
const shown = names.slice(0, MAX_LISTED).map((name) => name.length > MAX_LISTED_NAME ? `${name.slice(0, MAX_LISTED_NAME)}...` : name);
|
|
127
|
+
const more = names.length - shown.length;
|
|
128
|
+
return shown.join(", ") + (more > 0 ? ` and ${more} more` : "");
|
|
129
|
+
}
|
|
130
|
+
function warn(message) {
|
|
49
131
|
try {
|
|
50
|
-
|
|
132
|
+
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
133
|
+
console.warn(message);
|
|
134
|
+
}
|
|
51
135
|
} catch (e) {
|
|
52
|
-
throw new Error(`SolitonVerify: "url" is not a valid absolute URL`);
|
|
53
|
-
}
|
|
54
|
-
const isLocalHttp = url.protocol === "http:" && (url.hostname === "localhost" || url.hostname === "127.0.0.1");
|
|
55
|
-
if (configuredOrigin !== void 0 && url.origin !== configuredOrigin) {
|
|
56
|
-
throw new Error('SolitonVerify: "url" does not match the configured verificationOrigin');
|
|
57
136
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
137
|
+
}
|
|
138
|
+
function prepareTheme(source, warnPrefix, maxLength = MAX_THEME_PARAM_LENGTH) {
|
|
139
|
+
const ignored = [];
|
|
140
|
+
let theme = null;
|
|
141
|
+
let whole = "";
|
|
142
|
+
try {
|
|
143
|
+
const input = source.theme;
|
|
144
|
+
if (isUnset(input)) return { theme: null, param: null };
|
|
145
|
+
if (isRecord(input)) {
|
|
146
|
+
theme = filterTheme(input, ignored);
|
|
147
|
+
} else {
|
|
148
|
+
whole = "it is not an object";
|
|
149
|
+
}
|
|
150
|
+
} catch (e) {
|
|
151
|
+
theme = null;
|
|
152
|
+
whole = "it could not be read";
|
|
62
153
|
}
|
|
63
|
-
|
|
64
|
-
|
|
154
|
+
let param = null;
|
|
155
|
+
if (theme !== null) {
|
|
156
|
+
const json = JSON.stringify(theme);
|
|
157
|
+
if (json.length > maxLength) {
|
|
158
|
+
theme = null;
|
|
159
|
+
whole = `it is longer than ${maxLength} characters`;
|
|
160
|
+
} else {
|
|
161
|
+
param = json;
|
|
162
|
+
}
|
|
65
163
|
}
|
|
66
|
-
if (
|
|
67
|
-
|
|
68
|
-
|
|
164
|
+
if (whole !== "") {
|
|
165
|
+
warn(`${warnPrefix} theme ignored: ${whole}.`);
|
|
166
|
+
} else if (ignored.length > 0) {
|
|
167
|
+
warn(
|
|
168
|
+
`${warnPrefix} theme: ignored ${listNames(ignored)}. Colors must be "#rgb" or "#rrggbb" and colorScheme "auto", "light" or "dark".`
|
|
69
169
|
);
|
|
70
170
|
}
|
|
71
|
-
return {
|
|
171
|
+
return { theme, param };
|
|
172
|
+
}
|
|
173
|
+
function prefersDark() {
|
|
174
|
+
try {
|
|
175
|
+
return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-color-scheme: dark)").matches === true;
|
|
176
|
+
} catch (e) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
function activePalette(theme) {
|
|
181
|
+
var _a;
|
|
182
|
+
if (theme === null) return void 0;
|
|
183
|
+
const scheme = (_a = theme.colorScheme) != null ? _a : "auto";
|
|
184
|
+
const dark = scheme === "dark" || scheme === "auto" && prefersDark();
|
|
185
|
+
return dark ? theme.darkColors : theme.colors;
|
|
186
|
+
}
|
|
187
|
+
function relativeLuminance(hex) {
|
|
188
|
+
const digits = hex.length === 4 ? hex.slice(1).split("").map((digit) => digit + digit).join("") : hex.slice(1);
|
|
189
|
+
const channel = (offset) => {
|
|
190
|
+
const value = parseInt(digits.slice(offset, offset + 2), 16) / 255;
|
|
191
|
+
return value <= 0.04045 ? value / 12.92 : Math.pow((value + 0.055) / 1.055, 2.4);
|
|
192
|
+
};
|
|
193
|
+
return 0.2126 * channel(0) + 0.7152 * channel(2) + 0.0722 * channel(4);
|
|
194
|
+
}
|
|
195
|
+
function contrastRatio(a, b) {
|
|
196
|
+
const la = relativeLuminance(a);
|
|
197
|
+
const lb = relativeLuminance(b);
|
|
198
|
+
return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);
|
|
72
199
|
}
|
|
73
200
|
|
|
74
201
|
// sdk/src/overlay.ts
|
|
75
202
|
var MAX_Z_INDEX = "2147483647";
|
|
203
|
+
var DEFAULT_BACKDROP = "#0f110b";
|
|
204
|
+
var DEFAULT_CLOSE_FILL = "rgba(0,0,0,0.45)";
|
|
205
|
+
var LIGHT_INK = { hex: "#ffffff", rgb: "255,255,255" };
|
|
206
|
+
var DARK_INK = { hex: DEFAULT_BACKDROP, rgb: "15,17,11" };
|
|
207
|
+
function inkOn(backdrop) {
|
|
208
|
+
return contrastRatio(DARK_INK.hex, backdrop) > contrastRatio(LIGHT_INK.hex, backdrop) ? DARK_INK.rgb : LIGHT_INK.rgb;
|
|
209
|
+
}
|
|
76
210
|
var openOverlayCount = 0;
|
|
77
211
|
var savedBodyOverflow = "";
|
|
78
|
-
function createOverlay(iframeSrc, onCloseClick) {
|
|
212
|
+
function createOverlay(iframeSrc, onCloseClick, names, backdrop, closeFill) {
|
|
213
|
+
const background = backdrop != null ? backdrop : DEFAULT_BACKDROP;
|
|
214
|
+
const ink = backdrop === void 0 ? LIGHT_INK.rgb : inkOn(backdrop);
|
|
215
|
+
const closeInk = closeFill === void 0 ? LIGHT_INK.rgb : inkOn(closeFill);
|
|
79
216
|
const doc = document;
|
|
80
217
|
const container = doc.createElement("div");
|
|
81
|
-
container.setAttribute(
|
|
218
|
+
container.setAttribute(names.marker, "overlay");
|
|
82
219
|
container.style.cssText = [
|
|
83
220
|
"position:fixed",
|
|
84
221
|
"inset:0",
|
|
85
222
|
`z-index:${MAX_Z_INDEX}`,
|
|
86
|
-
|
|
223
|
+
`background:${background}`,
|
|
87
224
|
"display:block"
|
|
88
225
|
].join(";");
|
|
89
226
|
const style = doc.createElement("style");
|
|
90
|
-
style.textContent =
|
|
227
|
+
style.textContent = `@keyframes ${names.animation}{to{transform:rotate(360deg)}}`;
|
|
91
228
|
container.appendChild(style);
|
|
92
229
|
const loading = doc.createElement("div");
|
|
93
|
-
loading.setAttribute(
|
|
230
|
+
loading.setAttribute(names.marker, "loading");
|
|
94
231
|
loading.style.cssText = [
|
|
95
232
|
"position:absolute",
|
|
96
233
|
"inset:0",
|
|
@@ -99,7 +236,7 @@ function createOverlay(iframeSrc, onCloseClick) {
|
|
|
99
236
|
"align-items:center",
|
|
100
237
|
"justify-content:center",
|
|
101
238
|
"gap:14px",
|
|
102
|
-
|
|
239
|
+
`color:rgba(${ink},0.75)`,
|
|
103
240
|
"font:14px/1.4 -apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif"
|
|
104
241
|
].join(";");
|
|
105
242
|
const spinner = doc.createElement("div");
|
|
@@ -107,9 +244,9 @@ function createOverlay(iframeSrc, onCloseClick) {
|
|
|
107
244
|
"width:22px",
|
|
108
245
|
"height:22px",
|
|
109
246
|
"border-radius:999px",
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
247
|
+
`border:2px solid rgba(${ink},0.25)`,
|
|
248
|
+
`border-top-color:rgba(${ink},0.9)`,
|
|
249
|
+
`animation:${names.animation} 0.8s linear infinite`
|
|
113
250
|
].join(";");
|
|
114
251
|
const loadingText = doc.createElement("div");
|
|
115
252
|
loadingText.textContent = "Loading secure verification...";
|
|
@@ -118,7 +255,7 @@ function createOverlay(iframeSrc, onCloseClick) {
|
|
|
118
255
|
container.appendChild(loading);
|
|
119
256
|
const iframe = doc.createElement("iframe");
|
|
120
257
|
iframe.setAttribute("allow", "camera; microphone; fullscreen; autoplay");
|
|
121
|
-
iframe.setAttribute("title",
|
|
258
|
+
iframe.setAttribute("title", names.title);
|
|
122
259
|
iframe.style.cssText = [
|
|
123
260
|
"position:absolute",
|
|
124
261
|
"inset:0",
|
|
@@ -140,9 +277,9 @@ function createOverlay(iframeSrc, onCloseClick) {
|
|
|
140
277
|
"width:36px",
|
|
141
278
|
"height:36px",
|
|
142
279
|
"border-radius:999px",
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
280
|
+
`border:1px solid rgba(${closeInk},0.3)`,
|
|
281
|
+
`background:${closeFill != null ? closeFill : DEFAULT_CLOSE_FILL}`,
|
|
282
|
+
`color:rgba(${closeInk},0.85)`,
|
|
146
283
|
"font:20px/1 -apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif",
|
|
147
284
|
"cursor:pointer",
|
|
148
285
|
"padding:0"
|
|
@@ -173,43 +310,51 @@ function createOverlay(iframeSrc, onCloseClick) {
|
|
|
173
310
|
};
|
|
174
311
|
}
|
|
175
312
|
|
|
176
|
-
// sdk/src/
|
|
177
|
-
var EMBED_PROTOCOL = "soliton-v1";
|
|
178
|
-
|
|
179
|
-
// sdk/src/index.ts
|
|
313
|
+
// sdk/src/core.ts
|
|
180
314
|
var AUTO_CLOSE_DELAY_MS = 250;
|
|
181
315
|
var HELLO_INTERVAL_MS = 250;
|
|
182
316
|
var HELLO_MAX_PINGS = 40;
|
|
183
317
|
var READY_TIMEOUT_MS = 3e4;
|
|
184
|
-
function
|
|
318
|
+
function openOverlay(options, names, parseUrl) {
|
|
319
|
+
var _a;
|
|
185
320
|
if (!options || typeof options.url !== "string") {
|
|
186
|
-
throw new Error(
|
|
321
|
+
throw new Error(`${names.errorPrefix} open() requires an options object with a "url"`);
|
|
187
322
|
}
|
|
188
323
|
if (typeof options.onComplete !== "function") {
|
|
189
|
-
throw new Error(
|
|
324
|
+
throw new Error(`${names.errorPrefix} open() requires an onComplete callback`);
|
|
190
325
|
}
|
|
191
|
-
const { url, hostedOrigin } =
|
|
326
|
+
const { url, hostedOrigin } = parseUrl(options.url, options.verificationOrigin);
|
|
192
327
|
const src = new URL(url.toString());
|
|
193
328
|
src.searchParams.set("mode", "embed");
|
|
194
329
|
src.searchParams.set("sdk", "1");
|
|
330
|
+
for (const [key, value] of (_a = names.params) != null ? _a : []) src.searchParams.set(key, value);
|
|
195
331
|
if (options.locale) src.searchParams.set("locale", options.locale);
|
|
332
|
+
const theme = prepareTheme(options, names.errorPrefix);
|
|
333
|
+
if (theme.param !== null) src.searchParams.set("theme", theme.param);
|
|
196
334
|
let closed = false;
|
|
197
335
|
let terminalDelivered = false;
|
|
198
336
|
let loadTimedOut = false;
|
|
199
337
|
let autoCloseTimer = null;
|
|
200
338
|
let readyTimer = null;
|
|
201
|
-
const
|
|
339
|
+
const palette = activePalette(theme.theme);
|
|
340
|
+
const overlay = createOverlay(
|
|
341
|
+
src.toString(),
|
|
342
|
+
() => close(),
|
|
343
|
+
names.overlay,
|
|
344
|
+
palette == null ? void 0 : palette.overlay,
|
|
345
|
+
palette == null ? void 0 : palette.closeButton
|
|
346
|
+
);
|
|
202
347
|
let helloPings = 0;
|
|
203
348
|
const postHello = () => {
|
|
204
|
-
var
|
|
349
|
+
var _a2;
|
|
205
350
|
helloPings += 1;
|
|
206
351
|
if (helloPings > HELLO_MAX_PINGS) {
|
|
207
352
|
stopHello();
|
|
208
353
|
return;
|
|
209
354
|
}
|
|
210
355
|
try {
|
|
211
|
-
(
|
|
212
|
-
{ protocol:
|
|
356
|
+
(_a2 = overlay.iframe.contentWindow) == null ? void 0 : _a2.postMessage(
|
|
357
|
+
{ protocol: names.protocol, type: names.hello },
|
|
213
358
|
hostedOrigin
|
|
214
359
|
);
|
|
215
360
|
} catch (e) {
|
|
@@ -227,23 +372,23 @@ function open(options) {
|
|
|
227
372
|
readyTimer = null;
|
|
228
373
|
}
|
|
229
374
|
const onMessage = (event) => {
|
|
230
|
-
var
|
|
375
|
+
var _a2;
|
|
231
376
|
if (closed || loadTimedOut || terminalDelivered) return;
|
|
232
377
|
if (event.origin !== hostedOrigin) return;
|
|
233
378
|
if (!overlay.iframe.contentWindow || event.source !== overlay.iframe.contentWindow) {
|
|
234
379
|
return;
|
|
235
380
|
}
|
|
236
381
|
const data = event.data;
|
|
237
|
-
if (!data || typeof data !== "object" || data.protocol !==
|
|
382
|
+
if (!data || typeof data !== "object" || data.protocol !== names.protocol) {
|
|
238
383
|
return;
|
|
239
384
|
}
|
|
240
385
|
stopHello();
|
|
241
386
|
switch (data.type) {
|
|
242
|
-
case
|
|
387
|
+
case names.ready:
|
|
243
388
|
stopReadyWait();
|
|
244
389
|
overlay.markReady();
|
|
245
390
|
break;
|
|
246
|
-
case
|
|
391
|
+
case names.complete: {
|
|
247
392
|
if (terminalDelivered) break;
|
|
248
393
|
stopReadyWait();
|
|
249
394
|
terminalDelivered = true;
|
|
@@ -253,14 +398,14 @@ function open(options) {
|
|
|
253
398
|
});
|
|
254
399
|
break;
|
|
255
400
|
}
|
|
256
|
-
case
|
|
401
|
+
case names.error:
|
|
257
402
|
stopReadyWait();
|
|
258
|
-
(
|
|
403
|
+
(_a2 = options.onError) == null ? void 0 : _a2.call(options, {
|
|
259
404
|
code: typeof data.code === "string" ? data.code : "internal",
|
|
260
405
|
message: typeof data.message === "string" ? data.message : ""
|
|
261
406
|
});
|
|
262
407
|
break;
|
|
263
|
-
case
|
|
408
|
+
case names.close:
|
|
264
409
|
close();
|
|
265
410
|
break;
|
|
266
411
|
default:
|
|
@@ -269,11 +414,11 @@ function open(options) {
|
|
|
269
414
|
};
|
|
270
415
|
window.addEventListener("message", onMessage);
|
|
271
416
|
readyTimer = setTimeout(() => {
|
|
272
|
-
var
|
|
417
|
+
var _a2;
|
|
273
418
|
if (readyTimer === null || closed || terminalDelivered) return;
|
|
274
419
|
loadTimedOut = true;
|
|
275
420
|
try {
|
|
276
|
-
(
|
|
421
|
+
(_a2 = options.onError) == null ? void 0 : _a2.call(options, {
|
|
277
422
|
code: "load_timeout",
|
|
278
423
|
message: "Verification did not load. Please try again."
|
|
279
424
|
});
|
|
@@ -282,7 +427,7 @@ function open(options) {
|
|
|
282
427
|
}
|
|
283
428
|
}, READY_TIMEOUT_MS);
|
|
284
429
|
function close() {
|
|
285
|
-
var
|
|
430
|
+
var _a2;
|
|
286
431
|
if (closed) return;
|
|
287
432
|
closed = true;
|
|
288
433
|
if (autoCloseTimer !== null) clearTimeout(autoCloseTimer);
|
|
@@ -290,9 +435,88 @@ function open(options) {
|
|
|
290
435
|
stopHello();
|
|
291
436
|
window.removeEventListener("message", onMessage);
|
|
292
437
|
overlay.destroy();
|
|
293
|
-
if (!terminalDelivered) (
|
|
438
|
+
if (!terminalDelivered) (_a2 = options.onClose) == null ? void 0 : _a2.call(options);
|
|
294
439
|
}
|
|
295
440
|
return { close };
|
|
296
441
|
}
|
|
442
|
+
|
|
443
|
+
// sdk/src/trustedOrigin.ts
|
|
444
|
+
function trustedOrigin(value) {
|
|
445
|
+
const url = new URL(value);
|
|
446
|
+
const local = ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
|
|
447
|
+
if (url.origin !== value || url.username || url.password || value.includes("*") || url.protocol !== "https:" && !(url.protocol === "http:" && local)) {
|
|
448
|
+
throw new Error("Use an exact HTTPS origin (HTTP loopback is allowed for development)");
|
|
449
|
+
}
|
|
450
|
+
return url.origin;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// sdk/src/urlCheck.ts
|
|
454
|
+
var HOSTED_PATH_RE = /^\/v\/[0-9a-f]{32}$/;
|
|
455
|
+
function checkHostedUrl(raw, prefix, configuredOrigin, checkUnconfigured) {
|
|
456
|
+
let url;
|
|
457
|
+
try {
|
|
458
|
+
url = new URL(raw);
|
|
459
|
+
} catch (e) {
|
|
460
|
+
throw new Error(`${prefix} "url" is not a valid absolute URL`);
|
|
461
|
+
}
|
|
462
|
+
if (configuredOrigin !== void 0) {
|
|
463
|
+
if (url.origin !== configuredOrigin) {
|
|
464
|
+
throw new Error(`${prefix} "url" does not match the configured verificationOrigin`);
|
|
465
|
+
}
|
|
466
|
+
} else if (checkUnconfigured) {
|
|
467
|
+
checkUnconfigured(url);
|
|
468
|
+
} else {
|
|
469
|
+
throw new Error(`${prefix} open() requires "verificationOrigin"`);
|
|
470
|
+
}
|
|
471
|
+
if (url.username || url.password) {
|
|
472
|
+
throw new Error(`${prefix} "url" must not embed credentials`);
|
|
473
|
+
}
|
|
474
|
+
if (!HOSTED_PATH_RE.test(url.pathname)) {
|
|
475
|
+
throw new Error(
|
|
476
|
+
`${prefix} "url" does not look like a hosted verification URL (/v/{token})`
|
|
477
|
+
);
|
|
478
|
+
}
|
|
479
|
+
return { url, hostedOrigin: url.origin };
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// sdk/src/hostedUrl.ts
|
|
483
|
+
var ERROR_PREFIX = "SolitonVerify:";
|
|
484
|
+
var ALLOWED_HTTPS_ORIGINS = /* @__PURE__ */ new Set([
|
|
485
|
+
"https://soliton.id",
|
|
486
|
+
"https://staging.soliton.id"
|
|
487
|
+
]);
|
|
488
|
+
function parseHostedUrl(raw, verificationOrigin) {
|
|
489
|
+
const configuredOrigin = verificationOrigin === void 0 ? void 0 : trustedOrigin(verificationOrigin);
|
|
490
|
+
return checkHostedUrl(raw, ERROR_PREFIX, configuredOrigin, (url) => {
|
|
491
|
+
const isLocalHttp = url.protocol === "http:" && (url.hostname === "localhost" || url.hostname === "127.0.0.1");
|
|
492
|
+
if (!ALLOWED_HTTPS_ORIGINS.has(url.origin) && !isLocalHttp) {
|
|
493
|
+
throw new Error(
|
|
494
|
+
'SolitonVerify: "url" must be hosted on https://soliton.id or https://staging.soliton.id (http is allowed for localhost/127.0.0.1 development only)'
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// sdk/src/types.ts
|
|
501
|
+
var EMBED_PROTOCOL = "soliton-v1";
|
|
502
|
+
|
|
503
|
+
// sdk/src/index.ts
|
|
504
|
+
var SOLITON_NAMES = {
|
|
505
|
+
protocol: EMBED_PROTOCOL,
|
|
506
|
+
hello: "soliton:hello",
|
|
507
|
+
ready: "soliton:ready",
|
|
508
|
+
complete: "soliton:complete",
|
|
509
|
+
error: "soliton:error",
|
|
510
|
+
close: "soliton:close",
|
|
511
|
+
errorPrefix: "SolitonVerify:",
|
|
512
|
+
overlay: {
|
|
513
|
+
marker: "data-soliton-sdk",
|
|
514
|
+
animation: "soliton-sdk-spin",
|
|
515
|
+
title: "Soliton identity verification"
|
|
516
|
+
}
|
|
517
|
+
};
|
|
518
|
+
function open(options) {
|
|
519
|
+
return openOverlay(options, SOLITON_NAMES, parseHostedUrl);
|
|
520
|
+
}
|
|
297
521
|
var SolitonVerify = { open };
|
|
298
522
|
var index_default = SolitonVerify;
|
package/dist/index.d.ts
CHANGED
|
@@ -6,13 +6,19 @@
|
|
|
6
6
|
* the iframe, so anti-injection defenses update with each frontend release and the
|
|
7
7
|
* verdict never touches the customer page (only the verification id does).
|
|
8
8
|
*
|
|
9
|
+
* The lifecycle itself lives in core.ts; this entry injects the soliton-v1
|
|
10
|
+
* names and the Soliton origin allowlist. The white-label entry
|
|
11
|
+
* (white-label.ts) injects neutral ones instead and never imports this file.
|
|
12
|
+
*
|
|
9
13
|
* Built artifacts (npm run build:sdk):
|
|
10
14
|
* public/sdk/v1/soliton-web-sdk.js IIFE, global `SolitonVerify`
|
|
11
15
|
* public/sdk/v1/soliton-web-sdk.esm.js ESM, `import { open } ...`
|
|
12
16
|
* sdk/dist/index.mjs + index.cjs npm package `@soliton-id/web-sdk`
|
|
13
17
|
*/
|
|
18
|
+
import type { ThemeColorKey, ThemeColors, VerificationTheme } from "./theme";
|
|
14
19
|
import type { SolitonVerifyHandle, SolitonVerifyOptions } from "./types";
|
|
15
20
|
export type { SolitonVerifyHandle, SolitonVerifyOptions };
|
|
21
|
+
export type { ThemeColorKey, ThemeColors, VerificationTheme };
|
|
16
22
|
export declare function open(options: SolitonVerifyOptions): SolitonVerifyHandle;
|
|
17
23
|
export declare const SolitonVerify: {
|
|
18
24
|
open: typeof open;
|