@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,301 @@
|
|
|
1
|
+
import type {ProvisionedRunner, ProvisionedRunnerState} from '#core/entities/provisioned-runner.js';
|
|
2
|
+
import {
|
|
3
|
+
isTerminalState,
|
|
4
|
+
listActiveProvisionedRunners,
|
|
5
|
+
listActiveRunningJobExecutions,
|
|
6
|
+
type ProvisionedRunnerReportEvent,
|
|
7
|
+
reconcileProvisionedRunners as reconcileProvisionedRunnersDb,
|
|
8
|
+
reportProvisionedRunners as reportProvisionedRunnersDb,
|
|
9
|
+
} from '#db/index.js';
|
|
10
|
+
import type {
|
|
11
|
+
ActiveRunningJobExecution,
|
|
12
|
+
ProvisionedRunnerBoundJobExecution,
|
|
13
|
+
} from '#db/job-executions.js';
|
|
14
|
+
import {
|
|
15
|
+
provisionedRunnerAbsentTerminatedCount,
|
|
16
|
+
provisionedRunnerReconcileCallCount,
|
|
17
|
+
provisionedRunnerReportCount,
|
|
18
|
+
provisionedRunnerTerminateIntentHonoredCount,
|
|
19
|
+
provisionedRunnerTerminateIntentIssuedCount,
|
|
20
|
+
reservationReleasedCount,
|
|
21
|
+
} from '#metrics/instance.js';
|
|
22
|
+
import {config} from '../config.js';
|
|
23
|
+
|
|
24
|
+
export interface ReportProvisionedRunnersParams {
|
|
25
|
+
workspaceId: string;
|
|
26
|
+
provisionerId: string;
|
|
27
|
+
events: ProvisionedRunnerReportEvent[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface ReportProvisionedRunnersResult {
|
|
31
|
+
accepted: number;
|
|
32
|
+
reservationsReleased: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface ReconcileProvisionedRunnersParams {
|
|
36
|
+
workspaceId: string;
|
|
37
|
+
provisionerId: string;
|
|
38
|
+
observedProvisionedRunnerIds: string[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type ReconcileDesiredIntent = 'keep' | 'terminate';
|
|
42
|
+
type ReconcileDesiredIntentReason = 'job-cancelled' | 'terminal-state';
|
|
43
|
+
|
|
44
|
+
export interface ReconciledBoundJobExecution {
|
|
45
|
+
jobId: string;
|
|
46
|
+
jobExecutionId: string;
|
|
47
|
+
workflowRunAttemptId: string;
|
|
48
|
+
lastHeartbeatAt: Date;
|
|
49
|
+
cancellationRequestedAt: Date | null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface ReconciledProvisionedRunner {
|
|
53
|
+
provisionedRunnerId: string;
|
|
54
|
+
state: ProvisionedRunnerState | null;
|
|
55
|
+
reservationId: string | null;
|
|
56
|
+
runnerSessionId: string | null;
|
|
57
|
+
boundJobExecution: ReconciledBoundJobExecution | null;
|
|
58
|
+
desiredIntent: ReconcileDesiredIntent;
|
|
59
|
+
desiredIntentReason: ReconcileDesiredIntentReason | null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface ReconcileProvisionedRunnersResult {
|
|
63
|
+
runners: ReconciledProvisionedRunner[];
|
|
64
|
+
terminatedAbsentProvisionedRunnerIds: string[];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export type ActiveRunnerState = 'starting' | 'running' | 'stopping' | 'busy';
|
|
68
|
+
|
|
69
|
+
export interface ActiveRunner {
|
|
70
|
+
runnerSessionId: string | null;
|
|
71
|
+
provisionedRunnerId: string | null;
|
|
72
|
+
provisionerId: string | null;
|
|
73
|
+
state: ActiveRunnerState;
|
|
74
|
+
labels: string[];
|
|
75
|
+
templateKey: string | null;
|
|
76
|
+
providerKind: string | null;
|
|
77
|
+
jobId: string | null;
|
|
78
|
+
workflowRunAttemptId: string | null;
|
|
79
|
+
projectId: string | null;
|
|
80
|
+
reportedAt: Date | null;
|
|
81
|
+
lastHeartbeatAt: Date | null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export async function reportProvisionedRunners(
|
|
85
|
+
params: ReportProvisionedRunnersParams,
|
|
86
|
+
): Promise<ReportProvisionedRunnersResult> {
|
|
87
|
+
const result = await reportProvisionedRunnersDb(params);
|
|
88
|
+
|
|
89
|
+
for (const event of params.events) {
|
|
90
|
+
provisionedRunnerReportCount.add(1, {state: event.state});
|
|
91
|
+
}
|
|
92
|
+
for (const intent of result.terminateIntentsHonored) {
|
|
93
|
+
provisionedRunnerTerminateIntentHonoredCount.add(1, {reason: intent.reason});
|
|
94
|
+
}
|
|
95
|
+
if (result.reservationsReleased > 0) reservationReleasedCount.add(result.reservationsReleased);
|
|
96
|
+
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export async function reconcileProvisionedRunners(
|
|
101
|
+
params: ReconcileProvisionedRunnersParams,
|
|
102
|
+
): Promise<ReconcileProvisionedRunnersResult> {
|
|
103
|
+
const result = await reconcileProvisionedRunnersDb({
|
|
104
|
+
...params,
|
|
105
|
+
terminateGraceSeconds: config.RUNNER_RECONCILE_TERMINATE_GRACE_SECONDS,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
if (result.reservationsReleased > 0) reservationReleasedCount.add(result.reservationsReleased);
|
|
109
|
+
provisionedRunnerReconcileCallCount.add(1);
|
|
110
|
+
if (result.absentIds.length > 0)
|
|
111
|
+
provisionedRunnerAbsentTerminatedCount.add(result.absentIds.length);
|
|
112
|
+
|
|
113
|
+
const runners = reconcileProvisionedRunnersFromDbResult({
|
|
114
|
+
observedProvisionedRunnerIds: params.observedProvisionedRunnerIds,
|
|
115
|
+
observedRows: result.observedRows,
|
|
116
|
+
boundJobExecutionsByProvisionedRunnerId: result.boundJobExecutionsByProvisionedRunnerId,
|
|
117
|
+
});
|
|
118
|
+
for (const runner of runners) {
|
|
119
|
+
if (runner.desiredIntentReason) {
|
|
120
|
+
provisionedRunnerTerminateIntentIssuedCount.add(1, {
|
|
121
|
+
surface: 'reconcile',
|
|
122
|
+
reason: runner.desiredIntentReason,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return {
|
|
128
|
+
runners,
|
|
129
|
+
terminatedAbsentProvisionedRunnerIds: result.absentIds,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function reconcileProvisionedRunnersFromDbResult(params: {
|
|
134
|
+
observedProvisionedRunnerIds: string[];
|
|
135
|
+
observedRows: ProvisionedRunner[];
|
|
136
|
+
boundJobExecutionsByProvisionedRunnerId: Map<string, ProvisionedRunnerBoundJobExecution>;
|
|
137
|
+
}): ReconciledProvisionedRunner[] {
|
|
138
|
+
const rowsByProvisionedRunnerId = new Map(
|
|
139
|
+
params.observedRows.map((row) => [row.provisionedRunnerId, row]),
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
return params.observedProvisionedRunnerIds.map((provisionedRunnerId) => {
|
|
143
|
+
const row = rowsByProvisionedRunnerId.get(provisionedRunnerId);
|
|
144
|
+
const boundJobExecution =
|
|
145
|
+
params.boundJobExecutionsByProvisionedRunnerId.get(provisionedRunnerId);
|
|
146
|
+
|
|
147
|
+
const desiredIntentReason = getDesiredIntentReason(row, boundJobExecution);
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
provisionedRunnerId,
|
|
151
|
+
state: row?.state ?? null,
|
|
152
|
+
reservationId: row?.reservationId ?? null,
|
|
153
|
+
runnerSessionId: row?.runnerSessionId ?? null,
|
|
154
|
+
boundJobExecution: boundJobExecution
|
|
155
|
+
? toReconciledBoundJobExecution(boundJobExecution)
|
|
156
|
+
: null,
|
|
157
|
+
desiredIntent: desiredIntentReason ? 'terminate' : 'keep',
|
|
158
|
+
desiredIntentReason,
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export async function listActiveRunners(params: {workspaceId: string}): Promise<ActiveRunner[]> {
|
|
164
|
+
const [provisionedRunnerRows, jobExecutionRows] = await Promise.all([
|
|
165
|
+
listActiveProvisionedRunners({
|
|
166
|
+
workspaceId: params.workspaceId,
|
|
167
|
+
windowSeconds: config.RUNNER_ACTIVE_WINDOW_SECONDS,
|
|
168
|
+
}),
|
|
169
|
+
listActiveRunningJobExecutions({
|
|
170
|
+
workspaceId: params.workspaceId,
|
|
171
|
+
windowSeconds: config.RUNNER_ACTIVE_WINDOW_SECONDS,
|
|
172
|
+
}),
|
|
173
|
+
]);
|
|
174
|
+
|
|
175
|
+
return mergeActiveRunners(provisionedRunnerRows, jobExecutionRows);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function toReconciledBoundJobExecution(
|
|
179
|
+
jobExecution: ProvisionedRunnerBoundJobExecution,
|
|
180
|
+
): ReconciledBoundJobExecution {
|
|
181
|
+
return {
|
|
182
|
+
jobId: jobExecution.jobId,
|
|
183
|
+
jobExecutionId: jobExecution.jobExecutionId,
|
|
184
|
+
workflowRunAttemptId: jobExecution.workflowRunAttemptId,
|
|
185
|
+
lastHeartbeatAt: jobExecution.lastHeartbeatAt,
|
|
186
|
+
cancellationRequestedAt: jobExecution.cancellationRequestedAt,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function desiredIntent(
|
|
191
|
+
row: ProvisionedRunner | undefined,
|
|
192
|
+
boundJobExecution: ProvisionedRunnerBoundJobExecution | undefined,
|
|
193
|
+
): ReconcileDesiredIntent {
|
|
194
|
+
return getDesiredIntentReason(row, boundJobExecution) ? 'terminate' : 'keep';
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function getDesiredIntentReason(
|
|
198
|
+
row: ProvisionedRunner | undefined,
|
|
199
|
+
boundJobExecution: ProvisionedRunnerBoundJobExecution | undefined,
|
|
200
|
+
): ReconcileDesiredIntentReason | null {
|
|
201
|
+
if (!row) return null;
|
|
202
|
+
if (isTerminalState(row.state)) return 'terminal-state';
|
|
203
|
+
if (boundJobExecution?.cancellationRequestedAt) return 'job-cancelled';
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function mergeActiveRunners(
|
|
208
|
+
provisionedRunners: ProvisionedRunner[],
|
|
209
|
+
jobExecutions: ActiveRunningJobExecution[],
|
|
210
|
+
): ActiveRunner[] {
|
|
211
|
+
const jobExecutionsByRunnerSessionId = new Map<string, ActiveRunningJobExecution[]>();
|
|
212
|
+
const jobExecutionsByProvisionedRunnerId = new Map<string, ActiveRunningJobExecution[]>();
|
|
213
|
+
for (const jobExecution of jobExecutions) {
|
|
214
|
+
const runnerJobExecutions =
|
|
215
|
+
jobExecutionsByRunnerSessionId.get(jobExecution.runnerSessionId) ?? [];
|
|
216
|
+
runnerJobExecutions.push(jobExecution);
|
|
217
|
+
jobExecutionsByRunnerSessionId.set(jobExecution.runnerSessionId, runnerJobExecutions);
|
|
218
|
+
|
|
219
|
+
if (jobExecution.provisionerId && jobExecution.provisionedRunnerId) {
|
|
220
|
+
const key = provisionedRunnerKey(
|
|
221
|
+
jobExecution.provisionerId,
|
|
222
|
+
jobExecution.provisionedRunnerId,
|
|
223
|
+
);
|
|
224
|
+
const provisionedRunnerJobExecutions = jobExecutionsByProvisionedRunnerId.get(key) ?? [];
|
|
225
|
+
provisionedRunnerJobExecutions.push(jobExecution);
|
|
226
|
+
jobExecutionsByProvisionedRunnerId.set(key, provisionedRunnerJobExecutions);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const merged: ActiveRunner[] = [];
|
|
231
|
+
const usedJobExecutionIds = new Set<string>();
|
|
232
|
+
|
|
233
|
+
for (const provisionedRunner of provisionedRunners) {
|
|
234
|
+
const provisionedRunnerJobExecutions =
|
|
235
|
+
jobExecutionsByProvisionedRunnerId.get(
|
|
236
|
+
provisionedRunnerKey(
|
|
237
|
+
provisionedRunner.provisionerId,
|
|
238
|
+
provisionedRunner.provisionedRunnerId,
|
|
239
|
+
),
|
|
240
|
+
) ??
|
|
241
|
+
(provisionedRunner.runnerSessionId
|
|
242
|
+
? jobExecutionsByRunnerSessionId.get(provisionedRunner.runnerSessionId)
|
|
243
|
+
: undefined);
|
|
244
|
+
if (!provisionedRunnerJobExecutions || provisionedRunnerJobExecutions.length === 0) {
|
|
245
|
+
merged.push(toActiveRunner(provisionedRunner, undefined));
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
let emitted = false;
|
|
250
|
+
for (const jobExecution of provisionedRunnerJobExecutions) {
|
|
251
|
+
if (usedJobExecutionIds.has(jobExecution.jobExecutionId)) continue;
|
|
252
|
+
usedJobExecutionIds.add(jobExecution.jobExecutionId);
|
|
253
|
+
merged.push(toActiveRunner(provisionedRunner, jobExecution));
|
|
254
|
+
emitted = true;
|
|
255
|
+
}
|
|
256
|
+
if (!emitted) merged.push(toActiveRunner(provisionedRunner, undefined));
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
for (const jobExecution of jobExecutions) {
|
|
260
|
+
if (usedJobExecutionIds.has(jobExecution.jobExecutionId)) continue;
|
|
261
|
+
merged.push(toActiveRunner(undefined, jobExecution));
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return merged.sort(compareActiveRunners);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function provisionedRunnerKey(provisionerId: string, provisionedRunnerId: string): string {
|
|
268
|
+
return `${provisionerId}:${provisionedRunnerId}`;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function toActiveRunner(
|
|
272
|
+
provisionedRunner: ProvisionedRunner | undefined,
|
|
273
|
+
jobExecution: ActiveRunningJobExecution | undefined,
|
|
274
|
+
): ActiveRunner {
|
|
275
|
+
return {
|
|
276
|
+
runnerSessionId: provisionedRunner?.runnerSessionId ?? jobExecution?.runnerSessionId ?? null,
|
|
277
|
+
provisionedRunnerId:
|
|
278
|
+
provisionedRunner?.provisionedRunnerId ?? jobExecution?.provisionedRunnerId ?? null,
|
|
279
|
+
provisionerId: provisionedRunner?.provisionerId ?? jobExecution?.provisionerId ?? null,
|
|
280
|
+
state: jobExecution ? 'busy' : toActiveRunnerState(provisionedRunner?.state ?? 'running'),
|
|
281
|
+
labels: provisionedRunner?.labels ?? jobExecution?.runnerLabels ?? [],
|
|
282
|
+
templateKey: provisionedRunner?.templateKey ?? null,
|
|
283
|
+
providerKind: provisionedRunner?.providerKind ?? null,
|
|
284
|
+
jobId: jobExecution?.jobId ?? null,
|
|
285
|
+
workflowRunAttemptId: jobExecution?.workflowRunAttemptId ?? null,
|
|
286
|
+
projectId: jobExecution?.projectId ?? null,
|
|
287
|
+
reportedAt: provisionedRunner?.reportedAt ?? null,
|
|
288
|
+
lastHeartbeatAt: jobExecution?.lastHeartbeatAt ?? null,
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function toActiveRunnerState(state: ProvisionedRunnerState): ActiveRunnerState {
|
|
293
|
+
if (state === 'starting' || state === 'stopping') return state;
|
|
294
|
+
return 'running';
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function compareActiveRunners(a: ActiveRunner, b: ActiveRunner): number {
|
|
298
|
+
const aTime = Math.max(a.lastHeartbeatAt?.getTime() ?? 0, a.reportedAt?.getTime() ?? 0);
|
|
299
|
+
const bTime = Math.max(b.lastHeartbeatAt?.getTime() ?? 0, b.reportedAt?.getTime() ?? 0);
|
|
300
|
+
return bTime - aTime;
|
|
301
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {hashOpaqueToken, tokenTypeParts} from '@shipfox/node-tokens';
|
|
2
|
+
import {eq} from 'drizzle-orm';
|
|
3
|
+
import {db} from '#db/db.js';
|
|
4
|
+
import {provisionerTokens} from '#db/schema/provisioner-tokens.js';
|
|
5
|
+
import {provisionerTokenFactory} from '#test/index.js';
|
|
6
|
+
import {
|
|
7
|
+
createWorkspaceProvisionerToken,
|
|
8
|
+
listUsableProvisionerTokens,
|
|
9
|
+
revokeWorkspaceProvisionerToken,
|
|
10
|
+
} from './provisioner-tokens.js';
|
|
11
|
+
|
|
12
|
+
describe('provisioner token core', () => {
|
|
13
|
+
it('creates a workspace provisioner token and stores only the hash', async () => {
|
|
14
|
+
const workspaceId = crypto.randomUUID();
|
|
15
|
+
const createdByUserId = crypto.randomUUID();
|
|
16
|
+
|
|
17
|
+
const result = await createWorkspaceProvisionerToken({
|
|
18
|
+
workspaceId,
|
|
19
|
+
createdByUserId,
|
|
20
|
+
name: 'local provisioner',
|
|
21
|
+
ttlSeconds: 3600,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
expect(result.rawToken.startsWith(`sf_${tokenTypeParts.provisionerToken}_`)).toBe(true);
|
|
25
|
+
expect(result.token.workspaceId).toBe(workspaceId);
|
|
26
|
+
expect(result.token.createdByUserId).toBe(createdByUserId);
|
|
27
|
+
expect(result.token.expiresAt).toBeInstanceOf(Date);
|
|
28
|
+
expect(result.token.prefix).toBe(result.rawToken.slice(0, 12));
|
|
29
|
+
const rows = await db()
|
|
30
|
+
.select()
|
|
31
|
+
.from(provisionerTokens)
|
|
32
|
+
.where(eq(provisionerTokens.id, result.token.id));
|
|
33
|
+
expect(rows[0]?.hashedToken).toBe(hashOpaqueToken(result.rawToken));
|
|
34
|
+
expect(rows[0]?.hashedToken).not.toBe(result.rawToken);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('lists usable tokens and excludes revoked tokens after revoke', async () => {
|
|
38
|
+
const workspaceId = crypto.randomUUID();
|
|
39
|
+
const token = await provisionerTokenFactory.create({workspaceId});
|
|
40
|
+
const revokedByUserId = crypto.randomUUID();
|
|
41
|
+
|
|
42
|
+
const beforeRevoke = await listUsableProvisionerTokens(workspaceId);
|
|
43
|
+
await revokeWorkspaceProvisionerToken({tokenId: token.id, workspaceId, revokedByUserId});
|
|
44
|
+
const afterRevoke = await listUsableProvisionerTokens(workspaceId);
|
|
45
|
+
|
|
46
|
+
expect(beforeRevoke.map((item) => item.id)).toEqual([token.id]);
|
|
47
|
+
expect(afterRevoke).toEqual([]);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('throws when revoking a token outside the workspace', async () => {
|
|
51
|
+
const token = await provisionerTokenFactory.create({workspaceId: crypto.randomUUID()});
|
|
52
|
+
|
|
53
|
+
const result = revokeWorkspaceProvisionerToken({
|
|
54
|
+
tokenId: token.id,
|
|
55
|
+
workspaceId: crypto.randomUUID(),
|
|
56
|
+
revokedByUserId: crypto.randomUUID(),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
await expect(result).rejects.toThrow(`Provisioner token not found: ${token.id}`);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {extractDisplayPrefix, generateOpaqueToken, hashOpaqueToken} from '@shipfox/node-tokens';
|
|
2
|
+
import {
|
|
3
|
+
createProvisionerToken,
|
|
4
|
+
listActiveProvisionerTokens,
|
|
5
|
+
listUsableProvisionerTokensByWorkspaceId,
|
|
6
|
+
revokeProvisionerToken,
|
|
7
|
+
} from '#db/provisioner-tokens.js';
|
|
8
|
+
import {config} from '../config.js';
|
|
9
|
+
import type {ActiveProvisionerToken, ProvisionerToken} from './entities/provisioner-token.js';
|
|
10
|
+
import {ProvisionerTokenNotFoundError} from './errors.js';
|
|
11
|
+
|
|
12
|
+
export interface CreateWorkspaceProvisionerTokenParams {
|
|
13
|
+
workspaceId: string;
|
|
14
|
+
createdByUserId: string;
|
|
15
|
+
name?: string | undefined;
|
|
16
|
+
ttlSeconds?: number | undefined;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface CreateWorkspaceProvisionerTokenResult {
|
|
20
|
+
token: ProvisionerToken;
|
|
21
|
+
rawToken: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function createWorkspaceProvisionerToken(
|
|
25
|
+
params: CreateWorkspaceProvisionerTokenParams,
|
|
26
|
+
): Promise<CreateWorkspaceProvisionerTokenResult> {
|
|
27
|
+
const rawToken = generateOpaqueToken('provisionerToken');
|
|
28
|
+
const expiresAt = params.ttlSeconds ? new Date(Date.now() + params.ttlSeconds * 1000) : undefined;
|
|
29
|
+
|
|
30
|
+
const token = await createProvisionerToken({
|
|
31
|
+
workspaceId: params.workspaceId,
|
|
32
|
+
hashedToken: hashOpaqueToken(rawToken),
|
|
33
|
+
prefix: extractDisplayPrefix(rawToken),
|
|
34
|
+
name: params.name,
|
|
35
|
+
createdByUserId: params.createdByUserId,
|
|
36
|
+
expiresAt,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return {token, rawToken};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function listUsableProvisionerTokens(workspaceId: string): Promise<ProvisionerToken[]> {
|
|
43
|
+
return listUsableProvisionerTokensByWorkspaceId(workspaceId);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function listActiveProvisioners(workspaceId: string): Promise<ActiveProvisionerToken[]> {
|
|
47
|
+
return listActiveProvisionerTokens({
|
|
48
|
+
workspaceId,
|
|
49
|
+
windowSeconds: config.PROVISIONER_ACTIVE_WINDOW_SECONDS,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export async function revokeWorkspaceProvisionerToken(params: {
|
|
54
|
+
tokenId: string;
|
|
55
|
+
workspaceId: string;
|
|
56
|
+
revokedByUserId: string;
|
|
57
|
+
}): Promise<ProvisionerToken> {
|
|
58
|
+
const token = await revokeProvisionerToken(params);
|
|
59
|
+
if (!token) throw new ProvisionerTokenNotFoundError(params.tokenId);
|
|
60
|
+
return token;
|
|
61
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import {vi} from '@shipfox/vitest/vi';
|
|
2
|
+
import {eq, sql} from 'drizzle-orm';
|
|
3
|
+
import {db} from '#db/db.js';
|
|
4
|
+
import {runnersRateLimits} from '#db/schema/rate-limits.js';
|
|
5
|
+
import {
|
|
6
|
+
checkRunnersRateLimit,
|
|
7
|
+
hashRunnersRateLimitIdentifier,
|
|
8
|
+
RunnersRateLimitUnavailableError,
|
|
9
|
+
} from './rate-limit.js';
|
|
10
|
+
|
|
11
|
+
const HMAC_HEX_PATTERN = /^[a-f0-9]{64}$/;
|
|
12
|
+
|
|
13
|
+
describe('checkRunnersRateLimit', () => {
|
|
14
|
+
it('hashes identifiers without storing the raw identifier', async () => {
|
|
15
|
+
const identifier = `provisioner-${crypto.randomUUID()}`;
|
|
16
|
+
const identifierHmac = hashRunnersRateLimitIdentifier({
|
|
17
|
+
action: 'provisioner-mint',
|
|
18
|
+
scope: 'provisioner',
|
|
19
|
+
identifier,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
await checkRunnersRateLimit({
|
|
23
|
+
action: 'provisioner-mint',
|
|
24
|
+
scope: 'provisioner',
|
|
25
|
+
identifier,
|
|
26
|
+
limit: 1,
|
|
27
|
+
windowSeconds: 60,
|
|
28
|
+
now: new Date('2026-06-23T00:00:10Z'),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const rows = await db()
|
|
32
|
+
.select({identifierHmac: runnersRateLimits.identifierHmac})
|
|
33
|
+
.from(runnersRateLimits)
|
|
34
|
+
.where(eq(runnersRateLimits.identifierHmac, identifierHmac));
|
|
35
|
+
expect(identifierHmac).toMatch(HMAC_HEX_PATTERN);
|
|
36
|
+
expect(identifierHmac).not.toContain(identifier);
|
|
37
|
+
expect(rows).toEqual([{identifierHmac}]);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('rejects the first over-limit attempt with retry-after seconds', async () => {
|
|
41
|
+
const identifier = `ephemeral-${crypto.randomUUID()}`;
|
|
42
|
+
const now = new Date('2026-06-23T00:00:10Z');
|
|
43
|
+
|
|
44
|
+
await checkRunnersRateLimit({
|
|
45
|
+
action: 'ephemeral-register',
|
|
46
|
+
scope: 'ephemeral-token',
|
|
47
|
+
identifier,
|
|
48
|
+
limit: 2,
|
|
49
|
+
windowSeconds: 60,
|
|
50
|
+
now,
|
|
51
|
+
});
|
|
52
|
+
await checkRunnersRateLimit({
|
|
53
|
+
action: 'ephemeral-register',
|
|
54
|
+
scope: 'ephemeral-token',
|
|
55
|
+
identifier,
|
|
56
|
+
limit: 2,
|
|
57
|
+
windowSeconds: 60,
|
|
58
|
+
now,
|
|
59
|
+
});
|
|
60
|
+
const result = checkRunnersRateLimit({
|
|
61
|
+
action: 'ephemeral-register',
|
|
62
|
+
scope: 'ephemeral-token',
|
|
63
|
+
identifier,
|
|
64
|
+
limit: 2,
|
|
65
|
+
windowSeconds: 60,
|
|
66
|
+
now,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
await expect(result).rejects.toMatchObject({
|
|
70
|
+
name: 'RunnersRateLimitExceededError',
|
|
71
|
+
retryAfterSeconds: 50,
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('fails closed when the limiter query times out', async () => {
|
|
76
|
+
const identifier = `provisioner-${crypto.randomUUID()}`;
|
|
77
|
+
const identifierHmac = hashRunnersRateLimitIdentifier({
|
|
78
|
+
action: 'provisioner-mint',
|
|
79
|
+
scope: 'provisioner',
|
|
80
|
+
identifier,
|
|
81
|
+
});
|
|
82
|
+
await db()
|
|
83
|
+
.insert(runnersRateLimits)
|
|
84
|
+
.values({
|
|
85
|
+
action: 'provisioner-mint',
|
|
86
|
+
scope: 'provisioner',
|
|
87
|
+
identifierHmac,
|
|
88
|
+
windowStart: new Date('2026-06-23T00:03:00Z'),
|
|
89
|
+
count: 1,
|
|
90
|
+
expiresAt: new Date('2026-06-23T00:04:00Z'),
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
await db().transaction(async (tx) => {
|
|
94
|
+
await tx.execute(sql`
|
|
95
|
+
SELECT 1
|
|
96
|
+
FROM runners_rate_limits
|
|
97
|
+
WHERE identifier_hmac = ${identifierHmac}
|
|
98
|
+
FOR UPDATE
|
|
99
|
+
`);
|
|
100
|
+
const result = checkRunnersRateLimit({
|
|
101
|
+
action: 'provisioner-mint',
|
|
102
|
+
scope: 'provisioner',
|
|
103
|
+
identifier,
|
|
104
|
+
limit: 1,
|
|
105
|
+
windowSeconds: 60,
|
|
106
|
+
now: new Date('2026-06-23T00:03:30Z'),
|
|
107
|
+
timeoutMs: 10,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
await expect(result).rejects.toBeInstanceOf(RunnersRateLimitUnavailableError);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('uses the configured shared identifier secret when present', async () => {
|
|
115
|
+
vi.resetModules();
|
|
116
|
+
vi.doMock('#config.js', () => ({
|
|
117
|
+
config: {
|
|
118
|
+
RATE_LIMIT_IDENTIFIER_SECRET: 'configured-secret',
|
|
119
|
+
RUNNERS_RATE_LIMIT_TIMEOUT_MS: 250,
|
|
120
|
+
},
|
|
121
|
+
}));
|
|
122
|
+
vi.doMock('@shipfox/api-auth/config', () => ({
|
|
123
|
+
config: {
|
|
124
|
+
AUTH_JWT_SECRET: 'jwt-secret',
|
|
125
|
+
},
|
|
126
|
+
}));
|
|
127
|
+
|
|
128
|
+
try {
|
|
129
|
+
const configuredSecretModule = await import('./rate-limit.js');
|
|
130
|
+
const configuredSecretHash = configuredSecretModule.hashRunnersRateLimitIdentifier({
|
|
131
|
+
action: 'provisioner-mint',
|
|
132
|
+
scope: 'provisioner',
|
|
133
|
+
identifier: 'provisioner-token-id',
|
|
134
|
+
});
|
|
135
|
+
vi.doMock('#config.js', () => ({
|
|
136
|
+
config: {
|
|
137
|
+
RATE_LIMIT_IDENTIFIER_SECRET: undefined,
|
|
138
|
+
RUNNERS_RATE_LIMIT_TIMEOUT_MS: 250,
|
|
139
|
+
},
|
|
140
|
+
}));
|
|
141
|
+
vi.resetModules();
|
|
142
|
+
const derivedSecretModule = await import('./rate-limit.js');
|
|
143
|
+
const derivedSecretHash = derivedSecretModule.hashRunnersRateLimitIdentifier({
|
|
144
|
+
action: 'provisioner-mint',
|
|
145
|
+
scope: 'provisioner',
|
|
146
|
+
identifier: 'provisioner-token-id',
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
expect(configuredSecretHash).toMatch(HMAC_HEX_PATTERN);
|
|
150
|
+
expect(derivedSecretHash).toMatch(HMAC_HEX_PATTERN);
|
|
151
|
+
expect(configuredSecretHash).not.toBe(derivedSecretHash);
|
|
152
|
+
} finally {
|
|
153
|
+
vi.doUnmock('#config.js');
|
|
154
|
+
vi.doUnmock('@shipfox/api-auth/config');
|
|
155
|
+
vi.resetModules();
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
});
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import {createHmac} from 'node:crypto';
|
|
2
|
+
import {config as authConfig} from '@shipfox/api-auth/config';
|
|
3
|
+
import {
|
|
4
|
+
checkRateLimit,
|
|
5
|
+
hashRateLimitIdentifier,
|
|
6
|
+
RateLimitExceededError,
|
|
7
|
+
type RateLimitOutcome,
|
|
8
|
+
type RateLimitPolicy,
|
|
9
|
+
RateLimitUnavailableError,
|
|
10
|
+
} from '@shipfox/node-rate-limit';
|
|
11
|
+
import {config} from '#config.js';
|
|
12
|
+
import {consumeRunnersRateLimit, pruneExpiredRunnersRateLimits} from '#db/rate-limits.js';
|
|
13
|
+
import {recordRunnersRateLimitCheck, recordRunnersRateLimitPruneFailure} from '#metrics/index.js';
|
|
14
|
+
|
|
15
|
+
export type RunnersRateLimitAction = 'provisioner-mint' | 'ephemeral-register';
|
|
16
|
+
export type RunnersRateLimitScope = 'provisioner' | 'ephemeral-token';
|
|
17
|
+
export type RunnersRateLimitOutcome = RateLimitOutcome;
|
|
18
|
+
export type RunnersRateLimitPolicy = RateLimitPolicy;
|
|
19
|
+
|
|
20
|
+
export interface CheckRunnersRateLimitParams extends RunnersRateLimitPolicy {
|
|
21
|
+
action: RunnersRateLimitAction;
|
|
22
|
+
scope: RunnersRateLimitScope;
|
|
23
|
+
identifier: string;
|
|
24
|
+
now?: Date | undefined;
|
|
25
|
+
timeoutMs?: number | undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export class RunnersRateLimitExceededError extends RateLimitExceededError<
|
|
29
|
+
RunnersRateLimitAction,
|
|
30
|
+
RunnersRateLimitScope
|
|
31
|
+
> {
|
|
32
|
+
constructor(params: {
|
|
33
|
+
action: RunnersRateLimitAction;
|
|
34
|
+
scope: RunnersRateLimitScope;
|
|
35
|
+
retryAfterSeconds: number;
|
|
36
|
+
identifierHmacPrefix: string;
|
|
37
|
+
}) {
|
|
38
|
+
super(params);
|
|
39
|
+
this.name = 'RunnersRateLimitExceededError';
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export class RunnersRateLimitUnavailableError extends RateLimitUnavailableError<
|
|
44
|
+
RunnersRateLimitAction,
|
|
45
|
+
RunnersRateLimitScope
|
|
46
|
+
> {
|
|
47
|
+
constructor(params: {
|
|
48
|
+
action: RunnersRateLimitAction;
|
|
49
|
+
scope: RunnersRateLimitScope;
|
|
50
|
+
identifierHmacPrefix: string;
|
|
51
|
+
cause: unknown;
|
|
52
|
+
}) {
|
|
53
|
+
super(params);
|
|
54
|
+
this.name = 'RunnersRateLimitUnavailableError';
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const IDENTIFIER_HASH_DOMAIN = 'shipfox.runners.rate-limit.identifier.v1';
|
|
59
|
+
const IDENTIFIER_SECRET_DERIVATION_DOMAIN = 'shipfox.runners.rate-limit.identifier-secret.v1';
|
|
60
|
+
|
|
61
|
+
export function hashRunnersRateLimitIdentifier(params: {
|
|
62
|
+
action: RunnersRateLimitAction;
|
|
63
|
+
scope: RunnersRateLimitScope;
|
|
64
|
+
identifier: string;
|
|
65
|
+
}): string {
|
|
66
|
+
return hashRateLimitIdentifier({
|
|
67
|
+
action: params.action,
|
|
68
|
+
scope: params.scope,
|
|
69
|
+
identifier: params.identifier,
|
|
70
|
+
secret: effectiveIdentifierSecret(),
|
|
71
|
+
domain: IDENTIFIER_HASH_DOMAIN,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export async function checkRunnersRateLimit(params: CheckRunnersRateLimitParams): Promise<void> {
|
|
76
|
+
try {
|
|
77
|
+
await checkRateLimit({
|
|
78
|
+
action: params.action,
|
|
79
|
+
scope: params.scope,
|
|
80
|
+
identifier: params.identifier,
|
|
81
|
+
limit: params.limit,
|
|
82
|
+
windowSeconds: params.windowSeconds,
|
|
83
|
+
identifierSecret: effectiveIdentifierSecret(),
|
|
84
|
+
identifierHashDomain: IDENTIFIER_HASH_DOMAIN,
|
|
85
|
+
consume: consumeRunnersRateLimit,
|
|
86
|
+
prune: pruneExpiredRunnersRateLimits,
|
|
87
|
+
onCheck: recordRunnersRateLimitCheck,
|
|
88
|
+
onPruneFailure: recordRunnersRateLimitPruneFailure,
|
|
89
|
+
now: params.now,
|
|
90
|
+
timeoutMs: params.timeoutMs ?? config.RUNNERS_RATE_LIMIT_TIMEOUT_MS,
|
|
91
|
+
});
|
|
92
|
+
} catch (error) {
|
|
93
|
+
if (error instanceof RateLimitExceededError) {
|
|
94
|
+
throw new RunnersRateLimitExceededError({
|
|
95
|
+
action: error.action,
|
|
96
|
+
scope: error.scope,
|
|
97
|
+
retryAfterSeconds: error.retryAfterSeconds,
|
|
98
|
+
identifierHmacPrefix: error.identifierHmacPrefix,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
if (error instanceof RateLimitUnavailableError) {
|
|
102
|
+
throw new RunnersRateLimitUnavailableError({
|
|
103
|
+
action: error.action,
|
|
104
|
+
scope: error.scope,
|
|
105
|
+
identifierHmacPrefix: error.identifierHmacPrefix,
|
|
106
|
+
cause: error.cause,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
throw error;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function effectiveIdentifierSecret(): Buffer | string {
|
|
114
|
+
if (config.RATE_LIMIT_IDENTIFIER_SECRET) {
|
|
115
|
+
return config.RATE_LIMIT_IDENTIFIER_SECRET;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return createHmac('sha256', authConfig.AUTH_JWT_SECRET)
|
|
119
|
+
.update(IDENTIFIER_SECRET_DERIVATION_DOMAIN)
|
|
120
|
+
.digest();
|
|
121
|
+
}
|