@aws-sdk/credential-provider-cognito-identity 3.901.0 → 3.907.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 +175 -268
- package/dist-cjs/loadCognitoIdentity-BPNvueUJ.js +18 -0
- package/package.json +2 -2
package/dist-cjs/index.js
CHANGED
|
@@ -1,295 +1,202 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}, [])
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
AccessKeyId = throwOnMissingAccessKeyId(parameters.logger),
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
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
|
-
|
|
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
|
-
|
|
217
|
-
var inMemoryStorage = new InMemoryStorage();
|
|
144
|
+
const inMemoryStorage = new InMemoryStorage();
|
|
218
145
|
function localStorage() {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
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
|
-
|
|
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.
|
|
3
|
+
"version": "3.907.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.
|
|
27
|
+
"@aws-sdk/client-cognito-identity": "3.907.0",
|
|
28
28
|
"@aws-sdk/types": "3.901.0",
|
|
29
29
|
"@smithy/property-provider": "^4.2.0",
|
|
30
30
|
"@smithy/types": "^4.6.0",
|