@cross-deck/web 1.12.1 → 1.13.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 +10 -0
- package/README.md +35 -0
- package/dist/crossdeck.umd.min.js +2 -2
- package/dist/crossdeck.umd.min.js.map +1 -1
- package/dist/error-codes.json +1 -1
- package/dist/index.cjs +150 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +23 -2
- package/dist/index.d.ts +23 -2
- package/dist/index.mjs +147 -2
- package/dist/index.mjs.map +1 -1
- package/dist/react.cjs +186 -3
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.mts +40 -2
- package/dist/react.d.ts +40 -2
- package/dist/react.mjs +184 -3
- package/dist/react.mjs.map +1 -1
- package/dist/trust-C0RcpR5I.d.mts +91 -0
- package/dist/trust-C0RcpR5I.d.ts +91 -0
- package/dist/vue.cjs +168 -3
- package/dist/vue.cjs.map +1 -1
- package/dist/vue.d.mts +25 -1
- package/dist/vue.d.ts +25 -1
- package/dist/vue.mjs +166 -2
- package/dist/vue.mjs.map +1 -1
- package/package.json +1 -1
package/dist/error-codes.json
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -29,7 +29,9 @@ __export(index_exports, {
|
|
|
29
29
|
MemoryStorage: () => MemoryStorage,
|
|
30
30
|
SDK_NAME: () => SDK_NAME,
|
|
31
31
|
SDK_VERSION: () => SDK_VERSION,
|
|
32
|
-
|
|
32
|
+
TRUST_PANEL_ORIGIN: () => TRUST_PANEL_ORIGIN,
|
|
33
|
+
getErrorCode: () => getErrorCode,
|
|
34
|
+
mountTrustPanel: () => mountTrustPanel
|
|
33
35
|
});
|
|
34
36
|
module.exports = __toCommonJS(index_exports);
|
|
35
37
|
|
|
@@ -104,7 +106,7 @@ function typeMapForStatus(status) {
|
|
|
104
106
|
}
|
|
105
107
|
|
|
106
108
|
// src/_version.ts
|
|
107
|
-
var SDK_VERSION = "1.
|
|
109
|
+
var SDK_VERSION = "1.13.0";
|
|
108
110
|
var SDK_NAME = "@cross-deck/web";
|
|
109
111
|
|
|
110
112
|
// src/http.ts
|
|
@@ -361,6 +363,125 @@ function randomChars(count) {
|
|
|
361
363
|
return out.join("");
|
|
362
364
|
}
|
|
363
365
|
|
|
366
|
+
// src/trust.ts
|
|
367
|
+
var TRUST_PANEL_ORIGIN = "https://trust.cross-deck.com";
|
|
368
|
+
var MAX_WIDTH_PX = 360;
|
|
369
|
+
var INITIAL_HEIGHT_PX = 132;
|
|
370
|
+
var MIN_HEIGHT_PX = 96;
|
|
371
|
+
var MAX_HEIGHT_PX = 220;
|
|
372
|
+
var DEFAULT_TIMEOUT_MS2 = 15e3;
|
|
373
|
+
function mountTrustPanel(opts) {
|
|
374
|
+
const origin = normalizeOrigin(opts.origin) || TRUST_PANEL_ORIGIN;
|
|
375
|
+
const timeoutMs = clampInt(opts.timeoutMs, DEFAULT_TIMEOUT_MS2, 1e3, 12e4);
|
|
376
|
+
let settled = false;
|
|
377
|
+
let onMessage = null;
|
|
378
|
+
let timer = null;
|
|
379
|
+
let frame = null;
|
|
380
|
+
let resolveReady;
|
|
381
|
+
const ready = new Promise((res) => {
|
|
382
|
+
resolveReady = res;
|
|
383
|
+
});
|
|
384
|
+
function settle(result, reason) {
|
|
385
|
+
if (settled) return;
|
|
386
|
+
settled = true;
|
|
387
|
+
if (timer) safe(() => clearTimeout(timer));
|
|
388
|
+
if (onMessage) safe(() => window.removeEventListener("message", onMessage));
|
|
389
|
+
if (result) {
|
|
390
|
+
safe(() => opts.onToken?.(result));
|
|
391
|
+
resolveReady(result);
|
|
392
|
+
} else {
|
|
393
|
+
const why = reason || "unavailable";
|
|
394
|
+
safe(() => opts.onUnavailable?.(why));
|
|
395
|
+
resolveReady({ token: null, expiresAt: null, reason: why });
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
try {
|
|
399
|
+
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
400
|
+
queueMicrotask(() => settle(null, "no_dom"));
|
|
401
|
+
return makeHandle();
|
|
402
|
+
}
|
|
403
|
+
const host = resolveTarget(opts.target);
|
|
404
|
+
frame = createFrame(origin, opts.publicKey);
|
|
405
|
+
if (!host) {
|
|
406
|
+
queueMicrotask(() => settle(null, "no_mount_target"));
|
|
407
|
+
return makeHandle();
|
|
408
|
+
}
|
|
409
|
+
onMessage = (ev) => {
|
|
410
|
+
if (ev.origin !== origin) return;
|
|
411
|
+
if (!ev.data || !frame || ev.source !== frame.contentWindow) return;
|
|
412
|
+
const d = ev.data;
|
|
413
|
+
if (d.type === "cd-trust-size" && typeof d.height === "number") {
|
|
414
|
+
safe(() => {
|
|
415
|
+
if (frame) frame.style.height = clampInt(d.height, INITIAL_HEIGHT_PX, MIN_HEIGHT_PX, MAX_HEIGHT_PX) + "px";
|
|
416
|
+
});
|
|
417
|
+
} else if (d.type === "cd-trust-token" && typeof d.token === "string") {
|
|
418
|
+
settle({ token: d.token, expiresAt: typeof d.expMs === "number" ? d.expMs : null });
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
window.addEventListener("message", onMessage);
|
|
422
|
+
host.appendChild(frame);
|
|
423
|
+
timer = setTimeout(() => settle(null, "timeout"), timeoutMs);
|
|
424
|
+
} catch (err) {
|
|
425
|
+
queueMicrotask(() => settle(null, "mount_error:" + safeMessage(err)));
|
|
426
|
+
}
|
|
427
|
+
return makeHandle();
|
|
428
|
+
function makeHandle() {
|
|
429
|
+
return {
|
|
430
|
+
frame,
|
|
431
|
+
ready,
|
|
432
|
+
destroy() {
|
|
433
|
+
if (onMessage) safe(() => window.removeEventListener("message", onMessage));
|
|
434
|
+
if (timer) safe(() => clearTimeout(timer));
|
|
435
|
+
safe(() => frame?.parentNode?.removeChild(frame));
|
|
436
|
+
settle(null, "destroyed");
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
function createFrame(origin, publicKey) {
|
|
442
|
+
const frame = document.createElement("iframe");
|
|
443
|
+
frame.title = "Protected by Crossdeck Trust";
|
|
444
|
+
frame.setAttribute("aria-label", "Protected by Crossdeck Trust");
|
|
445
|
+
frame.setAttribute("scrolling", "no");
|
|
446
|
+
frame.setAttribute("allowtransparency", "true");
|
|
447
|
+
frame.style.cssText = "border:0;display:block;width:100%;max-width:" + MAX_WIDTH_PX + "px;height:" + INITIAL_HEIGHT_PX + "px;margin:0;background:transparent;color-scheme:light;";
|
|
448
|
+
frame.src = origin + "/panel?k=" + encodeURIComponent(publicKey || "");
|
|
449
|
+
return frame;
|
|
450
|
+
}
|
|
451
|
+
function resolveTarget(target) {
|
|
452
|
+
try {
|
|
453
|
+
if (typeof target === "string") return document.querySelector(target);
|
|
454
|
+
return target || null;
|
|
455
|
+
} catch {
|
|
456
|
+
return null;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
function normalizeOrigin(o) {
|
|
460
|
+
if (!o || typeof o !== "string") return null;
|
|
461
|
+
try {
|
|
462
|
+
return new URL(o).origin;
|
|
463
|
+
} catch {
|
|
464
|
+
return null;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
function clampInt(v, fallback, min, max) {
|
|
468
|
+
const n = typeof v === "number" && isFinite(v) ? v : fallback;
|
|
469
|
+
return Math.min(Math.max(n, min), max);
|
|
470
|
+
}
|
|
471
|
+
function safe(fn) {
|
|
472
|
+
try {
|
|
473
|
+
fn();
|
|
474
|
+
} catch {
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
function safeMessage(err) {
|
|
478
|
+
try {
|
|
479
|
+
return err instanceof Error ? err.message : String(err);
|
|
480
|
+
} catch {
|
|
481
|
+
return "unknown";
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
364
485
|
// src/hash.ts
|
|
365
486
|
var K = new Uint32Array([
|
|
366
487
|
1116352408,
|
|
@@ -5823,6 +5944,30 @@ var CrossdeckClient = class {
|
|
|
5823
5944
|
getAnonymousId() {
|
|
5824
5945
|
return this.state ? this.state.identity.anonymousId : null;
|
|
5825
5946
|
}
|
|
5947
|
+
/**
|
|
5948
|
+
* **Crossdeck Trust** — human-proof at your signup, native to the SDK.
|
|
5949
|
+
*
|
|
5950
|
+
* `Crossdeck.trust.panel({ target, onToken })` renders the branded, un-restylable
|
|
5951
|
+
* Trust panel (the same cross-origin iframe on every install) and mints a
|
|
5952
|
+
* single-use attestation. Hand the token to your server and verify it at the gate
|
|
5953
|
+
* (`crossdeck.trust.gate(...)` in @cross-deck/node). The publishable key is taken
|
|
5954
|
+
* from your `init()` — you don't pass it again.
|
|
5955
|
+
*
|
|
5956
|
+
* Fail-open by contract: if the panel can't mint (adblocker, offline, our outage),
|
|
5957
|
+
* `ready` resolves with `{ token: null }` and your signup proceeds — the server
|
|
5958
|
+
* scores the missing token. It never throws and never blocks your form.
|
|
5959
|
+
*
|
|
5960
|
+
* @example
|
|
5961
|
+
* const { ready } = Crossdeck.trust.panel({ target: "#cd-trust" });
|
|
5962
|
+
* const result = await ready; // { token, expiresAt } | { token: null }
|
|
5963
|
+
* await createUser({ email, cdTrustToken: result.token });
|
|
5964
|
+
*/
|
|
5965
|
+
get trust() {
|
|
5966
|
+
const publicKey = this.state ? this.state.options.publicKey : "";
|
|
5967
|
+
return {
|
|
5968
|
+
panel: (input) => mountTrustPanel({ ...input, publicKey })
|
|
5969
|
+
};
|
|
5970
|
+
}
|
|
5826
5971
|
// ---------- private helpers ----------
|
|
5827
5972
|
requireStarted() {
|
|
5828
5973
|
if (!this.state) {
|
|
@@ -6615,6 +6760,8 @@ var CrossdeckContracts = {
|
|
|
6615
6760
|
MemoryStorage,
|
|
6616
6761
|
SDK_NAME,
|
|
6617
6762
|
SDK_VERSION,
|
|
6618
|
-
|
|
6763
|
+
TRUST_PANEL_ORIGIN,
|
|
6764
|
+
getErrorCode,
|
|
6765
|
+
mountTrustPanel
|
|
6619
6766
|
});
|
|
6620
6767
|
//# sourceMappingURL=index.cjs.map
|