@shipfox/api-secrets 5.0.0 → 6.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 +1 -1
- package/CHANGELOG.md +28 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +29 -15
- package/dist/index.js.map +1 -1
- package/dist/presentation/inter-module.d.ts +4 -0
- package/dist/presentation/inter-module.d.ts.map +1 -0
- package/dist/presentation/inter-module.js +73 -0
- package/dist/presentation/inter-module.js.map +1 -0
- package/dist/presentation/routes/auth.d.ts +14 -10
- package/dist/presentation/routes/auth.d.ts.map +1 -1
- package/dist/presentation/routes/auth.js +27 -11
- package/dist/presentation/routes/auth.js.map +1 -1
- package/dist/presentation/routes/batch-secrets.d.ts +2 -1
- package/dist/presentation/routes/batch-secrets.d.ts.map +1 -1
- package/dist/presentation/routes/batch-secrets.js +35 -34
- package/dist/presentation/routes/batch-secrets.js.map +1 -1
- package/dist/presentation/routes/batch-variables.d.ts +2 -1
- package/dist/presentation/routes/batch-variables.d.ts.map +1 -1
- package/dist/presentation/routes/batch-variables.js +35 -34
- package/dist/presentation/routes/batch-variables.js.map +1 -1
- package/dist/presentation/routes/delete-secret.d.ts +2 -1
- package/dist/presentation/routes/delete-secret.d.ts.map +1 -1
- package/dist/presentation/routes/delete-secret.js +33 -32
- package/dist/presentation/routes/delete-secret.js.map +1 -1
- package/dist/presentation/routes/delete-variable.d.ts +2 -1
- package/dist/presentation/routes/delete-variable.d.ts.map +1 -1
- package/dist/presentation/routes/delete-variable.js +33 -32
- package/dist/presentation/routes/delete-variable.js.map +1 -1
- package/dist/presentation/routes/errors.d.ts.map +1 -1
- package/dist/presentation/routes/errors.js +0 -6
- package/dist/presentation/routes/errors.js.map +1 -1
- package/dist/presentation/routes/get-variable.d.ts +2 -1
- package/dist/presentation/routes/get-variable.d.ts.map +1 -1
- package/dist/presentation/routes/get-variable.js +34 -33
- package/dist/presentation/routes/get-variable.js.map +1 -1
- package/dist/presentation/routes/index.d.ts +2 -1
- package/dist/presentation/routes/index.d.ts.map +1 -1
- package/dist/presentation/routes/index.js +21 -17
- package/dist/presentation/routes/index.js.map +1 -1
- package/dist/presentation/routes/list-secrets.d.ts +2 -1
- package/dist/presentation/routes/list-secrets.d.ts.map +1 -1
- package/dist/presentation/routes/list-secrets.js +40 -39
- package/dist/presentation/routes/list-secrets.js.map +1 -1
- package/dist/presentation/routes/list-variables.d.ts +2 -1
- package/dist/presentation/routes/list-variables.d.ts.map +1 -1
- package/dist/presentation/routes/list-variables.js +40 -39
- package/dist/presentation/routes/list-variables.js.map +1 -1
- package/dist/presentation/routes/put-secret.d.ts +2 -1
- package/dist/presentation/routes/put-secret.d.ts.map +1 -1
- package/dist/presentation/routes/put-secret.js +43 -42
- package/dist/presentation/routes/put-secret.js.map +1 -1
- package/dist/presentation/routes/put-variable.d.ts +2 -1
- package/dist/presentation/routes/put-variable.d.ts.map +1 -1
- package/dist/presentation/routes/put-variable.js +43 -42
- package/dist/presentation/routes/put-variable.js.map +1 -1
- package/dist/tsconfig.test.tsbuildinfo +1 -1
- package/package.json +11 -8
- package/src/index.ts +16 -5
- package/src/presentation/inter-module.test.ts +32 -0
- package/src/presentation/inter-module.ts +78 -0
- package/src/presentation/routes/auth.ts +65 -19
- package/src/presentation/routes/batch-secrets.ts +26 -24
- package/src/presentation/routes/batch-variables.ts +26 -24
- package/src/presentation/routes/delete-secret.ts +21 -19
- package/src/presentation/routes/delete-variable.ts +21 -19
- package/src/presentation/routes/errors.ts +0 -5
- package/src/presentation/routes/get-variable.ts +21 -19
- package/src/presentation/routes/index.ts +22 -17
- package/src/presentation/routes/list-secrets.ts +33 -31
- package/src/presentation/routes/list-variables.ts +33 -31
- package/src/presentation/routes/management.test.ts +32 -18
- package/src/presentation/routes/put-secret.ts +28 -26
- package/src/presentation/routes/put-variable.ts +28 -26
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -3,48 +3,49 @@ import { ClientError, defineRoute } from '@shipfox/node-fastify';
|
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { listManagedVariables } from '#core/index.js';
|
|
5
5
|
import { toVariableListItemDto } from '#presentation/dto/index.js';
|
|
6
|
-
import { requireManagementRead } from './auth.js';
|
|
7
6
|
import { decodeManagementCursor, encodeManagementCursor } from './cursor.js';
|
|
8
7
|
import { translateManagementError } from './errors.js';
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
8
|
+
export function listVariablesRoute(accessControl) {
|
|
9
|
+
return 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 accessControl.requireManagementRead({
|
|
33
|
+
request,
|
|
34
|
+
workspaceId,
|
|
35
|
+
projectId
|
|
36
|
+
});
|
|
37
|
+
const result = await listManagedVariables({
|
|
38
|
+
workspaceId,
|
|
39
|
+
projectId,
|
|
40
|
+
limit,
|
|
41
|
+
cursor: decodedCursor ?? undefined
|
|
30
42
|
});
|
|
43
|
+
return {
|
|
44
|
+
variables: result.variables.map(toVariableListItemDto),
|
|
45
|
+
next_cursor: result.nextCursor ? encodeManagementCursor(result.nextCursor) : null
|
|
46
|
+
};
|
|
31
47
|
}
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
49
50
|
|
|
50
51
|
//# sourceMappingURL=list-variables.js.map
|
|
@@ -1 +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 {
|
|
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 type {ManagementAccessHelpers} from './auth.js';\nimport {decodeManagementCursor, encodeManagementCursor} from './cursor.js';\nimport {translateManagementError} from './errors.js';\n\nexport function listVariablesRoute(accessControl: ManagementAccessHelpers) {\n return 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 accessControl.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}\n"],"names":["listVariablesQuerySchema","listVariablesResponseSchema","ClientError","defineRoute","z","listManagedVariables","toVariableListItemDto","decodeManagementCursor","encodeManagementCursor","translateManagementError","listVariablesRoute","accessControl","method","path","description","schema","params","object","workspaceId","string","uuid","querystring","response","errorHandler","handler","request","project_id","projectId","limit","cursor","query","decodedCursor","status","requireManagementRead","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;AAEjE,SAAQC,sBAAsB,EAAEC,sBAAsB,QAAO,cAAc;AAC3E,SAAQC,wBAAwB,QAAO,cAAc;AAErD,OAAO,SAASC,mBAAmBC,aAAsC;IACvE,OAAOR,YAAY;QACjBS,QAAQ;QACRC,MAAM;QACNC,aAAa;QACbC,QAAQ;YACNC,QAAQZ,EAAEa,MAAM,CAAC;gBAACC,aAAad,EAAEe,MAAM,GAAGC,IAAI;YAAE;YAChDC,aAAarB;YACbsB,UAAU;gBAAC,KAAKrB;YAA2B;QAC7C;QACAsB,cAAcd;QACde,SAAS,OAAOC;YACd,MAAM,EAACP,WAAW,EAAC,GAAGO,QAAQT,MAAM;YACpC,MAAM,EAACU,YAAYC,SAAS,EAAEC,KAAK,EAAEC,MAAM,EAAC,GAAGJ,QAAQK,KAAK;YAC5D,MAAMC,gBAAgBxB,uBAAuBsB;YAC7C,IAAIA,UAAU,CAACE,eAAe;gBAC5B,MAAM,IAAI7B,YAAY,kBAAkB,kBAAkB;oBAAC8B,QAAQ;gBAAG;YACxE;YAEA,MAAMrB,cAAcsB,qBAAqB,CAAC;gBAACR;gBAASP;gBAAaS;YAAS;YAC1E,MAAMO,SAAS,MAAM7B,qBAAqB;gBACxCa;gBACAS;gBACAC;gBACAC,QAAQE,iBAAiBI;YAC3B;YAEA,OAAO;gBACLC,WAAWF,OAAOE,SAAS,CAACC,GAAG,CAAC/B;gBAChCgC,aAAaJ,OAAOK,UAAU,GAAG/B,uBAAuB0B,OAAOK,UAAU,IAAI;YAC/E;QACF;IACF;AACF"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import type { ManagementAccessHelpers } from './auth.js';
|
|
2
|
+
export declare function putSecretRoute(accessControl: ManagementAccessHelpers): import("@shipfox/node-fastify").RouteDefinition;
|
|
2
3
|
//# sourceMappingURL=put-secret.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"put-secret.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/put-secret.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"put-secret.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/put-secret.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAC,uBAAuB,EAAC,MAAM,WAAW,CAAC;AAIvD,wBAAgB,cAAc,CAAC,aAAa,EAAE,uBAAuB,mDA2BpE"}
|
|
@@ -3,50 +3,51 @@ import { defineRoute } from '@shipfox/node-fastify';
|
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { setManagedSecrets } from '#core/index.js';
|
|
5
5
|
import { toSecretDto } from '#presentation/dto/index.js';
|
|
6
|
-
import { requireManagementWrite } from './auth.js';
|
|
7
6
|
import { translateManagementError } from './errors.js';
|
|
8
7
|
import { secretWarnings } from './warnings.js';
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
|
8
|
+
export function putSecretRoute(accessControl) {
|
|
9
|
+
return 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
|
|
36
21
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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 accessControl.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
|
+
}
|
|
51
52
|
|
|
52
53
|
//# sourceMappingURL=put-secret.js.map
|
|
@@ -1 +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 {
|
|
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 type {ManagementAccessHelpers} from './auth.js';\nimport {translateManagementError} from './errors.js';\nimport {secretWarnings} from './warnings.js';\n\nexport function putSecretRoute(accessControl: ManagementAccessHelpers) {\n return 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 accessControl.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}\n"],"names":["putSecretBodySchema","putSecretResponseSchema","secretKeySchema","defineRoute","z","setManagedSecrets","toSecretDto","translateManagementError","secretWarnings","putSecretRoute","accessControl","method","path","description","schema","params","object","workspaceId","string","uuid","key","body","response","errorHandler","handler","request","project_id","projectId","value","access","requireManagementWrite","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;AAEvD,SAAQC,wBAAwB,QAAO,cAAc;AACrD,SAAQC,cAAc,QAAO,gBAAgB;AAE7C,OAAO,SAASC,eAAeC,aAAsC;IACnE,OAAOP,YAAY;QACjBQ,QAAQ;QACRC,MAAM;QACNC,aAAa;QACbC,QAAQ;YACNC,QAAQX,EAAEY,MAAM,CAAC;gBAACC,aAAab,EAAEc,MAAM,GAAGC,IAAI;gBAAIC,KAAKlB;YAAe;YACtEmB,MAAMrB;YACNsB,UAAU;gBAAC,KAAKrB;YAAuB;QACzC;QACAsB,cAAchB;QACdiB,SAAS,OAAOC;YACd,MAAM,EAACR,WAAW,EAAEG,GAAG,EAAC,GAAGK,QAAQV,MAAM;YACzC,MAAM,EAACW,YAAYC,SAAS,EAAEC,KAAK,EAAC,GAAGH,QAAQJ,IAAI;YACnD,MAAMQ,SAAS,MAAMnB,cAAcoB,sBAAsB,CAAC;gBAACL;gBAASR;gBAAaU;YAAS;YAC1F,MAAMI,UAAU;gBAAC;oBAACX;oBAAKQ;gBAAK;aAAE;YAC9B,MAAM,CAACI,OAAO,GAAG,MAAM3B,kBAAkB;gBACvCY;gBACAU;gBACAM,SAASJ,OAAOK,MAAM;gBACtBH;YACF;YACA,IAAI,CAACC,QAAQ,MAAM,IAAIG,MAAM;YAE7B,OAAO;gBAACH,QAAQ1B,YAAY0B;gBAASI,UAAU5B,eAAeuB;YAAQ;QACxE;IACF;AACF"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import type { ManagementAccessHelpers } from './auth.js';
|
|
2
|
+
export declare function putVariableRoute(accessControl: ManagementAccessHelpers): import("@shipfox/node-fastify").RouteDefinition;
|
|
2
3
|
//# sourceMappingURL=put-variable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"put-variable.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/put-variable.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"put-variable.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/put-variable.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAC,uBAAuB,EAAC,MAAM,WAAW,CAAC;AAIvD,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,uBAAuB,mDA2BtE"}
|
|
@@ -3,50 +3,51 @@ import { defineRoute } from '@shipfox/node-fastify';
|
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { setManagedVariables } from '#core/index.js';
|
|
5
5
|
import { toVariableDto } from '#presentation/dto/index.js';
|
|
6
|
-
import { requireManagementWrite } from './auth.js';
|
|
7
6
|
import { translateManagementError } from './errors.js';
|
|
8
7
|
import { variableWarnings } from './warnings.js';
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
|
8
|
+
export function putVariableRoute(accessControl) {
|
|
9
|
+
return 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
|
|
36
21
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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 accessControl.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
|
+
}
|
|
51
52
|
|
|
52
53
|
//# sourceMappingURL=put-variable.js.map
|
|
@@ -1 +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 {
|
|
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 type {ManagementAccessHelpers} from './auth.js';\nimport {translateManagementError} from './errors.js';\nimport {variableWarnings} from './warnings.js';\n\nexport function putVariableRoute(accessControl: ManagementAccessHelpers) {\n return 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 accessControl.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}\n"],"names":["putVariableBodySchema","putVariableResponseSchema","secretKeySchema","defineRoute","z","setManagedVariables","toVariableDto","translateManagementError","variableWarnings","putVariableRoute","accessControl","method","path","description","schema","params","object","workspaceId","string","uuid","key","body","response","errorHandler","handler","request","project_id","projectId","value","access","requireManagementWrite","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;AAEzD,SAAQC,wBAAwB,QAAO,cAAc;AACrD,SAAQC,gBAAgB,QAAO,gBAAgB;AAE/C,OAAO,SAASC,iBAAiBC,aAAsC;IACrE,OAAOP,YAAY;QACjBQ,QAAQ;QACRC,MAAM;QACNC,aAAa;QACbC,QAAQ;YACNC,QAAQX,EAAEY,MAAM,CAAC;gBAACC,aAAab,EAAEc,MAAM,GAAGC,IAAI;gBAAIC,KAAKlB;YAAe;YACtEmB,MAAMrB;YACNsB,UAAU;gBAAC,KAAKrB;YAAyB;QAC3C;QACAsB,cAAchB;QACdiB,SAAS,OAAOC;YACd,MAAM,EAACR,WAAW,EAAEG,GAAG,EAAC,GAAGK,QAAQV,MAAM;YACzC,MAAM,EAACW,YAAYC,SAAS,EAAEC,KAAK,EAAC,GAAGH,QAAQJ,IAAI;YACnD,MAAMQ,SAAS,MAAMnB,cAAcoB,sBAAsB,CAAC;gBAACL;gBAASR;gBAAaU;YAAS;YAC1F,MAAMI,UAAU;gBAAC;oBAACX;oBAAKQ;gBAAK;aAAE;YAC9B,MAAM,CAACI,SAAS,GAAG,MAAM3B,oBAAoB;gBAC3CY;gBACAU;gBACAM,SAASJ,OAAOK,MAAM;gBACtBH;YACF;YACA,IAAI,CAACC,UAAU,MAAM,IAAIG,MAAM;YAE/B,OAAO;gBAACH,UAAU1B,cAAc0B;gBAAWI,UAAU5B,iBAAiBuB;YAAQ;QAChF;IACF;AACF"}
|