@aws-amplify/core 5.4.1-unstable.c1fa9c7.8 → 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 (89) 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/index.d.ts +2 -1
  34. package/lib/index.js +17 -2
  35. package/lib/tsconfig.tsbuildinfo +1 -1
  36. package/lib-esm/AwsClients/CognitoIdentity/base.js +6 -2
  37. package/lib-esm/AwsClients/Pinpoint/base.js +2 -2
  38. package/lib-esm/Platform/detectFramework.d.ts +7 -0
  39. package/lib-esm/Platform/detectFramework.js +47 -0
  40. package/lib-esm/Platform/detection/Angular.d.ts +2 -0
  41. package/lib-esm/Platform/detection/Angular.js +18 -0
  42. package/lib-esm/Platform/detection/Expo.d.ts +1 -0
  43. package/lib-esm/Platform/detection/Expo.js +8 -0
  44. package/lib-esm/Platform/detection/Next.d.ts +2 -0
  45. package/lib-esm/Platform/detection/Next.js +12 -0
  46. package/lib-esm/Platform/detection/Nuxt.d.ts +2 -0
  47. package/lib-esm/Platform/detection/Nuxt.js +13 -0
  48. package/lib-esm/Platform/detection/React.d.ts +2 -0
  49. package/lib-esm/Platform/detection/React.js +19 -0
  50. package/lib-esm/Platform/detection/ReactNative.d.ts +1 -0
  51. package/lib-esm/Platform/detection/ReactNative.js +8 -0
  52. package/lib-esm/Platform/detection/Svelte.d.ts +2 -0
  53. package/lib-esm/Platform/detection/Svelte.js +12 -0
  54. package/lib-esm/Platform/detection/Vue.d.ts +2 -0
  55. package/lib-esm/Platform/detection/Vue.js +10 -0
  56. package/lib-esm/Platform/detection/Web.d.ts +1 -0
  57. package/lib-esm/Platform/detection/Web.js +6 -0
  58. package/lib-esm/Platform/detection/helpers.d.ts +6 -0
  59. package/lib-esm/Platform/detection/helpers.js +20 -0
  60. package/lib-esm/Platform/detection/index.d.ts +2 -0
  61. package/lib-esm/Platform/detection/index.js +37 -0
  62. package/lib-esm/Platform/index.d.ts +11 -6
  63. package/lib-esm/Platform/index.js +60 -22
  64. package/lib-esm/Platform/types.d.ts +104 -0
  65. package/lib-esm/Platform/types.js +130 -0
  66. package/lib-esm/Platform/version.d.ts +1 -1
  67. package/lib-esm/Platform/version.js +1 -1
  68. package/lib-esm/index.d.ts +2 -1
  69. package/lib-esm/index.js +2 -1
  70. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  71. package/package.json +3 -3
  72. package/src/AwsClients/CognitoIdentity/base.ts +7 -2
  73. package/src/AwsClients/Pinpoint/base.ts +2 -2
  74. package/src/Platform/detectFramework.ts +57 -0
  75. package/src/Platform/detection/Angular.ts +26 -0
  76. package/src/Platform/detection/Expo.ts +11 -0
  77. package/src/Platform/detection/Next.ts +18 -0
  78. package/src/Platform/detection/Nuxt.ts +19 -0
  79. package/src/Platform/detection/React.ts +26 -0
  80. package/src/Platform/detection/ReactNative.ts +12 -0
  81. package/src/Platform/detection/Svelte.ts +18 -0
  82. package/src/Platform/detection/Vue.ts +13 -0
  83. package/src/Platform/detection/Web.ts +8 -0
  84. package/src/Platform/detection/helpers.ts +26 -0
  85. package/src/Platform/detection/index.ts +48 -0
  86. package/src/Platform/index.ts +42 -21
  87. package/src/Platform/types.ts +160 -0
  88. package/src/Platform/version.ts +1 -1
  89. package/src/index.ts +21 -1
@@ -0,0 +1,12 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // Tested with react-native 0.17.7
5
+
6
+ export function reactNativeDetect() {
7
+ return (
8
+ typeof navigator !== 'undefined' &&
9
+ typeof navigator.product !== 'undefined' &&
10
+ navigator.product === 'ReactNative'
11
+ );
12
+ }
@@ -0,0 +1,18 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { keyPrefixMatch, processExists, windowExists } from './helpers';
5
+
6
+ // Tested with svelte 3.59
7
+
8
+ export function svelteWebDetect() {
9
+ return windowExists() && keyPrefixMatch(window, '__SVELTE');
10
+ }
11
+
12
+ export function svelteSSRDetect() {
13
+ return (
14
+ processExists() &&
15
+ typeof process.env !== 'undefined' &&
16
+ !!Object.keys(process.env).find(key => key.includes('svelte'))
17
+ );
18
+ }
@@ -0,0 +1,13 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { globalExists, keyPrefixMatch, windowExists } from './helpers';
5
+
6
+ // Tested with vue 3.3.2
7
+
8
+ export function vueWebDetect() {
9
+ return windowExists() && keyPrefixMatch(window, '__VUE');
10
+ }
11
+ export function vueSSRDetect() {
12
+ return globalExists() && keyPrefixMatch(global, '__VUE');
13
+ }
@@ -0,0 +1,8 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { windowExists } from './helpers';
5
+
6
+ export function webDetect() {
7
+ return windowExists();
8
+ }
@@ -0,0 +1,26 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export const globalExists = () => {
5
+ return typeof global !== 'undefined';
6
+ };
7
+
8
+ export const globalThisExists = () => {
9
+ return typeof globalThis !== 'undefined';
10
+ };
11
+
12
+ export const windowExists = () => {
13
+ return typeof window !== 'undefined';
14
+ };
15
+
16
+ export const documentExists = () => {
17
+ return typeof document !== 'undefined';
18
+ };
19
+
20
+ export const processExists = () => {
21
+ return typeof process !== 'undefined';
22
+ };
23
+
24
+ export const keyPrefixMatch = (object: object, prefix: string) => {
25
+ return !!Object.keys(object).find(key => key.startsWith(prefix));
26
+ };
@@ -0,0 +1,48 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { Framework } from '../types';
5
+
6
+ import { reactWebDetect, reactSSRDetect } from './React';
7
+ import { vueWebDetect, vueSSRDetect } from './Vue';
8
+ import { svelteWebDetect, svelteSSRDetect } from './Svelte';
9
+ import { nextWebDetect, nextSSRDetect } from './Next';
10
+ import { nuxtWebDetect, nuxtSSRDetect } from './Nuxt';
11
+ import { angularWebDetect, angularSSRDetect } from './Angular';
12
+ import { reactNativeDetect } from './ReactNative';
13
+ import { expoDetect } from './Expo';
14
+ import { webDetect } from './Web';
15
+
16
+ type PlatformDetectionEntry = {
17
+ platform: Framework;
18
+ detectionMethod: () => boolean;
19
+ };
20
+
21
+ // These are in the order of detection where when both are detectable, the early Framework will be reported
22
+ const detectionMap: PlatformDetectionEntry[] = [
23
+ // First, detect mobile
24
+ { platform: Framework.Expo, detectionMethod: expoDetect },
25
+ { platform: Framework.ReactNative, detectionMethod: reactNativeDetect },
26
+ // Next, detect web frameworks
27
+ { platform: Framework.NextJs, detectionMethod: nextWebDetect },
28
+ { platform: Framework.Nuxt, detectionMethod: nuxtWebDetect },
29
+ { platform: Framework.Angular, detectionMethod: angularWebDetect },
30
+ { platform: Framework.React, detectionMethod: reactWebDetect },
31
+ { platform: Framework.VueJs, detectionMethod: vueWebDetect },
32
+ { platform: Framework.Svelte, detectionMethod: svelteWebDetect },
33
+ { platform: Framework.WebUnknown, detectionMethod: webDetect },
34
+ // Last, detect ssr frameworks
35
+ { platform: Framework.NextJsSSR, detectionMethod: nextSSRDetect },
36
+ { platform: Framework.NuxtSSR, detectionMethod: nuxtSSRDetect },
37
+ { platform: Framework.ReactSSR, detectionMethod: reactSSRDetect },
38
+ { platform: Framework.VueJsSSR, detectionMethod: vueSSRDetect },
39
+ { platform: Framework.AngularSSR, detectionMethod: angularSSRDetect },
40
+ { platform: Framework.SvelteSSR, detectionMethod: svelteSSRDetect },
41
+ ];
42
+
43
+ export function detect() {
44
+ return (
45
+ detectionMap.find(detectionEntry => detectionEntry.detectionMethod())
46
+ ?.platform || Framework.ServerSideUnknown
47
+ );
48
+ }
@@ -1,30 +1,51 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { CustomUserAgentDetails, Framework } from './types';
3
5
  import { version } from './version';
6
+ import { detectFramework, observeFrameworkChanges } from './detectFramework';
7
+ import { UserAgent as AWSUserAgent } from '@aws-sdk/types';
4
8
 
5
- const BASE_USER_AGENT = `aws-amplify/${version}`;
9
+ const BASE_USER_AGENT = `aws-amplify`;
6
10
 
7
- export const Platform = {
8
- userAgent: `${BASE_USER_AGENT} js`,
9
- product: '',
10
- navigator: null,
11
- isReactNative: false,
12
- };
13
- if (typeof navigator !== 'undefined' && navigator.product) {
14
- Platform.product = navigator.product || '';
15
- Platform.navigator = navigator || null;
16
- switch (navigator.product) {
17
- case 'ReactNative':
18
- Platform.userAgent = `${BASE_USER_AGENT} react-native`;
19
- Platform.isReactNative = true;
20
- break;
21
- default:
22
- Platform.userAgent = `${BASE_USER_AGENT} js`;
23
- Platform.isReactNative = false;
24
- break;
11
+ class PlatformBuilder {
12
+ userAgent = `${BASE_USER_AGENT}/${version}`;
13
+ get framework() {
14
+ return detectFramework();
15
+ }
16
+
17
+ get isReactNative() {
18
+ return this.framework === Framework.ReactNative;
19
+ }
20
+
21
+ observeFrameworkChanges(fcn: () => void) {
22
+ observeFrameworkChanges(fcn);
25
23
  }
26
24
  }
27
25
 
28
- export const getAmplifyUserAgent = (content?: string) => {
29
- return `${Platform.userAgent}${content ? content : ''}`;
26
+ export const Platform = new PlatformBuilder();
27
+
28
+ export const getAmplifyUserAgent = ({
29
+ category,
30
+ action,
31
+ framework,
32
+ }: CustomUserAgentDetails = {}): AWSUserAgent => {
33
+ const userAgent: AWSUserAgent = [[BASE_USER_AGENT, version]];
34
+ if (category) {
35
+ userAgent.push([category, action]);
36
+ }
37
+ userAgent.push(['framework', detectFramework()]);
38
+
39
+ return userAgent;
40
+ };
41
+
42
+ export const getAmplifyUserAgentString = (
43
+ customUserAgentDetails?: CustomUserAgentDetails
44
+ ): string => {
45
+ const userAgent = getAmplifyUserAgent(customUserAgentDetails);
46
+ const userAgentString = userAgent
47
+ .map(([agentKey, agentValue]) => `${agentKey}/${agentValue}`)
48
+ .join(' ');
49
+
50
+ return userAgentString;
30
51
  };
@@ -0,0 +1,160 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export enum Framework {
5
+ // < 100 - Web frameworks
6
+ WebUnknown = '0',
7
+ React = '1',
8
+ NextJs = '2',
9
+ Angular = '3',
10
+ VueJs = '4',
11
+ Nuxt = '5',
12
+ Svelte = '6',
13
+
14
+ // 100s - Server side frameworks
15
+ ServerSideUnknown = '100',
16
+ ReactSSR = '101',
17
+ NextJsSSR = '102',
18
+ AngularSSR = '103',
19
+ VueJsSSR = '104',
20
+ NuxtSSR = '105',
21
+ SvelteSSR = '106',
22
+
23
+ // 200s - Mobile framework
24
+ ReactNative = '201',
25
+ Expo = '202',
26
+ }
27
+
28
+ export enum Category {
29
+ API = 'api',
30
+ Auth = 'auth',
31
+ Analytics = 'analytics',
32
+ DataStore = 'datastore',
33
+ Geo = 'geo',
34
+ InAppMessaging = 'inappmessaging',
35
+ Interactions = 'interactions',
36
+ Predictions = 'predictions',
37
+ PubSub = 'pubsub',
38
+ PushNotification = 'pushnotification',
39
+ Storage = 'storage',
40
+ }
41
+
42
+ export enum AnalyticsAction {
43
+ Record = '1',
44
+ UpdateEndpoint = '2',
45
+ }
46
+ export enum ApiAction {
47
+ GraphQl = '1',
48
+ Get = '2',
49
+ Post = '3',
50
+ Put = '4',
51
+ Patch = '5',
52
+ Del = '6',
53
+ Head = '7',
54
+ }
55
+ export enum AuthAction {
56
+ // SignUp = '1',
57
+ // ConfirmSignUp = '2',
58
+ // ResendSignUp = '3',
59
+ // SignIn = '4',
60
+ // GetMFAOptions = '5',
61
+ // GetPreferredMFA = '6',
62
+ // SetPreferredMFA = '7',
63
+ // DisableSMS = '8',
64
+ // EnableSMS = '9',
65
+ // SetupTOTP = '10',
66
+ // VerifyTotpToken = '11',
67
+ // ConfirmSignIn = '12',
68
+ // CompleteNewPassword = '13',
69
+ // SendCustomChallengeAnswer = '14',
70
+ // DeleteUserAttributes = '15',
71
+ // DeleteUser = '16',
72
+ // UpdateUserAttributes = '17',
73
+ // UserAttributes = '18',
74
+ // CurrentUserPoolUser = '19',
75
+ // CurrentAuthenticatedUser = '20',
76
+ // CurrentSession = '21',
77
+ // VerifyUserAttribute = '22',
78
+ // VerifyUserAttributeSubmit = '23',
79
+ // VerifyCurrentUserAttribute = '24',
80
+ // VerifyCurrentUserAttributeSubmit = '25',
81
+ // SignOut = '26',
82
+ // ChangePassword = '27',
83
+ // ForgotPassword = '28',
84
+ // ForgotPasswordSubmit = '29',
85
+ FederatedSignIn = '30',
86
+ // CurrentUserInfo = '31',
87
+ // RememberDevice = '32',
88
+ // ForgetDevice = '33',
89
+ // FetchDevices = '34',
90
+ }
91
+ export enum DataStoreAction {
92
+ Subscribe = '1',
93
+ GraphQl = '2',
94
+ }
95
+ export enum GeoAction {
96
+ None = '0',
97
+ }
98
+ export enum InAppMessagingAction {
99
+ None = '0',
100
+ }
101
+ export enum InteractionsAction {
102
+ None = '0',
103
+ }
104
+ export enum PredictionsAction {
105
+ Convert = '1',
106
+ Identify = '2',
107
+ Interpret = '3',
108
+ }
109
+ export enum PubSubAction {
110
+ Subscribe = '1',
111
+ }
112
+ export enum PushNotificationAction {
113
+ None = '0',
114
+ }
115
+ export enum StorageAction {
116
+ Put = '1',
117
+ Get = '2',
118
+ List = '3',
119
+ Copy = '4',
120
+ Remove = '5',
121
+ GetProperties = '6',
122
+ }
123
+
124
+ type ActionMap = {
125
+ [Category.Auth]: AuthAction;
126
+ [Category.API]: ApiAction;
127
+ [Category.Analytics]: AnalyticsAction;
128
+ [Category.DataStore]: DataStoreAction;
129
+ [Category.Geo]: GeoAction;
130
+ [Category.InAppMessaging]: InAppMessagingAction;
131
+ [Category.Interactions]: InteractionsAction;
132
+ [Category.Predictions]: PredictionsAction;
133
+ [Category.PubSub]: PubSubAction;
134
+ [Category.PushNotification]: PushNotificationAction;
135
+ [Category.Storage]: StorageAction;
136
+ };
137
+
138
+ type UserAgentDetailsWithCategory<T extends Category> =
139
+ CustomUserAgentDetailsBase & {
140
+ category: T;
141
+ action: T extends keyof ActionMap ? ActionMap[T] : never;
142
+ };
143
+
144
+ type CustomUserAgentDetailsBase = {
145
+ framework?: Framework;
146
+ };
147
+
148
+ export type CustomUserAgentDetails =
149
+ | (CustomUserAgentDetailsBase & { category?: never; action?: never })
150
+ | UserAgentDetailsWithCategory<Category.API>
151
+ | UserAgentDetailsWithCategory<Category.Auth>
152
+ | UserAgentDetailsWithCategory<Category.Analytics>
153
+ | UserAgentDetailsWithCategory<Category.DataStore>
154
+ | UserAgentDetailsWithCategory<Category.Geo>
155
+ | UserAgentDetailsWithCategory<Category.Interactions>
156
+ | UserAgentDetailsWithCategory<Category.InAppMessaging>
157
+ | UserAgentDetailsWithCategory<Category.Predictions>
158
+ | UserAgentDetailsWithCategory<Category.PubSub>
159
+ | UserAgentDetailsWithCategory<Category.PushNotification>
160
+ | UserAgentDetailsWithCategory<Category.Storage>;
@@ -1,2 +1,2 @@
1
1
  // generated by genversion
2
- export const version = '5.2.8-unstable.c1fa9c7.2+c1fa9c736';
2
+ export const version = '5.3.0';
package/src/index.ts CHANGED
@@ -35,7 +35,27 @@ export { ServiceWorker } from './ServiceWorker';
35
35
  export { ICredentials } from './types';
36
36
  export { StorageHelper, MemoryStorage } from './StorageHelper';
37
37
  export { UniversalStorage } from './UniversalStorage';
38
- export { Platform, getAmplifyUserAgent } from './Platform';
38
+ export {
39
+ Platform,
40
+ getAmplifyUserAgent,
41
+ getAmplifyUserAgentString,
42
+ } from './Platform';
43
+ export {
44
+ ApiAction,
45
+ AuthAction,
46
+ AnalyticsAction,
47
+ Category,
48
+ CustomUserAgentDetails,
49
+ DataStoreAction,
50
+ Framework,
51
+ GeoAction,
52
+ InteractionsAction,
53
+ InAppMessagingAction,
54
+ PredictionsAction,
55
+ PubSubAction,
56
+ PushNotificationAction,
57
+ StorageAction,
58
+ } from './Platform/types';
39
59
  export {
40
60
  INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER,
41
61
  USER_AGENT_HEADER,