@aws-amplify/core 6.0.1-console-preview.e8aa063.0 → 6.0.1-console-preview.096eee3.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 (39) hide show
  1. package/lib/Platform/version.d.ts +1 -1
  2. package/lib/Platform/version.js +1 -1
  3. package/lib/index.d.ts +1 -1
  4. package/lib/index.js +2 -1
  5. package/lib/libraryUtils.d.ts +1 -0
  6. package/lib/singleton/Auth/index.d.ts +1 -8
  7. package/lib/singleton/Auth/index.js +24 -26
  8. package/lib/singleton/Auth/types.d.ts +2 -0
  9. package/lib/singleton/Auth/utils/index.js +8 -3
  10. package/lib/singleton/apis/clearCredentials.d.ts +1 -0
  11. package/lib/singleton/apis/clearCredentials.js +10 -0
  12. package/lib/singleton/index.d.ts +1 -0
  13. package/lib/singleton/index.js +3 -1
  14. package/lib/tsconfig.tsbuildinfo +1 -1
  15. package/lib-esm/Platform/version.d.ts +1 -1
  16. package/lib-esm/Platform/version.js +1 -1
  17. package/lib-esm/index.d.ts +1 -1
  18. package/lib-esm/index.js +1 -1
  19. package/lib-esm/libraryUtils.d.ts +1 -0
  20. package/lib-esm/singleton/Auth/index.d.ts +1 -8
  21. package/lib-esm/singleton/Auth/index.js +24 -26
  22. package/lib-esm/singleton/Auth/types.d.ts +2 -0
  23. package/lib-esm/singleton/Auth/utils/index.js +8 -3
  24. package/lib-esm/singleton/apis/clearCredentials.d.ts +1 -0
  25. package/lib-esm/singleton/apis/clearCredentials.js +6 -0
  26. package/lib-esm/singleton/index.d.ts +1 -0
  27. package/lib-esm/singleton/index.js +1 -0
  28. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  29. package/package.json +3 -5
  30. package/polyfills/URL/index.ts +2 -2
  31. package/src/Platform/version.ts +1 -1
  32. package/src/index.ts +1 -0
  33. package/src/libraryUtils.ts +1 -0
  34. package/src/singleton/Auth/index.ts +9 -19
  35. package/src/singleton/Auth/types.ts +2 -0
  36. package/src/singleton/Auth/utils/index.ts +10 -7
  37. package/src/singleton/apis/clearCredentials.ts +8 -0
  38. package/src/singleton/index.ts +1 -0
  39. package/polyfills/URL/index.js +0 -1
@@ -1 +1 @@
1
- export declare const version = "6.0.1-console-preview.e8aa063.0+e8aa063";
1
+ export declare const version = "6.0.1-console-preview.096eee3.0+096eee3";
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = void 0;
4
4
  // generated by genversion
5
- exports.version = '6.0.1-console-preview.e8aa063.0+e8aa063';
5
+ exports.version = '6.0.1-console-preview.096eee3.0+096eee3';
package/lib/index.d.ts CHANGED
@@ -8,7 +8,7 @@ export { Credentials, CredentialsClass } from './Credentials';
8
8
  export { ICredentials } from './types';
9
9
  export { TokenProvider, AuthTokens, FetchAuthSessionOptions, AWSCredentialsAndIdentityIdProvider, AWSCredentialsAndIdentityId, Identity, OAuthConfig, } from './singleton/Auth/types';
10
10
  export { AuthConfig, UserPoolConfig, UserPoolConfigAndIdentityPoolConfig, StorageAccessLevel, StorageConfig, GetCredentialsOptions, ResourcesConfig, LibraryOptions, } from './singleton/types';
11
- export { Amplify, fetchAuthSession, AmplifyClass as AmplifyClassV6, } from './singleton';
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';
package/lib/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.parseAWSExports = exports.I18n = exports.Cache = exports.BrowserStorageCache = exports.InMemoryCache = exports.UniversalStorage = exports.MemoryKeyValueStorage = exports.SessionStorage = exports.CookieStorage = exports.LocalStorage = exports.MemoryStorage = exports.StorageHelper = exports.getId = exports.getCredentialsForIdentity = exports.AmplifyClassV6 = exports.fetchAuthSession = exports.Amplify = exports.CredentialsClass = exports.Credentials = exports.Linking = exports.AsyncStorage = exports.AppState = exports.GoogleOAuth = exports.FacebookOAuth = exports.Hub = exports.Logger = exports.ConsoleLogger = exports.ClientDevice = void 0;
5
+ exports.parseAWSExports = exports.I18n = exports.Cache = exports.BrowserStorageCache = exports.InMemoryCache = exports.UniversalStorage = exports.MemoryKeyValueStorage = exports.SessionStorage = exports.CookieStorage = exports.LocalStorage = exports.MemoryStorage = exports.StorageHelper = exports.getId = exports.getCredentialsForIdentity = exports.clearCredentials = exports.AmplifyClassV6 = exports.fetchAuthSession = exports.Amplify = exports.CredentialsClass = exports.Credentials = exports.Linking = exports.AsyncStorage = exports.AppState = exports.GoogleOAuth = exports.FacebookOAuth = exports.Hub = exports.Logger = exports.ConsoleLogger = exports.ClientDevice = void 0;
6
6
  /*
7
7
  This file maps top-level exports from `@aws-amplify/core`. These are intended to be potentially customer-facing exports.
8
8
  */
@@ -28,6 +28,7 @@ var singleton_1 = require("./singleton");
28
28
  Object.defineProperty(exports, "Amplify", { enumerable: true, get: function () { return singleton_1.Amplify; } });
29
29
  Object.defineProperty(exports, "fetchAuthSession", { enumerable: true, get: function () { return singleton_1.fetchAuthSession; } });
30
30
  Object.defineProperty(exports, "AmplifyClassV6", { enumerable: true, get: function () { return singleton_1.AmplifyClass; } });
31
+ Object.defineProperty(exports, "clearCredentials", { enumerable: true, get: function () { return singleton_1.clearCredentials; } });
31
32
  // AWSClients exports
32
33
  var CognitoIdentity_1 = require("./AwsClients/CognitoIdentity");
33
34
  Object.defineProperty(exports, "getCredentialsForIdentity", { enumerable: true, get: function () { return CognitoIdentity_1.getCredentialsForIdentity; } });
@@ -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 } 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,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
  }
@@ -37,9 +37,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.AuthClass = exports.isTokenExpired = void 0;
40
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
41
- // SPDX-License-Identifier: Apache-2.0
42
- var rxjs_1 = require("rxjs");
43
40
  var AssertError_1 = require("../../Util/errors/AssertError");
44
41
  var Constants_1 = require("../../Util/Constants");
45
42
  function isTokenExpired(_a) {
@@ -50,7 +47,6 @@ function isTokenExpired(_a) {
50
47
  exports.isTokenExpired = isTokenExpired;
51
48
  var AuthClass = /** @class */ (function () {
52
49
  function AuthClass() {
53
- this.authSessionObservers = new Set();
54
50
  }
55
51
  /**
56
52
  * Configure Auth category
@@ -67,12 +63,12 @@ var AuthClass = /** @class */ (function () {
67
63
  this.authOptions = authOptions;
68
64
  };
69
65
  AuthClass.prototype.fetchAuthSession = function (options) {
70
- var _a, _b, _c, _d, _e, _f, _g;
66
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
71
67
  if (options === void 0) { options = {}; }
72
68
  return __awaiter(this, void 0, void 0, function () {
73
- var tokens, credentialsAndIdentityId;
74
- return __generator(this, function (_h) {
75
- switch (_h.label) {
69
+ var tokens, credentialsAndIdentityId, userSub;
70
+ return __generator(this, function (_k) {
71
+ switch (_k.label) {
76
72
  case 0:
77
73
  (0, AssertError_1.asserts)(!!this.authConfig, {
78
74
  name: Constants_1.AUTH_CONFING_EXCEPTION,
@@ -83,9 +79,10 @@ var AuthClass = /** @class */ (function () {
83
79
  case 1:
84
80
  // Get tokens will throw if session cannot be refreshed (network or service error) or return null if not available
85
81
  tokens =
86
- (_c = (_h.sent())) !== null && _c !== void 0 ? _c : undefined;
82
+ (_c = (_k.sent())) !== null && _c !== void 0 ? _c : undefined;
87
83
  if (!tokens) return [3 /*break*/, 3];
88
- return [4 /*yield*/, ((_e = (_d = this.authOptions) === null || _d === void 0 ? void 0 : _d.credentialsProvider) === null || _e === void 0 ? void 0 : _e.getCredentialsAndIdentityId({
84
+ userSub = (_e = (_d = tokens.accessToken) === null || _d === void 0 ? void 0 : _d.payload) === null || _e === void 0 ? void 0 : _e.sub;
85
+ return [4 /*yield*/, ((_g = (_f = this.authOptions) === null || _f === void 0 ? void 0 : _f.credentialsProvider) === null || _g === void 0 ? void 0 : _g.getCredentialsAndIdentityId({
89
86
  authConfig: this.authConfig,
90
87
  tokens: tokens,
91
88
  authenticated: true,
@@ -94,11 +91,11 @@ var AuthClass = /** @class */ (function () {
94
91
  case 2:
95
92
  // getCredentialsAndIdentityId will throw if cannot get credentials (network or service error)
96
93
  credentialsAndIdentityId =
97
- _h.sent();
94
+ _k.sent();
98
95
  return [3 /*break*/, 5];
99
96
  case 3:
100
97
  if (!!this.authConfig.isMandatorySignInEnabled) return [3 /*break*/, 5];
101
- return [4 /*yield*/, ((_g = (_f = this.authOptions) === null || _f === void 0 ? void 0 : _f.credentialsProvider) === null || _g === void 0 ? void 0 : _g.getCredentialsAndIdentityId({
98
+ return [4 /*yield*/, ((_j = (_h = this.authOptions) === null || _h === void 0 ? void 0 : _h.credentialsProvider) === null || _j === void 0 ? void 0 : _j.getCredentialsAndIdentityId({
102
99
  authConfig: this.authConfig,
103
100
  authenticated: false,
104
101
  forceRefresh: options.forceRefresh,
@@ -106,29 +103,30 @@ var AuthClass = /** @class */ (function () {
106
103
  case 4:
107
104
  // getCredentialsAndIdentityId will throw if cannot get credentials (network or service error)
108
105
  credentialsAndIdentityId =
109
- _h.sent();
110
- _h.label = 5;
106
+ _k.sent();
107
+ _k.label = 5;
111
108
  case 5: return [2 /*return*/, {
112
109
  tokens: tokens,
113
110
  credentials: credentialsAndIdentityId === null || credentialsAndIdentityId === void 0 ? void 0 : credentialsAndIdentityId.credentials,
114
111
  identityId: credentialsAndIdentityId === null || credentialsAndIdentityId === void 0 ? void 0 : credentialsAndIdentityId.identityId,
112
+ userSub: userSub,
115
113
  }];
116
114
  }
117
115
  });
118
116
  });
119
117
  };
120
- /**
121
- * Obtain an Observable that notifies on session changes
122
- *
123
- * @returns Observable<AmplifyUserSession>
124
- */
125
- AuthClass.prototype.listenSessionChanges = function () {
126
- var _this = this;
127
- return new rxjs_1.Observable(function (observer) {
128
- _this.authSessionObservers.add(observer);
129
- return function () {
130
- _this.authSessionObservers.delete(observer);
131
- };
118
+ AuthClass.prototype.clearCredentials = function () {
119
+ var _a;
120
+ return __awaiter(this, void 0, void 0, function () {
121
+ return __generator(this, function (_b) {
122
+ switch (_b.label) {
123
+ case 0:
124
+ if (!((_a = this.authOptions) === null || _a === void 0 ? void 0 : _a.credentialsProvider)) return [3 /*break*/, 2];
125
+ return [4 /*yield*/, this.authOptions.credentialsProvider.clearCredentials()];
126
+ case 1: return [2 /*return*/, _b.sent()];
127
+ case 2: return [2 /*return*/];
128
+ }
129
+ });
132
130
  });
133
131
  };
134
132
  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;
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.decodeJWT = exports.assertUserPoolAndIdentityPooConfig = exports.assertIdentityPooIdConfig = exports.assertOAuthConfig = exports.assertTokenProviderConfig = void 0;
4
4
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
5
  // SPDX-License-Identifier: Apache-2.0
6
- var buffer_1 = require("buffer");
7
6
  var AssertError_1 = require("../../../Util/errors/AssertError");
8
7
  function assertTokenProviderConfig(authConfig) {
9
8
  var validConfig = !!(authConfig === null || authConfig === void 0 ? void 0 : authConfig.userPoolId) && !!(authConfig === null || authConfig === void 0 ? void 0 : authConfig.userPoolWebClientId);
@@ -51,9 +50,11 @@ function decodeJWT(token) {
51
50
  if (tokenSplitted.length !== 3) {
52
51
  throw new Error('Invalid token');
53
52
  }
54
- var payloadString = tokenSplitted[1];
55
- var payload = JSON.parse(buffer_1.Buffer.from(payloadString, 'base64').toString('utf8'));
56
53
  try {
54
+ var payloadStringb64 = tokenSplitted[1];
55
+ var payloadArrayBuffer = base64ToBytes(payloadStringb64);
56
+ var decodeString = new TextDecoder().decode(payloadArrayBuffer);
57
+ var payload = JSON.parse(decodeString);
57
58
  return {
58
59
  toString: function () { return token; },
59
60
  payload: payload,
@@ -64,3 +65,7 @@ function decodeJWT(token) {
64
65
  }
65
66
  }
66
67
  exports.decodeJWT = decodeJWT;
68
+ function base64ToBytes(base64) {
69
+ var binString = atob(base64);
70
+ return Uint8Array.from(binString, function (m) { return m.codePointAt(0) || 0; });
71
+ }
@@ -0,0 +1 @@
1
+ export declare function clearCredentials(): Promise<void>;
@@ -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.clearCredentials = void 0;
6
+ var Amplify_1 = require("../Amplify");
7
+ function clearCredentials() {
8
+ return Amplify_1.Amplify.Auth.clearCredentials();
9
+ }
10
+ exports.clearCredentials = clearCredentials;
@@ -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,9 +2,11 @@
2
2
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.fetchAuthSession = exports.Amplify = exports.AmplifyClass = void 0;
5
+ exports.clearCredentials = exports.fetchAuthSession = exports.Amplify = exports.AmplifyClass = void 0;
6
6
  var Amplify_1 = require("./Amplify");
7
7
  Object.defineProperty(exports, "AmplifyClass", { enumerable: true, get: function () { return Amplify_1.AmplifyClass; } });
8
8
  Object.defineProperty(exports, "Amplify", { enumerable: true, get: function () { return Amplify_1.Amplify; } });
9
9
  var fetchAuthSession_1 = require("./apis/fetchAuthSession");
10
10
  Object.defineProperty(exports, "fetchAuthSession", { enumerable: true, get: function () { return fetchAuthSession_1.fetchAuthSession; } });
11
+ var clearCredentials_1 = require("./apis/clearCredentials");
12
+ Object.defineProperty(exports, "clearCredentials", { enumerable: true, get: function () { return clearCredentials_1.clearCredentials; } });