@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,115 @@
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.VersionsPage = void 0;
13
+ const interface_api_1 = require("@antelopejs/interface-api");
14
+ const default_types_1 = require("@antelopejs/interface-dms/base/data-types/default-types");
15
+ const table_view_1 = require("@antelopejs/interface-dms/base/table-view");
16
+ const page_1 = require("@antelopejs/interface-dms/page");
17
+ const config_1 = require("../config");
18
+ const refs_1 = require("../git/refs");
19
+ const repository_1 = require("../git/repository");
20
+ const versions_1 = require("../git/versions");
21
+ const navigation_1 = require("./navigation");
22
+ const slugs_1 = require("./slugs");
23
+ const LIST_ROUTE = "/list";
24
+ /** Where the page of one version lives, `{{row.number}}` filled from a table row. */
25
+ const VERSION_PAGE = `${(0, slugs_1.detailPageSlug)("version")}/{{row.number}}`;
26
+ /** Every published version of the project and the environments on each. */
27
+ let VersionsPage = class VersionsPage extends (0, page_1.PageController)("versions", (0, navigation_1.navigationEntry)("versions")) {
28
+ static versions = table_view_1.TableView.fromSource({
29
+ fetchUrl: (0, page_1.pageRoutePath)((0, slugs_1.modulePageSlug)("versions"), LIST_ROUTE),
30
+ rowIdKey: "tag",
31
+ rowClick: "single",
32
+ searchPlaceholder: "Search versions",
33
+ columns: {
34
+ name: {
35
+ name: "Version",
36
+ type: new default_types_1.DefaultDataTypes.StringType(),
37
+ display: new table_view_1.DefaultDisplays.TwoLineDisplay({ subField: "tag" }),
38
+ order: 0,
39
+ },
40
+ message: {
41
+ name: "Summary",
42
+ type: new default_types_1.DefaultDataTypes.StringType(),
43
+ order: 1,
44
+ },
45
+ shortCommit: {
46
+ name: "Commit",
47
+ type: new default_types_1.DefaultDataTypes.StringType(),
48
+ display: new table_view_1.DefaultDisplays.MonoDisplay(),
49
+ order: 2,
50
+ },
51
+ authorName: {
52
+ name: "Author",
53
+ type: new default_types_1.DefaultDataTypes.StringType(),
54
+ order: 3,
55
+ },
56
+ publishedAt: {
57
+ name: "Published",
58
+ type: new default_types_1.DefaultDataTypes.DateType(),
59
+ order: 4,
60
+ sortable: true,
61
+ },
62
+ environments: {
63
+ name: "Environments",
64
+ type: new default_types_1.DefaultDataTypes.StringType(),
65
+ display: new table_view_1.DefaultDisplays.PillsDisplay({ emptyLabel: "None" }),
66
+ order: 5,
67
+ },
68
+ },
69
+ rowActions: {
70
+ custom: [
71
+ {
72
+ label: "Open {name}",
73
+ icon: "i-ph-arrow-right",
74
+ target: { type: "page", url: VERSION_PAGE },
75
+ isDefault: true,
76
+ },
77
+ ],
78
+ },
79
+ emptyStates: {
80
+ firstRun: {
81
+ title: "No version published yet",
82
+ description: "Publish your unpublished changes to make the first version, release/v1.",
83
+ icon: "i-ph-tag",
84
+ actions: [
85
+ {
86
+ label: "Review unpublished changes",
87
+ to: (0, slugs_1.modulePageSlug)("changes"),
88
+ },
89
+ ],
90
+ },
91
+ },
92
+ });
93
+ async list() {
94
+ const read = await (0, repository_1.readRepository)((0, config_1.cloudSettings)().repositoryPath, "recent");
95
+ if (read.kind === "refused")
96
+ return { results: [], total: 0 };
97
+ const results = (0, versions_1.listVersions)(read.snapshot).map((version) => ({
98
+ ...version,
99
+ shortCommit: (0, refs_1.shortSha)(version.commit),
100
+ authorName: version.author.name,
101
+ }));
102
+ return { results, total: results.length };
103
+ }
104
+ };
105
+ exports.VersionsPage = VersionsPage;
106
+ __decorate([
107
+ (0, interface_api_1.Get)(LIST_ROUTE),
108
+ __metadata("design:type", Function),
109
+ __metadata("design:paramtypes", []),
110
+ __metadata("design:returntype", Promise)
111
+ ], VersionsPage.prototype, "list", null);
112
+ exports.VersionsPage = VersionsPage = __decorate([
113
+ (0, page_1.RegisterPage)()
114
+ ], VersionsPage);
115
+ //# sourceMappingURL=versions.js.map
@@ -0,0 +1,15 @@
1
+ import type { CurrentConnection } from "../connection/current";
2
+ /**
3
+ * Asks AntelopeJS Cloud, signed in with the tenant's stored token, to create
4
+ * the databases the running project's modules need on an environment, named
5
+ * by name or id, or the project's first one. Cloud computes the plan again
6
+ * and refuses before any write when it cannot be applied. The environment's
7
+ * apps are then connected to its databases, those it ran before included:
8
+ * each gets the variable the project's `envOverrides` feed the module's
9
+ * address from, following the connection variable the database publishes.
10
+ * The tenant's open Resources pages then read again.
11
+ *
12
+ * @throws The refusal to answer with, as an `HTTPResult` whose message is an
13
+ * i18n key the dashboard translates.
14
+ */
15
+ export declare function applyResources(tenantId: string, stored: CurrentConnection | undefined, requested: string | undefined): Promise<void>;
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applyResources = applyResources;
4
+ const cloud_sdk_1 = require("@antelopejs/cloud-sdk");
5
+ const refusals_1 = require("../connection/refusals");
6
+ const announce_1 = require("../connection/announce");
7
+ const cloud_1 = require("../connection/cloud");
8
+ const project_config_1 = require("../variables/project-config");
9
+ const roles_1 = require("../environments/roles");
10
+ const connect_1 = require("./connect");
11
+ const modules_1 = require("./modules");
12
+ const refusals_2 = require("./refusals");
13
+ const read_1 = require("./read");
14
+ const routes_1 = require("./routes");
15
+ const HTTP_CONFLICT = 409;
16
+ const HTTP_UNPROCESSABLE = 422;
17
+ const HTTP_UNAVAILABLE = 503;
18
+ const NO_PROJECT_CHOSEN = (0, refusals_1.badRequest)("project_required");
19
+ const APPLY_REFUSALS = {
20
+ busy: { status: HTTP_UNAVAILABLE, error: "resources.apply_in_progress" },
21
+ missing: {
22
+ status: HTTP_UNPROCESSABLE,
23
+ error: "resources.unknown_environment",
24
+ },
25
+ unconnected: { status: HTTP_CONFLICT, error: "resources.connect_failed" },
26
+ };
27
+ const CLIENT_ERRORS = { from: 400, to: 499 };
28
+ const HTTP_UNAUTHORIZED = 401;
29
+ /**
30
+ * Connects the apps of an environment to its databases: each app service
31
+ * gets the variables it lacks, following what its databases publish.
32
+ * A variable AntelopeJS Cloud refuses leaves the databases as they are, and
33
+ * reads as `unconnected`.
34
+ */
35
+ async function tryConnect(api, projectId, environment, config) {
36
+ try {
37
+ const [{ resources }, { variables }] = await Promise.all([
38
+ api.environmentResources(projectId, environment.id),
39
+ api.listVariables(projectId, environment.id),
40
+ ]);
41
+ const { apps: serviceIds } = await (0, roles_1.rolesAmong)(api, environment.services, new Set(resources.map(({ serviceId }) => serviceId)));
42
+ const { missing } = (0, connect_1.plannedConnections)({ resources, serviceIds, variables }, config);
43
+ await (0, connect_1.connect)(api, missing);
44
+ return { kind: "applied" };
45
+ }
46
+ catch (error) {
47
+ const isRefused = error instanceof cloud_sdk_1.CloudApiError &&
48
+ error.status !== HTTP_UNAUTHORIZED &&
49
+ error.status >= CLIENT_ERRORS.from &&
50
+ error.status <= CLIENT_ERRORS.to;
51
+ if (!isRefused)
52
+ throw error;
53
+ return { kind: "unconnected" };
54
+ }
55
+ }
56
+ async function tryApply(api, projectId, environmentId, packages) {
57
+ try {
58
+ await api.applyResources(projectId, environmentId, packages);
59
+ return { kind: "applied" };
60
+ }
61
+ catch (error) {
62
+ if (!(error instanceof cloud_sdk_1.CloudApiError))
63
+ throw error;
64
+ if (error.status === HTTP_UNAVAILABLE)
65
+ return { kind: "busy" };
66
+ const refusal = error.status === HTTP_CONFLICT
67
+ ? (0, refusals_2.refusalOfCloudKey)(error.code)
68
+ : undefined;
69
+ if (!refusal)
70
+ throw error;
71
+ return { kind: "refused", refusal };
72
+ }
73
+ }
74
+ function refusalOf(answer) {
75
+ if (answer.kind === "refused") {
76
+ return {
77
+ status: HTTP_CONFLICT,
78
+ error: `resources.${refusals_2.PLAN_REFUSALS[answer.refusal].key}`,
79
+ };
80
+ }
81
+ return APPLY_REFUSALS[answer.kind];
82
+ }
83
+ /**
84
+ * Asks AntelopeJS Cloud, signed in with the tenant's stored token, to create
85
+ * the databases the running project's modules need on an environment, named
86
+ * by name or id, or the project's first one. Cloud computes the plan again
87
+ * and refuses before any write when it cannot be applied. The environment's
88
+ * apps are then connected to its databases, those it ran before included:
89
+ * each gets the variable the project's `envOverrides` feed the module's
90
+ * address from, following the connection variable the database publishes.
91
+ * The tenant's open Resources pages then read again.
92
+ *
93
+ * @throws The refusal to answer with, as an `HTTPResult` whose message is an
94
+ * i18n key the dashboard translates.
95
+ */
96
+ async function applyResources(tenantId, stored, requested) {
97
+ if (stored?.state !== "connected")
98
+ throw (0, refusals_1.refuse)(refusals_1.NOT_CONNECTED);
99
+ const { projectId } = stored;
100
+ if (projectId === null)
101
+ throw (0, refusals_1.refuse)(NO_PROJECT_CHOSEN);
102
+ const [{ packages }, config] = await Promise.all([
103
+ (0, modules_1.readProjectModules)(),
104
+ (0, project_config_1.readProjectConfig)(),
105
+ ]);
106
+ const outcome = await (0, cloud_1.readCloud)(stored, async (api) => {
107
+ const project = await api.readProject(projectId);
108
+ const environment = (0, read_1.pickEnvironment)(project.environments, requested);
109
+ if (!environment)
110
+ return { kind: "missing" };
111
+ const applied = await tryApply(api, projectId, environment.id, packages);
112
+ return applied.kind === "applied"
113
+ ? tryConnect(api, projectId, environment, config)
114
+ : applied;
115
+ });
116
+ if (outcome.kind === "revoked")
117
+ await (0, announce_1.announce)(tenantId);
118
+ if (outcome.kind === "missing")
119
+ throw (0, refusals_1.refuse)(APPLY_REFUSALS.missing);
120
+ if (outcome.kind !== "ok") {
121
+ throw (0, refusals_1.refuse)((0, refusals_1.cloudRefusal)(outcome, APPLY_REFUSALS));
122
+ }
123
+ await (0, routes_1.announceResources)(tenantId);
124
+ if (outcome.value.kind !== "applied")
125
+ throw (0, refusals_1.refuse)(refusalOf(outcome.value));
126
+ }
127
+ //# sourceMappingURL=apply.js.map
@@ -0,0 +1,41 @@
1
+ import type { EnvironmentResource, PlannedResource, ResourcePlan, UnprovidedResource } from "@antelopejs/cloud-sdk";
2
+ import type { KeyValueListItem } from "@antelopejs/interface-dms/base/key-value-list";
3
+ import type { NavCardItem } from "@antelopejs/interface-dms/base/nav-card-grid";
4
+ import type { ProjectModules } from "./modules";
5
+ import type { ResourcesRead } from "./read";
6
+ type Environment = Extract<ResourcesRead, {
7
+ kind: "ok";
8
+ }>;
9
+ /**
10
+ * One resource card: a database that runs on the environment, one the plan
11
+ * creates, or a need AntelopeJS Cloud cannot provide.
12
+ */
13
+ export type ResourceCard = {
14
+ state: "running";
15
+ resource: EnvironmentResource;
16
+ } | {
17
+ state: "planned";
18
+ planned: PlannedResource;
19
+ } | {
20
+ state: "refused";
21
+ planned: PlannedResource;
22
+ } | {
23
+ state: "unprovided";
24
+ need: UnprovidedResource;
25
+ };
26
+ /**
27
+ * The cards of an environment: what runs, what the plan creates, or what it
28
+ * would create when Cloud refuses the plan, and what Cloud cannot provide.
29
+ */
30
+ export declare function resourceCards(resources: readonly EnvironmentResource[], plan: ResourcePlan): ResourceCard[];
31
+ /** The `NavCardGrid` item of a card: its look from the state table, its figures from the API. */
32
+ export declare function cardItem(card: ResourceCard, index: number): NavCardItem;
33
+ /**
34
+ * The "How this is derived" rows: each module of the project's
35
+ * `antelope.config.ts` and what it becomes on Cloud, then the modules that
36
+ * run inside the app service.
37
+ */
38
+ export declare function derivedItems(modules: ProjectModules, environment: Environment): KeyValueListItem[];
39
+ /** The environment and the ceilings of its plan, with what applying the plan would leave. */
40
+ export declare function limitItems(environment: Environment): KeyValueListItem[];
41
+ export {};
@@ -0,0 +1,211 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resourceCards = resourceCards;
4
+ exports.cardItem = cardItem;
5
+ exports.derivedItems = derivedItems;
6
+ exports.limitItems = limitItems;
7
+ const page_1 = require("@antelopejs/interface-dms/page");
8
+ const slugs_1 = require("../pages/slugs");
9
+ const format_1 = require("./format");
10
+ const CARD_STATES = {
11
+ running: { label: "Running", tone: "success", icon: "i-ph-database" },
12
+ planned: { label: "To create", tone: "warning", icon: "i-ph-plus-circle" },
13
+ refused: {
14
+ label: "Refused by your plan",
15
+ tone: "error",
16
+ icon: "i-ph-lock-simple",
17
+ },
18
+ unprovided: {
19
+ label: "Not available",
20
+ tone: "error",
21
+ icon: "i-ph-prohibit",
22
+ },
23
+ };
24
+ /** What each reason Cloud cannot provide a need says, below the card's title. */
25
+ const UNPROVIDED_REASONS = {
26
+ not_offered: {
27
+ label: "Not available",
28
+ text: "AntelopeJS Cloud does not run it yet. Point the app to a database you run elsewhere.",
29
+ },
30
+ not_on_plan: {
31
+ label: "Not on your plan",
32
+ text: "AntelopeJS Cloud runs it, but your plan does not include it.",
33
+ },
34
+ };
35
+ const MODE_TEXTS = { single: "single node", ha: "high availability" };
36
+ const VARIABLES_PAGE = `${page_1.MODULE_URL_PREFIX}/${slugs_1.MODULE_ID}/variables`;
37
+ /**
38
+ * The cards of an environment: what runs, what the plan creates, or what it
39
+ * would create when Cloud refuses the plan, and what Cloud cannot provide.
40
+ */
41
+ function resourceCards(resources, plan) {
42
+ return [
43
+ ...resources.map((resource) => ({ state: "running", resource })),
44
+ ...plan.create.map((planned) => ({
45
+ state: plan.canApply ? "planned" : "refused",
46
+ planned,
47
+ })),
48
+ ...plan.unprovided.map((need) => ({ state: "unprovided", need })),
49
+ ];
50
+ }
51
+ function figuresOf(resource) {
52
+ const { version, mode, instances, volumeGb, backups } = resource;
53
+ const readout = [
54
+ `${resource.connectionVariable}`,
55
+ backups ? "Backed up off the cluster" : "No backups",
56
+ ];
57
+ if (resource.monthlyCost)
58
+ readout.push((0, format_1.monthlyCostText)(resource.monthlyCost));
59
+ if (resource.module)
60
+ readout.push(`Serves ${resource.module}`);
61
+ return {
62
+ description: `${version} · ${MODE_TEXTS[mode]} · ${(0, format_1.plural)(instances, "instance")} · ${volumeGb} GB volume`,
63
+ readout,
64
+ };
65
+ }
66
+ function cardFigures(card) {
67
+ if (card.state === "running") {
68
+ return {
69
+ title: card.resource.label,
70
+ state: CARD_STATES.running.label,
71
+ details: figuresOf(card.resource),
72
+ };
73
+ }
74
+ if (card.state === "planned" || card.state === "refused") {
75
+ return {
76
+ title: card.planned.label,
77
+ state: CARD_STATES[card.state].label,
78
+ details: figuresOf(card.planned),
79
+ };
80
+ }
81
+ const reason = UNPROVIDED_REASONS[card.need.reason];
82
+ const readout = [`Serves ${card.need.module}`];
83
+ if (card.need.reason === "not_on_plan") {
84
+ readout.push(`Needs the ${card.need.requiredTier} plan or above`);
85
+ }
86
+ return {
87
+ title: card.need.resource,
88
+ state: reason.label,
89
+ details: { description: reason.text, readout },
90
+ };
91
+ }
92
+ /** The `NavCardGrid` item of a card: its look from the state table, its figures from the API. */
93
+ function cardItem(card, index) {
94
+ const { tone, icon } = CARD_STATES[card.state];
95
+ const { title, state, details } = cardFigures(card);
96
+ return {
97
+ id: `${card.state}-${index}`,
98
+ title,
99
+ icon,
100
+ iconTone: tone,
101
+ to: VARIABLES_PAGE,
102
+ state,
103
+ stateTone: tone,
104
+ ...details,
105
+ };
106
+ }
107
+ function placementsOf(module, environment) {
108
+ const { plan } = environment;
109
+ return [
110
+ ...plan.existing
111
+ .filter((existing) => existing.module === module)
112
+ .map(({ name }) => ({
113
+ text: `Running as ${name}`,
114
+ tone: CARD_STATES.running.tone,
115
+ })),
116
+ ...plan.create
117
+ .filter((planned) => planned.module === module)
118
+ .map(({ label, name }) => plan.canApply
119
+ ? {
120
+ text: `${label} to create as ${name}`,
121
+ tone: CARD_STATES.planned.tone,
122
+ }
123
+ : {
124
+ text: `${label} refused by your plan`,
125
+ tone: CARD_STATES.refused.tone,
126
+ }),
127
+ ...plan.unprovided
128
+ .filter((need) => need.module === module)
129
+ .map((need) => ({
130
+ text: `${need.resource}: ${UNPROVIDED_REASONS[need.reason].label.toLowerCase()}`,
131
+ tone: CARD_STATES.unprovided.tone,
132
+ })),
133
+ ];
134
+ }
135
+ const INSIDE_APP = {
136
+ text: "Runs inside the app service",
137
+ tone: "neutral",
138
+ };
139
+ function derivedRows(module, environment) {
140
+ const placements = placementsOf(module, environment);
141
+ return (placements.length > 0 ? placements : [INSIDE_APP]).map(({ text, tone }, index) => ({
142
+ id: `${module}-${index}`,
143
+ label: module,
144
+ value: text,
145
+ type: "status",
146
+ tone,
147
+ }));
148
+ }
149
+ /**
150
+ * The "How this is derived" rows: each module of the project's
151
+ * `antelope.config.ts` and what it becomes on Cloud, then the modules that
152
+ * run inside the app service.
153
+ */
154
+ function derivedItems(modules, environment) {
155
+ return [
156
+ ...modules.packages.flatMap((module) => derivedRows(module, environment)),
157
+ ...modules.inApp.map((module) => ({
158
+ id: `${module}-inside`,
159
+ label: module,
160
+ value: INSIDE_APP.text,
161
+ type: "status",
162
+ tone: INSIDE_APP.tone,
163
+ detail: "A local or git module of the project",
164
+ })),
165
+ ];
166
+ }
167
+ function ceilingText(use) {
168
+ const now = `${use.used} / ${use.ceiling}`;
169
+ return use.afterApply === use.used ? now : `${now} → ${use.afterApply}`;
170
+ }
171
+ /** The environment and the ceilings of its plan, with what applying the plan would leave. */
172
+ function limitItems(environment) {
173
+ const { limits } = environment.plan;
174
+ const { servicesPerEnvironment, databasesPerEnvironment } = limits;
175
+ const items = [
176
+ {
177
+ id: "environment",
178
+ label: "Environment",
179
+ value: environment.environment.name,
180
+ type: "mono",
181
+ },
182
+ {
183
+ id: "plan",
184
+ label: "Plan",
185
+ value: limits.planName ?? limits.tier,
186
+ detail: `${limits.tier} tier`,
187
+ },
188
+ {
189
+ id: "services",
190
+ label: "Services per environment",
191
+ value: ceilingText(servicesPerEnvironment),
192
+ type: "mono",
193
+ tone: servicesPerEnvironment.afterApply > servicesPerEnvironment.ceiling
194
+ ? "warning"
195
+ : undefined,
196
+ },
197
+ ];
198
+ if (databasesPerEnvironment) {
199
+ items.push({
200
+ id: "databases",
201
+ label: "Databases per environment",
202
+ value: ceilingText(databasesPerEnvironment),
203
+ type: "mono",
204
+ tone: databasesPerEnvironment.afterApply > databasesPerEnvironment.ceiling
205
+ ? "warning"
206
+ : undefined,
207
+ });
208
+ }
209
+ return items;
210
+ }
211
+ //# sourceMappingURL=cards.js.map
@@ -0,0 +1,66 @@
1
+ import type { CloudApi, EnvironmentResource, EnvironmentVariable } from "@antelopejs/cloud-sdk";
2
+ import { type ProjectConfig } from "../variables/project-config";
3
+ /** A database of an environment, as a connection names it. */
4
+ type Database = Pick<EnvironmentResource, "serviceId" | "label" | "connectionVariable">;
5
+ /**
6
+ * A variable an app service does not hold yet, which would carry a
7
+ * database's connection string into the module the database serves.
8
+ */
9
+ export interface Connection {
10
+ /** The app service that gets the variable. */
11
+ readonly serviceId: string;
12
+ /** The variable's name: an `envOverrides` entry of the project. */
13
+ readonly variable: string;
14
+ /** The database whose connection variable it follows. */
15
+ readonly database: Database;
16
+ }
17
+ /**
18
+ * A database whose connection string no `envOverrides` entry of the project
19
+ * carries into the module it serves.
20
+ */
21
+ export interface Unfed {
22
+ readonly database: Database;
23
+ /** The config path an `envOverrides` entry has to feed, such as `modules.mongodb.config.url`. */
24
+ readonly path: string;
25
+ /** A name the entry could take, such as `MONGODB_URL`: the project chooses its own. */
26
+ readonly suggestion: string;
27
+ }
28
+ /** What stands between the databases of an environment and its apps. */
29
+ export interface Connections {
30
+ /** The variables to add, at most one of a name per service. */
31
+ readonly missing: readonly Connection[];
32
+ readonly unfed: readonly Unfed[];
33
+ }
34
+ /** What {@link plannedConnections} reads of an environment. */
35
+ export interface ConnectionFacts {
36
+ /** The databases the environment runs. */
37
+ readonly resources: readonly EnvironmentResource[];
38
+ /**
39
+ * The ids of the services that may read a database: its apps, databases
40
+ * included or not. The dashboard of the project reads none and is left
41
+ * out.
42
+ */
43
+ readonly serviceIds: readonly string[];
44
+ /** The variables its services hold. */
45
+ readonly variables: readonly Pick<EnvironmentVariable, "serviceId" | "key">[];
46
+ }
47
+ /**
48
+ * What connecting an environment's databases to its apps takes. A database
49
+ * serves a module of the project; the module reads its address at
50
+ * `modules.<key>.config.url`, and the project's `envOverrides` name the
51
+ * variable that feeds that path. Each service of the environment that is not
52
+ * a database is to hold that variable; one that holds a variable of that
53
+ * name keeps it, and of two databases serving one module the first is
54
+ * followed. A database serving a module the project does not load takes
55
+ * nothing.
56
+ */
57
+ export declare function plannedConnections({ resources, serviceIds, variables }: ConnectionFacts, config: ProjectConfig): Connections;
58
+ /**
59
+ * Adds each missing variable to its service: it follows the connection
60
+ * variable its database publishes, so AntelopeJS Cloud keeps its value, which
61
+ * never reaches this server.
62
+ *
63
+ * @throws The `CloudApiError` of a variable AntelopeJS Cloud refuses
64
+ */
65
+ export declare function connect(api: CloudApi, missing: readonly Connection[]): Promise<void>;
66
+ export {};
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.plannedConnections = plannedConnections;
4
+ exports.connect = connect;
5
+ const model_1 = require("../variables/model");
6
+ const project_config_1 = require("../variables/project-config");
7
+ function urlPath(key) {
8
+ return `modules.${key}.config.url`;
9
+ }
10
+ function suggestedName(key) {
11
+ return `${key.replace(/[^A-Za-z0-9]+/g, "_").toUpperCase()}_URL`;
12
+ }
13
+ /**
14
+ * The names of the valid `envOverrides` entries that feed one of `paths`, in
15
+ * the order the file lists them.
16
+ */
17
+ function feeding(config, paths) {
18
+ return Object.entries(config.envOverrides).flatMap(([name, fed]) => model_1.variableKeySchema.safeParse(name).success &&
19
+ fed.some((path) => paths.includes(path))
20
+ ? [name]
21
+ : []);
22
+ }
23
+ /**
24
+ * What connecting an environment's databases to its apps takes. A database
25
+ * serves a module of the project; the module reads its address at
26
+ * `modules.<key>.config.url`, and the project's `envOverrides` name the
27
+ * variable that feeds that path. Each service of the environment that is not
28
+ * a database is to hold that variable; one that holds a variable of that
29
+ * name keeps it, and of two databases serving one module the first is
30
+ * followed. A database serving a module the project does not load takes
31
+ * nothing.
32
+ */
33
+ function plannedConnections({ resources, serviceIds, variables }, config) {
34
+ const databases = new Set(resources.map(({ serviceId }) => serviceId));
35
+ const apps = serviceIds.filter((id) => !databases.has(id));
36
+ const held = new Set(variables.map(({ serviceId, key }) => `${serviceId} ${key}`));
37
+ const missing = [];
38
+ const unfed = [];
39
+ for (const database of resources) {
40
+ const keys = database.module === null ? [] : (0, project_config_1.moduleKeysOf)(config, database.module);
41
+ if (keys.length === 0)
42
+ continue;
43
+ const names = feeding(config, keys.map(urlPath));
44
+ if (names.length === 0) {
45
+ unfed.push({
46
+ database,
47
+ path: urlPath(keys[0]),
48
+ suggestion: suggestedName(keys[0]),
49
+ });
50
+ continue;
51
+ }
52
+ for (const serviceId of apps) {
53
+ for (const variable of names) {
54
+ if (held.has(`${serviceId} ${variable}`))
55
+ continue;
56
+ held.add(`${serviceId} ${variable}`);
57
+ missing.push({ serviceId, variable, database });
58
+ }
59
+ }
60
+ }
61
+ return { missing, unfed };
62
+ }
63
+ /**
64
+ * Adds each missing variable to its service: it follows the connection
65
+ * variable its database publishes, so AntelopeJS Cloud keeps its value, which
66
+ * never reaches this server.
67
+ *
68
+ * @throws The `CloudApiError` of a variable AntelopeJS Cloud refuses
69
+ */
70
+ async function connect(api, missing) {
71
+ for (const { serviceId, variable, database } of missing) {
72
+ await api.followPublishedValue(serviceId, variable, {
73
+ serviceId: database.serviceId,
74
+ publishedKey: database.connectionVariable,
75
+ });
76
+ }
77
+ }
78
+ //# sourceMappingURL=connect.js.map
@@ -0,0 +1,26 @@
1
+ import type { BannerContent } from "@antelopejs/interface-dms/base/banner";
2
+ import type { NavCardItem } from "@antelopejs/interface-dms/base/nav-card-grid";
3
+ import type { ResourcesRead } from "./read";
4
+ /** What the page says of an environment the project does not list. */
5
+ export declare function unknownEnvironmentTexts(requested: string): {
6
+ title: string;
7
+ description: string;
8
+ };
9
+ /**
10
+ * The call to action at the top of the page: how many dependencies of the
11
+ * environment are not running yet, and the plan to review. On a plan Cloud
12
+ * refuses, it warns that they cannot be created. Once they all run, it says
13
+ * which database the app is not connected to, with the action that connects
14
+ * it, or the `envOverrides` line whose absence leaves a database unreachable.
15
+ * `null` when the plan creates nothing and every database is connected.
16
+ */
17
+ export declare function resourcesBanner(read: ResourcesRead): BannerContent | null;
18
+ /**
19
+ * What the next version adds to an environment, for the publish form: the
20
+ * databases the plan creates, named after the modules that need them, with a
21
+ * link to review the plan. On a plan Cloud refuses, it says the version needs
22
+ * them and publishing does not create them. `null` when it adds nothing.
23
+ */
24
+ export declare function publishNote(read: ResourcesRead): BannerContent | null;
25
+ /** The environments of the project, each a link to the page for it. */
26
+ export declare function environmentItems(read: ResourcesRead): NavCardItem[];