@esri/telemetry-amazon 6.0.0-beta.5 → 6.0.0-beta.7
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/dist/esm/auth.js +11 -18
- package/dist/esm/auth.js.map +1 -1
- package/dist/esm/plugins/esri.js +49 -55
- package/dist/esm/plugins/esri.js.map +1 -1
- package/dist/esm/plugins/esri.test.js +26 -38
- package/dist/esm/plugins/esri.test.js.map +1 -1
- package/dist/esm/plugins/{shared.js → utils/shared.js} +1 -2
- package/dist/esm/plugins/utils/shared.js.map +1 -0
- package/dist/node/auth.js +11 -18
- package/dist/node/auth.js.map +1 -1
- package/dist/node/plugins/esri.js +49 -55
- package/dist/node/plugins/esri.js.map +1 -1
- package/dist/node/plugins/esri.test.js +26 -38
- package/dist/node/plugins/esri.test.js.map +1 -1
- package/dist/node/plugins/{shared.js → utils/shared.js} +1 -2
- package/dist/node/plugins/utils/shared.js.map +1 -0
- package/dist/types/plugins/esri.d.ts +4 -10
- package/dist/types/plugins/{shared.d.ts → utils/shared.d.ts} +1 -1
- package/dist/types/types.d.ts +83 -9
- package/dist/umd/telemetry-amazon.js +59 -73
- package/dist/umd/telemetry-amazon.js.map +1 -1
- package/dist/umd/telemetry-amazon.min.js +59 -73
- package/dist/umd/telemetry-amazon.min.js.map +1 -1
- package/package.json +1 -1
- package/dist/esm/plugins/shared.js.map +0 -1
- package/dist/node/plugins/shared.js.map +0 -1
package/dist/types/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ArcGISIdentityManager } from '@esri/arcgis-rest-request';
|
|
2
2
|
import type { AnalyticsInstance } from 'analytics';
|
|
3
|
+
import { getBrowserClientInfo } from './plugins/utils/shared';
|
|
3
4
|
export declare type GenericObject = {
|
|
4
5
|
[key: string]: any;
|
|
5
6
|
};
|
|
@@ -56,19 +57,14 @@ export declare type AmazonApp = {
|
|
|
56
57
|
id?: string;
|
|
57
58
|
version?: string;
|
|
58
59
|
};
|
|
59
|
-
export declare type
|
|
60
|
+
export declare type AmazonTelemetryOptions = {
|
|
60
61
|
userPoolID: string;
|
|
61
62
|
app?: AmazonApp;
|
|
62
63
|
fips?: boolean;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
userPoolID: string;
|
|
67
|
-
app?: AmazonApp;
|
|
68
|
-
fips?: boolean;
|
|
69
|
-
mode: 'esri';
|
|
64
|
+
dimensions?: Dimensions;
|
|
65
|
+
metrics?: Metrics;
|
|
66
|
+
mode?: AmazonTelemetryEndpointMode;
|
|
70
67
|
};
|
|
71
|
-
export declare type AmazonTelemetryOptions = AmazonTelemetryPinpointOptions | AmazonTelemetryEsriOptions;
|
|
72
68
|
export declare type AmazonTelemetryEndpointMode = 'pinpoint' | 'esri';
|
|
73
69
|
export declare type LogPageViewPayload = {
|
|
74
70
|
name: string;
|
|
@@ -88,4 +84,82 @@ export declare type LogEventPayload = {
|
|
|
88
84
|
hostname?: string;
|
|
89
85
|
path?: string;
|
|
90
86
|
};
|
|
87
|
+
export declare type EventMetrics = Record<string, number>;
|
|
88
|
+
export declare type EventAttributes = Record<string, string>;
|
|
89
|
+
export declare type EsriBatchEventPayload = {
|
|
90
|
+
name?: string;
|
|
91
|
+
appTitle?: string;
|
|
92
|
+
appVersion?: string;
|
|
93
|
+
clientSdkVersion?: string;
|
|
94
|
+
deviceMake?: string;
|
|
95
|
+
deviceModel?: string;
|
|
96
|
+
city?: string;
|
|
97
|
+
country?: string;
|
|
98
|
+
lat?: string | number;
|
|
99
|
+
lon?: string | number;
|
|
100
|
+
[key: string]: any;
|
|
101
|
+
};
|
|
102
|
+
export declare type EsriBatchEvent = {
|
|
103
|
+
BatchEvent: {
|
|
104
|
+
Endpoint: {
|
|
105
|
+
Id: string;
|
|
106
|
+
Device: {
|
|
107
|
+
Locale: string;
|
|
108
|
+
Make: string;
|
|
109
|
+
Model: string;
|
|
110
|
+
ModelVersion: string;
|
|
111
|
+
Platform: string;
|
|
112
|
+
PlatformVersion?: string;
|
|
113
|
+
};
|
|
114
|
+
Location: Partial<{
|
|
115
|
+
City: string;
|
|
116
|
+
Country: string;
|
|
117
|
+
Lat: number;
|
|
118
|
+
Lon: number;
|
|
119
|
+
}>;
|
|
120
|
+
Application: {
|
|
121
|
+
AppTitle: string;
|
|
122
|
+
AppVersion: string | undefined;
|
|
123
|
+
ClientSdkVersion: string;
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
Events: Array<{
|
|
127
|
+
EventType: string;
|
|
128
|
+
Timestamp: string;
|
|
129
|
+
Session: {
|
|
130
|
+
Id: string;
|
|
131
|
+
StartTimestamp: string;
|
|
132
|
+
EndTimestamp: string;
|
|
133
|
+
Duration: number;
|
|
134
|
+
};
|
|
135
|
+
Attributes: EventAttributes;
|
|
136
|
+
Metrics: EventMetrics;
|
|
137
|
+
}>;
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
export declare type SessionContext = {
|
|
141
|
+
id: string;
|
|
142
|
+
startTimestamp: string;
|
|
143
|
+
startUnixMs: number;
|
|
144
|
+
};
|
|
145
|
+
export declare type TrackOptions = {
|
|
146
|
+
immediate?: boolean;
|
|
147
|
+
};
|
|
148
|
+
export declare type QueuedEvent = {
|
|
149
|
+
eventName: string;
|
|
150
|
+
payload: EsriBatchEventPayload;
|
|
151
|
+
session?: SessionContext;
|
|
152
|
+
browserInfo?: ReturnType<typeof getBrowserClientInfo>;
|
|
153
|
+
timestamp: string;
|
|
154
|
+
unixMs: number;
|
|
155
|
+
};
|
|
156
|
+
export declare type EsriPluginOptions = {
|
|
157
|
+
trackerName: string;
|
|
158
|
+
appId: string;
|
|
159
|
+
appName?: string;
|
|
160
|
+
appVersion?: string;
|
|
161
|
+
userPoolID?: string;
|
|
162
|
+
fips?: boolean;
|
|
163
|
+
debounceMs?: number;
|
|
164
|
+
};
|
|
91
165
|
export {};
|
|
@@ -257,16 +257,13 @@
|
|
|
257
257
|
},
|
|
258
258
|
body: JSON.stringify({ IdentityPoolId }),
|
|
259
259
|
};
|
|
260
|
-
return
|
|
261
|
-
|
|
262
|
-
if (!
|
|
263
|
-
throw new Error(
|
|
260
|
+
return (async () => {
|
|
261
|
+
const getIdResponse = await fetch(COGNITO_URL, fetchOptions);
|
|
262
|
+
if (!getIdResponse.ok) {
|
|
263
|
+
throw new Error(getIdResponse.statusText);
|
|
264
264
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
.then((response) => {
|
|
268
|
-
const { IdentityId } = response;
|
|
269
|
-
const options = {
|
|
265
|
+
const { IdentityId } = await getIdResponse.json();
|
|
266
|
+
const credentialsOptions = {
|
|
270
267
|
method: 'POST',
|
|
271
268
|
headers: {
|
|
272
269
|
'Content-type': 'application/x-amz-json-1.1',
|
|
@@ -274,18 +271,14 @@
|
|
|
274
271
|
},
|
|
275
272
|
body: JSON.stringify({ IdentityId }),
|
|
276
273
|
};
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
if (!response.ok) {
|
|
281
|
-
throw new Error(response.statusText);
|
|
274
|
+
const getCredentialsResponse = await fetch(COGNITO_URL, credentialsOptions);
|
|
275
|
+
if (!getCredentialsResponse.ok) {
|
|
276
|
+
throw new Error(getCredentialsResponse.statusText);
|
|
282
277
|
}
|
|
283
|
-
|
|
284
|
-
})
|
|
285
|
-
.then(({ Credentials }) => {
|
|
278
|
+
const { Credentials } = await getCredentialsResponse.json();
|
|
286
279
|
storage.set(COGNITO_KEY, Credentials);
|
|
287
280
|
return Credentials;
|
|
288
|
-
});
|
|
281
|
+
})();
|
|
289
282
|
}
|
|
290
283
|
|
|
291
284
|
/******************************************************************************
|
|
@@ -1805,7 +1798,6 @@
|
|
|
1805
1798
|
};
|
|
1806
1799
|
}
|
|
1807
1800
|
|
|
1808
|
-
// Shared utilities for plugins
|
|
1809
1801
|
const PINPOINT_ENDPOINT_KEY = 'TELEMETRY_PINPOINT_ENDPOINT_ID';
|
|
1810
1802
|
const LOG_PREFIX = '[telemetry-amazon]';
|
|
1811
1803
|
function isDebugEnabled() {
|
|
@@ -1865,6 +1857,7 @@
|
|
|
1865
1857
|
const numeric = Number(value);
|
|
1866
1858
|
return Number.isFinite(numeric) ? numeric : fallback;
|
|
1867
1859
|
}
|
|
1860
|
+
/** Splits an EsriBatchEventPayload into attributes and metrics */
|
|
1868
1861
|
function splitEventData(payload) {
|
|
1869
1862
|
const attributes = {};
|
|
1870
1863
|
const metrics = {};
|
|
@@ -1901,6 +1894,7 @@
|
|
|
1901
1894
|
metrics,
|
|
1902
1895
|
};
|
|
1903
1896
|
}
|
|
1897
|
+
/** Constructs an event payload in the shape expected by the endpoint. */
|
|
1904
1898
|
function buildBatchEventPayload({ queuedEvents, trackerName, appName, appVersion, }) {
|
|
1905
1899
|
var _a, _b, _c, _d, _e, _f;
|
|
1906
1900
|
const endpointEvent = queuedEvents[queuedEvents.length - 1] ||
|
|
@@ -1928,13 +1922,9 @@
|
|
|
1928
1922
|
BatchEvent: {
|
|
1929
1923
|
Endpoint: {
|
|
1930
1924
|
Id: endpointId,
|
|
1931
|
-
|
|
1925
|
+
Device: Object.assign({ Locale: (browserInfo === null || browserInfo === void 0 ? void 0 : browserInfo.language) || '', Make: (payload === null || payload === void 0 ? void 0 : payload.deviceMake) || (browserInfo === null || browserInfo === void 0 ? void 0 : browserInfo.make) || '', Model: (payload === null || payload === void 0 ? void 0 : payload.deviceModel) || (browserInfo === null || browserInfo === void 0 ? void 0 : browserInfo.model) || '', ModelVersion: (browserInfo === null || browserInfo === void 0 ? void 0 : browserInfo.version) || '', Platform: ((_a = browserInfo === null || browserInfo === void 0 ? void 0 : browserInfo.os) === null || _a === void 0 ? void 0 : _a.name) || (browserInfo === null || browserInfo === void 0 ? void 0 : browserInfo.platform) || '' }, (((_b = browserInfo === null || browserInfo === void 0 ? void 0 : browserInfo.os) === null || _b === void 0 ? void 0 : _b.version)
|
|
1932
1926
|
? { PlatformVersion: browserInfo.os.version }
|
|
1933
1927
|
: {})),
|
|
1934
|
-
Device: {
|
|
1935
|
-
Make: (payload === null || payload === void 0 ? void 0 : payload.deviceMake) || (browserInfo === null || browserInfo === void 0 ? void 0 : browserInfo.make) || '',
|
|
1936
|
-
Model: (payload === null || payload === void 0 ? void 0 : payload.deviceModel) || (browserInfo === null || browserInfo === void 0 ? void 0 : browserInfo.model) || '',
|
|
1937
|
-
},
|
|
1938
1928
|
Location: location,
|
|
1939
1929
|
Application: {
|
|
1940
1930
|
AppTitle: (_d = (_c = payload === null || payload === void 0 ? void 0 : payload.appTitle) !== null && _c !== void 0 ? _c : appName) !== null && _d !== void 0 ? _d : trackerName,
|
|
@@ -1943,7 +1933,6 @@
|
|
|
1943
1933
|
},
|
|
1944
1934
|
},
|
|
1945
1935
|
Events: queuedEvents.map((queuedEvent) => {
|
|
1946
|
-
console.log('queued event', queuedEvent.eventName);
|
|
1947
1936
|
const timestamp = queuedEvent.timestamp;
|
|
1948
1937
|
const { attributes, metrics } = splitEventData(queuedEvent.payload);
|
|
1949
1938
|
const sessionContext = queuedEvent.session ||
|
|
@@ -2058,53 +2047,53 @@
|
|
|
2058
2047
|
url,
|
|
2059
2048
|
eventCount: queuedEvents.length,
|
|
2060
2049
|
});
|
|
2061
|
-
void
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2050
|
+
void (async () => {
|
|
2051
|
+
var _a;
|
|
2052
|
+
try {
|
|
2053
|
+
const credentials = await getCredentials(userPoolID, { fips });
|
|
2054
|
+
const accessKeyId = (credentials === null || credentials === void 0 ? void 0 : credentials.AccessKeyId) || (credentials === null || credentials === void 0 ? void 0 : credentials.accessKeyId);
|
|
2055
|
+
const secretAccessKey = (credentials === null || credentials === void 0 ? void 0 : credentials.SecretKey) || (credentials === null || credentials === void 0 ? void 0 : credentials.secretAccessKey);
|
|
2056
|
+
const sessionToken = (credentials === null || credentials === void 0 ? void 0 : credentials.SessionToken) || (credentials === null || credentials === void 0 ? void 0 : credentials.sessionToken);
|
|
2057
|
+
if (!accessKeyId || !secretAccessKey) {
|
|
2058
|
+
throw new Error('Signed endpoint credentials are missing required key fields.');
|
|
2059
|
+
}
|
|
2060
|
+
const client = new AwsClient({
|
|
2061
|
+
accessKeyId,
|
|
2062
|
+
secretAccessKey,
|
|
2063
|
+
sessionToken,
|
|
2064
|
+
service: ESRI_SIGNING_SERVICE,
|
|
2065
|
+
region: ESRI_SIGNING_REGION,
|
|
2066
|
+
});
|
|
2067
|
+
await client.fetch(url, {
|
|
2068
|
+
method: 'POST',
|
|
2069
|
+
headers: {
|
|
2070
|
+
'Content-Type': 'application/json',
|
|
2071
|
+
},
|
|
2072
|
+
body: JSON.stringify(buildBatchEventPayload({
|
|
2073
|
+
queuedEvents,
|
|
2074
|
+
trackerName,
|
|
2075
|
+
appName,
|
|
2076
|
+
appVersion,
|
|
2077
|
+
})),
|
|
2078
|
+
});
|
|
2079
|
+
debugLog('Endpoint event sent', {
|
|
2080
|
+
trackerName,
|
|
2081
|
+
eventCount: queuedEvents.length,
|
|
2082
|
+
});
|
|
2068
2083
|
}
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
method: 'POST',
|
|
2078
|
-
headers: {
|
|
2079
|
-
'Content-Type': 'application/json',
|
|
2080
|
-
},
|
|
2081
|
-
body: JSON.stringify(buildBatchEventPayload({
|
|
2082
|
-
queuedEvents,
|
|
2084
|
+
catch (error) {
|
|
2085
|
+
isDisabled = true;
|
|
2086
|
+
clearIdleTimer();
|
|
2087
|
+
clearDebounceTimer();
|
|
2088
|
+
clearPendingEvents();
|
|
2089
|
+
removeAllLifecycleListeners();
|
|
2090
|
+
warnOnce('Esri telemetry disabled after endpoint track failure', {
|
|
2091
|
+
eventName: (_a = queuedEvents[queuedEvents.length - 1]) === null || _a === void 0 ? void 0 : _a.eventName,
|
|
2083
2092
|
trackerName,
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
})
|
|
2089
|
-
.then(() => {
|
|
2090
|
-
debugLog('Endpoint event sent', {
|
|
2091
|
-
trackerName,
|
|
2092
|
-
eventCount: queuedEvents.length,
|
|
2093
|
-
});
|
|
2094
|
-
})
|
|
2095
|
-
.catch((error) => {
|
|
2096
|
-
var _a;
|
|
2097
|
-
isDisabled = true;
|
|
2098
|
-
clearIdleTimer();
|
|
2099
|
-
clearDebounceTimer();
|
|
2100
|
-
clearPendingEvents();
|
|
2101
|
-
removeAllLifecycleListeners();
|
|
2102
|
-
warnOnce('Esri telemetry disabled after endpoint track failure', {
|
|
2103
|
-
eventName: (_a = queuedEvents[queuedEvents.length - 1]) === null || _a === void 0 ? void 0 : _a.eventName,
|
|
2104
|
-
trackerName,
|
|
2105
|
-
message: (error === null || error === void 0 ? void 0 : error.message) || String(error),
|
|
2106
|
-
});
|
|
2107
|
-
});
|
|
2093
|
+
message: (error === null || error === void 0 ? void 0 : error.message) || String(error),
|
|
2094
|
+
});
|
|
2095
|
+
}
|
|
2096
|
+
})();
|
|
2108
2097
|
};
|
|
2109
2098
|
const flushPendingEvents = (eventToAppend) => {
|
|
2110
2099
|
clearDebounceTimer();
|
|
@@ -2112,8 +2101,6 @@
|
|
|
2112
2101
|
if (eventToAppend) {
|
|
2113
2102
|
queuedEvents.push(eventToAppend);
|
|
2114
2103
|
}
|
|
2115
|
-
console.log('flushing', eventToAppend);
|
|
2116
|
-
console.log('stack', queuedEvents);
|
|
2117
2104
|
sendQueuedEvents(queuedEvents);
|
|
2118
2105
|
};
|
|
2119
2106
|
const scheduleDebounceFlush = () => {
|
|
@@ -2172,7 +2159,6 @@
|
|
|
2172
2159
|
}, sessionOverride, undefined, true);
|
|
2173
2160
|
};
|
|
2174
2161
|
const stopSession = (reason) => {
|
|
2175
|
-
console.log('stopping session');
|
|
2176
2162
|
if (!hasSessionStarted || sessionStopSent) {
|
|
2177
2163
|
return false;
|
|
2178
2164
|
}
|