@antelopejs/dms-antelope-cloud 0.0.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +448 -0
  3. package/dist/cloud-status.d.ts +13 -0
  4. package/dist/cloud-status.js +77 -0
  5. package/dist/config.d.ts +84 -0
  6. package/dist/config.js +104 -0
  7. package/dist/configured.d.ts +16 -0
  8. package/dist/configured.js +26 -0
  9. package/dist/connection/actions.d.ts +40 -0
  10. package/dist/connection/actions.js +120 -0
  11. package/dist/connection/announce.d.ts +8 -0
  12. package/dist/connection/announce.js +20 -0
  13. package/dist/connection/cloud.d.ts +60 -0
  14. package/dist/connection/cloud.js +87 -0
  15. package/dist/connection/content.d.ts +70 -0
  16. package/dist/connection/content.js +462 -0
  17. package/dist/connection/current.d.ts +26 -0
  18. package/dist/connection/current.js +28 -0
  19. package/dist/connection/device-flow.d.ts +16 -0
  20. package/dist/connection/device-flow.js +146 -0
  21. package/dist/connection/refusals.d.ts +51 -0
  22. package/dist/connection/refusals.js +85 -0
  23. package/dist/connection/repository.d.ts +28 -0
  24. package/dist/connection/repository.js +69 -0
  25. package/dist/connection/seal.d.ts +22 -0
  26. package/dist/connection/seal.js +47 -0
  27. package/dist/connection/store.d.ts +294 -0
  28. package/dist/connection/store.js +165 -0
  29. package/dist/connection/view.d.ts +39 -0
  30. package/dist/connection/view.js +39 -0
  31. package/dist/dashboard/actions.d.ts +40 -0
  32. package/dist/dashboard/actions.js +115 -0
  33. package/dist/dashboard/dockerfile.d.ts +34 -0
  34. package/dist/dashboard/dockerfile.js +71 -0
  35. package/dist/dashboard/service.d.ts +61 -0
  36. package/dist/dashboard/service.js +137 -0
  37. package/dist/dashboard/variables.d.ts +30 -0
  38. package/dist/dashboard/variables.js +34 -0
  39. package/dist/deployments/build-log.d.ts +39 -0
  40. package/dist/deployments/build-log.js +57 -0
  41. package/dist/deployments/cloud-steps.d.ts +77 -0
  42. package/dist/deployments/cloud-steps.js +132 -0
  43. package/dist/deployments/content.d.ts +61 -0
  44. package/dist/deployments/content.js +268 -0
  45. package/dist/deployments/deployment.d.ts +96 -0
  46. package/dist/deployments/deployment.js +3 -0
  47. package/dist/deployments/follow.d.ts +18 -0
  48. package/dist/deployments/follow.js +112 -0
  49. package/dist/deployments/ledger.d.ts +23 -0
  50. package/dist/deployments/ledger.js +359 -0
  51. package/dist/deployments/lifecycle.d.ts +123 -0
  52. package/dist/deployments/lifecycle.js +146 -0
  53. package/dist/deployments/live.d.ts +28 -0
  54. package/dist/deployments/live.js +54 -0
  55. package/dist/deployments/publish-read.d.ts +20 -0
  56. package/dist/deployments/publish-read.js +24 -0
  57. package/dist/deployments/refusals.d.ts +13 -0
  58. package/dist/deployments/refusals.js +35 -0
  59. package/dist/environments/actions.d.ts +86 -0
  60. package/dist/environments/actions.js +210 -0
  61. package/dist/environments/address.d.ts +60 -0
  62. package/dist/environments/address.js +149 -0
  63. package/dist/environments/content.d.ts +97 -0
  64. package/dist/environments/content.js +275 -0
  65. package/dist/environments/follower.d.ts +32 -0
  66. package/dist/environments/follower.js +114 -0
  67. package/dist/environments/pipeline.d.ts +58 -0
  68. package/dist/environments/pipeline.js +76 -0
  69. package/dist/environments/publish-targets.d.ts +18 -0
  70. package/dist/environments/publish-targets.js +55 -0
  71. package/dist/environments/roles.d.ts +73 -0
  72. package/dist/environments/roles.js +97 -0
  73. package/dist/frontend-module.d.ts +12 -0
  74. package/dist/frontend-module.js +25 -0
  75. package/dist/git/changed-files.d.ts +30 -0
  76. package/dist/git/changed-files.js +107 -0
  77. package/dist/git/changes.d.ts +89 -0
  78. package/dist/git/changes.js +162 -0
  79. package/dist/git/command.d.ts +51 -0
  80. package/dist/git/command.js +231 -0
  81. package/dist/git/promotion.d.ts +23 -0
  82. package/dist/git/promotion.js +46 -0
  83. package/dist/git/publish-input.d.ts +42 -0
  84. package/dist/git/publish-input.js +62 -0
  85. package/dist/git/publish-job.d.ts +82 -0
  86. package/dist/git/publish-job.js +99 -0
  87. package/dist/git/publish-steps.d.ts +90 -0
  88. package/dist/git/publish-steps.js +205 -0
  89. package/dist/git/publisher.d.ts +23 -0
  90. package/dist/git/publisher.js +206 -0
  91. package/dist/git/refs.d.ts +99 -0
  92. package/dist/git/refs.js +178 -0
  93. package/dist/git/refusal.d.ts +49 -0
  94. package/dist/git/refusal.js +70 -0
  95. package/dist/git/repository.d.ts +101 -0
  96. package/dist/git/repository.js +273 -0
  97. package/dist/git/versions.d.ts +99 -0
  98. package/dist/git/versions.js +174 -0
  99. package/dist/git/write-lock.d.ts +19 -0
  100. package/dist/git/write-lock.js +49 -0
  101. package/dist/index.d.ts +5 -0
  102. package/dist/index.js +59 -0
  103. package/dist/lifecycle.d.ts +8 -0
  104. package/dist/lifecycle.js +78 -0
  105. package/dist/logs/relay.d.ts +25 -0
  106. package/dist/logs/relay.js +138 -0
  107. package/dist/null-prototype.d.ts +7 -0
  108. package/dist/null-prototype.js +3 -0
  109. package/dist/overview/content.d.ts +40 -0
  110. package/dist/overview/content.js +172 -0
  111. package/dist/pages/changes.d.ts +32 -0
  112. package/dist/pages/changes.js +141 -0
  113. package/dist/pages/connection.d.ts +43 -0
  114. package/dist/pages/connection.js +295 -0
  115. package/dist/pages/deployment.d.ts +67 -0
  116. package/dist/pages/deployment.js +261 -0
  117. package/dist/pages/deployments.d.ts +46 -0
  118. package/dist/pages/deployments.js +266 -0
  119. package/dist/pages/environments.d.ts +34 -0
  120. package/dist/pages/environments.js +368 -0
  121. package/dist/pages/logs.d.ts +46 -0
  122. package/dist/pages/logs.js +140 -0
  123. package/dist/pages/navigation.d.ts +61 -0
  124. package/dist/pages/navigation.js +107 -0
  125. package/dist/pages/overview.d.ts +35 -0
  126. package/dist/pages/overview.js +201 -0
  127. package/dist/pages/project-guard.d.ts +32 -0
  128. package/dist/pages/project-guard.js +99 -0
  129. package/dist/pages/query.d.ts +6 -0
  130. package/dist/pages/query.js +14 -0
  131. package/dist/pages/resources.d.ts +37 -0
  132. package/dist/pages/resources.js +211 -0
  133. package/dist/pages/setup.d.ts +40 -0
  134. package/dist/pages/setup.js +271 -0
  135. package/dist/pages/slugs.d.ts +15 -0
  136. package/dist/pages/slugs.js +28 -0
  137. package/dist/pages/variables.d.ts +43 -0
  138. package/dist/pages/variables.js +327 -0
  139. package/dist/pages/version.d.ts +26 -0
  140. package/dist/pages/version.js +214 -0
  141. package/dist/pages/versions.d.ts +20 -0
  142. package/dist/pages/versions.js +115 -0
  143. package/dist/resources/apply.d.ts +15 -0
  144. package/dist/resources/apply.js +127 -0
  145. package/dist/resources/cards.d.ts +41 -0
  146. package/dist/resources/cards.js +211 -0
  147. package/dist/resources/connect.d.ts +66 -0
  148. package/dist/resources/connect.js +78 -0
  149. package/dist/resources/content.d.ts +26 -0
  150. package/dist/resources/content.js +158 -0
  151. package/dist/resources/format.d.ts +10 -0
  152. package/dist/resources/format.js +30 -0
  153. package/dist/resources/guard.d.ts +23 -0
  154. package/dist/resources/guard.js +60 -0
  155. package/dist/resources/modules.d.ts +23 -0
  156. package/dist/resources/modules.js +39 -0
  157. package/dist/resources/plan.d.ts +8 -0
  158. package/dist/resources/plan.js +93 -0
  159. package/dist/resources/read.d.ts +54 -0
  160. package/dist/resources/read.js +69 -0
  161. package/dist/resources/refusals.d.ts +15 -0
  162. package/dist/resources/refusals.js +33 -0
  163. package/dist/resources/routes.d.ts +32 -0
  164. package/dist/resources/routes.js +53 -0
  165. package/dist/setup/actions.d.ts +79 -0
  166. package/dist/setup/actions.js +188 -0
  167. package/dist/setup/apply.d.ts +37 -0
  168. package/dist/setup/apply.js +172 -0
  169. package/dist/setup/content.d.ts +50 -0
  170. package/dist/setup/content.js +440 -0
  171. package/dist/setup/rollout.d.ts +119 -0
  172. package/dist/setup/rollout.js +227 -0
  173. package/dist/setup/steps.d.ts +93 -0
  174. package/dist/setup/steps.js +95 -0
  175. package/dist/setup/storage.d.ts +29 -0
  176. package/dist/setup/storage.js +78 -0
  177. package/dist/setup/store.d.ts +214 -0
  178. package/dist/setup/store.js +174 -0
  179. package/dist/setup/volume.d.ts +31 -0
  180. package/dist/setup/volume.js +52 -0
  181. package/dist/slug.d.ts +7 -0
  182. package/dist/slug.js +26 -0
  183. package/dist/variables/actions.d.ts +76 -0
  184. package/dist/variables/actions.js +185 -0
  185. package/dist/variables/content.d.ts +69 -0
  186. package/dist/variables/content.js +310 -0
  187. package/dist/variables/decide.d.ts +27 -0
  188. package/dist/variables/decide.js +155 -0
  189. package/dist/variables/decided-dialog.d.ts +11 -0
  190. package/dist/variables/decided-dialog.js +129 -0
  191. package/dist/variables/decided.d.ts +80 -0
  192. package/dist/variables/decided.js +240 -0
  193. package/dist/variables/dialogs.d.ts +8 -0
  194. package/dist/variables/dialogs.js +219 -0
  195. package/dist/variables/model.d.ts +106 -0
  196. package/dist/variables/model.js +156 -0
  197. package/dist/variables/project-config.d.ts +117 -0
  198. package/dist/variables/project-config.js +248 -0
  199. package/dist/variables/read.d.ts +33 -0
  200. package/dist/variables/read.js +118 -0
  201. package/dist/web-url.d.ts +9 -0
  202. package/dist/web-url.js +19 -0
  203. package/frontend-vue/app/components/BuildLog.vue +99 -0
  204. package/frontend-vue/app/components/ChangedFiles.vue +165 -0
  205. package/frontend-vue/app/components/DashboardEnvironments.vue +102 -0
  206. package/frontend-vue/app/components/LogLine.vue +33 -0
  207. package/frontend-vue/app/components/LogViewer.vue +314 -0
  208. package/frontend-vue/app/components/PublishChipIcon.vue +39 -0
  209. package/frontend-vue/app/components/PublishForm.vue +505 -0
  210. package/frontend-vue/app/components/PublishPopover.vue +90 -0
  211. package/frontend-vue/app/components/PublishRoute.vue +222 -0
  212. package/frontend-vue/app/composables/usePublishSummary.ts +80 -0
  213. package/frontend-vue/app/plugins/publish-chip.client.ts +44 -0
  214. package/frontend-vue/app/types/publishing.ts +154 -0
  215. package/frontend-vue/app/utils/build-log.ts +96 -0
  216. package/frontend-vue/app/utils/changed-files.ts +142 -0
  217. package/frontend-vue/app/utils/log-line.ts +15 -0
  218. package/frontend-vue/app/utils/log-stream.ts +361 -0
  219. package/frontend-vue/app/utils/publish-state.ts +299 -0
  220. package/frontend-vue/dms.frontend.ts +27 -0
  221. package/frontend-vue/i18n/locales/antelope-cloud-en-GB.json +110 -0
  222. package/frontend-vue/package.json +38 -0
  223. package/frontend-vue/pnpm-lock.yaml +2697 -0
  224. package/package.json +115 -4
@@ -0,0 +1,359 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readDeployments = readDeployments;
4
+ exports.readDeployment = readDeployment;
5
+ exports.rollBack = rollBack;
6
+ exports.readCommitDeployment = readCommitDeployment;
7
+ const cloud_sdk_1 = require("@antelopejs/cloud-sdk");
8
+ const lifecycle_1 = require("./lifecycle");
9
+ const refusals_1 = require("./refusals");
10
+ const PAGE_SIZE = 100;
11
+ const MAX_DEPLOYMENTS = 1_000;
12
+ const SETTLED_LIMIT = 500;
13
+ const HTTP_NOT_FOUND = 404;
14
+ const settled = new Map();
15
+ function remember(key, status) {
16
+ if (!(0, lifecycle_1.isTerminal)(status))
17
+ return;
18
+ settled.set(key, status);
19
+ const oldest = settled.keys().next();
20
+ if (settled.size > SETTLED_LIMIT && !oldest.done)
21
+ settled.delete(oldest.value);
22
+ }
23
+ function historyReader(api) {
24
+ const histories = new Map();
25
+ return (serviceId) => {
26
+ const known = histories.get(serviceId);
27
+ if (known)
28
+ return known;
29
+ const read = api.deploymentHistory(serviceId);
30
+ histories.set(serviceId, read);
31
+ return read;
32
+ };
33
+ }
34
+ async function snapshotOf(environment, history) {
35
+ const services = await Promise.all(environment.services.map(async ({ id, name }) => ({
36
+ id,
37
+ name,
38
+ history: await history(id),
39
+ })));
40
+ return { environment, services };
41
+ }
42
+ function fromRoute(deployment) {
43
+ return {
44
+ id: deployment.id,
45
+ environmentId: deployment.environmentId,
46
+ status: (0, lifecycle_1.parseStatus)(deployment.status),
47
+ number: deployment.number,
48
+ commit: deployment.commit,
49
+ branch: deployment.branch,
50
+ trigger: deployment.trigger,
51
+ createdAt: deployment.createdAt,
52
+ finishedAt: deployment.finishedAt,
53
+ revisionIds: deployment.revisionIds,
54
+ };
55
+ }
56
+ function idsOf({ environment, services }) {
57
+ const ids = [
58
+ environment.target?.id,
59
+ environment.serving?.id,
60
+ ];
61
+ for (const { history } of services) {
62
+ ids.push(...(history.activeBuilds ?? []).map((build) => build.deploymentId));
63
+ ids.push(...history.revisions.map((revision) => revision.deploymentId));
64
+ }
65
+ return [...new Set(ids.filter((id) => typeof id === "string"))];
66
+ }
67
+ function revisionsOf(snapshot, deploymentId) {
68
+ return snapshot.services.flatMap(({ history }) => history.revisions.filter((revision) => revision.deploymentId === deploymentId));
69
+ }
70
+ async function statusOf(api, snapshot, deploymentId) {
71
+ const { serving, target } = snapshot.environment;
72
+ const known = [target, serving].find((one) => one?.id === deploymentId);
73
+ if (known)
74
+ return (0, lifecycle_1.parseStatus)(known.status);
75
+ const build = snapshot.services
76
+ .flatMap(({ history }) => history.activeBuilds ?? [])
77
+ .find((one) => one.deploymentId === deploymentId);
78
+ const building = build ? lifecycle_1.BUILD_PHASES.get(build.status) : undefined;
79
+ if (building)
80
+ return building;
81
+ const memo = settled.get(deploymentId);
82
+ if (memo)
83
+ return memo;
84
+ const status = (0, lifecycle_1.parseStatus)((await api.readDeployment(deploymentId)).status);
85
+ remember(deploymentId, status);
86
+ return status;
87
+ }
88
+ async function composedRecord(api, snapshot, id) {
89
+ const { serving, target } = snapshot.environment;
90
+ const known = [target, serving].find((one) => one?.id === id) ?? null;
91
+ const revisions = revisionsOf(snapshot, id);
92
+ const build = revisions.find((revision) => revision.build)?.build ?? null;
93
+ const builds = snapshot.services.flatMap(({ history }) => history.activeBuilds ?? []);
94
+ const createdAt = [
95
+ known?.createdAt,
96
+ ...builds
97
+ .filter((one) => one.deploymentId === id)
98
+ .map((one) => one.createdAt),
99
+ ...revisions.map((revision) => revision.createdAt),
100
+ ].find((at) => typeof at === "string");
101
+ return {
102
+ id,
103
+ environmentId: snapshot.environment.id,
104
+ status: await statusOf(api, snapshot, id),
105
+ number: known?.number ?? null,
106
+ commit: known ? known.commit : (build?.commit ?? null),
107
+ branch: known ? known.branch : (build?.branch ?? null),
108
+ trigger: null,
109
+ createdAt: createdAt ?? null,
110
+ finishedAt: null,
111
+ revisionIds: revisions.map((revision) => revision.id),
112
+ };
113
+ }
114
+ function newestFirst(a, b) {
115
+ return (b.createdAt ?? "").localeCompare(a.createdAt ?? "");
116
+ }
117
+ async function composedRecords(api, environments, history) {
118
+ const snapshots = await Promise.all(environments.map((environment) => snapshotOf(environment, history)));
119
+ const records = await Promise.all(snapshots.flatMap((snapshot) => idsOf(snapshot).map((id) => composedRecord(api, snapshot, id))));
120
+ return records.sort(newestFirst);
121
+ }
122
+ /**
123
+ * The project's deployments from the Cloud project route, newest first, up
124
+ * to {@link MAX_DEPLOYMENTS}. Only the first page's refusal reaches the
125
+ * caller. A later page that fails cuts the list short; one that adds no new
126
+ * deployment, or a repeated cursor, ends it.
127
+ */
128
+ async function routeRecords(api, projectId) {
129
+ const first = await api.projectDeployments.list(projectId, {
130
+ limit: PAGE_SIZE,
131
+ });
132
+ const records = first.deployments.map(fromRoute);
133
+ const ids = new Set(records.map(({ id }) => id));
134
+ const cursors = new Set();
135
+ let cursor = first.nextCursor;
136
+ while (cursor !== null &&
137
+ !cursors.has(cursor) &&
138
+ records.length < MAX_DEPLOYMENTS) {
139
+ cursors.add(cursor);
140
+ const limit = Math.min(PAGE_SIZE, MAX_DEPLOYMENTS - records.length);
141
+ const page = await api.projectDeployments
142
+ .list(projectId, { cursor, limit })
143
+ .catch(() => null);
144
+ if (!page)
145
+ return { records, cutShort: true };
146
+ const fresh = page.deployments.filter(({ id }) => !ids.has(id));
147
+ if (fresh.length === 0)
148
+ break;
149
+ for (const deployment of fresh)
150
+ ids.add(deployment.id);
151
+ records.push(...fresh.map(fromRoute));
152
+ cursor = page.nextCursor;
153
+ }
154
+ return { records, cutShort: false };
155
+ }
156
+ async function readRecords(api, projectId, environments, history) {
157
+ try {
158
+ return await routeRecords(api, projectId);
159
+ }
160
+ catch (error) {
161
+ if (!(error instanceof cloud_sdk_1.CloudApiError) || error.status !== HTTP_NOT_FOUND) {
162
+ throw error;
163
+ }
164
+ }
165
+ return {
166
+ records: await composedRecords(api, environments, history),
167
+ cutShort: false,
168
+ };
169
+ }
170
+ function dateOf(at) {
171
+ return at === null ? null : new Date(at);
172
+ }
173
+ function toDeployment(record, environment, status = record.status) {
174
+ return {
175
+ id: record.id,
176
+ environment: { id: environment.id, name: environment.name },
177
+ phase: (0, lifecycle_1.phaseOf)(status, environment.serving?.id === record.id),
178
+ number: record.number,
179
+ commit: record.commit,
180
+ branch: record.branch,
181
+ trigger: record.trigger,
182
+ startedAt: dateOf(record.createdAt),
183
+ finishedAt: dateOf(record.finishedAt),
184
+ };
185
+ }
186
+ function withEnvironments(records, environments) {
187
+ const byId = new Map(environments.map((one) => [one.id, one]));
188
+ return records.flatMap((record) => {
189
+ const environment = byId.get(record.environmentId);
190
+ return environment ? [toDeployment(record, environment)] : [];
191
+ });
192
+ }
193
+ /**
194
+ * Every deployment of the project, newest first. The seam for the Cloud
195
+ * project route: it reads that route, and composes the list from the
196
+ * environments and their services' histories only while it answers 404.
197
+ */
198
+ async function readDeployments(api, projectId) {
199
+ const environments = await api.environments.list(projectId);
200
+ const { records } = await readRecords(api, projectId, environments, historyReader(api));
201
+ return withEnvironments(records, environments);
202
+ }
203
+ function revisionOfDeployment(history, record) {
204
+ const revisionIds = new Set(record.revisionIds);
205
+ return history.revisions.find((one) => one.deploymentId === record.id || revisionIds.has(one.id));
206
+ }
207
+ function isShippedByDeployments(history, record) {
208
+ return (revisionOfDeployment(history, record) !== undefined ||
209
+ history.revisions.some(({ deploymentId }) => Boolean(deploymentId)));
210
+ }
211
+ function planRollback(snapshot, record) {
212
+ const { environment, services } = snapshot;
213
+ if (environment.serving?.id === record.id) {
214
+ return { kind: "refused", reason: "rollback_serving" };
215
+ }
216
+ const target = environment.target;
217
+ if (target && !(0, lifecycle_1.isTerminal)((0, lifecycle_1.parseStatus)(target.status))) {
218
+ return { kind: "refused", reason: "rollback_in_progress" };
219
+ }
220
+ const moves = [];
221
+ const shipped = services.filter(({ history }) => isShippedByDeployments(history, record));
222
+ for (const { id, name, history } of shipped) {
223
+ const revision = revisionOfDeployment(history, record);
224
+ const isBack = revision?.id === history.desiredRevisionId;
225
+ if (!revision || (!isBack && !revision.canRollback)) {
226
+ return { kind: "refused", reason: "rollback_missing_revision" };
227
+ }
228
+ if (!isBack) {
229
+ moves.push({ serviceId: id, serviceName: name, revisionId: revision.id });
230
+ }
231
+ }
232
+ if (moves.length === 0)
233
+ return { kind: "refused", reason: "rollback_serving" };
234
+ return { kind: "ready", environmentName: environment.name, moves };
235
+ }
236
+ function shippedRevisions(snapshot, record) {
237
+ return snapshot.services.flatMap(({ id, name, history }) => {
238
+ const revision = revisionOfDeployment(history, record);
239
+ return revision
240
+ ? [{ serviceId: id, serviceName: name, revisionNumber: revision.number }]
241
+ : [];
242
+ });
243
+ }
244
+ function queuePositionOf(snapshot, deploymentId) {
245
+ const positions = snapshot.services
246
+ .flatMap(({ history }) => history.activeBuilds ?? [])
247
+ .filter((build) => build.deploymentId === deploymentId)
248
+ .map((build) => build.queuePosition)
249
+ .filter((position) => position !== null);
250
+ return positions.length > 0 ? Math.min(...positions) : null;
251
+ }
252
+ function failureOf(phase, detail) {
253
+ if (phase !== "failed" && phase !== "cancelled")
254
+ return null;
255
+ const builds = detail.builds ?? [];
256
+ const failedBuild = builds.find((build) => build.failureReason);
257
+ const reason = failedBuild?.failureReason ?? (0, refusals_1.deploymentRefusal)(detail.failure?.key);
258
+ return {
259
+ step: (0, lifecycle_1.reachedStep)(builds),
260
+ summary: reason?.summary ?? null,
261
+ platform: reason?.platform ?? false,
262
+ buildId: failedBuild?.id ?? null,
263
+ };
264
+ }
265
+ async function snapshotHolding(api, projectId, deploymentId) {
266
+ const environments = await api.environments.list(projectId);
267
+ const history = historyReader(api);
268
+ const { records, cutShort } = await readRecords(api, projectId, environments, history);
269
+ const record = records.find((one) => one.id === deploymentId);
270
+ if (!record && cutShort) {
271
+ throw new Error("The Cloud failed a page of the project's deployments");
272
+ }
273
+ const environment = environments.find((one) => one.id === record?.environmentId);
274
+ if (!record || !environment)
275
+ return null;
276
+ return { record, snapshot: await snapshotOf(environment, history) };
277
+ }
278
+ /** One deployment of the project, or null when no environment of the project ran it. */
279
+ async function readDeployment(api, projectId, deploymentId) {
280
+ const held = await snapshotHolding(api, projectId, deploymentId);
281
+ if (!held)
282
+ return null;
283
+ const { record, snapshot } = held;
284
+ const detail = await api.readDeployment(deploymentId);
285
+ const deployment = toDeployment(record, snapshot.environment, (0, lifecycle_1.parseStatus)(detail.status));
286
+ const serving = snapshot.environment.serving;
287
+ return {
288
+ ...deployment,
289
+ revisions: shippedRevisions(snapshot, record),
290
+ reached: (0, lifecycle_1.reachedStep)(detail.builds ?? []),
291
+ queuePosition: queuePositionOf(snapshot, deploymentId),
292
+ failure: failureOf(deployment.phase, detail),
293
+ serving: serving ? { id: serving.id, number: serving.number } : null,
294
+ rollback: planRollback(snapshot, record),
295
+ };
296
+ }
297
+ /**
298
+ * Rolls the environment holding `deploymentId` back to it: reads the
299
+ * histories again, plans, then calls `api.rollback` service by service. A
300
+ * refusal comes before any write. A failure after the first move answers
301
+ * `partial`, and running it again moves only what is left.
302
+ */
303
+ async function rollBack(api, projectId, deploymentId) {
304
+ const held = await snapshotHolding(api, projectId, deploymentId);
305
+ if (!held)
306
+ return { kind: "refused", reason: "rollback_not_found" };
307
+ const plan = planRollback(held.snapshot, held.record);
308
+ if (plan.kind === "refused")
309
+ return plan;
310
+ const moved = [];
311
+ for (const move of plan.moves) {
312
+ try {
313
+ await api.rollback(move.serviceId, move.revisionId);
314
+ }
315
+ catch (error) {
316
+ if (moved.length === 0)
317
+ throw error;
318
+ const left = plan.moves.slice(moved.length).map((one) => one.serviceName);
319
+ return { kind: "partial", moved, left };
320
+ }
321
+ moved.push(move.serviceName);
322
+ }
323
+ return { kind: "done", environmentName: plan.environmentName };
324
+ }
325
+ async function deploymentOfCommit(api, projectId, environment, commit) {
326
+ const found = [environment.target, environment.serving].find((one) => one?.commit === commit);
327
+ if (found) {
328
+ const isServing = environment.serving?.id === found.id;
329
+ return {
330
+ id: found.id,
331
+ phase: (0, lifecycle_1.phaseOf)((0, lifecycle_1.parseStatus)(found.status), isServing),
332
+ };
333
+ }
334
+ const deployments = await readDeployments(api, projectId);
335
+ const newest = deployments.find((one) => one.environment.id === environment.id && one.commit === commit);
336
+ return newest ? { id: newest.id, phase: newest.phase } : null;
337
+ }
338
+ /**
339
+ * The deployment of `commit` on an environment: its target or serving one,
340
+ * else the newest the project ran of it, a replaced or cancelled one
341
+ * included. Null while the Cloud has run none.
342
+ */
343
+ async function readCommitDeployment(api, projectId, environment, commit) {
344
+ const found = await deploymentOfCommit(api, projectId, environment, commit);
345
+ if (!found)
346
+ return null;
347
+ const { id, phase } = found;
348
+ if (lifecycle_1.LIFECYCLE[phase].step !== "reached") {
349
+ return { id, phase, reached: "queued", failure: null };
350
+ }
351
+ const detail = await api.readDeployment(id);
352
+ return {
353
+ id,
354
+ phase,
355
+ reached: (0, lifecycle_1.reachedStep)(detail.builds ?? []),
356
+ failure: failureOf(phase, detail),
357
+ };
358
+ }
359
+ //# sourceMappingURL=ledger.js.map
@@ -0,0 +1,123 @@
1
+ declare const CLOUD_STATUSES: readonly ["queued", "building", "checking", "switching", "succeeded", "failed", "cancelled"];
2
+ /** A deployment status as the Cloud API reports it. */
3
+ export type CloudStatus = (typeof CLOUD_STATUSES)[number];
4
+ /**
5
+ * Where a deployment stands for this module: a Cloud status, `superseded`
6
+ * (it went live, and its environment serves another deployment now), or
7
+ * `unknown` (a status string this module does not know yet).
8
+ */
9
+ export type Phase = CloudStatus | "superseded" | "unknown";
10
+ /** The route of a deployment, in order. No API reports resource provisioning. */
11
+ export declare const STEPS: readonly ["queued", "build", "check", "switch", "live"];
12
+ /** A step of a deployment's route. */
13
+ export type StepId = (typeof STEPS)[number];
14
+ /** The tones a status takes in the DMS blocks. */
15
+ export type Tone = "neutral" | "info" | "success" | "warning" | "error";
16
+ /** The list tab a phase falls under: In progress, Failed, or neither. */
17
+ export type Stage = "active" | "failed" | "settled";
18
+ /** Every phase's label, tone, end, tab and step: the one status table. */
19
+ export declare const LIFECYCLE: {
20
+ readonly queued: {
21
+ readonly label: "Queued";
22
+ readonly tone: "neutral";
23
+ readonly terminal: false;
24
+ readonly stage: "active";
25
+ readonly step: "queued";
26
+ };
27
+ readonly building: {
28
+ readonly label: "Building";
29
+ readonly tone: "info";
30
+ readonly terminal: false;
31
+ readonly stage: "active";
32
+ readonly step: "build";
33
+ };
34
+ readonly checking: {
35
+ readonly label: "Health check";
36
+ readonly tone: "info";
37
+ readonly terminal: false;
38
+ readonly stage: "active";
39
+ readonly step: "check";
40
+ };
41
+ readonly switching: {
42
+ readonly label: "Switching traffic";
43
+ readonly tone: "info";
44
+ readonly terminal: false;
45
+ readonly stage: "active";
46
+ readonly step: "switch";
47
+ };
48
+ readonly succeeded: {
49
+ readonly label: "Live";
50
+ readonly tone: "success";
51
+ readonly terminal: true;
52
+ readonly stage: "settled";
53
+ readonly step: "live";
54
+ };
55
+ readonly superseded: {
56
+ readonly label: "Superseded";
57
+ readonly tone: "neutral";
58
+ readonly terminal: true;
59
+ readonly stage: "settled";
60
+ readonly step: "live";
61
+ };
62
+ readonly failed: {
63
+ readonly label: "Failed";
64
+ readonly tone: "error";
65
+ readonly terminal: true;
66
+ readonly stage: "failed";
67
+ readonly step: "reached";
68
+ };
69
+ readonly cancelled: {
70
+ readonly label: "Cancelled";
71
+ readonly tone: "warning";
72
+ readonly terminal: true;
73
+ readonly stage: "failed";
74
+ readonly step: "reached";
75
+ };
76
+ readonly unknown: {
77
+ readonly label: "Unknown";
78
+ readonly tone: "neutral";
79
+ readonly terminal: false;
80
+ readonly stage: "active";
81
+ readonly step: "reached";
82
+ };
83
+ };
84
+ /** An active build's status, read while its deployment has no status of its own yet. */
85
+ export declare const BUILD_PHASES: Map<string, "cancelled" | "failed" | "queued" | "building" | "checking" | "switching" | "succeeded">;
86
+ /** How one step of the route reads on the detail page. */
87
+ export type StepState = "done" | "current" | "todo" | "failed" | "skipped";
88
+ /** One step of the detail page's route. */
89
+ export interface StepView {
90
+ readonly id: StepId;
91
+ readonly state: StepState;
92
+ }
93
+ /** What {@link stepsOf} needs to place a deployment on its route. */
94
+ export interface Progress {
95
+ readonly phase: Phase;
96
+ /** The step it got to, read from its builds when the phase does not say. */
97
+ readonly reached: StepId;
98
+ }
99
+ /** A build of a deployment, as far as {@link reachedStep} reads it. */
100
+ export interface BuildState {
101
+ readonly status: string;
102
+ }
103
+ /** Reads a status string of the Cloud API. Unknown strings stay visible as `unknown`. */
104
+ export declare function parseStatus(raw: string): CloudStatus | "unknown";
105
+ /** A status, made `superseded` when it went live and its environment serves another deployment. */
106
+ export declare function phaseOf(status: CloudStatus | "unknown", isServing: boolean): Phase;
107
+ /**
108
+ * The step a deployment got to, from its builds: no build yet is `queued`, a
109
+ * build that did not succeed is `build`, succeeded builds are `check`. A
110
+ * failure after the build is the health check: the switch is only tried
111
+ * after a passing one.
112
+ */
113
+ export declare function reachedStep(builds: readonly BuildState[]): StepId;
114
+ /**
115
+ * The five steps of a deployment. Steps before the one it stands on are
116
+ * done. The one it stands on is current while it runs, done once live,
117
+ * failed when it failed and skipped when it was cancelled. The steps after
118
+ * it wait while it runs and are skipped once it ended.
119
+ */
120
+ export declare function stepsOf(progress: Progress): readonly StepView[];
121
+ /** Whether nothing changes after this status: the deployment ended. */
122
+ export declare function isTerminal(status: CloudStatus | "unknown"): boolean;
123
+ export {};
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BUILD_PHASES = exports.LIFECYCLE = exports.STEPS = void 0;
4
+ exports.parseStatus = parseStatus;
5
+ exports.phaseOf = phaseOf;
6
+ exports.reachedStep = reachedStep;
7
+ exports.stepsOf = stepsOf;
8
+ exports.isTerminal = isTerminal;
9
+ const CLOUD_STATUSES = [
10
+ "queued",
11
+ "building",
12
+ "checking",
13
+ "switching",
14
+ "succeeded",
15
+ "failed",
16
+ "cancelled",
17
+ ];
18
+ /** The route of a deployment, in order. No API reports resource provisioning. */
19
+ exports.STEPS = ["queued", "build", "check", "switch", "live"];
20
+ /** Every phase's label, tone, end, tab and step: the one status table. */
21
+ exports.LIFECYCLE = {
22
+ queued: {
23
+ label: "Queued",
24
+ tone: "neutral",
25
+ terminal: false,
26
+ stage: "active",
27
+ step: "queued",
28
+ },
29
+ building: {
30
+ label: "Building",
31
+ tone: "info",
32
+ terminal: false,
33
+ stage: "active",
34
+ step: "build",
35
+ },
36
+ checking: {
37
+ label: "Health check",
38
+ tone: "info",
39
+ terminal: false,
40
+ stage: "active",
41
+ step: "check",
42
+ },
43
+ switching: {
44
+ label: "Switching traffic",
45
+ tone: "info",
46
+ terminal: false,
47
+ stage: "active",
48
+ step: "switch",
49
+ },
50
+ succeeded: {
51
+ label: "Live",
52
+ tone: "success",
53
+ terminal: true,
54
+ stage: "settled",
55
+ step: "live",
56
+ },
57
+ superseded: {
58
+ label: "Superseded",
59
+ tone: "neutral",
60
+ terminal: true,
61
+ stage: "settled",
62
+ step: "live",
63
+ },
64
+ failed: {
65
+ label: "Failed",
66
+ tone: "error",
67
+ terminal: true,
68
+ stage: "failed",
69
+ step: "reached",
70
+ },
71
+ cancelled: {
72
+ label: "Cancelled",
73
+ tone: "warning",
74
+ terminal: true,
75
+ stage: "failed",
76
+ step: "reached",
77
+ },
78
+ unknown: {
79
+ label: "Unknown",
80
+ tone: "neutral",
81
+ terminal: false,
82
+ stage: "active",
83
+ step: "reached",
84
+ },
85
+ };
86
+ /** An active build's status, read while its deployment has no status of its own yet. */
87
+ exports.BUILD_PHASES = new Map([
88
+ ["queued", "queued"],
89
+ ["starting", "building"],
90
+ ["running", "building"],
91
+ ]);
92
+ const KNOWN_STATUSES = new Set(CLOUD_STATUSES);
93
+ function isCloudStatus(raw) {
94
+ return KNOWN_STATUSES.has(raw);
95
+ }
96
+ /** Reads a status string of the Cloud API. Unknown strings stay visible as `unknown`. */
97
+ function parseStatus(raw) {
98
+ return isCloudStatus(raw) ? raw : "unknown";
99
+ }
100
+ /** A status, made `superseded` when it went live and its environment serves another deployment. */
101
+ function phaseOf(status, isServing) {
102
+ return status === "succeeded" && !isServing ? "superseded" : status;
103
+ }
104
+ /**
105
+ * The step a deployment got to, from its builds: no build yet is `queued`, a
106
+ * build that did not succeed is `build`, succeeded builds are `check`. A
107
+ * failure after the build is the health check: the switch is only tried
108
+ * after a passing one.
109
+ */
110
+ function reachedStep(builds) {
111
+ if (builds.length === 0)
112
+ return "queued";
113
+ return builds.every(({ status }) => status === "succeeded")
114
+ ? "check"
115
+ : "build";
116
+ }
117
+ function standingState(phase) {
118
+ if (!exports.LIFECYCLE[phase].terminal)
119
+ return "current";
120
+ if (phase === "failed")
121
+ return "failed";
122
+ return phase === "cancelled" ? "skipped" : "done";
123
+ }
124
+ /**
125
+ * The five steps of a deployment. Steps before the one it stands on are
126
+ * done. The one it stands on is current while it runs, done once live,
127
+ * failed when it failed and skipped when it was cancelled. The steps after
128
+ * it wait while it runs and are skipped once it ended.
129
+ */
130
+ function stepsOf(progress) {
131
+ const row = exports.LIFECYCLE[progress.phase];
132
+ const at = exports.STEPS.indexOf(row.step === "reached" ? progress.reached : row.step);
133
+ const later = row.terminal ? "skipped" : "todo";
134
+ return exports.STEPS.map((id, index) => {
135
+ if (index < at)
136
+ return { id, state: "done" };
137
+ if (index > at)
138
+ return { id, state: later };
139
+ return { id, state: standingState(progress.phase) };
140
+ });
141
+ }
142
+ /** Whether nothing changes after this status: the deployment ended. */
143
+ function isTerminal(status) {
144
+ return exports.LIFECYCLE[status].terminal;
145
+ }
146
+ //# sourceMappingURL=lifecycle.js.map
@@ -0,0 +1,28 @@
1
+ import type { EnvironmentDetail } from "@antelopejs/cloud-sdk";
2
+ import { type CloudGap, type ReleaseLookup } from "./cloud-steps";
3
+ /** How an environment stands on the Cloud, as the dashboard widget shows it. */
4
+ type LiveState = "live" | "building" | "sleeping" | "failed" | "waiting" | "unknown";
5
+ /** One environment of the project and what it serves. */
6
+ interface EnvironmentLive {
7
+ readonly id: string;
8
+ readonly name: string;
9
+ readonly label: string;
10
+ /** `v15`, `#4` when no git version is its commit, `null` when it serves nothing. */
11
+ readonly version: string | null;
12
+ readonly state: LiveState;
13
+ readonly url: string | null;
14
+ readonly logsUrl: string;
15
+ }
16
+ /** What the dashboard widget's route answers. */
17
+ export type EnvironmentsLive = {
18
+ readonly state: "unavailable";
19
+ readonly message: string;
20
+ } | {
21
+ readonly state: "ok";
22
+ readonly environments: readonly EnvironmentLive[];
23
+ };
24
+ /** Why the widget has no environment to show. */
25
+ export declare function environmentsUnavailable(reason: CloudGap): EnvironmentsLive;
26
+ /** Each environment of the project, with the version it serves and its state. */
27
+ export declare function environmentsLive(environments: readonly EnvironmentDetail[], releaseOf: ReleaseLookup, logsUrl: (environmentId: string) => string): EnvironmentsLive;
28
+ export {};