@aws-amplify/core 5.4.1-unstable.f47d472.4 → 5.5.0

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.
Files changed (102) hide show
  1. package/lib/AwsClients/CognitoIdentity/base.js +5 -1
  2. package/lib/AwsClients/Pinpoint/base.js +1 -1
  3. package/lib/Platform/detectFramework.d.ts +7 -0
  4. package/lib/Platform/detectFramework.js +53 -0
  5. package/lib/Platform/detection/Angular.d.ts +2 -0
  6. package/lib/Platform/detection/Angular.js +23 -0
  7. package/lib/Platform/detection/Expo.d.ts +1 -0
  8. package/lib/Platform/detection/Expo.js +12 -0
  9. package/lib/Platform/detection/Next.d.ts +2 -0
  10. package/lib/Platform/detection/Next.js +17 -0
  11. package/lib/Platform/detection/Nuxt.d.ts +2 -0
  12. package/lib/Platform/detection/Nuxt.js +18 -0
  13. package/lib/Platform/detection/React.d.ts +2 -0
  14. package/lib/Platform/detection/React.js +24 -0
  15. package/lib/Platform/detection/ReactNative.d.ts +1 -0
  16. package/lib/Platform/detection/ReactNative.js +12 -0
  17. package/lib/Platform/detection/Svelte.d.ts +2 -0
  18. package/lib/Platform/detection/Svelte.js +17 -0
  19. package/lib/Platform/detection/Vue.d.ts +2 -0
  20. package/lib/Platform/detection/Vue.js +15 -0
  21. package/lib/Platform/detection/Web.d.ts +1 -0
  22. package/lib/Platform/detection/Web.js +10 -0
  23. package/lib/Platform/detection/helpers.d.ts +6 -0
  24. package/lib/Platform/detection/helpers.js +29 -0
  25. package/lib/Platform/detection/index.d.ts +2 -0
  26. package/lib/Platform/detection/index.js +41 -0
  27. package/lib/Platform/index.d.ts +11 -6
  28. package/lib/Platform/index.js +63 -24
  29. package/lib/Platform/types.d.ts +104 -0
  30. package/lib/Platform/types.js +133 -0
  31. package/lib/Platform/version.d.ts +1 -1
  32. package/lib/Platform/version.js +1 -1
  33. package/lib/clients/middleware/retry/defaultRetryDecider.js +1 -1
  34. package/lib/clients/middleware/signing/middleware.d.ts +1 -0
  35. package/lib/clients/middleware/signing/middleware.js +8 -21
  36. package/lib/index.d.ts +2 -1
  37. package/lib/index.js +17 -2
  38. package/lib/tsconfig.tsbuildinfo +1 -1
  39. package/lib-esm/AwsClients/CognitoIdentity/base.js +6 -2
  40. package/lib-esm/AwsClients/Pinpoint/base.js +2 -2
  41. package/lib-esm/Platform/detectFramework.d.ts +7 -0
  42. package/lib-esm/Platform/detectFramework.js +47 -0
  43. package/lib-esm/Platform/detection/Angular.d.ts +2 -0
  44. package/lib-esm/Platform/detection/Angular.js +18 -0
  45. package/lib-esm/Platform/detection/Expo.d.ts +1 -0
  46. package/lib-esm/Platform/detection/Expo.js +8 -0
  47. package/lib-esm/Platform/detection/Next.d.ts +2 -0
  48. package/lib-esm/Platform/detection/Next.js +12 -0
  49. package/lib-esm/Platform/detection/Nuxt.d.ts +2 -0
  50. package/lib-esm/Platform/detection/Nuxt.js +13 -0
  51. package/lib-esm/Platform/detection/React.d.ts +2 -0
  52. package/lib-esm/Platform/detection/React.js +19 -0
  53. package/lib-esm/Platform/detection/ReactNative.d.ts +1 -0
  54. package/lib-esm/Platform/detection/ReactNative.js +8 -0
  55. package/lib-esm/Platform/detection/Svelte.d.ts +2 -0
  56. package/lib-esm/Platform/detection/Svelte.js +12 -0
  57. package/lib-esm/Platform/detection/Vue.d.ts +2 -0
  58. package/lib-esm/Platform/detection/Vue.js +10 -0
  59. package/lib-esm/Platform/detection/Web.d.ts +1 -0
  60. package/lib-esm/Platform/detection/Web.js +6 -0
  61. package/lib-esm/Platform/detection/helpers.d.ts +6 -0
  62. package/lib-esm/Platform/detection/helpers.js +20 -0
  63. package/lib-esm/Platform/detection/index.d.ts +2 -0
  64. package/lib-esm/Platform/detection/index.js +37 -0
  65. package/lib-esm/Platform/index.d.ts +11 -6
  66. package/lib-esm/Platform/index.js +60 -22
  67. package/lib-esm/Platform/types.d.ts +104 -0
  68. package/lib-esm/Platform/types.js +130 -0
  69. package/lib-esm/Platform/version.d.ts +1 -1
  70. package/lib-esm/Platform/version.js +1 -1
  71. package/lib-esm/clients/middleware/retry/defaultRetryDecider.js +1 -1
  72. package/lib-esm/clients/middleware/signing/middleware.d.ts +1 -0
  73. package/lib-esm/clients/middleware/signing/middleware.js +8 -21
  74. package/lib-esm/index.d.ts +2 -1
  75. package/lib-esm/index.js +2 -1
  76. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  77. package/package.json +3 -3
  78. package/src/AwsClients/CognitoIdentity/base.ts +7 -2
  79. package/src/AwsClients/Pinpoint/base.ts +2 -2
  80. package/src/Platform/detectFramework.ts +57 -0
  81. package/src/Platform/detection/Angular.ts +26 -0
  82. package/src/Platform/detection/Expo.ts +11 -0
  83. package/src/Platform/detection/Next.ts +18 -0
  84. package/src/Platform/detection/Nuxt.ts +19 -0
  85. package/src/Platform/detection/React.ts +26 -0
  86. package/src/Platform/detection/ReactNative.ts +12 -0
  87. package/src/Platform/detection/Svelte.ts +18 -0
  88. package/src/Platform/detection/Vue.ts +13 -0
  89. package/src/Platform/detection/Web.ts +8 -0
  90. package/src/Platform/detection/helpers.ts +26 -0
  91. package/src/Platform/detection/index.ts +48 -0
  92. package/src/Platform/index.ts +42 -21
  93. package/src/Platform/types.ts +160 -0
  94. package/src/Platform/version.ts +1 -1
  95. package/src/clients/middleware/retry/defaultRetryDecider.ts +1 -1
  96. package/src/clients/middleware/signing/middleware.ts +13 -19
  97. package/src/index.ts +21 -1
  98. /package/lib/clients/{utils → middleware/retry}/isClockSkewError.d.ts +0 -0
  99. /package/lib/clients/{utils → middleware/retry}/isClockSkewError.js +0 -0
  100. /package/lib-esm/clients/{utils → middleware/retry}/isClockSkewError.d.ts +0 -0
  101. /package/lib-esm/clients/{utils → middleware/retry}/isClockSkewError.js +0 -0
  102. /package/src/clients/{utils → middleware/retry}/isClockSkewError.ts +0 -0
@@ -43,6 +43,7 @@ var clients_1 = require("../../clients");
43
43
  var composeTransferHandler_1 = require("../../clients/internal/composeTransferHandler");
44
44
  var retry_1 = require("../../clients/middleware/retry");
45
45
  var Platform_1 = require("../../Platform");
46
+ var detectFramework_1 = require("../../Platform/detectFramework");
46
47
  /**
47
48
  * The service name used to sign requests if the API requires authentication.
48
49
  */
@@ -84,8 +85,11 @@ exports.defaultConfig = {
84
85
  endpointResolver: endpointResolver,
85
86
  retryDecider: (0, retry_1.getRetryDecider)(clients_1.parseJsonError),
86
87
  computeDelay: retry_1.jitteredBackoff,
87
- userAgentValue: (0, Platform_1.getAmplifyUserAgent)(), // TODO: use getAmplifyUserAgentString() when available.
88
+ userAgentValue: (0, Platform_1.getAmplifyUserAgentString)(),
88
89
  };
90
+ (0, detectFramework_1.observeFrameworkChanges)(function () {
91
+ exports.defaultConfig.userAgentValue = (0, Platform_1.getAmplifyUserAgentString)();
92
+ });
89
93
  /**
90
94
  * @internal
91
95
  */
@@ -28,7 +28,7 @@ exports.defaultConfig = {
28
28
  endpointResolver: endpointResolver,
29
29
  retryDecider: (0, retry_1.getRetryDecider)(json_1.parseJsonError),
30
30
  computeDelay: retry_1.jitteredBackoff,
31
- userAgentValue: (0, Platform_1.getAmplifyUserAgent)(), // TODO: use getAmplifyUserAgentString() when available.
31
+ userAgentValue: (0, Platform_1.getAmplifyUserAgentString)(),
32
32
  };
33
33
  /**
34
34
  * @internal
@@ -0,0 +1,7 @@
1
+ import { Framework } from './types';
2
+ export declare const detectFramework: () => Framework;
3
+ /**
4
+ * @internal Setup observer callback that will be called everytime the framework changes
5
+ */
6
+ export declare const observeFrameworkChanges: (fcn: () => void) => void;
7
+ export declare function clearCache(): void;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.clearCache = exports.observeFrameworkChanges = exports.detectFramework = void 0;
6
+ var types_1 = require("./types");
7
+ var detection_1 = require("./detection");
8
+ // We want to cache detection since the framework won't change
9
+ var frameworkCache;
10
+ var frameworkChangeObservers = [];
11
+ // Setup the detection reset tracking / timeout delays
12
+ var resetTriggered = false;
13
+ var SSR_RESET_TIMEOUT = 10; // ms
14
+ var WEB_RESET_TIMEOUT = 10; // ms
15
+ var PRIME_FRAMEWORK_DELAY = 1000; // ms
16
+ var detectFramework = function () {
17
+ if (!frameworkCache) {
18
+ frameworkCache = (0, detection_1.detect)();
19
+ // Everytime we update the cache, call each observer function
20
+ frameworkChangeObservers.forEach(function (fcn) { return fcn(); });
21
+ // Retry once for either Unknown type after a delay (explained below)
22
+ resetTimeout(types_1.Framework.ServerSideUnknown, SSR_RESET_TIMEOUT);
23
+ resetTimeout(types_1.Framework.WebUnknown, WEB_RESET_TIMEOUT);
24
+ }
25
+ return frameworkCache;
26
+ };
27
+ exports.detectFramework = detectFramework;
28
+ /**
29
+ * @internal Setup observer callback that will be called everytime the framework changes
30
+ */
31
+ var observeFrameworkChanges = function (fcn) {
32
+ frameworkChangeObservers.push(fcn);
33
+ };
34
+ exports.observeFrameworkChanges = observeFrameworkChanges;
35
+ function clearCache() {
36
+ frameworkCache = undefined;
37
+ }
38
+ exports.clearCache = clearCache;
39
+ // For a framework type and a delay amount, setup the event to re-detect
40
+ // During the runtime boot, it is possible that framework detection will
41
+ // be triggered before the framework has made modifications to the
42
+ // global/window/etc needed for detection. When no framework is detected
43
+ // we will reset and try again to ensure we don't use a cached
44
+ // non-framework detection result for all requests.
45
+ function resetTimeout(framework, delay) {
46
+ if (frameworkCache === framework && !resetTriggered) {
47
+ setTimeout(function () {
48
+ clearCache();
49
+ resetTriggered = true;
50
+ setTimeout(exports.detectFramework, PRIME_FRAMEWORK_DELAY);
51
+ }, delay);
52
+ }
53
+ }
@@ -0,0 +1,2 @@
1
+ export declare function angularWebDetect(): boolean;
2
+ export declare function angularSSRDetect(): boolean;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.angularSSRDetect = exports.angularWebDetect = void 0;
6
+ var helpers_1 = require("./helpers");
7
+ // Tested with @angular/core 16.0.0
8
+ function angularWebDetect() {
9
+ var angularVersionSetInDocument = Boolean((0, helpers_1.documentExists)() && document.querySelector('[ng-version]'));
10
+ var angularContentSetInWindow = Boolean(
11
+ // @ts-ignore
12
+ (0, helpers_1.windowExists)() && typeof window['ng'] !== 'undefined');
13
+ return angularVersionSetInDocument || angularContentSetInWindow;
14
+ }
15
+ exports.angularWebDetect = angularWebDetect;
16
+ function angularSSRDetect() {
17
+ var _a;
18
+ return (((0, helpers_1.processExists)() &&
19
+ typeof process.env === 'object' &&
20
+ ((_a = process.env['npm_lifecycle_script']) === null || _a === void 0 ? void 0 : _a.startsWith('ng '))) ||
21
+ false);
22
+ }
23
+ exports.angularSSRDetect = angularSSRDetect;
@@ -0,0 +1 @@
1
+ export declare function expoDetect(): boolean;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.expoDetect = void 0;
6
+ var helpers_1 = require("./helpers");
7
+ // Tested with expo 48 / react-native 0.71.3
8
+ function expoDetect() {
9
+ // @ts-ignore
10
+ return (0, helpers_1.globalExists)() && typeof global['expo'] !== 'undefined';
11
+ }
12
+ exports.expoDetect = expoDetect;
@@ -0,0 +1,2 @@
1
+ export declare function nextWebDetect(): boolean;
2
+ export declare function nextSSRDetect(): boolean;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.nextSSRDetect = exports.nextWebDetect = void 0;
6
+ var helpers_1 = require("./helpers");
7
+ // Tested with next 13.4 / react 18.2
8
+ function nextWebDetect() {
9
+ // @ts-ignore
10
+ return (0, helpers_1.windowExists)() && window['next'] && typeof window['next'] === 'object';
11
+ }
12
+ exports.nextWebDetect = nextWebDetect;
13
+ function nextSSRDetect() {
14
+ return ((0, helpers_1.globalExists)() &&
15
+ ((0, helpers_1.keyPrefixMatch)(global, '__next') || (0, helpers_1.keyPrefixMatch)(global, '__NEXT')));
16
+ }
17
+ exports.nextSSRDetect = nextSSRDetect;
@@ -0,0 +1,2 @@
1
+ export declare function nuxtWebDetect(): boolean;
2
+ export declare function nuxtSSRDetect(): boolean;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.nuxtSSRDetect = exports.nuxtWebDetect = void 0;
6
+ var helpers_1 = require("./helpers");
7
+ // Tested with nuxt 2.15 / vue 2.7
8
+ function nuxtWebDetect() {
9
+ return ((0, helpers_1.windowExists)() &&
10
+ // @ts-ignore
11
+ (window['__NUXT__'] !== undefined || window['$nuxt'] !== undefined));
12
+ }
13
+ exports.nuxtWebDetect = nuxtWebDetect;
14
+ function nuxtSSRDetect() {
15
+ // @ts-ignore
16
+ return (0, helpers_1.globalExists)() && typeof global['__NUXT_PATHS__'] !== 'undefined';
17
+ }
18
+ exports.nuxtSSRDetect = nuxtSSRDetect;
@@ -0,0 +1,2 @@
1
+ export declare function reactWebDetect(): boolean;
2
+ export declare function reactSSRDetect(): boolean;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.reactSSRDetect = exports.reactWebDetect = void 0;
6
+ var helpers_1 = require("./helpers");
7
+ // Tested with react 18.2 - built using Vite
8
+ function reactWebDetect() {
9
+ var elementKeyPrefixedWithReact = function (key) {
10
+ return key.startsWith('_react') || key.startsWith('__react');
11
+ };
12
+ var elementIsReactEnabled = function (element) {
13
+ return Object.keys(element).find(elementKeyPrefixedWithReact);
14
+ };
15
+ var allElementsWithId = function () { return Array.from(document.querySelectorAll('[id]')); };
16
+ return (0, helpers_1.documentExists)() && allElementsWithId().some(elementIsReactEnabled);
17
+ }
18
+ exports.reactWebDetect = reactWebDetect;
19
+ function reactSSRDetect() {
20
+ return ((0, helpers_1.processExists)() &&
21
+ typeof process.env !== 'undefined' &&
22
+ !!Object.keys(process.env).find(function (key) { return key.includes('react'); }));
23
+ }
24
+ exports.reactSSRDetect = reactSSRDetect;
@@ -0,0 +1 @@
1
+ export declare function reactNativeDetect(): boolean;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.reactNativeDetect = void 0;
6
+ // Tested with react-native 0.17.7
7
+ function reactNativeDetect() {
8
+ return (typeof navigator !== 'undefined' &&
9
+ typeof navigator.product !== 'undefined' &&
10
+ navigator.product === 'ReactNative');
11
+ }
12
+ exports.reactNativeDetect = reactNativeDetect;
@@ -0,0 +1,2 @@
1
+ export declare function svelteWebDetect(): boolean;
2
+ export declare function svelteSSRDetect(): boolean;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.svelteSSRDetect = exports.svelteWebDetect = void 0;
6
+ var helpers_1 = require("./helpers");
7
+ // Tested with svelte 3.59
8
+ function svelteWebDetect() {
9
+ return (0, helpers_1.windowExists)() && (0, helpers_1.keyPrefixMatch)(window, '__SVELTE');
10
+ }
11
+ exports.svelteWebDetect = svelteWebDetect;
12
+ function svelteSSRDetect() {
13
+ return ((0, helpers_1.processExists)() &&
14
+ typeof process.env !== 'undefined' &&
15
+ !!Object.keys(process.env).find(function (key) { return key.includes('svelte'); }));
16
+ }
17
+ exports.svelteSSRDetect = svelteSSRDetect;
@@ -0,0 +1,2 @@
1
+ export declare function vueWebDetect(): boolean;
2
+ export declare function vueSSRDetect(): boolean;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.vueSSRDetect = exports.vueWebDetect = void 0;
6
+ var helpers_1 = require("./helpers");
7
+ // Tested with vue 3.3.2
8
+ function vueWebDetect() {
9
+ return (0, helpers_1.windowExists)() && (0, helpers_1.keyPrefixMatch)(window, '__VUE');
10
+ }
11
+ exports.vueWebDetect = vueWebDetect;
12
+ function vueSSRDetect() {
13
+ return (0, helpers_1.globalExists)() && (0, helpers_1.keyPrefixMatch)(global, '__VUE');
14
+ }
15
+ exports.vueSSRDetect = vueSSRDetect;
@@ -0,0 +1 @@
1
+ export declare function webDetect(): boolean;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.webDetect = void 0;
6
+ var helpers_1 = require("./helpers");
7
+ function webDetect() {
8
+ return (0, helpers_1.windowExists)();
9
+ }
10
+ exports.webDetect = webDetect;
@@ -0,0 +1,6 @@
1
+ export declare const globalExists: () => boolean;
2
+ export declare const globalThisExists: () => boolean;
3
+ export declare const windowExists: () => boolean;
4
+ export declare const documentExists: () => boolean;
5
+ export declare const processExists: () => boolean;
6
+ export declare const keyPrefixMatch: (object: object, prefix: string) => boolean;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.keyPrefixMatch = exports.processExists = exports.documentExists = exports.windowExists = exports.globalThisExists = exports.globalExists = void 0;
6
+ var globalExists = function () {
7
+ return typeof global !== 'undefined';
8
+ };
9
+ exports.globalExists = globalExists;
10
+ var globalThisExists = function () {
11
+ return typeof globalThis !== 'undefined';
12
+ };
13
+ exports.globalThisExists = globalThisExists;
14
+ var windowExists = function () {
15
+ return typeof window !== 'undefined';
16
+ };
17
+ exports.windowExists = windowExists;
18
+ var documentExists = function () {
19
+ return typeof document !== 'undefined';
20
+ };
21
+ exports.documentExists = documentExists;
22
+ var processExists = function () {
23
+ return typeof process !== 'undefined';
24
+ };
25
+ exports.processExists = processExists;
26
+ var keyPrefixMatch = function (object, prefix) {
27
+ return !!Object.keys(object).find(function (key) { return key.startsWith(prefix); });
28
+ };
29
+ exports.keyPrefixMatch = keyPrefixMatch;
@@ -0,0 +1,2 @@
1
+ import { Framework } from '../types';
2
+ export declare function detect(): Framework;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.detect = void 0;
6
+ var types_1 = require("../types");
7
+ var React_1 = require("./React");
8
+ var Vue_1 = require("./Vue");
9
+ var Svelte_1 = require("./Svelte");
10
+ var Next_1 = require("./Next");
11
+ var Nuxt_1 = require("./Nuxt");
12
+ var Angular_1 = require("./Angular");
13
+ var ReactNative_1 = require("./ReactNative");
14
+ var Expo_1 = require("./Expo");
15
+ var Web_1 = require("./Web");
16
+ // These are in the order of detection where when both are detectable, the early Framework will be reported
17
+ var detectionMap = [
18
+ // First, detect mobile
19
+ { platform: types_1.Framework.Expo, detectionMethod: Expo_1.expoDetect },
20
+ { platform: types_1.Framework.ReactNative, detectionMethod: ReactNative_1.reactNativeDetect },
21
+ // Next, detect web frameworks
22
+ { platform: types_1.Framework.NextJs, detectionMethod: Next_1.nextWebDetect },
23
+ { platform: types_1.Framework.Nuxt, detectionMethod: Nuxt_1.nuxtWebDetect },
24
+ { platform: types_1.Framework.Angular, detectionMethod: Angular_1.angularWebDetect },
25
+ { platform: types_1.Framework.React, detectionMethod: React_1.reactWebDetect },
26
+ { platform: types_1.Framework.VueJs, detectionMethod: Vue_1.vueWebDetect },
27
+ { platform: types_1.Framework.Svelte, detectionMethod: Svelte_1.svelteWebDetect },
28
+ { platform: types_1.Framework.WebUnknown, detectionMethod: Web_1.webDetect },
29
+ // Last, detect ssr frameworks
30
+ { platform: types_1.Framework.NextJsSSR, detectionMethod: Next_1.nextSSRDetect },
31
+ { platform: types_1.Framework.NuxtSSR, detectionMethod: Nuxt_1.nuxtSSRDetect },
32
+ { platform: types_1.Framework.ReactSSR, detectionMethod: React_1.reactSSRDetect },
33
+ { platform: types_1.Framework.VueJsSSR, detectionMethod: Vue_1.vueSSRDetect },
34
+ { platform: types_1.Framework.AngularSSR, detectionMethod: Angular_1.angularSSRDetect },
35
+ { platform: types_1.Framework.SvelteSSR, detectionMethod: Svelte_1.svelteSSRDetect },
36
+ ];
37
+ function detect() {
38
+ var _a;
39
+ return (((_a = detectionMap.find(function (detectionEntry) { return detectionEntry.detectionMethod(); })) === null || _a === void 0 ? void 0 : _a.platform) || types_1.Framework.ServerSideUnknown);
40
+ }
41
+ exports.detect = detect;
@@ -1,7 +1,12 @@
1
- export declare const Platform: {
1
+ import { CustomUserAgentDetails, Framework } from './types';
2
+ import { UserAgent as AWSUserAgent } from '@aws-sdk/types';
3
+ declare class PlatformBuilder {
2
4
  userAgent: string;
3
- product: string;
4
- navigator: any;
5
- isReactNative: boolean;
6
- };
7
- export declare const getAmplifyUserAgent: (content?: string) => string;
5
+ get framework(): Framework;
6
+ get isReactNative(): boolean;
7
+ observeFrameworkChanges(fcn: () => void): void;
8
+ }
9
+ export declare const Platform: PlatformBuilder;
10
+ export declare const getAmplifyUserAgent: ({ category, action, framework, }?: CustomUserAgentDetails) => AWSUserAgent;
11
+ export declare const getAmplifyUserAgentString: (customUserAgentDetails?: CustomUserAgentDetails) => string;
12
+ export {};
@@ -1,31 +1,70 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAmplifyUserAgent = exports.Platform = void 0;
4
2
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
3
  // SPDX-License-Identifier: Apache-2.0
6
- var version_1 = require("./version");
7
- var BASE_USER_AGENT = "aws-amplify/".concat(version_1.version);
8
- exports.Platform = {
9
- userAgent: "".concat(BASE_USER_AGENT, " js"),
10
- product: '',
11
- navigator: null,
12
- isReactNative: false,
4
+ var __read = (this && this.__read) || function (o, n) {
5
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
6
+ if (!m) return o;
7
+ var i = m.call(o), r, ar = [], e;
8
+ try {
9
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
10
+ }
11
+ catch (error) { e = { error: error }; }
12
+ finally {
13
+ try {
14
+ if (r && !r.done && (m = i["return"])) m.call(i);
15
+ }
16
+ finally { if (e) throw e.error; }
17
+ }
18
+ return ar;
13
19
  };
14
- if (typeof navigator !== 'undefined' && navigator.product) {
15
- exports.Platform.product = navigator.product || '';
16
- exports.Platform.navigator = navigator || null;
17
- switch (navigator.product) {
18
- case 'ReactNative':
19
- exports.Platform.userAgent = "".concat(BASE_USER_AGENT, " react-native");
20
- exports.Platform.isReactNative = true;
21
- break;
22
- default:
23
- exports.Platform.userAgent = "".concat(BASE_USER_AGENT, " js");
24
- exports.Platform.isReactNative = false;
25
- break;
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.getAmplifyUserAgentString = exports.getAmplifyUserAgent = exports.Platform = void 0;
22
+ var types_1 = require("./types");
23
+ var version_1 = require("./version");
24
+ var detectFramework_1 = require("./detectFramework");
25
+ var BASE_USER_AGENT = "aws-amplify";
26
+ var PlatformBuilder = /** @class */ (function () {
27
+ function PlatformBuilder() {
28
+ this.userAgent = "".concat(BASE_USER_AGENT, "/").concat(version_1.version);
26
29
  }
27
- }
28
- var getAmplifyUserAgent = function (content) {
29
- return "".concat(exports.Platform.userAgent).concat(content ? content : '');
30
+ Object.defineProperty(PlatformBuilder.prototype, "framework", {
31
+ get: function () {
32
+ return (0, detectFramework_1.detectFramework)();
33
+ },
34
+ enumerable: false,
35
+ configurable: true
36
+ });
37
+ Object.defineProperty(PlatformBuilder.prototype, "isReactNative", {
38
+ get: function () {
39
+ return this.framework === types_1.Framework.ReactNative;
40
+ },
41
+ enumerable: false,
42
+ configurable: true
43
+ });
44
+ PlatformBuilder.prototype.observeFrameworkChanges = function (fcn) {
45
+ (0, detectFramework_1.observeFrameworkChanges)(fcn);
46
+ };
47
+ return PlatformBuilder;
48
+ }());
49
+ exports.Platform = new PlatformBuilder();
50
+ var getAmplifyUserAgent = function (_a) {
51
+ var _b = _a === void 0 ? {} : _a, category = _b.category, action = _b.action, framework = _b.framework;
52
+ var userAgent = [[BASE_USER_AGENT, version_1.version]];
53
+ if (category) {
54
+ userAgent.push([category, action]);
55
+ }
56
+ userAgent.push(['framework', (0, detectFramework_1.detectFramework)()]);
57
+ return userAgent;
30
58
  };
31
59
  exports.getAmplifyUserAgent = getAmplifyUserAgent;
60
+ var getAmplifyUserAgentString = function (customUserAgentDetails) {
61
+ var userAgent = (0, exports.getAmplifyUserAgent)(customUserAgentDetails);
62
+ var userAgentString = userAgent
63
+ .map(function (_a) {
64
+ var _b = __read(_a, 2), agentKey = _b[0], agentValue = _b[1];
65
+ return "".concat(agentKey, "/").concat(agentValue);
66
+ })
67
+ .join(' ');
68
+ return userAgentString;
69
+ };
70
+ exports.getAmplifyUserAgentString = getAmplifyUserAgentString;
@@ -0,0 +1,104 @@
1
+ export declare enum Framework {
2
+ WebUnknown = "0",
3
+ React = "1",
4
+ NextJs = "2",
5
+ Angular = "3",
6
+ VueJs = "4",
7
+ Nuxt = "5",
8
+ Svelte = "6",
9
+ ServerSideUnknown = "100",
10
+ ReactSSR = "101",
11
+ NextJsSSR = "102",
12
+ AngularSSR = "103",
13
+ VueJsSSR = "104",
14
+ NuxtSSR = "105",
15
+ SvelteSSR = "106",
16
+ ReactNative = "201",
17
+ Expo = "202"
18
+ }
19
+ export declare enum Category {
20
+ API = "api",
21
+ Auth = "auth",
22
+ Analytics = "analytics",
23
+ DataStore = "datastore",
24
+ Geo = "geo",
25
+ InAppMessaging = "inappmessaging",
26
+ Interactions = "interactions",
27
+ Predictions = "predictions",
28
+ PubSub = "pubsub",
29
+ PushNotification = "pushnotification",
30
+ Storage = "storage"
31
+ }
32
+ export declare enum AnalyticsAction {
33
+ Record = "1",
34
+ UpdateEndpoint = "2"
35
+ }
36
+ export declare enum ApiAction {
37
+ GraphQl = "1",
38
+ Get = "2",
39
+ Post = "3",
40
+ Put = "4",
41
+ Patch = "5",
42
+ Del = "6",
43
+ Head = "7"
44
+ }
45
+ export declare enum AuthAction {
46
+ FederatedSignIn = "30"
47
+ }
48
+ export declare enum DataStoreAction {
49
+ Subscribe = "1",
50
+ GraphQl = "2"
51
+ }
52
+ export declare enum GeoAction {
53
+ None = "0"
54
+ }
55
+ export declare enum InAppMessagingAction {
56
+ None = "0"
57
+ }
58
+ export declare enum InteractionsAction {
59
+ None = "0"
60
+ }
61
+ export declare enum PredictionsAction {
62
+ Convert = "1",
63
+ Identify = "2",
64
+ Interpret = "3"
65
+ }
66
+ export declare enum PubSubAction {
67
+ Subscribe = "1"
68
+ }
69
+ export declare enum PushNotificationAction {
70
+ None = "0"
71
+ }
72
+ export declare enum StorageAction {
73
+ Put = "1",
74
+ Get = "2",
75
+ List = "3",
76
+ Copy = "4",
77
+ Remove = "5",
78
+ GetProperties = "6"
79
+ }
80
+ type ActionMap = {
81
+ [Category.Auth]: AuthAction;
82
+ [Category.API]: ApiAction;
83
+ [Category.Analytics]: AnalyticsAction;
84
+ [Category.DataStore]: DataStoreAction;
85
+ [Category.Geo]: GeoAction;
86
+ [Category.InAppMessaging]: InAppMessagingAction;
87
+ [Category.Interactions]: InteractionsAction;
88
+ [Category.Predictions]: PredictionsAction;
89
+ [Category.PubSub]: PubSubAction;
90
+ [Category.PushNotification]: PushNotificationAction;
91
+ [Category.Storage]: StorageAction;
92
+ };
93
+ type UserAgentDetailsWithCategory<T extends Category> = CustomUserAgentDetailsBase & {
94
+ category: T;
95
+ action: T extends keyof ActionMap ? ActionMap[T] : never;
96
+ };
97
+ type CustomUserAgentDetailsBase = {
98
+ framework?: Framework;
99
+ };
100
+ export type CustomUserAgentDetails = (CustomUserAgentDetailsBase & {
101
+ category?: never;
102
+ action?: never;
103
+ }) | UserAgentDetailsWithCategory<Category.API> | UserAgentDetailsWithCategory<Category.Auth> | UserAgentDetailsWithCategory<Category.Analytics> | UserAgentDetailsWithCategory<Category.DataStore> | UserAgentDetailsWithCategory<Category.Geo> | UserAgentDetailsWithCategory<Category.Interactions> | UserAgentDetailsWithCategory<Category.InAppMessaging> | UserAgentDetailsWithCategory<Category.Predictions> | UserAgentDetailsWithCategory<Category.PubSub> | UserAgentDetailsWithCategory<Category.PushNotification> | UserAgentDetailsWithCategory<Category.Storage>;
104
+ export {};