@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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @cipherstash/stack
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- afe0a55: Improved encrypt model return types to account for Encrypted values.
|
|
8
|
+
|
|
9
|
+
## 0.2.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 68c8199: Improved typing for model interfaces and full bun support.
|
|
14
|
+
|
|
3
15
|
## 0.1.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -139,29 +139,27 @@ const decrypted = await client.decrypt(encrypted.data)
|
|
|
139
139
|
|
|
140
140
|
Encrypt or decrypt an entire object. Only fields matching your schema are encrypted; other fields pass through unchanged.
|
|
141
141
|
|
|
142
|
+
The return type is **schema-aware**: fields matching the table schema are typed as `Encrypted`, while other fields retain their original types. For best results, let TypeScript infer the type parameters from the arguments:
|
|
143
|
+
|
|
142
144
|
```typescript
|
|
145
|
+
type User = { id: string; email: string; createdAt: Date }
|
|
146
|
+
|
|
143
147
|
const user = {
|
|
144
148
|
id: "user_123",
|
|
145
149
|
email: "alice@example.com", // defined in schema -> encrypted
|
|
146
150
|
createdAt: new Date(), // not in schema -> unchanged
|
|
147
151
|
}
|
|
148
152
|
|
|
149
|
-
//
|
|
153
|
+
// Let TypeScript infer the return type from the schema
|
|
150
154
|
const encryptedResult = await client.encryptModel(user, users)
|
|
155
|
+
// encryptedResult.data.email -> Encrypted
|
|
156
|
+
// encryptedResult.data.id -> string
|
|
157
|
+
// encryptedResult.data.createdAt -> Date
|
|
151
158
|
|
|
152
159
|
// Decrypt a model
|
|
153
160
|
const decryptedResult = await client.decryptModel(encryptedResult.data)
|
|
154
161
|
```
|
|
155
162
|
|
|
156
|
-
Type-safe generics are supported:
|
|
157
|
-
|
|
158
|
-
```typescript
|
|
159
|
-
type User = { id: string; email: string; createdAt: Date }
|
|
160
|
-
|
|
161
|
-
const result = await client.encryptModel<User>(user, users)
|
|
162
|
-
const back = await client.decryptModel<User>(result.data)
|
|
163
|
-
```
|
|
164
|
-
|
|
165
163
|
### Bulk Operations
|
|
166
164
|
|
|
167
165
|
All bulk methods make a single call to ZeroKMS regardless of the number of records, while still using a unique key per value.
|
|
@@ -592,11 +590,11 @@ function Encryption(config: EncryptionClientConfig): Promise<EncryptionClient>
|
|
|
592
590
|
| `decrypt` | `(encryptedData)` | `DecryptOperation` (thenable) |
|
|
593
591
|
| `encryptQuery` | `(plaintext, { column, table, queryType?, returnType? })` | `EncryptQueryOperation` (thenable) |
|
|
594
592
|
| `encryptQuery` | `(terms: ScalarQueryTerm[])` | `BatchEncryptQueryOperation` (thenable) |
|
|
595
|
-
| `encryptModel` | `(model, table)` | `EncryptModelOperation<T
|
|
593
|
+
| `encryptModel` | `(model, table)` | `EncryptModelOperation<EncryptedFromSchema<T, S>>` (thenable) |
|
|
596
594
|
| `decryptModel` | `(encryptedModel)` | `DecryptModelOperation<T>` (thenable) |
|
|
597
595
|
| `bulkEncrypt` | `(plaintexts, { column, table })` | `BulkEncryptOperation` (thenable) |
|
|
598
596
|
| `bulkDecrypt` | `(encryptedPayloads)` | `BulkDecryptOperation` (thenable) |
|
|
599
|
-
| `bulkEncryptModels` | `(models, table)` | `BulkEncryptModelsOperation<T
|
|
597
|
+
| `bulkEncryptModels` | `(models, table)` | `BulkEncryptModelsOperation<EncryptedFromSchema<T, S>>` (thenable) |
|
|
600
598
|
| `bulkDecryptModels` | `(encryptedModels)` | `BulkDecryptModelsOperation<T>` (thenable) |
|
|
601
599
|
|
|
602
600
|
All operations are thenable (awaitable) and support `.withLockContext(lockContext)` for identity-aware encryption.
|
|
@@ -629,7 +627,7 @@ await secrets.delete(name)
|
|
|
629
627
|
import { encryptedTable, encryptedColumn, csValue } from "@cipherstash/stack/schema"
|
|
630
628
|
|
|
631
629
|
encryptedTable(tableName, columns)
|
|
632
|
-
encryptedColumn(columnName) // returns
|
|
630
|
+
encryptedColumn(columnName) // returns EncryptedColumn
|
|
633
631
|
csValue(valueName) // returns ProtectValue (for nested values)
|
|
634
632
|
```
|
|
635
633
|
|
|
@@ -663,7 +661,6 @@ All method signatures on the encryption client (`encrypt`, `decrypt`, `encryptMo
|
|
|
663
661
|
|
|
664
662
|
- **Node.js** >= 18
|
|
665
663
|
- The package includes a native FFI module (`@cipherstash/protect-ffi`) written in Rust and embedded via [Neon](https://github.com/neon-bindings/neon). You must opt out of bundling this package in tools like Webpack, esbuild, or Next.js (`serverExternalPackages`).
|
|
666
|
-
- [Bun](https://bun.sh/) is not currently supported due to incomplete Node-API compatibility.
|
|
667
664
|
|
|
668
665
|
## License
|
|
669
666
|
|
package/dist/bin/stash.js
CHANGED
|
@@ -1561,7 +1561,7 @@ var encryptConfigSchema = z2.object({
|
|
|
1561
1561
|
v: z2.number(),
|
|
1562
1562
|
tables: tablesSchema
|
|
1563
1563
|
});
|
|
1564
|
-
var
|
|
1564
|
+
var EncryptedField = class {
|
|
1565
1565
|
valueName;
|
|
1566
1566
|
castAsValue;
|
|
1567
1567
|
constructor(valueName) {
|
|
@@ -1569,20 +1569,20 @@ var ProtectValue = class {
|
|
|
1569
1569
|
this.castAsValue = "string";
|
|
1570
1570
|
}
|
|
1571
1571
|
/**
|
|
1572
|
-
* Set or override the plaintext data type for this
|
|
1572
|
+
* Set or override the plaintext data type for this field.
|
|
1573
1573
|
*
|
|
1574
1574
|
* By default all values are treated as `'string'`. Use this method to specify
|
|
1575
1575
|
* a different type so the encryption layer knows how to encode the plaintext
|
|
1576
1576
|
* before encrypting.
|
|
1577
1577
|
*
|
|
1578
1578
|
* @param castAs - The plaintext data type: `'string'`, `'number'`, `'boolean'`, `'date'`, `'bigint'`, or `'json'`.
|
|
1579
|
-
* @returns This `
|
|
1579
|
+
* @returns This `EncryptedField` instance for method chaining.
|
|
1580
1580
|
*
|
|
1581
1581
|
* @example
|
|
1582
1582
|
* ```typescript
|
|
1583
|
-
* import {
|
|
1583
|
+
* import { encryptedField } from "@cipherstash/stack/schema"
|
|
1584
1584
|
*
|
|
1585
|
-
* const age =
|
|
1585
|
+
* const age = encryptedField("age").dataType("number")
|
|
1586
1586
|
* ```
|
|
1587
1587
|
*/
|
|
1588
1588
|
dataType(castAs) {
|
|
@@ -1599,7 +1599,7 @@ var ProtectValue = class {
|
|
|
1599
1599
|
return this.valueName;
|
|
1600
1600
|
}
|
|
1601
1601
|
};
|
|
1602
|
-
var
|
|
1602
|
+
var EncryptedColumn = class {
|
|
1603
1603
|
columnName;
|
|
1604
1604
|
castAsValue;
|
|
1605
1605
|
indexesValue = {};
|
|
@@ -1615,7 +1615,7 @@ var ProtectColumn = class {
|
|
|
1615
1615
|
* before encrypting.
|
|
1616
1616
|
*
|
|
1617
1617
|
* @param castAs - The plaintext data type: `'string'`, `'number'`, `'boolean'`, `'date'`, `'bigint'`, or `'json'`.
|
|
1618
|
-
* @returns This `
|
|
1618
|
+
* @returns This `EncryptedColumn` instance for method chaining.
|
|
1619
1619
|
*
|
|
1620
1620
|
* @example
|
|
1621
1621
|
* ```typescript
|
|
@@ -1634,7 +1634,7 @@ var ProtectColumn = class {
|
|
|
1634
1634
|
* ORE allows sorting, comparison, and range queries on encrypted data.
|
|
1635
1635
|
* Use with `encryptQuery` and `queryType: 'orderAndRange'`.
|
|
1636
1636
|
*
|
|
1637
|
-
* @returns This `
|
|
1637
|
+
* @returns This `EncryptedColumn` instance for method chaining.
|
|
1638
1638
|
*
|
|
1639
1639
|
* @example
|
|
1640
1640
|
* ```typescript
|
|
@@ -1657,7 +1657,7 @@ var ProtectColumn = class {
|
|
|
1657
1657
|
*
|
|
1658
1658
|
* @param tokenFilters - Optional array of token filters (e.g. `[{ kind: 'downcase' }]`).
|
|
1659
1659
|
* When omitted, no token filters are applied.
|
|
1660
|
-
* @returns This `
|
|
1660
|
+
* @returns This `EncryptedColumn` instance for method chaining.
|
|
1661
1661
|
*
|
|
1662
1662
|
* @example
|
|
1663
1663
|
* ```typescript
|
|
@@ -1682,7 +1682,7 @@ var ProtectColumn = class {
|
|
|
1682
1682
|
*
|
|
1683
1683
|
* @param opts - Optional match index configuration. Defaults to 3-character ngram
|
|
1684
1684
|
* tokenization with a downcase filter, `k=6`, `m=2048`, and `include_original=true`.
|
|
1685
|
-
* @returns This `
|
|
1685
|
+
* @returns This `EncryptedColumn` instance for method chaining.
|
|
1686
1686
|
*
|
|
1687
1687
|
* @example
|
|
1688
1688
|
* ```typescript
|
|
@@ -1727,7 +1727,7 @@ var ProtectColumn = class {
|
|
|
1727
1727
|
* the plaintext type: strings become selector queries, objects/arrays become
|
|
1728
1728
|
* containment queries.
|
|
1729
1729
|
*
|
|
1730
|
-
* @returns This `
|
|
1730
|
+
* @returns This `EncryptedColumn` instance for method chaining.
|
|
1731
1731
|
*
|
|
1732
1732
|
* @example
|
|
1733
1733
|
* ```typescript
|
|
@@ -1753,7 +1753,7 @@ var ProtectColumn = class {
|
|
|
1753
1753
|
return this.columnName;
|
|
1754
1754
|
}
|
|
1755
1755
|
};
|
|
1756
|
-
var
|
|
1756
|
+
var EncryptedTable = class {
|
|
1757
1757
|
constructor(tableName, columnBuilders) {
|
|
1758
1758
|
this.tableName = tableName;
|
|
1759
1759
|
this.columnBuilders = columnBuilders;
|
|
@@ -1780,7 +1780,7 @@ var ProtectTable = class {
|
|
|
1780
1780
|
build() {
|
|
1781
1781
|
const builtColumns = {};
|
|
1782
1782
|
const processColumn = (builder, colName) => {
|
|
1783
|
-
if (builder instanceof
|
|
1783
|
+
if (builder instanceof EncryptedColumn) {
|
|
1784
1784
|
const builtColumn = builder.build();
|
|
1785
1785
|
if (builtColumn.cast_as === "json" && builtColumn.indexes.ste_vec?.prefix === "enabled") {
|
|
1786
1786
|
builtColumns[colName] = {
|
|
@@ -1797,7 +1797,7 @@ var ProtectTable = class {
|
|
|
1797
1797
|
}
|
|
1798
1798
|
} else {
|
|
1799
1799
|
for (const [key, value] of Object.entries(builder)) {
|
|
1800
|
-
if (value instanceof
|
|
1800
|
+
if (value instanceof EncryptedField) {
|
|
1801
1801
|
builtColumns[value.getName()] = value.build();
|
|
1802
1802
|
} else {
|
|
1803
1803
|
processColumn(value, key);
|
|
@@ -1815,7 +1815,10 @@ var ProtectTable = class {
|
|
|
1815
1815
|
}
|
|
1816
1816
|
};
|
|
1817
1817
|
function encryptedTable(tableName, columns) {
|
|
1818
|
-
const tableBuilder = new
|
|
1818
|
+
const tableBuilder = new EncryptedTable(
|
|
1819
|
+
tableName,
|
|
1820
|
+
columns
|
|
1821
|
+
);
|
|
1819
1822
|
for (const [colName, colBuilder] of Object.entries(columns)) {
|
|
1820
1823
|
;
|
|
1821
1824
|
tableBuilder[colName] = colBuilder;
|
|
@@ -1823,7 +1826,7 @@ function encryptedTable(tableName, columns) {
|
|
|
1823
1826
|
return tableBuilder;
|
|
1824
1827
|
}
|
|
1825
1828
|
function encryptedColumn(columnName) {
|
|
1826
|
-
return new
|
|
1829
|
+
return new EncryptedColumn(columnName);
|
|
1827
1830
|
}
|
|
1828
1831
|
function buildEncryptConfig(...protectTables) {
|
|
1829
1832
|
const config3 = {
|
|
@@ -1917,7 +1920,7 @@ function initStackLogger(config3) {
|
|
|
1917
1920
|
const rates = samplingFromEnv();
|
|
1918
1921
|
initLogger({
|
|
1919
1922
|
env: { service: "@cipherstash/stack" },
|
|
1920
|
-
enabled: config3?.enabled ??
|
|
1923
|
+
enabled: config3?.enabled ?? !!rates,
|
|
1921
1924
|
pretty: config3?.pretty,
|
|
1922
1925
|
...rates && { sampling: { rates } },
|
|
1923
1926
|
...config3?.drain && { drain: config3.drain }
|
|
@@ -1930,7 +1933,11 @@ function safeMessage(args) {
|
|
|
1930
1933
|
var logger = {
|
|
1931
1934
|
debug(...args) {
|
|
1932
1935
|
const log = createRequestLogger();
|
|
1933
|
-
log.set({
|
|
1936
|
+
log.set({
|
|
1937
|
+
level: "debug",
|
|
1938
|
+
source: "@cipherstash/stack",
|
|
1939
|
+
message: safeMessage(args)
|
|
1940
|
+
});
|
|
1934
1941
|
log.emit();
|
|
1935
1942
|
},
|
|
1936
1943
|
info(...args) {
|
|
@@ -1951,16 +1958,16 @@ var logger = {
|
|
|
1951
1958
|
}
|
|
1952
1959
|
};
|
|
1953
1960
|
|
|
1954
|
-
// src/encryption/
|
|
1961
|
+
// src/encryption/index.ts
|
|
1955
1962
|
import { withResult as withResult11 } from "@byteslice/result";
|
|
1956
1963
|
import { newClient } from "@cipherstash/protect-ffi";
|
|
1957
1964
|
|
|
1958
|
-
// src/encryption/
|
|
1965
|
+
// src/encryption/helpers/type-guards.ts
|
|
1959
1966
|
function isScalarQueryTermArray(value) {
|
|
1960
1967
|
return Array.isArray(value) && value.length > 0 && typeof value[0] === "object" && value[0] !== null && "column" in value[0] && "table" in value[0];
|
|
1961
1968
|
}
|
|
1962
1969
|
|
|
1963
|
-
// src/encryption/
|
|
1970
|
+
// src/encryption/helpers/error-code.ts
|
|
1964
1971
|
import {
|
|
1965
1972
|
ProtectError as FfiProtectError
|
|
1966
1973
|
} from "@cipherstash/protect-ffi";
|
|
@@ -1968,7 +1975,7 @@ function getErrorCode(error) {
|
|
|
1968
1975
|
return error instanceof FfiProtectError ? error.code : void 0;
|
|
1969
1976
|
}
|
|
1970
1977
|
|
|
1971
|
-
// src/encryption/
|
|
1978
|
+
// src/encryption/operations/batch-encrypt-query.ts
|
|
1972
1979
|
import { withResult } from "@byteslice/result";
|
|
1973
1980
|
import {
|
|
1974
1981
|
encryptQueryBulk as ffiEncryptQueryBulk
|
|
@@ -1988,7 +1995,7 @@ var queryTypeToQueryOp = {
|
|
|
1988
1995
|
steVecTerm: "ste_vec_term"
|
|
1989
1996
|
};
|
|
1990
1997
|
|
|
1991
|
-
// src/encryption/
|
|
1998
|
+
// src/encryption/helpers/infer-index-type.ts
|
|
1992
1999
|
function inferIndexType(column) {
|
|
1993
2000
|
const config3 = column.build();
|
|
1994
2001
|
const indexes = config3.indexes;
|
|
@@ -2048,7 +2055,7 @@ function resolveIndexType(column, queryType, plaintext) {
|
|
|
2048
2055
|
return { indexType };
|
|
2049
2056
|
}
|
|
2050
2057
|
|
|
2051
|
-
// src/encryption/
|
|
2058
|
+
// src/encryption/helpers/validation.ts
|
|
2052
2059
|
function validateNumericValue(value) {
|
|
2053
2060
|
if (typeof value === "number" && Number.isNaN(value)) {
|
|
2054
2061
|
return {
|
|
@@ -2084,7 +2091,7 @@ function assertValueIndexCompatibility(value, indexType, columnName) {
|
|
|
2084
2091
|
}
|
|
2085
2092
|
}
|
|
2086
2093
|
|
|
2087
|
-
// src/encryption/
|
|
2094
|
+
// src/encryption/operations/base-operation.ts
|
|
2088
2095
|
var EncryptionOperation = class {
|
|
2089
2096
|
auditMetadata;
|
|
2090
2097
|
/**
|
|
@@ -2112,7 +2119,7 @@ var EncryptionOperation = class {
|
|
|
2112
2119
|
}
|
|
2113
2120
|
};
|
|
2114
2121
|
|
|
2115
|
-
// src/encryption/
|
|
2122
|
+
// src/encryption/operations/batch-encrypt-query.ts
|
|
2116
2123
|
function filterNullTerms(terms) {
|
|
2117
2124
|
const nullIndices = /* @__PURE__ */ new Set();
|
|
2118
2125
|
const nonNullTerms = [];
|
|
@@ -2267,7 +2274,7 @@ var BatchEncryptQueryOperationWithLockContext = class extends EncryptionOperatio
|
|
|
2267
2274
|
}
|
|
2268
2275
|
};
|
|
2269
2276
|
|
|
2270
|
-
// src/encryption/
|
|
2277
|
+
// src/encryption/operations/bulk-decrypt.ts
|
|
2271
2278
|
import { withResult as withResult2 } from "@byteslice/result";
|
|
2272
2279
|
import {
|
|
2273
2280
|
decryptBulkFallible
|
|
@@ -2420,10 +2427,10 @@ var BulkDecryptOperationWithLockContext = class extends EncryptionOperation {
|
|
|
2420
2427
|
}
|
|
2421
2428
|
};
|
|
2422
2429
|
|
|
2423
|
-
// src/encryption/
|
|
2430
|
+
// src/encryption/operations/bulk-decrypt-models.ts
|
|
2424
2431
|
import { withResult as withResult3 } from "@byteslice/result";
|
|
2425
2432
|
|
|
2426
|
-
// src/encryption/
|
|
2433
|
+
// src/encryption/helpers/model-helpers.ts
|
|
2427
2434
|
import {
|
|
2428
2435
|
decryptBulk,
|
|
2429
2436
|
encryptBulk
|
|
@@ -2941,7 +2948,7 @@ async function bulkEncryptModelsWithLockContext(models, table, client, lockConte
|
|
|
2941
2948
|
});
|
|
2942
2949
|
}
|
|
2943
2950
|
|
|
2944
|
-
// src/encryption/
|
|
2951
|
+
// src/encryption/operations/bulk-decrypt-models.ts
|
|
2945
2952
|
var BulkDecryptModelsOperation = class extends EncryptionOperation {
|
|
2946
2953
|
client;
|
|
2947
2954
|
models;
|
|
@@ -3038,7 +3045,7 @@ var BulkDecryptModelsOperationWithLockContext = class extends EncryptionOperatio
|
|
|
3038
3045
|
}
|
|
3039
3046
|
};
|
|
3040
3047
|
|
|
3041
|
-
// src/encryption/
|
|
3048
|
+
// src/encryption/operations/bulk-encrypt.ts
|
|
3042
3049
|
import { withResult as withResult4 } from "@byteslice/result";
|
|
3043
3050
|
import { encryptBulk as encryptBulk2 } from "@cipherstash/protect-ffi";
|
|
3044
3051
|
var createEncryptPayloads = (plaintexts, column, table, lockContext) => {
|
|
@@ -3203,7 +3210,7 @@ var BulkEncryptOperationWithLockContext = class extends EncryptionOperation {
|
|
|
3203
3210
|
}
|
|
3204
3211
|
};
|
|
3205
3212
|
|
|
3206
|
-
// src/encryption/
|
|
3213
|
+
// src/encryption/operations/bulk-encrypt-models.ts
|
|
3207
3214
|
import { withResult as withResult5 } from "@byteslice/result";
|
|
3208
3215
|
var BulkEncryptModelsOperation = class extends EncryptionOperation {
|
|
3209
3216
|
client;
|
|
@@ -3312,7 +3319,7 @@ var BulkEncryptModelsOperationWithLockContext = class extends EncryptionOperatio
|
|
|
3312
3319
|
}
|
|
3313
3320
|
};
|
|
3314
3321
|
|
|
3315
|
-
// src/encryption/
|
|
3322
|
+
// src/encryption/operations/decrypt.ts
|
|
3316
3323
|
import { withResult as withResult6 } from "@byteslice/result";
|
|
3317
3324
|
import {
|
|
3318
3325
|
decrypt as ffiDecrypt
|
|
@@ -3421,7 +3428,7 @@ var DecryptOperationWithLockContext = class extends EncryptionOperation {
|
|
|
3421
3428
|
}
|
|
3422
3429
|
};
|
|
3423
3430
|
|
|
3424
|
-
// src/encryption/
|
|
3431
|
+
// src/encryption/operations/decrypt-model.ts
|
|
3425
3432
|
import { withResult as withResult7 } from "@byteslice/result";
|
|
3426
3433
|
var DecryptModelOperation = class extends EncryptionOperation {
|
|
3427
3434
|
client;
|
|
@@ -3517,7 +3524,7 @@ var DecryptModelOperationWithLockContext = class extends EncryptionOperation {
|
|
|
3517
3524
|
}
|
|
3518
3525
|
};
|
|
3519
3526
|
|
|
3520
|
-
// src/encryption/
|
|
3527
|
+
// src/encryption/operations/encrypt.ts
|
|
3521
3528
|
import { withResult as withResult8 } from "@byteslice/result";
|
|
3522
3529
|
import {
|
|
3523
3530
|
encrypt as ffiEncrypt
|
|
@@ -3645,7 +3652,7 @@ var EncryptOperationWithLockContext = class extends EncryptionOperation {
|
|
|
3645
3652
|
}
|
|
3646
3653
|
};
|
|
3647
3654
|
|
|
3648
|
-
// src/encryption/
|
|
3655
|
+
// src/encryption/operations/encrypt-model.ts
|
|
3649
3656
|
import { withResult as withResult9 } from "@byteslice/result";
|
|
3650
3657
|
var EncryptModelOperation = class extends EncryptionOperation {
|
|
3651
3658
|
client;
|
|
@@ -3752,7 +3759,7 @@ var EncryptModelOperationWithLockContext = class extends EncryptionOperation {
|
|
|
3752
3759
|
}
|
|
3753
3760
|
};
|
|
3754
3761
|
|
|
3755
|
-
// src/encryption/
|
|
3762
|
+
// src/encryption/operations/encrypt-query.ts
|
|
3756
3763
|
import { withResult as withResult10 } from "@byteslice/result";
|
|
3757
3764
|
import {
|
|
3758
3765
|
encryptQuery as ffiEncryptQuery
|
|
@@ -3904,9 +3911,9 @@ var EncryptQueryOperationWithLockContext = class extends EncryptionOperation {
|
|
|
3904
3911
|
}
|
|
3905
3912
|
};
|
|
3906
3913
|
|
|
3907
|
-
// src/encryption/
|
|
3914
|
+
// src/encryption/index.ts
|
|
3908
3915
|
var noClientError = () => new Error(
|
|
3909
|
-
"The
|
|
3916
|
+
"The Encryption client has not been initialized. Please call init() before using the client."
|
|
3910
3917
|
);
|
|
3911
3918
|
var EncryptionClient = class {
|
|
3912
3919
|
client;
|
|
@@ -3929,7 +3936,7 @@ var EncryptionClient = class {
|
|
|
3929
3936
|
config3.encryptConfig
|
|
3930
3937
|
);
|
|
3931
3938
|
logger.debug(
|
|
3932
|
-
"Initializing the
|
|
3939
|
+
"Initializing the Encryption client with the following config:",
|
|
3933
3940
|
{
|
|
3934
3941
|
encryptConfig: validated
|
|
3935
3942
|
}
|
|
@@ -3937,15 +3944,15 @@ var EncryptionClient = class {
|
|
|
3937
3944
|
this.client = await newClient({
|
|
3938
3945
|
encryptConfig: validated,
|
|
3939
3946
|
clientOpts: {
|
|
3940
|
-
workspaceCrn: config3.workspaceCrn,
|
|
3941
|
-
accessKey: config3.accessKey,
|
|
3942
|
-
clientId: config3.clientId,
|
|
3943
|
-
clientKey: config3.clientKey,
|
|
3947
|
+
workspaceCrn: config3.workspaceCrn ?? process.env.CS_WORKSPACE_CRN,
|
|
3948
|
+
accessKey: config3.accessKey ?? process.env.CS_CLIENT_ACCESS_KEY,
|
|
3949
|
+
clientId: config3.clientId ?? process.env.CS_CLIENT_ID,
|
|
3950
|
+
clientKey: config3.clientKey ?? process.env.CS_CLIENT_KEY,
|
|
3944
3951
|
keyset: toFfiKeysetIdentifier(config3.keyset)
|
|
3945
3952
|
}
|
|
3946
3953
|
});
|
|
3947
3954
|
this.encryptConfig = validated;
|
|
3948
|
-
logger.debug("Successfully initialized the
|
|
3955
|
+
logger.debug("Successfully initialized the Encryption client.");
|
|
3949
3956
|
return this;
|
|
3950
3957
|
},
|
|
3951
3958
|
(error) => ({
|
|
@@ -3958,7 +3965,7 @@ var EncryptionClient = class {
|
|
|
3958
3965
|
* Encrypt a value - returns a promise which resolves to an encrypted value.
|
|
3959
3966
|
*
|
|
3960
3967
|
* @param plaintext - The plaintext value to be encrypted. Can be null.
|
|
3961
|
-
* @param opts - Options specifying the column and table for encryption.
|
|
3968
|
+
* @param opts - Options specifying the column (or nested field) and table for encryption. See {@link EncryptOptions}.
|
|
3962
3969
|
* @returns An EncryptOperation that can be awaited or chained with additional methods.
|
|
3963
3970
|
*
|
|
3964
3971
|
* @example
|
|
@@ -4021,8 +4028,11 @@ var EncryptionClient = class {
|
|
|
4021
4028
|
* .withLockContext(lockContext)
|
|
4022
4029
|
* ```
|
|
4023
4030
|
*
|
|
4031
|
+
* @see {@link EncryptOptions}
|
|
4024
4032
|
* @see {@link Result}
|
|
4025
4033
|
* @see {@link encryptedTable}
|
|
4034
|
+
* @see {@link encryptedColumn}
|
|
4035
|
+
* @see {@link encryptedField}
|
|
4026
4036
|
* @see {@link LockContext}
|
|
4027
4037
|
* @see {@link EncryptOperation}
|
|
4028
4038
|
*/
|
|
@@ -4090,10 +4100,16 @@ var EncryptionClient = class {
|
|
|
4090
4100
|
* All other fields are passed through unchanged. Returns a thenable operation
|
|
4091
4101
|
* that supports `.withLockContext()` for identity-aware encryption.
|
|
4092
4102
|
*
|
|
4103
|
+
* The return type is **schema-aware**: fields matching the table schema are
|
|
4104
|
+
* typed as `Encrypted`, while other fields retain their original types. For
|
|
4105
|
+
* best results, let TypeScript infer the type parameters from the arguments
|
|
4106
|
+
* rather than providing an explicit type argument.
|
|
4107
|
+
*
|
|
4093
4108
|
* @param input - The model object with plaintext values to encrypt.
|
|
4094
4109
|
* @param table - The table schema defining which fields to encrypt.
|
|
4095
|
-
* @returns An `EncryptModelOperation
|
|
4096
|
-
* containing the model with
|
|
4110
|
+
* @returns An `EncryptModelOperation` that can be awaited to get a `Result`
|
|
4111
|
+
* containing the model with schema-defined fields typed as `Encrypted`,
|
|
4112
|
+
* or an `EncryptionError`.
|
|
4097
4113
|
*
|
|
4098
4114
|
* @example
|
|
4099
4115
|
* ```typescript
|
|
@@ -4108,7 +4124,9 @@ var EncryptionClient = class {
|
|
|
4108
4124
|
*
|
|
4109
4125
|
* const client = await Encryption({ schemas: [usersSchema] })
|
|
4110
4126
|
*
|
|
4111
|
-
*
|
|
4127
|
+
* // Let TypeScript infer the return type from the schema.
|
|
4128
|
+
* // result.data.email is typed as `Encrypted`, result.data.id stays `string`.
|
|
4129
|
+
* const result = await client.encryptModel(
|
|
4112
4130
|
* { id: "user_123", email: "alice@example.com", createdAt: new Date() },
|
|
4113
4131
|
* usersSchema,
|
|
4114
4132
|
* )
|
|
@@ -4116,13 +4134,17 @@ var EncryptionClient = class {
|
|
|
4116
4134
|
* if (result.failure) {
|
|
4117
4135
|
* console.error(result.failure.message)
|
|
4118
4136
|
* } else {
|
|
4119
|
-
*
|
|
4120
|
-
* console.log(result.data)
|
|
4137
|
+
* console.log(result.data.id) // string
|
|
4138
|
+
* console.log(result.data.email) // Encrypted
|
|
4121
4139
|
* }
|
|
4122
4140
|
* ```
|
|
4123
4141
|
*/
|
|
4124
4142
|
encryptModel(input, table) {
|
|
4125
|
-
return new EncryptModelOperation(
|
|
4143
|
+
return new EncryptModelOperation(
|
|
4144
|
+
this.client,
|
|
4145
|
+
input,
|
|
4146
|
+
table
|
|
4147
|
+
);
|
|
4126
4148
|
}
|
|
4127
4149
|
/**
|
|
4128
4150
|
* Decrypt a model (object) whose fields contain encrypted values.
|
|
@@ -4162,10 +4184,15 @@ var EncryptionClient = class {
|
|
|
4162
4184
|
* while still using a unique key for each encrypted value. Only fields
|
|
4163
4185
|
* matching the table schema are encrypted; other fields pass through unchanged.
|
|
4164
4186
|
*
|
|
4187
|
+
* The return type is **schema-aware**: fields matching the table schema are
|
|
4188
|
+
* typed as `Encrypted`, while other fields retain their original types. For
|
|
4189
|
+
* best results, let TypeScript infer the type parameters from the arguments.
|
|
4190
|
+
*
|
|
4165
4191
|
* @param input - An array of model objects with plaintext values to encrypt.
|
|
4166
4192
|
* @param table - The table schema defining which fields to encrypt.
|
|
4167
|
-
* @returns A `BulkEncryptModelsOperation
|
|
4168
|
-
* containing an array of models with
|
|
4193
|
+
* @returns A `BulkEncryptModelsOperation` that can be awaited to get a `Result`
|
|
4194
|
+
* containing an array of models with schema-defined fields typed as `Encrypted`,
|
|
4195
|
+
* or an `EncryptionError`.
|
|
4169
4196
|
*
|
|
4170
4197
|
* @example
|
|
4171
4198
|
* ```typescript
|
|
@@ -4180,7 +4207,9 @@ var EncryptionClient = class {
|
|
|
4180
4207
|
*
|
|
4181
4208
|
* const client = await Encryption({ schemas: [usersSchema] })
|
|
4182
4209
|
*
|
|
4183
|
-
*
|
|
4210
|
+
* // Let TypeScript infer the return type from the schema.
|
|
4211
|
+
* // Each item's email is typed as `Encrypted`, id stays `string`.
|
|
4212
|
+
* const result = await client.bulkEncryptModels(
|
|
4184
4213
|
* [
|
|
4185
4214
|
* { id: "1", email: "alice@example.com" },
|
|
4186
4215
|
* { id: "2", email: "bob@example.com" },
|
|
@@ -4194,7 +4223,11 @@ var EncryptionClient = class {
|
|
|
4194
4223
|
* ```
|
|
4195
4224
|
*/
|
|
4196
4225
|
bulkEncryptModels(input, table) {
|
|
4197
|
-
return new BulkEncryptModelsOperation(
|
|
4226
|
+
return new BulkEncryptModelsOperation(
|
|
4227
|
+
this.client,
|
|
4228
|
+
input,
|
|
4229
|
+
table
|
|
4230
|
+
);
|
|
4198
4231
|
}
|
|
4199
4232
|
/**
|
|
4200
4233
|
* Decrypt multiple models (objects) in a single bulk operation.
|
|
@@ -4235,7 +4268,7 @@ var EncryptionClient = class {
|
|
|
4235
4268
|
* your application data. Null plaintext values are preserved as null.
|
|
4236
4269
|
*
|
|
4237
4270
|
* @param plaintexts - An array of objects with `plaintext` (and optional `id`) fields.
|
|
4238
|
-
* @param opts - Options specifying the target column and table
|
|
4271
|
+
* @param opts - Options specifying the target column (or nested {@link encryptedField}) and table. See {@link EncryptOptions}.
|
|
4239
4272
|
* @returns A `BulkEncryptOperation` that can be awaited to get a `Result`
|
|
4240
4273
|
* containing an array of `{ id?, data: Encrypted }` objects, or an `EncryptionError`.
|
|
4241
4274
|
*
|