@cipherstash/stack 0.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.
- package/CHANGELOG.md +7 -0
- package/LICENSE.md +21 -0
- package/README.md +670 -0
- package/dist/bin/stash.js +5049 -0
- package/dist/bin/stash.js.map +1 -0
- package/dist/chunk-2GZMIJFO.js +2400 -0
- package/dist/chunk-2GZMIJFO.js.map +1 -0
- package/dist/chunk-5DCT6YU2.js +138 -0
- package/dist/chunk-5DCT6YU2.js.map +1 -0
- package/dist/chunk-7XRPN2KX.js +336 -0
- package/dist/chunk-7XRPN2KX.js.map +1 -0
- package/dist/chunk-SJ7JO4ME.js +28 -0
- package/dist/chunk-SJ7JO4ME.js.map +1 -0
- package/dist/chunk-SUYMGQBY.js +67 -0
- package/dist/chunk-SUYMGQBY.js.map +1 -0
- package/dist/client-BxJG56Ey.d.cts +647 -0
- package/dist/client-DtGq9dJp.d.ts +647 -0
- package/dist/client.cjs +347 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +7 -0
- package/dist/client.d.ts +7 -0
- package/dist/client.js +11 -0
- package/dist/client.js.map +1 -0
- package/dist/drizzle/index.cjs +1528 -0
- package/dist/drizzle/index.cjs.map +1 -0
- package/dist/drizzle/index.d.cts +350 -0
- package/dist/drizzle/index.d.ts +350 -0
- package/dist/drizzle/index.js +1212 -0
- package/dist/drizzle/index.js.map +1 -0
- package/dist/dynamodb/index.cjs +382 -0
- package/dist/dynamodb/index.cjs.map +1 -0
- package/dist/dynamodb/index.d.cts +125 -0
- package/dist/dynamodb/index.d.ts +125 -0
- package/dist/dynamodb/index.js +355 -0
- package/dist/dynamodb/index.js.map +1 -0
- package/dist/identity/index.cjs +271 -0
- package/dist/identity/index.cjs.map +1 -0
- package/dist/identity/index.d.cts +3 -0
- package/dist/identity/index.d.ts +3 -0
- package/dist/identity/index.js +117 -0
- package/dist/identity/index.js.map +1 -0
- package/dist/index-9-Ya3fDK.d.cts +169 -0
- package/dist/index-9-Ya3fDK.d.ts +169 -0
- package/dist/index.cjs +2915 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +22 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/schema/index.cjs +368 -0
- package/dist/schema/index.cjs.map +1 -0
- package/dist/schema/index.d.cts +4 -0
- package/dist/schema/index.d.ts +4 -0
- package/dist/schema/index.js +23 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/secrets/index.cjs +3207 -0
- package/dist/secrets/index.cjs.map +1 -0
- package/dist/secrets/index.d.cts +227 -0
- package/dist/secrets/index.d.ts +227 -0
- package/dist/secrets/index.js +323 -0
- package/dist/secrets/index.js.map +1 -0
- package/dist/supabase/index.cjs +1113 -0
- package/dist/supabase/index.cjs.map +1 -0
- package/dist/supabase/index.d.cts +144 -0
- package/dist/supabase/index.d.ts +144 -0
- package/dist/supabase/index.js +864 -0
- package/dist/supabase/index.js.map +1 -0
- package/dist/types-public-BCj1L4fi.d.cts +1013 -0
- package/dist/types-public-BCj1L4fi.d.ts +1013 -0
- package/dist/types-public.cjs +40 -0
- package/dist/types-public.cjs.map +1 -0
- package/dist/types-public.d.cts +4 -0
- package/dist/types-public.d.ts +4 -0
- package/dist/types-public.js +7 -0
- package/dist/types-public.js.map +1 -0
- package/package.json +202 -0
|
@@ -0,0 +1,647 @@
|
|
|
1
|
+
import { j as EncryptedQueryResult, k as Client, S as ScalarQueryTerm, B as BulkDecryptedData, l as BulkDecryptPayload, D as Decrypted, m as BulkEncryptedData, n as BulkEncryptPayload, o as EncryptOptions, P as ProtectColumn, g as ProtectValue, d as ProtectTable, f as ProtectTableColumn, h as Encrypted, p as EncryptQueryOptions, Q as QueryTypeName, q as EncryptedReturnType, r as EncryptConfig, K as KeysetIdentifier } from './types-public-BCj1L4fi.cjs';
|
|
2
|
+
import { a as EncryptionError, d as LockContext } from './index-9-Ya3fDK.cjs';
|
|
3
|
+
import { Result } from '@byteslice/result';
|
|
4
|
+
import { JsPlaintext } from '@cipherstash/protect-ffi';
|
|
5
|
+
|
|
6
|
+
type AuditConfig = {
|
|
7
|
+
metadata?: Record<string, unknown>;
|
|
8
|
+
};
|
|
9
|
+
type AuditData = {
|
|
10
|
+
metadata?: Record<string, unknown>;
|
|
11
|
+
};
|
|
12
|
+
declare abstract class EncryptionOperation<T> {
|
|
13
|
+
protected auditMetadata?: Record<string, unknown>;
|
|
14
|
+
/**
|
|
15
|
+
* Attach audit metadata to this operation. Can be chained.
|
|
16
|
+
* @param config Configuration for ZeroKMS audit logging
|
|
17
|
+
* @param config.metadata Arbitrary JSON object for appending metadata to the audit log
|
|
18
|
+
*/
|
|
19
|
+
audit(config: AuditConfig): this;
|
|
20
|
+
/**
|
|
21
|
+
* Get the audit data for this operation.
|
|
22
|
+
*/
|
|
23
|
+
getAuditData(): AuditData;
|
|
24
|
+
/**
|
|
25
|
+
* Execute the operation and return a Result
|
|
26
|
+
*/
|
|
27
|
+
abstract execute(): Promise<Result<T, EncryptionError>>;
|
|
28
|
+
/**
|
|
29
|
+
* Make the operation thenable
|
|
30
|
+
*/
|
|
31
|
+
then<TResult1 = Result<T, EncryptionError>, TResult2 = never>(onfulfilled?: ((value: Result<T, EncryptionError>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @internal Use {@link EncryptionClient.encryptQuery} with array input instead.
|
|
36
|
+
*/
|
|
37
|
+
declare class BatchEncryptQueryOperation extends EncryptionOperation<EncryptedQueryResult[]> {
|
|
38
|
+
private client;
|
|
39
|
+
private terms;
|
|
40
|
+
constructor(client: Client, terms: readonly ScalarQueryTerm[]);
|
|
41
|
+
withLockContext(lockContext: LockContext): BatchEncryptQueryOperationWithLockContext;
|
|
42
|
+
execute(): Promise<Result<EncryptedQueryResult[], EncryptionError>>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* @internal Use {@link EncryptionClient.encryptQuery} with array input and `.withLockContext()` instead.
|
|
46
|
+
*/
|
|
47
|
+
declare class BatchEncryptQueryOperationWithLockContext extends EncryptionOperation<EncryptedQueryResult[]> {
|
|
48
|
+
private client;
|
|
49
|
+
private terms;
|
|
50
|
+
private lockContext;
|
|
51
|
+
constructor(client: Client, terms: readonly ScalarQueryTerm[], lockContext: LockContext, auditMetadata?: Record<string, unknown>);
|
|
52
|
+
execute(): Promise<Result<EncryptedQueryResult[], EncryptionError>>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
declare class BulkDecryptOperation extends EncryptionOperation<BulkDecryptedData> {
|
|
56
|
+
private client;
|
|
57
|
+
private encryptedPayloads;
|
|
58
|
+
constructor(client: Client, encryptedPayloads: BulkDecryptPayload);
|
|
59
|
+
withLockContext(lockContext: LockContext): BulkDecryptOperationWithLockContext;
|
|
60
|
+
execute(): Promise<Result<BulkDecryptedData, EncryptionError>>;
|
|
61
|
+
getOperation(): {
|
|
62
|
+
client: Client;
|
|
63
|
+
encryptedPayloads: BulkDecryptPayload;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
declare class BulkDecryptOperationWithLockContext extends EncryptionOperation<BulkDecryptedData> {
|
|
67
|
+
private operation;
|
|
68
|
+
private lockContext;
|
|
69
|
+
constructor(operation: BulkDecryptOperation, lockContext: LockContext);
|
|
70
|
+
execute(): Promise<Result<BulkDecryptedData, EncryptionError>>;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
declare class BulkDecryptModelsOperation<T extends Record<string, unknown>> extends EncryptionOperation<Decrypted<T>[]> {
|
|
74
|
+
private client;
|
|
75
|
+
private models;
|
|
76
|
+
constructor(client: Client, models: T[]);
|
|
77
|
+
withLockContext(lockContext: LockContext): BulkDecryptModelsOperationWithLockContext<T>;
|
|
78
|
+
execute(): Promise<Result<Decrypted<T>[], EncryptionError>>;
|
|
79
|
+
getOperation(): {
|
|
80
|
+
client: Client;
|
|
81
|
+
models: T[];
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
declare class BulkDecryptModelsOperationWithLockContext<T extends Record<string, unknown>> extends EncryptionOperation<Decrypted<T>[]> {
|
|
85
|
+
private operation;
|
|
86
|
+
private lockContext;
|
|
87
|
+
constructor(operation: BulkDecryptModelsOperation<T>, lockContext: LockContext);
|
|
88
|
+
execute(): Promise<Result<Decrypted<T>[], EncryptionError>>;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
declare class BulkEncryptOperation extends EncryptionOperation<BulkEncryptedData> {
|
|
92
|
+
private client;
|
|
93
|
+
private plaintexts;
|
|
94
|
+
private column;
|
|
95
|
+
private table;
|
|
96
|
+
constructor(client: Client, plaintexts: BulkEncryptPayload, opts: EncryptOptions);
|
|
97
|
+
withLockContext(lockContext: LockContext): BulkEncryptOperationWithLockContext;
|
|
98
|
+
execute(): Promise<Result<BulkEncryptedData, EncryptionError>>;
|
|
99
|
+
getOperation(): {
|
|
100
|
+
client: Client;
|
|
101
|
+
plaintexts: BulkEncryptPayload;
|
|
102
|
+
column: ProtectColumn | ProtectValue;
|
|
103
|
+
table: ProtectTable<ProtectTableColumn>;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
declare class BulkEncryptOperationWithLockContext extends EncryptionOperation<BulkEncryptedData> {
|
|
107
|
+
private operation;
|
|
108
|
+
private lockContext;
|
|
109
|
+
constructor(operation: BulkEncryptOperation, lockContext: LockContext);
|
|
110
|
+
execute(): Promise<Result<BulkEncryptedData, EncryptionError>>;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
declare class BulkEncryptModelsOperation<T extends Record<string, unknown>> extends EncryptionOperation<T[]> {
|
|
114
|
+
private client;
|
|
115
|
+
private models;
|
|
116
|
+
private table;
|
|
117
|
+
constructor(client: Client, models: Decrypted<T>[], table: ProtectTable<ProtectTableColumn>);
|
|
118
|
+
withLockContext(lockContext: LockContext): BulkEncryptModelsOperationWithLockContext<T>;
|
|
119
|
+
execute(): Promise<Result<T[], EncryptionError>>;
|
|
120
|
+
getOperation(): {
|
|
121
|
+
client: Client;
|
|
122
|
+
models: Decrypted<T>[];
|
|
123
|
+
table: ProtectTable<ProtectTableColumn>;
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
declare class BulkEncryptModelsOperationWithLockContext<T extends Record<string, unknown>> extends EncryptionOperation<T[]> {
|
|
127
|
+
private operation;
|
|
128
|
+
private lockContext;
|
|
129
|
+
constructor(operation: BulkEncryptModelsOperation<T>, lockContext: LockContext);
|
|
130
|
+
execute(): Promise<Result<T[], EncryptionError>>;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Decrypts an encrypted payload using the provided client.
|
|
135
|
+
* This is the type returned by the {@link EncryptionClient.decrypt | decrypt} method of the {@link EncryptionClient}.
|
|
136
|
+
*/
|
|
137
|
+
declare class DecryptOperation extends EncryptionOperation<JsPlaintext | null> {
|
|
138
|
+
private client;
|
|
139
|
+
private encryptedData;
|
|
140
|
+
constructor(client: Client, encryptedData: Encrypted);
|
|
141
|
+
withLockContext(lockContext: LockContext): DecryptOperationWithLockContext;
|
|
142
|
+
execute(): Promise<Result<JsPlaintext | null, EncryptionError>>;
|
|
143
|
+
getOperation(): {
|
|
144
|
+
client: Client;
|
|
145
|
+
encryptedData: Encrypted;
|
|
146
|
+
auditData?: Record<string, unknown>;
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
declare class DecryptOperationWithLockContext extends EncryptionOperation<JsPlaintext | null> {
|
|
150
|
+
private operation;
|
|
151
|
+
private lockContext;
|
|
152
|
+
constructor(operation: DecryptOperation, lockContext: LockContext);
|
|
153
|
+
execute(): Promise<Result<JsPlaintext | null, EncryptionError>>;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
declare class DecryptModelOperation<T extends Record<string, unknown>> extends EncryptionOperation<Decrypted<T>> {
|
|
157
|
+
private client;
|
|
158
|
+
private model;
|
|
159
|
+
constructor(client: Client, model: T);
|
|
160
|
+
withLockContext(lockContext: LockContext): DecryptModelOperationWithLockContext<T>;
|
|
161
|
+
execute(): Promise<Result<Decrypted<T>, EncryptionError>>;
|
|
162
|
+
getOperation(): {
|
|
163
|
+
client: Client;
|
|
164
|
+
model: T;
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
declare class DecryptModelOperationWithLockContext<T extends Record<string, unknown>> extends EncryptionOperation<Decrypted<T>> {
|
|
168
|
+
private operation;
|
|
169
|
+
private lockContext;
|
|
170
|
+
constructor(operation: DecryptModelOperation<T>, lockContext: LockContext);
|
|
171
|
+
execute(): Promise<Result<Decrypted<T>, EncryptionError>>;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
declare class EncryptOperation extends EncryptionOperation<Encrypted> {
|
|
175
|
+
private client;
|
|
176
|
+
private plaintext;
|
|
177
|
+
private column;
|
|
178
|
+
private table;
|
|
179
|
+
constructor(client: Client, plaintext: JsPlaintext | null, opts: EncryptOptions);
|
|
180
|
+
withLockContext(lockContext: LockContext): EncryptOperationWithLockContext;
|
|
181
|
+
execute(): Promise<Result<Encrypted, EncryptionError>>;
|
|
182
|
+
getOperation(): {
|
|
183
|
+
client: Client;
|
|
184
|
+
plaintext: JsPlaintext | null;
|
|
185
|
+
column: ProtectColumn | ProtectValue;
|
|
186
|
+
table: ProtectTable<ProtectTableColumn>;
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
declare class EncryptOperationWithLockContext extends EncryptionOperation<Encrypted> {
|
|
190
|
+
private operation;
|
|
191
|
+
private lockContext;
|
|
192
|
+
constructor(operation: EncryptOperation, lockContext: LockContext);
|
|
193
|
+
execute(): Promise<Result<Encrypted, EncryptionError>>;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
declare class EncryptModelOperation<T extends Record<string, unknown>> extends EncryptionOperation<T> {
|
|
197
|
+
private client;
|
|
198
|
+
private model;
|
|
199
|
+
private table;
|
|
200
|
+
constructor(client: Client, model: Decrypted<T>, table: ProtectTable<ProtectTableColumn>);
|
|
201
|
+
withLockContext(lockContext: LockContext): EncryptModelOperationWithLockContext<T>;
|
|
202
|
+
execute(): Promise<Result<T, EncryptionError>>;
|
|
203
|
+
getOperation(): {
|
|
204
|
+
client: Client;
|
|
205
|
+
model: Decrypted<T>;
|
|
206
|
+
table: ProtectTable<ProtectTableColumn>;
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
declare class EncryptModelOperationWithLockContext<T extends Record<string, unknown>> extends EncryptionOperation<T> {
|
|
210
|
+
private operation;
|
|
211
|
+
private lockContext;
|
|
212
|
+
constructor(operation: EncryptModelOperation<T>, lockContext: LockContext);
|
|
213
|
+
execute(): Promise<Result<T, EncryptionError>>;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* @internal Use {@link EncryptionClient.encryptQuery} instead.
|
|
218
|
+
*/
|
|
219
|
+
declare class EncryptQueryOperation extends EncryptionOperation<EncryptedQueryResult> {
|
|
220
|
+
private client;
|
|
221
|
+
private plaintext;
|
|
222
|
+
private opts;
|
|
223
|
+
constructor(client: Client, plaintext: JsPlaintext | null, opts: EncryptQueryOptions);
|
|
224
|
+
withLockContext(lockContext: LockContext): EncryptQueryOperationWithLockContext;
|
|
225
|
+
execute(): Promise<Result<EncryptedQueryResult, EncryptionError>>;
|
|
226
|
+
getOperation(): {
|
|
227
|
+
column: ProtectColumn;
|
|
228
|
+
table: ProtectTable<ProtectTableColumn>;
|
|
229
|
+
queryType?: QueryTypeName;
|
|
230
|
+
returnType?: EncryptedReturnType;
|
|
231
|
+
client: Client;
|
|
232
|
+
plaintext: JsPlaintext | null;
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* @internal Use {@link EncryptionClient.encryptQuery} with `.withLockContext()` instead.
|
|
237
|
+
*/
|
|
238
|
+
declare class EncryptQueryOperationWithLockContext extends EncryptionOperation<EncryptedQueryResult> {
|
|
239
|
+
private client;
|
|
240
|
+
private plaintext;
|
|
241
|
+
private opts;
|
|
242
|
+
private lockContext;
|
|
243
|
+
constructor(client: Client, plaintext: JsPlaintext | null, opts: EncryptQueryOptions, lockContext: LockContext, auditMetadata?: Record<string, unknown>);
|
|
244
|
+
execute(): Promise<Result<EncryptedQueryResult, EncryptionError>>;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** The EncryptionClient is the main entry point for interacting with the CipherStash Protect.js library.
|
|
248
|
+
* It provides methods for encrypting and decrypting individual values, as well as models (objects) and bulk operations.
|
|
249
|
+
*
|
|
250
|
+
* The client must be initialized using the {@link Encryption} function before it can be used.
|
|
251
|
+
*/
|
|
252
|
+
declare class EncryptionClient {
|
|
253
|
+
private client;
|
|
254
|
+
private encryptConfig;
|
|
255
|
+
private workspaceId;
|
|
256
|
+
constructor(workspaceCrn?: string);
|
|
257
|
+
/**
|
|
258
|
+
* Initializes the EncryptionClient with the provided configuration.
|
|
259
|
+
* @internal
|
|
260
|
+
* @param config - The configuration object for initializing the client.
|
|
261
|
+
* @returns A promise that resolves to a {@link Result} containing the initialized EncryptionClient or an {@link EncryptionError}.
|
|
262
|
+
**/
|
|
263
|
+
init(config: {
|
|
264
|
+
encryptConfig: EncryptConfig;
|
|
265
|
+
workspaceCrn?: string;
|
|
266
|
+
accessKey?: string;
|
|
267
|
+
clientId?: string;
|
|
268
|
+
clientKey?: string;
|
|
269
|
+
keyset?: KeysetIdentifier;
|
|
270
|
+
}): Promise<Result<EncryptionClient, EncryptionError>>;
|
|
271
|
+
/**
|
|
272
|
+
* Encrypt a value - returns a promise which resolves to an encrypted value.
|
|
273
|
+
*
|
|
274
|
+
* @param plaintext - The plaintext value to be encrypted. Can be null.
|
|
275
|
+
* @param opts - Options specifying the column and table for encryption.
|
|
276
|
+
* @returns An EncryptOperation that can be awaited or chained with additional methods.
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* The following example demonstrates how to encrypt a value using the Encryption client.
|
|
280
|
+
* It includes defining an encryption schema with {@link encryptedTable} and {@link encryptedColumn},
|
|
281
|
+
* initializing the client with {@link Encryption}, and performing the encryption.
|
|
282
|
+
*
|
|
283
|
+
* `encrypt` returns an {@link EncryptOperation} which can be awaited to get a {@link Result}
|
|
284
|
+
* which can either be the encrypted value or an {@link EncryptionError}.
|
|
285
|
+
*
|
|
286
|
+
* ```typescript
|
|
287
|
+
* // Define encryption schema
|
|
288
|
+
* import { Encryption } from "@cipherstash/stack"
|
|
289
|
+
* import { encryptedTable, encryptedColumn } from "@cipherstash/stack/schema"
|
|
290
|
+
* const userSchema = encryptedTable("users", {
|
|
291
|
+
* email: encryptedColumn("email"),
|
|
292
|
+
* });
|
|
293
|
+
*
|
|
294
|
+
* // Initialize Encryption client
|
|
295
|
+
* const client = await Encryption({ schemas: [userSchema] })
|
|
296
|
+
*
|
|
297
|
+
* // Encrypt a value
|
|
298
|
+
* const encryptedResult = await client.encrypt(
|
|
299
|
+
* "person@example.com",
|
|
300
|
+
* { column: userSchema.email, table: userSchema }
|
|
301
|
+
* )
|
|
302
|
+
*
|
|
303
|
+
* // Handle encryption result
|
|
304
|
+
* if (encryptedResult.failure) {
|
|
305
|
+
* throw new Error(`Encryption failed: ${encryptedResult.failure.message}`);
|
|
306
|
+
* }
|
|
307
|
+
*
|
|
308
|
+
* console.log("Encrypted data:", encryptedResult.data);
|
|
309
|
+
* ```
|
|
310
|
+
*
|
|
311
|
+
* @example
|
|
312
|
+
* When encrypting data, a {@link LockContext} can be provided to tie the encryption to a specific user or session.
|
|
313
|
+
* This ensures that the same lock context is required for decryption.
|
|
314
|
+
*
|
|
315
|
+
* The following example demonstrates how to create a lock context using a user's JWT token
|
|
316
|
+
* and use it during encryption.
|
|
317
|
+
*
|
|
318
|
+
* ```typescript
|
|
319
|
+
* // Define encryption schema and initialize client as above
|
|
320
|
+
*
|
|
321
|
+
* // Create a lock for the user's `sub` claim from their JWT
|
|
322
|
+
* const lc = new LockContext();
|
|
323
|
+
* const lockContext = await lc.identify(userJwt);
|
|
324
|
+
*
|
|
325
|
+
* if (lockContext.failure) {
|
|
326
|
+
* // Handle the failure
|
|
327
|
+
* }
|
|
328
|
+
*
|
|
329
|
+
* // Encrypt a value with the lock context
|
|
330
|
+
* // Decryption will then require the same lock context
|
|
331
|
+
* const encryptedResult = await client.encrypt(
|
|
332
|
+
* "person@example.com",
|
|
333
|
+
* { column: userSchema.email, table: userSchema }
|
|
334
|
+
* )
|
|
335
|
+
* .withLockContext(lockContext)
|
|
336
|
+
* ```
|
|
337
|
+
*
|
|
338
|
+
* @see {@link Result}
|
|
339
|
+
* @see {@link encryptedTable}
|
|
340
|
+
* @see {@link LockContext}
|
|
341
|
+
* @see {@link EncryptOperation}
|
|
342
|
+
*/
|
|
343
|
+
encrypt(plaintext: JsPlaintext | null, opts: EncryptOptions): EncryptOperation;
|
|
344
|
+
/**
|
|
345
|
+
* Encrypt a query value - returns a promise which resolves to an encrypted query value.
|
|
346
|
+
*
|
|
347
|
+
* @param plaintext - The plaintext value to be encrypted for querying. Can be null.
|
|
348
|
+
* @param opts - Options specifying the column, table, and optional queryType for encryption.
|
|
349
|
+
* @returns An EncryptQueryOperation that can be awaited or chained with additional methods.
|
|
350
|
+
*
|
|
351
|
+
* @example
|
|
352
|
+
* The following example demonstrates how to encrypt a query value using the Encryption client.
|
|
353
|
+
*
|
|
354
|
+
* ```typescript
|
|
355
|
+
* // Define encryption schema
|
|
356
|
+
* import { Encryption } from "@cipherstash/stack"
|
|
357
|
+
* import { encryptedTable, encryptedColumn } from "@cipherstash/stack/schema"
|
|
358
|
+
* const userSchema = encryptedTable("users", {
|
|
359
|
+
* email: encryptedColumn("email").equality(),
|
|
360
|
+
* });
|
|
361
|
+
*
|
|
362
|
+
* // Initialize Encryption client
|
|
363
|
+
* const client = await Encryption({ schemas: [userSchema] })
|
|
364
|
+
*
|
|
365
|
+
* // Encrypt a query value
|
|
366
|
+
* const encryptedResult = await client.encryptQuery(
|
|
367
|
+
* "person@example.com",
|
|
368
|
+
* { column: userSchema.email, table: userSchema, queryType: 'equality' }
|
|
369
|
+
* )
|
|
370
|
+
*
|
|
371
|
+
* // Handle encryption result
|
|
372
|
+
* if (encryptedResult.failure) {
|
|
373
|
+
* throw new Error(`Encryption failed: ${encryptedResult.failure.message}`);
|
|
374
|
+
* }
|
|
375
|
+
*
|
|
376
|
+
* console.log("Encrypted query:", encryptedResult.data);
|
|
377
|
+
* ```
|
|
378
|
+
*
|
|
379
|
+
* @example
|
|
380
|
+
* The queryType can be auto-inferred from the column's configured indexes:
|
|
381
|
+
*
|
|
382
|
+
* ```typescript
|
|
383
|
+
* // When queryType is omitted, it will be inferred from the column's indexes
|
|
384
|
+
* const encryptedResult = await client.encryptQuery(
|
|
385
|
+
* "person@example.com",
|
|
386
|
+
* { column: userSchema.email, table: userSchema }
|
|
387
|
+
* )
|
|
388
|
+
* ```
|
|
389
|
+
*
|
|
390
|
+
* @see {@link EncryptQueryOperation}
|
|
391
|
+
*
|
|
392
|
+
* **JSONB columns (searchableJson):**
|
|
393
|
+
* When `queryType` is omitted on a `searchableJson()` column, the query operation is inferred:
|
|
394
|
+
* - String plaintext → `steVecSelector` (JSONPath queries like `'$.user.email'`)
|
|
395
|
+
* - Object/Array plaintext → `steVecTerm` (containment queries like `{ role: 'admin' }`)
|
|
396
|
+
*/
|
|
397
|
+
encryptQuery(plaintext: JsPlaintext | null, opts: EncryptQueryOptions): EncryptQueryOperation;
|
|
398
|
+
/**
|
|
399
|
+
* Encrypt multiple values for use in queries (batch operation).
|
|
400
|
+
* @param terms - Array of query terms to encrypt
|
|
401
|
+
*/
|
|
402
|
+
encryptQuery(terms: readonly ScalarQueryTerm[]): BatchEncryptQueryOperation;
|
|
403
|
+
/**
|
|
404
|
+
* Decryption - returns a promise which resolves to a decrypted value.
|
|
405
|
+
*
|
|
406
|
+
* @param encryptedData - The encrypted data to be decrypted.
|
|
407
|
+
* @returns A DecryptOperation that can be awaited or chained with additional methods.
|
|
408
|
+
*
|
|
409
|
+
* @example
|
|
410
|
+
* The following example demonstrates how to decrypt a value that was previously encrypted using the {@link encrypt} method.
|
|
411
|
+
* It includes encrypting a value first, then decrypting it, and handling the result.
|
|
412
|
+
*
|
|
413
|
+
* ```typescript
|
|
414
|
+
* const encryptedData = await client.encrypt(
|
|
415
|
+
* "person@example.com",
|
|
416
|
+
* { column: "email", table: "users" }
|
|
417
|
+
* )
|
|
418
|
+
* const decryptResult = await client.decrypt(encryptedData)
|
|
419
|
+
* if (decryptResult.failure) {
|
|
420
|
+
* throw new Error(`Decryption failed: ${decryptResult.failure.message}`);
|
|
421
|
+
* }
|
|
422
|
+
* console.log("Decrypted data:", decryptResult.data);
|
|
423
|
+
* ```
|
|
424
|
+
*
|
|
425
|
+
* @example
|
|
426
|
+
* Provide a lock context when decrypting:
|
|
427
|
+
* ```typescript
|
|
428
|
+
* await client.decrypt(encryptedData)
|
|
429
|
+
* .withLockContext(lockContext)
|
|
430
|
+
* ```
|
|
431
|
+
*
|
|
432
|
+
* @see {@link LockContext}
|
|
433
|
+
* @see {@link DecryptOperation}
|
|
434
|
+
*/
|
|
435
|
+
decrypt(encryptedData: Encrypted): DecryptOperation;
|
|
436
|
+
/**
|
|
437
|
+
* Encrypt a model (object) based on the table schema.
|
|
438
|
+
*
|
|
439
|
+
* Only fields whose keys match columns defined in the table schema are encrypted.
|
|
440
|
+
* All other fields are passed through unchanged. Returns a thenable operation
|
|
441
|
+
* that supports `.withLockContext()` for identity-aware encryption.
|
|
442
|
+
*
|
|
443
|
+
* @param input - The model object with plaintext values to encrypt.
|
|
444
|
+
* @param table - The table schema defining which fields to encrypt.
|
|
445
|
+
* @returns An `EncryptModelOperation<T>` that can be awaited to get a `Result`
|
|
446
|
+
* containing the model with encrypted fields, or an `EncryptionError`.
|
|
447
|
+
*
|
|
448
|
+
* @example
|
|
449
|
+
* ```typescript
|
|
450
|
+
* import { Encryption } from "@cipherstash/stack"
|
|
451
|
+
* import { encryptedTable, encryptedColumn } from "@cipherstash/stack/schema"
|
|
452
|
+
*
|
|
453
|
+
* type User = { id: string; email: string; createdAt: Date }
|
|
454
|
+
*
|
|
455
|
+
* const usersSchema = encryptedTable("users", {
|
|
456
|
+
* email: encryptedColumn("email").equality(),
|
|
457
|
+
* })
|
|
458
|
+
*
|
|
459
|
+
* const client = await Encryption({ schemas: [usersSchema] })
|
|
460
|
+
*
|
|
461
|
+
* const result = await client.encryptModel<User>(
|
|
462
|
+
* { id: "user_123", email: "alice@example.com", createdAt: new Date() },
|
|
463
|
+
* usersSchema,
|
|
464
|
+
* )
|
|
465
|
+
*
|
|
466
|
+
* if (result.failure) {
|
|
467
|
+
* console.error(result.failure.message)
|
|
468
|
+
* } else {
|
|
469
|
+
* // result.data.id is unchanged, result.data.email is encrypted
|
|
470
|
+
* console.log(result.data)
|
|
471
|
+
* }
|
|
472
|
+
* ```
|
|
473
|
+
*/
|
|
474
|
+
encryptModel<T extends Record<string, unknown>>(input: Decrypted<T>, table: ProtectTable<ProtectTableColumn>): EncryptModelOperation<T>;
|
|
475
|
+
/**
|
|
476
|
+
* Decrypt a model (object) whose fields contain encrypted values.
|
|
477
|
+
*
|
|
478
|
+
* Identifies encrypted fields automatically and decrypts them, returning the
|
|
479
|
+
* model with plaintext values. Returns a thenable operation that supports
|
|
480
|
+
* `.withLockContext()` for identity-aware decryption.
|
|
481
|
+
*
|
|
482
|
+
* @param input - The model object with encrypted field values.
|
|
483
|
+
* @returns A `DecryptModelOperation<T>` that can be awaited to get a `Result`
|
|
484
|
+
* containing the model with decrypted plaintext fields, or an `EncryptionError`.
|
|
485
|
+
*
|
|
486
|
+
* @example
|
|
487
|
+
* ```typescript
|
|
488
|
+
* // Decrypt a previously encrypted model
|
|
489
|
+
* const decrypted = await client.decryptModel<User>(encryptedUser)
|
|
490
|
+
*
|
|
491
|
+
* if (decrypted.failure) {
|
|
492
|
+
* console.error(decrypted.failure.message)
|
|
493
|
+
* } else {
|
|
494
|
+
* console.log(decrypted.data.email) // "alice@example.com"
|
|
495
|
+
* }
|
|
496
|
+
*
|
|
497
|
+
* // With a lock context
|
|
498
|
+
* const decrypted = await client
|
|
499
|
+
* .decryptModel<User>(encryptedUser)
|
|
500
|
+
* .withLockContext(lockContext)
|
|
501
|
+
* ```
|
|
502
|
+
*/
|
|
503
|
+
decryptModel<T extends Record<string, unknown>>(input: T): DecryptModelOperation<T>;
|
|
504
|
+
/**
|
|
505
|
+
* Encrypt multiple models (objects) in a single bulk operation.
|
|
506
|
+
*
|
|
507
|
+
* Performs a single call to ZeroKMS regardless of the number of models,
|
|
508
|
+
* while still using a unique key for each encrypted value. Only fields
|
|
509
|
+
* matching the table schema are encrypted; other fields pass through unchanged.
|
|
510
|
+
*
|
|
511
|
+
* @param input - An array of model objects with plaintext values to encrypt.
|
|
512
|
+
* @param table - The table schema defining which fields to encrypt.
|
|
513
|
+
* @returns A `BulkEncryptModelsOperation<T>` that can be awaited to get a `Result`
|
|
514
|
+
* containing an array of models with encrypted fields, or an `EncryptionError`.
|
|
515
|
+
*
|
|
516
|
+
* @example
|
|
517
|
+
* ```typescript
|
|
518
|
+
* import { Encryption } from "@cipherstash/stack"
|
|
519
|
+
* import { encryptedTable, encryptedColumn } from "@cipherstash/stack/schema"
|
|
520
|
+
*
|
|
521
|
+
* type User = { id: string; email: string }
|
|
522
|
+
*
|
|
523
|
+
* const usersSchema = encryptedTable("users", {
|
|
524
|
+
* email: encryptedColumn("email"),
|
|
525
|
+
* })
|
|
526
|
+
*
|
|
527
|
+
* const client = await Encryption({ schemas: [usersSchema] })
|
|
528
|
+
*
|
|
529
|
+
* const result = await client.bulkEncryptModels<User>(
|
|
530
|
+
* [
|
|
531
|
+
* { id: "1", email: "alice@example.com" },
|
|
532
|
+
* { id: "2", email: "bob@example.com" },
|
|
533
|
+
* ],
|
|
534
|
+
* usersSchema,
|
|
535
|
+
* )
|
|
536
|
+
*
|
|
537
|
+
* if (!result.failure) {
|
|
538
|
+
* console.log(result.data) // array of models with encrypted email fields
|
|
539
|
+
* }
|
|
540
|
+
* ```
|
|
541
|
+
*/
|
|
542
|
+
bulkEncryptModels<T extends Record<string, unknown>>(input: Array<Decrypted<T>>, table: ProtectTable<ProtectTableColumn>): BulkEncryptModelsOperation<T>;
|
|
543
|
+
/**
|
|
544
|
+
* Decrypt multiple models (objects) in a single bulk operation.
|
|
545
|
+
*
|
|
546
|
+
* Performs a single call to ZeroKMS regardless of the number of models,
|
|
547
|
+
* restoring all encrypted fields to their original plaintext values.
|
|
548
|
+
*
|
|
549
|
+
* @param input - An array of model objects with encrypted field values.
|
|
550
|
+
* @returns A `BulkDecryptModelsOperation<T>` that can be awaited to get a `Result`
|
|
551
|
+
* containing an array of models with decrypted plaintext fields, or an `EncryptionError`.
|
|
552
|
+
*
|
|
553
|
+
* @example
|
|
554
|
+
* ```typescript
|
|
555
|
+
* const encryptedUsers = encryptedResult.data // from bulkEncryptModels
|
|
556
|
+
*
|
|
557
|
+
* const result = await client.bulkDecryptModels<User>(encryptedUsers)
|
|
558
|
+
*
|
|
559
|
+
* if (!result.failure) {
|
|
560
|
+
* for (const user of result.data) {
|
|
561
|
+
* console.log(user.email) // plaintext email
|
|
562
|
+
* }
|
|
563
|
+
* }
|
|
564
|
+
*
|
|
565
|
+
* // With a lock context
|
|
566
|
+
* const result = await client
|
|
567
|
+
* .bulkDecryptModels<User>(encryptedUsers)
|
|
568
|
+
* .withLockContext(lockContext)
|
|
569
|
+
* ```
|
|
570
|
+
*/
|
|
571
|
+
bulkDecryptModels<T extends Record<string, unknown>>(input: Array<T>): BulkDecryptModelsOperation<T>;
|
|
572
|
+
/**
|
|
573
|
+
* Encrypt multiple plaintext values in a single bulk operation.
|
|
574
|
+
*
|
|
575
|
+
* Each value is encrypted with its own unique key via a single call to ZeroKMS.
|
|
576
|
+
* Values can include optional `id` fields for correlating results back to
|
|
577
|
+
* your application data. Null plaintext values are preserved as null.
|
|
578
|
+
*
|
|
579
|
+
* @param plaintexts - An array of objects with `plaintext` (and optional `id`) fields.
|
|
580
|
+
* @param opts - Options specifying the target column and table for encryption.
|
|
581
|
+
* @returns A `BulkEncryptOperation` that can be awaited to get a `Result`
|
|
582
|
+
* containing an array of `{ id?, data: Encrypted }` objects, or an `EncryptionError`.
|
|
583
|
+
*
|
|
584
|
+
* @example
|
|
585
|
+
* ```typescript
|
|
586
|
+
* import { Encryption } from "@cipherstash/stack"
|
|
587
|
+
* import { encryptedTable, encryptedColumn } from "@cipherstash/stack/schema"
|
|
588
|
+
*
|
|
589
|
+
* const users = encryptedTable("users", {
|
|
590
|
+
* email: encryptedColumn("email"),
|
|
591
|
+
* })
|
|
592
|
+
* const client = await Encryption({ schemas: [users] })
|
|
593
|
+
*
|
|
594
|
+
* const result = await client.bulkEncrypt(
|
|
595
|
+
* [
|
|
596
|
+
* { id: "u1", plaintext: "alice@example.com" },
|
|
597
|
+
* { id: "u2", plaintext: "bob@example.com" },
|
|
598
|
+
* { id: "u3", plaintext: null },
|
|
599
|
+
* ],
|
|
600
|
+
* { column: users.email, table: users },
|
|
601
|
+
* )
|
|
602
|
+
*
|
|
603
|
+
* if (!result.failure) {
|
|
604
|
+
* // result.data = [{ id: "u1", data: Encrypted }, { id: "u2", data: Encrypted }, ...]
|
|
605
|
+
* console.log(result.data)
|
|
606
|
+
* }
|
|
607
|
+
* ```
|
|
608
|
+
*/
|
|
609
|
+
bulkEncrypt(plaintexts: BulkEncryptPayload, opts: EncryptOptions): BulkEncryptOperation;
|
|
610
|
+
/**
|
|
611
|
+
* Decrypt multiple encrypted values in a single bulk operation.
|
|
612
|
+
*
|
|
613
|
+
* Performs a single call to ZeroKMS to decrypt all values. The result uses
|
|
614
|
+
* a multi-status pattern: each item in the returned array has either a `data`
|
|
615
|
+
* field (success) or an `error` field (failure), allowing graceful handling
|
|
616
|
+
* of partial failures.
|
|
617
|
+
*
|
|
618
|
+
* @param encryptedPayloads - An array of objects with `data` (encrypted payload) and optional `id` fields.
|
|
619
|
+
* @returns A `BulkDecryptOperation` that can be awaited to get a `Result`
|
|
620
|
+
* containing an array of `{ id?, data: plaintext }` or `{ id?, error: string }` objects,
|
|
621
|
+
* or an `EncryptionError` if the entire operation fails.
|
|
622
|
+
*
|
|
623
|
+
* @example
|
|
624
|
+
* ```typescript
|
|
625
|
+
* const encrypted = await client.bulkEncrypt(plaintexts, { column: users.email, table: users })
|
|
626
|
+
*
|
|
627
|
+
* const result = await client.bulkDecrypt(encrypted.data)
|
|
628
|
+
*
|
|
629
|
+
* if (!result.failure) {
|
|
630
|
+
* for (const item of result.data) {
|
|
631
|
+
* if ("data" in item) {
|
|
632
|
+
* console.log(`${item.id}: ${item.data}`)
|
|
633
|
+
* } else {
|
|
634
|
+
* console.error(`${item.id} failed: ${item.error}`)
|
|
635
|
+
* }
|
|
636
|
+
* }
|
|
637
|
+
* }
|
|
638
|
+
* ```
|
|
639
|
+
*/
|
|
640
|
+
bulkDecrypt(encryptedPayloads: BulkDecryptPayload): BulkDecryptOperation;
|
|
641
|
+
/** e.g., debugging or environment info */
|
|
642
|
+
clientInfo(): {
|
|
643
|
+
workspaceId: string | undefined;
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
export { type AuditConfig as A, EncryptionClient as E };
|