@kya-os/checkpoint-shared 1.9.0 → 1.11.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 +113 -0
- package/README.md +1 -1
- package/dist/base64url-BbVG8f-v.js +65 -0
- package/dist/base64url-D2MvsR20.mjs +49 -0
- package/dist/base64url-D2MvsR20.mjs.map +1 -0
- package/dist/beacon-forward-secret/index.d.mts +4 -0
- package/dist/beacon-forward-secret/index.d.mts.map +1 -0
- package/dist/beacon-forward-secret/index.d.ts +4 -0
- package/dist/beacon-forward-secret/index.d.ts.map +1 -0
- package/dist/beacon-forward-secret/index.js +15 -0
- package/dist/beacon-forward-secret/index.mjs +15 -0
- package/dist/beacon-forward-secret/index.mjs.map +1 -0
- package/dist/beacon-types/index.d.mts +53 -1
- package/dist/beacon-types/index.d.mts.map +1 -1
- package/dist/beacon-types/index.d.ts +53 -1
- package/dist/beacon-types/index.d.ts.map +1 -1
- package/dist/beacon-types/index.js +86 -1
- package/dist/beacon-types/index.mjs +77 -2
- package/dist/beacon-types/index.mjs.map +1 -1
- package/dist/{browser-posture-5fPrsxx7.d.mts → browser-posture-WPk0kl9u.d.mts} +18 -1
- package/dist/browser-posture-WPk0kl9u.d.mts.map +1 -0
- package/dist/{browser-posture-CCR1kh5e.d.ts → browser-posture-_y6BcdXw.d.ts} +18 -1
- package/dist/browser-posture-_y6BcdXw.d.ts.map +1 -0
- package/dist/browser-posture-cookie.mjs.map +1 -1
- package/dist/browser-posture-proof-verifier.js +136 -5
- package/dist/browser-posture-proof-verifier.mjs +134 -2
- package/dist/browser-posture-proof-verifier.mjs.map +1 -0
- package/dist/browser-posture-proof.d.mts +1 -1
- package/dist/browser-posture-proof.d.ts +1 -1
- package/dist/browser-posture-proof.js +1 -1
- package/dist/browser-posture-proof.mjs +1 -1
- package/dist/browser-posture-report.d.mts +17 -0
- package/dist/browser-posture-report.d.mts.map +1 -1
- package/dist/browser-posture-report.d.ts +17 -0
- package/dist/browser-posture-report.d.ts.map +1 -1
- package/dist/browser-posture.d.mts +1 -1
- package/dist/browser-posture.d.ts +1 -1
- package/dist/browser-posture.js +53 -5
- package/dist/browser-posture.mjs +53 -5
- package/dist/browser-posture.mjs.map +1 -1
- package/dist/browser.d.mts +10 -0
- package/dist/browser.d.mts.map +1 -1
- package/dist/browser.d.ts +10 -0
- 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 +0 -4
- package/dist/canonical-signer/index.mjs +0 -4
- package/dist/canonical-signer/index.mjs.map +1 -1
- package/dist/{client-ip-B7w-uHfS.d.ts → client-ip-8KneiMK0.d.mts} +12 -2
- package/dist/{client-ip-B7w-uHfS.d.mts.map → client-ip-8KneiMK0.d.mts.map} +1 -1
- package/dist/{client-ip-B7w-uHfS.d.mts → client-ip-8KneiMK0.d.ts} +12 -2
- package/dist/{client-ip-B7w-uHfS.d.ts.map → client-ip-8KneiMK0.d.ts.map} +1 -1
- package/dist/{client-ip-B8wFzJ5f.js → client-ip-BEmLC4I4.js} +71 -0
- package/dist/{client-ip-DIJyr6px.mjs → client-ip-DlHx7GGh.mjs} +61 -2
- package/dist/client-ip-DlHx7GGh.mjs.map +1 -0
- package/dist/client-ip.d.mts +2 -2
- package/dist/client-ip.d.ts +2 -2
- package/dist/client-ip.js +3 -1
- package/dist/client-ip.mjs +2 -2
- package/dist/deploy/index.d.mts +1 -0
- package/dist/deploy/index.d.mts.map +1 -1
- package/dist/deploy/index.d.ts +1 -0
- package/dist/deploy/index.d.ts.map +1 -1
- package/dist/deploy/index.js +14 -2
- package/dist/deploy/index.mjs +14 -2
- package/dist/deploy/index.mjs.map +1 -1
- package/dist/{detection-reason-mapping-CQexNvR7.d.ts → detection-reason-mapping-BemDaDED.d.mts} +5 -2
- package/dist/detection-reason-mapping-BemDaDED.d.mts.map +1 -0
- package/dist/{detection-reason-mapping-CQexNvR7.d.mts → detection-reason-mapping-BemDaDED.d.ts} +5 -2
- package/dist/detection-reason-mapping-BemDaDED.d.ts.map +1 -0
- package/dist/{detection-reason-mapping-B9RSkOs8.js → detection-reason-mapping-BxYaQ8kb.js} +33 -8
- package/dist/{detection-reason-mapping-BGymWIPl.mjs → detection-reason-mapping-j-7bXsVb.mjs} +29 -10
- package/dist/detection-reason-mapping-j-7bXsVb.mjs.map +1 -0
- package/dist/errors/index.d.mts +4 -0
- package/dist/errors/index.d.mts.map +1 -1
- package/dist/errors/index.d.ts +4 -0
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +24 -8
- package/dist/errors/index.mjs +24 -8
- package/dist/errors/index.mjs.map +1 -1
- package/dist/{fetcher-D2vjr7jB.d.mts → fetcher-CTKz07jg.d.mts} +13 -3
- package/dist/fetcher-CTKz07jg.d.mts.map +1 -0
- package/dist/{fetcher-C8qvwdnA.d.ts → fetcher-DCr920hx.d.ts} +13 -3
- package/dist/fetcher-DCr920hx.d.ts.map +1 -0
- package/dist/gateway-client-ip.js +1 -1
- package/dist/gateway-client-ip.mjs +1 -1
- package/dist/host-adapter/index.d.mts +1 -1
- package/dist/host-adapter/index.d.ts +1 -1
- package/dist/identity-cookie/index.d.mts +14 -0
- package/dist/identity-cookie/index.d.mts.map +1 -0
- package/dist/identity-cookie/index.d.ts +14 -0
- package/dist/identity-cookie/index.d.ts.map +1 -0
- package/dist/identity-cookie/index.js +45 -0
- package/dist/identity-cookie/index.mjs +43 -0
- package/dist/identity-cookie/index.mjs.map +1 -0
- package/dist/{index-DnFsmr_o.d.ts → index-Cdv_FH0H.d.ts} +2 -2
- package/dist/{index-DnFsmr_o.d.ts.map → index-Cdv_FH0H.d.ts.map} +1 -1
- package/dist/{index-rvw5Bz-r.d.mts → index-DL_dmQBY.d.mts} +2 -2
- package/dist/{index-rvw5Bz-r.d.mts.map → index-DL_dmQBY.d.mts.map} +1 -1
- package/dist/index.d.mts +641 -169
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +641 -169
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +819 -210
- package/dist/index.mjs +765 -200
- package/dist/index.mjs.map +1 -1
- package/dist/kya-http.d.mts +2 -2
- package/dist/kya-http.d.ts +2 -2
- package/dist/kya-http.js +7 -2
- package/dist/kya-http.mjs +2 -2
- package/dist/mcpi/dashboard-config/index.mjs.map +1 -1
- package/dist/patterns-CdTh7LU2.d.mts +35 -0
- package/dist/patterns-CdTh7LU2.d.mts.map +1 -0
- package/dist/patterns-CdTh7LU2.d.ts +35 -0
- package/dist/patterns-CdTh7LU2.d.ts.map +1 -0
- package/dist/{patterns-CiMpbdAF.js → patterns-CnNxRnaK.js} +3 -130
- package/dist/{patterns-D4OAsNQY.mjs → patterns-CpRk9R3M.mjs} +5 -96
- package/dist/patterns-CpRk9R3M.mjs.map +1 -0
- package/dist/patterns.d.mts +2 -2
- package/dist/patterns.d.ts +2 -2
- package/dist/patterns.js +1 -7
- package/dist/patterns.mjs +2 -2
- package/dist/policy/fetcher.d.mts +2 -2
- package/dist/policy/fetcher.d.ts +2 -2
- package/dist/policy/fetcher.js +100 -8
- package/dist/policy/fetcher.mjs +99 -9
- package/dist/policy/fetcher.mjs.map +1 -1
- package/dist/policy/schemas.d.mts +1 -1
- package/dist/policy/schemas.d.ts +1 -1
- package/dist/proxy-assertion-mapping-BVwXVSMZ.mjs +81 -0
- package/dist/proxy-assertion-mapping-BVwXVSMZ.mjs.map +1 -0
- package/dist/proxy-assertion-mapping-BxhENrcY.d.mts +70 -0
- package/dist/proxy-assertion-mapping-BxhENrcY.d.mts.map +1 -0
- package/dist/proxy-assertion-mapping-D64AyZfG.js +85 -0
- package/dist/proxy-assertion-mapping-DhAynFqG.d.ts +70 -0
- package/dist/proxy-assertion-mapping-DhAynFqG.d.ts.map +1 -0
- package/dist/proxy-assertions.d.mts +2 -0
- package/dist/proxy-assertions.d.ts +2 -0
- package/dist/proxy-assertions.js +4 -0
- package/dist/proxy-assertions.mjs +3 -0
- package/dist/reason-codes.d.mts +2 -2
- package/dist/reason-codes.d.ts +2 -2
- package/dist/reason-codes.js +3 -2
- package/dist/reason-codes.mjs +2 -2
- package/dist/{registered-sid-D6KCaT1E.d.ts → registered-sid-BgDhdj2l.d.mts} +24 -2
- package/dist/registered-sid-BgDhdj2l.d.mts.map +1 -0
- package/dist/{registered-sid-D6KCaT1E.d.mts → registered-sid-BgDhdj2l.d.ts} +24 -2
- package/dist/registered-sid-BgDhdj2l.d.ts.map +1 -0
- package/dist/{registered-sid-DVGTSH0L.js → registered-sid-DG1tSSvl.js} +162 -4
- package/dist/{registered-sid-26hNxp6t.mjs → registered-sid-D__xiDPu.mjs} +134 -6
- package/dist/registered-sid-D__xiDPu.mjs.map +1 -0
- package/dist/{schemas-m-GqyfyO.d.mts → schemas-BhC88D1-.d.mts} +5 -5
- package/dist/{schemas-m-GqyfyO.d.mts.map → schemas-BhC88D1-.d.mts.map} +1 -1
- package/dist/{schemas-CGKHzcMV.d.ts → schemas-DZa1ouGs.d.ts} +5 -5
- package/dist/{schemas-CGKHzcMV.d.ts.map → schemas-DZa1ouGs.d.ts.map} +1 -1
- package/dist/signals/index.d.mts.map +1 -1
- package/dist/signals/index.d.ts.map +1 -1
- package/dist/signals/index.js +4 -0
- package/dist/signals/index.mjs +4 -0
- package/dist/signals/index.mjs.map +1 -1
- package/dist/timezone-country-B6PkDyNP.d.mts +15 -0
- package/dist/timezone-country-B6PkDyNP.d.mts.map +1 -0
- package/dist/timezone-country-B6PkDyNP.d.ts +15 -0
- package/dist/timezone-country-B6PkDyNP.d.ts.map +1 -0
- package/dist/timezone-country-CROxU2Tl.js +505 -0
- package/dist/timezone-country-CrrnkOdy.mjs +489 -0
- package/dist/timezone-country-CrrnkOdy.mjs.map +1 -0
- package/dist/timezone-country.d.mts +2 -0
- package/dist/timezone-country.d.ts +2 -0
- package/dist/timezone-country.js +6 -0
- package/dist/timezone-country.mjs +3 -0
- package/dist/tool-protection/index.mjs.map +1 -1
- package/fixtures/detection/cloudflare-alias-parity.json +383 -0
- package/fixtures/detection/reason-codes.json +3 -1
- package/fixtures/detection/signal-exposure-example.json +1 -1
- package/fixtures/iana-tzdata/backward +375 -0
- package/fixtures/iana-tzdata/renamed-zones.json +21 -0
- package/fixtures/iana-tzdata/version +1 -0
- package/fixtures/iana-tzdata/zone.tab +448 -0
- package/fixtures/workbench/management-session.v1.json +20 -0
- package/fixtures/workbench/model-credentials.v1.json +8 -0
- package/fixtures/workbench/task-grant.v1.json +37 -0
- package/package.json +25 -3
- package/src/data/compiled/merged-rules.json +9 -7
- package/dist/browser-posture-5fPrsxx7.d.mts.map +0 -1
- package/dist/browser-posture-CCR1kh5e.d.ts.map +0 -1
- package/dist/browser-posture-proof-verifier-DvsOmFrM.js +0 -202
- package/dist/browser-posture-proof-verifier-I0HP2Ics.mjs +0 -180
- package/dist/browser-posture-proof-verifier-I0HP2Ics.mjs.map +0 -1
- package/dist/client-ip-DIJyr6px.mjs.map +0 -1
- package/dist/detection-reason-mapping-BGymWIPl.mjs.map +0 -1
- package/dist/detection-reason-mapping-CQexNvR7.d.mts.map +0 -1
- package/dist/detection-reason-mapping-CQexNvR7.d.ts.map +0 -1
- package/dist/fetcher-C8qvwdnA.d.ts.map +0 -1
- package/dist/fetcher-D2vjr7jB.d.mts.map +0 -1
- package/dist/patterns-Bp40cwh2.d.mts +0 -110
- package/dist/patterns-Bp40cwh2.d.mts.map +0 -1
- package/dist/patterns-Bp40cwh2.d.ts +0 -110
- package/dist/patterns-Bp40cwh2.d.ts.map +0 -1
- package/dist/patterns-D4OAsNQY.mjs.map +0 -1
- package/dist/registered-sid-26hNxp6t.mjs.map +0 -1
- package/dist/registered-sid-D6KCaT1E.d.mts.map +0 -1
- package/dist/registered-sid-D6KCaT1E.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetcher.mjs","names":[],"sources":["../../src/policy/fetcher.ts"],"sourcesContent":["/**\n * Policy Fetcher\n *\n * Runtime-agnostic policy fetching with caching support.\n * Works in Edge (Cloudflare Workers, Next.js Edge), Node.js, and browser environments.\n *\n * The fetcher supports:\n * - In-memory caching with TTL\n * - Origin reads for legacy adapters that cannot coordinate shared invalidation\n * - Fallback to default policy on errors\n * - Configurable API endpoints\n */\n\nimport { CACHE_TTL, DEFAULT_POLICY } from './constants';\nimport { PolicyConfigSchema, safeParsePolicyConfig } from './schemas';\nimport type { PolicyConfig } from './schemas';\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/**\n * Legacy cache adapter interface retained for source compatibility.\n * Get/set alone cannot fence policy revocation across runtimes, so configured\n * adapters use fresh origin reads rather than selectable memory or external entries.\n */\nexport interface PolicyCacheAdapter {\n get(key: string): Promise<string | null>;\n set(key: string, value: string, ttlSeconds: number): Promise<void>;\n /** Optional cleanup of retired entries; invalidation does not depend on deletion. */\n delete?(key: string): Promise<boolean>;\n}\n\n/**\n * Configuration for the policy fetcher\n */\nexport interface PolicyFetcherConfig {\n /** Base URL for the policy API */\n apiBaseUrl: string;\n /** API key for authentication (optional) */\n apiKey?: string;\n /** Cache TTL in seconds (default: 300) */\n cacheTtlSeconds?: number;\n /** Legacy external adapter; loads use origin authority without cache hits. */\n cacheAdapter?: PolicyCacheAdapter;\n /** Disable in-memory caching (default: false) */\n disableMemoryCache?: boolean;\n /** Total policy-load timeout, including response parsing (default: 5000ms). */\n timeoutMs?: number;\n /** Reject origin failures as POLICY_UNAVAILABLE instead of returning DEFAULT_POLICY. */\n throwOnUnavailable?: boolean;\n /** Custom fetch function (for testing or custom transport) */\n fetchFn?: typeof fetch;\n}\n\n/**\n * Cached policy entry with metadata\n */\nexport interface CachedPolicy {\n policy: PolicyConfig;\n projectId: string;\n cachedAt: string;\n expiresAt: string;\n}\n\nfunction looksLikePolicyApiBody(data: unknown): data is Record<string, unknown> {\n if (typeof data !== 'object' || data === null) return false;\n const threshold = (data as { blockThreshold?: unknown }).blockThreshold;\n return typeof threshold === 'number' && Number.isFinite(threshold);\n}\n\n/**\n * The policy API serves the allow list as agent names (the `string[]` the\n * gateway Worker reads), while the policy schema models each entry as an\n * object. Read a name as `{ clientName }` before validating; anything else is\n * left for the schema to judge.\n */\nfunction fromPolicyApiBody(data: Record<string, unknown>): Record<string, unknown> {\n const { allowList } = data;\n if (!Array.isArray(allowList)) return data;\n return {\n ...data,\n allowList: allowList.map((entry: unknown) =>\n typeof entry === 'string' ? { clientName: entry } : entry\n ),\n };\n}\n\nexport class PolicyUnavailableError extends Error {\n readonly code = 'POLICY_UNAVAILABLE';\n\n constructor() {\n super('Current policy could not be loaded within the permitted bound');\n this.name = 'PolicyUnavailableError';\n }\n}\n\n/** Recognize the same failure across independently loaded SDK package copies. */\nexport function isPolicyUnavailableError(error: unknown): boolean {\n return (\n error instanceof Error &&\n error.name === 'PolicyUnavailableError' &&\n 'code' in error &&\n error.code === 'POLICY_UNAVAILABLE'\n );\n}\n\n// ============================================================================\n// In-Memory Cache\n// ============================================================================\n\n/**\n * Simple in-memory cache with TTL support\n */\nclass MemoryCache {\n private cache = new Map<string, { value: string; expiresAt: number }>();\n\n get(key: string): string | null {\n const entry = this.cache.get(key);\n if (!entry) {\n return null;\n }\n\n if (Date.now() > entry.expiresAt) {\n this.cache.delete(key);\n return null;\n }\n\n return entry.value;\n }\n\n set(key: string, value: string, ttlSeconds: number): void {\n this.cache.set(key, {\n value,\n expiresAt: Date.now() + ttlSeconds * 1000,\n });\n }\n\n delete(key: string): boolean {\n return this.cache.delete(key);\n }\n\n clear(): void {\n this.cache.clear();\n }\n}\n\n// Global in-memory cache instance\nconst globalMemoryCache = new MemoryCache();\n// Share invalidation with other fetchers using the same backend, TTL and project.\nconst globalPolicyCacheKeys = new Map<string, string>();\nconst fallbackCachePrefix = `${Date.now().toString(36)}:${Math.random().toString(36).slice(2)}:${Math.random().toString(36).slice(2)}`;\nlet fallbackCacheSequence = 0;\n\nfunction nextCacheRevision(): string {\n // This token only separates cache generations; it is not an authentication secret.\n return globalThis.crypto?.randomUUID?.() ?? `${fallbackCachePrefix}:${++fallbackCacheSequence}`;\n}\n\n// ============================================================================\n// Policy Fetcher Class\n// ============================================================================\n\n/**\n * Policy fetcher with caching and fallback support\n */\nexport class PolicyFetcher {\n private config: Required<Omit<PolicyFetcherConfig, 'cacheAdapter' | 'apiKey'>> & {\n cacheAdapter?: PolicyCacheAdapter;\n apiKey?: string;\n };\n private memoryCache: MemoryCache;\n\n constructor(config: PolicyFetcherConfig) {\n this.config = {\n apiBaseUrl: config.apiBaseUrl,\n apiKey: config.apiKey,\n cacheTtlSeconds: config.cacheTtlSeconds ?? CACHE_TTL.POLICY,\n cacheAdapter: config.cacheAdapter,\n disableMemoryCache: config.disableMemoryCache ?? false,\n timeoutMs: config.timeoutMs ?? 5000,\n throwOnUnavailable: config.throwOnUnavailable ?? false,\n fetchFn: config.fetchFn ?? globalThis.fetch,\n };\n this.memoryCache = config.disableMemoryCache ? new MemoryCache() : globalMemoryCache;\n }\n\n /**\n * Generate a cache key that includes the API base URL and TTL to prevent\n * cache collisions when multiple fetchers use different backends or TTL settings.\n */\n private getBaseCacheKey(projectId: string): string {\n // Use a hash of the apiBaseUrl to keep keys reasonably short\n const urlHash = this.config.apiBaseUrl\n .split('')\n .reduce((hash, char) => ((hash << 5) - hash + char.charCodeAt(0)) | 0, 0)\n .toString(36);\n // Include TTL in key to prevent cross-fetcher cache interference\n // (fetcher with TTL=60 shouldn't read cache written by fetcher with TTL=300)\n return `policy:${urlHash}:${this.config.cacheTtlSeconds}:${projectId}`;\n }\n\n private getCacheKey(projectId: string): string {\n const baseKey = this.getBaseCacheKey(projectId);\n return globalPolicyCacheKeys.get(baseKey) ?? baseKey;\n }\n\n /**\n * Get policy for a project, with caching\n */\n async getPolicy(projectId: string): Promise<PolicyConfig> {\n const deadline = Date.now() + this.config.timeoutMs;\n if (!Number.isFinite(deadline) || this.config.timeoutMs <= 0)\n throw new PolicyUnavailableError();\n const controller = new AbortController();\n const requireActiveLoad = () => {\n if (controller.signal.aborted || Date.now() >= deadline) throw new PolicyUnavailableError();\n };\n let timer: ReturnType<typeof setTimeout> | undefined;\n const expired = new Promise<never>((_resolve, reject) => {\n timer = setTimeout(() => {\n const failure = new PolicyUnavailableError();\n controller.abort(failure);\n reject(failure);\n }, this.config.timeoutMs);\n });\n // Without shared revision coordination, neither a peer's entry nor a local\n // memory hit can prove current authority. Keep legacy adapters compatible\n // by using origin reads, while preserving local-only memory caching.\n const useMemoryCache = !this.config.disableMemoryCache && !this.config.cacheAdapter;\n try {\n for (let attempt = 0; attempt < 4; attempt++) {\n requireActiveLoad();\n const cacheKey = this.getCacheKey(projectId);\n if (useMemoryCache) {\n const memoryCached = this.memoryCache.get(cacheKey);\n if (memoryCached) {\n const cached = JSON.parse(memoryCached) as CachedPolicy;\n requireActiveLoad();\n if (!this.isExpired(cached.expiresAt)) return cached.policy;\n }\n }\n try {\n const policy = await Promise.race([\n this.fetchPolicyFromApi(projectId, controller.signal),\n expired,\n ]);\n requireActiveLoad();\n if (cacheKey !== this.getCacheKey(projectId)) continue;\n if (useMemoryCache) {\n const now = new Date();\n const cached: CachedPolicy = {\n policy,\n projectId,\n cachedAt: now.toISOString(),\n expiresAt: new Date(now.getTime() + this.config.cacheTtlSeconds * 1000).toISOString(),\n };\n const cacheValue = JSON.stringify(cached);\n requireActiveLoad();\n this.memoryCache.set(cacheKey, cacheValue, this.config.cacheTtlSeconds);\n }\n requireActiveLoad();\n return policy;\n } catch (error) {\n requireActiveLoad();\n if (isPolicyUnavailableError(error)) throw error;\n if (cacheKey !== this.getCacheKey(projectId)) continue;\n console.error(`[PolicyFetcher] Failed to fetch policy for ${projectId}:`, error);\n if (this.config.throwOnUnavailable) throw new PolicyUnavailableError();\n return this.getDefaultPolicy();\n }\n }\n throw new PolicyUnavailableError();\n } finally {\n if (timer !== undefined) clearTimeout(timer);\n }\n }\n\n /**\n * Fetch policy from the API\n */\n private async fetchPolicyFromApi(projectId: string, signal: AbortSignal): Promise<PolicyConfig> {\n const url = `${this.config.apiBaseUrl}/api/internal/policies/${projectId}`;\n\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n 'User-Agent': 'AgentShield-PolicyFetcher/1.0',\n };\n\n if (this.config.apiKey) {\n headers['Authorization'] = `Bearer ${this.config.apiKey}`;\n }\n\n const response = await this.config.fetchFn(url, {\n method: 'GET',\n headers,\n signal,\n // Origin responses permit HTTP caching; it must not restore retired authority.\n cache: 'no-store',\n });\n\n if (!response.ok) {\n throw new Error(`API returned ${response.status}: ${response.statusText}`);\n }\n\n const data = await response.json();\n\n // The API response contract requires this field; schemas also accept\n // partial user config, so validate the wire shape before applying defaults.\n if (!looksLikePolicyApiBody(data)) {\n throw new Error('Policy response is not from the policy API');\n }\n\n // Parse and validate the response\n const policy = safeParsePolicyConfig(fromPolicyApiBody(data));\n if (!policy) {\n throw new Error('Invalid policy response format');\n }\n\n return policy;\n }\n\n /**\n * Get the default policy\n */\n getDefaultPolicy(): PolicyConfig {\n return PolicyConfigSchema.parse(DEFAULT_POLICY);\n }\n\n /**\n * Retire this runtime's cached policy key before any asynchronous cleanup.\n * Older reads and writes cannot restore the retired entry for these fetchers.\n */\n async invalidateCache(projectId: string): Promise<void> {\n const cacheKey = this.getCacheKey(projectId);\n const baseKey = this.getBaseCacheKey(projectId);\n globalPolicyCacheKeys.set(baseKey, `${baseKey}:${nextCacheRevision()}`);\n\n // Retire shared memory even when this caller does not read memory entries.\n globalMemoryCache.delete(cacheKey);\n\n // Clear external cache if adapter supports delete\n if (this.config.cacheAdapter?.delete) {\n const keys = cacheKey === baseKey ? [baseKey] : [cacheKey, baseKey];\n await Promise.all(\n keys.map(async (key) => {\n try {\n await this.config.cacheAdapter!.delete!(key);\n } catch (error) {\n console.error('[PolicyFetcher] Failed to delete from external cache:', error);\n }\n })\n );\n }\n }\n\n /**\n * Clear all cached policies\n */\n clearCache(): void {\n if (!this.config.disableMemoryCache) {\n this.memoryCache.clear();\n }\n }\n\n /**\n * Check if a date string is expired\n */\n private isExpired(dateString: string): boolean {\n return new Date(dateString).getTime() < Date.now();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiEA,SAAS,uBAAuB,MAAgD;CAC9E,IAAI,OAAO,SAAS,YAAY,SAAS,MAAM,OAAO;CACtD,MAAM,YAAa,KAAsC;CACzD,OAAO,OAAO,cAAc,YAAY,OAAO,SAAS,SAAS;AACnE;;;;;;;AAQA,SAAS,kBAAkB,MAAwD;CACjF,MAAM,EAAE,cAAc;CACtB,IAAI,CAAC,MAAM,QAAQ,SAAS,GAAG,OAAO;CACtC,OAAO;EACL,GAAG;EACH,WAAW,UAAU,KAAK,UACxB,OAAO,UAAU,WAAW,EAAE,YAAY,MAAM,IAAI,KACtD;CACF;AACF;AAEA,IAAa,yBAAb,cAA4C,MAAM;CAChD,AAAS,OAAO;CAEhB,cAAc;EACZ,MAAM,+DAA+D;EACrE,KAAK,OAAO;CACd;AACF;;AAGA,SAAgB,yBAAyB,OAAyB;CAChE,OACE,iBAAiB,SACjB,MAAM,SAAS,4BACf,UAAU,SACV,MAAM,SAAS;AAEnB;;;;AASA,IAAM,cAAN,MAAkB;CAChB,AAAQ,wBAAQ,IAAI,IAAkD;CAEtE,IAAI,KAA4B;EAC9B,MAAM,QAAQ,KAAK,MAAM,IAAI,GAAG;EAChC,IAAI,CAAC,OACH,OAAO;EAGT,IAAI,KAAK,IAAI,IAAI,MAAM,WAAW;GAChC,KAAK,MAAM,OAAO,GAAG;GACrB,OAAO;EACT;EAEA,OAAO,MAAM;CACf;CAEA,IAAI,KAAa,OAAe,YAA0B;EACxD,KAAK,MAAM,IAAI,KAAK;GAClB;GACA,WAAW,KAAK,IAAI,IAAI,aAAa;EACvC,CAAC;CACH;CAEA,OAAO,KAAsB;EAC3B,OAAO,KAAK,MAAM,OAAO,GAAG;CAC9B;CAEA,QAAc;EACZ,KAAK,MAAM,MAAM;CACnB;AACF;AA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AAQ;GACpC,MAAM,OAAO,aAAa,UAAU,CAAC,OAAO,IAAI,CAAC,UAAU,OAAO;GAClE,MAAM,QAAQ,IACZ,KAAK,IAAI,OAAO,QAAQ;IACtB,IAAI;KACF,MAAM,KAAK,OAAO,aAAc,OAAQ,GAAG;IAC7C,SAAS,OAAO;KACd,QAAQ,MAAM,yDAAyD,KAAK;IAC9E;GACF,CAAC,CACH;EACF;CACF;;;;CAKA,aAAmB;EACjB,IAAI,CAAC,KAAK,OAAO,oBACf,KAAK,YAAY,MAAM;CAE3B;;;;CAKA,AAAQ,UAAU,YAA6B;EAC7C,OAAO,IAAI,KAAK,UAAU,CAAC,CAAC,QAAQ,IAAI,KAAK,IAAI;CACnD;AACF"}
|
|
1
|
+
{"version":3,"file":"fetcher.mjs","names":[],"sources":["../../src/policy/fetcher.ts"],"sourcesContent":["/**\n * Policy Fetcher\n *\n * Runtime-agnostic policy fetching with caching support.\n * Works in Edge (Cloudflare Workers, Next.js Edge), Node.js, and browser environments.\n *\n * The fetcher supports:\n * - In-memory caching with TTL\n * - Origin reads for legacy adapters that cannot coordinate shared invalidation\n * - Fallback to default policy on errors\n * - A short, jittered memory of failed loads: a refused key or a timeout costs\n * one origin call and one log line per window, and any other failure is\n * retried on the next load but logged once per window\n * - Configurable API endpoints\n */\n\nimport { CACHE_TTL, DEFAULT_POLICY } from './constants';\nimport { PolicyConfigSchema, safeParsePolicyConfig } from './schemas';\nimport type { PolicyConfig } from './schemas';\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/**\n * Legacy cache adapter interface retained for source compatibility.\n * Get/set alone cannot fence policy revocation across runtimes, so configured\n * adapters use fresh origin reads rather than selectable memory or external entries.\n */\nexport interface PolicyCacheAdapter {\n get(key: string): Promise<string | null>;\n set(key: string, value: string, ttlSeconds: number): Promise<void>;\n /** Optional cleanup of retired entries; invalidation does not depend on deletion. */\n delete?(key: string): Promise<boolean>;\n}\n\n/**\n * Configuration for the policy fetcher\n */\nexport interface PolicyFetcherConfig {\n /** Base URL for the policy API */\n apiBaseUrl: string;\n /** API key for authentication (optional) */\n apiKey?: string;\n /** Cache TTL in seconds (default: 300) */\n cacheTtlSeconds?: number;\n /** Legacy external adapter; loads use origin authority without cache hits. */\n cacheAdapter?: PolicyCacheAdapter;\n /** Disable in-memory caching (default: false) */\n disableMemoryCache?: boolean;\n /** Total policy-load timeout, including response parsing (default: 5000ms). */\n timeoutMs?: number;\n /** Reject origin failures as POLICY_UNAVAILABLE instead of returning DEFAULT_POLICY. */\n throwOnUnavailable?: boolean;\n /** Custom fetch function (for testing or custom transport) */\n fetchFn?: typeof fetch;\n}\n\n/**\n * Cached policy entry with metadata\n */\nexport interface CachedPolicy {\n policy: PolicyConfig;\n projectId: string;\n cachedAt: string;\n expiresAt: string;\n}\n\nfunction looksLikePolicyApiBody(data: unknown): data is Record<string, unknown> {\n if (typeof data !== 'object' || data === null) return false;\n const threshold = (data as { blockThreshold?: unknown }).blockThreshold;\n return typeof threshold === 'number' && Number.isFinite(threshold);\n}\n\n/**\n * The policy API serves the allow list as agent names (the `string[]` the\n * gateway Worker reads), while the policy schema models each entry as an\n * object. Read a name as `{ clientName }` before validating; anything else is\n * left for the schema to judge.\n */\nfunction fromPolicyApiBody(data: Record<string, unknown>): Record<string, unknown> {\n const { allowList } = data;\n if (!Array.isArray(allowList)) return data;\n return {\n ...data,\n allowList: allowList.map((entry: unknown) =>\n typeof entry === 'string' ? { clientName: entry } : entry\n ),\n };\n}\n\nexport class PolicyUnavailableError extends Error {\n readonly code = 'POLICY_UNAVAILABLE';\n\n constructor() {\n super('Current policy could not be loaded within the permitted bound');\n this.name = 'PolicyUnavailableError';\n }\n}\n\n/** Recognize the same failure across independently loaded SDK package copies. */\nexport function isPolicyUnavailableError(error: unknown): boolean {\n return (\n error instanceof Error &&\n error.name === 'PolicyUnavailableError' &&\n 'code' in error &&\n error.code === 'POLICY_UNAVAILABLE'\n );\n}\n\n/**\n * The policy API refused the request's credentials (HTTP 401 or 403). This is a\n * configuration fault, not an outage, so the message names the key to check.\n */\nexport class PolicyAuthError extends Error {\n readonly code = 'POLICY_AUTH_FAILED';\n readonly status: number;\n\n constructor(status: number, apiKeySent: boolean) {\n super(\n apiKeySent\n ? `The policy API refused the API key (HTTP ${status}); check that CHECKPOINT_API_KEY is this project's API key`\n : `The policy API requires an API key (HTTP ${status}); set apiKey (CHECKPOINT_API_KEY)`\n );\n this.name = 'PolicyAuthError';\n this.status = status;\n }\n}\n\n/** Recognize the same failure across independently loaded SDK package copies. */\nexport function isPolicyAuthError(error: unknown): error is PolicyAuthError {\n return (\n error instanceof Error &&\n error.name === 'PolicyAuthError' &&\n 'code' in error &&\n error.code === 'POLICY_AUTH_FAILED'\n );\n}\n\n/**\n * How long a failed load is remembered. After a refused key or a timeout, a\n * load within the window gets the same outcome without a fetch or a log line,\n * so a wrong key or a hung origin costs one origin call and one log line per\n * window rather than one per request (and no request waits out another\n * timeout). A refused key waits longer, since it does not recover until the\n * host is reconfigured. Any other failure (a 5xx, a network error, a body\n * that is not a policy) is often transient, so the next load reads the origin\n * again; only its repeat log lines are suppressed for the window.\n */\nconst FAILURE_RETRY_MS = { unavailable: 5_000, auth: 60_000 } as const;\n/** Each window is stretched or shortened by up to this fraction, so instances spread their retries. */\nconst FAILURE_RETRY_JITTER = 0.2;\n\ntype PolicyLoadFailure =\n | { kind: 'timeout' }\n | { kind: 'failed' }\n | { kind: 'auth'; status: number; apiKeySent: boolean };\n\n// ============================================================================\n// In-Memory Cache\n// ============================================================================\n\n/**\n * Simple in-memory cache with TTL support\n */\nclass MemoryCache {\n private cache = new Map<string, { value: string; expiresAt: number }>();\n\n get(key: string): string | null {\n const entry = this.cache.get(key);\n if (!entry) {\n return null;\n }\n\n if (Date.now() >= entry.expiresAt) {\n this.cache.delete(key);\n return null;\n }\n\n return entry.value;\n }\n\n set(key: string, value: string, ttlSeconds: number): void {\n this.cache.set(key, {\n value,\n expiresAt: Date.now() + ttlSeconds * 1000,\n });\n }\n\n delete(key: string): boolean {\n return this.cache.delete(key);\n }\n\n clear(): void {\n this.cache.clear();\n }\n}\n\n// Global in-memory cache instance\nconst globalMemoryCache = new MemoryCache();\n// Share invalidation with other fetchers using the same backend, TTL and project.\nconst globalPolicyCacheKeys = new Map<string, string>();\nconst fallbackCachePrefix = `${Date.now().toString(36)}:${Math.random().toString(36).slice(2)}:${Math.random().toString(36).slice(2)}`;\nlet fallbackCacheSequence = 0;\n\nfunction nextCacheRevision(): string {\n // This token only separates cache generations; it is not an authentication secret.\n return globalThis.crypto?.randomUUID?.() ?? `${fallbackCachePrefix}:${++fallbackCacheSequence}`;\n}\n\n// ============================================================================\n// Policy Fetcher Class\n// ============================================================================\n\n/**\n * Policy fetcher with caching and fallback support\n */\nexport class PolicyFetcher {\n private config: Required<Omit<PolicyFetcherConfig, 'cacheAdapter' | 'apiKey'>> & {\n cacheAdapter?: PolicyCacheAdapter;\n apiKey?: string;\n };\n private memoryCache: MemoryCache;\n /** Recent failed loads by cache key; see {@link FAILURE_RETRY_MS}. */\n private failures = new Map<string, { failure: PolicyLoadFailure; retryAt: number }>();\n\n constructor(config: PolicyFetcherConfig) {\n this.config = {\n apiBaseUrl: config.apiBaseUrl,\n apiKey: config.apiKey,\n cacheTtlSeconds: config.cacheTtlSeconds ?? CACHE_TTL.POLICY,\n cacheAdapter: config.cacheAdapter,\n disableMemoryCache: config.disableMemoryCache ?? false,\n timeoutMs: config.timeoutMs ?? 5000,\n throwOnUnavailable: config.throwOnUnavailable ?? false,\n fetchFn: config.fetchFn ?? globalThis.fetch,\n };\n this.memoryCache = config.disableMemoryCache ? new MemoryCache() : globalMemoryCache;\n }\n\n /**\n * Generate a cache key that includes the API base URL and TTL to prevent\n * cache collisions when multiple fetchers use different backends or TTL settings.\n */\n private getBaseCacheKey(projectId: string): string {\n // Use a hash of the apiBaseUrl to keep keys reasonably short\n const urlHash = this.config.apiBaseUrl\n .split('')\n .reduce((hash, char) => ((hash << 5) - hash + char.charCodeAt(0)) | 0, 0)\n .toString(36);\n // Include TTL in key to prevent cross-fetcher cache interference\n // (fetcher with TTL=60 shouldn't read cache written by fetcher with TTL=300)\n return `policy:${urlHash}:${this.config.cacheTtlSeconds}:${projectId}`;\n }\n\n private getCacheKey(projectId: string): string {\n const baseKey = this.getBaseCacheKey(projectId);\n return globalPolicyCacheKeys.get(baseKey) ?? baseKey;\n }\n\n /**\n * Get policy for a project, with caching\n */\n async getPolicy(projectId: string): Promise<PolicyConfig> {\n const deadline = Date.now() + this.config.timeoutMs;\n if (!Number.isFinite(deadline) || this.config.timeoutMs <= 0)\n throw new PolicyUnavailableError();\n const controller = new AbortController();\n const requireActiveLoad = () => {\n if (controller.signal.aborted || Date.now() >= deadline) throw new PolicyUnavailableError();\n };\n let timer: ReturnType<typeof setTimeout> | undefined;\n const expired = new Promise<never>((_resolve, reject) => {\n timer = setTimeout(() => {\n const failure = new PolicyUnavailableError();\n controller.abort(failure);\n reject(failure);\n }, this.config.timeoutMs);\n });\n // Without shared revision coordination, neither a peer's entry nor a local\n // memory hit can prove current authority. Keep legacy adapters compatible\n // by using origin reads, while preserving local-only memory caching.\n const useMemoryCache = !this.config.disableMemoryCache && !this.config.cacheAdapter;\n try {\n for (let attempt = 0; attempt < 4; attempt++) {\n requireActiveLoad();\n const cacheKey = this.getCacheKey(projectId);\n if (useMemoryCache) {\n const memoryCached = this.memoryCache.get(cacheKey);\n if (memoryCached) {\n const cached = JSON.parse(memoryCached) as CachedPolicy;\n requireActiveLoad();\n if (!this.isExpired(cached.expiresAt)) return cached.policy;\n }\n }\n const recent = this.recentFailure(cacheKey);\n if (recent && recent.kind !== 'failed') return this.failedLoad(recent);\n try {\n const policy = await Promise.race([\n this.fetchPolicyFromApi(projectId, controller.signal),\n expired,\n ]);\n requireActiveLoad();\n if (cacheKey !== this.getCacheKey(projectId)) continue;\n // A successful load ends any failure remembered for its key.\n if (this.failures.has(cacheKey)) this.failures.delete(cacheKey);\n if (useMemoryCache) {\n const now = new Date();\n const cached: CachedPolicy = {\n policy,\n projectId,\n cachedAt: now.toISOString(),\n expiresAt: new Date(now.getTime() + this.config.cacheTtlSeconds * 1000).toISOString(),\n };\n const cacheValue = JSON.stringify(cached);\n requireActiveLoad();\n this.memoryCache.set(cacheKey, cacheValue, this.config.cacheTtlSeconds);\n }\n requireActiveLoad();\n return policy;\n } catch (error) {\n const timedOut =\n controller.signal.aborted || Date.now() >= deadline || isPolicyUnavailableError(error);\n const current = cacheKey === this.getCacheKey(projectId);\n if (!timedOut && !current) continue;\n const failure: PolicyLoadFailure = timedOut\n ? { kind: 'timeout' }\n : isPolicyAuthError(error)\n ? { kind: 'auth', status: error.status, apiKeySent: Boolean(this.config.apiKey) }\n : { kind: 'failed' };\n // A load that crossed an invalidation says nothing about the new key.\n if (current) this.rememberFailure(cacheKey, projectId, failure, error);\n return this.failedLoad(failure);\n }\n }\n throw new PolicyUnavailableError();\n } finally {\n if (timer !== undefined) clearTimeout(timer);\n }\n }\n\n /**\n * Fetch policy from the API\n */\n private async fetchPolicyFromApi(projectId: string, signal: AbortSignal): Promise<PolicyConfig> {\n const url = `${this.config.apiBaseUrl}/api/internal/policies/${projectId}`;\n\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n 'User-Agent': 'AgentShield-PolicyFetcher/1.0',\n };\n\n if (this.config.apiKey) {\n headers['Authorization'] = `Bearer ${this.config.apiKey}`;\n }\n\n const response = await this.config.fetchFn(url, {\n method: 'GET',\n headers,\n signal,\n // Origin responses permit HTTP caching; it must not restore retired authority.\n cache: 'no-store',\n });\n\n if (response.status === 401 || response.status === 403) {\n throw new PolicyAuthError(response.status, Boolean(this.config.apiKey));\n }\n if (!response.ok) {\n throw new Error(`API returned ${response.status}: ${response.statusText}`);\n }\n\n const data = await response.json();\n\n // The API response contract requires this field; schemas also accept\n // partial user config, so validate the wire shape before applying defaults.\n if (!looksLikePolicyApiBody(data)) {\n throw new Error('Policy response is not from the policy API');\n }\n\n // Parse and validate the response\n const policy = safeParsePolicyConfig(fromPolicyApiBody(data));\n if (!policy) {\n throw new Error('Invalid policy response format');\n }\n\n return policy;\n }\n\n /**\n * Get the default policy\n */\n getDefaultPolicy(): PolicyConfig {\n return PolicyConfigSchema.parse(DEFAULT_POLICY);\n }\n\n /** The failure remembered for this key, while its window lasts. */\n private recentFailure(cacheKey: string): PolicyLoadFailure | undefined {\n const entry = this.failures.get(cacheKey);\n if (!entry) return undefined;\n if (Date.now() < entry.retryAt) return entry.failure;\n this.failures.delete(cacheKey);\n return undefined;\n }\n\n /**\n * Remember a failed load and log it, once per window: a load that fails the\n * same way while the window is open neither extends it nor logs again, and\n * neither does a fast failure during a refused-key or timeout window. A\n * different failure replaces a fast failure's window and is logged.\n */\n private rememberFailure(\n cacheKey: string,\n projectId: string,\n failure: PolicyLoadFailure,\n error: unknown\n ): void {\n const recent = this.recentFailure(cacheKey);\n if (recent && (recent.kind === failure.kind || failure.kind === 'failed')) return;\n const now = Date.now();\n for (const [key, entry] of this.failures) {\n if (now >= entry.retryAt) this.failures.delete(key);\n }\n const windowMs = FAILURE_RETRY_MS[failure.kind === 'auth' ? 'auth' : 'unavailable'];\n const jitter = 1 + FAILURE_RETRY_JITTER * (2 * Math.random() - 1);\n this.failures.set(cacheKey, { failure, retryAt: now + Math.round(windowMs * jitter) });\n\n const retry = `retrying after about ${windowMs / 1000} s`;\n if (failure.kind === 'auth') {\n const refused = new PolicyAuthError(failure.status, failure.apiKeySent);\n console.error(\n `[PolicyFetcher] Policy for ${projectId} not loaded: ${refused.message}; ${retry}`\n );\n } else if (failure.kind === 'timeout') {\n console.error(\n `[PolicyFetcher] Policy for ${projectId} did not load within ${this.config.timeoutMs} ms; ${retry}`\n );\n } else {\n console.error(\n `[PolicyFetcher] Failed to fetch policy for ${projectId}; further failures in the next ${windowMs / 1000} s are not logged:`,\n error\n );\n }\n }\n\n /**\n * The outcome of a failed load. A timeout always rejects. A refused key\n * rejects with {@link PolicyAuthError} and any other failure with\n * {@link PolicyUnavailableError} when `throwOnUnavailable` is set; otherwise\n * both return the default policy.\n */\n private failedLoad(failure: PolicyLoadFailure): PolicyConfig {\n if (failure.kind === 'timeout') throw new PolicyUnavailableError();\n if (!this.config.throwOnUnavailable) return this.getDefaultPolicy();\n if (failure.kind === 'auth') throw new PolicyAuthError(failure.status, failure.apiKeySent);\n throw new PolicyUnavailableError();\n }\n\n /**\n * Retire this runtime's cached policy key before any asynchronous cleanup.\n * Older reads and writes cannot restore the retired entry for these fetchers.\n */\n async invalidateCache(projectId: string): Promise<void> {\n const cacheKey = this.getCacheKey(projectId);\n const baseKey = this.getBaseCacheKey(projectId);\n globalPolicyCacheKeys.set(baseKey, `${baseKey}:${nextCacheRevision()}`);\n\n // Retire shared memory even when this caller does not read memory entries.\n globalMemoryCache.delete(cacheKey);\n\n // Clear external cache if adapter supports delete\n if (this.config.cacheAdapter?.delete) {\n const keys = cacheKey === baseKey ? [baseKey] : [cacheKey, baseKey];\n await Promise.all(\n keys.map(async (key) => {\n try {\n await this.config.cacheAdapter!.delete!(key);\n } catch (error) {\n console.error('[PolicyFetcher] Failed to delete from external cache:', error);\n }\n })\n );\n }\n }\n\n /**\n * Clear all cached policies\n */\n clearCache(): void {\n if (!this.config.disableMemoryCache) {\n this.memoryCache.clear();\n }\n this.failures.clear();\n }\n\n /**\n * Check if a date string is expired\n */\n private isExpired(dateString: string): boolean {\n return new Date(dateString).getTime() <= Date.now();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoEA,SAAS,uBAAuB,MAAgD;CAC9E,IAAI,OAAO,SAAS,YAAY,SAAS,MAAM,OAAO;CACtD,MAAM,YAAa,KAAsC;CACzD,OAAO,OAAO,cAAc,YAAY,OAAO,SAAS,SAAS;AACnE;;;;;;;AAQA,SAAS,kBAAkB,MAAwD;CACjF,MAAM,EAAE,cAAc;CACtB,IAAI,CAAC,MAAM,QAAQ,SAAS,GAAG,OAAO;CACtC,OAAO;EACL,GAAG;EACH,WAAW,UAAU,KAAK,UACxB,OAAO,UAAU,WAAW,EAAE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;;;;;;;CAQA,AAAQ,WAAW,SAA0C;EAC3D,IAAI,QAAQ,SAAS,WAAW,MAAM,IAAI,uBAAuB;EACjE,IAAI,CAAC,KAAK,OAAO,oBAAoB,OAAO,KAAK,iBAAiB;EAClE,IAAI,QAAQ,SAAS,QAAQ,MAAM,IAAI,gBAAgB,QAAQ,QAAQ,QAAQ,UAAU;EACzF,MAAM,IAAI,uBAAuB;CACnC;;;;;CAMA,MAAM,gBAAgB,WAAkC;EACtD,MAAM,WAAW,KAAK,YAAY,SAAS;EAC3C,MAAM,UAAU,KAAK,gBAAgB,SAAS;EAC9C,sBAAsB,IAAI,SAAS,GAAG,QAAQ,GAAG,kBAAkB,GAAG;EAGtE,kBAAkB,OAAO,QAAQ;EAGjC,IAAI,KAAK,OAAO,cAAc,QAAQ;GACpC,MAAM,OAAO,aAAa,UAAU,CAAC,OAAO,IAAI,CAAC,UAAU,OAAO;GAClE,MAAM,QAAQ,IACZ,KAAK,IAAI,OAAO,QAAQ;IACtB,IAAI;KACF,MAAM,KAAK,OAAO,aAAc,OAAQ,GAAG;IAC7C,SAAS,OAAO;KACd,QAAQ,MAAM,yDAAyD,KAAK;IAC9E;GACF,CAAC,CACH;EACF;CACF;;;;CAKA,aAAmB;EACjB,IAAI,CAAC,KAAK,OAAO,oBACf,KAAK,YAAY,MAAM;EAEzB,KAAK,SAAS,MAAM;CACtB;;;;CAKA,AAAQ,UAAU,YAA6B;EAC7C,OAAO,IAAI,KAAK,UAAU,CAAC,CAAC,QAAQ,KAAK,KAAK,IAAI;CACpD;AACF"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { n as normalizeChallengeType, t as isEngineEnforcing } from "../engine-enforcing-DiOclGqf.mjs";
|
|
2
|
-
import { A as PolicyMetadataSchema, B as ThresholdConfigSchema, C as InstructPayload, D as PolicyConfig, E as PolicyConditionSchema, F as RuleMetadata, I as RuleMetadataSchema, L as SuggestedAction, M as PolicyRuleSchema, N as RedirectTarget, O as PolicyConfigSchema, P as RedirectTargetSchema, R as SuggestedActionSchema, S as EnforcementModeSchema, T as PolicyCondition, V as safeParsePolicyConfig, _ as DenyListEntry, a as BlockReason, b as EnforcementActionSchema, c as ChallengeParamsSchema, d as ConditionOperator, f as ConditionOperatorSchema, g as DecisionSchema, h as Decision, i as AssuranceTierSchema, j as PolicyRule, k as PolicyMetadata, l as ConditionField, m as ConditionValueSchema, n as AllowListEntrySchema, o as BlockReasonSchema, p as ConditionValue, r as AssuranceTier, s as ChallengeParams, t as AllowListEntry, u as ConditionFieldSchema, v as DenyListEntrySchema, w as InstructPayloadSchema, x as EnforcementMode, y as EnforcementAction, z as ThresholdConfig } from "../schemas-
|
|
2
|
+
import { A as PolicyMetadataSchema, B as ThresholdConfigSchema, C as InstructPayload, D as PolicyConfig, E as PolicyConditionSchema, F as RuleMetadata, I as RuleMetadataSchema, L as SuggestedAction, M as PolicyRuleSchema, N as RedirectTarget, O as PolicyConfigSchema, P as RedirectTargetSchema, R as SuggestedActionSchema, S as EnforcementModeSchema, T as PolicyCondition, V as safeParsePolicyConfig, _ as DenyListEntry, a as BlockReason, b as EnforcementActionSchema, c as ChallengeParamsSchema, d as ConditionOperator, f as ConditionOperatorSchema, g as DecisionSchema, h as Decision, i as AssuranceTierSchema, j as PolicyRule, k as PolicyMetadata, l as ConditionField, m as ConditionValueSchema, n as AllowListEntrySchema, o as BlockReasonSchema, p as ConditionValue, r as AssuranceTier, s as ChallengeParams, t as AllowListEntry, u as ConditionFieldSchema, v as DenyListEntrySchema, w as InstructPayloadSchema, x as EnforcementMode, y as EnforcementAction, z as ThresholdConfig } from "../schemas-BhC88D1-.mjs";
|
|
3
3
|
export { AllowListEntry, AllowListEntrySchema, AssuranceTier, AssuranceTierSchema, BlockReason, BlockReasonSchema, ChallengeParams, ChallengeParamsSchema, ConditionField, ConditionFieldSchema, ConditionOperator, ConditionOperatorSchema, ConditionValue, ConditionValueSchema, Decision, DecisionSchema, DenyListEntry, DenyListEntrySchema, EnforcementAction, EnforcementActionSchema, EnforcementMode, EnforcementModeSchema, InstructPayload, InstructPayloadSchema, PolicyCondition, PolicyConditionSchema, PolicyConfig, PolicyConfigSchema, PolicyMetadata, PolicyMetadataSchema, PolicyRule, PolicyRuleSchema, RedirectTarget, RedirectTargetSchema, RuleMetadata, RuleMetadataSchema, SuggestedAction, SuggestedActionSchema, ThresholdConfig, ThresholdConfigSchema, isEngineEnforcing, normalizeChallengeType, safeParsePolicyConfig };
|
package/dist/policy/schemas.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { n as normalizeChallengeType, t as isEngineEnforcing } from "../engine-enforcing-DiOclGqf.js";
|
|
2
|
-
import { A as PolicyMetadataSchema, B as ThresholdConfigSchema, C as InstructPayload, D as PolicyConfig, E as PolicyConditionSchema, F as RuleMetadata, I as RuleMetadataSchema, L as SuggestedAction, M as PolicyRuleSchema, N as RedirectTarget, O as PolicyConfigSchema, P as RedirectTargetSchema, R as SuggestedActionSchema, S as EnforcementModeSchema, T as PolicyCondition, V as safeParsePolicyConfig, _ as DenyListEntry, a as BlockReason, b as EnforcementActionSchema, c as ChallengeParamsSchema, d as ConditionOperator, f as ConditionOperatorSchema, g as DecisionSchema, h as Decision, i as AssuranceTierSchema, j as PolicyRule, k as PolicyMetadata, l as ConditionField, m as ConditionValueSchema, n as AllowListEntrySchema, o as BlockReasonSchema, p as ConditionValue, r as AssuranceTier, s as ChallengeParams, t as AllowListEntry, u as ConditionFieldSchema, v as DenyListEntrySchema, w as InstructPayloadSchema, x as EnforcementMode, y as EnforcementAction, z as ThresholdConfig } from "../schemas-
|
|
2
|
+
import { A as PolicyMetadataSchema, B as ThresholdConfigSchema, C as InstructPayload, D as PolicyConfig, E as PolicyConditionSchema, F as RuleMetadata, I as RuleMetadataSchema, L as SuggestedAction, M as PolicyRuleSchema, N as RedirectTarget, O as PolicyConfigSchema, P as RedirectTargetSchema, R as SuggestedActionSchema, S as EnforcementModeSchema, T as PolicyCondition, V as safeParsePolicyConfig, _ as DenyListEntry, a as BlockReason, b as EnforcementActionSchema, c as ChallengeParamsSchema, d as ConditionOperator, f as ConditionOperatorSchema, g as DecisionSchema, h as Decision, i as AssuranceTierSchema, j as PolicyRule, k as PolicyMetadata, l as ConditionField, m as ConditionValueSchema, n as AllowListEntrySchema, o as BlockReasonSchema, p as ConditionValue, r as AssuranceTier, s as ChallengeParams, t as AllowListEntry, u as ConditionFieldSchema, v as DenyListEntrySchema, w as InstructPayloadSchema, x as EnforcementMode, y as EnforcementAction, z as ThresholdConfig } from "../schemas-DZa1ouGs.js";
|
|
3
3
|
export { AllowListEntry, AllowListEntrySchema, AssuranceTier, AssuranceTierSchema, BlockReason, BlockReasonSchema, ChallengeParams, ChallengeParamsSchema, ConditionField, ConditionFieldSchema, ConditionOperator, ConditionOperatorSchema, ConditionValue, ConditionValueSchema, Decision, DecisionSchema, DenyListEntry, DenyListEntrySchema, EnforcementAction, EnforcementActionSchema, EnforcementMode, EnforcementModeSchema, InstructPayload, InstructPayloadSchema, PolicyCondition, PolicyConditionSchema, PolicyConfig, PolicyConfigSchema, PolicyMetadata, PolicyMetadataSchema, PolicyRule, PolicyRuleSchema, RedirectTarget, RedirectTargetSchema, RuleMetadata, RuleMetadataSchema, SuggestedAction, SuggestedActionSchema, ThresholdConfig, ThresholdConfigSchema, isEngineEnforcing, normalizeChallengeType, safeParsePolicyConfig };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
//#region src/core/proxy-assertion-mapping.ts
|
|
2
|
+
const knownKinds = /* @__PURE__ */ new Set([
|
|
3
|
+
"tor_exit",
|
|
4
|
+
"published_vpn_exit",
|
|
5
|
+
"observed_proxy",
|
|
6
|
+
"suspected_residential_proxy",
|
|
7
|
+
"privacy_relay",
|
|
8
|
+
"local_tunnel",
|
|
9
|
+
"hosting"
|
|
10
|
+
]);
|
|
11
|
+
function mapProxyAssertions(proxyAssertions, nowSeconds, collectionState, compatibility = "confirmed_current") {
|
|
12
|
+
const states = [collectionState];
|
|
13
|
+
const eligible = [];
|
|
14
|
+
for (const assertion of proxyAssertions) {
|
|
15
|
+
if (!knownKinds.has(assertion.kind)) {
|
|
16
|
+
states.push("unsupported");
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (assertion.kind === "hosting" || assertion.kind === "privacy_relay" || assertion.kind === "local_tunnel") continue;
|
|
20
|
+
states.push(assertion.collectionState);
|
|
21
|
+
if (assertion.collectionState !== "current" && assertion.collectionState !== "insufficient_support") {
|
|
22
|
+
states.push(assertion.collectionState);
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
const dated = assertion.observedAt !== null && assertion.expiresAt !== null;
|
|
26
|
+
const current = dated && assertion.observedAt <= nowSeconds && assertion.expiresAt > nowSeconds;
|
|
27
|
+
if (dated && !current) {
|
|
28
|
+
states.push("stale");
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const confirmed = assertion.evidenceGrade === "confirmed" && assertion.collectionState === "current" && current;
|
|
32
|
+
const legacy = compatibility === "maxmind_legacy" && assertion.source === "maxmind-anonymous-ip" && assertion.evidenceGrade === "vendor_reported" && assertion.collectionState === "insufficient_support" && assertion.observedAt === null && assertion.expiresAt === null;
|
|
33
|
+
if (confirmed || legacy) eligible.push(assertion);
|
|
34
|
+
else states.push("insufficient_support");
|
|
35
|
+
}
|
|
36
|
+
const conflictingKinds = /* @__PURE__ */ new Set();
|
|
37
|
+
for (const assertion of eligible) if (assertion.membership === "present" && eligible.some((other) => other.kind === assertion.kind && other.membership === "absent")) {
|
|
38
|
+
conflictingKinds.add(assertion.kind);
|
|
39
|
+
states.push("conflicting");
|
|
40
|
+
}
|
|
41
|
+
if (proxyAssertions.length === 0) states.push("insufficient_support");
|
|
42
|
+
const diagnosticState = [
|
|
43
|
+
"conflicting",
|
|
44
|
+
"unsupported",
|
|
45
|
+
"unavailable",
|
|
46
|
+
"stale",
|
|
47
|
+
"insufficient_support",
|
|
48
|
+
"current"
|
|
49
|
+
].find((state) => states.includes(state));
|
|
50
|
+
const blocked = collectionState !== "current" && collectionState !== "insufficient_support";
|
|
51
|
+
const positive = eligible.filter((assertion) => assertion.membership === "present" && !conflictingKinds.has(assertion.kind));
|
|
52
|
+
const confirmedPositive = positive.filter((assertion) => assertion.evidenceGrade === "confirmed");
|
|
53
|
+
const candidates = confirmedPositive.length > 0 ? confirmedPositive : positive;
|
|
54
|
+
const preferred = [
|
|
55
|
+
candidates.find((assertion) => assertion.kind === "tor_exit"),
|
|
56
|
+
candidates.find((assertion) => assertion.kind === "published_vpn_exit"),
|
|
57
|
+
candidates.find((assertion) => assertion.kind === "suspected_residential_proxy"),
|
|
58
|
+
candidates.find((assertion) => assertion.kind === "observed_proxy" && assertion.proxyClass === "datacenter"),
|
|
59
|
+
candidates.find((assertion) => assertion.kind === "observed_proxy")
|
|
60
|
+
].find(Boolean);
|
|
61
|
+
const types = {
|
|
62
|
+
tor_exit: "tor",
|
|
63
|
+
published_vpn_exit: "vpn",
|
|
64
|
+
suspected_residential_proxy: "residential_proxy",
|
|
65
|
+
observed_proxy: preferred?.proxyClass === "datacenter" ? "datacenter" : "unknown"
|
|
66
|
+
};
|
|
67
|
+
const proxy = !blocked && preferred ? {
|
|
68
|
+
isProxy: true,
|
|
69
|
+
proxyType: types[preferred.kind],
|
|
70
|
+
confidence: preferred.membershipConfidence ?? (preferred.evidenceGrade === "vendor_reported" ? 90 : 0)
|
|
71
|
+
} : void 0;
|
|
72
|
+
return {
|
|
73
|
+
proxy,
|
|
74
|
+
proxyAssertions,
|
|
75
|
+
proxyCollectionState: proxy && preferred.evidenceGrade === "confirmed" ? "current" : diagnosticState
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
export { mapProxyAssertions as t };
|
|
81
|
+
//# sourceMappingURL=proxy-assertion-mapping-BVwXVSMZ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy-assertion-mapping-BVwXVSMZ.mjs","names":[],"sources":["../src/core/proxy-assertion-mapping.ts"],"sourcesContent":["import type { ProxyAssertion, ProxyCollectionState } from './network-assertions';\n\nconst knownKinds = new Set([\n 'tor_exit',\n 'published_vpn_exit',\n 'observed_proxy',\n 'suspected_residential_proxy',\n 'privacy_relay',\n 'local_tunnel',\n 'hosting',\n]);\n\nexport function mapProxyAssertions(\n proxyAssertions: readonly ProxyAssertion[],\n nowSeconds: number,\n collectionState: ProxyCollectionState,\n compatibility: 'confirmed_current' | 'maxmind_legacy' = 'confirmed_current'\n) {\n const states: ProxyCollectionState[] = [collectionState];\n const eligible: ProxyAssertion[] = [];\n for (const assertion of proxyAssertions) {\n if (!knownKinds.has(assertion.kind)) {\n states.push('unsupported');\n continue;\n }\n if (\n assertion.kind === 'hosting' ||\n assertion.kind === 'privacy_relay' ||\n assertion.kind === 'local_tunnel'\n )\n continue;\n states.push(assertion.collectionState);\n const explicitUnknown =\n assertion.collectionState !== 'current' &&\n assertion.collectionState !== 'insufficient_support';\n if (explicitUnknown) {\n states.push(assertion.collectionState);\n continue;\n }\n const dated = assertion.observedAt !== null && assertion.expiresAt !== null;\n const current =\n dated && assertion.observedAt! <= nowSeconds && assertion.expiresAt! > nowSeconds;\n if (dated && !current) {\n states.push('stale');\n continue;\n }\n const confirmed =\n assertion.evidenceGrade === 'confirmed' && assertion.collectionState === 'current' && current;\n const legacy =\n compatibility === 'maxmind_legacy' &&\n assertion.source === 'maxmind-anonymous-ip' &&\n assertion.evidenceGrade === 'vendor_reported' &&\n assertion.collectionState === 'insufficient_support' &&\n assertion.observedAt === null &&\n assertion.expiresAt === null;\n if (confirmed || legacy) eligible.push(assertion);\n else states.push('insufficient_support');\n }\n\n const conflictingKinds = new Set<string>();\n for (const assertion of eligible) {\n if (\n assertion.membership === 'present' &&\n eligible.some((other) => other.kind === assertion.kind && other.membership === 'absent')\n ) {\n conflictingKinds.add(assertion.kind);\n states.push('conflicting');\n }\n }\n\n if (proxyAssertions.length === 0) states.push('insufficient_support');\n const diagnosticState = (\n [\n 'conflicting',\n 'unsupported',\n 'unavailable',\n 'stale',\n 'insufficient_support',\n 'current',\n ] as const\n ).find((state) => states.includes(state))!;\n const blocked = collectionState !== 'current' && collectionState !== 'insufficient_support';\n const positive = eligible.filter(\n (assertion) => assertion.membership === 'present' && !conflictingKinds.has(assertion.kind)\n );\n const confirmedPositive = positive.filter((assertion) => assertion.evidenceGrade === 'confirmed');\n const candidates = confirmedPositive.length > 0 ? confirmedPositive : positive;\n const preferred = [\n candidates.find((assertion) => assertion.kind === 'tor_exit'),\n candidates.find((assertion) => assertion.kind === 'published_vpn_exit'),\n candidates.find((assertion) => assertion.kind === 'suspected_residential_proxy'),\n candidates.find(\n (assertion) => assertion.kind === 'observed_proxy' && assertion.proxyClass === 'datacenter'\n ),\n candidates.find((assertion) => assertion.kind === 'observed_proxy'),\n ].find(Boolean);\n const types = {\n tor_exit: 'tor',\n published_vpn_exit: 'vpn',\n suspected_residential_proxy: 'residential_proxy',\n observed_proxy: preferred?.proxyClass === 'datacenter' ? 'datacenter' : 'unknown',\n } as const;\n const proxy =\n !blocked && preferred\n ? {\n isProxy: true,\n proxyType: types[preferred.kind as keyof typeof types],\n confidence:\n preferred.membershipConfidence ??\n (preferred.evidenceGrade === 'vendor_reported' ? 90 : 0),\n }\n : undefined;\n const proxyCollectionState =\n proxy && preferred!.evidenceGrade === 'confirmed' ? 'current' : diagnosticState;\n return { proxy, proxyAssertions, proxyCollectionState };\n}\n"],"mappings":";AAEA,MAAM,6BAAa,IAAI,IAAI;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,SAAgB,mBACd,iBACA,YACA,iBACA,gBAAwD,qBACxD;CACA,MAAM,SAAiC,CAAC,eAAe;CACvD,MAAM,WAA6B,CAAC;CACpC,KAAK,MAAM,aAAa,iBAAiB;EACvC,IAAI,CAAC,WAAW,IAAI,UAAU,IAAI,GAAG;GACnC,OAAO,KAAK,aAAa;GACzB;EACF;EACA,IACE,U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AAM,YAAY;EAChB,WAAW,MAAM,cAAc,UAAU,SAAS,UAAU;EAC5D,WAAW,MAAM,cAAc,UAAU,SAAS,oBAAoB;EACtE,WAAW,MAAM,cAAc,UAAU,SAAS,6BAA6B;EAC/E,WAAW,MACR,cAAc,UAAU,SAAS,oBAAoB,UAAU,eAAe,YACjF;EACA,WAAW,MAAM,cAAc,UAAU,SAAS,gBAAgB;CACpE,CAAC,CAAC,KAAK,OAAO;CACd,MAAM,QAAQ;EACZ,UAAU;EACV,oBAAoB;EACpB,6BAA6B;EAC7B,gBAAgB,WAAW,eAAe,eAAe,eAAe;CAC1E;CACA,MAAM,QACJ,CAAC,WAAW,YACR;EACE,SAAS;EACT,WAAW,MAAM,UAAU;EAC3B,YACE,UAAU,yBACT,UAAU,kBAAkB,oBAAoB,KAAK;CAC1D,IACA;CAGN,OAAO;EAAE;EAAO;EAAiB,sBAD/B,SAAS,UAAW,kBAAkB,cAAc,YAAY;CACZ;AACxD"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { A as ZodString, C as ZodNullable, E as ZodOptional, I as output, T as ZodObject, g as ZodEnum, t as external_d_exports, w as ZodNumber, x as ZodLiteral, z as $strict } from "./external-m3Kmafwj.mjs";
|
|
2
|
+
//#region src/core/network-assertions.d.ts
|
|
3
|
+
declare const ProxyCollectionStateSchema: ZodEnum<{
|
|
4
|
+
current: "current";
|
|
5
|
+
unavailable: "unavailable";
|
|
6
|
+
stale: "stale";
|
|
7
|
+
unsupported: "unsupported";
|
|
8
|
+
conflicting: "conflicting";
|
|
9
|
+
insufficient_support: "insufficient_support";
|
|
10
|
+
}>;
|
|
11
|
+
type ProxyCollectionState = output<typeof ProxyCollectionStateSchema>;
|
|
12
|
+
declare const ProxyAssertionSchema: ZodObject<{
|
|
13
|
+
kind: ZodString;
|
|
14
|
+
source: ZodString;
|
|
15
|
+
subjectScope: ZodLiteral<"request_egress">;
|
|
16
|
+
membership: ZodEnum<{
|
|
17
|
+
absent: "absent";
|
|
18
|
+
unknown: "unknown";
|
|
19
|
+
present: "present";
|
|
20
|
+
}>;
|
|
21
|
+
evidenceGrade: ZodEnum<{
|
|
22
|
+
confirmed: "confirmed";
|
|
23
|
+
vendor_reported: "vendor_reported";
|
|
24
|
+
}>;
|
|
25
|
+
collectionState: ZodEnum<{
|
|
26
|
+
current: "current";
|
|
27
|
+
unavailable: "unavailable";
|
|
28
|
+
stale: "stale";
|
|
29
|
+
unsupported: "unsupported";
|
|
30
|
+
conflicting: "conflicting";
|
|
31
|
+
insufficient_support: "insufficient_support";
|
|
32
|
+
}>;
|
|
33
|
+
observedAt: ZodNullable<ZodNumber>;
|
|
34
|
+
expiresAt: ZodNullable<ZodNumber>;
|
|
35
|
+
membershipConfidence: ZodNullable<ZodNumber>;
|
|
36
|
+
sourceReliability: ZodNullable<ZodNumber>;
|
|
37
|
+
fraudProbability: ZodNullable<ZodNumber>;
|
|
38
|
+
proxyClass: ZodOptional<ZodEnum<{
|
|
39
|
+
unknown: "unknown";
|
|
40
|
+
datacenter: "datacenter";
|
|
41
|
+
}>>;
|
|
42
|
+
}, $strict>;
|
|
43
|
+
type ProxyAssertion = output<typeof ProxyAssertionSchema>;
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/core/proxy-assertion-mapping.d.ts
|
|
46
|
+
declare function mapProxyAssertions(proxyAssertions: readonly ProxyAssertion[], nowSeconds: number, collectionState: ProxyCollectionState, compatibility?: 'confirmed_current' | 'maxmind_legacy'): {
|
|
47
|
+
proxy: {
|
|
48
|
+
isProxy: boolean;
|
|
49
|
+
proxyType: "unknown" | "datacenter" | "tor" | "vpn" | "residential_proxy";
|
|
50
|
+
confidence: number;
|
|
51
|
+
} | undefined;
|
|
52
|
+
proxyAssertions: readonly {
|
|
53
|
+
kind: string;
|
|
54
|
+
source: string;
|
|
55
|
+
subjectScope: "request_egress";
|
|
56
|
+
membership: "absent" | "unknown" | "present";
|
|
57
|
+
evidenceGrade: "confirmed" | "vendor_reported";
|
|
58
|
+
collectionState: "current" | "unavailable" | "stale" | "unsupported" | "conflicting" | "insufficient_support";
|
|
59
|
+
observedAt: number | null;
|
|
60
|
+
expiresAt: number | null;
|
|
61
|
+
membershipConfidence: number | null;
|
|
62
|
+
sourceReliability: number | null;
|
|
63
|
+
fraudProbability: number | null;
|
|
64
|
+
proxyClass?: "unknown" | "datacenter" | undefined;
|
|
65
|
+
}[];
|
|
66
|
+
proxyCollectionState: "current" | "unavailable" | "stale" | "unsupported" | "conflicting" | "insufficient_support";
|
|
67
|
+
};
|
|
68
|
+
//#endregion
|
|
69
|
+
export { ProxyCollectionStateSchema as a, ProxyCollectionState as i, ProxyAssertion as n, ProxyAssertionSchema as r, mapProxyAssertions as t };
|
|
70
|
+
//# sourceMappingURL=proxy-assertion-mapping-BxhENrcY.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy-assertion-mapping-BxhENrcY.d.mts","names":[],"sources":["../src/core/network-assertions.ts","../src/core/proxy-assertion-mapping.ts"],"mappings":";;cAEa,4BAA0B;;;;;;;;KAQ3B,uBAAuB,cAAe;cAMrC,sBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiBtB;KACC,iBAAiB,cAAe;;;iBCtB5B,mBACd,0BAA0B,kBAC1B,oBACA,iBAAiB,sBACjB"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
//#region src/core/proxy-assertion-mapping.ts
|
|
2
|
+
const knownKinds = /* @__PURE__ */ new Set([
|
|
3
|
+
"tor_exit",
|
|
4
|
+
"published_vpn_exit",
|
|
5
|
+
"observed_proxy",
|
|
6
|
+
"suspected_residential_proxy",
|
|
7
|
+
"privacy_relay",
|
|
8
|
+
"local_tunnel",
|
|
9
|
+
"hosting"
|
|
10
|
+
]);
|
|
11
|
+
function mapProxyAssertions(proxyAssertions, nowSeconds, collectionState, compatibility = "confirmed_current") {
|
|
12
|
+
const states = [collectionState];
|
|
13
|
+
const eligible = [];
|
|
14
|
+
for (const assertion of proxyAssertions) {
|
|
15
|
+
if (!knownKinds.has(assertion.kind)) {
|
|
16
|
+
states.push("unsupported");
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (assertion.kind === "hosting" || assertion.kind === "privacy_relay" || assertion.kind === "local_tunnel") continue;
|
|
20
|
+
states.push(assertion.collectionState);
|
|
21
|
+
if (assertion.collectionState !== "current" && assertion.collectionState !== "insufficient_support") {
|
|
22
|
+
states.push(assertion.collectionState);
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
const dated = assertion.observedAt !== null && assertion.expiresAt !== null;
|
|
26
|
+
const current = dated && assertion.observedAt <= nowSeconds && assertion.expiresAt > nowSeconds;
|
|
27
|
+
if (dated && !current) {
|
|
28
|
+
states.push("stale");
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const confirmed = assertion.evidenceGrade === "confirmed" && assertion.collectionState === "current" && current;
|
|
32
|
+
const legacy = compatibility === "maxmind_legacy" && assertion.source === "maxmind-anonymous-ip" && assertion.evidenceGrade === "vendor_reported" && assertion.collectionState === "insufficient_support" && assertion.observedAt === null && assertion.expiresAt === null;
|
|
33
|
+
if (confirmed || legacy) eligible.push(assertion);
|
|
34
|
+
else states.push("insufficient_support");
|
|
35
|
+
}
|
|
36
|
+
const conflictingKinds = /* @__PURE__ */ new Set();
|
|
37
|
+
for (const assertion of eligible) if (assertion.membership === "present" && eligible.some((other) => other.kind === assertion.kind && other.membership === "absent")) {
|
|
38
|
+
conflictingKinds.add(assertion.kind);
|
|
39
|
+
states.push("conflicting");
|
|
40
|
+
}
|
|
41
|
+
if (proxyAssertions.length === 0) states.push("insufficient_support");
|
|
42
|
+
const diagnosticState = [
|
|
43
|
+
"conflicting",
|
|
44
|
+
"unsupported",
|
|
45
|
+
"unavailable",
|
|
46
|
+
"stale",
|
|
47
|
+
"insufficient_support",
|
|
48
|
+
"current"
|
|
49
|
+
].find((state) => states.includes(state));
|
|
50
|
+
const blocked = collectionState !== "current" && collectionState !== "insufficient_support";
|
|
51
|
+
const positive = eligible.filter((assertion) => assertion.membership === "present" && !conflictingKinds.has(assertion.kind));
|
|
52
|
+
const confirmedPositive = positive.filter((assertion) => assertion.evidenceGrade === "confirmed");
|
|
53
|
+
const candidates = confirmedPositive.length > 0 ? confirmedPositive : positive;
|
|
54
|
+
const preferred = [
|
|
55
|
+
candidates.find((assertion) => assertion.kind === "tor_exit"),
|
|
56
|
+
candidates.find((assertion) => assertion.kind === "published_vpn_exit"),
|
|
57
|
+
candidates.find((assertion) => assertion.kind === "suspected_residential_proxy"),
|
|
58
|
+
candidates.find((assertion) => assertion.kind === "observed_proxy" && assertion.proxyClass === "datacenter"),
|
|
59
|
+
candidates.find((assertion) => assertion.kind === "observed_proxy")
|
|
60
|
+
].find(Boolean);
|
|
61
|
+
const types = {
|
|
62
|
+
tor_exit: "tor",
|
|
63
|
+
published_vpn_exit: "vpn",
|
|
64
|
+
suspected_residential_proxy: "residential_proxy",
|
|
65
|
+
observed_proxy: preferred?.proxyClass === "datacenter" ? "datacenter" : "unknown"
|
|
66
|
+
};
|
|
67
|
+
const proxy = !blocked && preferred ? {
|
|
68
|
+
isProxy: true,
|
|
69
|
+
proxyType: types[preferred.kind],
|
|
70
|
+
confidence: preferred.membershipConfidence ?? (preferred.evidenceGrade === "vendor_reported" ? 90 : 0)
|
|
71
|
+
} : void 0;
|
|
72
|
+
return {
|
|
73
|
+
proxy,
|
|
74
|
+
proxyAssertions,
|
|
75
|
+
proxyCollectionState: proxy && preferred.evidenceGrade === "confirmed" ? "current" : diagnosticState
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
Object.defineProperty(exports, 'mapProxyAssertions', {
|
|
81
|
+
enumerable: true,
|
|
82
|
+
get: function () {
|
|
83
|
+
return mapProxyAssertions;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { A as ZodString, C as ZodNullable, E as ZodOptional, I as output, T as ZodObject, g as ZodEnum, t as external_d_exports, w as ZodNumber, x as ZodLiteral, z as $strict } from "./external-m3Kmafwj.js";
|
|
2
|
+
//#region src/core/network-assertions.d.ts
|
|
3
|
+
declare const ProxyCollectionStateSchema: ZodEnum<{
|
|
4
|
+
current: "current";
|
|
5
|
+
unavailable: "unavailable";
|
|
6
|
+
stale: "stale";
|
|
7
|
+
unsupported: "unsupported";
|
|
8
|
+
conflicting: "conflicting";
|
|
9
|
+
insufficient_support: "insufficient_support";
|
|
10
|
+
}>;
|
|
11
|
+
type ProxyCollectionState = output<typeof ProxyCollectionStateSchema>;
|
|
12
|
+
declare const ProxyAssertionSchema: ZodObject<{
|
|
13
|
+
kind: ZodString;
|
|
14
|
+
source: ZodString;
|
|
15
|
+
subjectScope: ZodLiteral<"request_egress">;
|
|
16
|
+
membership: ZodEnum<{
|
|
17
|
+
absent: "absent";
|
|
18
|
+
unknown: "unknown";
|
|
19
|
+
present: "present";
|
|
20
|
+
}>;
|
|
21
|
+
evidenceGrade: ZodEnum<{
|
|
22
|
+
confirmed: "confirmed";
|
|
23
|
+
vendor_reported: "vendor_reported";
|
|
24
|
+
}>;
|
|
25
|
+
collectionState: ZodEnum<{
|
|
26
|
+
current: "current";
|
|
27
|
+
unavailable: "unavailable";
|
|
28
|
+
stale: "stale";
|
|
29
|
+
unsupported: "unsupported";
|
|
30
|
+
conflicting: "conflicting";
|
|
31
|
+
insufficient_support: "insufficient_support";
|
|
32
|
+
}>;
|
|
33
|
+
observedAt: ZodNullable<ZodNumber>;
|
|
34
|
+
expiresAt: ZodNullable<ZodNumber>;
|
|
35
|
+
membershipConfidence: ZodNullable<ZodNumber>;
|
|
36
|
+
sourceReliability: ZodNullable<ZodNumber>;
|
|
37
|
+
fraudProbability: ZodNullable<ZodNumber>;
|
|
38
|
+
proxyClass: ZodOptional<ZodEnum<{
|
|
39
|
+
unknown: "unknown";
|
|
40
|
+
datacenter: "datacenter";
|
|
41
|
+
}>>;
|
|
42
|
+
}, $strict>;
|
|
43
|
+
type ProxyAssertion = output<typeof ProxyAssertionSchema>;
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/core/proxy-assertion-mapping.d.ts
|
|
46
|
+
declare function mapProxyAssertions(proxyAssertions: readonly ProxyAssertion[], nowSeconds: number, collectionState: ProxyCollectionState, compatibility?: 'confirmed_current' | 'maxmind_legacy'): {
|
|
47
|
+
proxy: {
|
|
48
|
+
isProxy: boolean;
|
|
49
|
+
proxyType: "unknown" | "datacenter" | "tor" | "vpn" | "residential_proxy";
|
|
50
|
+
confidence: number;
|
|
51
|
+
} | undefined;
|
|
52
|
+
proxyAssertions: readonly {
|
|
53
|
+
kind: string;
|
|
54
|
+
source: string;
|
|
55
|
+
subjectScope: "request_egress";
|
|
56
|
+
membership: "absent" | "unknown" | "present";
|
|
57
|
+
evidenceGrade: "confirmed" | "vendor_reported";
|
|
58
|
+
collectionState: "current" | "unavailable" | "stale" | "unsupported" | "conflicting" | "insufficient_support";
|
|
59
|
+
observedAt: number | null;
|
|
60
|
+
expiresAt: number | null;
|
|
61
|
+
membershipConfidence: number | null;
|
|
62
|
+
sourceReliability: number | null;
|
|
63
|
+
fraudProbability: number | null;
|
|
64
|
+
proxyClass?: "unknown" | "datacenter" | undefined;
|
|
65
|
+
}[];
|
|
66
|
+
proxyCollectionState: "current" | "unavailable" | "stale" | "unsupported" | "conflicting" | "insufficient_support";
|
|
67
|
+
};
|
|
68
|
+
//#endregion
|
|
69
|
+
export { ProxyCollectionStateSchema as a, ProxyCollectionState as i, ProxyAssertion as n, ProxyAssertionSchema as r, mapProxyAssertions as t };
|
|
70
|
+
//# sourceMappingURL=proxy-assertion-mapping-DhAynFqG.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy-assertion-mapping-DhAynFqG.d.ts","names":[],"sources":["../src/core/network-assertions.ts","../src/core/proxy-assertion-mapping.ts"],"mappings":";;cAEa,4BAA0B;;;;;;;;KAQ3B,uBAAuB,cAAe;cAMrC,sBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiBtB;KACC,iBAAiB,cAAe;;;iBCtB5B,mBACd,0BAA0B,kBAC1B,oBACA,iBAAiB,sBACjB"}
|
package/dist/reason-codes.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as mapDetectionToReasonCodes, i as formatReasonCodesHeader, n as MAX_REASON_CODES_ON_WIRE, o as
|
|
2
|
-
export { DETECTION_REASON_CODES, DetectionReasonCode, MAX_REASON_CODES_HEADER_BYTES, MAX_REASON_CODES_ON_WIRE, ReasonCodeDetectionFacts, formatReasonCodesHeader, mapDetectionToReasonCodes };
|
|
1
|
+
import { a as mapDetectionToReasonCodes, c as DetectionReasonCode, i as formatReasonCodesHeader, n as MAX_REASON_CODES_ON_WIRE, o as reasonCodeForSignalSource, r as ReasonCodeDetectionFacts, s as DETECTION_REASON_CODES, t as MAX_REASON_CODES_HEADER_BYTES } from "./detection-reason-mapping-BemDaDED.mjs";
|
|
2
|
+
export { DETECTION_REASON_CODES, DetectionReasonCode, MAX_REASON_CODES_HEADER_BYTES, MAX_REASON_CODES_ON_WIRE, ReasonCodeDetectionFacts, formatReasonCodesHeader, mapDetectionToReasonCodes, reasonCodeForSignalSource };
|
package/dist/reason-codes.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as mapDetectionToReasonCodes, i as formatReasonCodesHeader, n as MAX_REASON_CODES_ON_WIRE, o as
|
|
2
|
-
export { DETECTION_REASON_CODES, DetectionReasonCode, MAX_REASON_CODES_HEADER_BYTES, MAX_REASON_CODES_ON_WIRE, ReasonCodeDetectionFacts, formatReasonCodesHeader, mapDetectionToReasonCodes };
|
|
1
|
+
import { a as mapDetectionToReasonCodes, c as DetectionReasonCode, i as formatReasonCodesHeader, n as MAX_REASON_CODES_ON_WIRE, o as reasonCodeForSignalSource, r as ReasonCodeDetectionFacts, s as DETECTION_REASON_CODES, t as MAX_REASON_CODES_HEADER_BYTES } from "./detection-reason-mapping-BemDaDED.js";
|
|
2
|
+
export { DETECTION_REASON_CODES, DetectionReasonCode, MAX_REASON_CODES_HEADER_BYTES, MAX_REASON_CODES_ON_WIRE, ReasonCodeDetectionFacts, formatReasonCodesHeader, mapDetectionToReasonCodes, reasonCodeForSignalSource };
|
package/dist/reason-codes.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_detection_reason_mapping = require('./detection-reason-mapping-
|
|
2
|
+
const require_detection_reason_mapping = require('./detection-reason-mapping-BxYaQ8kb.js');
|
|
3
3
|
|
|
4
4
|
exports.DETECTION_REASON_CODES = require_detection_reason_mapping.DETECTION_REASON_CODES;
|
|
5
5
|
exports.MAX_REASON_CODES_HEADER_BYTES = require_detection_reason_mapping.MAX_REASON_CODES_HEADER_BYTES;
|
|
6
6
|
exports.MAX_REASON_CODES_ON_WIRE = require_detection_reason_mapping.MAX_REASON_CODES_ON_WIRE;
|
|
7
7
|
exports.formatReasonCodesHeader = require_detection_reason_mapping.formatReasonCodesHeader;
|
|
8
|
-
exports.mapDetectionToReasonCodes = require_detection_reason_mapping.mapDetectionToReasonCodes;
|
|
8
|
+
exports.mapDetectionToReasonCodes = require_detection_reason_mapping.mapDetectionToReasonCodes;
|
|
9
|
+
exports.reasonCodeForSignalSource = require_detection_reason_mapping.reasonCodeForSignalSource;
|
package/dist/reason-codes.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as reasonCodeForSignalSource, i as mapDetectionToReasonCodes, n as MAX_REASON_CODES_ON_WIRE, o as DETECTION_REASON_CODES, r as formatReasonCodesHeader, t as MAX_REASON_CODES_HEADER_BYTES } from "./detection-reason-mapping-j-7bXsVb.mjs";
|
|
2
2
|
|
|
3
|
-
export { DETECTION_REASON_CODES, MAX_REASON_CODES_HEADER_BYTES, MAX_REASON_CODES_ON_WIRE, formatReasonCodesHeader, mapDetectionToReasonCodes };
|
|
3
|
+
export { DETECTION_REASON_CODES, MAX_REASON_CODES_HEADER_BYTES, MAX_REASON_CODES_ON_WIRE, formatReasonCodesHeader, mapDetectionToReasonCodes, reasonCodeForSignalSource };
|
|
@@ -21,6 +21,28 @@ declare function getVerificationRiskLevel(method: VerificationMethod, confidence
|
|
|
21
21
|
declare const DELEGATION_PROOF_HEADERS: readonly ["kya-os-delegation-credential", "kya-delegation"];
|
|
22
22
|
declare function requestCarriesDelegationProof(headers: Headers | Record<string, unknown> | null | undefined): boolean;
|
|
23
23
|
declare function requestPresentedCredential(headers: Headers | Record<string, unknown> | null | undefined): boolean;
|
|
24
|
+
declare function requestPresentsKyaSignature(headers: Headers | Record<string, unknown> | null | undefined): boolean;
|
|
25
|
+
declare function requestDeclaresBody(headers: Headers | Record<string, unknown> | null | undefined): boolean;
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/mcpi/signed-body.d.ts
|
|
28
|
+
declare const KYA_SIGNED_BODY_MAX_BYTES = 1048576;
|
|
29
|
+
type BoundedBody = {
|
|
30
|
+
bytes: Uint8Array;
|
|
31
|
+
} | {
|
|
32
|
+
failure: 'too-large' | 'unreadable';
|
|
33
|
+
};
|
|
34
|
+
type DeadlineBoundedBody = BoundedBody | {
|
|
35
|
+
failure: 'timed-out';
|
|
36
|
+
bytesRead: number;
|
|
37
|
+
};
|
|
38
|
+
interface BodyReadOptions {
|
|
39
|
+
deadlineMs: number;
|
|
40
|
+
}
|
|
41
|
+
declare function readBodyBounded(request: Request, maxBytes: number): Promise<BoundedBody>;
|
|
42
|
+
declare function readBodyBounded(request: Request, maxBytes: number, options: BodyReadOptions): Promise<DeadlineBoundedBody>;
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/mcpi/relayed-request-target.d.ts
|
|
45
|
+
declare function relayedRequestTarget(url: unknown, path: unknown): string;
|
|
24
46
|
//#endregion
|
|
25
47
|
//#region src/mcpi/anonymous-principal.d.ts
|
|
26
48
|
declare const ANONYMOUS_PRINCIPAL_DID = "did:web:kya.vouched.id:principals:anonymous";
|
|
@@ -29,5 +51,5 @@ declare const ANONYMOUS_PRINCIPAL_DID = "did:web:kya.vouched.id:principals:anony
|
|
|
29
51
|
declare const REGISTERED_SID_MAX_LENGTH = 100;
|
|
30
52
|
declare const SID_ATTRIBUTABLE_RESULT: "verified";
|
|
31
53
|
//#endregion
|
|
32
|
-
export { normalizeWireMethod as _,
|
|
33
|
-
//# sourceMappingURL=registered-sid-
|
|
54
|
+
export { isKyaOsWireMethod as C, isKyaOsHandshakeMethod as S, normalizeWireMethod as T, VerificationMethod as _, BodyReadOptions as a, getVerificationRiskLevel as b, KYA_SIGNED_BODY_MAX_BYTES as c, requestCarriesDelegationProof as d, requestDeclaresBody as f, KYA_OS_WIRE_METHODS as g, KYA_OS_HANDSHAKE_METHODS as h, relayedRequestTarget as i, readBodyBounded as l, requestPresentsKyaSignature as m, SID_ATTRIBUTABLE_RESULT as n, BoundedBody as o, requestPresentedCredential as p, ANONYMOUS_PRINCIPAL_DID as r, DeadlineBoundedBody as s, REGISTERED_SID_MAX_LENGTH as t, DELEGATION_PROOF_HEADERS as u, getVerificationMethodDescription as v, normalizeHandshakeMethod as w, isHighConfidenceVerification as x, getVerificationReliability as y };
|
|
55
|
+
//# sourceMappingURL=registered-sid-BgDhdj2l.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registered-sid-BgDhdj2l.d.mts","names":[],"sources":["../src/utils/verification.ts","../src/mcpi/delegation-headers.ts","../src/mcpi/signed-body.ts","../src/mcpi/relayed-request-target.ts","../src/mcpi/anonymous-principal.ts","../src/mcpi/registered-sid.ts"],"mappings":";KAIY;cA8BC;WAAA;WAAA;;cAOA;WAAA;WAAA;;iBAQG,uBAAuB;iBAKvB,kBAAkB;iBAsBlB,yBAAyB,qCACvC,OAAO,IACN,WAAW,yBAAyB;iBAavB,oBAAoB,qCAClC,OAAO,IACN,WAAW,oBAAoB;iBAOlB,iCAAiC,QAAQ;iBA2BzC,2BAA2B,QAAQ;iBAwBnC,6BAA6B,QAAQ;iBAQrC,yBACd,QAAQ,oBACR;;;cC9IW;iBAgBG,8BACd,SAAS,UAAU;iBA4FL,2BACd,SAAS,UAAU;iBAeL,4BACd,SAAS,UAAU;iBAmBL,oBACd,SAAS,UAAU;;;cCxJR;KAGD;EAAgB,OAAO;;EAAiB;;KAExC,sBAAsB;EAAgB;EAAsB;;UAEvD;EACf;;iBAuBc,gBAAgB,SAAS,SAAS,mBAAmB,QAAQ;iBAC7D,gBACd,SAAS,SACT,kBACA,SAAS,kBACR,QAAQ;;;iBC1BK,qBAAqB,cAAc;;;cClBtC;;;cCUA;cAUA"}
|
|
@@ -21,6 +21,28 @@ declare function getVerificationRiskLevel(method: VerificationMethod, confidence
|
|
|
21
21
|
declare const DELEGATION_PROOF_HEADERS: readonly ["kya-os-delegation-credential", "kya-delegation"];
|
|
22
22
|
declare function requestCarriesDelegationProof(headers: Headers | Record<string, unknown> | null | undefined): boolean;
|
|
23
23
|
declare function requestPresentedCredential(headers: Headers | Record<string, unknown> | null | undefined): boolean;
|
|
24
|
+
declare function requestPresentsKyaSignature(headers: Headers | Record<string, unknown> | null | undefined): boolean;
|
|
25
|
+
declare function requestDeclaresBody(headers: Headers | Record<string, unknown> | null | undefined): boolean;
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/mcpi/signed-body.d.ts
|
|
28
|
+
declare const KYA_SIGNED_BODY_MAX_BYTES = 1048576;
|
|
29
|
+
type BoundedBody = {
|
|
30
|
+
bytes: Uint8Array;
|
|
31
|
+
} | {
|
|
32
|
+
failure: 'too-large' | 'unreadable';
|
|
33
|
+
};
|
|
34
|
+
type DeadlineBoundedBody = BoundedBody | {
|
|
35
|
+
failure: 'timed-out';
|
|
36
|
+
bytesRead: number;
|
|
37
|
+
};
|
|
38
|
+
interface BodyReadOptions {
|
|
39
|
+
deadlineMs: number;
|
|
40
|
+
}
|
|
41
|
+
declare function readBodyBounded(request: Request, maxBytes: number): Promise<BoundedBody>;
|
|
42
|
+
declare function readBodyBounded(request: Request, maxBytes: number, options: BodyReadOptions): Promise<DeadlineBoundedBody>;
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/mcpi/relayed-request-target.d.ts
|
|
45
|
+
declare function relayedRequestTarget(url: unknown, path: unknown): string;
|
|
24
46
|
//#endregion
|
|
25
47
|
//#region src/mcpi/anonymous-principal.d.ts
|
|
26
48
|
declare const ANONYMOUS_PRINCIPAL_DID = "did:web:kya.vouched.id:principals:anonymous";
|
|
@@ -29,5 +51,5 @@ declare const ANONYMOUS_PRINCIPAL_DID = "did:web:kya.vouched.id:principals:anony
|
|
|
29
51
|
declare const REGISTERED_SID_MAX_LENGTH = 100;
|
|
30
52
|
declare const SID_ATTRIBUTABLE_RESULT: "verified";
|
|
31
53
|
//#endregion
|
|
32
|
-
export { normalizeWireMethod as _,
|
|
33
|
-
//# sourceMappingURL=registered-sid-
|
|
54
|
+
export { isKyaOsWireMethod as C, isKyaOsHandshakeMethod as S, normalizeWireMethod as T, VerificationMethod as _, BodyReadOptions as a, getVerificationRiskLevel as b, KYA_SIGNED_BODY_MAX_BYTES as c, requestCarriesDelegationProof as d, requestDeclaresBody as f, KYA_OS_WIRE_METHODS as g, KYA_OS_HANDSHAKE_METHODS as h, relayedRequestTarget as i, readBodyBounded as l, requestPresentsKyaSignature as m, SID_ATTRIBUTABLE_RESULT as n, BoundedBody as o, requestPresentedCredential as p, ANONYMOUS_PRINCIPAL_DID as r, DeadlineBoundedBody as s, REGISTERED_SID_MAX_LENGTH as t, DELEGATION_PROOF_HEADERS as u, getVerificationMethodDescription as v, normalizeHandshakeMethod as w, isHighConfidenceVerification as x, getVerificationReliability as y };
|
|
55
|
+
//# sourceMappingURL=registered-sid-BgDhdj2l.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registered-sid-BgDhdj2l.d.ts","names":[],"sources":["../src/utils/verification.ts","../src/mcpi/delegation-headers.ts","../src/mcpi/signed-body.ts","../src/mcpi/relayed-request-target.ts","../src/mcpi/anonymous-principal.ts","../src/mcpi/registered-sid.ts"],"mappings":";KAIY;cA8BC;WAAA;WAAA;;cAOA;WAAA;WAAA;;iBAQG,uBAAuB;iBAKvB,kBAAkB;iBAsBlB,yBAAyB,qCACvC,OAAO,IACN,WAAW,yBAAyB;iBAavB,oBAAoB,qCAClC,OAAO,IACN,WAAW,oBAAoB;iBAOlB,iCAAiC,QAAQ;iBA2BzC,2BAA2B,QAAQ;iBAwBnC,6BAA6B,QAAQ;iBAQrC,yBACd,QAAQ,oBACR;;;cC9IW;iBAgBG,8BACd,SAAS,UAAU;iBA4FL,2BACd,SAAS,UAAU;iBAeL,4BACd,SAAS,UAAU;iBAmBL,oBACd,SAAS,UAAU;;;cCxJR;KAGD;EAAgB,OAAO;;EAAiB;;KAExC,sBAAsB;EAAgB;EAAsB;;UAEvD;EACf;;iBAuBc,gBAAgB,SAAS,SAAS,mBAAmB,QAAQ;iBAC7D,gBACd,SAAS,SACT,kBACA,SAAS,kBACR,QAAQ;;;iBC1BK,qBAAqB,cAAc;;;cClBtC;;;cCUA;cAUA"}
|