@cipherstash/stack 0.3.0 → 0.5.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 +19 -0
- package/README.md +10 -37
- package/dist/bin/stash.js +261 -320
- 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-OAPLZLR5.js → chunk-GXGEW6T4.js} +2 -76
- package/dist/chunk-GXGEW6T4.js.map +1 -0
- package/dist/{chunk-JLI27P46.js → chunk-HCL75LXQ.js} +1 -1
- package/dist/chunk-HCL75LXQ.js.map +1 -0
- package/dist/chunk-LBMC4D6D.js +19 -0
- package/dist/chunk-LBMC4D6D.js.map +1 -0
- package/dist/chunk-Q5FTQLYG.js +68 -0
- package/dist/chunk-Q5FTQLYG.js.map +1 -0
- package/dist/{chunk-MW6D52V2.js → chunk-TGUELLJS.js} +58 -150
- package/dist/chunk-TGUELLJS.js.map +1 -0
- package/dist/{chunk-TBAIVO6T.js → chunk-Y35W4WFN.js} +6 -6
- package/dist/chunk-Y35W4WFN.js.map +1 -0
- package/dist/chunk-YLISU7FD.js +357 -0
- package/dist/chunk-YLISU7FD.js.map +1 -0
- package/dist/{client-Bf0Xw2xo.d.cts → client-BFrHTgC6.d.ts} +50 -18
- package/dist/{client-Kfp8OsPB.d.ts → client-BVQvgvdY.d.cts} +50 -18
- package/dist/client.cjs +5 -5
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +4 -4
- package/dist/client.d.ts +4 -4
- 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 +14 -6
- package/dist/drizzle/index.d.ts +14 -6
- package/dist/drizzle/index.js +4 -4
- package/dist/drizzle/index.js.map +1 -1
- package/dist/dynamodb/index.cjs +68 -0
- package/dist/dynamodb/index.cjs.map +1 -1
- package/dist/dynamodb/index.d.cts +4 -4
- package/dist/dynamodb/index.d.ts +4 -4
- package/dist/dynamodb/index.js +9 -0
- package/dist/dynamodb/index.js.map +1 -1
- package/dist/encryption/index.cjs +2572 -0
- package/dist/encryption/index.cjs.map +1 -0
- package/dist/encryption/index.d.cts +7 -0
- package/dist/encryption/index.d.ts +7 -0
- package/dist/encryption/index.js +17 -0
- package/dist/encryption/index.js.map +1 -0
- package/dist/errors/index.cjs +44 -0
- package/dist/errors/index.cjs.map +1 -0
- package/dist/errors/index.d.cts +94 -0
- package/dist/errors/index.d.ts +94 -0
- package/dist/errors/index.js +9 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/identity/index.cjs +21 -13
- package/dist/identity/index.cjs.map +1 -1
- package/dist/identity/index.d.cts +78 -2
- package/dist/identity/index.d.ts +78 -2
- package/dist/identity/index.js +7 -3
- package/dist/identity/index.js.map +1 -1
- package/dist/index.cjs +425 -182
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -19
- package/dist/index.d.ts +21 -19
- package/dist/index.js +15 -9
- package/dist/schema/index.cjs +5 -5
- package/dist/schema/index.cjs.map +1 -1
- package/dist/schema/index.d.cts +1 -2
- package/dist/schema/index.d.ts +1 -2
- package/dist/schema/index.js +1 -1
- package/dist/secrets/index.cjs +116 -180
- package/dist/secrets/index.cjs.map +1 -1
- package/dist/secrets/index.d.cts +4 -6
- package/dist/secrets/index.d.ts +4 -6
- package/dist/secrets/index.js +9 -318
- package/dist/secrets/index.js.map +1 -1
- package/dist/supabase/index.cjs +86 -3
- package/dist/supabase/index.cjs.map +1 -1
- package/dist/supabase/index.d.cts +4 -4
- package/dist/supabase/index.d.ts +4 -4
- package/dist/supabase/index.js +26 -3
- package/dist/supabase/index.js.map +1 -1
- package/dist/{types-public-0CzBV45X.d.cts → types-public-dKxDzTIL.d.cts} +47 -34
- package/dist/{types-public-0CzBV45X.d.ts → types-public-dKxDzTIL.d.ts} +47 -34
- package/dist/types-public.cjs.map +1 -1
- package/dist/types-public.d.cts +1 -2
- package/dist/types-public.d.ts +1 -2
- package/dist/types-public.js +1 -1
- package/package.json +30 -2
- package/dist/chunk-JLI27P46.js.map +0 -1
- package/dist/chunk-MW6D52V2.js.map +0 -1
- package/dist/chunk-OAPLZLR5.js.map +0 -1
- package/dist/chunk-SUYMGQBY.js.map +0 -1
- package/dist/chunk-TBAIVO6T.js.map +0 -1
- package/dist/index-9-Ya3fDK.d.cts +0 -169
- package/dist/index-9-Ya3fDK.d.ts +0 -169
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { LoggerConfig } from 'evlog';
|
|
3
2
|
import { Encrypted as Encrypted$1, newClient, JsPlaintext } from '@cipherstash/protect-ffi';
|
|
4
3
|
|
|
5
|
-
type LoggingConfig = {
|
|
6
|
-
enabled?: boolean;
|
|
7
|
-
pretty?: boolean;
|
|
8
|
-
drain?: LoggerConfig['drain'];
|
|
9
|
-
};
|
|
10
|
-
|
|
11
4
|
/** Brand symbol for nominal typing */
|
|
12
5
|
declare const __brand: unique symbol;
|
|
13
6
|
/** Creates a branded type that is structurally incompatible with the base type */
|
|
@@ -16,10 +9,9 @@ type Brand<T, B extends string> = T & {
|
|
|
16
9
|
};
|
|
17
10
|
type Client = Awaited<ReturnType<typeof newClient>> | undefined;
|
|
18
11
|
/** A branded type representing encrypted data. Cannot be accidentally used as plaintext. */
|
|
19
|
-
type EncryptedValue = Brand<Encrypted$1, 'encrypted'
|
|
12
|
+
type EncryptedValue = Brand<Encrypted$1, 'encrypted'>;
|
|
20
13
|
/** Structural type representing encrypted data. See also `EncryptedValue` for branded nominal typing. */
|
|
21
|
-
type Encrypted = Encrypted$1
|
|
22
|
-
type EncryptPayload = JsPlaintext | null;
|
|
14
|
+
type Encrypted = Encrypted$1;
|
|
23
15
|
type KeysetIdentifier = {
|
|
24
16
|
name: string;
|
|
25
17
|
} | {
|
|
@@ -63,7 +55,6 @@ type AtLeastOneCsTable<T> = [T, ...T[]];
|
|
|
63
55
|
type EncryptionClientConfig = {
|
|
64
56
|
schemas: AtLeastOneCsTable<EncryptedTable<EncryptedTableColumn>>;
|
|
65
57
|
config?: ClientConfig;
|
|
66
|
-
logging?: LoggingConfig;
|
|
67
58
|
};
|
|
68
59
|
/**
|
|
69
60
|
* Options for single-value encrypt operations.
|
|
@@ -85,16 +76,16 @@ type SearchTerm = {
|
|
|
85
76
|
};
|
|
86
77
|
/** Encrypted search term result: EQL object or composite literal string */
|
|
87
78
|
type EncryptedSearchTerm = Encrypted | string;
|
|
88
|
-
/** Result of encryptQuery (single or batch): EQL
|
|
89
|
-
type EncryptedQueryResult = Encrypted | string
|
|
79
|
+
/** Result of encryptQuery (single or batch): EQL or composite literal string */
|
|
80
|
+
type EncryptedQueryResult = Encrypted | string;
|
|
90
81
|
type EncryptedFields<T> = {
|
|
91
|
-
[K in keyof T as T[K] extends Encrypted ? K : never]: T[K];
|
|
82
|
+
[K in keyof T as NonNullable<T[K]> extends Encrypted ? K : never]: T[K];
|
|
92
83
|
};
|
|
93
84
|
type OtherFields<T> = {
|
|
94
|
-
[K in keyof T as T[K] extends Encrypted ? never : K]: T[K];
|
|
85
|
+
[K in keyof T as NonNullable<T[K]> extends Encrypted ? never : K]: T[K];
|
|
95
86
|
};
|
|
96
87
|
type DecryptedFields<T> = {
|
|
97
|
-
[K in keyof T as T[K] extends Encrypted ? K : never]: string;
|
|
88
|
+
[K in keyof T as NonNullable<T[K]> extends Encrypted ? K : never]: null extends T[K] ? string | null : string;
|
|
98
89
|
};
|
|
99
90
|
/** Model with encrypted fields replaced by plaintext (decrypted) values */
|
|
100
91
|
type Decrypted<T> = OtherFields<T> & DecryptedFields<T>;
|
|
@@ -120,11 +111,11 @@ type Decrypted<T> = OtherFields<T> & DecryptedFields<T>;
|
|
|
120
111
|
* ```
|
|
121
112
|
*/
|
|
122
113
|
type EncryptedFromSchema<T, S extends EncryptedTableColumn> = {
|
|
123
|
-
[K in keyof T]: [K] extends [keyof S] ? [S[K & keyof S]] extends [EncryptedColumn | EncryptedField] ? Encrypted : T[K] : T[K];
|
|
114
|
+
[K in keyof T]: [K] extends [keyof S] ? [S[K & keyof S]] extends [EncryptedColumn | EncryptedField] ? null extends T[K] ? Encrypted | null : Encrypted : T[K] : T[K];
|
|
124
115
|
};
|
|
125
116
|
type BulkEncryptPayload = Array<{
|
|
126
117
|
id?: string;
|
|
127
|
-
plaintext: JsPlaintext
|
|
118
|
+
plaintext: JsPlaintext;
|
|
128
119
|
}>;
|
|
129
120
|
type BulkEncryptedData = Array<{
|
|
130
121
|
id?: string;
|
|
@@ -134,7 +125,7 @@ type BulkDecryptPayload = Array<{
|
|
|
134
125
|
id?: string;
|
|
135
126
|
data: Encrypted;
|
|
136
127
|
}>;
|
|
137
|
-
type BulkDecryptedData = Array<DecryptionResult<JsPlaintext
|
|
128
|
+
type BulkDecryptedData = Array<DecryptionResult<JsPlaintext>>;
|
|
138
129
|
type DecryptionSuccess<T> = {
|
|
139
130
|
error?: never;
|
|
140
131
|
data: T;
|
|
@@ -179,7 +170,7 @@ type QueryTermBase = {
|
|
|
179
170
|
};
|
|
180
171
|
type EncryptQueryOptions = QueryTermBase;
|
|
181
172
|
type ScalarQueryTerm = QueryTermBase & {
|
|
182
|
-
value: JsPlaintext
|
|
173
|
+
value: JsPlaintext;
|
|
183
174
|
};
|
|
184
175
|
|
|
185
176
|
/**
|
|
@@ -192,6 +183,7 @@ type ScalarQueryTerm = QueryTermBase & {
|
|
|
192
183
|
* - `"number"`
|
|
193
184
|
* - `"string"`
|
|
194
185
|
* - `"json"`
|
|
186
|
+
* - `"text"`
|
|
195
187
|
*
|
|
196
188
|
* @remarks
|
|
197
189
|
* This is a Zod enum used at runtime to validate schema definitions.
|
|
@@ -199,7 +191,7 @@ type ScalarQueryTerm = QueryTermBase & {
|
|
|
199
191
|
*
|
|
200
192
|
* @internal
|
|
201
193
|
*/
|
|
202
|
-
declare const castAsEnum: z.ZodDefault<z.ZodEnum<["bigint", "boolean", "date", "number", "string", "json"]>>;
|
|
194
|
+
declare const castAsEnum: z.ZodDefault<z.ZodEnum<["bigint", "boolean", "date", "number", "string", "json", "text"]>>;
|
|
203
195
|
declare const tokenFilterSchema: z.ZodObject<{
|
|
204
196
|
kind: z.ZodLiteral<"downcase">;
|
|
205
197
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -287,7 +279,7 @@ declare const steVecIndexOptsSchema: z.ZodObject<{
|
|
|
287
279
|
prefix: string;
|
|
288
280
|
}>;
|
|
289
281
|
declare const columnSchema: z.ZodDefault<z.ZodObject<{
|
|
290
|
-
cast_as: z.ZodDefault<z.ZodEnum<["bigint", "boolean", "date", "number", "string", "json"]>>;
|
|
282
|
+
cast_as: z.ZodDefault<z.ZodEnum<["bigint", "boolean", "date", "number", "string", "json", "text"]>>;
|
|
291
283
|
indexes: z.ZodDefault<z.ZodObject<{
|
|
292
284
|
ore: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>;
|
|
293
285
|
unique: z.ZodOptional<z.ZodObject<{
|
|
@@ -418,7 +410,7 @@ declare const columnSchema: z.ZodDefault<z.ZodObject<{
|
|
|
418
410
|
} | undefined;
|
|
419
411
|
}>>;
|
|
420
412
|
}, "strip", z.ZodTypeAny, {
|
|
421
|
-
cast_as: "string" | "number" | "bigint" | "boolean" | "date" | "json";
|
|
413
|
+
cast_as: "string" | "number" | "bigint" | "boolean" | "date" | "json" | "text";
|
|
422
414
|
indexes: {
|
|
423
415
|
match?: {
|
|
424
416
|
token_filters?: {
|
|
@@ -445,7 +437,7 @@ declare const columnSchema: z.ZodDefault<z.ZodObject<{
|
|
|
445
437
|
} | undefined;
|
|
446
438
|
};
|
|
447
439
|
}, {
|
|
448
|
-
cast_as?: "string" | "number" | "bigint" | "boolean" | "date" | "json" | undefined;
|
|
440
|
+
cast_as?: "string" | "number" | "bigint" | "boolean" | "date" | "json" | "text" | undefined;
|
|
449
441
|
indexes?: {
|
|
450
442
|
match?: {
|
|
451
443
|
token_filters?: {
|
|
@@ -476,7 +468,7 @@ declare const columnSchema: z.ZodDefault<z.ZodObject<{
|
|
|
476
468
|
declare const encryptConfigSchema: z.ZodObject<{
|
|
477
469
|
v: z.ZodNumber;
|
|
478
470
|
tables: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodDefault<z.ZodObject<{
|
|
479
|
-
cast_as: z.ZodDefault<z.ZodEnum<["bigint", "boolean", "date", "number", "string", "json"]>>;
|
|
471
|
+
cast_as: z.ZodDefault<z.ZodEnum<["bigint", "boolean", "date", "number", "string", "json", "text"]>>;
|
|
480
472
|
indexes: z.ZodDefault<z.ZodObject<{
|
|
481
473
|
ore: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>;
|
|
482
474
|
unique: z.ZodOptional<z.ZodObject<{
|
|
@@ -607,7 +599,7 @@ declare const encryptConfigSchema: z.ZodObject<{
|
|
|
607
599
|
} | undefined;
|
|
608
600
|
}>>;
|
|
609
601
|
}, "strip", z.ZodTypeAny, {
|
|
610
|
-
cast_as: "string" | "number" | "bigint" | "boolean" | "date" | "json";
|
|
602
|
+
cast_as: "string" | "number" | "bigint" | "boolean" | "date" | "json" | "text";
|
|
611
603
|
indexes: {
|
|
612
604
|
match?: {
|
|
613
605
|
token_filters?: {
|
|
@@ -634,7 +626,7 @@ declare const encryptConfigSchema: z.ZodObject<{
|
|
|
634
626
|
} | undefined;
|
|
635
627
|
};
|
|
636
628
|
}, {
|
|
637
|
-
cast_as?: "string" | "number" | "bigint" | "boolean" | "date" | "json" | undefined;
|
|
629
|
+
cast_as?: "string" | "number" | "bigint" | "boolean" | "date" | "json" | "text" | undefined;
|
|
638
630
|
indexes?: {
|
|
639
631
|
match?: {
|
|
640
632
|
token_filters?: {
|
|
@@ -664,7 +656,7 @@ declare const encryptConfigSchema: z.ZodObject<{
|
|
|
664
656
|
}, "strip", z.ZodTypeAny, {
|
|
665
657
|
v: number;
|
|
666
658
|
tables: Record<string, Record<string, {
|
|
667
|
-
cast_as: "string" | "number" | "bigint" | "boolean" | "date" | "json";
|
|
659
|
+
cast_as: "string" | "number" | "bigint" | "boolean" | "date" | "json" | "text";
|
|
668
660
|
indexes: {
|
|
669
661
|
match?: {
|
|
670
662
|
token_filters?: {
|
|
@@ -694,7 +686,7 @@ declare const encryptConfigSchema: z.ZodObject<{
|
|
|
694
686
|
}, {
|
|
695
687
|
v: number;
|
|
696
688
|
tables?: Record<string, Record<string, {
|
|
697
|
-
cast_as?: "string" | "number" | "bigint" | "boolean" | "date" | "json" | undefined;
|
|
689
|
+
cast_as?: "string" | "number" | "bigint" | "boolean" | "date" | "json" | "text" | undefined;
|
|
698
690
|
indexes?: {
|
|
699
691
|
match?: {
|
|
700
692
|
token_filters?: {
|
|
@@ -765,7 +757,7 @@ declare class EncryptedField {
|
|
|
765
757
|
* a different type so the encryption layer knows how to encode the plaintext
|
|
766
758
|
* before encrypting.
|
|
767
759
|
*
|
|
768
|
-
* @param castAs - The plaintext data type: `'string'`, `'number'`, `'boolean'`, `'date'`, `'bigint'`, or `'json'`.
|
|
760
|
+
* @param castAs - The plaintext data type: `'string'`, `'number'`, `'boolean'`, `'date'`, `'text'`, `'bigint'`, or `'json'`.
|
|
769
761
|
* @returns This `EncryptedField` instance for method chaining.
|
|
770
762
|
*
|
|
771
763
|
* @example
|
|
@@ -777,7 +769,7 @@ declare class EncryptedField {
|
|
|
777
769
|
*/
|
|
778
770
|
dataType(castAs: CastAs): this;
|
|
779
771
|
build(): {
|
|
780
|
-
cast_as: "
|
|
772
|
+
cast_as: "number" | "bigint" | "boolean" | "date" | "json" | "text";
|
|
781
773
|
indexes: {};
|
|
782
774
|
};
|
|
783
775
|
getName(): string;
|
|
@@ -896,7 +888,7 @@ declare class EncryptedColumn {
|
|
|
896
888
|
*/
|
|
897
889
|
searchableJson(): this;
|
|
898
890
|
build(): {
|
|
899
|
-
cast_as: "
|
|
891
|
+
cast_as: "number" | "bigint" | "boolean" | "date" | "json" | "text";
|
|
900
892
|
indexes: {
|
|
901
893
|
ore?: OreIndexOpts;
|
|
902
894
|
unique?: UniqueIndexOpts;
|
|
@@ -1049,7 +1041,28 @@ declare function encryptedColumn(columnName: string): EncryptedColumn;
|
|
|
1049
1041
|
* ```
|
|
1050
1042
|
*/
|
|
1051
1043
|
declare function encryptedField(valueName: string): EncryptedField;
|
|
1052
|
-
/**
|
|
1044
|
+
/**
|
|
1045
|
+
* Build an encrypt config from a list of encrypted tables.
|
|
1046
|
+
*
|
|
1047
|
+
* @param ...tables - The list of encrypted tables to build the config from.
|
|
1048
|
+
* @returns An encrypt config object.
|
|
1049
|
+
*
|
|
1050
|
+
* @example
|
|
1051
|
+
* ```typescript
|
|
1052
|
+
* import { buildEncryptConfig } from "@cipherstash/stack/schema"
|
|
1053
|
+
*
|
|
1054
|
+
* const users = encryptedTable("users", {
|
|
1055
|
+
* email: encryptedColumn("email").equality(),
|
|
1056
|
+
* })
|
|
1057
|
+
*
|
|
1058
|
+
* const orders = encryptedTable("orders", {
|
|
1059
|
+
* amount: encryptedColumn("amount").dataType("number"),
|
|
1060
|
+
* })
|
|
1061
|
+
*
|
|
1062
|
+
* const config = buildEncryptConfig(users, orders)
|
|
1063
|
+
* console.log(config)
|
|
1064
|
+
* ```
|
|
1065
|
+
*/
|
|
1053
1066
|
declare function buildEncryptConfig(...protectTables: Array<EncryptedTable<EncryptedTableColumn>>): EncryptConfig;
|
|
1054
1067
|
|
|
1055
|
-
export { type
|
|
1068
|
+
export { type SearchTerm as A, type BulkDecryptedData as B, type CastAs as C, type Decrypted as D, type Encrypted as E, type EncryptedSearchTerm as F, type EncryptedFields as G, type OtherFields as H, type InferPlaintext as I, type DecryptedFields as J, type KeysetIdentifier as K, type DecryptionResult as L, type MatchIndexOpts as M, queryTypes as N, type OreIndexOpts as O, type QueryTypeName as Q, type ScalarQueryTerm as S, type TokenFilter as T, type UniqueIndexOpts as U, encryptedColumn as a, encryptedField as b, EncryptedTable as c, type EncryptedTableColumn as d, encryptedTable as e, EncryptedColumn as f, type EncryptedValue as g, type EncryptedQueryResult as h, type Client as i, type BulkDecryptPayload as j, type BulkEncryptedData as k, type BulkEncryptPayload as l, type EncryptOptions as m, EncryptedField as n, type EncryptQueryOptions as o, type EncryptedReturnType as p, type EncryptConfig as q, type EncryptedFromSchema as r, type EncryptionClientConfig as s, type InferEncrypted as t, castAsEnum as u, encryptConfigSchema as v, type SteVecIndexOpts as w, type ColumnSchema as x, buildEncryptConfig as y, type ClientConfig as z };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types-public.ts","../src/types.ts"],"sourcesContent":["/**\n * Public type re-exports for `@cipherstash/stack/types`.\n *\n * This module exposes only the public types from the internal types module.\n * Internal helpers (`queryTypeToFfi`, `queryTypeToQueryOp`, `FfiIndexTypeName`,\n * `QueryTermBase`) are excluded.\n */\n\n// Core types\nexport type {\n Client,\n EncryptedValue,\n Encrypted,\n EncryptPayload,\n} from '@/types'\n\n// Client configuration\nexport type {\n KeysetIdentifier,\n ClientConfig,\n EncryptionClientConfig,\n} from '@/types'\n\n// Encrypt / decrypt operation options and results\nexport type {\n EncryptOptions,\n EncryptedReturnType,\n SearchTerm,\n EncryptedSearchTerm,\n EncryptedQueryResult,\n} from '@/types'\n\n// Model field types\nexport type {\n EncryptedFields,\n OtherFields,\n DecryptedFields,\n Decrypted,\n} from '@/types'\n\n// Bulk operations\nexport type {\n BulkEncryptPayload,\n BulkEncryptedData,\n BulkDecryptPayload,\n BulkDecryptedData,\n DecryptionResult,\n} from '@/types'\n\n// Query types (public only)\nexport type {\n QueryTypeName,\n EncryptQueryOptions,\n ScalarQueryTerm,\n} from '@/types'\n\n// Logging\nexport type { LoggingConfig } from '@/utils/logger'\n\n// Runtime values\nexport { queryTypes } from '@/types'\n","import type {\n EncryptedColumn,\n EncryptedTable,\n EncryptedTableColumn,\n EncryptedField,\n} from '@/schema'\nimport type { LoggingConfig } from '@/utils/logger'\nimport type {\n Encrypted as CipherStashEncrypted,\n JsPlaintext,\n QueryOpName,\n newClient,\n} from '@cipherstash/protect-ffi'\n\n// ---------------------------------------------------------------------------\n// Branded type utilities\n// ---------------------------------------------------------------------------\n\n/** Brand symbol for nominal typing */\ndeclare const __brand: unique symbol\n\n/** Creates a branded type that is structurally incompatible with the base type */\ntype Brand<T, B extends string> = T & { readonly [__brand]: B }\n\n// ---------------------------------------------------------------------------\n// Core types\n// ---------------------------------------------------------------------------\n\nexport type Client = Awaited<ReturnType<typeof newClient>> | undefined\n\n/** A branded type representing encrypted data. Cannot be accidentally used as plaintext. */\nexport type EncryptedValue = Brand<CipherStashEncrypted, 'encrypted'> | null\n\n/** Structural type representing encrypted data. See also `EncryptedValue` for branded nominal typing. */\nexport type Encrypted = CipherStashEncrypted | null\n\nexport type EncryptPayload = JsPlaintext | null\n\n// ---------------------------------------------------------------------------\n// Client configuration\n// ---------------------------------------------------------------------------\n\nexport type KeysetIdentifier = { name: string } | { id: string }\n\nexport type ClientConfig = {\n /**\n * The CipherStash workspace CRN (Cloud Resource Name).\n * Format: `crn:<region>.aws:<workspace-id>`.\n * Can also be set via the `CS_WORKSPACE_CRN` environment variable.\n * If omitted, the SDK reads from the environment or TOML config files.\n */\n workspaceCrn?: string\n\n /**\n * The API access key used for authenticating with the CipherStash API.\n * Can also be set via the `CS_CLIENT_ACCESS_KEY` environment variable.\n * Obtain this from the CipherStash dashboard after creating a workspace.\n */\n accessKey?: string\n\n /**\n * The client identifier used to authenticate with CipherStash services.\n * Can also be set via the `CS_CLIENT_ID` environment variable.\n * Generated during workspace onboarding in the CipherStash dashboard.\n */\n clientId?: string\n\n /**\n * The client key material used in combination with ZeroKMS for encryption operations.\n * Can also be set via the `CS_CLIENT_KEY` environment variable.\n * Generated during workspace onboarding in the CipherStash dashboard.\n */\n clientKey?: string\n\n /**\n * An optional keyset identifier for multi-tenant encryption.\n * Each keyset provides cryptographic isolation, giving each tenant its own keyspace.\n * Specify by name (`{ name: \"tenant-a\" }`) or UUID (`{ id: \"...\" }`).\n * Keysets are created and managed in the CipherStash dashboard.\n */\n keyset?: KeysetIdentifier\n}\n\ntype AtLeastOneCsTable<T> = [T, ...T[]]\n\nexport type EncryptionClientConfig = {\n schemas: AtLeastOneCsTable<EncryptedTable<EncryptedTableColumn>>\n config?: ClientConfig\n logging?: LoggingConfig\n}\n\n// ---------------------------------------------------------------------------\n// Encrypt / decrypt operation options and results\n// ---------------------------------------------------------------------------\n\n/**\n * Options for single-value encrypt operations.\n * Use a column from your table schema (from {@link encryptedColumn}) or a nested\n * field (from {@link encryptedField}) as the target for encryption.\n */\nexport type EncryptOptions = {\n /** The column or nested field to encrypt into. From {@link EncryptedColumn} or {@link EncryptedField}. */\n column: EncryptedColumn | EncryptedField\n table: EncryptedTable<EncryptedTableColumn>\n}\n\n/** Format for encrypted query/search term return values */\nexport type EncryptedReturnType =\n | 'eql'\n | 'composite-literal'\n | 'escaped-composite-literal'\n\nexport type SearchTerm = {\n value: JsPlaintext\n column: EncryptedColumn\n table: EncryptedTable<EncryptedTableColumn>\n returnType?: EncryptedReturnType\n}\n\n/** Encrypted search term result: EQL object or composite literal string */\nexport type EncryptedSearchTerm = Encrypted | string\n\n/** Result of encryptQuery (single or batch): EQL, composite literal string, or null */\nexport type EncryptedQueryResult = Encrypted | string | null\n\n// ---------------------------------------------------------------------------\n// Model field types (encrypted vs decrypted views)\n// ---------------------------------------------------------------------------\n\nexport type EncryptedFields<T> = {\n [K in keyof T as T[K] extends Encrypted ? K : never]: T[K]\n}\n\nexport type OtherFields<T> = {\n [K in keyof T as T[K] extends Encrypted ? never : K]: T[K]\n}\n\nexport type DecryptedFields<T> = {\n [K in keyof T as T[K] extends Encrypted ? K : never]: string\n}\n\n/** Model with encrypted fields replaced by plaintext (decrypted) values */\nexport type Decrypted<T> = OtherFields<T> & DecryptedFields<T>\n\n/**\n * Maps a plaintext model type to its encrypted form using the table schema.\n *\n * Fields whose keys match columns defined in `S` become `Encrypted`;\n * all other fields retain their original types from `T`.\n *\n * When `S` is the widened `EncryptedTableColumn` (e.g. when a user passes an\n * explicit `<User>` type argument without specifying `S`), the type degrades\n * gracefully to `T` — preserving backward compatibility.\n *\n * @typeParam T - The plaintext model type (e.g. `{ id: string; email: string }`)\n * @typeParam S - The table schema column definition, inferred from the `table` argument\n *\n * @example\n * ```typescript\n * type User = { id: string; email: string }\n * // With a schema that defines `email`:\n * type Encrypted = EncryptedFromSchema<User, { email: EncryptedColumn }>\n * // => { id: string; email: Encrypted }\n * ```\n */\nexport type EncryptedFromSchema<T, S extends EncryptedTableColumn> = {\n [K in keyof T]: [K] extends [keyof S]\n ? [S[K & keyof S]] extends [EncryptedColumn | EncryptedField]\n ? Encrypted\n : T[K]\n : T[K]\n}\n\n// ---------------------------------------------------------------------------\n// Bulk operations\n// ---------------------------------------------------------------------------\n\nexport type BulkEncryptPayload = Array<{\n id?: string\n plaintext: JsPlaintext | null\n}>\n\nexport type BulkEncryptedData = Array<{ id?: string; data: Encrypted }>\nexport type BulkDecryptPayload = Array<{ id?: string; data: Encrypted }>\nexport type BulkDecryptedData = Array<DecryptionResult<JsPlaintext | null>>\n\ntype DecryptionSuccess<T> = { error?: never; data: T; id?: string }\ntype DecryptionError<T> = { error: T; id?: string; data?: never }\n\n/**\n * Result type for individual items in bulk decrypt operations.\n * Uses `error`/`data` fields (not `failure`/`data`) since bulk operations\n * can have per-item failures.\n */\nexport type DecryptionResult<T> = DecryptionSuccess<T> | DecryptionError<T>\n\n// ---------------------------------------------------------------------------\n// Query types (for searchable encryption / encryptQuery)\n// ---------------------------------------------------------------------------\n\n/**\n * User-facing query type names for encrypting query values.\n *\n * - `'equality'`: Exact match. [Exact Queries](https://cipherstash.com/docs/platform/searchable-encryption/supported-queries/exact)\n * - `'freeTextSearch'`: Text search. [Match Queries](https://cipherstash.com/docs/platform/searchable-encryption/supported-queries/match)\n * - `'orderAndRange'`: Comparison and range. [Range Queries](https://cipherstash.com/docs/platform/searchable-encryption/supported-queries/range)\n * - `'steVecSelector'`: JSONPath selector (e.g. `'$.user.email'`)\n * - `'steVecTerm'`: Containment (e.g. `{ role: 'admin' }`)\n * - `'searchableJson'`: Auto-infers selector or term from plaintext type (recommended)\n */\nexport type QueryTypeName =\n | 'orderAndRange'\n | 'freeTextSearch'\n | 'equality'\n | 'steVecSelector'\n | 'steVecTerm'\n | 'searchableJson'\n\n/** @internal */\nexport type FfiIndexTypeName = 'ore' | 'match' | 'unique' | 'ste_vec'\n\nexport const queryTypes = {\n orderAndRange: 'orderAndRange',\n freeTextSearch: 'freeTextSearch',\n equality: 'equality',\n steVecSelector: 'steVecSelector',\n steVecTerm: 'steVecTerm',\n searchableJson: 'searchableJson',\n} as const satisfies Record<string, QueryTypeName>\n\n/** @internal */\nexport const queryTypeToFfi: Record<QueryTypeName, FfiIndexTypeName> = {\n orderAndRange: 'ore',\n freeTextSearch: 'match',\n equality: 'unique',\n steVecSelector: 'ste_vec',\n steVecTerm: 'ste_vec',\n searchableJson: 'ste_vec',\n}\n\n/** @internal */\nexport const queryTypeToQueryOp: Partial<Record<QueryTypeName, QueryOpName>> = {\n steVecSelector: 'ste_vec_selector',\n steVecTerm: 'ste_vec_term',\n}\n\n/** @internal */\nexport type QueryTermBase = {\n column: EncryptedColumn\n table: EncryptedTable<EncryptedTableColumn>\n queryType?: QueryTypeName\n returnType?: EncryptedReturnType\n}\n\nexport type EncryptQueryOptions = QueryTermBase\n\nexport type ScalarQueryTerm = QueryTermBase & {\n value: JsPlaintext | null\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC6NO,IAAM,aAAa;AAAA,EACxB,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,UAAU;AAAA,EACV,gBAAgB;AAAA,EAChB,YAAY;AAAA,EACZ,gBAAgB;AAClB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/types-public.ts","../src/types.ts"],"sourcesContent":["/**\n * Public type re-exports for `@cipherstash/stack/types`.\n *\n * This module exposes only the public types from the internal types module.\n * Internal helpers (`queryTypeToFfi`, `queryTypeToQueryOp`, `FfiIndexTypeName`,\n * `QueryTermBase`) are excluded.\n */\n\n// Core types\nexport type {\n Client,\n EncryptedValue,\n Encrypted,\n} from '@/types'\n\n// Client configuration\nexport type {\n KeysetIdentifier,\n ClientConfig,\n EncryptionClientConfig,\n} from '@/types'\n\n// Encrypt / decrypt operation options and results\nexport type {\n EncryptOptions,\n EncryptedReturnType,\n SearchTerm,\n EncryptedSearchTerm,\n EncryptedQueryResult,\n} from '@/types'\n\n// Model field types\nexport type {\n EncryptedFields,\n OtherFields,\n DecryptedFields,\n Decrypted,\n} from '@/types'\n\n// Bulk operations\nexport type {\n BulkEncryptPayload,\n BulkEncryptedData,\n BulkDecryptPayload,\n BulkDecryptedData,\n DecryptionResult,\n} from '@/types'\n\n// Query types (public only)\nexport type {\n QueryTypeName,\n EncryptQueryOptions,\n ScalarQueryTerm,\n} from '@/types'\n\n// Runtime values\nexport { queryTypes } from '@/types'\n","import type {\n EncryptedColumn,\n EncryptedField,\n EncryptedTable,\n EncryptedTableColumn,\n} from '@/schema'\nimport type {\n Encrypted as CipherStashEncrypted,\n JsPlaintext,\n QueryOpName,\n newClient,\n} from '@cipherstash/protect-ffi'\n\n// ---------------------------------------------------------------------------\n// Branded type utilities\n// ---------------------------------------------------------------------------\n\n/** Brand symbol for nominal typing */\ndeclare const __brand: unique symbol\n\n/** Creates a branded type that is structurally incompatible with the base type */\ntype Brand<T, B extends string> = T & { readonly [__brand]: B }\n\n// ---------------------------------------------------------------------------\n// Core types\n// ---------------------------------------------------------------------------\n\nexport type Client = Awaited<ReturnType<typeof newClient>> | undefined\n\n/** A branded type representing encrypted data. Cannot be accidentally used as plaintext. */\nexport type EncryptedValue = Brand<CipherStashEncrypted, 'encrypted'>\n\n/** Structural type representing encrypted data. See also `EncryptedValue` for branded nominal typing. */\nexport type Encrypted = CipherStashEncrypted\n\n// ---------------------------------------------------------------------------\n// Client configuration\n// ---------------------------------------------------------------------------\n\nexport type KeysetIdentifier = { name: string } | { id: string }\n\nexport type ClientConfig = {\n /**\n * The CipherStash workspace CRN (Cloud Resource Name).\n * Format: `crn:<region>.aws:<workspace-id>`.\n * Can also be set via the `CS_WORKSPACE_CRN` environment variable.\n * If omitted, the SDK reads from the environment or TOML config files.\n */\n workspaceCrn?: string\n\n /**\n * The API access key used for authenticating with the CipherStash API.\n * Can also be set via the `CS_CLIENT_ACCESS_KEY` environment variable.\n * Obtain this from the CipherStash dashboard after creating a workspace.\n */\n accessKey?: string\n\n /**\n * The client identifier used to authenticate with CipherStash services.\n * Can also be set via the `CS_CLIENT_ID` environment variable.\n * Generated during workspace onboarding in the CipherStash dashboard.\n */\n clientId?: string\n\n /**\n * The client key material used in combination with ZeroKMS for encryption operations.\n * Can also be set via the `CS_CLIENT_KEY` environment variable.\n * Generated during workspace onboarding in the CipherStash dashboard.\n */\n clientKey?: string\n\n /**\n * An optional keyset identifier for multi-tenant encryption.\n * Each keyset provides cryptographic isolation, giving each tenant its own keyspace.\n * Specify by name (`{ name: \"tenant-a\" }`) or UUID (`{ id: \"...\" }`).\n * Keysets are created and managed in the CipherStash dashboard.\n */\n keyset?: KeysetIdentifier\n}\n\ntype AtLeastOneCsTable<T> = [T, ...T[]]\n\nexport type EncryptionClientConfig = {\n schemas: AtLeastOneCsTable<EncryptedTable<EncryptedTableColumn>>\n config?: ClientConfig\n}\n\n// ---------------------------------------------------------------------------\n// Encrypt / decrypt operation options and results\n// ---------------------------------------------------------------------------\n\n/**\n * Options for single-value encrypt operations.\n * Use a column from your table schema (from {@link encryptedColumn}) or a nested\n * field (from {@link encryptedField}) as the target for encryption.\n */\nexport type EncryptOptions = {\n /** The column or nested field to encrypt into. From {@link EncryptedColumn} or {@link EncryptedField}. */\n column: EncryptedColumn | EncryptedField\n table: EncryptedTable<EncryptedTableColumn>\n}\n\n/** Format for encrypted query/search term return values */\nexport type EncryptedReturnType =\n | 'eql'\n | 'composite-literal'\n | 'escaped-composite-literal'\n\nexport type SearchTerm = {\n value: JsPlaintext\n column: EncryptedColumn\n table: EncryptedTable<EncryptedTableColumn>\n returnType?: EncryptedReturnType\n}\n\n/** Encrypted search term result: EQL object or composite literal string */\nexport type EncryptedSearchTerm = Encrypted | string\n\n/** Result of encryptQuery (single or batch): EQL or composite literal string */\nexport type EncryptedQueryResult = Encrypted | string\n\n// ---------------------------------------------------------------------------\n// Model field types (encrypted vs decrypted views)\n// ---------------------------------------------------------------------------\n\nexport type EncryptedFields<T> = {\n [K in keyof T as NonNullable<T[K]> extends Encrypted ? K : never]: T[K]\n}\n\nexport type OtherFields<T> = {\n [K in keyof T as NonNullable<T[K]> extends Encrypted ? never : K]: T[K]\n}\n\nexport type DecryptedFields<T> = {\n [K in keyof T as NonNullable<T[K]> extends Encrypted\n ? K\n : never]: null extends T[K] ? string | null : string\n}\n\n/** Model with encrypted fields replaced by plaintext (decrypted) values */\nexport type Decrypted<T> = OtherFields<T> & DecryptedFields<T>\n\n/**\n * Maps a plaintext model type to its encrypted form using the table schema.\n *\n * Fields whose keys match columns defined in `S` become `Encrypted`;\n * all other fields retain their original types from `T`.\n *\n * When `S` is the widened `EncryptedTableColumn` (e.g. when a user passes an\n * explicit `<User>` type argument without specifying `S`), the type degrades\n * gracefully to `T` — preserving backward compatibility.\n *\n * @typeParam T - The plaintext model type (e.g. `{ id: string; email: string }`)\n * @typeParam S - The table schema column definition, inferred from the `table` argument\n *\n * @example\n * ```typescript\n * type User = { id: string; email: string }\n * // With a schema that defines `email`:\n * type Encrypted = EncryptedFromSchema<User, { email: EncryptedColumn }>\n * // => { id: string; email: Encrypted }\n * ```\n */\nexport type EncryptedFromSchema<T, S extends EncryptedTableColumn> = {\n [K in keyof T]: [K] extends [keyof S]\n ? [S[K & keyof S]] extends [EncryptedColumn | EncryptedField]\n ? null extends T[K]\n ? Encrypted | null\n : Encrypted\n : T[K]\n : T[K]\n}\n\n// ---------------------------------------------------------------------------\n// Bulk operations\n// ---------------------------------------------------------------------------\n\nexport type BulkEncryptPayload = Array<{\n id?: string\n plaintext: JsPlaintext\n}>\n\nexport type BulkEncryptedData = Array<{ id?: string; data: Encrypted }>\nexport type BulkDecryptPayload = Array<{ id?: string; data: Encrypted }>\nexport type BulkDecryptedData = Array<DecryptionResult<JsPlaintext>>\n\ntype DecryptionSuccess<T> = { error?: never; data: T; id?: string }\ntype DecryptionError<T> = { error: T; id?: string; data?: never }\n\n/**\n * Result type for individual items in bulk decrypt operations.\n * Uses `error`/`data` fields (not `failure`/`data`) since bulk operations\n * can have per-item failures.\n */\nexport type DecryptionResult<T> = DecryptionSuccess<T> | DecryptionError<T>\n\n// ---------------------------------------------------------------------------\n// Query types (for searchable encryption / encryptQuery)\n// ---------------------------------------------------------------------------\n\n/**\n * User-facing query type names for encrypting query values.\n *\n * - `'equality'`: Exact match. [Exact Queries](https://cipherstash.com/docs/platform/searchable-encryption/supported-queries/exact)\n * - `'freeTextSearch'`: Text search. [Match Queries](https://cipherstash.com/docs/platform/searchable-encryption/supported-queries/match)\n * - `'orderAndRange'`: Comparison and range. [Range Queries](https://cipherstash.com/docs/platform/searchable-encryption/supported-queries/range)\n * - `'steVecSelector'`: JSONPath selector (e.g. `'$.user.email'`)\n * - `'steVecTerm'`: Containment (e.g. `{ role: 'admin' }`)\n * - `'searchableJson'`: Auto-infers selector or term from plaintext type (recommended)\n */\nexport type QueryTypeName =\n | 'orderAndRange'\n | 'freeTextSearch'\n | 'equality'\n | 'steVecSelector'\n | 'steVecTerm'\n | 'searchableJson'\n\n/** @internal */\nexport type FfiIndexTypeName = 'ore' | 'match' | 'unique' | 'ste_vec'\n\nexport const queryTypes = {\n orderAndRange: 'orderAndRange',\n freeTextSearch: 'freeTextSearch',\n equality: 'equality',\n steVecSelector: 'steVecSelector',\n steVecTerm: 'steVecTerm',\n searchableJson: 'searchableJson',\n} as const satisfies Record<string, QueryTypeName>\n\n/** @internal */\nexport const queryTypeToFfi: Record<QueryTypeName, FfiIndexTypeName> = {\n orderAndRange: 'ore',\n freeTextSearch: 'match',\n equality: 'unique',\n steVecSelector: 'ste_vec',\n steVecTerm: 'ste_vec',\n searchableJson: 'ste_vec',\n}\n\n/** @internal */\nexport const queryTypeToQueryOp: Partial<Record<QueryTypeName, QueryOpName>> = {\n steVecSelector: 'ste_vec_selector',\n steVecTerm: 'ste_vec_term',\n}\n\n/** @internal */\nexport type QueryTermBase = {\n column: EncryptedColumn\n table: EncryptedTable<EncryptedTableColumn>\n queryType?: QueryTypeName\n returnType?: EncryptedReturnType\n}\n\nexport type EncryptQueryOptions = QueryTermBase\n\nexport type ScalarQueryTerm = QueryTermBase & {\n value: JsPlaintext\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC6NO,IAAM,aAAa;AAAA,EACxB,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,UAAU;AAAA,EACV,gBAAgB;AAAA,EAChB,YAAY;AAAA,EACZ,gBAAgB;AAClB;","names":[]}
|
package/dist/types-public.d.cts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { j as BulkDecryptPayload, B as BulkDecryptedData, l as BulkEncryptPayload, k as BulkEncryptedData, i as Client, z as ClientConfig, D as Decrypted, J as DecryptedFields, L as DecryptionResult, m as EncryptOptions, o as EncryptQueryOptions, E as Encrypted, G as EncryptedFields, h as EncryptedQueryResult, p as EncryptedReturnType, F as EncryptedSearchTerm, g as EncryptedValue, s as EncryptionClientConfig, K as KeysetIdentifier, H as OtherFields, Q as QueryTypeName, S as ScalarQueryTerm, A as SearchTerm, N as queryTypes } from './types-public-dKxDzTIL.cjs';
|
|
2
2
|
import 'zod';
|
|
3
|
-
import 'evlog';
|
|
4
3
|
import '@cipherstash/protect-ffi';
|
package/dist/types-public.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { j as BulkDecryptPayload, B as BulkDecryptedData, l as BulkEncryptPayload, k as BulkEncryptedData, i as Client, z as ClientConfig, D as Decrypted, J as DecryptedFields, L as DecryptionResult, m as EncryptOptions, o as EncryptQueryOptions, E as Encrypted, G as EncryptedFields, h as EncryptedQueryResult, p as EncryptedReturnType, F as EncryptedSearchTerm, g as EncryptedValue, s as EncryptionClientConfig, K as KeysetIdentifier, H as OtherFields, Q as QueryTypeName, S as ScalarQueryTerm, A as SearchTerm, N as queryTypes } from './types-public-dKxDzTIL.js';
|
|
2
2
|
import 'zod';
|
|
3
|
-
import 'evlog';
|
|
4
3
|
import '@cipherstash/protect-ffi';
|
package/dist/types-public.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cipherstash/stack",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "CipherStash Stack for TypeScript and JavaScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"encrypted",
|
|
@@ -36,6 +36,12 @@
|
|
|
36
36
|
"types": "./dist/index.d.ts",
|
|
37
37
|
"typesVersions": {
|
|
38
38
|
"*": {
|
|
39
|
+
"encryption": [
|
|
40
|
+
"./dist/encryption/index.d.ts"
|
|
41
|
+
],
|
|
42
|
+
"errors": [
|
|
43
|
+
"./dist/errors/index.d.ts"
|
|
44
|
+
],
|
|
39
45
|
"client": [
|
|
40
46
|
"./dist/client.d.ts"
|
|
41
47
|
],
|
|
@@ -153,11 +159,32 @@
|
|
|
153
159
|
"default": "./dist/supabase/index.cjs"
|
|
154
160
|
}
|
|
155
161
|
},
|
|
162
|
+
"./encryption": {
|
|
163
|
+
"import": {
|
|
164
|
+
"types": "./dist/encryption/index.d.ts",
|
|
165
|
+
"default": "./dist/encryption/index.js"
|
|
166
|
+
},
|
|
167
|
+
"require": {
|
|
168
|
+
"types": "./dist/encryption/index.d.cts",
|
|
169
|
+
"default": "./dist/encryption/index.cjs"
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
"./errors": {
|
|
173
|
+
"import": {
|
|
174
|
+
"types": "./dist/errors/index.d.ts",
|
|
175
|
+
"default": "./dist/errors/index.js"
|
|
176
|
+
},
|
|
177
|
+
"require": {
|
|
178
|
+
"types": "./dist/errors/index.d.cts",
|
|
179
|
+
"default": "./dist/errors/index.cjs"
|
|
180
|
+
}
|
|
181
|
+
},
|
|
156
182
|
"./package.json": "./package.json"
|
|
157
183
|
},
|
|
158
184
|
"devDependencies": {
|
|
159
185
|
"@clack/prompts": "^0.10.1",
|
|
160
186
|
"@supabase/supabase-js": "^2.47.10",
|
|
187
|
+
"@types/uuid": "^11.0.0",
|
|
161
188
|
"dotenv": "16.4.7",
|
|
162
189
|
"drizzle-orm": ">=0.33",
|
|
163
190
|
"execa": "^9.5.2",
|
|
@@ -173,8 +200,9 @@
|
|
|
173
200
|
},
|
|
174
201
|
"dependencies": {
|
|
175
202
|
"@byteslice/result": "^0.2.0",
|
|
176
|
-
"@cipherstash/protect-ffi": "0.20.
|
|
203
|
+
"@cipherstash/protect-ffi": "0.20.2",
|
|
177
204
|
"evlog": "^1.9.0",
|
|
205
|
+
"uuid": "^13.0.0",
|
|
178
206
|
"zod": "3.24.2"
|
|
179
207
|
},
|
|
180
208
|
"peerDependencies": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n EncryptedColumn,\n EncryptedTable,\n EncryptedTableColumn,\n EncryptedField,\n} from '@/schema'\nimport type { LoggingConfig } from '@/utils/logger'\nimport type {\n Encrypted as CipherStashEncrypted,\n JsPlaintext,\n QueryOpName,\n newClient,\n} from '@cipherstash/protect-ffi'\n\n// ---------------------------------------------------------------------------\n// Branded type utilities\n// ---------------------------------------------------------------------------\n\n/** Brand symbol for nominal typing */\ndeclare const __brand: unique symbol\n\n/** Creates a branded type that is structurally incompatible with the base type */\ntype Brand<T, B extends string> = T & { readonly [__brand]: B }\n\n// ---------------------------------------------------------------------------\n// Core types\n// ---------------------------------------------------------------------------\n\nexport type Client = Awaited<ReturnType<typeof newClient>> | undefined\n\n/** A branded type representing encrypted data. Cannot be accidentally used as plaintext. */\nexport type EncryptedValue = Brand<CipherStashEncrypted, 'encrypted'> | null\n\n/** Structural type representing encrypted data. See also `EncryptedValue` for branded nominal typing. */\nexport type Encrypted = CipherStashEncrypted | null\n\nexport type EncryptPayload = JsPlaintext | null\n\n// ---------------------------------------------------------------------------\n// Client configuration\n// ---------------------------------------------------------------------------\n\nexport type KeysetIdentifier = { name: string } | { id: string }\n\nexport type ClientConfig = {\n /**\n * The CipherStash workspace CRN (Cloud Resource Name).\n * Format: `crn:<region>.aws:<workspace-id>`.\n * Can also be set via the `CS_WORKSPACE_CRN` environment variable.\n * If omitted, the SDK reads from the environment or TOML config files.\n */\n workspaceCrn?: string\n\n /**\n * The API access key used for authenticating with the CipherStash API.\n * Can also be set via the `CS_CLIENT_ACCESS_KEY` environment variable.\n * Obtain this from the CipherStash dashboard after creating a workspace.\n */\n accessKey?: string\n\n /**\n * The client identifier used to authenticate with CipherStash services.\n * Can also be set via the `CS_CLIENT_ID` environment variable.\n * Generated during workspace onboarding in the CipherStash dashboard.\n */\n clientId?: string\n\n /**\n * The client key material used in combination with ZeroKMS for encryption operations.\n * Can also be set via the `CS_CLIENT_KEY` environment variable.\n * Generated during workspace onboarding in the CipherStash dashboard.\n */\n clientKey?: string\n\n /**\n * An optional keyset identifier for multi-tenant encryption.\n * Each keyset provides cryptographic isolation, giving each tenant its own keyspace.\n * Specify by name (`{ name: \"tenant-a\" }`) or UUID (`{ id: \"...\" }`).\n * Keysets are created and managed in the CipherStash dashboard.\n */\n keyset?: KeysetIdentifier\n}\n\ntype AtLeastOneCsTable<T> = [T, ...T[]]\n\nexport type EncryptionClientConfig = {\n schemas: AtLeastOneCsTable<EncryptedTable<EncryptedTableColumn>>\n config?: ClientConfig\n logging?: LoggingConfig\n}\n\n// ---------------------------------------------------------------------------\n// Encrypt / decrypt operation options and results\n// ---------------------------------------------------------------------------\n\n/**\n * Options for single-value encrypt operations.\n * Use a column from your table schema (from {@link encryptedColumn}) or a nested\n * field (from {@link encryptedField}) as the target for encryption.\n */\nexport type EncryptOptions = {\n /** The column or nested field to encrypt into. From {@link EncryptedColumn} or {@link EncryptedField}. */\n column: EncryptedColumn | EncryptedField\n table: EncryptedTable<EncryptedTableColumn>\n}\n\n/** Format for encrypted query/search term return values */\nexport type EncryptedReturnType =\n | 'eql'\n | 'composite-literal'\n | 'escaped-composite-literal'\n\nexport type SearchTerm = {\n value: JsPlaintext\n column: EncryptedColumn\n table: EncryptedTable<EncryptedTableColumn>\n returnType?: EncryptedReturnType\n}\n\n/** Encrypted search term result: EQL object or composite literal string */\nexport type EncryptedSearchTerm = Encrypted | string\n\n/** Result of encryptQuery (single or batch): EQL, composite literal string, or null */\nexport type EncryptedQueryResult = Encrypted | string | null\n\n// ---------------------------------------------------------------------------\n// Model field types (encrypted vs decrypted views)\n// ---------------------------------------------------------------------------\n\nexport type EncryptedFields<T> = {\n [K in keyof T as T[K] extends Encrypted ? K : never]: T[K]\n}\n\nexport type OtherFields<T> = {\n [K in keyof T as T[K] extends Encrypted ? never : K]: T[K]\n}\n\nexport type DecryptedFields<T> = {\n [K in keyof T as T[K] extends Encrypted ? K : never]: string\n}\n\n/** Model with encrypted fields replaced by plaintext (decrypted) values */\nexport type Decrypted<T> = OtherFields<T> & DecryptedFields<T>\n\n/**\n * Maps a plaintext model type to its encrypted form using the table schema.\n *\n * Fields whose keys match columns defined in `S` become `Encrypted`;\n * all other fields retain their original types from `T`.\n *\n * When `S` is the widened `EncryptedTableColumn` (e.g. when a user passes an\n * explicit `<User>` type argument without specifying `S`), the type degrades\n * gracefully to `T` — preserving backward compatibility.\n *\n * @typeParam T - The plaintext model type (e.g. `{ id: string; email: string }`)\n * @typeParam S - The table schema column definition, inferred from the `table` argument\n *\n * @example\n * ```typescript\n * type User = { id: string; email: string }\n * // With a schema that defines `email`:\n * type Encrypted = EncryptedFromSchema<User, { email: EncryptedColumn }>\n * // => { id: string; email: Encrypted }\n * ```\n */\nexport type EncryptedFromSchema<T, S extends EncryptedTableColumn> = {\n [K in keyof T]: [K] extends [keyof S]\n ? [S[K & keyof S]] extends [EncryptedColumn | EncryptedField]\n ? Encrypted\n : T[K]\n : T[K]\n}\n\n// ---------------------------------------------------------------------------\n// Bulk operations\n// ---------------------------------------------------------------------------\n\nexport type BulkEncryptPayload = Array<{\n id?: string\n plaintext: JsPlaintext | null\n}>\n\nexport type BulkEncryptedData = Array<{ id?: string; data: Encrypted }>\nexport type BulkDecryptPayload = Array<{ id?: string; data: Encrypted }>\nexport type BulkDecryptedData = Array<DecryptionResult<JsPlaintext | null>>\n\ntype DecryptionSuccess<T> = { error?: never; data: T; id?: string }\ntype DecryptionError<T> = { error: T; id?: string; data?: never }\n\n/**\n * Result type for individual items in bulk decrypt operations.\n * Uses `error`/`data` fields (not `failure`/`data`) since bulk operations\n * can have per-item failures.\n */\nexport type DecryptionResult<T> = DecryptionSuccess<T> | DecryptionError<T>\n\n// ---------------------------------------------------------------------------\n// Query types (for searchable encryption / encryptQuery)\n// ---------------------------------------------------------------------------\n\n/**\n * User-facing query type names for encrypting query values.\n *\n * - `'equality'`: Exact match. [Exact Queries](https://cipherstash.com/docs/platform/searchable-encryption/supported-queries/exact)\n * - `'freeTextSearch'`: Text search. [Match Queries](https://cipherstash.com/docs/platform/searchable-encryption/supported-queries/match)\n * - `'orderAndRange'`: Comparison and range. [Range Queries](https://cipherstash.com/docs/platform/searchable-encryption/supported-queries/range)\n * - `'steVecSelector'`: JSONPath selector (e.g. `'$.user.email'`)\n * - `'steVecTerm'`: Containment (e.g. `{ role: 'admin' }`)\n * - `'searchableJson'`: Auto-infers selector or term from plaintext type (recommended)\n */\nexport type QueryTypeName =\n | 'orderAndRange'\n | 'freeTextSearch'\n | 'equality'\n | 'steVecSelector'\n | 'steVecTerm'\n | 'searchableJson'\n\n/** @internal */\nexport type FfiIndexTypeName = 'ore' | 'match' | 'unique' | 'ste_vec'\n\nexport const queryTypes = {\n orderAndRange: 'orderAndRange',\n freeTextSearch: 'freeTextSearch',\n equality: 'equality',\n steVecSelector: 'steVecSelector',\n steVecTerm: 'steVecTerm',\n searchableJson: 'searchableJson',\n} as const satisfies Record<string, QueryTypeName>\n\n/** @internal */\nexport const queryTypeToFfi: Record<QueryTypeName, FfiIndexTypeName> = {\n orderAndRange: 'ore',\n freeTextSearch: 'match',\n equality: 'unique',\n steVecSelector: 'ste_vec',\n steVecTerm: 'ste_vec',\n searchableJson: 'ste_vec',\n}\n\n/** @internal */\nexport const queryTypeToQueryOp: Partial<Record<QueryTypeName, QueryOpName>> = {\n steVecSelector: 'ste_vec_selector',\n steVecTerm: 'ste_vec_term',\n}\n\n/** @internal */\nexport type QueryTermBase = {\n column: EncryptedColumn\n table: EncryptedTable<EncryptedTableColumn>\n queryType?: QueryTypeName\n returnType?: EncryptedReturnType\n}\n\nexport type EncryptQueryOptions = QueryTermBase\n\nexport type ScalarQueryTerm = QueryTermBase & {\n value: JsPlaintext | null\n}\n"],"mappings":";AA6NO,IAAM,aAAa;AAAA,EACxB,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,UAAU;AAAA,EACV,gBAAgB;AAAA,EAChB,YAAY;AAAA,EACZ,gBAAgB;AAClB;AAGO,IAAM,iBAA0D;AAAA,EACrE,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,UAAU;AAAA,EACV,gBAAgB;AAAA,EAChB,YAAY;AAAA,EACZ,gBAAgB;AAClB;AAGO,IAAM,qBAAkE;AAAA,EAC7E,gBAAgB;AAAA,EAChB,YAAY;AACd;","names":[]}
|