@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,84 @@
1
+ import type { KeyObject } from "node:crypto";
2
+ /** The module's options in a project's `antelope.config.ts`. */
3
+ export interface AntelopeCloudConfig {
4
+ /** Base URL of the AntelopeJS Cloud API. Defaults to `https://api.antelopejs.cloud`. */
5
+ apiUrl?: string;
6
+ /**
7
+ * The secret the AntelopeJS Cloud tokens this server stores are encrypted
8
+ * with: at least 32 characters. Without it the module does not run on this
9
+ * instance, which is what a deployed instance wants. Changing it makes the
10
+ * stored tokens unreadable, so every workspace signs in again.
11
+ */
12
+ secretKey?: string;
13
+ /**
14
+ * Root of the project's git work tree, the repository that Publishing
15
+ * commits, tags and pushes. A relative path resolves against the process's
16
+ * working directory, which is also the default.
17
+ */
18
+ repositoryPath?: string;
19
+ /**
20
+ * How the module follows the deployment a promotion starts, so that open
21
+ * pages show it build, then serve or fail: it reads the environment every
22
+ * `intervalMs` milliseconds, for at most `limitMs`. Defaults to every 5
23
+ * seconds for 10 minutes.
24
+ */
25
+ promotionFollow?: {
26
+ intervalMs?: number;
27
+ limitMs?: number;
28
+ };
29
+ /**
30
+ * The connection a Cloud development environment gives this instance: a
31
+ * token limited to one project (deploy and observe), and that project's id.
32
+ * Both set, the module is connected from its first start without a device
33
+ * sign-in, to that project: the token is never stored and never sent to the
34
+ * browser. Both left out, or empty as unset environment variables often
35
+ * read, the module signs in with a device code as usual. One alone is a
36
+ * mistake, and the options parser refuses it.
37
+ */
38
+ managed?: {
39
+ token?: string;
40
+ projectId?: string;
41
+ };
42
+ }
43
+ /** The module's options, parsed once at startup. */
44
+ export interface AntelopeCloudSettings {
45
+ /** The API base URL. Its path ends with a slash, so API paths resolve below it. */
46
+ readonly apiUrl: URL;
47
+ /** The AES key derived from `secretKey`. */
48
+ readonly sealingKey: KeyObject;
49
+ /** Absolute path of the project's git work tree. */
50
+ readonly repositoryPath: string;
51
+ /** How often and how long the module reads an environment it promoted to, in milliseconds. */
52
+ readonly promotionFollow: {
53
+ readonly intervalMs: number;
54
+ readonly limitMs: number;
55
+ };
56
+ /** The token and the project of a Cloud development environment, `null` outside one. */
57
+ readonly managed: {
58
+ readonly token: string;
59
+ readonly projectId: string;
60
+ } | null;
61
+ }
62
+ /**
63
+ * Parses the module's options.
64
+ *
65
+ * @throws When `apiUrl` is not an absolute http or https URL, or `secretKey`
66
+ * is missing or shorter than 32 characters, or `promotionFollow` holds
67
+ * other than positive whole numbers, or `managed` gives only one of its
68
+ * token and its projectId.
69
+ */
70
+ export declare function parseConfig(config: AntelopeCloudConfig): AntelopeCloudSettings;
71
+ /**
72
+ * Parses the options the module was started with and keeps them for its routes.
73
+ *
74
+ * @returns Whether the project configured the module. Without a `secretKey`
75
+ * nothing is parsed or kept, and the module stays out of this instance.
76
+ * @throws As {@link parseConfig} does, when the project did configure it.
77
+ */
78
+ export declare function configureCloudModule(config: AntelopeCloudConfig): boolean;
79
+ /**
80
+ * The options the module was started with.
81
+ *
82
+ * @throws Before `construct()` parsed them.
83
+ */
84
+ export declare function cloudSettings(): AntelopeCloudSettings;
package/dist/config.js ADDED
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseConfig = parseConfig;
4
+ exports.configureCloudModule = configureCloudModule;
5
+ exports.cloudSettings = cloudSettings;
6
+ const node_path_1 = require("node:path");
7
+ const zod_1 = require("zod");
8
+ const configured_1 = require("./configured");
9
+ const seal_1 = require("./connection/seal");
10
+ const DEFAULT_API_URL = "https://api.antelopejs.cloud";
11
+ const WEB_PROTOCOLS = new Set(["http:", "https:"]);
12
+ const MIN_SECRET_KEY_LENGTH = 32;
13
+ function parseApiUrl(raw) {
14
+ const apiUrl = URL.parse(raw);
15
+ if (!apiUrl || !WEB_PROTOCOLS.has(apiUrl.protocol)) {
16
+ throw new Error(`antelope-cloud: the apiUrl option must be an http or https URL, got "${raw}"`);
17
+ }
18
+ if (!apiUrl.pathname.endsWith("/"))
19
+ apiUrl.pathname += "/";
20
+ return apiUrl;
21
+ }
22
+ const secretKeySchema = zod_1.z.string().min(MIN_SECRET_KEY_LENGTH);
23
+ function parseSecretKey(secretKey) {
24
+ const parsed = secretKeySchema.safeParse(secretKey);
25
+ if (!parsed.success) {
26
+ throw new Error(`antelope-cloud: the secretKey option must be a string of at least ${MIN_SECRET_KEY_LENGTH} characters`);
27
+ }
28
+ return (0, seal_1.deriveSealingKey)(parsed.data);
29
+ }
30
+ const FOLLOW_INTERVAL_MS = 5_000;
31
+ const FOLLOW_LIMIT_MS = 600_000;
32
+ const promotionFollowSchema = zod_1.z
33
+ .object({
34
+ intervalMs: zod_1.z.number().int().positive().default(FOLLOW_INTERVAL_MS),
35
+ limitMs: zod_1.z.number().int().positive().default(FOLLOW_LIMIT_MS),
36
+ })
37
+ .default({});
38
+ function parsePromotionFollow(promotionFollow) {
39
+ const parsed = promotionFollowSchema.safeParse(promotionFollow);
40
+ if (!parsed.success) {
41
+ throw new Error("antelope-cloud: the promotionFollow option takes positive whole numbers of milliseconds");
42
+ }
43
+ return parsed.data;
44
+ }
45
+ const managedSchema = zod_1.z
46
+ .object({ token: zod_1.z.string().optional(), projectId: zod_1.z.string().optional() })
47
+ .nullish();
48
+ function parseManaged(managed) {
49
+ const parsed = managedSchema.safeParse(managed);
50
+ if (!parsed.success) {
51
+ throw new Error("antelope-cloud: the managed option takes a token and a projectId, both strings");
52
+ }
53
+ const token = parsed.data?.token?.trim() ?? "";
54
+ const projectId = parsed.data?.projectId?.trim() ?? "";
55
+ if (token === "" && projectId === "")
56
+ return null;
57
+ if (token === "" || projectId === "") {
58
+ throw new Error("antelope-cloud: the managed option needs both a token and a projectId, or neither");
59
+ }
60
+ return { token, projectId };
61
+ }
62
+ /**
63
+ * Parses the module's options.
64
+ *
65
+ * @throws When `apiUrl` is not an absolute http or https URL, or `secretKey`
66
+ * is missing or shorter than 32 characters, or `promotionFollow` holds
67
+ * other than positive whole numbers, or `managed` gives only one of its
68
+ * token and its projectId.
69
+ */
70
+ function parseConfig(config) {
71
+ return {
72
+ apiUrl: parseApiUrl(config.apiUrl ?? DEFAULT_API_URL),
73
+ sealingKey: parseSecretKey(config.secretKey),
74
+ repositoryPath: (0, node_path_1.resolve)(config.repositoryPath ?? "."),
75
+ promotionFollow: parsePromotionFollow(config.promotionFollow),
76
+ managed: parseManaged(config.managed),
77
+ };
78
+ }
79
+ let currentSettings;
80
+ /**
81
+ * Parses the options the module was started with and keeps them for its routes.
82
+ *
83
+ * @returns Whether the project configured the module. Without a `secretKey`
84
+ * nothing is parsed or kept, and the module stays out of this instance.
85
+ * @throws As {@link parseConfig} does, when the project did configure it.
86
+ */
87
+ function configureCloudModule(config) {
88
+ currentSettings = (0, configured_1.isCloudModuleConfigured)(config)
89
+ ? parseConfig(config)
90
+ : undefined;
91
+ return currentSettings !== undefined;
92
+ }
93
+ /**
94
+ * The options the module was started with.
95
+ *
96
+ * @throws Before `construct()` parsed them.
97
+ */
98
+ function cloudSettings() {
99
+ if (!currentSettings) {
100
+ throw new Error("antelope-cloud: the module options are not parsed yet");
101
+ }
102
+ return currentSettings;
103
+ }
104
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1,16 @@
1
+ import type { AntelopeCloudConfig } from "./config";
2
+ /**
3
+ * What the module prints, once, at startup when the project gave it no
4
+ * `secretKey`.
5
+ */
6
+ export declare const NOT_CONFIGURED_NOTICE: string;
7
+ /**
8
+ * Whether the project configured the module: it gave it a `secretKey`. A key
9
+ * left out, or empty as an unset environment variable often reads, means the
10
+ * module does not run on this instance. A key that is set and too short is a
11
+ * mistake, and the options parser refuses it.
12
+ *
13
+ * This file imports nothing at runtime: `frontend-module.ts` reads it, and
14
+ * `ajs dms` loads that file without the backend.
15
+ */
16
+ export declare function isCloudModuleConfigured(config: Pick<AntelopeCloudConfig, "secretKey"> | null | undefined): boolean;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NOT_CONFIGURED_NOTICE = void 0;
4
+ exports.isCloudModuleConfigured = isCloudModuleConfigured;
5
+ /**
6
+ * What the module prints, once, at startup when the project gave it no
7
+ * `secretKey`.
8
+ */
9
+ exports.NOT_CONFIGURED_NOTICE = "No secretKey is configured, so AntelopeJS Cloud publishing is not running on this instance: " +
10
+ "it adds no page and no route, and stores nothing. This is expected on a deployed instance, " +
11
+ "which has no git work tree to publish and must not hold an AntelopeJS Cloud token. " +
12
+ "Set the secretKey option where the project is published from.";
13
+ /**
14
+ * Whether the project configured the module: it gave it a `secretKey`. A key
15
+ * left out, or empty as an unset environment variable often reads, means the
16
+ * module does not run on this instance. A key that is set and too short is a
17
+ * mistake, and the options parser refuses it.
18
+ *
19
+ * This file imports nothing at runtime: `frontend-module.ts` reads it, and
20
+ * `ajs dms` loads that file without the backend.
21
+ */
22
+ function isCloudModuleConfigured(config) {
23
+ const secretKey = config?.secretKey;
24
+ return secretKey !== undefined && secretKey !== null && secretKey !== "";
25
+ }
26
+ //# sourceMappingURL=configured.js.map
@@ -0,0 +1,40 @@
1
+ import { z } from "zod";
2
+ import { type CloudRefusals } from "./refusals";
3
+ declare const projectChoiceSchema: z.ZodObject<{
4
+ projectId: z.ZodString;
5
+ }, "strip", z.ZodTypeAny, {
6
+ projectId: string;
7
+ }, {
8
+ projectId: string;
9
+ }>;
10
+ /** How a page refuses a read of a project: a project the workspace lacks is unknown. */
11
+ export declare const PROJECT_REFUSALS: CloudRefusals;
12
+ /**
13
+ * Starts a device sign-in for the tenant, in place of a pending or failed
14
+ * one. A signed-in tenant is refused unless AntelopeJS Cloud refuses its token,
15
+ * and so is a tenant signed in while the sign-in starts.
16
+ *
17
+ * @throws The `managed_connection` refusal when AntelopeJS Cloud manages the
18
+ * connection. So do the actions below.
19
+ */
20
+ export declare function connect(tenantId: string, startedBy: string): Promise<void>;
21
+ /** Forgets the tenant's pending or failed sign-in. A signed-in tenant stays. */
22
+ export declare function cancel(tenantId: string): Promise<void>;
23
+ /** What the Choose project dialog sends. */
24
+ export type ProjectChoice = z.infer<typeof projectChoiceSchema>;
25
+ /** Reads the body of the Choose project dialog. */
26
+ export declare function parseProjectChoice(body: Parameters<typeof projectChoiceSchema.safeParse>[0]): ProjectChoice | undefined;
27
+ /**
28
+ * Sets the project this DMS publishes, once AntelopeJS Cloud confirms the
29
+ * workspace has it. When AntelopeJS Cloud refuses the token, the open pages
30
+ * read the connection again and show the sign-in as revoked.
31
+ */
32
+ export declare function chooseProject(tenantId: string, choice: ProjectChoice | undefined): Promise<void>;
33
+ /** Forgets the project of the tenant's connection and keeps its sign-in. */
34
+ export declare function disconnect(tenantId: string): Promise<void>;
35
+ /**
36
+ * Deletes whatever the module stores for the tenant, its token and its
37
+ * first-run setup included.
38
+ */
39
+ export declare function signOut(tenantId: string): Promise<void>;
40
+ export {};
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PROJECT_REFUSALS = void 0;
4
+ exports.connect = connect;
5
+ exports.cancel = cancel;
6
+ exports.parseProjectChoice = parseProjectChoice;
7
+ exports.chooseProject = chooseProject;
8
+ exports.disconnect = disconnect;
9
+ exports.signOut = signOut;
10
+ const cloud_sdk_1 = require("@antelopejs/cloud-sdk");
11
+ const zod_1 = require("zod");
12
+ const config_1 = require("../config");
13
+ const follow_1 = require("../deployments/follow");
14
+ const store_1 = require("../setup/store");
15
+ const announce_1 = require("./announce");
16
+ const cloud_1 = require("./cloud");
17
+ const device_flow_1 = require("./device-flow");
18
+ const refusals_1 = require("./refusals");
19
+ const store_2 = require("./store");
20
+ const projectChoiceSchema = zod_1.z.object({ projectId: zod_1.z.string().min(1) });
21
+ /** How a page refuses a read of a project: a project the workspace lacks is unknown. */
22
+ exports.PROJECT_REFUSALS = {
23
+ missing: (0, refusals_1.unprocessable)("unknown_project"),
24
+ };
25
+ const ALREADY_CONNECTED = (0, refusals_1.conflict)("already_connected");
26
+ const NO_PROJECT_CHOSEN = (0, refusals_1.badRequest)("project_required");
27
+ /**
28
+ * Refuses an action on a connection AntelopeJS Cloud manages: a development
29
+ * environment gives the module its token and project, so there is no sign-in
30
+ * to start, cancel or end, and no project to choose or forget.
31
+ */
32
+ function refuseWhenManaged() {
33
+ if ((0, config_1.cloudSettings)().managed)
34
+ throw (0, refusals_1.refuse)(refusals_1.MANAGED_CONNECTION);
35
+ }
36
+ async function authorizeDevice() {
37
+ try {
38
+ return await (0, cloud_sdk_1.createDevice)(device_flow_1.DEVICE_NAME, (0, cloud_1.endpoint)());
39
+ }
40
+ catch {
41
+ throw (0, refusals_1.refuse)(refusals_1.CLOUD_UNREACHABLE);
42
+ }
43
+ }
44
+ /**
45
+ * Starts a device sign-in for the tenant, in place of a pending or failed
46
+ * one. A signed-in tenant is refused unless AntelopeJS Cloud refuses its token,
47
+ * and so is a tenant signed in while the sign-in starts.
48
+ *
49
+ * @throws The `managed_connection` refusal when AntelopeJS Cloud manages the
50
+ * connection. So do the actions below.
51
+ */
52
+ async function connect(tenantId, startedBy) {
53
+ refuseWhenManaged();
54
+ const stored = await (0, store_2.connections)().read(tenantId);
55
+ if (stored?.state === "connected") {
56
+ const access = await (0, cloud_1.readCloud)(stored, (api) => api.listProjects());
57
+ if (access.kind !== "revoked")
58
+ throw (0, refusals_1.refuse)(ALREADY_CONNECTED);
59
+ }
60
+ const revoked = stored?.state === "connected" ? stored.token : undefined;
61
+ const authorization = await authorizeDevice();
62
+ if (!(await (0, device_flow_1.startDeviceFlow)(tenantId, startedBy, authorization, revoked))) {
63
+ throw (0, refusals_1.refuse)(ALREADY_CONNECTED);
64
+ }
65
+ await (0, announce_1.announce)(tenantId);
66
+ }
67
+ /** Forgets the tenant's pending or failed sign-in. A signed-in tenant stays. */
68
+ async function cancel(tenantId) {
69
+ refuseWhenManaged();
70
+ await (0, store_2.connections)().removeUnconnected(tenantId);
71
+ await (0, announce_1.announce)(tenantId);
72
+ }
73
+ /** Reads the body of the Choose project dialog. */
74
+ function parseProjectChoice(body) {
75
+ return projectChoiceSchema.safeParse(body).data;
76
+ }
77
+ /**
78
+ * Sets the project this DMS publishes, once AntelopeJS Cloud confirms the
79
+ * workspace has it. When AntelopeJS Cloud refuses the token, the open pages
80
+ * read the connection again and show the sign-in as revoked.
81
+ */
82
+ async function chooseProject(tenantId, choice) {
83
+ refuseWhenManaged();
84
+ if (!choice)
85
+ throw (0, refusals_1.refuse)(NO_PROJECT_CHOSEN);
86
+ const model = (0, store_2.connections)();
87
+ const stored = await model.read(tenantId);
88
+ if (stored?.state !== "connected")
89
+ throw (0, refusals_1.refuse)(refusals_1.NOT_CONNECTED);
90
+ const project = await (0, cloud_1.readCloud)(stored, (api) => api.readProject(choice.projectId));
91
+ if (project.kind !== "ok") {
92
+ throw await (0, refusals_1.refuseCloud)(tenantId, project, exports.PROJECT_REFUSALS);
93
+ }
94
+ await model.setProject(tenantId, project.value.id);
95
+ await (0, store_1.setups)().clearCreation(tenantId);
96
+ await (0, announce_1.announce)(tenantId);
97
+ }
98
+ /** Forgets the project of the tenant's connection and keeps its sign-in. */
99
+ async function disconnect(tenantId) {
100
+ refuseWhenManaged();
101
+ (0, follow_1.stopFollowing)(tenantId);
102
+ await (0, store_2.connections)().setProject(tenantId, null);
103
+ await (0, store_1.setups)().clearCreation(tenantId);
104
+ await (0, announce_1.announce)(tenantId);
105
+ }
106
+ /**
107
+ * Deletes whatever the module stores for the tenant, its token and its
108
+ * first-run setup included.
109
+ */
110
+ async function signOut(tenantId) {
111
+ refuseWhenManaged();
112
+ (0, follow_1.stopFollowing)(tenantId);
113
+ await Promise.all([
114
+ (0, store_2.connections)().delete(tenantId),
115
+ (0, store_1.setups)().delete(tenantId),
116
+ ]);
117
+ await (0, announce_1.announce)(tenantId);
118
+ await (0, announce_1.announceProject)(tenantId);
119
+ }
120
+ //# sourceMappingURL=actions.js.map
@@ -0,0 +1,8 @@
1
+ /** The realtime topic the Connection page's blocks read their routes again on. */
2
+ export declare const CONNECTION_TOPIC = "antelope-cloud.connection";
3
+ /** The topics a page about the project follows: its connection and the project itself. */
4
+ export declare const PROJECT_TOPICS: string[];
5
+ /** Tells the tenant's open Connection pages that its connection changed. */
6
+ export declare function announce(tenantId: string): Promise<void>;
7
+ /** Tells the tenant's open pages that its project, environments or setup changed. */
8
+ export declare function announceProject(tenantId: string): Promise<void>;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PROJECT_TOPICS = exports.CONNECTION_TOPIC = void 0;
4
+ exports.announce = announce;
5
+ exports.announceProject = announceProject;
6
+ const realtime_1 = require("@antelopejs/interface-dms/realtime");
7
+ /** The realtime topic the Connection page's blocks read their routes again on. */
8
+ exports.CONNECTION_TOPIC = "antelope-cloud.connection";
9
+ const PROJECT_TOPIC = "antelope-cloud.project";
10
+ /** The topics a page about the project follows: its connection and the project itself. */
11
+ exports.PROJECT_TOPICS = [exports.CONNECTION_TOPIC, PROJECT_TOPIC];
12
+ /** Tells the tenant's open Connection pages that its connection changed. */
13
+ function announce(tenantId) {
14
+ return (0, realtime_1.PublishMessage)(exports.CONNECTION_TOPIC, "changed", { tenantId });
15
+ }
16
+ /** Tells the tenant's open pages that its project, environments or setup changed. */
17
+ function announceProject(tenantId) {
18
+ return (0, realtime_1.PublishMessage)(PROJECT_TOPIC, "changed", { tenantId });
19
+ }
20
+ //# sourceMappingURL=announce.js.map
@@ -0,0 +1,60 @@
1
+ import { CloudApi, type EndpointOptions } from "@antelopejs/cloud-sdk";
2
+ import { type ActiveConnection } from "./current";
3
+ /**
4
+ * What a read of the Cloud API with a workspace's token gave: the value, a
5
+ * token the API refuses (`revoked`), a resource it does not know (`missing`),
6
+ * a request the token is not allowed to make (`forbidden`, with its error
7
+ * code), or no usable answer (`unreachable`).
8
+ */
9
+ export type CloudRead<T> = {
10
+ kind: "ok";
11
+ value: T;
12
+ } | {
13
+ kind: "revoked";
14
+ } | {
15
+ kind: "missing";
16
+ } | {
17
+ kind: "forbidden";
18
+ code: string;
19
+ } | {
20
+ kind: "unreachable";
21
+ };
22
+ /**
23
+ * What a call of the Cloud API gave: what a read gives, or a request
24
+ * AntelopeJS Cloud refused with another client error (`refused`), its status
25
+ * and its error code.
26
+ */
27
+ export type CloudCall<T> = CloudRead<T> | {
28
+ kind: "refused";
29
+ status: number;
30
+ code: string;
31
+ };
32
+ /** A call of the Cloud API that gave no value. */
33
+ export type CloudFailure = Exclude<CloudCall<unknown>, {
34
+ kind: "ok";
35
+ }>;
36
+ /** How a read reaches the cloud. Without a signal, each answer has 10 s. */
37
+ export interface CloudReadOptions {
38
+ /**
39
+ * Ends the read when it aborts, and lifts the timeout: a stream lives
40
+ * until then.
41
+ */
42
+ readonly signal?: AbortSignal;
43
+ }
44
+ /**
45
+ * Where the SDK sends its requests: the module's `apiUrl`, with a timeout on
46
+ * each answer, or bound to `signal` when one is given.
47
+ */
48
+ export declare function endpoint(options?: CloudReadOptions): EndpointOptions;
49
+ /**
50
+ * Calls the Cloud API signed in with the workspace's token: the stored one,
51
+ * or the one a Cloud development environment gave the module. A stored token
52
+ * this server can no longer open, after `secretKey` changed, reads as
53
+ * `revoked`.
54
+ */
55
+ export declare function callCloud<T>(connection: ActiveConnection, call: (api: CloudApi) => Promise<T>, options?: CloudReadOptions): Promise<CloudCall<T>>;
56
+ /**
57
+ * Reads the Cloud API as {@link callCloud} calls it, a refused read reading
58
+ * as `unreachable`.
59
+ */
60
+ export declare function readCloud<T>(connection: ActiveConnection, read: (api: CloudApi) => Promise<T>, options?: CloudReadOptions): Promise<CloudRead<T>>;
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.endpoint = endpoint;
4
+ exports.callCloud = callCloud;
5
+ exports.readCloud = readCloud;
6
+ const cloud_sdk_1 = require("@antelopejs/cloud-sdk");
7
+ const config_1 = require("../config");
8
+ const current_1 = require("./current");
9
+ const seal_1 = require("./seal");
10
+ const CLOUD_TIMEOUT_MS = 10_000;
11
+ const UNREACHABLE = {
12
+ kind: "unreachable",
13
+ };
14
+ const REVOKED = { kind: "revoked" };
15
+ const FAILURES_BY_STATUS = new Map([
16
+ [401, REVOKED],
17
+ [404, { kind: "missing" }],
18
+ ]);
19
+ const CLIENT_ERRORS = { from: 400, to: 499 };
20
+ const HTTP_FORBIDDEN = 403;
21
+ function failureOf({ status, code }) {
22
+ const known = FAILURES_BY_STATUS.get(status);
23
+ if (known)
24
+ return known;
25
+ if (status === HTTP_FORBIDDEN)
26
+ return { kind: "forbidden", code };
27
+ return status >= CLIENT_ERRORS.from && status <= CLIENT_ERRORS.to
28
+ ? { kind: "refused", status, code }
29
+ : UNREACHABLE;
30
+ }
31
+ const timedFetch = (input, init) => fetch(input, { ...init, signal: AbortSignal.timeout(CLOUD_TIMEOUT_MS) });
32
+ function boundFetch(signal) {
33
+ return (input, init) => fetch(input, {
34
+ ...init,
35
+ signal: init?.signal ? AbortSignal.any([signal, init.signal]) : signal,
36
+ });
37
+ }
38
+ /**
39
+ * Where the SDK sends its requests: the module's `apiUrl`, with a timeout on
40
+ * each answer, or bound to `signal` when one is given.
41
+ */
42
+ function endpoint(options = {}) {
43
+ const { signal } = options;
44
+ return {
45
+ baseUrl: (0, config_1.cloudSettings)().apiUrl.href,
46
+ fetch: signal ? boundFetch(signal) : timedFetch,
47
+ };
48
+ }
49
+ function tokenOf(connection) {
50
+ const { managed, sealingKey } = (0, config_1.cloudSettings)();
51
+ if (!(0, current_1.isManaged)(connection)) {
52
+ return (0, seal_1.open)(sealingKey, connection._id, connection.token);
53
+ }
54
+ if (!managed)
55
+ throw new Error("antelope-cloud: no managed token is set");
56
+ return managed.token;
57
+ }
58
+ /**
59
+ * Calls the Cloud API signed in with the workspace's token: the stored one,
60
+ * or the one a Cloud development environment gave the module. A stored token
61
+ * this server can no longer open, after `secretKey` changed, reads as
62
+ * `revoked`.
63
+ */
64
+ async function callCloud(connection, call, options = {}) {
65
+ let api;
66
+ try {
67
+ api = new cloud_sdk_1.CloudApi({ ...endpoint(options), token: tokenOf(connection) });
68
+ }
69
+ catch {
70
+ return REVOKED;
71
+ }
72
+ try {
73
+ return { kind: "ok", value: await call(api) };
74
+ }
75
+ catch (error) {
76
+ return error instanceof cloud_sdk_1.CloudApiError ? failureOf(error) : UNREACHABLE;
77
+ }
78
+ }
79
+ /**
80
+ * Reads the Cloud API as {@link callCloud} calls it, a refused read reading
81
+ * as `unreachable`.
82
+ */
83
+ async function readCloud(connection, read, options = {}) {
84
+ const answer = await callCloud(connection, read, options);
85
+ return answer.kind === "refused" ? UNREACHABLE : answer;
86
+ }
87
+ //# sourceMappingURL=cloud.js.map
@@ -0,0 +1,70 @@
1
+ import type { CloudApi } from "@antelopejs/cloud-sdk";
2
+ import type { BannerContent } from "@antelopejs/interface-dms/base/banner";
3
+ import type { GuardFallback } from "@antelopejs/interface-dms/base/guard";
4
+ import type { KeyValueListItem } from "@antelopejs/interface-dms/base/key-value-list";
5
+ import type { ConfirmDialogSerialized } from "@antelopejs/interface-dms/base/types/confirm-dialog";
6
+ import type { CloudRead } from "./cloud";
7
+ import type { Repository } from "./repository";
8
+ import type { ConnectionView } from "./view";
9
+ /** The routes of the Connection page, relative to it. */
10
+ export declare const CONNECTION_ROUTES: {
11
+ readonly banner: "/banner";
12
+ readonly state: "/state";
13
+ readonly account: "/account";
14
+ readonly workspace: "/workspace";
15
+ readonly repository: "/repository";
16
+ readonly disconnectBanner: "/disconnect-banner";
17
+ readonly signOutBanner: "/sign-out-banner";
18
+ readonly projectDialog: "/project-dialog";
19
+ readonly connect: "/connect";
20
+ readonly cancel: "/cancel";
21
+ readonly project: "/project";
22
+ readonly disconnect: "/disconnect";
23
+ readonly signOut: "/sign-out";
24
+ readonly apiStatus: "/api-status";
25
+ };
26
+ /** A route of the Connection page. */
27
+ export type ConnectionRoute = (typeof CONNECTION_ROUTES)[keyof typeof CONNECTION_ROUTES];
28
+ /** A project of the workspace, as the Cloud API reads it. */
29
+ export type CloudProject = Awaited<ReturnType<CloudApi["readProject"]>>;
30
+ /** The projects of the workspace, as the Cloud API lists them. */
31
+ export type CloudProjects = Awaited<ReturnType<CloudApi["listProjects"]>>;
32
+ /** What the Connection page's `Guard` reads: whether the workspace is signed in. */
33
+ export interface GuardAnswer {
34
+ connected: boolean;
35
+ /** Laid over the not-connected empty state: the code to confirm. */
36
+ emptyState?: GuardFallback;
37
+ }
38
+ /** The URL of a Connection page route, as a block or a button names it. */
39
+ export declare function connectionRoute(route: ConnectionRoute): string;
40
+ /** The call to action at the top of the page, `null` when there is none. */
41
+ export declare function connectionBanner(view: ConnectionView, access: CloudRead<unknown>["kind"] | undefined): BannerContent | null;
42
+ /** Whether the page shows the connection's sections, and the code while one is pending. */
43
+ export declare function guardAnswer(view: ConnectionView): GuardAnswer;
44
+ /** Who signed the workspace in, and how its token is kept. */
45
+ export declare function accountItems(view: ConnectionView): KeyValueListItem[];
46
+ /** The workspace signed in and the project this DMS publishes. */
47
+ export declare function workspaceItems(view: ConnectionView, project: CloudRead<CloudProject> | undefined): KeyValueListItem[];
48
+ /** The repository the module publishes: its origin remote and branch. */
49
+ export declare function repositoryItems(repository: Repository): KeyValueListItem[];
50
+ /** What a page's repository `Guard` reads: whether origin is on GitHub, and how to put it there. */
51
+ export interface RemoteAnswer {
52
+ remote: boolean;
53
+ /** Laid over the guard's fallback: the commands that add the remote. */
54
+ emptyState?: GuardFallback;
55
+ }
56
+ /**
57
+ * Whether AntelopeJS Cloud can build the repository the module publishes: its
58
+ * origin is on GitHub. When it is not, the git commands that make it so.
59
+ */
60
+ export declare function remoteAnswer(repository: Repository): RemoteAnswer;
61
+ /** Why a page's repository `Guard` shows nothing: origin is not on GitHub. */
62
+ export declare const NO_GITHUB_REMOTE: GuardFallback;
63
+ /** The Disconnect row of the danger zone, while a project is chosen. */
64
+ export declare function disconnectBanner(view: ConnectionView): BannerContent | null;
65
+ /** The Sign out row of the danger zone, while the workspace is signed in. */
66
+ export declare function signOutBanner(view: ConnectionView): BannerContent | null;
67
+ /** The dialog the Choose project button would open on a connection AntelopeJS Cloud manages. */
68
+ export declare function managedProjectDialog(): ConfirmDialogSerialized;
69
+ /** The dialog the Choose project button opens: the workspace's projects. */
70
+ export declare function projectDialog(projects: CloudRead<CloudProjects> | undefined): ConfirmDialogSerialized;