@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/dist/index.js CHANGED
@@ -102,16 +102,17 @@ function createEndpoint({ transport, channelId, requestTimeoutMs = 1e4 }) {
102
102
  }
103
103
  }
104
104
  return {
105
- request(method, params) {
105
+ request(method, params, options) {
106
106
  if (closed) {
107
107
  return Promise.reject(new RpcError("CHART_DESTROYED", "The chart has been destroyed", method));
108
108
  }
109
109
  const id = nextId++;
110
110
  return new Promise((resolve, reject) => {
111
- const timeout = setTimeout(() => {
111
+ const timeoutMs = options?.timeoutMs === void 0 ? requestTimeoutMs : options.timeoutMs;
112
+ const timeout = timeoutMs === null ? void 0 : setTimeout(() => {
112
113
  pending.delete(id);
113
- reject(new RpcError("ENGINE_UNREACHABLE", `Engine did not reply to '${method}' within ${requestTimeoutMs}ms`, method));
114
- }, requestTimeoutMs);
114
+ reject(new RpcError("ENGINE_UNREACHABLE", `Engine did not reply to '${method}' within ${timeoutMs}ms`, method));
115
+ }, timeoutMs);
115
116
  pending.set(id, { resolve, reject, method, timeout });
116
117
  try {
117
118
  transport.send({
@@ -208,6 +209,41 @@ function createWindowTransport({ target, targetOrigin, channelId }) {
208
209
  };
209
210
  }
210
211
 
212
+ // ../seatmap-types/dist/index.js
213
+ var SECTION_CONTENTS_MODES = [
214
+ "always",
215
+ "seatsOnly",
216
+ "afterZoom"
217
+ ];
218
+ function isSectionContentsMode(value) {
219
+ return SECTION_CONTENTS_MODES.some((mode) => mode === value);
220
+ }
221
+ var LEGEND_CONTENT_MODES = ["nameAndPrice", "name", "price"];
222
+ function isLegendContentMode(value) {
223
+ return LEGEND_CONTENT_MODES.some((mode) => mode === value);
224
+ }
225
+ function isSeatmapLegendConfig(value) {
226
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
227
+ return false;
228
+ }
229
+ return Object.entries(value).every(([key, entry]) => {
230
+ switch (key) {
231
+ case "show":
232
+ case "hideAccessibleSeatsFilter":
233
+ case "hideUnavailableItem":
234
+ case "hideNonSelectableCategories":
235
+ return entry === void 0 || typeof entry === "boolean";
236
+ case "content":
237
+ return entry === void 0 || isLegendContentMode(entry);
238
+ default:
239
+ return false;
240
+ }
241
+ });
242
+ }
243
+ function isSeatmapColorScheme(value) {
244
+ return value === "light" || value === "dark";
245
+ }
246
+
211
247
  // src/chartHandle.ts
212
248
  function isRecord(value) {
213
249
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -221,6 +257,139 @@ function isObjectRef(value) {
221
257
  function isObjectRefArray(value) {
222
258
  return Array.isArray(value) && value.every(isObjectRef);
223
259
  }
260
+ function isNonemptyString(value) {
261
+ return typeof value === "string" && value.length > 0;
262
+ }
263
+ function isOptionalString(value) {
264
+ return value === void 0 || typeof value === "string";
265
+ }
266
+ function isOptionalIdentifier(value) {
267
+ return value === void 0 || isNonemptyString(value);
268
+ }
269
+ function isStringArray(value) {
270
+ return Array.isArray(value) && value.every(isNonemptyString);
271
+ }
272
+ function isFloor(value) {
273
+ return isRecord(value) && isNonemptyString(value.id) && isNonemptyString(value.name) && isNonemptyString(value.shortName) && isStringArray(value.categoryIds);
274
+ }
275
+ function isNonnegativeFiniteNumber(value) {
276
+ return typeof value === "number" && Number.isFinite(value) && value >= 0;
277
+ }
278
+ function isPositiveFiniteNumber(value) {
279
+ return typeof value === "number" && Number.isFinite(value) && value > 0;
280
+ }
281
+ function isNonnegativeSafeInteger(value) {
282
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
283
+ }
284
+ function isOptionalPrice(value) {
285
+ return value === void 0 || typeof value === "string" || typeof value === "number" && Number.isFinite(value);
286
+ }
287
+ function toLifecycleIdentity(value) {
288
+ if (!isRecord(value)) {
289
+ return void 0;
290
+ }
291
+ const keys = Object.keys(value);
292
+ if (keys.length === 1 && keys[0] === "sessionId" && isNonemptyString(value.sessionId)) {
293
+ return { sessionId: value.sessionId };
294
+ }
295
+ if (keys.length === 1 && keys[0] === "seasonKey" && isNonemptyString(value.seasonKey)) {
296
+ return { seasonKey: value.seasonKey };
297
+ }
298
+ return void 0;
299
+ }
300
+ function isSeatEventPayload(value) {
301
+ 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);
302
+ }
303
+ function isSeatClickEventPayload(value) {
304
+ return isRecord(value) && isSeatEventPayload(value) && typeof value.selected === "boolean" && typeof value.status === "string";
305
+ }
306
+ function hasSeatSelectionFields(value, selected) {
307
+ return isRecord(value) && isSeatEventPayload(value) && value.selected === selected && isOptionalString(value.sectionLabel);
308
+ }
309
+ function hasGaAreaFields(value, selected) {
310
+ 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);
311
+ }
312
+ function isGaAreaEventPayload(value) {
313
+ return hasGaAreaFields(value);
314
+ }
315
+ function hasTableFields(value, selected) {
316
+ 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);
317
+ }
318
+ function isTableEventPayload(value) {
319
+ return hasTableFields(value);
320
+ }
321
+ function isSelectionEventPayload(value, selected) {
322
+ if (!isRecord(value)) {
323
+ return false;
324
+ }
325
+ switch (value.type) {
326
+ case "seat":
327
+ return hasSeatSelectionFields(value, selected);
328
+ case "gaArea":
329
+ return hasGaAreaFields(value, selected);
330
+ case "table":
331
+ return hasTableFields(value, selected);
332
+ default:
333
+ return false;
334
+ }
335
+ }
336
+ function isSelectedObject(value) {
337
+ if (!isRecord(value)) {
338
+ return false;
339
+ }
340
+ if (value.type === "table") {
341
+ return hasTableFields(value, true) && isNonnegativeSafeInteger(value.available) && isNonnegativeSafeInteger(value.capacity) && isNonnegativeSafeInteger(value.booked) && isNonnegativeSafeInteger(value.held);
342
+ }
343
+ return isSelectionEventPayload(value, true);
344
+ }
345
+ function isClickedObject(value) {
346
+ if (!isRecord(value)) {
347
+ return false;
348
+ }
349
+ switch (value.type) {
350
+ case "seat":
351
+ return isSeatClickEventPayload(value);
352
+ case "gaArea":
353
+ return isGaAreaEventPayload(value);
354
+ case "table":
355
+ return isTableEventPayload(value);
356
+ default:
357
+ return false;
358
+ }
359
+ }
360
+ function isMouseObject(value) {
361
+ if (!isRecord(value)) {
362
+ return false;
363
+ }
364
+ switch (value.type) {
365
+ case "seat":
366
+ return isSeatEventPayload(value);
367
+ case "gaArea":
368
+ return isGaAreaEventPayload(value);
369
+ case "table":
370
+ return isTableEventPayload(value);
371
+ default:
372
+ return false;
373
+ }
374
+ }
375
+ function isSeatBlockedEventPayload(value) {
376
+ return isRecord(value) && isSeatEventPayload(value) && isNonemptyString(value.reason) && isOptionalString(value.message);
377
+ }
378
+ function isObjectStatusChangedEventPayload(value) {
379
+ return isRecord(value) && isSeatEventPayload(value) && isNonemptyString(value.status) && isNonemptyString(value.previousStatus) && typeof value.selected === "boolean";
380
+ }
381
+ function isZoomLevelChangedEventPayload(value) {
382
+ return isRecord(value) && (value.level === "overview" || value.level === "section" || value.level === "seat") && isPositiveFiniteNumber(value.scale) && isNonnegativeFiniteNumber(value.seatPixelSize);
383
+ }
384
+ function isViewportChangedEventPayload(value) {
385
+ if (!isRecord(value) || !isRecord(value.transform) || !isRecord(value.boundsWorld)) {
386
+ return false;
387
+ }
388
+ 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);
389
+ }
390
+ function isSectionFocusEventPayload(value) {
391
+ return isRecord(value) && isNonemptyString(value.sectionId) && isOptionalIdentifier(value.floorId);
392
+ }
224
393
  function isInventorySelection(value) {
225
394
  if (!isRecord(value)) {
226
395
  return false;
@@ -319,21 +488,42 @@ function toPublicSeasonHoldState(value) {
319
488
  function isEventPayload(event, payload) {
320
489
  switch (event) {
321
490
  case "chartRendered":
322
- return payload === void 0;
491
+ return toLifecycleIdentity(payload) !== void 0;
323
492
  case "chartRenderingFailed":
324
493
  return isRecord(payload) && typeof payload.message === "string";
325
- case "selectionChanged":
326
- return isRecord(payload) && isObjectRefArray(payload.selected);
327
- case "seasonHoldChanged":
328
- return isRecord(payload) && isSeasonHoldState(payload);
329
494
  case "objectClicked":
495
+ return isClickedObject(payload);
330
496
  case "objectSelected":
497
+ return isSelectionEventPayload(payload, true);
331
498
  case "objectDeselected":
499
+ return isSelectionEventPayload(payload, false);
500
+ case "selectionChanged":
501
+ return isRecord(payload) && Array.isArray(payload.selected) && payload.selected.every(isSelectedObject);
332
502
  case "objectMouseOver":
333
503
  case "objectMouseOut":
334
- return isObjectRef(payload);
504
+ return isMouseObject(payload);
505
+ case "seatBlocked":
506
+ return isSeatBlockedEventPayload(payload);
507
+ case "objectStatusChanged":
508
+ return isObjectStatusChangedEventPayload(payload);
509
+ case "zoomLevelChanged":
510
+ return isZoomLevelChangedEventPayload(payload);
511
+ case "viewportChanged":
512
+ return isViewportChangedEventPayload(payload);
513
+ case "sectionFocused":
514
+ case "sectionUnfocused":
515
+ return isSectionFocusEventPayload(payload);
516
+ case "floorChanged":
517
+ return isRecord(payload) && (payload.floor === null || isRecord(payload.floor) && isFloor(payload.floor));
518
+ case "seasonHoldChanged":
519
+ return isRecord(payload) && isSeasonHoldState(payload);
335
520
  }
336
521
  }
522
+ function copyFloorChanged(payload) {
523
+ return {
524
+ floor: payload.floor ? { ...payload.floor, categoryIds: [...payload.floor.categoryIds] } : null
525
+ };
526
+ }
337
527
  function destroyedError(method) {
338
528
  return new RpcError(
339
529
  "CHART_DESTROYED",
@@ -341,16 +531,28 @@ function destroyedError(method) {
341
531
  method
342
532
  );
343
533
  }
344
- async function requestVoid(endpoint, method, params) {
345
- await endpoint.request(method, params);
534
+ async function requestVoid(endpoint, method, params, waitForConfirmation = false) {
535
+ await endpoint.request(
536
+ method,
537
+ params,
538
+ waitForConfirmation ? { timeoutMs: null } : void 0
539
+ );
346
540
  }
347
541
  function createChartHandle(endpoint, removeIframe, options) {
348
542
  let destroyed = false;
349
- let chartRendered = false;
543
+ let chartRenderedIdentity;
350
544
  let currentSeasonHold = options?.initialSeasonHold;
545
+ let currentFloor;
546
+ const unsubscribeFloorChanged = endpoint.on("floorChanged", (payload) => {
547
+ if (isEventPayload("floorChanged", payload))
548
+ currentFloor = copyFloorChanged(payload);
549
+ });
351
550
  const subscriptions = [];
352
- const unsubscribeChartRendered = endpoint.on("chartRendered", () => {
353
- chartRendered = true;
551
+ const unsubscribeChartRendered = endpoint.on("chartRendered", (payload) => {
552
+ const identity = toLifecycleIdentity(payload);
553
+ if (identity !== void 0) {
554
+ chartRenderedIdentity = identity;
555
+ }
354
556
  });
355
557
  const unsubscribeSeasonHoldChanged = endpoint.on(
356
558
  "seasonHoldChanged",
@@ -397,21 +599,94 @@ function createChartHandle(endpoint, removeIframe, options) {
397
599
  });
398
600
  }
399
601
  }
602
+ function onChartRendered(handler) {
603
+ if (subscriptions.some(
604
+ (subscription) => subscription.event === "chartRendered" && subscription.handler === handler
605
+ )) {
606
+ return;
607
+ }
608
+ const stickyIdentity = chartRenderedIdentity;
609
+ if (stickyIdentity !== void 0) {
610
+ let active = true;
611
+ const subscription = {
612
+ event: "chartRendered",
613
+ handler,
614
+ unsubscribe() {
615
+ active = false;
616
+ }
617
+ };
618
+ subscriptions.push(subscription);
619
+ queueMicrotask(() => {
620
+ if (active) {
621
+ handler(stickyIdentity);
622
+ }
623
+ });
624
+ return;
625
+ }
626
+ const unsubscribe = endpoint.on("chartRendered", (payload) => {
627
+ const identity = toLifecycleIdentity(payload);
628
+ if (identity !== void 0) {
629
+ handler(identity);
630
+ }
631
+ });
632
+ subscriptions.push({
633
+ event: "chartRendered",
634
+ handler,
635
+ unsubscribe
636
+ });
637
+ }
400
638
  return {
401
639
  get isDestroyed() {
402
640
  return destroyed;
403
641
  },
404
642
  async selectObjects(objects) {
405
643
  assertActive("selectObjects");
406
- await requestVoid(endpoint, "selectObjects", { objects });
644
+ await requestVoid(
645
+ endpoint,
646
+ "selectObjects",
647
+ { objects },
648
+ options?.confirmSeatSelection
649
+ );
407
650
  },
408
651
  async deselectObjects(objects) {
409
652
  assertActive("deselectObjects");
410
- await requestVoid(endpoint, "deselectObjects", { objects });
653
+ await requestVoid(
654
+ endpoint,
655
+ "deselectObjects",
656
+ { objects },
657
+ options?.confirmSeatSelection
658
+ );
411
659
  },
412
660
  async clearSelection() {
413
661
  assertActive("clearSelection");
414
- await requestVoid(endpoint, "clearSelection", {});
662
+ await requestVoid(
663
+ endpoint,
664
+ "clearSelection",
665
+ {},
666
+ options?.confirmSeatSelection
667
+ );
668
+ },
669
+ async listFloors() {
670
+ assertActive("listFloors");
671
+ const result = await endpoint.request("listFloors", {});
672
+ if (!Array.isArray(result) || !result.every(
673
+ (floor) => isRecord(floor) && isFloor(floor)
674
+ )) {
675
+ throw new RpcError(
676
+ "ENGINE_INCOMPATIBLE",
677
+ "Engine returned invalid floors",
678
+ "listFloors"
679
+ );
680
+ }
681
+ return result;
682
+ },
683
+ async goToFloor(floorId) {
684
+ assertActive("goToFloor");
685
+ await requestVoid(endpoint, "goToFloor", { floorId });
686
+ },
687
+ async goToAllFloors() {
688
+ assertActive("goToAllFloors");
689
+ await requestVoid(endpoint, "goToAllFloors", {});
415
690
  },
416
691
  async listSelectedObjects() {
417
692
  assertActive("listSelectedObjects");
@@ -493,27 +768,28 @@ function createChartHandle(endpoint, removeIframe, options) {
493
768
  assertActive("findObject");
494
769
  await requestVoid(endpoint, "findObject", {});
495
770
  },
496
- async zoomToObjects() {
771
+ async zoomToObjects(objects) {
497
772
  assertActive("zoomToObjects");
498
- await requestVoid(endpoint, "zoomToObjects", {});
773
+ await requestVoid(endpoint, "zoomToObjects", { objects });
499
774
  },
500
- async zoomToSection() {
775
+ async zoomToSection(sectionId) {
501
776
  assertActive("zoomToSection");
502
- await requestVoid(endpoint, "zoomToSection", {});
777
+ await requestVoid(endpoint, "zoomToSection", { sectionId });
503
778
  },
504
779
  async resetView() {
505
780
  assertActive("resetView");
506
781
  await requestVoid(endpoint, "resetView", {});
507
782
  },
508
- async changeConfig() {
783
+ async changeConfig(config) {
509
784
  assertActive("changeConfig");
510
- await requestVoid(endpoint, "changeConfig", {});
785
+ await requestVoid(endpoint, "changeConfig", config);
511
786
  },
512
787
  async destroy() {
513
788
  assertActive("destroy");
514
789
  destroyed = true;
515
790
  subscriptions.splice(0).forEach((subscription) => subscription.unsubscribe());
516
791
  unsubscribeChartRendered();
792
+ unsubscribeFloorChanged();
517
793
  unsubscribeSeasonHoldChanged();
518
794
  endpoint.close();
519
795
  removeIframe();
@@ -526,35 +802,38 @@ function createChartHandle(endpoint, removeIframe, options) {
526
802
  );
527
803
  return;
528
804
  }
805
+ if (event === "chartRendered") {
806
+ onChartRendered(handler);
807
+ return;
808
+ }
529
809
  if (subscriptions.some(
530
810
  (subscription) => subscription.event === event && subscription.handler === handler
531
811
  )) {
532
812
  return;
533
813
  }
534
- if (event === "chartRendered" && chartRendered) {
535
- let active = true;
536
- const subscription = {
537
- event,
538
- handler,
539
- unsubscribe() {
540
- active = false;
541
- }
542
- };
543
- subscriptions.push(subscription);
544
- const chartRenderedHandler = handler;
545
- queueMicrotask(() => {
546
- if (active) {
547
- chartRenderedHandler();
548
- }
549
- });
550
- return;
551
- }
814
+ let liveEventSeen = false;
815
+ let active = true;
552
816
  const unsubscribe = endpoint.on(event, (payload) => {
553
817
  if (isEventPayload(event, payload)) {
818
+ liveEventSeen = true;
554
819
  handler(payload);
555
820
  }
556
821
  });
557
- subscriptions.push({ event, handler, unsubscribe });
822
+ subscriptions.push({
823
+ event,
824
+ handler,
825
+ unsubscribe() {
826
+ active = false;
827
+ unsubscribe();
828
+ }
829
+ });
830
+ if (event === "floorChanged" && currentFloor !== void 0) {
831
+ const initialFloor = copyFloorChanged(currentFloor);
832
+ queueMicrotask(() => {
833
+ if (active && !liveEventSeen && isEventPayload(event, initialFloor))
834
+ handler(initialFloor);
835
+ });
836
+ }
558
837
  },
559
838
  off(event, handler) {
560
839
  assertActive("off");
@@ -569,8 +848,208 @@ function createChartHandle(endpoint, removeIframe, options) {
569
848
  };
570
849
  }
571
850
 
851
+ // src/core/startSeatmapSession.ts
852
+ function isRecord2(value) {
853
+ return typeof value === "object" && value !== null && !Array.isArray(value);
854
+ }
855
+ function isHandshakeAcknowledgement(value) {
856
+ if (typeof value !== "object" || value === null) {
857
+ return false;
858
+ }
859
+ const result = value;
860
+ return result.protocolVersion === PROTOCOL_VERSION;
861
+ }
862
+ function invalidConfigError() {
863
+ return new RpcError(
864
+ "ENGINE_INCOMPATIBLE",
865
+ "Seatmap config must provide either classic or Season authority, never both"
866
+ );
867
+ }
868
+ function isCategoryFilter(value) {
869
+ if (!isRecord2(value)) {
870
+ return false;
871
+ }
872
+ const keys = Object.keys(value);
873
+ 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) {
874
+ return false;
875
+ }
876
+ return value.nonMatchingObjects === "hidden" || value.nonMatchingObjects === "disabled";
877
+ }
878
+ function hasValidOptions(config) {
879
+ 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));
880
+ }
881
+ function copyCategoryFilter(filter) {
882
+ return {
883
+ categoryIds: [...filter.categoryIds],
884
+ nonMatchingObjects: filter.nonMatchingObjects
885
+ };
886
+ }
887
+ function hasValidClassicAuthority(config) {
888
+ 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);
889
+ }
890
+ function hasValidSeasonAuthority(config) {
891
+ 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);
892
+ }
893
+ function validateMountConfig(config) {
894
+ return hasValidClassicAuthority(config) || hasValidSeasonAuthority(config) ? void 0 : invalidConfigError();
895
+ }
896
+ function classicHelloParams(config) {
897
+ const params = {
898
+ sessionId: config.sessionId,
899
+ clientToken: config.clientToken
900
+ };
901
+ if (config.channelKeys !== void 0) {
902
+ params.channelKeys = config.channelKeys;
903
+ }
904
+ if (config.includePublic !== void 0) {
905
+ params.includePublic = config.includePublic;
906
+ }
907
+ if (config.categoryFilter !== void 0) {
908
+ params.categoryFilter = copyCategoryFilter(config.categoryFilter);
909
+ }
910
+ if (config.sectionContents !== void 0)
911
+ params.sectionContents = config.sectionContents;
912
+ if (config.startFloor !== void 0) params.startFloor = config.startFloor;
913
+ if (config.lockedFloor !== void 0) params.lockedFloor = config.lockedFloor;
914
+ if (config.showFloorPicker !== void 0)
915
+ params.showFloorPicker = config.showFloorPicker;
916
+ if (config.scrollZoom !== void 0) params.scrollZoom = config.scrollZoom;
917
+ if (config.colorScheme !== void 0) params.colorScheme = config.colorScheme;
918
+ if (config.legend !== void 0) params.legend = { ...config.legend };
919
+ if (config.showActiveBlockOnMobile !== void 0)
920
+ params.showActiveBlockOnMobile = config.showActiveBlockOnMobile;
921
+ return {
922
+ ...params,
923
+ ...config.onSeatSelectionChange ? { confirmSeatSelection: true } : {}
924
+ };
925
+ }
926
+ function seasonHelloParams(config) {
927
+ const params = {
928
+ mode: "season",
929
+ seasonKey: config.season.seasonKey
930
+ };
931
+ if (config.channelKeys !== void 0) {
932
+ params.channelKeys = config.channelKeys;
933
+ }
934
+ if (config.includePublic !== void 0) {
935
+ params.includePublic = config.includePublic;
936
+ }
937
+ if (config.categoryFilter !== void 0) {
938
+ params.categoryFilter = copyCategoryFilter(config.categoryFilter);
939
+ }
940
+ if (config.sectionContents !== void 0)
941
+ params.sectionContents = config.sectionContents;
942
+ if (config.startFloor !== void 0) params.startFloor = config.startFloor;
943
+ if (config.lockedFloor !== void 0) params.lockedFloor = config.lockedFloor;
944
+ if (config.showFloorPicker !== void 0)
945
+ params.showFloorPicker = config.showFloorPicker;
946
+ if (config.scrollZoom !== void 0) params.scrollZoom = config.scrollZoom;
947
+ if (config.colorScheme !== void 0) params.colorScheme = config.colorScheme;
948
+ if (config.legend !== void 0) params.legend = { ...config.legend };
949
+ if (config.showActiveBlockOnMobile !== void 0)
950
+ params.showActiveBlockOnMobile = config.showActiveBlockOnMobile;
951
+ return params;
952
+ }
953
+ function startSeatmapSession({
954
+ transport,
955
+ channelId,
956
+ config,
957
+ onHandshake,
958
+ onTerminate
959
+ }) {
960
+ const endpoint = createEndpoint({ transport, channelId });
961
+ const isSeasonMount = config.season !== void 0;
962
+ if ("onSeatSelectionChange" in config && config.onSeatSelectionChange) {
963
+ const confirm = config.onSeatSelectionChange;
964
+ endpoint.handle("selection.confirmSeats", async (params) => {
965
+ 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") {
966
+ throw new RpcError(
967
+ "RPC_INVALID_ARGS",
968
+ "Invalid seat selection request"
969
+ );
970
+ }
971
+ await confirm({
972
+ seatIds: [...params.seatIds],
973
+ selected: params.selected
974
+ });
975
+ });
976
+ }
977
+ if (isSeasonMount && "season" in config) {
978
+ const { holdId, tokenProvider } = config;
979
+ endpoint.handle("season.getToken", () => tokenProvider());
980
+ endpoint.handle("season.getHoldId", () => holdId);
981
+ }
982
+ const chart = createChartHandle(
983
+ endpoint,
984
+ onTerminate,
985
+ isSeasonMount && "season" in config ? {
986
+ initialSeasonHold: {
987
+ status: "idle",
988
+ seasonKey: config.season.seasonKey
989
+ }
990
+ } : {
991
+ confirmSeatSelection: "onSeatSelectionChange" in config && Boolean(config.onSeatSelectionChange)
992
+ }
993
+ );
994
+ let detachHandshake;
995
+ const removeHandshakeListener = () => {
996
+ detachHandshake?.();
997
+ detachHandshake = void 0;
998
+ };
999
+ const ready = new Promise((resolve, reject) => {
1000
+ detachHandshake = onHandshake((data) => {
1001
+ if (!isRecord2(data) || data.channelId !== channelId || data.type !== "hello" || typeof data.protocolVersion !== "number") {
1002
+ return;
1003
+ }
1004
+ removeHandshakeListener();
1005
+ if (data.protocolVersion !== PROTOCOL_VERSION) {
1006
+ reject(
1007
+ new RpcError(
1008
+ "ENGINE_INCOMPATIBLE",
1009
+ `Engine uses unsupported protocol version ${data.protocolVersion}`
1010
+ )
1011
+ );
1012
+ return;
1013
+ }
1014
+ if (isEnvelope(data) && data.error) {
1015
+ reject(
1016
+ new RpcError(
1017
+ data.error.code,
1018
+ data.error.message || "Engine rejected the handshake",
1019
+ data.error.method
1020
+ )
1021
+ );
1022
+ return;
1023
+ }
1024
+ if (!isEnvelope(data) || !isHandshakeAcknowledgement(data.result)) {
1025
+ reject(
1026
+ new RpcError(
1027
+ "ENGINE_INCOMPATIBLE",
1028
+ "Engine acknowledged with an incompatible protocol version"
1029
+ )
1030
+ );
1031
+ return;
1032
+ }
1033
+ resolve(chart);
1034
+ });
1035
+ });
1036
+ transport.send({
1037
+ protocolVersion: PROTOCOL_VERSION,
1038
+ channelId,
1039
+ type: "hello",
1040
+ params: config.season !== void 0 && "season" in config ? seasonHelloParams(config) : classicHelloParams(config)
1041
+ });
1042
+ return {
1043
+ ready,
1044
+ close() {
1045
+ removeHandshakeListener();
1046
+ endpoint.close();
1047
+ }
1048
+ };
1049
+ }
1050
+
572
1051
  // src/engineUrl.ts
573
- var ENGINE_ARTIFACT = "f509dddb477e0234";
1052
+ var ENGINE_ARTIFACT = "3055fcaa6d7f2600";
574
1053
  var CDN_BASE = "https://dev-seatmap.knottech.ai";
575
1054
  function resolveEngineUrl({
576
1055
  artifact,
@@ -597,16 +1076,6 @@ function getSeatmapEngineOrigin() {
597
1076
 
598
1077
  // src/mountSeatmap.ts
599
1078
  var HANDSHAKE_TIMEOUT_MS = 5e3;
600
- function isRecord2(value) {
601
- return typeof value === "object" && value !== null && !Array.isArray(value);
602
- }
603
- function isHandshakeAcknowledgement(value) {
604
- if (typeof value !== "object" || value === null) {
605
- return false;
606
- }
607
- const result = value;
608
- return result.protocolVersion === PROTOCOL_VERSION;
609
- }
610
1079
  function unreachableError(artifact) {
611
1080
  return new RpcError(
612
1081
  "ENGINE_UNREACHABLE",
@@ -621,33 +1090,11 @@ function configureIframe(iframe, src) {
621
1090
  iframe.style.height = "100%";
622
1091
  iframe.style.border = "0";
623
1092
  }
624
- function classicHelloParams(config) {
625
- const params = {
626
- sessionId: config.sessionId,
627
- clientToken: config.clientToken
628
- };
629
- if (config.channelKeys !== void 0) {
630
- params.channelKeys = config.channelKeys;
631
- }
632
- if (config.includePublic !== void 0) {
633
- params.includePublic = config.includePublic;
634
- }
635
- return params;
636
- }
637
- function seasonHelloParams(config) {
638
- const params = {
639
- mode: "season",
640
- seasonKey: config.seasonKey
641
- };
642
- if (config.channelKeys !== void 0) {
643
- params.channelKeys = config.channelKeys;
644
- }
645
- if (config.includePublic !== void 0) {
646
- params.includePublic = config.includePublic;
647
- }
648
- return params;
649
- }
650
1093
  function mountSeatmap(container, config, signal) {
1094
+ const configError = validateMountConfig(config);
1095
+ if (configError) {
1096
+ return Promise.reject(configError);
1097
+ }
651
1098
  return new Promise((resolve, reject) => {
652
1099
  const artifact = ENGINE_ARTIFACT;
653
1100
  const engineUrl = resolveEngineUrl({ artifact, cdnBase: CDN_BASE });
@@ -655,9 +1102,8 @@ function mountSeatmap(container, config, signal) {
655
1102
  const channelId = crypto.randomUUID();
656
1103
  const iframe = document.createElement("iframe");
657
1104
  configureIframe(iframe, engineUrl);
658
- let endpoint;
1105
+ let session;
659
1106
  let transport;
660
- let detachHandshake;
661
1107
  let channelStarted = false;
662
1108
  let settled = false;
663
1109
  const timer = window.setTimeout(() => {
@@ -673,14 +1119,9 @@ function mountSeatmap(container, config, signal) {
673
1119
  iframe.removeEventListener("error", handleError);
674
1120
  signal?.removeEventListener("abort", handleAbort);
675
1121
  }
676
- function removeHandshakeListener() {
677
- detachHandshake?.();
678
- detachHandshake = void 0;
679
- }
680
1122
  function closeChannel() {
681
- removeHandshakeListener();
682
- if (endpoint) {
683
- endpoint.close();
1123
+ if (session) {
1124
+ session.close();
684
1125
  } else {
685
1126
  transport?.close();
686
1127
  }
@@ -716,73 +1157,37 @@ function mountSeatmap(container, config, signal) {
716
1157
  return;
717
1158
  }
718
1159
  transport = createWindowTransport({ target, targetOrigin, channelId });
719
- endpoint = createEndpoint({ transport, channelId });
720
- const isSeasonMount = config.seasonKey !== void 0;
721
- if (isSeasonMount && "seasonKey" in config) {
722
- const { holdId, tokenProvider } = config;
723
- endpoint.handle("season.getToken", () => tokenProvider());
724
- endpoint.handle("season.getHoldId", () => holdId);
725
- }
726
- const chart = createChartHandle(
727
- endpoint,
728
- () => {
729
- iframe.remove();
1160
+ session = startSeatmapSession({
1161
+ transport,
1162
+ channelId,
1163
+ config,
1164
+ onHandshake: (listener) => {
1165
+ const receive = (event) => {
1166
+ if (event.origin === targetOrigin && event.source === target) {
1167
+ listener(event.data);
1168
+ }
1169
+ };
1170
+ window.addEventListener("message", receive);
1171
+ return () => {
1172
+ window.removeEventListener("message", receive);
1173
+ };
730
1174
  },
731
- isSeasonMount && "seasonKey" in config ? {
732
- initialSeasonHold: {
733
- status: "idle",
734
- seasonKey: config.seasonKey
735
- }
736
- } : void 0
737
- );
738
- const receiveHandshake = (event) => {
739
- if (event.origin !== targetOrigin || event.source !== target || !isRecord2(event.data) || event.data.channelId !== channelId || event.data.type !== "hello" || typeof event.data.protocolVersion !== "number") {
740
- return;
741
- }
742
- if (event.data.protocolVersion !== PROTOCOL_VERSION) {
743
- fail(
744
- new RpcError(
745
- "ENGINE_INCOMPATIBLE",
746
- `Engine uses unsupported protocol version ${event.data.protocolVersion}`
747
- )
748
- );
749
- return;
750
- }
751
- if (isEnvelope(event.data) && event.data.error) {
752
- fail(
753
- new RpcError(
754
- event.data.error.code,
755
- event.data.error.message || "Engine rejected the handshake",
756
- event.data.error.method
757
- )
758
- );
759
- return;
760
- }
761
- if (!isEnvelope(event.data) || !isHandshakeAcknowledgement(event.data.result)) {
762
- fail(
763
- new RpcError(
764
- "ENGINE_INCOMPATIBLE",
765
- "Engine acknowledged with an incompatible protocol version"
766
- )
767
- );
768
- return;
1175
+ onTerminate: () => {
1176
+ iframe.remove();
769
1177
  }
770
- settled = true;
771
- window.clearTimeout(timer);
772
- removeMountListeners();
773
- removeHandshakeListener();
774
- resolve(chart);
775
- };
776
- window.addEventListener("message", receiveHandshake);
777
- detachHandshake = () => {
778
- window.removeEventListener("message", receiveHandshake);
779
- };
780
- transport.send({
781
- protocolVersion: PROTOCOL_VERSION,
782
- channelId,
783
- type: "hello",
784
- params: config.seasonKey !== void 0 && "seasonKey" in config ? seasonHelloParams(config) : classicHelloParams(config)
785
1178
  });
1179
+ session.ready.then(
1180
+ (chart) => {
1181
+ if (settled) {
1182
+ return;
1183
+ }
1184
+ settled = true;
1185
+ window.clearTimeout(timer);
1186
+ removeMountListeners();
1187
+ resolve(chart);
1188
+ },
1189
+ (error) => fail(error)
1190
+ );
786
1191
  }
787
1192
  iframe.addEventListener("load", handleLoad);
788
1193
  iframe.addEventListener("error", handleError);