@wix/astro 1.0.32 → 1.0.33

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.
@@ -4,9 +4,16 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __esm = (fn, res) => function __init() {
8
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
9
+ };
7
10
  var __commonJS = (cb, mod) => function __require() {
8
11
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
12
  };
13
+ var __export = (target, all) => {
14
+ for (var name in all)
15
+ __defProp(target, name, { get: all[name], enumerable: true });
16
+ };
10
17
  var __copyProps = (to, from, except, desc) => {
11
18
  if (from && typeof from === "object" || typeof from === "function") {
12
19
  for (let key of __getOwnPropNames(from))
@@ -23,6 +30,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
23
30
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
31
  mod
25
32
  ));
33
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
26
34
 
27
35
  // ../../node_modules/@wix/monitoring/build/index.cjs
28
36
  var require_build = __commonJS({
@@ -32,7 +40,7 @@ var require_build = __commonJS({
32
40
  var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
33
41
  var __getOwnPropNames2 = Object.getOwnPropertyNames;
34
42
  var __hasOwnProp2 = Object.prototype.hasOwnProperty;
35
- var __export = (target, all) => {
43
+ var __export2 = (target, all) => {
36
44
  for (var name in all)
37
45
  __defProp2(target, name, { get: all[name], enumerable: true });
38
46
  };
@@ -44,13 +52,13 @@ var require_build = __commonJS({
44
52
  }
45
53
  return to;
46
54
  };
47
- var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
55
+ var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
48
56
  var index_exports = {};
49
- __export(index_exports, {
57
+ __export2(index_exports, {
50
58
  createFallbackMonitoringClient: () => createFallbackMonitoringClient,
51
59
  generateTagsAndContext: () => generateTagsAndContext
52
60
  });
53
- module.exports = __toCommonJS(index_exports);
61
+ module.exports = __toCommonJS2(index_exports);
54
62
  var validValue = (value) => value !== void 0 && value !== null && value !== "";
55
63
  var pickByValidValues = (obj) => pickBy(obj, validValue);
56
64
  function pickBy(object, predicate = (value) => !!value) {
@@ -131,6 +139,44 @@ var require_build = __commonJS({
131
139
  }
132
140
  });
133
141
 
142
+ // ../../node_modules/@wix/monitoring-common/build/index.js
143
+ var build_exports = {};
144
+ __export(build_exports, {
145
+ getCallLocation: () => getCallLocation,
146
+ getCallStack: () => getCallStack
147
+ });
148
+ var getCallStack, getCallLocation;
149
+ var init_build = __esm({
150
+ "../../node_modules/@wix/monitoring-common/build/index.js"() {
151
+ "use strict";
152
+ getCallStack = () => {
153
+ try {
154
+ throw new Error();
155
+ } catch (e) {
156
+ return e?.stack;
157
+ }
158
+ };
159
+ getCallLocation = (stack) => {
160
+ stack = stack ?? getCallStack();
161
+ const frames = stack?.trim().split("\n");
162
+ if (!frames) {
163
+ return null;
164
+ }
165
+ for (let i = frames.length - 1; i >= 0; i--) {
166
+ const match = frames[i].match(/https?:\/\/.+?(\/.+):(\d+):(\d+)/) ?? frames[i].match(/.*(\/[^/]+):(\d+):(\d+)/);
167
+ if (match) {
168
+ return {
169
+ file: match[1],
170
+ line: parseInt(match[2], 10) ?? 0,
171
+ column: parseInt(match[3], 10) ?? 0
172
+ };
173
+ }
174
+ }
175
+ return null;
176
+ };
177
+ }
178
+ });
179
+
134
180
  // ../../node_modules/lodash/isObject.js
135
181
  var require_isObject = __commonJS({
136
182
  "../../node_modules/lodash/isObject.js"(exports, module) {
@@ -466,7 +512,7 @@ var require_build2 = __commonJS({
466
512
  var __getOwnPropNames2 = Object.getOwnPropertyNames;
467
513
  var __getProtoOf2 = Object.getPrototypeOf;
468
514
  var __hasOwnProp2 = Object.prototype.hasOwnProperty;
469
- var __export = (target, all) => {
515
+ var __export2 = (target, all) => {
470
516
  for (var name in all)
471
517
  __defProp2(target, name, { get: all[name], enumerable: true });
472
518
  };
@@ -486,69 +532,97 @@ var require_build2 = __commonJS({
486
532
  isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
487
533
  mod
488
534
  ));
489
- var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
535
+ var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
490
536
  var index_exports = {};
491
- __export(index_exports, {
537
+ __export2(index_exports, {
492
538
  createVeloMonitoringClient: () => createVeloMonitoringClient2
493
539
  });
494
- module.exports = __toCommonJS(index_exports);
540
+ module.exports = __toCommonJS2(index_exports);
495
541
  var import_monitoring = require_build();
542
+ var import_monitoring_common = (init_build(), __toCommonJS(build_exports));
496
543
  var generateId = () => {
497
544
  return typeof crypto !== "undefined" && typeof crypto.randomUUID === "function" ? crypto.randomUUID() : "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(e) {
498
545
  const i = 16 * Math.random() | 0;
499
546
  return ("x" === e ? i : 3 & i | 8).toString(16);
500
547
  });
501
548
  };
502
- var buildMessagePayload = (params) => {
503
- const { message, level = "INFO", timestamp = Date.now(), tags, req } = params;
549
+ var stringifySafe = (value) => {
550
+ try {
551
+ return JSON.stringify(value);
552
+ } catch (error) {
553
+ return `Failed to stringify log value: ${error?.toString()}`;
554
+ }
555
+ };
556
+ var buildTelemetryPayload = (options, params) => {
557
+ const { namespace, producer, req, requestId } = options;
558
+ const {
559
+ message,
560
+ level = "INFO",
561
+ timestamp = Date.now(),
562
+ tags,
563
+ contexts
564
+ } = params;
565
+ const { __sourceLocation, ...restOfContext } = contexts ?? {};
504
566
  let siteUrl = "";
505
567
  if (req) {
506
568
  try {
507
- siteUrl = new URL(req.headers.get("referer") ?? "").origin;
569
+ if (req.headers.get("referer")) {
570
+ siteUrl = new URL(req.headers.get("referer") ?? "").origin;
571
+ } else {
572
+ siteUrl = new URL(req.url).origin;
573
+ }
508
574
  } catch (e) {
509
575
  }
510
- } else if (typeof document !== "undefined") {
511
- siteUrl = document.location.origin;
512
576
  }
513
- const sourceLocation = tags?.fileName && {
514
- file: tags.fileName,
515
- line: tags.lineNumber ?? 0,
516
- column: tags.columnNumber ?? 0
517
- };
577
+ const messageParts = [message];
578
+ if (tags) {
579
+ messageParts.push(stringifySafe(tags));
580
+ }
581
+ if (Object.keys(restOfContext).length > 0) {
582
+ messageParts.push(stringifySafe(restOfContext));
583
+ }
584
+ const sourceLocation = __sourceLocation ?? (0, import_monitoring_common.getCallLocation)();
518
585
  return {
519
586
  insertId: generateId(),
520
587
  timestamp: new Date(timestamp).toISOString(),
521
588
  severity: level.toUpperCase(),
522
589
  labels: {
523
590
  tenantId: "",
524
- ...tags?.namespace ? { namespace: tags.namespace } : { namespace: "unknown" },
591
+ namespace,
525
592
  ...siteUrl ? { siteUrl } : {}
526
593
  },
527
594
  operation: {
528
- id: generateId(),
529
- ...tags?.producer ? { producer: tags.producer } : { producer: "unknown" }
595
+ id: requestId ?? generateId(),
596
+ producer
530
597
  },
531
598
  ...sourceLocation ? { sourceLocation } : {},
532
599
  jsonPayload: {
533
- message
600
+ message: messageParts.join(" ")
534
601
  }
535
602
  };
536
603
  };
537
- var report = (messages, authToken = "", fetch = globalThis.fetch) => {
538
- fetch("https://www.wixapis.com/wixcode/v1/telemetry/telemetry-messages", {
539
- method: "POST",
540
- body: JSON.stringify({ messages }),
541
- headers: {
542
- Authorization: authToken
543
- }
544
- }).catch(() => {
545
- });
604
+ var TELEMETRY_URL = "https://www.wixapis.com/wixcode/v1/telemetry/telemetry-messages";
605
+ var MAX_BATCH_SIZE = 100;
606
+ var THROTTLE_DURATION = 300;
607
+ var report = async (messages, authToken = "", fetch = globalThis.fetch) => {
608
+ try {
609
+ await fetch(TELEMETRY_URL, {
610
+ method: "POST",
611
+ body: JSON.stringify({ messages }),
612
+ headers: {
613
+ Authorization: authToken
614
+ }
615
+ });
616
+ } catch (_e) {
617
+ }
546
618
  };
547
619
  var import_throttle = __toESM2(require_throttle(), 1);
548
620
  var BatchQueue = class {
549
621
  constructor(options) {
550
622
  this.options = options;
551
623
  this.queue = [];
624
+ this.batchQueuePromise = null;
625
+ this.resolveBatchQueuePromise = null;
552
626
  this.flushThrottled = (0, import_throttle.default)(
553
627
  () => this.flush(),
554
628
  options.throttleDuration,
@@ -559,10 +633,20 @@ var require_build2 = __commonJS({
559
633
  }
560
634
  flush() {
561
635
  const events = this.queue.splice(0);
562
- this.options.flushHandler(events);
636
+ this.options.flushHandler(events).then(() => {
637
+ this.resolveBatchQueuePromise?.();
638
+ this.resolveBatchQueuePromise = null;
639
+ });
640
+ this.batchQueuePromise = null;
563
641
  }
564
642
  enqueue(payload) {
565
643
  this.queue.push(payload);
644
+ if (!this.batchQueuePromise) {
645
+ this.batchQueuePromise = new Promise((resolve) => {
646
+ this.resolveBatchQueuePromise = resolve;
647
+ });
648
+ this.options.onBatchQueueCreated?.(this.batchQueuePromise);
649
+ }
566
650
  if (this.queue.length === this.options.maxBatchSize) {
567
651
  this.flushThrottled.cancel();
568
652
  this.flush();
@@ -571,31 +655,64 @@ var require_build2 = __commonJS({
571
655
  }
572
656
  }
573
657
  };
658
+ var isPromise = (value) => typeof value?.then === "function";
659
+ var import_monitoring_common2 = (init_build(), __toCommonJS(build_exports));
574
660
  var VeloClient = class {
575
661
  constructor(options) {
576
662
  this.options = options;
663
+ this.reportError = (captureContext = {}, e) => {
664
+ const { tags, contexts } = captureContext;
665
+ const messagePayload = buildTelemetryPayload(this.options, {
666
+ message: e?.toString() ?? "Unknown error",
667
+ level: "error",
668
+ tags,
669
+ contexts: {
670
+ __sourceLocation: (0, import_monitoring_common2.getCallLocation)(e?.stack),
671
+ ...contexts
672
+ }
673
+ });
674
+ this.batchQueue.enqueue(messagePayload);
675
+ };
577
676
  this.captureException = (error, captureContext) => {
677
+ this.reportError(captureContext, error);
578
678
  };
579
679
  this.captureMessage = (message, captureContext = {}) => {
580
- const { level = "info", tags } = captureContext;
581
- const messagePayload = buildMessagePayload({
680
+ const { level = "info", tags, contexts } = captureContext;
681
+ const messagePayload = buildTelemetryPayload(this.options, {
582
682
  message,
583
683
  level,
584
684
  tags,
585
- req: this.options.req
685
+ contexts
586
686
  });
587
687
  this.batchQueue.enqueue(messagePayload);
588
688
  };
589
689
  this.startSpan = (spanOptions, callback) => {
590
- return null;
690
+ let res;
691
+ try {
692
+ res = callback();
693
+ if (isPromise(res)) {
694
+ res = res.then((_res) => {
695
+ return _res;
696
+ }).catch((e) => {
697
+ this.reportError(spanOptions, e);
698
+ throw e;
699
+ });
700
+ } else {
701
+ }
702
+ } catch (e) {
703
+ this.reportError(spanOptions, e);
704
+ throw e;
705
+ }
706
+ return res;
591
707
  };
592
708
  this.addBreadcrumb = (breadcrumb) => {
593
709
  };
594
710
  const { getAuthToken, fetch } = options;
595
711
  this.batchQueue = new BatchQueue({
596
- maxBatchSize: 100,
597
- throttleDuration: 300,
598
- flushHandler: (messages) => report(messages, getAuthToken(), fetch)
712
+ maxBatchSize: MAX_BATCH_SIZE,
713
+ throttleDuration: THROTTLE_DURATION,
714
+ flushHandler: (messages) => getAuthToken().then((token) => report(messages, token, fetch)),
715
+ onBatchQueueCreated: options.onBatchQueueCreated
599
716
  });
600
717
  }
601
718
  startSpanManual(spanOptions) {
@@ -603,6 +720,7 @@ var require_build2 = __commonJS({
603
720
  end: () => {
604
721
  },
605
722
  fail: (error) => {
723
+ this.reportError(spanOptions, error);
606
724
  }
607
725
  };
608
726
  }
@@ -775,11 +893,25 @@ var createHostModule = () => {
775
893
  essentials: {
776
894
  get passThroughHeaders() {
777
895
  return getPassThroughHeaders();
778
- }
896
+ },
897
+ language: "en",
898
+ locale: "en-US",
899
+ timezone: "UTC"
779
900
  },
780
- getMonitoringClient: () => (0, import_monitoring_velo.createVeloMonitoringClient)({
781
- getAuthToken: () => resolveAuthToken()
782
- })
901
+ getMonitoringClient: () => {
902
+ let producer = "unknown";
903
+ let req;
904
+ if (typeof document !== "undefined") {
905
+ producer = document.location.href;
906
+ req = new Request(document.location.href);
907
+ }
908
+ return (0, import_monitoring_velo.createVeloMonitoringClient)({
909
+ namespace: "Headless",
910
+ producer,
911
+ getAuthToken: async () => resolveAuthToken(),
912
+ req
913
+ });
914
+ }
783
915
  };
784
916
  }
785
917
  };
@@ -16,7 +16,7 @@ import {
16
16
  } from "./chunk-PSHIUVP2.js";
17
17
  import {
18
18
  __export
19
- } from "./chunk-U67V476Y.js";
19
+ } from "./chunk-QRPWKJ4C.js";
20
20
 
21
21
  // ../../node_modules/@wix/auto_sdk_auth-management_o-auth-apps/build/es/index.mjs
22
22
  var es_exports = {};
@@ -6,8 +6,11 @@ import {
6
6
  } from "./chunk-PSHIUVP2.js";
7
7
  import {
8
8
  __commonJS,
9
+ __esm,
10
+ __export,
11
+ __toCommonJS,
9
12
  __toESM
10
- } from "./chunk-U67V476Y.js";
13
+ } from "./chunk-QRPWKJ4C.js";
11
14
 
12
15
  // ../../node_modules/@wix/monitoring/build/index.cjs
13
16
  var require_build = __commonJS({
@@ -17,7 +20,7 @@ var require_build = __commonJS({
17
20
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
18
21
  var __getOwnPropNames = Object.getOwnPropertyNames;
19
22
  var __hasOwnProp = Object.prototype.hasOwnProperty;
20
- var __export = (target, all) => {
23
+ var __export2 = (target, all) => {
21
24
  for (var name in all)
22
25
  __defProp(target, name, { get: all[name], enumerable: true });
23
26
  };
@@ -29,13 +32,13 @@ var require_build = __commonJS({
29
32
  }
30
33
  return to;
31
34
  };
32
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
35
+ var __toCommonJS2 = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
33
36
  var index_exports = {};
34
- __export(index_exports, {
37
+ __export2(index_exports, {
35
38
  createFallbackMonitoringClient: () => createFallbackMonitoringClient,
36
39
  generateTagsAndContext: () => generateTagsAndContext
37
40
  });
38
- module.exports = __toCommonJS(index_exports);
41
+ module.exports = __toCommonJS2(index_exports);
39
42
  var validValue = (value) => value !== void 0 && value !== null && value !== "";
40
43
  var pickByValidValues = (obj) => pickBy(obj, validValue);
41
44
  function pickBy(object, predicate = (value) => !!value) {
@@ -116,6 +119,44 @@ var require_build = __commonJS({
116
119
  }
117
120
  });
118
121
 
122
+ // ../../node_modules/@wix/monitoring-common/build/index.js
123
+ var build_exports = {};
124
+ __export(build_exports, {
125
+ getCallLocation: () => getCallLocation,
126
+ getCallStack: () => getCallStack
127
+ });
128
+ var getCallStack, getCallLocation;
129
+ var init_build = __esm({
130
+ "../../node_modules/@wix/monitoring-common/build/index.js"() {
131
+ "use strict";
132
+ getCallStack = () => {
133
+ try {
134
+ throw new Error();
135
+ } catch (e) {
136
+ return e?.stack;
137
+ }
138
+ };
139
+ getCallLocation = (stack) => {
140
+ stack = stack ?? getCallStack();
141
+ const frames = stack?.trim().split("\n");
142
+ if (!frames) {
143
+ return null;
144
+ }
145
+ for (let i = frames.length - 1; i >= 0; i--) {
146
+ const match = frames[i].match(/https?:\/\/.+?(\/.+):(\d+):(\d+)/) ?? frames[i].match(/.*(\/[^/]+):(\d+):(\d+)/);
147
+ if (match) {
148
+ return {
149
+ file: match[1],
150
+ line: parseInt(match[2], 10) ?? 0,
151
+ column: parseInt(match[3], 10) ?? 0
152
+ };
153
+ }
154
+ }
155
+ return null;
156
+ };
157
+ }
158
+ });
159
+
119
160
  // ../../node_modules/lodash/isObject.js
120
161
  var require_isObject = __commonJS({
121
162
  "../../node_modules/lodash/isObject.js"(exports, module) {
@@ -451,7 +492,7 @@ var require_build2 = __commonJS({
451
492
  var __getOwnPropNames = Object.getOwnPropertyNames;
452
493
  var __getProtoOf = Object.getPrototypeOf;
453
494
  var __hasOwnProp = Object.prototype.hasOwnProperty;
454
- var __export = (target, all) => {
495
+ var __export2 = (target, all) => {
455
496
  for (var name in all)
456
497
  __defProp(target, name, { get: all[name], enumerable: true });
457
498
  };
@@ -471,69 +512,97 @@ var require_build2 = __commonJS({
471
512
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
472
513
  mod
473
514
  ));
474
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
515
+ var __toCommonJS2 = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
475
516
  var index_exports = {};
476
- __export(index_exports, {
517
+ __export2(index_exports, {
477
518
  createVeloMonitoringClient: () => createVeloMonitoringClient2
478
519
  });
479
- module.exports = __toCommonJS(index_exports);
520
+ module.exports = __toCommonJS2(index_exports);
480
521
  var import_monitoring = require_build();
522
+ var import_monitoring_common = (init_build(), __toCommonJS(build_exports));
481
523
  var generateId = () => {
482
524
  return typeof crypto !== "undefined" && typeof crypto.randomUUID === "function" ? crypto.randomUUID() : "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(e) {
483
525
  const i = 16 * Math.random() | 0;
484
526
  return ("x" === e ? i : 3 & i | 8).toString(16);
485
527
  });
486
528
  };
487
- var buildMessagePayload = (params) => {
488
- const { message, level = "INFO", timestamp = Date.now(), tags, req } = params;
529
+ var stringifySafe = (value) => {
530
+ try {
531
+ return JSON.stringify(value);
532
+ } catch (error) {
533
+ return `Failed to stringify log value: ${error?.toString()}`;
534
+ }
535
+ };
536
+ var buildTelemetryPayload = (options, params) => {
537
+ const { namespace, producer, req, requestId } = options;
538
+ const {
539
+ message,
540
+ level = "INFO",
541
+ timestamp = Date.now(),
542
+ tags,
543
+ contexts
544
+ } = params;
545
+ const { __sourceLocation, ...restOfContext } = contexts ?? {};
489
546
  let siteUrl = "";
490
547
  if (req) {
491
548
  try {
492
- siteUrl = new URL(req.headers.get("referer") ?? "").origin;
549
+ if (req.headers.get("referer")) {
550
+ siteUrl = new URL(req.headers.get("referer") ?? "").origin;
551
+ } else {
552
+ siteUrl = new URL(req.url).origin;
553
+ }
493
554
  } catch (e) {
494
555
  }
495
- } else if (typeof document !== "undefined") {
496
- siteUrl = document.location.origin;
497
556
  }
498
- const sourceLocation = tags?.fileName && {
499
- file: tags.fileName,
500
- line: tags.lineNumber ?? 0,
501
- column: tags.columnNumber ?? 0
502
- };
557
+ const messageParts = [message];
558
+ if (tags) {
559
+ messageParts.push(stringifySafe(tags));
560
+ }
561
+ if (Object.keys(restOfContext).length > 0) {
562
+ messageParts.push(stringifySafe(restOfContext));
563
+ }
564
+ const sourceLocation = __sourceLocation ?? (0, import_monitoring_common.getCallLocation)();
503
565
  return {
504
566
  insertId: generateId(),
505
567
  timestamp: new Date(timestamp).toISOString(),
506
568
  severity: level.toUpperCase(),
507
569
  labels: {
508
570
  tenantId: "",
509
- ...tags?.namespace ? { namespace: tags.namespace } : { namespace: "unknown" },
571
+ namespace,
510
572
  ...siteUrl ? { siteUrl } : {}
511
573
  },
512
574
  operation: {
513
- id: generateId(),
514
- ...tags?.producer ? { producer: tags.producer } : { producer: "unknown" }
575
+ id: requestId ?? generateId(),
576
+ producer
515
577
  },
516
578
  ...sourceLocation ? { sourceLocation } : {},
517
579
  jsonPayload: {
518
- message
580
+ message: messageParts.join(" ")
519
581
  }
520
582
  };
521
583
  };
522
- var report = (messages, authToken = "", fetch = globalThis.fetch) => {
523
- fetch("https://www.wixapis.com/wixcode/v1/telemetry/telemetry-messages", {
524
- method: "POST",
525
- body: JSON.stringify({ messages }),
526
- headers: {
527
- Authorization: authToken
528
- }
529
- }).catch(() => {
530
- });
584
+ var TELEMETRY_URL = "https://www.wixapis.com/wixcode/v1/telemetry/telemetry-messages";
585
+ var MAX_BATCH_SIZE = 100;
586
+ var THROTTLE_DURATION = 300;
587
+ var report = async (messages, authToken = "", fetch = globalThis.fetch) => {
588
+ try {
589
+ await fetch(TELEMETRY_URL, {
590
+ method: "POST",
591
+ body: JSON.stringify({ messages }),
592
+ headers: {
593
+ Authorization: authToken
594
+ }
595
+ });
596
+ } catch (_e) {
597
+ }
531
598
  };
532
599
  var import_throttle = __toESM2(require_throttle(), 1);
533
600
  var BatchQueue = class {
534
601
  constructor(options) {
535
602
  this.options = options;
536
603
  this.queue = [];
604
+ this.batchQueuePromise = null;
605
+ this.resolveBatchQueuePromise = null;
537
606
  this.flushThrottled = (0, import_throttle.default)(
538
607
  () => this.flush(),
539
608
  options.throttleDuration,
@@ -544,10 +613,20 @@ var require_build2 = __commonJS({
544
613
  }
545
614
  flush() {
546
615
  const events = this.queue.splice(0);
547
- this.options.flushHandler(events);
616
+ this.options.flushHandler(events).then(() => {
617
+ this.resolveBatchQueuePromise?.();
618
+ this.resolveBatchQueuePromise = null;
619
+ });
620
+ this.batchQueuePromise = null;
548
621
  }
549
622
  enqueue(payload) {
550
623
  this.queue.push(payload);
624
+ if (!this.batchQueuePromise) {
625
+ this.batchQueuePromise = new Promise((resolve) => {
626
+ this.resolveBatchQueuePromise = resolve;
627
+ });
628
+ this.options.onBatchQueueCreated?.(this.batchQueuePromise);
629
+ }
551
630
  if (this.queue.length === this.options.maxBatchSize) {
552
631
  this.flushThrottled.cancel();
553
632
  this.flush();
@@ -556,31 +635,64 @@ var require_build2 = __commonJS({
556
635
  }
557
636
  }
558
637
  };
638
+ var isPromise = (value) => typeof value?.then === "function";
639
+ var import_monitoring_common2 = (init_build(), __toCommonJS(build_exports));
559
640
  var VeloClient = class {
560
641
  constructor(options) {
561
642
  this.options = options;
643
+ this.reportError = (captureContext = {}, e) => {
644
+ const { tags, contexts } = captureContext;
645
+ const messagePayload = buildTelemetryPayload(this.options, {
646
+ message: e?.toString() ?? "Unknown error",
647
+ level: "error",
648
+ tags,
649
+ contexts: {
650
+ __sourceLocation: (0, import_monitoring_common2.getCallLocation)(e?.stack),
651
+ ...contexts
652
+ }
653
+ });
654
+ this.batchQueue.enqueue(messagePayload);
655
+ };
562
656
  this.captureException = (error, captureContext) => {
657
+ this.reportError(captureContext, error);
563
658
  };
564
659
  this.captureMessage = (message, captureContext = {}) => {
565
- const { level = "info", tags } = captureContext;
566
- const messagePayload = buildMessagePayload({
660
+ const { level = "info", tags, contexts } = captureContext;
661
+ const messagePayload = buildTelemetryPayload(this.options, {
567
662
  message,
568
663
  level,
569
664
  tags,
570
- req: this.options.req
665
+ contexts
571
666
  });
572
667
  this.batchQueue.enqueue(messagePayload);
573
668
  };
574
669
  this.startSpan = (spanOptions, callback) => {
575
- return null;
670
+ let res;
671
+ try {
672
+ res = callback();
673
+ if (isPromise(res)) {
674
+ res = res.then((_res) => {
675
+ return _res;
676
+ }).catch((e) => {
677
+ this.reportError(spanOptions, e);
678
+ throw e;
679
+ });
680
+ } else {
681
+ }
682
+ } catch (e) {
683
+ this.reportError(spanOptions, e);
684
+ throw e;
685
+ }
686
+ return res;
576
687
  };
577
688
  this.addBreadcrumb = (breadcrumb) => {
578
689
  };
579
690
  const { getAuthToken, fetch } = options;
580
691
  this.batchQueue = new BatchQueue({
581
- maxBatchSize: 100,
582
- throttleDuration: 300,
583
- flushHandler: (messages) => report(messages, getAuthToken(), fetch)
692
+ maxBatchSize: MAX_BATCH_SIZE,
693
+ throttleDuration: THROTTLE_DURATION,
694
+ flushHandler: (messages) => getAuthToken().then((token) => report(messages, token, fetch)),
695
+ onBatchQueueCreated: options.onBatchQueueCreated
584
696
  });
585
697
  }
586
698
  startSpanManual(spanOptions) {
@@ -588,6 +700,7 @@ var require_build2 = __commonJS({
588
700
  end: () => {
589
701
  },
590
702
  fail: (error) => {
703
+ this.reportError(spanOptions, error);
591
704
  }
592
705
  };
593
706
  }
@@ -658,17 +771,26 @@ var createHostModule = () => {
658
771
  },
659
772
  host: function(_temp) {
660
773
  let {
661
- req
774
+ req,
775
+ waitUntil
662
776
  } = _temp === void 0 ? {} : _temp;
663
777
  const passThroughHeaders = getPassThroughHeaders(req);
664
778
  return {
665
779
  essentials: {
666
- passThroughHeaders
780
+ passThroughHeaders,
781
+ language: "en",
782
+ locale: "en-US",
783
+ timezone: "UTC"
667
784
  },
668
- getMonitoringClient: () => (0, import_monitoring_velo.createVeloMonitoringClient)({
669
- getAuthToken: () => resolveAuthToken(),
670
- req
671
- })
785
+ getMonitoringClient: () => {
786
+ return (0, import_monitoring_velo.createVeloMonitoringClient)({
787
+ req,
788
+ namespace: "Headless",
789
+ producer: "backend",
790
+ getAuthToken: async () => resolveAuthToken(),
791
+ onBatchQueueCreated: (batchFlushPromise) => waitUntil == null ? void 0 : waitUntil(batchFlushPromise)
792
+ });
793
+ }
672
794
  };
673
795
  }
674
796
  };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  __export
3
- } from "./chunk-U67V476Y.js";
3
+ } from "./chunk-QRPWKJ4C.js";
4
4
 
5
5
  // ../../node_modules/zod/dist/esm/v4/core/core.js
6
6
  // @__NO_SIDE_EFFECTS__
@@ -4,6 +4,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __esm = (fn, res) => function __init() {
8
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
9
+ };
7
10
  var __commonJS = (cb, mod) => function __require() {
8
11
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
12
  };
@@ -27,9 +30,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
30
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
31
  mod
29
32
  ));
33
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
34
 
31
35
  export {
36
+ __esm,
32
37
  __commonJS,
33
38
  __export,
34
- __toESM
39
+ __toESM,
40
+ __toCommonJS
35
41
  };
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  createHostProxy
3
- } from "../chunk-NKY4T53W.js";
3
+ } from "../chunk-NKFV7KCT.js";
4
4
  import "../chunk-NVTQFGTR.js";
5
5
  import "../chunk-PSHIUVP2.js";
6
- import "../chunk-U67V476Y.js";
6
+ import "../chunk-QRPWKJ4C.js";
7
7
 
8
8
  // src/context/elevated.ts
9
9
  import { AppStrategy, createClient } from "@wix/sdk";
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  createHostProxy
3
- } from "../chunk-NKY4T53W.js";
3
+ } from "../chunk-NKFV7KCT.js";
4
4
  import {
5
5
  authAsyncLocalStorage
6
6
  } from "../chunk-NVTQFGTR.js";
7
7
  import "../chunk-PSHIUVP2.js";
8
- import "../chunk-U67V476Y.js";
8
+ import "../chunk-QRPWKJ4C.js";
9
9
 
10
10
  // src/context/nonElevated.ts
11
11
  import { createClient, OAuthStrategy } from "@wix/sdk";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  setupClient
3
3
  } from "../chunk-W73LN534.js";
4
- import "../chunk-U67V476Y.js";
4
+ import "../chunk-QRPWKJ4C.js";
5
5
 
6
6
  // src/context/setupServicePlugin.ts
7
7
  async function setupServicePlugin(fn) {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  setupClient
3
3
  } from "../chunk-W73LN534.js";
4
- import "../chunk-U67V476Y.js";
4
+ import "../chunk-QRPWKJ4C.js";
5
5
 
6
6
  // src/context/setupWebhook.ts
7
7
  async function setupWebhook(fn) {
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  authAsyncLocalStorage
6
6
  } from "../chunk-NVTQFGTR.js";
7
- import "../chunk-U67V476Y.js";
7
+ import "../chunk-QRPWKJ4C.js";
8
8
 
9
9
  // src/utils/generateVisitorTokens.ts
10
10
  import { OAuthStrategy } from "@wix/sdk";
@@ -9,7 +9,7 @@ import {
9
9
  import "../chunk-PSHIUVP2.js";
10
10
  import {
11
11
  __export
12
- } from "../chunk-U67V476Y.js";
12
+ } from "../chunk-QRPWKJ4C.js";
13
13
 
14
14
  // ../../node_modules/@wix/auto_sdk_headless-site-assets_scripts/build/es/index.mjs
15
15
  var es_exports = {};
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  object,
3
3
  string
4
- } from "../../chunk-WE3ELMU5.js";
4
+ } from "../../chunk-Q3KPY4P2.js";
5
5
  import {
6
6
  auth,
7
7
  oAuthStateCookieName
@@ -9,7 +9,7 @@ import {
9
9
  import {
10
10
  saveSessionTokensToCookie
11
11
  } from "../../chunk-HPW4ZAEJ.js";
12
- import "../../chunk-U67V476Y.js";
12
+ import "../../chunk-QRPWKJ4C.js";
13
13
 
14
14
  // src/routes/auth/callback.ts
15
15
  var oauthCookieSchema = object({
@@ -2,12 +2,12 @@ import {
2
2
  _enum,
3
3
  object,
4
4
  string
5
- } from "../../chunk-WE3ELMU5.js";
5
+ } from "../../chunk-Q3KPY4P2.js";
6
6
  import {
7
7
  auth,
8
8
  oAuthStateCookieName
9
9
  } from "../../chunk-UZPSWWI5.js";
10
- import "../../chunk-U67V476Y.js";
10
+ import "../../chunk-QRPWKJ4C.js";
11
11
 
12
12
  // src/routes/auth/login.ts
13
13
  var loginSearchParams = object({
@@ -5,7 +5,7 @@ import {
5
5
  import {
6
6
  saveSessionTokensToCookie
7
7
  } from "../../chunk-HPW4ZAEJ.js";
8
- import "../../chunk-U67V476Y.js";
8
+ import "../../chunk-QRPWKJ4C.js";
9
9
 
10
10
  // src/routes/auth/logout-callback.ts
11
11
  var GET = async (context) => {
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  object,
3
3
  string
4
- } from "../../chunk-WE3ELMU5.js";
4
+ } from "../../chunk-Q3KPY4P2.js";
5
5
  import {
6
6
  auth,
7
7
  returnToQueryParamName
8
8
  } from "../../chunk-UZPSWWI5.js";
9
- import "../../chunk-U67V476Y.js";
9
+ import "../../chunk-QRPWKJ4C.js";
10
10
 
11
11
  // src/routes/auth/logout.ts
12
12
  var logoutSearchParams = object({
@@ -3,10 +3,10 @@ import {
3
3
  } from "../../chunk-YX6EVX5Q.js";
4
4
  import {
5
5
  es_exports
6
- } from "../../chunk-7EHL72JI.js";
6
+ } from "../../chunk-JODQ44LE.js";
7
7
  import "../../chunk-EK7YZVWJ.js";
8
8
  import "../../chunk-PSHIUVP2.js";
9
- import "../../chunk-U67V476Y.js";
9
+ import "../../chunk-QRPWKJ4C.js";
10
10
 
11
11
  // src/routes/paylink/checkout.ts
12
12
  import { auth } from "@wix/essentials";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  es_exports
3
- } from "../../chunk-7EHL72JI.js";
3
+ } from "../../chunk-JODQ44LE.js";
4
4
  import "../../chunk-EK7YZVWJ.js";
5
5
  import "../../chunk-PSHIUVP2.js";
6
- import "../../chunk-U67V476Y.js";
6
+ import "../../chunk-QRPWKJ4C.js";
7
7
 
8
8
  // src/routes/paylink/paylink.ts
9
9
  import { auth } from "@wix/essentials";
@@ -3,10 +3,10 @@ import {
3
3
  } from "../../chunk-YX6EVX5Q.js";
4
4
  import {
5
5
  es_exports
6
- } from "../../chunk-7EHL72JI.js";
6
+ } from "../../chunk-JODQ44LE.js";
7
7
  import "../../chunk-EK7YZVWJ.js";
8
8
  import "../../chunk-PSHIUVP2.js";
9
- import "../../chunk-U67V476Y.js";
9
+ import "../../chunk-QRPWKJ4C.js";
10
10
 
11
11
  // src/routes/robots/robots.ts
12
12
  import { auth } from "@wix/essentials";
@@ -1,4 +1,4 @@
1
- import "../chunk-U67V476Y.js";
1
+ import "../chunk-QRPWKJ4C.js";
2
2
 
3
3
  // src/routes/servicePluginsDevRoute.ts
4
4
  var ALL = async (context) => {
@@ -1,4 +1,4 @@
1
- import "../chunk-U67V476Y.js";
1
+ import "../chunk-QRPWKJ4C.js";
2
2
 
3
3
  // src/routes/webhooksDevRoute.ts
4
4
  var ALL = async (context) => {
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@wix/astro",
3
- "version": "1.0.32",
3
+ "version": "1.0.33",
4
4
  "devDependencies": {
5
5
  "@wix/auth-management": "^1.0.70",
6
6
  "@wix/dashboard": "^1.3.35",
7
7
  "@wix/essentials": "^0.1.23",
8
- "@wix/headless-node": "^1.7.0",
9
- "@wix/headless-site": "^1.3.0",
8
+ "@wix/headless-node": "^1.11.0",
9
+ "@wix/headless-site": "^1.7.0",
10
10
  "@wix/headless-site-assets": "^1.0.2",
11
11
  "@wix/sdk": "^1.15.23",
12
12
  "@wix/sdk-context": "^0.0.1",
@@ -51,5 +51,5 @@
51
51
  "artifactId": "wix-astro"
52
52
  }
53
53
  },
54
- "falconPackageHash": "6f606824546987477247020af5483a643d4c7e87e963a9fd1bca977b"
54
+ "falconPackageHash": "6d3fa14f5c808afa661a207cc6b85f6668862487c17e814c9a9995d3"
55
55
  }