@topy-ai/maggie 0.7.38 → 0.7.41

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 (95) hide show
  1. package/README-zh-TW.md +82 -6
  2. package/README.md +99 -7
  3. package/bin/maggie.js +30 -3
  4. package/bundled-contracts/maggie-clone/interaction-state-v1.schema.json +26 -0
  5. package/bundled-contracts/maggie-content/provenance-v1.schema.json +20 -0
  6. package/bundled-contracts/maggie-design/brand-kit-v1.schema.json +18 -0
  7. package/bundled-contracts/maggie-design/browser-interactions-v1.schema.json +27 -0
  8. package/bundled-contracts/maggie-design/css-utility-evidence-v1.schema.json +10 -0
  9. package/bundled-contracts/maggie-design/dashboard-surface-v1.schema.json +11 -0
  10. package/bundled-contracts/maggie-design/progressive-enhancement-v1.schema.json +12 -0
  11. package/bundled-contracts/maggie-design/sample-surface-v1.schema.json +13 -0
  12. package/bundled-contracts/maggie-design/style-editing-v1.schema.json +35 -0
  13. package/bundled-contracts/maggie-media/image-generation-policy-v1.json +28 -0
  14. package/bundled-contracts/maggie-media/video-generation-policy-v1.json +40 -0
  15. package/bundled-contracts/maggie-media/video-job-v1.schema.json +20 -0
  16. package/bundled-contracts/maggie-media/video-playback-evidence-v1.schema.json +15 -0
  17. package/bundled-contracts/maggie-ops/npm11-preflight-v1.schema.json +17 -0
  18. package/bundled-contracts/maggie-scaffold/host-scaffold-v1.schema.json +25 -0
  19. package/bundled-contracts/maggie-seo/gsc-readiness-v1.schema.json +19 -0
  20. package/bundled-contracts/maggie-seo/privacy-origin-evidence-v1.schema.json +11 -0
  21. package/bundled-contracts/maggie-service-booking/delivery-provider-default-v1.json +8 -0
  22. package/bundled-contracts/maggie-service-booking/delivery-provider-v1.schema.json +16 -0
  23. package/bundled-contracts/maggiedash/booking-access-v1.json +5 -4
  24. package/bundled-contracts/maggiedash/booking-customer-surface-v1.json +12 -1
  25. package/bundled-contracts/maggiedash/booking-email-templates-v1.json +2 -0
  26. package/bundled-contracts/maggiedash/booking-host-adapter-v1.json +14 -2
  27. package/bundled-contracts/maggiedash/booking-runtime.v1.json +41 -0
  28. package/bundled-contracts/maggiedash/browser-session-v1.schema.json +18 -0
  29. package/bundled-contracts/maggiedash/content-overrides-v1.schema.json +19 -0
  30. package/bundled-contracts/maggiedash/execution-board.json +526 -26
  31. package/bundled-contracts/maggiedash/host-capabilities-v1.schema.json +10 -0
  32. package/bundled-contracts/maggiedash/public-session-cache-v1.schema.json +17 -0
  33. package/bundled-contracts/maggiedash/site-structure-v1.schema.json +13 -0
  34. package/bundled-references/browser-inspection.md +21 -0
  35. package/bundled-references/maggiedash-booking/ARCHITECTURE.md +218 -0
  36. package/bundled-references/maggiedash-booking/CURRENT-STATE.md +92 -0
  37. package/bundled-references/maggiedash-booking/DATA-FLOW.md +143 -0
  38. package/bundled-references/maggiedash-booking/DATA-MODEL.md +367 -0
  39. package/bundled-references/maggiedash-booking/DECISIONS.md +94 -0
  40. package/bundled-references/maggiedash-booking/EXECUTION-BOARD.json +2387 -0
  41. package/bundled-references/maggiedash-booking/HOST-ADAPTER.md +314 -0
  42. package/bundled-references/maggiedash-booking/ORAWELLNESS-INTEGRATION-AUDIT.md +227 -0
  43. package/bundled-references/maggiedash-booking/PAYMENT-GATEWAY.md +267 -0
  44. package/bundled-references/maggiedash-booking/PRD.md +228 -0
  45. package/bundled-references/maggiedash-booking/PROGRESS.md +2434 -0
  46. package/bundled-references/maggiedash-booking/QA-TEST-PLAN.md +235 -0
  47. package/bundled-references/maggiedash-booking/README.md +271 -0
  48. package/bundled-references/maggiedash-booking/RUNTIME-OPERATIONS.md +152 -0
  49. package/bundled-references/maggiedash-booking/SECURITY-COMPLIANCE.md +158 -0
  50. package/bundled-references/maggiedash-booking/SKILLS-AND-CLI.md +542 -0
  51. package/bundled-references/maggiedash-booking/STRIPE-INTEGRATION.md +129 -0
  52. package/bundled-references/maggiedash-booking/TASK-RUNBOOK.md +107 -0
  53. package/bundled-references/maggiedash-booking/TASKS.md +137 -0
  54. package/bundled-references/maggiedash-booking/USER-JOURNEYS.md +224 -0
  55. package/bundled-references/maggiedash-booking/diagrams/booking-dfd.excalidraw +1 -0
  56. package/bundled-references/maggiedash-booking/diagrams/booking-dfd.mmd +16 -0
  57. package/bundled-references/maggiedash-booking/diagrams/booking-dfd.png +0 -0
  58. package/bundled-references/maggiedash-booking/diagrams/booking-dfd.svg +1 -0
  59. package/bundled-references/maggiedash-booking/diagrams/booking-state-machine.mmd +19 -0
  60. package/bundled-references/maggiedash-booking/diagrams/booking-state-machine.png +0 -0
  61. package/bundled-references/maggiedash-booking/diagrams/booking-state-machine.svg +1 -0
  62. package/bundled-references/maggiedash-booking/diagrams/manager-journey.excalidraw +1 -0
  63. package/bundled-references/maggiedash-booking/diagrams/manager-journey.mmd +11 -0
  64. package/bundled-references/maggiedash-booking/diagrams/manager-journey.png +0 -0
  65. package/bundled-references/maggiedash-booking/diagrams/manager-journey.svg +1 -0
  66. package/bundled-references/maggiedash-booking/diagrams/payment-sequence.mmd +20 -0
  67. package/bundled-references/maggiedash-booking/diagrams/payment-sequence.png +0 -0
  68. package/bundled-references/maggiedash-booking/diagrams/payment-sequence.svg +1 -0
  69. package/bundled-references/maggiedash-booking/diagrams/system-context.excalidraw +1 -0
  70. package/bundled-references/maggiedash-booking/diagrams/system-context.mmd +10 -0
  71. package/bundled-references/maggiedash-booking/diagrams/system-context.png +0 -0
  72. package/bundled-references/maggiedash-booking/diagrams/system-context.svg +1 -0
  73. package/bundled-skills/maggie-blog/SKILL.md +12 -0
  74. package/bundled-skills/maggie-blog-bootstrap/SKILL.md +39 -0
  75. package/bundled-skills/maggie-booking/SKILL.md +112 -18
  76. package/bundled-skills/maggie-clone/SKILL.md +13 -0
  77. package/bundled-skills/maggie-deployment/SKILL.md +6 -0
  78. package/bundled-skills/maggie-design/SKILL.md +64 -3
  79. package/bundled-skills/maggie-ops/SKILL.md +12 -0
  80. package/bundled-skills/maggie-seo-geo/SKILL.md +45 -0
  81. package/bundled-skills/maggie-service-booking/SKILL.md +14 -0
  82. package/bundled-tools/clis/maggie_analytics.py +43 -1
  83. package/bundled-tools/clis/maggie_booking.py +161 -26
  84. package/bundled-tools/clis/maggie_browser_audit.py +99 -3
  85. package/bundled-tools/clis/maggie_clone.py +46 -1
  86. package/bundled-tools/clis/maggie_contracts.py +393 -0
  87. package/bundled-tools/clis/maggie_dash.py +22 -6
  88. package/bundled-tools/clis/maggie_design.py +84 -12
  89. package/bundled-tools/clis/maggie_service_booking.py +50 -1
  90. package/bundled-tools/clis/maggie_workflows.py +387 -0
  91. package/bundled-tools/clis/site_audit.py +77 -1
  92. package/bundled-tools/integrations/analytics.md +14 -0
  93. package/bundled-tools/runtime/site_baseline.py +3 -0
  94. package/package.json +1 -1
  95. package/references/browser-inspection.md +21 -0
@@ -0,0 +1,542 @@
1
+ # ai-cmo-skills support for Booking
2
+
3
+ This document turns the architecture into stable, repeatable checks for
4
+ Maggie users and implementers. Commands marked implemented are shipped in
5
+ `tools/clis/maggie_booking.py`; commands that need a real host runtime remain
6
+ explicit host-evidence gates and fail closed when that evidence is absent.
7
+
8
+ Current release baseline: MaggieDash `0.2.8`, commit `9d99de7` on
9
+ `origin/main`; the working tree includes the BK-100 dashboard-managed Stripe
10
+ connection slice and BK-099 cancellation-safe
11
+ package-credit restoration
12
+ extension. The local implementation and validators pass; the remaining
13
+ runtime/browser/ops evidence is tracked as BK-030/BK-031/BK-032 in the
14
+ [execution board](./EXECUTION-BOARD.json).
15
+
16
+ The installer fetches MaggieDash from its public GitHub source by default. A
17
+ fresh disposable Astro project was installed without `--source`, then passed
18
+ the installed host validator and `maggie booking inspect`; the public install
19
+ contains the 47-route Booking release, worker, schema, Astro host scaffold, and
20
+ blank-host SSR adapter/config fallback.
21
+
22
+ ## 1. Existing support
23
+
24
+ ### `maggie-service-booking`
25
+
26
+ Current support includes:
27
+
28
+ - provider catalogue import and sync;
29
+ - service, variant, price, duration, provider URL, and provenance validation;
30
+ - provider capability audit using sanitized fixtures;
31
+ - timezone-aware appointment input validation;
32
+ - worker/resolver evidence checks;
33
+ - booking-aware service-page generation gates;
34
+ - retirement and notification lifecycle contracts.
35
+
36
+ This is useful for catalog bootstrap and provider facts. It does not create a
37
+ local transactional booking engine, native availability, payment webhooks, or
38
+ manager booking screens.
39
+
40
+ ### `maggie-dash`
41
+
42
+ Current support includes:
43
+
44
+ - dashboard installation and diff planning;
45
+ - host adapter conformance evidence;
46
+ - migration preflight;
47
+ - UI/runtime evidence and panel audits;
48
+ - provider-neutral MaggieDash schema and dashboard contracts.
49
+ - manager-created multi-treatment appointments with per-segment service,
50
+ time, price, staff/resource allocation, same-location/currency validation,
51
+ transactional persistence, and idempotent replay.
52
+ - public multi-treatment customer holds and checkout with combined-duration
53
+ availability, safe segment DTOs, summed pricing, and segment-safe
54
+ token-bound rescheduling.
55
+ - blank-project location setup through the tenant-scoped Locations screen and
56
+ `locations.json` route, before catalogue/staff/resource/schedule setup.
57
+ - tenant-scoped prepaid treatment package catalogue management through the
58
+ `packages.json` read/write routes and Packages screen, plus customer package
59
+ entitlement grants, balance reads, and transactional manager/public-customer
60
+ redemption through `customer-packages.json` and public hold/checkout. Public package checkout,
61
+ Stripe reconciliation/webhook fulfillment, manager purchase listing, and
62
+ guarded package refunds are now separate payment flows.
63
+
64
+ The current installer keeps `_maggie/admin` as the dashboard target and can
65
+ auto-detect an Astro host. Booking host bootstrap is non-destructive: it adds
66
+ missing auth/routes/adapter/schema/worker files and idempotently merges the
67
+ Booking/login/register/reset rewrite block into a conventional existing
68
+ `src/middleware.ts` without replacing host auth or redirects.
69
+
70
+ ### Related existing skills
71
+
72
+ | Skill | Booking relationship |
73
+ |---|---|
74
+ | `maggie-project-context` | records project, domain, provider, and deployment decisions |
75
+ | `maggie-auth-reference` | keeps email/password session and server-only provider credentials consistent |
76
+ | `maggie-ops` | supplies operational dashboard, audit, health, and recovery patterns |
77
+ | `maggie-deployment` | carries migration, runtime, and release evidence into deployment |
78
+ | `maggie-qa-workflow` | validates browser behavior and host evidence |
79
+ | `maggie-memory` | records durable implementation learnings only after confirmation |
80
+ | `maggie-service-booking` | supplies catalogue/provider facts and booking-link fallback |
81
+
82
+ ## 2. Implemented skill surface
83
+
84
+ The general skill is:
85
+
86
+ ```text
87
+ maggie-booking
88
+ ```
89
+
90
+ Implemented responsibilities:
91
+
92
+ 1. inspect the installed workspace, root artifacts, adapter, and schema;
93
+ 2. validate the provider-neutral host contract and email/password boundary;
94
+ 3. validate the administrator-only Booking access contract for staff roles,
95
+ granular permissions, Resend invitations, password reset, and revocation;
96
+ 4. validate sanitized runtime endpoint observations;
97
+ 5. run a read-only release gate over the installed workspace and contract;
98
+ 6. record failures through the existing feedback/memory workflow without
99
+ writing active memory automatically.
100
+
101
+ The skill must not auto-enable native booking or payment writes. Applying a
102
+ migration, configuring a provider, or changing public booking behavior remains
103
+ an explicit confirmation step.
104
+
105
+ ## 3. Stable CLI
106
+
107
+ The implementation lives under `tools/clis/maggie_booking.py` and is dispatched
108
+ by `tools/clis/maggie.py`.
109
+
110
+ ### Inspect and plan
111
+
112
+ ```bash
113
+ maggie booking install --project . --confirm
114
+ maggie booking install --project . --host astro --dry-run
115
+ maggie booking install --project . --confirm --install-dependencies
116
+ maggie booking install --project . --confirm --bootstrap
117
+ maggie booking install --project . --confirm --bootstrap --schedule systemd
118
+ maggie booking worker-schedule --project . --scheduler cron --confirm
119
+ maggie booking inspect --project .
120
+ maggie booking setup --project .
121
+ maggie booking access-contract
122
+ maggie booking email-templates-contract
123
+ maggie booking contract
124
+ ```
125
+
126
+ `maggie booking install` delegates to the MaggieDash distribution installer.
127
+ For Astro it installs the manager/public pages, email/password login and
128
+ first-owner registration, server-side PostgreSQL/Stripe adapter, middleware
129
+ rewrite, schema command, Resend worker, and `.env.maggie-booking.example`.
130
+ The default `--host auto` only selects Astro when `package.json` or `src/**/*.astro`
131
+ proves it. Existing files are preserved; `--force` is required to replace
132
+ them. A conventional existing middleware is merged automatically, including
133
+ the common destructured `defineMiddleware(({ url, request }, next) => {})`
134
+ form; an unsupported middleware shape is preserved, recorded in install state, and
135
+ causes `maggie booking inspect` to fail until the rewrite is integrated.
136
+ The command still does not apply SQL, create an account, send an email, or
137
+ configure Stripe.
138
+
139
+ `--install-dependencies` is an explicit host mutation for a fresh Astro
140
+ project. It detects the existing npm/pnpm/yarn/bun lockfile and adds only the
141
+ missing React, Phosphor, Tailwind, PostgreSQL, Stripe, and SSR adapter packages
142
+ required by the Booking scaffold. A blank Astro host gets `@astrojs/node` and
143
+ an `astro.config.mjs` server config; a host with an existing
144
+ `astro.config.*`/deployment adapter keeps that host-owned choice. It is
145
+ incompatible with `--dry-run`, `--diff`, and without `--confirm`; existing
146
+ dependency versions are preserved.
147
+
148
+ For a new host where the database migration has already been reviewed and
149
+ approved, `--ready` is the convenience form of
150
+ `--install-dependencies --bootstrap`:
151
+
152
+ ```bash
153
+ maggie booking install --project . --confirm --ready
154
+ ```
155
+
156
+ It installs missing host packages, creates the implementation-only booking
157
+ token when the local environment permits it, and applies the idempotent
158
+ Booking schema. It does not create the first owner, configure Stripe, send a
159
+ Resend email, enable systemd/cron, or deploy. `--ready --schedule systemd`
160
+ or `--ready --schedule cron` only writes reviewable scheduler artifacts.
161
+
162
+ For a blank project, complete setup in this order after the schema and owner
163
+ exist: create the first location in Booking → Locations, then add services and
164
+ treatments, staff/resources, and schedule rules. The location form validates
165
+ the IANA timezone and keeps the write idempotent; it does not depend on
166
+ `location-1` or another fixture ID.
167
+
168
+ `--bootstrap` is the explicit exception for a reviewed new host: after the
169
+ files are installed, it runs the host-provided
170
+ `scripts/maggie-booking-schema.mjs --apply --confirm` from the project with the
171
+ existing environment. When the host uses a local `.env`, it generates the
172
+ implementation-only `BOOKING_TOKEN_SECRET` if absent, never replaces an
173
+ existing value, and refuses a configured value shorter than 32 characters.
174
+ External secret stores must be provisioned separately. It still does not
175
+ create an owner, configure Stripe, send email, or deploy. Do not use it before
176
+ backup/migration approval.
177
+
178
+ `--schedule systemd` generates a reviewed `deploy/maggie-booking-worker.service`
179
+ and `.timer`; `maggie booking worker-schedule --scheduler cron` generates a
180
+ cron artifact instead. These commands do not edit crontab, enable systemd, or
181
+ start a worker. Review the service user and enable the scheduler only after
182
+ schema, backup/restore, and host evidence gates pass.
183
+
184
+ The installed host schema command also supports a safe permission preflight:
185
+
186
+ ```bash
187
+ node scripts/maggie-booking-schema.mjs --dry-run
188
+ ```
189
+
190
+ It runs the core schema and Booking schema first, then applies an optional
191
+ `maggiedash/schema/host-extensions.sql` supplied by the host, all inside a
192
+ transaction that is rolled back. This catches missing PostgreSQL permissions
193
+ such as `btree_gist` without changing the host database; only
194
+ `--apply --confirm` commits the migration.
195
+
196
+ All commands in this section are read-only. `inspect` reports whether
197
+ `_maggie/booking`, the installed manager and public customer contracts, the
198
+ starter schema, runtime/customer-flow validators, and the installer state
199
+ exist. `setup` adds a safe first-run checklist for required environment-key
200
+ presence and explicit next steps for schema application, first-owner
201
+ registration, Stripe webhooks, and the Resend worker. It never prints secret
202
+ values and does not connect to PostgreSQL or mutate the host. It validates the
203
+ 32-character minimum for `BOOKING_TOKEN_SECRET`, reports a partially
204
+ configured Stripe key pair as degraded, and reports a complete pair as
205
+ `online-payments-pending-verification` until the signed-in manager runs the
206
+ server-side Verify Stripe connection action.
207
+ `setup` reports a complete deployment Stripe key pair as
208
+ `online-payments-pending-verification`; when no deployment Stripe keys are
209
+ present it reports `dashboard-or-host-secret-pending` and points the signed-in
210
+ owner/manager to the secure Booking Overview connection form. A partial
211
+ deployment pair remains `degraded` because the dashboard form is intentionally
212
+ not allowed to override deployment-managed credentials.
213
+ `contract` accepts both the source contract JSON Schema and the compact
214
+ ai-cmo-skills contract representation. It never reads secrets or customer data.
215
+
216
+ `email-templates-contract` validates the tenant-scoped Resend template
217
+ boundary: ten event keys, including package purchase confirmation/refund and
218
+ no-show fee notification,
219
+ event-specific `{{variable}}` allowlists,
220
+ owner/admin/manager access, audited idempotent mutations, 50,000-character
221
+ HTML limits, and the rule that provider credentials and recipient data remain
222
+ server-only. It is a static contract check; it does not send email.
223
+
224
+ Maintainers must also validate the artifact that npm users will receive, not
225
+ only the source checkout:
226
+
227
+ ```bash
228
+ node scripts/validate-cli-package.mjs
229
+ node scripts/validate-cli-package.mjs --project /home/balalior/Dev/clients/orawellness.uk
230
+ ```
231
+
232
+ After publishing, verify the package served by npm rather than relying only
233
+ on the local tarball:
234
+
235
+ ```bash
236
+ node scripts/verify-published-cli.mjs --version 0.7.39
237
+ ```
238
+
239
+ `scripts/publish-npm.mjs` runs this registry verification automatically after
240
+ `npm publish`; it fails the release if the published Booking contracts are
241
+ stale or incomplete.
242
+
243
+ This regenerates the bundled contracts/tools, packages the Booking runbook and
244
+ sanitized runtime fixture, rewrites repository-only links, packs the exact npm
245
+ tarball, and runs the packaged `booking contract`, access, email-template,
246
+ task-board, and optional host-inspect checks. It is read-only with respect to
247
+ hosts and never publishes the package.
248
+
249
+ The installer inspector accepts both contract representations used by the
250
+ distribution: the compact installed form and the JSON Schema source form with
251
+ `properties` plus endpoint inventory. This keeps a fresh MaggieDash source
252
+ install and an installed project on the same auth, endpoint, idempotency, and
253
+ privacy checks.
254
+
255
+ The installed Booking manager workspace includes an Email templates screen.
256
+ Managers can edit a draft, inspect a sandboxed preview, publish a new version,
257
+ and roll back a prior version. The worker resolves the latest published row by
258
+ project and event, then falls back to the provider-neutral template when no
259
+ tenant override exists. Template values are escaped before the Resend request;
260
+ the outbox remains responsible for retry, dead-letter, and replay state.
261
+
262
+ The worker cycle also runs `match-waitlist` between availability refresh and
263
+ reminder enqueue. It requires explicit service/location scope in the worker
264
+ availability snapshot; the Astro scaffold accepts
265
+ `BOOKING_WAITLIST_SERVICE_VARIANT_ID`, `BOOKING_WAITLIST_LOCATION_ID`,
266
+ `BOOKING_WAITLIST_SERVICE_NAME`, and `BOOKING_WAITLIST_LOCATION_NAME`. Matching
267
+ is priority-first with FIFO tie-breaking, persists a one-time offered slot, and
268
+ only queues `booking.waitlist.available`; it never auto-creates or reserves a
269
+ booking.
270
+
271
+ ### Runtime and release gates
272
+
273
+ ```bash
274
+ maggie booking runtime-validate --project . \
275
+ --contract maggiedash/contracts/booking-host-adapter-v1.json \
276
+ --evidence .maggie/booking-runtime.json
277
+
278
+ maggie booking release-gate --project . --require-runtime \
279
+ --contract maggiedash/contracts/booking-host-adapter-v1.json \
280
+ --evidence .maggie/booking-runtime.json
281
+ ```
282
+
283
+ `runtime-validate` requires one sanitized 2xx observation for every declared
284
+ endpoint, exact endpoint cardinality, an ISO timestamp, a dedicated tenant,
285
+ and no sensitive evidence keys. `release-gate` verifies the contract,
286
+ installed workspace, starter schema, and optional/required runtime evidence. It
287
+ fails closed when `--require-runtime` is used. It does not run migrations,
288
+ create bookings, capture/refund payments, or deploy.
289
+
290
+ Before a host session is used, `npm run booking:runtime:plan:test` checks that
291
+ the runtime plan covers every contract endpoint, uses concrete path parameters
292
+ where needed, retains required query parameters, supplies mutation bodies, and
293
+ rejects routes outside the `/api/maggie/booking` contract.
294
+
295
+ The public customer contract has its own source/install validator:
296
+
297
+ ```bash
298
+ npm run booking:customer-flow:test
299
+ ```
300
+
301
+ It covers public DTO redaction, catalog/availability, hold input, pending
302
+ payment-return recovery, notification intents, no-store/noindex responses,
303
+ mutation idempotency, and fail-closed tenant binding. It does not claim that a
304
+ host has configured rate limits, bot controls, a payment provider, or email
305
+ delivery.
306
+
307
+ The customer reference-host validator additionally exercises a two-treatment
308
+ hold, combined-duration availability, summed checkout pricing, and a
309
+ token-bound multi-treatment reschedule. PostgreSQL-core validation verifies
310
+ that the manager repository shifts each segment and allocation independently;
311
+ these are lifecycle regressions, not production-host evidence.
312
+
313
+ The manager UI configuration gate also verifies install-time data binding:
314
+ catalog reads expose tenant locations, schedule reads expose staff-visible
315
+ locations, and staff/resource forms derive service/location defaults from those
316
+ responses. It rejects the old fixture `location-1`/`service-1` fallbacks, which
317
+ would make a fresh host appear installed while posting IDs that do not exist in
318
+ the tenant database.
319
+
320
+ Exercise the full public journey against the secret-free reference host:
321
+
322
+ ```bash
323
+ npm run booking:customer-reference-host:test
324
+ ```
325
+
326
+ This checks the public catalog, availability, hold replay, checkout pending
327
+ state, payment-return recovery, token-bound cancel, manager-session isolation,
328
+ and notification intents. It does not replace real host evidence.
329
+
330
+ Validate the host-owned operational proof separately:
331
+
332
+ ```bash
333
+ maggie booking ops-validate --evidence .maggie/booking/ops-evidence.json
334
+ ```
335
+
336
+ The ops evidence contract requires sanitized proof for backup/restore,
337
+ delivery of all seven stable health alert codes, and a recovery rehearsal
338
+ (rollback write guard, worker restart, and outbox replay). The command checks
339
+ the artifact only; it does not run a backup, page an operator, or mutate the
340
+ host. Use `--require-host` for a release artifact; it rejects fixture, test,
341
+ and local environments and requires every timestamp/boolean proof field.
342
+ The installed MaggieDash package also ships the manual
343
+ `.github/workflows/booking-ops-evidence.yml` workflow for validating a
344
+ sanitized host artifact from an environment-scoped secret.
345
+
346
+ For the final release gate, require that proof explicitly:
347
+
348
+ ```bash
349
+ maggie booking release-gate --project . --require-runtime \
350
+ --evidence .maggie/booking/runtime-evidence.json \
351
+ --require-browser \
352
+ --browser-evidence .maggie/booking/browser/evidence.json \
353
+ --require-ops \
354
+ --ops-evidence .maggie/booking/ops-evidence.json \
355
+ --require-board
356
+ ```
357
+
358
+ `--require-ops` fails closed until the sanitized operational artifact passes
359
+ the versioned ops contract. This keeps BK-030 evidence in the same final
360
+ decision as the runtime, browser, and execution-board gates.
361
+
362
+ When an explicitly supplied runtime, browser, or ops artifact is missing or
363
+ malformed, `release-gate` returns a structured `blocked` JSON result with the
364
+ affected evidence status set to `failed` and an actionable read error. It does
365
+ not crash before printing the release decision, which keeps CI artifacts and
366
+ task progress machine-readable.
367
+
368
+ The browser portion also requires the 390/768/1440 viewport set, safe
369
+ screenshots, ready routes, empty console/request errors, and an empty
370
+ `layoutErrors` array for horizontal overflow.
371
+
372
+ The MaggieDash source repository also exposes the implementation gates used by
373
+ the task board:
374
+
375
+ ```bash
376
+ npm run booking:ui:test
377
+ npm run booking:security:test
378
+ npm run booking:route-handler:test
379
+ npm run booking:service-contract:test
380
+ npm run booking:worker-adapter:test
381
+ npm run booking:postgres-repository:test
382
+ npm run booking:health:test
383
+ ```
384
+
385
+ With a disposable or approved staging PostgreSQL URL and a host-installed
386
+ `pg` dependency, run the real repository cycle:
387
+
388
+ ```bash
389
+ npm run booking:postgres-repository:integration -- \
390
+ --database-url "$DATABASE_URL" --confirm
391
+ ```
392
+
393
+ The integration gate creates and removes one uniquely-prefixed test tenant; it
394
+ must never target an unapproved production database.
395
+
396
+ The backup/restore rehearsal is a separate explicit two-database command. It
397
+ requires an empty target database with no public application tables, rejects a
398
+ non-empty target without modifying it, does not clean either database, and
399
+ compares protected table row counts after a custom-format dump and restore.
400
+ `pg_dump` and `pg_restore` must be the same major version and match or exceed
401
+ both server major versions; use `--pg-bin-dir` when the matching client is not
402
+ the first client on `PATH`:
403
+
404
+ ```bash
405
+ npm run booking:postgres-backup-restore:integration -- \
406
+ --source-database-url "$DATABASE_URL" \
407
+ --restore-database-url "$RESTORE_DATABASE_URL" \
408
+ --pg-bin-dir "$PG_BIN_DIR" --confirm
409
+ ```
410
+
411
+ The route-handler gate covers the reusable host HTTP boundary. It dispatches
412
+ all 47 contract routes while checking email/password session lookup,
413
+ role/project scope, idempotency headers, JSON parsing, safe errors, and raw
414
+ webhook forwarding. A host still injects its repository/service and provider
415
+ verifier.
416
+
417
+ The service-contract gate covers the installed host seam: every one of the 47
418
+ manager endpoint IDs must map to one injected service method, the repository
419
+ transaction surface must be declared, and the eleven public customer methods must
420
+ remain separate from the manager session boundary. The installed manager
421
+ method gate also protects the 29 database-backed PostgreSQL methods while
422
+ keeping payment SDK and webhook methods injected. `maggie booking inspect` and
423
+ `release-gate` fail when the installed type contract, service/manager
424
+ validators, or PostgreSQL core repository artifact is missing.
425
+
426
+ The source package also ships `npm run booking:postgres-payment-adapter:test`
427
+ and `postgres-payment-adapter.mjs`. It persists normalized provider results
428
+ without importing an SDK; the host still injects the gateway and verified
429
+ webhook handler.
430
+
431
+ The public persistence seam is `postgres-customer-adapter.mjs`; its validator
432
+ protects sealed customer tokens, public DTOs, checkout/payment-return state,
433
+ and token-bound cancellation. A host must still supply the token key and
434
+ public abuse/security controls.
435
+
436
+ After a protected host run, make browser evidence part of the release gate:
437
+
438
+ ```bash
439
+ maggie booking release-gate --project . --require-runtime \
440
+ --evidence .maggie/booking/runtime-evidence.json \
441
+ --require-browser \
442
+ --browser-evidence .maggie/booking/browser/evidence.json \
443
+ --require-ops \
444
+ --ops-evidence .maggie/booking/ops-evidence.json \
445
+ --require-board
446
+ ```
447
+
448
+ The browser gate checks all 15 screens at mobile/tablet/desktop widths, safe
449
+ screenshot paths, ready state, no console errors, and no failed requests.
450
+ The board gate additionally fails closed until every task in
451
+ `docs/maggiedash-booking/EXECUTION-BOARD.json` is `passed`; use `--board` to
452
+ inspect a different board.
453
+
454
+ The installed MaggieDash package provides the host runtime commands separately:
455
+
456
+ ```bash
457
+ npm run booking:worker -- --job all
458
+ node maggiedash/scripts/capture-booking-runtime-evidence.mjs \
459
+ --base-url https://booking.example.test \
460
+ --plan .secrets/booking-runtime-plan.json \
461
+ --storage-state .secrets/booking-storage-state.json \
462
+ --output .maggie/booking/runtime/evidence.json \
463
+ --confirm
464
+ node maggiedash/scripts/validate-booking-runtime-evidence.mjs \
465
+ .maggie/booking/runtime/evidence.json
466
+ node maggiedash/scripts/capture-booking-browser-evidence.mjs \
467
+ --base-url https://booking.example.test \
468
+ --storage-state .secrets/booking-storage-state.json \
469
+ --output .maggie/booking/browser/evidence.json
470
+ node maggiedash/scripts/validate-booking-browser-evidence.mjs \
471
+ .maggie/booking/browser/evidence.json \
472
+ .maggie/booking/browser
473
+ ```
474
+
475
+ The worker is fixture-safe and dry-run by default. Its report includes a
476
+ correlation ID, `waitlistMatched`, and sanitized health codes for lock
477
+ contention, stale worker or availability state, payment lag, notification
478
+ retries, and dead letters. A real host must inject the PostgreSQL/provider/
479
+ notification adapter and route the health result to its alerting system using
480
+ the systemd, cron, or platform scheduler template from MaggieDash.
481
+
482
+ The remaining host evidence is tracked in [`TASKS.md`](./TASKS.md): PostgreSQL
483
+ transaction/lock integration, full host conformance, and protected browser
484
+ release evidence. The local UI, security, payment, notification, and worker
485
+ adapter gates are implemented; they do not replace real-host evidence.
486
+
487
+ The runtime capture plan is host-owned and must cover all 47 contract endpoint
488
+ IDs. It requires a dedicated test tenant, a traditional email/password session
489
+ cookie, explicit mutation bodies, and `--confirm`. The generated evidence only
490
+ contains canonical endpoint IDs/routes, status codes, and required-field
491
+ booleans; it never stores response bodies, cookies, request bodies, or provider
492
+ payloads. The protected workflow is
493
+ `.github/workflows/booking-runtime-evidence.yml`.
494
+
495
+ ## 4. Workflow phases
496
+
497
+ The existing Maggie bootstrap phase model can be extended with booking-specific
498
+ phases without changing the general bootstrap contract:
499
+
500
+ ```text
501
+ booking-discovery
502
+ -> booking-contract
503
+ -> booking-schema
504
+ -> booking-availability
505
+ -> booking-payments
506
+ -> booking-dashboard
507
+ -> booking-qa
508
+ -> booking-release
509
+ ```
510
+
511
+ Each phase has `pending`, `running`, `passed`, or `failed`, a validation command,
512
+ an owner, and a safe evidence path. A later phase cannot pass when an earlier
513
+ required phase is pending or failed.
514
+
515
+ ## 5. Feedback and memory integration
516
+
517
+ When a booking skill run fails:
518
+
519
+ 1. Generate a local feedback draft with skill, Maggie version, workflow/run ID,
520
+ phase, fingerprint, expected/actual result, command, and safe evidence paths.
521
+ 2. Let the user review and submit it through the existing feedback workflow.
522
+ 3. After maintainer triage, add the confirmed general fix to a regression test,
523
+ fixture, contract, or skill instruction.
524
+ 4. Only then write a durable memory entry. Never write a project-specific
525
+ preference or an unverified diagnosis directly to active memory.
526
+
527
+ This keeps the Booking skill useful across projects without leaking one host's
528
+ temporary configuration into another host.
529
+
530
+ ## 6. CLI design rules
531
+
532
+ - Read-only by default.
533
+ - `--confirm` for migrations, provider configuration, publication, or any
534
+ mutation.
535
+ - `--project` defaults to `.` but all output paths are validated inside the
536
+ project.
537
+ - JSON reports use explicit schema versions.
538
+ - Reports contain hashes and counts rather than raw provider responses.
539
+ - No CLI accepts a token as an argument.
540
+ - No CLI reads secrets into generated reports.
541
+ - Every failed check names the phase, stable error code, and next action.
542
+ - Every successful check prints the exact fixture/contract/revision it verified.
@@ -0,0 +1,129 @@
1
+ # Stripe integration audit
2
+
3
+ **Verified:** 2026-09-20
4
+ **Scope:** MaggieDash Booking payments and adjacent business operations
5
+ **Status:** contract-ready; a host-specific Stripe adapter is still required
6
+
7
+ This audit covers every Stripe resource used or proposed by the MaggieDash
8
+ Booking boundary. It does not claim that every resource in Stripe's complete
9
+ API is relevant to booking. The executable source of truth is the
10
+ [`stripe-booking-capabilities-v1.json`](../../bundled-contracts/maggiedash/stripe-booking-capabilities-v1.json)
11
+ contract, mirrored into the MaggieDash distribution.
12
+
13
+ ## Current integration decision
14
+
15
+ MaggieDash has a provider-neutral payment port, a verified webhook boundary,
16
+ idempotent event reconciliation, and a host-owned Stripe adapter seam. The
17
+ adapter uses an injected official Stripe SDK factory, server-side credentials,
18
+ the account's pinned API version, and a raw-body webhook signature check. The
19
+ MaggieDash package itself still has no Stripe SDK dependency or secret.
20
+
21
+ Booking customer IDs are tenant-local database identifiers, not Stripe
22
+ customer references. The Astro host resolves each local customer through a
23
+ stable tenant-scoped idempotency key, creates or reuses a Stripe Customer, and
24
+ stores only `provider_customer_ref`. Checkout, PaymentIntent, and SetupIntent
25
+ requests use that provider reference; a local UUID is never sent to Stripe as
26
+ a `cus_*` value and the reference is not included in public DTOs.
27
+
28
+ Stripe's public API documentation is account-aware: the account's API version
29
+ and enabled capabilities are part of the effective contract. Do not copy a
30
+ version date from a generic search result into application code. Pin the
31
+ server SDK/API version, upgrade it in a sandbox, run conformance fixtures, and
32
+ then approve the account upgrade. See [Stripe API versioning](https://docs.stripe.com/api/versioning)
33
+ and the [API reference](https://docs.stripe.com/api).
34
+
35
+ ## API matrix
36
+
37
+ | Capability | Status | MaggieDash use | Boundary |
38
+ |---|---|---|---|
39
+ | Customers | Core | Stable customer mapping, receipts, saved methods | Host owns PII and account scope |
40
+ | Checkout Sessions | Core | Hosted or embedded deposits and one-off payments | Use one Session per payment attempt |
41
+ | PaymentIntents | Core | Custom Payment Element, SCA, capture and reconciliation | Prefer this for new custom flows |
42
+ | SetupIntents | Optional | Save a method with consent for later balance/no-show charges | Never charge without a local policy and consent |
43
+ | Refunds | Core | Full/partial refund requests | Local refund row first; reconcile `refund.*` events |
44
+ | Events/webhooks | Core | Idempotent payment state projection | Verify raw body before parsing |
45
+ | Coupons + Promotion Codes | Optional | Campaign and referral discounts | Stripe applies the discount; local rules own eligibility |
46
+ | Customer Balance Transactions | Optional | Stripe invoice credits | Not a gift-card ledger by itself |
47
+ | Billing Subscriptions + Invoices | Future | Memberships or recurring plans | Add only when recurring booking is a product requirement |
48
+ | Customer Portal | Future | Customer-managed subscriptions and billing details | Use short-lived portal sessions |
49
+ | Stripe Tax | Optional | VAT/tax calculation and transaction records | Confirm jurisdiction, evidence, and price ownership |
50
+ | Terminal | Future | In-person deposits/balances | Requires reader operations and device lifecycle |
51
+ | Connect | Future | Multi-merchant/platform money movement | Not for a single business or multi-location tenant |
52
+
53
+ The implementation maps Stripe's provider states into the existing normalized
54
+ states (`requires_action`, `pending`, `failed`, `succeeded`, `cancelled`, and
55
+ `refunded`). Stripe object names never become booking lifecycle states.
56
+
57
+ ## Webhook set
58
+
59
+ The first adapter should subscribe only to events the configured capabilities
60
+ need:
61
+
62
+ - `checkout.session.completed`, `checkout.session.async_payment_succeeded`,
63
+ and `checkout.session.async_payment_failed`;
64
+ - `payment_intent.processing`, `payment_intent.payment_failed`,
65
+ `payment_intent.succeeded`, `payment_intent.requires_action`, and
66
+ `payment_intent.canceled`;
67
+ - `refund.created`, `refund.updated`, and `refund.failed`;
68
+ - `setup_intent.succeeded` and `setup_intent.setup_failed` when saved methods
69
+ are enabled;
70
+ - `invoice.paid`, `invoice.payment_failed`,
71
+ `customer.subscription.updated`, and `customer.subscription.deleted` only
72
+ when Billing is enabled.
73
+
74
+ The [Stripe event type reference](https://docs.stripe.com/api/events/types) is
75
+ the authoritative list and is continuously evolving. Unknown events are
76
+ stored as safe unmatched events or ignored by policy; they must not mutate a
77
+ booking merely because a webhook was received.
78
+
79
+ ## Gift cards, credits, and referrals
80
+
81
+ Stripe has native discounts, customer balance credits, Billing, Tax, Terminal,
82
+ and Connect. It does not expose a native `gift_card` or referral-program
83
+ resource in the API surface reviewed here. Therefore:
84
+
85
+ 1. Gift cards should be either a MaggieDash domain ledger (with issue, redeem,
86
+ refund, expiry, and immutable transaction rows) or a separately reviewed
87
+ partner system. A successful Stripe payment funds issuance, but the local
88
+ gift-card ledger remains the redemption source of truth.
89
+ 2. Stripe Customer Balance is invoice credit, not a complete gift-card product.
90
+ It should not be used for checkout redemption, expiry, transfers, or
91
+ reconciliation without an explicit accounting decision.
92
+ 3. Referrals should be tracked locally: referrer, referred customer, qualifying
93
+ booking, reward state, reversal state, and idempotency key. Stripe
94
+ Promotion Codes/Coupons can apply the reward discount; they do not own the
95
+ referral attribution or qualification rule.
96
+ 4. For affiliate-style payouts, the [PartnerStack Stripe App](https://marketplace.stripe.com/apps/partnerstack)
97
+ is a candidate. For branded omnichannel gift cards, [Gift Up](https://marketplace.stripe.com/apps/gift-up)
98
+ is a candidate. These are partner apps, not native MaggieDash features, and
99
+ require permission, privacy, pricing, jurisdiction, and reconciliation
100
+ review before installation.
101
+
102
+ The broader [Stripe Apps ecosystem](https://stripe.com/apps) is useful for
103
+ accounting, CRM, support, analytics, marketing, and workflow automation. It is
104
+ an integration surface, not a reason to add third-party credentials to the
105
+ MaggieDash browser bundle.
106
+
107
+ ## Recommended rollout order
108
+
109
+ 1. Stripe Customers + Checkout Sessions or PaymentIntents.
110
+ 2. Verified webhook reconciliation and Refunds.
111
+ 3. Optional SetupIntents for explicitly consented off-session charges.
112
+ 4. Coupons/Promotion Codes for campaigns; add local referral attribution.
113
+ 5. Stripe Tax if the host has the required tax configuration.
114
+ 6. Billing/Portal for memberships; Terminal for in-person operations; Connect
115
+ only for a true platform model.
116
+ 7. Gift-card partner or local ledger after accounting and redemption rules are
117
+ approved.
118
+
119
+ Run the local contract gate with:
120
+
121
+ ```bash
122
+ npm run booking:stripe:validate
123
+ npm run booking:stripe-adapter:test
124
+ maggie booking stripe-audit --contract /path/to/MaggieDash/contracts/stripe-booking-capabilities-v1.json
125
+ ```
126
+
127
+ No production payment, refund, gift-card issue, or referral reward is enabled
128
+ by this document. The host must add its adapter, integration tests, secret
129
+ configuration, and runtime evidence first.