@composable-os/pack-ticketing 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/automations.d.ts +2 -1
- package/dist/automations.js +52 -145
- package/dist/blocks/ticketing-checkout/ticket-picker.d.ts +9 -3
- package/dist/blocks/ticketing-checkout/ticket-picker.js +91 -17
- package/dist/blocks/ticketing-my-tickets/my-tickets.js +9 -3
- package/dist/blocks/ticketing-native-my-tickets/my-tickets-screen.d.ts +5 -2
- package/dist/blocks/ticketing-native-my-tickets/my-tickets-screen.js +5 -6
- package/dist/blocks/ticketing-native-scanner/door-scanner-screen.js +2 -2
- package/dist/blocks/ticketing-native-ticket/ticket-screen.js +4 -3
- package/dist/blocks/ticketing-order/order-confirmation.js +2 -1
- package/dist/client/index.d.ts +28 -2
- package/dist/client/index.js +31 -14
- package/dist/index.d.ts +218 -1
- package/dist/index.js +77 -5
- package/dist/routine-mail.d.ts +160 -0
- package/dist/routine-mail.js +137 -0
- package/dist/tools.d.ts +21 -0
- package/dist/tools.js +86 -45
- package/package.json +3 -3
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
export declare const ticketingRoutineMail: {
|
|
2
|
+
tickets: {
|
|
3
|
+
label: string;
|
|
4
|
+
description: string;
|
|
5
|
+
about: string;
|
|
6
|
+
slots: {
|
|
7
|
+
events: {
|
|
8
|
+
each: {
|
|
9
|
+
object: string;
|
|
10
|
+
via: string;
|
|
11
|
+
distinct: string;
|
|
12
|
+
max: number;
|
|
13
|
+
line: string;
|
|
14
|
+
slots: {
|
|
15
|
+
event: {
|
|
16
|
+
field: string;
|
|
17
|
+
};
|
|
18
|
+
when: {
|
|
19
|
+
field: string;
|
|
20
|
+
format: "datetime";
|
|
21
|
+
zone: string;
|
|
22
|
+
year: true;
|
|
23
|
+
optional: true;
|
|
24
|
+
};
|
|
25
|
+
venue: {
|
|
26
|
+
field: string;
|
|
27
|
+
optional: true;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
tickets: {
|
|
33
|
+
each: {
|
|
34
|
+
object: string;
|
|
35
|
+
via: string;
|
|
36
|
+
max: number;
|
|
37
|
+
line: string;
|
|
38
|
+
slots: {
|
|
39
|
+
name: {
|
|
40
|
+
field: string;
|
|
41
|
+
};
|
|
42
|
+
code: {
|
|
43
|
+
field: string;
|
|
44
|
+
max: number;
|
|
45
|
+
private: true;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
link: {
|
|
51
|
+
link: string;
|
|
52
|
+
withId: string;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
messages: {
|
|
56
|
+
one: {
|
|
57
|
+
subject: string;
|
|
58
|
+
text: string;
|
|
59
|
+
};
|
|
60
|
+
many: {
|
|
61
|
+
subject: string;
|
|
62
|
+
text: string;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
eventReminder: {
|
|
67
|
+
label: string;
|
|
68
|
+
description: string;
|
|
69
|
+
about: string;
|
|
70
|
+
essential: false;
|
|
71
|
+
channels: ("push" | "email" | "text")[];
|
|
72
|
+
until: string;
|
|
73
|
+
open: {
|
|
74
|
+
screen: string;
|
|
75
|
+
};
|
|
76
|
+
slots: {
|
|
77
|
+
event: {
|
|
78
|
+
field: string;
|
|
79
|
+
};
|
|
80
|
+
when: {
|
|
81
|
+
field: string;
|
|
82
|
+
format: "datetime";
|
|
83
|
+
zone: string;
|
|
84
|
+
year: true;
|
|
85
|
+
optional: true;
|
|
86
|
+
};
|
|
87
|
+
venue: {
|
|
88
|
+
field: string;
|
|
89
|
+
optional: true;
|
|
90
|
+
};
|
|
91
|
+
count: {
|
|
92
|
+
count: {
|
|
93
|
+
max: number;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
time: {
|
|
97
|
+
field: string;
|
|
98
|
+
format: "time";
|
|
99
|
+
zone: string;
|
|
100
|
+
optional: true;
|
|
101
|
+
};
|
|
102
|
+
place: {
|
|
103
|
+
field: string;
|
|
104
|
+
max: number;
|
|
105
|
+
optional: true;
|
|
106
|
+
};
|
|
107
|
+
short: {
|
|
108
|
+
field: string;
|
|
109
|
+
max: number;
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
messages: {
|
|
113
|
+
one: {
|
|
114
|
+
subject: string;
|
|
115
|
+
text: string;
|
|
116
|
+
textMessage: string;
|
|
117
|
+
push: {
|
|
118
|
+
title: string;
|
|
119
|
+
body: string;
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
many: {
|
|
123
|
+
subject: string;
|
|
124
|
+
text: string;
|
|
125
|
+
textMessage: string;
|
|
126
|
+
push: {
|
|
127
|
+
title: string;
|
|
128
|
+
body: string;
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
balance: {
|
|
134
|
+
label: string;
|
|
135
|
+
description: string;
|
|
136
|
+
about: string;
|
|
137
|
+
slots: {
|
|
138
|
+
balance: {
|
|
139
|
+
field: string;
|
|
140
|
+
format: "money";
|
|
141
|
+
currency: string;
|
|
142
|
+
};
|
|
143
|
+
due: {
|
|
144
|
+
field: string;
|
|
145
|
+
format: "date";
|
|
146
|
+
year: true;
|
|
147
|
+
};
|
|
148
|
+
link: {
|
|
149
|
+
link: string;
|
|
150
|
+
withId: string;
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
messages: {
|
|
154
|
+
due: {
|
|
155
|
+
subject: string;
|
|
156
|
+
text: string;
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
};
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
export const ticketingRoutineMail = {
|
|
2
|
+
tickets: {
|
|
3
|
+
label: "Tickets by email",
|
|
4
|
+
description: "When an order is first paid (in full, or its deposit): the buyer's tickets, one line per " +
|
|
5
|
+
"ticket with its code, and the page where they can show them. To the order's own address.",
|
|
6
|
+
about: "order",
|
|
7
|
+
slots: {
|
|
8
|
+
events: {
|
|
9
|
+
each: {
|
|
10
|
+
object: "ticket",
|
|
11
|
+
via: "order",
|
|
12
|
+
distinct: "event",
|
|
13
|
+
max: 100,
|
|
14
|
+
line: "{event}[: {when}][, {venue}]",
|
|
15
|
+
slots: {
|
|
16
|
+
event: { field: "event.name" },
|
|
17
|
+
when: {
|
|
18
|
+
field: "event.startsAt",
|
|
19
|
+
format: "datetime",
|
|
20
|
+
zone: "event.timezone",
|
|
21
|
+
year: true,
|
|
22
|
+
optional: true,
|
|
23
|
+
},
|
|
24
|
+
venue: { field: "event.venue", optional: true },
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
tickets: {
|
|
29
|
+
each: {
|
|
30
|
+
object: "ticket",
|
|
31
|
+
via: "order",
|
|
32
|
+
max: 100,
|
|
33
|
+
line: "{name}: {code}",
|
|
34
|
+
// The door code: never in a push, which shows on a locked screen.
|
|
35
|
+
slots: { name: { field: "name" }, code: { field: "code", max: 40, private: true } },
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
link: { link: "ticketsUrl", withId: "order" },
|
|
39
|
+
},
|
|
40
|
+
messages: {
|
|
41
|
+
one: {
|
|
42
|
+
subject: "Your ticket",
|
|
43
|
+
text: [
|
|
44
|
+
"Thank you. Your ticket is below: show the code at the door.",
|
|
45
|
+
"",
|
|
46
|
+
"{events}",
|
|
47
|
+
"",
|
|
48
|
+
"{tickets}",
|
|
49
|
+
"",
|
|
50
|
+
"[See it any time: {link}]",
|
|
51
|
+
].join("\n"),
|
|
52
|
+
},
|
|
53
|
+
many: {
|
|
54
|
+
subject: "Your tickets",
|
|
55
|
+
text: [
|
|
56
|
+
"Thank you. Your tickets are below: show the code at the door.",
|
|
57
|
+
"",
|
|
58
|
+
"{events}",
|
|
59
|
+
"",
|
|
60
|
+
"{tickets}",
|
|
61
|
+
"",
|
|
62
|
+
"[See them any time: {link}]",
|
|
63
|
+
].join("\n"),
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
eventReminder: {
|
|
68
|
+
label: "Event reminders",
|
|
69
|
+
description: "The day before an event on sale starts, counted in the event's own time zone: its time " +
|
|
70
|
+
"and venue. To each holder of a valid ticket, once however many tickets they hold.",
|
|
71
|
+
about: "ticket",
|
|
72
|
+
essential: false,
|
|
73
|
+
channels: ["email", "text", "push"],
|
|
74
|
+
until: "event.startsAt",
|
|
75
|
+
open: { screen: "ticket" },
|
|
76
|
+
slots: {
|
|
77
|
+
event: { field: "event.name" },
|
|
78
|
+
when: {
|
|
79
|
+
field: "event.startsAt",
|
|
80
|
+
format: "datetime",
|
|
81
|
+
zone: "event.timezone",
|
|
82
|
+
year: true,
|
|
83
|
+
optional: true,
|
|
84
|
+
},
|
|
85
|
+
venue: { field: "event.venue", optional: true },
|
|
86
|
+
count: { count: { max: 1000 } },
|
|
87
|
+
// For texts and pushes, which have less room.
|
|
88
|
+
time: { field: "event.startsAt", format: "time", zone: "event.timezone", optional: true },
|
|
89
|
+
place: { field: "event.venue", max: 40, optional: true },
|
|
90
|
+
short: { field: "event.name", max: 60 },
|
|
91
|
+
},
|
|
92
|
+
messages: {
|
|
93
|
+
one: {
|
|
94
|
+
subject: "Tomorrow: {event}",
|
|
95
|
+
text: [
|
|
96
|
+
"{event} is tomorrow[, starting {when}][ at {venue}].",
|
|
97
|
+
"You have a ticket: bring the code.",
|
|
98
|
+
].join("\n"),
|
|
99
|
+
textMessage: "Tomorrow: {event}[ at {time}][, {place}]. Bring your ticket's code.",
|
|
100
|
+
push: { title: "Tomorrow[ at {time}]", body: "{short}[, {place}]. Bring your ticket." },
|
|
101
|
+
},
|
|
102
|
+
many: {
|
|
103
|
+
subject: "Tomorrow: {event}",
|
|
104
|
+
text: [
|
|
105
|
+
"{event} is tomorrow[, starting {when}][ at {venue}].",
|
|
106
|
+
"You have {count} tickets: bring the code.",
|
|
107
|
+
].join("\n"),
|
|
108
|
+
textMessage: "Tomorrow: {event}[ at {time}][, {place}]. Bring your {count} tickets' codes.",
|
|
109
|
+
push: {
|
|
110
|
+
title: "Tomorrow[ at {time}]",
|
|
111
|
+
body: "{short}[, {place}]. Bring your {count} tickets.",
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
balance: {
|
|
117
|
+
label: "Balance reminders",
|
|
118
|
+
description: "Every morning, for a part-paid ticket order whose balance is due in a week or tomorrow: " +
|
|
119
|
+
"how much is owed, when, and the page to pay it. To the order's own address.",
|
|
120
|
+
about: "order",
|
|
121
|
+
slots: {
|
|
122
|
+
balance: { field: "balance", format: "money", currency: "currency" },
|
|
123
|
+
due: { field: "balanceDueAt", format: "date", year: true },
|
|
124
|
+
link: { link: "payUrl", withId: "order" },
|
|
125
|
+
},
|
|
126
|
+
messages: {
|
|
127
|
+
due: {
|
|
128
|
+
subject: "Balance due {due}",
|
|
129
|
+
text: [
|
|
130
|
+
"The balance on your tickets, {balance}, is due on {due}.",
|
|
131
|
+
"Pay it when you sign in with this email address[: {link}].",
|
|
132
|
+
"You can pay it in one go or in parts.",
|
|
133
|
+
].join("\n"),
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
};
|
package/dist/tools.d.ts
CHANGED
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
import { z } from "@composable-os/sdk";
|
|
2
|
+
export declare const EVENT = "ticketing.event";
|
|
3
|
+
export declare const TICKET_TYPE = "ticketing.tickettype";
|
|
4
|
+
export declare const TICKET = "ticketing.ticket";
|
|
5
|
+
/** A record as record.get, record.list, my.list and public.list return it. */
|
|
6
|
+
export interface HostRecord {
|
|
7
|
+
id: string;
|
|
8
|
+
title: string | null;
|
|
9
|
+
values: Record<string, unknown>;
|
|
10
|
+
}
|
|
11
|
+
/** A page of records. */
|
|
12
|
+
export interface HostPage {
|
|
13
|
+
items: HostRecord[];
|
|
14
|
+
nextCursor?: string | null;
|
|
15
|
+
/** On a sellable object's records (a ticket type): the currency its prices are in. */
|
|
16
|
+
currency?: string | null;
|
|
17
|
+
}
|
|
18
|
+
/** The host refused a move `from` a state the record is no longer in (ADR 0437). */
|
|
19
|
+
export declare function isConflict(error: unknown): boolean;
|
|
2
20
|
export declare const eventsOnSale: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
|
|
3
21
|
event: z.ZodOptional<z.ZodString>;
|
|
4
22
|
limit: z.ZodDefault<z.ZodNumber>;
|
|
@@ -52,6 +70,7 @@ export declare const orderStart: import("@composable-os/sdk").ToolSpec<z.ZodObje
|
|
|
52
70
|
full: "full";
|
|
53
71
|
}>>;
|
|
54
72
|
email: z.ZodOptional<z.ZodString>;
|
|
73
|
+
agreements: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
55
74
|
}, z.core.$strip>, z.ZodObject<{
|
|
56
75
|
id: z.ZodString;
|
|
57
76
|
state: z.ZodString;
|
|
@@ -100,6 +119,8 @@ export declare const myTickets: import("@composable-os/sdk").ToolSpec<z.ZodObjec
|
|
|
100
119
|
}, z.core.$strip>>;
|
|
101
120
|
nextCursor: z.ZodNullable<z.ZodString>;
|
|
102
121
|
}, z.core.$strip>>;
|
|
122
|
+
/** Ticket types per revenue query: with the object type, 100 bound values, query.sql's most. */
|
|
123
|
+
export declare const REVENUE_IDS_PER_QUERY = 99;
|
|
103
124
|
export declare const salesSummary: import("@composable-os/sdk").ToolSpec<z.ZodObject<{
|
|
104
125
|
eventId: z.ZodString;
|
|
105
126
|
}, z.core.$strip>, z.ZodObject<{
|
package/dist/tools.js
CHANGED
|
@@ -3,11 +3,33 @@
|
|
|
3
3
|
// order, places, who may see a ticket and that a ticket is used once are all the host's. A tool
|
|
4
4
|
// asks, and reports what the host answered.
|
|
5
5
|
import { defineTool, OpsCallError, z } from "@composable-os/sdk";
|
|
6
|
-
const EVENT = "ticketing.event";
|
|
7
|
-
const TICKET_TYPE = "ticketing.tickettype";
|
|
8
|
-
const TICKET = "ticketing.ticket";
|
|
6
|
+
export const EVENT = "ticketing.event";
|
|
7
|
+
export const TICKET_TYPE = "ticketing.tickettype";
|
|
8
|
+
export const TICKET = "ticketing.ticket";
|
|
9
|
+
/** The host refused a move `from` a state the record is no longer in (ADR 0437). */
|
|
10
|
+
export function isConflict(error) {
|
|
11
|
+
return error instanceof OpsCallError && error.code === "conflict";
|
|
12
|
+
}
|
|
9
13
|
const text = (value) => value === null || value === undefined ? null : String(value);
|
|
10
14
|
const num = (value) => typeof value === "number" ? value : value == null ? null : Number(value);
|
|
15
|
+
const sum = (values) => values.reduce((total, value) => total + value, 0);
|
|
16
|
+
/**
|
|
17
|
+
* An amount in the minor unit as the door reads it: `300.00 AUD`, `5000 JPY`. The same as the
|
|
18
|
+
* headless entry's formatMoney, which the blocks use; the host bundles only the extension's own
|
|
19
|
+
* files, so the tools cannot import client code.
|
|
20
|
+
*/
|
|
21
|
+
function moneyText(minor, currency) {
|
|
22
|
+
let digits = 2;
|
|
23
|
+
try {
|
|
24
|
+
digits =
|
|
25
|
+
new Intl.NumberFormat("en", { style: "currency", currency }).resolvedOptions()
|
|
26
|
+
.maximumFractionDigits ?? 2;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// Not a currency Intl knows: two places, as the blocks show it.
|
|
30
|
+
}
|
|
31
|
+
return `${(minor / 10 ** digits).toFixed(digits)} ${currency}`;
|
|
32
|
+
}
|
|
11
33
|
// --- On sale -------------------------------------------------------------------------------------
|
|
12
34
|
const availability = z.object({
|
|
13
35
|
status: z.enum(["available", "low", "sold_out"]),
|
|
@@ -72,19 +94,20 @@ export const eventsOnSale = defineTool({
|
|
|
72
94
|
limit: input.limit,
|
|
73
95
|
});
|
|
74
96
|
const places = async (object, id) => {
|
|
75
|
-
const
|
|
76
|
-
return {
|
|
77
|
-
status: view.status,
|
|
78
|
-
...(view.available === undefined ? {} : { available: view.available }),
|
|
79
|
-
};
|
|
97
|
+
const { status, available } = await ctx.ops.call("capacity.get", { object, id });
|
|
98
|
+
return available === undefined ? { status } : { status, available };
|
|
80
99
|
};
|
|
81
100
|
const out = [];
|
|
82
101
|
for (const event of events.items) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
102
|
+
// The event's ticket types and its own places, asked together.
|
|
103
|
+
const [types, eventPlaces] = await Promise.all([
|
|
104
|
+
ctx.ops.call("public.list", {
|
|
105
|
+
object: TICKET_TYPE,
|
|
106
|
+
filter: { field: "event", op: "eq", value: event.id },
|
|
107
|
+
limit: 50,
|
|
108
|
+
}),
|
|
109
|
+
places(EVENT, event.id),
|
|
110
|
+
]);
|
|
88
111
|
const v = event.values;
|
|
89
112
|
out.push({
|
|
90
113
|
id: event.id,
|
|
@@ -95,7 +118,7 @@ export const eventsOnSale = defineTool({
|
|
|
95
118
|
venue: text(v.venue),
|
|
96
119
|
description: text(v.description),
|
|
97
120
|
image: text(v.image),
|
|
98
|
-
availability:
|
|
121
|
+
availability: eventPlaces,
|
|
99
122
|
ticketTypes: await Promise.all(types.items.map(async (type) => ({
|
|
100
123
|
id: type.id,
|
|
101
124
|
name: text(type.values.name),
|
|
@@ -164,6 +187,13 @@ export const orderStart = defineTool({
|
|
|
164
187
|
.max(320)
|
|
165
188
|
.optional()
|
|
166
189
|
.describe("A guest's email address. A signed-in customer passes none."),
|
|
190
|
+
agreements: z
|
|
191
|
+
.array(z.record(z.string(), z.unknown()))
|
|
192
|
+
.max(20)
|
|
193
|
+
.optional()
|
|
194
|
+
.describe("A guest only: their acceptances of what is due, passed on to the host as they are (each " +
|
|
195
|
+
"{ versionId, typedName, signature?, answers? }); the host checks and records them. A " +
|
|
196
|
+
"signed-in member agrees first."),
|
|
167
197
|
}),
|
|
168
198
|
output: orderOutput,
|
|
169
199
|
risk: "write",
|
|
@@ -177,6 +207,7 @@ export const orderStart = defineTool({
|
|
|
177
207
|
})),
|
|
178
208
|
pay: input.pay,
|
|
179
209
|
...(input.email === undefined ? {} : { email: input.email }),
|
|
210
|
+
...(input.agreements === undefined ? {} : { agreements: input.agreements }),
|
|
180
211
|
});
|
|
181
212
|
return {
|
|
182
213
|
id: order.id,
|
|
@@ -256,7 +287,9 @@ export const myTickets = defineTool({
|
|
|
256
287
|
// fields those objects declare for them (customerVia, ADR 0439), whatever the event's state,
|
|
257
288
|
// and only for records one of their own tickets points to.
|
|
258
289
|
const pointed = async (object, field) => {
|
|
259
|
-
const ids = [
|
|
290
|
+
const ids = [
|
|
291
|
+
...new Set(page.items.map((t) => text(t.values[field])).filter((id) => Boolean(id))),
|
|
292
|
+
];
|
|
260
293
|
if (!ids.length)
|
|
261
294
|
return new Map();
|
|
262
295
|
const found = await ctx.ops.call("my.list", {
|
|
@@ -266,8 +299,10 @@ export const myTickets = defineTool({
|
|
|
266
299
|
});
|
|
267
300
|
return new Map(found.items.map((item) => [item.id, item.values]));
|
|
268
301
|
};
|
|
269
|
-
const events = await
|
|
270
|
-
|
|
302
|
+
const [events, types] = await Promise.all([
|
|
303
|
+
pointed(EVENT, "event"),
|
|
304
|
+
pointed(TICKET_TYPE, "tickettype"),
|
|
305
|
+
]);
|
|
271
306
|
return {
|
|
272
307
|
items: page.items.map((ticket) => {
|
|
273
308
|
const eventId = text(ticket.values.event);
|
|
@@ -294,6 +329,8 @@ export const myTickets = defineTool({
|
|
|
294
329
|
},
|
|
295
330
|
});
|
|
296
331
|
// --- Sales ----------------------------------------------------------------------------------------
|
|
332
|
+
/** Ticket types per revenue query: with the object type, 100 bound values, query.sql's most. */
|
|
333
|
+
export const REVENUE_IDS_PER_QUERY = 99;
|
|
297
334
|
export const salesSummary = defineTool({
|
|
298
335
|
description: "How one event is selling, per ticket type: places sold (taken), held by orders being paid, " +
|
|
299
336
|
"remaining (null when unlimited), and revenue (the line totals of orders paid in full or by " +
|
|
@@ -326,22 +363,27 @@ export const salesSummary = defineTool({
|
|
|
326
363
|
object: EVENT,
|
|
327
364
|
id: input.eventId,
|
|
328
365
|
});
|
|
329
|
-
const types = await
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
366
|
+
const [types, settings] = await Promise.all([
|
|
367
|
+
ctx.ops.call("record.list", {
|
|
368
|
+
object: TICKET_TYPE,
|
|
369
|
+
filter: { field: "event", op: "eq", value: event.id },
|
|
370
|
+
sort: { field: "name", direction: "asc" },
|
|
371
|
+
limit: 200,
|
|
372
|
+
}),
|
|
373
|
+
ctx.ops.call("order.settings.get", {}),
|
|
374
|
+
]);
|
|
375
|
+
// Revenue from the order lines the host snapshotted: paid in full, or by deposit. query.sql
|
|
376
|
+
// binds at most 100 values (and D1 no more), so the ticket types are asked in parts.
|
|
335
377
|
const revenue = new Map();
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
const
|
|
378
|
+
const ids = types.items.map((t) => t.id);
|
|
379
|
+
for (let at = 0; at < ids.length; at += REVENUE_IDS_PER_QUERY) {
|
|
380
|
+
const part = ids.slice(at, at + REVENUE_IDS_PER_QUERY);
|
|
339
381
|
const result = await ctx.ops.call("query.sql", {
|
|
340
382
|
sql: "SELECT l.record_id AS id, SUM(l.line_total) AS revenue FROM rec_order_line l " +
|
|
341
383
|
"JOIN rec_order o ON o.id = l.order_id WHERE l.object_type = ? " +
|
|
342
|
-
`AND o.state IN ('paid', 'part_paid') AND l.record_id IN (${
|
|
384
|
+
`AND o.state IN ('paid', 'part_paid') AND l.record_id IN (${part.map(() => "?").join(", ")}) ` +
|
|
343
385
|
"GROUP BY l.record_id",
|
|
344
|
-
params: [TICKET_TYPE, ...
|
|
386
|
+
params: [TICKET_TYPE, ...part],
|
|
345
387
|
});
|
|
346
388
|
for (const row of result.rows)
|
|
347
389
|
revenue.set(row.id, Number(row.revenue ?? 0));
|
|
@@ -357,23 +399,22 @@ export const salesSummary = defineTool({
|
|
|
357
399
|
}));
|
|
358
400
|
const eventLeft = num(event.values.available);
|
|
359
401
|
const typesLeft = ticketTypes.every((t) => t.remaining !== null)
|
|
360
|
-
? ticketTypes.
|
|
402
|
+
? sum(ticketTypes.map((t) => t.remaining ?? 0))
|
|
361
403
|
: null;
|
|
362
|
-
const settings = await ctx.ops.call("order.settings.get", {});
|
|
363
404
|
return {
|
|
364
405
|
event: { id: event.id, name: text(event.values.name), status: text(event.values.status) },
|
|
365
406
|
currency: settings.currency ?? null,
|
|
366
407
|
ticketTypes,
|
|
367
408
|
totals: {
|
|
368
|
-
sold: ticketTypes.
|
|
369
|
-
held: ticketTypes.
|
|
409
|
+
sold: sum(ticketTypes.map((t) => t.sold)),
|
|
410
|
+
held: sum(ticketTypes.map((t) => t.held)),
|
|
370
411
|
// The fewer of the event's places left and the ticket types' own.
|
|
371
412
|
remaining: eventLeft === null
|
|
372
413
|
? typesLeft
|
|
373
414
|
: typesLeft === null
|
|
374
415
|
? eventLeft
|
|
375
416
|
: Math.min(eventLeft, typesLeft),
|
|
376
|
-
revenue: ticketTypes.
|
|
417
|
+
revenue: sum(ticketTypes.map((t) => t.revenue)),
|
|
377
418
|
},
|
|
378
419
|
};
|
|
379
420
|
},
|
|
@@ -438,6 +479,10 @@ async function describeTicket(ctx, ticket) {
|
|
|
438
479
|
usedBy: usedBy ? { id: usedBy, name: text(v.usedByName) } : null,
|
|
439
480
|
};
|
|
440
481
|
}
|
|
482
|
+
/** A ticket as it is now, after the host refused to move it. */
|
|
483
|
+
async function readTicket(ctx, id) {
|
|
484
|
+
return describeTicket(ctx, await ctx.ops.call("record.get", { object: TICKET, id }));
|
|
485
|
+
}
|
|
441
486
|
/** What a ticket that cannot be let in is reported as. */
|
|
442
487
|
function refusedFor(ticket) {
|
|
443
488
|
if (ticket.state === "void") {
|
|
@@ -498,6 +543,7 @@ async function checkInHandler(input, ctx) {
|
|
|
498
543
|
const usedAt = new Date().toISOString();
|
|
499
544
|
const staff = ctx.caller?.kind === "staff" ? ctx.caller : null;
|
|
500
545
|
const usedBy = staff?.userId ?? null;
|
|
546
|
+
const usedByName = staff?.name || null;
|
|
501
547
|
try {
|
|
502
548
|
// Moved out of `valid` only if it is still valid when the host writes it (ADR 0437): of two
|
|
503
549
|
// scanners at the same moment, one is let in and the other told who was first.
|
|
@@ -505,14 +551,13 @@ async function checkInHandler(input, ctx) {
|
|
|
505
551
|
object: TICKET,
|
|
506
552
|
id: record.id,
|
|
507
553
|
from: "valid",
|
|
508
|
-
values: { state: "used", usedAt, usedBy, usedByName
|
|
554
|
+
values: { state: "used", usedAt, usedBy, usedByName },
|
|
509
555
|
});
|
|
510
556
|
}
|
|
511
557
|
catch (error) {
|
|
512
|
-
if (!(error
|
|
558
|
+
if (!isConflict(error))
|
|
513
559
|
throw error;
|
|
514
|
-
const
|
|
515
|
-
const ticket = await describeTicket(ctx, now);
|
|
560
|
+
const ticket = await readTicket(ctx, record.id);
|
|
516
561
|
return (refusedFor(ticket) ?? {
|
|
517
562
|
// Moved by someone and back again in the meantime: say so, and let them scan again.
|
|
518
563
|
result: "unknown",
|
|
@@ -528,12 +573,12 @@ async function checkInHandler(input, ctx) {
|
|
|
528
573
|
result: "accepted",
|
|
529
574
|
accepted: true,
|
|
530
575
|
message: `Valid${name ? `: ${name}` : ""}. Let them in.` +
|
|
531
|
-
(owing ? ` A balance of ${(owing.amount
|
|
576
|
+
(owing ? ` A balance of ${moneyText(owing.amount, owing.currency)} is owing.` : ""),
|
|
532
577
|
ticket: {
|
|
533
578
|
...before,
|
|
534
579
|
state: "used",
|
|
535
580
|
usedAt,
|
|
536
|
-
usedBy: usedBy ? { id: usedBy, name:
|
|
581
|
+
usedBy: usedBy ? { id: usedBy, name: usedByName } : null,
|
|
537
582
|
},
|
|
538
583
|
balanceOwing: owing,
|
|
539
584
|
};
|
|
@@ -572,13 +617,9 @@ export const undoCheckIn = defineTool({
|
|
|
572
617
|
};
|
|
573
618
|
}
|
|
574
619
|
catch (error) {
|
|
575
|
-
if (!(error
|
|
620
|
+
if (!isConflict(error))
|
|
576
621
|
throw error;
|
|
577
|
-
const
|
|
578
|
-
object: TICKET,
|
|
579
|
-
id: input.ticketId,
|
|
580
|
-
});
|
|
581
|
-
const ticket = await describeTicket(ctx, now);
|
|
622
|
+
const ticket = await readTicket(ctx, input.ticketId);
|
|
582
623
|
return {
|
|
583
624
|
undone: false,
|
|
584
625
|
message: ticket.state === "void"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@composable-os/pack-ticketing",
|
|
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": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"dist"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@composable-os/client": "0.1.0-beta.
|
|
31
|
-
"@composable-os/sdk": "0.1.0-beta.
|
|
30
|
+
"@composable-os/client": "0.1.0-beta.13",
|
|
31
|
+
"@composable-os/sdk": "0.1.0-beta.13"
|
|
32
32
|
}
|
|
33
33
|
}
|