@cipherstash/stack 0.1.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 +7 -0
- package/LICENSE.md +21 -0
- package/README.md +670 -0
- package/dist/bin/stash.js +5049 -0
- package/dist/bin/stash.js.map +1 -0
- package/dist/chunk-2GZMIJFO.js +2400 -0
- package/dist/chunk-2GZMIJFO.js.map +1 -0
- package/dist/chunk-5DCT6YU2.js +138 -0
- package/dist/chunk-5DCT6YU2.js.map +1 -0
- package/dist/chunk-7XRPN2KX.js +336 -0
- package/dist/chunk-7XRPN2KX.js.map +1 -0
- package/dist/chunk-SJ7JO4ME.js +28 -0
- package/dist/chunk-SJ7JO4ME.js.map +1 -0
- package/dist/chunk-SUYMGQBY.js +67 -0
- package/dist/chunk-SUYMGQBY.js.map +1 -0
- package/dist/client-BxJG56Ey.d.cts +647 -0
- package/dist/client-DtGq9dJp.d.ts +647 -0
- package/dist/client.cjs +347 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +7 -0
- package/dist/client.d.ts +7 -0
- package/dist/client.js +11 -0
- package/dist/client.js.map +1 -0
- package/dist/drizzle/index.cjs +1528 -0
- package/dist/drizzle/index.cjs.map +1 -0
- package/dist/drizzle/index.d.cts +350 -0
- package/dist/drizzle/index.d.ts +350 -0
- package/dist/drizzle/index.js +1212 -0
- package/dist/drizzle/index.js.map +1 -0
- package/dist/dynamodb/index.cjs +382 -0
- package/dist/dynamodb/index.cjs.map +1 -0
- package/dist/dynamodb/index.d.cts +125 -0
- package/dist/dynamodb/index.d.ts +125 -0
- package/dist/dynamodb/index.js +355 -0
- package/dist/dynamodb/index.js.map +1 -0
- package/dist/identity/index.cjs +271 -0
- package/dist/identity/index.cjs.map +1 -0
- package/dist/identity/index.d.cts +3 -0
- package/dist/identity/index.d.ts +3 -0
- package/dist/identity/index.js +117 -0
- package/dist/identity/index.js.map +1 -0
- package/dist/index-9-Ya3fDK.d.cts +169 -0
- package/dist/index-9-Ya3fDK.d.ts +169 -0
- package/dist/index.cjs +2915 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +22 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/schema/index.cjs +368 -0
- package/dist/schema/index.cjs.map +1 -0
- package/dist/schema/index.d.cts +4 -0
- package/dist/schema/index.d.ts +4 -0
- package/dist/schema/index.js +23 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/secrets/index.cjs +3207 -0
- package/dist/secrets/index.cjs.map +1 -0
- package/dist/secrets/index.d.cts +227 -0
- package/dist/secrets/index.d.ts +227 -0
- package/dist/secrets/index.js +323 -0
- package/dist/secrets/index.js.map +1 -0
- package/dist/supabase/index.cjs +1113 -0
- package/dist/supabase/index.cjs.map +1 -0
- package/dist/supabase/index.d.cts +144 -0
- package/dist/supabase/index.d.ts +144 -0
- package/dist/supabase/index.js +864 -0
- package/dist/supabase/index.js.map +1 -0
- package/dist/types-public-BCj1L4fi.d.cts +1013 -0
- package/dist/types-public-BCj1L4fi.d.ts +1013 -0
- package/dist/types-public.cjs +40 -0
- package/dist/types-public.cjs.map +1 -0
- package/dist/types-public.d.cts +4 -0
- package/dist/types-public.d.ts +4 -0
- package/dist/types-public.js +7 -0
- package/dist/types-public.js.map +1 -0
- package/package.json +202 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { ProtectErrorCode } from '@cipherstash/protect-ffi';
|
|
2
|
+
import { Result } from '@byteslice/result';
|
|
3
|
+
|
|
4
|
+
declare const EncryptionErrorTypes: {
|
|
5
|
+
ClientInitError: string;
|
|
6
|
+
EncryptionError: string;
|
|
7
|
+
DecryptionError: string;
|
|
8
|
+
LockContextError: string;
|
|
9
|
+
CtsTokenError: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Base error interface returned by all encryption operations.
|
|
13
|
+
*
|
|
14
|
+
* Every operation that can fail returns `Result<T, EncryptionError>`.
|
|
15
|
+
* Use the `type` field to narrow to a specific error kind, or use
|
|
16
|
+
* {@link StackError} for an exhaustive discriminated union.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const result = await client.encrypt(value, opts)
|
|
21
|
+
* if (result.failure) {
|
|
22
|
+
* switch (result.failure.type) {
|
|
23
|
+
* case 'EncryptionError':
|
|
24
|
+
* console.error('Encryption failed:', result.failure.message)
|
|
25
|
+
* break
|
|
26
|
+
* case 'LockContextError':
|
|
27
|
+
* console.error('Lock context issue:', result.failure.message)
|
|
28
|
+
* break
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
interface EncryptionError {
|
|
34
|
+
type: (typeof EncryptionErrorTypes)[keyof typeof EncryptionErrorTypes];
|
|
35
|
+
message: string;
|
|
36
|
+
code?: ProtectErrorCode;
|
|
37
|
+
}
|
|
38
|
+
interface ClientInitError {
|
|
39
|
+
type: typeof EncryptionErrorTypes.ClientInitError;
|
|
40
|
+
message: string;
|
|
41
|
+
}
|
|
42
|
+
interface EncryptionOperationError {
|
|
43
|
+
type: typeof EncryptionErrorTypes.EncryptionError;
|
|
44
|
+
message: string;
|
|
45
|
+
code?: ProtectErrorCode;
|
|
46
|
+
}
|
|
47
|
+
interface DecryptionOperationError {
|
|
48
|
+
type: typeof EncryptionErrorTypes.DecryptionError;
|
|
49
|
+
message: string;
|
|
50
|
+
code?: ProtectErrorCode;
|
|
51
|
+
}
|
|
52
|
+
interface LockContextError {
|
|
53
|
+
type: typeof EncryptionErrorTypes.LockContextError;
|
|
54
|
+
message: string;
|
|
55
|
+
}
|
|
56
|
+
interface CtsTokenError {
|
|
57
|
+
type: typeof EncryptionErrorTypes.CtsTokenError;
|
|
58
|
+
message: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Discriminated union of all specific error types.
|
|
62
|
+
*
|
|
63
|
+
* Use `StackError` when you need exhaustive error handling via `switch` on the `type` field.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* function handleError(error: StackError) {
|
|
68
|
+
* switch (error.type) {
|
|
69
|
+
* case 'ClientInitError':
|
|
70
|
+
* // re-initialize client
|
|
71
|
+
* break
|
|
72
|
+
* case 'EncryptionError':
|
|
73
|
+
* case 'DecryptionError':
|
|
74
|
+
* // log and retry
|
|
75
|
+
* break
|
|
76
|
+
* case 'LockContextError':
|
|
77
|
+
* // re-authenticate
|
|
78
|
+
* break
|
|
79
|
+
* case 'CtsTokenError':
|
|
80
|
+
* // refresh token
|
|
81
|
+
* break
|
|
82
|
+
* default:
|
|
83
|
+
* error satisfies never
|
|
84
|
+
* }
|
|
85
|
+
* }
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
type StackError = ClientInitError | EncryptionOperationError | DecryptionOperationError | LockContextError | CtsTokenError;
|
|
89
|
+
/**
|
|
90
|
+
* Safely extract an error message from an unknown thrown value.
|
|
91
|
+
* Unlike `(error as Error).message`, this handles non-Error values gracefully.
|
|
92
|
+
*/
|
|
93
|
+
declare function getErrorMessage(error: unknown): string;
|
|
94
|
+
|
|
95
|
+
type CtsRegions = 'ap-southeast-2';
|
|
96
|
+
type IdentifyOptions = {
|
|
97
|
+
fetchFromCts?: boolean;
|
|
98
|
+
};
|
|
99
|
+
type CtsToken = {
|
|
100
|
+
accessToken: string;
|
|
101
|
+
expiry: number;
|
|
102
|
+
};
|
|
103
|
+
type Context = {
|
|
104
|
+
identityClaim: string[];
|
|
105
|
+
};
|
|
106
|
+
type LockContextOptions = {
|
|
107
|
+
context?: Context;
|
|
108
|
+
ctsToken?: CtsToken;
|
|
109
|
+
};
|
|
110
|
+
type GetLockContextResponse = {
|
|
111
|
+
ctsToken: CtsToken;
|
|
112
|
+
context: Context;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Manages CipherStash lock contexts for row-level access control.
|
|
116
|
+
*
|
|
117
|
+
* A `LockContext` ties encryption/decryption operations to an authenticated
|
|
118
|
+
* user identity via CTS (CipherStash Token Service). Call {@link identify}
|
|
119
|
+
* with a user's JWT to obtain a CTS token, then pass the `LockContext`
|
|
120
|
+
* to `.withLockContext()` on any encrypt/decrypt operation.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* import { LockContext } from "@cipherstash/stack/identity"
|
|
125
|
+
*
|
|
126
|
+
* const lc = new LockContext()
|
|
127
|
+
* const identified = await lc.identify(userJwt)
|
|
128
|
+
*
|
|
129
|
+
* if (identified.failure) throw new Error(identified.failure.message)
|
|
130
|
+
*
|
|
131
|
+
* const result = await client
|
|
132
|
+
* .encrypt(value, { column: users.email, table: users })
|
|
133
|
+
* .withLockContext(identified.data)
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
declare class LockContext {
|
|
137
|
+
private ctsToken;
|
|
138
|
+
private workspaceId;
|
|
139
|
+
private context;
|
|
140
|
+
constructor({ context, ctsToken, }?: LockContextOptions);
|
|
141
|
+
/**
|
|
142
|
+
* Exchange a user's JWT for a CTS token and bind it to this lock context.
|
|
143
|
+
*
|
|
144
|
+
* @param jwtToken - A valid OIDC / JWT token for the current user.
|
|
145
|
+
* @returns A `Result` containing this `LockContext` (now authenticated) or an error.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* const lc = new LockContext()
|
|
150
|
+
* const result = await lc.identify(userJwt)
|
|
151
|
+
* if (result.failure) {
|
|
152
|
+
* console.error("Auth failed:", result.failure.message)
|
|
153
|
+
* }
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
identify(jwtToken: string): Promise<Result<LockContext, EncryptionError>>;
|
|
157
|
+
/**
|
|
158
|
+
* Retrieve the current CTS token and context for use with encryption operations.
|
|
159
|
+
*
|
|
160
|
+
* Must be called after {@link identify}. Returns the token/context pair that
|
|
161
|
+
* `.withLockContext()` expects.
|
|
162
|
+
*
|
|
163
|
+
* @returns A `Result` containing the CTS token and identity context, or an error
|
|
164
|
+
* if {@link identify} has not been called.
|
|
165
|
+
*/
|
|
166
|
+
getLockContext(): Promise<Result<GetLockContextResponse, EncryptionError>>;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export { type ClientInitError as C, type DecryptionOperationError as D, EncryptionErrorTypes as E, type GetLockContextResponse as G, type IdentifyOptions as I, type LockContextError as L, type StackError as S, type EncryptionError as a, type EncryptionOperationError as b, type CtsTokenError as c, LockContext as d, type CtsRegions as e, type CtsToken as f, getErrorMessage as g, type Context as h, type LockContextOptions as i };
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { ProtectErrorCode } from '@cipherstash/protect-ffi';
|
|
2
|
+
import { Result } from '@byteslice/result';
|
|
3
|
+
|
|
4
|
+
declare const EncryptionErrorTypes: {
|
|
5
|
+
ClientInitError: string;
|
|
6
|
+
EncryptionError: string;
|
|
7
|
+
DecryptionError: string;
|
|
8
|
+
LockContextError: string;
|
|
9
|
+
CtsTokenError: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Base error interface returned by all encryption operations.
|
|
13
|
+
*
|
|
14
|
+
* Every operation that can fail returns `Result<T, EncryptionError>`.
|
|
15
|
+
* Use the `type` field to narrow to a specific error kind, or use
|
|
16
|
+
* {@link StackError} for an exhaustive discriminated union.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const result = await client.encrypt(value, opts)
|
|
21
|
+
* if (result.failure) {
|
|
22
|
+
* switch (result.failure.type) {
|
|
23
|
+
* case 'EncryptionError':
|
|
24
|
+
* console.error('Encryption failed:', result.failure.message)
|
|
25
|
+
* break
|
|
26
|
+
* case 'LockContextError':
|
|
27
|
+
* console.error('Lock context issue:', result.failure.message)
|
|
28
|
+
* break
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
interface EncryptionError {
|
|
34
|
+
type: (typeof EncryptionErrorTypes)[keyof typeof EncryptionErrorTypes];
|
|
35
|
+
message: string;
|
|
36
|
+
code?: ProtectErrorCode;
|
|
37
|
+
}
|
|
38
|
+
interface ClientInitError {
|
|
39
|
+
type: typeof EncryptionErrorTypes.ClientInitError;
|
|
40
|
+
message: string;
|
|
41
|
+
}
|
|
42
|
+
interface EncryptionOperationError {
|
|
43
|
+
type: typeof EncryptionErrorTypes.EncryptionError;
|
|
44
|
+
message: string;
|
|
45
|
+
code?: ProtectErrorCode;
|
|
46
|
+
}
|
|
47
|
+
interface DecryptionOperationError {
|
|
48
|
+
type: typeof EncryptionErrorTypes.DecryptionError;
|
|
49
|
+
message: string;
|
|
50
|
+
code?: ProtectErrorCode;
|
|
51
|
+
}
|
|
52
|
+
interface LockContextError {
|
|
53
|
+
type: typeof EncryptionErrorTypes.LockContextError;
|
|
54
|
+
message: string;
|
|
55
|
+
}
|
|
56
|
+
interface CtsTokenError {
|
|
57
|
+
type: typeof EncryptionErrorTypes.CtsTokenError;
|
|
58
|
+
message: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Discriminated union of all specific error types.
|
|
62
|
+
*
|
|
63
|
+
* Use `StackError` when you need exhaustive error handling via `switch` on the `type` field.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* function handleError(error: StackError) {
|
|
68
|
+
* switch (error.type) {
|
|
69
|
+
* case 'ClientInitError':
|
|
70
|
+
* // re-initialize client
|
|
71
|
+
* break
|
|
72
|
+
* case 'EncryptionError':
|
|
73
|
+
* case 'DecryptionError':
|
|
74
|
+
* // log and retry
|
|
75
|
+
* break
|
|
76
|
+
* case 'LockContextError':
|
|
77
|
+
* // re-authenticate
|
|
78
|
+
* break
|
|
79
|
+
* case 'CtsTokenError':
|
|
80
|
+
* // refresh token
|
|
81
|
+
* break
|
|
82
|
+
* default:
|
|
83
|
+
* error satisfies never
|
|
84
|
+
* }
|
|
85
|
+
* }
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
type StackError = ClientInitError | EncryptionOperationError | DecryptionOperationError | LockContextError | CtsTokenError;
|
|
89
|
+
/**
|
|
90
|
+
* Safely extract an error message from an unknown thrown value.
|
|
91
|
+
* Unlike `(error as Error).message`, this handles non-Error values gracefully.
|
|
92
|
+
*/
|
|
93
|
+
declare function getErrorMessage(error: unknown): string;
|
|
94
|
+
|
|
95
|
+
type CtsRegions = 'ap-southeast-2';
|
|
96
|
+
type IdentifyOptions = {
|
|
97
|
+
fetchFromCts?: boolean;
|
|
98
|
+
};
|
|
99
|
+
type CtsToken = {
|
|
100
|
+
accessToken: string;
|
|
101
|
+
expiry: number;
|
|
102
|
+
};
|
|
103
|
+
type Context = {
|
|
104
|
+
identityClaim: string[];
|
|
105
|
+
};
|
|
106
|
+
type LockContextOptions = {
|
|
107
|
+
context?: Context;
|
|
108
|
+
ctsToken?: CtsToken;
|
|
109
|
+
};
|
|
110
|
+
type GetLockContextResponse = {
|
|
111
|
+
ctsToken: CtsToken;
|
|
112
|
+
context: Context;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Manages CipherStash lock contexts for row-level access control.
|
|
116
|
+
*
|
|
117
|
+
* A `LockContext` ties encryption/decryption operations to an authenticated
|
|
118
|
+
* user identity via CTS (CipherStash Token Service). Call {@link identify}
|
|
119
|
+
* with a user's JWT to obtain a CTS token, then pass the `LockContext`
|
|
120
|
+
* to `.withLockContext()` on any encrypt/decrypt operation.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* import { LockContext } from "@cipherstash/stack/identity"
|
|
125
|
+
*
|
|
126
|
+
* const lc = new LockContext()
|
|
127
|
+
* const identified = await lc.identify(userJwt)
|
|
128
|
+
*
|
|
129
|
+
* if (identified.failure) throw new Error(identified.failure.message)
|
|
130
|
+
*
|
|
131
|
+
* const result = await client
|
|
132
|
+
* .encrypt(value, { column: users.email, table: users })
|
|
133
|
+
* .withLockContext(identified.data)
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
declare class LockContext {
|
|
137
|
+
private ctsToken;
|
|
138
|
+
private workspaceId;
|
|
139
|
+
private context;
|
|
140
|
+
constructor({ context, ctsToken, }?: LockContextOptions);
|
|
141
|
+
/**
|
|
142
|
+
* Exchange a user's JWT for a CTS token and bind it to this lock context.
|
|
143
|
+
*
|
|
144
|
+
* @param jwtToken - A valid OIDC / JWT token for the current user.
|
|
145
|
+
* @returns A `Result` containing this `LockContext` (now authenticated) or an error.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* const lc = new LockContext()
|
|
150
|
+
* const result = await lc.identify(userJwt)
|
|
151
|
+
* if (result.failure) {
|
|
152
|
+
* console.error("Auth failed:", result.failure.message)
|
|
153
|
+
* }
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
identify(jwtToken: string): Promise<Result<LockContext, EncryptionError>>;
|
|
157
|
+
/**
|
|
158
|
+
* Retrieve the current CTS token and context for use with encryption operations.
|
|
159
|
+
*
|
|
160
|
+
* Must be called after {@link identify}. Returns the token/context pair that
|
|
161
|
+
* `.withLockContext()` expects.
|
|
162
|
+
*
|
|
163
|
+
* @returns A `Result` containing the CTS token and identity context, or an error
|
|
164
|
+
* if {@link identify} has not been called.
|
|
165
|
+
*/
|
|
166
|
+
getLockContext(): Promise<Result<GetLockContextResponse, EncryptionError>>;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export { type ClientInitError as C, type DecryptionOperationError as D, EncryptionErrorTypes as E, type GetLockContextResponse as G, type IdentifyOptions as I, type LockContextError as L, type StackError as S, type EncryptionError as a, type EncryptionOperationError as b, type CtsTokenError as c, LockContext as d, type CtsRegions as e, type CtsToken as f, getErrorMessage as g, type Context as h, type LockContextOptions as i };
|