@farthershore/client 0.4.0 → 0.6.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.
package/dist/index.js CHANGED
@@ -1,9 +1,15 @@
1
1
  // ../contracts/dist/platform-authorization.js
2
- var PLATFORM_DEFAULT_ROLES = ["owner", "admin", "member"];
2
+ var PLATFORM_DEFAULT_ROLES = [
3
+ "owner",
4
+ "admin",
5
+ "member",
6
+ "subscriber"
7
+ ];
3
8
  function delegationAllowsMakerToken(delegation) {
4
9
  return delegation === "maker_token";
5
10
  }
6
- var ALL_ROLES = PLATFORM_DEFAULT_ROLES;
11
+ var BUILDER_ROLES = ["owner", "admin", "member"];
12
+ var BUILDER_ROLES_AND_SUBSCRIBER = PLATFORM_DEFAULT_ROLES;
7
13
  var OWNER_ADMIN = ["owner", "admin"];
8
14
  var OWNER_ONLY = ["owner"];
9
15
  var BUSINESS = ["business"];
@@ -44,7 +50,7 @@ var PLATFORM_PERMISSION_CATALOG = {
44
50
  "auth_provider_connection:read": permission("auth_provider_connection:read", {
45
51
  effect: "read",
46
52
  allowedTargetKinds: BUSINESS,
47
- defaultRoles: ALL_ROLES,
53
+ defaultRoles: BUILDER_ROLES,
48
54
  delegation: "browser_only"
49
55
  }),
50
56
  "auth_provider_connection:update": permission("auth_provider_connection:update", {
@@ -56,37 +62,19 @@ var PLATFORM_PERMISSION_CATALOG = {
56
62
  "agent:read": permission("agent:read", {
57
63
  effect: "read",
58
64
  allowedTargetKinds: BUSINESS,
59
- defaultRoles: ALL_ROLES,
60
- delegation: "maker_token"
61
- }),
62
- "agreement:amend": permission("agreement:amend", {
63
- effect: "write",
64
- allowedTargetKinds: BUSINESS,
65
- defaultRoles: OWNER_ADMIN,
66
- delegation: "maker_token"
67
- }),
68
- "agreement:create": permission("agreement:create", {
69
- effect: "write",
70
- allowedTargetKinds: BUSINESS,
71
- defaultRoles: OWNER_ADMIN,
72
- delegation: "maker_token"
73
- }),
74
- "agreement:read": permission("agreement:read", {
75
- effect: "read",
76
- allowedTargetKinds: BUSINESS,
77
- defaultRoles: ALL_ROLES,
65
+ defaultRoles: BUILDER_ROLES,
78
66
  delegation: "maker_token"
79
67
  }),
80
68
  "analytics:read": permission("analytics:read", {
81
69
  effect: "read",
82
70
  allowedTargetKinds: BUSINESS,
83
- defaultRoles: ALL_ROLES,
71
+ defaultRoles: BUILDER_ROLES,
84
72
  delegation: "maker_token"
85
73
  }),
86
74
  "apply_timeline:read": permission("apply_timeline:read", {
87
75
  effect: "read",
88
76
  allowedTargetKinds: BUSINESS,
89
- defaultRoles: ALL_ROLES,
77
+ defaultRoles: BUILDER_ROLES,
90
78
  delegation: "maker_token"
91
79
  }),
92
80
  "audit_log:export": permission("audit_log:export", {
@@ -98,13 +86,13 @@ var PLATFORM_PERMISSION_CATALOG = {
98
86
  "audit_log:read": permission("audit_log:read", {
99
87
  effect: "read",
100
88
  allowedTargetKinds: BUSINESS_OR_ORGANIZATION,
101
- defaultRoles: ALL_ROLES,
89
+ defaultRoles: BUILDER_ROLES,
102
90
  delegation: "maker_token"
103
91
  }),
104
92
  "auth_context:read": permission("auth_context:read", {
105
93
  effect: "read",
106
94
  allowedTargetKinds: SELF,
107
- defaultRoles: ALL_ROLES,
95
+ defaultRoles: BUILDER_ROLES_AND_SUBSCRIBER,
108
96
  delegation: "maker_token"
109
97
  }),
110
98
  "auth_context:issue": permission("auth_context:issue", {
@@ -128,7 +116,7 @@ var PLATFORM_PERMISSION_CATALOG = {
128
116
  "automation_rule:read": permission("automation_rule:read", {
129
117
  effect: "read",
130
118
  allowedTargetKinds: BUSINESS,
131
- defaultRoles: ALL_ROLES,
119
+ defaultRoles: BUILDER_ROLES,
132
120
  delegation: "maker_token"
133
121
  }),
134
122
  "automation_rule:update": permission("automation_rule:update", {
@@ -158,7 +146,17 @@ var PLATFORM_PERMISSION_CATALOG = {
158
146
  "backend:read": permission("backend:read", {
159
147
  effect: "read",
160
148
  allowedTargetKinds: BUSINESS,
161
- defaultRoles: ALL_ROLES,
149
+ defaultRoles: BUILDER_ROLES,
150
+ delegation: "maker_token"
151
+ }),
152
+ // CI spec upload (FAR-1490): the one authority a CI maker token needs to
153
+ // push a business's backend spec. Business-targeted, so a token holding it
154
+ // is also limited to the businesses it selects; it carries no plan, price,
155
+ // customer or secret authority.
156
+ "backend_spec:write": permission("backend_spec:write", {
157
+ effect: "write",
158
+ allowedTargetKinds: BUSINESS,
159
+ defaultRoles: OWNER_ADMIN,
162
160
  delegation: "maker_token"
163
161
  }),
164
162
  "brand:update": permission("brand:update", {
@@ -176,7 +174,7 @@ var PLATFORM_PERMISSION_CATALOG = {
176
174
  "bulletin:read": permission("bulletin:read", {
177
175
  effect: "read",
178
176
  allowedTargetKinds: BUSINESS,
179
- defaultRoles: ALL_ROLES,
177
+ defaultRoles: BUILDER_ROLES,
180
178
  delegation: "maker_token"
181
179
  }),
182
180
  "bulletin:resolve": permission("bulletin:resolve", {
@@ -201,7 +199,8 @@ var PLATFORM_PERMISSION_CATALOG = {
201
199
  effect: "write",
202
200
  allowedTargetKinds: BUSINESS,
203
201
  defaultRoles: OWNER_ADMIN,
204
- delegation: "maker_token"
202
+ humanOnly: true,
203
+ delegation: "browser_only"
205
204
  }),
206
205
  "business:docs_update": permission("business:docs_update", {
207
206
  effect: "write",
@@ -238,19 +237,13 @@ var PLATFORM_PERMISSION_CATALOG = {
238
237
  "business:read": permission("business:read", {
239
238
  effect: "read",
240
239
  allowedTargetKinds: BUSINESS_OR_ORGANIZATION,
241
- defaultRoles: ALL_ROLES,
242
- delegation: "maker_token"
243
- }),
244
- "business:rollback": permission("business:rollback", {
245
- effect: "write",
246
- allowedTargetKinds: BUSINESS,
247
- defaultRoles: OWNER_ADMIN,
240
+ defaultRoles: BUILDER_ROLES,
248
241
  delegation: "maker_token"
249
242
  }),
250
243
  "business_dependents:read": permission("business_dependents:read", {
251
244
  effect: "read",
252
245
  allowedTargetKinds: BUSINESS,
253
- defaultRoles: ALL_ROLES,
246
+ defaultRoles: BUILDER_ROLES,
254
247
  delegation: "maker_token"
255
248
  }),
256
249
  "business_variable:create": permission("business_variable:create", {
@@ -268,13 +261,13 @@ var PLATFORM_PERMISSION_CATALOG = {
268
261
  "business_variable:operation_read": permission("business_variable:operation_read", {
269
262
  effect: "read",
270
263
  allowedTargetKinds: BUSINESS,
271
- defaultRoles: ALL_ROLES,
264
+ defaultRoles: BUILDER_ROLES,
272
265
  delegation: "maker_token"
273
266
  }),
274
267
  "business_variable:read": permission("business_variable:read", {
275
268
  effect: "read",
276
269
  allowedTargetKinds: BUSINESS,
277
- defaultRoles: ALL_ROLES,
270
+ defaultRoles: BUILDER_ROLES,
278
271
  delegation: "maker_token"
279
272
  }),
280
273
  "business_variable:revoke": permission("business_variable:revoke", {
@@ -316,7 +309,7 @@ var PLATFORM_PERMISSION_CATALOG = {
316
309
  "consumer:read": permission("consumer:read", {
317
310
  effect: "read",
318
311
  allowedTargetKinds: BUSINESS,
319
- defaultRoles: ALL_ROLES,
312
+ defaultRoles: BUILDER_ROLES,
320
313
  delegation: "maker_token"
321
314
  }),
322
315
  "consumer:remove": permission("consumer:remove", {
@@ -334,7 +327,7 @@ var PLATFORM_PERMISSION_CATALOG = {
334
327
  "denial:read": permission("denial:read", {
335
328
  effect: "read",
336
329
  allowedTargetKinds: BUSINESS,
337
- defaultRoles: ALL_ROLES,
330
+ defaultRoles: BUILDER_ROLES,
338
331
  delegation: "maker_token"
339
332
  }),
340
333
  "environment:create": permission("environment:create", {
@@ -352,13 +345,13 @@ var PLATFORM_PERMISSION_CATALOG = {
352
345
  "environment:read": permission("environment:read", {
353
346
  effect: "read",
354
347
  allowedTargetKinds: BUSINESS,
355
- defaultRoles: ALL_ROLES,
348
+ defaultRoles: BUILDER_ROLES,
356
349
  delegation: "maker_token"
357
350
  }),
358
351
  "frontend:read": permission("frontend:read", {
359
352
  effect: "read",
360
353
  allowedTargetKinds: BUSINESS,
361
- defaultRoles: ALL_ROLES,
354
+ defaultRoles: BUILDER_ROLES,
362
355
  delegation: "maker_token"
363
356
  }),
364
357
  "frontend:rollback": permission("frontend:rollback", {
@@ -394,7 +387,7 @@ var PLATFORM_PERMISSION_CATALOG = {
394
387
  "knowledge:read": permission("knowledge:read", {
395
388
  effect: "read",
396
389
  allowedTargetKinds: BUSINESS_OR_SELF,
397
- defaultRoles: ALL_ROLES,
390
+ defaultRoles: BUILDER_ROLES,
398
391
  delegation: "maker_token"
399
392
  }),
400
393
  "maker_token:create": permission("maker_token:create", {
@@ -430,13 +423,13 @@ var PLATFORM_PERMISSION_CATALOG = {
430
423
  "notification:preferences_read": permission("notification:preferences_read", {
431
424
  effect: "read",
432
425
  allowedTargetKinds: BUSINESS,
433
- defaultRoles: ALL_ROLES,
426
+ defaultRoles: BUILDER_ROLES,
434
427
  delegation: "user_session_only"
435
428
  }),
436
429
  "notification:preferences_update": permission("notification:preferences_update", {
437
430
  effect: "write",
438
431
  allowedTargetKinds: BUSINESS,
439
- defaultRoles: ALL_ROLES,
432
+ defaultRoles: BUILDER_ROLES,
440
433
  delegation: "user_session_only"
441
434
  }),
442
435
  "organization:create": permission("organization:create", {
@@ -449,20 +442,21 @@ var PLATFORM_PERMISSION_CATALOG = {
449
442
  effect: "write",
450
443
  allowedTargetKinds: ORGANIZATION,
451
444
  defaultRoles: OWNER_ONLY,
452
- delegation: "user_session_only"
445
+ humanOnly: true,
446
+ delegation: "browser_only"
453
447
  }),
454
- // A human owner may transfer primary ownership from a signed-in CLI session
455
- // (`farthershore organization ownership-transfer`); a MakerToken never can.
448
+ // Ownership transfer requires a freshly verified person in the dashboard.
456
449
  "organization:ownership_transfer": permission("organization:ownership_transfer", {
457
450
  effect: "write",
458
451
  allowedTargetKinds: ORGANIZATION,
459
452
  defaultRoles: OWNER_ONLY,
460
- delegation: "user_session_only"
453
+ humanOnly: true,
454
+ delegation: "browser_only"
461
455
  }),
462
456
  "organization:read": permission("organization:read", {
463
457
  effect: "read",
464
458
  allowedTargetKinds: ORGANIZATION_OR_SELF,
465
- defaultRoles: ALL_ROLES,
459
+ defaultRoles: BUILDER_ROLES_AND_SUBSCRIBER,
466
460
  delegation: "maker_token"
467
461
  }),
468
462
  "organization:manage_billing": permission("organization:manage_billing", {
@@ -474,7 +468,7 @@ var PLATFORM_PERMISSION_CATALOG = {
474
468
  "organization_role:read": permission("organization_role:read", {
475
469
  effect: "read",
476
470
  allowedTargetKinds: ORGANIZATION,
477
- defaultRoles: ALL_ROLES,
471
+ defaultRoles: BUILDER_ROLES,
478
472
  delegation: "user_session_only"
479
473
  }),
480
474
  "organization_role:create": permission("organization_role:create", {
@@ -498,13 +492,13 @@ var PLATFORM_PERMISSION_CATALOG = {
498
492
  "organization_bulletin:read": permission("organization_bulletin:read", {
499
493
  effect: "read",
500
494
  allowedTargetKinds: ORGANIZATION,
501
- defaultRoles: ALL_ROLES,
495
+ defaultRoles: BUILDER_ROLES,
502
496
  delegation: "maker_token"
503
497
  }),
504
498
  "organization_invitation:accept": permission("organization_invitation:accept", {
505
499
  effect: "write",
506
500
  allowedTargetKinds: SELF,
507
- defaultRoles: ALL_ROLES,
501
+ defaultRoles: BUILDER_ROLES_AND_SUBSCRIBER,
508
502
  delegation: "user_session_only"
509
503
  }),
510
504
  "organization_invitation:create": permission("organization_invitation:create", {
@@ -519,7 +513,7 @@ var PLATFORM_PERMISSION_CATALOG = {
519
513
  // `organization` — the org's outstanding SENT invitations
520
514
  // (GET /builder/organizations/:orgId/invitations, team-tab redesign).
521
515
  allowedTargetKinds: ORGANIZATION_OR_SELF,
522
- defaultRoles: ALL_ROLES,
516
+ defaultRoles: BUILDER_ROLES,
523
517
  delegation: "user_session_only"
524
518
  }),
525
519
  "organization_invitation:revoke": permission("organization_invitation:revoke", {
@@ -531,16 +525,18 @@ var PLATFORM_PERMISSION_CATALOG = {
531
525
  "organization_member:list": permission("organization_member:list", {
532
526
  effect: "read",
533
527
  allowedTargetKinds: ORGANIZATION,
534
- defaultRoles: ALL_ROLES,
528
+ defaultRoles: BUILDER_ROLES,
535
529
  delegation: "user_session_only"
536
530
  }),
537
531
  "organization_member:remove": permission("organization_member:remove", {
532
+ humanOnlyWhen: "target_owner",
538
533
  effect: "write",
539
534
  allowedTargetKinds: ORGANIZATION,
540
535
  defaultRoles: OWNER_ADMIN,
541
536
  delegation: "user_session_only"
542
537
  }),
543
538
  "organization_member:update": permission("organization_member:update", {
539
+ humanOnlyWhen: "target_owner",
544
540
  effect: "write",
545
541
  allowedTargetKinds: ORGANIZATION,
546
542
  defaultRoles: OWNER_ADMIN,
@@ -555,7 +551,7 @@ var PLATFORM_PERMISSION_CATALOG = {
555
551
  "persona:read": permission("persona:read", {
556
552
  effect: "read",
557
553
  allowedTargetKinds: BUSINESS,
558
- defaultRoles: ALL_ROLES,
554
+ defaultRoles: BUILDER_ROLES,
559
555
  delegation: "maker_token"
560
556
  }),
561
557
  "persona:revoke": permission("persona:revoke", {
@@ -573,7 +569,7 @@ var PLATFORM_PERMISSION_CATALOG = {
573
569
  "plan:read": permission("plan:read", {
574
570
  effect: "read",
575
571
  allowedTargetKinds: BUSINESS,
576
- defaultRoles: ALL_ROLES,
572
+ defaultRoles: BUILDER_ROLES,
577
573
  delegation: "maker_token"
578
574
  }),
579
575
  // Subscriber-RBAC R1 — subscribing the ORG to an external product commits
@@ -617,7 +613,7 @@ var PLATFORM_PERMISSION_CATALOG = {
617
613
  "promo_code:read": permission("promo_code:read", {
618
614
  effect: "read",
619
615
  allowedTargetKinds: BUSINESS,
620
- defaultRoles: ALL_ROLES,
616
+ defaultRoles: BUILDER_ROLES,
621
617
  delegation: "maker_token"
622
618
  }),
623
619
  "promo_code:update": permission("promo_code:update", {
@@ -629,7 +625,7 @@ var PLATFORM_PERMISSION_CATALOG = {
629
625
  "rbac:read": permission("rbac:read", {
630
626
  effect: "read",
631
627
  allowedTargetKinds: BUSINESS,
632
- defaultRoles: ALL_ROLES,
628
+ defaultRoles: BUILDER_ROLES,
633
629
  delegation: "maker_token"
634
630
  }),
635
631
  "resource_count:report": permission("resource_count:report", {
@@ -647,7 +643,7 @@ var PLATFORM_PERMISSION_CATALOG = {
647
643
  "runtime_token:read": permission("runtime_token:read", {
648
644
  effect: "read",
649
645
  allowedTargetKinds: BUSINESS,
650
- defaultRoles: ALL_ROLES,
646
+ defaultRoles: BUILDER_ROLES,
651
647
  delegation: "maker_token"
652
648
  }),
653
649
  "runtime_token:revoke": permission("runtime_token:revoke", {
@@ -662,22 +658,27 @@ var PLATFORM_PERMISSION_CATALOG = {
662
658
  defaultRoles: OWNER_ADMIN,
663
659
  delegation: "maker_token"
664
660
  }),
665
- "stripe_connection:create": permission("stripe_connection:create", {
661
+ // Permanently closing (deleting) the organization Stripe Connect account
662
+ // is an irreversible, money-adjacent decision kept
663
+ // for a signed-in human owner in the dashboard: no CLI session, no MCP tool,
664
+ // no MakerToken. A deliberate exception to CLI/MCP authz parity, declared
665
+ // unavailable on the `stripe_connection.close` operation.
666
+ "stripe_connection:close": permission("stripe_connection:close", {
666
667
  effect: "write",
667
668
  allowedTargetKinds: ORGANIZATION,
668
669
  defaultRoles: OWNER_ONLY,
670
+ humanOnly: true,
669
671
  delegation: "browser_only"
670
672
  }),
671
- // Connecting Stripe is a browser-only OAuth/onboarding handshake, but reading
672
- // the connection state and disconnecting a per-business override are plain
673
- // owner actions a signed-in CLI session may run (`farthershore stripe
674
- // status|disconnect`). Neither is delegable to a MakerToken.
675
- "stripe_connection:delete": permission("stripe_connection:delete", {
673
+ "stripe_connection:create": permission("stripe_connection:create", {
676
674
  effect: "write",
677
675
  allowedTargetKinds: ORGANIZATION,
678
676
  defaultRoles: OWNER_ONLY,
679
- delegation: "user_session_only"
677
+ humanOnly: true,
678
+ delegation: "browser_only"
680
679
  }),
680
+ // Connecting Stripe is a browser-only OAuth/onboarding handshake, but reading
681
+ // connection status can be read by a signed-in CLI session.
681
682
  "stripe_connection:read": permission("stripe_connection:read", {
682
683
  effect: "read",
683
684
  allowedTargetKinds: ORGANIZATION,
@@ -687,7 +688,7 @@ var PLATFORM_PERMISSION_CATALOG = {
687
688
  "tax_settings:read": permission("tax_settings:read", {
688
689
  effect: "read",
689
690
  allowedTargetKinds: BUSINESS,
690
- defaultRoles: ALL_ROLES,
691
+ defaultRoles: BUILDER_ROLES,
691
692
  delegation: "maker_token"
692
693
  }),
693
694
  "tax_settings:update": permission("tax_settings:update", {
@@ -699,7 +700,7 @@ var PLATFORM_PERMISSION_CATALOG = {
699
700
  "usage:read": permission("usage:read", {
700
701
  effect: "read",
701
702
  allowedTargetKinds: BUSINESS,
702
- defaultRoles: ALL_ROLES,
703
+ defaultRoles: BUILDER_ROLES,
703
704
  delegation: "maker_token"
704
705
  }),
705
706
  "webhook:create": permission("webhook:create", {
@@ -723,13 +724,13 @@ var PLATFORM_PERMISSION_CATALOG = {
723
724
  "webhook:delivery_read": permission("webhook:delivery_read", {
724
725
  effect: "read",
725
726
  allowedTargetKinds: BUSINESS,
726
- defaultRoles: ALL_ROLES,
727
+ defaultRoles: BUILDER_ROLES,
727
728
  delegation: "maker_token"
728
729
  }),
729
730
  "webhook:read": permission("webhook:read", {
730
731
  effect: "read",
731
732
  allowedTargetKinds: BUSINESS,
732
- defaultRoles: ALL_ROLES,
733
+ defaultRoles: BUILDER_ROLES,
733
734
  delegation: "maker_token"
734
735
  }),
735
736
  "webhook:test": permission("webhook:test", {
@@ -771,6 +772,9 @@ function validatePlatformPermissionCatalog() {
771
772
  if (metadata.defaultRoles.length === 0) {
772
773
  throw new Error(`Platform permission has no default role: ${permission2}`);
773
774
  }
775
+ if (metadata.defaultRoles.includes("subscriber") && metadata.allowedTargetKinds.includes("business")) {
776
+ throw new Error(`The subscriber role must hold no business-targeting permission: ${permission2}`);
777
+ }
774
778
  }
775
779
  }
776
780
  validatePlatformPermissionCatalog();
@@ -1232,12 +1236,6 @@ var PLATFORM_OPERATION_DEFINITIONS = [
1232
1236
  },
1233
1237
  { key: "persona.rotate", class: "operate", domain: "personas" },
1234
1238
  { key: "persona.delete", class: "operate", domain: "personas" },
1235
- // FAR-910 — economic agreements are confirm-gated Core API/CLI operations,
1236
- // never repo-authored (plan §2): OPERATE. Amendments append versions; the
1237
- // agreement row itself is immutable.
1238
- { key: "agreement.read", class: "operate", domain: "agreements" },
1239
- { key: "agreement.create", class: "operate", domain: "agreements" },
1240
- { key: "agreement.amend", class: "operate", domain: "agreements" },
1241
1239
  { key: "analytics.timeseries", class: "operate", domain: "analytics" },
1242
1240
  { key: "analytics.latency", class: "operate", domain: "analytics" },
1243
1241
  { key: "analytics.top", class: "operate", domain: "analytics" },
@@ -1449,7 +1447,6 @@ var PLATFORM_OPERATION_DEFINITIONS = [
1449
1447
  { key: "business.routes.read", class: "contract", domain: "businesses" },
1450
1448
  { key: "business.contract.read", class: "contract", domain: "businesses" },
1451
1449
  { key: "business.publish", class: "operate", domain: "lifecycle" },
1452
- { key: "business.rollback", class: "operate", domain: "lifecycle" },
1453
1450
  {
1454
1451
  key: "manifest.apply",
1455
1452
  class: "contract",
@@ -1516,9 +1513,7 @@ var PLATFORM_OPERATION_DEFINITIONS = [
1516
1513
  domain: "authentication"
1517
1514
  })),
1518
1515
  // Connecting Stripe is a browser-only OAuth/onboarding handshake with Stripe
1519
- // (credential administration). Reading the connection and disconnecting a
1520
- // per-business override are ordinary owner actions backed by
1521
- // `farthershore stripe status|disconnect`.
1516
+ // (credential administration). Reading the organization connection is read-only.
1522
1517
  {
1523
1518
  key: "stripe_connection.create",
1524
1519
  class: "operate",
@@ -1528,7 +1523,27 @@ var PLATFORM_OPERATION_DEFINITIONS = [
1528
1523
  detail: "Connect Stripe from the signed-in dashboard (Connections or the business's Billing tab). The Stripe onboarding handshake is browser-only; check the result with `farthershore stripe status <business>`."
1529
1524
  }
1530
1525
  },
1531
- ...["read", "delete"].map((action) => ({
1526
+ {
1527
+ key: "stripe_connection.payout.update",
1528
+ class: "operate",
1529
+ domain: "billing",
1530
+ unavailable: {
1531
+ reason: "credential_administration",
1532
+ detail: "Change the payout account in the dashboard after signing in again and typing the organization name."
1533
+ }
1534
+ },
1535
+ // Closing (permanently deleting) a Stripe Connect account is browser-only by
1536
+ // product decision: the dashboard owner danger zone is the only surface.
1537
+ {
1538
+ key: "stripe_connection.close",
1539
+ class: "operate",
1540
+ domain: "billing",
1541
+ unavailable: {
1542
+ reason: "credential_administration",
1543
+ detail: "Close a Stripe account from the signed-in dashboard after signing in again and typing the name. Closing is permanent."
1544
+ }
1545
+ },
1546
+ ...["read"].map((action) => ({
1532
1547
  key: `stripe_connection.${action}`,
1533
1548
  class: "operate",
1534
1549
  domain: "billing"
@@ -1628,12 +1643,16 @@ var AGENT_OPERATION_AUTHORIZATIONS = {
1628
1643
  permission: "git_connection:update",
1629
1644
  targetKind: "organization"
1630
1645
  },
1631
- "stripe_connection.create": {
1646
+ "stripe_connection.payout.update": {
1632
1647
  permission: "stripe_connection:create",
1633
1648
  targetKind: "organization"
1634
1649
  },
1635
- "stripe_connection.delete": {
1636
- permission: "stripe_connection:delete",
1650
+ "stripe_connection.close": {
1651
+ permission: "stripe_connection:close",
1652
+ targetKind: "organization"
1653
+ },
1654
+ "stripe_connection.create": {
1655
+ permission: "stripe_connection:create",
1637
1656
  targetKind: "organization"
1638
1657
  },
1639
1658
  "stripe_connection.read": {
@@ -1645,12 +1664,6 @@ var AGENT_OPERATION_AUTHORIZATIONS = {
1645
1664
  "agents.list": { permission: "agent:read", targetKind: "business" },
1646
1665
  "agents.runs.show": { permission: "agent:read", targetKind: "business" },
1647
1666
  "agents.status": { permission: "agent:read", targetKind: "business" },
1648
- "agreement.amend": { permission: "agreement:amend", targetKind: "business" },
1649
- "agreement.create": {
1650
- permission: "agreement:create",
1651
- targetKind: "business"
1652
- },
1653
- "agreement.read": { permission: "agreement:read", targetKind: "business" },
1654
1667
  "analytics.latency": { permission: "analytics:read", targetKind: "business" },
1655
1668
  "analytics.log": { permission: "analytics:read", targetKind: "business" },
1656
1669
  "analytics.timeseries": {
@@ -2155,10 +2168,6 @@ var AGENT_OPERATION_AUTHORIZATIONS = {
2155
2168
  "brand.update": {
2156
2169
  permission: "brand:update",
2157
2170
  targetKind: "business"
2158
- },
2159
- "business.rollback": {
2160
- permission: "business:rollback",
2161
- targetKind: "business"
2162
2171
  }
2163
2172
  };
2164
2173
  var EXCLUDED_AGENT_REASONS = /* @__PURE__ */ new Set([
@@ -2221,7 +2230,7 @@ function validatePlatformOperationCatalog(operations) {
2221
2230
  if (operation2.agentVisibility === "excluded") {
2222
2231
  const core = AGENT_OPERATION_AUTHORIZATIONS[operation2.key];
2223
2232
  const validBoundary = operation2.unavailable !== void 0 && EXCLUDED_AGENT_REASONS.has(operation2.unavailable.reason);
2224
- const validEligibility = operation2.unavailable === void 0 && core !== void 0 && core.permission !== LOCAL_REPOSITORY_WRITE_PERMISSION && PLATFORM_PERMISSION_CATALOG[core.permission].delegation === "browser_only";
2233
+ const validEligibility = operation2.unavailable === void 0 && core !== void 0 && core.permission !== LOCAL_REPOSITORY_WRITE_PERMISSION && (PLATFORM_PERMISSION_CATALOG[core.permission].delegation === "browser_only" || isHumanOnlyOperation(operation2.key));
2225
2234
  if (operation2.authorization !== void 0 || !validBoundary && !validEligibility) {
2226
2235
  throw new Error(`Excluded operation ${operation2.key} has an invalid agent visibility binding`);
2227
2236
  }
@@ -2246,7 +2255,7 @@ var PLATFORM_OPERATIONS = PLATFORM_OPERATION_DEFINITIONS.map((operation2) => {
2246
2255
  };
2247
2256
  }
2248
2257
  const core = AGENT_OPERATION_AUTHORIZATIONS[operation2.key];
2249
- const excludedByPrincipalEligibility = core !== void 0 && core.permission !== LOCAL_REPOSITORY_WRITE_PERMISSION && PLATFORM_PERMISSION_CATALOG[core.permission].delegation === "browser_only";
2258
+ const excludedByPrincipalEligibility = core !== void 0 && core.permission !== LOCAL_REPOSITORY_WRITE_PERMISSION && (PLATFORM_PERMISSION_CATALOG[core.permission].delegation === "browser_only" || isHumanOnlyOperation(operation2.key));
2250
2259
  if (excludedByPrincipalEligibility) {
2251
2260
  return {
2252
2261
  ...operation2,
@@ -2277,6 +2286,13 @@ for (const key of Object.keys(AGENT_OPERATION_AUTHORIZATIONS)) {
2277
2286
  throw new Error(`Authorization binding references unknown operation: ${key}`);
2278
2287
  }
2279
2288
  }
2289
+ function operationAuthorizationFor(key) {
2290
+ return AGENT_OPERATION_AUTHORIZATIONS[key];
2291
+ }
2292
+ function isHumanOnlyOperation(key) {
2293
+ const permission2 = operationAuthorizationFor(key)?.permission;
2294
+ return permission2 !== void 0 && permission2 !== LOCAL_REPOSITORY_WRITE_PERMISSION && PLATFORM_PERMISSION_CATALOG[permission2].humanOnly === true;
2295
+ }
2280
2296
 
2281
2297
  // ../contracts/dist/operation-spec.js
2282
2298
  var SPECS = {
@@ -2378,7 +2394,7 @@ var SPECS = {
2378
2394
  preview: false,
2379
2395
  reconcile: { op: "business.read" }
2380
2396
  },
2381
- // DECISION: Stays NOT destructive: a publish is reversible with `business.rollback`, and the CLI keeps its own y/N prompt.
2397
+ // Publish keeps its explicit preview and the CLI confirmation prompt.
2382
2398
  "business.publish": {
2383
2399
  summary: "Publish a draft business (make it live) and cut a versioned release with an auto-computed semver. Requires at least one plan, a bound backend, and a verified Stripe connection",
2384
2400
  description: "Publish a business \u2014 validate its current spec and queue a versioned release with an auto-computed semver. Use business status to prove it is live.",
@@ -2387,15 +2403,6 @@ var SPECS = {
2387
2403
  preview: true,
2388
2404
  reconcile: { op: "business.status" }
2389
2405
  },
2390
- // DECISION: NEITHER side → destructive. Rollbacks are destructive: they replace the live release customers are served.
2391
- "business.rollback": {
2392
- summary: "Roll back a prior business publish workflow",
2393
- description: "Roll back a prior business publish workflow",
2394
- destructive: true,
2395
- oneTimeSecret: false,
2396
- preview: false,
2397
- reconcile: { op: "business.status" }
2398
- },
2399
2406
  "business.delete": {
2400
2407
  summary: "Permanently delete a business (stage only)",
2401
2408
  description: "(stage only) Permanently delete a business. Requires --yes. Registered only in the stage channel (`make cli-stage`); production businesses are deleted from the dashboard.",
@@ -2792,8 +2799,8 @@ var SPECS = {
2792
2799
  reconcile: { op: "promo_code.read" }
2793
2800
  },
2794
2801
  "consumer.read": {
2795
- summary: "List a business's consumers, one consumer's API keys, or its Managed-RBAC roles",
2796
- description: "Reads a business's consumers (subscribers). The same capability lists one consumer's API keys (metadata only; key material is never returned) and one subscriber's Managed-RBAC roles.",
2802
+ summary: "List a business's consumers, or read one consumer's API keys, balances or Managed-RBAC roles",
2803
+ description: "Reads a business's consumers (subscribers). The same capability lists one consumer's API keys (metadata only; key material is never returned), reads its usage-unit balances (exact amounts, with whether each read is live or an estimate), and lists one subscriber's Managed-RBAC roles.",
2797
2804
  destructive: false,
2798
2805
  oneTimeSecret: false,
2799
2806
  preview: false
@@ -2923,30 +2930,6 @@ var SPECS = {
2923
2930
  oneTimeSecret: false,
2924
2931
  preview: false
2925
2932
  },
2926
- "agreement.read": {
2927
- summary: "List or show a business's economic agreements and their pins",
2928
- description: "Lists a business's economic agreements, shows one agreement with its terms, and shows the agreement pins that bind subscribers to a version.",
2929
- destructive: false,
2930
- oneTimeSecret: false,
2931
- preview: false,
2932
- pagination: "offset"
2933
- },
2934
- "agreement.create": {
2935
- summary: "Create an economic agreement (previews first; commits with the confirmation token)",
2936
- description: "Create an economic agreement (confirm-gated: previews first; pass --confirm <token> to commit)",
2937
- destructive: false,
2938
- oneTimeSecret: false,
2939
- preview: false,
2940
- reconcile: { op: "agreement.read" }
2941
- },
2942
- "agreement.amend": {
2943
- summary: "Amend an agreement's contract terms (append-only; previews first; commits with the confirmation token)",
2944
- description: "Amend an agreement's contract terms (append-only; confirm-gated: previews first; pass --confirm <token> to commit)",
2945
- destructive: false,
2946
- oneTimeSecret: false,
2947
- preview: false,
2948
- reconcile: { op: "agreement.read" }
2949
- },
2950
2933
  "usage.read": {
2951
2934
  summary: "Show usage summary for the last 30 days",
2952
2935
  description: "Read a business's usage summary \u2014 request counts (all time and the last 30 days), active API keys, a per-member breakdown, and served requests that can never be rated. Without environmentId this rolls up EVERY environment. Read-only.",
@@ -3251,20 +3234,12 @@ var SPECS = {
3251
3234
  reconcile: { op: "org_maker_token.list" }
3252
3235
  },
3253
3236
  "stripe_connection.read": {
3254
- summary: "Show the Stripe connection a business bills through (business override or org default)",
3255
- description: "Read whether a business bills through a connected Stripe account \u2014 a per-business override when present, otherwise the organization default \u2014 and whether that account can take charges and card payments. Read-only. Connecting Stripe is browser-only and has no tool.",
3237
+ summary: "Show the organization Stripe connection a business bills through",
3238
+ description: "Read whether a business bills through its organization connected Stripe account and whether that account can take charges and card payments. Read-only. Connecting Stripe is browser-only and has no tool.",
3256
3239
  destructive: false,
3257
3240
  oneTimeSecret: false,
3258
3241
  preview: false
3259
3242
  },
3260
- "stripe_connection.delete": {
3261
- summary: "Remove a business's per-business Stripe override so it bills through the org default again",
3262
- description: "Remove a business's per-business Stripe Connect override so it bills through the organization default again. Refused while any subscription is still money-bearing. Destructive live-state operation; it does not edit repo-authored business behavior.",
3263
- destructive: true,
3264
- oneTimeSecret: false,
3265
- preview: false,
3266
- reconcile: { op: "stripe_connection.read" }
3267
- },
3268
3243
  "audit_log.read": {
3269
3244
  summary: "List organization or business-scoped audit-log rows",
3270
3245
  description: "List organization or business-scoped audit-log rows",
@@ -3687,6 +3662,9 @@ var STREAMING_EXEMPT_CONTENT_TYPE_SET = new Set(STREAMING_EXEMPT_CONTENT_TYPES);
3687
3662
 
3688
3663
  // ../contracts/dist/error-codes.js
3689
3664
  var ERROR_CODES = {
3665
+ MAINTENANCE_JOB_RETIRED: "MAINTENANCE_JOB_RETIRED",
3666
+ INVALID_USAGE_UNIT_LABEL: "INVALID_USAGE_UNIT_LABEL",
3667
+ HUMAN_ONLY_ACTION: "HUMAN_ONLY_ACTION",
3690
3668
  // --- Generic / cross-cutting ---------------------------------------
3691
3669
  VALIDATION_ERROR: "VALIDATION_ERROR",
3692
3670
  CONFLICT: "CONFLICT",
@@ -3709,6 +3687,9 @@ var ERROR_CODES = {
3709
3687
  DRY_RUN_NOT_SUPPORTED: "DRY_RUN_NOT_SUPPORTED",
3710
3688
  // --- Auth ---------------------------------------------------------
3711
3689
  UNAUTHORIZED: "UNAUTHORIZED",
3690
+ /** An internal service JWT whose jti was already used. The token is spent,
3691
+ * not invalid: the caller may retry once with a freshly minted token. */
3692
+ SERVICE_JWT_REPLAYED: "SERVICE_JWT_REPLAYED",
3712
3693
  FORBIDDEN: "FORBIDDEN",
3713
3694
  INVALID_ACCESS_KEY: "INVALID_ACCESS_KEY",
3714
3695
  AUTO_KEY_CREATION_FAILED: "AUTO_KEY_CREATION_FAILED",
@@ -3768,6 +3749,7 @@ var ERROR_CODES = {
3768
3749
  /** The owner role always holds every permission — it can never be edited,
3769
3750
  * reduced, or deleted, on either the builder or subscriber plane. */
3770
3751
  OWNER_ROLE_IMMUTABLE: "OWNER_ROLE_IMMUTABLE",
3752
+ SUBSCRIBER_ROLE_IMMUTABLE: "SUBSCRIBER_ROLE_IMMUTABLE",
3771
3753
  /** Floor→rows: the seeded account-role rows (`account_admin` /
3772
3754
  * `account_member`) replace the fixed bundles. They cannot be created,
3773
3755
  * deleted, renamed, or referenced from assignments/defaultRoleKey — and
@@ -3778,18 +3760,11 @@ var ERROR_CODES = {
3778
3760
  // --- Managed RBAC (Lane E, FAR-698) --------------------------------
3779
3761
  // Org-facing RBAC management APIs (/portal/.../me/rbac/*). All three
3780
3762
  // gates return before any RBAC state is read or written:
3781
- // - RBAC_REQUIRES_TEAM_ORG (400): legacy organization-type restriction;
3782
- // no longer emitted since Unified Organizations.
3783
3763
  // - RBAC_NOT_ENABLED_BY_PRODUCT (400): the accepted spec's
3784
3764
  // `product.rbac` is absent/false — the product never compiled the
3785
3765
  // `permission` constraint, so org role config would be inert.
3786
3766
  // UNKNOWN_PERMISSION (400) rejects role permissions outside the derived
3787
3767
  // catalog (`routePermission` grammar; `"*"` is always allowed).
3788
- /**
3789
- * @deprecated No longer emitted since Unified Organizations; kept one
3790
- * published release for SDK compat.
3791
- */
3792
- RBAC_REQUIRES_TEAM_ORG: "RBAC_REQUIRES_TEAM_ORG",
3793
3768
  RBAC_NOT_ENABLED_BY_PRODUCT: "RBAC_NOT_ENABLED_BY_PRODUCT",
3794
3769
  UNKNOWN_PERMISSION: "UNKNOWN_PERMISSION",
3795
3770
  // FAR-852 — a custom permission subject write collides with a reserved
@@ -3849,6 +3824,9 @@ var ERROR_CODES = {
3849
3824
  // --- Subscriptions / billing --------------------------------------
3850
3825
  BILLING_EVENT_NOT_FOUND: "BILLING_EVENT_NOT_FOUND",
3851
3826
  BILLING_NOT_CONFIGURED: "BILLING_NOT_CONFIGURED",
3827
+ // Their last period's invoice is unpaid after every retry, so this customer
3828
+ // cannot subscribe to this business again until it is paid.
3829
+ UNPAID_USAGE_INVOICE: "UNPAID_USAGE_INVOICE",
3852
3830
  SUBSCRIPTION_NOT_READY: "SUBSCRIPTION_NOT_READY",
3853
3831
  SUBSCRIPTION_FETCH_FAILED: "SUBSCRIPTION_FETCH_FAILED",
3854
3832
  // There is no paid, Stripe-managed subscription to end: the subscription is
@@ -3902,6 +3880,11 @@ var ERROR_CODES = {
3902
3880
  // someone connects Stripe, so "try again shortly" is never true here.
3903
3881
  STRIPE_NOT_CONNECTED: "STRIPE_NOT_CONNECTED",
3904
3882
  STRIPE_BALANCE_OUTSTANDING: "STRIPE_BALANCE_OUTSTANDING",
3883
+ // POST /builder/stripe/close (409): the Connect account cannot be closed
3884
+ // yet. `details.blockers` names every reason found — money-bearing
3885
+ // subscriptions, a non-zero Stripe balance, open disputes — so the
3886
+ // dashboard can explain all of them at once.
3887
+ STRIPE_ACCOUNT_CLOSE_BLOCKED: "STRIPE_ACCOUNT_CLOSE_BLOCKED",
3905
3888
  // A Stripe API call the route depended on failed (e.g. balance
3906
3889
  // retrieve or account delete during product disconnect). The human
3907
3890
  // `message` carries the upstream Stripe error text; the route blocks
@@ -4133,6 +4116,12 @@ function previewOperation(entry) {
4133
4116
  return { ...entry, preview: true };
4134
4117
  }
4135
4118
  function seg(value) {
4119
+ if (typeof value !== "string" || value === "" || value === "." || value === "..")
4120
+ throw new FartherShoreError(
4121
+ 'A path parameter must be a non-empty string other than "." or "..".',
4122
+ 400,
4123
+ { code: "INVALID_INPUT" }
4124
+ );
4136
4125
  return encodeURIComponent(value);
4137
4126
  }
4138
4127
  function withQuery(path, params) {
@@ -4218,75 +4207,6 @@ var agentOperations = {
4218
4207
  "bulletin.resolve": setStatus("bulletin.resolve", "resolved")
4219
4208
  };
4220
4209
 
4221
- // src/operations/agreements.ts
4222
- var agreements = (businessId) => `/businesses/${seg(businessId)}/agreements`;
4223
- var agreementOperations = {
4224
- "agreements.read": operation({
4225
- op: "agreement.read",
4226
- run: (ctx, { businessId, subjectId, environmentId, limit, offset }) => send(
4227
- ctx,
4228
- "GET",
4229
- withQuery(agreements(businessId), {
4230
- subjectId,
4231
- environmentId,
4232
- limit: num(limit),
4233
- offset: num(offset)
4234
- })
4235
- )
4236
- }),
4237
- "agreements.get": operation({
4238
- op: "agreement.read",
4239
- summary: "Show one economic agreement",
4240
- run: (ctx, { businessId, agreementId }) => send(ctx, "GET", `${agreements(businessId)}/${seg(agreementId)}`)
4241
- }),
4242
- "agreements.pins": operation({
4243
- op: "agreement.read",
4244
- summary: "Show the price pins in force for one subject",
4245
- run: (ctx, { businessId, subjectId }) => send(
4246
- ctx,
4247
- "GET",
4248
- `/businesses/${seg(businessId)}/subjects/${seg(subjectId)}/pins`
4249
- )
4250
- }),
4251
- "agreements.previewCreate": operation({
4252
- op: "agreement.create",
4253
- summary: "Preview a new agreement's effect and get its confirmation token",
4254
- sideEffect: "read",
4255
- run: (ctx, { businessId, body }) => send(
4256
- ctx,
4257
- "POST",
4258
- `${agreements(businessId)}/preview`,
4259
- body,
4260
- readOnly(ctx)
4261
- )
4262
- }),
4263
- "agreements.create": operation({
4264
- op: "agreement.create",
4265
- run: (ctx, { businessId, body }) => send(ctx, "POST", agreements(businessId), body)
4266
- }),
4267
- "agreements.previewAmend": operation({
4268
- op: "agreement.amend",
4269
- summary: "Preview an amendment's effect and get its confirmation token",
4270
- sideEffect: "read",
4271
- run: (ctx, { businessId, agreementId, body }) => send(
4272
- ctx,
4273
- "POST",
4274
- `${agreements(businessId)}/${seg(agreementId)}/amendments/preview`,
4275
- body,
4276
- readOnly(ctx)
4277
- )
4278
- }),
4279
- "agreements.amend": operation({
4280
- op: "agreement.amend",
4281
- run: (ctx, { businessId, agreementId, body }) => send(
4282
- ctx,
4283
- "POST",
4284
- `${agreements(businessId)}/${seg(agreementId)}/amendments`,
4285
- body
4286
- )
4287
- })
4288
- };
4289
-
4290
4210
  // src/operations/analytics.ts
4291
4211
  var runQuery = (ctx, businessId, body) => send(
4292
4212
  ctx,
@@ -4401,11 +4321,7 @@ var authOperations = {
4401
4321
  op: "auth.context.read",
4402
4322
  async run(ctx) {
4403
4323
  if (ctx.transport.credentialKind === "cli_exchange") {
4404
- const who2 = await send(
4405
- ctx,
4406
- "GET",
4407
- "/management/whoami"
4408
- );
4324
+ const who2 = await send(ctx, "GET", "/agent/v1/whoami");
4409
4325
  return who2.credentialType === "cli_session" ? { kind: "cli_user", ...who2 } : { kind: "maker", ...who2 };
4410
4326
  }
4411
4327
  const who = await send(
@@ -4424,7 +4340,7 @@ var authOperations = {
4424
4340
  const res = await send(
4425
4341
  ctx,
4426
4342
  "POST",
4427
- `/management/businesses/${seg(businessId)}/auth/context-token`,
4343
+ `/agent/v1/businesses/${seg(businessId)}/auth/context-token`,
4428
4344
  { ...data, actorType: "user" }
4429
4345
  );
4430
4346
  return res.data;
@@ -4514,23 +4430,12 @@ var billingOperations = {
4514
4430
  `/businesses/${seg(businessId)}/stripe/status`
4515
4431
  )
4516
4432
  }),
4517
- "billing.stripe.delete": operation({
4518
- op: "stripe_connection.delete",
4519
- run: (ctx, { businessId, deleteAccount }) => send(
4520
- ctx,
4521
- "POST",
4522
- `/businesses/${seg(businessId)}/stripe/disconnect`,
4523
- {
4524
- deleteAccount: deleteAccount === true
4525
- }
4526
- )
4527
- }),
4528
4433
  "billing.taxSettings.read": operation({
4529
4434
  op: "tax_settings.read",
4530
4435
  run: (ctx, { businessId }) => send(
4531
4436
  ctx,
4532
4437
  "GET",
4533
- `/management/businesses/${seg(businessId)}/tax-settings`
4438
+ `/agent/v1/businesses/${seg(businessId)}/tax-settings`
4534
4439
  )
4535
4440
  }),
4536
4441
  "billing.taxSettings.update": operation({
@@ -4538,7 +4443,7 @@ var billingOperations = {
4538
4443
  run: (ctx, { businessId, body }) => send(
4539
4444
  ctx,
4540
4445
  "POST",
4541
- `/management/businesses/${seg(businessId)}/tax-settings`,
4446
+ `/agent/v1/businesses/${seg(businessId)}/tax-settings`,
4542
4447
  body
4543
4448
  )
4544
4449
  })
@@ -4581,10 +4486,6 @@ var businessOperations = {
4581
4486
  op: "business.create",
4582
4487
  run: (ctx, data) => send(ctx, "POST", "/businesses", data)
4583
4488
  }),
4584
- "businesses.delete": operation({
4585
- op: "business.delete",
4586
- run: (ctx, { businessId }) => send(ctx, "DELETE", business(businessId))
4587
- }),
4588
4489
  "businesses.routes.read": operation({
4589
4490
  op: "business.routes.read",
4590
4491
  run: (ctx, { businessId, env }) => send(ctx, "GET", withQuery(`${business(businessId)}/routes`, { env }))
@@ -4612,7 +4513,7 @@ var businessOperations = {
4612
4513
  run: (ctx, { subdomain }) => send(
4613
4514
  ctx,
4614
4515
  "GET",
4615
- withQuery("/management/businesses/subdomain-availability", {
4516
+ withQuery("/agent/v1/businesses/subdomain-availability", {
4616
4517
  subdomain
4617
4518
  })
4618
4519
  )
@@ -4636,15 +4537,6 @@ var businessOperations = {
4636
4537
  Object.keys(body).length > 0 ? body : void 0
4637
4538
  )
4638
4539
  }),
4639
- "businesses.rollback": operation({
4640
- op: "business.rollback",
4641
- run: (ctx, { businessId, ...body }) => send(
4642
- ctx,
4643
- "POST",
4644
- `/management/businesses/${seg(businessId)}/rollback`,
4645
- body
4646
- )
4647
- }),
4648
4540
  // A retry may append another diagnostic compilation record; it never
4649
4541
  // applies or publishes the contract.
4650
4542
  "businesses.compile": operation({
@@ -4867,6 +4759,13 @@ var consumerOperations = {
4867
4759
  summary: "List one subscriber's API keys (metadata only)",
4868
4760
  run: (ctx, { businessId, subscriberId }) => send(ctx, "GET", `${consumer(businessId, subscriberId)}/api-keys`)
4869
4761
  }),
4762
+ // Exact amounts, whatever the plan's subscriber-facing disclosure. Each
4763
+ // balance says whether it was read live or is an estimate.
4764
+ "consumers.balance.read": operation({
4765
+ op: "consumer.read",
4766
+ summary: "Read one subscriber's usage-unit balances",
4767
+ run: (ctx, { businessId, subscriberId }) => send(ctx, "GET", `${consumer(businessId, subscriberId)}/balance`)
4768
+ }),
4870
4769
  "consumers.apiKeys.revoke": operation({
4871
4770
  op: "consumer.block",
4872
4771
  summary: "Revoke one subscriber API key",
@@ -4991,10 +4890,6 @@ var organizationOperations = {
4991
4890
  op: "organization.create",
4992
4891
  run: (ctx, data) => send(ctx, "POST", "/builder/organizations", data)
4993
4892
  }),
4994
- "organizations.delete": operation({
4995
- op: "organization.delete",
4996
- run: (ctx, { organizationId }) => send(ctx, "DELETE", org(organizationId))
4997
- }),
4998
4893
  "organizations.overview.read": operation({
4999
4894
  op: "organization.overview.read",
5000
4895
  run: (ctx, { organizationId }) => send(ctx, "GET", `${org(organizationId)}/overview`)
@@ -5065,12 +4960,6 @@ var organizationOperations = {
5065
4960
  `${org(organizationId)}/members/${seg(memberUserId)}`
5066
4961
  )
5067
4962
  }),
5068
- "organizations.ownership.transfer": operation({
5069
- op: "organization.ownership.transfer",
5070
- run: (ctx, { organizationId, newOwnerUserId }) => send(ctx, "POST", `${org(organizationId)}/ownership/transfer`, {
5071
- newOwnerUserId
5072
- })
5073
- }),
5074
4963
  "organizations.invitation.create": operation({
5075
4964
  op: "organization.invitation.create",
5076
4965
  run: (ctx, { organizationId, ...data }) => send(ctx, "POST", `${org(organizationId)}/invitations`, data)
@@ -5154,7 +5043,7 @@ var personaOperations = {
5154
5043
  };
5155
5044
 
5156
5045
  // src/operations/plans-usage.ts
5157
- var management = (businessId) => `/management/businesses/${seg(businessId)}`;
5046
+ var management = (businessId) => `/agent/v1/businesses/${seg(businessId)}`;
5158
5047
  var plansUsageOperations = {
5159
5048
  "plans.read": operation({
5160
5049
  op: "plan.read",
@@ -5196,7 +5085,7 @@ var plansUsageOperations = {
5196
5085
  };
5197
5086
 
5198
5087
  // src/operations/platform.ts
5199
- var management2 = (businessId) => `/management/businesses/${seg(businessId)}`;
5088
+ var management2 = (businessId) => `/agent/v1/businesses/${seg(businessId)}`;
5200
5089
  var rules = (businessId) => `/businesses/${seg(businessId)}/automation-rules`;
5201
5090
  var platformOperations = {
5202
5091
  "platform.resourceCounts.report": operation({
@@ -5385,6 +5274,14 @@ var portalOperations = {
5385
5274
  {}
5386
5275
  )
5387
5276
  }),
5277
+ "portal.balance.read": operation({
5278
+ op: null,
5279
+ // Amounts on a plan that discloses pricing; only the share of each
5280
+ // allowance used and left on an opaque plan.
5281
+ summary: "Read the signed-in subscriber's usage-unit balances",
5282
+ sideEffect: "read",
5283
+ run: (ctx, { businessId }) => portal(ctx, "GET", `${me(businessId)}/balance`)
5284
+ }),
5388
5285
  "portal.usageLimits.list": operation({
5389
5286
  op: null,
5390
5287
  pagination: "offset",
@@ -5515,7 +5412,7 @@ var variableOperations = {
5515
5412
  };
5516
5413
 
5517
5414
  // src/operations/webhooks.ts
5518
- var webhooks = (businessId) => `/management/businesses/${seg(businessId)}/webhooks`;
5415
+ var webhooks = (businessId) => `/agent/v1/businesses/${seg(businessId)}/webhooks`;
5519
5416
  var webhook = (businessId, webhookId) => `${webhooks(businessId)}/${seg(webhookId)}`;
5520
5417
  var sendTest = operation({
5521
5418
  op: "webhook.test",
@@ -5581,7 +5478,7 @@ var webhookOperations = {
5581
5478
  run: (ctx, { businessId }) => send(
5582
5479
  ctx,
5583
5480
  "GET",
5584
- `/management/businesses/${seg(businessId)}/webhook-event-types`
5481
+ `/agent/v1/businesses/${seg(businessId)}/webhook-event-types`
5585
5482
  )
5586
5483
  }),
5587
5484
  "webhooks.delivery.read": operation({
@@ -5618,7 +5515,6 @@ var webhookOperations = {
5618
5515
  // src/operations/index.ts
5619
5516
  var OPERATION_TABLE = {
5620
5517
  ...agentOperations,
5621
- ...agreementOperations,
5622
5518
  ...analyticsOperations,
5623
5519
  ...auditNotificationOperations,
5624
5520
  ...authOperations,
@@ -6082,8 +5978,7 @@ async function poll(options) {
6082
5978
  }
6083
5979
 
6084
5980
  // src/helpers/wait-for-frontend-build.ts
6085
- var FAILURE = /* @__PURE__ */ new Set(["FAILED", "CANCELLED"]);
6086
- var SUPERSEDED = "SUPERSEDED";
5981
+ var FAILURE = /* @__PURE__ */ new Set(["FAILED", "CANCELLED", "SUPERSEDED"]);
6087
5982
  async function waitForFrontendBuild(source, input) {
6088
5983
  const intervalMs = input.intervalMs ?? 5e3;
6089
5984
  const sleep = input.sleep ?? sleepFor;
@@ -6126,7 +6021,7 @@ async function waitForFrontendBuild(source, input) {
6126
6021
  }
6127
6022
  }
6128
6023
  const eligibleBuilds = input.buildId == null && input.ref === void 0 ? builds.filter((build) => !unpinnedBaselineIds.has(build.id)) : builds;
6129
- const row = (followId ? builds.find((b) => b.id === followId) : void 0) ?? eligibleBuilds[0];
6024
+ const row = followId ? builds.find((b) => b.id === followId) : eligibleBuilds[0];
6130
6025
  if (row) {
6131
6026
  const status = row.status;
6132
6027
  const rowId = row.id;
@@ -6143,12 +6038,6 @@ async function waitForFrontendBuild(source, input) {
6143
6038
  if (followId === null) followId = rowId;
6144
6039
  if (FAILURE.has(status)) return last;
6145
6040
  if (status === "SUCCEEDED" && last.activated) return last;
6146
- if (status === SUPERSEDED) {
6147
- const successor = eligibleBuilds.find(
6148
- (b) => b.ref === row.ref && b.id !== row.id
6149
- );
6150
- followId = successor ? successor.id : null;
6151
- }
6152
6041
  }
6153
6042
  if (now() >= deadline) return { ...last, timedOut: true };
6154
6043
  await sleep(Math.min(intervalMs, Math.max(0, deadline - now())), signal);
@@ -6199,7 +6088,7 @@ function diagnosticsOf(parsed) {
6199
6088
  }
6200
6089
 
6201
6090
  // src/version.ts
6202
- var CLIENT_VERSION = "0.4.0";
6091
+ var CLIENT_VERSION = "0.6.0";
6203
6092
  var CLIENT_PRODUCT = `@farthershore/client/${CLIENT_VERSION}`;
6204
6093
 
6205
6094
  // src/transport.ts
@@ -6247,11 +6136,11 @@ function withDryRun(path) {
6247
6136
  function supportsReadOnlyDryRun(method, path) {
6248
6137
  const pathname = path.split("?")[0];
6249
6138
  if (method.toUpperCase() === "PATCH")
6250
- return /^\/(?:businesses|management\/businesses|agent\/v1\/businesses)\/[^/]+\/backends\/[^/]+\/?$/.test(
6139
+ return /^\/(?:businesses|agent\/v1\/businesses)\/[^/]+\/backends\/[^/]+\/?$/.test(
6251
6140
  pathname
6252
6141
  );
6253
6142
  if (method.toUpperCase() !== "POST") return false;
6254
- return /^\/(?:businesses|management\/businesses|agent\/v1\/businesses)\/[^/]+\/backends\/?$/.test(
6143
+ return /^\/(?:businesses|agent\/v1\/businesses)\/[^/]+\/backends\/?$/.test(
6255
6144
  pathname
6256
6145
  ) || /^\/businesses\/[^/]+\/publish\/?$/.test(pathname) || /^\/businesses\/[^/]+\/frontend\/rollback\/?$/.test(pathname) || /^\/businesses\/[^/]+\/consumers\/[^/]+\/change-sets\/?$/.test(pathname) || /^\/agent\/v1\/(?:replay|rollback-to-config)\/?$/.test(pathname);
6257
6146
  }
@@ -6516,7 +6405,11 @@ function createTransport(options) {
6516
6405
  const credentials = options.credentials;
6517
6406
  const doFetch = (input, init) => (options.fetch ?? globalThis.fetch)(input, init);
6518
6407
  function baseHeaders() {
6519
- return { [SURFACE_HEADER]: surface, [CLIENT_HEADER]: clientHeader };
6408
+ return {
6409
+ [SURFACE_HEADER]: surface,
6410
+ [CLIENT_HEADER]: clientHeader,
6411
+ ...options.cliVersion ? { "x-farthershore-cli-version": options.cliVersion } : {}
6412
+ };
6520
6413
  }
6521
6414
  async function fetchWithRetry(url, init, policy, consume, retryEnabled = true) {
6522
6415
  const callerSignal = init.signal ?? void 0;
@@ -6885,12 +6778,14 @@ async function joinShared(shared, signal) {
6885
6778
  function isExchangeCredential(rawToken) {
6886
6779
  return rawToken.startsWith("fscli_") || rawToken.startsWith("mk_");
6887
6780
  }
6888
- function cliExchangeCredentials(rawToken) {
6889
- if (!isExchangeCredential(rawToken)) return bearerCredentials(rawToken);
6890
- const isUserCliCredential = rawToken.startsWith("fscli_");
6781
+ function cliExchangeCredentials(rawToken, options = {}) {
6782
+ const oauth = options.oauth === true && !isExchangeCredential(rawToken);
6783
+ if (!oauth && !isExchangeCredential(rawToken))
6784
+ return bearerCredentials(rawToken);
6785
+ const isUserCliCredential = oauth || rawToken.startsWith("fscli_");
6891
6786
  let cliAccess = null;
6892
6787
  let cliAccessRefreshAt = 0;
6893
- async function listCliOrganizations(context, signal, options) {
6788
+ async function listCliOrganizations(context, signal, options2) {
6894
6789
  if (!isUserCliCredential) {
6895
6790
  throw new FartherShoreError(
6896
6791
  "Organization switching requires a user CLI login.",
@@ -6904,14 +6799,14 @@ function cliExchangeCredentials(rawToken) {
6904
6799
  {
6905
6800
  headers: { Authorization: `Bearer ${rawToken}` },
6906
6801
  signal,
6907
- ...options?.retry === "none" ? { retry: "none" } : {}
6802
+ ...options2?.retry === "none" ? { retry: "none" } : {}
6908
6803
  },
6909
6804
  "read"
6910
6805
  );
6911
6806
  return data;
6912
6807
  }
6913
6808
  let organizationResolution = null;
6914
- function resolveExchangeOrganization(context, signal, options) {
6809
+ function resolveExchangeOrganization(context, signal, options2) {
6915
6810
  if (!isUserCliCredential) {
6916
6811
  return Promise.resolve(
6917
6812
  context.organizationId ?? context.requiredOrganizationId
@@ -6923,7 +6818,7 @@ function cliExchangeCredentials(rawToken) {
6923
6818
  return Promise.reject(requestAborted(error));
6924
6819
  }
6925
6820
  if (!organizationResolution) {
6926
- const resolution = lookUpExchangeOrganization(context, options);
6821
+ const resolution = lookUpExchangeOrganization(context, options2);
6927
6822
  organizationResolution = resolution;
6928
6823
  resolution.catch(() => {
6929
6824
  if (organizationResolution === resolution) {
@@ -6933,10 +6828,10 @@ function cliExchangeCredentials(rawToken) {
6933
6828
  }
6934
6829
  return joinShared(organizationResolution, signal);
6935
6830
  }
6936
- async function lookUpExchangeOrganization(context, options) {
6831
+ async function lookUpExchangeOrganization(context, options2) {
6937
6832
  const selector = context.organizationId ?? context.requiredOrganizationId;
6938
6833
  if (!selector) return void 0;
6939
- const available = await listCliOrganizations(context, void 0, options);
6834
+ const available = await listCliOrganizations(context, void 0, options2);
6940
6835
  const matches = available.organizations.filter(
6941
6836
  (organization) => organization.id === selector || organization.slug === selector
6942
6837
  );
@@ -6958,14 +6853,14 @@ function cliExchangeCredentials(rawToken) {
6958
6853
  return selected.id;
6959
6854
  }
6960
6855
  let exchangeInFlight = null;
6961
- function exchangeCliToken(context, signal, options) {
6856
+ function exchangeCliToken(context, signal, options2) {
6962
6857
  let flight = exchangeInFlight;
6963
6858
  if (!flight) {
6964
6859
  const controller = new AbortController();
6965
6860
  const created = {
6966
6861
  controller,
6967
6862
  waiters: 0,
6968
- promise: mintAccessToken(context, controller.signal, options)
6863
+ promise: mintAccessToken(context, controller.signal, options2)
6969
6864
  };
6970
6865
  const clear = () => {
6971
6866
  if (exchangeInFlight === created) exchangeInFlight = null;
@@ -7002,11 +6897,11 @@ function cliExchangeCredentials(rawToken) {
7002
6897
  leave(false);
7003
6898
  }
7004
6899
  }
7005
- async function mintAccessToken(context, signal, options) {
6900
+ async function mintAccessToken(context, signal, options2) {
7006
6901
  const organizationId = await resolveExchangeOrganization(
7007
6902
  context,
7008
6903
  signal,
7009
- options
6904
+ options2
7010
6905
  );
7011
6906
  const { data, headers, receivedAt } = await context.sendJson(
7012
6907
  "POST",
@@ -7018,7 +6913,7 @@ function cliExchangeCredentials(rawToken) {
7018
6913
  },
7019
6914
  body: organizationId ? JSON.stringify({ organizationId }) : void 0,
7020
6915
  signal,
7021
- ...options?.retry === "none" ? { retry: "none" } : {}
6916
+ ...options2?.retry === "none" ? { retry: "none" } : {}
7022
6917
  },
7023
6918
  "read"
7024
6919
  );
@@ -7057,14 +6952,14 @@ function cliExchangeCredentials(rawToken) {
7057
6952
  refreshable: true,
7058
6953
  getAccessToken,
7059
6954
  listOrganizations: listCliOrganizations,
7060
- async selectedOrganizationId(context, signal, options) {
6955
+ async selectedOrganizationId(context, signal, options2) {
7061
6956
  const selected = await resolveExchangeOrganization(
7062
6957
  context,
7063
6958
  signal,
7064
- options
6959
+ options2
7065
6960
  );
7066
6961
  if (selected) return selected;
7067
- if (!cliAccess) await exchangeCliToken(context, signal, options);
6962
+ if (!cliAccess) await exchangeCliToken(context, signal, options2);
7068
6963
  return cliAccess?.organizationId;
7069
6964
  }
7070
6965
  });