@hideandseeklab/aoox 0.1.0-alpha.8 → 0.1.0-beta.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 (100) hide show
  1. package/README.md +666 -35
  2. package/assets/install/docker-compose.dist.yml +15 -1
  3. package/bin/dev.js +8 -2
  4. package/bin/run.js +6 -2
  5. package/dist/commands/deploy.js +14 -8
  6. package/dist/commands/domain/clear.d.ts +16 -0
  7. package/dist/commands/domain/clear.js +61 -0
  8. package/dist/commands/domain/set.d.ts +1 -0
  9. package/dist/commands/domain/set.js +15 -3
  10. package/dist/commands/env/diff.d.ts +18 -0
  11. package/dist/commands/env/diff.js +51 -0
  12. package/dist/commands/env/history.d.ts +17 -0
  13. package/dist/commands/env/history.js +48 -0
  14. package/dist/commands/env/link.d.ts +17 -0
  15. package/dist/commands/env/link.js +53 -0
  16. package/dist/commands/env/links.d.ts +14 -0
  17. package/dist/commands/env/links.js +17 -0
  18. package/dist/commands/env/list.d.ts +40 -0
  19. package/dist/commands/env/list.js +120 -0
  20. package/dist/commands/env/promote.d.ts +20 -0
  21. package/dist/commands/env/promote.js +96 -0
  22. package/dist/commands/env/pull.d.ts +17 -0
  23. package/dist/commands/env/pull.js +69 -0
  24. package/dist/commands/env/push.d.ts +17 -0
  25. package/dist/commands/env/push.js +70 -0
  26. package/dist/commands/env/set.d.ts +19 -0
  27. package/dist/commands/env/set.js +60 -0
  28. package/dist/commands/env/unlink.d.ts +17 -0
  29. package/dist/commands/env/unlink.js +39 -0
  30. package/dist/commands/env/unset.d.ts +18 -0
  31. package/dist/commands/env/unset.js +45 -0
  32. package/dist/commands/install.d.ts +19 -0
  33. package/dist/commands/install.js +232 -82
  34. package/dist/commands/link.js +5 -4
  35. package/dist/commands/login.js +4 -3
  36. package/dist/commands/registry/build.d.ts +7 -3
  37. package/dist/commands/registry/build.js +23 -8
  38. package/dist/commands/registry/domain.js +3 -2
  39. package/dist/commands/registry/password.d.ts +19 -0
  40. package/dist/commands/registry/password.js +82 -0
  41. package/dist/commands/registry/push.d.ts +2 -1
  42. package/dist/commands/registry/push.js +10 -13
  43. package/dist/commands/reinstall.js +26 -20
  44. package/dist/commands/run.d.ts +23 -0
  45. package/dist/commands/run.js +163 -0
  46. package/dist/commands/update/panel.js +28 -5
  47. package/dist/commands/update.js +6 -5
  48. package/dist/commands/whoami.js +2 -1
  49. package/dist/lib/api.js +2 -2
  50. package/dist/lib/compose-version.d.ts +26 -0
  51. package/dist/lib/compose-version.js +61 -0
  52. package/dist/lib/connection-summary.d.ts +11 -4
  53. package/dist/lib/connection-summary.js +46 -11
  54. package/dist/lib/discovery.d.ts +24 -2
  55. package/dist/lib/discovery.js +97 -3
  56. package/dist/lib/docker.d.ts +9 -1
  57. package/dist/lib/docker.js +32 -2
  58. package/dist/lib/env-command.d.ts +109 -0
  59. package/dist/lib/env-command.js +230 -0
  60. package/dist/lib/env-file.d.ts +21 -0
  61. package/dist/lib/env-file.js +61 -0
  62. package/dist/lib/env-plan.d.ts +23 -0
  63. package/dist/lib/env-plan.js +34 -0
  64. package/dist/lib/env-run.d.ts +24 -0
  65. package/dist/lib/env-run.js +56 -0
  66. package/dist/lib/env-text.d.ts +97 -0
  67. package/dist/lib/env-text.js +266 -0
  68. package/dist/lib/image-confirm.d.ts +38 -0
  69. package/dist/lib/image-confirm.js +102 -0
  70. package/dist/lib/image-source.d.ts +59 -0
  71. package/dist/lib/image-source.js +261 -0
  72. package/dist/lib/install-plan.d.ts +69 -0
  73. package/dist/lib/install-plan.js +86 -0
  74. package/dist/lib/interrupt.d.ts +19 -0
  75. package/dist/lib/interrupt.js +42 -0
  76. package/dist/lib/leftover-volumes.d.ts +18 -0
  77. package/dist/lib/leftover-volumes.js +69 -0
  78. package/dist/lib/link-command.d.ts +9 -0
  79. package/dist/lib/link-command.js +23 -0
  80. package/dist/lib/manifest-parsers.d.ts +23 -0
  81. package/dist/lib/manifest-parsers.js +152 -0
  82. package/dist/lib/panel-addresses.d.ts +35 -0
  83. package/dist/lib/panel-addresses.js +122 -0
  84. package/dist/lib/registry-image-command.d.ts +24 -3
  85. package/dist/lib/registry-image-command.js +71 -10
  86. package/dist/lib/reinstall.d.ts +7 -0
  87. package/dist/lib/reinstall.js +28 -0
  88. package/dist/lib/run-banner.d.ts +18 -0
  89. package/dist/lib/run-banner.js +20 -0
  90. package/dist/lib/self-update.d.ts +4 -3
  91. package/dist/lib/self-update.js +6 -8
  92. package/dist/lib/style.d.ts +34 -0
  93. package/dist/lib/style.js +75 -0
  94. package/dist/lib/system-ca.d.ts +20 -0
  95. package/dist/lib/system-ca.js +29 -0
  96. package/dist/lib/types.d.ts +132 -0
  97. package/dist/lib/variable-sets.d.ts +90 -0
  98. package/dist/lib/variable-sets.js +177 -0
  99. package/oclif.manifest.json +1329 -72
  100. package/package.json +4 -1
@@ -86,7 +86,13 @@ services:
86
86
  # Self-hosted registry container is started by the API on the host engine.
87
87
  REGISTRY_PORT: ${REGISTRY_PORT:-5000}
88
88
  REGISTRY_PUBLIC_HOST: ${REGISTRY_PUBLIC_HOST:-localhost}
89
- REGISTRY_INTERNAL_URL: http://host.docker.internal:${REGISTRY_PORT:-5000}
89
+ # Interface the registry's host port is published on. Default 127.0.0.1 (this
90
+ # server only); 0.0.0.0 lets other machines push by IP. Applied when the
91
+ # registry container is (re)created.
92
+ REGISTRY_PUBLISH_ADDRESS: ${REGISTRY_PUBLISH_ADDRESS:-}
93
+ # The API reaches the registry over the `aoox` network (a loopback-only host port
94
+ # is not reachable through host.docker.internal on Linux).
95
+ REGISTRY_INTERNAL_URL: http://aoox-registry:5000
90
96
  # Traefik reverse proxy (container started by the API on the host engine)
91
97
  PROXY_HTTP_PORT: ${PROXY_HTTP_PORT:-80}
92
98
  PROXY_HTTPS_PORT: ${PROXY_HTTPS_PORT:-443}
@@ -100,8 +106,13 @@ services:
100
106
  BUILDKIT_CACHE_KEEP_GB: ${BUILDKIT_CACHE_KEEP_GB:-10}
101
107
  CONTAINER_LOG_MAX_SIZE: ${CONTAINER_LOG_MAX_SIZE:-10m}
102
108
  CONTAINER_LOG_MAX_FILE: ${CONTAINER_LOG_MAX_FILE:-3}
109
+ # Time zone cron schedules (jobs, backups, nightly maintenance) run in; UTC when unset.
110
+ TZ: ${TZ:-UTC}
103
111
  # Public IP app domains must point at (DNS check); auto-detected when empty.
104
112
  PUBLIC_IP: ${PUBLIC_IP:-}
113
+ # Host port the web is published on (same value as the `web` port mapping); only used
114
+ # to tell the owner where to reopen the dashboard after removing the panel domain.
115
+ WEB_PORT: ${WEB_PORT:-3000}
105
116
  STORAGE_PATH: ${STORAGE_PATH:-}
106
117
  # Absolute path, on this host, of the folder holding this file — required
107
118
  # only for Settings -> "Domain panel" (lets the API write
@@ -121,6 +132,9 @@ services:
121
132
  # (<app>-pr<N>.<domain>, needs a wildcard DNS record).
122
133
  WEBHOOK_VERIFY_GITHUB_IP: ${WEBHOOK_VERIFY_GITHUB_IP:-}
123
134
  PREVIEW_DOMAIN: ${PREVIEW_DOMAIN:-}
135
+ # Which proxy hops may set the client IP (X-Forwarded-For). Empty = private networks
136
+ # only (Traefik, the web container); see TRUST_PROXY in .env.dist.example.
137
+ TRUST_PROXY: ${TRUST_PROXY:-}
124
138
  # The api container runs as the unprivileged `node` user; add the gid that
125
139
  # owns the docker socket on the host (stat -c %g /var/run/docker.sock).
126
140
  group_add:
package/bin/dev.js CHANGED
@@ -4,12 +4,18 @@
4
4
  // so importing straight from src/ — instead of duplicating
5
5
  // windows-exit-fix.ts here — is fine.
6
6
  // eslint-disable-next-line n/no-unpublished-import
7
+ import {executeCli} from '../src/lib/interrupt.js'
8
+ // eslint-disable-next-line n/no-unpublished-import
9
+ import {applySystemCa} from '../src/lib/system-ca.js'
10
+ // eslint-disable-next-line n/no-unpublished-import
7
11
  import {applyWindowsExitFix} from '../src/lib/windows-exit-fix.js'
8
12
 
9
13
  // Must run before any command (and any fetch()) — see the doc comment on
10
14
  // applyWindowsExitFix for why.
11
15
  applyWindowsExitFix()
12
16
 
13
- const {execute} = await import('@oclif/core')
17
+ // Trust the OS certificate store too (antivirus HTTPS scanning, corporate proxies).
18
+ // Runs before the first fetch(); opt out with AOOX_SYSTEM_CA=0.
19
+ applySystemCa()
14
20
 
15
- await execute({development: true, dir: import.meta.url})
21
+ await executeCli({development: true, dir: import.meta.url})
package/bin/run.js CHANGED
@@ -1,11 +1,15 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ import {executeCli} from '../dist/lib/interrupt.js'
4
+ import {applySystemCa} from '../dist/lib/system-ca.js'
3
5
  import {applyWindowsExitFix} from '../dist/lib/windows-exit-fix.js'
4
6
 
5
7
  // Must run before any command (and any fetch()) — see the doc comment on
6
8
  // applyWindowsExitFix for why.
7
9
  applyWindowsExitFix()
8
10
 
9
- const {execute} = await import('@oclif/core')
11
+ // Trust the OS certificate store too (antivirus HTTPS scanning, corporate proxies).
12
+ // Runs before the first fetch(); opt out with AOOX_SYSTEM_CA=0.
13
+ applySystemCa()
10
14
 
11
- await execute({dir: import.meta.url})
15
+ await executeCli({dir: import.meta.url})
@@ -2,13 +2,14 @@ import { select } from '@inquirer/prompts';
2
2
  import { Command, Flags } from '@oclif/core';
3
3
  import { api, ApiError } from '../lib/api.js';
4
4
  import { MissingCredentialsError } from '../lib/config.js';
5
- import { dockerInherit, dockerLogin } from '../lib/docker.js';
5
+ import { dockerEngineStatus, dockerInherit, dockerLogin, dockerUnavailableLines } from '../lib/docker.js';
6
6
  import { connectionFlags, loadCredentials } from '../lib/flags.js';
7
7
  import { deployTag } from '../lib/git.js';
8
8
  import { imageRefFor } from '../lib/image-ref.js';
9
9
  import { readLink } from '../lib/link.js';
10
10
  import { warnIfOutdated } from '../lib/outdated.js';
11
11
  import { chooseRegistry, localhostRegistryHint } from '../lib/registry-select.js';
12
+ import { stepLine, successLine, warnLine } from '../lib/style.js';
12
13
  /** How often to poll GET /deployments/:id while a deploy is in progress. */
13
14
  const POLL_MS = 1500;
14
15
  export default class Deploy extends Command {
@@ -38,24 +39,29 @@ export default class Deploy extends Command {
38
39
  }
39
40
  throw error;
40
41
  }
41
- await warnIfOutdated((m) => this.warn(m), this.config.version, config);
42
+ await warnIfOutdated((m) => this.logToStderr(warnLine(m)), this.config.version, config);
42
43
  const app = await this.getApplication(config, link.applicationId);
43
44
  const registry = await this.pickRegistry(config, flags.registry);
44
45
  const credentials = await api(config, `/registries/${registry.id}/credentials`);
45
46
  const localHint = localhostRegistryHint(registry.url, config.url);
46
47
  if (localHint)
47
- this.warn(localHint);
48
+ this.logToStderr(warnLine(localHint));
48
49
  const tag = flags.tag ?? deployTag(cwd);
49
50
  const imageRef = imageRefFor({ appName: app.appName, projectName: app.project.name, registryUrl: registry.url, tag });
50
- this.log(`==> Build ${imageRef}`);
51
+ const engine = await dockerEngineStatus();
52
+ if (engine !== 'ok') {
53
+ const [headline, hint] = dockerUnavailableLines(engine);
54
+ this.error(headline, { suggestions: [hint] });
55
+ }
56
+ this.log(stepLine('Build', imageRef));
51
57
  await dockerInherit(['build', '-t', imageRef, '-f', flags.dockerfile, flags.context], cwd);
52
58
  if (credentials.username && credentials.password) {
53
- this.log(`==> docker login ${registry.url}`);
59
+ this.log(stepLine('docker login', registry.url));
54
60
  await dockerLogin(registry.url, credentials.username, credentials.password, cwd);
55
61
  }
56
- this.log(`==> Push ${imageRef}`);
62
+ this.log(stepLine('Push', imageRef));
57
63
  await dockerInherit(['push', imageRef], cwd);
58
- this.log('==> Updating the application & triggering a deploy');
64
+ this.log(stepLine('Updating the application & triggering a deploy'));
59
65
  await api(config, `/applications/${app.id}`, {
60
66
  body: { imageRef, imageRegistryId: registry.id, sourceType: 'image' },
61
67
  method: 'PATCH',
@@ -76,7 +82,7 @@ export default class Deploy extends Command {
76
82
  printed = dep.logs.length;
77
83
  }
78
84
  if (dep.status === 'success') {
79
- this.log(`Deployed: ${dep.imageRef}`);
85
+ this.log(successLine('Deployed:', dep.imageRef ?? undefined));
80
86
  return;
81
87
  }
82
88
  if (dep.status === 'failed') {
@@ -0,0 +1,16 @@
1
+ import { Command } from '@oclif/core';
2
+ /**
3
+ * Counterpart of `aoox domain set`: calls the panel's `DELETE /instance/domain`,
4
+ * which takes the dashboard and API back to plain IP access and recreates the
5
+ * web/api containers. The reverse proxy and application domains are untouched.
6
+ */
7
+ export default class DomainClear extends Command {
8
+ static description: string;
9
+ static examples: string[];
10
+ static flags: {
11
+ yes: import("@oclif/core/interfaces").BooleanFlag<boolean>;
12
+ token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
+ url: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
+ };
15
+ run(): Promise<void>;
16
+ }
@@ -0,0 +1,61 @@
1
+ import { confirm } from '@inquirer/prompts';
2
+ import { Command, Flags } from '@oclif/core';
3
+ import { api, ApiError } from '../../lib/api.js';
4
+ import { MissingCredentialsError } from '../../lib/config.js';
5
+ import { connectionFlags, loadCredentials } from '../../lib/flags.js';
6
+ import { warnIfOutdated } from '../../lib/outdated.js';
7
+ import { successLine, warnLine } from '../../lib/style.js';
8
+ /**
9
+ * Counterpart of `aoox domain set`: calls the panel's `DELETE /instance/domain`,
10
+ * which takes the dashboard and API back to plain IP access and recreates the
11
+ * web/api containers. The reverse proxy and application domains are untouched.
12
+ */
13
+ export default class DomainClear extends Command {
14
+ static description = 'Remove the custom domain of the panel itself and go back to IP access (IP:3000) through the running panel API';
15
+ static examples = ['<%= config.bin %> <%= command.id %>', '<%= config.bin %> <%= command.id %> --yes'];
16
+ static flags = {
17
+ ...connectionFlags,
18
+ yes: Flags.boolean({ char: 'y', default: false, description: 'Do not ask for confirmation' }),
19
+ };
20
+ async run() {
21
+ const { flags } = await this.parse(DomainClear);
22
+ let config;
23
+ try {
24
+ config = await loadCredentials(this.config.configDir, flags);
25
+ }
26
+ catch (error) {
27
+ if (error instanceof MissingCredentialsError) {
28
+ this.error(error.message, { suggestions: ['Run `aoox login` against this panel first.'] });
29
+ }
30
+ throw error;
31
+ }
32
+ await warnIfOutdated((m) => this.logToStderr(warnLine(m)), this.config.version, config);
33
+ if (!flags.yes) {
34
+ const ok = await confirm({
35
+ default: false,
36
+ message: 'Remove the panel domain? The dashboard and API go back to http://<server IP>:3000 / :3001 after a short restart, and this domain stops working. Applications and their domains are not touched.',
37
+ });
38
+ if (!ok)
39
+ this.exit(0);
40
+ }
41
+ let result;
42
+ try {
43
+ result = await api(config, '/instance/domain', { method: 'DELETE' });
44
+ }
45
+ catch (error) {
46
+ if (error instanceof ApiError && error.status === 400) {
47
+ this.error(error.message, {
48
+ suggestions: ['If INSTALL_DIR is missing, set it in the panel .env.dist, restart the stack and try again.'],
49
+ });
50
+ }
51
+ if (error instanceof ApiError && error.status === 502) {
52
+ this.error(error.message, { suggestions: ['Start Docker on the panel host and try again.'] });
53
+ }
54
+ throw error;
55
+ }
56
+ this.log(successLine('Panel domain removed.'));
57
+ this.log('The panel will restart for a few seconds to go back to IP access — the connection to this API will drop briefly.');
58
+ this.log(`Reopen the dashboard at ${result.reopenUrl ?? 'http://<server IP>:3000'} afterwards.`);
59
+ this.log('Run `aoox login` again with that address if you used the domain to sign in.');
60
+ }
61
+ }
@@ -11,6 +11,7 @@ export default class DomainSet extends Command {
11
11
  static flags: {
12
12
  'acme-email': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
13
  api: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
14
+ 'domain-only': import("@oclif/core/interfaces").BooleanFlag<boolean>;
14
15
  web: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
15
16
  token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
16
17
  url: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
@@ -3,6 +3,7 @@ import { api, ApiError } from '../../lib/api.js';
3
3
  import { MissingCredentialsError } from '../../lib/config.js';
4
4
  import { connectionFlags, loadCredentials } from '../../lib/flags.js';
5
5
  import { warnIfOutdated } from '../../lib/outdated.js';
6
+ import { successLine, warnLine } from '../../lib/style.js';
6
7
  /**
7
8
  * Post-install alternative to hand-editing docker-compose.domain.yml/.env.dist
8
9
  * over SSH (see the aoox-api AGENTS.md "Domains for the panel itself"):
@@ -14,11 +15,16 @@ export default class DomainSet extends Command {
14
15
  static examples = [
15
16
  '<%= config.bin %> <%= command.id %> --web panel.example.com --api api.example.com',
16
17
  '<%= config.bin %> <%= command.id %> --web panel.example.com --api api.example.com --acme-email you@example.com',
18
+ '<%= config.bin %> <%= command.id %> --web panel.example.com --api api.example.com --domain-only',
17
19
  ];
18
20
  static flags = {
19
21
  ...connectionFlags,
20
22
  'acme-email': Flags.string({ description: "Email for the Let's Encrypt certificate" }),
21
23
  api: Flags.string({ description: 'Domain for the panel API', required: true }),
24
+ 'domain-only': Flags.boolean({
25
+ allowNo: true,
26
+ description: 'Only allow access through the domain: ports 3000/3001 listen on 127.0.0.1 only (default: keep the current setting). Use --no-domain-only to open them again. Make sure the domain works first, or you lose IP:port access',
27
+ }),
22
28
  web: Flags.string({ description: 'Domain for the panel dashboard', required: true }),
23
29
  };
24
30
  async run() {
@@ -33,13 +39,14 @@ export default class DomainSet extends Command {
33
39
  }
34
40
  throw error;
35
41
  }
36
- await warnIfOutdated((m) => this.warn(m), this.config.version, config);
42
+ await warnIfOutdated((m) => this.logToStderr(warnLine(m)), this.config.version, config);
37
43
  let result;
38
44
  try {
39
45
  result = await api(config, '/instance/domain', {
40
46
  body: {
41
47
  ...(flags['acme-email'] ? { acmeEmail: flags['acme-email'] } : {}),
42
48
  apiHost: flags.api,
49
+ ...(flags['domain-only'] === undefined ? {} : { restrictPorts: flags['domain-only'] }),
43
50
  webHost: flags.web,
44
51
  },
45
52
  method: 'PATCH',
@@ -53,11 +60,16 @@ export default class DomainSet extends Command {
53
60
  }
54
61
  throw error;
55
62
  }
56
- this.log(`Domain saved: ${flags.web} (dashboard), ${flags.api} (API).`);
63
+ this.log(successLine(`Domain saved: ${flags.web} (dashboard), ${flags.api} (API).`));
57
64
  this.log('The panel will restart for a few seconds to apply it — the connection to this API will drop briefly.');
65
+ if (result.restrictPortsNote) {
66
+ this.log('');
67
+ this.logToStderr(warnLine('Access through IP:3000 / IP:3001 is closed once the panel restarts — use the domains above.'));
68
+ this.log(result.restrictPortsNote);
69
+ }
58
70
  if (result.proxyAutoProvisioned) {
59
71
  this.log('');
60
- this.warn('The reverse proxy was not running before — it has been enabled automatically.');
72
+ this.logToStderr(warnLine('The reverse proxy was not running before — it has been enabled automatically.'));
61
73
  this.log('The new domains will be reachable only if these three things are also correct:');
62
74
  this.log(` 1. DNS A records for ${flags.web} and ${flags.api} point to this server's IP.`);
63
75
  this.log(' 2. Ports 80 and 443 are open to the public (both the OS firewall and the VPS provider security group).');
@@ -0,0 +1,18 @@
1
+ import type { EnvironmentDiff } from '../../lib/types.js';
2
+ import { EnvCommand } from '../../lib/env-command.js';
3
+ export default class EnvDiff extends EnvCommand {
4
+ static description: string;
5
+ static enableJsonFlag: boolean;
6
+ static examples: string[];
7
+ static flags: {
8
+ from: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
9
+ set: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ to: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
11
+ app: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ stack: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
+ token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
+ url: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
15
+ };
16
+ run(): Promise<EnvironmentDiff>;
17
+ private section;
18
+ }
@@ -0,0 +1,51 @@
1
+ import { Flags } from '@oclif/core';
2
+ import { api } from '../../lib/api.js';
3
+ import { EnvCommand, ownerFlags, selectorFlags } from '../../lib/env-command.js';
4
+ import { connectionFlags } from '../../lib/flags.js';
5
+ export default class EnvDiff extends EnvCommand {
6
+ static description = 'Compare two environments of a variable set key by key: which variables exist on one side only and which have different values. Prints names only, never values';
7
+ static enableJsonFlag = true;
8
+ static examples = ['<%= config.bin %> <%= command.id %> --set shared --from staging --to production'];
9
+ static flags = {
10
+ ...connectionFlags,
11
+ ...ownerFlags,
12
+ from: Flags.string({ description: 'Environment to compare from', required: true }),
13
+ set: selectorFlags.set,
14
+ to: Flags.string({ description: 'Environment to compare to', required: true }),
15
+ };
16
+ async run() {
17
+ const { flags } = await this.parse(EnvDiff);
18
+ if (flags.from === flags.to)
19
+ this.fail('Choose two different environments.');
20
+ const { config, set } = await this.resolveSet(flags);
21
+ let diff;
22
+ try {
23
+ diff = await api(config, `/variable-sets/${set.id}/diff?from=${encodeURIComponent(flags.from)}&to=${encodeURIComponent(flags.to)}`);
24
+ }
25
+ catch (error) {
26
+ return this.failFromApi(error);
27
+ }
28
+ this.log(`Set: ${set.slug} · ${diff.from.name} -> ${diff.to.name}`);
29
+ this.section(`Only in ${diff.from.name}`, diff.onlyInFrom);
30
+ this.section(`Only in ${diff.to.name}`, diff.onlyInTo);
31
+ if (diff.comparable && diff.different && diff.same) {
32
+ this.section('Different values', diff.different);
33
+ this.log(`Same in both: ${diff.same.length}`);
34
+ if (diff.onlyInFrom.length + diff.onlyInTo.length + diff.different.length === 0) {
35
+ this.log('The two environments are identical.');
36
+ }
37
+ }
38
+ else {
39
+ this.log(`In both: ${diff.inBoth.length}`);
40
+ this.log('Values were not compared: you cannot read both environments (a protected environment needs an instance owner or admin, and a token scope can exclude one).');
41
+ }
42
+ return diff;
43
+ }
44
+ section(title, names) {
45
+ if (names.length === 0)
46
+ return;
47
+ this.log(`${title} (${names.length}):`);
48
+ for (const n of names)
49
+ this.log(` ${n}`);
50
+ }
51
+ }
@@ -0,0 +1,17 @@
1
+ import type { EnvironmentVersion } from '../../lib/types.js';
2
+ import { EnvCommand } from '../../lib/env-command.js';
3
+ export default class EnvHistory extends EnvCommand {
4
+ static description: string;
5
+ static enableJsonFlag: boolean;
6
+ static examples: string[];
7
+ static flags: {
8
+ limit: import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>;
9
+ env: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ set: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ app: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ stack: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
+ token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
+ url: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
15
+ };
16
+ run(): Promise<EnvironmentVersion[]>;
17
+ }
@@ -0,0 +1,48 @@
1
+ import { Flags } from '@oclif/core';
2
+ import { api } from '../../lib/api.js';
3
+ import { EnvCommand, environmentCommandFlags } from '../../lib/env-command.js';
4
+ import { describeSummary } from '../../lib/env-plan.js';
5
+ export default class EnvHistory extends EnvCommand {
6
+ static description = 'Show the version history of a variable set environment: when, who, and which variable names were added (+), changed (~) or removed (-). Values are never shown';
7
+ static enableJsonFlag = true;
8
+ static examples = [
9
+ '<%= config.bin %> <%= command.id %> --set shared --env production',
10
+ '<%= config.bin %> <%= command.id %> --limit 5 --json',
11
+ ];
12
+ static flags = {
13
+ ...environmentCommandFlags,
14
+ limit: Flags.integer({ default: 20, description: 'How many versions to show (newest first)', min: 1 }),
15
+ };
16
+ async run() {
17
+ const { flags } = await this.parse(EnvHistory);
18
+ const resolved = await this.resolveEnvironment(flags);
19
+ let versions;
20
+ try {
21
+ versions = await api(resolved.config, `/variable-sets/${resolved.set.id}/environments/${resolved.environment.id}/versions`);
22
+ }
23
+ catch (error) {
24
+ return this.failFromApi(error, { environment: resolved.label });
25
+ }
26
+ this.log(`Environment: ${resolved.label}`);
27
+ if (versions.length === 0) {
28
+ this.log('No versions yet: the first change creates one.');
29
+ return [];
30
+ }
31
+ const shown = versions.slice(0, flags.limit);
32
+ const when = (v) => new Date(v.createdAt).toISOString().replace('T', ' ').slice(0, 19);
33
+ const who = (v) => `${v.authorEmail ?? 'system'}${v.via === 'token' ? ' (token)' : ''}`;
34
+ const w = {
35
+ action: Math.max(6, ...shown.map((v) => v.action.length)),
36
+ who: Math.max(3, ...shown.map((v) => who(v).length)),
37
+ };
38
+ this.log(`${'WHEN (UTC)'.padEnd(19)} ${'WHO'.padEnd(w.who)} ${'ACTION'.padEnd(w.action)} CHANGE`);
39
+ for (const v of shown) {
40
+ const detail = v.detail && v.action !== 'baseline' ? ` (${v.detail})` : '';
41
+ this.log(`${when(v).padEnd(19)} ${who(v).padEnd(w.who)} ${v.action.padEnd(w.action)} ${describeSummary(v.summary)}${detail}${v.current ? ' <- current' : ''}`);
42
+ }
43
+ const older = versions.length - shown.length;
44
+ if (older > 0)
45
+ this.log(`... ${older} older version${older === 1 ? '' : 's'} (use --limit)`);
46
+ return shown;
47
+ }
48
+ }
@@ -0,0 +1,17 @@
1
+ import type { LinkView } from '../../lib/types.js';
2
+ import { LinkCommand } from '../../lib/link-command.js';
3
+ export default class EnvLink extends LinkCommand {
4
+ static description: string;
5
+ static enableJsonFlag: boolean;
6
+ static examples: string[];
7
+ static flags: {
8
+ env: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
9
+ position: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ set: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
11
+ app: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ stack: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
+ token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
+ url: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
15
+ };
16
+ run(): Promise<LinkView[]>;
17
+ }
@@ -0,0 +1,53 @@
1
+ import { Flags } from '@oclif/core';
2
+ import { api } from '../../lib/api.js';
3
+ import { ownerFlags } from '../../lib/env-command.js';
4
+ import { connectionFlags } from '../../lib/flags.js';
5
+ import { LinkCommand } from '../../lib/link-command.js';
6
+ import { addLink, findSet, pickEnvironment, SelectionError } from '../../lib/variable-sets.js';
7
+ export default class EnvLink extends LinkCommand {
8
+ static description = 'Link a variable set environment to the linked application (or --stack). It is added last, so it wins over the other links, unless --position is given; an environment that is already linked is moved. Takes effect on the next deploy';
9
+ static enableJsonFlag = true;
10
+ static examples = [
11
+ '<%= config.bin %> <%= command.id %> --set shared --env production',
12
+ '<%= config.bin %> <%= command.id %> --set defaults --env production --position 1',
13
+ ];
14
+ static flags = {
15
+ ...connectionFlags,
16
+ ...ownerFlags,
17
+ env: Flags.string({ char: 'e', description: 'Environment of the set', required: true }),
18
+ position: Flags.integer({ description: '1-based place in the list (1 = first, overridden by every later link). Default: last' }),
19
+ set: Flags.string({ char: 's', description: 'Variable set slug (or name)', required: true }),
20
+ };
21
+ async run() {
22
+ const { flags } = await this.parse(EnvLink);
23
+ const { config, link } = await this.connect(flags);
24
+ const owner = (await this.resolveOwner(config, link, flags, true));
25
+ let sets;
26
+ try {
27
+ sets = await api(config, '/variable-sets');
28
+ }
29
+ catch (error) {
30
+ return this.failFromApi(error);
31
+ }
32
+ let next;
33
+ try {
34
+ const set = findSet(sets, flags.set);
35
+ if (!set) {
36
+ throw new SelectionError(`Variable set "${flags.set}" not found.`, [
37
+ `Sets you can see: ${sets.map((s) => s.slug).join(', ') || 'none'}`,
38
+ ]);
39
+ }
40
+ const environment = pickEnvironment(set, flags.env);
41
+ const current = [...owner.detail.variableSets]
42
+ .sort((a, b) => a.position - b.position)
43
+ .map((l) => ({ environmentId: l.environmentId }));
44
+ next = addLink(current, environment.id, flags.position);
45
+ }
46
+ catch (error) {
47
+ if (error instanceof SelectionError)
48
+ this.fail(error.message, ...error.hints);
49
+ throw error;
50
+ }
51
+ return this.replaceLinks(config, owner, next);
52
+ }
53
+ }
@@ -0,0 +1,14 @@
1
+ import type { LinkView } from '../../lib/types.js';
2
+ import { EnvCommand } from '../../lib/env-command.js';
3
+ export default class EnvLinks extends EnvCommand {
4
+ static description: string;
5
+ static enableJsonFlag: boolean;
6
+ static examples: string[];
7
+ static flags: {
8
+ app: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ stack: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ url: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ };
13
+ run(): Promise<LinkView[]>;
14
+ }
@@ -0,0 +1,17 @@
1
+ import { EnvCommand, ownerFlags } from '../../lib/env-command.js';
2
+ import { connectionFlags } from '../../lib/flags.js';
3
+ import { describeLinks } from '../../lib/variable-sets.js';
4
+ export default class EnvLinks extends EnvCommand {
5
+ static description = 'Show the variable set environments the linked application (or --stack) uses, in merge order, with the variables a later link or the own env overrides';
6
+ static enableJsonFlag = true;
7
+ static examples = ['<%= config.bin %> <%= command.id %>', '<%= config.bin %> <%= command.id %> --stack <id>'];
8
+ static flags = { ...connectionFlags, ...ownerFlags };
9
+ async run() {
10
+ const { flags } = await this.parse(EnvLinks);
11
+ const { config, link } = await this.connect(flags);
12
+ const owner = (await this.resolveOwner(config, link, flags, true));
13
+ for (const line of describeLinks(owner.label, owner.detail.variableSets))
14
+ this.log(line);
15
+ return owner.detail.variableSets;
16
+ }
17
+ }
@@ -0,0 +1,40 @@
1
+ import { EnvCommand } from '../../lib/env-command.js';
2
+ export interface EnvListSet {
3
+ environments: Array<{
4
+ name: string;
5
+ protected: boolean;
6
+ usedBy: number;
7
+ variables: number;
8
+ }>;
9
+ name: string;
10
+ role: string;
11
+ sharedWithAll: boolean;
12
+ slug: string;
13
+ }
14
+ export interface EnvListVariables {
15
+ environment: string;
16
+ protected: boolean;
17
+ /** Variables flagged secret. */
18
+ secretKeys: string[];
19
+ set: string;
20
+ /** Present only with `--reveal`. */
21
+ values?: Record<string, string>;
22
+ variables: string[];
23
+ }
24
+ export default class EnvList extends EnvCommand {
25
+ static aliases: string[];
26
+ static description: string;
27
+ static enableJsonFlag: boolean;
28
+ static examples: string[];
29
+ static flags: {
30
+ env: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
31
+ reveal: import("@oclif/core/interfaces").BooleanFlag<boolean>;
32
+ set: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
33
+ app: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
34
+ stack: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
35
+ token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
36
+ url: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
37
+ };
38
+ run(): Promise<EnvListSet[] | EnvListVariables>;
39
+ private listVariables;
40
+ }