avo-inspector 3.2.0 → 3.2.3-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/dist/AvoBatcher.d.ts +9 -3
- package/dist/AvoInspector.d.ts +4 -0
- package/dist/AvoNetworkCallsHandler.d.ts +80 -5
- package/dist/__tests__/ApiKeyHeaderInjection_test.d.ts +1 -0
- package/dist/__tests__/BrowserBootstrap_test.d.ts +1 -0
- package/dist/__tests__/EnableLoggingLite_test.d.ts +1 -0
- package/dist/__tests__/EnableLogging_test.d.ts +1 -0
- package/dist/__tests__/EventSpecGatewayCoordinates_test.d.ts +1 -0
- package/dist/__tests__/InFlightQueueGaps_test.d.ts +1 -0
- package/dist/__tests__/InFlightQueue_test.d.ts +1 -0
- package/dist/__tests__/NetworkCallsHandlerLite_test.d.ts +1 -0
- package/dist/__tests__/PublicSurface_test.d.ts +1 -0
- package/dist/__tests__/TrackOptionsIntegration_test.d.ts +1 -0
- package/dist/__tests__/TrackOptionsTransport_test.d.ts +1 -0
- package/dist/__tests__/TrackingHeaders_test.d.ts +1 -0
- package/dist/__tests__/UnboundPublicMethods_test.d.ts +1 -0
- package/dist/__tests__/V1WireBaseline_test.d.ts +1 -0
- package/dist/__tests__/V2QueuedAttribution_test.d.ts +1 -0
- package/dist/__tests__/V2StopSending_test.d.ts +1 -0
- package/dist/__tests__/constants.d.ts +2 -1
- package/dist/__tests__/helpers/internalGateway.d.ts +23 -0
- package/dist/browser.js +2 -0
- package/dist/eventSpec/AvoEventSpecCache.d.ts +7 -4
- package/dist/eventSpec/AvoEventSpecFetchTypes.d.ts +12 -1
- package/dist/eventSpec/AvoEventSpecFetcher.d.ts +6 -1
- package/dist/index.js +1 -1
- package/dist/lite/AvoBatcherLite.d.ts +9 -3
- package/dist/lite/AvoBatcherLite.js +46 -7
- package/dist/lite/AvoInspectorLite.d.ts +2 -0
- package/dist/lite/AvoInspectorLite.js +95 -15
- package/dist/lite/AvoNetworkCallsHandlerLite.d.ts +79 -5
- package/dist/lite/AvoNetworkCallsHandlerLite.js +300 -20
- package/package.json +10 -1
package/README.md
CHANGED
|
@@ -269,10 +269,20 @@ inspector.setBatchFlushSeconds(10);
|
|
|
269
269
|
|
|
270
270
|
You can control the network timeout for the SDK. Default is 2 seconds.
|
|
271
271
|
|
|
272
|
+
In dev and staging, every send waits at least 10 seconds, or `networkTimeout` if it is longer (0, no timeout, is kept). That includes an event that has an event spec, which is validated and sent on its own, right away. Production sends use `networkTimeout`.
|
|
273
|
+
|
|
272
274
|
```javascript
|
|
273
275
|
Inspector.AvoInspector.networkTimeout = 5000;
|
|
274
276
|
```
|
|
275
277
|
|
|
278
|
+
# Maintainers: web GTM template support is internal
|
|
279
|
+
|
|
280
|
+
The Avo web GTM tag template reaches features that are not part of this SDK's public API: the
|
|
281
|
+
`/inspector/v2/track` transport and per-event gateway fields. They are reachable only through the
|
|
282
|
+
script-tag build, when `window.inspector.__CLIENT__` is `"gtm-web"`. Everything else — npm full,
|
|
283
|
+
npm lite and a regular script tag — sends to `/inspector/v1/track` exactly as 3.2.0 did. See
|
|
284
|
+
`src/browser.js` and `src/AvoNetworkCallsHandler.cs.md`. Don't document these for SDK users.
|
|
285
|
+
|
|
276
286
|
## Author
|
|
277
287
|
|
|
278
288
|
Avo (https://www.avo.app), friends@avo.app
|
package/dist/AvoBatcher.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type AvoNetworkCallsHandler, type EventProperty } from "./AvoNetworkCallsHandler";
|
|
1
|
+
import { type EventSchemaBody, type AvoNetworkCallsHandler, type EventProperty, type TrackOptions } from "./AvoNetworkCallsHandler";
|
|
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;
|
package/dist/AvoInspector.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export declare class AvoInspector {
|
|
|
15
15
|
private eventSpecCache?;
|
|
16
16
|
private eventSpecFetcher?;
|
|
17
17
|
private currentBranchId;
|
|
18
|
+
private readonly hasGatewayClient;
|
|
18
19
|
static avoStorage: AvoStorage;
|
|
19
20
|
private static _batchSize;
|
|
20
21
|
static get batchSize(): number;
|
|
@@ -36,6 +37,7 @@ export declare class AvoInspector {
|
|
|
36
37
|
publicEncryptionKey?: string;
|
|
37
38
|
});
|
|
38
39
|
trackSchemaFromEvent(eventName: string, eventProperties: Record<string, any>): Promise<EventProperty[]>;
|
|
40
|
+
private _trackSchemaFromEventWithOptions;
|
|
39
41
|
private _avoFunctionTrackSchemaFromEvent;
|
|
40
42
|
trackSchema(eventName: string, eventSchema: Array<{
|
|
41
43
|
propertyName: string;
|
|
@@ -43,6 +45,7 @@ export declare class AvoInspector {
|
|
|
43
45
|
encryptedPropertyValue?: string;
|
|
44
46
|
children?: any;
|
|
45
47
|
}>): Promise<void>;
|
|
48
|
+
private _trackSchemaWithOptions;
|
|
46
49
|
private trackSchemaInternal;
|
|
47
50
|
enableLogging(enable: boolean): void;
|
|
48
51
|
extractSchema(eventProperties: Record<string, any>, shouldLogIfEnabled?: boolean): Promise<Array<{
|
|
@@ -53,6 +56,7 @@ export declare class AvoInspector {
|
|
|
53
56
|
}>>;
|
|
54
57
|
setBatchSize(newBatchSize: number): void;
|
|
55
58
|
setBatchFlushSeconds(newBatchFlushSeconds: number): void;
|
|
59
|
+
private specCoordinates;
|
|
56
60
|
/**
|
|
57
61
|
* Handles branch change detection and cache storage for a fetched event spec.
|
|
58
62
|
* This logic is shared between fetchEventSpecIfNeeded and fetchAndValidateEvent.
|
|
@@ -39,8 +39,44 @@ export interface BaseBody {
|
|
|
39
39
|
export interface SessionStartedBody extends BaseBody {
|
|
40
40
|
type: "sessionStarted";
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
/**
|
|
43
|
+
* INTERNAL — not part of the public API, and not exported from either entry
|
|
44
|
+
* point. Per-call gateway coordinates for the web GTM tag template, which passes
|
|
45
|
+
* them as a third argument to `window.inspector.trackSchemaFromEvent` in the
|
|
46
|
+
* script-tag build (see src/browser.js).
|
|
47
|
+
*
|
|
48
|
+
* They are sent as top-level siblings of `eventProperties` on the track body —
|
|
49
|
+
* never nested inside the schema, and never read from event data. Every value is
|
|
50
|
+
* trimmed; empty, whitespace-only and non-string values are treated as absent.
|
|
51
|
+
*
|
|
52
|
+
* They only apply on the v2 transport, i.e. when a client is configured.
|
|
53
|
+
* `POST /inspector/v2/track` decodes both hints and accepts a literal
|
|
54
|
+
* `appVersion: null` (stored as "unversioned"). Without a client the SDK is on
|
|
55
|
+
* `POST /inspector/v1/track` and the options are ignored entirely, `appVersion`
|
|
56
|
+
* included, so the body is exactly the one 3.2.0 built.
|
|
57
|
+
*
|
|
58
|
+
* Defined locally (not imported) in both AvoNetworkCallsHandler.ts and
|
|
59
|
+
* AvoNetworkCallsHandlerLite.ts to keep the lite-sync diff flat.
|
|
60
|
+
*/
|
|
61
|
+
export interface TrackOptions {
|
|
62
|
+
/** Reference of the gateway output this observation was bound for. Omit for a gateway-level observation. */
|
|
63
|
+
outputReference?: string;
|
|
64
|
+
/** Low-cardinality hint identifying the event's upstream source (e.g. "web", "ios"). Never a user identifier. */
|
|
65
|
+
originHint?: string;
|
|
66
|
+
/** 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. */
|
|
67
|
+
appVersion?: string;
|
|
68
|
+
}
|
|
69
|
+
/** Events of a failed send that are worth queueing again; undefined means all of them. */
|
|
70
|
+
type RetryEvents = Array<SessionStartedBody | EventSchemaBody> | undefined;
|
|
71
|
+
export interface EventSchemaBody extends Omit<BaseBody, "appVersion"> {
|
|
43
72
|
type: "event";
|
|
73
|
+
/**
|
|
74
|
+
* Nullable only here, and only on v2: with an originHint set and no per-event
|
|
75
|
+
* appVersion the event is source-scoped, so a literal null is sent rather than
|
|
76
|
+
* the SDK's configured version. Session-started bodies, and every v1 body,
|
|
77
|
+
* always carry the string version.
|
|
78
|
+
*/
|
|
79
|
+
appVersion: string | null;
|
|
44
80
|
/** ID of the base event from spec (null if no spec available) */
|
|
45
81
|
eventId: string | null;
|
|
46
82
|
/** Name seen in code */
|
|
@@ -50,6 +86,10 @@ export interface EventSchemaBody extends BaseBody {
|
|
|
50
86
|
eventHash: string | null;
|
|
51
87
|
/** Branch ID from getEventSpec response when value validation was performed */
|
|
52
88
|
validatedBranchId?: string;
|
|
89
|
+
/** Gateway output this observation was bound for; absent = gateway checkpoint. v2 only. */
|
|
90
|
+
outputReference?: string;
|
|
91
|
+
/** Low-cardinality hint identifying the event's upstream source. v2 only. */
|
|
92
|
+
originHint?: string;
|
|
53
93
|
}
|
|
54
94
|
export declare class AvoNetworkCallsHandler {
|
|
55
95
|
private readonly apiKey;
|
|
@@ -58,14 +98,42 @@ export declare class AvoNetworkCallsHandler {
|
|
|
58
98
|
private readonly appVersion;
|
|
59
99
|
private readonly libVersion;
|
|
60
100
|
private readonly publicEncryptionKey?;
|
|
101
|
+
/**
|
|
102
|
+
* "gtm-web" for the web GTM tag template, otherwise undefined. It is the
|
|
103
|
+
* transport switch, decided once in the constructor: undefined keeps the v1
|
|
104
|
+
* request byte for byte as 3.2.0 sent it; "gtm-web" selects v2 and is the
|
|
105
|
+
* X-Avo-Client value.
|
|
106
|
+
*/
|
|
107
|
+
private readonly client;
|
|
108
|
+
private readonly trackingEndpoint;
|
|
61
109
|
private samplingRate;
|
|
62
110
|
private sending;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
111
|
+
/** v2 only: permanent failures in a row for this instance's own events. */
|
|
112
|
+
private permanentFailures;
|
|
113
|
+
/** v2 only: permanent failures in a row per other api key and env, keyed as the send groups are. */
|
|
114
|
+
private readonly foreignFailures;
|
|
115
|
+
/** v2 only: set at most once, when sending can no longer succeed on this page. */
|
|
116
|
+
private sendingDisabled;
|
|
117
|
+
/** v2 only: set when the events themselves can never be sent, so queueing them would only grow the stored queue. */
|
|
118
|
+
private queueingDisabled;
|
|
119
|
+
constructor(apiKey: string, envName: string, appName: string, appVersion: string, libVersion: string, publicEncryptionKey?: string, client?: string);
|
|
120
|
+
/**
|
|
121
|
+
* v2 only: true once sending has stopped for this page (see
|
|
122
|
+
* maxConsecutivePermanentFailures). Always false on v1.
|
|
123
|
+
*/
|
|
124
|
+
isSendingDisabled(): boolean;
|
|
125
|
+
/**
|
|
126
|
+
* v2 only: true when queueing events would only grow the stored queue, because
|
|
127
|
+
* they could never be sent under any configuration. Always false on v1.
|
|
128
|
+
*/
|
|
129
|
+
isQueueingDisabled(): boolean;
|
|
130
|
+
private disableSending;
|
|
131
|
+
/** True while a batch sent through callInspectorWithBatchBody awaits its response. */
|
|
132
|
+
isBatchInFlight(): boolean;
|
|
133
|
+
callInspectorWithBatchBody(inEvents: Array<SessionStartedBody | EventSchemaBody>, onCompleted: (error: Error | null, retryEvents?: RetryEvents) => any): void;
|
|
66
134
|
private fixStreamIds;
|
|
67
135
|
bodyForSessionStartedCall(): SessionStartedBody;
|
|
68
|
-
bodyForEventSchemaCall(eventName: string, eventProperties: EventProperty[], eventId: string | null, eventHash: string | null, eventSpecMetadata?: EventSpecMetadata, validatedBranchId?: string): EventSchemaBody;
|
|
136
|
+
bodyForEventSchemaCall(eventName: string, eventProperties: EventProperty[], eventId: string | null, eventHash: string | null, eventSpecMetadata?: EventSpecMetadata, validatedBranchId?: string, options?: TrackOptions): EventSchemaBody;
|
|
69
137
|
private createBaseCallBody;
|
|
70
138
|
/**
|
|
71
139
|
* Calls Inspector API immediately with a single event (bypasses batching).
|
|
@@ -86,5 +154,12 @@ export declare class AvoNetworkCallsHandler {
|
|
|
86
154
|
* synchronously in the unavailable case, so legacy timing is preserved.
|
|
87
155
|
*/
|
|
88
156
|
private callInspectorApi;
|
|
157
|
+
private sendEvents;
|
|
158
|
+
/**
|
|
159
|
+
* Reports a failure as permanent (second argument true) when retrying the same
|
|
160
|
+
* request cannot succeed: the browser refused to build it, or the API answered
|
|
161
|
+
* a 4xx other than 408 and 429.
|
|
162
|
+
*/
|
|
89
163
|
private sendTrackingRequest;
|
|
90
164
|
}
|
|
165
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../__mocks__/xhr";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -22,6 +22,7 @@ declare const requestMsg: {
|
|
|
22
22
|
TIMEOUT: string;
|
|
23
23
|
};
|
|
24
24
|
declare const trackingEndpoint = "https://api.avo.app/inspector/v1/track";
|
|
25
|
+
declare const trackingEndpointV2 = "https://api.avo.app/inspector/v2/track";
|
|
25
26
|
declare const sessionTimeMs: number;
|
|
26
27
|
declare const type: {
|
|
27
28
|
STRING: string;
|
|
@@ -33,4 +34,4 @@ declare const type: {
|
|
|
33
34
|
NULL: string;
|
|
34
35
|
UNKNOWN: string;
|
|
35
36
|
};
|
|
36
|
-
export { defaultOptions, error, mockedReturns, networkCallType, requestMsg, sessionTimeMs, type, trackingEndpoint };
|
|
37
|
+
export { defaultOptions, error, mockedReturns, networkCallType, requestMsg, sessionTimeMs, type, trackingEndpoint, trackingEndpointV2 };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The internal web GTM tag template path, for tests.
|
|
3
|
+
*
|
|
4
|
+
* None of this is public API. In production only the script-tag bootstrap
|
|
5
|
+
* (src/browser.js) uses it: it passes `window.inspector.__CLIENT__` as the
|
|
6
|
+
* untyped `_client` constructor option, and routes a third `trackSchemaFromEvent`
|
|
7
|
+
* / `trackSchema` argument to the private `_…WithOptions` methods. These helpers
|
|
8
|
+
* do the same from TypeScript, so tests reach it without widening public types.
|
|
9
|
+
*/
|
|
10
|
+
export interface GatewayOptions {
|
|
11
|
+
outputReference?: unknown;
|
|
12
|
+
originHint?: unknown;
|
|
13
|
+
appVersion?: unknown;
|
|
14
|
+
}
|
|
15
|
+
/** Constructor options with the internal client set, as browser.js builds them. */
|
|
16
|
+
export declare const withClient: <T extends object>(options: T, client: string | undefined) => T;
|
|
17
|
+
/** Calls the internal `_trackSchemaFromEventWithOptions` on either build. */
|
|
18
|
+
export declare const trackSchemaFromEventWithOptions: (inspector: object, eventName: string, eventProperties: Record<string, any>, options: GatewayOptions | undefined) => Promise<any[]>;
|
|
19
|
+
/** Calls the internal `_trackSchemaWithOptions` on either build. */
|
|
20
|
+
export declare const trackSchemaWithOptions: (inspector: object, eventName: string, eventSchema: Array<{
|
|
21
|
+
propertyName: string;
|
|
22
|
+
propertyType: string;
|
|
23
|
+
}>, options: GatewayOptions | undefined) => Promise<void>;
|