@nodatachat/sdk 1.0.0 → 2.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.
@@ -1,47 +1 @@
1
- import {
2
- NoData
3
- } from "../chunk-V6GUTSNO.mjs";
4
-
5
- // src/plugins/fastify.ts
6
- function nodataFastify(fastify, config, done) {
7
- const nd = new NoData({ apiKey: config.apiKey, baseUrl: config.baseUrl });
8
- const encryptFields = config.encryptFields || [];
9
- const decryptFields = config.decryptFields || [];
10
- const skipPaths = config.skipPaths || [];
11
- if (decryptFields.length > 0) {
12
- fastify.addHook("preHandler", async (request) => {
13
- if (skipPaths.some((p) => request.url.startsWith(p))) return;
14
- if (!request.body || typeof request.body !== "object") return;
15
- if (request.method === "GET") return;
16
- const shouldDecrypt = !config.decryptHeader || request.headers[config.decryptHeader.toLowerCase()];
17
- if (shouldDecrypt) {
18
- try {
19
- request.body = await nd.decryptObject(
20
- request.body,
21
- decryptFields,
22
- request.headers["x-requester"] || "fastify-plugin"
23
- );
24
- } catch {
25
- }
26
- }
27
- });
28
- }
29
- if (encryptFields.length > 0) {
30
- fastify.addHook("onSend", async (_request, _reply, payload) => {
31
- if (typeof payload !== "string") return payload;
32
- try {
33
- const parsed = JSON.parse(payload);
34
- if (typeof parsed === "object" && parsed !== null) {
35
- const encrypted = await nd.encryptObject(parsed, encryptFields, config.context);
36
- return JSON.stringify(encrypted);
37
- }
38
- } catch {
39
- }
40
- return payload;
41
- });
42
- }
43
- done();
44
- }
45
- export {
46
- nodataFastify
47
- };
1
+ import{r as d}from"../chunk-R62LOWK3.mjs";function f(a,e,i){let o=new d({apiKey:e.apiKey,baseUrl:e.baseUrl}),s=e.encryptFields||[],y=e.decryptFields||[],p=e.skipPaths||[];y.length>0&&a.addHook("preHandler",async t=>{if(p.some(r=>t.url.startsWith(r))||!t.body||typeof t.body!="object"||t.method==="GET")return;if(!e.decryptHeader||t.headers[e.decryptHeader.toLowerCase()])try{t.body=await o.decryptObject(t.body,y,t.headers["x-requester"]||"fastify-plugin")}catch{}}),s.length>0&&a.addHook("onSend",async(t,c,r)=>{if(typeof r!="string")return r;try{let n=JSON.parse(r);if(typeof n=="object"&&n!==null){let l=await o.encryptObject(n,s,e.context);return JSON.stringify(l)}}catch{}return r}),i()}export{f as nodataFastify};
@@ -1,7 +1,7 @@
1
1
  interface NoDataConfig {
2
- /** API key (sk_live_...) — get from https://www.nodatachat.com/developers */
2
+ /** API key (sk_live_...) — get from https://www.nodatacapsule.com/developers */
3
3
  apiKey: string;
4
- /** Base URL (default: https://www.nodatachat.com) */
4
+ /** Base URL (default: https://www.nodatacapsule.com) */
5
5
  baseUrl?: string;
6
6
  /** Timeout in ms (default: 30000) */
7
7
  timeout?: number;
@@ -223,6 +223,135 @@ interface PluginConfig {
223
223
  /** Audit context */
224
224
  context?: string;
225
225
  }
226
+ interface RegisterTableRequest {
227
+ /** Your table name (also the scope key in grants). */
228
+ table: string;
229
+ /** Columns stored as <col>_ct/_iv/_tag triplets · per-column key release. */
230
+ encryptedColumns?: string[];
231
+ /** Plaintext columns returned as-is (filters / classification metadata). */
232
+ plaintextColumns?: string[];
233
+ /** Which plaintext column carries the classification value. */
234
+ classificationColumn?: string;
235
+ /** HKDF namespace · stable forever (default at_<table>). */
236
+ hkdfPrefix?: string;
237
+ /** Display label. */
238
+ uiLabel?: string;
239
+ }
240
+ interface RegisteredTable {
241
+ table_name: string;
242
+ encrypted_columns: string[];
243
+ plaintext_columns: string[];
244
+ classification_column: string | null;
245
+ hkdf_prefix: string;
246
+ ui_label: string | null;
247
+ active: boolean;
248
+ }
249
+ interface RegisterTableResponse {
250
+ success?: boolean;
251
+ table?: RegisteredTable;
252
+ tables?: RegisteredTable[];
253
+ }
254
+ interface GrantRequest {
255
+ /** Agent label · becomes its handle (slugified, made unique). */
256
+ agent: string;
257
+ /** Target table (default agent_demo_records). */
258
+ table?: string;
259
+ /** Columns the agent may read · must be registered for the table. */
260
+ columns: string[];
261
+ /** Equality filter · plaintext columns only. */
262
+ where?: Record<string, string | number | boolean>;
263
+ /** Allowed classification values · empty = no classification gating. */
264
+ classifications?: string[];
265
+ /** Token lifetime in seconds (default 30d, max 1y). */
266
+ ttlSeconds?: number;
267
+ }
268
+ interface GrantResponse {
269
+ success: boolean;
270
+ /** The bearer token the agent presents to read · shown ONCE. */
271
+ grant_token: string;
272
+ handle: string;
273
+ agent_id: string;
274
+ jti: string;
275
+ table: string;
276
+ columns: string[];
277
+ classifications: string[];
278
+ expires_at: string;
279
+ read_url: string;
280
+ note?: string;
281
+ }
282
+ interface RevokeRequest {
283
+ /** Agent handle · revokes all active credentials for the agent. */
284
+ agent?: string;
285
+ /** Or a specific credential jti. */
286
+ jti?: string;
287
+ reason?: string;
288
+ }
289
+ interface RevokeResponse {
290
+ success: boolean;
291
+ revoked: number;
292
+ jtis?: string[];
293
+ }
294
+ interface AgentReadRequest {
295
+ table: string;
296
+ columns: string[];
297
+ where?: Record<string, string | number | boolean>;
298
+ limit?: number;
299
+ /** Agent handle · auto-derived from the grant token if omitted. */
300
+ handle?: string;
301
+ }
302
+ interface AgentReadResponse {
303
+ rows: Array<Record<string, unknown>>;
304
+ count: number;
305
+ audit: {
306
+ id: string;
307
+ chain_index: number;
308
+ } | null;
309
+ }
310
+ type Clearance = 'public' | 'internal' | 'confidential' | 'restricted';
311
+ interface ComputeRequest {
312
+ /** The intent — what the AI is asking to do with the information. */
313
+ question: string;
314
+ /** The reader's clearance ceiling (default 'internal'). Anything above it is withheld. */
315
+ clearance?: Clearance;
316
+ /** The information to reason over — titled sections… */
317
+ sections?: Array<{
318
+ title?: string;
319
+ text: string;
320
+ }>;
321
+ /** …or a single blob of text (use one of sections/text). */
322
+ text?: string;
323
+ }
324
+ interface ComputeSection {
325
+ title: string;
326
+ classification: string;
327
+ /** true = this section was authorized and sent to the model; false = withheld by policy. */
328
+ sent: boolean;
329
+ }
330
+ interface ComputeDecision {
331
+ /** allow = at least one section was authorized; deny = everything was above clearance. */
332
+ decision: 'allow' | 'deny';
333
+ /** The model's answer over ONLY the authorized sections, or null if the model was unavailable / nothing was authorized. */
334
+ answer: string | null;
335
+ /** Which model answered ('gemini' | 'claude'), or null. */
336
+ model: string | null;
337
+ /** Every section, flagged sent vs withheld — the authorized view. */
338
+ sections: ComputeSection[];
339
+ /** A signed, hash-chained proof of the decision. Verify it with nd.verify(proof.id). */
340
+ proof: {
341
+ id: string | null;
342
+ hash: string | null;
343
+ persisted: boolean;
344
+ };
345
+ }
346
+ interface VerifyResult {
347
+ /** true iff the proof exists and its hash-chain re-verifies. "No proof" is never "fine". */
348
+ authentic: boolean;
349
+ unaltered: boolean;
350
+ signer?: string;
351
+ surface?: string;
352
+ decision?: string;
353
+ issuedAt?: string;
354
+ }
226
355
  declare class NoDataError extends Error {
227
356
  status: number;
228
357
  code?: string | undefined;
@@ -230,4 +359,4 @@ declare class NoDataError extends Error {
230
359
  constructor(message: string, status: number, code?: string | undefined, retryAfter?: number | undefined);
231
360
  }
232
361
 
233
- export { type BatchResult as B, type ChannelCreateRequest as C, type DeliverRequest as D, type EvidenceQuery as E, type NoDataConfig as N, type PluginConfig as P, type VaultCreateRequest as V, type WebhookChannelCreateRequest as W, type ChannelCreateResponse as a, type ChannelSendRequest as b, type ChannelSendResponse as c, type ChannelReceiveRequest as d, type ChannelReceiveResponse as e, type WebhookChannelCreateResponse as f, type WebhookEventsResponse as g, type DeliverResponse as h, type EvidenceResponse as i, type VaultCreateResponse as j, type VaultReadResponse as k, type EncryptRequest as l, type EncryptResponse as m, type DecryptRequest as n, type DecryptResponse as o, type EvidenceEntry as p, NoDataError as q, type WebhookEvent as r };
362
+ export { type AgentReadRequest as A, type BatchResult as B, type ChannelCreateRequest as C, type DeliverRequest as D, type EvidenceQuery as E, type EvidenceEntry as F, type GrantRequest as G, type RegisteredTable as H, type WebhookEvent as I, type NoDataConfig as N, type PluginConfig as P, type RegisterTableRequest as R, type VaultCreateRequest as V, type WebhookChannelCreateRequest as W, type AgentReadResponse as a, type RegisterTableResponse as b, type GrantResponse as c, type RevokeRequest as d, type RevokeResponse as e, type VaultCreateResponse as f, type VaultReadResponse as g, type EvidenceResponse as h, type DeliverResponse as i, type WebhookChannelCreateResponse as j, type WebhookEventsResponse as k, type ChannelCreateResponse as l, type ChannelSendRequest as m, type ChannelSendResponse as n, type ChannelReceiveRequest as o, type ChannelReceiveResponse as p, type EncryptRequest as q, type EncryptResponse as r, type DecryptRequest as s, type DecryptResponse as t, NoDataError as u, type ComputeRequest as v, type ComputeDecision as w, type VerifyResult as x, type Clearance as y, type ComputeSection as z };
@@ -1,7 +1,7 @@
1
1
  interface NoDataConfig {
2
- /** API key (sk_live_...) — get from https://www.nodatachat.com/developers */
2
+ /** API key (sk_live_...) — get from https://www.nodatacapsule.com/developers */
3
3
  apiKey: string;
4
- /** Base URL (default: https://www.nodatachat.com) */
4
+ /** Base URL (default: https://www.nodatacapsule.com) */
5
5
  baseUrl?: string;
6
6
  /** Timeout in ms (default: 30000) */
7
7
  timeout?: number;
@@ -223,6 +223,135 @@ interface PluginConfig {
223
223
  /** Audit context */
224
224
  context?: string;
225
225
  }
226
+ interface RegisterTableRequest {
227
+ /** Your table name (also the scope key in grants). */
228
+ table: string;
229
+ /** Columns stored as <col>_ct/_iv/_tag triplets · per-column key release. */
230
+ encryptedColumns?: string[];
231
+ /** Plaintext columns returned as-is (filters / classification metadata). */
232
+ plaintextColumns?: string[];
233
+ /** Which plaintext column carries the classification value. */
234
+ classificationColumn?: string;
235
+ /** HKDF namespace · stable forever (default at_<table>). */
236
+ hkdfPrefix?: string;
237
+ /** Display label. */
238
+ uiLabel?: string;
239
+ }
240
+ interface RegisteredTable {
241
+ table_name: string;
242
+ encrypted_columns: string[];
243
+ plaintext_columns: string[];
244
+ classification_column: string | null;
245
+ hkdf_prefix: string;
246
+ ui_label: string | null;
247
+ active: boolean;
248
+ }
249
+ interface RegisterTableResponse {
250
+ success?: boolean;
251
+ table?: RegisteredTable;
252
+ tables?: RegisteredTable[];
253
+ }
254
+ interface GrantRequest {
255
+ /** Agent label · becomes its handle (slugified, made unique). */
256
+ agent: string;
257
+ /** Target table (default agent_demo_records). */
258
+ table?: string;
259
+ /** Columns the agent may read · must be registered for the table. */
260
+ columns: string[];
261
+ /** Equality filter · plaintext columns only. */
262
+ where?: Record<string, string | number | boolean>;
263
+ /** Allowed classification values · empty = no classification gating. */
264
+ classifications?: string[];
265
+ /** Token lifetime in seconds (default 30d, max 1y). */
266
+ ttlSeconds?: number;
267
+ }
268
+ interface GrantResponse {
269
+ success: boolean;
270
+ /** The bearer token the agent presents to read · shown ONCE. */
271
+ grant_token: string;
272
+ handle: string;
273
+ agent_id: string;
274
+ jti: string;
275
+ table: string;
276
+ columns: string[];
277
+ classifications: string[];
278
+ expires_at: string;
279
+ read_url: string;
280
+ note?: string;
281
+ }
282
+ interface RevokeRequest {
283
+ /** Agent handle · revokes all active credentials for the agent. */
284
+ agent?: string;
285
+ /** Or a specific credential jti. */
286
+ jti?: string;
287
+ reason?: string;
288
+ }
289
+ interface RevokeResponse {
290
+ success: boolean;
291
+ revoked: number;
292
+ jtis?: string[];
293
+ }
294
+ interface AgentReadRequest {
295
+ table: string;
296
+ columns: string[];
297
+ where?: Record<string, string | number | boolean>;
298
+ limit?: number;
299
+ /** Agent handle · auto-derived from the grant token if omitted. */
300
+ handle?: string;
301
+ }
302
+ interface AgentReadResponse {
303
+ rows: Array<Record<string, unknown>>;
304
+ count: number;
305
+ audit: {
306
+ id: string;
307
+ chain_index: number;
308
+ } | null;
309
+ }
310
+ type Clearance = 'public' | 'internal' | 'confidential' | 'restricted';
311
+ interface ComputeRequest {
312
+ /** The intent — what the AI is asking to do with the information. */
313
+ question: string;
314
+ /** The reader's clearance ceiling (default 'internal'). Anything above it is withheld. */
315
+ clearance?: Clearance;
316
+ /** The information to reason over — titled sections… */
317
+ sections?: Array<{
318
+ title?: string;
319
+ text: string;
320
+ }>;
321
+ /** …or a single blob of text (use one of sections/text). */
322
+ text?: string;
323
+ }
324
+ interface ComputeSection {
325
+ title: string;
326
+ classification: string;
327
+ /** true = this section was authorized and sent to the model; false = withheld by policy. */
328
+ sent: boolean;
329
+ }
330
+ interface ComputeDecision {
331
+ /** allow = at least one section was authorized; deny = everything was above clearance. */
332
+ decision: 'allow' | 'deny';
333
+ /** The model's answer over ONLY the authorized sections, or null if the model was unavailable / nothing was authorized. */
334
+ answer: string | null;
335
+ /** Which model answered ('gemini' | 'claude'), or null. */
336
+ model: string | null;
337
+ /** Every section, flagged sent vs withheld — the authorized view. */
338
+ sections: ComputeSection[];
339
+ /** A signed, hash-chained proof of the decision. Verify it with nd.verify(proof.id). */
340
+ proof: {
341
+ id: string | null;
342
+ hash: string | null;
343
+ persisted: boolean;
344
+ };
345
+ }
346
+ interface VerifyResult {
347
+ /** true iff the proof exists and its hash-chain re-verifies. "No proof" is never "fine". */
348
+ authentic: boolean;
349
+ unaltered: boolean;
350
+ signer?: string;
351
+ surface?: string;
352
+ decision?: string;
353
+ issuedAt?: string;
354
+ }
226
355
  declare class NoDataError extends Error {
227
356
  status: number;
228
357
  code?: string | undefined;
@@ -230,4 +359,4 @@ declare class NoDataError extends Error {
230
359
  constructor(message: string, status: number, code?: string | undefined, retryAfter?: number | undefined);
231
360
  }
232
361
 
233
- export { type BatchResult as B, type ChannelCreateRequest as C, type DeliverRequest as D, type EvidenceQuery as E, type NoDataConfig as N, type PluginConfig as P, type VaultCreateRequest as V, type WebhookChannelCreateRequest as W, type ChannelCreateResponse as a, type ChannelSendRequest as b, type ChannelSendResponse as c, type ChannelReceiveRequest as d, type ChannelReceiveResponse as e, type WebhookChannelCreateResponse as f, type WebhookEventsResponse as g, type DeliverResponse as h, type EvidenceResponse as i, type VaultCreateResponse as j, type VaultReadResponse as k, type EncryptRequest as l, type EncryptResponse as m, type DecryptRequest as n, type DecryptResponse as o, type EvidenceEntry as p, NoDataError as q, type WebhookEvent as r };
362
+ export { type AgentReadRequest as A, type BatchResult as B, type ChannelCreateRequest as C, type DeliverRequest as D, type EvidenceQuery as E, type EvidenceEntry as F, type GrantRequest as G, type RegisteredTable as H, type WebhookEvent as I, type NoDataConfig as N, type PluginConfig as P, type RegisterTableRequest as R, type VaultCreateRequest as V, type WebhookChannelCreateRequest as W, type AgentReadResponse as a, type RegisterTableResponse as b, type GrantResponse as c, type RevokeRequest as d, type RevokeResponse as e, type VaultCreateResponse as f, type VaultReadResponse as g, type EvidenceResponse as h, type DeliverResponse as i, type WebhookChannelCreateResponse as j, type WebhookEventsResponse as k, type ChannelCreateResponse as l, type ChannelSendRequest as m, type ChannelSendResponse as n, type ChannelReceiveRequest as o, type ChannelReceiveResponse as p, type EncryptRequest as q, type EncryptResponse as r, type DecryptRequest as s, type DecryptResponse as t, NoDataError as u, type ComputeRequest as v, type ComputeDecision as w, type VerifyResult as x, type Clearance as y, type ComputeSection as z };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nodatachat/sdk",
3
- "version": "1.0.0",
4
- "description": "NoData M2M SDK — Blind relay encryption, secure channels, and zero-knowledge delivery for machine-to-machine communication.",
3
+ "version": "2.1.0",
4
+ "description": "NoData SDK for the Information Access Processor: one call decides whether an identity may access information and returns a signed proof.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",
@@ -22,43 +22,49 @@
22
22
  "require": "./dist/plugins/fastify.js"
23
23
  }
24
24
  },
25
- "files": ["dist", "README.md"],
25
+ "files": [
26
+ "dist",
27
+ "README.md",
28
+ "LICENSE.md"
29
+ ],
26
30
  "scripts": {
27
- "build": "tsup src/index.ts src/plugins/express.ts src/plugins/fastify.ts --format esm,cjs --dts",
31
+ "build": "tsup src/index.ts src/plugins/express.ts src/plugins/fastify.ts --format esm,cjs --dts --minify --clean",
28
32
  "dev": "tsup --watch",
29
33
  "test": "vitest run",
30
34
  "prepublishOnly": "npm run build"
31
35
  },
32
36
  "keywords": [
33
37
  "nodata",
34
- "encryption",
35
- "m2m",
36
- "machine-to-machine",
37
- "blind-relay",
38
- "zero-knowledge",
39
- "pii",
40
- "soc",
41
- "compliance",
42
- "field-level-encryption",
43
- "sdk"
38
+ "sdk",
39
+ "information-access-processor",
40
+ "access-control",
41
+ "governance",
42
+ "ai-agents",
43
+ "capsule",
44
+ "receipts",
45
+ "encryption"
44
46
  ],
45
- "license": "MIT",
46
- "repository": {
47
- "type": "git",
48
- "url": "https://github.com/nodatachat/sdk"
49
- },
50
- "homepage": "https://www.nodatachat.com/developers",
47
+ "license": "FSL-1.1-ALv2",
48
+ "homepage": "https://www.nodatacapsule.com/developers",
51
49
  "peerDependencies": {
52
50
  "express": ">=4.0.0",
53
51
  "fastify": ">=4.0.0"
54
52
  },
55
53
  "peerDependenciesMeta": {
56
- "express": { "optional": true },
57
- "fastify": { "optional": true }
54
+ "express": {
55
+ "optional": true
56
+ },
57
+ "fastify": {
58
+ "optional": true
59
+ }
58
60
  },
59
61
  "devDependencies": {
60
62
  "tsup": "^8.0.0",
61
63
  "typescript": "^5.7.0",
62
64
  "vitest": "^3.0.0"
65
+ },
66
+ "author": "Capsule Ltd.",
67
+ "engines": {
68
+ "node": ">=18.0.0"
63
69
  }
64
70
  }