@esri/telemetry-amazon 0.3.2 → 0.4.2

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.
@@ -1,291 +1,489 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@esri/telemetry-shared'), require('analytics'), require('@analytics/aws-pinpoint')) :
3
- typeof define === 'function' && define.amd ? define(['@esri/telemetry-shared', 'analytics', '@analytics/aws-pinpoint'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.telemetry = factory(global.telemetryShared, global.Analytics, global.awsPinpointPlugin));
5
- })(this, (function (telemetryShared, Analytics, awsPinpointPlugin) { 'use strict';
6
-
7
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
-
9
- var Analytics__default = /*#__PURE__*/_interopDefaultLegacy(Analytics);
10
- var awsPinpointPlugin__default = /*#__PURE__*/_interopDefaultLegacy(awsPinpointPlugin);
11
-
12
- var COGNITO_KEY = 'TELEMETRY_COGNITO_CREDENTIALS';
13
- function getCredentials(IdentityPoolId) {
14
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
15
-
16
- var fipsSubdomainSuffix = options.fips === true ? '-fips' : '';
17
- var COGNITO_URL = 'https://cognito-identity' + fipsSubdomainSuffix + '.us-east-1.amazonaws.com/';
18
- var cached = telemetryShared.storage.get(COGNITO_KEY);
19
- if (cached && Date.now() / 1000 < cached.Expiration) return Promise.resolve(cached);
20
- var fetchOptions = {
21
- method: 'POST',
22
- headers: {
23
- 'Content-type': 'application/x-amz-json-1.1',
24
- 'X-Amz-Target': 'AWSCognitoIdentityService.GetId'
25
- },
26
- body: JSON.stringify({ IdentityPoolId: IdentityPoolId })
27
- };
28
- return fetch(COGNITO_URL, fetchOptions).then(function (response) {
29
- if (!response.ok) {
30
- throw new Error(response.statusText);
31
- }
32
- return response.json();
33
- }).then(function (response) {
34
- var IdentityId = response.IdentityId;
35
-
36
- var options = {
37
- method: 'POST',
38
- headers: {
39
- 'Content-type': 'application/x-amz-json-1.1',
40
- 'X-Amz-Target': 'AWSCognitoIdentityService.GetCredentialsForIdentity'
41
- },
42
- body: JSON.stringify({ IdentityId: IdentityId })
43
- };
44
- return fetch(COGNITO_URL, options);
45
- }).then(function (response) {
46
- if (!response.ok) {
47
- throw new Error(response.statusText);
48
- }
49
- return response.json();
50
- }).then(function (_ref) {
51
- var Credentials = _ref.Credentials;
52
-
53
- telemetryShared.storage.set(COGNITO_KEY, Credentials);
54
- return Credentials;
55
- });
56
- }
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@esri/telemetry-shared'), require('analytics'), require('@analytics/aws-pinpoint'), require('@esri/arcgis-rest-portal')) :
3
+ typeof define === 'function' && define.amd ? define(['@esri/telemetry-shared', 'analytics', '@analytics/aws-pinpoint', '@esri/arcgis-rest-portal'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.telemetry = factory(global.telemetryShared, global.Analytics, global.awsPinpointPlugin, global.arcgisRestPortal));
5
+ })(this, (function (telemetryShared, Analytics, awsPinpointPlugin, arcgisRestPortal) { 'use strict';
57
6
 
58
- function formatTelemetryAttributes(_ref) {
59
- var telemetryData = _ref.telemetryData,
60
- _ref$dimensionLookup = _ref.dimensionLookup,
61
- dimensionLookup = _ref$dimensionLookup === undefined ? {} : _ref$dimensionLookup,
62
- _ref$excludeKeys = _ref.excludeKeys,
63
- excludeKeys = _ref$excludeKeys === undefined ? [] : _ref$excludeKeys;
64
-
65
- return Object.keys(telemetryData).filter(function (key) {
66
- return !excludeKeys.includes(key);
67
- }).map(function (key) {
68
- if (dimensionLookup[key]) {
69
- return {
70
- key: getCustomDimensionKey(dimensionLookup, key),
71
- value: telemetryData[key]
72
- };
73
- }
74
- return {
75
- key: key,
76
- value: getValue(telemetryData, key)
77
- };
78
- }).reduce(function (acc, _ref2) {
79
- var key = _ref2.key,
80
- value = _ref2.value;
81
-
82
- acc[key] = value;
83
- return acc;
84
- }, {});
85
- }
86
- function getValue(data, key) {
87
- if (key === 'json') {
88
- return data[key] ? JSON.stringify(data[key]) : 'null';
89
- }
90
- return data[key] === undefined ? 'null' : data[key].toString();
91
- }
92
- function getCustomDimensionKey(lookup, key) {
93
- return 'dimension' + lookup[key];
94
- }
7
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
+
9
+ var Analytics__default = /*#__PURE__*/_interopDefaultLegacy(Analytics);
10
+ var awsPinpointPlugin__default = /*#__PURE__*/_interopDefaultLegacy(awsPinpointPlugin);
95
11
 
96
- var METRICS = ['size', 'duration', 'position', 'number', 'count'];
97
- function formatTelemetryMetrics(telemetryData) {
98
- var metricLookup = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
99
-
100
- return Object.keys(telemetryData).filter(function (key) {
101
- return metricLookup[key] || METRICS.includes(key);
102
- }).map(function (key) {
103
- if (metricLookup[key]) {
104
- return {
105
- key: getCustomMetricKey(metricLookup, key),
106
- value: telemetryData[key]
107
- };
108
- }
109
- return {
110
- key: key,
111
- value: telemetryData[key]
112
- };
113
- }).reduce(function (acc, _ref) {
114
- var key = _ref.key,
115
- value = _ref.value;
116
-
117
- acc[key] = value;
118
- return acc;
119
- }, {});
12
+ var classCallCheck = function (instance, Constructor) {
13
+ if (!(instance instanceof Constructor)) {
14
+ throw new TypeError("Cannot call a class as a function");
120
15
  }
121
- function getCustomMetricKey(lookup, key) {
122
- return 'metric' + lookup[key];
16
+ };
17
+
18
+ var createClass = function () {
19
+ function defineProperties(target, props) {
20
+ for (var i = 0; i < props.length; i++) {
21
+ var descriptor = props[i];
22
+ descriptor.enumerable = descriptor.enumerable || false;
23
+ descriptor.configurable = true;
24
+ if ("value" in descriptor) descriptor.writable = true;
25
+ Object.defineProperty(target, descriptor.key, descriptor);
26
+ }
123
27
  }
124
28
 
125
- var classCallCheck = function (instance, Constructor) {
126
- if (!(instance instanceof Constructor)) {
127
- throw new TypeError("Cannot call a class as a function");
128
- }
29
+ return function (Constructor, protoProps, staticProps) {
30
+ if (protoProps) defineProperties(Constructor.prototype, protoProps);
31
+ if (staticProps) defineProperties(Constructor, staticProps);
32
+ return Constructor;
129
33
  };
34
+ }();
35
+
36
+ var _extends = Object.assign || function (target) {
37
+ for (var i = 1; i < arguments.length; i++) {
38
+ var source = arguments[i];
130
39
 
131
- var createClass = function () {
132
- function defineProperties(target, props) {
133
- for (var i = 0; i < props.length; i++) {
134
- var descriptor = props[i];
135
- descriptor.enumerable = descriptor.enumerable || false;
136
- descriptor.configurable = true;
137
- if ("value" in descriptor) descriptor.writable = true;
138
- Object.defineProperty(target, descriptor.key, descriptor);
40
+ for (var key in source) {
41
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
42
+ target[key] = source[key];
139
43
  }
140
44
  }
45
+ }
141
46
 
142
- return function (Constructor, protoProps, staticProps) {
143
- if (protoProps) defineProperties(Constructor.prototype, protoProps);
144
- if (staticProps) defineProperties(Constructor, staticProps);
145
- return Constructor;
146
- };
147
- }();
47
+ return target;
48
+ };
148
49
 
149
- var _extends = Object.assign || function (target) {
150
- for (var i = 1; i < arguments.length; i++) {
151
- var source = arguments[i];
50
+ var toConsumableArray = function (arr) {
51
+ if (Array.isArray(arr)) {
52
+ for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
152
53
 
153
- for (var key in source) {
154
- if (Object.prototype.hasOwnProperty.call(source, key)) {
155
- target[key] = source[key];
54
+ return arr2;
55
+ } else {
56
+ return Array.from(arr);
57
+ }
58
+ };
59
+
60
+ /******************************************************************************
61
+ Copyright (c) Microsoft Corporation.
62
+
63
+ Permission to use, copy, modify, and/or distribute this software for any
64
+ purpose with or without fee is hereby granted.
65
+
66
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
67
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
68
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
69
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
70
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
71
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
72
+ PERFORMANCE OF THIS SOFTWARE.
73
+ ***************************************************************************** */
74
+ function __rest(s, e) {
75
+ var t = {};
76
+ for (var p in s) {
77
+ if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
78
+ }if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
79
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
80
+ }
81
+ return t;
82
+ }
83
+
84
+ function __awaiter(thisArg, _arguments, P, generator) {
85
+ function adopt(value) {
86
+ return value instanceof P ? value : new P(function (resolve) {
87
+ resolve(value);
88
+ });
89
+ }
90
+ return new (P || (P = Promise))(function (resolve, reject) {
91
+ function fulfilled(value) {
92
+ try {
93
+ step(generator.next(value));
94
+ } catch (e) {
95
+ reject(e);
96
+ }
156
97
  }
157
- }
98
+ function rejected(value) {
99
+ try {
100
+ step(generator["throw"](value));
101
+ } catch (e) {
102
+ reject(e);
103
+ }
104
+ }
105
+ function step(result) {
106
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
107
+ }
108
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
109
+ });
110
+ }
111
+
112
+ var COGNITO_KEY = 'TELEMETRY_COGNITO_CREDENTIALS';
113
+ function getCredentials(IdentityPoolId) {
114
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
115
+
116
+ var fipsSubdomainSuffix = options.fips === true ? '-fips' : '';
117
+ var COGNITO_URL = 'https://cognito-identity' + fipsSubdomainSuffix + '.us-east-1.amazonaws.com/';
118
+ var cached = telemetryShared.storage.get(COGNITO_KEY);
119
+ if (cached && Date.now() / 1000 < cached.Expiration) return Promise.resolve(cached);
120
+ var fetchOptions = {
121
+ method: 'POST',
122
+ headers: {
123
+ 'Content-type': 'application/x-amz-json-1.1',
124
+ 'X-Amz-Target': 'AWSCognitoIdentityService.GetId'
125
+ },
126
+ body: JSON.stringify({ IdentityPoolId: IdentityPoolId })
127
+ };
128
+ return fetch(COGNITO_URL, fetchOptions).then(function (response) {
129
+ if (!response.ok) {
130
+ throw new Error(response.statusText);
131
+ }
132
+ return response.json();
133
+ }).then(function (response) {
134
+ var IdentityId = response.IdentityId;
135
+
136
+ var options = {
137
+ method: 'POST',
138
+ headers: {
139
+ 'Content-type': 'application/x-amz-json-1.1',
140
+ 'X-Amz-Target': 'AWSCognitoIdentityService.GetCredentialsForIdentity'
141
+ },
142
+ body: JSON.stringify({ IdentityId: IdentityId })
143
+ };
144
+ return fetch(COGNITO_URL, options);
145
+ }).then(function (response) {
146
+ if (!response.ok) {
147
+ throw new Error(response.statusText);
148
+ }
149
+ return response.json();
150
+ }).then(function (_ref) {
151
+ var Credentials = _ref.Credentials;
152
+
153
+ telemetryShared.storage.set(COGNITO_KEY, Credentials);
154
+ return Credentials;
155
+ });
156
+ }
157
+
158
+ function formatTelemetryAttributes(_ref) {
159
+ var telemetryData = _ref.telemetryData,
160
+ _ref$dimensionLookup = _ref.dimensionLookup,
161
+ dimensionLookup = _ref$dimensionLookup === undefined ? {} : _ref$dimensionLookup,
162
+ _ref$excludeKeys = _ref.excludeKeys,
163
+ excludeKeys = _ref$excludeKeys === undefined ? [] : _ref$excludeKeys;
164
+
165
+ return Object.keys(telemetryData).filter(function (key) {
166
+ return !excludeKeys.includes(key);
167
+ }).map(function (key) {
168
+ if (dimensionLookup[key]) {
169
+ return {
170
+ key: getCustomDimensionKey(dimensionLookup, key),
171
+ value: telemetryData[key]
172
+ };
173
+ }
174
+ return {
175
+ key: key,
176
+ value: getValue(telemetryData, key)
177
+ };
178
+ }).reduce(function (acc, _ref2) {
179
+ var key = _ref2.key,
180
+ value = _ref2.value;
181
+
182
+ acc[key] = value;
183
+ return acc;
184
+ }, {});
185
+ }
186
+ function getValue(data, key) {
187
+ if (key === 'json') {
188
+ return data[key] ? JSON.stringify(data[key]) : 'null';
158
189
  }
159
-
160
- return target;
161
- };
162
-
163
- var toConsumableArray = function (arr) {
164
- if (Array.isArray(arr)) {
165
- for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
166
-
167
- return arr2;
168
- } else {
169
- return Array.from(arr);
190
+ return data[key] === undefined ? 'null' : data[key].toString();
191
+ }
192
+ function getCustomDimensionKey(lookup, key) {
193
+ return 'dimension' + lookup[key];
194
+ }
195
+
196
+ var METRICS = ['size', 'duration', 'position', 'number', 'count'];
197
+ function formatTelemetryMetrics(telemetryData) {
198
+ var metricLookup = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
199
+
200
+ return Object.keys(telemetryData).filter(function (key) {
201
+ return metricLookup[key] || METRICS.includes(key);
202
+ }).map(function (key) {
203
+ if (metricLookup[key]) {
204
+ return {
205
+ key: getCustomMetricKey(metricLookup, key),
206
+ value: telemetryData[key]
207
+ };
208
+ }
209
+ return {
210
+ key: key,
211
+ value: telemetryData[key]
212
+ };
213
+ }).reduce(function (acc, _ref) {
214
+ var key = _ref.key,
215
+ value = _ref.value;
216
+
217
+ acc[key] = value;
218
+ return acc;
219
+ }, {});
220
+ }
221
+ function getCustomMetricKey(lookup, key) {
222
+ return 'metric' + lookup[key];
223
+ }
224
+
225
+ function createEventLog(_ref) {
226
+ var _ref$event = _ref.event,
227
+ event = _ref$event === undefined ? {} : _ref$event,
228
+ _ref$dimensionLookup = _ref.dimensionLookup,
229
+ dimensionLookup = _ref$dimensionLookup === undefined ? {} : _ref$dimensionLookup,
230
+ _ref$metricLookup = _ref.metricLookup,
231
+ metricLookup = _ref$metricLookup === undefined ? {} : _ref$metricLookup;
232
+
233
+ var _a, _b;
234
+ var eventPathname = event.pathname,
235
+ _event$eventType = event.eventType,
236
+ eventType = _event$eventType === undefined ? 'other' : _event$eventType;
237
+
238
+ var metrics = formatTelemetryMetrics(event, metricLookup);
239
+ var eventAttributes = formatTelemetryAttributes({
240
+ telemetryData: _extends({ eventType: eventType }, event),
241
+ dimensionLookup: dimensionLookup,
242
+ excludeKeys: ['workflow', 'pathname'].concat(toConsumableArray(Object.keys(metrics)), toConsumableArray(Object.keys(metricLookup)))
243
+ });
244
+ var telemetryPayload = _extends(_extends({ name: eventType }, eventAttributes), metrics);
245
+ // Set browser properties if available
246
+ if (typeof document !== 'undefined' && document.referrer) {
247
+ telemetryPayload.referrer = document.referrer;
248
+ }
249
+ if (typeof window !== 'undefined' && !telemetryPayload.hostname) {
250
+ telemetryPayload.hostname = (_a = window.location) === null || _a === void 0 ? void 0 : _a.hostname;
251
+ }
252
+ telemetryPayload.path = typeof window !== 'undefined' && window.location.pathname ? (_b = window.location) === null || _b === void 0 ? void 0 : _b.pathname : eventPathname;
253
+ return telemetryPayload;
254
+ }
255
+
256
+ function createPageViewLog(_ref) {
257
+ var page = _ref.page,
258
+ _ref$previousPage = _ref.previousPage,
259
+ previousPage = _ref$previousPage === undefined ? {} : _ref$previousPage,
260
+ _ref$options = _ref.options,
261
+ options = _ref$options === undefined ? {} : _ref$options,
262
+ _ref$dimensionLookup = _ref.dimensionLookup,
263
+ dimensionLookup = _ref$dimensionLookup === undefined ? {} : _ref$dimensionLookup,
264
+ _ref$metricLookup = _ref.metricLookup,
265
+ metricLookup = _ref$metricLookup === undefined ? {} : _ref$metricLookup;
266
+
267
+ var metrics = formatTelemetryMetrics(options, metricLookup);
268
+ var attributes = formatTelemetryAttributes({
269
+ telemetryData: options,
270
+ dimensionLookup: dimensionLookup,
271
+ excludeKeys: ['workflow'].concat(toConsumableArray(Object.keys(metrics)), toConsumableArray(Object.keys(metricLookup)))
272
+ });
273
+
274
+ var _ref2 = document || {},
275
+ referrer = _ref2.referrer,
276
+ title = _ref2.title;
277
+
278
+ var _ref3 = window && window.location ? window.location : {},
279
+ hostname = _ref3.hostname,
280
+ pathname = _ref3.pathname;
281
+
282
+ return _extends(_extends({ name: 'pageView', referrer: referrer,
283
+ hostname: hostname, path: page || pathname, pageUrl: page || pathname, pageName: title, previousPageUrl: previousPage.pageUrl, previousPageName: previousPage.pageName }, attributes), metrics);
284
+ }
285
+
286
+ function buildAccessProperties(username, currentAccessProperties, accessChangeset) {
287
+ return accessChangeset.reduce(function (accessProperties, accessChange) {
288
+ var action = accessChange.action,
289
+ targetProperty = accessChange.targetProperty;
290
+
291
+ if (action === 'add') {
292
+ accessProperties[targetProperty] = {
293
+ updatedAt: new Date(),
294
+ updatedBy: username
295
+ };
296
+ } else if (action === 'remove') {
297
+ delete accessProperties[targetProperty];
298
+ }
299
+ return accessProperties;
300
+ }, currentAccessProperties);
301
+ }
302
+
303
+ function setPortalItemAccessPermissions(_ref) {
304
+ var id = _ref.id,
305
+ authentication = _ref.authentication,
306
+ username = _ref.username,
307
+ accessChangeset = _ref.accessChangeset;
308
+
309
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
310
+ var _ref2, _ref2$properties, properties, _a, _b, _b$arcgis, _b$arcgis$access, currentAccessProperties, additionalTelemetryProperties, accessProperties;
311
+
312
+ return regeneratorRuntime.wrap(function _callee$(_context) {
313
+ while (1) {
314
+ switch (_context.prev = _context.next) {
315
+ case 0:
316
+ _context.next = 2;
317
+ return arcgisRestPortal.getItem(id, {
318
+ authentication: authentication
319
+ });
320
+
321
+ case 2:
322
+ _ref2 = _context.sent;
323
+ _ref2$properties = _ref2.properties;
324
+ properties = _ref2$properties === undefined ? {} : _ref2$properties;
325
+ _a = properties.telemetry, _b = _a === void 0 ? {} : _a, _b$arcgis = _b.arcgis;
326
+ _b$arcgis = _b$arcgis === undefined ? {} : _b$arcgis;
327
+ _b$arcgis$access = _b$arcgis.access, currentAccessProperties = _b$arcgis$access === undefined ? {} : _b$arcgis$access, additionalTelemetryProperties = __rest(_b, ["arcgis"]);
328
+ accessProperties = buildAccessProperties(username, currentAccessProperties, accessChangeset);
329
+ return _context.abrupt('return', arcgisRestPortal.updateItem({
330
+ item: {
331
+ id: id,
332
+ properties: _extends(_extends({}, properties), { telemetry: _extends(_extends({}, additionalTelemetryProperties), { arcgis: {
333
+ access: _extends({}, accessProperties)
334
+ } }) })
335
+ },
336
+ authentication: authentication
337
+ }));
338
+
339
+ case 10:
340
+ case 'end':
341
+ return _context.stop();
342
+ }
343
+ }
344
+ }, _callee, this);
345
+ }));
346
+ }
347
+
348
+ function getPortalItemAccessPermissions(_ref) {
349
+ var id = _ref.id,
350
+ authentication = _ref.authentication;
351
+
352
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
353
+ var _ref2, _ref2$properties$tele, _ref2$properties$tele2, _ref2$properties$tele3, access;
354
+
355
+ return regeneratorRuntime.wrap(function _callee$(_context) {
356
+ while (1) {
357
+ switch (_context.prev = _context.next) {
358
+ case 0:
359
+ _context.next = 2;
360
+ return arcgisRestPortal.getItem(id, {
361
+ authentication: authentication
362
+ });
363
+
364
+ case 2:
365
+ _ref2 = _context.sent;
366
+ _ref2$properties$tele = _ref2.properties.telemetry;
367
+ _ref2$properties$tele = _ref2$properties$tele === undefined ? {} : _ref2$properties$tele;
368
+ _ref2$properties$tele2 = _ref2$properties$tele.arcgis;
369
+ _ref2$properties$tele2 = _ref2$properties$tele2 === undefined ? {} : _ref2$properties$tele2;
370
+ _ref2$properties$tele3 = _ref2$properties$tele2.access, access = _ref2$properties$tele3 === undefined ? {} : _ref2$properties$tele3;
371
+ return _context.abrupt("return", { access: access });
372
+
373
+ case 9:
374
+ case "end":
375
+ return _context.stop();
376
+ }
377
+ }
378
+ }, _callee, this);
379
+ }));
380
+ }
381
+
382
+ var Amazon = function () {
383
+ function Amazon(options) {
384
+ classCallCheck(this, Amazon);
385
+
386
+ this.name = 'amazon';
387
+ var _options$app = options.app,
388
+ app = _options$app === undefined ? {} : _options$app,
389
+ fips = options.fips,
390
+ userPoolID = options.userPoolID;
391
+
392
+ this.analytics = Analytics__default["default"]({
393
+ app: app.name,
394
+ version: app.version,
395
+ plugins: [awsPinpointPlugin__default["default"]({
396
+ fips: fips,
397
+ pinpointAppId: app.id,
398
+ getCredentials: function getCredentials$1() {
399
+ return getCredentials(userPoolID, { fips: fips });
400
+ }
401
+ })]
402
+ });
403
+ _extends(this, options);
170
404
  }
171
- };
172
-
173
- function createEventLog(_ref) {
174
- var _ref$event = _ref.event,
175
- event = _ref$event === undefined ? {} : _ref$event,
176
- _ref$dimensionLookup = _ref.dimensionLookup,
177
- dimensionLookup = _ref$dimensionLookup === undefined ? {} : _ref$dimensionLookup,
178
- _ref$metricLookup = _ref.metricLookup,
179
- metricLookup = _ref$metricLookup === undefined ? {} : _ref$metricLookup;
180
-
181
- var _a, _b;
182
- var eventPathname = event.pathname,
183
- _event$eventType = event.eventType,
184
- eventType = _event$eventType === undefined ? 'other' : _event$eventType;
185
-
186
- var metrics = formatTelemetryMetrics(event, metricLookup);
187
- var eventAttributes = formatTelemetryAttributes({
188
- telemetryData: _extends({ eventType: eventType }, event),
189
- dimensionLookup: dimensionLookup,
190
- excludeKeys: ['workflow', 'pathname'].concat(toConsumableArray(Object.keys(metrics)), toConsumableArray(Object.keys(metricLookup)))
191
- });
192
- var telemetryPayload = _extends(_extends({ name: eventType }, eventAttributes), metrics);
193
- // Set browser properties if available
194
- if (typeof document !== 'undefined' && document.referrer) {
195
- telemetryPayload.referrer = document.referrer;
196
- }
197
- if (typeof window !== 'undefined' && !telemetryPayload.hostname) {
198
- telemetryPayload.hostname = (_a = window.location) === null || _a === void 0 ? void 0 : _a.hostname;
199
- }
200
- telemetryPayload.path = typeof window !== 'undefined' && window.location.pathname ? (_b = window.location) === null || _b === void 0 ? void 0 : _b.pathname : eventPathname;
201
- return telemetryPayload;
202
- }
203
-
204
- function createPageViewLog(_ref) {
205
- var page = _ref.page,
206
- _ref$previousPage = _ref.previousPage,
207
- previousPage = _ref$previousPage === undefined ? {} : _ref$previousPage,
208
- _ref$options = _ref.options,
209
- options = _ref$options === undefined ? {} : _ref$options,
210
- _ref$dimensionLookup = _ref.dimensionLookup,
211
- dimensionLookup = _ref$dimensionLookup === undefined ? {} : _ref$dimensionLookup,
212
- _ref$metricLookup = _ref.metricLookup,
213
- metricLookup = _ref$metricLookup === undefined ? {} : _ref$metricLookup;
214
-
215
- var metrics = formatTelemetryMetrics(options, metricLookup);
216
- var attributes = formatTelemetryAttributes({
217
- telemetryData: options,
218
- dimensionLookup: dimensionLookup,
219
- excludeKeys: ['workflow'].concat(toConsumableArray(Object.keys(metrics)), toConsumableArray(Object.keys(metricLookup)))
220
- });
221
-
222
- var _ref2 = document || {},
223
- referrer = _ref2.referrer,
224
- title = _ref2.title;
225
-
226
- var _ref3 = window && window.location ? window.location : {},
227
- hostname = _ref3.hostname,
228
- pathname = _ref3.pathname;
229
-
230
- return _extends(_extends({ name: 'pageView', referrer: referrer,
231
- hostname: hostname, path: page || pathname, pageUrl: page || pathname, pageName: title, previousPageUrl: previousPage.pageUrl, previousPageName: previousPage.pageName }, attributes), metrics);
232
- }
233
405
 
234
- var Amazon = function () {
235
- function Amazon(options) {
236
- classCallCheck(this, Amazon);
237
- var _options$app = options.app,
238
- app = _options$app === undefined ? {} : _options$app,
239
- fips = options.fips,
240
- userPoolID = options.userPoolID;
241
-
242
- this.analytics = Analytics__default["default"]({
243
- app: app.name,
244
- version: app.version,
245
- plugins: [awsPinpointPlugin__default["default"]({
246
- fips: fips,
247
- pinpointAppId: app.id,
248
- getCredentials: function getCredentials$1() {
249
- return getCredentials(userPoolID, { fips: fips });
250
- }
251
- })]
252
- });
253
- this.name = 'amazon';
254
- _extends(this, options);
255
- }
406
+ createClass(Amazon, [{
407
+ key: 'logPageView',
408
+ value: function logPageView(page, options) {
409
+ var telemetryPayload = createPageViewLog({
410
+ page: page,
411
+ previousPage: this.previousPage,
412
+ options: options,
413
+ dimensionLookup: this.dimensions,
414
+ metricLookup: this.metrics
415
+ });
416
+ this.previousPage = telemetryPayload.attributes;
417
+ this.analytics.track('pageView', telemetryPayload);
418
+ }
419
+ }, {
420
+ key: 'logEvent',
421
+ value: function logEvent() {
422
+ var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
423
+
424
+ var telemetryPayload = createEventLog({
425
+ event: event,
426
+ dimensionLookup: this.dimensions,
427
+ metricLookup: this.metrics
428
+ });
429
+ var name = telemetryPayload.name;
430
+
431
+ this.analytics.track(name, telemetryPayload);
432
+ }
433
+ }], [{
434
+ key: 'setAccessPermissions',
435
+ value: function setAccessPermissions(_ref) {
436
+ var id = _ref.id,
437
+ authentication = _ref.authentication,
438
+ username = _ref.username,
439
+ accessChangeset = _ref.accessChangeset;
440
+
441
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
442
+ return regeneratorRuntime.wrap(function _callee$(_context) {
443
+ while (1) {
444
+ switch (_context.prev = _context.next) {
445
+ case 0:
446
+ return _context.abrupt('return', setPortalItemAccessPermissions({
447
+ id: id,
448
+ authentication: authentication,
449
+ username: username,
450
+ accessChangeset: accessChangeset
451
+ }));
452
+
453
+ case 1:
454
+ case 'end':
455
+ return _context.stop();
456
+ }
457
+ }
458
+ }, _callee, this);
459
+ }));
460
+ }
461
+ }, {
462
+ key: 'getAccessPermissions',
463
+ value: function getAccessPermissions(_ref2) {
464
+ var id = _ref2.id,
465
+ authentication = _ref2.authentication;
466
+
467
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
468
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
469
+ while (1) {
470
+ switch (_context2.prev = _context2.next) {
471
+ case 0:
472
+ return _context2.abrupt('return', getPortalItemAccessPermissions({ id: id, authentication: authentication }));
473
+
474
+ case 1:
475
+ case 'end':
476
+ return _context2.stop();
477
+ }
478
+ }
479
+ }, _callee2, this);
480
+ }));
481
+ }
482
+ }]);
483
+ return Amazon;
484
+ }();
256
485
 
257
- createClass(Amazon, [{
258
- key: 'logPageView',
259
- value: function logPageView(page, options) {
260
- var telemetryPayload = createPageViewLog({
261
- page: page,
262
- previousPage: this.previousPage,
263
- options: options,
264
- dimensionLookup: this.dimensions,
265
- metricLookup: this.metrics
266
- });
267
- this.previousPage = telemetryPayload.attributes;
268
- this.analytics.track('pageView', telemetryPayload);
269
- }
270
- }, {
271
- key: 'logEvent',
272
- value: function logEvent() {
273
- var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
274
-
275
- var telemetryPayload = createEventLog({
276
- event: event,
277
- dimensionLookup: this.dimensions,
278
- metricLookup: this.metrics
279
- });
280
- var name = telemetryPayload.name;
281
-
282
- this.analytics.track(name, telemetryPayload);
283
- }
284
- }]);
285
- return Amazon;
286
- }();
287
-
288
- return Amazon;
486
+ return Amazon;
289
487
 
290
488
  }));
291
489
  //# sourceMappingURL=telemetry-amazon.min.js.map