@shipfox/api-definitions 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 +215 -0
- package/LICENSE +21 -0
- package/dist/config.d.ts +10 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +35 -0
- package/dist/config.js.map +1 -0
- package/dist/core/entities/index.d.ts +5 -0
- package/dist/core/entities/index.d.ts.map +1 -0
- package/dist/core/entities/index.js +6 -0
- package/dist/core/entities/index.js.map +1 -0
- package/dist/core/entities/integration-context.d.ts +11 -0
- package/dist/core/entities/integration-context.d.ts.map +1 -0
- package/dist/core/entities/integration-context.js +3 -0
- package/dist/core/entities/integration-context.js.map +1 -0
- package/dist/core/entities/sync-state.d.ts +19 -0
- package/dist/core/entities/sync-state.d.ts.map +1 -0
- package/dist/core/entities/sync-state.js +20 -0
- package/dist/core/entities/sync-state.js.map +1 -0
- package/dist/core/entities/workflow-definition.d.ts +35 -0
- package/dist/core/entities/workflow-definition.d.ts.map +1 -0
- package/dist/core/entities/workflow-definition.js +3 -0
- package/dist/core/entities/workflow-definition.js.map +1 -0
- package/dist/core/entities/workflow-model.d.ts +138 -0
- package/dist/core/entities/workflow-model.d.ts.map +1 -0
- package/dist/core/entities/workflow-model.js +3 -0
- package/dist/core/entities/workflow-model.js.map +1 -0
- package/dist/core/errors.d.ts +10 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +14 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/has-agent-step-integrations.d.ts +3 -0
- package/dist/core/has-agent-step-integrations.d.ts.map +1 -0
- package/dist/core/has-agent-step-integrations.js +5 -0
- package/dist/core/has-agent-step-integrations.js.map +1 -0
- package/dist/core/index.d.ts +9 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +9 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/parse-definition.d.ts +9 -0
- package/dist/core/parse-definition.d.ts.map +1 -0
- package/dist/core/parse-definition.js +17 -0
- package/dist/core/parse-definition.js.map +1 -0
- package/dist/core/sync-definitions.d.ts +44 -0
- package/dist/core/sync-definitions.d.ts.map +1 -0
- package/dist/core/sync-definitions.js +140 -0
- package/dist/core/sync-definitions.js.map +1 -0
- package/dist/core/validate-definition.d.ts +20 -0
- package/dist/core/validate-definition.d.ts.map +1 -0
- package/dist/core/validate-definition.js +61 -0
- package/dist/core/validate-definition.js.map +1 -0
- package/dist/core/workflow-model/constants.d.ts +2 -0
- package/dist/core/workflow-model/constants.d.ts.map +1 -0
- package/dist/core/workflow-model/constants.js +3 -0
- package/dist/core/workflow-model/constants.js.map +1 -0
- package/dist/core/workflow-model/cron-trigger.d.ts +16 -0
- package/dist/core/workflow-model/cron-trigger.d.ts.map +1 -0
- package/dist/core/workflow-model/cron-trigger.js +85 -0
- package/dist/core/workflow-model/cron-trigger.js.map +1 -0
- package/dist/core/workflow-model/index.d.ts +4 -0
- package/dist/core/workflow-model/index.d.ts.map +1 -0
- package/dist/core/workflow-model/index.js +5 -0
- package/dist/core/workflow-model/index.js.map +1 -0
- package/dist/core/workflow-model/invalid-workflow-model-error.d.ts +15 -0
- package/dist/core/workflow-model/invalid-workflow-model-error.d.ts.map +1 -0
- package/dist/core/workflow-model/invalid-workflow-model-error.js +9 -0
- package/dist/core/workflow-model/invalid-workflow-model-error.js.map +1 -0
- package/dist/core/workflow-model/map-job-ids.d.ts +4 -0
- package/dist/core/workflow-model/map-job-ids.d.ts.map +1 -0
- package/dist/core/workflow-model/map-job-ids.js +33 -0
- package/dist/core/workflow-model/map-job-ids.js.map +1 -0
- package/dist/core/workflow-model/normalize-agent-integrations.d.ts +12 -0
- package/dist/core/workflow-model/normalize-agent-integrations.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-agent-integrations.js +157 -0
- package/dist/core/workflow-model/normalize-agent-integrations.js.map +1 -0
- package/dist/core/workflow-model/normalize-dependencies.d.ts +6 -0
- package/dist/core/workflow-model/normalize-dependencies.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-dependencies.js +119 -0
- package/dist/core/workflow-model/normalize-dependencies.js.map +1 -0
- package/dist/core/workflow-model/normalize-env.d.ts +17 -0
- package/dist/core/workflow-model/normalize-env.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-env.js +40 -0
- package/dist/core/workflow-model/normalize-env.js.map +1 -0
- package/dist/core/workflow-model/normalize-if-condition.d.ts +14 -0
- package/dist/core/workflow-model/normalize-if-condition.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-if-condition.js +75 -0
- package/dist/core/workflow-model/normalize-if-condition.js.map +1 -0
- package/dist/core/workflow-model/normalize-job-checkout.d.ts +5 -0
- package/dist/core/workflow-model/normalize-job-checkout.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-job-checkout.js +16 -0
- package/dist/core/workflow-model/normalize-job-checkout.js.map +1 -0
- package/dist/core/workflow-model/normalize-job-listening.d.ts +10 -0
- package/dist/core/workflow-model/normalize-job-listening.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-job-listening.js +125 -0
- package/dist/core/workflow-model/normalize-job-listening.js.map +1 -0
- package/dist/core/workflow-model/normalize-job-success.d.ts +11 -0
- package/dist/core/workflow-model/normalize-job-success.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-job-success.js +23 -0
- package/dist/core/workflow-model/normalize-job-success.js.map +1 -0
- package/dist/core/workflow-model/normalize-jobs.d.ts +12 -0
- package/dist/core/workflow-model/normalize-jobs.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-jobs.js +935 -0
- package/dist/core/workflow-model/normalize-jobs.js.map +1 -0
- package/dist/core/workflow-model/normalize-needs.d.ts +2 -0
- package/dist/core/workflow-model/normalize-needs.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-needs.js +16 -0
- package/dist/core/workflow-model/normalize-needs.js.map +1 -0
- package/dist/core/workflow-model/normalize-step-gate.d.ts +15 -0
- package/dist/core/workflow-model/normalize-step-gate.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-step-gate.js +89 -0
- package/dist/core/workflow-model/normalize-step-gate.js.map +1 -0
- package/dist/core/workflow-model/normalize-step-outputs.d.ts +10 -0
- package/dist/core/workflow-model/normalize-step-outputs.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-step-outputs.js +32 -0
- package/dist/core/workflow-model/normalize-step-outputs.js.map +1 -0
- package/dist/core/workflow-model/normalize-triggers.d.ts +11 -0
- package/dist/core/workflow-model/normalize-triggers.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-triggers.js +128 -0
- package/dist/core/workflow-model/normalize-triggers.js.map +1 -0
- package/dist/core/workflow-model/normalize-workflow-document.d.ts +11 -0
- package/dist/core/workflow-model/normalize-workflow-document.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-workflow-document.js +43 -0
- package/dist/core/workflow-model/normalize-workflow-document.js.map +1 -0
- package/dist/core/workflow-model/parse-duration-ms.d.ts +11 -0
- package/dist/core/workflow-model/parse-duration-ms.d.ts.map +1 -0
- package/dist/core/workflow-model/parse-duration-ms.js +47 -0
- package/dist/core/workflow-model/parse-duration-ms.js.map +1 -0
- package/dist/core/workflow-model/parse-interpolation-field.d.ts +14 -0
- package/dist/core/workflow-model/parse-interpolation-field.d.ts.map +1 -0
- package/dist/core/workflow-model/parse-interpolation-field.js +377 -0
- package/dist/core/workflow-model/parse-interpolation-field.js.map +1 -0
- package/dist/core/workflow-model/stable-id.d.ts +2 -0
- package/dist/core/workflow-model/stable-id.d.ts.map +1 -0
- package/dist/core/workflow-model/stable-id.js +8 -0
- package/dist/core/workflow-model/stable-id.js.map +1 -0
- package/dist/core/workflow-model/validate-job-references.d.ts +10 -0
- package/dist/core/workflow-model/validate-job-references.d.ts.map +1 -0
- package/dist/core/workflow-model/validate-job-references.js +42 -0
- package/dist/core/workflow-model/validate-job-references.js.map +1 -0
- package/dist/core/workflow-model/validate-predicate-expression.d.ts +14 -0
- package/dist/core/workflow-model/validate-predicate-expression.d.ts.map +1 -0
- package/dist/core/workflow-model/validate-predicate-expression.js +273 -0
- package/dist/core/workflow-model/validate-predicate-expression.js.map +1 -0
- package/dist/core/workflow-model/validation-issue.d.ts +8 -0
- package/dist/core/workflow-model/validation-issue.d.ts.map +1 -0
- package/dist/core/workflow-model/validation-issue.js +17 -0
- package/dist/core/workflow-model/validation-issue.js.map +1 -0
- package/dist/core/workflow-model/workflow-field-label.d.ts +3 -0
- package/dist/core/workflow-model/workflow-field-label.d.ts.map +1 -0
- package/dist/core/workflow-model/workflow-field-label.js +47 -0
- package/dist/core/workflow-model/workflow-field-label.js.map +1 -0
- package/dist/core/workflow-yaml/index.d.ts +3 -0
- package/dist/core/workflow-yaml/index.d.ts.map +1 -0
- package/dist/core/workflow-yaml/index.js +4 -0
- package/dist/core/workflow-yaml/index.js.map +1 -0
- package/dist/core/workflow-yaml/invalid-workflow-yaml-error.d.ts +16 -0
- package/dist/core/workflow-yaml/invalid-workflow-yaml-error.d.ts.map +1 -0
- package/dist/core/workflow-yaml/invalid-workflow-yaml-error.js +12 -0
- package/dist/core/workflow-yaml/invalid-workflow-yaml-error.js.map +1 -0
- package/dist/core/workflow-yaml/parse-workflow-yaml.d.ts +9 -0
- package/dist/core/workflow-yaml/parse-workflow-yaml.d.ts.map +1 -0
- package/dist/core/workflow-yaml/parse-workflow-yaml.js +52 -0
- package/dist/core/workflow-yaml/parse-workflow-yaml.js.map +1 -0
- package/dist/core/workflow-yaml/source-locations.d.ts +3 -0
- package/dist/core/workflow-yaml/source-locations.d.ts.map +1 -0
- package/dist/core/workflow-yaml/source-locations.js +48 -0
- package/dist/core/workflow-yaml/source-locations.js.map +1 -0
- package/dist/db/db.d.ts +1277 -0
- package/dist/db/db.d.ts.map +1 -0
- package/dist/db/db.js +22 -0
- package/dist/db/db.js.map +1 -0
- package/dist/db/definition-triggers.d.ts +4 -0
- package/dist/db/definition-triggers.d.ts.map +1 -0
- package/dist/db/definition-triggers.js +17 -0
- package/dist/db/definition-triggers.js.map +1 -0
- package/dist/db/definitions.d.ts +63 -0
- package/dist/db/definitions.d.ts.map +1 -0
- package/dist/db/definitions.js +208 -0
- package/dist/db/definitions.js.map +1 -0
- package/dist/db/index.d.ts +8 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +10 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/schema/common.d.ts +2 -0
- package/dist/db/schema/common.d.ts.map +1 -0
- package/dist/db/schema/common.js +4 -0
- package/dist/db/schema/common.js.map +1 -0
- package/dist/db/schema/definitions.d.ts +237 -0
- package/dist/db/schema/definitions.d.ts.map +1 -0
- package/dist/db/schema/definitions.js +63 -0
- package/dist/db/schema/definitions.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/sync-states.d.ts +218 -0
- package/dist/db/schema/sync-states.d.ts.map +1 -0
- package/dist/db/schema/sync-states.js +68 -0
- package/dist/db/schema/sync-states.js.map +1 -0
- package/dist/db/sync-states.d.ts +21 -0
- package/dist/db/sync-states.d.ts.map +1 -0
- package/dist/db/sync-states.js +47 -0
- package/dist/db/sync-states.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +63 -0
- package/dist/index.js.map +1 -0
- package/dist/presentation/dto/definition.d.ts +6 -0
- package/dist/presentation/dto/definition.d.ts.map +1 -0
- package/dist/presentation/dto/definition.js +35 -0
- package/dist/presentation/dto/definition.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/index.d.ts +2 -0
- package/dist/presentation/index.d.ts.map +1 -0
- package/dist/presentation/index.js +3 -0
- package/dist/presentation/index.js.map +1 -0
- package/dist/presentation/routes/create-definition.d.ts +9 -0
- package/dist/presentation/routes/create-definition.d.ts.map +1 -0
- package/dist/presentation/routes/create-definition.js +76 -0
- package/dist/presentation/routes/create-definition.js.map +1 -0
- package/dist/presentation/routes/get-definition.d.ts +2 -0
- package/dist/presentation/routes/get-definition.d.ts.map +1 -0
- package/dist/presentation/routes/get-definition.js +43 -0
- package/dist/presentation/routes/get-definition.js.map +1 -0
- package/dist/presentation/routes/index.d.ts +7 -0
- package/dist/presentation/routes/index.d.ts.map +1 -0
- package/dist/presentation/routes/index.js +22 -0
- package/dist/presentation/routes/index.js.map +1 -0
- package/dist/presentation/routes/list-definitions.d.ts +2 -0
- package/dist/presentation/routes/list-definitions.d.ts.map +1 -0
- package/dist/presentation/routes/list-definitions.js +56 -0
- package/dist/presentation/routes/list-definitions.js.map +1 -0
- package/dist/presentation/routes/validate-definition.d.ts +2 -0
- package/dist/presentation/routes/validate-definition.d.ts.map +1 -0
- package/dist/presentation/routes/validate-definition.js +43 -0
- package/dist/presentation/routes/validate-definition.js.map +1 -0
- package/dist/presentation/subscribers/index.d.ts +3 -0
- package/dist/presentation/subscribers/index.d.ts.map +1 -0
- package/dist/presentation/subscribers/index.js +4 -0
- package/dist/presentation/subscribers/index.js.map +1 -0
- package/dist/presentation/subscribers/on-project-source-bound.d.ts +3 -0
- package/dist/presentation/subscribers/on-project-source-bound.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-project-source-bound.js +11 -0
- package/dist/presentation/subscribers/on-project-source-bound.js.map +1 -0
- package/dist/presentation/subscribers/on-project-source-commit-observed.d.ts +3 -0
- package/dist/presentation/subscribers/on-project-source-commit-observed.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-project-source-commit-observed.js +13 -0
- package/dist/presentation/subscribers/on-project-source-commit-observed.js.map +1 -0
- package/dist/presentation/subscribers/start-definition-sync.d.ts +10 -0
- package/dist/presentation/subscribers/start-definition-sync.d.ts.map +1 -0
- package/dist/presentation/subscribers/start-definition-sync.js +26 -0
- package/dist/presentation/subscribers/start-definition-sync.js.map +1 -0
- package/dist/temporal/activities/index.d.ts +3 -0
- package/dist/temporal/activities/index.d.ts.map +1 -0
- package/dist/temporal/activities/index.js +3 -0
- package/dist/temporal/activities/index.js.map +1 -0
- package/dist/temporal/activities/sync-activities.d.ts +47 -0
- package/dist/temporal/activities/sync-activities.d.ts.map +1 -0
- package/dist/temporal/activities/sync-activities.js +128 -0
- package/dist/temporal/activities/sync-activities.js.map +1 -0
- package/dist/temporal/constants.d.ts +3 -0
- package/dist/temporal/constants.d.ts.map +1 -0
- package/dist/temporal/constants.js +4 -0
- package/dist/temporal/constants.js.map +1 -0
- package/dist/temporal/index.d.ts +3 -0
- package/dist/temporal/index.d.ts.map +1 -0
- package/dist/temporal/index.js +4 -0
- package/dist/temporal/index.js.map +1 -0
- package/dist/temporal/workflows/definition-sync.d.ts +20 -0
- package/dist/temporal/workflows/definition-sync.d.ts.map +1 -0
- package/dist/temporal/workflows/definition-sync.js +95 -0
- package/dist/temporal/workflows/definition-sync.js.map +1 -0
- package/dist/temporal/workflows/index.d.ts +2 -0
- package/dist/temporal/workflows/index.d.ts.map +1 -0
- package/dist/temporal/workflows/index.js +3 -0
- package/dist/temporal/workflows/index.js.map +1 -0
- package/dist/tsconfig.test.tsbuildinfo +1 -0
- package/drizzle/0000_initial.sql +64 -0
- package/drizzle/0001_definition_list_pagination.sql +1 -0
- package/drizzle/meta/0000_snapshot.json +527 -0
- package/drizzle/meta/_journal.json +20 -0
- package/drizzle.config.ts +11 -0
- package/package.json +89 -0
- package/src/config.test.ts +23 -0
- package/src/config.ts +50 -0
- package/src/core/entities/index.ts +4 -0
- package/src/core/entities/integration-context.ts +21 -0
- package/src/core/entities/sync-state.ts +40 -0
- package/src/core/entities/workflow-definition.ts +38 -0
- package/src/core/entities/workflow-model.ts +162 -0
- package/src/core/errors.ts +21 -0
- package/src/core/has-agent-step-integrations.ts +7 -0
- package/src/core/index.ts +23 -0
- package/src/core/parse-definition.test.ts +200 -0
- package/src/core/parse-definition.ts +28 -0
- package/src/core/sync-definitions.test.ts +390 -0
- package/src/core/sync-definitions.ts +216 -0
- package/src/core/validate-definition.test.ts +152 -0
- package/src/core/validate-definition.ts +72 -0
- package/src/core/workflow-model/README.md +129 -0
- package/src/core/workflow-model/constants.ts +1 -0
- package/src/core/workflow-model/cron-trigger.test.ts +29 -0
- package/src/core/workflow-model/cron-trigger.ts +83 -0
- package/src/core/workflow-model/index.ts +9 -0
- package/src/core/workflow-model/invalid-workflow-model-error.ts +71 -0
- package/src/core/workflow-model/map-job-ids.ts +33 -0
- package/src/core/workflow-model/normalize-agent-integrations.ts +208 -0
- package/src/core/workflow-model/normalize-dependencies.ts +139 -0
- package/src/core/workflow-model/normalize-env.ts +48 -0
- package/src/core/workflow-model/normalize-if-condition.ts +126 -0
- package/src/core/workflow-model/normalize-job-checkout.ts +19 -0
- package/src/core/workflow-model/normalize-job-listening.ts +121 -0
- package/src/core/workflow-model/normalize-job-success.ts +28 -0
- package/src/core/workflow-model/normalize-jobs.ts +1010 -0
- package/src/core/workflow-model/normalize-needs.ts +12 -0
- package/src/core/workflow-model/normalize-step-gate.ts +90 -0
- package/src/core/workflow-model/normalize-step-outputs.ts +36 -0
- package/src/core/workflow-model/normalize-triggers.ts +130 -0
- package/src/core/workflow-model/normalize-workflow-document.test.ts +4463 -0
- package/src/core/workflow-model/normalize-workflow-document.ts +63 -0
- package/src/core/workflow-model/parse-duration-ms.ts +58 -0
- package/src/core/workflow-model/parse-interpolation-field.ts +566 -0
- package/src/core/workflow-model/stable-id.ts +12 -0
- package/src/core/workflow-model/validate-job-references.ts +54 -0
- package/src/core/workflow-model/validate-predicate-expression.test.ts +161 -0
- package/src/core/workflow-model/validate-predicate-expression.ts +406 -0
- package/src/core/workflow-model/validation-issue.ts +27 -0
- package/src/core/workflow-model/workflow-field-label.ts +50 -0
- package/src/core/workflow-yaml/README.md +77 -0
- package/src/core/workflow-yaml/index.ts +11 -0
- package/src/core/workflow-yaml/invalid-workflow-yaml-error.ts +23 -0
- package/src/core/workflow-yaml/parse-workflow-yaml.test.ts +71 -0
- package/src/core/workflow-yaml/parse-workflow-yaml.ts +74 -0
- package/src/core/workflow-yaml/source-locations.ts +62 -0
- package/src/db/db.ts +18 -0
- package/src/db/definition-triggers.test.ts +95 -0
- package/src/db/definition-triggers.ts +17 -0
- package/src/db/definitions.test.ts +1309 -0
- package/src/db/definitions.ts +357 -0
- package/src/db/index.ts +31 -0
- package/src/db/schema/common.ts +3 -0
- package/src/db/schema/definitions.test.ts +36 -0
- package/src/db/schema/definitions.ts +76 -0
- package/src/db/schema/outbox.ts +4 -0
- package/src/db/schema/sync-states.ts +79 -0
- package/src/db/sync-states.test.ts +90 -0
- package/src/db/sync-states.ts +86 -0
- package/src/index.ts +104 -0
- package/src/presentation/dto/definition.test.ts +59 -0
- package/src/presentation/dto/definition.ts +41 -0
- package/src/presentation/dto/index.ts +1 -0
- package/src/presentation/index.ts +1 -0
- package/src/presentation/routes/create-definition.test.ts +356 -0
- package/src/presentation/routes/create-definition.ts +101 -0
- package/src/presentation/routes/get-definition.test.ts +79 -0
- package/src/presentation/routes/get-definition.ts +37 -0
- package/src/presentation/routes/index.test.ts +41 -0
- package/src/presentation/routes/index.ts +28 -0
- package/src/presentation/routes/list-definitions.test.ts +195 -0
- package/src/presentation/routes/list-definitions.ts +49 -0
- package/src/presentation/routes/validate-definition.test.ts +63 -0
- package/src/presentation/routes/validate-definition.ts +46 -0
- package/src/presentation/subscribers/index.ts +2 -0
- package/src/presentation/subscribers/on-project-source-bound.test.ts +65 -0
- package/src/presentation/subscribers/on-project-source-bound.ts +11 -0
- package/src/presentation/subscribers/on-project-source-commit-observed.test.ts +56 -0
- package/src/presentation/subscribers/on-project-source-commit-observed.ts +15 -0
- package/src/presentation/subscribers/start-definition-sync.ts +38 -0
- package/src/temporal/activities/index.ts +10 -0
- package/src/temporal/activities/sync-activities.test.ts +337 -0
- package/src/temporal/activities/sync-activities.ts +206 -0
- package/src/temporal/constants.ts +2 -0
- package/src/temporal/index.ts +2 -0
- package/src/temporal/workflows/definition-sync.test.ts +59 -0
- package/src/temporal/workflows/definition-sync.ts +116 -0
- package/src/temporal/workflows/index.ts +1 -0
- package/test/env.ts +7 -0
- package/test/factories/definition.ts +66 -0
- package/test/fixtures/invalid-cycle.yml +13 -0
- package/test/fixtures/invalid-missing-name.yml +4 -0
- package/test/fixtures/invalid-yaml-syntax.yml +6 -0
- package/test/fixtures/valid-dag.yml +25 -0
- package/test/fixtures/valid-listening-job.yml +21 -0
- package/test/fixtures/valid-simple.yml +18 -0
- package/test/fixtures/workflow-yaml/invalid/invalid-yaml-syntax.yaml +6 -0
- package/test/fixtures/workflow-yaml/invalid/missing-step-run.yaml +5 -0
- package/test/fixtures/workflow-yaml/valid/simple-build.document.json +26 -0
- package/test/fixtures/workflow-yaml/valid/simple-build.yaml +14 -0
- package/test/globalSetup.ts +25 -0
- package/test/index.ts +1 -0
- package/test/setup.ts +17 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +3 -0
- package/tsconfig.test.json +8 -0
- package/vitest.config.ts +11 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createDefinitionBodySchema,
|
|
3
|
+
definitionResponseSchema,
|
|
4
|
+
definitionValidationErrorSchema,
|
|
5
|
+
} from '@shipfox/api-definitions-dto';
|
|
6
|
+
import type {
|
|
7
|
+
AgentToolSelectionCatalogs,
|
|
8
|
+
GetIntegrationConnectionByIdFn,
|
|
9
|
+
LoadWorkspaceConnectionSnapshot,
|
|
10
|
+
} from '@shipfox/api-integration-core';
|
|
11
|
+
import {ProjectNotFoundError, requireProjectAccess} from '@shipfox/api-projects';
|
|
12
|
+
import {ClientError, defineRoute} from '@shipfox/node-fastify';
|
|
13
|
+
import {z} from 'zod';
|
|
14
|
+
import {DefinitionParseError} from '#core/errors.js';
|
|
15
|
+
import {hasAgentStepIntegrations} from '#core/has-agent-step-integrations.js';
|
|
16
|
+
import {parseDefinition} from '#core/parse-definition.js';
|
|
17
|
+
import {upsertDefinition} from '#db/definitions.js';
|
|
18
|
+
import {toDefinitionDto} from '#presentation/dto/index.js';
|
|
19
|
+
|
|
20
|
+
export interface CreateDefinitionRouteOptions {
|
|
21
|
+
agentToolSelectionCatalogs?: AgentToolSelectionCatalogs | undefined;
|
|
22
|
+
loadWorkspaceConnectionSnapshot?: LoadWorkspaceConnectionSnapshot | undefined;
|
|
23
|
+
getIntegrationConnectionById?: GetIntegrationConnectionByIdFn | undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function buildCreateDefinitionRoute(options: CreateDefinitionRouteOptions = {}) {
|
|
27
|
+
return defineRoute({
|
|
28
|
+
method: 'POST',
|
|
29
|
+
path: '/',
|
|
30
|
+
description: 'Create or update a workflow definition',
|
|
31
|
+
schema: {
|
|
32
|
+
body: createDefinitionBodySchema,
|
|
33
|
+
response: {
|
|
34
|
+
200: definitionResponseSchema,
|
|
35
|
+
400: z.object({
|
|
36
|
+
code: z.string(),
|
|
37
|
+
message: z.string().optional(),
|
|
38
|
+
details: z.array(definitionValidationErrorSchema).optional(),
|
|
39
|
+
}),
|
|
40
|
+
404: z.object({code: z.string()}),
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
errorHandler: (error, _request, _reply) => {
|
|
44
|
+
if (error instanceof DefinitionParseError) {
|
|
45
|
+
throw new ClientError(error.message, 'invalid-workflow-definition', {
|
|
46
|
+
details: error.details,
|
|
47
|
+
status: 400,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
if (error instanceof ProjectNotFoundError) {
|
|
51
|
+
throw new ClientError(error.message, 'project-not-found', {status: 404});
|
|
52
|
+
}
|
|
53
|
+
throw error;
|
|
54
|
+
},
|
|
55
|
+
handler: async (request) => {
|
|
56
|
+
const {project_id: projectId, config_path, source, yaml: yamlString, sha, ref} = request.body;
|
|
57
|
+
const {project} = await requireProjectAccess({request, projectId});
|
|
58
|
+
|
|
59
|
+
const structurallyParsed = parseDefinition(yamlString);
|
|
60
|
+
const {
|
|
61
|
+
agentToolSelectionCatalogs,
|
|
62
|
+
loadWorkspaceConnectionSnapshot,
|
|
63
|
+
getIntegrationConnectionById,
|
|
64
|
+
} = options;
|
|
65
|
+
const parsed =
|
|
66
|
+
agentToolSelectionCatalogs !== undefined &&
|
|
67
|
+
loadWorkspaceConnectionSnapshot !== undefined &&
|
|
68
|
+
hasAgentStepIntegrations(structurallyParsed.document)
|
|
69
|
+
? parseDefinition(yamlString, {
|
|
70
|
+
integrationValidationContext: {
|
|
71
|
+
agentToolSelectionCatalogs,
|
|
72
|
+
workspaceConnectionSnapshot: await loadWorkspaceConnectionSnapshot(
|
|
73
|
+
project.workspaceId,
|
|
74
|
+
),
|
|
75
|
+
defaultConnectionSlug:
|
|
76
|
+
getIntegrationConnectionById === undefined
|
|
77
|
+
? undefined
|
|
78
|
+
: (await getIntegrationConnectionById(project.sourceConnectionId))?.slug,
|
|
79
|
+
},
|
|
80
|
+
})
|
|
81
|
+
: structurallyParsed;
|
|
82
|
+
|
|
83
|
+
const definition = await upsertDefinition({
|
|
84
|
+
projectId,
|
|
85
|
+
workspaceId: project.workspaceId,
|
|
86
|
+
configPath: config_path,
|
|
87
|
+
source,
|
|
88
|
+
name: parsed.document.name,
|
|
89
|
+
document: parsed.document,
|
|
90
|
+
model: parsed.model,
|
|
91
|
+
sourceSnapshot: parsed.sourceSnapshot,
|
|
92
|
+
sha,
|
|
93
|
+
ref,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
return toDefinitionDto(definition);
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export const createDefinitionRoute = buildCreateDefinitionRoute();
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import {buildUserContext, setUserContext} from '@shipfox/api-auth-context';
|
|
2
|
+
import type {FastifyInstance} from 'fastify';
|
|
3
|
+
import Fastify from 'fastify';
|
|
4
|
+
import {serializerCompiler, validatorCompiler} from 'fastify-type-provider-zod';
|
|
5
|
+
import {definitionFactory} from '#test/index.js';
|
|
6
|
+
import {getDefinitionRoute} from './get-definition.js';
|
|
7
|
+
|
|
8
|
+
const projectAccessState = vi.hoisted(() => ({workspaceId: ''}));
|
|
9
|
+
|
|
10
|
+
vi.mock('@shipfox/api-projects', () => ({
|
|
11
|
+
ProjectNotFoundError: class ProjectNotFoundError extends Error {},
|
|
12
|
+
requireProjectAccess: vi.fn(({projectId}) =>
|
|
13
|
+
Promise.resolve({
|
|
14
|
+
project: {id: projectId, workspaceId: projectAccessState.workspaceId},
|
|
15
|
+
workspaceId: projectAccessState.workspaceId,
|
|
16
|
+
}),
|
|
17
|
+
),
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
describe('GET /api/definitions/:id', () => {
|
|
21
|
+
let app: FastifyInstance;
|
|
22
|
+
let workspaceId: string;
|
|
23
|
+
|
|
24
|
+
beforeAll(async () => {
|
|
25
|
+
app = Fastify();
|
|
26
|
+
app.setValidatorCompiler(validatorCompiler);
|
|
27
|
+
app.setSerializerCompiler(serializerCompiler);
|
|
28
|
+
app.addHook('onRequest', (request, _reply, done) => {
|
|
29
|
+
setUserContext(
|
|
30
|
+
request,
|
|
31
|
+
buildUserContext({
|
|
32
|
+
userId: crypto.randomUUID(),
|
|
33
|
+
email: 'user@example.com',
|
|
34
|
+
memberships: [{workspaceId, role: 'admin'}],
|
|
35
|
+
}),
|
|
36
|
+
);
|
|
37
|
+
done();
|
|
38
|
+
});
|
|
39
|
+
app.get('/api/definitions/:id', getDefinitionRoute);
|
|
40
|
+
await app.ready();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
beforeEach(() => {
|
|
44
|
+
workspaceId = crypto.randomUUID();
|
|
45
|
+
projectAccessState.workspaceId = workspaceId;
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('returns 200 with definition when found', async () => {
|
|
49
|
+
const definition = await definitionFactory.create();
|
|
50
|
+
|
|
51
|
+
const res = await app.inject({
|
|
52
|
+
method: 'GET',
|
|
53
|
+
url: `/api/definitions/${definition.id}`,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
expect(res.statusCode).toBe(200);
|
|
57
|
+
expect(res.json().id).toBe(definition.id);
|
|
58
|
+
expect(res.json().name).toBe(definition.name);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('returns 404 when not found', async () => {
|
|
62
|
+
const res = await app.inject({
|
|
63
|
+
method: 'GET',
|
|
64
|
+
url: `/api/definitions/${crypto.randomUUID()}`,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
expect(res.statusCode).toBe(404);
|
|
68
|
+
expect(res.json().code).toBe('not-found');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('returns 400 for invalid UUID', async () => {
|
|
72
|
+
const res = await app.inject({
|
|
73
|
+
method: 'GET',
|
|
74
|
+
url: '/api/definitions/not-a-uuid',
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
expect(res.statusCode).toBe(400);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {definitionResponseSchema} from '@shipfox/api-definitions-dto';
|
|
2
|
+
import {ProjectNotFoundError, requireProjectAccess} from '@shipfox/api-projects';
|
|
3
|
+
import {ClientError, defineRoute} from '@shipfox/node-fastify';
|
|
4
|
+
import {z} from 'zod';
|
|
5
|
+
import {getDefinitionById} from '#db/definitions.js';
|
|
6
|
+
import {toDefinitionDto} from '#presentation/dto/index.js';
|
|
7
|
+
|
|
8
|
+
export const getDefinitionRoute = defineRoute({
|
|
9
|
+
method: 'GET',
|
|
10
|
+
path: '/:id',
|
|
11
|
+
description: 'Get a definition by ID',
|
|
12
|
+
schema: {
|
|
13
|
+
params: z.object({
|
|
14
|
+
id: z.string().uuid(),
|
|
15
|
+
}),
|
|
16
|
+
response: {
|
|
17
|
+
200: definitionResponseSchema,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
errorHandler: (error) => {
|
|
21
|
+
if (error instanceof ProjectNotFoundError) {
|
|
22
|
+
throw new ClientError('Definition not found', 'not-found', {status: 404});
|
|
23
|
+
}
|
|
24
|
+
throw error;
|
|
25
|
+
},
|
|
26
|
+
handler: async (request) => {
|
|
27
|
+
const {id} = request.params;
|
|
28
|
+
const definition = await getDefinitionById(id);
|
|
29
|
+
|
|
30
|
+
if (!definition) {
|
|
31
|
+
throw new ClientError('Definition not found', 'not-found', {status: 404});
|
|
32
|
+
}
|
|
33
|
+
await requireProjectAccess({request, projectId: definition.projectId});
|
|
34
|
+
|
|
35
|
+
return toDefinitionDto(definition);
|
|
36
|
+
},
|
|
37
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {AUTH_USER, buildUserContext, setUserContext} from '@shipfox/api-auth-context';
|
|
2
|
+
import {type AuthMethod, ClientError, closeApp, createApp} from '@shipfox/node-fastify';
|
|
3
|
+
import type {FastifyRequest} from 'fastify';
|
|
4
|
+
import {definitionRoutes} from './index.js';
|
|
5
|
+
|
|
6
|
+
const fakeUserAuth: AuthMethod = {
|
|
7
|
+
name: AUTH_USER,
|
|
8
|
+
authenticate: (request: FastifyRequest) => {
|
|
9
|
+
if (request.headers.authorization !== 'Bearer user') {
|
|
10
|
+
throw new ClientError('Invalid user token', 'unauthorized', {status: 401});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
setUserContext(
|
|
14
|
+
request,
|
|
15
|
+
buildUserContext({userId: 'user-1', email: 'user@example.com', memberships: []}),
|
|
16
|
+
);
|
|
17
|
+
return Promise.resolve();
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
afterEach(async () => {
|
|
22
|
+
await closeApp();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe('definition route auth', () => {
|
|
26
|
+
test('uses user auth', () => {
|
|
27
|
+
expect(definitionRoutes[0]?.auth).toBe(AUTH_USER);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('rejects API-key-only requests', async () => {
|
|
31
|
+
const app = await createApp({auth: [fakeUserAuth], routes: definitionRoutes, swagger: false});
|
|
32
|
+
const res = await app.inject({
|
|
33
|
+
method: 'GET',
|
|
34
|
+
url: `/definitions?project_id=${crypto.randomUUID()}`,
|
|
35
|
+
headers: {authorization: 'Bearer api-key'},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
expect(res.statusCode).toBe(401);
|
|
39
|
+
expect(res.json().code).toBe('unauthorized');
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {AUTH_USER} from '@shipfox/api-auth-context';
|
|
2
|
+
import type {RouteGroup} from '@shipfox/node-fastify';
|
|
3
|
+
import {
|
|
4
|
+
buildCreateDefinitionRoute,
|
|
5
|
+
type CreateDefinitionRouteOptions,
|
|
6
|
+
} from './create-definition.js';
|
|
7
|
+
import {getDefinitionRoute} from './get-definition.js';
|
|
8
|
+
import {listDefinitionsRoute} from './list-definitions.js';
|
|
9
|
+
import {validateDefinitionRoute} from './validate-definition.js';
|
|
10
|
+
|
|
11
|
+
export interface DefinitionRouteOptions extends CreateDefinitionRouteOptions {}
|
|
12
|
+
|
|
13
|
+
export function createDefinitionRoutes(options: DefinitionRouteOptions = {}): RouteGroup[] {
|
|
14
|
+
return [
|
|
15
|
+
{
|
|
16
|
+
prefix: '/definitions',
|
|
17
|
+
auth: AUTH_USER,
|
|
18
|
+
routes: [
|
|
19
|
+
buildCreateDefinitionRoute(options),
|
|
20
|
+
listDefinitionsRoute,
|
|
21
|
+
getDefinitionRoute,
|
|
22
|
+
validateDefinitionRoute,
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const definitionRoutes = createDefinitionRoutes();
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import {buildUserContext, setUserContext} from '@shipfox/api-auth-context';
|
|
2
|
+
import {encodeStringIdCursor} from '@shipfox/node-drizzle';
|
|
3
|
+
import type {FastifyInstance} from 'fastify';
|
|
4
|
+
import Fastify from 'fastify';
|
|
5
|
+
import {serializerCompiler, validatorCompiler} from 'fastify-type-provider-zod';
|
|
6
|
+
import {markDefinitionSyncState} from '#db/index.js';
|
|
7
|
+
import {definitionFactory} from '#test/index.js';
|
|
8
|
+
import {listDefinitionsRoute} from './list-definitions.js';
|
|
9
|
+
|
|
10
|
+
const projectAccessState = vi.hoisted(() => ({
|
|
11
|
+
workspaceId: '',
|
|
12
|
+
sourceConnectionId: '',
|
|
13
|
+
sourceExternalRepositoryId: '',
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
vi.mock('@shipfox/api-projects', () => ({
|
|
17
|
+
ProjectNotFoundError: class ProjectNotFoundError extends Error {},
|
|
18
|
+
requireProjectAccess: vi.fn(({projectId}) =>
|
|
19
|
+
Promise.resolve({
|
|
20
|
+
project: {
|
|
21
|
+
id: projectId,
|
|
22
|
+
workspaceId: projectAccessState.workspaceId,
|
|
23
|
+
sourceConnectionId: projectAccessState.sourceConnectionId,
|
|
24
|
+
sourceExternalRepositoryId: projectAccessState.sourceExternalRepositoryId,
|
|
25
|
+
},
|
|
26
|
+
workspaceId: projectAccessState.workspaceId,
|
|
27
|
+
}),
|
|
28
|
+
),
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
describe('GET /api/definitions', () => {
|
|
32
|
+
let app: FastifyInstance;
|
|
33
|
+
let workspaceId: string;
|
|
34
|
+
let projectId: string;
|
|
35
|
+
let sourceConnectionId: string;
|
|
36
|
+
let sourceExternalRepositoryId: string;
|
|
37
|
+
|
|
38
|
+
beforeAll(async () => {
|
|
39
|
+
app = Fastify();
|
|
40
|
+
app.setValidatorCompiler(validatorCompiler);
|
|
41
|
+
app.setSerializerCompiler(serializerCompiler);
|
|
42
|
+
app.addHook('onRequest', (request, _reply, done) => {
|
|
43
|
+
setUserContext(
|
|
44
|
+
request,
|
|
45
|
+
buildUserContext({
|
|
46
|
+
userId: crypto.randomUUID(),
|
|
47
|
+
email: 'user@example.com',
|
|
48
|
+
memberships: [{workspaceId, role: 'admin'}],
|
|
49
|
+
}),
|
|
50
|
+
);
|
|
51
|
+
done();
|
|
52
|
+
});
|
|
53
|
+
app.get('/api/definitions', listDefinitionsRoute);
|
|
54
|
+
await app.ready();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
beforeEach(() => {
|
|
58
|
+
workspaceId = crypto.randomUUID();
|
|
59
|
+
projectId = crypto.randomUUID();
|
|
60
|
+
sourceConnectionId = crypto.randomUUID();
|
|
61
|
+
sourceExternalRepositoryId = `repo:${crypto.randomUUID()}`;
|
|
62
|
+
projectAccessState.workspaceId = workspaceId;
|
|
63
|
+
projectAccessState.sourceConnectionId = sourceConnectionId;
|
|
64
|
+
projectAccessState.sourceExternalRepositoryId = sourceExternalRepositoryId;
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('returns 200 with definitions list and sync summary', async () => {
|
|
68
|
+
await definitionFactory.create({projectId, name: 'Bravo', configPath: 'b.yml'});
|
|
69
|
+
await definitionFactory.create({projectId, name: 'Alpha', configPath: 'a.yml'});
|
|
70
|
+
const startedAt = new Date('2026-05-07T01:00:00.000Z');
|
|
71
|
+
const finishedAt = new Date('2026-05-07T01:00:05.000Z');
|
|
72
|
+
await markDefinitionSyncState({
|
|
73
|
+
projectId,
|
|
74
|
+
sourceConnectionId,
|
|
75
|
+
sourceExternalRepositoryId,
|
|
76
|
+
ref: 'main',
|
|
77
|
+
status: 'succeeded',
|
|
78
|
+
startedAt,
|
|
79
|
+
finishedAt,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const res = await app.inject({
|
|
83
|
+
method: 'GET',
|
|
84
|
+
url: `/api/definitions?project_id=${projectId}`,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
expect(res.statusCode).toBe(200);
|
|
88
|
+
const body = res.json();
|
|
89
|
+
expect(body.definitions).toHaveLength(2);
|
|
90
|
+
expect(body.definitions[0].name).toBe('Alpha');
|
|
91
|
+
expect(body.definitions[1].name).toBe('Bravo');
|
|
92
|
+
expect(body.next_cursor).toBeNull();
|
|
93
|
+
expect(body.sync).toEqual({
|
|
94
|
+
ref: 'main',
|
|
95
|
+
status: 'succeeded',
|
|
96
|
+
last_sync_at: finishedAt.toISOString(),
|
|
97
|
+
started_at: startedAt.toISOString(),
|
|
98
|
+
finished_at: finishedAt.toISOString(),
|
|
99
|
+
last_error_code: null,
|
|
100
|
+
last_error_message: null,
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('returns 200 with empty array and null sync for project with no definitions', async () => {
|
|
105
|
+
const res = await app.inject({
|
|
106
|
+
method: 'GET',
|
|
107
|
+
url: `/api/definitions?project_id=${projectId}`,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
expect(res.statusCode).toBe(200);
|
|
111
|
+
expect(res.json().definitions).toEqual([]);
|
|
112
|
+
expect(res.json().sync).toBeNull();
|
|
113
|
+
expect(res.json().next_cursor).toBeNull();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('returns failed sync summary', async () => {
|
|
117
|
+
const startedAt = new Date('2026-05-07T02:00:00.000Z');
|
|
118
|
+
await markDefinitionSyncState({
|
|
119
|
+
projectId,
|
|
120
|
+
sourceConnectionId,
|
|
121
|
+
sourceExternalRepositoryId,
|
|
122
|
+
ref: 'main',
|
|
123
|
+
status: 'failed',
|
|
124
|
+
startedAt,
|
|
125
|
+
lastErrorCode: 'no-workflow-files',
|
|
126
|
+
lastErrorMessage: 'No workflow files found',
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
const res = await app.inject({
|
|
130
|
+
method: 'GET',
|
|
131
|
+
url: `/api/definitions?project_id=${projectId}`,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
expect(res.statusCode).toBe(200);
|
|
135
|
+
expect(res.json().sync).toMatchObject({
|
|
136
|
+
ref: 'main',
|
|
137
|
+
status: 'failed',
|
|
138
|
+
started_at: startedAt.toISOString(),
|
|
139
|
+
finished_at: null,
|
|
140
|
+
last_error_code: 'no-workflow-files',
|
|
141
|
+
last_error_message: 'No workflow files found',
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('invalid projectId UUID returns 400', async () => {
|
|
146
|
+
const res = await app.inject({
|
|
147
|
+
method: 'GET',
|
|
148
|
+
url: '/api/definitions?project_id=not-a-uuid',
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
expect(res.statusCode).toBe(400);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test('paginates alphabetically with name and id cursor', async () => {
|
|
155
|
+
const bravo = await definitionFactory.create({projectId, name: 'Bravo', configPath: 'b.yml'});
|
|
156
|
+
const charlie = await definitionFactory.create({
|
|
157
|
+
projectId,
|
|
158
|
+
name: 'Charlie',
|
|
159
|
+
configPath: 'c.yml',
|
|
160
|
+
});
|
|
161
|
+
await definitionFactory.create({projectId, name: 'Alpha', configPath: 'a.yml'});
|
|
162
|
+
|
|
163
|
+
const res = await app.inject({
|
|
164
|
+
method: 'GET',
|
|
165
|
+
url: `/api/definitions?project_id=${projectId}&limit=2`,
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
expect(res.statusCode).toBe(200);
|
|
169
|
+
const body = res.json();
|
|
170
|
+
expect(body.definitions.map((definition: {name: string}) => definition.name)).toEqual([
|
|
171
|
+
'Alpha',
|
|
172
|
+
'Bravo',
|
|
173
|
+
]);
|
|
174
|
+
expect(body.next_cursor).toBe(encodeStringIdCursor({value: bravo.name, id: bravo.id}));
|
|
175
|
+
|
|
176
|
+
const next = await app.inject({
|
|
177
|
+
method: 'GET',
|
|
178
|
+
url: `/api/definitions?project_id=${projectId}&limit=2&cursor=${body.next_cursor}`,
|
|
179
|
+
});
|
|
180
|
+
expect(next.statusCode).toBe(200);
|
|
181
|
+
expect(next.json().definitions.map((definition: {id: string}) => definition.id)).toEqual([
|
|
182
|
+
charlie.id,
|
|
183
|
+
]);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
test('invalid cursor returns stable client error', async () => {
|
|
187
|
+
const res = await app.inject({
|
|
188
|
+
method: 'GET',
|
|
189
|
+
url: `/api/definitions?project_id=${projectId}&cursor=not-a-cursor`,
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
expect(res.statusCode).toBe(400);
|
|
193
|
+
expect(res.json().code).toBe('invalid-cursor');
|
|
194
|
+
});
|
|
195
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
definitionListQuerySchema,
|
|
3
|
+
definitionListResponseSchema,
|
|
4
|
+
} from '@shipfox/api-definitions-dto';
|
|
5
|
+
import {ProjectNotFoundError, requireProjectAccess} from '@shipfox/api-projects';
|
|
6
|
+
import {decodeStringIdCursor, encodeStringIdCursor} from '@shipfox/node-drizzle';
|
|
7
|
+
import {ClientError, defineRoute} from '@shipfox/node-fastify';
|
|
8
|
+
import {listDefinitions} from '#db/definitions.js';
|
|
9
|
+
import {getLatestDefinitionSyncState} from '#db/sync-states.js';
|
|
10
|
+
import {toDefinitionDto, toDefinitionSyncSummaryDto} from '#presentation/dto/index.js';
|
|
11
|
+
|
|
12
|
+
export const listDefinitionsRoute = defineRoute({
|
|
13
|
+
method: 'GET',
|
|
14
|
+
path: '/',
|
|
15
|
+
description: 'List all definitions for a project',
|
|
16
|
+
schema: {
|
|
17
|
+
querystring: definitionListQuerySchema,
|
|
18
|
+
response: {
|
|
19
|
+
200: definitionListResponseSchema,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
errorHandler: (error) => {
|
|
23
|
+
if (error instanceof ProjectNotFoundError) {
|
|
24
|
+
throw new ClientError(error.message, 'project-not-found', {status: 404});
|
|
25
|
+
}
|
|
26
|
+
throw error;
|
|
27
|
+
},
|
|
28
|
+
handler: async (request) => {
|
|
29
|
+
const {project_id: projectId, limit, cursor} = request.query;
|
|
30
|
+
const decodedCursor = decodeStringIdCursor(cursor);
|
|
31
|
+
if (cursor && !decodedCursor) {
|
|
32
|
+
throw new ClientError('Invalid cursor', 'invalid-cursor', {status: 400});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const {project} = await requireProjectAccess({request, projectId});
|
|
36
|
+
const result = await listDefinitions({projectId, limit, cursor: decodedCursor});
|
|
37
|
+
const syncState = await getLatestDefinitionSyncState({
|
|
38
|
+
projectId,
|
|
39
|
+
sourceConnectionId: project.sourceConnectionId,
|
|
40
|
+
sourceExternalRepositoryId: project.sourceExternalRepositoryId,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
definitions: result.definitions.map(toDefinitionDto),
|
|
45
|
+
sync: toDefinitionSyncSummaryDto(syncState),
|
|
46
|
+
next_cursor: result.nextCursor ? encodeStringIdCursor(result.nextCursor) : null,
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type {FastifyInstance} from 'fastify';
|
|
2
|
+
import Fastify from 'fastify';
|
|
3
|
+
import {serializerCompiler, validatorCompiler} from 'fastify-type-provider-zod';
|
|
4
|
+
import {validateDefinitionRoute} from './validate-definition.js';
|
|
5
|
+
|
|
6
|
+
describe('POST /definitions/validate', () => {
|
|
7
|
+
let app: FastifyInstance;
|
|
8
|
+
|
|
9
|
+
beforeAll(async () => {
|
|
10
|
+
app = Fastify();
|
|
11
|
+
app.setValidatorCompiler(validatorCompiler);
|
|
12
|
+
app.setSerializerCompiler(serializerCompiler);
|
|
13
|
+
app.post('/definitions/validate', validateDefinitionRoute);
|
|
14
|
+
await app.ready();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test('valid YAML returns 200 with { valid: true }', async () => {
|
|
18
|
+
const res = await app.inject({
|
|
19
|
+
method: 'POST',
|
|
20
|
+
url: '/definitions/validate',
|
|
21
|
+
payload: {
|
|
22
|
+
yaml: `
|
|
23
|
+
name: Test
|
|
24
|
+
runner: ubuntu-latest
|
|
25
|
+
jobs:
|
|
26
|
+
build:
|
|
27
|
+
steps:
|
|
28
|
+
- run: echo hello
|
|
29
|
+
`,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
expect(res.statusCode).toBe(200);
|
|
34
|
+
const body = res.json();
|
|
35
|
+
expect(body.valid).toBe(true);
|
|
36
|
+
expect(body.workflow_document.name).toBe('Test');
|
|
37
|
+
expect(body.workflow_model.kind).toBe('workflow');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('invalid YAML returns 200 with { valid: false, errors }', async () => {
|
|
41
|
+
const res = await app.inject({
|
|
42
|
+
method: 'POST',
|
|
43
|
+
url: '/definitions/validate',
|
|
44
|
+
payload: {yaml: 'name: Bad\n invalid:\nindentation'},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
expect(res.statusCode).toBe(200);
|
|
48
|
+
const body = res.json();
|
|
49
|
+
expect(body.valid).toBe(false);
|
|
50
|
+
expect(body.errors).toBeDefined();
|
|
51
|
+
expect(body.errors.length).toBeGreaterThan(0);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('missing body returns 400', async () => {
|
|
55
|
+
const res = await app.inject({
|
|
56
|
+
method: 'POST',
|
|
57
|
+
url: '/definitions/validate',
|
|
58
|
+
payload: {},
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
expect(res.statusCode).toBe(400);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {definitionDtoSchema, definitionValidationErrorSchema} from '@shipfox/api-definitions-dto';
|
|
2
|
+
import {defineRoute} from '@shipfox/node-fastify';
|
|
3
|
+
import {z} from 'zod';
|
|
4
|
+
import {validateDefinition} from '#core/validate-definition.js';
|
|
5
|
+
|
|
6
|
+
const validateBodySchema = z.object({
|
|
7
|
+
yaml: z.string().min(1).max(1_000_000),
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const validationResultSchema = z.union([
|
|
11
|
+
z.object({
|
|
12
|
+
valid: z.literal(true),
|
|
13
|
+
workflow_document: definitionDtoSchema.shape.workflow_document,
|
|
14
|
+
workflow_model: definitionDtoSchema.shape.workflow_model,
|
|
15
|
+
}),
|
|
16
|
+
z.object({
|
|
17
|
+
valid: z.literal(false),
|
|
18
|
+
errors: z.array(definitionValidationErrorSchema),
|
|
19
|
+
}),
|
|
20
|
+
]);
|
|
21
|
+
|
|
22
|
+
export const validateDefinitionRoute = defineRoute({
|
|
23
|
+
method: 'POST',
|
|
24
|
+
path: '/validate',
|
|
25
|
+
description: 'Validate a workflow definition without persisting',
|
|
26
|
+
schema: {
|
|
27
|
+
body: validateBodySchema,
|
|
28
|
+
response: {
|
|
29
|
+
200: validationResultSchema,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
handler: (request) => {
|
|
33
|
+
const {yaml} = request.body;
|
|
34
|
+
const result = validateDefinition(yaml);
|
|
35
|
+
|
|
36
|
+
if (result.valid) {
|
|
37
|
+
return {
|
|
38
|
+
valid: true as const,
|
|
39
|
+
workflow_document: result.definition.document,
|
|
40
|
+
workflow_model: result.definition.model,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return result;
|
|
45
|
+
},
|
|
46
|
+
});
|