@kya-os/checkpoint-shared 1.3.0 → 1.3.1

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.
Files changed (52) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/beacon-types/index.d.mts +3 -1
  3. package/dist/beacon-types/index.d.ts +3 -1
  4. package/dist/beacon-types/index.js +15 -2
  5. package/dist/beacon-types/index.mjs +15 -2
  6. package/dist/browser-posture-report.d.mts +85 -0
  7. package/dist/browser-posture-report.d.ts +85 -0
  8. package/dist/browser-posture-report.js +1 -0
  9. package/dist/browser-posture-report.mjs +1 -0
  10. package/dist/browser-posture.d.mts +114 -0
  11. package/dist/browser-posture.d.ts +114 -0
  12. package/dist/browser-posture.js +4204 -0
  13. package/dist/browser-posture.mjs +4187 -0
  14. package/dist/browser.d.mts +30 -1
  15. package/dist/browser.d.ts +30 -1
  16. package/dist/browser.js +1 -1
  17. package/dist/browser.mjs +1 -1
  18. package/dist/errors/index.d.mts +104 -0
  19. package/dist/errors/index.d.ts +104 -0
  20. package/dist/errors/index.js +338 -0
  21. package/dist/errors/index.mjs +333 -0
  22. package/dist/gateway/index.d.mts +6 -1
  23. package/dist/gateway/index.d.ts +6 -1
  24. package/dist/gateway/index.js +4 -0
  25. package/dist/gateway/index.mjs +4 -1
  26. package/dist/index.d.mts +769 -146
  27. package/dist/index.d.ts +769 -146
  28. package/dist/index.js +926 -282
  29. package/dist/index.mjs +903 -283
  30. package/dist/signals/index.d.mts +1 -1
  31. package/dist/signals/index.d.ts +1 -1
  32. package/dist/signals/index.js +95 -2
  33. package/dist/signals/index.mjs +95 -2
  34. package/fixtures/client-ip-resolution.json +103 -0
  35. package/fixtures/detection/reason-codes.json +35 -0
  36. package/fixtures/detection/signal-exposure-example.json +62 -0
  37. package/fixtures/kya-http/README.md +112 -0
  38. package/fixtures/kya-http/challenge-proof.canonical.json +25 -0
  39. package/fixtures/kya-http/challenge.approval-quorum.json +37 -0
  40. package/fixtures/kya-http/challenge.delegation.fetcher-200.json +55 -0
  41. package/fixtures/kya-http/challenge.delegation.full.json +81 -0
  42. package/fixtures/kya-http/challenge.delegation.minimal.json +57 -0
  43. package/fixtures/kya-http/error-codes.json +35 -0
  44. package/fixtures/kya-http/fetcher-200-predicate.vectors.json +72 -0
  45. package/fixtures/kya-http/negative.challenges.json +54 -0
  46. package/fixtures/kya-http/pickup.transcript.json +96 -0
  47. package/fixtures/kya-http/pickup.transcript.quorum.json +156 -0
  48. package/fixtures/kya-http/protected-resource-metadata.full.json +30 -0
  49. package/fixtures/kya-http/protected-resource-metadata.global.json +28 -0
  50. package/fixtures/kya-http/registration.request.json +33 -0
  51. package/fixtures/kya-http/registration.response.json +32 -0
  52. package/package.json +20 -2
@@ -1,3 +1,32 @@
1
+ type ClientIpSource = 'explicit' | 'cf-connecting-ip' | 'x-vercel-forwarded-for' | 'x-forwarded-for' | 'x-real-ip' | 'framework' | 'socket' | 'none';
2
+ interface ClientIpResolution {
3
+ ip: string | null;
4
+ source: ClientIpSource;
5
+ trusted: boolean;
6
+ }
7
+ type ClientIpTrustPolicy = {
8
+ platform: 'vercel';
9
+ } | {
10
+ platform: 'cloudflare';
11
+ } | {
12
+ platform: 'trusted-proxy';
13
+ trustedHops: number;
14
+ } | {
15
+ platform: 'direct';
16
+ };
17
+ type ClientIpHeaderValue = string | readonly string[] | undefined;
18
+ type ClientIpHeaders = Headers | Record<string, ClientIpHeaderValue>;
19
+ interface ResolveClientIpInput {
20
+ headers: ClientIpHeaders;
21
+ directAddress?: string | null;
22
+ frameworkAddress?: string | null;
23
+ explicitAddress?: string | null;
24
+ explicitAddressTrusted?: boolean;
25
+ policy: ClientIpTrustPolicy;
26
+ }
27
+ declare function normalizeClientIp(raw: string | null | undefined): string | null;
28
+ declare function resolveClientIp(input: ResolveClientIpInput): ClientIpResolution;
29
+
1
30
  interface BrowserDetectionResult {
2
31
  category: AgentCategory;
3
32
  confidence: ConfidenceLevel;
@@ -321,4 +350,4 @@ declare const RULE_CACHE: {
321
350
  readonly TIMESTAMP_KEY: "agentshield_rules_timestamp";
322
351
  };
323
352
 
324
- export { type AgentCategory, type AgentInfo, type BatchEvent, type BeaconBatch, type BeaconCollectorData, type BeaconConfig, type BeaconEvent, type BeaconEventType, type BeaconIdentity, type BeaconMetadata, type BeaconWorkerMessage, type BeaconWorkerMessageType, type BrowserDetectionResult, type CircuitBreakerConfig, type CircuitBreakerState, type ConfidenceLevel, type ConnectionType, DEFAULT_CONFIG, type BrowserDetectionResult as DetectionResult, ERROR_TYPES, type FallbackOptions, Guards, type MessagePriority, type NetworkInfo, type OfflineQueueEntry, type ProtocolVersion, RULE_CACHE, type ResourceUsage, type RetryStrategy, type TransportConfig, type TransportMetrics, type TransportOptions, type TransportResponse, type TransportState, type WorkerAction, type WorkerCapabilities, type WorkerConfig, type WorkerError, type WorkerErrorType, type WorkerHealthStatus, type WorkerMessage, type WorkerMessageType, type WorkerMetrics, type WorkerPoolConfig, type WorkerState, type WorkerTask, parseBeaconConfig, parseBeaconWorkerMessage, parseCircuitBreakerConfig, parseFallbackOptions, parseOfflineQueueEntry, parseResourceUsage, parseRetryStrategy, parseWorkerCapabilities, parseWorkerConfig, parseWorkerError, parseWorkerMessage, parseWorkerPoolConfig, parseWorkerTask, validateBeaconBatch, validateBeaconConfig, validateBeaconEvent };
353
+ export { type AgentCategory, type AgentInfo, type BatchEvent, type BeaconBatch, type BeaconCollectorData, type BeaconConfig, type BeaconEvent, type BeaconEventType, type BeaconIdentity, type BeaconMetadata, type BeaconWorkerMessage, type BeaconWorkerMessageType, type BrowserDetectionResult, type CircuitBreakerConfig, type CircuitBreakerState, type ClientIpHeaderValue, type ClientIpHeaders, type ClientIpResolution, type ClientIpSource, type ClientIpTrustPolicy, type ConfidenceLevel, type ConnectionType, DEFAULT_CONFIG, type BrowserDetectionResult as DetectionResult, ERROR_TYPES, type FallbackOptions, Guards, type MessagePriority, type NetworkInfo, type OfflineQueueEntry, type ProtocolVersion, RULE_CACHE, type ResolveClientIpInput, type ResourceUsage, type RetryStrategy, type TransportConfig, type TransportMetrics, type TransportOptions, type TransportResponse, type TransportState, type WorkerAction, type WorkerCapabilities, type WorkerConfig, type WorkerError, type WorkerErrorType, type WorkerHealthStatus, type WorkerMessage, type WorkerMessageType, type WorkerMetrics, type WorkerPoolConfig, type WorkerState, type WorkerTask, normalizeClientIp, parseBeaconConfig, parseBeaconWorkerMessage, parseCircuitBreakerConfig, parseFallbackOptions, parseOfflineQueueEntry, parseResourceUsage, parseRetryStrategy, parseWorkerCapabilities, parseWorkerConfig, parseWorkerError, parseWorkerMessage, parseWorkerPoolConfig, parseWorkerTask, resolveClientIp, validateBeaconBatch, validateBeaconConfig, validateBeaconEvent };
package/dist/browser.d.ts CHANGED
@@ -1,3 +1,32 @@
1
+ type ClientIpSource = 'explicit' | 'cf-connecting-ip' | 'x-vercel-forwarded-for' | 'x-forwarded-for' | 'x-real-ip' | 'framework' | 'socket' | 'none';
2
+ interface ClientIpResolution {
3
+ ip: string | null;
4
+ source: ClientIpSource;
5
+ trusted: boolean;
6
+ }
7
+ type ClientIpTrustPolicy = {
8
+ platform: 'vercel';
9
+ } | {
10
+ platform: 'cloudflare';
11
+ } | {
12
+ platform: 'trusted-proxy';
13
+ trustedHops: number;
14
+ } | {
15
+ platform: 'direct';
16
+ };
17
+ type ClientIpHeaderValue = string | readonly string[] | undefined;
18
+ type ClientIpHeaders = Headers | Record<string, ClientIpHeaderValue>;
19
+ interface ResolveClientIpInput {
20
+ headers: ClientIpHeaders;
21
+ directAddress?: string | null;
22
+ frameworkAddress?: string | null;
23
+ explicitAddress?: string | null;
24
+ explicitAddressTrusted?: boolean;
25
+ policy: ClientIpTrustPolicy;
26
+ }
27
+ declare function normalizeClientIp(raw: string | null | undefined): string | null;
28
+ declare function resolveClientIp(input: ResolveClientIpInput): ClientIpResolution;
29
+
1
30
  interface BrowserDetectionResult {
2
31
  category: AgentCategory;
3
32
  confidence: ConfidenceLevel;
@@ -321,4 +350,4 @@ declare const RULE_CACHE: {
321
350
  readonly TIMESTAMP_KEY: "agentshield_rules_timestamp";
322
351
  };
323
352
 
324
- export { type AgentCategory, type AgentInfo, type BatchEvent, type BeaconBatch, type BeaconCollectorData, type BeaconConfig, type BeaconEvent, type BeaconEventType, type BeaconIdentity, type BeaconMetadata, type BeaconWorkerMessage, type BeaconWorkerMessageType, type BrowserDetectionResult, type CircuitBreakerConfig, type CircuitBreakerState, type ConfidenceLevel, type ConnectionType, DEFAULT_CONFIG, type BrowserDetectionResult as DetectionResult, ERROR_TYPES, type FallbackOptions, Guards, type MessagePriority, type NetworkInfo, type OfflineQueueEntry, type ProtocolVersion, RULE_CACHE, type ResourceUsage, type RetryStrategy, type TransportConfig, type TransportMetrics, type TransportOptions, type TransportResponse, type TransportState, type WorkerAction, type WorkerCapabilities, type WorkerConfig, type WorkerError, type WorkerErrorType, type WorkerHealthStatus, type WorkerMessage, type WorkerMessageType, type WorkerMetrics, type WorkerPoolConfig, type WorkerState, type WorkerTask, parseBeaconConfig, parseBeaconWorkerMessage, parseCircuitBreakerConfig, parseFallbackOptions, parseOfflineQueueEntry, parseResourceUsage, parseRetryStrategy, parseWorkerCapabilities, parseWorkerConfig, parseWorkerError, parseWorkerMessage, parseWorkerPoolConfig, parseWorkerTask, validateBeaconBatch, validateBeaconConfig, validateBeaconEvent };
353
+ export { type AgentCategory, type AgentInfo, type BatchEvent, type BeaconBatch, type BeaconCollectorData, type BeaconConfig, type BeaconEvent, type BeaconEventType, type BeaconIdentity, type BeaconMetadata, type BeaconWorkerMessage, type BeaconWorkerMessageType, type BrowserDetectionResult, type CircuitBreakerConfig, type CircuitBreakerState, type ClientIpHeaderValue, type ClientIpHeaders, type ClientIpResolution, type ClientIpSource, type ClientIpTrustPolicy, type ConfidenceLevel, type ConnectionType, DEFAULT_CONFIG, type BrowserDetectionResult as DetectionResult, ERROR_TYPES, type FallbackOptions, Guards, type MessagePriority, type NetworkInfo, type OfflineQueueEntry, type ProtocolVersion, RULE_CACHE, type ResolveClientIpInput, type ResourceUsage, type RetryStrategy, type TransportConfig, type TransportMetrics, type TransportOptions, type TransportResponse, type TransportState, type WorkerAction, type WorkerCapabilities, type WorkerConfig, type WorkerError, type WorkerErrorType, type WorkerHealthStatus, type WorkerMessage, type WorkerMessageType, type WorkerMetrics, type WorkerPoolConfig, type WorkerState, type WorkerTask, normalizeClientIp, parseBeaconConfig, parseBeaconWorkerMessage, parseCircuitBreakerConfig, parseFallbackOptions, parseOfflineQueueEntry, parseResourceUsage, parseRetryStrategy, parseWorkerCapabilities, parseWorkerConfig, parseWorkerError, parseWorkerMessage, parseWorkerPoolConfig, parseWorkerTask, resolveClientIp, validateBeaconBatch, validateBeaconConfig, validateBeaconEvent };
package/dist/browser.js CHANGED
@@ -1 +1 @@
1
- 'use strict';function t(r){if(!r||typeof r!="object")return false;let e=r,n=e.metadata;return !!(e.type&&typeof e.type=="string"&&e.data&&typeof e.data=="object"&&n&&typeof n=="object"&&n.sessionId&&n.timestamp)}function o(r){if(!r||typeof r!="object")return false;let e=r;return !!(e.projectId&&typeof e.projectId=="string")}function a(r){if(!r||typeof r!="object")return false;let e=r;return !!(e.projectId&&typeof e.projectId=="string"&&Array.isArray(e.events)&&e.events.every(n=>t(n))&&e.sessionId&&typeof e.sessionId=="string"&&e.batchId&&e.timestamp&&typeof e.timestamp=="number")}function s(r){return typeof r=="object"&&r!==null&&!Array.isArray(r)&&typeof r.userId=="string"&&r.userId.length>0}function i(r){let e=r&&typeof r=="object"?r:{};if(!e.projectId||typeof e.projectId!="string")throw new Error("Project ID is required");return {projectId:e.projectId,environment:e.environment,tags:e.tags,identity:s(e.identity)?e.identity:void 0,endpoint:e.endpoint,enabled:e.enabled!==false,debug:e.debug===true,logLevel:e.logLevel||"error",respectDoNotTrack:e.respectDoNotTrack!==false,anonymizeIp:e.anonymizeIp===true,sessionTimeout:e.sessionTimeout||18e5,sessionCookieName:e.sessionCookieName||"_as_beacon_session",batchSize:e.batchSize||10,flushInterval:e.flushInterval||5e3,maxQueueSize:e.maxQueueSize||100,retryAttempts:e.retryAttempts||3,retryDelay:e.retryDelay||2e3,useWorker:e.useWorker!==false,workerUrl:e.workerUrl,workerConfig:e.workerConfig}}var u={isBeaconEvent:t,isBeaconConfig:o,isBeaconBatch:a,isWorkerMessage(r){if(!r||typeof r!="object")return false;let e=r;return !!(e.id&&e.type&&["request","response","error","heartbeat","status"].includes(e.type)&&typeof e.timestamp=="number")},isWorkerError(r){if(!r||typeof r!="object")return false;let e=r;return !!(e.type&&e.message&&typeof e.timestamp=="number"&&typeof e.recoverable=="boolean")},isWorkerCapabilities(r){if(!r||typeof r!="object")return false;let e=r;return typeof e.workerAPI=="boolean"&&typeof e.sharedArrayBuffer=="boolean"&&typeof e.transferableObjects=="boolean"&&typeof e.offscreenCanvas=="boolean"}};function m(r){let e=r&&typeof r=="object"?r:{};return {enabled:e.enabled!==false,url:e.url,heartbeatInterval:e.heartbeatInterval||5e3,maxUnhealthyCount:e.maxUnhealthyCount||3,maxRetries:e.maxRetries||3,retryDelay:e.retryDelay||1e3,messageTimeout:e.messageTimeout||3e4,compressionThreshold:e.compressionThreshold||1024,allowFallback:e.allowFallback!==false,crossOriginIsolated:e.crossOriginIsolated===true}}function c(r){let e=r;if(!e||typeof e!="object")throw new Error("Invalid worker message");return {id:e.id||crypto.randomUUID(),type:e.type||"request",action:e.action,payload:e.payload,timestamp:e.timestamp||Date.now(),compressed:e.compressed===true,priority:e.priority||"normal",correlationId:e.correlationId}}function d(r){let e=r;return !e||typeof e!="object"?{type:"unknown",message:String(r),timestamp:Date.now(),recoverable:false}:{type:e.type||"unknown",message:e.message||"Unknown error",stack:e.stack,timestamp:e.timestamp||Date.now(),recoverable:!!e.recoverable}}function l(r){let e=r&&typeof r=="object"?r:{};return {workerAPI:e.workerAPI!==false,sharedArrayBuffer:e.sharedArrayBuffer===true,transferableObjects:e.transferableObjects===true,offscreenCanvas:e.offscreenCanvas===true,webAssembly:e.webAssembly===true,atomics:e.atomics===true,bigInt:e.bigInt===true,csp:e.csp||{workerSrc:false,scriptSrc:false,blobUrls:false,inlineWorkers:false},performance:e.performance||{memory:false,measureUserAgentSpecificMemory:false}}}function b(r){let e=r;if(!e||typeof e!="object")throw new Error("Invalid worker task");return {id:e.id||crypto.randomUUID(),type:e.type||"process",data:e.data,priority:e.priority||"normal",createdAt:e.createdAt||Date.now(),startedAt:e.startedAt,completedAt:e.completedAt,error:e.error,maxRetries:e.maxRetries,retries:e.retries,timeout:e.timeout}}function f(r){let e=r&&typeof r=="object"?r:{};return {useRequestIdleCallback:e.useRequestIdleCallback!==false,idleTimeout:e.idleTimeout||1e4,chunkSize:e.chunkSize||10,throttleMs:e.throttleMs||16,maxExecutionTime:e.maxExecutionTime||50}}function p(r){let e=r&&typeof r=="object"?r:{};return {maxAttempts:e.maxAttempts||3,baseDelay:e.baseDelay||1e3,maxDelay:e.maxDelay||3e4,factor:e.factor||2,jitter:e.jitter!==false}}function g(r){let e=r&&typeof r=="object"?r:{};return {threshold:e.threshold||5,timeout:e.timeout||6e4,resetTimeout:e.resetTimeout||3e4}}function y(r){let e=r;if(!e||typeof e!="object")throw new Error("Invalid offline queue entry");return {id:e.id||`${Date.now()}_${Math.random().toString(36).substr(2,9)}`,events:Array.isArray(e.events)?e.events:[],timestamp:e.timestamp||Date.now(),expiresAt:e.expiresAt||Date.now()+864e5,retryCount:e.retryCount||0,size:e.size||0}}function k(r){let e=r&&typeof r=="object"?r:{};return {memoryUsage:e.memoryUsage||0,cpuUsage:e.cpuUsage||0,taskCount:e.taskCount||0,activeWorkers:e.activeWorkers||0,pendingTasks:e.pendingTasks||0,completedTasks:e.completedTasks||0,failedTasks:e.failedTasks||0,averageTaskDuration:e.averageTaskDuration||0}}function w(r){let e=r&&typeof r=="object"?r:{};return {maxWorkers:e.maxWorkers||4,minWorkers:e.minWorkers||1,workerIdleTimeout:e.workerIdleTimeout||6e4,taskQueueSize:e.taskQueueSize||100,resourceLimits:e.resourceLimits||{}}}function h(r){let e=r;if(!e||typeof e!="object")throw new Error("Invalid beacon worker message");return {type:e.type||"collect",data:e.data,messageId:e.messageId||crypto.randomUUID(),timestamp:e.timestamp||Date.now()}}var x={batchSize:10,flushInterval:5e3,sessionTimeout:18e5,sessionCookieName:"_as_beacon_session",retryAttempts:3,retryDelay:2e3},T={NETWORK:"network",VALIDATION:"validation",TIMEOUT:"timeout",UNKNOWN:"unknown"},I={DEFAULT_DURATION:36e5,MAX_DURATION:864e5,MIN_DURATION:6e4,STORAGE_KEY:"agentshield_rules",TIMESTAMP_KEY:"agentshield_rules_timestamp"};exports.DEFAULT_CONFIG=x;exports.ERROR_TYPES=T;exports.Guards=u;exports.RULE_CACHE=I;exports.parseBeaconConfig=i;exports.parseBeaconWorkerMessage=h;exports.parseCircuitBreakerConfig=g;exports.parseFallbackOptions=f;exports.parseOfflineQueueEntry=y;exports.parseResourceUsage=k;exports.parseRetryStrategy=p;exports.parseWorkerCapabilities=l;exports.parseWorkerConfig=m;exports.parseWorkerError=d;exports.parseWorkerMessage=c;exports.parseWorkerPoolConfig=w;exports.parseWorkerTask=b;exports.validateBeaconBatch=a;exports.validateBeaconConfig=o;exports.validateBeaconEvent=t;
1
+ 'use strict';function p(r){for(let e=0;e<r.length;e++){let n=r.charCodeAt(e);if(n<=31||n===127)return true}return false}function b(r){return /^(?:0|[1-9]\d{0,4})$/.test(r)&&Number(r)<=65535}function g(r){let e=r.split(".");if(e.length!==4)return null;let n=[];for(let t of e){if(!/^\d{1,3}$/.test(t))return null;let s=Number(t);if(s>255)return null;n.push(s);}return n}function h(r){return /^[0-9a-fA-F]{1,4}$/.test(r)?Number.parseInt(r,16):null}function I(r){if(!r||r.includes("%")||p(r))return null;let e=r;if(e.includes(".")){let o=e.lastIndexOf(":");if(o<0)return null;let a=g(e.slice(o+1));if(!a)return null;let i=a[0]<<8|a[1],c=a[2]<<8|a[3];e=`${e.slice(0,o+1)}${i.toString(16)}:${c.toString(16)}`;}let n=e.indexOf("::");if(n!==e.lastIndexOf("::"))return null;let t=o=>{if(!o)return [];let a=o.split(":"),i=[];for(let c of a){let m=h(c);if(m===null)return null;i.push(m);}return i};if(n>=0){let o=t(e.slice(0,n)),a=t(e.slice(n+2));if(!o||!a)return null;let i=8-o.length-a.length;return i<1?null:[...o,...Array(i).fill(0),...a]}let s=t(e);return (s==null?void 0:s.length)===8?s:null}function C(r){let e=r.map(i=>i.toString(16)),n=-1,t=1,s=-1;for(let i=0;i<=r.length;i+=1){if(i<r.length&&r[i]===0){s<0&&(s=i);continue}if(s>=0){let c=i-s;c>t&&(n=s,t=c),s=-1;}}if(n<0)return e.join(":");let o=e.slice(0,n).join(":"),a=e.slice(n+t).join(":");return !o&&!a?"::":o?a?`${o}::${a}`:`${o}::`:`::${a}`}function k(r){var o;let e=r.trim();if(!e||e.length>128||p(e))return null;let n=e;if(e.startsWith("[")){let a=e.indexOf("]");if(a<=1)return null;let i=e.slice(a+1);if(i&&(!i.startsWith(":")||!b(i.slice(1))))return null;n=e.slice(1,a);}else if(((o=e.match(/:/g))!=null?o:[]).length===1&&e.includes(".")){let a=e.indexOf(":");if(!b(e.slice(a+1)))return null;n=e.slice(0,a);}let t=g(n);if(t)return t.join(".");let s=I(n);return s?C(s):null}function y(r){if(r==null||!r||r.length>4096||p(r))return null;let e=r.split(",");return e.length>32?null:e}function u(r){let e=y(r);if(!e)return null;for(let n of e){let t=k(n);if(t)return t}return null}function d(r,e){var t;if("get"in r&&typeof r.get=="function")return (t=r.get(e))!=null?t:void 0;let n=e.toLowerCase();for(let[s,o]of Object.entries(r))if(!(s.toLowerCase()!==n||o===void 0))return Array.isArray(o)?o.join(","):o}function l(r,e,n){return r?{ip:r,source:e,trusted:n}:null}function f(r,e){return l(u(r),e,true)}function T(r){return r.explicitAddressTrusted!==true?null:l(u(r.explicitAddress),"explicit",true)}function v(r){var s,o;let e=l(u(d(r.headers,"x-vercel-forwarded-for")),"x-vercel-forwarded-for",true);if(e)return e;let n=l(u(d(r.headers,"x-forwarded-for")),"x-forwarded-for",true);if(n)return n;let t=l(u(d(r.headers,"x-real-ip")),"x-real-ip",false);return t||((o=(s=f(r.frameworkAddress,"framework"))!=null?s:f(r.directAddress,"socket"))!=null?o:{ip:null,source:"none",trusted:false})}function A(r){var n,t,s,o;let e=l(u(d(r.headers,"cf-connecting-ip")),"cf-connecting-ip",true);return e||((o=(s=(t=(n=f(r.directAddress,"socket"))!=null?n:f(r.frameworkAddress,"framework"))!=null?t:l(u(d(r.headers,"x-forwarded-for")),"x-forwarded-for",false))!=null?s:l(u(d(r.headers,"x-real-ip")),"x-real-ip",false))!=null?o:{ip:null,source:"none",trusted:false})}function R(r,e){var s,o,a;let n=d(r.headers,"x-forwarded-for"),t=y(n);if(t&&Number.isInteger(e)&&e>0&&t.length>e){let i=t.map(k),c=t.length-e-1,m=i[c];if(m&&i.every(x=>x!==null))return {ip:m,source:"x-forwarded-for",trusted:true}}return (a=(o=(s=f(r.frameworkAddress,"framework"))!=null?s:f(r.directAddress,"socket"))!=null?o:l(u(d(r.headers,"x-real-ip")),"x-real-ip",false))!=null?a:{ip:null,source:"none",trusted:false}}function S(r){var n,t;let e=T(r);if(e)return e;switch(r.policy.platform){case "vercel":return v(r);case "cloudflare":return A(r);case "trusted-proxy":return R(r,r.policy.trustedHops);case "direct":return (t=(n=f(r.frameworkAddress,"framework"))!=null?n:f(r.directAddress,"socket"))!=null?t:{ip:null,source:"none",trusted:false}}}function w(r){if(!r||typeof r!="object")return false;let e=r,n=e.metadata;return !!(e.type&&typeof e.type=="string"&&e.data&&typeof e.data=="object"&&n&&typeof n=="object"&&n.sessionId&&n.timestamp)}function W(r){if(!r||typeof r!="object")return false;let e=r;return !!(e.projectId&&typeof e.projectId=="string")}function B(r){if(!r||typeof r!="object")return false;let e=r;return !!(e.projectId&&typeof e.projectId=="string"&&Array.isArray(e.events)&&e.events.every(n=>w(n))&&e.sessionId&&typeof e.sessionId=="string"&&e.batchId&&e.timestamp&&typeof e.timestamp=="number")}function E(r){return typeof r=="object"&&r!==null&&!Array.isArray(r)&&typeof r.userId=="string"&&r.userId.length>0}function j(r){let e=r&&typeof r=="object"?r:{};if(!e.projectId||typeof e.projectId!="string")throw new Error("Project ID is required");return {projectId:e.projectId,environment:e.environment,tags:e.tags,identity:E(e.identity)?e.identity:void 0,endpoint:e.endpoint,enabled:e.enabled!==false,debug:e.debug===true,logLevel:e.logLevel||"error",respectDoNotTrack:e.respectDoNotTrack!==false,anonymizeIp:e.anonymizeIp===true,sessionTimeout:e.sessionTimeout||18e5,sessionCookieName:e.sessionCookieName||"_as_beacon_session",batchSize:e.batchSize||10,flushInterval:e.flushInterval||5e3,maxQueueSize:e.maxQueueSize||100,retryAttempts:e.retryAttempts||3,retryDelay:e.retryDelay||2e3,useWorker:e.useWorker!==false,workerUrl:e.workerUrl,workerConfig:e.workerConfig}}var U={isBeaconEvent:w,isBeaconConfig:W,isBeaconBatch:B,isWorkerMessage(r){if(!r||typeof r!="object")return false;let e=r;return !!(e.id&&e.type&&["request","response","error","heartbeat","status"].includes(e.type)&&typeof e.timestamp=="number")},isWorkerError(r){if(!r||typeof r!="object")return false;let e=r;return !!(e.type&&e.message&&typeof e.timestamp=="number"&&typeof e.recoverable=="boolean")},isWorkerCapabilities(r){if(!r||typeof r!="object")return false;let e=r;return typeof e.workerAPI=="boolean"&&typeof e.sharedArrayBuffer=="boolean"&&typeof e.transferableObjects=="boolean"&&typeof e.offscreenCanvas=="boolean"}};function M(r){let e=r&&typeof r=="object"?r:{};return {enabled:e.enabled!==false,url:e.url,heartbeatInterval:e.heartbeatInterval||5e3,maxUnhealthyCount:e.maxUnhealthyCount||3,maxRetries:e.maxRetries||3,retryDelay:e.retryDelay||1e3,messageTimeout:e.messageTimeout||3e4,compressionThreshold:e.compressionThreshold||1024,allowFallback:e.allowFallback!==false,crossOriginIsolated:e.crossOriginIsolated===true}}function O(r){let e=r;if(!e||typeof e!="object")throw new Error("Invalid worker message");return {id:e.id||crypto.randomUUID(),type:e.type||"request",action:e.action,payload:e.payload,timestamp:e.timestamp||Date.now(),compressed:e.compressed===true,priority:e.priority||"normal",correlationId:e.correlationId}}function N(r){let e=r;return !e||typeof e!="object"?{type:"unknown",message:String(r),timestamp:Date.now(),recoverable:false}:{type:e.type||"unknown",message:e.message||"Unknown error",stack:e.stack,timestamp:e.timestamp||Date.now(),recoverable:!!e.recoverable}}function _(r){let e=r&&typeof r=="object"?r:{};return {workerAPI:e.workerAPI!==false,sharedArrayBuffer:e.sharedArrayBuffer===true,transferableObjects:e.transferableObjects===true,offscreenCanvas:e.offscreenCanvas===true,webAssembly:e.webAssembly===true,atomics:e.atomics===true,bigInt:e.bigInt===true,csp:e.csp||{workerSrc:false,scriptSrc:false,blobUrls:false,inlineWorkers:false},performance:e.performance||{memory:false,measureUserAgentSpecificMemory:false}}}function z(r){let e=r;if(!e||typeof e!="object")throw new Error("Invalid worker task");return {id:e.id||crypto.randomUUID(),type:e.type||"process",data:e.data,priority:e.priority||"normal",createdAt:e.createdAt||Date.now(),startedAt:e.startedAt,completedAt:e.completedAt,error:e.error,maxRetries:e.maxRetries,retries:e.retries,timeout:e.timeout}}function P(r){let e=r&&typeof r=="object"?r:{};return {useRequestIdleCallback:e.useRequestIdleCallback!==false,idleTimeout:e.idleTimeout||1e4,chunkSize:e.chunkSize||10,throttleMs:e.throttleMs||16,maxExecutionTime:e.maxExecutionTime||50}}function L(r){let e=r&&typeof r=="object"?r:{};return {maxAttempts:e.maxAttempts||3,baseDelay:e.baseDelay||1e3,maxDelay:e.maxDelay||3e4,factor:e.factor||2,jitter:e.jitter!==false}}function H(r){let e=r&&typeof r=="object"?r:{};return {threshold:e.threshold||5,timeout:e.timeout||6e4,resetTimeout:e.resetTimeout||3e4}}function F(r){let e=r;if(!e||typeof e!="object")throw new Error("Invalid offline queue entry");return {id:e.id||`${Date.now()}_${Math.random().toString(36).substr(2,9)}`,events:Array.isArray(e.events)?e.events:[],timestamp:e.timestamp||Date.now(),expiresAt:e.expiresAt||Date.now()+864e5,retryCount:e.retryCount||0,size:e.size||0}}function $(r){let e=r&&typeof r=="object"?r:{};return {memoryUsage:e.memoryUsage||0,cpuUsage:e.cpuUsage||0,taskCount:e.taskCount||0,activeWorkers:e.activeWorkers||0,pendingTasks:e.pendingTasks||0,completedTasks:e.completedTasks||0,failedTasks:e.failedTasks||0,averageTaskDuration:e.averageTaskDuration||0}}function Q(r){let e=r&&typeof r=="object"?r:{};return {maxWorkers:e.maxWorkers||4,minWorkers:e.minWorkers||1,workerIdleTimeout:e.workerIdleTimeout||6e4,taskQueueSize:e.taskQueueSize||100,resourceLimits:e.resourceLimits||{}}}function q(r){let e=r;if(!e||typeof e!="object")throw new Error("Invalid beacon worker message");return {type:e.type||"collect",data:e.data,messageId:e.messageId||crypto.randomUUID(),timestamp:e.timestamp||Date.now()}}var G={batchSize:10,flushInterval:5e3,sessionTimeout:18e5,sessionCookieName:"_as_beacon_session",retryAttempts:3,retryDelay:2e3},X={NETWORK:"network",VALIDATION:"validation",TIMEOUT:"timeout",UNKNOWN:"unknown"},K={DEFAULT_DURATION:36e5,MAX_DURATION:864e5,MIN_DURATION:6e4,STORAGE_KEY:"agentshield_rules",TIMESTAMP_KEY:"agentshield_rules_timestamp"};exports.DEFAULT_CONFIG=G;exports.ERROR_TYPES=X;exports.Guards=U;exports.RULE_CACHE=K;exports.normalizeClientIp=u;exports.parseBeaconConfig=j;exports.parseBeaconWorkerMessage=q;exports.parseCircuitBreakerConfig=H;exports.parseFallbackOptions=P;exports.parseOfflineQueueEntry=F;exports.parseResourceUsage=$;exports.parseRetryStrategy=L;exports.parseWorkerCapabilities=_;exports.parseWorkerConfig=M;exports.parseWorkerError=N;exports.parseWorkerMessage=O;exports.parseWorkerPoolConfig=Q;exports.parseWorkerTask=z;exports.resolveClientIp=S;exports.validateBeaconBatch=B;exports.validateBeaconConfig=W;exports.validateBeaconEvent=w;
package/dist/browser.mjs CHANGED
@@ -1 +1 @@
1
- function t(r){if(!r||typeof r!="object")return false;let e=r,n=e.metadata;return !!(e.type&&typeof e.type=="string"&&e.data&&typeof e.data=="object"&&n&&typeof n=="object"&&n.sessionId&&n.timestamp)}function o(r){if(!r||typeof r!="object")return false;let e=r;return !!(e.projectId&&typeof e.projectId=="string")}function a(r){if(!r||typeof r!="object")return false;let e=r;return !!(e.projectId&&typeof e.projectId=="string"&&Array.isArray(e.events)&&e.events.every(n=>t(n))&&e.sessionId&&typeof e.sessionId=="string"&&e.batchId&&e.timestamp&&typeof e.timestamp=="number")}function s(r){return typeof r=="object"&&r!==null&&!Array.isArray(r)&&typeof r.userId=="string"&&r.userId.length>0}function i(r){let e=r&&typeof r=="object"?r:{};if(!e.projectId||typeof e.projectId!="string")throw new Error("Project ID is required");return {projectId:e.projectId,environment:e.environment,tags:e.tags,identity:s(e.identity)?e.identity:void 0,endpoint:e.endpoint,enabled:e.enabled!==false,debug:e.debug===true,logLevel:e.logLevel||"error",respectDoNotTrack:e.respectDoNotTrack!==false,anonymizeIp:e.anonymizeIp===true,sessionTimeout:e.sessionTimeout||18e5,sessionCookieName:e.sessionCookieName||"_as_beacon_session",batchSize:e.batchSize||10,flushInterval:e.flushInterval||5e3,maxQueueSize:e.maxQueueSize||100,retryAttempts:e.retryAttempts||3,retryDelay:e.retryDelay||2e3,useWorker:e.useWorker!==false,workerUrl:e.workerUrl,workerConfig:e.workerConfig}}var u={isBeaconEvent:t,isBeaconConfig:o,isBeaconBatch:a,isWorkerMessage(r){if(!r||typeof r!="object")return false;let e=r;return !!(e.id&&e.type&&["request","response","error","heartbeat","status"].includes(e.type)&&typeof e.timestamp=="number")},isWorkerError(r){if(!r||typeof r!="object")return false;let e=r;return !!(e.type&&e.message&&typeof e.timestamp=="number"&&typeof e.recoverable=="boolean")},isWorkerCapabilities(r){if(!r||typeof r!="object")return false;let e=r;return typeof e.workerAPI=="boolean"&&typeof e.sharedArrayBuffer=="boolean"&&typeof e.transferableObjects=="boolean"&&typeof e.offscreenCanvas=="boolean"}};function m(r){let e=r&&typeof r=="object"?r:{};return {enabled:e.enabled!==false,url:e.url,heartbeatInterval:e.heartbeatInterval||5e3,maxUnhealthyCount:e.maxUnhealthyCount||3,maxRetries:e.maxRetries||3,retryDelay:e.retryDelay||1e3,messageTimeout:e.messageTimeout||3e4,compressionThreshold:e.compressionThreshold||1024,allowFallback:e.allowFallback!==false,crossOriginIsolated:e.crossOriginIsolated===true}}function c(r){let e=r;if(!e||typeof e!="object")throw new Error("Invalid worker message");return {id:e.id||crypto.randomUUID(),type:e.type||"request",action:e.action,payload:e.payload,timestamp:e.timestamp||Date.now(),compressed:e.compressed===true,priority:e.priority||"normal",correlationId:e.correlationId}}function d(r){let e=r;return !e||typeof e!="object"?{type:"unknown",message:String(r),timestamp:Date.now(),recoverable:false}:{type:e.type||"unknown",message:e.message||"Unknown error",stack:e.stack,timestamp:e.timestamp||Date.now(),recoverable:!!e.recoverable}}function l(r){let e=r&&typeof r=="object"?r:{};return {workerAPI:e.workerAPI!==false,sharedArrayBuffer:e.sharedArrayBuffer===true,transferableObjects:e.transferableObjects===true,offscreenCanvas:e.offscreenCanvas===true,webAssembly:e.webAssembly===true,atomics:e.atomics===true,bigInt:e.bigInt===true,csp:e.csp||{workerSrc:false,scriptSrc:false,blobUrls:false,inlineWorkers:false},performance:e.performance||{memory:false,measureUserAgentSpecificMemory:false}}}function b(r){let e=r;if(!e||typeof e!="object")throw new Error("Invalid worker task");return {id:e.id||crypto.randomUUID(),type:e.type||"process",data:e.data,priority:e.priority||"normal",createdAt:e.createdAt||Date.now(),startedAt:e.startedAt,completedAt:e.completedAt,error:e.error,maxRetries:e.maxRetries,retries:e.retries,timeout:e.timeout}}function f(r){let e=r&&typeof r=="object"?r:{};return {useRequestIdleCallback:e.useRequestIdleCallback!==false,idleTimeout:e.idleTimeout||1e4,chunkSize:e.chunkSize||10,throttleMs:e.throttleMs||16,maxExecutionTime:e.maxExecutionTime||50}}function p(r){let e=r&&typeof r=="object"?r:{};return {maxAttempts:e.maxAttempts||3,baseDelay:e.baseDelay||1e3,maxDelay:e.maxDelay||3e4,factor:e.factor||2,jitter:e.jitter!==false}}function g(r){let e=r&&typeof r=="object"?r:{};return {threshold:e.threshold||5,timeout:e.timeout||6e4,resetTimeout:e.resetTimeout||3e4}}function y(r){let e=r;if(!e||typeof e!="object")throw new Error("Invalid offline queue entry");return {id:e.id||`${Date.now()}_${Math.random().toString(36).substr(2,9)}`,events:Array.isArray(e.events)?e.events:[],timestamp:e.timestamp||Date.now(),expiresAt:e.expiresAt||Date.now()+864e5,retryCount:e.retryCount||0,size:e.size||0}}function k(r){let e=r&&typeof r=="object"?r:{};return {memoryUsage:e.memoryUsage||0,cpuUsage:e.cpuUsage||0,taskCount:e.taskCount||0,activeWorkers:e.activeWorkers||0,pendingTasks:e.pendingTasks||0,completedTasks:e.completedTasks||0,failedTasks:e.failedTasks||0,averageTaskDuration:e.averageTaskDuration||0}}function w(r){let e=r&&typeof r=="object"?r:{};return {maxWorkers:e.maxWorkers||4,minWorkers:e.minWorkers||1,workerIdleTimeout:e.workerIdleTimeout||6e4,taskQueueSize:e.taskQueueSize||100,resourceLimits:e.resourceLimits||{}}}function h(r){let e=r;if(!e||typeof e!="object")throw new Error("Invalid beacon worker message");return {type:e.type||"collect",data:e.data,messageId:e.messageId||crypto.randomUUID(),timestamp:e.timestamp||Date.now()}}var x={batchSize:10,flushInterval:5e3,sessionTimeout:18e5,sessionCookieName:"_as_beacon_session",retryAttempts:3,retryDelay:2e3},T={NETWORK:"network",VALIDATION:"validation",TIMEOUT:"timeout",UNKNOWN:"unknown"},I={DEFAULT_DURATION:36e5,MAX_DURATION:864e5,MIN_DURATION:6e4,STORAGE_KEY:"agentshield_rules",TIMESTAMP_KEY:"agentshield_rules_timestamp"};export{x as DEFAULT_CONFIG,T as ERROR_TYPES,u as Guards,I as RULE_CACHE,i as parseBeaconConfig,h as parseBeaconWorkerMessage,g as parseCircuitBreakerConfig,f as parseFallbackOptions,y as parseOfflineQueueEntry,k as parseResourceUsage,p as parseRetryStrategy,l as parseWorkerCapabilities,m as parseWorkerConfig,d as parseWorkerError,c as parseWorkerMessage,w as parseWorkerPoolConfig,b as parseWorkerTask,a as validateBeaconBatch,o as validateBeaconConfig,t as validateBeaconEvent};
1
+ function p(r){for(let e=0;e<r.length;e++){let n=r.charCodeAt(e);if(n<=31||n===127)return true}return false}function b(r){return /^(?:0|[1-9]\d{0,4})$/.test(r)&&Number(r)<=65535}function g(r){let e=r.split(".");if(e.length!==4)return null;let n=[];for(let t of e){if(!/^\d{1,3}$/.test(t))return null;let s=Number(t);if(s>255)return null;n.push(s);}return n}function h(r){return /^[0-9a-fA-F]{1,4}$/.test(r)?Number.parseInt(r,16):null}function I(r){if(!r||r.includes("%")||p(r))return null;let e=r;if(e.includes(".")){let o=e.lastIndexOf(":");if(o<0)return null;let a=g(e.slice(o+1));if(!a)return null;let i=a[0]<<8|a[1],c=a[2]<<8|a[3];e=`${e.slice(0,o+1)}${i.toString(16)}:${c.toString(16)}`;}let n=e.indexOf("::");if(n!==e.lastIndexOf("::"))return null;let t=o=>{if(!o)return [];let a=o.split(":"),i=[];for(let c of a){let m=h(c);if(m===null)return null;i.push(m);}return i};if(n>=0){let o=t(e.slice(0,n)),a=t(e.slice(n+2));if(!o||!a)return null;let i=8-o.length-a.length;return i<1?null:[...o,...Array(i).fill(0),...a]}let s=t(e);return (s==null?void 0:s.length)===8?s:null}function C(r){let e=r.map(i=>i.toString(16)),n=-1,t=1,s=-1;for(let i=0;i<=r.length;i+=1){if(i<r.length&&r[i]===0){s<0&&(s=i);continue}if(s>=0){let c=i-s;c>t&&(n=s,t=c),s=-1;}}if(n<0)return e.join(":");let o=e.slice(0,n).join(":"),a=e.slice(n+t).join(":");return !o&&!a?"::":o?a?`${o}::${a}`:`${o}::`:`::${a}`}function k(r){var o;let e=r.trim();if(!e||e.length>128||p(e))return null;let n=e;if(e.startsWith("[")){let a=e.indexOf("]");if(a<=1)return null;let i=e.slice(a+1);if(i&&(!i.startsWith(":")||!b(i.slice(1))))return null;n=e.slice(1,a);}else if(((o=e.match(/:/g))!=null?o:[]).length===1&&e.includes(".")){let a=e.indexOf(":");if(!b(e.slice(a+1)))return null;n=e.slice(0,a);}let t=g(n);if(t)return t.join(".");let s=I(n);return s?C(s):null}function y(r){if(r==null||!r||r.length>4096||p(r))return null;let e=r.split(",");return e.length>32?null:e}function u(r){let e=y(r);if(!e)return null;for(let n of e){let t=k(n);if(t)return t}return null}function d(r,e){var t;if("get"in r&&typeof r.get=="function")return (t=r.get(e))!=null?t:void 0;let n=e.toLowerCase();for(let[s,o]of Object.entries(r))if(!(s.toLowerCase()!==n||o===void 0))return Array.isArray(o)?o.join(","):o}function l(r,e,n){return r?{ip:r,source:e,trusted:n}:null}function f(r,e){return l(u(r),e,true)}function T(r){return r.explicitAddressTrusted!==true?null:l(u(r.explicitAddress),"explicit",true)}function v(r){var s,o;let e=l(u(d(r.headers,"x-vercel-forwarded-for")),"x-vercel-forwarded-for",true);if(e)return e;let n=l(u(d(r.headers,"x-forwarded-for")),"x-forwarded-for",true);if(n)return n;let t=l(u(d(r.headers,"x-real-ip")),"x-real-ip",false);return t||((o=(s=f(r.frameworkAddress,"framework"))!=null?s:f(r.directAddress,"socket"))!=null?o:{ip:null,source:"none",trusted:false})}function A(r){var n,t,s,o;let e=l(u(d(r.headers,"cf-connecting-ip")),"cf-connecting-ip",true);return e||((o=(s=(t=(n=f(r.directAddress,"socket"))!=null?n:f(r.frameworkAddress,"framework"))!=null?t:l(u(d(r.headers,"x-forwarded-for")),"x-forwarded-for",false))!=null?s:l(u(d(r.headers,"x-real-ip")),"x-real-ip",false))!=null?o:{ip:null,source:"none",trusted:false})}function R(r,e){var s,o,a;let n=d(r.headers,"x-forwarded-for"),t=y(n);if(t&&Number.isInteger(e)&&e>0&&t.length>e){let i=t.map(k),c=t.length-e-1,m=i[c];if(m&&i.every(x=>x!==null))return {ip:m,source:"x-forwarded-for",trusted:true}}return (a=(o=(s=f(r.frameworkAddress,"framework"))!=null?s:f(r.directAddress,"socket"))!=null?o:l(u(d(r.headers,"x-real-ip")),"x-real-ip",false))!=null?a:{ip:null,source:"none",trusted:false}}function S(r){var n,t;let e=T(r);if(e)return e;switch(r.policy.platform){case "vercel":return v(r);case "cloudflare":return A(r);case "trusted-proxy":return R(r,r.policy.trustedHops);case "direct":return (t=(n=f(r.frameworkAddress,"framework"))!=null?n:f(r.directAddress,"socket"))!=null?t:{ip:null,source:"none",trusted:false}}}function w(r){if(!r||typeof r!="object")return false;let e=r,n=e.metadata;return !!(e.type&&typeof e.type=="string"&&e.data&&typeof e.data=="object"&&n&&typeof n=="object"&&n.sessionId&&n.timestamp)}function W(r){if(!r||typeof r!="object")return false;let e=r;return !!(e.projectId&&typeof e.projectId=="string")}function B(r){if(!r||typeof r!="object")return false;let e=r;return !!(e.projectId&&typeof e.projectId=="string"&&Array.isArray(e.events)&&e.events.every(n=>w(n))&&e.sessionId&&typeof e.sessionId=="string"&&e.batchId&&e.timestamp&&typeof e.timestamp=="number")}function E(r){return typeof r=="object"&&r!==null&&!Array.isArray(r)&&typeof r.userId=="string"&&r.userId.length>0}function j(r){let e=r&&typeof r=="object"?r:{};if(!e.projectId||typeof e.projectId!="string")throw new Error("Project ID is required");return {projectId:e.projectId,environment:e.environment,tags:e.tags,identity:E(e.identity)?e.identity:void 0,endpoint:e.endpoint,enabled:e.enabled!==false,debug:e.debug===true,logLevel:e.logLevel||"error",respectDoNotTrack:e.respectDoNotTrack!==false,anonymizeIp:e.anonymizeIp===true,sessionTimeout:e.sessionTimeout||18e5,sessionCookieName:e.sessionCookieName||"_as_beacon_session",batchSize:e.batchSize||10,flushInterval:e.flushInterval||5e3,maxQueueSize:e.maxQueueSize||100,retryAttempts:e.retryAttempts||3,retryDelay:e.retryDelay||2e3,useWorker:e.useWorker!==false,workerUrl:e.workerUrl,workerConfig:e.workerConfig}}var U={isBeaconEvent:w,isBeaconConfig:W,isBeaconBatch:B,isWorkerMessage(r){if(!r||typeof r!="object")return false;let e=r;return !!(e.id&&e.type&&["request","response","error","heartbeat","status"].includes(e.type)&&typeof e.timestamp=="number")},isWorkerError(r){if(!r||typeof r!="object")return false;let e=r;return !!(e.type&&e.message&&typeof e.timestamp=="number"&&typeof e.recoverable=="boolean")},isWorkerCapabilities(r){if(!r||typeof r!="object")return false;let e=r;return typeof e.workerAPI=="boolean"&&typeof e.sharedArrayBuffer=="boolean"&&typeof e.transferableObjects=="boolean"&&typeof e.offscreenCanvas=="boolean"}};function M(r){let e=r&&typeof r=="object"?r:{};return {enabled:e.enabled!==false,url:e.url,heartbeatInterval:e.heartbeatInterval||5e3,maxUnhealthyCount:e.maxUnhealthyCount||3,maxRetries:e.maxRetries||3,retryDelay:e.retryDelay||1e3,messageTimeout:e.messageTimeout||3e4,compressionThreshold:e.compressionThreshold||1024,allowFallback:e.allowFallback!==false,crossOriginIsolated:e.crossOriginIsolated===true}}function O(r){let e=r;if(!e||typeof e!="object")throw new Error("Invalid worker message");return {id:e.id||crypto.randomUUID(),type:e.type||"request",action:e.action,payload:e.payload,timestamp:e.timestamp||Date.now(),compressed:e.compressed===true,priority:e.priority||"normal",correlationId:e.correlationId}}function N(r){let e=r;return !e||typeof e!="object"?{type:"unknown",message:String(r),timestamp:Date.now(),recoverable:false}:{type:e.type||"unknown",message:e.message||"Unknown error",stack:e.stack,timestamp:e.timestamp||Date.now(),recoverable:!!e.recoverable}}function _(r){let e=r&&typeof r=="object"?r:{};return {workerAPI:e.workerAPI!==false,sharedArrayBuffer:e.sharedArrayBuffer===true,transferableObjects:e.transferableObjects===true,offscreenCanvas:e.offscreenCanvas===true,webAssembly:e.webAssembly===true,atomics:e.atomics===true,bigInt:e.bigInt===true,csp:e.csp||{workerSrc:false,scriptSrc:false,blobUrls:false,inlineWorkers:false},performance:e.performance||{memory:false,measureUserAgentSpecificMemory:false}}}function z(r){let e=r;if(!e||typeof e!="object")throw new Error("Invalid worker task");return {id:e.id||crypto.randomUUID(),type:e.type||"process",data:e.data,priority:e.priority||"normal",createdAt:e.createdAt||Date.now(),startedAt:e.startedAt,completedAt:e.completedAt,error:e.error,maxRetries:e.maxRetries,retries:e.retries,timeout:e.timeout}}function P(r){let e=r&&typeof r=="object"?r:{};return {useRequestIdleCallback:e.useRequestIdleCallback!==false,idleTimeout:e.idleTimeout||1e4,chunkSize:e.chunkSize||10,throttleMs:e.throttleMs||16,maxExecutionTime:e.maxExecutionTime||50}}function L(r){let e=r&&typeof r=="object"?r:{};return {maxAttempts:e.maxAttempts||3,baseDelay:e.baseDelay||1e3,maxDelay:e.maxDelay||3e4,factor:e.factor||2,jitter:e.jitter!==false}}function H(r){let e=r&&typeof r=="object"?r:{};return {threshold:e.threshold||5,timeout:e.timeout||6e4,resetTimeout:e.resetTimeout||3e4}}function F(r){let e=r;if(!e||typeof e!="object")throw new Error("Invalid offline queue entry");return {id:e.id||`${Date.now()}_${Math.random().toString(36).substr(2,9)}`,events:Array.isArray(e.events)?e.events:[],timestamp:e.timestamp||Date.now(),expiresAt:e.expiresAt||Date.now()+864e5,retryCount:e.retryCount||0,size:e.size||0}}function $(r){let e=r&&typeof r=="object"?r:{};return {memoryUsage:e.memoryUsage||0,cpuUsage:e.cpuUsage||0,taskCount:e.taskCount||0,activeWorkers:e.activeWorkers||0,pendingTasks:e.pendingTasks||0,completedTasks:e.completedTasks||0,failedTasks:e.failedTasks||0,averageTaskDuration:e.averageTaskDuration||0}}function Q(r){let e=r&&typeof r=="object"?r:{};return {maxWorkers:e.maxWorkers||4,minWorkers:e.minWorkers||1,workerIdleTimeout:e.workerIdleTimeout||6e4,taskQueueSize:e.taskQueueSize||100,resourceLimits:e.resourceLimits||{}}}function q(r){let e=r;if(!e||typeof e!="object")throw new Error("Invalid beacon worker message");return {type:e.type||"collect",data:e.data,messageId:e.messageId||crypto.randomUUID(),timestamp:e.timestamp||Date.now()}}var G={batchSize:10,flushInterval:5e3,sessionTimeout:18e5,sessionCookieName:"_as_beacon_session",retryAttempts:3,retryDelay:2e3},X={NETWORK:"network",VALIDATION:"validation",TIMEOUT:"timeout",UNKNOWN:"unknown"},K={DEFAULT_DURATION:36e5,MAX_DURATION:864e5,MIN_DURATION:6e4,STORAGE_KEY:"agentshield_rules",TIMESTAMP_KEY:"agentshield_rules_timestamp"};export{G as DEFAULT_CONFIG,X as ERROR_TYPES,U as Guards,K as RULE_CACHE,u as normalizeClientIp,j as parseBeaconConfig,q as parseBeaconWorkerMessage,H as parseCircuitBreakerConfig,P as parseFallbackOptions,F as parseOfflineQueueEntry,$ as parseResourceUsage,L as parseRetryStrategy,_ as parseWorkerCapabilities,M as parseWorkerConfig,N as parseWorkerError,O as parseWorkerMessage,Q as parseWorkerPoolConfig,z as parseWorkerTask,S as resolveClientIp,B as validateBeaconBatch,W as validateBeaconConfig,w as validateBeaconEvent};
@@ -0,0 +1,104 @@
1
+ declare const ERROR_CODES: {
2
+ readonly LOWERCASE_INVALID_JSON: "invalid_json";
3
+ readonly LOWERCASE_VALIDATION_ERROR: "validation_error";
4
+ readonly BARE_VALIDATION_ERROR: "VALIDATION_ERROR";
5
+ readonly BARE_INTERNAL_ERROR: "INTERNAL_ERROR";
6
+ readonly POLICY_FETCH_FAILED: "POLICY_FETCH_FAILED";
7
+ readonly CONFLICT: "CONFLICT";
8
+ readonly PROJECT_NOT_FOUND: "PROJECT_NOT_FOUND";
9
+ readonly REVIEW_REQUIRED: "REVIEW_REQUIRED";
10
+ readonly LIMIT_EXCEEDED: "LIMIT_EXCEEDED";
11
+ readonly BILLING_SUSPENDED: "BILLING_SUSPENDED";
12
+ readonly BILLING_GRACE_PERIOD: "BILLING_GRACE_PERIOD";
13
+ readonly ENDPOINT_NOT_FOUND: "API_ENDPOINT_NOT_FOUND";
14
+ readonly METHOD_NOT_ALLOWED: "API_METHOD_NOT_ALLOWED";
15
+ readonly VERSION_NOT_SUPPORTED: "API_VERSION_NOT_SUPPORTED";
16
+ readonly CONTENT_TYPE_NOT_SUPPORTED: "API_CONTENT_TYPE_NOT_SUPPORTED";
17
+ readonly RESPONSE_TOO_LARGE: "API_RESPONSE_TOO_LARGE";
18
+ readonly REQUEST_TOO_LARGE: "API_REQUEST_TOO_LARGE";
19
+ readonly PIXEL_NOT_FOUND: "PIXEL_NOT_FOUND";
20
+ readonly PIXEL_DISABLED: "PIXEL_DISABLED";
21
+ readonly PIXEL_CONFIGURATION_ERROR: "PIXEL_CONFIGURATION_ERROR";
22
+ readonly PIXEL_DOMAIN_NOT_ALLOWED: "PIXEL_DOMAIN_NOT_ALLOWED";
23
+ readonly PIXEL_PATH_SKIPPED: "PIXEL_PATH_SKIPPED";
24
+ readonly PIXEL_EVENT_INVALID: "PIXEL_EVENT_INVALID";
25
+ readonly PIXEL_BATCH_TOO_LARGE: "PIXEL_BATCH_TOO_LARGE";
26
+ readonly MISSING_PIXEL_ID: "MISSING_PIXEL_ID";
27
+ readonly INVALID_EDGE_SIGNATURE: "INVALID_EDGE_SIGNATURE";
28
+ readonly DETECTION_STORAGE_FAILED: "DETECTION_STORAGE_FAILED";
29
+ readonly SESSION_NOT_FOUND: "SESSION_NOT_FOUND";
30
+ readonly SESSION_EXPIRED: "SESSION_EXPIRED";
31
+ readonly SESSION_INVALID: "SESSION_INVALID";
32
+ readonly SESSION_CREATION_FAILED: "SESSION_CREATION_FAILED";
33
+ readonly SESSION_UPDATE_FAILED: "SESSION_UPDATE_FAILED";
34
+ readonly SESSION_STORAGE_ERROR: "SESSION_STORAGE_ERROR";
35
+ readonly MAX_SESSIONS_EXCEEDED: "SESSION_MAX_EXCEEDED";
36
+ readonly INTERNAL_SERVER_ERROR: "INTERNAL_SERVER_ERROR";
37
+ readonly DATABASE_ERROR: "INTERNAL_DATABASE_ERROR";
38
+ readonly CACHE_ERROR: "INTERNAL_CACHE_ERROR";
39
+ readonly CONFIGURATION_ERROR: "INTERNAL_CONFIGURATION_ERROR";
40
+ readonly INITIALIZATION_ERROR: "INTERNAL_INITIALIZATION_ERROR";
41
+ readonly PROCESSING_ERROR: "INTERNAL_PROCESSING_ERROR";
42
+ readonly UNKNOWN_ERROR: "INTERNAL_UNKNOWN_ERROR";
43
+ readonly SERVICE_UNAVAILABLE_TRANSIENT: "SERVICE_UNAVAILABLE_TRANSIENT";
44
+ readonly CONNECTION_FAILED: "NETWORK_CONNECTION_FAILED";
45
+ readonly TIMEOUT: "NETWORK_TIMEOUT";
46
+ readonly DNS_RESOLUTION_FAILED: "NETWORK_DNS_FAILED";
47
+ readonly SSL_ERROR: "NETWORK_SSL_ERROR";
48
+ readonly PROXY_ERROR: "NETWORK_PROXY_ERROR";
49
+ readonly UPSTREAM_ERROR: "NETWORK_UPSTREAM_ERROR";
50
+ readonly INSUFFICIENT_PERMISSIONS: "PERMISSION_INSUFFICIENT";
51
+ readonly RESOURCE_NOT_FOUND: "PERMISSION_RESOURCE_NOT_FOUND";
52
+ readonly RESOURCE_ACCESS_DENIED: "PERMISSION_ACCESS_DENIED";
53
+ readonly OPERATION_NOT_ALLOWED: "PERMISSION_OPERATION_NOT_ALLOWED";
54
+ readonly PROJECT_ACCESS_DENIED: "PERMISSION_PROJECT_ACCESS_DENIED";
55
+ readonly PIXEL_ACCESS_DENIED: "PERMISSION_PIXEL_ACCESS_DENIED";
56
+ readonly FORBIDDEN: "PERMISSION_FORBIDDEN";
57
+ readonly RATE_LIMIT_EXCEEDED: "RATE_LIMIT_EXCEEDED";
58
+ readonly BURST_LIMIT_EXCEEDED: "RATE_LIMIT_BURST_EXCEEDED";
59
+ readonly DAILY_LIMIT_EXCEEDED: "RATE_LIMIT_DAILY_EXCEEDED";
60
+ readonly MONTHLY_LIMIT_EXCEEDED: "RATE_LIMIT_MONTHLY_EXCEEDED";
61
+ readonly CONCURRENT_LIMIT_EXCEEDED: "RATE_LIMIT_CONCURRENT_EXCEEDED";
62
+ readonly QUOTA_EXCEEDED: "RATE_LIMIT_QUOTA_EXCEEDED";
63
+ readonly DETECTION_FAILED: "DETECTION_FAILED";
64
+ readonly INSUFFICIENT_DATA: "DETECTION_INSUFFICIENT_DATA";
65
+ readonly PATTERN_MATCH_FAILED: "DETECTION_PATTERN_MATCH_FAILED";
66
+ readonly WASM_NOT_LOADED: "DETECTION_WASM_NOT_LOADED";
67
+ readonly WASM_EXECUTION_FAILED: "DETECTION_WASM_EXECUTION_FAILED";
68
+ readonly CONFIDENCE_BELOW_THRESHOLD: "DETECTION_CONFIDENCE_BELOW_THRESHOLD";
69
+ readonly SIGNATURE_VERIFICATION_FAILED: "DETECTION_SIGNATURE_VERIFICATION_FAILED";
70
+ readonly INVALID_REQUEST: "VALIDATION_INVALID_REQUEST";
71
+ readonly MISSING_REQUIRED_FIELD: "VALIDATION_MISSING_REQUIRED_FIELD";
72
+ readonly INVALID_FIELD_TYPE: "VALIDATION_INVALID_FIELD_TYPE";
73
+ readonly INVALID_FIELD_VALUE: "VALIDATION_INVALID_FIELD_VALUE";
74
+ readonly FIELD_TOO_LONG: "VALIDATION_FIELD_TOO_LONG";
75
+ readonly FIELD_TOO_SHORT: "VALIDATION_FIELD_TOO_SHORT";
76
+ readonly INVALID_EMAIL: "VALIDATION_INVALID_EMAIL";
77
+ readonly INVALID_URL: "VALIDATION_INVALID_URL";
78
+ readonly INVALID_UUID: "VALIDATION_INVALID_UUID";
79
+ readonly INVALID_IP_ADDRESS: "VALIDATION_INVALID_IP_ADDRESS";
80
+ readonly INVALID_USER_AGENT: "VALIDATION_INVALID_USER_AGENT";
81
+ readonly BAD_REQUEST: "VALIDATION_BAD_REQUEST";
82
+ readonly INVALID_START_DATE: "VALIDATION_INVALID_START_DATE";
83
+ readonly INVALID_END_DATE: "VALIDATION_INVALID_END_DATE";
84
+ readonly INVALID_DATE_RANGE: "VALIDATION_INVALID_DATE_RANGE";
85
+ readonly INVALID_API_KEY: "AUTH_INVALID_API_KEY";
86
+ readonly EXPIRED_API_KEY: "AUTH_EXPIRED_API_KEY";
87
+ readonly INVALID_TOKEN: "AUTH_INVALID_TOKEN";
88
+ readonly EXPIRED_TOKEN: "AUTH_EXPIRED_TOKEN";
89
+ readonly MISSING_CREDENTIALS: "AUTH_MISSING_CREDENTIALS";
90
+ readonly UNAUTHORIZED: "AUTH_UNAUTHORIZED";
91
+ readonly INVALID_PIXEL_ID: "AUTH_INVALID_PIXEL_ID";
92
+ readonly INVALID_SECRET_KEY: "AUTH_INVALID_SECRET_KEY";
93
+ };
94
+ type ErrorCode = (typeof ERROR_CODES)[keyof typeof ERROR_CODES];
95
+ declare const ERROR_MESSAGES: Record<ErrorCode, string>;
96
+ declare const ERROR_STATUS_CODES: Partial<Record<ErrorCode, number>>;
97
+
98
+ type ErrorCodeKey = keyof typeof ERROR_CODES;
99
+ type PickedErrorCodes<K extends readonly ErrorCodeKey[]> = {
100
+ readonly [P in K[number]]: (typeof ERROR_CODES)[P];
101
+ };
102
+ declare function pickErrorCodes<const K extends readonly ErrorCodeKey[]>(keys: K): PickedErrorCodes<K>;
103
+
104
+ export { ERROR_CODES, ERROR_MESSAGES, ERROR_STATUS_CODES, type ErrorCode, type ErrorCodeKey, type PickedErrorCodes, pickErrorCodes };
@@ -0,0 +1,104 @@
1
+ declare const ERROR_CODES: {
2
+ readonly LOWERCASE_INVALID_JSON: "invalid_json";
3
+ readonly LOWERCASE_VALIDATION_ERROR: "validation_error";
4
+ readonly BARE_VALIDATION_ERROR: "VALIDATION_ERROR";
5
+ readonly BARE_INTERNAL_ERROR: "INTERNAL_ERROR";
6
+ readonly POLICY_FETCH_FAILED: "POLICY_FETCH_FAILED";
7
+ readonly CONFLICT: "CONFLICT";
8
+ readonly PROJECT_NOT_FOUND: "PROJECT_NOT_FOUND";
9
+ readonly REVIEW_REQUIRED: "REVIEW_REQUIRED";
10
+ readonly LIMIT_EXCEEDED: "LIMIT_EXCEEDED";
11
+ readonly BILLING_SUSPENDED: "BILLING_SUSPENDED";
12
+ readonly BILLING_GRACE_PERIOD: "BILLING_GRACE_PERIOD";
13
+ readonly ENDPOINT_NOT_FOUND: "API_ENDPOINT_NOT_FOUND";
14
+ readonly METHOD_NOT_ALLOWED: "API_METHOD_NOT_ALLOWED";
15
+ readonly VERSION_NOT_SUPPORTED: "API_VERSION_NOT_SUPPORTED";
16
+ readonly CONTENT_TYPE_NOT_SUPPORTED: "API_CONTENT_TYPE_NOT_SUPPORTED";
17
+ readonly RESPONSE_TOO_LARGE: "API_RESPONSE_TOO_LARGE";
18
+ readonly REQUEST_TOO_LARGE: "API_REQUEST_TOO_LARGE";
19
+ readonly PIXEL_NOT_FOUND: "PIXEL_NOT_FOUND";
20
+ readonly PIXEL_DISABLED: "PIXEL_DISABLED";
21
+ readonly PIXEL_CONFIGURATION_ERROR: "PIXEL_CONFIGURATION_ERROR";
22
+ readonly PIXEL_DOMAIN_NOT_ALLOWED: "PIXEL_DOMAIN_NOT_ALLOWED";
23
+ readonly PIXEL_PATH_SKIPPED: "PIXEL_PATH_SKIPPED";
24
+ readonly PIXEL_EVENT_INVALID: "PIXEL_EVENT_INVALID";
25
+ readonly PIXEL_BATCH_TOO_LARGE: "PIXEL_BATCH_TOO_LARGE";
26
+ readonly MISSING_PIXEL_ID: "MISSING_PIXEL_ID";
27
+ readonly INVALID_EDGE_SIGNATURE: "INVALID_EDGE_SIGNATURE";
28
+ readonly DETECTION_STORAGE_FAILED: "DETECTION_STORAGE_FAILED";
29
+ readonly SESSION_NOT_FOUND: "SESSION_NOT_FOUND";
30
+ readonly SESSION_EXPIRED: "SESSION_EXPIRED";
31
+ readonly SESSION_INVALID: "SESSION_INVALID";
32
+ readonly SESSION_CREATION_FAILED: "SESSION_CREATION_FAILED";
33
+ readonly SESSION_UPDATE_FAILED: "SESSION_UPDATE_FAILED";
34
+ readonly SESSION_STORAGE_ERROR: "SESSION_STORAGE_ERROR";
35
+ readonly MAX_SESSIONS_EXCEEDED: "SESSION_MAX_EXCEEDED";
36
+ readonly INTERNAL_SERVER_ERROR: "INTERNAL_SERVER_ERROR";
37
+ readonly DATABASE_ERROR: "INTERNAL_DATABASE_ERROR";
38
+ readonly CACHE_ERROR: "INTERNAL_CACHE_ERROR";
39
+ readonly CONFIGURATION_ERROR: "INTERNAL_CONFIGURATION_ERROR";
40
+ readonly INITIALIZATION_ERROR: "INTERNAL_INITIALIZATION_ERROR";
41
+ readonly PROCESSING_ERROR: "INTERNAL_PROCESSING_ERROR";
42
+ readonly UNKNOWN_ERROR: "INTERNAL_UNKNOWN_ERROR";
43
+ readonly SERVICE_UNAVAILABLE_TRANSIENT: "SERVICE_UNAVAILABLE_TRANSIENT";
44
+ readonly CONNECTION_FAILED: "NETWORK_CONNECTION_FAILED";
45
+ readonly TIMEOUT: "NETWORK_TIMEOUT";
46
+ readonly DNS_RESOLUTION_FAILED: "NETWORK_DNS_FAILED";
47
+ readonly SSL_ERROR: "NETWORK_SSL_ERROR";
48
+ readonly PROXY_ERROR: "NETWORK_PROXY_ERROR";
49
+ readonly UPSTREAM_ERROR: "NETWORK_UPSTREAM_ERROR";
50
+ readonly INSUFFICIENT_PERMISSIONS: "PERMISSION_INSUFFICIENT";
51
+ readonly RESOURCE_NOT_FOUND: "PERMISSION_RESOURCE_NOT_FOUND";
52
+ readonly RESOURCE_ACCESS_DENIED: "PERMISSION_ACCESS_DENIED";
53
+ readonly OPERATION_NOT_ALLOWED: "PERMISSION_OPERATION_NOT_ALLOWED";
54
+ readonly PROJECT_ACCESS_DENIED: "PERMISSION_PROJECT_ACCESS_DENIED";
55
+ readonly PIXEL_ACCESS_DENIED: "PERMISSION_PIXEL_ACCESS_DENIED";
56
+ readonly FORBIDDEN: "PERMISSION_FORBIDDEN";
57
+ readonly RATE_LIMIT_EXCEEDED: "RATE_LIMIT_EXCEEDED";
58
+ readonly BURST_LIMIT_EXCEEDED: "RATE_LIMIT_BURST_EXCEEDED";
59
+ readonly DAILY_LIMIT_EXCEEDED: "RATE_LIMIT_DAILY_EXCEEDED";
60
+ readonly MONTHLY_LIMIT_EXCEEDED: "RATE_LIMIT_MONTHLY_EXCEEDED";
61
+ readonly CONCURRENT_LIMIT_EXCEEDED: "RATE_LIMIT_CONCURRENT_EXCEEDED";
62
+ readonly QUOTA_EXCEEDED: "RATE_LIMIT_QUOTA_EXCEEDED";
63
+ readonly DETECTION_FAILED: "DETECTION_FAILED";
64
+ readonly INSUFFICIENT_DATA: "DETECTION_INSUFFICIENT_DATA";
65
+ readonly PATTERN_MATCH_FAILED: "DETECTION_PATTERN_MATCH_FAILED";
66
+ readonly WASM_NOT_LOADED: "DETECTION_WASM_NOT_LOADED";
67
+ readonly WASM_EXECUTION_FAILED: "DETECTION_WASM_EXECUTION_FAILED";
68
+ readonly CONFIDENCE_BELOW_THRESHOLD: "DETECTION_CONFIDENCE_BELOW_THRESHOLD";
69
+ readonly SIGNATURE_VERIFICATION_FAILED: "DETECTION_SIGNATURE_VERIFICATION_FAILED";
70
+ readonly INVALID_REQUEST: "VALIDATION_INVALID_REQUEST";
71
+ readonly MISSING_REQUIRED_FIELD: "VALIDATION_MISSING_REQUIRED_FIELD";
72
+ readonly INVALID_FIELD_TYPE: "VALIDATION_INVALID_FIELD_TYPE";
73
+ readonly INVALID_FIELD_VALUE: "VALIDATION_INVALID_FIELD_VALUE";
74
+ readonly FIELD_TOO_LONG: "VALIDATION_FIELD_TOO_LONG";
75
+ readonly FIELD_TOO_SHORT: "VALIDATION_FIELD_TOO_SHORT";
76
+ readonly INVALID_EMAIL: "VALIDATION_INVALID_EMAIL";
77
+ readonly INVALID_URL: "VALIDATION_INVALID_URL";
78
+ readonly INVALID_UUID: "VALIDATION_INVALID_UUID";
79
+ readonly INVALID_IP_ADDRESS: "VALIDATION_INVALID_IP_ADDRESS";
80
+ readonly INVALID_USER_AGENT: "VALIDATION_INVALID_USER_AGENT";
81
+ readonly BAD_REQUEST: "VALIDATION_BAD_REQUEST";
82
+ readonly INVALID_START_DATE: "VALIDATION_INVALID_START_DATE";
83
+ readonly INVALID_END_DATE: "VALIDATION_INVALID_END_DATE";
84
+ readonly INVALID_DATE_RANGE: "VALIDATION_INVALID_DATE_RANGE";
85
+ readonly INVALID_API_KEY: "AUTH_INVALID_API_KEY";
86
+ readonly EXPIRED_API_KEY: "AUTH_EXPIRED_API_KEY";
87
+ readonly INVALID_TOKEN: "AUTH_INVALID_TOKEN";
88
+ readonly EXPIRED_TOKEN: "AUTH_EXPIRED_TOKEN";
89
+ readonly MISSING_CREDENTIALS: "AUTH_MISSING_CREDENTIALS";
90
+ readonly UNAUTHORIZED: "AUTH_UNAUTHORIZED";
91
+ readonly INVALID_PIXEL_ID: "AUTH_INVALID_PIXEL_ID";
92
+ readonly INVALID_SECRET_KEY: "AUTH_INVALID_SECRET_KEY";
93
+ };
94
+ type ErrorCode = (typeof ERROR_CODES)[keyof typeof ERROR_CODES];
95
+ declare const ERROR_MESSAGES: Record<ErrorCode, string>;
96
+ declare const ERROR_STATUS_CODES: Partial<Record<ErrorCode, number>>;
97
+
98
+ type ErrorCodeKey = keyof typeof ERROR_CODES;
99
+ type PickedErrorCodes<K extends readonly ErrorCodeKey[]> = {
100
+ readonly [P in K[number]]: (typeof ERROR_CODES)[P];
101
+ };
102
+ declare function pickErrorCodes<const K extends readonly ErrorCodeKey[]>(keys: K): PickedErrorCodes<K>;
103
+
104
+ export { ERROR_CODES, ERROR_MESSAGES, ERROR_STATUS_CODES, type ErrorCode, type ErrorCodeKey, type PickedErrorCodes, pickErrorCodes };