saaslayer 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +199 -18
  2. package/bin/saaslayer.js +335 -62
  3. package/package.json +3 -2
  4. package/src/aws-sigv4.js +74 -26
  5. package/src/commands/access-admins.js +2 -2
  6. package/src/commands/admin-allowlist.js +23 -3
  7. package/src/commands/api-keys.js +83 -0
  8. package/src/commands/audit.js +77 -0
  9. package/src/commands/aws.js +355 -82
  10. package/src/commands/binding-handoff.js +174 -0
  11. package/src/commands/bindings.js +111 -0
  12. package/src/commands/catalog.js +30 -3
  13. package/src/commands/deploy.js +49 -11
  14. package/src/commands/env-export.js +58 -0
  15. package/src/commands/first-admin.js +15 -4
  16. package/src/commands/foundation.js +75 -117
  17. package/src/commands/hooks.js +271 -0
  18. package/src/commands/integration-credentials.js +1 -1
  19. package/src/commands/lifecycle.js +149 -24
  20. package/src/commands/login-domain.js +259 -0
  21. package/src/commands/permission-orgs.js +80 -0
  22. package/src/commands/release-manifest.js +17 -8
  23. package/src/commands/service-principals.js +42 -5
  24. package/src/commands/settings.js +21 -5
  25. package/src/commands/sms-registration.js +182 -0
  26. package/src/commands/sms.js +178 -0
  27. package/src/commands/social.js +265 -0
  28. package/src/commands/support-staff.js +72 -0
  29. package/src/commands/users-management.js +2 -20
  30. package/src/commands/users.js +56 -11
  31. package/src/commands/versions.js +61 -0
  32. package/src/connection-proof.js +41 -0
  33. package/src/deployments.js +14 -2
  34. package/src/foundation-change-set.js +180 -0
  35. package/src/foundation-home.js +121 -0
  36. package/src/foundation-template.js +51 -10
  37. package/src/foundation-trust-write.js +379 -0
  38. package/src/iam-session.js +14 -8
  39. package/src/login-domain.js +138 -0
  40. package/src/login-methods.js +118 -0
  41. package/src/module-catalog.js +3 -2
  42. package/src/release-manifest.js +11 -4
  43. package/src/scope.js +3 -1
  44. package/src/settings.js +85 -13
  45. package/src/sms/number.js +37 -0
  46. package/src/sms/registration-fields.js +167 -0
  47. package/src/sms/registration-validate.js +151 -0
  48. package/src/sms/registration.js +216 -0
  49. package/src/sms/release.js +55 -0
  50. package/src/sms/scope.js +86 -0
  51. package/src/sms/status.js +181 -0
  52. package/src/ssm-api.js +31 -0
  53. package/src/trust-entries.js +350 -0
  54. package/src/user-service-instance.js +27 -0
  55. package/src/users-api.js +55 -8
  56. package/src/users-import/checkpoint.js +76 -0
  57. package/src/users-import/import.js +233 -24
  58. package/src/versions.js +80 -0
  59. package/templates/bootstrap/saaslayer-bootstrap-permission-set-inline-policy.json +148 -0
  60. package/templates/bootstrap/saaslayer-bootstrap-policy-email-sender.json +22 -0
  61. package/templates/bootstrap/saaslayer-bootstrap-policy-sms-number.json +22 -0
  62. package/templates/bootstrap/saaslayer-bootstrap-policy.json +114 -0
  63. package/templates/bootstrap/saaslayer-bootstrap-trust-policy.json +18 -0
  64. package/templates/saaslayer-foundation-region.yml +45 -1
  65. package/templates/saaslayer-foundation.yml +759 -309
package/bin/saaslayer.js CHANGED
@@ -30,11 +30,12 @@ function parseArgs(argv) {
30
30
  const HELP = `saaslayer — SaaSLayer onboarding CLI
31
31
 
32
32
  Usage:
33
- saaslayer init --control-plane-account <12-digit> --external-id <secret> [--stack-name NAME]
33
+ saaslayer init --control-plane-account <12-digit> --external-id <id> --control-plane-id <id> [--stack-name NAME]
34
34
  [--region REGION] [--stack-name-prefix sl-] [--org-id ID] [--template PATH] [--dry-run]
35
- Deploy the SaaSLayer foundation stack (3 IAM roles + permissions boundary + artifact
36
- bucket) into the caller's AWS account, trusting the SaaSLayer control plane.
37
- Uses the bundled templates/saaslayer-foundation.yml. --dry-run validates only.
35
+ Create the SaaSLayer foundation stack (3 IAM roles + permissions boundary) in the caller's AWS account, with one
36
+ trust entry for that SaaSLayer control plane (its control-plane account, trust identifier and control-plane id) and
37
+ the caller as the account's connection authorizer. Refuses an account that already has a foundation (use
38
+ saaslayer foundation upgrade). Uses the bundled templates/saaslayer-foundation.yml. --dry-run validates only.
38
39
 
39
40
  saaslayer foundation status [--region R] [--profile P] [--stack-name saaslayer-foundation] [--only account|region]
40
41
  Show each installed foundation stack (saaslayer-foundation + saaslayer-foundation-<region>): its status,
@@ -42,13 +43,15 @@ Usage:
42
43
  saaslayer foundation upgrade [--region R] [--profile P] [--stack-name saaslayer-foundation] [--only account|region]
43
44
  [--dry-run] [--yes] [--allow-replacement]
44
45
  Upgrade the installed foundation stacks in place to this CLI's bundled templates with YOUR AWS credentials.
45
- Builds a CloudFormation change set that keeps every existing parameter value (the ExternalId is never
46
+ The account stack is upgraded in its home region (where it was first created), with its trust re-rendered from
47
+ its own TrustEntries; a foundation that still trusts a single ExternalId converts through saaslayer aws connect.
48
+ Builds a CloudFormation change set that keeps every existing parameter value (trust identifiers are never
46
49
  re-entered or printed; new parameters take their template default), prints the version change and each
47
50
  resource change, then executes after you confirm and reads the new version back. Refuses a stack that is
48
51
  not in a stable state or that runs a newer version than this CLI. A change that replaces a resource or
49
52
  removes an IAM role, the permissions boundary or the artifact bucket needs --allow-replacement.
50
- --dry-run shows the change set and deletes it; --yes skips the confirmation. --region is where the stacks
51
- live (default $AWS_REGION, else us-east-1). The region stack is skipped when it is not installed.
53
+ --dry-run shows the change set and deletes it; --yes skips the confirmation. --region is the region stack's region
54
+ (default $AWS_REGION, else us-east-1). The region stack is skipped when it is not installed.
52
55
  After the upgrade (or when nothing changed) the control plane re-reads the account's foundation through its
53
56
  own trust, as your saaslayer login (no AWS credentials are sent), so the console and deploys see the new
54
57
  version; if that fails the upgrade still stands and the console's "check again" re-reads it.
@@ -111,8 +114,10 @@ Usage:
111
114
  saaslayer permissions owner bootstrap <product> --org ORG --user USER --api-base URL (--iam PRINCIPAL | --token KEY)
112
115
  Make a member the FIRST owner of an org (refused once the org has an owner). Needs saaslayer:catalog:owner:bootstrap
113
116
  (a machine: the owners:bootstrap scope and a grant of it).
114
- saaslayer permissions owner reconcile <product> --api-base URL (--iam PRINCIPAL | --token KEY) [--org ORG] [--apply]
115
- Compare each org's owner counter with a live recount; --apply repairs drift. Needs saaslayer:catalog:owner:reconcile
117
+ saaslayer permissions owner reconcile <product> --api-base URL (--iam PRINCIPAL | --token KEY) [--org ORG] [--complete-owners] [--apply]
118
+ Compare each org's owner counter with a live recount; --apply repairs drift. --complete-owners also grants the
119
+ product's ownerRole to every org's platform owners (saaslayer:org-owner) who lack it and prints the counts
120
+ (dry run unless --apply; resumes from its checkpoint). Needs saaslayer:catalog:owner:reconcile
116
121
  (a machine: the catalog:write scope and a grant of it).
117
122
  saaslayer permissions service-principal roles (<id> | --machine PRINCIPAL) --api-base URL (--token KEY | --iam PRINCIPAL)
118
123
  saaslayer permissions service-principal assign (<id> | --machine PRINCIPAL) --role ROLE [--scope S] --api-base URL (--token KEY | --iam PRINCIPAL)
@@ -121,6 +126,11 @@ Usage:
121
126
  mapped principal (iam.PRINCIPAL), which acts with its scopes AND these grants.
122
127
  Grants are deployment-wide unless --scope names an org scope. Needs roles:role:{assign,unassign} +
123
128
  identity:principal:read.
129
+ saaslayer permissions service-principal verifier-key create <id> [--ssm-parameter PATH [--region R] [--profile P]] --api-base URL (--token KEY | --iam PRINCIPAL)
130
+ Issue service account <id> (created, owned by you, when missing) a deployment-wide key whose only permission is
131
+ verifying API keys, for a backend that accepts its users' keys. Prints the key once; --ssm-parameter also writes it
132
+ to that SecureString (replacing the key it held) with your AWS credentials. Needs keys:api-key:issue-verifier.
133
+ Rotate: create a new key, deploy it, then revoke the old one (DELETE /api-keys/<keyId>).
124
134
  saaslayer permissions machine-trust list | get <principalId> --api-base URL [auth]
125
135
  saaslayer permissions machine-trust declare <principalId> --role-arn ARN --scope S [--scope S2] --api-base URL [auth]
126
136
  saaslayer permissions machine-trust update <principalId> [--role-arn ARN] [--scope S …] [--expected-revision N] --api-base URL [auth]
@@ -139,11 +149,34 @@ Usage:
139
149
  saaslayer permissions access-admins status | cancel <transferId> --api-base URL [auth]
140
150
  saaslayer permissions access-admins accept <transferId> | activate --api-base URL [your deployment login]
141
151
  The deployment's administrators (saaslayer:access-admin). At least one usable human administrator
142
- always remains — enabled, and activated: signed in themselves with a verified email; machines never count — so
143
- the last one can't be revoked, disabled, deleted or unverified (409 LAST_ADMIN). offer grants <suid> the role at
144
- once; it counts once they accept with their own deployment login. --mode transfer (default) then removes you,
152
+ always remains — enabled, and activated: signed in themselves with a verified email or phone
153
+ number; machines never count — so the last one can't be revoked, disabled, deleted or unverified (409
154
+ LAST_ADMIN). offer grants <suid> the role at once; it counts once they accept with their own deployment login. --mode transfer (default) then removes you,
145
155
  add keeps you. An interrupted accept leaves both admins; accept again to finish. cancel (pending offers, by you)
146
156
  revokes the grant. activate records your own activation. See services/permissions-service/user-docs/access-admins.md.
157
+ saaslayer permissions support-staff grant <suid> --mode view-only|act-as [--expires-at ISO] --api-base URL [your deployment login]
158
+ saaslayer permissions support-staff revoke <suid> --mode view-only|act-as --api-base URL [your deployment login]
159
+ saaslayer permissions support-staff list --api-base URL [auth]
160
+ The deployment's support staff: people who view as a member of any org without belonging to it
161
+ (saaslayer:support-view-only refuses every write while viewing; saaslayer:support-act-as also allows them,
162
+ reserved operations stay refused). Only an access admin signed in themselves grants or revokes them
163
+ (--id-token-file or a deployment login; never an API key or IAM machine). Find a suid with saaslayer users get --email.
164
+ saaslayer permissions orgs create <name> [--id ID] [--description TEXT] --api-base URL [auth]
165
+ saaslayer permissions orgs members add <orgId> --user <suid> [--email E] --api-base URL [auth]
166
+ A deployment's runtime orgs (not your SaaSLayer account org — that is saaslayer org). create makes an org
167
+ (--id picks its id, else one is generated); members add puts a user in it. Then permissions owner bootstrap
168
+ makes a member its first owner. Needs orgs:write (an access admin holds it).
169
+ saaslayer permissions orgs hook-joinable set <orgId> --consumer <user-service@<deploymentId>/<instance>> --role <roleId> [--role …] --api-base URL [auth]
170
+ saaslayer permissions orgs hook-joinable disable <orgId> --api-base URL [auth]
171
+ Which roles one user-service instance's lifecycle hook may grant in the org (exact role ids, at most 20; privileged
172
+ roles are refused). set publishes the list for that --consumer; disable stops the org's hooks granting any role.
173
+ Only an owner of the org, signed in as themselves (deployment login), may change it.
174
+ saaslayer permissions api-keys create --user OWNER --name N --allow service:resource:action [--allow …] [--deny …]
175
+ [--scope ORG] [--expires-at ISO] (--deployment ID | --api-base URL) [auth]
176
+ saaslayer permissions api-keys list [--user OWNER] | get <keyId> | revoke <keyId> (--deployment ID | --api-base URL) [auth]
177
+ Scoped API keys on the deployment's permissions API (for deployments without a console, e.g. permissions-only with an
178
+ outside login provider). A key holds exactly its --allow tuples minus --deny (product:service:resource:action also
179
+ accepted), never more than the caller holds. create prints the key once; revoke stops it authenticating at once.
147
180
  saaslayer permissions trust-policies list | get <policyId> (--deployment ID | --api-base URL) [auth]
148
181
  saaslayer permissions trust-policies add <issuerUrl> --audience A [--audience B] (--subject S … | --allow-any-subject)
149
182
  [--principal-claim sub] [--jwks-uri URL] [--description D] (--deployment ID | --api-base URL) [auth]
@@ -171,10 +204,13 @@ Usage:
171
204
  exported; the file holds personal data.
172
205
  saaslayer users import --manifest manifest.json --user-pool-id POOL --region R [--profile P]
173
206
  [--api-base URL --product P (--iam PRINCIPAL | --token KEY) [--logs-role-arn ARN] --apply] [--report FILE]
174
- Dry run by default: prints what would be created or linked. --apply imports new users through a Cognito CSV
175
- import job (reset required on first sign-in, no emails sent), stamps their SaaSLayer id + default org, then
176
- creates each user's permissions principal and org, adds members and bootstraps the first Owner (IAM scopes users:write + orgs:write + owners:bootstrap).
177
- Idempotent: re-run to retry failures. See docs/users-import.md.
207
+ Dry run by default: prints what would be created or linked (with --iam, also checks the profile permissions and
208
+ counts profiles). --apply imports new users through a Cognito CSV import job (reset required on first sign-in, no
209
+ emails sent), stamps their SaaSLayer id + default org, creates each person's user-service profile (no email, no
210
+ password), then each permissions principal and org, adds members and bootstraps the first Owner. --apply needs --iam
211
+ (--token: dry run only; IAM scopes users:write + users:read + users:write-reserved + orgs:write + owners:bootstrap, checked for user-service
212
+ before anything is written). Idempotent: re-run to retry failures; resumes from <manifest>.profiles-checkpoint.json.
213
+ Exits 1 when any user or profile needs attention. See docs/users-import.md.
178
214
  saaslayer users <command> … [target] [auth]
179
215
  Administer a deployment's users through its user-service /api/users (see services/user-service/docs/users.md).
180
216
  [auth] = the current deployment login (\`saaslayer login --deployment\`; pick one with --deployment/--as), or
@@ -195,12 +231,19 @@ Usage:
195
231
  saaslayer users list (--email E | --default-org ORG) [--limit N] [--cursor C]
196
232
  Users holding an email, or whose default org is ORG; prints nextCursor for the next page.
197
233
  saaslayer users update <user> [--name N] [--attr name=value …]
198
- Profile attributes (name, given_name, family_name, locale, zoneinfo, picture).
234
+ Profile attributes (name, given_name, family_name, locale, zoneinfo, picture), or reserved ones (email,
235
+ email_verified=true|false, soid) through the reserved route, which needs saaslayer:users:account:update-reserved.
236
+ Profile and reserved attributes are separate updates; one command never mixes them.
199
237
  saaslayer users disable <user> | saaslayer users enable <user>
200
238
  Sign the user out everywhere and refuse sign-in / allow it again (grants and credentials are kept). The last
201
239
  usable owner of an org can't be disabled.
202
240
  saaslayer users delete <suid> --yes [--email E]
203
241
  GDPR delete everywhere (sign-in, passwordless data, profile). --email finds a user that was never projected.
242
+ First erases the person from the audit and their membership profile copies, then removes their own personal
243
+ workspace; prints auditIdentities (requested|done|not-configured), profileCopies (removed|not-configured) and
244
+ personalWorkspace (removed|none|not-configured). If that fails nothing is deleted:
245
+ run it again. After a finished delete, erase an address user-service never held with
246
+ saaslayer audit erase <suid> --email E.
204
247
  saaslayer users reset-password <user>
205
248
  Cognito mails a reset code to the verified email; the current password stops working.
206
249
  saaslayer users set-password <user> --password-stdin [--temporary]
@@ -227,11 +270,67 @@ Usage:
227
270
  Purposes: account-read, account-provisioning, account-import, account-administration, account-deletion,
228
271
  account-sensitive, account-recovery (humans only), reconciliation, config, email-authoring. A raw key is written
229
272
  only to --output (0600); revoke needs --reason; a revoked grant or root comes back only with --reason.
273
+ saaslayer audit erase <suid> [--email E …] (--iam PRINCIPAL [--region R] [--profile P] | --token KEY)
274
+ (--api-base PERMISSIONS_URL | --deployment <dep_id|env> [--config-url URL] | --discovery-url URL)
275
+ GDPR erasure of a person from the deployment's audit trail: their name and email come off every audit entry that
276
+ names them, and each --email address (repeat, at most 50) comes off the invitation entries holding it; ids and
277
+ events stay. Invitation entries are found only by the addresses you pass: give every address the person had,
278
+ including any the deployment never knew.
279
+ For operators, and to retry the erasure after \`saaslayer users delete\`. Needs the platform-only scope
280
+ audit:person:erase. Prints { personId, status, emails: <count> } (addresses are never printed);
281
+ status requested is finished by the deployment's audit worker within minutes. Safe to run again, with more addresses.
282
+
283
+ Organizations and projects (requires login):
284
+ saaslayer org create <name> Create an org (you are its owner) and make it the active org.
285
+ saaslayer org list List the orgs you belong to.
286
+ saaslayer org use <id> Set the active org.
287
+ saaslayer projects [--org ID] List the active org's projects.
288
+ saaslayer project create <name> [--slug <slug>] [--org ID]
289
+ Create a project in the active org and make it the active project. --slug is its public deploy name (letter-first,
290
+ lowercase, at most 15 characters; derived from the name when omitted).
230
291
 
231
292
  Deploy & lifecycle (requires login + a connected AWS account):
232
- saaslayer aws connect --aws-account <id> [--region R] [--org ID] [--org-wide]
233
- Connect your AWS account to an org. Binds it to your active project by
234
- default; --org-wide lets any project in the org deploy into it.
293
+ saaslayer aws connect --aws-account <id> [--region R] [--profile P] [--org ID] [--org-wide] [--sms-toll-free [--yes]]
294
+ Connect your AWS account to an org, with YOUR AWS credentials for that account (--profile, else the AWS CLI's
295
+ default credentials: environment, SSO profile or AWS CloudShell). Binds it to your active project by
296
+ default; --org-wide lets any project in the org deploy into it. The account foundation lives in one home region
297
+ (created by the first connect); connecting another region adds only that region's stack. --sms-toll-free also installs the account's US
298
+ toll-free SMS sending number (~$2/month, asks first unless --yes) and prints its ARN.
299
+ The org connection is activated by a proof signed with your AWS credentials: you must be one of the account's
300
+ connection authorizers (the first connect makes you one); until then it stays PENDING_PROOF and rerunning resumes it.
301
+ saaslayer aws authorizers <add|remove> <arn> --aws-account <id> [--region R] [--profile P]
302
+ Change who may authorize SaaSLayer org connections to the account (ConnectionAuthorizerArns, stored as path-less
303
+ role ARNs). Run by a current authorizer; the last one cannot be removed.
304
+ saaslayer aws rotate-trust <start|verify|switch|retire|rollback|status> --aws-account <id> [--reason <text>] [--region R] [--org ID] [--profile P]
305
+ Rotate the account's trust identifier for this control plane, with overlap: start (needs --reason) adds a new
306
+ identifier beside the current one, verify checks it assumes, switch moves new operations to it, retire removes the
307
+ old one once no running operation carries it. rollback (before retire) goes back to the current identifier; after
308
+ a switch it waits for the operations already using the new one. Each step is signed with your AWS credentials (a
309
+ connection authorizer of the account) and is safe to rerun. status shows the rotation; identifiers are never shown.
310
+ saaslayer sms setup --env E [--region R] [--simulator] [--yes] [--profile P]
311
+ Install the SMS sending number for phone login on the region foundation of the env's account and region (from
312
+ the project's deployment there, else its connected account), with your own AWS credentials for that account
313
+ (cloud-prem; hosted accounts are not supported yet). Shows the cost (~$2/month) and asks unless --yes. Prints the
314
+ number's ARN and the exact settings command. It cannot send until its registration is approved (AWS review: up to
315
+ 15 business days). --simulator (dev only, refused when the account has staging or prod deployments) installs an
316
+ AWS simulator number instead: it reaches simulator destinations only, and needs no registration.
317
+ saaslayer sms register --env <env> [--region R] [--file registration.json] [--profile P]
318
+ Register the account's toll-free sending number with AWS (cloud-prem, with YOUR AWS credentials for the env's
319
+ account): asks for (or reads from --file) the company, website, public privacy-policy and terms URLs, contact,
320
+ opt-in description + PNG screenshot and message samples (naming the brand, with HELP and STOP), checks them,
321
+ then creates the registration, fills it, associates the number and submits. AWS review: up to 15 business days.
322
+ Re-running resumes the same registration; after AWS asks for updates it shows the reasons, re-asks only the
323
+ flagged fields and resubmits. A submitted, reviewing or complete registration is left as it is.
324
+ saaslayer sms status --env <env> [--region R] [--json] [--profile P]
325
+ The sending number, registration state, sandbox or production, spend limit and what is still missing (as the
326
+ deploy's sms.* readiness codes), with the console links and values for the production-access and spend-limit
327
+ requests (AWS has no API for either). An unfinished sms release is moved forward from the stack's actual state
328
+ and shown with the command that resumes it.
329
+ saaslayer sms release --env E [--region R] [--yes] [--profile P]
330
+ Retire the account-and-region SMS number: takes the control plane's SMS lock (deploys that set the number are
331
+ refused meanwhile), checks that no deployment in any project still uses it, asks, removes the number (billing
332
+ stops), then deletes its registration. Every step is recorded; re-run it from any machine to resume (sms status
333
+ also records a number removal that landed).
235
334
  saaslayer project use <id> Set the active project for deploy/status (a project id tnt_… or a customer id).
236
335
  saaslayer org members list [--org ID]
237
336
  saaslayer org members add --user <accountId> [--role deployer] [--org ID] [--yes]
@@ -246,64 +345,95 @@ Deploy & lifecycle (requires login + a connected AWS account):
246
345
  deployments is live: destroy each with \`saaslayer destroy\` first. Asks for the id to be typed unless --yes.
247
346
  saaslayer stacks List the modules a project can deploy: module id, regions, required
248
347
  modules and stable outputs.
348
+ saaslayer versions [--project ID] [--json]
349
+ The versions a deployment may move to, highest first: the channels on each (stable), breaking releases, and
350
+ which of the project's deployments run each one (a deployment on an unversioned commit is listed apart).
249
351
  saaslayer deploy [--services a,b | --module M ...] [--set MODULE.Setting=VALUE ...] [--settings FILE] [--env prod]
250
- [--region R] [--target ACCT] [--commit-sha SHA] [--admin-email E] [--yes]
251
- Deploy the project's modules into your connected account. --services/--module and --set take catalog module
352
+ [--region R] [--hosting hosted|byoa] [--target ACCT] [--version X.Y.Z | --channel stable] [--admin-email E | --admin-phone-number +E164] [--yes]
353
+ Deploy the project's modules. --hosting hosted runs them in a SaaSLayer AWS account (no AWS account of your own);
354
+ --hosting byoa runs them in your connected account (\`saaslayer aws connect\`). Without it, a project with a
355
+ connected account deploys there and one without is hosted. --services/--module and --set take catalog module
252
356
  ids (\`saaslayer stacks\`, e.g. permissions-service); an unknown id or a missing required module is refused before
253
357
  anything is sent. --settings FILE is { "<module>": { "<Setting>": value } }; --set overrides it (--param is
254
- the same as --set). The settings are checked against the schema of the release being deployed (--commit-sha,
255
- else the default release \`saaslayer stacks\` reports) before anything is sent, and the create-only ones are
256
- listed; the control plane always checks them too. A secret takes ssm:/<parameter name>.
358
+ the same as --set). --version (\`saaslayer versions\`) or --channel names the release to start on; without either
359
+ the control plane picks its default (stable). With neither, the settings are checked against the schema of the
360
+ default release \`saaslayer stacks\` reports before anything is sent and the create-only ones are listed; the
361
+ control plane always checks them too (it alone checks them for a --version). A secret takes ssm:/<parameter name>.
257
362
  Asks before creating anything, then confirms any cost estimate (--yes answers both; required non-interactively).
363
+ Sign-in: user-service.PrimaryLoginMethod (email, the default, or phone) is permanent. Only the opposite method can be
364
+ added as a second sign-in pool: EnablePhoneLogin on an email primary, EnableEmailLogin on a phone primary
365
+ (EnableEmailLogin=false means no email pool is added, not that sign-in is off); once accepted it is never turned off.
366
+ Phone sign-in needs user-service.PhoneSmsAllowedCountries (e.g. US,CA) and passes the SMS setup check first
367
+ (\`saaslayer sms status\`; a failed check saves nothing). A phone primary names its first admin by
368
+ --admin-phone-number (E.164; shown masked). The permanent primary, added pools, countries and SMS/Cognito cost
369
+ categories are printed before the confirm.
258
370
  saaslayer status [--project ID] [--env E] [--region R]
259
371
  Show the deployed instances of a project. --project takes a project id (tnt_…) or a customer id. Every scoped
260
372
  command prints \`scope: org=… project=… env=… (from: …)\` on stderr first (--json omits it); an empty result
261
373
  lists the projects you can see that do have deployments.
262
- saaslayer service add <service> [--region R]
374
+ saaslayer service add <service> [--region R] [--param MODULE.Setting=VALUE] [--settings FILE]
263
375
  saaslayer service remove <service> --data-custody delete|retain [--region R] [--reason TEXT] [--yes]
264
376
  Add or remove a single service on an existing deployment. A protected env (staging, prod) removal needs --reason
265
377
  and the service name typed to confirm (--yes confirms it).
266
- saaslayer update --commit-sha SHA [--env E] [--region R] [--reason TEXT] [--force]
267
- Roll an existing deployment's services to a new release (upgrade; deploy only creates). Protected envs
268
- (staging, prod) need --reason; --force updates past the drift gate (audited with the reason).
378
+ saaslayer update --version X.Y.Z | --channel stable [--env E] [--region R] [--reason TEXT] [--force]
379
+ Roll an existing deployment's services to a version (upgrade; deploy only creates); a lower version is a
380
+ rollback. --channel moves to what the channel points at now (once, not a subscription). \`saaslayer versions\`
381
+ lists them. Protected envs (staging, prod) need --reason; --force updates past the drift gate (audited with the
382
+ reason). --commit-sha SHA still works until the control plane refuses it.
383
+ saaslayer update --retry [--env E] [--region R] [--reason TEXT] [--no-wait]
384
+ Retry the deployment at its deployed release with its stored settings (nothing is rewritten): resumes an accepted
385
+ sign-in method that failed or is not ready yet (\`saaslayer settings get\` shows why and what to fix first). An
386
+ accepted method is never turned off. Nothing to resume answers "nothing to retry". Protected envs need --reason.
269
387
  saaslayer migrations approve --env E [--region R] --run <runId> --reason TEXT [--no-wait]
270
388
  Approve the migrations an update left awaiting approval (a protected env's destructive contract migrations, e.g. a
271
389
  rename's retire step): \`saaslayer update\` prints the run id. The control plane records you and the reason.
272
390
  saaslayer update --param MODULE.Setting=VALUE ... [--env E] [--region R] [--reason TEXT]
273
391
  Change settings, keeping the current release: --param goes through the settings route, exactly like
274
- \`saaslayer settings set --set\`. --commit-sha and --param cannot be combined: move the release, then set.
392
+ \`saaslayer settings set --set\`. A release (--version, --channel) and --param cannot be combined: move it, then set.
275
393
  saaslayer update --manifest FILE [--env E] [--region R] [--settings F] [--reason TEXT] [--force] [--dry-run]
276
394
  Promote a tested release manifest to this environment. Preflight first, nothing sent on any problem: the CLI
277
395
  version the release was tested with, every deployed module in the bundle, each module's published settings
278
396
  contract matching the manifest's sha256, schema transitions from the deployed revision (a set setting the target
279
397
  drops or refuses, a changed create-only default), the environment's settings (environments.<env>.settings in
280
398
  the manifest, or --settings) against the target contracts, direct-mode readers (permissionsDirectMode.readers) against
281
- what the release writes, and --reason for staging/prod. Then moves the release through the update route, waits,
282
- and writes the settings that differ through the settings route. --dry-run prints the preflight and plan only.
399
+ what the release writes, and --reason for staging/prod. Then moves the release through the update route (by
400
+ bundle.version when the manifest has one), waits, and writes the settings that differ through the settings route.
401
+ --dry-run prints the preflight and plan only.
283
402
  saaslayer release-manifest create --env E [--region R] [--out FILE] [--name NAME]
284
- Record a tested deployment as a release manifest: its revision, each module's settings-contract sha256, this
285
- CLI's version and what its permissions service writes. Add permissionsDirectMode.readers and environments.<env>.settings yourself.
403
+ Record a tested deployment as a release manifest: its version (bundle.version; a deployment on an unversioned
404
+ commit is refused) and revision, each module's settings-contract sha256, this CLI's version and what its
405
+ permissions service writes. Add permissionsDirectMode.readers and environments.<env>.settings yourself.
286
406
  saaslayer settings schema --module M [--revision SHA] [--env E] [--json]
287
407
  Print a module's published settings schema: type, update behavior (update-safe | create-only), kind
288
408
  (deployment | runtime), secret, billing impact, default. Without --revision, the revision the selected
289
409
  deployment runs.
290
410
  saaslayer settings get --env E [--region R] [--json]
291
411
  Print a deployment's settings: value and source (set | default | unset), the settings revision and any
292
- pending operation. A secret shows only whether it is set.
412
+ pending operation. A secret shows only whether it is set. With phone sign-in requested, also each sign-in
413
+ method's stage (accepted, provisioning, failed, created, ready — only ready signs in), why it is not ready and
414
+ the next command (sms setup, first-admin resend, update --retry).
293
415
  saaslayer settings set --env E (--set MODULE.Setting=VALUE ... | --file settings.<env>.json) [--reason TEXT] [--no-wait]
294
416
  Change settings (null in a file resets one to its default; omitted settings are untouched). Checked against
295
417
  the deployment's schema before anything is sent: create-only, runtime and unknown settings are refused, and
296
418
  a secret takes a reference (ssm:/<parameter name>, or { "ssmParameter": "/<name>" } in a file), never the
297
419
  value. Sent with the settings revision just read, so a concurrent change is refused (re-read and retry).
298
420
  A billing change and the protected envs (staging, prod) need --reason. Waits for the update operation.
421
+ The login-domain settings (user-service.CustomCognitoDomainName, CustomCognitoDomainCertificateArn,
422
+ ActiveLoginDomain) are set by saaslayer login-domain and refused here (LOGIN_DOMAIN_MANAGED_SETTING).
299
423
  saaslayer settings diff --env A --env B [--manifest release.json] [--json]
300
424
  Compare two environments: module revisions, differing settings (create-only and secret marked; secrets as
301
425
  set/unset) and each settings revision, plus the gaps between them. With --manifest, each environment is also
302
426
  checked against the release: modules outside or behind the bundle, bundle modules it lacks, the
303
427
  permission-doc format it writes, and its deployed values against environments.<env>.settings.
304
428
  Every settings command prints its scope and the deployment id on stderr (--json omits them).
305
- saaslayer destroy --data-custody delete|retain [--region R] [--yes]
306
- Tear down the project's deployment (typed-name confirmation).
429
+ saaslayer destroy --data-custody delete|retain [--region R] [--reason TEXT] [--yes]
430
+ saaslayer destroy --purge-retained --reason TEXT [--region R] [--yes]
431
+ Tear down the project's deployment (typed-name confirmation; --yes confirms it). delete removes its data
432
+ (irreversible); retain keeps its data and leaves the deployment RETIRED: retained resources remain your
433
+ organization's responsibility and cost until purged. --purge-retained deletes what a retain destroy kept
434
+ (irreversible) and takes no --data-custody. A protected env (staging, prod) and every purge need --reason.
435
+ A delete destroy or purge prints its purgeResult: complete, pending (residual items AWS finishes later, with
436
+ when) or incomplete (failed items and items outside SaaSLayer custody).
307
437
  saaslayer operations get <operationId> [--deployment ID] [--json]
308
438
  saaslayer operations watch <operationId> [--deployment ID] [--interval SECONDS]
309
439
  Show (get) or wait for (watch) an operation: a deploy, update, service add/remove or destroy and each
@@ -316,11 +446,70 @@ Deploy & lifecycle (requires login + a connected AWS account):
316
446
  Cancel an in-flight operation: stops its run and releases the deployment for the next command. The deployment's
317
447
  activity records who cancelled it and the reason. A finished operation is refused.
318
448
  saaslayer first-admin resend [--deployment ID | --env E --region R] [--reason TEXT] [--no-wait]
319
- saaslayer first-admin recover --email E --reason TEXT [--suid ID] [--deployment ID | --env E --region R] [--no-wait]
449
+ saaslayer first-admin recover (--email E | --phone-number +E164) --reason TEXT [--suid ID] [--deployment ID | --env E --region R] [--no-wait]
320
450
  The deployment's first administrator (needs saaslayer:deployer:deployment:admin-bootstrap; org owners hold it).
321
451
  resend delivers the designated admin's first sign-in again (the only rotation of its temporary password;
322
- refused once they activated). recover designates a new first admin (--email, optional --suid) and is refused
452
+ refused once they activated). recover designates a new first admin (--email; --phone-number on a phone-primary
453
+ deployment; optional --suid) and is refused
323
454
  with ADMIN_EXISTS while any usable access admin remains. Both wait for their operation.
455
+ saaslayer social status [--env E] [--region R] [--service REF] [--json]
456
+ One user-service instance's social sign-in: each provider on or off, its client id and hosted domains, the
457
+ callback/logout URLs and app origins, and the redirect URI and JavaScript origin to paste into the Google console.
458
+ --service names the instance (user-service or user-service@<instance>); a deployment with several needs it.
459
+ saaslayer social enable google [--client-id ID] [--client-secret-stdin] [--hosted-domain D ...] [--callback-url URL ...]
460
+ [--app-origin ORIGIN ...] [--env E] [--service REF] [--reason TEXT] [--no-wait]
461
+ saaslayer social rotate-secret google --client-secret-stdin [--env E] [--service REF] [--reason TEXT] [--no-wait]
462
+ saaslayer social disable google [--confirm] [--env E] [--service REF] [--reason TEXT] [--no-wait]
463
+ Change the instance's social sign-in as one request and wait for the deployment run it starts. The client secret
464
+ is read only from stdin (e.g. < secret.txt); it is never a flag and never printed. enable keeps the stored
465
+ client id and secret unless given; each --callback-url / --app-origin / --hosted-domain list replaces the
466
+ stored one. A protected env (staging, prod) needs --reason. disable is refused (SOCIAL_ONLY_USERS_AFFECTED, with
467
+ the count) while users sign in only with that provider, even with --confirm, until they have another method.
468
+ A retry after a dropped connection repeats the same request and answers the same run.
469
+ saaslayer login-domain status [--env E] [--region R] [--service REF] [--json]
470
+ One user-service instance's branded login domain: kind (managed | custom), host and state, the active and
471
+ opaque hosts, the certificate status and whether DNS points correctly, the records a custom domain needs at
472
+ your DNS provider, the redirect URIs to keep registered in each provider console, and the account+region quota.
473
+ saaslayer login-domain provision managed|HOST [--env E] [--service REF] [--reason TEXT] [--no-wait] [--json]
474
+ managed: auth.<space>.saaslayer-cloud.com. HOST: your own (e.g. auth.acme.com); the first call requests its
475
+ certificate and prints the two records to add; run it again once the certificate is ISSUED to start the
476
+ provision run. Provisioning keeps the opaque login domain advertised until activate.
477
+ saaslayer login-domain activate --confirm-domain HOST --reason TEXT [--env E] [--service REF] [--no-wait] [--json]
478
+ saaslayer login-domain deactivate --confirm-domain HOST --reason TEXT [--env E] [--service REF] [--no-wait] [--json]
479
+ Advertise the custom login domain (activate) or the opaque one again (deactivate). Switching breaks the provider
480
+ redirects and app callbacks registered against the current host, so it is refused
481
+ (LOGIN_DOMAIN_HANDOFF_REQUIRED, listing them) unless --confirm-domain names the current host; passkeys and the
482
+ issuer do not change. A completion checklist is printed: the switch is done when the new host serves sign-in and every
483
+ listed redirect and callback is updated. Register the new redirect URI before activate and keep the old one.
484
+ saaslayer login-domain remove [--env E] [--service REF] [--reason TEXT] [--no-wait] [--json]
485
+ Delete the custom login domain, its DNS alias and (for HOST) its certificate, and free its quota slot. Refused
486
+ while it is active: deactivate first. A protected env (staging, prod) needs --reason for every change.
487
+ saaslayer hooks status [--env E] [--region R] [--service REF] [--json]
488
+ One user-service instance's lifecycle hooks: each point's target (URL or Lambda), failure mode and timeout, the
489
+ {org, role} pairs a hook may grant, and the signing-secret key ids (never the secret). --service names the
490
+ instance (user-service or user-service@<instance>); a deployment with several needs it.
491
+ saaslayer hooks set <point> (--url URL | --lambda ARN) [--on-failure allow|deny] [--timeout-ms N] [--claims-ttl-seconds N]
492
+ [--env E] [--service REF]
493
+ saaslayer hooks unset <point> [--env E] [--service REF]
494
+ Set or remove the target of one point: beforeSignUp, afterUserCreated, beforeTokenIssue, afterSignIn, message.
495
+ set replaces the point's whole configuration. --on-failure and --timeout-ms apply to beforeSignUp and
496
+ beforeTokenIssue. --claims-ttl-seconds (beforeTokenIssue only) is how long the hook's app: claims are reused
497
+ before it is asked again; 0 asks on every issuance. A Lambda must first be listed in the instance's HookLambdaArns setting (saaslayer settings
498
+ set; a protected env needs --reason there). Owners of the deployment's org only.
499
+ saaslayer hooks grants set --org ID --role ROLE [--org ID --role ROLE ...] [--env E] [--service REF]
500
+ Replace the exact {org, role} pairs a hook may grant; each --org pairs with the --role after it. The org's owner
501
+ must also list the role as hook-joinable. Owners of the deployment's org only.
502
+ saaslayer hooks test <point> [--env E] [--service REF] [--json]
503
+ The instance sends the point a signed test event (test: true, sample data naming no real account) and shows
504
+ what the hook proposed, or why the call failed and what a real call would then do. Nothing is applied.
505
+ saaslayer hooks rotate-secret [--env E] [--service REF] [--json]
506
+ A new signing secret, printed once: store it in your receiver. The previous key keeps signing until the time
507
+ shown, so verify with both until then. Owners of the deployment's org only.
508
+ saaslayer hooks claims-cache invalidate [--env E] [--service REF] [--json]
509
+ Drop every cached beforeTokenIssue claim, so the next sign-in asks the hook again (after changing its logic).
510
+ saaslayer hooks logs [--point P] [--env E] [--service REF] [--json]
511
+ The newest hook calls (kept 14 days): when, point, event and attempt, target kind, outcome, HTTP status,
512
+ time, reason code and the names of the actions a reply proposed. Never a body, target, secret or personal data.
324
513
  saaslayer activity --env E [--region R | --deployment ID] [--limit N] [--json]
325
514
  A deployment's activity, newest first: every change — yours and any SaaSLayer operator's — with who made it
326
515
  (customer:<id> | operator:<id>), the action, what it touched, the reason and its operation id.
@@ -329,6 +518,32 @@ Deploy & lifecycle (requires login + a connected AWS account):
329
518
  Org owners: a user-service instance's console integration credentials (key ids, state, age; never a value), and an
330
519
  emergency revoke of one key (no delay). The revoke answers its pending operation; the key stops working once every
331
520
  verifier holds the replacement.
521
+ saaslayer bindings create --label NAME (--deployment <dep_id> | --env E [--region R]) [--user-service-instance I] [--permissions-instance I] [--json]
522
+ saaslayer bindings list [--org ID] [--json]
523
+ saaslayer bindings show <bindingId> [--json]
524
+ Org owners: consumer bindings. A consumer binding points at one deployment and its user-service and
525
+ permissions-service instances (the default ones unless named) and keeps pointing there when instances are added;
526
+ consumers read it at its discovery URL (<api>/api/discovery/bindings/<bindingId>), which create prints.
527
+ saaslayer bindings handoff start <bindingId> --to <dep_id> [--json]
528
+ saaslayer bindings handoff prepare <bindingId> [--validation-writes FILE] [--reader-role-confirmed] [--consumer NAME]... [--consumers-confirmed] [--json]
529
+ saaslayer bindings handoff freeze|cutover|complete <bindingId> [--json]
530
+ saaslayer bindings handoff sync <bindingId> --report FILE [--json]
531
+ saaslayer bindings handoff rollback <bindingId> [--mode reverse-migration|accept-loss] [--json]
532
+ saaslayer bindings handoff status <bindingId> [--json]
533
+ Org owners: move a consumer binding to a replacement deployment in a maintenance window (only when the control
534
+ plane enables it). start names the replacement; prepare records the writes made validating against it (FILE: a
535
+ JSON array of { description, disposition: reverted|overwritten }), the reader role on it, the consumers and that
536
+ static consumers were rebuilt; freeze verifies the current deployment's write freeze (WriteFreeze and
537
+ AdminMaintenance on, writers drained); sync records the final sync (FILE: the user-service
538
+ scripts/migrate-pool.js --delta --commit report, which must match); cutover switches the binding; rollback
539
+ returns it (after the replacement accepted writes, --mode is required); complete closes it. The previous
540
+ deployment is never removed by a handoff. Each step prints the next one.
541
+ saaslayer env export --binding <bindingId> [--format dotenv|json]
542
+ A consumer binding's public configuration as env, to bake in at build or deploy time (no login needed):
543
+ SAASLAYER_USER_POOL_ID, SAASLAYER_CLIENT_ID, SAASLAYER_REGION, SAASLAYER_ISSUER, SAASLAYER_JWKS_URL,
544
+ SAASLAYER_USERS_API_BASE, SAASLAYER_PERMISSIONS_API_BASE, SAASLAYER_HOSTED_LOGIN_URL. dotenv (default) prints
545
+ KEY=value lines; json prints one object. A handoff underway is a notice on stderr. Apps that discover at runtime
546
+ instead set SAASLAYER_DISCOVERY_URL to the binding's discovery URL.
332
547
 
333
548
  Data migrations you run yourself (a deployment with migrationRunner self):
334
549
  saaslayer migrate status --deployment <id> [--service <ref>]
@@ -346,9 +561,10 @@ Data migrations you run yourself (a deployment with migrationRunner self):
346
561
  Exit codes: 0 ok / up-to-date, 1 failed, 2 awaiting approval, 3 applied but not reported.
347
562
 
348
563
  Platform operators:
349
- saaslayer admin allowlist list | add <email> | remove <email>
350
- The control plane's signup allowlist (the login pool's PreSignUp gate for console and CLI signup). Operators
351
- only; the control plane refuses anyone else.
564
+ saaslayer admin allowlist list | add <email> | remove <email> | open | close
565
+ The control plane's signup allowlist (the login pool's PreSignUp gate for console and CLI signup). close: only
566
+ listed emails may sign up; open: anyone may (the emails are kept for the next close). Operators only; the
567
+ control plane refuses anyone else.
352
568
 
353
569
  Global:
354
570
  --help Show this help.`
@@ -360,33 +576,43 @@ function cmdInit({ flags }) {
360
576
  // Canonical name — the account-global named IAM resources allow only one SaaSLayer
361
577
  // foundation stack per account, so init always updates the same stack.
362
578
  const stackName = flags['stack-name'] || 'saaslayer-foundation'
363
- const { writeDeployableTemplate, initDeployArgs, redactArgs } = require('../src/foundation-template')
579
+ const { writeDeployableTemplate } = require('../src/foundation-template')
364
580
  if (flags['dry-run']) {
365
581
  execFileSync('aws', ['cloudformation', 'validate-template', '--template-body', `file://${writeDeployableTemplate(template)}`, '--region', region], { stdio: 'inherit' })
366
582
  console.log(`\n[dry-run] template valid. Would deploy stack "${stackName}" to ${region}.`)
367
583
  return
368
584
  }
369
- // Required params: the SaaSLayer control-plane account that may assume the deploy role,
370
- // and the ExternalId trust secret shared during onboarding.
585
+ // Required params: the SaaSLayer control plane the foundation trusts: its control-plane account, its control-plane id and
586
+ // the trust identifier (AWS ExternalId) shared during onboarding.
371
587
  const controlPlaneAccount = flags['control-plane-account'] || process.env.SAASLAYER_CONTROL_PLANE_ACCOUNT
372
588
  const externalId = flags['external-id'] || process.env.SAASLAYER_EXTERNAL_ID
589
+ const controlPlaneId = flags['control-plane-id']
373
590
  const stackPrefix = flags['stack-name-prefix'] || 'sl-'
374
591
  const orgId = flags['org-id'] || process.env.SAASLAYER_ORG_ID || ''
375
592
  if (!controlPlaneAccount) throw new Error('init: --control-plane-account <12-digit id> (or $SAASLAYER_CONTROL_PLANE_ACCOUNT) is required')
376
593
  if (!/^[0-9]{12}$/.test(controlPlaneAccount)) throw new Error('init: --control-plane-account must be a 12-digit AWS account id')
377
- if (!externalId) throw new Error('init: --external-id <secret> (or $SAASLAYER_EXTERNAL_ID) is required — shared during onboarding')
378
- console.log(`Deploying SaaSLayer foundation stack "${stackName}" to ${region} (control plane ${controlPlaneAccount})…`)
379
- const args = initDeployArgs({ template, stackName, region, controlPlaneAccount, externalId, stackPrefix, orgId })
594
+ if (!externalId) throw new Error('init: --external-id <id> (or $SAASLAYER_EXTERNAL_ID) is required — shared during onboarding')
595
+ if (!controlPlaneId) throw new Error('init: --control-plane-id <id> is required — the SaaSLayer control plane this account trusts')
596
+ const { controlPlaneEntry, mergeTrustEntry, canonicalRoleArn } = require('../src/trust-entries')
597
+ const { resolveFoundationHome } = require('../src/foundation-home')
598
+ const { awsRunner } = require('../src/foundation-change-set')
599
+ const { createAccountFoundation } = require('../src/commands/aws')
600
+ const trustEntries = mergeTrustEntry('', controlPlaneEntry({ controlPlaneId, principalAccountId: controlPlaneAccount, trustIdentifiers: [externalId] }))
601
+ const exec = (cmd, args) => execFileSync(cmd, args, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 16 * 1024 * 1024 })
602
+ const awsIn = (r) => awsRunner(exec, { region: r, profile: flags.profile })
603
+ const home = resolveFoundationHome({ awsIn, requestedRegion: region, stackName })
604
+ if (home.state === 'home') throw new Error(`init: this account already has a foundation (${home.stackId}); upgrade it with saaslayer foundation upgrade`)
605
+ const authorizer = canonicalRoleArn(awsIn(region)(['sts', 'get-caller-identity']).Arn)
606
+ console.log(`Creating SaaSLayer foundation stack "${stackName}" in ${region} (control plane ${controlPlaneId}, account ${controlPlaneAccount})…`)
380
607
  try {
381
- execFileSync('aws', args, { stdio: 'inherit' })
608
+ createAccountFoundation({ aws: awsIn(region), trustEntries, connectionAuthorizerArns: authorizer, controlPlaneAccount, stackNamePrefix: stackPrefix, orgId, stackName, templatePath: template })
382
609
  } catch (err) {
383
- // execFileSync's message echoes the full argv; never let the ExternalId reach the terminal or logs.
384
- throw new Error(`init: aws ${redactArgs(args).join(' ')} failed (exit ${err.status ?? '?'})`)
610
+ throw new Error(`init: ${err.message}`)
385
611
  }
386
- console.log('\nSaaSLayer foundation deployed.')
387
- console.log(` • Control plane ${controlPlaneAccount} may now assume the deploy role (ExternalId gated).`)
612
+ console.log('\nSaaSLayer foundation created.')
613
+ console.log(` • Control plane ${controlPlaneId} (account ${controlPlaneAccount}) may now assume the deploy role (trust identifier gated).`)
388
614
  console.log(` • It can manage only CloudFormation stacks named "${stackPrefix}*" in this account.`)
389
- console.log(' • Share the ControlPlaneAccountId + ExternalId with SaaSLayer onboarding to finish setup.')
615
+ console.log(` • Connection authorizer: ${authorizer}.`)
390
616
  }
391
617
 
392
618
  async function main() {
@@ -401,9 +627,8 @@ async function main() {
401
627
  if (cmd === 'permissions' && sub === 'model' && positional[2] === 'apply') { await require('../src/commands/catalog').catalogApply(positional.slice(3), flags); return }
402
628
  if (cmd === 'permissions' && sub === 'owner' && positional[2] === 'bootstrap') { const a = await require('../src/commands/catalog').catalogBootstrapOwner(positional.slice(3), flags); console.log(`${a.userId} is now ${a.roleId} of ${a.scope}`); return }
403
629
  if (cmd === 'permissions' && sub === 'owner' && positional[2] === 'reconcile') {
404
- const r = await require('../src/commands/catalog').catalogReconcileOwners(positional.slice(3), flags)
405
- for (const o of r.orgs) console.log(`${o.ok ? 'ok ' : 'DRIFT'} ${o.orgId} counter=${o.counter} actual=${o.actual}`)
406
- console.log(r.applied ? 'repaired mismatched counters' : 'report only (pass --apply to repair)')
630
+ const catalog = require('../src/commands/catalog')
631
+ console.log(catalog.formatReconcileResult(await catalog.catalogReconcileOwners(positional.slice(3), flags)))
407
632
  return
408
633
  }
409
634
  if (cmd === 'permissions' && sub === 'model' && positional[2] === 'export') { await require('../src/commands/catalog').catalogExport(positional.slice(3), flags); return }
@@ -413,7 +638,14 @@ async function main() {
413
638
  if (positional[2] === 'roles') { console.log(JSON.stringify(await sp.servicePrincipalRoles(positional.slice(3), flags), null, 2)); return }
414
639
  if (positional[2] === 'assign') { const a = await sp.servicePrincipalAssign(positional.slice(3), flags); console.log(`granted ${a.roleId} to ${a.principalId}${a.scope ? ` in ${a.scope}` : ' (deployment-wide)'}`); return }
415
640
  if (positional[2] === 'unassign') { await sp.servicePrincipalUnassign(positional.slice(3), flags); console.log(`revoked ${flags.role}`); return }
416
- console.error('usage: saaslayer permissions service-principal <roles|assign|unassign> (<id> | --machine PRINCIPAL) [--role ROLE] [--scope S] --api-base URL'); process.exit(1)
641
+ if (positional[2] === 'verifier-key' && positional[3] === 'create') {
642
+ const issued = await sp.verifierKeyCreate(positional.slice(4), flags)
643
+ console.log(`issued verifier key ${issued.keyId} for service account ${issued.servicePrincipalId}${issued.expiresAt ? ` (expires ${issued.expiresAt})` : ''}`)
644
+ console.log(`key (shown once): ${issued.apiKey}`)
645
+ if (flags['ssm-parameter']) { const stored = await sp.storeVerifierKey(issued.apiKey, flags); console.log(`stored in SSM SecureString ${stored.name} (version ${stored.version})`) }
646
+ return
647
+ }
648
+ console.error('usage: saaslayer permissions service-principal <roles|assign|unassign|verifier-key create> (<id> | --machine PRINCIPAL) [--role ROLE] [--scope S] [--ssm-parameter PATH] --api-base URL'); process.exit(1)
417
649
  }
418
650
  if (cmd === 'permissions' && sub === 'machine-trust') {
419
651
  const trust = require('../src/commands/machine-trust')
@@ -434,6 +666,27 @@ async function main() {
434
666
  if (run) { console.log(JSON.stringify(await run(rest, flags), null, 2)); return }
435
667
  console.error('usage: saaslayer permissions access-admins <list|offer|status|cancel|accept|activate> [suid|transferId] --api-base URL'); process.exit(1)
436
668
  }
669
+ if (cmd === 'permissions' && sub === 'support-staff') {
670
+ const staff = require('../src/commands/support-staff')
671
+ const run = { grant: staff.supportStaffGrant, revoke: staff.supportStaffRevoke, list: staff.supportStaffList }[positional[2]]
672
+ if (run) { console.log(JSON.stringify(await run(positional.slice(3), flags), null, 2)); return }
673
+ console.error('usage: saaslayer permissions support-staff <grant|revoke|list> [suid] --mode view-only|act-as --api-base URL'); process.exit(1)
674
+ }
675
+ if (cmd === 'permissions' && sub === 'orgs') {
676
+ const orgs = require('../src/commands/permission-orgs')
677
+ if (positional[2] === 'create') { console.log(JSON.stringify(await orgs.orgCreate(positional.slice(3), flags), null, 2)); return }
678
+ if (positional[2] === 'members' && positional[3] === 'add') { console.log(JSON.stringify(await orgs.orgMemberAdd(positional.slice(4), flags), null, 2)); return }
679
+ if (positional[2] === 'hook-joinable' && positional[3] === 'set') { console.log(JSON.stringify(await orgs.orgHookJoinableSet(positional.slice(4), flags), null, 2)); return }
680
+ if (positional[2] === 'hook-joinable' && positional[3] === 'disable') { console.log(JSON.stringify(await orgs.orgHookJoinableDisable(positional.slice(4), flags), null, 2)); return }
681
+ console.error('usage: saaslayer permissions orgs <create <name> | members add <orgId> --user <suid> | hook-joinable set <orgId> --consumer <ref> --role <roleId> | hook-joinable disable <orgId>> --api-base URL [auth]'); process.exit(1)
682
+ }
683
+ if (cmd === 'permissions' && sub === 'api-keys') {
684
+ const keys = require('../src/commands/api-keys')
685
+ const rest = positional.slice(3)
686
+ const run = { create: keys.apiKeysCreate, list: keys.apiKeysList, get: keys.apiKeysGet, revoke: keys.apiKeysRevoke }[positional[2]]
687
+ if (run) { console.log(JSON.stringify(await run(rest, flags), null, 2)); return }
688
+ console.error('usage: saaslayer permissions api-keys <create|list|get|revoke> [keyId] (--deployment ID | --api-base URL) [auth]'); process.exit(1)
689
+ }
437
690
  if (cmd === 'permissions' && sub === 'trust-policies') {
438
691
  const tp = require('../src/commands/trust-policies')
439
692
  const rest = positional.slice(3)
@@ -441,10 +694,14 @@ async function main() {
441
694
  if (run) { console.log(JSON.stringify(await run(rest, flags), null, 2)); return }
442
695
  console.error('usage: saaslayer permissions trust-policies <list|get|add|update|disable|enable|delete> [policyId|issuerUrl] (--deployment ID | --api-base URL) [auth]'); process.exit(1)
443
696
  }
697
+ if (cmd === 'audit') {
698
+ if (sub === 'erase') { await require('../src/commands/audit').auditErase(positional.slice(2), flags); return }
699
+ console.error('usage: saaslayer audit erase <suid> [--email E …] (--iam PRINCIPAL | --token KEY) (--api-base URL | --deployment ID | --discovery-url URL)'); process.exit(1)
700
+ }
444
701
  if (cmd === 'users') {
445
702
  const users = require('../src/commands/users')
446
703
  if (sub === 'export') { await users.usersExport(flags); return }
447
- if (sub === 'import') { await users.usersImport(flags); return }
704
+ if (sub === 'import') { const result = await users.usersImport(flags); if (result.exitCode) process.exitCode = result.exitCode; return }
448
705
  if (sub === 'admin') { await require('../src/commands/users-management').usersManagement(positional[2], flags); return }
449
706
  if (users.ADMIN_COMMANDS.includes(sub)) { await users.usersAdmin(sub, positional.slice(2), flags); return }
450
707
  console.error(users.USAGE); process.exit(1)
@@ -559,8 +816,11 @@ async function main() {
559
816
  if (cmd === 'aws') {
560
817
  const aws = require('../src/commands/aws')
561
818
  if (sub === 'connect') { await aws.awsConnect(flags); return }
562
- console.error('usage: saaslayer aws connect --aws-account <id> [--region <r>] [--org-wide]'); process.exit(1)
819
+ if (sub === 'authorizers') { await aws.awsAuthorizers(positional[2], positional[3], flags); return }
820
+ if (sub === 'rotate-trust') { await aws.awsRotateTrust(positional[2], flags); return }
821
+ console.error('usage: saaslayer aws connect --aws-account <id> [--region <r>] [--org-wide] [--sms-toll-free]\n saaslayer aws authorizers <add|remove> <arn> --aws-account <id>\n saaslayer aws rotate-trust <start|verify|switch|retire|rollback|status> --aws-account <id>'); process.exit(1)
563
822
  }
823
+ if (cmd === 'sms') { const { smsCommand } = require('../src/commands/sms'); await smsCommand(sub, flags); return }
564
824
  if (cmd === 'foundation') {
565
825
  const foundation = require('../src/commands/foundation')
566
826
  if (sub === 'status') { await foundation.foundationStatus(flags); return }
@@ -569,11 +829,12 @@ async function main() {
569
829
  }
570
830
  if (cmd === 'admin' && sub === 'allowlist') {
571
831
  const allowlist = require('../src/commands/admin-allowlist')
572
- const run = { list: allowlist.allowlistList, add: allowlist.allowlistAdd, remove: allowlist.allowlistRemove }[positional[2]]
832
+ const run = { list: allowlist.allowlistList, add: allowlist.allowlistAdd, remove: allowlist.allowlistRemove, open: allowlist.allowlistOpen, close: allowlist.allowlistClose }[positional[2]]
573
833
  if (run) { await run(flags, positional[3]); return }
574
- console.error('usage: saaslayer admin allowlist <list|add <email>|remove <email>>'); process.exit(1)
834
+ console.error('usage: saaslayer admin allowlist <list|add <email>|remove <email>|open|close>'); process.exit(1)
575
835
  }
576
836
  if (cmd === 'stacks') { const { stacks } = require('../src/commands/stacks'); await stacks(flags); return }
837
+ if (cmd === 'versions') { const { versions } = require('../src/commands/versions'); await versions(flags); return }
577
838
  if (cmd === 'deploy') { const { deploy } = require('../src/commands/deploy'); await deploy(flags); return }
578
839
  if (cmd === 'status') { const { status } = require('../src/commands/lifecycle'); await status(flags); return }
579
840
  if (cmd === 'update') { const { update } = require('../src/commands/lifecycle'); await update(flags); return }
@@ -590,8 +851,20 @@ async function main() {
590
851
  }
591
852
  if (cmd === 'release-manifest') { const { releaseManifestCommand } = require('../src/commands/release-manifest'); await releaseManifestCommand(sub, flags); return }
592
853
  if (cmd === 'settings') { const { settingsCommand } = require('../src/commands/settings'); await settingsCommand(sub, flags); return }
854
+ if (cmd === 'social') { const { socialCommand } = require('../src/commands/social'); await socialCommand(sub, positional[2], flags); return }
855
+ if (cmd === 'login-domain') { const { loginDomainCommand } = require('../src/commands/login-domain'); await loginDomainCommand(sub, positional[2], flags); return }
856
+ if (cmd === 'hooks') { const { hooksCommand } = require('../src/commands/hooks'); await hooksCommand(sub, positional.slice(2), flags); return }
593
857
  if (cmd === 'first-admin') { const { firstAdminCommand } = require('../src/commands/first-admin'); await firstAdminCommand(sub, flags); return }
594
858
  if (cmd === 'activity') { const { activityCommand } = require('../src/commands/activity'); await activityCommand(flags); return }
859
+ if (cmd === 'bindings') {
860
+ const bindings = require('../src/commands/bindings')
861
+ if (sub === 'create') { await bindings.bindingsCreate(flags); return }
862
+ if (sub === 'list') { await bindings.bindingsList(flags); return }
863
+ if (sub === 'show') { await bindings.bindingsShow(flags, positional[2]); return }
864
+ if (sub === 'handoff') { await require('../src/commands/binding-handoff').bindingsHandoff(flags, positional[2], positional[3]); return }
865
+ console.error('usage: saaslayer bindings <create|list|show <bindingId>|handoff <step> <bindingId>> (see saaslayer --help)'); process.exit(1)
866
+ }
867
+ if (cmd === 'env' && sub === 'export') { await require('../src/commands/env-export').envExport(flags); return }
595
868
  if (cmd === 'credentials' && sub === 'status') { await require('../src/commands/integration-credentials').credentialsStatus(flags); return }
596
869
  if (cmd === 'credentials' && sub === 'revoke') { await require('../src/commands/integration-credentials').credentialsRevoke(flags); return }
597
870
  if (cmd === 'operations' || cmd === 'operation') { const { operationsCommand } = require('../src/commands/operations'); await operationsCommand(sub, positional[2], flags); return }