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