@aws-sdk/credential-provider-cognito-identity 3.185.0 → 3.186.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.186.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.185.0...v3.186.0) (2022-10-06)
7
+
8
+ **Note:** Version bump only for package @aws-sdk/credential-provider-cognito-identity
9
+
10
+
11
+
12
+
13
+
6
14
  # [3.185.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.184.0...v3.185.0) (2022-10-05)
7
15
 
8
16
  **Note:** Version bump only for package @aws-sdk/credential-provider-cognito-identity
@@ -1,17 +1,20 @@
1
- export class InMemoryStorage {
2
- constructor(store = {}) {
1
+ var InMemoryStorage = (function () {
2
+ function InMemoryStorage(store) {
3
+ if (store === void 0) { store = {}; }
3
4
  this.store = store;
4
5
  }
5
- getItem(key) {
6
+ InMemoryStorage.prototype.getItem = function (key) {
6
7
  if (key in this.store) {
7
8
  return this.store[key];
8
9
  }
9
10
  return null;
10
- }
11
- removeItem(key) {
11
+ };
12
+ InMemoryStorage.prototype.removeItem = function (key) {
12
13
  delete this.store[key];
13
- }
14
- setItem(key, value) {
14
+ };
15
+ InMemoryStorage.prototype.setItem = function (key, value) {
15
16
  this.store[key] = value;
16
- }
17
- }
17
+ };
18
+ return InMemoryStorage;
19
+ }());
20
+ export { InMemoryStorage };
@@ -1,67 +1,70 @@
1
- const STORE_NAME = "IdentityIds";
2
- export class IndexedDbStorage {
3
- constructor(dbName = "aws:cognito-identity-ids") {
1
+ var STORE_NAME = "IdentityIds";
2
+ var IndexedDbStorage = (function () {
3
+ function IndexedDbStorage(dbName) {
4
+ if (dbName === void 0) { dbName = "aws:cognito-identity-ids"; }
4
5
  this.dbName = dbName;
5
6
  }
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);
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); };
12
13
  });
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();
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(); };
21
22
  });
22
23
  });
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();
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(); };
30
31
  });
31
32
  });
32
- }
33
- getDb() {
34
- const openDbRequest = self.indexedDB.open(this.dbName, 1);
35
- return new Promise((resolve, reject) => {
36
- openDbRequest.onsuccess = () => {
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 () {
37
38
  resolve(openDbRequest.result);
38
39
  };
39
- openDbRequest.onerror = () => {
40
+ openDbRequest.onerror = function () {
40
41
  reject(openDbRequest.error);
41
42
  };
42
- openDbRequest.onblocked = () => {
43
+ openDbRequest.onblocked = function () {
43
44
  reject(new Error("Unable to access DB"));
44
45
  };
45
- openDbRequest.onupgradeneeded = () => {
46
- const db = openDbRequest.result;
47
- db.onerror = () => {
46
+ openDbRequest.onupgradeneeded = function () {
47
+ var db = openDbRequest.result;
48
+ db.onerror = function () {
48
49
  reject(new Error("Failed to create object store"));
49
50
  };
50
51
  db.createObjectStore(STORE_NAME, { keyPath: "id" });
51
52
  };
52
53
  });
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);
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); };
60
61
  resolve(action(tx.objectStore(STORE_NAME)));
61
- }).catch((err) => {
62
+ }).catch(function (err) {
62
63
  db.close();
63
64
  throw err;
64
65
  });
65
66
  });
66
- }
67
- }
67
+ };
68
+ return IndexedDbStorage;
69
+ }());
70
+ export { IndexedDbStorage };
@@ -1,21 +1,43 @@
1
+ import { __awaiter, __generator } from "tslib";
1
2
  import { GetCredentialsForIdentityCommand } from "@aws-sdk/client-cognito-identity";
2
3
  import { CredentialsProviderError } from "@aws-sdk/property-provider";
3
4
  import { resolveLogins } from "./resolveLogins";
4
5
  export function fromCognitoIdentity(parameters) {
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
- };
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
+ }); };
19
41
  }
20
42
  function throwOnMissingAccessKeyId() {
21
43
  throw new CredentialsProviderError("Response from Amazon Cognito contained no access key ID");
@@ -1,37 +1,72 @@
1
+ import { __awaiter, __generator } from "tslib";
1
2
  import { GetIdCommand } from "@aws-sdk/client-cognito-identity";
2
3
  import { CredentialsProviderError } from "@aws-sdk/property-provider";
3
4
  import { fromCognitoIdentity } from "./fromCognitoIdentity";
4
5
  import { localStorage } from "./localStorage";
5
6
  import { resolveLogins } from "./resolveLogins";
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(() => { });
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()];
19
57
  }
20
- }
21
- provider = fromCognitoIdentity({
22
- client,
23
- customRoleArn,
24
- logins,
25
- identityId,
26
58
  });
27
- return provider();
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
+ }); });
28
69
  };
29
- return () => provider().catch(async (err) => {
30
- if (cacheKey) {
31
- Promise.resolve(cache.removeItem(cacheKey)).catch(() => { });
32
- }
33
- throw err;
34
- });
35
70
  }
36
71
  function throwOnMissingId() {
37
72
  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
- const inMemoryStorage = new InMemoryStorage();
3
+ var inMemoryStorage = new InMemoryStorage();
4
4
  export function localStorage() {
5
5
  if (typeof self === "object" && self.indexedDB) {
6
6
  return new IndexedDbStorage();
@@ -1,15 +1,19 @@
1
+ import { __read } from "tslib";
1
2
  export function resolveLogins(logins) {
2
- return Promise.all(Object.keys(logins).reduce((arr, name) => {
3
- const tokenOrProvider = logins[name];
3
+ return Promise.all(Object.keys(logins).reduce(function (arr, name) {
4
+ var tokenOrProvider = logins[name];
4
5
  if (typeof tokenOrProvider === "string") {
5
6
  arr.push([name, tokenOrProvider]);
6
7
  }
7
8
  else {
8
- arr.push(tokenOrProvider().then((token) => [name, token]));
9
+ arr.push(tokenOrProvider().then(function (token) { return [name, token]; }));
9
10
  }
10
11
  return arr;
11
- }, [])).then((resolvedPairs) => resolvedPairs.reduce((logins, [key, value]) => {
12
- logins[key] = value;
13
- return logins;
14
- }, {}));
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
+ });
15
19
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/credential-provider-cognito-identity",
3
- "version": "3.185.0",
3
+ "version": "3.186.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.185.0",
25
- "@aws-sdk/property-provider": "3.183.0",
26
- "@aws-sdk/types": "3.183.0",
24
+ "@aws-sdk/client-cognito-identity": "3.186.0",
25
+ "@aws-sdk/property-provider": "3.186.0",
26
+ "@aws-sdk/types": "3.186.0",
27
27
  "tslib": "^2.3.1"
28
28
  },
29
29
  "engines": {