@composable-os/pack-ticketing 0.0.0-stage → 0.1.0-beta.8

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/index.js ADDED
@@ -0,0 +1,314 @@
1
+ // Ticketing (stage 27): events, the ticket types sold for them, and the tickets a paid order
2
+ // grants. Any product can turn it on (`packs` in its product.ts); a product that does not list it
3
+ // has none of this.
4
+ //
5
+ // Everything that is a rule is the host's, declared here as behaviours (ADR 0404):
6
+ // - an event's lifecycle (`states`) and its places, shared by its ticket types (`capacity`);
7
+ // - a ticket type is for sale (`sellable`): its price, sale window, most per order and deposit
8
+ // are fields staff edit, and a paid line grants one ticket per place, with the host's code,
9
+ // in the batch that marks the order paid; a full refund or a cancelled deposit voids them;
10
+ // - a ticket is its holder's (`customer`): they read its event, type, code and state, and
11
+ // nothing else, through the visibility seam, and through it their event's name, times and
12
+ // venue and their ticket type's name, live, whatever the event's state (`customerVia`);
13
+ // - the door role (`roles`, ADR 0436): check tickets in and read events, ticket types and
14
+ // tickets, and nothing else.
15
+ // The tools in tools.ts compose the host's operations and add no rules of their own.
16
+ import { defineExtension } from "@composable-os/sdk";
17
+ import { ticketingAutomations } from "./automations.js";
18
+ import { ticketingDashboards } from "./dashboards.js";
19
+ import { checkIn, eventsOnSale, myTickets, orderStart, salesSummary, undoCheckIn, } from "./tools.js";
20
+ export default defineExtension({
21
+ id: "ticketing",
22
+ version: "0.1.0",
23
+ contractVersion: 1,
24
+ label: "Ticketing",
25
+ description: "Events, ticket types for sale and the tickets a paid order grants, with check-in at the " +
26
+ "door. Buyers are people; tickets are theirs to see.",
27
+ permissions: {
28
+ // order.start: a buyer's order, priced and held by the host. order.get: whether a ticket's
29
+ // order still has a balance owing, at check-in. query.sql: revenue per ticket type for the
30
+ // sales summary. person.get (read person): the holder's name a check-in reports.
31
+ read: ["person"],
32
+ // public.list and capacity.get: the events on sale and their places, for the public.
33
+ // extensionSettings.list: the pages the buyer's emails link to. email-send: the buyer's mail.
34
+ // order.settings.get: the currency the sales summary's amounts are in (staff).
35
+ operations: [
36
+ "order.start",
37
+ "order.get",
38
+ "query.sql",
39
+ "public.list",
40
+ "capacity.get",
41
+ "extensionSettings.list",
42
+ "order.settings.get",
43
+ ],
44
+ modules: ["ops", "email-send"],
45
+ },
46
+ objects: {
47
+ event: {
48
+ label: "Event",
49
+ plural: "Events",
50
+ icon: "calendar",
51
+ titleField: "name",
52
+ description: "Something tickets are sold for: a camp, a workshop, a night.",
53
+ navigation: "main",
54
+ navigationOrder: 10,
55
+ fields: {
56
+ name: { type: "text", label: "Name", required: true },
57
+ startsAt: { type: "datetime", label: "Starts" },
58
+ endsAt: { type: "datetime", label: "Ends" },
59
+ // Where the event's clock is (ADR 0460): its days and times are this zone's, for buyers,
60
+ // holders, the emails and the reminders. Left empty, the deployment's zone.
61
+ timezone: {
62
+ type: "timezone",
63
+ label: "Time zone",
64
+ required: true,
65
+ description: "The event's own time zone, e.g. Asia/Bangkok for a camp in Thailand. Its dates are " +
66
+ "shown, and its reminders sent, on this zone's days. Empty: this deployment's zone.",
67
+ },
68
+ venue: { type: "text", label: "Venue" },
69
+ description: { type: "longText", label: "Description" },
70
+ image: { type: "url", label: "Image" },
71
+ status: {
72
+ type: "select",
73
+ label: "Status",
74
+ track: "timeline",
75
+ options: [
76
+ { value: "draft", label: "Draft" },
77
+ { value: "on_sale", label: "On sale" },
78
+ { value: "ended", label: "Ended" },
79
+ { value: "cancelled", label: "Cancelled" },
80
+ ],
81
+ },
82
+ places: {
83
+ type: "number",
84
+ label: "Places",
85
+ description: "How many people the event holds across all its ticket types. Empty: no limit " +
86
+ "beyond each ticket type's own.",
87
+ },
88
+ },
89
+ states: {
90
+ field: "status",
91
+ initial: "draft",
92
+ moves: [
93
+ { from: "draft", to: "on_sale", by: ["staff"] },
94
+ { from: "on_sale", to: "draft", by: ["staff"] },
95
+ { from: "on_sale", to: "ended", by: ["staff"], final: true },
96
+ { from: ["draft", "on_sale"], to: "cancelled", by: ["staff"], final: true },
97
+ ],
98
+ },
99
+ capacity: { places: "places" },
100
+ // The public reads an event while it is on sale (ADR 0438): what its page shows.
101
+ public: {
102
+ read: ["name", "startsAt", "endsAt", "timezone", "venue", "description", "image", "status"],
103
+ when: { field: "status", in: ["on_sale"] },
104
+ },
105
+ // A ticket's holder reads its event whatever the event's state (ADR 0439): an ended
106
+ // event's name, times and venue are what a ticket is looked at for.
107
+ customerVia: {
108
+ from: "ticketing.ticket",
109
+ field: "event",
110
+ read: ["name", "startsAt", "endsAt", "timezone", "venue", "status"],
111
+ },
112
+ indexes: [["status", "startsAt"], ["startsAt"]],
113
+ },
114
+ tickettype: {
115
+ label: "Ticket type",
116
+ plural: "Ticket types",
117
+ icon: "ticket",
118
+ titleField: "name",
119
+ description: "One kind of ticket for an event, with its own price and places: a package, a room " +
120
+ "type. One ticket is one person.",
121
+ navigation: "settings",
122
+ fields: {
123
+ event: { type: "relation", label: "Event", to: "ticketing.event", required: true },
124
+ name: { type: "text", label: "Name", required: true },
125
+ description: { type: "longText", label: "Description" },
126
+ price: { type: "currency", label: "Price", required: true },
127
+ places: {
128
+ type: "number",
129
+ label: "Places",
130
+ description: "How many of this ticket type there are. Empty: only the event's limit.",
131
+ },
132
+ onSaleFrom: { type: "datetime", label: "On sale from" },
133
+ onSaleUntil: { type: "datetime", label: "On sale until" },
134
+ maxPerOrder: {
135
+ type: "number",
136
+ label: "Most per order",
137
+ description: "The most one order may hold. Empty: 10.",
138
+ },
139
+ depositAmount: {
140
+ type: "currency",
141
+ label: "Deposit",
142
+ description: "Set with a balance due date to let buyers pay a deposit now.",
143
+ },
144
+ balanceDue: { type: "date", label: "Balance due" },
145
+ },
146
+ capacity: { places: "places", pool: "event", show: "low", lowAt: 10 },
147
+ sellable: {
148
+ price: "price",
149
+ saleWindow: { from: "onSaleFrom", until: "onSaleUntil" },
150
+ maxPerOrder: "maxPerOrder",
151
+ deposit: { amount: "depositAmount", balanceDue: "balanceDue" },
152
+ grants: {
153
+ object: "ticket",
154
+ set: {
155
+ name: "line.title",
156
+ tickettype: "item",
157
+ event: "item.event",
158
+ holder: "order.person",
159
+ order: "order",
160
+ code: "code",
161
+ },
162
+ void: "void",
163
+ },
164
+ },
165
+ // A ticket type is public while its event is on sale; its places are capacity.get's.
166
+ public: {
167
+ read: [
168
+ "event",
169
+ "name",
170
+ "description",
171
+ "price",
172
+ "onSaleFrom",
173
+ "onSaleUntil",
174
+ "maxPerOrder",
175
+ "depositAmount",
176
+ "balanceDue",
177
+ ],
178
+ when: { via: "event", field: "status", in: ["on_sale"] },
179
+ },
180
+ // A ticket's holder reads the name of its ticket type, whatever its event's state. Reading
181
+ // it is not buying it: a customer buys only what they may read as the public (ADR 0439).
182
+ customerVia: { from: "ticketing.ticket", field: "tickettype", read: ["name"] },
183
+ indexes: [["event"]],
184
+ },
185
+ ticket: {
186
+ label: "Ticket",
187
+ plural: "Tickets",
188
+ icon: "ticket-check",
189
+ titleField: "name",
190
+ description: "One person's ticket, granted by the host when its order was paid, with a code that " +
191
+ "is checked at the door.",
192
+ navigation: "main",
193
+ navigationOrder: 11,
194
+ fields: {
195
+ name: { type: "text", label: "Name", required: true },
196
+ code: {
197
+ type: "text",
198
+ label: "Code",
199
+ readOnly: true,
200
+ description: "Made by the host when the ticket is granted. The QR code carries only this.",
201
+ },
202
+ tickettype: {
203
+ type: "relation",
204
+ label: "Ticket type",
205
+ to: "ticketing.tickettype",
206
+ required: true,
207
+ },
208
+ event: { type: "relation", label: "Event", to: "ticketing.event", required: true },
209
+ holder: { type: "relation", label: "Holder", to: "person" },
210
+ order: { type: "text", label: "Order" },
211
+ state: {
212
+ type: "select",
213
+ label: "State",
214
+ track: "timeline",
215
+ options: [
216
+ { value: "valid", label: "Valid" },
217
+ { value: "used", label: "Used" },
218
+ { value: "void", label: "Void" },
219
+ ],
220
+ },
221
+ usedAt: { type: "datetime", label: "Checked in at" },
222
+ usedBy: { type: "user", label: "Checked in by" },
223
+ usedByName: {
224
+ type: "text",
225
+ label: "Checked in by (name)",
226
+ description: "The name of whoever checked the ticket in, as it was then.",
227
+ },
228
+ },
229
+ states: {
230
+ field: "state",
231
+ initial: "valid",
232
+ moves: [
233
+ { from: "valid", to: "used", by: ["staff"] },
234
+ { from: "used", to: "valid", by: ["staff"] },
235
+ { from: ["valid", "used"], to: "void", by: ["staff", "host"], final: true },
236
+ ],
237
+ },
238
+ // The holder reads their ticket's event, type, code and state, and changes nothing.
239
+ customer: { field: "holder", read: ["event", "tickettype", "code", "state"], write: [] },
240
+ timelineLinks: ["holder"],
241
+ indexes: [["code"], ["event", "state"], ["holder"], ["order"]],
242
+ },
243
+ },
244
+ views: {
245
+ onSale: {
246
+ label: "On sale",
247
+ object: "ticketing.event",
248
+ filter: { field: "status", op: "eq", value: "on_sale" },
249
+ sort: { field: "startsAt", direction: "asc" },
250
+ columns: ["name", "startsAt", "venue", "places", "taken", "available"],
251
+ },
252
+ thisWeek: {
253
+ label: "This week's events",
254
+ object: "ticketing.event",
255
+ filter: {
256
+ and: [
257
+ { field: "startsAt", op: "gte", value: { $relative: "startOfWeek" } },
258
+ { field: "startsAt", op: "lt", value: { $relative: "startOfNextWeek" } },
259
+ ],
260
+ },
261
+ sort: { field: "startsAt", direction: "asc" },
262
+ columns: ["name", "startsAt", "venue", "status", "taken"],
263
+ },
264
+ unusedTickets: {
265
+ label: "Unused tickets",
266
+ object: "ticketing.ticket",
267
+ filter: { field: "state", op: "eq", value: "valid" },
268
+ sort: { field: "createdAt", direction: "desc" },
269
+ columns: ["name", "event", "tickettype", "holder", "code", "createdAt"],
270
+ },
271
+ },
272
+ dashboards: ticketingDashboards,
273
+ // A buyer's tickets on their Person page; check-ins post to their timeline through the
274
+ // ticket's tracked state and its holder link, and orders through the host (ADR 0429).
275
+ recordTabs: {
276
+ personTickets: {
277
+ label: "Tickets",
278
+ on: "person",
279
+ view: {
280
+ type: "table",
281
+ object: "ticketing.ticket",
282
+ relation: "holder",
283
+ columns: ["name", "event", "tickettype", "state", "usedAt", "code"],
284
+ sort: { field: "createdAt", direction: "desc" },
285
+ },
286
+ order: 30,
287
+ },
288
+ },
289
+ settings: {
290
+ ticketsUrl: {
291
+ type: "text",
292
+ label: "Where buyers see their tickets",
293
+ description: "The page on your site or app where a signed-in buyer sees their tickets. Linked from the " +
294
+ "tickets email, with ?order=<id>.",
295
+ },
296
+ payUrl: {
297
+ type: "text",
298
+ label: "Where buyers pay a balance",
299
+ description: "The page where a signed-in buyer pays what is owed on an order. Linked from the balance " +
300
+ "reminders, with ?order=<id>.",
301
+ },
302
+ },
303
+ automations: ticketingAutomations,
304
+ roles: {
305
+ door: {
306
+ label: "Door",
307
+ description: "Checks tickets in at the door and sees events, ticket types and tickets. Nothing " +
308
+ "else: no people, orders, leads or settings.",
309
+ permissions: ["ticketing:checkin"],
310
+ read: ["ticketing.event", "ticketing.tickettype", "ticketing.ticket"],
311
+ },
312
+ },
313
+ tools: { eventsOnSale, orderStart, myTickets, salesSummary, checkIn, undoCheckIn },
314
+ });
@@ -0,0 +1,184 @@
1
+ import { z } from "@composable-os/sdk";
2
+ export declare const eventsOnSale: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
3
+ event: z.ZodOptional<z.ZodString>;
4
+ limit: z.ZodDefault<z.ZodNumber>;
5
+ }, z.core.$strip>, z.ZodObject<{
6
+ events: z.ZodArray<z.ZodObject<{
7
+ id: z.ZodString;
8
+ name: z.ZodNullable<z.ZodString>;
9
+ startsAt: z.ZodNullable<z.ZodString>;
10
+ endsAt: z.ZodNullable<z.ZodString>;
11
+ timeZone: z.ZodNullable<z.ZodString>;
12
+ venue: z.ZodNullable<z.ZodString>;
13
+ description: z.ZodNullable<z.ZodString>;
14
+ image: z.ZodNullable<z.ZodString>;
15
+ availability: z.ZodObject<{
16
+ status: z.ZodEnum<{
17
+ available: "available";
18
+ low: "low";
19
+ sold_out: "sold_out";
20
+ }>;
21
+ available: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
22
+ }, z.core.$strip>;
23
+ ticketTypes: z.ZodArray<z.ZodObject<{
24
+ id: z.ZodString;
25
+ name: z.ZodNullable<z.ZodString>;
26
+ description: z.ZodNullable<z.ZodString>;
27
+ price: z.ZodNullable<z.ZodNumber>;
28
+ currency: z.ZodNullable<z.ZodString>;
29
+ onSaleFrom: z.ZodNullable<z.ZodString>;
30
+ onSaleUntil: z.ZodNullable<z.ZodString>;
31
+ maxPerOrder: z.ZodNullable<z.ZodNumber>;
32
+ deposit: z.ZodNullable<z.ZodNumber>;
33
+ balanceDue: z.ZodNullable<z.ZodString>;
34
+ availability: z.ZodObject<{
35
+ status: z.ZodEnum<{
36
+ available: "available";
37
+ low: "low";
38
+ sold_out: "sold_out";
39
+ }>;
40
+ available: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
41
+ }, z.core.$strip>;
42
+ }, z.core.$strip>>;
43
+ }, z.core.$strip>>;
44
+ }, z.core.$strip>>;
45
+ export declare const orderStart: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
46
+ lines: z.ZodArray<z.ZodObject<{
47
+ ticketTypeId: z.ZodString;
48
+ quantity: z.ZodDefault<z.ZodNumber>;
49
+ }, z.core.$strip>>;
50
+ pay: z.ZodDefault<z.ZodEnum<{
51
+ deposit: "deposit";
52
+ full: "full";
53
+ }>>;
54
+ email: z.ZodOptional<z.ZodString>;
55
+ }, z.core.$strip>, z.ZodObject<{
56
+ id: z.ZodString;
57
+ state: z.ZodString;
58
+ currency: z.ZodString;
59
+ total: z.ZodNumber;
60
+ paid: z.ZodNumber;
61
+ balance: z.ZodNumber;
62
+ pay: z.ZodString;
63
+ deposit: z.ZodNullable<z.ZodNumber>;
64
+ balanceDueAt: z.ZodNullable<z.ZodString>;
65
+ expiresAt: z.ZodNullable<z.ZodString>;
66
+ lines: z.ZodArray<z.ZodObject<{
67
+ id: z.ZodString;
68
+ ticketTypeId: z.ZodString;
69
+ title: z.ZodString;
70
+ quantity: z.ZodNumber;
71
+ unitPrice: z.ZodNumber;
72
+ total: z.ZodNumber;
73
+ }, z.core.$strip>>;
74
+ token: z.ZodNullable<z.ZodString>;
75
+ }, z.core.$strip>>;
76
+ export declare const myTickets: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
77
+ event: z.ZodOptional<z.ZodString>;
78
+ code: z.ZodOptional<z.ZodString>;
79
+ state: z.ZodOptional<z.ZodEnum<{
80
+ void: "void";
81
+ valid: "valid";
82
+ used: "used";
83
+ }>>;
84
+ cursor: z.ZodOptional<z.ZodString>;
85
+ limit: z.ZodDefault<z.ZodNumber>;
86
+ }, z.core.$strip>, z.ZodObject<{
87
+ items: z.ZodArray<z.ZodObject<{
88
+ id: z.ZodString;
89
+ event: z.ZodNullable<z.ZodString>;
90
+ ticketType: z.ZodNullable<z.ZodString>;
91
+ code: z.ZodNullable<z.ZodString>;
92
+ state: z.ZodNullable<z.ZodString>;
93
+ eventName: z.ZodNullable<z.ZodString>;
94
+ startsAt: z.ZodNullable<z.ZodString>;
95
+ endsAt: z.ZodNullable<z.ZodString>;
96
+ timeZone: z.ZodNullable<z.ZodString>;
97
+ venue: z.ZodNullable<z.ZodString>;
98
+ eventStatus: z.ZodNullable<z.ZodString>;
99
+ ticketTypeName: z.ZodNullable<z.ZodString>;
100
+ }, z.core.$strip>>;
101
+ nextCursor: z.ZodNullable<z.ZodString>;
102
+ }, z.core.$strip>>;
103
+ export declare const salesSummary: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
104
+ eventId: z.ZodString;
105
+ }, z.core.$strip>, z.ZodObject<{
106
+ event: z.ZodObject<{
107
+ id: z.ZodString;
108
+ name: z.ZodNullable<z.ZodString>;
109
+ status: z.ZodNullable<z.ZodString>;
110
+ }, z.core.$strip>;
111
+ currency: z.ZodNullable<z.ZodString>;
112
+ ticketTypes: z.ZodArray<z.ZodObject<{
113
+ id: z.ZodString;
114
+ name: z.ZodNullable<z.ZodString>;
115
+ price: z.ZodNullable<z.ZodNumber>;
116
+ sold: z.ZodNumber;
117
+ held: z.ZodNumber;
118
+ remaining: z.ZodNullable<z.ZodNumber>;
119
+ revenue: z.ZodNumber;
120
+ }, z.core.$strip>>;
121
+ totals: z.ZodObject<{
122
+ sold: z.ZodNumber;
123
+ held: z.ZodNumber;
124
+ remaining: z.ZodNullable<z.ZodNumber>;
125
+ revenue: z.ZodNumber;
126
+ }, z.core.$strip>;
127
+ }, z.core.$strip>>;
128
+ /** A code as a scanner or a person typed it: case, spaces and dashes do not matter. */
129
+ export declare function normaliseCode(code: string): string;
130
+ export declare const checkIn: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
131
+ code: z.ZodString;
132
+ }, z.core.$strip>, z.ZodObject<{
133
+ result: z.ZodEnum<{
134
+ void: "void";
135
+ unknown: "unknown";
136
+ accepted: "accepted";
137
+ already_used: "already_used";
138
+ }>;
139
+ accepted: z.ZodBoolean;
140
+ message: z.ZodString;
141
+ ticket: z.ZodNullable<z.ZodObject<{
142
+ id: z.ZodString;
143
+ name: z.ZodNullable<z.ZodString>;
144
+ event: z.ZodNullable<z.ZodString>;
145
+ ticketType: z.ZodNullable<z.ZodString>;
146
+ holder: z.ZodNullable<z.ZodObject<{
147
+ id: z.ZodString;
148
+ name: z.ZodNullable<z.ZodString>;
149
+ }, z.core.$strip>>;
150
+ state: z.ZodNullable<z.ZodString>;
151
+ usedAt: z.ZodNullable<z.ZodString>;
152
+ usedBy: z.ZodNullable<z.ZodObject<{
153
+ id: z.ZodString;
154
+ name: z.ZodNullable<z.ZodString>;
155
+ }, z.core.$strip>>;
156
+ }, z.core.$strip>>;
157
+ balanceOwing: z.ZodNullable<z.ZodObject<{
158
+ amount: z.ZodNumber;
159
+ currency: z.ZodString;
160
+ dueAt: z.ZodNullable<z.ZodString>;
161
+ }, z.core.$strip>>;
162
+ }, z.core.$strip>>;
163
+ export declare const undoCheckIn: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
164
+ ticketId: z.ZodString;
165
+ }, z.core.$strip>, z.ZodObject<{
166
+ undone: z.ZodBoolean;
167
+ message: z.ZodString;
168
+ ticket: z.ZodObject<{
169
+ id: z.ZodString;
170
+ name: z.ZodNullable<z.ZodString>;
171
+ event: z.ZodNullable<z.ZodString>;
172
+ ticketType: z.ZodNullable<z.ZodString>;
173
+ holder: z.ZodNullable<z.ZodObject<{
174
+ id: z.ZodString;
175
+ name: z.ZodNullable<z.ZodString>;
176
+ }, z.core.$strip>>;
177
+ state: z.ZodNullable<z.ZodString>;
178
+ usedAt: z.ZodNullable<z.ZodString>;
179
+ usedBy: z.ZodNullable<z.ZodObject<{
180
+ id: z.ZodString;
181
+ name: z.ZodNullable<z.ZodString>;
182
+ }, z.core.$strip>>;
183
+ }, z.core.$strip>;
184
+ }, z.core.$strip>>;