@attestry/sdk 0.6.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.
Files changed (99) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +1269 -0
  3. package/dist/client.d.ts +58 -0
  4. package/dist/client.d.ts.map +1 -0
  5. package/dist/client.js +74 -0
  6. package/dist/client.js.map +1 -0
  7. package/dist/constants.d.ts +7 -0
  8. package/dist/constants.d.ts.map +1 -0
  9. package/dist/constants.js +43 -0
  10. package/dist/constants.js.map +1 -0
  11. package/dist/errors.d.ts +16 -0
  12. package/dist/errors.d.ts.map +1 -0
  13. package/dist/errors.js +41 -0
  14. package/dist/errors.js.map +1 -0
  15. package/dist/index.d.ts +17 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +20 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/lines-parser.d.ts +50 -0
  20. package/dist/lines-parser.d.ts.map +1 -0
  21. package/dist/lines-parser.js +211 -0
  22. package/dist/lines-parser.js.map +1 -0
  23. package/dist/ndjson-parser.d.ts +57 -0
  24. package/dist/ndjson-parser.d.ts.map +1 -0
  25. package/dist/ndjson-parser.js +245 -0
  26. package/dist/ndjson-parser.js.map +1 -0
  27. package/dist/resources/abac-policies.d.ts +1034 -0
  28. package/dist/resources/abac-policies.d.ts.map +1 -0
  29. package/dist/resources/abac-policies.js +1519 -0
  30. package/dist/resources/abac-policies.js.map +1 -0
  31. package/dist/resources/audit-log.d.ts +588 -0
  32. package/dist/resources/audit-log.d.ts.map +1 -0
  33. package/dist/resources/audit-log.js +629 -0
  34. package/dist/resources/audit-log.js.map +1 -0
  35. package/dist/resources/batch.d.ts +845 -0
  36. package/dist/resources/batch.d.ts.map +1 -0
  37. package/dist/resources/batch.js +1074 -0
  38. package/dist/resources/batch.js.map +1 -0
  39. package/dist/resources/chat.d.ts +151 -0
  40. package/dist/resources/chat.d.ts.map +1 -0
  41. package/dist/resources/chat.js +124 -0
  42. package/dist/resources/chat.js.map +1 -0
  43. package/dist/resources/check.d.ts +348 -0
  44. package/dist/resources/check.d.ts.map +1 -0
  45. package/dist/resources/check.js +543 -0
  46. package/dist/resources/check.js.map +1 -0
  47. package/dist/resources/compliance-check.d.ts +330 -0
  48. package/dist/resources/compliance-check.d.ts.map +1 -0
  49. package/dist/resources/compliance-check.js +402 -0
  50. package/dist/resources/compliance-check.js.map +1 -0
  51. package/dist/resources/decisions.d.ts +1208 -0
  52. package/dist/resources/decisions.d.ts.map +1 -0
  53. package/dist/resources/decisions.js +1362 -0
  54. package/dist/resources/decisions.js.map +1 -0
  55. package/dist/resources/evidence-pack.d.ts +1080 -0
  56. package/dist/resources/evidence-pack.d.ts.map +1 -0
  57. package/dist/resources/evidence-pack.js +1789 -0
  58. package/dist/resources/evidence-pack.js.map +1 -0
  59. package/dist/resources/gate.d.ts +613 -0
  60. package/dist/resources/gate.d.ts.map +1 -0
  61. package/dist/resources/gate.js +737 -0
  62. package/dist/resources/gate.js.map +1 -0
  63. package/dist/resources/incidents.d.ts +136 -0
  64. package/dist/resources/incidents.d.ts.map +1 -0
  65. package/dist/resources/incidents.js +229 -0
  66. package/dist/resources/incidents.js.map +1 -0
  67. package/dist/resources/regulatory-changes.d.ts +307 -0
  68. package/dist/resources/regulatory-changes.d.ts.map +1 -0
  69. package/dist/resources/regulatory-changes.js +365 -0
  70. package/dist/resources/regulatory-changes.js.map +1 -0
  71. package/dist/resources/safe-input-read.d.ts +21 -0
  72. package/dist/resources/safe-input-read.d.ts.map +1 -0
  73. package/dist/resources/safe-input-read.js +57 -0
  74. package/dist/resources/safe-input-read.js.map +1 -0
  75. package/dist/resources/ship-gate.d.ts +475 -0
  76. package/dist/resources/ship-gate.d.ts.map +1 -0
  77. package/dist/resources/ship-gate.js +727 -0
  78. package/dist/resources/ship-gate.js.map +1 -0
  79. package/dist/resources/vision.d.ts +540 -0
  80. package/dist/resources/vision.d.ts.map +1 -0
  81. package/dist/resources/vision.js +1036 -0
  82. package/dist/resources/vision.js.map +1 -0
  83. package/dist/retry.d.ts +103 -0
  84. package/dist/retry.d.ts.map +1 -0
  85. package/dist/retry.js +224 -0
  86. package/dist/retry.js.map +1 -0
  87. package/dist/sse-parser.d.ts +64 -0
  88. package/dist/sse-parser.d.ts.map +1 -0
  89. package/dist/sse-parser.js +271 -0
  90. package/dist/sse-parser.js.map +1 -0
  91. package/dist/transport.d.ts +142 -0
  92. package/dist/transport.d.ts.map +1 -0
  93. package/dist/transport.js +455 -0
  94. package/dist/transport.js.map +1 -0
  95. package/dist/types.d.ts +61 -0
  96. package/dist/types.d.ts.map +1 -0
  97. package/dist/types.js +3 -0
  98. package/dist/types.js.map +1 -0
  99. package/package.json +44 -0
@@ -0,0 +1,58 @@
1
+ import { AbacPoliciesResource } from "./resources/abac-policies.js";
2
+ import { AuditLogResource } from "./resources/audit-log.js";
3
+ import { BatchResource } from "./resources/batch.js";
4
+ import { ChatResource } from "./resources/chat.js";
5
+ import { CheckResource } from "./resources/check.js";
6
+ import { ComplianceCheckResource } from "./resources/compliance-check.js";
7
+ import { DecisionsResource } from "./resources/decisions.js";
8
+ import { EvidencePackResource } from "./resources/evidence-pack.js";
9
+ import { GateResource } from "./resources/gate.js";
10
+ import { IncidentsResource } from "./resources/incidents.js";
11
+ import { RegulatoryChangesResource } from "./resources/regulatory-changes.js";
12
+ import { ShipGateResource } from "./resources/ship-gate.js";
13
+ import { VisionResource } from "./resources/vision.js";
14
+ import type { AttestryClientOptions, RequestOptions } from "./types.js";
15
+ interface InternalRequestArgs {
16
+ method: "GET" | "POST" | "PATCH" | "DELETE";
17
+ path: string;
18
+ body?: unknown;
19
+ query?: Record<string, string | number | boolean | undefined | null>;
20
+ options?: RequestOptions;
21
+ }
22
+ export declare class AttestryClient {
23
+ readonly incidents: IncidentsResource;
24
+ readonly decisions: DecisionsResource;
25
+ readonly chat: ChatResource;
26
+ readonly auditLog: AuditLogResource;
27
+ readonly regulatoryChanges: RegulatoryChangesResource;
28
+ readonly complianceCheck: ComplianceCheckResource;
29
+ readonly check: CheckResource;
30
+ readonly gate: GateResource;
31
+ readonly batch: BatchResource;
32
+ readonly shipGate: ShipGateResource;
33
+ readonly abacPolicies: AbacPoliciesResource;
34
+ readonly evidencePack: EvidencePackResource;
35
+ readonly vision: VisionResource;
36
+ private readonly _config;
37
+ constructor(options: AttestryClientOptions);
38
+ /** Internal — resources call this to dispatch HTTP requests. */
39
+ _request<T>(args: InternalRequestArgs): Promise<T>;
40
+ /**
41
+ * Internal — resources call this to dispatch streaming requests (SSE
42
+ * or NDJSON). Returns the un-consumed `Response` so the caller can
43
+ * attach the appropriate parser to `response.body`. Non-2xx responses
44
+ * throw `AttestryAPIError` exactly like `_request`. See `streamRequest`
45
+ * in transport for the full contract — including the
46
+ * `expectedContentType` parameter that drives both the `Accept:`
47
+ * request header and the response content-type fail-fast guard.
48
+ */
49
+ _streamRequest(args: {
50
+ path: string;
51
+ query?: Record<string, string | number | boolean | undefined | null>;
52
+ headers?: Record<string, string>;
53
+ options?: RequestOptions;
54
+ expectedContentType?: string;
55
+ }): Promise<Response>;
56
+ }
57
+ export {};
58
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OA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AAE,cAAc,CAAC;IAGhC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAyC;gBAErD,OAAO,EAAE,qBAAqB;IAiB1C,gEAAgE;IAChE,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,CAAC,CAAC;IAIlD;;;;;;;;OAQG;IACH,cAAc,CAAC,IAAI,EAAE;QACnB,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,IAAI,CAAC,CAAC;QACrE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACjC,OAAO,CAAC,EAAE,cAAc,CAAC;QACzB,mBAAmB,CAAC,EAAE,MAAM,CAAC;KAC9B,GAAG,OAAO,CAAC,QAAQ,CAAC;CAGtB"}
package/dist/client.js ADDED
@@ -0,0 +1,74 @@
1
+ // ─── AttestryClient ─────────────────────────────────────────────────────────
2
+ //
3
+ // The single entry point. Construct with `new AttestryClient({ apiKey })`,
4
+ // then access resource sub-clients on `client.<resource>` (Stripe-style).
5
+ //
6
+ // Resources call back into the client via `_request<T>(args)`. The
7
+ // underscore prefix signals "internal — don't call from consumer code";
8
+ // it's not literally private because TypeScript class-private fields
9
+ // would also hide it from the resource modules in this codebase.
10
+ import { AbacPoliciesResource } from "./resources/abac-policies.js";
11
+ import { AuditLogResource } from "./resources/audit-log.js";
12
+ import { BatchResource } from "./resources/batch.js";
13
+ import { ChatResource } from "./resources/chat.js";
14
+ import { CheckResource } from "./resources/check.js";
15
+ import { ComplianceCheckResource } from "./resources/compliance-check.js";
16
+ import { DecisionsResource } from "./resources/decisions.js";
17
+ import { EvidencePackResource } from "./resources/evidence-pack.js";
18
+ import { GateResource } from "./resources/gate.js";
19
+ import { IncidentsResource } from "./resources/incidents.js";
20
+ import { RegulatoryChangesResource } from "./resources/regulatory-changes.js";
21
+ import { ShipGateResource } from "./resources/ship-gate.js";
22
+ import { VisionResource } from "./resources/vision.js";
23
+ import { request as transportRequest, resolveClientConfig, streamRequest as transportStreamRequest, } from "./transport.js";
24
+ export class AttestryClient {
25
+ incidents;
26
+ decisions;
27
+ chat;
28
+ auditLog;
29
+ regulatoryChanges;
30
+ complianceCheck;
31
+ check;
32
+ gate;
33
+ batch;
34
+ shipGate;
35
+ abacPolicies;
36
+ // 2.0 flagship resources (the ≥0.6.0 union — W1 deliverable 5)
37
+ evidencePack;
38
+ vision;
39
+ // Frozen at construction time; resources read this through `_request`.
40
+ _config;
41
+ constructor(options) {
42
+ this._config = resolveClientConfig(options);
43
+ this.incidents = new IncidentsResource(this);
44
+ this.decisions = new DecisionsResource(this);
45
+ this.chat = new ChatResource(this);
46
+ this.auditLog = new AuditLogResource(this);
47
+ this.regulatoryChanges = new RegulatoryChangesResource(this);
48
+ this.complianceCheck = new ComplianceCheckResource(this);
49
+ this.check = new CheckResource(this);
50
+ this.gate = new GateResource(this);
51
+ this.batch = new BatchResource(this);
52
+ this.shipGate = new ShipGateResource(this);
53
+ this.abacPolicies = new AbacPoliciesResource(this);
54
+ this.evidencePack = new EvidencePackResource(this);
55
+ this.vision = new VisionResource(this);
56
+ }
57
+ /** Internal — resources call this to dispatch HTTP requests. */
58
+ _request(args) {
59
+ return transportRequest({ config: this._config, ...args });
60
+ }
61
+ /**
62
+ * Internal — resources call this to dispatch streaming requests (SSE
63
+ * or NDJSON). Returns the un-consumed `Response` so the caller can
64
+ * attach the appropriate parser to `response.body`. Non-2xx responses
65
+ * throw `AttestryAPIError` exactly like `_request`. See `streamRequest`
66
+ * in transport for the full contract — including the
67
+ * `expectedContentType` parameter that drives both the `Accept:`
68
+ * request header and the response content-type fail-fast guard.
69
+ */
70
+ _streamRequest(args) {
71
+ return transportStreamRequest({ config: this._config, ...args });
72
+ }
73
+ }
74
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot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ACC,OAAO,sBAAsB,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;IACnE,CAAC;CACF"}
@@ -0,0 +1,7 @@
1
+ export declare const INCIDENT_TYPES: readonly ["prompt_injection", "jailbreak", "tool_misuse", "compliance_violation", "data_leak", "hallucination", "bias_detected", "safety_bypass", "other"];
2
+ export type IncidentType = (typeof INCIDENT_TYPES)[number];
3
+ export declare const SEVERITIES: readonly ["low", "medium", "high", "critical"];
4
+ export type Severity = (typeof SEVERITIES)[number];
5
+ export declare const FRAMEWORK_CODES: readonly ["eu_ai_act", "colorado_ai_act", "nyc_local_law_144", "nist_ai_rmf", "iso_42001", "soc_2", "hipaa", "gdpr"];
6
+ export type FrameworkCode = (typeof FRAMEWORK_CODES)[number];
7
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,cAAc,4JAUhB,CAAC;AAEZ,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAE3D,eAAO,MAAM,UAAU,gDAKZ,CAAC;AAEZ,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnD,eAAO,MAAM,eAAe,sHASjB,CAAC;AAEZ,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC"}
@@ -0,0 +1,43 @@
1
+ // ─── Public enums mirrored from the kernel's incident schema ────────────────
2
+ //
3
+ // Duplicated here on purpose: the SDK is a public API and must not import
4
+ // from the kernel's internal `src/lib/incidents/schema.ts`. Drift is caught
5
+ // by a server-side test in the kernel that reads this file and asserts
6
+ // the arrays match.
7
+ //
8
+ // **Object.freeze (P1 hardening)**: each export is runtime-frozen so a
9
+ // hostile or buggy npm dependency cannot mutate the array between SDK
10
+ // import and method call. Without freeze, a `(SEVERITIES as
11
+ // any).push("evil")` from a misbehaving dependency would bypass the
12
+ // SDK's `.includes()` validation on closed-enum input fields. The
13
+ // drift extractor in `src/lib/incidents/__tests__/sdk-drift.test.ts`
14
+ // accepts both `as const` forms (bare and `Object.freeze`-wrapped) so
15
+ // kernel-side route-local consts continue to extract cleanly.
16
+ export const INCIDENT_TYPES = Object.freeze([
17
+ "prompt_injection",
18
+ "jailbreak",
19
+ "tool_misuse",
20
+ "compliance_violation",
21
+ "data_leak",
22
+ "hallucination",
23
+ "bias_detected",
24
+ "safety_bypass",
25
+ "other",
26
+ ]);
27
+ export const SEVERITIES = Object.freeze([
28
+ "low",
29
+ "medium",
30
+ "high",
31
+ "critical",
32
+ ]);
33
+ export const FRAMEWORK_CODES = Object.freeze([
34
+ "eu_ai_act",
35
+ "colorado_ai_act",
36
+ "nyc_local_law_144",
37
+ "nist_ai_rmf",
38
+ "iso_42001",
39
+ "soc_2",
40
+ "hipaa",
41
+ "gdpr",
42
+ ]);
43
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,EAAE;AACF,0EAA0E;AAC1E,4EAA4E;AAC5E,uEAAuE;AACvE,oBAAoB;AACpB,EAAE;AACF,uEAAuE;AACvE,sEAAsE;AACtE,4DAA4D;AAC5D,oEAAoE;AACpE,kEAAkE;AAClE,qEAAqE;AACrE,sEAAsE;AACtE,8DAA8D;AAE9D,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC;IAC1C,kBAAkB;IAClB,WAAW;IACX,aAAa;IACb,sBAAsB;IACtB,WAAW;IACX,eAAe;IACf,eAAe;IACf,eAAe;IACf,OAAO;CACC,CAAC,CAAC;AAIZ,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC;IACtC,KAAK;IACL,QAAQ;IACR,MAAM;IACN,UAAU;CACF,CAAC,CAAC;AAIZ,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC;IAC3C,WAAW;IACX,iBAAiB;IACjB,mBAAmB;IACnB,aAAa;IACb,WAAW;IACX,OAAO;IACP,OAAO;IACP,MAAM;CACE,CAAC,CAAC"}
@@ -0,0 +1,16 @@
1
+ export declare class AttestryError extends Error {
2
+ constructor(message: string, options?: {
3
+ cause?: unknown;
4
+ });
5
+ }
6
+ /**
7
+ * Thrown when the API returns a non-2xx HTTP response. Always carries the
8
+ * `status` code; `details` holds the parsed response body (when JSON) or
9
+ * `null` (when the body wasn't valid JSON or was empty).
10
+ */
11
+ export declare class AttestryAPIError extends AttestryError {
12
+ readonly status: number;
13
+ readonly details: unknown;
14
+ constructor(message: string, status: number, details?: unknown);
15
+ }
16
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAaA,qBAAa,aAAc,SAAQ,KAAK;gBAC1B,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAU3D;AAED;;;;GAIG;AACH,qBAAa,gBAAiB,SAAQ,aAAa;IACjD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;gBAEd,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,OAAc;CAOrE"}
package/dist/errors.js ADDED
@@ -0,0 +1,41 @@
1
+ // ─── SDK error hierarchy ────────────────────────────────────────────────────
2
+ //
3
+ // Two error classes:
4
+ // - `AttestryError` — non-API errors (network failure, invalid client
5
+ // configuration, request timeout). Always indicates the request did
6
+ // not reach the API.
7
+ // - `AttestryAPIError` — the API returned a non-2xx response. Carries
8
+ // `status` (HTTP status code), normalized `code` from the response
9
+ // body when present, and the raw response shape under `details`.
10
+ //
11
+ // Both extend the standard `Error` so consumer code can `instanceof` test
12
+ // each layer separately.
13
+ export class AttestryError extends Error {
14
+ constructor(message, options) {
15
+ super(message);
16
+ this.name = "AttestryError";
17
+ if (options?.cause !== undefined) {
18
+ // Preserve native ES2022 cause chain when available.
19
+ this.cause = options.cause;
20
+ }
21
+ // Restore prototype chain across compile targets that drop it.
22
+ Object.setPrototypeOf(this, new.target.prototype);
23
+ }
24
+ }
25
+ /**
26
+ * Thrown when the API returns a non-2xx HTTP response. Always carries the
27
+ * `status` code; `details` holds the parsed response body (when JSON) or
28
+ * `null` (when the body wasn't valid JSON or was empty).
29
+ */
30
+ export class AttestryAPIError extends AttestryError {
31
+ status;
32
+ details;
33
+ constructor(message, status, details = null) {
34
+ super(message);
35
+ this.name = "AttestryAPIError";
36
+ this.status = status;
37
+ this.details = details;
38
+ Object.setPrototypeOf(this, new.target.prototype);
39
+ }
40
+ }
41
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,EAAE;AACF,qBAAqB;AACrB,wEAAwE;AACxE,wEAAwE;AACxE,yBAAyB;AACzB,wEAAwE;AACxE,uEAAuE;AACvE,qEAAqE;AACrE,EAAE;AACF,0EAA0E;AAC1E,yBAAyB;AAEzB,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC,YAAY,OAAe,EAAE,OAA6B;QACxD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,OAAO,EAAE,KAAK,KAAK,SAAS,EAAE,CAAC;YACjC,qDAAqD;YACpD,IAAoC,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC9D,CAAC;QACD,+DAA+D;QAC/D,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAO,gBAAiB,SAAQ,aAAa;IACxC,MAAM,CAAS;IACf,OAAO,CAAU;IAE1B,YAAY,OAAe,EAAE,MAAc,EAAE,UAAmB,IAAI;QAClE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACF"}
@@ -0,0 +1,17 @@
1
+ export { AttestryClient } from "./client.js";
2
+ export { AttestryError, AttestryAPIError } from "./errors.js";
3
+ export { INCIDENT_TYPES, SEVERITIES, FRAMEWORK_CODES, type IncidentType, type Severity, type FrameworkCode, } from "./constants.js";
4
+ export type { AttestryClientOptions, FetchLike, RequestOptions, } from "./types.js";
5
+ export { DEFAULT_RETRY_OPTIONS, type RetryOptions, } from "./retry.js";
6
+ export { IncidentsResource, type Incident, type IncidentReportInput, type IncidentListInput, type IncidentListResponse, type IncidentPatchInput, type IncidentSearchInput, type IncidentSearchResponse, type IncidentCluster, type IncidentClusterSeverityCounts, } from "./resources/incidents.js";
7
+ export { DecisionsResource, DECISION_STREAM_EVENT_TYPES, type DecisionRecord, type DecisionIngestInput, type FrameworkClaim, type ToolInvocation, type DelegationEntry, type ZkProof, type DecisionBulkInput, type BulkInsertedSummary, type BulkFailedSummary, type BulkIngestResult, type DecisionListItem, type DecisionsListInput, type DecisionsListResponse, type DecisionStreamEvent, type DecisionStreamEventType, type DecisionsStreamInput, type DecisionsExportInput, type DecisionExportRecord, type DecisionExportTrailer, type DecisionExportFrame, type ChainVerificationResult, } from "./resources/decisions.js";
8
+ export { ChatResource, CHAT_MESSAGE_ROLES, type ChatMessage, type ChatMessageRole, type ChatContext, type ChatContextGap, type ChatSendInput, type ChatSendResponse, type ChatStreamChunk, } from "./resources/chat.js";
9
+ export { AuditLogResource, AUDIT_LOG_EXPORT_FORMATS, type AuditLogExportFormat, type AuditLogRecord, type AuditLogExportInput, type AuditChainVerificationResult, } from "./resources/audit-log.js";
10
+ export { RegulatoryChangesResource, REGULATORY_CHANGE_SEVERITIES, REGULATORY_CHANGE_STATUSES, type RegulatoryChangeSeverity, type RegulatoryChangeStatus, type RegulatoryChange, type RegulatoryChangesListInput, } from "./resources/regulatory-changes.js";
11
+ export { ComplianceCheckResource, type ComplianceCheckInput, type ComplianceCheckResult, type ComplianceCheckResponse, type ComplianceCheckFrameworkCoverage, } from "./resources/compliance-check.js";
12
+ export { CheckResource, type CheckInput, type CheckResponse, } from "./resources/check.js";
13
+ export { GateResource, type GateInput, type GateGap, type GateResponse, } from "./resources/gate.js";
14
+ export { BatchResource, BATCH_JOB_TYPES, BATCH_JOB_STATUSES, type BatchJobType, type BatchJobStatusValue, type BatchSystemResult, type BatchConfig, type BatchSubmitInput, type BatchSubmitResponse, type BatchJobStatus, } from "./resources/batch.js";
15
+ export { ShipGateResource, type ShipGateInput, type ShipGateCheckResponse, type ShipGateReasonCode, type ShipGateState, } from "./resources/ship-gate.js";
16
+ export { AbacPoliciesResource, ABAC_POLICY_RESOURCES, ABAC_POLICY_ACTIONS, ABAC_POLICY_EFFECTS, type AbacPolicy, type AbacPoliciesListResponse, type AbacPolicyCreateInput, type AbacPolicyUpdateInput, type AbacPolicyEffect, type AbacPolicyResource, type AbacPolicyAction, type AbacAttrRoot, type AbacAttrPath, type AbacAttrValue, type AbacLeafCondition, type AbacCompoundCondition, type AbacCondition, } from "./resources/abac-policies.js";
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,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B,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,aAAa,GACnB,MAAM,8BAA8B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ // ─── Public API ─────────────────────────────────────────────────────────────
2
+ //
3
+ // Entry point of `@attestry/sdk`. Anything not re-exported here is internal
4
+ // and not part of the public contract.
5
+ export { AttestryClient } from "./client.js";
6
+ export { AttestryError, AttestryAPIError } from "./errors.js";
7
+ export { INCIDENT_TYPES, SEVERITIES, FRAMEWORK_CODES, } from "./constants.js";
8
+ export { DEFAULT_RETRY_OPTIONS, } from "./retry.js";
9
+ export { IncidentsResource, } from "./resources/incidents.js";
10
+ export { DecisionsResource, DECISION_STREAM_EVENT_TYPES, } from "./resources/decisions.js";
11
+ export { ChatResource, CHAT_MESSAGE_ROLES, } from "./resources/chat.js";
12
+ export { AuditLogResource, AUDIT_LOG_EXPORT_FORMATS, } from "./resources/audit-log.js";
13
+ export { RegulatoryChangesResource, REGULATORY_CHANGE_SEVERITIES, REGULATORY_CHANGE_STATUSES, } from "./resources/regulatory-changes.js";
14
+ export { ComplianceCheckResource, } from "./resources/compliance-check.js";
15
+ export { CheckResource, } from "./resources/check.js";
16
+ export { GateResource, } from "./resources/gate.js";
17
+ export { BatchResource, BATCH_JOB_TYPES, BATCH_JOB_STATUSES, } from "./resources/batch.js";
18
+ export { ShipGateResource, } from "./resources/ship-gate.js";
19
+ export { AbacPoliciesResource, ABAC_POLICY_RESOURCES, ABAC_POLICY_ACTIONS, ABAC_POLICY_EFFECTS, } from "./resources/abac-policies.js";
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,EAAE;AACF,4EAA4E;AAC5E,uCAAuC;AAEvC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE9D,OAAO,EACL,cAAc,EACd,UAAU,EACV,eAAe,GAIhB,MAAM,gBAAgB,CAAC;AAQxB,OAAO,EACL,qBAAqB,GAEtB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,iBAAiB,GAUlB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,iBAAiB,EACjB,2BAA2B,GAsB5B,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,YAAY,EACZ,kBAAkB,GAQnB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,gBAAgB,EAChB,wBAAwB,GAKzB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,yBAAyB,EACzB,4BAA4B,EAC5B,0BAA0B,GAK3B,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EACL,uBAAuB,GAKxB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EACL,aAAa,GAGd,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,YAAY,GAIb,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,aAAa,EACb,eAAe,EACf,kBAAkB,GAQnB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,gBAAgB,GAKjB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,mBAAmB,EACnB,mBAAmB,GAcpB,MAAM,8BAA8B,CAAC"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Async generator: reads from a stream of UTF-8-encoded line-oriented
3
+ * bytes and yields each `\n`-delimited line as a raw string. Ends when
4
+ * the underlying reader signals `done`. Defensive: a caller that breaks
5
+ * early out of the for-await loop leaves the reader open — call
6
+ * `reader.cancel()` from your finally block (or use `parseLinesResponse`
7
+ * below which handles cleanup automatically).
8
+ *
9
+ * Mid-stream read errors are wrapped as
10
+ * `AttestryError("network error during stream: <reason>")` with the
11
+ * original error chained as `cause`. AbortError-shaped rejects (caller
12
+ * cancelled the underlying signal) are wrapped as
13
+ * `AttestryError("request aborted by caller")` for symmetry with the
14
+ * pre-fetch abort surface and with the ndjson-parser. The resource layer
15
+ * can rely on these wrappings — `runAuditLogExport`'s loop passes any
16
+ * `AttestryError` through verbatim.
17
+ *
18
+ * @throws AttestryError if the residual line buffer exceeds `maxLineBytes`
19
+ * (defense against unbounded-line DoS), OR the underlying reader
20
+ * rejects mid-iteration (network drop, abort).
21
+ */
22
+ export declare function parseLines(reader: ReadableStreamDefaultReader<Uint8Array>, options?: {
23
+ maxLineBytes?: number;
24
+ }): AsyncGenerator<string, void, unknown>;
25
+ /**
26
+ * Convenience wrapper around `parseLines` that accepts a `Response`,
27
+ * derives the reader, and ALWAYS calls `reader.cancel()` in a `finally`
28
+ * block — including when a caller breaks out of the for-await loop
29
+ * early. Without this, an early `break` leaks the underlying connection.
30
+ *
31
+ * Resources should call this rather than `parseLines` directly.
32
+ *
33
+ * Symmetric to `parseNDJSONResponse` and `parseSSEResponse`.
34
+ */
35
+ export declare function parseLinesResponse(response: Response, options?: {
36
+ maxLineBytes?: number;
37
+ }): AsyncGenerator<string, void, unknown>;
38
+ /**
39
+ * Trim a single trailing `\r` (CR). Defensive: line-oriented streaming
40
+ * formats mandate LF only, but a Windows-tooling artifact could leave
41
+ * a CR before the LF. Trimming exactly one CR keeps the parser permissive
42
+ * without treating CR alone as a line separator.
43
+ */
44
+ declare function stripTrailingCR(s: string): string;
45
+ export declare const __test__: {
46
+ DEFAULT_MAX_LINE_BYTES: number;
47
+ stripTrailingCR: typeof stripTrailingCR;
48
+ };
49
+ export {};
50
+ //# sourceMappingURL=lines-parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lines-parser.d.ts","sourceRoot":"","sources":["../src/lines-parser.ts"],"names":[],"mappings":"AA8CA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAuB,UAAU,CAC/B,MAAM,EAAE,2BAA2B,CAAC,UAAU,CAAC,EAC/C,OAAO,GAAE;IAAE,YAAY,CAAC,EAAE,MAAM,CAAA;CAAO,GACtC,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CA2FvC;AAED;;;;;;;;;GASG;AACH,wBAAuB,kBAAkB,CACvC,QAAQ,EAAE,QAAQ,EAClB,OAAO,GAAE;IAAE,YAAY,CAAC,EAAE,MAAM,CAAA;CAAO,GACtC,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAmBvC;AAID;;;;;GAKG;AACH,iBAAS,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE1C;AAmBD,eAAO,MAAM,QAAQ;;;CAGpB,CAAC"}
@@ -0,0 +1,211 @@
1
+ // ─── Lines parser ───────────────────────────────────────────────────────────
2
+ //
3
+ // Parses a stream of UTF-8-encoded text bytes into newline-delimited line
4
+ // strings. Symmetric to `ndjson-parser.ts` but does NOT JSON.parse — yields
5
+ // each line raw. Used by streaming endpoints whose payload is line-oriented
6
+ // but NOT JSON (today: `audit-log.export?format=cef`; future: any other
7
+ // text/plain-line format such as CSV or syslog).
8
+ //
9
+ // Subset implemented (mirrors the strict ndjson subset for symmetry):
10
+ // - One value per line, separated by U+000A LINE FEED (`\n`).
11
+ // - UTF-8 decoded with `{stream: true}` so multibyte chars split across
12
+ // reads recombine correctly.
13
+ // - Leading BOM (U+FEFF) stripped once at stream start.
14
+ // - Blank lines silently skipped (lenient — the kernel's CEF path doesn't
15
+ // emit them but defensive parsers should tolerate whitespace artifacts).
16
+ // - Final unterminated line (no trailing `\n`) is emitted (lenient —
17
+ // handles HTTP/1.1 connection-close mid-line).
18
+ // - Buffer cap (1 MiB default) on the residual partial-line buffer,
19
+ // defending against an unbounded line attack.
20
+ // - Trailing `\r` (CRLF artifact) trimmed defensively before yielding.
21
+ // - Mid-stream reader rejections wrapped as `AttestryError` (`AbortError`
22
+ // becomes "request aborted by caller"; everything else becomes
23
+ // "network error during stream: ..."). Symmetric to ndjson-parser
24
+ // post hostile-fix.
25
+ //
26
+ // The parser yields raw strings; the resource-level caller decides how to
27
+ // interpret each line (CEF lines start with "CEF:0|...", but this parser
28
+ // doesn't enforce that — forward-compatible with future text formats).
29
+ import { AttestryError } from "./errors.js";
30
+ /**
31
+ * Maximum residual buffer size before the parser bails. Defends against
32
+ * a server / proxy emitting an unbounded line (no `\n` boundary) — the
33
+ * parser would otherwise accumulate until OOM.
34
+ *
35
+ * 1 MiB matches `ndjson-parser.ts`'s cap. The kernel's CEF emitter caps
36
+ * the `Name` field at 512 bytes and the structured extensions at a
37
+ * handful of KB total; a real audit-log row CEF line is ~1 KB. 1 MiB
38
+ * is ~1000× headroom.
39
+ *
40
+ * Configurable via `parseLines`'s `maxLineBytes` option for callers
41
+ * with legitimate large-line use cases (none today).
42
+ */
43
+ const DEFAULT_MAX_LINE_BYTES = 1024 * 1024;
44
+ /**
45
+ * Async generator: reads from a stream of UTF-8-encoded line-oriented
46
+ * bytes and yields each `\n`-delimited line as a raw string. Ends when
47
+ * the underlying reader signals `done`. Defensive: a caller that breaks
48
+ * early out of the for-await loop leaves the reader open — call
49
+ * `reader.cancel()` from your finally block (or use `parseLinesResponse`
50
+ * below which handles cleanup automatically).
51
+ *
52
+ * Mid-stream read errors are wrapped as
53
+ * `AttestryError("network error during stream: <reason>")` with the
54
+ * original error chained as `cause`. AbortError-shaped rejects (caller
55
+ * cancelled the underlying signal) are wrapped as
56
+ * `AttestryError("request aborted by caller")` for symmetry with the
57
+ * pre-fetch abort surface and with the ndjson-parser. The resource layer
58
+ * can rely on these wrappings — `runAuditLogExport`'s loop passes any
59
+ * `AttestryError` through verbatim.
60
+ *
61
+ * @throws AttestryError if the residual line buffer exceeds `maxLineBytes`
62
+ * (defense against unbounded-line DoS), OR the underlying reader
63
+ * rejects mid-iteration (network drop, abort).
64
+ */
65
+ export async function* parseLines(reader, options = {}) {
66
+ const maxLineBytes = options.maxLineBytes ?? DEFAULT_MAX_LINE_BYTES;
67
+ const decoder = new TextDecoder("utf-8");
68
+ let buffer = "";
69
+ let bomStripped = false;
70
+ while (true) {
71
+ let result;
72
+ try {
73
+ result = await reader.read();
74
+ }
75
+ catch (err) {
76
+ // Mid-stream reader rejects: TCP RST, proxy hang-up, signal-
77
+ // aborted fetch. Wrap with a clear AttestryError so consumers
78
+ // can branch uniformly via `instanceof AttestryError` rather
79
+ // than having to type-narrow on raw DOMException / TypeError.
80
+ // Resource-layer wrapper passes AttestryError through verbatim.
81
+ if (isAbortErrorShape(err)) {
82
+ throw new AttestryError("request aborted by caller", { cause: err });
83
+ }
84
+ throw new AttestryError(`network error during stream: ${err instanceof Error ? err.message : String(err)}`, { cause: err });
85
+ }
86
+ const { value, done } = result;
87
+ if (done) {
88
+ // Flush any final bytes (no-op if value was always complete).
89
+ buffer += decoder.decode();
90
+ // The final newline is optional — emit any trailing partial line
91
+ // if non-empty after stripping CR. This handles HTTP/1.1
92
+ // connection-close mid-line: better to surface the partial line
93
+ // to the caller than silently drop it. Symmetric to ndjson-parser.
94
+ const stripped = stripTrailingCR(buffer);
95
+ if (stripped.length > 0)
96
+ yield stripped;
97
+ return;
98
+ }
99
+ if (value === undefined)
100
+ continue;
101
+ // `{stream: true}` carries multi-byte UTF-8 boundaries across chunks.
102
+ buffer += decoder.decode(value, { stream: true });
103
+ // Strip a leading BOM (U+FEFF) if present. Kernel doesn't emit a
104
+ // BOM today, but a misconfigured proxy / charset transcoder could
105
+ // prepend one. Without this strip, the first line's first char
106
+ // would be `CEF:0|...` and downstream consumers parsing the
107
+ // CEF prefix would silently fail. One-shot: only at the very first
108
+ // decoded codepoint of the stream.
109
+ //
110
+ // Mirror of ndjson-parser fix: `bomStripped` is only flipped once
111
+ // we've actually decoded at least one character. Otherwise an empty
112
+ // / partial-multibyte first read would set the flag prematurely; if
113
+ // the BOM bytes arrived in a later read, the strip-attempt would
114
+ // be skipped.
115
+ if (!bomStripped && buffer.length > 0) {
116
+ bomStripped = true;
117
+ // Defense-in-depth dead path: in Node 18+ / browsers,
118
+ // `TextDecoder("utf-8")` defaults to `ignoreBOM: false` and
119
+ // strips a stream-start BOM internally — by the time the byte
120
+ // reaches our buffer, the BOM is already gone. Marked for v8
121
+ // coverage to make the intentional defense visible.
122
+ /* v8 ignore next 3 */
123
+ if (buffer.charCodeAt(0) === 0xfeff) {
124
+ buffer = buffer.slice(1);
125
+ }
126
+ }
127
+ // Yield each complete line. We split on `\n` rather than using
128
+ // String.split to keep the indexing explicit (and to make the
129
+ // residual-buffer accounting visible). Symmetric to ndjson-parser.
130
+ while (true) {
131
+ const newlineIdx = buffer.indexOf("\n");
132
+ if (newlineIdx === -1)
133
+ break;
134
+ const line = buffer.slice(0, newlineIdx);
135
+ buffer = buffer.slice(newlineIdx + 1);
136
+ const stripped = stripTrailingCR(line);
137
+ if (stripped.length === 0)
138
+ continue; // blank line — skip silently
139
+ yield stripped;
140
+ }
141
+ // Defense in depth: after consuming all complete lines, the residual
142
+ // buffer holds at most a partial line. If THAT exceeds the cap, the
143
+ // server emitted an unbounded line (or omitted the delimiter) — bail
144
+ // before we OOM. Checking after the yield-loop avoids tripping on a
145
+ // single huge chunk that contains many small complete lines.
146
+ if (buffer.length > maxLineBytes) {
147
+ throw new AttestryError(`line exceeded maximum buffer size (${maxLineBytes} bytes) — server emitted an unbounded line or omitted the line delimiter`);
148
+ }
149
+ }
150
+ }
151
+ /**
152
+ * Convenience wrapper around `parseLines` that accepts a `Response`,
153
+ * derives the reader, and ALWAYS calls `reader.cancel()` in a `finally`
154
+ * block — including when a caller breaks out of the for-await loop
155
+ * early. Without this, an early `break` leaks the underlying connection.
156
+ *
157
+ * Resources should call this rather than `parseLines` directly.
158
+ *
159
+ * Symmetric to `parseNDJSONResponse` and `parseSSEResponse`.
160
+ */
161
+ export async function* parseLinesResponse(response, options = {}) {
162
+ if (response.body === null) {
163
+ // 204 No Content / empty body — iterator ends with zero lines.
164
+ // (Throwing would be over-strict; the server may legitimately close
165
+ // before any data — symmetric to parseNDJSONResponse / parseSSEResponse.)
166
+ return;
167
+ }
168
+ const reader = response.body.getReader();
169
+ try {
170
+ yield* parseLines(reader, options);
171
+ }
172
+ finally {
173
+ // Release the lock + signal cancellation upstream. Wrapped in
174
+ // try/catch because cancel() on an already-closed reader rejects.
175
+ try {
176
+ await reader.cancel();
177
+ }
178
+ catch {
179
+ // Already canceled / closed — nothing to do.
180
+ }
181
+ }
182
+ }
183
+ // ─── Internals ──────────────────────────────────────────────────────────────
184
+ /**
185
+ * Trim a single trailing `\r` (CR). Defensive: line-oriented streaming
186
+ * formats mandate LF only, but a Windows-tooling artifact could leave
187
+ * a CR before the LF. Trimming exactly one CR keeps the parser permissive
188
+ * without treating CR alone as a line separator.
189
+ */
190
+ function stripTrailingCR(s) {
191
+ return s.length > 0 && s.charCodeAt(s.length - 1) === 0x0d ? s.slice(0, -1) : s;
192
+ }
193
+ /**
194
+ * True if `err` is an AbortError-shaped exception (DOMException or
195
+ * Error with `name === "AbortError"`). Both browsers and Node 18+
196
+ * produce this shape when `fetch` / `reader.read()` is aborted via
197
+ * `AbortController.abort()`. Same helper signature as the one in
198
+ * `ndjson-parser.ts`.
199
+ */
200
+ function isAbortErrorShape(err) {
201
+ return (err !== null &&
202
+ typeof err === "object" &&
203
+ "name" in err &&
204
+ err.name === "AbortError");
205
+ }
206
+ // Test-only handles for direct pinning of internals.
207
+ export const __test__ = {
208
+ DEFAULT_MAX_LINE_BYTES,
209
+ stripTrailingCR,
210
+ };
211
+ //# sourceMappingURL=lines-parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lines-parser.js","sourceRoot":"","sources":["../src/lines-parser.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,EAAE;AACF,0EAA0E;AAC1E,4EAA4E;AAC5E,4EAA4E;AAC5E,wEAAwE;AACxE,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,gEAAgE;AAChE,0EAA0E;AAC1E,iCAAiC;AACjC,0DAA0D;AAC1D,4EAA4E;AAC5E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