@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,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.environmentsUnavailable = environmentsUnavailable;
4
+ exports.environmentsLive = environmentsLive;
5
+ const web_url_1 = require("../web-url");
6
+ const cloud_steps_1 = require("./cloud-steps");
7
+ const LIVE_STATES = new Map([
8
+ ["live", "live"],
9
+ ["build", "building"],
10
+ ["sleep", "sleeping"],
11
+ ["failed", "failed"],
12
+ ["waiting", "waiting"],
13
+ ]);
14
+ const UNAVAILABLE = {
15
+ __proto__: null,
16
+ not_connected: {
17
+ state: "unavailable",
18
+ message: "Connect this DMS to an AntelopeJS Cloud project to see what each environment serves.",
19
+ },
20
+ no_project: {
21
+ state: "unavailable",
22
+ message: "The AntelopeJS Cloud project this DMS publishes no longer exists. Choose another project on the Connection page.",
23
+ },
24
+ forbidden: {
25
+ state: "unavailable",
26
+ message: "AntelopeJS Cloud does not allow this token to read what each environment serves.",
27
+ },
28
+ unreachable: {
29
+ state: "unavailable",
30
+ message: "AntelopeJS Cloud did not answer. What each environment serves shows again once it does.",
31
+ },
32
+ };
33
+ /** Why the widget has no environment to show. */
34
+ function environmentsUnavailable(reason) {
35
+ return UNAVAILABLE[reason];
36
+ }
37
+ /** Each environment of the project, with the version it serves and its state. */
38
+ function environmentsLive(environments, releaseOf, logsUrl) {
39
+ return {
40
+ state: "ok",
41
+ environments: environments.map((environment) => ({
42
+ id: environment.id,
43
+ name: environment.name,
44
+ label: (0, cloud_steps_1.environmentLabel)(environment.name),
45
+ version: environment.serving
46
+ ? (0, cloud_steps_1.servedName)(environment.serving, releaseOf)
47
+ : null,
48
+ state: LIVE_STATES.get(environment.state) ?? "unknown",
49
+ url: (0, web_url_1.webUrl)(environment.url),
50
+ logsUrl: logsUrl(environment.id),
51
+ })),
52
+ };
53
+ }
54
+ //# sourceMappingURL=live.js.map
@@ -0,0 +1,20 @@
1
+ import type { CloudApi } from "@antelopejs/cloud-sdk";
2
+ import type { FollowedPublish } from "./cloud-steps";
3
+ /**
4
+ * What the Cloud runs of a publish: no environment of the project builds
5
+ * its branch, none has a deployment of its commit yet, or that deployment.
6
+ */
7
+ export type PublishRead = {
8
+ readonly kind: "untracked";
9
+ readonly branch: string;
10
+ } | {
11
+ readonly kind: "waiting";
12
+ } | {
13
+ readonly kind: "found";
14
+ readonly followed: FollowedPublish;
15
+ };
16
+ /**
17
+ * Reads the deployment of `commit` on the Cloud environment that builds the
18
+ * branch of the environment named `environment`, `env/<environment>`.
19
+ */
20
+ export declare function readPublish(api: CloudApi, projectId: string, environment: string, commit: string): Promise<PublishRead>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readPublish = readPublish;
4
+ const refs_1 = require("../git/refs");
5
+ const ledger_1 = require("./ledger");
6
+ /**
7
+ * Reads the deployment of `commit` on the Cloud environment that builds the
8
+ * branch of the environment named `environment`, `env/<environment>`.
9
+ */
10
+ async function readPublish(api, projectId, environment, commit) {
11
+ const branch = (0, refs_1.environmentBranch)(environment);
12
+ const environments = await api.environments.list(projectId);
13
+ const tracked = environments.find((one) => one.branch === branch);
14
+ if (!tracked)
15
+ return { kind: "untracked", branch };
16
+ const deployment = await (0, ledger_1.readCommitDeployment)(api, projectId, tracked, commit);
17
+ if (!deployment)
18
+ return { kind: "waiting" };
19
+ return {
20
+ kind: "found",
21
+ followed: { deployment, environment, serving: tracked.serving },
22
+ };
23
+ }
24
+ //# sourceMappingURL=publish-read.js.map
@@ -0,0 +1,13 @@
1
+ /** Why AntelopeJS Cloud ended a deployment whose build did not fail, in words a page shows. */
2
+ export interface DeploymentRefusal {
3
+ /** One sentence, without its final period. */
4
+ readonly summary: string;
5
+ /** AntelopeJS Cloud failed, not the project: deploying the same commit again is the way out. */
6
+ readonly platform: boolean;
7
+ }
8
+ /**
9
+ * The refusal AntelopeJS Cloud names with `key` on a failed deployment, or
10
+ * `null` for a key this module has no words for: the page then says the step
11
+ * the deployment stopped at, and nothing it would have to guess.
12
+ */
13
+ export declare function deploymentRefusal(key: string | undefined): DeploymentRefusal | null;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deploymentRefusal = deploymentRefusal;
4
+ const REFUSALS = new Map([
5
+ [
6
+ "cloud.errors.builds.missing_port",
7
+ {
8
+ summary: "The service has no port, so AntelopeJS Cloud can neither route to it nor check it. Set its port in the AntelopeJS Cloud console, then deploy again",
9
+ platform: false,
10
+ },
11
+ ],
12
+ [
13
+ "cloud.errors.builds.settlement_failed",
14
+ {
15
+ summary: "The image was built, and AntelopeJS Cloud could not deploy it",
16
+ platform: true,
17
+ },
18
+ ],
19
+ [
20
+ "cloud.errors.builds.workflow_missing",
21
+ {
22
+ summary: "AntelopeJS Cloud lost the build before it reported its result",
23
+ platform: true,
24
+ },
25
+ ],
26
+ ]);
27
+ /**
28
+ * The refusal AntelopeJS Cloud names with `key` on a failed deployment, or
29
+ * `null` for a key this module has no words for: the page then says the step
30
+ * the deployment stopped at, and nothing it would have to guess.
31
+ */
32
+ function deploymentRefusal(key) {
33
+ return (key === undefined ? undefined : REFUSALS.get(key)) ?? null;
34
+ }
35
+ //# sourceMappingURL=refusals.js.map
@@ -0,0 +1,86 @@
1
+ import type { EnvironmentDetail } from "@antelopejs/cloud-sdk";
2
+ import { z } from "zod";
3
+ import { type CloudRead } from "../connection/cloud";
4
+ import { type CurrentConnection } from "../connection/current";
5
+ /**
6
+ * The environments of the project a stored connection publishes, as
7
+ * AntelopeJS Cloud lists them: `undefined` without a signed-in workspace and
8
+ * its project.
9
+ */
10
+ export declare function readEnvironments(stored: CurrentConnection | undefined): Promise<CloudRead<EnvironmentDetail[]> | undefined>;
11
+ /**
12
+ * The environments of the project the tenant publishes, as AntelopeJS Cloud
13
+ * lists them.
14
+ *
15
+ * @throws The refusal of a tenant without a project, or of a failed read.
16
+ */
17
+ export declare function listEnvironments(tenantId: string): Promise<EnvironmentDetail[]>;
18
+ /**
19
+ * Reads the environment a row action names in its `environment` query
20
+ * parameter.
21
+ *
22
+ * @throws The refusal of a request that names none.
23
+ */
24
+ export declare function parseEnvironmentId(raw: Parameters<z.ZodString["safeParse"]>[0]): string;
25
+ /**
26
+ * What a promotion started: the push of the branch the next stage tracks,
27
+ * which AntelopeJS Cloud deploys, the deployment AntelopeJS Cloud started for
28
+ * it, or the deployment of the commit already under way, whose id is `null`
29
+ * while AntelopeJS Cloud has not started the one an earlier push asked for.
30
+ */
31
+ export type PromotionAnswer = {
32
+ readonly via: "push";
33
+ readonly branch: string;
34
+ readonly commit: string;
35
+ } | {
36
+ readonly via: "cloud";
37
+ readonly deploymentId: string;
38
+ readonly commit: string;
39
+ } | {
40
+ readonly via: "under_way";
41
+ readonly deploymentId: string | null;
42
+ readonly commit: string;
43
+ };
44
+ /**
45
+ * Puts, on the next stage of the pipeline, the commit the environment
46
+ * `fromEnvironmentId` serves. A stage that tracks an `env/<name>` branch gets
47
+ * it by a push of that branch, which AntelopeJS Cloud deploys; a stage that
48
+ * tracks no branch, or whose branch on origin holds the commit already, gets
49
+ * it from AntelopeJS Cloud directly, unless a deployment of it is under way or
50
+ * an earlier promotion pushed it and AntelopeJS Cloud has not started it yet.
51
+ * What the next stage serves keeps the traffic until the new version passes
52
+ * its health check. Promotions that push run one after the other, and none
53
+ * while a publish runs.
54
+ *
55
+ * @throws The refusal of an environment that is the last stage, outside the
56
+ * pipeline, or that serves no version a full commit id names; of a next stage
57
+ * that tracks a branch other than its own `env/<name>`, or one another
58
+ * environment tracks too, or that serves the commit already; and of a branch
59
+ * the repository cannot move on origin.
60
+ */
61
+ export declare function promote(tenantId: string, fromEnvironmentId: string): Promise<PromotionAnswer>;
62
+ declare const newEnvironmentSchema: z.ZodObject<{
63
+ name: z.ZodString;
64
+ branch: z.ZodOptional<z.ZodNullable<z.ZodString>>;
65
+ cloneFrom: z.ZodOptional<z.ZodNullable<z.ZodString>>;
66
+ }, "strip", z.ZodTypeAny, {
67
+ name: string;
68
+ branch?: string | null | undefined;
69
+ cloneFrom?: string | null | undefined;
70
+ }, {
71
+ name: string;
72
+ branch?: string | null | undefined;
73
+ cloneFrom?: string | null | undefined;
74
+ }>;
75
+ /** What the New environment dialog sends. */
76
+ export type NewEnvironmentInput = z.infer<typeof newEnvironmentSchema>;
77
+ /** Reads the body of the New environment dialog. */
78
+ export declare function parseNewEnvironment(body: Parameters<typeof newEnvironmentSchema.safeParse>[0]): NewEnvironmentInput | undefined;
79
+ /**
80
+ * Creates an environment in the project, building `env/<name>` unless the
81
+ * dialog names another branch, and copying the services of `cloneFrom`.
82
+ */
83
+ export declare function createEnvironment(tenantId: string, input: NewEnvironmentInput | undefined): Promise<void>;
84
+ /** Deletes an environment of the project. AntelopeJS Cloud refuses a protected one. */
85
+ export declare function deleteEnvironment(tenantId: string, environmentId: string): Promise<void>;
86
+ export {};
@@ -0,0 +1,210 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readEnvironments = readEnvironments;
4
+ exports.listEnvironments = listEnvironments;
5
+ exports.parseEnvironmentId = parseEnvironmentId;
6
+ exports.promote = promote;
7
+ exports.parseNewEnvironment = parseNewEnvironment;
8
+ exports.createEnvironment = createEnvironment;
9
+ exports.deleteEnvironment = deleteEnvironment;
10
+ const zod_1 = require("zod");
11
+ const config_1 = require("../config");
12
+ const actions_1 = require("../connection/actions");
13
+ const announce_1 = require("../connection/announce");
14
+ const cloud_1 = require("../connection/cloud");
15
+ const current_1 = require("../connection/current");
16
+ const refusals_1 = require("../connection/refusals");
17
+ const promotion_1 = require("../git/promotion");
18
+ const refs_1 = require("../git/refs");
19
+ const write_lock_1 = require("../git/write-lock");
20
+ const slug_1 = require("../slug");
21
+ const follower_1 = require("./follower");
22
+ const pipeline_1 = require("./pipeline");
23
+ const NO_PROJECT = (0, refusals_1.conflict)("no_project");
24
+ const ENVIRONMENT_REQUIRED = (0, refusals_1.badRequest)("environment_required");
25
+ const UNKNOWN_ENVIRONMENT = (0, refusals_1.unprocessable)("unknown_environment");
26
+ const NO_NEXT_STAGE = (0, refusals_1.conflict)("no_next_stage");
27
+ const NOTHING_TO_PROMOTE = (0, refusals_1.conflict)("nothing_to_promote");
28
+ const ENVIRONMENT_NAME_REQUIRED = (0, refusals_1.badRequest)("environment_name_required");
29
+ const ALREADY_SERVING = (0, refusals_1.conflict)("already_serving");
30
+ const UNDER_WAY = new Set([
31
+ "queued",
32
+ "building",
33
+ "checking",
34
+ "switching",
35
+ ]);
36
+ const ENVIRONMENT_REFUSALS = {
37
+ missing: UNKNOWN_ENVIRONMENT,
38
+ codes: new Map([
39
+ [
40
+ "cloud.errors.limits.environments_per_project",
41
+ (0, refusals_1.conflict)("environment_limit"),
42
+ ],
43
+ [
44
+ "cloud.errors.project.environment_protected",
45
+ (0, refusals_1.conflict)("environment_protected"),
46
+ ],
47
+ [
48
+ "cloud.errors.project.environment_name_taken",
49
+ (0, refusals_1.conflict)("environment_name_taken"),
50
+ ],
51
+ [
52
+ "cloud.errors.project.invalid_environment_name",
53
+ (0, refusals_1.badRequest)("invalid_environment_name"),
54
+ ],
55
+ ["cloud.errors.project.invalid_branch", (0, refusals_1.badRequest)("invalid_branch")],
56
+ ["cloud.errors.promotion.no_repository", (0, refusals_1.conflict)("no_repository")],
57
+ [
58
+ "cloud.errors.promotion.no_target_services",
59
+ (0, refusals_1.conflict)("no_target_services"),
60
+ ],
61
+ ["cloud.errors.promotion.commit_not_found", (0, refusals_1.conflict)("commit_not_found")],
62
+ ["cloud.errors.promotion.invalid", (0, refusals_1.badRequest)("invalid_promotion")],
63
+ ]),
64
+ };
65
+ async function linkedProject(tenantId) {
66
+ const stored = await (0, current_1.readConnection)(tenantId);
67
+ if (stored?.state !== "connected")
68
+ throw (0, refusals_1.refuse)(refusals_1.NOT_CONNECTED);
69
+ if (stored.projectId === null)
70
+ throw (0, refusals_1.refuse)(NO_PROJECT);
71
+ return { connection: stored, projectId: stored.projectId };
72
+ }
73
+ /**
74
+ * The environments of the project a stored connection publishes, as
75
+ * AntelopeJS Cloud lists them: `undefined` without a signed-in workspace and
76
+ * its project.
77
+ */
78
+ async function readEnvironments(stored) {
79
+ if (stored?.state !== "connected" || stored.projectId === null) {
80
+ return undefined;
81
+ }
82
+ const { projectId } = stored;
83
+ return (0, cloud_1.readCloud)(stored, (api) => api.environments.list(projectId));
84
+ }
85
+ function callProject({ connection, projectId }, call, refusals) {
86
+ return (0, refusals_1.callOrRefuse)(connection, (api) => call(api, projectId), refusals);
87
+ }
88
+ /**
89
+ * The environments of the project the tenant publishes, as AntelopeJS Cloud
90
+ * lists them.
91
+ *
92
+ * @throws The refusal of a tenant without a project, or of a failed read.
93
+ */
94
+ async function listEnvironments(tenantId) {
95
+ return callProject(await linkedProject(tenantId), (api, projectId) => api.environments.list(projectId), actions_1.PROJECT_REFUSALS);
96
+ }
97
+ /**
98
+ * Reads the environment a row action names in its `environment` query
99
+ * parameter.
100
+ *
101
+ * @throws The refusal of a request that names none.
102
+ */
103
+ function parseEnvironmentId(raw) {
104
+ const parsed = zod_1.z.string().min(1).safeParse(raw);
105
+ if (!parsed.success)
106
+ throw (0, refusals_1.refuse)(ENVIRONMENT_REQUIRED);
107
+ return parsed.data;
108
+ }
109
+ async function deployThroughCloud(project, environmentId, commit) {
110
+ const receipt = await callProject(project, (api, projectId) => api.environments.promote(projectId, environmentId, { commit }), ENVIRONMENT_REFUSALS);
111
+ return { via: "cloud", ...receipt };
112
+ }
113
+ async function deployHeldCommit(project, environmentId, commit) {
114
+ const { serving, target } = await callProject(project, (api, projectId) => api.environments.read(projectId, environmentId), ENVIRONMENT_REFUSALS);
115
+ if (serving?.commit === commit)
116
+ throw (0, refusals_1.refuse)(ALREADY_SERVING);
117
+ if (target?.commit === commit) {
118
+ return UNDER_WAY.has(target.status)
119
+ ? { via: "under_way", deploymentId: target.id, commit }
120
+ : deployThroughCloud(project, environmentId, commit);
121
+ }
122
+ return (0, follower_1.isFollowing)(project.connection._id, environmentId, commit)
123
+ ? { via: "under_way", deploymentId: null, commit }
124
+ : deployThroughCloud(project, environmentId, commit);
125
+ }
126
+ function isFollowedAlready(answer) {
127
+ return answer.via === "under_way" && answer.deploymentId === null;
128
+ }
129
+ async function reachNextStage(project, environments, to, commit) {
130
+ const route = (0, pipeline_1.promotionRoute)(to, environments);
131
+ if (route.kind === "refused")
132
+ throw (0, refusals_1.refuse)((0, refusals_1.conflict)(route.refusal));
133
+ if (route.kind === "cloud")
134
+ return deployThroughCloud(project, to.id, commit);
135
+ const { environment } = route;
136
+ return (0, write_lock_1.inPromotionTurn)(async () => {
137
+ const move = await (0, promotion_1.moveEnvironmentBranch)((0, config_1.cloudSettings)().repositoryPath, environment, commit);
138
+ if (move.kind === "refused")
139
+ throw (0, refusals_1.refuse)((0, refusals_1.conflict)(move.refusal));
140
+ if (move.kind === "held")
141
+ return deployHeldCommit(project, to.id, commit);
142
+ return { via: "push", branch: (0, refs_1.environmentBranch)(environment), commit };
143
+ });
144
+ }
145
+ /**
146
+ * Puts, on the next stage of the pipeline, the commit the environment
147
+ * `fromEnvironmentId` serves. A stage that tracks an `env/<name>` branch gets
148
+ * it by a push of that branch, which AntelopeJS Cloud deploys; a stage that
149
+ * tracks no branch, or whose branch on origin holds the commit already, gets
150
+ * it from AntelopeJS Cloud directly, unless a deployment of it is under way or
151
+ * an earlier promotion pushed it and AntelopeJS Cloud has not started it yet.
152
+ * What the next stage serves keeps the traffic until the new version passes
153
+ * its health check. Promotions that push run one after the other, and none
154
+ * while a publish runs.
155
+ *
156
+ * @throws The refusal of an environment that is the last stage, outside the
157
+ * pipeline, or that serves no version a full commit id names; of a next stage
158
+ * that tracks a branch other than its own `env/<name>`, or one another
159
+ * environment tracks too, or that serves the commit already; and of a branch
160
+ * the repository cannot move on origin.
161
+ */
162
+ async function promote(tenantId, fromEnvironmentId) {
163
+ const project = await linkedProject(tenantId);
164
+ const environments = await callProject(project, (api, projectId) => api.environments.list(projectId), actions_1.PROJECT_REFUSALS);
165
+ const from = environments.find(({ id }) => id === fromEnvironmentId);
166
+ if (!from)
167
+ throw (0, refusals_1.refuse)(UNKNOWN_ENVIRONMENT);
168
+ const to = (0, pipeline_1.promotionTarget)(environments, from.id);
169
+ if (!to)
170
+ throw (0, refusals_1.refuse)(NO_NEXT_STAGE);
171
+ const commit = (0, refs_1.commitId)(from.serving?.commit);
172
+ if (!commit)
173
+ throw (0, refusals_1.refuse)(NOTHING_TO_PROMOTE);
174
+ const answer = await reachNextStage(project, environments, to, commit);
175
+ if (!isFollowedAlready(answer))
176
+ (0, follower_1.followPromotion)(tenantId, to, commit);
177
+ await (0, announce_1.announceProject)(tenantId);
178
+ return answer;
179
+ }
180
+ const newEnvironmentSchema = zod_1.z.object({
181
+ name: zod_1.z.string().trim().min(1),
182
+ branch: zod_1.z.string().trim().nullish(),
183
+ cloneFrom: zod_1.z.string().nullish(),
184
+ });
185
+ /** Reads the body of the New environment dialog. */
186
+ function parseNewEnvironment(body) {
187
+ return newEnvironmentSchema.safeParse(body).data;
188
+ }
189
+ /**
190
+ * Creates an environment in the project, building `env/<name>` unless the
191
+ * dialog names another branch, and copying the services of `cloneFrom`.
192
+ */
193
+ async function createEnvironment(tenantId, input) {
194
+ if (!input)
195
+ throw (0, refusals_1.refuse)(ENVIRONMENT_NAME_REQUIRED);
196
+ const project = await linkedProject(tenantId);
197
+ await callProject(project, (api, projectId) => api.environments.create(projectId, {
198
+ name: input.name,
199
+ branch: input.branch || (0, pipeline_1.defaultBranch)((0, slug_1.slugify)(input.name)),
200
+ cloneFrom: input.cloneFrom || null,
201
+ }), ENVIRONMENT_REFUSALS);
202
+ await (0, announce_1.announceProject)(tenantId);
203
+ }
204
+ /** Deletes an environment of the project. AntelopeJS Cloud refuses a protected one. */
205
+ async function deleteEnvironment(tenantId, environmentId) {
206
+ const project = await linkedProject(tenantId);
207
+ await callProject(project, (api, projectId) => api.environments.delete(projectId, environmentId), ENVIRONMENT_REFUSALS);
208
+ await (0, announce_1.announceProject)(tenantId);
209
+ }
210
+ //# sourceMappingURL=actions.js.map
@@ -0,0 +1,60 @@
1
+ import type { CloudApi, EnvironmentDetail } from "@antelopejs/cloud-sdk";
2
+ import type { ConfirmDialogSerialized } from "@antelopejs/interface-dms/base/types/confirm-dialog";
3
+ import { type CloudRefusals } from "../connection/refusals";
4
+ import { type ProjectConfig } from "../variables/project-config";
5
+ /**
6
+ * The address the project's app can get on AntelopeJS Cloud, as its
7
+ * `antelope.config.ts` allows: an internet-reachable one on the port its API
8
+ * answers on (`public`), none because the file names no such port
9
+ * (`no_port`), or none because AntelopeJS Cloud runs apps on ports 1024 to
10
+ * 65535 only (`port_out_of_range`).
11
+ */
12
+ export type AppAddress = {
13
+ readonly kind: "public";
14
+ readonly port: number;
15
+ } | {
16
+ readonly kind: "no_port";
17
+ } | {
18
+ readonly kind: "port_out_of_range";
19
+ readonly port: number;
20
+ };
21
+ /** The address the app of a project with this config can get. */
22
+ export declare function appAddressOf(config: ProjectConfig): AppAddress;
23
+ /**
24
+ * What opening an environment did: its app got its port and its address
25
+ * (`opened`), it had an address already (`existing`), or it runs no app
26
+ * service or several, so none can be told to be the public one
27
+ * (`not_one_app`). The dashboard of the project is not an app service: an
28
+ * environment that runs the API and its dashboard has one app.
29
+ */
30
+ export type OpenOutcome = "opened" | "existing" | "not_one_app";
31
+ /** How a page refuses a failed opening of an environment. */
32
+ export declare const ADDRESS_REFUSALS: CloudRefusals;
33
+ /**
34
+ * Gives an environment without an address one: sets the port its one app
35
+ * service listens on, then opens that service to the internet. Both writes
36
+ * can be sent again, so a run after a lost answer finishes the opening. An
37
+ * environment that has an address is left as it is, whatever its port.
38
+ *
39
+ * @param environment The environment as AntelopeJS Cloud lists it now
40
+ * @param port The port the app answers on
41
+ * @throws The `CloudApiError` of a write AntelopeJS Cloud refuses
42
+ */
43
+ export declare function openEnvironment(api: CloudApi, projectId: string, environment: EnvironmentDetail, port: number): Promise<OpenOutcome>;
44
+ /**
45
+ * The dialog that gives an environment its address: what it sets on
46
+ * AntelopeJS Cloud and who can reach the app afterwards, or why it cannot.
47
+ *
48
+ * @param name The environment's name, `undefined` when the project has none such any more
49
+ */
50
+ export declare function addressDialog(name: string | undefined, address: AppAddress): ConfirmDialogSerialized;
51
+ /**
52
+ * Gives an environment of the project the tenant publishes its address, on
53
+ * the port the project's config gives its API. The tenant's open pages then
54
+ * read the project again.
55
+ *
56
+ * @throws The refusal of a config that names no usable port, of an
57
+ * environment the project lacks, of one that runs no app or several, or of
58
+ * a write AntelopeJS Cloud refuses.
59
+ */
60
+ export declare function giveAddress(tenantId: string, environmentId: string): Promise<void>;
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ADDRESS_REFUSALS = void 0;
4
+ exports.appAddressOf = appAddressOf;
5
+ exports.openEnvironment = openEnvironment;
6
+ exports.addressDialog = addressDialog;
7
+ exports.giveAddress = giveAddress;
8
+ const confirm_dialog_1 = require("@antelopejs/interface-dms/base/confirm-dialog");
9
+ const announce_1 = require("../connection/announce");
10
+ const current_1 = require("../connection/current");
11
+ const refusals_1 = require("../connection/refusals");
12
+ const project_config_1 = require("../variables/project-config");
13
+ const pipeline_1 = require("./pipeline");
14
+ const roles_1 = require("./roles");
15
+ const MIN_PORT = 1024;
16
+ const MAX_PORT = 65_535;
17
+ /** The address the app of a project with this config can get. */
18
+ function appAddressOf(config) {
19
+ const port = (0, project_config_1.apiHttpPort)(config);
20
+ if (port === null)
21
+ return { kind: "no_port" };
22
+ const isUsable = Number.isInteger(port) && port >= MIN_PORT && port <= MAX_PORT;
23
+ return isUsable
24
+ ? { kind: "public", port }
25
+ : { kind: "port_out_of_range", port };
26
+ }
27
+ /** How a page refuses a failed opening of an environment. */
28
+ exports.ADDRESS_REFUSALS = {
29
+ missing: (0, refusals_1.unprocessable)("unknown_environment"),
30
+ codes: new Map([
31
+ ["cloud.errors.settings.invalid_port", (0, refusals_1.badRequest)("app_port_refused")],
32
+ ["cloud.errors.settings.public_needs_port", (0, refusals_1.conflict)("app_needs_port")],
33
+ ["cloud.errors.settings.subdomain_taken", (0, refusals_1.conflict)("app_address_taken")],
34
+ ["cloud.errors.settings.preview_read_only", (0, refusals_1.conflict)("preview_read_only")],
35
+ ]),
36
+ };
37
+ /**
38
+ * Whether the address an environment answers on is its app's. With no
39
+ * dashboard it is: only an app service is open to the internet. With one, the
40
+ * address may be the dashboard's alone, so the app's own is read; when the
41
+ * app cannot be told, the environment is left as it is.
42
+ */
43
+ async function isAppOpen(api, projectId, environment, roles) {
44
+ if (environment.url === null)
45
+ return false;
46
+ const app = (0, roles_1.appOf)(roles);
47
+ if (roles.dashboard === null || app === null)
48
+ return true;
49
+ const project = await api.readProject(projectId);
50
+ return (0, roles_1.serviceAddress)(project, environment.id, app) !== null;
51
+ }
52
+ /**
53
+ * Gives an environment without an address one: sets the port its one app
54
+ * service listens on, then opens that service to the internet. Both writes
55
+ * can be sent again, so a run after a lost answer finishes the opening. An
56
+ * environment that has an address is left as it is, whatever its port.
57
+ *
58
+ * @param environment The environment as AntelopeJS Cloud lists it now
59
+ * @param port The port the app answers on
60
+ * @throws The `CloudApiError` of a write AntelopeJS Cloud refuses
61
+ */
62
+ async function openEnvironment(api, projectId, environment, port) {
63
+ const hasOneService = environment.services.length < 2;
64
+ if (environment.url !== null && hasOneService)
65
+ return "existing";
66
+ const roles = await (0, roles_1.serviceRolesOf)(api, projectId, environment);
67
+ if (await isAppOpen(api, projectId, environment, roles))
68
+ return "existing";
69
+ const serviceId = (0, roles_1.appOf)(roles);
70
+ if (serviceId === null)
71
+ return "not_one_app";
72
+ await api.setServicePort(serviceId, port);
73
+ await api.setServiceExposure(serviceId, true);
74
+ return "opened";
75
+ }
76
+ const NOT_ONE_APP = (0, refusals_1.conflict)("app_not_single");
77
+ const NO_PROJECT = (0, refusals_1.conflict)("no_project");
78
+ const UNOPENABLE = {
79
+ no_port: {
80
+ refusal: (0, refusals_1.conflict)("app_port_unknown"),
81
+ description: "antelope.config.ts gives @antelopejs/api no http server with a port. Add one, then give the environment its address.",
82
+ },
83
+ port_out_of_range: {
84
+ refusal: (0, refusals_1.conflict)("app_port_out_of_range"),
85
+ description: "AntelopeJS Cloud runs apps on ports 1024 to 65535. Change the API's port in antelope.config.ts, then give the environment its address.",
86
+ },
87
+ };
88
+ /**
89
+ * The dialog that gives an environment its address: what it sets on
90
+ * AntelopeJS Cloud and who can reach the app afterwards, or why it cannot.
91
+ *
92
+ * @param name The environment's name, `undefined` when the project has none such any more
93
+ */
94
+ function addressDialog(name, address) {
95
+ if (name === undefined) {
96
+ return (0, confirm_dialog_1.serializeConfirmDialog)({
97
+ title: "This environment is gone",
98
+ description: "AntelopeJS Cloud no longer lists it in this project.",
99
+ blocked: true,
100
+ });
101
+ }
102
+ const label = (0, pipeline_1.environmentLabel)(name);
103
+ if (address.kind !== "public") {
104
+ return (0, confirm_dialog_1.serializeConfirmDialog)({
105
+ title: `${label} can't get an address yet`,
106
+ description: UNOPENABLE[address.kind].description,
107
+ blocked: true,
108
+ });
109
+ }
110
+ return (0, confirm_dialog_1.serializeConfirmDialog)({
111
+ title: `Give ${label} an address?`,
112
+ description: `AntelopeJS Cloud sets its app to listen on port ${address.port}, the API's port in antelope.config.ts, and opens it to the internet on an address of its own. Anyone who has the address can reach the app. The next deployment answers there.`,
113
+ icon: "i-ph-globe",
114
+ confirmLabel: "Open to the internet",
115
+ });
116
+ }
117
+ /**
118
+ * Gives an environment of the project the tenant publishes its address, on
119
+ * the port the project's config gives its API. The tenant's open pages then
120
+ * read the project again.
121
+ *
122
+ * @throws The refusal of a config that names no usable port, of an
123
+ * environment the project lacks, of one that runs no app or several, or of
124
+ * a write AntelopeJS Cloud refuses.
125
+ */
126
+ async function giveAddress(tenantId, environmentId) {
127
+ const stored = await (0, current_1.readConnection)(tenantId);
128
+ if (stored?.state !== "connected")
129
+ throw (0, refusals_1.refuse)(refusals_1.NOT_CONNECTED);
130
+ const { projectId } = stored;
131
+ if (projectId === null)
132
+ throw (0, refusals_1.refuse)(NO_PROJECT);
133
+ const address = appAddressOf(await (0, project_config_1.readProjectConfig)());
134
+ if (address.kind !== "public")
135
+ throw (0, refusals_1.refuse)(UNOPENABLE[address.kind].refusal);
136
+ const outcome = await (0, refusals_1.callOrRefuse)(stored, async (api) => {
137
+ const environments = await api.environments.list(projectId);
138
+ const environment = environments.find(({ id }) => id === environmentId);
139
+ return environment
140
+ ? openEnvironment(api, projectId, environment, address.port)
141
+ : "missing";
142
+ }, exports.ADDRESS_REFUSALS);
143
+ if (outcome === "missing")
144
+ throw (0, refusals_1.refuse)(exports.ADDRESS_REFUSALS.missing);
145
+ if (outcome === "not_one_app")
146
+ throw (0, refusals_1.refuse)(NOT_ONE_APP);
147
+ await (0, announce_1.announceProject)(tenantId);
148
+ }
149
+ //# sourceMappingURL=address.js.map