@cipherstash/stack 0.2.0 → 0.4.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 +12 -0
- package/README.md +2 -3
- package/dist/bin/stash.js +109 -186
- package/dist/bin/stash.js.map +1 -1
- package/dist/{chunk-SUYMGQBY.js → chunk-4RNBI3UH.js} +1 -7
- package/dist/chunk-4RNBI3UH.js.map +1 -0
- package/dist/{chunk-5G4F4JJG.js → chunk-KOU2MHXJ.js} +1 -1
- package/dist/chunk-KOU2MHXJ.js.map +1 -0
- package/dist/{chunk-5DCT6YU2.js → chunk-OAPLZLR5.js} +7 -3
- package/dist/{chunk-5DCT6YU2.js.map → chunk-OAPLZLR5.js.map} +1 -1
- package/dist/{chunk-LHZ6KZIG.js → chunk-WUZGKTMG.js} +84 -162
- package/dist/chunk-WUZGKTMG.js.map +1 -0
- package/dist/{chunk-7XRPN2KX.js → chunk-Y35W4WFN.js} +31 -28
- package/dist/chunk-Y35W4WFN.js.map +1 -0
- package/dist/{client-D-ZH8SB2.d.cts → client-CUGXheRq.d.cts} +33 -31
- package/dist/{client-BV9pXC-d.d.ts → client-CrGQnSlk.d.ts} +33 -31
- package/dist/client.cjs +30 -27
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +2 -2
- package/dist/client.d.ts +2 -2
- package/dist/client.js +5 -5
- package/dist/drizzle/index.cjs +24 -21
- package/dist/drizzle/index.cjs.map +1 -1
- package/dist/drizzle/index.d.cts +5 -5
- package/dist/drizzle/index.d.ts +5 -5
- package/dist/drizzle/index.js +2 -2
- package/dist/drizzle/index.js.map +1 -1
- package/dist/dynamodb/index.cjs.map +1 -1
- package/dist/dynamodb/index.d.cts +10 -10
- package/dist/dynamodb/index.d.ts +10 -10
- package/dist/dynamodb/index.js.map +1 -1
- package/dist/identity/index.cjs +6 -2
- package/dist/identity/index.cjs.map +1 -1
- package/dist/identity/index.js +1 -1
- package/dist/index.cjs +113 -190
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +8 -8
- package/dist/schema/index.cjs +36 -33
- package/dist/schema/index.cjs.map +1 -1
- package/dist/schema/index.d.cts +1 -1
- package/dist/schema/index.d.ts +1 -1
- package/dist/schema/index.js +11 -11
- package/dist/secrets/index.cjs +109 -186
- package/dist/secrets/index.cjs.map +1 -1
- package/dist/secrets/index.d.cts +1 -1
- package/dist/secrets/index.d.ts +1 -1
- package/dist/secrets/index.js +5 -5
- package/dist/secrets/index.js.map +1 -1
- package/dist/supabase/index.cjs +9 -9
- package/dist/supabase/index.cjs.map +1 -1
- package/dist/supabase/index.d.cts +3 -3
- package/dist/supabase/index.d.ts +3 -3
- package/dist/supabase/index.js +4 -4
- package/dist/supabase/index.js.map +1 -1
- package/dist/{types-public-Dfg-hkuQ.d.cts → types-public-Wj6tB_ux.d.cts} +115 -76
- package/dist/{types-public-Dfg-hkuQ.d.ts → types-public-Wj6tB_ux.d.ts} +115 -76
- package/dist/types-public.cjs.map +1 -1
- package/dist/types-public.d.cts +1 -1
- package/dist/types-public.d.ts +1 -1
- package/dist/types-public.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-5G4F4JJG.js.map +0 -1
- package/dist/chunk-7XRPN2KX.js.map +0 -1
- package/dist/chunk-LHZ6KZIG.js.map +0 -1
- package/dist/chunk-SUYMGQBY.js.map +0 -1
|
@@ -2,33 +2,33 @@ import {
|
|
|
2
2
|
formatEncryptedResult,
|
|
3
3
|
isEncryptedPayload,
|
|
4
4
|
toFfiKeysetIdentifier
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-4RNBI3UH.js";
|
|
6
6
|
import {
|
|
7
7
|
queryTypeToFfi,
|
|
8
8
|
queryTypeToQueryOp
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-KOU2MHXJ.js";
|
|
10
10
|
import {
|
|
11
11
|
EncryptionErrorTypes,
|
|
12
12
|
createRequestLogger,
|
|
13
13
|
initStackLogger,
|
|
14
14
|
loadWorkSpaceId,
|
|
15
15
|
logger
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-OAPLZLR5.js";
|
|
17
17
|
import {
|
|
18
18
|
buildEncryptConfig,
|
|
19
19
|
encryptConfigSchema
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-Y35W4WFN.js";
|
|
21
21
|
|
|
22
|
-
// src/encryption/
|
|
22
|
+
// src/encryption/index.ts
|
|
23
23
|
import { withResult as withResult11 } from "@byteslice/result";
|
|
24
24
|
import { newClient } from "@cipherstash/protect-ffi";
|
|
25
25
|
|
|
26
|
-
// src/encryption/
|
|
26
|
+
// src/encryption/helpers/type-guards.ts
|
|
27
27
|
function isScalarQueryTermArray(value) {
|
|
28
28
|
return Array.isArray(value) && value.length > 0 && typeof value[0] === "object" && value[0] !== null && "column" in value[0] && "table" in value[0];
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
// src/encryption/
|
|
31
|
+
// src/encryption/helpers/error-code.ts
|
|
32
32
|
import {
|
|
33
33
|
ProtectError as FfiProtectError
|
|
34
34
|
} from "@cipherstash/protect-ffi";
|
|
@@ -36,13 +36,13 @@ function getErrorCode(error) {
|
|
|
36
36
|
return error instanceof FfiProtectError ? error.code : void 0;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
// src/encryption/
|
|
39
|
+
// src/encryption/operations/batch-encrypt-query.ts
|
|
40
40
|
import { withResult } from "@byteslice/result";
|
|
41
41
|
import {
|
|
42
42
|
encryptQueryBulk as ffiEncryptQueryBulk
|
|
43
43
|
} from "@cipherstash/protect-ffi";
|
|
44
44
|
|
|
45
|
-
// src/encryption/
|
|
45
|
+
// src/encryption/helpers/infer-index-type.ts
|
|
46
46
|
function inferIndexType(column) {
|
|
47
47
|
const config = column.build();
|
|
48
48
|
const indexes = config.indexes;
|
|
@@ -102,7 +102,7 @@ function resolveIndexType(column, queryType, plaintext) {
|
|
|
102
102
|
return { indexType };
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
// src/encryption/
|
|
105
|
+
// src/encryption/helpers/validation.ts
|
|
106
106
|
function validateNumericValue(value) {
|
|
107
107
|
if (typeof value === "number" && Number.isNaN(value)) {
|
|
108
108
|
return {
|
|
@@ -138,7 +138,7 @@ function assertValueIndexCompatibility(value, indexType, columnName) {
|
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
// src/encryption/
|
|
141
|
+
// src/encryption/operations/base-operation.ts
|
|
142
142
|
var EncryptionOperation = class {
|
|
143
143
|
auditMetadata;
|
|
144
144
|
/**
|
|
@@ -166,19 +166,7 @@ var EncryptionOperation = class {
|
|
|
166
166
|
}
|
|
167
167
|
};
|
|
168
168
|
|
|
169
|
-
// src/encryption/
|
|
170
|
-
function filterNullTerms(terms) {
|
|
171
|
-
const nullIndices = /* @__PURE__ */ new Set();
|
|
172
|
-
const nonNullTerms = [];
|
|
173
|
-
terms.forEach((term, index) => {
|
|
174
|
-
if (term.value === null || term.value === void 0) {
|
|
175
|
-
nullIndices.add(index);
|
|
176
|
-
} else {
|
|
177
|
-
nonNullTerms.push({ term, originalIndex: index });
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
return { nullIndices, nonNullTerms };
|
|
181
|
-
}
|
|
169
|
+
// src/encryption/operations/batch-encrypt-query.ts
|
|
182
170
|
function buildQueryPayload(term, lockContext) {
|
|
183
171
|
assertValidNumericValue(term.value);
|
|
184
172
|
const { indexType, queryOp } = resolveIndexType(
|
|
@@ -199,13 +187,10 @@ function buildQueryPayload(term, lockContext) {
|
|
|
199
187
|
}
|
|
200
188
|
return payload;
|
|
201
189
|
}
|
|
202
|
-
function assembleResults(
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
results[originalIndex] = formatEncryptedResult(encrypted, term.returnType);
|
|
207
|
-
});
|
|
208
|
-
return results;
|
|
190
|
+
function assembleResults(terms, encryptedValues) {
|
|
191
|
+
return terms.map(
|
|
192
|
+
(term, i) => formatEncryptedResult(encryptedValues[i], term.returnType)
|
|
193
|
+
);
|
|
209
194
|
}
|
|
210
195
|
var BatchEncryptQueryOperation = class extends EncryptionOperation {
|
|
211
196
|
constructor(client, terms) {
|
|
@@ -232,23 +217,18 @@ var BatchEncryptQueryOperation = class extends EncryptionOperation {
|
|
|
232
217
|
log.emit();
|
|
233
218
|
return { data: [] };
|
|
234
219
|
}
|
|
235
|
-
const { nullIndices, nonNullTerms } = filterNullTerms(this.terms);
|
|
236
|
-
if (nonNullTerms.length === 0) {
|
|
237
|
-
log.emit();
|
|
238
|
-
return { data: this.terms.map(() => null) };
|
|
239
|
-
}
|
|
240
220
|
const result = await withResult(
|
|
241
221
|
async () => {
|
|
242
222
|
if (!this.client) throw noClientError();
|
|
243
223
|
const { metadata } = this.getAuditData();
|
|
244
|
-
const queries =
|
|
245
|
-
(
|
|
224
|
+
const queries = this.terms.map(
|
|
225
|
+
(term) => buildQueryPayload(term)
|
|
246
226
|
);
|
|
247
227
|
const encrypted = await ffiEncryptQueryBulk(this.client, {
|
|
248
228
|
queries,
|
|
249
229
|
unverifiedContext: metadata
|
|
250
230
|
});
|
|
251
|
-
return assembleResults(this.terms
|
|
231
|
+
return assembleResults(this.terms, encrypted);
|
|
252
232
|
},
|
|
253
233
|
(error) => {
|
|
254
234
|
log.set({ errorCode: getErrorCode(error) ?? "unknown" });
|
|
@@ -282,11 +262,6 @@ var BatchEncryptQueryOperationWithLockContext = class extends EncryptionOperatio
|
|
|
282
262
|
log.emit();
|
|
283
263
|
return { data: [] };
|
|
284
264
|
}
|
|
285
|
-
const { nullIndices, nonNullTerms } = filterNullTerms(this.terms);
|
|
286
|
-
if (nonNullTerms.length === 0) {
|
|
287
|
-
log.emit();
|
|
288
|
-
return { data: this.terms.map(() => null) };
|
|
289
|
-
}
|
|
290
265
|
const lockContextResult = await this.lockContext.getLockContext();
|
|
291
266
|
if (lockContextResult.failure) {
|
|
292
267
|
log.emit();
|
|
@@ -297,15 +272,15 @@ var BatchEncryptQueryOperationWithLockContext = class extends EncryptionOperatio
|
|
|
297
272
|
async () => {
|
|
298
273
|
if (!this.client) throw noClientError();
|
|
299
274
|
const { metadata } = this.getAuditData();
|
|
300
|
-
const queries =
|
|
301
|
-
(
|
|
275
|
+
const queries = this.terms.map(
|
|
276
|
+
(term) => buildQueryPayload(term, context)
|
|
302
277
|
);
|
|
303
278
|
const encrypted = await ffiEncryptQueryBulk(this.client, {
|
|
304
279
|
queries,
|
|
305
280
|
serviceToken: ctsToken,
|
|
306
281
|
unverifiedContext: metadata
|
|
307
282
|
});
|
|
308
|
-
return assembleResults(this.terms
|
|
283
|
+
return assembleResults(this.terms, encrypted);
|
|
309
284
|
},
|
|
310
285
|
(error) => {
|
|
311
286
|
log.set({ errorCode: getErrorCode(error) ?? "unknown" });
|
|
@@ -321,48 +296,31 @@ var BatchEncryptQueryOperationWithLockContext = class extends EncryptionOperatio
|
|
|
321
296
|
}
|
|
322
297
|
};
|
|
323
298
|
|
|
324
|
-
// src/encryption/
|
|
299
|
+
// src/encryption/operations/bulk-decrypt.ts
|
|
325
300
|
import { withResult as withResult2 } from "@byteslice/result";
|
|
326
301
|
import {
|
|
327
302
|
decryptBulkFallible
|
|
328
303
|
} from "@cipherstash/protect-ffi";
|
|
329
304
|
var createDecryptPayloads = (encryptedPayloads, lockContext) => {
|
|
330
|
-
return encryptedPayloads.map((
|
|
305
|
+
return encryptedPayloads.map(({ id, data }) => ({
|
|
331
306
|
id,
|
|
332
307
|
ciphertext: data,
|
|
333
|
-
originalIndex,
|
|
334
308
|
...lockContext && { lockContext }
|
|
335
309
|
}));
|
|
336
310
|
};
|
|
337
|
-
var createNullResult = (encryptedPayloads) => {
|
|
338
|
-
return encryptedPayloads.map(({ id }) => ({
|
|
339
|
-
id,
|
|
340
|
-
data: null
|
|
341
|
-
}));
|
|
342
|
-
};
|
|
343
311
|
var mapDecryptedDataToResult = (encryptedPayloads, decryptedData) => {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
const decryptResult = decryptedData[decryptedIndex];
|
|
351
|
-
if ("error" in decryptResult) {
|
|
352
|
-
result[i] = {
|
|
353
|
-
id: encryptedPayloads[i].id,
|
|
354
|
-
error: decryptResult.error
|
|
355
|
-
};
|
|
356
|
-
} else {
|
|
357
|
-
result[i] = {
|
|
358
|
-
id: encryptedPayloads[i].id,
|
|
359
|
-
data: decryptResult.data
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
|
-
decryptedIndex++;
|
|
312
|
+
return decryptedData.map((decryptResult, i) => {
|
|
313
|
+
if ("error" in decryptResult) {
|
|
314
|
+
return {
|
|
315
|
+
id: encryptedPayloads[i].id,
|
|
316
|
+
error: decryptResult.error
|
|
317
|
+
};
|
|
363
318
|
}
|
|
364
|
-
|
|
365
|
-
|
|
319
|
+
return {
|
|
320
|
+
id: encryptedPayloads[i].id,
|
|
321
|
+
data: decryptResult.data
|
|
322
|
+
};
|
|
323
|
+
});
|
|
366
324
|
};
|
|
367
325
|
var BulkDecryptOperation = class extends EncryptionOperation {
|
|
368
326
|
client;
|
|
@@ -387,13 +345,10 @@ var BulkDecryptOperation = class extends EncryptionOperation {
|
|
|
387
345
|
if (!this.client) throw noClientError();
|
|
388
346
|
if (!this.encryptedPayloads || this.encryptedPayloads.length === 0)
|
|
389
347
|
return [];
|
|
390
|
-
const
|
|
391
|
-
if (nonNullPayloads.length === 0) {
|
|
392
|
-
return createNullResult(this.encryptedPayloads);
|
|
393
|
-
}
|
|
348
|
+
const payloads = createDecryptPayloads(this.encryptedPayloads);
|
|
394
349
|
const { metadata } = this.getAuditData();
|
|
395
350
|
const decryptedData = await decryptBulkFallible(this.client, {
|
|
396
|
-
ciphertexts:
|
|
351
|
+
ciphertexts: payloads,
|
|
397
352
|
unverifiedContext: metadata
|
|
398
353
|
});
|
|
399
354
|
return mapDecryptedDataToResult(this.encryptedPayloads, decryptedData);
|
|
@@ -445,16 +400,13 @@ var BulkDecryptOperationWithLockContext = class extends EncryptionOperation {
|
|
|
445
400
|
if (context.failure) {
|
|
446
401
|
throw new Error(`[encryption]: ${context.failure.message}`);
|
|
447
402
|
}
|
|
448
|
-
const
|
|
403
|
+
const payloads = createDecryptPayloads(
|
|
449
404
|
encryptedPayloads,
|
|
450
405
|
context.data.context
|
|
451
406
|
);
|
|
452
|
-
if (nonNullPayloads.length === 0) {
|
|
453
|
-
return createNullResult(encryptedPayloads);
|
|
454
|
-
}
|
|
455
407
|
const { metadata } = this.getAuditData();
|
|
456
408
|
const decryptedData = await decryptBulkFallible(client, {
|
|
457
|
-
ciphertexts:
|
|
409
|
+
ciphertexts: payloads,
|
|
458
410
|
serviceToken: context.data.ctsToken,
|
|
459
411
|
unverifiedContext: metadata
|
|
460
412
|
});
|
|
@@ -474,10 +426,10 @@ var BulkDecryptOperationWithLockContext = class extends EncryptionOperation {
|
|
|
474
426
|
}
|
|
475
427
|
};
|
|
476
428
|
|
|
477
|
-
// src/encryption/
|
|
429
|
+
// src/encryption/operations/bulk-decrypt-models.ts
|
|
478
430
|
import { withResult as withResult3 } from "@byteslice/result";
|
|
479
431
|
|
|
480
|
-
// src/encryption/
|
|
432
|
+
// src/encryption/helpers/model-helpers.ts
|
|
481
433
|
import {
|
|
482
434
|
decryptBulk,
|
|
483
435
|
encryptBulk
|
|
@@ -995,7 +947,7 @@ async function bulkEncryptModelsWithLockContext(models, table, client, lockConte
|
|
|
995
947
|
});
|
|
996
948
|
}
|
|
997
949
|
|
|
998
|
-
// src/encryption/
|
|
950
|
+
// src/encryption/operations/bulk-decrypt-models.ts
|
|
999
951
|
var BulkDecryptModelsOperation = class extends EncryptionOperation {
|
|
1000
952
|
client;
|
|
1001
953
|
models;
|
|
@@ -1092,38 +1044,18 @@ var BulkDecryptModelsOperationWithLockContext = class extends EncryptionOperatio
|
|
|
1092
1044
|
}
|
|
1093
1045
|
};
|
|
1094
1046
|
|
|
1095
|
-
// src/encryption/
|
|
1047
|
+
// src/encryption/operations/bulk-encrypt.ts
|
|
1096
1048
|
import { withResult as withResult4 } from "@byteslice/result";
|
|
1097
1049
|
import { encryptBulk as encryptBulk2 } from "@cipherstash/protect-ffi";
|
|
1098
1050
|
var createEncryptPayloads = (plaintexts, column, table, lockContext) => {
|
|
1099
|
-
return plaintexts.map((
|
|
1051
|
+
return plaintexts.map(({ id, plaintext }) => ({
|
|
1100
1052
|
id,
|
|
1101
1053
|
plaintext,
|
|
1102
1054
|
column: column.getName(),
|
|
1103
1055
|
table: table.tableName,
|
|
1104
|
-
originalIndex,
|
|
1105
1056
|
...lockContext && { lockContext }
|
|
1106
1057
|
}));
|
|
1107
1058
|
};
|
|
1108
|
-
var createNullResult2 = (plaintexts) => {
|
|
1109
|
-
return plaintexts.map(({ id }) => ({ id, data: null }));
|
|
1110
|
-
};
|
|
1111
|
-
var mapEncryptedDataToResult = (plaintexts, encryptedData) => {
|
|
1112
|
-
const result = new Array(plaintexts.length);
|
|
1113
|
-
let encryptedIndex = 0;
|
|
1114
|
-
for (let i = 0; i < plaintexts.length; i++) {
|
|
1115
|
-
if (plaintexts[i].plaintext === null) {
|
|
1116
|
-
result[i] = { id: plaintexts[i].id, data: null };
|
|
1117
|
-
} else {
|
|
1118
|
-
result[i] = {
|
|
1119
|
-
id: plaintexts[i].id,
|
|
1120
|
-
data: encryptedData[encryptedIndex]
|
|
1121
|
-
};
|
|
1122
|
-
encryptedIndex++;
|
|
1123
|
-
}
|
|
1124
|
-
}
|
|
1125
|
-
return result;
|
|
1126
|
-
};
|
|
1127
1059
|
var BulkEncryptOperation = class extends EncryptionOperation {
|
|
1128
1060
|
client;
|
|
1129
1061
|
plaintexts;
|
|
@@ -1156,20 +1088,20 @@ var BulkEncryptOperation = class extends EncryptionOperation {
|
|
|
1156
1088
|
if (!this.plaintexts || this.plaintexts.length === 0) {
|
|
1157
1089
|
return [];
|
|
1158
1090
|
}
|
|
1159
|
-
const
|
|
1091
|
+
const payloads = createEncryptPayloads(
|
|
1160
1092
|
this.plaintexts,
|
|
1161
1093
|
this.column,
|
|
1162
1094
|
this.table
|
|
1163
1095
|
);
|
|
1164
|
-
if (nonNullPayloads.length === 0) {
|
|
1165
|
-
return createNullResult2(this.plaintexts);
|
|
1166
|
-
}
|
|
1167
1096
|
const { metadata } = this.getAuditData();
|
|
1168
1097
|
const encryptedData = await encryptBulk2(this.client, {
|
|
1169
|
-
plaintexts:
|
|
1098
|
+
plaintexts: payloads,
|
|
1170
1099
|
unverifiedContext: metadata
|
|
1171
1100
|
});
|
|
1172
|
-
return
|
|
1101
|
+
return encryptedData.map((data, i) => ({
|
|
1102
|
+
id: this.plaintexts[i].id,
|
|
1103
|
+
data
|
|
1104
|
+
}));
|
|
1173
1105
|
},
|
|
1174
1106
|
(error) => {
|
|
1175
1107
|
log.set({ errorCode: getErrorCode(error) ?? "unknown" });
|
|
@@ -1226,22 +1158,22 @@ var BulkEncryptOperationWithLockContext = class extends EncryptionOperation {
|
|
|
1226
1158
|
if (context.failure) {
|
|
1227
1159
|
throw new Error(`[encryption]: ${context.failure.message}`);
|
|
1228
1160
|
}
|
|
1229
|
-
const
|
|
1161
|
+
const payloads = createEncryptPayloads(
|
|
1230
1162
|
plaintexts,
|
|
1231
1163
|
column,
|
|
1232
1164
|
table,
|
|
1233
1165
|
context.data.context
|
|
1234
1166
|
);
|
|
1235
|
-
if (nonNullPayloads.length === 0) {
|
|
1236
|
-
return createNullResult2(plaintexts);
|
|
1237
|
-
}
|
|
1238
1167
|
const { metadata } = this.getAuditData();
|
|
1239
1168
|
const encryptedData = await encryptBulk2(client, {
|
|
1240
|
-
plaintexts:
|
|
1169
|
+
plaintexts: payloads,
|
|
1241
1170
|
serviceToken: context.data.ctsToken,
|
|
1242
1171
|
unverifiedContext: metadata
|
|
1243
1172
|
});
|
|
1244
|
-
return
|
|
1173
|
+
return encryptedData.map((data, i) => ({
|
|
1174
|
+
id: plaintexts[i].id,
|
|
1175
|
+
data
|
|
1176
|
+
}));
|
|
1245
1177
|
},
|
|
1246
1178
|
(error) => {
|
|
1247
1179
|
log.set({ errorCode: getErrorCode(error) ?? "unknown" });
|
|
@@ -1257,7 +1189,7 @@ var BulkEncryptOperationWithLockContext = class extends EncryptionOperation {
|
|
|
1257
1189
|
}
|
|
1258
1190
|
};
|
|
1259
1191
|
|
|
1260
|
-
// src/encryption/
|
|
1192
|
+
// src/encryption/operations/bulk-encrypt-models.ts
|
|
1261
1193
|
import { withResult as withResult5 } from "@byteslice/result";
|
|
1262
1194
|
var BulkEncryptModelsOperation = class extends EncryptionOperation {
|
|
1263
1195
|
client;
|
|
@@ -1366,7 +1298,7 @@ var BulkEncryptModelsOperationWithLockContext = class extends EncryptionOperatio
|
|
|
1366
1298
|
}
|
|
1367
1299
|
};
|
|
1368
1300
|
|
|
1369
|
-
// src/encryption/
|
|
1301
|
+
// src/encryption/operations/decrypt.ts
|
|
1370
1302
|
import { withResult as withResult6 } from "@byteslice/result";
|
|
1371
1303
|
import {
|
|
1372
1304
|
decrypt as ffiDecrypt
|
|
@@ -1393,9 +1325,6 @@ var DecryptOperation = class extends EncryptionOperation {
|
|
|
1393
1325
|
if (!this.client) {
|
|
1394
1326
|
throw noClientError();
|
|
1395
1327
|
}
|
|
1396
|
-
if (this.encryptedData === null) {
|
|
1397
|
-
return null;
|
|
1398
|
-
}
|
|
1399
1328
|
const { metadata } = this.getAuditData();
|
|
1400
1329
|
return await ffiDecrypt(this.client, {
|
|
1401
1330
|
ciphertext: this.encryptedData,
|
|
@@ -1446,9 +1375,6 @@ var DecryptOperationWithLockContext = class extends EncryptionOperation {
|
|
|
1446
1375
|
if (!client) {
|
|
1447
1376
|
throw noClientError();
|
|
1448
1377
|
}
|
|
1449
|
-
if (encryptedData === null) {
|
|
1450
|
-
return null;
|
|
1451
|
-
}
|
|
1452
1378
|
const { metadata } = this.getAuditData();
|
|
1453
1379
|
const context = await this.lockContext.getLockContext();
|
|
1454
1380
|
if (context.failure) {
|
|
@@ -1475,7 +1401,7 @@ var DecryptOperationWithLockContext = class extends EncryptionOperation {
|
|
|
1475
1401
|
}
|
|
1476
1402
|
};
|
|
1477
1403
|
|
|
1478
|
-
// src/encryption/
|
|
1404
|
+
// src/encryption/operations/decrypt-model.ts
|
|
1479
1405
|
import { withResult as withResult7 } from "@byteslice/result";
|
|
1480
1406
|
var DecryptModelOperation = class extends EncryptionOperation {
|
|
1481
1407
|
client;
|
|
@@ -1571,7 +1497,7 @@ var DecryptModelOperationWithLockContext = class extends EncryptionOperation {
|
|
|
1571
1497
|
}
|
|
1572
1498
|
};
|
|
1573
1499
|
|
|
1574
|
-
// src/encryption/
|
|
1500
|
+
// src/encryption/operations/encrypt.ts
|
|
1575
1501
|
import { withResult as withResult8 } from "@byteslice/result";
|
|
1576
1502
|
import {
|
|
1577
1503
|
encrypt as ffiEncrypt
|
|
@@ -1604,9 +1530,6 @@ var EncryptOperation = class extends EncryptionOperation {
|
|
|
1604
1530
|
if (!this.client) {
|
|
1605
1531
|
throw noClientError();
|
|
1606
1532
|
}
|
|
1607
|
-
if (this.plaintext === null) {
|
|
1608
|
-
return null;
|
|
1609
|
-
}
|
|
1610
1533
|
if (typeof this.plaintext === "number" && Number.isNaN(this.plaintext)) {
|
|
1611
1534
|
throw new Error("[encryption]: Cannot encrypt NaN value");
|
|
1612
1535
|
}
|
|
@@ -1668,9 +1591,6 @@ var EncryptOperationWithLockContext = class extends EncryptionOperation {
|
|
|
1668
1591
|
if (!client) {
|
|
1669
1592
|
throw noClientError();
|
|
1670
1593
|
}
|
|
1671
|
-
if (plaintext === null) {
|
|
1672
|
-
return null;
|
|
1673
|
-
}
|
|
1674
1594
|
const { metadata } = this.getAuditData();
|
|
1675
1595
|
const context = await this.lockContext.getLockContext();
|
|
1676
1596
|
if (context.failure) {
|
|
@@ -1699,7 +1619,7 @@ var EncryptOperationWithLockContext = class extends EncryptionOperation {
|
|
|
1699
1619
|
}
|
|
1700
1620
|
};
|
|
1701
1621
|
|
|
1702
|
-
// src/encryption/
|
|
1622
|
+
// src/encryption/operations/encrypt-model.ts
|
|
1703
1623
|
import { withResult as withResult9 } from "@byteslice/result";
|
|
1704
1624
|
var EncryptModelOperation = class extends EncryptionOperation {
|
|
1705
1625
|
client;
|
|
@@ -1806,7 +1726,7 @@ var EncryptModelOperationWithLockContext = class extends EncryptionOperation {
|
|
|
1806
1726
|
}
|
|
1807
1727
|
};
|
|
1808
1728
|
|
|
1809
|
-
// src/encryption/
|
|
1729
|
+
// src/encryption/operations/encrypt-query.ts
|
|
1810
1730
|
import { withResult as withResult10 } from "@byteslice/result";
|
|
1811
1731
|
import {
|
|
1812
1732
|
encryptQuery as ffiEncryptQuery
|
|
@@ -1836,10 +1756,6 @@ var EncryptQueryOperation = class extends EncryptionOperation {
|
|
|
1836
1756
|
queryType: this.opts.queryType,
|
|
1837
1757
|
lockContext: false
|
|
1838
1758
|
});
|
|
1839
|
-
if (this.plaintext === null || this.plaintext === void 0) {
|
|
1840
|
-
log.emit();
|
|
1841
|
-
return { data: null };
|
|
1842
|
-
}
|
|
1843
1759
|
const validationError = validateNumericValue(this.plaintext);
|
|
1844
1760
|
if (validationError?.failure) {
|
|
1845
1761
|
log.emit();
|
|
@@ -1903,10 +1819,6 @@ var EncryptQueryOperationWithLockContext = class extends EncryptionOperation {
|
|
|
1903
1819
|
queryType: this.opts.queryType,
|
|
1904
1820
|
lockContext: true
|
|
1905
1821
|
});
|
|
1906
|
-
if (this.plaintext === null || this.plaintext === void 0) {
|
|
1907
|
-
log.emit();
|
|
1908
|
-
return { data: null };
|
|
1909
|
-
}
|
|
1910
1822
|
const validationError = validateNumericValue(this.plaintext);
|
|
1911
1823
|
if (validationError?.failure) {
|
|
1912
1824
|
log.emit();
|
|
@@ -1958,9 +1870,9 @@ var EncryptQueryOperationWithLockContext = class extends EncryptionOperation {
|
|
|
1958
1870
|
}
|
|
1959
1871
|
};
|
|
1960
1872
|
|
|
1961
|
-
// src/encryption/
|
|
1873
|
+
// src/encryption/index.ts
|
|
1962
1874
|
var noClientError = () => new Error(
|
|
1963
|
-
"The
|
|
1875
|
+
"The Encryption client has not been initialized. Please call init() before using the client."
|
|
1964
1876
|
);
|
|
1965
1877
|
var EncryptionClient = class {
|
|
1966
1878
|
client;
|
|
@@ -1983,7 +1895,7 @@ var EncryptionClient = class {
|
|
|
1983
1895
|
config.encryptConfig
|
|
1984
1896
|
);
|
|
1985
1897
|
logger.debug(
|
|
1986
|
-
"Initializing the
|
|
1898
|
+
"Initializing the Encryption client with the following config:",
|
|
1987
1899
|
{
|
|
1988
1900
|
encryptConfig: validated
|
|
1989
1901
|
}
|
|
@@ -1999,7 +1911,7 @@ var EncryptionClient = class {
|
|
|
1999
1911
|
}
|
|
2000
1912
|
});
|
|
2001
1913
|
this.encryptConfig = validated;
|
|
2002
|
-
logger.debug("Successfully initialized the
|
|
1914
|
+
logger.debug("Successfully initialized the Encryption client.");
|
|
2003
1915
|
return this;
|
|
2004
1916
|
},
|
|
2005
1917
|
(error) => ({
|
|
@@ -2011,8 +1923,8 @@ var EncryptionClient = class {
|
|
|
2011
1923
|
/**
|
|
2012
1924
|
* Encrypt a value - returns a promise which resolves to an encrypted value.
|
|
2013
1925
|
*
|
|
2014
|
-
* @param plaintext - The plaintext value to be encrypted.
|
|
2015
|
-
* @param opts - Options specifying the column and table for encryption.
|
|
1926
|
+
* @param plaintext - The plaintext value to be encrypted.
|
|
1927
|
+
* @param opts - Options specifying the column (or nested field) and table for encryption. See {@link EncryptOptions}.
|
|
2016
1928
|
* @returns An EncryptOperation that can be awaited or chained with additional methods.
|
|
2017
1929
|
*
|
|
2018
1930
|
* @example
|
|
@@ -2075,8 +1987,11 @@ var EncryptionClient = class {
|
|
|
2075
1987
|
* .withLockContext(lockContext)
|
|
2076
1988
|
* ```
|
|
2077
1989
|
*
|
|
1990
|
+
* @see {@link EncryptOptions}
|
|
2078
1991
|
* @see {@link Result}
|
|
2079
1992
|
* @see {@link encryptedTable}
|
|
1993
|
+
* @see {@link encryptedColumn}
|
|
1994
|
+
* @see {@link encryptedField}
|
|
2080
1995
|
* @see {@link LockContext}
|
|
2081
1996
|
* @see {@link EncryptOperation}
|
|
2082
1997
|
*/
|
|
@@ -2184,7 +2099,11 @@ var EncryptionClient = class {
|
|
|
2184
2099
|
* ```
|
|
2185
2100
|
*/
|
|
2186
2101
|
encryptModel(input, table) {
|
|
2187
|
-
return new EncryptModelOperation(
|
|
2102
|
+
return new EncryptModelOperation(
|
|
2103
|
+
this.client,
|
|
2104
|
+
input,
|
|
2105
|
+
table
|
|
2106
|
+
);
|
|
2188
2107
|
}
|
|
2189
2108
|
/**
|
|
2190
2109
|
* Decrypt a model (object) whose fields contain encrypted values.
|
|
@@ -2263,7 +2182,11 @@ var EncryptionClient = class {
|
|
|
2263
2182
|
* ```
|
|
2264
2183
|
*/
|
|
2265
2184
|
bulkEncryptModels(input, table) {
|
|
2266
|
-
return new BulkEncryptModelsOperation(
|
|
2185
|
+
return new BulkEncryptModelsOperation(
|
|
2186
|
+
this.client,
|
|
2187
|
+
input,
|
|
2188
|
+
table
|
|
2189
|
+
);
|
|
2267
2190
|
}
|
|
2268
2191
|
/**
|
|
2269
2192
|
* Decrypt multiple models (objects) in a single bulk operation.
|
|
@@ -2301,10 +2224,10 @@ var EncryptionClient = class {
|
|
|
2301
2224
|
*
|
|
2302
2225
|
* Each value is encrypted with its own unique key via a single call to ZeroKMS.
|
|
2303
2226
|
* Values can include optional `id` fields for correlating results back to
|
|
2304
|
-
* your application data.
|
|
2227
|
+
* your application data.
|
|
2305
2228
|
*
|
|
2306
2229
|
* @param plaintexts - An array of objects with `plaintext` (and optional `id`) fields.
|
|
2307
|
-
* @param opts - Options specifying the target column and table
|
|
2230
|
+
* @param opts - Options specifying the target column (or nested {@link encryptedField}) and table. See {@link EncryptOptions}.
|
|
2308
2231
|
* @returns A `BulkEncryptOperation` that can be awaited to get a `Result`
|
|
2309
2232
|
* containing an array of `{ id?, data: Encrypted }` objects, or an `EncryptionError`.
|
|
2310
2233
|
*
|
|
@@ -2322,7 +2245,6 @@ var EncryptionClient = class {
|
|
|
2322
2245
|
* [
|
|
2323
2246
|
* { id: "u1", plaintext: "alice@example.com" },
|
|
2324
2247
|
* { id: "u2", plaintext: "bob@example.com" },
|
|
2325
|
-
* { id: "u3", plaintext: null },
|
|
2326
2248
|
* ],
|
|
2327
2249
|
* { column: users.email, table: users },
|
|
2328
2250
|
* )
|
|
@@ -2412,4 +2334,4 @@ var Encryption = async (config) => {
|
|
|
2412
2334
|
export {
|
|
2413
2335
|
Encryption
|
|
2414
2336
|
};
|
|
2415
|
-
//# sourceMappingURL=chunk-
|
|
2337
|
+
//# sourceMappingURL=chunk-WUZGKTMG.js.map
|