@runfile-ai/schemas 0.1.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 (41) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +163 -0
  3. package/dist/canonical.d.ts +32 -0
  4. package/dist/canonical.d.ts.map +1 -0
  5. package/dist/canonical.js +46 -0
  6. package/dist/canonical.js.map +1 -0
  7. package/dist/control-mapping.d.ts +85 -0
  8. package/dist/control-mapping.d.ts.map +1 -0
  9. package/dist/control-mapping.js +31 -0
  10. package/dist/control-mapping.js.map +1 -0
  11. package/dist/event.d.ts +866 -0
  12. package/dist/event.d.ts.map +1 -0
  13. package/dist/event.js +289 -0
  14. package/dist/event.js.map +1 -0
  15. package/dist/evidence.d.ts +955 -0
  16. package/dist/evidence.d.ts.map +1 -0
  17. package/dist/evidence.js +31 -0
  18. package/dist/evidence.js.map +1 -0
  19. package/dist/index.d.ts +8 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +8 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/ingest.d.ts +1595 -0
  24. package/dist/ingest.d.ts.map +1 -0
  25. package/dist/ingest.js +177 -0
  26. package/dist/ingest.js.map +1 -0
  27. package/dist/manifest.d.ts +110 -0
  28. package/dist/manifest.d.ts.map +1 -0
  29. package/dist/manifest.js +46 -0
  30. package/dist/manifest.js.map +1 -0
  31. package/dist/vault.d.ts +459 -0
  32. package/dist/vault.d.ts.map +1 -0
  33. package/dist/vault.js +188 -0
  34. package/dist/vault.js.map +1 -0
  35. package/generated/json-schema/control_mapping.json +107 -0
  36. package/generated/json-schema/event.json +600 -0
  37. package/generated/json-schema/evidence.json +721 -0
  38. package/generated/json-schema/ingest.json +800 -0
  39. package/generated/json-schema/manifest.json +148 -0
  40. package/generated/json-schema/vault.json +468 -0
  41. package/package.json +59 -0
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may accept and charge a
167
+ fee for, acceptance of support, warranty, indemnity, or other
168
+ liability obligations and/or rights consistent with this License.
169
+ However, in accepting such obligations, You may act only on Your
170
+ own behalf and on Your sole responsibility, not on behalf of any
171
+ other Contributor, and only if You agree to indemnify, defend,
172
+ and hold each Contributor harmless for any liability incurred by,
173
+ or claims asserted against, such Contributor by reason of your
174
+ accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 Runfile
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,163 @@
1
+ # @runfile-ai/schemas
2
+
3
+ The single source of truth for every data shape that crosses a service boundary in Runfile.
4
+
5
+ - **Source of truth:** Zod definitions in TypeScript (`src/`)
6
+ - **Generated downstream:** JSON Schema 2020-12, Python Pydantic v2, Go structs (`generated/`)
7
+ - **Published to:**
8
+ - npm — [`@runfile-ai/schemas`](https://www.npmjs.com/package/@runfile-ai/schemas)
9
+ - PyPI — [`runfile-ai-schemas`](https://pypi.org/project/runfile-ai-schemas/)
10
+ - Go modules — [`github.com/runfile-ai/schemas`](https://pkg.go.dev/github.com/runfile-ai/schemas) (via Git tags, no registry)
11
+ - **Versioned:** strict semver, managed by [Changesets](https://github.com/changesets/changesets). Every release PR is reviewable before it ships.
12
+
13
+ See [`private/apispecs/schemas.md`](../private/apispecs/schemas.md) (internal) for the full design rationale.
14
+
15
+ ## What's in here
16
+
17
+ | Path | Contents |
18
+ |------|----------|
19
+ | `src/event.ts` | `RunfileEventSchema` + sub-shapes (actor, action, subject, model_ref, decision, payload_ref) |
20
+ | `src/ingest.ts` | `BatchSubmissionSchema`, `EventSubmissionSchema`, error/response shapes for the Ingest API |
21
+ | `src/vault.ts` | Tokenize/Resolve/Lifecycle request and response shapes |
22
+ | `src/evidence.ts` | Evidence bundle format (consumed by the Verifier CLI) |
23
+ | `src/manifest.ts` | Daily Merkle manifest format |
24
+ | `src/control-mapping.ts` | Regulatory control mapping YAML schema |
25
+ | `src/canonical.ts` | RFC 8785 JCS canonical JSON helpers |
26
+ | `generated/` | JSON Schema, Pydantic, Go structs — never edit by hand (except `canonical.py` / `canonical.go`) |
27
+ | `scripts/generate.ts` | Master generator: Zod → JSON Schema → Pydantic + Go |
28
+ | `scripts/check-drift.ts` | CI guard: fails if `generated/` is out of date w.r.t. Zod source |
29
+ | `scripts/publish-all.ts` | Local fallback for publishing (CI is the normal path) |
30
+ | `go.mod` | Go module declaration at repo root — module path `github.com/runfile-ai/schemas` |
31
+
32
+ ## Usage
33
+
34
+ ```bash
35
+ pnpm install
36
+ pnpm run generate # regenerate downstream artifacts after editing Zod
37
+ pnpm test # round-trip + canonical JSON + cross-language fixtures
38
+ pnpm run check-drift # verify committed generated/ matches what generate would produce
39
+ pnpm run build # compile TypeScript to dist/
40
+ pnpm run publish-all # local fallback for publishing (CI is the normal path)
41
+ ```
42
+
43
+ ### Toolchain required for `pnpm run generate`
44
+
45
+ - **Node 20+** — always
46
+ - **Python 3.10+** with `datamodel-code-generator >= 0.57` on PATH (Step 2: Pydantic generation). Python 3.9 caps at `datamodel-code-generator 0.45`, which produces an older form that CI rejects via the drift check.
47
+ ```bash
48
+ python3.11 -m pip install --user 'datamodel-code-generator[http]>=0.57,<1.0'
49
+ ```
50
+ - **quicktype** — installed as a devDependency, invoked via `pnpm exec` (Step 3: Go generation). No separate install needed.
51
+
52
+ No Go toolchain is required for codegen — `quicktype` is the documented alternative to `go-jsonschema` and produces struct files that compile under any Go 1.22+ consumer.
53
+
54
+ ### What's hand-written vs generated
55
+
56
+ Everything under `generated/` is produced by `pnpm run generate` EXCEPT:
57
+
58
+ - `generated/python/runfile_schemas/canonical.py` — RFC 8785 canonical JSON helper for Python (parity with the TS leg)
59
+ - `generated/go/pkg/canonical/canonical.go` — RFC 8785 canonical JSON helper for Go
60
+
61
+ These are part of the published packages but cannot be auto-generated from Zod. They sit alongside the generated files and are preserved across regenerations.
62
+
63
+ ### In a TypeScript consumer
64
+
65
+ ```ts
66
+ import { RunfileEventSchema, type RunfileEvent } from '@runfile-ai/schemas/event';
67
+ import { BatchSubmissionSchema } from '@runfile-ai/schemas/ingest';
68
+
69
+ const event: RunfileEvent = RunfileEventSchema.parse(unknownInput);
70
+ ```
71
+
72
+ ### In a Python consumer
73
+
74
+ ```python
75
+ from runfile_schemas.event import RunfileEvent, Actor
76
+ from runfile_schemas.ingest import BatchSubmission
77
+ from runfile_schemas.canonical import canonical_sha256
78
+ ```
79
+
80
+ (The PyPI distribution is `runfile-ai-schemas`; the importable package name is `runfile_schemas`.)
81
+
82
+ ### In a Go consumer
83
+
84
+ ```go
85
+ import (
86
+ "github.com/runfile-ai/schemas/generated/go/pkg/event"
87
+ "github.com/runfile-ai/schemas/generated/go/pkg/canonical"
88
+ )
89
+ ```
90
+
91
+ The `go.mod` at the repo root declares `module github.com/runfile-ai/schemas`, so Go consumers fetch with:
92
+
93
+ ```bash
94
+ go get github.com/runfile-ai/schemas@v1.0.0
95
+ ```
96
+
97
+ The Git tag IS the Go module version — there's no separate registry.
98
+
99
+ ## Versioning
100
+
101
+ Strict semver:
102
+ - **Major** (`1.x → 2.x`): breaking. Removed fields, changed validation. Forces coordinated SDK upgrades.
103
+ - **Minor** (`1.0 → 1.1`): additive only. New optional fields, new enum values.
104
+ - **Patch** (`1.0.0 → 1.0.1`): documentation fixes only.
105
+
106
+ The npm/Go package version stays in lockstep — `package.json#version` is the master, and `generate.ts` templates it into `generated/python/pyproject.toml` automatically. The Go consumer-visible version is whatever Git tag is pushed (`v1.1.0`).
107
+
108
+ The package version may differ from the `event.schema_version` field embedded in events; in v1 they are kept in sync.
109
+
110
+ ## Publishing
111
+
112
+ Releases are driven by [Changesets](https://github.com/changesets/changesets). Every change that should ship to consumers gets a changeset file describing the bump (`patch` / `minor` / `major`) and a one-line summary. Changesets accumulate on `main` until they're released as a batch.
113
+
114
+ ### Day-to-day: include a changeset with your PR
115
+
116
+ ```bash
117
+ pnpm changeset
118
+ # Pick patch/minor/major, write a 1–2 sentence summary.
119
+ # A markdown file lands in .changeset/; commit it alongside your code.
120
+ ```
121
+
122
+ If your PR doesn't change anything consumer-visible (CI tweaks, docs, internal refactor), skip this — no changeset needed.
123
+
124
+ ### Cutting a release
125
+
126
+ You don't tag manually. The flow is:
127
+
128
+ 1. Merge PRs to `main` with their changesets.
129
+ 2. The `Changesets` workflow opens a `chore(release): version packages` PR. It bumps `package.json`, writes `CHANGELOG.md`, and updates `generated/python/pyproject.toml` (via `pnpm run generate`).
130
+ 3. Review that PR. When merged:
131
+ - The same workflow runs again, calls `changeset publish`, which:
132
+ - Publishes `@runfile-ai/schemas@X.Y.Z` to npm
133
+ - Pushes the `vX.Y.Z` git tag
134
+ - The tag push triggers `release.yml`, which announces the Go module path (and will publish to PyPI once the runfile-ai PyPI org is set up).
135
+
136
+ You can preview what the next release will look like locally:
137
+
138
+ ```bash
139
+ pnpm changeset status --verbose
140
+ ```
141
+
142
+ ### One-time setup before the first release
143
+
144
+ | Registry | What to set up |
145
+ |---|---|
146
+ | **npm** | `NPM_TOKEN` repo secret (an automation token from npmjs.org with `Publish` rights on `@runfile-ai/schemas`) |
147
+ | **PyPI** | *Deferred to GA.* A trusted publisher on [pypi.org/manage/account/publishing/](https://pypi.org/manage/account/publishing/) pointing at this repo's `release.yml` workflow and `release` GitHub environment. Until then the PyPI step in `release.yml` is commented out. |
148
+ | **Go** | Nothing. The repo must be public (or the consumer's `GOPRIVATE` must include it) and tags must be pushed — Changesets pushes them for you. |
149
+
150
+ ### Manual fallback: `pnpm run publish-all`
151
+
152
+ If CI is broken mid-release, you can publish from your laptop:
153
+
154
+ ```bash
155
+ pnpm run publish-all # full publish (npm + PyPI + Git tag verification)
156
+ pnpm run publish-all -- --dry-run # print steps without publishing
157
+ ```
158
+
159
+ Requires `npm login`, a `~/.pypirc` token (or `PYPI_API_TOKEN` env var), and Python's `build` + `twine` (`pip3 install --user build twine`).
160
+
161
+ ## License
162
+
163
+ Apache 2.0. See `LICENSE`.
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Canonical JSON serialisation per RFC 8785 (JSON Canonicalization Scheme).
3
+ *
4
+ * Every consumer — TS SDK, TS backend, Python SDK, Go Event Processor, Verifier CLI —
5
+ * must produce byte-identical output for the same logical value, because `event_hash`
6
+ * commits to the canonical serialisation. The schemas package owns the canonical form
7
+ * and re-exports it.
8
+ *
9
+ * Use this for any value whose hash crosses a service boundary. Do NOT use it for
10
+ * general API payloads (those go through plain JSON.stringify) — RFC 8785 is strictly
11
+ * for hash determinism.
12
+ */
13
+ export declare function stringify(value: unknown): string;
14
+ /** @deprecated Alias retained for the documented import name in schemas.md. */
15
+ export { stringify as canonicalStringify };
16
+ /**
17
+ * Computes SHA-256(stringify(value)) as the lowercase-hex form `sha256:<64 chars>`.
18
+ *
19
+ * This is the exact form that appears in `event.event_hash`, `payload_ref.sha256`,
20
+ * `model_version_hash`, etc.
21
+ */
22
+ export declare function canonicalSha256(value: unknown): string;
23
+ /**
24
+ * Computes the event_hash for a RunfileEvent.
25
+ *
26
+ * Per the canonicalisation spec: the `event_hash` field itself is excluded from
27
+ * canonicalisation — serialise with `event_hash` omitted, compute SHA-256, then set.
28
+ */
29
+ export declare function computeEventHash<T extends {
30
+ event_hash?: unknown;
31
+ }>(event: T): string;
32
+ //# sourceMappingURL=canonical.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical.d.ts","sourceRoot":"","sources":["../src/canonical.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAMhD;AAED,+EAA+E;AAC/E,OAAO,EAAE,SAAS,IAAI,kBAAkB,EAAE,CAAC;AAE3C;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEtD;AAMD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS;IAAE,UAAU,CAAC,EAAE,OAAO,CAAA;CAAE,EAAE,KAAK,EAAE,CAAC,GAAG,MAAM,CAGrF"}
@@ -0,0 +1,46 @@
1
+ import canonicalize from 'canonicalize';
2
+ import { createHash } from 'node:crypto';
3
+ /**
4
+ * Canonical JSON serialisation per RFC 8785 (JSON Canonicalization Scheme).
5
+ *
6
+ * Every consumer — TS SDK, TS backend, Python SDK, Go Event Processor, Verifier CLI —
7
+ * must produce byte-identical output for the same logical value, because `event_hash`
8
+ * commits to the canonical serialisation. The schemas package owns the canonical form
9
+ * and re-exports it.
10
+ *
11
+ * Use this for any value whose hash crosses a service boundary. Do NOT use it for
12
+ * general API payloads (those go through plain JSON.stringify) — RFC 8785 is strictly
13
+ * for hash determinism.
14
+ */
15
+ export function stringify(value) {
16
+ const result = canonicalize(value);
17
+ if (result === undefined) {
18
+ throw new TypeError('canonicalize returned undefined; value is not JSON-serialisable');
19
+ }
20
+ return result;
21
+ }
22
+ /** @deprecated Alias retained for the documented import name in schemas.md. */
23
+ export { stringify as canonicalStringify };
24
+ /**
25
+ * Computes SHA-256(stringify(value)) as the lowercase-hex form `sha256:<64 chars>`.
26
+ *
27
+ * This is the exact form that appears in `event.event_hash`, `payload_ref.sha256`,
28
+ * `model_version_hash`, etc.
29
+ */
30
+ export function canonicalSha256(value) {
31
+ return `sha256:${sha256Hex(stringify(value))}`;
32
+ }
33
+ function sha256Hex(input) {
34
+ return createHash('sha256').update(input).digest('hex');
35
+ }
36
+ /**
37
+ * Computes the event_hash for a RunfileEvent.
38
+ *
39
+ * Per the canonicalisation spec: the `event_hash` field itself is excluded from
40
+ * canonicalisation — serialise with `event_hash` omitted, compute SHA-256, then set.
41
+ */
42
+ export function computeEventHash(event) {
43
+ const { event_hash: _omit, ...rest } = event;
44
+ return canonicalSha256(rest);
45
+ }
46
+ //# sourceMappingURL=canonical.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical.js","sourceRoot":"","sources":["../src/canonical.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,UAAU,EAAmB,MAAM,aAAa,CAAC;AAE1D;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,SAAS,CAAC,KAAc;IACtC,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;IACnC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,MAAM,IAAI,SAAS,CAAC,iEAAiE,CAAC,CAAC;IACzF,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,+EAA+E;AAC/E,OAAO,EAAE,SAAS,IAAI,kBAAkB,EAAE,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,OAAO,UAAU,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;AACjD,CAAC;AAED,SAAS,SAAS,CAAC,KAAiB;IAClC,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC1D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAqC,KAAQ;IAC3E,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;IAC7C,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,85 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Control mapping — authored as signed YAML in the Control Mapping repo, but
4
+ * validated against this JSON Schema. Maps regulatory framework controls to the
5
+ * event-level predicates the Query API evaluates.
6
+ */
7
+ export declare const ControlMappingSchema: z.ZodObject<{
8
+ mapping_version: z.ZodString;
9
+ framework: z.ZodString;
10
+ framework_version: z.ZodString;
11
+ published_at: z.ZodString;
12
+ controls: z.ZodArray<z.ZodObject<{
13
+ control_id: z.ZodString;
14
+ title: z.ZodString;
15
+ description: z.ZodString;
16
+ regulatory_tags: z.ZodArray<z.ZodString, "many">;
17
+ predicates: z.ZodArray<z.ZodObject<{
18
+ kind: z.ZodEnum<["event_count", "event_exists", "event_absent", "aggregate"]>;
19
+ expression: z.ZodString;
20
+ threshold: z.ZodOptional<z.ZodNumber>;
21
+ }, "strict", z.ZodTypeAny, {
22
+ kind: "event_count" | "event_exists" | "event_absent" | "aggregate";
23
+ expression: string;
24
+ threshold?: number | undefined;
25
+ }, {
26
+ kind: "event_count" | "event_exists" | "event_absent" | "aggregate";
27
+ expression: string;
28
+ threshold?: number | undefined;
29
+ }>, "many">;
30
+ }, "strict", z.ZodTypeAny, {
31
+ control_id: string;
32
+ title: string;
33
+ description: string;
34
+ regulatory_tags: string[];
35
+ predicates: {
36
+ kind: "event_count" | "event_exists" | "event_absent" | "aggregate";
37
+ expression: string;
38
+ threshold?: number | undefined;
39
+ }[];
40
+ }, {
41
+ control_id: string;
42
+ title: string;
43
+ description: string;
44
+ regulatory_tags: string[];
45
+ predicates: {
46
+ kind: "event_count" | "event_exists" | "event_absent" | "aggregate";
47
+ expression: string;
48
+ threshold?: number | undefined;
49
+ }[];
50
+ }>, "many">;
51
+ }, "strict", z.ZodTypeAny, {
52
+ mapping_version: string;
53
+ framework: string;
54
+ framework_version: string;
55
+ published_at: string;
56
+ controls: {
57
+ control_id: string;
58
+ title: string;
59
+ description: string;
60
+ regulatory_tags: string[];
61
+ predicates: {
62
+ kind: "event_count" | "event_exists" | "event_absent" | "aggregate";
63
+ expression: string;
64
+ threshold?: number | undefined;
65
+ }[];
66
+ }[];
67
+ }, {
68
+ mapping_version: string;
69
+ framework: string;
70
+ framework_version: string;
71
+ published_at: string;
72
+ controls: {
73
+ control_id: string;
74
+ title: string;
75
+ description: string;
76
+ regulatory_tags: string[];
77
+ predicates: {
78
+ kind: "event_count" | "event_exists" | "event_absent" | "aggregate";
79
+ expression: string;
80
+ threshold?: number | undefined;
81
+ }[];
82
+ }[];
83
+ }>;
84
+ export type ControlMapping = z.infer<typeof ControlMappingSchema>;
85
+ //# sourceMappingURL=control-mapping.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"control-mapping.d.ts","sourceRoot":"","sources":["../src/control-mapping.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB;;;;GAIG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0BtB,CAAC;AACZ,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { z } from 'zod';
2
+ const semver = z.string().regex(/^\d+\.\d+\.\d+$/);
3
+ /**
4
+ * Control mapping — authored as signed YAML in the Control Mapping repo, but
5
+ * validated against this JSON Schema. Maps regulatory framework controls to the
6
+ * event-level predicates the Query API evaluates.
7
+ */
8
+ export const ControlMappingSchema = z
9
+ .object({
10
+ mapping_version: semver,
11
+ framework: z.string(),
12
+ framework_version: z.string(),
13
+ published_at: z.string().datetime(),
14
+ controls: z.array(z
15
+ .object({
16
+ control_id: z.string(),
17
+ title: z.string(),
18
+ description: z.string(),
19
+ regulatory_tags: z.array(z.string().regex(/^[a-z0-9_]+$/)),
20
+ predicates: z.array(z
21
+ .object({
22
+ kind: z.enum(['event_count', 'event_exists', 'event_absent', 'aggregate']),
23
+ expression: z.string(),
24
+ threshold: z.number().optional(),
25
+ })
26
+ .strict()),
27
+ })
28
+ .strict()),
29
+ })
30
+ .strict();
31
+ //# sourceMappingURL=control-mapping.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"control-mapping.js","sourceRoot":"","sources":["../src/control-mapping.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;AAEnD;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC;KAClC,MAAM,CAAC;IACN,eAAe,EAAE,MAAM;IACvB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,iBAAiB,EAAE,CAAC,CAAC,MAAM,EAAE;IAC7B,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACnC,QAAQ,EAAE,CAAC,CAAC,KAAK,CACf,CAAC;SACE,MAAM,CAAC;QACN,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;QACtB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;QACjB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;QACvB,eAAe,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;QAC1D,UAAU,EAAE,CAAC,CAAC,KAAK,CACjB,CAAC;aACE,MAAM,CAAC;YACN,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,CAAC,CAAC;YAC1E,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;YACtB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;SACjC,CAAC;aACD,MAAM,EAAE,CACZ;KACF,CAAC;SACD,MAAM,EAAE,CACZ;CACF,CAAC;KACD,MAAM,EAAE,CAAC"}