@truststate/sdk 0.2.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/LICENSE +21 -0
- package/README.md +230 -0
- package/dist/client.d.ts +96 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +346 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +9 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +17 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware.d.ts +93 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +129 -0
- package/dist/middleware.js.map +1 -0
- package/dist/types.d.ts +121 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/package.json +45 -0
- package/src/client.ts +448 -0
- package/src/errors.ts +15 -0
- package/src/index.ts +23 -0
- package/src/middleware.ts +224 -0
- package/src/types.ts +122 -0
package/dist/client.js
ADDED
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* TrustStateClient — async HTTP client for the TrustState compliance API.
|
|
4
|
+
*
|
|
5
|
+
* Uses native fetch (Node 18+) and crypto.randomUUID(). Zero runtime dependencies.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { TrustStateClient } from "@truststate/sdk";
|
|
10
|
+
*
|
|
11
|
+
* const client = new TrustStateClient({ apiKey: "your-key" });
|
|
12
|
+
* const result = await client.check("AgentResponse", { text: "Hello!", score: 0.95 });
|
|
13
|
+
* console.log(result.passed, result.recordId);
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.TrustStateClient = void 0;
|
|
18
|
+
const errors_js_1 = require("./errors.js");
|
|
19
|
+
const DEFAULT_BASE_URL = "https://truststate-api.apps.trustchainlabs.com";
|
|
20
|
+
class TrustStateClient {
|
|
21
|
+
constructor(options) {
|
|
22
|
+
this.apiKey = options.apiKey;
|
|
23
|
+
this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "");
|
|
24
|
+
this.defaultSchemaVersion = options.defaultSchemaVersion ?? "1.0";
|
|
25
|
+
this.defaultActorId = options.defaultActorId ?? "";
|
|
26
|
+
this.mock = options.mock ?? false;
|
|
27
|
+
this.mockPassRate = options.mockPassRate ?? 1.0;
|
|
28
|
+
this.timeoutMs = options.timeoutMs ?? 30000;
|
|
29
|
+
}
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
// Public API
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
/**
|
|
34
|
+
* Submit a single record for compliance checking.
|
|
35
|
+
*
|
|
36
|
+
* Internally wraps the record in a one-item batch call (POST /v1/write/batch).
|
|
37
|
+
*
|
|
38
|
+
* @param entityType - Entity category (e.g. "AgentResponse").
|
|
39
|
+
* @param data - The record payload to validate.
|
|
40
|
+
* @param options - Optional overrides for action, entityId, schemaVersion, actorId.
|
|
41
|
+
* @returns ComplianceResult with pass/fail status and, if passed, a recordId.
|
|
42
|
+
* @throws TrustStateError on HTTP 4xx/5xx.
|
|
43
|
+
*/
|
|
44
|
+
async check(entityType, data, options = {}) {
|
|
45
|
+
const entityId = options.entityId ?? crypto.randomUUID();
|
|
46
|
+
if (this.mock) {
|
|
47
|
+
return this.mockSingleResult(entityId);
|
|
48
|
+
}
|
|
49
|
+
const batchResult = await this.checkBatch([
|
|
50
|
+
{
|
|
51
|
+
entityType,
|
|
52
|
+
data,
|
|
53
|
+
action: options.action,
|
|
54
|
+
entityId,
|
|
55
|
+
schemaVersion: options.schemaVersion,
|
|
56
|
+
actorId: options.actorId,
|
|
57
|
+
},
|
|
58
|
+
], {
|
|
59
|
+
defaultSchemaVersion: options.schemaVersion,
|
|
60
|
+
defaultActorId: options.actorId,
|
|
61
|
+
});
|
|
62
|
+
return batchResult.results[0];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Submit multiple records for compliance checking in a single API call.
|
|
66
|
+
*
|
|
67
|
+
* @param items - Array of CheckItem objects.
|
|
68
|
+
* @param options - Optional default schemaVersion and actorId for items that omit them.
|
|
69
|
+
* @returns BatchResult with per-item results and aggregate counts.
|
|
70
|
+
* @throws TrustStateError on HTTP 4xx/5xx.
|
|
71
|
+
*/
|
|
72
|
+
async checkBatch(items, options = {}) {
|
|
73
|
+
const schemaVer = options.defaultSchemaVersion ?? this.defaultSchemaVersion;
|
|
74
|
+
const actor = options.defaultActorId ?? this.defaultActorId;
|
|
75
|
+
// Normalise items — assign missing entity IDs and fill defaults
|
|
76
|
+
const normalised = items.map((item) => {
|
|
77
|
+
const entry = {
|
|
78
|
+
entityType: item.entityType,
|
|
79
|
+
data: item.data,
|
|
80
|
+
action: item.action ?? "upsert",
|
|
81
|
+
entityId: item.entityId ?? crypto.randomUUID(),
|
|
82
|
+
actorId: item.actorId ?? actor ?? "sdk-writer",
|
|
83
|
+
};
|
|
84
|
+
const sv = item.schemaVersion ?? schemaVer;
|
|
85
|
+
if (sv)
|
|
86
|
+
entry.schemaVersion = sv;
|
|
87
|
+
return entry;
|
|
88
|
+
});
|
|
89
|
+
if (this.mock) {
|
|
90
|
+
return this.mockBatchResult(normalised, options.feedLabel);
|
|
91
|
+
}
|
|
92
|
+
const payload = { items: normalised };
|
|
93
|
+
if (schemaVer)
|
|
94
|
+
payload.defaultSchemaVersion = schemaVer;
|
|
95
|
+
if (actor)
|
|
96
|
+
payload.defaultActorId = actor;
|
|
97
|
+
if (options.feedLabel)
|
|
98
|
+
payload.feedLabel = options.feedLabel;
|
|
99
|
+
const responseJson = await this.post("/v1/write/batch", payload);
|
|
100
|
+
return this.parseBatchResponse(responseJson);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Retrieve an immutable compliance record from the ledger.
|
|
104
|
+
*
|
|
105
|
+
* @param recordId - The record ID returned by a previous check() that passed.
|
|
106
|
+
* @param bearerToken - A valid Bearer token for the TrustState API.
|
|
107
|
+
* @returns The full record object from the API.
|
|
108
|
+
* @throws TrustStateError on HTTP 4xx/5xx.
|
|
109
|
+
*/
|
|
110
|
+
// ---------------------------------------------------------------------------
|
|
111
|
+
// BYOP Evidence fetch helpers
|
|
112
|
+
// ---------------------------------------------------------------------------
|
|
113
|
+
/** Fetch an FX rate oracle evidence item.
|
|
114
|
+
* @example
|
|
115
|
+
* const fx = await client.fetchFxRate("MYR", "USD");
|
|
116
|
+
* const result = await client.checkWithEvidence("SukukBond", data, [fx]);
|
|
117
|
+
*/
|
|
118
|
+
async fetchFxRate(fromCurrency, toCurrency, providerId = "reuters-fx", maxAgeSeconds = 300) {
|
|
119
|
+
const subject = { from: fromCurrency, to: toCurrency };
|
|
120
|
+
if (this.mock) {
|
|
121
|
+
const stubs = { MYR_USD: 0.2119, USD_MYR: 4.72, EUR_USD: 1.085, GBP_USD: 1.267 };
|
|
122
|
+
return this.makeEvidenceItem(providerId, "fx_rate", subject, stubs[`${fromCurrency}_${toCurrency}`] ?? 1.0, maxAgeSeconds);
|
|
123
|
+
}
|
|
124
|
+
const data = await this.get(`/v1/oracle/fx-rate?from=${fromCurrency}&to=${toCurrency}&providerId=${providerId}`);
|
|
125
|
+
return this.parseEvidenceResponse(data, providerId, "fx_rate", subject, maxAgeSeconds);
|
|
126
|
+
}
|
|
127
|
+
/** Fetch a KYC status oracle evidence item. */
|
|
128
|
+
async fetchKycStatus(subjectId, providerId = "sumsub-kyc", maxAgeSeconds = 86400) {
|
|
129
|
+
const subject = { id: subjectId };
|
|
130
|
+
if (this.mock) {
|
|
131
|
+
return this.makeEvidenceItem(providerId, "kyc_status", subject, "PASS", maxAgeSeconds);
|
|
132
|
+
}
|
|
133
|
+
const data = await this.get(`/v1/oracle/kyc-status?subjectId=${subjectId}&providerId=${providerId}`);
|
|
134
|
+
return this.parseEvidenceResponse(data, providerId, "kyc_status", subject, maxAgeSeconds);
|
|
135
|
+
}
|
|
136
|
+
/** Fetch a credit score oracle evidence item. */
|
|
137
|
+
async fetchCreditScore(subjectId, providerId = "coface-credit", maxAgeSeconds = 86400) {
|
|
138
|
+
const subject = { id: subjectId };
|
|
139
|
+
if (this.mock) {
|
|
140
|
+
return this.makeEvidenceItem(providerId, "credit_score", subject, 720, maxAgeSeconds);
|
|
141
|
+
}
|
|
142
|
+
const data = await this.get(`/v1/oracle/credit-score?subjectId=${subjectId}&providerId=${providerId}`);
|
|
143
|
+
return this.parseEvidenceResponse(data, providerId, "credit_score", subject, maxAgeSeconds);
|
|
144
|
+
}
|
|
145
|
+
/** Fetch a sanctions screening oracle evidence item. */
|
|
146
|
+
async fetchSanctions(subjectId, providerId = "refinitiv-sanct", maxAgeSeconds = 3600) {
|
|
147
|
+
const subject = { id: subjectId };
|
|
148
|
+
if (this.mock) {
|
|
149
|
+
return this.makeEvidenceItem(providerId, "sanctions", subject, "CLEAR", maxAgeSeconds);
|
|
150
|
+
}
|
|
151
|
+
const data = await this.get(`/v1/oracle/sanctions?subjectId=${subjectId}&providerId=${providerId}`);
|
|
152
|
+
return this.parseEvidenceResponse(data, providerId, "sanctions", subject, maxAgeSeconds);
|
|
153
|
+
}
|
|
154
|
+
/** Submit a compliance check with oracle evidence attached.
|
|
155
|
+
* @example
|
|
156
|
+
* const fx = await client.fetchFxRate("MYR", "USD");
|
|
157
|
+
* const result = await client.checkWithEvidence("SukukBond", payload, [fx]);
|
|
158
|
+
*/
|
|
159
|
+
async checkWithEvidence(entityType, data, evidence, options = {}) {
|
|
160
|
+
if (this.mock)
|
|
161
|
+
return this.mockSingleResult(options.entityId ?? crypto.randomUUID());
|
|
162
|
+
const entityId = options.entityId ?? crypto.randomUUID();
|
|
163
|
+
const schemaVersion = options.schemaVersion ?? this.defaultSchemaVersion;
|
|
164
|
+
const actorId = options.actorId ?? this.defaultActorId;
|
|
165
|
+
const item = {
|
|
166
|
+
entityType,
|
|
167
|
+
data,
|
|
168
|
+
action: options.action ?? "upsert",
|
|
169
|
+
entityId,
|
|
170
|
+
actorId: actorId ?? "sdk-writer",
|
|
171
|
+
evidence,
|
|
172
|
+
};
|
|
173
|
+
if (schemaVersion)
|
|
174
|
+
item.schemaVersion = schemaVersion;
|
|
175
|
+
const response = await this.post("/v1/write/batch", { items: [item] });
|
|
176
|
+
return this.parseBatchResponse(response).results[0];
|
|
177
|
+
}
|
|
178
|
+
makeEvidenceItem(providerId, providerType, subject, observedValue, maxAgeSeconds) {
|
|
179
|
+
const now = new Date().toISOString();
|
|
180
|
+
return {
|
|
181
|
+
evidenceId: crypto.randomUUID(),
|
|
182
|
+
providerId,
|
|
183
|
+
providerType,
|
|
184
|
+
subject,
|
|
185
|
+
observedValue,
|
|
186
|
+
observedAt: now,
|
|
187
|
+
retrievedAt: now,
|
|
188
|
+
maxAgeSeconds,
|
|
189
|
+
mock: true,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
parseEvidenceResponse(data, defaultProviderId, providerType, subject, maxAgeSeconds) {
|
|
193
|
+
return {
|
|
194
|
+
evidenceId: crypto.randomUUID(),
|
|
195
|
+
providerId: data.providerId ?? defaultProviderId,
|
|
196
|
+
providerType,
|
|
197
|
+
subject,
|
|
198
|
+
observedValue: data.observedValue,
|
|
199
|
+
observedAt: data.observedAt,
|
|
200
|
+
retrievedAt: new Date().toISOString(),
|
|
201
|
+
maxAgeSeconds,
|
|
202
|
+
proofHash: data.proofHash,
|
|
203
|
+
rawProofUri: data.rawProofUri,
|
|
204
|
+
attestation: data.attestation,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
async verify(recordId, bearerToken) {
|
|
208
|
+
const url = `${this.baseUrl}/v1/records/${recordId}`;
|
|
209
|
+
const controller = new AbortController();
|
|
210
|
+
const timerId = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
211
|
+
let response;
|
|
212
|
+
try {
|
|
213
|
+
response = await fetch(url, {
|
|
214
|
+
method: "GET",
|
|
215
|
+
headers: { Authorization: `Bearer ${bearerToken}` },
|
|
216
|
+
signal: controller.signal,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
catch (err) {
|
|
220
|
+
throw new errors_js_1.TrustStateError(`Network error: ${err.message}`);
|
|
221
|
+
}
|
|
222
|
+
finally {
|
|
223
|
+
clearTimeout(timerId);
|
|
224
|
+
}
|
|
225
|
+
if (!response.ok) {
|
|
226
|
+
const body = await response.text().catch(() => "");
|
|
227
|
+
throw new errors_js_1.TrustStateError(`API error ${response.status}: ${body}`, response.status);
|
|
228
|
+
}
|
|
229
|
+
return response.json();
|
|
230
|
+
}
|
|
231
|
+
// ---------------------------------------------------------------------------
|
|
232
|
+
// Internal helpers
|
|
233
|
+
// ---------------------------------------------------------------------------
|
|
234
|
+
async get(path) {
|
|
235
|
+
const url = `${this.baseUrl}${path}`;
|
|
236
|
+
const controller = new AbortController();
|
|
237
|
+
const timerId = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
238
|
+
let response;
|
|
239
|
+
try {
|
|
240
|
+
response = await fetch(url, {
|
|
241
|
+
method: "GET",
|
|
242
|
+
headers: { "X-API-Key": this.apiKey },
|
|
243
|
+
signal: controller.signal,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
catch (err) {
|
|
247
|
+
throw new errors_js_1.TrustStateError(`Network error: ${err.message}`);
|
|
248
|
+
}
|
|
249
|
+
finally {
|
|
250
|
+
clearTimeout(timerId);
|
|
251
|
+
}
|
|
252
|
+
if (!response.ok) {
|
|
253
|
+
const body = await response.text().catch(() => "");
|
|
254
|
+
throw new errors_js_1.TrustStateError(`API error ${response.status}: ${body}`, response.status);
|
|
255
|
+
}
|
|
256
|
+
return response.json();
|
|
257
|
+
}
|
|
258
|
+
async post(path, payload) {
|
|
259
|
+
const url = `${this.baseUrl}${path}`;
|
|
260
|
+
const controller = new AbortController();
|
|
261
|
+
const timerId = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
262
|
+
let response;
|
|
263
|
+
try {
|
|
264
|
+
response = await fetch(url, {
|
|
265
|
+
method: "POST",
|
|
266
|
+
headers: {
|
|
267
|
+
"Content-Type": "application/json",
|
|
268
|
+
"X-API-Key": this.apiKey,
|
|
269
|
+
},
|
|
270
|
+
body: JSON.stringify(payload),
|
|
271
|
+
signal: controller.signal,
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
catch (err) {
|
|
275
|
+
throw new errors_js_1.TrustStateError(`Network error: ${err.message}`);
|
|
276
|
+
}
|
|
277
|
+
finally {
|
|
278
|
+
clearTimeout(timerId);
|
|
279
|
+
}
|
|
280
|
+
if (!response.ok) {
|
|
281
|
+
const body = await response.text().catch(() => "");
|
|
282
|
+
throw new errors_js_1.TrustStateError(`API error ${response.status}: ${body}`, response.status);
|
|
283
|
+
}
|
|
284
|
+
return response.json();
|
|
285
|
+
}
|
|
286
|
+
parseBatchResponse(data) {
|
|
287
|
+
const rawResults = data.results ?? [];
|
|
288
|
+
const results = rawResults.map((r) => {
|
|
289
|
+
// Batch API returns status: 'accepted' | 'rejected', or passed: true/false directly
|
|
290
|
+
const passed = r.status === "accepted" || r.passed === true;
|
|
291
|
+
return {
|
|
292
|
+
passed,
|
|
293
|
+
recordId: r.recordId,
|
|
294
|
+
requestId: r.requestId ?? "",
|
|
295
|
+
entityId: r.entityId ?? "",
|
|
296
|
+
failReason: r.failReason,
|
|
297
|
+
failedStep: r.failedStep,
|
|
298
|
+
feedLabel: r.feedLabel ?? null,
|
|
299
|
+
mock: false,
|
|
300
|
+
};
|
|
301
|
+
});
|
|
302
|
+
const accepted = results.filter((r) => r.passed).length;
|
|
303
|
+
return {
|
|
304
|
+
batchId: data.batchId ?? crypto.randomUUID(),
|
|
305
|
+
total: data.total ?? results.length,
|
|
306
|
+
accepted: data.accepted ?? accepted,
|
|
307
|
+
rejected: data.rejected ?? results.length - accepted,
|
|
308
|
+
results,
|
|
309
|
+
feedLabel: data.feedLabel ?? null,
|
|
310
|
+
mock: false,
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
// ---------------------------------------------------------------------------
|
|
314
|
+
// Mock helpers (zero network calls)
|
|
315
|
+
// ---------------------------------------------------------------------------
|
|
316
|
+
mockSingleResult(entityId) {
|
|
317
|
+
const passed = Math.random() < this.mockPassRate;
|
|
318
|
+
return {
|
|
319
|
+
passed,
|
|
320
|
+
recordId: passed ? `mock-rec-${crypto.randomUUID()}` : undefined,
|
|
321
|
+
requestId: `mock-req-${crypto.randomUUID()}`,
|
|
322
|
+
entityId,
|
|
323
|
+
failReason: passed ? undefined : "Mock: simulated policy failure",
|
|
324
|
+
failedStep: passed ? undefined : 9,
|
|
325
|
+
mock: true,
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
mockBatchResult(normalisedItems, feedLabel) {
|
|
329
|
+
const results = normalisedItems.map((item) => ({
|
|
330
|
+
...this.mockSingleResult(item.entityId),
|
|
331
|
+
feedLabel: feedLabel ?? null,
|
|
332
|
+
}));
|
|
333
|
+
const accepted = results.filter((r) => r.passed).length;
|
|
334
|
+
return {
|
|
335
|
+
batchId: `mock-batch-${crypto.randomUUID()}`,
|
|
336
|
+
total: results.length,
|
|
337
|
+
accepted,
|
|
338
|
+
rejected: results.length - accepted,
|
|
339
|
+
results,
|
|
340
|
+
feedLabel: feedLabel ?? null,
|
|
341
|
+
mock: true,
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
exports.TrustStateClient = TrustStateClient;
|
|
346
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;AAEH,2CAA8C;AAS9C,MAAM,gBAAgB,GAAG,gDAAgD,CAAC;AAE1E,MAAa,gBAAgB;IAS3B,YAAY,OAAgC;QAC1C,I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package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom error class for TrustState API failures.
|
|
3
|
+
*/
|
|
4
|
+
export declare class TrustStateError extends Error {
|
|
5
|
+
/** HTTP status code returned by the API (0 if not an HTTP error). */
|
|
6
|
+
readonly statusCode: number;
|
|
7
|
+
constructor(message: string, statusCode?: number);
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IACxC,qEAAqE;IACrE,SAAgB,UAAU,EAAE,MAAM,CAAC;gBAEvB,OAAO,EAAE,MAAM,EAAE,UAAU,SAAI;CAO5C"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TrustStateError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Custom error class for TrustState API failures.
|
|
6
|
+
*/
|
|
7
|
+
class TrustStateError extends Error {
|
|
8
|
+
constructor(message, statusCode = 0) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = "TrustStateError";
|
|
11
|
+
this.statusCode = statusCode;
|
|
12
|
+
// Maintain proper prototype chain in transpiled ES5
|
|
13
|
+
Object.setPrototypeOf(this, TrustStateError.prototype);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.TrustStateError = TrustStateError;
|
|
17
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,MAAa,eAAgB,SAAQ,KAAK;IAIxC,YAAY,OAAe,EAAE,UAAU,GAAG,CAAC;QACzC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,oDAAoD;QACpD,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;IACzD,CAAC;CACF;AAXD,0CAWC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @truststate/sdk — TypeScript/JavaScript SDK for TrustState compliance validation.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* import { TrustStateClient } from "@truststate/sdk";
|
|
7
|
+
*
|
|
8
|
+
* const client = new TrustStateClient({ apiKey: "your-key" });
|
|
9
|
+
* const result = await client.check("AgentResponse", { text: "Hello!", score: 0.95 });
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export { TrustStateClient } from "./client.js";
|
|
13
|
+
export { TrustStateError } from "./errors.js";
|
|
14
|
+
export { trustStateMiddleware, withCompliance } from "./middleware.js";
|
|
15
|
+
export type { BatchResult, CheckItem, ComplianceResult, EvidenceItem, TrustStateClientOptions, } from "./types.js";
|
|
16
|
+
export type { TrustStateMiddlewareOptions } from "./middleware.js";
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACvE,YAAY,EACV,WAAW,EACX,SAAS,EACT,gBAAgB,EAChB,YAAY,EACZ,uBAAuB,GACxB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @truststate/sdk — TypeScript/JavaScript SDK for TrustState compliance validation.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* import { TrustStateClient } from "@truststate/sdk";
|
|
8
|
+
*
|
|
9
|
+
* const client = new TrustStateClient({ apiKey: "your-key" });
|
|
10
|
+
* const result = await client.check("AgentResponse", { text: "Hello!", score: 0.95 });
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.withCompliance = exports.trustStateMiddleware = exports.TrustStateError = exports.TrustStateClient = void 0;
|
|
15
|
+
var client_js_1 = require("./client.js");
|
|
16
|
+
Object.defineProperty(exports, "TrustStateClient", { enumerable: true, get: function () { return client_js_1.TrustStateClient; } });
|
|
17
|
+
var errors_js_1 = require("./errors.js");
|
|
18
|
+
Object.defineProperty(exports, "TrustStateError", { enumerable: true, get: function () { return errors_js_1.TrustStateError; } });
|
|
19
|
+
var middleware_js_1 = require("./middleware.js");
|
|
20
|
+
Object.defineProperty(exports, "trustStateMiddleware", { enumerable: true, get: function () { return middleware_js_1.trustStateMiddleware; } });
|
|
21
|
+
Object.defineProperty(exports, "withCompliance", { enumerable: true, get: function () { return middleware_js_1.withCompliance; } });
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAEH,yCAA+C;AAAtC,6GAAA,gBAAgB,OAAA;AACzB,yCAA8C;AAArC,4GAAA,eAAe,OAAA;AACxB,iDAAuE;AAA9D,qHAAA,oBAAoB,OAAA;AAAE,+GAAA,cAAc,OAAA"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TrustState middleware for Express and Next.js.
|
|
3
|
+
*
|
|
4
|
+
* @example Express
|
|
5
|
+
* ```typescript
|
|
6
|
+
* import express from "express";
|
|
7
|
+
* import { TrustStateClient, trustStateMiddleware } from "@truststate/sdk";
|
|
8
|
+
*
|
|
9
|
+
* const app = express();
|
|
10
|
+
* const client = new TrustStateClient({ apiKey: "your-key" });
|
|
11
|
+
* app.use(express.json());
|
|
12
|
+
* app.use(trustStateMiddleware(client));
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @example Next.js API route
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { withCompliance } from "@truststate/sdk";
|
|
18
|
+
* import { client } from "@/lib/truststate";
|
|
19
|
+
*
|
|
20
|
+
* export default withCompliance(client, "AgentResponse", async (req, res) => {
|
|
21
|
+
* res.json({ message: "Compliant response" });
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
import { TrustStateClient } from "./client.js";
|
|
26
|
+
interface ExpressRequest {
|
|
27
|
+
method: string;
|
|
28
|
+
headers: Record<string, string | string[] | undefined>;
|
|
29
|
+
body: unknown;
|
|
30
|
+
}
|
|
31
|
+
interface ExpressResponse {
|
|
32
|
+
status(code: number): ExpressResponse;
|
|
33
|
+
json(body: unknown): void;
|
|
34
|
+
setHeader(name: string, value: string): void;
|
|
35
|
+
}
|
|
36
|
+
type NextFunction = (err?: unknown) => void;
|
|
37
|
+
type RequestHandler = (req: ExpressRequest, res: ExpressResponse, next: NextFunction) => void | Promise<void>;
|
|
38
|
+
interface NextApiRequest {
|
|
39
|
+
method?: string;
|
|
40
|
+
headers: Record<string, string | string[] | undefined>;
|
|
41
|
+
body: unknown;
|
|
42
|
+
}
|
|
43
|
+
interface NextApiResponse {
|
|
44
|
+
status(code: number): NextApiResponse;
|
|
45
|
+
json(body: unknown): void;
|
|
46
|
+
setHeader(name: string, value: string): void;
|
|
47
|
+
}
|
|
48
|
+
type NextApiHandler = (req: NextApiRequest, res: NextApiResponse) => void | Promise<void>;
|
|
49
|
+
export interface TrustStateMiddlewareOptions {
|
|
50
|
+
/**
|
|
51
|
+
* Default entity type to use when X-Compliance-Entity-Type header is absent.
|
|
52
|
+
* If neither the header nor this option is set, the request passes through.
|
|
53
|
+
*/
|
|
54
|
+
defaultEntityType?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Default action to use when X-Compliance-Action header is absent.
|
|
57
|
+
* @default "CREATE"
|
|
58
|
+
*/
|
|
59
|
+
defaultAction?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Header that carries a stable entity ID for this request.
|
|
62
|
+
* @default "X-Compliance-Entity-Id"
|
|
63
|
+
*/
|
|
64
|
+
entityIdHeader?: string;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Express middleware that gates requests on TrustState compliance.
|
|
68
|
+
*
|
|
69
|
+
* Reads X-Compliance-Entity-Type and X-Compliance-Action headers.
|
|
70
|
+
* If X-Compliance-Entity-Type is present (or defaultEntityType is set),
|
|
71
|
+
* the request body is submitted to TrustState before the request proceeds.
|
|
72
|
+
*
|
|
73
|
+
* Failed checks return HTTP 422. Passed checks attach X-Compliance-Record-Id
|
|
74
|
+
* to the response headers.
|
|
75
|
+
*/
|
|
76
|
+
export declare function trustStateMiddleware(client: TrustStateClient, options?: TrustStateMiddlewareOptions): RequestHandler;
|
|
77
|
+
/**
|
|
78
|
+
* Wraps a Next.js API route handler with TrustState compliance checking.
|
|
79
|
+
*
|
|
80
|
+
* The request body is submitted to TrustState before the handler runs.
|
|
81
|
+
* Returns 422 if the check fails.
|
|
82
|
+
*
|
|
83
|
+
* @param client - TrustStateClient instance.
|
|
84
|
+
* @param entityType - The TrustState entity type to validate against.
|
|
85
|
+
* @param handler - The Next.js route handler to wrap.
|
|
86
|
+
* @param options - Optional action and entityIdHeader overrides.
|
|
87
|
+
*/
|
|
88
|
+
export declare function withCompliance(client: TrustStateClient, entityType: string, handler: NextApiHandler, options?: {
|
|
89
|
+
action?: string;
|
|
90
|
+
entityIdHeader?: string;
|
|
91
|
+
}): NextApiHandler;
|
|
92
|
+
export {};
|
|
93
|
+
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAM/C,UAAU,cAAc;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;IACvD,IAAI,EAAE,OAAO,CAAC;CACf;AAED,UAAU,eAAe;IACvB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAAC;IACtC,IAAI,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;IAC1B,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9C;AAED,KAAK,YAAY,GAAG,CAAC,GAAG,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;AAC5C,KAAK,cAAc,GAAG,CACpB,GAAG,EAAE,cAAc,EACnB,GAAG,EAAE,eAAe,EACpB,IAAI,EAAE,YAAY,KACf,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAM1B,UAAU,cAAc;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;IACvD,IAAI,EAAE,OAAO,CAAC;CACf;AAED,UAAU,eAAe;IACvB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAAC;IAC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