@aws-amplify/core 6.0.1-console-preview.d7e0545.0 → 6.0.1-console-preview.7739091.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 (153) hide show
  1. package/lib/Cache/Utils/CacheUtils.js +2 -4
  2. package/lib/Platform/version.d.ts +1 -1
  3. package/lib/Platform/version.js +1 -1
  4. package/lib/RNComponents/index.d.ts +1 -1
  5. package/lib/RNComponents/index.js +4 -4
  6. package/lib/ServiceWorker/ServiceWorker.js +1 -1
  7. package/lib/Util/JS.d.ts +1 -4
  8. package/lib/Util/JS.js +4 -11
  9. package/lib/Util/Reachability.js +0 -3
  10. package/lib/clients/handlers/fetch.d.ts +0 -1
  11. package/lib/clients/handlers/fetch.js +0 -1
  12. package/lib/index.d.ts +1 -1
  13. package/lib/index.js +6 -8
  14. package/lib/libraryUtils.d.ts +1 -2
  15. package/lib/libraryUtils.js +3 -6
  16. package/lib/parseAWSExports.js +20 -1
  17. package/lib/providers/pinpoint/apis/record.d.ts +2 -2
  18. package/lib/providers/pinpoint/apis/record.js +3 -3
  19. package/lib/providers/pinpoint/apis/updateEndpoint.d.ts +2 -2
  20. package/lib/providers/pinpoint/types/pinpoint.d.ts +2 -2
  21. package/lib/singleton/API/types.d.ts +34 -0
  22. package/lib/singleton/API/types.js +2 -0
  23. package/lib/singleton/Auth/index.js +6 -16
  24. package/lib/singleton/Auth/types.d.ts +2 -2
  25. package/lib/singleton/Storage/types.d.ts +5 -0
  26. package/lib/singleton/types.d.ts +4 -1
  27. package/lib/{StorageHelper/cookieStorage.d.ts → storage/CookieStorage.d.ts} +4 -3
  28. package/lib/{StorageHelper/cookieStorage.js → storage/CookieStorage.js} +35 -83
  29. package/lib/storage/CookieStorage.native.d.ts +7 -0
  30. package/lib/storage/CookieStorage.native.js +32 -0
  31. package/lib/storage/DefaultStorage.d.ts +7 -0
  32. package/lib/storage/DefaultStorage.js +33 -0
  33. package/{lib-esm/StorageHelper/localStorage.d.ts → lib/storage/DefaultStorage.native.d.ts} +7 -6
  34. package/lib/{StorageHelper/sessionStorage.js → storage/DefaultStorage.native.js} +46 -43
  35. package/lib/storage/InMemoryStorage.d.ts +12 -0
  36. package/lib/storage/InMemoryStorage.js +41 -0
  37. package/lib/{StorageHelper/sessionStorage.d.ts → storage/KeyValueStorage.d.ts} +5 -4
  38. package/lib/{StorageHelper/localStorage.js → storage/KeyValueStorage.js} +13 -15
  39. package/lib/storage/SessionStorage.d.ts +7 -0
  40. package/lib/storage/SessionStorage.js +33 -0
  41. package/lib/storage/index.d.ts +7 -0
  42. package/lib/storage/index.js +14 -0
  43. package/lib/storage/utils.d.ts +10 -0
  44. package/lib/storage/utils.js +26 -0
  45. package/lib/tsconfig.tsbuildinfo +1 -1
  46. package/lib/types/storage.d.ts +3 -0
  47. package/lib-esm/Cache/Utils/CacheUtils.js +2 -4
  48. package/lib-esm/Platform/version.d.ts +1 -1
  49. package/lib-esm/Platform/version.js +1 -1
  50. package/lib-esm/RNComponents/index.d.ts +1 -1
  51. package/lib-esm/RNComponents/index.js +5 -5
  52. package/lib-esm/ServiceWorker/ServiceWorker.js +2 -2
  53. package/lib-esm/Util/JS.d.ts +1 -4
  54. package/lib-esm/Util/JS.js +2 -9
  55. package/lib-esm/Util/Reachability.js +1 -4
  56. package/lib-esm/clients/handlers/fetch.d.ts +0 -1
  57. package/lib-esm/clients/handlers/fetch.js +0 -1
  58. package/lib-esm/index.d.ts +1 -1
  59. package/lib-esm/index.js +1 -1
  60. package/lib-esm/libraryUtils.d.ts +1 -2
  61. package/lib-esm/libraryUtils.js +1 -2
  62. package/lib-esm/parseAWSExports.js +20 -1
  63. package/lib-esm/providers/pinpoint/apis/record.d.ts +2 -2
  64. package/lib-esm/providers/pinpoint/apis/record.js +3 -3
  65. package/lib-esm/providers/pinpoint/apis/updateEndpoint.d.ts +2 -2
  66. package/lib-esm/providers/pinpoint/types/pinpoint.d.ts +2 -2
  67. package/lib-esm/singleton/API/types.d.ts +34 -0
  68. package/lib-esm/singleton/API/types.js +1 -0
  69. package/lib-esm/singleton/Auth/index.js +6 -16
  70. package/lib-esm/singleton/Auth/types.d.ts +2 -2
  71. package/lib-esm/singleton/Storage/types.d.ts +5 -0
  72. package/lib-esm/singleton/types.d.ts +4 -1
  73. package/lib-esm/{StorageHelper/cookieStorage.d.ts → storage/CookieStorage.d.ts} +4 -3
  74. package/lib-esm/{StorageHelper/cookieStorage.js → storage/CookieStorage.js} +36 -61
  75. package/lib-esm/storage/CookieStorage.native.d.ts +7 -0
  76. package/lib-esm/storage/CookieStorage.native.js +29 -0
  77. package/lib-esm/storage/DefaultStorage.d.ts +7 -0
  78. package/lib-esm/storage/DefaultStorage.js +30 -0
  79. package/{lib/StorageHelper/localStorage.d.ts → lib-esm/storage/DefaultStorage.native.d.ts} +7 -6
  80. package/lib-esm/{StorageHelper/sessionStorage.js → storage/DefaultStorage.native.js} +45 -42
  81. package/lib-esm/storage/InMemoryStorage.d.ts +12 -0
  82. package/lib-esm/storage/InMemoryStorage.js +38 -0
  83. package/lib-esm/{StorageHelper/sessionStorage.d.ts → storage/KeyValueStorage.d.ts} +5 -4
  84. package/lib-esm/{StorageHelper/localStorage.js → storage/KeyValueStorage.js} +12 -14
  85. package/lib-esm/storage/SessionStorage.d.ts +7 -0
  86. package/lib-esm/storage/SessionStorage.js +30 -0
  87. package/lib-esm/storage/index.d.ts +7 -0
  88. package/lib-esm/storage/index.js +10 -0
  89. package/lib-esm/storage/utils.d.ts +10 -0
  90. package/lib-esm/storage/utils.js +21 -0
  91. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  92. package/lib-esm/types/storage.d.ts +3 -0
  93. package/package.json +3 -5
  94. package/src/Cache/Utils/CacheUtils.ts +2 -4
  95. package/src/Platform/version.ts +1 -1
  96. package/src/RNComponents/index.ts +5 -5
  97. package/src/ServiceWorker/ServiceWorker.ts +2 -2
  98. package/src/Util/JS.ts +2 -13
  99. package/src/Util/Reachability.ts +1 -5
  100. package/src/clients/handlers/fetch.ts +0 -1
  101. package/src/index.ts +4 -6
  102. package/src/libraryUtils.ts +1 -2
  103. package/src/parseAWSExports.ts +26 -0
  104. package/src/providers/pinpoint/apis/record.ts +8 -8
  105. package/src/providers/pinpoint/apis/updateEndpoint.ts +2 -2
  106. package/src/providers/pinpoint/types/pinpoint.ts +7 -6
  107. package/src/singleton/API/types.ts +31 -0
  108. package/src/singleton/Auth/index.ts +1 -10
  109. package/src/singleton/Auth/types.ts +2 -2
  110. package/src/singleton/Storage/types.ts +6 -2
  111. package/src/singleton/types.ts +4 -1
  112. package/src/storage/CookieStorage.native.ts +13 -0
  113. package/src/storage/CookieStorage.ts +72 -0
  114. package/src/storage/DefaultStorage.native.ts +78 -0
  115. package/src/storage/DefaultStorage.ts +14 -0
  116. package/src/storage/InMemoryStorage.ts +36 -0
  117. package/src/{StorageHelper/sessionStorage.ts → storage/KeyValueStorage.ts} +10 -13
  118. package/src/storage/SessionStorage.ts +14 -0
  119. package/src/storage/index.ts +13 -0
  120. package/src/storage/utils.ts +22 -0
  121. package/src/types/storage.ts +4 -0
  122. package/lib/OAuthHelper/FacebookOAuth.d.ts +0 -6
  123. package/lib/OAuthHelper/FacebookOAuth.js +0 -124
  124. package/lib/OAuthHelper/GoogleOAuth.d.ts +0 -6
  125. package/lib/OAuthHelper/GoogleOAuth.js +0 -134
  126. package/lib/OAuthHelper/index.d.ts +0 -4
  127. package/lib/OAuthHelper/index.js +0 -9
  128. package/lib/StorageHelper/inMemoryStorage.d.ts +0 -10
  129. package/lib/StorageHelper/inMemoryStorage.js +0 -82
  130. package/lib/StorageHelper/index.d.ts +0 -45
  131. package/lib/StorageHelper/index.js +0 -83
  132. package/lib/StorageHelper/reactnative.d.ts +0 -83
  133. package/lib/StorageHelper/reactnative.js +0 -250
  134. package/lib-esm/OAuthHelper/FacebookOAuth.d.ts +0 -6
  135. package/lib-esm/OAuthHelper/FacebookOAuth.js +0 -121
  136. package/lib-esm/OAuthHelper/GoogleOAuth.d.ts +0 -6
  137. package/lib-esm/OAuthHelper/GoogleOAuth.js +0 -131
  138. package/lib-esm/OAuthHelper/index.d.ts +0 -4
  139. package/lib-esm/OAuthHelper/index.js +0 -6
  140. package/lib-esm/StorageHelper/inMemoryStorage.d.ts +0 -10
  141. package/lib-esm/StorageHelper/inMemoryStorage.js +0 -79
  142. package/lib-esm/StorageHelper/index.d.ts +0 -45
  143. package/lib-esm/StorageHelper/index.js +0 -76
  144. package/lib-esm/StorageHelper/reactnative.d.ts +0 -83
  145. package/lib-esm/StorageHelper/reactnative.js +0 -244
  146. package/src/OAuthHelper/FacebookOAuth.ts +0 -83
  147. package/src/OAuthHelper/GoogleOAuth.ts +0 -97
  148. package/src/OAuthHelper/index.ts +0 -7
  149. package/src/StorageHelper/cookieStorage.ts +0 -99
  150. package/src/StorageHelper/inMemoryStorage.ts +0 -32
  151. package/src/StorageHelper/index.ts +0 -78
  152. package/src/StorageHelper/localStorage.ts +0 -60
  153. package/src/StorageHelper/reactnative.ts +0 -182
@@ -1,4 +1,4 @@
1
- export { browserOrNode, filenameToContentType, generateRandomString, isEmpty, isStrictObject, isTextFile, isWebWorker, makeQuerablePromise, objectLessAttributes, sortByField, transferKeyToLowerCase, transferKeyToUpperCase, } from './Util/JS';
1
+ export { isBrowser, filenameToContentType, generateRandomString, isEmpty, isStrictObject, isTextFile, isWebWorker, makeQuerablePromise, objectLessAttributes, sortByField, transferKeyToLowerCase, transferKeyToUpperCase, } from './Util/JS';
2
2
  export { JWT, StrictUnion, CognitoIdentityPoolConfig, } from './singleton/Auth/types';
3
3
  export { decodeJWT, assertTokenProviderConfig, assertIdentityPooIdConfig, assertOAuthConfig, } from './singleton/Auth/utils';
4
4
  export { isTokenExpired } from './singleton/Auth';
@@ -14,7 +14,6 @@ export { ServiceWorker } from './ServiceWorker';
14
14
  export { AWS_CLOUDWATCH_CATEGORY, BackgroundManagerNotOpenError, BackgroundProcessManager, BackgroundProcessManagerState, DateUtils, Mutex, NO_CREDS_ERROR_STRING, NonRetryableError, RETRY_ERROR_CODES, Reachability, isNonRetryableError, jitteredBackoff, jitteredExponentialRetry, retry, urlSafeDecode, urlSafeEncode, } from './Util';
15
15
  export { asserts } from './Util/errors/AssertError';
16
16
  export { invalidParameter, missingConfig, AmplifyError, AmplifyErrorString, } from './Util/Errors';
17
- export { FacebookOAuth, GoogleOAuth } from './OAuthHelper';
18
17
  export { AppState, AsyncStorage, Linking } from './RNComponents';
19
18
  export { ErrorParams, AmplifyErrorMap, ServiceError } from './types';
20
19
  export { INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER, USER_AGENT_HEADER, } from './Util/Constants';
@@ -5,7 +5,7 @@ This file maps top-level exports from `@aws-amplify/core/internals/utils`. These
5
5
  utils for use throughout the library.
6
6
  */
7
7
  // JS utilities
8
- export { browserOrNode, filenameToContentType, generateRandomString, isEmpty, isStrictObject, isTextFile, isWebWorker, makeQuerablePromise, objectLessAttributes, sortByField, transferKeyToLowerCase, transferKeyToUpperCase, } from './Util/JS';
8
+ export { isBrowser, filenameToContentType, generateRandomString, isEmpty, isStrictObject, isTextFile, isWebWorker, makeQuerablePromise, objectLessAttributes, sortByField, transferKeyToLowerCase, transferKeyToUpperCase, } from './Util/JS';
9
9
  // Auth utilities
10
10
  export { decodeJWT, assertTokenProviderConfig, assertIdentityPooIdConfig, assertOAuthConfig, } from './singleton/Auth/utils';
11
11
  export { isTokenExpired } from './singleton/Auth';
@@ -26,7 +26,6 @@ export { ServiceWorker } from './ServiceWorker';
26
26
  export { AWS_CLOUDWATCH_CATEGORY, BackgroundManagerNotOpenError, BackgroundProcessManager, BackgroundProcessManagerState, DateUtils, Mutex, NO_CREDS_ERROR_STRING, NonRetryableError, RETRY_ERROR_CODES, Reachability, isNonRetryableError, jitteredBackoff, jitteredExponentialRetry, retry, urlSafeDecode, urlSafeEncode, } from './Util';
27
27
  export { asserts } from './Util/errors/AssertError';
28
28
  export { invalidParameter, missingConfig, AmplifyError, AmplifyErrorString, } from './Util/Errors';
29
- export { FacebookOAuth, GoogleOAuth } from './OAuthHelper';
30
29
  export { AppState, AsyncStorage, Linking } from './RNComponents';
31
30
  export { INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER, USER_AGENT_HEADER, } from './Util/Constants';
32
31
  export { fetchAuthSession } from './singleton/apis/internal/fetchAuthSession';
@@ -9,6 +9,11 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
+ var authTypeMapping = {
13
+ API_KEY: 'apiKey',
14
+ AWS_IAM: 'iam',
15
+ AMAZON_COGNITO_USER_POOLS: 'jwt',
16
+ };
12
17
  /**
13
18
  * This utility converts the `aws-exports.js` file generated by the Amplify CLI into a {@link ResourcesConfig} object
14
19
  * consumable by Amplify.
@@ -19,7 +24,7 @@ var __assign = (this && this.__assign) || function () {
19
24
  */
20
25
  export var parseAWSExports = function (config) {
21
26
  if (config === void 0) { config = {}; }
22
- var aws_cognito_identity_pool_id = config.aws_cognito_identity_pool_id, aws_cognito_sign_up_verification_method = config.aws_cognito_sign_up_verification_method, aws_mandatory_sign_in = config.aws_mandatory_sign_in, aws_mobile_analytics_app_id = config.aws_mobile_analytics_app_id, aws_mobile_analytics_app_region = config.aws_mobile_analytics_app_region, aws_user_files_s3_bucket = config.aws_user_files_s3_bucket, aws_user_files_s3_bucket_region = config.aws_user_files_s3_bucket_region, aws_user_files_s3_dangerously_connect_to_http_endpoint_for_testing = config.aws_user_files_s3_dangerously_connect_to_http_endpoint_for_testing, aws_user_pools_id = config.aws_user_pools_id, aws_user_pools_web_client_id = config.aws_user_pools_web_client_id, geo = config.geo, oauth = config.oauth;
27
+ var aws_appsync_apiKey = config.aws_appsync_apiKey, aws_appsync_authenticationType = config.aws_appsync_authenticationType, aws_appsync_graphqlEndpoint = config.aws_appsync_graphqlEndpoint, aws_appsync_region = config.aws_appsync_region, aws_cognito_identity_pool_id = config.aws_cognito_identity_pool_id, aws_cognito_sign_up_verification_method = config.aws_cognito_sign_up_verification_method, aws_mandatory_sign_in = config.aws_mandatory_sign_in, aws_mobile_analytics_app_id = config.aws_mobile_analytics_app_id, aws_mobile_analytics_app_region = config.aws_mobile_analytics_app_region, aws_user_files_s3_bucket = config.aws_user_files_s3_bucket, aws_user_files_s3_bucket_region = config.aws_user_files_s3_bucket_region, aws_user_files_s3_dangerously_connect_to_http_endpoint_for_testing = config.aws_user_files_s3_dangerously_connect_to_http_endpoint_for_testing, aws_user_pools_id = config.aws_user_pools_id, aws_user_pools_web_client_id = config.aws_user_pools_web_client_id, geo = config.geo, oauth = config.oauth;
23
28
  var amplifyConfig = {};
24
29
  // Analytics
25
30
  if (aws_mobile_analytics_app_id) {
@@ -30,6 +35,20 @@ export var parseAWSExports = function (config) {
30
35
  },
31
36
  };
32
37
  }
38
+ // TODO: Need to support all API configurations
39
+ // API
40
+ if (aws_appsync_graphqlEndpoint) {
41
+ amplifyConfig.API = {
42
+ AppSync: {
43
+ defaultAuthMode: {
44
+ type: authTypeMapping[aws_appsync_authenticationType],
45
+ apiKey: aws_appsync_apiKey,
46
+ },
47
+ endpoint: aws_appsync_graphqlEndpoint,
48
+ region: aws_appsync_region,
49
+ },
50
+ };
51
+ }
33
52
  // Auth
34
53
  if (aws_cognito_identity_pool_id || aws_user_pools_id) {
35
54
  amplifyConfig.Auth = {
@@ -1,5 +1,5 @@
1
- import { PinpointRecordParameters } from '../types';
1
+ import { PinpointRecordInput } from '../types';
2
2
  /**
3
3
  * @internal
4
4
  */
5
- export declare const record: ({ appId, category, credentials, event, identityId, region, userAgentValue, }: PinpointRecordParameters) => Promise<void>;
5
+ export declare const record: ({ appId, category, credentials, event, identityId, region, userAgentValue, }: PinpointRecordInput) => Promise<void>;
@@ -68,7 +68,7 @@ export var record = function (_a) {
68
68
  identityId: identityId,
69
69
  region: region,
70
70
  resendLimit: RESEND_LIMIT,
71
- userAgentValue: userAgentValue
71
+ userAgentValue: userAgentValue,
72
72
  });
73
73
  if (!!endpointId) return [3 /*break*/, 4];
74
74
  return [4 /*yield*/, updateEndpoint({
@@ -89,7 +89,7 @@ export var record = function (_a) {
89
89
  if (!endpointId) {
90
90
  throw new AmplifyError({
91
91
  name: 'ENDPOINT_NOT_CREATED',
92
- message: 'Endpoint was not created.'
92
+ message: 'Endpoint was not created.',
93
93
  });
94
94
  }
95
95
  // Generate session if required
@@ -107,7 +107,7 @@ export var record = function (_a) {
107
107
  event: event,
108
108
  session: session,
109
109
  timestamp: timestampISOString,
110
- resendLimit: RESEND_LIMIT
110
+ resendLimit: RESEND_LIMIT,
111
111
  });
112
112
  return [2 /*return*/];
113
113
  }
@@ -1,5 +1,5 @@
1
- import { PinpointUpdateEndpointParameters } from '../types';
1
+ import { PinpointUpdateEndpointInput } from '../types';
2
2
  /**
3
3
  * @internal
4
4
  */
5
- export declare const updateEndpoint: ({ address, appId, category, channelType, credentials, identityId, optOut, region, userId, userProfile, userAgentValue, }: PinpointUpdateEndpointParameters) => Promise<void>;
5
+ export declare const updateEndpoint: ({ address, appId, category, channelType, credentials, identityId, optOut, region, userId, userProfile, userAgentValue, }: PinpointUpdateEndpointInput) => Promise<void>;
@@ -29,12 +29,12 @@ type PinpointCommonParameters = {
29
29
  region: string;
30
30
  userAgentValue?: string;
31
31
  };
32
- export type PinpointUpdateEndpointParameters = PinpointCommonParameters & PinpointServiceOptions & {
32
+ export type PinpointUpdateEndpointInput = PinpointCommonParameters & PinpointServiceOptions & {
33
33
  channelType?: SupportedChannelType;
34
34
  userId?: string;
35
35
  userProfile?: UserProfile;
36
36
  };
37
- export type PinpointRecordParameters = PinpointCommonParameters & {
37
+ export type PinpointRecordInput = PinpointCommonParameters & {
38
38
  event: PinpointAnalyticsEvent;
39
39
  };
40
40
  export {};
@@ -0,0 +1,34 @@
1
+ export type LibraryAPIOptions = {
2
+ AppSync: {
3
+ query: string;
4
+ variables?: object;
5
+ authMode?: any;
6
+ authToken?: string;
7
+ /**
8
+ * @deprecated This property should not be used
9
+ */
10
+ userAgentSuffix?: string;
11
+ };
12
+ customHeaders: Function;
13
+ };
14
+ export type APIConfig = {
15
+ AppSync?: {
16
+ defaultAuthMode?: GraphQLAuthMode;
17
+ region?: string;
18
+ endpoint?: string;
19
+ modelIntrospectionSchema?: any;
20
+ };
21
+ };
22
+ export type GraphQLAuthMode = {
23
+ type: 'apiKey';
24
+ apiKey: string;
25
+ } | {
26
+ type: 'jwt';
27
+ token: 'id' | 'access';
28
+ } | {
29
+ type: 'iam';
30
+ } | {
31
+ type: 'lambda';
32
+ } | {
33
+ type: 'custom';
34
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -34,8 +34,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
34
34
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
35
  }
36
36
  };
37
- import { asserts } from '../../Util/errors/AssertError';
38
- import { AUTH_CONFING_EXCEPTION } from '../../Util/Constants';
39
37
  export function isTokenExpired(_a) {
40
38
  var expiresAt = _a.expiresAt, clockDrift = _a.clockDrift;
41
39
  var currentTime = Date.now();
@@ -65,13 +63,7 @@ var AuthClass = /** @class */ (function () {
65
63
  var tokens, credentialsAndIdentityId, userSub;
66
64
  return __generator(this, function (_k) {
67
65
  switch (_k.label) {
68
- case 0:
69
- asserts(!!this.authConfig, {
70
- name: AUTH_CONFING_EXCEPTION,
71
- message: 'AuthConfig is required',
72
- recoverySuggestion: 'call Amplify.configure in your app with a valid AuthConfig',
73
- });
74
- return [4 /*yield*/, ((_b = (_a = this.authOptions) === null || _a === void 0 ? void 0 : _a.tokenProvider) === null || _b === void 0 ? void 0 : _b.getTokens(options))];
66
+ case 0: return [4 /*yield*/, ((_b = (_a = this.authOptions) === null || _a === void 0 ? void 0 : _a.tokenProvider) === null || _b === void 0 ? void 0 : _b.getTokens(options))];
75
67
  case 1:
76
68
  // Get tokens will throw if session cannot be refreshed (network or service error) or return null if not available
77
69
  tokens =
@@ -89,13 +81,11 @@ var AuthClass = /** @class */ (function () {
89
81
  credentialsAndIdentityId =
90
82
  _k.sent();
91
83
  return [3 /*break*/, 5];
92
- case 3:
93
- if (!this.authConfig.Cognito.allowGuestAccess) return [3 /*break*/, 5];
94
- return [4 /*yield*/, ((_j = (_h = this.authOptions) === null || _h === void 0 ? void 0 : _h.credentialsProvider) === null || _j === void 0 ? void 0 : _j.getCredentialsAndIdentityId({
95
- authConfig: this.authConfig,
96
- authenticated: false,
97
- forceRefresh: options.forceRefresh,
98
- }))];
84
+ case 3: return [4 /*yield*/, ((_j = (_h = this.authOptions) === null || _h === void 0 ? void 0 : _h.credentialsProvider) === null || _j === void 0 ? void 0 : _j.getCredentialsAndIdentityId({
85
+ authConfig: this.authConfig,
86
+ authenticated: false,
87
+ forceRefresh: options.forceRefresh,
88
+ }))];
99
89
  case 4:
100
90
  // getCredentialsAndIdentityId will throw if cannot get credentials (network or service error)
101
91
  credentialsAndIdentityId =
@@ -106,13 +106,13 @@ export type GetCredentialsOptions = GetCredentialsAuthenticatedUser | GetCredent
106
106
  type GetCredentialsAuthenticatedUser = {
107
107
  authenticated: true;
108
108
  forceRefresh?: boolean;
109
- authConfig: AuthConfig;
109
+ authConfig: AuthConfig | undefined;
110
110
  tokens: AuthTokens;
111
111
  };
112
112
  type GetCredentialsUnauthenticatedUser = {
113
113
  authenticated: false;
114
114
  forceRefresh?: boolean;
115
- authConfig: AuthConfig;
115
+ authConfig: AuthConfig | undefined;
116
116
  tokens?: never;
117
117
  };
118
118
  export type AWSCredentialsAndIdentityId = {
@@ -3,6 +3,11 @@ export interface StorageConfig {
3
3
  S3: {
4
4
  bucket?: string;
5
5
  region?: string;
6
+ /**
7
+ * Internal-only configuration for testing purpose. You should not use this.
8
+ *
9
+ * @internal
10
+ */
6
11
  dangerouslyConnectToHttpEndpointForTesting?: string;
7
12
  };
8
13
  }
@@ -1,14 +1,17 @@
1
+ import { APIConfig, LibraryAPIOptions } from './API/types';
1
2
  import { AnalyticsConfig } from './Analytics/types';
2
3
  import { AuthConfig, LibraryAuthOptions, AuthUserPoolConfig, AuthIdentityPoolConfig, AuthUserPoolAndIdentityPoolConfig, GetCredentialsOptions, CognitoIdentityPoolConfig } from './Auth/types';
3
4
  import { LibraryStorageOptions, StorageAccessLevel, StorageConfig } from './Storage/types';
4
5
  export type ResourcesConfig = {
6
+ API?: APIConfig;
5
7
  Analytics?: AnalyticsConfig;
6
8
  Auth?: AuthConfig;
7
9
  Storage?: StorageConfig;
8
10
  };
9
11
  export type LibraryOptions = {
12
+ API?: LibraryAPIOptions;
10
13
  Auth?: LibraryAuthOptions;
11
14
  Storage?: LibraryStorageOptions;
12
15
  ssr?: boolean;
13
16
  };
14
- export { AuthConfig, AuthUserPoolConfig, AuthIdentityPoolConfig, AuthUserPoolAndIdentityPoolConfig, GetCredentialsOptions, StorageAccessLevel, StorageConfig, AnalyticsConfig, CognitoIdentityPoolConfig, };
17
+ export { APIConfig, AuthConfig, AuthUserPoolConfig, AuthIdentityPoolConfig, AuthUserPoolAndIdentityPoolConfig, GetCredentialsOptions, StorageAccessLevel, StorageConfig, AnalyticsConfig, CognitoIdentityPoolConfig, };
@@ -1,13 +1,14 @@
1
1
  import { CookieStorageData, KeyValueStorageInterface, SameSite } from '../types';
2
2
  export declare class CookieStorage implements KeyValueStorageInterface {
3
- domain?: string;
4
3
  path: string;
4
+ domain?: string;
5
5
  expires?: number;
6
- secure?: boolean;
7
6
  sameSite?: SameSite;
7
+ secure?: boolean;
8
8
  constructor(data?: CookieStorageData);
9
9
  setItem(key: string, value: string): Promise<void>;
10
- getItem(key: string): Promise<string>;
10
+ getItem(key: string): Promise<string | null>;
11
11
  removeItem(key: string): Promise<void>;
12
12
  clear(): Promise<void>;
13
+ private getData;
13
14
  }
@@ -1,3 +1,16 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ var __assign = (this && this.__assign) || function () {
4
+ __assign = Object.assign || function(t) {
5
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
6
+ s = arguments[i];
7
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
8
+ t[p] = s[p];
9
+ }
10
+ return t;
11
+ };
12
+ return __assign.apply(this, arguments);
13
+ };
1
14
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
15
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
16
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -34,101 +47,60 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
34
47
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
48
  }
36
49
  };
37
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
38
- // SPDX-License-Identifier: Apache-2.0
39
- // @ts-ignore
40
- import * as Cookies from 'js-cookie';
50
+ import { get as getJsCookie, remove as removeJsCookie, set as setJsCookie, } from 'js-cookie';
41
51
  var CookieStorage = /** @class */ (function () {
42
52
  function CookieStorage(data) {
43
53
  if (data === void 0) { data = {}; }
44
- if (data.domain) {
45
- this.domain = data.domain;
46
- }
47
- if (data.path) {
48
- this.path = data.path;
49
- }
50
- else {
51
- this.path = '/';
52
- }
53
- if (Object.prototype.hasOwnProperty.call(data, 'expires')) {
54
- this.expires = data.expires;
55
- }
56
- else {
57
- this.expires = 365;
58
- }
59
- if (Object.prototype.hasOwnProperty.call(data, 'secure')) {
60
- this.secure = data.secure;
61
- }
62
- else {
63
- this.secure = true;
64
- }
54
+ var path = data.path, domain = data.domain, expires = data.expires, sameSite = data.sameSite, secure = data.secure;
55
+ this.domain = domain;
56
+ this.path = path ? path : '/';
57
+ this.expires = data.hasOwnProperty('expires') ? expires : 365;
58
+ this.secure = data.hasOwnProperty('secure') ? secure : true;
65
59
  if (data.hasOwnProperty('sameSite')) {
66
- if (!data.sameSite ||
67
- !['strict', 'lax', 'none'].includes(data.sameSite)) {
60
+ if (!sameSite || !['strict', 'lax', 'none'].includes(sameSite)) {
68
61
  throw new Error('The sameSite value of cookieStorage must be "lax", "strict" or "none".');
69
62
  }
70
- if (data.sameSite === 'none' && !this.secure) {
63
+ if (sameSite === 'none' && !this.secure) {
71
64
  throw new Error('sameSite = None requires the Secure attribute in latest browser versions.');
72
65
  }
73
- this.sameSite = data.sameSite;
66
+ this.sameSite = sameSite;
74
67
  }
75
68
  }
76
69
  CookieStorage.prototype.setItem = function (key, value) {
77
70
  return __awaiter(this, void 0, void 0, function () {
78
- var options;
79
71
  return __generator(this, function (_a) {
80
- options = {
81
- path: this.path,
82
- expires: this.expires,
83
- domain: this.domain,
84
- secure: this.secure,
85
- };
86
- if (this.sameSite) {
87
- options.sameSite = this.sameSite;
88
- }
89
- Cookies.set(key, value, options);
90
- return [2 /*return*/, Cookies.get(key)];
72
+ setJsCookie(key, value, this.getData());
73
+ return [2 /*return*/];
91
74
  });
92
75
  });
93
76
  };
94
77
  CookieStorage.prototype.getItem = function (key) {
95
78
  return __awaiter(this, void 0, void 0, function () {
79
+ var item;
96
80
  return __generator(this, function (_a) {
97
- return [2 /*return*/, Cookies.get(key)];
81
+ item = getJsCookie(key);
82
+ return [2 /*return*/, item !== null && item !== void 0 ? item : null];
98
83
  });
99
84
  });
100
85
  };
101
86
  CookieStorage.prototype.removeItem = function (key) {
102
87
  return __awaiter(this, void 0, void 0, function () {
103
- var options;
104
88
  return __generator(this, function (_a) {
105
- options = {
106
- path: this.path,
107
- expires: this.expires,
108
- domain: this.domain,
109
- secure: this.secure,
110
- };
111
- if (this.sameSite) {
112
- options.sameSite = this.sameSite;
113
- }
114
- Cookies.remove(key, options);
89
+ removeJsCookie(key, this.getData());
115
90
  return [2 /*return*/];
116
91
  });
117
92
  });
118
93
  };
119
94
  CookieStorage.prototype.clear = function () {
120
95
  return __awaiter(this, void 0, void 0, function () {
121
- var cookies, numKeys, promiseArray, index;
96
+ var cookie, promises;
97
+ var _this = this;
122
98
  return __generator(this, function (_a) {
123
99
  switch (_a.label) {
124
100
  case 0:
125
- cookies = Cookies.get();
126
- numKeys = Object.keys(cookies).length;
127
- promiseArray = [];
128
- for (index = 0; index < numKeys; ++index) {
129
- promiseArray.push(this.removeItem(Object.keys(cookies)[index]));
130
- }
131
- return [4 /*yield*/, Promise.all(promiseArray)];
101
+ cookie = getJsCookie();
102
+ promises = Object.keys(cookie).map(function (key) { return _this.removeItem(key); });
103
+ return [4 /*yield*/, Promise.all(promises)];
132
104
  case 1:
133
105
  _a.sent();
134
106
  return [2 /*return*/];
@@ -136,6 +108,9 @@ var CookieStorage = /** @class */ (function () {
136
108
  });
137
109
  });
138
110
  };
111
+ CookieStorage.prototype.getData = function () {
112
+ return __assign({ path: this.path, expires: this.expires, domain: this.domain, secure: this.secure }, (this.sameSite && { sameSite: this.sameSite }));
113
+ };
139
114
  return CookieStorage;
140
115
  }());
141
116
  export { CookieStorage };
@@ -0,0 +1,7 @@
1
+ import { KeyValueStorage } from './KeyValueStorage';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare class CookieStorage extends KeyValueStorage {
6
+ constructor();
7
+ }
@@ -0,0 +1,29 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ var __extends = (this && this.__extends) || (function () {
4
+ var extendStatics = function (d, b) {
5
+ extendStatics = Object.setPrototypeOf ||
6
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
7
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
8
+ return extendStatics(d, b);
9
+ };
10
+ return function (d, b) {
11
+ if (typeof b !== "function" && b !== null)
12
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
13
+ extendStatics(d, b);
14
+ function __() { this.constructor = d; }
15
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
16
+ };
17
+ })();
18
+ import { KeyValueStorage } from './KeyValueStorage';
19
+ /**
20
+ * @internal
21
+ */
22
+ var CookieStorage = /** @class */ (function (_super) {
23
+ __extends(CookieStorage, _super);
24
+ function CookieStorage() {
25
+ return _super.call(this) || this;
26
+ }
27
+ return CookieStorage;
28
+ }(KeyValueStorage));
29
+ export { CookieStorage };
@@ -0,0 +1,7 @@
1
+ import { KeyValueStorage } from './KeyValueStorage';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare class DefaultStorage extends KeyValueStorage {
6
+ constructor();
7
+ }
@@ -0,0 +1,30 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ var __extends = (this && this.__extends) || (function () {
4
+ var extendStatics = function (d, b) {
5
+ extendStatics = Object.setPrototypeOf ||
6
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
7
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
8
+ return extendStatics(d, b);
9
+ };
10
+ return function (d, b) {
11
+ if (typeof b !== "function" && b !== null)
12
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
13
+ extendStatics(d, b);
14
+ function __() { this.constructor = d; }
15
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
16
+ };
17
+ })();
18
+ import { KeyValueStorage } from './KeyValueStorage';
19
+ import { getDefaultStorageWithFallback } from './utils';
20
+ /**
21
+ * @internal
22
+ */
23
+ var DefaultStorage = /** @class */ (function (_super) {
24
+ __extends(DefaultStorage, _super);
25
+ function DefaultStorage() {
26
+ return _super.call(this, getDefaultStorageWithFallback()) || this;
27
+ }
28
+ return DefaultStorage;
29
+ }(KeyValueStorage));
30
+ export { DefaultStorage };
@@ -1,7 +1,9 @@
1
- import { KeyValueStorageInterface } from "../types";
2
- declare class LocalStorageClass implements KeyValueStorageInterface {
3
- storage?: Storage;
4
- constructor();
1
+ import { KeyValueStorageInterface } from '../types';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare class DefaultStorage implements KeyValueStorageInterface {
6
+ private asyncStorage?;
5
7
  /**
6
8
  * This is used to set a specific item in storage
7
9
  * @param {string} key - the key for the item
@@ -27,6 +29,5 @@ declare class LocalStorageClass implements KeyValueStorageInterface {
27
29
  * @returns {string} nothing
28
30
  */
29
31
  clear(): Promise<void>;
32
+ private assertModule;
30
33
  }
31
- export declare const LocalStorage: LocalStorageClass;
32
- export {};