@zabaca/zbc 0.11.0 → 0.12.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zabaca/zbc",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "Zabaca stack CLI — scaffold and deploy infrastructure",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -206,7 +206,17 @@ const configSchema = z
206
206
  */
207
207
  serviceTokenPolicyName: z.string().min(1).optional(),
208
208
  /** Whether the application shows as a tile in the App Launcher. */
209
- appLauncherVisible: z.boolean().default(false),
209
+ /**
210
+ * Whether the application shows as a tile in the App Launcher.
211
+ *
212
+ * DEFAULTS TO TRUE, which is Cloudflare's own default and therefore what
213
+ * omitting the field has always meant. A PUT is a full replace, so "omit
214
+ * it" and "send the default" are the same act and there is no third option
215
+ * — which is why defaulting it to `false` (as this did until 2026-08-23)
216
+ * made the first apply of every migrating consumer a change to live state.
217
+ * An instance that wants the tile hidden says so.
218
+ */
219
+ appLauncherVisible: z.boolean().default(true),
210
220
  /**
211
221
  * Cloudflare's binding cookie. Off, matching Cloudflare's own default and
212
222
  * the module this replaces: a machine caller should never be handed one.
@@ -633,6 +643,70 @@ export function appBody(config: {
633
643
  }
634
644
  }
635
645
 
646
+ /**
647
+ * Which fields of the body disagree with the live application. Pure; exported
648
+ * for tests.
649
+ *
650
+ * ⚠️ EVERY KEY THE BODY CARRIES, and that is the whole point rather than a
651
+ * detail. Until 2026-08-23 this comparison was three hand-listed fields — name,
652
+ * domain, session duration — defended by a comment arguing that the module
653
+ * "declares more of the application than it can read back reliably", so a
654
+ * re-apply "reports honestly without silently accepting drift in a field nobody
655
+ * looked at".
656
+ *
657
+ * That rationale is sound and it covers the wrong case. It defends not
658
+ * comparing a field THE DASHBOARD might have changed. It says nothing about a
659
+ * field THIS MODULE writes from its own default on every single apply — which
660
+ * is not drift being accepted, it is a change being made and not reported. A
661
+ * correct-sounding rationale covering the wrong case is harder to spot than no
662
+ * rationale, and this one hid `app_launcher_visible` flipping a live
663
+ * application while the apply printed `unchanged`.
664
+ *
665
+ * So the answer to "compare it or stop writing it" is COMPARE IT, and the
666
+ * comparison is derived from the body rather than listed beside it: add a field
667
+ * to `appBody` and it is compared, with no second place to remember.
668
+ */
669
+ export function appDiffers(
670
+ desired: Record<string, unknown>,
671
+ live: Record<string, unknown>,
672
+ ): string[] {
673
+ return Object.keys(desired).filter((key) => {
674
+ const want = desired[key]
675
+ const have = live[key]
676
+ // The one field with an identity of its own: `https://Host/` and `host`
677
+ // are the same application, and reading them as different would make every
678
+ // apply a change.
679
+ if (key === 'domain') {
680
+ return normalizeDomain(String(want)) !== normalizeDomain(String(have ?? ''))
681
+ }
682
+ return JSON.stringify(want) !== JSON.stringify(have)
683
+ })
684
+ }
685
+
686
+ /**
687
+ * What the summary line says a person may sign in with. Pure; exported for
688
+ * tests.
689
+ *
690
+ * DECLARED AND UNDECLARED BOTH, because the question this answers is "can a
691
+ * person sign in", not "what did this instance declare". Reporting only the
692
+ * declared set meant that an instance declaring none — the recommended
693
+ * configuration when the organisation already offers what is needed, since
694
+ * declaring one converges nothing and needs write access over state every other
695
+ * application in the account shares — printed "nobody can sign in" three lines
696
+ * under its own report that two providers were offered and kept.
697
+ *
698
+ * The empty case still says nobody can, and that half is not incidental: an
699
+ * organisation really offering nothing must not be reassured by a fix aimed at
700
+ * a false alarm.
701
+ */
702
+ export function signInWith(providers: {
703
+ declared: readonly string[]
704
+ undeclared: readonly string[]
705
+ }): string {
706
+ const all = [...providers.declared, ...providers.undeclared]
707
+ return all.length > 0 ? all.join(', ') : '(nothing, so nobody can sign in)'
708
+ }
709
+
636
710
  /**
637
711
  * The application this instance converges, and how it was recognised.
638
712
  *
@@ -941,21 +1015,18 @@ export const cloudflareAccessModule = defineModule({
941
1015
  let app: CfApp
942
1016
  let appChanged: boolean
943
1017
  if (found) {
944
- // ALWAYS a PUT, even when the compared fields agree. This module declares
945
- // more of the application than it can read back reliably, and a converge
946
- // that skips the write leaves whatever the dashboard did to the fields it
947
- // does not compare. `changed` is computed from the compared subset
948
- // instead, so a re-apply reports honestly without silently accepting
949
- // drift in a field nobody looked at.
950
- appChanged =
951
- found.app.name !== config.name ||
952
- normalizeDomain(found.app.domain) !== domain ||
953
- (typeof found.app.session_duration === 'string' &&
954
- found.app.session_duration !== config.sessionDuration)
1018
+ // ALWAYS a PUT, even when everything agrees: a converge that skips the
1019
+ // write leaves whatever the dashboard did to the fields this module owns.
1020
+ // What it reports is now derived from the body it is about to send, so
1021
+ // every field it writes is a field it compares — see `appDiffers` for why
1022
+ // the previous three-field subset was worse than no comparison.
1023
+ const differing = appDiffers(body, found.app as unknown as Record<string, unknown>)
1024
+ appChanged = differing.length > 0
955
1025
  app = await cf<CfApp>(token, 'PUT', `${account}/access/apps/${found.app.id}`, body)
956
1026
  console.log(
957
1027
  ` Converged Access application "${config.name}" on ${domain} (${app.id}, matched by ` +
958
- `${found.by})`,
1028
+ `${found.by})` +
1029
+ (appChanged ? ` — changed ${differing.join(', ')}` : ''),
959
1030
  )
960
1031
  } else {
961
1032
  app = await cf<CfApp>(token, 'POST', `${account}/access/apps`, body)
@@ -1119,7 +1190,7 @@ export const cloudflareAccessModule = defineModule({
1119
1190
  if (app.aud) console.log(` audience ${app.aud}`)
1120
1191
  if (config.emails.length > 0) {
1121
1192
  console.log(
1122
- ` sign in with ${identityProviders.join(', ') || '(nothing, so nobody can sign in)'}`,
1193
+ ` sign in with ${signInWith({ declared: identityProviders, undeclared: undeclaredIdps })}`,
1123
1194
  )
1124
1195
  console.log(` admits ${config.emails.join(', ')}`)
1125
1196
  }