@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,28 @@
|
|
|
1
|
+
import type {HarnessToolDeploymentConfig} from '@shipfox/api-agent-dto';
|
|
2
|
+
import type {IntegrationValidationContext} from './entities/integration-context.js';
|
|
3
|
+
import type {WorkflowDefinitionPayload} from './entities/workflow-definition.js';
|
|
4
|
+
import {DefinitionParseError} from './errors.js';
|
|
5
|
+
import {validateDefinition} from './validate-definition.js';
|
|
6
|
+
|
|
7
|
+
export function parseDefinition(
|
|
8
|
+
yamlString: string,
|
|
9
|
+
options?: {
|
|
10
|
+
defaultRunnerLabels?: readonly string[];
|
|
11
|
+
harnessToolDeploymentConfig?: HarnessToolDeploymentConfig;
|
|
12
|
+
integrationValidationContext?: IntegrationValidationContext;
|
|
13
|
+
},
|
|
14
|
+
): WorkflowDefinitionPayload {
|
|
15
|
+
const result = validateDefinition(yamlString, options);
|
|
16
|
+
|
|
17
|
+
if (!result.valid) {
|
|
18
|
+
throw new DefinitionParseError(
|
|
19
|
+
result.errors[0]?.message ?? 'Invalid definition',
|
|
20
|
+
result.errors,
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
...result.definition,
|
|
26
|
+
sourceSnapshot: {content: yamlString, format: 'yaml'},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IntegrationConnectionInactiveError,
|
|
3
|
+
IntegrationConnectionNotFoundError,
|
|
4
|
+
IntegrationConnectionWorkspaceMismatchError,
|
|
5
|
+
IntegrationProviderError,
|
|
6
|
+
type IntegrationSourceControlService,
|
|
7
|
+
} from '@shipfox/api-integration-core';
|
|
8
|
+
import {LOWERCASE_SHA256_HEX_RE} from '@shipfox/regex';
|
|
9
|
+
import type {IntegrationValidationContext} from './entities/integration-context.js';
|
|
10
|
+
import {DefinitionSyncPermanentError} from './errors.js';
|
|
11
|
+
import {
|
|
12
|
+
classifySyncFailure,
|
|
13
|
+
discoverWorkflowFiles,
|
|
14
|
+
fetchAndParseWorkflows,
|
|
15
|
+
resolveSyncSource,
|
|
16
|
+
} from './sync-definitions.js';
|
|
17
|
+
|
|
18
|
+
const validYaml = `
|
|
19
|
+
name: CI
|
|
20
|
+
runner: ubuntu-latest
|
|
21
|
+
jobs:
|
|
22
|
+
build:
|
|
23
|
+
steps:
|
|
24
|
+
- run: pnpm test
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
const validIntegrationYaml = `
|
|
28
|
+
name: Agent CI
|
|
29
|
+
runner: ubuntu-latest
|
|
30
|
+
jobs:
|
|
31
|
+
build:
|
|
32
|
+
steps:
|
|
33
|
+
- prompt: Fix the issue
|
|
34
|
+
integrations:
|
|
35
|
+
- connection: github-main
|
|
36
|
+
include: [issue_read]
|
|
37
|
+
`;
|
|
38
|
+
|
|
39
|
+
const invalidIntegrationYaml = `
|
|
40
|
+
name: Agent CI
|
|
41
|
+
runner: ubuntu-latest
|
|
42
|
+
jobs:
|
|
43
|
+
build:
|
|
44
|
+
steps:
|
|
45
|
+
- prompt: Fix the issue
|
|
46
|
+
integrations:
|
|
47
|
+
- connection: github-main
|
|
48
|
+
include: [issue_read.missing]
|
|
49
|
+
`;
|
|
50
|
+
|
|
51
|
+
const integrationValidationContext = {
|
|
52
|
+
agentToolSelectionCatalogs: new Map([
|
|
53
|
+
[
|
|
54
|
+
'github',
|
|
55
|
+
{
|
|
56
|
+
selectors: [
|
|
57
|
+
{token: 'issue_read', kind: 'family', sensitivity: 'read', sensitive: false},
|
|
58
|
+
{token: 'issue_read.get', kind: 'method', sensitivity: 'read', sensitive: false},
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
]),
|
|
63
|
+
workspaceConnectionSnapshot: new Map([
|
|
64
|
+
['github-main', {id: 'connection-1', provider: 'github', capabilities: ['agent_tools']}],
|
|
65
|
+
]),
|
|
66
|
+
} satisfies IntegrationValidationContext;
|
|
67
|
+
|
|
68
|
+
function sourceControl(
|
|
69
|
+
overrides: Partial<IntegrationSourceControlService> = {},
|
|
70
|
+
): IntegrationSourceControlService {
|
|
71
|
+
return {
|
|
72
|
+
getConnection: vi.fn(),
|
|
73
|
+
listRepositories: vi.fn(),
|
|
74
|
+
resolveRepository: vi.fn(() =>
|
|
75
|
+
Promise.resolve({
|
|
76
|
+
connection: {
|
|
77
|
+
id: 'connection-1',
|
|
78
|
+
workspaceId: 'workspace-1',
|
|
79
|
+
provider: 'gitea',
|
|
80
|
+
externalAccountId: 'gitea-owner',
|
|
81
|
+
slug: 'gitea_owner',
|
|
82
|
+
displayName: 'Gitea',
|
|
83
|
+
lifecycleStatus: 'active' as const,
|
|
84
|
+
createdAt: new Date(),
|
|
85
|
+
updatedAt: new Date(),
|
|
86
|
+
},
|
|
87
|
+
repository: {
|
|
88
|
+
externalRepositoryId: 'gitea:gitea-owner/platform',
|
|
89
|
+
owner: 'gitea-owner',
|
|
90
|
+
name: 'platform',
|
|
91
|
+
fullName: 'gitea-owner/platform',
|
|
92
|
+
defaultBranch: 'main',
|
|
93
|
+
visibility: 'private' as const,
|
|
94
|
+
cloneUrl: 'https://gitea.local/gitea-owner/platform.git',
|
|
95
|
+
htmlUrl: 'https://gitea.local/gitea-owner/platform',
|
|
96
|
+
},
|
|
97
|
+
}),
|
|
98
|
+
),
|
|
99
|
+
listFiles: vi.fn(() =>
|
|
100
|
+
Promise.resolve({
|
|
101
|
+
files: [{path: '.shipfox/workflows/ci.yml', type: 'file' as const, size: validYaml.length}],
|
|
102
|
+
nextCursor: null,
|
|
103
|
+
}),
|
|
104
|
+
),
|
|
105
|
+
fetchFile: vi.fn(() =>
|
|
106
|
+
Promise.resolve({path: '.shipfox/workflows/ci.yml', ref: 'main', content: validYaml}),
|
|
107
|
+
),
|
|
108
|
+
createCheckoutSpec: vi.fn(),
|
|
109
|
+
...overrides,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const baseContext = {
|
|
114
|
+
workspaceId: 'workspace-1',
|
|
115
|
+
sourceConnectionId: 'connection-1',
|
|
116
|
+
sourceExternalRepositoryId: 'gitea:gitea-owner/platform',
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
describe('resolveSyncSource', () => {
|
|
120
|
+
it('returns the repository default branch as ref', async () => {
|
|
121
|
+
const result = await resolveSyncSource({...baseContext, sourceControl: sourceControl()});
|
|
122
|
+
|
|
123
|
+
expect(result).toEqual({ref: 'main'});
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe('discoverWorkflowFiles', () => {
|
|
128
|
+
it('returns yaml/yml workflow paths', async () => {
|
|
129
|
+
const result = await discoverWorkflowFiles({
|
|
130
|
+
...baseContext,
|
|
131
|
+
ref: 'main',
|
|
132
|
+
sourceControl: sourceControl({
|
|
133
|
+
listFiles: vi.fn(() =>
|
|
134
|
+
Promise.resolve({
|
|
135
|
+
files: [
|
|
136
|
+
{path: '.shipfox/workflows/ci.yml', type: 'file' as const, size: 64},
|
|
137
|
+
{path: '.shipfox/workflows/deploy.yaml', type: 'file' as const, size: 64},
|
|
138
|
+
{path: '.shipfox/workflows/README.md', type: 'file' as const, size: 64},
|
|
139
|
+
],
|
|
140
|
+
nextCursor: null,
|
|
141
|
+
}),
|
|
142
|
+
),
|
|
143
|
+
}),
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
expect(result.paths).toEqual(['.shipfox/workflows/ci.yml', '.shipfox/workflows/deploy.yaml']);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('throws no-workflow-files when nothing matches the yaml extensions', async () => {
|
|
150
|
+
const result = discoverWorkflowFiles({
|
|
151
|
+
...baseContext,
|
|
152
|
+
ref: 'main',
|
|
153
|
+
sourceControl: sourceControl({
|
|
154
|
+
listFiles: vi.fn(() =>
|
|
155
|
+
Promise.resolve({
|
|
156
|
+
files: [{path: '.shipfox/workflows/README.md', type: 'file' as const, size: 1}],
|
|
157
|
+
nextCursor: null,
|
|
158
|
+
}),
|
|
159
|
+
),
|
|
160
|
+
}),
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
await expect(result).rejects.toMatchObject({code: 'no-workflow-files'});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('throws too-many-files when the listing reports more pages', async () => {
|
|
167
|
+
const result = discoverWorkflowFiles({
|
|
168
|
+
...baseContext,
|
|
169
|
+
ref: 'main',
|
|
170
|
+
sourceControl: sourceControl({
|
|
171
|
+
listFiles: vi.fn(() =>
|
|
172
|
+
Promise.resolve({
|
|
173
|
+
files: [{path: '.shipfox/workflows/ci.yml', type: 'file' as const, size: 1}],
|
|
174
|
+
nextCursor: '1',
|
|
175
|
+
}),
|
|
176
|
+
),
|
|
177
|
+
}),
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
await expect(result).rejects.toMatchObject({code: 'too-many-files'});
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe('fetchAndParseWorkflows', () => {
|
|
185
|
+
it('fetches and parses each provided path', async () => {
|
|
186
|
+
const result = await fetchAndParseWorkflows({
|
|
187
|
+
...baseContext,
|
|
188
|
+
ref: 'main',
|
|
189
|
+
paths: ['.shipfox/workflows/ci.yml'],
|
|
190
|
+
sourceControl: sourceControl(),
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
expect(result).toHaveLength(1);
|
|
194
|
+
expect(result[0]?.name).toBe('CI');
|
|
195
|
+
expect(result[0]?.path).toBe('.shipfox/workflows/ci.yml');
|
|
196
|
+
expect(result[0]?.contentHash).toMatch(LOWERCASE_SHA256_HEX_RE);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it('produces stable content hashes for identical content', async () => {
|
|
200
|
+
const sourceControlA = sourceControl();
|
|
201
|
+
const sourceControlB = sourceControl();
|
|
202
|
+
|
|
203
|
+
const a = await fetchAndParseWorkflows({
|
|
204
|
+
...baseContext,
|
|
205
|
+
ref: 'main',
|
|
206
|
+
paths: ['.shipfox/workflows/ci.yml'],
|
|
207
|
+
sourceControl: sourceControlA,
|
|
208
|
+
});
|
|
209
|
+
const b = await fetchAndParseWorkflows({
|
|
210
|
+
...baseContext,
|
|
211
|
+
ref: 'main',
|
|
212
|
+
paths: ['.shipfox/workflows/ci.yml'],
|
|
213
|
+
sourceControl: sourceControlB,
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
expect(a[0]?.contentHash).toBe(b[0]?.contentHash);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('rejects oversized contents as content-too-large', async () => {
|
|
220
|
+
const huge = 'x'.repeat(1_000_001);
|
|
221
|
+
const result = fetchAndParseWorkflows({
|
|
222
|
+
...baseContext,
|
|
223
|
+
ref: 'main',
|
|
224
|
+
paths: ['.shipfox/workflows/big.yml'],
|
|
225
|
+
sourceControl: sourceControl({
|
|
226
|
+
fetchFile: vi.fn(() =>
|
|
227
|
+
Promise.resolve({path: '.shipfox/workflows/big.yml', ref: 'main', content: huge}),
|
|
228
|
+
),
|
|
229
|
+
}),
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
await expect(result).rejects.toBeInstanceOf(DefinitionSyncPermanentError);
|
|
233
|
+
await expect(result).rejects.toMatchObject({code: 'content-too-large'});
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it('rejects invalid YAML as invalid-definition', async () => {
|
|
237
|
+
const result = fetchAndParseWorkflows({
|
|
238
|
+
...baseContext,
|
|
239
|
+
ref: 'main',
|
|
240
|
+
paths: ['.shipfox/workflows/bad.yml'],
|
|
241
|
+
sourceControl: sourceControl({
|
|
242
|
+
fetchFile: vi.fn(() =>
|
|
243
|
+
Promise.resolve({
|
|
244
|
+
path: '.shipfox/workflows/bad.yml',
|
|
245
|
+
ref: 'main',
|
|
246
|
+
content: 'name: Bad\n broken:\nindent',
|
|
247
|
+
}),
|
|
248
|
+
),
|
|
249
|
+
}),
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
await expect(result).rejects.toMatchObject({code: 'invalid-definition'});
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('emits onProgress for every path', async () => {
|
|
256
|
+
const onProgress = vi.fn();
|
|
257
|
+
await fetchAndParseWorkflows({
|
|
258
|
+
...baseContext,
|
|
259
|
+
ref: 'main',
|
|
260
|
+
paths: ['.shipfox/workflows/ci.yml'],
|
|
261
|
+
sourceControl: sourceControl(),
|
|
262
|
+
onProgress,
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
expect(onProgress).toHaveBeenCalledWith('.shipfox/workflows/ci.yml');
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it('does not load integration validation context when no workflow uses integrations', async () => {
|
|
269
|
+
const loadIntegrationValidationContext = vi.fn(() =>
|
|
270
|
+
Promise.resolve(integrationValidationContext),
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
const result = await fetchAndParseWorkflows({
|
|
274
|
+
...baseContext,
|
|
275
|
+
ref: 'main',
|
|
276
|
+
paths: ['.shipfox/workflows/ci.yml'],
|
|
277
|
+
sourceControl: sourceControl(),
|
|
278
|
+
loadIntegrationValidationContext,
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
expect(loadIntegrationValidationContext).not.toHaveBeenCalled();
|
|
282
|
+
expect(result[0]).not.toHaveProperty('rawContent');
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it('loads integration validation context once and reparses integration workflows', async () => {
|
|
286
|
+
const loadIntegrationValidationContext = vi.fn(() =>
|
|
287
|
+
Promise.resolve(integrationValidationContext),
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
const result = await fetchAndParseWorkflows({
|
|
291
|
+
...baseContext,
|
|
292
|
+
ref: 'main',
|
|
293
|
+
paths: ['.shipfox/workflows/ci.yml', '.shipfox/workflows/agent.yml'],
|
|
294
|
+
sourceControl: sourceControl({
|
|
295
|
+
fetchFile: vi.fn(({path}) =>
|
|
296
|
+
Promise.resolve({
|
|
297
|
+
path,
|
|
298
|
+
ref: 'main',
|
|
299
|
+
content: path.endsWith('/agent.yml') ? validIntegrationYaml : validYaml,
|
|
300
|
+
}),
|
|
301
|
+
),
|
|
302
|
+
}),
|
|
303
|
+
loadIntegrationValidationContext,
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
expect(loadIntegrationValidationContext).toHaveBeenCalledTimes(1);
|
|
307
|
+
expect(result).toHaveLength(2);
|
|
308
|
+
expect(result[0]).not.toHaveProperty('rawContent');
|
|
309
|
+
expect(result[1]?.definition.model.jobs[0]?.steps[0]).toMatchObject({
|
|
310
|
+
kind: 'agent',
|
|
311
|
+
integrations: [{connection: 'github-main', include: ['issue_read']}],
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it('rejects integration catalog issues after loading validation context', async () => {
|
|
316
|
+
const loadIntegrationValidationContext = vi.fn(() =>
|
|
317
|
+
Promise.resolve(integrationValidationContext),
|
|
318
|
+
);
|
|
319
|
+
|
|
320
|
+
const result = fetchAndParseWorkflows({
|
|
321
|
+
...baseContext,
|
|
322
|
+
ref: 'main',
|
|
323
|
+
paths: ['.shipfox/workflows/agent.yml'],
|
|
324
|
+
sourceControl: sourceControl({
|
|
325
|
+
fetchFile: vi.fn(() =>
|
|
326
|
+
Promise.resolve({
|
|
327
|
+
path: '.shipfox/workflows/agent.yml',
|
|
328
|
+
ref: 'main',
|
|
329
|
+
content: invalidIntegrationYaml,
|
|
330
|
+
}),
|
|
331
|
+
),
|
|
332
|
+
}),
|
|
333
|
+
loadIntegrationValidationContext,
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
await expect(result).rejects.toMatchObject({code: 'invalid-definition'});
|
|
337
|
+
expect(loadIntegrationValidationContext).toHaveBeenCalledTimes(1);
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
describe('classifySyncFailure', () => {
|
|
342
|
+
it.each([
|
|
343
|
+
['rate-limited', true, 'provider-rate-limited'],
|
|
344
|
+
['timeout', true, 'provider-timeout'],
|
|
345
|
+
['provider-unavailable', true, 'provider-unavailable'],
|
|
346
|
+
['access-denied', false, 'provider-access-denied'],
|
|
347
|
+
['repository-not-found', false, 'provider-repository-not-found'],
|
|
348
|
+
['file-not-found', false, 'provider-file-not-found'],
|
|
349
|
+
['malformed-provider-response', false, 'provider-malformed-response'],
|
|
350
|
+
['content-too-large', false, 'content-too-large'],
|
|
351
|
+
['too-many-files', false, 'too-many-files'],
|
|
352
|
+
])('maps IntegrationProviderError(%s) to retryable=%s code=%s', (reason, retryable, code) => {
|
|
353
|
+
const result = classifySyncFailure(
|
|
354
|
+
// biome-ignore lint/suspicious/noExplicitAny: enumerated reason
|
|
355
|
+
new IntegrationProviderError(reason as any, 'boom'),
|
|
356
|
+
);
|
|
357
|
+
|
|
358
|
+
expect(result).toEqual({code, message: 'boom', retryable});
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
it('classifies DefinitionSyncPermanentError as non-retryable', () => {
|
|
362
|
+
const result = classifySyncFailure(
|
|
363
|
+
new DefinitionSyncPermanentError('invalid-definition', 'bad yaml'),
|
|
364
|
+
);
|
|
365
|
+
|
|
366
|
+
expect(result).toEqual({code: 'invalid-definition', message: 'bad yaml', retryable: false});
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
it.each([
|
|
370
|
+
() => new IntegrationConnectionNotFoundError('connection-1'),
|
|
371
|
+
() => new IntegrationConnectionInactiveError('connection-1'),
|
|
372
|
+
() => new IntegrationConnectionWorkspaceMismatchError('connection-1'),
|
|
373
|
+
])('classifies connection lifecycle errors as non-retryable connection-unavailable', (build) => {
|
|
374
|
+
const error = build();
|
|
375
|
+
|
|
376
|
+
const result = classifySyncFailure(error);
|
|
377
|
+
|
|
378
|
+
expect(result).toEqual({
|
|
379
|
+
code: 'connection-unavailable',
|
|
380
|
+
message: error.message,
|
|
381
|
+
retryable: false,
|
|
382
|
+
});
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
it('falls back to unknown + retryable for plain errors', () => {
|
|
386
|
+
const result = classifySyncFailure(new Error('boom'));
|
|
387
|
+
|
|
388
|
+
expect(result).toEqual({code: 'unknown', message: 'boom', retryable: true});
|
|
389
|
+
});
|
|
390
|
+
});
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import {createHash} from 'node:crypto';
|
|
2
|
+
import {
|
|
3
|
+
IntegrationConnectionInactiveError,
|
|
4
|
+
IntegrationConnectionNotFoundError,
|
|
5
|
+
IntegrationConnectionWorkspaceMismatchError,
|
|
6
|
+
IntegrationProviderError,
|
|
7
|
+
type IntegrationSourceControlService,
|
|
8
|
+
MAX_REPOSITORY_FILE_BYTES,
|
|
9
|
+
} from '@shipfox/api-integration-core';
|
|
10
|
+
import {boundedMap} from '@shipfox/node-module';
|
|
11
|
+
import type {IntegrationValidationContext} from './entities/integration-context.js';
|
|
12
|
+
import type {DefinitionSyncErrorCode} from './entities/sync-state.js';
|
|
13
|
+
import type {WorkflowDefinitionPayload} from './entities/workflow-definition.js';
|
|
14
|
+
import {DefinitionParseError, DefinitionSyncPermanentError} from './errors.js';
|
|
15
|
+
import {hasAgentStepIntegrations} from './has-agent-step-integrations.js';
|
|
16
|
+
import {parseDefinition} from './parse-definition.js';
|
|
17
|
+
|
|
18
|
+
export const WORKFLOW_PREFIX = '.shipfox/workflows/';
|
|
19
|
+
export const MAX_WORKFLOW_FILES = 100;
|
|
20
|
+
export const FILE_FETCH_CONCURRENCY = 4;
|
|
21
|
+
export const UNRESOLVED_SYNC_REF = '__unresolved__';
|
|
22
|
+
|
|
23
|
+
export interface SyncSourceContext {
|
|
24
|
+
workspaceId: string;
|
|
25
|
+
sourceConnectionId: string;
|
|
26
|
+
sourceExternalRepositoryId: string;
|
|
27
|
+
sourceControl: IntegrationSourceControlService;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface ResolvedSyncSource {
|
|
31
|
+
ref: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export async function resolveSyncSource(params: SyncSourceContext): Promise<ResolvedSyncSource> {
|
|
35
|
+
const source = await params.sourceControl.resolveRepository({
|
|
36
|
+
workspaceId: params.workspaceId,
|
|
37
|
+
connectionId: params.sourceConnectionId,
|
|
38
|
+
externalRepositoryId: params.sourceExternalRepositoryId,
|
|
39
|
+
});
|
|
40
|
+
return {ref: source.repository.defaultBranch};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface DiscoverWorkflowFilesParams extends SyncSourceContext {
|
|
44
|
+
ref: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function discoverWorkflowFiles(
|
|
48
|
+
params: DiscoverWorkflowFilesParams,
|
|
49
|
+
): Promise<{paths: string[]}> {
|
|
50
|
+
const page = await params.sourceControl.listFiles({
|
|
51
|
+
workspaceId: params.workspaceId,
|
|
52
|
+
connectionId: params.sourceConnectionId,
|
|
53
|
+
externalRepositoryId: params.sourceExternalRepositoryId,
|
|
54
|
+
ref: params.ref,
|
|
55
|
+
prefix: WORKFLOW_PREFIX,
|
|
56
|
+
limit: MAX_WORKFLOW_FILES,
|
|
57
|
+
});
|
|
58
|
+
if (page.nextCursor) {
|
|
59
|
+
throw new DefinitionSyncPermanentError(
|
|
60
|
+
'too-many-files',
|
|
61
|
+
`More than ${MAX_WORKFLOW_FILES} workflow files were found`,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const paths = page.files
|
|
66
|
+
.filter((file) => file.path.endsWith('.yml') || file.path.endsWith('.yaml'))
|
|
67
|
+
.map((file) => file.path);
|
|
68
|
+
if (paths.length === 0) {
|
|
69
|
+
throw new DefinitionSyncPermanentError(
|
|
70
|
+
'no-workflow-files',
|
|
71
|
+
`No workflow files were found under ${WORKFLOW_PREFIX}`,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return {paths};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface ParsedWorkflow {
|
|
79
|
+
path: string;
|
|
80
|
+
name: string;
|
|
81
|
+
definition: WorkflowDefinitionPayload;
|
|
82
|
+
contentHash: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface FetchAndParseWorkflowsParams extends SyncSourceContext {
|
|
86
|
+
ref: string;
|
|
87
|
+
paths: string[];
|
|
88
|
+
onProgress?: ((path: string) => void) | undefined;
|
|
89
|
+
loadIntegrationValidationContext?: (() => Promise<IntegrationValidationContext>) | undefined;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export async function fetchAndParseWorkflows(
|
|
93
|
+
params: FetchAndParseWorkflowsParams,
|
|
94
|
+
): Promise<ParsedWorkflow[]> {
|
|
95
|
+
const parsed = await boundedMap(
|
|
96
|
+
params.paths,
|
|
97
|
+
FILE_FETCH_CONCURRENCY,
|
|
98
|
+
async (path) => {
|
|
99
|
+
params.onProgress?.(path);
|
|
100
|
+
|
|
101
|
+
const snapshot = await params.sourceControl.fetchFile({
|
|
102
|
+
workspaceId: params.workspaceId,
|
|
103
|
+
connectionId: params.sourceConnectionId,
|
|
104
|
+
externalRepositoryId: params.sourceExternalRepositoryId,
|
|
105
|
+
ref: params.ref,
|
|
106
|
+
path,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
if (Buffer.byteLength(snapshot.content, 'utf8') > MAX_REPOSITORY_FILE_BYTES) {
|
|
110
|
+
throw new DefinitionSyncPermanentError(
|
|
111
|
+
'content-too-large',
|
|
112
|
+
`Workflow file is larger than ${MAX_REPOSITORY_FILE_BYTES} bytes: ${snapshot.path}`,
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
...parseWorkflowSnapshot({path: snapshot.path, content: snapshot.content}),
|
|
118
|
+
rawContent: snapshot.content,
|
|
119
|
+
};
|
|
120
|
+
},
|
|
121
|
+
{stopOnError: true},
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
if (
|
|
125
|
+
!params.loadIntegrationValidationContext ||
|
|
126
|
+
!parsed.some((entry) => hasAgentStepIntegrations(entry.definition.document))
|
|
127
|
+
) {
|
|
128
|
+
return parsed.map(({rawContent: _rawContent, ...entry}) => entry);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const integrationValidationContext = await params.loadIntegrationValidationContext();
|
|
132
|
+
return parsed.map((entry) =>
|
|
133
|
+
parseWorkflowSnapshot({
|
|
134
|
+
path: entry.path,
|
|
135
|
+
content: entry.rawContent,
|
|
136
|
+
integrationValidationContext,
|
|
137
|
+
}),
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function parseWorkflowSnapshot(params: {
|
|
142
|
+
path: string;
|
|
143
|
+
content: string;
|
|
144
|
+
integrationValidationContext?: IntegrationValidationContext | undefined;
|
|
145
|
+
}): ParsedWorkflow {
|
|
146
|
+
try {
|
|
147
|
+
const definition =
|
|
148
|
+
params.integrationValidationContext === undefined
|
|
149
|
+
? parseDefinition(params.content)
|
|
150
|
+
: parseDefinition(params.content, {
|
|
151
|
+
integrationValidationContext: params.integrationValidationContext,
|
|
152
|
+
});
|
|
153
|
+
const contentHash = sha256Hex(params.content);
|
|
154
|
+
return {path: params.path, name: definition.document.name, definition, contentHash};
|
|
155
|
+
} catch (error) {
|
|
156
|
+
if (error instanceof DefinitionParseError) {
|
|
157
|
+
throw new DefinitionSyncPermanentError(
|
|
158
|
+
'invalid-definition',
|
|
159
|
+
`Invalid workflow definition at ${params.path}: ${error.message}`,
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
throw error;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export interface SyncFailureClassification {
|
|
167
|
+
code: DefinitionSyncErrorCode;
|
|
168
|
+
message: string;
|
|
169
|
+
retryable: boolean;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function classifySyncFailure(error: unknown): SyncFailureClassification {
|
|
173
|
+
if (error instanceof DefinitionSyncPermanentError) {
|
|
174
|
+
return {code: error.code, message: error.message, retryable: false};
|
|
175
|
+
}
|
|
176
|
+
if (
|
|
177
|
+
error instanceof IntegrationConnectionNotFoundError ||
|
|
178
|
+
error instanceof IntegrationConnectionInactiveError ||
|
|
179
|
+
error instanceof IntegrationConnectionWorkspaceMismatchError
|
|
180
|
+
) {
|
|
181
|
+
return {code: 'connection-unavailable', message: error.message, retryable: false};
|
|
182
|
+
}
|
|
183
|
+
if (error instanceof IntegrationProviderError) {
|
|
184
|
+
return {
|
|
185
|
+
code: providerErrorCode(error.reason),
|
|
186
|
+
message: error.message,
|
|
187
|
+
retryable: isProviderReasonRetryable(error.reason),
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
code: 'unknown',
|
|
192
|
+
message: error instanceof Error ? error.message : String(error),
|
|
193
|
+
retryable: true,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function isProviderReasonRetryable(reason: string): boolean {
|
|
198
|
+
return reason === 'rate-limited' || reason === 'timeout' || reason === 'provider-unavailable';
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function providerErrorCode(reason: string): DefinitionSyncErrorCode {
|
|
202
|
+
if (reason === 'repository-not-found') return 'provider-repository-not-found';
|
|
203
|
+
if (reason === 'file-not-found') return 'provider-file-not-found';
|
|
204
|
+
if (reason === 'access-denied') return 'provider-access-denied';
|
|
205
|
+
if (reason === 'rate-limited') return 'provider-rate-limited';
|
|
206
|
+
if (reason === 'timeout') return 'provider-timeout';
|
|
207
|
+
if (reason === 'provider-unavailable') return 'provider-unavailable';
|
|
208
|
+
if (reason === 'malformed-provider-response') return 'provider-malformed-response';
|
|
209
|
+
if (reason === 'content-too-large') return 'content-too-large';
|
|
210
|
+
if (reason === 'too-many-files') return 'too-many-files';
|
|
211
|
+
return 'unknown';
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function sha256Hex(content: string): string {
|
|
215
|
+
return createHash('sha256').update(content, 'utf8').digest('hex');
|
|
216
|
+
}
|