@faable/faable 4.34.1 → 4.36.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,12 +2,13 @@ import { withAuthHints, requireAuthAdmin } from '../../../api/auth_admin.js';
2
2
  import { log } from '../../../log.js';
3
3
  import { tenant_options } from '../options.js';
4
4
  import { yes_no } from '../render.js';
5
+ import { api_setting_options, api_settings_patch } from './settings.js';
5
6
  import { json_option, print_json } from '../../../lib/listing.js';
6
7
 
7
8
  const apis_create = {
8
9
  command: 'create <identifier>',
9
10
  describe: 'Create an API (the audience tokens are issued for)',
10
- builder: yargs => json_option(tenant_options(yargs))
11
+ builder: yargs => api_setting_options(json_option(tenant_options(yargs)))
11
12
  .positional('identifier', {
12
13
  type: 'string',
13
14
  demandOption: true,
@@ -26,18 +27,22 @@ const apis_create = {
26
27
  description: 'Turn on RBAC (and the access_token_authz dialect, which carries `permissions`)'
27
28
  })
28
29
  .example('$0 auth apis create https://api.example.com --permission tickets:read --permission tickets:write --rbac', 'An API whose user tokens carry the permissions their roles grant')
30
+ .example('$0 auth apis create https://api.example.com --token-lifetime 3600 --include-roles-in-access-token', 'Access tokens that last one hour and carry the `roles` claim')
29
31
  .showHelpOnFail(false),
30
32
  handler: withAuthHints(async (args) => {
33
+ // Before the login: a bad value fails without touching the network.
34
+ const settings = api_settings_patch(args);
31
35
  const api = await requireAuthAdmin(args);
32
36
  const a = (await api.apiCreate({
33
37
  name: args.name ?? args.identifier,
34
38
  identifier: args.identifier,
35
39
  permissions: (args.permission ?? []).map(value => ({ value })),
36
- ...(args.rbac ? { rbac: true, token_dialect: 'access_token_authz' } : {})
40
+ ...(args.rbac ? { rbac: true, token_dialect: 'access_token_authz' } : {}),
41
+ ...settings
37
42
  }));
38
43
  if (args.json)
39
44
  return print_json(a);
40
- log.info(`✅ Created API ${a.name} (${a.id}) — ${a.identifier}, ${a.permissions?.length ?? 0} permission(s), RBAC ${yes_no(a.rbac)}.`);
45
+ log.info(`✅ Created API ${a.name} (${a.id}) — ${a.identifier}, ${a.permissions?.length ?? 0} permission(s), RBAC ${yes_no(a.rbac)}, tokens last ${a.token_lifetime} s.`);
41
46
  })
42
47
  };
43
48
 
@@ -24,7 +24,12 @@ const apis_get = {
24
24
  log.info(` Identifier: ${a.identifier}`);
25
25
  log.info(` Token dialect: ${a.token_dialect ?? '-'}`);
26
26
  log.info(` RBAC: ${yes_no(a.rbac)}`);
27
+ log.info(` Token lifetime: ${a.token_lifetime ?? '-'} s`);
27
28
  log.info(` Enforce policies: ${yes_no(a.enforce_policies)}`);
29
+ log.info(` Offline access: ${yes_no(a.allow_offline_access)}`);
30
+ log.info(` Skip consent: ${yes_no(a.skip_consent)}`);
31
+ log.info(` Roles claim: access token ${yes_no(a.include_roles_in_access_token)}, id_token ${yes_no(a.include_roles_in_id_token)}`);
32
+ log.info(` Teams claim: access token ${yes_no(a.include_teams_in_access_token)}, id_token ${yes_no(a.include_teams_in_id_token)}`);
28
33
  log.info(` Permissions (${a.permissions?.length ?? 0}):`);
29
34
  for (const p of a.permissions ?? []) {
30
35
  log.info(` ${p.value}${p.description ? ` — ${p.description}` : ''}`);
@@ -0,0 +1,62 @@
1
+ import { CliError } from '../../../lib/errors.js';
2
+
3
+ // The range the Auth API accepts (auth ApiCreate / ApiUpdate schemas).
4
+ const TOKEN_LIFETIME_MIN = 60;
5
+ const TOKEN_LIFETIME_MAX = 60 * 60 * 24 * 30;
6
+ // Every boolean setting `apis get --json` shows, flag = the field in kebab case.
7
+ const API_BOOLEAN_SETTINGS = {
8
+ allow_offline_access: 'Clients may request `offline_access` and get a refresh_token for this API',
9
+ skip_consent: 'Skip the consent screen for first-party clients',
10
+ include_roles_in_access_token: "Access tokens carry a `roles` claim with the user's role names",
11
+ include_teams_in_access_token: "Access tokens carry a `teams` claim with the user's team slugs",
12
+ include_roles_in_id_token: 'id_tokens issued with an access token for this API carry `roles`',
13
+ include_teams_in_id_token: 'id_tokens issued with an access token for this API carry `teams`',
14
+ enforce_policies: 'Filter the requested scopes against the permission catalog at issuance'
15
+ };
16
+ const camel = (field) => field.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
17
+ const kebab = (field) => field.replace(/_/g, '-');
18
+ const api_setting_options = (yargs) => {
19
+ let y = yargs
20
+ .option('token-lifetime', {
21
+ // A string, so "3600.5" or "1h" are refused instead of rounded or NaN.
22
+ type: 'string',
23
+ description: `Access token lifetime in seconds, ${TOKEN_LIFETIME_MIN}–${TOKEN_LIFETIME_MAX} (30 days); a new API gets 86400`
24
+ })
25
+ .option('description', {
26
+ type: 'string',
27
+ description: 'Description of the API'
28
+ });
29
+ for (const [field, description] of Object.entries(API_BOOLEAN_SETTINGS)) {
30
+ y = y.option(kebab(field), {
31
+ type: 'boolean',
32
+ description
33
+ });
34
+ }
35
+ return y;
36
+ };
37
+ const parse_token_lifetime = (raw) => {
38
+ const n = /^\d+$/.test(raw.trim()) ? Number(raw.trim()) : NaN;
39
+ if (!Number.isSafeInteger(n) ||
40
+ n < TOKEN_LIFETIME_MIN ||
41
+ n > TOKEN_LIFETIME_MAX) {
42
+ throw new CliError('usage', `--token-lifetime must be a whole number of seconds between ${TOKEN_LIFETIME_MIN} and ${TOKEN_LIFETIME_MAX} (30 days), got "${raw}".`);
43
+ }
44
+ return n;
45
+ };
46
+ // The fields of the body the flags ask for — only those passed.
47
+ const api_settings_patch = (args) => {
48
+ const patch = {};
49
+ if (args.tokenLifetime !== undefined) {
50
+ patch.token_lifetime = parse_token_lifetime(String(args.tokenLifetime));
51
+ }
52
+ if (args.description !== undefined)
53
+ patch.description = args.description;
54
+ for (const field of Object.keys(API_BOOLEAN_SETTINGS)) {
55
+ const value = args[camel(field)];
56
+ if (typeof value === 'boolean')
57
+ patch[field] = value;
58
+ }
59
+ return patch;
60
+ };
61
+
62
+ export { API_BOOLEAN_SETTINGS, TOKEN_LIFETIME_MAX, TOKEN_LIFETIME_MIN, api_setting_options, api_settings_patch, parse_token_lifetime };
@@ -4,12 +4,13 @@ import { log } from '../../../log.js';
4
4
  import { tenant_options } from '../options.js';
5
5
  import { yes_no } from '../render.js';
6
6
  import { resolve_api_ref } from '../roles/shared.js';
7
+ import { api_setting_options, api_settings_patch } from './settings.js';
7
8
  import { json_option, print_json } from '../../../lib/listing.js';
8
9
 
9
10
  const apis_update = {
10
11
  command: 'update <api>',
11
- describe: "Change an API's RBAC, token dialect and permission catalog",
12
- builder: yargs => json_option(tenant_options(yargs))
12
+ describe: "Change an API's token settings and permission catalog (its identifier cannot change)",
13
+ builder: yargs => api_setting_options(json_option(tenant_options(yargs)))
13
14
  .positional('api', {
14
15
  type: 'string',
15
16
  demandOption: true,
@@ -35,16 +36,19 @@ const apis_update = {
35
36
  description: 'Remove a permission from the catalog — repeatable. Roles that grant it stop granting it'
36
37
  })
37
38
  .example('$0 auth apis update https://api.example.com --rbac --token-dialect access_token_authz', 'Turn on RBAC for an API')
39
+ .example('$0 auth apis update https://api.example.com --token-lifetime 3600', 'Access tokens issued from now on last one hour')
40
+ .epilog('Turn a yes/no setting off with --no-<flag>, e.g. --no-skip-consent. Changes apply to tokens issued from now on; tokens already issued keep theirs until they expire. The identifier (audience) cannot be changed: create a new API.')
38
41
  .showHelpOnFail(false),
39
42
  handler: withAuthHints(async (args) => {
40
43
  const add = args.addPermission ?? [];
41
44
  const rm = new Set(args.rmPermission ?? []);
42
45
  const patch = {
43
46
  ...(args.rbac !== undefined ? { rbac: args.rbac } : {}),
44
- ...(args.tokenDialect ? { token_dialect: args.tokenDialect } : {})
47
+ ...(args.tokenDialect ? { token_dialect: args.tokenDialect } : {}),
48
+ ...api_settings_patch(args)
45
49
  };
46
50
  if (Object.keys(patch).length === 0 && !add.length && !rm.size) {
47
- throw new CliError('usage', 'Nothing to update — pass --rbac / --no-rbac, --token-dialect, --add-permission or --rm-permission.');
51
+ throw new CliError('usage', 'Nothing to update — pass a setting (--token-lifetime, --rbac, --token-dialect, --include-roles-in-access-token…), --add-permission or --rm-permission. See --help.');
48
52
  }
49
53
  const admin = await requireAuthAdmin(args);
50
54
  const target = await resolve_api_ref(admin, args.api);
@@ -60,7 +64,7 @@ const apis_update = {
60
64
  const a = (await admin.apiUpdate(target.id, patch));
61
65
  if (args.json)
62
66
  return print_json(a);
63
- log.info(`✅ ${a.name}: RBAC ${yes_no(a.rbac)}, dialect ${a.token_dialect}. Applies to tokens issued from now on.`);
67
+ log.info(`✅ ${a.name}: RBAC ${yes_no(a.rbac)}, dialect ${a.token_dialect}, tokens last ${a.token_lifetime} s. Applies to tokens issued from now on.`);
64
68
  if (a.rbac && a.token_dialect !== 'access_token_authz') {
65
69
  log.warn('⚠️ RBAC is on but the dialect is not access_token_authz: tokens carry no `permissions` claim.');
66
70
  }
@@ -3,6 +3,7 @@ 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
5
  import { 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>',
@@ -29,10 +30,12 @@ const domains_add = {
29
30
  const ctx = await requireApi();
30
31
  const app_id = await resolve_app_id(args.app, ctx.appId, ctx.api);
31
32
  const app = await ctx.api.getApp(app_id);
32
- const domain = await ctx.api.createDomain(app.team, {
33
- fqdn: args.fqdn,
34
- app_id,
35
- tls: args.tls
33
+ const domain = await ctx.api
34
+ .createDomain(app.team, { fqdn: args.fqdn, app_id, tls: args.tls })
35
+ .catch(async (err) => {
36
+ // Already in this project (an app deletion leaves its domains linked
37
+ // to no app): name the command that fixes it, not "another project".
38
+ throw ((await add_conflict_hint(ctx.api, app.team, args.fqdn, app_id, err)) ?? err);
36
39
  });
37
40
  // Same shape as `domains check --json`: the record plus the CNAME to
38
41
  // create, which is the whole next step.
@@ -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(', ')}`);
@@ -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)];
@@ -99,6 +104,80 @@ const log_user = (l) => typeof l.user === 'string'
99
104
  ? { user_id: l.user.id, email: l.user.email, name: l.user.name }
100
105
  : {};
101
106
  const AUTH_READ = { ...READ };
107
+ // ── Auth APIs: the settings create_auth_api and update_auth_api take ────────
108
+ // Same names as the API fields; the CLI flag is the field in kebab case
109
+ // (src/commands/auth/apis/settings.ts).
110
+ const API_BOOLEANS = [
111
+ 'allow_offline_access',
112
+ 'skip_consent',
113
+ 'include_roles_in_access_token',
114
+ 'include_teams_in_access_token',
115
+ 'include_roles_in_id_token',
116
+ 'include_teams_in_id_token',
117
+ 'enforce_policies'
118
+ ];
119
+ const api_settings_input = {
120
+ token_lifetime: z
121
+ .number()
122
+ .int()
123
+ .min(60)
124
+ .max(60 * 60 * 24 * 30)
125
+ .optional()
126
+ .describe('Access token lifetime in seconds, 60–2592000 (30 days). A new API gets 86400'),
127
+ description: z.string().max(512).optional(),
128
+ rbac: z
129
+ .boolean()
130
+ .optional()
131
+ .describe('User tokens carry only the requested permissions their roles grant. On create it also sets the access_token_authz dialect'),
132
+ allow_offline_access: z
133
+ .boolean()
134
+ .optional()
135
+ .describe('Clients may request offline_access and get a refresh_token'),
136
+ skip_consent: z
137
+ .boolean()
138
+ .optional()
139
+ .describe('Skip the consent screen for first-party clients'),
140
+ include_roles_in_access_token: z
141
+ .boolean()
142
+ .optional()
143
+ .describe("Access tokens carry a `roles` claim with the user's role names"),
144
+ include_teams_in_access_token: z
145
+ .boolean()
146
+ .optional()
147
+ .describe("Access tokens carry a `teams` claim with the user's team slugs"),
148
+ include_roles_in_id_token: z
149
+ .boolean()
150
+ .optional()
151
+ .describe('id_tokens issued with an access token for this API carry `roles`'),
152
+ include_teams_in_id_token: z
153
+ .boolean()
154
+ .optional()
155
+ .describe('id_tokens issued with an access token for this API carry `teams`'),
156
+ enforce_policies: z
157
+ .boolean()
158
+ .optional()
159
+ .describe('Filter requested scopes against the permission catalog at issuance')
160
+ };
161
+ const api_settings_flags = (a) => [
162
+ ...opt('--token-lifetime', a.token_lifetime),
163
+ ...optText('--description', a.description),
164
+ ...(a.rbac === undefined ? [] : [a.rbac ? '--rbac' : '--no-rbac']),
165
+ ...API_BOOLEANS.flatMap(f => {
166
+ const flag = f.replace(/_/g, '-');
167
+ return a[f] === undefined ? [] : [a[f] ? `--${flag}` : `--no-${flag}`];
168
+ })
169
+ ];
170
+ const api_detail = (a) => ({
171
+ id: a.id,
172
+ name: a.name,
173
+ identifier: a.identifier,
174
+ description: a.description,
175
+ token_lifetime: a.token_lifetime,
176
+ token_dialect: a.token_dialect,
177
+ rbac: !!a.rbac,
178
+ ...Object.fromEntries(API_BOOLEANS.map(f => [f, !!a[f]])),
179
+ permissions: (a.permissions ?? []).map((p) => p.value)
180
+ });
102
181
  // Which product a tool works on — /tools.json and the landing group by it.
103
182
  const product_of = (tool) => tool.command[0] === 'auth' ? 'auth' : 'deploy';
104
183
  const AUTH_WRITE = {
@@ -345,13 +424,14 @@ const TOOLS = [
345
424
  {
346
425
  name: 'list_domains',
347
426
  title: 'List custom domains',
348
- description: 'Custom domains of an app and whether their DNS is verified.',
349
- input: { app, project },
427
+ 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.',
428
+ input: { app: optional_app, project },
350
429
  command: ['deploy', 'domains', 'list'],
351
- flags: target,
430
+ flags: app_or_project,
352
431
  shape: page((d) => ({
353
432
  id: d.id,
354
433
  fqdn: d.fqdn,
434
+ app_id: d.app_id ?? null,
355
435
  verified: d.verified,
356
436
  tls: d.tls,
357
437
  dns_message: d.status?.dns_message
@@ -364,14 +444,15 @@ const TOOLS = [
364
444
  title: 'Check a domain',
365
445
  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`).',
366
446
  input: {
367
- app,
447
+ app: optional_app,
368
448
  project,
369
449
  fqdn: z.string().describe('The domain, e.g. www.example.com')
370
450
  },
371
451
  command: ['deploy', 'domains', 'check'],
372
- flags: a => [a.fqdn, ...target(a)],
452
+ flags: a => [a.fqdn, ...app_or_project(a)],
373
453
  shape: (d) => ({
374
454
  fqdn: d.fqdn,
455
+ app_id: d.app_id ?? null,
375
456
  verified: d.verified,
376
457
  expected_cname: d.expected_cname,
377
458
  observed: d.status?.dns_observed ?? [],
@@ -906,7 +987,7 @@ const TOOLS = [
906
987
  {
907
988
  name: 'add_domain',
908
989
  title: 'Add a custom domain',
909
- 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.",
990
+ 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.",
910
991
  input: { app, project, fqdn: z.string().describe('e.g. www.example.com') },
911
992
  command: ['deploy', 'domains', 'add'],
912
993
  flags: a => [a.fqdn, ...target(a)],
@@ -918,6 +999,24 @@ const TOOLS = [
918
999
  },
919
1000
  example: { app: 'web', fqdn: 'www.example.com' }
920
1001
  },
1002
+ {
1003
+ name: 'attach_domain',
1004
+ title: 'Link a domain to an app',
1005
+ 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.",
1006
+ input: { app, project, fqdn: z.string().describe('e.g. app.example.com') },
1007
+ command: ['deploy', 'domains', 'attach'],
1008
+ // --yes: the model was asked to move it; the CLI prompt has no one to ask.
1009
+ flags: a => [a.fqdn, '--yes', ...target(a)],
1010
+ write: true,
1011
+ shape: (d) => ({ id: d.id, fqdn: d.fqdn, app_id: d.app_id ?? null }),
1012
+ annotations: {
1013
+ readOnlyHint: false,
1014
+ destructiveHint: false,
1015
+ idempotentHint: true,
1016
+ openWorldHint: true
1017
+ },
1018
+ example: { app: 'web', fqdn: 'app.example.com' }
1019
+ },
921
1020
  {
922
1021
  name: 'configure_repo',
923
1022
  title: 'Configure how an app deploys',
@@ -1096,6 +1195,72 @@ const TOOLS = [
1096
1195
  remove: ['tickets:admin']
1097
1196
  }
1098
1197
  },
1198
+ {
1199
+ name: 'create_auth_api',
1200
+ title: 'Create an API',
1201
+ description: 'Create an API (resource server) in the Auth tenant: the audience clients request tokens for. The identifier becomes the `aud` claim and cannot change later. Settings left out take the defaults (tokens last 86400 s, no roles or teams claims).',
1202
+ input: {
1203
+ identifier: z
1204
+ .string()
1205
+ .regex(/^[^-]/, 'cannot start with "-"')
1206
+ .describe('Audience URL, e.g. https://api.example.com (cannot change later)'),
1207
+ name: z
1208
+ .string()
1209
+ .max(120)
1210
+ .optional()
1211
+ .describe('Display name (defaults to the identifier)'),
1212
+ permissions: z
1213
+ .array(z.string())
1214
+ .optional()
1215
+ .describe('Its permission catalog, e.g. tickets:read'),
1216
+ ...api_settings_input,
1217
+ tenant,
1218
+ project
1219
+ },
1220
+ command: ['auth', 'apis', 'create'],
1221
+ flags: a => [
1222
+ a.identifier,
1223
+ ...optText('--name', a.name),
1224
+ ...(a.permissions ?? []).flatMap((p) => [`--permission=${p}`]),
1225
+ ...api_settings_flags(a),
1226
+ ...auth_scope(a)
1227
+ ],
1228
+ shape: api_detail,
1229
+ write: true,
1230
+ // API writes change what every token of the tenant carries: never on the
1231
+ // hosted server, whose token only reads APIs (api tenant_access.ts).
1232
+ local_only: true,
1233
+ annotations: { ...AUTH_WRITE, idempotentHint: false },
1234
+ example: {
1235
+ identifier: 'https://api.example.com',
1236
+ permissions: ['tickets:read'],
1237
+ token_lifetime: 3600,
1238
+ include_roles_in_access_token: true
1239
+ }
1240
+ },
1241
+ {
1242
+ name: 'update_auth_api',
1243
+ title: "Change an API's settings",
1244
+ description: "Change an API's token settings: token lifetime, RBAC, the roles and teams claims, offline access, consent, description. Only the settings passed change. Applies to tokens issued from now on; tokens already issued keep theirs until they expire. The identifier cannot change. The permission catalog is not edited here.",
1245
+ input: {
1246
+ api: z.string().describe('API id (api_…) or identifier (audience URL)'),
1247
+ ...api_settings_input,
1248
+ tenant,
1249
+ project
1250
+ },
1251
+ command: ['auth', 'apis', 'update'],
1252
+ flags: a => [a.api, ...api_settings_flags(a), ...auth_scope(a)],
1253
+ shape: api_detail,
1254
+ write: true,
1255
+ // See create_auth_api.
1256
+ local_only: true,
1257
+ annotations: AUTH_WRITE,
1258
+ example: {
1259
+ api: 'https://api.example.com',
1260
+ token_lifetime: 3600,
1261
+ include_teams_in_access_token: true
1262
+ }
1263
+ },
1099
1264
  {
1100
1265
  name: 'update_auth_user_roles',
1101
1266
  title: "Change a user's roles",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faable/faable",
3
- "version": "4.34.1",
3
+ "version": "4.36.0",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "author": "Marc Pomar <marc@faable.com>",