@knot-technologies/seatmap 0.4.0-dev.1 → 0.4.0-dev.11
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/README.md +195 -3
- package/dist/core/index.cjs +1144 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +21 -0
- package/dist/core/index.d.ts +21 -0
- package/dist/core/index.js +1109 -0
- package/dist/core/index.js.map +1 -0
- package/dist/engineUrl-sEraidd5.d.cts +11 -0
- package/dist/engineUrl-sEraidd5.d.ts +11 -0
- package/dist/index.cjs +561 -156
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.js +558 -153
- package/dist/index.js.map +1 -1
- package/package.json +15 -5
|
@@ -0,0 +1,1109 @@
|
|
|
1
|
+
// ../seatmap-types/dist/index.js
|
|
2
|
+
var SECTION_CONTENTS_MODES = [
|
|
3
|
+
"always",
|
|
4
|
+
"seatsOnly",
|
|
5
|
+
"afterZoom"
|
|
6
|
+
];
|
|
7
|
+
function isSectionContentsMode(value) {
|
|
8
|
+
return SECTION_CONTENTS_MODES.some((mode) => mode === value);
|
|
9
|
+
}
|
|
10
|
+
var LEGEND_CONTENT_MODES = ["nameAndPrice", "name", "price"];
|
|
11
|
+
function isLegendContentMode(value) {
|
|
12
|
+
return LEGEND_CONTENT_MODES.some((mode) => mode === value);
|
|
13
|
+
}
|
|
14
|
+
function isSeatmapLegendConfig(value) {
|
|
15
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return Object.entries(value).every(([key, entry]) => {
|
|
19
|
+
switch (key) {
|
|
20
|
+
case "show":
|
|
21
|
+
case "hideAccessibleSeatsFilter":
|
|
22
|
+
case "hideUnavailableItem":
|
|
23
|
+
case "hideNonSelectableCategories":
|
|
24
|
+
return entry === void 0 || typeof entry === "boolean";
|
|
25
|
+
case "content":
|
|
26
|
+
return entry === void 0 || isLegendContentMode(entry);
|
|
27
|
+
default:
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function isSeatmapColorScheme(value) {
|
|
33
|
+
return value === "light" || value === "dark";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// ../seatmap-rpc/dist/envelope.js
|
|
37
|
+
var PROTOCOL_VERSION = 1;
|
|
38
|
+
var ENVELOPE_TYPES = [
|
|
39
|
+
"request",
|
|
40
|
+
"reply",
|
|
41
|
+
"event",
|
|
42
|
+
"hello"
|
|
43
|
+
];
|
|
44
|
+
function isEnvelopeType(value) {
|
|
45
|
+
return ENVELOPE_TYPES.includes(value);
|
|
46
|
+
}
|
|
47
|
+
function isEnvelope(value) {
|
|
48
|
+
if (typeof value !== "object" || value === null) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
const candidate = value;
|
|
52
|
+
return candidate.protocolVersion === PROTOCOL_VERSION && typeof candidate.channelId === "string" && isEnvelopeType(candidate.type);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ../seatmap-rpc/dist/endpoint.js
|
|
56
|
+
var RpcError = class extends Error {
|
|
57
|
+
code;
|
|
58
|
+
method;
|
|
59
|
+
constructor(code, message, method) {
|
|
60
|
+
super(message);
|
|
61
|
+
this.name = "RpcError";
|
|
62
|
+
this.code = code;
|
|
63
|
+
this.method = method;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
function createEndpoint({ transport, channelId, requestTimeoutMs = 1e4 }) {
|
|
67
|
+
const pending = /* @__PURE__ */ new Map();
|
|
68
|
+
const eventHandlers = /* @__PURE__ */ new Map();
|
|
69
|
+
const requestHandlers = /* @__PURE__ */ new Map();
|
|
70
|
+
let nextId = 1;
|
|
71
|
+
let closed = false;
|
|
72
|
+
const detach = transport.onMessage((message) => {
|
|
73
|
+
if (!isEnvelope(message) || message.channelId !== channelId) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (message.type === "reply") {
|
|
77
|
+
settleReply(message);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (message.type === "request") {
|
|
81
|
+
void serveRequest(message);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (message.type === "event" && typeof message.event === "string") {
|
|
85
|
+
eventHandlers.get(message.event)?.forEach((handler) => handler(message.payload));
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
function settleReply(message) {
|
|
89
|
+
if (typeof message.id !== "number") {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const settlers = pending.get(message.id);
|
|
93
|
+
if (!settlers) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
pending.delete(message.id);
|
|
97
|
+
clearTimeout(settlers.timeout);
|
|
98
|
+
if (message.error) {
|
|
99
|
+
settlers.reject(new RpcError(message.error.code, message.error.message, message.error.method));
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
settlers.resolve(message.result);
|
|
103
|
+
}
|
|
104
|
+
function sendMethodError(message, error) {
|
|
105
|
+
transport.send({
|
|
106
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
107
|
+
channelId,
|
|
108
|
+
type: "reply",
|
|
109
|
+
id: message.id,
|
|
110
|
+
error: {
|
|
111
|
+
code: error.code,
|
|
112
|
+
message: error.message,
|
|
113
|
+
method: error.method ?? message.method
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
async function serveRequest(message) {
|
|
118
|
+
if (typeof message.id !== "number" || typeof message.method !== "string") {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const handler = requestHandlers.get(message.method);
|
|
122
|
+
if (!handler) {
|
|
123
|
+
sendMethodError(message, new RpcError("METHOD_NOT_IMPLEMENTED", `Method '${message.method}' is not implemented`, message.method));
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
const result = await handler(message.params);
|
|
128
|
+
transport.send({
|
|
129
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
130
|
+
channelId,
|
|
131
|
+
type: "reply",
|
|
132
|
+
id: message.id,
|
|
133
|
+
result
|
|
134
|
+
});
|
|
135
|
+
} catch (error) {
|
|
136
|
+
sendMethodError(message, error instanceof RpcError ? error : new RpcError("ENGINE_INCOMPATIBLE", error instanceof Error ? error.message : "RPC handler failed", message.method));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
request(method, params, options) {
|
|
141
|
+
if (closed) {
|
|
142
|
+
return Promise.reject(new RpcError("CHART_DESTROYED", "The chart has been destroyed", method));
|
|
143
|
+
}
|
|
144
|
+
const id = nextId++;
|
|
145
|
+
return new Promise((resolve, reject) => {
|
|
146
|
+
const timeoutMs = options?.timeoutMs === void 0 ? requestTimeoutMs : options.timeoutMs;
|
|
147
|
+
const timeout = timeoutMs === null ? void 0 : setTimeout(() => {
|
|
148
|
+
pending.delete(id);
|
|
149
|
+
reject(new RpcError("ENGINE_UNREACHABLE", `Engine did not reply to '${method}' within ${timeoutMs}ms`, method));
|
|
150
|
+
}, timeoutMs);
|
|
151
|
+
pending.set(id, { resolve, reject, method, timeout });
|
|
152
|
+
try {
|
|
153
|
+
transport.send({
|
|
154
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
155
|
+
channelId,
|
|
156
|
+
type: "request",
|
|
157
|
+
id,
|
|
158
|
+
method,
|
|
159
|
+
params
|
|
160
|
+
});
|
|
161
|
+
} catch {
|
|
162
|
+
clearTimeout(timeout);
|
|
163
|
+
pending.delete(id);
|
|
164
|
+
reject(new RpcError("ENGINE_UNREACHABLE", `Engine is unreachable for '${method}'`, method));
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
},
|
|
168
|
+
handle(method, handler) {
|
|
169
|
+
requestHandlers.set(method, handler);
|
|
170
|
+
return () => {
|
|
171
|
+
if (requestHandlers.get(method) === handler) {
|
|
172
|
+
requestHandlers.delete(method);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
},
|
|
176
|
+
emit(event, payload) {
|
|
177
|
+
if (closed) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
transport.send({
|
|
181
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
182
|
+
channelId,
|
|
183
|
+
type: "event",
|
|
184
|
+
event,
|
|
185
|
+
payload
|
|
186
|
+
});
|
|
187
|
+
},
|
|
188
|
+
on(event, handler) {
|
|
189
|
+
const forEvent = eventHandlers.get(event) ?? /* @__PURE__ */ new Set();
|
|
190
|
+
forEvent.add(handler);
|
|
191
|
+
eventHandlers.set(event, forEvent);
|
|
192
|
+
return () => {
|
|
193
|
+
forEvent.delete(handler);
|
|
194
|
+
};
|
|
195
|
+
},
|
|
196
|
+
close() {
|
|
197
|
+
if (closed) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
closed = true;
|
|
201
|
+
detach();
|
|
202
|
+
pending.forEach(({ reject, method, timeout }) => {
|
|
203
|
+
clearTimeout(timeout);
|
|
204
|
+
reject(new RpcError("CHART_DESTROYED", "The chart has been destroyed", method));
|
|
205
|
+
});
|
|
206
|
+
pending.clear();
|
|
207
|
+
eventHandlers.clear();
|
|
208
|
+
requestHandlers.clear();
|
|
209
|
+
transport.close();
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// ../seatmap-rpc/dist/nativeTransport.js
|
|
215
|
+
var NATIVE_BRIDGE_GLOBAL = "__knotSeatmapNative";
|
|
216
|
+
function nativeReceiveScript(envelope) {
|
|
217
|
+
return `window.${NATIVE_BRIDGE_GLOBAL}.receive(${JSON.stringify(envelope)});true;`;
|
|
218
|
+
}
|
|
219
|
+
function originOf(url) {
|
|
220
|
+
try {
|
|
221
|
+
return new URL(url).origin;
|
|
222
|
+
} catch {
|
|
223
|
+
return void 0;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function parse(data) {
|
|
227
|
+
try {
|
|
228
|
+
return JSON.parse(data);
|
|
229
|
+
} catch {
|
|
230
|
+
return void 0;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
function createNativeHostTransport({ inject, channelId, engineOrigin: engineOrigin2 }) {
|
|
234
|
+
if (engineOrigin2 === "*") {
|
|
235
|
+
throw new Error("A wildcard engine origin is not allowed; pass the exact engine origin");
|
|
236
|
+
}
|
|
237
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
238
|
+
let closed = false;
|
|
239
|
+
return {
|
|
240
|
+
send(envelope) {
|
|
241
|
+
if (closed) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
inject(nativeReceiveScript(envelope));
|
|
245
|
+
},
|
|
246
|
+
onMessage(listener) {
|
|
247
|
+
listeners.add(listener);
|
|
248
|
+
return () => {
|
|
249
|
+
listeners.delete(listener);
|
|
250
|
+
};
|
|
251
|
+
},
|
|
252
|
+
close() {
|
|
253
|
+
closed = true;
|
|
254
|
+
listeners.clear();
|
|
255
|
+
},
|
|
256
|
+
deliver({ data, url }) {
|
|
257
|
+
if (closed || originOf(url) !== engineOrigin2) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
const message = parse(data);
|
|
261
|
+
if (!isEnvelope(message) || message.channelId !== channelId) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
listeners.forEach((listener) => listener(message));
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// src/chartHandle.ts
|
|
270
|
+
function isRecord(value) {
|
|
271
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
272
|
+
}
|
|
273
|
+
function isObjectRef(value) {
|
|
274
|
+
if (!isRecord(value)) {
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
return (value.type === "seat" || value.type === "gaArea" || value.type === "table") && typeof value.id === "string" && value.id.length > 0;
|
|
278
|
+
}
|
|
279
|
+
function isObjectRefArray(value) {
|
|
280
|
+
return Array.isArray(value) && value.every(isObjectRef);
|
|
281
|
+
}
|
|
282
|
+
function isNonemptyString(value) {
|
|
283
|
+
return typeof value === "string" && value.length > 0;
|
|
284
|
+
}
|
|
285
|
+
function isOptionalString(value) {
|
|
286
|
+
return value === void 0 || typeof value === "string";
|
|
287
|
+
}
|
|
288
|
+
function isOptionalIdentifier(value) {
|
|
289
|
+
return value === void 0 || isNonemptyString(value);
|
|
290
|
+
}
|
|
291
|
+
function isStringArray(value) {
|
|
292
|
+
return Array.isArray(value) && value.every(isNonemptyString);
|
|
293
|
+
}
|
|
294
|
+
function isFloor(value) {
|
|
295
|
+
return isRecord(value) && isNonemptyString(value.id) && isNonemptyString(value.name) && isNonemptyString(value.shortName) && isStringArray(value.categoryIds);
|
|
296
|
+
}
|
|
297
|
+
function isNonnegativeFiniteNumber(value) {
|
|
298
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
299
|
+
}
|
|
300
|
+
function isPositiveFiniteNumber(value) {
|
|
301
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0;
|
|
302
|
+
}
|
|
303
|
+
function isNonnegativeSafeInteger(value) {
|
|
304
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
305
|
+
}
|
|
306
|
+
function isOptionalPrice(value) {
|
|
307
|
+
return value === void 0 || typeof value === "string" || typeof value === "number" && Number.isFinite(value);
|
|
308
|
+
}
|
|
309
|
+
function toLifecycleIdentity(value) {
|
|
310
|
+
if (!isRecord(value)) {
|
|
311
|
+
return void 0;
|
|
312
|
+
}
|
|
313
|
+
const keys = Object.keys(value);
|
|
314
|
+
if (keys.length === 1 && keys[0] === "sessionId" && isNonemptyString(value.sessionId)) {
|
|
315
|
+
return { sessionId: value.sessionId };
|
|
316
|
+
}
|
|
317
|
+
if (keys.length === 1 && keys[0] === "seasonKey" && isNonemptyString(value.seasonKey)) {
|
|
318
|
+
return { seasonKey: value.seasonKey };
|
|
319
|
+
}
|
|
320
|
+
return void 0;
|
|
321
|
+
}
|
|
322
|
+
function isSeatEventPayload(value) {
|
|
323
|
+
return isRecord(value) && value.type === "seat" && isOptionalIdentifier(value.floorId) && isNonemptyString(value.id) && isNonemptyString(value.sectionId) && isOptionalIdentifier(value.categoryId) && isOptionalString(value.label) && isOptionalString(value.rowLabel) && isOptionalString(value.seatLabel);
|
|
324
|
+
}
|
|
325
|
+
function isSeatClickEventPayload(value) {
|
|
326
|
+
return isRecord(value) && isSeatEventPayload(value) && typeof value.selected === "boolean" && typeof value.status === "string";
|
|
327
|
+
}
|
|
328
|
+
function hasSeatSelectionFields(value, selected) {
|
|
329
|
+
return isRecord(value) && isSeatEventPayload(value) && value.selected === selected && isOptionalString(value.sectionLabel);
|
|
330
|
+
}
|
|
331
|
+
function hasGaAreaFields(value, selected) {
|
|
332
|
+
return isRecord(value) && value.type === "gaArea" && isOptionalIdentifier(value.floorId) && isNonemptyString(value.id) && isNonemptyString(value.categoryId) && typeof value.label === "string" && typeof value.code === "string" && typeof value.selected === "boolean" && (selected === void 0 || value.selected === selected) && isNonnegativeSafeInteger(value.quantity) && isNonnegativeSafeInteger(value.available) && isNonnegativeSafeInteger(value.capacity) && isNonnegativeSafeInteger(value.booked) && isNonnegativeSafeInteger(value.held) && isOptionalPrice(value.price);
|
|
333
|
+
}
|
|
334
|
+
function isGaAreaEventPayload(value) {
|
|
335
|
+
return hasGaAreaFields(value);
|
|
336
|
+
}
|
|
337
|
+
function hasTableFields(value, selected) {
|
|
338
|
+
return isRecord(value) && value.type === "table" && isOptionalIdentifier(value.floorId) && isNonemptyString(value.id) && isStringArray(value.seatIds) && isOptionalIdentifier(value.sectionId) && isOptionalIdentifier(value.categoryId) && (value.bookingMode === void 0 || value.bookingMode === "seat" || value.bookingMode === "table" || value.bookingMode === "variable") && isOptionalString(value.label) && typeof value.selected === "boolean" && (selected === void 0 || value.selected === selected) && isNonnegativeSafeInteger(value.quantity);
|
|
339
|
+
}
|
|
340
|
+
function isTableEventPayload(value) {
|
|
341
|
+
return hasTableFields(value);
|
|
342
|
+
}
|
|
343
|
+
function isSelectionEventPayload(value, selected) {
|
|
344
|
+
if (!isRecord(value)) {
|
|
345
|
+
return false;
|
|
346
|
+
}
|
|
347
|
+
switch (value.type) {
|
|
348
|
+
case "seat":
|
|
349
|
+
return hasSeatSelectionFields(value, selected);
|
|
350
|
+
case "gaArea":
|
|
351
|
+
return hasGaAreaFields(value, selected);
|
|
352
|
+
case "table":
|
|
353
|
+
return hasTableFields(value, selected);
|
|
354
|
+
default:
|
|
355
|
+
return false;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
function isSelectedObject(value) {
|
|
359
|
+
if (!isRecord(value)) {
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
362
|
+
if (value.type === "table") {
|
|
363
|
+
return hasTableFields(value, true) && isNonnegativeSafeInteger(value.available) && isNonnegativeSafeInteger(value.capacity) && isNonnegativeSafeInteger(value.booked) && isNonnegativeSafeInteger(value.held);
|
|
364
|
+
}
|
|
365
|
+
return isSelectionEventPayload(value, true);
|
|
366
|
+
}
|
|
367
|
+
function isClickedObject(value) {
|
|
368
|
+
if (!isRecord(value)) {
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
371
|
+
switch (value.type) {
|
|
372
|
+
case "seat":
|
|
373
|
+
return isSeatClickEventPayload(value);
|
|
374
|
+
case "gaArea":
|
|
375
|
+
return isGaAreaEventPayload(value);
|
|
376
|
+
case "table":
|
|
377
|
+
return isTableEventPayload(value);
|
|
378
|
+
default:
|
|
379
|
+
return false;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
function isMouseObject(value) {
|
|
383
|
+
if (!isRecord(value)) {
|
|
384
|
+
return false;
|
|
385
|
+
}
|
|
386
|
+
switch (value.type) {
|
|
387
|
+
case "seat":
|
|
388
|
+
return isSeatEventPayload(value);
|
|
389
|
+
case "gaArea":
|
|
390
|
+
return isGaAreaEventPayload(value);
|
|
391
|
+
case "table":
|
|
392
|
+
return isTableEventPayload(value);
|
|
393
|
+
default:
|
|
394
|
+
return false;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
function isSeatBlockedEventPayload(value) {
|
|
398
|
+
return isRecord(value) && isSeatEventPayload(value) && isNonemptyString(value.reason) && isOptionalString(value.message);
|
|
399
|
+
}
|
|
400
|
+
function isObjectStatusChangedEventPayload(value) {
|
|
401
|
+
return isRecord(value) && isSeatEventPayload(value) && isNonemptyString(value.status) && isNonemptyString(value.previousStatus) && typeof value.selected === "boolean";
|
|
402
|
+
}
|
|
403
|
+
function isZoomLevelChangedEventPayload(value) {
|
|
404
|
+
return isRecord(value) && (value.level === "overview" || value.level === "section" || value.level === "seat") && isPositiveFiniteNumber(value.scale) && isNonnegativeFiniteNumber(value.seatPixelSize);
|
|
405
|
+
}
|
|
406
|
+
function isViewportChangedEventPayload(value) {
|
|
407
|
+
if (!isRecord(value) || !isRecord(value.transform) || !isRecord(value.boundsWorld)) {
|
|
408
|
+
return false;
|
|
409
|
+
}
|
|
410
|
+
return isPositiveFiniteNumber(value.transform.scale) && typeof value.transform.x === "number" && Number.isFinite(value.transform.x) && typeof value.transform.y === "number" && Number.isFinite(value.transform.y) && typeof value.boundsWorld.minX === "number" && Number.isFinite(value.boundsWorld.minX) && typeof value.boundsWorld.minY === "number" && Number.isFinite(value.boundsWorld.minY) && typeof value.boundsWorld.maxX === "number" && Number.isFinite(value.boundsWorld.maxX) && typeof value.boundsWorld.maxY === "number" && Number.isFinite(value.boundsWorld.maxY);
|
|
411
|
+
}
|
|
412
|
+
function isSectionFocusEventPayload(value) {
|
|
413
|
+
return isRecord(value) && isNonemptyString(value.sectionId) && isOptionalIdentifier(value.floorId);
|
|
414
|
+
}
|
|
415
|
+
function isInventorySelection(value) {
|
|
416
|
+
if (!isRecord(value)) {
|
|
417
|
+
return false;
|
|
418
|
+
}
|
|
419
|
+
return Object.keys(value).every((key) => key === "seatIds" || key === "gaAreas") && Array.isArray(value.seatIds) && value.seatIds.every((id) => typeof id === "string") && Array.isArray(value.gaAreas) && value.gaAreas.every(
|
|
420
|
+
(area) => isRecord(area) && Object.keys(area).every((key) => key === "id" || key === "quantity") && typeof area.id === "string" && typeof area.quantity === "number" && Number.isSafeInteger(area.quantity) && area.quantity >= 1
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
function toInventorySelection(selection) {
|
|
424
|
+
return {
|
|
425
|
+
seatIds: [...selection.seatIds],
|
|
426
|
+
gaAreas: selection.gaAreas.map((area) => ({
|
|
427
|
+
id: area.id,
|
|
428
|
+
quantity: area.quantity
|
|
429
|
+
}))
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
var SEASON_HOLD_OPERATIONS = ["create", "replace", "renew", "release"];
|
|
433
|
+
var SEASON_HOLD_TERMINAL_STATUSES = ["released", "expired", "booked"];
|
|
434
|
+
var SEASON_HOLD_ALLOWED_KEYS = {
|
|
435
|
+
idle: ["status", "seasonKey"],
|
|
436
|
+
updating: ["status", "seasonKey", "operation", "holdId"],
|
|
437
|
+
active: ["status", "seasonKey", "holdId", "selection", "expiresAt"],
|
|
438
|
+
released: ["status", "seasonKey", "holdId"],
|
|
439
|
+
expired: ["status", "seasonKey", "holdId"],
|
|
440
|
+
booked: ["status", "seasonKey", "holdId"]
|
|
441
|
+
};
|
|
442
|
+
function hasOnlyApprovedKeys(value, status) {
|
|
443
|
+
const allowed = SEASON_HOLD_ALLOWED_KEYS[status];
|
|
444
|
+
if (!allowed) {
|
|
445
|
+
return false;
|
|
446
|
+
}
|
|
447
|
+
return Object.keys(value).every((key) => allowed.includes(key));
|
|
448
|
+
}
|
|
449
|
+
function isSeasonHoldState(value) {
|
|
450
|
+
if (!isRecord(value) || typeof value.seasonKey !== "string") {
|
|
451
|
+
return false;
|
|
452
|
+
}
|
|
453
|
+
if (typeof value.status !== "string") {
|
|
454
|
+
return false;
|
|
455
|
+
}
|
|
456
|
+
switch (value.status) {
|
|
457
|
+
case "idle":
|
|
458
|
+
break;
|
|
459
|
+
case "updating":
|
|
460
|
+
if (typeof value.operation !== "string" || !SEASON_HOLD_OPERATIONS.includes(value.operation) || value.holdId !== void 0 && typeof value.holdId !== "string") {
|
|
461
|
+
return false;
|
|
462
|
+
}
|
|
463
|
+
break;
|
|
464
|
+
case "active":
|
|
465
|
+
if (typeof value.holdId !== "string" || typeof value.selection !== "object" || value.selection === null || !isInventorySelection(value.selection) || typeof value.expiresAt !== "string") {
|
|
466
|
+
return false;
|
|
467
|
+
}
|
|
468
|
+
break;
|
|
469
|
+
default:
|
|
470
|
+
if (!SEASON_HOLD_TERMINAL_STATUSES.includes(value.status) || typeof value.holdId !== "string") {
|
|
471
|
+
return false;
|
|
472
|
+
}
|
|
473
|
+
break;
|
|
474
|
+
}
|
|
475
|
+
return hasOnlyApprovedKeys(value, value.status);
|
|
476
|
+
}
|
|
477
|
+
function toPublicSeasonHoldState(value) {
|
|
478
|
+
switch (value.status) {
|
|
479
|
+
case "idle":
|
|
480
|
+
return { status: "idle", seasonKey: value.seasonKey };
|
|
481
|
+
case "updating": {
|
|
482
|
+
const updating = {
|
|
483
|
+
status: "updating",
|
|
484
|
+
seasonKey: value.seasonKey,
|
|
485
|
+
operation: value.operation
|
|
486
|
+
};
|
|
487
|
+
if (value.holdId !== void 0) {
|
|
488
|
+
updating.holdId = value.holdId;
|
|
489
|
+
}
|
|
490
|
+
return updating;
|
|
491
|
+
}
|
|
492
|
+
case "active":
|
|
493
|
+
return {
|
|
494
|
+
status: "active",
|
|
495
|
+
seasonKey: value.seasonKey,
|
|
496
|
+
holdId: value.holdId,
|
|
497
|
+
selection: toInventorySelection(value.selection),
|
|
498
|
+
expiresAt: value.expiresAt
|
|
499
|
+
};
|
|
500
|
+
default: {
|
|
501
|
+
const terminal = {
|
|
502
|
+
status: value.status,
|
|
503
|
+
seasonKey: value.seasonKey,
|
|
504
|
+
holdId: value.holdId
|
|
505
|
+
};
|
|
506
|
+
return terminal;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
function isEventPayload(event, payload) {
|
|
511
|
+
switch (event) {
|
|
512
|
+
case "chartRendered":
|
|
513
|
+
return toLifecycleIdentity(payload) !== void 0;
|
|
514
|
+
case "chartRenderingFailed":
|
|
515
|
+
return isRecord(payload) && typeof payload.message === "string";
|
|
516
|
+
case "objectClicked":
|
|
517
|
+
return isClickedObject(payload);
|
|
518
|
+
case "objectSelected":
|
|
519
|
+
return isSelectionEventPayload(payload, true);
|
|
520
|
+
case "objectDeselected":
|
|
521
|
+
return isSelectionEventPayload(payload, false);
|
|
522
|
+
case "selectionChanged":
|
|
523
|
+
return isRecord(payload) && Array.isArray(payload.selected) && payload.selected.every(isSelectedObject);
|
|
524
|
+
case "objectMouseOver":
|
|
525
|
+
case "objectMouseOut":
|
|
526
|
+
return isMouseObject(payload);
|
|
527
|
+
case "seatBlocked":
|
|
528
|
+
return isSeatBlockedEventPayload(payload);
|
|
529
|
+
case "objectStatusChanged":
|
|
530
|
+
return isObjectStatusChangedEventPayload(payload);
|
|
531
|
+
case "zoomLevelChanged":
|
|
532
|
+
return isZoomLevelChangedEventPayload(payload);
|
|
533
|
+
case "viewportChanged":
|
|
534
|
+
return isViewportChangedEventPayload(payload);
|
|
535
|
+
case "sectionFocused":
|
|
536
|
+
case "sectionUnfocused":
|
|
537
|
+
return isSectionFocusEventPayload(payload);
|
|
538
|
+
case "floorChanged":
|
|
539
|
+
return isRecord(payload) && (payload.floor === null || isRecord(payload.floor) && isFloor(payload.floor));
|
|
540
|
+
case "seasonHoldChanged":
|
|
541
|
+
return isRecord(payload) && isSeasonHoldState(payload);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
function copyFloorChanged(payload) {
|
|
545
|
+
return {
|
|
546
|
+
floor: payload.floor ? { ...payload.floor, categoryIds: [...payload.floor.categoryIds] } : null
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
function destroyedError(method) {
|
|
550
|
+
return new RpcError(
|
|
551
|
+
"CHART_DESTROYED",
|
|
552
|
+
"The chart has been destroyed",
|
|
553
|
+
method
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
async function requestVoid(endpoint, method, params, waitForConfirmation = false) {
|
|
557
|
+
await endpoint.request(
|
|
558
|
+
method,
|
|
559
|
+
params,
|
|
560
|
+
waitForConfirmation ? { timeoutMs: null } : void 0
|
|
561
|
+
);
|
|
562
|
+
}
|
|
563
|
+
function createChartHandle(endpoint, removeIframe, options) {
|
|
564
|
+
let destroyed = false;
|
|
565
|
+
let chartRenderedIdentity;
|
|
566
|
+
let currentSeasonHold = options?.initialSeasonHold;
|
|
567
|
+
let currentFloor;
|
|
568
|
+
const unsubscribeFloorChanged = endpoint.on("floorChanged", (payload) => {
|
|
569
|
+
if (isEventPayload("floorChanged", payload))
|
|
570
|
+
currentFloor = copyFloorChanged(payload);
|
|
571
|
+
});
|
|
572
|
+
const subscriptions = [];
|
|
573
|
+
const unsubscribeChartRendered = endpoint.on("chartRendered", (payload) => {
|
|
574
|
+
const identity = toLifecycleIdentity(payload);
|
|
575
|
+
if (identity !== void 0) {
|
|
576
|
+
chartRenderedIdentity = identity;
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
const unsubscribeSeasonHoldChanged = endpoint.on(
|
|
580
|
+
"seasonHoldChanged",
|
|
581
|
+
(payload) => {
|
|
582
|
+
if (isRecord(payload) && isSeasonHoldState(payload)) {
|
|
583
|
+
currentSeasonHold = toPublicSeasonHoldState(payload);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
);
|
|
587
|
+
function assertActive(method) {
|
|
588
|
+
if (destroyed) {
|
|
589
|
+
throw destroyedError(method);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
function onSeasonHoldChanged(handler) {
|
|
593
|
+
if (subscriptions.some(
|
|
594
|
+
(subscription2) => subscription2.event === "seasonHoldChanged" && subscription2.handler === handler
|
|
595
|
+
)) {
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
598
|
+
let liveEventSeen = false;
|
|
599
|
+
const unsubscribe = endpoint.on("seasonHoldChanged", (payload) => {
|
|
600
|
+
if (isRecord(payload) && isSeasonHoldState(payload)) {
|
|
601
|
+
liveEventSeen = true;
|
|
602
|
+
handler(toPublicSeasonHoldState(payload));
|
|
603
|
+
}
|
|
604
|
+
});
|
|
605
|
+
let active = true;
|
|
606
|
+
const subscription = {
|
|
607
|
+
event: "seasonHoldChanged",
|
|
608
|
+
handler,
|
|
609
|
+
unsubscribe() {
|
|
610
|
+
active = false;
|
|
611
|
+
unsubscribe();
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
subscriptions.push(subscription);
|
|
615
|
+
if (currentSeasonHold !== void 0) {
|
|
616
|
+
const stickyState = toPublicSeasonHoldState(currentSeasonHold);
|
|
617
|
+
queueMicrotask(() => {
|
|
618
|
+
if (active && !liveEventSeen) {
|
|
619
|
+
handler(stickyState);
|
|
620
|
+
}
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
function onChartRendered(handler) {
|
|
625
|
+
if (subscriptions.some(
|
|
626
|
+
(subscription) => subscription.event === "chartRendered" && subscription.handler === handler
|
|
627
|
+
)) {
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
const stickyIdentity = chartRenderedIdentity;
|
|
631
|
+
if (stickyIdentity !== void 0) {
|
|
632
|
+
let active = true;
|
|
633
|
+
const subscription = {
|
|
634
|
+
event: "chartRendered",
|
|
635
|
+
handler,
|
|
636
|
+
unsubscribe() {
|
|
637
|
+
active = false;
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
subscriptions.push(subscription);
|
|
641
|
+
queueMicrotask(() => {
|
|
642
|
+
if (active) {
|
|
643
|
+
handler(stickyIdentity);
|
|
644
|
+
}
|
|
645
|
+
});
|
|
646
|
+
return;
|
|
647
|
+
}
|
|
648
|
+
const unsubscribe = endpoint.on("chartRendered", (payload) => {
|
|
649
|
+
const identity = toLifecycleIdentity(payload);
|
|
650
|
+
if (identity !== void 0) {
|
|
651
|
+
handler(identity);
|
|
652
|
+
}
|
|
653
|
+
});
|
|
654
|
+
subscriptions.push({
|
|
655
|
+
event: "chartRendered",
|
|
656
|
+
handler,
|
|
657
|
+
unsubscribe
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
return {
|
|
661
|
+
get isDestroyed() {
|
|
662
|
+
return destroyed;
|
|
663
|
+
},
|
|
664
|
+
async selectObjects(objects) {
|
|
665
|
+
assertActive("selectObjects");
|
|
666
|
+
await requestVoid(
|
|
667
|
+
endpoint,
|
|
668
|
+
"selectObjects",
|
|
669
|
+
{ objects },
|
|
670
|
+
options?.confirmSeatSelection
|
|
671
|
+
);
|
|
672
|
+
},
|
|
673
|
+
async deselectObjects(objects) {
|
|
674
|
+
assertActive("deselectObjects");
|
|
675
|
+
await requestVoid(
|
|
676
|
+
endpoint,
|
|
677
|
+
"deselectObjects",
|
|
678
|
+
{ objects },
|
|
679
|
+
options?.confirmSeatSelection
|
|
680
|
+
);
|
|
681
|
+
},
|
|
682
|
+
async clearSelection() {
|
|
683
|
+
assertActive("clearSelection");
|
|
684
|
+
await requestVoid(
|
|
685
|
+
endpoint,
|
|
686
|
+
"clearSelection",
|
|
687
|
+
{},
|
|
688
|
+
options?.confirmSeatSelection
|
|
689
|
+
);
|
|
690
|
+
},
|
|
691
|
+
async listFloors() {
|
|
692
|
+
assertActive("listFloors");
|
|
693
|
+
const result = await endpoint.request("listFloors", {});
|
|
694
|
+
if (!Array.isArray(result) || !result.every(
|
|
695
|
+
(floor) => isRecord(floor) && isFloor(floor)
|
|
696
|
+
)) {
|
|
697
|
+
throw new RpcError(
|
|
698
|
+
"ENGINE_INCOMPATIBLE",
|
|
699
|
+
"Engine returned invalid floors",
|
|
700
|
+
"listFloors"
|
|
701
|
+
);
|
|
702
|
+
}
|
|
703
|
+
return result;
|
|
704
|
+
},
|
|
705
|
+
async goToFloor(floorId) {
|
|
706
|
+
assertActive("goToFloor");
|
|
707
|
+
await requestVoid(endpoint, "goToFloor", { floorId });
|
|
708
|
+
},
|
|
709
|
+
async goToAllFloors() {
|
|
710
|
+
assertActive("goToAllFloors");
|
|
711
|
+
await requestVoid(endpoint, "goToAllFloors", {});
|
|
712
|
+
},
|
|
713
|
+
async listSelectedObjects() {
|
|
714
|
+
assertActive("listSelectedObjects");
|
|
715
|
+
const result = await endpoint.request("listSelectedObjects", {});
|
|
716
|
+
if (!isObjectRefArray(result)) {
|
|
717
|
+
throw new RpcError(
|
|
718
|
+
"ENGINE_INCOMPATIBLE",
|
|
719
|
+
"Engine returned an invalid selection",
|
|
720
|
+
"listSelectedObjects"
|
|
721
|
+
);
|
|
722
|
+
}
|
|
723
|
+
return result;
|
|
724
|
+
},
|
|
725
|
+
async setObjectQuantity(object, quantity) {
|
|
726
|
+
assertActive("setObjectQuantity");
|
|
727
|
+
await requestVoid(endpoint, "setObjectQuantity", { object, quantity });
|
|
728
|
+
},
|
|
729
|
+
async highlightObjects(objects, color) {
|
|
730
|
+
assertActive("highlightObjects");
|
|
731
|
+
await requestVoid(
|
|
732
|
+
endpoint,
|
|
733
|
+
"highlightObjects",
|
|
734
|
+
color === void 0 ? { objects } : { objects, color }
|
|
735
|
+
);
|
|
736
|
+
},
|
|
737
|
+
async clearHighlights() {
|
|
738
|
+
assertActive("clearHighlights");
|
|
739
|
+
await requestVoid(endpoint, "clearHighlights", {});
|
|
740
|
+
},
|
|
741
|
+
async setMetadata(metadata) {
|
|
742
|
+
assertActive("setMetadata");
|
|
743
|
+
await requestVoid(endpoint, "setMetadata", { metadata });
|
|
744
|
+
},
|
|
745
|
+
async setCategoryMetadata(metadata) {
|
|
746
|
+
assertActive("setCategoryMetadata");
|
|
747
|
+
await requestVoid(endpoint, "setCategoryMetadata", { metadata });
|
|
748
|
+
},
|
|
749
|
+
async holdBestAvailable() {
|
|
750
|
+
assertActive("holdBestAvailable");
|
|
751
|
+
await requestVoid(endpoint, "holdBestAvailable", {});
|
|
752
|
+
},
|
|
753
|
+
async pulse() {
|
|
754
|
+
assertActive("pulse");
|
|
755
|
+
await requestVoid(endpoint, "pulse", {});
|
|
756
|
+
},
|
|
757
|
+
async unpulse() {
|
|
758
|
+
assertActive("unpulse");
|
|
759
|
+
await requestVoid(endpoint, "unpulse", {});
|
|
760
|
+
},
|
|
761
|
+
async spotlight() {
|
|
762
|
+
assertActive("spotlight");
|
|
763
|
+
await requestVoid(endpoint, "spotlight", {});
|
|
764
|
+
},
|
|
765
|
+
async clearSpotlight() {
|
|
766
|
+
assertActive("clearSpotlight");
|
|
767
|
+
await requestVoid(endpoint, "clearSpotlight", {});
|
|
768
|
+
},
|
|
769
|
+
async disableObjects() {
|
|
770
|
+
assertActive("disableObjects");
|
|
771
|
+
await requestVoid(endpoint, "disableObjects", {});
|
|
772
|
+
},
|
|
773
|
+
async enableObjects() {
|
|
774
|
+
assertActive("enableObjects");
|
|
775
|
+
await requestVoid(endpoint, "enableObjects", {});
|
|
776
|
+
},
|
|
777
|
+
async selectCategories() {
|
|
778
|
+
assertActive("selectCategories");
|
|
779
|
+
await requestVoid(endpoint, "selectCategories", {});
|
|
780
|
+
},
|
|
781
|
+
async deselectCategories() {
|
|
782
|
+
assertActive("deselectCategories");
|
|
783
|
+
await requestVoid(endpoint, "deselectCategories", {});
|
|
784
|
+
},
|
|
785
|
+
async listCategories() {
|
|
786
|
+
assertActive("listCategories");
|
|
787
|
+
await requestVoid(endpoint, "listCategories", {});
|
|
788
|
+
},
|
|
789
|
+
async findObject() {
|
|
790
|
+
assertActive("findObject");
|
|
791
|
+
await requestVoid(endpoint, "findObject", {});
|
|
792
|
+
},
|
|
793
|
+
async zoomToObjects(objects) {
|
|
794
|
+
assertActive("zoomToObjects");
|
|
795
|
+
await requestVoid(endpoint, "zoomToObjects", { objects });
|
|
796
|
+
},
|
|
797
|
+
async zoomToSection(sectionId) {
|
|
798
|
+
assertActive("zoomToSection");
|
|
799
|
+
await requestVoid(endpoint, "zoomToSection", { sectionId });
|
|
800
|
+
},
|
|
801
|
+
async resetView() {
|
|
802
|
+
assertActive("resetView");
|
|
803
|
+
await requestVoid(endpoint, "resetView", {});
|
|
804
|
+
},
|
|
805
|
+
async changeConfig(config) {
|
|
806
|
+
assertActive("changeConfig");
|
|
807
|
+
await requestVoid(endpoint, "changeConfig", config);
|
|
808
|
+
},
|
|
809
|
+
async destroy() {
|
|
810
|
+
assertActive("destroy");
|
|
811
|
+
destroyed = true;
|
|
812
|
+
subscriptions.splice(0).forEach((subscription) => subscription.unsubscribe());
|
|
813
|
+
unsubscribeChartRendered();
|
|
814
|
+
unsubscribeFloorChanged();
|
|
815
|
+
unsubscribeSeasonHoldChanged();
|
|
816
|
+
endpoint.close();
|
|
817
|
+
removeIframe();
|
|
818
|
+
},
|
|
819
|
+
on(event, handler) {
|
|
820
|
+
assertActive("on");
|
|
821
|
+
if (event === "seasonHoldChanged") {
|
|
822
|
+
onSeasonHoldChanged(
|
|
823
|
+
handler
|
|
824
|
+
);
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
if (event === "chartRendered") {
|
|
828
|
+
onChartRendered(handler);
|
|
829
|
+
return;
|
|
830
|
+
}
|
|
831
|
+
if (subscriptions.some(
|
|
832
|
+
(subscription) => subscription.event === event && subscription.handler === handler
|
|
833
|
+
)) {
|
|
834
|
+
return;
|
|
835
|
+
}
|
|
836
|
+
let liveEventSeen = false;
|
|
837
|
+
let active = true;
|
|
838
|
+
const unsubscribe = endpoint.on(event, (payload) => {
|
|
839
|
+
if (isEventPayload(event, payload)) {
|
|
840
|
+
liveEventSeen = true;
|
|
841
|
+
handler(payload);
|
|
842
|
+
}
|
|
843
|
+
});
|
|
844
|
+
subscriptions.push({
|
|
845
|
+
event,
|
|
846
|
+
handler,
|
|
847
|
+
unsubscribe() {
|
|
848
|
+
active = false;
|
|
849
|
+
unsubscribe();
|
|
850
|
+
}
|
|
851
|
+
});
|
|
852
|
+
if (event === "floorChanged" && currentFloor !== void 0) {
|
|
853
|
+
const initialFloor = copyFloorChanged(currentFloor);
|
|
854
|
+
queueMicrotask(() => {
|
|
855
|
+
if (active && !liveEventSeen && isEventPayload(event, initialFloor))
|
|
856
|
+
handler(initialFloor);
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
},
|
|
860
|
+
off(event, handler) {
|
|
861
|
+
assertActive("off");
|
|
862
|
+
const index = subscriptions.findIndex(
|
|
863
|
+
(subscription) => subscription.event === event && subscription.handler === handler
|
|
864
|
+
);
|
|
865
|
+
if (index < 0) {
|
|
866
|
+
return;
|
|
867
|
+
}
|
|
868
|
+
subscriptions.splice(index, 1)[0]?.unsubscribe();
|
|
869
|
+
}
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
// src/core/startSeatmapSession.ts
|
|
874
|
+
function isRecord2(value) {
|
|
875
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
876
|
+
}
|
|
877
|
+
function isHandshakeAcknowledgement(value) {
|
|
878
|
+
if (typeof value !== "object" || value === null) {
|
|
879
|
+
return false;
|
|
880
|
+
}
|
|
881
|
+
const result = value;
|
|
882
|
+
return result.protocolVersion === PROTOCOL_VERSION;
|
|
883
|
+
}
|
|
884
|
+
function invalidConfigError() {
|
|
885
|
+
return new RpcError(
|
|
886
|
+
"ENGINE_INCOMPATIBLE",
|
|
887
|
+
"Seatmap config must provide either classic or Season authority, never both"
|
|
888
|
+
);
|
|
889
|
+
}
|
|
890
|
+
function isCategoryFilter(value) {
|
|
891
|
+
if (!isRecord2(value)) {
|
|
892
|
+
return false;
|
|
893
|
+
}
|
|
894
|
+
const keys = Object.keys(value);
|
|
895
|
+
if (keys.length !== 2 || !keys.every((key) => ["categoryIds", "nonMatchingObjects"].includes(key)) || !Array.isArray(value.categoryIds) || !value.categoryIds.every((id) => typeof id === "string" && id.length > 0) || new Set(value.categoryIds).size !== value.categoryIds.length) {
|
|
896
|
+
return false;
|
|
897
|
+
}
|
|
898
|
+
return value.nonMatchingObjects === "hidden" || value.nonMatchingObjects === "disabled";
|
|
899
|
+
}
|
|
900
|
+
function hasValidOptions(config) {
|
|
901
|
+
return (config.colorScheme === void 0 || isSeatmapColorScheme(config.colorScheme)) && (config.sectionContents === void 0 || isSectionContentsMode(config.sectionContents)) && (config.categoryFilter === void 0 || isCategoryFilter(config.categoryFilter)) && (config.startFloor === void 0 || typeof config.startFloor === "string") && (config.lockedFloor === void 0 || typeof config.lockedFloor === "string") && (config.scrollZoom === void 0 || typeof config.scrollZoom === "boolean") && (config.showFloorPicker === void 0 || typeof config.showFloorPicker === "boolean") && (config.showActiveBlockOnMobile === void 0 || typeof config.showActiveBlockOnMobile === "boolean") && (config.legend === void 0 || isSeatmapLegendConfig(config.legend));
|
|
902
|
+
}
|
|
903
|
+
function copyCategoryFilter(filter) {
|
|
904
|
+
return {
|
|
905
|
+
categoryIds: [...filter.categoryIds],
|
|
906
|
+
nonMatchingObjects: filter.nonMatchingObjects
|
|
907
|
+
};
|
|
908
|
+
}
|
|
909
|
+
function hasValidClassicAuthority(config) {
|
|
910
|
+
return typeof config.sessionId === "string" && config.sessionId.length > 0 && typeof config.clientToken === "string" && config.clientToken.length > 0 && config.season === void 0 && config.tokenProvider === void 0 && config.holdId === void 0 && (config.onSeatSelectionChange === void 0 || typeof config.onSeatSelectionChange === "function") && hasValidOptions(config);
|
|
911
|
+
}
|
|
912
|
+
function hasValidSeasonAuthority(config) {
|
|
913
|
+
return !("onSeatSelectionChange" in config && config.onSeatSelectionChange !== void 0) && config.sessionId === void 0 && config.clientToken === void 0 && typeof config.season === "object" && config.season !== null && typeof config.season.seasonKey === "string" && config.season.seasonKey.length > 0 && typeof config.tokenProvider === "function" && hasValidOptions(config);
|
|
914
|
+
}
|
|
915
|
+
function validateMountConfig(config) {
|
|
916
|
+
return hasValidClassicAuthority(config) || hasValidSeasonAuthority(config) ? void 0 : invalidConfigError();
|
|
917
|
+
}
|
|
918
|
+
function classicHelloParams(config) {
|
|
919
|
+
const params = {
|
|
920
|
+
sessionId: config.sessionId,
|
|
921
|
+
clientToken: config.clientToken
|
|
922
|
+
};
|
|
923
|
+
if (config.channelKeys !== void 0) {
|
|
924
|
+
params.channelKeys = config.channelKeys;
|
|
925
|
+
}
|
|
926
|
+
if (config.includePublic !== void 0) {
|
|
927
|
+
params.includePublic = config.includePublic;
|
|
928
|
+
}
|
|
929
|
+
if (config.categoryFilter !== void 0) {
|
|
930
|
+
params.categoryFilter = copyCategoryFilter(config.categoryFilter);
|
|
931
|
+
}
|
|
932
|
+
if (config.sectionContents !== void 0)
|
|
933
|
+
params.sectionContents = config.sectionContents;
|
|
934
|
+
if (config.startFloor !== void 0) params.startFloor = config.startFloor;
|
|
935
|
+
if (config.lockedFloor !== void 0) params.lockedFloor = config.lockedFloor;
|
|
936
|
+
if (config.showFloorPicker !== void 0)
|
|
937
|
+
params.showFloorPicker = config.showFloorPicker;
|
|
938
|
+
if (config.scrollZoom !== void 0) params.scrollZoom = config.scrollZoom;
|
|
939
|
+
if (config.colorScheme !== void 0) params.colorScheme = config.colorScheme;
|
|
940
|
+
if (config.legend !== void 0) params.legend = { ...config.legend };
|
|
941
|
+
if (config.showActiveBlockOnMobile !== void 0)
|
|
942
|
+
params.showActiveBlockOnMobile = config.showActiveBlockOnMobile;
|
|
943
|
+
return {
|
|
944
|
+
...params,
|
|
945
|
+
...config.onSeatSelectionChange ? { confirmSeatSelection: true } : {}
|
|
946
|
+
};
|
|
947
|
+
}
|
|
948
|
+
function seasonHelloParams(config) {
|
|
949
|
+
const params = {
|
|
950
|
+
mode: "season",
|
|
951
|
+
seasonKey: config.season.seasonKey
|
|
952
|
+
};
|
|
953
|
+
if (config.channelKeys !== void 0) {
|
|
954
|
+
params.channelKeys = config.channelKeys;
|
|
955
|
+
}
|
|
956
|
+
if (config.includePublic !== void 0) {
|
|
957
|
+
params.includePublic = config.includePublic;
|
|
958
|
+
}
|
|
959
|
+
if (config.categoryFilter !== void 0) {
|
|
960
|
+
params.categoryFilter = copyCategoryFilter(config.categoryFilter);
|
|
961
|
+
}
|
|
962
|
+
if (config.sectionContents !== void 0)
|
|
963
|
+
params.sectionContents = config.sectionContents;
|
|
964
|
+
if (config.startFloor !== void 0) params.startFloor = config.startFloor;
|
|
965
|
+
if (config.lockedFloor !== void 0) params.lockedFloor = config.lockedFloor;
|
|
966
|
+
if (config.showFloorPicker !== void 0)
|
|
967
|
+
params.showFloorPicker = config.showFloorPicker;
|
|
968
|
+
if (config.scrollZoom !== void 0) params.scrollZoom = config.scrollZoom;
|
|
969
|
+
if (config.colorScheme !== void 0) params.colorScheme = config.colorScheme;
|
|
970
|
+
if (config.legend !== void 0) params.legend = { ...config.legend };
|
|
971
|
+
if (config.showActiveBlockOnMobile !== void 0)
|
|
972
|
+
params.showActiveBlockOnMobile = config.showActiveBlockOnMobile;
|
|
973
|
+
return params;
|
|
974
|
+
}
|
|
975
|
+
function startSeatmapSession({
|
|
976
|
+
transport,
|
|
977
|
+
channelId,
|
|
978
|
+
config,
|
|
979
|
+
onHandshake,
|
|
980
|
+
onTerminate
|
|
981
|
+
}) {
|
|
982
|
+
const endpoint = createEndpoint({ transport, channelId });
|
|
983
|
+
const isSeasonMount = config.season !== void 0;
|
|
984
|
+
if ("onSeatSelectionChange" in config && config.onSeatSelectionChange) {
|
|
985
|
+
const confirm = config.onSeatSelectionChange;
|
|
986
|
+
endpoint.handle("selection.confirmSeats", async (params) => {
|
|
987
|
+
if (!isRecord2(params) || !Array.isArray(params.seatIds) || params.seatIds.length === 0 || !params.seatIds.every((id) => typeof id === "string" && id.length > 0) || typeof params.selected !== "boolean") {
|
|
988
|
+
throw new RpcError(
|
|
989
|
+
"RPC_INVALID_ARGS",
|
|
990
|
+
"Invalid seat selection request"
|
|
991
|
+
);
|
|
992
|
+
}
|
|
993
|
+
await confirm({
|
|
994
|
+
seatIds: [...params.seatIds],
|
|
995
|
+
selected: params.selected
|
|
996
|
+
});
|
|
997
|
+
});
|
|
998
|
+
}
|
|
999
|
+
if (isSeasonMount && "season" in config) {
|
|
1000
|
+
const { holdId, tokenProvider } = config;
|
|
1001
|
+
endpoint.handle("season.getToken", () => tokenProvider());
|
|
1002
|
+
endpoint.handle("season.getHoldId", () => holdId);
|
|
1003
|
+
}
|
|
1004
|
+
const chart = createChartHandle(
|
|
1005
|
+
endpoint,
|
|
1006
|
+
onTerminate,
|
|
1007
|
+
isSeasonMount && "season" in config ? {
|
|
1008
|
+
initialSeasonHold: {
|
|
1009
|
+
status: "idle",
|
|
1010
|
+
seasonKey: config.season.seasonKey
|
|
1011
|
+
}
|
|
1012
|
+
} : {
|
|
1013
|
+
confirmSeatSelection: "onSeatSelectionChange" in config && Boolean(config.onSeatSelectionChange)
|
|
1014
|
+
}
|
|
1015
|
+
);
|
|
1016
|
+
let detachHandshake;
|
|
1017
|
+
const removeHandshakeListener = () => {
|
|
1018
|
+
detachHandshake?.();
|
|
1019
|
+
detachHandshake = void 0;
|
|
1020
|
+
};
|
|
1021
|
+
const ready = new Promise((resolve, reject) => {
|
|
1022
|
+
detachHandshake = onHandshake((data) => {
|
|
1023
|
+
if (!isRecord2(data) || data.channelId !== channelId || data.type !== "hello" || typeof data.protocolVersion !== "number") {
|
|
1024
|
+
return;
|
|
1025
|
+
}
|
|
1026
|
+
removeHandshakeListener();
|
|
1027
|
+
if (data.protocolVersion !== PROTOCOL_VERSION) {
|
|
1028
|
+
reject(
|
|
1029
|
+
new RpcError(
|
|
1030
|
+
"ENGINE_INCOMPATIBLE",
|
|
1031
|
+
`Engine uses unsupported protocol version ${data.protocolVersion}`
|
|
1032
|
+
)
|
|
1033
|
+
);
|
|
1034
|
+
return;
|
|
1035
|
+
}
|
|
1036
|
+
if (isEnvelope(data) && data.error) {
|
|
1037
|
+
reject(
|
|
1038
|
+
new RpcError(
|
|
1039
|
+
data.error.code,
|
|
1040
|
+
data.error.message || "Engine rejected the handshake",
|
|
1041
|
+
data.error.method
|
|
1042
|
+
)
|
|
1043
|
+
);
|
|
1044
|
+
return;
|
|
1045
|
+
}
|
|
1046
|
+
if (!isEnvelope(data) || !isHandshakeAcknowledgement(data.result)) {
|
|
1047
|
+
reject(
|
|
1048
|
+
new RpcError(
|
|
1049
|
+
"ENGINE_INCOMPATIBLE",
|
|
1050
|
+
"Engine acknowledged with an incompatible protocol version"
|
|
1051
|
+
)
|
|
1052
|
+
);
|
|
1053
|
+
return;
|
|
1054
|
+
}
|
|
1055
|
+
resolve(chart);
|
|
1056
|
+
});
|
|
1057
|
+
});
|
|
1058
|
+
transport.send({
|
|
1059
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
1060
|
+
channelId,
|
|
1061
|
+
type: "hello",
|
|
1062
|
+
params: config.season !== void 0 && "season" in config ? seasonHelloParams(config) : classicHelloParams(config)
|
|
1063
|
+
});
|
|
1064
|
+
return {
|
|
1065
|
+
ready,
|
|
1066
|
+
close() {
|
|
1067
|
+
removeHandshakeListener();
|
|
1068
|
+
endpoint.close();
|
|
1069
|
+
}
|
|
1070
|
+
};
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
// src/engineUrl.ts
|
|
1074
|
+
var ENGINE_ARTIFACT = "3055fcaa6d7f2600";
|
|
1075
|
+
var CDN_BASE = "https://dev-seatmap.knottech.ai";
|
|
1076
|
+
function resolveEngineUrl({
|
|
1077
|
+
artifact,
|
|
1078
|
+
cdnBase
|
|
1079
|
+
}) {
|
|
1080
|
+
const base = cdnBase.replace(/\/+$/, "");
|
|
1081
|
+
if (base.length === 0 || artifact.length === 0) {
|
|
1082
|
+
throw new Error("Engine artifact and CDN base must be configured");
|
|
1083
|
+
}
|
|
1084
|
+
return `${base}/engine/${artifact}/engine.html`;
|
|
1085
|
+
}
|
|
1086
|
+
function engineOrigin(engineUrl) {
|
|
1087
|
+
const url = new URL(engineUrl);
|
|
1088
|
+
if (url.protocol !== "https:" && url.protocol !== "http:") {
|
|
1089
|
+
throw new Error("Engine URL must use HTTP or HTTPS");
|
|
1090
|
+
}
|
|
1091
|
+
return url.origin;
|
|
1092
|
+
}
|
|
1093
|
+
function getSeatmapEngineOrigin() {
|
|
1094
|
+
return engineOrigin(
|
|
1095
|
+
resolveEngineUrl({ artifact: ENGINE_ARTIFACT, cdnBase: CDN_BASE })
|
|
1096
|
+
);
|
|
1097
|
+
}
|
|
1098
|
+
export {
|
|
1099
|
+
CDN_BASE,
|
|
1100
|
+
ENGINE_ARTIFACT,
|
|
1101
|
+
RpcError,
|
|
1102
|
+
createNativeHostTransport,
|
|
1103
|
+
engineOrigin,
|
|
1104
|
+
getSeatmapEngineOrigin,
|
|
1105
|
+
resolveEngineUrl,
|
|
1106
|
+
startSeatmapSession,
|
|
1107
|
+
validateMountConfig
|
|
1108
|
+
};
|
|
1109
|
+
//# sourceMappingURL=index.js.map
|