@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,155 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setDecided = setDecided;
4
+ const node_crypto_1 = require("node:crypto");
5
+ const cloud_sdk_1 = require("@antelopejs/cloud-sdk");
6
+ const interface_api_1 = require("@antelopejs/interface-api");
7
+ const current_1 = require("../connection/current");
8
+ const actions_1 = require("./actions");
9
+ const read_1 = require("./read");
10
+ const MESSAGE_KEY_PREFIX = "$dms_antelope_cloud.errors.";
11
+ const SECRET_BYTES = 32;
12
+ const NOT_CONNECTED = { status: 409, error: "not_connected" };
13
+ const NO_PROJECT = { status: 400, error: "project_required" };
14
+ const UNKNOWN_ENVIRONMENT = {
15
+ status: 422,
16
+ error: "unknown_environment",
17
+ };
18
+ const NOTHING_TO_DECIDE = { status: 409, error: "nothing_to_decide" };
19
+ /** How the action refuses when the project cannot be read. */
20
+ const UNREADABLE = {
21
+ disconnected: NOT_CONNECTED,
22
+ no_project: NO_PROJECT,
23
+ revoked: { status: 409, error: "sign_in_revoked" },
24
+ missing: { status: 422, error: "unknown_project" },
25
+ forbidden: { status: 409, error: "cloud_forbidden" },
26
+ unreachable: { status: 502, error: "cloud_unreachable" },
27
+ };
28
+ function refuse({ status, error }) {
29
+ return new interface_api_1.HTTPResult(status, {
30
+ error,
31
+ message: `${MESSAGE_KEY_PREFIX}${error}`,
32
+ });
33
+ }
34
+ /** A secret nobody chose: 32 random bytes, in hex. */
35
+ function generated() {
36
+ return (0, node_crypto_1.randomBytes)(SECRET_BYTES).toString("hex");
37
+ }
38
+ /**
39
+ * The values of a plan as they are sent, in the plan's order: each text as
40
+ * it is, one generated secret per group, and a generated setup token.
41
+ */
42
+ function valuesOf({ sets }) {
43
+ const groups = new Map();
44
+ return sets.map((planned) => {
45
+ const { content } = planned;
46
+ if (content.kind === "plain") {
47
+ return { planned, value: content.value, isSecret: false };
48
+ }
49
+ if (content.kind === "setup_token") {
50
+ return { planned, value: generated(), isSecret: true };
51
+ }
52
+ const value = groups.get(content.group) ?? generated();
53
+ groups.set(content.group, value);
54
+ return { planned, value, isSecret: true };
55
+ });
56
+ }
57
+ function groupOf({ planned }) {
58
+ return planned.content.kind === "secret" ? planned.content.group : null;
59
+ }
60
+ /**
61
+ * The order the values are sent in: those one service holds alone, then a
62
+ * secret several services share, one after the other, then the setup token.
63
+ * A shared secret is so half-written for the time of one request at most.
64
+ */
65
+ function inSendOrder(values) {
66
+ const members = new Map();
67
+ const firsts = new Map();
68
+ values.forEach((sent, index) => {
69
+ const group = groupOf(sent);
70
+ if (group === null)
71
+ return;
72
+ members.set(group, (members.get(group) ?? 0) + 1);
73
+ if (!firsts.has(group))
74
+ firsts.set(group, index);
75
+ });
76
+ const rank = (sent) => {
77
+ if (sent.planned.content.kind === "setup_token")
78
+ return 2;
79
+ return (members.get(groupOf(sent) ?? "") ?? 0) > 1 ? 1 : 0;
80
+ };
81
+ const together = (sent) => rank(sent) === 1 ? (firsts.get(groupOf(sent) ?? "") ?? 0) : 0;
82
+ return [...values].sort((left, right) => rank(left) - rank(right) || together(left) - together(right));
83
+ }
84
+ /**
85
+ * Takes back the members of a shared secret this run wrote, once another
86
+ * member of it was refused: a half-written group would leave two services
87
+ * with values nobody can match. A removal AntelopeJS Cloud refuses in turn
88
+ * is left for the person, who sees both rows.
89
+ */
90
+ async function takeBack(api, at, written, refused) {
91
+ const group = groupOf(refused);
92
+ if (group === null)
93
+ return;
94
+ for (const one of written.filter((sent) => groupOf(sent) === group)) {
95
+ const { serviceId, key } = one.planned;
96
+ try {
97
+ await api.deleteVariable(at.projectId, at.environmentId, serviceId, key);
98
+ }
99
+ catch (error) {
100
+ if (!(error instanceof cloud_sdk_1.CloudApiError))
101
+ throw error;
102
+ }
103
+ }
104
+ }
105
+ /**
106
+ * Sets the values AntelopeJS Cloud can decide on an environment of the
107
+ * project the tenant publishes: the addresses of its app and its dashboard,
108
+ * the header AntelopeJS Cloud's gateway sets, and the secrets the project
109
+ * owns, generated here and sent as secrets. The plan is computed from a new
110
+ * read, so a variable a service holds by then is left as it is. A generated
111
+ * secret is never logged nor stored, and none is answered but the setup
112
+ * token, once.
113
+ *
114
+ * @param environment The environment, by id or by name
115
+ * @throws The refusal of a tenant without a project, of an environment the
116
+ * project lacks, of one with nothing left to decide, or of a write
117
+ * AntelopeJS Cloud refuses
118
+ */
119
+ async function setDecided(tenantId, environment) {
120
+ const read = await (0, read_1.readVariables)(await (0, current_1.readConnection)(tenantId));
121
+ if (read.kind !== "ok")
122
+ throw refuse(UNREADABLE[read.kind]);
123
+ const decided = read.decided.find(({ environmentId, environmentName }) => environmentId === environment || environmentName === environment);
124
+ if (!decided)
125
+ throw refuse(UNKNOWN_ENVIRONMENT);
126
+ if (decided.plan.sets.length === 0)
127
+ throw refuse(NOTHING_TO_DECIDE);
128
+ const values = inSendOrder(valuesOf(decided.plan));
129
+ const { environmentId } = decided;
130
+ const written = [];
131
+ await (0, actions_1.write)(tenantId, async (api, projectId) => {
132
+ for (const sent of values) {
133
+ const { serviceId, key } = sent.planned;
134
+ const outcome = await (0, actions_1.send)(async () => {
135
+ await api.setVariable(projectId, environmentId, serviceId, key, {
136
+ value: sent.value,
137
+ secret: sent.isSecret,
138
+ });
139
+ });
140
+ if (outcome !== "written") {
141
+ await takeBack(api, { projectId, environmentId }, written, sent);
142
+ return outcome;
143
+ }
144
+ written.push(sent);
145
+ }
146
+ return "written";
147
+ });
148
+ const token = written.find(({ planned }) => planned.content.kind === "setup_token");
149
+ const set = written.map(({ planned }) => ({
150
+ service: planned.serviceName,
151
+ key: planned.key,
152
+ }));
153
+ return token ? { set, setupToken: token.value } : { set };
154
+ }
155
+ //# sourceMappingURL=decide.js.map
@@ -0,0 +1,11 @@
1
+ import type { ConfirmDialogSerialized } from "@antelopejs/interface-dms/base/types/confirm-dialog";
2
+ import type { VariablesRead } from "./read";
3
+ /**
4
+ * The dialog the action of an environment opens: each variable it sets, on
5
+ * which service, with its value when everyone may read it, and each missing
6
+ * variable it leaves to the person, with the reason. Nothing to confirm
7
+ * when it sets none.
8
+ *
9
+ * @param environment The environment, by id or by name
10
+ */
11
+ export declare function decidedDialog(read: VariablesRead, environment: string): ConfirmDialogSerialized;
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decidedDialog = decidedDialog;
4
+ const confirm_dialog_1 = require("@antelopejs/interface-dms/base/confirm-dialog");
5
+ const content_1 = require("./content");
6
+ const dialogs_1 = require("./dialogs");
7
+ const ICONS = {
8
+ app_address: "i-ph-globe",
9
+ dashboard_address: "i-ph-globe",
10
+ fixed: "i-ph-plus",
11
+ volume: "i-ph-hard-drives",
12
+ secret: "i-ph-lock-key",
13
+ setupToken: "i-ph-key",
14
+ left: "i-ph-pencil-simple",
15
+ };
16
+ /** Why a variable is left to the person, as the end of its line. */
17
+ const LEFT = {
18
+ yours: "yours to set, on its row",
19
+ app_needs_volume: "the app can't start until this names a folder on a persistent, writable volume: add a volume to the app in its service settings on AntelopeJS Cloud, then set this to a folder on it",
20
+ resources: "a database of the environment publishes it: connect it on the Resources page",
21
+ app_has_no_address: "the app has no address yet: open it on the Environments page",
22
+ dashboard_has_no_address: "the dashboard has no address yet: add or open it on the Environments page",
23
+ shared_held: "the app and the dashboard share this secret and one of them holds it: set the same value on the other, or remove it there to have both generated",
24
+ dashboard_first: "the dashboard shares this secret and does not run yet: add the dashboard on the Environments page first",
25
+ };
26
+ function line({ serviceName, key }) {
27
+ return `${serviceName} · ${key}`;
28
+ }
29
+ /** The services that get one same generated value, by group. */
30
+ function sharers(plan) {
31
+ const groups = new Map();
32
+ for (const { serviceName, content } of plan.sets) {
33
+ if (content.kind !== "secret")
34
+ continue;
35
+ groups.set(content.group, [
36
+ ...(groups.get(content.group) ?? []),
37
+ serviceName,
38
+ ]);
39
+ }
40
+ return groups;
41
+ }
42
+ /**
43
+ * A variable the action sets, as a line of the dialog: an address or a
44
+ * header name with its value, a secret as the fact that one is generated.
45
+ * No line carries a generated value: none exists before the action runs.
46
+ */
47
+ function setRow(planned, groups) {
48
+ const { content } = planned;
49
+ if (content.kind === "plain") {
50
+ return {
51
+ icon: ICONS[content.from],
52
+ label: `${line(planned)}: ${content.value}`,
53
+ };
54
+ }
55
+ if (content.kind === "setup_token") {
56
+ return {
57
+ icon: ICONS.setupToken,
58
+ label: `${line(planned)}: the setup token, generated now and copied to your clipboard, once`,
59
+ };
60
+ }
61
+ const shared = groups.get(content.group) ?? [];
62
+ return {
63
+ icon: ICONS.secret,
64
+ label: shared.length > 1
65
+ ? `${line(planned)}: a secret generated now, the same on ${(0, content_1.names)(shared)}`
66
+ : `${line(planned)}: a secret generated now`,
67
+ };
68
+ }
69
+ function leftRow(left) {
70
+ return { icon: ICONS.left, label: `${line(left)}: ${LEFT[left.reason]}` };
71
+ }
72
+ function summaryOf({ sets, left }) {
73
+ const sentences = [
74
+ "AntelopeJS Cloud sets what it can decide: the addresses of the app and the dashboard, and the secrets this project owns, generated on this server and sent as secrets. No value a service holds is replaced.",
75
+ ];
76
+ if (sets.some(({ content }) => content.kind === "setup_token")) {
77
+ sentences.push("The setup token is copied to your clipboard when the values are set, and shown nowhere again: paste it somewhere safe.");
78
+ }
79
+ if (left.length > 0) {
80
+ sentences.push(`${left.length} ${left.length === 1 ? "variable stays" : "variables stay"} yours to set.`);
81
+ }
82
+ return sentences.join(" ");
83
+ }
84
+ function dialogOf({ environmentName, plan, }) {
85
+ const left = plan.left.map(leftRow);
86
+ if (plan.sets.length === 0) {
87
+ return (0, confirm_dialog_1.serializeConfirmDialog)({
88
+ title: `Nothing to set on ${environmentName}`,
89
+ description: left.length > 0
90
+ ? "Every value AntelopeJS Cloud can decide is set. What is listed is yours to set."
91
+ : "Every value AntelopeJS Cloud can decide is set.",
92
+ icon: "i-ph-magic-wand",
93
+ impact: left,
94
+ blocked: true,
95
+ });
96
+ }
97
+ const groups = sharers(plan);
98
+ const count = plan.sets.length;
99
+ return (0, confirm_dialog_1.serializeConfirmDialog)({
100
+ title: `Set ${count} ${count === 1 ? "value" : "values"} on ${environmentName}?`,
101
+ description: summaryOf(plan),
102
+ icon: "i-ph-magic-wand",
103
+ color: "primary",
104
+ confirmLabel: `Set on ${environmentName}`,
105
+ impact: [...plan.sets.map((planned) => setRow(planned, groups)), ...left],
106
+ });
107
+ }
108
+ /**
109
+ * The dialog the action of an environment opens: each variable it sets, on
110
+ * which service, with its value when everyone may read it, and each missing
111
+ * variable it leaves to the person, with the reason. Nothing to confirm
112
+ * when it sets none.
113
+ *
114
+ * @param environment The environment, by id or by name
115
+ */
116
+ function decidedDialog(read, environment) {
117
+ if (read.kind !== "ok")
118
+ return (0, dialogs_1.unavailableDialog)(read.kind);
119
+ const decided = read.decided.find(({ environmentId, environmentName }) => environmentId === environment || environmentName === environment);
120
+ if (!decided) {
121
+ return (0, confirm_dialog_1.serializeConfirmDialog)({
122
+ title: "AntelopeJS Cloud has no such environment in this project",
123
+ description: "Reload the page: its environments changed.",
124
+ blocked: true,
125
+ });
126
+ }
127
+ return dialogOf(decided);
128
+ }
129
+ //# sourceMappingURL=decided-dialog.js.map
@@ -0,0 +1,80 @@
1
+ import { type ProjectConfig } from "./project-config";
2
+ /** A service the plan sets values on, and where it answers. */
3
+ export interface DecidedService {
4
+ readonly id: string;
5
+ readonly name: string;
6
+ /** Its address, `null` when the internet does not reach it. */
7
+ readonly address: string | null;
8
+ }
9
+ /** What the plan of an environment is drawn from. */
10
+ export interface DecidedFacts {
11
+ /** Its one app service, `null` when it runs none or several. */
12
+ readonly app: DecidedService | null;
13
+ /** Its dashboard, `null` when it runs none. */
14
+ readonly dashboard: DecidedService | null;
15
+ /** Whether the project builds a dashboard, so that one is to come where none runs. */
16
+ readonly expectsDashboard: boolean;
17
+ /** Where its app mounts its volume, `null` when it has none. */
18
+ readonly appVolume: string | null;
19
+ /** What its services hold, as `<serviceId> <key>`. */
20
+ readonly held: ReadonlySet<string>;
21
+ /**
22
+ * The variables the Resources page would add, as `<serviceId> <key>`: each
23
+ * follows the connection string a database of the environment publishes.
24
+ */
25
+ readonly followable: ReadonlySet<string>;
26
+ }
27
+ /**
28
+ * The value the plan gives a variable: a text everyone may read (`plain`), a
29
+ * secret generated when the plan is applied, one value per `group`
30
+ * (`secret`), or the setup token, generated then and shown once
31
+ * (`setup_token`).
32
+ */
33
+ type PlannedContent = {
34
+ readonly kind: "plain";
35
+ readonly value: string;
36
+ readonly from: "app_address" | "dashboard_address" | "fixed" | "volume";
37
+ } | {
38
+ readonly kind: "secret";
39
+ readonly group: string;
40
+ } | {
41
+ readonly kind: "setup_token";
42
+ };
43
+ /** A variable the plan sets on a service. */
44
+ export interface PlannedValue {
45
+ readonly serviceId: string;
46
+ readonly serviceName: string;
47
+ readonly key: string;
48
+ readonly content: PlannedContent;
49
+ }
50
+ /**
51
+ * Why the plan leaves a missing variable to the person: AntelopeJS Cloud
52
+ * cannot know its value (`yours`), a database of the environment publishes
53
+ * it and the Resources page connects it (`resources`), the app or the
54
+ * dashboard it is the address of has none yet, the other service already
55
+ * holds the shared secret, whose value nobody can read back
56
+ * (`shared_held`), the dashboard that shares it does not exist yet
57
+ * (`dashboard_first`), or it names a folder of a persistent volume the app
58
+ * has to be given first (`app_needs_volume`).
59
+ */
60
+ export type LeftReason = "yours" | "app_needs_volume" | "resources" | "app_has_no_address" | "dashboard_has_no_address" | "shared_held" | "dashboard_first";
61
+ /** A missing variable the plan does not set. */
62
+ export interface LeftValue {
63
+ readonly serviceName: string;
64
+ readonly key: string;
65
+ readonly reason: LeftReason;
66
+ }
67
+ /** What AntelopeJS Cloud can decide for an environment, and what it cannot. */
68
+ export interface DecidedPlan {
69
+ readonly sets: readonly PlannedValue[];
70
+ readonly left: readonly LeftValue[];
71
+ }
72
+ /**
73
+ * What AntelopeJS Cloud can decide for an environment: for each variable its
74
+ * app lacks among the project's `envOverrides`, and each one its dashboard
75
+ * lacks among those a dashboard reads, the value to set, or why it is left
76
+ * to the person. A variable a service holds is never in the plan. The setup
77
+ * token comes last, so that it is generated only once the rest is set.
78
+ */
79
+ export declare function planDecided(facts: DecidedFacts, config: ProjectConfig): DecidedPlan;
80
+ export {};
@@ -0,0 +1,240 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.planDecided = planDecided;
4
+ const variables_1 = require("../dashboard/variables");
5
+ const storage_1 = require("../setup/storage");
6
+ const model_1 = require("./model");
7
+ const project_config_1 = require("./project-config");
8
+ const API_PACKAGE = "@antelopejs/api";
9
+ const DMS_PACKAGE = "@antelopejs/dms";
10
+ const AUTH_JWT_PACKAGE = "@antelopejs/auth-jwt";
11
+ const MODULE_PATH = /^modules\.([^.]+)\.config\.(.+)$/;
12
+ /** The header AntelopeJS Cloud's gateway overwrites with the client's address. */
13
+ const CLIENT_IP_HEADER = "X-Client-IP";
14
+ const SHARED_GROUPS = ["bootstrap", "html_render"];
15
+ /**
16
+ * The config paths whose value AntelopeJS Cloud can decide, by the npm
17
+ * package of the module they configure and the path below its `config`. A
18
+ * secret is listed only when the project owns it: a signing secret nobody
19
+ * else has to know. A credential of another service, an API key or an SMTP
20
+ * password, is never generated, whatever its name.
21
+ */
22
+ const DECIDED_PATHS = new Map([
23
+ [
24
+ API_PACKAGE,
25
+ new Map([["publicBaseUrl", { kind: "app_address" }]]),
26
+ ],
27
+ [
28
+ DMS_PACKAGE,
29
+ new Map([
30
+ ["clientBaseUrl", { kind: "dashboard_address" }],
31
+ ["auth.clientIpHeader", { kind: "fixed", value: CLIENT_IP_HEADER }],
32
+ ["auth.jwtSecret", { kind: "secret", shared: null }],
33
+ ["htmlRender.serviceSecret", { kind: "secret", shared: "html_render" }],
34
+ ["frontend.bootstrapSecret", { kind: "secret", shared: "bootstrap" }],
35
+ ]),
36
+ ],
37
+ [
38
+ AUTH_JWT_PACKAGE,
39
+ new Map([["secret", { kind: "secret", shared: null }]]),
40
+ ],
41
+ [
42
+ storage_1.FILE_STORAGE_PACKAGE,
43
+ new Map([["storagePath", { kind: "volume_folder" }]]),
44
+ ],
45
+ ]);
46
+ function decisionOfPath(config, path) {
47
+ const match = MODULE_PATH.exec(path);
48
+ if (!match)
49
+ return null;
50
+ const [, moduleKey, below] = match;
51
+ const packageName = config.modules[moduleKey]?.package ?? "";
52
+ return DECIDED_PATHS.get(packageName)?.get(below) ?? null;
53
+ }
54
+ function sameDecision(left, right) {
55
+ return JSON.stringify(left) === JSON.stringify(right);
56
+ }
57
+ /**
58
+ * What AntelopeJS Cloud can set a variable to, from the config paths its
59
+ * `envOverrides` entry feeds: `null` when a path is not one it decides, or
60
+ * when the paths would take different values.
61
+ */
62
+ function decisionOf(config, paths) {
63
+ const decisions = paths.map((path) => decisionOfPath(config, path));
64
+ const [first] = decisions;
65
+ if (!first)
66
+ return null;
67
+ return decisions.every((decision) => decision !== null && sameDecision(decision, first))
68
+ ? first
69
+ : null;
70
+ }
71
+ function isHeld({ held }, service, key) {
72
+ return held.has(`${service.id} ${key}`);
73
+ }
74
+ function appWants(facts, config) {
75
+ const { app } = facts;
76
+ if (app === null)
77
+ return [];
78
+ return Object.entries(config.envOverrides).flatMap(([key, paths]) => model_1.variableKeySchema.safeParse(key).success && !isHeld(facts, app, key)
79
+ ? [{ service: app, key, decision: decisionOf(config, paths) }]
80
+ : []);
81
+ }
82
+ /**
83
+ * What decides each variable of a dashboard: those it cannot start without,
84
+ * then the header it reads the client's address from, which it runs without
85
+ * and AntelopeJS Cloud's gateway sets all the same.
86
+ */
87
+ const DASHBOARD_DECISIONS = [
88
+ [variables_1.DASHBOARD_VARIABLES.apiBaseUrl, { kind: "app_address" }],
89
+ [variables_1.DASHBOARD_VARIABLES.clientBaseUrl, { kind: "dashboard_address" }],
90
+ [variables_1.DASHBOARD_VARIABLES.sessionSecret, { kind: "secret", shared: null }],
91
+ [
92
+ variables_1.DASHBOARD_VARIABLES.bootstrapSecret,
93
+ { kind: "secret", shared: "bootstrap" },
94
+ ],
95
+ [
96
+ variables_1.DASHBOARD_VARIABLES.htmlRenderSecret,
97
+ { kind: "secret", shared: "html_render" },
98
+ ],
99
+ [variables_1.CLIENT_IP_VARIABLE, { kind: "fixed", value: CLIENT_IP_HEADER }],
100
+ ];
101
+ function dashboardWants(facts) {
102
+ const { dashboard } = facts;
103
+ if (dashboard === null)
104
+ return [];
105
+ return DASHBOARD_DECISIONS.flatMap(([key, decision]) => isHeld(facts, dashboard, key)
106
+ ? []
107
+ : [{ service: dashboard, key, decision }]);
108
+ }
109
+ function sharesIn(decision, group) {
110
+ return decision?.kind === "secret" && decision.shared === group;
111
+ }
112
+ /**
113
+ * Why the secret of `group` cannot be generated now, `null` when it can. It
114
+ * is generated only for the app and the dashboard together: nobody can read
115
+ * a secret back, so a value one of them got alone could never be given to
116
+ * the other. One that holds it, a dashboard that does not run yet, or an app
117
+ * no `envOverrides` entry hands it to, leaves it to the person.
118
+ */
119
+ function sharedObstacle(facts, config, wanted, group) {
120
+ const { app, dashboard } = facts;
121
+ const appHolds = app !== null &&
122
+ Object.entries(config.envOverrides).some(([key, paths]) => isHeld(facts, app, key) && sharesIn(decisionOf(config, paths), group));
123
+ const dashboardHolds = dashboard !== null &&
124
+ DASHBOARD_DECISIONS.some(([key, decision]) => sharesIn(decision, group) && isHeld(facts, dashboard, key));
125
+ if (appHolds || dashboardHolds)
126
+ return "shared_held";
127
+ if (dashboard === null) {
128
+ return facts.expectsDashboard ? "dashboard_first" : "yours";
129
+ }
130
+ const sharers = new Set(wanted
131
+ .filter(({ decision }) => sharesIn(decision, group))
132
+ .map(({ service }) => service.id));
133
+ return app !== null && sharers.has(app.id) && sharers.has(dashboard.id)
134
+ ? null
135
+ : "yours";
136
+ }
137
+ function appAddress({ app }) {
138
+ return app?.address
139
+ ? { content: { kind: "plain", value: app.address, from: "app_address" } }
140
+ : { reason: "app_has_no_address" };
141
+ }
142
+ /**
143
+ * The address of the dashboard. A project that builds none serves its
144
+ * dashboard elsewhere: where is for the person to say.
145
+ */
146
+ function dashboardAddress({ dashboard, expectsDashboard, }) {
147
+ if (dashboard?.address) {
148
+ return {
149
+ content: {
150
+ kind: "plain",
151
+ value: dashboard.address,
152
+ from: "dashboard_address",
153
+ },
154
+ };
155
+ }
156
+ return {
157
+ reason: dashboard === null && !expectsDashboard
158
+ ? "yours"
159
+ : "dashboard_has_no_address",
160
+ };
161
+ }
162
+ function plannedFor({ service, key, decision }, facts, shared) {
163
+ if (decision === null) {
164
+ return {
165
+ reason: facts.followable.has(`${service.id} ${key}`)
166
+ ? "resources"
167
+ : "yours",
168
+ };
169
+ }
170
+ if (decision.kind === "app_address")
171
+ return appAddress(facts);
172
+ if (decision.kind === "dashboard_address")
173
+ return dashboardAddress(facts);
174
+ if (decision.kind === "volume_folder") {
175
+ return facts.appVolume === null
176
+ ? { reason: "app_needs_volume" }
177
+ : { content: { kind: "plain", value: facts.appVolume, from: "volume" } };
178
+ }
179
+ if (decision.kind === "fixed") {
180
+ return {
181
+ content: { kind: "plain", value: decision.value, from: "fixed" },
182
+ };
183
+ }
184
+ if (decision.shared === null) {
185
+ return { content: { kind: "secret", group: `${service.id} ${key}` } };
186
+ }
187
+ const obstacle = shared.get(decision.shared) ?? null;
188
+ return obstacle === null
189
+ ? { content: { kind: "secret", group: decision.shared } }
190
+ : { reason: obstacle };
191
+ }
192
+ /** The setup token of a DMS whose app does not hold one yet. */
193
+ function setupToken(facts, config) {
194
+ const { app } = facts;
195
+ const runsDms = (0, project_config_1.moduleKeysOf)(config, DMS_PACKAGE).length > 0;
196
+ if (app === null || !runsDms || isHeld(facts, app, variables_1.SETUP_TOKEN_VARIABLE)) {
197
+ return [];
198
+ }
199
+ return [
200
+ {
201
+ serviceId: app.id,
202
+ serviceName: app.name,
203
+ key: variables_1.SETUP_TOKEN_VARIABLE,
204
+ content: { kind: "setup_token" },
205
+ },
206
+ ];
207
+ }
208
+ /**
209
+ * What AntelopeJS Cloud can decide for an environment: for each variable its
210
+ * app lacks among the project's `envOverrides`, and each one its dashboard
211
+ * lacks among those a dashboard reads, the value to set, or why it is left
212
+ * to the person. A variable a service holds is never in the plan. The setup
213
+ * token comes last, so that it is generated only once the rest is set.
214
+ */
215
+ function planDecided(facts, config) {
216
+ const wants = [...appWants(facts, config), ...dashboardWants(facts)];
217
+ const shared = new Map(SHARED_GROUPS.map((group) => [
218
+ group,
219
+ sharedObstacle(facts, config, wants, group),
220
+ ]));
221
+ const sets = [];
222
+ const left = [];
223
+ for (const wanted of wants) {
224
+ const { service, key } = wanted;
225
+ const planned = plannedFor(wanted, facts, shared);
226
+ if ("content" in planned) {
227
+ sets.push({
228
+ serviceId: service.id,
229
+ serviceName: service.name,
230
+ key,
231
+ content: planned.content,
232
+ });
233
+ }
234
+ else {
235
+ left.push({ serviceName: service.name, key, reason: planned.reason });
236
+ }
237
+ }
238
+ return { sets: [...sets, ...setupToken(facts, config)], left };
239
+ }
240
+ //# sourceMappingURL=decided.js.map
@@ -0,0 +1,8 @@
1
+ import type { ConfirmDialogSerialized } from "@antelopejs/interface-dms/base/types/confirm-dialog";
2
+ import { type RowRef } from "./model";
3
+ import type { VariablesRead } from "./read";
4
+ /** The dialog of an action the page cannot run: why it cannot read the project. */
5
+ export declare function unavailableDialog(kind: Exclude<VariablesRead["kind"], "ok">): ConfirmDialogSerialized;
6
+ export declare function valueDialog(read: VariablesRead, ref: RowRef | undefined): ConfirmDialogSerialized;
7
+ export declare function removeDialog(read: VariablesRead, ref: RowRef | undefined): ConfirmDialogSerialized;
8
+ export declare function addDialog(read: VariablesRead): ConfirmDialogSerialized;