@aws-sdk/credential-provider-cognito-identity 3.901.0 → 3.906.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/dist-cjs/index.js CHANGED
@@ -1,295 +1,202 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
- var __esm = (fn, res) => function __init() {
8
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
9
- };
10
- var __export = (target, all) => {
11
- for (var name in all)
12
- __defProp(target, name, { get: all[name], enumerable: true });
13
- };
14
- var __copyProps = (to, from, except, desc) => {
15
- if (from && typeof from === "object" || typeof from === "function") {
16
- for (let key of __getOwnPropNames(from))
17
- if (!__hasOwnProp.call(to, key) && key !== except)
18
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
- }
20
- return to;
21
- };
22
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ 'use strict';
23
2
 
24
- // src/loadCognitoIdentity.ts
25
- var loadCognitoIdentity_exports = {};
26
- __export(loadCognitoIdentity_exports, {
27
- CognitoIdentityClient: () => import_client_cognito_identity.CognitoIdentityClient,
28
- GetCredentialsForIdentityCommand: () => import_client_cognito_identity.GetCredentialsForIdentityCommand,
29
- GetIdCommand: () => import_client_cognito_identity.GetIdCommand
30
- });
31
- var import_client_cognito_identity;
32
- var init_loadCognitoIdentity = __esm({
33
- "src/loadCognitoIdentity.ts"() {
34
- "use strict";
35
- import_client_cognito_identity = require("@aws-sdk/client-cognito-identity");
36
- }
37
- });
3
+ var propertyProvider = require('@smithy/property-provider');
38
4
 
39
- // src/index.ts
40
- var index_exports = {};
41
- __export(index_exports, {
42
- fromCognitoIdentity: () => fromCognitoIdentity,
43
- fromCognitoIdentityPool: () => fromCognitoIdentityPool
44
- });
45
- module.exports = __toCommonJS(index_exports);
46
-
47
- // src/fromCognitoIdentity.ts
48
- var import_property_provider = require("@smithy/property-provider");
49
-
50
- // src/resolveLogins.ts
51
5
  function resolveLogins(logins) {
52
- return Promise.all(
53
- Object.keys(logins).reduce((arr, name) => {
54
- const tokenOrProvider = logins[name];
55
- if (typeof tokenOrProvider === "string") {
56
- arr.push([name, tokenOrProvider]);
57
- } else {
58
- arr.push(tokenOrProvider().then((token) => [name, token]));
59
- }
60
- return arr;
61
- }, [])
62
- ).then(
63
- (resolvedPairs) => resolvedPairs.reduce((logins2, [key, value]) => {
64
- logins2[key] = value;
65
- return logins2;
66
- }, {})
67
- );
6
+ return Promise.all(Object.keys(logins).reduce((arr, name) => {
7
+ const tokenOrProvider = logins[name];
8
+ if (typeof tokenOrProvider === "string") {
9
+ arr.push([name, tokenOrProvider]);
10
+ }
11
+ else {
12
+ arr.push(tokenOrProvider().then((token) => [name, token]));
13
+ }
14
+ return arr;
15
+ }, [])).then((resolvedPairs) => resolvedPairs.reduce((logins, [key, value]) => {
16
+ logins[key] = value;
17
+ return logins;
18
+ }, {}));
68
19
  }
69
- __name(resolveLogins, "resolveLogins");
70
20
 
71
- // src/fromCognitoIdentity.ts
72
21
  function fromCognitoIdentity(parameters) {
73
- return async (awsIdentityProperties) => {
74
- parameters.logger?.debug("@aws-sdk/credential-provider-cognito-identity - fromCognitoIdentity");
75
- const { GetCredentialsForIdentityCommand: GetCredentialsForIdentityCommand2, CognitoIdentityClient: CognitoIdentityClient2 } = await Promise.resolve().then(() => (init_loadCognitoIdentity(), loadCognitoIdentity_exports));
76
- const fromConfigs = /* @__PURE__ */ __name((property) => parameters.clientConfig?.[property] ?? parameters.parentClientConfig?.[property] ?? awsIdentityProperties?.callerClientConfig?.[property], "fromConfigs");
77
- const {
78
- Credentials: {
79
- AccessKeyId = throwOnMissingAccessKeyId(parameters.logger),
80
- Expiration,
81
- SecretKey = throwOnMissingSecretKey(parameters.logger),
82
- SessionToken
83
- } = throwOnMissingCredentials(parameters.logger)
84
- } = await (parameters.client ?? new CognitoIdentityClient2(
85
- Object.assign({}, parameters.clientConfig ?? {}, {
86
- region: fromConfigs("region"),
87
- profile: fromConfigs("profile")
88
- })
89
- )).send(
90
- new GetCredentialsForIdentityCommand2({
91
- CustomRoleArn: parameters.customRoleArn,
92
- IdentityId: parameters.identityId,
93
- Logins: parameters.logins ? await resolveLogins(parameters.logins) : void 0
94
- })
95
- );
96
- return {
97
- identityId: parameters.identityId,
98
- accessKeyId: AccessKeyId,
99
- secretAccessKey: SecretKey,
100
- sessionToken: SessionToken,
101
- expiration: Expiration
22
+ return async (awsIdentityProperties) => {
23
+ parameters.logger?.debug("@aws-sdk/credential-provider-cognito-identity - fromCognitoIdentity");
24
+ const { GetCredentialsForIdentityCommand, CognitoIdentityClient } = await Promise.resolve().then(function () { return require('./loadCognitoIdentity-BPNvueUJ.js'); });
25
+ const fromConfigs = (property) => parameters.clientConfig?.[property] ??
26
+ parameters.parentClientConfig?.[property] ??
27
+ awsIdentityProperties?.callerClientConfig?.[property];
28
+ const { Credentials: { AccessKeyId = throwOnMissingAccessKeyId(parameters.logger), Expiration, SecretKey = throwOnMissingSecretKey(parameters.logger), SessionToken, } = throwOnMissingCredentials(parameters.logger), } = await (parameters.client ??
29
+ new CognitoIdentityClient(Object.assign({}, parameters.clientConfig ?? {}, {
30
+ region: fromConfigs("region"),
31
+ profile: fromConfigs("profile"),
32
+ }))).send(new GetCredentialsForIdentityCommand({
33
+ CustomRoleArn: parameters.customRoleArn,
34
+ IdentityId: parameters.identityId,
35
+ Logins: parameters.logins ? await resolveLogins(parameters.logins) : undefined,
36
+ }));
37
+ return {
38
+ identityId: parameters.identityId,
39
+ accessKeyId: AccessKeyId,
40
+ secretAccessKey: SecretKey,
41
+ sessionToken: SessionToken,
42
+ expiration: Expiration,
43
+ };
102
44
  };
103
- };
104
45
  }
105
- __name(fromCognitoIdentity, "fromCognitoIdentity");
106
46
  function throwOnMissingAccessKeyId(logger) {
107
- throw new import_property_provider.CredentialsProviderError("Response from Amazon Cognito contained no access key ID", { logger });
47
+ throw new propertyProvider.CredentialsProviderError("Response from Amazon Cognito contained no access key ID", { logger });
108
48
  }
109
- __name(throwOnMissingAccessKeyId, "throwOnMissingAccessKeyId");
110
49
  function throwOnMissingCredentials(logger) {
111
- throw new import_property_provider.CredentialsProviderError("Response from Amazon Cognito contained no credentials", { logger });
50
+ throw new propertyProvider.CredentialsProviderError("Response from Amazon Cognito contained no credentials", { logger });
112
51
  }
113
- __name(throwOnMissingCredentials, "throwOnMissingCredentials");
114
52
  function throwOnMissingSecretKey(logger) {
115
- throw new import_property_provider.CredentialsProviderError("Response from Amazon Cognito contained no secret key", { logger });
53
+ throw new propertyProvider.CredentialsProviderError("Response from Amazon Cognito contained no secret key", { logger });
116
54
  }
117
- __name(throwOnMissingSecretKey, "throwOnMissingSecretKey");
118
-
119
- // src/fromCognitoIdentityPool.ts
120
-
121
55
 
122
- // src/IndexedDbStorage.ts
123
- var STORE_NAME = "IdentityIds";
124
- var IndexedDbStorage = class {
125
- constructor(dbName = "aws:cognito-identity-ids") {
126
- this.dbName = dbName;
127
- }
128
- static {
129
- __name(this, "IndexedDbStorage");
130
- }
131
- getItem(key) {
132
- return this.withObjectStore("readonly", (store) => {
133
- const req = store.get(key);
134
- return new Promise((resolve) => {
135
- req.onerror = () => resolve(null);
136
- req.onsuccess = () => resolve(req.result ? req.result.value : null);
137
- });
138
- }).catch(() => null);
139
- }
140
- removeItem(key) {
141
- return this.withObjectStore("readwrite", (store) => {
142
- const req = store.delete(key);
143
- return new Promise((resolve, reject) => {
144
- req.onerror = () => reject(req.error);
145
- req.onsuccess = () => resolve();
146
- });
147
- });
148
- }
149
- setItem(id, value) {
150
- return this.withObjectStore("readwrite", (store) => {
151
- const req = store.put({ id, value });
152
- return new Promise((resolve, reject) => {
153
- req.onerror = () => reject(req.error);
154
- req.onsuccess = () => resolve();
155
- });
156
- });
157
- }
158
- getDb() {
159
- const openDbRequest = self.indexedDB.open(this.dbName, 1);
160
- return new Promise((resolve, reject) => {
161
- openDbRequest.onsuccess = () => {
162
- resolve(openDbRequest.result);
163
- };
164
- openDbRequest.onerror = () => {
165
- reject(openDbRequest.error);
166
- };
167
- openDbRequest.onblocked = () => {
168
- reject(new Error("Unable to access DB"));
169
- };
170
- openDbRequest.onupgradeneeded = () => {
171
- const db = openDbRequest.result;
172
- db.onerror = () => {
173
- reject(new Error("Failed to create object store"));
174
- };
175
- db.createObjectStore(STORE_NAME, { keyPath: "id" });
176
- };
177
- });
178
- }
179
- withObjectStore(mode, action) {
180
- return this.getDb().then((db) => {
181
- const tx = db.transaction(STORE_NAME, mode);
182
- tx.oncomplete = () => db.close();
183
- return new Promise((resolve, reject) => {
184
- tx.onerror = () => reject(tx.error);
185
- resolve(action(tx.objectStore(STORE_NAME)));
186
- }).catch((err) => {
187
- db.close();
188
- throw err;
189
- });
190
- });
191
- }
192
- };
56
+ const STORE_NAME = "IdentityIds";
57
+ class IndexedDbStorage {
58
+ dbName;
59
+ constructor(dbName = "aws:cognito-identity-ids") {
60
+ this.dbName = dbName;
61
+ }
62
+ getItem(key) {
63
+ return this.withObjectStore("readonly", (store) => {
64
+ const req = store.get(key);
65
+ return new Promise((resolve) => {
66
+ req.onerror = () => resolve(null);
67
+ req.onsuccess = () => resolve(req.result ? req.result.value : null);
68
+ });
69
+ }).catch(() => null);
70
+ }
71
+ removeItem(key) {
72
+ return this.withObjectStore("readwrite", (store) => {
73
+ const req = store.delete(key);
74
+ return new Promise((resolve, reject) => {
75
+ req.onerror = () => reject(req.error);
76
+ req.onsuccess = () => resolve();
77
+ });
78
+ });
79
+ }
80
+ setItem(id, value) {
81
+ return this.withObjectStore("readwrite", (store) => {
82
+ const req = store.put({ id, value });
83
+ return new Promise((resolve, reject) => {
84
+ req.onerror = () => reject(req.error);
85
+ req.onsuccess = () => resolve();
86
+ });
87
+ });
88
+ }
89
+ getDb() {
90
+ const openDbRequest = self.indexedDB.open(this.dbName, 1);
91
+ return new Promise((resolve, reject) => {
92
+ openDbRequest.onsuccess = () => {
93
+ resolve(openDbRequest.result);
94
+ };
95
+ openDbRequest.onerror = () => {
96
+ reject(openDbRequest.error);
97
+ };
98
+ openDbRequest.onblocked = () => {
99
+ reject(new Error("Unable to access DB"));
100
+ };
101
+ openDbRequest.onupgradeneeded = () => {
102
+ const db = openDbRequest.result;
103
+ db.onerror = () => {
104
+ reject(new Error("Failed to create object store"));
105
+ };
106
+ db.createObjectStore(STORE_NAME, { keyPath: "id" });
107
+ };
108
+ });
109
+ }
110
+ withObjectStore(mode, action) {
111
+ return this.getDb().then((db) => {
112
+ const tx = db.transaction(STORE_NAME, mode);
113
+ tx.oncomplete = () => db.close();
114
+ return new Promise((resolve, reject) => {
115
+ tx.onerror = () => reject(tx.error);
116
+ resolve(action(tx.objectStore(STORE_NAME)));
117
+ }).catch((err) => {
118
+ db.close();
119
+ throw err;
120
+ });
121
+ });
122
+ }
123
+ }
193
124
 
194
- // src/InMemoryStorage.ts
195
- var InMemoryStorage = class {
196
- constructor(store = {}) {
197
- this.store = store;
198
- }
199
- static {
200
- __name(this, "InMemoryStorage");
201
- }
202
- getItem(key) {
203
- if (key in this.store) {
204
- return this.store[key];
125
+ class InMemoryStorage {
126
+ store;
127
+ constructor(store = {}) {
128
+ this.store = store;
129
+ }
130
+ getItem(key) {
131
+ if (key in this.store) {
132
+ return this.store[key];
133
+ }
134
+ return null;
135
+ }
136
+ removeItem(key) {
137
+ delete this.store[key];
138
+ }
139
+ setItem(key, value) {
140
+ this.store[key] = value;
205
141
  }
206
- return null;
207
- }
208
- removeItem(key) {
209
- delete this.store[key];
210
- }
211
- setItem(key, value) {
212
- this.store[key] = value;
213
- }
214
- };
142
+ }
215
143
 
216
- // src/localStorage.ts
217
- var inMemoryStorage = new InMemoryStorage();
144
+ const inMemoryStorage = new InMemoryStorage();
218
145
  function localStorage() {
219
- if (typeof self === "object" && self.indexedDB) {
220
- return new IndexedDbStorage();
221
- }
222
- if (typeof window === "object" && window.localStorage) {
223
- return window.localStorage;
224
- }
225
- return inMemoryStorage;
146
+ if (typeof self === "object" && self.indexedDB) {
147
+ return new IndexedDbStorage();
148
+ }
149
+ if (typeof window === "object" && window.localStorage) {
150
+ return window.localStorage;
151
+ }
152
+ return inMemoryStorage;
226
153
  }
227
- __name(localStorage, "localStorage");
228
154
 
229
- // src/fromCognitoIdentityPool.ts
230
- function fromCognitoIdentityPool({
231
- accountId,
232
- cache = localStorage(),
233
- client,
234
- clientConfig,
235
- customRoleArn,
236
- identityPoolId,
237
- logins,
238
- userIdentifier = !logins || Object.keys(logins).length === 0 ? "ANONYMOUS" : void 0,
239
- logger,
240
- parentClientConfig
241
- }) {
242
- logger?.debug("@aws-sdk/credential-provider-cognito-identity - fromCognitoIdentity");
243
- const cacheKey = userIdentifier ? `aws:cognito-identity-credentials:${identityPoolId}:${userIdentifier}` : void 0;
244
- let provider = /* @__PURE__ */ __name(async (awsIdentityProperties) => {
245
- const { GetIdCommand: GetIdCommand2, CognitoIdentityClient: CognitoIdentityClient2 } = await Promise.resolve().then(() => (init_loadCognitoIdentity(), loadCognitoIdentity_exports));
246
- const fromConfigs = /* @__PURE__ */ __name((property) => clientConfig?.[property] ?? parentClientConfig?.[property] ?? awsIdentityProperties?.callerClientConfig?.[property], "fromConfigs");
247
- const _client = client ?? new CognitoIdentityClient2(
248
- Object.assign({}, clientConfig ?? {}, {
249
- region: fromConfigs("region"),
250
- profile: fromConfigs("profile")
251
- })
252
- );
253
- let identityId = cacheKey && await cache.getItem(cacheKey);
254
- if (!identityId) {
255
- const { IdentityId = throwOnMissingId(logger) } = await _client.send(
256
- new GetIdCommand2({
257
- AccountId: accountId,
258
- IdentityPoolId: identityPoolId,
259
- Logins: logins ? await resolveLogins(logins) : void 0
260
- })
261
- );
262
- identityId = IdentityId;
263
- if (cacheKey) {
264
- Promise.resolve(cache.setItem(cacheKey, identityId)).catch(() => {
155
+ function fromCognitoIdentityPool({ accountId, cache = localStorage(), client, clientConfig, customRoleArn, identityPoolId, logins, userIdentifier = !logins || Object.keys(logins).length === 0 ? "ANONYMOUS" : undefined, logger, parentClientConfig, }) {
156
+ logger?.debug("@aws-sdk/credential-provider-cognito-identity - fromCognitoIdentity");
157
+ const cacheKey = userIdentifier
158
+ ? `aws:cognito-identity-credentials:${identityPoolId}:${userIdentifier}`
159
+ : undefined;
160
+ let provider = async (awsIdentityProperties) => {
161
+ const { GetIdCommand, CognitoIdentityClient } = await Promise.resolve().then(function () { return require('./loadCognitoIdentity-BPNvueUJ.js'); });
162
+ const fromConfigs = (property) => clientConfig?.[property] ??
163
+ parentClientConfig?.[property] ??
164
+ awsIdentityProperties?.callerClientConfig?.[property];
165
+ const _client = client ??
166
+ new CognitoIdentityClient(Object.assign({}, clientConfig ?? {}, {
167
+ region: fromConfigs("region"),
168
+ profile: fromConfigs("profile"),
169
+ }));
170
+ let identityId = (cacheKey && (await cache.getItem(cacheKey)));
171
+ if (!identityId) {
172
+ const { IdentityId = throwOnMissingId(logger) } = await _client.send(new GetIdCommand({
173
+ AccountId: accountId,
174
+ IdentityPoolId: identityPoolId,
175
+ Logins: logins ? await resolveLogins(logins) : undefined,
176
+ }));
177
+ identityId = IdentityId;
178
+ if (cacheKey) {
179
+ Promise.resolve(cache.setItem(cacheKey, identityId)).catch(() => { });
180
+ }
181
+ }
182
+ provider = fromCognitoIdentity({
183
+ client: _client,
184
+ customRoleArn,
185
+ logins,
186
+ identityId,
265
187
  });
266
- }
267
- }
268
- provider = fromCognitoIdentity({
269
- client: _client,
270
- customRoleArn,
271
- logins,
272
- identityId
188
+ return provider(awsIdentityProperties);
189
+ };
190
+ return (awsIdentityProperties) => provider(awsIdentityProperties).catch(async (err) => {
191
+ if (cacheKey) {
192
+ Promise.resolve(cache.removeItem(cacheKey)).catch(() => { });
193
+ }
194
+ throw err;
273
195
  });
274
- return provider(awsIdentityProperties);
275
- }, "provider");
276
- return (awsIdentityProperties) => provider(awsIdentityProperties).catch(async (err) => {
277
- if (cacheKey) {
278
- Promise.resolve(cache.removeItem(cacheKey)).catch(() => {
279
- });
280
- }
281
- throw err;
282
- });
283
196
  }
284
- __name(fromCognitoIdentityPool, "fromCognitoIdentityPool");
285
197
  function throwOnMissingId(logger) {
286
- throw new import_property_provider.CredentialsProviderError("Response from Amazon Cognito contained no identity ID", { logger });
198
+ throw new propertyProvider.CredentialsProviderError("Response from Amazon Cognito contained no identity ID", { logger });
287
199
  }
288
- __name(throwOnMissingId, "throwOnMissingId");
289
- // Annotate the CommonJS export names for ESM import in node:
290
-
291
- 0 && (module.exports = {
292
- fromCognitoIdentity,
293
- fromCognitoIdentityPool
294
- });
295
200
 
201
+ exports.fromCognitoIdentity = fromCognitoIdentity;
202
+ exports.fromCognitoIdentityPool = fromCognitoIdentityPool;
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ var clientCognitoIdentity = require('@aws-sdk/client-cognito-identity');
4
+
5
+
6
+
7
+ Object.defineProperty(exports, "CognitoIdentityClient", {
8
+ enumerable: true,
9
+ get: function () { return clientCognitoIdentity.CognitoIdentityClient; }
10
+ });
11
+ Object.defineProperty(exports, "GetCredentialsForIdentityCommand", {
12
+ enumerable: true,
13
+ get: function () { return clientCognitoIdentity.GetCredentialsForIdentityCommand; }
14
+ });
15
+ Object.defineProperty(exports, "GetIdCommand", {
16
+ enumerable: true,
17
+ get: function () { return clientCognitoIdentity.GetIdCommand; }
18
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/credential-provider-cognito-identity",
3
- "version": "3.901.0",
3
+ "version": "3.906.0",
4
4
  "scripts": {
5
5
  "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
6
6
  "build:cjs": "node ../../scripts/compilation/inline credential-provider-cognito-identity",
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "license": "Apache-2.0",
26
26
  "dependencies": {
27
- "@aws-sdk/client-cognito-identity": "3.901.0",
27
+ "@aws-sdk/client-cognito-identity": "3.906.0",
28
28
  "@aws-sdk/types": "3.901.0",
29
29
  "@smithy/property-provider": "^4.2.0",
30
30
  "@smithy/types": "^4.6.0",