@faable/faable 4.36.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.
@@ -2,7 +2,7 @@ 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
6
  import { add_conflict_hint } from './locate.js';
7
7
 
8
8
  const domains_add = {
@@ -23,33 +23,62 @@ const domains_add = {
23
23
  type: 'boolean',
24
24
  default: true,
25
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'
26
30
  })
27
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')
28
33
  .showHelpOnFail(false),
29
34
  handler: async (args) => {
30
35
  const ctx = await requireApi();
31
36
  const app_id = await resolve_app_id(args.app, ctx.appId, ctx.api);
32
37
  const app = await ctx.api.getApp(app_id);
33
38
  const domain = await ctx.api
34
- .createDomain(app.team, { fqdn: args.fqdn, app_id, tls: args.tls })
39
+ .createDomain(app.team, {
40
+ fqdn: args.fqdn,
41
+ app_id,
42
+ tls: args.tls,
43
+ ...(args.www ? { www: true } : {})
44
+ })
35
45
  .catch(async (err) => {
36
46
  // Already in this project (an app deletion leaves its domains linked
37
47
  // to no app): name the command that fixes it, not "another project".
38
48
  throw ((await add_conflict_hint(ctx.api, app.team, args.fqdn, app_id, err)) ?? err);
39
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;
40
55
  // Same shape as `domains check --json`: the record plus the CNAME to
41
56
  // create, which is the whole next step.
42
57
  if (args.json) {
43
58
  return print_json({
44
59
  ...domain,
45
60
  expected_cname: cname_target(domain),
46
- ...(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
+ : {})
47
71
  });
48
72
  }
49
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
+ }
50
77
  log.info(``);
51
- 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:`);
52
79
  log.info(` ${domain.fqdn} → ${cname_target(domain)}`);
80
+ if (pair)
81
+ log.info(` ${pair.fqdn} → ${cname_target(pair)}`);
53
82
  log.info(``);
54
83
  log.info(`Faable verifies the record automatically once DNS propagates${args.tls ? ' and then provisions the TLS certificate' : ''}.`);
55
84
  if (args.tls) {
@@ -57,6 +86,10 @@ const domains_add = {
57
86
  log.info(``);
58
87
  log.info(`Already serving ${domain.fqdn} somewhere else? Create this record FIRST and leave the CNAME above for later:`);
59
88
  log.info(` ${acme.name} → ${acme.target}`);
89
+ if (pair) {
90
+ const pacme = acme_record(pair);
91
+ log.info(` ${pacme.name} → ${pacme.target}`);
92
+ }
60
93
  log.info(`Faable then issues the certificate before any traffic moves, and switching the CNAME has no TLS gap.`);
61
94
  }
62
95
  log.info(`Track it with: faable deploy domains check ${domain.fqdn}`);
@@ -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 };
package/dist/mcp/tools.js CHANGED
@@ -73,12 +73,8 @@ const tenant = z
73
73
  .optional()
74
74
  .describe("Auth tenant id (account_…). Defaults to the project's tenant (list_auth_tenants when it has several).");
75
75
  const auth_scope = (a) => [...opt('--account', a.tenant), ...scope(a)];
76
- const user_ref = z
77
- .string()
78
- .describe('User id (user_…) or exact email');
79
- const time = z
80
- .string()
81
- .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,})$/);
82
78
  const limit_flag = (a, d = 50) => ['--limit', String(a.limit ?? d)];
83
79
  const limit = z
84
80
  .number()
@@ -179,7 +175,7 @@ const api_detail = (a) => ({
179
175
  permissions: (a.permissions ?? []).map((p) => p.value)
180
176
  });
181
177
  // Which product a tool works on — /tools.json and the landing group by it.
182
- const product_of = (tool) => tool.command[0] === 'auth' ? 'auth' : 'deploy';
178
+ const product_of = (tool) => (tool.command[0] === 'auth' ? 'auth' : 'deploy');
183
179
  const AUTH_WRITE = {
184
180
  readOnlyHint: false,
185
181
  destructiveHint: false,
@@ -481,7 +477,7 @@ const TOOLS = [
481
477
  {
482
478
  name: 'list_auth_tenants',
483
479
  title: 'List Auth tenants',
484
- 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`.',
485
481
  input: { project },
486
482
  command: ['auth', 'accounts', 'list'],
487
483
  flags: scope,
@@ -539,7 +535,9 @@ const TOOLS = [
539
535
  last_login_since: time
540
536
  .optional()
541
537
  .describe('Logged in at or after: 24h, 7d, a date'),
542
- 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'),
543
541
  created_until: time.optional().describe('Signed up at or before'),
544
542
  suspended: z.boolean().optional(),
545
543
  tenant,
@@ -551,7 +549,9 @@ const TOOLS = [
551
549
  ...opt('--last-login-since', a.last_login_since),
552
550
  ...opt('--created-since', a.created_since),
553
551
  ...opt('--created-until', a.created_until),
554
- ...(a.suspended === undefined ? [] : [a.suspended ? '--suspended' : '--no-suspended']),
552
+ ...(a.suspended === undefined
553
+ ? []
554
+ : [a.suspended ? '--suspended' : '--no-suspended']),
555
555
  ...auth_scope(a)
556
556
  ],
557
557
  annotations: AUTH_READ,
@@ -560,15 +560,23 @@ const TOOLS = [
560
560
  {
561
561
  name: 'list_auth_users',
562
562
  title: 'List users',
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.",
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.',
564
564
  input: {
565
565
  search: z.string().optional().describe('Text in name, email or phone'),
566
566
  email: z.string().optional().describe('Exact email'),
567
567
  suspended: z.boolean().optional(),
568
568
  sort: z
569
- .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
+ ])
570
576
  .optional(),
571
- 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'),
572
580
  created_since: time.optional().describe('Signed up at or after'),
573
581
  limit,
574
582
  cursor,
@@ -579,7 +587,9 @@ const TOOLS = [
579
587
  flags: a => [
580
588
  ...opt('-q', a.search),
581
589
  ...opt('--email', a.email),
582
- ...(a.suspended === undefined ? [] : [a.suspended ? '--suspended' : '--no-suspended']),
590
+ ...(a.suspended === undefined
591
+ ? []
592
+ : [a.suspended ? '--suspended' : '--no-suspended']),
583
593
  // `--sort=-x`: as two words yargs would read `-last_login` as flags.
584
594
  ...(a.sort ? [`--sort=${a.sort}`] : []),
585
595
  ...opt('--last-login-since', a.last_login_since),
@@ -649,9 +659,15 @@ const TOOLS = [
649
659
  title: 'Read the Auth audit log',
650
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).",
651
661
  input: {
652
- 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)"),
653
666
  user: z.string().optional().describe('Only this user id (user_…)'),
654
- 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'),
655
671
  origin: z.string().optional().describe('Type prefix, e.g. oauth, admin'),
656
672
  status: z.enum(['success', 'failed', 'skipped', 'info']).optional(),
657
673
  since: time.optional().describe('30m, 24h, 7d or a date (default 7d)'),
@@ -713,7 +729,10 @@ const TOOLS = [
713
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.',
714
730
  input: {
715
731
  user: user_ref,
716
- active: z.boolean().optional().describe('Only active sessions (default true)'),
732
+ active: z
733
+ .boolean()
734
+ .optional()
735
+ .describe('Only active sessions (default true)'),
717
736
  tenant,
718
737
  project
719
738
  },
@@ -791,7 +810,10 @@ const TOOLS = [
791
810
  .describe('Wait until live or failed, up to 5 minutes (default false)')
792
811
  },
793
812
  command: ['deploy', 'trigger'],
794
- flags: a => [...target(a), ...(a.wait ? ['--wait', '--timeout', '300'] : [])],
813
+ flags: a => [
814
+ ...target(a),
815
+ ...(a.wait ? ['--wait', '--timeout', '300'] : [])
816
+ ],
795
817
  timeout_ms: 330_000,
796
818
  annotations: {
797
819
  readOnlyHint: false,
@@ -987,10 +1009,18 @@ const TOOLS = [
987
1009
  {
988
1010
  name: 'add_domain',
989
1011
  title: 'Add a custom domain',
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.",
991
- 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
+ },
992
1022
  command: ['deploy', 'domains', 'add'],
993
- flags: a => [a.fqdn, ...target(a)],
1023
+ flags: a => [a.fqdn, ...(a.www ? ['--www'] : []), ...target(a)],
994
1024
  write: true,
995
1025
  annotations: {
996
1026
  readOnlyHint: false,
@@ -1052,7 +1082,7 @@ const TOOLS = [
1052
1082
  {
1053
1083
  name: 'link_repo',
1054
1084
  title: 'Link a repository to an app',
1055
- 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.',
1056
1086
  input: {
1057
1087
  app,
1058
1088
  repo: z.string().describe('GitHub repository, owner/repo'),
@@ -1063,12 +1093,7 @@ const TOOLS = [
1063
1093
  project
1064
1094
  },
1065
1095
  command: ['deploy', 'link'],
1066
- flags: a => [
1067
- '--repo',
1068
- a.repo,
1069
- ...opt('--branch', a.branch),
1070
- ...target(a)
1071
- ],
1096
+ flags: a => ['--repo', a.repo, ...opt('--branch', a.branch), ...target(a)],
1072
1097
  write: true,
1073
1098
  annotations: {
1074
1099
  readOnlyHint: false,
@@ -1296,7 +1321,7 @@ const TOOLS = [
1296
1321
  {
1297
1322
  name: 'suspend_auth_user',
1298
1323
  title: 'Suspend a user',
1299
- 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.',
1300
1325
  input: {
1301
1326
  user: user_ref,
1302
1327
  reason: z.string().max(512).describe('Why — recorded on the user'),
@@ -1380,7 +1405,7 @@ const TOOLS = [
1380
1405
  },
1381
1406
  {
1382
1407
  name: 'update_auth_client_login',
1383
- title: "Change how users sign in to an app",
1408
+ title: 'Change how users sign in to an app',
1384
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.",
1385
1410
  input: {
1386
1411
  client: z
@@ -1447,7 +1472,12 @@ const TOOLS = [
1447
1472
  project
1448
1473
  },
1449
1474
  command: ['auth', 'users', 'password-setup'],
1450
- 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
+ ],
1451
1481
  write: true,
1452
1482
  annotations: { ...AUTH_WRITE, idempotentHint: false },
1453
1483
  example: { user: 'ana@example.com', channel: 'email' }
@@ -1458,9 +1488,15 @@ const TOOLS = [
1458
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.",
1459
1489
  input: {
1460
1490
  user: user_ref,
1461
- 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'),
1462
1495
  name: z.string().optional(),
1463
- 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)'),
1464
1500
  profile_only: z
1465
1501
  .boolean()
1466
1502
  .optional()
@@ -1499,7 +1535,10 @@ const TOOLS = [
1499
1535
  .string()
1500
1536
  .optional()
1501
1537
  .describe('The exact new password. Omit and set generate:true to have one made.'),
1502
- 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'),
1503
1542
  connection: z
1504
1543
  .string()
1505
1544
  .optional()
@@ -1525,7 +1564,7 @@ const TOOLS = [
1525
1564
  {
1526
1565
  name: 'get_auth_recovery_link',
1527
1566
  title: 'Get a password-reset link',
1528
- 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`.',
1529
1568
  input: { user: user_ref, tenant, project },
1530
1569
  command: ['auth', 'users', 'password-setup'],
1531
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.36.0",
3
+ "version": "4.37.0",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "author": "Marc Pomar <marc@faable.com>",