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