@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,462 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NO_GITHUB_REMOTE = exports.CONNECTION_ROUTES = void 0;
4
+ exports.connectionRoute = connectionRoute;
5
+ exports.connectionBanner = connectionBanner;
6
+ exports.guardAnswer = guardAnswer;
7
+ exports.accountItems = accountItems;
8
+ exports.workspaceItems = workspaceItems;
9
+ exports.repositoryItems = repositoryItems;
10
+ exports.remoteAnswer = remoteAnswer;
11
+ exports.disconnectBanner = disconnectBanner;
12
+ exports.signOutBanner = signOutBanner;
13
+ exports.managedProjectDialog = managedProjectDialog;
14
+ exports.projectDialog = projectDialog;
15
+ const web_url_1 = require("../web-url");
16
+ const confirm_dialog_1 = require("@antelopejs/interface-dms/base/confirm-dialog");
17
+ const default_types_1 = require("@antelopejs/interface-dms/base/data-types/default-types");
18
+ const page_1 = require("@antelopejs/interface-dms/page");
19
+ const slugs_1 = require("../pages/slugs");
20
+ /** The routes of the Connection page, relative to it. */
21
+ exports.CONNECTION_ROUTES = {
22
+ banner: "/banner",
23
+ state: "/state",
24
+ account: "/account",
25
+ workspace: "/workspace",
26
+ repository: "/repository",
27
+ disconnectBanner: "/disconnect-banner",
28
+ signOutBanner: "/sign-out-banner",
29
+ projectDialog: "/project-dialog",
30
+ connect: "/connect",
31
+ cancel: "/cancel",
32
+ project: "/project",
33
+ disconnect: "/disconnect",
34
+ signOut: "/sign-out",
35
+ apiStatus: "/api-status",
36
+ };
37
+ const MS_PER_MINUTE = 60_000;
38
+ /** The URL of a Connection page route, as a block or a button names it. */
39
+ function connectionRoute(route) {
40
+ return (0, page_1.pageRoutePath)((0, slugs_1.modulePageSlug)("connection"), route);
41
+ }
42
+ function post(route, successMessage) {
43
+ return {
44
+ type: "api",
45
+ url: connectionRoute(route),
46
+ method: "POST",
47
+ successMessage,
48
+ };
49
+ }
50
+ const CONNECT = {
51
+ label: "Connect",
52
+ icon: "i-ph-plugs-connected",
53
+ target: post(exports.CONNECTION_ROUTES.connect, "Confirm the code to finish"),
54
+ };
55
+ const FAILURES = {
56
+ denied: {
57
+ title: "The sign-in was refused",
58
+ description: "The code was declined in AntelopeJS Cloud. Connect again to get a new one.",
59
+ },
60
+ expired: {
61
+ title: "The code expired before it was approved",
62
+ description: "Connect again to get a new code.",
63
+ },
64
+ };
65
+ function plural(count, noun) {
66
+ return `${count} ${noun}${count === 1 ? "" : "s"}`;
67
+ }
68
+ const MANAGED_ACCESS_BANNERS = {
69
+ revoked: {
70
+ title: "AntelopeJS Cloud no longer accepts this environment's token",
71
+ description: "Restart the development environment from AntelopeJS Cloud to get a new one. Publishing still pushes to GitHub, but can't show build status or manage environments.",
72
+ },
73
+ forbidden: {
74
+ title: "AntelopeJS Cloud does not allow this token here",
75
+ description: "The token of a development environment reaches its own project only.",
76
+ },
77
+ missing: {
78
+ title: "AntelopeJS Cloud has no such project any more",
79
+ description: "The project this development environment was made for is gone.",
80
+ },
81
+ };
82
+ /** The banner of a connection AntelopeJS Cloud manages: one only when the cloud refuses what it gave. */
83
+ function managedBanner(access) {
84
+ if (access !== "revoked" && access !== "forbidden" && access !== "missing") {
85
+ return null;
86
+ }
87
+ return { tone: "warning", ...MANAGED_ACCESS_BANNERS[access] };
88
+ }
89
+ /** The call to action at the top of the page, `null` when there is none. */
90
+ function connectionBanner(view, access) {
91
+ if (view.state === "connected" && view.managed) {
92
+ return managedBanner(access);
93
+ }
94
+ if (view.state === "disconnected") {
95
+ return {
96
+ tone: "primary",
97
+ title: "Not connected to AntelopeJS Cloud",
98
+ description: "Sign in with your AntelopeJS Cloud account to link this DMS to a workspace and a project.",
99
+ actions: [CONNECT],
100
+ };
101
+ }
102
+ if (view.state === "pending") {
103
+ const minutes = Math.round((view.expiresAt.getTime() - view.startedAt.getTime()) / MS_PER_MINUTE);
104
+ return {
105
+ tone: "info",
106
+ title: "Waiting for approval",
107
+ description: `Confirm the code below within ${plural(minutes, "minute")}.`,
108
+ actions: [
109
+ {
110
+ label: "Cancel",
111
+ color: "neutral",
112
+ target: post(exports.CONNECTION_ROUTES.cancel, "Sign-in cancelled"),
113
+ },
114
+ ],
115
+ };
116
+ }
117
+ if (view.state === "failed") {
118
+ return {
119
+ tone: "warning",
120
+ ...FAILURES[view.reason],
121
+ actions: [{ ...CONNECT, label: "Connect again" }],
122
+ };
123
+ }
124
+ if (access === "revoked") {
125
+ return {
126
+ tone: "warning",
127
+ title: "Your AntelopeJS Cloud sign-in was revoked",
128
+ description: "Publishing still pushes to GitHub, but can't show build status or manage environments.",
129
+ actions: [{ ...CONNECT, label: "Sign in again" }],
130
+ };
131
+ }
132
+ if (view.projectId !== null)
133
+ return null;
134
+ return {
135
+ tone: "info",
136
+ title: "Choose the project this DMS publishes",
137
+ description: `Signed in to the workspace ${view.workspace.name ?? view.workspace.id}.`,
138
+ actions: [
139
+ {
140
+ label: "Choose project",
141
+ icon: "i-ph-folder-simple",
142
+ target: post(exports.CONNECTION_ROUTES.project, "Project chosen"),
143
+ confirm: { from: connectionRoute(exports.CONNECTION_ROUTES.projectDialog) },
144
+ },
145
+ { label: "Open first-run setup", to: slugs_1.SETUP_PAGE_SLUG },
146
+ ],
147
+ };
148
+ }
149
+ /** Whether the page shows the connection's sections, and the code while one is pending. */
150
+ function guardAnswer(view) {
151
+ if (view.state !== "pending") {
152
+ return { connected: view.state === "connected" };
153
+ }
154
+ const link = URL.parse(view.verificationUri);
155
+ const shown = link ? `${link.host}${link.pathname}` : view.verificationUri;
156
+ const confirmAt = (0, web_url_1.webUrl)(view.verificationUriComplete);
157
+ return {
158
+ connected: false,
159
+ emptyState: {
160
+ title: "Your code",
161
+ description: "Open the link and confirm this code, signed in to your AntelopeJS Cloud workspace.",
162
+ icon: "i-ph-device-mobile",
163
+ code: { content: view.userCode },
164
+ actions: confirmAt
165
+ ? [
166
+ {
167
+ label: `Open ${shown}`,
168
+ icon: "i-ph-arrow-square-out",
169
+ to: confirmAt,
170
+ },
171
+ ]
172
+ : [],
173
+ },
174
+ };
175
+ }
176
+ const MANAGED_BY_CLOUD = "Managed by AntelopeJS Cloud";
177
+ const MANAGED_ACCOUNT_ITEMS = [
178
+ {
179
+ id: "account",
180
+ label: "Account",
181
+ value: MANAGED_BY_CLOUD,
182
+ detail: "This DMS runs in an AntelopeJS Cloud development environment: nobody signs it in.",
183
+ },
184
+ {
185
+ id: "credentials",
186
+ label: "Credentials",
187
+ value: MANAGED_BY_CLOUD,
188
+ type: "status",
189
+ tone: "success",
190
+ detail: "A token limited to this project, given by the environment. It is never stored and never sent to the browser.",
191
+ },
192
+ ];
193
+ /** Who signed the workspace in, and how its token is kept. */
194
+ function accountItems(view) {
195
+ if (view.state !== "connected")
196
+ return [];
197
+ if (view.managed)
198
+ return MANAGED_ACCOUNT_ITEMS;
199
+ return [
200
+ { id: "connectedBy", label: "Connected by", value: view.connectedBy },
201
+ {
202
+ id: "connectedAt",
203
+ label: "Connected",
204
+ value: view.connectedAt.toISOString(),
205
+ type: "date",
206
+ },
207
+ {
208
+ id: "credentials",
209
+ label: "Credentials",
210
+ value: "Encrypted on this server",
211
+ type: "status",
212
+ tone: "success",
213
+ detail: "A workspace token issued by the device flow. Revoke it from your AntelopeJS Cloud profile.",
214
+ },
215
+ ];
216
+ }
217
+ const MANAGED_TOKEN_REFUSED = "AntelopeJS Cloud refused this environment's token";
218
+ const PROJECT_UNAVAILABLE = {
219
+ revoked: "AntelopeJS Cloud refused the stored sign-in",
220
+ missing: "AntelopeJS Cloud has no such project any more",
221
+ forbidden: "AntelopeJS Cloud does not allow this token here",
222
+ unreachable: "AntelopeJS Cloud did not answer",
223
+ };
224
+ function projectItems(view, project) {
225
+ if (view.projectId === null || project === undefined) {
226
+ return [
227
+ {
228
+ id: "project",
229
+ label: "Project",
230
+ value: "Not chosen",
231
+ type: "status",
232
+ tone: "warning",
233
+ },
234
+ ];
235
+ }
236
+ if (project.kind !== "ok") {
237
+ return [
238
+ {
239
+ id: "project",
240
+ label: "Project",
241
+ value: "Unavailable",
242
+ type: "status",
243
+ tone: "warning",
244
+ detail: view.managed && project.kind === "revoked"
245
+ ? MANAGED_TOKEN_REFUSED
246
+ : PROJECT_UNAVAILABLE[project.kind],
247
+ },
248
+ ];
249
+ }
250
+ const { slug, region, environments } = project.value;
251
+ const services = environments.reduce((count, environment) => count + environment.services.length, 0);
252
+ return [
253
+ {
254
+ id: "project",
255
+ label: "Project",
256
+ value: slug,
257
+ type: "mono",
258
+ detail: `${plural(environments.length, "environment")} · ${plural(services, "service")}`,
259
+ },
260
+ {
261
+ id: "region",
262
+ label: "Region",
263
+ value: region,
264
+ type: "mono",
265
+ detail: "Set when the project was created. Data and services stay there.",
266
+ },
267
+ ];
268
+ }
269
+ /** The workspace signed in and the project this DMS publishes. */
270
+ function workspaceItems(view, project) {
271
+ if (view.state !== "connected")
272
+ return [];
273
+ if (view.managed)
274
+ return projectItems(view, project);
275
+ const { id, name } = view.workspace;
276
+ const workspace = {
277
+ id: "workspace",
278
+ label: "Workspace",
279
+ value: name ?? id,
280
+ };
281
+ if (name !== null)
282
+ workspace.detail = id;
283
+ return [workspace, ...projectItems(view, project)];
284
+ }
285
+ /** The repository the module publishes: its origin remote and branch. */
286
+ function repositoryItems(repository) {
287
+ const { remote, branch } = repository;
288
+ const remoteItem = remote
289
+ ? {
290
+ id: "remote",
291
+ label: "Remote",
292
+ value: remote.label,
293
+ type: "mono",
294
+ detail: "Read from git config remote.origin.url.",
295
+ }
296
+ : {
297
+ id: "remote",
298
+ label: "Remote",
299
+ value: "No origin remote",
300
+ type: "status",
301
+ tone: "warning",
302
+ detail: "AntelopeJS Cloud builds from a GitHub repository.",
303
+ };
304
+ if (remote?.webUrl)
305
+ remoteItem.to = remote.webUrl;
306
+ return [
307
+ remoteItem,
308
+ {
309
+ id: "branch",
310
+ label: "Working branch",
311
+ value: branch ?? "Detached HEAD",
312
+ type: "mono",
313
+ },
314
+ ];
315
+ }
316
+ const DEFAULT_BRANCH = "main";
317
+ /**
318
+ * Whether AntelopeJS Cloud can build the repository the module publishes: its
319
+ * origin is on GitHub. When it is not, the git commands that make it so.
320
+ */
321
+ function remoteAnswer(repository) {
322
+ if (repository.remote?.webUrl)
323
+ return { remote: true };
324
+ const add = repository.remote ? "remote set-url" : "remote add";
325
+ const branch = repository.branch ?? DEFAULT_BRANCH;
326
+ return {
327
+ remote: false,
328
+ emptyState: {
329
+ code: {
330
+ language: "shell",
331
+ content: `git ${add} origin git@github.com:<owner>/<name>.git\ngit push -u origin ${branch}`,
332
+ },
333
+ },
334
+ };
335
+ }
336
+ /** Why a page's repository `Guard` shows nothing: origin is not on GitHub. */
337
+ exports.NO_GITHUB_REMOTE = {
338
+ title: "This project has no GitHub remote",
339
+ description: "AntelopeJS Cloud builds from GitHub: each environment follows a branch. Create a repository, then add it as origin.",
340
+ icon: "i-ph-github-logo",
341
+ };
342
+ /** The Disconnect row of the danger zone, while a project is chosen. */
343
+ function disconnectBanner(view) {
344
+ if (view.state !== "connected" || view.managed)
345
+ return null;
346
+ if (view.projectId === null)
347
+ return null;
348
+ return {
349
+ tone: "warning",
350
+ size: "sm",
351
+ title: "Disconnect this project",
352
+ description: "Removes the link to the project. Your environments keep running on AntelopeJS Cloud; reconnect at any time.",
353
+ actions: [
354
+ {
355
+ label: "Disconnect",
356
+ color: "warning",
357
+ target: post(exports.CONNECTION_ROUTES.disconnect, "Project disconnected"),
358
+ confirm: {
359
+ title: "Disconnect this project?",
360
+ description: "Nothing is deleted on AntelopeJS Cloud: your environments keep running. The sign-in is kept.",
361
+ icon: "i-ph-link-break",
362
+ color: "warning",
363
+ confirmLabel: "Disconnect",
364
+ },
365
+ },
366
+ ],
367
+ };
368
+ }
369
+ /** The Sign out row of the danger zone, while the workspace is signed in. */
370
+ function signOutBanner(view) {
371
+ if (view.state !== "connected" || view.managed)
372
+ return null;
373
+ return {
374
+ tone: "error",
375
+ size: "sm",
376
+ title: "Sign out of AntelopeJS Cloud",
377
+ description: "Deletes the token this server stores. Revoke it from your AntelopeJS Cloud profile as well.",
378
+ actions: [
379
+ {
380
+ label: "Sign out",
381
+ color: "error",
382
+ target: post(exports.CONNECTION_ROUTES.signOut, "Signed out of AntelopeJS Cloud"),
383
+ confirm: {
384
+ title: "Sign out of AntelopeJS Cloud?",
385
+ description: "This DMS forgets the project and the workspace token. Nothing is deleted on AntelopeJS Cloud.",
386
+ icon: "i-ph-sign-out",
387
+ color: "error",
388
+ confirmLabel: "Sign out",
389
+ },
390
+ },
391
+ ],
392
+ };
393
+ }
394
+ const BLOCKED_PROJECT_DIALOGS = {
395
+ revoked: {
396
+ title: "Your AntelopeJS Cloud sign-in was revoked",
397
+ description: "Sign in again to choose a project.",
398
+ },
399
+ missing: {
400
+ title: "AntelopeJS Cloud did not list the projects",
401
+ description: "Try again in a moment.",
402
+ },
403
+ forbidden: {
404
+ title: "AntelopeJS Cloud does not allow this token here",
405
+ description: "This sign-in can't list the projects of the workspace.",
406
+ },
407
+ unreachable: {
408
+ title: "AntelopeJS Cloud did not answer",
409
+ description: "Try again in a moment.",
410
+ },
411
+ };
412
+ /** The dialog the Choose project button would open on a connection AntelopeJS Cloud manages. */
413
+ function managedProjectDialog() {
414
+ return (0, confirm_dialog_1.serializeConfirmDialog)({
415
+ title: MANAGED_BY_CLOUD,
416
+ description: "The project of a development environment is the one AntelopeJS Cloud made it for.",
417
+ blocked: true,
418
+ });
419
+ }
420
+ /** The dialog the Choose project button opens: the workspace's projects. */
421
+ function projectDialog(projects) {
422
+ if (projects === undefined) {
423
+ return (0, confirm_dialog_1.serializeConfirmDialog)({
424
+ title: "Not connected to AntelopeJS Cloud",
425
+ description: "Connect this DMS before you choose a project.",
426
+ blocked: true,
427
+ });
428
+ }
429
+ if (projects.kind !== "ok") {
430
+ return (0, confirm_dialog_1.serializeConfirmDialog)({
431
+ ...BLOCKED_PROJECT_DIALOGS[projects.kind],
432
+ blocked: true,
433
+ });
434
+ }
435
+ if (projects.value.projects.length === 0) {
436
+ return (0, confirm_dialog_1.serializeConfirmDialog)({
437
+ title: "This workspace has no project yet",
438
+ description: "Create a project in AntelopeJS Cloud, then choose it here.",
439
+ blocked: true,
440
+ });
441
+ }
442
+ return (0, confirm_dialog_1.serializeConfirmDialog)({
443
+ title: "Choose the project",
444
+ description: "This DMS publishes to the project you choose.",
445
+ icon: "i-ph-folder-simple",
446
+ confirmLabel: "Use this project",
447
+ fields: [
448
+ {
449
+ id: "projectId",
450
+ label: "Project",
451
+ required: true,
452
+ type: new default_types_1.DefaultDataTypes.SelectType({
453
+ items: projects.value.projects.map(({ id, slug }) => ({
454
+ label: slug,
455
+ value: id,
456
+ })),
457
+ }),
458
+ },
459
+ ],
460
+ });
461
+ }
462
+ //# sourceMappingURL=content.js.map
@@ -0,0 +1,26 @@
1
+ import { type ConnectedConnection, type StoredConnection } from "./store";
2
+ /**
3
+ * The connection of a DMS that runs in an AntelopeJS Cloud development
4
+ * environment: Cloud gave it a token and a project through the module's
5
+ * options, so nothing of it is stored and no token is held here.
6
+ */
7
+ export interface ManagedConnection {
8
+ /** The id of the DMS workspace (tenant). */
9
+ readonly _id: string;
10
+ readonly state: "connected";
11
+ readonly managed: true;
12
+ /** The project the token is limited to. */
13
+ readonly projectId: string;
14
+ }
15
+ /** What a DMS workspace reads when it is connected: a stored sign-in, or the managed connection. */
16
+ export type ActiveConnection = ConnectedConnection | ManagedConnection;
17
+ /** What a DMS workspace's connection reads as: what is stored, or the managed connection. */
18
+ export type CurrentConnection = StoredConnection | ManagedConnection;
19
+ /** Whether the connection is the managed one, whose token the options hold. */
20
+ export declare function isManaged(connection: CurrentConnection): connection is ManagedConnection;
21
+ /**
22
+ * The tenant's connection: the managed one, whatever is stored, when the
23
+ * module runs in a Cloud development environment, else what the tenant stored
24
+ * or `undefined` when it has none.
25
+ */
26
+ export declare function readConnection(tenantId: string): Promise<CurrentConnection | undefined>;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isManaged = isManaged;
4
+ exports.readConnection = readConnection;
5
+ const config_1 = require("../config");
6
+ const store_1 = require("./store");
7
+ /** Whether the connection is the managed one, whose token the options hold. */
8
+ function isManaged(connection) {
9
+ return "managed" in connection;
10
+ }
11
+ /**
12
+ * The tenant's connection: the managed one, whatever is stored, when the
13
+ * module runs in a Cloud development environment, else what the tenant stored
14
+ * or `undefined` when it has none.
15
+ */
16
+ async function readConnection(tenantId) {
17
+ const { managed } = (0, config_1.cloudSettings)();
18
+ if (managed) {
19
+ return {
20
+ _id: tenantId,
21
+ state: "connected",
22
+ managed: true,
23
+ projectId: managed.projectId,
24
+ };
25
+ }
26
+ return (0, store_1.connections)().read(tenantId);
27
+ }
28
+ //# sourceMappingURL=current.js.map
@@ -0,0 +1,16 @@
1
+ import { type DeviceAuthorization } from "@antelopejs/cloud-sdk";
2
+ import { type Sealed } from "./seal";
3
+ /** How AntelopeJS Cloud names this server among the devices a person approved. */
4
+ export declare const DEVICE_NAME = "AntelopeJS DMS";
5
+ /**
6
+ * Stores the tenant's device sign-in in place of a pending or failed one, or
7
+ * of the sign-in whose token is `revokedToken`, and polls it until it is
8
+ * approved, refused or expired.
9
+ *
10
+ * @returns Whether it started: `false` when the tenant is signed in.
11
+ */
12
+ export declare function startDeviceFlow(tenantId: string, startedBy: string, authorization: DeviceAuthorization, revokedToken: Sealed | undefined): Promise<boolean>;
13
+ /** Polls every stored sign-in still pending, as after a restart. */
14
+ export declare function resumeDeviceFlows(): Promise<void>;
15
+ /** Stops polling. A stored sign-in stays pending for the next start. */
16
+ export declare function stopDeviceFlows(): void;
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEVICE_NAME = void 0;
4
+ exports.startDeviceFlow = startDeviceFlow;
5
+ exports.resumeDeviceFlows = resumeDeviceFlows;
6
+ exports.stopDeviceFlows = stopDeviceFlows;
7
+ const cloud_sdk_1 = require("@antelopejs/cloud-sdk");
8
+ const config_1 = require("../config");
9
+ const announce_1 = require("./announce");
10
+ const cloud_1 = require("./cloud");
11
+ const seal_1 = require("./seal");
12
+ const store_1 = require("./store");
13
+ /** How AntelopeJS Cloud names this server among the devices a person approved. */
14
+ exports.DEVICE_NAME = "AntelopeJS DMS";
15
+ const SLOW_DOWN_S = 5;
16
+ const RETRY_S = 5;
17
+ const MS_PER_S = 1_000;
18
+ const PENDING = { kind: "pending" };
19
+ const EXPIRED = { kind: "refused", reason: "expired" };
20
+ const EXCHANGE_REFUSALS = new Map([
21
+ ["authorization_pending", PENDING],
22
+ ["slow_down", { kind: "slow-down" }],
23
+ ["access_denied", { kind: "refused", reason: "denied" }],
24
+ ["expired_token", EXPIRED],
25
+ ["invalid_grant", { kind: "spent" }],
26
+ ]);
27
+ const followedFlows = new Map();
28
+ let activeRun;
29
+ async function exchange(deviceCode) {
30
+ try {
31
+ return {
32
+ kind: "approved",
33
+ token: await (0, cloud_sdk_1.exchangeDevice)(deviceCode, (0, cloud_1.endpoint)()),
34
+ };
35
+ }
36
+ catch (error) {
37
+ if (!(error instanceof cloud_sdk_1.CloudApiError))
38
+ return PENDING;
39
+ return EXCHANGE_REFUSALS.get(error.code) ?? PENDING;
40
+ }
41
+ }
42
+ function settled(stored, result, now) {
43
+ if (result.kind === "refused") {
44
+ return { _id: stored._id, state: "failed", reason: result.reason, at: now };
45
+ }
46
+ return {
47
+ _id: stored._id,
48
+ state: "connected",
49
+ token: (0, seal_1.seal)((0, config_1.cloudSettings)().sealingKey, stored._id, result.token.access_token),
50
+ workspaceId: result.token.workspace_id,
51
+ workspaceName: result.token.workspace_name ?? null,
52
+ projectId: null,
53
+ connectedBy: stored.startedBy,
54
+ connectedAt: now,
55
+ };
56
+ }
57
+ /**
58
+ * One poll of a flow, from what is stored: the seconds to wait before the
59
+ * next one, or `undefined` once the flow is over, settled here, by a request
60
+ * that cancelled or replaced it, or by the poller that traded its code.
61
+ */
62
+ async function poll(flow) {
63
+ const model = (0, store_1.connections)();
64
+ const stored = await model.read(flow.tenantId);
65
+ if (stored?.state !== "pending" || stored.device.data !== flow.device.data) {
66
+ return undefined;
67
+ }
68
+ const result = stored.expiresAt <= new Date()
69
+ ? EXPIRED
70
+ : await exchange((0, seal_1.open)((0, config_1.cloudSettings)().sealingKey, flow.tenantId, stored.device));
71
+ if (result.kind === "pending")
72
+ return stored.intervalS;
73
+ if (result.kind === "spent")
74
+ return undefined;
75
+ if (result.kind === "slow-down") {
76
+ const intervalS = stored.intervalS + SLOW_DOWN_S;
77
+ await model.slowFlow(flow.tenantId, flow.device, intervalS);
78
+ return intervalS;
79
+ }
80
+ await model.settleFlow(flow.device, settled(stored, result, new Date()));
81
+ await (0, announce_1.announce)(flow.tenantId);
82
+ return undefined;
83
+ }
84
+ function schedule(flow, delayS, owner) {
85
+ followedFlows.set(flow.device.data, setTimeout(() => void step(flow, owner), delayS * MS_PER_S));
86
+ }
87
+ async function step(flow, owner) {
88
+ followedFlows.set(flow.device.data, "polling");
89
+ const delayS = await poll(flow).catch(() => RETRY_S);
90
+ if (owner !== activeRun)
91
+ return;
92
+ if (delayS === undefined) {
93
+ followedFlows.delete(flow.device.data);
94
+ return;
95
+ }
96
+ schedule(flow, delayS, owner);
97
+ }
98
+ /** Polls a flow after `delayS`, unless this process polls it already. */
99
+ function follow(flow, delayS) {
100
+ if (!activeRun || followedFlows.has(flow.device.data))
101
+ return;
102
+ schedule(flow, delayS, activeRun);
103
+ }
104
+ /**
105
+ * Stores the tenant's device sign-in in place of a pending or failed one, or
106
+ * of the sign-in whose token is `revokedToken`, and polls it until it is
107
+ * approved, refused or expired.
108
+ *
109
+ * @returns Whether it started: `false` when the tenant is signed in.
110
+ */
111
+ async function startDeviceFlow(tenantId, startedBy, authorization, revokedToken) {
112
+ const now = new Date();
113
+ const pending = {
114
+ _id: tenantId,
115
+ state: "pending",
116
+ device: (0, seal_1.seal)((0, config_1.cloudSettings)().sealingKey, tenantId, authorization.device_code),
117
+ userCode: authorization.user_code,
118
+ verificationUri: authorization.verification_uri,
119
+ verificationUriComplete: authorization.verification_uri_complete,
120
+ expiresAt: new Date(now.getTime() + authorization.expires_in * MS_PER_S),
121
+ intervalS: authorization.interval,
122
+ startedBy,
123
+ startedAt: now,
124
+ };
125
+ if (!(await (0, store_1.connections)().startFlow(pending, revokedToken)))
126
+ return false;
127
+ follow({ tenantId, device: pending.device }, pending.intervalS);
128
+ return true;
129
+ }
130
+ /** Polls every stored sign-in still pending, as after a restart. */
131
+ async function resumeDeviceFlows() {
132
+ activeRun = Symbol("device flows");
133
+ for (const pending of await (0, store_1.connections)().pending()) {
134
+ follow({ tenantId: pending._id, device: pending.device }, pending.intervalS);
135
+ }
136
+ }
137
+ /** Stops polling. A stored sign-in stays pending for the next start. */
138
+ function stopDeviceFlows() {
139
+ activeRun = undefined;
140
+ for (const timer of followedFlows.values()) {
141
+ if (timer !== "polling")
142
+ clearTimeout(timer);
143
+ }
144
+ followedFlows.clear();
145
+ }
146
+ //# sourceMappingURL=device-flow.js.map