@faable/faable 4.35.0 → 4.37.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.
@@ -495,6 +495,13 @@ class FaableApi {
495
495
  headers: projectHeader(team)
496
496
  }));
497
497
  }
498
+ // Relink a domain to another app of its project (or `null` to unlink it).
499
+ // Keeps the row: same id, same CNAME target, same certificate.
500
+ async updateDomain(domain_id, team, params) {
501
+ return data(this.client.post(`/domain/${domain_id}`, params, {
502
+ headers: projectHeader(team)
503
+ }));
504
+ }
498
505
  async deleteDomain(domain_id, team) {
499
506
  return data(this.client.delete(`/domain/${domain_id}`, {
500
507
  headers: projectHeader(team)
@@ -2,7 +2,8 @@ import { requireApi } from '../../../api/context.js';
2
2
  import { print_json, json_option } from '../../../lib/listing.js';
3
3
  import { log } from '../../../log.js';
4
4
  import { resolve_app_id } from '../resolve_app_id.js';
5
- import { acme_record, cname_target } from './format.js';
5
+ import { pair_fqdn, acme_record, cname_target } from './format.js';
6
+ import { add_conflict_hint } from './locate.js';
6
7
 
7
8
  const domains_add = {
8
9
  command: 'add <fqdn>',
@@ -22,31 +23,62 @@ const domains_add = {
22
23
  type: 'boolean',
23
24
  default: true,
24
25
  description: 'Provision a TLS certificate automatically (default)'
26
+ })
27
+ .option('www', {
28
+ type: 'boolean',
29
+ description: 'Also add the www (or root) counterpart, redirecting to this domain: example.com and www.example.com'
25
30
  })
26
31
  .example('$0 deploy domains add www.example.com', 'Attach www.example.com to the linked app')
32
+ .example('$0 deploy domains add example.com --www', 'Attach example.com, and www.example.com redirecting to it')
27
33
  .showHelpOnFail(false),
28
34
  handler: async (args) => {
29
35
  const ctx = await requireApi();
30
36
  const app_id = await resolve_app_id(args.app, ctx.appId, ctx.api);
31
37
  const app = await ctx.api.getApp(app_id);
32
- const domain = await ctx.api.createDomain(app.team, {
38
+ const domain = await ctx.api
39
+ .createDomain(app.team, {
33
40
  fqdn: args.fqdn,
34
41
  app_id,
35
- tls: args.tls
42
+ tls: args.tls,
43
+ ...(args.www ? { www: true } : {})
44
+ })
45
+ .catch(async (err) => {
46
+ // Already in this project (an app deletion leaves its domains linked
47
+ // to no app): name the command that fixes it, not "another project".
48
+ throw ((await add_conflict_hint(ctx.api, app.team, args.fqdn, app_id, err)) ?? err);
36
49
  });
50
+ // The pair's other half was created by the api with the main one; its DNS
51
+ // is a second record to create, so it is shown too.
52
+ const pair = args.www
53
+ ? (await ctx.api.listDomains(app_id, app.team)).find(d => d.fqdn === pair_fqdn(domain.fqdn))
54
+ : undefined;
37
55
  // Same shape as `domains check --json`: the record plus the CNAME to
38
56
  // create, which is the whole next step.
39
57
  if (args.json) {
40
58
  return print_json({
41
59
  ...domain,
42
60
  expected_cname: cname_target(domain),
43
- ...(args.tls ? { prevalidation_cname: acme_record(domain) } : {})
61
+ ...(args.tls ? { prevalidation_cname: acme_record(domain) } : {}),
62
+ ...(pair
63
+ ? {
64
+ pair: {
65
+ ...pair,
66
+ expected_cname: cname_target(pair),
67
+ ...(args.tls ? { prevalidation_cname: acme_record(pair) } : {})
68
+ }
69
+ }
70
+ : {})
44
71
  });
45
72
  }
46
73
  log.info(`🌐 Domain ${domain.fqdn} added to ${app.name} (${app_id}).`);
74
+ if (pair) {
75
+ log.info(` ${pair.fqdn} added too, redirecting to ${domain.fqdn}.`);
76
+ }
47
77
  log.info(``);
48
- log.info(`Now create a CNAME record at your DNS provider:`);
78
+ log.info(`Now create ${pair ? 'these records' : 'a CNAME record'} at your DNS provider:`);
49
79
  log.info(` ${domain.fqdn} → ${cname_target(domain)}`);
80
+ if (pair)
81
+ log.info(` ${pair.fqdn} → ${cname_target(pair)}`);
50
82
  log.info(``);
51
83
  log.info(`Faable verifies the record automatically once DNS propagates${args.tls ? ' and then provisions the TLS certificate' : ''}.`);
52
84
  if (args.tls) {
@@ -54,6 +86,10 @@ const domains_add = {
54
86
  log.info(``);
55
87
  log.info(`Already serving ${domain.fqdn} somewhere else? Create this record FIRST and leave the CNAME above for later:`);
56
88
  log.info(` ${acme.name} → ${acme.target}`);
89
+ if (pair) {
90
+ const pacme = acme_record(pair);
91
+ log.info(` ${pacme.name} → ${pacme.target}`);
92
+ }
57
93
  log.info(`Faable then issues the certificate before any traffic moves, and switching the CNAME has no TLS gap.`);
58
94
  }
59
95
  log.info(`Track it with: faable deploy domains check ${domain.fqdn}`);
@@ -0,0 +1,63 @@
1
+ import { requireApi } from '../../../api/context.js';
2
+ import { confirm } from '../../../lib/interactive.js';
3
+ import { print_json, json_option } from '../../../lib/listing.js';
4
+ import { log } from '../../../log.js';
5
+ import { resolve_app_id } from '../resolve_app_id.js';
6
+ import { cname_target } from './format.js';
7
+ import { locate_domain, attach_plan } from './locate.js';
8
+
9
+ const domains_attach = {
10
+ command: 'attach <fqdn>',
11
+ describe: 'Link a domain of the project to an app — one left with no app, or one moving from another app',
12
+ builder: yargs => json_option(yargs)
13
+ .positional('fqdn', {
14
+ type: 'string',
15
+ demandOption: true,
16
+ description: 'A domain already in the project'
17
+ })
18
+ .option('app', {
19
+ alias: 'a',
20
+ type: 'string',
21
+ description: 'App id, name or slug (defaults to the linked app)'
22
+ })
23
+ .option('yes', {
24
+ alias: 'y',
25
+ type: 'boolean',
26
+ default: false,
27
+ description: 'Skip the confirmation when the domain moves from another app'
28
+ })
29
+ .example('$0 deploy domains attach app.example.com --app web', 'Serve a domain whose app was deleted from "web"')
30
+ .epilog('The domain keeps its id, its CNAME target and its TLS certificate: no DNS change and no new certificate. Deleting an app leaves its domains in the project with no app; this links them again.')
31
+ .showHelpOnFail(false),
32
+ handler: async (args) => {
33
+ const ctx = await requireApi();
34
+ const app_id = await resolve_app_id(args.app, ctx.appId, ctx.api);
35
+ const app = await ctx.api.getApp(app_id);
36
+ // Any domain of the project: `locate_domain` without an app restriction.
37
+ const found = await locate_domain(ctx.api, app.team, args.fqdn, null);
38
+ const plan = attach_plan(found, app_id);
39
+ if (plan.kind === 'already') {
40
+ if (args.json)
41
+ return print_json(plan.domain);
42
+ log.info(`🌐 ${plan.domain.fqdn} is already attached to ${app.name} (${app_id}).`);
43
+ return;
44
+ }
45
+ if (plan.from) {
46
+ const go = await confirm({
47
+ message: `Move domain "${found.fqdn}" from ${plan.from} to ${app.name} (${app_id})? ${plan.from} stops serving it.`,
48
+ yes: args.yes
49
+ });
50
+ if (!go) {
51
+ log.info('Cancelled.');
52
+ return;
53
+ }
54
+ }
55
+ const domain = await ctx.api.updateDomain(found.id, app.team, { app_id });
56
+ if (args.json)
57
+ return print_json(domain);
58
+ log.info(`🔗 ${domain.fqdn} now serves ${app.name} (${app_id})${plan.from ? `, instead of ${plan.from}` : ''}.`);
59
+ log.info(`Same CNAME (${domain.fqdn} → ${cname_target(domain)}) and the same certificate: nothing to change at your DNS provider.`);
60
+ }
61
+ };
62
+
63
+ export { domains_attach };
@@ -1,8 +1,8 @@
1
1
  import { requireApi } from '../../../api/context.js';
2
2
  import { print_json, json_option } from '../../../lib/listing.js';
3
3
  import { log } from '../../../log.js';
4
- import { resolve_app_id } from '../resolve_app_id.js';
5
- import { find_by_fqdn, acme_record, cname_target, dns_badge, tls_line } from './format.js';
4
+ import { acme_record, cname_target, dns_badge, tls_line } from './format.js';
5
+ import { domain_scope, locate_domain } from './locate.js';
6
6
 
7
7
  const domains_check = {
8
8
  command: 'check <fqdn>',
@@ -16,18 +16,13 @@ const domains_check = {
16
16
  .option('app', {
17
17
  alias: 'a',
18
18
  type: 'string',
19
- description: 'App id, name or slug (defaults to the linked app)'
19
+ description: 'App id, name or slug. Optional: the domain is looked up in the project'
20
20
  })
21
21
  .showHelpOnFail(false),
22
22
  handler: async (args) => {
23
23
  const ctx = await requireApi();
24
- const app_id = await resolve_app_id(args.app, ctx.appId, ctx.api);
25
- const app = await ctx.api.getApp(app_id);
26
- const domains = await ctx.api.listDomains(app_id, app.team);
27
- const domain = find_by_fqdn(domains, args.fqdn);
28
- if (!domain) {
29
- throw new Error(`Domain ${args.fqdn} is not attached to ${app_id}. List them with "faable deploy domains list".`);
30
- }
24
+ const scope = await domain_scope(ctx.api, args.app, ctx.appId);
25
+ const domain = await locate_domain(ctx.api, scope.team, args.fqdn, scope.explicit);
31
26
  // The record plus the one thing it does not carry: the CNAME to create.
32
27
  if (args.json) {
33
28
  return print_json({
@@ -38,6 +33,9 @@ const domains_check = {
38
33
  }
39
34
  const status = domain.status;
40
35
  log.info(`🌐 ${domain.fqdn} — ${dns_badge(domain)}`);
36
+ if (!domain.app_id) {
37
+ log.warn(` Linked to no app: it answers DOMAIN_NOT_LINKED. Serve it with: faable deploy domains attach ${domain.fqdn} --app <app>`);
38
+ }
41
39
  log.info(` Expected CNAME: ${domain.fqdn} → ${cname_target(domain)}`);
42
40
  if (status?.dns_observed?.length) {
43
41
  log.info(` Observed: ${status.dns_observed.join(', ')}`);
@@ -41,5 +41,11 @@ const tls_line = (domain) => {
41
41
  : '⏳ issued once the CNAME (or the pre-validation record) is in place';
42
42
  };
43
43
  const find_by_fqdn = (domains, fqdn) => domains.find(d => d.fqdn.toLowerCase() === fqdn.toLowerCase());
44
+ /**
45
+ * The other half of an apex/www pair created with `--www`. The api has already
46
+ * checked the name is an apex or its www (Public Suffix List); this only names
47
+ * the counterpart to look it up.
48
+ */
49
+ const pair_fqdn = (fqdn) => fqdn.startsWith('www.') ? fqdn.slice(4) : `www.${fqdn}`;
44
50
 
45
- export { acme_record, cname_target, dns_badge, find_by_fqdn, tls_line };
51
+ export { acme_record, cname_target, dns_badge, find_by_fqdn, pair_fqdn, tls_line };
@@ -1,4 +1,5 @@
1
1
  import { domains_add } from './add.js';
2
+ import { domains_attach } from './attach.js';
2
3
  import { domains_check } from './check.js';
3
4
  import { domains_list } from './list.js';
4
5
  import { domains_rm } from './rm.js';
@@ -9,9 +10,10 @@ const domains = {
9
10
  builder: yargs => yargs
10
11
  .command(domains_list)
11
12
  .command(domains_add)
13
+ .command(domains_attach)
12
14
  .command(domains_check)
13
15
  .command(domains_rm)
14
- .demandCommand(1, 'Specify a domains command: list, add, check or rm'),
16
+ .demandCommand(1, 'Specify a domains command: list, add, attach, check or rm'),
15
17
  handler: () => {
16
18
  // Unreachable: demandCommand(1) either routes to a subcommand or fails
17
19
  // through the global .fail() in src/index.ts.
@@ -0,0 +1,67 @@
1
+ import { requireProject } from '../../../api/project.js';
2
+ import { CliError } from '../../../lib/errors.js';
3
+ import { fetch_page } from '../../../lib/listing.js';
4
+ import { find_app_id } from '../resolve_app_id.js';
5
+ import { find_by_fqdn } from './format.js';
6
+
7
+ // A domain is the PROJECT's, not the app's: deleting an app unlinks its domains
8
+ // and leaves them in the project with no app (api deploy/domain/lifecycle.ts).
9
+ // So a domain is looked up in the whole project, never only in one app's list —
10
+ // that is how `rm` and `check` could not see app.ciapol.com (2026-11-09).
11
+ const project_domains = async (api, team) => (await fetch_page(p => api.listDomainsPage(undefined, team, p), {
12
+ limit: 200,
13
+ all: true
14
+ })).data;
15
+ const find_project_domain = async (api, team, fqdn) => find_by_fqdn(await project_domains(api, team), fqdn);
16
+ const not_in_project = (fqdn, team) => new CliError('not_found', `Domain ${fqdn} is not in project ${team}. List them with "faable deploy domains list".`);
17
+ /**
18
+ * The domain `fqdn` of the project. With an app, it must be that app's — or
19
+ * linked to no app, which any app may act on: there is no other app to name.
20
+ */
21
+ const locate_domain = async (api, team, fqdn, app_id) => {
22
+ const domain = await find_project_domain(api, team, fqdn);
23
+ if (!domain)
24
+ throw not_in_project(fqdn, team);
25
+ if (app_id && domain.app_id && domain.app_id !== app_id) {
26
+ throw new CliError('not_found', `Domain ${domain.fqdn} is attached to ${domain.app_id}, not to ${app_id}. Run the command with --app ${domain.app_id}, or move it with "faable deploy domains attach ${domain.fqdn} --app ${app_id}".`);
27
+ }
28
+ return domain;
29
+ };
30
+ // What `attach` does with the domain it found.
31
+ const attach_plan = (domain, app_id) => domain.app_id === app_id
32
+ ? { kind: 'already', domain }
33
+ : { kind: 'link', domain, from: domain.app_id ?? null };
34
+ // `domains add` on a hostname the project already has: say which command fixes
35
+ // it. The api says so too from `domain_unlinked` on; this also covers an older
36
+ // api, which answers the same anonymous `domain_taken` to everyone.
37
+ const add_conflict_hint = async (api, team, fqdn, app_id, err) => {
38
+ const code = err?.code;
39
+ if (code !== 'domain_taken' && code !== 'domain_unlinked')
40
+ return undefined;
41
+ const domain = await find_project_domain(api, team, fqdn).catch(() => undefined);
42
+ if (!domain)
43
+ return undefined;
44
+ if (domain.app_id === app_id) {
45
+ return new CliError('domain_taken', `Domain ${domain.fqdn} is already attached to ${app_id}. See it with "faable deploy domains check ${domain.fqdn} --app ${app_id}".`, { status: 409, cause: err });
46
+ }
47
+ return domain.app_id
48
+ ? new CliError('domain_taken', `Domain ${domain.fqdn} is already in this project, attached to ${domain.app_id}. Move it with: faable deploy domains attach ${domain.fqdn} --app ${app_id}`, { status: 409, cause: err })
49
+ : new CliError('domain_unlinked', `Domain ${domain.fqdn} is already in this project, linked to no app. Link it — its CNAME and certificate stay valid — with: faable deploy domains attach ${domain.fqdn} --app ${app_id}`, { status: 409, cause: err });
50
+ };
51
+ /**
52
+ * Where a domain command acts: the project of the app (`--app`, or the one the
53
+ * directory is linked to), else the active project (`--project`). `explicit`
54
+ * is the app the user NAMED — only that one restricts which domain matches; an
55
+ * app inferred from the directory just says which project.
56
+ */
57
+ const domain_scope = async (api, app_ref, ctx_app_id) => {
58
+ const app_id = await find_app_id(app_ref, ctx_app_id, api);
59
+ if (app_id) {
60
+ const app = await api.getApp(app_id);
61
+ return { team: app.team, app, explicit: app_ref ? app_id : null };
62
+ }
63
+ const { id } = await requireProject(api);
64
+ return { team: id, app: null, explicit: null };
65
+ };
66
+
67
+ export { add_conflict_hint, attach_plan, domain_scope, find_project_domain, locate_domain, not_in_project, project_domains };
@@ -1,13 +1,12 @@
1
1
  import { requireApi } from '../../../api/context.js';
2
+ import { confirm } from '../../../lib/interactive.js';
2
3
  import { print_json, json_option } from '../../../lib/listing.js';
3
4
  import { log } from '../../../log.js';
4
- import { resolve_app_id } from '../resolve_app_id.js';
5
- import { find_by_fqdn } from './format.js';
6
- import { confirm } from '../../../lib/interactive.js';
5
+ import { domain_scope, locate_domain } from './locate.js';
7
6
 
8
7
  const domains_rm = {
9
8
  command: 'rm <fqdn>',
10
- describe: 'Remove a custom domain from the app',
9
+ describe: 'Remove a custom domain (from its app, or one linked to no app)',
11
10
  builder: yargs => json_option(yargs)
12
11
  .positional('fqdn', {
13
12
  type: 'string',
@@ -17,7 +16,7 @@ const domains_rm = {
17
16
  .option('app', {
18
17
  alias: 'a',
19
18
  type: 'string',
20
- description: 'App id, name or slug (defaults to the linked app)'
19
+ description: 'App id, name or slug. Optional: the domain is looked up in the project'
21
20
  })
22
21
  .option('yes', {
23
22
  alias: 'y',
@@ -26,30 +25,33 @@ const domains_rm = {
26
25
  description: 'Skip the confirmation prompt'
27
26
  })
28
27
  .example('$0 deploy domains rm www.example.com', 'Detach after confirmation')
28
+ .example('$0 deploy domains rm app.example.com -p my-project -y', 'A domain linked to no app (its app was deleted). To keep it, link it instead: domains attach')
29
29
  .showHelpOnFail(false),
30
30
  handler: async (args) => {
31
31
  const ctx = await requireApi();
32
- const app_id = await resolve_app_id(args.app, ctx.appId, ctx.api);
33
- const app = await ctx.api.getApp(app_id);
34
- const domains = await ctx.api.listDomains(app_id, app.team);
35
- const domain = find_by_fqdn(domains, args.fqdn);
36
- if (!domain) {
37
- throw new Error(`Domain ${args.fqdn} is not attached to ${app_id}. List them with "faable deploy domains list".`);
38
- }
32
+ const scope = await domain_scope(ctx.api, args.app, ctx.appId);
33
+ const domain = await locate_domain(ctx.api, scope.team, args.fqdn, scope.explicit);
34
+ const serves = domain.app_id
35
+ ? scope.app?.id === domain.app_id
36
+ ? `${scope.app.name} (${domain.app_id})`
37
+ : domain.app_id
38
+ : null;
39
39
  const go = await confirm({
40
- message: `Remove domain "${domain.fqdn}" from ${app.name} (${app_id})? Traffic to it will stop being served.`,
40
+ message: serves
41
+ ? `Remove domain "${domain.fqdn}" from ${serves}? Traffic to it will stop being served.`
42
+ : `Remove domain "${domain.fqdn}"? It is linked to no app. To serve it again with the same CNAME and certificate, use "faable deploy domains attach" instead.`,
41
43
  yes: args.yes
42
44
  });
43
45
  if (!go) {
44
46
  log.info('Cancelled.');
45
47
  return;
46
48
  }
47
- await ctx.api.deleteDomain(domain.id, app.team);
49
+ await ctx.api.deleteDomain(domain.id, scope.team);
48
50
  if (args.json) {
49
51
  return print_json({ deleted: true, id: domain.id, fqdn: domain.fqdn });
50
52
  }
51
- log.info(`🗑️ Removed domain ${domain.fqdn} from ${app_id}.`);
52
- log.info(`The app stays live at https://${app.url}. Remember to delete the CNAME at your DNS provider.`);
53
+ log.info(`🗑️ Removed domain ${domain.fqdn}${serves ? ` from ${serves}` : ''}.`);
54
+ log.info(`Remember to delete the CNAME at your DNS provider.`);
53
55
  }
54
56
  };
55
57
 
package/dist/mcp/tools.js CHANGED
@@ -13,6 +13,11 @@ const cursor = z
13
13
  .describe('next_cursor from the previous page, to continue a listing');
14
14
  const scope = (a) => (a.project ? ['--project', a.project] : []);
15
15
  const target = (a) => ['--app', a.app, ...scope(a)];
16
+ // Domains are the project's: a tool that finds one needs no app.
17
+ const optional_app = app
18
+ .optional()
19
+ .describe('App id (app_…), name or slug. Optional: without it, the whole project');
20
+ const app_or_project = (a) => (a.app ? target(a) : scope(a));
16
21
  const opt = (flag, value) => value === undefined || value === null || value === ''
17
22
  ? []
18
23
  : [flag, String(value)];
@@ -68,12 +73,8 @@ const tenant = z
68
73
  .optional()
69
74
  .describe("Auth tenant id (account_…). Defaults to the project's tenant (list_auth_tenants when it has several).");
70
75
  const auth_scope = (a) => [...opt('--account', a.tenant), ...scope(a)];
71
- const user_ref = z
72
- .string()
73
- .describe('User id (user_…) or exact email');
74
- const time = z
75
- .string()
76
- .regex(/^(\d+[mhd]|\d{4}-\d{2}-\d{2}|\d{10,})$/);
76
+ const user_ref = z.string().describe('User id (user_…) or exact email');
77
+ const time = z.string().regex(/^(\d+[mhd]|\d{4}-\d{2}-\d{2}|\d{10,})$/);
77
78
  const limit_flag = (a, d = 50) => ['--limit', String(a.limit ?? d)];
78
79
  const limit = z
79
80
  .number()
@@ -174,7 +175,7 @@ const api_detail = (a) => ({
174
175
  permissions: (a.permissions ?? []).map((p) => p.value)
175
176
  });
176
177
  // Which product a tool works on — /tools.json and the landing group by it.
177
- const product_of = (tool) => tool.command[0] === 'auth' ? 'auth' : 'deploy';
178
+ const product_of = (tool) => (tool.command[0] === 'auth' ? 'auth' : 'deploy');
178
179
  const AUTH_WRITE = {
179
180
  readOnlyHint: false,
180
181
  destructiveHint: false,
@@ -419,13 +420,14 @@ const TOOLS = [
419
420
  {
420
421
  name: 'list_domains',
421
422
  title: 'List custom domains',
422
- description: 'Custom domains of an app and whether their DNS is verified.',
423
- input: { app, project },
423
+ description: 'Custom domains of an app and whether their DNS is verified. Without `app`, every domain of the project with the app it serves: `app_id: null` is a domain linked to no app (its app was deleted), which answers DOMAIN_NOT_LINKED until attach_domain links it.',
424
+ input: { app: optional_app, project },
424
425
  command: ['deploy', 'domains', 'list'],
425
- flags: target,
426
+ flags: app_or_project,
426
427
  shape: page((d) => ({
427
428
  id: d.id,
428
429
  fqdn: d.fqdn,
430
+ app_id: d.app_id ?? null,
429
431
  verified: d.verified,
430
432
  tls: d.tls,
431
433
  dns_message: d.status?.dns_message
@@ -438,14 +440,15 @@ const TOOLS = [
438
440
  title: 'Check a domain',
439
441
  description: 'DNS diagnostic of one custom domain: the CNAME it expects, what DNS answers today, and why it is not verified yet. `prevalidation_cname.ready` says whether the optional `_acme-challenge` record is in place, so the certificate is issued without waiting for the CNAME; `status.tls_state` is `ok` once the edge serves a valid certificate for the domain (`status.tls_expires_at`).',
440
442
  input: {
441
- app,
443
+ app: optional_app,
442
444
  project,
443
445
  fqdn: z.string().describe('The domain, e.g. www.example.com')
444
446
  },
445
447
  command: ['deploy', 'domains', 'check'],
446
- flags: a => [a.fqdn, ...target(a)],
448
+ flags: a => [a.fqdn, ...app_or_project(a)],
447
449
  shape: (d) => ({
448
450
  fqdn: d.fqdn,
451
+ app_id: d.app_id ?? null,
449
452
  verified: d.verified,
450
453
  expected_cname: d.expected_cname,
451
454
  observed: d.status?.dns_observed ?? [],
@@ -474,7 +477,7 @@ const TOOLS = [
474
477
  {
475
478
  name: 'list_auth_tenants',
476
479
  title: 'List Auth tenants',
477
- description: "The Faable Auth tenants (user directories) of a project. Most projects have one and every Auth tool uses it; with several, pass the right one as `tenant`.",
480
+ description: 'The Faable Auth tenants (user directories) of a project. Most projects have one and every Auth tool uses it; with several, pass the right one as `tenant`.',
478
481
  input: { project },
479
482
  command: ['auth', 'accounts', 'list'],
480
483
  flags: scope,
@@ -532,7 +535,9 @@ const TOOLS = [
532
535
  last_login_since: time
533
536
  .optional()
534
537
  .describe('Logged in at or after: 24h, 7d, a date'),
535
- created_since: time.optional().describe('Signed up at or after: 24h, 7d, a date'),
538
+ created_since: time
539
+ .optional()
540
+ .describe('Signed up at or after: 24h, 7d, a date'),
536
541
  created_until: time.optional().describe('Signed up at or before'),
537
542
  suspended: z.boolean().optional(),
538
543
  tenant,
@@ -544,7 +549,9 @@ const TOOLS = [
544
549
  ...opt('--last-login-since', a.last_login_since),
545
550
  ...opt('--created-since', a.created_since),
546
551
  ...opt('--created-until', a.created_until),
547
- ...(a.suspended === undefined ? [] : [a.suspended ? '--suspended' : '--no-suspended']),
552
+ ...(a.suspended === undefined
553
+ ? []
554
+ : [a.suspended ? '--suspended' : '--no-suspended']),
548
555
  ...auth_scope(a)
549
556
  ],
550
557
  annotations: AUTH_READ,
@@ -553,15 +560,23 @@ const TOOLS = [
553
560
  {
554
561
  name: 'list_auth_users',
555
562
  title: 'List users',
556
- description: "Users of the Auth tenant. Find one by email or text, list the suspended ones, or sort: `-last_login` (most recent login first), `last_login` (longest without logging in), `-logins_count` (most active), `-createdAt` (newest sign-ups, the default). Sorting by last_login leaves out users who never logged in.",
563
+ description: 'Users of the Auth tenant. Find one by email or text, list the suspended ones, or sort: `-last_login` (most recent login first), `last_login` (longest without logging in), `-logins_count` (most active), `-createdAt` (newest sign-ups, the default). Sorting by last_login leaves out users who never logged in.',
557
564
  input: {
558
565
  search: z.string().optional().describe('Text in name, email or phone'),
559
566
  email: z.string().optional().describe('Exact email'),
560
567
  suspended: z.boolean().optional(),
561
568
  sort: z
562
- .enum(['-last_login', 'last_login', '-logins_count', '-createdAt', 'createdAt'])
569
+ .enum([
570
+ '-last_login',
571
+ 'last_login',
572
+ '-logins_count',
573
+ '-createdAt',
574
+ 'createdAt'
575
+ ])
563
576
  .optional(),
564
- last_login_since: time.optional().describe('Logged in at or after: 24h, 7d, a date'),
577
+ last_login_since: time
578
+ .optional()
579
+ .describe('Logged in at or after: 24h, 7d, a date'),
565
580
  created_since: time.optional().describe('Signed up at or after'),
566
581
  limit,
567
582
  cursor,
@@ -572,7 +587,9 @@ const TOOLS = [
572
587
  flags: a => [
573
588
  ...opt('-q', a.search),
574
589
  ...opt('--email', a.email),
575
- ...(a.suspended === undefined ? [] : [a.suspended ? '--suspended' : '--no-suspended']),
590
+ ...(a.suspended === undefined
591
+ ? []
592
+ : [a.suspended ? '--suspended' : '--no-suspended']),
576
593
  // `--sort=-x`: as two words yargs would read `-last_login` as flags.
577
594
  ...(a.sort ? [`--sort=${a.sort}`] : []),
578
595
  ...opt('--last-login-since', a.last_login_since),
@@ -642,9 +659,15 @@ const TOOLS = [
642
659
  title: 'Read the Auth audit log',
643
660
  description: "The Auth tenant's audit log, newest first: logins, failed logins (`status: failed`), sign-ups, password resets, admin changes (`type` prefix `admin.user`). Filter by user to answer 'why can't X log in?' — the failed attempts say why. On a failed login no user resolves, so each row also carries `attempted_identifier`: the email/username the person actually typed (diagnose_auth_login turns that into the account they should be using).",
644
661
  input: {
645
- email: z.string().optional().describe("Only this user's events (exact email)"),
662
+ email: z
663
+ .string()
664
+ .optional()
665
+ .describe("Only this user's events (exact email)"),
646
666
  user: z.string().optional().describe('Only this user id (user_…)'),
647
- type: z.string().optional().describe('Exact event type, e.g. user.login, user.signup'),
667
+ type: z
668
+ .string()
669
+ .optional()
670
+ .describe('Exact event type, e.g. user.login, user.signup'),
648
671
  origin: z.string().optional().describe('Type prefix, e.g. oauth, admin'),
649
672
  status: z.enum(['success', 'failed', 'skipped', 'info']).optional(),
650
673
  since: time.optional().describe('30m, 24h, 7d or a date (default 7d)'),
@@ -706,7 +729,10 @@ const TOOLS = [
706
729
  description: 'The devices a user is signed in on (one row per login session): IP, device, last activity and whether it is still active.',
707
730
  input: {
708
731
  user: user_ref,
709
- active: z.boolean().optional().describe('Only active sessions (default true)'),
732
+ active: z
733
+ .boolean()
734
+ .optional()
735
+ .describe('Only active sessions (default true)'),
710
736
  tenant,
711
737
  project
712
738
  },
@@ -784,7 +810,10 @@ const TOOLS = [
784
810
  .describe('Wait until live or failed, up to 5 minutes (default false)')
785
811
  },
786
812
  command: ['deploy', 'trigger'],
787
- flags: a => [...target(a), ...(a.wait ? ['--wait', '--timeout', '300'] : [])],
813
+ flags: a => [
814
+ ...target(a),
815
+ ...(a.wait ? ['--wait', '--timeout', '300'] : [])
816
+ ],
788
817
  timeout_ms: 330_000,
789
818
  annotations: {
790
819
  readOnlyHint: false,
@@ -980,10 +1009,18 @@ const TOOLS = [
980
1009
  {
981
1010
  name: 'add_domain',
982
1011
  title: 'Add a custom domain',
983
- description: "Attach a custom domain to an app. Returns the CNAME record the user must create at their DNS provider; Faable verifies it and issues the certificate on its own. If the domain already serves traffic somewhere else, tell the user to create `prevalidation_cname` (`_acme-challenge.<fqdn>` CNAME) FIRST and switch the main CNAME only once check_domain shows it ready: the certificate then exists before traffic moves, with no TLS gap.",
984
- input: { app, project, fqdn: z.string().describe('e.g. www.example.com') },
1012
+ description: 'Attach a custom domain to an app. Returns the CNAME record the user must create at their DNS provider; Faable verifies it and issues the certificate on its own. If the domain already serves traffic somewhere else, tell the user to create `prevalidation_cname` (`_acme-challenge.<fqdn>` CNAME) FIRST and switch the main CNAME only once check_domain shows it ready: the certificate then exists before traffic moves, with no TLS gap. If it says the domain is already in this project, use attach_domain instead: adding it again cannot work.',
1013
+ input: {
1014
+ app,
1015
+ project,
1016
+ fqdn: z.string().describe('e.g. www.example.com'),
1017
+ www: z
1018
+ .boolean()
1019
+ .optional()
1020
+ .describe('Also add the www (or root) counterpart, redirecting to this domain: example.com and www.example.com. Only for a root domain or its www. Both need their DNS record.')
1021
+ },
985
1022
  command: ['deploy', 'domains', 'add'],
986
- flags: a => [a.fqdn, ...target(a)],
1023
+ flags: a => [a.fqdn, ...(a.www ? ['--www'] : []), ...target(a)],
987
1024
  write: true,
988
1025
  annotations: {
989
1026
  readOnlyHint: false,
@@ -992,6 +1029,24 @@ const TOOLS = [
992
1029
  },
993
1030
  example: { app: 'web', fqdn: 'www.example.com' }
994
1031
  },
1032
+ {
1033
+ name: 'attach_domain',
1034
+ title: 'Link a domain to an app',
1035
+ description: "Link a custom domain of the project to an app: one left linked to no app (deleting an app leaves its domains in the project, answering DOMAIN_NOT_LINKED), or one moving from another of the project's apps. It keeps its id, its CNAME target and its certificate: nothing changes at the DNS provider. Use it instead of add_domain when add_domain says the domain is already in this project.",
1036
+ input: { app, project, fqdn: z.string().describe('e.g. app.example.com') },
1037
+ command: ['deploy', 'domains', 'attach'],
1038
+ // --yes: the model was asked to move it; the CLI prompt has no one to ask.
1039
+ flags: a => [a.fqdn, '--yes', ...target(a)],
1040
+ write: true,
1041
+ shape: (d) => ({ id: d.id, fqdn: d.fqdn, app_id: d.app_id ?? null }),
1042
+ annotations: {
1043
+ readOnlyHint: false,
1044
+ destructiveHint: false,
1045
+ idempotentHint: true,
1046
+ openWorldHint: true
1047
+ },
1048
+ example: { app: 'web', fqdn: 'app.example.com' }
1049
+ },
995
1050
  {
996
1051
  name: 'configure_repo',
997
1052
  title: 'Configure how an app deploys',
@@ -1027,7 +1082,7 @@ const TOOLS = [
1027
1082
  {
1028
1083
  name: 'link_repo',
1029
1084
  title: 'Link a repository to an app',
1030
- description: "Link a GitHub repository to an app that already exists, so a push deploys it (for a new app, create_app does both). What is live keeps serving until the next push — linking starts no deploy. Needs the Faable GitHub App installed on the repository; if not, the error says what to fix.",
1085
+ description: 'Link a GitHub repository to an app that already exists, so a push deploys it (for a new app, create_app does both). What is live keeps serving until the next push — linking starts no deploy. Needs the Faable GitHub App installed on the repository; if not, the error says what to fix.',
1031
1086
  input: {
1032
1087
  app,
1033
1088
  repo: z.string().describe('GitHub repository, owner/repo'),
@@ -1038,12 +1093,7 @@ const TOOLS = [
1038
1093
  project
1039
1094
  },
1040
1095
  command: ['deploy', 'link'],
1041
- flags: a => [
1042
- '--repo',
1043
- a.repo,
1044
- ...opt('--branch', a.branch),
1045
- ...target(a)
1046
- ],
1096
+ flags: a => ['--repo', a.repo, ...opt('--branch', a.branch), ...target(a)],
1047
1097
  write: true,
1048
1098
  annotations: {
1049
1099
  readOnlyHint: false,
@@ -1271,7 +1321,7 @@ const TOOLS = [
1271
1321
  {
1272
1322
  name: 'suspend_auth_user',
1273
1323
  title: 'Suspend a user',
1274
- description: "Suspend one user of the Auth tenant: they can no longer log in, and their sessions and refresh tokens stop working (access tokens already issued live until they expire). Reversible with reinstate_auth_user. Confirm with get_auth_user that it is the right person first, and say why in `reason` — it is recorded on the user.",
1324
+ description: 'Suspend one user of the Auth tenant: they can no longer log in, and their sessions and refresh tokens stop working (access tokens already issued live until they expire). Reversible with reinstate_auth_user. Confirm with get_auth_user that it is the right person first, and say why in `reason` — it is recorded on the user.',
1275
1325
  input: {
1276
1326
  user: user_ref,
1277
1327
  reason: z.string().max(512).describe('Why — recorded on the user'),
@@ -1355,7 +1405,7 @@ const TOOLS = [
1355
1405
  },
1356
1406
  {
1357
1407
  name: 'update_auth_client_login',
1358
- title: "Change how users sign in to an app",
1408
+ title: 'Change how users sign in to an app',
1359
1409
  description: "Choose which login methods one Auth application offers: which connections (by id or name, as list_auth_connections shows them) and whether the passkey button appears. `only` keeps exactly those connections and removes the rest; `disable`/`enable` change one at a time. A removed connection is refused at /authorize too, not just hidden. `passkey` needs the Pro plan. `inherit: true` drops the app's own settings and follows the tenant's again. Settings not mentioned keep their current value.",
1360
1410
  input: {
1361
1411
  client: z
@@ -1422,7 +1472,12 @@ const TOOLS = [
1422
1472
  project
1423
1473
  },
1424
1474
  command: ['auth', 'users', 'password-setup'],
1425
- flags: a => [a.user, ...opt('--channel', a.channel), '--yes', ...auth_scope(a)],
1475
+ flags: a => [
1476
+ a.user,
1477
+ ...opt('--channel', a.channel),
1478
+ '--yes',
1479
+ ...auth_scope(a)
1480
+ ],
1426
1481
  write: true,
1427
1482
  annotations: { ...AUTH_WRITE, idempotentHint: false },
1428
1483
  example: { user: 'ana@example.com', channel: 'email' }
@@ -1433,9 +1488,15 @@ const TOOLS = [
1433
1488
  description: "Change a user's profile: `email`, `name`, `email_verified`. Changing `email` also moves their database login identifier (the email they type at the password login) so sign-in keeps working — pass `profile_only: true` to change only the profile email and leave the login identifier. Use this when someone cannot log in because the address they were given is not the one on their account. Confirm the person first with get_auth_user.",
1434
1489
  input: {
1435
1490
  user: user_ref,
1436
- email: z.string().optional().describe('New email — also the database login identifier unless profile_only'),
1491
+ email: z
1492
+ .string()
1493
+ .optional()
1494
+ .describe('New email — also the database login identifier unless profile_only'),
1437
1495
  name: z.string().optional(),
1438
- email_verified: z.boolean().optional().describe('Mark the email verified (true) or clear verification (false)'),
1496
+ email_verified: z
1497
+ .boolean()
1498
+ .optional()
1499
+ .describe('Mark the email verified (true) or clear verification (false)'),
1439
1500
  profile_only: z
1440
1501
  .boolean()
1441
1502
  .optional()
@@ -1474,7 +1535,10 @@ const TOOLS = [
1474
1535
  .string()
1475
1536
  .optional()
1476
1537
  .describe('The exact new password. Omit and set generate:true to have one made.'),
1477
- generate: z.boolean().optional().describe('Generate a strong password and return it once'),
1538
+ generate: z
1539
+ .boolean()
1540
+ .optional()
1541
+ .describe('Generate a strong password and return it once'),
1478
1542
  connection: z
1479
1543
  .string()
1480
1544
  .optional()
@@ -1500,7 +1564,7 @@ const TOOLS = [
1500
1564
  {
1501
1565
  name: 'get_auth_recovery_link',
1502
1566
  title: 'Get a password-reset link',
1503
- description: "Mint a fresh password-reset link for a user and return it, so you can hand it over by another channel when the reset email will not reach them (e.g. the address on the account is not a real inbox). This ALSO sends the standard reset email. The link lets whoever holds it set the password, so treat it like a password; it works once, until used or expired. Returns `link` (email channel only), `ticket_id` and `channel`.",
1567
+ description: 'Mint a fresh password-reset link for a user and return it, so you can hand it over by another channel when the reset email will not reach them (e.g. the address on the account is not a real inbox). This ALSO sends the standard reset email. The link lets whoever holds it set the password, so treat it like a password; it works once, until used or expired. Returns `link` (email channel only), `ticket_id` and `channel`.',
1504
1568
  input: { user: user_ref, tenant, project },
1505
1569
  command: ['auth', 'users', 'password-setup'],
1506
1570
  flags: a => [a.user, '--print', '--yes', ...auth_scope(a)],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faable/faable",
3
- "version": "4.35.0",
3
+ "version": "4.37.0",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "author": "Marc Pomar <marc@faable.com>",