@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,7 +1,808 @@
1
- import '../errors/index.cjs';
2
- import '../types-public-BTxqjmtv.cjs';
3
- import '@byteslice/result';
4
- import '@cipherstash/protect-ffi';
5
- export { B as BatchEncryptQueryOperation, b as BulkDecryptModelsOperation, c as BulkDecryptOperation, d as BulkEncryptModelsOperation, e as BulkEncryptOperation, D as DecryptModelOperation, f as DecryptOperation, g as EncryptModelOperation, h as EncryptOperation, i as EncryptQueryOperation, E as Encryption, a as EncryptionClient, n as noClientError } from '../client-Dt98Rugc.cjs';
1
+ import { Result } from '@byteslice/result';
2
+ import { EncryptionError } from '../errors/index.cjs';
3
+ import { w as EncryptedQueryResult, i as Client, S as ScalarQueryTerm, f as BulkDecryptedData, e as BulkDecryptPayload, D as Decrypted, h as BulkEncryptedData, g as BulkEncryptPayload, n as EncryptOptions, B as BuildableColumn, b as BuildableTable, p as Encrypted, P as Plaintext, o as EncryptQueryOptions, a as BuildableQueryColumn, Q as QueryTypeName, x as EncryptedReturnType, E as EncryptConfig, K as KeysetIdentifier, t as EncryptedFromBuildableTable, G as EncryptionClientConfig } from '../types-public-QMjYNfQO.cjs';
4
+ import { LockContextInput } from '../identity/index.cjs';
5
+ import { E as EncryptionOperation } from '../base-operation-AOAIvsSB.cjs';
6
+ import { JsPlaintext, AuthStrategy } from '@cipherstash/protect-ffi';
6
7
  import 'zod';
7
- import '../identity/index.cjs';
8
+
9
+ declare class BatchEncryptQueryOperation extends EncryptionOperation<EncryptedQueryResult[]> {
10
+ private client;
11
+ private terms;
12
+ constructor(client: Client, terms: readonly ScalarQueryTerm[]);
13
+ withLockContext(lockContext: LockContextInput): BatchEncryptQueryOperationWithLockContext;
14
+ execute(): Promise<Result<EncryptedQueryResult[], EncryptionError>>;
15
+ }
16
+ declare class BatchEncryptQueryOperationWithLockContext extends EncryptionOperation<EncryptedQueryResult[]> {
17
+ private client;
18
+ private terms;
19
+ private lockContext;
20
+ constructor(client: Client, terms: readonly ScalarQueryTerm[], lockContext: LockContextInput, auditMetadata?: Record<string, unknown>);
21
+ execute(): Promise<Result<EncryptedQueryResult[], EncryptionError>>;
22
+ }
23
+
24
+ declare class BulkDecryptOperation extends EncryptionOperation<BulkDecryptedData> {
25
+ private client;
26
+ private encryptedPayloads;
27
+ constructor(client: Client, encryptedPayloads: BulkDecryptPayload);
28
+ withLockContext(lockContext: LockContextInput): BulkDecryptOperationWithLockContext;
29
+ execute(): Promise<Result<BulkDecryptedData, EncryptionError>>;
30
+ getOperation(): {
31
+ client: Client;
32
+ encryptedPayloads: BulkDecryptPayload;
33
+ };
34
+ }
35
+ declare class BulkDecryptOperationWithLockContext extends EncryptionOperation<BulkDecryptedData> {
36
+ private operation;
37
+ private lockContext;
38
+ constructor(operation: BulkDecryptOperation, lockContext: LockContextInput);
39
+ execute(): Promise<Result<BulkDecryptedData, EncryptionError>>;
40
+ }
41
+
42
+ declare class BulkDecryptModelsOperation<T extends Record<string, unknown>> extends EncryptionOperation<Decrypted<T>[]> {
43
+ private client;
44
+ private models;
45
+ constructor(client: Client, models: T[]);
46
+ withLockContext(lockContext: LockContextInput): BulkDecryptModelsOperationWithLockContext<T>;
47
+ execute(): Promise<Result<Decrypted<T>[], EncryptionError>>;
48
+ getOperation(): {
49
+ client: Client;
50
+ models: T[];
51
+ };
52
+ }
53
+ declare class BulkDecryptModelsOperationWithLockContext<T extends Record<string, unknown>> extends EncryptionOperation<Decrypted<T>[]> {
54
+ private operation;
55
+ private lockContext;
56
+ constructor(operation: BulkDecryptModelsOperation<T>, lockContext: LockContextInput);
57
+ execute(): Promise<Result<Decrypted<T>[], EncryptionError>>;
58
+ }
59
+
60
+ declare class BulkEncryptOperation extends EncryptionOperation<BulkEncryptedData> {
61
+ private client;
62
+ private plaintexts;
63
+ private column;
64
+ private table;
65
+ constructor(client: Client, plaintexts: BulkEncryptPayload, opts: EncryptOptions);
66
+ withLockContext(lockContext: LockContextInput): BulkEncryptOperationWithLockContext;
67
+ execute(): Promise<Result<BulkEncryptedData, EncryptionError>>;
68
+ getOperation(): {
69
+ client: Client;
70
+ plaintexts: BulkEncryptPayload;
71
+ column: BuildableColumn;
72
+ table: BuildableTable;
73
+ };
74
+ }
75
+ declare class BulkEncryptOperationWithLockContext extends EncryptionOperation<BulkEncryptedData> {
76
+ private operation;
77
+ private lockContext;
78
+ constructor(operation: BulkEncryptOperation, lockContext: LockContextInput);
79
+ execute(): Promise<Result<BulkEncryptedData, EncryptionError>>;
80
+ }
81
+
82
+ declare class BulkEncryptModelsOperation<T extends Record<string, unknown>> extends EncryptionOperation<T[]> {
83
+ private client;
84
+ private models;
85
+ private table;
86
+ constructor(client: Client, models: Record<string, unknown>[], table: BuildableTable);
87
+ withLockContext(lockContext: LockContextInput): BulkEncryptModelsOperationWithLockContext<T>;
88
+ execute(): Promise<Result<T[], EncryptionError>>;
89
+ getOperation(): {
90
+ client: Client;
91
+ models: Record<string, unknown>[];
92
+ table: BuildableTable;
93
+ };
94
+ }
95
+ declare class BulkEncryptModelsOperationWithLockContext<T extends Record<string, unknown>> extends EncryptionOperation<T[]> {
96
+ private operation;
97
+ private lockContext;
98
+ constructor(operation: BulkEncryptModelsOperation<T>, lockContext: LockContextInput);
99
+ execute(): Promise<Result<T[], EncryptionError>>;
100
+ }
101
+
102
+ /**
103
+ * Decrypts an encrypted payload using the provided client.
104
+ * This is the type returned by the {@link EncryptionClient.decrypt | decrypt} method of the {@link EncryptionClient}.
105
+ */
106
+ declare class DecryptOperation extends EncryptionOperation<JsPlaintext> {
107
+ private client;
108
+ private encryptedData;
109
+ constructor(client: Client, encryptedData: Encrypted | null);
110
+ withLockContext(lockContext: LockContextInput): DecryptOperationWithLockContext;
111
+ execute(): Promise<Result<JsPlaintext, EncryptionError>>;
112
+ getOperation(): {
113
+ client: Client;
114
+ encryptedData: Encrypted | null;
115
+ auditData?: Record<string, unknown>;
116
+ };
117
+ }
118
+ declare class DecryptOperationWithLockContext extends EncryptionOperation<JsPlaintext> {
119
+ private operation;
120
+ private lockContext;
121
+ constructor(operation: DecryptOperation, lockContext: LockContextInput);
122
+ execute(): Promise<Result<JsPlaintext, EncryptionError>>;
123
+ }
124
+
125
+ declare class DecryptModelOperation<T extends Record<string, unknown>> extends EncryptionOperation<Decrypted<T>> {
126
+ private client;
127
+ private model;
128
+ constructor(client: Client, model: T);
129
+ withLockContext(lockContext: LockContextInput): DecryptModelOperationWithLockContext<T>;
130
+ execute(): Promise<Result<Decrypted<T>, EncryptionError>>;
131
+ getOperation(): {
132
+ client: Client;
133
+ model: T;
134
+ };
135
+ }
136
+ declare class DecryptModelOperationWithLockContext<T extends Record<string, unknown>> extends EncryptionOperation<Decrypted<T>> {
137
+ private operation;
138
+ private lockContext;
139
+ constructor(operation: DecryptModelOperation<T>, lockContext: LockContextInput);
140
+ execute(): Promise<Result<Decrypted<T>, EncryptionError>>;
141
+ }
142
+
143
+ declare class EncryptOperation extends EncryptionOperation<Encrypted> {
144
+ private client;
145
+ private plaintext;
146
+ private column;
147
+ private table;
148
+ constructor(client: Client, plaintext: Plaintext | null, opts: EncryptOptions);
149
+ withLockContext(lockContext: LockContextInput): EncryptOperationWithLockContext;
150
+ execute(): Promise<Result<Encrypted, EncryptionError>>;
151
+ getOperation(): {
152
+ client: Client;
153
+ plaintext: Plaintext | null;
154
+ column: BuildableColumn;
155
+ table: BuildableTable;
156
+ };
157
+ }
158
+ declare class EncryptOperationWithLockContext extends EncryptionOperation<Encrypted> {
159
+ private operation;
160
+ private lockContext;
161
+ constructor(operation: EncryptOperation, lockContext: LockContextInput);
162
+ execute(): Promise<Result<Encrypted, EncryptionError>>;
163
+ }
164
+
165
+ declare class EncryptModelOperation<T extends Record<string, unknown>> extends EncryptionOperation<T> {
166
+ private client;
167
+ private model;
168
+ private table;
169
+ constructor(client: Client, model: Record<string, unknown>, table: BuildableTable);
170
+ withLockContext(lockContext: LockContextInput): EncryptModelOperationWithLockContext<T>;
171
+ execute(): Promise<Result<T, EncryptionError>>;
172
+ getOperation(): {
173
+ client: Client;
174
+ model: Record<string, unknown>;
175
+ table: BuildableTable;
176
+ };
177
+ }
178
+ declare class EncryptModelOperationWithLockContext<T extends Record<string, unknown>> extends EncryptionOperation<T> {
179
+ private operation;
180
+ private lockContext;
181
+ constructor(operation: EncryptModelOperation<T>, lockContext: LockContextInput);
182
+ execute(): Promise<Result<T, EncryptionError>>;
183
+ }
184
+
185
+ declare class EncryptQueryOperation extends EncryptionOperation<EncryptedQueryResult> {
186
+ private client;
187
+ private plaintext;
188
+ private opts;
189
+ constructor(client: Client, plaintext: Plaintext | null | undefined, opts: EncryptQueryOptions);
190
+ withLockContext(lockContext: LockContextInput): EncryptQueryOperationWithLockContext;
191
+ execute(): Promise<Result<EncryptedQueryResult, EncryptionError>>;
192
+ getOperation(): {
193
+ column: BuildableQueryColumn;
194
+ table: BuildableTable;
195
+ queryType?: QueryTypeName;
196
+ returnType?: EncryptedReturnType;
197
+ client: Client;
198
+ plaintext: Plaintext | null | undefined;
199
+ };
200
+ }
201
+ declare class EncryptQueryOperationWithLockContext extends EncryptionOperation<EncryptedQueryResult> {
202
+ private client;
203
+ private plaintext;
204
+ private opts;
205
+ private lockContext;
206
+ constructor(client: Client, plaintext: Plaintext | null | undefined, opts: EncryptQueryOptions, lockContext: LockContextInput, auditMetadata?: Record<string, unknown>);
207
+ execute(): Promise<Result<EncryptedQueryResult, EncryptionError>>;
208
+ }
209
+
210
+ declare const noClientError: () => Error;
211
+ /**
212
+ * Resolve the EQL wire version for a client from its schema set.
213
+ *
214
+ * One FFI client emits exactly one wire format, so the whole schema set must
215
+ * agree. EQL v3 tables (from `@cipherstash/stack/v3`) are detected by their
216
+ * `buildColumnKeyMap()` marker — v2 tables don't have one:
217
+ *
218
+ * - every schema is v3 → `3`;
219
+ * - no schema is v3 → `undefined`, leaving the FFI's v2 default (and its
220
+ * byte-identical v2 output) untouched;
221
+ * - a mix of the two → throws: the v2 tables target `eql_v2_encrypted`
222
+ * columns and the v3 tables target `eql_v3` domains, so no single wire
223
+ * format serves both. Split them across two clients.
224
+ *
225
+ * An explicit `config.eqlVersion` bypasses detection (the wire format is
226
+ * then unambiguous — e.g. writing v2-wire from a v3 schema set during a
227
+ * migration), but a mixed schema set still throws.
228
+ *
229
+ * @internal exported for unit-test coverage of the detection matrix.
230
+ */
231
+ declare function resolveEqlVersion(schemas: readonly BuildableTable[], explicit?: 2 | 3): 2 | 3 | undefined;
232
+ /** The EncryptionClient is the main entry point for interacting with the CipherStash Encryption library.
233
+ * It provides methods for encrypting and decrypting individual values, as well as models (objects) and bulk operations.
234
+ *
235
+ * The client must be initialized using the {@link Encryption} function before it can be used.
236
+ */
237
+ declare class EncryptionClient {
238
+ private client;
239
+ private encryptConfig;
240
+ /**
241
+ * Initializes the EncryptionClient with the provided configuration.
242
+ * @internal
243
+ * @param config - The configuration object for initializing the client.
244
+ * @returns A promise that resolves to a {@link Result} containing the initialized EncryptionClient or an {@link EncryptionError}.
245
+ **/
246
+ init(config: {
247
+ encryptConfig: EncryptConfig;
248
+ workspaceCrn?: string;
249
+ accessKey?: string;
250
+ clientId?: string;
251
+ clientKey?: string;
252
+ keyset?: KeysetIdentifier;
253
+ authStrategy?: AuthStrategy;
254
+ eqlVersion?: 2 | 3;
255
+ }): Promise<Result<EncryptionClient, EncryptionError>>;
256
+ /**
257
+ * Encrypt a value - returns a promise which resolves to an encrypted value.
258
+ *
259
+ * @param plaintext - The plaintext value to be encrypted.
260
+ * @param opts - Options specifying the column (or nested field) and table for encryption. See {@link EncryptOptions}.
261
+ * @returns An EncryptOperation that can be awaited or chained with additional methods.
262
+ *
263
+ * @example
264
+ * The following example demonstrates how to encrypt a value using the Encryption client.
265
+ * It includes defining an encryption schema with {@link encryptedTable} and {@link encryptedColumn},
266
+ * initializing the client with {@link Encryption}, and performing the encryption.
267
+ *
268
+ * `encrypt` returns an {@link EncryptOperation} which can be awaited to get a {@link Result}
269
+ * which can either be the encrypted value or an {@link EncryptionError}.
270
+ *
271
+ * ```typescript
272
+ * // Define encryption schema
273
+ * import { Encryption } from "@cipherstash/stack"
274
+ * import { encryptedTable, encryptedColumn } from "@cipherstash/stack/schema"
275
+ * const userSchema = encryptedTable("users", {
276
+ * email: encryptedColumn("email"),
277
+ * });
278
+ *
279
+ * // Initialize Encryption client
280
+ * const client = await Encryption({ schemas: [userSchema] })
281
+ *
282
+ * // Encrypt a value
283
+ * const encryptedResult = await client.encrypt(
284
+ * "person@example.com",
285
+ * { column: userSchema.email, table: userSchema }
286
+ * )
287
+ *
288
+ * // Handle encryption result
289
+ * if (encryptedResult.failure) {
290
+ * throw new Error(`Encryption failed: ${encryptedResult.failure.message}`);
291
+ * }
292
+ *
293
+ * console.log("Encrypted data:", encryptedResult.data);
294
+ * ```
295
+ *
296
+ * @example
297
+ * When encrypting data, a {@link LockContext} can be provided to tie the encryption to a specific user or session.
298
+ * This ensures that the same lock context is required for decryption.
299
+ *
300
+ * The following example demonstrates how to create a lock context using a user's JWT token
301
+ * and use it during encryption.
302
+ *
303
+ * ```typescript
304
+ * // Define encryption schema and initialize client as above
305
+ *
306
+ * // Create a lock for the user's `sub` claim from their JWT
307
+ * const lc = new LockContext();
308
+ * const lockContext = await lc.identify(userJwt);
309
+ *
310
+ * if (lockContext.failure) {
311
+ * // Handle the failure
312
+ * }
313
+ *
314
+ * // Encrypt a value with the lock context
315
+ * // Decryption will then require the same lock context
316
+ * const encryptedResult = await client.encrypt(
317
+ * "person@example.com",
318
+ * { column: userSchema.email, table: userSchema }
319
+ * )
320
+ * .withLockContext(lockContext)
321
+ * ```
322
+ *
323
+ * @see {@link EncryptOptions}
324
+ * @see {@link Result}
325
+ * @see {@link encryptedTable}
326
+ * @see {@link encryptedColumn}
327
+ * @see {@link encryptedField}
328
+ * @see {@link LockContext}
329
+ * @see {@link EncryptOperation}
330
+ */
331
+ encrypt(plaintext: Plaintext, opts: EncryptOptions): EncryptOperation;
332
+ /**
333
+ * Encrypt a query value - returns a promise which resolves to an encrypted query value.
334
+ *
335
+ * @param plaintext - The plaintext value to be encrypted for querying.
336
+ * @param opts - Options specifying the column, table, and optional queryType for encryption.
337
+ * @returns An EncryptQueryOperation that can be awaited or chained with additional methods.
338
+ *
339
+ * @example
340
+ * The following example demonstrates how to encrypt a query value using the Encryption client.
341
+ *
342
+ * ```typescript
343
+ * // Define encryption schema
344
+ * import { Encryption } from "@cipherstash/stack"
345
+ * import { encryptedTable, encryptedColumn } from "@cipherstash/stack/schema"
346
+ * const userSchema = encryptedTable("users", {
347
+ * email: encryptedColumn("email").equality(),
348
+ * });
349
+ *
350
+ * // Initialize Encryption client
351
+ * const client = await Encryption({ schemas: [userSchema] })
352
+ *
353
+ * // Encrypt a query value
354
+ * const encryptedResult = await client.encryptQuery(
355
+ * "person@example.com",
356
+ * { column: userSchema.email, table: userSchema, queryType: 'equality' }
357
+ * )
358
+ *
359
+ * // Handle encryption result
360
+ * if (encryptedResult.failure) {
361
+ * throw new Error(`Encryption failed: ${encryptedResult.failure.message}`);
362
+ * }
363
+ *
364
+ * console.log("Encrypted query:", encryptedResult.data);
365
+ * ```
366
+ *
367
+ * @example
368
+ * The queryType can be auto-inferred from the column's configured indexes:
369
+ *
370
+ * ```typescript
371
+ * // When queryType is omitted, it will be inferred from the column's indexes
372
+ * const encryptedResult = await client.encryptQuery(
373
+ * "person@example.com",
374
+ * { column: userSchema.email, table: userSchema }
375
+ * )
376
+ * ```
377
+ *
378
+ * @see {@link EncryptQueryOperation}
379
+ *
380
+ * **JSONB columns (searchableJson):**
381
+ * When `queryType` is omitted on a `searchableJson()` column, the query operation is inferred:
382
+ * - String plaintext → `steVecSelector` (JSONPath queries like `'$.user.email'`)
383
+ * - Object/Array plaintext → `steVecTerm` (containment queries like `{ role: 'admin' }`)
384
+ */
385
+ encryptQuery(plaintext: Plaintext, opts: EncryptQueryOptions): EncryptQueryOperation;
386
+ /**
387
+ * Encrypt multiple values for use in queries (batch operation).
388
+ * @param terms - Array of query terms to encrypt
389
+ */
390
+ encryptQuery(terms: readonly ScalarQueryTerm[]): BatchEncryptQueryOperation;
391
+ /**
392
+ * Decryption - returns a promise which resolves to a decrypted value.
393
+ *
394
+ * @param encryptedData - The encrypted data to be decrypted.
395
+ * @returns A DecryptOperation that can be awaited or chained with additional methods.
396
+ *
397
+ * @example
398
+ * The following example demonstrates how to decrypt a value that was previously encrypted using the {@link encrypt} method.
399
+ * It includes encrypting a value first, then decrypting it, and handling the result.
400
+ *
401
+ * ```typescript
402
+ * const encryptedData = await client.encrypt(
403
+ * "person@example.com",
404
+ * { column: "email", table: "users" }
405
+ * )
406
+ * const decryptResult = await client.decrypt(encryptedData)
407
+ * if (decryptResult.failure) {
408
+ * throw new Error(`Decryption failed: ${decryptResult.failure.message}`);
409
+ * }
410
+ * console.log("Decrypted data:", decryptResult.data);
411
+ * ```
412
+ *
413
+ * @example
414
+ * Provide a lock context when decrypting:
415
+ * ```typescript
416
+ * await client.decrypt(encryptedData)
417
+ * .withLockContext(lockContext)
418
+ * ```
419
+ *
420
+ * @remarks
421
+ * The public input type rejects null, but at runtime `decrypt` will
422
+ * short-circuit and return null when given a null ciphertext
423
+ * (defense in depth for legacy / manually-NULLed DB rows reached via
424
+ * casts or dynamic field walking). The narrow return type holds for
425
+ * any caller that respects the input contract.
426
+ *
427
+ * @see {@link LockContext}
428
+ * @see {@link DecryptOperation}
429
+ */
430
+ decrypt(encryptedData: Encrypted): DecryptOperation;
431
+ /**
432
+ * Encrypt a model (object) based on the table schema.
433
+ *
434
+ * Only fields whose keys match columns defined in the table schema are encrypted.
435
+ * All other fields are passed through unchanged. Returns a thenable operation
436
+ * that supports `.withLockContext()` for identity-aware encryption.
437
+ *
438
+ * The return type is **schema-aware**: fields matching the table schema are
439
+ * typed as `Encrypted`, while other fields retain their original types. For
440
+ * best results, let TypeScript infer the type parameters from the arguments
441
+ * rather than providing an explicit type argument.
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` that can be awaited to get a `Result`
446
+ * containing the model with schema-defined fields typed as `Encrypted`,
447
+ * or an `EncryptionError`.
448
+ *
449
+ * @example
450
+ * ```typescript
451
+ * import { Encryption } from "@cipherstash/stack"
452
+ * import { encryptedTable, encryptedColumn } from "@cipherstash/stack/schema"
453
+ *
454
+ * type User = { id: string; email: string; createdAt: Date }
455
+ *
456
+ * const usersSchema = encryptedTable("users", {
457
+ * email: encryptedColumn("email").equality(),
458
+ * })
459
+ *
460
+ * const client = await Encryption({ schemas: [usersSchema] })
461
+ *
462
+ * // Let TypeScript infer the return type from the schema.
463
+ * // result.data.email is typed as `Encrypted`, result.data.id stays `string`.
464
+ * const result = await client.encryptModel(
465
+ * { id: "user_123", email: "alice@example.com", createdAt: new Date() },
466
+ * usersSchema,
467
+ * )
468
+ *
469
+ * if (result.failure) {
470
+ * console.error(result.failure.message)
471
+ * } else {
472
+ * console.log(result.data.id) // string
473
+ * console.log(result.data.email) // Encrypted
474
+ * }
475
+ * ```
476
+ */
477
+ encryptModel<T extends Record<string, unknown>, Table extends BuildableTable>(input: T, table: Table): EncryptModelOperation<EncryptedFromBuildableTable<T, Table>>;
478
+ /**
479
+ * Decrypt a model (object) whose fields contain encrypted values.
480
+ *
481
+ * Identifies encrypted fields automatically and decrypts them, returning the
482
+ * model with plaintext values. Returns a thenable operation that supports
483
+ * `.withLockContext()` for identity-aware decryption.
484
+ *
485
+ * @param input - The model object with encrypted field values.
486
+ * @returns A `DecryptModelOperation<T>` that can be awaited to get a `Result`
487
+ * containing the model with decrypted plaintext fields, or an `EncryptionError`.
488
+ *
489
+ * @example
490
+ * ```typescript
491
+ * // Decrypt a previously encrypted model
492
+ * const decrypted = await client.decryptModel<User>(encryptedUser)
493
+ *
494
+ * if (decrypted.failure) {
495
+ * console.error(decrypted.failure.message)
496
+ * } else {
497
+ * console.log(decrypted.data.email) // "alice@example.com"
498
+ * }
499
+ *
500
+ * // With a lock context
501
+ * const decrypted = await client
502
+ * .decryptModel<User>(encryptedUser)
503
+ * .withLockContext(lockContext)
504
+ * ```
505
+ */
506
+ decryptModel<T extends Record<string, unknown>>(input: T): DecryptModelOperation<T>;
507
+ /**
508
+ * Encrypt multiple models (objects) in a single bulk operation.
509
+ *
510
+ * Performs a single call to ZeroKMS regardless of the number of models,
511
+ * while still using a unique key for each encrypted value. Only fields
512
+ * matching the table schema are encrypted; other fields pass through unchanged.
513
+ *
514
+ * The return type is **schema-aware**: fields matching the table schema are
515
+ * typed as `Encrypted`, while other fields retain their original types. For
516
+ * best results, let TypeScript infer the type parameters from the arguments.
517
+ *
518
+ * @param input - An array of model objects with plaintext values to encrypt.
519
+ * @param table - The table schema defining which fields to encrypt.
520
+ * @returns A `BulkEncryptModelsOperation` that can be awaited to get a `Result`
521
+ * containing an array of models with schema-defined fields typed as `Encrypted`,
522
+ * or an `EncryptionError`.
523
+ *
524
+ * @example
525
+ * ```typescript
526
+ * import { Encryption } from "@cipherstash/stack"
527
+ * import { encryptedTable, encryptedColumn } from "@cipherstash/stack/schema"
528
+ *
529
+ * type User = { id: string; email: string }
530
+ *
531
+ * const usersSchema = encryptedTable("users", {
532
+ * email: encryptedColumn("email"),
533
+ * })
534
+ *
535
+ * const client = await Encryption({ schemas: [usersSchema] })
536
+ *
537
+ * // Let TypeScript infer the return type from the schema.
538
+ * // Each item's email is typed as `Encrypted`, id stays `string`.
539
+ * const result = await client.bulkEncryptModels(
540
+ * [
541
+ * { id: "1", email: "alice@example.com" },
542
+ * { id: "2", email: "bob@example.com" },
543
+ * ],
544
+ * usersSchema,
545
+ * )
546
+ *
547
+ * if (!result.failure) {
548
+ * console.log(result.data) // array of models with encrypted email fields
549
+ * }
550
+ * ```
551
+ */
552
+ bulkEncryptModels<T extends Record<string, unknown>, Table extends BuildableTable>(input: Array<T>, table: Table): BulkEncryptModelsOperation<EncryptedFromBuildableTable<T, Table>>;
553
+ /**
554
+ * Decrypt multiple models (objects) in a single bulk operation.
555
+ *
556
+ * Performs a single call to ZeroKMS regardless of the number of models,
557
+ * restoring all encrypted fields to their original plaintext values.
558
+ *
559
+ * @param input - An array of model objects with encrypted field values.
560
+ * @returns A `BulkDecryptModelsOperation<T>` that can be awaited to get a `Result`
561
+ * containing an array of models with decrypted plaintext fields, or an `EncryptionError`.
562
+ *
563
+ * @example
564
+ * ```typescript
565
+ * const encryptedUsers = encryptedResult.data // from bulkEncryptModels
566
+ *
567
+ * const result = await client.bulkDecryptModels<User>(encryptedUsers)
568
+ *
569
+ * if (!result.failure) {
570
+ * for (const user of result.data) {
571
+ * console.log(user.email) // plaintext email
572
+ * }
573
+ * }
574
+ *
575
+ * // With a lock context
576
+ * const result = await client
577
+ * .bulkDecryptModels<User>(encryptedUsers)
578
+ * .withLockContext(lockContext)
579
+ * ```
580
+ */
581
+ bulkDecryptModels<T extends Record<string, unknown>>(input: Array<T>): BulkDecryptModelsOperation<T>;
582
+ /**
583
+ * Encrypt multiple plaintext values in a single bulk operation.
584
+ *
585
+ * Each value is encrypted with its own unique key via a single call to ZeroKMS.
586
+ * Values can include optional `id` fields for correlating results back to
587
+ * your application data.
588
+ *
589
+ * @param plaintexts - An array of objects with `plaintext` (and optional `id`) fields.
590
+ * @param opts - Options specifying the target column (or nested {@link encryptedField}) and table. See {@link EncryptOptions}.
591
+ * @returns A `BulkEncryptOperation` that can be awaited to get a `Result`
592
+ * containing an array of `{ id?, data: Encrypted }` objects, or an `EncryptionError`.
593
+ *
594
+ * @example
595
+ * ```typescript
596
+ * import { Encryption } from "@cipherstash/stack"
597
+ * import { encryptedTable, encryptedColumn } from "@cipherstash/stack/schema"
598
+ *
599
+ * const users = encryptedTable("users", {
600
+ * email: encryptedColumn("email"),
601
+ * })
602
+ * const client = await Encryption({ schemas: [users] })
603
+ *
604
+ * const result = await client.bulkEncrypt(
605
+ * [
606
+ * { id: "u1", plaintext: "alice@example.com" },
607
+ * { id: "u2", plaintext: "bob@example.com" },
608
+ * ],
609
+ * { column: users.email, table: users },
610
+ * )
611
+ *
612
+ * if (!result.failure) {
613
+ * // result.data = [{ id: "u1", data: Encrypted }, { id: "u2", data: Encrypted }, ...]
614
+ * console.log(result.data)
615
+ * }
616
+ * ```
617
+ */
618
+ bulkEncrypt(plaintexts: BulkEncryptPayload, opts: EncryptOptions): BulkEncryptOperation;
619
+ /**
620
+ * Decrypt multiple encrypted values in a single bulk operation.
621
+ *
622
+ * Performs a single call to ZeroKMS to decrypt all values. The result uses
623
+ * a multi-status pattern: each item in the returned array has either a `data`
624
+ * field (success) or an `error` field (failure), allowing graceful handling
625
+ * of partial failures.
626
+ *
627
+ * @param encryptedPayloads - An array of objects with `data` (encrypted payload) and optional `id` fields.
628
+ * @returns A `BulkDecryptOperation` that can be awaited to get a `Result`
629
+ * containing an array of `{ id?, data: plaintext }` or `{ id?, error: string }` objects,
630
+ * or an `EncryptionError` if the entire operation fails.
631
+ *
632
+ * @example
633
+ * ```typescript
634
+ * const encrypted = await client.bulkEncrypt(plaintexts, { column: users.email, table: users })
635
+ *
636
+ * const result = await client.bulkDecrypt(encrypted.data)
637
+ *
638
+ * if (!result.failure) {
639
+ * for (const item of result.data) {
640
+ * if ("data" in item) {
641
+ * console.log(`${item.id}: ${item.data}`)
642
+ * } else {
643
+ * console.error(`${item.id} failed: ${item.error}`)
644
+ * }
645
+ * }
646
+ * }
647
+ * ```
648
+ */
649
+ bulkDecrypt(encryptedPayloads: BulkDecryptPayload): BulkDecryptOperation;
650
+ /**
651
+ * Get the encrypt config object.
652
+ *
653
+ * @returns The encrypt config object.
654
+ */
655
+ getEncryptConfig(): EncryptConfig | undefined;
656
+ }
657
+ /**
658
+ * Reset the once-per-process deprecation-warning latch. Test-only hook so
659
+ * suites can assert the warning fires deterministically, independent of test
660
+ * ordering. Not re-exported from the package entry, so it stays off the public
661
+ * API surface.
662
+ * @internal
663
+ */
664
+ declare function __resetStrategyDeprecationWarningForTests(): void;
665
+ /**
666
+ * Creates and initializes an Encryption client for encrypting and decrypting data with CipherStash.
667
+ *
668
+ * Provide at least one schema (from {@link encryptedTable}) so the client knows which tables and
669
+ * columns to use:
670
+ *
671
+ * ```typescript
672
+ * import { Encryption, encryptedTable, encryptedColumn } from "@cipherstash/stack"
673
+ *
674
+ * const users = encryptedTable("users", { email: encryptedColumn("email") })
675
+ * const client = await Encryption({ schemas: [users] })
676
+ * const result = await client.encrypt("alice@example.com", { column: users.email, table: users })
677
+ * ```
678
+ *
679
+ * ## Authentication
680
+ *
681
+ * The snippets in this section reuse the `users` schema from the example above, and
682
+ * `workspaceCrn` / `accessKey` stand in for your own workspace credentials (from the
683
+ * [dashboard](https://dashboard.cipherstash.com) or the `CS_*` variables below).
684
+ *
685
+ * By default the client uses the `auto` auth strategy. `auto` first looks for the `CS_*`
686
+ * environment variables (see below) and, if they are not set, falls back to the local **dev
687
+ * profile** on your machine. The dev profile also supplies the client key, so during local
688
+ * development you generally don't need to set any environment variables at all.
689
+ *
690
+ * ### Local development — create a dev profile
691
+ *
692
+ * Log in once to create the dev profile that `auto` picks up automatically:
693
+ *
694
+ * ```bash
695
+ * npx stash auth login
696
+ * ```
697
+ *
698
+ * ### Production / CI — environment variables
699
+ *
700
+ * In production and CI you typically authenticate with the four `CS_*` environment variables
701
+ * instead of a dev profile. Developers can obtain these values from the
702
+ * [CipherStash dashboard](https://dashboard.cipherstash.com):
703
+ *
704
+ * | Environment variable | Description |
705
+ * | ---------------------- | ------------------------------------------------------------------------------ |
706
+ * | `CS_WORKSPACE_CRN` | The workspace Cloud Resource Name (CRN) that identifies your workspace. |
707
+ * | `CS_CLIENT_ID` | The client identifier issued when you create an access key. |
708
+ * | `CS_CLIENT_KEY` | The client key material combined with ZeroKMS to perform encryption. |
709
+ * | `CS_CLIENT_ACCESS_KEY` | The API access key used to authenticate requests to CipherStash. |
710
+ *
711
+ * When these are set, `auto` uses them in preference to the local dev profile.
712
+ *
713
+ * ### Custom auth strategies — `config.authStrategy`
714
+ *
715
+ * For finer control, pass an explicit strategy via `config.authStrategy` (from `@cipherstash/auth`,
716
+ * re-exported by `@cipherstash/stack`). See the `@cipherstash/auth` package for the full list. Two
717
+ * common choices:
718
+ *
719
+ * `AccessKeyStrategy` — like `auto`, but only ever uses an access key; it never falls back to the
720
+ * local dev profile. Ideal for services and CI:
721
+ *
722
+ * ```typescript
723
+ * import { Encryption, AccessKeyStrategy } from "@cipherstash/stack"
724
+ *
725
+ * const client = await Encryption({
726
+ * schemas: [users],
727
+ * config: {
728
+ * authStrategy: AccessKeyStrategy.create(workspaceCrn, accessKey),
729
+ * },
730
+ * })
731
+ * ```
732
+ *
733
+ * `OidcFederationStrategy` — authenticate end users through your own identity provider (Supabase,
734
+ * Clerk, Auth0 or Okta) by federating their OIDC JWT into a CipherStash token. Add the provider to
735
+ * your workspace first at
736
+ * [dashboard.cipherstash.com/workspaces/_/oidc-providers](https://dashboard.cipherstash.com/workspaces/_/oidc-providers)
737
+ * (the `_` in the URL resolves to whichever workspace you select):
738
+ *
739
+ * ```typescript
740
+ * import { Encryption, OidcFederationStrategy } from "@cipherstash/stack"
741
+ *
742
+ * // Authenticate every ZeroKMS request as the signed-in user.
743
+ * const client = await Encryption({
744
+ * schemas: [users],
745
+ * config: {
746
+ * authStrategy: OidcFederationStrategy.create(workspaceCrn, () => getUserJwt()),
747
+ * },
748
+ * })
749
+ * ```
750
+ *
751
+ * ### Lock context (identity-bound encryption)
752
+ *
753
+ * Lock context is an **additional** capability layered on top of `OidcFederationStrategy`: it
754
+ * requires that strategy, but `OidcFederationStrategy` does not require lock context. It binds a
755
+ * value to a claim from the user's JWT (typically `sub`) so that only the user who encrypted a
756
+ * value can decrypt it:
757
+ *
758
+ * ```typescript
759
+ * // Bind the data key to the user's `sub` claim.
760
+ * const result = await client
761
+ * .encrypt("alice@example.com", { column: users.email, table: users })
762
+ * .withLockContext({ identityClaim: ["sub"] })
763
+ * ```
764
+ *
765
+ * Because the lock is tied to a specific end user's identity, `AccessKeyStrategy` (which
766
+ * authenticates a service, not a user) is not valid for lock context — there is no user `sub`
767
+ * claim to bind to.
768
+ *
769
+ * ## Keysets (multi-tenant isolation)
770
+ *
771
+ * Pass `config.keyset` to encrypt under a specific **keyset** — a named or UUID-identified keyspace
772
+ * that gives each tenant its own cryptographic isolation, so data encrypted under one keyset cannot
773
+ * be decrypted under another. Create and manage keysets in the
774
+ * [dashboard](https://dashboard.cipherstash.com/workspaces/_/keysets) (the `_` in the URL resolves
775
+ * to whichever workspace you select); omit `config.keyset` to use the workspace's default keyset.
776
+ *
777
+ * ```typescript
778
+ * // `users` is the schema from the first example above.
779
+ * const client = await Encryption({
780
+ * schemas: [users],
781
+ * config: {
782
+ * keyset: { name: "tenant-a" }, // or { id: "<uuid>" }
783
+ * },
784
+ * })
785
+ * ```
786
+ *
787
+ * A client is bound to a single keyset for its lifetime, so multi-tenant applications use **one
788
+ * `Encryption()` client per tenant**. Keysets are orthogonal to `authStrategy` and lock context —
789
+ * they isolate a whole tenant's *keyspace* (coarse, fixed per client), whereas lock context binds
790
+ * an individual value to a user's identity claim (fine-grained, per operation) — and can be
791
+ * combined with both.
792
+ *
793
+ * @param config - Initialization options. Must include `schemas`; optionally include `config` for
794
+ * credentials and authentication. Logging is configured via the `STASH_STACK_LOG` environment
795
+ * variable (`debug | info | error`, default: `error`).
796
+ * @returns A Promise that resolves to an initialized {@link EncryptionClient} ready for
797
+ * {@link EncryptionClient.encrypt}, {@link EncryptionClient.decrypt}, and related operations.
798
+ *
799
+ * @throws Throws if `schemas` is empty, or if a keyset `id` is supplied but is not a valid UUID.
800
+ * Also throws if the client fails to initialize (e.g. invalid credentials or config).
801
+ *
802
+ * @see {@link EncryptionClientConfig} for full config options.
803
+ * @see {@link ClientConfig.authStrategy} for the auth strategy field.
804
+ * @see {@link EncryptionClient} for available methods after initialization.
805
+ */
806
+ declare const Encryption: (config: EncryptionClientConfig) => Promise<EncryptionClient>;
807
+
808
+ export { BatchEncryptQueryOperation, BulkDecryptModelsOperation, BulkDecryptOperation, BulkEncryptModelsOperation, BulkEncryptOperation, DecryptModelOperation, DecryptOperation, EncryptModelOperation, EncryptOperation, EncryptQueryOperation, Encryption, EncryptionClient, __resetStrategyDeprecationWarningForTests, noClientError, resolveEqlVersion };