@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,51 @@
1
+ import type { CloudApi } from "@antelopejs/cloud-sdk";
2
+ import { HTTPResult } from "@antelopejs/interface-api";
3
+ import { type CloudFailure } from "./cloud";
4
+ import type { ActiveConnection } from "./current";
5
+ /**
6
+ * Why a page route refuses a request: its HTTP status, and the error whose
7
+ * text the dashboard shows, under `dms_antelope_cloud.errors` in the
8
+ * frontend's locale files.
9
+ */
10
+ export interface Refusal {
11
+ readonly status: number;
12
+ readonly error: string;
13
+ }
14
+ /** A refusal with a 400 status. */
15
+ export declare function badRequest(error: string): Refusal;
16
+ /** A refusal with a 409 status. */
17
+ export declare function conflict(error: string): Refusal;
18
+ /** A refusal with a 422 status. */
19
+ export declare function unprocessable(error: string): Refusal;
20
+ /** AntelopeJS Cloud gave no usable answer. */
21
+ export declare const CLOUD_UNREACHABLE: Refusal;
22
+ /** The workspace is not signed in to AntelopeJS Cloud. */
23
+ export declare const NOT_CONNECTED: Refusal;
24
+ /** The connection is the one AntelopeJS Cloud manages, which no one signs in to or out of here. */
25
+ export declare const MANAGED_CONNECTION: Refusal;
26
+ /** What the page route answers for a refusal. */
27
+ export declare function refuse({ status, error }: Refusal): HTTPResult;
28
+ /**
29
+ * How a page refuses a call AntelopeJS Cloud did not answer with a value, past
30
+ * the token and the API being down: a resource it does not know (`missing`),
31
+ * and a request it refused, by its error code (`codes`), which a request the
32
+ * token is not allowed to make (`forbidden`) is looked up by too.
33
+ */
34
+ export interface CloudRefusals {
35
+ readonly missing: Refusal;
36
+ readonly codes?: ReadonlyMap<string, Refusal>;
37
+ }
38
+ /** The refusal of a call AntelopeJS Cloud did not answer with a value. */
39
+ export declare function cloudRefusal(failure: CloudFailure, refusals: CloudRefusals): Refusal;
40
+ /**
41
+ * What a page route answers for a failed call. When AntelopeJS Cloud refused
42
+ * the token, the tenant's open pages read the connection again and show the
43
+ * sign-in as revoked.
44
+ */
45
+ export declare function refuseCloud(tenantId: string, failure: CloudFailure, refusals: CloudRefusals): Promise<HTTPResult>;
46
+ /**
47
+ * Calls the Cloud API with a tenant's connection.
48
+ *
49
+ * @throws The page route's refusal of a call that gave no value.
50
+ */
51
+ export declare function callOrRefuse<T>(connection: ActiveConnection, call: (api: CloudApi) => Promise<T>, refusals: CloudRefusals): Promise<T>;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MANAGED_CONNECTION = exports.NOT_CONNECTED = exports.CLOUD_UNREACHABLE = void 0;
4
+ exports.badRequest = badRequest;
5
+ exports.conflict = conflict;
6
+ exports.unprocessable = unprocessable;
7
+ exports.refuse = refuse;
8
+ exports.cloudRefusal = cloudRefusal;
9
+ exports.refuseCloud = refuseCloud;
10
+ exports.callOrRefuse = callOrRefuse;
11
+ const interface_api_1 = require("@antelopejs/interface-api");
12
+ const announce_1 = require("./announce");
13
+ const cloud_1 = require("./cloud");
14
+ const HTTP_BAD_REQUEST = 400;
15
+ const HTTP_CONFLICT = 409;
16
+ const HTTP_UNPROCESSABLE = 422;
17
+ const HTTP_BAD_GATEWAY = 502;
18
+ const MESSAGE_KEY_PREFIX = "$dms_antelope_cloud.errors.";
19
+ /** A refusal with a 400 status. */
20
+ function badRequest(error) {
21
+ return { status: HTTP_BAD_REQUEST, error };
22
+ }
23
+ /** A refusal with a 409 status. */
24
+ function conflict(error) {
25
+ return { status: HTTP_CONFLICT, error };
26
+ }
27
+ /** A refusal with a 422 status. */
28
+ function unprocessable(error) {
29
+ return { status: HTTP_UNPROCESSABLE, error };
30
+ }
31
+ /** AntelopeJS Cloud gave no usable answer. */
32
+ exports.CLOUD_UNREACHABLE = {
33
+ status: HTTP_BAD_GATEWAY,
34
+ error: "cloud_unreachable",
35
+ };
36
+ /** The workspace is not signed in to AntelopeJS Cloud. */
37
+ exports.NOT_CONNECTED = conflict("not_connected");
38
+ /** The connection is the one AntelopeJS Cloud manages, which no one signs in to or out of here. */
39
+ exports.MANAGED_CONNECTION = conflict("managed_connection");
40
+ const SIGN_IN_REVOKED = conflict("sign_in_revoked");
41
+ const CLOUD_REFUSED = conflict("cloud_refused");
42
+ const CLOUD_FORBIDDEN = conflict("cloud_forbidden");
43
+ /** What the page route answers for a refusal. */
44
+ function refuse({ status, error }) {
45
+ return new interface_api_1.HTTPResult(status, {
46
+ error,
47
+ message: `${MESSAGE_KEY_PREFIX}${error}`,
48
+ });
49
+ }
50
+ /** The refusal of a call AntelopeJS Cloud did not answer with a value. */
51
+ function cloudRefusal(failure, refusals) {
52
+ if (failure.kind === "revoked")
53
+ return SIGN_IN_REVOKED;
54
+ if (failure.kind === "missing")
55
+ return refusals.missing;
56
+ if (failure.kind === "unreachable")
57
+ return exports.CLOUD_UNREACHABLE;
58
+ const refusal = refusals.codes?.get(failure.code);
59
+ if (refusal)
60
+ return refusal;
61
+ return failure.kind === "forbidden" ? CLOUD_FORBIDDEN : CLOUD_REFUSED;
62
+ }
63
+ /**
64
+ * What a page route answers for a failed call. When AntelopeJS Cloud refused
65
+ * the token, the tenant's open pages read the connection again and show the
66
+ * sign-in as revoked.
67
+ */
68
+ async function refuseCloud(tenantId, failure, refusals) {
69
+ if (failure.kind === "revoked")
70
+ await (0, announce_1.announce)(tenantId);
71
+ return refuse(cloudRefusal(failure, refusals));
72
+ }
73
+ /**
74
+ * Calls the Cloud API with a tenant's connection.
75
+ *
76
+ * @throws The page route's refusal of a call that gave no value.
77
+ */
78
+ async function callOrRefuse(connection, call, refusals) {
79
+ const answer = await (0, cloud_1.callCloud)(connection, call);
80
+ if (answer.kind !== "ok") {
81
+ throw await refuseCloud(connection._id, answer, refusals);
82
+ }
83
+ return answer.value;
84
+ }
85
+ //# sourceMappingURL=refusals.js.map
@@ -0,0 +1,28 @@
1
+ /** The origin remote of a repository, as the Connection page shows it. */
2
+ export interface GitRemote {
3
+ /** `owner/repo` for a GitHub repository, else the URL without its credentials. */
4
+ readonly label: string;
5
+ /** The repository's page on GitHub, `null` elsewhere. */
6
+ readonly webUrl: string | null;
7
+ }
8
+ /** The git repository a directory belongs to. */
9
+ export interface Repository {
10
+ /** Its `origin` remote, `null` when it has none. */
11
+ readonly remote: GitRemote | null;
12
+ /** The branch checked out, `null` on a detached HEAD or outside a repository. */
13
+ readonly branch: string | null;
14
+ }
15
+ /**
16
+ * Reads a remote URL as git accepts it: a URL (`https://`, `ssh://`), the
17
+ * scp-like `git@github.com:owner/repo.git`, or a local path. Credentials in
18
+ * the URL are left out of what it gives.
19
+ */
20
+ export declare function parseRemote(remote: string): GitRemote;
21
+ /**
22
+ * The `origin` remote and the current branch of the repository `cwd` is in.
23
+ * Origin's URL is read as the owner configured it, before an `insteadOf`
24
+ * mapping rewrites it.
25
+ */
26
+ export declare function readRepository(cwd: string): Promise<Repository>;
27
+ /** The repository the module publishes, at its `repositoryPath` option. */
28
+ export declare function readPublishedRepository(): Promise<Repository>;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseRemote = parseRemote;
4
+ exports.readRepository = readRepository;
5
+ exports.readPublishedRepository = readPublishedRepository;
6
+ const node_child_process_1 = require("node:child_process");
7
+ const node_util_1 = require("node:util");
8
+ const config_1 = require("../config");
9
+ const execFileAsync = (0, node_util_1.promisify)(node_child_process_1.execFile);
10
+ const GIT_TIMEOUT_MS = 5_000;
11
+ const GITHUB_HOST = "github.com";
12
+ const GIT_SUFFIX = /\.git$/;
13
+ const SCP_LIKE_REMOTE = /^(?:[^@/]+@)?([^:/]+):(.+)$/;
14
+ function remoteOn(host, path, label) {
15
+ const segments = path.replace(GIT_SUFFIX, "").split("/").filter(Boolean);
16
+ if (host.toLowerCase() !== GITHUB_HOST || segments.length !== 2) {
17
+ return { label, webUrl: null };
18
+ }
19
+ const slug = segments.join("/");
20
+ return { label: slug, webUrl: `https://${GITHUB_HOST}/${slug}` };
21
+ }
22
+ /**
23
+ * Reads a remote URL as git accepts it: a URL (`https://`, `ssh://`), the
24
+ * scp-like `git@github.com:owner/repo.git`, or a local path. Credentials in
25
+ * the URL are left out of what it gives.
26
+ */
27
+ function parseRemote(remote) {
28
+ const url = URL.parse(remote);
29
+ if (url?.host) {
30
+ url.username = "";
31
+ url.password = "";
32
+ return remoteOn(url.hostname, url.pathname, url.href);
33
+ }
34
+ const scpLike = SCP_LIKE_REMOTE.exec(remote);
35
+ if (scpLike) {
36
+ const [, host, path] = scpLike;
37
+ return remoteOn(host, path, `${host}:${path}`);
38
+ }
39
+ return { label: remote, webUrl: null };
40
+ }
41
+ async function git(cwd, args) {
42
+ try {
43
+ const { stdout } = await execFileAsync("git", args, {
44
+ cwd,
45
+ timeout: GIT_TIMEOUT_MS,
46
+ });
47
+ return stdout.trim() || null;
48
+ }
49
+ catch {
50
+ return null;
51
+ }
52
+ }
53
+ /**
54
+ * The `origin` remote and the current branch of the repository `cwd` is in.
55
+ * Origin's URL is read as the owner configured it, before an `insteadOf`
56
+ * mapping rewrites it.
57
+ */
58
+ async function readRepository(cwd) {
59
+ const [remote, branch] = await Promise.all([
60
+ git(cwd, ["config", "--get", "remote.origin.url"]),
61
+ git(cwd, ["branch", "--show-current"]),
62
+ ]);
63
+ return { remote: remote === null ? null : parseRemote(remote), branch };
64
+ }
65
+ /** The repository the module publishes, at its `repositoryPath` option. */
66
+ function readPublishedRepository() {
67
+ return readRepository((0, config_1.cloudSettings)().repositoryPath);
68
+ }
69
+ //# sourceMappingURL=repository.js.map
@@ -0,0 +1,22 @@
1
+ import { type KeyObject } from "node:crypto";
2
+ /**
3
+ * A secret encrypted for one tenant with AES-256-GCM, each part in base64.
4
+ * The tenant id is its additional authenticated data, so it opens only for
5
+ * the tenant it was sealed for.
6
+ */
7
+ export interface Sealed {
8
+ readonly iv: string;
9
+ readonly tag: string;
10
+ readonly data: string;
11
+ }
12
+ /** The AES-256 key that seals the module's secrets: HKDF-SHA256 of `secretKey`. */
13
+ export declare function deriveSealingKey(secretKey: string): KeyObject;
14
+ /** Encrypts `plaintext` for `tenantId`, with a fresh random IV. */
15
+ export declare function seal(key: KeyObject, tenantId: string, plaintext: string): Sealed;
16
+ /**
17
+ * Decrypts what {@link seal} encrypted.
18
+ *
19
+ * @throws When the key or the tenant differ from the ones it was sealed with,
20
+ * or any part was altered.
21
+ */
22
+ export declare function open(key: KeyObject, tenantId: string, sealed: Sealed): string;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deriveSealingKey = deriveSealingKey;
4
+ exports.seal = seal;
5
+ exports.open = open;
6
+ const node_crypto_1 = require("node:crypto");
7
+ const CIPHER = "aes-256-gcm";
8
+ const KEY_BYTES = 32;
9
+ const IV_BYTES = 12;
10
+ const TAG_BYTES = 16;
11
+ const KEY_SALT = "antelope-cloud";
12
+ const KEY_INFO = "connection-token";
13
+ /** The AES-256 key that seals the module's secrets: HKDF-SHA256 of `secretKey`. */
14
+ function deriveSealingKey(secretKey) {
15
+ return (0, node_crypto_1.createSecretKey)(Buffer.from((0, node_crypto_1.hkdfSync)("sha256", secretKey, KEY_SALT, KEY_INFO, KEY_BYTES)));
16
+ }
17
+ /** Encrypts `plaintext` for `tenantId`, with a fresh random IV. */
18
+ function seal(key, tenantId, plaintext) {
19
+ const iv = (0, node_crypto_1.randomBytes)(IV_BYTES);
20
+ const cipher = (0, node_crypto_1.createCipheriv)(CIPHER, key, iv, { authTagLength: TAG_BYTES });
21
+ cipher.setAAD(Buffer.from(tenantId));
22
+ const data = Buffer.concat([
23
+ cipher.update(plaintext, "utf8"),
24
+ cipher.final(),
25
+ ]);
26
+ return {
27
+ iv: iv.toString("base64"),
28
+ tag: cipher.getAuthTag().toString("base64"),
29
+ data: data.toString("base64"),
30
+ };
31
+ }
32
+ /**
33
+ * Decrypts what {@link seal} encrypted.
34
+ *
35
+ * @throws When the key or the tenant differ from the ones it was sealed with,
36
+ * or any part was altered.
37
+ */
38
+ function open(key, tenantId, sealed) {
39
+ const decipher = (0, node_crypto_1.createDecipheriv)(CIPHER, key, Buffer.from(sealed.iv, "base64"), { authTagLength: TAG_BYTES });
40
+ decipher.setAAD(Buffer.from(tenantId));
41
+ decipher.setAuthTag(Buffer.from(sealed.tag, "base64"));
42
+ return Buffer.concat([
43
+ decipher.update(Buffer.from(sealed.data, "base64")),
44
+ decipher.final(),
45
+ ]).toString("utf8");
46
+ }
47
+ //# sourceMappingURL=seal.js.map
@@ -0,0 +1,294 @@
1
+ import { Table } from "@antelopejs/interface-database-decorators";
2
+ import { z } from "zod";
3
+ import type { Sealed } from "./seal";
4
+ /** The database schema the module owns. */
5
+ export declare const SCHEMA_NAME = "antelope-cloud";
6
+ declare const FAILURE_REASONS: readonly ["denied", "expired"];
7
+ /** Why a device sign-in ended without a token. */
8
+ export type FailureReason = (typeof FAILURE_REASONS)[number];
9
+ declare const pendingSchema: z.ZodObject<{
10
+ _id: z.ZodString;
11
+ state: z.ZodLiteral<"pending">;
12
+ device: z.ZodObject<{
13
+ iv: z.ZodString;
14
+ tag: z.ZodString;
15
+ data: z.ZodString;
16
+ }, "strip", z.ZodTypeAny, {
17
+ data: string;
18
+ iv: string;
19
+ tag: string;
20
+ }, {
21
+ data: string;
22
+ iv: string;
23
+ tag: string;
24
+ }>;
25
+ userCode: z.ZodString;
26
+ verificationUri: z.ZodString;
27
+ verificationUriComplete: z.ZodString;
28
+ expiresAt: z.ZodDate;
29
+ intervalS: z.ZodNumber;
30
+ startedBy: z.ZodString;
31
+ startedAt: z.ZodDate;
32
+ }, "strip", z.ZodTypeAny, {
33
+ _id: string;
34
+ expiresAt: Date;
35
+ state: "pending";
36
+ device: {
37
+ data: string;
38
+ iv: string;
39
+ tag: string;
40
+ };
41
+ userCode: string;
42
+ verificationUri: string;
43
+ verificationUriComplete: string;
44
+ intervalS: number;
45
+ startedBy: string;
46
+ startedAt: Date;
47
+ }, {
48
+ _id: string;
49
+ expiresAt: Date;
50
+ state: "pending";
51
+ device: {
52
+ data: string;
53
+ iv: string;
54
+ tag: string;
55
+ };
56
+ userCode: string;
57
+ verificationUri: string;
58
+ verificationUriComplete: string;
59
+ intervalS: number;
60
+ startedBy: string;
61
+ startedAt: Date;
62
+ }>;
63
+ declare const connectedSchema: z.ZodObject<{
64
+ _id: z.ZodString;
65
+ state: z.ZodLiteral<"connected">;
66
+ token: z.ZodObject<{
67
+ iv: z.ZodString;
68
+ tag: z.ZodString;
69
+ data: z.ZodString;
70
+ }, "strip", z.ZodTypeAny, {
71
+ data: string;
72
+ iv: string;
73
+ tag: string;
74
+ }, {
75
+ data: string;
76
+ iv: string;
77
+ tag: string;
78
+ }>;
79
+ workspaceId: z.ZodString;
80
+ workspaceName: z.ZodNullable<z.ZodString>;
81
+ projectId: z.ZodNullable<z.ZodString>;
82
+ connectedBy: z.ZodString;
83
+ connectedAt: z.ZodDate;
84
+ }, "strip", z.ZodTypeAny, {
85
+ _id: string;
86
+ token: {
87
+ data: string;
88
+ iv: string;
89
+ tag: string;
90
+ };
91
+ state: "connected";
92
+ projectId: string | null;
93
+ workspaceId: string;
94
+ workspaceName: string | null;
95
+ connectedBy: string;
96
+ connectedAt: Date;
97
+ }, {
98
+ _id: string;
99
+ token: {
100
+ data: string;
101
+ iv: string;
102
+ tag: string;
103
+ };
104
+ state: "connected";
105
+ projectId: string | null;
106
+ workspaceId: string;
107
+ workspaceName: string | null;
108
+ connectedBy: string;
109
+ connectedAt: Date;
110
+ }>;
111
+ declare const storedConnectionSchema: z.ZodDiscriminatedUnion<"state", [z.ZodObject<{
112
+ _id: z.ZodString;
113
+ state: z.ZodLiteral<"pending">;
114
+ device: z.ZodObject<{
115
+ iv: z.ZodString;
116
+ tag: z.ZodString;
117
+ data: z.ZodString;
118
+ }, "strip", z.ZodTypeAny, {
119
+ data: string;
120
+ iv: string;
121
+ tag: string;
122
+ }, {
123
+ data: string;
124
+ iv: string;
125
+ tag: string;
126
+ }>;
127
+ userCode: z.ZodString;
128
+ verificationUri: z.ZodString;
129
+ verificationUriComplete: z.ZodString;
130
+ expiresAt: z.ZodDate;
131
+ intervalS: z.ZodNumber;
132
+ startedBy: z.ZodString;
133
+ startedAt: z.ZodDate;
134
+ }, "strip", z.ZodTypeAny, {
135
+ _id: string;
136
+ expiresAt: Date;
137
+ state: "pending";
138
+ device: {
139
+ data: string;
140
+ iv: string;
141
+ tag: string;
142
+ };
143
+ userCode: string;
144
+ verificationUri: string;
145
+ verificationUriComplete: string;
146
+ intervalS: number;
147
+ startedBy: string;
148
+ startedAt: Date;
149
+ }, {
150
+ _id: string;
151
+ expiresAt: Date;
152
+ state: "pending";
153
+ device: {
154
+ data: string;
155
+ iv: string;
156
+ tag: string;
157
+ };
158
+ userCode: string;
159
+ verificationUri: string;
160
+ verificationUriComplete: string;
161
+ intervalS: number;
162
+ startedBy: string;
163
+ startedAt: Date;
164
+ }>, z.ZodObject<{
165
+ _id: z.ZodString;
166
+ state: z.ZodLiteral<"connected">;
167
+ token: z.ZodObject<{
168
+ iv: z.ZodString;
169
+ tag: z.ZodString;
170
+ data: z.ZodString;
171
+ }, "strip", z.ZodTypeAny, {
172
+ data: string;
173
+ iv: string;
174
+ tag: string;
175
+ }, {
176
+ data: string;
177
+ iv: string;
178
+ tag: string;
179
+ }>;
180
+ workspaceId: z.ZodString;
181
+ workspaceName: z.ZodNullable<z.ZodString>;
182
+ projectId: z.ZodNullable<z.ZodString>;
183
+ connectedBy: z.ZodString;
184
+ connectedAt: z.ZodDate;
185
+ }, "strip", z.ZodTypeAny, {
186
+ _id: string;
187
+ token: {
188
+ data: string;
189
+ iv: string;
190
+ tag: string;
191
+ };
192
+ state: "connected";
193
+ projectId: string | null;
194
+ workspaceId: string;
195
+ workspaceName: string | null;
196
+ connectedBy: string;
197
+ connectedAt: Date;
198
+ }, {
199
+ _id: string;
200
+ token: {
201
+ data: string;
202
+ iv: string;
203
+ tag: string;
204
+ };
205
+ state: "connected";
206
+ projectId: string | null;
207
+ workspaceId: string;
208
+ workspaceName: string | null;
209
+ connectedBy: string;
210
+ connectedAt: Date;
211
+ }>, z.ZodObject<{
212
+ _id: z.ZodString;
213
+ state: z.ZodLiteral<"failed">;
214
+ reason: z.ZodEnum<["denied", "expired"]>;
215
+ at: z.ZodDate;
216
+ }, "strip", z.ZodTypeAny, {
217
+ _id: string;
218
+ state: "failed";
219
+ reason: "expired" | "denied";
220
+ at: Date;
221
+ }, {
222
+ _id: string;
223
+ state: "failed";
224
+ reason: "expired" | "denied";
225
+ at: Date;
226
+ }>]>;
227
+ /**
228
+ * What the module stores for one DMS workspace (tenant), whose id is `_id`,
229
+ * with `device` and `token` sealed for that tenant.
230
+ */
231
+ export type StoredConnection = z.infer<typeof storedConnectionSchema>;
232
+ /** A device sign-in waiting for its approval. */
233
+ export type PendingConnection = z.infer<typeof pendingSchema>;
234
+ /** A workspace signed in to AntelopeJS Cloud. */
235
+ export type ConnectedConnection = z.infer<typeof connectedSchema>;
236
+ declare class ConnectionRow extends Table {
237
+ state: StoredConnection["state"];
238
+ device?: Sealed;
239
+ token?: Sealed;
240
+ intervalS?: number;
241
+ projectId?: string | null;
242
+ }
243
+ declare const ConnectionModel_base: {
244
+ new (database: import("@antelopejs/interface-database").SchemaInstance<any>): {
245
+ readonly table: import("@antelopejs/interface-database").Table<ConnectionRow>;
246
+ readonly database: import("@antelopejs/interface-database").SchemaInstance<any>;
247
+ get(id: string): Promise<ConnectionRow | undefined>;
248
+ getBy(index: keyof ConnectionRow, ...keys: import("@antelopejs/interface-database-decorators").IndexKey[]): Promise<ConnectionRow[]>;
249
+ getAll(): Promise<ConnectionRow[]>;
250
+ insert(obj: import("@antelopejs/interface-database-decorators").DeepPartial<ConnectionRow> | import("@antelopejs/interface-database-decorators").DeepPartial<ConnectionRow>[], options?: import("@antelopejs/interface-database-decorators").ValidateOptions): Promise<string[]>;
251
+ update(id: string, obj: import("@antelopejs/interface-database-decorators").DeepPartial<ConnectionRow>, options?: import("@antelopejs/interface-database-decorators").ValidateOptions): Promise<number>;
252
+ update(obj: import("@antelopejs/interface-database-decorators").DeepPartial<ConnectionRow> & {
253
+ _id: string;
254
+ }, options?: import("@antelopejs/interface-database-decorators").ValidateOptions): Promise<number>;
255
+ delete(id: string): Promise<number>;
256
+ };
257
+ readonly schemaName: string | undefined;
258
+ readonly tableClass: import("@antelopejs/interface-database-decorators").Constructible<ConnectionRow>;
259
+ fromPlainData(obj: ConnectionRow | import("@antelopejs/interface-database-decorators").PlainData<ConnectionRow>): ConnectionRow;
260
+ fromDatabase(obj: any): ConnectionRow | undefined;
261
+ toDatabase(obj: ConnectionRow | import("@antelopejs/interface-database-decorators").PlainData<ConnectionRow>): import("@antelopejs/interface-database-decorators").StoredRow<ConnectionRow>;
262
+ validate(obj: unknown, options?: import("@antelopejs/interface-database-decorators").ValidateInputOptions): import("@antelopejs/interface-database-decorators").ValidationResult;
263
+ };
264
+ /** Reads and writes the connection of each tenant. */
265
+ export declare class ConnectionModel extends ConnectionModel_base {
266
+ /** The tenant's connection, or `undefined` when it has none. */
267
+ read(tenantId: string): Promise<StoredConnection | undefined>;
268
+ /** Every device sign-in still waiting, whatever its tenant. */
269
+ pending(): Promise<PendingConnection[]>;
270
+ /**
271
+ * Stores the tenant's new device sign-in in place of a pending or failed
272
+ * one, or of the sign-in whose token is `revokedToken`. A tenant signed in
273
+ * otherwise keeps its sign-in.
274
+ *
275
+ * @returns Whether the sign-in was stored.
276
+ */
277
+ startFlow(pending: PendingConnection, revokedToken: Sealed | undefined): Promise<boolean>;
278
+ /**
279
+ * Replaces the tenant's document with `next`, only while it is the pending
280
+ * sign-in of `device`: a sign-in cancelled or started again meanwhile keeps
281
+ * its result.
282
+ */
283
+ settleFlow(device: Sealed, next: StoredConnection): Promise<void>;
284
+ /** Sets the polling interval of the tenant's pending sign-in of `device`. */
285
+ slowFlow(tenantId: string, device: Sealed, intervalS: number): Promise<void>;
286
+ /** Sets the project of the tenant's connection, `null` for none, while it is signed in. */
287
+ setProject(tenantId: string, projectId: string | null): Promise<void>;
288
+ /** Deletes the tenant's sign-in when it is pending or failed. */
289
+ removeUnconnected(tenantId: string): Promise<void>;
290
+ private flow;
291
+ }
292
+ /** The connection model of the module's schema. */
293
+ export declare function connections(): ConnectionModel;
294
+ export {};