@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/src/types.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TrustState SDK — TypeScript type definitions.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/** Result of a single compliance check. */
|
|
6
|
+
export interface ComplianceResult {
|
|
7
|
+
/** True if all compliance checks passed. */
|
|
8
|
+
passed: boolean;
|
|
9
|
+
/** Immutable ledger record ID — only present when passed=true. */
|
|
10
|
+
recordId?: string;
|
|
11
|
+
/** Unique API request identifier (useful for support/debugging). */
|
|
12
|
+
requestId: string;
|
|
13
|
+
/** The entity identifier submitted (caller-supplied or auto-generated). */
|
|
14
|
+
entityId: string;
|
|
15
|
+
/** Human-readable reason for failure — only present when passed=false. */
|
|
16
|
+
failReason?: string;
|
|
17
|
+
/** Numeric step that failed. 8 = schema validation, 9 = policy check. */
|
|
18
|
+
failedStep?: number;
|
|
19
|
+
/** Feed label from the batch request — useful for identifying source feeds. */
|
|
20
|
+
feedLabel?: string | null;
|
|
21
|
+
/** True when this result was synthesised locally in mock mode (no HTTP call). */
|
|
22
|
+
mock: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Aggregated result for a batch compliance submission. */
|
|
26
|
+
export interface BatchResult {
|
|
27
|
+
/** Unique identifier for this batch request. */
|
|
28
|
+
batchId: string;
|
|
29
|
+
/** Total number of items submitted. */
|
|
30
|
+
total: number;
|
|
31
|
+
/** Number of items that passed compliance checks. */
|
|
32
|
+
accepted: number;
|
|
33
|
+
/** Number of items that failed compliance checks. */
|
|
34
|
+
rejected: number;
|
|
35
|
+
/** Per-item results in the same order as the submitted items. */
|
|
36
|
+
results: ComplianceResult[];
|
|
37
|
+
/** Feed label echoed from the batch request. */
|
|
38
|
+
feedLabel?: string | null;
|
|
39
|
+
/** True when running in mock mode (no HTTP calls made). */
|
|
40
|
+
mock: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** A single item in a batch submission. */
|
|
44
|
+
export interface CheckItem {
|
|
45
|
+
/** The TrustState entity type (e.g. "AgentResponse", "Transaction"). */
|
|
46
|
+
entityType: string;
|
|
47
|
+
/** The record payload to validate. */
|
|
48
|
+
data: Record<string, unknown>;
|
|
49
|
+
/** Action being performed. Defaults to "CREATE". */
|
|
50
|
+
action?: string;
|
|
51
|
+
/** Optional stable entity identifier. Auto-generated if omitted. */
|
|
52
|
+
entityId?: string;
|
|
53
|
+
/** Schema version to validate against. Uses client default if omitted. */
|
|
54
|
+
schemaVersion?: string;
|
|
55
|
+
/** Actor ID for the audit trail. Uses client default if omitted. */
|
|
56
|
+
actorId?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** A single oracle evidence item to submit alongside a compliance write. */
|
|
60
|
+
export interface EvidenceItem {
|
|
61
|
+
/** Unique ID for this evidence item. Auto-generated if not set. */
|
|
62
|
+
evidenceId: string;
|
|
63
|
+
/** Registered oracle provider ID (e.g. "reuters-fx"). */
|
|
64
|
+
providerId: string;
|
|
65
|
+
/** Oracle provider type (e.g. "fx_rate", "kyc_status"). */
|
|
66
|
+
providerType: string;
|
|
67
|
+
/** Key-value subject descriptor (e.g. { from: "MYR", to: "USD" }). */
|
|
68
|
+
subject: Record<string, unknown>;
|
|
69
|
+
/** The oracle-reported value. */
|
|
70
|
+
observedValue: string | number;
|
|
71
|
+
/** ISO-8601 timestamp when the value was observed by the oracle. */
|
|
72
|
+
observedAt: string;
|
|
73
|
+
/** ISO-8601 timestamp when you fetched this value. Defaults to now. */
|
|
74
|
+
retrievedAt: string;
|
|
75
|
+
/** Maximum acceptable age of this evidence in seconds. Default 300. */
|
|
76
|
+
maxAgeSeconds: number;
|
|
77
|
+
/** Optional sha256:<hex> hash of the raw proof document. */
|
|
78
|
+
proofHash?: string;
|
|
79
|
+
/** Optional URL for the raw proof document (background verified by TrustState). */
|
|
80
|
+
rawProofUri?: string;
|
|
81
|
+
/** Optional cryptographic attestation from the oracle provider. */
|
|
82
|
+
attestation?: { type: string; algorithm: string; signature: string };
|
|
83
|
+
/** True when synthesised locally in mock mode. */
|
|
84
|
+
mock?: boolean;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Options for check_batch / checkBatch. */
|
|
88
|
+
export interface BatchOptions {
|
|
89
|
+
/** Optional label identifying this feed/source (e.g. "core-banking-feed"). */
|
|
90
|
+
feedLabel?: string;
|
|
91
|
+
/** Override default schema version for this batch. */
|
|
92
|
+
defaultSchemaVersion?: string;
|
|
93
|
+
/** Override default actor ID for this batch. */
|
|
94
|
+
defaultActorId?: string;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Constructor options for TrustStateClient. */
|
|
98
|
+
export interface TrustStateClientOptions {
|
|
99
|
+
/** Your TrustState API key (sent as X-API-Key header). */
|
|
100
|
+
apiKey: string;
|
|
101
|
+
/** Override the default API base URL. */
|
|
102
|
+
baseUrl?: string;
|
|
103
|
+
/**
|
|
104
|
+
* Default schema version applied when not specified per-call.
|
|
105
|
+
* If omitted, the server auto-resolves to the active schema for each entity type.
|
|
106
|
+
*/
|
|
107
|
+
defaultSchemaVersion?: string;
|
|
108
|
+
/** Default actor ID for the audit trail. */
|
|
109
|
+
defaultActorId?: string;
|
|
110
|
+
/**
|
|
111
|
+
* Enable mock mode. When true, all HTTP calls are skipped and
|
|
112
|
+
* synthetic results are returned locally.
|
|
113
|
+
*/
|
|
114
|
+
mock?: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Probability (0.0–1.0) that a mock check returns passed=true.
|
|
117
|
+
* 1.0 = always pass, 0.0 = always fail.
|
|
118
|
+
*/
|
|
119
|
+
mockPassRate?: number;
|
|
120
|
+
/** HTTP request timeout in milliseconds. */
|
|
121
|
+
timeoutMs?: number;
|
|
122
|
+
}
|