@shipfox/api-definitions 7.1.0 → 9.0.1
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 +4 -4
- package/CHANGELOG.md +71 -0
- package/dist/config.d.ts +0 -4
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -14
- package/dist/config.js.map +1 -1
- package/dist/core/entities/integration-context.d.ts +12 -1
- package/dist/core/entities/integration-context.d.ts.map +1 -1
- package/dist/core/entities/integration-context.js.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/integrations.d.ts +1 -1
- package/dist/core/integrations.d.ts.map +1 -1
- package/dist/core/integrations.js +1 -1
- package/dist/core/integrations.js.map +1 -1
- package/dist/core/parse-definition.d.ts +3 -3
- package/dist/core/parse-definition.d.ts.map +1 -1
- package/dist/core/parse-definition.js.map +1 -1
- package/dist/core/sync-definitions.d.ts +3 -0
- package/dist/core/sync-definitions.d.ts.map +1 -1
- package/dist/core/sync-definitions.js +11 -5
- package/dist/core/sync-definitions.js.map +1 -1
- package/dist/core/validate-definition.d.ts +3 -3
- package/dist/core/validate-definition.d.ts.map +1 -1
- package/dist/core/validate-definition.js +3 -3
- package/dist/core/validate-definition.js.map +1 -1
- package/dist/core/workflow-model/normalize-agent-integrations.d.ts.map +1 -1
- package/dist/core/workflow-model/normalize-agent-integrations.js.map +1 -1
- package/dist/core/workflow-model/normalize-jobs.d.ts +2 -2
- package/dist/core/workflow-model/normalize-jobs.d.ts.map +1 -1
- package/dist/core/workflow-model/normalize-jobs.js +9 -11
- package/dist/core/workflow-model/normalize-jobs.js.map +1 -1
- package/dist/core/workflow-model/normalize-workflow-document.d.ts +3 -3
- package/dist/core/workflow-model/normalize-workflow-document.d.ts.map +1 -1
- package/dist/core/workflow-model/normalize-workflow-document.js +2 -4
- package/dist/core/workflow-model/normalize-workflow-document.js.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/presentation/routes/create-definition.d.ts +4 -2
- package/dist/presentation/routes/create-definition.d.ts.map +1 -1
- package/dist/presentation/routes/create-definition.js +5 -1
- package/dist/presentation/routes/create-definition.js.map +1 -1
- package/dist/presentation/routes/get-definition.d.ts +1 -1
- package/dist/presentation/routes/get-definition.d.ts.map +1 -1
- package/dist/presentation/routes/get-definition.js.map +1 -1
- package/dist/presentation/routes/index.js +2 -2
- package/dist/presentation/routes/index.js.map +1 -1
- package/dist/presentation/routes/list-definitions.d.ts +1 -1
- package/dist/presentation/routes/list-definitions.d.ts.map +1 -1
- package/dist/presentation/routes/list-definitions.js.map +1 -1
- package/dist/presentation/routes/project-access.d.ts +1 -1
- package/dist/presentation/routes/project-access.d.ts.map +1 -1
- package/dist/presentation/routes/project-access.js.map +1 -1
- package/dist/presentation/routes/validate-definition.d.ts +2 -1
- package/dist/presentation/routes/validate-definition.d.ts.map +1 -1
- package/dist/presentation/routes/validate-definition.js +26 -22
- package/dist/presentation/routes/validate-definition.js.map +1 -1
- package/dist/temporal/activities/sync-activities.d.ts +3 -2
- package/dist/temporal/activities/sync-activities.d.ts.map +1 -1
- package/dist/temporal/activities/sync-activities.js +4 -3
- package/dist/temporal/activities/sync-activities.js.map +1 -1
- package/dist/tsconfig.test.tsbuildinfo +1 -1
- package/package.json +23 -24
- package/src/config.ts +1 -19
- package/src/core/entities/integration-context.ts +13 -5
- package/src/core/index.ts +4 -1
- package/src/core/integrations.ts +1 -1
- package/src/core/parse-definition.test.ts +6 -1
- package/src/core/parse-definition.ts +3 -3
- package/src/core/sync-definitions.test.ts +12 -8
- package/src/core/sync-definitions.ts +15 -8
- package/src/core/validate-definition.test.ts +18 -4
- package/src/core/validate-definition.ts +5 -6
- package/src/core/workflow-model/normalize-agent-integrations.ts +7 -1
- package/src/core/workflow-model/normalize-jobs.ts +22 -23
- package/src/core/workflow-model/normalize-workflow-document.test.ts +37 -18
- package/src/core/workflow-model/normalize-workflow-document.ts +4 -9
- package/src/db/definitions.test.ts +2 -1
- package/src/db/schema/definitions.test.ts +2 -1
- package/src/index.ts +8 -5
- package/src/presentation/dto/definition.test.ts +2 -1
- package/src/presentation/routes/create-definition.test.ts +10 -3
- package/src/presentation/routes/create-definition.ts +7 -3
- package/src/presentation/routes/get-definition.test.ts +1 -1
- package/src/presentation/routes/get-definition.ts +1 -1
- package/src/presentation/routes/index.test.ts +6 -2
- package/src/presentation/routes/index.ts +2 -2
- package/src/presentation/routes/list-definitions.test.ts +1 -1
- package/src/presentation/routes/list-definitions.ts +1 -1
- package/src/presentation/routes/project-access.ts +1 -1
- package/src/presentation/routes/validate-definition.test.ts +8 -2
- package/src/presentation/routes/validate-definition.ts +27 -22
- package/src/temporal/activities/sync-activities.test.ts +17 -14
- package/src/temporal/activities/sync-activities.ts +10 -2
- package/test/agent-validation-catalog.ts +26 -0
- package/test/factories/definition.ts +2 -1
- package/test/published/workflow-source-bundle.mjs +17 -0
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/presentation/routes/create-definition.ts"],"sourcesContent":["import {\n createDefinitionBodySchema,\n definitionResponseSchema,\n definitionValidationErrorSchema,\n} from '@shipfox/api-definitions-dto';\nimport type {IntegrationsModuleClient} from '@shipfox/api-integration-core-dto';\nimport type {ProjectsModuleClient} from '@shipfox/api-projects-dto';\nimport {ClientError, defineRoute} from '@shipfox/node-fastify';\nimport {z} from 'zod';\nimport {DefinitionParseError} from '#core/errors.js';\nimport {hasAgentStepIntegrations} from '#core/has-agent-step-integrations.js';\nimport {loadIntegrationValidationContext} from '#core/integrations.js';\nimport {parseDefinition} from '#core/parse-definition.js';\nimport {upsertDefinition} from '#db/definitions.js';\nimport {toDefinitionDto} from '#presentation/dto/index.js';\nimport {requireProjectAccess} from './project-access.js';\n\nexport interface CreateDefinitionRouteOptions {\n projects: ProjectsModuleClient;\n integrations?: IntegrationsModuleClient;\n}\n\nexport function buildCreateDefinitionRoute(options: CreateDefinitionRouteOptions) {\n return defineRoute({\n method: 'POST',\n path: '/',\n description: 'Create or update a workflow definition',\n schema: {\n body: createDefinitionBodySchema,\n response: {\n 200: definitionResponseSchema,\n 400: z.object({\n code: z.string(),\n message: z.string().optional(),\n details: z.array(definitionValidationErrorSchema).optional(),\n }),\n 404: z.object({code: z.string()}),\n },\n },\n errorHandler: (error, _request, _reply) => {\n if (error instanceof DefinitionParseError) {\n throw new ClientError(error.message, 'invalid-workflow-definition', {\n details: error.details,\n status: 400,\n });\n }\n throw error;\n },\n handler: async (request) => {\n const {project_id: projectId, config_path, source, yaml: yamlString, sha, ref} = request.body;\n const project = await requireProjectAccess(request, projectId, options.projects);\n\n const structurallyParsed = parseDefinition(yamlString);\n const {integrations} = options;\n const parsed =\n integrations !== undefined && hasAgentStepIntegrations(structurallyParsed.document)\n ? parseDefinition(yamlString, {\n integrationValidationContext: await loadIntegrationValidationContext(\n integrations,\n project.workspaceId,\n project.sourceConnectionId,\n ),\n })\n : structurallyParsed;\n\n const definition = await upsertDefinition({\n projectId,\n workspaceId: project.workspaceId,\n configPath: config_path,\n source,\n name: parsed.document.name,\n document: parsed.document,\n model: parsed.model,\n sourceSnapshot: parsed.sourceSnapshot,\n sha,\n ref,\n });\n\n return toDefinitionDto(definition);\n },\n });\n}\n"],"names":["createDefinitionBodySchema","definitionResponseSchema","definitionValidationErrorSchema","ClientError","defineRoute","z","DefinitionParseError","hasAgentStepIntegrations","loadIntegrationValidationContext","parseDefinition","upsertDefinition","toDefinitionDto","requireProjectAccess","buildCreateDefinitionRoute","options","method","path","description","schema","body","response","object","code","string","message","optional","details","array","errorHandler","error","_request","_reply","status","handler","request","project_id","projectId","config_path","source","yaml","yamlString","sha","ref","project","projects","structurallyParsed","integrations","parsed","undefined","document","integrationValidationContext","workspaceId","sourceConnectionId","definition","configPath","name","model","sourceSnapshot"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/presentation/routes/create-definition.ts"],"sourcesContent":["import type {AgentInterModuleClient} from '@shipfox/api-agent-dto/inter-module';\nimport {\n createDefinitionBodySchema,\n definitionResponseSchema,\n definitionValidationErrorSchema,\n} from '@shipfox/api-definitions-dto';\nimport type {IntegrationsModuleClient} from '@shipfox/api-integration-core-dto/inter-module';\nimport type {ProjectsModuleClient} from '@shipfox/api-projects-dto/inter-module';\nimport {ClientError, defineRoute} from '@shipfox/node-fastify';\nimport {z} from 'zod';\nimport {DefinitionParseError} from '#core/errors.js';\nimport {hasAgentStepIntegrations} from '#core/has-agent-step-integrations.js';\nimport {loadIntegrationValidationContext} from '#core/integrations.js';\nimport {parseDefinition} from '#core/parse-definition.js';\nimport {upsertDefinition} from '#db/definitions.js';\nimport {toDefinitionDto} from '#presentation/dto/index.js';\nimport {requireProjectAccess} from './project-access.js';\n\nexport interface CreateDefinitionRouteOptions {\n projects: ProjectsModuleClient;\n agent: AgentInterModuleClient;\n integrations?: IntegrationsModuleClient;\n}\n\nexport function buildCreateDefinitionRoute(options: CreateDefinitionRouteOptions) {\n return defineRoute({\n method: 'POST',\n path: '/',\n description: 'Create or update a workflow definition',\n schema: {\n body: createDefinitionBodySchema,\n response: {\n 200: definitionResponseSchema,\n 400: z.object({\n code: z.string(),\n message: z.string().optional(),\n details: z.array(definitionValidationErrorSchema).optional(),\n }),\n 404: z.object({code: z.string()}),\n },\n },\n errorHandler: (error, _request, _reply) => {\n if (error instanceof DefinitionParseError) {\n throw new ClientError(error.message, 'invalid-workflow-definition', {\n details: error.details,\n status: 400,\n });\n }\n throw error;\n },\n handler: async (request) => {\n const {project_id: projectId, config_path, source, yaml: yamlString, sha, ref} = request.body;\n const project = await requireProjectAccess(request, projectId, options.projects);\n\n const agentValidationCatalog = await options.agent.getValidationCatalog({});\n const structurallyParsed = parseDefinition(yamlString, {agentValidationCatalog});\n const {integrations} = options;\n const parsed =\n integrations !== undefined && hasAgentStepIntegrations(structurallyParsed.document)\n ? parseDefinition(yamlString, {\n agentValidationCatalog,\n integrationValidationContext: await loadIntegrationValidationContext(\n integrations,\n project.workspaceId,\n project.sourceConnectionId,\n ),\n })\n : structurallyParsed;\n\n const definition = await upsertDefinition({\n projectId,\n workspaceId: project.workspaceId,\n configPath: config_path,\n source,\n name: parsed.document.name,\n document: parsed.document,\n model: parsed.model,\n sourceSnapshot: parsed.sourceSnapshot,\n sha,\n ref,\n });\n\n return toDefinitionDto(definition);\n },\n });\n}\n"],"names":["createDefinitionBodySchema","definitionResponseSchema","definitionValidationErrorSchema","ClientError","defineRoute","z","DefinitionParseError","hasAgentStepIntegrations","loadIntegrationValidationContext","parseDefinition","upsertDefinition","toDefinitionDto","requireProjectAccess","buildCreateDefinitionRoute","options","method","path","description","schema","body","response","object","code","string","message","optional","details","array","errorHandler","error","_request","_reply","status","handler","request","project_id","projectId","config_path","source","yaml","yamlString","sha","ref","project","projects","agentValidationCatalog","agent","getValidationCatalog","structurallyParsed","integrations","parsed","undefined","document","integrationValidationContext","workspaceId","sourceConnectionId","definition","configPath","name","model","sourceSnapshot"],"mappings":"AACA,SACEA,0BAA0B,EAC1BC,wBAAwB,EACxBC,+BAA+B,QAC1B,+BAA+B;AAGtC,SAAQC,WAAW,EAAEC,WAAW,QAAO,wBAAwB;AAC/D,SAAQC,CAAC,QAAO,MAAM;AACtB,SAAQC,oBAAoB,QAAO,kBAAkB;AACrD,SAAQC,wBAAwB,QAAO,uCAAuC;AAC9E,SAAQC,gCAAgC,QAAO,wBAAwB;AACvE,SAAQC,eAAe,QAAO,4BAA4B;AAC1D,SAAQC,gBAAgB,QAAO,qBAAqB;AACpD,SAAQC,eAAe,QAAO,6BAA6B;AAC3D,SAAQC,oBAAoB,QAAO,sBAAsB;AAQzD,OAAO,SAASC,2BAA2BC,OAAqC;IAC9E,OAAOV,YAAY;QACjBW,QAAQ;QACRC,MAAM;QACNC,aAAa;QACbC,QAAQ;YACNC,MAAMnB;YACNoB,U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OT,OAAOS,KAAK;gBACnBC,gBAAgBV,OAAOU,cAAc;gBACrCnB;gBACAC;YACF;YAEA,OAAO/B,gBAAgB6C;QACzB;IACF;AACF"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { ProjectsModuleClient } from '@shipfox/api-projects-dto';
|
|
1
|
+
import type { ProjectsModuleClient } from '@shipfox/api-projects-dto/inter-module';
|
|
2
2
|
export declare function buildGetDefinitionRoute(projects: ProjectsModuleClient): import("@shipfox/node-fastify").RouteDefinition;
|
|
3
3
|
//# sourceMappingURL=get-definition.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-definition.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/get-definition.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"get-definition.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/get-definition.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,wCAAwC,CAAC;AAOjF,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,oBAAoB,mDAyBrE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/presentation/routes/get-definition.ts"],"sourcesContent":["import {definitionResponseSchema} from '@shipfox/api-definitions-dto';\nimport type {ProjectsModuleClient} from '@shipfox/api-projects-dto';\nimport {ClientError, defineRoute} from '@shipfox/node-fastify';\nimport {z} from 'zod';\nimport {getDefinitionById} from '#db/definitions.js';\nimport {toDefinitionDto} from '#presentation/dto/index.js';\nimport {requireProjectAccess} from './project-access.js';\n\nexport function buildGetDefinitionRoute(projects: ProjectsModuleClient) {\n return defineRoute({\n method: 'GET',\n path: '/:id',\n description: 'Get a definition by ID',\n schema: {\n params: z.object({\n id: z.string().uuid(),\n }),\n response: {\n 200: definitionResponseSchema,\n },\n },\n handler: async (request) => {\n const {id} = request.params;\n const definition = await getDefinitionById(id);\n\n if (!definition) {\n throw new ClientError('Definition not found', 'not-found', {status: 404});\n }\n await requireProjectAccess(request, definition.projectId, projects);\n\n return toDefinitionDto(definition);\n },\n });\n}\n"],"names":["definitionResponseSchema","ClientError","defineRoute","z","getDefinitionById","toDefinitionDto","requireProjectAccess","buildGetDefinitionRoute","projects","method","path","description","schema","params","object","id","string","uuid","response","handler","request","definition","status","projectId"],"mappings":"AAAA,SAAQA,wBAAwB,QAAO,+BAA+B;AAEtE,SAAQC,WAAW,EAAEC,WAAW,QAAO,wBAAwB;AAC/D,SAAQC,CAAC,QAAO,MAAM;AACtB,SAAQC,iBAAiB,QAAO,qBAAqB;AACrD,SAAQC,eAAe,QAAO,6BAA6B;AAC3D,SAAQC,oBAAoB,QAAO,sBAAsB;AAEzD,OAAO,SAASC,wBAAwBC,QAA8B;IACpE,OAAON,YAAY;QACjBO,QAAQ;QACRC,MAAM;QACNC,aAAa;QACbC,QAAQ;YACNC,QAAQV,EAAEW,MAAM,CAAC;gBACfC,IAAIZ,EAAEa,MAAM,GAAGC,IAAI;YACrB;YACAC,UAAU;gBACR,KAAKlB;YACP;QACF;QACAmB,SAAS,OAAOC;YACd,MAAM,EAACL,EAAE,EAAC,GAAGK,QAAQP,MAAM;YAC3B,MAAMQ,aAAa,MAAMjB,kBAAkBW;YAE3C,IAAI,CAACM,YAAY;gBACf,MAAM,IAAIpB,YAAY,wBAAwB,aAAa;oBAACqB,QAAQ;gBAAG;YACzE;YACA,MAAMhB,qBAAqBc,SAASC,WAAWE,SAAS,EAAEf;YAE1D,OAAOH,gBAAgBgB;QACzB;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/presentation/routes/get-definition.ts"],"sourcesContent":["import {definitionResponseSchema} from '@shipfox/api-definitions-dto';\nimport type {ProjectsModuleClient} from '@shipfox/api-projects-dto/inter-module';\nimport {ClientError, defineRoute} from '@shipfox/node-fastify';\nimport {z} from 'zod';\nimport {getDefinitionById} from '#db/definitions.js';\nimport {toDefinitionDto} from '#presentation/dto/index.js';\nimport {requireProjectAccess} from './project-access.js';\n\nexport function buildGetDefinitionRoute(projects: ProjectsModuleClient) {\n return defineRoute({\n method: 'GET',\n path: '/:id',\n description: 'Get a definition by ID',\n schema: {\n params: z.object({\n id: z.string().uuid(),\n }),\n response: {\n 200: definitionResponseSchema,\n },\n },\n handler: async (request) => {\n const {id} = request.params;\n const definition = await getDefinitionById(id);\n\n if (!definition) {\n throw new ClientError('Definition not found', 'not-found', {status: 404});\n }\n await requireProjectAccess(request, definition.projectId, projects);\n\n return toDefinitionDto(definition);\n },\n });\n}\n"],"names":["definitionResponseSchema","ClientError","defineRoute","z","getDefinitionById","toDefinitionDto","requireProjectAccess","buildGetDefinitionRoute","projects","method","path","description","schema","params","object","id","string","uuid","response","handler","request","definition","status","projectId"],"mappings":"AAAA,SAAQA,wBAAwB,QAAO,+BAA+B;AAEtE,SAAQC,WAAW,EAAEC,WAAW,QAAO,wBAAwB;AAC/D,SAAQC,CAAC,QAAO,MAAM;AACtB,SAAQC,iBAAiB,QAAO,qBAAqB;AACrD,SAAQC,eAAe,QAAO,6BAA6B;AAC3D,SAAQC,oBAAoB,QAAO,sBAAsB;AAEzD,OAAO,SAASC,wBAAwBC,QAA8B;IACpE,OAAON,YAAY;QACjBO,QAAQ;QACRC,MAAM;QACNC,aAAa;QACbC,QAAQ;YACNC,QAAQV,EAAEW,MAAM,CAAC;gBACfC,IAAIZ,EAAEa,MAAM,GAAGC,IAAI;YACrB;YACAC,UAAU;gBACR,KAAKlB;YACP;QACF;QACAmB,SAAS,OAAOC;YACd,MAAM,EAACL,EAAE,EAAC,GAAGK,QAAQP,MAAM;YAC3B,MAAMQ,aAAa,MAAMjB,kBAAkBW;YAE3C,IAAI,CAACM,YAAY;gBACf,MAAM,IAAIpB,YAAY,wBAAwB,aAAa;oBAACqB,QAAQ;gBAAG;YACzE;YACA,MAAMhB,qBAAqBc,SAASC,WAAWE,SAAS,EAAEf;YAE1D,OAAOH,gBAAgBgB;QACzB;IACF;AACF"}
|
|
@@ -2,7 +2,7 @@ import { AUTH_USER } from '@shipfox/api-auth-context';
|
|
|
2
2
|
import { buildCreateDefinitionRoute } from './create-definition.js';
|
|
3
3
|
import { buildGetDefinitionRoute } from './get-definition.js';
|
|
4
4
|
import { buildListDefinitionsRoute } from './list-definitions.js';
|
|
5
|
-
import {
|
|
5
|
+
import { buildValidateDefinitionRoute } from './validate-definition.js';
|
|
6
6
|
export function createDefinitionRoutes(options) {
|
|
7
7
|
return [
|
|
8
8
|
{
|
|
@@ -12,7 +12,7 @@ export function createDefinitionRoutes(options) {
|
|
|
12
12
|
buildCreateDefinitionRoute(options),
|
|
13
13
|
buildListDefinitionsRoute(options.projects),
|
|
14
14
|
buildGetDefinitionRoute(options.projects),
|
|
15
|
-
|
|
15
|
+
buildValidateDefinitionRoute(options.agent)
|
|
16
16
|
]
|
|
17
17
|
}
|
|
18
18
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/presentation/routes/index.ts"],"sourcesContent":["import {AUTH_USER} from '@shipfox/api-auth-context';\nimport type {RouteGroup} from '@shipfox/node-fastify';\nimport {\n buildCreateDefinitionRoute,\n type CreateDefinitionRouteOptions,\n} from './create-definition.js';\nimport {buildGetDefinitionRoute} from './get-definition.js';\nimport {buildListDefinitionsRoute} from './list-definitions.js';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/presentation/routes/index.ts"],"sourcesContent":["import {AUTH_USER} from '@shipfox/api-auth-context';\nimport type {RouteGroup} from '@shipfox/node-fastify';\nimport {\n buildCreateDefinitionRoute,\n type CreateDefinitionRouteOptions,\n} from './create-definition.js';\nimport {buildGetDefinitionRoute} from './get-definition.js';\nimport {buildListDefinitionsRoute} from './list-definitions.js';\nimport {buildValidateDefinitionRoute} from './validate-definition.js';\n\nexport interface DefinitionRouteOptions extends CreateDefinitionRouteOptions {}\n\nexport function createDefinitionRoutes(options: DefinitionRouteOptions): RouteGroup[] {\n return [\n {\n prefix: '/definitions',\n auth: AUTH_USER,\n routes: [\n buildCreateDefinitionRoute(options),\n buildListDefinitionsRoute(options.projects),\n buildGetDefinitionRoute(options.projects),\n buildValidateDefinitionRoute(options.agent),\n ],\n },\n ];\n}\n"],"names":["AUTH_USER","buildCreateDefinitionRoute","buildGetDefinitionRoute","buildListDefinitionsRoute","buildValidateDefinitionRoute","createDefinitionRoutes","options","prefix","auth","routes","projects","agent"],"mappings":"AAAA,SAAQA,SAAS,QAAO,4BAA4B;AAEpD,SACEC,0BAA0B,QAErB,yBAAyB;AAChC,SAAQC,uBAAuB,QAAO,sBAAsB;AAC5D,SAAQC,yBAAyB,QAAO,wBAAwB;AAChE,SAAQC,4BAA4B,QAAO,2BAA2B;AAItE,OAAO,SAASC,uBAAuBC,OAA+B;IACpE,OAAO;QACL;YACEC,QAAQ;YACRC,MAAMR;YACNS,QAAQ;gBACNR,2BAA2BK;gBAC3BH,0BAA0BG,QAAQI,QAAQ;gBAC1CR,wBAAwBI,QAAQI,QAAQ;gBACxCN,6BAA6BE,QAAQK,KAAK;aAC3C;QACH;KACD;AACH"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { ProjectsModuleClient } from '@shipfox/api-projects-dto';
|
|
1
|
+
import type { ProjectsModuleClient } from '@shipfox/api-projects-dto/inter-module';
|
|
2
2
|
export declare function buildListDefinitionsRoute(projects: ProjectsModuleClient): import("@shipfox/node-fastify").RouteDefinition;
|
|
3
3
|
//# sourceMappingURL=list-definitions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-definitions.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/list-definitions.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"list-definitions.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/list-definitions.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,wCAAwC,CAAC;AAQjF,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,oBAAoB,mDAiCvE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/presentation/routes/list-definitions.ts"],"sourcesContent":["import {\n definitionListQuerySchema,\n definitionListResponseSchema,\n} from '@shipfox/api-definitions-dto';\nimport type {ProjectsModuleClient} from '@shipfox/api-projects-dto';\nimport {decodeStringIdCursor, encodeStringIdCursor} from '@shipfox/node-drizzle';\nimport {ClientError, defineRoute} from '@shipfox/node-fastify';\nimport {listDefinitions} from '#db/definitions.js';\nimport {getLatestDefinitionSyncState} from '#db/sync-states.js';\nimport {toDefinitionDto, toDefinitionSyncSummaryDto} from '#presentation/dto/index.js';\nimport {requireProjectAccess} from './project-access.js';\n\nexport function buildListDefinitionsRoute(projects: ProjectsModuleClient) {\n return defineRoute({\n method: 'GET',\n path: '/',\n description: 'List all definitions for a project',\n schema: {\n querystring: definitionListQuerySchema,\n response: {\n 200: definitionListResponseSchema,\n },\n },\n handler: async (request) => {\n const {project_id: projectId, limit, cursor} = request.query;\n const decodedCursor = decodeStringIdCursor(cursor);\n if (cursor && !decodedCursor) {\n throw new ClientError('Invalid cursor', 'invalid-cursor', {status: 400});\n }\n\n const project = await requireProjectAccess(request, projectId, projects);\n const result = await listDefinitions({projectId, limit, cursor: decodedCursor});\n const syncState = await getLatestDefinitionSyncState({\n projectId,\n sourceConnectionId: project.sourceConnectionId,\n sourceExternalRepositoryId: project.sourceExternalRepositoryId,\n });\n\n return {\n definitions: result.definitions.map(toDefinitionDto),\n sync: toDefinitionSyncSummaryDto(syncState),\n next_cursor: result.nextCursor ? encodeStringIdCursor(result.nextCursor) : null,\n };\n },\n });\n}\n"],"names":["definitionListQuerySchema","definitionListResponseSchema","decodeStringIdCursor","encodeStringIdCursor","ClientError","defineRoute","listDefinitions","getLatestDefinitionSyncState","toDefinitionDto","toDefinitionSyncSummaryDto","requireProjectAccess","buildListDefinitionsRoute","projects","method","path","description","schema","querystring","response","handler","request","project_id","projectId","limit","cursor","query","decodedCursor","status","project","result","syncState","sourceConnectionId","sourceExternalRepositoryId","definitions","map","sync","next_cursor","nextCursor"],"mappings":"AAAA,SACEA,yBAAyB,EACzBC,4BAA4B,QACvB,+BAA+B;AAEtC,SAAQC,oBAAoB,EAAEC,oBAAoB,QAAO,wBAAwB;AACjF,SAAQC,WAAW,EAAEC,WAAW,QAAO,wBAAwB;AAC/D,SAAQC,eAAe,QAAO,qBAAqB;AACnD,SAAQC,4BAA4B,QAAO,qBAAqB;AAChE,SAAQC,eAAe,EAAEC,0BAA0B,QAAO,6BAA6B;AACvF,SAAQC,oBAAoB,QAAO,sBAAsB;AAEzD,OAAO,SAASC,0BAA0BC,QAA8B;IACtE,OAAOP,YAAY;QACjBQ,QAAQ;QACRC,MAAM;QACNC,aAAa;QACbC,QAAQ;YACNC,aAAajB;YACbkB,UAAU;gBACR,KAAKjB;YACP;QACF;QACAkB,SAAS,OAAOC;YACd,MAAM,EAACC,YAAYC,SAAS,EAAEC,KAAK,EAAEC,MAAM,EAAC,GAAGJ,QAAQK,KAAK;YAC5D,MAAMC,gBAAgBxB,qBAAqBsB;YAC3C,IAAIA,UAAU,CAACE,eAAe;gBAC5B,MAAM,IAAItB,YAAY,kBAAkB,kBAAkB;oBAACuB,QAAQ;gBAAG;YACxE;YAEA,MAAMC,UAAU,MAAMlB,qBAAqBU,SAASE,WAAWV;YAC/D,MAAMiB,SAAS,MAAMvB,gBAAgB;gBAACgB;gBAAWC;gBAAOC,QAAQE;YAAa;YAC7E,MAAMI,YAAY,MAAMvB,6BAA6B;gBACnDe;gBACAS,oBAAoBH,QAAQG,kBAAkB;gBAC9CC,4BAA4BJ,QAAQI,0BAA0B;YAChE;YAEA,OAAO;gBACLC,aAAaJ,OAAOI,WAAW,CAACC,GAAG,CAAC1B;gBACpC2B,MAAM1B,2BAA2BqB;gBACjCM,aAAaP,OAAOQ,UAAU,GAAGlC,qBAAqB0B,OAAOQ,UAAU,IAAI;YAC7E;QACF;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/presentation/routes/list-definitions.ts"],"sourcesContent":["import {\n definitionListQuerySchema,\n definitionListResponseSchema,\n} from '@shipfox/api-definitions-dto';\nimport type {ProjectsModuleClient} from '@shipfox/api-projects-dto/inter-module';\nimport {decodeStringIdCursor, encodeStringIdCursor} from '@shipfox/node-drizzle';\nimport {ClientError, defineRoute} from '@shipfox/node-fastify';\nimport {listDefinitions} from '#db/definitions.js';\nimport {getLatestDefinitionSyncState} from '#db/sync-states.js';\nimport {toDefinitionDto, toDefinitionSyncSummaryDto} from '#presentation/dto/index.js';\nimport {requireProjectAccess} from './project-access.js';\n\nexport function buildListDefinitionsRoute(projects: ProjectsModuleClient) {\n return defineRoute({\n method: 'GET',\n path: '/',\n description: 'List all definitions for a project',\n schema: {\n querystring: definitionListQuerySchema,\n response: {\n 200: definitionListResponseSchema,\n },\n },\n handler: async (request) => {\n const {project_id: projectId, limit, cursor} = request.query;\n const decodedCursor = decodeStringIdCursor(cursor);\n if (cursor && !decodedCursor) {\n throw new ClientError('Invalid cursor', 'invalid-cursor', {status: 400});\n }\n\n const project = await requireProjectAccess(request, projectId, projects);\n const result = await listDefinitions({projectId, limit, cursor: decodedCursor});\n const syncState = await getLatestDefinitionSyncState({\n projectId,\n sourceConnectionId: project.sourceConnectionId,\n sourceExternalRepositoryId: project.sourceExternalRepositoryId,\n });\n\n return {\n definitions: result.definitions.map(toDefinitionDto),\n sync: toDefinitionSyncSummaryDto(syncState),\n next_cursor: result.nextCursor ? encodeStringIdCursor(result.nextCursor) : null,\n };\n },\n });\n}\n"],"names":["definitionListQuerySchema","definitionListResponseSchema","decodeStringIdCursor","encodeStringIdCursor","ClientError","defineRoute","listDefinitions","getLatestDefinitionSyncState","toDefinitionDto","toDefinitionSyncSummaryDto","requireProjectAccess","buildListDefinitionsRoute","projects","method","path","description","schema","querystring","response","handler","request","project_id","projectId","limit","cursor","query","decodedCursor","status","project","result","syncState","sourceConnectionId","sourceExternalRepositoryId","definitions","map","sync","next_cursor","nextCursor"],"mappings":"AAAA,SACEA,yBAAyB,EACzBC,4BAA4B,QACvB,+BAA+B;AAEtC,SAAQC,oBAAoB,EAAEC,oBAAoB,QAAO,wBAAwB;AACjF,SAAQC,WAAW,EAAEC,WAAW,QAAO,wBAAwB;AAC/D,SAAQC,eAAe,QAAO,qBAAqB;AACnD,SAAQC,4BAA4B,QAAO,qBAAqB;AAChE,SAAQC,eAAe,EAAEC,0BAA0B,QAAO,6BAA6B;AACvF,SAAQC,oBAAoB,QAAO,sBAAsB;AAEzD,OAAO,SAASC,0BAA0BC,QAA8B;IACtE,OAAOP,YAAY;QACjBQ,QAAQ;QACRC,MAAM;QACNC,aAAa;QACbC,QAAQ;YACNC,aAAajB;YACbkB,UAAU;gBACR,KAAKjB;YACP;QACF;QACAkB,SAAS,OAAOC;YACd,MAAM,EAACC,YAAYC,SAAS,EAAEC,KAAK,EAAEC,MAAM,EAAC,GAAGJ,QAAQK,KAAK;YAC5D,MAAMC,gBAAgBxB,qBAAqBsB;YAC3C,IAAIA,UAAU,CAACE,eAAe;gBAC5B,MAAM,IAAItB,YAAY,kBAAkB,kBAAkB;oBAACuB,QAAQ;gBAAG;YACxE;YAEA,MAAMC,UAAU,MAAMlB,qBAAqBU,SAASE,WAAWV;YAC/D,MAAMiB,SAAS,MAAMvB,gBAAgB;gBAACgB;gBAAWC;gBAAOC,QAAQE;YAAa;YAC7E,MAAMI,YAAY,MAAMvB,6BAA6B;gBACnDe;gBACAS,oBAAoBH,QAAQG,kBAAkB;gBAC9CC,4BAA4BJ,QAAQI,0BAA0B;YAChE;YAEA,OAAO;gBACLC,aAAaJ,OAAOI,WAAW,CAACC,GAAG,CAAC1B;gBACpC2B,MAAM1B,2BAA2BqB;gBACjCM,aAAaP,OAAOQ,UAAU,GAAGlC,qBAAqB0B,OAAOQ,UAAU,IAAI;YAC7E;QACF;IACF;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ProjectsModuleClient } from '@shipfox/api-projects-dto';
|
|
1
|
+
import type { ProjectsModuleClient } from '@shipfox/api-projects-dto/inter-module';
|
|
2
2
|
import type { FastifyRequest } from 'fastify';
|
|
3
3
|
export declare function requireProjectAccess(request: FastifyRequest, projectId: string, projects: ProjectsModuleClient): Promise<{
|
|
4
4
|
id: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project-access.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/project-access.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"project-access.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/project-access.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,wCAAwC,CAAC;AAEjF,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,SAAS,CAAC;AAE5C,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,oBAAoB;;;;;;GAO/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/presentation/routes/project-access.ts"],"sourcesContent":["import {requireWorkspaceAccess} from '@shipfox/api-auth-context';\nimport type {ProjectsModuleClient} from '@shipfox/api-projects-dto';\nimport {ClientError} from '@shipfox/node-fastify';\nimport type {FastifyRequest} from 'fastify';\n\nexport async function requireProjectAccess(\n request: FastifyRequest,\n projectId: string,\n projects: ProjectsModuleClient,\n) {\n const {project} = await projects.getProjectById({projectId});\n if (project === null)\n throw new ClientError('Project not found', 'project-not-found', {status: 404});\n requireWorkspaceAccess({request, workspaceId: project.workspaceId});\n return project;\n}\n"],"names":["requireWorkspaceAccess","ClientError","requireProjectAccess","request","projectId","projects","project","getProjectById","status","workspaceId"],"mappings":"AAAA,SAAQA,sBAAsB,QAAO,4BAA4B;AAEjE,SAAQC,WAAW,QAAO,wBAAwB;AAGlD,OAAO,eAAeC,qBACpBC,OAAuB,EACvBC,SAAiB,EACjBC,QAA8B;IAE9B,MAAM,EAACC,OAAO,EAAC,GAAG,MAAMD,SAASE,cAAc,CAAC;QAACH;IAAS;IAC1D,IAAIE,YAAY,MACd,MAAM,IAAIL,YAAY,qBAAqB,qBAAqB;QAACO,QAAQ;IAAG;IAC9ER,uBAAuB;QAACG;QAASM,aAAaH,QAAQG,WAAW;IAAA;IACjE,OAAOH;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../../src/presentation/routes/project-access.ts"],"sourcesContent":["import {requireWorkspaceAccess} from '@shipfox/api-auth-context';\nimport type {ProjectsModuleClient} from '@shipfox/api-projects-dto/inter-module';\nimport {ClientError} from '@shipfox/node-fastify';\nimport type {FastifyRequest} from 'fastify';\n\nexport async function requireProjectAccess(\n request: FastifyRequest,\n projectId: string,\n projects: ProjectsModuleClient,\n) {\n const {project} = await projects.getProjectById({projectId});\n if (project === null)\n throw new ClientError('Project not found', 'project-not-found', {status: 404});\n requireWorkspaceAccess({request, workspaceId: project.workspaceId});\n return project;\n}\n"],"names":["requireWorkspaceAccess","ClientError","requireProjectAccess","request","projectId","projects","project","getProjectById","status","workspaceId"],"mappings":"AAAA,SAAQA,sBAAsB,QAAO,4BAA4B;AAEjE,SAAQC,WAAW,QAAO,wBAAwB;AAGlD,OAAO,eAAeC,qBACpBC,OAAuB,EACvBC,SAAiB,EACjBC,QAA8B;IAE9B,MAAM,EAACC,OAAO,EAAC,GAAG,MAAMD,SAASE,cAAc,CAAC;QAACH;IAAS;IAC1D,IAAIE,YAAY,MACd,MAAM,IAAIL,YAAY,qBAAqB,qBAAqB;QAACO,QAAQ;IAAG;IAC9ER,uBAAuB;QAACG;QAASM,aAAaH,QAAQG,WAAW;IAAA;IACjE,OAAOH;AACT"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import type { AgentInterModuleClient } from '@shipfox/api-agent-dto/inter-module';
|
|
2
|
+
export declare function buildValidateDefinitionRoute(agent: AgentInterModuleClient): import("@shipfox/node-fastify").RouteDefinition;
|
|
2
3
|
//# sourceMappingURL=validate-definition.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-definition.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/validate-definition.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validate-definition.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/validate-definition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,sBAAsB,EAAC,MAAM,qCAAqC,CAAC;AAsBhF,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,sBAAsB,mDA4BzE"}
|
|
@@ -16,28 +16,32 @@ const validationResultSchema = z.union([
|
|
|
16
16
|
errors: z.array(definitionValidationErrorSchema)
|
|
17
17
|
})
|
|
18
18
|
]);
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
export function buildValidateDefinitionRoute(agent) {
|
|
20
|
+
return defineRoute({
|
|
21
|
+
method: 'POST',
|
|
22
|
+
path: '/validate',
|
|
23
|
+
description: 'Validate a workflow definition without persisting',
|
|
24
|
+
schema: {
|
|
25
|
+
body: validateBodySchema,
|
|
26
|
+
response: {
|
|
27
|
+
200: validationResultSchema
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
handler: async (request)=>{
|
|
31
|
+
const { yaml } = request.body;
|
|
32
|
+
const result = validateDefinition(yaml, {
|
|
33
|
+
agentValidationCatalog: await agent.getValidationCatalog({})
|
|
34
|
+
});
|
|
35
|
+
if (result.valid) {
|
|
36
|
+
return {
|
|
37
|
+
valid: true,
|
|
38
|
+
workflow_document: result.definition.document,
|
|
39
|
+
workflow_model: result.definition.model
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
27
43
|
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const { yaml } = request.body;
|
|
31
|
-
const result = validateDefinition(yaml);
|
|
32
|
-
if (result.valid) {
|
|
33
|
-
return {
|
|
34
|
-
valid: true,
|
|
35
|
-
workflow_document: result.definition.document,
|
|
36
|
-
workflow_model: result.definition.model
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
return result;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
44
|
+
});
|
|
45
|
+
}
|
|
42
46
|
|
|
43
47
|
//# sourceMappingURL=validate-definition.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/presentation/routes/validate-definition.ts"],"sourcesContent":["import {definitionDtoSchema, definitionValidationErrorSchema} from '@shipfox/api-definitions-dto';\nimport {defineRoute} from '@shipfox/node-fastify';\nimport {z} from 'zod';\nimport {validateDefinition} from '#core/validate-definition.js';\n\nconst validateBodySchema = z.object({\n yaml: z.string().min(1).max(1_000_000),\n});\n\nconst validationResultSchema = z.union([\n z.object({\n valid: z.literal(true),\n workflow_document: definitionDtoSchema.shape.workflow_document,\n workflow_model: definitionDtoSchema.shape.workflow_model,\n }),\n z.object({\n valid: z.literal(false),\n errors: z.array(definitionValidationErrorSchema),\n }),\n]);\n\nexport
|
|
1
|
+
{"version":3,"sources":["../../../src/presentation/routes/validate-definition.ts"],"sourcesContent":["import type {AgentInterModuleClient} from '@shipfox/api-agent-dto/inter-module';\nimport {definitionDtoSchema, definitionValidationErrorSchema} from '@shipfox/api-definitions-dto';\nimport {defineRoute} from '@shipfox/node-fastify';\nimport {z} from 'zod';\nimport {validateDefinition} from '#core/validate-definition.js';\n\nconst validateBodySchema = z.object({\n yaml: z.string().min(1).max(1_000_000),\n});\n\nconst validationResultSchema = z.union([\n z.object({\n valid: z.literal(true),\n workflow_document: definitionDtoSchema.shape.workflow_document,\n workflow_model: definitionDtoSchema.shape.workflow_model,\n }),\n z.object({\n valid: z.literal(false),\n errors: z.array(definitionValidationErrorSchema),\n }),\n]);\n\nexport function buildValidateDefinitionRoute(agent: AgentInterModuleClient) {\n return defineRoute({\n method: 'POST',\n path: '/validate',\n description: 'Validate a workflow definition without persisting',\n schema: {\n body: validateBodySchema,\n response: {\n 200: validationResultSchema,\n },\n },\n handler: async (request) => {\n const {yaml} = request.body;\n const result = validateDefinition(yaml, {\n agentValidationCatalog: await agent.getValidationCatalog({}),\n });\n\n if (result.valid) {\n return {\n valid: true as const,\n workflow_document: result.definition.document,\n workflow_model: result.definition.model,\n };\n }\n\n return result;\n },\n });\n}\n"],"names":["definitionDtoSchema","definitionValidationErrorSchema","defineRoute","z","validateDefinition","validateBodySchema","object","yaml","string","min","max","validationResultSchema","union","valid","literal","workflow_document","shape","workflow_model","errors","array","buildValidateDefinitionRoute","agent","method","path","description","schema","body","response","handler","request","result","agentValidationCatalog","getValidationCatalog","definition","document","model"],"mappings":"AACA,SAAQA,mBAAmB,EAAEC,+BAA+B,QAAO,+BAA+B;AAClG,SAAQC,WAAW,QAAO,wBAAwB;AAClD,SAAQC,CAAC,QAAO,MAAM;AACtB,SAAQC,kBAAkB,QAAO,+BAA+B;AAEhE,MAAMC,qBAAqBF,EAAEG,MAAM,CAAC;IAClCC,MAAMJ,EAAEK,MAAM,GAAGC,GAAG,CAAC,GAAGC,GAAG,CAAC;AAC9B;AAEA,MAAMC,yBAAyBR,EAAES,KAAK,CAAC;IACrCT,EAAEG,MAAM,CAAC;QACPO,OAAOV,EAAEW,OAAO,CAAC;QACjBC,mBAAmBf,oBAAoBgB,KAAK,CAACD,iBAAiB;QAC9DE,gBAAgBjB,oBAAoBgB,KAAK,CAACC,cAAc;IAC1D;IACAd,EAAEG,MAAM,CAAC;QACPO,OAAOV,EAAEW,OAAO,CAAC;QACjBI,QAAQf,EAAEgB,KAAK,CAAClB;IAClB;CACD;AAED,OAAO,SAASmB,6BAA6BC,KAA6B;IACxE,OAAOnB,YAAY;QACjBoB,QAAQ;QACRC,MAAM;QACNC,aAAa;QACbC,QAAQ;YACNC,MAAMrB;YACNsB,UAAU;gBACR,KAAKhB;YACP;QACF;QACAiB,SAAS,OAAOC;YACd,MAAM,EAACtB,IAAI,EAAC,GAAGsB,QAAQH,IAAI;YAC3B,MAAMI,SAAS1B,mBAAmBG,MAAM;gBACtCwB,wBAAwB,MAAMV,MAAMW,oBAAoB,CAAC,CAAC;YAC5D;YAEA,IAAIF,OAAOjB,KAAK,EAAE;gBAChB,OAAO;oBACLA,OAAO;oBACPE,mBAAmBe,OAAOG,UAAU,CAACC,QAAQ;oBAC7CjB,gBAAgBa,OAAOG,UAAU,CAACE,KAAK;gBACzC;YACF;YAEA,OAAOL;QACT;IACF;AACF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AgentInterModuleClient } from '@shipfox/api-agent-dto/inter-module';
|
|
2
|
+
import type { IntegrationsModuleClient } from '@shipfox/api-integration-core-dto/inter-module';
|
|
2
3
|
import type { DefinitionSyncErrorCode } from '#core/entities/sync-state.js';
|
|
3
4
|
import type { DefinitionsSourceControl } from '#core/integrations.js';
|
|
4
5
|
export interface SyncWorkflowInput {
|
|
@@ -31,7 +32,7 @@ export interface FetchAndApplyActivityResult {
|
|
|
31
32
|
appliedCount: number;
|
|
32
33
|
deletedCount: number;
|
|
33
34
|
}
|
|
34
|
-
export declare function createDefinitionSyncActivities(sourceControl: DefinitionsSourceControl, integrations?: IntegrationsModuleClient | undefined): {
|
|
35
|
+
export declare function createDefinitionSyncActivities(sourceControl: DefinitionsSourceControl, agent: AgentInterModuleClient, integrations?: IntegrationsModuleClient | undefined): {
|
|
35
36
|
prepareDefinitionSync: (input: SyncWorkflowInput) => Promise<PrepareSyncResult>;
|
|
36
37
|
discoverDefinitionWorkflows: (input: SyncRefScopedInput) => Promise<DiscoverWorkflowsActivityResult>;
|
|
37
38
|
fetchAndApplyDefinitionWorkflows: (input: FetchAndApplyActivityInput) => Promise<FetchAndApplyActivityResult>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-activities.d.ts","sourceRoot":"","sources":["../../../src/temporal/activities/sync-activities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,wBAAwB,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"sync-activities.d.ts","sourceRoot":"","sources":["../../../src/temporal/activities/sync-activities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,sBAAsB,EAAC,MAAM,qCAAqC,CAAC;AAChF,OAAO,KAAK,EAAC,wBAAwB,EAAC,MAAM,gDAAgD,CAAC;AAI7F,OAAO,KAAK,EAAC,uBAAuB,EAAC,MAAM,8BAA8B,CAAC;AAQ1E,OAAO,KAAK,EAAC,wBAAwB,EAAC,MAAM,uBAAuB,CAAC;AAIpE,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,0BAA0B,EAAE,MAAM,CAAC;IACnC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACtC;AAED,MAAM,WAAW,kBAAmB,SAAQ,iBAAiB;IAC3D,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,0BAA2B,SAAQ,kBAAkB;IACpE,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,WAAW,2BAA4B,SAAQ,IAAI,CAAC,iBAAiB,EAAE,WAAW,CAAC;IACvF,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,IAAI,EAAE,uBAAuB,CAAC;IAC9B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACtC;AAED,MAAM,WAAW,+BAA+B;IAC9C,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,WAAW,2BAA2B;IAC1C,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,8BAA8B,CAC5C,aAAa,EAAE,wBAAwB,EACvC,KAAK,EAAE,sBAAsB,EAC7B,YAAY,CAAC,EAAE,wBAAwB,GAAG,SAAS;mCAiB1C,iBAAiB,KACvB,OAAO,CAAC,iBAAiB,CAAC;yCAuBpB,kBAAkB,KACxB,OAAO,CAAC,+BAA+B,CAAC;8CAiBlC,0BAA0B,KAChC,OAAO,CAAC,2BAA2B,CAAC;yCAsCkB,kBAAkB,KAAG,OAAO,CAAC,IAAI,CAAC;sCAgBlF,2BAA2B,KACjC,OAAO,CAAC,IAAI,CAAC;EAtGjB"}
|
|
@@ -4,11 +4,11 @@ import { ApplicationFailure } from '@temporalio/common';
|
|
|
4
4
|
import { classifySyncFailure, discoverWorkflowFiles, fetchAndParseWorkflows, resolveSyncSource, UNRESOLVED_SYNC_REF } from '#core/index.js';
|
|
5
5
|
import { loadIntegrationValidationContext } from '#core/integrations.js';
|
|
6
6
|
import { applyVcsDefinitionsBatch, markDefinitionSyncState } from '#db/index.js';
|
|
7
|
-
export function createDefinitionSyncActivities(sourceControl, integrations) {
|
|
7
|
+
export function createDefinitionSyncActivities(sourceControl, agent, integrations) {
|
|
8
8
|
return {
|
|
9
9
|
prepareDefinitionSync: createPrepareDefinitionSyncActivity(sourceControl),
|
|
10
10
|
discoverDefinitionWorkflows: createDiscoverDefinitionWorkflowsActivity(sourceControl),
|
|
11
|
-
fetchAndApplyDefinitionWorkflows: createFetchAndApplyActivity(sourceControl, integrations),
|
|
11
|
+
fetchAndApplyDefinitionWorkflows: createFetchAndApplyActivity(sourceControl, agent, integrations),
|
|
12
12
|
markDefinitionSyncSucceeded: createMarkSyncSucceededActivity(),
|
|
13
13
|
markDefinitionSyncFailed: createMarkSyncFailedActivity()
|
|
14
14
|
};
|
|
@@ -49,13 +49,14 @@ function createDiscoverDefinitionWorkflowsActivity(sourceControl) {
|
|
|
49
49
|
});
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
|
-
function createFetchAndApplyActivity(sourceControl, integrations) {
|
|
52
|
+
function createFetchAndApplyActivity(sourceControl, agent, integrations) {
|
|
53
53
|
return async function fetchAndApplyDefinitionWorkflows(input) {
|
|
54
54
|
return await runWithPermanentTranslation(async ()=>{
|
|
55
55
|
const definitions = await fetchAndParseWorkflows({
|
|
56
56
|
...input,
|
|
57
57
|
ref: input.sourceCommitSha ?? input.sourceRef,
|
|
58
58
|
sourceControl,
|
|
59
|
+
agentValidationCatalog: await agent.getValidationCatalog({}),
|
|
59
60
|
onProgress: (path)=>Context.current().heartbeat({
|
|
60
61
|
path
|
|
61
62
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/temporal/activities/sync-activities.ts"],"sourcesContent":["import type {IntegrationsModuleClient} from '@shipfox/api-integration-core-dto';\nimport {markErrorReported} from '@shipfox/node-error-monitoring';\nimport {Context} from '@temporalio/activity';\nimport {ApplicationFailure} from '@temporalio/common';\nimport type {DefinitionSyncErrorCode} from '#core/entities/sync-state.js';\nimport {\n classifySyncFailure,\n discoverWorkflowFiles,\n fetchAndParseWorkflows,\n resolveSyncSource,\n UNRESOLVED_SYNC_REF,\n} from '#core/index.js';\nimport type {DefinitionsSourceControl} from '#core/integrations.js';\nimport {loadIntegrationValidationContext} from '#core/integrations.js';\nimport {applyVcsDefinitionsBatch, markDefinitionSyncState} from '#db/index.js';\n\nexport interface SyncWorkflowInput {\n projectId: string;\n workspaceId: string;\n sourceConnectionId: string;\n sourceExternalRepositoryId: string;\n sourceRef?: string | undefined;\n sourceCommitSha?: string | undefined;\n}\n\nexport interface SyncRefScopedInput extends SyncWorkflowInput {\n sourceRef: string;\n}\n\nexport interface FetchAndApplyActivityInput extends SyncRefScopedInput {\n paths: string[];\n}\n\nexport interface MarkSyncFailedActivityInput extends Omit<SyncWorkflowInput, 'sourceRef'> {\n sourceRef: string | null;\n code: DefinitionSyncErrorCode;\n message: string;\n}\n\nexport interface PrepareSyncResult {\n sourceRef: string;\n sourceCommitSha?: string | undefined;\n}\n\nexport interface DiscoverWorkflowsActivityResult {\n paths: string[];\n}\n\nexport interface FetchAndApplyActivityResult {\n appliedCount: number;\n deletedCount: number;\n}\n\nexport function createDefinitionSyncActivities(\n sourceControl: DefinitionsSourceControl,\n integrations?: IntegrationsModuleClient | undefined,\n) {\n return {\n prepareDefinitionSync: createPrepareDefinitionSyncActivity(sourceControl),\n discoverDefinitionWorkflows: createDiscoverDefinitionWorkflowsActivity(sourceControl),\n fetchAndApplyDefinitionWorkflows: createFetchAndApplyActivity(sourceControl, integrations),\n markDefinitionSyncSucceeded: createMarkSyncSucceededActivity(),\n markDefinitionSyncFailed: createMarkSyncFailedActivity(),\n };\n}\n\nfunction createPrepareDefinitionSyncActivity(sourceControl: DefinitionsSourceControl) {\n return async function prepareDefinitionSync(\n input: SyncWorkflowInput,\n ): Promise<PrepareSyncResult> {\n return await runWithPermanentTranslation(async () => {\n const sourceRef = input.sourceRef ?? (await resolveSyncSource({...input, sourceControl})).ref;\n\n await markDefinitionSyncState({\n projectId: input.projectId,\n sourceConnectionId: input.sourceConnectionId,\n sourceExternalRepositoryId: input.sourceExternalRepositoryId,\n ref: sourceRef,\n status: 'syncing',\n lastErrorCode: null,\n lastErrorMessage: null,\n startedAt: new Date(),\n finishedAt: null,\n });\n\n return {sourceRef, sourceCommitSha: input.sourceCommitSha};\n });\n };\n}\n\nfunction createDiscoverDefinitionWorkflowsActivity(sourceControl: DefinitionsSourceControl) {\n return async function discoverDefinitionWorkflows(\n input: SyncRefScopedInput,\n ): Promise<DiscoverWorkflowsActivityResult> {\n return await runWithPermanentTranslation(async () => {\n return await discoverWorkflowFiles({\n ...input,\n ref: input.sourceCommitSha ?? input.sourceRef,\n sourceControl,\n });\n });\n };\n}\n\nfunction createFetchAndApplyActivity(\n sourceControl: DefinitionsSourceControl,\n integrations?: IntegrationsModuleClient | undefined,\n) {\n return async function fetchAndApplyDefinitionWorkflows(\n input: FetchAndApplyActivityInput,\n ): Promise<FetchAndApplyActivityResult> {\n return await runWithPermanentTranslation(async () => {\n const definitions = await fetchAndParseWorkflows({\n ...input,\n ref: input.sourceCommitSha ?? input.sourceRef,\n sourceControl,\n onProgress: (path) => Context.current().heartbeat({path}),\n loadIntegrationValidationContext:\n integrations === undefined\n ? undefined\n : async () => {\n return await loadIntegrationValidationContext(\n integrations,\n input.workspaceId,\n input.sourceConnectionId,\n );\n },\n });\n\n return await applyVcsDefinitionsBatch({\n projectId: input.projectId,\n workspaceId: input.workspaceId,\n ref: input.sourceRef,\n upserts: definitions.map((entry) => ({\n configPath: entry.path,\n name: entry.name,\n document: entry.definition.document,\n model: entry.definition.model,\n sourceSnapshot: entry.definition.sourceSnapshot,\n contentHash: entry.contentHash,\n })),\n });\n });\n };\n}\n\nfunction createMarkSyncSucceededActivity() {\n return async function markDefinitionSyncSucceeded(input: SyncRefScopedInput): Promise<void> {\n await markDefinitionSyncState({\n projectId: input.projectId,\n sourceConnectionId: input.sourceConnectionId,\n sourceExternalRepositoryId: input.sourceExternalRepositoryId,\n ref: input.sourceRef,\n status: 'succeeded',\n lastErrorCode: null,\n lastErrorMessage: null,\n finishedAt: new Date(),\n });\n };\n}\n\nfunction createMarkSyncFailedActivity() {\n return async function markDefinitionSyncFailed(\n input: MarkSyncFailedActivityInput,\n ): Promise<void> {\n await markDefinitionSyncState({\n projectId: input.projectId,\n sourceConnectionId: input.sourceConnectionId,\n sourceExternalRepositoryId: input.sourceExternalRepositoryId,\n ref: input.sourceRef ?? UNRESOLVED_SYNC_REF,\n status: 'failed',\n lastErrorCode: input.code,\n lastErrorMessage: input.message,\n finishedAt: new Date(),\n });\n };\n}\n\nasync function runWithPermanentTranslation<T>(operation: () => Promise<T>): Promise<T> {\n try {\n return await operation();\n } catch (error) {\n if (error instanceof ApplicationFailure) {\n throw error;\n }\n const failure = classifySyncFailure(error);\n const translatedError = failure.retryable\n ? ApplicationFailure.retryable(failure.message, failure.code)\n : ApplicationFailure.nonRetryable(failure.message, failure.code);\n if (failure.code !== 'unknown') markErrorReported(translatedError);\n throw translatedError;\n }\n}\n"],"names":["markErrorReported","Context","ApplicationFailure","classifySyncFailure","discoverWorkflowFiles","fetchAndParseWorkflows","resolveSyncSource","UNRESOLVED_SYNC_REF","loadIntegrationValidationContext","applyVcsDefinitionsBatch","markDefinitionSyncState","createDefinitionSyncActivities","sourceControl","integrations","prepareDefinitionSync","createPrepareDefinitionSyncActivity","discoverDefinitionWorkflows","createDiscoverDefinitionWorkflowsActivity","fetchAndApplyDefinitionWorkflows","createFetchAndApplyActivity","markDefinitionSyncSucceeded","createMarkSyncSucceededActivity","markDefinitionSyncFailed","createMarkSyncFailedActivity","input","runWithPermanentTranslation","sourceRef","ref","projectId","sourceConnectionId","sourceExternalRepositoryId","status","lastErrorCode","lastErrorMessage","startedAt","Date","finishedAt","sourceCommitSha","definitions","onProgress","path","current","heartbeat","undefined","workspaceId","upserts","map","entry","configPath","name","document","definition","model","sourceSnapshot","contentHash","code","message","operation","error","failure","translatedError","retryable","nonRetryable"],"mappings":"AACA,SAAQA,iBAAiB,QAAO,iCAAiC;AACjE,SAAQC,OAAO,QAAO,uBAAuB;AAC7C,SAAQC,kBAAkB,QAAO,qBAAqB;AAEtD,SACEC,mBAAmB,EACnBC,qBAAqB,EACrBC,sBAAsB,EACtBC,iBAAiB,EACjBC,mBAAmB,QACd,iBAAiB;AAExB,SAAQC,gCAAgC,QAAO,wBAAwB;AACvE,SAAQC,wBAAwB,EAAEC,uBAAuB,QAAO,eAAe;AAuC/E,OAAO,SAASC,+BACdC,aAAuC,EACvCC,YAAmD;IAEnD,OAAO;QACLC,uBAAuBC,oCAAoCH;QAC3DI,6BAA6BC,0CAA0CL;QACvEM,kCAAkCC,4BAA4BP,eAAeC;QAC7EO,6BAA6BC;QAC7BC,0BAA0BC;IAC5B;AACF;AAEA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H,QAAQH,OAAO,EAAEG,QAAQJ,IAAI;QACjE,IAAII,QAAQJ,IAAI,KAAK,WAAWvD,kBAAkB4D;QAClD,MAAMA;IACR;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/temporal/activities/sync-activities.ts"],"sourcesContent":["import type {AgentInterModuleClient} from '@shipfox/api-agent-dto/inter-module';\nimport type {IntegrationsModuleClient} from '@shipfox/api-integration-core-dto/inter-module';\nimport {markErrorReported} from '@shipfox/node-error-monitoring';\nimport {Context} from '@temporalio/activity';\nimport {ApplicationFailure} from '@temporalio/common';\nimport type {DefinitionSyncErrorCode} from '#core/entities/sync-state.js';\nimport {\n classifySyncFailure,\n discoverWorkflowFiles,\n fetchAndParseWorkflows,\n resolveSyncSource,\n UNRESOLVED_SYNC_REF,\n} from '#core/index.js';\nimport type {DefinitionsSourceControl} from '#core/integrations.js';\nimport {loadIntegrationValidationContext} from '#core/integrations.js';\nimport {applyVcsDefinitionsBatch, markDefinitionSyncState} from '#db/index.js';\n\nexport interface SyncWorkflowInput {\n projectId: string;\n workspaceId: string;\n sourceConnectionId: string;\n sourceExternalRepositoryId: string;\n sourceRef?: string | undefined;\n sourceCommitSha?: string | undefined;\n}\n\nexport interface SyncRefScopedInput extends SyncWorkflowInput {\n sourceRef: string;\n}\n\nexport interface FetchAndApplyActivityInput extends SyncRefScopedInput {\n paths: string[];\n}\n\nexport interface MarkSyncFailedActivityInput extends Omit<SyncWorkflowInput, 'sourceRef'> {\n sourceRef: string | null;\n code: DefinitionSyncErrorCode;\n message: string;\n}\n\nexport interface PrepareSyncResult {\n sourceRef: string;\n sourceCommitSha?: string | undefined;\n}\n\nexport interface DiscoverWorkflowsActivityResult {\n paths: string[];\n}\n\nexport interface FetchAndApplyActivityResult {\n appliedCount: number;\n deletedCount: number;\n}\n\nexport function createDefinitionSyncActivities(\n sourceControl: DefinitionsSourceControl,\n agent: AgentInterModuleClient,\n integrations?: IntegrationsModuleClient | undefined,\n) {\n return {\n prepareDefinitionSync: createPrepareDefinitionSyncActivity(sourceControl),\n discoverDefinitionWorkflows: createDiscoverDefinitionWorkflowsActivity(sourceControl),\n fetchAndApplyDefinitionWorkflows: createFetchAndApplyActivity(\n sourceControl,\n agent,\n integrations,\n ),\n markDefinitionSyncSucceeded: createMarkSyncSucceededActivity(),\n markDefinitionSyncFailed: createMarkSyncFailedActivity(),\n };\n}\n\nfunction createPrepareDefinitionSyncActivity(sourceControl: DefinitionsSourceControl) {\n return async function prepareDefinitionSync(\n input: SyncWorkflowInput,\n ): Promise<PrepareSyncResult> {\n return await runWithPermanentTranslation(async () => {\n const sourceRef = input.sourceRef ?? (await resolveSyncSource({...input, sourceControl})).ref;\n\n await markDefinitionSyncState({\n projectId: input.projectId,\n sourceConnectionId: input.sourceConnectionId,\n sourceExternalRepositoryId: input.sourceExternalRepositoryId,\n ref: sourceRef,\n status: 'syncing',\n lastErrorCode: null,\n lastErrorMessage: null,\n startedAt: new Date(),\n finishedAt: null,\n });\n\n return {sourceRef, sourceCommitSha: input.sourceCommitSha};\n });\n };\n}\n\nfunction createDiscoverDefinitionWorkflowsActivity(sourceControl: DefinitionsSourceControl) {\n return async function discoverDefinitionWorkflows(\n input: SyncRefScopedInput,\n ): Promise<DiscoverWorkflowsActivityResult> {\n return await runWithPermanentTranslation(async () => {\n return await discoverWorkflowFiles({\n ...input,\n ref: input.sourceCommitSha ?? input.sourceRef,\n sourceControl,\n });\n });\n };\n}\n\nfunction createFetchAndApplyActivity(\n sourceControl: DefinitionsSourceControl,\n agent: AgentInterModuleClient,\n integrations?: IntegrationsModuleClient | undefined,\n) {\n return async function fetchAndApplyDefinitionWorkflows(\n input: FetchAndApplyActivityInput,\n ): Promise<FetchAndApplyActivityResult> {\n return await runWithPermanentTranslation(async () => {\n const definitions = await fetchAndParseWorkflows({\n ...input,\n ref: input.sourceCommitSha ?? input.sourceRef,\n sourceControl,\n agentValidationCatalog: await agent.getValidationCatalog({}),\n onProgress: (path) => Context.current().heartbeat({path}),\n loadIntegrationValidationContext:\n integrations === undefined\n ? undefined\n : async () => {\n return await loadIntegrationValidationContext(\n integrations,\n input.workspaceId,\n input.sourceConnectionId,\n );\n },\n });\n\n return await applyVcsDefinitionsBatch({\n projectId: input.projectId,\n workspaceId: input.workspaceId,\n ref: input.sourceRef,\n upserts: definitions.map((entry) => ({\n configPath: entry.path,\n name: entry.name,\n document: entry.definition.document,\n model: entry.definition.model,\n sourceSnapshot: entry.definition.sourceSnapshot,\n contentHash: entry.contentHash,\n })),\n });\n });\n };\n}\n\nfunction createMarkSyncSucceededActivity() {\n return async function markDefinitionSyncSucceeded(input: SyncRefScopedInput): Promise<void> {\n await markDefinitionSyncState({\n projectId: input.projectId,\n sourceConnectionId: input.sourceConnectionId,\n sourceExternalRepositoryId: input.sourceExternalRepositoryId,\n ref: input.sourceRef,\n status: 'succeeded',\n lastErrorCode: null,\n lastErrorMessage: null,\n finishedAt: new Date(),\n });\n };\n}\n\nfunction createMarkSyncFailedActivity() {\n return async function markDefinitionSyncFailed(\n input: MarkSyncFailedActivityInput,\n ): Promise<void> {\n await markDefinitionSyncState({\n projectId: input.projectId,\n sourceConnectionId: input.sourceConnectionId,\n sourceExternalRepositoryId: input.sourceExternalRepositoryId,\n ref: input.sourceRef ?? UNRESOLVED_SYNC_REF,\n status: 'failed',\n lastErrorCode: input.code,\n lastErrorMessage: input.message,\n finishedAt: new Date(),\n });\n };\n}\n\nasync function runWithPermanentTranslation<T>(operation: () => Promise<T>): Promise<T> {\n try {\n return await operation();\n } catch (error) {\n if (error instanceof ApplicationFailure) {\n throw error;\n }\n const failure = classifySyncFailure(error);\n const translatedError = failure.retryable\n ? ApplicationFailure.retryable(failure.message, failure.code)\n : ApplicationFailure.nonRetryable(failure.message, failure.code);\n if (failure.code !== 'unknown') markErrorReported(translatedError);\n throw translatedError;\n }\n}\n"],"names":["markErrorReported","Context","ApplicationFailure","classifySyncFailure","discoverWorkflowFiles","fetchAndParseWorkflows","resolveSyncSource","UNRESOLVED_SYNC_REF","loadIntegrationValidationContext","applyVcsDefinitionsBatch","markDefinitionSyncState","createDefinitionSyncActivities","sourceControl","agent","integrations","prepareDefinitionSync","createPrepareDefinitionSyncActivity","discoverDefinitionWorkflows","createDiscoverDefinitionWorkflowsActivity","fetchAndApplyDefinitionWorkflows","createFetchAndApplyActivity","markDefinitionSyncSucceeded","createMarkSyncSucceededActivity","markDefinitionSyncFailed","createMarkSyncFailedActivity","input","runWithPermanentTranslation","sourceRef","ref","projectId","sourceConnectionId","sourceExternalRepositoryId","status","lastErrorCode","lastErrorMessage","startedAt","Date","finishedAt","sourceCommitSha","definitions","agentValidationCatalog","getValidationCatalog","onProgress","path","current","heartbeat","undefined","workspaceId","upserts","map","entry","configPath","name","document","definition","model","sourceSnapshot","contentHash","code","message","operation","error","failure","translatedError","retryable","nonRetryable"],"mappings":"AAEA,SAAQA,iBAAiB,QAAO,iCAAiC;AACjE,SAAQC,OAAO,QAAO,uBAAuB;AAC7C,SAAQC,kBAAkB,QAAO,qBAAqB;AAEtD,SACEC,mBAAmB,EACnBC,qBAAqB,EACrBC,sBAAsB,EACtBC,iBAAiB,EACjBC,mBAAmB,QACd,iBAAiB;AAExB,SAAQC,gCAAgC,QAAO,wBAAwB;AACvE,SAAQC,wBAAwB,EAAEC,uBAAuB,QAAO,eAAe;AAuC/E,OAAO,SAASC,+BACdC,aAAuC,EACvCC,KAA6B,EAC7BC,YAAmD;IAEnD,OAAO;QACLC,uBAAuBC,oCAAoCJ;QAC3DK,6BAA6BC,0CAA0CN;QACvEO,kCAAkCC,4BAChCR,eACAC,OACAC;QAEFO,6BAA6BC;QAC7BC,0BAA0BC;IAC5B;AACF;AAEA,SAASR,oCAAoCJ,aAAuC;IAClF,OAAO,eAAeG,sBACpBU,KAAwB;QAExB,OAAO,MAAMC,4BAA4B;YACvC,MAAMC,YAAYF,MAAME,SAAS,IAAI,AAAC,CAAA,MAAMrB,kBAAkB;gBAAC,GAAGmB,KAAK;gBAAEb;YAAa,EAAC,EAAGgB,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