@composable-os/pack-memberships 0.1.0-beta.10 → 0.1.0-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/blocks/memberships-mine/mine.d.ts +6 -4
- package/dist/blocks/memberships-mine/mine.js +85 -23
- package/dist/blocks/memberships-native-mine/mine-screen.d.ts +6 -2
- package/dist/blocks/memberships-native-mine/mine-screen.js +30 -6
- package/dist/blocks/memberships-passes/passes.d.ts +6 -1
- package/dist/blocks/memberships-passes/passes.js +75 -8
- package/dist/blocks/memberships-plans/plans.d.ts +6 -1
- package/dist/blocks/memberships-plans/plans.js +71 -6
- package/dist/blocks/memberships-staff-holdings/holdings.d.ts +10 -1
- package/dist/blocks/memberships-staff-holdings/holdings.js +31 -3
- package/dist/client/index.d.ts +593 -27
- package/dist/client/index.js +245 -9
- package/dist/dashboards.d.ts +5 -0
- package/dist/dashboards.js +165 -0
- package/dist/index.d.ts +290 -23
- package/dist/index.js +228 -27
- package/dist/tools.d.ts +4 -5
- package/dist/tools.js +38 -24
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -16,10 +16,19 @@
|
|
|
16
16
|
// - a membership and a pass hold an `allowance` (ADRs 0493, 0494): uses per week, month or in
|
|
17
17
|
// all, the class types, weekdays and times of day they pay for, spent by a booking of their own
|
|
18
18
|
// Person, refused past the limit by the database for every actor;
|
|
19
|
+
// - a member changes plan on the web (an upgrade now, prorated, applied once paid; a downgrade from
|
|
20
|
+
// the next period) and staff pause a membership for a set time within the plan's bounds
|
|
21
|
+
// (`recurring.pause`): the host's `subscription.change` and `subscription.pause`, asked of the
|
|
22
|
+
// provider, followed from its verified events (ADRs 0530, 0531). The membership's terms follow
|
|
23
|
+
// the plan when the change takes effect; while paused it gives and spends nothing;
|
|
24
|
+
// - a new member may end their membership in the business's cooling-off period
|
|
25
|
+
// (`recurring.coolingOff`, the `coolingOffDays` setting, ADR 0647): the host's
|
|
26
|
+
// `subscription.coolOff`, every paid period owed back, each refund approved by a person;
|
|
19
27
|
// - every term of a membership or a pass is read-only: only the host (and this pack's own staff
|
|
20
28
|
// tools, which a person calls) writes it, never a caller of the generic record operations.
|
|
21
29
|
// The tools in tools.ts compose the host's operations and hold no rule of their own.
|
|
22
30
|
import { defineExtension } from "@composable-os/sdk";
|
|
31
|
+
import { membershipsDashboards } from "./dashboards.js";
|
|
23
32
|
import { buy, givePass, holdings, mine, passTypes, plans, voidPass } from "./tools.js";
|
|
24
33
|
/** Weekdays as the host's local time numbers them (ISO: 1 is Monday), for an off-peak limit. */
|
|
25
34
|
const WEEKDAYS = [
|
|
@@ -31,17 +40,58 @@ const WEEKDAYS = [
|
|
|
31
40
|
{ value: "6", label: "Saturday" },
|
|
32
41
|
{ value: "7", label: "Sunday" },
|
|
33
42
|
];
|
|
43
|
+
const PER = [
|
|
44
|
+
{ value: "week", label: "A week" },
|
|
45
|
+
{ value: "month", label: "A month" },
|
|
46
|
+
];
|
|
47
|
+
/**
|
|
48
|
+
* Gym dues (the provider's "Fitness Centers - Dues and Membership Fees"): taxed only once a human
|
|
49
|
+
* admin turns tax on (ADR 0479). Whether the provider needs the gym's address as the place is an
|
|
50
|
+
* open check of the test-mode runbook.
|
|
51
|
+
*/
|
|
52
|
+
const GYM_DUES = { code: "txcd_50021001" };
|
|
53
|
+
/**
|
|
54
|
+
* Where agreement may be needed (stage 44, ADR 0641): the business attaches its documents (its
|
|
55
|
+
* terms, a waiver) to "membership"; nothing is needed until it does. The plans and passes blocks
|
|
56
|
+
* show what is due and let a person agree (stage 44 step 5).
|
|
57
|
+
*/
|
|
58
|
+
const BUYING = {
|
|
59
|
+
point: "membership",
|
|
60
|
+
label: "Buying a membership or a pass",
|
|
61
|
+
suggests: ["terms", "waiver", "health", "guardian"],
|
|
62
|
+
};
|
|
34
63
|
const ON_SALE = [
|
|
35
64
|
{ value: "draft", label: "Draft" },
|
|
36
65
|
{ value: "on_sale", label: "On sale" },
|
|
37
66
|
{ value: "retired", label: "No longer sold" },
|
|
38
67
|
];
|
|
68
|
+
/** What a plan or a pass type pays for: classes, one-to-one sessions (stage 49), or both. */
|
|
69
|
+
const COVERS = [
|
|
70
|
+
{ value: "classes", label: "Classes" },
|
|
71
|
+
{ value: "sessions", label: "One-to-one sessions" },
|
|
72
|
+
];
|
|
39
73
|
/**
|
|
40
|
-
* What a plan or a pass type allows, copied onto the membership or the pass it grants:
|
|
41
|
-
*
|
|
42
|
-
*
|
|
74
|
+
* What a plan or a pass type allows, copied onto the membership or the pass it grants: what it
|
|
75
|
+
* pays for (empty: classes only, as before sessions existed), the class types (empty: every one)
|
|
76
|
+
* and the services (empty: every one) it pays for, weekdays (empty: every day) and a time of day,
|
|
77
|
+
* in minutes after local midnight (empty: no bound).
|
|
43
78
|
*/
|
|
44
79
|
const limits = (readOnly) => ({
|
|
80
|
+
covers: {
|
|
81
|
+
type: "multiSelect",
|
|
82
|
+
label: "Pays for",
|
|
83
|
+
options: COVERS,
|
|
84
|
+
description: "Classes, one-to-one sessions (Bookings' appointments), or both. Empty: classes only.",
|
|
85
|
+
...(readOnly ? { readOnly: true } : {}),
|
|
86
|
+
},
|
|
87
|
+
services: {
|
|
88
|
+
type: "relation",
|
|
89
|
+
label: "Services",
|
|
90
|
+
to: "bookings.service",
|
|
91
|
+
many: true,
|
|
92
|
+
description: "The one-to-one sessions it pays for, when it pays for sessions. Empty: every one.",
|
|
93
|
+
...(readOnly ? { readOnly: true } : {}),
|
|
94
|
+
},
|
|
45
95
|
classTypes: {
|
|
46
96
|
type: "relation",
|
|
47
97
|
label: "Class types",
|
|
@@ -80,15 +130,33 @@ const limits = (readOnly) => ({
|
|
|
80
130
|
* What a holder pays for: stage 31's bookings (`bookings.booking`, whose `paidBy` lists this pack),
|
|
81
131
|
* by the class type, the local weekday and the local minute the host copies onto the booking.
|
|
82
132
|
*/
|
|
83
|
-
const
|
|
133
|
+
const SPENDS_ON_CLASSES = {
|
|
84
134
|
object: "bookings.booking",
|
|
85
135
|
when: [
|
|
136
|
+
// A booking is a class: paid for unless the holder pays for sessions only (empty: classes).
|
|
137
|
+
{ value: "classes", in: "covers" },
|
|
86
138
|
{ field: "classType", in: "classTypes" },
|
|
87
139
|
{ field: "weekday", in: "weekdays" },
|
|
88
140
|
{ field: "minute", atLeast: "fromMinute" },
|
|
89
141
|
{ field: "minute", below: "untilMinute" },
|
|
90
142
|
],
|
|
91
143
|
};
|
|
144
|
+
/**
|
|
145
|
+
* Stage 49's appointments (`bookings.appointment`, whose `paidBy` lists this pack), by the service
|
|
146
|
+
* the host copies onto the appointment and its local weekday and minute. Only a holder that says
|
|
147
|
+
* it pays for sessions does (`empty: "none"`): a class pass never pays for a session (ADR 0764).
|
|
148
|
+
*/
|
|
149
|
+
const SPENDS_ON_SESSIONS = {
|
|
150
|
+
object: "bookings.appointment",
|
|
151
|
+
when: [
|
|
152
|
+
{ value: "sessions", in: "covers", empty: "none" },
|
|
153
|
+
{ field: "serviceId", in: "services" },
|
|
154
|
+
{ field: "weekday", in: "weekdays" },
|
|
155
|
+
{ field: "minute", atLeast: "fromMinute" },
|
|
156
|
+
{ field: "minute", below: "untilMinute" },
|
|
157
|
+
],
|
|
158
|
+
};
|
|
159
|
+
const SPENDS_ON = [SPENDS_ON_CLASSES, SPENDS_ON_SESSIONS];
|
|
92
160
|
const RUNNING = ["trialing", "active", "past_due", "unpaid", "paused"];
|
|
93
161
|
/** A membership follows its subscription: the host moves it from any running state to another. */
|
|
94
162
|
const followMoves = [
|
|
@@ -106,22 +174,20 @@ export default defineExtension({
|
|
|
106
174
|
label: "Memberships",
|
|
107
175
|
description: "Membership plans paid every month and class passes bought once, with what each allows " +
|
|
108
176
|
"and what a member has left.",
|
|
109
|
-
// A plan and a pass name the class types they pay for: Programs' (stage 31 extends them)
|
|
110
|
-
|
|
177
|
+
// A plan and a pass name the class types they pay for: Programs' (stage 31 extends them); and
|
|
178
|
+
// the services (Bookings' one-to-one sessions, stage 49), so Bookings is installed first. What
|
|
179
|
+
// they pay for, classes and sessions, is Bookings' anyway.
|
|
180
|
+
requires: ["programs", "bookings"],
|
|
111
181
|
permissions: {
|
|
112
182
|
read: ["person", "programs.classtype"],
|
|
183
|
+
// record.* and my.* are not listed: they are granted by object (Memberships' own, and the
|
|
184
|
+
// read list above), and a listed one would reach every object.
|
|
113
185
|
operations: [
|
|
114
186
|
"public.list",
|
|
115
|
-
"public.get",
|
|
116
|
-
"my.list",
|
|
117
|
-
"my.get",
|
|
118
|
-
"record.create",
|
|
119
|
-
"record.update",
|
|
120
|
-
"record.get",
|
|
121
|
-
"record.list",
|
|
122
|
-
"allowance.get",
|
|
123
187
|
"allowance.list",
|
|
124
188
|
"order.start",
|
|
189
|
+
// The member's own id and the children staff linked to them (ADR 0540).
|
|
190
|
+
"me.family",
|
|
125
191
|
],
|
|
126
192
|
modules: ["ops"],
|
|
127
193
|
},
|
|
@@ -157,10 +223,7 @@ export default defineExtension({
|
|
|
157
223
|
label: "Per",
|
|
158
224
|
required: true,
|
|
159
225
|
default: "week",
|
|
160
|
-
options:
|
|
161
|
-
{ value: "week", label: "A week" },
|
|
162
|
-
{ value: "month", label: "A month" },
|
|
163
|
-
],
|
|
226
|
+
options: PER,
|
|
164
227
|
},
|
|
165
228
|
...limits(false),
|
|
166
229
|
trialDays: {
|
|
@@ -171,6 +234,22 @@ export default defineExtension({
|
|
|
171
234
|
step: 1,
|
|
172
235
|
description: "Empty or 0: charged from the start. A person gets one trial on any plan.",
|
|
173
236
|
},
|
|
237
|
+
pauseMinDays: {
|
|
238
|
+
type: "number",
|
|
239
|
+
label: "Shortest pause (days)",
|
|
240
|
+
min: 1,
|
|
241
|
+
max: 366,
|
|
242
|
+
step: 1,
|
|
243
|
+
description: "Staff pause a membership for at least this long. Empty: 1 day.",
|
|
244
|
+
},
|
|
245
|
+
pauseMaxDays: {
|
|
246
|
+
type: "number",
|
|
247
|
+
label: "Longest pause (days)",
|
|
248
|
+
min: 1,
|
|
249
|
+
max: 366,
|
|
250
|
+
step: 1,
|
|
251
|
+
description: "And at most this long. Empty: a year.",
|
|
252
|
+
},
|
|
174
253
|
status: { type: "select", label: "Status", default: "draft", options: ON_SALE },
|
|
175
254
|
},
|
|
176
255
|
public: {
|
|
@@ -191,13 +270,18 @@ export default defineExtension({
|
|
|
191
270
|
},
|
|
192
271
|
sellable: {
|
|
193
272
|
price: "price",
|
|
194
|
-
|
|
195
|
-
//
|
|
196
|
-
|
|
197
|
-
tax: { code: "txcd_50021001" },
|
|
273
|
+
tax: GYM_DUES,
|
|
274
|
+
// In the finance reports (ADR 0792): a paid period is earned day by day over it.
|
|
275
|
+
finance: { category: { key: "memberships", label: "Memberships" }, earned: "over_period" },
|
|
198
276
|
recurring: {
|
|
199
277
|
interval: "month",
|
|
200
278
|
trialDays: "trialDays",
|
|
279
|
+
// Staff pause a membership for a set time (decision 10, ADR 0531): nothing charged, no
|
|
280
|
+
// classes, until the provider resumes it on its date.
|
|
281
|
+
pause: { minDays: "pauseMinDays", maxDays: "pauseMaxDays" },
|
|
282
|
+
// A new member may end it within the business's cooling-off days for a full refund,
|
|
283
|
+
// each refund approved by a person (stage 44 step 7, decision 11, ADR 0647).
|
|
284
|
+
coolingOff: { setting: "coolingOffDays" },
|
|
201
285
|
// What a subscription to it gives its holder, kept in step by the host (ADR 0510).
|
|
202
286
|
grants: {
|
|
203
287
|
object: "membership",
|
|
@@ -209,6 +293,8 @@ export default defineExtension({
|
|
|
209
293
|
title: "item.title",
|
|
210
294
|
uses: "item.uses",
|
|
211
295
|
per: "item.per",
|
|
296
|
+
covers: "item.covers",
|
|
297
|
+
services: "item.services",
|
|
212
298
|
classTypes: "item.classTypes",
|
|
213
299
|
weekdays: "item.weekdays",
|
|
214
300
|
fromMinute: "item.fromMinute",
|
|
@@ -227,6 +313,8 @@ export default defineExtension({
|
|
|
227
313
|
},
|
|
228
314
|
},
|
|
229
315
|
},
|
|
316
|
+
// The host asks when a subscription to a plan or an order for a pass type starts (ADR 0644).
|
|
317
|
+
agreements: { ...BUYING, inlineStep: true },
|
|
230
318
|
},
|
|
231
319
|
membership: {
|
|
232
320
|
label: "Membership",
|
|
@@ -255,10 +343,7 @@ export default defineExtension({
|
|
|
255
343
|
type: "select",
|
|
256
344
|
label: "Per",
|
|
257
345
|
readOnly: true,
|
|
258
|
-
options:
|
|
259
|
-
{ value: "week", label: "A week" },
|
|
260
|
-
{ value: "month", label: "A month" },
|
|
261
|
-
],
|
|
346
|
+
options: PER,
|
|
262
347
|
},
|
|
263
348
|
...limits(true),
|
|
264
349
|
from: { type: "datetime", label: "From", readOnly: true },
|
|
@@ -283,9 +368,13 @@ export default defineExtension({
|
|
|
283
368
|
},
|
|
284
369
|
},
|
|
285
370
|
states: { field: "status", initial: "active", moves: followMoves },
|
|
371
|
+
// A member reads their own; a parent or guardian staff linked to a child reads the child's
|
|
372
|
+
// too, read only (ADR 0540): what the child has left to book with.
|
|
286
373
|
customer: {
|
|
287
374
|
field: "person",
|
|
375
|
+
guardians: {},
|
|
288
376
|
read: [
|
|
377
|
+
"person",
|
|
289
378
|
"title",
|
|
290
379
|
"plan",
|
|
291
380
|
"uses",
|
|
@@ -373,7 +462,7 @@ export default defineExtension({
|
|
|
373
462
|
},
|
|
374
463
|
sellable: {
|
|
375
464
|
price: "price",
|
|
376
|
-
tax:
|
|
465
|
+
tax: GYM_DUES,
|
|
377
466
|
grants: {
|
|
378
467
|
object: "pass",
|
|
379
468
|
set: {
|
|
@@ -382,6 +471,8 @@ export default defineExtension({
|
|
|
382
471
|
title: "line.title",
|
|
383
472
|
order: "order",
|
|
384
473
|
uses: "item.uses",
|
|
474
|
+
covers: "item.covers",
|
|
475
|
+
services: "item.services",
|
|
385
476
|
classTypes: "item.classTypes",
|
|
386
477
|
weekdays: "item.weekdays",
|
|
387
478
|
fromMinute: "item.fromMinute",
|
|
@@ -391,7 +482,11 @@ export default defineExtension({
|
|
|
391
482
|
valid: { from: "from", until: "until", days: "item.validDays" },
|
|
392
483
|
},
|
|
393
484
|
onePerPerson: "onePerPerson",
|
|
485
|
+
// In the finance reports (ADR 0792, decision 4): earned class by class as the pass is
|
|
486
|
+
// used, the rest when it expires.
|
|
487
|
+
finance: { category: { key: "passes", label: "Class passes" }, earned: "per_use" },
|
|
394
488
|
},
|
|
489
|
+
agreements: { ...BUYING, inlineStep: true },
|
|
395
490
|
},
|
|
396
491
|
pass: {
|
|
397
492
|
label: "Pass",
|
|
@@ -446,9 +541,16 @@ export default defineExtension({
|
|
|
446
541
|
{ from: "active", to: "void", by: ["host"], tools: ["voidPass"], final: true },
|
|
447
542
|
],
|
|
448
543
|
},
|
|
544
|
+
// A pass given by staff by hand (givePass) starts a pass as buying one does: the same point,
|
|
545
|
+
// asked by the engine when a caller makes one (stage 44, ADR 0644). A pass a paid order
|
|
546
|
+
// grants is the host's, asked when the order started.
|
|
547
|
+
agreements: { ...BUYING, enter: ["active"], person: "person", inlineStep: true },
|
|
548
|
+
// As a membership: their own, and a linked child's for a guardian, read only (ADR 0540).
|
|
449
549
|
customer: {
|
|
450
550
|
field: "person",
|
|
551
|
+
guardians: {},
|
|
451
552
|
read: [
|
|
553
|
+
"person",
|
|
452
554
|
"title",
|
|
453
555
|
"passtype",
|
|
454
556
|
"uses",
|
|
@@ -500,6 +602,13 @@ export default defineExtension({
|
|
|
500
602
|
sort: { field: "until", direction: "asc" },
|
|
501
603
|
columns: ["person", "title", "payer", "until"],
|
|
502
604
|
},
|
|
605
|
+
paused: {
|
|
606
|
+
label: "Paused",
|
|
607
|
+
object: "memberships.membership",
|
|
608
|
+
filter: { field: "status", op: "eq", value: "paused" },
|
|
609
|
+
sort: { field: "from", direction: "desc" },
|
|
610
|
+
columns: ["person", "title", "payer", "from"],
|
|
611
|
+
},
|
|
503
612
|
endingThisMonth: {
|
|
504
613
|
label: "Ending this month",
|
|
505
614
|
object: "memberships.membership",
|
|
@@ -512,6 +621,19 @@ export default defineExtension({
|
|
|
512
621
|
sort: { field: "until", direction: "asc" },
|
|
513
622
|
columns: ["person", "title", "status", "until"],
|
|
514
623
|
},
|
|
624
|
+
passesExpiringThisWeek: {
|
|
625
|
+
label: "Passes expiring this week",
|
|
626
|
+
object: "memberships.pass",
|
|
627
|
+
filter: {
|
|
628
|
+
and: [
|
|
629
|
+
{ field: "status", op: "eq", value: "active" },
|
|
630
|
+
{ field: "until", op: "gte", value: { $relative: "now" } },
|
|
631
|
+
{ field: "until", op: "lt", value: { $relative: "startOfNextWeek" } },
|
|
632
|
+
],
|
|
633
|
+
},
|
|
634
|
+
sort: { field: "until", direction: "asc" },
|
|
635
|
+
columns: ["person", "title", "uses", "until"],
|
|
636
|
+
},
|
|
515
637
|
passesExpiringThisMonth: {
|
|
516
638
|
label: "Passes expiring this month",
|
|
517
639
|
object: "memberships.pass",
|
|
@@ -555,5 +677,84 @@ export default defineExtension({
|
|
|
555
677
|
// Giving or voiding a pass by hand: a person on the staff, with this permission, which admins
|
|
556
678
|
// and members hold and a human admin may grant to anyone else (ADR 0449).
|
|
557
679
|
grantable: ["memberships:passes"],
|
|
680
|
+
// What a journey can start or stop on (stage 53, ADR 0802): the host records the last time each
|
|
681
|
+
// member had each, in the write's batch. A trial that turns into a paid membership is not a
|
|
682
|
+
// trial ended: that is the member joining. A payment caught up, or a pause ended, is neither.
|
|
683
|
+
journeySignals: {
|
|
684
|
+
started: {
|
|
685
|
+
label: "Membership started",
|
|
686
|
+
description: "A membership begins, on trial or paid.",
|
|
687
|
+
object: "membership",
|
|
688
|
+
},
|
|
689
|
+
joined: {
|
|
690
|
+
label: "Joined after a trial",
|
|
691
|
+
description: "A trial becomes a paid membership.",
|
|
692
|
+
object: "membership",
|
|
693
|
+
enters: ["active"],
|
|
694
|
+
from: ["trialing"],
|
|
695
|
+
created: false,
|
|
696
|
+
},
|
|
697
|
+
ended: {
|
|
698
|
+
label: "Membership ended",
|
|
699
|
+
description: "A membership ends.",
|
|
700
|
+
object: "membership",
|
|
701
|
+
enters: ["ended"],
|
|
702
|
+
},
|
|
703
|
+
trialEnded: {
|
|
704
|
+
label: "Trial ended without joining",
|
|
705
|
+
description: "A trial stops without becoming a paid membership.",
|
|
706
|
+
object: "membership",
|
|
707
|
+
enters: ["past_due", "unpaid", "paused", "ended"],
|
|
708
|
+
from: ["trialing"],
|
|
709
|
+
created: false,
|
|
710
|
+
},
|
|
711
|
+
passStarted: {
|
|
712
|
+
label: "Pass started",
|
|
713
|
+
description: "A member gets a pass: bought, or given by staff.",
|
|
714
|
+
object: "pass",
|
|
715
|
+
},
|
|
716
|
+
},
|
|
717
|
+
// Cooling off (stage 44 step 7, decision 11, ADR 0647): the business's own number, for every
|
|
718
|
+
// plan. Off until a person sets it; what any law requires is the business's to confirm.
|
|
719
|
+
settings: {
|
|
720
|
+
coolingOffDays: {
|
|
721
|
+
type: "number",
|
|
722
|
+
label: "Cooling-off period (days)",
|
|
723
|
+
description: "A new member may end their membership within this many days of joining, counted to " +
|
|
724
|
+
"the end of the last day, for a full refund of what they paid; each refund is approved " +
|
|
725
|
+
"by a person who may refund. Not for passes, or for members moving over with a " +
|
|
726
|
+
"continuation offer; once per member. 0: none. Say it in your membership terms; " +
|
|
727
|
+
"whether a law asks for one, and how long, is for your lawyer. Shortening it never " +
|
|
728
|
+
"shortens the period of someone who joined before.",
|
|
729
|
+
default: 0,
|
|
730
|
+
min: 0,
|
|
731
|
+
max: 30,
|
|
732
|
+
personApproves: true,
|
|
733
|
+
},
|
|
734
|
+
},
|
|
558
735
|
tools: { plans, passTypes, buy, mine, holdings, givePass, voidPass },
|
|
736
|
+
dashboards: membershipsDashboards,
|
|
737
|
+
// Staff screens in the product's admin (stage 47, ADR 0660): a person's memberships and passes,
|
|
738
|
+
// a tab on the Person, for whoever may read them and give and void a pass by hand (any member
|
|
739
|
+
// of staff; a viewer reads no further than the record page).
|
|
740
|
+
screens: {
|
|
741
|
+
holdings: {
|
|
742
|
+
label: "Memberships",
|
|
743
|
+
block: "memberships-staff-holdings",
|
|
744
|
+
export: "PersonMemberships",
|
|
745
|
+
opens: ["holdings", "givePass"],
|
|
746
|
+
record: { object: "person", as: "personId" },
|
|
747
|
+
},
|
|
748
|
+
},
|
|
749
|
+
// Its section of My account (stage 48, ADR 0710): a member's memberships and passes, and a linked
|
|
750
|
+
// child's (both open to guardians), shown once they or the child hold one.
|
|
751
|
+
portal: {
|
|
752
|
+
memberships: {
|
|
753
|
+
label: "Memberships and passes",
|
|
754
|
+
web: { block: "memberships-mine", export: "MyMemberships" },
|
|
755
|
+
native: { block: "memberships-native-mine", export: "MyMembershipsScreen" },
|
|
756
|
+
order: 20,
|
|
757
|
+
has: ["memberships.membership", "memberships.pass"],
|
|
758
|
+
},
|
|
759
|
+
},
|
|
559
760
|
});
|
package/dist/tools.d.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
import { z } from "@composable-os/sdk";
|
|
2
|
-
export declare const PLAN = "memberships.plan";
|
|
3
|
-
export declare const MEMBERSHIP = "memberships.membership";
|
|
4
|
-
export declare const PASSTYPE = "memberships.passtype";
|
|
5
|
-
export declare const PASS = "memberships.pass";
|
|
6
2
|
export declare const plans: import("@composable-os/sdk").ToolSpec<z.ZodObject<{}, z.core.$strip>, z.ZodObject<{
|
|
7
3
|
plans: z.ZodArray<z.ZodObject<{
|
|
8
4
|
classTypes: z.ZodArray<z.ZodString>;
|
|
@@ -43,6 +39,7 @@ export declare const passTypes: import("@composable-os/sdk").ToolSpec<z.ZodObjec
|
|
|
43
39
|
export declare const buy: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
|
|
44
40
|
passTypeId: z.ZodString;
|
|
45
41
|
email: z.ZodOptional<z.ZodString>;
|
|
42
|
+
agreements: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
46
43
|
}, z.core.$strip>, z.ZodObject<{
|
|
47
44
|
id: z.ZodString;
|
|
48
45
|
state: z.ZodString;
|
|
@@ -50,7 +47,9 @@ export declare const buy: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
|
|
|
50
47
|
total: z.ZodNumber;
|
|
51
48
|
token: z.ZodNullable<z.ZodString>;
|
|
52
49
|
}, z.core.$strip>>;
|
|
53
|
-
export declare const mine: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
|
|
50
|
+
export declare const mine: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
|
|
51
|
+
personId: z.ZodOptional<z.ZodString>;
|
|
52
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
54
53
|
holdings: z.ZodArray<z.ZodObject<{
|
|
55
54
|
classTypes: z.ZodArray<z.ZodString>;
|
|
56
55
|
weekdays: z.ZodArray<z.ZodString>;
|
package/dist/tools.js
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
// on are the host's (`sellable`, `recurring.grants`, `allowance`). What is left is the host's
|
|
5
5
|
// count (`allowance.get`). A tool asks, and reports what the host answered.
|
|
6
6
|
import { defineTool, OpsCallError, z } from "@composable-os/sdk";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
const PLAN = "memberships.plan";
|
|
8
|
+
const MEMBERSHIP = "memberships.membership";
|
|
9
|
+
const PASSTYPE = "memberships.passtype";
|
|
10
|
+
const PASS = "memberships.pass";
|
|
11
11
|
const id = z.string().min(1).max(64);
|
|
12
12
|
const text = (value) => value === null || value === undefined || value === "" ? null : String(value);
|
|
13
13
|
const num = (value) => typeof value === "number" ? value : value == null || value === "" ? null : Number(value);
|
|
@@ -33,6 +33,16 @@ const limitsOf = (v) => ({
|
|
|
33
33
|
untilMinute: num(v.untilMinute),
|
|
34
34
|
});
|
|
35
35
|
// --- What is on sale -----------------------------------------------------------------------------
|
|
36
|
+
/** What a plan and a pass type on sale both say of themselves. */
|
|
37
|
+
const onSale = (p) => ({
|
|
38
|
+
id: p.id,
|
|
39
|
+
title: text(p.values.title),
|
|
40
|
+
summary: text(p.values.summary),
|
|
41
|
+
description: text(p.values.description),
|
|
42
|
+
price: num(p.values.price),
|
|
43
|
+
uses: num(p.values.uses),
|
|
44
|
+
...limitsOf(p.values),
|
|
45
|
+
});
|
|
36
46
|
export const plans = defineTool({
|
|
37
47
|
description: "The membership plans on sale: each plan's title, a line on what it gives, description, " +
|
|
38
48
|
"price per month (in the major unit of `currency`), classes per week or month (null: " +
|
|
@@ -63,15 +73,9 @@ export const plans = defineTool({
|
|
|
63
73
|
});
|
|
64
74
|
return {
|
|
65
75
|
plans: page.items.map((p) => ({
|
|
66
|
-
|
|
67
|
-
title: text(p.values.title),
|
|
68
|
-
summary: text(p.values.summary),
|
|
69
|
-
description: text(p.values.description),
|
|
70
|
-
price: num(p.values.price),
|
|
71
|
-
uses: num(p.values.uses),
|
|
76
|
+
...onSale(p),
|
|
72
77
|
per: p.values.per === "month" ? "month" : p.values.per ? "week" : null,
|
|
73
78
|
trialDays: num(p.values.trialDays),
|
|
74
|
-
...limitsOf(p.values),
|
|
75
79
|
})),
|
|
76
80
|
currency: page.currency ?? null,
|
|
77
81
|
};
|
|
@@ -107,15 +111,9 @@ export const passTypes = defineTool({
|
|
|
107
111
|
});
|
|
108
112
|
return {
|
|
109
113
|
passTypes: page.items.map((p) => ({
|
|
110
|
-
|
|
111
|
-
title: text(p.values.title),
|
|
112
|
-
summary: text(p.values.summary),
|
|
113
|
-
description: text(p.values.description),
|
|
114
|
-
price: num(p.values.price),
|
|
115
|
-
uses: num(p.values.uses),
|
|
114
|
+
...onSale(p),
|
|
116
115
|
validDays: num(p.values.validDays),
|
|
117
116
|
onePerPerson: p.values.onePerPerson === true,
|
|
118
|
-
...limitsOf(p.values),
|
|
119
117
|
})),
|
|
120
118
|
currency: page.currency ?? null,
|
|
121
119
|
};
|
|
@@ -132,6 +130,13 @@ export const buy = defineTool({
|
|
|
132
130
|
input: z.object({
|
|
133
131
|
passTypeId: id,
|
|
134
132
|
email: z.string().trim().max(320).optional().describe("A guest's email address"),
|
|
133
|
+
agreements: z
|
|
134
|
+
.array(z.record(z.string(), z.unknown()))
|
|
135
|
+
.max(20)
|
|
136
|
+
.optional()
|
|
137
|
+
.describe("A guest only: their acceptances of what is due, passed on to the host as they are (each " +
|
|
138
|
+
"{ versionId, typedName, signature?, answers? }); the host checks and records them. A " +
|
|
139
|
+
"signed-in member agrees first."),
|
|
135
140
|
}),
|
|
136
141
|
output: z.object({
|
|
137
142
|
id: z.string(),
|
|
@@ -147,6 +152,7 @@ export const buy = defineTool({
|
|
|
147
152
|
lines: [{ object: PASSTYPE, id: input.passTypeId, quantity: 1 }],
|
|
148
153
|
pay: "full",
|
|
149
154
|
...(input.email === undefined ? {} : { email: input.email }),
|
|
155
|
+
...(input.agreements === undefined ? {} : { agreements: input.agreements }),
|
|
150
156
|
});
|
|
151
157
|
return {
|
|
152
158
|
id: order.id,
|
|
@@ -183,10 +189,9 @@ const holding = limitsOut.extend({
|
|
|
183
189
|
/** At most this many of each: what one call reads (review of 32b step 6). */
|
|
184
190
|
const HOLDINGS_MAX = 50;
|
|
185
191
|
async function holdingsOf(ctx, read, personId) {
|
|
186
|
-
const filter = personId ? { filter: { field: "person", op: "eq", value: personId } } : {};
|
|
187
192
|
const list = (object) => ctx.ops.call(read, {
|
|
188
193
|
object,
|
|
189
|
-
|
|
194
|
+
filter: { field: "person", op: "eq", value: personId },
|
|
190
195
|
sort: { field: "from", direction: "desc" },
|
|
191
196
|
limit: HOLDINGS_MAX,
|
|
192
197
|
});
|
|
@@ -232,13 +237,19 @@ export const mine = defineTool({
|
|
|
232
237
|
description: "The signed-in member's own memberships and passes: each one's title, state, what it allows " +
|
|
233
238
|
"(classes per week or month, or in all; class types, days and times), when it started and " +
|
|
234
239
|
"when it stops or expires, and the host's count for now: classes used and left this week, " +
|
|
235
|
-
"this month or in all (left null: unlimited).
|
|
236
|
-
|
|
240
|
+
"this month or in all (left null: unlimited). With personId, a child's the gym linked to " +
|
|
241
|
+
"them instead (their parent or guardian reads what the child has left). Read-only.",
|
|
242
|
+
input: z.object({
|
|
243
|
+
personId: id.optional().describe("A child linked to them; left out, their own"),
|
|
244
|
+
}),
|
|
237
245
|
output: z.object({ holdings: z.array(holding) }),
|
|
238
246
|
risk: "read",
|
|
239
247
|
audiences: ["customer"],
|
|
240
|
-
async handler(
|
|
241
|
-
|
|
248
|
+
async handler(input, ctx) {
|
|
249
|
+
// The seam gives them their own and a linked child's (ADR 0540); the filter picks whose.
|
|
250
|
+
const whose = input.personId ??
|
|
251
|
+
(await ctx.ops.call("me.family", {})).self.personId;
|
|
252
|
+
return { holdings: await holdingsOf(ctx, "my.list", whose) };
|
|
242
253
|
},
|
|
243
254
|
});
|
|
244
255
|
export const holdings = defineTool({
|
|
@@ -297,6 +308,9 @@ export const givePass = defineTool({
|
|
|
297
308
|
passtype: input.passTypeId,
|
|
298
309
|
uses: input.uses ?? most,
|
|
299
310
|
...limitsOf(v),
|
|
311
|
+
// What it pays for: classes, one-to-one sessions and which services (stage 49).
|
|
312
|
+
covers: list(v.covers),
|
|
313
|
+
services: list(v.services),
|
|
300
314
|
source: "staff",
|
|
301
315
|
reason: signed(input.reason, ctx),
|
|
302
316
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@composable-os/pack-memberships",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.13",
|
|
4
4
|
"license": "FSL-1.1-ALv2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"description": "Membership plans paid every month and class passes bought once, with what each allows and what is left. Requires Programs."
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@composable-os/client": "0.1.0-beta.
|
|
36
|
-
"@composable-os/sdk": "0.1.0-beta.
|
|
35
|
+
"@composable-os/client": "0.1.0-beta.13",
|
|
36
|
+
"@composable-os/sdk": "0.1.0-beta.13"
|
|
37
37
|
}
|
|
38
38
|
}
|