UNPKG

2.4 kBJavaScriptView Raw
1// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2// SPDX-License-Identifier: Apache-2.0
3var __read = (this && this.__read) || function (o, n) {
4 var m = typeof Symbol === "function" && o[Symbol.iterator];
5 if (!m) return o;
6 var i = m.call(o), r, ar = [], e;
7 try {
8 while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
9 }
10 catch (error) { e = { error: error }; }
11 finally {
12 try {
13 if (r && !r.done && (m = i["return"])) m.call(i);
14 }
15 finally { if (e) throw e.error; }
16 }
17 return ar;
18};
19import { Framework } from './types';
20import { version } from './version';
21import { detectFramework, observeFrameworkChanges } from './detectFramework';
22var BASE_USER_AGENT = "aws-amplify";
23var PlatformBuilder = /** @class */ (function () {
24 function PlatformBuilder() {
25 this.userAgent = "".concat(BASE_USER_AGENT, "/").concat(version);
26 }
27 Object.defineProperty(PlatformBuilder.prototype, "framework", {
28 get: function () {
29 return detectFramework();
30 },
31 enumerable: false,
32 configurable: true
33 });
34 Object.defineProperty(PlatformBuilder.prototype, "isReactNative", {
35 get: function () {
36 return (this.framework === Framework.ReactNative ||
37 this.framework === Framework.Expo);
38 },
39 enumerable: false,
40 configurable: true
41 });
42 PlatformBuilder.prototype.observeFrameworkChanges = function (fcn) {
43 observeFrameworkChanges(fcn);
44 };
45 return PlatformBuilder;
46}());
47export var Platform = new PlatformBuilder();
48export var getAmplifyUserAgentObject = function (_a) {
49 var _b = _a === void 0 ? {} : _a, category = _b.category, action = _b.action, framework = _b.framework;
50 var userAgent = [[BASE_USER_AGENT, version]];
51 if (category) {
52 userAgent.push([category, action]);
53 }
54 userAgent.push(['framework', detectFramework()]);
55 return userAgent;
56};
57export var getAmplifyUserAgent = function (customUserAgentDetails) {
58 var userAgent = getAmplifyUserAgentObject(customUserAgentDetails);
59 var userAgentString = userAgent
60 .map(function (_a) {
61 var _b = __read(_a, 2), agentKey = _b[0], agentValue = _b[1];
62 return "".concat(agentKey, "/").concat(agentValue);
63 })
64 .join(' ');
65 return userAgentString;
66};