@knot-technologies/seatmap 0.4.0-dev.1 → 0.4.0-dev.10

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.cjs CHANGED
@@ -18,12 +18,12 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
20
  // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
23
  getSeatmapEngineOrigin: () => getSeatmapEngineOrigin,
24
24
  mountSeatmap: () => mountSeatmap
25
25
  });
26
- module.exports = __toCommonJS(index_exports);
26
+ module.exports = __toCommonJS(src_exports);
27
27
 
28
28
  // ../seatmap-rpc/dist/envelope.js
29
29
  var PROTOCOL_VERSION = 1;
@@ -129,16 +129,17 @@ function createEndpoint({ transport, channelId, requestTimeoutMs = 1e4 }) {
129
129
  }
130
130
  }
131
131
  return {
132
- request(method, params) {
132
+ request(method, params, options) {
133
133
  if (closed) {
134
134
  return Promise.reject(new RpcError("CHART_DESTROYED", "The chart has been destroyed", method));
135
135
  }
136
136
  const id = nextId++;
137
137
  return new Promise((resolve, reject) => {
138
- const timeout = setTimeout(() => {
138
+ const timeoutMs = options?.timeoutMs === void 0 ? requestTimeoutMs : options.timeoutMs;
139
+ const timeout = timeoutMs === null ? void 0 : setTimeout(() => {
139
140
  pending.delete(id);
140
- reject(new RpcError("ENGINE_UNREACHABLE", `Engine did not reply to '${method}' within ${requestTimeoutMs}ms`, method));
141
- }, requestTimeoutMs);
141
+ reject(new RpcError("ENGINE_UNREACHABLE", `Engine did not reply to '${method}' within ${timeoutMs}ms`, method));
142
+ }, timeoutMs);
142
143
  pending.set(id, { resolve, reject, method, timeout });
143
144
  try {
144
145
  transport.send({
@@ -235,6 +236,41 @@ function createWindowTransport({ target, targetOrigin, channelId }) {
235
236
  };
236
237
  }
237
238
 
239
+ // ../seatmap-types/dist/index.js
240
+ var SECTION_CONTENTS_MODES = [
241
+ "always",
242
+ "seatsOnly",
243
+ "afterZoom"
244
+ ];
245
+ function isSectionContentsMode(value) {
246
+ return SECTION_CONTENTS_MODES.some((mode) => mode === value);
247
+ }
248
+ var LEGEND_CONTENT_MODES = ["nameAndPrice", "name", "price"];
249
+ function isLegendContentMode(value) {
250
+ return LEGEND_CONTENT_MODES.some((mode) => mode === value);
251
+ }
252
+ function isSeatmapLegendConfig(value) {
253
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
254
+ return false;
255
+ }
256
+ return Object.entries(value).every(([key, entry]) => {
257
+ switch (key) {
258
+ case "show":
259
+ case "hideAccessibleSeatsFilter":
260
+ case "hideUnavailableItem":
261
+ case "hideNonSelectableCategories":
262
+ return entry === void 0 || typeof entry === "boolean";
263
+ case "content":
264
+ return entry === void 0 || isLegendContentMode(entry);
265
+ default:
266
+ return false;
267
+ }
268
+ });
269
+ }
270
+ function isSeatmapColorScheme(value) {
271
+ return value === "light" || value === "dark";
272
+ }
273
+
238
274
  // src/chartHandle.ts
239
275
  function isRecord(value) {
240
276
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -248,6 +284,139 @@ function isObjectRef(value) {
248
284
  function isObjectRefArray(value) {
249
285
  return Array.isArray(value) && value.every(isObjectRef);
250
286
  }
287
+ function isNonemptyString(value) {
288
+ return typeof value === "string" && value.length > 0;
289
+ }
290
+ function isOptionalString(value) {
291
+ return value === void 0 || typeof value === "string";
292
+ }
293
+ function isOptionalIdentifier(value) {
294
+ return value === void 0 || isNonemptyString(value);
295
+ }
296
+ function isStringArray(value) {
297
+ return Array.isArray(value) && value.every(isNonemptyString);
298
+ }
299
+ function isFloor(value) {
300
+ return isRecord(value) && isNonemptyString(value.id) && isNonemptyString(value.name) && isNonemptyString(value.shortName) && isStringArray(value.categoryIds);
301
+ }
302
+ function isNonnegativeFiniteNumber(value) {
303
+ return typeof value === "number" && Number.isFinite(value) && value >= 0;
304
+ }
305
+ function isPositiveFiniteNumber(value) {
306
+ return typeof value === "number" && Number.isFinite(value) && value > 0;
307
+ }
308
+ function isNonnegativeSafeInteger(value) {
309
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
310
+ }
311
+ function isOptionalPrice(value) {
312
+ return value === void 0 || typeof value === "string" || typeof value === "number" && Number.isFinite(value);
313
+ }
314
+ function toLifecycleIdentity(value) {
315
+ if (!isRecord(value)) {
316
+ return void 0;
317
+ }
318
+ const keys = Object.keys(value);
319
+ if (keys.length === 1 && keys[0] === "sessionId" && isNonemptyString(value.sessionId)) {
320
+ return { sessionId: value.sessionId };
321
+ }
322
+ if (keys.length === 1 && keys[0] === "seasonKey" && isNonemptyString(value.seasonKey)) {
323
+ return { seasonKey: value.seasonKey };
324
+ }
325
+ return void 0;
326
+ }
327
+ function isSeatEventPayload(value) {
328
+ 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);
329
+ }
330
+ function isSeatClickEventPayload(value) {
331
+ return isRecord(value) && isSeatEventPayload(value) && typeof value.selected === "boolean" && typeof value.status === "string";
332
+ }
333
+ function hasSeatSelectionFields(value, selected) {
334
+ return isRecord(value) && isSeatEventPayload(value) && value.selected === selected && isOptionalString(value.sectionLabel);
335
+ }
336
+ function hasGaAreaFields(value, selected) {
337
+ 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);
338
+ }
339
+ function isGaAreaEventPayload(value) {
340
+ return hasGaAreaFields(value);
341
+ }
342
+ function hasTableFields(value, selected) {
343
+ 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);
344
+ }
345
+ function isTableEventPayload(value) {
346
+ return hasTableFields(value);
347
+ }
348
+ function isSelectionEventPayload(value, selected) {
349
+ if (!isRecord(value)) {
350
+ return false;
351
+ }
352
+ switch (value.type) {
353
+ case "seat":
354
+ return hasSeatSelectionFields(value, selected);
355
+ case "gaArea":
356
+ return hasGaAreaFields(value, selected);
357
+ case "table":
358
+ return hasTableFields(value, selected);
359
+ default:
360
+ return false;
361
+ }
362
+ }
363
+ function isSelectedObject(value) {
364
+ if (!isRecord(value)) {
365
+ return false;
366
+ }
367
+ if (value.type === "table") {
368
+ return hasTableFields(value, true) && isNonnegativeSafeInteger(value.available) && isNonnegativeSafeInteger(value.capacity) && isNonnegativeSafeInteger(value.booked) && isNonnegativeSafeInteger(value.held);
369
+ }
370
+ return isSelectionEventPayload(value, true);
371
+ }
372
+ function isClickedObject(value) {
373
+ if (!isRecord(value)) {
374
+ return false;
375
+ }
376
+ switch (value.type) {
377
+ case "seat":
378
+ return isSeatClickEventPayload(value);
379
+ case "gaArea":
380
+ return isGaAreaEventPayload(value);
381
+ case "table":
382
+ return isTableEventPayload(value);
383
+ default:
384
+ return false;
385
+ }
386
+ }
387
+ function isMouseObject(value) {
388
+ if (!isRecord(value)) {
389
+ return false;
390
+ }
391
+ switch (value.type) {
392
+ case "seat":
393
+ return isSeatEventPayload(value);
394
+ case "gaArea":
395
+ return isGaAreaEventPayload(value);
396
+ case "table":
397
+ return isTableEventPayload(value);
398
+ default:
399
+ return false;
400
+ }
401
+ }
402
+ function isSeatBlockedEventPayload(value) {
403
+ return isRecord(value) && isSeatEventPayload(value) && isNonemptyString(value.reason) && isOptionalString(value.message);
404
+ }
405
+ function isObjectStatusChangedEventPayload(value) {
406
+ return isRecord(value) && isSeatEventPayload(value) && isNonemptyString(value.status) && isNonemptyString(value.previousStatus) && typeof value.selected === "boolean";
407
+ }
408
+ function isZoomLevelChangedEventPayload(value) {
409
+ return isRecord(value) && (value.level === "overview" || value.level === "section" || value.level === "seat") && isPositiveFiniteNumber(value.scale) && isNonnegativeFiniteNumber(value.seatPixelSize);
410
+ }
411
+ function isViewportChangedEventPayload(value) {
412
+ if (!isRecord(value) || !isRecord(value.transform) || !isRecord(value.boundsWorld)) {
413
+ return false;
414
+ }
415
+ 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);
416
+ }
417
+ function isSectionFocusEventPayload(value) {
418
+ return isRecord(value) && isNonemptyString(value.sectionId) && isOptionalIdentifier(value.floorId);
419
+ }
251
420
  function isInventorySelection(value) {
252
421
  if (!isRecord(value)) {
253
422
  return false;
@@ -346,21 +515,42 @@ function toPublicSeasonHoldState(value) {
346
515
  function isEventPayload(event, payload) {
347
516
  switch (event) {
348
517
  case "chartRendered":
349
- return payload === void 0;
518
+ return toLifecycleIdentity(payload) !== void 0;
350
519
  case "chartRenderingFailed":
351
520
  return isRecord(payload) && typeof payload.message === "string";
352
- case "selectionChanged":
353
- return isRecord(payload) && isObjectRefArray(payload.selected);
354
- case "seasonHoldChanged":
355
- return isRecord(payload) && isSeasonHoldState(payload);
356
521
  case "objectClicked":
522
+ return isClickedObject(payload);
357
523
  case "objectSelected":
524
+ return isSelectionEventPayload(payload, true);
358
525
  case "objectDeselected":
526
+ return isSelectionEventPayload(payload, false);
527
+ case "selectionChanged":
528
+ return isRecord(payload) && Array.isArray(payload.selected) && payload.selected.every(isSelectedObject);
359
529
  case "objectMouseOver":
360
530
  case "objectMouseOut":
361
- return isObjectRef(payload);
531
+ return isMouseObject(payload);
532
+ case "seatBlocked":
533
+ return isSeatBlockedEventPayload(payload);
534
+ case "objectStatusChanged":
535
+ return isObjectStatusChangedEventPayload(payload);
536
+ case "zoomLevelChanged":
537
+ return isZoomLevelChangedEventPayload(payload);
538
+ case "viewportChanged":
539
+ return isViewportChangedEventPayload(payload);
540
+ case "sectionFocused":
541
+ case "sectionUnfocused":
542
+ return isSectionFocusEventPayload(payload);
543
+ case "floorChanged":
544
+ return isRecord(payload) && (payload.floor === null || isRecord(payload.floor) && isFloor(payload.floor));
545
+ case "seasonHoldChanged":
546
+ return isRecord(payload) && isSeasonHoldState(payload);
362
547
  }
363
548
  }
549
+ function copyFloorChanged(payload) {
550
+ return {
551
+ floor: payload.floor ? { ...payload.floor, categoryIds: [...payload.floor.categoryIds] } : null
552
+ };
553
+ }
364
554
  function destroyedError(method) {
365
555
  return new RpcError(
366
556
  "CHART_DESTROYED",
@@ -368,16 +558,28 @@ function destroyedError(method) {
368
558
  method
369
559
  );
370
560
  }
371
- async function requestVoid(endpoint, method, params) {
372
- await endpoint.request(method, params);
561
+ async function requestVoid(endpoint, method, params, waitForConfirmation = false) {
562
+ await endpoint.request(
563
+ method,
564
+ params,
565
+ waitForConfirmation ? { timeoutMs: null } : void 0
566
+ );
373
567
  }
374
568
  function createChartHandle(endpoint, removeIframe, options) {
375
569
  let destroyed = false;
376
- let chartRendered = false;
570
+ let chartRenderedIdentity;
377
571
  let currentSeasonHold = options?.initialSeasonHold;
572
+ let currentFloor;
573
+ const unsubscribeFloorChanged = endpoint.on("floorChanged", (payload) => {
574
+ if (isEventPayload("floorChanged", payload))
575
+ currentFloor = copyFloorChanged(payload);
576
+ });
378
577
  const subscriptions = [];
379
- const unsubscribeChartRendered = endpoint.on("chartRendered", () => {
380
- chartRendered = true;
578
+ const unsubscribeChartRendered = endpoint.on("chartRendered", (payload) => {
579
+ const identity = toLifecycleIdentity(payload);
580
+ if (identity !== void 0) {
581
+ chartRenderedIdentity = identity;
582
+ }
381
583
  });
382
584
  const unsubscribeSeasonHoldChanged = endpoint.on(
383
585
  "seasonHoldChanged",
@@ -424,21 +626,94 @@ function createChartHandle(endpoint, removeIframe, options) {
424
626
  });
425
627
  }
426
628
  }
629
+ function onChartRendered(handler) {
630
+ if (subscriptions.some(
631
+ (subscription) => subscription.event === "chartRendered" && subscription.handler === handler
632
+ )) {
633
+ return;
634
+ }
635
+ const stickyIdentity = chartRenderedIdentity;
636
+ if (stickyIdentity !== void 0) {
637
+ let active = true;
638
+ const subscription = {
639
+ event: "chartRendered",
640
+ handler,
641
+ unsubscribe() {
642
+ active = false;
643
+ }
644
+ };
645
+ subscriptions.push(subscription);
646
+ queueMicrotask(() => {
647
+ if (active) {
648
+ handler(stickyIdentity);
649
+ }
650
+ });
651
+ return;
652
+ }
653
+ const unsubscribe = endpoint.on("chartRendered", (payload) => {
654
+ const identity = toLifecycleIdentity(payload);
655
+ if (identity !== void 0) {
656
+ handler(identity);
657
+ }
658
+ });
659
+ subscriptions.push({
660
+ event: "chartRendered",
661
+ handler,
662
+ unsubscribe
663
+ });
664
+ }
427
665
  return {
428
666
  get isDestroyed() {
429
667
  return destroyed;
430
668
  },
431
669
  async selectObjects(objects) {
432
670
  assertActive("selectObjects");
433
- await requestVoid(endpoint, "selectObjects", { objects });
671
+ await requestVoid(
672
+ endpoint,
673
+ "selectObjects",
674
+ { objects },
675
+ options?.confirmSeatSelection
676
+ );
434
677
  },
435
678
  async deselectObjects(objects) {
436
679
  assertActive("deselectObjects");
437
- await requestVoid(endpoint, "deselectObjects", { objects });
680
+ await requestVoid(
681
+ endpoint,
682
+ "deselectObjects",
683
+ { objects },
684
+ options?.confirmSeatSelection
685
+ );
438
686
  },
439
687
  async clearSelection() {
440
688
  assertActive("clearSelection");
441
- await requestVoid(endpoint, "clearSelection", {});
689
+ await requestVoid(
690
+ endpoint,
691
+ "clearSelection",
692
+ {},
693
+ options?.confirmSeatSelection
694
+ );
695
+ },
696
+ async listFloors() {
697
+ assertActive("listFloors");
698
+ const result = await endpoint.request("listFloors", {});
699
+ if (!Array.isArray(result) || !result.every(
700
+ (floor) => isRecord(floor) && isFloor(floor)
701
+ )) {
702
+ throw new RpcError(
703
+ "ENGINE_INCOMPATIBLE",
704
+ "Engine returned invalid floors",
705
+ "listFloors"
706
+ );
707
+ }
708
+ return result;
709
+ },
710
+ async goToFloor(floorId) {
711
+ assertActive("goToFloor");
712
+ await requestVoid(endpoint, "goToFloor", { floorId });
713
+ },
714
+ async goToAllFloors() {
715
+ assertActive("goToAllFloors");
716
+ await requestVoid(endpoint, "goToAllFloors", {});
442
717
  },
443
718
  async listSelectedObjects() {
444
719
  assertActive("listSelectedObjects");
@@ -520,27 +795,28 @@ function createChartHandle(endpoint, removeIframe, options) {
520
795
  assertActive("findObject");
521
796
  await requestVoid(endpoint, "findObject", {});
522
797
  },
523
- async zoomToObjects() {
798
+ async zoomToObjects(objects) {
524
799
  assertActive("zoomToObjects");
525
- await requestVoid(endpoint, "zoomToObjects", {});
800
+ await requestVoid(endpoint, "zoomToObjects", { objects });
526
801
  },
527
- async zoomToSection() {
802
+ async zoomToSection(sectionId) {
528
803
  assertActive("zoomToSection");
529
- await requestVoid(endpoint, "zoomToSection", {});
804
+ await requestVoid(endpoint, "zoomToSection", { sectionId });
530
805
  },
531
806
  async resetView() {
532
807
  assertActive("resetView");
533
808
  await requestVoid(endpoint, "resetView", {});
534
809
  },
535
- async changeConfig() {
810
+ async changeConfig(config) {
536
811
  assertActive("changeConfig");
537
- await requestVoid(endpoint, "changeConfig", {});
812
+ await requestVoid(endpoint, "changeConfig", config);
538
813
  },
539
814
  async destroy() {
540
815
  assertActive("destroy");
541
816
  destroyed = true;
542
817
  subscriptions.splice(0).forEach((subscription) => subscription.unsubscribe());
543
818
  unsubscribeChartRendered();
819
+ unsubscribeFloorChanged();
544
820
  unsubscribeSeasonHoldChanged();
545
821
  endpoint.close();
546
822
  removeIframe();
@@ -553,35 +829,38 @@ function createChartHandle(endpoint, removeIframe, options) {
553
829
  );
554
830
  return;
555
831
  }
832
+ if (event === "chartRendered") {
833
+ onChartRendered(handler);
834
+ return;
835
+ }
556
836
  if (subscriptions.some(
557
837
  (subscription) => subscription.event === event && subscription.handler === handler
558
838
  )) {
559
839
  return;
560
840
  }
561
- if (event === "chartRendered" && chartRendered) {
562
- let active = true;
563
- const subscription = {
564
- event,
565
- handler,
566
- unsubscribe() {
567
- active = false;
568
- }
569
- };
570
- subscriptions.push(subscription);
571
- const chartRenderedHandler = handler;
572
- queueMicrotask(() => {
573
- if (active) {
574
- chartRenderedHandler();
575
- }
576
- });
577
- return;
578
- }
841
+ let liveEventSeen = false;
842
+ let active = true;
579
843
  const unsubscribe = endpoint.on(event, (payload) => {
580
844
  if (isEventPayload(event, payload)) {
845
+ liveEventSeen = true;
581
846
  handler(payload);
582
847
  }
583
848
  });
584
- subscriptions.push({ event, handler, unsubscribe });
849
+ subscriptions.push({
850
+ event,
851
+ handler,
852
+ unsubscribe() {
853
+ active = false;
854
+ unsubscribe();
855
+ }
856
+ });
857
+ if (event === "floorChanged" && currentFloor !== void 0) {
858
+ const initialFloor = copyFloorChanged(currentFloor);
859
+ queueMicrotask(() => {
860
+ if (active && !liveEventSeen && isEventPayload(event, initialFloor))
861
+ handler(initialFloor);
862
+ });
863
+ }
585
864
  },
586
865
  off(event, handler) {
587
866
  assertActive("off");
@@ -596,8 +875,208 @@ function createChartHandle(endpoint, removeIframe, options) {
596
875
  };
597
876
  }
598
877
 
878
+ // src/core/startSeatmapSession.ts
879
+ function isRecord2(value) {
880
+ return typeof value === "object" && value !== null && !Array.isArray(value);
881
+ }
882
+ function isHandshakeAcknowledgement(value) {
883
+ if (typeof value !== "object" || value === null) {
884
+ return false;
885
+ }
886
+ const result = value;
887
+ return result.protocolVersion === PROTOCOL_VERSION;
888
+ }
889
+ function invalidConfigError() {
890
+ return new RpcError(
891
+ "ENGINE_INCOMPATIBLE",
892
+ "Seatmap config must provide either classic or Season authority, never both"
893
+ );
894
+ }
895
+ function isCategoryFilter(value) {
896
+ if (!isRecord2(value)) {
897
+ return false;
898
+ }
899
+ const keys = Object.keys(value);
900
+ 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) {
901
+ return false;
902
+ }
903
+ return value.nonMatchingObjects === "hidden" || value.nonMatchingObjects === "disabled";
904
+ }
905
+ function hasValidOptions(config) {
906
+ 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));
907
+ }
908
+ function copyCategoryFilter(filter) {
909
+ return {
910
+ categoryIds: [...filter.categoryIds],
911
+ nonMatchingObjects: filter.nonMatchingObjects
912
+ };
913
+ }
914
+ function hasValidClassicAuthority(config) {
915
+ 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);
916
+ }
917
+ function hasValidSeasonAuthority(config) {
918
+ 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);
919
+ }
920
+ function validateMountConfig(config) {
921
+ return hasValidClassicAuthority(config) || hasValidSeasonAuthority(config) ? void 0 : invalidConfigError();
922
+ }
923
+ function classicHelloParams(config) {
924
+ const params = {
925
+ sessionId: config.sessionId,
926
+ clientToken: config.clientToken
927
+ };
928
+ if (config.channelKeys !== void 0) {
929
+ params.channelKeys = config.channelKeys;
930
+ }
931
+ if (config.includePublic !== void 0) {
932
+ params.includePublic = config.includePublic;
933
+ }
934
+ if (config.categoryFilter !== void 0) {
935
+ params.categoryFilter = copyCategoryFilter(config.categoryFilter);
936
+ }
937
+ if (config.sectionContents !== void 0)
938
+ params.sectionContents = config.sectionContents;
939
+ if (config.startFloor !== void 0) params.startFloor = config.startFloor;
940
+ if (config.lockedFloor !== void 0) params.lockedFloor = config.lockedFloor;
941
+ if (config.showFloorPicker !== void 0)
942
+ params.showFloorPicker = config.showFloorPicker;
943
+ if (config.scrollZoom !== void 0) params.scrollZoom = config.scrollZoom;
944
+ if (config.colorScheme !== void 0) params.colorScheme = config.colorScheme;
945
+ if (config.legend !== void 0) params.legend = { ...config.legend };
946
+ if (config.showActiveBlockOnMobile !== void 0)
947
+ params.showActiveBlockOnMobile = config.showActiveBlockOnMobile;
948
+ return {
949
+ ...params,
950
+ ...config.onSeatSelectionChange ? { confirmSeatSelection: true } : {}
951
+ };
952
+ }
953
+ function seasonHelloParams(config) {
954
+ const params = {
955
+ mode: "season",
956
+ seasonKey: config.season.seasonKey
957
+ };
958
+ if (config.channelKeys !== void 0) {
959
+ params.channelKeys = config.channelKeys;
960
+ }
961
+ if (config.includePublic !== void 0) {
962
+ params.includePublic = config.includePublic;
963
+ }
964
+ if (config.categoryFilter !== void 0) {
965
+ params.categoryFilter = copyCategoryFilter(config.categoryFilter);
966
+ }
967
+ if (config.sectionContents !== void 0)
968
+ params.sectionContents = config.sectionContents;
969
+ if (config.startFloor !== void 0) params.startFloor = config.startFloor;
970
+ if (config.lockedFloor !== void 0) params.lockedFloor = config.lockedFloor;
971
+ if (config.showFloorPicker !== void 0)
972
+ params.showFloorPicker = config.showFloorPicker;
973
+ if (config.scrollZoom !== void 0) params.scrollZoom = config.scrollZoom;
974
+ if (config.colorScheme !== void 0) params.colorScheme = config.colorScheme;
975
+ if (config.legend !== void 0) params.legend = { ...config.legend };
976
+ if (config.showActiveBlockOnMobile !== void 0)
977
+ params.showActiveBlockOnMobile = config.showActiveBlockOnMobile;
978
+ return params;
979
+ }
980
+ function startSeatmapSession({
981
+ transport,
982
+ channelId,
983
+ config,
984
+ onHandshake,
985
+ onTerminate
986
+ }) {
987
+ const endpoint = createEndpoint({ transport, channelId });
988
+ const isSeasonMount = config.season !== void 0;
989
+ if ("onSeatSelectionChange" in config && config.onSeatSelectionChange) {
990
+ const confirm = config.onSeatSelectionChange;
991
+ endpoint.handle("selection.confirmSeats", async (params) => {
992
+ 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") {
993
+ throw new RpcError(
994
+ "RPC_INVALID_ARGS",
995
+ "Invalid seat selection request"
996
+ );
997
+ }
998
+ await confirm({
999
+ seatIds: [...params.seatIds],
1000
+ selected: params.selected
1001
+ });
1002
+ });
1003
+ }
1004
+ if (isSeasonMount && "season" in config) {
1005
+ const { holdId, tokenProvider } = config;
1006
+ endpoint.handle("season.getToken", () => tokenProvider());
1007
+ endpoint.handle("season.getHoldId", () => holdId);
1008
+ }
1009
+ const chart = createChartHandle(
1010
+ endpoint,
1011
+ onTerminate,
1012
+ isSeasonMount && "season" in config ? {
1013
+ initialSeasonHold: {
1014
+ status: "idle",
1015
+ seasonKey: config.season.seasonKey
1016
+ }
1017
+ } : {
1018
+ confirmSeatSelection: "onSeatSelectionChange" in config && Boolean(config.onSeatSelectionChange)
1019
+ }
1020
+ );
1021
+ let detachHandshake;
1022
+ const removeHandshakeListener = () => {
1023
+ detachHandshake?.();
1024
+ detachHandshake = void 0;
1025
+ };
1026
+ const ready = new Promise((resolve, reject) => {
1027
+ detachHandshake = onHandshake((data) => {
1028
+ if (!isRecord2(data) || data.channelId !== channelId || data.type !== "hello" || typeof data.protocolVersion !== "number") {
1029
+ return;
1030
+ }
1031
+ removeHandshakeListener();
1032
+ if (data.protocolVersion !== PROTOCOL_VERSION) {
1033
+ reject(
1034
+ new RpcError(
1035
+ "ENGINE_INCOMPATIBLE",
1036
+ `Engine uses unsupported protocol version ${data.protocolVersion}`
1037
+ )
1038
+ );
1039
+ return;
1040
+ }
1041
+ if (isEnvelope(data) && data.error) {
1042
+ reject(
1043
+ new RpcError(
1044
+ data.error.code,
1045
+ data.error.message || "Engine rejected the handshake",
1046
+ data.error.method
1047
+ )
1048
+ );
1049
+ return;
1050
+ }
1051
+ if (!isEnvelope(data) || !isHandshakeAcknowledgement(data.result)) {
1052
+ reject(
1053
+ new RpcError(
1054
+ "ENGINE_INCOMPATIBLE",
1055
+ "Engine acknowledged with an incompatible protocol version"
1056
+ )
1057
+ );
1058
+ return;
1059
+ }
1060
+ resolve(chart);
1061
+ });
1062
+ });
1063
+ transport.send({
1064
+ protocolVersion: PROTOCOL_VERSION,
1065
+ channelId,
1066
+ type: "hello",
1067
+ params: config.season !== void 0 && "season" in config ? seasonHelloParams(config) : classicHelloParams(config)
1068
+ });
1069
+ return {
1070
+ ready,
1071
+ close() {
1072
+ removeHandshakeListener();
1073
+ endpoint.close();
1074
+ }
1075
+ };
1076
+ }
1077
+
599
1078
  // src/engineUrl.ts
600
- var ENGINE_ARTIFACT = "f509dddb477e0234";
1079
+ var ENGINE_ARTIFACT = "b5c64dede4a9bc1a";
601
1080
  var CDN_BASE = "https://dev-seatmap.knottech.ai";
602
1081
  function resolveEngineUrl({
603
1082
  artifact,
@@ -624,16 +1103,6 @@ function getSeatmapEngineOrigin() {
624
1103
 
625
1104
  // src/mountSeatmap.ts
626
1105
  var HANDSHAKE_TIMEOUT_MS = 5e3;
627
- function isRecord2(value) {
628
- return typeof value === "object" && value !== null && !Array.isArray(value);
629
- }
630
- function isHandshakeAcknowledgement(value) {
631
- if (typeof value !== "object" || value === null) {
632
- return false;
633
- }
634
- const result = value;
635
- return result.protocolVersion === PROTOCOL_VERSION;
636
- }
637
1106
  function unreachableError(artifact) {
638
1107
  return new RpcError(
639
1108
  "ENGINE_UNREACHABLE",
@@ -648,33 +1117,11 @@ function configureIframe(iframe, src) {
648
1117
  iframe.style.height = "100%";
649
1118
  iframe.style.border = "0";
650
1119
  }
651
- function classicHelloParams(config) {
652
- const params = {
653
- sessionId: config.sessionId,
654
- clientToken: config.clientToken
655
- };
656
- if (config.channelKeys !== void 0) {
657
- params.channelKeys = config.channelKeys;
658
- }
659
- if (config.includePublic !== void 0) {
660
- params.includePublic = config.includePublic;
661
- }
662
- return params;
663
- }
664
- function seasonHelloParams(config) {
665
- const params = {
666
- mode: "season",
667
- seasonKey: config.seasonKey
668
- };
669
- if (config.channelKeys !== void 0) {
670
- params.channelKeys = config.channelKeys;
671
- }
672
- if (config.includePublic !== void 0) {
673
- params.includePublic = config.includePublic;
674
- }
675
- return params;
676
- }
677
1120
  function mountSeatmap(container, config, signal) {
1121
+ const configError = validateMountConfig(config);
1122
+ if (configError) {
1123
+ return Promise.reject(configError);
1124
+ }
678
1125
  return new Promise((resolve, reject) => {
679
1126
  const artifact = ENGINE_ARTIFACT;
680
1127
  const engineUrl = resolveEngineUrl({ artifact, cdnBase: CDN_BASE });
@@ -682,9 +1129,8 @@ function mountSeatmap(container, config, signal) {
682
1129
  const channelId = crypto.randomUUID();
683
1130
  const iframe = document.createElement("iframe");
684
1131
  configureIframe(iframe, engineUrl);
685
- let endpoint;
1132
+ let session;
686
1133
  let transport;
687
- let detachHandshake;
688
1134
  let channelStarted = false;
689
1135
  let settled = false;
690
1136
  const timer = window.setTimeout(() => {
@@ -700,14 +1146,9 @@ function mountSeatmap(container, config, signal) {
700
1146
  iframe.removeEventListener("error", handleError);
701
1147
  signal?.removeEventListener("abort", handleAbort);
702
1148
  }
703
- function removeHandshakeListener() {
704
- detachHandshake?.();
705
- detachHandshake = void 0;
706
- }
707
1149
  function closeChannel() {
708
- removeHandshakeListener();
709
- if (endpoint) {
710
- endpoint.close();
1150
+ if (session) {
1151
+ session.close();
711
1152
  } else {
712
1153
  transport?.close();
713
1154
  }
@@ -743,73 +1184,37 @@ function mountSeatmap(container, config, signal) {
743
1184
  return;
744
1185
  }
745
1186
  transport = createWindowTransport({ target, targetOrigin, channelId });
746
- endpoint = createEndpoint({ transport, channelId });
747
- const isSeasonMount = config.seasonKey !== void 0;
748
- if (isSeasonMount && "seasonKey" in config) {
749
- const { holdId, tokenProvider } = config;
750
- endpoint.handle("season.getToken", () => tokenProvider());
751
- endpoint.handle("season.getHoldId", () => holdId);
752
- }
753
- const chart = createChartHandle(
754
- endpoint,
755
- () => {
756
- iframe.remove();
1187
+ session = startSeatmapSession({
1188
+ transport,
1189
+ channelId,
1190
+ config,
1191
+ onHandshake: (listener) => {
1192
+ const receive = (event) => {
1193
+ if (event.origin === targetOrigin && event.source === target) {
1194
+ listener(event.data);
1195
+ }
1196
+ };
1197
+ window.addEventListener("message", receive);
1198
+ return () => {
1199
+ window.removeEventListener("message", receive);
1200
+ };
757
1201
  },
758
- isSeasonMount && "seasonKey" in config ? {
759
- initialSeasonHold: {
760
- status: "idle",
761
- seasonKey: config.seasonKey
762
- }
763
- } : void 0
764
- );
765
- const receiveHandshake = (event) => {
766
- if (event.origin !== targetOrigin || event.source !== target || !isRecord2(event.data) || event.data.channelId !== channelId || event.data.type !== "hello" || typeof event.data.protocolVersion !== "number") {
767
- return;
768
- }
769
- if (event.data.protocolVersion !== PROTOCOL_VERSION) {
770
- fail(
771
- new RpcError(
772
- "ENGINE_INCOMPATIBLE",
773
- `Engine uses unsupported protocol version ${event.data.protocolVersion}`
774
- )
775
- );
776
- return;
777
- }
778
- if (isEnvelope(event.data) && event.data.error) {
779
- fail(
780
- new RpcError(
781
- event.data.error.code,
782
- event.data.error.message || "Engine rejected the handshake",
783
- event.data.error.method
784
- )
785
- );
786
- return;
787
- }
788
- if (!isEnvelope(event.data) || !isHandshakeAcknowledgement(event.data.result)) {
789
- fail(
790
- new RpcError(
791
- "ENGINE_INCOMPATIBLE",
792
- "Engine acknowledged with an incompatible protocol version"
793
- )
794
- );
795
- return;
1202
+ onTerminate: () => {
1203
+ iframe.remove();
796
1204
  }
797
- settled = true;
798
- window.clearTimeout(timer);
799
- removeMountListeners();
800
- removeHandshakeListener();
801
- resolve(chart);
802
- };
803
- window.addEventListener("message", receiveHandshake);
804
- detachHandshake = () => {
805
- window.removeEventListener("message", receiveHandshake);
806
- };
807
- transport.send({
808
- protocolVersion: PROTOCOL_VERSION,
809
- channelId,
810
- type: "hello",
811
- params: config.seasonKey !== void 0 && "seasonKey" in config ? seasonHelloParams(config) : classicHelloParams(config)
812
1205
  });
1206
+ session.ready.then(
1207
+ (chart) => {
1208
+ if (settled) {
1209
+ return;
1210
+ }
1211
+ settled = true;
1212
+ window.clearTimeout(timer);
1213
+ removeMountListeners();
1214
+ resolve(chart);
1215
+ },
1216
+ (error) => fail(error)
1217
+ );
813
1218
  }
814
1219
  iframe.addEventListener("load", handleLoad);
815
1220
  iframe.addEventListener("error", handleError);