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
package/dist/esm/utils.js DELETED
@@ -1,38 +0,0 @@
1
- const isValueEmpty = (value) => {
2
- return value === null || value === undefined || value.trim().length == 0;
3
- };
4
- function deepEquals(x, y) {
5
- if (x === y) {
6
- return true;
7
- }
8
- if (!(x instanceof Object) || !(y instanceof Object)) {
9
- return false;
10
- }
11
- if (x.constructor !== y.constructor) {
12
- return false;
13
- }
14
- for (var p in x) {
15
- if (!x.hasOwnProperty(p)) {
16
- continue;
17
- }
18
- if (!y.hasOwnProperty(p)) {
19
- return false;
20
- }
21
- if (x[p] === y[p]) {
22
- continue;
23
- }
24
- if (typeof x[p] !== "object") {
25
- return false;
26
- }
27
- if (!deepEquals(x[p], y[p])) {
28
- return false;
29
- }
30
- }
31
- for (p in y) {
32
- if (y.hasOwnProperty(p) && !x.hasOwnProperty(p)) {
33
- return false;
34
- }
35
- }
36
- return true;
37
- }
38
- export { isValueEmpty, deepEquals };
@@ -1,2 +0,0 @@
1
- // Auto-generated by build script. Do not edit manually.
2
- export const LIB_VERSION = "3.0.1";
@@ -1,181 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EventSpecCache = void 0;
4
- /**
5
- * EventSpecCache implements a dual-condition cache with LRU eviction.
6
- *
7
- * Cache Policy:
8
- * - TTL: Entries expire after 60 seconds
9
- * - Per-entry eviction: Entries retrieved 50+ times evicted immediately on next get
10
- * - Global sweep: Runs every 50 cache operations (get/set)
11
- * - Capacity: LRU eviction when size > 50 entries
12
- * - Null spec responses: cached (to avoid re-fetching)
13
- * - branchId flush: cache cleared when branchId changes (handled externally)
14
- *
15
- * Cache Key Format: ${apiKey}:${streamId}:${eventName}
16
- */
17
- var EventSpecCache = /** @class */ (function () {
18
- function EventSpecCache(shouldLog) {
19
- if (shouldLog === void 0) { shouldLog = false; }
20
- /** Time-to-live in milliseconds (60 seconds) */
21
- this.TTL_MS = 60 * 1000;
22
- /** Maximum cache hit count before per-entry eviction (50 hits) */
23
- this.MAX_EVENT_COUNT = 50;
24
- /** Maximum number of cache entries */
25
- this.MAX_ENTRIES = 50;
26
- /** Global cache operation counter to track when to sweep */
27
- this.globalEventCount = 0;
28
- this.cache = new Map();
29
- this.shouldLog = shouldLog;
30
- }
31
- /**
32
- * Generates a cache key from the provided parameters.
33
- */
34
- EventSpecCache.prototype.generateKey = function (apiKey, streamId, eventName) {
35
- return "".concat(apiKey, ":").concat(streamId, ":").concat(eventName);
36
- };
37
- /**
38
- * Retrieves an event spec response from the cache if it exists and is valid.
39
- * Returns undefined (cache miss) if the entry is missing.
40
- * Returns null if a null spec was cached (known absent).
41
- * Returns the spec if valid.
42
- *
43
- * On cache hit, increments the hit count for this entry and the global counter.
44
- */
45
- EventSpecCache.prototype.get = function (apiKey, streamId, eventName) {
46
- var key = this.generateKey(apiKey, streamId, eventName);
47
- var entry = this.cache.get(key);
48
- if (!entry) {
49
- return undefined;
50
- }
51
- // Check if entry has expired by TTL
52
- if (this.isExpiredByTTL(entry)) {
53
- this.cache.delete(key);
54
- return undefined;
55
- }
56
- // Check per-entry eviction (50+ accesses)
57
- if (entry.eventCount >= this.MAX_EVENT_COUNT) {
58
- this.cache.delete(key);
59
- return undefined;
60
- }
61
- if (this.shouldLog) {
62
- console.log("[Avo Inspector] Cache hit for key: ".concat(key));
63
- }
64
- // Update lastAccessed for LRU eviction
65
- entry.lastAccessed = Date.now();
66
- // Increment hit count for this entry
67
- entry.eventCount++;
68
- this.globalEventCount++;
69
- // Global sweep every 50 operations
70
- if (this.globalEventCount >= this.MAX_EVENT_COUNT) {
71
- this.sweep();
72
- this.globalEventCount = 0;
73
- }
74
- return entry.spec;
75
- };
76
- /**
77
- * Stores an event spec response in the cache.
78
- * Null responses are cached to prevent re-fetching for known absent specs.
79
- */
80
- EventSpecCache.prototype.set = function (apiKey, streamId, eventName, spec) {
81
- var key = this.generateKey(apiKey, streamId, eventName);
82
- // Enforce capacity limit with LRU eviction
83
- if (!this.cache.has(key) && this.cache.size >= this.MAX_ENTRIES) {
84
- this.evictLRU();
85
- }
86
- var now = Date.now();
87
- var entry = {
88
- spec: spec,
89
- timestamp: now,
90
- lastAccessed: now,
91
- eventCount: 0
92
- };
93
- this.cache.set(key, entry);
94
- this.globalEventCount++;
95
- // Global sweep every 50 operations
96
- if (this.globalEventCount >= this.MAX_EVENT_COUNT) {
97
- this.sweep();
98
- this.globalEventCount = 0;
99
- }
100
- };
101
- /**
102
- * Checks if a cache entry has expired by TTL (older than 60s).
103
- */
104
- EventSpecCache.prototype.isExpiredByTTL = function (entry) {
105
- var age = Date.now() - entry.timestamp;
106
- return age > this.TTL_MS;
107
- };
108
- /**
109
- * Sweeps the cache: removes all entries expired by TTL.
110
- */
111
- EventSpecCache.prototype.sweep = function () {
112
- var _this = this;
113
- var keysToDelete = [];
114
- this.cache.forEach(function (entry, key) {
115
- if (_this.isExpiredByTTL(entry)) {
116
- keysToDelete.push(key);
117
- }
118
- });
119
- for (var _i = 0, keysToDelete_1 = keysToDelete; _i < keysToDelete_1.length; _i++) {
120
- var key = keysToDelete_1[_i];
121
- this.cache.delete(key);
122
- }
123
- };
124
- /**
125
- * Evicts the least recently used cache entry based on lastAccessed timestamp.
126
- */
127
- EventSpecCache.prototype.evictLRU = function () {
128
- if (this.cache.size === 0) {
129
- return;
130
- }
131
- var lruKey = null;
132
- var oldestAccessTime = Infinity;
133
- this.cache.forEach(function (entry, key) {
134
- if (entry.lastAccessed < oldestAccessTime) {
135
- oldestAccessTime = entry.lastAccessed;
136
- lruKey = key;
137
- }
138
- });
139
- if (lruKey !== null) {
140
- this.cache.delete(lruKey);
141
- }
142
- };
143
- /**
144
- * Clears all cached entries.
145
- */
146
- EventSpecCache.prototype.clear = function () {
147
- this.cache.clear();
148
- this.globalEventCount = 0;
149
- if (this.shouldLog) {
150
- console.log("[Avo Inspector] Cache cleared");
151
- }
152
- };
153
- /**
154
- * Returns the current size of the cache.
155
- */
156
- EventSpecCache.prototype.size = function () {
157
- return this.cache.size;
158
- };
159
- /**
160
- * Returns cache statistics for debugging.
161
- */
162
- EventSpecCache.prototype.getStats = function () {
163
- var entries = [];
164
- var now = Date.now();
165
- this.cache.forEach(function (entry, key) {
166
- entries.push({
167
- key: key,
168
- age: now - entry.timestamp,
169
- lastAccessedAgo: now - entry.lastAccessed,
170
- eventCount: entry.eventCount
171
- });
172
- });
173
- return {
174
- size: this.cache.size,
175
- globalEventCount: this.globalEventCount,
176
- entries: entries
177
- };
178
- };
179
- return EventSpecCache;
180
- }());
181
- exports.EventSpecCache = EventSpecCache;
@@ -1,290 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.AvoEventSpecFetcher = void 0;
40
- /**
41
- * EventSpecFetcher handles fetching event specifications from the Avo API.
42
- *
43
- * Endpoint: GET /trackingPlan/eventSpec
44
- * Base URL: https://api.avo.app
45
- *
46
- * Adapted for React Native: uses global fetch instead of XMLHttpRequest.
47
- */
48
- var AvoEventSpecFetcher = /** @class */ (function () {
49
- function AvoEventSpecFetcher(timeout, shouldLog, env, baseUrl) {
50
- if (timeout === void 0) { timeout = 2000; }
51
- if (shouldLog === void 0) { shouldLog = false; }
52
- if (baseUrl === void 0) { baseUrl = "https://api.avo.app"; }
53
- this.baseUrl = baseUrl;
54
- this.timeout = timeout;
55
- this.shouldLog = shouldLog;
56
- this.env = env;
57
- this.inFlightRequests = new Map();
58
- }
59
- /** Generates a unique key for tracking in-flight requests. */
60
- AvoEventSpecFetcher.prototype.generateRequestKey = function (params) {
61
- return "".concat(params.apiKey, ":").concat(params.streamId, ":").concat(params.eventName);
62
- };
63
- /**
64
- * Fetches an event specification from the API.
65
- *
66
- * Returns null if:
67
- * - The network request fails
68
- * - The response has an invalid status code (non-200)
69
- * - The response is invalid or malformed
70
- * - The request times out
71
- *
72
- * This method gracefully degrades - failures do not throw errors.
73
- * When null is returned, validation is skipped for that event.
74
- *
75
- * In-flight de-duplication: concurrent requests for the same key
76
- * share a single fetch promise. On failure, all waiters receive null.
77
- */
78
- AvoEventSpecFetcher.prototype.fetch = function (params) {
79
- return __awaiter(this, void 0, void 0, function () {
80
- var requestKey, existingRequest, requestPromise, result;
81
- return __generator(this, function (_a) {
82
- switch (_a.label) {
83
- case 0:
84
- requestKey = this.generateRequestKey(params);
85
- existingRequest = this.inFlightRequests.get(requestKey);
86
- if (existingRequest) {
87
- return [2 /*return*/, existingRequest];
88
- }
89
- requestPromise = this.fetchInternal(params);
90
- this.inFlightRequests.set(requestKey, requestPromise);
91
- _a.label = 1;
92
- case 1:
93
- _a.trys.push([1, , 3, 4]);
94
- return [4 /*yield*/, requestPromise];
95
- case 2:
96
- result = _a.sent();
97
- return [2 /*return*/, result];
98
- case 3:
99
- // Clean up the in-flight request tracking
100
- this.inFlightRequests.delete(requestKey);
101
- return [7 /*endfinally*/];
102
- case 4: return [2 /*return*/];
103
- }
104
- });
105
- });
106
- };
107
- /** Internal fetch implementation. */
108
- AvoEventSpecFetcher.prototype.fetchInternal = function (params) {
109
- return __awaiter(this, void 0, void 0, function () {
110
- var url, wireResponse, response, error_1;
111
- return __generator(this, function (_a) {
112
- switch (_a.label) {
113
- case 0:
114
- // Defensive: AvoEventSpecFetcher is only constructed for dev/staging in AvoInspector,
115
- // so this guard should never be reached in practice.
116
- if (!(this.env === "dev" || this.env === "staging")) {
117
- return [2 /*return*/, null];
118
- }
119
- url = this.buildUrl(params);
120
- _a.label = 1;
121
- case 1:
122
- _a.trys.push([1, 3, , 4]);
123
- return [4 /*yield*/, this.makeRequest(url)];
124
- case 2:
125
- wireResponse = _a.sent();
126
- if (!wireResponse) {
127
- if (this.shouldLog) {
128
- console.warn("[Avo Inspector] Failed to fetch event spec for: ".concat(params.eventName));
129
- }
130
- return [2 /*return*/, null];
131
- }
132
- // Basic structure check for wire format
133
- if (!this.hasExpectedShape(wireResponse)) {
134
- if (this.shouldLog) {
135
- console.warn("[Avo Inspector] Invalid event spec response for: ".concat(params.eventName));
136
- }
137
- return [2 /*return*/, null];
138
- }
139
- response = AvoEventSpecFetcher.parseEventSpecResponse(wireResponse);
140
- return [2 /*return*/, response];
141
- case 3:
142
- error_1 = _a.sent();
143
- if (this.shouldLog) {
144
- console.error("[Avo Inspector] Error fetching event spec for: ".concat(params.eventName), error_1);
145
- }
146
- return [2 /*return*/, null];
147
- case 4: return [2 /*return*/];
148
- }
149
- });
150
- });
151
- };
152
- /** Builds the complete URL with query parameters. */
153
- AvoEventSpecFetcher.prototype.buildUrl = function (params) {
154
- var queryParams = new URLSearchParams({
155
- apiKey: params.apiKey,
156
- streamId: params.streamId,
157
- eventName: params.eventName,
158
- });
159
- return "".concat(this.baseUrl, "/trackingPlan/eventSpec?").concat(queryParams.toString());
160
- };
161
- /**
162
- * Makes an HTTP GET request using global fetch (available in React Native).
163
- * Returns the parsed JSON response or null on failure.
164
- */
165
- AvoEventSpecFetcher.prototype.makeRequest = function (url) {
166
- return __awaiter(this, void 0, void 0, function () {
167
- var controller, timeoutId, response, json, parseError_1, error_2;
168
- return __generator(this, function (_a) {
169
- switch (_a.label) {
170
- case 0:
171
- controller = new AbortController();
172
- timeoutId = setTimeout(function () { return controller.abort(); }, this.timeout);
173
- _a.label = 1;
174
- case 1:
175
- _a.trys.push([1, 7, , 8]);
176
- return [4 /*yield*/, fetch(url, {
177
- method: "GET",
178
- signal: controller.signal,
179
- })];
180
- case 2:
181
- response = _a.sent();
182
- clearTimeout(timeoutId);
183
- if (response.status !== 200) {
184
- if (this.shouldLog) {
185
- console.warn("[Avo Inspector] Request failed with status: ".concat(response.status));
186
- }
187
- return [2 /*return*/, null];
188
- }
189
- _a.label = 3;
190
- case 3:
191
- _a.trys.push([3, 5, , 6]);
192
- return [4 /*yield*/, response.json()];
193
- case 4:
194
- json = _a.sent();
195
- return [2 /*return*/, json];
196
- case 5:
197
- parseError_1 = _a.sent();
198
- if (this.shouldLog) {
199
- console.error("[Avo Inspector] Failed to parse response:", parseError_1);
200
- }
201
- return [2 /*return*/, null];
202
- case 6: return [3 /*break*/, 8];
203
- case 7:
204
- error_2 = _a.sent();
205
- clearTimeout(timeoutId);
206
- if (error_2 && error_2.name === "AbortError") {
207
- if (this.shouldLog) {
208
- console.error("[Avo Inspector] Request timed out after ".concat(this.timeout, "ms"));
209
- }
210
- }
211
- else {
212
- if (this.shouldLog) {
213
- console.error("[Avo Inspector] Network error occurred");
214
- }
215
- }
216
- return [2 /*return*/, null];
217
- case 8: return [2 /*return*/];
218
- }
219
- });
220
- });
221
- };
222
- /**
223
- * Basic shape check for wire format - ensures response has the minimum expected structure.
224
- * Uses short field names from wire format.
225
- */
226
- AvoEventSpecFetcher.prototype.hasExpectedShape = function (response) {
227
- return (response &&
228
- typeof response === "object" &&
229
- Array.isArray(response.events) &&
230
- response.metadata &&
231
- typeof response.metadata === "object" &&
232
- typeof response.metadata.schemaId === "string" &&
233
- typeof response.metadata.branchId === "string" &&
234
- typeof response.metadata.latestActionId === "string");
235
- };
236
- /** Parses the wire format response into internal format with meaningful field names. */
237
- AvoEventSpecFetcher.parseEventSpecResponse = function (wire) {
238
- return {
239
- events: wire.events.map(AvoEventSpecFetcher.parseEventSpecEntry),
240
- metadata: wire.metadata,
241
- };
242
- };
243
- /** Parses a single event spec entry from wire format. */
244
- AvoEventSpecFetcher.parseEventSpecEntry = function (wire) {
245
- var props = {};
246
- var wireProps = wire.p || {};
247
- for (var _i = 0, _a = Object.entries(wireProps); _i < _a.length; _i++) {
248
- var entry = _a[_i];
249
- var propName = entry[0];
250
- var propWire = entry[1];
251
- props[propName] = AvoEventSpecFetcher.parsePropertyConstraints(propWire);
252
- }
253
- return {
254
- branchId: wire.b,
255
- baseEventId: wire.id,
256
- variantIds: wire.vids,
257
- props: props,
258
- };
259
- };
260
- /** Parses property constraints from wire format. */
261
- AvoEventSpecFetcher.parsePropertyConstraints = function (wire) {
262
- var result = { type: wire.t, required: wire.r };
263
- if (wire.l) {
264
- result.isList = wire.l;
265
- }
266
- if (wire.p) {
267
- result.pinnedValues = wire.p;
268
- }
269
- if (wire.v) {
270
- result.allowedValues = wire.v;
271
- }
272
- if (wire.rx) {
273
- result.regexPatterns = wire.rx;
274
- }
275
- if (wire.minmax) {
276
- result.minMaxRanges = wire.minmax;
277
- }
278
- if (wire.children) {
279
- result.children = {};
280
- for (var _i = 0, _a = Object.entries(wire.children); _i < _a.length; _i++) {
281
- var _b = _a[_i], propName = _b[0], childWire = _b[1];
282
- result.children[propName] =
283
- AvoEventSpecFetcher.parsePropertyConstraints(childWire);
284
- }
285
- }
286
- return result;
287
- };
288
- return AvoEventSpecFetcher;
289
- }());
290
- exports.AvoEventSpecFetcher = AvoEventSpecFetcher;