@aws-sdk/credential-provider-cognito-identity 3.186.0 → 3.188.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [3.188.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.187.0...v3.188.0) (2022-10-13)
7
+
8
+ **Note:** Version bump only for package @aws-sdk/credential-provider-cognito-identity
9
+
10
+
11
+
12
+
13
+
6
14
  # [3.186.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.185.0...v3.186.0) (2022-10-06)
7
15
 
8
16
  **Note:** Version bump only for package @aws-sdk/credential-provider-cognito-identity
@@ -1,20 +1,17 @@
1
- var InMemoryStorage = (function () {
2
- function InMemoryStorage(store) {
3
- if (store === void 0) { store = {}; }
1
+ export class InMemoryStorage {
2
+ constructor(store = {}) {
4
3
  this.store = store;
5
4
  }
6
- InMemoryStorage.prototype.getItem = function (key) {
5
+ getItem(key) {
7
6
  if (key in this.store) {
8
7
  return this.store[key];
9
8
  }
10
9
  return null;
11
- };
12
- InMemoryStorage.prototype.removeItem = function (key) {
10
+ }
11
+ removeItem(key) {
13
12
  delete this.store[key];
14
- };
15
- InMemoryStorage.prototype.setItem = function (key, value) {
13
+ }
14
+ setItem(key, value) {
16
15
  this.store[key] = value;
17
- };
18
- return InMemoryStorage;
19
- }());
20
- export { InMemoryStorage };
16
+ }
17
+ }
@@ -1,70 +1,67 @@
1
- var STORE_NAME = "IdentityIds";
2
- var IndexedDbStorage = (function () {
3
- function IndexedDbStorage(dbName) {
4
- if (dbName === void 0) { dbName = "aws:cognito-identity-ids"; }
1
+ const STORE_NAME = "IdentityIds";
2
+ export class IndexedDbStorage {
3
+ constructor(dbName = "aws:cognito-identity-ids") {
5
4
  this.dbName = dbName;
6
5
  }
7
- IndexedDbStorage.prototype.getItem = function (key) {
8
- return this.withObjectStore("readonly", function (store) {
9
- var req = store.get(key);
10
- return new Promise(function (resolve) {
11
- req.onerror = function () { return resolve(null); };
12
- req.onsuccess = function () { return resolve(req.result ? req.result.value : null); };
6
+ getItem(key) {
7
+ return this.withObjectStore("readonly", (store) => {
8
+ const req = store.get(key);
9
+ return new Promise((resolve) => {
10
+ req.onerror = () => resolve(null);
11
+ req.onsuccess = () => resolve(req.result ? req.result.value : null);
13
12
  });
14
- }).catch(function () { return null; });
15
- };
16
- IndexedDbStorage.prototype.removeItem = function (key) {
17
- return this.withObjectStore("readwrite", function (store) {
18
- var req = store.delete(key);
19
- return new Promise(function (resolve, reject) {
20
- req.onerror = function () { return reject(req.error); };
21
- req.onsuccess = function () { return resolve(); };
13
+ }).catch(() => null);
14
+ }
15
+ removeItem(key) {
16
+ return this.withObjectStore("readwrite", (store) => {
17
+ const req = store.delete(key);
18
+ return new Promise((resolve, reject) => {
19
+ req.onerror = () => reject(req.error);
20
+ req.onsuccess = () => resolve();
22
21
  });
23
22
  });
24
- };
25
- IndexedDbStorage.prototype.setItem = function (id, value) {
26
- return this.withObjectStore("readwrite", function (store) {
27
- var req = store.put({ id: id, value: value });
28
- return new Promise(function (resolve, reject) {
29
- req.onerror = function () { return reject(req.error); };
30
- req.onsuccess = function () { return resolve(); };
23
+ }
24
+ setItem(id, value) {
25
+ return this.withObjectStore("readwrite", (store) => {
26
+ const req = store.put({ id, value });
27
+ return new Promise((resolve, reject) => {
28
+ req.onerror = () => reject(req.error);
29
+ req.onsuccess = () => resolve();
31
30
  });
32
31
  });
33
- };
34
- IndexedDbStorage.prototype.getDb = function () {
35
- var openDbRequest = self.indexedDB.open(this.dbName, 1);
36
- return new Promise(function (resolve, reject) {
37
- openDbRequest.onsuccess = function () {
32
+ }
33
+ getDb() {
34
+ const openDbRequest = self.indexedDB.open(this.dbName, 1);
35
+ return new Promise((resolve, reject) => {
36
+ openDbRequest.onsuccess = () => {
38
37
  resolve(openDbRequest.result);
39
38
  };
40
- openDbRequest.onerror = function () {
39
+ openDbRequest.onerror = () => {
41
40
  reject(openDbRequest.error);
42
41
  };
43
- openDbRequest.onblocked = function () {
42
+ openDbRequest.onblocked = () => {
44
43
  reject(new Error("Unable to access DB"));
45
44
  };
46
- openDbRequest.onupgradeneeded = function () {
47
- var db = openDbRequest.result;
48
- db.onerror = function () {
45
+ openDbRequest.onupgradeneeded = () => {
46
+ const db = openDbRequest.result;
47
+ db.onerror = () => {
49
48
  reject(new Error("Failed to create object store"));
50
49
  };
51
50
  db.createObjectStore(STORE_NAME, { keyPath: "id" });
52
51
  };
53
52
  });
54
- };
55
- IndexedDbStorage.prototype.withObjectStore = function (mode, action) {
56
- return this.getDb().then(function (db) {
57
- var tx = db.transaction(STORE_NAME, mode);
58
- tx.oncomplete = function () { return db.close(); };
59
- return new Promise(function (resolve, reject) {
60
- tx.onerror = function () { return reject(tx.error); };
53
+ }
54
+ withObjectStore(mode, action) {
55
+ return this.getDb().then((db) => {
56
+ const tx = db.transaction(STORE_NAME, mode);
57
+ tx.oncomplete = () => db.close();
58
+ return new Promise((resolve, reject) => {
59
+ tx.onerror = () => reject(tx.error);
61
60
  resolve(action(tx.objectStore(STORE_NAME)));
62
- }).catch(function (err) {
61
+ }).catch((err) => {
63
62
  db.close();
64
63
  throw err;
65
64
  });
66
65
  });
67
- };
68
- return IndexedDbStorage;
69
- }());
70
- export { IndexedDbStorage };
66
+ }
67
+ }
@@ -1,43 +1,21 @@
1
- import { __awaiter, __generator } from "tslib";
2
1
  import { GetCredentialsForIdentityCommand } from "@aws-sdk/client-cognito-identity";
3
2
  import { CredentialsProviderError } from "@aws-sdk/property-provider";
4
3
  import { resolveLogins } from "./resolveLogins";
5
4
  export function fromCognitoIdentity(parameters) {
6
- var _this = this;
7
- return function () { return __awaiter(_this, void 0, void 0, function () {
8
- var _a, _b, _c, AccessKeyId, Expiration, _d, SecretKey, SessionToken, _e, _f, _g, _h;
9
- var _j;
10
- return __generator(this, function (_k) {
11
- switch (_k.label) {
12
- case 0:
13
- _f = (_e = parameters.client).send;
14
- _g = GetCredentialsForIdentityCommand.bind;
15
- _j = {
16
- CustomRoleArn: parameters.customRoleArn,
17
- IdentityId: parameters.identityId
18
- };
19
- if (!parameters.logins) return [3, 2];
20
- return [4, resolveLogins(parameters.logins)];
21
- case 1:
22
- _h = _k.sent();
23
- return [3, 3];
24
- case 2:
25
- _h = undefined;
26
- _k.label = 3;
27
- case 3: return [4, _f.apply(_e, [new (_g.apply(GetCredentialsForIdentityCommand, [void 0, (_j.Logins = _h,
28
- _j)]))()])];
29
- case 4:
30
- _a = (_k.sent()).Credentials, _b = _a === void 0 ? throwOnMissingCredentials() : _a, _c = _b.AccessKeyId, AccessKeyId = _c === void 0 ? throwOnMissingAccessKeyId() : _c, Expiration = _b.Expiration, _d = _b.SecretKey, SecretKey = _d === void 0 ? throwOnMissingSecretKey() : _d, SessionToken = _b.SessionToken;
31
- return [2, {
32
- identityId: parameters.identityId,
33
- accessKeyId: AccessKeyId,
34
- secretAccessKey: SecretKey,
35
- sessionToken: SessionToken,
36
- expiration: Expiration,
37
- }];
38
- }
39
- });
40
- }); };
5
+ return async () => {
6
+ const { Credentials: { AccessKeyId = throwOnMissingAccessKeyId(), Expiration, SecretKey = throwOnMissingSecretKey(), SessionToken, } = throwOnMissingCredentials(), } = await parameters.client.send(new GetCredentialsForIdentityCommand({
7
+ CustomRoleArn: parameters.customRoleArn,
8
+ IdentityId: parameters.identityId,
9
+ Logins: parameters.logins ? await resolveLogins(parameters.logins) : undefined,
10
+ }));
11
+ return {
12
+ identityId: parameters.identityId,
13
+ accessKeyId: AccessKeyId,
14
+ secretAccessKey: SecretKey,
15
+ sessionToken: SessionToken,
16
+ expiration: Expiration,
17
+ };
18
+ };
41
19
  }
42
20
  function throwOnMissingAccessKeyId() {
43
21
  throw new CredentialsProviderError("Response from Amazon Cognito contained no access key ID");
@@ -1,72 +1,37 @@
1
- import { __awaiter, __generator } from "tslib";
2
1
  import { GetIdCommand } from "@aws-sdk/client-cognito-identity";
3
2
  import { CredentialsProviderError } from "@aws-sdk/property-provider";
4
3
  import { fromCognitoIdentity } from "./fromCognitoIdentity";
5
4
  import { localStorage } from "./localStorage";
6
5
  import { resolveLogins } from "./resolveLogins";
7
- export function fromCognitoIdentityPool(_a) {
8
- var _this = this;
9
- var accountId = _a.accountId, _b = _a.cache, cache = _b === void 0 ? localStorage() : _b, client = _a.client, customRoleArn = _a.customRoleArn, identityPoolId = _a.identityPoolId, logins = _a.logins, _c = _a.userIdentifier, userIdentifier = _c === void 0 ? !logins || Object.keys(logins).length === 0 ? "ANONYMOUS" : undefined : _c;
10
- var cacheKey = userIdentifier ? "aws:cognito-identity-credentials:".concat(identityPoolId, ":").concat(userIdentifier) : undefined;
11
- var provider = function () { return __awaiter(_this, void 0, void 0, function () {
12
- var identityId, _a, _b, IdentityId, _c, _d, _e, _f;
13
- var _g;
14
- return __generator(this, function (_h) {
15
- switch (_h.label) {
16
- case 0:
17
- _a = cacheKey;
18
- if (!_a) return [3, 2];
19
- return [4, cache.getItem(cacheKey)];
20
- case 1:
21
- _a = (_h.sent());
22
- _h.label = 2;
23
- case 2:
24
- identityId = _a;
25
- if (!!identityId) return [3, 7];
26
- _d = (_c = client).send;
27
- _e = GetIdCommand.bind;
28
- _g = {
29
- AccountId: accountId,
30
- IdentityPoolId: identityPoolId
31
- };
32
- if (!logins) return [3, 4];
33
- return [4, resolveLogins(logins)];
34
- case 3:
35
- _f = _h.sent();
36
- return [3, 5];
37
- case 4:
38
- _f = undefined;
39
- _h.label = 5;
40
- case 5: return [4, _d.apply(_c, [new (_e.apply(GetIdCommand, [void 0, (_g.Logins = _f,
41
- _g)]))()])];
42
- case 6:
43
- _b = (_h.sent()).IdentityId, IdentityId = _b === void 0 ? throwOnMissingId() : _b;
44
- identityId = IdentityId;
45
- if (cacheKey) {
46
- Promise.resolve(cache.setItem(cacheKey, identityId)).catch(function () { });
47
- }
48
- _h.label = 7;
49
- case 7:
50
- provider = fromCognitoIdentity({
51
- client: client,
52
- customRoleArn: customRoleArn,
53
- logins: logins,
54
- identityId: identityId,
55
- });
56
- return [2, provider()];
6
+ export function fromCognitoIdentityPool({ accountId, cache = localStorage(), client, customRoleArn, identityPoolId, logins, userIdentifier = !logins || Object.keys(logins).length === 0 ? "ANONYMOUS" : undefined, }) {
7
+ const cacheKey = userIdentifier ? `aws:cognito-identity-credentials:${identityPoolId}:${userIdentifier}` : undefined;
8
+ let provider = async () => {
9
+ let identityId = cacheKey && (await cache.getItem(cacheKey));
10
+ if (!identityId) {
11
+ const { IdentityId = throwOnMissingId() } = await client.send(new GetIdCommand({
12
+ AccountId: accountId,
13
+ IdentityPoolId: identityPoolId,
14
+ Logins: logins ? await resolveLogins(logins) : undefined,
15
+ }));
16
+ identityId = IdentityId;
17
+ if (cacheKey) {
18
+ Promise.resolve(cache.setItem(cacheKey, identityId)).catch(() => { });
57
19
  }
20
+ }
21
+ provider = fromCognitoIdentity({
22
+ client,
23
+ customRoleArn,
24
+ logins,
25
+ identityId,
58
26
  });
59
- }); };
60
- return function () {
61
- return provider().catch(function (err) { return __awaiter(_this, void 0, void 0, function () {
62
- return __generator(this, function (_a) {
63
- if (cacheKey) {
64
- Promise.resolve(cache.removeItem(cacheKey)).catch(function () { });
65
- }
66
- throw err;
67
- });
68
- }); });
27
+ return provider();
69
28
  };
29
+ return () => provider().catch(async (err) => {
30
+ if (cacheKey) {
31
+ Promise.resolve(cache.removeItem(cacheKey)).catch(() => { });
32
+ }
33
+ throw err;
34
+ });
70
35
  }
71
36
  function throwOnMissingId() {
72
37
  throw new CredentialsProviderError("Response from Amazon Cognito contained no identity ID");
@@ -1,6 +1,6 @@
1
1
  import { IndexedDbStorage } from "./IndexedDbStorage";
2
2
  import { InMemoryStorage } from "./InMemoryStorage";
3
- var inMemoryStorage = new InMemoryStorage();
3
+ const inMemoryStorage = new InMemoryStorage();
4
4
  export function localStorage() {
5
5
  if (typeof self === "object" && self.indexedDB) {
6
6
  return new IndexedDbStorage();
@@ -1,19 +1,15 @@
1
- import { __read } from "tslib";
2
1
  export function resolveLogins(logins) {
3
- return Promise.all(Object.keys(logins).reduce(function (arr, name) {
4
- var tokenOrProvider = logins[name];
2
+ return Promise.all(Object.keys(logins).reduce((arr, name) => {
3
+ const tokenOrProvider = logins[name];
5
4
  if (typeof tokenOrProvider === "string") {
6
5
  arr.push([name, tokenOrProvider]);
7
6
  }
8
7
  else {
9
- arr.push(tokenOrProvider().then(function (token) { return [name, token]; }));
8
+ arr.push(tokenOrProvider().then((token) => [name, token]));
10
9
  }
11
10
  return arr;
12
- }, [])).then(function (resolvedPairs) {
13
- return resolvedPairs.reduce(function (logins, _a) {
14
- var _b = __read(_a, 2), key = _b[0], value = _b[1];
15
- logins[key] = value;
16
- return logins;
17
- }, {});
18
- });
11
+ }, [])).then((resolvedPairs) => resolvedPairs.reduce((logins, [key, value]) => {
12
+ logins[key] = value;
13
+ return logins;
14
+ }, {}));
19
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/credential-provider-cognito-identity",
3
- "version": "3.186.0",
3
+ "version": "3.188.0",
4
4
  "scripts": {
5
5
  "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
6
6
  "build:cjs": "tsc -p tsconfig.cjs.json",
@@ -21,9 +21,9 @@
21
21
  },
22
22
  "license": "Apache-2.0",
23
23
  "dependencies": {
24
- "@aws-sdk/client-cognito-identity": "3.186.0",
25
- "@aws-sdk/property-provider": "3.186.0",
26
- "@aws-sdk/types": "3.186.0",
24
+ "@aws-sdk/client-cognito-identity": "3.188.0",
25
+ "@aws-sdk/property-provider": "3.188.0",
26
+ "@aws-sdk/types": "3.188.0",
27
27
  "tslib": "^2.3.1"
28
28
  },
29
29
  "engines": {