@codemation/host 0.7.0 → 0.9.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/CHANGELOG.md +89 -0
- package/LICENSE +37 -1
- package/dist/{ApiPaths-Dv1dcHu_.js → ApiPaths-DCvrlIjg.js} +12 -1
- package/dist/{ApiPaths-Dv1dcHu_.js.map → ApiPaths-DCvrlIjg.js.map} +1 -1
- package/dist/{AppConfigFactory-Cx4qQvRk.js → AppConfigFactory-D4LL1aOR.js} +77 -297
- package/dist/AppConfigFactory-D4LL1aOR.js.map +1 -0
- package/dist/{AppConfigFactory-DnLoQ9Li.d.ts → AppConfigFactory-DncmwCD1.d.ts} +2918 -199
- package/dist/{AppContainerFactory-DqKYCRNP.js → AppContainerFactory-jpYXGZGe.js} +1733 -475
- package/dist/AppContainerFactory-jpYXGZGe.js.map +1 -0
- package/dist/{CodemationAppContext-CKVv9W9q.d.ts → CodemationAppContext-K51b7oXe.d.ts} +9 -3
- package/dist/{CodemationAuthoring.types-DA3G3s6d.d.ts → CodemationAuthoring.types-BXlXIl4K.d.ts} +9 -4
- package/dist/{CodemationAuthoring.types-NGkBcmmT.js → CodemationAuthoring.types-BteaR3Dc.js} +3 -2
- package/dist/CodemationAuthoring.types-BteaR3Dc.js.map +1 -0
- package/dist/{CodemationConfigNormalizer-BAKjetJ6.d.ts → CodemationConfigNormalizer-B4rDYC9h.d.ts} +3 -3
- package/dist/{CodemationConsumerConfigLoader-GYpBBvqE.js → CodemationConsumerConfigLoader-By-6tuGc.js} +3 -1
- package/dist/CodemationConsumerConfigLoader-By-6tuGc.js.map +1 -0
- package/dist/{CodemationConsumerConfigLoader-nxOqvv46.d.ts → CodemationConsumerConfigLoader-Dt4jyLx6.d.ts} +3 -2
- package/dist/{CodemationPluginListMerger-DKLAHT2b.d.ts → CodemationPluginListMerger-DS6I3Xe0.d.ts} +64 -27
- package/dist/{persistenceServer-C-hH4z6l.js → CodemationPostgresPrismaClientFactory-C7156Fe-.js} +2 -2
- package/dist/CodemationPostgresPrismaClientFactory-C7156Fe-.js.map +1 -0
- package/dist/CodemationPostgresPrismaClientFactory-CTNTPnDr.d.ts +9 -0
- package/dist/{CredentialContractsRegistry-Bq2bq28t.d.ts → CredentialContractsRegistry-Dgu-rEXi.d.ts} +16 -3
- package/dist/{CredentialServices-Be2I60Th.d.ts → CredentialServices-B3wPyp2y.d.ts} +4 -4
- package/dist/{CredentialServices-Dk8yypeL.js → CredentialServices-Bios0dM8.js} +10 -4
- package/dist/CredentialServices-Bios0dM8.js.map +1 -0
- package/dist/{InternalPingRegistrar-DY3kSfxP.js → InternalPingRegistrar-BavAAnvk.js} +19 -16
- package/dist/InternalPingRegistrar-BavAAnvk.js.map +1 -0
- package/dist/{ItemsInputNormalizer-_RwIfRIQ.d.ts → ItemsInputNormalizer-CFkfNMLt.d.ts} +1434 -1225
- package/dist/PrismaMigrationDeployer-DdEcXXVi.d.ts +14 -0
- package/dist/{PublicFrontendBootstrapFactory-CY2FS-5g.d.ts → PublicFrontendBootstrapFactory-ClEjZP74.d.ts} +2 -2
- package/dist/{PublicFrontendBootstrapJsonCodec-CXG9Dxft.d.ts → PublicFrontendBootstrapJsonCodec-HNItQ7ol.d.ts} +6 -1
- package/dist/{TelemetryContracts-BtDx84Cp.d.ts → TelemetryContracts-DpZEODQM.d.ts} +2 -2
- package/dist/{WorkflowPolicyUiPresentationFactory-6MyjCvBO.d.ts → WorkflowPolicyUiPresentationFactory-BNn2fvR_.d.ts} +2 -2
- package/dist/{WorkflowPolicyUiPresentationFactory-Bb-ae_Zh.js → WorkflowPolicyUiPresentationFactory-DfvD2VHk.js} +1 -1
- package/dist/{WorkflowPolicyUiPresentationFactory-Bb-ae_Zh.js.map → WorkflowPolicyUiPresentationFactory-DfvD2VHk.js.map} +1 -1
- package/dist/authoring.d.ts +4 -4
- package/dist/authoring.js +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js +1 -1
- package/dist/consumer.d.ts +5 -5
- package/dist/consumer.js +1 -1
- package/dist/credentials.d.ts +5 -5
- package/dist/credentials.js +1 -1
- package/dist/devServerSidecar.d.ts +2 -2
- package/dist/dto.d.ts +5 -5
- package/dist/{index-DilAYwnH.d.ts → index-ChIfeWzk.d.ts} +71 -28
- package/dist/index.d.ts +49 -17
- package/dist/index.js +106 -13
- package/dist/index.js.map +1 -0
- package/dist/infrastructure/persistence/PrismaMigrationOperations.d.ts +44 -0
- package/dist/infrastructure/persistence/PrismaMigrationOperations.js +302 -0
- package/dist/infrastructure/persistence/PrismaMigrationOperations.js.map +1 -0
- package/dist/mapping.d.ts +2 -2
- package/dist/mapping.js +1 -1
- package/dist/nextServer.d.ts +15 -39
- package/dist/nextServer.js +6 -6
- package/dist/pairing.d.ts +27 -8
- package/dist/pairing.js +19 -3
- package/dist/pairing.js.map +1 -0
- package/dist/{pairing.types-snfZ_OzB.d.ts → pairing.types-D9Bjn98U.d.ts} +1 -1
- package/dist/persistenceServer.d.ts +31 -7
- package/dist/persistenceServer.js +2 -2
- package/dist/{server-C4bS62rg.d.ts → server-B5trn7y4.d.ts} +5 -5
- package/dist/{server-Y7kxwtCK.js → server-BlG9qV5S.js} +5 -5
- package/dist/{server-Y7kxwtCK.js.map → server-BlG9qV5S.js.map} +1 -1
- package/dist/server.d.ts +10 -10
- package/dist/server.js +9 -9
- package/package.json +28 -25
- package/playwright.config.ts +8 -2
- package/playwright.scaffolded-dev.config.ts +8 -2
- package/prisma/migrations/20260526120000_credential_material_pointer/migration.sql +18 -0
- package/prisma/migrations/20260527120000_add_human_task/migration.sql +32 -0
- package/prisma/migrations/20260527130000_add_hitl_state_json/migration.sql +6 -0
- package/prisma/migrations/20260527130000_add_hmac_nonce/migration.sql +12 -0
- package/prisma/migrations.sqlite/20260526120000_credential_material_pointer/migration.sql +13 -0
- package/prisma/migrations.sqlite/20260527120000_add_human_task/migration.sql +30 -0
- package/prisma/migrations.sqlite/20260527130000_add_hitl_state_json/migration.sql +6 -0
- package/prisma/migrations.sqlite/20260527130000_add_hmac_nonce/migration.sql +9 -0
- package/prisma/schema.postgresql.prisma +48 -0
- package/prisma/schema.sqlite.prisma +48 -0
- package/prisma-generated/prisma-postgresql-client/edge.js +40 -6
- package/prisma-generated/prisma-postgresql-client/index-browser.js +36 -2
- package/prisma-generated/prisma-postgresql-client/index.d.ts +3179 -163
- package/prisma-generated/prisma-postgresql-client/index.js +40 -6
- package/prisma-generated/prisma-postgresql-client/package.json +1 -1
- package/prisma-generated/prisma-postgresql-client/schema.prisma +48 -0
- package/prisma-generated/prisma-sqlite-client/edge.js +40 -6
- package/prisma-generated/prisma-sqlite-client/index-browser.js +36 -2
- package/prisma-generated/prisma-sqlite-client/index.d.ts +3175 -163
- package/prisma-generated/prisma-sqlite-client/index.js +40 -6
- package/prisma-generated/prisma-sqlite-client/package.json +1 -1
- package/prisma-generated/prisma-sqlite-client/schema.prisma +48 -0
- package/src/application/contracts/CredentialContractsRegistry.ts +15 -0
- package/src/application/credentials/AppGalleryProjector.ts +69 -0
- package/src/application/hitl/DecideHumanTaskCommandHandler.ts +149 -0
- package/src/application/hitl/DecisionSchemaValidator.ts +22 -0
- package/src/application/hitl/HitlCallbackHandler.ts +96 -0
- package/src/application/mapping/WorkflowDefinitionMapper.ts +1 -3
- package/src/application/queries/CredentialQueryHandlers.ts +2 -0
- package/src/application/queries/GetCredentialAppsQuery.ts +4 -0
- package/src/application/queries/GetCredentialAppsQueryHandler.ts +27 -0
- package/src/application/telemetry/ResumeTelemetryContextForRun.ts +53 -0
- package/src/application/telemetry/TelemetryRetentionTimestampFactory.ts +9 -8
- package/src/applicationTokens.ts +11 -1
- package/src/auth/managed/ManagedCorsMiddleware.ts +20 -5
- package/src/bootstrap/AppContainerFactory.ts +121 -3
- package/src/bootstrap/runtime/HeadlessApiRuntime.ts +47 -0
- package/src/credentials/CachingCredentialMaterialProvider.ts +96 -0
- package/src/credentials/CompositeCredentialMaterialProvider.ts +47 -0
- package/src/credentials/ControlPlaneCatalogFetcher.ts +8 -28
- package/src/credentials/ControlPlaneCredentialMaterialProvider.ts +79 -0
- package/src/credentials/CredentialOAuth2MaterialReader.ts +2 -7
- package/src/credentials/InternalCredentialsBindingRegistrar.ts +83 -0
- package/src/credentials/LocalCredentialMaterialProvider.ts +92 -0
- package/src/domain/credentials/CredentialInstanceService.ts +5 -1
- package/src/domain/credentials/CredentialTypeRegistryImpl.ts +18 -4
- package/src/domain/workflows/WorkflowActivationPreflightRules.ts +7 -4
- package/src/dto.ts +2 -0
- package/src/hitl/ControlPlaneInboxChannel.ts +102 -0
- package/src/hitl/HitlResumeTokenSigner.ts +80 -0
- package/src/hitl/HitlTimeoutJobScheduler.ts +77 -0
- package/src/hitl/HitlTimeoutWorker.ts +138 -0
- package/src/hitl/InboxChannelResolver.ts +49 -0
- package/src/hitl/LocalInboxChannel.ts +37 -0
- package/src/index.ts +3 -0
- package/src/infrastructure/persistence/PrismaCredentialStore.ts +10 -0
- package/src/infrastructure/persistence/PrismaHmacNonceStore.ts +29 -0
- package/src/infrastructure/persistence/PrismaHumanTaskStore.ts +156 -0
- package/src/infrastructure/persistence/PrismaMigrationDeployer.ts +53 -383
- package/src/infrastructure/persistence/PrismaMigrationOperations.ts +401 -0
- package/src/infrastructure/persistence/PrismaWorkflowRunRepository.ts +39 -0
- package/src/mcp/AgentMcpIntegrationImpl.ts +5 -1
- package/src/pairing/HmacNonceStore.ts +14 -0
- package/src/pairing/HmacNonceStoreToken.ts +4 -0
- package/src/pairing/HmacRequestSigner.ts +10 -1
- package/src/pairing/InMemoryHmacNonceStore.ts +24 -0
- package/src/pairing/IncomingHmacVerifier.ts +28 -12
- package/src/pairing/InternalHmacAuthMiddleware.ts +1 -1
- package/src/pairing/index.ts +3 -0
- package/src/presentation/config/CodemationAuthoring.types.ts +7 -1
- package/src/presentation/config/CodemationConfig.ts +6 -0
- package/src/presentation/http/ApiPaths.ts +14 -0
- package/src/presentation/http/HeadlessHttpServerFactory.ts +56 -0
- package/src/presentation/http/hono/HonoHttpAnonymousRoutePolicyRegistry.ts +4 -0
- package/src/presentation/http/hono/registrars/CredentialHonoApiRouteRegistrar.ts +1 -0
- package/src/presentation/http/hono/registrars/HitlDecideHonoApiRouteRegistrar.ts +54 -0
- package/src/presentation/http/hono/registrars/HitlInternalCallbackHonoApiRouteRegistrar.ts +33 -0
- package/src/presentation/http/hono/registrars/HitlResumeHonoApiRouteRegistrar.ts +43 -0
- package/src/presentation/http/routeHandlers/CredentialHttpRouteHandler.ts +9 -0
- package/src/presentation/http/routeHandlers/OAuth2HttpRouteHandlerFactory.ts +1 -1
- package/src/presentation/server/CodemationConsumerConfigLoader.ts +7 -2
- package/src/presentation/websocket/WorkflowWebsocketServerFactory.ts +16 -0
- package/src/server.ts +7 -2
- package/src/workflows/InternalWorkflowTestRunRegistrar.ts +9 -0
- package/tsconfig.json +1 -0
- package/dist/AppConfigFactory-Cx4qQvRk.js.map +0 -1
- package/dist/AppContainerFactory-DqKYCRNP.js.map +0 -1
- package/dist/CodemationAuthoring.types-NGkBcmmT.js.map +0 -1
- package/dist/CodemationConsumerConfigLoader-GYpBBvqE.js.map +0 -1
- package/dist/CredentialServices-Dk8yypeL.js.map +0 -1
- package/dist/InternalPingRegistrar-DY3kSfxP.js.map +0 -1
- package/dist/persistenceServer-C-hH4z6l.js.map +0 -1
- package/dist/persistenceServer-CeTHtC6E.d.ts +0 -30
- package/src/credentials/catalogTypes.ts +0 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["appContainerFactory: AppContainerFactory","websocketServerFactory: WorkflowWebsocketServerFactory","httpServerFactory: HeadlessHttpServerFactory","logger: Logger","chunks: Buffer[]","responseHeaders: Record<string, string>"],"sources":["../src/bootstrap/runtime/HeadlessApiRuntime.ts","../src/presentation/websocket/WorkflowWebsocketServerFactory.ts","../src/presentation/http/HeadlessHttpServerFactory.ts"],"sourcesContent":["import type { AppConfig } from \"../../presentation/config/AppConfig\";\nimport type { AppContainerFactory } from \"../AppContainerFactory\";\nimport { FrontendRuntime } from \"./FrontendRuntime\";\nimport { CodemationHonoApiApp } from \"../../presentation/http/hono/CodemationHonoApiAppFactory\";\nimport type { WorkflowWebsocketServerFactory } from \"../../presentation/websocket/WorkflowWebsocketServerFactory\";\nimport type { HeadlessHttpServerFactory } from \"../../presentation/http/HeadlessHttpServerFactory\";\nimport type { Logger } from \"../../application/logging/Logger\";\n\n/**\n * Boots the Codemation API + WebSocket servers without the Next.js UI process.\n * Used by `codemation serve web --headless` for workspace pod containers where the\n * UI is served externally (e.g. from the control-plane's customer-ui).\n */\nexport class HeadlessApiRuntime {\n constructor(\n private readonly appContainerFactory: AppContainerFactory,\n private readonly websocketServerFactory: WorkflowWebsocketServerFactory,\n private readonly httpServerFactory: HeadlessHttpServerFactory,\n private readonly logger: Logger,\n ) {}\n\n async start(appConfig: AppConfig): Promise<void> {\n const port = Number(appConfig.env.PORT ?? 4001);\n\n this.logger.info(`Starting codemation headless API runtime`);\n this.logger.info(`HTTP port: ${port}, WS port: ${appConfig.webSocketPort}`);\n\n const websocketServer = this.websocketServerFactory.create(appConfig);\n\n const container = await this.appContainerFactory.create({\n appConfig,\n sharedWorkflowWebsocketServer: websocketServer,\n });\n\n await container.resolve(FrontendRuntime).start();\n\n const honoApp = container.resolve(CodemationHonoApiApp);\n const httpServer = this.httpServerFactory.create(honoApp, port, this.logger);\n\n await new Promise<void>((resolve) => {\n httpServer.listen(port, () => {\n this.logger.info(`codemation headless API listening on port ${port}`);\n resolve();\n });\n });\n }\n}\n","import type { AppConfig } from \"../config/AppConfig\";\nimport { WorkflowWebsocketServer } from \"./WorkflowWebsocketServer\";\nimport { logLevelPolicyFactory } from \"../../infrastructure/logging/LogLevelPolicyFactory\";\nimport { ServerLoggerFactory } from \"../../infrastructure/logging/ServerLoggerFactory\";\n\nconst loggerFactory = new ServerLoggerFactory(logLevelPolicyFactory);\n\nexport class WorkflowWebsocketServerFactory {\n create(appConfig: AppConfig): WorkflowWebsocketServer {\n return new WorkflowWebsocketServer(\n appConfig.webSocketPort,\n appConfig.webSocketBindHost,\n loggerFactory.create(\"codemation-websocket.server\"),\n );\n }\n}\n","import { createServer, type Server } from \"node:http\";\nimport type { Logger } from \"../../application/logging/Logger\";\nimport type { CodemationHonoApiApp } from \"./hono/CodemationHonoApiAppFactory\";\n\n/**\n * Creates a Node.js http.Server that bridges IncomingMessage to Hono's Fetch API.\n * Used by {@link import(\"../../bootstrap/runtime/HeadlessApiRuntime\").HeadlessApiRuntime}\n * to serve the Hono API without Next.js.\n */\nexport class HeadlessHttpServerFactory {\n create(honoApp: CodemationHonoApiApp, port: number, logger: Logger): Server {\n return createServer((req, res) => {\n const url = new URL(req.url ?? \"/\", `http://${req.headers.host ?? `127.0.0.1:${port}`}`);\n const headers = new Headers();\n for (const [key, value] of Object.entries(req.headers)) {\n if (value === undefined) continue;\n if (Array.isArray(value)) {\n for (const v of value) headers.append(key, v);\n } else {\n headers.set(key, value);\n }\n }\n const chunks: Buffer[] = [];\n req.on(\"data\", (chunk: Buffer) => chunks.push(chunk));\n req.on(\"end\", () => {\n // eslint-disable-next-line codemation/no-buffer-everything -- node:http bridge; no streaming alternative when adapting IncomingMessage to Fetch API Request\n const body = chunks.length > 0 ? Buffer.concat(chunks) : null;\n const fetchRequest = new Request(url, {\n method: req.method ?? \"GET\",\n headers,\n body: body?.byteLength ? body : undefined,\n // @ts-expect-error — Node's Request needs duplex for streaming; required in some runtimes\n duplex: \"half\",\n });\n Promise.resolve(honoApp.fetch(fetchRequest))\n .then(async (fetchResponse: Response) => {\n const responseHeaders: Record<string, string> = {};\n fetchResponse.headers.forEach((value, key) => {\n responseHeaders[key] = value;\n });\n res.writeHead(fetchResponse.status, responseHeaders);\n // eslint-disable-next-line codemation/no-buffer-everything -- node:http bridge; Hono Fetch Response must be fully buffered to write to ServerResponse\n const responseBody = await fetchResponse.arrayBuffer();\n res.end(Buffer.from(responseBody));\n })\n .catch((err: unknown) => {\n logger.error(\"Unhandled request error\", err instanceof Error ? err : new Error(String(err)));\n if (!res.headersSent) {\n res.writeHead(500);\n res.end(\"Internal server error\");\n }\n });\n });\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,IAAa,qBAAb,MAAgC;CAC9B,YACE,AAAiBA,qBACjB,AAAiBC,wBACjB,AAAiBC,mBACjB,AAAiBC,QACjB;EAJiB;EACA;EACA;EACA;;CAGnB,MAAM,MAAM,WAAqC;EAC/C,MAAM,OAAO,OAAO,UAAU,IAAI,QAAQ,KAAK;AAE/C,OAAK,OAAO,KAAK,2CAA2C;AAC5D,OAAK,OAAO,KAAK,cAAc,KAAK,aAAa,UAAU,gBAAgB;EAE3E,MAAM,kBAAkB,KAAK,uBAAuB,OAAO,UAAU;EAErE,MAAM,YAAY,MAAM,KAAK,oBAAoB,OAAO;GACtD;GACA,+BAA+B;GAChC,CAAC;AAEF,QAAM,UAAU,QAAQ,gBAAgB,CAAC,OAAO;EAEhD,MAAM,UAAU,UAAU,QAAQ,qBAAqB;EACvD,MAAM,aAAa,KAAK,kBAAkB,OAAO,SAAS,MAAM,KAAK,OAAO;AAE5E,QAAM,IAAI,SAAe,YAAY;AACnC,cAAW,OAAO,YAAY;AAC5B,SAAK,OAAO,KAAK,6CAA6C,OAAO;AACrE,aAAS;KACT;IACF;;;;;;ACvCN,MAAM,gBAAgB,IAAI,oBAAoB,sBAAsB;AAEpE,IAAa,iCAAb,MAA4C;CAC1C,OAAO,WAA+C;AACpD,SAAO,IAAI,wBACT,UAAU,eACV,UAAU,mBACV,cAAc,OAAO,8BAA8B,CACpD;;;;;;;;;;;ACJL,IAAa,4BAAb,MAAuC;CACrC,OAAO,SAA+B,MAAc,QAAwB;AAC1E,SAAO,cAAc,KAAK,QAAQ;GAChC,MAAM,MAAM,IAAI,IAAI,IAAI,OAAO,KAAK,UAAU,IAAI,QAAQ,QAAQ,aAAa,SAAS;GACxF,MAAM,UAAU,IAAI,SAAS;AAC7B,QAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,IAAI,QAAQ,EAAE;AACtD,QAAI,UAAU,OAAW;AACzB,QAAI,MAAM,QAAQ,MAAM,CACtB,MAAK,MAAM,KAAK,MAAO,SAAQ,OAAO,KAAK,EAAE;QAE7C,SAAQ,IAAI,KAAK,MAAM;;GAG3B,MAAMC,SAAmB,EAAE;AAC3B,OAAI,GAAG,SAAS,UAAkB,OAAO,KAAK,MAAM,CAAC;AACrD,OAAI,GAAG,aAAa;IAElB,MAAM,OAAO,OAAO,SAAS,IAAI,OAAO,OAAO,OAAO,GAAG;IACzD,MAAM,eAAe,IAAI,QAAQ,KAAK;KACpC,QAAQ,IAAI,UAAU;KACtB;KACA,MAAM,MAAM,aAAa,OAAO;KAEhC,QAAQ;KACT,CAAC;AACF,YAAQ,QAAQ,QAAQ,MAAM,aAAa,CAAC,CACzC,KAAK,OAAO,kBAA4B;KACvC,MAAMC,kBAA0C,EAAE;AAClD,mBAAc,QAAQ,SAAS,OAAO,QAAQ;AAC5C,sBAAgB,OAAO;OACvB;AACF,SAAI,UAAU,cAAc,QAAQ,gBAAgB;KAEpD,MAAM,eAAe,MAAM,cAAc,aAAa;AACtD,SAAI,IAAI,OAAO,KAAK,aAAa,CAAC;MAClC,CACD,OAAO,QAAiB;AACvB,YAAO,MAAM,2BAA2B,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,IAAI,CAAC,CAAC;AAC5F,SAAI,CAAC,IAAI,aAAa;AACpB,UAAI,UAAU,IAAI;AAClB,UAAI,IAAI,wBAAwB;;MAElC;KACJ;IACF"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import "../../index-ChIfeWzk.js";
|
|
2
|
+
import "../../ItemsInputNormalizer-CFkfNMLt.js";
|
|
3
|
+
import { i as AppPersistenceConfig } from "../../CodemationAppContext-K51b7oXe.js";
|
|
4
|
+
import "../../CodemationWhitelabelConfig-Ca2mCUeC.js";
|
|
5
|
+
|
|
6
|
+
//#region src/infrastructure/persistence/PrismaMigrationOperations.d.ts
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Contains all runtime logic for deploying Prisma migrations.
|
|
10
|
+
* This class is loaded lazily via `await import(...)` from PrismaMigrationDeployer
|
|
11
|
+
* so that the dynamic fs/path/createRequire operations never appear in the
|
|
12
|
+
* static module graph visible to the Turbopack / Next.js NFT tracer.
|
|
13
|
+
*/
|
|
14
|
+
declare class PrismaMigrationOperations {
|
|
15
|
+
private static readonly normalizedRuntimeMigrationName;
|
|
16
|
+
private readonly require;
|
|
17
|
+
deployPersistence(persistence: AppPersistenceConfig, env?: Readonly<NodeJS.ProcessEnv>): Promise<void>;
|
|
18
|
+
deploy(args: Readonly<{
|
|
19
|
+
databaseUrl: string;
|
|
20
|
+
env?: Readonly<NodeJS.ProcessEnv>;
|
|
21
|
+
}>): Promise<void>;
|
|
22
|
+
resolvePackageRoot(env?: Readonly<NodeJS.ProcessEnv>): string;
|
|
23
|
+
private deploySqlite;
|
|
24
|
+
private deployPostgres;
|
|
25
|
+
private deployWithProvider;
|
|
26
|
+
private resolveAppliedMigration;
|
|
27
|
+
private runPrismaCommand;
|
|
28
|
+
private tryRecoverPartiallyAppliedNormalizedRuntimeMigration;
|
|
29
|
+
private isRecoverableNormalizedRuntimeMigrationError;
|
|
30
|
+
private repairPartiallyAppliedNormalizedRuntimeSqliteDatabase;
|
|
31
|
+
private hasActiveFailedMigrationRecord;
|
|
32
|
+
private readSqliteTableColumns;
|
|
33
|
+
private ensureNormalizedRuntimeRepairArtifacts;
|
|
34
|
+
private cleanupNormalizedRuntimeLegacyArtifacts;
|
|
35
|
+
private sqliteFilePathToDatabaseUrl;
|
|
36
|
+
private createProcessEnvironment;
|
|
37
|
+
private resolvePrismaCliPath;
|
|
38
|
+
private resolveAbsolutePrismaConfigPath;
|
|
39
|
+
private ensureSqliteParentDirectoryExists;
|
|
40
|
+
private createDeployError;
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { PrismaMigrationOperations };
|
|
44
|
+
//# sourceMappingURL=PrismaMigrationOperations.d.ts.map
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { mkdir } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
import { spawn } from "node:child_process";
|
|
7
|
+
|
|
8
|
+
//#region src/infrastructure/persistence/PrismaMigrationOperations.ts
|
|
9
|
+
/**
|
|
10
|
+
* Contains all runtime logic for deploying Prisma migrations.
|
|
11
|
+
* This class is loaded lazily via `await import(...)` from PrismaMigrationDeployer
|
|
12
|
+
* so that the dynamic fs/path/createRequire operations never appear in the
|
|
13
|
+
* static module graph visible to the Turbopack / Next.js NFT tracer.
|
|
14
|
+
*/
|
|
15
|
+
var PrismaMigrationOperations = class PrismaMigrationOperations {
|
|
16
|
+
static normalizedRuntimeMigrationName = "20260407140000_run_normalized_persistence";
|
|
17
|
+
require = createRequire(import.meta.url);
|
|
18
|
+
async deployPersistence(persistence, env) {
|
|
19
|
+
if (persistence.kind === "none") return;
|
|
20
|
+
if (persistence.kind === "postgresql") {
|
|
21
|
+
await this.deployPostgres({
|
|
22
|
+
databaseUrl: persistence.databaseUrl,
|
|
23
|
+
env
|
|
24
|
+
});
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
await this.deploySqlite({
|
|
28
|
+
databaseFilePath: persistence.databaseFilePath,
|
|
29
|
+
env
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
async deploy(args) {
|
|
33
|
+
await this.deployPostgres(args);
|
|
34
|
+
}
|
|
35
|
+
resolvePackageRoot(env = process.env) {
|
|
36
|
+
const configuredRoot = env.CODEMATION_HOST_PACKAGE_ROOT;
|
|
37
|
+
if (configuredRoot) return configuredRoot;
|
|
38
|
+
let currentDirectory = path.dirname(fileURLToPath(import.meta.url));
|
|
39
|
+
for (let depth = 0; depth < 8; depth += 1) {
|
|
40
|
+
if (existsSync(path.join(currentDirectory, "prisma", "schema.postgresql.prisma"))) return currentDirectory;
|
|
41
|
+
const parentDirectory = path.dirname(currentDirectory);
|
|
42
|
+
if (parentDirectory === currentDirectory) break;
|
|
43
|
+
currentDirectory = parentDirectory;
|
|
44
|
+
}
|
|
45
|
+
throw new Error(`Could not locate prisma/schema.postgresql.prisma near ${fileURLToPath(import.meta.url)}.`);
|
|
46
|
+
}
|
|
47
|
+
async deploySqlite(args) {
|
|
48
|
+
await this.ensureSqliteParentDirectoryExists(args.databaseFilePath);
|
|
49
|
+
const databaseUrl = this.sqliteFilePathToDatabaseUrl(args.databaseFilePath);
|
|
50
|
+
try {
|
|
51
|
+
await this.deployWithProvider({
|
|
52
|
+
provider: "sqlite",
|
|
53
|
+
databaseUrl,
|
|
54
|
+
env: args.env
|
|
55
|
+
});
|
|
56
|
+
} catch (error) {
|
|
57
|
+
if (!await this.tryRecoverPartiallyAppliedNormalizedRuntimeMigration({
|
|
58
|
+
databaseFilePath: args.databaseFilePath,
|
|
59
|
+
databaseUrl,
|
|
60
|
+
env: args.env,
|
|
61
|
+
error
|
|
62
|
+
})) throw error;
|
|
63
|
+
}
|
|
64
|
+
await this.cleanupNormalizedRuntimeLegacyArtifacts(args.databaseFilePath);
|
|
65
|
+
}
|
|
66
|
+
async deployPostgres(args) {
|
|
67
|
+
await this.deployWithProvider({
|
|
68
|
+
provider: "postgresql",
|
|
69
|
+
databaseUrl: args.databaseUrl,
|
|
70
|
+
env: args.env
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
async deployWithProvider(args) {
|
|
74
|
+
await this.runPrismaCommand({
|
|
75
|
+
prismaArgs: ["migrate", "deploy"],
|
|
76
|
+
provider: args.provider,
|
|
77
|
+
databaseUrl: args.databaseUrl,
|
|
78
|
+
env: args.env
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
async resolveAppliedMigration(args) {
|
|
82
|
+
await this.runPrismaCommand({
|
|
83
|
+
prismaArgs: [
|
|
84
|
+
"migrate",
|
|
85
|
+
"resolve",
|
|
86
|
+
"--applied",
|
|
87
|
+
args.migrationName
|
|
88
|
+
],
|
|
89
|
+
provider: args.provider,
|
|
90
|
+
databaseUrl: args.databaseUrl,
|
|
91
|
+
env: args.env
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async runPrismaCommand(args) {
|
|
95
|
+
const resolverEnv = {
|
|
96
|
+
...process.env,
|
|
97
|
+
...args.env ?? {}
|
|
98
|
+
};
|
|
99
|
+
const prismaConfigPath = this.resolveAbsolutePrismaConfigPath(resolverEnv);
|
|
100
|
+
await new Promise((resolve, reject) => {
|
|
101
|
+
const command = spawn(process.execPath, [
|
|
102
|
+
...[this.resolvePrismaCliPath(resolverEnv), ...args.prismaArgs],
|
|
103
|
+
"--config",
|
|
104
|
+
path.basename(prismaConfigPath)
|
|
105
|
+
], {
|
|
106
|
+
cwd: path.dirname(prismaConfigPath),
|
|
107
|
+
env: this.createProcessEnvironment(args.databaseUrl, args.provider, args.env),
|
|
108
|
+
stdio: [
|
|
109
|
+
"ignore",
|
|
110
|
+
"pipe",
|
|
111
|
+
"pipe"
|
|
112
|
+
]
|
|
113
|
+
});
|
|
114
|
+
let stdout = "";
|
|
115
|
+
let stderr = "";
|
|
116
|
+
command.stdout.on("data", (chunk) => {
|
|
117
|
+
stdout += chunk.toString();
|
|
118
|
+
});
|
|
119
|
+
command.stderr.on("data", (chunk) => {
|
|
120
|
+
stderr += chunk.toString();
|
|
121
|
+
});
|
|
122
|
+
command.once("error", (error) => {
|
|
123
|
+
reject(error);
|
|
124
|
+
});
|
|
125
|
+
command.once("close", (exitCode) => {
|
|
126
|
+
if (exitCode === 0) {
|
|
127
|
+
resolve();
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
reject(this.createDeployError(exitCode, stdout, stderr));
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
async tryRecoverPartiallyAppliedNormalizedRuntimeMigration(args) {
|
|
135
|
+
if (!this.isRecoverableNormalizedRuntimeMigrationError(args.error)) return false;
|
|
136
|
+
if (!await this.repairPartiallyAppliedNormalizedRuntimeSqliteDatabase(args.databaseFilePath)) return false;
|
|
137
|
+
await this.resolveAppliedMigration({
|
|
138
|
+
provider: "sqlite",
|
|
139
|
+
databaseUrl: args.databaseUrl,
|
|
140
|
+
migrationName: PrismaMigrationOperations.normalizedRuntimeMigrationName,
|
|
141
|
+
env: args.env
|
|
142
|
+
});
|
|
143
|
+
await this.deployWithProvider({
|
|
144
|
+
provider: "sqlite",
|
|
145
|
+
databaseUrl: args.databaseUrl,
|
|
146
|
+
env: args.env
|
|
147
|
+
});
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
isRecoverableNormalizedRuntimeMigrationError(error) {
|
|
151
|
+
if (!(error instanceof Error)) return false;
|
|
152
|
+
return error.message.includes("Error: P3009") && error.message.includes(PrismaMigrationOperations.normalizedRuntimeMigrationName);
|
|
153
|
+
}
|
|
154
|
+
async repairPartiallyAppliedNormalizedRuntimeSqliteDatabase(databaseFilePath) {
|
|
155
|
+
const { createClient } = await import("@libsql/client");
|
|
156
|
+
const client = createClient({ url: this.sqliteFilePathToDatabaseUrl(databaseFilePath) });
|
|
157
|
+
try {
|
|
158
|
+
if (!await this.hasActiveFailedMigrationRecord(client, PrismaMigrationOperations.normalizedRuntimeMigrationName)) return false;
|
|
159
|
+
const runColumns = await this.readSqliteTableColumns(client, "Run");
|
|
160
|
+
if (!(runColumns.has("finished_at") && runColumns.has("revision") && runColumns.has("outputs_by_node_json") && !runColumns.has("state_json"))) return false;
|
|
161
|
+
await this.ensureNormalizedRuntimeRepairArtifacts(client);
|
|
162
|
+
return true;
|
|
163
|
+
} finally {
|
|
164
|
+
client.close();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
async hasActiveFailedMigrationRecord(client, migrationName) {
|
|
168
|
+
return (await client.execute({
|
|
169
|
+
sql: [
|
|
170
|
+
"SELECT 1 AS \"has_failed\"",
|
|
171
|
+
"FROM \"_prisma_migrations\"",
|
|
172
|
+
"WHERE \"migration_name\" = ?",
|
|
173
|
+
" AND \"finished_at\" IS NULL",
|
|
174
|
+
" AND \"rolled_back_at\" IS NULL",
|
|
175
|
+
"LIMIT 1"
|
|
176
|
+
].join(" "),
|
|
177
|
+
args: [migrationName]
|
|
178
|
+
})).rows.length > 0;
|
|
179
|
+
}
|
|
180
|
+
async readSqliteTableColumns(client, tableName) {
|
|
181
|
+
const result = await client.execute(`PRAGMA table_info("${tableName}")`);
|
|
182
|
+
return new Set(result.rows.map((row) => String(row.name)));
|
|
183
|
+
}
|
|
184
|
+
async ensureNormalizedRuntimeRepairArtifacts(client) {
|
|
185
|
+
await client.execute(`
|
|
186
|
+
CREATE TABLE IF NOT EXISTS "RunWorkItem" (
|
|
187
|
+
"work_item_id" TEXT NOT NULL PRIMARY KEY,
|
|
188
|
+
"run_id" TEXT NOT NULL,
|
|
189
|
+
"workflow_id" TEXT NOT NULL,
|
|
190
|
+
"status" TEXT NOT NULL,
|
|
191
|
+
"target_node_id" TEXT NOT NULL,
|
|
192
|
+
"batch_id" TEXT NOT NULL,
|
|
193
|
+
"queue_name" TEXT,
|
|
194
|
+
"claim_token" TEXT,
|
|
195
|
+
"claimed_by" TEXT,
|
|
196
|
+
"claimed_at" TEXT,
|
|
197
|
+
"available_at" TEXT NOT NULL,
|
|
198
|
+
"enqueued_at" TEXT NOT NULL,
|
|
199
|
+
"completed_at" TEXT,
|
|
200
|
+
"failed_at" TEXT,
|
|
201
|
+
"source_instance_id" TEXT,
|
|
202
|
+
"parent_instance_id" TEXT,
|
|
203
|
+
"items_in" INTEGER NOT NULL,
|
|
204
|
+
"inputs_by_port_json" TEXT NOT NULL,
|
|
205
|
+
"error_json" TEXT,
|
|
206
|
+
CONSTRAINT "RunWorkItem_run_id_fkey" FOREIGN KEY ("run_id") REFERENCES "Run"("run_id") ON DELETE CASCADE ON UPDATE CASCADE
|
|
207
|
+
)
|
|
208
|
+
`);
|
|
209
|
+
await client.execute(`
|
|
210
|
+
CREATE INDEX IF NOT EXISTS "RunWorkItem_run_id_status_available_at_idx"
|
|
211
|
+
ON "RunWorkItem"("run_id", "status", "available_at")
|
|
212
|
+
`);
|
|
213
|
+
await client.execute(`
|
|
214
|
+
CREATE INDEX IF NOT EXISTS "RunWorkItem_run_id_target_node_id_batch_id_idx"
|
|
215
|
+
ON "RunWorkItem"("run_id", "target_node_id", "batch_id")
|
|
216
|
+
`);
|
|
217
|
+
await client.execute(`
|
|
218
|
+
CREATE TABLE IF NOT EXISTS "RunSlotProjection" (
|
|
219
|
+
"run_id" TEXT NOT NULL PRIMARY KEY,
|
|
220
|
+
"workflow_id" TEXT NOT NULL,
|
|
221
|
+
"revision" INTEGER NOT NULL,
|
|
222
|
+
"updated_at" TEXT NOT NULL,
|
|
223
|
+
"slot_states_json" TEXT NOT NULL,
|
|
224
|
+
CONSTRAINT "RunSlotProjection_run_id_fkey" FOREIGN KEY ("run_id") REFERENCES "Run"("run_id") ON DELETE CASCADE ON UPDATE CASCADE
|
|
225
|
+
)
|
|
226
|
+
`);
|
|
227
|
+
await client.execute(`
|
|
228
|
+
CREATE INDEX IF NOT EXISTS "RunSlotProjection_workflow_id_updated_at_idx"
|
|
229
|
+
ON "RunSlotProjection"("workflow_id", "updated_at")
|
|
230
|
+
`);
|
|
231
|
+
await client.execute(`
|
|
232
|
+
INSERT OR IGNORE INTO "RunSlotProjection" (
|
|
233
|
+
"run_id",
|
|
234
|
+
"workflow_id",
|
|
235
|
+
"revision",
|
|
236
|
+
"updated_at",
|
|
237
|
+
"slot_states_json"
|
|
238
|
+
)
|
|
239
|
+
SELECT
|
|
240
|
+
"run_id",
|
|
241
|
+
"workflow_id",
|
|
242
|
+
"revision",
|
|
243
|
+
"updated_at",
|
|
244
|
+
json_object('slotStatesByNodeId', json('{}'))
|
|
245
|
+
FROM "Run"
|
|
246
|
+
`);
|
|
247
|
+
}
|
|
248
|
+
async cleanupNormalizedRuntimeLegacyArtifacts(databaseFilePath) {
|
|
249
|
+
const { createClient } = await import("@libsql/client");
|
|
250
|
+
const client = createClient({ url: this.sqliteFilePathToDatabaseUrl(databaseFilePath) });
|
|
251
|
+
try {
|
|
252
|
+
const runColumns = await this.readSqliteTableColumns(client, "Run");
|
|
253
|
+
if (!(runColumns.has("finished_at") && runColumns.has("revision") && runColumns.has("outputs_by_node_json") && !runColumns.has("state_json"))) return;
|
|
254
|
+
const runSlotProjectionColumns = await this.readSqliteTableColumns(client, "RunSlotProjection");
|
|
255
|
+
await client.execute("DROP TABLE IF EXISTS \"Run_legacy\"");
|
|
256
|
+
if (runSlotProjectionColumns.size > 0) await client.execute("DROP TABLE IF EXISTS \"RunProjection\"");
|
|
257
|
+
} finally {
|
|
258
|
+
client.close();
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
sqliteFilePathToDatabaseUrl(databaseFilePath) {
|
|
262
|
+
return `file:${path.resolve(databaseFilePath)}`;
|
|
263
|
+
}
|
|
264
|
+
createProcessEnvironment(databaseUrl, provider, env) {
|
|
265
|
+
return {
|
|
266
|
+
...process.env,
|
|
267
|
+
...env ?? {},
|
|
268
|
+
DATABASE_URL: databaseUrl,
|
|
269
|
+
CODEMATION_PRISMA_PROVIDER: provider
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
resolvePrismaCliPath(env) {
|
|
273
|
+
const configuredPath = env.CODEMATION_PRISMA_CLI_PATH;
|
|
274
|
+
if (configuredPath && existsSync(configuredPath)) return configuredPath;
|
|
275
|
+
const packageRoot = this.resolvePackageRoot(env);
|
|
276
|
+
const packageManagerCandidates = [path.resolve(process.cwd(), "node_modules", "prisma", "build", "index.js"), path.resolve(packageRoot, "node_modules", "prisma", "build", "index.js")];
|
|
277
|
+
for (const candidate of packageManagerCandidates) if (existsSync(candidate)) return candidate;
|
|
278
|
+
try {
|
|
279
|
+
return this.require.resolve("prisma/build/index.js", { paths: [process.cwd(), packageRoot] });
|
|
280
|
+
} catch {
|
|
281
|
+
throw new Error("Unable to resolve the Prisma CLI required for startup migrations. Ensure `prisma` is installed.");
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
resolveAbsolutePrismaConfigPath(env) {
|
|
285
|
+
const configuredPath = env.CODEMATION_PRISMA_CONFIG_PATH;
|
|
286
|
+
const packageRoot = this.resolvePackageRoot(env);
|
|
287
|
+
if (configuredPath) return path.isAbsolute(configuredPath) ? configuredPath : path.resolve(packageRoot, configuredPath);
|
|
288
|
+
return path.resolve(packageRoot, "prisma.config.ts");
|
|
289
|
+
}
|
|
290
|
+
async ensureSqliteParentDirectoryExists(databaseFilePath) {
|
|
291
|
+
await mkdir(path.dirname(databaseFilePath), { recursive: true });
|
|
292
|
+
}
|
|
293
|
+
createDeployError(exitCode, stdout, stderr) {
|
|
294
|
+
const output = stderr.trim() || stdout.trim();
|
|
295
|
+
if (!output) return /* @__PURE__ */ new Error(`Prisma migrate deploy failed during startup with exit code ${exitCode ?? "unknown"}.`);
|
|
296
|
+
return /* @__PURE__ */ new Error(`Prisma migrate deploy failed during startup with exit code ${exitCode ?? "unknown"}.\n${output}`);
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
//#endregion
|
|
301
|
+
export { PrismaMigrationOperations };
|
|
302
|
+
//# sourceMappingURL=PrismaMigrationOperations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrismaMigrationOperations.js","names":[],"sources":["../../../src/infrastructure/persistence/PrismaMigrationOperations.ts"],"sourcesContent":["import type { Client } from \"@libsql/client\";\nimport { spawn } from \"node:child_process\";\nimport { existsSync } from \"node:fs\";\nimport { mkdir } from \"node:fs/promises\";\nimport { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport type { AppPersistenceConfig } from \"../../presentation/config/AppConfig\";\n\n/**\n * Contains all runtime logic for deploying Prisma migrations.\n * This class is loaded lazily via `await import(...)` from PrismaMigrationDeployer\n * so that the dynamic fs/path/createRequire operations never appear in the\n * static module graph visible to the Turbopack / Next.js NFT tracer.\n */\nexport class PrismaMigrationOperations {\n private static readonly normalizedRuntimeMigrationName = \"20260407140000_run_normalized_persistence\";\n private readonly require = createRequire(import.meta.url);\n\n async deployPersistence(persistence: AppPersistenceConfig, env?: Readonly<NodeJS.ProcessEnv>): Promise<void> {\n if (persistence.kind === \"none\") {\n return;\n }\n if (persistence.kind === \"postgresql\") {\n await this.deployPostgres({ databaseUrl: persistence.databaseUrl, env });\n return;\n }\n await this.deploySqlite({ databaseFilePath: persistence.databaseFilePath, env });\n }\n\n async deploy(args: Readonly<{ databaseUrl: string; env?: Readonly<NodeJS.ProcessEnv> }>): Promise<void> {\n await this.deployPostgres(args);\n }\n\n resolvePackageRoot(env: Readonly<NodeJS.ProcessEnv> = process.env): string {\n const configuredRoot = env.CODEMATION_HOST_PACKAGE_ROOT;\n if (configuredRoot) {\n return configuredRoot;\n }\n let currentDirectory = path.dirname(fileURLToPath(import.meta.url));\n for (let depth = 0; depth < 8; depth += 1) {\n if (existsSync(path.join(currentDirectory, \"prisma\", \"schema.postgresql.prisma\"))) {\n return currentDirectory;\n }\n const parentDirectory = path.dirname(currentDirectory);\n if (parentDirectory === currentDirectory) {\n break;\n }\n currentDirectory = parentDirectory;\n }\n throw new Error(`Could not locate prisma/schema.postgresql.prisma near ${fileURLToPath(import.meta.url)}.`);\n }\n\n private async deploySqlite(\n args: Readonly<{ databaseFilePath: string; env?: Readonly<NodeJS.ProcessEnv> }>,\n ): Promise<void> {\n await this.ensureSqliteParentDirectoryExists(args.databaseFilePath);\n const databaseUrl = this.sqliteFilePathToDatabaseUrl(args.databaseFilePath);\n try {\n await this.deployWithProvider({\n provider: \"sqlite\",\n databaseUrl,\n env: args.env,\n });\n } catch (error) {\n const recovered = await this.tryRecoverPartiallyAppliedNormalizedRuntimeMigration({\n databaseFilePath: args.databaseFilePath,\n databaseUrl,\n env: args.env,\n error,\n });\n if (!recovered) {\n throw error;\n }\n }\n await this.cleanupNormalizedRuntimeLegacyArtifacts(args.databaseFilePath);\n }\n\n private async deployPostgres(\n args: Readonly<{ databaseUrl: string; env?: Readonly<NodeJS.ProcessEnv> }>,\n ): Promise<void> {\n await this.deployWithProvider({\n provider: \"postgresql\",\n databaseUrl: args.databaseUrl,\n env: args.env,\n });\n }\n\n private async deployWithProvider(\n args: Readonly<{\n provider: \"postgresql\" | \"sqlite\";\n databaseUrl: string;\n env?: Readonly<NodeJS.ProcessEnv>;\n }>,\n ): Promise<void> {\n await this.runPrismaCommand({\n prismaArgs: [\"migrate\", \"deploy\"],\n provider: args.provider,\n databaseUrl: args.databaseUrl,\n env: args.env,\n });\n }\n\n private async resolveAppliedMigration(\n args: Readonly<{\n provider: \"postgresql\" | \"sqlite\";\n databaseUrl: string;\n migrationName: string;\n env?: Readonly<NodeJS.ProcessEnv>;\n }>,\n ): Promise<void> {\n await this.runPrismaCommand({\n prismaArgs: [\"migrate\", \"resolve\", \"--applied\", args.migrationName],\n provider: args.provider,\n databaseUrl: args.databaseUrl,\n env: args.env,\n });\n }\n\n private async runPrismaCommand(\n args: Readonly<{\n prismaArgs: string[];\n provider: \"postgresql\" | \"sqlite\";\n databaseUrl: string;\n env?: Readonly<NodeJS.ProcessEnv>;\n }>,\n ): Promise<void> {\n const resolverEnv = { ...process.env, ...(args.env ?? {}) };\n const prismaConfigPath = this.resolveAbsolutePrismaConfigPath(resolverEnv);\n await new Promise<void>((resolve, reject) => {\n const command = spawn(\n process.execPath,\n [...[this.resolvePrismaCliPath(resolverEnv), ...args.prismaArgs], \"--config\", path.basename(prismaConfigPath)],\n {\n cwd: path.dirname(prismaConfigPath),\n env: this.createProcessEnvironment(args.databaseUrl, args.provider, args.env),\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n },\n );\n let stdout = \"\";\n let stderr = \"\";\n command.stdout.on(\"data\", (chunk: Buffer | string) => {\n stdout += chunk.toString();\n });\n command.stderr.on(\"data\", (chunk: Buffer | string) => {\n stderr += chunk.toString();\n });\n command.once(\"error\", (error) => {\n reject(error);\n });\n command.once(\"close\", (exitCode) => {\n if (exitCode === 0) {\n resolve();\n return;\n }\n reject(this.createDeployError(exitCode, stdout, stderr));\n });\n });\n }\n\n private async tryRecoverPartiallyAppliedNormalizedRuntimeMigration(\n args: Readonly<{\n databaseFilePath: string;\n databaseUrl: string;\n env?: Readonly<NodeJS.ProcessEnv>;\n error: unknown;\n }>,\n ): Promise<boolean> {\n if (!this.isRecoverableNormalizedRuntimeMigrationError(args.error)) {\n return false;\n }\n const repaired = await this.repairPartiallyAppliedNormalizedRuntimeSqliteDatabase(args.databaseFilePath);\n if (!repaired) {\n return false;\n }\n await this.resolveAppliedMigration({\n provider: \"sqlite\",\n databaseUrl: args.databaseUrl,\n migrationName: PrismaMigrationOperations.normalizedRuntimeMigrationName,\n env: args.env,\n });\n await this.deployWithProvider({\n provider: \"sqlite\",\n databaseUrl: args.databaseUrl,\n env: args.env,\n });\n return true;\n }\n\n private isRecoverableNormalizedRuntimeMigrationError(error: unknown): boolean {\n if (!(error instanceof Error)) {\n return false;\n }\n return (\n error.message.includes(\"Error: P3009\") &&\n error.message.includes(PrismaMigrationOperations.normalizedRuntimeMigrationName)\n );\n }\n\n private async repairPartiallyAppliedNormalizedRuntimeSqliteDatabase(databaseFilePath: string): Promise<boolean> {\n // Lazy import: @libsql/client pulls in platform-specific native bindings that confuse the\n // Next.js / Turbopack module tracer (forcing the whole project to be traced via NFT). This\n // recovery path is rarely needed, so defer the load until it's actually invoked.\n const { createClient } = await import(\"@libsql/client\");\n const client = createClient({ url: this.sqliteFilePathToDatabaseUrl(databaseFilePath) });\n try {\n const failedMigration = await this.hasActiveFailedMigrationRecord(\n client,\n PrismaMigrationOperations.normalizedRuntimeMigrationName,\n );\n if (!failedMigration) {\n return false;\n }\n const runColumns = await this.readSqliteTableColumns(client, \"Run\");\n const hasNormalizedRunShape =\n runColumns.has(\"finished_at\") &&\n runColumns.has(\"revision\") &&\n runColumns.has(\"outputs_by_node_json\") &&\n !runColumns.has(\"state_json\");\n if (!hasNormalizedRunShape) {\n return false;\n }\n await this.ensureNormalizedRuntimeRepairArtifacts(client);\n return true;\n } finally {\n client.close();\n }\n }\n\n private async hasActiveFailedMigrationRecord(client: Client, migrationName: string): Promise<boolean> {\n const result = await client.execute({\n sql: [\n 'SELECT 1 AS \"has_failed\"',\n 'FROM \"_prisma_migrations\"',\n 'WHERE \"migration_name\" = ?',\n ' AND \"finished_at\" IS NULL',\n ' AND \"rolled_back_at\" IS NULL',\n \"LIMIT 1\",\n ].join(\" \"),\n args: [migrationName],\n });\n return result.rows.length > 0;\n }\n\n private async readSqliteTableColumns(client: Client, tableName: string): Promise<Set<string>> {\n const result = await client.execute(`PRAGMA table_info(\"${tableName}\")`);\n return new Set(result.rows.map((row) => String(row.name)));\n }\n\n private async ensureNormalizedRuntimeRepairArtifacts(client: Client): Promise<void> {\n await client.execute(`\n CREATE TABLE IF NOT EXISTS \"RunWorkItem\" (\n \"work_item_id\" TEXT NOT NULL PRIMARY KEY,\n \"run_id\" TEXT NOT NULL,\n \"workflow_id\" TEXT NOT NULL,\n \"status\" TEXT NOT NULL,\n \"target_node_id\" TEXT NOT NULL,\n \"batch_id\" TEXT NOT NULL,\n \"queue_name\" TEXT,\n \"claim_token\" TEXT,\n \"claimed_by\" TEXT,\n \"claimed_at\" TEXT,\n \"available_at\" TEXT NOT NULL,\n \"enqueued_at\" TEXT NOT NULL,\n \"completed_at\" TEXT,\n \"failed_at\" TEXT,\n \"source_instance_id\" TEXT,\n \"parent_instance_id\" TEXT,\n \"items_in\" INTEGER NOT NULL,\n \"inputs_by_port_json\" TEXT NOT NULL,\n \"error_json\" TEXT,\n CONSTRAINT \"RunWorkItem_run_id_fkey\" FOREIGN KEY (\"run_id\") REFERENCES \"Run\"(\"run_id\") ON DELETE CASCADE ON UPDATE CASCADE\n )\n `);\n await client.execute(`\n CREATE INDEX IF NOT EXISTS \"RunWorkItem_run_id_status_available_at_idx\"\n ON \"RunWorkItem\"(\"run_id\", \"status\", \"available_at\")\n `);\n await client.execute(`\n CREATE INDEX IF NOT EXISTS \"RunWorkItem_run_id_target_node_id_batch_id_idx\"\n ON \"RunWorkItem\"(\"run_id\", \"target_node_id\", \"batch_id\")\n `);\n await client.execute(`\n CREATE TABLE IF NOT EXISTS \"RunSlotProjection\" (\n \"run_id\" TEXT NOT NULL PRIMARY KEY,\n \"workflow_id\" TEXT NOT NULL,\n \"revision\" INTEGER NOT NULL,\n \"updated_at\" TEXT NOT NULL,\n \"slot_states_json\" TEXT NOT NULL,\n CONSTRAINT \"RunSlotProjection_run_id_fkey\" FOREIGN KEY (\"run_id\") REFERENCES \"Run\"(\"run_id\") ON DELETE CASCADE ON UPDATE CASCADE\n )\n `);\n await client.execute(`\n CREATE INDEX IF NOT EXISTS \"RunSlotProjection_workflow_id_updated_at_idx\"\n ON \"RunSlotProjection\"(\"workflow_id\", \"updated_at\")\n `);\n await client.execute(`\n INSERT OR IGNORE INTO \"RunSlotProjection\" (\n \"run_id\",\n \"workflow_id\",\n \"revision\",\n \"updated_at\",\n \"slot_states_json\"\n )\n SELECT\n \"run_id\",\n \"workflow_id\",\n \"revision\",\n \"updated_at\",\n json_object('slotStatesByNodeId', json('{}'))\n FROM \"Run\"\n `);\n }\n\n private async cleanupNormalizedRuntimeLegacyArtifacts(databaseFilePath: string): Promise<void> {\n const { createClient } = await import(\"@libsql/client\");\n const client = createClient({ url: this.sqliteFilePathToDatabaseUrl(databaseFilePath) });\n try {\n const runColumns = await this.readSqliteTableColumns(client, \"Run\");\n const hasNormalizedRunShape =\n runColumns.has(\"finished_at\") &&\n runColumns.has(\"revision\") &&\n runColumns.has(\"outputs_by_node_json\") &&\n !runColumns.has(\"state_json\");\n if (!hasNormalizedRunShape) {\n return;\n }\n const runSlotProjectionColumns = await this.readSqliteTableColumns(client, \"RunSlotProjection\");\n await client.execute('DROP TABLE IF EXISTS \"Run_legacy\"');\n if (runSlotProjectionColumns.size > 0) {\n await client.execute('DROP TABLE IF EXISTS \"RunProjection\"');\n }\n } finally {\n client.close();\n }\n }\n\n private sqliteFilePathToDatabaseUrl(databaseFilePath: string): string {\n return `file:${path.resolve(databaseFilePath)}`;\n }\n\n private createProcessEnvironment(\n databaseUrl: string,\n provider: \"postgresql\" | \"sqlite\",\n env?: Readonly<NodeJS.ProcessEnv>,\n ): NodeJS.ProcessEnv {\n return {\n ...process.env,\n ...(env ?? {}),\n DATABASE_URL: databaseUrl,\n CODEMATION_PRISMA_PROVIDER: provider,\n };\n }\n\n private resolvePrismaCliPath(env: Readonly<NodeJS.ProcessEnv>): string {\n const configuredPath = env.CODEMATION_PRISMA_CLI_PATH;\n if (configuredPath && existsSync(configuredPath)) {\n return configuredPath;\n }\n const packageRoot = this.resolvePackageRoot(env);\n const packageManagerCandidates = [\n path.resolve(process.cwd(), \"node_modules\", \"prisma\", \"build\", \"index.js\"),\n path.resolve(packageRoot, \"node_modules\", \"prisma\", \"build\", \"index.js\"),\n ];\n for (const candidate of packageManagerCandidates) {\n if (existsSync(candidate)) {\n return candidate;\n }\n }\n try {\n return this.require.resolve(\"prisma/build/index.js\", {\n paths: [process.cwd(), packageRoot],\n });\n } catch {\n throw new Error(\n \"Unable to resolve the Prisma CLI required for startup migrations. Ensure `prisma` is installed.\",\n );\n }\n }\n\n private resolveAbsolutePrismaConfigPath(env: Readonly<NodeJS.ProcessEnv>): string {\n const configuredPath = env.CODEMATION_PRISMA_CONFIG_PATH;\n const packageRoot = this.resolvePackageRoot(env);\n if (configuredPath) {\n return path.isAbsolute(configuredPath) ? configuredPath : path.resolve(packageRoot, configuredPath);\n }\n return path.resolve(packageRoot, \"prisma.config.ts\");\n }\n\n private async ensureSqliteParentDirectoryExists(databaseFilePath: string): Promise<void> {\n await mkdir(path.dirname(databaseFilePath), { recursive: true });\n }\n\n private createDeployError(exitCode: number | null, stdout: string, stderr: string): Error {\n const output = stderr.trim() || stdout.trim();\n if (!output) {\n return new Error(`Prisma migrate deploy failed during startup with exit code ${exitCode ?? \"unknown\"}.`);\n }\n return new Error(`Prisma migrate deploy failed during startup with exit code ${exitCode ?? \"unknown\"}.\\n${output}`);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAeA,IAAa,4BAAb,MAAa,0BAA0B;CACrC,OAAwB,iCAAiC;CACzD,AAAiB,UAAU,cAAc,OAAO,KAAK,IAAI;CAEzD,MAAM,kBAAkB,aAAmC,KAAkD;AAC3G,MAAI,YAAY,SAAS,OACvB;AAEF,MAAI,YAAY,SAAS,cAAc;AACrC,SAAM,KAAK,eAAe;IAAE,aAAa,YAAY;IAAa;IAAK,CAAC;AACxE;;AAEF,QAAM,KAAK,aAAa;GAAE,kBAAkB,YAAY;GAAkB;GAAK,CAAC;;CAGlF,MAAM,OAAO,MAA2F;AACtG,QAAM,KAAK,eAAe,KAAK;;CAGjC,mBAAmB,MAAmC,QAAQ,KAAa;EACzE,MAAM,iBAAiB,IAAI;AAC3B,MAAI,eACF,QAAO;EAET,IAAI,mBAAmB,KAAK,QAAQ,cAAc,OAAO,KAAK,IAAI,CAAC;AACnE,OAAK,IAAI,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG;AACzC,OAAI,WAAW,KAAK,KAAK,kBAAkB,UAAU,2BAA2B,CAAC,CAC/E,QAAO;GAET,MAAM,kBAAkB,KAAK,QAAQ,iBAAiB;AACtD,OAAI,oBAAoB,iBACtB;AAEF,sBAAmB;;AAErB,QAAM,IAAI,MAAM,yDAAyD,cAAc,OAAO,KAAK,IAAI,CAAC,GAAG;;CAG7G,MAAc,aACZ,MACe;AACf,QAAM,KAAK,kCAAkC,KAAK,iBAAiB;EACnE,MAAM,cAAc,KAAK,4BAA4B,KAAK,iBAAiB;AAC3E,MAAI;AACF,SAAM,KAAK,mBAAmB;IAC5B,UAAU;IACV;IACA,KAAK,KAAK;IACX,CAAC;WACK,OAAO;AAOd,OAAI,CANc,MAAM,KAAK,qDAAqD;IAChF,kBAAkB,KAAK;IACvB;IACA,KAAK,KAAK;IACV;IACD,CAAC,CAEA,OAAM;;AAGV,QAAM,KAAK,wCAAwC,KAAK,iBAAiB;;CAG3E,MAAc,eACZ,MACe;AACf,QAAM,KAAK,mBAAmB;GAC5B,UAAU;GACV,aAAa,KAAK;GAClB,KAAK,KAAK;GACX,CAAC;;CAGJ,MAAc,mBACZ,MAKe;AACf,QAAM,KAAK,iBAAiB;GAC1B,YAAY,CAAC,WAAW,SAAS;GACjC,UAAU,KAAK;GACf,aAAa,KAAK;GAClB,KAAK,KAAK;GACX,CAAC;;CAGJ,MAAc,wBACZ,MAMe;AACf,QAAM,KAAK,iBAAiB;GAC1B,YAAY;IAAC;IAAW;IAAW;IAAa,KAAK;IAAc;GACnE,UAAU,KAAK;GACf,aAAa,KAAK;GAClB,KAAK,KAAK;GACX,CAAC;;CAGJ,MAAc,iBACZ,MAMe;EACf,MAAM,cAAc;GAAE,GAAG,QAAQ;GAAK,GAAI,KAAK,OAAO,EAAE;GAAG;EAC3D,MAAM,mBAAmB,KAAK,gCAAgC,YAAY;AAC1E,QAAM,IAAI,SAAe,SAAS,WAAW;GAC3C,MAAM,UAAU,MACd,QAAQ,UACR;IAAC,GAAG,CAAC,KAAK,qBAAqB,YAAY,EAAE,GAAG,KAAK,WAAW;IAAE;IAAY,KAAK,SAAS,iBAAiB;IAAC,EAC9G;IACE,KAAK,KAAK,QAAQ,iBAAiB;IACnC,KAAK,KAAK,yBAAyB,KAAK,aAAa,KAAK,UAAU,KAAK,IAAI;IAC7E,OAAO;KAAC;KAAU;KAAQ;KAAO;IAClC,CACF;GACD,IAAI,SAAS;GACb,IAAI,SAAS;AACb,WAAQ,OAAO,GAAG,SAAS,UAA2B;AACpD,cAAU,MAAM,UAAU;KAC1B;AACF,WAAQ,OAAO,GAAG,SAAS,UAA2B;AACpD,cAAU,MAAM,UAAU;KAC1B;AACF,WAAQ,KAAK,UAAU,UAAU;AAC/B,WAAO,MAAM;KACb;AACF,WAAQ,KAAK,UAAU,aAAa;AAClC,QAAI,aAAa,GAAG;AAClB,cAAS;AACT;;AAEF,WAAO,KAAK,kBAAkB,UAAU,QAAQ,OAAO,CAAC;KACxD;IACF;;CAGJ,MAAc,qDACZ,MAMkB;AAClB,MAAI,CAAC,KAAK,6CAA6C,KAAK,MAAM,CAChE,QAAO;AAGT,MAAI,CADa,MAAM,KAAK,sDAAsD,KAAK,iBAAiB,CAEtG,QAAO;AAET,QAAM,KAAK,wBAAwB;GACjC,UAAU;GACV,aAAa,KAAK;GAClB,eAAe,0BAA0B;GACzC,KAAK,KAAK;GACX,CAAC;AACF,QAAM,KAAK,mBAAmB;GAC5B,UAAU;GACV,aAAa,KAAK;GAClB,KAAK,KAAK;GACX,CAAC;AACF,SAAO;;CAGT,AAAQ,6CAA6C,OAAyB;AAC5E,MAAI,EAAE,iBAAiB,OACrB,QAAO;AAET,SACE,MAAM,QAAQ,SAAS,eAAe,IACtC,MAAM,QAAQ,SAAS,0BAA0B,+BAA+B;;CAIpF,MAAc,sDAAsD,kBAA4C;EAI9G,MAAM,EAAE,iBAAiB,MAAM,OAAO;EACtC,MAAM,SAAS,aAAa,EAAE,KAAK,KAAK,4BAA4B,iBAAiB,EAAE,CAAC;AACxF,MAAI;AAKF,OAAI,CAJoB,MAAM,KAAK,+BACjC,QACA,0BAA0B,+BAC3B,CAEC,QAAO;GAET,MAAM,aAAa,MAAM,KAAK,uBAAuB,QAAQ,MAAM;AAMnE,OAAI,EAJF,WAAW,IAAI,cAAc,IAC7B,WAAW,IAAI,WAAW,IAC1B,WAAW,IAAI,uBAAuB,IACtC,CAAC,WAAW,IAAI,aAAa,EAE7B,QAAO;AAET,SAAM,KAAK,uCAAuC,OAAO;AACzD,UAAO;YACC;AACR,UAAO,OAAO;;;CAIlB,MAAc,+BAA+B,QAAgB,eAAyC;AAYpG,UAXe,MAAM,OAAO,QAAQ;GAClC,KAAK;IACH;IACA;IACA;IACA;IACA;IACA;IACD,CAAC,KAAK,IAAI;GACX,MAAM,CAAC,cAAc;GACtB,CAAC,EACY,KAAK,SAAS;;CAG9B,MAAc,uBAAuB,QAAgB,WAAyC;EAC5F,MAAM,SAAS,MAAM,OAAO,QAAQ,sBAAsB,UAAU,IAAI;AACxE,SAAO,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,OAAO,IAAI,KAAK,CAAC,CAAC;;CAG5D,MAAc,uCAAuC,QAA+B;AAClF,QAAM,OAAO,QAAQ;;;;;;;;;;;;;;;;;;;;;;;MAuBnB;AACF,QAAM,OAAO,QAAQ;;;MAGnB;AACF,QAAM,OAAO,QAAQ;;;MAGnB;AACF,QAAM,OAAO,QAAQ;;;;;;;;;MASnB;AACF,QAAM,OAAO,QAAQ;;;MAGnB;AACF,QAAM,OAAO,QAAQ;;;;;;;;;;;;;;;MAenB;;CAGJ,MAAc,wCAAwC,kBAAyC;EAC7F,MAAM,EAAE,iBAAiB,MAAM,OAAO;EACtC,MAAM,SAAS,aAAa,EAAE,KAAK,KAAK,4BAA4B,iBAAiB,EAAE,CAAC;AACxF,MAAI;GACF,MAAM,aAAa,MAAM,KAAK,uBAAuB,QAAQ,MAAM;AAMnE,OAAI,EAJF,WAAW,IAAI,cAAc,IAC7B,WAAW,IAAI,WAAW,IAC1B,WAAW,IAAI,uBAAuB,IACtC,CAAC,WAAW,IAAI,aAAa,EAE7B;GAEF,MAAM,2BAA2B,MAAM,KAAK,uBAAuB,QAAQ,oBAAoB;AAC/F,SAAM,OAAO,QAAQ,sCAAoC;AACzD,OAAI,yBAAyB,OAAO,EAClC,OAAM,OAAO,QAAQ,yCAAuC;YAEtD;AACR,UAAO,OAAO;;;CAIlB,AAAQ,4BAA4B,kBAAkC;AACpE,SAAO,QAAQ,KAAK,QAAQ,iBAAiB;;CAG/C,AAAQ,yBACN,aACA,UACA,KACmB;AACnB,SAAO;GACL,GAAG,QAAQ;GACX,GAAI,OAAO,EAAE;GACb,cAAc;GACd,4BAA4B;GAC7B;;CAGH,AAAQ,qBAAqB,KAA0C;EACrE,MAAM,iBAAiB,IAAI;AAC3B,MAAI,kBAAkB,WAAW,eAAe,CAC9C,QAAO;EAET,MAAM,cAAc,KAAK,mBAAmB,IAAI;EAChD,MAAM,2BAA2B,CAC/B,KAAK,QAAQ,QAAQ,KAAK,EAAE,gBAAgB,UAAU,SAAS,WAAW,EAC1E,KAAK,QAAQ,aAAa,gBAAgB,UAAU,SAAS,WAAW,CACzE;AACD,OAAK,MAAM,aAAa,yBACtB,KAAI,WAAW,UAAU,CACvB,QAAO;AAGX,MAAI;AACF,UAAO,KAAK,QAAQ,QAAQ,yBAAyB,EACnD,OAAO,CAAC,QAAQ,KAAK,EAAE,YAAY,EACpC,CAAC;UACI;AACN,SAAM,IAAI,MACR,kGACD;;;CAIL,AAAQ,gCAAgC,KAA0C;EAChF,MAAM,iBAAiB,IAAI;EAC3B,MAAM,cAAc,KAAK,mBAAmB,IAAI;AAChD,MAAI,eACF,QAAO,KAAK,WAAW,eAAe,GAAG,iBAAiB,KAAK,QAAQ,aAAa,eAAe;AAErG,SAAO,KAAK,QAAQ,aAAa,mBAAmB;;CAGtD,MAAc,kCAAkC,kBAAyC;AACvF,QAAM,MAAM,KAAK,QAAQ,iBAAiB,EAAE,EAAE,WAAW,MAAM,CAAC;;CAGlE,AAAQ,kBAAkB,UAAyB,QAAgB,QAAuB;EACxF,MAAM,SAAS,OAAO,MAAM,IAAI,OAAO,MAAM;AAC7C,MAAI,CAAC,OACH,wBAAO,IAAI,MAAM,8DAA8D,YAAY,UAAU,GAAG;AAE1G,yBAAO,IAAI,MAAM,8DAA8D,YAAY,UAAU,KAAK,SAAS"}
|
package/dist/mapping.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "./ItemsInputNormalizer-
|
|
2
|
-
import { t as WorkflowPolicyUiPresentationFactory } from "./WorkflowPolicyUiPresentationFactory-
|
|
1
|
+
import "./ItemsInputNormalizer-CFkfNMLt.js";
|
|
2
|
+
import { t as WorkflowPolicyUiPresentationFactory } from "./WorkflowPolicyUiPresentationFactory-BNn2fvR_.js";
|
|
3
3
|
export { WorkflowPolicyUiPresentationFactory };
|
package/dist/mapping.js
CHANGED
package/dist/nextServer.d.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
import {
|
|
3
|
-
import { r as AppConfig } from "./CodemationAppContext-
|
|
1
|
+
import { n as OAuthFlowExecutor, r as RunIntentService } from "./index-ChIfeWzk.js";
|
|
2
|
+
import { A as WorkflowDefinition, D as RunIdFactory, St as WebhookInvocationMatch, _ as Item, a as BinaryStorage, g as BinaryAttachment, h as ActivationIdFactory, tt as WorkflowActivationPolicy } from "./ItemsInputNormalizer-CFkfNMLt.js";
|
|
3
|
+
import { r as AppConfig } from "./CodemationAppContext-K51b7oXe.js";
|
|
4
4
|
import { l as Logger, u as LoggerFactory } from "./CodemationWhitelabelConfig-Ca2mCUeC.js";
|
|
5
5
|
import { n as logLevelPolicyFactory, t as LogLevelPolicyFactory } from "./LogLevelPolicyFactory-ewCHLDLn.js";
|
|
6
6
|
import { a as CodemationFrontendAuthSnapshot, i as CodemationFrontendAuthProviderSnapshot, n as InternalAuthBootstrap, r as FrontendAppConfig, t as PublicFrontendBootstrap } from "./PublicFrontendBootstrap-Cev3qK46.js";
|
|
7
|
-
import "./CodemationConfigNormalizer-
|
|
8
|
-
import { a as CredentialSecretCipher, i as CredentialInstanceService, o as McpServerCatalog, r as CredentialBindingService, t as CredentialStore } from "./CredentialServices-
|
|
9
|
-
import "./CredentialContractsRegistry-
|
|
10
|
-
import "./TelemetryContracts-
|
|
7
|
+
import "./CodemationConfigNormalizer-B4rDYC9h.js";
|
|
8
|
+
import { a as CredentialSecretCipher, i as CredentialInstanceService, o as McpServerCatalog, r as CredentialBindingService, t as CredentialStore } from "./CredentialServices-B3wPyp2y.js";
|
|
9
|
+
import "./CredentialContractsRegistry-Dgu-rEXi.js";
|
|
10
|
+
import "./TelemetryContracts-DpZEODQM.js";
|
|
11
11
|
import { i as WorkflowSummary, t as WorkflowDto } from "./WorkflowViewContracts-B7aFQcIw.js";
|
|
12
|
-
import { _ as
|
|
13
|
-
import { t as AppConfigFactory } from "./AppConfigFactory-
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import { t as
|
|
17
|
-
import { t as
|
|
18
|
-
import {
|
|
12
|
+
import { S as CommandBus, _ as AppContainerLifecycle, a as CodemationHonoApiApp, b as QueryBus, c as SessionVerifier, d as WorkflowRunRetentionPruneScheduler, f as ServerLoggerFactory, g as DatabaseMigrations, i as WorkflowDebuggerOverlayRepository, l as WorkerRuntime, m as WorkflowRunRepository, n as CodemationBootstrapRequest, o as BinaryHttpRouteHandler, p as LogFilter, r as ApplicationTokens, s as ServerHttpRouteParams, t as CodemationPluginListMerger, u as FrontendRuntime, v as AppContainerFactory, y as WorkflowWebsocketServer } from "./CodemationPluginListMerger-DS6I3Xe0.js";
|
|
13
|
+
import { t as AppConfigFactory } from "./AppConfigFactory-DncmwCD1.js";
|
|
14
|
+
import "./PrismaMigrationDeployer-DdEcXXVi.js";
|
|
15
|
+
import "./InternalHonoApiRouteRegistrar-Ce1yxpnO.js";
|
|
16
|
+
import { n as InternalAuthBootstrapFactory, r as FrontendAppConfigFactory, t as PublicFrontendBootstrapFactory } from "./PublicFrontendBootstrapFactory-ClEjZP74.js";
|
|
17
|
+
import { t as WorkflowPolicyUiPresentationFactory } from "./WorkflowPolicyUiPresentationFactory-BNn2fvR_.js";
|
|
18
|
+
import { t as PairingConfig } from "./pairing.types-D9Bjn98U.js";
|
|
19
19
|
|
|
20
20
|
//#region src/application/dev/DevBootstrapSummaryJson.types.d.ts
|
|
21
21
|
type DevBootstrapSummaryJson = Readonly<{
|
|
@@ -132,31 +132,6 @@ declare class RequestToWebhookItemMapper {
|
|
|
132
132
|
private toQuery;
|
|
133
133
|
}
|
|
134
134
|
//#endregion
|
|
135
|
-
//#region src/presentation/http/ServerHttpRouteParams.d.ts
|
|
136
|
-
type ServerHttpRouteParams = Readonly<Record<string, string>>;
|
|
137
|
-
//#endregion
|
|
138
|
-
//#region src/presentation/http/routeHandlers/BinaryHttpRouteHandlerFactory.d.ts
|
|
139
|
-
declare class BinaryHttpRouteHandler {
|
|
140
|
-
private readonly queryBus;
|
|
141
|
-
private readonly commandBus;
|
|
142
|
-
private readonly binaryStorage;
|
|
143
|
-
constructor(queryBus: QueryBus, commandBus: CommandBus, binaryStorage: BinaryStorage);
|
|
144
|
-
getRunBinaryContent(_: Request, params: ServerHttpRouteParams): Promise<Response>;
|
|
145
|
-
getWorkflowOverlayBinaryContent(_: Request, params: ServerHttpRouteParams): Promise<Response>;
|
|
146
|
-
postWorkflowDebuggerOverlayBinaryUpload(request: Request, params: ServerHttpRouteParams): Promise<Response>;
|
|
147
|
-
private createBinaryResponse;
|
|
148
|
-
private createContentDisposition;
|
|
149
|
-
private escapeFilename;
|
|
150
|
-
}
|
|
151
|
-
//#endregion
|
|
152
|
-
//#region src/presentation/http/hono/CodemationHonoApiAppFactory.d.ts
|
|
153
|
-
declare class CodemationHonoApiApp {
|
|
154
|
-
private readonly app;
|
|
155
|
-
constructor(sessionVerifier: SessionVerifier, registrars: ReadonlyArray<HonoApiRouteRegistrar>, binaryHttpRouteHandler: BinaryHttpRouteHandler, internalRegistrars: ReadonlyArray<InternalHonoApiRouteRegistrar>, corsMiddlewareList: ReadonlyArray<ManagedCorsMiddleware>);
|
|
156
|
-
getHono(): Hono;
|
|
157
|
-
fetch(request: Request): Response | Promise<Response>;
|
|
158
|
-
}
|
|
159
|
-
//#endregion
|
|
160
135
|
//#region src/presentation/http/routeHandlers/CredentialHttpRouteHandler.d.ts
|
|
161
136
|
declare class CredentialHttpRouteHandler {
|
|
162
137
|
private readonly queryBus;
|
|
@@ -167,6 +142,7 @@ declare class CredentialHttpRouteHandler {
|
|
|
167
142
|
getCredentialTypes(): Promise<Response>;
|
|
168
143
|
getCredentialFieldEnvStatus(): Promise<Response>;
|
|
169
144
|
getCredentialInstances(): Promise<Response>;
|
|
145
|
+
getCredentialApps(): Promise<Response>;
|
|
170
146
|
getCredentialInstance(request: Request, params: ServerHttpRouteParams): Promise<Response>;
|
|
171
147
|
postCredentialInstance(request: Request): Promise<Response>;
|
|
172
148
|
putCredentialInstance(request: Request, params: ServerHttpRouteParams): Promise<Response>;
|
package/dist/nextServer.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { n as logLevelPolicyFactory, t as LogLevelPolicyFactory } from "./LogLevelPolicyFactory-DCUzIN6G.js";
|
|
2
|
-
import "./ApiPaths-
|
|
2
|
+
import "./ApiPaths-DCvrlIjg.js";
|
|
3
3
|
import { a as FilteringLogger, i as PerformanceLogPolicy, n as PerformanceLogPolicyFactory, r as performanceLogPolicyFactory, t as ServerLoggerFactory } from "./ServerLoggerFactory-Ckk52S3w.js";
|
|
4
4
|
import "./decorateParam-BWxkAUSj.js";
|
|
5
5
|
import "./decorate-CXWmflG_.js";
|
|
6
|
-
import { a as CredentialInstanceService, i as CredentialBindingService, m as ApplicationTokens } from "./CredentialServices-
|
|
6
|
+
import { a as CredentialInstanceService, i as CredentialBindingService, m as ApplicationTokens } from "./CredentialServices-Bios0dM8.js";
|
|
7
7
|
import "./CodemationTsyringeTypeInfoRegistrar-Bj6FJYFz.js";
|
|
8
|
-
import { A as WorkflowDefinitionMapper, C as CodemationHonoApiApp, D as FrontendAppConfigFactory, E as InternalAuthBootstrapFactory, P as RunBinaryAttachmentLookupService, S as CredentialHttpRouteHandler, T as PublicFrontendBootstrapFactory, _ as WorkflowHttpRouteHandler, b as RunHttpRouteHandler, d as FrontendRuntime, h as WorkflowRunRetentionPruneScheduler, k as WorkflowWebsocketServer, m as AppContainerLifecycle, p as DatabaseMigrations, t as AppContainerFactory, u as WorkerRuntime, v as WebhookHttpRouteHandler, w as BinaryHttpRouteHandler, x as OAuth2HttpRouteHandler, y as RequestToWebhookItemMapper } from "./AppContainerFactory-
|
|
9
|
-
import
|
|
10
|
-
import "./
|
|
11
|
-
import { t as AppConfigFactory } from "./AppConfigFactory-
|
|
8
|
+
import { A as WorkflowDefinitionMapper, C as CodemationHonoApiApp, D as FrontendAppConfigFactory, E as InternalAuthBootstrapFactory, P as RunBinaryAttachmentLookupService, S as CredentialHttpRouteHandler, T as PublicFrontendBootstrapFactory, _ as WorkflowHttpRouteHandler, b as RunHttpRouteHandler, d as FrontendRuntime, h as WorkflowRunRetentionPruneScheduler, k as WorkflowWebsocketServer, m as AppContainerLifecycle, p as DatabaseMigrations, t as AppContainerFactory, u as WorkerRuntime, v as WebhookHttpRouteHandler, w as BinaryHttpRouteHandler, x as OAuth2HttpRouteHandler, y as RequestToWebhookItemMapper } from "./AppContainerFactory-jpYXGZGe.js";
|
|
9
|
+
import "./InternalPingRegistrar-BavAAnvk.js";
|
|
10
|
+
import { t as WorkflowPolicyUiPresentationFactory } from "./WorkflowPolicyUiPresentationFactory-DfvD2VHk.js";
|
|
11
|
+
import { t as AppConfigFactory } from "./AppConfigFactory-D4LL1aOR.js";
|
|
12
12
|
import { n as CodemationBootstrapRequest, t as CodemationPluginListMerger } from "./CodemationPluginListMerger-D1B1IEbt.js";
|
|
13
13
|
|
|
14
14
|
export { AppConfigFactory, AppContainerFactory, AppContainerLifecycle, ApplicationTokens, BinaryHttpRouteHandler, CodemationBootstrapRequest, CodemationHonoApiApp, CodemationPluginListMerger, CredentialBindingService, CredentialHttpRouteHandler, CredentialInstanceService, DatabaseMigrations, FilteringLogger, FrontendAppConfigFactory, FrontendRuntime, InternalAuthBootstrapFactory, LogLevelPolicyFactory, OAuth2HttpRouteHandler, PerformanceLogPolicy, PerformanceLogPolicyFactory, PublicFrontendBootstrapFactory, RequestToWebhookItemMapper, RunBinaryAttachmentLookupService, RunHttpRouteHandler, ServerLoggerFactory, WebhookHttpRouteHandler, WorkerRuntime, WorkflowDefinitionMapper, WorkflowHttpRouteHandler, WorkflowPolicyUiPresentationFactory, WorkflowRunRetentionPruneScheduler, WorkflowWebsocketServer, logLevelPolicyFactory, performanceLogPolicyFactory };
|
package/dist/pairing.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import "./index-
|
|
2
|
-
import {
|
|
1
|
+
import "./index-ChIfeWzk.js";
|
|
2
|
+
import { G as TypeToken } from "./ItemsInputNormalizer-CFkfNMLt.js";
|
|
3
3
|
import { t as InternalHonoApiRouteRegistrar } from "./InternalHonoApiRouteRegistrar-Ce1yxpnO.js";
|
|
4
|
-
import { i as PairingVerificationSuccess, n as PairingVerificationFailure, r as PairingVerificationResult, t as PairingConfig } from "./pairing.types-
|
|
4
|
+
import { i as PairingVerificationSuccess, n as PairingVerificationFailure, r as PairingVerificationResult, t as PairingConfig } from "./pairing.types-D9Bjn98U.js";
|
|
5
5
|
import { Hono, MiddlewareHandler } from "hono";
|
|
6
6
|
|
|
7
7
|
//#region src/pairing/HmacRequestSigner.d.ts
|
|
@@ -10,7 +10,7 @@ interface SignedHeaders {
|
|
|
10
10
|
}
|
|
11
11
|
declare class HmacRequestSigner {
|
|
12
12
|
private readonly config;
|
|
13
|
-
constructor(config
|
|
13
|
+
constructor(config?: PairingConfig | null);
|
|
14
14
|
sign(method: string, urlOrPath: string, body: string): SignedHeaders;
|
|
15
15
|
}
|
|
16
16
|
//#endregion
|
|
@@ -29,19 +29,38 @@ declare class PairedFetch {
|
|
|
29
29
|
delete(url: string): Promise<Response>;
|
|
30
30
|
}
|
|
31
31
|
//#endregion
|
|
32
|
+
//#region src/pairing/HmacNonceStore.d.ts
|
|
33
|
+
/**
|
|
34
|
+
* Seam for durable HMAC replay-protection nonce storage (T6 security fix).
|
|
35
|
+
*
|
|
36
|
+
* The default in-process store (InMemoryHmacNonceStore) clears on restart, allowing
|
|
37
|
+
* replay within the timestamp window. PrismaHmacNonceStore provides durability.
|
|
38
|
+
*/
|
|
39
|
+
interface HmacNonceStore {
|
|
40
|
+
/**
|
|
41
|
+
* Atomically record a nonce if it has not been seen before.
|
|
42
|
+
* Returns `true` if the nonce was new (request should proceed),
|
|
43
|
+
* `false` if the nonce was already present (replay — reject).
|
|
44
|
+
*/
|
|
45
|
+
recordIfNew(nonce: string, expiresAt: Date): Promise<boolean>;
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
32
48
|
//#region src/pairing/IncomingHmacVerifier.d.ts
|
|
33
49
|
/**
|
|
34
50
|
* Verifies incoming HMAC-signed requests from the control plane.
|
|
35
51
|
* Mirrors the control-plane HmacVerifier — both sides follow docs/pairing-protocol.md.
|
|
52
|
+
*
|
|
53
|
+
* Security (T6): The nonce store is injected and defaults to PrismaHmacNonceStore in
|
|
54
|
+
* managed mode so replay protection survives process restarts within the 300-second
|
|
55
|
+
* timestamp window.
|
|
36
56
|
*/
|
|
37
57
|
declare class IncomingHmacVerifier {
|
|
38
58
|
private readonly config;
|
|
39
|
-
private readonly
|
|
59
|
+
private readonly nonceStore;
|
|
40
60
|
private readonly nonceTtlSeconds;
|
|
41
|
-
constructor(config: PairingConfig);
|
|
42
|
-
verify(method: string, url: string, body: string, authHeader: string | null): PairingVerificationResult
|
|
61
|
+
constructor(config: (PairingConfig | null) | undefined, nonceStore: HmacNonceStore);
|
|
62
|
+
verify(method: string, url: string, body: string, authHeader: string | null): Promise<PairingVerificationResult>;
|
|
43
63
|
private parseHeader;
|
|
44
|
-
private pruneExpiredNonces;
|
|
45
64
|
}
|
|
46
65
|
//#endregion
|
|
47
66
|
//#region src/pairing/InternalHmacAuthMiddleware.d.ts
|
package/dist/pairing.js
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
import "./decorateParam-BWxkAUSj.js";
|
|
2
|
-
import "./decorate-CXWmflG_.js";
|
|
3
|
-
import { a as
|
|
2
|
+
import { t as __decorate } from "./decorate-CXWmflG_.js";
|
|
3
|
+
import { a as PairingConfigFactory, c as PairingConfigToken, n as InternalHmacAuthMiddleware, o as PairedFetch, r as IncomingHmacVerifier, s as HmacRequestSigner, t as InternalPingRegistrar } from "./InternalPingRegistrar-BavAAnvk.js";
|
|
4
|
+
import { injectable } from "@codemation/core";
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
//#region src/pairing/InMemoryHmacNonceStore.ts
|
|
7
|
+
let InMemoryHmacNonceStore = class InMemoryHmacNonceStore$1 {
|
|
8
|
+
store = /* @__PURE__ */ new Map();
|
|
9
|
+
async recordIfNew(nonce, expiresAt) {
|
|
10
|
+
const nowSec = Math.floor(Date.now() / 1e3);
|
|
11
|
+
for (const [key, expirySec] of this.store.entries()) if (expirySec <= nowSec) this.store.delete(key);
|
|
12
|
+
if (this.store.has(nonce)) return false;
|
|
13
|
+
this.store.set(nonce, Math.floor(expiresAt.getTime() / 1e3));
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
InMemoryHmacNonceStore = __decorate([injectable()], InMemoryHmacNonceStore);
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { HmacRequestSigner, IncomingHmacVerifier, InternalHmacAuthMiddleware, InternalPingRegistrar, PairedFetch, PairingConfigFactory, PairingConfigToken };
|
|
21
|
+
//# sourceMappingURL=pairing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pairing.js","names":["InMemoryHmacNonceStore"],"sources":["../src/pairing/InMemoryHmacNonceStore.ts"],"sourcesContent":["import { injectable } from \"@codemation/core\";\nimport type { HmacNonceStore } from \"./HmacNonceStore\";\n\n/**\n * In-memory HMAC nonce store for unit tests and non-managed mode.\n *\n * NOTE: Nonces are lost on process restart; this is intentional for non-managed\n * mode where replay risk is low. Use PrismaHmacNonceStore in managed mode.\n */\n@injectable()\nexport class InMemoryHmacNonceStore implements HmacNonceStore {\n private readonly store = new Map<string, number>();\n\n async recordIfNew(nonce: string, expiresAt: Date): Promise<boolean> {\n const nowSec = Math.floor(Date.now() / 1000);\n // Prune expired entries on each call (mirrors original in-process behaviour)\n for (const [key, expirySec] of this.store.entries()) {\n if (expirySec <= nowSec) this.store.delete(key);\n }\n if (this.store.has(nonce)) return false;\n this.store.set(nonce, Math.floor(expiresAt.getTime() / 1000));\n return true;\n }\n}\n"],"mappings":";;;;;;AAUO,mCAAMA,yBAAiD;CAC5D,AAAiB,wBAAQ,IAAI,KAAqB;CAElD,MAAM,YAAY,OAAe,WAAmC;EAClE,MAAM,SAAS,KAAK,MAAM,KAAK,KAAK,GAAG,IAAK;AAE5C,OAAK,MAAM,CAAC,KAAK,cAAc,KAAK,MAAM,SAAS,CACjD,KAAI,aAAa,OAAQ,MAAK,MAAM,OAAO,IAAI;AAEjD,MAAI,KAAK,MAAM,IAAI,MAAM,CAAE,QAAO;AAClC,OAAK,MAAM,IAAI,OAAO,KAAK,MAAM,UAAU,SAAS,GAAG,IAAK,CAAC;AAC7D,SAAO;;;qCAZV,YAAY"}
|
|
@@ -16,4 +16,4 @@ type PairingVerificationSuccess = {
|
|
|
16
16
|
type PairingVerificationResult = PairingVerificationSuccess | PairingVerificationFailure;
|
|
17
17
|
//#endregion
|
|
18
18
|
export { PairingVerificationSuccess as i, PairingVerificationFailure as n, PairingVerificationResult as r, PairingConfig as t };
|
|
19
|
-
//# sourceMappingURL=pairing.types-
|
|
19
|
+
//# sourceMappingURL=pairing.types-D9Bjn98U.d.ts.map
|