@kya-os/checkpoint-shared 1.6.0 → 1.8.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 +122 -9
- package/README.md +24 -7
- package/dist/beacon-nonce/index.d.mts +1 -0
- package/dist/beacon-nonce/index.d.mts.map +1 -1
- package/dist/beacon-nonce/index.d.ts +1 -0
- package/dist/beacon-nonce/index.d.ts.map +1 -1
- package/dist/beacon-nonce/index.js +9 -3
- package/dist/beacon-nonce/index.mjs +9 -4
- package/dist/beacon-nonce/index.mjs.map +1 -1
- package/dist/beacon-types/index.d.mts +23 -1
- package/dist/beacon-types/index.d.mts.map +1 -1
- package/dist/beacon-types/index.d.ts +23 -1
- package/dist/beacon-types/index.d.ts.map +1 -1
- package/dist/beacon-types/index.js +49 -4
- package/dist/beacon-types/index.mjs +47 -4
- package/dist/beacon-types/index.mjs.map +1 -1
- package/dist/{browser-posture-BuChqmH5.d.mts → browser-posture-5fPrsxx7.d.mts} +2 -2
- package/dist/{browser-posture-BuChqmH5.d.mts.map → browser-posture-5fPrsxx7.d.mts.map} +1 -1
- package/dist/{browser-posture-DIaVLuW3.d.ts → browser-posture-CCR1kh5e.d.ts} +2 -2
- package/dist/{browser-posture-DIaVLuW3.d.ts.map → browser-posture-CCR1kh5e.d.ts.map} +1 -1
- package/dist/browser-posture-cookie.js +1 -1
- package/dist/browser-posture-cookie.mjs +1 -1
- package/dist/browser-posture-cookie.mjs.map +1 -1
- package/dist/browser-posture-proof.d.mts +16 -2
- package/dist/browser-posture-proof.d.mts.map +1 -1
- package/dist/browser-posture-proof.d.ts +16 -2
- package/dist/browser-posture-proof.d.ts.map +1 -1
- package/dist/browser-posture-proof.js +114 -17
- package/dist/browser-posture-proof.mjs +112 -17
- package/dist/browser-posture-proof.mjs.map +1 -1
- package/dist/browser-posture.d.mts +1 -1
- package/dist/browser-posture.d.ts +1 -1
- package/dist/browser-posture.js +6 -5
- package/dist/browser-posture.mjs +4 -3
- package/dist/browser-posture.mjs.map +1 -1
- package/dist/browser.d.mts +25 -4
- package/dist/browser.d.mts.map +1 -1
- package/dist/browser.d.ts +25 -4
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +1 -1
- package/dist/browser.mjs +1 -1
- package/dist/browser.mjs.map +1 -1
- package/dist/canonical-signer/index.d.mts.map +1 -1
- package/dist/canonical-signer/index.d.ts.map +1 -1
- package/dist/canonical-signer/index.js +116 -79
- package/dist/canonical-signer/index.mjs +117 -52
- package/dist/canonical-signer/index.mjs.map +1 -1
- package/dist/clearance.d.mts +1 -1
- package/dist/clearance.d.ts +1 -1
- package/dist/clearance.js +2 -2
- package/dist/clearance.mjs +2 -2
- package/dist/client-ip-B7w-uHfS.d.mts +55 -0
- package/dist/client-ip-B7w-uHfS.d.mts.map +1 -0
- package/dist/client-ip-B7w-uHfS.d.ts +55 -0
- package/dist/client-ip-B7w-uHfS.d.ts.map +1 -0
- package/dist/{client-ip-CW6pRyLf.js → client-ip-B8wFzJ5f.js} +117 -7
- package/dist/{client-ip-B2Xeo-GK.mjs → client-ip-DIJyr6px.mjs} +113 -9
- package/dist/client-ip-DIJyr6px.mjs.map +1 -0
- package/dist/client-ip.d.mts +2 -0
- package/dist/client-ip.d.ts +2 -0
- package/dist/client-ip.js +8 -0
- package/dist/client-ip.mjs +3 -0
- package/dist/detection-reason-mapping-B9RSkOs8.js +277 -0
- package/dist/detection-reason-mapping-BGymWIPl.mjs +249 -0
- package/dist/detection-reason-mapping-BGymWIPl.mjs.map +1 -0
- package/dist/detection-reason-mapping-CQexNvR7.d.mts +52 -0
- package/dist/detection-reason-mapping-CQexNvR7.d.mts.map +1 -0
- package/dist/detection-reason-mapping-CQexNvR7.d.ts +52 -0
- package/dist/detection-reason-mapping-CQexNvR7.d.ts.map +1 -0
- package/dist/engine-enforcing-AYEcgNsb.js +39 -0
- package/dist/engine-enforcing-B5eNfCpG.mjs +29 -0
- package/dist/engine-enforcing-B5eNfCpG.mjs.map +1 -0
- package/dist/engine-enforcing-DiOclGqf.d.mts +11 -0
- package/dist/engine-enforcing-DiOclGqf.d.mts.map +1 -0
- package/dist/engine-enforcing-DiOclGqf.d.ts +11 -0
- package/dist/engine-enforcing-DiOclGqf.d.ts.map +1 -0
- package/dist/engine-info.d.mts +2 -0
- package/dist/engine-info.d.ts +2 -0
- package/dist/engine-info.js +4 -0
- package/dist/engine-info.mjs +3 -0
- package/dist/errors/index.d.mts +5 -0
- package/dist/errors/index.d.mts.map +1 -1
- package/dist/errors/index.d.ts +5 -0
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +23 -4
- package/dist/errors/index.mjs +23 -4
- package/dist/errors/index.mjs.map +1 -1
- package/dist/{external-B7WI9FyQ.d.ts → external-m3Kmafwj.d.mts} +2 -2
- package/dist/{external-B7WI9FyQ.d.mts.map → external-m3Kmafwj.d.mts.map} +1 -1
- package/dist/{external-B7WI9FyQ.d.mts → external-m3Kmafwj.d.ts} +2 -2
- package/dist/{external-B7WI9FyQ.d.ts.map → external-m3Kmafwj.d.ts.map} +1 -1
- package/dist/fetcher-CivUCbhL.d.ts +44 -0
- package/dist/fetcher-CivUCbhL.d.ts.map +1 -0
- package/dist/fetcher-cXQsbm6s.d.mts +44 -0
- package/dist/fetcher-cXQsbm6s.d.mts.map +1 -0
- package/dist/gateway-client-ip.d.mts +1 -1
- package/dist/gateway-client-ip.d.ts +1 -1
- package/dist/gateway-client-ip.js +2 -2
- package/dist/gateway-client-ip.mjs +2 -2
- package/dist/host-adapter/index.d.mts +2 -0
- package/dist/host-adapter/index.d.ts +2 -0
- package/dist/host-adapter/index.js +24 -0
- package/dist/host-adapter/index.mjs +3 -0
- package/dist/host-adapter-0F8EpbD6.js +753 -0
- package/dist/host-adapter-DHyISsIf.mjs +593 -0
- package/dist/host-adapter-DHyISsIf.mjs.map +1 -0
- package/dist/index-B3cHxr3O.d.mts +156 -0
- package/dist/index-B3cHxr3O.d.mts.map +1 -0
- package/dist/index-CXbOY7gB.d.ts +156 -0
- package/dist/index-CXbOY7gB.d.ts.map +1 -0
- package/dist/index.d.mts +6997 -12170
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +6997 -12170
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2510 -8893
- package/dist/index.mjs +2366 -8534
- package/dist/index.mjs.map +1 -1
- package/dist/kya-http-error-codes-7ewV5RuK.d.mts +29 -0
- package/dist/kya-http-error-codes-7ewV5RuK.d.mts.map +1 -0
- package/dist/kya-http-error-codes-7ewV5RuK.d.ts +29 -0
- package/dist/kya-http-error-codes-7ewV5RuK.d.ts.map +1 -0
- package/dist/kya-http-error-codes-C2JiWPsi.mjs +73 -0
- package/dist/kya-http-error-codes-C2JiWPsi.mjs.map +1 -0
- package/dist/kya-http-error-codes-UYb1zpGM.js +83 -0
- package/dist/kya-http.d.mts +3 -0
- package/dist/kya-http.d.ts +3 -0
- package/dist/kya-http.js +19 -0
- package/dist/kya-http.mjs +5 -0
- package/dist/mcpi/dashboard-config/index.d.mts.map +1 -1
- package/dist/mcpi/dashboard-config/index.d.ts.map +1 -1
- package/dist/mcpi/status-list/index.d.mts +72 -0
- package/dist/mcpi/status-list/index.d.mts.map +1 -0
- package/dist/mcpi/status-list/index.d.ts +72 -0
- package/dist/mcpi/status-list/index.d.ts.map +1 -0
- package/dist/mcpi/status-list/index.js +703 -0
- package/dist/mcpi/status-list/index.mjs +684 -0
- package/dist/mcpi/status-list/index.mjs.map +1 -0
- package/dist/patterns-B2r7M9wR.js +243 -0
- package/dist/patterns-B7dQoeE3.mjs +173 -0
- package/dist/patterns-B7dQoeE3.mjs.map +1 -0
- package/dist/patterns-Bp40cwh2.d.mts +110 -0
- package/dist/patterns-Bp40cwh2.d.mts.map +1 -0
- package/dist/patterns-Bp40cwh2.d.ts +110 -0
- package/dist/patterns-Bp40cwh2.d.ts.map +1 -0
- package/dist/patterns.d.mts +2 -0
- package/dist/patterns.d.ts +2 -0
- package/dist/patterns.js +15 -0
- package/dist/patterns.mjs +3 -0
- package/dist/policy/enforcement.d.mts +3 -0
- package/dist/policy/enforcement.d.ts +3 -0
- package/dist/policy/enforcement.js +21 -0
- package/dist/policy/enforcement.mjs +4 -0
- package/dist/policy/fetcher.d.mts +2 -0
- package/dist/policy/fetcher.d.ts +2 -0
- package/dist/policy/fetcher.js +240 -0
- package/dist/policy/fetcher.mjs +238 -0
- package/dist/policy/fetcher.mjs.map +1 -0
- package/dist/policy/schemas.d.mts +3 -0
- package/dist/policy/schemas.d.ts +3 -0
- package/dist/policy/schemas.js +27 -0
- package/dist/policy/schemas.mjs +4 -0
- package/dist/{posture-origins-Pn-ii-Pp.mjs → posture-origins-Ci6k4Zh1.js} +24 -173
- package/dist/{posture-origins-LFkX80oF.js → posture-origins-DGyS4Vuk.mjs} +2 -267
- package/dist/posture-origins-DGyS4Vuk.mjs.map +1 -0
- package/dist/{project-verification-key-BccT12tQ.js → project-verification-key-B-L3D2nC.js} +1 -1
- package/dist/{project-verification-key-66N4edKn.mjs → project-verification-key-CWXdu3-n.mjs} +2 -2
- package/dist/{project-verification-key-66N4edKn.mjs.map → project-verification-key-CWXdu3-n.mjs.map} +1 -1
- package/dist/provider-registry.d.mts +2 -0
- package/dist/provider-registry.d.ts +2 -0
- package/dist/provider-registry.js +51 -0
- package/dist/provider-registry.mjs +3 -0
- package/dist/reason-codes.d.mts +2 -0
- package/dist/reason-codes.d.ts +2 -0
- package/dist/reason-codes.js +8 -0
- package/dist/reason-codes.mjs +3 -0
- package/dist/registered-sid-26hNxp6t.mjs +151 -0
- package/dist/registered-sid-26hNxp6t.mjs.map +1 -0
- package/dist/registered-sid-D6KCaT1E.d.mts +33 -0
- package/dist/registered-sid-D6KCaT1E.d.mts.map +1 -0
- package/dist/registered-sid-D6KCaT1E.d.ts +33 -0
- package/dist/registered-sid-D6KCaT1E.d.ts.map +1 -0
- package/dist/registered-sid-DVGTSH0L.js +185 -0
- package/dist/ruleset-hash-Cmv8MSO5.js +34 -0
- package/dist/ruleset-hash-IRN5eI9H.d.mts +5 -0
- package/dist/ruleset-hash-IRN5eI9H.d.mts.map +1 -0
- package/dist/ruleset-hash-IRN5eI9H.d.ts +5 -0
- package/dist/ruleset-hash-IRN5eI9H.d.ts.map +1 -0
- package/dist/ruleset-hash-QQIaLuPi.mjs +30 -0
- package/dist/ruleset-hash-QQIaLuPi.mjs.map +1 -0
- package/dist/schemas-02CI7jgm.d.mts +535 -0
- package/dist/schemas-02CI7jgm.d.mts.map +1 -0
- package/dist/{schemas-YhagYDx_.js → schemas-BlScS1it.js} +0 -20
- package/dist/schemas-C_3C72SR.d.ts +535 -0
- package/dist/schemas-C_3C72SR.d.ts.map +1 -0
- package/dist/schemas-Cm4C4Z5G.js +703 -0
- package/dist/schemas-DPIT8usF.mjs +525 -0
- package/dist/schemas-DPIT8usF.mjs.map +1 -0
- package/dist/{schemas-7qodsG-Z.mjs → schemas-IHAhH3gV.mjs} +2 -16
- package/dist/schemas-IHAhH3gV.mjs.map +1 -0
- package/dist/step-up-BK0oBi11.mjs +1563 -0
- package/dist/step-up-BK0oBi11.mjs.map +1 -0
- package/dist/step-up-Bp8RAQwv.js +1759 -0
- package/dist/step-up-Bz12gYKT.d.mts +130 -0
- package/dist/step-up-Bz12gYKT.d.mts.map +1 -0
- package/dist/step-up-Bz12gYKT.d.ts +130 -0
- package/dist/step-up-Bz12gYKT.d.ts.map +1 -0
- package/dist/test-fixtures/index.d.mts +4 -4
- package/dist/test-fixtures/index.d.mts.map +1 -1
- package/dist/test-fixtures/index.d.ts +4 -4
- package/dist/test-fixtures/index.d.ts.map +1 -1
- package/dist/test-fixtures/index.js +4 -4
- package/dist/test-fixtures/index.mjs +4 -4
- package/dist/test-fixtures/index.mjs.map +1 -1
- package/dist/verification-BAw9N8Pt.js +181 -0
- package/dist/verification-Cvvv86TT.mjs +123 -0
- package/dist/verification-Cvvv86TT.mjs.map +1 -0
- package/fixtures/client-ip-resolution.n01.json +101 -0
- package/fixtures/reviewer-grant-revocation.v1.json +53 -81
- package/package.json +59 -2
- package/dist/client-ip-B2Xeo-GK.mjs.map +0 -1
- package/dist/posture-origins-Pn-ii-Pp.mjs.map +0 -1
- package/dist/schemas-7qodsG-Z.mjs.map +0 -1
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
//#region src/constants/patterns.d.ts
|
|
2
|
+
declare const UUID_PATTERN: RegExp;
|
|
3
|
+
declare const VALIDATION_PATTERNS: {
|
|
4
|
+
readonly UUID: RegExp;
|
|
5
|
+
readonly ULID: RegExp;
|
|
6
|
+
readonly SLUG: RegExp;
|
|
7
|
+
readonly IPV4: RegExp;
|
|
8
|
+
readonly IPV6: RegExp;
|
|
9
|
+
readonly IP: RegExp;
|
|
10
|
+
readonly CIDR: RegExp;
|
|
11
|
+
readonly DOMAIN: RegExp;
|
|
12
|
+
readonly HOSTNAME: RegExp;
|
|
13
|
+
readonly URL: RegExp;
|
|
14
|
+
readonly EMAIL: RegExp;
|
|
15
|
+
readonly PHONE: RegExp;
|
|
16
|
+
readonly JWT: RegExp;
|
|
17
|
+
readonly BASE64: RegExp;
|
|
18
|
+
readonly HEX: RegExp;
|
|
19
|
+
readonly MD5: RegExp;
|
|
20
|
+
readonly SHA1: RegExp;
|
|
21
|
+
readonly SHA256: RegExp;
|
|
22
|
+
readonly SEMVER: RegExp;
|
|
23
|
+
readonly FILENAME: RegExp;
|
|
24
|
+
readonly PATH: RegExp;
|
|
25
|
+
readonly API_KEY: RegExp;
|
|
26
|
+
readonly SECRET_KEY: RegExp;
|
|
27
|
+
readonly PIXEL_ID: RegExp;
|
|
28
|
+
};
|
|
29
|
+
declare const USER_AGENT_PATTERNS: {
|
|
30
|
+
readonly OPENAI: RegExp;
|
|
31
|
+
readonly ANTHROPIC: RegExp;
|
|
32
|
+
readonly PERPLEXITY: RegExp;
|
|
33
|
+
readonly GOOGLE_AI: RegExp;
|
|
34
|
+
readonly MICROSOFT_AI: RegExp;
|
|
35
|
+
readonly GOOGLEBOT: RegExp;
|
|
36
|
+
readonly BINGBOT: RegExp;
|
|
37
|
+
readonly DUCKDUCKBOT: RegExp;
|
|
38
|
+
readonly BAIDUBOT: RegExp;
|
|
39
|
+
readonly YANDEXBOT: RegExp;
|
|
40
|
+
readonly FACEBOOK: RegExp;
|
|
41
|
+
readonly TWITTER: RegExp;
|
|
42
|
+
readonly LINKEDIN: RegExp;
|
|
43
|
+
readonly WHATSAPP: RegExp;
|
|
44
|
+
readonly TELEGRAM: RegExp;
|
|
45
|
+
readonly DISCORD: RegExp;
|
|
46
|
+
readonly SLACK: RegExp;
|
|
47
|
+
readonly GENERIC_BOT: RegExp;
|
|
48
|
+
readonly SCRAPY: RegExp;
|
|
49
|
+
readonly PUPPETEER: RegExp;
|
|
50
|
+
readonly PLAYWRIGHT: RegExp;
|
|
51
|
+
readonly SELENIUM: RegExp;
|
|
52
|
+
readonly POSTMAN: RegExp;
|
|
53
|
+
readonly INSOMNIA: RegExp;
|
|
54
|
+
readonly CURL: RegExp;
|
|
55
|
+
readonly WGET: RegExp;
|
|
56
|
+
readonly HTTPIE: RegExp;
|
|
57
|
+
readonly UPTIMEROBOT: RegExp;
|
|
58
|
+
readonly PINGDOM: RegExp;
|
|
59
|
+
readonly NEWRELIC: RegExp;
|
|
60
|
+
readonly DATADOG: RegExp;
|
|
61
|
+
};
|
|
62
|
+
declare const HEADER_PATTERNS: {
|
|
63
|
+
readonly AI_HEADERS: RegExp;
|
|
64
|
+
readonly AUTOMATION_HEADERS: RegExp;
|
|
65
|
+
readonly MISSING_ACCEPT: RegExp;
|
|
66
|
+
readonly MISSING_ACCEPT_LANGUAGE: RegExp;
|
|
67
|
+
readonly MISSING_ACCEPT_ENCODING: RegExp;
|
|
68
|
+
readonly GENERIC_ACCEPT: RegExp;
|
|
69
|
+
readonly NO_COOKIES: RegExp;
|
|
70
|
+
readonly PROXY_HEADERS: RegExp;
|
|
71
|
+
readonly CLOUD_HEADERS: RegExp;
|
|
72
|
+
};
|
|
73
|
+
declare const BROWSER_PATTERNS: {
|
|
74
|
+
readonly CHROME: RegExp;
|
|
75
|
+
readonly FIREFOX: RegExp;
|
|
76
|
+
readonly SAFARI: RegExp;
|
|
77
|
+
readonly EDGE: RegExp;
|
|
78
|
+
readonly OPERA: RegExp;
|
|
79
|
+
readonly IE: RegExp;
|
|
80
|
+
};
|
|
81
|
+
declare const OS_PATTERNS: {
|
|
82
|
+
readonly WINDOWS: RegExp;
|
|
83
|
+
readonly MACOS: RegExp;
|
|
84
|
+
readonly LINUX: RegExp;
|
|
85
|
+
readonly ANDROID: RegExp;
|
|
86
|
+
readonly IOS: RegExp;
|
|
87
|
+
};
|
|
88
|
+
declare const MOBILE_PATTERNS: {
|
|
89
|
+
readonly MOBILE: RegExp;
|
|
90
|
+
readonly TABLET: RegExp;
|
|
91
|
+
readonly DESKTOP: RegExp;
|
|
92
|
+
};
|
|
93
|
+
declare const SUSPICIOUS_PATTERNS: {
|
|
94
|
+
readonly RAPID_REQUESTS: RegExp;
|
|
95
|
+
readonly SEQUENTIAL_URLS: RegExp;
|
|
96
|
+
readonly API_ENDPOINTS: RegExp;
|
|
97
|
+
readonly DIRECT_POST: RegExp;
|
|
98
|
+
readonly SQL_INJECTION: RegExp;
|
|
99
|
+
readonly XSS_ATTEMPT: RegExp;
|
|
100
|
+
readonly PATH_TRAVERSAL: RegExp;
|
|
101
|
+
readonly URL_ENCODED: RegExp;
|
|
102
|
+
readonly BASE64_DATA: RegExp;
|
|
103
|
+
};
|
|
104
|
+
declare function testPattern(pattern: RegExp, value: string): boolean;
|
|
105
|
+
declare function extractMatch(pattern: RegExp, value: string): string | null;
|
|
106
|
+
declare function testPatterns(patterns: RegExp[], value: string): boolean;
|
|
107
|
+
declare function findMatchingPattern(patterns: Record<string, RegExp>, value: string): string | null;
|
|
108
|
+
//#endregion
|
|
109
|
+
export { SUSPICIOUS_PATTERNS as a, VALIDATION_PATTERNS as c, testPattern as d, testPatterns as f, OS_PATTERNS as i, extractMatch as l, HEADER_PATTERNS as n, USER_AGENT_PATTERNS as o, MOBILE_PATTERNS as r, UUID_PATTERN as s, BROWSER_PATTERNS as t, findMatchingPattern as u };
|
|
110
|
+
//# sourceMappingURL=patterns-Bp40cwh2.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patterns-Bp40cwh2.d.mts","names":[],"sources":["../src/constants/patterns.ts"],"mappings":";cAiBa,cAAY;cAGZ;;;;;;;;;;;;;;;;;;;;;;;;;;cAsDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAgDA;;;;;;;;;;;cA0BA;;;;;;;;cAYA;;;;;;;cAWA;;;;;cASA;;;;;;;;;;;iBAuCG,YAAY,SAAS,QAAQ;iBAS7B,aAAa,SAAS,QAAQ;iBAS9B,aAAa,UAAU,UAAU;iBAOjC,oBACd,UAAU,eAAe,SACzB"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
//#region src/constants/patterns.d.ts
|
|
2
|
+
declare const UUID_PATTERN: RegExp;
|
|
3
|
+
declare const VALIDATION_PATTERNS: {
|
|
4
|
+
readonly UUID: RegExp;
|
|
5
|
+
readonly ULID: RegExp;
|
|
6
|
+
readonly SLUG: RegExp;
|
|
7
|
+
readonly IPV4: RegExp;
|
|
8
|
+
readonly IPV6: RegExp;
|
|
9
|
+
readonly IP: RegExp;
|
|
10
|
+
readonly CIDR: RegExp;
|
|
11
|
+
readonly DOMAIN: RegExp;
|
|
12
|
+
readonly HOSTNAME: RegExp;
|
|
13
|
+
readonly URL: RegExp;
|
|
14
|
+
readonly EMAIL: RegExp;
|
|
15
|
+
readonly PHONE: RegExp;
|
|
16
|
+
readonly JWT: RegExp;
|
|
17
|
+
readonly BASE64: RegExp;
|
|
18
|
+
readonly HEX: RegExp;
|
|
19
|
+
readonly MD5: RegExp;
|
|
20
|
+
readonly SHA1: RegExp;
|
|
21
|
+
readonly SHA256: RegExp;
|
|
22
|
+
readonly SEMVER: RegExp;
|
|
23
|
+
readonly FILENAME: RegExp;
|
|
24
|
+
readonly PATH: RegExp;
|
|
25
|
+
readonly API_KEY: RegExp;
|
|
26
|
+
readonly SECRET_KEY: RegExp;
|
|
27
|
+
readonly PIXEL_ID: RegExp;
|
|
28
|
+
};
|
|
29
|
+
declare const USER_AGENT_PATTERNS: {
|
|
30
|
+
readonly OPENAI: RegExp;
|
|
31
|
+
readonly ANTHROPIC: RegExp;
|
|
32
|
+
readonly PERPLEXITY: RegExp;
|
|
33
|
+
readonly GOOGLE_AI: RegExp;
|
|
34
|
+
readonly MICROSOFT_AI: RegExp;
|
|
35
|
+
readonly GOOGLEBOT: RegExp;
|
|
36
|
+
readonly BINGBOT: RegExp;
|
|
37
|
+
readonly DUCKDUCKBOT: RegExp;
|
|
38
|
+
readonly BAIDUBOT: RegExp;
|
|
39
|
+
readonly YANDEXBOT: RegExp;
|
|
40
|
+
readonly FACEBOOK: RegExp;
|
|
41
|
+
readonly TWITTER: RegExp;
|
|
42
|
+
readonly LINKEDIN: RegExp;
|
|
43
|
+
readonly WHATSAPP: RegExp;
|
|
44
|
+
readonly TELEGRAM: RegExp;
|
|
45
|
+
readonly DISCORD: RegExp;
|
|
46
|
+
readonly SLACK: RegExp;
|
|
47
|
+
readonly GENERIC_BOT: RegExp;
|
|
48
|
+
readonly SCRAPY: RegExp;
|
|
49
|
+
readonly PUPPETEER: RegExp;
|
|
50
|
+
readonly PLAYWRIGHT: RegExp;
|
|
51
|
+
readonly SELENIUM: RegExp;
|
|
52
|
+
readonly POSTMAN: RegExp;
|
|
53
|
+
readonly INSOMNIA: RegExp;
|
|
54
|
+
readonly CURL: RegExp;
|
|
55
|
+
readonly WGET: RegExp;
|
|
56
|
+
readonly HTTPIE: RegExp;
|
|
57
|
+
readonly UPTIMEROBOT: RegExp;
|
|
58
|
+
readonly PINGDOM: RegExp;
|
|
59
|
+
readonly NEWRELIC: RegExp;
|
|
60
|
+
readonly DATADOG: RegExp;
|
|
61
|
+
};
|
|
62
|
+
declare const HEADER_PATTERNS: {
|
|
63
|
+
readonly AI_HEADERS: RegExp;
|
|
64
|
+
readonly AUTOMATION_HEADERS: RegExp;
|
|
65
|
+
readonly MISSING_ACCEPT: RegExp;
|
|
66
|
+
readonly MISSING_ACCEPT_LANGUAGE: RegExp;
|
|
67
|
+
readonly MISSING_ACCEPT_ENCODING: RegExp;
|
|
68
|
+
readonly GENERIC_ACCEPT: RegExp;
|
|
69
|
+
readonly NO_COOKIES: RegExp;
|
|
70
|
+
readonly PROXY_HEADERS: RegExp;
|
|
71
|
+
readonly CLOUD_HEADERS: RegExp;
|
|
72
|
+
};
|
|
73
|
+
declare const BROWSER_PATTERNS: {
|
|
74
|
+
readonly CHROME: RegExp;
|
|
75
|
+
readonly FIREFOX: RegExp;
|
|
76
|
+
readonly SAFARI: RegExp;
|
|
77
|
+
readonly EDGE: RegExp;
|
|
78
|
+
readonly OPERA: RegExp;
|
|
79
|
+
readonly IE: RegExp;
|
|
80
|
+
};
|
|
81
|
+
declare const OS_PATTERNS: {
|
|
82
|
+
readonly WINDOWS: RegExp;
|
|
83
|
+
readonly MACOS: RegExp;
|
|
84
|
+
readonly LINUX: RegExp;
|
|
85
|
+
readonly ANDROID: RegExp;
|
|
86
|
+
readonly IOS: RegExp;
|
|
87
|
+
};
|
|
88
|
+
declare const MOBILE_PATTERNS: {
|
|
89
|
+
readonly MOBILE: RegExp;
|
|
90
|
+
readonly TABLET: RegExp;
|
|
91
|
+
readonly DESKTOP: RegExp;
|
|
92
|
+
};
|
|
93
|
+
declare const SUSPICIOUS_PATTERNS: {
|
|
94
|
+
readonly RAPID_REQUESTS: RegExp;
|
|
95
|
+
readonly SEQUENTIAL_URLS: RegExp;
|
|
96
|
+
readonly API_ENDPOINTS: RegExp;
|
|
97
|
+
readonly DIRECT_POST: RegExp;
|
|
98
|
+
readonly SQL_INJECTION: RegExp;
|
|
99
|
+
readonly XSS_ATTEMPT: RegExp;
|
|
100
|
+
readonly PATH_TRAVERSAL: RegExp;
|
|
101
|
+
readonly URL_ENCODED: RegExp;
|
|
102
|
+
readonly BASE64_DATA: RegExp;
|
|
103
|
+
};
|
|
104
|
+
declare function testPattern(pattern: RegExp, value: string): boolean;
|
|
105
|
+
declare function extractMatch(pattern: RegExp, value: string): string | null;
|
|
106
|
+
declare function testPatterns(patterns: RegExp[], value: string): boolean;
|
|
107
|
+
declare function findMatchingPattern(patterns: Record<string, RegExp>, value: string): string | null;
|
|
108
|
+
//#endregion
|
|
109
|
+
export { SUSPICIOUS_PATTERNS as a, VALIDATION_PATTERNS as c, testPattern as d, testPatterns as f, OS_PATTERNS as i, extractMatch as l, HEADER_PATTERNS as n, USER_AGENT_PATTERNS as o, MOBILE_PATTERNS as r, UUID_PATTERN as s, BROWSER_PATTERNS as t, findMatchingPattern as u };
|
|
110
|
+
//# sourceMappingURL=patterns-Bp40cwh2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patterns-Bp40cwh2.d.ts","names":[],"sources":["../src/constants/patterns.ts"],"mappings":";cAiBa,cAAY;cAGZ;;;;;;;;;;;;;;;;;;;;;;;;;;cAsDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAgDA;;;;;;;;;;;cA0BA;;;;;;;;cAYA;;;;;;;cAWA;;;;;cASA;;;;;;;;;;;iBAuCG,YAAY,SAAS,QAAQ;iBAS7B,aAAa,SAAS,QAAQ;iBAS9B,aAAa,UAAU,UAAU;iBAOjC,oBACd,UAAU,eAAe,SACzB"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as SUSPICIOUS_PATTERNS, c as VALIDATION_PATTERNS, d as testPattern, f as testPatterns, i as OS_PATTERNS, l as extractMatch, n as HEADER_PATTERNS, o as USER_AGENT_PATTERNS, r as MOBILE_PATTERNS, s as UUID_PATTERN, t as BROWSER_PATTERNS, u as findMatchingPattern } from "./patterns-Bp40cwh2.mjs";
|
|
2
|
+
export { BROWSER_PATTERNS, HEADER_PATTERNS, MOBILE_PATTERNS, OS_PATTERNS, SUSPICIOUS_PATTERNS, USER_AGENT_PATTERNS, UUID_PATTERN, VALIDATION_PATTERNS, extractMatch, findMatchingPattern, testPattern, testPatterns };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as SUSPICIOUS_PATTERNS, c as VALIDATION_PATTERNS, d as testPattern, f as testPatterns, i as OS_PATTERNS, l as extractMatch, n as HEADER_PATTERNS, o as USER_AGENT_PATTERNS, r as MOBILE_PATTERNS, s as UUID_PATTERN, t as BROWSER_PATTERNS, u as findMatchingPattern } from "./patterns-Bp40cwh2.js";
|
|
2
|
+
export { BROWSER_PATTERNS, HEADER_PATTERNS, MOBILE_PATTERNS, OS_PATTERNS, SUSPICIOUS_PATTERNS, USER_AGENT_PATTERNS, UUID_PATTERN, VALIDATION_PATTERNS, extractMatch, findMatchingPattern, testPattern, testPatterns };
|
package/dist/patterns.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_patterns = require('./patterns-B2r7M9wR.js');
|
|
3
|
+
|
|
4
|
+
exports.BROWSER_PATTERNS = require_patterns.BROWSER_PATTERNS;
|
|
5
|
+
exports.HEADER_PATTERNS = require_patterns.HEADER_PATTERNS;
|
|
6
|
+
exports.MOBILE_PATTERNS = require_patterns.MOBILE_PATTERNS;
|
|
7
|
+
exports.OS_PATTERNS = require_patterns.OS_PATTERNS;
|
|
8
|
+
exports.SUSPICIOUS_PATTERNS = require_patterns.SUSPICIOUS_PATTERNS;
|
|
9
|
+
exports.USER_AGENT_PATTERNS = require_patterns.USER_AGENT_PATTERNS;
|
|
10
|
+
exports.UUID_PATTERN = require_patterns.UUID_PATTERN;
|
|
11
|
+
exports.VALIDATION_PATTERNS = require_patterns.VALIDATION_PATTERNS;
|
|
12
|
+
exports.extractMatch = require_patterns.extractMatch;
|
|
13
|
+
exports.findMatchingPattern = require_patterns.findMatchingPattern;
|
|
14
|
+
exports.testPattern = require_patterns.testPattern;
|
|
15
|
+
exports.testPatterns = require_patterns.testPatterns;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as SUSPICIOUS_PATTERNS, c as VALIDATION_PATTERNS, d as testPattern, f as testPatterns, i as OS_PATTERNS, l as extractMatch, n as HEADER_PATTERNS, o as USER_AGENT_PATTERNS, r as MOBILE_PATTERNS, s as UUID_PATTERN, t as BROWSER_PATTERNS, u as findMatchingPattern } from "./patterns-B7dQoeE3.mjs";
|
|
2
|
+
|
|
3
|
+
export { BROWSER_PATTERNS, HEADER_PATTERNS, MOBILE_PATTERNS, OS_PATTERNS, SUSPICIOUS_PATTERNS, USER_AGENT_PATTERNS, UUID_PATTERN, VALIDATION_PATTERNS, extractMatch, findMatchingPattern, testPattern, testPatterns };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { n as normalizeChallengeType, t as isEngineEnforcing } from "../engine-enforcing-DiOclGqf.mjs";
|
|
2
|
+
import { A as NO_EVIDENCE_EQUALITY_TERM, F as FAIL_CLOSED_HEADERS, I as FAIL_CLOSED_STATUS, M as withNoEvidenceExclusion, N as matchPath, P as FAIL_CLOSED_BODY, _ as requiredScopesForRequest, a as ApprovalQuorum, b as analyzePolicySource, c as BESPOKE_POLICY_IDS, g as ByteBoundedMemo, h as decisionPolicyId, i as validateStepUpQuorum, j as NO_EVIDENCE_EXCLUSION_TERM, k as NO_EVIDENCE_CATEGORY, l as BespokePolicyId, m as DecisionLike, n as StepUpQuorumCheck, o as approvalQuorumForRequest, r as StepUpQuorumLike, t as InvalidStepUpReason, v as PolicyHazardAnalysis, y as RequestFacts } from "../step-up-Bz12gYKT.mjs";
|
|
3
|
+
export { type ApprovalQuorum, BESPOKE_POLICY_IDS, type BespokePolicyId, ByteBoundedMemo, type DecisionLike, FAIL_CLOSED_BODY, FAIL_CLOSED_HEADERS, FAIL_CLOSED_STATUS, type InvalidStepUpReason, NO_EVIDENCE_CATEGORY, NO_EVIDENCE_EQUALITY_TERM, NO_EVIDENCE_EXCLUSION_TERM, type PolicyHazardAnalysis, type RequestFacts, type StepUpQuorumCheck, type StepUpQuorumLike, analyzePolicySource, approvalQuorumForRequest, decisionPolicyId, isEngineEnforcing, matchPath, normalizeChallengeType, requiredScopesForRequest, validateStepUpQuorum, withNoEvidenceExclusion };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { n as normalizeChallengeType, t as isEngineEnforcing } from "../engine-enforcing-DiOclGqf.js";
|
|
2
|
+
import { A as NO_EVIDENCE_EQUALITY_TERM, F as FAIL_CLOSED_HEADERS, I as FAIL_CLOSED_STATUS, M as withNoEvidenceExclusion, N as matchPath, P as FAIL_CLOSED_BODY, _ as requiredScopesForRequest, a as ApprovalQuorum, b as analyzePolicySource, c as BESPOKE_POLICY_IDS, g as ByteBoundedMemo, h as decisionPolicyId, i as validateStepUpQuorum, j as NO_EVIDENCE_EXCLUSION_TERM, k as NO_EVIDENCE_CATEGORY, l as BespokePolicyId, m as DecisionLike, n as StepUpQuorumCheck, o as approvalQuorumForRequest, r as StepUpQuorumLike, t as InvalidStepUpReason, v as PolicyHazardAnalysis, y as RequestFacts } from "../step-up-Bz12gYKT.js";
|
|
3
|
+
export { type ApprovalQuorum, BESPOKE_POLICY_IDS, type BespokePolicyId, ByteBoundedMemo, type DecisionLike, FAIL_CLOSED_BODY, FAIL_CLOSED_HEADERS, FAIL_CLOSED_STATUS, type InvalidStepUpReason, NO_EVIDENCE_CATEGORY, NO_EVIDENCE_EQUALITY_TERM, NO_EVIDENCE_EXCLUSION_TERM, type PolicyHazardAnalysis, type RequestFacts, type StepUpQuorumCheck, type StepUpQuorumLike, analyzePolicySource, approvalQuorumForRequest, decisionPolicyId, isEngineEnforcing, matchPath, normalizeChallengeType, requiredScopesForRequest, validateStepUpQuorum, withNoEvidenceExclusion };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_engine_enforcing = require('../engine-enforcing-AYEcgNsb.js');
|
|
3
|
+
const require_step_up = require('../step-up-Bp8RAQwv.js');
|
|
4
|
+
|
|
5
|
+
exports.BESPOKE_POLICY_IDS = require_step_up.BESPOKE_POLICY_IDS;
|
|
6
|
+
exports.ByteBoundedMemo = require_step_up.ByteBoundedMemo;
|
|
7
|
+
exports.FAIL_CLOSED_BODY = require_step_up.FAIL_CLOSED_BODY;
|
|
8
|
+
exports.FAIL_CLOSED_HEADERS = require_step_up.FAIL_CLOSED_HEADERS;
|
|
9
|
+
exports.FAIL_CLOSED_STATUS = require_step_up.FAIL_CLOSED_STATUS;
|
|
10
|
+
exports.NO_EVIDENCE_CATEGORY = require_step_up.NO_EVIDENCE_CATEGORY;
|
|
11
|
+
exports.NO_EVIDENCE_EQUALITY_TERM = require_step_up.NO_EVIDENCE_EQUALITY_TERM;
|
|
12
|
+
exports.NO_EVIDENCE_EXCLUSION_TERM = require_step_up.NO_EVIDENCE_EXCLUSION_TERM;
|
|
13
|
+
exports.analyzePolicySource = require_step_up.analyzePolicySource;
|
|
14
|
+
exports.approvalQuorumForRequest = require_step_up.approvalQuorumForRequest;
|
|
15
|
+
exports.decisionPolicyId = require_step_up.decisionPolicyId;
|
|
16
|
+
exports.isEngineEnforcing = require_engine_enforcing.isEngineEnforcing;
|
|
17
|
+
exports.matchPath = require_step_up.matchPath;
|
|
18
|
+
exports.normalizeChallengeType = require_engine_enforcing.normalizeChallengeType;
|
|
19
|
+
exports.requiredScopesForRequest = require_step_up.requiredScopesForRequest;
|
|
20
|
+
exports.validateStepUpQuorum = require_step_up.validateStepUpQuorum;
|
|
21
|
+
exports.withNoEvidenceExclusion = require_step_up.withNoEvidenceExclusion;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { n as normalizeChallengeType, t as isEngineEnforcing } from "../engine-enforcing-B5eNfCpG.mjs";
|
|
2
|
+
import { A as matchPath, C as NO_EVIDENCE_CATEGORY, E as withNoEvidenceExclusion, M as FAIL_CLOSED_HEADERS, N as FAIL_CLOSED_STATUS, T as NO_EVIDENCE_EXCLUSION_TERM, d as ByteBoundedMemo, f as analyzePolicySource, i as BESPOKE_POLICY_IDS, j as FAIL_CLOSED_BODY, l as decisionPolicyId, n as approvalQuorumForRequest, t as validateStepUpQuorum, u as requiredScopesForRequest, w as NO_EVIDENCE_EQUALITY_TERM } from "../step-up-BK0oBi11.mjs";
|
|
3
|
+
|
|
4
|
+
export { BESPOKE_POLICY_IDS, ByteBoundedMemo, FAIL_CLOSED_BODY, FAIL_CLOSED_HEADERS, FAIL_CLOSED_STATUS, NO_EVIDENCE_CATEGORY, NO_EVIDENCE_EQUALITY_TERM, NO_EVIDENCE_EXCLUSION_TERM, analyzePolicySource, approvalQuorumForRequest, decisionPolicyId, isEngineEnforcing, matchPath, normalizeChallengeType, requiredScopesForRequest, validateStepUpQuorum, withNoEvidenceExclusion };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as PolicyUnavailableError, i as PolicyFetcherConfig, n as PolicyCacheAdapter, o as isPolicyUnavailableError, r as PolicyFetcher, t as CachedPolicy } from "../fetcher-cXQsbm6s.mjs";
|
|
2
|
+
export { CachedPolicy, PolicyCacheAdapter, PolicyFetcher, PolicyFetcherConfig, PolicyUnavailableError, isPolicyUnavailableError };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as PolicyUnavailableError, i as PolicyFetcherConfig, n as PolicyCacheAdapter, o as isPolicyUnavailableError, r as PolicyFetcher, t as CachedPolicy } from "../fetcher-CivUCbhL.js";
|
|
2
|
+
export { CachedPolicy, PolicyCacheAdapter, PolicyFetcher, PolicyFetcherConfig, PolicyUnavailableError, isPolicyUnavailableError };
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_schemas = require('../schemas-Cm4C4Z5G.js');
|
|
3
|
+
|
|
4
|
+
//#region src/policy/fetcher.ts
|
|
5
|
+
/**
|
|
6
|
+
* Policy Fetcher
|
|
7
|
+
*
|
|
8
|
+
* Runtime-agnostic policy fetching with caching support.
|
|
9
|
+
* Works in Edge (Cloudflare Workers, Next.js Edge), Node.js, and browser environments.
|
|
10
|
+
*
|
|
11
|
+
* The fetcher supports:
|
|
12
|
+
* - In-memory caching with TTL
|
|
13
|
+
* - Origin reads for legacy adapters that cannot coordinate shared invalidation
|
|
14
|
+
* - Fallback to default policy on errors
|
|
15
|
+
* - Configurable API endpoints
|
|
16
|
+
*/
|
|
17
|
+
function looksLikePolicyApiBody(data) {
|
|
18
|
+
if (typeof data !== "object" || data === null) return false;
|
|
19
|
+
const threshold = data.blockThreshold;
|
|
20
|
+
return typeof threshold === "number" && Number.isFinite(threshold);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The policy API serves the allow list as agent names (the `string[]` the
|
|
24
|
+
* gateway Worker reads), while the policy schema models each entry as an
|
|
25
|
+
* object. Read a name as `{ clientName }` before validating; anything else is
|
|
26
|
+
* left for the schema to judge.
|
|
27
|
+
*/
|
|
28
|
+
function fromPolicyApiBody(data) {
|
|
29
|
+
const { allowList } = data;
|
|
30
|
+
if (!Array.isArray(allowList)) return data;
|
|
31
|
+
return {
|
|
32
|
+
...data,
|
|
33
|
+
allowList: allowList.map((entry) => typeof entry === "string" ? { clientName: entry } : entry)
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
var PolicyUnavailableError = class extends Error {
|
|
37
|
+
code = "POLICY_UNAVAILABLE";
|
|
38
|
+
constructor() {
|
|
39
|
+
super("Current policy could not be loaded within the permitted bound");
|
|
40
|
+
this.name = "PolicyUnavailableError";
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
/** Recognize the same failure across independently loaded SDK package copies. */
|
|
44
|
+
function isPolicyUnavailableError(error) {
|
|
45
|
+
return error instanceof Error && error.name === "PolicyUnavailableError" && "code" in error && error.code === "POLICY_UNAVAILABLE";
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Simple in-memory cache with TTL support
|
|
49
|
+
*/
|
|
50
|
+
var MemoryCache = class {
|
|
51
|
+
cache = /* @__PURE__ */ new Map();
|
|
52
|
+
get(key) {
|
|
53
|
+
const entry = this.cache.get(key);
|
|
54
|
+
if (!entry) return null;
|
|
55
|
+
if (Date.now() > entry.expiresAt) {
|
|
56
|
+
this.cache.delete(key);
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
return entry.value;
|
|
60
|
+
}
|
|
61
|
+
set(key, value, ttlSeconds) {
|
|
62
|
+
this.cache.set(key, {
|
|
63
|
+
value,
|
|
64
|
+
expiresAt: Date.now() + ttlSeconds * 1e3
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
delete(key) {
|
|
68
|
+
return this.cache.delete(key);
|
|
69
|
+
}
|
|
70
|
+
clear() {
|
|
71
|
+
this.cache.clear();
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const globalMemoryCache = new MemoryCache();
|
|
75
|
+
const globalPolicyCacheKeys = /* @__PURE__ */ new Map();
|
|
76
|
+
const fallbackCachePrefix = `${Date.now().toString(36)}:${Math.random().toString(36).slice(2)}:${Math.random().toString(36).slice(2)}`;
|
|
77
|
+
let fallbackCacheSequence = 0;
|
|
78
|
+
function nextCacheRevision() {
|
|
79
|
+
return globalThis.crypto?.randomUUID?.() ?? `${fallbackCachePrefix}:${++fallbackCacheSequence}`;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Policy fetcher with caching and fallback support
|
|
83
|
+
*/
|
|
84
|
+
var PolicyFetcher = class {
|
|
85
|
+
config;
|
|
86
|
+
memoryCache;
|
|
87
|
+
constructor(config) {
|
|
88
|
+
this.config = {
|
|
89
|
+
apiBaseUrl: config.apiBaseUrl,
|
|
90
|
+
apiKey: config.apiKey,
|
|
91
|
+
cacheTtlSeconds: config.cacheTtlSeconds ?? require_schemas.CACHE_TTL.POLICY,
|
|
92
|
+
cacheAdapter: config.cacheAdapter,
|
|
93
|
+
disableMemoryCache: config.disableMemoryCache ?? false,
|
|
94
|
+
timeoutMs: config.timeoutMs ?? 5e3,
|
|
95
|
+
throwOnUnavailable: config.throwOnUnavailable ?? false,
|
|
96
|
+
fetchFn: config.fetchFn ?? globalThis.fetch
|
|
97
|
+
};
|
|
98
|
+
this.memoryCache = config.disableMemoryCache ? new MemoryCache() : globalMemoryCache;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Generate a cache key that includes the API base URL and TTL to prevent
|
|
102
|
+
* cache collisions when multiple fetchers use different backends or TTL settings.
|
|
103
|
+
*/
|
|
104
|
+
getBaseCacheKey(projectId) {
|
|
105
|
+
return `policy:${this.config.apiBaseUrl.split("").reduce((hash, char) => (hash << 5) - hash + char.charCodeAt(0) | 0, 0).toString(36)}:${this.config.cacheTtlSeconds}:${projectId}`;
|
|
106
|
+
}
|
|
107
|
+
getCacheKey(projectId) {
|
|
108
|
+
const baseKey = this.getBaseCacheKey(projectId);
|
|
109
|
+
return globalPolicyCacheKeys.get(baseKey) ?? baseKey;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Get policy for a project, with caching
|
|
113
|
+
*/
|
|
114
|
+
async getPolicy(projectId) {
|
|
115
|
+
const deadline = Date.now() + this.config.timeoutMs;
|
|
116
|
+
if (!Number.isFinite(deadline) || this.config.timeoutMs <= 0) throw new PolicyUnavailableError();
|
|
117
|
+
const controller = new AbortController();
|
|
118
|
+
const requireActiveLoad = () => {
|
|
119
|
+
if (controller.signal.aborted || Date.now() >= deadline) throw new PolicyUnavailableError();
|
|
120
|
+
};
|
|
121
|
+
let timer;
|
|
122
|
+
const expired = new Promise((_resolve, reject) => {
|
|
123
|
+
timer = setTimeout(() => {
|
|
124
|
+
const failure = new PolicyUnavailableError();
|
|
125
|
+
controller.abort(failure);
|
|
126
|
+
reject(failure);
|
|
127
|
+
}, this.config.timeoutMs);
|
|
128
|
+
});
|
|
129
|
+
const useMemoryCache = !this.config.disableMemoryCache && !this.config.cacheAdapter;
|
|
130
|
+
try {
|
|
131
|
+
for (let attempt = 0; attempt < 4; attempt++) {
|
|
132
|
+
requireActiveLoad();
|
|
133
|
+
const cacheKey = this.getCacheKey(projectId);
|
|
134
|
+
if (useMemoryCache) {
|
|
135
|
+
const memoryCached = this.memoryCache.get(cacheKey);
|
|
136
|
+
if (memoryCached) {
|
|
137
|
+
const cached = JSON.parse(memoryCached);
|
|
138
|
+
requireActiveLoad();
|
|
139
|
+
if (!this.isExpired(cached.expiresAt)) return cached.policy;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
try {
|
|
143
|
+
const policy = await Promise.race([this.fetchPolicyFromApi(projectId, controller.signal), expired]);
|
|
144
|
+
requireActiveLoad();
|
|
145
|
+
if (cacheKey !== this.getCacheKey(projectId)) continue;
|
|
146
|
+
if (useMemoryCache) {
|
|
147
|
+
const now = /* @__PURE__ */ new Date();
|
|
148
|
+
const cached = {
|
|
149
|
+
policy,
|
|
150
|
+
projectId,
|
|
151
|
+
cachedAt: now.toISOString(),
|
|
152
|
+
expiresAt: new Date(now.getTime() + this.config.cacheTtlSeconds * 1e3).toISOString()
|
|
153
|
+
};
|
|
154
|
+
const cacheValue = JSON.stringify(cached);
|
|
155
|
+
requireActiveLoad();
|
|
156
|
+
this.memoryCache.set(cacheKey, cacheValue, this.config.cacheTtlSeconds);
|
|
157
|
+
}
|
|
158
|
+
requireActiveLoad();
|
|
159
|
+
return policy;
|
|
160
|
+
} catch (error) {
|
|
161
|
+
requireActiveLoad();
|
|
162
|
+
if (isPolicyUnavailableError(error)) throw error;
|
|
163
|
+
if (cacheKey !== this.getCacheKey(projectId)) continue;
|
|
164
|
+
console.error(`[PolicyFetcher] Failed to fetch policy for ${projectId}:`, error);
|
|
165
|
+
if (this.config.throwOnUnavailable) throw new PolicyUnavailableError();
|
|
166
|
+
return this.getDefaultPolicy();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
throw new PolicyUnavailableError();
|
|
170
|
+
} finally {
|
|
171
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Fetch policy from the API
|
|
176
|
+
*/
|
|
177
|
+
async fetchPolicyFromApi(projectId, signal) {
|
|
178
|
+
const url = `${this.config.apiBaseUrl}/api/internal/policies/${projectId}`;
|
|
179
|
+
const headers = {
|
|
180
|
+
"Content-Type": "application/json",
|
|
181
|
+
"User-Agent": "AgentShield-PolicyFetcher/1.0"
|
|
182
|
+
};
|
|
183
|
+
if (this.config.apiKey) headers["Authorization"] = `Bearer ${this.config.apiKey}`;
|
|
184
|
+
const response = await this.config.fetchFn(url, {
|
|
185
|
+
method: "GET",
|
|
186
|
+
headers,
|
|
187
|
+
signal,
|
|
188
|
+
cache: "no-store"
|
|
189
|
+
});
|
|
190
|
+
if (!response.ok) throw new Error(`API returned ${response.status}: ${response.statusText}`);
|
|
191
|
+
const data = await response.json();
|
|
192
|
+
if (!looksLikePolicyApiBody(data)) throw new Error("Policy response is not from the policy API");
|
|
193
|
+
const policy = require_schemas.safeParsePolicyConfig(fromPolicyApiBody(data));
|
|
194
|
+
if (!policy) throw new Error("Invalid policy response format");
|
|
195
|
+
return policy;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Get the default policy
|
|
199
|
+
*/
|
|
200
|
+
getDefaultPolicy() {
|
|
201
|
+
return require_schemas.PolicyConfigSchema.parse(require_schemas.DEFAULT_POLICY);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Retire this runtime's cached policy key before any asynchronous cleanup.
|
|
205
|
+
* Older reads and writes cannot restore the retired entry for these fetchers.
|
|
206
|
+
*/
|
|
207
|
+
async invalidateCache(projectId) {
|
|
208
|
+
const cacheKey = this.getCacheKey(projectId);
|
|
209
|
+
const baseKey = this.getBaseCacheKey(projectId);
|
|
210
|
+
globalPolicyCacheKeys.set(baseKey, `${baseKey}:${nextCacheRevision()}`);
|
|
211
|
+
globalMemoryCache.delete(cacheKey);
|
|
212
|
+
if (this.config.cacheAdapter?.delete) {
|
|
213
|
+
const keys = cacheKey === baseKey ? [baseKey] : [cacheKey, baseKey];
|
|
214
|
+
await Promise.all(keys.map(async (key) => {
|
|
215
|
+
try {
|
|
216
|
+
await this.config.cacheAdapter.delete(key);
|
|
217
|
+
} catch (error) {
|
|
218
|
+
console.error("[PolicyFetcher] Failed to delete from external cache:", error);
|
|
219
|
+
}
|
|
220
|
+
}));
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Clear all cached policies
|
|
225
|
+
*/
|
|
226
|
+
clearCache() {
|
|
227
|
+
if (!this.config.disableMemoryCache) this.memoryCache.clear();
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Check if a date string is expired
|
|
231
|
+
*/
|
|
232
|
+
isExpired(dateString) {
|
|
233
|
+
return new Date(dateString).getTime() < Date.now();
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
//#endregion
|
|
238
|
+
exports.PolicyFetcher = PolicyFetcher;
|
|
239
|
+
exports.PolicyUnavailableError = PolicyUnavailableError;
|
|
240
|
+
exports.isPolicyUnavailableError = isPolicyUnavailableError;
|