@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,97 @@
1
+ import type { EnvironmentDeployment, EnvironmentDetail } from "@antelopejs/cloud-sdk";
2
+ import type { BannerContent } from "@antelopejs/interface-dms/base/banner";
3
+ import type { GuardFallback } from "@antelopejs/interface-dms/base/guard";
4
+ import type { CellSubline } from "@antelopejs/interface-dms/base/table-view";
5
+ import type { ComposedText } from "@antelopejs/interface-dms/base/types/composed-text";
6
+ import type { ConfirmDialogSerialized } from "@antelopejs/interface-dms/base/types/confirm-dialog";
7
+ import type { Tone } from "@antelopejs/interface-dms/base/types/tone";
8
+ import type { CloudRead } from "../connection/cloud";
9
+ import type { ConnectionView } from "../connection/view";
10
+ import type { Dashboards } from "../dashboard/actions";
11
+ /** The routes of the Environments page, relative to it. */
12
+ export declare const ENVIRONMENTS_ROUTES: {
13
+ readonly state: "/state";
14
+ readonly banner: "/banner";
15
+ readonly rows: "/rows";
16
+ readonly promoteDialog: "/promote-dialog";
17
+ readonly newDialog: "/new-dialog";
18
+ readonly promote: "/promote";
19
+ readonly create: "/create";
20
+ readonly delete: "/delete";
21
+ readonly addressDialog: "/address-dialog";
22
+ readonly address: "/address";
23
+ readonly dashboardDialog: "/dashboard-dialog";
24
+ readonly dashboard: "/dashboard";
25
+ };
26
+ /** A route of the Environments page. */
27
+ export type EnvironmentsRoute = (typeof ENVIRONMENTS_ROUTES)[keyof typeof ENVIRONMENTS_ROUTES];
28
+ /** The URL of an Environments page route, as a block or a button names it. */
29
+ export declare function environmentsRoute(route: EnvironmentsRoute): string;
30
+ /** The environments of a project as a page reads them, `undefined` without a project. */
31
+ export type EnvironmentsRead = CloudRead<EnvironmentDetail[]> | undefined;
32
+ /** What a page's `Guard` reads: whether the workspace has a project to show. */
33
+ export interface ReadyAnswer {
34
+ ready: boolean;
35
+ /** Laid over the guard's fallback: why there is nothing to show. */
36
+ emptyState?: GuardFallback;
37
+ }
38
+ /** Whether a page about the project has one to show, and why not. */
39
+ export declare function projectReadiness(view: ConnectionView): ReadyAnswer;
40
+ /** Why the environments cannot be read, `null` when they can. */
41
+ export declare function environmentsBanner(environments: EnvironmentsRead): BannerContent | null;
42
+ /** How pages name an environment's state, and the tone they draw it in. */
43
+ export declare function environmentState(environment: EnvironmentDetail): {
44
+ label: string;
45
+ tone: Tone;
46
+ };
47
+ /** An environment as a row of the Environments page's table. */
48
+ export interface EnvironmentRow {
49
+ _id: string;
50
+ /** Its stage's place in the pipeline ("01"), empty outside it. */
51
+ order: string;
52
+ /** Its name as AntelopeJS Cloud stores it, which the delete dialog asks to type. */
53
+ name: string;
54
+ label: string;
55
+ branch: string;
56
+ /** Where its app answers; `null` when the internet does not reach it. */
57
+ address: string | null;
58
+ /** Where its dashboard answers; `null` when it runs none, or one without an address. */
59
+ dashboard: string | null;
60
+ /** Whether the project has a dashboard to build and the environment runs none. */
61
+ canAddDashboard: boolean;
62
+ /** The deployment it serves, as "#12 · 3f9c2e1"; `null` before the first one. */
63
+ serving: string | null;
64
+ servingSince: ComposedText | null;
65
+ state: string;
66
+ stateTone: Tone;
67
+ /** The deployment that failed while it kept serving another one. */
68
+ stateDetail: CellSubline | null;
69
+ /** The environment a promotion of it goes to. */
70
+ promotesTo: string | null;
71
+ isProtected: boolean;
72
+ }
73
+ /** What the table's route answers: every row, on one page. */
74
+ export interface EnvironmentList {
75
+ results: EnvironmentRow[];
76
+ total: number;
77
+ }
78
+ /** A stage's place in the pipeline as pages show it: "01" for the first. */
79
+ export declare function stageOrder(index: number): string;
80
+ /** A deployment as pages name it: its number, and its commit when it has one. */
81
+ export declare function deploymentName(deployment: EnvironmentDeployment): string;
82
+ /** When a deployment went live, written in the reader's language. */
83
+ export declare function deployedSince(deployment: EnvironmentDeployment): ComposedText;
84
+ /** The line under a state: the deployment that failed, and what keeps the traffic. */
85
+ export declare function failureLine(environment: EnvironmentDetail): CellSubline | null;
86
+ /**
87
+ * The rows of the Environments page: the pipeline's stages in order, then
88
+ * the other durable environments.
89
+ *
90
+ * @param dashboards Where the app and the dashboard of each environment
91
+ * answer; left out, each row shows the address AntelopeJS Cloud lists
92
+ */
93
+ export declare function environmentRows(environments: readonly EnvironmentDetail[], dashboards?: Dashboards): EnvironmentRow[];
94
+ /** The dialog the Promote button of an environment opens. */
95
+ export declare function promoteDialog(environments: EnvironmentsRead, environmentId: string): ConfirmDialogSerialized;
96
+ /** The dialog the New environment button opens: its name, branch and services. */
97
+ export declare function newEnvironmentDialog(environments: EnvironmentsRead): ConfirmDialogSerialized;
@@ -0,0 +1,275 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ENVIRONMENTS_ROUTES = void 0;
4
+ exports.environmentsRoute = environmentsRoute;
5
+ exports.projectReadiness = projectReadiness;
6
+ exports.environmentsBanner = environmentsBanner;
7
+ exports.environmentState = environmentState;
8
+ exports.stageOrder = stageOrder;
9
+ exports.deploymentName = deploymentName;
10
+ exports.deployedSince = deployedSince;
11
+ exports.failureLine = failureLine;
12
+ exports.environmentRows = environmentRows;
13
+ exports.promoteDialog = promoteDialog;
14
+ exports.newEnvironmentDialog = newEnvironmentDialog;
15
+ const confirm_dialog_1 = require("@antelopejs/interface-dms/base/confirm-dialog");
16
+ const default_types_1 = require("@antelopejs/interface-dms/base/data-types/default-types");
17
+ const page_1 = require("@antelopejs/interface-dms/page");
18
+ const slugs_1 = require("../pages/slugs");
19
+ const pipeline_1 = require("./pipeline");
20
+ /** The routes of the Environments page, relative to it. */
21
+ exports.ENVIRONMENTS_ROUTES = {
22
+ state: "/state",
23
+ banner: "/banner",
24
+ rows: "/rows",
25
+ promoteDialog: "/promote-dialog",
26
+ newDialog: "/new-dialog",
27
+ promote: "/promote",
28
+ create: "/create",
29
+ delete: "/delete",
30
+ addressDialog: "/address-dialog",
31
+ address: "/address",
32
+ dashboardDialog: "/dashboard-dialog",
33
+ dashboard: "/dashboard",
34
+ };
35
+ /** The URL of an Environments page route, as a block or a button names it. */
36
+ function environmentsRoute(route) {
37
+ return (0, page_1.pageRoutePath)((0, slugs_1.modulePageSlug)("environments"), route);
38
+ }
39
+ /** Whether a page about the project has one to show, and why not. */
40
+ function projectReadiness(view) {
41
+ if (view.state !== "connected")
42
+ return { ready: false };
43
+ if (view.projectId !== null)
44
+ return { ready: true };
45
+ return {
46
+ ready: false,
47
+ emptyState: {
48
+ title: "No project chosen",
49
+ description: "Choose the AntelopeJS Cloud project this DMS publishes, or create one.",
50
+ },
51
+ };
52
+ }
53
+ const UNAVAILABLE = {
54
+ revoked: {
55
+ title: "Your AntelopeJS Cloud sign-in was revoked",
56
+ description: "Sign in again on the Connection page.",
57
+ },
58
+ missing: {
59
+ title: "AntelopeJS Cloud has no such project any more",
60
+ description: "Choose the project this DMS publishes again.",
61
+ },
62
+ forbidden: {
63
+ title: "AntelopeJS Cloud does not allow this token here",
64
+ description: "Its access does not cover the environments of this project.",
65
+ },
66
+ unreachable: {
67
+ title: "AntelopeJS Cloud did not answer",
68
+ description: "Try again in a moment.",
69
+ },
70
+ };
71
+ /** Why the environments cannot be read, `null` when they can. */
72
+ function environmentsBanner(environments) {
73
+ if (environments === undefined || environments.kind === "ok")
74
+ return null;
75
+ return {
76
+ tone: "warning",
77
+ ...UNAVAILABLE[environments.kind],
78
+ actions: [{ label: "Open Connection", to: (0, slugs_1.modulePageSlug)("connection") }],
79
+ };
80
+ }
81
+ const STATES = {
82
+ live: { label: "Live", tone: "success" },
83
+ build: { label: "Building", tone: "info" },
84
+ waiting: { label: "Waiting", tone: "neutral" },
85
+ sleep: { label: "Sleeping", tone: "neutral" },
86
+ failed: { label: "Failed", tone: "error" },
87
+ unknown: { label: "Unknown", tone: "warning" },
88
+ };
89
+ /** How pages name an environment's state, and the tone they draw it in. */
90
+ function environmentState(environment) {
91
+ return STATES[environment.state];
92
+ }
93
+ const ORDER_DIGITS = 2;
94
+ /** A stage's place in the pipeline as pages show it: "01" for the first. */
95
+ function stageOrder(index) {
96
+ return String(index + 1).padStart(ORDER_DIGITS, "0");
97
+ }
98
+ /** A deployment as pages name it: its number, and its commit when it has one. */
99
+ function deploymentName(deployment) {
100
+ return deployment.commit
101
+ ? `#${deployment.number} · ${(0, pipeline_1.shortCommit)(deployment.commit)}`
102
+ : `#${deployment.number}`;
103
+ }
104
+ /** When a deployment went live, written in the reader's language. */
105
+ function deployedSince(deployment) {
106
+ return {
107
+ key: "dms_antelope_cloud.environments.deployed",
108
+ params: { when: { type: "relative", value: deployment.createdAt } },
109
+ };
110
+ }
111
+ /** The line under a state: the deployment that failed, and what keeps the traffic. */
112
+ function failureLine(environment) {
113
+ const failed = (0, pipeline_1.failedTarget)(environment);
114
+ if (!failed)
115
+ return null;
116
+ const kept = environment.serving
117
+ ? ` · #${environment.serving.number} keeps the traffic`
118
+ : "";
119
+ return { text: `#${failed.number} failed${kept}`, tone: "error" };
120
+ }
121
+ /** The dashboards of a project nobody read: no address beyond what AntelopeJS Cloud lists, none to add. */
122
+ const NO_DASHBOARDS = {
123
+ addresses: new Map(),
124
+ hasDockerfile: false,
125
+ };
126
+ /**
127
+ * Where an environment answers, as its row shows it. AntelopeJS Cloud lists
128
+ * one address for an environment, its first open service's. Without a
129
+ * dashboard that is an app's, and the row shows it. With one, the row shows
130
+ * the app's own address, none when only the dashboard is open, and the
131
+ * dashboard's in its column. An environment whose services were not read
132
+ * shows the address AntelopeJS Cloud lists.
133
+ */
134
+ function rowAddresses(environment, { addresses, hasDockerfile }) {
135
+ const known = addresses.get(environment.id);
136
+ if (!known) {
137
+ return {
138
+ address: environment.url,
139
+ dashboard: null,
140
+ canAddDashboard: false,
141
+ };
142
+ }
143
+ return {
144
+ address: known.hasDashboard && known.hasOneApp ? known.app : environment.url,
145
+ dashboard: known.dashboard,
146
+ canAddDashboard: hasDockerfile && !known.hasDashboard,
147
+ };
148
+ }
149
+ function row(environment, order, { environments, dashboards }) {
150
+ const { id, name, branch, serving, isProtected } = environment;
151
+ const next = (0, pipeline_1.promotionTarget)(environments, id);
152
+ const state = environmentState(environment);
153
+ return {
154
+ _id: id,
155
+ order,
156
+ name,
157
+ label: (0, pipeline_1.environmentLabel)(name),
158
+ branch: branch ?? "No branch",
159
+ ...rowAddresses(environment, dashboards),
160
+ serving: serving ? deploymentName(serving) : null,
161
+ servingSince: serving ? deployedSince(serving) : null,
162
+ state: state.label,
163
+ stateTone: state.tone,
164
+ stateDetail: failureLine(environment),
165
+ promotesTo: next ? (0, pipeline_1.environmentLabel)(next.name) : null,
166
+ isProtected,
167
+ };
168
+ }
169
+ /**
170
+ * The rows of the Environments page: the pipeline's stages in order, then
171
+ * the other durable environments.
172
+ *
173
+ * @param dashboards Where the app and the dashboard of each environment
174
+ * answer; left out, each row shows the address AntelopeJS Cloud lists
175
+ */
176
+ function environmentRows(environments, dashboards = NO_DASHBOARDS) {
177
+ const { stages, others } = (0, pipeline_1.pipelineOf)(environments);
178
+ const listed = { environments, dashboards };
179
+ return [
180
+ ...stages.map((environment, index) => row(environment, stageOrder(index), listed)),
181
+ ...others.map((environment) => row(environment, "", listed)),
182
+ ];
183
+ }
184
+ function unavailableDialog(environments) {
185
+ return (0, confirm_dialog_1.serializeConfirmDialog)({
186
+ ...(environments === undefined
187
+ ? {
188
+ title: "No AntelopeJS Cloud project",
189
+ description: "Choose the project this DMS publishes first.",
190
+ }
191
+ : UNAVAILABLE[environments.kind]),
192
+ blocked: true,
193
+ });
194
+ }
195
+ function promotionDialog(environments, environmentId) {
196
+ const from = environments.find(({ id }) => id === environmentId);
197
+ if (!from) {
198
+ return (0, confirm_dialog_1.serializeConfirmDialog)({
199
+ title: "AntelopeJS Cloud has no such environment",
200
+ description: "It may have been deleted meanwhile.",
201
+ blocked: true,
202
+ });
203
+ }
204
+ const fromLabel = (0, pipeline_1.environmentLabel)(from.name);
205
+ const to = (0, pipeline_1.promotionTarget)(environments, from.id);
206
+ if (!to) {
207
+ return (0, confirm_dialog_1.serializeConfirmDialog)({
208
+ title: `${fromLabel} is the last stage`,
209
+ description: "Nothing comes after it in the pipeline.",
210
+ blocked: true,
211
+ });
212
+ }
213
+ const toLabel = (0, pipeline_1.environmentLabel)(to.name);
214
+ if (!from.serving?.commit) {
215
+ return (0, confirm_dialog_1.serializeConfirmDialog)({
216
+ title: "Nothing to promote",
217
+ description: `${fromLabel} serves no version built from a commit yet.`,
218
+ blocked: true,
219
+ });
220
+ }
221
+ const version = deploymentName(from.serving);
222
+ return (0, confirm_dialog_1.serializeConfirmDialog)({
223
+ title: `Promote #${from.serving.number} to ${toLabel}?`,
224
+ description: `${toLabel} builds and serves what ${fromLabel} serves today: ${version}. The version ${toLabel} serves keeps the traffic until the new one passes its health check.`,
225
+ icon: "i-ph-arrow-fat-lines-up",
226
+ confirmLabel: `Promote to ${toLabel}`,
227
+ });
228
+ }
229
+ /** The dialog the Promote button of an environment opens. */
230
+ function promoteDialog(environments, environmentId) {
231
+ if (environments?.kind !== "ok")
232
+ return unavailableDialog(environments);
233
+ return promotionDialog(environments.value, environmentId);
234
+ }
235
+ /** The dialog the New environment button opens: its name, branch and services. */
236
+ function newEnvironmentDialog(environments) {
237
+ if (environments?.kind !== "ok")
238
+ return unavailableDialog(environments);
239
+ const { stages, others } = (0, pipeline_1.pipelineOf)(environments.value);
240
+ const durable = [...stages, ...others];
241
+ const production = durable.find(({ name }) => name === "production");
242
+ return (0, confirm_dialog_1.serializeConfirmDialog)({
243
+ title: "New environment",
244
+ description: "An environment is a branch that AntelopeJS Cloud builds and serves, with its own resources.",
245
+ icon: "i-ph-stack",
246
+ confirmLabel: "Create environment",
247
+ fields: [
248
+ {
249
+ id: "name",
250
+ label: "Name",
251
+ required: true,
252
+ type: new default_types_1.DefaultDataTypes.StringType({ placeholder: "staging" }),
253
+ },
254
+ {
255
+ id: "branch",
256
+ label: "Branch",
257
+ hint: "The branch AntelopeJS Cloud builds. Empty, it is env/ followed by the name.",
258
+ type: new default_types_1.DefaultDataTypes.StringType({ placeholder: "env/staging" }),
259
+ },
260
+ {
261
+ id: "cloneFrom",
262
+ label: "Copy services from",
263
+ type: new default_types_1.DefaultDataTypes.SelectType({
264
+ deselectable: true,
265
+ items: durable.map(({ id, name }) => ({
266
+ label: (0, pipeline_1.environmentLabel)(name),
267
+ value: id,
268
+ })),
269
+ }),
270
+ defaultValue: production?.id ?? null,
271
+ },
272
+ ],
273
+ });
274
+ }
275
+ //# sourceMappingURL=content.js.map
@@ -0,0 +1,32 @@
1
+ import type { EnvironmentDetail } from "@antelopejs/cloud-sdk";
2
+ import { type CloudRead } from "../connection/cloud";
3
+ /** What a follower checks each read of the environment it follows against. */
4
+ export interface FollowedPromotion {
5
+ /** The commit the promotion put on the environment. */
6
+ readonly commit: string;
7
+ /** When the follower gives up, in milliseconds since the epoch. */
8
+ readonly deadline: number;
9
+ }
10
+ /**
11
+ * Whether a follower reads the environment again after `read`, at `now`. It
12
+ * stops once the environment serves the promoted commit, once a deployment of
13
+ * that commit failed or was cancelled, past its deadline, and once Antelope
14
+ * Cloud refuses the token or no longer knows the environment.
15
+ */
16
+ export declare function followNext(read: CloudRead<EnvironmentDetail>, promotion: FollowedPromotion, now: number): "follow" | "stop";
17
+ /**
18
+ * Follows the deployment that the promotion of `commit` to `target` starts:
19
+ * reads the environment through the tenant's stored connection, and tells
20
+ * the tenant's open pages each time what it targets or serves changes, until
21
+ * {@link followNext} stops. Replaces the follower of an earlier promotion to
22
+ * the same environment.
23
+ */
24
+ export declare function followPromotion(tenantId: string, target: EnvironmentDetail, commit: string): void;
25
+ /**
26
+ * Whether a follower still follows the promotion of `commit` to the
27
+ * environment `environmentId` of the tenant: AntelopeJS Cloud may not have
28
+ * started the deployment of a pushed commit yet.
29
+ */
30
+ export declare function isFollowing(tenantId: string, environmentId: string, commit: string): boolean;
31
+ /** Stops every follower, as the module stops. */
32
+ export declare function stopFollowingPromotions(): void;
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.followNext = followNext;
4
+ exports.followPromotion = followPromotion;
5
+ exports.isFollowing = isFollowing;
6
+ exports.stopFollowingPromotions = stopFollowingPromotions;
7
+ const config_1 = require("../config");
8
+ const announce_1 = require("../connection/announce");
9
+ const cloud_1 = require("../connection/cloud");
10
+ const current_1 = require("../connection/current");
11
+ const ENDED = new Set(["failed", "cancelled"]);
12
+ const MISSING = { kind: "missing" };
13
+ const UNREACHABLE = { kind: "unreachable" };
14
+ const followers = new Map();
15
+ /**
16
+ * Whether a follower reads the environment again after `read`, at `now`. It
17
+ * stops once the environment serves the promoted commit, once a deployment of
18
+ * that commit failed or was cancelled, past its deadline, and once Antelope
19
+ * Cloud refuses the token or no longer knows the environment.
20
+ */
21
+ function followNext(read, promotion, now) {
22
+ if (read.kind === "revoked" ||
23
+ read.kind === "missing" ||
24
+ read.kind === "forbidden") {
25
+ return "stop";
26
+ }
27
+ if (now >= promotion.deadline)
28
+ return "stop";
29
+ if (read.kind === "unreachable")
30
+ return "follow";
31
+ const { serving, target } = read.value;
32
+ if (serving?.commit === promotion.commit)
33
+ return "stop";
34
+ return target?.commit === promotion.commit && ENDED.has(target.status)
35
+ ? "stop"
36
+ : "follow";
37
+ }
38
+ function keyOf({ tenantId, environmentId, }) {
39
+ return JSON.stringify([tenantId, environmentId]);
40
+ }
41
+ function fingerprint({ serving, target }) {
42
+ return JSON.stringify([serving?.id, target?.id, target?.status]);
43
+ }
44
+ function isFollowed(follower) {
45
+ return followers.get(keyOf(follower)) === follower;
46
+ }
47
+ async function readFollowed(follower) {
48
+ const stored = await (0, current_1.readConnection)(follower.tenantId);
49
+ if (stored?.state !== "connected" || stored.projectId === null) {
50
+ return MISSING;
51
+ }
52
+ const { projectId } = stored;
53
+ return (0, cloud_1.readCloud)(stored, (api) => api.environments.read(projectId, follower.environmentId));
54
+ }
55
+ async function check(follower) {
56
+ const read = await readFollowed(follower);
57
+ if (!isFollowed(follower))
58
+ return "stop";
59
+ const seen = read.kind === "ok" ? fingerprint(read.value) : follower.seen;
60
+ if (seen !== follower.seen) {
61
+ follower.seen = seen;
62
+ await (0, announce_1.announceProject)(follower.tenantId);
63
+ }
64
+ return followNext(read, follower, Date.now());
65
+ }
66
+ function schedule(follower) {
67
+ follower.timer = setTimeout(() => void step(follower), (0, config_1.cloudSettings)().promotionFollow.intervalMs);
68
+ }
69
+ async function step(follower) {
70
+ const next = await check(follower).catch(() => followNext(UNREACHABLE, follower, Date.now()));
71
+ if (!isFollowed(follower))
72
+ return;
73
+ if (next === "stop")
74
+ followers.delete(keyOf(follower));
75
+ else
76
+ schedule(follower);
77
+ }
78
+ /**
79
+ * Follows the deployment that the promotion of `commit` to `target` starts:
80
+ * reads the environment through the tenant's stored connection, and tells
81
+ * the tenant's open pages each time what it targets or serves changes, until
82
+ * {@link followNext} stops. Replaces the follower of an earlier promotion to
83
+ * the same environment.
84
+ */
85
+ function followPromotion(tenantId, target, commit) {
86
+ const follower = {
87
+ tenantId,
88
+ environmentId: target.id,
89
+ commit,
90
+ deadline: Date.now() + (0, config_1.cloudSettings)().promotionFollow.limitMs,
91
+ seen: fingerprint(target),
92
+ timer: undefined,
93
+ };
94
+ const key = keyOf(follower);
95
+ clearTimeout(followers.get(key)?.timer);
96
+ followers.set(key, follower);
97
+ schedule(follower);
98
+ }
99
+ /**
100
+ * Whether a follower still follows the promotion of `commit` to the
101
+ * environment `environmentId` of the tenant: AntelopeJS Cloud may not have
102
+ * started the deployment of a pushed commit yet.
103
+ */
104
+ function isFollowing(tenantId, environmentId, commit) {
105
+ const follower = followers.get(keyOf({ tenantId, environmentId }));
106
+ return follower?.commit === commit && Date.now() < follower.deadline;
107
+ }
108
+ /** Stops every follower, as the module stops. */
109
+ function stopFollowingPromotions() {
110
+ for (const { timer } of followers.values())
111
+ clearTimeout(timer);
112
+ followers.clear();
113
+ }
114
+ //# sourceMappingURL=follower.js.map
@@ -0,0 +1,58 @@
1
+ import type { EnvironmentDeployment, EnvironmentDetail } from "@antelopejs/cloud-sdk";
2
+ import { type EnvironmentName } from "../git/refs";
3
+ /** A project's durable environments, by their part in promotion. */
4
+ export interface Pipeline {
5
+ /** The environments named after a stage, in stage order. */
6
+ readonly stages: readonly EnvironmentDetail[];
7
+ /**
8
+ * The other durable environments, in the order AntelopeJS Cloud lists them.
9
+ * None of them promotes, nor is promoted to.
10
+ */
11
+ readonly others: readonly EnvironmentDetail[];
12
+ }
13
+ /** The pipeline of a project's environments. Pull-request previews take no part in it. */
14
+ export declare function pipelineOf(environments: readonly EnvironmentDetail[]): Pipeline;
15
+ /**
16
+ * Where a promotion of the environment `fromId` goes: the next stage the
17
+ * project has. `undefined` for the last stage and for an environment outside
18
+ * the pipeline.
19
+ */
20
+ export declare function promotionTarget(environments: readonly EnvironmentDetail[], fromId: string): EnvironmentDetail | undefined;
21
+ /**
22
+ * Why a promotion does not reach the environment it goes to: it tracks a
23
+ * branch publishing never moves, the `env/` branch of another environment,
24
+ * or a branch another environment tracks too, which the push would deploy.
25
+ */
26
+ export type RouteRefusal = "not_an_environment_branch" | "branch_of_another_environment" | "shared_environment_branch";
27
+ /**
28
+ * How a promotion reaches the environment it goes to. One that alone tracks
29
+ * its own `env/<name>` branch is reached by pushing that branch, which
30
+ * AntelopeJS Cloud deploys (`push`). One that tracks no branch, as the CLI
31
+ * deploys, is reached by asking AntelopeJS Cloud to deploy the commit
32
+ * (`cloud`). Any other is not reached (`refused`).
33
+ */
34
+ export type PromotionRoute = {
35
+ readonly kind: "push";
36
+ readonly environment: EnvironmentName;
37
+ } | {
38
+ readonly kind: "cloud";
39
+ } | {
40
+ readonly kind: "refused";
41
+ readonly refusal: RouteRefusal;
42
+ };
43
+ /**
44
+ * How a promotion reaches `target`, one of the project's `environments`,
45
+ * from the branch it tracks.
46
+ */
47
+ export declare function promotionRoute(target: EnvironmentDetail, environments: readonly EnvironmentDetail[]): PromotionRoute;
48
+ /**
49
+ * The latest deployment, when it failed while the environment kept serving
50
+ * another one: `null` otherwise.
51
+ */
52
+ export declare function failedTarget(environment: EnvironmentDetail): EnvironmentDeployment | null;
53
+ /** How a page names an environment: its name with a capital, as "Staging". */
54
+ export declare function environmentLabel(name: string): string;
55
+ /** The branch AntelopeJS Cloud builds an environment named `name` from by default. */
56
+ export declare function defaultBranch(name: string): string;
57
+ /** A commit as pages show it: its first 7 characters. */
58
+ export declare function shortCommit(commit: string): string;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pipelineOf = pipelineOf;
4
+ exports.promotionTarget = promotionTarget;
5
+ exports.promotionRoute = promotionRoute;
6
+ exports.failedTarget = failedTarget;
7
+ exports.environmentLabel = environmentLabel;
8
+ exports.defaultBranch = defaultBranch;
9
+ exports.shortCommit = shortCommit;
10
+ const refs_1 = require("../git/refs");
11
+ const STAGES = ["preview", "staging", "production"];
12
+ function isStage(name) {
13
+ return STAGES.some((stage) => stage === name);
14
+ }
15
+ /** The pipeline of a project's environments. Pull-request previews take no part in it. */
16
+ function pipelineOf(environments) {
17
+ const durable = environments.filter(({ preview }) => preview === null);
18
+ return {
19
+ stages: STAGES.flatMap((stage) => durable.filter(({ name }) => name === stage)),
20
+ others: durable.filter(({ name }) => !isStage(name)),
21
+ };
22
+ }
23
+ /**
24
+ * Where a promotion of the environment `fromId` goes: the next stage the
25
+ * project has. `undefined` for the last stage and for an environment outside
26
+ * the pipeline.
27
+ */
28
+ function promotionTarget(environments, fromId) {
29
+ const { stages } = pipelineOf(environments);
30
+ const at = stages.findIndex(({ id }) => id === fromId);
31
+ return at === -1 ? undefined : stages[at + 1];
32
+ }
33
+ /**
34
+ * How a promotion reaches `target`, one of the project's `environments`,
35
+ * from the branch it tracks.
36
+ */
37
+ function promotionRoute(target, environments) {
38
+ const { branch } = target;
39
+ if (branch === null)
40
+ return { kind: "cloud" };
41
+ const name = (0, refs_1.environmentOfBranch)(branch);
42
+ if (name === null) {
43
+ return { kind: "refused", refusal: "not_an_environment_branch" };
44
+ }
45
+ if (name !== target.name) {
46
+ return { kind: "refused", refusal: "branch_of_another_environment" };
47
+ }
48
+ const shared = environments.some((other) => other.id !== target.id && other.branch === branch);
49
+ return shared
50
+ ? { kind: "refused", refusal: "shared_environment_branch" }
51
+ : { kind: "push", environment: (0, refs_1.environmentName)(name) };
52
+ }
53
+ /**
54
+ * The latest deployment, when it failed while the environment kept serving
55
+ * another one: `null` otherwise.
56
+ */
57
+ function failedTarget(environment) {
58
+ const { serving, target } = environment;
59
+ return target?.status === "failed" && target.id !== serving?.id
60
+ ? target
61
+ : null;
62
+ }
63
+ /** How a page names an environment: its name with a capital, as "Staging". */
64
+ function environmentLabel(name) {
65
+ return `${name.charAt(0).toUpperCase()}${name.slice(1)}`;
66
+ }
67
+ /** The branch AntelopeJS Cloud builds an environment named `name` from by default. */
68
+ function defaultBranch(name) {
69
+ return `env/${name}`;
70
+ }
71
+ const SHORT_COMMIT_LENGTH = 7;
72
+ /** A commit as pages show it: its first 7 characters. */
73
+ function shortCommit(commit) {
74
+ return commit.slice(0, SHORT_COMMIT_LENGTH);
75
+ }
76
+ //# sourceMappingURL=pipeline.js.map
@@ -0,0 +1,18 @@
1
+ import type { EnvironmentDetail } from "@antelopejs/cloud-sdk";
2
+ import { type Refusal } from "../git/refusal";
3
+ /**
4
+ * The environments of a project a publish may move, by name: the pipeline's
5
+ * stages in their order, then the others. Each one alone builds its own
6
+ * `env/<name>` branch, the branch a publish pushes and AntelopeJS Cloud
7
+ * deploys. Production takes promoted versions only once the project has a
8
+ * stage before it; without one, it takes publishes.
9
+ */
10
+ export declare function publishTargetNames(environments: readonly EnvironmentDetail[]): string[];
11
+ /**
12
+ * Why a publish to the environment `name` is refused, `null` when it may
13
+ * run. With the linked project's `environments`, only its
14
+ * {@link publishTargetNames} are accepted. Without them, for a DMS that
15
+ * publishes no project or whose project AntelopeJS Cloud did not answer for,
16
+ * any environment but production is.
17
+ */
18
+ export declare function publishTargetRefusal(environments: readonly EnvironmentDetail[] | undefined, name: string): Refusal | null;