@shipfox/api-secrets 2.0.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/.turbo/turbo-build.log +2 -0
- package/.turbo/turbo-type$colon$emit.log +1 -0
- package/.turbo/turbo-type.log +1 -0
- package/CHANGELOG.md +116 -0
- package/LICENSE +21 -0
- package/README.md +207 -0
- package/dist/config.d.ts +8 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +38 -0
- package/dist/config.js.map +1 -0
- package/dist/core/crypto.d.ts +25 -0
- package/dist/core/crypto.d.ts.map +1 -0
- package/dist/core/crypto.js +85 -0
- package/dist/core/crypto.js.map +1 -0
- package/dist/core/dek-manager.d.ts +16 -0
- package/dist/core/dek-manager.d.ts.map +1 -0
- package/dist/core/dek-manager.js +85 -0
- package/dist/core/dek-manager.js.map +1 -0
- package/dist/core/errors.d.ts +53 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +86 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/fingerprint.d.ts +2 -0
- package/dist/core/fingerprint.d.ts.map +1 -0
- package/dist/core/fingerprint.js +9 -0
- package/dist/core/fingerprint.js.map +1 -0
- package/dist/core/index.d.ts +30 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +97 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/key-provider.d.ts +17 -0
- package/dist/core/key-provider.d.ts.map +1 -0
- package/dist/core/key-provider.js +45 -0
- package/dist/core/key-provider.js.map +1 -0
- package/dist/core/local-secret-store.d.ts +19 -0
- package/dist/core/local-secret-store.d.ts.map +1 -0
- package/dist/core/local-secret-store.js +40 -0
- package/dist/core/local-secret-store.js.map +1 -0
- package/dist/core/management.d.ts +37 -0
- package/dist/core/management.d.ts.map +1 -0
- package/dist/core/management.js +403 -0
- package/dist/core/management.js.map +1 -0
- package/dist/core/rotate-kek.d.ts +10 -0
- package/dist/core/rotate-kek.d.ts.map +1 -0
- package/dist/core/rotate-kek.js +94 -0
- package/dist/core/rotate-kek.js.map +1 -0
- package/dist/core/secret-store.d.ts +33 -0
- package/dist/core/secret-store.d.ts.map +1 -0
- package/dist/core/secret-store.js +209 -0
- package/dist/core/secret-store.js.map +1 -0
- package/dist/core/store-resolver.d.ts +18 -0
- package/dist/core/store-resolver.d.ts.map +1 -0
- package/dist/core/store-resolver.js +10 -0
- package/dist/core/store-resolver.js.map +1 -0
- package/dist/core/store-validation.d.ts +11 -0
- package/dist/core/store-validation.d.ts.map +1 -0
- package/dist/core/store-validation.js +30 -0
- package/dist/core/store-validation.js.map +1 -0
- package/dist/core/value-cipher.d.ts +10 -0
- package/dist/core/value-cipher.d.ts.map +1 -0
- package/dist/core/value-cipher.js +22 -0
- package/dist/core/value-cipher.js.map +1 -0
- package/dist/core/variable-store.d.ts +24 -0
- package/dist/core/variable-store.d.ts.map +1 -0
- package/dist/core/variable-store.js +194 -0
- package/dist/core/variable-store.js.map +1 -0
- package/dist/db/cap.d.ts +8 -0
- package/dist/db/cap.d.ts.map +1 -0
- package/dist/db/cap.js +39 -0
- package/dist/db/cap.js.map +1 -0
- package/dist/db/data-keys.d.ts +24 -0
- package/dist/db/data-keys.d.ts.map +1 -0
- package/dist/db/data-keys.js +61 -0
- package/dist/db/data-keys.js.map +1 -0
- package/dist/db/db.d.ts +1254 -0
- package/dist/db/db.d.ts.map +1 -0
- package/dist/db/db.js +24 -0
- package/dist/db/db.js.map +1 -0
- package/dist/db/index.d.ts +13 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +15 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/management.d.ts +50 -0
- package/dist/db/management.d.ts.map +1 -0
- package/dist/db/management.js +127 -0
- package/dist/db/management.js.map +1 -0
- package/dist/db/schema/common.d.ts +3 -0
- package/dist/db/schema/common.d.ts.map +1 -0
- package/dist/db/schema/common.js +8 -0
- package/dist/db/schema/common.js.map +1 -0
- package/dist/db/schema/data-keys.d.ts +103 -0
- package/dist/db/schema/data-keys.d.ts.map +1 -0
- package/dist/db/schema/data-keys.js +24 -0
- package/dist/db/schema/data-keys.js.map +1 -0
- package/dist/db/schema/outbox.d.ts +195 -0
- package/dist/db/schema/outbox.d.ts.map +1 -0
- package/dist/db/schema/outbox.js +5 -0
- package/dist/db/schema/outbox.js.map +1 -0
- package/dist/db/schema/values.d.ts +193 -0
- package/dist/db/schema/values.d.ts.map +1 -0
- package/dist/db/schema/values.js +43 -0
- package/dist/db/schema/values.js.map +1 -0
- package/dist/db/schema/variables.d.ts +175 -0
- package/dist/db/schema/variables.d.ts.map +1 -0
- package/dist/db/schema/variables.js +41 -0
- package/dist/db/schema/variables.js.map +1 -0
- package/dist/db/scope.d.ts +20 -0
- package/dist/db/scope.d.ts.map +1 -0
- package/dist/db/scope.js +19 -0
- package/dist/db/scope.js.map +1 -0
- package/dist/db/values.d.ts +33 -0
- package/dist/db/values.d.ts.map +1 -0
- package/dist/db/values.js +119 -0
- package/dist/db/values.js.map +1 -0
- package/dist/db/variables.d.ts +32 -0
- package/dist/db/variables.d.ts.map +1 -0
- package/dist/db/variables.js +117 -0
- package/dist/db/variables.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/metrics/index.d.ts +3 -0
- package/dist/metrics/index.d.ts.map +1 -0
- package/dist/metrics/index.js +4 -0
- package/dist/metrics/index.js.map +1 -0
- package/dist/metrics/instance.d.ts +39 -0
- package/dist/metrics/instance.d.ts.map +1 -0
- package/dist/metrics/instance.js +151 -0
- package/dist/metrics/instance.js.map +1 -0
- package/dist/metrics/service.d.ts +2 -0
- package/dist/metrics/service.d.ts.map +1 -0
- package/dist/metrics/service.js +21 -0
- package/dist/metrics/service.js.map +1 -0
- package/dist/presentation/dto/index.d.ts +2 -0
- package/dist/presentation/dto/index.d.ts.map +1 -0
- package/dist/presentation/dto/index.js +3 -0
- package/dist/presentation/dto/index.js.map +1 -0
- package/dist/presentation/dto/management.d.ts +7 -0
- package/dist/presentation/dto/management.d.ts.map +1 -0
- package/dist/presentation/dto/management.js +32 -0
- package/dist/presentation/dto/management.js.map +1 -0
- package/dist/presentation/e2eRoutes/create-secret.d.ts +2 -0
- package/dist/presentation/e2eRoutes/create-secret.d.ts.map +1 -0
- package/dist/presentation/e2eRoutes/create-secret.js +34 -0
- package/dist/presentation/e2eRoutes/create-secret.js.map +1 -0
- package/dist/presentation/e2eRoutes/create-variable.d.ts +2 -0
- package/dist/presentation/e2eRoutes/create-variable.d.ts.map +1 -0
- package/dist/presentation/e2eRoutes/create-variable.js +34 -0
- package/dist/presentation/e2eRoutes/create-variable.js.map +1 -0
- package/dist/presentation/e2eRoutes/index.d.ts +3 -0
- package/dist/presentation/e2eRoutes/index.d.ts.map +1 -0
- package/dist/presentation/e2eRoutes/index.js +11 -0
- package/dist/presentation/e2eRoutes/index.js.map +1 -0
- package/dist/presentation/routes/auth.d.ts +16 -0
- package/dist/presentation/routes/auth.d.ts.map +1 -0
- package/dist/presentation/routes/auth.js +42 -0
- package/dist/presentation/routes/auth.js.map +1 -0
- package/dist/presentation/routes/batch-secrets.d.ts +2 -0
- package/dist/presentation/routes/batch-secrets.d.ts.map +1 -0
- package/dist/presentation/routes/batch-secrets.js +44 -0
- package/dist/presentation/routes/batch-secrets.js.map +1 -0
- package/dist/presentation/routes/batch-variables.d.ts +2 -0
- package/dist/presentation/routes/batch-variables.d.ts.map +1 -0
- package/dist/presentation/routes/batch-variables.js +44 -0
- package/dist/presentation/routes/batch-variables.js.map +1 -0
- package/dist/presentation/routes/cursor.d.ts +3 -0
- package/dist/presentation/routes/cursor.d.ts.map +1 -0
- package/dist/presentation/routes/cursor.js +19 -0
- package/dist/presentation/routes/cursor.js.map +1 -0
- package/dist/presentation/routes/delete-secret.d.ts +2 -0
- package/dist/presentation/routes/delete-secret.d.ts.map +1 -0
- package/dist/presentation/routes/delete-secret.js +40 -0
- package/dist/presentation/routes/delete-secret.js.map +1 -0
- package/dist/presentation/routes/delete-variable.d.ts +2 -0
- package/dist/presentation/routes/delete-variable.d.ts.map +1 -0
- package/dist/presentation/routes/delete-variable.js +40 -0
- package/dist/presentation/routes/delete-variable.js.map +1 -0
- package/dist/presentation/routes/errors.d.ts +2 -0
- package/dist/presentation/routes/errors.d.ts.map +1 -0
- package/dist/presentation/routes/errors.js +73 -0
- package/dist/presentation/routes/errors.js.map +1 -0
- package/dist/presentation/routes/get-variable.d.ts +2 -0
- package/dist/presentation/routes/get-variable.d.ts.map +1 -0
- package/dist/presentation/routes/get-variable.js +42 -0
- package/dist/presentation/routes/get-variable.js.map +1 -0
- package/dist/presentation/routes/index.d.ts +3 -0
- package/dist/presentation/routes/index.d.ts.map +1 -0
- package/dist/presentation/routes/index.js +29 -0
- package/dist/presentation/routes/index.js.map +1 -0
- package/dist/presentation/routes/list-secrets.d.ts +2 -0
- package/dist/presentation/routes/list-secrets.d.ts.map +1 -0
- package/dist/presentation/routes/list-secrets.js +50 -0
- package/dist/presentation/routes/list-secrets.js.map +1 -0
- package/dist/presentation/routes/list-variables.d.ts +2 -0
- package/dist/presentation/routes/list-variables.d.ts.map +1 -0
- package/dist/presentation/routes/list-variables.js +50 -0
- package/dist/presentation/routes/list-variables.js.map +1 -0
- package/dist/presentation/routes/put-secret.d.ts +2 -0
- package/dist/presentation/routes/put-secret.d.ts.map +1 -0
- package/dist/presentation/routes/put-secret.js +52 -0
- package/dist/presentation/routes/put-secret.js.map +1 -0
- package/dist/presentation/routes/put-variable.d.ts +2 -0
- package/dist/presentation/routes/put-variable.d.ts.map +1 -0
- package/dist/presentation/routes/put-variable.js +52 -0
- package/dist/presentation/routes/put-variable.js.map +1 -0
- package/dist/presentation/routes/warnings.d.ts +5 -0
- package/dist/presentation/routes/warnings.d.ts.map +1 -0
- package/dist/presentation/routes/warnings.js +16 -0
- package/dist/presentation/routes/warnings.js.map +1 -0
- package/dist/tsconfig.test.tsbuildinfo +1 -0
- package/drizzle/0000_lowly_ogun.sql +59 -0
- package/drizzle/meta/0000_snapshot.json +547 -0
- package/drizzle/meta/_journal.json +13 -0
- package/drizzle.config.ts +7 -0
- package/package.json +77 -0
- package/src/config.test.ts +41 -0
- package/src/config.ts +41 -0
- package/src/core/crypto.test.ts +115 -0
- package/src/core/crypto.ts +105 -0
- package/src/core/dek-manager.test.ts +120 -0
- package/src/core/dek-manager.ts +98 -0
- package/src/core/errors.ts +100 -0
- package/src/core/fingerprint.test.ts +27 -0
- package/src/core/fingerprint.ts +14 -0
- package/src/core/index.ts +153 -0
- package/src/core/key-provider.test.ts +44 -0
- package/src/core/key-provider.ts +70 -0
- package/src/core/local-secret-store.ts +49 -0
- package/src/core/management.test.ts +37 -0
- package/src/core/management.ts +503 -0
- package/src/core/rotate-kek.test.ts +183 -0
- package/src/core/rotate-kek.ts +100 -0
- package/src/core/secret-store.test.ts +301 -0
- package/src/core/secret-store.ts +251 -0
- package/src/core/store-resolver.test.ts +20 -0
- package/src/core/store-resolver.ts +28 -0
- package/src/core/store-validation.ts +43 -0
- package/src/core/value-cipher.ts +26 -0
- package/src/core/variable-store.test.ts +106 -0
- package/src/core/variable-store.ts +232 -0
- package/src/db/cap.ts +58 -0
- package/src/db/data-keys.ts +99 -0
- package/src/db/db.ts +26 -0
- package/src/db/index.ts +45 -0
- package/src/db/management.ts +252 -0
- package/src/db/schema/common.ts +8 -0
- package/src/db/schema/data-keys.ts +31 -0
- package/src/db/schema/outbox.ts +4 -0
- package/src/db/schema/values.ts +74 -0
- package/src/db/schema/variables.ts +71 -0
- package/src/db/scope.ts +42 -0
- package/src/db/values.ts +191 -0
- package/src/db/variables.ts +187 -0
- package/src/index.test.ts +11 -0
- package/src/index.ts +50 -0
- package/src/metrics/index.ts +19 -0
- package/src/metrics/instance.ts +219 -0
- package/src/metrics/service.ts +19 -0
- package/src/presentation/dto/index.ts +1 -0
- package/src/presentation/dto/management.ts +36 -0
- package/src/presentation/e2eRoutes/create-secret.ts +31 -0
- package/src/presentation/e2eRoutes/create-variable.ts +34 -0
- package/src/presentation/e2eRoutes/index.test.ts +94 -0
- package/src/presentation/e2eRoutes/index.ts +8 -0
- package/src/presentation/routes/auth.ts +50 -0
- package/src/presentation/routes/batch-secrets.ts +33 -0
- package/src/presentation/routes/batch-variables.ts +33 -0
- package/src/presentation/routes/cursor.ts +23 -0
- package/src/presentation/routes/delete-secret.ts +26 -0
- package/src/presentation/routes/delete-variable.ts +26 -0
- package/src/presentation/routes/errors.ts +63 -0
- package/src/presentation/routes/get-variable.ts +32 -0
- package/src/presentation/routes/index.ts +29 -0
- package/src/presentation/routes/list-secrets.ts +41 -0
- package/src/presentation/routes/list-variables.ts +41 -0
- package/src/presentation/routes/management.test.ts +452 -0
- package/src/presentation/routes/put-secret.ts +39 -0
- package/src/presentation/routes/put-variable.ts +39 -0
- package/src/presentation/routes/warnings.ts +23 -0
- package/test/env.ts +8 -0
- package/test/globalSetup.ts +18 -0
- package/test/setup.ts +17 -0
- package/tsconfig.build.json +10 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +7 -0
- package/tsconfig.test.json +8 -0
- package/vitest.config.ts +12 -0
package/dist/db/cap.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { and, count, eq, notLike, sql } from 'drizzle-orm';
|
|
2
|
+
import { db } from './db.js';
|
|
3
|
+
import { secretValues } from './schema/values.js';
|
|
4
|
+
import { secretVariables } from './schema/variables.js';
|
|
5
|
+
export async function countWorkspaceEntries(workspaceId, tx) {
|
|
6
|
+
const executor = tx ?? db();
|
|
7
|
+
const valueCount = executor.select({
|
|
8
|
+
count: count().as('value_count')
|
|
9
|
+
}).from(secretValues).where(and(eq(secretValues.workspaceId, workspaceId), notLike(secretValues.namespace, 'system/%'))).as('value_count');
|
|
10
|
+
const variableCount = executor.select({
|
|
11
|
+
count: count().as('variable_count')
|
|
12
|
+
}).from(secretVariables).where(and(eq(secretVariables.workspaceId, workspaceId), notLike(secretVariables.namespace, 'system/%'))).as('variable_count');
|
|
13
|
+
const [row] = await executor.select({
|
|
14
|
+
value: sql`${valueCount.count} + ${variableCount.count}`
|
|
15
|
+
}).from(valueCount).crossJoin(variableCount);
|
|
16
|
+
return Number(row?.value ?? 0);
|
|
17
|
+
}
|
|
18
|
+
export async function countPublicEntriesByResource(tx) {
|
|
19
|
+
const executor = tx ?? db();
|
|
20
|
+
const [secretCount, variableCount] = await Promise.all([
|
|
21
|
+
executor.select({
|
|
22
|
+
count: count().as('secret_count')
|
|
23
|
+
}).from(secretValues).where(notLike(secretValues.namespace, 'system/%')),
|
|
24
|
+
executor.select({
|
|
25
|
+
count: count().as('variable_count')
|
|
26
|
+
}).from(secretVariables).where(notLike(secretVariables.namespace, 'system/%'))
|
|
27
|
+
]);
|
|
28
|
+
return {
|
|
29
|
+
secrets: Number(secretCount[0]?.count ?? 0),
|
|
30
|
+
variables: Number(variableCount[0]?.count ?? 0)
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export async function lockWorkspaceEntries(workspaceId, tx) {
|
|
34
|
+
await tx.execute(sql`
|
|
35
|
+
SELECT pg_advisory_xact_lock(hashtext('shipfox_secrets_workspace_cap'), hashtext(${workspaceId}))
|
|
36
|
+
`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=cap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/db/cap.ts"],"sourcesContent":["import {and, count, eq, notLike, sql} from 'drizzle-orm';\nimport {db, type Tx} from './db.js';\nimport {secretValues} from './schema/values.js';\nimport {secretVariables} from './schema/variables.js';\n\nexport async function countWorkspaceEntries(workspaceId: string, tx?: Tx): Promise<number> {\n const executor = tx ?? db();\n const valueCount = executor\n .select({count: count().as('value_count')})\n .from(secretValues)\n .where(\n and(eq(secretValues.workspaceId, workspaceId), notLike(secretValues.namespace, 'system/%')),\n )\n .as('value_count');\n const variableCount = executor\n .select({count: count().as('variable_count')})\n .from(secretVariables)\n .where(\n and(\n eq(secretVariables.workspaceId, workspaceId),\n notLike(secretVariables.namespace, 'system/%'),\n ),\n )\n .as('variable_count');\n const [row] = await executor\n .select({value: sql<number>`${valueCount.count} + ${variableCount.count}`})\n .from(valueCount)\n .crossJoin(variableCount);\n\n return Number(row?.value ?? 0);\n}\n\nexport async function countPublicEntriesByResource(\n tx?: Tx,\n): Promise<{secrets: number; variables: number}> {\n const executor = tx ?? db();\n const [secretCount, variableCount] = await Promise.all([\n executor\n .select({count: count().as('secret_count')})\n .from(secretValues)\n .where(notLike(secretValues.namespace, 'system/%')),\n executor\n .select({count: count().as('variable_count')})\n .from(secretVariables)\n .where(notLike(secretVariables.namespace, 'system/%')),\n ]);\n\n return {\n secrets: Number(secretCount[0]?.count ?? 0),\n variables: Number(variableCount[0]?.count ?? 0),\n };\n}\n\nexport async function lockWorkspaceEntries(workspaceId: string, tx: Tx): Promise<void> {\n await tx.execute(sql`\n SELECT pg_advisory_xact_lock(hashtext('shipfox_secrets_workspace_cap'), hashtext(${workspaceId}))\n `);\n}\n"],"names":["and","count","eq","notLike","sql","db","secretValues","secretVariables","countWorkspaceEntries","workspaceId","tx","executor","valueCount","select","as","from","where","namespace","variableCount","row","value","crossJoin","Number","countPublicEntriesByResource","secretCount","Promise","all","secrets","variables","lockWorkspaceEntries","execute"],"mappings":"AAAA,SAAQA,GAAG,EAAEC,KAAK,EAAEC,EAAE,EAAEC,OAAO,EAAEC,GAAG,QAAO,cAAc;AACzD,SAAQC,EAAE,QAAgB,UAAU;AACpC,SAAQC,YAAY,QAAO,qBAAqB;AAChD,SAAQC,eAAe,QAAO,wBAAwB;AAEtD,OAAO,eAAeC,sBAAsBC,WAAmB,EAAEC,EAAO;IACtE,MAAMC,WAAWD,MAAML;IACvB,MAAMO,aAAaD,SAChBE,MAAM,CAAC;QAACZ,OAAOA,QAAQa,EAAE,CAAC;IAAc,GACxCC,IAAI,CAACT,cACLU,KAAK,CACJhB,IAAIE,GAAGI,aAAaG,WAAW,EAA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
|
2
|
+
import { type DataKey } from './schema/data-keys.js';
|
|
3
|
+
export declare function getDataKey(workspaceId: string, tx?: Tx): Promise<DataKey | undefined>;
|
|
4
|
+
export declare function insertDataKeyIfAbsent(dataKey: {
|
|
5
|
+
workspaceId: string;
|
|
6
|
+
wrappedDek: string;
|
|
7
|
+
kekVersion: string;
|
|
8
|
+
}, tx?: Tx): Promise<boolean>;
|
|
9
|
+
export declare function updateDataKeyWrapCas(params: {
|
|
10
|
+
workspaceId: string;
|
|
11
|
+
oldKekVersion: string;
|
|
12
|
+
wrappedDek: string;
|
|
13
|
+
kekVersion: string;
|
|
14
|
+
}, tx?: Tx): Promise<boolean>;
|
|
15
|
+
export declare function listDataKeyVersions(knownVersions: string[], params?: {
|
|
16
|
+
workspaceIds?: string[] | undefined;
|
|
17
|
+
}): Promise<string[]>;
|
|
18
|
+
export declare function listDataKeysPage(params: {
|
|
19
|
+
afterWorkspaceId?: string | undefined;
|
|
20
|
+
limit: number;
|
|
21
|
+
versions?: string[] | undefined;
|
|
22
|
+
workspaceIds?: string[] | undefined;
|
|
23
|
+
}): Promise<DataKey[]>;
|
|
24
|
+
//# sourceMappingURL=data-keys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-keys.d.ts","sourceRoot":"","sources":["../../src/db/data-keys.ts"],"names":[],"mappings":"AACA,OAAO,EAAK,KAAK,EAAE,EAAC,MAAM,SAAS,CAAC;AACpC,OAAO,EAAC,KAAK,OAAO,EAA4B,MAAM,uBAAuB,CAAC;AAE9E,wBAAsB,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,EAAE,GAAG,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAS3F;AAED,wBAAsB,qBAAqB,CACzC,OAAO,EAAE;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAC,EACtE,EAAE,CAAC,EAAE,EAAE,GACN,OAAO,CAAC,OAAO,CAAC,CAUlB;AAED,wBAAsB,oBAAoB,CACxC,MAAM,EAAE;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAC,EAC5F,EAAE,CAAC,EAAE,EAAE,GACN,OAAO,CAAC,OAAO,CAAC,CAiBlB;AAED,wBAAsB,mBAAmB,CACvC,aAAa,EAAE,MAAM,EAAE,EACvB,MAAM,GAAE;IAAC,YAAY,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;CAAM,GACjD,OAAO,CAAC,MAAM,EAAE,CAAC,CAenB;AAED,wBAAsB,gBAAgB,CAAC,MAAM,EAAE;IAC7C,gBAAgB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAChC,YAAY,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;CACrC,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAqBrB"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { and, eq, gt, inArray, notInArray, sql } from 'drizzle-orm';
|
|
2
|
+
import { db } from './db.js';
|
|
3
|
+
import { secretDataKeys, toDataKey } from './schema/data-keys.js';
|
|
4
|
+
export async function getDataKey(workspaceId, tx) {
|
|
5
|
+
const executor = tx ?? db();
|
|
6
|
+
const rows = await executor.select().from(secretDataKeys).where(eq(secretDataKeys.workspaceId, workspaceId)).limit(1);
|
|
7
|
+
const row = rows[0];
|
|
8
|
+
return row ? toDataKey(row) : undefined;
|
|
9
|
+
}
|
|
10
|
+
export async function insertDataKeyIfAbsent(dataKey, tx) {
|
|
11
|
+
const executor = tx ?? db();
|
|
12
|
+
const rows = await executor.insert(secretDataKeys).values(dataKey).onConflictDoNothing({
|
|
13
|
+
target: secretDataKeys.workspaceId
|
|
14
|
+
}).returning({
|
|
15
|
+
workspaceId: secretDataKeys.workspaceId
|
|
16
|
+
});
|
|
17
|
+
return rows.length > 0;
|
|
18
|
+
}
|
|
19
|
+
export async function updateDataKeyWrapCas(params, tx) {
|
|
20
|
+
const executor = tx ?? db();
|
|
21
|
+
const rows = await executor.update(secretDataKeys).set({
|
|
22
|
+
wrappedDek: params.wrappedDek,
|
|
23
|
+
kekVersion: params.kekVersion,
|
|
24
|
+
rotatedAt: sql`NOW()`
|
|
25
|
+
}).where(and(eq(secretDataKeys.workspaceId, params.workspaceId), eq(secretDataKeys.kekVersion, params.oldKekVersion))).returning({
|
|
26
|
+
workspaceId: secretDataKeys.workspaceId
|
|
27
|
+
});
|
|
28
|
+
return rows.length > 0;
|
|
29
|
+
}
|
|
30
|
+
export async function listDataKeyVersions(knownVersions, params = {}) {
|
|
31
|
+
if (params.workspaceIds?.length === 0) return [];
|
|
32
|
+
const filters = [];
|
|
33
|
+
if (knownVersions.length > 0) {
|
|
34
|
+
filters.push(notInArray(secretDataKeys.kekVersion, knownVersions));
|
|
35
|
+
}
|
|
36
|
+
if (params.workspaceIds) {
|
|
37
|
+
filters.push(inArray(secretDataKeys.workspaceId, params.workspaceIds));
|
|
38
|
+
}
|
|
39
|
+
const rows = await db().selectDistinct({
|
|
40
|
+
kekVersion: secretDataKeys.kekVersion
|
|
41
|
+
}).from(secretDataKeys).where(filters.length > 0 ? and(...filters) : undefined);
|
|
42
|
+
return rows.map((row)=>row.kekVersion);
|
|
43
|
+
}
|
|
44
|
+
export async function listDataKeysPage(params) {
|
|
45
|
+
if (params.versions && params.versions.length === 0) return [];
|
|
46
|
+
if (params.workspaceIds?.length === 0) return [];
|
|
47
|
+
const filters = [];
|
|
48
|
+
if (params.afterWorkspaceId) {
|
|
49
|
+
filters.push(gt(secretDataKeys.workspaceId, params.afterWorkspaceId));
|
|
50
|
+
}
|
|
51
|
+
if (params.versions) {
|
|
52
|
+
filters.push(inArray(secretDataKeys.kekVersion, params.versions));
|
|
53
|
+
}
|
|
54
|
+
if (params.workspaceIds) {
|
|
55
|
+
filters.push(inArray(secretDataKeys.workspaceId, params.workspaceIds));
|
|
56
|
+
}
|
|
57
|
+
const rows = await db().select().from(secretDataKeys).where(filters.length > 0 ? and(...filters) : undefined).orderBy(secretDataKeys.workspaceId).limit(params.limit);
|
|
58
|
+
return rows.map(toDataKey);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=data-keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/db/data-keys.ts"],"sourcesContent":["import {and, eq, gt, inArray, notInArray, type SQL, sql} from 'drizzle-orm';\nimport {db, type Tx} from './db.js';\nimport {type DataKey, secretDataKeys, toDataKey} from './schema/data-keys.js';\n\nexport async function getDataKey(workspaceId: string, tx?: Tx): Promise<DataKey | undefined> {\n const executor = tx ?? db();\n const rows = await executor\n .select()\n .from(secretDataKeys)\n .where(eq(secretDataKeys.workspaceId, workspaceId))\n .limit(1);\n const row = rows[0];\n return row ? toDataKey(row) : undefined;\n}\n\nexport async function insertDataKeyIfAbsent(\n dataKey: {workspaceId: string; wrappedDek: string; kekVersion: string},\n tx?: Tx,\n): Promise<boolean> {\n const executor = tx ?? db();\n const rows = await executor\n .insert(secretDataKeys)\n .values(dataKey)\n .onConflictDoNothing({\n target: secretDataKeys.workspaceId,\n })\n .returning({workspaceId: secretDataKeys.workspaceId});\n return rows.length > 0;\n}\n\nexport async function updateDataKeyWrapCas(\n params: {workspaceId: string; oldKekVersion: string; wrappedDek: string; kekVersion: string},\n tx?: Tx,\n): Promise<boolean> {\n const executor = tx ?? db();\n const rows = await executor\n .update(secretDataKeys)\n .set({\n wrappedDek: params.wrappedDek,\n kekVersion: params.kekVersion,\n rotatedAt: sql`NOW()`,\n })\n .where(\n and(\n eq(secretDataKeys.workspaceId, params.workspaceId),\n eq(secretDataKeys.kekVersion, params.oldKekVersion),\n ),\n )\n .returning({workspaceId: secretDataKeys.workspaceId});\n return rows.length > 0;\n}\n\nexport async function listDataKeyVersions(\n knownVersions: string[],\n params: {workspaceIds?: string[] | undefined} = {},\n): Promise<string[]> {\n if (params.workspaceIds?.length === 0) return [];\n\n const filters: SQL[] = [];\n if (knownVersions.length > 0) {\n filters.push(notInArray(secretDataKeys.kekVersion, knownVersions));\n }\n if (params.workspaceIds) {\n filters.push(inArray(secretDataKeys.workspaceId, params.workspaceIds));\n }\n const rows = await db()\n .selectDistinct({kekVersion: secretDataKeys.kekVersion})\n .from(secretDataKeys)\n .where(filters.length > 0 ? and(...filters) : undefined);\n return rows.map((row) => row.kekVersion);\n}\n\nexport async function listDataKeysPage(params: {\n afterWorkspaceId?: string | undefined;\n limit: number;\n versions?: string[] | undefined;\n workspaceIds?: string[] | undefined;\n}): Promise<DataKey[]> {\n if (params.versions && params.versions.length === 0) return [];\n if (params.workspaceIds?.length === 0) return [];\n\n const filters: SQL[] = [];\n if (params.afterWorkspaceId) {\n filters.push(gt(secretDataKeys.workspaceId, params.afterWorkspaceId));\n }\n if (params.versions) {\n filters.push(inArray(secretDataKeys.kekVersion, params.versions));\n }\n if (params.workspaceIds) {\n filters.push(inArray(secretDataKeys.workspaceId, params.workspaceIds));\n }\n const rows = await db()\n .select()\n .from(secretDataKeys)\n .where(filters.length > 0 ? and(...filters) : undefined)\n .orderBy(secretDataKeys.workspaceId)\n .limit(params.limit);\n return rows.map(toDataKey);\n}\n"],"names":["and","eq","gt","inArray","notInArray","sql","db","secretDataKeys","toDataKey","getDataKey","workspaceId","tx","executor","rows","select","from","where","limit","row","undefined","insertDataKeyIfAbsent","dataKey","insert","values","onConflictDoNothing","target","returning","length","updateDataKeyWrapCas","params","update","set","wrappedDek","kekVersion","rotatedAt","oldKekVersion","listDataKeyVersions","knownVersions","workspaceIds","filters","push","selectDistinct","map","listDataKeysPage","versions","afterWorkspaceId","orderBy"],"mappings":"AAAA,SAAQA,GAAG,EAAEC,EAAE,EAAE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