Return to My Kanzen
MY KANZEN — CLOUDFLARE PORTAL v4.0

Built from your uploaded wix-default-custom-element(6).txt and the supplied
My Kanzen page/backend service files. This is the first full portal test build.

INSTALL IN THIS ORDER
1. Wix Studio > Backend: create an ordinary JavaScript file called
   cloudflare-portal.js (not .web.js).
   Paste all of Kanzen_Cloudflare_Portal_v4_0_PASTE.txt into it.
2. Replace the entire existing backend/http-functions.js with
   Kanzen_HTTP_Functions_v4_0_PASTE.txt.
   This includes the existing GoCardless webhook and the v3.1 account-check
   endpoint, plus the new portal endpoint. Original webhook bytes are retained.
3. SAVE AND PUBLISH THE WIX SITE. Saving alone does not expose the endpoint.
   Use the same Studio site attached to your working headless login client.
4. Cloudflare > Workers & Pages > my-kanzen > Create deployment > Production.
   Upload My_Kanzen_Portal_v4_0.zip. Its index.html and _worker.js are at the root.
5. Refresh https://app.kanzenmartialarts.co.uk. Existing sign-in should open the
   dashboard automatically. The sign-in/loading screen identifies v4.0.

Keep cloudflare-account.js from v3.1 and all existing backend service files.
No changes are needed to Wix's custom element/page, CMS permissions, DNS,
headless client, D1 database, Cloudflare secrets or notification permissions.

WHAT IS CONNECTED
- Your existing account-holder dashboard design, membership tile, event tile
  and member list.
- Member profile overview, grading history, achievements and documents.
- Calendar/invitations, competition summary, RSVP, announcement dismissal,
  notification preferences and personal-calendar export UI.
- Account-holder and training-member avatar updates.
- Membership PIN status, creation, verification, reset and protected details.
- Existing monthly/annual cooling-off cancellation functions, including the
  original GoCardless integration. No new refund rules were introduced.
- Existing login persistence and logout, installation card and working push
  receiver. Push device enrollment/sending remains the existing test tool.
- Existing Contact us email action and existing Coming soon labels.

TEST WITH JOHN LENNON AND BARRY FIRST
Confirm greeting, members, membership plan, images and upcoming event.
Open a member, then use Home and the phone/browser Back button.
Open calendar and inspect an invitation; submit only a deliberate test RSVP.
Check that membership fees stay hidden behind the existing PIN gate where
required. The existing sole-member/payer exemption is retained.
Check achievements, certificate previews/downloads and Contact us.
Sign out, sign in as the other account, and confirm no previous-account data.
Check on your phone and desktop. Existing installed Cloudflare app can be used.

Actions are connected to your existing Wix services. Avatar changes, RSVP,
PIN changes/reset email and confirmed cancellation perform the real action on
that site. Cancellation confirmation invokes your existing GoCardless code.
The assistant's automated checks use test data and do not perform live actions.

IF SOMETHING FAILS
The banner shows a fixed code and Wix HTTP status when available. Send that
message and the screen/action where it occurred.
PORTAL_EMPTY with Wix HTTP 404: check both Wix files and PUBLISH the site.
PORTAL_SERVICE_UNAVAILABLE: check the Wix backend import filenames and logs.
The adapter imports your existing ./my-kanzen-service.web.js service, which
in turn imports member-dashboard.web.js, calendar-service.web.js,
member-profile.web.js, achievement-service.web.js, certificate-service.web.js,
member-avatar.web.js and my-kanzen-logic.js.
ACCOUNT_DATA_CONFLICT: an account/member link needs checking; it is not bypassed.
The previous diagnostic tools remain at /tools.html.

TECHNICAL SCOPE
The Cloudflare server uses the signed-in Wix member token to call one fixed
published Wix HTTP function. The function gets the Wix member identity itself,
checks exactly one AccountHolder mapping and verifies linked record ownership.
Only a fixed set of portal actions/fields is accepted; no caller-supplied payer
identity or arbitrary backend function can be selected.
Existing backend services remain responsible for event eligibility, PIN proofs,
fees, cancellation/refund policy, avatar storage and prepared display data.
Browser scripts do not receive the Wix OAuth access/refresh tokens.
Private API responses are not cached. Logout/offline removes the private iframe
and clears the page's profile/PIN state. On returning to a hidden page, sign-in
is checked before revealing it. After 15 minutes hidden, the portal is remounted
with a fresh PIN gate; this does not implement the future child-device mode.

The renderer is served from Cloudflare with external scripts and a script-src
self policy. Images continue to use the Wix media URLs from your original code.
The notification service worker, manifest and notification artwork are retained.
Account-linked push preferences/sending and child-device provisioning remain
separate future work.

VALIDATION
Account ownership, schema/CSRF/session checks, response identity and concurrent
logout were tested locally. The existing PIN verification/protected-details
functions were exercised with test data, including wrong-account/tampered proofs.
The existing login, account-proof and push regression tests pass.
Headless Chromium browser checks passed for mobile dashboard/profile, PIN
unlock, calendar RSVP, desktop rendering and logout clearing the private iframe,
with no runtime or CSP errors. Browser checks used simulated account/API data.
External media could not be visually verified in this environment; original
Wix/Unsplash URLs are retained and allowed by the content policy. Live service
calls and image loading still need your test after publication/deployment.

REFERENCE
https://dev.wix.com/docs/develop-websites/articles/coding-with-velo/integrations/exposing-services/about-custom-site-apis