@shipfox/api-workflows 9.2.0 → 10.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.
Files changed (41) hide show
  1. package/.turbo/turbo-build.log +4 -4
  2. package/CHANGELOG.md +57 -0
  3. package/dist/core/errors.d.ts +12 -0
  4. package/dist/core/errors.d.ts.map +1 -1
  5. package/dist/core/errors.js +18 -0
  6. package/dist/core/errors.js.map +1 -1
  7. package/dist/core/workspace-admission.d.ts +3 -0
  8. package/dist/core/workspace-admission.d.ts.map +1 -0
  9. package/dist/core/workspace-admission.js +32 -0
  10. package/dist/core/workspace-admission.js.map +1 -0
  11. package/dist/index.d.ts +3 -1
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +5 -3
  14. package/dist/index.js.map +1 -1
  15. package/dist/presentation/inter-module.d.ts +2 -0
  16. package/dist/presentation/inter-module.d.ts.map +1 -1
  17. package/dist/presentation/inter-module.js +40 -5
  18. package/dist/presentation/inter-module.js.map +1 -1
  19. package/dist/presentation/routes/index.d.ts +4 -1
  20. package/dist/presentation/routes/index.d.ts.map +1 -1
  21. package/dist/presentation/routes/index.js +1 -1
  22. package/dist/presentation/routes/index.js.map +1 -1
  23. package/dist/presentation/routes/rerun-run.d.ts +2 -1
  24. package/dist/presentation/routes/rerun-run.d.ts.map +1 -1
  25. package/dist/presentation/routes/rerun-run.js +22 -2
  26. package/dist/presentation/routes/rerun-run.js.map +1 -1
  27. package/dist/tsconfig.test.tsbuildinfo +1 -1
  28. package/package.json +17 -16
  29. package/src/core/errors.ts +21 -0
  30. package/src/core/workspace-admission.test.ts +64 -0
  31. package/src/core/workspace-admission.ts +43 -0
  32. package/src/index.ts +5 -0
  33. package/src/presentation/dto/step.test.ts +20 -0
  34. package/src/presentation/inter-module.test.ts +198 -1
  35. package/src/presentation/inter-module.ts +55 -3
  36. package/src/presentation/routes/index.test.ts +1 -0
  37. package/src/presentation/routes/index.ts +6 -2
  38. package/src/presentation/routes/rerun-run.test.ts +58 -1
  39. package/src/presentation/routes/rerun-run.ts +34 -2
  40. package/test/fixtures/runners-inter-module.ts +3 -0
  41. package/tsconfig.build.tsbuildinfo +1 -1
@@ -2,11 +2,12 @@ import { requireUserContext } from '@shipfox/api-auth-context';
2
2
  import { rerunWorkflowRunBodySchema, workflowRunResponseSchema } from '@shipfox/api-workflows-dto';
3
3
  import { ClientError, defineRoute } from '@shipfox/node-fastify';
4
4
  import { z } from 'zod';
5
- import { NoFailedJobsError, RunNotTerminalError, SourceRunNotFoundError } from '#core/errors.js';
5
+ import { NoFailedJobsError, RunNotTerminalError, SourceRunNotFoundError, WorkspaceDeletedError, WorkspaceNotFoundError, WorkspaceSuspendedError } from '#core/errors.js';
6
+ import { assertWorkspaceAdmitsNewJobs } from '#core/workspace-admission.js';
6
7
  import { createRerunWorkflowRun } from '#db/index.js';
7
8
  import { toRunDto } from '#presentation/dto/index.js';
8
9
  import { requireAccessibleRun } from './require-accessible-run.js';
9
- export function rerunRunRoute(projects) {
10
+ export function rerunRunRoute(projects, workspaces) {
10
11
  return defineRoute({
11
12
  method: 'POST',
12
13
  path: '/:id/rerun',
@@ -36,6 +37,24 @@ export function rerunRunRoute(projects) {
36
37
  status: 409
37
38
  });
38
39
  }
40
+ if (error instanceof WorkspaceSuspendedError) {
41
+ throw new ClientError('Workspace is suspended', 'workspace-suspended', {
42
+ status: 409,
43
+ cause: error
44
+ });
45
+ }
46
+ if (error instanceof WorkspaceDeletedError) {
47
+ throw new ClientError('Workspace is deleted', 'workspace-deleted', {
48
+ status: 404,
49
+ cause: error
50
+ });
51
+ }
52
+ if (error instanceof WorkspaceNotFoundError) {
53
+ throw new ClientError('Workspace not found', 'workspace-not-found', {
54
+ status: 404,
55
+ cause: error
56
+ });
57
+ }
39
58
  throw error;
40
59
  },
41
60
  handler: async (request)=>{
@@ -45,6 +64,7 @@ export function rerunRunRoute(projects) {
45
64
  id,
46
65
  projects
47
66
  });
67
+ await assertWorkspaceAdmitsNewJobs(workspaces, sourceRun.workspaceId);
48
68
  const actor = requireUserContext(request);
49
69
  const run = await createRerunWorkflowRun({
50
70
  workflowRunId: sourceRun.id,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/presentation/routes/rerun-run.ts"],"sourcesContent":["import {requireUserContext} from '@shipfox/api-auth-context';\nimport type {ProjectsModuleClient} from '@shipfox/api-projects-dto/inter-module';\nimport {rerunWorkflowRunBodySchema, workflowRunResponseSchema} from '@shipfox/api-workflows-dto';\nimport {ClientError, defineRoute} from '@shipfox/node-fastify';\nimport {z} from 'zod';\nimport {NoFailedJobsError, RunNotTerminalError, SourceRunNotFoundError} from '#core/errors.js';\nimport {createRerunWorkflowRun} from '#db/index.js';\nimport {toRunDto} from '#presentation/dto/index.js';\nimport {requireAccessibleRun} from './require-accessible-run.js';\n\nexport function rerunRunRoute(projects: ProjectsModuleClient) {\n return defineRoute({\n method: 'POST',\n path: '/:id/rerun',\n description: 'Re-run a terminal workflow run',\n schema: {\n params: z.object({\n id: z.string().uuid(),\n }),\n body: rerunWorkflowRunBodySchema,\n response: {\n 200: workflowRunResponseSchema,\n },\n },\n errorHandler: (error) => {\n if (error instanceof SourceRunNotFoundError) {\n throw new ClientError('Run not found', 'not-found', {status: 404});\n }\n if (error instanceof RunNotTerminalError) {\n throw new ClientError('Run is not terminal', 'run-not-terminal', {status: 409});\n }\n if (error instanceof NoFailedJobsError) {\n throw new ClientError('Run has no failed jobs', 'no-failed-jobs', {status: 409});\n }\n throw error;\n },\n handler: async (request) => {\n const {id} = request.params;\n const sourceRun = await requireAccessibleRun({request, id, projects});\n\n const actor = requireUserContext(request);\n const run = await createRerunWorkflowRun({\n workflowRunId: sourceRun.id,\n mode: request.body.mode,\n actorUserId: actor.userId,\n });\n\n return toRunDto(run, run.currentAttempt);\n },\n });\n}\n"],"names":["requireUserContext","rerunWorkflowRunBodySchema","workflowRunResponseSchema","ClientError","defineRoute","z","NoFailedJobsError","RunNotTerminalError","SourceRunNotFoundError","createRerunWorkflowRun","toRunDto","requireAccessibleRun","rerunRunRoute","projects","method","path","description","schema","params","object","id","string","uuid","body","response","errorHandler","error","status","handler","request","sourceRun","actor","run","workflowRunId","mode","actorUserId","userId","currentAttempt"],"mappings":"AAAA,SAAQA,kBAAkB,QAAO,4BAA4B;AAE7D,SAAQC,0BAA0B,EAAEC,yBAAyB,QAAO,6BAA6B;AACjG,SAAQC,WAAW,EAAEC,WAAW,QAAO,wBAAwB;AAC/D,SAAQC,CAAC,QAAO,MAAM;AACtB,SAAQC,iBAAiB,EAAEC,mBAAmB,EAAEC,sBAAsB,QAAO,kBAAkB;AAC/F,SAAQC,sBAAsB,QAAO,eAAe;AACpD,SAAQC,QAAQ,QAAO,6BAA6B;AACpD,SAAQC,oBAAoB,QAAO,8BAA8B;AAEjE,OAAO,SAASC,cAAcC,QAA8B;IAC1D,OAAOT,YAAY;QACjBU,QAAQ;QACRC,MAAM;QACNC,aAAa;QACbC,QAAQ;YACNC,QAAQb,EAAEc,MAAM,CAAC;gBACfC,IAAIf,EAAEgB,MAAM,GAAGC,IAAI;YACrB;YACAC,MAAMtB;YACNuB,UAAU;gBACR,KAAKtB;YACP;QACF;QACAuB,cAAc,CAACC;YACb,IAAIA,iBAAiBlB,wBAAwB;gBAC3C,MAAM,IAAIL,YAAY,iBAAiB,aAAa;oBAACwB,QAAQ;gBAAG;YAClE;YACA,IAAID,iBAAiBnB,qBAAqB;gBACxC,MAAM,IAAIJ,YAAY,uBAAuB,oBAAoB;oBAACwB,QAAQ;gBAAG;YAC/E;YACA,IAAID,iBAAiBpB,mBAAmB;gBACtC,MAAM,IAAIH,YAAY,0BAA0B,kBAAkB;oBAACwB,QAAQ;gBAAG;YAChF;YACA,MAAMD;QACR;QACAE,SAAS,OAAOC;YACd,MAAM,EAACT,EAAE,EAAC,GAAGS,QAAQX,MAAM;YAC3B,MAAMY,YAAY,MAAMnB,qBAAqB;gBAACkB;gBAAST;gBAAIP;YAAQ;YAEnE,MAAMkB,QAAQ/B,mBAAmB6B;YACjC,MAAMG,MAAM,MAAMvB,uBAAuB;gBACvCwB,eAAeH,UAAUV,EAAE;gBAC3Bc,MAAML,QAAQN,IAAI,CAACW,IAAI;gBACvBC,aAAaJ,MAAMK,MAAM;YAC3B;YAEA,OAAO1B,SAASsB,KAAKA,IAAIK,cAAc;QACzC;IACF;AACF"}
1
+ {"version":3,"sources":["../../../src/presentation/routes/rerun-run.ts"],"sourcesContent":["import {requireUserContext} from '@shipfox/api-auth-context';\nimport type {ProjectsModuleClient} from '@shipfox/api-projects-dto/inter-module';\nimport {rerunWorkflowRunBodySchema, workflowRunResponseSchema} from '@shipfox/api-workflows-dto';\nimport type {WorkspacesInterModuleClient} from '@shipfox/api-workspaces-dto/inter-module';\nimport {ClientError, defineRoute} from '@shipfox/node-fastify';\nimport {z} from 'zod';\nimport {\n NoFailedJobsError,\n RunNotTerminalError,\n SourceRunNotFoundError,\n WorkspaceDeletedError,\n WorkspaceNotFoundError,\n WorkspaceSuspendedError,\n} from '#core/errors.js';\nimport {assertWorkspaceAdmitsNewJobs} from '#core/workspace-admission.js';\nimport {createRerunWorkflowRun} from '#db/index.js';\nimport {toRunDto} from '#presentation/dto/index.js';\nimport {requireAccessibleRun} from './require-accessible-run.js';\n\nexport function rerunRunRoute(\n projects: ProjectsModuleClient,\n workspaces: WorkspacesInterModuleClient,\n) {\n return defineRoute({\n method: 'POST',\n path: '/:id/rerun',\n description: 'Re-run a terminal workflow run',\n schema: {\n params: z.object({\n id: z.string().uuid(),\n }),\n body: rerunWorkflowRunBodySchema,\n response: {\n 200: workflowRunResponseSchema,\n },\n },\n errorHandler: (error) => {\n if (error instanceof SourceRunNotFoundError) {\n throw new ClientError('Run not found', 'not-found', {status: 404});\n }\n if (error instanceof RunNotTerminalError) {\n throw new ClientError('Run is not terminal', 'run-not-terminal', {status: 409});\n }\n if (error instanceof NoFailedJobsError) {\n throw new ClientError('Run has no failed jobs', 'no-failed-jobs', {status: 409});\n }\n if (error instanceof WorkspaceSuspendedError) {\n throw new ClientError('Workspace is suspended', 'workspace-suspended', {\n status: 409,\n cause: error,\n });\n }\n if (error instanceof WorkspaceDeletedError) {\n throw new ClientError('Workspace is deleted', 'workspace-deleted', {\n status: 404,\n cause: error,\n });\n }\n if (error instanceof WorkspaceNotFoundError) {\n throw new ClientError('Workspace not found', 'workspace-not-found', {\n status: 404,\n cause: error,\n });\n }\n throw error;\n },\n handler: async (request) => {\n const {id} = request.params;\n const sourceRun = await requireAccessibleRun({request, id, projects});\n\n await assertWorkspaceAdmitsNewJobs(workspaces, sourceRun.workspaceId);\n\n const actor = requireUserContext(request);\n const run = await createRerunWorkflowRun({\n workflowRunId: sourceRun.id,\n mode: request.body.mode,\n actorUserId: actor.userId,\n });\n\n return toRunDto(run, run.currentAttempt);\n },\n });\n}\n"],"names":["requireUserContext","rerunWorkflowRunBodySchema","workflowRunResponseSchema","ClientError","defineRoute","z","NoFailedJobsError","RunNotTerminalError","SourceRunNotFoundError","WorkspaceDeletedError","WorkspaceNotFoundError","WorkspaceSuspendedError","assertWorkspaceAdmitsNewJobs","createRerunWorkflowRun","toRunDto","requireAccessibleRun","rerunRunRoute","projects","workspaces","method","path","description","schema","params","object","id","string","uuid","body","response","errorHandler","error","status","cause","handler","request","sourceRun","workspaceId","actor","run","workflowRunId","mode","actorUserId","userId","currentAttempt"],"mappings":"AAAA,SAAQA,kBAAkB,QAAO,4BAA4B;AAE7D,SAAQC,0BAA0B,EAAEC,yBAAyB,QAAO,6BAA6B;AAEjG,SAAQC,WAAW,EAAEC,WAAW,QAAO,wBAAwB;AAC/D,SAAQC,CAAC,QAAO,MAAM;AACtB,SACEC,iBAAiB,EACjBC,mBAAmB,EACnBC,sBAAsB,EACtBC,qBAAqB,EACrBC,sBAAsB,EACtBC,uBAAuB,QAClB,kBAAkB;AACzB,SAAQC,4BAA4B,QAAO,+BAA+B;AAC1E,SAAQC,sBAAsB,QAAO,eAAe;AACpD,SAAQC,QAAQ,QAAO,6BAA6B;AACpD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