@soliton-id/web-sdk 1.1.2 → 1.3.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.
@@ -0,0 +1,331 @@
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/overlay.ts
22
+ var MAX_Z_INDEX = "2147483647";
23
+ var openOverlayCount = 0;
24
+ var savedBodyOverflow = "";
25
+ function createOverlay(iframeSrc, onCloseClick, names) {
26
+ const doc = document;
27
+ const container = doc.createElement("div");
28
+ container.setAttribute(names.marker, "overlay");
29
+ container.style.cssText = [
30
+ "position:fixed",
31
+ "inset:0",
32
+ `z-index:${MAX_Z_INDEX}`,
33
+ "background:#0f110b",
34
+ "display:block"
35
+ ].join(";");
36
+ const style = doc.createElement("style");
37
+ style.textContent = `@keyframes ${names.animation}{to{transform:rotate(360deg)}}`;
38
+ container.appendChild(style);
39
+ const loading = doc.createElement("div");
40
+ loading.setAttribute(names.marker, "loading");
41
+ loading.style.cssText = [
42
+ "position:absolute",
43
+ "inset:0",
44
+ "display:flex",
45
+ "flex-direction:column",
46
+ "align-items:center",
47
+ "justify-content:center",
48
+ "gap:14px",
49
+ "color:rgba(255,255,255,0.75)",
50
+ "font:14px/1.4 -apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif"
51
+ ].join(";");
52
+ const spinner = doc.createElement("div");
53
+ spinner.style.cssText = [
54
+ "width:22px",
55
+ "height:22px",
56
+ "border-radius:999px",
57
+ "border:2px solid rgba(255,255,255,0.25)",
58
+ "border-top-color:rgba(255,255,255,0.9)",
59
+ `animation:${names.animation} 0.8s linear infinite`
60
+ ].join(";");
61
+ const loadingText = doc.createElement("div");
62
+ loadingText.textContent = "Loading secure verification...";
63
+ loading.appendChild(spinner);
64
+ loading.appendChild(loadingText);
65
+ container.appendChild(loading);
66
+ const iframe = doc.createElement("iframe");
67
+ iframe.setAttribute("allow", "camera; microphone; fullscreen; autoplay");
68
+ iframe.setAttribute("title", names.title);
69
+ iframe.style.cssText = [
70
+ "position:absolute",
71
+ "inset:0",
72
+ "width:100%",
73
+ "height:100%",
74
+ "border:0",
75
+ "display:block"
76
+ ].join(";");
77
+ iframe.src = iframeSrc;
78
+ container.appendChild(iframe);
79
+ const closeButton = doc.createElement("button");
80
+ closeButton.type = "button";
81
+ closeButton.setAttribute("aria-label", "Close verification");
82
+ closeButton.textContent = "\xD7";
83
+ closeButton.style.cssText = [
84
+ "position:absolute",
85
+ "top:14px",
86
+ "right:14px",
87
+ "width:36px",
88
+ "height:36px",
89
+ "border-radius:999px",
90
+ "border:1px solid rgba(255,255,255,0.3)",
91
+ "background:rgba(0,0,0,0.45)",
92
+ "color:rgba(255,255,255,0.85)",
93
+ "font:20px/1 -apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif",
94
+ "cursor:pointer",
95
+ "padding:0"
96
+ ].join(";");
97
+ closeButton.addEventListener("click", onCloseClick);
98
+ container.appendChild(closeButton);
99
+ if (openOverlayCount === 0) {
100
+ savedBodyOverflow = doc.body.style.overflow;
101
+ }
102
+ openOverlayCount += 1;
103
+ doc.body.style.overflow = "hidden";
104
+ doc.body.appendChild(container);
105
+ let destroyed = false;
106
+ return {
107
+ iframe,
108
+ markReady() {
109
+ loading.style.display = "none";
110
+ },
111
+ destroy() {
112
+ if (destroyed) return;
113
+ destroyed = true;
114
+ openOverlayCount -= 1;
115
+ if (openOverlayCount === 0) {
116
+ doc.body.style.overflow = savedBodyOverflow;
117
+ }
118
+ if (container.parentNode) container.parentNode.removeChild(container);
119
+ }
120
+ };
121
+ }
122
+
123
+ // sdk/src/core.ts
124
+ var AUTO_CLOSE_DELAY_MS = 250;
125
+ var HELLO_INTERVAL_MS = 250;
126
+ var HELLO_MAX_PINGS = 40;
127
+ var READY_TIMEOUT_MS = 3e4;
128
+ function openOverlay(options, names, parseUrl) {
129
+ var _a;
130
+ if (!options || typeof options.url !== "string") {
131
+ throw new Error(`${names.errorPrefix} open() requires an options object with a "url"`);
132
+ }
133
+ if (typeof options.onComplete !== "function") {
134
+ throw new Error(`${names.errorPrefix} open() requires an onComplete callback`);
135
+ }
136
+ const { url, hostedOrigin } = parseUrl(options.url, options.verificationOrigin);
137
+ const src = new URL(url.toString());
138
+ src.searchParams.set("mode", "embed");
139
+ src.searchParams.set("sdk", "1");
140
+ for (const [key, value] of (_a = names.params) != null ? _a : []) src.searchParams.set(key, value);
141
+ if (options.locale) src.searchParams.set("locale", options.locale);
142
+ let closed = false;
143
+ let terminalDelivered = false;
144
+ let loadTimedOut = false;
145
+ let autoCloseTimer = null;
146
+ let readyTimer = null;
147
+ const overlay = createOverlay(src.toString(), () => close(), names.overlay);
148
+ let helloPings = 0;
149
+ const postHello = () => {
150
+ var _a2;
151
+ helloPings += 1;
152
+ if (helloPings > HELLO_MAX_PINGS) {
153
+ stopHello();
154
+ return;
155
+ }
156
+ try {
157
+ (_a2 = overlay.iframe.contentWindow) == null ? void 0 : _a2.postMessage(
158
+ { protocol: names.protocol, type: names.hello },
159
+ hostedOrigin
160
+ );
161
+ } catch (e) {
162
+ }
163
+ };
164
+ const helloTimer = setInterval(postHello, HELLO_INTERVAL_MS);
165
+ const onIframeLoad = () => postHello();
166
+ overlay.iframe.addEventListener("load", onIframeLoad);
167
+ function stopHello() {
168
+ clearInterval(helloTimer);
169
+ overlay.iframe.removeEventListener("load", onIframeLoad);
170
+ }
171
+ function stopReadyWait() {
172
+ if (readyTimer !== null) clearTimeout(readyTimer);
173
+ readyTimer = null;
174
+ }
175
+ const onMessage = (event) => {
176
+ var _a2;
177
+ if (closed || loadTimedOut || terminalDelivered) return;
178
+ if (event.origin !== hostedOrigin) return;
179
+ if (!overlay.iframe.contentWindow || event.source !== overlay.iframe.contentWindow) {
180
+ return;
181
+ }
182
+ const data = event.data;
183
+ if (!data || typeof data !== "object" || data.protocol !== names.protocol) {
184
+ return;
185
+ }
186
+ stopHello();
187
+ switch (data.type) {
188
+ case names.ready:
189
+ stopReadyWait();
190
+ overlay.markReady();
191
+ break;
192
+ case names.complete: {
193
+ if (terminalDelivered) break;
194
+ stopReadyWait();
195
+ terminalDelivered = true;
196
+ autoCloseTimer = setTimeout(() => close(), AUTO_CLOSE_DELAY_MS);
197
+ options.onComplete({
198
+ verificationId: typeof data.verificationId === "string" ? data.verificationId : ""
199
+ });
200
+ break;
201
+ }
202
+ case names.error:
203
+ stopReadyWait();
204
+ (_a2 = options.onError) == null ? void 0 : _a2.call(options, {
205
+ code: typeof data.code === "string" ? data.code : "internal",
206
+ message: typeof data.message === "string" ? data.message : ""
207
+ });
208
+ break;
209
+ case names.close:
210
+ close();
211
+ break;
212
+ default:
213
+ break;
214
+ }
215
+ };
216
+ window.addEventListener("message", onMessage);
217
+ readyTimer = setTimeout(() => {
218
+ var _a2;
219
+ if (readyTimer === null || closed || terminalDelivered) return;
220
+ loadTimedOut = true;
221
+ try {
222
+ (_a2 = options.onError) == null ? void 0 : _a2.call(options, {
223
+ code: "load_timeout",
224
+ message: "Verification did not load. Please try again."
225
+ });
226
+ } finally {
227
+ close();
228
+ }
229
+ }, READY_TIMEOUT_MS);
230
+ function close() {
231
+ var _a2;
232
+ if (closed) return;
233
+ closed = true;
234
+ if (autoCloseTimer !== null) clearTimeout(autoCloseTimer);
235
+ stopReadyWait();
236
+ stopHello();
237
+ window.removeEventListener("message", onMessage);
238
+ overlay.destroy();
239
+ if (!terminalDelivered) (_a2 = options.onClose) == null ? void 0 : _a2.call(options);
240
+ }
241
+ return { close };
242
+ }
243
+
244
+ // sdk/src/trustedOrigin.ts
245
+ function trustedOrigin(value) {
246
+ const url = new URL(value);
247
+ const local = ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
248
+ if (url.origin !== value || url.username || url.password || value.includes("*") || url.protocol !== "https:" && !(url.protocol === "http:" && local)) {
249
+ throw new Error("Use an exact HTTPS origin (HTTP loopback is allowed for development)");
250
+ }
251
+ return url.origin;
252
+ }
253
+
254
+ // sdk/src/urlCheck.ts
255
+ var HOSTED_PATH_RE = /^\/v\/[0-9a-f]{32}$/;
256
+ function checkHostedUrl(raw, prefix, configuredOrigin, checkUnconfigured) {
257
+ let url;
258
+ try {
259
+ url = new URL(raw);
260
+ } catch (e) {
261
+ throw new Error(`${prefix} "url" is not a valid absolute URL`);
262
+ }
263
+ if (configuredOrigin !== void 0) {
264
+ if (url.origin !== configuredOrigin) {
265
+ throw new Error(`${prefix} "url" does not match the configured verificationOrigin`);
266
+ }
267
+ } else if (checkUnconfigured) {
268
+ checkUnconfigured(url);
269
+ } else {
270
+ throw new Error(`${prefix} open() requires "verificationOrigin"`);
271
+ }
272
+ if (url.username || url.password) {
273
+ throw new Error(`${prefix} "url" must not embed credentials`);
274
+ }
275
+ if (!HOSTED_PATH_RE.test(url.pathname)) {
276
+ throw new Error(
277
+ `${prefix} "url" does not look like a hosted verification URL (/v/{token})`
278
+ );
279
+ }
280
+ return { url, hostedOrigin: url.origin };
281
+ }
282
+
283
+ // sdk/src/white-label.ts
284
+ var ERROR_PREFIX = "Verification SDK:";
285
+ var DEFAULT_TITLE = "Identity verification";
286
+ var PROTOCOL = "idv-v1";
287
+ var NAMES = {
288
+ protocol: PROTOCOL,
289
+ hello: "idv:hello",
290
+ ready: "idv:ready",
291
+ complete: "idv:complete",
292
+ error: "idv:error",
293
+ close: "idv:close",
294
+ errorPrefix: ERROR_PREFIX,
295
+ overlay: {
296
+ marker: "data-idv-sdk",
297
+ animation: "idv-sdk-spin",
298
+ title: DEFAULT_TITLE
299
+ },
300
+ params: [["embed_protocol", PROTOCOL]]
301
+ };
302
+ function parseVerificationUrl(raw, verificationOrigin) {
303
+ if (typeof verificationOrigin !== "string" || verificationOrigin === "") {
304
+ throw new Error(
305
+ `${ERROR_PREFIX} open() requires "verificationOrigin", the exact origin of your verification host (for example https://verify.example.com)`
306
+ );
307
+ }
308
+ let configuredOrigin;
309
+ try {
310
+ configuredOrigin = trustedOrigin(verificationOrigin);
311
+ } catch (e) {
312
+ throw new Error(
313
+ `${ERROR_PREFIX} "verificationOrigin" must be an exact HTTPS origin such as https://verify.example.com (HTTP loopback is allowed for development)`
314
+ );
315
+ }
316
+ return checkHostedUrl(raw, ERROR_PREFIX, configuredOrigin);
317
+ }
318
+ function open(options) {
319
+ const title = options && typeof options.title === "string" && options.title.trim() !== "" ? options.title : DEFAULT_TITLE;
320
+ return openOverlay(
321
+ options,
322
+ __spreadProps(__spreadValues({}, NAMES), { overlay: __spreadProps(__spreadValues({}, NAMES.overlay), { title }) }),
323
+ parseVerificationUrl
324
+ );
325
+ }
326
+ var verification = { open };
327
+ var white_label_default = verification;
328
+ export {
329
+ white_label_default as default,
330
+ open
331
+ };
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.1.2",
4
+ "version": "1.3.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,