@antelopejs/dms-antelope-cloud 0.0.0-stage → 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 +447 -2
  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 -3
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DASHBOARD_REFUSALS = void 0;
4
+ exports.dashboardAppName = dashboardAppName;
5
+ exports.ensureDashboard = ensureDashboard;
6
+ exports.readAddresses = readAddresses;
7
+ const refusals_1 = require("../connection/refusals");
8
+ const roles_1 = require("../environments/roles");
9
+ const dockerfile_1 = require("./dockerfile");
10
+ const PRODUCTION = "production";
11
+ /** AntelopeJS Cloud takes application names of at most this many characters. */
12
+ const MAX_APP_NAME_LENGTH = 40;
13
+ const APP_NAME_SUFFIX = `-${roles_1.DASHBOARD_SERVICE}`;
14
+ /** How much of an environment's name an application name keeps. */
15
+ const MAX_ENVIRONMENT_PART = 14;
16
+ /** How a page refuses a failed creation or opening of a dashboard. */
17
+ exports.DASHBOARD_REFUSALS = {
18
+ missing: (0, refusals_1.unprocessable)("unknown_environment"),
19
+ codes: new Map([
20
+ [
21
+ "cloud.errors.services.app_name_taken",
22
+ (0, refusals_1.conflict)("dashboard_address_taken"),
23
+ ],
24
+ [
25
+ "cloud.errors.settings.subdomain_taken",
26
+ (0, refusals_1.conflict)("dashboard_address_taken"),
27
+ ],
28
+ [
29
+ "cloud.errors.settings.service_name_taken",
30
+ (0, refusals_1.conflict)("dashboard_name_taken"),
31
+ ],
32
+ [
33
+ "cloud.errors.limits.services_per_environment",
34
+ (0, refusals_1.conflict)("dashboard_service_limit"),
35
+ ],
36
+ [
37
+ "cloud.errors.projects.repository_not_granted",
38
+ (0, refusals_1.unprocessable)("dashboard_repository_not_visible"),
39
+ ],
40
+ [
41
+ "cloud.errors.settings.invalid_port",
42
+ (0, refusals_1.badRequest)("dashboard_port_refused"),
43
+ ],
44
+ [
45
+ "cloud.errors.settings.public_needs_port",
46
+ (0, refusals_1.conflict)("dashboard_needs_port"),
47
+ ],
48
+ ["cloud.errors.settings.preview_read_only", (0, refusals_1.conflict)("preview_read_only")],
49
+ ]),
50
+ };
51
+ function clipped(slug, length) {
52
+ return slug.slice(0, length).replace(/-+$/, "");
53
+ }
54
+ /**
55
+ * The application name a dashboard is created under, which is where its
56
+ * address starts: the project's name and `-dashboard` on Production, with
57
+ * the environment's name in between elsewhere, as AntelopeJS Cloud names the
58
+ * services it copies. The project's name is cut first, then a long
59
+ * environment name, so that the whole fits the length AntelopeJS Cloud takes
60
+ * and two environments of a project keep different names.
61
+ */
62
+ function dashboardAppName(projectSlug, environmentName) {
63
+ const room = MAX_APP_NAME_LENGTH - APP_NAME_SUFFIX.length;
64
+ if (environmentName === PRODUCTION) {
65
+ return `${clipped(projectSlug, room)}${APP_NAME_SUFFIX}`;
66
+ }
67
+ const environment = clipped(environmentName, MAX_ENVIRONMENT_PART);
68
+ const project = clipped(projectSlug, room - environment.length - 1);
69
+ return `${project}-${environment}${APP_NAME_SUFFIX}`;
70
+ }
71
+ /**
72
+ * Gives an environment its dashboard: a second service that builds the
73
+ * project's repository with `frontend.Dockerfile`, answers on `port` and is
74
+ * open to the internet on its own address. An environment that runs a
75
+ * dashboard keeps it: one without an address gets its port and its address,
76
+ * one with an address is left as it is. Every write can be sent again, so a
77
+ * run after a lost answer finishes the work.
78
+ *
79
+ * @param environment The environment as AntelopeJS Cloud lists it now
80
+ * @throws The `CloudApiError` of a read or a write AntelopeJS Cloud refuses
81
+ */
82
+ async function ensureDashboard(api, { projectId, repository, port }, environment) {
83
+ const [{ dashboard }, project] = await Promise.all([
84
+ (0, roles_1.serviceRolesOf)(api, projectId, environment),
85
+ api.readProject(projectId),
86
+ ]);
87
+ if (dashboard === null) {
88
+ await api.createService(projectId, environment.id, {
89
+ name: roles_1.DASHBOARD_SERVICE,
90
+ appName: dashboardAppName(project.slug, environment.name),
91
+ source: {
92
+ type: "repository",
93
+ repository,
94
+ dockerfilePath: dockerfile_1.DASHBOARD_DOCKERFILE,
95
+ },
96
+ port,
97
+ isPublic: true,
98
+ });
99
+ return "created";
100
+ }
101
+ if ((0, roles_1.serviceAddress)(project, environment.id, dashboard) !== null) {
102
+ return "existing";
103
+ }
104
+ await api.setServicePort(dashboard, port);
105
+ await api.setServiceExposure(dashboard, true);
106
+ return "opened";
107
+ }
108
+ /**
109
+ * Reads where the app and the dashboard of each environment answer, by
110
+ * environment id.
111
+ *
112
+ * @throws The `CloudApiError` of a read AntelopeJS Cloud does not answer
113
+ */
114
+ async function readAddresses(api, projectId, environments) {
115
+ const [project, roles] = await Promise.all([
116
+ api.readProject(projectId),
117
+ Promise.all(environments.map((environment) => (0, roles_1.serviceRolesOf)(api, projectId, environment))),
118
+ ]);
119
+ return new Map(environments.map((environment, index) => {
120
+ const { apps, dashboard } = roles[index];
121
+ const hasOneApp = apps.length === 1;
122
+ return [
123
+ environment.id,
124
+ {
125
+ app: hasOneApp
126
+ ? (0, roles_1.serviceAddress)(project, environment.id, apps[0])
127
+ : null,
128
+ dashboard: dashboard === null
129
+ ? null
130
+ : (0, roles_1.serviceAddress)(project, environment.id, dashboard),
131
+ hasDashboard: dashboard !== null,
132
+ hasOneApp,
133
+ },
134
+ ];
135
+ }));
136
+ }
137
+ //# sourceMappingURL=service.js.map
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The variables the dashboard of a DMS reads from its environment: it loads
3
+ * no `antelope.config.ts` at start, so no `envOverrides` entry names them.
4
+ */
5
+ export declare const DASHBOARD_VARIABLES: {
6
+ /** The address of the API it calls. */
7
+ readonly apiBaseUrl: "DMS_API_BASE_URL";
8
+ /** Its own address, as browsers reach it. */
9
+ readonly clientBaseUrl: "DMS_CLIENT_BASE_URL";
10
+ /** What it signs its sessions with. */
11
+ readonly sessionSecret: "DMS_SESSION_SECRET";
12
+ /** What it proves itself to the API with: the API holds the same value. */
13
+ readonly bootstrapSecret: "DMS_BOOTSTRAP_SECRET";
14
+ /** What the API signs its calls to the dashboard's e-mail renderer with: the API holds the same value. */
15
+ readonly htmlRenderSecret: "DMS_HTML_RENDER_SECRET";
16
+ };
17
+ /** The names of {@link DASHBOARD_VARIABLES}, in the order pages list them. */
18
+ export declare const DASHBOARD_KEYS: readonly string[];
19
+ /**
20
+ * The variable a dashboard reads the name of the header the hosting platform
21
+ * overwrites with the client's address from. It runs without it, and then
22
+ * takes the address of the platform's gateway for every visitor's.
23
+ */
24
+ export declare const CLIENT_IP_VARIABLE = "DMS_CLIENT_IP_HEADER";
25
+ /**
26
+ * The variable the API of a DMS reads the setup token from: the token the
27
+ * first owner of a deployed instance registers with. The DMS reads it from
28
+ * its environment, not through `envOverrides`.
29
+ */
30
+ export declare const SETUP_TOKEN_VARIABLE = "DMS_SETUP_TOKEN";
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SETUP_TOKEN_VARIABLE = exports.CLIENT_IP_VARIABLE = exports.DASHBOARD_KEYS = exports.DASHBOARD_VARIABLES = void 0;
4
+ /**
5
+ * The variables the dashboard of a DMS reads from its environment: it loads
6
+ * no `antelope.config.ts` at start, so no `envOverrides` entry names them.
7
+ */
8
+ exports.DASHBOARD_VARIABLES = {
9
+ /** The address of the API it calls. */
10
+ apiBaseUrl: "DMS_API_BASE_URL",
11
+ /** Its own address, as browsers reach it. */
12
+ clientBaseUrl: "DMS_CLIENT_BASE_URL",
13
+ /** What it signs its sessions with. */
14
+ sessionSecret: "DMS_SESSION_SECRET",
15
+ /** What it proves itself to the API with: the API holds the same value. */
16
+ bootstrapSecret: "DMS_BOOTSTRAP_SECRET",
17
+ /** What the API signs its calls to the dashboard's e-mail renderer with: the API holds the same value. */
18
+ htmlRenderSecret: "DMS_HTML_RENDER_SECRET",
19
+ };
20
+ /** The names of {@link DASHBOARD_VARIABLES}, in the order pages list them. */
21
+ exports.DASHBOARD_KEYS = Object.values(exports.DASHBOARD_VARIABLES);
22
+ /**
23
+ * The variable a dashboard reads the name of the header the hosting platform
24
+ * overwrites with the client's address from. It runs without it, and then
25
+ * takes the address of the platform's gateway for every visitor's.
26
+ */
27
+ exports.CLIENT_IP_VARIABLE = "DMS_CLIENT_IP_HEADER";
28
+ /**
29
+ * The variable the API of a DMS reads the setup token from: the token the
30
+ * first owner of a deployed instance registers with. The DMS reads it from
31
+ * its environment, not through `envOverrides`.
32
+ */
33
+ exports.SETUP_TOKEN_VARIABLE = "DMS_SETUP_TOKEN";
34
+ //# sourceMappingURL=variables.js.map
@@ -0,0 +1,39 @@
1
+ import type { CloudApi } from "@antelopejs/cloud-sdk";
2
+ import { z } from "zod";
3
+ declare const lineSchema: z.ZodObject<{
4
+ at: z.ZodString;
5
+ level: z.ZodString;
6
+ message: z.ZodString;
7
+ instance: z.ZodNullable<z.ZodString>;
8
+ }, "strip", z.ZodTypeAny, {
9
+ instance: string | null;
10
+ message: string;
11
+ at: string;
12
+ level: string;
13
+ }, {
14
+ instance: string | null;
15
+ message: string;
16
+ at: string;
17
+ level: string;
18
+ }>;
19
+ /** A line of a build's log, as its viewer shows it. */
20
+ export type BuildLogLine = z.infer<typeof lineSchema>;
21
+ /**
22
+ * The end of a build's log: its newest lines, oldest first. `truncated`
23
+ * says the read reached its bound, so the log may hold older lines.
24
+ */
25
+ export interface BuildLogTail {
26
+ readonly lines: readonly BuildLogLine[];
27
+ readonly truncated: boolean;
28
+ }
29
+ /**
30
+ * Reads the end of a build's log from AntelopeJS Cloud: one bounded read,
31
+ * at most {@link BUILD_LOG_LINES} lines after the line that names how the
32
+ * build runs, each cut to 2000 characters.
33
+ *
34
+ * @throws The SDK's error when the Cloud refuses the read, as for a build it
35
+ * no longer knows, and an `Error` when the Cloud ends the stream with its
36
+ * `error` event.
37
+ */
38
+ export declare function readBuildLog(api: CloudApi, buildId: string): Promise<BuildLogTail>;
39
+ export {};
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readBuildLog = readBuildLog;
4
+ const zod_1 = require("zod");
5
+ const lineSchema = zod_1.z.object({
6
+ at: zod_1.z.string(),
7
+ level: zod_1.z.string(),
8
+ message: zod_1.z.string(),
9
+ instance: zod_1.z.string().nullable(),
10
+ });
11
+ /** The most lines of a build's log the module reads and shows. */
12
+ const BUILD_LOG_LINES = 300;
13
+ /** The longest line shown whole; a longer one is cut and ends with an ellipsis. */
14
+ const MAX_LINE_LENGTH = 2000;
15
+ const ELLIPSIS = "…";
16
+ function bounded(line) {
17
+ if (line.message.length <= MAX_LINE_LENGTH)
18
+ return line;
19
+ return {
20
+ ...line,
21
+ message: `${line.message.slice(0, MAX_LINE_LENGTH)}${ELLIPSIS}`,
22
+ };
23
+ }
24
+ /**
25
+ * Reads the end of a build's log from AntelopeJS Cloud: one bounded read,
26
+ * at most {@link BUILD_LOG_LINES} lines after the line that names how the
27
+ * build runs, each cut to 2000 characters.
28
+ *
29
+ * @throws The SDK's error when the Cloud refuses the read, as for a build it
30
+ * no longer knows, and an `Error` when the Cloud ends the stream with its
31
+ * `error` event.
32
+ */
33
+ async function readBuildLog(api, buildId) {
34
+ const lines = [];
35
+ let read = 0;
36
+ const events = api.buildLogs(buildId, {
37
+ follow: false,
38
+ limit: BUILD_LOG_LINES,
39
+ });
40
+ for await (const event of events) {
41
+ if (event.event === "error") {
42
+ throw new Error("AntelopeJS Cloud could not serve the build log");
43
+ }
44
+ if (event.event === "end")
45
+ break;
46
+ const line = lineSchema.safeParse(event.data);
47
+ if (event.event !== "log" || !line.success)
48
+ continue;
49
+ if (event.id)
50
+ read += 1;
51
+ lines.push(bounded(line.data));
52
+ if (read >= BUILD_LOG_LINES)
53
+ break;
54
+ }
55
+ return { lines, truncated: read >= BUILD_LOG_LINES };
56
+ }
57
+ //# sourceMappingURL=build-log.js.map
@@ -0,0 +1,77 @@
1
+ import type { CommitDeployment } from "./deployment";
2
+ /** A Cloud step of a publish, after the four git steps. */
3
+ type CloudStepId = "provision" | "build" | "health" | "switch";
4
+ /** How a Cloud step of a publish stands. */
5
+ type CloudStepStatus = "todo" | "running" | "done" | "skipped" | "failed";
6
+ /** One Cloud step of a publish. */
7
+ interface CloudStep {
8
+ readonly id: CloudStepId;
9
+ readonly status: CloudStepStatus;
10
+ }
11
+ /** Where the deployment of a publish ended up, or that it still runs. */
12
+ type PublishOutcome = "running" | "live" | "failed";
13
+ /**
14
+ * Why the Cloud has nothing to show for the project this DMS publishes: the
15
+ * DMS is not connected or its sign-in was revoked, the project no longer
16
+ * exists on the Cloud, its token is not allowed to read it, or the Cloud did
17
+ * not answer.
18
+ */
19
+ export type CloudGap = "not_connected" | "no_project" | "forbidden" | "unreachable";
20
+ /** Why the Cloud steps of a publish cannot be followed. */
21
+ type UnavailableReason = CloudGap | "untracked";
22
+ /**
23
+ * The Cloud steps of one publish: why they cannot be followed, `waiting`
24
+ * until the Cloud runs a deployment of its commit, then that deployment's
25
+ * steps and, once it failed, the step it stopped at and what visitors see.
26
+ */
27
+ export type PublishSteps = {
28
+ readonly state: "unavailable";
29
+ readonly reason: UnavailableReason;
30
+ readonly message: string;
31
+ } | {
32
+ readonly state: "waiting";
33
+ readonly steps: readonly CloudStep[];
34
+ } | {
35
+ readonly state: "following";
36
+ readonly deploymentId: string;
37
+ readonly deploymentUrl: string;
38
+ readonly steps: readonly CloudStep[];
39
+ readonly outcome: PublishOutcome;
40
+ readonly failure: {
41
+ readonly title: string;
42
+ readonly visitors: string;
43
+ /** Opens the failed build's log on the deployment's page; null when no build failed. */
44
+ readonly buildLogUrl: string | null;
45
+ } | null;
46
+ };
47
+ /** The number of the published version whose tagged commit is the one given, else null. */
48
+ export type ReleaseLookup = (commit: string) => number | null;
49
+ /** A deployment an environment serves, as far as naming it goes. */
50
+ export interface Served {
51
+ readonly number: number;
52
+ readonly commit: string | null;
53
+ }
54
+ /** The deployment of a publish's commit, and what its environment serves. */
55
+ export interface FollowedPublish {
56
+ readonly deployment: CommitDeployment;
57
+ readonly environment: string;
58
+ readonly serving: Served | null;
59
+ }
60
+ /** `preview` → `Preview`. */
61
+ export declare function environmentLabel(name: string): string;
62
+ /** What a served deployment is called: `v15`, its git version, else `#4`. */
63
+ export declare function servedName(served: Served, releaseOf: ReleaseLookup): string;
64
+ /** Why a publish's Cloud steps cannot be followed, said in words. */
65
+ export declare function unavailableSteps(reason: CloudGap): PublishSteps;
66
+ /** No Cloud environment builds the branch a publish moved. */
67
+ export declare function untrackedSteps(branch: string): PublishSteps;
68
+ /** The Cloud steps before the Cloud runs a deployment of the commit. */
69
+ export declare function waitingSteps(): PublishSteps;
70
+ /**
71
+ * The four Cloud steps of a publish, read from the deployment of its commit.
72
+ * No Cloud signal reports provisioning: it is skipped once the deployment
73
+ * left the queue, and waits before. `releaseOf` names what visitors still
74
+ * see once it failed, and is read only then.
75
+ */
76
+ export declare function followingSteps(followed: FollowedPublish, deploymentUrl: string, releaseOf: () => Promise<ReleaseLookup>): Promise<PublishSteps>;
77
+ export {};
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.environmentLabel = environmentLabel;
4
+ exports.servedName = servedName;
5
+ exports.unavailableSteps = unavailableSteps;
6
+ exports.untrackedSteps = untrackedSteps;
7
+ exports.waitingSteps = waitingSteps;
8
+ exports.followingSteps = followingSteps;
9
+ const content_1 = require("./content");
10
+ const lifecycle_1 = require("./lifecycle");
11
+ const CLOUD_STEPS = {
12
+ build: "build",
13
+ health: "check",
14
+ switch: "switch",
15
+ };
16
+ const CLOUD_STATUSES = {
17
+ done: "done",
18
+ current: "running",
19
+ todo: "todo",
20
+ failed: "failed",
21
+ skipped: "skipped",
22
+ };
23
+ const OUTCOMES = {
24
+ queued: "running",
25
+ building: "running",
26
+ checking: "running",
27
+ switching: "running",
28
+ unknown: "running",
29
+ succeeded: "live",
30
+ superseded: "live",
31
+ failed: "failed",
32
+ cancelled: "failed",
33
+ };
34
+ const WAITING = {
35
+ state: "waiting",
36
+ steps: [
37
+ { id: "provision", status: "todo" },
38
+ { id: "build", status: "todo" },
39
+ { id: "health", status: "todo" },
40
+ { id: "switch", status: "todo" },
41
+ ],
42
+ };
43
+ const UNAVAILABLE_MESSAGES = {
44
+ not_connected: "Connect this DMS to an AntelopeJS Cloud project to follow its deployment.",
45
+ no_project: "The AntelopeJS Cloud project this DMS publishes no longer exists, so nothing deploys this version. Choose another project on the Connection page.",
46
+ forbidden: "AntelopeJS Cloud does not allow this token to follow the deployment of this project, so it cannot be followed here.",
47
+ unreachable: "AntelopeJS Cloud did not answer, so its deployment cannot be followed here. Open Deployments to see it.",
48
+ };
49
+ /** `preview` → `Preview`. */
50
+ function environmentLabel(name) {
51
+ return name.charAt(0).toUpperCase() + name.slice(1);
52
+ }
53
+ /** What a served deployment is called: `v15`, its git version, else `#4`. */
54
+ function servedName(served, releaseOf) {
55
+ const release = served.commit === null ? null : releaseOf(served.commit);
56
+ return release === null ? `#${served.number}` : `v${release}`;
57
+ }
58
+ /** Why a publish's Cloud steps cannot be followed, said in words. */
59
+ function unavailableSteps(reason) {
60
+ return {
61
+ state: "unavailable",
62
+ reason,
63
+ message: UNAVAILABLE_MESSAGES[reason],
64
+ };
65
+ }
66
+ /** No Cloud environment builds the branch a publish moved. */
67
+ function untrackedSteps(branch) {
68
+ return {
69
+ state: "unavailable",
70
+ reason: "untracked",
71
+ message: `No AntelopeJS Cloud environment builds ${branch}, so nothing deploys this version.`,
72
+ };
73
+ }
74
+ /** The Cloud steps before the Cloud runs a deployment of the commit. */
75
+ function waitingSteps() {
76
+ return WAITING;
77
+ }
78
+ function cloudSteps(deployment) {
79
+ const states = new Map((0, lifecycle_1.stepsOf)(deployment).map(({ id, state }) => [id, state]));
80
+ const status = (id) => CLOUD_STATUSES[states.get(id) ?? "todo"];
81
+ return [
82
+ {
83
+ id: "provision",
84
+ status: status("queued") === "running" ? "todo" : "skipped",
85
+ },
86
+ { id: "build", status: status(CLOUD_STEPS.build) },
87
+ { id: "health", status: status(CLOUD_STEPS.health) },
88
+ { id: "switch", status: status(CLOUD_STEPS.switch) },
89
+ ];
90
+ }
91
+ function failureTitle(deployment) {
92
+ if (deployment.phase === "cancelled")
93
+ return content_1.CANCELLED_TITLE;
94
+ const step = deployment.failure?.step ?? deployment.reached;
95
+ const summary = deployment.failure?.summary ?? null;
96
+ return summary === null ? (0, content_1.failedAt)(step) : `${(0, content_1.failedAt)(step)}: ${summary}`;
97
+ }
98
+ /** What visitors of the environment see after a deployment failed there. */
99
+ function visitors(followed, releaseOf) {
100
+ const label = environmentLabel(followed.environment);
101
+ if (followed.serving === null)
102
+ return `Visitors get no site on ${label} yet.`;
103
+ const name = servedName(followed.serving, releaseOf);
104
+ return `Visitors still see ${name} on ${label}: AntelopeJS Cloud kept it serving.`;
105
+ }
106
+ /**
107
+ * The four Cloud steps of a publish, read from the deployment of its commit.
108
+ * No Cloud signal reports provisioning: it is skipped once the deployment
109
+ * left the queue, and waits before. `releaseOf` names what visitors still
110
+ * see once it failed, and is read only then.
111
+ */
112
+ async function followingSteps(followed, deploymentUrl, releaseOf) {
113
+ const { deployment } = followed;
114
+ const outcome = OUTCOMES[deployment.phase];
115
+ return {
116
+ state: "following",
117
+ deploymentId: deployment.id,
118
+ deploymentUrl,
119
+ steps: cloudSteps(deployment),
120
+ outcome,
121
+ failure: outcome === "failed"
122
+ ? {
123
+ title: failureTitle(deployment),
124
+ visitors: visitors(followed, await releaseOf()),
125
+ buildLogUrl: (deployment.failure?.buildId ?? null) === null
126
+ ? null
127
+ : `${deploymentUrl}?${content_1.BUILD_LOG_QUERY}`,
128
+ }
129
+ : null,
130
+ };
131
+ }
132
+ //# sourceMappingURL=cloud-steps.js.map
@@ -0,0 +1,61 @@
1
+ import type { BannerContent } from "@antelopejs/interface-dms/base/banner";
2
+ import type { KeyValueListItem } from "@antelopejs/interface-dms/base/key-value-list";
3
+ import type { Deployment, DeploymentDetail, Trigger } from "./deployment";
4
+ import { type Stage, type StepId, type Tone } from "./lifecycle";
5
+ /** Where a row's links lead: its detail page and the Logs page of its environment. */
6
+ export interface RowLinks {
7
+ readonly detail: (deploymentId: string) => string;
8
+ readonly logs: (environmentId: string) => string;
9
+ }
10
+ /** A row of the Deployments table. `stage`, `environmentId` and `triggerKind` back its filters. */
11
+ export interface DeploymentRow {
12
+ readonly id: string;
13
+ /** `#42`, or `—` when the Cloud API gives no number. */
14
+ readonly name: string;
15
+ /** `env/preview @ 3f9c2e1`, null when the Cloud API names no source. */
16
+ readonly source: string | null;
17
+ readonly environmentId: string;
18
+ readonly environment: string;
19
+ readonly status: string;
20
+ readonly statusTone: Tone;
21
+ readonly stage: Stage;
22
+ readonly trigger: string | null;
23
+ readonly triggerKind: Trigger | "unknown";
24
+ readonly startedAt: string | null;
25
+ readonly durationSeconds: number | null;
26
+ readonly href: string;
27
+ readonly logsHref: string;
28
+ }
29
+ /** What the Deployments table's list route answers. */
30
+ export interface DeploymentRows {
31
+ readonly results: DeploymentRow[];
32
+ readonly total: number;
33
+ }
34
+ /** The fields the Deployments table filters on, by `filter_<field>`. */
35
+ export type RowFilters = Partial<Record<"stage" | "environmentId" | "triggerKind", string>>;
36
+ /** One deployment as a row of the Deployments table. */
37
+ export declare function deploymentRow(deployment: Deployment, links: RowLinks): DeploymentRow;
38
+ /** The rows that pass every filter the table sent; the browser searches, sorts and pages them. */
39
+ export declare function selectRows(rows: readonly DeploymentRow[], filters: RowFilters): DeploymentRows;
40
+ /** The facts of one deployment: where, what, when. */
41
+ export declare function factItems(detail: DeploymentDetail): KeyValueListItem[];
42
+ /** One status row per step of the deployment's route. */
43
+ export declare function stepItems(detail: DeploymentDetail): KeyValueListItem[];
44
+ /** The title of a cancelled deployment. */
45
+ export declare const CANCELLED_TITLE = "This deployment was cancelled";
46
+ /** "Failed at the health check": the step a failed deployment stopped at. */
47
+ export declare function failedAt(step: StepId): string;
48
+ /** The query that opens the build log on a deployment's page. */
49
+ export declare const BUILD_LOG_QUERY = "log=build";
50
+ /**
51
+ * Null unless the deployment failed or was cancelled. It says the step it
52
+ * stopped at, the build's summary, and what the environment still serves.
53
+ * A failed build adds a link that opens its log on the page at `pageHref`.
54
+ */
55
+ export declare function failureBanner(detail: DeploymentDetail, pageHref: string): BannerContent | null;
56
+ /**
57
+ * Null unless the deployment went live and its environment serves another
58
+ * one now. A ready plan gives a Roll back button that confirms first; a
59
+ * refused one says why, with the refusal the button would answer.
60
+ */
61
+ export declare function rollbackBanner(detail: DeploymentDetail, rollbackUrl: string): BannerContent | null;