@cipherstash/stack 0.1.0 → 0.3.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 +11 -14
- package/dist/bin/stash.js +90 -57
- package/dist/bin/stash.js.map +1 -1
- package/dist/{chunk-SJ7JO4ME.js → chunk-JLI27P46.js} +1 -1
- package/dist/chunk-JLI27P46.js.map +1 -0
- package/dist/{chunk-2GZMIJFO.js → chunk-MW6D52V2.js} +69 -43
- package/dist/chunk-MW6D52V2.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-7XRPN2KX.js → chunk-TBAIVO6T.js} +26 -23
- package/dist/chunk-TBAIVO6T.js.map +1 -0
- package/dist/{client-BxJG56Ey.d.cts → client-Bf0Xw2xo.d.cts} +44 -26
- package/dist/{client-DtGq9dJp.d.ts → client-Kfp8OsPB.d.ts} +44 -26
- package/dist/client.cjs +25 -22
- 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 +19 -16
- 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 +94 -61
- 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 +7 -7
- package/dist/schema/index.cjs +31 -28
- 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 +90 -57
- 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 +4 -4
- package/dist/secrets/index.js.map +1 -1
- package/dist/supabase/index.cjs +7 -7
- 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 +3 -3
- package/dist/supabase/index.js.map +1 -1
- package/dist/{types-public-BCj1L4fi.d.ts → types-public-0CzBV45X.d.cts} +100 -58
- package/dist/{types-public-BCj1L4fi.d.cts → types-public-0CzBV45X.d.ts} +100 -58
- 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 +1 -1
- package/dist/chunk-2GZMIJFO.js.map +0 -1
- package/dist/chunk-7XRPN2KX.js.map +0 -1
- package/dist/chunk-SJ7JO4ME.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -33,8 +33,8 @@ __export(index_exports, {
|
|
|
33
33
|
Encryption: () => Encryption,
|
|
34
34
|
EncryptionErrorTypes: () => EncryptionErrorTypes,
|
|
35
35
|
encryptedColumn: () => encryptedColumn,
|
|
36
|
+
encryptedField: () => encryptedField,
|
|
36
37
|
encryptedTable: () => encryptedTable,
|
|
37
|
-
encryptedValue: () => encryptedValue,
|
|
38
38
|
getErrorMessage: () => getErrorMessage
|
|
39
39
|
});
|
|
40
40
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -98,7 +98,7 @@ var encryptConfigSchema = import_zod.z.object({
|
|
|
98
98
|
v: import_zod.z.number(),
|
|
99
99
|
tables: tablesSchema
|
|
100
100
|
});
|
|
101
|
-
var
|
|
101
|
+
var EncryptedField = class {
|
|
102
102
|
valueName;
|
|
103
103
|
castAsValue;
|
|
104
104
|
constructor(valueName) {
|
|
@@ -106,20 +106,20 @@ var ProtectValue = class {
|
|
|
106
106
|
this.castAsValue = "string";
|
|
107
107
|
}
|
|
108
108
|
/**
|
|
109
|
-
* Set or override the plaintext data type for this
|
|
109
|
+
* Set or override the plaintext data type for this field.
|
|
110
110
|
*
|
|
111
111
|
* By default all values are treated as `'string'`. Use this method to specify
|
|
112
112
|
* a different type so the encryption layer knows how to encode the plaintext
|
|
113
113
|
* before encrypting.
|
|
114
114
|
*
|
|
115
115
|
* @param castAs - The plaintext data type: `'string'`, `'number'`, `'boolean'`, `'date'`, `'bigint'`, or `'json'`.
|
|
116
|
-
* @returns This `
|
|
116
|
+
* @returns This `EncryptedField` instance for method chaining.
|
|
117
117
|
*
|
|
118
118
|
* @example
|
|
119
119
|
* ```typescript
|
|
120
|
-
* import {
|
|
120
|
+
* import { encryptedField } from "@cipherstash/stack/schema"
|
|
121
121
|
*
|
|
122
|
-
* const age =
|
|
122
|
+
* const age = encryptedField("age").dataType("number")
|
|
123
123
|
* ```
|
|
124
124
|
*/
|
|
125
125
|
dataType(castAs) {
|
|
@@ -136,7 +136,7 @@ var ProtectValue = class {
|
|
|
136
136
|
return this.valueName;
|
|
137
137
|
}
|
|
138
138
|
};
|
|
139
|
-
var
|
|
139
|
+
var EncryptedColumn = class {
|
|
140
140
|
columnName;
|
|
141
141
|
castAsValue;
|
|
142
142
|
indexesValue = {};
|
|
@@ -152,7 +152,7 @@ var ProtectColumn = class {
|
|
|
152
152
|
* before encrypting.
|
|
153
153
|
*
|
|
154
154
|
* @param castAs - The plaintext data type: `'string'`, `'number'`, `'boolean'`, `'date'`, `'bigint'`, or `'json'`.
|
|
155
|
-
* @returns This `
|
|
155
|
+
* @returns This `EncryptedColumn` instance for method chaining.
|
|
156
156
|
*
|
|
157
157
|
* @example
|
|
158
158
|
* ```typescript
|
|
@@ -171,7 +171,7 @@ var ProtectColumn = class {
|
|
|
171
171
|
* ORE allows sorting, comparison, and range queries on encrypted data.
|
|
172
172
|
* Use with `encryptQuery` and `queryType: 'orderAndRange'`.
|
|
173
173
|
*
|
|
174
|
-
* @returns This `
|
|
174
|
+
* @returns This `EncryptedColumn` instance for method chaining.
|
|
175
175
|
*
|
|
176
176
|
* @example
|
|
177
177
|
* ```typescript
|
|
@@ -194,7 +194,7 @@ var ProtectColumn = class {
|
|
|
194
194
|
*
|
|
195
195
|
* @param tokenFilters - Optional array of token filters (e.g. `[{ kind: 'downcase' }]`).
|
|
196
196
|
* When omitted, no token filters are applied.
|
|
197
|
-
* @returns This `
|
|
197
|
+
* @returns This `EncryptedColumn` instance for method chaining.
|
|
198
198
|
*
|
|
199
199
|
* @example
|
|
200
200
|
* ```typescript
|
|
@@ -219,7 +219,7 @@ var ProtectColumn = class {
|
|
|
219
219
|
*
|
|
220
220
|
* @param opts - Optional match index configuration. Defaults to 3-character ngram
|
|
221
221
|
* tokenization with a downcase filter, `k=6`, `m=2048`, and `include_original=true`.
|
|
222
|
-
* @returns This `
|
|
222
|
+
* @returns This `EncryptedColumn` instance for method chaining.
|
|
223
223
|
*
|
|
224
224
|
* @example
|
|
225
225
|
* ```typescript
|
|
@@ -264,7 +264,7 @@ var ProtectColumn = class {
|
|
|
264
264
|
* the plaintext type: strings become selector queries, objects/arrays become
|
|
265
265
|
* containment queries.
|
|
266
266
|
*
|
|
267
|
-
* @returns This `
|
|
267
|
+
* @returns This `EncryptedColumn` instance for method chaining.
|
|
268
268
|
*
|
|
269
269
|
* @example
|
|
270
270
|
* ```typescript
|
|
@@ -290,7 +290,7 @@ var ProtectColumn = class {
|
|
|
290
290
|
return this.columnName;
|
|
291
291
|
}
|
|
292
292
|
};
|
|
293
|
-
var
|
|
293
|
+
var EncryptedTable = class {
|
|
294
294
|
constructor(tableName, columnBuilders) {
|
|
295
295
|
this.tableName = tableName;
|
|
296
296
|
this.columnBuilders = columnBuilders;
|
|
@@ -317,7 +317,7 @@ var ProtectTable = class {
|
|
|
317
317
|
build() {
|
|
318
318
|
const builtColumns = {};
|
|
319
319
|
const processColumn = (builder, colName) => {
|
|
320
|
-
if (builder instanceof
|
|
320
|
+
if (builder instanceof EncryptedColumn) {
|
|
321
321
|
const builtColumn = builder.build();
|
|
322
322
|
if (builtColumn.cast_as === "json" && builtColumn.indexes.ste_vec?.prefix === "enabled") {
|
|
323
323
|
builtColumns[colName] = {
|
|
@@ -334,7 +334,7 @@ var ProtectTable = class {
|
|
|
334
334
|
}
|
|
335
335
|
} else {
|
|
336
336
|
for (const [key, value] of Object.entries(builder)) {
|
|
337
|
-
if (value instanceof
|
|
337
|
+
if (value instanceof EncryptedField) {
|
|
338
338
|
builtColumns[value.getName()] = value.build();
|
|
339
339
|
} else {
|
|
340
340
|
processColumn(value, key);
|
|
@@ -352,7 +352,10 @@ var ProtectTable = class {
|
|
|
352
352
|
}
|
|
353
353
|
};
|
|
354
354
|
function encryptedTable(tableName, columns) {
|
|
355
|
-
const tableBuilder = new
|
|
355
|
+
const tableBuilder = new EncryptedTable(
|
|
356
|
+
tableName,
|
|
357
|
+
columns
|
|
358
|
+
);
|
|
356
359
|
for (const [colName, colBuilder] of Object.entries(columns)) {
|
|
357
360
|
;
|
|
358
361
|
tableBuilder[colName] = colBuilder;
|
|
@@ -360,10 +363,10 @@ function encryptedTable(tableName, columns) {
|
|
|
360
363
|
return tableBuilder;
|
|
361
364
|
}
|
|
362
365
|
function encryptedColumn(columnName) {
|
|
363
|
-
return new
|
|
366
|
+
return new EncryptedColumn(columnName);
|
|
364
367
|
}
|
|
365
|
-
function
|
|
366
|
-
return new
|
|
368
|
+
function encryptedField(valueName) {
|
|
369
|
+
return new EncryptedField(valueName);
|
|
367
370
|
}
|
|
368
371
|
function buildEncryptConfig(...protectTables) {
|
|
369
372
|
const config = {
|
|
@@ -457,7 +460,7 @@ function initStackLogger(config) {
|
|
|
457
460
|
const rates = samplingFromEnv();
|
|
458
461
|
(0, import_evlog.initLogger)({
|
|
459
462
|
env: { service: "@cipherstash/stack" },
|
|
460
|
-
enabled: config?.enabled ??
|
|
463
|
+
enabled: config?.enabled ?? !!rates,
|
|
461
464
|
pretty: config?.pretty,
|
|
462
465
|
...rates && { sampling: { rates } },
|
|
463
466
|
...config?.drain && { drain: config.drain }
|
|
@@ -470,7 +473,11 @@ function safeMessage(args) {
|
|
|
470
473
|
var logger = {
|
|
471
474
|
debug(...args) {
|
|
472
475
|
const log = (0, import_evlog.createRequestLogger)();
|
|
473
|
-
log.set({
|
|
476
|
+
log.set({
|
|
477
|
+
level: "debug",
|
|
478
|
+
source: "@cipherstash/stack",
|
|
479
|
+
message: safeMessage(args)
|
|
480
|
+
});
|
|
474
481
|
log.emit();
|
|
475
482
|
},
|
|
476
483
|
info(...args) {
|
|
@@ -491,7 +498,7 @@ var logger = {
|
|
|
491
498
|
}
|
|
492
499
|
};
|
|
493
500
|
|
|
494
|
-
// src/encryption/
|
|
501
|
+
// src/encryption/index.ts
|
|
495
502
|
var import_result11 = require("@byteslice/result");
|
|
496
503
|
var import_protect_ffi9 = require("@cipherstash/protect-ffi");
|
|
497
504
|
|
|
@@ -534,18 +541,18 @@ function isEncryptedPayload(value) {
|
|
|
534
541
|
return true;
|
|
535
542
|
}
|
|
536
543
|
|
|
537
|
-
// src/encryption/
|
|
544
|
+
// src/encryption/helpers/type-guards.ts
|
|
538
545
|
function isScalarQueryTermArray(value) {
|
|
539
546
|
return Array.isArray(value) && value.length > 0 && typeof value[0] === "object" && value[0] !== null && "column" in value[0] && "table" in value[0];
|
|
540
547
|
}
|
|
541
548
|
|
|
542
|
-
// src/encryption/
|
|
549
|
+
// src/encryption/helpers/error-code.ts
|
|
543
550
|
var import_protect_ffi = require("@cipherstash/protect-ffi");
|
|
544
551
|
function getErrorCode(error) {
|
|
545
552
|
return error instanceof import_protect_ffi.ProtectError ? error.code : void 0;
|
|
546
553
|
}
|
|
547
554
|
|
|
548
|
-
// src/encryption/
|
|
555
|
+
// src/encryption/operations/batch-encrypt-query.ts
|
|
549
556
|
var import_result = require("@byteslice/result");
|
|
550
557
|
var import_protect_ffi2 = require("@cipherstash/protect-ffi");
|
|
551
558
|
|
|
@@ -563,7 +570,7 @@ var queryTypeToQueryOp = {
|
|
|
563
570
|
steVecTerm: "ste_vec_term"
|
|
564
571
|
};
|
|
565
572
|
|
|
566
|
-
// src/encryption/
|
|
573
|
+
// src/encryption/helpers/infer-index-type.ts
|
|
567
574
|
function inferIndexType(column) {
|
|
568
575
|
const config = column.build();
|
|
569
576
|
const indexes = config.indexes;
|
|
@@ -623,7 +630,7 @@ function resolveIndexType(column, queryType, plaintext) {
|
|
|
623
630
|
return { indexType };
|
|
624
631
|
}
|
|
625
632
|
|
|
626
|
-
// src/encryption/
|
|
633
|
+
// src/encryption/helpers/validation.ts
|
|
627
634
|
function validateNumericValue(value) {
|
|
628
635
|
if (typeof value === "number" && Number.isNaN(value)) {
|
|
629
636
|
return {
|
|
@@ -659,7 +666,7 @@ function assertValueIndexCompatibility(value, indexType, columnName) {
|
|
|
659
666
|
}
|
|
660
667
|
}
|
|
661
668
|
|
|
662
|
-
// src/encryption/
|
|
669
|
+
// src/encryption/operations/base-operation.ts
|
|
663
670
|
var EncryptionOperation = class {
|
|
664
671
|
auditMetadata;
|
|
665
672
|
/**
|
|
@@ -687,7 +694,7 @@ var EncryptionOperation = class {
|
|
|
687
694
|
}
|
|
688
695
|
};
|
|
689
696
|
|
|
690
|
-
// src/encryption/
|
|
697
|
+
// src/encryption/operations/batch-encrypt-query.ts
|
|
691
698
|
function filterNullTerms(terms) {
|
|
692
699
|
const nullIndices = /* @__PURE__ */ new Set();
|
|
693
700
|
const nonNullTerms = [];
|
|
@@ -842,7 +849,7 @@ var BatchEncryptQueryOperationWithLockContext = class extends EncryptionOperatio
|
|
|
842
849
|
}
|
|
843
850
|
};
|
|
844
851
|
|
|
845
|
-
// src/encryption/
|
|
852
|
+
// src/encryption/operations/bulk-decrypt.ts
|
|
846
853
|
var import_result2 = require("@byteslice/result");
|
|
847
854
|
var import_protect_ffi3 = require("@cipherstash/protect-ffi");
|
|
848
855
|
var createDecryptPayloads = (encryptedPayloads, lockContext) => {
|
|
@@ -993,10 +1000,10 @@ var BulkDecryptOperationWithLockContext = class extends EncryptionOperation {
|
|
|
993
1000
|
}
|
|
994
1001
|
};
|
|
995
1002
|
|
|
996
|
-
// src/encryption/
|
|
1003
|
+
// src/encryption/operations/bulk-decrypt-models.ts
|
|
997
1004
|
var import_result3 = require("@byteslice/result");
|
|
998
1005
|
|
|
999
|
-
// src/encryption/
|
|
1006
|
+
// src/encryption/helpers/model-helpers.ts
|
|
1000
1007
|
var import_protect_ffi4 = require("@cipherstash/protect-ffi");
|
|
1001
1008
|
function setNestedValue(obj, path2, value) {
|
|
1002
1009
|
const FORBIDDEN_KEYS = ["__proto__", "prototype", "constructor"];
|
|
@@ -1511,7 +1518,7 @@ async function bulkEncryptModelsWithLockContext(models, table, client, lockConte
|
|
|
1511
1518
|
});
|
|
1512
1519
|
}
|
|
1513
1520
|
|
|
1514
|
-
// src/encryption/
|
|
1521
|
+
// src/encryption/operations/bulk-decrypt-models.ts
|
|
1515
1522
|
var BulkDecryptModelsOperation = class extends EncryptionOperation {
|
|
1516
1523
|
client;
|
|
1517
1524
|
models;
|
|
@@ -1608,7 +1615,7 @@ var BulkDecryptModelsOperationWithLockContext = class extends EncryptionOperatio
|
|
|
1608
1615
|
}
|
|
1609
1616
|
};
|
|
1610
1617
|
|
|
1611
|
-
// src/encryption/
|
|
1618
|
+
// src/encryption/operations/bulk-encrypt.ts
|
|
1612
1619
|
var import_result4 = require("@byteslice/result");
|
|
1613
1620
|
var import_protect_ffi5 = require("@cipherstash/protect-ffi");
|
|
1614
1621
|
var createEncryptPayloads = (plaintexts, column, table, lockContext) => {
|
|
@@ -1773,7 +1780,7 @@ var BulkEncryptOperationWithLockContext = class extends EncryptionOperation {
|
|
|
1773
1780
|
}
|
|
1774
1781
|
};
|
|
1775
1782
|
|
|
1776
|
-
// src/encryption/
|
|
1783
|
+
// src/encryption/operations/bulk-encrypt-models.ts
|
|
1777
1784
|
var import_result5 = require("@byteslice/result");
|
|
1778
1785
|
var BulkEncryptModelsOperation = class extends EncryptionOperation {
|
|
1779
1786
|
client;
|
|
@@ -1882,7 +1889,7 @@ var BulkEncryptModelsOperationWithLockContext = class extends EncryptionOperatio
|
|
|
1882
1889
|
}
|
|
1883
1890
|
};
|
|
1884
1891
|
|
|
1885
|
-
// src/encryption/
|
|
1892
|
+
// src/encryption/operations/decrypt.ts
|
|
1886
1893
|
var import_result6 = require("@byteslice/result");
|
|
1887
1894
|
var import_protect_ffi6 = require("@cipherstash/protect-ffi");
|
|
1888
1895
|
var DecryptOperation = class extends EncryptionOperation {
|
|
@@ -1989,7 +1996,7 @@ var DecryptOperationWithLockContext = class extends EncryptionOperation {
|
|
|
1989
1996
|
}
|
|
1990
1997
|
};
|
|
1991
1998
|
|
|
1992
|
-
// src/encryption/
|
|
1999
|
+
// src/encryption/operations/decrypt-model.ts
|
|
1993
2000
|
var import_result7 = require("@byteslice/result");
|
|
1994
2001
|
var DecryptModelOperation = class extends EncryptionOperation {
|
|
1995
2002
|
client;
|
|
@@ -2085,7 +2092,7 @@ var DecryptModelOperationWithLockContext = class extends EncryptionOperation {
|
|
|
2085
2092
|
}
|
|
2086
2093
|
};
|
|
2087
2094
|
|
|
2088
|
-
// src/encryption/
|
|
2095
|
+
// src/encryption/operations/encrypt.ts
|
|
2089
2096
|
var import_result8 = require("@byteslice/result");
|
|
2090
2097
|
var import_protect_ffi7 = require("@cipherstash/protect-ffi");
|
|
2091
2098
|
var EncryptOperation = class extends EncryptionOperation {
|
|
@@ -2211,7 +2218,7 @@ var EncryptOperationWithLockContext = class extends EncryptionOperation {
|
|
|
2211
2218
|
}
|
|
2212
2219
|
};
|
|
2213
2220
|
|
|
2214
|
-
// src/encryption/
|
|
2221
|
+
// src/encryption/operations/encrypt-model.ts
|
|
2215
2222
|
var import_result9 = require("@byteslice/result");
|
|
2216
2223
|
var EncryptModelOperation = class extends EncryptionOperation {
|
|
2217
2224
|
client;
|
|
@@ -2318,7 +2325,7 @@ var EncryptModelOperationWithLockContext = class extends EncryptionOperation {
|
|
|
2318
2325
|
}
|
|
2319
2326
|
};
|
|
2320
2327
|
|
|
2321
|
-
// src/encryption/
|
|
2328
|
+
// src/encryption/operations/encrypt-query.ts
|
|
2322
2329
|
var import_result10 = require("@byteslice/result");
|
|
2323
2330
|
var import_protect_ffi8 = require("@cipherstash/protect-ffi");
|
|
2324
2331
|
var EncryptQueryOperation = class extends EncryptionOperation {
|
|
@@ -2468,9 +2475,9 @@ var EncryptQueryOperationWithLockContext = class extends EncryptionOperation {
|
|
|
2468
2475
|
}
|
|
2469
2476
|
};
|
|
2470
2477
|
|
|
2471
|
-
// src/encryption/
|
|
2478
|
+
// src/encryption/index.ts
|
|
2472
2479
|
var noClientError = () => new Error(
|
|
2473
|
-
"The
|
|
2480
|
+
"The Encryption client has not been initialized. Please call init() before using the client."
|
|
2474
2481
|
);
|
|
2475
2482
|
var EncryptionClient = class {
|
|
2476
2483
|
client;
|
|
@@ -2493,7 +2500,7 @@ var EncryptionClient = class {
|
|
|
2493
2500
|
config.encryptConfig
|
|
2494
2501
|
);
|
|
2495
2502
|
logger.debug(
|
|
2496
|
-
"Initializing the
|
|
2503
|
+
"Initializing the Encryption client with the following config:",
|
|
2497
2504
|
{
|
|
2498
2505
|
encryptConfig: validated
|
|
2499
2506
|
}
|
|
@@ -2501,15 +2508,15 @@ var EncryptionClient = class {
|
|
|
2501
2508
|
this.client = await (0, import_protect_ffi9.newClient)({
|
|
2502
2509
|
encryptConfig: validated,
|
|
2503
2510
|
clientOpts: {
|
|
2504
|
-
workspaceCrn: config.workspaceCrn,
|
|
2505
|
-
accessKey: config.accessKey,
|
|
2506
|
-
clientId: config.clientId,
|
|
2507
|
-
clientKey: config.clientKey,
|
|
2511
|
+
workspaceCrn: config.workspaceCrn ?? process.env.CS_WORKSPACE_CRN,
|
|
2512
|
+
accessKey: config.accessKey ?? process.env.CS_CLIENT_ACCESS_KEY,
|
|
2513
|
+
clientId: config.clientId ?? process.env.CS_CLIENT_ID,
|
|
2514
|
+
clientKey: config.clientKey ?? process.env.CS_CLIENT_KEY,
|
|
2508
2515
|
keyset: toFfiKeysetIdentifier(config.keyset)
|
|
2509
2516
|
}
|
|
2510
2517
|
});
|
|
2511
2518
|
this.encryptConfig = validated;
|
|
2512
|
-
logger.debug("Successfully initialized the
|
|
2519
|
+
logger.debug("Successfully initialized the Encryption client.");
|
|
2513
2520
|
return this;
|
|
2514
2521
|
},
|
|
2515
2522
|
(error) => ({
|
|
@@ -2522,7 +2529,7 @@ var EncryptionClient = class {
|
|
|
2522
2529
|
* Encrypt a value - returns a promise which resolves to an encrypted value.
|
|
2523
2530
|
*
|
|
2524
2531
|
* @param plaintext - The plaintext value to be encrypted. Can be null.
|
|
2525
|
-
* @param opts - Options specifying the column and table for encryption.
|
|
2532
|
+
* @param opts - Options specifying the column (or nested field) and table for encryption. See {@link EncryptOptions}.
|
|
2526
2533
|
* @returns An EncryptOperation that can be awaited or chained with additional methods.
|
|
2527
2534
|
*
|
|
2528
2535
|
* @example
|
|
@@ -2585,8 +2592,11 @@ var EncryptionClient = class {
|
|
|
2585
2592
|
* .withLockContext(lockContext)
|
|
2586
2593
|
* ```
|
|
2587
2594
|
*
|
|
2595
|
+
* @see {@link EncryptOptions}
|
|
2588
2596
|
* @see {@link Result}
|
|
2589
2597
|
* @see {@link encryptedTable}
|
|
2598
|
+
* @see {@link encryptedColumn}
|
|
2599
|
+
* @see {@link encryptedField}
|
|
2590
2600
|
* @see {@link LockContext}
|
|
2591
2601
|
* @see {@link EncryptOperation}
|
|
2592
2602
|
*/
|
|
@@ -2654,10 +2664,16 @@ var EncryptionClient = class {
|
|
|
2654
2664
|
* All other fields are passed through unchanged. Returns a thenable operation
|
|
2655
2665
|
* that supports `.withLockContext()` for identity-aware encryption.
|
|
2656
2666
|
*
|
|
2667
|
+
* The return type is **schema-aware**: fields matching the table schema are
|
|
2668
|
+
* typed as `Encrypted`, while other fields retain their original types. For
|
|
2669
|
+
* best results, let TypeScript infer the type parameters from the arguments
|
|
2670
|
+
* rather than providing an explicit type argument.
|
|
2671
|
+
*
|
|
2657
2672
|
* @param input - The model object with plaintext values to encrypt.
|
|
2658
2673
|
* @param table - The table schema defining which fields to encrypt.
|
|
2659
|
-
* @returns An `EncryptModelOperation
|
|
2660
|
-
* containing the model with
|
|
2674
|
+
* @returns An `EncryptModelOperation` that can be awaited to get a `Result`
|
|
2675
|
+
* containing the model with schema-defined fields typed as `Encrypted`,
|
|
2676
|
+
* or an `EncryptionError`.
|
|
2661
2677
|
*
|
|
2662
2678
|
* @example
|
|
2663
2679
|
* ```typescript
|
|
@@ -2672,7 +2688,9 @@ var EncryptionClient = class {
|
|
|
2672
2688
|
*
|
|
2673
2689
|
* const client = await Encryption({ schemas: [usersSchema] })
|
|
2674
2690
|
*
|
|
2675
|
-
*
|
|
2691
|
+
* // Let TypeScript infer the return type from the schema.
|
|
2692
|
+
* // result.data.email is typed as `Encrypted`, result.data.id stays `string`.
|
|
2693
|
+
* const result = await client.encryptModel(
|
|
2676
2694
|
* { id: "user_123", email: "alice@example.com", createdAt: new Date() },
|
|
2677
2695
|
* usersSchema,
|
|
2678
2696
|
* )
|
|
@@ -2680,13 +2698,17 @@ var EncryptionClient = class {
|
|
|
2680
2698
|
* if (result.failure) {
|
|
2681
2699
|
* console.error(result.failure.message)
|
|
2682
2700
|
* } else {
|
|
2683
|
-
*
|
|
2684
|
-
* console.log(result.data)
|
|
2701
|
+
* console.log(result.data.id) // string
|
|
2702
|
+
* console.log(result.data.email) // Encrypted
|
|
2685
2703
|
* }
|
|
2686
2704
|
* ```
|
|
2687
2705
|
*/
|
|
2688
2706
|
encryptModel(input, table) {
|
|
2689
|
-
return new EncryptModelOperation(
|
|
2707
|
+
return new EncryptModelOperation(
|
|
2708
|
+
this.client,
|
|
2709
|
+
input,
|
|
2710
|
+
table
|
|
2711
|
+
);
|
|
2690
2712
|
}
|
|
2691
2713
|
/**
|
|
2692
2714
|
* Decrypt a model (object) whose fields contain encrypted values.
|
|
@@ -2726,10 +2748,15 @@ var EncryptionClient = class {
|
|
|
2726
2748
|
* while still using a unique key for each encrypted value. Only fields
|
|
2727
2749
|
* matching the table schema are encrypted; other fields pass through unchanged.
|
|
2728
2750
|
*
|
|
2751
|
+
* The return type is **schema-aware**: fields matching the table schema are
|
|
2752
|
+
* typed as `Encrypted`, while other fields retain their original types. For
|
|
2753
|
+
* best results, let TypeScript infer the type parameters from the arguments.
|
|
2754
|
+
*
|
|
2729
2755
|
* @param input - An array of model objects with plaintext values to encrypt.
|
|
2730
2756
|
* @param table - The table schema defining which fields to encrypt.
|
|
2731
|
-
* @returns A `BulkEncryptModelsOperation
|
|
2732
|
-
* containing an array of models with
|
|
2757
|
+
* @returns A `BulkEncryptModelsOperation` that can be awaited to get a `Result`
|
|
2758
|
+
* containing an array of models with schema-defined fields typed as `Encrypted`,
|
|
2759
|
+
* or an `EncryptionError`.
|
|
2733
2760
|
*
|
|
2734
2761
|
* @example
|
|
2735
2762
|
* ```typescript
|
|
@@ -2744,7 +2771,9 @@ var EncryptionClient = class {
|
|
|
2744
2771
|
*
|
|
2745
2772
|
* const client = await Encryption({ schemas: [usersSchema] })
|
|
2746
2773
|
*
|
|
2747
|
-
*
|
|
2774
|
+
* // Let TypeScript infer the return type from the schema.
|
|
2775
|
+
* // Each item's email is typed as `Encrypted`, id stays `string`.
|
|
2776
|
+
* const result = await client.bulkEncryptModels(
|
|
2748
2777
|
* [
|
|
2749
2778
|
* { id: "1", email: "alice@example.com" },
|
|
2750
2779
|
* { id: "2", email: "bob@example.com" },
|
|
@@ -2758,7 +2787,11 @@ var EncryptionClient = class {
|
|
|
2758
2787
|
* ```
|
|
2759
2788
|
*/
|
|
2760
2789
|
bulkEncryptModels(input, table) {
|
|
2761
|
-
return new BulkEncryptModelsOperation(
|
|
2790
|
+
return new BulkEncryptModelsOperation(
|
|
2791
|
+
this.client,
|
|
2792
|
+
input,
|
|
2793
|
+
table
|
|
2794
|
+
);
|
|
2762
2795
|
}
|
|
2763
2796
|
/**
|
|
2764
2797
|
* Decrypt multiple models (objects) in a single bulk operation.
|
|
@@ -2799,7 +2832,7 @@ var EncryptionClient = class {
|
|
|
2799
2832
|
* your application data. Null plaintext values are preserved as null.
|
|
2800
2833
|
*
|
|
2801
2834
|
* @param plaintexts - An array of objects with `plaintext` (and optional `id`) fields.
|
|
2802
|
-
* @param opts - Options specifying the target column and table
|
|
2835
|
+
* @param opts - Options specifying the target column (or nested {@link encryptedField}) and table. See {@link EncryptOptions}.
|
|
2803
2836
|
* @returns A `BulkEncryptOperation` that can be awaited to get a `Result`
|
|
2804
2837
|
* containing an array of `{ id?, data: Encrypted }` objects, or an `EncryptionError`.
|
|
2805
2838
|
*
|
|
@@ -2908,8 +2941,8 @@ var Encryption = async (config) => {
|
|
|
2908
2941
|
Encryption,
|
|
2909
2942
|
EncryptionErrorTypes,
|
|
2910
2943
|
encryptedColumn,
|
|
2944
|
+
encryptedField,
|
|
2911
2945
|
encryptedTable,
|
|
2912
|
-
encryptedValue,
|
|
2913
2946
|
getErrorMessage
|
|
2914
2947
|
});
|
|
2915
2948
|
//# sourceMappingURL=index.cjs.map
|