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,203 +0,0 @@
1
- /**
2
- * This file is generated. Internal development changes should be made in the generator
3
- * and the file should be re-generated. External contributions are welcome to submit
4
- * changes directly to this file, and we'll apply them to the generator internally.
5
- */
6
- /**
7
- * EventSpecFetcher handles fetching event specifications from the Avo API.
8
- *
9
- * Endpoint: GET /trackingPlan/eventSpec
10
- * Base URL: https://api.avo.app
11
- */
12
- export class AvoEventSpecFetcher {
13
- constructor(timeout = 2000, shouldLog = false, env, baseUrl = "https://api.avo.app") {
14
- this.baseUrl = baseUrl;
15
- this.timeout = timeout;
16
- this.shouldLog = shouldLog;
17
- this.env = env;
18
- this.inFlightRequests = new Map();
19
- }
20
- /** Generates a unique key for tracking in-flight requests. */
21
- generateRequestKey(params) {
22
- return `${params.streamId}:${params.eventName}`;
23
- }
24
- /**
25
- * Fetches an event specification from the API.
26
- *
27
- * Returns null if:
28
- * - The network request fails
29
- * - The response has an invalid status code (non-200)
30
- * - The response is invalid or malformed
31
- * - The request times out
32
- *
33
- * This method gracefully degrades - failures do not throw errors.
34
- * When null is returned, Phase 2 should skip validation for that event.
35
- */
36
- async fetch(params) {
37
- const requestKey = this.generateRequestKey(params);
38
- // Check if there's already an in-flight request for this spec
39
- const existingRequest = this.inFlightRequests.get(requestKey);
40
- if (existingRequest) {
41
- return existingRequest;
42
- }
43
- // Create and track the new request
44
- const requestPromise = this.fetchInternal(params);
45
- this.inFlightRequests.set(requestKey, requestPromise);
46
- try {
47
- const result = await requestPromise;
48
- return result;
49
- }
50
- finally {
51
- // Clean up the in-flight request tracking
52
- this.inFlightRequests.delete(requestKey);
53
- }
54
- }
55
- /** Internal fetch implementation. */
56
- async fetchInternal(params) {
57
- if (!(this.env === "dev" || this.env === "staging")) {
58
- return null;
59
- }
60
- const url = this.buildUrl(params);
61
- try {
62
- const wireResponse = await this.makeRequest(url);
63
- if (!wireResponse) {
64
- if (this.shouldLog) {
65
- console.warn(`[Avo Inspector] Failed to fetch event spec for: ${params.eventName}`);
66
- }
67
- return null;
68
- }
69
- // Basic structure check for wire format
70
- if (!this.hasExpectedShape(wireResponse)) {
71
- if (this.shouldLog) {
72
- console.warn(`[Avo Inspector] Invalid event spec response for: ${params.eventName}`);
73
- }
74
- return null;
75
- }
76
- // Parse wire format to internal format
77
- const response = AvoEventSpecFetcher.parseEventSpecResponse(wireResponse);
78
- return response;
79
- }
80
- catch (error) {
81
- if (this.shouldLog) {
82
- console.error(`[Avo Inspector] Error fetching event spec for: ${params.eventName}`, error);
83
- }
84
- return null;
85
- }
86
- }
87
- /** Builds the complete URL with query parameters. */
88
- buildUrl(params) {
89
- const queryParams = new URLSearchParams({
90
- apiKey: params.apiKey,
91
- streamId: params.streamId,
92
- eventName: params.eventName,
93
- });
94
- return `${this.baseUrl}/trackingPlan/eventSpec?${queryParams.toString()}`;
95
- }
96
- /**
97
- * Makes an HTTP GET request using XMLHttpRequest.
98
- * Returns the parsed JSON response or null on failure.
99
- */
100
- makeRequest(url) {
101
- return new Promise((resolve) => {
102
- const xhr = new XMLHttpRequest();
103
- xhr.open("GET", url, true);
104
- xhr.timeout = this.timeout;
105
- xhr.onload = () => {
106
- if (xhr.status === 200) {
107
- try {
108
- const response = JSON.parse(xhr.responseText);
109
- resolve(response);
110
- }
111
- catch (error) {
112
- if (this.shouldLog) {
113
- console.error("[Avo Inspector] Failed to parse response:", error);
114
- }
115
- resolve(null);
116
- }
117
- }
118
- else {
119
- if (this.shouldLog) {
120
- console.warn(`[Avo Inspector] Request failed with status: ${xhr.status}`);
121
- }
122
- resolve(null);
123
- }
124
- };
125
- xhr.onerror = () => {
126
- if (this.shouldLog) {
127
- console.error("[Avo Inspector] Network error occurred");
128
- }
129
- resolve(null);
130
- };
131
- xhr.ontimeout = () => {
132
- if (this.shouldLog) {
133
- console.error(`[Avo Inspector] Request timed out after ${this.timeout}ms`);
134
- }
135
- resolve(null);
136
- };
137
- xhr.send();
138
- });
139
- }
140
- /**
141
- * Basic shape check for wire format - ensures response has the minimum expected structure.
142
- * Uses short field names from wire format.
143
- */
144
- hasExpectedShape(response) {
145
- return (response &&
146
- typeof response === "object" &&
147
- Array.isArray(response.events) &&
148
- response.metadata &&
149
- typeof response.metadata === "object" &&
150
- typeof response.metadata.schemaId === "string" &&
151
- typeof response.metadata.branchId === "string" &&
152
- typeof response.metadata.latestActionId === "string");
153
- }
154
- /** Parses the wire format response into internal format with meaningful field names. */
155
- static parseEventSpecResponse(wire) {
156
- return {
157
- events: wire.events.map(AvoEventSpecFetcher.parseEventSpecEntry),
158
- metadata: wire.metadata,
159
- };
160
- }
161
- /** Parses a single event spec entry from wire format. */
162
- static parseEventSpecEntry(wire) {
163
- const props = {};
164
- for (const entry of Object.entries(wire.p)) {
165
- const propName = Reflect.get(entry, "0");
166
- const propWire = Reflect.get(entry, "1");
167
- Reflect.set(props, propName, AvoEventSpecFetcher.parsePropertyConstraints(propWire));
168
- }
169
- return {
170
- branchId: wire.b,
171
- baseEventId: wire.id,
172
- variantIds: wire.vids,
173
- props: props,
174
- };
175
- }
176
- /** Parses property constraints from wire format. */
177
- static parsePropertyConstraints(wire) {
178
- const result = { type: wire.t, required: wire.r };
179
- if (wire.l) {
180
- result.isList = wire.l;
181
- }
182
- if (wire.p) {
183
- result.pinnedValues = wire.p;
184
- }
185
- if (wire.v) {
186
- result.allowedValues = wire.v;
187
- }
188
- if (wire.rx) {
189
- result.regexPatterns = wire.rx;
190
- }
191
- if (wire.minmax) {
192
- result.minMaxRanges = wire.minmax;
193
- }
194
- if (wire.children) {
195
- result.children = {};
196
- for (const [propName, childWire] of Object.entries(wire.children)) {
197
- result.children[propName] =
198
- AvoEventSpecFetcher.parsePropertyConstraints(childWire);
199
- }
200
- }
201
- return result;
202
- }
203
- }