@faable/faable 4.5.2 → 4.5.4
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.
package/dist/api/FaableApi.js
CHANGED
|
@@ -130,12 +130,19 @@ class FaableApi {
|
|
|
130
130
|
async issueAuthAccountToken(account_id) {
|
|
131
131
|
return data(this.client.post(`/auth-accounts/${account_id}/token`));
|
|
132
132
|
}
|
|
133
|
-
// Every app the caller can see, across projects
|
|
134
|
-
//
|
|
135
|
-
// app lives outside the active project must still resolve.
|
|
133
|
+
// Every app the caller can see, across projects (`faable link` offers them
|
|
134
|
+
// to pick from).
|
|
136
135
|
async list() {
|
|
137
136
|
return allPages(next => this.listApps({ pageSize: 200, next }, null));
|
|
138
137
|
}
|
|
138
|
+
// The apps linked to `repository` (the `org/repo` slug), across projects —
|
|
139
|
+
// filtered (and indexed) server side, so a staff session doesn't page
|
|
140
|
+
// through the whole platform to match one repository.
|
|
141
|
+
async appsByRepository(repository) {
|
|
142
|
+
return allPages(next => data(this.client.get(`/app`, {
|
|
143
|
+
params: { repository, ...page_params({ pageSize: 200, next }) }
|
|
144
|
+
})));
|
|
145
|
+
}
|
|
139
146
|
// One page of apps, scoped to `project` (default: the active project).
|
|
140
147
|
// `null` = unscoped. The api filters by the header, so an admin session
|
|
141
148
|
// doesn't page through the whole platform.
|
|
@@ -293,9 +300,10 @@ class FaableApi {
|
|
|
293
300
|
async listDomains(app_id, team) {
|
|
294
301
|
return firstPage(this.listDomainsPage(app_id, team));
|
|
295
302
|
}
|
|
303
|
+
// Without `app_id`, every domain of the project.
|
|
296
304
|
async listDomainsPage(app_id, team, params = {}) {
|
|
297
305
|
return data(this.client.get(`/domain`, {
|
|
298
|
-
params: { app_id, ...page_params(params) },
|
|
306
|
+
params: { ...(app_id ? { app_id } : {}), ...page_params(params) },
|
|
299
307
|
headers: projectHeader(team)
|
|
300
308
|
}));
|
|
301
309
|
}
|
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
import { requireApi } from '../../../api/context.js';
|
|
2
2
|
import { fetch_page, print_json, print, more_hint, list_options } from '../../../lib/listing.js';
|
|
3
3
|
import { log } from '../../../log.js';
|
|
4
|
-
import {
|
|
4
|
+
import { requireProject } from '../../../api/project.js';
|
|
5
|
+
import { find_app_id } from '../resolve_app_id.js';
|
|
5
6
|
import { dns_badge, cname_target } from './format.js';
|
|
6
7
|
|
|
7
8
|
const domains_list = {
|
|
8
9
|
command: 'list',
|
|
9
|
-
describe: 'List custom domains of the app',
|
|
10
|
+
describe: 'List custom domains of the app (or of the project, outside a linked repo)',
|
|
10
11
|
builder: yargs => list_options(yargs)
|
|
11
12
|
.option('app', {
|
|
12
13
|
alias: 'a',
|
|
13
14
|
type: 'string',
|
|
14
15
|
description: 'App id, name or slug (defaults to the linked app)'
|
|
15
16
|
})
|
|
16
|
-
.example('$0 deploy domains list', 'Domains of the linked app')
|
|
17
|
+
.example('$0 deploy domains list', 'Domains of the linked app, or of the active project when there is none')
|
|
17
18
|
.showHelpOnFail(false),
|
|
18
19
|
handler: async (args) => {
|
|
19
20
|
const ctx = await requireApi();
|
|
20
|
-
const app_id = await
|
|
21
|
+
const app_id = await find_app_id(args.app, ctx.appId, ctx.api);
|
|
22
|
+
if (!app_id)
|
|
23
|
+
return list_project_domains(ctx.api, args);
|
|
21
24
|
const app = await ctx.api.getApp(app_id);
|
|
22
25
|
const page = await fetch_page(p => ctx.api.listDomainsPage(app_id, app.team, p), args);
|
|
23
26
|
if (args.json)
|
|
@@ -48,5 +51,35 @@ const domains_list = {
|
|
|
48
51
|
}
|
|
49
52
|
}
|
|
50
53
|
};
|
|
54
|
+
// No app here (an unlinked directory): the domains of the active project,
|
|
55
|
+
// each with the app it routes to.
|
|
56
|
+
const list_project_domains = async (api, args) => {
|
|
57
|
+
const { id: project } = await requireProject(api);
|
|
58
|
+
const page = await fetch_page(p => api.listDomainsPage(undefined, project, p), args);
|
|
59
|
+
if (args.json)
|
|
60
|
+
return print_json(page);
|
|
61
|
+
const domains = page.data;
|
|
62
|
+
if (domains.length === 0) {
|
|
63
|
+
log.info(`🌐 No custom domains in ${project}.`);
|
|
64
|
+
log.info(`Add one with: faable deploy domains add <yourdomain.com> --app <app>.`);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const apps = await fetch_page(p => api.listApps(p, project), {
|
|
68
|
+
limit: 200,
|
|
69
|
+
all: true
|
|
70
|
+
});
|
|
71
|
+
const app_name = new Map(apps.data.map(a => [a.id, a.name]));
|
|
72
|
+
const label = (d) => d.app_id ? app_name.get(d.app_id) ?? d.app_id : '(no app)';
|
|
73
|
+
log.info(`🌐 ${domains.length} domain(s) in ${project}:`);
|
|
74
|
+
const width = Math.max(...domains.map(d => d.fqdn.length));
|
|
75
|
+
const app_width = Math.max(...domains.map(d => label(d).length));
|
|
76
|
+
for (const domain of domains) {
|
|
77
|
+
const tls = domain.tls ? 'tls' : 'no-tls';
|
|
78
|
+
print(` ${domain.fqdn.padEnd(width)} ${label(domain).padEnd(app_width)} ${dns_badge(domain)} (${tls})`);
|
|
79
|
+
}
|
|
80
|
+
const hint = more_hint(page);
|
|
81
|
+
if (hint)
|
|
82
|
+
log.info(hint);
|
|
83
|
+
};
|
|
51
84
|
|
|
52
85
|
export { domains_list };
|
|
@@ -57,8 +57,7 @@ const find_app_id = async (explicit, ctxAppId, api, workdir = process.cwd()) =>
|
|
|
57
57
|
return app_id;
|
|
58
58
|
const repository = await getGitRemoteUrl(workdir);
|
|
59
59
|
if (repository) {
|
|
60
|
-
const
|
|
61
|
-
const matches = apps.filter(app => app.repository === repository);
|
|
60
|
+
const matches = await api.appsByRepository(repository);
|
|
62
61
|
if (matches.length === 1) {
|
|
63
62
|
const app = matches[0];
|
|
64
63
|
log.info(`🔎 Detected app "${app.name}" (${app.id}) from repository ${repository}`);
|
|
@@ -23,12 +23,12 @@ const upgrade = {
|
|
|
23
23
|
}
|
|
24
24
|
const spinner = ora(`Upgrading ${CLI_PACKAGE} ${version} → ${latest}`).start();
|
|
25
25
|
try {
|
|
26
|
-
await cmd(`npm install -g ${CLI_PACKAGE}@latest`, { timeout: 180_000 });
|
|
26
|
+
await cmd(`npm install -g --prefer-online ${CLI_PACKAGE}@latest`, { timeout: 180_000 });
|
|
27
27
|
spinner.succeed(`Upgraded to ${latest}`);
|
|
28
28
|
}
|
|
29
29
|
catch {
|
|
30
30
|
spinner.fail("Upgrade failed");
|
|
31
|
-
log.error(`❌ Could not upgrade automatically. Try manually: npm install -g ${CLI_PACKAGE}@latest`);
|
|
31
|
+
log.error(`❌ Could not upgrade automatically. Try manually: npm install -g --prefer-online ${CLI_PACKAGE}@latest`);
|
|
32
32
|
process.exit(1);
|
|
33
33
|
}
|
|
34
34
|
},
|
|
@@ -23,7 +23,6 @@ class CredentialsStore {
|
|
|
23
23
|
await fs.ensureDir(this.faable_home);
|
|
24
24
|
await fs.writeJSON(this.credentials_path, config, { spaces: 2 });
|
|
25
25
|
await fs.chmod(this.credentials_path, 0o600);
|
|
26
|
-
this.log.info(`Stored credentials`);
|
|
27
26
|
}
|
|
28
27
|
async loadCredentials() {
|
|
29
28
|
const old_path = path__default.join(this.faable_home, 'credentials');
|