@cipherstash/stack 0.3.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 +6 -0
- package/README.md +1 -1
- package/dist/bin/stash.js +46 -141
- 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-JLI27P46.js → chunk-KOU2MHXJ.js} +1 -1
- package/dist/chunk-KOU2MHXJ.js.map +1 -0
- package/dist/{chunk-MW6D52V2.js → chunk-WUZGKTMG.js} +45 -134
- package/dist/chunk-WUZGKTMG.js.map +1 -0
- package/dist/{chunk-TBAIVO6T.js → chunk-Y35W4WFN.js} +6 -6
- package/dist/chunk-Y35W4WFN.js.map +1 -0
- package/dist/{client-Bf0Xw2xo.d.cts → client-CUGXheRq.d.cts} +15 -16
- package/dist/{client-Kfp8OsPB.d.ts → client-CrGQnSlk.d.ts} +15 -16
- package/dist/client.cjs +5 -5
- 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 +1 -1
- package/dist/drizzle/index.cjs +5 -5
- package/dist/drizzle/index.cjs.map +1 -1
- package/dist/drizzle/index.d.cts +2 -2
- package/dist/drizzle/index.d.ts +2 -2
- package/dist/drizzle/index.js +2 -2
- package/dist/dynamodb/index.d.cts +2 -2
- package/dist/dynamodb/index.d.ts +2 -2
- package/dist/index.cjs +46 -141
- 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 +4 -4
- package/dist/schema/index.cjs +5 -5
- 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 +1 -1
- package/dist/secrets/index.cjs +46 -141
- 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/supabase/index.cjs +2 -2
- package/dist/supabase/index.cjs.map +1 -1
- package/dist/supabase/index.d.cts +2 -2
- package/dist/supabase/index.d.ts +2 -2
- package/dist/supabase/index.js +2 -2
- package/dist/{types-public-0CzBV45X.d.cts → types-public-Wj6tB_ux.d.cts} +47 -26
- package/dist/{types-public-0CzBV45X.d.ts → types-public-Wj6tB_ux.d.ts} +47 -26
- 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-JLI27P46.js.map +0 -1
- package/dist/chunk-MW6D52V2.js.map +0 -1
- package/dist/chunk-SUYMGQBY.js.map +0 -1
- package/dist/chunk-TBAIVO6T.js.map +0 -1
package/dist/drizzle/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
|
|
2
2
|
import { PgTable } from 'drizzle-orm/pg-core';
|
|
3
|
-
import { e as encryptedTable, C as CastAs, M as MatchIndexOpts, T as TokenFilter } from '../types-public-
|
|
4
|
-
import { E as EncryptionClient } from '../client-
|
|
3
|
+
import { e as encryptedTable, C as CastAs, M as MatchIndexOpts, T as TokenFilter } from '../types-public-Wj6tB_ux.cjs';
|
|
4
|
+
import { E as EncryptionClient } from '../client-CUGXheRq.cjs';
|
|
5
5
|
import { SQLWrapper, SQL, exists, notExists, isNull, isNotNull, not, arrayContains, arrayContained, arrayOverlaps } from 'drizzle-orm';
|
|
6
6
|
import 'zod';
|
|
7
7
|
import 'evlog';
|
package/dist/drizzle/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
|
|
2
2
|
import { PgTable } from 'drizzle-orm/pg-core';
|
|
3
|
-
import { e as encryptedTable, C as CastAs, M as MatchIndexOpts, T as TokenFilter } from '../types-public-
|
|
4
|
-
import { E as EncryptionClient } from '../client-
|
|
3
|
+
import { e as encryptedTable, C as CastAs, M as MatchIndexOpts, T as TokenFilter } from '../types-public-Wj6tB_ux.js';
|
|
4
|
+
import { E as EncryptionClient } from '../client-CrGQnSlk.js';
|
|
5
5
|
import { SQLWrapper, SQL, exists, notExists, isNull, isNotNull, not, arrayContains, arrayContained, arrayOverlaps } from 'drizzle-orm';
|
|
6
6
|
import 'zod';
|
|
7
7
|
import 'evlog';
|
package/dist/drizzle/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
queryTypes
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-KOU2MHXJ.js";
|
|
4
4
|
import {
|
|
5
5
|
encryptedColumn,
|
|
6
6
|
encryptedTable
|
|
7
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-Y35W4WFN.js";
|
|
8
8
|
|
|
9
9
|
// src/drizzle/index.ts
|
|
10
10
|
import { customType } from "drizzle-orm/pg-core";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { E as EncryptionClient } from '../client-
|
|
2
|
-
import { D as Decrypted, k as EncryptedValue, f as EncryptedTable, g as EncryptedTableColumn } from '../types-public-
|
|
1
|
+
import { E as EncryptionClient } from '../client-CUGXheRq.cjs';
|
|
2
|
+
import { D as Decrypted, k as EncryptedValue, f as EncryptedTable, g as EncryptedTableColumn } from '../types-public-Wj6tB_ux.cjs';
|
|
3
3
|
import { ProtectErrorCode } from '@cipherstash/protect-ffi';
|
|
4
4
|
import { Result } from '@byteslice/result';
|
|
5
5
|
import '../index-9-Ya3fDK.cjs';
|
package/dist/dynamodb/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { E as EncryptionClient } from '../client-
|
|
2
|
-
import { D as Decrypted, k as EncryptedValue, f as EncryptedTable, g as EncryptedTableColumn } from '../types-public-
|
|
1
|
+
import { E as EncryptionClient } from '../client-CrGQnSlk.js';
|
|
2
|
+
import { D as Decrypted, k as EncryptedValue, f as EncryptedTable, g as EncryptedTableColumn } from '../types-public-Wj6tB_ux.js';
|
|
3
3
|
import { ProtectErrorCode } from '@cipherstash/protect-ffi';
|
|
4
4
|
import { Result } from '@byteslice/result';
|
|
5
5
|
import '../index-9-Ya3fDK.js';
|
package/dist/index.cjs
CHANGED
|
@@ -55,7 +55,7 @@ function getErrorMessage(error) {
|
|
|
55
55
|
|
|
56
56
|
// src/schema/index.ts
|
|
57
57
|
var import_zod = require("zod");
|
|
58
|
-
var castAsEnum = import_zod.z.enum(["bigint", "boolean", "date", "number", "string", "json"]).default("
|
|
58
|
+
var castAsEnum = import_zod.z.enum(["bigint", "boolean", "date", "number", "string", "json", "text"]).default("text");
|
|
59
59
|
var tokenFilterSchema = import_zod.z.object({
|
|
60
60
|
kind: import_zod.z.literal("downcase")
|
|
61
61
|
});
|
|
@@ -103,7 +103,7 @@ var EncryptedField = class {
|
|
|
103
103
|
castAsValue;
|
|
104
104
|
constructor(valueName) {
|
|
105
105
|
this.valueName = valueName;
|
|
106
|
-
this.castAsValue = "
|
|
106
|
+
this.castAsValue = "text";
|
|
107
107
|
}
|
|
108
108
|
/**
|
|
109
109
|
* Set or override the plaintext data type for this field.
|
|
@@ -112,7 +112,7 @@ var EncryptedField = class {
|
|
|
112
112
|
* a different type so the encryption layer knows how to encode the plaintext
|
|
113
113
|
* before encrypting.
|
|
114
114
|
*
|
|
115
|
-
* @param castAs - The plaintext data type: `'string'`, `'number'`, `'boolean'`, `'date'`, `'bigint'`, or `'json'`.
|
|
115
|
+
* @param castAs - The plaintext data type: `'string'`, `'number'`, `'boolean'`, `'date'`, `'text'`, `'bigint'`, or `'json'`.
|
|
116
116
|
* @returns This `EncryptedField` instance for method chaining.
|
|
117
117
|
*
|
|
118
118
|
* @example
|
|
@@ -128,7 +128,7 @@ var EncryptedField = class {
|
|
|
128
128
|
}
|
|
129
129
|
build() {
|
|
130
130
|
return {
|
|
131
|
-
cast_as: this.castAsValue,
|
|
131
|
+
cast_as: this.castAsValue === "string" ? "text" : this.castAsValue,
|
|
132
132
|
indexes: {}
|
|
133
133
|
};
|
|
134
134
|
}
|
|
@@ -282,7 +282,7 @@ var EncryptedColumn = class {
|
|
|
282
282
|
}
|
|
283
283
|
build() {
|
|
284
284
|
return {
|
|
285
|
-
cast_as: this.castAsValue,
|
|
285
|
+
cast_as: this.castAsValue === "string" ? "text" : this.castAsValue,
|
|
286
286
|
indexes: this.indexesValue
|
|
287
287
|
};
|
|
288
288
|
}
|
|
@@ -504,15 +504,9 @@ var import_protect_ffi9 = require("@cipherstash/protect-ffi");
|
|
|
504
504
|
|
|
505
505
|
// src/encryption/helpers/index.ts
|
|
506
506
|
function encryptedToCompositeLiteral(obj) {
|
|
507
|
-
if (obj === null) {
|
|
508
|
-
throw new Error("encryptedToCompositeLiteral: obj cannot be null");
|
|
509
|
-
}
|
|
510
507
|
return `(${JSON.stringify(JSON.stringify(obj))})`;
|
|
511
508
|
}
|
|
512
509
|
function encryptedToEscapedCompositeLiteral(obj) {
|
|
513
|
-
if (obj === null) {
|
|
514
|
-
throw new Error("encryptedToEscapedCompositeLiteral: obj cannot be null");
|
|
515
|
-
}
|
|
516
510
|
return JSON.stringify(encryptedToCompositeLiteral(obj));
|
|
517
511
|
}
|
|
518
512
|
function formatEncryptedResult(encrypted, returnType) {
|
|
@@ -695,18 +689,6 @@ var EncryptionOperation = class {
|
|
|
695
689
|
};
|
|
696
690
|
|
|
697
691
|
// src/encryption/operations/batch-encrypt-query.ts
|
|
698
|
-
function filterNullTerms(terms) {
|
|
699
|
-
const nullIndices = /* @__PURE__ */ new Set();
|
|
700
|
-
const nonNullTerms = [];
|
|
701
|
-
terms.forEach((term, index) => {
|
|
702
|
-
if (term.value === null || term.value === void 0) {
|
|
703
|
-
nullIndices.add(index);
|
|
704
|
-
} else {
|
|
705
|
-
nonNullTerms.push({ term, originalIndex: index });
|
|
706
|
-
}
|
|
707
|
-
});
|
|
708
|
-
return { nullIndices, nonNullTerms };
|
|
709
|
-
}
|
|
710
692
|
function buildQueryPayload(term, lockContext) {
|
|
711
693
|
assertValidNumericValue(term.value);
|
|
712
694
|
const { indexType, queryOp } = resolveIndexType(
|
|
@@ -727,13 +709,10 @@ function buildQueryPayload(term, lockContext) {
|
|
|
727
709
|
}
|
|
728
710
|
return payload;
|
|
729
711
|
}
|
|
730
|
-
function assembleResults(
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
results[originalIndex] = formatEncryptedResult(encrypted, term.returnType);
|
|
735
|
-
});
|
|
736
|
-
return results;
|
|
712
|
+
function assembleResults(terms, encryptedValues) {
|
|
713
|
+
return terms.map(
|
|
714
|
+
(term, i) => formatEncryptedResult(encryptedValues[i], term.returnType)
|
|
715
|
+
);
|
|
737
716
|
}
|
|
738
717
|
var BatchEncryptQueryOperation = class extends EncryptionOperation {
|
|
739
718
|
constructor(client, terms) {
|
|
@@ -760,23 +739,18 @@ var BatchEncryptQueryOperation = class extends EncryptionOperation {
|
|
|
760
739
|
log.emit();
|
|
761
740
|
return { data: [] };
|
|
762
741
|
}
|
|
763
|
-
const { nullIndices, nonNullTerms } = filterNullTerms(this.terms);
|
|
764
|
-
if (nonNullTerms.length === 0) {
|
|
765
|
-
log.emit();
|
|
766
|
-
return { data: this.terms.map(() => null) };
|
|
767
|
-
}
|
|
768
742
|
const result = await (0, import_result.withResult)(
|
|
769
743
|
async () => {
|
|
770
744
|
if (!this.client) throw noClientError();
|
|
771
745
|
const { metadata } = this.getAuditData();
|
|
772
|
-
const queries =
|
|
773
|
-
(
|
|
746
|
+
const queries = this.terms.map(
|
|
747
|
+
(term) => buildQueryPayload(term)
|
|
774
748
|
);
|
|
775
749
|
const encrypted = await (0, import_protect_ffi2.encryptQueryBulk)(this.client, {
|
|
776
750
|
queries,
|
|
777
751
|
unverifiedContext: metadata
|
|
778
752
|
});
|
|
779
|
-
return assembleResults(this.terms
|
|
753
|
+
return assembleResults(this.terms, encrypted);
|
|
780
754
|
},
|
|
781
755
|
(error) => {
|
|
782
756
|
log.set({ errorCode: getErrorCode(error) ?? "unknown" });
|
|
@@ -810,11 +784,6 @@ var BatchEncryptQueryOperationWithLockContext = class extends EncryptionOperatio
|
|
|
810
784
|
log.emit();
|
|
811
785
|
return { data: [] };
|
|
812
786
|
}
|
|
813
|
-
const { nullIndices, nonNullTerms } = filterNullTerms(this.terms);
|
|
814
|
-
if (nonNullTerms.length === 0) {
|
|
815
|
-
log.emit();
|
|
816
|
-
return { data: this.terms.map(() => null) };
|
|
817
|
-
}
|
|
818
787
|
const lockContextResult = await this.lockContext.getLockContext();
|
|
819
788
|
if (lockContextResult.failure) {
|
|
820
789
|
log.emit();
|
|
@@ -825,15 +794,15 @@ var BatchEncryptQueryOperationWithLockContext = class extends EncryptionOperatio
|
|
|
825
794
|
async () => {
|
|
826
795
|
if (!this.client) throw noClientError();
|
|
827
796
|
const { metadata } = this.getAuditData();
|
|
828
|
-
const queries =
|
|
829
|
-
(
|
|
797
|
+
const queries = this.terms.map(
|
|
798
|
+
(term) => buildQueryPayload(term, context)
|
|
830
799
|
);
|
|
831
800
|
const encrypted = await (0, import_protect_ffi2.encryptQueryBulk)(this.client, {
|
|
832
801
|
queries,
|
|
833
802
|
serviceToken: ctsToken,
|
|
834
803
|
unverifiedContext: metadata
|
|
835
804
|
});
|
|
836
|
-
return assembleResults(this.terms
|
|
805
|
+
return assembleResults(this.terms, encrypted);
|
|
837
806
|
},
|
|
838
807
|
(error) => {
|
|
839
808
|
log.set({ errorCode: getErrorCode(error) ?? "unknown" });
|
|
@@ -853,42 +822,25 @@ var BatchEncryptQueryOperationWithLockContext = class extends EncryptionOperatio
|
|
|
853
822
|
var import_result2 = require("@byteslice/result");
|
|
854
823
|
var import_protect_ffi3 = require("@cipherstash/protect-ffi");
|
|
855
824
|
var createDecryptPayloads = (encryptedPayloads, lockContext) => {
|
|
856
|
-
return encryptedPayloads.map((
|
|
825
|
+
return encryptedPayloads.map(({ id, data }) => ({
|
|
857
826
|
id,
|
|
858
827
|
ciphertext: data,
|
|
859
|
-
originalIndex,
|
|
860
828
|
...lockContext && { lockContext }
|
|
861
829
|
}));
|
|
862
830
|
};
|
|
863
|
-
var createNullResult = (encryptedPayloads) => {
|
|
864
|
-
return encryptedPayloads.map(({ id }) => ({
|
|
865
|
-
id,
|
|
866
|
-
data: null
|
|
867
|
-
}));
|
|
868
|
-
};
|
|
869
831
|
var mapDecryptedDataToResult = (encryptedPayloads, decryptedData) => {
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
const decryptResult = decryptedData[decryptedIndex];
|
|
877
|
-
if ("error" in decryptResult) {
|
|
878
|
-
result[i] = {
|
|
879
|
-
id: encryptedPayloads[i].id,
|
|
880
|
-
error: decryptResult.error
|
|
881
|
-
};
|
|
882
|
-
} else {
|
|
883
|
-
result[i] = {
|
|
884
|
-
id: encryptedPayloads[i].id,
|
|
885
|
-
data: decryptResult.data
|
|
886
|
-
};
|
|
887
|
-
}
|
|
888
|
-
decryptedIndex++;
|
|
832
|
+
return decryptedData.map((decryptResult, i) => {
|
|
833
|
+
if ("error" in decryptResult) {
|
|
834
|
+
return {
|
|
835
|
+
id: encryptedPayloads[i].id,
|
|
836
|
+
error: decryptResult.error
|
|
837
|
+
};
|
|
889
838
|
}
|
|
890
|
-
|
|
891
|
-
|
|
839
|
+
return {
|
|
840
|
+
id: encryptedPayloads[i].id,
|
|
841
|
+
data: decryptResult.data
|
|
842
|
+
};
|
|
843
|
+
});
|
|
892
844
|
};
|
|
893
845
|
var BulkDecryptOperation = class extends EncryptionOperation {
|
|
894
846
|
client;
|
|
@@ -913,13 +865,10 @@ var BulkDecryptOperation = class extends EncryptionOperation {
|
|
|
913
865
|
if (!this.client) throw noClientError();
|
|
914
866
|
if (!this.encryptedPayloads || this.encryptedPayloads.length === 0)
|
|
915
867
|
return [];
|
|
916
|
-
const
|
|
917
|
-
if (nonNullPayloads.length === 0) {
|
|
918
|
-
return createNullResult(this.encryptedPayloads);
|
|
919
|
-
}
|
|
868
|
+
const payloads = createDecryptPayloads(this.encryptedPayloads);
|
|
920
869
|
const { metadata } = this.getAuditData();
|
|
921
870
|
const decryptedData = await (0, import_protect_ffi3.decryptBulkFallible)(this.client, {
|
|
922
|
-
ciphertexts:
|
|
871
|
+
ciphertexts: payloads,
|
|
923
872
|
unverifiedContext: metadata
|
|
924
873
|
});
|
|
925
874
|
return mapDecryptedDataToResult(this.encryptedPayloads, decryptedData);
|
|
@@ -971,16 +920,13 @@ var BulkDecryptOperationWithLockContext = class extends EncryptionOperation {
|
|
|
971
920
|
if (context.failure) {
|
|
972
921
|
throw new Error(`[encryption]: ${context.failure.message}`);
|
|
973
922
|
}
|
|
974
|
-
const
|
|
923
|
+
const payloads = createDecryptPayloads(
|
|
975
924
|
encryptedPayloads,
|
|
976
925
|
context.data.context
|
|
977
926
|
);
|
|
978
|
-
if (nonNullPayloads.length === 0) {
|
|
979
|
-
return createNullResult(encryptedPayloads);
|
|
980
|
-
}
|
|
981
927
|
const { metadata } = this.getAuditData();
|
|
982
928
|
const decryptedData = await (0, import_protect_ffi3.decryptBulkFallible)(client, {
|
|
983
|
-
ciphertexts:
|
|
929
|
+
ciphertexts: payloads,
|
|
984
930
|
serviceToken: context.data.ctsToken,
|
|
985
931
|
unverifiedContext: metadata
|
|
986
932
|
});
|
|
@@ -1619,34 +1565,14 @@ var BulkDecryptModelsOperationWithLockContext = class extends EncryptionOperatio
|
|
|
1619
1565
|
var import_result4 = require("@byteslice/result");
|
|
1620
1566
|
var import_protect_ffi5 = require("@cipherstash/protect-ffi");
|
|
1621
1567
|
var createEncryptPayloads = (plaintexts, column, table, lockContext) => {
|
|
1622
|
-
return plaintexts.map((
|
|
1568
|
+
return plaintexts.map(({ id, plaintext }) => ({
|
|
1623
1569
|
id,
|
|
1624
1570
|
plaintext,
|
|
1625
1571
|
column: column.getName(),
|
|
1626
1572
|
table: table.tableName,
|
|
1627
|
-
originalIndex,
|
|
1628
1573
|
...lockContext && { lockContext }
|
|
1629
1574
|
}));
|
|
1630
1575
|
};
|
|
1631
|
-
var createNullResult2 = (plaintexts) => {
|
|
1632
|
-
return plaintexts.map(({ id }) => ({ id, data: null }));
|
|
1633
|
-
};
|
|
1634
|
-
var mapEncryptedDataToResult = (plaintexts, encryptedData) => {
|
|
1635
|
-
const result = new Array(plaintexts.length);
|
|
1636
|
-
let encryptedIndex = 0;
|
|
1637
|
-
for (let i = 0; i < plaintexts.length; i++) {
|
|
1638
|
-
if (plaintexts[i].plaintext === null) {
|
|
1639
|
-
result[i] = { id: plaintexts[i].id, data: null };
|
|
1640
|
-
} else {
|
|
1641
|
-
result[i] = {
|
|
1642
|
-
id: plaintexts[i].id,
|
|
1643
|
-
data: encryptedData[encryptedIndex]
|
|
1644
|
-
};
|
|
1645
|
-
encryptedIndex++;
|
|
1646
|
-
}
|
|
1647
|
-
}
|
|
1648
|
-
return result;
|
|
1649
|
-
};
|
|
1650
1576
|
var BulkEncryptOperation = class extends EncryptionOperation {
|
|
1651
1577
|
client;
|
|
1652
1578
|
plaintexts;
|
|
@@ -1679,20 +1605,20 @@ var BulkEncryptOperation = class extends EncryptionOperation {
|
|
|
1679
1605
|
if (!this.plaintexts || this.plaintexts.length === 0) {
|
|
1680
1606
|
return [];
|
|
1681
1607
|
}
|
|
1682
|
-
const
|
|
1608
|
+
const payloads = createEncryptPayloads(
|
|
1683
1609
|
this.plaintexts,
|
|
1684
1610
|
this.column,
|
|
1685
1611
|
this.table
|
|
1686
1612
|
);
|
|
1687
|
-
if (nonNullPayloads.length === 0) {
|
|
1688
|
-
return createNullResult2(this.plaintexts);
|
|
1689
|
-
}
|
|
1690
1613
|
const { metadata } = this.getAuditData();
|
|
1691
1614
|
const encryptedData = await (0, import_protect_ffi5.encryptBulk)(this.client, {
|
|
1692
|
-
plaintexts:
|
|
1615
|
+
plaintexts: payloads,
|
|
1693
1616
|
unverifiedContext: metadata
|
|
1694
1617
|
});
|
|
1695
|
-
return
|
|
1618
|
+
return encryptedData.map((data, i) => ({
|
|
1619
|
+
id: this.plaintexts[i].id,
|
|
1620
|
+
data
|
|
1621
|
+
}));
|
|
1696
1622
|
},
|
|
1697
1623
|
(error) => {
|
|
1698
1624
|
log.set({ errorCode: getErrorCode(error) ?? "unknown" });
|
|
@@ -1749,22 +1675,22 @@ var BulkEncryptOperationWithLockContext = class extends EncryptionOperation {
|
|
|
1749
1675
|
if (context.failure) {
|
|
1750
1676
|
throw new Error(`[encryption]: ${context.failure.message}`);
|
|
1751
1677
|
}
|
|
1752
|
-
const
|
|
1678
|
+
const payloads = createEncryptPayloads(
|
|
1753
1679
|
plaintexts,
|
|
1754
1680
|
column,
|
|
1755
1681
|
table,
|
|
1756
1682
|
context.data.context
|
|
1757
1683
|
);
|
|
1758
|
-
if (nonNullPayloads.length === 0) {
|
|
1759
|
-
return createNullResult2(plaintexts);
|
|
1760
|
-
}
|
|
1761
1684
|
const { metadata } = this.getAuditData();
|
|
1762
1685
|
const encryptedData = await (0, import_protect_ffi5.encryptBulk)(client, {
|
|
1763
|
-
plaintexts:
|
|
1686
|
+
plaintexts: payloads,
|
|
1764
1687
|
serviceToken: context.data.ctsToken,
|
|
1765
1688
|
unverifiedContext: metadata
|
|
1766
1689
|
});
|
|
1767
|
-
return
|
|
1690
|
+
return encryptedData.map((data, i) => ({
|
|
1691
|
+
id: plaintexts[i].id,
|
|
1692
|
+
data
|
|
1693
|
+
}));
|
|
1768
1694
|
},
|
|
1769
1695
|
(error) => {
|
|
1770
1696
|
log.set({ errorCode: getErrorCode(error) ?? "unknown" });
|
|
@@ -1914,9 +1840,6 @@ var DecryptOperation = class extends EncryptionOperation {
|
|
|
1914
1840
|
if (!this.client) {
|
|
1915
1841
|
throw noClientError();
|
|
1916
1842
|
}
|
|
1917
|
-
if (this.encryptedData === null) {
|
|
1918
|
-
return null;
|
|
1919
|
-
}
|
|
1920
1843
|
const { metadata } = this.getAuditData();
|
|
1921
1844
|
return await (0, import_protect_ffi6.decrypt)(this.client, {
|
|
1922
1845
|
ciphertext: this.encryptedData,
|
|
@@ -1967,9 +1890,6 @@ var DecryptOperationWithLockContext = class extends EncryptionOperation {
|
|
|
1967
1890
|
if (!client) {
|
|
1968
1891
|
throw noClientError();
|
|
1969
1892
|
}
|
|
1970
|
-
if (encryptedData === null) {
|
|
1971
|
-
return null;
|
|
1972
|
-
}
|
|
1973
1893
|
const { metadata } = this.getAuditData();
|
|
1974
1894
|
const context = await this.lockContext.getLockContext();
|
|
1975
1895
|
if (context.failure) {
|
|
@@ -2123,9 +2043,6 @@ var EncryptOperation = class extends EncryptionOperation {
|
|
|
2123
2043
|
if (!this.client) {
|
|
2124
2044
|
throw noClientError();
|
|
2125
2045
|
}
|
|
2126
|
-
if (this.plaintext === null) {
|
|
2127
|
-
return null;
|
|
2128
|
-
}
|
|
2129
2046
|
if (typeof this.plaintext === "number" && Number.isNaN(this.plaintext)) {
|
|
2130
2047
|
throw new Error("[encryption]: Cannot encrypt NaN value");
|
|
2131
2048
|
}
|
|
@@ -2187,9 +2104,6 @@ var EncryptOperationWithLockContext = class extends EncryptionOperation {
|
|
|
2187
2104
|
if (!client) {
|
|
2188
2105
|
throw noClientError();
|
|
2189
2106
|
}
|
|
2190
|
-
if (plaintext === null) {
|
|
2191
|
-
return null;
|
|
2192
|
-
}
|
|
2193
2107
|
const { metadata } = this.getAuditData();
|
|
2194
2108
|
const context = await this.lockContext.getLockContext();
|
|
2195
2109
|
if (context.failure) {
|
|
@@ -2353,10 +2267,6 @@ var EncryptQueryOperation = class extends EncryptionOperation {
|
|
|
2353
2267
|
queryType: this.opts.queryType,
|
|
2354
2268
|
lockContext: false
|
|
2355
2269
|
});
|
|
2356
|
-
if (this.plaintext === null || this.plaintext === void 0) {
|
|
2357
|
-
log.emit();
|
|
2358
|
-
return { data: null };
|
|
2359
|
-
}
|
|
2360
2270
|
const validationError = validateNumericValue(this.plaintext);
|
|
2361
2271
|
if (validationError?.failure) {
|
|
2362
2272
|
log.emit();
|
|
@@ -2420,10 +2330,6 @@ var EncryptQueryOperationWithLockContext = class extends EncryptionOperation {
|
|
|
2420
2330
|
queryType: this.opts.queryType,
|
|
2421
2331
|
lockContext: true
|
|
2422
2332
|
});
|
|
2423
|
-
if (this.plaintext === null || this.plaintext === void 0) {
|
|
2424
|
-
log.emit();
|
|
2425
|
-
return { data: null };
|
|
2426
|
-
}
|
|
2427
2333
|
const validationError = validateNumericValue(this.plaintext);
|
|
2428
2334
|
if (validationError?.failure) {
|
|
2429
2335
|
log.emit();
|
|
@@ -2528,7 +2434,7 @@ var EncryptionClient = class {
|
|
|
2528
2434
|
/**
|
|
2529
2435
|
* Encrypt a value - returns a promise which resolves to an encrypted value.
|
|
2530
2436
|
*
|
|
2531
|
-
* @param plaintext - The plaintext value to be encrypted.
|
|
2437
|
+
* @param plaintext - The plaintext value to be encrypted.
|
|
2532
2438
|
* @param opts - Options specifying the column (or nested field) and table for encryption. See {@link EncryptOptions}.
|
|
2533
2439
|
* @returns An EncryptOperation that can be awaited or chained with additional methods.
|
|
2534
2440
|
*
|
|
@@ -2829,7 +2735,7 @@ var EncryptionClient = class {
|
|
|
2829
2735
|
*
|
|
2830
2736
|
* Each value is encrypted with its own unique key via a single call to ZeroKMS.
|
|
2831
2737
|
* Values can include optional `id` fields for correlating results back to
|
|
2832
|
-
* your application data.
|
|
2738
|
+
* your application data.
|
|
2833
2739
|
*
|
|
2834
2740
|
* @param plaintexts - An array of objects with `plaintext` (and optional `id`) fields.
|
|
2835
2741
|
* @param opts - Options specifying the target column (or nested {@link encryptedField}) and table. See {@link EncryptOptions}.
|
|
@@ -2850,7 +2756,6 @@ var EncryptionClient = class {
|
|
|
2850
2756
|
* [
|
|
2851
2757
|
* { id: "u1", plaintext: "alice@example.com" },
|
|
2852
2758
|
* { id: "u2", plaintext: "bob@example.com" },
|
|
2853
|
-
* { id: "u3", plaintext: null },
|
|
2854
2759
|
* ],
|
|
2855
2760
|
* { column: users.email, table: users },
|
|
2856
2761
|
* )
|