@debros/orama 0.122.4-nightly
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 +665 -0
- package/dist/index.d.ts +1334 -0
- package/dist/index.js +2553 -0
- package/dist/index.js.map +1 -0
- package/package.json +82 -0
- package/src/auth/client.ts +276 -0
- package/src/auth/index.ts +3 -0
- package/src/auth/types.ts +62 -0
- package/src/cache/client.ts +203 -0
- package/src/cache/index.ts +14 -0
- package/src/core/http.ts +541 -0
- package/src/core/index.ts +10 -0
- package/src/core/interfaces/IAuthStrategy.ts +28 -0
- package/src/core/interfaces/IHttpTransport.ts +73 -0
- package/src/core/interfaces/IRetryPolicy.ts +20 -0
- package/src/core/interfaces/IWebSocketClient.ts +60 -0
- package/src/core/interfaces/index.ts +4 -0
- package/src/core/transport/AuthHeaderStrategy.ts +108 -0
- package/src/core/transport/RequestLogger.ts +116 -0
- package/src/core/transport/RequestRetryPolicy.ts +53 -0
- package/src/core/transport/TLSConfiguration.ts +53 -0
- package/src/core/transport/index.ts +4 -0
- package/src/core/ws.ts +246 -0
- package/src/db/client.ts +126 -0
- package/src/db/index.ts +13 -0
- package/src/db/qb.ts +111 -0
- package/src/db/repository.ts +128 -0
- package/src/db/types.ts +67 -0
- package/src/errors.ts +38 -0
- package/src/functions/client.ts +62 -0
- package/src/functions/index.ts +2 -0
- package/src/functions/types.ts +21 -0
- package/src/index.ts +201 -0
- package/src/network/client.ts +119 -0
- package/src/network/index.ts +7 -0
- package/src/pubsub/client.ts +361 -0
- package/src/pubsub/index.ts +12 -0
- package/src/pubsub/types.ts +46 -0
- package/src/storage/client.ts +272 -0
- package/src/storage/index.ts +7 -0
- package/src/utils/codec.ts +68 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/platform.ts +44 -0
- package/src/utils/retry.ts +58 -0
- package/src/vault/auth.ts +98 -0
- package/src/vault/client.ts +197 -0
- package/src/vault/crypto/aes.ts +271 -0
- package/src/vault/crypto/hkdf.ts +42 -0
- package/src/vault/crypto/index.ts +27 -0
- package/src/vault/crypto/shamir.ts +173 -0
- package/src/vault/index.ts +65 -0
- package/src/vault/quorum.ts +16 -0
- package/src/vault/transport/fanout.ts +94 -0
- package/src/vault/transport/guardian.ts +285 -0
- package/src/vault/transport/index.ts +19 -0
- package/src/vault/transport/types.ts +101 -0
- package/src/vault/types.ts +62 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1334 @@
|
|
|
1
|
+
import WebSocket from 'isomorphic-ws';
|
|
2
|
+
|
|
3
|
+
declare class SDKError extends Error {
|
|
4
|
+
readonly httpStatus: number;
|
|
5
|
+
readonly code: string;
|
|
6
|
+
readonly details: Record<string, any>;
|
|
7
|
+
constructor(message: string, httpStatus?: number, code?: string, details?: Record<string, any>);
|
|
8
|
+
static fromResponse(status: number, body: any, message?: string): SDKError;
|
|
9
|
+
toJSON(): {
|
|
10
|
+
name: string;
|
|
11
|
+
message: string;
|
|
12
|
+
httpStatus: number;
|
|
13
|
+
code: string;
|
|
14
|
+
details: Record<string, any>;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Context provided to the onNetworkError callback
|
|
20
|
+
*/
|
|
21
|
+
interface NetworkErrorContext {
|
|
22
|
+
method: "GET" | "POST" | "PUT" | "DELETE" | "WS";
|
|
23
|
+
path: string;
|
|
24
|
+
isRetry: boolean;
|
|
25
|
+
attempt: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Callback invoked when a network error occurs.
|
|
29
|
+
* Use this to trigger gateway failover or other error handling.
|
|
30
|
+
*/
|
|
31
|
+
type NetworkErrorCallback = (error: SDKError, context: NetworkErrorContext) => void;
|
|
32
|
+
interface HttpClientConfig {
|
|
33
|
+
baseURL: string;
|
|
34
|
+
timeout?: number;
|
|
35
|
+
maxRetries?: number;
|
|
36
|
+
retryDelayMs?: number;
|
|
37
|
+
fetch?: typeof fetch;
|
|
38
|
+
/**
|
|
39
|
+
* Enable debug logging (includes full SQL queries and args). Default: false
|
|
40
|
+
*/
|
|
41
|
+
debug?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Callback invoked on network errors (after all retries exhausted).
|
|
44
|
+
* Use this to trigger gateway failover at the application layer.
|
|
45
|
+
*/
|
|
46
|
+
onNetworkError?: NetworkErrorCallback;
|
|
47
|
+
}
|
|
48
|
+
declare class HttpClient {
|
|
49
|
+
private baseURL;
|
|
50
|
+
private timeout;
|
|
51
|
+
private maxRetries;
|
|
52
|
+
private retryDelayMs;
|
|
53
|
+
private fetch;
|
|
54
|
+
private apiKey?;
|
|
55
|
+
private jwt?;
|
|
56
|
+
private debug;
|
|
57
|
+
private onNetworkError?;
|
|
58
|
+
constructor(config: HttpClientConfig);
|
|
59
|
+
/**
|
|
60
|
+
* Set the network error callback
|
|
61
|
+
*/
|
|
62
|
+
setOnNetworkError(callback: NetworkErrorCallback | undefined): void;
|
|
63
|
+
setApiKey(apiKey?: string): void;
|
|
64
|
+
setJwt(jwt?: string): void;
|
|
65
|
+
private getAuthHeaders;
|
|
66
|
+
private getAuthToken;
|
|
67
|
+
getApiKey(): string | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* Get the base URL
|
|
70
|
+
*/
|
|
71
|
+
getBaseURL(): string;
|
|
72
|
+
request<T = any>(method: "GET" | "POST" | "PUT" | "DELETE", path: string, options?: {
|
|
73
|
+
body?: any;
|
|
74
|
+
headers?: Record<string, string>;
|
|
75
|
+
query?: Record<string, string | number | boolean>;
|
|
76
|
+
timeout?: number;
|
|
77
|
+
}): Promise<T>;
|
|
78
|
+
private requestWithRetry;
|
|
79
|
+
get<T = any>(path: string, options?: Omit<Parameters<typeof this.request>[2], "body">): Promise<T>;
|
|
80
|
+
post<T = any>(path: string, body?: any, options?: Omit<Parameters<typeof this.request>[2], "body">): Promise<T>;
|
|
81
|
+
put<T = any>(path: string, body?: any, options?: Omit<Parameters<typeof this.request>[2], "body">): Promise<T>;
|
|
82
|
+
delete<T = any>(path: string, options?: Omit<Parameters<typeof this.request>[2], "body">): Promise<T>;
|
|
83
|
+
/**
|
|
84
|
+
* Upload a file using multipart/form-data
|
|
85
|
+
* This is a special method for file uploads that bypasses JSON serialization
|
|
86
|
+
*/
|
|
87
|
+
uploadFile<T = any>(path: string, formData: FormData, options?: {
|
|
88
|
+
timeout?: number;
|
|
89
|
+
}): Promise<T>;
|
|
90
|
+
/**
|
|
91
|
+
* Get a binary response (returns Response object for streaming)
|
|
92
|
+
*/
|
|
93
|
+
getBinary(path: string): Promise<Response>;
|
|
94
|
+
getToken(): string | undefined;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
interface AuthConfig {
|
|
98
|
+
apiKey?: string;
|
|
99
|
+
jwt?: string;
|
|
100
|
+
}
|
|
101
|
+
interface WhoAmI {
|
|
102
|
+
address?: string;
|
|
103
|
+
namespace?: string;
|
|
104
|
+
authenticated: boolean;
|
|
105
|
+
}
|
|
106
|
+
interface StorageAdapter {
|
|
107
|
+
get(key: string): Promise<string | null>;
|
|
108
|
+
set(key: string, value: string): Promise<void>;
|
|
109
|
+
clear(): Promise<void>;
|
|
110
|
+
}
|
|
111
|
+
declare class MemoryStorage implements StorageAdapter {
|
|
112
|
+
private storage;
|
|
113
|
+
get(key: string): Promise<string | null>;
|
|
114
|
+
set(key: string, value: string): Promise<void>;
|
|
115
|
+
clear(): Promise<void>;
|
|
116
|
+
}
|
|
117
|
+
declare class LocalStorageAdapter implements StorageAdapter {
|
|
118
|
+
private prefix;
|
|
119
|
+
get(key: string): Promise<string | null>;
|
|
120
|
+
set(key: string, value: string): Promise<void>;
|
|
121
|
+
clear(): Promise<void>;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
declare class AuthClient$1 {
|
|
125
|
+
private httpClient;
|
|
126
|
+
private storage;
|
|
127
|
+
private currentApiKey?;
|
|
128
|
+
private currentJwt?;
|
|
129
|
+
constructor(config: {
|
|
130
|
+
httpClient: HttpClient;
|
|
131
|
+
storage?: StorageAdapter;
|
|
132
|
+
apiKey?: string;
|
|
133
|
+
jwt?: string;
|
|
134
|
+
});
|
|
135
|
+
setApiKey(apiKey: string): void;
|
|
136
|
+
setJwt(jwt: string): void;
|
|
137
|
+
getToken(): string | undefined;
|
|
138
|
+
whoami(): Promise<WhoAmI>;
|
|
139
|
+
/**
|
|
140
|
+
* Exchange a stored refresh token for a fresh access token.
|
|
141
|
+
*
|
|
142
|
+
* Pulls the refresh token (and the namespace it was issued for) out of
|
|
143
|
+
* storage — both are persisted by `verify()` after a successful wallet
|
|
144
|
+
* sign-in. The gateway returns a new access token and may rotate the
|
|
145
|
+
* refresh token; we persist the rotated one if present.
|
|
146
|
+
*
|
|
147
|
+
* Bug #239: previously this method (a) sent no body and (b) read the
|
|
148
|
+
* wrong response field, so the call always 400-ed AND silently wrote
|
|
149
|
+
* `undefined` as the in-memory JWT. Both issues fixed.
|
|
150
|
+
*/
|
|
151
|
+
refresh(): Promise<string>;
|
|
152
|
+
/**
|
|
153
|
+
* Logout user and clear JWT, but preserve API key
|
|
154
|
+
* Use this for user logout in apps where API key is app-level credential
|
|
155
|
+
*/
|
|
156
|
+
logoutUser(): Promise<void>;
|
|
157
|
+
/**
|
|
158
|
+
* Full logout - clears both JWT and API key
|
|
159
|
+
* Use this to completely reset authentication state
|
|
160
|
+
*/
|
|
161
|
+
logout(): Promise<void>;
|
|
162
|
+
clear(): Promise<void>;
|
|
163
|
+
/**
|
|
164
|
+
* Request a challenge nonce for wallet authentication
|
|
165
|
+
*/
|
|
166
|
+
challenge(params: {
|
|
167
|
+
wallet: string;
|
|
168
|
+
purpose?: string;
|
|
169
|
+
namespace?: string;
|
|
170
|
+
}): Promise<{
|
|
171
|
+
nonce: string;
|
|
172
|
+
wallet: string;
|
|
173
|
+
namespace: string;
|
|
174
|
+
expires_at: string;
|
|
175
|
+
}>;
|
|
176
|
+
/**
|
|
177
|
+
* Verify wallet signature and get JWT token
|
|
178
|
+
*/
|
|
179
|
+
verify(params: {
|
|
180
|
+
wallet: string;
|
|
181
|
+
nonce: string;
|
|
182
|
+
signature: string;
|
|
183
|
+
namespace?: string;
|
|
184
|
+
chain_type?: "ETH" | "SOL";
|
|
185
|
+
}): Promise<{
|
|
186
|
+
access_token: string;
|
|
187
|
+
refresh_token?: string;
|
|
188
|
+
subject: string;
|
|
189
|
+
namespace: string;
|
|
190
|
+
api_key?: string;
|
|
191
|
+
expires_in?: number;
|
|
192
|
+
token_type?: string;
|
|
193
|
+
}>;
|
|
194
|
+
/**
|
|
195
|
+
* Get API key for wallet (creates namespace ownership)
|
|
196
|
+
*/
|
|
197
|
+
getApiKey(params: {
|
|
198
|
+
wallet: string;
|
|
199
|
+
nonce: string;
|
|
200
|
+
signature: string;
|
|
201
|
+
namespace?: string;
|
|
202
|
+
chain_type?: "ETH" | "SOL";
|
|
203
|
+
}): Promise<{
|
|
204
|
+
api_key: string;
|
|
205
|
+
namespace: string;
|
|
206
|
+
wallet: string;
|
|
207
|
+
}>;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
declare class QueryBuilder {
|
|
211
|
+
private httpClient;
|
|
212
|
+
private table;
|
|
213
|
+
private options;
|
|
214
|
+
constructor(httpClient: HttpClient, table: string);
|
|
215
|
+
select(...columns: string[]): this;
|
|
216
|
+
innerJoin(table: string, on: string): this;
|
|
217
|
+
leftJoin(table: string, on: string): this;
|
|
218
|
+
rightJoin(table: string, on: string): this;
|
|
219
|
+
where(expr: string, args?: any[]): this;
|
|
220
|
+
andWhere(expr: string, args?: any[]): this;
|
|
221
|
+
orWhere(expr: string, args?: any[]): this;
|
|
222
|
+
groupBy(...columns: string[]): this;
|
|
223
|
+
orderBy(...columns: string[]): this;
|
|
224
|
+
limit(n: number): this;
|
|
225
|
+
offset(n: number): this;
|
|
226
|
+
getMany<T = any>(ctx?: any): Promise<T[]>;
|
|
227
|
+
getOne<T = any>(ctx?: any): Promise<T | null>;
|
|
228
|
+
count(): Promise<number>;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
interface Entity {
|
|
232
|
+
TableName(): string;
|
|
233
|
+
}
|
|
234
|
+
interface QueryResponse {
|
|
235
|
+
columns?: string[];
|
|
236
|
+
rows?: any[][];
|
|
237
|
+
count?: number;
|
|
238
|
+
items?: any[];
|
|
239
|
+
}
|
|
240
|
+
interface TransactionOp {
|
|
241
|
+
kind: "exec" | "query";
|
|
242
|
+
sql: string;
|
|
243
|
+
args?: any[];
|
|
244
|
+
}
|
|
245
|
+
interface TransactionRequest {
|
|
246
|
+
statements?: string[];
|
|
247
|
+
ops?: TransactionOp[];
|
|
248
|
+
return_results?: boolean;
|
|
249
|
+
}
|
|
250
|
+
interface SelectOptions {
|
|
251
|
+
select?: string[];
|
|
252
|
+
joins?: Array<{
|
|
253
|
+
kind: "INNER" | "LEFT" | "RIGHT" | "FULL";
|
|
254
|
+
table: string;
|
|
255
|
+
on: string;
|
|
256
|
+
}>;
|
|
257
|
+
where?: Array<{
|
|
258
|
+
conj?: "AND" | "OR";
|
|
259
|
+
expr: string;
|
|
260
|
+
args?: any[];
|
|
261
|
+
}>;
|
|
262
|
+
group_by?: string[];
|
|
263
|
+
order_by?: string[];
|
|
264
|
+
limit?: number;
|
|
265
|
+
offset?: number;
|
|
266
|
+
one?: boolean;
|
|
267
|
+
}
|
|
268
|
+
type FindOptions = Omit<SelectOptions, "select" | "joins" | "one">;
|
|
269
|
+
interface ColumnDefinition {
|
|
270
|
+
name: string;
|
|
271
|
+
isPrimaryKey?: boolean;
|
|
272
|
+
isAutoIncrement?: boolean;
|
|
273
|
+
}
|
|
274
|
+
declare function extractTableName(entity: Entity | string): string;
|
|
275
|
+
declare function extractPrimaryKey(entity: any): string | undefined;
|
|
276
|
+
|
|
277
|
+
declare class Repository<T extends Record<string, any>> {
|
|
278
|
+
private httpClient;
|
|
279
|
+
private tableName;
|
|
280
|
+
private primaryKey;
|
|
281
|
+
constructor(httpClient: HttpClient, tableName: string, primaryKey?: string);
|
|
282
|
+
createQueryBuilder(): QueryBuilder;
|
|
283
|
+
find(criteria?: Record<string, any>, options?: FindOptions): Promise<T[]>;
|
|
284
|
+
findOne(criteria: Record<string, any>): Promise<T | null>;
|
|
285
|
+
save(entity: T): Promise<T>;
|
|
286
|
+
remove(entity: T | Record<string, any>): Promise<void>;
|
|
287
|
+
private buildInsertSql;
|
|
288
|
+
private buildInsertArgs;
|
|
289
|
+
private buildUpdateSql;
|
|
290
|
+
private buildUpdateArgs;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
declare class DBClient {
|
|
294
|
+
private httpClient;
|
|
295
|
+
constructor(httpClient: HttpClient);
|
|
296
|
+
/**
|
|
297
|
+
* Execute a write/DDL SQL statement.
|
|
298
|
+
*/
|
|
299
|
+
exec(sql: string, args?: any[]): Promise<{
|
|
300
|
+
rows_affected: number;
|
|
301
|
+
last_insert_id?: number;
|
|
302
|
+
}>;
|
|
303
|
+
/**
|
|
304
|
+
* Execute a SELECT query.
|
|
305
|
+
*/
|
|
306
|
+
query<T = any>(sql: string, args?: any[]): Promise<T[]>;
|
|
307
|
+
/**
|
|
308
|
+
* Find rows with map-based criteria.
|
|
309
|
+
*/
|
|
310
|
+
find<T = any>(table: string, criteria?: Record<string, any>, options?: FindOptions): Promise<T[]>;
|
|
311
|
+
/**
|
|
312
|
+
* Find a single row with map-based criteria.
|
|
313
|
+
*/
|
|
314
|
+
findOne<T = any>(table: string, criteria: Record<string, any>): Promise<T | null>;
|
|
315
|
+
/**
|
|
316
|
+
* Create a fluent QueryBuilder for complex SELECT queries.
|
|
317
|
+
*/
|
|
318
|
+
createQueryBuilder(table: string): QueryBuilder;
|
|
319
|
+
/**
|
|
320
|
+
* Create a Repository for entity-based operations.
|
|
321
|
+
*/
|
|
322
|
+
repository<T extends Record<string, any>>(tableName: string, primaryKey?: string): Repository<T>;
|
|
323
|
+
/**
|
|
324
|
+
* Execute multiple operations atomically.
|
|
325
|
+
*/
|
|
326
|
+
transaction(ops: TransactionOp[], returnResults?: boolean): Promise<any[]>;
|
|
327
|
+
/**
|
|
328
|
+
* Create a table from DDL SQL.
|
|
329
|
+
*/
|
|
330
|
+
createTable(schema: string): Promise<void>;
|
|
331
|
+
/**
|
|
332
|
+
* Drop a table.
|
|
333
|
+
*/
|
|
334
|
+
dropTable(table: string): Promise<void>;
|
|
335
|
+
/**
|
|
336
|
+
* Get current database schema.
|
|
337
|
+
*/
|
|
338
|
+
getSchema(): Promise<any>;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
interface WSClientConfig {
|
|
342
|
+
wsURL: string;
|
|
343
|
+
timeout?: number;
|
|
344
|
+
authToken?: string;
|
|
345
|
+
WebSocket?: typeof WebSocket;
|
|
346
|
+
/**
|
|
347
|
+
* Callback invoked on WebSocket errors.
|
|
348
|
+
* Use this to trigger gateway failover at the application layer.
|
|
349
|
+
*/
|
|
350
|
+
onNetworkError?: NetworkErrorCallback;
|
|
351
|
+
}
|
|
352
|
+
type WSMessageHandler = (data: string) => void;
|
|
353
|
+
type WSErrorHandler = (error: Error) => void;
|
|
354
|
+
type WSCloseHandler = (code: number, reason: string) => void;
|
|
355
|
+
type WSOpenHandler = () => void;
|
|
356
|
+
/**
|
|
357
|
+
* Simple WebSocket client with minimal abstractions
|
|
358
|
+
* No complex reconnection, no failover - keep it simple
|
|
359
|
+
* Gateway failover is handled at the application layer
|
|
360
|
+
*/
|
|
361
|
+
declare class WSClient {
|
|
362
|
+
private wsURL;
|
|
363
|
+
private timeout;
|
|
364
|
+
private authToken?;
|
|
365
|
+
private WebSocketClass;
|
|
366
|
+
private onNetworkError?;
|
|
367
|
+
private ws?;
|
|
368
|
+
private messageHandlers;
|
|
369
|
+
private errorHandlers;
|
|
370
|
+
private closeHandlers;
|
|
371
|
+
private openHandlers;
|
|
372
|
+
private isClosed;
|
|
373
|
+
constructor(config: WSClientConfig);
|
|
374
|
+
/**
|
|
375
|
+
* Set the network error callback
|
|
376
|
+
*/
|
|
377
|
+
setOnNetworkError(callback: NetworkErrorCallback | undefined): void;
|
|
378
|
+
/**
|
|
379
|
+
* Get the current WebSocket URL
|
|
380
|
+
*/
|
|
381
|
+
get url(): string;
|
|
382
|
+
/**
|
|
383
|
+
* Connect to WebSocket server
|
|
384
|
+
*/
|
|
385
|
+
connect(): Promise<void>;
|
|
386
|
+
/**
|
|
387
|
+
* Build WebSocket URL with auth token
|
|
388
|
+
*/
|
|
389
|
+
private buildWSUrl;
|
|
390
|
+
/**
|
|
391
|
+
* Register message handler
|
|
392
|
+
*/
|
|
393
|
+
onMessage(handler: WSMessageHandler): () => void;
|
|
394
|
+
/**
|
|
395
|
+
* Unregister message handler
|
|
396
|
+
*/
|
|
397
|
+
offMessage(handler: WSMessageHandler): void;
|
|
398
|
+
/**
|
|
399
|
+
* Register error handler
|
|
400
|
+
*/
|
|
401
|
+
onError(handler: WSErrorHandler): () => void;
|
|
402
|
+
/**
|
|
403
|
+
* Unregister error handler
|
|
404
|
+
*/
|
|
405
|
+
offError(handler: WSErrorHandler): void;
|
|
406
|
+
/**
|
|
407
|
+
* Register close handler
|
|
408
|
+
*/
|
|
409
|
+
onClose(handler: WSCloseHandler): () => void;
|
|
410
|
+
/**
|
|
411
|
+
* Unregister close handler
|
|
412
|
+
*/
|
|
413
|
+
offClose(handler: WSCloseHandler): void;
|
|
414
|
+
/**
|
|
415
|
+
* Register open handler
|
|
416
|
+
*/
|
|
417
|
+
onOpen(handler: WSOpenHandler): () => void;
|
|
418
|
+
/**
|
|
419
|
+
* Send data through WebSocket
|
|
420
|
+
*/
|
|
421
|
+
send(data: string): void;
|
|
422
|
+
/**
|
|
423
|
+
* Close WebSocket connection
|
|
424
|
+
*/
|
|
425
|
+
close(): void;
|
|
426
|
+
/**
|
|
427
|
+
* Check if WebSocket is connected
|
|
428
|
+
*/
|
|
429
|
+
isConnected(): boolean;
|
|
430
|
+
/**
|
|
431
|
+
* Update auth token
|
|
432
|
+
*/
|
|
433
|
+
setAuthToken(token?: string): void;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
interface PubSubMessage {
|
|
437
|
+
data: string;
|
|
438
|
+
topic: string;
|
|
439
|
+
timestamp: number;
|
|
440
|
+
}
|
|
441
|
+
interface PresenceMember {
|
|
442
|
+
memberId: string;
|
|
443
|
+
joinedAt: number;
|
|
444
|
+
meta?: Record<string, unknown>;
|
|
445
|
+
}
|
|
446
|
+
interface PresenceResponse {
|
|
447
|
+
topic: string;
|
|
448
|
+
members: PresenceMember[];
|
|
449
|
+
count: number;
|
|
450
|
+
}
|
|
451
|
+
interface PresenceOptions {
|
|
452
|
+
enabled: boolean;
|
|
453
|
+
memberId: string;
|
|
454
|
+
meta?: Record<string, unknown>;
|
|
455
|
+
onJoin?: (member: PresenceMember) => void;
|
|
456
|
+
onLeave?: (member: PresenceMember) => void;
|
|
457
|
+
}
|
|
458
|
+
interface SubscribeOptions {
|
|
459
|
+
onMessage?: MessageHandler;
|
|
460
|
+
onError?: ErrorHandler;
|
|
461
|
+
onClose?: CloseHandler;
|
|
462
|
+
presence?: PresenceOptions;
|
|
463
|
+
}
|
|
464
|
+
type MessageHandler = (message: PubSubMessage) => void;
|
|
465
|
+
type ErrorHandler = (error: Error) => void;
|
|
466
|
+
type CloseHandler = (code: number, reason: string) => void;
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Simple PubSub client - one WebSocket connection per topic
|
|
470
|
+
* Gateway failover is handled at the application layer
|
|
471
|
+
*/
|
|
472
|
+
declare class PubSubClient {
|
|
473
|
+
private httpClient;
|
|
474
|
+
private wsConfig;
|
|
475
|
+
constructor(httpClient: HttpClient, wsConfig?: Partial<WSClientConfig>);
|
|
476
|
+
/**
|
|
477
|
+
* Publish a message to a topic via HTTP
|
|
478
|
+
*/
|
|
479
|
+
publish(topic: string, data: string | Uint8Array): Promise<void>;
|
|
480
|
+
/**
|
|
481
|
+
* List active topics in the current namespace
|
|
482
|
+
*/
|
|
483
|
+
topics(): Promise<string[]>;
|
|
484
|
+
/**
|
|
485
|
+
* Get current presence for a topic without subscribing
|
|
486
|
+
*/
|
|
487
|
+
getPresence(topic: string): Promise<PresenceResponse>;
|
|
488
|
+
/**
|
|
489
|
+
* Subscribe to a topic via WebSocket
|
|
490
|
+
* Creates one WebSocket connection per topic
|
|
491
|
+
*/
|
|
492
|
+
subscribe(topic: string, options?: SubscribeOptions): Promise<Subscription>;
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Subscription represents an active WebSocket subscription to a topic
|
|
496
|
+
*/
|
|
497
|
+
declare class Subscription {
|
|
498
|
+
private wsClient;
|
|
499
|
+
private topic;
|
|
500
|
+
private presenceOptions?;
|
|
501
|
+
private messageHandlers;
|
|
502
|
+
private errorHandlers;
|
|
503
|
+
private closeHandlers;
|
|
504
|
+
private isClosed;
|
|
505
|
+
private wsMessageHandler;
|
|
506
|
+
private wsErrorHandler;
|
|
507
|
+
private wsCloseHandler;
|
|
508
|
+
private getPresenceFn;
|
|
509
|
+
constructor(wsClient: WSClient, topic: string, presenceOptions: PresenceOptions | undefined, getPresenceFn: () => Promise<PresenceResponse>);
|
|
510
|
+
/**
|
|
511
|
+
* Get current presence (requires presence.enabled on subscribe)
|
|
512
|
+
*/
|
|
513
|
+
getPresence(): Promise<PresenceMember[]>;
|
|
514
|
+
/**
|
|
515
|
+
* Check if presence is enabled for this subscription
|
|
516
|
+
*/
|
|
517
|
+
hasPresence(): boolean;
|
|
518
|
+
/**
|
|
519
|
+
* Register message handler
|
|
520
|
+
*/
|
|
521
|
+
onMessage(handler: MessageHandler): () => void;
|
|
522
|
+
/**
|
|
523
|
+
* Register error handler
|
|
524
|
+
*/
|
|
525
|
+
onError(handler: ErrorHandler): () => void;
|
|
526
|
+
/**
|
|
527
|
+
* Register close handler
|
|
528
|
+
*/
|
|
529
|
+
onClose(handler: CloseHandler): () => void;
|
|
530
|
+
/**
|
|
531
|
+
* Close subscription and underlying WebSocket
|
|
532
|
+
*/
|
|
533
|
+
close(): void;
|
|
534
|
+
/**
|
|
535
|
+
* Check if subscription is active
|
|
536
|
+
*/
|
|
537
|
+
isConnected(): boolean;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
interface PeerInfo {
|
|
541
|
+
id: string;
|
|
542
|
+
addresses: string[];
|
|
543
|
+
lastSeen?: string;
|
|
544
|
+
}
|
|
545
|
+
interface NetworkStatus {
|
|
546
|
+
node_id: string;
|
|
547
|
+
connected: boolean;
|
|
548
|
+
peer_count: number;
|
|
549
|
+
database_size: number;
|
|
550
|
+
uptime: number;
|
|
551
|
+
}
|
|
552
|
+
interface ProxyRequest {
|
|
553
|
+
url: string;
|
|
554
|
+
method: string;
|
|
555
|
+
headers?: Record<string, string>;
|
|
556
|
+
body?: string;
|
|
557
|
+
}
|
|
558
|
+
interface ProxyResponse {
|
|
559
|
+
status_code: number;
|
|
560
|
+
headers: Record<string, string>;
|
|
561
|
+
body: string;
|
|
562
|
+
error?: string;
|
|
563
|
+
}
|
|
564
|
+
declare class NetworkClient {
|
|
565
|
+
private httpClient;
|
|
566
|
+
constructor(httpClient: HttpClient);
|
|
567
|
+
/**
|
|
568
|
+
* Check gateway health.
|
|
569
|
+
*/
|
|
570
|
+
health(): Promise<boolean>;
|
|
571
|
+
/**
|
|
572
|
+
* Get network status.
|
|
573
|
+
*/
|
|
574
|
+
status(): Promise<NetworkStatus>;
|
|
575
|
+
/**
|
|
576
|
+
* Get connected peers.
|
|
577
|
+
*/
|
|
578
|
+
peers(): Promise<PeerInfo[]>;
|
|
579
|
+
/**
|
|
580
|
+
* Connect to a peer.
|
|
581
|
+
*/
|
|
582
|
+
connect(peerAddr: string): Promise<void>;
|
|
583
|
+
/**
|
|
584
|
+
* Disconnect from a peer.
|
|
585
|
+
*/
|
|
586
|
+
disconnect(peerId: string): Promise<void>;
|
|
587
|
+
/**
|
|
588
|
+
* Proxy an HTTP request through the Anyone network.
|
|
589
|
+
* Requires authentication (API key or JWT).
|
|
590
|
+
*
|
|
591
|
+
* @param request - The proxy request configuration
|
|
592
|
+
* @returns The proxied response
|
|
593
|
+
* @throws {SDKError} If the Anyone proxy is not available or the request fails
|
|
594
|
+
*
|
|
595
|
+
* @example
|
|
596
|
+
* ```ts
|
|
597
|
+
* const response = await client.network.proxyAnon({
|
|
598
|
+
* url: 'https://api.example.com/data',
|
|
599
|
+
* method: 'GET',
|
|
600
|
+
* headers: {
|
|
601
|
+
* 'Accept': 'application/json'
|
|
602
|
+
* }
|
|
603
|
+
* });
|
|
604
|
+
*
|
|
605
|
+
* console.log(response.status_code); // 200
|
|
606
|
+
* console.log(response.body); // Response data
|
|
607
|
+
* ```
|
|
608
|
+
*/
|
|
609
|
+
proxyAnon(request: ProxyRequest): Promise<ProxyResponse>;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
interface CacheGetRequest {
|
|
613
|
+
dmap: string;
|
|
614
|
+
key: string;
|
|
615
|
+
}
|
|
616
|
+
interface CacheGetResponse {
|
|
617
|
+
key: string;
|
|
618
|
+
value: any;
|
|
619
|
+
dmap: string;
|
|
620
|
+
}
|
|
621
|
+
interface CachePutRequest {
|
|
622
|
+
dmap: string;
|
|
623
|
+
key: string;
|
|
624
|
+
value: any;
|
|
625
|
+
ttl?: string;
|
|
626
|
+
}
|
|
627
|
+
interface CachePutResponse {
|
|
628
|
+
status: string;
|
|
629
|
+
key: string;
|
|
630
|
+
dmap: string;
|
|
631
|
+
}
|
|
632
|
+
interface CacheDeleteRequest {
|
|
633
|
+
dmap: string;
|
|
634
|
+
key: string;
|
|
635
|
+
}
|
|
636
|
+
interface CacheDeleteResponse {
|
|
637
|
+
status: string;
|
|
638
|
+
key: string;
|
|
639
|
+
dmap: string;
|
|
640
|
+
}
|
|
641
|
+
interface CacheMultiGetRequest {
|
|
642
|
+
dmap: string;
|
|
643
|
+
keys: string[];
|
|
644
|
+
}
|
|
645
|
+
interface CacheMultiGetResponse {
|
|
646
|
+
results: Array<{
|
|
647
|
+
key: string;
|
|
648
|
+
value: any;
|
|
649
|
+
}>;
|
|
650
|
+
dmap: string;
|
|
651
|
+
}
|
|
652
|
+
interface CacheScanRequest {
|
|
653
|
+
dmap: string;
|
|
654
|
+
match?: string;
|
|
655
|
+
}
|
|
656
|
+
interface CacheScanResponse {
|
|
657
|
+
keys: string[];
|
|
658
|
+
count: number;
|
|
659
|
+
dmap: string;
|
|
660
|
+
}
|
|
661
|
+
interface CacheHealthResponse {
|
|
662
|
+
status: string;
|
|
663
|
+
service: string;
|
|
664
|
+
}
|
|
665
|
+
declare class CacheClient {
|
|
666
|
+
private httpClient;
|
|
667
|
+
constructor(httpClient: HttpClient);
|
|
668
|
+
/**
|
|
669
|
+
* Check cache service health
|
|
670
|
+
*/
|
|
671
|
+
health(): Promise<CacheHealthResponse>;
|
|
672
|
+
/**
|
|
673
|
+
* Get a value from cache
|
|
674
|
+
* Returns null if the key is not found (cache miss/expired), which is normal behavior
|
|
675
|
+
*/
|
|
676
|
+
get(dmap: string, key: string): Promise<CacheGetResponse | null>;
|
|
677
|
+
/**
|
|
678
|
+
* Put a value into cache
|
|
679
|
+
*/
|
|
680
|
+
put(dmap: string, key: string, value: any, ttl?: string): Promise<CachePutResponse>;
|
|
681
|
+
/**
|
|
682
|
+
* Delete a value from cache
|
|
683
|
+
*/
|
|
684
|
+
delete(dmap: string, key: string): Promise<CacheDeleteResponse>;
|
|
685
|
+
/**
|
|
686
|
+
* Get multiple values from cache in a single request
|
|
687
|
+
* Returns a map of key -> value (or null if not found)
|
|
688
|
+
* Gracefully handles 404 errors (endpoint not implemented) by returning empty results
|
|
689
|
+
*/
|
|
690
|
+
multiGet(dmap: string, keys: string[]): Promise<Map<string, any | null>>;
|
|
691
|
+
/**
|
|
692
|
+
* Scan keys in a distributed map, optionally matching a regex pattern
|
|
693
|
+
*/
|
|
694
|
+
scan(dmap: string, match?: string): Promise<CacheScanResponse>;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
interface StorageUploadResponse {
|
|
698
|
+
cid: string;
|
|
699
|
+
name: string;
|
|
700
|
+
size: number;
|
|
701
|
+
}
|
|
702
|
+
interface StoragePinRequest {
|
|
703
|
+
cid: string;
|
|
704
|
+
name?: string;
|
|
705
|
+
}
|
|
706
|
+
interface StoragePinResponse {
|
|
707
|
+
cid: string;
|
|
708
|
+
name: string;
|
|
709
|
+
}
|
|
710
|
+
interface StorageStatus {
|
|
711
|
+
cid: string;
|
|
712
|
+
name: string;
|
|
713
|
+
status: string;
|
|
714
|
+
replication_min: number;
|
|
715
|
+
replication_max: number;
|
|
716
|
+
replication_factor: number;
|
|
717
|
+
peers: string[];
|
|
718
|
+
error?: string;
|
|
719
|
+
}
|
|
720
|
+
declare class StorageClient {
|
|
721
|
+
private httpClient;
|
|
722
|
+
constructor(httpClient: HttpClient);
|
|
723
|
+
/**
|
|
724
|
+
* Upload content to IPFS and optionally pin it.
|
|
725
|
+
* Supports both File objects (browser) and Buffer/ReadableStream (Node.js).
|
|
726
|
+
*
|
|
727
|
+
* @param file - File to upload (File, Blob, or Buffer)
|
|
728
|
+
* @param name - Optional filename
|
|
729
|
+
* @param options - Optional upload options
|
|
730
|
+
* @param options.pin - Whether to pin the content (default: true). Pinning happens asynchronously on the backend.
|
|
731
|
+
* @returns Upload result with CID
|
|
732
|
+
*
|
|
733
|
+
* @example
|
|
734
|
+
* ```ts
|
|
735
|
+
* // Browser
|
|
736
|
+
* const fileInput = document.querySelector('input[type="file"]');
|
|
737
|
+
* const file = fileInput.files[0];
|
|
738
|
+
* const result = await client.storage.upload(file, file.name);
|
|
739
|
+
* console.log(result.cid);
|
|
740
|
+
*
|
|
741
|
+
* // Node.js
|
|
742
|
+
* const fs = require('fs');
|
|
743
|
+
* const fileBuffer = fs.readFileSync('image.jpg');
|
|
744
|
+
* const result = await client.storage.upload(fileBuffer, 'image.jpg', { pin: true });
|
|
745
|
+
* ```
|
|
746
|
+
*/
|
|
747
|
+
upload(file: File | Blob | ArrayBuffer | Uint8Array | ReadableStream<Uint8Array>, name?: string, options?: {
|
|
748
|
+
pin?: boolean;
|
|
749
|
+
}): Promise<StorageUploadResponse>;
|
|
750
|
+
/**
|
|
751
|
+
* Pin an existing CID
|
|
752
|
+
*
|
|
753
|
+
* @param cid - Content ID to pin
|
|
754
|
+
* @param name - Optional name for the pin
|
|
755
|
+
* @returns Pin result
|
|
756
|
+
*/
|
|
757
|
+
pin(cid: string, name?: string): Promise<StoragePinResponse>;
|
|
758
|
+
/**
|
|
759
|
+
* Get the pin status for a CID
|
|
760
|
+
*
|
|
761
|
+
* @param cid - Content ID to check
|
|
762
|
+
* @returns Pin status information
|
|
763
|
+
*/
|
|
764
|
+
status(cid: string): Promise<StorageStatus>;
|
|
765
|
+
/**
|
|
766
|
+
* Retrieve content from IPFS by CID
|
|
767
|
+
*
|
|
768
|
+
* @param cid - Content ID to retrieve
|
|
769
|
+
* @returns ReadableStream of the content
|
|
770
|
+
*
|
|
771
|
+
* @example
|
|
772
|
+
* ```ts
|
|
773
|
+
* const stream = await client.storage.get(cid);
|
|
774
|
+
* const reader = stream.getReader();
|
|
775
|
+
* while (true) {
|
|
776
|
+
* const { done, value } = await reader.read();
|
|
777
|
+
* if (done) break;
|
|
778
|
+
* // Process chunk
|
|
779
|
+
* }
|
|
780
|
+
* ```
|
|
781
|
+
*/
|
|
782
|
+
get(cid: string): Promise<ReadableStream<Uint8Array>>;
|
|
783
|
+
/**
|
|
784
|
+
* Retrieve content from IPFS by CID and return the full Response object
|
|
785
|
+
* Useful when you need access to response headers (e.g., content-length)
|
|
786
|
+
*
|
|
787
|
+
* @param cid - Content ID to retrieve
|
|
788
|
+
* @returns Response object with body stream and headers
|
|
789
|
+
*
|
|
790
|
+
* @example
|
|
791
|
+
* ```ts
|
|
792
|
+
* const response = await client.storage.getBinary(cid);
|
|
793
|
+
* const contentLength = response.headers.get('content-length');
|
|
794
|
+
* const reader = response.body.getReader();
|
|
795
|
+
* // ... read stream
|
|
796
|
+
* ```
|
|
797
|
+
*/
|
|
798
|
+
getBinary(cid: string): Promise<Response>;
|
|
799
|
+
/**
|
|
800
|
+
* Unpin a CID
|
|
801
|
+
*
|
|
802
|
+
* @param cid - Content ID to unpin
|
|
803
|
+
*/
|
|
804
|
+
unpin(cid: string): Promise<void>;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
/**
|
|
808
|
+
* Functions Client
|
|
809
|
+
* Client for calling serverless functions on the Orama Network
|
|
810
|
+
*/
|
|
811
|
+
|
|
812
|
+
interface FunctionsClientConfig {
|
|
813
|
+
/**
|
|
814
|
+
* Base URL for the functions gateway
|
|
815
|
+
* Defaults to using the same baseURL as the HTTP client
|
|
816
|
+
*/
|
|
817
|
+
gatewayURL?: string;
|
|
818
|
+
/**
|
|
819
|
+
* Namespace for the functions
|
|
820
|
+
*/
|
|
821
|
+
namespace: string;
|
|
822
|
+
}
|
|
823
|
+
declare class FunctionsClient {
|
|
824
|
+
private httpClient;
|
|
825
|
+
private gatewayURL?;
|
|
826
|
+
private namespace;
|
|
827
|
+
constructor(httpClient: HttpClient, config?: FunctionsClientConfig);
|
|
828
|
+
/**
|
|
829
|
+
* Invoke a serverless function by name
|
|
830
|
+
*
|
|
831
|
+
* @param functionName - Name of the function to invoke
|
|
832
|
+
* @param input - Input payload for the function
|
|
833
|
+
* @returns The function response
|
|
834
|
+
*/
|
|
835
|
+
invoke<TInput = any, TOutput = any>(functionName: string, input: TInput): Promise<TOutput>;
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
/** A guardian node endpoint. */
|
|
839
|
+
interface GuardianEndpoint {
|
|
840
|
+
address: string;
|
|
841
|
+
port: number;
|
|
842
|
+
}
|
|
843
|
+
/** V1 push response. */
|
|
844
|
+
interface PushResponse {
|
|
845
|
+
status: string;
|
|
846
|
+
}
|
|
847
|
+
/** V1 pull response. */
|
|
848
|
+
interface PullResponse {
|
|
849
|
+
share: string;
|
|
850
|
+
}
|
|
851
|
+
/** V2 store response. */
|
|
852
|
+
interface StoreSecretResponse {
|
|
853
|
+
status: string;
|
|
854
|
+
name: string;
|
|
855
|
+
version: number;
|
|
856
|
+
}
|
|
857
|
+
/** V2 get response. */
|
|
858
|
+
interface GetSecretResponse {
|
|
859
|
+
share: string;
|
|
860
|
+
name: string;
|
|
861
|
+
version: number;
|
|
862
|
+
created_ns: number;
|
|
863
|
+
updated_ns: number;
|
|
864
|
+
}
|
|
865
|
+
/** V2 delete response. */
|
|
866
|
+
interface DeleteSecretResponse {
|
|
867
|
+
status: string;
|
|
868
|
+
name: string;
|
|
869
|
+
}
|
|
870
|
+
/** V2 list response. */
|
|
871
|
+
interface ListSecretsResponse {
|
|
872
|
+
secrets: SecretEntry[];
|
|
873
|
+
}
|
|
874
|
+
/** An entry in the list secrets response. */
|
|
875
|
+
interface SecretEntry {
|
|
876
|
+
name: string;
|
|
877
|
+
version: number;
|
|
878
|
+
size: number;
|
|
879
|
+
}
|
|
880
|
+
/** Health check response. */
|
|
881
|
+
interface HealthResponse {
|
|
882
|
+
status: string;
|
|
883
|
+
version: string;
|
|
884
|
+
}
|
|
885
|
+
/** Status response. */
|
|
886
|
+
interface StatusResponse {
|
|
887
|
+
status: string;
|
|
888
|
+
version: string;
|
|
889
|
+
data_dir: string;
|
|
890
|
+
client_port: number;
|
|
891
|
+
peer_port: number;
|
|
892
|
+
}
|
|
893
|
+
/** Guardian info response. */
|
|
894
|
+
interface GuardianInfo {
|
|
895
|
+
guardians: Array<{
|
|
896
|
+
address: string;
|
|
897
|
+
port: number;
|
|
898
|
+
}>;
|
|
899
|
+
threshold: number;
|
|
900
|
+
total: number;
|
|
901
|
+
}
|
|
902
|
+
/** Challenge response from auth endpoint. */
|
|
903
|
+
interface ChallengeResponse {
|
|
904
|
+
nonce: string;
|
|
905
|
+
created_ns: number;
|
|
906
|
+
tag: string;
|
|
907
|
+
}
|
|
908
|
+
/** Session token response from auth endpoint. */
|
|
909
|
+
interface SessionResponse {
|
|
910
|
+
identity: string;
|
|
911
|
+
expiry_ns: number;
|
|
912
|
+
tag: string;
|
|
913
|
+
}
|
|
914
|
+
/** Error classification codes. */
|
|
915
|
+
type GuardianErrorCode = 'TIMEOUT' | 'NOT_FOUND' | 'AUTH' | 'SERVER_ERROR' | 'NETWORK' | 'CONFLICT';
|
|
916
|
+
/** Fan-out result for a single guardian. */
|
|
917
|
+
interface FanOutResult<T> {
|
|
918
|
+
endpoint: GuardianEndpoint;
|
|
919
|
+
result: T | null;
|
|
920
|
+
error: string | null;
|
|
921
|
+
errorCode?: GuardianErrorCode;
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
/** Configuration for VaultClient. */
|
|
925
|
+
interface VaultConfig {
|
|
926
|
+
/** Guardian endpoints to connect to. */
|
|
927
|
+
guardians: GuardianEndpoint[];
|
|
928
|
+
/** HMAC key for authentication (derived from user's secret). */
|
|
929
|
+
hmacKey: Uint8Array;
|
|
930
|
+
/** Identity hash (hex string, 64 chars). */
|
|
931
|
+
identityHex: string;
|
|
932
|
+
/** Request timeout in ms (default: 10000). */
|
|
933
|
+
timeoutMs?: number;
|
|
934
|
+
}
|
|
935
|
+
/** Metadata for a stored secret. */
|
|
936
|
+
interface SecretMeta {
|
|
937
|
+
name: string;
|
|
938
|
+
version: number;
|
|
939
|
+
size: number;
|
|
940
|
+
}
|
|
941
|
+
/** Result of a store operation. */
|
|
942
|
+
interface StoreResult {
|
|
943
|
+
/** Number of guardians that acknowledged. */
|
|
944
|
+
ackCount: number;
|
|
945
|
+
/** Total guardians contacted. */
|
|
946
|
+
totalContacted: number;
|
|
947
|
+
/** Number of failures. */
|
|
948
|
+
failCount: number;
|
|
949
|
+
/** Whether write quorum was met. */
|
|
950
|
+
quorumMet: boolean;
|
|
951
|
+
/** Per-guardian results. */
|
|
952
|
+
guardianResults: GuardianResult[];
|
|
953
|
+
}
|
|
954
|
+
/** Result of a retrieve operation. */
|
|
955
|
+
interface RetrieveResult {
|
|
956
|
+
/** The reconstructed secret data. */
|
|
957
|
+
data: Uint8Array;
|
|
958
|
+
/** Number of shares collected. */
|
|
959
|
+
sharesCollected: number;
|
|
960
|
+
}
|
|
961
|
+
/** Result of a list operation. */
|
|
962
|
+
interface ListResult {
|
|
963
|
+
secrets: SecretMeta[];
|
|
964
|
+
}
|
|
965
|
+
/** Result of a delete operation. */
|
|
966
|
+
interface DeleteResult {
|
|
967
|
+
/** Number of guardians that acknowledged. */
|
|
968
|
+
ackCount: number;
|
|
969
|
+
totalContacted: number;
|
|
970
|
+
quorumMet: boolean;
|
|
971
|
+
}
|
|
972
|
+
/** Per-guardian operation result. */
|
|
973
|
+
interface GuardianResult {
|
|
974
|
+
endpoint: string;
|
|
975
|
+
success: boolean;
|
|
976
|
+
error?: string;
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
/**
|
|
980
|
+
* High-level client for the orama-vault distributed secrets store.
|
|
981
|
+
*
|
|
982
|
+
* Handles:
|
|
983
|
+
* - Authentication with guardian nodes
|
|
984
|
+
* - Shamir split/combine for data distribution
|
|
985
|
+
* - Quorum-based writes and reads
|
|
986
|
+
* - V2 CRUD operations (store, retrieve, list, delete)
|
|
987
|
+
*/
|
|
988
|
+
declare class VaultClient {
|
|
989
|
+
private config;
|
|
990
|
+
private auth;
|
|
991
|
+
constructor(config: VaultConfig);
|
|
992
|
+
/**
|
|
993
|
+
* Store a secret across guardian nodes using Shamir splitting.
|
|
994
|
+
*
|
|
995
|
+
* @param name - Secret name (alphanumeric, _, -, max 128 chars)
|
|
996
|
+
* @param data - Secret data to store
|
|
997
|
+
* @param version - Monotonic version number (must be > previous)
|
|
998
|
+
*/
|
|
999
|
+
store(name: string, data: Uint8Array, version: number): Promise<StoreResult>;
|
|
1000
|
+
/**
|
|
1001
|
+
* Retrieve and reconstruct a secret from guardian nodes.
|
|
1002
|
+
*
|
|
1003
|
+
* @param name - Secret name
|
|
1004
|
+
*/
|
|
1005
|
+
retrieve(name: string): Promise<RetrieveResult>;
|
|
1006
|
+
/**
|
|
1007
|
+
* List all secrets for this identity.
|
|
1008
|
+
* Queries the first reachable guardian (metadata is replicated).
|
|
1009
|
+
*/
|
|
1010
|
+
list(): Promise<ListResult>;
|
|
1011
|
+
/**
|
|
1012
|
+
* Delete a secret from all guardian nodes.
|
|
1013
|
+
*
|
|
1014
|
+
* @param name - Secret name to delete
|
|
1015
|
+
*/
|
|
1016
|
+
delete(name: string): Promise<DeleteResult>;
|
|
1017
|
+
/** Clear all cached auth sessions. */
|
|
1018
|
+
clearSessions(): void;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
/**
|
|
1022
|
+
* Serverless Functions Types
|
|
1023
|
+
* Type definitions for calling serverless functions on the Orama Network
|
|
1024
|
+
*/
|
|
1025
|
+
/**
|
|
1026
|
+
* Generic response from a serverless function
|
|
1027
|
+
*/
|
|
1028
|
+
interface FunctionResponse<T = unknown> {
|
|
1029
|
+
success: boolean;
|
|
1030
|
+
error?: string;
|
|
1031
|
+
data?: T;
|
|
1032
|
+
}
|
|
1033
|
+
/**
|
|
1034
|
+
* Standard success/error response used by many functions
|
|
1035
|
+
*/
|
|
1036
|
+
interface SuccessResponse {
|
|
1037
|
+
success: boolean;
|
|
1038
|
+
error?: string;
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
declare class GuardianError extends Error {
|
|
1042
|
+
readonly code: GuardianErrorCode;
|
|
1043
|
+
constructor(code: GuardianErrorCode, message: string);
|
|
1044
|
+
}
|
|
1045
|
+
/**
|
|
1046
|
+
* HTTP client for a single orama-vault guardian node.
|
|
1047
|
+
* Supports V1 (push/pull) and V2 (CRUD secrets) endpoints.
|
|
1048
|
+
*/
|
|
1049
|
+
declare class GuardianClient {
|
|
1050
|
+
private baseUrl;
|
|
1051
|
+
private timeoutMs;
|
|
1052
|
+
private sessionToken;
|
|
1053
|
+
constructor(endpoint: GuardianEndpoint, timeoutMs?: number);
|
|
1054
|
+
/** Set a session token for authenticated V2 requests. */
|
|
1055
|
+
setSessionToken(token: string): void;
|
|
1056
|
+
/** Get the current session token. */
|
|
1057
|
+
getSessionToken(): string | null;
|
|
1058
|
+
/** Clear the session token. */
|
|
1059
|
+
clearSessionToken(): void;
|
|
1060
|
+
/** GET /v1/vault/health */
|
|
1061
|
+
health(): Promise<HealthResponse>;
|
|
1062
|
+
/** GET /v1/vault/status */
|
|
1063
|
+
status(): Promise<StatusResponse>;
|
|
1064
|
+
/** GET /v1/vault/guardians */
|
|
1065
|
+
guardians(): Promise<GuardianInfo>;
|
|
1066
|
+
/** POST /v1/vault/push — store a share (V1). */
|
|
1067
|
+
push(identity: string, share: Uint8Array): Promise<PushResponse>;
|
|
1068
|
+
/** POST /v1/vault/pull — retrieve a share (V1). */
|
|
1069
|
+
pull(identity: string): Promise<Uint8Array>;
|
|
1070
|
+
/** Check if this guardian is reachable. */
|
|
1071
|
+
isReachable(): Promise<boolean>;
|
|
1072
|
+
/** POST /v2/vault/auth/challenge — request an auth challenge. */
|
|
1073
|
+
requestChallenge(identity: string): Promise<ChallengeResponse>;
|
|
1074
|
+
/** POST /v2/vault/auth/session — exchange challenge for session token. */
|
|
1075
|
+
createSession(identity: string, nonce: string, created_ns: number, tag: string): Promise<SessionResponse>;
|
|
1076
|
+
/** PUT /v2/vault/secrets/{name} — store a secret. Requires session token. */
|
|
1077
|
+
putSecret(name: string, share: Uint8Array, version: number): Promise<StoreSecretResponse>;
|
|
1078
|
+
/** GET /v2/vault/secrets/{name} — retrieve a secret. Requires session token. */
|
|
1079
|
+
getSecret(name: string): Promise<{
|
|
1080
|
+
share: Uint8Array;
|
|
1081
|
+
name: string;
|
|
1082
|
+
version: number;
|
|
1083
|
+
created_ns: number;
|
|
1084
|
+
updated_ns: number;
|
|
1085
|
+
}>;
|
|
1086
|
+
/** DELETE /v2/vault/secrets/{name} — delete a secret. Requires session token. */
|
|
1087
|
+
deleteSecret(name: string): Promise<DeleteSecretResponse>;
|
|
1088
|
+
/** GET /v2/vault/secrets — list all secrets. Requires session token. */
|
|
1089
|
+
listSecrets(): Promise<ListSecretsResponse>;
|
|
1090
|
+
private authedRequest;
|
|
1091
|
+
private get;
|
|
1092
|
+
private post;
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
/**
|
|
1096
|
+
* Handles challenge-response authentication with guardian nodes.
|
|
1097
|
+
* Caches session tokens per guardian endpoint.
|
|
1098
|
+
*
|
|
1099
|
+
* Auth flow:
|
|
1100
|
+
* 1. POST /v2/vault/auth/challenge with identity → get {nonce, created_ns, tag}
|
|
1101
|
+
* 2. POST /v2/vault/auth/session with identity + challenge fields → get session token
|
|
1102
|
+
* 3. Use session token as X-Session-Token header for V2 requests
|
|
1103
|
+
*
|
|
1104
|
+
* The session token format is: `<identity_hex>:<expiry_ns>:<tag_hex>`
|
|
1105
|
+
*/
|
|
1106
|
+
declare class AuthClient {
|
|
1107
|
+
private sessions;
|
|
1108
|
+
private identityHex;
|
|
1109
|
+
private timeoutMs;
|
|
1110
|
+
constructor(identityHex: string, timeoutMs?: number);
|
|
1111
|
+
/**
|
|
1112
|
+
* Authenticate with a guardian and cache the session token.
|
|
1113
|
+
* Returns a GuardianClient with the session token set.
|
|
1114
|
+
*/
|
|
1115
|
+
authenticate(endpoint: GuardianEndpoint): Promise<GuardianClient>;
|
|
1116
|
+
/**
|
|
1117
|
+
* Authenticate with multiple guardians in parallel.
|
|
1118
|
+
* Returns authenticated GuardianClients for all that succeed.
|
|
1119
|
+
*/
|
|
1120
|
+
authenticateAll(endpoints: GuardianEndpoint[]): Promise<{
|
|
1121
|
+
client: GuardianClient;
|
|
1122
|
+
endpoint: GuardianEndpoint;
|
|
1123
|
+
}[]>;
|
|
1124
|
+
/** Clear all cached sessions. */
|
|
1125
|
+
clearSessions(): void;
|
|
1126
|
+
/** Get the identity hex string. */
|
|
1127
|
+
getIdentityHex(): string;
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
/**
|
|
1131
|
+
* Fan out an operation to multiple guardians in parallel.
|
|
1132
|
+
* Returns results from all guardians (both successes and failures).
|
|
1133
|
+
*/
|
|
1134
|
+
declare function fanOut<T>(guardians: GuardianEndpoint[], operation: (client: GuardianClient) => Promise<T>): Promise<FanOutResult<T>[]>;
|
|
1135
|
+
/**
|
|
1136
|
+
* Fan out an indexed operation to multiple guardians in parallel.
|
|
1137
|
+
* The operation receives the index so each guardian can get a different share.
|
|
1138
|
+
*/
|
|
1139
|
+
declare function fanOutIndexed<T>(guardians: GuardianEndpoint[], operation: (client: GuardianClient, index: number) => Promise<T>): Promise<FanOutResult<T>[]>;
|
|
1140
|
+
/**
|
|
1141
|
+
* Race a promise against a timeout.
|
|
1142
|
+
*/
|
|
1143
|
+
declare function withTimeout<T>(promise: Promise<T>, ms: number): Promise<T>;
|
|
1144
|
+
/**
|
|
1145
|
+
* Retry a function with exponential backoff.
|
|
1146
|
+
* Does not retry auth or not-found errors.
|
|
1147
|
+
*/
|
|
1148
|
+
declare function withRetry<T>(fn: () => Promise<T>, attempts?: number): Promise<T>;
|
|
1149
|
+
|
|
1150
|
+
/**
|
|
1151
|
+
* Quorum calculations for distributed vault operations.
|
|
1152
|
+
* Must match orama-vault (Zig side).
|
|
1153
|
+
*/
|
|
1154
|
+
/** Adaptive Shamir threshold: max(3, floor(N/3)). */
|
|
1155
|
+
declare function adaptiveThreshold(n: number): number;
|
|
1156
|
+
/** Write quorum: ceil(2N/3). Requires majority for consistency. */
|
|
1157
|
+
declare function writeQuorum(n: number): number;
|
|
1158
|
+
|
|
1159
|
+
/**
|
|
1160
|
+
* AES-256-GCM Encryption
|
|
1161
|
+
*
|
|
1162
|
+
* Implements authenticated encryption using AES-256 in Galois/Counter Mode.
|
|
1163
|
+
* Uses @noble/ciphers for platform-agnostic, audited cryptographic operations.
|
|
1164
|
+
*
|
|
1165
|
+
* Features:
|
|
1166
|
+
* - Authenticated encryption (confidentiality + integrity)
|
|
1167
|
+
* - 256-bit keys for strong security
|
|
1168
|
+
* - 96-bit nonces (randomly generated)
|
|
1169
|
+
* - 128-bit authentication tags
|
|
1170
|
+
*
|
|
1171
|
+
* Security considerations:
|
|
1172
|
+
* - Never reuse a nonce with the same key
|
|
1173
|
+
* - Nonces are randomly generated and prepended to ciphertext
|
|
1174
|
+
* - Authentication tags are verified before decryption
|
|
1175
|
+
*/
|
|
1176
|
+
/**
|
|
1177
|
+
* Size constants
|
|
1178
|
+
*/
|
|
1179
|
+
declare const KEY_SIZE = 32;
|
|
1180
|
+
declare const NONCE_SIZE = 12;
|
|
1181
|
+
declare const TAG_SIZE = 16;
|
|
1182
|
+
/**
|
|
1183
|
+
* Encrypted data structure
|
|
1184
|
+
*/
|
|
1185
|
+
interface EncryptedData {
|
|
1186
|
+
/** Ciphertext including authentication tag */
|
|
1187
|
+
ciphertext: Uint8Array;
|
|
1188
|
+
/** Nonce used for encryption */
|
|
1189
|
+
nonce: Uint8Array;
|
|
1190
|
+
/** Additional authenticated data (optional) */
|
|
1191
|
+
aad?: Uint8Array;
|
|
1192
|
+
}
|
|
1193
|
+
/**
|
|
1194
|
+
* Serialized encrypted data (nonce prepended to ciphertext)
|
|
1195
|
+
*/
|
|
1196
|
+
interface SerializedEncryptedData {
|
|
1197
|
+
/** Combined nonce + ciphertext + tag */
|
|
1198
|
+
data: Uint8Array;
|
|
1199
|
+
/** Additional authenticated data (optional) */
|
|
1200
|
+
aad?: Uint8Array;
|
|
1201
|
+
}
|
|
1202
|
+
/**
|
|
1203
|
+
* Encrypts data using AES-256-GCM
|
|
1204
|
+
*/
|
|
1205
|
+
declare function encrypt(plaintext: Uint8Array, key: Uint8Array, aad?: Uint8Array): EncryptedData;
|
|
1206
|
+
/**
|
|
1207
|
+
* Decrypts data using AES-256-GCM
|
|
1208
|
+
*/
|
|
1209
|
+
declare function decrypt(encryptedData: EncryptedData, key: Uint8Array): Uint8Array;
|
|
1210
|
+
/**
|
|
1211
|
+
* Encrypts a string message
|
|
1212
|
+
*/
|
|
1213
|
+
declare function encryptString(message: string, key: Uint8Array, aad?: Uint8Array): EncryptedData;
|
|
1214
|
+
/**
|
|
1215
|
+
* Decrypts to a string message
|
|
1216
|
+
*/
|
|
1217
|
+
declare function decryptString(encryptedData: EncryptedData, key: Uint8Array): string;
|
|
1218
|
+
/**
|
|
1219
|
+
* Serializes encrypted data (prepends nonce to ciphertext)
|
|
1220
|
+
*/
|
|
1221
|
+
declare function serialize(encryptedData: EncryptedData): SerializedEncryptedData;
|
|
1222
|
+
/**
|
|
1223
|
+
* Deserializes encrypted data
|
|
1224
|
+
*/
|
|
1225
|
+
declare function deserialize(serialized: SerializedEncryptedData): EncryptedData;
|
|
1226
|
+
/**
|
|
1227
|
+
* Encrypts and serializes data in one step
|
|
1228
|
+
*/
|
|
1229
|
+
declare function encryptAndSerialize(plaintext: Uint8Array, key: Uint8Array, aad?: Uint8Array): SerializedEncryptedData;
|
|
1230
|
+
/**
|
|
1231
|
+
* Deserializes and decrypts data in one step
|
|
1232
|
+
*/
|
|
1233
|
+
declare function deserializeAndDecrypt(serialized: SerializedEncryptedData, key: Uint8Array): Uint8Array;
|
|
1234
|
+
/**
|
|
1235
|
+
* Converts encrypted data to hex string
|
|
1236
|
+
*/
|
|
1237
|
+
declare function toHex(encryptedData: EncryptedData): string;
|
|
1238
|
+
/**
|
|
1239
|
+
* Parses encrypted data from hex string
|
|
1240
|
+
*/
|
|
1241
|
+
declare function fromHex(hex: string, aad?: Uint8Array): EncryptedData;
|
|
1242
|
+
/**
|
|
1243
|
+
* Converts encrypted data to base64 string
|
|
1244
|
+
*/
|
|
1245
|
+
declare function toBase64(encryptedData: EncryptedData): string;
|
|
1246
|
+
/**
|
|
1247
|
+
* Parses encrypted data from base64 string
|
|
1248
|
+
*/
|
|
1249
|
+
declare function fromBase64(base64: string, aad?: Uint8Array): EncryptedData;
|
|
1250
|
+
/**
|
|
1251
|
+
* Generates a random encryption key
|
|
1252
|
+
*/
|
|
1253
|
+
declare function generateKey(): Uint8Array;
|
|
1254
|
+
/**
|
|
1255
|
+
* Generates a random nonce
|
|
1256
|
+
*/
|
|
1257
|
+
declare function generateNonce(): Uint8Array;
|
|
1258
|
+
/**
|
|
1259
|
+
* Securely clears a key from memory
|
|
1260
|
+
*/
|
|
1261
|
+
declare function clearKey(key: Uint8Array): void;
|
|
1262
|
+
/**
|
|
1263
|
+
* Checks if encrypted data appears valid (basic structure check)
|
|
1264
|
+
*/
|
|
1265
|
+
declare function isValidEncryptedData(data: EncryptedData): boolean;
|
|
1266
|
+
|
|
1267
|
+
/**
|
|
1268
|
+
* HKDF Key Derivation
|
|
1269
|
+
*
|
|
1270
|
+
* Derives deterministic sub-keys from a master secret using HKDF-SHA256 (RFC 5869).
|
|
1271
|
+
*/
|
|
1272
|
+
/**
|
|
1273
|
+
* Derives a sub-key from input key material using HKDF-SHA256.
|
|
1274
|
+
*
|
|
1275
|
+
* @param ikm - Input key material (e.g., wallet private key). MUST be high-entropy.
|
|
1276
|
+
* @param salt - Domain separation salt. Can be a string or bytes.
|
|
1277
|
+
* @param info - Context-specific info. Can be a string or bytes.
|
|
1278
|
+
* @param length - Output key length in bytes (default: 32).
|
|
1279
|
+
* @returns Derived key as Uint8Array. Caller MUST zero this after use.
|
|
1280
|
+
*/
|
|
1281
|
+
declare function deriveKeyHKDF(ikm: Uint8Array, salt: string | Uint8Array, info: string | Uint8Array, length?: number): Uint8Array;
|
|
1282
|
+
|
|
1283
|
+
/** A single Shamir share */
|
|
1284
|
+
interface Share {
|
|
1285
|
+
/** Share index (1..N, never 0) */
|
|
1286
|
+
x: number;
|
|
1287
|
+
/** Share data (same length as secret) */
|
|
1288
|
+
y: Uint8Array;
|
|
1289
|
+
}
|
|
1290
|
+
/**
|
|
1291
|
+
* Splits a secret into N shares with threshold K.
|
|
1292
|
+
*
|
|
1293
|
+
* @param secret - Secret bytes to split (any length)
|
|
1294
|
+
* @param n - Total number of shares to create (2..255)
|
|
1295
|
+
* @param k - Minimum shares needed for reconstruction (2..n)
|
|
1296
|
+
* @returns Array of N shares
|
|
1297
|
+
*/
|
|
1298
|
+
declare function split(secret: Uint8Array, n: number, k: number): Share[];
|
|
1299
|
+
/**
|
|
1300
|
+
* Reconstructs a secret from K or more shares using Lagrange interpolation.
|
|
1301
|
+
*
|
|
1302
|
+
* @param shares - Array of K or more shares (must all have same y.length)
|
|
1303
|
+
* @returns Reconstructed secret
|
|
1304
|
+
*/
|
|
1305
|
+
declare function combine(shares: Share[]): Uint8Array;
|
|
1306
|
+
|
|
1307
|
+
interface ClientConfig extends Omit<HttpClientConfig, "fetch"> {
|
|
1308
|
+
apiKey?: string;
|
|
1309
|
+
jwt?: string;
|
|
1310
|
+
storage?: StorageAdapter;
|
|
1311
|
+
wsConfig?: Partial<Omit<WSClientConfig, "wsURL">>;
|
|
1312
|
+
functionsConfig?: FunctionsClientConfig;
|
|
1313
|
+
fetch?: typeof fetch;
|
|
1314
|
+
/**
|
|
1315
|
+
* Callback invoked on network errors (HTTP and WebSocket).
|
|
1316
|
+
* Use this to trigger gateway failover at the application layer.
|
|
1317
|
+
*/
|
|
1318
|
+
onNetworkError?: NetworkErrorCallback;
|
|
1319
|
+
/** Configuration for the vault (distributed secrets store). */
|
|
1320
|
+
vaultConfig?: VaultConfig;
|
|
1321
|
+
}
|
|
1322
|
+
interface Client {
|
|
1323
|
+
auth: AuthClient$1;
|
|
1324
|
+
db: DBClient;
|
|
1325
|
+
pubsub: PubSubClient;
|
|
1326
|
+
network: NetworkClient;
|
|
1327
|
+
cache: CacheClient;
|
|
1328
|
+
storage: StorageClient;
|
|
1329
|
+
functions: FunctionsClient;
|
|
1330
|
+
vault: VaultClient | null;
|
|
1331
|
+
}
|
|
1332
|
+
declare function createClient(config: ClientConfig): Client;
|
|
1333
|
+
|
|
1334
|
+
export { AuthClient$1 as AuthClient, type AuthConfig, CacheClient, type CacheDeleteRequest, type CacheDeleteResponse, type CacheGetRequest, type CacheGetResponse, type CacheHealthResponse, type CacheMultiGetRequest, type CacheMultiGetResponse, type CachePutRequest, type CachePutResponse, type CacheScanRequest, type CacheScanResponse, type Client, type ClientConfig, type CloseHandler, type ColumnDefinition, DBClient, type DeleteResult, type DeleteSecretResponse, type EncryptedData, type Entity, type ErrorHandler, type FanOutResult, type FindOptions, type FunctionResponse, FunctionsClient, type FunctionsClientConfig, type GetSecretResponse, type ChallengeResponse as GuardianChallengeResponse, GuardianClient, type GuardianEndpoint, GuardianError, type GuardianErrorCode, type HealthResponse as GuardianHealthResponse, type GuardianInfo, type SessionResponse as GuardianSessionResponse, type StatusResponse as GuardianStatusResponse, HttpClient, KEY_SIZE, type ListResult, type ListSecretsResponse, LocalStorageAdapter, MemoryStorage, type MessageHandler, NONCE_SIZE, NetworkClient, type NetworkErrorCallback, type NetworkErrorContext, type NetworkStatus, type PeerInfo, type PresenceMember, type PresenceOptions, type PresenceResponse, type ProxyRequest, type ProxyResponse, PubSubClient, type PubSubMessage, type PullResponse, type PushResponse, QueryBuilder, type QueryResponse, Repository, type RetrieveResult, SDKError, type SecretEntry, type SecretMeta, type SelectOptions, type SerializedEncryptedData, type Share as ShamirShare, type StorageAdapter, StorageClient, type StoragePinRequest, type StoragePinResponse, type StorageStatus, type StorageUploadResponse, type StoreResult, type StoreSecretResponse, type SubscribeOptions, Subscription, type SuccessResponse, TAG_SIZE, type TransactionOp, type TransactionRequest, AuthClient as VaultAuthClient, VaultClient, type VaultConfig, type GuardianResult as VaultGuardianResult, WSClient, type WhoAmI, adaptiveThreshold, clearKey, createClient, decrypt, decryptString, deriveKeyHKDF, deserializeAndDecrypt, deserialize as deserializeEncrypted, encrypt, encryptAndSerialize, encryptString, fromBase64 as encryptedFromBase64, fromHex as encryptedFromHex, toBase64 as encryptedToBase64, toHex as encryptedToHex, extractPrimaryKey, extractTableName, fanOut, fanOutIndexed, generateKey, generateNonce, isValidEncryptedData, serialize as serializeEncrypted, combine as shamirCombine, split as shamirSplit, withRetry, withTimeout, writeQuorum };
|