@medalsocial/booking 0.0.0-placeholder.0 → 0.1.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/CHANGELOG.md +14 -0
- package/LICENSE +201 -0
- package/NOTICE +6 -0
- package/README.md +220 -1
- package/dist/core/age.d.mts +34 -0
- package/dist/core/age.mjs +95 -0
- package/dist/core/age.mjs.map +1 -0
- package/dist/core/attempt-store.d.mts +111 -0
- package/dist/core/attempt-store.mjs +159 -0
- package/dist/core/attempt-store.mjs.map +1 -0
- package/dist/core/categories.d.mts +27 -0
- package/dist/core/categories.mjs +42 -0
- package/dist/core/categories.mjs.map +1 -0
- package/dist/core/clock.d.mts +33 -0
- package/dist/core/clock.mjs +251 -0
- package/dist/core/clock.mjs.map +1 -0
- package/dist/core/config.d.mts +171 -0
- package/dist/core/config.mjs +392 -0
- package/dist/core/config.mjs.map +1 -0
- package/dist/core/consent.d.mts +14 -0
- package/dist/core/consent.mjs +17 -0
- package/dist/core/consent.mjs.map +1 -0
- package/dist/core/deep-link.d.mts +40 -0
- package/dist/core/deep-link.mjs +160 -0
- package/dist/core/deep-link.mjs.map +1 -0
- package/dist/core/display-name.d.mts +18 -0
- package/dist/core/display-name.mjs +30 -0
- package/dist/core/display-name.mjs.map +1 -0
- package/dist/core/draft-store.d.mts +83 -0
- package/dist/core/draft-store.mjs +115 -0
- package/dist/core/draft-store.mjs.map +1 -0
- package/dist/core/dto.d.mts +46 -0
- package/dist/core/dto.mjs +157 -0
- package/dist/core/dto.mjs.map +1 -0
- package/dist/core/ics.d.mts +63 -0
- package/dist/core/ics.mjs +130 -0
- package/dist/core/ics.mjs.map +1 -0
- package/dist/core/index.d.mts +34 -0
- package/dist/core/index.mjs +31 -0
- package/dist/core/labels.d.mts +88 -0
- package/dist/core/labels.mjs +93 -0
- package/dist/core/labels.mjs.map +1 -0
- package/dist/core/machine.d.mts +598 -0
- package/dist/core/machine.mjs +878 -0
- package/dist/core/machine.mjs.map +1 -0
- package/dist/core/money.d.mts +12 -0
- package/dist/core/money.mjs +51 -0
- package/dist/core/money.mjs.map +1 -0
- package/dist/core/next-available.d.mts +20 -0
- package/dist/core/next-available.mjs +36 -0
- package/dist/core/next-available.mjs.map +1 -0
- package/dist/core/next-free.d.mts +25 -0
- package/dist/core/next-free.mjs +44 -0
- package/dist/core/next-free.mjs.map +1 -0
- package/dist/core/party-slots.d.mts +72 -0
- package/dist/core/party-slots.mjs +223 -0
- package/dist/core/party-slots.mjs.map +1 -0
- package/dist/core/paths.d.mts +11 -0
- package/dist/core/paths.mjs +56 -0
- package/dist/core/paths.mjs.map +1 -0
- package/dist/core/phone.d.mts +17 -0
- package/dist/core/phone.mjs +58 -0
- package/dist/core/phone.mjs.map +1 -0
- package/dist/core/portal/cookies.d.mts +29 -0
- package/dist/core/portal/dto.d.mts +140 -0
- package/dist/core/portal/dto.mjs +142 -0
- package/dist/core/portal/dto.mjs.map +1 -0
- package/dist/core/portal/family.d.mts +39 -0
- package/dist/core/portal/family.mjs +39 -0
- package/dist/core/portal/family.mjs.map +1 -0
- package/dist/core/portal/login-input.d.mts +29 -0
- package/dist/core/portal/login-input.mjs +29 -0
- package/dist/core/portal/login-input.mjs.map +1 -0
- package/dist/core/portal/next-path.d.mts +12 -0
- package/dist/core/portal/next-path.mjs +98 -0
- package/dist/core/portal/next-path.mjs.map +1 -0
- package/dist/core/portal/return-path.d.mts +7 -0
- package/dist/core/portal/return-path.mjs +49 -0
- package/dist/core/portal/return-path.mjs.map +1 -0
- package/dist/core/portal/session-cookie.d.mts +27 -0
- package/dist/core/portal/session-cookie.mjs +30 -0
- package/dist/core/portal/session-cookie.mjs.map +1 -0
- package/dist/core/portal/vipps-link.d.mts +56 -0
- package/dist/core/portal/vipps-link.mjs +136 -0
- package/dist/core/portal/vipps-link.mjs.map +1 -0
- package/dist/core/portal/vipps-return.d.mts +39 -0
- package/dist/core/portal/vipps-return.mjs +69 -0
- package/dist/core/portal/vipps-return.mjs.map +1 -0
- package/dist/core/rebook-store.d.mts +28 -0
- package/dist/core/rebook-store.mjs +60 -0
- package/dist/core/rebook-store.mjs.map +1 -0
- package/dist/core/restore-gate.d.mts +40 -0
- package/dist/core/restore-gate.mjs +96 -0
- package/dist/core/restore-gate.mjs.map +1 -0
- package/dist/core/stores.d.mts +8 -0
- package/dist/core/stores.mjs +23 -0
- package/dist/core/stores.mjs.map +1 -0
- package/dist/core/types.d.mts +241 -0
- package/dist/core/wire.d.mts +37 -0
- package/dist/next/cache/memory.d.mts +14 -0
- package/dist/next/cache/memory.mjs +51 -0
- package/dist/next/cache/memory.mjs.map +1 -0
- package/dist/next/cache/next-data.d.mts +6 -0
- package/dist/next/cache/next-data.mjs +35 -0
- package/dist/next/cache/next-data.mjs.map +1 -0
- package/dist/next/cache/noop.d.mts +6 -0
- package/dist/next/cache/noop.mjs +15 -0
- package/dist/next/cache/noop.mjs.map +1 -0
- package/dist/next/cache/workers.d.mts +29 -0
- package/dist/next/cache/workers.mjs +74 -0
- package/dist/next/cache/workers.mjs.map +1 -0
- package/dist/next/catalogue.d.mts +38 -0
- package/dist/next/catalogue.mjs +197 -0
- package/dist/next/catalogue.mjs.map +1 -0
- package/dist/next/handler.d.mts +11 -0
- package/dist/next/handler.mjs +150 -0
- package/dist/next/handler.mjs.map +1 -0
- package/dist/next/index.d.mts +17 -0
- package/dist/next/index.mjs +14 -0
- package/dist/next/loaders.d.mts +79 -0
- package/dist/next/loaders.mjs +195 -0
- package/dist/next/loaders.mjs.map +1 -0
- package/dist/next/manage-dto.d.mts +6 -0
- package/dist/next/manage-dto.mjs +28 -0
- package/dist/next/manage-dto.mjs.map +1 -0
- package/dist/next/medal.d.mts +98 -0
- package/dist/next/medal.mjs +154 -0
- package/dist/next/medal.mjs.map +1 -0
- package/dist/next/options.d.mts +158 -0
- package/dist/next/options.mjs +65 -0
- package/dist/next/options.mjs.map +1 -0
- package/dist/next/portal/guardian.d.mts +42 -0
- package/dist/next/portal/guardian.mjs +76 -0
- package/dist/next/portal/guardian.mjs.map +1 -0
- package/dist/next/portal/medal-portal.d.mts +161 -0
- package/dist/next/portal/medal-portal.mjs +825 -0
- package/dist/next/portal/medal-portal.mjs.map +1 -0
- package/dist/next/portal/session.d.mts +38 -0
- package/dist/next/portal/session.mjs +40 -0
- package/dist/next/portal/session.mjs.map +1 -0
- package/dist/next/portal/vipps-flash.d.mts +14 -0
- package/dist/next/portal/vipps-flash.mjs +41 -0
- package/dist/next/portal/vipps-flash.mjs.map +1 -0
- package/dist/next/portal.d.mts +205 -0
- package/dist/next/portal.mjs +469 -0
- package/dist/next/portal.mjs.map +1 -0
- package/dist/next/request.d.mts +51 -0
- package/dist/next/request.mjs +123 -0
- package/dist/next/request.mjs.map +1 -0
- package/dist/next/routes/catalogue-routes.mjs +330 -0
- package/dist/next/routes/catalogue-routes.mjs.map +1 -0
- package/dist/next/routes/create.mjs +422 -0
- package/dist/next/routes/create.mjs.map +1 -0
- package/dist/next/routes/manage.mjs +191 -0
- package/dist/next/routes/manage.mjs.map +1 -0
- package/dist/next/routes/portal-routes.mjs +312 -0
- package/dist/next/routes/portal-routes.mjs.map +1 -0
- package/dist/next/routes/shared.mjs +134 -0
- package/dist/next/routes/shared.mjs.map +1 -0
- package/dist/next/routes/vipps-return.mjs +166 -0
- package/dist/next/routes/vipps-return.mjs.map +1 -0
- package/dist/next/runtime.d.mts +49 -0
- package/dist/next/runtime.mjs +94 -0
- package/dist/next/runtime.mjs.map +1 -0
- package/dist/next/seed.d.mts +71 -0
- package/dist/next/seed.mjs +495 -0
- package/dist/next/seed.mjs.map +1 -0
- package/dist/next/server.d.mts +26 -0
- package/dist/next/server.mjs +63 -0
- package/dist/next/server.mjs.map +1 -0
- package/dist/react/BookingLink.d.mts +61 -0
- package/dist/react/BookingLink.mjs +102 -0
- package/dist/react/BookingLink.mjs.map +1 -0
- package/dist/react/BookingWizard.d.mts +49 -0
- package/dist/react/BookingWizard.mjs +577 -0
- package/dist/react/BookingWizard.mjs.map +1 -0
- package/dist/react/LoginPageQuery.d.mts +37 -0
- package/dist/react/LoginPageQuery.mjs +106 -0
- package/dist/react/LoginPageQuery.mjs.map +1 -0
- package/dist/react/LoginSheet.d.mts +49 -0
- package/dist/react/LoginSheet.mjs +98 -0
- package/dist/react/LoginSheet.mjs.map +1 -0
- package/dist/react/ManageBooking.d.mts +50 -0
- package/dist/react/ManageBooking.mjs +197 -0
- package/dist/react/ManageBooking.mjs.map +1 -0
- package/dist/react/PortalDashboard.d.mts +10 -0
- package/dist/react/Provider.d.mts +82 -0
- package/dist/react/Provider.mjs +132 -0
- package/dist/react/Provider.mjs.map +1 -0
- package/dist/react/actions.d.mts +133 -0
- package/dist/react/actions.mjs +90 -0
- package/dist/react/actions.mjs.map +1 -0
- package/dist/react/index.d.mts +28 -0
- package/dist/react/index.mjs +20 -0
- package/dist/react/kit.d.mts +54 -0
- package/dist/react/kit.mjs +127 -0
- package/dist/react/kit.mjs.map +1 -0
- package/dist/react/labels/index.d.mts +23 -0
- package/dist/react/labels/index.mjs +44 -0
- package/dist/react/labels/index.mjs.map +1 -0
- package/dist/react/labels/login.d.mts +10 -0
- package/dist/react/labels/login.mjs +13 -0
- package/dist/react/labels/login.mjs.map +1 -0
- package/dist/react/labels/manage.d.mts +15 -0
- package/dist/react/labels/manage.mjs +19 -0
- package/dist/react/labels/manage.mjs.map +1 -0
- package/dist/react/labels/portal.d.mts +25 -0
- package/dist/react/labels/portal.mjs +41 -0
- package/dist/react/labels/portal.mjs.map +1 -0
- package/dist/react/labels/screens.d.mts +11 -0
- package/dist/react/labels/screens.mjs +709 -0
- package/dist/react/labels/screens.mjs.map +1 -0
- package/dist/react/labels/wizard.d.mts +69 -0
- package/dist/react/labels/wizard.mjs +95 -0
- package/dist/react/labels/wizard.mjs.map +1 -0
- package/dist/react/link/index.d.mts +5 -0
- package/dist/react/link/index.mjs +5 -0
- package/dist/react/portal/SessionTouch.d.mts +19 -0
- package/dist/react/portal/SessionTouch.mjs +40 -0
- package/dist/react/portal/SessionTouch.mjs.map +1 -0
- package/dist/react/portal/age-prompt.d.mts +10 -0
- package/dist/react/portal/age-prompt.mjs +21 -0
- package/dist/react/portal/age-prompt.mjs.map +1 -0
- package/dist/react/portal/book-again.d.mts +18 -0
- package/dist/react/portal/book-again.mjs +21 -0
- package/dist/react/portal/book-again.mjs.map +1 -0
- package/dist/react/portal/child-summary.d.mts +17 -0
- package/dist/react/portal/child-summary.mjs +45 -0
- package/dist/react/portal/child-summary.mjs.map +1 -0
- package/dist/react/portal/dashboard.d.mts +74 -0
- package/dist/react/portal/dashboard.mjs +204 -0
- package/dist/react/portal/dashboard.mjs.map +1 -0
- package/dist/react/portal/leave.d.mts +17 -0
- package/dist/react/portal/leave.mjs +21 -0
- package/dist/react/portal/leave.mjs.map +1 -0
- package/dist/react/portal/sections.d.mts +12 -0
- package/dist/react/portal/sections.mjs +48 -0
- package/dist/react/portal/sections.mjs.map +1 -0
- package/dist/react/portal/tabs.d.mts +23 -0
- package/dist/react/portal/tabs.mjs +36 -0
- package/dist/react/portal/tabs.mjs.map +1 -0
- package/dist/react/portal/vipps-flash.d.mts +11 -0
- package/dist/react/portal/vipps-flash.mjs +18 -0
- package/dist/react/portal/vipps-flash.mjs.map +1 -0
- package/dist/react/portal/wired.mjs +202 -0
- package/dist/react/portal/wired.mjs.map +1 -0
- package/dist/react/screen-labels.mjs +14 -0
- package/dist/react/screen-labels.mjs.map +1 -0
- package/dist/react/shared.d.mts +13 -0
- package/dist/react/shared.mjs +7 -0
- package/dist/react/use-next-free.d.mts +19 -0
- package/dist/react/use-next-free.mjs +56 -0
- package/dist/react/use-next-free.mjs.map +1 -0
- package/dist/react/useBooking.d.mts +177 -0
- package/dist/react/useBooking.mjs +1205 -0
- package/dist/react/useBooking.mjs.map +1 -0
- package/dist/react/wizard/adapters.mjs +187 -0
- package/dist/react/wizard/adapters.mjs.map +1 -0
- package/dist/react/wizard/index.d.mts +11 -0
- package/dist/react/wizard/index.mjs +6 -0
- package/package.json +126 -5
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# @medalsocial/booking
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#174](https://github.com/Medal-Social/MedalSocial-SDK/pull/174) [`3f5475e`](https://github.com/Medal-Social/MedalSocial-SDK/commit/3f5475e6c667e9de0c625331e050cb2f8c790f3a) Thanks [@alioftech](https://github.com/alioftech)! - New package `@medalsocial/booking` (0.1.0): a complete, themeable booking product for Medal customer sites.
|
|
8
|
+
|
|
9
|
+
- `@medalsocial/booking/core` — the booking wizard's state machine and rules, the business's clock, money and phone formatting, service categories, age, party seating, deep links, Medal DTO mapping, ICS export, browser stores and customer-portal helpers, all driven by one validated, client-safe `BookingConfig` (`resolveBookingConfig`).
|
|
10
|
+
- `@medalsocial/booking/react` — `<BookingWizard>` (on the headless `useBooking()`), `<ManageBooking>`, `<PortalDashboard>`, `<LoginSheet>`, `<BookingLink>` and `<BookingProvider>`, composed from `@medalsocial/meda/booking` screens; server-safe label packs in `/react/shared`. A booking page imports from `@medalsocial/booking/react/wizard` (the wizard, `useBooking()`, the provider and the login sheet, without the manage page or the portal) and its layout from `@medalsocial/booking/react/link` (`<BookingLink>`, `<BookingPendingHost>`, `useNextFree()`); the build is one module per source module with `"sideEffects": false`.
|
|
11
|
+
- Labels: every key takes a `BookingLabel`, a string (one text node once filled) or an array of strings (one text node per element), so a site decides where each sentence breaks into text nodes; `fill`, `fillParts`, `labelText` and `isBookingLabel` in `/core`. The built-in packs are strings except `wizard.progress`, `wizard.slotsUnavailable.call` and `portal.greeting`; `wizard.party.sizeWord.*` spells the party size for meda's `{sizeWord}`.
|
|
12
|
+
- `@medalsocial/booking/next` — `createBookingServer()`: one route handler for every booking and portal API route, page loaders, portal action functions, and cache adapters (`/next/cache/workers`, `/next/cache/next-data`, `/next/cache/memory`, `/next/cache/noop`). The stylist-photo proxy fetches only from `avatarHosts` (default `DEFAULT_AVATAR_HOSTS`) and relays only raster images; a Vipps login grant is exchanged only in the browser that started the login.
|
|
13
|
+
|
|
14
|
+
Pre-1.0: a minor bump may break in 0.x; pin the exact version.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2023-2026 Medal Social
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,222 @@
|
|
|
1
1
|
# @medalsocial/booking
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The booking product behind a Medal Social booking site: the wizard's rules,
|
|
4
|
+
the business's clock, money, phone and deep-link handling, browser stores,
|
|
5
|
+
and the customer-portal helpers — built on [`@medalsocial/sdk`](../sdk).
|
|
6
|
+
|
|
7
|
+
> **Status: pre-release (0.x, not yet published).** `/core`, `/react` and
|
|
8
|
+
> `/next` are in place for the first release, `0.1.0`. In 0.x a minor version
|
|
9
|
+
> may break; pin the exact version.
|
|
10
|
+
|
|
11
|
+
## Entry points
|
|
12
|
+
|
|
13
|
+
| Import | What it is | Runs in |
|
|
14
|
+
|---|---|---|
|
|
15
|
+
| `@medalsocial/booking/core` | Config, wizard state machine, clock, money, phone, categories, age, party seating, deep links, DTO mapping, ICS, browser stores, portal pure helpers | Browser, Node, Workers — no React, no Next, no DOM at import time |
|
|
16
|
+
| `@medalsocial/booking/react` | `<BookingWizard>` and the headless `useBooking()`, `<ManageBooking>`, `<PortalDashboard>`, `<LoginSheet>`, `<LoginFromQuery>`, `<BookingLink>`, `useNextFree()`, `<BookingProvider>` — composed from `@medalsocial/meda/booking` | Client components (`'use client'`) |
|
|
17
|
+
| `@medalsocial/booking/react/wizard` | The booking page's entry: `<BookingWizard>`, `useBooking()`, `<BookingProvider>`, `<LoginSheet>` — and none of the manage page or the portal. Import a booking page from here | Client components (`'use client'`) |
|
|
18
|
+
| `@medalsocial/booking/react/link` | What a layout mounts outside the booking page: `<BookingLink>`, `<BookingPendingHost>`, `useNextFree()`, `<BookingProvider>`. A root layout renders on the booking page too, so import it from here | Client components (`'use client'`) |
|
|
19
|
+
| `@medalsocial/booking/react/shared` | The label packs (`BOOKING_LABELS`, `mergeLabels`) and the portal's URL/cookie readers (`parsePortalTab`, …) | Server Components and the browser — no React |
|
|
20
|
+
| `@medalsocial/booking/next` | `createBookingServer`: one handler for every booking and portal API route, the page loaders (`loadBookingPage`, `loadManagePage`, `loadPortalPage`), portal session and action functions, the Medal seam | Server only (`server-only`), Next ≥ 16.3 |
|
|
21
|
+
| `@medalsocial/booking/next/cache/{workers,memory,next-data,noop}` | Cache adapters: Workers Cache API, in-process LRU, Next's data cache, none | Server only |
|
|
22
|
+
|
|
23
|
+
ESM only, one built module per source module, `"sideEffects": false`, so a
|
|
24
|
+
bundler keeps only the modules a page reaches. A bundler keeps a `'use client'`
|
|
25
|
+
entry whole, though (Turbopack does), so `/react` brings everything it exports
|
|
26
|
+
to the page that imports it: use `/react/wizard` on a booking page and
|
|
27
|
+
`/react/link` in the layout around it, and keep `/react` for pages where size
|
|
28
|
+
does not matter.
|
|
29
|
+
|
|
30
|
+
Peer dependencies: `zod` 4, `react`/`react-dom` 19 (for `/react`),
|
|
31
|
+
and optionally `next` ≥ 16.3, `@medalsocial/meda` ^3.2 and `lucide-react` (all
|
|
32
|
+
three needed by `/react`).
|
|
33
|
+
|
|
34
|
+
## Configuration
|
|
35
|
+
|
|
36
|
+
Everything a site tells the package goes through one client-safe object.
|
|
37
|
+
`resolveBookingConfig` fills the defaults, validates with zod and freezes the
|
|
38
|
+
result; every factory takes the resolved config.
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { createClock, createWizard, resolveBookingConfig } from '@medalsocial/booking/core';
|
|
42
|
+
|
|
43
|
+
export const bookingConfig = resolveBookingConfig({
|
|
44
|
+
timeZone: 'Europe/Oslo', // required
|
|
45
|
+
locale: 'nb-NO',
|
|
46
|
+
currency: 'NOK',
|
|
47
|
+
contact: { name: 'Salong Demo', phone: '22 33 44 55', address: null },
|
|
48
|
+
categories: [
|
|
49
|
+
{ key: 'barn', audience: 'child', adultEquivalent: [{ nameIncludes: 'gutt', category: 'herre' }] },
|
|
50
|
+
{ key: 'herre', audience: 'adult' },
|
|
51
|
+
{ key: 'annet', audience: 'any' },
|
|
52
|
+
],
|
|
53
|
+
fallbackCategory: 'annet',
|
|
54
|
+
storageNamespace: 'salong-demo',
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const wizard = createWizard(bookingConfig);
|
|
58
|
+
const clock = createClock(bookingConfig);
|
|
59
|
+
clock.when(Date.now()); // «i dag 14:15», on the business's clock
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
`BookingConfig` never holds a secret: it is serialised into the page. The
|
|
63
|
+
Medal API key, cache adapters and session secret belong to the server options
|
|
64
|
+
of `/next`, which read no environment variable themselves — the site passes
|
|
65
|
+
its own values in.
|
|
66
|
+
|
|
67
|
+
| Field | Default | Purpose |
|
|
68
|
+
|---|---|---|
|
|
69
|
+
| `timeZone` | — (required) | IANA zone of the business's opening hours; every clock face uses it |
|
|
70
|
+
| `locale` | `nb-NO` | `Intl` formatting and the built-in label pack (`nb` or `en`) |
|
|
71
|
+
| `currency` | `NOK` | ISO 4217; amounts stay in minor units on the wire |
|
|
72
|
+
| `phone` | `{ country: 'NO', validate: 'strict' }` | `NO` is the only strict rule set in 0.x |
|
|
73
|
+
| `paths` | `/bestill`, `/bestill/administrer`, `/min-side`, `/api/booking`, … | The URLs the site serves |
|
|
74
|
+
| `query` / `whoValues` | `kategori`, `tjeneste`, `frisor`, `antall`, `hvem`, … | Deep-link query keys and values |
|
|
75
|
+
| `categories` / `fallbackCategory` | `barn` (child), `annet` (any) | Service groups in display order; unknown Medal categories land on the fallback |
|
|
76
|
+
| `party` | `{ maxPeople: 3, allowParallel: true, askWhoFirst: true }` | Step 1's rules |
|
|
77
|
+
| `window` | `{ rangeDays: 7, prefetchLimit: 4, prefetchCategory: null }` | Bookable window and page prefetch |
|
|
78
|
+
| `dayparts` | `formiddag` 0–12, `ettermiddag` 12–17, `kveld` 17–24 | Named parts of the day, contiguous from 0 to 24 |
|
|
79
|
+
| `portal` | disabled; cookie `booking_portal` (+ derived `_next`, `__Host-…_vipps_bind`, `_vipps_link`) | Customer portal switches and cookie names |
|
|
80
|
+
| `consent` | `{ termsUrl: null, marketing: null }` | The marketing sentence and its version are the site's own |
|
|
81
|
+
| `storageNamespace` | `medal` | Browser keys are `<ns>:booking:draft`, `<ns>:booking:attempt`, `<ns>:booking:rebook-who` |
|
|
82
|
+
| `ics` | `-//Medal Social//Booking//EN` | Calendar product id and UID domain |
|
|
83
|
+
| `labels` | built-in pack for `locale` | Partial copy overrides (`summary.pickTime`, `daypart.<key>`, …) |
|
|
84
|
+
|
|
85
|
+
A site moving onto the package keeps its live sessions, drafts and cache
|
|
86
|
+
entries by passing the paths, cookie names and storage namespace it already
|
|
87
|
+
uses.
|
|
88
|
+
|
|
89
|
+
## The UI (`/react`)
|
|
90
|
+
|
|
91
|
+
The screens are meda's; the package feeds them. A site needs Tailwind v4 and
|
|
92
|
+
three of meda's stylesheets, and themes them with its own shadcn variables
|
|
93
|
+
(`--primary`, `--card`, …):
|
|
94
|
+
|
|
95
|
+
```css
|
|
96
|
+
@import '@medalsocial/meda/styles/bridge.css';
|
|
97
|
+
@import '@medalsocial/meda/primitives/styles.css'; /* the sheets and dialogs the screens open */
|
|
98
|
+
@import '@medalsocial/meda/booking/styles.css';
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Without the primitives sheet the login sheet's positioning classes are never
|
|
102
|
+
generated, and it opens at the top of the page.
|
|
103
|
+
|
|
104
|
+
```tsx
|
|
105
|
+
// app/bestill/page.tsx — a Server Component
|
|
106
|
+
import { resolveBookingConfig } from '@medalsocial/booking/core';
|
|
107
|
+
import { BookingWizard } from '@medalsocial/booking/react/wizard';
|
|
108
|
+
import { mergeLabels } from '@medalsocial/booking/react/shared';
|
|
109
|
+
import { startLogin, startVipps } from './actions'; // the app's 'use server' wrappers
|
|
110
|
+
|
|
111
|
+
const config = resolveBookingConfig({
|
|
112
|
+
timeZone: 'Europe/Oslo',
|
|
113
|
+
// Resolved here, so the browser bundle carries no copy it does not show.
|
|
114
|
+
labels: mergeLabels('nb-NO', { 'who.heading': 'Hvem gjelder timen?' }),
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
export default async function Page() {
|
|
118
|
+
const seed = await loadSeed(); // `/next`'s loader
|
|
119
|
+
return <BookingWizard config={config} seed={seed} actions={{ startLogin, startVipps }} />;
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
The override ladder, cheapest first, all public API:
|
|
124
|
+
|
|
125
|
+
1. **CSS variables** — the bridge's shadcn names.
|
|
126
|
+
2. **`labels`** — any key of `BookingLabels`, over the pack in `config.labels`
|
|
127
|
+
(see [Labels and text nodes](#labels-and-text-nodes)).
|
|
128
|
+
3. **`classNames`** — per screen and slot: `classNames={{ who: { chip: '…' }, time: { chip: '…' } }}`.
|
|
129
|
+
4. **`components`** — card renderers: `components={{ ServiceCard, StylistCard, TimeChip, … }}`.
|
|
130
|
+
5. **`useBooking()`** — the wizard's whole state, fetches and actions, without its markup.
|
|
131
|
+
|
|
132
|
+
`<BookingProvider config labels classNames components>` shares one set of
|
|
133
|
+
these with every booking piece under it. Server actions stay in the app
|
|
134
|
+
(`PortalActions`): each is a three-line `'use server'` wrapper passed in as a
|
|
135
|
+
prop, answering with its result or with next-safe-action's envelope.
|
|
136
|
+
|
|
137
|
+
### Labels and text nodes
|
|
138
|
+
|
|
139
|
+
A label is a `BookingLabel`: a `string` or an array of strings. Both forms are
|
|
140
|
+
serialisable and work for every key. They differ only in the DOM they render as:
|
|
141
|
+
|
|
142
|
+
- A **string** is ONE text node once its `{holes}` are filled, the way a
|
|
143
|
+
template literal is.
|
|
144
|
+
- An **array** is one text node per element, each element filled with the same
|
|
145
|
+
values. For example, `['Steg ', '{step}', ' av ', '{total}']` is four nodes,
|
|
146
|
+
the DOM of `Steg {step} av {total}` written out in JSX. An element that fills
|
|
147
|
+
to `''` renders nothing.
|
|
148
|
+
|
|
149
|
+
A browser lays text out per text node, so a site moving onto these screens
|
|
150
|
+
from its own JSX can match its old pixels by writing each sentence in the shape
|
|
151
|
+
its old markup had. Text-only targets read an array joined: `aria-label`, the
|
|
152
|
+
calendar file, its name, and messages.
|
|
153
|
+
|
|
154
|
+
The built-in packs are strings, except the three sentences the package itself
|
|
155
|
+
draws in pieces: `wizard.progress`, `wizard.slotsUnavailable.call` and
|
|
156
|
+
`portal.greeting`. `wizard.party.sizeWord.two` / `.three` / `.other` spell the
|
|
157
|
+
party size («to», «tre», «flere») for `{sizeWord}` in the stylist step's
|
|
158
|
+
`stylist.party.parallel.*` and `stylist.party.parallelNote.*`. Left blank, the
|
|
159
|
+
number is filled in instead. An array for a meda screen key needs
|
|
160
|
+
`@medalsocial/meda` 3.4 or later.
|
|
161
|
+
|
|
162
|
+
## Server (`/next`)
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
// lib/booking/server.ts
|
|
166
|
+
import 'server-only';
|
|
167
|
+
import { createBookingServer } from '@medalsocial/booking/next';
|
|
168
|
+
import { nextDataCacheAdapter } from '@medalsocial/booking/next/cache/next-data';
|
|
169
|
+
import { workersCacheAdapter } from '@medalsocial/booking/next/cache/workers';
|
|
170
|
+
|
|
171
|
+
export const booking = createBookingServer({
|
|
172
|
+
config: bookingConfig,
|
|
173
|
+
// Functions, so the key is read per request (OpenNext fills process.env late).
|
|
174
|
+
medal: { apiKey: () => process.env.MEDAL_API_KEY, baseUrl: () => process.env.MEDAL_API_ENDPOINT },
|
|
175
|
+
cache: {
|
|
176
|
+
edge: workersCacheAdapter({ origin: () => process.env.NEXT_PUBLIC_BASE_URL }),
|
|
177
|
+
data: nextDataCacheAdapter(),
|
|
178
|
+
prefix: 'my-site-booking',
|
|
179
|
+
environment: 'production',
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
// app/api/booking/[...path]/route.ts and app/api/portal/[...path]/route.ts
|
|
184
|
+
export const { GET, POST, DELETE } = booking.handler;
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
- **Pages** call `booking.loadBookingPage({ searchParams })`,
|
|
188
|
+
`booking.loadManagePage(token)` and `booking.loadPortalPage()`; each answers
|
|
189
|
+
a tagged result (`redirect`, `unavailable`, `ready`, …) and the page renders it.
|
|
190
|
+
- **Server actions stay in the app.** `booking.portal.actions.*` are plain async
|
|
191
|
+
functions; wrap each in a `'use server'` export and pass it to the components.
|
|
192
|
+
- **Caches.** `edge` holds the booking seed (per location, a few ms); `data`
|
|
193
|
+
holds services, stylists, hours and free slots. On Node use
|
|
194
|
+
`memoryCacheAdapter()` for both. Every adapter keeps one contract
|
|
195
|
+
(`tests/next/cache/contract.test.ts`).
|
|
196
|
+
- **Stylist photos.** `/api/booking/avatar/<id>` fetches a stylist's photo
|
|
197
|
+
server-side and serves it from the site with a day of browser cache. It
|
|
198
|
+
fetches only from `avatarHosts` (exact names or `*.` suffixes; default
|
|
199
|
+
`DEFAULT_AVATAR_HOSTS`, Medal's photo storage and Google profile pictures),
|
|
200
|
+
over `https:` on the default port, never from an IP address or internal
|
|
201
|
+
name and never through a redirect, and it relays only JPEG, PNG, WebP, AVIF
|
|
202
|
+
and GIF. A photo anywhere else falls back to the stylist's initials.
|
|
203
|
+
- `examples/next-booking` is a runnable site on plain `next start`.
|
|
204
|
+
|
|
205
|
+
## Development
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
pnpm --filter @medalsocial/booking test # node + jsdom projects
|
|
209
|
+
pnpm --filter @medalsocial/booking test:coverage # 100% thresholds
|
|
210
|
+
pnpm --filter @medalsocial/booking build
|
|
211
|
+
pnpm --filter @medalsocial/booking verify:paths # export map + bare-Node core check
|
|
212
|
+
pnpm --filter @medalsocial/booking size:budget # gzip budgets, esbuild-bundled
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
`/core` may import nothing from React, Next, `server-only` or meda — Biome's
|
|
216
|
+
`noRestrictedImports` and `tests/core/boundary.test.ts` both enforce it. This
|
|
217
|
+
repository is public: no customer names, copy or data in any file
|
|
218
|
+
(`tests/core/denylist.test.ts`).
|
|
219
|
+
|
|
220
|
+
## License
|
|
221
|
+
|
|
222
|
+
Apache-2.0
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { BookingConfig } from "./config.mjs";
|
|
2
|
+
//#region src/core/age.d.ts
|
|
3
|
+
type AgeConfig = Pick<BookingConfig, 'categories' | 'fallbackCategory' | 'locale' | 'labels'>;
|
|
4
|
+
export interface AgeRange {
|
|
5
|
+
/** Inclusive; equal to `max` when the age is exact. */
|
|
6
|
+
min: number;
|
|
7
|
+
max: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function ageOnDay(birthYear: number, birthMonth: number | null | undefined, dayKey: string): AgeRange | null;
|
|
10
|
+
/** A service's age range, as the wizard carries it (`WizardService`). */
|
|
11
|
+
export interface AgeBounds {
|
|
12
|
+
ageMinYears?: number;
|
|
13
|
+
ageMaxYears?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Whether a service can be suggested for a child of this age. Only a CERTAIN
|
|
17
|
+
* miss rules it out: a child who is «6–7 år» is not too old for a service up
|
|
18
|
+
* to 6, because they may still be six on the day. `null` — nobody's age is
|
|
19
|
+
* known (a guest, a grown-up) — fits everything.
|
|
20
|
+
*/
|
|
21
|
+
export declare function fitsAge(service: AgeBounds, age: AgeRange | null): boolean;
|
|
22
|
+
export interface Age {
|
|
23
|
+
ageOnDay: typeof ageOnDay;
|
|
24
|
+
fitsAge: typeof fitsAge;
|
|
25
|
+
ageLabel(range: AgeRange): string;
|
|
26
|
+
grownUpEquivalent<S extends AgeBounds & {
|
|
27
|
+
id: string;
|
|
28
|
+
name: string;
|
|
29
|
+
category: string;
|
|
30
|
+
}>(last: S, candidates: readonly S[], age: AgeRange | null): S | null;
|
|
31
|
+
}
|
|
32
|
+
export declare function createAge(config: AgeConfig): Age;
|
|
33
|
+
//#endregion
|
|
34
|
+
//# sourceMappingURL=age.d.mts.map
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { adultEquivalent } from "./categories.mjs";
|
|
2
|
+
import { fill, resolveLabels } from "./labels.mjs";
|
|
3
|
+
//#region src/core/age.ts
|
|
4
|
+
/**
|
|
5
|
+
* How old a child is ON THE APPOINTMENT DAY — the one age that decides which
|
|
6
|
+
* haircut and which price they get.
|
|
7
|
+
*
|
|
8
|
+
* The profile keeps a birth YEAR and, since SP10, optionally a birth MONTH —
|
|
9
|
+
* never a full date (data minimisation for children). So the answer is a
|
|
10
|
+
* RANGE: with the month it is exact (Medal's own `ageOnDay` counts the
|
|
11
|
+
* birthday as the first of the month, and this agrees with it), without it
|
|
12
|
+
* the child is one of two ages depending on whether the birthday has been yet
|
|
13
|
+
* this year, which the card says honestly as «7–8 år».
|
|
14
|
+
*
|
|
15
|
+
* `dayKey` is `clock.dayKey`'s `2026-08-29` — the SALON's calendar date, not the
|
|
16
|
+
* viewer's, for the reason every date on this site is.
|
|
17
|
+
*
|
|
18
|
+
* Pure and dependency-free, so the wizard (a browser bundle) and the portal (a
|
|
19
|
+
* server render) read the same number.
|
|
20
|
+
*
|
|
21
|
+
* `ageOnDay` and `fitsAge` are config-free; `createAge(config)` adds the two
|
|
22
|
+
* that are not — the label's words, and which adult group a kids' service
|
|
23
|
+
* grows up into (`categories[].adultEquivalent`, which replaced a hard-coded
|
|
24
|
+
* table of Norwegian service names).
|
|
25
|
+
*/
|
|
26
|
+
function ageOnDay(birthYear, birthMonth, dayKey) {
|
|
27
|
+
const year = Number(dayKey.slice(0, 4));
|
|
28
|
+
const month = Number(dayKey.slice(5, 7));
|
|
29
|
+
if (!Number.isInteger(year) || !Number.isInteger(month) || !Number.isInteger(birthYear)) return null;
|
|
30
|
+
const yearDiff = year - birthYear;
|
|
31
|
+
if (yearDiff < 0) return null;
|
|
32
|
+
if (typeof birthMonth === "number" && Number.isInteger(birthMonth) && birthMonth >= 1 && birthMonth <= 12) {
|
|
33
|
+
const exact = month < birthMonth ? yearDiff - 1 : yearDiff;
|
|
34
|
+
return exact < 0 ? null : {
|
|
35
|
+
min: exact,
|
|
36
|
+
max: exact
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
min: Math.max(0, yearDiff - 1),
|
|
41
|
+
max: yearDiff
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** «7 år», or «7–8 år» when only the year is known — in the words of `labels`. */
|
|
45
|
+
function ageLabel(labels, range) {
|
|
46
|
+
return range.min === range.max ? fill(labels["age.exact"], { min: range.min }) : fill(labels["age.range"], {
|
|
47
|
+
min: range.min,
|
|
48
|
+
max: range.max
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Whether a service can be suggested for a child of this age. Only a CERTAIN
|
|
53
|
+
* miss rules it out: a child who is «6–7 år» is not too old for a service up
|
|
54
|
+
* to 6, because they may still be six on the day. `null` — nobody's age is
|
|
55
|
+
* known (a guest, a grown-up) — fits everything.
|
|
56
|
+
*/
|
|
57
|
+
function fitsAge(service, age) {
|
|
58
|
+
if (age === null) return true;
|
|
59
|
+
if (service.ageMaxYears !== void 0 && age.min > service.ageMaxYears) return false;
|
|
60
|
+
if (service.ageMinYears !== void 0 && age.max < service.ageMinYears) return false;
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* What «Samme som sist» becomes for a child who has outgrown their last cut:
|
|
65
|
+
* the one service in the same category that fits their age now — an
|
|
66
|
+
* age-banded one first (a «Barnehageklipp» child is a «Barneklipp» child at
|
|
67
|
+
* seven) — or — where the
|
|
68
|
+
* category holds none — the grown-up cut its group's `adultEquivalent` points at (by
|
|
69
|
+
* name: «gutt» → the men's group, «jente» → the women's), again only when
|
|
70
|
+
* exactly one fits. Anything less
|
|
71
|
+
* certain is `null`: the parent picks from the menu, which is better than a
|
|
72
|
+
* guess that books the wrong cut at the wrong price.
|
|
73
|
+
*/
|
|
74
|
+
function grownUpEquivalent(config, last, candidates, age) {
|
|
75
|
+
const fitting = candidates.filter((service) => service.id !== last.id && fitsAge(service, age));
|
|
76
|
+
const sameCategory = fitting.filter((service) => service.category === last.category);
|
|
77
|
+
const banded = sameCategory.filter((service) => service.ageMinYears !== void 0 || service.ageMaxYears !== void 0);
|
|
78
|
+
if (banded.length === 1) return banded[0];
|
|
79
|
+
if (sameCategory.length === 1) return sameCategory[0];
|
|
80
|
+
const grownUp = adultEquivalent(config, last, fitting);
|
|
81
|
+
return grownUp.length === 1 ? grownUp[0] : null;
|
|
82
|
+
}
|
|
83
|
+
function createAge(config) {
|
|
84
|
+
const labels = resolveLabels(config.locale, config.labels);
|
|
85
|
+
return {
|
|
86
|
+
ageOnDay,
|
|
87
|
+
fitsAge,
|
|
88
|
+
ageLabel: (range) => ageLabel(labels, range),
|
|
89
|
+
grownUpEquivalent: (last, candidates, age) => grownUpEquivalent(config, last, candidates, age)
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
//#endregion
|
|
93
|
+
export { ageOnDay, createAge, fitsAge };
|
|
94
|
+
|
|
95
|
+
//# sourceMappingURL=age.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"age.mjs","names":[],"sources":["../../src/core/age.ts"],"sourcesContent":["/**\n * How old a child is ON THE APPOINTMENT DAY — the one age that decides which\n * haircut and which price they get.\n *\n * The profile keeps a birth YEAR and, since SP10, optionally a birth MONTH —\n * never a full date (data minimisation for children). So the answer is a\n * RANGE: with the month it is exact (Medal's own `ageOnDay` counts the\n * birthday as the first of the month, and this agrees with it), without it\n * the child is one of two ages depending on whether the birthday has been yet\n * this year, which the card says honestly as «7–8 år».\n *\n * `dayKey` is `clock.dayKey`'s `2026-08-29` — the SALON's calendar date, not the\n * viewer's, for the reason every date on this site is.\n *\n * Pure and dependency-free, so the wizard (a browser bundle) and the portal (a\n * server render) read the same number.\n *\n * `ageOnDay` and `fitsAge` are config-free; `createAge(config)` adds the two\n * that are not — the label's words, and which adult group a kids' service\n * grows up into (`categories[].adultEquivalent`, which replaced a hard-coded\n * table of Norwegian service names).\n */\n\nimport { adultEquivalent } from './categories';\nimport type { BookingConfig } from './config';\nimport { type BookingLabels, fill, resolveLabels } from './labels';\n\ntype AgeConfig = Pick<BookingConfig, 'categories' | 'fallbackCategory' | 'locale' | 'labels'>;\n\nexport interface AgeRange {\n /** Inclusive; equal to `max` when the age is exact. */\n min: number;\n max: number;\n}\n\nexport function ageOnDay(\n birthYear: number,\n birthMonth: number | null | undefined,\n dayKey: string\n): AgeRange | null {\n const year = Number(dayKey.slice(0, 4));\n const month = Number(dayKey.slice(5, 7));\n if (!Number.isInteger(year) || !Number.isInteger(month) || !Number.isInteger(birthYear)) {\n return null;\n }\n const yearDiff = year - birthYear;\n if (yearDiff < 0) return null;\n const hasMonth =\n typeof birthMonth === 'number' &&\n Number.isInteger(birthMonth) &&\n birthMonth >= 1 &&\n birthMonth <= 12;\n if (hasMonth) {\n const exact = month < birthMonth ? yearDiff - 1 : yearDiff;\n return exact < 0 ? null : { min: exact, max: exact };\n }\n return { min: Math.max(0, yearDiff - 1), max: yearDiff };\n}\n\n/** «7 år», or «7–8 år» when only the year is known — in the words of `labels`. */\nfunction ageLabel(labels: Readonly<BookingLabels>, range: AgeRange): string {\n return range.min === range.max\n ? fill(labels['age.exact'], { min: range.min })\n : fill(labels['age.range'], { min: range.min, max: range.max });\n}\n\n/** A service's age range, as the wizard carries it (`WizardService`). */\nexport interface AgeBounds {\n ageMinYears?: number;\n ageMaxYears?: number;\n}\n\n/**\n * Whether a service can be suggested for a child of this age. Only a CERTAIN\n * miss rules it out: a child who is «6–7 år» is not too old for a service up\n * to 6, because they may still be six on the day. `null` — nobody's age is\n * known (a guest, a grown-up) — fits everything.\n */\nexport function fitsAge(service: AgeBounds, age: AgeRange | null): boolean {\n if (age === null) return true;\n if (service.ageMaxYears !== undefined && age.min > service.ageMaxYears) return false;\n if (service.ageMinYears !== undefined && age.max < service.ageMinYears) return false;\n return true;\n}\n\n/**\n * What «Samme som sist» becomes for a child who has outgrown their last cut:\n * the one service in the same category that fits their age now — an\n * age-banded one first (a «Barnehageklipp» child is a «Barneklipp» child at\n * seven) — or — where the\n * category holds none — the grown-up cut its group's `adultEquivalent` points at (by\n * name: «gutt» → the men's group, «jente» → the women's), again only when\n * exactly one fits. Anything less\n * certain is `null`: the parent picks from the menu, which is better than a\n * guess that books the wrong cut at the wrong price.\n */\nfunction grownUpEquivalent<S extends AgeBounds & { id: string; name: string; category: string }>(\n config: AgeConfig,\n last: S,\n candidates: readonly S[],\n age: AgeRange | null\n): S | null {\n const fitting = candidates.filter((service) => service.id !== last.id && fitsAge(service, age));\n const sameCategory = fitting.filter((service) => service.category === last.category);\n // A service the salon banded by age is the likelier «next size up» than one\n // it did not — «Barneklipp 7–12» over «Hull i ørene» — so those are asked first.\n const banded = sameCategory.filter(\n (service) => service.ageMinYears !== undefined || service.ageMaxYears !== undefined\n );\n if (banded.length === 1) return banded[0];\n if (sameCategory.length === 1) return sameCategory[0];\n const grownUp = adultEquivalent(config, last, fitting);\n return grownUp.length === 1 ? grownUp[0] : null;\n}\n\nexport interface Age {\n ageOnDay: typeof ageOnDay;\n fitsAge: typeof fitsAge;\n ageLabel(range: AgeRange): string;\n grownUpEquivalent<S extends AgeBounds & { id: string; name: string; category: string }>(\n last: S,\n candidates: readonly S[],\n age: AgeRange | null\n ): S | null;\n}\n\nexport function createAge(config: AgeConfig): Age {\n const labels = resolveLabels(config.locale, config.labels);\n return {\n ageOnDay,\n fitsAge,\n ageLabel: (range) => ageLabel(labels, range),\n grownUpEquivalent: (last, candidates, age) => grownUpEquivalent(config, last, candidates, age),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,SAAgB,SACd,WACA,YACA,QACiB;CACjB,MAAM,OAAO,OAAO,OAAO,MAAM,GAAG,CAAC,CAAC;CACtC,MAAM,QAAQ,OAAO,OAAO,MAAM,GAAG,CAAC,CAAC;CACvC,IAAI,CAAC,OAAO,UAAU,IAAI,KAAK,CAAC,OAAO,UAAU,KAAK,KAAK,CAAC,OAAO,UAAU,SAAS,GACpF,OAAO;CAET,MAAM,WAAW,OAAO;CACxB,IAAI,WAAW,GAAG,OAAO;CAMzB,IAJE,OAAO,eAAe,YACtB,OAAO,UAAU,UAAU,KAC3B,cAAc,KACd,cAAc,IACF;EACZ,MAAM,QAAQ,QAAQ,aAAa,WAAW,IAAI;EAClD,OAAO,QAAQ,IAAI,OAAO;GAAE,KAAK;GAAO,KAAK;EAAM;CACrD;CACA,OAAO;EAAE,KAAK,KAAK,IAAI,GAAG,WAAW,CAAC;EAAG,KAAK;CAAS;AACzD;;AAGA,SAAS,SAAS,QAAiC,OAAyB;CAC1E,OAAO,MAAM,QAAQ,MAAM,MACvB,KAAK,OAAO,cAAc,EAAE,KAAK,MAAM,IAAI,CAAC,IAC5C,KAAK,OAAO,cAAc;EAAE,KAAK,MAAM;EAAK,KAAK,MAAM;CAAI,CAAC;AAClE;;;;;;;AAcA,SAAgB,QAAQ,SAAoB,KAA+B;CACzE,IAAI,QAAQ,MAAM,OAAO;CACzB,IAAI,QAAQ,gBAAgB,KAAA,KAAa,IAAI,MAAM,QAAQ,aAAa,OAAO;CAC/E,IAAI,QAAQ,gBAAgB,KAAA,KAAa,IAAI,MAAM,QAAQ,aAAa,OAAO;CAC/E,OAAO;AACT;;;;;;;;;;;;AAaA,SAAS,kBACP,QACA,MACA,YACA,KACU;CACV,MAAM,UAAU,WAAW,QAAQ,YAAY,QAAQ,OAAO,KAAK,MAAM,QAAQ,SAAS,GAAG,CAAC;CAC9F,MAAM,eAAe,QAAQ,QAAQ,YAAY,QAAQ,aAAa,KAAK,QAAQ;CAGnF,MAAM,SAAS,aAAa,QACzB,YAAY,QAAQ,gBAAgB,KAAA,KAAa,QAAQ,gBAAgB,KAAA,CAC5E;CACA,IAAI,OAAO,WAAW,GAAG,OAAO,OAAO;CACvC,IAAI,aAAa,WAAW,GAAG,OAAO,aAAa;CACnD,MAAM,UAAU,gBAAgB,QAAQ,MAAM,OAAO;CACrD,OAAO,QAAQ,WAAW,IAAI,QAAQ,KAAK;AAC7C;AAaA,SAAgB,UAAU,QAAwB;CAChD,MAAM,SAAS,cAAc,OAAO,QAAQ,OAAO,MAAM;CACzD,OAAO;EACL;EACA;EACA,WAAW,UAAU,SAAS,QAAQ,KAAK;EAC3C,oBAAoB,MAAM,YAAY,QAAQ,kBAAkB,QAAQ,MAAM,YAAY,GAAG;CAC/F;AACF"}
|