@vaultgraph/sdk 0.1.7 → 0.1.8

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
@@ -147,6 +147,31 @@ const updated = await agents.update(created.id, {
147
147
  await agents.delete(updated.id);
148
148
  ```
149
149
 
150
+ ### Manage consumers via the API (server-only)
151
+
152
+ ```ts
153
+ import { createConsumersClient } from "@vaultgraph/sdk";
154
+
155
+ const consumers = createConsumersClient({
156
+ apiKey: process.env.VAULTGRAPH_VENDOR_API_KEY!,
157
+ });
158
+
159
+ const created = await consumers.create({
160
+ name: "Acme Holdings",
161
+ description: "Primary customer record.",
162
+ });
163
+
164
+ const list = await consumers.list();
165
+ const detail = await consumers.get(created.id);
166
+
167
+ const updated = await consumers.update(created.id, {
168
+ name: "Acme Holdings v2",
169
+ description: "Updated customer record.",
170
+ });
171
+
172
+ await consumers.delete(updated.id);
173
+ ```
174
+
150
175
  ## API surface
151
176
 
152
177
  - `hashContext(value, options?)` → sha256 hash of canonical JSON/bytes
@@ -158,8 +183,9 @@ await agents.delete(updated.id);
158
183
  - `submitSignedReceipt(options)` → creates, signs, and submits; defaults `apiUrl` to portal base
159
184
  - `submitReceipt(options)` → POSTs to `/api/receipts` (requires `apiKey`)
160
185
  - `createAgentsClient(options)` → CRUD helper for `/api/agents`
186
+ - `createConsumersClient(options)` → CRUD helper for `/api/consumers`
161
187
  - `generateKeyPair()` → returns PEM-encoded Ed25519 keypair
162
- - Types: `CreateReceiptInput`, `JobReceipt`, `JobReceiptV0`, `JobResolution`, `ReceiptVersion`, `SubmitReceiptOptions`, `SubmitReceiptResponse`, `AgentRecord`, `AgentCreateInput`, `AgentUpdateInput`, `AgentsClientOptions`, `AgentsClient`
188
+ - Types: `CreateReceiptInput`, `JobReceipt`, `JobReceiptV0`, `JobResolution`, `ReceiptVersion`, `SubmitReceiptOptions`, `SubmitReceiptResponse`, `AgentRecord`, `AgentCreateInput`, `AgentUpdateInput`, `AgentsClientOptions`, `AgentsClient`, `ConsumerRecord`, `ConsumerCreateInput`, `ConsumerUpdateInput`, `ConsumersClientOptions`, `ConsumersClient`
163
189
 
164
190
  ## Notes
165
191
 
package/dist/index.d.ts CHANGED
@@ -55,6 +55,59 @@ interface AgentsClient {
55
55
  */
56
56
  declare function createAgentsClient(options: AgentsClientOptions): AgentsClient;
57
57
 
58
+ /**
59
+ * Consumer record returned by the API.
60
+ */
61
+ interface ConsumerRecord {
62
+ id: string;
63
+ name: string;
64
+ description: string | null;
65
+ linked_consumer_org_id: string | null;
66
+ linked_at: string | null;
67
+ created_at: string;
68
+ updated_at: string;
69
+ }
70
+ /**
71
+ * Payload for creating consumers.
72
+ */
73
+ interface ConsumerCreateInput {
74
+ name: string;
75
+ description?: string | null;
76
+ }
77
+ /**
78
+ * Payload for updating consumers.
79
+ */
80
+ interface ConsumerUpdateInput {
81
+ name: string;
82
+ description?: string | null;
83
+ }
84
+ /**
85
+ * Configuration for `createConsumersClient`.
86
+ */
87
+ interface ConsumersClientOptions {
88
+ apiKey: string;
89
+ /** API base URL; defaults to the portal URL (app.vaultgraph.com in prod). */
90
+ apiUrl?: string;
91
+ fetchImpl?: typeof fetch;
92
+ }
93
+ /**
94
+ * Client interface for the consumer API.
95
+ */
96
+ interface ConsumersClient {
97
+ list: () => Promise<ConsumerRecord[]>;
98
+ get: (id: string) => Promise<ConsumerRecord>;
99
+ create: (input: ConsumerCreateInput) => Promise<ConsumerRecord>;
100
+ update: (id: string, input: ConsumerUpdateInput) => Promise<ConsumerRecord>;
101
+ delete: (id: string) => Promise<{
102
+ id: string;
103
+ }>;
104
+ }
105
+
106
+ /**
107
+ * Creates a minimal API client for managing consumers.
108
+ */
109
+ declare function createConsumersClient(options: ConsumersClientOptions): ConsumersClient;
110
+
58
111
  /**
59
112
  * Input for `createSignedReceipt`.
60
113
  */
@@ -102,4 +155,4 @@ declare function generateKeyPair(): {
102
155
  publicKey: string;
103
156
  };
104
157
 
105
- export { type AgentCreateInput, type AgentRecord, type AgentUpdateInput, type AgentsClient, type AgentsClientOptions, type CreateSignedReceiptOptions, type SubmitSignedReceiptOptions, createAgentsClient, createSignedReceipt, generateKeyPair, submitSignedReceipt };
158
+ export { type AgentCreateInput, type AgentRecord, type AgentUpdateInput, type AgentsClient, type AgentsClientOptions, type ConsumerCreateInput, type ConsumerRecord, type ConsumerUpdateInput, type ConsumersClient, type ConsumersClientOptions, type CreateSignedReceiptOptions, type SubmitSignedReceiptOptions, createAgentsClient, createConsumersClient, createSignedReceipt, generateKeyPair, submitSignedReceipt };
package/dist/index.js CHANGED
@@ -260,6 +260,38 @@ async function safeParseJson2(response) {
260
260
  }
261
261
  }
262
262
 
263
+ // src/shared/records.ts
264
+ function extractDataArray(payload, label) {
265
+ if (!payload || typeof payload !== "object") {
266
+ throw new Error(`Invalid ${label} response payload`);
267
+ }
268
+ const data = payload.data;
269
+ if (!Array.isArray(data)) {
270
+ throw new Error(`Invalid ${label} response data`);
271
+ }
272
+ return data;
273
+ }
274
+ function extractDataRecord(payload, label) {
275
+ if (!payload || typeof payload !== "object") {
276
+ throw new Error(`Invalid ${label} response payload`);
277
+ }
278
+ const data = payload.data;
279
+ if (!data || typeof data !== "object") {
280
+ throw new Error(`Invalid ${label} response data`);
281
+ }
282
+ return data;
283
+ }
284
+ function extractDeleteResponse(payload) {
285
+ if (!payload || typeof payload !== "object") {
286
+ throw new Error("Invalid delete response payload");
287
+ }
288
+ const id = payload.id;
289
+ if (!id) {
290
+ throw new Error("Invalid delete response data");
291
+ }
292
+ return { id };
293
+ }
294
+
263
295
  // src/agents/client.ts
264
296
  function createAgentsClient(options) {
265
297
  const { apiKey, apiUrl, fetchImpl } = options;
@@ -335,35 +367,81 @@ function createAgentsClient(options) {
335
367
  }
336
368
  };
337
369
  }
338
- function extractDataArray(payload, label) {
339
- if (!payload || typeof payload !== "object") {
340
- throw new Error(`Invalid ${label} response payload`);
341
- }
342
- const data = payload.data;
343
- if (!Array.isArray(data)) {
344
- throw new Error(`Invalid ${label} response data`);
345
- }
346
- return data;
347
- }
348
- function extractDataRecord(payload, label) {
349
- if (!payload || typeof payload !== "object") {
350
- throw new Error(`Invalid ${label} response payload`);
351
- }
352
- const data = payload.data;
353
- if (!data || typeof data !== "object") {
354
- throw new Error(`Invalid ${label} response data`);
355
- }
356
- return data;
357
- }
358
- function extractDeleteResponse(payload) {
359
- if (!payload || typeof payload !== "object") {
360
- throw new Error("Invalid delete response payload");
361
- }
362
- const id = payload.id;
363
- if (!id) {
364
- throw new Error("Invalid delete response data");
365
- }
366
- return { id };
370
+
371
+ // src/consumers/client.ts
372
+ function createConsumersClient(options) {
373
+ const { apiKey, apiUrl, fetchImpl } = options;
374
+ const targetApiUrl = apiUrl ?? getPortalURL();
375
+ assertNonEmpty(apiKey, "apiKey");
376
+ assertNonEmpty(targetApiUrl, "apiUrl");
377
+ return {
378
+ list: async () => {
379
+ const payload = await requestJson({
380
+ apiUrl: targetApiUrl,
381
+ apiKey,
382
+ path: "/api/consumers",
383
+ method: "GET",
384
+ fetchImpl
385
+ });
386
+ return extractDataArray(payload, "consumers");
387
+ },
388
+ get: async (id) => {
389
+ assertNonEmpty(id, "id");
390
+ const encodedId = encodeURIComponent(id);
391
+ const payload = await requestJson({
392
+ apiUrl: targetApiUrl,
393
+ apiKey,
394
+ path: `/api/consumers/${encodedId}`,
395
+ method: "GET",
396
+ fetchImpl
397
+ });
398
+ return extractDataRecord(payload, "consumer");
399
+ },
400
+ create: async (input) => {
401
+ assertNonEmpty(input.name, "name");
402
+ const payload = await requestJson({
403
+ apiUrl: targetApiUrl,
404
+ apiKey,
405
+ path: "/api/consumers",
406
+ method: "POST",
407
+ body: {
408
+ name: input.name,
409
+ description: input.description ?? null
410
+ },
411
+ fetchImpl
412
+ });
413
+ return extractDataRecord(payload, "consumer");
414
+ },
415
+ update: async (id, input) => {
416
+ assertNonEmpty(id, "id");
417
+ assertNonEmpty(input.name, "name");
418
+ const encodedId = encodeURIComponent(id);
419
+ const payload = await requestJson({
420
+ apiUrl: targetApiUrl,
421
+ apiKey,
422
+ path: `/api/consumers/${encodedId}`,
423
+ method: "PUT",
424
+ body: {
425
+ name: input.name,
426
+ description: input.description ?? null
427
+ },
428
+ fetchImpl
429
+ });
430
+ return extractDataRecord(payload, "consumer");
431
+ },
432
+ delete: async (id) => {
433
+ assertNonEmpty(id, "id");
434
+ const encodedId = encodeURIComponent(id);
435
+ const payload = await requestJson({
436
+ apiUrl: targetApiUrl,
437
+ apiKey,
438
+ path: `/api/consumers/${encodedId}`,
439
+ method: "DELETE",
440
+ fetchImpl
441
+ });
442
+ return extractDeleteResponse(payload);
443
+ }
444
+ };
367
445
  }
368
446
  function createSignedReceipt(options) {
369
447
  const { privateKey, algorithm, encoding, ...receiptInput } = options;
@@ -398,4 +476,4 @@ function generateKeyPair() {
398
476
  return { privateKey, publicKey };
399
477
  }
400
478
 
401
- export { JOB_RESOLUTIONS, canonicalJSONStringify, createAgentsClient, createReceipt, createSignedReceipt, generateKeyPair, hashContext, jobReceiptV0Schema, serializeReceipt, signReceipt, submitReceipt, submitSignedReceipt, verifyReceipt };
479
+ export { JOB_RESOLUTIONS, canonicalJSONStringify, createAgentsClient, createConsumersClient, createReceipt, createSignedReceipt, generateKeyPair, hashContext, jobReceiptV0Schema, serializeReceipt, signReceipt, submitReceipt, submitSignedReceipt, verifyReceipt };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaultgraph/sdk",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "license": "MIT",