@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
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function encodeManagementCursor(cursor) {
|
|
2
|
+
return Buffer.from(JSON.stringify({
|
|
3
|
+
key: cursor
|
|
4
|
+
}), 'utf8').toString('base64url');
|
|
5
|
+
}
|
|
6
|
+
export function decodeManagementCursor(cursor) {
|
|
7
|
+
if (!cursor) return undefined;
|
|
8
|
+
try {
|
|
9
|
+
const parsed = JSON.parse(Buffer.from(cursor, 'base64url').toString('utf8'));
|
|
10
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return undefined;
|
|
11
|
+
const { key } = parsed;
|
|
12
|
+
if (typeof key !== 'string' || key.length === 0) return undefined;
|
|
13
|
+
return key;
|
|
14
|
+
} catch {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=cursor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/presentation/routes/cursor.ts"],"sourcesContent":["interface ManagementCursor {\n key: string;\n}\n\nexport function encodeManagementCursor(cursor: string): string {\n return Buffer.from(JSON.stringify({key: cursor} satisfies ManagementCursor), 'utf8').toString(\n 'base64url',\n );\n}\n\nexport function decodeManagementCursor(cursor: string | undefined): string | undefined {\n if (!cursor) return undefined;\n\n try {\n const parsed: unknown = JSON.parse(Buffer.from(cursor, 'base64url').toString('utf8'));\n if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return undefined;\n const {key} = parsed as Partial<ManagementCursor>;\n if (typeof key !== 'string' || key.length === 0) return undefined;\n return key;\n } catch {\n return undefined;\n }\n}\n"],"names":["encodeManagementCursor","cursor","Buffer","from","JSON","stringify","key","toString","decodeManagementCursor","undefined","parsed","parse","Array","isArray","length"],"mappings":"AAIA,OAAO,SAASA,uBAAuBC,MAAc;IACnD,OAAOC,OAAOC,IAAI,CAACC,KAAKC,SAAS,CAAC;QAACC,KAAKL;IAAM,IAA+B,QAAQM,QAAQ,CAC3F;AAEJ;AAEA,OAAO,SAASC,uBAAuBP,MAA0B;IAC/D,IAAI,CAACA,QAAQ,OAAOQ;IAEpB,IAAI;QACF,MAAMC,SAAkBN,KAAKO,KAAK,CAACT,OAAOC,IAAI,CAACF,QAAQ,aAAaM,QAAQ,CAAC;QAC7E,IAAI,CAACG,UAAU,OAAOA,WAAW,YAAYE,MAAMC,OAAO,CAACH,SAAS,OAAOD;QAC3E,MAAM,EAACH,GAAG,EAAC,GAAGI;QACd,IAAI,OAAOJ,QAAQ,YAAYA,IAAIQ,MAAM,KAAK,GAAG,OAAOL;QACxD,OAAOH;IACT,EAAE,OAAM;QACN,OAAOG;IACT;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-secret.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/delete-secret.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,iBAAiB,iDAkB5B,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { secretKeySchema, secretScopeQuerySchema } from '@shipfox/api-secrets-dto';
|
|
2
|
+
import { defineRoute } from '@shipfox/node-fastify';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { deleteManagedSecret } from '#core/index.js';
|
|
5
|
+
import { requireManagementWrite } from './auth.js';
|
|
6
|
+
import { translateManagementError } from './errors.js';
|
|
7
|
+
export const deleteSecretRoute = defineRoute({
|
|
8
|
+
method: 'DELETE',
|
|
9
|
+
path: '/secrets/:key',
|
|
10
|
+
description: 'Delete a user-managed secret.',
|
|
11
|
+
schema: {
|
|
12
|
+
params: z.object({
|
|
13
|
+
workspaceId: z.string().uuid(),
|
|
14
|
+
key: secretKeySchema
|
|
15
|
+
}),
|
|
16
|
+
querystring: secretScopeQuerySchema,
|
|
17
|
+
response: {
|
|
18
|
+
204: z.void()
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
errorHandler: translateManagementError,
|
|
22
|
+
handler: async (request, reply)=>{
|
|
23
|
+
const { workspaceId, key } = request.params;
|
|
24
|
+
const { project_id: projectId } = request.query;
|
|
25
|
+
const access = await requireManagementWrite({
|
|
26
|
+
request,
|
|
27
|
+
workspaceId,
|
|
28
|
+
projectId
|
|
29
|
+
});
|
|
30
|
+
await deleteManagedSecret({
|
|
31
|
+
workspaceId,
|
|
32
|
+
projectId,
|
|
33
|
+
key,
|
|
34
|
+
actorId: access.userId
|
|
35
|
+
});
|
|
36
|
+
return reply.status(204).send();
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=delete-secret.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/presentation/routes/delete-secret.ts"],"sourcesContent":["import {secretKeySchema, secretScopeQuerySchema} from '@shipfox/api-secrets-dto';\nimport {defineRoute} from '@shipfox/node-fastify';\nimport {z} from 'zod';\nimport {deleteManagedSecret} from '#core/index.js';\nimport {requireManagementWrite} from './auth.js';\nimport {translateManagementError} from './errors.js';\n\nexport const deleteSecretRoute = defineRoute({\n method: 'DELETE',\n path: '/secrets/:key',\n description: 'Delete a user-managed secret.',\n schema: {\n params: z.object({workspaceId: z.string().uuid(), key: secretKeySchema}),\n querystring: secretScopeQuerySchema,\n response: {204: z.void()},\n },\n errorHandler: translateManagementError,\n handler: async (request, reply) => {\n const {workspaceId, key} = request.params;\n const {project_id: projectId} = request.query;\n const access = await requireManagementWrite({request, workspaceId, projectId});\n\n await deleteManagedSecret({workspaceId, projectId, key, actorId: access.userId});\n return reply.status(204).send();\n },\n});\n"],"names":["secretKeySchema","secretScopeQuerySchema","defineRoute","z","deleteManagedSecret","requireManagementWrite","translateManagementError","deleteSecretRoute","method","path","description","schema","params","object","workspaceId","string","uuid","key","querystring","response","void","errorHandler","handler","request","reply","project_id","projectId","query","access","actorId","userId","status","send"],"mappings":"AAAA,SAAQA,eAAe,EAAEC,sBAAsB,QAAO,2BAA2B;AACjF,SAAQC,WAAW,QAAO,wBAAwB;AAClD,SAAQC,CAAC,QAAO,MAAM;AACtB,SAAQC,mBAAmB,QAAO,iBAAiB;AACnD,SAAQC,sBAAsB,QAAO,YAAY;AACjD,SAAQC,wBAAwB,QAAO,cAAc;AAErD,OAAO,MAAMC,oBAAoBL,YAAY;IAC3CM,QAAQ;IACRC,MAAM;IACNC,aAAa;IACbC,QAAQ;QACNC,QAAQT,EAAEU,MAAM,CAAC;YAACC,aAAaX,EAAEY,MAAM,GAAGC,IAAI;YAAIC,KAAKjB;QAAe;QACtEkB,aAAajB;QACbkB,UAAU;YAAC,KAAKhB,EAAEiB,IAAI;QAAE;IAC1B;IACAC,cAAcf;IACdgB,SAAS,OAAOC,SAASC;QACvB,MAAM,EAACV,WAAW,EAAEG,GAAG,EAAC,GAAGM,QAAQX,MAAM;QACzC,MAAM,EAACa,YAAYC,SAAS,EAAC,GAAGH,QAAQI,KAAK;QAC7C,MAAMC,SAAS,MAAMvB,uBAAuB;YAACkB;YAAST;YAAaY;QAAS;QAE5E,MAAMtB,oBAAoB;YAACU;YAAaY;YAAWT;YAAKY,SAASD,OAAOE,MAAM;QAAA;QAC9E,OAAON,MAAMO,MAAM,CAAC,KAAKC,IAAI;IAC/B;AACF,GAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-variable.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/delete-variable.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,mBAAmB,iDAkB9B,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { secretKeySchema, secretScopeQuerySchema } from '@shipfox/api-secrets-dto';
|
|
2
|
+
import { defineRoute } from '@shipfox/node-fastify';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { deleteManagedVariable } from '#core/index.js';
|
|
5
|
+
import { requireManagementWrite } from './auth.js';
|
|
6
|
+
import { translateManagementError } from './errors.js';
|
|
7
|
+
export const deleteVariableRoute = defineRoute({
|
|
8
|
+
method: 'DELETE',
|
|
9
|
+
path: '/variables/:key',
|
|
10
|
+
description: 'Delete a user-managed variable.',
|
|
11
|
+
schema: {
|
|
12
|
+
params: z.object({
|
|
13
|
+
workspaceId: z.string().uuid(),
|
|
14
|
+
key: secretKeySchema
|
|
15
|
+
}),
|
|
16
|
+
querystring: secretScopeQuerySchema,
|
|
17
|
+
response: {
|
|
18
|
+
204: z.void()
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
errorHandler: translateManagementError,
|
|
22
|
+
handler: async (request, reply)=>{
|
|
23
|
+
const { workspaceId, key } = request.params;
|
|
24
|
+
const { project_id: projectId } = request.query;
|
|
25
|
+
const access = await requireManagementWrite({
|
|
26
|
+
request,
|
|
27
|
+
workspaceId,
|
|
28
|
+
projectId
|
|
29
|
+
});
|
|
30
|
+
await deleteManagedVariable({
|
|
31
|
+
workspaceId,
|
|
32
|
+
projectId,
|
|
33
|
+
key,
|
|
34
|
+
actorId: access.userId
|
|
35
|
+
});
|
|
36
|
+
return reply.status(204).send();
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=delete-variable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/presentation/routes/delete-variable.ts"],"sourcesContent":["import {secretKeySchema, secretScopeQuerySchema} from '@shipfox/api-secrets-dto';\nimport {defineRoute} from '@shipfox/node-fastify';\nimport {z} from 'zod';\nimport {deleteManagedVariable} from '#core/index.js';\nimport {requireManagementWrite} from './auth.js';\nimport {translateManagementError} from './errors.js';\n\nexport const deleteVariableRoute = defineRoute({\n method: 'DELETE',\n path: '/variables/:key',\n description: 'Delete a user-managed variable.',\n schema: {\n params: z.object({workspaceId: z.string().uuid(), key: secretKeySchema}),\n querystring: secretScopeQuerySchema,\n response: {204: z.void()},\n },\n errorHandler: translateManagementError,\n handler: async (request, reply) => {\n const {workspaceId, key} = request.params;\n const {project_id: projectId} = request.query;\n const access = await requireManagementWrite({request, workspaceId, projectId});\n\n await deleteManagedVariable({workspaceId, projectId, key, actorId: access.userId});\n return reply.status(204).send();\n },\n});\n"],"names":["secretKeySchema","secretScopeQuerySchema","defineRoute","z","deleteManagedVariable","requireManagementWrite","translateManagementError","deleteVariableRoute","method","path","description","schema","params","object","workspaceId","string","uuid","key","querystring","response","void","errorHandler","handler","request","reply","project_id","projectId","query","access","actorId","userId","status","send"],"mappings":"AAAA,SAAQA,eAAe,EAAEC,sBAAsB,QAAO,2BAA2B;AACjF,SAAQC,WAAW,QAAO,wBAAwB;AAClD,SAAQC,CAAC,QAAO,MAAM;AACtB,SAAQC,qBAAqB,QAAO,iBAAiB;AACrD,SAAQC,sBAAsB,QAAO,YAAY;AACjD,SAAQC,wBAAwB,QAAO,cAAc;AAErD,OAAO,MAAMC,sBAAsBL,YAAY;IAC7CM,QAAQ;IACRC,MAAM;IACNC,aAAa;IACbC,QAAQ;QACNC,QAAQT,EAAEU,MAAM,CAAC;YAACC,aAAaX,EAAEY,MAAM,GAAGC,IAAI;YAAIC,KAAKjB;QAAe;QACtEkB,aAAajB;QACbkB,UAAU;YAAC,KAAKhB,EAAEiB,IAAI;QAAE;IAC1B;IACAC,cAAcf;IACdgB,SAAS,OAAOC,SAASC;QACvB,MAAM,EAACV,WAAW,EAAEG,GAAG,EAAC,GAAGM,QAAQX,MAAM;QACzC,MAAM,EAACa,YAAYC,SAAS,EAAC,GAAGH,QAAQI,KAAK;QAC7C,MAAMC,SAAS,MAAMvB,uBAAuB;YAACkB;YAAST;YAAaY;QAAS;QAE5E,MAAMtB,sBAAsB;YAACU;YAAaY;YAAWT;YAAKY,SAASD,OAAOE,MAAM;QAAA;QAChF,OAAON,MAAMO,MAAM,CAAC,KAAKC,IAAI;IAC/B;AACF,GAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/errors.ts"],"names":[],"mappings":"AAcA,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CAgD9D"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { ProjectNotFoundError } from '@shipfox/api-projects';
|
|
2
|
+
import { ClientError } from '@shipfox/node-fastify';
|
|
3
|
+
import { NamespaceValidationError, SecretBatchDuplicateKeyError, SecretBatchScopeMismatchError, SecretKeyValidationError, SecretNotFoundError, SecretValueTooLargeError, UnknownSecretStoreError, VariableNotFoundError, WorkspaceSecretCapExceededError } from '#core/errors.js';
|
|
4
|
+
export function translateManagementError(error) {
|
|
5
|
+
if (error instanceof SecretKeyValidationError) {
|
|
6
|
+
throw new ClientError('Invalid secret key', 'invalid-key', {
|
|
7
|
+
status: 400,
|
|
8
|
+
details: {
|
|
9
|
+
key: error.key
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
if (error instanceof NamespaceValidationError) {
|
|
14
|
+
throw new ClientError('Invalid namespace', 'invalid-namespace', {
|
|
15
|
+
status: 400,
|
|
16
|
+
details: {
|
|
17
|
+
namespace: error.namespace
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
if (error instanceof SecretValueTooLargeError) {
|
|
22
|
+
throw new ClientError(error.message, 'value-too-large', {
|
|
23
|
+
status: 413,
|
|
24
|
+
details: {
|
|
25
|
+
max_bytes: error.maxBytes
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
if (error instanceof WorkspaceSecretCapExceededError) {
|
|
30
|
+
throw new ClientError('Workspace secret cap exceeded', 'workspace-secret-cap-exceeded', {
|
|
31
|
+
status: 409,
|
|
32
|
+
details: {
|
|
33
|
+
cap: error.cap
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (error instanceof SecretBatchScopeMismatchError) {
|
|
38
|
+
throw new ClientError(error.message, 'batch-scope-mismatch', {
|
|
39
|
+
status: 400
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
if (error instanceof SecretBatchDuplicateKeyError) {
|
|
43
|
+
throw new ClientError('Duplicate batch key', 'duplicate-key', {
|
|
44
|
+
status: 400,
|
|
45
|
+
details: {
|
|
46
|
+
key: error.key
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
if (error instanceof SecretNotFoundError) {
|
|
51
|
+
throw new ClientError('Secret not found', 'secret-not-found', {
|
|
52
|
+
status: 404
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
if (error instanceof VariableNotFoundError) {
|
|
56
|
+
throw new ClientError('Variable not found', 'variable-not-found', {
|
|
57
|
+
status: 404
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
if (error instanceof UnknownSecretStoreError) {
|
|
61
|
+
throw new ClientError('Unknown secret store', 'unknown-secret-store', {
|
|
62
|
+
status: 400
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
if (error instanceof ProjectNotFoundError) {
|
|
66
|
+
throw new ClientError('Project not found', 'project-not-found', {
|
|
67
|
+
status: 404
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/presentation/routes/errors.ts"],"sourcesContent":["import {ProjectNotFoundError} from '@shipfox/api-projects';\nimport {ClientError} from '@shipfox/node-fastify';\nimport {\n NamespaceValidationError,\n SecretBatchDuplicateKeyError,\n SecretBatchScopeMismatchError,\n SecretKeyValidationError,\n SecretNotFoundError,\n SecretValueTooLargeError,\n UnknownSecretStoreError,\n VariableNotFoundError,\n WorkspaceSecretCapExceededError,\n} from '#core/errors.js';\n\nexport function translateManagementError(error: unknown): never {\n if (error instanceof SecretKeyValidationError) {\n throw new ClientError('Invalid secret key', 'invalid-key', {\n status: 400,\n details: {key: error.key},\n });\n }\n if (error instanceof NamespaceValidationError) {\n throw new ClientError('Invalid namespace', 'invalid-namespace', {\n status: 400,\n details: {namespace: error.namespace},\n });\n }\n if (error instanceof SecretValueTooLargeError) {\n throw new ClientError(error.message, 'value-too-large', {\n status: 413,\n details: {max_bytes: error.maxBytes},\n });\n }\n if (error instanceof WorkspaceSecretCapExceededError) {\n throw new ClientError('Workspace secret cap exceeded', 'workspace-secret-cap-exceeded', {\n status: 409,\n details: {cap: error.cap},\n });\n }\n if (error instanceof SecretBatchScopeMismatchError) {\n throw new ClientError(error.message, 'batch-scope-mismatch', {status: 400});\n }\n if (error instanceof SecretBatchDuplicateKeyError) {\n throw new ClientError('Duplicate batch key', 'duplicate-key', {\n status: 400,\n details: {key: error.key},\n });\n }\n if (error instanceof SecretNotFoundError) {\n throw new ClientError('Secret not found', 'secret-not-found', {status: 404});\n }\n if (error instanceof VariableNotFoundError) {\n throw new ClientError('Variable not found', 'variable-not-found', {status: 404});\n }\n if (error instanceof UnknownSecretStoreError) {\n throw new ClientError('Unknown secret store', 'unknown-secret-store', {status: 400});\n }\n if (error instanceof ProjectNotFoundError) {\n throw new ClientError('Project not found', 'project-not-found', {status: 404});\n }\n\n throw error;\n}\n"],"names":["ProjectNotFoundError","ClientError","NamespaceValidationError","SecretBatchDuplicateKeyError","SecretBatchScopeMismatchError","SecretKeyValidationError","SecretNotFoundError","SecretValueTooLargeError","UnknownSecretStoreError","VariableNotFoundError","WorkspaceSecretCapExceededError","translateManagementError","error","status","details","key","namespace","message","max_bytes","maxBytes","cap"],"mappings":"AAAA,SAAQA,oBAAoB,QAAO,wBAAwB;AAC3D,SAAQC,WAAW,QAAO,wBAAwB;AAClD,SACEC,wBAAwB,EACxBC,4BAA4B,EAC5BC,6BAA6B,EAC7BC,wBAAwB,EACxBC,mBAAmB,EACnBC,wBAAwB,EACxBC,uBAAuB,EACvBC,qBAAqB,EACrBC,+BAA+B,QAC1B,kBAAkB;AAEzB,OAAO,SAASC,yBAAyBC,KAAc;IACrD,IAAIA,iBAAiBP,0BAA0B;QAC7C,MAAM,IAAIJ,YAAY,sBAAsB,eAAe;YACzDY,QAAQ;YACRC,SAAS;gBAACC,KAAKH,MAAMG,GAAG;YAAA;QAC1B;IACF;IACA,IAAIH,iBAAiBV,0BAA0B;QAC7C,MAAM,IAAID,YAAY,qBAAqB,qBAAqB;YAC9DY,QAAQ;YACRC,SAAS;gBAACE,WAAWJ,MAAMI,SAAS;YAAA;QACtC;IACF;IACA,IAAIJ,iBAAiBL,0BAA0B;QAC7C,MAAM,IAAIN,YAAYW,MAAMK,OAAO,EAAE,mBAAmB;YACtDJ,QAAQ;YACRC,SAAS;gBAACI,WAAWN,MAAMO,QAAQ;YAAA;QACrC;IACF;IACA,IAAIP,iBAAiBF,iCAAiC;QACpD,MAAM,IAAIT,YAAY,iCAAiC,iCAAiC;YACtFY,QAAQ;YACRC,SAAS;gBAACM,KAAKR,MAAMQ,GAAG;YAAA;QAC1B;IACF;IACA,IAAIR,iBAAiBR,+BAA+B;QAClD,MAAM,IAAIH,YAAYW,MAAMK,OAAO,EAAE,wBAAwB;YAACJ,QAAQ;QAAG;IAC3E;IACA,IAAID,iBAAiBT,8BAA8B;QACjD,MAAM,IAAIF,YAAY,uBAAuB,iBAAiB;YAC5DY,QAAQ;YACRC,SAAS;gBAACC,KAAKH,MAAMG,GAAG;YAAA;QAC1B;IACF;IACA,IAAIH,iBAAiBN,qBAAqB;QACxC,MAAM,IAAIL,YAAY,oBAAoB,oBAAoB;YAACY,QAAQ;QAAG;IAC5E;IACA,IAAID,iBAAiBH,uBAAuB;QAC1C,MAAM,IAAIR,YAAY,sBAAsB,sBAAsB;YAACY,QAAQ;QAAG;IAChF;IACA,IAAID,iBAAiBJ,yBAAyB;QAC5C,MAAM,IAAIP,YAAY,wBAAwB,wBAAwB;YAACY,QAAQ;QAAG;IACpF;IACA,IAAID,iBAAiBZ,sBAAsB;QACzC,MAAM,IAAIC,YAAY,qBAAqB,qBAAqB;YAACY,QAAQ;QAAG;IAC9E;IAEA,MAAMD;AACR"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-variable.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/get-variable.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,gBAAgB,iDAmB3B,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { getVariableResponseSchema, secretKeySchema, secretScopeQuerySchema } from '@shipfox/api-secrets-dto';
|
|
2
|
+
import { defineRoute } from '@shipfox/node-fastify';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { getManagedVariable } from '#core/index.js';
|
|
5
|
+
import { toVariableDto } from '#presentation/dto/index.js';
|
|
6
|
+
import { requireManagementRead } from './auth.js';
|
|
7
|
+
import { translateManagementError } from './errors.js';
|
|
8
|
+
export const getVariableRoute = defineRoute({
|
|
9
|
+
method: 'GET',
|
|
10
|
+
path: '/variables/:key',
|
|
11
|
+
description: 'Read a user-managed variable.',
|
|
12
|
+
schema: {
|
|
13
|
+
params: z.object({
|
|
14
|
+
workspaceId: z.string().uuid(),
|
|
15
|
+
key: secretKeySchema
|
|
16
|
+
}),
|
|
17
|
+
querystring: secretScopeQuerySchema,
|
|
18
|
+
response: {
|
|
19
|
+
200: getVariableResponseSchema
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
errorHandler: translateManagementError,
|
|
23
|
+
handler: async (request)=>{
|
|
24
|
+
const { workspaceId, key } = request.params;
|
|
25
|
+
const { project_id: projectId } = request.query;
|
|
26
|
+
await requireManagementRead({
|
|
27
|
+
request,
|
|
28
|
+
workspaceId,
|
|
29
|
+
projectId
|
|
30
|
+
});
|
|
31
|
+
const variable = await getManagedVariable({
|
|
32
|
+
workspaceId,
|
|
33
|
+
projectId,
|
|
34
|
+
key
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
variable: toVariableDto(variable)
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=get-variable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/presentation/routes/get-variable.ts"],"sourcesContent":["import {\n getVariableResponseSchema,\n secretKeySchema,\n secretScopeQuerySchema,\n} from '@shipfox/api-secrets-dto';\nimport {defineRoute} from '@shipfox/node-fastify';\nimport {z} from 'zod';\nimport {getManagedVariable} from '#core/index.js';\nimport {toVariableDto} from '#presentation/dto/index.js';\nimport {requireManagementRead} from './auth.js';\nimport {translateManagementError} from './errors.js';\n\nexport const getVariableRoute = defineRoute({\n method: 'GET',\n path: '/variables/:key',\n description: 'Read a user-managed variable.',\n schema: {\n params: z.object({workspaceId: z.string().uuid(), key: secretKeySchema}),\n querystring: secretScopeQuerySchema,\n response: {200: getVariableResponseSchema},\n },\n errorHandler: translateManagementError,\n handler: async (request) => {\n const {workspaceId, key} = request.params;\n const {project_id: projectId} = request.query;\n\n await requireManagementRead({request, workspaceId, projectId});\n const variable = await getManagedVariable({workspaceId, projectId, key});\n\n return {variable: toVariableDto(variable)};\n },\n});\n"],"names":["getVariableResponseSchema","secretKeySchema","secretScopeQuerySchema","defineRoute","z","getManagedVariable","toVariableDto","requireManagementRead","translateManagementError","getVariableRoute","method","path","description","schema","params","object","workspaceId","string","uuid","key","querystring","response","errorHandler","handler","request","project_id","projectId","query","variable"],"mappings":"AAAA,SACEA,yBAAyB,EACzBC,eAAe,EACfC,sBAAsB,QACjB,2BAA2B;AAClC,SAAQC,WAAW,QAAO,wBAAwB;AAClD,SAAQC,CAAC,QAAO,MAAM;AACtB,SAAQC,kBAAkB,QAAO,iBAAiB;AAClD,SAAQC,aAAa,QAAO,6BAA6B;AACzD,SAAQC,qBAAqB,QAAO,YAAY;AAChD,SAAQC,wBAAwB,QAAO,cAAc;AAErD,OAAO,MAAMC,mBAAmBN,YAAY;IAC1CO,QAAQ;IACRC,MAAM;IACNC,aAAa;IACbC,QAAQ;QACNC,QAAQV,EAAEW,MAAM,CAAC;YAACC,aAAaZ,EAAEa,MAAM,GAAGC,IAAI;YAAIC,KAAKlB;QAAe;QACtEmB,aAAalB;QACbmB,UAAU;YAAC,KAAKrB;QAAyB;IAC3C;IACAsB,cAAcd;IACde,SAAS,OAAOC;QACd,MAAM,EAACR,WAAW,EAAEG,GAAG,EAAC,GAAGK,QAAQV,MAAM;QACzC,MAAM,EAACW,YAAYC,SAAS,EAAC,GAAGF,QAAQG,KAAK;QAE7C,MAAMpB,sBAAsB;YAACiB;YAASR;YAAaU;QAAS;QAC5D,MAAME,WAAW,MAAMvB,mBAAmB;YAACW;YAAaU;YAAWP;QAAG;QAEtE,OAAO;YAACS,UAAUtB,cAAcsB;QAAS;IAC3C;AACF,GAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAC;AAWtD,eAAO,MAAM,aAAa,EAAE,UAAU,EAgBrC,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AUTH_USER } from '@shipfox/api-auth-context';
|
|
2
|
+
import { batchSecretsRoute } from './batch-secrets.js';
|
|
3
|
+
import { batchVariablesRoute } from './batch-variables.js';
|
|
4
|
+
import { deleteSecretRoute } from './delete-secret.js';
|
|
5
|
+
import { deleteVariableRoute } from './delete-variable.js';
|
|
6
|
+
import { getVariableRoute } from './get-variable.js';
|
|
7
|
+
import { listSecretsRoute } from './list-secrets.js';
|
|
8
|
+
import { listVariablesRoute } from './list-variables.js';
|
|
9
|
+
import { putSecretRoute } from './put-secret.js';
|
|
10
|
+
import { putVariableRoute } from './put-variable.js';
|
|
11
|
+
export const secretsRoutes = [
|
|
12
|
+
{
|
|
13
|
+
prefix: '/workspaces/:workspaceId',
|
|
14
|
+
auth: AUTH_USER,
|
|
15
|
+
routes: [
|
|
16
|
+
listSecretsRoute,
|
|
17
|
+
putSecretRoute,
|
|
18
|
+
batchSecretsRoute,
|
|
19
|
+
deleteSecretRoute,
|
|
20
|
+
listVariablesRoute,
|
|
21
|
+
getVariableRoute,
|
|
22
|
+
putVariableRoute,
|
|
23
|
+
batchVariablesRoute,
|
|
24
|
+
deleteVariableRoute
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/presentation/routes/index.ts"],"sourcesContent":["import {AUTH_USER} from '@shipfox/api-auth-context';\nimport type {RouteGroup} from '@shipfox/node-fastify';\nimport {batchSecretsRoute} from './batch-secrets.js';\nimport {batchVariablesRoute} from './batch-variables.js';\nimport {deleteSecretRoute} from './delete-secret.js';\nimport {deleteVariableRoute} from './delete-variable.js';\nimport {getVariableRoute} from './get-variable.js';\nimport {listSecretsRoute} from './list-secrets.js';\nimport {listVariablesRoute} from './list-variables.js';\nimport {putSecretRoute} from './put-secret.js';\nimport {putVariableRoute} from './put-variable.js';\n\nexport const secretsRoutes: RouteGroup[] = [\n {\n prefix: '/workspaces/:workspaceId',\n auth: AUTH_USER,\n routes: [\n listSecretsRoute,\n putSecretRoute,\n batchSecretsRoute,\n deleteSecretRoute,\n listVariablesRoute,\n getVariableRoute,\n putVariableRoute,\n batchVariablesRoute,\n deleteVariableRoute,\n ],\n },\n];\n"],"names":["AUTH_USER","batchSecretsRoute","batchVariablesRoute","deleteSecretRoute","deleteVariableRoute","getVariableRoute","listSecretsRoute","listVariablesRoute","putSecretRoute","putVariableRoute","secretsRoutes","prefix","auth","routes"],"mappings":"AAAA,SAAQA,SAAS,QAAO,4BAA4B;AAEpD,SAAQC,iBAAiB,QAAO,qBAAqB;AACrD,SAAQC,mBAAmB,QAAO,uBAAuB;AACzD,SAAQC,iBAAiB,QAAO,qBAAqB;AACrD,SAAQC,mBAAmB,QAAO,uBAAuB;AACzD,SAAQC,gBAAgB,QAAO,oBAAoB;AACnD,SAAQC,gBAAgB,QAAO,oBAAoB;AACnD,SAAQC,kBAAkB,QAAO,sBAAsB;AACvD,SAAQC,cAAc,QAAO,kBAAkB;AAC/C,SAAQC,gBAAgB,QAAO,oBAAoB;AAEnD,OAAO,MAAMC,gBAA8B;IACzC;QACEC,QAAQ;QACRC,MAAMZ;QACNa,QAAQ;YACNP;YACAE;YACAP;YACAE;YACAI;YACAF;YACAI;YACAP;YACAE;SACD;IACH;CACD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-secrets.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/list-secrets.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,gBAAgB,iDA+B3B,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { listSecretsQuerySchema, listSecretsResponseSchema } from '@shipfox/api-secrets-dto';
|
|
2
|
+
import { ClientError, defineRoute } from '@shipfox/node-fastify';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { listManagedSecrets } from '#core/index.js';
|
|
5
|
+
import { toSecretDto } from '#presentation/dto/index.js';
|
|
6
|
+
import { requireManagementRead } from './auth.js';
|
|
7
|
+
import { decodeManagementCursor, encodeManagementCursor } from './cursor.js';
|
|
8
|
+
import { translateManagementError } from './errors.js';
|
|
9
|
+
export const listSecretsRoute = defineRoute({
|
|
10
|
+
method: 'GET',
|
|
11
|
+
path: '/secrets',
|
|
12
|
+
description: 'List user-managed secrets for a workspace or project scope.',
|
|
13
|
+
schema: {
|
|
14
|
+
params: z.object({
|
|
15
|
+
workspaceId: z.string().uuid()
|
|
16
|
+
}),
|
|
17
|
+
querystring: listSecretsQuerySchema,
|
|
18
|
+
response: {
|
|
19
|
+
200: listSecretsResponseSchema
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
errorHandler: translateManagementError,
|
|
23
|
+
handler: async (request)=>{
|
|
24
|
+
const { workspaceId } = request.params;
|
|
25
|
+
const { project_id: projectId, limit, cursor } = request.query;
|
|
26
|
+
const decodedCursor = decodeManagementCursor(cursor);
|
|
27
|
+
if (cursor && !decodedCursor) {
|
|
28
|
+
throw new ClientError('Invalid cursor', 'invalid-cursor', {
|
|
29
|
+
status: 400
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
await requireManagementRead({
|
|
33
|
+
request,
|
|
34
|
+
workspaceId,
|
|
35
|
+
projectId
|
|
36
|
+
});
|
|
37
|
+
const result = await listManagedSecrets({
|
|
38
|
+
workspaceId,
|
|
39
|
+
projectId,
|
|
40
|
+
limit,
|
|
41
|
+
cursor: decodedCursor ?? undefined
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
secrets: result.secrets.map(toSecretDto),
|
|
45
|
+
next_cursor: result.nextCursor ? encodeManagementCursor(result.nextCursor) : null
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
//# sourceMappingURL=list-secrets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/presentation/routes/list-secrets.ts"],"sourcesContent":["import {listSecretsQuerySchema, listSecretsResponseSchema} from '@shipfox/api-secrets-dto';\nimport {ClientError, defineRoute} from '@shipfox/node-fastify';\nimport {z} from 'zod';\nimport {listManagedSecrets} from '#core/index.js';\nimport {toSecretDto} from '#presentation/dto/index.js';\nimport {requireManagementRead} from './auth.js';\nimport {decodeManagementCursor, encodeManagementCursor} from './cursor.js';\nimport {translateManagementError} from './errors.js';\n\nexport const listSecretsRoute = defineRoute({\n method: 'GET',\n path: '/secrets',\n description: 'List user-managed secrets for a workspace or project scope.',\n schema: {\n params: z.object({workspaceId: z.string().uuid()}),\n querystring: listSecretsQuerySchema,\n response: {200: listSecretsResponseSchema},\n },\n errorHandler: translateManagementError,\n handler: async (request) => {\n const {workspaceId} = request.params;\n const {project_id: projectId, limit, cursor} = request.query;\n const decodedCursor = decodeManagementCursor(cursor);\n if (cursor && !decodedCursor) {\n throw new ClientError('Invalid cursor', 'invalid-cursor', {status: 400});\n }\n\n await requireManagementRead({request, workspaceId, projectId});\n const result = await listManagedSecrets({\n workspaceId,\n projectId,\n limit,\n cursor: decodedCursor ?? undefined,\n });\n\n return {\n secrets: result.secrets.map(toSecretDto),\n next_cursor: result.nextCursor ? encodeManagementCursor(result.nextCursor) : null,\n };\n },\n});\n"],"names":["listSecretsQuerySchema","listSecretsResponseSchema","ClientError","defineRoute","z","listManagedSecrets","toSecretDto","requireManagementRead","decodeManagementCursor","encodeManagementCursor","translateManagementError","listSecretsRoute","method","path","description","schema","params","object","workspaceId","string","uuid","querystring","response","errorHandler","handler","request","project_id","projectId","limit","cursor","query","decodedCursor","status","result","undefined","secrets","map","next_cursor","nextCursor"],"mappings":"AAAA,SAAQA,sBAAsB,EAAEC,yBAAyB,QAAO,2BAA2B;AAC3F,SAAQC,WAAW,EAAEC,WAAW,QAAO,wBAAwB;AAC/D,SAAQC,CAAC,QAAO,MAAM;AACtB,SAAQC,kBAAkB,QAAO,iBAAiB;AAClD,SAAQC,WAAW,QAAO,6BAA6B;AACvD,SAAQC,qBAAqB,QAAO,YAAY;AAChD,SAAQC,sBAAsB,EAAEC,sBAAsB,QAAO,cAAc;AAC3E,SAAQC,wBAAwB,QAAO,cAAc;AAErD,OAAO,MAAMC,mBAAmBR,YAAY;IAC1CS,QAAQ;IACRC,MAAM;IACNC,aAAa;IACbC,QAAQ;QACNC,QAAQZ,EAAEa,MAAM,CAAC;YAACC,aAAad,EAAEe,MAAM,GAAGC,IAAI;QAAE;QAChDC,aAAarB;QACbsB,UAAU;YAAC,KAAKrB;QAAyB;IAC3C;IACAsB,cAAcb;IACdc,SAAS,OAAOC;QACd,MAAM,EAACP,WAAW,EAAC,GAAGO,QAAQT,MAAM;QACpC,MAAM,EAACU,YAAYC,SAAS,EAAEC,KAAK,EAAEC,MAAM,EAAC,GAAGJ,QAAQK,KAAK;QAC5D,MAAMC,gBAAgBvB,uBAAuBqB;QAC7C,IAAIA,UAAU,CAACE,eAAe;YAC5B,MAAM,IAAI7B,YAAY,kBAAkB,kBAAkB;gBAAC8B,QAAQ;YAAG;QACxE;QAEA,MAAMzB,sBAAsB;YAACkB;YAASP;YAAaS;QAAS;QAC5D,MAAMM,SAAS,MAAM5B,mBAAmB;YACtCa;YACAS;YACAC;YACAC,QAAQE,iBAAiBG;QAC3B;QAEA,OAAO;YACLC,SAASF,OAAOE,OAAO,CAACC,GAAG,CAAC9B;YAC5B+B,aAAaJ,OAAOK,UAAU,GAAG7B,uBAAuBwB,OAAOK,UAAU,IAAI;QAC/E;IACF;AACF,GAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-variables.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/list-variables.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,kBAAkB,iDA+B7B,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { listVariablesQuerySchema, listVariablesResponseSchema } from '@shipfox/api-secrets-dto';
|
|
2
|
+
import { ClientError, defineRoute } from '@shipfox/node-fastify';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { listManagedVariables } from '#core/index.js';
|
|
5
|
+
import { toVariableListItemDto } from '#presentation/dto/index.js';
|
|
6
|
+
import { requireManagementRead } from './auth.js';
|
|
7
|
+
import { decodeManagementCursor, encodeManagementCursor } from './cursor.js';
|
|
8
|
+
import { translateManagementError } from './errors.js';
|
|
9
|
+
export const listVariablesRoute = defineRoute({
|
|
10
|
+
method: 'GET',
|
|
11
|
+
path: '/variables',
|
|
12
|
+
description: 'List user-managed variables for a workspace or project scope.',
|
|
13
|
+
schema: {
|
|
14
|
+
params: z.object({
|
|
15
|
+
workspaceId: z.string().uuid()
|
|
16
|
+
}),
|
|
17
|
+
querystring: listVariablesQuerySchema,
|
|
18
|
+
response: {
|
|
19
|
+
200: listVariablesResponseSchema
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
errorHandler: translateManagementError,
|
|
23
|
+
handler: async (request)=>{
|
|
24
|
+
const { workspaceId } = request.params;
|
|
25
|
+
const { project_id: projectId, limit, cursor } = request.query;
|
|
26
|
+
const decodedCursor = decodeManagementCursor(cursor);
|
|
27
|
+
if (cursor && !decodedCursor) {
|
|
28
|
+
throw new ClientError('Invalid cursor', 'invalid-cursor', {
|
|
29
|
+
status: 400
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
await requireManagementRead({
|
|
33
|
+
request,
|
|
34
|
+
workspaceId,
|
|
35
|
+
projectId
|
|
36
|
+
});
|
|
37
|
+
const result = await listManagedVariables({
|
|
38
|
+
workspaceId,
|
|
39
|
+
projectId,
|
|
40
|
+
limit,
|
|
41
|
+
cursor: decodedCursor ?? undefined
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
variables: result.variables.map(toVariableListItemDto),
|
|
45
|
+
next_cursor: result.nextCursor ? encodeManagementCursor(result.nextCursor) : null
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
//# sourceMappingURL=list-variables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/presentation/routes/list-variables.ts"],"sourcesContent":["import {listVariablesQuerySchema, listVariablesResponseSchema} from '@shipfox/api-secrets-dto';\nimport {ClientError, defineRoute} from '@shipfox/node-fastify';\nimport {z} from 'zod';\nimport {listManagedVariables} from '#core/index.js';\nimport {toVariableListItemDto} from '#presentation/dto/index.js';\nimport {requireManagementRead} from './auth.js';\nimport {decodeManagementCursor, encodeManagementCursor} from './cursor.js';\nimport {translateManagementError} from './errors.js';\n\nexport const listVariablesRoute = defineRoute({\n method: 'GET',\n path: '/variables',\n description: 'List user-managed variables for a workspace or project scope.',\n schema: {\n params: z.object({workspaceId: z.string().uuid()}),\n querystring: listVariablesQuerySchema,\n response: {200: listVariablesResponseSchema},\n },\n errorHandler: translateManagementError,\n handler: async (request) => {\n const {workspaceId} = request.params;\n const {project_id: projectId, limit, cursor} = request.query;\n const decodedCursor = decodeManagementCursor(cursor);\n if (cursor && !decodedCursor) {\n throw new ClientError('Invalid cursor', 'invalid-cursor', {status: 400});\n }\n\n await requireManagementRead({request, workspaceId, projectId});\n const result = await listManagedVariables({\n workspaceId,\n projectId,\n limit,\n cursor: decodedCursor ?? undefined,\n });\n\n return {\n variables: result.variables.map(toVariableListItemDto),\n next_cursor: result.nextCursor ? encodeManagementCursor(result.nextCursor) : null,\n };\n },\n});\n"],"names":["listVariablesQuerySchema","listVariablesResponseSchema","ClientError","defineRoute","z","listManagedVariables","toVariableListItemDto","requireManagementRead","decodeManagementCursor","encodeManagementCursor","translateManagementError","listVariablesRoute","method","path","description","schema","params","object","workspaceId","string","uuid","querystring","response","errorHandler","handler","request","project_id","projectId","limit","cursor","query","decodedCursor","status","result","undefined","variables","map","next_cursor","nextCursor"],"mappings":"AAAA,SAAQA,wBAAwB,EAAEC,2BAA2B,QAAO,2BAA2B;AAC/F,SAAQC,WAAW,EAAEC,WAAW,QAAO,wBAAwB;AAC/D,SAAQC,CAAC,QAAO,MAAM;AACtB,SAAQC,oBAAoB,QAAO,iBAAiB;AACpD,SAAQC,qBAAqB,QAAO,6BAA6B;AACjE,SAAQC,qBAAqB,QAAO,YAAY;AAChD,SAAQC,sBAAsB,EAAEC,sBAAsB,QAAO,cAAc;AAC3E,SAAQC,wBAAwB,QAAO,cAAc;AAErD,OAAO,MAAMC,qBAAqBR,YAAY;IAC5CS,QAAQ;IACRC,MAAM;IACNC,aAAa;IACbC,QAAQ;QACNC,QAAQZ,EAAEa,MAAM,CAAC;YAACC,aAAad,EAAEe,MAAM,GAAGC,IAAI;QAAE;QAChDC,aAAarB;QACbsB,UAAU;YAAC,KAAKrB;QAA2B;IAC7C;IACAsB,cAAcb;IACdc,SAAS,OAAOC;QACd,MAAM,EAACP,WAAW,EAAC,GAAGO,QAAQT,MAAM;QACpC,MAAM,EAACU,YAAYC,SAAS,EAAEC,KAAK,EAAEC,MAAM,EAAC,GAAGJ,QAAQK,KAAK;QAC5D,MAAMC,gBAAgBvB,uBAAuBqB;QAC7C,IAAIA,UAAU,CAACE,eAAe;YAC5B,MAAM,IAAI7B,YAAY,kBAAkB,kBAAkB;gBAAC8B,QAAQ;YAAG;QACxE;QAEA,MAAMzB,sBAAsB;YAACkB;YAASP;YAAaS;QAAS;QAC5D,MAAMM,SAAS,MAAM5B,qBAAqB;YACxCa;YACAS;YACAC;YACAC,QAAQE,iBAAiBG;QAC3B;QAEA,OAAO;YACLC,WAAWF,OAAOE,SAAS,CAACC,GAAG,CAAC9B;YAChC+B,aAAaJ,OAAOK,UAAU,GAAG7B,uBAAuBwB,OAAOK,UAAU,IAAI;QAC/E;IACF;AACF,GAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"put-secret.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/put-secret.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,cAAc,iDAyBzB,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { putSecretBodySchema, putSecretResponseSchema, secretKeySchema } from '@shipfox/api-secrets-dto';
|
|
2
|
+
import { defineRoute } from '@shipfox/node-fastify';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { setManagedSecrets } from '#core/index.js';
|
|
5
|
+
import { toSecretDto } from '#presentation/dto/index.js';
|
|
6
|
+
import { requireManagementWrite } from './auth.js';
|
|
7
|
+
import { translateManagementError } from './errors.js';
|
|
8
|
+
import { secretWarnings } from './warnings.js';
|
|
9
|
+
export const putSecretRoute = defineRoute({
|
|
10
|
+
method: 'PUT',
|
|
11
|
+
path: '/secrets/:key',
|
|
12
|
+
description: 'Create or update a user-managed secret.',
|
|
13
|
+
schema: {
|
|
14
|
+
params: z.object({
|
|
15
|
+
workspaceId: z.string().uuid(),
|
|
16
|
+
key: secretKeySchema
|
|
17
|
+
}),
|
|
18
|
+
body: putSecretBodySchema,
|
|
19
|
+
response: {
|
|
20
|
+
200: putSecretResponseSchema
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
errorHandler: translateManagementError,
|
|
24
|
+
handler: async (request)=>{
|
|
25
|
+
const { workspaceId, key } = request.params;
|
|
26
|
+
const { project_id: projectId, value } = request.body;
|
|
27
|
+
const access = await requireManagementWrite({
|
|
28
|
+
request,
|
|
29
|
+
workspaceId,
|
|
30
|
+
projectId
|
|
31
|
+
});
|
|
32
|
+
const entries = [
|
|
33
|
+
{
|
|
34
|
+
key,
|
|
35
|
+
value
|
|
36
|
+
}
|
|
37
|
+
];
|
|
38
|
+
const [secret] = await setManagedSecrets({
|
|
39
|
+
workspaceId,
|
|
40
|
+
projectId,
|
|
41
|
+
actorId: access.userId,
|
|
42
|
+
entries
|
|
43
|
+
});
|
|
44
|
+
if (!secret) throw new Error('Secret write returned no row');
|
|
45
|
+
return {
|
|
46
|
+
secret: toSecretDto(secret),
|
|
47
|
+
warnings: secretWarnings(entries)
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=put-secret.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/presentation/routes/put-secret.ts"],"sourcesContent":["import {\n putSecretBodySchema,\n putSecretResponseSchema,\n secretKeySchema,\n} from '@shipfox/api-secrets-dto';\nimport {defineRoute} from '@shipfox/node-fastify';\nimport {z} from 'zod';\nimport {setManagedSecrets} from '#core/index.js';\nimport {toSecretDto} from '#presentation/dto/index.js';\nimport {requireManagementWrite} from './auth.js';\nimport {translateManagementError} from './errors.js';\nimport {secretWarnings} from './warnings.js';\n\nexport const putSecretRoute = defineRoute({\n method: 'PUT',\n path: '/secrets/:key',\n description: 'Create or update a user-managed secret.',\n schema: {\n params: z.object({workspaceId: z.string().uuid(), key: secretKeySchema}),\n body: putSecretBodySchema,\n response: {200: putSecretResponseSchema},\n },\n errorHandler: translateManagementError,\n handler: async (request) => {\n const {workspaceId, key} = request.params;\n const {project_id: projectId, value} = request.body;\n const access = await requireManagementWrite({request, workspaceId, projectId});\n const entries = [{key, value}];\n const [secret] = await setManagedSecrets({\n workspaceId,\n projectId,\n actorId: access.userId,\n entries,\n });\n if (!secret) throw new Error('Secret write returned no row');\n\n return {secret: toSecretDto(secret), warnings: secretWarnings(entries)};\n },\n});\n"],"names":["putSecretBodySchema","putSecretResponseSchema","secretKeySchema","defineRoute","z","setManagedSecrets","toSecretDto","requireManagementWrite","translateManagementError","secretWarnings","putSecretRoute","method","path","description","schema","params","object","workspaceId","string","uuid","key","body","response","errorHandler","handler","request","project_id","projectId","value","access","entries","secret","actorId","userId","Error","warnings"],"mappings":"AAAA,SACEA,mBAAmB,EACnBC,uBAAuB,EACvBC,eAAe,QACV,2BAA2B;AAClC,SAAQC,WAAW,QAAO,wBAAwB;AAClD,SAAQC,CAAC,QAAO,MAAM;AACtB,SAAQC,iBAAiB,QAAO,iBAAiB;AACjD,SAAQC,WAAW,QAAO,6BAA6B;AACvD,SAAQC,sBAAsB,QAAO,YAAY;AACjD,SAAQC,wBAAwB,QAAO,cAAc;AACrD,SAAQC,cAAc,QAAO,gBAAgB;AAE7C,OAAO,MAAMC,iBAAiBP,YAAY;IACxCQ,QAAQ;IACRC,MAAM;IACNC,aAAa;IACbC,QAAQ;QACNC,QAAQX,EAAEY,MAAM,CAAC;YAACC,aAAab,EAAEc,MAAM,GAAGC,IAAI;YAAIC,KAAKlB;QAAe;QACtEmB,MAAMrB;QACNsB,UAAU;YAAC,KAAKrB;QAAuB;IACzC;IACAsB,cAAcf;IACdgB,SAAS,OAAOC;QACd,MAAM,EAACR,WAAW,EAAEG,GAAG,EAAC,GAAGK,QAAQV,MAAM;QACzC,MAAM,EAACW,YAAYC,SAAS,EAAEC,KAAK,EAAC,GAAGH,QAAQJ,IAAI;QACnD,MAAMQ,SAAS,MAAMtB,uBAAuB;YAACkB;YAASR;YAAaU;QAAS;QAC5E,MAAMG,UAAU;YAAC;gBAACV;gBAAKQ;YAAK;SAAE;QAC9B,MAAM,CAACG,OAAO,GAAG,MAAM1B,kBAAkB;YACvCY;YACAU;YACAK,SAASH,OAAOI,MAAM;YACtBH;QACF;QACA,IAAI,CAACC,QAAQ,MAAM,IAAIG,MAAM;QAE7B,OAAO;YAACH,QAAQzB,YAAYyB;YAASI,UAAU1B,eAAeqB;QAAQ;IACxE;AACF,GAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"put-variable.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/put-variable.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,gBAAgB,iDAyB3B,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { putVariableBodySchema, putVariableResponseSchema, secretKeySchema } from '@shipfox/api-secrets-dto';
|
|
2
|
+
import { defineRoute } from '@shipfox/node-fastify';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { setManagedVariables } from '#core/index.js';
|
|
5
|
+
import { toVariableDto } from '#presentation/dto/index.js';
|
|
6
|
+
import { requireManagementWrite } from './auth.js';
|
|
7
|
+
import { translateManagementError } from './errors.js';
|
|
8
|
+
import { variableWarnings } from './warnings.js';
|
|
9
|
+
export const putVariableRoute = defineRoute({
|
|
10
|
+
method: 'PUT',
|
|
11
|
+
path: '/variables/:key',
|
|
12
|
+
description: 'Create or update a user-managed variable.',
|
|
13
|
+
schema: {
|
|
14
|
+
params: z.object({
|
|
15
|
+
workspaceId: z.string().uuid(),
|
|
16
|
+
key: secretKeySchema
|
|
17
|
+
}),
|
|
18
|
+
body: putVariableBodySchema,
|
|
19
|
+
response: {
|
|
20
|
+
200: putVariableResponseSchema
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
errorHandler: translateManagementError,
|
|
24
|
+
handler: async (request)=>{
|
|
25
|
+
const { workspaceId, key } = request.params;
|
|
26
|
+
const { project_id: projectId, value } = request.body;
|
|
27
|
+
const access = await requireManagementWrite({
|
|
28
|
+
request,
|
|
29
|
+
workspaceId,
|
|
30
|
+
projectId
|
|
31
|
+
});
|
|
32
|
+
const entries = [
|
|
33
|
+
{
|
|
34
|
+
key,
|
|
35
|
+
value
|
|
36
|
+
}
|
|
37
|
+
];
|
|
38
|
+
const [variable] = await setManagedVariables({
|
|
39
|
+
workspaceId,
|
|
40
|
+
projectId,
|
|
41
|
+
actorId: access.userId,
|
|
42
|
+
entries
|
|
43
|
+
});
|
|
44
|
+
if (!variable) throw new Error('Variable write returned no row');
|
|
45
|
+
return {
|
|
46
|
+
variable: toVariableDto(variable),
|
|
47
|
+
warnings: variableWarnings(entries)
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=put-variable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/presentation/routes/put-variable.ts"],"sourcesContent":["import {\n putVariableBodySchema,\n putVariableResponseSchema,\n secretKeySchema,\n} from '@shipfox/api-secrets-dto';\nimport {defineRoute} from '@shipfox/node-fastify';\nimport {z} from 'zod';\nimport {setManagedVariables} from '#core/index.js';\nimport {toVariableDto} from '#presentation/dto/index.js';\nimport {requireManagementWrite} from './auth.js';\nimport {translateManagementError} from './errors.js';\nimport {variableWarnings} from './warnings.js';\n\nexport const putVariableRoute = defineRoute({\n method: 'PUT',\n path: '/variables/:key',\n description: 'Create or update a user-managed variable.',\n schema: {\n params: z.object({workspaceId: z.string().uuid(), key: secretKeySchema}),\n body: putVariableBodySchema,\n response: {200: putVariableResponseSchema},\n },\n errorHandler: translateManagementError,\n handler: async (request) => {\n const {workspaceId, key} = request.params;\n const {project_id: projectId, value} = request.body;\n const access = await requireManagementWrite({request, workspaceId, projectId});\n const entries = [{key, value}];\n const [variable] = await setManagedVariables({\n workspaceId,\n projectId,\n actorId: access.userId,\n entries,\n });\n if (!variable) throw new Error('Variable write returned no row');\n\n return {variable: toVariableDto(variable), warnings: variableWarnings(entries)};\n },\n});\n"],"names":["putVariableBodySchema","putVariableResponseSchema","secretKeySchema","defineRoute","z","setManagedVariables","toVariableDto","requireManagementWrite","translateManagementError","variableWarnings","putVariableRoute","method","path","description","schema","params","object","workspaceId","string","uuid","key","body","response","errorHandler","handler","request","project_id","projectId","value","access","entries","variable","actorId","userId","Error","warnings"],"mappings":"AAAA,SACEA,qBAAqB,EACrBC,yBAAyB,EACzBC,eAAe,QACV,2BAA2B;AAClC,SAAQC,WAAW,QAAO,wBAAwB;AAClD,SAAQC,CAAC,QAAO,MAAM;AACtB,SAAQC,mBAAmB,QAAO,iBAAiB;AACnD,SAAQC,aAAa,QAAO,6BAA6B;AACzD,SAAQC,sBAAsB,QAAO,YAAY;AACjD,SAAQC,wBAAwB,QAAO,cAAc;AACrD,SAAQC,gBAAgB,QAAO,gBAAgB;AAE/C,OAAO,MAAMC,mBAAmBP,YAAY;IAC1CQ,QAAQ;IACRC,MAAM;IACNC,aAAa;IACbC,QAAQ;QACNC,QAAQX,EAAEY,MAAM,CAAC;YAACC,aAAab,EAAEc,MAAM,GAAGC,IAAI;YAAIC,KAAKlB;QAAe;QACtEmB,MAAMrB;QACNsB,UAAU;YAAC,KAAKrB;QAAyB;IAC3C;IACAsB,cAAcf;IACdgB,SAAS,OAAOC;QACd,MAAM,EAACR,WAAW,EAAEG,GAAG,EAAC,GAAGK,QAAQV,MAAM;QACzC,MAAM,EAACW,YAAYC,SAAS,EAAEC,KAAK,EAAC,GAAGH,QAAQJ,IAAI;QACnD,MAAMQ,SAAS,MAAMtB,uBAAuB;YAACkB;YAASR;YAAaU;QAAS;QAC5E,MAAMG,UAAU;YAAC;gBAACV;gBAAKQ;YAAK;SAAE;QAC9B,MAAM,CAACG,SAAS,GAAG,MAAM1B,oBAAoB;YAC3CY;YACAU;YACAK,SAASH,OAAOI,MAAM;YACtBH;QACF;QACA,IAAI,CAACC,UAAU,MAAM,IAAIG,MAAM;QAE/B,OAAO;YAACH,UAAUzB,cAAcyB;YAAWI,UAAU1B,iBAAiBqB;QAAQ;IAChF;AACF,GAAG"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type SecretWriteWarningDto } from '@shipfox/api-secrets-dto';
|
|
2
|
+
import type { ManagementEntry } from '#core/index.js';
|
|
3
|
+
export declare function secretWarnings(entries: ManagementEntry[]): SecretWriteWarningDto[];
|
|
4
|
+
export declare function variableWarnings(entries: ManagementEntry[]): SecretWriteWarningDto[];
|
|
5
|
+
//# sourceMappingURL=warnings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"warnings.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/warnings.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,qBAAqB,EAI3B,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,gBAAgB,CAAC;AAEpD,wBAAgB,cAAc,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,qBAAqB,EAAE,CAMlF;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,qBAAqB,EAAE,CAIpF"}
|