@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,165 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ConnectionModel = exports.SCHEMA_NAME = void 0;
13
+ exports.connections = connections;
14
+ const interface_database_1 = require("@antelopejs/interface-database");
15
+ const interface_database_decorators_1 = require("@antelopejs/interface-database-decorators");
16
+ const zod_1 = require("zod");
17
+ /** The database schema the module owns. */
18
+ exports.SCHEMA_NAME = "antelope-cloud";
19
+ const CONNECTIONS_TABLE = "connections";
20
+ const sealedSchema = zod_1.z.object({
21
+ iv: zod_1.z.string(),
22
+ tag: zod_1.z.string(),
23
+ data: zod_1.z.string(),
24
+ });
25
+ const FAILURE_REASONS = ["denied", "expired"];
26
+ const pendingSchema = zod_1.z.object({
27
+ _id: zod_1.z.string(),
28
+ state: zod_1.z.literal("pending"),
29
+ device: sealedSchema,
30
+ userCode: zod_1.z.string(),
31
+ verificationUri: zod_1.z.string(),
32
+ verificationUriComplete: zod_1.z.string(),
33
+ expiresAt: zod_1.z.date(),
34
+ intervalS: zod_1.z.number(),
35
+ startedBy: zod_1.z.string(),
36
+ startedAt: zod_1.z.date(),
37
+ });
38
+ const connectedSchema = zod_1.z.object({
39
+ _id: zod_1.z.string(),
40
+ state: zod_1.z.literal("connected"),
41
+ token: sealedSchema,
42
+ workspaceId: zod_1.z.string(),
43
+ workspaceName: zod_1.z.string().nullable(),
44
+ projectId: zod_1.z.string().nullable(),
45
+ connectedBy: zod_1.z.string(),
46
+ connectedAt: zod_1.z.date(),
47
+ });
48
+ const failedSchema = zod_1.z.object({
49
+ _id: zod_1.z.string(),
50
+ state: zod_1.z.literal("failed"),
51
+ reason: zod_1.z.enum(FAILURE_REASONS),
52
+ at: zod_1.z.date(),
53
+ });
54
+ const storedConnectionSchema = zod_1.z.discriminatedUnion("state", [
55
+ pendingSchema,
56
+ connectedSchema,
57
+ failedSchema,
58
+ ]);
59
+ let ConnectionRow = class ConnectionRow extends interface_database_decorators_1.Table {
60
+ };
61
+ __decorate([
62
+ (0, interface_database_decorators_1.Field)("string"),
63
+ __metadata("design:type", Object)
64
+ ], ConnectionRow.prototype, "state", void 0);
65
+ __decorate([
66
+ (0, interface_database_decorators_1.Field)({ iv: "string", tag: "string", data: "string" }),
67
+ __metadata("design:type", Object)
68
+ ], ConnectionRow.prototype, "device", void 0);
69
+ __decorate([
70
+ (0, interface_database_decorators_1.Field)({ iv: "string", tag: "string", data: "string" }),
71
+ __metadata("design:type", Object)
72
+ ], ConnectionRow.prototype, "token", void 0);
73
+ __decorate([
74
+ (0, interface_database_decorators_1.Field)("number"),
75
+ __metadata("design:type", Number)
76
+ ], ConnectionRow.prototype, "intervalS", void 0);
77
+ __decorate([
78
+ (0, interface_database_decorators_1.Field)("string"),
79
+ __metadata("design:type", Object)
80
+ ], ConnectionRow.prototype, "projectId", void 0);
81
+ ConnectionRow = __decorate([
82
+ (0, interface_database_decorators_1.RegisterTable)(CONNECTIONS_TABLE, exports.SCHEMA_NAME)
83
+ ], ConnectionRow);
84
+ /** Reads and writes the connection of each tenant. */
85
+ class ConnectionModel extends (0, interface_database_decorators_1.BasicDataModel)(ConnectionRow, CONNECTIONS_TABLE) {
86
+ /** The tenant's connection, or `undefined` when it has none. */
87
+ async read(tenantId) {
88
+ const row = await this.table.get(tenantId).run();
89
+ return row ? storedConnectionSchema.parse(row) : undefined;
90
+ }
91
+ /** Every device sign-in still waiting, whatever its tenant. */
92
+ async pending() {
93
+ const rows = await this.table
94
+ .filter((row) => row.key("state").eq("pending"))
95
+ .run();
96
+ return rows.map((row) => pendingSchema.parse(row));
97
+ }
98
+ /**
99
+ * Stores the tenant's new device sign-in in place of a pending or failed
100
+ * one, or of the sign-in whose token is `revokedToken`. A tenant signed in
101
+ * otherwise keeps its sign-in.
102
+ *
103
+ * @returns Whether the sign-in was stored.
104
+ */
105
+ async startFlow(pending, revokedToken) {
106
+ try {
107
+ await this.table.insert(pending).run();
108
+ return true;
109
+ }
110
+ catch (error) {
111
+ if (!(0, interface_database_1.IsDuplicateKeyError)(error))
112
+ throw error;
113
+ }
114
+ const replaced = await this.table
115
+ .filter((row) => {
116
+ const unconnected = row.key("state").ne("connected");
117
+ const replaceable = revokedToken
118
+ ? unconnected.or(row.key("token").key("data").eq(revokedToken.data))
119
+ : unconnected;
120
+ return row.key("_id").eq(pending._id).and(replaceable);
121
+ })
122
+ .replace(pending)
123
+ .run();
124
+ return replaced > 0;
125
+ }
126
+ /**
127
+ * Replaces the tenant's document with `next`, only while it is the pending
128
+ * sign-in of `device`: a sign-in cancelled or started again meanwhile keeps
129
+ * its result.
130
+ */
131
+ async settleFlow(device, next) {
132
+ await this.flow(next._id, device).replace(next).run();
133
+ }
134
+ /** Sets the polling interval of the tenant's pending sign-in of `device`. */
135
+ async slowFlow(tenantId, device, intervalS) {
136
+ await this.flow(tenantId, device).update({ intervalS }).run();
137
+ }
138
+ /** Sets the project of the tenant's connection, `null` for none, while it is signed in. */
139
+ async setProject(tenantId, projectId) {
140
+ await this.table
141
+ .filter((row) => row.key("_id").eq(tenantId).and(row.key("state").eq("connected")))
142
+ .update({ projectId })
143
+ .run();
144
+ }
145
+ /** Deletes the tenant's sign-in when it is pending or failed. */
146
+ async removeUnconnected(tenantId) {
147
+ await this.table
148
+ .filter((row) => row.key("_id").eq(tenantId).and(row.key("state").ne("connected")))
149
+ .delete()
150
+ .run();
151
+ }
152
+ flow(tenantId, device) {
153
+ return this.table.filter((row) => row
154
+ .key("_id")
155
+ .eq(tenantId)
156
+ .and(row.key("state").eq("pending"))
157
+ .and(row.key("device").key("data").eq(device.data)));
158
+ }
159
+ }
160
+ exports.ConnectionModel = ConnectionModel;
161
+ /** The connection model of the module's schema. */
162
+ function connections() {
163
+ return (0, interface_database_decorators_1.GetModel)(ConnectionModel);
164
+ }
165
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1,39 @@
1
+ import { type CurrentConnection } from "./current";
2
+ import type { FailureReason } from "./store";
3
+ /**
4
+ * What the Connection page may know of a tenant's connection: the stored
5
+ * document without its secrets.
6
+ */
7
+ export type ConnectionView = {
8
+ state: "disconnected";
9
+ } | {
10
+ state: "pending";
11
+ userCode: string;
12
+ verificationUri: string;
13
+ verificationUriComplete: string;
14
+ startedAt: Date;
15
+ expiresAt: Date;
16
+ } | {
17
+ state: "failed";
18
+ reason: FailureReason;
19
+ } | {
20
+ state: "connected";
21
+ managed: false;
22
+ workspace: {
23
+ id: string;
24
+ name: string | null;
25
+ };
26
+ projectId: string | null;
27
+ connectedBy: string;
28
+ connectedAt: Date;
29
+ } | {
30
+ /** Connected by AntelopeJS Cloud itself, to the one project its token reaches. */
31
+ state: "connected";
32
+ managed: true;
33
+ projectId: string;
34
+ };
35
+ /**
36
+ * The view of a stored connection at `now`. A sign-in still pending past its
37
+ * expiry reads as expired, before the poller records it.
38
+ */
39
+ export declare function toView(stored: CurrentConnection | undefined, now: Date): ConnectionView;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toView = toView;
4
+ const current_1 = require("./current");
5
+ /**
6
+ * The view of a stored connection at `now`. A sign-in still pending past its
7
+ * expiry reads as expired, before the poller records it.
8
+ */
9
+ function toView(stored, now) {
10
+ if (!stored)
11
+ return { state: "disconnected" };
12
+ if (stored.state === "failed") {
13
+ return { state: "failed", reason: stored.reason };
14
+ }
15
+ if (stored.state === "pending") {
16
+ if (stored.expiresAt <= now)
17
+ return { state: "failed", reason: "expired" };
18
+ return {
19
+ state: "pending",
20
+ userCode: stored.userCode,
21
+ verificationUri: stored.verificationUri,
22
+ verificationUriComplete: stored.verificationUriComplete,
23
+ startedAt: stored.startedAt,
24
+ expiresAt: stored.expiresAt,
25
+ };
26
+ }
27
+ if ((0, current_1.isManaged)(stored)) {
28
+ return { state: "connected", managed: true, projectId: stored.projectId };
29
+ }
30
+ return {
31
+ state: "connected",
32
+ managed: false,
33
+ workspace: { id: stored.workspaceId, name: stored.workspaceName },
34
+ projectId: stored.projectId,
35
+ connectedBy: stored.connectedBy,
36
+ connectedAt: stored.connectedAt,
37
+ };
38
+ }
39
+ //# sourceMappingURL=view.js.map
@@ -0,0 +1,40 @@
1
+ import type { EnvironmentDetail } from "@antelopejs/cloud-sdk";
2
+ import type { ConfirmDialogSerialized } from "@antelopejs/interface-dms/base/types/confirm-dialog";
3
+ import { type DashboardBuild } from "./dockerfile";
4
+ import { type EnvironmentAddresses } from "./service";
5
+ /**
6
+ * What the Environments page shows of the dashboards: where the app and the
7
+ * dashboard of each environment answer, and whether the project has a
8
+ * dashboard to add where an environment runs none.
9
+ */
10
+ export interface Dashboards {
11
+ /** By environment id; an environment AntelopeJS Cloud did not answer for has no entry. */
12
+ readonly addresses: ReadonlyMap<string, EnvironmentAddresses>;
13
+ /** Whether the work tree the module publishes has `frontend.Dockerfile`. */
14
+ readonly hasDockerfile: boolean;
15
+ }
16
+ /**
17
+ * Reads the dashboards of the tenant's environments. When AntelopeJS Cloud
18
+ * does not answer, the addresses are left out: the page then shows the
19
+ * environments as AntelopeJS Cloud listed them, and offers no dashboard.
20
+ */
21
+ export declare function readDashboards(tenantId: string, environments: readonly EnvironmentDetail[]): Promise<Dashboards>;
22
+ /**
23
+ * The dialog that gives an environment its dashboard: what it creates on
24
+ * AntelopeJS Cloud and who can reach it afterwards, or why it cannot.
25
+ *
26
+ * @param name The environment's name, `undefined` when the project has none such any more
27
+ * @param build How the work tree builds the dashboard, `null` without a `frontend.Dockerfile`
28
+ */
29
+ export declare function dashboardDialog(name: string | undefined, build: DashboardBuild | null): ConfirmDialogSerialized;
30
+ /**
31
+ * Gives an environment of the project the tenant publishes its dashboard,
32
+ * built by the `frontend.Dockerfile` of the work tree the module publishes.
33
+ * The tenant's open pages then read the project again.
34
+ *
35
+ * @throws The refusal of a work tree without that Dockerfile or with one
36
+ * that exposes a port AntelopeJS Cloud runs no service on, of a repository
37
+ * without a GitHub remote, of an environment the project lacks, or of a
38
+ * write AntelopeJS Cloud refuses.
39
+ */
40
+ export declare function addDashboard(tenantId: string, environmentId: string): Promise<void>;
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readDashboards = readDashboards;
4
+ exports.dashboardDialog = dashboardDialog;
5
+ exports.addDashboard = addDashboard;
6
+ const confirm_dialog_1 = require("@antelopejs/interface-dms/base/confirm-dialog");
7
+ const announce_1 = require("../connection/announce");
8
+ const cloud_1 = require("../connection/cloud");
9
+ const current_1 = require("../connection/current");
10
+ const refusals_1 = require("../connection/refusals");
11
+ const repository_1 = require("../connection/repository");
12
+ const pipeline_1 = require("../environments/pipeline");
13
+ const dockerfile_1 = require("./dockerfile");
14
+ const service_1 = require("./service");
15
+ const NO_PROJECT = (0, refusals_1.conflict)("no_project");
16
+ const NO_DOCKERFILE = (0, refusals_1.conflict)("dashboard_dockerfile_missing");
17
+ const PORT_OUT_OF_RANGE = (0, refusals_1.conflict)("dashboard_port_out_of_range");
18
+ const NO_GITHUB_REMOTE = (0, refusals_1.conflict)("no_github_remote");
19
+ /**
20
+ * Reads the dashboards of the tenant's environments. When AntelopeJS Cloud
21
+ * does not answer, the addresses are left out: the page then shows the
22
+ * environments as AntelopeJS Cloud listed them, and offers no dashboard.
23
+ */
24
+ async function readDashboards(tenantId, environments) {
25
+ const [stored, build] = await Promise.all([
26
+ (0, current_1.readConnection)(tenantId),
27
+ (0, dockerfile_1.readDashboardBuild)(),
28
+ ]);
29
+ const projectId = stored?.state === "connected" ? stored.projectId : null;
30
+ if (stored?.state !== "connected" || projectId === null) {
31
+ return { addresses: new Map(), hasDockerfile: build !== null };
32
+ }
33
+ const read = await (0, cloud_1.readCloud)(stored, (api) => (0, service_1.readAddresses)(api, projectId, environments));
34
+ return {
35
+ addresses: read.kind === "ok" ? read.value : new Map(),
36
+ hasDockerfile: build !== null,
37
+ };
38
+ }
39
+ /**
40
+ * The dialog that gives an environment its dashboard: what it creates on
41
+ * AntelopeJS Cloud and who can reach it afterwards, or why it cannot.
42
+ *
43
+ * @param name The environment's name, `undefined` when the project has none such any more
44
+ * @param build How the work tree builds the dashboard, `null` without a `frontend.Dockerfile`
45
+ */
46
+ function dashboardDialog(name, build) {
47
+ if (name === undefined) {
48
+ return (0, confirm_dialog_1.serializeConfirmDialog)({
49
+ title: "This environment is gone",
50
+ description: "AntelopeJS Cloud no longer lists it in this project.",
51
+ blocked: true,
52
+ });
53
+ }
54
+ const label = (0, pipeline_1.environmentLabel)(name);
55
+ if (build === null) {
56
+ return (0, confirm_dialog_1.serializeConfirmDialog)({
57
+ title: `${label} can't get a dashboard yet`,
58
+ description: `The repository has no ${dockerfile_1.DASHBOARD_DOCKERFILE} at its root. Add the one of the DMS starter, then add the dashboard.`,
59
+ blocked: true,
60
+ });
61
+ }
62
+ if (build.kind !== "public") {
63
+ return (0, confirm_dialog_1.serializeConfirmDialog)({
64
+ title: `${label} can't get a dashboard yet`,
65
+ description: `${dockerfile_1.DASHBOARD_DOCKERFILE} exposes port ${build.port}. AntelopeJS Cloud runs services on ports 1024 to 65535. Change its EXPOSE, then add the dashboard.`,
66
+ blocked: true,
67
+ });
68
+ }
69
+ return (0, confirm_dialog_1.serializeConfirmDialog)({
70
+ title: `Add the dashboard to ${label}?`,
71
+ description: `AntelopeJS Cloud creates a second service in ${label}, built from the repository by ${dockerfile_1.DASHBOARD_DOCKERFILE}. It listens on port ${build.port} and is open to the internet on an address of its own. The next version published to ${label} builds it.`,
72
+ icon: "i-ph-layout",
73
+ confirmLabel: "Add the dashboard",
74
+ });
75
+ }
76
+ /**
77
+ * Gives an environment of the project the tenant publishes its dashboard,
78
+ * built by the `frontend.Dockerfile` of the work tree the module publishes.
79
+ * The tenant's open pages then read the project again.
80
+ *
81
+ * @throws The refusal of a work tree without that Dockerfile or with one
82
+ * that exposes a port AntelopeJS Cloud runs no service on, of a repository
83
+ * without a GitHub remote, of an environment the project lacks, or of a
84
+ * write AntelopeJS Cloud refuses.
85
+ */
86
+ async function addDashboard(tenantId, environmentId) {
87
+ const stored = await (0, current_1.readConnection)(tenantId);
88
+ if (stored?.state !== "connected")
89
+ throw (0, refusals_1.refuse)(refusals_1.NOT_CONNECTED);
90
+ const { projectId } = stored;
91
+ if (projectId === null)
92
+ throw (0, refusals_1.refuse)(NO_PROJECT);
93
+ const [build, { remote }] = await Promise.all([
94
+ (0, dockerfile_1.readDashboardBuild)(),
95
+ (0, repository_1.readPublishedRepository)(),
96
+ ]);
97
+ if (build === null)
98
+ throw (0, refusals_1.refuse)(NO_DOCKERFILE);
99
+ if (build.kind !== "public")
100
+ throw (0, refusals_1.refuse)(PORT_OUT_OF_RANGE);
101
+ if (!remote?.webUrl)
102
+ throw (0, refusals_1.refuse)(NO_GITHUB_REMOTE);
103
+ const source = { projectId, repository: remote.label, port: build.port };
104
+ const outcome = await (0, refusals_1.callOrRefuse)(stored, async (api) => {
105
+ const environments = await api.environments.list(projectId);
106
+ const environment = environments.find(({ id }) => id === environmentId);
107
+ return environment
108
+ ? (0, service_1.ensureDashboard)(api, source, environment)
109
+ : "missing";
110
+ }, service_1.DASHBOARD_REFUSALS);
111
+ if (outcome === "missing")
112
+ throw (0, refusals_1.refuse)(service_1.DASHBOARD_REFUSALS.missing);
113
+ await (0, announce_1.announceProject)(tenantId);
114
+ }
115
+ //# sourceMappingURL=actions.js.map
@@ -0,0 +1,34 @@
1
+ /**
2
+ * The Dockerfile that builds the dashboard of a DMS project, at the root of
3
+ * its repository: the DMS starter's convention.
4
+ */
5
+ export declare const DASHBOARD_DOCKERFILE = "frontend.Dockerfile";
6
+ /**
7
+ * How the dashboard of the project is built on AntelopeJS Cloud: by
8
+ * `frontend.Dockerfile`, as a service that answers on the port it exposes
9
+ * (`public`), or not at all, the port being one AntelopeJS Cloud runs no
10
+ * service on (`port_out_of_range`).
11
+ */
12
+ export type DashboardBuild = {
13
+ readonly kind: "public";
14
+ readonly port: number;
15
+ } | {
16
+ readonly kind: "port_out_of_range";
17
+ readonly port: number;
18
+ };
19
+ /**
20
+ * The port a Dockerfile says its container listens on: the first port of its
21
+ * last `EXPOSE` instruction, as the last build stage is the one that runs.
22
+ * `null` when it exposes none as a number.
23
+ */
24
+ export declare function exposedPort(dockerfile: string): number | null;
25
+ /** How a dashboard that this Dockerfile builds runs on AntelopeJS Cloud. */
26
+ export declare function dashboardBuildOf(dockerfile: string): DashboardBuild;
27
+ /**
28
+ * How the dashboard of the project the module publishes is built: read from
29
+ * `frontend.Dockerfile` at the root of its work tree. `null` when the work
30
+ * tree has no such file: the project then has no dashboard to put online.
31
+ *
32
+ * @param repositoryPath Root of the work tree, the module's `repositoryPath` by default
33
+ */
34
+ export declare function readDashboardBuild(repositoryPath?: string): Promise<DashboardBuild | null>;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DASHBOARD_DOCKERFILE = void 0;
4
+ exports.exposedPort = exposedPort;
5
+ exports.dashboardBuildOf = dashboardBuildOf;
6
+ exports.readDashboardBuild = readDashboardBuild;
7
+ const promises_1 = require("node:fs/promises");
8
+ const node_path_1 = require("node:path");
9
+ const config_1 = require("../config");
10
+ /**
11
+ * The Dockerfile that builds the dashboard of a DMS project, at the root of
12
+ * its repository: the DMS starter's convention.
13
+ */
14
+ exports.DASHBOARD_DOCKERFILE = "frontend.Dockerfile";
15
+ /** The port `ajs-dms start` answers on when the Dockerfile states none. */
16
+ const DEFAULT_PORT = 3000;
17
+ const MIN_PORT = 1024;
18
+ const MAX_PORT = 65_535;
19
+ /** A Dockerfile is read up to this size: its `EXPOSE` is not looked for past it. */
20
+ const READ_LIMIT_BYTES = 256 * 1024;
21
+ const EXPOSE = /^[ \t]*EXPOSE[ \t]+(\d+)(?:\/tcp)?(?=[ \t\r]|$)/gim;
22
+ /**
23
+ * The port a Dockerfile says its container listens on: the first port of its
24
+ * last `EXPOSE` instruction, as the last build stage is the one that runs.
25
+ * `null` when it exposes none as a number.
26
+ */
27
+ function exposedPort(dockerfile) {
28
+ const ports = [...dockerfile.matchAll(EXPOSE)].map(([, port]) => Number(port));
29
+ return ports[ports.length - 1] ?? null;
30
+ }
31
+ /** How a dashboard that this Dockerfile builds runs on AntelopeJS Cloud. */
32
+ function dashboardBuildOf(dockerfile) {
33
+ const port = exposedPort(dockerfile) ?? DEFAULT_PORT;
34
+ return port >= MIN_PORT && port <= MAX_PORT
35
+ ? { kind: "public", port }
36
+ : { kind: "port_out_of_range", port };
37
+ }
38
+ async function readStart(path) {
39
+ let file;
40
+ try {
41
+ file = await (0, promises_1.open)(path, "r");
42
+ }
43
+ catch {
44
+ return null;
45
+ }
46
+ try {
47
+ if (!(await file.stat()).isFile())
48
+ return null;
49
+ const buffer = Buffer.alloc(READ_LIMIT_BYTES);
50
+ const { bytesRead } = await file.read(buffer, 0, READ_LIMIT_BYTES, 0);
51
+ return buffer.toString("utf8", 0, bytesRead);
52
+ }
53
+ catch {
54
+ return null;
55
+ }
56
+ finally {
57
+ await file.close();
58
+ }
59
+ }
60
+ /**
61
+ * How the dashboard of the project the module publishes is built: read from
62
+ * `frontend.Dockerfile` at the root of its work tree. `null` when the work
63
+ * tree has no such file: the project then has no dashboard to put online.
64
+ *
65
+ * @param repositoryPath Root of the work tree, the module's `repositoryPath` by default
66
+ */
67
+ async function readDashboardBuild(repositoryPath = (0, config_1.cloudSettings)().repositoryPath) {
68
+ const dockerfile = await readStart((0, node_path_1.join)(repositoryPath, exports.DASHBOARD_DOCKERFILE));
69
+ return dockerfile === null ? null : dashboardBuildOf(dockerfile);
70
+ }
71
+ //# sourceMappingURL=dockerfile.js.map
@@ -0,0 +1,61 @@
1
+ import type { CloudApi, EnvironmentDetail } from "@antelopejs/cloud-sdk";
2
+ import { type CloudRefusals } from "../connection/refusals";
3
+ /**
4
+ * What giving an environment its dashboard did: the service was created,
5
+ * built by `frontend.Dockerfile` and open to the internet (`created`); it
6
+ * existed without an address and got one (`opened`); or it existed with its
7
+ * address and is left as it is (`existing`).
8
+ */
9
+ export type DashboardOutcome = "created" | "opened" | "existing";
10
+ /** How a page refuses a failed creation or opening of a dashboard. */
11
+ export declare const DASHBOARD_REFUSALS: CloudRefusals;
12
+ /** What a dashboard is created from. */
13
+ export interface DashboardSource {
14
+ readonly projectId: string;
15
+ /** The repository AntelopeJS Cloud builds it from, as `owner/name`. */
16
+ readonly repository: string;
17
+ /** The port its container answers on. */
18
+ readonly port: number;
19
+ }
20
+ /**
21
+ * The application name a dashboard is created under, which is where its
22
+ * address starts: the project's name and `-dashboard` on Production, with
23
+ * the environment's name in between elsewhere, as AntelopeJS Cloud names the
24
+ * services it copies. The project's name is cut first, then a long
25
+ * environment name, so that the whole fits the length AntelopeJS Cloud takes
26
+ * and two environments of a project keep different names.
27
+ */
28
+ export declare function dashboardAppName(projectSlug: string, environmentName: string): string;
29
+ /**
30
+ * Gives an environment its dashboard: a second service that builds the
31
+ * project's repository with `frontend.Dockerfile`, answers on `port` and is
32
+ * open to the internet on its own address. An environment that runs a
33
+ * dashboard keeps it: one without an address gets its port and its address,
34
+ * one with an address is left as it is. Every write can be sent again, so a
35
+ * run after a lost answer finishes the work.
36
+ *
37
+ * @param environment The environment as AntelopeJS Cloud lists it now
38
+ * @throws The `CloudApiError` of a read or a write AntelopeJS Cloud refuses
39
+ */
40
+ export declare function ensureDashboard(api: CloudApi, { projectId, repository, port }: DashboardSource, environment: EnvironmentDetail): Promise<DashboardOutcome>;
41
+ /** Where the app and the dashboard of an environment answer. */
42
+ export interface EnvironmentAddresses {
43
+ /**
44
+ * The address of its one app service; `null` when it has none, or when the
45
+ * environment runs no app service or several.
46
+ */
47
+ readonly app: string | null;
48
+ /** The address of its dashboard, `null` when it runs none or it has no address. */
49
+ readonly dashboard: string | null;
50
+ /** Whether it runs a dashboard. */
51
+ readonly hasDashboard: boolean;
52
+ /** Whether its app services are one, so that "the app" names a service. */
53
+ readonly hasOneApp: boolean;
54
+ }
55
+ /**
56
+ * Reads where the app and the dashboard of each environment answer, by
57
+ * environment id.
58
+ *
59
+ * @throws The `CloudApiError` of a read AntelopeJS Cloud does not answer
60
+ */
61
+ export declare function readAddresses(api: CloudApi, projectId: string, environments: readonly EnvironmentDetail[]): Promise<Map<string, EnvironmentAddresses>>;