avo-inspector 3.2.0 → 3.2.3

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.
Files changed (84) hide show
  1. package/README.md +10 -0
  2. package/dist/AvoBatcher.d.ts +9 -3
  3. package/dist/AvoInspector.d.ts +4 -0
  4. package/dist/AvoNetworkCallsHandler.d.ts +80 -5
  5. package/dist/__tests__/UnboundPublicMethods_test.d.ts +1 -0
  6. package/dist/__tests__/constants.d.ts +2 -1
  7. package/dist/__tests__/helpers/internalGateway.d.ts +23 -0
  8. package/dist/eventSpec/AvoEventSpecCache.d.ts +7 -4
  9. package/dist/eventSpec/AvoEventSpecFetchTypes.d.ts +12 -1
  10. package/dist/eventSpec/AvoEventSpecFetcher.d.ts +6 -1
  11. package/dist/index.js +1 -1
  12. package/dist/lite/AvoBatcherLite.d.ts +9 -3
  13. package/dist/lite/AvoBatcherLite.js +46 -7
  14. package/dist/lite/AvoInspectorLite.d.ts +2 -0
  15. package/dist/lite/AvoInspectorLite.js +95 -15
  16. package/dist/lite/AvoNetworkCallsHandlerLite.d.ts +79 -5
  17. package/dist/lite/AvoNetworkCallsHandlerLite.js +300 -20
  18. package/package.json +10 -1
  19. package/dist/AvoBatcher.js +0 -87
  20. package/dist/AvoDeduplicator.js +0 -142
  21. package/dist/AvoEncryption.js +0 -176
  22. package/dist/AvoInspector.js +0 -435
  23. package/dist/AvoNetworkCallsHandler.js +0 -229
  24. package/dist/AvoSchemaParser.js +0 -95
  25. package/dist/AvoStreamId.js +0 -82
  26. package/dist/__mocks__/xhr.js +0 -14
  27. package/dist/__mocks__/xhrError.js +0 -14
  28. package/dist/__tests__/AvoEncryption.js +0 -272
  29. package/dist/__tests__/AvoEncryptionIntegration.js +0 -191
  30. package/dist/__tests__/AvoEventSpecFetcher.js +0 -377
  31. package/dist/__tests__/AvoInspector.js +0 -335
  32. package/dist/__tests__/Batcher.js +0 -214
  33. package/dist/__tests__/BatcherPublic.js +0 -139
  34. package/dist/__tests__/Deduplicator.js +0 -190
  35. package/dist/__tests__/EventSpecCache.js +0 -143
  36. package/dist/__tests__/EventValidator.js +0 -543
  37. package/dist/__tests__/InstallationId.js +0 -60
  38. package/dist/__tests__/NetworkCallsHandler.js +0 -222
  39. package/dist/__tests__/NetworkCallsHandlerModelA.js +0 -206
  40. package/dist/__tests__/Parsing.js +0 -115
  41. package/dist/__tests__/Sessions.d.ts +0 -1
  42. package/dist/__tests__/Sessions.js +0 -10
  43. package/dist/__tests__/Storage.d.ts +0 -1
  44. package/dist/__tests__/Storage.js +0 -173
  45. package/dist/__tests__/StreamId.d.ts +0 -1
  46. package/dist/__tests__/StreamId.js +0 -153
  47. package/dist/__tests__/constants.js +0 -48
  48. package/dist/esm/AvoBatcher.js +0 -75
  49. package/dist/esm/AvoDeduplicator.js +0 -137
  50. package/dist/esm/AvoEncryption.js +0 -277
  51. package/dist/esm/AvoGuid.js +0 -9
  52. package/dist/esm/AvoInspector.js +0 -470
  53. package/dist/esm/AvoInspectorEnv.js +0 -5
  54. package/dist/esm/AvoNetworkCallsHandler.js +0 -181
  55. package/dist/esm/AvoSchemaParser.js +0 -128
  56. package/dist/esm/AvoStorage.js +0 -176
  57. package/dist/esm/AvoStreamId.js +0 -140
  58. package/dist/esm/eventSpec/AvoEventSpecCache.js +0 -165
  59. package/dist/esm/eventSpec/AvoEventSpecFetchTypes.js +0 -6
  60. package/dist/esm/eventSpec/AvoEventSpecFetcher.js +0 -203
  61. package/dist/esm/eventSpec/EventValidator.js +0 -687
  62. package/dist/esm/eventSpec/index.js +0 -4
  63. package/dist/esm/index.js +0 -3
  64. package/dist/esm/utils.js +0 -38
  65. package/dist/esm/version.js +0 -2
  66. package/dist/eventSpec/AvoEventSpecCache.js +0 -181
  67. package/dist/eventSpec/AvoEventSpecFetcher.js +0 -290
  68. package/dist/eventSpec/EventValidator.js +0 -846
  69. package/dist/eventSpec/index.js +0 -20
  70. package/dist/version.d.ts +0 -1
  71. package/dist/version.js +0 -5
  72. /package/dist/__tests__/{AvoEncryption.d.ts → ApiKeyHeaderInjection_test.d.ts} +0 -0
  73. /package/dist/__tests__/{AvoEncryptionIntegration.d.ts → BrowserBootstrap_test.d.ts} +0 -0
  74. /package/dist/__tests__/{AvoEventSpecFetcher.d.ts → EventSpecGatewayCoordinates_test.d.ts} +0 -0
  75. /package/dist/__tests__/{AvoInspector.d.ts → InFlightQueueGaps_test.d.ts} +0 -0
  76. /package/dist/__tests__/{Batcher.d.ts → InFlightQueue_test.d.ts} +0 -0
  77. /package/dist/__tests__/{BatcherPublic.d.ts → NetworkCallsHandlerLite_test.d.ts} +0 -0
  78. /package/dist/__tests__/{Deduplicator.d.ts → PublicSurface_test.d.ts} +0 -0
  79. /package/dist/__tests__/{EventSpecCache.d.ts → TrackOptionsIntegration_test.d.ts} +0 -0
  80. /package/dist/__tests__/{EventValidator.d.ts → TrackOptionsTransport_test.d.ts} +0 -0
  81. /package/dist/__tests__/{InstallationId.d.ts → TrackingHeaders_test.d.ts} +0 -0
  82. /package/dist/__tests__/{NetworkCallsHandler.d.ts → V1WireBaseline_test.d.ts} +0 -0
  83. /package/dist/__tests__/{NetworkCallsHandlerModelA.d.ts → V2QueuedAttribution_test.d.ts} +0 -0
  84. /package/dist/__tests__/{Parsing.d.ts → V2StopSending_test.d.ts} +0 -0
@@ -1,8 +1,8 @@
1
- import { type AvoNetworkCallsHandler, type EventProperty } from "./AvoNetworkCallsHandlerLite";
1
+ import { type EventSchemaBody, type AvoNetworkCallsHandler, type EventProperty, type TrackOptions } from "./AvoNetworkCallsHandlerLite";
2
2
  import type { EventSpecMetadata } from "../eventSpec/AvoEventSpecFetchTypes";
3
3
  export interface AvoBatcherType {
4
4
  handleSessionStarted: () => void;
5
- handleTrackSchema: (eventName: string, schema: EventProperty[], eventId: string | null, eventHash: string | null, eventSpecMetadata?: EventSpecMetadata) => void;
5
+ handleTrackSchema: (eventName: string, schema: EventProperty[], eventId: string | null, eventHash: string | null, eventSpecMetadata?: EventSpecMetadata, options?: TrackOptions) => void;
6
6
  }
7
7
  export declare class AvoBatcher implements AvoBatcherType {
8
8
  private events;
@@ -10,7 +10,13 @@ export declare class AvoBatcher implements AvoBatcherType {
10
10
  private readonly networkCallsHandler;
11
11
  constructor(networkCallsHandler: AvoNetworkCallsHandler);
12
12
  handleSessionStarted(): void;
13
- handleTrackSchema(eventName: string, schema: EventProperty[], eventId: string | null, eventHash: string | null, eventSpecMetadata?: EventSpecMetadata): void;
13
+ handleTrackSchema(eventName: string, schema: EventProperty[], eventId: string | null, eventHash: string | null, eventSpecMetadata?: EventSpecMetadata, options?: TrackOptions): void;
14
+ /**
15
+ * Queues an event body as it is, keeping its messageId and createdAt. Used to
16
+ * retry a failed immediate send: the request may have reached the server, and
17
+ * a resend must stay the same event rather than become a new one.
18
+ */
19
+ handleEventBody(eventBody: EventSchemaBody): void;
14
20
  private checkIfBatchNeedsToBeSent;
15
21
  private saveEvents;
16
22
  static get cacheKey(): string;
@@ -22,18 +22,45 @@ var AvoBatcher = /** @class */ (function () {
22
22
  });
23
23
  }
24
24
  AvoBatcher.prototype.handleSessionStarted = function () {
25
+ if (this.networkCallsHandler.isQueueingDisabled()) {
26
+ return;
27
+ }
25
28
  this.events.push(this.networkCallsHandler.bodyForSessionStartedCall());
26
29
  this.saveEvents();
30
+ if (this.networkCallsHandler.isSendingDisabled()) {
31
+ return;
32
+ }
27
33
  this.checkIfBatchNeedsToBeSent();
28
34
  };
29
- AvoBatcher.prototype.handleTrackSchema = function (eventName, schema, eventId, eventHash, eventSpecMetadata) {
30
- this.events.push(this.networkCallsHandler.bodyForEventSchemaCall(eventName, schema, eventId, eventHash, eventSpecMetadata));
35
+ AvoBatcher.prototype.handleTrackSchema = function (eventName, schema, eventId, eventHash, eventSpecMetadata, options) {
36
+ // v2 only: when the events could never be sent under any configuration (an api
37
+ // key that cannot be a header), queueing would only grow the stored queue.
38
+ if (this.networkCallsHandler.isQueueingDisabled()) {
39
+ return;
40
+ }
41
+ this.handleEventBody(this.networkCallsHandler.bodyForEventSchemaCall(eventName, schema, eventId, eventHash, eventSpecMetadata, undefined, options));
42
+ };
43
+ /**
44
+ * Queues an event body as it is, keeping its messageId and createdAt. Used to
45
+ * retry a failed immediate send: the request may have reached the server, and
46
+ * a resend must stay the same event rather than become a new one.
47
+ */
48
+ AvoBatcher.prototype.handleEventBody = function (eventBody) {
49
+ if (this.networkCallsHandler.isQueueingDisabled()) {
50
+ return;
51
+ }
52
+ this.events.push(eventBody);
31
53
  this.saveEvents();
32
54
  if (AvoInspectorLite_1.AvoInspector.shouldLog) {
33
55
  console.log("Avo Inspector: saved event " +
34
- eventName +
56
+ eventBody.eventName +
35
57
  " with schema " +
36
- JSON.stringify(schema));
58
+ JSON.stringify(eventBody.eventProperties));
59
+ }
60
+ // v2 only: sending has stopped for this page, but the queue is kept and saved,
61
+ // so a later page load can still deliver these events.
62
+ if (this.networkCallsHandler.isSendingDisabled()) {
63
+ return;
37
64
  }
38
65
  this.checkIfBatchNeedsToBeSent();
39
66
  };
@@ -41,18 +68,24 @@ var AvoBatcher = /** @class */ (function () {
41
68
  var batchSize = this.events.length;
42
69
  if (batchSize === 0)
43
70
  return;
71
+ // One batch at a time. The queue is checked again when the batch in flight
72
+ // completes, so waiting events do not depend on a later event to be sent.
73
+ if (this.networkCallsHandler.isBatchInFlight())
74
+ return;
44
75
  var now = Date.now();
45
76
  var timeSinceLastFlushAttempt = now - this.batchFlushAttemptTimestamp;
46
- var sendBySize = batchSize % AvoInspectorLite_1.AvoInspector.batchSize == 0;
77
+ var sendBySize = batchSize % AvoInspectorLite_1.AvoInspector.batchSize === 0;
47
78
  var sendByTime = timeSinceLastFlushAttempt >= AvoInspectorLite_1.AvoInspector.batchFlushSeconds * 1000;
48
79
  var avoBatcher = this;
49
80
  if (sendBySize || sendByTime) {
50
81
  this.batchFlushAttemptTimestamp = now;
51
82
  var sendingEvents_1 = avoBatcher.events;
52
83
  avoBatcher.events = [];
53
- this.networkCallsHandler.callInspectorWithBatchBody(sendingEvents_1, function (error) {
84
+ this.networkCallsHandler.callInspectorWithBatchBody(sendingEvents_1, function (error, retryEvents) {
54
85
  if (error != null) {
55
- avoBatcher.events = avoBatcher.events.concat(sendingEvents_1);
86
+ // v2 names the events worth retrying (it drops what can never pass);
87
+ // otherwise the whole batch goes back.
88
+ avoBatcher.events = avoBatcher.events.concat(retryEvents !== undefined ? retryEvents : sendingEvents_1);
56
89
  if (AvoInspectorLite_1.AvoInspector.shouldLog) {
57
90
  console.log("Avo Inspector: batch sending failed: " +
58
91
  error.message +
@@ -65,6 +98,12 @@ var AvoBatcher = /** @class */ (function () {
65
98
  }
66
99
  }
67
100
  avoBatcher.saveEvents();
101
+ // After a success, send what queued up meanwhile. After a failure the
102
+ // queue waits for the next event or flush, as before, rather than
103
+ // retrying in a loop against a failing network.
104
+ if (error == null && !avoBatcher.networkCallsHandler.isSendingDisabled()) {
105
+ avoBatcher.checkIfBatchNeedsToBeSent();
106
+ }
68
107
  });
69
108
  }
70
109
  };
@@ -28,6 +28,7 @@ export declare class AvoInspectorLite {
28
28
  suffix?: string;
29
29
  });
30
30
  trackSchemaFromEvent(eventName: string, eventProperties: Record<string, any>): Promise<EventProperty[]>;
31
+ private _trackSchemaFromEventWithOptions;
31
32
  private _avoFunctionTrackSchemaFromEvent;
32
33
  trackSchema(eventName: string, eventSchema: Array<{
33
34
  propertyName: string;
@@ -35,6 +36,7 @@ export declare class AvoInspectorLite {
35
36
  encryptedPropertyValue?: string;
36
37
  children?: any;
37
38
  }>): Promise<void>;
39
+ private _trackSchemaWithOptions;
38
40
  private trackSchemaInternal;
39
41
  enableLogging(enable: boolean): void;
40
42
  extractSchema(eventProperties: Record<string, any>, shouldLogIfEnabled?: boolean): Promise<Array<{
@@ -61,7 +61,27 @@ var AvoInspectorLite = /** @class */ (function () {
61
61
  throw new Error("[Avo Inspector] No API key provided. Inspector can't operate without API key.");
62
62
  }
63
63
  else {
64
- this.apiKey = options.apiKey;
64
+ // Trimmed once, here, so only the trimmed value is ever stored — on both
65
+ // transports. A key pasted out of a config file or read from an env var
66
+ // keeps its trailing newline, which on v2 has to survive being a request
67
+ // header. (On v1 the body is the only copy; v1 does not trim it either, so
68
+ // the untrimmed 3.2.0 behaviour was a failed key lookup, not a working send.)
69
+ //
70
+ // This is deliberately not a duplicate of what the platform already does.
71
+ // XMLHttpRequest strips surrounding whitespace from a header value before
72
+ // validating it, so a trailing-newline key reaches the server trimmed with
73
+ // no error — verified against a real server, not read off the spec. But it
74
+ // does that to the header only. The same key also travels in the request
75
+ // body, which nothing trims, so leaning on the platform is what would
76
+ // CREATE a divergence rather than avoid one: the header would carry "key"
77
+ // while the body carried the raw value. v2 reads the header and ignores
78
+ // the body copy, but that copy exists precisely so one body shape also
79
+ // serves v1 — and v1 reads its api key from the body.
80
+ //
81
+ // Trimming at the single source keeps the two identical, for 3 bytes
82
+ // gzipped. It is not a substitute for the send path's try/catch: an
83
+ // embedded control character survives trim and is still caught there.
84
+ this.apiKey = options.apiKey.trim();
65
85
  }
66
86
  if ((0, utils_1.isValueEmpty)(options.version)) {
67
87
  throw new Error("[Avo Inspector] No version provided. Many features of Inspector rely on versioning. Please provide comparable string version, i.e. integer or semantic.");
@@ -79,7 +99,12 @@ var AvoInspectorLite = /** @class */ (function () {
79
99
  AvoInspectorLite._shouldLog = false;
80
100
  }
81
101
  AvoInspectorLite.avoStorage = new AvoStorage_1.AvoStorage(AvoInspectorLite._shouldLog, options.suffix != null ? options.suffix : "");
82
- this.avoNetworkCallsHandler = new AvoNetworkCallsHandlerLite_1.AvoNetworkCallsHandlerLite(this.apiKey, this.environment.toString(), options.appName || "", this.version, libVersion);
102
+ this.avoNetworkCallsHandler = new AvoNetworkCallsHandlerLite_1.AvoNetworkCallsHandlerLite(this.apiKey, this.environment.toString(), options.appName || "", this.version, libVersion,
103
+ // INTERNAL: the web GTM tag template's client, which selects the v2
104
+ // transport. Only the script-tag bootstrap sets it (src/browser.js, from
105
+ // window.inspector.__CLIENT__), so it is deliberately not in the options
106
+ // type. Without it the SDK stays on v1 exactly as 3.2.0.
107
+ options._client);
83
108
  this.avoBatcher = new AvoBatcherLite_1.AvoBatcher(this.avoNetworkCallsHandler);
84
109
  }
85
110
  Object.defineProperty(AvoInspectorLite, "batchSize", {
@@ -124,9 +149,37 @@ var AvoInspectorLite = /** @class */ (function () {
124
149
  enumerable: false,
125
150
  configurable: true
126
151
  });
152
+ // Not a thin delegation: 3.2.0's public methods were async with the whole body
153
+ // in a try/catch, so even a call without a receiver (a destructured method)
154
+ // logged and resolved rather than throwing, and still does.
127
155
  AvoInspectorLite.prototype.trackSchemaFromEvent = function (eventName, eventProperties) {
128
156
  return __awaiter(this, void 0, void 0, function () {
129
- var eventSchema, e_1;
157
+ var e_1;
158
+ return __generator(this, function (_a) {
159
+ switch (_a.label) {
160
+ case 0:
161
+ _a.trys.push([0, 2, , 3]);
162
+ return [4 /*yield*/, this._trackSchemaFromEventWithOptions(eventName, eventProperties, undefined)];
163
+ case 1: return [2 /*return*/, _a.sent()];
164
+ case 2:
165
+ e_1 = _a.sent();
166
+ console.error("Avo Inspector: something went wrong. Please report to support@avo.app.", e_1);
167
+ return [2 /*return*/, []];
168
+ case 3: return [2 /*return*/];
169
+ }
170
+ });
171
+ });
172
+ };
173
+ // INTERNAL — not public API. `trackSchemaFromEvent` with the web GTM tag template's
174
+ // gateway options, mirroring the full build's internal method (the script-tag
175
+ // bootstrap uses the full build). Private and underscore-named like
176
+ // `_avoFunctionTrackSchemaFromEvent`, so it stays out of the typings (a line
177
+ // comment, not JSDoc, so none of this is emitted into the .d.ts either). The
178
+ // options have an effect only when the instance has a client (v2); without
179
+ // one they are ignored entirely.
180
+ AvoInspectorLite.prototype._trackSchemaFromEventWithOptions = function (eventName, eventProperties, options) {
181
+ return __awaiter(this, void 0, void 0, function () {
182
+ var eventSchema, e_2;
130
183
  return __generator(this, function (_a) {
131
184
  switch (_a.label) {
132
185
  case 0:
@@ -140,11 +193,11 @@ var AvoInspectorLite = /** @class */ (function () {
140
193
  return [4 /*yield*/, this.extractSchema(eventProperties, false)];
141
194
  case 1:
142
195
  eventSchema = _a.sent();
143
- this.trackSchemaInternal(eventName, eventSchema, null, null);
196
+ this.trackSchemaInternal(eventName, eventSchema, null, null, options);
144
197
  return [2 /*return*/, eventSchema];
145
198
  case 2:
146
- e_1 = _a.sent();
147
- console.error("Avo Inspector: something went wrong. Please report to support@avo.app.", e_1);
199
+ e_2 = _a.sent();
200
+ console.error("Avo Inspector: something went wrong. Please report to support@avo.app.", e_2);
148
201
  return [2 /*return*/, []];
149
202
  case 3: return [2 /*return*/];
150
203
  }
@@ -153,7 +206,7 @@ var AvoInspectorLite = /** @class */ (function () {
153
206
  };
154
207
  AvoInspectorLite.prototype._avoFunctionTrackSchemaFromEvent = function (eventName, eventProperties, eventId, eventHash) {
155
208
  return __awaiter(this, void 0, void 0, function () {
156
- var eventSchema, e_2;
209
+ var eventSchema, e_3;
157
210
  return __generator(this, function (_a) {
158
211
  switch (_a.label) {
159
212
  case 0:
@@ -170,8 +223,8 @@ var AvoInspectorLite = /** @class */ (function () {
170
223
  this.trackSchemaInternal(eventName, eventSchema, eventId, eventHash);
171
224
  return [2 /*return*/, eventSchema];
172
225
  case 2:
173
- e_2 = _a.sent();
174
- console.error("Avo Inspector: something went wrong. Please report to support@avo.app.", e_2);
226
+ e_3 = _a.sent();
227
+ console.error("Avo Inspector: something went wrong. Please report to support@avo.app.", e_3);
175
228
  return [2 /*return*/, []];
176
229
  case 3: return [2 /*return*/];
177
230
  }
@@ -179,6 +232,33 @@ var AvoInspectorLite = /** @class */ (function () {
179
232
  });
180
233
  };
181
234
  AvoInspectorLite.prototype.trackSchema = function (eventName, eventSchema) {
235
+ return __awaiter(this, void 0, void 0, function () {
236
+ var e_4;
237
+ return __generator(this, function (_a) {
238
+ switch (_a.label) {
239
+ case 0:
240
+ _a.trys.push([0, 2, , 3]);
241
+ return [4 /*yield*/, this._trackSchemaWithOptions(eventName, eventSchema, undefined)];
242
+ case 1:
243
+ _a.sent();
244
+ return [3 /*break*/, 3];
245
+ case 2:
246
+ e_4 = _a.sent();
247
+ console.error("Avo Inspector: something went wrong. Please report to support@avo.app.", e_4);
248
+ return [3 /*break*/, 3];
249
+ case 3: return [2 /*return*/];
250
+ }
251
+ });
252
+ });
253
+ };
254
+ // INTERNAL — not public API. `trackSchema` with the web GTM tag template's
255
+ // gateway options, mirroring the full build's internal method (the script-tag
256
+ // bootstrap uses the full build). Private and underscore-named like
257
+ // `_avoFunctionTrackSchemaFromEvent`, so it stays out of the typings (a line
258
+ // comment, not JSDoc, so none of this is emitted into the .d.ts either). The
259
+ // options have an effect only when the instance has a client (v2); without
260
+ // one they are ignored entirely.
261
+ AvoInspectorLite.prototype._trackSchemaWithOptions = function (eventName, eventSchema, options) {
182
262
  return __awaiter(this, void 0, void 0, function () {
183
263
  return __generator(this, function (_a) {
184
264
  try {
@@ -188,7 +268,7 @@ var AvoInspectorLite = /** @class */ (function () {
188
268
  " with schema " +
189
269
  JSON.stringify(eventSchema));
190
270
  }
191
- this.trackSchemaInternal(eventName, eventSchema, null, null);
271
+ this.trackSchemaInternal(eventName, eventSchema, null, null, options);
192
272
  }
193
273
  catch (e) {
194
274
  console.error("Avo Inspector: something went wrong. Please report to support@avo.app.", e);
@@ -197,9 +277,9 @@ var AvoInspectorLite = /** @class */ (function () {
197
277
  });
198
278
  });
199
279
  };
200
- AvoInspectorLite.prototype.trackSchemaInternal = function (eventName, eventSchema, eventId, eventHash) {
280
+ AvoInspectorLite.prototype.trackSchemaInternal = function (eventName, eventSchema, eventId, eventHash, options) {
201
281
  try {
202
- this.avoBatcher.handleTrackSchema(eventName, eventSchema, eventId, eventHash);
282
+ this.avoBatcher.handleTrackSchema(eventName, eventSchema, eventId, eventHash, undefined, options);
203
283
  }
204
284
  catch (e) {
205
285
  console.error("Avo Inspector: something went wrong. Please report to support@avo.app.", e);
@@ -210,7 +290,7 @@ var AvoInspectorLite = /** @class */ (function () {
210
290
  };
211
291
  AvoInspectorLite.prototype.extractSchema = function (eventProperties_1) {
212
292
  return __awaiter(this, arguments, void 0, function (eventProperties, shouldLogIfEnabled) {
213
- var e_3;
293
+ var e_5;
214
294
  if (shouldLogIfEnabled === void 0) { shouldLogIfEnabled = true; }
215
295
  return __generator(this, function (_a) {
216
296
  switch (_a.label) {
@@ -223,8 +303,8 @@ var AvoInspectorLite = /** @class */ (function () {
223
303
  return [4 /*yield*/, AvoSchemaParserLite_1.AvoSchemaParserLite.extractSchema(eventProperties)];
224
304
  case 1: return [2 /*return*/, _a.sent()];
225
305
  case 2:
226
- e_3 = _a.sent();
227
- console.error("Avo Inspector: something went wrong in extractSchema. Please report to support@avo.app.", e_3);
306
+ e_5 = _a.sent();
307
+ console.error("Avo Inspector: something went wrong in extractSchema. Please report to support@avo.app.", e_5);
228
308
  return [2 /*return*/, []];
229
309
  case 3: return [2 /*return*/];
230
310
  }
@@ -37,8 +37,44 @@ export interface BaseBody {
37
37
  export interface SessionStartedBody extends BaseBody {
38
38
  type: "sessionStarted";
39
39
  }
40
- export interface EventSchemaBody extends BaseBody {
40
+ /**
41
+ * INTERNAL — not part of the public API, and not exported from either entry
42
+ * point. Per-call gateway coordinates for the web GTM tag template, which passes
43
+ * them as a third argument to `window.inspector.trackSchemaFromEvent` in the
44
+ * script-tag build (see src/browser.js).
45
+ *
46
+ * They are sent as top-level siblings of `eventProperties` on the track body —
47
+ * never nested inside the schema, and never read from event data. Every value is
48
+ * trimmed; empty, whitespace-only and non-string values are treated as absent.
49
+ *
50
+ * They only apply on the v2 transport, i.e. when a client is configured.
51
+ * `POST /inspector/v2/track` decodes both hints and accepts a literal
52
+ * `appVersion: null` (stored as "unversioned"). Without a client the SDK is on
53
+ * `POST /inspector/v1/track` and the options are ignored entirely, `appVersion`
54
+ * included, so the body is exactly the one 3.2.0 built.
55
+ *
56
+ * Defined locally (not imported) in both AvoNetworkCallsHandler.ts and
57
+ * AvoNetworkCallsHandlerLite.ts to keep the lite-sync diff flat.
58
+ */
59
+ export interface TrackOptions {
60
+ /** Reference of the gateway output this observation was bound for. Omit for a gateway-level observation. */
61
+ outputReference?: string;
62
+ /** Low-cardinality hint identifying the event's upstream source (e.g. "web", "ios"). Never a user identifier. */
63
+ originHint?: string;
64
+ /** App version of the source that produced the event. With originHint set, replaces the SDK's configured version (literal null when omitted); without originHint, overrides it only when provided. */
65
+ appVersion?: string;
66
+ }
67
+ /** Events of a failed send that are worth queueing again; undefined means all of them. */
68
+ type RetryEvents = Array<SessionStartedBody | EventSchemaBody> | undefined;
69
+ export interface EventSchemaBody extends Omit<BaseBody, "appVersion"> {
41
70
  type: "event";
71
+ /**
72
+ * Nullable only here, and only on v2: with an originHint set and no per-event
73
+ * appVersion the event is source-scoped, so a literal null is sent rather than
74
+ * the SDK's configured version. Session-started bodies, and every v1 body,
75
+ * always carry the string version.
76
+ */
77
+ appVersion: string | null;
42
78
  /** ID of the base event from spec (null if no spec available) */
43
79
  eventId: string | null;
44
80
  /** Name seen in code */
@@ -48,6 +84,10 @@ export interface EventSchemaBody extends BaseBody {
48
84
  eventHash: string | null;
49
85
  /** Branch ID from getEventSpec response when value validation was performed */
50
86
  validatedBranchId?: string;
87
+ /** Gateway output this observation was bound for; absent = gateway checkpoint. v2 only. */
88
+ outputReference?: string;
89
+ /** Low-cardinality hint identifying the event's upstream source. v2 only. */
90
+ originHint?: string;
51
91
  }
52
92
  export declare class AvoNetworkCallsHandlerLite {
53
93
  private readonly apiKey;
@@ -55,14 +95,42 @@ export declare class AvoNetworkCallsHandlerLite {
55
95
  private readonly appName;
56
96
  private readonly appVersion;
57
97
  private readonly libVersion;
98
+ /**
99
+ * "gtm-web" for the web GTM tag template, otherwise undefined. It is the
100
+ * transport switch, decided once in the constructor: undefined keeps the v1
101
+ * request byte for byte as 3.2.0 sent it; "gtm-web" selects v2 and is the
102
+ * X-Avo-Client value.
103
+ */
104
+ private readonly client;
105
+ private readonly trackingEndpoint;
58
106
  private samplingRate;
59
107
  private sending;
60
- private static readonly trackingEndpoint;
61
- constructor(apiKey: string, envName: string, appName: string, appVersion: string, libVersion: string);
62
- callInspectorWithBatchBody(inEvents: Array<SessionStartedBody | EventSchemaBody>, onCompleted: (error: Error | null) => any): void;
108
+ /** v2 only: permanent failures in a row for this instance's own events. */
109
+ private permanentFailures;
110
+ /** v2 only: permanent failures in a row per other api key and env, keyed as the send groups are. */
111
+ private readonly foreignFailures;
112
+ /** v2 only: set at most once, when sending can no longer succeed on this page. */
113
+ private sendingDisabled;
114
+ /** v2 only: set when the events themselves can never be sent, so queueing them would only grow the stored queue. */
115
+ private queueingDisabled;
116
+ constructor(apiKey: string, envName: string, appName: string, appVersion: string, libVersion: string, client?: string);
117
+ /**
118
+ * v2 only: true once sending has stopped for this page (see
119
+ * maxConsecutivePermanentFailures). Always false on v1.
120
+ */
121
+ isSendingDisabled(): boolean;
122
+ /**
123
+ * v2 only: true when queueing events would only grow the stored queue, because
124
+ * they could never be sent under any configuration. Always false on v1.
125
+ */
126
+ isQueueingDisabled(): boolean;
127
+ private disableSending;
128
+ /** True while a batch sent through callInspectorWithBatchBody awaits its response. */
129
+ isBatchInFlight(): boolean;
130
+ callInspectorWithBatchBody(inEvents: Array<SessionStartedBody | EventSchemaBody>, onCompleted: (error: Error | null, retryEvents?: RetryEvents) => any): void;
63
131
  private fixStreamIds;
64
132
  bodyForSessionStartedCall(): SessionStartedBody;
65
- bodyForEventSchemaCall(eventName: string, eventProperties: EventProperty[], eventId: string | null, eventHash: string | null, eventSpecMetadata?: EventSpecMetadata, validatedBranchId?: string): EventSchemaBody;
133
+ bodyForEventSchemaCall(eventName: string, eventProperties: EventProperty[], eventId: string | null, eventHash: string | null, eventSpecMetadata?: EventSpecMetadata, validatedBranchId?: string, options?: TrackOptions): EventSchemaBody;
66
134
  private createBaseCallBody;
67
135
  /**
68
136
  * Calls Inspector API immediately with a single event (bypasses batching).
@@ -83,6 +151,12 @@ export declare class AvoNetworkCallsHandlerLite {
83
151
  * synchronously in the unavailable case, so legacy timing is preserved.
84
152
  */
85
153
  private callInspectorApi;
154
+ private sendEvents;
155
+ /**
156
+ * Reports a failure as permanent (second argument true) when retrying the same
157
+ * request cannot succeed: the browser refused to build it, or the API answered
158
+ * a 4xx other than 408 and 429.
159
+ */
86
160
  private sendTrackingRequest;
87
161
  }
88
162
  export { AvoNetworkCallsHandlerLite as AvoNetworkCallsHandler };