@shipfox/api-runners 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 +187 -0
- package/LICENSE +21 -0
- package/dist/config.d.ts +30 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +208 -0
- package/dist/config.js.map +1 -0
- package/dist/core/demand.d.ts +33 -0
- package/dist/core/demand.d.ts.map +1 -0
- package/dist/core/demand.js +169 -0
- package/dist/core/demand.js.map +1 -0
- package/dist/core/entities/ephemeral-registration-token.d.ts +14 -0
- package/dist/core/entities/ephemeral-registration-token.d.ts.map +1 -0
- package/dist/core/entities/ephemeral-registration-token.js +3 -0
- package/dist/core/entities/ephemeral-registration-token.js.map +1 -0
- package/dist/core/entities/manual-registration-token.d.ts +12 -0
- package/dist/core/entities/manual-registration-token.d.ts.map +1 -0
- package/dist/core/entities/manual-registration-token.js +3 -0
- package/dist/core/entities/manual-registration-token.js.map +1 -0
- package/dist/core/entities/provisioned-runner.d.ts +24 -0
- package/dist/core/entities/provisioned-runner.d.ts.map +1 -0
- package/dist/core/entities/provisioned-runner.js +3 -0
- package/dist/core/entities/provisioned-runner.js.map +1 -0
- package/dist/core/entities/provisioner-token.d.ts +18 -0
- package/dist/core/entities/provisioner-token.d.ts.map +1 -0
- package/dist/core/entities/provisioner-token.js +3 -0
- package/dist/core/entities/provisioner-token.js.map +1 -0
- package/dist/core/entities/reservation.d.ts +10 -0
- package/dist/core/entities/reservation.d.ts.map +1 -0
- package/dist/core/entities/reservation.js +3 -0
- package/dist/core/entities/reservation.js.map +1 -0
- package/dist/core/entities/runner-session.d.ts +18 -0
- package/dist/core/entities/runner-session.d.ts.map +1 -0
- package/dist/core/entities/runner-session.js +3 -0
- package/dist/core/entities/runner-session.js.map +1 -0
- package/dist/core/ephemeral-registration-tokens.d.ts +31 -0
- package/dist/core/ephemeral-registration-tokens.d.ts.map +1 -0
- package/dist/core/ephemeral-registration-tokens.js +61 -0
- package/dist/core/ephemeral-registration-tokens.js.map +1 -0
- package/dist/core/errors.d.ts +62 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +92 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/index.d.ts +14 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +10 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/job-executions.d.ts +14 -0
- package/dist/core/job-executions.d.ts.map +1 -0
- package/dist/core/job-executions.js +37 -0
- package/dist/core/job-executions.js.map +1 -0
- package/dist/core/maintenance-policy.d.ts +2 -0
- package/dist/core/maintenance-policy.d.ts.map +1 -0
- package/dist/core/maintenance-policy.js +3 -0
- package/dist/core/maintenance-policy.js.map +1 -0
- package/dist/core/maintenance.d.ts +33 -0
- package/dist/core/maintenance.d.ts.map +1 -0
- package/dist/core/maintenance.js +55 -0
- package/dist/core/maintenance.js.map +1 -0
- package/dist/core/manual-registration-tokens.d.ts +17 -0
- package/dist/core/manual-registration-tokens.d.ts.map +1 -0
- package/dist/core/manual-registration-tokens.js +28 -0
- package/dist/core/manual-registration-tokens.js.map +1 -0
- package/dist/core/provisioned-runners.d.ts +67 -0
- package/dist/core/provisioned-runners.d.ts.map +1 -0
- package/dist/core/provisioned-runners.js +162 -0
- package/dist/core/provisioned-runners.js.map +1 -0
- package/dist/core/provisioner-tokens.d.ts +20 -0
- package/dist/core/provisioner-tokens.d.ts.map +1 -0
- package/dist/core/provisioner-tokens.js +36 -0
- package/dist/core/provisioner-tokens.js.map +1 -0
- package/dist/core/rate-limit.d.ts +35 -0
- package/dist/core/rate-limit.d.ts.map +1 -0
- package/dist/core/rate-limit.js +74 -0
- package/dist/core/rate-limit.js.map +1 -0
- package/dist/core/runner-sessions.d.ts +26 -0
- package/dist/core/runner-sessions.d.ts.map +1 -0
- package/dist/core/runner-sessions.js +41 -0
- package/dist/core/runner-sessions.js.map +1 -0
- package/dist/core/runner-tool-capabilities.d.ts +24 -0
- package/dist/core/runner-tool-capabilities.d.ts.map +1 -0
- package/dist/core/runner-tool-capabilities.js +43 -0
- package/dist/core/runner-tool-capabilities.js.map +1 -0
- package/dist/db/db.d.ts +4478 -0
- package/dist/db/db.d.ts.map +1 -0
- package/dist/db/db.js +36 -0
- package/dist/db/db.js.map +1 -0
- package/dist/db/ephemeral-registration-tokens.d.ts +47 -0
- package/dist/db/ephemeral-registration-tokens.d.ts.map +1 -0
- package/dist/db/ephemeral-registration-tokens.js +170 -0
- package/dist/db/ephemeral-registration-tokens.js.map +1 -0
- package/dist/db/index.d.ts +19 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +15 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/job-executions.d.ts +128 -0
- package/dist/db/job-executions.d.ts.map +1 -0
- package/dist/db/job-executions.js +354 -0
- package/dist/db/job-executions.js.map +1 -0
- package/dist/db/manual-registration-tokens.d.ts +16 -0
- package/dist/db/manual-registration-tokens.d.ts.map +1 -0
- package/dist/db/manual-registration-tokens.js +37 -0
- package/dist/db/manual-registration-tokens.js.map +1 -0
- package/dist/db/provisioned-runners.d.ts +79 -0
- package/dist/db/provisioned-runners.d.ts.map +1 -0
- package/dist/db/provisioned-runners.js +466 -0
- package/dist/db/provisioned-runners.js.map +1 -0
- package/dist/db/provisioner-tokens.d.ts +26 -0
- package/dist/db/provisioner-tokens.d.ts.map +1 -0
- package/dist/db/provisioner-tokens.js +54 -0
- package/dist/db/provisioner-tokens.js.map +1 -0
- package/dist/db/rate-limits.d.ts +18 -0
- package/dist/db/rate-limits.d.ts.map +1 -0
- package/dist/db/rate-limits.js +44 -0
- package/dist/db/rate-limits.js.map +1 -0
- package/dist/db/reservations.d.ts +48 -0
- package/dist/db/reservations.d.ts.map +1 -0
- package/dist/db/reservations.js +162 -0
- package/dist/db/reservations.js.map +1 -0
- package/dist/db/runner-sessions.d.ts +18 -0
- package/dist/db/runner-sessions.d.ts.map +1 -0
- package/dist/db/runner-sessions.js +38 -0
- package/dist/db/runner-sessions.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/ephemeral-registration-tokens.d.ts +199 -0
- package/dist/db/schema/ephemeral-registration-tokens.d.ts.map +1 -0
- package/dist/db/schema/ephemeral-registration-tokens.js +45 -0
- package/dist/db/schema/ephemeral-registration-tokens.js.map +1 -0
- package/dist/db/schema/manual-registration-tokens.d.ts +165 -0
- package/dist/db/schema/manual-registration-tokens.d.ts.map +1 -0
- package/dist/db/schema/manual-registration-tokens.js +40 -0
- package/dist/db/schema/manual-registration-tokens.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/pending-job-executions.d.ts +189 -0
- package/dist/db/schema/pending-job-executions.d.ts.map +1 -0
- package/dist/db/schema/pending-job-executions.js +21 -0
- package/dist/db/schema/pending-job-executions.js.map +1 -0
- package/dist/db/schema/provisioned-runners.d.ts +379 -0
- package/dist/db/schema/provisioned-runners.d.ts.map +1 -0
- package/dist/db/schema/provisioned-runners.js +83 -0
- package/dist/db/schema/provisioned-runners.js.map +1 -0
- package/dist/db/schema/provisioner-tokens.d.ts +216 -0
- package/dist/db/schema/provisioner-tokens.d.ts.map +1 -0
- package/dist/db/schema/provisioner-tokens.js +48 -0
- package/dist/db/schema/provisioner-tokens.js.map +1 -0
- package/dist/db/schema/rate-limits.d.ts +145 -0
- package/dist/db/schema/rate-limits.d.ts.map +1 -0
- package/dist/db/schema/rate-limits.js +25 -0
- package/dist/db/schema/rate-limits.js.map +1 -0
- package/dist/db/schema/reservations.d.ts +157 -0
- package/dist/db/schema/reservations.d.ts.map +1 -0
- package/dist/db/schema/reservations.js +34 -0
- package/dist/db/schema/reservations.js.map +1 -0
- package/dist/db/schema/runner-sessions.d.ts +298 -0
- package/dist/db/schema/runner-sessions.d.ts.map +1 -0
- package/dist/db/schema/runner-sessions.js +61 -0
- package/dist/db/schema/runner-sessions.js.map +1 -0
- package/dist/db/schema/running-job-executions.d.ts +334 -0
- package/dist/db/schema/running-job-executions.d.ts.map +1 -0
- package/dist/db/schema/running-job-executions.js +41 -0
- package/dist/db/schema/running-job-executions.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/dist/metrics/index.d.ts +3 -0
- package/dist/metrics/index.d.ts.map +1 -0
- package/dist/metrics/index.js +4 -0
- package/dist/metrics/index.js.map +1 -0
- package/dist/metrics/instance.d.ts +34 -0
- package/dist/metrics/instance.d.ts.map +1 -0
- package/dist/metrics/instance.js +60 -0
- package/dist/metrics/instance.js.map +1 -0
- package/dist/metrics/service.d.ts +2 -0
- package/dist/metrics/service.d.ts.map +1 -0
- package/dist/metrics/service.js +21 -0
- package/dist/metrics/service.js.map +1 -0
- package/dist/presentation/auth/index.d.ts +3 -0
- package/dist/presentation/auth/index.d.ts.map +1 -0
- package/dist/presentation/auth/index.js +4 -0
- package/dist/presentation/auth/index.js.map +1 -0
- package/dist/presentation/auth/provisioner-token-auth.d.ts +3 -0
- package/dist/presentation/auth/provisioner-token-auth.d.ts.map +1 -0
- package/dist/presentation/auth/provisioner-token-auth.js +81 -0
- package/dist/presentation/auth/provisioner-token-auth.js.map +1 -0
- package/dist/presentation/auth/runner-registration-token-auth.d.ts +17 -0
- package/dist/presentation/auth/runner-registration-token-auth.d.ts.map +1 -0
- package/dist/presentation/auth/runner-registration-token-auth.js +77 -0
- package/dist/presentation/auth/runner-registration-token-auth.js.map +1 -0
- package/dist/presentation/dto/active-provisioner.d.ts +8 -0
- package/dist/presentation/dto/active-provisioner.d.ts.map +1 -0
- package/dist/presentation/dto/active-provisioner.js +10 -0
- package/dist/presentation/dto/active-provisioner.js.map +1 -0
- package/dist/presentation/dto/index.d.ts +7 -0
- package/dist/presentation/dto/index.d.ts.map +1 -0
- package/dist/presentation/dto/index.js +8 -0
- package/dist/presentation/dto/index.js.map +1 -0
- package/dist/presentation/dto/manual-registration-token.d.ts +12 -0
- package/dist/presentation/dto/manual-registration-token.d.ts.map +1 -0
- package/dist/presentation/dto/manual-registration-token.js +14 -0
- package/dist/presentation/dto/manual-registration-token.js.map +1 -0
- package/dist/presentation/dto/mint-registration-tokens.d.ts +5 -0
- package/dist/presentation/dto/mint-registration-tokens.d.ts.map +1 -0
- package/dist/presentation/dto/mint-registration-tokens.js +19 -0
- package/dist/presentation/dto/mint-registration-tokens.js.map +1 -0
- package/dist/presentation/dto/poll-demand.d.ts +4 -0
- package/dist/presentation/dto/poll-demand.d.ts.map +1 -0
- package/dist/presentation/dto/poll-demand.js +19 -0
- package/dist/presentation/dto/poll-demand.js.map +1 -0
- package/dist/presentation/dto/provisioned-runners.d.ts +38 -0
- package/dist/presentation/dto/provisioned-runners.d.ts.map +1 -0
- package/dist/presentation/dto/provisioned-runners.js +44 -0
- package/dist/presentation/dto/provisioned-runners.js.map +1 -0
- package/dist/presentation/dto/provisioner-token.d.ts +15 -0
- package/dist/presentation/dto/provisioner-token.d.ts.map +1 -0
- package/dist/presentation/dto/provisioner-token.js +17 -0
- package/dist/presentation/dto/provisioner-token.js.map +1 -0
- package/dist/presentation/index.d.ts +4 -0
- package/dist/presentation/index.d.ts.map +1 -0
- package/dist/presentation/index.js +5 -0
- package/dist/presentation/index.js.map +1 -0
- package/dist/presentation/routes/create-manual-registration-token.d.ts +2 -0
- package/dist/presentation/routes/create-manual-registration-token.d.ts.map +1 -0
- package/dist/presentation/routes/create-manual-registration-token.js +44 -0
- package/dist/presentation/routes/create-manual-registration-token.js.map +1 -0
- package/dist/presentation/routes/create-provisioner-token.d.ts +2 -0
- package/dist/presentation/routes/create-provisioner-token.d.ts.map +1 -0
- package/dist/presentation/routes/create-provisioner-token.js +42 -0
- package/dist/presentation/routes/create-provisioner-token.js.map +1 -0
- package/dist/presentation/routes/get-provisioner-me.d.ts +2 -0
- package/dist/presentation/routes/get-provisioner-me.d.ts.map +1 -0
- package/dist/presentation/routes/get-provisioner-me.js +22 -0
- package/dist/presentation/routes/get-provisioner-me.js.map +1 -0
- package/dist/presentation/routes/heartbeat.d.ts +2 -0
- package/dist/presentation/routes/heartbeat.d.ts.map +1 -0
- package/dist/presentation/routes/heartbeat.js +64 -0
- package/dist/presentation/routes/heartbeat.js.map +1 -0
- package/dist/presentation/routes/index.d.ts +4 -0
- package/dist/presentation/routes/index.d.ts.map +1 -0
- package/dist/presentation/routes/index.js +97 -0
- package/dist/presentation/routes/index.js.map +1 -0
- package/dist/presentation/routes/list-active-provisioners.d.ts +2 -0
- package/dist/presentation/routes/list-active-provisioners.d.ts.map +1 -0
- package/dist/presentation/routes/list-active-provisioners.js +32 -0
- package/dist/presentation/routes/list-active-provisioners.js.map +1 -0
- package/dist/presentation/routes/list-active-runners.d.ts +2 -0
- package/dist/presentation/routes/list-active-runners.d.ts.map +1 -0
- package/dist/presentation/routes/list-active-runners.js +32 -0
- package/dist/presentation/routes/list-active-runners.js.map +1 -0
- package/dist/presentation/routes/list-manual-registration-tokens.d.ts +2 -0
- package/dist/presentation/routes/list-manual-registration-tokens.d.ts.map +1 -0
- package/dist/presentation/routes/list-manual-registration-tokens.js +32 -0
- package/dist/presentation/routes/list-manual-registration-tokens.js.map +1 -0
- package/dist/presentation/routes/list-provisioner-tokens.d.ts +2 -0
- package/dist/presentation/routes/list-provisioner-tokens.d.ts.map +1 -0
- package/dist/presentation/routes/list-provisioner-tokens.js +32 -0
- package/dist/presentation/routes/list-provisioner-tokens.js.map +1 -0
- package/dist/presentation/routes/mint-registration-tokens.d.ts +2 -0
- package/dist/presentation/routes/mint-registration-tokens.d.ts.map +1 -0
- package/dist/presentation/routes/mint-registration-tokens.js +74 -0
- package/dist/presentation/routes/mint-registration-tokens.js.map +1 -0
- package/dist/presentation/routes/poll-demand.d.ts +2 -0
- package/dist/presentation/routes/poll-demand.d.ts.map +1 -0
- package/dist/presentation/routes/poll-demand.js +53 -0
- package/dist/presentation/routes/poll-demand.js.map +1 -0
- package/dist/presentation/routes/rate-limit.d.ts +4 -0
- package/dist/presentation/routes/rate-limit.d.ts.map +1 -0
- package/dist/presentation/routes/rate-limit.js +94 -0
- package/dist/presentation/routes/rate-limit.js.map +1 -0
- package/dist/presentation/routes/reconcile-provisioned-runners.d.ts +2 -0
- package/dist/presentation/routes/reconcile-provisioned-runners.d.ts.map +1 -0
- package/dist/presentation/routes/reconcile-provisioned-runners.js +27 -0
- package/dist/presentation/routes/reconcile-provisioned-runners.js.map +1 -0
- package/dist/presentation/routes/register.d.ts +2 -0
- package/dist/presentation/routes/register.d.ts.map +1 -0
- package/dist/presentation/routes/register.js +63 -0
- package/dist/presentation/routes/register.js.map +1 -0
- package/dist/presentation/routes/report-provisioned-runners.d.ts +2 -0
- package/dist/presentation/routes/report-provisioned-runners.d.ts.map +1 -0
- package/dist/presentation/routes/report-provisioned-runners.js +37 -0
- package/dist/presentation/routes/report-provisioned-runners.js.map +1 -0
- package/dist/presentation/routes/request-job.d.ts +2 -0
- package/dist/presentation/routes/request-job.d.ts.map +1 -0
- package/dist/presentation/routes/request-job.js +45 -0
- package/dist/presentation/routes/request-job.js.map +1 -0
- package/dist/presentation/routes/revoke-manual-registration-token.d.ts +2 -0
- package/dist/presentation/routes/revoke-manual-registration-token.d.ts.map +1 -0
- package/dist/presentation/routes/revoke-manual-registration-token.js +42 -0
- package/dist/presentation/routes/revoke-manual-registration-token.js.map +1 -0
- package/dist/presentation/routes/revoke-provisioner-token.d.ts +2 -0
- package/dist/presentation/routes/revoke-provisioner-token.d.ts.map +1 -0
- package/dist/presentation/routes/revoke-provisioner-token.js +44 -0
- package/dist/presentation/routes/revoke-provisioner-token.js.map +1 -0
- package/dist/presentation/routes/workspace-membership.d.ts +6 -0
- package/dist/presentation/routes/workspace-membership.d.ts.map +1 -0
- package/dist/presentation/routes/workspace-membership.js +6 -0
- package/dist/presentation/routes/workspace-membership.js.map +1 -0
- package/dist/presentation/subscribers/on-workflows-job-execution-timed-out.d.ts +3 -0
- package/dist/presentation/subscribers/on-workflows-job-execution-timed-out.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-workflows-job-execution-timed-out.js +14 -0
- package/dist/presentation/subscribers/on-workflows-job-execution-timed-out.js.map +1 -0
- package/dist/temporal/activities/index.d.ts +9 -0
- package/dist/temporal/activities/index.d.ts.map +1 -0
- package/dist/temporal/activities/index.js +12 -0
- package/dist/temporal/activities/index.js.map +1 -0
- package/dist/temporal/activities/maintenance-activities.d.ts +31 -0
- package/dist/temporal/activities/maintenance-activities.d.ts.map +1 -0
- package/dist/temporal/activities/maintenance-activities.js +18 -0
- package/dist/temporal/activities/maintenance-activities.js.map +1 -0
- package/dist/temporal/constants.d.ts +2 -0
- package/dist/temporal/constants.d.ts.map +1 -0
- package/dist/temporal/constants.js +3 -0
- package/dist/temporal/constants.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/temporal/workflows/stuck-job-detector.d.ts +2 -0
- package/dist/temporal/workflows/stuck-job-detector.d.ts.map +1 -0
- package/dist/temporal/workflows/stuck-job-detector.js +61 -0
- package/dist/temporal/workflows/stuck-job-detector.js.map +1 -0
- package/dist/tsconfig.test.tsbuildinfo +1 -0
- package/drizzle/0000_initial.sql +185 -0
- package/drizzle/meta/0000_snapshot.json +1582 -0
- package/drizzle/meta/_journal.json +13 -0
- package/drizzle.config.ts +7 -0
- package/package.json +82 -0
- package/src/config.test.ts +374 -0
- package/src/config.ts +330 -0
- package/src/core/demand.test.ts +301 -0
- package/src/core/demand.ts +239 -0
- package/src/core/entities/ephemeral-registration-token.ts +13 -0
- package/src/core/entities/manual-registration-token.ts +11 -0
- package/src/core/entities/provisioned-runner.ts +30 -0
- package/src/core/entities/provisioner-token.ts +16 -0
- package/src/core/entities/reservation.ts +9 -0
- package/src/core/entities/runner-session.ts +18 -0
- package/src/core/ephemeral-registration-tokens.test.ts +108 -0
- package/src/core/ephemeral-registration-tokens.ts +112 -0
- package/src/core/errors.ts +128 -0
- package/src/core/index.ts +56 -0
- package/src/core/job-executions.ts +47 -0
- package/src/core/maintenance-policy.ts +1 -0
- package/src/core/maintenance.test.ts +251 -0
- package/src/core/maintenance.ts +74 -0
- package/src/core/manual-registration-tokens.test.ts +44 -0
- package/src/core/manual-registration-tokens.ts +51 -0
- package/src/core/provisioned-runners.test.ts +101 -0
- package/src/core/provisioned-runners.ts +301 -0
- package/src/core/provisioner-tokens.test.ts +61 -0
- package/src/core/provisioner-tokens.ts +61 -0
- package/src/core/rate-limit.test.ts +158 -0
- package/src/core/rate-limit.ts +121 -0
- package/src/core/runner-sessions.test.ts +209 -0
- package/src/core/runner-sessions.ts +66 -0
- package/src/core/runner-tool-capabilities.test.ts +141 -0
- package/src/core/runner-tool-capabilities.ts +75 -0
- package/src/db/db.ts +38 -0
- package/src/db/ephemeral-registration-tokens.test.ts +332 -0
- package/src/db/ephemeral-registration-tokens.ts +348 -0
- package/src/db/index.ts +90 -0
- package/src/db/job-executions.test.ts +1500 -0
- package/src/db/job-executions.ts +647 -0
- package/src/db/manual-registration-tokens.test.ts +99 -0
- package/src/db/manual-registration-tokens.ts +87 -0
- package/src/db/provisioned-runners.test.ts +1812 -0
- package/src/db/provisioned-runners.ts +886 -0
- package/src/db/provisioner-tokens.test.ts +133 -0
- package/src/db/provisioner-tokens.ts +142 -0
- package/src/db/rate-limits.test.ts +74 -0
- package/src/db/rate-limits.ts +69 -0
- package/src/db/reservations.test.ts +399 -0
- package/src/db/reservations.ts +296 -0
- package/src/db/runner-sessions.test.ts +153 -0
- package/src/db/runner-sessions.ts +97 -0
- package/src/db/schema/common.ts +3 -0
- package/src/db/schema/ephemeral-registration-tokens.ts +58 -0
- package/src/db/schema/manual-registration-tokens.ts +40 -0
- package/src/db/schema/outbox.ts +4 -0
- package/src/db/schema/pending-job-executions.ts +25 -0
- package/src/db/schema/provisioned-runners.ts +89 -0
- package/src/db/schema/provisioner-tokens.ts +50 -0
- package/src/db/schema/rate-limits.ts +27 -0
- package/src/db/schema/reservations.ts +38 -0
- package/src/db/schema/runner-sessions.ts +77 -0
- package/src/db/schema/running-job-executions.ts +50 -0
- package/src/index.ts +63 -0
- package/src/metrics/index.ts +13 -0
- package/src/metrics/instance.ts +115 -0
- package/src/metrics/service.ts +22 -0
- package/src/presentation/auth/index.ts +6 -0
- package/src/presentation/auth/provisioner-token-auth.ts +76 -0
- package/src/presentation/auth/runner-registration-token-auth.ts +105 -0
- package/src/presentation/dto/active-provisioner.ts +15 -0
- package/src/presentation/dto/index.ts +13 -0
- package/src/presentation/dto/manual-registration-token.ts +23 -0
- package/src/presentation/dto/mint-registration-tokens.ts +35 -0
- package/src/presentation/dto/poll-demand.ts +20 -0
- package/src/presentation/dto/provisioned-runners.ts +88 -0
- package/src/presentation/dto/provisioner-token.ts +29 -0
- package/src/presentation/index.ts +6 -0
- package/src/presentation/routes/create-manual-registration-token.ts +43 -0
- package/src/presentation/routes/create-provisioner-token.ts +41 -0
- package/src/presentation/routes/get-provisioner-me.ts +22 -0
- package/src/presentation/routes/heartbeat.test.ts +325 -0
- package/src/presentation/routes/heartbeat.ts +80 -0
- package/src/presentation/routes/index.ts +86 -0
- package/src/presentation/routes/list-active-provisioners.ts +25 -0
- package/src/presentation/routes/list-active-runners.test.ts +366 -0
- package/src/presentation/routes/list-active-runners.ts +25 -0
- package/src/presentation/routes/list-manual-registration-tokens.ts +25 -0
- package/src/presentation/routes/list-provisioner-tokens.ts +25 -0
- package/src/presentation/routes/manual-registration-tokens.test.ts +213 -0
- package/src/presentation/routes/mint-registration-tokens.test.ts +453 -0
- package/src/presentation/routes/mint-registration-tokens.ts +82 -0
- package/src/presentation/routes/poll-demand-release.test.ts +80 -0
- package/src/presentation/routes/poll-demand.test.ts +323 -0
- package/src/presentation/routes/poll-demand.ts +56 -0
- package/src/presentation/routes/provisioner-me.test.ts +172 -0
- package/src/presentation/routes/provisioner-tokens.test.ts +219 -0
- package/src/presentation/routes/rate-limit.ts +115 -0
- package/src/presentation/routes/reconcile-provisioned-runners.test.ts +380 -0
- package/src/presentation/routes/reconcile-provisioned-runners.ts +30 -0
- package/src/presentation/routes/register.test.ts +453 -0
- package/src/presentation/routes/register.ts +75 -0
- package/src/presentation/routes/report-provisioned-runners.test.ts +249 -0
- package/src/presentation/routes/report-provisioned-runners.ts +40 -0
- package/src/presentation/routes/request-job.test.ts +222 -0
- package/src/presentation/routes/request-job.ts +47 -0
- package/src/presentation/routes/revoke-manual-registration-token.ts +35 -0
- package/src/presentation/routes/revoke-provisioner-token.ts +37 -0
- package/src/presentation/routes/workspace-membership.ts +9 -0
- package/src/presentation/subscribers/on-workflows-job-execution-timed-out.test.ts +147 -0
- package/src/presentation/subscribers/on-workflows-job-execution-timed-out.ts +17 -0
- package/src/temporal/activities/index.ts +17 -0
- package/src/temporal/activities/maintenance-activities.test.ts +104 -0
- package/src/temporal/activities/maintenance-activities.ts +41 -0
- package/src/temporal/constants.ts +1 -0
- package/src/temporal/workflows/index.ts +1 -0
- package/src/temporal/workflows/stuck-job-detector.test.ts +93 -0
- package/src/temporal/workflows/stuck-job-detector.ts +67 -0
- package/test/env.ts +11 -0
- package/test/factories/ephemeral-registration-token.ts +41 -0
- package/test/factories/manual-registration-token.ts +37 -0
- package/test/factories/pending-job.ts +44 -0
- package/test/factories/provisioned-runner.ts +78 -0
- package/test/factories/provisioner-token.ts +41 -0
- package/test/factories/reservation.ts +33 -0
- package/test/factories/runner-session.ts +32 -0
- package/test/globalSetup.ts +23 -0
- package/test/index.ts +16 -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 +14 -0
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AUTH_LEASED_JOB,
|
|
3
|
+
AUTH_PROVISIONER_TOKEN,
|
|
4
|
+
AUTH_RUNNER_REGISTRATION_TOKEN,
|
|
5
|
+
AUTH_RUNNER_SESSION,
|
|
6
|
+
AUTH_USER,
|
|
7
|
+
buildUserContext,
|
|
8
|
+
setUserContext,
|
|
9
|
+
type UserContextMembership,
|
|
10
|
+
} from '@shipfox/api-auth-context';
|
|
11
|
+
import type {AuthMethod} from '@shipfox/node-fastify';
|
|
12
|
+
import {ClientError, closeApp, createApp} from '@shipfox/node-fastify';
|
|
13
|
+
import type {FastifyInstance, FastifyRequest} from 'fastify';
|
|
14
|
+
import {db} from '#db/db.js';
|
|
15
|
+
import {provisionedRunners} from '#db/schema/provisioned-runners.js';
|
|
16
|
+
import {runningJobExecutions} from '#db/schema/running-job-executions.js';
|
|
17
|
+
import {runnerSessionFactory} from '#test/index.js';
|
|
18
|
+
import {runnerRoutes} from './index.js';
|
|
19
|
+
|
|
20
|
+
let authenticatedMemberships: ReadonlyArray<UserContextMembership> = [];
|
|
21
|
+
|
|
22
|
+
const fakeUserAuth: AuthMethod = {
|
|
23
|
+
name: AUTH_USER,
|
|
24
|
+
authenticate: (request: FastifyRequest) => {
|
|
25
|
+
if (request.headers.authorization !== 'Bearer user') {
|
|
26
|
+
throw new ClientError('Invalid user token', 'unauthorized', {status: 401});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
setUserContext(
|
|
30
|
+
request,
|
|
31
|
+
buildUserContext({
|
|
32
|
+
userId: 'user-1',
|
|
33
|
+
email: 'user@example.com',
|
|
34
|
+
memberships: authenticatedMemberships,
|
|
35
|
+
}),
|
|
36
|
+
);
|
|
37
|
+
return Promise.resolve();
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const passthroughAuth = (name: string): AuthMethod => ({
|
|
42
|
+
name,
|
|
43
|
+
authenticate: () => Promise.resolve(),
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe('GET /workspaces/:workspaceId/runners/active', () => {
|
|
47
|
+
let app: FastifyInstance;
|
|
48
|
+
let workspaceId: string;
|
|
49
|
+
|
|
50
|
+
beforeEach(async () => {
|
|
51
|
+
await closeApp();
|
|
52
|
+
workspaceId = crypto.randomUUID();
|
|
53
|
+
authenticatedMemberships = [{workspaceId, role: 'admin'}];
|
|
54
|
+
app = await createApp({
|
|
55
|
+
auth: [
|
|
56
|
+
fakeUserAuth,
|
|
57
|
+
passthroughAuth(AUTH_RUNNER_REGISTRATION_TOKEN),
|
|
58
|
+
passthroughAuth(AUTH_RUNNER_SESSION),
|
|
59
|
+
passthroughAuth(AUTH_LEASED_JOB),
|
|
60
|
+
passthroughAuth(AUTH_PROVISIONER_TOKEN),
|
|
61
|
+
],
|
|
62
|
+
routes: runnerRoutes,
|
|
63
|
+
swagger: false,
|
|
64
|
+
});
|
|
65
|
+
await app.ready();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
afterEach(async () => {
|
|
69
|
+
await closeApp();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('returns active provisioned runners merged with running jobs by runner session', async () => {
|
|
73
|
+
const runnerSession = await runnerSessionFactory.create({workspaceId});
|
|
74
|
+
const runnerSessionId = runnerSession.id;
|
|
75
|
+
await db()
|
|
76
|
+
.insert(provisionedRunners)
|
|
77
|
+
.values({
|
|
78
|
+
workspaceId,
|
|
79
|
+
provisionerId: crypto.randomUUID(),
|
|
80
|
+
provisionedRunnerId: 'provisioned-runner-1',
|
|
81
|
+
labels: ['linux'],
|
|
82
|
+
state: 'running',
|
|
83
|
+
runnerSessionId,
|
|
84
|
+
providerKind: 'docker',
|
|
85
|
+
reportedAt: new Date(),
|
|
86
|
+
});
|
|
87
|
+
await db()
|
|
88
|
+
.insert(runningJobExecutions)
|
|
89
|
+
.values({
|
|
90
|
+
workspaceId,
|
|
91
|
+
jobId: crypto.randomUUID(),
|
|
92
|
+
jobExecutionId: crypto.randomUUID(),
|
|
93
|
+
workflowRunId: crypto.randomUUID(),
|
|
94
|
+
workflowRunAttemptId: crypto.randomUUID(),
|
|
95
|
+
projectId: crypto.randomUUID(),
|
|
96
|
+
runnerSessionId,
|
|
97
|
+
requiredLabels: ['linux'],
|
|
98
|
+
runnerLabels: ['linux'],
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const res = await app.inject({
|
|
102
|
+
method: 'GET',
|
|
103
|
+
url: `/workspaces/${workspaceId}/runners/active`,
|
|
104
|
+
headers: {authorization: 'Bearer user'},
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
expect(res.statusCode).toBe(200);
|
|
108
|
+
expect(res.json().runners).toEqual([
|
|
109
|
+
expect.objectContaining({
|
|
110
|
+
runner_session_id: runnerSessionId,
|
|
111
|
+
provisioned_runner_id: 'provisioned-runner-1',
|
|
112
|
+
state: 'busy',
|
|
113
|
+
labels: ['linux'],
|
|
114
|
+
}),
|
|
115
|
+
]);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('returns every active job for the same runner session', async () => {
|
|
119
|
+
const runnerSession = await runnerSessionFactory.create({workspaceId});
|
|
120
|
+
const runnerSessionId = runnerSession.id;
|
|
121
|
+
const firstJobId = crypto.randomUUID();
|
|
122
|
+
const secondJobId = crypto.randomUUID();
|
|
123
|
+
await db()
|
|
124
|
+
.insert(provisionedRunners)
|
|
125
|
+
.values({
|
|
126
|
+
workspaceId,
|
|
127
|
+
provisionerId: crypto.randomUUID(),
|
|
128
|
+
provisionedRunnerId: 'provisioned-runner-1',
|
|
129
|
+
labels: ['linux'],
|
|
130
|
+
state: 'running',
|
|
131
|
+
runnerSessionId,
|
|
132
|
+
providerKind: 'docker',
|
|
133
|
+
reportedAt: new Date(),
|
|
134
|
+
});
|
|
135
|
+
await db()
|
|
136
|
+
.insert(runningJobExecutions)
|
|
137
|
+
.values([
|
|
138
|
+
{
|
|
139
|
+
workspaceId,
|
|
140
|
+
jobId: firstJobId,
|
|
141
|
+
jobExecutionId: crypto.randomUUID(),
|
|
142
|
+
workflowRunId: crypto.randomUUID(),
|
|
143
|
+
workflowRunAttemptId: crypto.randomUUID(),
|
|
144
|
+
projectId: crypto.randomUUID(),
|
|
145
|
+
runnerSessionId,
|
|
146
|
+
requiredLabels: ['linux'],
|
|
147
|
+
runnerLabels: ['linux'],
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
workspaceId,
|
|
151
|
+
jobId: secondJobId,
|
|
152
|
+
jobExecutionId: crypto.randomUUID(),
|
|
153
|
+
workflowRunId: crypto.randomUUID(),
|
|
154
|
+
workflowRunAttemptId: crypto.randomUUID(),
|
|
155
|
+
projectId: crypto.randomUUID(),
|
|
156
|
+
runnerSessionId,
|
|
157
|
+
requiredLabels: ['linux'],
|
|
158
|
+
runnerLabels: ['linux'],
|
|
159
|
+
},
|
|
160
|
+
]);
|
|
161
|
+
|
|
162
|
+
const res = await app.inject({
|
|
163
|
+
method: 'GET',
|
|
164
|
+
url: `/workspaces/${workspaceId}/runners/active`,
|
|
165
|
+
headers: {authorization: 'Bearer user'},
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
const body = res.json();
|
|
169
|
+
expect(res.statusCode).toBe(200);
|
|
170
|
+
expect(body.runners).toHaveLength(2);
|
|
171
|
+
expect(body.runners).toEqual(
|
|
172
|
+
expect.arrayContaining([
|
|
173
|
+
expect.objectContaining({
|
|
174
|
+
runner_session_id: runnerSessionId,
|
|
175
|
+
provisioned_runner_id: 'provisioned-runner-1',
|
|
176
|
+
state: 'busy',
|
|
177
|
+
job_id: firstJobId,
|
|
178
|
+
}),
|
|
179
|
+
expect.objectContaining({
|
|
180
|
+
runner_session_id: runnerSessionId,
|
|
181
|
+
provisioned_runner_id: 'provisioned-runner-1',
|
|
182
|
+
state: 'busy',
|
|
183
|
+
job_id: secondJobId,
|
|
184
|
+
}),
|
|
185
|
+
]),
|
|
186
|
+
);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it('merges active jobs by provisioned-runner link when the session id is not reported', async () => {
|
|
190
|
+
const provisionerId = crypto.randomUUID();
|
|
191
|
+
const runnerSession = await runnerSessionFactory.create({workspaceId});
|
|
192
|
+
const runnerSessionId = runnerSession.id;
|
|
193
|
+
const jobId = crypto.randomUUID();
|
|
194
|
+
await db()
|
|
195
|
+
.insert(provisionedRunners)
|
|
196
|
+
.values({
|
|
197
|
+
workspaceId,
|
|
198
|
+
provisionerId,
|
|
199
|
+
provisionedRunnerId: 'provisioned-runner-1',
|
|
200
|
+
labels: ['linux'],
|
|
201
|
+
state: 'running',
|
|
202
|
+
runnerSessionId: null,
|
|
203
|
+
providerKind: 'docker',
|
|
204
|
+
reportedAt: new Date(),
|
|
205
|
+
});
|
|
206
|
+
await db()
|
|
207
|
+
.insert(runningJobExecutions)
|
|
208
|
+
.values({
|
|
209
|
+
workspaceId,
|
|
210
|
+
jobId,
|
|
211
|
+
jobExecutionId: crypto.randomUUID(),
|
|
212
|
+
workflowRunId: crypto.randomUUID(),
|
|
213
|
+
workflowRunAttemptId: crypto.randomUUID(),
|
|
214
|
+
projectId: crypto.randomUUID(),
|
|
215
|
+
runnerSessionId,
|
|
216
|
+
provisionerId,
|
|
217
|
+
provisionedRunnerId: 'provisioned-runner-1',
|
|
218
|
+
requiredLabels: ['linux'],
|
|
219
|
+
runnerLabels: ['linux'],
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
const res = await app.inject({
|
|
223
|
+
method: 'GET',
|
|
224
|
+
url: `/workspaces/${workspaceId}/runners/active`,
|
|
225
|
+
headers: {authorization: 'Bearer user'},
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
expect(res.statusCode).toBe(200);
|
|
229
|
+
expect(res.json().runners).toEqual([
|
|
230
|
+
expect.objectContaining({
|
|
231
|
+
runner_session_id: runnerSessionId,
|
|
232
|
+
provisioned_runner_id: 'provisioned-runner-1',
|
|
233
|
+
provisioner_id: provisionerId,
|
|
234
|
+
state: 'busy',
|
|
235
|
+
job_id: jobId,
|
|
236
|
+
}),
|
|
237
|
+
]);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it('surfaces the job link for a busy runner without an active provisioned-runner row', async () => {
|
|
241
|
+
const provisionerId = crypto.randomUUID();
|
|
242
|
+
const runnerSession = await runnerSessionFactory.create({workspaceId});
|
|
243
|
+
const runnerSessionId = runnerSession.id;
|
|
244
|
+
const jobId = crypto.randomUUID();
|
|
245
|
+
await db()
|
|
246
|
+
.insert(runningJobExecutions)
|
|
247
|
+
.values({
|
|
248
|
+
workspaceId,
|
|
249
|
+
jobId,
|
|
250
|
+
jobExecutionId: crypto.randomUUID(),
|
|
251
|
+
workflowRunId: crypto.randomUUID(),
|
|
252
|
+
workflowRunAttemptId: crypto.randomUUID(),
|
|
253
|
+
projectId: crypto.randomUUID(),
|
|
254
|
+
runnerSessionId,
|
|
255
|
+
provisionerId,
|
|
256
|
+
provisionedRunnerId: 'provisioned-runner-1',
|
|
257
|
+
requiredLabels: ['linux'],
|
|
258
|
+
runnerLabels: ['linux'],
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
const res = await app.inject({
|
|
262
|
+
method: 'GET',
|
|
263
|
+
url: `/workspaces/${workspaceId}/runners/active`,
|
|
264
|
+
headers: {authorization: 'Bearer user'},
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
expect(res.statusCode).toBe(200);
|
|
268
|
+
expect(res.json().runners).toEqual([
|
|
269
|
+
expect.objectContaining({
|
|
270
|
+
runner_session_id: runnerSessionId,
|
|
271
|
+
provisioned_runner_id: 'provisioned-runner-1',
|
|
272
|
+
provisioner_id: provisionerId,
|
|
273
|
+
state: 'busy',
|
|
274
|
+
job_id: jobId,
|
|
275
|
+
}),
|
|
276
|
+
]);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it('keeps a provisioned runner visible when its session fallback job was already merged', async () => {
|
|
280
|
+
const provisionerId = crypto.randomUUID();
|
|
281
|
+
const runnerSession = await runnerSessionFactory.create({workspaceId});
|
|
282
|
+
const runnerSessionId = runnerSession.id;
|
|
283
|
+
const jobId = crypto.randomUUID();
|
|
284
|
+
const older = new Date(Date.now() - 1000);
|
|
285
|
+
const newer = new Date();
|
|
286
|
+
await db()
|
|
287
|
+
.insert(provisionedRunners)
|
|
288
|
+
.values([
|
|
289
|
+
{
|
|
290
|
+
workspaceId,
|
|
291
|
+
provisionerId,
|
|
292
|
+
provisionedRunnerId: 'provisioned-runner-b',
|
|
293
|
+
labels: ['linux'],
|
|
294
|
+
state: 'running',
|
|
295
|
+
runnerSessionId,
|
|
296
|
+
providerKind: 'docker',
|
|
297
|
+
reportedAt: older,
|
|
298
|
+
updatedAt: older,
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
workspaceId,
|
|
302
|
+
provisionerId,
|
|
303
|
+
provisionedRunnerId: 'provisioned-runner-a',
|
|
304
|
+
labels: ['linux'],
|
|
305
|
+
state: 'running',
|
|
306
|
+
runnerSessionId: null,
|
|
307
|
+
providerKind: 'docker',
|
|
308
|
+
reportedAt: newer,
|
|
309
|
+
updatedAt: newer,
|
|
310
|
+
},
|
|
311
|
+
]);
|
|
312
|
+
await db()
|
|
313
|
+
.insert(runningJobExecutions)
|
|
314
|
+
.values({
|
|
315
|
+
workspaceId,
|
|
316
|
+
jobId,
|
|
317
|
+
jobExecutionId: crypto.randomUUID(),
|
|
318
|
+
workflowRunId: crypto.randomUUID(),
|
|
319
|
+
workflowRunAttemptId: crypto.randomUUID(),
|
|
320
|
+
projectId: crypto.randomUUID(),
|
|
321
|
+
runnerSessionId,
|
|
322
|
+
provisionerId,
|
|
323
|
+
provisionedRunnerId: 'provisioned-runner-a',
|
|
324
|
+
requiredLabels: ['linux'],
|
|
325
|
+
runnerLabels: ['linux'],
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
const res = await app.inject({
|
|
329
|
+
method: 'GET',
|
|
330
|
+
url: `/workspaces/${workspaceId}/runners/active`,
|
|
331
|
+
headers: {authorization: 'Bearer user'},
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
const body = res.json();
|
|
335
|
+
expect(res.statusCode).toBe(200);
|
|
336
|
+
expect(body.runners).toHaveLength(2);
|
|
337
|
+
expect(body.runners).toEqual(
|
|
338
|
+
expect.arrayContaining([
|
|
339
|
+
expect.objectContaining({
|
|
340
|
+
runner_session_id: runnerSessionId,
|
|
341
|
+
provisioned_runner_id: 'provisioned-runner-a',
|
|
342
|
+
state: 'busy',
|
|
343
|
+
job_id: jobId,
|
|
344
|
+
}),
|
|
345
|
+
expect.objectContaining({
|
|
346
|
+
runner_session_id: runnerSessionId,
|
|
347
|
+
provisioned_runner_id: 'provisioned-runner-b',
|
|
348
|
+
state: 'running',
|
|
349
|
+
job_id: null,
|
|
350
|
+
}),
|
|
351
|
+
]),
|
|
352
|
+
);
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
it('returns 403 when the user is not a workspace member', async () => {
|
|
356
|
+
authenticatedMemberships = [{workspaceId: crypto.randomUUID(), role: 'admin'}];
|
|
357
|
+
|
|
358
|
+
const res = await app.inject({
|
|
359
|
+
method: 'GET',
|
|
360
|
+
url: `/workspaces/${workspaceId}/runners/active`,
|
|
361
|
+
headers: {authorization: 'Bearer user'},
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
expect(res.statusCode).toBe(403);
|
|
365
|
+
});
|
|
366
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {activeRunnersResponseSchema} from '@shipfox/api-runners-dto';
|
|
2
|
+
import {defineRoute} from '@shipfox/node-fastify';
|
|
3
|
+
import {z} from 'zod';
|
|
4
|
+
import {listActiveRunners} from '#core/index.js';
|
|
5
|
+
import {toActiveRunnersResponseDto} from '#presentation/dto/index.js';
|
|
6
|
+
import {requireManualRegistrationTokenWorkspaceMembership} from './workspace-membership.js';
|
|
7
|
+
|
|
8
|
+
export const listActiveRunnersRoute = defineRoute({
|
|
9
|
+
method: 'GET',
|
|
10
|
+
path: '/',
|
|
11
|
+
description: 'List active runners and provisioned runners for a workspace',
|
|
12
|
+
schema: {
|
|
13
|
+
params: z.object({workspaceId: z.string().uuid()}),
|
|
14
|
+
response: {
|
|
15
|
+
200: activeRunnersResponseSchema,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
handler: async (request) => {
|
|
19
|
+
const {workspaceId} = request.params;
|
|
20
|
+
requireManualRegistrationTokenWorkspaceMembership({request, workspaceId});
|
|
21
|
+
|
|
22
|
+
const runners = await listActiveRunners({workspaceId});
|
|
23
|
+
return toActiveRunnersResponseDto(runners);
|
|
24
|
+
},
|
|
25
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {listManualRegistrationTokensResponseSchema} from '@shipfox/api-runners-dto';
|
|
2
|
+
import {defineRoute} from '@shipfox/node-fastify';
|
|
3
|
+
import {z} from 'zod';
|
|
4
|
+
import {listUsableManualRegistrationTokens} from '#core/index.js';
|
|
5
|
+
import {toManualRegistrationTokenDto} from '#presentation/dto/index.js';
|
|
6
|
+
import {requireManualRegistrationTokenWorkspaceMembership} from './workspace-membership.js';
|
|
7
|
+
|
|
8
|
+
export const listManualRegistrationTokensRoute = defineRoute({
|
|
9
|
+
method: 'GET',
|
|
10
|
+
path: '/',
|
|
11
|
+
description: 'List currently usable manual registration tokens for a workspace',
|
|
12
|
+
schema: {
|
|
13
|
+
params: z.object({workspaceId: z.string().uuid()}),
|
|
14
|
+
response: {
|
|
15
|
+
200: listManualRegistrationTokensResponseSchema,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
handler: async (request) => {
|
|
19
|
+
const {workspaceId} = request.params;
|
|
20
|
+
requireManualRegistrationTokenWorkspaceMembership({request, workspaceId});
|
|
21
|
+
|
|
22
|
+
const tokens = await listUsableManualRegistrationTokens(workspaceId);
|
|
23
|
+
return {manual_registration_tokens: tokens.map(toManualRegistrationTokenDto)};
|
|
24
|
+
},
|
|
25
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {requireWorkspaceAccess} from '@shipfox/api-auth-context';
|
|
2
|
+
import {listProvisionerTokensResponseSchema} from '@shipfox/api-runners-dto';
|
|
3
|
+
import {defineRoute} from '@shipfox/node-fastify';
|
|
4
|
+
import {z} from 'zod';
|
|
5
|
+
import {listUsableProvisionerTokens} from '#core/index.js';
|
|
6
|
+
import {toProvisionerTokenDto} from '#presentation/dto/index.js';
|
|
7
|
+
|
|
8
|
+
export const listProvisionerTokensRoute = defineRoute({
|
|
9
|
+
method: 'GET',
|
|
10
|
+
path: '/',
|
|
11
|
+
description: 'List currently usable provisioner tokens for a workspace',
|
|
12
|
+
schema: {
|
|
13
|
+
params: z.object({workspaceId: z.string().uuid()}),
|
|
14
|
+
response: {
|
|
15
|
+
200: listProvisionerTokensResponseSchema,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
handler: async (request) => {
|
|
19
|
+
const {workspaceId} = request.params;
|
|
20
|
+
requireWorkspaceAccess({request, workspaceId});
|
|
21
|
+
|
|
22
|
+
const tokens = await listUsableProvisionerTokens(workspaceId);
|
|
23
|
+
return {tokens: tokens.map(toProvisionerTokenDto)};
|
|
24
|
+
},
|
|
25
|
+
});
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import {createLeaseTokenAuthMethod, createRunnerSessionAuthMethod} from '@shipfox/api-auth';
|
|
2
|
+
import {
|
|
3
|
+
AUTH_LEASED_JOB,
|
|
4
|
+
AUTH_PROVISIONER_TOKEN,
|
|
5
|
+
AUTH_RUNNER_REGISTRATION_TOKEN,
|
|
6
|
+
AUTH_RUNNER_SESSION,
|
|
7
|
+
AUTH_USER,
|
|
8
|
+
buildUserContext,
|
|
9
|
+
setUserContext,
|
|
10
|
+
type UserContextMembership,
|
|
11
|
+
} from '@shipfox/api-auth-context';
|
|
12
|
+
import type {AuthMethod} from '@shipfox/node-fastify';
|
|
13
|
+
import {ClientError, closeApp, createApp} from '@shipfox/node-fastify';
|
|
14
|
+
import {hashOpaqueToken, tokenTypeParts} from '@shipfox/node-tokens';
|
|
15
|
+
import {eq} from 'drizzle-orm';
|
|
16
|
+
import type {FastifyInstance, FastifyRequest} from 'fastify';
|
|
17
|
+
import {db} from '#db/db.js';
|
|
18
|
+
import {revokeManualRegistrationToken} from '#db/manual-registration-tokens.js';
|
|
19
|
+
import {manualRegistrationTokens} from '#db/schema/manual-registration-tokens.js';
|
|
20
|
+
import {createRunnerRegistrationTokenAuthMethod} from '#presentation/auth/index.js';
|
|
21
|
+
import {manualRegistrationTokenFactory} from '#test/index.js';
|
|
22
|
+
import {runnerRoutes} from './index.js';
|
|
23
|
+
|
|
24
|
+
let authenticatedMemberships: ReadonlyArray<UserContextMembership> = [];
|
|
25
|
+
|
|
26
|
+
const fakeUserAuth: AuthMethod = {
|
|
27
|
+
name: AUTH_USER,
|
|
28
|
+
authenticate: (request: FastifyRequest) => {
|
|
29
|
+
if (request.headers.authorization !== 'Bearer user') {
|
|
30
|
+
throw new ClientError('Invalid user token', 'unauthorized', {status: 401});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
setUserContext(
|
|
34
|
+
request,
|
|
35
|
+
buildUserContext({
|
|
36
|
+
userId: 'user-1',
|
|
37
|
+
email: 'user@example.com',
|
|
38
|
+
memberships: authenticatedMemberships,
|
|
39
|
+
}),
|
|
40
|
+
);
|
|
41
|
+
return Promise.resolve();
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const fakeProvisionerAuth: AuthMethod = {
|
|
46
|
+
name: AUTH_PROVISIONER_TOKEN,
|
|
47
|
+
authenticate: () => Promise.resolve(),
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
describe('manual registration token routes', () => {
|
|
51
|
+
let app: FastifyInstance;
|
|
52
|
+
let workspaceId: string;
|
|
53
|
+
|
|
54
|
+
beforeEach(async () => {
|
|
55
|
+
await closeApp();
|
|
56
|
+
workspaceId = crypto.randomUUID();
|
|
57
|
+
authenticatedMemberships = [{workspaceId, role: 'admin'}];
|
|
58
|
+
app = await createApp({
|
|
59
|
+
auth: [
|
|
60
|
+
fakeUserAuth,
|
|
61
|
+
createRunnerRegistrationTokenAuthMethod(),
|
|
62
|
+
createRunnerSessionAuthMethod(),
|
|
63
|
+
createLeaseTokenAuthMethod(),
|
|
64
|
+
fakeProvisionerAuth,
|
|
65
|
+
],
|
|
66
|
+
routes: runnerRoutes,
|
|
67
|
+
swagger: false,
|
|
68
|
+
});
|
|
69
|
+
await app.ready();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
afterEach(async () => {
|
|
73
|
+
await closeApp();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('uses the expected auth method for each runner route group', () => {
|
|
77
|
+
expect(runnerRoutes[0]?.auth).toBe(AUTH_USER);
|
|
78
|
+
expect(runnerRoutes[1]?.auth).toBe(AUTH_USER);
|
|
79
|
+
expect(runnerRoutes[2]?.auth).toBe(AUTH_RUNNER_REGISTRATION_TOKEN);
|
|
80
|
+
expect(runnerRoutes[3]?.auth).toBe(AUTH_RUNNER_SESSION);
|
|
81
|
+
expect(runnerRoutes[4]?.auth).toBe(AUTH_LEASED_JOB);
|
|
82
|
+
expect(runnerRoutes[5]?.auth).toBe(AUTH_PROVISIONER_TOKEN);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe('GET /workspaces/:workspaceId/runners/manual-registration-tokens', () => {
|
|
86
|
+
it('returns 401 without client auth', async () => {
|
|
87
|
+
const res = await app.inject({
|
|
88
|
+
method: 'GET',
|
|
89
|
+
url: `/workspaces/${workspaceId}/runners/manual-registration-tokens`,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
expect(res.statusCode).toBe(401);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('rejects API-key-only requests', async () => {
|
|
96
|
+
const res = await app.inject({
|
|
97
|
+
method: 'GET',
|
|
98
|
+
url: `/workspaces/${workspaceId}/runners/manual-registration-tokens`,
|
|
99
|
+
headers: {authorization: `Bearer api:${workspaceId}`},
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
expect(res.statusCode).toBe(401);
|
|
103
|
+
expect(res.json().code).toBe('unauthorized');
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('returns 403 when the user is not a workspace member', async () => {
|
|
107
|
+
authenticatedMemberships = [{workspaceId: crypto.randomUUID(), role: 'admin'}];
|
|
108
|
+
|
|
109
|
+
const res = await app.inject({
|
|
110
|
+
method: 'GET',
|
|
111
|
+
url: `/workspaces/${workspaceId}/runners/manual-registration-tokens`,
|
|
112
|
+
headers: {authorization: 'Bearer user'},
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
expect(res.statusCode).toBe(403);
|
|
116
|
+
expect(res.json().code).toBe('forbidden');
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('returns only usable tokens for the workspace', async () => {
|
|
120
|
+
const usable = await manualRegistrationTokenFactory.create({workspaceId, name: 'usable'});
|
|
121
|
+
const expired = await manualRegistrationTokenFactory.create({
|
|
122
|
+
workspaceId,
|
|
123
|
+
name: 'expired',
|
|
124
|
+
expiresAt: new Date(Date.now() - 60_000),
|
|
125
|
+
});
|
|
126
|
+
const revoked = await manualRegistrationTokenFactory.create({workspaceId, name: 'revoked'});
|
|
127
|
+
await manualRegistrationTokenFactory.create({
|
|
128
|
+
workspaceId: crypto.randomUUID(),
|
|
129
|
+
name: 'other workspace',
|
|
130
|
+
});
|
|
131
|
+
await revokeManualRegistrationToken({tokenId: revoked.id, workspaceId});
|
|
132
|
+
|
|
133
|
+
const res = await app.inject({
|
|
134
|
+
method: 'GET',
|
|
135
|
+
url: `/workspaces/${workspaceId}/runners/manual-registration-tokens`,
|
|
136
|
+
headers: {authorization: 'Bearer user'},
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
expect(res.statusCode).toBe(200);
|
|
140
|
+
expect(res.json().manual_registration_tokens.map((token: {id: string}) => token.id)).toEqual([
|
|
141
|
+
usable.id,
|
|
142
|
+
]);
|
|
143
|
+
expect(
|
|
144
|
+
res.json().manual_registration_tokens.map((token: {id: string}) => token.id),
|
|
145
|
+
).not.toContain(expired.id);
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
describe('POST /workspaces/:workspaceId/runners/manual-registration-tokens', () => {
|
|
150
|
+
it('returns 401 without client auth', async () => {
|
|
151
|
+
const res = await app.inject({
|
|
152
|
+
method: 'POST',
|
|
153
|
+
url: `/workspaces/${workspaceId}/runners/manual-registration-tokens`,
|
|
154
|
+
payload: {name: 'builder'},
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
expect(res.statusCode).toBe(401);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('creates a workspace-scoped manual registration token and returns the raw token once', async () => {
|
|
161
|
+
const res = await app.inject({
|
|
162
|
+
method: 'POST',
|
|
163
|
+
url: `/workspaces/${workspaceId}/runners/manual-registration-tokens`,
|
|
164
|
+
headers: {authorization: 'Bearer user'},
|
|
165
|
+
payload: {name: 'builder', ttl_seconds: 3600},
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
expect(res.statusCode).toBe(201);
|
|
169
|
+
const body = res.json();
|
|
170
|
+
expect(body.raw_token.startsWith(`sf_${tokenTypeParts.manualRegistrationToken}_`)).toBe(true);
|
|
171
|
+
expect(body.prefix).toBe(body.raw_token.slice(0, 12));
|
|
172
|
+
expect(body.name).toBe('builder');
|
|
173
|
+
expect(body.workspace_id).toBe(workspaceId);
|
|
174
|
+
expect(body.expires_at).not.toBeNull();
|
|
175
|
+
|
|
176
|
+
const rows = await db()
|
|
177
|
+
.select()
|
|
178
|
+
.from(manualRegistrationTokens)
|
|
179
|
+
.where(eq(manualRegistrationTokens.id, body.id));
|
|
180
|
+
expect(rows[0]?.hashedToken).toBe(hashOpaqueToken(body.raw_token));
|
|
181
|
+
expect(rows[0]?.hashedToken).not.toBe(body.raw_token);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
describe('POST /workspaces/:workspaceId/runners/manual-registration-tokens/:tokenId/revoke', () => {
|
|
186
|
+
it('revokes a token owned by the authenticated workspace', async () => {
|
|
187
|
+
const token = await manualRegistrationTokenFactory.create({workspaceId});
|
|
188
|
+
|
|
189
|
+
const res = await app.inject({
|
|
190
|
+
method: 'POST',
|
|
191
|
+
url: `/workspaces/${workspaceId}/runners/manual-registration-tokens/${token.id}/revoke`,
|
|
192
|
+
headers: {authorization: 'Bearer user'},
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
expect(res.statusCode).toBe(200);
|
|
196
|
+
expect(res.json().id).toBe(token.id);
|
|
197
|
+
expect(res.json().revoked_at).not.toBeNull();
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it('returns 404 for a token owned by another workspace', async () => {
|
|
201
|
+
const token = await manualRegistrationTokenFactory.create({workspaceId: crypto.randomUUID()});
|
|
202
|
+
|
|
203
|
+
const res = await app.inject({
|
|
204
|
+
method: 'POST',
|
|
205
|
+
url: `/workspaces/${workspaceId}/runners/manual-registration-tokens/${token.id}/revoke`,
|
|
206
|
+
headers: {authorization: 'Bearer user'},
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
expect(res.statusCode).toBe(404);
|
|
210
|
+
expect(res.json().code).toBe('not-found');
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
});
|