@burdenoff/website-sdk 2026.1101.1 → 2026.1101.2
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/README.md +42 -8
- package/dist/analytics/index.js +19 -69
- package/dist/analytics/index.js.map +1 -1
- package/dist/analytics/index.mjs +3 -69
- package/dist/analytics/index.mjs.map +1 -1
- package/dist/avatar-live/index.js +1 -0
- package/dist/avatar-live/index.js.map +1 -1
- package/dist/avatar-live/index.mjs +1 -0
- package/dist/avatar-live/index.mjs.map +1 -1
- package/dist/avatar-live-view/index.js +10 -30
- package/dist/avatar-live-view/index.js.map +1 -1
- package/dist/avatar-live-view/index.mjs +4 -24
- package/dist/avatar-live-view/index.mjs.map +1 -1
- package/dist/chunk-23H4JUL4.js +41 -0
- package/dist/chunk-23H4JUL4.js.map +1 -0
- package/dist/chunk-34RX5P75.mjs +25 -0
- package/dist/chunk-34RX5P75.mjs.map +1 -0
- package/dist/chunk-3LFFY7AZ.js +184 -0
- package/dist/chunk-3LFFY7AZ.js.map +1 -0
- package/dist/chunk-3X26GE4S.js +2794 -0
- package/dist/chunk-3X26GE4S.js.map +1 -0
- package/dist/chunk-45GCA4GG.js +85 -0
- package/dist/chunk-45GCA4GG.js.map +1 -0
- package/dist/chunk-4SAGVLHN.js +876 -0
- package/dist/chunk-4SAGVLHN.js.map +1 -0
- package/dist/chunk-4U6YAII5.js +218 -0
- package/dist/chunk-4U6YAII5.js.map +1 -0
- package/dist/chunk-5GMTBOO6.js +21 -0
- package/dist/chunk-5GMTBOO6.js.map +1 -0
- package/dist/chunk-5JRJ57CL.mjs +329 -0
- package/dist/chunk-5JRJ57CL.mjs.map +1 -0
- package/dist/chunk-6C2DKIC7.js +4 -0
- package/dist/chunk-6C2DKIC7.js.map +1 -0
- package/dist/chunk-6IBFBWC5.mjs +17 -0
- package/dist/chunk-6IBFBWC5.mjs.map +1 -0
- package/dist/chunk-6KY2ZRVI.js +116 -0
- package/dist/chunk-6KY2ZRVI.js.map +1 -0
- package/dist/chunk-6VJT3SM4.mjs +182 -0
- package/dist/chunk-6VJT3SM4.mjs.map +1 -0
- package/dist/chunk-6YZUFMK2.mjs +40 -0
- package/dist/chunk-6YZUFMK2.mjs.map +1 -0
- package/dist/chunk-7A6R7CGG.js +47 -0
- package/dist/chunk-7A6R7CGG.js.map +1 -0
- package/dist/chunk-7PWL4V2R.js +4 -0
- package/dist/chunk-7PWL4V2R.js.map +1 -0
- package/dist/chunk-AA33WDYS.js +161 -0
- package/dist/chunk-AA33WDYS.js.map +1 -0
- package/dist/chunk-AHRGFXV2.js +525 -0
- package/dist/chunk-AHRGFXV2.js.map +1 -0
- package/dist/chunk-B63XLDZH.mjs +109 -0
- package/dist/chunk-B63XLDZH.mjs.map +1 -0
- package/dist/chunk-BX2USEWF.mjs +35 -0
- package/dist/chunk-BX2USEWF.mjs.map +1 -0
- package/dist/chunk-BYSZT35R.js +150 -0
- package/dist/chunk-BYSZT35R.js.map +1 -0
- package/dist/chunk-C6OJIHNO.js +12 -0
- package/dist/chunk-C6OJIHNO.js.map +1 -0
- package/dist/chunk-COOELBX7.mjs +63 -0
- package/dist/chunk-COOELBX7.mjs.map +1 -0
- package/dist/chunk-D2TW7MNC.mjs +2771 -0
- package/dist/chunk-D2TW7MNC.mjs.map +1 -0
- package/dist/chunk-D5KEZ6V6.mjs +3 -0
- package/dist/chunk-D5KEZ6V6.mjs.map +1 -0
- package/dist/chunk-E3GUGJMY.js +46 -0
- package/dist/chunk-E3GUGJMY.js.map +1 -0
- package/dist/chunk-EBZ2HGJ2.mjs +52 -0
- package/dist/chunk-EBZ2HGJ2.mjs.map +1 -0
- package/dist/chunk-EDLTUOIA.mjs +210 -0
- package/dist/chunk-EDLTUOIA.mjs.map +1 -0
- package/dist/chunk-EJQSOT4X.js +4 -0
- package/dist/chunk-EJQSOT4X.js.map +1 -0
- package/dist/chunk-EUPFS6MZ.mjs +2019 -0
- package/dist/chunk-EUPFS6MZ.mjs.map +1 -0
- package/dist/chunk-F3XWDC3B.js +77 -0
- package/dist/chunk-F3XWDC3B.js.map +1 -0
- package/dist/chunk-FFADMVIK.mjs +5127 -0
- package/dist/chunk-FFADMVIK.mjs.map +1 -0
- package/dist/chunk-FJWS7BKT.mjs +3 -0
- package/dist/chunk-FJWS7BKT.mjs.map +1 -0
- package/dist/chunk-FJZJDUOR.mjs +3 -0
- package/dist/chunk-FJZJDUOR.mjs.map +1 -0
- package/dist/chunk-GCFLCO2Z.mjs +145 -0
- package/dist/chunk-GCFLCO2Z.mjs.map +1 -0
- package/dist/chunk-GEXC4LRP.js +61 -0
- package/dist/chunk-GEXC4LRP.js.map +1 -0
- package/dist/chunk-GTRAXQGC.mjs +3 -0
- package/dist/chunk-GTRAXQGC.mjs.map +1 -0
- package/dist/chunk-IKOIRUKW.js +270 -0
- package/dist/chunk-IKOIRUKW.js.map +1 -0
- package/dist/chunk-IXTWOPRN.js +45 -0
- package/dist/chunk-IXTWOPRN.js.map +1 -0
- package/dist/chunk-JDXOXGOK.js +547 -0
- package/dist/chunk-JDXOXGOK.js.map +1 -0
- package/dist/chunk-JSLDWYV7.mjs +558 -0
- package/dist/chunk-JSLDWYV7.mjs.map +1 -0
- package/dist/chunk-JXLSTVBK.js +336 -0
- package/dist/chunk-JXLSTVBK.js.map +1 -0
- package/dist/chunk-KHYXK7FG.mjs +49 -0
- package/dist/chunk-KHYXK7FG.mjs.map +1 -0
- package/dist/chunk-KSMBOWQQ.js +2034 -0
- package/dist/chunk-KSMBOWQQ.js.map +1 -0
- package/dist/chunk-KU2PXHGB.mjs +83 -0
- package/dist/chunk-KU2PXHGB.mjs.map +1 -0
- package/dist/chunk-KZANIV3S.mjs +37 -0
- package/dist/chunk-KZANIV3S.mjs.map +1 -0
- package/dist/chunk-L4BP6YOB.js +20 -0
- package/dist/chunk-L4BP6YOB.js.map +1 -0
- package/dist/chunk-MRKA2OAF.mjs +75 -0
- package/dist/chunk-MRKA2OAF.mjs.map +1 -0
- package/dist/chunk-N5EC53MH.mjs +80 -0
- package/dist/chunk-N5EC53MH.mjs.map +1 -0
- package/dist/chunk-NZANQGDM.mjs +34 -0
- package/dist/chunk-NZANQGDM.mjs.map +1 -0
- package/dist/chunk-O4GS3XPZ.js +10 -0
- package/dist/chunk-O4GS3XPZ.js.map +1 -0
- package/dist/chunk-O76QDGRM.js +5154 -0
- package/dist/chunk-O76QDGRM.js.map +1 -0
- package/dist/chunk-OYEUNZJY.js +114 -0
- package/dist/chunk-OYEUNZJY.js.map +1 -0
- package/dist/chunk-PHXAGQNB.js +74 -0
- package/dist/chunk-PHXAGQNB.js.map +1 -0
- package/dist/chunk-PIHHPP7J.mjs +16 -0
- package/dist/chunk-PIHHPP7J.mjs.map +1 -0
- package/dist/chunk-PXRHVVOU.mjs +499 -0
- package/dist/chunk-PXRHVVOU.mjs.map +1 -0
- package/dist/chunk-QMA6U6AU.js +36 -0
- package/dist/chunk-QMA6U6AU.js.map +1 -0
- package/dist/chunk-R6J7IULF.js +44 -0
- package/dist/chunk-R6J7IULF.js.map +1 -0
- package/dist/chunk-R7G6TWIS.mjs +10 -0
- package/dist/chunk-R7G6TWIS.mjs.map +1 -0
- package/dist/chunk-RUMGFI6L.mjs +544 -0
- package/dist/chunk-RUMGFI6L.mjs.map +1 -0
- package/dist/chunk-S54JWSJF.js +565 -0
- package/dist/chunk-S54JWSJF.js.map +1 -0
- package/dist/chunk-SK5UGG6A.js +2041 -0
- package/dist/chunk-SK5UGG6A.js.map +1 -0
- package/dist/chunk-SKIYDKIS.mjs +70 -0
- package/dist/chunk-SKIYDKIS.mjs.map +1 -0
- package/dist/chunk-SZNS5IK6.mjs +322 -0
- package/dist/chunk-SZNS5IK6.mjs.map +1 -0
- package/dist/chunk-T7JIPZAC.js +66 -0
- package/dist/chunk-T7JIPZAC.js.map +1 -0
- package/dist/chunk-TGYQHO2E.mjs +864 -0
- package/dist/chunk-TGYQHO2E.mjs.map +1 -0
- package/dist/chunk-TT3MHN42.mjs +8 -0
- package/dist/chunk-TT3MHN42.mjs.map +1 -0
- package/dist/chunk-UM55U65W.mjs +268 -0
- package/dist/chunk-UM55U65W.mjs.map +1 -0
- package/dist/chunk-UQ2HALUD.js +72 -0
- package/dist/chunk-UQ2HALUD.js.map +1 -0
- package/dist/chunk-UXWT7G77.js +82 -0
- package/dist/chunk-UXWT7G77.js.map +1 -0
- package/dist/chunk-VNS5WDWO.mjs +7 -0
- package/dist/chunk-VNS5WDWO.mjs.map +1 -0
- package/dist/chunk-VRWZLGR7.js +4 -0
- package/dist/chunk-VRWZLGR7.js.map +1 -0
- package/dist/chunk-VZLDSNH4.mjs +22 -0
- package/dist/chunk-VZLDSNH4.mjs.map +1 -0
- package/dist/chunk-W6P3YETJ.js +92 -0
- package/dist/chunk-W6P3YETJ.js.map +1 -0
- package/dist/chunk-WPKFFQCR.mjs +90 -0
- package/dist/chunk-WPKFFQCR.mjs.map +1 -0
- package/dist/chunk-WTVTI5TO.mjs +22 -0
- package/dist/chunk-WTVTI5TO.mjs.map +1 -0
- package/dist/chunk-XJOBZ4RJ.js +44 -0
- package/dist/chunk-XJOBZ4RJ.js.map +1 -0
- package/dist/chunk-XP2JDNDU.js +325 -0
- package/dist/chunk-XP2JDNDU.js.map +1 -0
- package/dist/chunk-Y4V5CEWD.mjs +112 -0
- package/dist/chunk-Y4V5CEWD.mjs.map +1 -0
- package/dist/chunk-YERN2UWM.js +116 -0
- package/dist/chunk-YERN2UWM.js.map +1 -0
- package/dist/chunk-ZKJQWFAA.mjs +114 -0
- package/dist/chunk-ZKJQWFAA.mjs.map +1 -0
- package/dist/chunk-ZOON3S3Y.mjs +138 -0
- package/dist/chunk-ZOON3S3Y.mjs.map +1 -0
- package/dist/chunk-ZP6QRAYC.mjs +2024 -0
- package/dist/chunk-ZP6QRAYC.mjs.map +1 -0
- package/dist/chunk-ZSTFX7FV.js +9 -0
- package/dist/chunk-ZSTFX7FV.js.map +1 -0
- package/dist/client/index.js +23 -331
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +3 -330
- package/dist/client/index.mjs.map +1 -1
- package/dist/comparison/index.js +28 -111
- package/dist/comparison/index.js.map +1 -1
- package/dist/comparison/index.mjs +2 -107
- package/dist/comparison/index.mjs.map +1 -1
- package/dist/components/contact.js +21 -931
- package/dist/components/contact.js.map +1 -1
- package/dist/components/contact.mjs +12 -909
- package/dist/components/contact.mjs.map +1 -1
- package/dist/components/electron-download.js +12 -124
- package/dist/components/electron-download.js.map +1 -1
- package/dist/components/electron-download.mjs +4 -106
- package/dist/components/electron-download.mjs.map +1 -1
- package/dist/components/explore-cta.js +8 -112
- package/dist/components/explore-cta.js.map +1 -1
- package/dist/components/explore-cta.mjs +3 -114
- package/dist/components/explore-cta.mjs.map +1 -1
- package/dist/components/explore.js +62 -7833
- package/dist/components/explore.js.map +1 -1
- package/dist/components/explore.mjs +13 -7800
- package/dist/components/explore.mjs.map +1 -1
- package/dist/components/launch-countdown.js +8 -83
- package/dist/components/launch-countdown.js.map +1 -1
- package/dist/components/launch-countdown.mjs +3 -85
- package/dist/components/launch-countdown.mjs.map +1 -1
- package/dist/components/newsletter.js +20 -993
- package/dist/components/newsletter.js.map +1 -1
- package/dist/components/newsletter.mjs +11 -971
- package/dist/components/newsletter.mjs.map +1 -1
- package/dist/components/partners.js +24 -1302
- package/dist/components/partners.js.map +1 -1
- package/dist/components/partners.mjs +15 -1276
- package/dist/components/partners.mjs.map +1 -1
- package/dist/components/pricing.js +49 -1249
- package/dist/components/pricing.js.map +1 -1
- package/dist/components/pricing.mjs +8 -1226
- package/dist/components/pricing.mjs.map +1 -1
- package/dist/components/problems-solved.js +8 -150
- package/dist/components/problems-solved.js.map +1 -1
- package/dist/components/problems-solved.mjs +4 -133
- package/dist/components/problems-solved.mjs.map +1 -1
- package/dist/components/resource-links.js +8 -304
- package/dist/components/resource-links.js.map +1 -1
- package/dist/components/resource-links.mjs +5 -308
- package/dist/components/resource-links.mjs.map +1 -1
- package/dist/components/social-links.js +8 -343
- package/dist/components/social-links.js.map +1 -1
- package/dist/components/social-links.mjs +5 -347
- package/dist/components/social-links.mjs.map +1 -1
- package/dist/components/unsubscribe.js +10 -627
- package/dist/components/unsubscribe.js.map +1 -1
- package/dist/components/unsubscribe.mjs +6 -611
- package/dist/components/unsubscribe.mjs.map +1 -1
- package/dist/components/waitlist.js +21 -1001
- package/dist/components/waitlist.js.map +1 -1
- package/dist/components/waitlist.mjs +12 -982
- package/dist/components/waitlist.mjs.map +1 -1
- package/dist/components/website-switcher.js +12 -175
- package/dist/components/website-switcher.js.map +1 -1
- package/dist/components/website-switcher.mjs +4 -157
- package/dist/components/website-switcher.mjs.map +1 -1
- package/dist/content/index.js +118 -3616
- package/dist/content/index.js.map +1 -1
- package/dist/content/index.mjs +12 -3567
- package/dist/content/index.mjs.map +1 -1
- package/dist/hooks/index.js +37 -2321
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +6 -2318
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4145 -20599
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3766 -20567
- package/dist/index.mjs.map +1 -1
- package/dist/product/index.js +20 -393
- package/dist/product/index.js.map +1 -1
- package/dist/product/index.mjs +5 -394
- package/dist/product/index.mjs.map +1 -1
- package/dist/seo/index.js +8 -76
- package/dist/seo/index.js.map +1 -1
- package/dist/seo/index.mjs +3 -78
- package/dist/seo/index.mjs.map +1 -1
- package/dist/store/index.js +51 -2650
- package/dist/store/index.js.map +1 -1
- package/dist/store/index.mjs +13 -2619
- package/dist/store/index.mjs.map +1 -1
- package/dist/utils/index.js +69 -134
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +5 -122
- package/dist/utils/index.mjs.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import { __publicField } from './chunk-VNS5WDWO.mjs';
|
|
2
|
+
import { createContext, useMemo, useContext } from 'react';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
// src/client/security.ts
|
|
6
|
+
var LOOPBACK_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "::1"]);
|
|
7
|
+
var RESERVED_HEADERS = /* @__PURE__ */ new Set([
|
|
8
|
+
"authorization",
|
|
9
|
+
"cookie",
|
|
10
|
+
"x-actor-id",
|
|
11
|
+
"x-actor-type",
|
|
12
|
+
"x-consent-granted-by",
|
|
13
|
+
"x-consent-scope",
|
|
14
|
+
"x-consent-granted-at",
|
|
15
|
+
"x-consent-expires-at"
|
|
16
|
+
]);
|
|
17
|
+
function validateGatewayUrl(value) {
|
|
18
|
+
let url;
|
|
19
|
+
try {
|
|
20
|
+
url = new URL(value);
|
|
21
|
+
} catch {
|
|
22
|
+
throw new Error("Gateway URL must be a valid absolute URL");
|
|
23
|
+
}
|
|
24
|
+
if (url.protocol === "https:") {
|
|
25
|
+
return url.toString();
|
|
26
|
+
}
|
|
27
|
+
if (url.protocol === "http:" && LOOPBACK_HOSTS.has(url.hostname.toLowerCase())) {
|
|
28
|
+
return url.toString();
|
|
29
|
+
}
|
|
30
|
+
throw new Error("Gateway URL must use HTTPS unless it targets localhost");
|
|
31
|
+
}
|
|
32
|
+
function sanitizeHeaders(headers) {
|
|
33
|
+
if (!headers) return void 0;
|
|
34
|
+
return Object.fromEntries(
|
|
35
|
+
Object.entries(headers).filter(
|
|
36
|
+
([key]) => !RESERVED_HEADERS.has(key.toLowerCase())
|
|
37
|
+
)
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
var CF_ACCESS_GATED_HOSTS = /* @__PURE__ */ new Set([
|
|
41
|
+
"alphagraphql.burdenoff.com",
|
|
42
|
+
"alphagraphqlworkspaces.burdenoff.com"
|
|
43
|
+
]);
|
|
44
|
+
function cfAccessHeaders(gatewayUrl, cfAccess) {
|
|
45
|
+
const clientId = cfAccess?.clientId?.trim();
|
|
46
|
+
const clientSecret = cfAccess?.clientSecret?.trim();
|
|
47
|
+
if (!clientId || !clientSecret) return {};
|
|
48
|
+
let host;
|
|
49
|
+
try {
|
|
50
|
+
host = new URL(gatewayUrl).hostname.toLowerCase();
|
|
51
|
+
} catch {
|
|
52
|
+
return {};
|
|
53
|
+
}
|
|
54
|
+
if (!CF_ACCESS_GATED_HOSTS.has(host)) return {};
|
|
55
|
+
return {
|
|
56
|
+
"CF-Access-Client-Id": clientId,
|
|
57
|
+
"CF-Access-Client-Secret": clientSecret
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// src/client/graphql-client.ts
|
|
62
|
+
var _WebSDKClient = class _WebSDKClient {
|
|
63
|
+
constructor(config) {
|
|
64
|
+
__publicField(this, "config");
|
|
65
|
+
__publicField(this, "queryCache", /* @__PURE__ */ new Map());
|
|
66
|
+
__publicField(this, "inflight", /* @__PURE__ */ new Map());
|
|
67
|
+
this.config = {
|
|
68
|
+
...config,
|
|
69
|
+
gatewayUrl: validateGatewayUrl(config.gatewayUrl),
|
|
70
|
+
headers: sanitizeHeaders(config.headers)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
getConfig() {
|
|
74
|
+
return this.config;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Execute a GraphQL query (with deduplication and caching).
|
|
78
|
+
*
|
|
79
|
+
* Pass `{ cache: false }` to bypass the cache entirely — required for poll
|
|
80
|
+
* loops, where every tick must reach the network.
|
|
81
|
+
*/
|
|
82
|
+
async query(query, variables, options) {
|
|
83
|
+
if (options?.cache === false) {
|
|
84
|
+
return this.request(query, variables, true, options.timeoutMs);
|
|
85
|
+
}
|
|
86
|
+
const cacheKey = JSON.stringify({ query, variables });
|
|
87
|
+
const cached = this.queryCache.get(cacheKey);
|
|
88
|
+
if (cached) {
|
|
89
|
+
if (Date.now() - cached.ts < _WebSDKClient.CACHE_TTL) {
|
|
90
|
+
return cached.data;
|
|
91
|
+
}
|
|
92
|
+
this.queryCache.delete(cacheKey);
|
|
93
|
+
}
|
|
94
|
+
const existing = this.inflight.get(cacheKey);
|
|
95
|
+
if (existing) {
|
|
96
|
+
return existing;
|
|
97
|
+
}
|
|
98
|
+
const promise = this.request(query, variables, true, options?.timeoutMs).then((result) => {
|
|
99
|
+
if (result.data && !result.errors?.length) {
|
|
100
|
+
if (this.queryCache.size >= _WebSDKClient.MAX_CACHE_ENTRIES) {
|
|
101
|
+
const oldestEntry = this.queryCache.keys().next().value;
|
|
102
|
+
if (oldestEntry) {
|
|
103
|
+
this.queryCache.delete(oldestEntry);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
this.queryCache.set(cacheKey, { data: result, ts: Date.now() });
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
109
|
+
}).finally(() => {
|
|
110
|
+
this.inflight.delete(cacheKey);
|
|
111
|
+
});
|
|
112
|
+
this.inflight.set(cacheKey, promise);
|
|
113
|
+
return promise;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Execute a GraphQL mutation
|
|
117
|
+
*/
|
|
118
|
+
async mutate(mutation, variables, options) {
|
|
119
|
+
return this.request(mutation, variables, false, options?.timeoutMs);
|
|
120
|
+
}
|
|
121
|
+
/** HTTP statuses worth another attempt — transient server/edge conditions. */
|
|
122
|
+
static isRetriableStatus(status) {
|
|
123
|
+
return status === 429 || status === 408 || status >= 500 && status < 600;
|
|
124
|
+
}
|
|
125
|
+
static sleep(ms) {
|
|
126
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Perform the HTTP call with a hard timeout. Every outcome resolves to a
|
|
130
|
+
* GraphQLResponse — callers never hang, so a UI's `loading` state always
|
|
131
|
+
* settles into data or a renderable error.
|
|
132
|
+
*/
|
|
133
|
+
async attempt(query, variables, timeoutMs) {
|
|
134
|
+
const controller = new AbortController();
|
|
135
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
136
|
+
try {
|
|
137
|
+
const response = await fetch(this.config.gatewayUrl, {
|
|
138
|
+
method: "POST",
|
|
139
|
+
headers: {
|
|
140
|
+
"Content-Type": "application/json",
|
|
141
|
+
"x-product-id": this.config.productId,
|
|
142
|
+
...this.config.headers,
|
|
143
|
+
...cfAccessHeaders(this.config.gatewayUrl, this.config.cfAccess)
|
|
144
|
+
},
|
|
145
|
+
body: JSON.stringify({ query, variables }),
|
|
146
|
+
signal: controller.signal
|
|
147
|
+
});
|
|
148
|
+
if (!response.ok) {
|
|
149
|
+
console.error(
|
|
150
|
+
"[WebSDK] GraphQL request failed",
|
|
151
|
+
response.status,
|
|
152
|
+
response.statusText
|
|
153
|
+
);
|
|
154
|
+
return {
|
|
155
|
+
res: {
|
|
156
|
+
errors: [
|
|
157
|
+
{
|
|
158
|
+
message: `HTTP ${response.status}: ${response.statusText}`,
|
|
159
|
+
extensions: { code: `HTTP_${response.status}` }
|
|
160
|
+
}
|
|
161
|
+
]
|
|
162
|
+
},
|
|
163
|
+
retriable: _WebSDKClient.isRetriableStatus(response.status)
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
res: await response.json(),
|
|
168
|
+
retriable: false
|
|
169
|
+
};
|
|
170
|
+
} catch (error) {
|
|
171
|
+
const aborted = error instanceof Error && (error.name === "AbortError" || controller.signal.aborted);
|
|
172
|
+
const message = aborted ? `Request timed out after ${timeoutMs}ms` : error instanceof Error ? error.message : "Network error";
|
|
173
|
+
console.error("[WebSDK] Network error", message);
|
|
174
|
+
return {
|
|
175
|
+
res: {
|
|
176
|
+
errors: [
|
|
177
|
+
{
|
|
178
|
+
message,
|
|
179
|
+
extensions: { code: aborted ? "TIMEOUT" : "NETWORK_ERROR" }
|
|
180
|
+
}
|
|
181
|
+
]
|
|
182
|
+
},
|
|
183
|
+
// Transport-level failures are worth one more try; a genuine outage
|
|
184
|
+
// just fails twice quickly and still renders an error state.
|
|
185
|
+
retriable: true
|
|
186
|
+
};
|
|
187
|
+
} finally {
|
|
188
|
+
clearTimeout(timer);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
async request(query, variables, retry = true, timeoutOverrideMs) {
|
|
192
|
+
const timeoutMs = timeoutOverrideMs ?? this.config.timeoutMs ?? _WebSDKClient.DEFAULT_TIMEOUT_MS;
|
|
193
|
+
const maxRetries = retry ? this.config.maxRetries ?? _WebSDKClient.DEFAULT_MAX_RETRIES : 0;
|
|
194
|
+
let last;
|
|
195
|
+
for (let i = 0; i <= maxRetries; i++) {
|
|
196
|
+
const { res, retriable } = await this.attempt(
|
|
197
|
+
query,
|
|
198
|
+
variables,
|
|
199
|
+
timeoutMs
|
|
200
|
+
);
|
|
201
|
+
if (!retriable || i === maxRetries) return res;
|
|
202
|
+
last = res;
|
|
203
|
+
await _WebSDKClient.sleep(
|
|
204
|
+
_WebSDKClient.RETRY_BASE_DELAY_MS * (i + 1) + Math.random() * 200
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
return last;
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
__publicField(_WebSDKClient, "CACHE_TTL", 5 * 60 * 1e3);
|
|
211
|
+
// 5 minutes
|
|
212
|
+
__publicField(_WebSDKClient, "MAX_CACHE_ENTRIES", 100);
|
|
213
|
+
__publicField(_WebSDKClient, "DEFAULT_TIMEOUT_MS", 12e3);
|
|
214
|
+
__publicField(_WebSDKClient, "DEFAULT_MAX_RETRIES", 1);
|
|
215
|
+
__publicField(_WebSDKClient, "RETRY_BASE_DELAY_MS", 400);
|
|
216
|
+
var WebSDKClient = _WebSDKClient;
|
|
217
|
+
|
|
218
|
+
// src/client/gateway-resolver.ts
|
|
219
|
+
var PROD_GATEWAY = "https://graphql.burdenoff.com/global/graphql";
|
|
220
|
+
var ALPHA_GATEWAY = "https://alphagraphql.burdenoff.com/global/graphql";
|
|
221
|
+
function getLocalFallback() {
|
|
222
|
+
if (typeof window !== "undefined") {
|
|
223
|
+
return `${window.location.origin}/global/graphql`;
|
|
224
|
+
}
|
|
225
|
+
return "http://localhost:4000/global/graphql";
|
|
226
|
+
}
|
|
227
|
+
var PRODUCT_DOMAINS = [
|
|
228
|
+
"burdenoff.com",
|
|
229
|
+
"algoshred.com",
|
|
230
|
+
"vibecontrols.com",
|
|
231
|
+
"fluidgrids.com",
|
|
232
|
+
"botmanor.com",
|
|
233
|
+
"botlit.ai",
|
|
234
|
+
// legacy BotManor domain, still served
|
|
235
|
+
"bigconsole.com",
|
|
236
|
+
"gethealthybowl.com",
|
|
237
|
+
"headshotmarketing.com",
|
|
238
|
+
"timecampus.com",
|
|
239
|
+
"ggnomad.com",
|
|
240
|
+
"movethewheels.com",
|
|
241
|
+
"crewfoundry.com",
|
|
242
|
+
"planmagnet.com",
|
|
243
|
+
"eventfullymanaged.com",
|
|
244
|
+
"kadaikodi.com",
|
|
245
|
+
"assethandler.com",
|
|
246
|
+
"technospam.com",
|
|
247
|
+
"semanticfed.com",
|
|
248
|
+
"manufacturedops.com",
|
|
249
|
+
"theglobalfuel.com",
|
|
250
|
+
"housingvista.com",
|
|
251
|
+
"proserviceworld.com",
|
|
252
|
+
"mybodyshield.com",
|
|
253
|
+
"artistrybase.com",
|
|
254
|
+
"collabkin.com",
|
|
255
|
+
"brainyrich.com",
|
|
256
|
+
"theculturepost.com",
|
|
257
|
+
"comradecircle.com",
|
|
258
|
+
"cosmicintersection.com",
|
|
259
|
+
"govcitizenhub.com",
|
|
260
|
+
"intelwatchtower.com",
|
|
261
|
+
"ecoimpacthub.com",
|
|
262
|
+
"buildmyiq.com",
|
|
263
|
+
"fluidgrids.ai"
|
|
264
|
+
];
|
|
265
|
+
function isProductionHost(hostname) {
|
|
266
|
+
return PRODUCT_DOMAINS.some(
|
|
267
|
+
(d) => hostname === d || hostname === `www.${d}` || hostname === `app.${d}`
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
function isAlphaHost(hostname) {
|
|
271
|
+
return PRODUCT_DOMAINS.some(
|
|
272
|
+
(d) => hostname === `alpha.${d}` || hostname === `alphaapp.${d}` || hostname === `staging.${d}`
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
function resolveGatewayUrl(explicitUrl) {
|
|
276
|
+
if (explicitUrl && isAbsoluteUrl(explicitUrl) && !isLocalhostUrl(explicitUrl)) {
|
|
277
|
+
return explicitUrl;
|
|
278
|
+
}
|
|
279
|
+
if (typeof window === "undefined") {
|
|
280
|
+
return explicitUrl && isAbsoluteUrl(explicitUrl) ? explicitUrl : getLocalFallback();
|
|
281
|
+
}
|
|
282
|
+
const hostname = window.location.hostname.toLowerCase();
|
|
283
|
+
if (isProductionHost(hostname)) return PROD_GATEWAY;
|
|
284
|
+
if (isAlphaHost(hostname)) return ALPHA_GATEWAY;
|
|
285
|
+
return getLocalFallback();
|
|
286
|
+
}
|
|
287
|
+
function isAbsoluteUrl(url) {
|
|
288
|
+
try {
|
|
289
|
+
new URL(url);
|
|
290
|
+
return true;
|
|
291
|
+
} catch {
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
function isLocalhostUrl(url) {
|
|
296
|
+
try {
|
|
297
|
+
const parsed = new URL(url);
|
|
298
|
+
const h = parsed.hostname;
|
|
299
|
+
return h === "localhost" || h === "127.0.0.1" || h === "::1";
|
|
300
|
+
} catch {
|
|
301
|
+
return false;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
var WebSDKContext = createContext(null);
|
|
305
|
+
function WebSDKProvider({ config, children }) {
|
|
306
|
+
const client = useMemo(() => {
|
|
307
|
+
const resolvedConfig = {
|
|
308
|
+
...config,
|
|
309
|
+
gatewayUrl: resolveGatewayUrl(config.gatewayUrl)
|
|
310
|
+
};
|
|
311
|
+
return new WebSDKClient(resolvedConfig);
|
|
312
|
+
}, [config]);
|
|
313
|
+
return /* @__PURE__ */ jsx(WebSDKContext.Provider, { value: client, children });
|
|
314
|
+
}
|
|
315
|
+
function useWebSDK() {
|
|
316
|
+
const client = useContext(WebSDKContext);
|
|
317
|
+
if (!client) {
|
|
318
|
+
throw new Error("useWebSDK must be used within a WebSDKProvider");
|
|
319
|
+
}
|
|
320
|
+
return client;
|
|
321
|
+
}
|
|
322
|
+
function useWebSDKConfig() {
|
|
323
|
+
const client = useWebSDK();
|
|
324
|
+
return client.getConfig();
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
export { WebSDKClient, WebSDKProvider, cfAccessHeaders, resolveGatewayUrl, useWebSDK, useWebSDKConfig };
|
|
328
|
+
//# sourceMappingURL=chunk-5JRJ57CL.mjs.map
|
|
329
|
+
//# sourceMappingURL=chunk-5JRJ57CL.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client/security.ts","../src/client/graphql-client.ts","../src/client/gateway-resolver.ts","../src/client/provider.tsx"],"names":[],"mappings":";;;;;AAAA,IAAM,iCAAiB,IAAI,GAAA,CAAI,CAAC,WAAA,EAAa,WAAA,EAAa,KAAK,CAAC,CAAA;AAChE,IAAM,gBAAA,uBAAuB,GAAA,CAAI;AAAA,EAC/B,eAAA;AAAA,EACA,QAAA;AAAA,EACA,YAAA;AAAA,EACA,cAAA;AAAA,EACA,sBAAA;AAAA,EACA,iBAAA;AAAA,EACA,sBAAA;AAAA,EACA;AACF,CAAC,CAAA;AAEM,SAAS,mBAAmB,KAAA,EAAuB;AACxD,EAAA,IAAI,GAAA;AAEJ,EAAA,IAAI;AACF,IAAA,GAAA,GAAM,IAAI,IAAI,KAAK,CAAA;AAAA,EACrB,CAAA,CAAA,MAAQ;AACN,IAAA,MAAM,IAAI,MAAM,0CAA0C,CAAA;AAAA,EAC5D;AAEA,EAAA,IAAI,GAAA,CAAI,aAAa,QAAA,EAAU;AAC7B,IAAA,OAAO,IAAI,QAAA,EAAS;AAAA,EACtB;AAEA,EAAA,IACE,GAAA,CAAI,aAAa,OAAA,IACjB,cAAA,CAAe,IAAI,GAAA,CAAI,QAAA,CAAS,WAAA,EAAa,CAAA,EAC7C;AACA,IAAA,OAAO,IAAI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IAAA,MAAM,IAAI,MAAM,gDAAgD,CAAA;AAAA,EAClE;AACA,EAAA,OAAO,MAAA;AACT;AAMO,SAAS,eAAA,GAAsC;AACpD,EAAA,MAAM,SAAS,SAAA,EAAU;AACzB,EAAA,OAAO,OAAO,SAAA,EAAU;AAC1B","file":"chunk-5JRJ57CL.mjs","sourcesContent":["const LOOPBACK_HOSTS = new Set([\"localhost\", \"127.0.0.1\", \"::1\"]);\nconst RESERVED_HEADERS = new Set([\n \"authorization\",\n \"cookie\",\n \"x-actor-id\",\n \"x-actor-type\",\n \"x-consent-granted-by\",\n \"x-consent-scope\",\n \"x-consent-granted-at\",\n \"x-consent-expires-at\",\n]);\n\nexport function validateGatewayUrl(value: string): string {\n let url: URL;\n\n try {\n url = new URL(value);\n } catch {\n throw new Error(\"Gateway URL must be a valid absolute URL\");\n }\n\n if (url.protocol === \"https:\") {\n return url.toString();\n }\n\n if (\n url.protocol === \"http:\" &&\n LOOPBACK_HOSTS.has(url.hostname.toLowerCase())\n ) {\n return url.toString();\n }\n\n throw new Error(\"Gateway URL must use HTTPS unless it targets localhost\");\n}\n\nexport function sanitizeHeaders(\n headers?: Record<string, string>,\n): Record<string, string> | undefined {\n if (!headers) return undefined;\n\n return Object.fromEntries(\n Object.entries(headers).filter(\n ([key]) => !RESERVED_HEADERS.has(key.toLowerCase()),\n ),\n );\n}\n\n/**\n * Hostnames whose Cloudflare Access application gates the GraphQL gateway.\n *\n * Only the alpha gateways are gated; the production gateways are public, so a token is never\n * attached there even if one is configured.\n */\nconst CF_ACCESS_GATED_HOSTS = new Set([\n \"alphagraphql.burdenoff.com\",\n \"alphagraphqlworkspaces.burdenoff.com\",\n]);\n\n/**\n * Service-token headers for a gated gateway, or nothing.\n *\n * Returns an empty object unless the target really is a gated host AND both halves of the token\n * are present — a half-configured token would send a malformed credential to every request.\n */\nexport function cfAccessHeaders(\n gatewayUrl: string,\n cfAccess?: { clientId?: string; clientSecret?: string },\n): Record<string, string> {\n const clientId = cfAccess?.clientId?.trim();\n const clientSecret = cfAccess?.clientSecret?.trim();\n if (!clientId || !clientSecret) return {};\n\n let host: string;\n try {\n host = new URL(gatewayUrl).hostname.toLowerCase();\n } catch {\n return {};\n }\n if (!CF_ACCESS_GATED_HOSTS.has(host)) return {};\n\n return {\n \"CF-Access-Client-Id\": clientId,\n \"CF-Access-Client-Secret\": clientSecret,\n };\n}\n","/**\n * Lightweight GraphQL client for the Burdenoff Web SDK.\n * Uses native fetch - zero external dependencies.\n * All calls are unauthenticated (public gateway operations only).\n */\n\nimport {\n cfAccessHeaders,\n sanitizeHeaders,\n validateGatewayUrl,\n} from \"./security\";\n\nexport interface WebSDKClientConfig {\n /** Global public gateway URL (e.g. \"https://api.burdenoff.com/global/graphql\") */\n gatewayUrl: string;\n /** Platform product ID for scoping operations */\n productId: string;\n /** Product slug (used for public product queries) */\n productSlug?: string;\n /** reCAPTCHA site key (if not fetched from product config) */\n recaptchaSiteKey?: string;\n /** Rybbit analytics site ID */\n rybbitSiteId?: string;\n /** Custom headers to include in all requests */\n headers?: Record<string, string>;\n /**\n * Cloudflare Access service token, for the ALPHA gateway hosts only.\n *\n * `alphagraphql.burdenoff.com` sits behind a Cloudflare Access application, so an\n * unauthenticated browser XHR is answered with a 302 to the Access login on a different\n * origin — which the browser reports as an opaque CORS failure rather than a 401. Attaching\n * the service-token headers is how every app shell already passes that gate (fe-libs\n * `installGatewayFetchRewrite`); the website SDK previously had no equivalent, so contact,\n * newsletter, waitlist and explore all failed on alpha.\n *\n * Vite only inlines `VITE_*` into APP source, never into a bundled library, so the host app\n * must read `import.meta.env` and pass the values in. Production gateways are not gated and\n * receive no headers.\n */\n cfAccess?: { clientId?: string; clientSecret?: string };\n /**\n * Per-request timeout in ms. Kept below the gateway's operation timeout so a\n * stalled request surfaces as an error the UI can render, instead of leaving\n * a page stuck on loading skeletons forever. Default 12000.\n */\n timeoutMs?: number;\n /**\n * Extra attempts for transient failures (timeout / network / 5xx / 429) on\n * QUERIES ONLY. Mutations are never retried — a retried contact-form or\n * waitlist submit would double-submit. Default 1 (2 attempts total).\n */\n maxRetries?: number;\n}\n\n/**\n * Per-call overrides for {@link WebSDKClient.query}.\n *\n * The defaults (5-minute response cache + in-flight deduplication) are right\n * for the read-once content queries most SDK components make, and wrong for a\n * poll loop: the second poll of the same `(query, variables)` pair would be\n * served straight from the cache and the UI would freeze on the first\n * response forever. Pass `{ cache: false }` for anything polled.\n */\nexport interface WebSDKQueryOptions {\n /**\n * Use the response cache and in-flight deduplication. Default `true`.\n * `false` skips the cache read, the dedupe map AND the cache write, so the\n * call always hits the network and never poisons a later cached read.\n */\n cache?: boolean;\n /** Override the client-wide request timeout for this call only. */\n timeoutMs?: number;\n}\n\n/** Per-call overrides for {@link WebSDKClient.mutate}. */\nexport interface WebSDKMutateOptions {\n /** Override the client-wide request timeout for this call only. */\n timeoutMs?: number;\n}\n\nexport interface GraphQLResponse<T = Record<string, unknown>> {\n data?: T;\n errors?: Array<{\n message: string;\n locations?: Array<{ line: number; column: number }>;\n path?: Array<string | number>;\n extensions?: Record<string, unknown>;\n }>;\n}\n\nexport class WebSDKClient {\n private config: WebSDKClientConfig;\n private queryCache = new Map<\n string,\n { data: GraphQLResponse<unknown>; ts: number }\n >();\n private inflight = new Map<string, Promise<GraphQLResponse<unknown>>>();\n private static CACHE_TTL = 5 * 60 * 1000; // 5 minutes\n private static MAX_CACHE_ENTRIES = 100;\n private static DEFAULT_TIMEOUT_MS = 12_000;\n private static DEFAULT_MAX_RETRIES = 1;\n private static RETRY_BASE_DELAY_MS = 400;\n\n constructor(config: WebSDKClientConfig) {\n this.config = {\n ...config,\n gatewayUrl: validateGatewayUrl(config.gatewayUrl),\n headers: sanitizeHeaders(config.headers),\n };\n }\n\n getConfig(): WebSDKClientConfig {\n return this.config;\n }\n\n /**\n * Execute a GraphQL query (with deduplication and caching).\n *\n * Pass `{ cache: false }` to bypass the cache entirely — required for poll\n * loops, where every tick must reach the network.\n */\n async query<T = Record<string, unknown>>(\n query: string,\n variables?: Record<string, unknown>,\n options?: WebSDKQueryOptions,\n ): Promise<GraphQLResponse<T>> {\n // Uncached path: no cache read, no in-flight dedupe, no cache write.\n // Deliberately bypasses the dedupe map too — two identical polls issued a\n // few hundred ms apart must both hit the network, otherwise the second one\n // resolves with the first one's (already stale) snapshot.\n if (options?.cache === false) {\n return this.request<T>(query, variables, true, options.timeoutMs);\n }\n\n const cacheKey = JSON.stringify({ query, variables });\n\n // Return cached response if still valid, evict if expired\n const cached = this.queryCache.get(cacheKey);\n if (cached) {\n if (Date.now() - cached.ts < WebSDKClient.CACHE_TTL) {\n return cached.data as GraphQLResponse<T>;\n }\n this.queryCache.delete(cacheKey);\n }\n\n // Deduplicate: if same query is already in-flight, reuse the promise\n const existing = this.inflight.get(cacheKey);\n if (existing) {\n return existing as Promise<GraphQLResponse<T>>;\n }\n\n const promise = this.request<T>(query, variables, true, options?.timeoutMs)\n .then((result) => {\n // Cache successful responses only\n if (result.data && !result.errors?.length) {\n if (this.queryCache.size >= WebSDKClient.MAX_CACHE_ENTRIES) {\n const oldestEntry = this.queryCache.keys().next().value;\n if (oldestEntry) {\n this.queryCache.delete(oldestEntry);\n }\n }\n this.queryCache.set(cacheKey, { data: result, ts: Date.now() });\n }\n return result;\n })\n .finally(() => {\n this.inflight.delete(cacheKey);\n });\n\n this.inflight.set(cacheKey, promise);\n return promise;\n }\n\n /**\n * Execute a GraphQL mutation\n */\n async mutate<T = Record<string, unknown>>(\n mutation: string,\n variables?: Record<string, unknown>,\n options?: WebSDKMutateOptions,\n ): Promise<GraphQLResponse<T>> {\n // retry=false: a retried mutation could double-submit (contact form,\n // waitlist signup, order). Only the timeout applies here.\n return this.request<T>(mutation, variables, false, options?.timeoutMs);\n }\n\n /** HTTP statuses worth another attempt — transient server/edge conditions. */\n private static isRetriableStatus(status: number): boolean {\n return status === 429 || status === 408 || (status >= 500 && status < 600);\n }\n\n private static sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n\n /**\n * Perform the HTTP call with a hard timeout. Every outcome resolves to a\n * GraphQLResponse — callers never hang, so a UI's `loading` state always\n * settles into data or a renderable error.\n */\n private async attempt<T>(\n query: string,\n variables: Record<string, unknown> | undefined,\n timeoutMs: number,\n ): Promise<{ res: GraphQLResponse<T>; retriable: boolean }> {\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), timeoutMs);\n try {\n const response = await fetch(this.config.gatewayUrl, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-product-id\": this.config.productId,\n ...this.config.headers,\n ...cfAccessHeaders(this.config.gatewayUrl, this.config.cfAccess),\n },\n body: JSON.stringify({ query, variables }),\n signal: controller.signal,\n });\n\n if (!response.ok) {\n console.error(\n \"[WebSDK] GraphQL request failed\",\n response.status,\n response.statusText,\n );\n return {\n res: {\n errors: [\n {\n message: `HTTP ${response.status}: ${response.statusText}`,\n extensions: { code: `HTTP_${response.status}` },\n },\n ],\n },\n retriable: WebSDKClient.isRetriableStatus(response.status),\n };\n }\n\n return {\n res: (await response.json()) as GraphQLResponse<T>,\n retriable: false,\n };\n } catch (error) {\n const aborted =\n error instanceof Error &&\n (error.name === \"AbortError\" || controller.signal.aborted);\n const message = aborted\n ? `Request timed out after ${timeoutMs}ms`\n : error instanceof Error\n ? error.message\n : \"Network error\";\n console.error(\"[WebSDK] Network error\", message);\n return {\n res: {\n errors: [\n {\n message,\n extensions: { code: aborted ? \"TIMEOUT\" : \"NETWORK_ERROR\" },\n },\n ],\n },\n // Transport-level failures are worth one more try; a genuine outage\n // just fails twice quickly and still renders an error state.\n retriable: true,\n };\n } finally {\n clearTimeout(timer);\n }\n }\n\n private async request<T>(\n query: string,\n variables?: Record<string, unknown>,\n retry = true,\n timeoutOverrideMs?: number,\n ): Promise<GraphQLResponse<T>> {\n const timeoutMs =\n timeoutOverrideMs ??\n this.config.timeoutMs ??\n WebSDKClient.DEFAULT_TIMEOUT_MS;\n const maxRetries = retry\n ? (this.config.maxRetries ?? WebSDKClient.DEFAULT_MAX_RETRIES)\n : 0;\n\n let last: GraphQLResponse<T> | undefined;\n for (let i = 0; i <= maxRetries; i++) {\n const { res, retriable } = await this.attempt<T>(\n query,\n variables,\n timeoutMs,\n );\n if (!retriable || i === maxRetries) return res;\n last = res;\n // Small backoff with jitter so a burst of clients doesn't retry in lockstep.\n await WebSDKClient.sleep(\n WebSDKClient.RETRY_BASE_DELAY_MS * (i + 1) + Math.random() * 200,\n );\n }\n return last as GraphQLResponse<T>;\n }\n}\n","/**\n * Runtime gateway URL resolution for product marketing websites.\n *\n * Mirrors the app shell pattern from @burdenoff/fe-libs/shared/config/gatewayUrls\n * but scoped to the website SDK's needs (global gateway only, no workspace gateway).\n *\n * Resolution priority:\n * 1. Explicit `gatewayUrl` passed in config — used as-is only if it is a valid\n * absolute, non-localhost URL (relative/invalid values fall through)\n * 2. Hostname-based auto-detection:\n * - Production domains (vibecontrols.com, bigconsole.com, ...) → prod gateway\n * - Alpha domains (alpha.vibecontrols.com, ...) → alpha gateway\n * - Everything else (localhost, *.local.burdenoff.com) → relative `/global/graphql`\n */\n\nconst PROD_GATEWAY = \"https://graphql.burdenoff.com/global/graphql\";\nconst ALPHA_GATEWAY = \"https://alphagraphql.burdenoff.com/global/graphql\";\n/**\n * Build the local fallback URL. In a browser context we need an absolute\n * URL (the SDK's security validator rejects relative paths), so we\n * prepend `window.location.origin`. During SSR/build (no window) we\n * return a placeholder localhost URL that the validator accepts.\n */\nfunction getLocalFallback(): string {\n if (typeof window !== \"undefined\") {\n return `${window.location.origin}/global/graphql`;\n }\n return \"http://localhost:4000/global/graphql\";\n}\n\n/**\n * All known product domains. When the website is served from any of these,\n * we can determine the environment from the subdomain pattern.\n */\nconst PRODUCT_DOMAINS = [\n \"burdenoff.com\",\n \"algoshred.com\",\n \"vibecontrols.com\",\n \"fluidgrids.com\",\n \"botmanor.com\",\n \"botlit.ai\", // legacy BotManor domain, still served\n \"bigconsole.com\",\n \"gethealthybowl.com\",\n \"headshotmarketing.com\",\n \"timecampus.com\",\n \"ggnomad.com\",\n \"movethewheels.com\",\n \"crewfoundry.com\",\n \"planmagnet.com\",\n \"eventfullymanaged.com\",\n \"kadaikodi.com\",\n \"assethandler.com\",\n \"technospam.com\",\n \"semanticfed.com\",\n \"manufacturedops.com\",\n \"theglobalfuel.com\",\n \"housingvista.com\",\n \"proserviceworld.com\",\n \"mybodyshield.com\",\n \"artistrybase.com\",\n \"collabkin.com\",\n \"brainyrich.com\",\n \"theculturepost.com\",\n \"comradecircle.com\",\n \"cosmicintersection.com\",\n \"govcitizenhub.com\",\n \"intelwatchtower.com\",\n \"ecoimpacthub.com\",\n \"buildmyiq.com\",\n \"fluidgrids.ai\",\n];\n\nfunction isProductionHost(hostname: string): boolean {\n return PRODUCT_DOMAINS.some(\n (d) => hostname === d || hostname === `www.${d}` || hostname === `app.${d}`,\n );\n}\n\nfunction isAlphaHost(hostname: string): boolean {\n return PRODUCT_DOMAINS.some(\n (d) =>\n hostname === `alpha.${d}` ||\n hostname === `alphaapp.${d}` ||\n hostname === `staging.${d}`,\n );\n}\n\n/**\n * Resolve the global gateway URL at runtime based on the current hostname.\n *\n * @param explicitUrl - URL explicitly passed in SDK config. Honored only when\n * it is a valid absolute, non-localhost URL; relative/invalid values are\n * ignored so hostname auto-detection can resolve the correct gateway.\n * @returns Resolved gateway URL\n */\nexport function resolveGatewayUrl(explicitUrl?: string): string {\n // Only honor an explicit URL if it's an *absolute* URL and not a localhost\n // dev default. Consumers commonly pass a relative fallback like\n // `'/global/graphql'` when their build-time env var is unset; treating that\n // as authoritative would skip hostname auto-detection and then fail the\n // absolute-URL validator (blank page). A relative/invalid value is ignored\n // here so detection can resolve the correct prod/alpha gateway.\n if (\n explicitUrl &&\n isAbsoluteUrl(explicitUrl) &&\n !isLocalhostUrl(explicitUrl)\n ) {\n return explicitUrl;\n }\n\n if (typeof window === \"undefined\") {\n // SSR / build-time — can't detect hostname. Use the explicit URL only if\n // it's absolute; otherwise the localhost fallback (validator-safe).\n return explicitUrl && isAbsoluteUrl(explicitUrl)\n ? explicitUrl\n : getLocalFallback();\n }\n\n const hostname = window.location.hostname.toLowerCase();\n\n if (isProductionHost(hostname)) return PROD_GATEWAY;\n if (isAlphaHost(hostname)) return ALPHA_GATEWAY;\n\n // Local dev, *.local.burdenoff.com, or unknown — use relative URL\n // which the Vite proxy (dev) or nginx (containerized) will handle.\n return getLocalFallback();\n}\n\nfunction isAbsoluteUrl(url: string): boolean {\n try {\n new URL(url);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction isLocalhostUrl(url: string): boolean {\n try {\n const parsed = new URL(url);\n const h = parsed.hostname;\n return h === \"localhost\" || h === \"127.0.0.1\" || h === \"::1\";\n } catch {\n return false;\n }\n}\n","/**\n * React context provider for the Web SDK client.\n * Wraps the application with WebSDKClient configuration.\n */\n\"use client\";\n\nimport { createContext, useContext, useMemo } from \"react\";\nimport type { ReactNode } from \"react\";\n\nimport { resolveGatewayUrl } from \"./gateway-resolver\";\nimport { WebSDKClient, type WebSDKClientConfig } from \"./graphql-client\";\n\nconst WebSDKContext = createContext<WebSDKClient | null>(null);\n\nexport interface WebSDKProviderProps {\n /** SDK client configuration */\n config: WebSDKClientConfig;\n /** Child components */\n children: ReactNode;\n}\n\n/**\n * Provider component that makes the WebSDKClient available to all child components.\n *\n * @example\n * ```tsx\n * <WebSDKProvider config={{\n * gatewayUrl: \"https://api.burdenoff.com/global/graphql\",\n * productId: \"your-product-id\",\n * productSlug: \"your-product\",\n * }}>\n * <App />\n * </WebSDKProvider>\n * ```\n */\nexport function WebSDKProvider({ config, children }: WebSDKProviderProps) {\n const client = useMemo(() => {\n const resolvedConfig = {\n ...config,\n gatewayUrl: resolveGatewayUrl(config.gatewayUrl),\n };\n return new WebSDKClient(resolvedConfig);\n }, [config]);\n\n return (\n <WebSDKContext.Provider value={client}>{children}</WebSDKContext.Provider>\n );\n}\n\n/**\n * Hook to access the WebSDKClient instance.\n * Must be used within a WebSDKProvider.\n */\nexport function useWebSDK(): WebSDKClient {\n const client = useContext(WebSDKContext);\n if (!client) {\n throw new Error(\"useWebSDK must be used within a WebSDKProvider\");\n }\n return client;\n}\n\n/**\n * Hook to access the SDK configuration.\n * Useful for components that need config values like productId, recaptchaSiteKey, etc.\n */\nexport function useWebSDKConfig(): WebSDKClientConfig {\n const client = useWebSDK();\n return client.getConfig();\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-6C2DKIC7.js"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useState, useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
var RECAPTCHA_WIDGET_HEIGHT = 78;
|
|
4
|
+
function useDeferredRecaptcha(siteKey) {
|
|
5
|
+
const [engaged, setEngaged] = useState(false);
|
|
6
|
+
const arm = useCallback(() => setEngaged(true), []);
|
|
7
|
+
const enabled = siteKey.length > 0;
|
|
8
|
+
return {
|
|
9
|
+
armed: enabled && engaged,
|
|
10
|
+
arm,
|
|
11
|
+
formProps: enabled && !engaged ? { onFocus: arm, onPointerDown: arm } : {}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { RECAPTCHA_WIDGET_HEIGHT, useDeferredRecaptcha };
|
|
16
|
+
//# sourceMappingURL=chunk-6IBFBWC5.mjs.map
|
|
17
|
+
//# sourceMappingURL=chunk-6IBFBWC5.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-deferred-recaptcha.ts"],"names":[],"mappings":";;AAMO,IAAM,uBAAA,GAA0B;AAuBhC,SAAS,qBAAqB,OAAA,EAAoC;AACvE,EAAA,MAAM,CAAC,OAAA,EAAS,UAAU,CAAA,GAAI,SAAS,KAAK,CAAA;AAC5C,EAAA,MAAM,MAAM,WAAA,CAAY,MAAM,WAAW,IAAI,CAAA,EAAG,EAAE,CAAA;AAClD,EAAA,MAAM,OAAA,GAAU,QAAQ,MAAA,GAAS,CAAA;AACjC,EAAA,OAAO;AAAA,IACL,OAAO,OAAA,IAAW,OAAA;AAAA,IAClB,GAAA;AAAA,IACA,SAAA,EAAW,OAAA,IAAW,CAAC,OAAA,GAAU,EAAE,SAAS,GAAA,EAAK,aAAA,EAAe,GAAA,EAAI,GAAI;AAAC,GAC3E;AACF","file":"chunk-6IBFBWC5.mjs","sourcesContent":["import { useCallback, useState } from \"react\";\n\n/**\n * reCAPTCHA v2 widget height (normal size). Reserved before the widget mounts so\n * arming it does not shift the layout under the visitor's pointer.\n */\nexport const RECAPTCHA_WIDGET_HEIGHT = 78;\n\nexport interface DeferredRecaptcha {\n /** True once the visitor has engaged with the form AND a site key is configured. */\n armed: boolean;\n /** Mount the widget now (e.g. a submit that arrived before any focus). */\n arm: () => void;\n /** Spread onto the guarded <form>: the first focus or pointer press arms the widget. */\n formProps: { onFocus?: () => void; onPointerDown?: () => void };\n}\n\n/**\n * Mount Google reCAPTCHA only once the visitor engages with the form it guards.\n *\n * Mounting it eagerly loaded google.com/recaptcha on every page that carries a\n * newsletter or contact form — the site footer, so every page. That shipped\n * third-party JS nobody had asked for, logged Google's own CSP report-only\n * violations into the page console (Lighthouse best-practices\n * `errors-in-console` / `inspector-issues`), and let the injected <script> and\n * origin-trial <meta> leak into build-time prerendered snapshots ahead of\n * <meta charset>. The token check at submit is unchanged: an unarmed form has\n * no token, so a submit still asks the visitor to complete the challenge.\n */\nexport function useDeferredRecaptcha(siteKey: string): DeferredRecaptcha {\n const [engaged, setEngaged] = useState(false);\n const arm = useCallback(() => setEngaged(true), []);\n const enabled = siteKey.length > 0;\n return {\n armed: enabled && engaged,\n arm,\n formProps: enabled && !engaged ? { onFocus: arm, onPointerDown: arm } : {},\n };\n}\n"]}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/comparison/index.ts
|
|
4
|
+
var DEFAULT_COMPARISON_MAX_AGE_DAYS = 180;
|
|
5
|
+
var DAY_MS = 24 * 60 * 60 * 1e3;
|
|
6
|
+
var ISO_DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
7
|
+
function parseVerifiedAt(value) {
|
|
8
|
+
if (typeof value !== "string" || !ISO_DATE.test(value)) return null;
|
|
9
|
+
const date = /* @__PURE__ */ new Date(`${value}T00:00:00.000Z`);
|
|
10
|
+
if (Number.isNaN(date.getTime())) return null;
|
|
11
|
+
return date.toISOString().slice(0, 10) === value ? date : null;
|
|
12
|
+
}
|
|
13
|
+
function isHttpUrl(value) {
|
|
14
|
+
try {
|
|
15
|
+
const url = new URL(value);
|
|
16
|
+
return url.protocol === "https:" || url.protocol === "http:";
|
|
17
|
+
} catch {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function checkComparisonFreshness(claims, options = {}) {
|
|
22
|
+
const maxAgeDays = options.maxAgeDays ?? DEFAULT_COMPARISON_MAX_AGE_DAYS;
|
|
23
|
+
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
24
|
+
const issues = [];
|
|
25
|
+
for (const claim of claims) {
|
|
26
|
+
const sources = claim.sources ?? [];
|
|
27
|
+
if (sources.length === 0) {
|
|
28
|
+
issues.push({
|
|
29
|
+
path: claim.path,
|
|
30
|
+
problem: "missing-source",
|
|
31
|
+
detail: "no source: add { url, verifiedAt } for the vendor page this claim was checked against"
|
|
32
|
+
});
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
let newest = null;
|
|
36
|
+
for (const source of sources) {
|
|
37
|
+
if (!isHttpUrl(source.url)) {
|
|
38
|
+
issues.push({
|
|
39
|
+
path: claim.path,
|
|
40
|
+
problem: "invalid-url",
|
|
41
|
+
detail: `source URL is not an http(s) URL: ${JSON.stringify(source.url)}`
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const verified = parseVerifiedAt(source.verifiedAt);
|
|
45
|
+
if (!verified) {
|
|
46
|
+
issues.push({
|
|
47
|
+
path: claim.path,
|
|
48
|
+
problem: "invalid-date",
|
|
49
|
+
detail: `verifiedAt must be YYYY-MM-DD, got ${JSON.stringify(source.verifiedAt)}`
|
|
50
|
+
});
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (verified.getTime() > now.getTime() + DAY_MS) {
|
|
54
|
+
issues.push({
|
|
55
|
+
path: claim.path,
|
|
56
|
+
problem: "future-date",
|
|
57
|
+
detail: `verifiedAt ${source.verifiedAt} is in the future`
|
|
58
|
+
});
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (!newest || verified.getTime() > newest.getTime()) newest = verified;
|
|
62
|
+
}
|
|
63
|
+
if (newest) {
|
|
64
|
+
const ageDays = Math.floor((now.getTime() - newest.getTime()) / DAY_MS);
|
|
65
|
+
if (ageDays > maxAgeDays) {
|
|
66
|
+
issues.push({
|
|
67
|
+
path: claim.path,
|
|
68
|
+
problem: "stale",
|
|
69
|
+
detail: `last verified ${newest.toISOString().slice(0, 10)} (${ageDays} days ago, limit ${maxAgeDays}): re-read the vendor page and update verifiedAt or the claim`
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return issues;
|
|
75
|
+
}
|
|
76
|
+
function latestVerification(claims) {
|
|
77
|
+
let latest = null;
|
|
78
|
+
for (const claim of claims) {
|
|
79
|
+
for (const source of claim.sources ?? []) {
|
|
80
|
+
if (parseVerifiedAt(source.verifiedAt) && (!latest || source.verifiedAt > latest)) {
|
|
81
|
+
latest = source.verifiedAt;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return latest;
|
|
86
|
+
}
|
|
87
|
+
function oldestVerification(claims) {
|
|
88
|
+
let oldest = null;
|
|
89
|
+
for (const claim of claims) {
|
|
90
|
+
for (const source of claim.sources ?? []) {
|
|
91
|
+
if (parseVerifiedAt(source.verifiedAt) && (!oldest || source.verifiedAt < oldest)) {
|
|
92
|
+
oldest = source.verifiedAt;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return oldest;
|
|
97
|
+
}
|
|
98
|
+
function formatFreshnessReport(issues) {
|
|
99
|
+
if (issues.length === 0)
|
|
100
|
+
return "Comparison sources: all claims sourced and fresh.";
|
|
101
|
+
const lines = issues.map((i) => ` - [${i.problem}] ${i.path}: ${i.detail}`);
|
|
102
|
+
return [
|
|
103
|
+
`Comparison sources: ${issues.length} problem(s) found.`,
|
|
104
|
+
...lines,
|
|
105
|
+
"Re-check each claim against the vendor's current page, then update the claim and its verifiedAt."
|
|
106
|
+
].join("\n");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
exports.DEFAULT_COMPARISON_MAX_AGE_DAYS = DEFAULT_COMPARISON_MAX_AGE_DAYS;
|
|
110
|
+
exports.checkComparisonFreshness = checkComparisonFreshness;
|
|
111
|
+
exports.formatFreshnessReport = formatFreshnessReport;
|
|
112
|
+
exports.latestVerification = latestVerification;
|
|
113
|
+
exports.oldestVerification = oldestVerification;
|
|
114
|
+
exports.parseVerifiedAt = parseVerifiedAt;
|
|
115
|
+
//# sourceMappingURL=chunk-6KY2ZRVI.js.map
|
|
116
|
+
//# sourceMappingURL=chunk-6KY2ZRVI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/comparison/index.ts"],"names":[],"mappings":";;;AA2EO,IAAM,+BAAA,GAAkC;AAE/C,IAAM,MAAA,GAAS,EAAA,GAAK,EAAA,GAAK,EAAA,GAAK,GAAA;AAC9B,IAAM,QAAA,GAAW,qBAAA;AAGV,SAAS,gBAAgB,KAAA,EAA4B;AAC1D,EAAA,IAAI,OAAO,UAAU,QAAA,IAAY,CAAC,SAAS,IAAA,CAAK,KAAK,GAAG,OAAO,IAAA;AAC/D,EAAA,MAAM,IAAA,mBAAO,IAAI,IAAA,CAAK,CAAA,EAAG,KAAK,CAAA,cAAA,CAAgB,CAAA;AAC9C,EAAA,IAAI,OAAO,KAAA,CAAM,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AAO;AAAA,IACL,CAAA,oBAAA,EAAuB,OAAO,MAAM,CAAA,kBAAA,CAAA;AAAA,IACpC,GAAG,KAAA;AAAA,IACH;AAAA,GACF,CAAE,KAAK,IAAI,CAAA;AACb","file":"chunk-6KY2ZRVI.js","sourcesContent":["/**\n * @burdenoff/website-sdk - Comparison page sources and freshness (BOFF-9971)\n *\n * Every product website with a /vs (competitor comparison) page makes claims\n * about other vendors. Those claims age fast: a vendor ships the feature we\n * said it lacked, or changes its prices. This module gives every site the same\n * contract and the same check:\n *\n * - each claim carries at least one source `{ url, verifiedAt }` (enforced by\n * the `Sourced` type at compile time), and\n * - `checkComparisonFreshness` fails when a claim has no source, a source is\n * not an http(s) URL, a date is malformed or in the future, or the newest\n * verification is older than `maxAgeDays` (180 by default).\n *\n * Sites run the check in their PR Check workflow, so a stale or unsourced\n * comparison blocks the next change until someone re-reads the vendor's page.\n *\n * @example\n * ```ts\n * import { checkComparisonFreshness, formatFreshnessReport } from '@burdenoff/website-sdk/comparison'\n *\n * const issues = checkComparisonFreshness(collectClaims(COMPETITORS))\n * if (issues.length) {\n * console.error(formatFreshnessReport(issues))\n * process.exit(1)\n * }\n * ```\n */\n\n/** Where a comparison claim was checked, and when (ISO date, YYYY-MM-DD). */\nexport interface ComparisonSource {\n /** The vendor page (or docs page) the claim was checked against. */\n url: string;\n /** The day a person last read that page and confirmed the claim. */\n verifiedAt: string;\n /** Optional short label shown with the link, e.g. \"Pricing\". */\n label?: string;\n}\n\n/** A non-empty list: a sourced claim always has at least one source. */\nexport type NonEmptySources = readonly [\n ComparisonSource,\n ...ComparisonSource[],\n];\n\n/** Mix-in for any comparison claim (table row, profile, pricing row). */\nexport interface Sourced {\n sources: NonEmptySources;\n}\n\n/** One claim to check, located by a human-readable path for the report. */\nexport interface ComparisonClaim {\n /** Where the claim lives, e.g. \"zapier.featureRows[Workflow versioning]\". */\n path: string;\n /** Its sources; missing or empty fails the check. */\n sources?: readonly ComparisonSource[] | null;\n}\n\nexport type FreshnessProblem =\n \"missing-source\" | \"invalid-url\" | \"invalid-date\" | \"future-date\" | \"stale\";\n\nexport interface FreshnessIssue {\n path: string;\n problem: FreshnessProblem;\n detail: string;\n}\n\nexport interface FreshnessOptions {\n /** Oldest acceptable verification, in days. Default 180. */\n maxAgeDays?: number;\n /** The clock to check against. Default: now. */\n now?: Date;\n}\n\n/** Default staleness threshold for comparison claims. */\nexport const DEFAULT_COMPARISON_MAX_AGE_DAYS = 180;\n\nconst DAY_MS = 24 * 60 * 60 * 1000;\nconst ISO_DATE = /^\\d{4}-\\d{2}-\\d{2}$/;\n\n/** Parse a strict YYYY-MM-DD date as UTC midnight, or null when invalid. */\nexport function parseVerifiedAt(value: string): Date | null {\n if (typeof value !== \"string\" || !ISO_DATE.test(value)) return null;\n const date = new Date(`${value}T00:00:00.000Z`);\n if (Number.isNaN(date.getTime())) return null;\n // Reject rollovers such as 2026-02-31 → 2026-03-03.\n return date.toISOString().slice(0, 10) === value ? date : null;\n}\n\nfunction isHttpUrl(value: string): boolean {\n try {\n const url = new URL(value);\n return url.protocol === \"https:\" || url.protocol === \"http:\";\n } catch {\n return false;\n }\n}\n\n/**\n * Check every claim and return the problems found (empty when all is well).\n * A claim passes on its newest valid source, so adding a fresh source to an\n * old claim is enough to clear a \"stale\" issue.\n */\nexport function checkComparisonFreshness(\n claims: readonly ComparisonClaim[],\n options: FreshnessOptions = {},\n): FreshnessIssue[] {\n const maxAgeDays = options.maxAgeDays ?? DEFAULT_COMPARISON_MAX_AGE_DAYS;\n const now = options.now ?? new Date();\n const issues: FreshnessIssue[] = [];\n\n for (const claim of claims) {\n const sources = claim.sources ?? [];\n if (sources.length === 0) {\n issues.push({\n path: claim.path,\n problem: \"missing-source\",\n detail:\n \"no source: add { url, verifiedAt } for the vendor page this claim was checked against\",\n });\n continue;\n }\n\n let newest: Date | null = null;\n for (const source of sources) {\n if (!isHttpUrl(source.url)) {\n issues.push({\n path: claim.path,\n problem: \"invalid-url\",\n detail: `source URL is not an http(s) URL: ${JSON.stringify(source.url)}`,\n });\n }\n const verified = parseVerifiedAt(source.verifiedAt);\n if (!verified) {\n issues.push({\n path: claim.path,\n problem: \"invalid-date\",\n detail: `verifiedAt must be YYYY-MM-DD, got ${JSON.stringify(source.verifiedAt)}`,\n });\n continue;\n }\n if (verified.getTime() > now.getTime() + DAY_MS) {\n issues.push({\n path: claim.path,\n problem: \"future-date\",\n detail: `verifiedAt ${source.verifiedAt} is in the future`,\n });\n continue;\n }\n if (!newest || verified.getTime() > newest.getTime()) newest = verified;\n }\n\n if (newest) {\n const ageDays = Math.floor((now.getTime() - newest.getTime()) / DAY_MS);\n if (ageDays > maxAgeDays) {\n issues.push({\n path: claim.path,\n problem: \"stale\",\n detail: `last verified ${newest.toISOString().slice(0, 10)} (${ageDays} days ago, limit ${maxAgeDays}): re-read the vendor page and update verifiedAt or the claim`,\n });\n }\n }\n }\n\n return issues;\n}\n\n/** Newest valid verification date across all claims, or null. */\nexport function latestVerification(\n claims: readonly ComparisonClaim[],\n): string | null {\n let latest: string | null = null;\n for (const claim of claims) {\n for (const source of claim.sources ?? []) {\n if (\n parseVerifiedAt(source.verifiedAt) &&\n (!latest || source.verifiedAt > latest)\n ) {\n latest = source.verifiedAt;\n }\n }\n }\n return latest;\n}\n\n/** Oldest valid verification date across all claims, or null. */\nexport function oldestVerification(\n claims: readonly ComparisonClaim[],\n): string | null {\n let oldest: string | null = null;\n for (const claim of claims) {\n for (const source of claim.sources ?? []) {\n if (\n parseVerifiedAt(source.verifiedAt) &&\n (!oldest || source.verifiedAt < oldest)\n ) {\n oldest = source.verifiedAt;\n }\n }\n }\n return oldest;\n}\n\n/** A plain-text report for CI logs, one line per issue. */\nexport function formatFreshnessReport(\n issues: readonly FreshnessIssue[],\n): string {\n if (issues.length === 0)\n return \"Comparison sources: all claims sourced and fresh.\";\n const lines = issues.map((i) => ` - [${i.problem}] ${i.path}: ${i.detail}`);\n return [\n `Comparison sources: ${issues.length} problem(s) found.`,\n ...lines,\n \"Re-check each claim against the vendor's current page, then update the claim and its verifiedAt.\",\n ].join(\"\\n\");\n}\n"]}
|