@composable-os/pack-memberships 0.0.0-stage → 0.1.0-beta.9
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/LICENSE +109 -0
- package/dist/blocks/memberships-mine/mine.d.ts +6 -0
- package/dist/blocks/memberships-mine/mine.js +48 -0
- package/dist/blocks/memberships-native-mine/mine-screen.d.ts +4 -0
- package/dist/blocks/memberships-native-mine/mine-screen.js +12 -0
- package/dist/blocks/memberships-passes/passes.d.ts +10 -0
- package/dist/blocks/memberships-passes/passes.js +43 -0
- package/dist/blocks/memberships-plans/plans.d.ts +15 -0
- package/dist/blocks/memberships-plans/plans.js +106 -0
- package/dist/blocks/memberships-staff-holdings/holdings.d.ts +10 -0
- package/dist/blocks/memberships-staff-holdings/holdings.js +35 -0
- package/dist/client/index.d.ts +808 -0
- package/dist/client/index.js +212 -0
- package/dist/index.d.ts +894 -0
- package/dist/index.js +559 -0
- package/dist/tools.d.ts +134 -0
- package/dist/tools.js +346 -0
- package/package.json +36 -4
- package/README.md +0 -3
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
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
|
+
export declare const plans: import("@composable-os/sdk").ToolSpec<z.ZodObject<{}, z.core.$strip>, z.ZodObject<{
|
|
7
|
+
plans: z.ZodArray<z.ZodObject<{
|
|
8
|
+
classTypes: z.ZodArray<z.ZodString>;
|
|
9
|
+
weekdays: z.ZodArray<z.ZodString>;
|
|
10
|
+
fromMinute: z.ZodNullable<z.ZodNumber>;
|
|
11
|
+
untilMinute: z.ZodNullable<z.ZodNumber>;
|
|
12
|
+
id: z.ZodString;
|
|
13
|
+
title: z.ZodNullable<z.ZodString>;
|
|
14
|
+
summary: z.ZodNullable<z.ZodString>;
|
|
15
|
+
description: z.ZodNullable<z.ZodString>;
|
|
16
|
+
price: z.ZodNullable<z.ZodNumber>;
|
|
17
|
+
uses: z.ZodNullable<z.ZodNumber>;
|
|
18
|
+
per: z.ZodNullable<z.ZodEnum<{
|
|
19
|
+
week: "week";
|
|
20
|
+
month: "month";
|
|
21
|
+
}>>;
|
|
22
|
+
trialDays: z.ZodNullable<z.ZodNumber>;
|
|
23
|
+
}, z.core.$strip>>;
|
|
24
|
+
currency: z.ZodNullable<z.ZodString>;
|
|
25
|
+
}, z.core.$strip>>;
|
|
26
|
+
export declare const passTypes: import("@composable-os/sdk").ToolSpec<z.ZodObject<{}, z.core.$strip>, z.ZodObject<{
|
|
27
|
+
passTypes: z.ZodArray<z.ZodObject<{
|
|
28
|
+
classTypes: z.ZodArray<z.ZodString>;
|
|
29
|
+
weekdays: z.ZodArray<z.ZodString>;
|
|
30
|
+
fromMinute: z.ZodNullable<z.ZodNumber>;
|
|
31
|
+
untilMinute: z.ZodNullable<z.ZodNumber>;
|
|
32
|
+
id: z.ZodString;
|
|
33
|
+
title: z.ZodNullable<z.ZodString>;
|
|
34
|
+
summary: z.ZodNullable<z.ZodString>;
|
|
35
|
+
description: z.ZodNullable<z.ZodString>;
|
|
36
|
+
price: z.ZodNullable<z.ZodNumber>;
|
|
37
|
+
uses: z.ZodNullable<z.ZodNumber>;
|
|
38
|
+
validDays: z.ZodNullable<z.ZodNumber>;
|
|
39
|
+
onePerPerson: z.ZodBoolean;
|
|
40
|
+
}, z.core.$strip>>;
|
|
41
|
+
currency: z.ZodNullable<z.ZodString>;
|
|
42
|
+
}, z.core.$strip>>;
|
|
43
|
+
export declare const buy: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
|
|
44
|
+
passTypeId: z.ZodString;
|
|
45
|
+
email: z.ZodOptional<z.ZodString>;
|
|
46
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
47
|
+
id: z.ZodString;
|
|
48
|
+
state: z.ZodString;
|
|
49
|
+
currency: z.ZodString;
|
|
50
|
+
total: z.ZodNumber;
|
|
51
|
+
token: z.ZodNullable<z.ZodString>;
|
|
52
|
+
}, z.core.$strip>>;
|
|
53
|
+
export declare const mine: import("@composable-os/sdk").ToolSpec<z.ZodObject<{}, z.core.$strip>, z.ZodObject<{
|
|
54
|
+
holdings: z.ZodArray<z.ZodObject<{
|
|
55
|
+
classTypes: z.ZodArray<z.ZodString>;
|
|
56
|
+
weekdays: z.ZodArray<z.ZodString>;
|
|
57
|
+
fromMinute: z.ZodNullable<z.ZodNumber>;
|
|
58
|
+
untilMinute: z.ZodNullable<z.ZodNumber>;
|
|
59
|
+
id: z.ZodString;
|
|
60
|
+
kind: z.ZodEnum<{
|
|
61
|
+
membership: "membership";
|
|
62
|
+
pass: "pass";
|
|
63
|
+
}>;
|
|
64
|
+
title: z.ZodNullable<z.ZodString>;
|
|
65
|
+
status: z.ZodString;
|
|
66
|
+
uses: z.ZodNullable<z.ZodNumber>;
|
|
67
|
+
per: z.ZodEnum<{
|
|
68
|
+
week: "week";
|
|
69
|
+
month: "month";
|
|
70
|
+
total: "total";
|
|
71
|
+
}>;
|
|
72
|
+
from: z.ZodNullable<z.ZodString>;
|
|
73
|
+
until: z.ZodNullable<z.ZodString>;
|
|
74
|
+
live: z.ZodBoolean;
|
|
75
|
+
period: z.ZodNullable<z.ZodObject<{
|
|
76
|
+
key: z.ZodString;
|
|
77
|
+
startsAt: z.ZodString;
|
|
78
|
+
endsAt: z.ZodString;
|
|
79
|
+
used: z.ZodNumber;
|
|
80
|
+
left: z.ZodNullable<z.ZodNumber>;
|
|
81
|
+
}, z.core.$strip>>;
|
|
82
|
+
}, z.core.$strip>>;
|
|
83
|
+
}, z.core.$strip>>;
|
|
84
|
+
export declare const holdings: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
|
|
85
|
+
personId: z.ZodString;
|
|
86
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
87
|
+
holdings: z.ZodArray<z.ZodObject<{
|
|
88
|
+
classTypes: z.ZodArray<z.ZodString>;
|
|
89
|
+
weekdays: z.ZodArray<z.ZodString>;
|
|
90
|
+
fromMinute: z.ZodNullable<z.ZodNumber>;
|
|
91
|
+
untilMinute: z.ZodNullable<z.ZodNumber>;
|
|
92
|
+
id: z.ZodString;
|
|
93
|
+
kind: z.ZodEnum<{
|
|
94
|
+
membership: "membership";
|
|
95
|
+
pass: "pass";
|
|
96
|
+
}>;
|
|
97
|
+
title: z.ZodNullable<z.ZodString>;
|
|
98
|
+
status: z.ZodString;
|
|
99
|
+
uses: z.ZodNullable<z.ZodNumber>;
|
|
100
|
+
per: z.ZodEnum<{
|
|
101
|
+
week: "week";
|
|
102
|
+
month: "month";
|
|
103
|
+
total: "total";
|
|
104
|
+
}>;
|
|
105
|
+
from: z.ZodNullable<z.ZodString>;
|
|
106
|
+
until: z.ZodNullable<z.ZodString>;
|
|
107
|
+
live: z.ZodBoolean;
|
|
108
|
+
period: z.ZodNullable<z.ZodObject<{
|
|
109
|
+
key: z.ZodString;
|
|
110
|
+
startsAt: z.ZodString;
|
|
111
|
+
endsAt: z.ZodString;
|
|
112
|
+
used: z.ZodNumber;
|
|
113
|
+
left: z.ZodNullable<z.ZodNumber>;
|
|
114
|
+
}, z.core.$strip>>;
|
|
115
|
+
}, z.core.$strip>>;
|
|
116
|
+
}, z.core.$strip>>;
|
|
117
|
+
export declare const givePass: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
|
|
118
|
+
personId: z.ZodString;
|
|
119
|
+
passTypeId: z.ZodString;
|
|
120
|
+
reason: z.ZodString;
|
|
121
|
+
uses: z.ZodOptional<z.ZodNumber>;
|
|
122
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
123
|
+
passId: z.ZodString;
|
|
124
|
+
status: z.ZodString;
|
|
125
|
+
source: z.ZodString;
|
|
126
|
+
}, z.core.$strip>>;
|
|
127
|
+
export declare const voidPass: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
|
|
128
|
+
passId: z.ZodString;
|
|
129
|
+
reason: z.ZodString;
|
|
130
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
131
|
+
passId: z.ZodString;
|
|
132
|
+
status: z.ZodString;
|
|
133
|
+
source: z.ZodString;
|
|
134
|
+
}, z.core.$strip>>;
|
package/dist/tools.js
ADDED
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
// The Memberships tools. They become operations x.memberships.<tool>, run in the sandbox, and reach
|
|
2
|
+
// the host only through ctx.ops. None holds a rule: a plan's price, the trial, a pass's price, its
|
|
3
|
+
// uses and expiry, the intro offer's one per person, and what a membership or a pass may be spent
|
|
4
|
+
// on are the host's (`sellable`, `recurring.grants`, `allowance`). What is left is the host's
|
|
5
|
+
// count (`allowance.get`). A tool asks, and reports what the host answered.
|
|
6
|
+
import { defineTool, OpsCallError, z } from "@composable-os/sdk";
|
|
7
|
+
export const PLAN = "memberships.plan";
|
|
8
|
+
export const MEMBERSHIP = "memberships.membership";
|
|
9
|
+
export const PASSTYPE = "memberships.passtype";
|
|
10
|
+
export const PASS = "memberships.pass";
|
|
11
|
+
const id = z.string().min(1).max(64);
|
|
12
|
+
const text = (value) => value === null || value === undefined || value === "" ? null : String(value);
|
|
13
|
+
const num = (value) => typeof value === "number" ? value : value == null || value === "" ? null : Number(value);
|
|
14
|
+
const list = (value) => Array.isArray(value) ? value.map(String) : value == null || value === "" ? [] : [String(value)];
|
|
15
|
+
const currency = z
|
|
16
|
+
.string()
|
|
17
|
+
.nullable()
|
|
18
|
+
.describe("The currency prices are in (ISO 4217), the deployment's one; null until it is set");
|
|
19
|
+
/** What a plan, a pass type, a membership or a pass allows, as its record says. */
|
|
20
|
+
const limitsOut = z.object({
|
|
21
|
+
classTypes: z.array(z.string()).describe("Class type ids; empty: every class type"),
|
|
22
|
+
weekdays: z.array(z.string()).describe("1 Monday to 7 Sunday; empty: every day"),
|
|
23
|
+
fromMinute: z
|
|
24
|
+
.number()
|
|
25
|
+
.nullable()
|
|
26
|
+
.describe("Classes starting at or after, minutes after midnight"),
|
|
27
|
+
untilMinute: z.number().nullable().describe("Classes starting before, minutes after midnight"),
|
|
28
|
+
});
|
|
29
|
+
const limitsOf = (v) => ({
|
|
30
|
+
classTypes: list(v.classTypes),
|
|
31
|
+
weekdays: list(v.weekdays),
|
|
32
|
+
fromMinute: num(v.fromMinute),
|
|
33
|
+
untilMinute: num(v.untilMinute),
|
|
34
|
+
});
|
|
35
|
+
// --- What is on sale -----------------------------------------------------------------------------
|
|
36
|
+
export const plans = defineTool({
|
|
37
|
+
description: "The membership plans on sale: each plan's title, a line on what it gives, description, " +
|
|
38
|
+
"price per month (in the major unit of `currency`), classes per week or month (null: " +
|
|
39
|
+
"unlimited), the class types, days and times it allows, and the days of its free trial. " +
|
|
40
|
+
"Whether a person gets the trial is the host's, when they subscribe (subscription.start): " +
|
|
41
|
+
"one per person, signed in. Read-only.",
|
|
42
|
+
input: z.object({}),
|
|
43
|
+
output: z.object({
|
|
44
|
+
plans: z.array(limitsOut.extend({
|
|
45
|
+
id: z.string(),
|
|
46
|
+
title: z.string().nullable(),
|
|
47
|
+
summary: z.string().nullable(),
|
|
48
|
+
description: z.string().nullable(),
|
|
49
|
+
price: z.number().nullable().describe("Per month, in the major unit of `currency`"),
|
|
50
|
+
uses: z.number().nullable().describe("Classes per period; null: unlimited"),
|
|
51
|
+
per: z.enum(["week", "month"]).nullable(),
|
|
52
|
+
trialDays: z.number().nullable(),
|
|
53
|
+
})),
|
|
54
|
+
currency,
|
|
55
|
+
}),
|
|
56
|
+
risk: "read",
|
|
57
|
+
audiences: ["customer", "public"],
|
|
58
|
+
async handler(_input, ctx) {
|
|
59
|
+
const page = await ctx.ops.call("public.list", {
|
|
60
|
+
object: PLAN,
|
|
61
|
+
sort: { field: "price", direction: "asc" },
|
|
62
|
+
limit: 50,
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
plans: page.items.map((p) => ({
|
|
66
|
+
id: p.id,
|
|
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),
|
|
72
|
+
per: p.values.per === "month" ? "month" : p.values.per ? "week" : null,
|
|
73
|
+
trialDays: num(p.values.trialDays),
|
|
74
|
+
...limitsOf(p.values),
|
|
75
|
+
})),
|
|
76
|
+
currency: page.currency ?? null,
|
|
77
|
+
};
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
export const passTypes = defineTool({
|
|
81
|
+
description: "The passes on sale, bought once: class packs, drop-ins and intro offers. Each one's title, " +
|
|
82
|
+
"a line on what it gives, description, price (in the major unit of `currency`), its classes, " +
|
|
83
|
+
"how many days it is valid for from the day it is bought (null: it does not expire), the " +
|
|
84
|
+
"class types, days and times it allows, and whether it is an intro offer (one per person, " +
|
|
85
|
+
"bought signed in; the host refuses a second). Read-only.",
|
|
86
|
+
input: z.object({}),
|
|
87
|
+
output: z.object({
|
|
88
|
+
passTypes: z.array(limitsOut.extend({
|
|
89
|
+
id: z.string(),
|
|
90
|
+
title: z.string().nullable(),
|
|
91
|
+
summary: z.string().nullable(),
|
|
92
|
+
description: z.string().nullable(),
|
|
93
|
+
price: z.number().nullable(),
|
|
94
|
+
uses: z.number().nullable(),
|
|
95
|
+
validDays: z.number().nullable(),
|
|
96
|
+
onePerPerson: z.boolean(),
|
|
97
|
+
})),
|
|
98
|
+
currency,
|
|
99
|
+
}),
|
|
100
|
+
risk: "read",
|
|
101
|
+
audiences: ["customer", "public"],
|
|
102
|
+
async handler(_input, ctx) {
|
|
103
|
+
const page = await ctx.ops.call("public.list", {
|
|
104
|
+
object: PASSTYPE,
|
|
105
|
+
sort: { field: "price", direction: "asc" },
|
|
106
|
+
limit: 50,
|
|
107
|
+
});
|
|
108
|
+
return {
|
|
109
|
+
passTypes: page.items.map((p) => ({
|
|
110
|
+
id: p.id,
|
|
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),
|
|
116
|
+
validDays: num(p.values.validDays),
|
|
117
|
+
onePerPerson: p.values.onePerPerson === true,
|
|
118
|
+
...limitsOf(p.values),
|
|
119
|
+
})),
|
|
120
|
+
currency: page.currency ?? null,
|
|
121
|
+
};
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
export const buy = defineTool({
|
|
125
|
+
description: "Start an order for one pass (a class pack, a drop-in or an intro offer). A signed-in " +
|
|
126
|
+
"customer buys as themselves; a guest gives their email address, and may not buy an intro " +
|
|
127
|
+
"offer (the host refuses it: one per person, signed in). The host prices it from the pass " +
|
|
128
|
+
"type, refuses one not on sale, and refuses a second intro offer for the same person. " +
|
|
129
|
+
"Nothing is paid here: the buyer then calls order.checkout with the order's id (and a " +
|
|
130
|
+
"guest's token) to pay on the provider's page; the pass is granted when the provider " +
|
|
131
|
+
"confirms the payment. Amounts in the minor unit.",
|
|
132
|
+
input: z.object({
|
|
133
|
+
passTypeId: id,
|
|
134
|
+
email: z.string().trim().max(320).optional().describe("A guest's email address"),
|
|
135
|
+
}),
|
|
136
|
+
output: z.object({
|
|
137
|
+
id: z.string(),
|
|
138
|
+
state: z.string(),
|
|
139
|
+
currency: z.string(),
|
|
140
|
+
total: z.number(),
|
|
141
|
+
token: z.string().nullable().describe("A guest's key to this order, shown once"),
|
|
142
|
+
}),
|
|
143
|
+
risk: "write",
|
|
144
|
+
audiences: ["customer", "public"],
|
|
145
|
+
async handler(input, ctx) {
|
|
146
|
+
const order = await ctx.ops.call("order.start", {
|
|
147
|
+
lines: [{ object: PASSTYPE, id: input.passTypeId, quantity: 1 }],
|
|
148
|
+
pay: "full",
|
|
149
|
+
...(input.email === undefined ? {} : { email: input.email }),
|
|
150
|
+
});
|
|
151
|
+
return {
|
|
152
|
+
id: order.id,
|
|
153
|
+
state: order.state,
|
|
154
|
+
currency: order.currency,
|
|
155
|
+
total: order.total,
|
|
156
|
+
token: order.token ?? null,
|
|
157
|
+
};
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
// --- What a member holds -------------------------------------------------------------------------
|
|
161
|
+
const periodOut = z.object({
|
|
162
|
+
key: z.string(),
|
|
163
|
+
startsAt: z.string(),
|
|
164
|
+
endsAt: z.string(),
|
|
165
|
+
used: z.number(),
|
|
166
|
+
left: z.number().nullable().describe("Null: unlimited"),
|
|
167
|
+
});
|
|
168
|
+
const holding = limitsOut.extend({
|
|
169
|
+
id: z.string(),
|
|
170
|
+
kind: z.enum(["membership", "pass"]),
|
|
171
|
+
title: z.string().nullable(),
|
|
172
|
+
status: z.string().describe("The record's own state, as the host keeps it"),
|
|
173
|
+
uses: z
|
|
174
|
+
.number()
|
|
175
|
+
.nullable()
|
|
176
|
+
.describe("Per period for a membership, in all for a pass; null: unlimited"),
|
|
177
|
+
per: z.enum(["total", "week", "month"]),
|
|
178
|
+
from: z.string().nullable(),
|
|
179
|
+
until: z.string().nullable().describe("When it stops or expires"),
|
|
180
|
+
live: z.boolean().describe("It can pay for a class now (the host's answer)"),
|
|
181
|
+
period: periodOut.nullable().describe("This week, this month or in all, as the host counts it"),
|
|
182
|
+
});
|
|
183
|
+
/** At most this many of each: what one call reads (review of 32b step 6). */
|
|
184
|
+
const HOLDINGS_MAX = 50;
|
|
185
|
+
async function holdingsOf(ctx, read, personId) {
|
|
186
|
+
const filter = personId ? { filter: { field: "person", op: "eq", value: personId } } : {};
|
|
187
|
+
const list = (object) => ctx.ops.call(read, {
|
|
188
|
+
object,
|
|
189
|
+
...filter,
|
|
190
|
+
sort: { field: "from", direction: "desc" },
|
|
191
|
+
limit: HOLDINGS_MAX,
|
|
192
|
+
});
|
|
193
|
+
const [memberships, passes] = await Promise.all([list(MEMBERSHIP), list(PASS)]);
|
|
194
|
+
// The host's count for every holding of an object in one call (allowance.list), never worked
|
|
195
|
+
// out here; one the caller cannot see is left out of its answer.
|
|
196
|
+
const counts = async (object, items) => items.length
|
|
197
|
+
? new Map((await ctx.ops.call("allowance.list", {
|
|
198
|
+
object,
|
|
199
|
+
ids: items.map((r) => r.id),
|
|
200
|
+
})).items.map((v) => [v.id, v]))
|
|
201
|
+
: new Map();
|
|
202
|
+
const [membershipCounts, passCounts] = await Promise.all([
|
|
203
|
+
counts(MEMBERSHIP, memberships.items),
|
|
204
|
+
counts(PASS, passes.items),
|
|
205
|
+
]);
|
|
206
|
+
const out = [];
|
|
207
|
+
for (const [kind, items, views] of [
|
|
208
|
+
["membership", memberships.items, membershipCounts],
|
|
209
|
+
["pass", passes.items, passCounts],
|
|
210
|
+
]) {
|
|
211
|
+
for (const r of items) {
|
|
212
|
+
const v = r.values;
|
|
213
|
+
const view = views.get(r.id);
|
|
214
|
+
out.push({
|
|
215
|
+
id: r.id,
|
|
216
|
+
kind,
|
|
217
|
+
title: text(v.title),
|
|
218
|
+
status: String(v.status ?? ""),
|
|
219
|
+
uses: num(v.uses),
|
|
220
|
+
per: kind === "pass" ? "total" : v.per === "month" ? "month" : "week",
|
|
221
|
+
from: text(v.from),
|
|
222
|
+
until: text(v.until),
|
|
223
|
+
live: view?.payable ?? false,
|
|
224
|
+
period: view?.period ?? null,
|
|
225
|
+
...limitsOf(v),
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return out;
|
|
230
|
+
}
|
|
231
|
+
export const mine = defineTool({
|
|
232
|
+
description: "The signed-in member's own memberships and passes: each one's title, state, what it allows " +
|
|
233
|
+
"(classes per week or month, or in all; class types, days and times), when it started and " +
|
|
234
|
+
"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). Read-only.",
|
|
236
|
+
input: z.object({}),
|
|
237
|
+
output: z.object({ holdings: z.array(holding) }),
|
|
238
|
+
risk: "read",
|
|
239
|
+
audiences: ["customer"],
|
|
240
|
+
async handler(_input, ctx) {
|
|
241
|
+
return { holdings: await holdingsOf(ctx, "my.list", null) };
|
|
242
|
+
},
|
|
243
|
+
});
|
|
244
|
+
export const holdings = defineTool({
|
|
245
|
+
description: "For staff: one person's memberships and passes, with their state, what each allows, when " +
|
|
246
|
+
"it stops or expires, and the classes used and left now, as the host counts them. Read-only.",
|
|
247
|
+
input: z.object({ personId: id }),
|
|
248
|
+
output: z.object({ holdings: z.array(holding) }),
|
|
249
|
+
risk: "read",
|
|
250
|
+
async handler(input, ctx) {
|
|
251
|
+
return { holdings: await holdingsOf(ctx, "record.list", input.personId) };
|
|
252
|
+
},
|
|
253
|
+
});
|
|
254
|
+
// --- Staff, by hand ------------------------------------------------------------------------------
|
|
255
|
+
const passOut = z.object({ passId: z.string(), status: z.string(), source: z.string() });
|
|
256
|
+
/** Who did it, as the host says (never the input), kept on the record with the reason. */
|
|
257
|
+
const signed = (reason, ctx) => `${reason}${ctx.caller?.kind === "staff" ? ` (${ctx.caller.name})` : ""}`.slice(0, 1000);
|
|
258
|
+
export const givePass = defineTool({
|
|
259
|
+
description: "Give a person a pass by hand, free, with the reason: a pass type's classes, or fewer if " +
|
|
260
|
+
"given (never more), valid from now for the type's days, as the host works them out for a " +
|
|
261
|
+
"pass bought. An intro offer given this way is the person's one: refused if they have had " +
|
|
262
|
+
"it. Recorded as given by staff, with who gave it and why. A person on the staff only (never " +
|
|
263
|
+
"the assistant or an automation), with the memberships:passes permission. Returns the pass.",
|
|
264
|
+
input: z.object({
|
|
265
|
+
personId: id,
|
|
266
|
+
passTypeId: id,
|
|
267
|
+
reason: z.string().trim().min(3).max(500),
|
|
268
|
+
uses: z
|
|
269
|
+
.number()
|
|
270
|
+
.int()
|
|
271
|
+
.min(1)
|
|
272
|
+
.max(1000)
|
|
273
|
+
.optional()
|
|
274
|
+
.describe("Fewer classes than the pass type gives; default: the type's"),
|
|
275
|
+
}),
|
|
276
|
+
output: passOut,
|
|
277
|
+
risk: "write",
|
|
278
|
+
permission: "memberships:passes",
|
|
279
|
+
humanOnly: true,
|
|
280
|
+
async handler(input, ctx) {
|
|
281
|
+
const type = await ctx.ops.call("record.get", {
|
|
282
|
+
object: PASSTYPE,
|
|
283
|
+
id: input.passTypeId,
|
|
284
|
+
});
|
|
285
|
+
const v = type.values;
|
|
286
|
+
const most = num(v.uses);
|
|
287
|
+
if (input.uses !== undefined && most !== null && input.uses > most) {
|
|
288
|
+
throw new OpsCallError("invalid_input", `A pass of this type gives at most ${most} classes; give fewer, or choose another type`, { field: "uses", max: most });
|
|
289
|
+
}
|
|
290
|
+
// Its dates (valid from now for the type's days) and, for an intro offer, the person's one
|
|
291
|
+
// per person are the host's (ADR 0513): this tool sends neither.
|
|
292
|
+
const created = await ctx.ops.call("record.create", {
|
|
293
|
+
object: PASS,
|
|
294
|
+
values: {
|
|
295
|
+
title: text(v.title) ?? "Pass",
|
|
296
|
+
person: input.personId,
|
|
297
|
+
passtype: input.passTypeId,
|
|
298
|
+
uses: input.uses ?? most,
|
|
299
|
+
...limitsOf(v),
|
|
300
|
+
source: "staff",
|
|
301
|
+
reason: signed(input.reason, ctx),
|
|
302
|
+
},
|
|
303
|
+
});
|
|
304
|
+
return { passId: created.id, status: "active", source: "staff" };
|
|
305
|
+
},
|
|
306
|
+
});
|
|
307
|
+
export const voidPass = defineTool({
|
|
308
|
+
description: "Void a pass by hand, with the reason: it pays for no more classes; classes already booked " +
|
|
309
|
+
"with it stay booked. For a pass bought, refund its order instead (a full refund voids it). " +
|
|
310
|
+
"A person on the staff only, with the memberships:passes permission. Returns the pass.",
|
|
311
|
+
input: z.object({ passId: id, reason: z.string().trim().min(3).max(500) }),
|
|
312
|
+
output: passOut,
|
|
313
|
+
risk: "write",
|
|
314
|
+
permission: "memberships:passes",
|
|
315
|
+
humanOnly: true,
|
|
316
|
+
recordAction: {
|
|
317
|
+
object: PASS,
|
|
318
|
+
label: "Void pass",
|
|
319
|
+
idInput: "passId",
|
|
320
|
+
confirm: "Void this pass? It pays for no more classes.",
|
|
321
|
+
ask: {
|
|
322
|
+
input: "reason",
|
|
323
|
+
label: "Why",
|
|
324
|
+
options: [
|
|
325
|
+
{ value: "Given in error", label: "Given in error" },
|
|
326
|
+
{ value: "Asked for by the member", label: "Asked for by the member" },
|
|
327
|
+
{ value: "Replaced by another pass", label: "Replaced by another pass" },
|
|
328
|
+
],
|
|
329
|
+
},
|
|
330
|
+
hideWhen: { field: "status", values: ["void"] },
|
|
331
|
+
},
|
|
332
|
+
async handler(input, ctx) {
|
|
333
|
+
const row = await ctx.ops.call("record.get", { object: PASS, id: input.passId });
|
|
334
|
+
if (row.values.source !== "staff") {
|
|
335
|
+
throw new OpsCallError("invalid_input", "A bought pass is voided by refunding its order in full, not here", { reason: "bought" });
|
|
336
|
+
}
|
|
337
|
+
// From a current read (ADR 0437): of two voids at once, the host lets one through.
|
|
338
|
+
await ctx.ops.call("record.update", {
|
|
339
|
+
object: PASS,
|
|
340
|
+
id: input.passId,
|
|
341
|
+
values: { status: "void", reason: signed(input.reason, ctx) },
|
|
342
|
+
from: "active",
|
|
343
|
+
});
|
|
344
|
+
return { passId: input.passId, status: "void", source: "staff" };
|
|
345
|
+
},
|
|
346
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@composable-os/pack-memberships",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0-beta.9",
|
|
4
|
+
"license": "FSL-1.1-ALv2",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/timoconnellaus/composable-os.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://composableos.dev",
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public",
|
|
13
|
+
"provenance": true
|
|
14
|
+
},
|
|
15
|
+
"description": "Memberships: membership plans sold as subscriptions (unlimited, or N classes a week or month), memberships that follow their subscription, pass types sold once (class packs that expire, drop-ins, a one-per-person intro offer) and the passes they grant, each an allowance a booking spends (stage 32b). Requires Programs (class types). Installed in every deployment of a product that lists it. Bundled as source into cos-runner.",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./client": {
|
|
22
|
+
"types": "./dist/client/index.d.ts",
|
|
23
|
+
"default": "./dist/client/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"composableOs": {
|
|
30
|
+
"optional": true,
|
|
31
|
+
"label": "Memberships",
|
|
32
|
+
"description": "Membership plans paid every month and class passes bought once, with what each allows and what is left. Requires Programs."
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@composable-os/client": "0.1.0-beta.9",
|
|
36
|
+
"@composable-os/sdk": "0.1.0-beta.9"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/README.md
DELETED