@aviaratech/ai-delivery 0.3.34 → 0.3.36

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 (301) hide show
  1. package/CONTRIBUTING.md +12 -206
  2. package/README.md +57 -506
  3. package/dist/agent.d.ts +0 -2
  4. package/dist/agent.js +76 -16
  5. package/dist/agent.js.map +7 -1
  6. package/dist/agentReadiness.test.js +73 -67
  7. package/dist/agentReadiness.test.js.map +7 -1
  8. package/dist/boardReconcile.test.js +1746 -0
  9. package/dist/boardReconcile.test.js.map +7 -0
  10. package/dist/build.test.js +130 -0
  11. package/dist/build.test.js.map +7 -0
  12. package/dist/callerErrors.test.js +105 -0
  13. package/dist/callerErrors.test.js.map +7 -0
  14. package/dist/cli.js +406 -485
  15. package/dist/cli.js.map +7 -1
  16. package/dist/cliResult.d.ts +2 -2
  17. package/dist/cliResult.js +42 -25
  18. package/dist/cliResult.js.map +7 -1
  19. package/dist/cliResult.test.js +434 -297
  20. package/dist/cliResult.test.js.map +7 -1
  21. package/dist/config/deliveryConfig.d.ts +320 -14
  22. package/dist/config/deliveryConfig.js +472 -385
  23. package/dist/config/deliveryConfig.js.map +7 -1
  24. package/dist/config/deliveryConfig.test.js +775 -584
  25. package/dist/config/deliveryConfig.test.js.map +7 -1
  26. package/dist/contributorChecks.test.js +1694 -916
  27. package/dist/contributorChecks.test.js.map +7 -1
  28. package/dist/currentConsumer.test.js +819 -737
  29. package/dist/currentConsumer.test.js.map +7 -1
  30. package/dist/currentTrackingScenario.test.js +499 -477
  31. package/dist/currentTrackingScenario.test.js.map +7 -1
  32. package/dist/delivery/common.js +160 -172
  33. package/dist/delivery/common.js.map +7 -1
  34. package/dist/delivery/delivery.test.js +509 -431
  35. package/dist/delivery/delivery.test.js.map +7 -1
  36. package/dist/delivery/evidence.d.ts +2 -2
  37. package/dist/delivery/evidence.js +133 -120
  38. package/dist/delivery/evidence.js.map +7 -1
  39. package/dist/delivery/index.js +7 -2
  40. package/dist/delivery/index.js.map +7 -1
  41. package/dist/delivery/legacy.js +65 -5
  42. package/dist/delivery/legacy.js.map +7 -1
  43. package/dist/delivery/policy.d.ts +10 -10
  44. package/dist/delivery/policy.js +211 -238
  45. package/dist/delivery/policy.js.map +7 -1
  46. package/dist/delivery/stage.d.ts +18 -18
  47. package/dist/delivery/stage.js +220 -235
  48. package/dist/delivery/stage.js.map +7 -1
  49. package/dist/deliveryBoard.d.ts +74 -0
  50. package/dist/deliveryBoard.js +644 -0
  51. package/dist/deliveryBoard.js.map +7 -0
  52. package/dist/deliveryBoard.test.d.ts +1 -0
  53. package/dist/deliveryBoard.test.js +649 -0
  54. package/dist/deliveryBoard.test.js.map +7 -0
  55. package/dist/deliveryHealth.test.js +179 -155
  56. package/dist/deliveryHealth.test.js.map +7 -1
  57. package/dist/dependencyCompatibility.test.js +154 -140
  58. package/dist/dependencyCompatibility.test.js.map +7 -1
  59. package/dist/directoryIndependent.test.js +417 -383
  60. package/dist/directoryIndependent.test.js.map +7 -1
  61. package/dist/dispatch.d.ts +17 -12
  62. package/dist/dispatch.js +330 -322
  63. package/dist/dispatch.js.map +7 -1
  64. package/dist/errors.d.ts +16 -3
  65. package/dist/errors.js +104 -82
  66. package/dist/errors.js.map +7 -1
  67. package/dist/fixtures/deliveryBoardReplay.d.ts +56 -0
  68. package/dist/fixtures/deliveryBoardReplay.js +617 -0
  69. package/dist/fixtures/deliveryBoardReplay.js.map +7 -0
  70. package/dist/fixtures/discovery.d.ts +59 -19
  71. package/dist/fixtures/discovery.js +96 -90
  72. package/dist/fixtures/discovery.js.map +7 -1
  73. package/dist/fixtures/inertEntrypointChild.js +57 -56
  74. package/dist/fixtures/inertEntrypointChild.js.map +7 -1
  75. package/dist/fixtures/inertEntrypoints.d.ts +1 -1
  76. package/dist/fixtures/inertEntrypoints.js +321 -276
  77. package/dist/fixtures/inertEntrypoints.js.map +7 -1
  78. package/dist/fixtures/inertTarget.d.ts +78 -7
  79. package/dist/fixtures/inertTarget.js +769 -691
  80. package/dist/fixtures/inertTarget.js.map +7 -1
  81. package/dist/fixtures/issue63.d.ts +4 -3
  82. package/dist/fixtures/issue63.js +260 -274
  83. package/dist/fixtures/issue63.js.map +7 -1
  84. package/dist/fixtures/issueProjectItems.d.ts +20 -0
  85. package/dist/fixtures/issueProjectItems.js +15 -0
  86. package/dist/fixtures/issueProjectItems.js.map +7 -0
  87. package/dist/fixtures/readView.d.ts +120 -0
  88. package/dist/fixtures/readView.js +172 -0
  89. package/dist/fixtures/readView.js.map +7 -0
  90. package/dist/fixtures/recordedGitHubFlows.d.ts +120 -0
  91. package/dist/fixtures/recordedGitHubFlows.js +109 -0
  92. package/dist/fixtures/recordedGitHubFlows.js.map +7 -0
  93. package/dist/genericCompatibility.test.js +64 -55
  94. package/dist/genericCompatibility.test.js.map +7 -1
  95. package/dist/git.js +73 -67
  96. package/dist/git.js.map +7 -1
  97. package/dist/gitProcess.d.ts +1 -1
  98. package/dist/gitProcess.js +58 -53
  99. package/dist/gitProcess.js.map +7 -1
  100. package/dist/github/client.d.ts +2 -2
  101. package/dist/github/client.js +484 -379
  102. package/dist/github/client.js.map +7 -1
  103. package/dist/github/commandIdentityPolicy.js +44 -51
  104. package/dist/github/commandIdentityPolicy.js.map +7 -1
  105. package/dist/github/discovery.d.ts +3 -0
  106. package/dist/github/discovery.js +197 -201
  107. package/dist/github/discovery.js.map +7 -1
  108. package/dist/github/discovery.test.js +223 -177
  109. package/dist/github/discovery.test.js.map +7 -1
  110. package/dist/github/issueHistory.d.ts +2 -2
  111. package/dist/github/issueHistory.js +117 -125
  112. package/dist/github/issueHistory.js.map +7 -1
  113. package/dist/github/machineAuth.d.ts +1 -1
  114. package/dist/github/machineAuth.js +126 -117
  115. package/dist/github/machineAuth.js.map +7 -1
  116. package/dist/github/machineAuth.test.js +755 -639
  117. package/dist/github/machineAuth.test.js.map +7 -1
  118. package/dist/github/nativeIssueMetadata.js +286 -273
  119. package/dist/github/nativeIssueMetadata.js.map +7 -1
  120. package/dist/github/projectDelivery.d.ts +53 -1
  121. package/dist/github/projectDelivery.js +623 -460
  122. package/dist/github/projectDelivery.js.map +7 -1
  123. package/dist/github/relationships.d.ts +5 -2
  124. package/dist/github/relationships.js +434 -333
  125. package/dist/github/relationships.js.map +7 -1
  126. package/dist/github/repo.d.ts +1 -0
  127. package/dist/github/repo.js +123 -96
  128. package/dist/github/repo.js.map +7 -1
  129. package/dist/index.js +3 -3
  130. package/dist/index.js.map +7 -1
  131. package/dist/issue.d.ts +103 -7
  132. package/dist/issue.js +2104 -1547
  133. package/dist/issue.js.map +7 -1
  134. package/dist/issue63History.test.js +40 -42
  135. package/dist/issue63History.test.js.map +7 -1
  136. package/dist/issue63Routes.test.js +154 -143
  137. package/dist/issue63Routes.test.js.map +7 -1
  138. package/dist/issueBatchUpdate.test.js +1004 -683
  139. package/dist/issueBatchUpdate.test.js.map +7 -1
  140. package/dist/issueBlockerGuard.test.js +262 -226
  141. package/dist/issueBlockerGuard.test.js.map +7 -1
  142. package/dist/issueContract.d.ts +23 -4
  143. package/dist/issueContract.js +416 -395
  144. package/dist/issueContract.js.map +7 -1
  145. package/dist/issueContract.test.d.ts +4 -3
  146. package/dist/issueContract.test.js +358 -321
  147. package/dist/issueContract.test.js.map +7 -1
  148. package/dist/issueDates.test.js +235 -233
  149. package/dist/issueDates.test.js.map +7 -1
  150. package/dist/issueInfoReadback.test.js +304 -190
  151. package/dist/issueInfoReadback.test.js.map +7 -1
  152. package/dist/issueIntake.test.js +1945 -1732
  153. package/dist/issueIntake.test.js.map +7 -1
  154. package/dist/issueJournal.d.ts +40 -19
  155. package/dist/issueJournal.js +229 -138
  156. package/dist/issueJournal.js.map +7 -1
  157. package/dist/issueJournal.test.js +605 -422
  158. package/dist/issueJournal.test.js.map +7 -1
  159. package/dist/issueRollup.test.d.ts +1 -0
  160. package/dist/issueRollup.test.js +476 -0
  161. package/dist/issueRollup.test.js.map +7 -0
  162. package/dist/issueTracking.test.js +1088 -593
  163. package/dist/issueTracking.test.js.map +7 -1
  164. package/dist/issueWriteRecovery.test.d.ts +1 -0
  165. package/dist/issueWriteRecovery.test.js +260 -0
  166. package/dist/issueWriteRecovery.test.js.map +7 -0
  167. package/dist/lifecycle.test.js +112 -441
  168. package/dist/lifecycle.test.js.map +7 -1
  169. package/dist/logger.js +80 -74
  170. package/dist/logger.js.map +7 -1
  171. package/dist/mcp/index.js +116 -90
  172. package/dist/mcp/index.js.map +7 -1
  173. package/dist/mcp/tools.d.ts +790 -220
  174. package/dist/mcp/tools.js +267 -333
  175. package/dist/mcp/tools.js.map +7 -1
  176. package/dist/pluginAuthProbe.js +63 -52
  177. package/dist/pluginAuthProbe.js.map +7 -1
  178. package/dist/pluginAuthProbe.test.js +85 -62
  179. package/dist/pluginAuthProbe.test.js.map +7 -1
  180. package/dist/pluginCredentials.test.js +282 -259
  181. package/dist/pluginCredentials.test.js.map +7 -1
  182. package/dist/pluginDoctor.test.js +653 -588
  183. package/dist/pluginDoctor.test.js.map +7 -1
  184. package/dist/pluginInstaller.d.ts +7 -5
  185. package/dist/pluginInstaller.js +1173 -1231
  186. package/dist/pluginInstaller.js.map +7 -1
  187. package/dist/pluginInstaller.test.js +1822 -1283
  188. package/dist/pluginInstaller.test.js.map +7 -1
  189. package/dist/pluginPackaging.test.js +485 -305
  190. package/dist/pluginPackaging.test.js.map +7 -1
  191. package/dist/pr.d.ts +132 -94
  192. package/dist/pr.js +1521 -1323
  193. package/dist/pr.js.map +7 -1
  194. package/dist/pr.test.js +1678 -632
  195. package/dist/pr.test.js.map +7 -1
  196. package/dist/prAssociation.test.js +2419 -1788
  197. package/dist/prAssociation.test.js.map +7 -1
  198. package/dist/prDispatch.test.js +150 -89
  199. package/dist/prDispatch.test.js.map +7 -1
  200. package/dist/readView.d.ts +183 -0
  201. package/dist/readView.js +217 -0
  202. package/dist/readView.js.map +7 -0
  203. package/dist/readView.test.d.ts +1 -0
  204. package/dist/readView.test.js +119 -0
  205. package/dist/readView.test.js.map +7 -0
  206. package/dist/releaseReconciliation.test.js +267 -288
  207. package/dist/releaseReconciliation.test.js.map +7 -1
  208. package/dist/releaseWorkflow.test.js +2493 -422
  209. package/dist/releaseWorkflow.test.js.map +7 -1
  210. package/dist/review.d.ts +738 -2
  211. package/dist/review.js +601 -348
  212. package/dist/review.js.map +7 -1
  213. package/dist/review.test.js +1218 -812
  214. package/dist/review.test.js.map +7 -1
  215. package/dist/reviewSubmit.test.d.ts +1 -0
  216. package/dist/reviewSubmit.test.js +747 -0
  217. package/dist/reviewSubmit.test.js.map +7 -0
  218. package/dist/services/agentReadinessService.js +42 -37
  219. package/dist/services/agentReadinessService.js.map +7 -1
  220. package/dist/services/blockerGuardService.js +188 -188
  221. package/dist/services/blockerGuardService.js.map +7 -1
  222. package/dist/services/boardReconcileService.d.ts +1204 -0
  223. package/dist/services/boardReconcileService.js +1445 -0
  224. package/dist/services/boardReconcileService.js.map +7 -0
  225. package/dist/services/deliveryAdmission.d.ts +2 -0
  226. package/dist/services/deliveryAdmission.js +129 -152
  227. package/dist/services/deliveryAdmission.js.map +7 -1
  228. package/dist/services/deliveryHealthService.js +197 -199
  229. package/dist/services/deliveryHealthService.js.map +7 -1
  230. package/dist/services/legacyIssueMigration.js +263 -277
  231. package/dist/services/legacyIssueMigration.js.map +7 -1
  232. package/dist/services/worktreeRegistry.d.ts +27 -119
  233. package/dist/services/worktreeRegistry.js +765 -1182
  234. package/dist/services/worktreeRegistry.js.map +7 -1
  235. package/dist/stagedChecks.test.js +396 -194
  236. package/dist/stagedChecks.test.js.map +7 -1
  237. package/dist/start.test.js +99 -95
  238. package/dist/start.test.js.map +7 -1
  239. package/dist/stdoutRegression.test.js +354 -350
  240. package/dist/stdoutRegression.test.js.map +7 -1
  241. package/dist/targetPolicyDiscovery.test.js +141 -143
  242. package/dist/targetPolicyDiscovery.test.js.map +7 -1
  243. package/dist/targetPolicyEntrypoints.test.js +308 -269
  244. package/dist/targetPolicyEntrypoints.test.js.map +7 -1
  245. package/dist/targetPolicyLocal.test.js +580 -1051
  246. package/dist/targetPolicyLocal.test.js.map +7 -1
  247. package/dist/targetPolicyRoutes.test.js +305 -281
  248. package/dist/targetPolicyRoutes.test.js.map +7 -1
  249. package/dist/targetRepositoryExecution.test.d.ts +1 -0
  250. package/dist/targetRepositoryExecution.test.js +463 -0
  251. package/dist/targetRepositoryExecution.test.js.map +7 -0
  252. package/dist/terminalMessages.js +41 -35
  253. package/dist/terminalMessages.js.map +7 -1
  254. package/dist/toolOutput.d.ts +2 -0
  255. package/dist/toolOutput.js +36 -0
  256. package/dist/toolOutput.js.map +7 -0
  257. package/dist/toolOutput.test.d.ts +1 -0
  258. package/dist/toolOutput.test.js +240 -0
  259. package/dist/toolOutput.test.js.map +7 -0
  260. package/dist/utils/atomicJson.js +84 -76
  261. package/dist/utils/atomicJson.js.map +7 -1
  262. package/dist/utils/filesystem.js +15 -18
  263. package/dist/utils/filesystem.js.map +7 -1
  264. package/dist/utils/lockfile.js +68 -71
  265. package/dist/utils/lockfile.js.map +7 -1
  266. package/dist/verification.d.ts +1 -19
  267. package/dist/verification.js +1020 -1929
  268. package/dist/verification.js.map +7 -1
  269. package/dist/verificationGate.test.js +127 -117
  270. package/dist/verificationGate.test.js.map +7 -1
  271. package/dist/version.d.ts +6 -0
  272. package/dist/version.js +24 -10
  273. package/dist/version.js.map +7 -1
  274. package/dist/worktree.d.ts +3 -15
  275. package/dist/worktree.js +97 -177
  276. package/dist/worktree.js.map +7 -1
  277. package/package.json +10 -8
  278. package/plugins/ai-delivery/.claude-plugin/plugin.json +2 -2
  279. package/plugins/ai-delivery/README.md +47 -156
  280. package/plugins/ai-delivery/plugin.json +1 -1
  281. package/plugins/ai-delivery/runtime/dist/THIRD-PARTY-NOTICES.md +261 -43
  282. package/plugins/ai-delivery/runtime/dist/cli.js +369 -125
  283. package/plugins/ai-delivery/runtime/package.json +1 -1
  284. package/plugins/ai-delivery/skills/intake-create/SKILL.md +14 -78
  285. package/plugins/ai-delivery/skills/pr-handoff/SKILL.md +35 -36
  286. package/plugins/ai-delivery/skills/worktree-lifecycle/SKILL.md +14 -15
  287. package/dist/investigationCompletion.test.js +0 -728
  288. package/dist/investigationCompletion.test.js.map +0 -1
  289. package/dist/setup.d.ts +0 -60
  290. package/dist/setup.js +0 -585
  291. package/dist/setup.js.map +0 -1
  292. package/dist/setup.test.js +0 -3058
  293. package/dist/setup.test.js.map +0 -1
  294. package/dist/worktreeTransition.d.ts +0 -211
  295. package/dist/worktreeTransition.js +0 -1037
  296. package/dist/worktreeTransition.js.map +0 -1
  297. package/dist/worktreeTransition.test.js +0 -1191
  298. package/dist/worktreeTransition.test.js.map +0 -1
  299. /package/dist/{investigationCompletion.test.d.ts → boardReconcile.test.d.ts} +0 -0
  300. /package/dist/{setup.test.d.ts → build.test.d.ts} +0 -0
  301. /package/dist/{worktreeTransition.test.d.ts → callerErrors.test.d.ts} +0 -0
@@ -1,82 +1,94 @@
1
- import { DeliveryError } from '../errors.js';
2
- export const PROJECT_DELIVERY_STATUSES = ['Todo', 'In Progress', 'Blocked', 'Done'];
3
- export async function archiveIssueProjectItem(input) {
4
- const configuration = input.configuration ??
5
- (await getProjectDeliveryConfiguration({
6
- ...input,
7
- settings: requireProjectSettings(input.settings),
8
- requireWritable: true,
9
- }));
10
- assertWritableConfiguration(configuration);
11
- const item = await findIssueProjectItem({ ...input, configuration });
12
- if (item === null)
13
- return null;
14
- if (item.archived)
15
- return { archived: true, itemId: item.id };
16
- const response = await input.graphql(`
1
+ import { CollectionLimitError, DeliveryError } from "../errors.js";
2
+ const PROJECT_DELIVERY_STATUSES = ["Todo", "In Progress", "Blocked", "Done"];
3
+ const PROJECT_REVIEW_STATUS = "In Review";
4
+ async function archiveIssueProjectItem(input) {
5
+ const configuration = input.configuration ?? await getProjectDeliveryConfiguration({
6
+ ...input,
7
+ settings: requireProjectSettings(input.settings),
8
+ requireWritable: true
9
+ });
10
+ assertWritableConfiguration(configuration);
11
+ const item = await findIssueProjectItem({ ...input, configuration });
12
+ if (item === null) return null;
13
+ if (item.archived) return { archived: true, itemId: item.id };
14
+ const response = await input.graphql(
15
+ `
17
16
  mutation ArchiveProjectDeliveryItem($projectId: ID!, $itemId: ID!) {
18
17
  archiveProjectV2Item(input: { projectId: $projectId, itemId: $itemId }) {
19
18
  item { id isArchived }
20
19
  }
21
20
  }
22
- `, { itemId: item.id, projectId: configuration.projectId });
23
- const record = requireRecord(response, 'GitHub returned invalid Project archive evidence.');
24
- const payload = requireRecord(record.archiveProjectV2Item, 'GitHub omitted Project archive payload.');
25
- const archivedItem = requireRecord(payload.item, 'GitHub omitted the archived Project item.');
26
- if (archivedItem.id !== item.id || archivedItem.isArchived !== true) {
27
- throw new DeliveryError('Project archive mutation did not return the exact archived item.');
28
- }
29
- await readBackProjectArchiveState({
30
- archived: true,
31
- configuration,
32
- graphql: input.graphql,
33
- issueNodeId: input.issueNodeId,
34
- itemId: item.id,
21
+ `,
22
+ { itemId: item.id, projectId: configuration.projectId }
23
+ );
24
+ const record = requireRecord(response, "GitHub returned invalid Project archive evidence.");
25
+ const payload = requireRecord(record.archiveProjectV2Item, "GitHub omitted Project archive payload.");
26
+ const archivedItem = requireRecord(payload.item, "GitHub omitted the archived Project item.");
27
+ if (archivedItem.id !== item.id || archivedItem.isArchived !== true) {
28
+ throw new DeliveryError("Project archive mutation did not return the exact archived item.");
29
+ }
30
+ await readBackProjectArchiveState({
31
+ archived: true,
32
+ configuration,
33
+ graphql: input.graphql,
34
+ issueNodeId: input.issueNodeId,
35
+ itemId: item.id
36
+ });
37
+ return { archived: true, itemId: item.id };
38
+ }
39
+ async function getIssueProjectStatus(input) {
40
+ const configuration = input.configuration ?? await getProjectDeliveryConfiguration({ ...input, settings: requireProjectSettings(input.settings) });
41
+ let item = await findIssueProjectItem({ ...input, configuration });
42
+ if (item === null || item.archived) return null;
43
+ if (item.status === null && item.statusOptionId === null) {
44
+ item = await readProjectItem({
45
+ configuration,
46
+ graphql: input.graphql,
47
+ issueNodeId: input.issueNodeId,
48
+ itemId: item.id,
49
+ ...input.capacityRead ? { capacityRead: true } : {}
35
50
  });
36
- return { archived: true, itemId: item.id };
51
+ }
52
+ if (item.archived) return null;
53
+ if (item.status === null && item.statusOptionId === null) return null;
54
+ const status = requireItemStatus(item, configuration);
55
+ return { itemId: item.id, status, ...item.review ? { review: true } : {} };
37
56
  }
38
- export async function getIssueProjectStatus(input) {
39
- const configuration = input.configuration ??
40
- (await getProjectDeliveryConfiguration({ ...input, settings: requireProjectSettings(input.settings) }));
41
- let item = await findIssueProjectItem({ ...input, configuration });
42
- if (item === null || item.archived)
43
- return null;
44
- // The list projection may omit a status already verified by a direct item read.
45
- // Resolve that exact item without inferring a status or accepting a missing item.
46
- if (item.status === null && item.statusOptionId === null) {
47
- item = await readProjectItem({
48
- configuration,
49
- graphql: input.graphql,
50
- issueNodeId: input.issueNodeId,
51
- itemId: item.id,
52
- ...(input.capacityRead ? { capacityRead: true } : {}),
53
- });
54
- }
55
- if (item.archived)
56
- return null;
57
- if (item.status === null && item.statusOptionId === null)
58
- return null;
59
- const status = requireItemStatus(item, configuration);
60
- return { itemId: item.id, status };
57
+ async function getArchivedIssueProjectStatus(input) {
58
+ const configuration = input.configuration ?? await getProjectDeliveryConfiguration({ ...input, settings: requireProjectSettings(input.settings) });
59
+ const item = await findIssueProjectItem({ ...input, configuration });
60
+ if (item === null || !item.archived || item.status === null && item.statusOptionId === null) return null;
61
+ return requireItemStatus(item, configuration);
61
62
  }
62
- export async function getProjectDeliveryConfiguration(input) {
63
- const settings = requireProjectSettings(input.settings);
64
- const project = await readProjectDeliveryDefinition({
65
- graphql: input.graphql,
66
- org: input.org,
67
- number: settings.number,
68
- });
69
- return resolveProjectDeliveryConfiguration(project, { requireWritable: input.requireWritable === true, settings });
63
+ async function getProjectDeliveryConfiguration(input) {
64
+ const settings = requireProjectSettings(input.settings);
65
+ const project = await readProjectDeliveryDefinition({
66
+ graphql: input.graphql,
67
+ org: input.org,
68
+ number: settings.number,
69
+ ...input.maxPages === void 0 ? {} : { maxPages: input.maxPages }
70
+ });
71
+ return resolveProjectDeliveryConfiguration(project, { requireWritable: input.requireWritable === true, settings });
70
72
  }
71
- export async function readProjectDeliveryDefinition(input) {
72
- const nodes = [];
73
- let cursor = null;
74
- let hasNextPage = true;
75
- const seenCursors = new Set();
76
- const fieldIds = new Set();
77
- let project = null;
78
- while (hasNextPage) {
79
- const response = await input.graphql(`
73
+ async function readProjectDeliveryDefinition(input) {
74
+ const nodes = [];
75
+ let cursor = null;
76
+ let hasNextPage = true;
77
+ const seenCursors = /* @__PURE__ */ new Set();
78
+ const fieldIds = /* @__PURE__ */ new Set();
79
+ let project = null;
80
+ let pages = 0;
81
+ while (hasNextPage) {
82
+ if (input.maxPages !== void 0 && pages >= input.maxPages)
83
+ throw new CollectionLimitError({
84
+ collection: "project-fields",
85
+ pagesRequested: pages,
86
+ rowsObserved: nodes.length,
87
+ limit: input.maxPages
88
+ });
89
+ pages++;
90
+ const response = await input.graphql(
91
+ `
80
92
  query ProjectDeliveryConfiguration($org: String!, $number: Int!, $cursor: String) {
81
93
  organization(login: $org) {
82
94
  projectV2(number: $number) {
@@ -122,206 +134,247 @@ export async function readProjectDeliveryDefinition(input) {
122
134
  }
123
135
  }
124
136
  }
125
- `, { cursor, number: input.number, org: input.org });
126
- const responseRecord = requireRecord(response, 'GitHub returned invalid delivery Project configuration.');
127
- if ('errors' in responseRecord)
128
- throw new DeliveryError('GitHub returned partial delivery Project evidence.');
129
- const organization = requireRecord(responseRecord.organization, `Organization ${input.org} is unavailable to the selected GitHub identity.`);
130
- const pageProject = requireRecord(organization.projectV2, `Expected organization Project #${String(input.number)}.`);
131
- const fields = requireRecord(pageProject.fields, 'GitHub omitted delivery Project fields.');
132
- const previousProject = project;
133
- if (previousProject !== null &&
134
- ['id', 'number', 'title', 'closed', 'viewerCanUpdate'].some((key) => previousProject[key] !== pageProject[key])) {
135
- throw new DeliveryError('Delivery Project identity changed while reading its field pages.');
136
- }
137
- if (!Array.isArray(fields.nodes)) {
138
- throw new DeliveryError('GitHub returned invalid delivery Project field nodes.');
139
- }
140
- for (const node of fields.nodes) {
141
- const field = requireRecord(node, 'GitHub returned an incomplete delivery Project field.');
142
- const fieldId = requireString(field.id, 'GitHub omitted a delivery Project field ID.');
143
- if (fieldIds.has(fieldId))
144
- throw new DeliveryError('GitHub repeated a delivery Project field.');
145
- fieldIds.add(fieldId);
146
- requireString(field.name, 'GitHub omitted a delivery Project field name.');
147
- requireString(field.__typename, 'GitHub omitted a delivery Project field type.');
148
- if (field.__typename === 'ProjectV2SingleSelectField') {
149
- if (typeof field.isIssueField !== 'boolean')
150
- throw new DeliveryError('GitHub omitted the Project field binding kind.');
151
- readOptions(field.options, 'Project field');
152
- if (field.isIssueField) {
153
- const issueField = requireRecord(field.issueField, 'GitHub omitted the bound organization field.');
154
- requireString(issueField.__typename, 'GitHub omitted the bound organization field type.');
155
- if (issueField.__typename === 'IssueFieldSingleSelect') {
156
- requireString(issueField.id, 'GitHub omitted the bound organization field ID.');
157
- requireString(issueField.name, 'GitHub omitted the bound organization field name.');
158
- if (!/^[1-9]\d*$/u.test(String(issueField.fullDatabaseId)))
159
- throw new DeliveryError('GitHub omitted the bound organization field database ID.');
160
- readOptions(issueField.options, 'organization field');
161
- }
162
- }
163
- }
164
- nodes.push(node);
165
- }
166
- project = { ...pageProject, fields: { nodes } };
167
- const pageInfo = requireRecord(fields.pageInfo, 'GitHub omitted delivery Project field pagination.');
168
- if (typeof pageInfo.hasNextPage !== 'boolean')
169
- throw new DeliveryError('GitHub omitted delivery Project pagination state.');
170
- hasNextPage = pageInfo.hasNextPage === true;
171
- const nextCursor = typeof pageInfo.endCursor === 'string' ? pageInfo.endCursor : null;
172
- assertAdvancingCursor({ cursor, hasNextPage, nextCursor, seenCursors, surface: 'field' });
173
- if (nextCursor !== null)
174
- seenCursors.add(nextCursor);
175
- cursor = nextCursor;
176
- }
177
- if (project === null) {
178
- throw new DeliveryError(`Expected organization Project #${String(input.number)}.`);
137
+ `,
138
+ { cursor, number: input.number, org: input.org }
139
+ );
140
+ const responseRecord = requireRecord(response, "GitHub returned invalid delivery Project configuration.");
141
+ if ("errors" in responseRecord) throw new DeliveryError("GitHub returned partial delivery Project evidence.");
142
+ const organization = requireRecord(
143
+ responseRecord.organization,
144
+ `Organization ${input.org} is unavailable to the selected GitHub identity.`
145
+ );
146
+ const pageProject = requireRecord(
147
+ organization.projectV2,
148
+ `Expected organization Project #${String(input.number)}.`
149
+ );
150
+ const fields = requireRecord(pageProject.fields, "GitHub omitted delivery Project fields.");
151
+ const previousProject = project;
152
+ if (previousProject !== null && ["id", "number", "title", "closed", "viewerCanUpdate"].some((key) => previousProject[key] !== pageProject[key])) {
153
+ throw new DeliveryError("Delivery Project identity changed while reading its field pages.");
179
154
  }
180
- return project;
181
- }
182
- export function projectSettingsFromDeliveryConfig(config) {
183
- const project = config.native.project;
184
- return {
185
- number: project.number,
186
- points: config.native.points,
187
- priority: config.native.priority,
188
- statuses: {
189
- Blocked: project.statuses.blocked,
190
- Done: project.statuses.done,
191
- 'In Progress': project.statuses.inProgress,
192
- Todo: project.statuses.todo,
193
- },
194
- statusField: project.statusField,
195
- title: project.title,
196
- };
197
- }
198
- export function resolveProjectDeliveryConfiguration(raw, options) {
199
- const settings = requireProjectSettings(options.settings);
200
- const project = requireRecord(raw, 'GitHub returned invalid delivery Project configuration.');
201
- if (project.number !== settings.number || project.title !== settings.title) {
202
- throw new DeliveryError(`Expected organization Project #${String(settings.number)} titled ${settings.title}.`);
203
- }
204
- if (options.requireWritable === true && project.viewerCanUpdate !== true) {
205
- throw new DeliveryError(`Organization Project #${String(settings.number)} is not writable by this identity.`);
206
- }
207
- const projectId = requireString(project.id, 'GitHub omitted the delivery Project node id.');
208
- const fields = requireRecord(project.fields, 'GitHub omitted delivery Project fields.');
209
155
  if (!Array.isArray(fields.nodes)) {
210
- throw new DeliveryError('GitHub returned invalid delivery Project field nodes.');
156
+ throw new DeliveryError("GitHub returned invalid delivery Project field nodes.");
211
157
  }
212
- const statusField = requireExactlyOneField(fields.nodes, settings.statusField);
213
- const pointsField = requireBoundIssueField({
214
- expectedDatabaseId: settings.points.databaseId,
215
- expectedOptions: settings.points.values,
216
- fields: fields.nodes,
217
- name: settings.points.name,
218
- });
219
- const priorityField = requireBoundIssueField({
220
- expectedDatabaseId: settings.priority.databaseId,
221
- expectedOptions: settings.priority.values,
222
- fields: fields.nodes,
223
- name: settings.priority.name,
224
- });
225
- if (statusField.__typename !== 'ProjectV2SingleSelectField' || statusField.isIssueField !== false) {
226
- throw new DeliveryError('Project Status must be the sole Project-owned single-select workflow field.');
158
+ for (const node of fields.nodes) {
159
+ const field = requireRecord(node, "GitHub returned an incomplete delivery Project field.");
160
+ const fieldId = requireString(field.id, "GitHub omitted a delivery Project field ID.");
161
+ if (fieldIds.has(fieldId)) throw new DeliveryError("GitHub repeated a delivery Project field.");
162
+ fieldIds.add(fieldId);
163
+ requireString(field.name, "GitHub omitted a delivery Project field name.");
164
+ requireString(field.__typename, "GitHub omitted a delivery Project field type.");
165
+ if (field.__typename === "ProjectV2SingleSelectField") {
166
+ if (typeof field.isIssueField !== "boolean")
167
+ throw new DeliveryError("GitHub omitted the Project field binding kind.");
168
+ readOptions(field.options, "Project field");
169
+ if (field.isIssueField) {
170
+ const issueField = requireRecord(field.issueField, "GitHub omitted the bound organization field.");
171
+ requireString(issueField.__typename, "GitHub omitted the bound organization field type.");
172
+ if (issueField.__typename === "IssueFieldSingleSelect") {
173
+ requireString(issueField.id, "GitHub omitted the bound organization field ID.");
174
+ requireString(issueField.name, "GitHub omitted the bound organization field name.");
175
+ if (!/^[1-9]\d*$/u.test(String(issueField.fullDatabaseId)))
176
+ throw new DeliveryError("GitHub omitted the bound organization field database ID.");
177
+ readOptions(issueField.options, "organization field");
178
+ }
179
+ }
180
+ }
181
+ nodes.push(node);
227
182
  }
228
- const statusOptions = readOptions(statusField.options, `Project ${settings.statusField}`);
229
- assertExactOptionSet({
230
- expected: PROJECT_DELIVERY_STATUSES.map((status) => settings.statuses[status]),
231
- fieldName: `Project ${settings.statusField}`,
232
- options: statusOptions,
233
- });
234
- const statusOptionIds = Object.fromEntries(PROJECT_DELIVERY_STATUSES.map((status) => [
235
- status,
236
- statusOptions.find((option) => option.name === settings.statuses[status])?.id,
237
- ]));
238
- return {
239
- pointsFieldId: requireString(pointsField.id, 'GitHub omitted the Project Points field id.'),
240
- priorityFieldId: requireString(priorityField.id, 'GitHub omitted the Project Priority field id.'),
241
- projectId,
242
- projectNumber: settings.number,
243
- settings,
244
- statusFieldId: requireString(statusField.id, 'GitHub omitted the Project Status field id.'),
245
- statusOptionIds,
246
- title: settings.title,
247
- writable: project.viewerCanUpdate === true,
248
- };
183
+ project = { ...pageProject, fields: { nodes } };
184
+ const pageInfo = requireRecord(fields.pageInfo, "GitHub omitted delivery Project field pagination.");
185
+ if (typeof pageInfo.hasNextPage !== "boolean")
186
+ throw new DeliveryError("GitHub omitted delivery Project pagination state.");
187
+ hasNextPage = pageInfo.hasNextPage === true;
188
+ const nextCursor = typeof pageInfo.endCursor === "string" ? pageInfo.endCursor : null;
189
+ assertAdvancingCursor({ cursor, hasNextPage, nextCursor, seenCursors, surface: "field" });
190
+ if (nextCursor !== null) seenCursors.add(nextCursor);
191
+ cursor = nextCursor;
192
+ }
193
+ if (project === null) {
194
+ throw new DeliveryError(`Expected organization Project #${String(input.number)}.`);
195
+ }
196
+ return project;
197
+ }
198
+ function projectSettingsFromDeliveryConfig(config) {
199
+ const project = config.native.project;
200
+ return {
201
+ number: project.number,
202
+ points: config.native.points,
203
+ priority: config.native.priority,
204
+ statuses: {
205
+ Blocked: project.statuses.blocked,
206
+ Done: project.statuses.done,
207
+ "In Progress": project.statuses.inProgress,
208
+ Todo: project.statuses.todo
209
+ },
210
+ statusField: project.statusField,
211
+ title: project.title
212
+ };
213
+ }
214
+ function resolveProjectDeliveryConfiguration(raw, options) {
215
+ const settings = requireProjectSettings(options.settings);
216
+ const project = requireRecord(raw, "GitHub returned invalid delivery Project configuration.");
217
+ if (project.number !== settings.number || project.title !== settings.title) {
218
+ throw new DeliveryError(`Expected organization Project #${String(settings.number)} titled ${settings.title}.`);
219
+ }
220
+ if (options.requireWritable === true && project.viewerCanUpdate !== true) {
221
+ throw new DeliveryError(`Organization Project #${String(settings.number)} is not writable by this identity.`);
222
+ }
223
+ const projectId = requireString(project.id, "GitHub omitted the delivery Project node id.");
224
+ const fields = requireRecord(project.fields, "GitHub omitted delivery Project fields.");
225
+ if (!Array.isArray(fields.nodes)) {
226
+ throw new DeliveryError("GitHub returned invalid delivery Project field nodes.");
227
+ }
228
+ const statusField = requireExactlyOneField(fields.nodes, settings.statusField);
229
+ const pointsField = requireBoundIssueField({
230
+ expectedDatabaseId: settings.points.databaseId,
231
+ expectedOptions: settings.points.values,
232
+ fields: fields.nodes,
233
+ name: settings.points.name
234
+ });
235
+ const priorityField = requireBoundIssueField({
236
+ expectedDatabaseId: settings.priority.databaseId,
237
+ expectedOptions: settings.priority.values,
238
+ fields: fields.nodes,
239
+ name: settings.priority.name
240
+ });
241
+ if (statusField.__typename !== "ProjectV2SingleSelectField" || statusField.isIssueField !== false) {
242
+ throw new DeliveryError("Project Status must be the sole Project-owned single-select workflow field.");
243
+ }
244
+ if (PROJECT_DELIVERY_STATUSES.some((status) => settings.statuses[status] === PROJECT_REVIEW_STATUS))
245
+ throw new DeliveryError(`Rename the configured Status that uses ${PROJECT_REVIEW_STATUS}; that name is reserved.`);
246
+ const allStatusOptions = readOptions(statusField.options, `Project ${settings.statusField}`);
247
+ const reviewOptions = allStatusOptions.filter((option) => option.name === PROJECT_REVIEW_STATUS);
248
+ const statusOptions = allStatusOptions.filter((option) => option.name !== PROJECT_REVIEW_STATUS);
249
+ if (reviewOptions.length > 1)
250
+ throw new DeliveryError(`Project ${settings.statusField} repeats ${PROJECT_REVIEW_STATUS}.`);
251
+ assertExactOptionSet({
252
+ expected: PROJECT_DELIVERY_STATUSES.map((status) => settings.statuses[status]),
253
+ fieldName: `Project ${settings.statusField}`,
254
+ options: statusOptions
255
+ });
256
+ const statusOptionIds = Object.fromEntries(
257
+ PROJECT_DELIVERY_STATUSES.map((status) => [
258
+ status,
259
+ statusOptions.find((option) => option.name === settings.statuses[status])?.id
260
+ ])
261
+ );
262
+ return {
263
+ pointsFieldId: requireString(pointsField.id, "GitHub omitted the Project Points field id."),
264
+ priorityFieldId: requireString(priorityField.id, "GitHub omitted the Project Priority field id."),
265
+ projectId,
266
+ projectNumber: settings.number,
267
+ settings,
268
+ statusFieldId: requireString(statusField.id, "GitHub omitted the Project Status field id."),
269
+ statusOptionIds,
270
+ ...reviewOptions[0] ? { reviewOptionId: reviewOptions[0].id } : {},
271
+ title: settings.title,
272
+ writable: project.viewerCanUpdate === true
273
+ };
249
274
  }
250
- export async function restoreIssueProjectItem(input) {
251
- const configuration = input.configuration ??
252
- (await getProjectDeliveryConfiguration({
253
- ...input,
254
- settings: requireProjectSettings(input.settings),
255
- requireWritable: true,
256
- }));
257
- assertWritableConfiguration(configuration);
258
- const item = await findIssueProjectItem({ ...input, configuration });
259
- if (item === null)
260
- return null;
261
- if (!item.archived)
262
- return { archived: false, itemId: item.id };
263
- const response = await input.graphql(`
275
+ async function restoreIssueProjectItem(input) {
276
+ const configuration = input.configuration ?? await getProjectDeliveryConfiguration({
277
+ ...input,
278
+ settings: requireProjectSettings(input.settings),
279
+ requireWritable: true
280
+ });
281
+ assertWritableConfiguration(configuration);
282
+ const item = await findIssueProjectItem({ ...input, configuration });
283
+ if (item === null) return null;
284
+ if (!item.archived) return { archived: false, itemId: item.id };
285
+ const response = await input.graphql(
286
+ `
264
287
  mutation RestoreProjectDeliveryItem($projectId: ID!, $itemId: ID!) {
265
288
  unarchiveProjectV2Item(input: { projectId: $projectId, itemId: $itemId }) {
266
289
  item { id isArchived }
267
290
  }
268
291
  }
269
- `, { itemId: item.id, projectId: configuration.projectId });
270
- const record = requireRecord(response, 'GitHub returned invalid Project restore evidence.');
271
- const payload = requireRecord(record.unarchiveProjectV2Item, 'GitHub omitted Project restore payload.');
272
- const restoredItem = requireRecord(payload.item, 'GitHub omitted the restored Project item.');
273
- if (restoredItem.id !== item.id || restoredItem.isArchived !== false) {
274
- throw new DeliveryError('Project restore mutation did not return the exact active item.');
275
- }
276
- await readBackProjectArchiveState({
277
- archived: false,
278
- configuration,
279
- graphql: input.graphql,
280
- issueNodeId: input.issueNodeId,
281
- itemId: item.id,
282
- });
283
- return { archived: false, itemId: item.id };
292
+ `,
293
+ { itemId: item.id, projectId: configuration.projectId }
294
+ );
295
+ const record = requireRecord(response, "GitHub returned invalid Project restore evidence.");
296
+ const payload = requireRecord(record.unarchiveProjectV2Item, "GitHub omitted Project restore payload.");
297
+ const restoredItem = requireRecord(payload.item, "GitHub omitted the restored Project item.");
298
+ if (restoredItem.id !== item.id || restoredItem.isArchived !== false) {
299
+ throw new DeliveryError("Project restore mutation did not return the exact active item.");
300
+ }
301
+ await readBackProjectArchiveState({
302
+ archived: false,
303
+ configuration,
304
+ graphql: input.graphql,
305
+ issueNodeId: input.issueNodeId,
306
+ itemId: item.id
307
+ });
308
+ return { archived: false, itemId: item.id };
284
309
  }
285
- export async function syncIssueProjectStatus(input) {
286
- const configuration = input.configuration ??
287
- (await getProjectDeliveryConfiguration({
288
- ...input,
289
- settings: requireProjectSettings(input.settings),
290
- requireWritable: true,
291
- }));
292
- assertWritableConfiguration(configuration);
293
- let item = await findIssueProjectItem({ ...input, configuration });
294
- if (item?.archived === true) {
295
- throw new DeliveryError('The issue delivery Project item is archived and cannot be updated.');
296
- }
297
- if (item !== null &&
298
- item.status !== null &&
299
- item.statusOptionId !== null &&
300
- requireItemStatus(item, configuration) === input.status) {
301
- return { itemId: item.id, status: input.status };
302
- }
303
- if (item === null) {
304
- const response = await input.graphql(`
310
+ async function assertIssueProjectWritable(input) {
311
+ const configuration = input.configuration ?? await getProjectDeliveryConfiguration({
312
+ ...input,
313
+ settings: requireProjectSettings(input.settings),
314
+ requireWritable: true
315
+ });
316
+ assertWritableConfiguration(configuration);
317
+ const item = await findIssueProjectItem({ ...input, configuration });
318
+ if (item?.archived === true) {
319
+ if (input.preserveArchived) return item.id;
320
+ throw new DeliveryError("The issue delivery Project item is archived and cannot be updated.");
321
+ }
322
+ return null;
323
+ }
324
+ async function ensureIssueProjectMembership(input) {
325
+ const configuration = input.configuration ?? await getProjectDeliveryConfiguration({
326
+ ...input,
327
+ settings: requireProjectSettings(input.settings),
328
+ requireWritable: true
329
+ });
330
+ assertWritableConfiguration(configuration);
331
+ const existing = await findIssueProjectItem({ ...input, configuration });
332
+ if (existing?.archived) throw new DeliveryError("The issue delivery Project item is archived and cannot be updated.");
333
+ let itemId = existing?.id;
334
+ if (itemId === void 0) {
335
+ await input.beforeAdd?.();
336
+ const response = await input.graphql(
337
+ `
305
338
  mutation AddProjectDeliveryItem($projectId: ID!, $contentId: ID!) {
306
339
  addProjectV2ItemById(input: { projectId: $projectId, contentId: $contentId }) {
307
340
  item { id }
308
341
  }
309
342
  }
310
- `, { contentId: input.issueNodeId, projectId: configuration.projectId });
311
- const added = requireRecord(response, 'GitHub returned invalid Project item creation evidence.');
312
- const payload = requireRecord(added.addProjectV2ItemById, 'GitHub omitted Project item creation payload.');
313
- const created = requireRecord(payload.item, 'GitHub omitted the created Project item.');
314
- item = {
315
- archived: false,
316
- contentId: input.issueNodeId,
317
- id: requireString(created.id, 'GitHub omitted the created Project item id.'),
318
- status: null,
319
- statusOptionId: null,
320
- };
321
- }
322
- const optionId = configuration.statusOptionIds[input.status];
323
- await input.beforeAdvance?.();
324
- const updateResponse = await input.graphql(`
343
+ `,
344
+ { contentId: input.issueNodeId, projectId: configuration.projectId }
345
+ );
346
+ const added = requireRecord(response, "GitHub returned invalid Project item creation evidence.");
347
+ const payload = requireRecord(added.addProjectV2ItemById, "GitHub omitted Project item creation payload.");
348
+ const created = requireRecord(payload.item, "GitHub omitted the created Project item.");
349
+ itemId = requireString(created.id, "GitHub omitted the created Project item id.");
350
+ }
351
+ input.onItemKnown?.(itemId);
352
+ const item = await readProjectItem({ configuration, graphql: input.graphql, issueNodeId: input.issueNodeId, itemId });
353
+ if (item.archived) throw new DeliveryError("Project membership readback is archived.");
354
+ return { itemId, archived: false };
355
+ }
356
+ async function syncIssueProjectStatus(input) {
357
+ const configuration = input.configuration ?? await getProjectDeliveryConfiguration({
358
+ ...input,
359
+ settings: requireProjectSettings(input.settings),
360
+ requireWritable: true
361
+ });
362
+ assertWritableConfiguration(configuration);
363
+ let item = await findIssueProjectItem({ ...input, configuration });
364
+ if (item?.archived === true) {
365
+ throw new DeliveryError("The issue delivery Project item is archived and cannot be updated.");
366
+ }
367
+ if (item !== null && item.status !== null && item.statusOptionId !== null && requireItemStatus(item, configuration) === input.status) {
368
+ return { itemId: item.id, status: input.status };
369
+ }
370
+ if (item === null) {
371
+ const membership = await ensureIssueProjectMembership({ ...input, configuration });
372
+ item = { archived: false, contentId: input.issueNodeId, id: membership.itemId, status: null, statusOptionId: null };
373
+ }
374
+ const optionId = configuration.statusOptionIds[input.status];
375
+ await input.beforeAdvance?.();
376
+ const updateResponse = await input.graphql(
377
+ `
325
378
  mutation UpdateProjectDeliveryStatus($projectId: ID!, $itemId: ID!, $fieldId: ID!, $optionId: String!) {
326
379
  updateProjectV2ItemFieldValue(
327
380
  input: {
@@ -334,64 +387,75 @@ export async function syncIssueProjectStatus(input) {
334
387
  projectV2Item { id }
335
388
  }
336
389
  }
337
- `, {
338
- fieldId: configuration.statusFieldId,
339
- itemId: item.id,
340
- optionId,
341
- projectId: configuration.projectId,
342
- });
343
- const update = requireRecord(updateResponse, 'GitHub returned invalid Project Status mutation evidence.');
344
- const updatePayload = requireRecord(update.updateProjectV2ItemFieldValue, 'GitHub omitted Project Status mutation payload.');
345
- const updatedItem = requireRecord(updatePayload.projectV2Item, 'GitHub omitted the updated Project item.');
346
- if (updatedItem.id !== item.id) {
347
- throw new DeliveryError('Project Status mutation returned a different item identity.');
390
+ `,
391
+ {
392
+ fieldId: configuration.statusFieldId,
393
+ itemId: item.id,
394
+ optionId,
395
+ projectId: configuration.projectId
348
396
  }
349
- return await readBackProjectItem({
350
- configuration,
351
- graphql: input.graphql,
352
- issueNodeId: input.issueNodeId,
353
- itemId: item.id,
354
- status: input.status,
355
- });
397
+ );
398
+ const update = requireRecord(updateResponse, "GitHub returned invalid Project Status mutation evidence.");
399
+ const updatePayload = requireRecord(
400
+ update.updateProjectV2ItemFieldValue,
401
+ "GitHub omitted Project Status mutation payload."
402
+ );
403
+ const updatedItem = requireRecord(updatePayload.projectV2Item, "GitHub omitted the updated Project item.");
404
+ if (updatedItem.id !== item.id) {
405
+ throw new DeliveryError("Project Status mutation returned a different item identity.");
406
+ }
407
+ return await readBackProjectItem({
408
+ configuration,
409
+ graphql: input.graphql,
410
+ issueNodeId: input.issueNodeId,
411
+ itemId: item.id,
412
+ status: input.status
413
+ });
356
414
  }
357
415
  function assertAdvancingCursor(input) {
358
- if (input.hasNextPage && input.nextCursor === null) {
359
- throw new DeliveryError(`Delivery Project ${input.surface} pagination omitted its next cursor.`);
360
- }
361
- if (input.hasNextPage &&
362
- input.nextCursor !== null &&
363
- (input.nextCursor === input.cursor || input.seenCursors.has(input.nextCursor))) {
364
- throw new DeliveryError(`Delivery Project ${input.surface} pagination repeated a non-advancing cursor.`);
365
- }
416
+ if (input.hasNextPage && input.nextCursor === null) {
417
+ throw new DeliveryError(`Delivery Project ${input.surface} pagination omitted its next cursor.`);
418
+ }
419
+ if (input.hasNextPage && input.nextCursor !== null && (input.nextCursor === input.cursor || input.seenCursors.has(input.nextCursor))) {
420
+ throw new DeliveryError(`Delivery Project ${input.surface} pagination repeated a non-advancing cursor.`);
421
+ }
366
422
  }
367
423
  function assertExactOptionSet(input) {
368
- const observed = input.options.map((option) => option.name);
369
- const observedSet = new Set(observed);
370
- const expectedSet = new Set(input.expected);
371
- if (observedSet.size !== observed.length ||
372
- observedSet.size !== expectedSet.size ||
373
- observed.some((option) => !expectedSet.has(option))) {
374
- throw new DeliveryError(`${input.fieldName} options must be exactly ${input.expected.join(', ')} (order is provider-owned).`);
375
- }
424
+ const observed = input.options.map((option) => option.name);
425
+ const observedSet = new Set(observed);
426
+ const expectedSet = new Set(input.expected);
427
+ if (observedSet.size !== observed.length || observedSet.size !== expectedSet.size || observed.some((option) => !expectedSet.has(option))) {
428
+ throw new DeliveryError(
429
+ `${input.fieldName} options must be exactly ${input.expected.join(", ")} (order is provider-owned).`
430
+ );
431
+ }
376
432
  }
377
433
  function assertWritableConfiguration(configuration) {
378
- if (!configuration.writable) {
379
- throw new DeliveryError(`Organization Project #${String(configuration.projectNumber)} is not writable by this identity.`);
380
- }
434
+ if (!configuration.writable) {
435
+ throw new DeliveryError(
436
+ `Organization Project #${String(configuration.projectNumber)} is not writable by this identity.`
437
+ );
438
+ }
381
439
  }
382
- async function findIssueProjectItem(input) {
383
- const matches = [];
384
- let cursor = null;
385
- let hasNextPage = true;
386
- const seenCursors = new Set();
387
- let pages = 0;
388
- if (input.maxPages !== undefined && (!Number.isSafeInteger(input.maxPages) || input.maxPages <= 0))
389
- throw new DeliveryError('Project item page budget must be positive.');
390
- while (hasNextPage) {
391
- if (input.maxPages !== undefined && pages >= input.maxPages)
392
- throw new DeliveryError('Project item page limit reached; status evidence is incomplete.');
393
- pages++;
394
- const response = await input.graphql(`
440
+ async function fetchProjectDeliveryItemNodes(input) {
441
+ const nodes = [];
442
+ let cursor = null;
443
+ let hasNextPage = true;
444
+ const seenCursors = /* @__PURE__ */ new Set();
445
+ let pages = 0;
446
+ if (input.maxPages !== void 0 && (!Number.isSafeInteger(input.maxPages) || input.maxPages <= 0))
447
+ throw new DeliveryError("Project item page budget must be positive.");
448
+ while (hasNextPage) {
449
+ if (input.maxPages !== void 0 && pages >= input.maxPages)
450
+ throw new CollectionLimitError({
451
+ collection: "project-items",
452
+ pagesRequested: pages,
453
+ rowsObserved: nodes.length,
454
+ limit: input.maxPages
455
+ });
456
+ pages++;
457
+ const response = await input.graphql(
458
+ `
395
459
  query ProjectDeliveryItems($org: String!, $number: Int!, $cursor: String, $statusField: String!) {
396
460
  organization(login: $org) {
397
461
  projectV2(number: $number) {
@@ -401,7 +465,7 @@ async function findIssueProjectItem(input) {
401
465
  nodes {
402
466
  id
403
467
  isArchived
404
- content { ... on Issue { id } }
468
+ content { __typename ... on Issue { id number repository { nameWithOwner } } ... on PullRequest { id } ... on DraftIssue { id } }
405
469
  fieldValueByName(name: $statusField) {
406
470
  ... on ProjectV2ItemFieldSingleSelectValue { name optionId }
407
471
  }
@@ -411,82 +475,174 @@ async function findIssueProjectItem(input) {
411
475
  }
412
476
  }
413
477
  }
414
- `, {
415
- cursor,
416
- number: input.configuration.projectNumber,
417
- org: input.org,
418
- statusField: input.configuration.settings.statusField,
419
- });
420
- const record = requireRecord(response, 'GitHub returned invalid delivery Project item evidence.');
421
- const organization = requireRecord(record.organization, 'GitHub omitted the delivery Project organization.');
422
- const project = requireRecord(organization.projectV2, 'GitHub omitted the delivery Project.');
423
- if (input.capacityRead &&
424
- (project.id !== input.configuration.projectId || project.number !== input.configuration.projectNumber))
425
- throw new DeliveryError('WIP capacity Project identity disagrees with the configured Project.');
426
- const items = requireRecord(project.items, 'GitHub omitted delivery Project items.');
427
- if (!Array.isArray(items.nodes)) {
428
- throw new DeliveryError('GitHub returned invalid delivery Project items.');
429
- }
430
- for (const rawItem of items.nodes) {
431
- const item = parseProjectItem(rawItem, input.configuration, input.capacityRead);
432
- if (item !== null && item.contentId === input.issueNodeId)
433
- matches.push(item);
434
- }
435
- const pageInfo = requireRecord(items.pageInfo, 'GitHub omitted delivery Project item pagination.');
436
- if (input.capacityRead && typeof pageInfo.hasNextPage !== 'boolean')
437
- throw new DeliveryError('WIP capacity Project pagination is incomplete.');
438
- hasNextPage = pageInfo.hasNextPage === true;
439
- const nextCursor = typeof pageInfo.endCursor === 'string' ? pageInfo.endCursor : null;
440
- assertAdvancingCursor({ cursor, hasNextPage, nextCursor, seenCursors, surface: 'item' });
441
- if (nextCursor !== null)
442
- seenCursors.add(nextCursor);
443
- cursor = nextCursor;
478
+ `,
479
+ {
480
+ cursor,
481
+ number: input.configuration.projectNumber,
482
+ org: input.org,
483
+ statusField: input.configuration.settings.statusField
484
+ }
485
+ );
486
+ const record = requireRecord(response, "GitHub returned invalid delivery Project item evidence.");
487
+ if (input.strictProjection && "errors" in record)
488
+ throw new DeliveryError("GitHub returned partial Project item evidence.");
489
+ const organization = requireRecord(record.organization, "GitHub omitted the delivery Project organization.");
490
+ const project = requireRecord(organization.projectV2, "GitHub omitted the delivery Project.");
491
+ if ((input.capacityRead || input.strictProjection) && (project.id !== input.configuration.projectId || project.number !== input.configuration.projectNumber))
492
+ throw new DeliveryError("WIP capacity Project identity disagrees with the configured Project.");
493
+ const items = requireRecord(project.items, "GitHub omitted delivery Project items.");
494
+ if (!Array.isArray(items.nodes)) {
495
+ throw new DeliveryError("GitHub returned invalid delivery Project items.");
444
496
  }
445
- if (matches.length > 1) {
446
- throw new DeliveryError(`Issue has ${String(matches.length)} duplicate Project items in ${input.configuration.title}.`);
497
+ nodes.push(...items.nodes);
498
+ const pageInfo = requireRecord(items.pageInfo, "GitHub omitted delivery Project item pagination.");
499
+ if ((input.capacityRead || input.strictProjection) && typeof pageInfo.hasNextPage !== "boolean" || input.capacityRead && pageInfo.endCursor !== null && typeof pageInfo.endCursor !== "string")
500
+ throw new DeliveryError("WIP capacity Project pagination is incomplete.");
501
+ hasNextPage = pageInfo.hasNextPage === true;
502
+ const nextCursor = typeof pageInfo.endCursor === "string" ? pageInfo.endCursor : null;
503
+ assertAdvancingCursor({ cursor, hasNextPage, nextCursor, seenCursors, surface: "item" });
504
+ if (nextCursor !== null) seenCursors.add(nextCursor);
505
+ cursor = nextCursor;
506
+ }
507
+ return nodes;
508
+ }
509
+ async function findIssueProjectItem(input) {
510
+ const response = await input.graphql(
511
+ `
512
+ query ProjectDeliveryIssueItems($issueNodeId: ID!, $statusField: String!) {
513
+ node(id: $issueNodeId) {
514
+ ... on Issue {
515
+ id
516
+ projectItems(first: 50, includeArchived: true) {
517
+ nodes {
518
+ id
519
+ isArchived
520
+ project { id number }
521
+ content { ... on Issue { id } }
522
+ fieldValueByName(name: $statusField) {
523
+ ... on ProjectV2ItemFieldSingleSelectValue { name optionId }
524
+ }
525
+ }
526
+ pageInfo { hasNextPage }
527
+ }
528
+ }
529
+ }
530
+ }
531
+ `,
532
+ { issueNodeId: input.issueNodeId, statusField: input.configuration.settings.statusField }
533
+ );
534
+ const record = requireRecord(response, "GitHub returned invalid issue Project evidence.");
535
+ const node = requireRecord(record.node, "GitHub omitted the issue.");
536
+ const items = requireRecord(node.projectItems, "GitHub omitted the issue Project items.");
537
+ if (node.id !== input.issueNodeId || !Array.isArray(items.nodes))
538
+ throw new DeliveryError("GitHub returned Project items for a different issue.");
539
+ if (requireRecord(items.pageInfo, "GitHub omitted issue Project pagination.").hasNextPage !== false)
540
+ throw new DeliveryError("Issue belongs to more than 50 Projects; Project membership cannot be proved.");
541
+ const matches = [];
542
+ for (const raw of items.nodes) {
543
+ const project = requireRecord(
544
+ requireRecord(raw, "GitHub returned an invalid Project item.").project,
545
+ "GitHub omitted the Project item identity."
546
+ );
547
+ if (project.id !== input.configuration.projectId) continue;
548
+ const item = parseProjectItem(raw, input.configuration, input.capacityRead);
549
+ if (item?.contentId !== input.issueNodeId)
550
+ throw new DeliveryError("Project membership is unreadable; absence cannot be proved.");
551
+ matches.push(item);
552
+ }
553
+ if (matches.length > 1)
554
+ throw new DeliveryError(
555
+ `Issue has ${String(matches.length)} duplicate Project items in ${input.configuration.title}.`
556
+ );
557
+ return matches[0] ?? null;
558
+ }
559
+ async function readProjectDeliveryItems(input) {
560
+ const observations = [];
561
+ const ids = /* @__PURE__ */ new Set();
562
+ for (const raw of await fetchProjectDeliveryItemNodes({ ...input, strictProjection: true })) {
563
+ const record = requireRecord(raw, "GitHub returned invalid Project membership.");
564
+ if (typeof record.isArchived !== "boolean") throw new DeliveryError("Project archive projection is incomplete.");
565
+ const content = requireRecord(record.content, "Project content is unreadable; absence cannot be proved.");
566
+ const kind = content.__typename;
567
+ if (kind !== "Issue" && kind !== "DraftIssue" && kind !== "PullRequest")
568
+ throw new DeliveryError("Project content type is unreadable.");
569
+ let item = parseProjectItem({ ...record, fieldValueByName: null }, input.configuration);
570
+ if (!item || ids.has(item.id)) throw new DeliveryError("Project item identity is missing or repeated.");
571
+ let statusRead = record.fieldValueByName === null ? "unset" : "unreadable";
572
+ const rawStatus = isRecord(record.fieldValueByName) ? record.fieldValueByName : null;
573
+ const safeText = (value) => typeof value === "string" && value.length > 0 && value.length <= 512 ? value : null;
574
+ const statusName = safeText(rawStatus?.name);
575
+ if (record.fieldValueByName !== void 0 && record.fieldValueByName !== null) {
576
+ try {
577
+ item = parseProjectItem(record, input.configuration);
578
+ statusRead = "verified";
579
+ } catch {
580
+ item.statusOptionId = safeText(rawStatus?.optionId);
581
+ }
447
582
  }
448
- return matches[0] ?? null;
583
+ ids.add(item.id);
584
+ const identity = {
585
+ ...item,
586
+ projectId: input.configuration.projectId,
587
+ projectNumber: input.configuration.projectNumber,
588
+ statusRead,
589
+ statusName
590
+ };
591
+ if (kind === "Issue") {
592
+ const repository = requireString(
593
+ requireRecord(content.repository, "Project issue repository is unreadable.").nameWithOwner,
594
+ "Project issue repository is missing."
595
+ );
596
+ if (!/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/u.test(repository) || !Number.isSafeInteger(content.number) || Number(content.number) <= 0)
597
+ throw new DeliveryError("Project issue identity is invalid.");
598
+ observations.push({ ...identity, contentKind: "issue", repository, issueNumber: Number(content.number) });
599
+ } else observations.push({ ...identity, contentKind: kind === "DraftIssue" ? "draft" : "pull-request" });
600
+ }
601
+ return observations;
449
602
  }
450
603
  function isRecord(value) {
451
- return typeof value === 'object' && value !== null && !Array.isArray(value);
604
+ return typeof value === "object" && value !== null && !Array.isArray(value);
452
605
  }
453
606
  function parseProjectItem(raw, configuration, capacityRead = false) {
454
- const item = requireRecord(raw, 'GitHub returned an invalid delivery Project item.');
455
- if (capacityRead && (typeof item.isArchived !== 'boolean' || item.fieldValueByName === undefined))
456
- throw new DeliveryError('WIP capacity Project status or archive evidence is missing.');
457
- const content = item.content;
458
- if (capacityRead && !item.isArchived && (content === null || content === undefined))
459
- throw new DeliveryError('WIP capacity Project item content is unreadable.');
460
- if (content === null || content === undefined)
461
- return null;
462
- const contentRecord = requireRecord(content, 'GitHub returned an invalid delivery Project item content node.');
463
- const contentId = requireString(contentRecord.id, 'GitHub omitted a delivery Project item content id.');
464
- const fieldValue = item.fieldValueByName;
465
- let status = null;
466
- let statusOptionId = null;
467
- if (fieldValue !== null && fieldValue !== undefined) {
468
- const statusRecord = requireRecord(fieldValue, 'GitHub returned invalid Project Status readback.');
469
- const name = requireString(statusRecord.name, 'GitHub omitted Project Status name.');
470
- const optionId = requireString(statusRecord.optionId, 'GitHub omitted Project Status option id.');
471
- const statuses = configuration.settings.statuses;
472
- const canonicalStatus = PROJECT_DELIVERY_STATUSES.find((candidate) => statuses[candidate] === name);
473
- if (canonicalStatus === undefined || configuration.statusOptionIds[canonicalStatus] !== optionId) {
474
- throw new DeliveryError(`GitHub returned unsupported Project Status ${name}.`);
475
- }
476
- status = canonicalStatus;
477
- statusOptionId = optionId;
607
+ const item = requireRecord(raw, "GitHub returned an invalid delivery Project item.");
608
+ if (capacityRead && (typeof item.isArchived !== "boolean" || item.fieldValueByName === void 0))
609
+ throw new DeliveryError("WIP capacity Project status or archive evidence is missing.");
610
+ const content = item.content;
611
+ if (capacityRead && !item.isArchived && (content === null || content === void 0))
612
+ throw new DeliveryError("WIP capacity Project item content is unreadable.");
613
+ if (content === null || content === void 0) return null;
614
+ const contentRecord = requireRecord(content, "GitHub returned an invalid delivery Project item content node.");
615
+ const contentId = requireString(contentRecord.id, "GitHub omitted a delivery Project item content id.");
616
+ const fieldValue = item.fieldValueByName;
617
+ let status = null;
618
+ let statusOptionId = null;
619
+ let review = false;
620
+ if (fieldValue !== null && fieldValue !== void 0) {
621
+ const statusRecord = requireRecord(fieldValue, "GitHub returned invalid Project Status readback.");
622
+ const name = requireString(statusRecord.name, "GitHub omitted Project Status name.");
623
+ const optionId = requireString(statusRecord.optionId, "GitHub omitted Project Status option id.");
624
+ const statuses = configuration.settings.statuses;
625
+ review = name === PROJECT_REVIEW_STATUS && optionId === configuration.reviewOptionId;
626
+ const canonicalStatus = review ? "In Progress" : PROJECT_DELIVERY_STATUSES.find((candidate) => statuses[candidate] === name);
627
+ if (canonicalStatus === void 0 || !review && configuration.statusOptionIds[canonicalStatus] !== optionId) {
628
+ throw new DeliveryError(`GitHub returned unsupported Project Status ${name}.`);
478
629
  }
479
- return {
480
- archived: item.isArchived === true,
481
- contentId,
482
- id: requireString(item.id, 'GitHub omitted the delivery Project item id.'),
483
- status,
484
- statusOptionId,
485
- };
630
+ status = canonicalStatus;
631
+ statusOptionId = review ? configuration.statusOptionIds["In Progress"] : optionId;
632
+ }
633
+ return {
634
+ archived: item.isArchived === true,
635
+ contentId,
636
+ id: requireString(item.id, "GitHub omitted the delivery Project item id."),
637
+ status,
638
+ statusOptionId,
639
+ ...review ? { review: true } : {}
640
+ };
486
641
  }
487
642
  async function readBackProjectArchiveState(input) {
488
- const response = await input.graphql(`
489
- query ${input.archived ? 'Archived' : 'Restored'}ProjectDeliveryItemReadback($itemId: ID!) {
643
+ const response = await input.graphql(
644
+ `
645
+ query ${input.archived ? "Archived" : "Restored"}ProjectDeliveryItemReadback($itemId: ID!) {
490
646
  node(id: $itemId) {
491
647
  ... on ProjectV2Item {
492
648
  id
@@ -496,31 +652,28 @@ async function readBackProjectArchiveState(input) {
496
652
  }
497
653
  }
498
654
  }
499
- `, { itemId: input.itemId });
500
- const state = input.archived ? 'archived' : 'restored';
501
- const record = requireRecord(response, `GitHub returned invalid ${state} Project item readback.`);
502
- const node = requireRecord(record.node, `GitHub omitted ${state} Project item readback.`);
503
- const project = requireRecord(node.project, `GitHub omitted ${state} Project identity readback.`);
504
- const content = requireRecord(node.content, `GitHub omitted ${state} Project item content readback.`);
505
- if (node.id !== input.itemId ||
506
- node.isArchived !== input.archived ||
507
- project.id !== input.configuration.projectId ||
508
- project.number !== input.configuration.projectNumber ||
509
- content.id !== input.issueNodeId) {
510
- throw new DeliveryError(`Project ${state} readback did not report the exact issue item.`);
511
- }
655
+ `,
656
+ { itemId: input.itemId }
657
+ );
658
+ const state = input.archived ? "archived" : "restored";
659
+ const record = requireRecord(response, `GitHub returned invalid ${state} Project item readback.`);
660
+ const node = requireRecord(record.node, `GitHub omitted ${state} Project item readback.`);
661
+ const project = requireRecord(node.project, `GitHub omitted ${state} Project identity readback.`);
662
+ const content = requireRecord(node.content, `GitHub omitted ${state} Project item content readback.`);
663
+ if (node.id !== input.itemId || node.isArchived !== input.archived || project.id !== input.configuration.projectId || project.number !== input.configuration.projectNumber || content.id !== input.issueNodeId) {
664
+ throw new DeliveryError(`Project ${state} readback did not report the exact issue item.`);
665
+ }
512
666
  }
513
667
  async function readBackProjectItem(input) {
514
- const item = await readProjectItem(input);
515
- if (item.archived ||
516
- item.status !== input.status ||
517
- item.statusOptionId !== input.configuration.statusOptionIds[input.status]) {
518
- throw new DeliveryError(`Project Status readback did not report ${input.status} for the exact issue item.`);
519
- }
520
- return { itemId: input.itemId, status: input.status };
668
+ const item = await readProjectItem(input);
669
+ if (item.archived || item.status !== input.status || item.statusOptionId !== input.configuration.statusOptionIds[input.status]) {
670
+ throw new DeliveryError(`Project Status readback did not report ${input.status} for the exact issue item.`);
671
+ }
672
+ return { itemId: input.itemId, status: input.status };
521
673
  }
522
674
  async function readProjectItem(input) {
523
- const response = await input.graphql(`
675
+ const response = await input.graphql(
676
+ `
524
677
  query ProjectDeliveryItemReadback($itemId: ID!, $statusField: String!) {
525
678
  node(id: $itemId) {
526
679
  ... on ProjectV2Item {
@@ -534,85 +687,95 @@ async function readProjectItem(input) {
534
687
  }
535
688
  }
536
689
  }
537
- `, { itemId: input.itemId, statusField: input.configuration.settings.statusField });
538
- const record = requireRecord(response, 'GitHub returned invalid Project item readback.');
539
- const node = requireRecord(record.node, 'GitHub omitted Project item readback.');
540
- const project = requireRecord(node.project, 'GitHub omitted Project identity readback.');
541
- const content = requireRecord(node.content, 'GitHub omitted Project item content readback.');
542
- if (node.id !== input.itemId ||
543
- typeof node.isArchived !== 'boolean' ||
544
- project.id !== input.configuration.projectId ||
545
- project.number !== input.configuration.projectNumber ||
546
- content.id !== input.issueNodeId) {
547
- throw new DeliveryError('Project Status readback did not report the exact issue item.');
548
- }
549
- const item = parseProjectItem(node, input.configuration, input.capacityRead);
550
- if (item === null)
551
- throw new DeliveryError('GitHub omitted Project item content readback.');
552
- return item;
690
+ `,
691
+ { itemId: input.itemId, statusField: input.configuration.settings.statusField }
692
+ );
693
+ const record = requireRecord(response, "GitHub returned invalid Project item readback.");
694
+ const node = requireRecord(record.node, "GitHub omitted Project item readback.");
695
+ const project = requireRecord(node.project, "GitHub omitted Project identity readback.");
696
+ const content = requireRecord(node.content, "GitHub omitted Project item content readback.");
697
+ if (node.id !== input.itemId || typeof node.isArchived !== "boolean" || project.id !== input.configuration.projectId || project.number !== input.configuration.projectNumber || content.id !== input.issueNodeId) {
698
+ throw new DeliveryError("Project Status readback did not report the exact issue item.");
699
+ }
700
+ const item = parseProjectItem(node, input.configuration, input.capacityRead);
701
+ if (item === null) throw new DeliveryError("GitHub omitted Project item content readback.");
702
+ return item;
553
703
  }
554
704
  function readOptions(raw, fieldName) {
555
- if (!Array.isArray(raw)) {
556
- throw new DeliveryError(`${fieldName} options are malformed.`);
557
- }
558
- return raw.map((option) => {
559
- const record = requireRecord(option, `${fieldName} option is malformed.`);
560
- return {
561
- id: requireString(record.id, `${fieldName} option id is missing.`),
562
- name: requireString(record.name, `${fieldName} option name is missing.`),
563
- };
564
- });
705
+ if (!Array.isArray(raw)) {
706
+ throw new DeliveryError(`${fieldName} options are malformed.`);
707
+ }
708
+ return raw.map((option) => {
709
+ const record = requireRecord(option, `${fieldName} option is malformed.`);
710
+ return {
711
+ id: requireString(record.id, `${fieldName} option id is missing.`),
712
+ name: requireString(record.name, `${fieldName} option name is missing.`)
713
+ };
714
+ });
565
715
  }
566
716
  function requireBoundIssueField(input) {
567
- const field = requireExactlyOneField(input.fields, input.name);
568
- if (field.__typename !== 'ProjectV2SingleSelectField' || field.isIssueField !== true) {
569
- throw new DeliveryError(`Project ${input.name} must bind the organization issue field.`);
570
- }
571
- if (Array.isArray(field.options) && field.options.length !== 0) {
572
- throw new DeliveryError(`Project ${input.name} must not define Project-owned duplicate options.`);
573
- }
574
- const issueField = requireRecord(field.issueField, `Project ${input.name} omitted its bound organization issue field.`);
575
- const databaseId = typeof issueField.fullDatabaseId === 'string' ? issueField.fullDatabaseId : String(issueField.fullDatabaseId);
576
- if (issueField.__typename !== 'IssueFieldSingleSelect' ||
577
- issueField.name !== input.name ||
578
- databaseId !== input.expectedDatabaseId) {
579
- throw new DeliveryError(`Project ${input.name} must bind organization issue field ${input.expectedDatabaseId}.`);
580
- }
581
- assertExactOptionSet({
582
- expected: input.expectedOptions,
583
- fieldName: input.name,
584
- options: readOptions(issueField.options, `organization ${input.name}`),
585
- });
586
- return field;
717
+ const field = requireExactlyOneField(input.fields, input.name);
718
+ if (field.__typename !== "ProjectV2SingleSelectField" || field.isIssueField !== true) {
719
+ throw new DeliveryError(`Project ${input.name} must bind the organization issue field.`);
720
+ }
721
+ if (Array.isArray(field.options) && field.options.length !== 0) {
722
+ throw new DeliveryError(`Project ${input.name} must not define Project-owned duplicate options.`);
723
+ }
724
+ const issueField = requireRecord(
725
+ field.issueField,
726
+ `Project ${input.name} omitted its bound organization issue field.`
727
+ );
728
+ const databaseId = typeof issueField.fullDatabaseId === "string" ? issueField.fullDatabaseId : String(issueField.fullDatabaseId);
729
+ if (issueField.__typename !== "IssueFieldSingleSelect" || issueField.name !== input.name || databaseId !== input.expectedDatabaseId) {
730
+ throw new DeliveryError(`Project ${input.name} must bind organization issue field ${input.expectedDatabaseId}.`);
731
+ }
732
+ assertExactOptionSet({
733
+ expected: input.expectedOptions,
734
+ fieldName: input.name,
735
+ options: readOptions(issueField.options, `organization ${input.name}`)
736
+ });
737
+ return field;
587
738
  }
588
739
  function requireExactlyOneField(fields, name) {
589
- const matches = fields.filter((field) => isRecord(field) && field.name === name);
590
- if (matches.length !== 1) {
591
- throw new DeliveryError(`Expected exactly one Project ${name} field, found ${String(matches.length)}.`);
592
- }
593
- return matches[0];
740
+ const matches = fields.filter((field) => isRecord(field) && field.name === name);
741
+ if (matches.length !== 1) {
742
+ throw new DeliveryError(`Expected exactly one Project ${name} field, found ${String(matches.length)}.`);
743
+ }
744
+ return matches[0];
594
745
  }
595
746
  function requireItemStatus(item, configuration) {
596
- if (item.status === null ||
597
- item.statusOptionId === null ||
598
- configuration.statusOptionIds[item.status] !== item.statusOptionId) {
599
- throw new DeliveryError('The issue delivery Project item has no canonical Project Status.');
600
- }
601
- return item.status;
747
+ if (item.status === null || item.statusOptionId === null || configuration.statusOptionIds[item.status] !== item.statusOptionId) {
748
+ throw new DeliveryError("The issue delivery Project item has no canonical Project Status.");
749
+ }
750
+ return item.status;
602
751
  }
603
752
  function requireRecord(value, message) {
604
- if (!isRecord(value))
605
- throw new DeliveryError(message);
606
- return value;
753
+ if (!isRecord(value)) throw new DeliveryError(message);
754
+ return value;
607
755
  }
608
756
  function requireString(value, message) {
609
- if (typeof value !== 'string' || value.length === 0)
610
- throw new DeliveryError(message);
611
- return value;
757
+ if (typeof value !== "string" || value.length === 0) throw new DeliveryError(message);
758
+ return value;
612
759
  }
613
760
  function requireProjectSettings(settings) {
614
- if (settings === undefined)
615
- throw new DeliveryError('Project delivery settings are required.');
616
- return settings;
761
+ if (settings === void 0) throw new DeliveryError("Project delivery settings are required.");
762
+ return settings;
617
763
  }
618
- //# sourceMappingURL=projectDelivery.js.map
764
+ export {
765
+ PROJECT_DELIVERY_STATUSES,
766
+ PROJECT_REVIEW_STATUS,
767
+ archiveIssueProjectItem,
768
+ assertIssueProjectWritable,
769
+ ensureIssueProjectMembership,
770
+ getArchivedIssueProjectStatus,
771
+ getIssueProjectStatus,
772
+ getProjectDeliveryConfiguration,
773
+ projectSettingsFromDeliveryConfig,
774
+ readBackProjectItem,
775
+ readProjectDeliveryDefinition,
776
+ readProjectDeliveryItems,
777
+ resolveProjectDeliveryConfiguration,
778
+ restoreIssueProjectItem,
779
+ syncIssueProjectStatus
780
+ };
781
+ //# sourceMappingURL=projectDelivery.js.map