@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,185 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseNewVariable = parseNewVariable;
4
+ exports.parseValueBody = parseValueBody;
5
+ exports.send = send;
6
+ exports.write = write;
7
+ exports.addVariable = addVariable;
8
+ exports.setValue = setValue;
9
+ exports.removeVariable = removeVariable;
10
+ const cloud_sdk_1 = require("@antelopejs/cloud-sdk");
11
+ const interface_api_1 = require("@antelopejs/interface-api");
12
+ const zod_1 = require("zod");
13
+ const announce_1 = require("../connection/announce");
14
+ const cloud_1 = require("../connection/cloud");
15
+ const current_1 = require("../connection/current");
16
+ const model_1 = require("./model");
17
+ const MESSAGE_KEY_PREFIX = "$dms_antelope_cloud.errors.";
18
+ const NOT_CONNECTED = { status: 409, error: "not_connected" };
19
+ const NO_PROJECT = { status: 400, error: "project_required" };
20
+ const INVALID = { status: 400, error: "invalid_variable" };
21
+ const UNKNOWN = { status: 404, error: "unknown_variable" };
22
+ const EXISTS = { status: 409, error: "variable_exists" };
23
+ const REFUSED = { status: 422, error: "variable_refused" };
24
+ const CLOUD_FAILURES = {
25
+ revoked: { status: 409, error: "sign_in_revoked" },
26
+ missing: { status: 422, error: "unknown_project" },
27
+ forbidden: { status: 409, error: "cloud_forbidden" },
28
+ unreachable: { status: 502, error: "cloud_unreachable" },
29
+ };
30
+ const WRITE_REFUSALS = new Map([
31
+ [400, REFUSED],
32
+ [404, UNKNOWN],
33
+ [409, REFUSED],
34
+ [422, REFUSED],
35
+ ]);
36
+ const value = zod_1.z.string().min(1);
37
+ const serviceId = zod_1.z.string().min(1);
38
+ const secret = zod_1.z.boolean().optional();
39
+ const newVariableSchema = zod_1.z.object({
40
+ serviceId,
41
+ key: model_1.variableKeySchema,
42
+ value,
43
+ secret,
44
+ });
45
+ const valueBodySchema = zod_1.z.object({
46
+ value,
47
+ serviceId: serviceId.optional(),
48
+ secret,
49
+ });
50
+ function refuse({ status, error }) {
51
+ return new interface_api_1.HTTPResult(status, {
52
+ error,
53
+ message: `${MESSAGE_KEY_PREFIX}${error}`,
54
+ });
55
+ }
56
+ function parseTarget(ref) {
57
+ const target = (0, model_1.parseRef)(ref);
58
+ if (!target)
59
+ throw refuse(UNKNOWN);
60
+ return target;
61
+ }
62
+ /** Reads the body of the Add variable dialog, `undefined` when it is not a variable. */
63
+ function parseNewVariable(body) {
64
+ return newVariableSchema.safeParse(body).data;
65
+ }
66
+ /** Reads the body of the Set value dialog, `undefined` when it holds no value. */
67
+ function parseValueBody(body) {
68
+ return valueBodySchema.safeParse(body).data;
69
+ }
70
+ /**
71
+ * Sends one write of a variable: `written`, or the refusal of a write
72
+ * AntelopeJS Cloud refuses.
73
+ *
74
+ * @throws What is not such a refusal: a revoked token, or no answer
75
+ */
76
+ async function send(write) {
77
+ try {
78
+ await write();
79
+ return "written";
80
+ }
81
+ catch (error) {
82
+ const refusal = error instanceof cloud_sdk_1.CloudApiError
83
+ ? WRITE_REFUSALS.get(error.status)
84
+ : undefined;
85
+ if (refusal)
86
+ return refusal;
87
+ throw error;
88
+ }
89
+ }
90
+ async function environmentOf(api, projectId, service) {
91
+ const { environments } = await api.readProject(projectId);
92
+ return environments.find(({ services }) => services.some(({ id }) => id === service))?.id;
93
+ }
94
+ async function holds(api, projectId, environmentId, ref) {
95
+ const { variables } = await api.listVariables(projectId, environmentId);
96
+ return variables.some(({ serviceId, key }) => serviceId === ref.serviceId && key === ref.key);
97
+ }
98
+ /**
99
+ * Runs a write on the project the tenant publishes, signed in with its
100
+ * stored token.
101
+ *
102
+ * @throws The refusal of a tenant without a project, of a failed call, or
103
+ * the one `act` answers
104
+ */
105
+ async function write(tenantId, act) {
106
+ const stored = await (0, current_1.readConnection)(tenantId);
107
+ if (stored?.state !== "connected")
108
+ throw refuse(NOT_CONNECTED);
109
+ const { projectId } = stored;
110
+ if (projectId === null)
111
+ throw refuse(NO_PROJECT);
112
+ const result = await (0, cloud_1.readCloud)(stored, (api) => act(api, projectId));
113
+ if (result.kind === "revoked")
114
+ await (0, announce_1.announce)(tenantId);
115
+ if (result.kind !== "ok")
116
+ throw refuse(CLOUD_FAILURES[result.kind]);
117
+ if (result.value !== "written")
118
+ throw refuse(result.value);
119
+ }
120
+ function create(variable, inEnvironment) {
121
+ return async (api, projectId) => {
122
+ const { serviceId, key } = variable;
123
+ const environmentId = await environmentOf(api, projectId, serviceId);
124
+ if (environmentId === undefined ||
125
+ (inEnvironment !== undefined && inEnvironment !== environmentId)) {
126
+ return UNKNOWN;
127
+ }
128
+ if (await holds(api, projectId, environmentId, variable))
129
+ return EXISTS;
130
+ return send(async () => {
131
+ await api.setVariable(projectId, environmentId, serviceId, key, {
132
+ value: variable.value,
133
+ secret: variable.secret ?? true,
134
+ });
135
+ });
136
+ };
137
+ }
138
+ function onHeld(target, change) {
139
+ return async (api, projectId) => {
140
+ const environmentId = await environmentOf(api, projectId, target.serviceId);
141
+ if (environmentId === undefined ||
142
+ !(await holds(api, projectId, environmentId, target))) {
143
+ return UNKNOWN;
144
+ }
145
+ return send(() => change(api, projectId, environmentId));
146
+ };
147
+ }
148
+ /** Creates a variable on a service of the project. A key the service holds already is refused. */
149
+ async function addVariable(tenantId, variable) {
150
+ if (!variable)
151
+ throw refuse(INVALID);
152
+ await write(tenantId, create(variable, undefined));
153
+ }
154
+ /**
155
+ * Sets the value of the row `ref` names. A held variable keeps its kind; a
156
+ * missing row is created on the service the body names, which must run in
157
+ * the row's environment, or on the one service the row is missing on.
158
+ */
159
+ async function setValue(tenantId, ref, body) {
160
+ if (!body)
161
+ throw refuse(INVALID);
162
+ const target = parseTarget(ref);
163
+ if (target.kind === "environment") {
164
+ if (body.serviceId === undefined)
165
+ throw refuse(INVALID);
166
+ const variable = { ...body, serviceId: body.serviceId, key: target.key };
167
+ await write(tenantId, create(variable, target.environmentId));
168
+ return;
169
+ }
170
+ if (target.kind === "missing") {
171
+ const variable = { ...body, serviceId: target.serviceId, key: target.key };
172
+ await write(tenantId, create(variable, undefined));
173
+ return;
174
+ }
175
+ await write(tenantId, onHeld(target, async (api, projectId, environmentId) => {
176
+ await api.setVariable(projectId, environmentId, target.serviceId, target.key, { value: body.value });
177
+ }));
178
+ }
179
+ async function removeVariable(tenantId, ref) {
180
+ const target = parseTarget(ref);
181
+ if (target.kind !== "service")
182
+ throw refuse(UNKNOWN);
183
+ await write(tenantId, onHeld(target, (api, projectId, environmentId) => api.deleteVariable(projectId, environmentId, target.serviceId, target.key)));
184
+ }
185
+ //# sourceMappingURL=actions.js.map
@@ -0,0 +1,69 @@
1
+ import type { BannerContent } from "@antelopejs/interface-dms/base/banner";
2
+ import type { Tone } from "@antelopejs/interface-dms/base/types/tone";
3
+ import type { RowState } from "./model";
4
+ import type { HardcodedSecret } from "./project-config";
5
+ import type { VariablesRead } from "./read";
6
+ export declare const VARIABLES_ROUTES: {
7
+ readonly status: "/status";
8
+ readonly hardcoded: "/hardcoded";
9
+ readonly environments: "/environments";
10
+ readonly list: "/list";
11
+ readonly addDialog: "/add-dialog";
12
+ readonly add: "/variables";
13
+ readonly valueDialog: "/variables/:ref/value-dialog";
14
+ readonly value: "/variables/:ref/value";
15
+ readonly removeDialog: "/variables/:ref/remove-dialog";
16
+ readonly remove: "/variables/:ref/remove";
17
+ readonly decidedDialog: "/decided-dialog";
18
+ readonly decided: "/decided";
19
+ };
20
+ export type VariablesRoute = (typeof VARIABLES_ROUTES)[keyof typeof VARIABLES_ROUTES];
21
+ export declare function variablesRoute(route: VariablesRoute): string;
22
+ /**
23
+ * The URL of a row's route, for the row `ref` names, or for the row a table
24
+ * action runs on when `ref` is left out.
25
+ */
26
+ export declare function rowRoute(route: VariablesRoute, ref?: string): string;
27
+ export interface TableRow {
28
+ readonly ref: string;
29
+ readonly state: RowState;
30
+ readonly environmentName: string;
31
+ readonly key: string;
32
+ /** Where the variable is set: "production · web", "production · not set", or "production · dashboard · not set". */
33
+ readonly location: string;
34
+ readonly value: string;
35
+ readonly valueTone?: Tone;
36
+ readonly source: string;
37
+ readonly sourceTone: Tone;
38
+ readonly sourceDetail?: string;
39
+ readonly feeds: string;
40
+ }
41
+ export interface TableAnswer {
42
+ readonly results: TableRow[];
43
+ readonly total: number;
44
+ }
45
+ export interface ListQuery {
46
+ readonly search?: string;
47
+ /** `filter_environmentName`, as `<mode>:<name>`. */
48
+ readonly environment?: string;
49
+ }
50
+ /**
51
+ * The rows the table lists for the query, in the order of the rows: none
52
+ * while the page cannot read the project, its status banner says why.
53
+ */
54
+ export declare function tableAnswer(read: VariablesRead, query: ListQuery): TableAnswer;
55
+ /** Names items as a sentence does: "a", "a and b", "a, b and c". */
56
+ export declare function names(items: readonly string[]): string;
57
+ /**
58
+ * Why the page shows nothing, or which variables have no value, with an
59
+ * action for each environment AntelopeJS Cloud can decide some of; `null`
60
+ * when all is set.
61
+ */
62
+ export declare function statusBanner(read: VariablesRead): BannerContent | null;
63
+ /**
64
+ * The secrets the config file sets for every environment, and the
65
+ * `envOverrides` lines that hand them to this page; `null` when there is
66
+ * none. It names paths, never a value.
67
+ */
68
+ export declare function hardcodedBanner(secrets: readonly HardcodedSecret[]): BannerContent | null;
69
+ export declare function environmentsBanner(read: VariablesRead): BannerContent | null;
@@ -0,0 +1,310 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VARIABLES_ROUTES = void 0;
4
+ exports.variablesRoute = variablesRoute;
5
+ exports.rowRoute = rowRoute;
6
+ exports.tableAnswer = tableAnswer;
7
+ exports.names = names;
8
+ exports.statusBanner = statusBanner;
9
+ exports.hardcodedBanner = hardcodedBanner;
10
+ exports.environmentsBanner = environmentsBanner;
11
+ const page_1 = require("@antelopejs/interface-dms/page");
12
+ const slugs_1 = require("../pages/slugs");
13
+ exports.VARIABLES_ROUTES = {
14
+ status: "/status",
15
+ hardcoded: "/hardcoded",
16
+ environments: "/environments",
17
+ list: "/list",
18
+ addDialog: "/add-dialog",
19
+ add: "/variables",
20
+ valueDialog: "/variables/:ref/value-dialog",
21
+ value: "/variables/:ref/value",
22
+ removeDialog: "/variables/:ref/remove-dialog",
23
+ remove: "/variables/:ref/remove",
24
+ decidedDialog: "/decided-dialog",
25
+ decided: "/decided",
26
+ };
27
+ function variablesRoute(route) {
28
+ return (0, page_1.pageRoutePath)((0, slugs_1.modulePageSlug)("variables"), route);
29
+ }
30
+ /**
31
+ * The URL of a row's route, for the row `ref` names, or for the row a table
32
+ * action runs on when `ref` is left out.
33
+ */
34
+ function rowRoute(route, ref = "{{row.ref}}") {
35
+ return variablesRoute(route).replace(":ref", ref);
36
+ }
37
+ const PROVIDED = { source: "Provided by you", sourceTone: "neutral" };
38
+ function followed(row) {
39
+ return `${row.publisherName} · ${row.publishedKey}`;
40
+ }
41
+ function manualSource(row, rows) {
42
+ if (!row.overridden)
43
+ return PROVIDED;
44
+ const wiring = rows
45
+ .filter((other) => other.state === "wired" &&
46
+ other.environmentId === row.environmentId &&
47
+ other.key === row.key)
48
+ .map((other) => `${other.serviceName} follows ${followed(other)}`);
49
+ return {
50
+ source: "Overridden",
51
+ sourceTone: "warning",
52
+ sourceDetail: wiring.join(", "),
53
+ };
54
+ }
55
+ const held = (row) => `${row.environmentName} · ${row.serviceName}`;
56
+ const STATES = {
57
+ __proto__: null,
58
+ wired: {
59
+ location: held,
60
+ value: (row) => `Follows ${followed(row)}`,
61
+ valueTone: "info",
62
+ source: () => ({ source: "From resources", sourceTone: "info" }),
63
+ },
64
+ plain: {
65
+ location: held,
66
+ value: (row) => row.value,
67
+ source: manualSource,
68
+ },
69
+ secret: {
70
+ location: held,
71
+ value: () => "Secret · write-only",
72
+ valueTone: "neutral",
73
+ source: manualSource,
74
+ },
75
+ missing: {
76
+ location: (row) => row.serviceName === undefined
77
+ ? `${row.environmentName} · not set`
78
+ : `${row.environmentName} · ${row.serviceName} · not set`,
79
+ value: () => "No value",
80
+ valueTone: "error",
81
+ source: () => ({ source: "Missing", sourceTone: "error" }),
82
+ },
83
+ };
84
+ function cellsOf(state, row, rows) {
85
+ const display = STATES[state];
86
+ return {
87
+ ref: row.ref,
88
+ state,
89
+ environmentName: row.environmentName,
90
+ key: row.key,
91
+ location: display.location(row),
92
+ value: display.value(row),
93
+ valueTone: display.valueTone,
94
+ ...display.source(row, rows),
95
+ feeds: row.feeds.join(", "),
96
+ };
97
+ }
98
+ function environmentNamed(filter) {
99
+ return filter.slice(filter.indexOf(":") + 1);
100
+ }
101
+ /**
102
+ * The rows the table lists for the query, in the order of the rows: none
103
+ * while the page cannot read the project, its status banner says why.
104
+ */
105
+ function tableAnswer(read, query) {
106
+ if (read.kind !== "ok")
107
+ return { results: [], total: 0 };
108
+ const environment = query.environment
109
+ ? environmentNamed(query.environment)
110
+ : undefined;
111
+ const search = query.search?.trim().toLowerCase() ?? "";
112
+ const results = read.rows
113
+ .filter((row) => (environment === undefined || row.environmentName === environment) &&
114
+ row.key.toLowerCase().includes(search))
115
+ .map((row) => cellsOf(row.state, row, read.rows));
116
+ return { results, total: results.length };
117
+ }
118
+ const CONNECTION_LINK = {
119
+ label: "Open Connection",
120
+ icon: "i-ph-plugs-connected",
121
+ to: (0, slugs_1.modulePageSlug)("connection"),
122
+ };
123
+ const UNAVAILABLE = {
124
+ disconnected: {
125
+ tone: "primary",
126
+ title: "Not connected to AntelopeJS Cloud",
127
+ description: "Connect this DMS to the project it publishes to read and set the variables of its environments.",
128
+ actions: [CONNECTION_LINK],
129
+ },
130
+ no_project: {
131
+ tone: "info",
132
+ title: "Choose the project this DMS publishes",
133
+ description: "The variables are those of its environments.",
134
+ actions: [CONNECTION_LINK],
135
+ },
136
+ revoked: {
137
+ tone: "warning",
138
+ title: "Your AntelopeJS Cloud sign-in was revoked",
139
+ description: "Sign in again to read and set the variables.",
140
+ actions: [{ ...CONNECTION_LINK, label: "Sign in again" }],
141
+ },
142
+ missing: {
143
+ tone: "warning",
144
+ title: "AntelopeJS Cloud has no such project any more",
145
+ description: "Choose the project this DMS publishes again.",
146
+ actions: [CONNECTION_LINK],
147
+ },
148
+ forbidden: {
149
+ tone: "warning",
150
+ title: "AntelopeJS Cloud does not allow this token here",
151
+ description: "Its access does not cover the variables of this project.",
152
+ actions: [CONNECTION_LINK],
153
+ },
154
+ unreachable: {
155
+ tone: "error",
156
+ title: "AntelopeJS Cloud did not answer",
157
+ description: "The variables show again once it answers.",
158
+ },
159
+ };
160
+ /** Names items as a sentence does: "a", "a and b", "a, b and c". */
161
+ function names(items) {
162
+ if (items.length <= 1)
163
+ return items.join("");
164
+ return `${items.slice(0, -1).join(", ")} and ${items[items.length - 1]}`;
165
+ }
166
+ function missingBanner(rows) {
167
+ const missing = rows.filter(({ state }) => state === "missing");
168
+ const [first] = missing;
169
+ if (!first)
170
+ return null;
171
+ const environments = names([
172
+ ...new Set(missing.map(({ environmentName }) => environmentName)),
173
+ ]);
174
+ const description = missing.every(({ feeds }) => feeds.length > 0)
175
+ ? "envOverrides feeds a config path from it, and no service of the environment holds it. Set a value on its row."
176
+ : "A service of the environment needs it and does not hold it. Set a value on its row.";
177
+ if (missing.length > 1) {
178
+ return {
179
+ tone: "error",
180
+ title: `${missing.length} variables have no value on ${environments}`,
181
+ description,
182
+ };
183
+ }
184
+ const ref = encodeURIComponent(first.ref);
185
+ return {
186
+ tone: "error",
187
+ title: `${first.key} has no value on ${environments}`,
188
+ description,
189
+ actions: [
190
+ {
191
+ label: "Set value",
192
+ icon: "i-ph-lock-key",
193
+ target: {
194
+ type: "api",
195
+ url: rowRoute(exports.VARIABLES_ROUTES.value, ref),
196
+ method: "POST",
197
+ successMessage: "Value saved",
198
+ },
199
+ confirm: { from: rowRoute(exports.VARIABLES_ROUTES.valueDialog, ref) },
200
+ },
201
+ ],
202
+ };
203
+ }
204
+ function decidedUrl(route, environmentId) {
205
+ return `${variablesRoute(route)}?environment=${encodeURIComponent(environmentId)}`;
206
+ }
207
+ /**
208
+ * The action that sets what AntelopeJS Cloud can decide on an environment,
209
+ * after a dialog lists it. When the plan generates the setup token, the
210
+ * answer's `setupToken` is copied to the clipboard: the token is shown
211
+ * nowhere else, and no other plan touches the clipboard.
212
+ */
213
+ function decidedAction({ environmentId, environmentName, plan, }) {
214
+ const count = plan.sets.length;
215
+ const hasToken = plan.sets.some(({ content }) => content.kind === "setup_token");
216
+ const url = decidedUrl(exports.VARIABLES_ROUTES.decided, environmentId);
217
+ return {
218
+ label: `Set ${count} ${count === 1 ? "value" : "values"} on ${environmentName}`,
219
+ icon: "i-ph-magic-wand",
220
+ color: "neutral",
221
+ target: hasToken
222
+ ? {
223
+ type: "api",
224
+ url,
225
+ method: "POST",
226
+ copy: "setupToken",
227
+ successMessage: "Values set. The setup token is in your clipboard: it is not shown again.",
228
+ }
229
+ : { type: "api", url, method: "POST", successMessage: "Values set" },
230
+ confirm: {
231
+ from: decidedUrl(exports.VARIABLES_ROUTES.decidedDialog, environmentId),
232
+ },
233
+ };
234
+ }
235
+ /** One action per environment AntelopeJS Cloud can decide values for. */
236
+ function decidedActions(decided) {
237
+ return decided.filter(({ plan }) => plan.sets.length > 0).map(decidedAction);
238
+ }
239
+ /**
240
+ * Why the page shows nothing, or which variables have no value, with an
241
+ * action for each environment AntelopeJS Cloud can decide some of; `null`
242
+ * when all is set.
243
+ */
244
+ function statusBanner(read) {
245
+ if (read.kind !== "ok")
246
+ return UNAVAILABLE[read.kind];
247
+ const decided = decidedActions(read.decided);
248
+ const missing = missingBanner(read.rows);
249
+ if (missing) {
250
+ return { ...missing, actions: [...(missing.actions ?? []), ...decided] };
251
+ }
252
+ if (decided.length === 0)
253
+ return null;
254
+ return {
255
+ tone: "info",
256
+ icon: "i-ph-magic-wand",
257
+ title: "AntelopeJS Cloud can set values this project still lacks",
258
+ description: "A dialog lists them before anything is set. No value a service holds is replaced.",
259
+ actions: decided,
260
+ };
261
+ }
262
+ /**
263
+ * The secrets the config file sets for every environment, and the
264
+ * `envOverrides` lines that hand them to this page; `null` when there is
265
+ * none. It names paths, never a value.
266
+ */
267
+ function hardcodedBanner(secrets) {
268
+ if (secrets.length === 0)
269
+ return null;
270
+ const count = secrets.length;
271
+ const lines = secrets
272
+ .map(({ path, variable }) => `${variable}: "${path}",`)
273
+ .join(" ");
274
+ return {
275
+ tone: "warning",
276
+ icon: "i-ph-warning-diamond",
277
+ title: `${count} ${count === 1 ? "secret" : "secrets"} hardcoded in antelope.config.ts`,
278
+ description: `${names(secrets.map(({ path }) => path))} ${count === 1 ? "has" : "have"} a value in the file and no envOverrides entry, so each environment signs with the same value. Add an envOverrides entry so AntelopeJS Cloud takes the value from this page: ${lines}`,
279
+ };
280
+ }
281
+ function environmentsBanner(read) {
282
+ if (read.kind !== "ok" || read.environments.length === 0)
283
+ return null;
284
+ const page = (0, slugs_1.modulePageSlug)("variables");
285
+ const links = read.environments.map(({ id, name }) => {
286
+ const missing = read.rows.filter((row) => row.state === "missing" && row.environmentId === id).length;
287
+ return {
288
+ label: missing > 0 ? `${name} · ${missing} missing` : name,
289
+ to: `${page}?environment=${encodeURIComponent(name)}`,
290
+ variant: "outline",
291
+ color: missing > 0 ? "error" : "neutral",
292
+ };
293
+ });
294
+ return {
295
+ tone: "info",
296
+ size: "sm",
297
+ icon: "i-ph-stack",
298
+ title: "Environments",
299
+ actions: [
300
+ ...links,
301
+ {
302
+ label: "All environments",
303
+ to: page,
304
+ variant: "outline",
305
+ color: "neutral",
306
+ },
307
+ ],
308
+ };
309
+ }
310
+ //# sourceMappingURL=content.js.map
@@ -0,0 +1,27 @@
1
+ /**
2
+ * What setting the decided values answers: the variables it set, by
3
+ * service, and the setup token when this run generated one. The token is in
4
+ * this answer only: nothing else of the module holds or sends it again.
5
+ */
6
+ export interface DecidedAnswer {
7
+ readonly set: readonly {
8
+ readonly service: string;
9
+ readonly key: string;
10
+ }[];
11
+ readonly setupToken?: string;
12
+ }
13
+ /**
14
+ * Sets the values AntelopeJS Cloud can decide on an environment of the
15
+ * project the tenant publishes: the addresses of its app and its dashboard,
16
+ * the header AntelopeJS Cloud's gateway sets, and the secrets the project
17
+ * owns, generated here and sent as secrets. The plan is computed from a new
18
+ * read, so a variable a service holds by then is left as it is. A generated
19
+ * secret is never logged nor stored, and none is answered but the setup
20
+ * token, once.
21
+ *
22
+ * @param environment The environment, by id or by name
23
+ * @throws The refusal of a tenant without a project, of an environment the
24
+ * project lacks, of one with nothing left to decide, or of a write
25
+ * AntelopeJS Cloud refuses
26
+ */
27
+ export declare function setDecided(tenantId: string, environment: string): Promise<DecidedAnswer>;