@receiz/sdk 95.0.0 → 96.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.
package/README.md CHANGED
@@ -6,7 +6,7 @@ Install:
6
6
  npm install @receiz/sdk
7
7
  ```
8
8
 
9
- Use one typed client for Receiz proof objects, public proof rendering, Sports Arena card/event proof integration, wallet ledger reads, Connect transfers, and webhook delivery verification.
9
+ Use one typed client for Receiz proof objects, public proof rendering, Sports Arena card/event proof integration, wallet ledger reads, Twin and World surfaces, Connect transfers, and webhook delivery verification.
10
10
 
11
11
  ```ts
12
12
  import { createReceizClient } from "@receiz/sdk";
@@ -17,6 +17,16 @@ 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.
@@ -42,19 +52,24 @@ This is the highest-leverage SDK path for most apps:
42
52
  ```ts
43
53
  import {
44
54
  createReceizClient,
45
- createReceizProofRegister,
55
+ createReceizLocalStorageProofMemoryStorage,
56
+ createReceizProofMemory,
46
57
  projectReceizAssetManifest,
47
58
  } from "@receiz/sdk";
48
59
 
49
60
  const receiz = createReceizClient({ accessToken: process.env.RECEIZ_ACCESS_TOKEN });
50
- 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
+ });
51
65
 
52
66
  const verified = await receiz.verification.verifyArtifact(file);
53
67
  if (!verified.ok) throw new Error(verified.errors.join(", "));
54
68
 
55
69
  const manifest = verified.bundle?.assetManifest;
56
70
  const projection = projectReceizAssetManifest(manifest);
57
- register.admitAssetManifest(manifest);
71
+ memory.admitAssetManifest(manifest);
72
+ await memory.flush();
58
73
 
59
74
  renderReceizObject({
60
75
  title: projection.title,
@@ -68,11 +83,37 @@ The register is not a cache. It is the app's admitted verified prefix. Use it im
68
83
 
69
84
  Full quickstart: `docs/proof-memory-and-projections.md`.
70
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
+
71
110
  ## Schemas, Projections, And Proof Memory
72
111
 
73
112
  ```ts
74
113
  import {
75
114
  RECEIZ_SCHEMAS,
115
+ createReceizInMemoryProofMemoryStorage,
116
+ createReceizProofMemory,
76
117
  createReceizProofRegister,
77
118
  projectReceizSportsCardManifest,
78
119
  } from "@receiz/sdk";
@@ -85,6 +126,11 @@ memory.admitSportsCardManifest(cardManifest);
85
126
  memory.admitWebhookEvent(webhookEvent);
86
127
 
87
128
  const snapshot = memory.snapshot();
129
+
130
+ const durableMemory = await createReceizProofMemory({
131
+ storage: createReceizInMemoryProofMemoryStorage(snapshot),
132
+ });
133
+ const additionsAfter = durableMemory.knownHead(50);
88
134
  ```
89
135
 
90
136
  Use schemas for developer validation, projections for display-ready proof rows, and proof memory for first-admission-then-append-forever UX.
@@ -173,6 +219,32 @@ const ledger = await receiz.wallet.publicLedger({ limit: 40 });
173
219
 
174
220
  Full quickstart: `docs/wallet-ledger-reads.md`.
175
221
 
222
+ ## Twin And World
223
+
224
+ Public World/Twin reads are available without a token. Owner-scoped Twin actions require a Receiz Connect access token with `receiz:twin.read` or `receiz:twin.write`, issued through a registered OIDC client.
225
+
226
+ ```ts
227
+ import { createReceizClient } from "@receiz/sdk";
228
+
229
+ const publicReceiz = createReceizClient();
230
+ const world = await publicReceiz.world.profile("bjklock");
231
+
232
+ const receiz = createReceizClient({ accessToken: process.env.RECEIZ_ACCESS_TOKEN });
233
+ const mandate = await receiz.twin.marketMandate();
234
+ await receiz.twin.saveMarketMandate({
235
+ status: "active",
236
+ executionMode: "approve",
237
+ maxOrderUsd: "25.00",
238
+ });
239
+ const intent = await receiz.twin.createMarketIntent({
240
+ marketItemId: "asset_123",
241
+ side: "buy",
242
+ amountUsd: "10.00",
243
+ });
244
+ ```
245
+
246
+ Full quickstart: `docs/twin-and-world.md`.
247
+
176
248
  ## Connect Transfers
177
249
 
178
250
  ```ts
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
+ });