@receiz/sdk 94.0.0 → 96.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -17,10 +17,22 @@ const receiz = createReceizClient({
17
17
  });
18
18
  ```
19
19
 
20
+ Local proof tooling ships with the same package:
21
+
22
+ ```bash
23
+ npx @receiz/sdk conformance
24
+ npx @receiz/sdk inspect ./receiz-asset-manifest.json
25
+ npx @receiz/sdk init ./receiz-integration
26
+ ```
27
+
28
+ These commands use packaged SDK validators, projections, and durable proof memory. `conformance` and `inspect` do not call Receiz production, Supabase, or any database; they prove the local SDK can admit and project Receiz proof objects from fixture or file-carried truth.
29
+
20
30
  ## Primitive Boundary
21
31
 
22
32
  The SDK is convenience, not authority. It reads public API projections, sends delegated actions, validates developer manifests, and verifies webhook delivery signatures. Sealed artifacts, proof bundles, verified appends, ownership appends, and settlement ledger records remain the stronger source of truth.
23
33
 
34
+ Kai Klok is the proof object state machine. `kaiPulseEternal` is the pulse unit carried by that state machine. A complete Receiz proof object carries Kai; without its Kai coordinate it is not complete Receiz proof truth.
35
+
24
36
  Receiz ID is the default account-continuity rail for everyday login. It does not replace PBI/passkey, email magic-link recovery, Receiz Key, Identity Record, Identity Seal, or OIDC/Connect. Those rails all preserve the same account when bound: PBI/passkey can create or recover a Receiz account, email can recover the account, Receiz identity artifacts can restore it locally, and OIDC/Connect can delegate API access after identity proof.
25
37
 
26
38
  Receiz Key, Identity Record, and Identity Seal are Receiz identity primitives exposed through the SDK for developer apps. Their current account-state envelope is `receiz.account.state.v3`; it carries admitted account proof memory across profile, action ledger, calendar, wallet settlement, Sports vault/cards/appends/event proofs, and related entries. The SDK mirrors the same law for developer apps through local proof registers: admit verified truth once, persist it, and ask Receiz only for verified additions after the known head. Connect is delegated API access; it is not the identity proof root.
@@ -30,7 +42,8 @@ Default integration order:
30
42
  1. Verify first, then project.
31
43
  2. Render the proof object or manifest as the user-facing truth.
32
44
  3. Append public proof, wallet, sports, or Connect additions after the known truth.
33
- 4. Never treat an SDK response as stronger than the sealed artifact, verified append, ownership append, or settlement primitive it projects.
45
+ 4. Order proof objects by Kai/Klok state; render Chronos only as display.
46
+ 5. Never treat an SDK response as stronger than the sealed artifact, verified append, ownership append, or settlement primitive it projects.
34
47
 
35
48
  ## Five-Minute Proof Object App
36
49
 
@@ -39,19 +52,24 @@ This is the highest-leverage SDK path for most apps:
39
52
  ```ts
40
53
  import {
41
54
  createReceizClient,
42
- createReceizProofRegister,
55
+ createReceizLocalStorageProofMemoryStorage,
56
+ createReceizProofMemory,
43
57
  projectReceizAssetManifest,
44
58
  } from "@receiz/sdk";
45
59
 
46
60
  const receiz = createReceizClient({ accessToken: process.env.RECEIZ_ACCESS_TOKEN });
47
- const register = createReceizProofRegister({ ownerId: "local-user-or-workspace-id" });
61
+ const memory = await createReceizProofMemory({
62
+ ownerId: "local-user-or-workspace-id",
63
+ storage: createReceizLocalStorageProofMemoryStorage("receiz:proof-memory"),
64
+ });
48
65
 
49
66
  const verified = await receiz.verification.verifyArtifact(file);
50
67
  if (!verified.ok) throw new Error(verified.errors.join(", "));
51
68
 
52
69
  const manifest = verified.bundle?.assetManifest;
53
70
  const projection = projectReceizAssetManifest(manifest);
54
- register.admitAssetManifest(manifest);
71
+ memory.admitAssetManifest(manifest);
72
+ await memory.flush();
55
73
 
56
74
  renderReceizObject({
57
75
  title: projection.title,
@@ -65,11 +83,37 @@ The register is not a cache. It is the app's admitted verified prefix. Use it im
65
83
 
66
84
  Full quickstart: `docs/proof-memory-and-projections.md`.
67
85
 
86
+ For complete copy-paste integrations, use `docs/copy-paste-integrations.md`. It includes a React proof memory hook, browser admission helper, Next append-sync route, webhook receiver, Sports card renderer, and local CLI proof commands.
87
+
88
+ ## CLI And Local Conformance
89
+
90
+ ```bash
91
+ npx @receiz/sdk conformance
92
+ ```
93
+
94
+ Runs the packaged asset manifest, Sports card manifest, and webhook event fixtures through the SDK validators and durable proof memory. This is existing SDK conformance exposed as an executable developer rail; it is not a new authority layer.
95
+
96
+ ```bash
97
+ npx @receiz/sdk inspect ./receiz-asset-manifest.json
98
+ ```
99
+
100
+ Validates one proof payload, projects display-ready rows, admits it into in-memory proof memory, and prints the known Kai/proof head your app can use to ask for verified additions.
101
+
102
+ ```bash
103
+ npx @receiz/sdk init ./receiz-integration
104
+ ```
105
+
106
+ Writes a local-first proof memory starter. The starter opens durable proof memory, admits verified proof objects, projects them immediately, and exposes `knownHead()` for append-only sync.
107
+
108
+ Full quickstart: `docs/cli-and-conformance.md`.
109
+
68
110
  ## Schemas, Projections, And Proof Memory
69
111
 
70
112
  ```ts
71
113
  import {
72
114
  RECEIZ_SCHEMAS,
115
+ createReceizInMemoryProofMemoryStorage,
116
+ createReceizProofMemory,
73
117
  createReceizProofRegister,
74
118
  projectReceizSportsCardManifest,
75
119
  } from "@receiz/sdk";
@@ -82,6 +126,11 @@ memory.admitSportsCardManifest(cardManifest);
82
126
  memory.admitWebhookEvent(webhookEvent);
83
127
 
84
128
  const snapshot = memory.snapshot();
129
+
130
+ const durableMemory = await createReceizProofMemory({
131
+ storage: createReceizInMemoryProofMemoryStorage(snapshot),
132
+ });
133
+ const additionsAfter = durableMemory.knownHead(50);
85
134
  ```
86
135
 
87
136
  Use schemas for developer validation, projections for display-ready proof rows, and proof memory for first-admission-then-append-forever UX.
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,238 @@
1
+ #!/usr/bin/env node
2
+ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
+ import { dirname, join, resolve } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { assertReceizAssetManifest, assertReceizProofRegisterSnapshot, assertReceizSportsCardManifest, assertReceizWebhookEvent, createReceizInMemoryProofMemoryStorage, createReceizProofMemory, projectReceizAssetManifest, projectReceizSportsCardManifest, receizProofMemoryAdditionsQuery, } from "./index.js";
6
+ const moduleDir = dirname(fileURLToPath(import.meta.url));
7
+ const packageRoot = moduleDir.endsWith(`${join("packages", "receiz-sdk", "dist")}`)
8
+ ? dirname(moduleDir)
9
+ : dirname(moduleDir);
10
+ function printJson(value) {
11
+ process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
12
+ }
13
+ function printError(error, detail) {
14
+ const payload = detail
15
+ ? { ok: false, schema: "receiz.sdk.cli.error.v1", error, detail }
16
+ : { ok: false, schema: "receiz.sdk.cli.error.v1", error };
17
+ process.stderr.write(`${JSON.stringify(payload, null, 2)}\n`);
18
+ }
19
+ function readJsonFile(path) {
20
+ return JSON.parse(readFileSync(resolve(path), "utf8"));
21
+ }
22
+ async function inspectProofObject(path) {
23
+ const value = readJsonFile(path);
24
+ const storage = createReceizInMemoryProofMemoryStorage();
25
+ const memory = await createReceizProofMemory({ storage });
26
+ try {
27
+ const manifest = assertReceizAssetManifest(value);
28
+ memory.admitAssetManifest(manifest);
29
+ await memory.flush();
30
+ return {
31
+ ok: true,
32
+ schema: "receiz.sdk.cli.inspect.v1",
33
+ kind: "asset_manifest",
34
+ sourcePath: resolve(path),
35
+ projection: projectReceizAssetManifest(manifest),
36
+ knownHead: memory.knownHead(100),
37
+ };
38
+ }
39
+ catch {
40
+ // Try the next implemented Receiz proof payload shape.
41
+ }
42
+ try {
43
+ const manifest = assertReceizSportsCardManifest(value);
44
+ memory.admitSportsCardManifest(manifest);
45
+ await memory.flush();
46
+ return {
47
+ ok: true,
48
+ schema: "receiz.sdk.cli.inspect.v1",
49
+ kind: "sports_card_manifest",
50
+ sourcePath: resolve(path),
51
+ projection: projectReceizSportsCardManifest(manifest),
52
+ knownHead: memory.knownHead(100),
53
+ };
54
+ }
55
+ catch {
56
+ // Try the next implemented Receiz proof payload shape.
57
+ }
58
+ try {
59
+ const event = assertReceizWebhookEvent(value);
60
+ memory.admitWebhookEvent(event);
61
+ await memory.flush();
62
+ const entry = memory.entries()[0];
63
+ return {
64
+ ok: true,
65
+ schema: "receiz.sdk.cli.inspect.v1",
66
+ kind: "webhook_event",
67
+ sourcePath: resolve(path),
68
+ projection: (entry?.projection ?? {}),
69
+ knownHead: memory.knownHead(100),
70
+ };
71
+ }
72
+ catch {
73
+ // Try the register snapshot shape before failing.
74
+ }
75
+ const snapshot = assertReceizProofRegisterSnapshot(value);
76
+ return {
77
+ ok: true,
78
+ schema: "receiz.sdk.cli.inspect.v1",
79
+ kind: "proof_register_snapshot",
80
+ sourcePath: resolve(path),
81
+ projection: {
82
+ schema: snapshot.schema,
83
+ ownerId: snapshot.ownerId ?? null,
84
+ count: snapshot.head.count,
85
+ head: snapshot.head,
86
+ },
87
+ knownHead: receizProofMemoryAdditionsQuery(snapshot, 100),
88
+ };
89
+ }
90
+ async function admitFixture(memory, path) {
91
+ const value = readJsonFile(path);
92
+ memory.admit(value);
93
+ await memory.flush();
94
+ }
95
+ async function runConformance() {
96
+ const fixtures = [
97
+ join(packageRoot, "fixtures", "receiz-asset-manifest.example.json"),
98
+ join(packageRoot, "fixtures", "receiz-sports-card-manifest.example.json"),
99
+ join(packageRoot, "fixtures", "receiz-webhook-event.example.json"),
100
+ ];
101
+ const failures = [];
102
+ const storage = createReceizInMemoryProofMemoryStorage();
103
+ const memory = await createReceizProofMemory({ ownerId: "receiz-sdk-conformance", storage });
104
+ for (const fixture of fixtures) {
105
+ try {
106
+ await admitFixture(memory, fixture);
107
+ }
108
+ catch (error) {
109
+ failures.push({
110
+ fixture,
111
+ error: error instanceof Error ? error.message : String(error),
112
+ });
113
+ }
114
+ }
115
+ const reopened = await createReceizProofMemory({ ownerId: "receiz-sdk-conformance", storage });
116
+ printJson({
117
+ ok: failures.length === 0,
118
+ schema: "receiz.sdk.cli.conformance.v1",
119
+ summary: {
120
+ fixtures: fixtures.length,
121
+ proofMemoryEntries: reopened.snapshot().head.count,
122
+ networkCalls: 0,
123
+ dbCalls: 0,
124
+ },
125
+ knownHead: reopened.knownHead(100),
126
+ failures,
127
+ });
128
+ if (failures.length > 0)
129
+ process.exitCode = 1;
130
+ }
131
+ function writeStarter(targetDir) {
132
+ mkdirSync(targetDir, { recursive: true });
133
+ writeFileSync(join(targetDir, "receiz-proof-memory.ts"), `import {
134
+ assertReceizAssetManifest,
135
+ assertReceizSportsCardManifest,
136
+ assertReceizWebhookEvent,
137
+ createReceizLocalStorageProofMemoryStorage,
138
+ createReceizProofMemory,
139
+ projectReceizAssetManifest,
140
+ projectReceizSportsCardManifest,
141
+ type ReceizProofMemory,
142
+ } from "@receiz/sdk";
143
+
144
+ export async function openReceizProofMemory(ownerId: string): Promise<ReceizProofMemory> {
145
+ return createReceizProofMemory({
146
+ ownerId,
147
+ storage: createReceizLocalStorageProofMemoryStorage(\`receiz:proof-memory:\${ownerId}:v1\`),
148
+ });
149
+ }
150
+
151
+ export async function admitVerifiedProofObject(memory: ReceizProofMemory, value: unknown) {
152
+ if (typeof value !== "object" || value === null) throw new Error("receiz_proof_object_required");
153
+ const schema = "schema" in value ? value.schema : null;
154
+
155
+ if (schema === "receiz.asset_manifest.v1") {
156
+ const manifest = assertReceizAssetManifest(value);
157
+ memory.admitAssetManifest(manifest);
158
+ await memory.flush();
159
+ return projectReceizAssetManifest(manifest);
160
+ }
161
+
162
+ if (schema === "receiz.sports_arena.card_manifest.v1") {
163
+ const manifest = assertReceizSportsCardManifest(value);
164
+ memory.admitSportsCardManifest(manifest);
165
+ await memory.flush();
166
+ return projectReceizSportsCardManifest(manifest);
167
+ }
168
+
169
+ if (schema === "receiz.webhook_event.v1") {
170
+ const event = assertReceizWebhookEvent(value);
171
+ memory.admitWebhookEvent(event);
172
+ await memory.flush();
173
+ return memory.snapshot().entries.find((entry) => entry.id === \`webhook:\${event.id}\`)?.projection ?? null;
174
+ }
175
+
176
+ throw new Error(\`receiz_unsupported_proof_schema:\${String(schema ?? "unknown")}\`);
177
+ }
178
+
179
+ export function verifiedAdditionsAfterKnownHead(memory: ReceizProofMemory) {
180
+ return memory.knownHead(100);
181
+ }
182
+ `, "utf8");
183
+ }
184
+ function printHelp() {
185
+ process.stdout.write(`Receiz SDK CLI
186
+
187
+ Usage:
188
+ receiz inspect <path-to-proof-json>
189
+ receiz conformance
190
+ receiz init <target-dir>
191
+
192
+ This CLI uses local Receiz SDK validators, projections, and durable proof memory.
193
+ It does not make network or database calls for inspect or conformance.
194
+ `);
195
+ }
196
+ async function main(argv) {
197
+ const [command, ...args] = argv;
198
+ if (!command || command === "help" || command === "--help" || command === "-h") {
199
+ printHelp();
200
+ return;
201
+ }
202
+ if (command === "inspect") {
203
+ const path = args[0];
204
+ if (!path) {
205
+ printError("missing_path", "Usage: receiz inspect <path-to-proof-json>");
206
+ process.exitCode = 1;
207
+ return;
208
+ }
209
+ printJson(await inspectProofObject(path));
210
+ return;
211
+ }
212
+ if (command === "conformance") {
213
+ await runConformance();
214
+ return;
215
+ }
216
+ if (command === "init") {
217
+ const targetDir = args[0];
218
+ if (!targetDir) {
219
+ printError("missing_target_dir", "Usage: receiz init <target-dir>");
220
+ process.exitCode = 1;
221
+ return;
222
+ }
223
+ writeStarter(resolve(targetDir));
224
+ printJson({
225
+ ok: true,
226
+ schema: "receiz.sdk.cli.init.v1",
227
+ targetDir: resolve(targetDir),
228
+ files: ["receiz-proof-memory.ts"],
229
+ });
230
+ return;
231
+ }
232
+ printError("unknown_command", command);
233
+ process.exitCode = 1;
234
+ }
235
+ main(process.argv.slice(2)).catch((error) => {
236
+ printError("receiz_cli_failed", error instanceof Error ? error.message : String(error));
237
+ process.exitCode = 1;
238
+ });