convex-secret-store 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/LICENSE +201 -0
- package/README.md +604 -0
- package/dist/client/_generated/_ignore.d.ts +1 -0
- package/dist/client/_generated/_ignore.d.ts.map +1 -0
- package/dist/client/_generated/_ignore.js +3 -0
- package/dist/client/_generated/_ignore.js.map +1 -0
- package/dist/client/base64.d.ts +3 -0
- package/dist/client/base64.d.ts.map +1 -0
- package/dist/client/base64.js +32 -0
- package/dist/client/base64.js.map +1 -0
- package/dist/client/crypto.d.ts +43 -0
- package/dist/client/crypto.d.ts.map +1 -0
- package/dist/client/crypto.js +133 -0
- package/dist/client/crypto.js.map +1 -0
- package/dist/client/errors.d.ts +14 -0
- package/dist/client/errors.d.ts.map +1 -0
- package/dist/client/errors.js +29 -0
- package/dist/client/errors.js.map +1 -0
- package/dist/client/index.d.ts +6 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +3 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/operations.d.ts +88 -0
- package/dist/client/operations.d.ts.map +1 -0
- package/dist/client/operations.js +388 -0
- package/dist/client/operations.js.map +1 -0
- package/dist/client/options.d.ts +27 -0
- package/dist/client/options.d.ts.map +1 -0
- package/dist/client/options.js +66 -0
- package/dist/client/options.js.map +1 -0
- package/dist/client/types.d.ts +133 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +2 -0
- package/dist/client/types.js.map +1 -0
- package/dist/component/_generated/api.d.ts +36 -0
- package/dist/component/_generated/api.d.ts.map +1 -0
- package/dist/component/_generated/api.js +31 -0
- package/dist/component/_generated/api.js.map +1 -0
- package/dist/component/_generated/component.d.ts +187 -0
- package/dist/component/_generated/component.d.ts.map +1 -0
- package/dist/component/_generated/component.js +11 -0
- package/dist/component/_generated/component.js.map +1 -0
- package/dist/component/_generated/dataModel.d.ts +46 -0
- package/dist/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/component/_generated/dataModel.js +11 -0
- package/dist/component/_generated/dataModel.js.map +1 -0
- package/dist/component/_generated/server.d.ts +121 -0
- package/dist/component/_generated/server.d.ts.map +1 -0
- package/dist/component/_generated/server.js +78 -0
- package/dist/component/_generated/server.js.map +1 -0
- package/dist/component/cleanup.d.ts +27 -0
- package/dist/component/cleanup.d.ts.map +1 -0
- package/dist/component/cleanup.js +96 -0
- package/dist/component/cleanup.js.map +1 -0
- package/dist/component/convex.config.d.ts +3 -0
- package/dist/component/convex.config.d.ts.map +1 -0
- package/dist/component/convex.config.js +3 -0
- package/dist/component/convex.config.js.map +1 -0
- package/dist/component/lib.d.ts +177 -0
- package/dist/component/lib.d.ts.map +1 -0
- package/dist/component/lib.js +531 -0
- package/dist/component/lib.js.map +1 -0
- package/dist/component/schema.d.ts +73 -0
- package/dist/component/schema.d.ts.map +1 -0
- package/dist/component/schema.js +45 -0
- package/dist/component/schema.js.map +1 -0
- package/dist/shared.d.ts +7 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +12 -0
- package/dist/shared.js.map +1 -0
- package/package.json +115 -0
- package/src/client/_generated/_ignore.ts +1 -0
- package/src/client/base64.ts +37 -0
- package/src/client/crypto.ts +229 -0
- package/src/client/errors.ts +64 -0
- package/src/client/index.test.ts +480 -0
- package/src/client/index.ts +34 -0
- package/src/client/operations.ts +513 -0
- package/src/client/options.ts +110 -0
- package/src/client/setup.test.ts +26 -0
- package/src/client/types.ts +213 -0
- package/src/component/_generated/api.ts +52 -0
- package/src/component/_generated/component.ts +222 -0
- package/src/component/_generated/dataModel.ts +60 -0
- package/src/component/_generated/server.ts +156 -0
- package/src/component/cleanup.test.ts +91 -0
- package/src/component/cleanup.ts +124 -0
- package/src/component/convex.config.ts +3 -0
- package/src/component/lib.test.ts +202 -0
- package/src/component/lib.ts +659 -0
- package/src/component/schema.ts +48 -0
- package/src/component/setup.test.ts +11 -0
- package/src/shared.ts +28 -0
- package/src/test.ts +18 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { invalidArgumentError, runtimeUnavailableError } from "./errors.js";
|
|
2
|
+
import { decodeBase64, encodeBase64 } from "./base64.js";
|
|
3
|
+
const textEncoder = new TextEncoder();
|
|
4
|
+
const textDecoder = new TextDecoder();
|
|
5
|
+
function asBufferSource(bytes) {
|
|
6
|
+
const copy = new Uint8Array(bytes.byteLength);
|
|
7
|
+
copy.set(bytes);
|
|
8
|
+
return copy;
|
|
9
|
+
}
|
|
10
|
+
function getRuntimeCrypto() {
|
|
11
|
+
if (typeof globalThis.crypto === "undefined" ||
|
|
12
|
+
typeof globalThis.crypto.subtle === "undefined") {
|
|
13
|
+
throw runtimeUnavailableError("Web Crypto API is unavailable");
|
|
14
|
+
}
|
|
15
|
+
return globalThis.crypto;
|
|
16
|
+
}
|
|
17
|
+
export function base64UrlEncode(bytes) {
|
|
18
|
+
return encodeBase64(bytes)
|
|
19
|
+
.replace(/\+/g, "-")
|
|
20
|
+
.replace(/\//g, "_")
|
|
21
|
+
.replace(/=+$/g, "");
|
|
22
|
+
}
|
|
23
|
+
export function base64UrlDecode(input) {
|
|
24
|
+
return decodeBase64(input);
|
|
25
|
+
}
|
|
26
|
+
function utf8Bytes(value) {
|
|
27
|
+
return textEncoder.encode(value);
|
|
28
|
+
}
|
|
29
|
+
function buildAadParts(namespace, name) {
|
|
30
|
+
return [namespace ?? null, name];
|
|
31
|
+
}
|
|
32
|
+
export function buildValueAAD(namespace, name) {
|
|
33
|
+
return utf8Bytes(JSON.stringify(["value", ...buildAadParts(namespace, name)]));
|
|
34
|
+
}
|
|
35
|
+
export function buildDekAAD(namespace, name, keyVersion) {
|
|
36
|
+
return utf8Bytes(JSON.stringify(["dek", ...buildAadParts(namespace, name), keyVersion]));
|
|
37
|
+
}
|
|
38
|
+
export async function importKey(rawKeyBase64) {
|
|
39
|
+
const bytes = decodeBase64(rawKeyBase64);
|
|
40
|
+
if (bytes.byteLength !== 32) {
|
|
41
|
+
throw invalidArgumentError("KEK must decode to exactly 32 bytes");
|
|
42
|
+
}
|
|
43
|
+
return await getRuntimeCrypto().subtle.importKey("raw", asBufferSource(bytes), "AES-GCM", false, ["encrypt", "decrypt"]);
|
|
44
|
+
}
|
|
45
|
+
export function generateDEK() {
|
|
46
|
+
const bytes = new Uint8Array(32);
|
|
47
|
+
getRuntimeCrypto().getRandomValues(bytes);
|
|
48
|
+
return bytes;
|
|
49
|
+
}
|
|
50
|
+
export function generateIV() {
|
|
51
|
+
const bytes = new Uint8Array(12);
|
|
52
|
+
getRuntimeCrypto().getRandomValues(bytes);
|
|
53
|
+
return bytes;
|
|
54
|
+
}
|
|
55
|
+
async function importDekKey(dek) {
|
|
56
|
+
return await getRuntimeCrypto().subtle.importKey("raw", asBufferSource(dek), "AES-GCM", false, ["encrypt", "decrypt"]);
|
|
57
|
+
}
|
|
58
|
+
async function encryptRaw(params) {
|
|
59
|
+
const ciphertext = await getRuntimeCrypto().subtle.encrypt({
|
|
60
|
+
name: "AES-GCM",
|
|
61
|
+
iv: asBufferSource(params.iv),
|
|
62
|
+
additionalData: asBufferSource(params.aad),
|
|
63
|
+
}, params.key, asBufferSource(params.plaintext));
|
|
64
|
+
return new Uint8Array(ciphertext);
|
|
65
|
+
}
|
|
66
|
+
async function decryptRaw(params) {
|
|
67
|
+
const plaintext = await getRuntimeCrypto().subtle.decrypt({
|
|
68
|
+
name: "AES-GCM",
|
|
69
|
+
iv: asBufferSource(params.iv),
|
|
70
|
+
additionalData: asBufferSource(params.aad),
|
|
71
|
+
}, params.key, asBufferSource(params.ciphertext));
|
|
72
|
+
return new Uint8Array(plaintext);
|
|
73
|
+
}
|
|
74
|
+
export async function encryptSecret(params) {
|
|
75
|
+
const dek = generateDEK();
|
|
76
|
+
const valueIv = generateIV();
|
|
77
|
+
const dekIv = generateIV();
|
|
78
|
+
const dekKey = await importDekKey(dek);
|
|
79
|
+
const encryptedValue = await encryptRaw({
|
|
80
|
+
key: dekKey,
|
|
81
|
+
iv: valueIv,
|
|
82
|
+
plaintext: utf8Bytes(params.value),
|
|
83
|
+
aad: buildValueAAD(params.namespace, params.name),
|
|
84
|
+
});
|
|
85
|
+
const wrappedDEK = await encryptRaw({
|
|
86
|
+
key: params.kek,
|
|
87
|
+
iv: dekIv,
|
|
88
|
+
plaintext: dek,
|
|
89
|
+
aad: buildDekAAD(params.namespace, params.name, params.keyVersion),
|
|
90
|
+
});
|
|
91
|
+
return {
|
|
92
|
+
encryptedValue: base64UrlEncode(encryptedValue),
|
|
93
|
+
iv: base64UrlEncode(valueIv),
|
|
94
|
+
wrappedDEK: base64UrlEncode(wrappedDEK),
|
|
95
|
+
dekIv: base64UrlEncode(dekIv),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
export async function decryptSecret(params) {
|
|
99
|
+
const dek = await decryptRaw({
|
|
100
|
+
key: params.kek,
|
|
101
|
+
iv: base64UrlDecode(params.dekIv),
|
|
102
|
+
ciphertext: base64UrlDecode(params.wrappedDEK),
|
|
103
|
+
aad: buildDekAAD(params.namespace, params.name, params.keyVersion),
|
|
104
|
+
});
|
|
105
|
+
const dekKey = await importDekKey(dek);
|
|
106
|
+
const plaintext = await decryptRaw({
|
|
107
|
+
key: dekKey,
|
|
108
|
+
iv: base64UrlDecode(params.iv),
|
|
109
|
+
ciphertext: base64UrlDecode(params.encryptedValue),
|
|
110
|
+
aad: buildValueAAD(params.namespace, params.name),
|
|
111
|
+
});
|
|
112
|
+
return textDecoder.decode(plaintext);
|
|
113
|
+
}
|
|
114
|
+
export async function rewrapDEK(params) {
|
|
115
|
+
const dek = await decryptRaw({
|
|
116
|
+
key: params.fromKek,
|
|
117
|
+
iv: base64UrlDecode(params.dekIv),
|
|
118
|
+
ciphertext: base64UrlDecode(params.wrappedDEK),
|
|
119
|
+
aad: buildDekAAD(params.namespace, params.name, params.fromVersion),
|
|
120
|
+
});
|
|
121
|
+
const nextIv = generateIV();
|
|
122
|
+
const wrappedDEK = await encryptRaw({
|
|
123
|
+
key: params.toKek,
|
|
124
|
+
iv: nextIv,
|
|
125
|
+
plaintext: dek,
|
|
126
|
+
aad: buildDekAAD(params.namespace, params.name, params.toVersion),
|
|
127
|
+
});
|
|
128
|
+
return {
|
|
129
|
+
wrappedDEK: base64UrlEncode(wrappedDEK),
|
|
130
|
+
dekIv: base64UrlEncode(nextIv),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=crypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../src/client/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEzD,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AACtC,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AAEtC,SAAS,cAAc,CAAC,KAAiB;IACvC,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAC9C,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAChB,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,gBAAgB;IACvB,IACE,OAAO,UAAU,CAAC,MAAM,KAAK,WAAW;QACxC,OAAO,UAAU,CAAC,MAAM,CAAC,MAAM,KAAK,WAAW,EAC/C,CAAC;QACD,MAAM,uBAAuB,CAAC,+BAA+B,CAAC,CAAC;IACjE,CAAC;IACD,OAAO,UAAU,CAAC,MAAM,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,KAAiB;IAC/C,OAAO,YAAY,CAAC,KAAK,CAAC;SACvB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;SACnB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;SACnB,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AACzB,CA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+
export type SecretStoreClientErrorCode = "INVALID_OPTIONS" | "INVALID_ARGUMENT" | "KEY_VERSION_UNAVAILABLE" | "RUNTIME_UNAVAILABLE" | "OPERATION_FAILED";
|
|
2
|
+
export declare class SecretStoreClientError extends Error {
|
|
3
|
+
readonly name = "SecretStoreClientError";
|
|
4
|
+
readonly code: SecretStoreClientErrorCode;
|
|
5
|
+
readonly cause?: unknown;
|
|
6
|
+
constructor(code: SecretStoreClientErrorCode, message: string, cause?: unknown);
|
|
7
|
+
}
|
|
8
|
+
export declare function isSecretStoreClientError(error: unknown): error is SecretStoreClientError;
|
|
9
|
+
export declare function optionsError(message: string): SecretStoreClientError;
|
|
10
|
+
export declare function invalidArgumentError(message: string): SecretStoreClientError;
|
|
11
|
+
export declare function keyVersionUnavailableError(version: number): SecretStoreClientError;
|
|
12
|
+
export declare function runtimeUnavailableError(message: string): SecretStoreClientError;
|
|
13
|
+
export declare function operationFailedError(message: string, cause: unknown): SecretStoreClientError;
|
|
14
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/client/errors.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,0BAA0B,GAClC,iBAAiB,GACjB,kBAAkB,GAClB,yBAAyB,GACzB,qBAAqB,GACrB,kBAAkB,CAAC;AAEvB,qBAAa,sBAAuB,SAAQ,KAAK;IAC/C,QAAQ,CAAC,IAAI,4BAA4B;IACzC,QAAQ,CAAC,IAAI,EAAE,0BAA0B,CAAC;IAC1C,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;gBAGvB,IAAI,EAAE,0BAA0B,EAChC,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,OAAO;CAMlB;AAED,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,sBAAsB,CAEjC;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,0BAK3C;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,0BAKnD;AAED,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,MAAM,0BAKzD;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,0BAKtD;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,0BAMnE"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export class SecretStoreClientError extends Error {
|
|
2
|
+
name = "SecretStoreClientError";
|
|
3
|
+
code;
|
|
4
|
+
cause;
|
|
5
|
+
constructor(code, message, cause) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.code = code;
|
|
8
|
+
this.cause = cause;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export function isSecretStoreClientError(error) {
|
|
12
|
+
return error instanceof SecretStoreClientError;
|
|
13
|
+
}
|
|
14
|
+
export function optionsError(message) {
|
|
15
|
+
return new SecretStoreClientError("INVALID_OPTIONS", `secret-store options: ${message}`);
|
|
16
|
+
}
|
|
17
|
+
export function invalidArgumentError(message) {
|
|
18
|
+
return new SecretStoreClientError("INVALID_ARGUMENT", `secret-store: ${message}`);
|
|
19
|
+
}
|
|
20
|
+
export function keyVersionUnavailableError(version) {
|
|
21
|
+
return new SecretStoreClientError("KEY_VERSION_UNAVAILABLE", `secret-store: key version ${version} is not configured`);
|
|
22
|
+
}
|
|
23
|
+
export function runtimeUnavailableError(message) {
|
|
24
|
+
return new SecretStoreClientError("RUNTIME_UNAVAILABLE", `secret-store runtime: ${message}`);
|
|
25
|
+
}
|
|
26
|
+
export function operationFailedError(message, cause) {
|
|
27
|
+
return new SecretStoreClientError("OPERATION_FAILED", `secret-store operation failed: ${message}`, cause);
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/client/errors.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IACtC,IAAI,GAAG,wBAAwB,CAAC;IAChC,IAAI,CAA6B;IACjC,KAAK,CAAW;IAEzB,YACE,IAAgC,EAChC,OAAe,EACf,KAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AAED,MAAM,UAAU,wBAAwB,CACtC,KAAc;IAEd,OAAO,KAAK,YAAY,sBAAsB,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,OAAe;IAC1C,OAAO,IAAI,sBAAsB,CAC/B,iBAAiB,EACjB,yBAAyB,OAAO,EAAE,CACnC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,OAAe;IAClD,OAAO,IAAI,sBAAsB,CAC/B,kBAAkB,EAClB,iBAAiB,OAAO,EAAE,CAC3B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,OAAe;IACxD,OAAO,IAAI,sBAAsB,CAC/B,yBAAyB,EACzB,6BAA6B,OAAO,oBAAoB,CACzD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,OAAe;IACrD,OAAO,IAAI,sBAAsB,CAC/B,qBAAqB,EACrB,yBAAyB,OAAO,EAAE,CACnC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,OAAe,EAAE,KAAc;IAClE,OAAO,IAAI,sBAAsB,CAC/B,kBAAkB,EAClB,kCAAkC,OAAO,EAAE,EAC3C,KAAK,CACN,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { SecretStore, SecretStore as default } from "./operations.js";
|
|
2
|
+
export { SecretStoreClientError, isSecretStoreClientError } from "./errors.js";
|
|
3
|
+
export type { SecretStoreClientErrorCode } from "./errors.js";
|
|
4
|
+
export type { SecretStoreOptions } from "./options.js";
|
|
5
|
+
export type { CleanupEventsArgs, CleanupEventsResult, CleanupSecretsArgs, CleanupSecretsResult, GetArgs, GetResult, HasArgs, ListArgs, ListEventsArgs, ListEventsResult, ListResult, PaginationOptions, PutArgs, PutResult, RemoveArgs, RemoveResult, RotateKeysArgs, RotateKeysResult, RunMutationCtx, RunQueryCtx, RunReadWriteCtx, SecretId, SecretStoreTypeOptions, UpdateArgs, UpdateResult, } from "./types.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,IAAI,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAEtE,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAE/E,YAAY,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAC9D,YAAY,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEvD,YAAY,EACV,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,OAAO,EACP,SAAS,EACT,OAAO,EACP,QAAQ,EACR,cAAc,EACd,gBAAgB,EAChB,UAAU,EACV,iBAAiB,EACjB,OAAO,EACP,SAAS,EACT,UAAU,EACV,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,eAAe,EACf,QAAQ,EACR,sBAAsB,EACtB,UAAU,EACV,YAAY,GACb,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,IAAI,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAEtE,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { ComponentApi } from "../component/_generated/component.js";
|
|
2
|
+
import { type NormalizedSecretStoreOptions, type SecretStoreOptions } from "./options.js";
|
|
3
|
+
import type { CleanupEventsArgs, CleanupEventsResult, CleanupSecretsArgs, CleanupSecretsResult, GetArgs, GetResult, HasArgs, ListArgs, ListEventsArgs, ListEventsResult, ListResult, PutArgs, PutResult, RemoveArgs, RemoveResult, RotateKeysArgs, RotateKeysResult, RunMutationCtx, RunQueryCtx, UpdateArgs, UpdateResult, SecretStoreTypeOptions } from "./types.js";
|
|
4
|
+
export declare class SecretStore<TOptions extends SecretStoreTypeOptions = Record<never, never>> {
|
|
5
|
+
readonly component: ComponentApi;
|
|
6
|
+
readonly options: NormalizedSecretStoreOptions;
|
|
7
|
+
private readonly kekCache;
|
|
8
|
+
/**
|
|
9
|
+
* Create a typed SecretStore client for a mounted component instance.
|
|
10
|
+
*
|
|
11
|
+
* `keys` must contain one or more versioned KEKs. The first entry is the
|
|
12
|
+
* active key used for new writes; later entries are decrypt-only keys used to
|
|
13
|
+
* read older rows and rotate them forward.
|
|
14
|
+
*/
|
|
15
|
+
constructor(component: ComponentApi, options: SecretStoreOptions<TOptions>);
|
|
16
|
+
private getKEK;
|
|
17
|
+
/**
|
|
18
|
+
* Encrypt and store a secret value.
|
|
19
|
+
*
|
|
20
|
+
* The plaintext is encrypted client-side with a fresh DEK, that DEK is wrapped
|
|
21
|
+
* with the active KEK, and only ciphertext fields are persisted in Convex.
|
|
22
|
+
* When a secret with the same `namespace + name` already exists, the row is
|
|
23
|
+
* replaced in place and an `updated` audit event is written.
|
|
24
|
+
*/
|
|
25
|
+
put(ctx: RunMutationCtx, args: PutArgs<TOptions>): Promise<PutResult>;
|
|
26
|
+
/**
|
|
27
|
+
* Load and decrypt a secret value.
|
|
28
|
+
*
|
|
29
|
+
* Returns `not_found` or `expired` when the backend row is unavailable for
|
|
30
|
+
* use. Returns `key_version_unavailable` when the row exists but the current
|
|
31
|
+
* runtime is missing the KEK version required to unwrap it.
|
|
32
|
+
*/
|
|
33
|
+
get(ctx: RunQueryCtx, args: GetArgs<TOptions>): Promise<GetResult<TOptions>>;
|
|
34
|
+
/**
|
|
35
|
+
* Check whether a usable secret exists.
|
|
36
|
+
*
|
|
37
|
+
* This is an expiry-aware existence check: expired rows return `false`.
|
|
38
|
+
*/
|
|
39
|
+
has(ctx: RunQueryCtx, args: HasArgs<TOptions>): Promise<boolean>;
|
|
40
|
+
remove(ctx: RunMutationCtx, args: RemoveArgs<TOptions>): Promise<RemoveResult>;
|
|
41
|
+
/**
|
|
42
|
+
* Update plaintext metadata or expiry without rewriting encrypted value bytes.
|
|
43
|
+
*
|
|
44
|
+
* Pass `null` for `metadata` or `expiresAt` to remove those fields entirely.
|
|
45
|
+
*/
|
|
46
|
+
update(ctx: RunMutationCtx, args: UpdateArgs<TOptions>): Promise<UpdateResult>;
|
|
47
|
+
/**
|
|
48
|
+
* List secrets in one namespace.
|
|
49
|
+
*
|
|
50
|
+
* Results are ordered by `updatedAt` and include `effectiveState` so callers
|
|
51
|
+
* can distinguish active and expired rows without additional filtering.
|
|
52
|
+
*/
|
|
53
|
+
list(ctx: RunQueryCtx, args: ListArgs<TOptions>): Promise<ListResult<TOptions>>;
|
|
54
|
+
/**
|
|
55
|
+
* List audit events for a namespace or one specific secret.
|
|
56
|
+
*
|
|
57
|
+
* In V1, `name` and `type` cannot be combined in the same query. When using a
|
|
58
|
+
* namespaced client, normal event listing requires `namespace`; the only
|
|
59
|
+
* namespace-less variant is a direct `secretId` lookup.
|
|
60
|
+
*/
|
|
61
|
+
listEvents(ctx: RunQueryCtx, args: ListEventsArgs<TOptions>): Promise<ListEventsResult<TOptions>>;
|
|
62
|
+
/**
|
|
63
|
+
* Rewrap rows from one KEK version onto the active KEK version.
|
|
64
|
+
*
|
|
65
|
+
* This operation does not rewrite encrypted secret plaintext. It only unwraps
|
|
66
|
+
* each row's stored DEK with `fromVersion` and rewraps that DEK with the
|
|
67
|
+
* active version. Concurrent writes are protected with compare-and-swap checks;
|
|
68
|
+
* stale rows are skipped safely and can be retried in later batches.
|
|
69
|
+
*/
|
|
70
|
+
rotateKeys(ctx: RunMutationCtx & RunQueryCtx, args: RotateKeysArgs): Promise<RotateKeysResult>;
|
|
71
|
+
/**
|
|
72
|
+
* Hard-delete expired secrets that have been past their expiry timestamp for
|
|
73
|
+
* at least the retention window.
|
|
74
|
+
*
|
|
75
|
+
* The cleanup mutation processes up to 100 rows per run and automatically
|
|
76
|
+
* reschedules itself while backlog remains. Deleting an expired secret writes
|
|
77
|
+
* a final `deleted` audit event with `deletedReason: "expired_cleanup"`.
|
|
78
|
+
*/
|
|
79
|
+
cleanupSecrets(ctx: RunMutationCtx, args?: CleanupSecretsArgs): Promise<CleanupSecretsResult>;
|
|
80
|
+
/**
|
|
81
|
+
* Hard-delete audit events older than the retention window.
|
|
82
|
+
*
|
|
83
|
+
* Event cleanup is independent from secret cleanup and may keep audit rows
|
|
84
|
+
* for much longer than expired secret rows remain in storage.
|
|
85
|
+
*/
|
|
86
|
+
cleanupEvents(ctx: RunMutationCtx, args?: CleanupEventsArgs): Promise<CleanupEventsResult>;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=operations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../src/client/operations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AAYzE,OAAO,EAGL,KAAK,4BAA4B,EACjC,KAAK,kBAAkB,EACxB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EACV,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,OAAO,EACP,SAAS,EACT,OAAO,EACP,QAAQ,EACR,cAAc,EACd,gBAAgB,EAChB,UAAU,EACV,OAAO,EACP,SAAS,E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