@mastra/factory 0.2.2-alpha.1 → 0.2.2-alpha.2

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.
Files changed (155) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/auth.js +401 -334
  3. package/dist/auth.js.map +1 -1
  4. package/dist/capabilities/connection.js +1 -1
  5. package/dist/capabilities/intake.js +1 -1
  6. package/dist/capabilities/version-control.js +1 -1
  7. package/dist/factory.js +441 -39622
  8. package/dist/factory.js.map +1 -1
  9. package/dist/index.js +2 -39633
  10. package/dist/integrations/base.js +1 -1
  11. package/dist/integrations/github/config.js +36 -22
  12. package/dist/integrations/github/config.js.map +1 -1
  13. package/dist/integrations/github/factory-session.js +33 -37
  14. package/dist/integrations/github/factory-session.js.map +1 -1
  15. package/dist/integrations/github/integration.js +1037 -3672
  16. package/dist/integrations/github/integration.js.map +1 -1
  17. package/dist/integrations/github/issue-triage.js +71 -71
  18. package/dist/integrations/github/issue-triage.js.map +1 -1
  19. package/dist/integrations/github/pat.js +47 -36
  20. package/dist/integrations/github/pat.js.map +1 -1
  21. package/dist/integrations/github/provenance.js +72 -101
  22. package/dist/integrations/github/provenance.js.map +1 -1
  23. package/dist/integrations/github/routes.js +1272 -1881
  24. package/dist/integrations/github/routes.js.map +1 -1
  25. package/dist/integrations/github/rules.js +203 -471
  26. package/dist/integrations/github/rules.js.map +1 -1
  27. package/dist/integrations/github/sandbox.js +400 -345
  28. package/dist/integrations/github/sandbox.js.map +1 -1
  29. package/dist/integrations/github/session-subscriptions.js +165 -223
  30. package/dist/integrations/github/session-subscriptions.js.map +1 -1
  31. package/dist/integrations/github/subscriptions.js +43 -51
  32. package/dist/integrations/github/subscriptions.js.map +1 -1
  33. package/dist/integrations/github/token-refresh.js +15 -18
  34. package/dist/integrations/github/token-refresh.js.map +1 -1
  35. package/dist/integrations/github/webhook.js +359 -343
  36. package/dist/integrations/github/webhook.js.map +1 -1
  37. package/dist/integrations/linear/agent-tools.js +77 -100
  38. package/dist/integrations/linear/agent-tools.js.map +1 -1
  39. package/dist/integrations/linear/integration.js +611 -1309
  40. package/dist/integrations/linear/integration.js.map +1 -1
  41. package/dist/integrations/linear/routes.js +227 -230
  42. package/dist/integrations/linear/routes.js.map +1 -1
  43. package/dist/integrations/linear/rules.js +126 -346
  44. package/dist/integrations/linear/rules.js.map +1 -1
  45. package/dist/integrations/linear/storage.js +1 -1
  46. package/dist/integrations/platform/api-client.js +131 -135
  47. package/dist/integrations/platform/api-client.js.map +1 -1
  48. package/dist/integrations/platform/github/event-worker.js +275 -573
  49. package/dist/integrations/platform/github/event-worker.js.map +1 -1
  50. package/dist/integrations/platform/github/integration.js +845 -4022
  51. package/dist/integrations/platform/github/integration.js.map +1 -1
  52. package/dist/integrations/platform/linear/integration.js +457 -1309
  53. package/dist/integrations/platform/linear/integration.js.map +1 -1
  54. package/dist/integrations/workos/integration.js +80 -85
  55. package/dist/integrations/workos/integration.js.map +1 -1
  56. package/dist/routes/config.d.ts.map +1 -1
  57. package/dist/routes/config.js +933 -912
  58. package/dist/routes/config.js.map +1 -1
  59. package/dist/routes/custom-provider-source.js +110 -93
  60. package/dist/routes/custom-provider-source.js.map +1 -1
  61. package/dist/routes/fs.js +401 -349
  62. package/dist/routes/fs.js.map +1 -1
  63. package/dist/routes/intake.js +165 -165
  64. package/dist/routes/intake.js.map +1 -1
  65. package/dist/routes/oauth.js +447 -25166
  66. package/dist/routes/oauth.js.map +1 -1
  67. package/dist/routes/projects.js +437 -376
  68. package/dist/routes/projects.js.map +1 -1
  69. package/dist/routes/provider-credentials.js +76 -58
  70. package/dist/routes/provider-credentials.js.map +1 -1
  71. package/dist/routes/route.js +12 -8
  72. package/dist/routes/route.js.map +1 -1
  73. package/dist/routes/skills.js +160 -173
  74. package/dist/routes/skills.js.map +1 -1
  75. package/dist/routes/surface.js +250 -28615
  76. package/dist/routes/surface.js.map +1 -1
  77. package/dist/routes/tenant-credentials.js +141 -166
  78. package/dist/routes/tenant-credentials.js.map +1 -1
  79. package/dist/routes/work-items.js +654 -862
  80. package/dist/routes/work-items.js.map +1 -1
  81. package/dist/rules/binding-context.js +23 -35
  82. package/dist/rules/binding-context.js.map +1 -1
  83. package/dist/rules/defaults.js +200 -309
  84. package/dist/rules/defaults.js.map +1 -1
  85. package/dist/rules/dispatcher.js +438 -683
  86. package/dist/rules/dispatcher.js.map +1 -1
  87. package/dist/rules/index.js +5 -599
  88. package/dist/rules/processor.js +344 -596
  89. package/dist/rules/processor.js.map +1 -1
  90. package/dist/rules/resolve.js +21 -18
  91. package/dist/rules/resolve.js.map +1 -1
  92. package/dist/rules/start-coordinator.js +168 -157
  93. package/dist/rules/start-coordinator.js.map +1 -1
  94. package/dist/rules/tools.js +50 -85
  95. package/dist/rules/tools.js.map +1 -1
  96. package/dist/rules/transition-service.js +183 -454
  97. package/dist/rules/transition-service.js.map +1 -1
  98. package/dist/rules/types.js +33 -29
  99. package/dist/rules/types.js.map +1 -1
  100. package/dist/rules/validation.js +266 -281
  101. package/dist/rules/validation.js.map +1 -1
  102. package/dist/sandbox/fleet.js +272 -250
  103. package/dist/sandbox/fleet.js.map +1 -1
  104. package/dist/sandbox/reattach.js +13 -6
  105. package/dist/sandbox/reattach.js.map +1 -1
  106. package/dist/server-error.js +12 -16
  107. package/dist/server-error.js.map +1 -1
  108. package/dist/skills/service.js +30 -35
  109. package/dist/skills/service.js.map +1 -1
  110. package/dist/spa-static.js +91 -65
  111. package/dist/spa-static.js.map +1 -1
  112. package/dist/state-signing.js +73 -44
  113. package/dist/state-signing.js.map +1 -1
  114. package/dist/storage/domains/audit/agent-audit.js +60 -59
  115. package/dist/storage/domains/audit/agent-audit.js.map +1 -1
  116. package/dist/storage/domains/audit/base.js +169 -112
  117. package/dist/storage/domains/audit/base.js.map +1 -1
  118. package/dist/storage/domains/audit/domain.js +155 -153
  119. package/dist/storage/domains/audit/domain.js.map +1 -1
  120. package/dist/storage/domains/credentials/base.js +259 -243
  121. package/dist/storage/domains/credentials/base.js.map +1 -1
  122. package/dist/storage/domains/custom-providers/base.js +138 -143
  123. package/dist/storage/domains/custom-providers/base.js.map +1 -1
  124. package/dist/storage/domains/intake/base.js +75 -57
  125. package/dist/storage/domains/intake/base.js.map +1 -1
  126. package/dist/storage/domains/integrations/base.js +310 -245
  127. package/dist/storage/domains/integrations/base.js.map +1 -1
  128. package/dist/storage/domains/memory-settings/base.js +117 -102
  129. package/dist/storage/domains/memory-settings/base.js.map +1 -1
  130. package/dist/storage/domains/model-packs/base.js +89 -88
  131. package/dist/storage/domains/model-packs/base.js.map +1 -1
  132. package/dist/storage/domains/projects/base.js +97 -92
  133. package/dist/storage/domains/projects/base.js.map +1 -1
  134. package/dist/storage/domains/queue-health/base.js +111 -76
  135. package/dist/storage/domains/queue-health/base.js.map +1 -1
  136. package/dist/storage/domains/source-control/base.js +777 -706
  137. package/dist/storage/domains/source-control/base.js.map +1 -1
  138. package/dist/storage/domains/source-control/inmemory.js +322 -348
  139. package/dist/storage/domains/source-control/inmemory.js.map +1 -1
  140. package/dist/storage/domains/work-items/base.js +1266 -1148
  141. package/dist/storage/domains/work-items/base.js.map +1 -1
  142. package/dist/storage/domains/work-items/metrics.js +202 -184
  143. package/dist/storage/domains/work-items/metrics.js.map +1 -1
  144. package/dist/timing.js +29 -22
  145. package/dist/timing.js.map +1 -1
  146. package/dist/workspace.js +236 -477
  147. package/dist/workspace.js.map +1 -1
  148. package/package.json +8 -8
  149. package/dist/capabilities/connection.js.map +0 -1
  150. package/dist/capabilities/intake.js.map +0 -1
  151. package/dist/capabilities/version-control.js.map +0 -1
  152. package/dist/index.js.map +0 -1
  153. package/dist/integrations/base.js.map +0 -1
  154. package/dist/integrations/linear/storage.js.map +0 -1
  155. package/dist/rules/index.js.map +0 -1
@@ -1 +1 @@
1
- //# sourceMappingURL=base.js.map
1
+ export {};
@@ -1,28 +1,42 @@
1
- // src/integrations/github/config.ts
2
- var GITHUB_APP_ENV_VARS = [
3
- "GITHUB_APP_ID",
4
- "GITHUB_APP_PRIVATE_KEY",
5
- "GITHUB_APP_CLIENT_ID",
6
- "GITHUB_APP_CLIENT_SECRET",
7
- "GITHUB_APP_SLUG"
1
+ //#region src/integrations/github/config.ts
2
+ /**
3
+ * Env vars the deploy entry reads to construct a `GithubIntegration`. Names
4
+ * only — used by diagnostics to tell an operator what to set when the
5
+ * integration is absent. The entry enforces all-or-nothing: partial config
6
+ * fails the boot, so at runtime the integration is either fully configured or
7
+ * not configured at all.
8
+ */
9
+ const GITHUB_APP_ENV_VARS = [
10
+ "GITHUB_APP_ID",
11
+ "GITHUB_APP_PRIVATE_KEY",
12
+ "GITHUB_APP_CLIENT_ID",
13
+ "GITHUB_APP_CLIENT_SECRET",
14
+ "GITHUB_APP_SLUG"
8
15
  ];
16
+ /**
17
+ * True when the GitHub App project feature should be active.
18
+ */
9
19
  function isGithubFeatureEnabled(options) {
10
- return options.github !== void 0 && options.auth.enabled();
20
+ return options.github !== void 0 && options.auth.enabled();
11
21
  }
22
+ /**
23
+ * Collect a non-secret diagnostic snapshot of every GitHub feature gate. Centralizes
24
+ * the feature-gate reasoning so startup logs, the status API, and the SPA explain
25
+ * the same state. Does not change `isGithubFeatureEnabled()` behavior.
26
+ */
12
27
  function getGithubFeatureDiagnostics(options) {
13
- const { github, auth, appDbConfigured, stateSigner, fleet } = options;
14
- return {
15
- githubAppConfigured: github !== void 0,
16
- factoryAuthEnabled: auth.enabled(),
17
- appDbConfigured,
18
- stateSecretConfigured: stateSigner?.stable ?? false,
19
- sandboxEnabled: fleet?.enabled ?? false,
20
- sandboxProvider: fleet?.provider ?? "none",
21
- missingGithubAppEnvVars: github ? [] : [...GITHUB_APP_ENV_VARS]
22
- };
28
+ const { github, auth, appDbConfigured, stateSigner, fleet } = options;
29
+ return {
30
+ githubAppConfigured: github !== void 0,
31
+ factoryAuthEnabled: auth.enabled(),
32
+ appDbConfigured,
33
+ stateSecretConfigured: stateSigner?.stable ?? false,
34
+ sandboxEnabled: fleet?.enabled ?? false,
35
+ sandboxProvider: fleet?.provider ?? "none",
36
+ missingGithubAppEnvVars: github ? [] : [...GITHUB_APP_ENV_VARS]
37
+ };
23
38
  }
24
- export {
25
- getGithubFeatureDiagnostics,
26
- isGithubFeatureEnabled
27
- };
39
+ //#endregion
40
+ export { getGithubFeatureDiagnostics, isGithubFeatureEnabled };
41
+
28
42
  //# sourceMappingURL=config.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/integrations/github/config.ts"],"sourcesContent":["/**\n * Composite feature gate + diagnostics for the GitHub App project feature.\n *\n * The GitHub feature is enabled only when *all three* hold:\n * - a `GithubIntegration` instance is registered with the factory\n * (constructed by the deploy entry from the `GITHUB_APP_*` env vars),\n * - web auth is enabled (a per-user installation requires a logged-in user),\n * - the application database is configured.\n *\n * OAuth/install `state` signing lives in `../../state-signing.ts` — the factory\n * creates one shared signer at boot and hands it to every integration.\n *\n * Everything here is pure: callers pass the handles they already own (the\n * integration, auth seam, state signer, sandbox fleet) — there is no global\n * registry lookup.\n */\n\nimport type { RouteAuth } from '../../routes/route.js';\nimport type { SandboxFleet } from '../../sandbox/fleet.js';\nimport type { StateSigner } from '../../state-signing.js';\nimport type { GithubIntegration } from './integration.js';\n\n/**\n * Env vars the deploy entry reads to construct a `GithubIntegration`. Names\n * only — used by diagnostics to tell an operator what to set when the\n * integration is absent. The entry enforces all-or-nothing: partial config\n * fails the boot, so at runtime the integration is either fully configured or\n * not configured at all.\n */\nconst GITHUB_APP_ENV_VARS = [\n 'GITHUB_APP_ID',\n 'GITHUB_APP_PRIVATE_KEY',\n 'GITHUB_APP_CLIENT_ID',\n 'GITHUB_APP_CLIENT_SECRET',\n 'GITHUB_APP_SLUG',\n] as const;\n\n/** Handles the GitHub feature gate + diagnostics are computed from. */\nexport interface GithubFeatureGateOptions {\n /** The registered GitHub integration, when configured. */\n github: GithubIntegration | undefined;\n /** Web auth seam — the feature requires a logged-in user. */\n auth: RouteAuth;\n /** True when the application database is configured. */\n appDbConfigured: boolean;\n /** Shared OAuth/install `state` signer, when configured. */\n stateSigner?: StateSigner;\n /** Sandbox fleet, when sandboxes are configured. */\n fleet?: SandboxFleet;\n}\n\n/**\n * True when the GitHub App project feature should be active.\n */\nexport function isGithubFeatureEnabled(options: Pick<GithubFeatureGateOptions, 'github' | 'auth'>): boolean {\n return options.github !== undefined && options.auth.enabled();\n}\n\n/**\n * Non-secret diagnostic snapshot of every GitHub feature gate. Used by startup\n * logs, `/web/github/status`, and the SPA so all three explain the same state.\n *\n * Only env var *names* and booleans are exposed — never secret values.\n */\nexport interface GithubFeatureDiagnostics {\n githubAppConfigured: boolean;\n factoryAuthEnabled: boolean;\n appDbConfigured: boolean;\n stateSecretConfigured: boolean;\n sandboxEnabled: boolean;\n sandboxProvider: string;\n /** Names of the GitHub App env vars still needed (empty when configured). */\n missingGithubAppEnvVars: string[];\n}\n\n/**\n * Collect a non-secret diagnostic snapshot of every GitHub feature gate. Centralizes\n * the feature-gate reasoning so startup logs, the status API, and the SPA explain\n * the same state. Does not change `isGithubFeatureEnabled()` behavior.\n */\nexport function getGithubFeatureDiagnostics(options: GithubFeatureGateOptions): GithubFeatureDiagnostics {\n const { github, auth, appDbConfigured, stateSigner, fleet } = options;\n return {\n githubAppConfigured: github !== undefined,\n factoryAuthEnabled: auth.enabled(),\n appDbConfigured,\n stateSecretConfigured: stateSigner?.stable ?? false,\n sandboxEnabled: fleet?.enabled ?? false,\n sandboxProvider: fleet?.provider ?? 'none',\n missingGithubAppEnvVars: github ? [] : [...GITHUB_APP_ENV_VARS],\n };\n}\n"],"mappings":";AA6BA,IAAM,sBAAsB;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAmBO,SAAS,uBAAuB,SAAqE;AAC1G,SAAO,QAAQ,WAAW,UAAa,QAAQ,KAAK,QAAQ;AAC9D;AAwBO,SAAS,4BAA4B,SAA6D;AACvG,QAAM,EAAE,QAAQ,MAAM,iBAAiB,aAAa,MAAM,IAAI;AAC9D,SAAO;AAAA,IACL,qBAAqB,WAAW;AAAA,IAChC,oBAAoB,KAAK,QAAQ;AAAA,IACjC;AAAA,IACA,uBAAuB,aAAa,UAAU;AAAA,IAC9C,gBAAgB,OAAO,WAAW;AAAA,IAClC,iBAAiB,OAAO,YAAY;AAAA,IACpC,yBAAyB,SAAS,CAAC,IAAI,CAAC,GAAG,mBAAmB;AAAA,EAChE;AACF;","names":[]}
1
+ {"version":3,"file":"config.js","names":[],"sources":["../../../src/integrations/github/config.ts"],"sourcesContent":["/**\n * Composite feature gate + diagnostics for the GitHub App project feature.\n *\n * The GitHub feature is enabled only when *all three* hold:\n * - a `GithubIntegration` instance is registered with the factory\n * (constructed by the deploy entry from the `GITHUB_APP_*` env vars),\n * - web auth is enabled (a per-user installation requires a logged-in user),\n * - the application database is configured.\n *\n * OAuth/install `state` signing lives in `../../state-signing.ts` — the factory\n * creates one shared signer at boot and hands it to every integration.\n *\n * Everything here is pure: callers pass the handles they already own (the\n * integration, auth seam, state signer, sandbox fleet) — there is no global\n * registry lookup.\n */\n\nimport type { RouteAuth } from '../../routes/route.js';\nimport type { SandboxFleet } from '../../sandbox/fleet.js';\nimport type { StateSigner } from '../../state-signing.js';\nimport type { GithubIntegration } from './integration.js';\n\n/**\n * Env vars the deploy entry reads to construct a `GithubIntegration`. Names\n * only — used by diagnostics to tell an operator what to set when the\n * integration is absent. The entry enforces all-or-nothing: partial config\n * fails the boot, so at runtime the integration is either fully configured or\n * not configured at all.\n */\nconst GITHUB_APP_ENV_VARS = [\n 'GITHUB_APP_ID',\n 'GITHUB_APP_PRIVATE_KEY',\n 'GITHUB_APP_CLIENT_ID',\n 'GITHUB_APP_CLIENT_SECRET',\n 'GITHUB_APP_SLUG',\n] as const;\n\n/** Handles the GitHub feature gate + diagnostics are computed from. */\nexport interface GithubFeatureGateOptions {\n /** The registered GitHub integration, when configured. */\n github: GithubIntegration | undefined;\n /** Web auth seam — the feature requires a logged-in user. */\n auth: RouteAuth;\n /** True when the application database is configured. */\n appDbConfigured: boolean;\n /** Shared OAuth/install `state` signer, when configured. */\n stateSigner?: StateSigner;\n /** Sandbox fleet, when sandboxes are configured. */\n fleet?: SandboxFleet;\n}\n\n/**\n * True when the GitHub App project feature should be active.\n */\nexport function isGithubFeatureEnabled(options: Pick<GithubFeatureGateOptions, 'github' | 'auth'>): boolean {\n return options.github !== undefined && options.auth.enabled();\n}\n\n/**\n * Non-secret diagnostic snapshot of every GitHub feature gate. Used by startup\n * logs, `/web/github/status`, and the SPA so all three explain the same state.\n *\n * Only env var *names* and booleans are exposed — never secret values.\n */\nexport interface GithubFeatureDiagnostics {\n githubAppConfigured: boolean;\n factoryAuthEnabled: boolean;\n appDbConfigured: boolean;\n stateSecretConfigured: boolean;\n sandboxEnabled: boolean;\n sandboxProvider: string;\n /** Names of the GitHub App env vars still needed (empty when configured). */\n missingGithubAppEnvVars: string[];\n}\n\n/**\n * Collect a non-secret diagnostic snapshot of every GitHub feature gate. Centralizes\n * the feature-gate reasoning so startup logs, the status API, and the SPA explain\n * the same state. Does not change `isGithubFeatureEnabled()` behavior.\n */\nexport function getGithubFeatureDiagnostics(options: GithubFeatureGateOptions): GithubFeatureDiagnostics {\n const { github, auth, appDbConfigured, stateSigner, fleet } = options;\n return {\n githubAppConfigured: github !== undefined,\n factoryAuthEnabled: auth.enabled(),\n appDbConfigured,\n stateSecretConfigured: stateSigner?.stable ?? false,\n sandboxEnabled: fleet?.enabled ?? false,\n sandboxProvider: fleet?.provider ?? 'none',\n missingGithubAppEnvVars: github ? [] : [...GITHUB_APP_ENV_VARS],\n };\n}\n"],"mappings":";;;;;;;;AA6BA,MAAM,sBAAsB;CAC1B;CACA;CACA;CACA;CACA;AACF;;;;AAmBA,SAAgB,uBAAuB,SAAqE;CAC1G,OAAO,QAAQ,WAAW,KAAA,KAAa,QAAQ,KAAK,QAAQ;AAC9D;;;;;;AAwBA,SAAgB,4BAA4B,SAA6D;CACvG,MAAM,EAAE,QAAQ,MAAM,iBAAiB,aAAa,UAAU;CAC9D,OAAO;EACL,qBAAqB,WAAW,KAAA;EAChC,oBAAoB,KAAK,QAAQ;EACjC;EACA,uBAAuB,aAAa,UAAU;EAC9C,gBAAgB,OAAO,WAAW;EAClC,iBAAiB,OAAO,YAAY;EACpC,yBAAyB,SAAS,CAAC,IAAI,CAAC,GAAG,mBAAmB;CAChE;AACF"}
@@ -1,41 +1,37 @@
1
- // src/integrations/github/factory-session.ts
2
1
  import { randomUUID } from "crypto";
2
+ //#region src/integrations/github/factory-session.ts
3
3
  async function ensureFactoryRuleSession(args) {
4
- const connections = await args.github.sourceControlStorage.connections.list({
5
- orgId: args.orgId,
6
- factoryProjectId: args.factoryProjectId
7
- });
8
- const connection = connections.find((candidate) => candidate.integrationId === args.github.id);
9
- if (!connection) throw new Error("Factory GitHub connection not found.");
10
- const projectRepositories = await args.github.sourceControlStorage.projectRepositories.list({
11
- orgId: args.orgId,
12
- connectionId: connection.id
13
- });
14
- const resolvedRepositories = await Promise.all(
15
- projectRepositories.map(async (projectRepository) => ({
16
- projectRepository,
17
- repository: await args.github.sourceControlStorage.repositories.get({
18
- orgId: args.orgId,
19
- id: projectRepository.repositoryId
20
- })
21
- }))
22
- );
23
- const resolved = resolvedRepositories.find(
24
- (candidate) => candidate.repository && (!args.repositorySlug || candidate.repository.slug === args.repositorySlug)
25
- );
26
- if (!resolved?.repository) throw new Error("Factory GitHub repository not found.");
27
- const userId = connection.createdByUserId;
28
- const session = await args.github.sourceControlStorage.sessions.create({
29
- sessionId: randomUUID(),
30
- projectRepositoryId: resolved.projectRepository.id,
31
- orgId: args.orgId,
32
- userId,
33
- branch: args.branch,
34
- baseBranch: resolved.projectRepository.branch ?? resolved.repository.defaultBranch
35
- });
36
- return { sessionId: session.sessionId, userId };
4
+ const connection = (await args.github.sourceControlStorage.connections.list({
5
+ orgId: args.orgId,
6
+ factoryProjectId: args.factoryProjectId
7
+ })).find((candidate) => candidate.integrationId === args.github.id);
8
+ if (!connection) throw new Error("Factory GitHub connection not found.");
9
+ const projectRepositories = await args.github.sourceControlStorage.projectRepositories.list({
10
+ orgId: args.orgId,
11
+ connectionId: connection.id
12
+ });
13
+ const resolved = (await Promise.all(projectRepositories.map(async (projectRepository) => ({
14
+ projectRepository,
15
+ repository: await args.github.sourceControlStorage.repositories.get({
16
+ orgId: args.orgId,
17
+ id: projectRepository.repositoryId
18
+ })
19
+ })))).find((candidate) => candidate.repository && (!args.repositorySlug || candidate.repository.slug === args.repositorySlug));
20
+ if (!resolved?.repository) throw new Error("Factory GitHub repository not found.");
21
+ const userId = connection.createdByUserId;
22
+ return {
23
+ sessionId: (await args.github.sourceControlStorage.sessions.create({
24
+ sessionId: randomUUID(),
25
+ projectRepositoryId: resolved.projectRepository.id,
26
+ orgId: args.orgId,
27
+ userId,
28
+ branch: args.branch,
29
+ baseBranch: resolved.projectRepository.branch ?? resolved.repository.defaultBranch
30
+ })).sessionId,
31
+ userId
32
+ };
37
33
  }
38
- export {
39
- ensureFactoryRuleSession
40
- };
34
+ //#endregion
35
+ export { ensureFactoryRuleSession };
36
+
41
37
  //# sourceMappingURL=factory-session.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/integrations/github/factory-session.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\n\nimport type { GithubIntegration } from './integration.js';\n\nexport async function ensureFactoryRuleSession(args: {\n github: GithubIntegration;\n orgId: string;\n factoryProjectId: string;\n repositorySlug?: string;\n branch: string;\n}): Promise<{ sessionId: string; userId: string }> {\n const connections = await args.github.sourceControlStorage.connections.list({\n orgId: args.orgId,\n factoryProjectId: args.factoryProjectId,\n });\n const connection = connections.find(candidate => candidate.integrationId === args.github.id);\n if (!connection) throw new Error('Factory GitHub connection not found.');\n\n const projectRepositories = await args.github.sourceControlStorage.projectRepositories.list({\n orgId: args.orgId,\n connectionId: connection.id,\n });\n const resolvedRepositories = await Promise.all(\n projectRepositories.map(async projectRepository => ({\n projectRepository,\n repository: await args.github.sourceControlStorage.repositories.get({\n orgId: args.orgId,\n id: projectRepository.repositoryId,\n }),\n })),\n );\n const resolved = resolvedRepositories.find(\n candidate => candidate.repository && (!args.repositorySlug || candidate.repository.slug === args.repositorySlug),\n );\n if (!resolved?.repository) throw new Error('Factory GitHub repository not found.');\n\n const userId = connection.createdByUserId;\n const session = await args.github.sourceControlStorage.sessions.create({\n sessionId: randomUUID(),\n projectRepositoryId: resolved.projectRepository.id,\n orgId: args.orgId,\n userId,\n branch: args.branch,\n baseBranch: resolved.projectRepository.branch ?? resolved.repository.defaultBranch,\n });\n return { sessionId: session.sessionId, userId };\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;AAI3B,eAAsB,yBAAyB,MAMI;AACjD,QAAM,cAAc,MAAM,KAAK,OAAO,qBAAqB,YAAY,KAAK;AAAA,IAC1E,OAAO,KAAK;AAAA,IACZ,kBAAkB,KAAK;AAAA,EACzB,CAAC;AACD,QAAM,aAAa,YAAY,KAAK,eAAa,UAAU,kBAAkB,KAAK,OAAO,EAAE;AAC3F,MAAI,CAAC,WAAY,OAAM,IAAI,MAAM,sCAAsC;AAEvE,QAAM,sBAAsB,MAAM,KAAK,OAAO,qBAAqB,oBAAoB,KAAK;AAAA,IAC1F,OAAO,KAAK;AAAA,IACZ,cAAc,WAAW;AAAA,EAC3B,CAAC;AACD,QAAM,uBAAuB,MAAM,QAAQ;AAAA,IACzC,oBAAoB,IAAI,OAAM,uBAAsB;AAAA,MAClD;AAAA,MACA,YAAY,MAAM,KAAK,OAAO,qBAAqB,aAAa,IAAI;AAAA,QAClE,OAAO,KAAK;AAAA,QACZ,IAAI,kBAAkB;AAAA,MACxB,CAAC;AAAA,IACH,EAAE;AAAA,EACJ;AACA,QAAM,WAAW,qBAAqB;AAAA,IACpC,eAAa,UAAU,eAAe,CAAC,KAAK,kBAAkB,UAAU,WAAW,SAAS,KAAK;AAAA,EACnG;AACA,MAAI,CAAC,UAAU,WAAY,OAAM,IAAI,MAAM,sCAAsC;AAEjF,QAAM,SAAS,WAAW;AAC1B,QAAM,UAAU,MAAM,KAAK,OAAO,qBAAqB,SAAS,OAAO;AAAA,IACrE,WAAW,WAAW;AAAA,IACtB,qBAAqB,SAAS,kBAAkB;AAAA,IAChD,OAAO,KAAK;AAAA,IACZ;AAAA,IACA,QAAQ,KAAK;AAAA,IACb,YAAY,SAAS,kBAAkB,UAAU,SAAS,WAAW;AAAA,EACvE,CAAC;AACD,SAAO,EAAE,WAAW,QAAQ,WAAW,OAAO;AAChD;","names":[]}
1
+ {"version":3,"file":"factory-session.js","names":[],"sources":["../../../src/integrations/github/factory-session.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\n\nimport type { GithubIntegration } from './integration.js';\n\nexport async function ensureFactoryRuleSession(args: {\n github: GithubIntegration;\n orgId: string;\n factoryProjectId: string;\n repositorySlug?: string;\n branch: string;\n}): Promise<{ sessionId: string; userId: string }> {\n const connections = await args.github.sourceControlStorage.connections.list({\n orgId: args.orgId,\n factoryProjectId: args.factoryProjectId,\n });\n const connection = connections.find(candidate => candidate.integrationId === args.github.id);\n if (!connection) throw new Error('Factory GitHub connection not found.');\n\n const projectRepositories = await args.github.sourceControlStorage.projectRepositories.list({\n orgId: args.orgId,\n connectionId: connection.id,\n });\n const resolvedRepositories = await Promise.all(\n projectRepositories.map(async projectRepository => ({\n projectRepository,\n repository: await args.github.sourceControlStorage.repositories.get({\n orgId: args.orgId,\n id: projectRepository.repositoryId,\n }),\n })),\n );\n const resolved = resolvedRepositories.find(\n candidate => candidate.repository && (!args.repositorySlug || candidate.repository.slug === args.repositorySlug),\n );\n if (!resolved?.repository) throw new Error('Factory GitHub repository not found.');\n\n const userId = connection.createdByUserId;\n const session = await args.github.sourceControlStorage.sessions.create({\n sessionId: randomUUID(),\n projectRepositoryId: resolved.projectRepository.id,\n orgId: args.orgId,\n userId,\n branch: args.branch,\n baseBranch: resolved.projectRepository.branch ?? resolved.repository.defaultBranch,\n });\n return { sessionId: session.sessionId, userId };\n}\n"],"mappings":";;AAIA,eAAsB,yBAAyB,MAMI;CAKjD,MAAM,cAAa,MAJO,KAAK,OAAO,qBAAqB,YAAY,KAAK;EAC1E,OAAO,KAAK;EACZ,kBAAkB,KAAK;CACzB,CAAC,EAAA,CAC8B,MAAK,cAAa,UAAU,kBAAkB,KAAK,OAAO,EAAE;CAC3F,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,sCAAsC;CAEvE,MAAM,sBAAsB,MAAM,KAAK,OAAO,qBAAqB,oBAAoB,KAAK;EAC1F,OAAO,KAAK;EACZ,cAAc,WAAW;CAC3B,CAAC;CAUD,MAAM,YAAW,MATkB,QAAQ,IACzC,oBAAoB,IAAI,OAAM,uBAAsB;EAClD;EACA,YAAY,MAAM,KAAK,OAAO,qBAAqB,aAAa,IAAI;GAClE,OAAO,KAAK;GACZ,IAAI,kBAAkB;EACxB,CAAC;CACH,EAAE,CACJ,EAAA,CACsC,MACpC,cAAa,UAAU,eAAe,CAAC,KAAK,kBAAkB,UAAU,WAAW,SAAS,KAAK,eACnG;CACA,IAAI,CAAC,UAAU,YAAY,MAAM,IAAI,MAAM,sCAAsC;CAEjF,MAAM,SAAS,WAAW;CAS1B,OAAO;EAAE,YAAW,MARE,KAAK,OAAO,qBAAqB,SAAS,OAAO;GACrE,WAAW,WAAW;GACtB,qBAAqB,SAAS,kBAAkB;GAChD,OAAO,KAAK;GACZ;GACA,QAAQ,KAAK;GACb,YAAY,SAAS,kBAAkB,UAAU,SAAS,WAAW;EACvE,CAAC,EAAA,CAC2B;EAAW;CAAO;AAChD"}