@aws-amplify/core 6.0.1-console-preview.26f7c82.0 → 6.0.1-console-preview.3b09ef9.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 (61) hide show
  1. package/lib/Cache/StorageCache.js +2 -2
  2. package/lib/I18n/I18n.js +4 -5
  3. package/lib/Platform/version.d.ts +1 -1
  4. package/lib/Platform/version.js +1 -1
  5. package/lib/index.d.ts +3 -4
  6. package/lib/index.js +2 -1
  7. package/lib/libraryUtils.d.ts +1 -0
  8. package/lib/parseAWSExports.d.ts +7 -0
  9. package/lib/parseAWSExports.js +8 -1
  10. package/lib/providers/pinpoint/types/pinpoint.d.ts +1 -1
  11. package/lib/singleton/Auth/index.d.ts +1 -8
  12. package/lib/singleton/Auth/index.js +25 -27
  13. package/lib/singleton/Auth/types.d.ts +45 -37
  14. package/lib/singleton/Auth/utils/index.d.ts +4 -5
  15. package/lib/singleton/Auth/utils/index.js +28 -18
  16. package/lib/singleton/Storage/types.d.ts +6 -4
  17. package/lib/singleton/apis/clearCredentials.d.ts +1 -0
  18. package/lib/singleton/apis/clearCredentials.js +10 -0
  19. package/lib/singleton/index.d.ts +1 -0
  20. package/lib/singleton/index.js +3 -1
  21. package/lib/singleton/types.d.ts +2 -11
  22. package/lib/tsconfig.tsbuildinfo +1 -1
  23. package/lib-esm/Cache/StorageCache.js +2 -2
  24. package/lib-esm/I18n/I18n.js +4 -5
  25. package/lib-esm/Platform/version.d.ts +1 -1
  26. package/lib-esm/Platform/version.js +1 -1
  27. package/lib-esm/index.d.ts +3 -4
  28. package/lib-esm/index.js +1 -1
  29. package/lib-esm/libraryUtils.d.ts +1 -0
  30. package/lib-esm/parseAWSExports.d.ts +7 -0
  31. package/lib-esm/parseAWSExports.js +8 -1
  32. package/lib-esm/providers/pinpoint/types/pinpoint.d.ts +1 -1
  33. package/lib-esm/singleton/Auth/index.d.ts +1 -8
  34. package/lib-esm/singleton/Auth/index.js +25 -27
  35. package/lib-esm/singleton/Auth/types.d.ts +45 -37
  36. package/lib-esm/singleton/Auth/utils/index.d.ts +4 -5
  37. package/lib-esm/singleton/Auth/utils/index.js +28 -17
  38. package/lib-esm/singleton/Storage/types.d.ts +6 -4
  39. package/lib-esm/singleton/apis/clearCredentials.d.ts +1 -0
  40. package/lib-esm/singleton/apis/clearCredentials.js +6 -0
  41. package/lib-esm/singleton/index.d.ts +1 -0
  42. package/lib-esm/singleton/index.js +1 -0
  43. package/lib-esm/singleton/types.d.ts +2 -11
  44. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  45. package/package.json +3 -5
  46. package/polyfills/URL/index.ts +2 -2
  47. package/src/Cache/StorageCache.ts +2 -1
  48. package/src/I18n/I18n.ts +2 -2
  49. package/src/Platform/version.ts +1 -1
  50. package/src/index.ts +3 -1
  51. package/src/libraryUtils.ts +1 -0
  52. package/src/parseAWSExports.ts +8 -1
  53. package/src/providers/pinpoint/types/pinpoint.ts +1 -1
  54. package/src/singleton/Auth/index.ts +10 -20
  55. package/src/singleton/Auth/types.ts +54 -39
  56. package/src/singleton/Auth/utils/index.ts +51 -36
  57. package/src/singleton/Storage/types.ts +6 -4
  58. package/src/singleton/apis/clearCredentials.ts +8 -0
  59. package/src/singleton/index.ts +1 -0
  60. package/src/singleton/types.ts +14 -14
  61. package/polyfills/URL/index.js +0 -1
@@ -6,9 +6,9 @@ export { FacebookOAuth, GoogleOAuth } from './OAuthHelper';
6
6
  export { AppState, AsyncStorage, Linking } from './RNComponents';
7
7
  export { Credentials, CredentialsClass } from './Credentials';
8
8
  export { ICredentials } from './types';
9
- export { TokenProvider, AuthTokens, FetchAuthSessionOptions, AWSCredentialsAndIdentityIdProvider, AWSCredentialsAndIdentityId, Identity, OAuthConfig, } from './singleton/Auth/types';
10
- export { AuthConfig, UserPoolConfig, UserPoolConfigAndIdentityPoolConfig, StorageAccessLevel, StorageConfig, GetCredentialsOptions, ResourcesConfig, LibraryOptions, } from './singleton/types';
11
- export { Amplify, fetchAuthSession, AmplifyClass as AmplifyClassV6, } from './singleton';
9
+ export { TokenProvider, AuthTokens, FetchAuthSessionOptions, AWSCredentialsAndIdentityIdProvider, AWSCredentialsAndIdentityId, Identity, OAuthConfig, CognitoUserPoolConfig, } from './singleton/Auth/types';
10
+ export { AuthConfig, UserPoolConfig, UserPoolConfigAndIdentityPoolConfig, StorageAccessLevel, StorageConfig, GetCredentialsOptions, ResourcesConfig, LibraryOptions, AnalyticsConfig, } from './singleton/types';
11
+ export { Amplify, fetchAuthSession, AmplifyClass as AmplifyClassV6, clearCredentials, } from './singleton';
12
12
  export { getCredentialsForIdentity, getId, GetCredentialsForIdentityInput, GetCredentialsForIdentityOutput, } from './AwsClients/CognitoIdentity';
13
13
  export { UserProfile } from './types';
14
14
  export { StorageHelper, MemoryStorage, LocalStorage, CookieStorage, SessionStorage, MemoryKeyValueStorage, } from './StorageHelper';
@@ -16,7 +16,6 @@ export { KeyValueStorageInterface } from './types';
16
16
  export { UniversalStorage } from './UniversalStorage';
17
17
  import { BrowserStorageCache } from './Cache/BrowserStorageCache';
18
18
  export { InMemoryCache } from './Cache/InMemoryCache';
19
- export { CacheConfig } from './Cache/types';
20
19
  export { BrowserStorageCache };
21
20
  export { BrowserStorageCache as Cache };
22
21
  export { I18n } from './I18n';
package/lib-esm/index.js CHANGED
@@ -10,7 +10,7 @@ export { Hub } from './Hub';
10
10
  export { FacebookOAuth, GoogleOAuth } from './OAuthHelper';
11
11
  export { AppState, AsyncStorage, Linking } from './RNComponents';
12
12
  export { Credentials, CredentialsClass } from './Credentials';
13
- export { Amplify, fetchAuthSession, AmplifyClass as AmplifyClassV6, } from './singleton';
13
+ export { Amplify, fetchAuthSession, AmplifyClass as AmplifyClassV6, clearCredentials, } from './singleton';
14
14
  // AWSClients exports
15
15
  export { getCredentialsForIdentity, getId, } from './AwsClients/CognitoIdentity';
16
16
  // Storage helpers
@@ -1,4 +1,5 @@
1
1
  export { browserOrNode, filenameToContentType, generateRandomString, isEmpty, isStrictObject, isTextFile, isWebWorker, makeQuerablePromise, objectLessAttributes, sortByField, transferKeyToLowerCase, transferKeyToUpperCase, } from './Util/JS';
2
+ export { JWT, StrictUnion } from './singleton/Auth/types';
2
3
  export { decodeJWT, assertTokenProviderConfig, assertIdentityPooIdConfig, assertOAuthConfig, } from './singleton/Auth/utils';
3
4
  export { isTokenExpired } from './singleton/Auth';
4
5
  export { Signer } from './Signer';
@@ -1,2 +1,9 @@
1
1
  import { AmplifyConfig } from './types';
2
+ /**
3
+ * This utility generates an `AmplifyConfig` object from an `aws-exports.js` file generated by the Amplify CLI.
4
+ *
5
+ * @param config A configuration object from `aws-exports.js`.
6
+ *
7
+ * @returns An AmplifyConfig object.
8
+ */
2
9
  export declare const parseAWSExports: (config: Record<string, any>) => AmplifyConfig;
@@ -11,12 +11,19 @@ var __assign = (this && this.__assign) || function () {
11
11
  };
12
12
  import { ConsoleLogger as Logger } from './Logger';
13
13
  var logger = new Logger('Parser');
14
+ /**
15
+ * This utility generates an `AmplifyConfig` object from an `aws-exports.js` file generated by the Amplify CLI.
16
+ *
17
+ * @param config A configuration object from `aws-exports.js`.
18
+ *
19
+ * @returns An AmplifyConfig object.
20
+ */
14
21
  export var parseAWSExports = function (config) {
15
22
  var amplifyConfig = {};
16
23
  // Analytics
17
24
  if (config['aws_mobile_analytics_app_id']) {
18
25
  var Analytics = {
19
- AWSPinpoint: {
26
+ Pinpoint: {
20
27
  appId: config['aws_mobile_analytics_app_id'],
21
28
  region: config['aws_mobile_analytics_app_region'],
22
29
  },
@@ -3,7 +3,7 @@ import { UserProfile } from '../../../types';
3
3
  export type SupportedCategory = 'Analytics' | 'InAppMessaging' | 'PushNotification';
4
4
  export type SupportedChannelType = 'APNS' | 'APNS_SANDBOX' | 'GCM' | 'IN_APP';
5
5
  export type PinpointProviderConfig = {
6
- AWSPinpoint: {
6
+ Pinpoint: {
7
7
  appId: string;
8
8
  region: string;
9
9
  };
@@ -1,11 +1,9 @@
1
- import { Observable } from 'rxjs';
2
1
  import { AuthConfig, AuthSession, FetchAuthSessionOptions, LibraryAuthOptions } from './types';
3
2
  export declare function isTokenExpired({ expiresAt, clockDrift, }: {
4
3
  expiresAt: number;
5
4
  clockDrift: number;
6
5
  }): boolean;
7
6
  export declare class AuthClass {
8
- private authSessionObservers;
9
7
  private authConfig?;
10
8
  private authOptions?;
11
9
  constructor();
@@ -21,10 +19,5 @@ export declare class AuthClass {
21
19
  */
22
20
  configure(authResourcesConfig: AuthConfig, authOptions?: LibraryAuthOptions): void;
23
21
  fetchAuthSession(options?: FetchAuthSessionOptions): Promise<AuthSession>;
24
- /**
25
- * Obtain an Observable that notifies on session changes
26
- *
27
- * @returns Observable<AmplifyUserSession>
28
- */
29
- listenSessionChanges(): Observable<AuthSession>;
22
+ clearCredentials(): Promise<void>;
30
23
  }
@@ -34,9 +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
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
38
- // SPDX-License-Identifier: Apache-2.0
39
- import { Observable } from 'rxjs';
40
37
  import { asserts } from '../../Util/errors/AssertError';
41
38
  import { AUTH_CONFING_EXCEPTION } from '../../Util/Constants';
42
39
  export function isTokenExpired(_a) {
@@ -46,7 +43,6 @@ export function isTokenExpired(_a) {
46
43
  }
47
44
  var AuthClass = /** @class */ (function () {
48
45
  function AuthClass() {
49
- this.authSessionObservers = new Set();
50
46
  }
51
47
  /**
52
48
  * Configure Auth category
@@ -63,12 +59,12 @@ var AuthClass = /** @class */ (function () {
63
59
  this.authOptions = authOptions;
64
60
  };
65
61
  AuthClass.prototype.fetchAuthSession = function (options) {
66
- var _a, _b, _c, _d, _e, _f, _g;
62
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
67
63
  if (options === void 0) { options = {}; }
68
64
  return __awaiter(this, void 0, void 0, function () {
69
- var tokens, credentialsAndIdentityId;
70
- return __generator(this, function (_h) {
71
- switch (_h.label) {
65
+ var tokens, credentialsAndIdentityId, userSub;
66
+ return __generator(this, function (_k) {
67
+ switch (_k.label) {
72
68
  case 0:
73
69
  asserts(!!this.authConfig, {
74
70
  name: AUTH_CONFING_EXCEPTION,
@@ -79,9 +75,10 @@ var AuthClass = /** @class */ (function () {
79
75
  case 1:
80
76
  // Get tokens will throw if session cannot be refreshed (network or service error) or return null if not available
81
77
  tokens =
82
- (_c = (_h.sent())) !== null && _c !== void 0 ? _c : undefined;
78
+ (_c = (_k.sent())) !== null && _c !== void 0 ? _c : undefined;
83
79
  if (!tokens) return [3 /*break*/, 3];
84
- return [4 /*yield*/, ((_e = (_d = this.authOptions) === null || _d === void 0 ? void 0 : _d.credentialsProvider) === null || _e === void 0 ? void 0 : _e.getCredentialsAndIdentityId({
80
+ userSub = (_e = (_d = tokens.accessToken) === null || _d === void 0 ? void 0 : _d.payload) === null || _e === void 0 ? void 0 : _e.sub;
81
+ return [4 /*yield*/, ((_g = (_f = this.authOptions) === null || _f === void 0 ? void 0 : _f.credentialsProvider) === null || _g === void 0 ? void 0 : _g.getCredentialsAndIdentityId({
85
82
  authConfig: this.authConfig,
86
83
  tokens: tokens,
87
84
  authenticated: true,
@@ -90,11 +87,11 @@ var AuthClass = /** @class */ (function () {
90
87
  case 2:
91
88
  // getCredentialsAndIdentityId will throw if cannot get credentials (network or service error)
92
89
  credentialsAndIdentityId =
93
- _h.sent();
90
+ _k.sent();
94
91
  return [3 /*break*/, 5];
95
92
  case 3:
96
- if (!!this.authConfig.isMandatorySignInEnabled) return [3 /*break*/, 5];
97
- return [4 /*yield*/, ((_g = (_f = this.authOptions) === null || _f === void 0 ? void 0 : _f.credentialsProvider) === null || _g === void 0 ? void 0 : _g.getCredentialsAndIdentityId({
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({
98
95
  authConfig: this.authConfig,
99
96
  authenticated: false,
100
97
  forceRefresh: options.forceRefresh,
@@ -102,29 +99,30 @@ var AuthClass = /** @class */ (function () {
102
99
  case 4:
103
100
  // getCredentialsAndIdentityId will throw if cannot get credentials (network or service error)
104
101
  credentialsAndIdentityId =
105
- _h.sent();
106
- _h.label = 5;
102
+ _k.sent();
103
+ _k.label = 5;
107
104
  case 5: return [2 /*return*/, {
108
105
  tokens: tokens,
109
106
  credentials: credentialsAndIdentityId === null || credentialsAndIdentityId === void 0 ? void 0 : credentialsAndIdentityId.credentials,
110
107
  identityId: credentialsAndIdentityId === null || credentialsAndIdentityId === void 0 ? void 0 : credentialsAndIdentityId.identityId,
108
+ userSub: userSub,
111
109
  }];
112
110
  }
113
111
  });
114
112
  });
115
113
  };
116
- /**
117
- * Obtain an Observable that notifies on session changes
118
- *
119
- * @returns Observable<AmplifyUserSession>
120
- */
121
- AuthClass.prototype.listenSessionChanges = function () {
122
- var _this = this;
123
- return new Observable(function (observer) {
124
- _this.authSessionObservers.add(observer);
125
- return function () {
126
- _this.authSessionObservers.delete(observer);
127
- };
114
+ AuthClass.prototype.clearCredentials = function () {
115
+ var _a;
116
+ return __awaiter(this, void 0, void 0, function () {
117
+ return __generator(this, function (_b) {
118
+ switch (_b.label) {
119
+ case 0:
120
+ if (!((_a = this.authOptions) === null || _a === void 0 ? void 0 : _a.credentialsProvider)) return [3 /*break*/, 2];
121
+ return [4 /*yield*/, this.authOptions.credentialsProvider.clearCredentials()];
122
+ case 1: return [2 /*return*/, _b.sent()];
123
+ case 2: return [2 /*return*/];
124
+ }
125
+ });
128
126
  });
129
127
  };
130
128
  return AuthClass;
@@ -6,6 +6,7 @@ interface JwtPayloadStandardFields {
6
6
  iat?: number;
7
7
  scope?: string;
8
8
  jti?: string;
9
+ sub?: string;
9
10
  }
10
11
  /** JSON type */
11
12
  type Json = null | string | number | boolean | Json[] | JsonObject;
@@ -23,6 +24,7 @@ export type AuthSession = {
23
24
  tokens?: AuthTokens;
24
25
  credentials?: AWSCredentials;
25
26
  identityId?: string;
27
+ userSub?: string;
26
28
  };
27
29
  export type LibraryAuthOptions = {
28
30
  tokenProvider?: TokenProvider;
@@ -48,52 +50,58 @@ export type AuthTokens = {
48
50
  idToken?: JWT;
49
51
  accessToken: JWT;
50
52
  };
51
- export type AuthConfig = StrictUnion<IdentityPoolConfig | UserPoolConfig | UserPoolConfigWithOAuth | UserPoolConfigAndIdentityPoolConfig | UserPoolConfigAndIdentityPoolConfigWithOAuth>;
53
+ export type AuthConfig = StrictUnion<AuthIdentityPoolConfig | AuthUserPoolConfig | AuthUserPoolAndIdentityPoolConfig>;
52
54
  type UnionKeys<T> = T extends T ? keyof T : never;
53
55
  type StrictUnionHelper<T, TAll> = T extends any ? T & Partial<Record<Exclude<UnionKeys<TAll>, keyof T>, never>> : never;
54
- type StrictUnion<T> = StrictUnionHelper<T, T>;
55
- export type IdentityPoolConfig = {
56
+ export type StrictUnion<T> = StrictUnionHelper<T, T>;
57
+ export type AuthIdentityPoolConfig = {
58
+ Cognito: CognitoIdentityPoolConfig & {
59
+ userPoolClientId?: never;
60
+ userPoolId?: never;
61
+ loginWith?: never;
62
+ };
63
+ };
64
+ export type CognitoIdentityPoolConfig = {
56
65
  identityPoolId: string;
57
- userPoolWebClientId?: never;
58
- userPoolId?: never;
59
- clientMetadata?: never;
60
- isMandatorySignInEnabled?: never;
66
+ allowGuestAccess?: boolean;
61
67
  };
62
- export type UserPoolConfig = {
63
- userPoolWebClientId: string;
64
- userPoolId: string;
65
- identityPoolId?: never;
66
- clientMetadata?: Record<string, string>;
68
+ export type AuthUserPoolConfig = {
69
+ Cognito: CognitoUserPoolConfig & {
70
+ identityPoolId?: never;
71
+ allowGuestAccess?: never;
72
+ };
67
73
  };
68
- export type UserPoolConfigWithOAuth = {
69
- userPoolWebClientId: string;
74
+ export type CognitoUserPoolConfig = {
75
+ userPoolClientId: string;
70
76
  userPoolId: string;
71
- identityPoolId?: never;
72
- clientMetadata?: Record<string, string>;
73
- oauth: OAuthConfig;
77
+ signUpVerificationMethod?: 'code' | 'link';
78
+ loginWith?: {
79
+ oauth?: OAuthConfig;
80
+ };
74
81
  };
75
82
  export type OAuthConfig = {
76
83
  domain: string;
77
- scopes: Array<string>;
78
- redirectSignIn: string;
79
- redirectSignOut: string;
80
- responseType: string;
81
- };
82
- export type UserPoolConfigAndIdentityPoolConfig = {
83
- userPoolWebClientId: string;
84
- userPoolId: string;
85
- identityPoolId: string;
86
- clientMetadata?: Record<string, string>;
87
- isMandatorySignInEnabled?: boolean;
88
- };
89
- export type UserPoolConfigAndIdentityPoolConfigWithOAuth = {
90
- userPoolWebClientId: string;
91
- userPoolId: string;
92
- identityPoolId: string;
93
- clientMetadata?: Record<string, string>;
94
- isMandatorySignInEnabled?: boolean;
95
- oauth: OAuthConfig;
96
- };
84
+ scopes: Array<OAuthScope>;
85
+ redirectSignIn: Array<string>;
86
+ redirectSignOut: Array<string>;
87
+ responseType: 'code' | 'token';
88
+ providers?: Array<OAuthProviders | CustomProvider>;
89
+ };
90
+ type OAuthProviders = 'Google' | 'Facebook' | 'Amazon' | 'Apple';
91
+ type CustomProvider = {
92
+ custom: string;
93
+ };
94
+ type CustomScope = string & {};
95
+ type OAuthScope = 'email' | 'openid' | 'phone' | 'email' | 'profile' | 'aws.cognito.signin.user.admin' | CustomScope;
96
+ export type CognitoUserPoolWithOAuthConfig = CognitoUserPoolConfig & {
97
+ loginWith: {
98
+ oauth: OAuthConfig;
99
+ };
100
+ };
101
+ export type AuthUserPoolAndIdentityPoolConfig = {
102
+ Cognito: CognitoUserPoolAndIdentityPoolConfig;
103
+ };
104
+ export type CognitoUserPoolAndIdentityPoolConfig = CognitoUserPoolConfig & CognitoIdentityPoolConfig;
97
105
  export type GetCredentialsOptions = GetCredentialsAuthenticatedUser | GetCredentialsUnauthenticatedUser;
98
106
  type GetCredentialsAuthenticatedUser = {
99
107
  authenticated: true;
@@ -1,6 +1,5 @@
1
- import { AuthConfig, IdentityPoolConfig, JWT, UserPoolConfig, UserPoolConfigAndIdentityPoolConfig, UserPoolConfigAndIdentityPoolConfigWithOAuth, UserPoolConfigWithOAuth } from '../types';
2
- export declare function assertTokenProviderConfig(authConfig?: AuthConfig): asserts authConfig is UserPoolConfigAndIdentityPoolConfigWithOAuth | UserPoolConfigWithOAuth | UserPoolConfigAndIdentityPoolConfig | UserPoolConfig;
3
- export declare function assertOAuthConfig(authConfig?: AuthConfig): asserts authConfig is UserPoolConfigAndIdentityPoolConfigWithOAuth | UserPoolConfigWithOAuth;
4
- export declare function assertIdentityPooIdConfig(authConfig: AuthConfig): asserts authConfig is IdentityPoolConfig;
5
- export declare function assertUserPoolAndIdentityPooConfig(authConfig: AuthConfig): asserts authConfig is UserPoolConfigAndIdentityPoolConfig;
1
+ import { JWT, CognitoUserPoolWithOAuthConfig, CognitoUserPoolConfig, CognitoUserPoolAndIdentityPoolConfig, CognitoIdentityPoolConfig, StrictUnion } from '../types';
2
+ export declare function assertTokenProviderConfig(cognitoConfig?: StrictUnion<CognitoUserPoolConfig | CognitoUserPoolAndIdentityPoolConfig | CognitoIdentityPoolConfig>): asserts cognitoConfig is CognitoUserPoolAndIdentityPoolConfig | CognitoUserPoolConfig;
3
+ export declare function assertOAuthConfig(cognitoConfig?: CognitoUserPoolConfig | CognitoUserPoolAndIdentityPoolConfig): asserts cognitoConfig is CognitoUserPoolWithOAuthConfig;
4
+ export declare function assertIdentityPooIdConfig(cognitoConfig?: StrictUnion<CognitoUserPoolConfig | CognitoUserPoolAndIdentityPoolConfig | CognitoIdentityPoolConfig>): asserts cognitoConfig is CognitoIdentityPoolConfig;
6
5
  export declare function decodeJWT(token: string): JWT;
@@ -1,38 +1,43 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import { Buffer } from 'buffer';
4
3
  import { asserts } from '../../../Util/errors/AssertError';
5
- export function assertTokenProviderConfig(authConfig) {
6
- var validConfig = !!(authConfig === null || authConfig === void 0 ? void 0 : authConfig.userPoolId) && !!(authConfig === null || authConfig === void 0 ? void 0 : authConfig.userPoolWebClientId);
7
- return asserts(validConfig, {
4
+ export function assertTokenProviderConfig(cognitoConfig) {
5
+ var assertionValid = true; // assume valid until otherwise proveed
6
+ if (!cognitoConfig) {
7
+ assertionValid = false;
8
+ }
9
+ else {
10
+ assertionValid =
11
+ !!cognitoConfig.userPoolClientId && !!cognitoConfig.userPoolClientId;
12
+ }
13
+ return asserts(assertionValid, {
8
14
  name: 'AuthTokenConfigException',
9
15
  message: 'Auth Token Provider not configured',
10
16
  recoverySuggestion: 'Make sure to call Amplify.configure in your app',
11
17
  });
12
18
  }
13
- export function assertOAuthConfig(authConfig) {
14
- var _a, _b, _c, _d;
15
- assertTokenProviderConfig(authConfig);
16
- var validOAuthConfig = !!((_a = authConfig.oauth) === null || _a === void 0 ? void 0 : _a.domain) &&
17
- !!((_b = authConfig.oauth) === null || _b === void 0 ? void 0 : _b.redirectSignOut) &&
18
- !!((_c = authConfig.oauth) === null || _c === void 0 ? void 0 : _c.redirectSignIn) &&
19
- !!((_d = authConfig.oauth) === null || _d === void 0 ? void 0 : _d.responseType);
19
+ export function assertOAuthConfig(cognitoConfig) {
20
+ var _a, _b, _c, _d, _e, _f, _g, _h;
21
+ var validOAuthConfig = !!((_b = (_a = cognitoConfig === null || cognitoConfig === void 0 ? void 0 : cognitoConfig.loginWith) === null || _a === void 0 ? void 0 : _a.oauth) === null || _b === void 0 ? void 0 : _b.domain) &&
22
+ !!((_d = (_c = cognitoConfig === null || cognitoConfig === void 0 ? void 0 : cognitoConfig.loginWith) === null || _c === void 0 ? void 0 : _c.oauth) === null || _d === void 0 ? void 0 : _d.redirectSignOut) &&
23
+ !!((_f = (_e = cognitoConfig === null || cognitoConfig === void 0 ? void 0 : cognitoConfig.loginWith) === null || _e === void 0 ? void 0 : _e.oauth) === null || _f === void 0 ? void 0 : _f.redirectSignIn) &&
24
+ !!((_h = (_g = cognitoConfig === null || cognitoConfig === void 0 ? void 0 : cognitoConfig.loginWith) === null || _g === void 0 ? void 0 : _g.oauth) === null || _h === void 0 ? void 0 : _h.responseType);
20
25
  return asserts(validOAuthConfig, {
21
26
  name: 'OAuthNotConfigureException',
22
27
  message: 'oauth param not configured',
23
28
  recoverySuggestion: 'Make sure to call Amplify.configure with oauth parameter in your app',
24
29
  });
25
30
  }
26
- export function assertIdentityPooIdConfig(authConfig) {
27
- var validConfig = !!(authConfig === null || authConfig === void 0 ? void 0 : authConfig.identityPoolId);
31
+ export function assertIdentityPooIdConfig(cognitoConfig) {
32
+ var validConfig = !!(cognitoConfig === null || cognitoConfig === void 0 ? void 0 : cognitoConfig.identityPoolId);
28
33
  return asserts(validConfig, {
29
34
  name: 'AuthIdentityPoolIdException',
30
35
  message: 'Auth IdentityPoolId not configured',
31
36
  recoverySuggestion: 'Make sure to call Amplify.configure in your app with a valid IdentityPoolId',
32
37
  });
33
38
  }
34
- export function assertUserPoolAndIdentityPooConfig(authConfig) {
35
- var validConfig = !!(authConfig === null || authConfig === void 0 ? void 0 : authConfig.identityPoolId) && !!(authConfig === null || authConfig === void 0 ? void 0 : authConfig.userPoolId);
39
+ function assertUserPoolAndIdentityPooConfig(authConfig) {
40
+ var validConfig = !!(authConfig === null || authConfig === void 0 ? void 0 : authConfig.Cognito.identityPoolId) && !!(authConfig === null || authConfig === void 0 ? void 0 : authConfig.Cognito.userPoolId);
36
41
  return asserts(validConfig, {
37
42
  name: 'AuthUserPoolAndIdentityPoolException',
38
43
  message: 'Auth UserPool and IdentityPool not configured',
@@ -44,9 +49,11 @@ export function decodeJWT(token) {
44
49
  if (tokenSplitted.length !== 3) {
45
50
  throw new Error('Invalid token');
46
51
  }
47
- var payloadString = tokenSplitted[1];
48
- var payload = JSON.parse(Buffer.from(payloadString, 'base64').toString('utf8'));
49
52
  try {
53
+ var payloadStringb64 = tokenSplitted[1];
54
+ var payloadArrayBuffer = base64ToBytes(payloadStringb64);
55
+ var decodeString = new TextDecoder().decode(payloadArrayBuffer);
56
+ var payload = JSON.parse(decodeString);
50
57
  return {
51
58
  toString: function () { return token; },
52
59
  payload: payload,
@@ -56,3 +63,7 @@ export function decodeJWT(token) {
56
63
  throw new Error('Invalid token payload');
57
64
  }
58
65
  }
66
+ function base64ToBytes(base64) {
67
+ var binString = atob(base64);
68
+ return Uint8Array.from(binString, function (m) { return m.codePointAt(0) || 0; });
69
+ }
@@ -1,15 +1,17 @@
1
1
  export type StorageAccessLevel = 'guest' | 'protected' | 'private';
2
2
  export interface StorageConfig {
3
- bucket?: string;
4
- region?: string;
5
- dangerouslyConnectToHttpEndpointForTesting?: string;
3
+ S3: {
4
+ bucket?: string;
5
+ region?: string;
6
+ dangerouslyConnectToHttpEndpointForTesting?: string;
7
+ };
6
8
  }
7
9
  type StoragePrefixResolver = (params: {
8
10
  accessLevel: StorageAccessLevel;
9
11
  targetIdentityId?: string;
10
12
  }) => Promise<string>;
11
13
  export interface LibraryStorageOptions {
12
- AWSS3: {
14
+ S3: {
13
15
  prefixResolver?: StoragePrefixResolver;
14
16
  defaultAccessLevel?: StorageAccessLevel;
15
17
  isObjectLockEnabled?: boolean;
@@ -0,0 +1 @@
1
+ export declare function clearCredentials(): Promise<void>;
@@ -0,0 +1,6 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { Amplify } from '../Amplify';
4
+ export function clearCredentials() {
5
+ return Amplify.Auth.clearCredentials();
6
+ }
@@ -1,2 +1,3 @@
1
1
  export { AmplifyClass, Amplify } from './Amplify';
2
2
  export { fetchAuthSession } from './apis/fetchAuthSession';
3
+ export { clearCredentials } from './apis/clearCredentials';
@@ -2,3 +2,4 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  export { AmplifyClass, Amplify } from './Amplify';
4
4
  export { fetchAuthSession } from './apis/fetchAuthSession';
5
+ export { clearCredentials } from './apis/clearCredentials';
@@ -1,18 +1,9 @@
1
1
  import { AnalyticsConfig } from './Analytics/types';
2
- import { AuthConfig, LibraryAuthOptions, UserPoolConfig, IdentityPoolConfig, UserPoolConfigAndIdentityPoolConfig, GetCredentialsOptions } from './Auth/types';
2
+ import { AuthConfig, LibraryAuthOptions, AuthUserPoolConfig, AuthIdentityPoolConfig, AuthUserPoolAndIdentityPoolConfig, GetCredentialsOptions } from './Auth/types';
3
3
  import { LibraryStorageOptions, StorageAccessLevel, StorageConfig } from './Storage/types';
4
- import { CacheConfig } from '../Cache/types';
5
- import { I18nOptions } from '../I18n/types';
6
4
  export type ResourcesConfig = {
7
- API?: {};
8
5
  Analytics?: AnalyticsConfig;
9
6
  Auth?: AuthConfig;
10
- Cache?: CacheConfig;
11
- DataStore?: {};
12
- I18n?: I18nOptions;
13
- Interactions?: {};
14
- Notifications?: {};
15
- Predictions?: {};
16
7
  Storage?: StorageConfig;
17
8
  ssr?: boolean;
18
9
  };
@@ -20,4 +11,4 @@ export type LibraryOptions = {
20
11
  Auth?: LibraryAuthOptions;
21
12
  Storage?: LibraryStorageOptions;
22
13
  };
23
- export { AuthConfig, UserPoolConfig, IdentityPoolConfig, UserPoolConfigAndIdentityPoolConfig, GetCredentialsOptions, StorageAccessLevel, StorageConfig, };
14
+ export { AuthConfig, AuthUserPoolConfig as UserPoolConfig, AuthIdentityPoolConfig as IdentityPoolConfig, AuthUserPoolAndIdentityPoolConfig as UserPoolConfigAndIdentityPoolConfig, GetCredentialsOptions, StorageAccessLevel, StorageConfig, AnalyticsConfig, };