@gugananuvem/aws-local-simulator 1.0.18 → 1.0.20
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gugananuvem/aws-local-simulator",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.20",
|
|
4
4
|
"description": "Simulador local completo para serviços AWS",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -120,6 +120,6 @@
|
|
|
120
120
|
"optional": true
|
|
121
121
|
}
|
|
122
122
|
},
|
|
123
|
-
"buildDate": "2026-04-
|
|
123
|
+
"buildDate": "2026-04-22T02:31:17.105Z",
|
|
124
124
|
"published": true
|
|
125
125
|
}
|
|
@@ -223,7 +223,7 @@ class CognitoSimulator {
|
|
|
223
223
|
Enabled: u.Enabled,
|
|
224
224
|
UserCreateDate: u.CreatedDate,
|
|
225
225
|
UserLastModifiedDate: u.LastModifiedDate,
|
|
226
|
-
Attributes: this.
|
|
226
|
+
Attributes: this._formatUserAttributesWithSub(u),
|
|
227
227
|
})),
|
|
228
228
|
PaginationToken: nextToken,
|
|
229
229
|
};
|
|
@@ -570,9 +570,10 @@ class CognitoSimulator {
|
|
|
570
570
|
if (!this.sessions.has(session.Id)) throw new Error("Token has been revoked");
|
|
571
571
|
const user = this.users.get(session.UserId);
|
|
572
572
|
if (!user) throw new Error("User not found");
|
|
573
|
+
const attributes = this._formatUserAttributesWithSub(user);
|
|
573
574
|
return {
|
|
574
575
|
Username: user.Username,
|
|
575
|
-
UserAttributes:
|
|
576
|
+
UserAttributes: attributes,
|
|
576
577
|
UserStatus: user.UserStatus,
|
|
577
578
|
};
|
|
578
579
|
}
|
|
@@ -1155,7 +1156,7 @@ class CognitoSimulator {
|
|
|
1155
1156
|
|
|
1156
1157
|
return {
|
|
1157
1158
|
Username: user.Username,
|
|
1158
|
-
UserAttributes: this.
|
|
1159
|
+
UserAttributes: this._formatUserAttributesWithSub(user),
|
|
1159
1160
|
UserCreateDate: user.CreatedDate,
|
|
1160
1161
|
UserLastModifiedDate: user.LastModifiedDate,
|
|
1161
1162
|
Enabled: user.Enabled,
|
|
@@ -1214,7 +1215,7 @@ class CognitoSimulator {
|
|
|
1214
1215
|
return {
|
|
1215
1216
|
User: {
|
|
1216
1217
|
Username: user.Username,
|
|
1217
|
-
UserAttributes: this.
|
|
1218
|
+
UserAttributes: this._formatUserAttributesWithSub(user),
|
|
1218
1219
|
UserCreateDate: user.CreatedDate,
|
|
1219
1220
|
UserLastModifiedDate: user.LastModifiedDate,
|
|
1220
1221
|
Enabled: user.Enabled,
|
|
@@ -1321,6 +1322,14 @@ class CognitoSimulator {
|
|
|
1321
1322
|
return Object.entries(attributes).map(([Name, Value]) => ({ Name, Value }));
|
|
1322
1323
|
}
|
|
1323
1324
|
|
|
1325
|
+
_formatUserAttributesWithSub(user) {
|
|
1326
|
+
const attrs = this.formatUserAttributes(user.Attributes);
|
|
1327
|
+
if (!attrs.find(a => a.Name === 'sub')) {
|
|
1328
|
+
attrs.unshift({ Name: 'sub', Value: user.UserId });
|
|
1329
|
+
}
|
|
1330
|
+
return attrs;
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1324
1333
|
hashPassword(password) {
|
|
1325
1334
|
// Simulação de hash (não usar em produção real)
|
|
1326
1335
|
return crypto.createHash("sha256").update(password).digest("hex");
|
|
@@ -550,39 +550,53 @@ class DynamoDBSimulator {
|
|
|
550
550
|
normalizeItem(item, table) {
|
|
551
551
|
const normalized = { ...item };
|
|
552
552
|
|
|
553
|
-
// Remove os tipos do DynamoDB (S, N, etc)
|
|
554
553
|
for (const [key, value] of Object.entries(normalized)) {
|
|
555
|
-
|
|
556
|
-
if (value.S !== undefined) normalized[key] = value.S;
|
|
557
|
-
else if (value.N !== undefined) normalized[key] = parseFloat(value.N);
|
|
558
|
-
else if (value.BOOL !== undefined) normalized[key] = value.BOOL;
|
|
559
|
-
else if (value.L !== undefined) normalized[key] = value.L.map((v) => this.normalizeItem(v, table));
|
|
560
|
-
else if (value.M !== undefined) normalized[key] = this.normalizeItem(value.M, table);
|
|
561
|
-
}
|
|
554
|
+
normalized[key] = this.normalizeValue(value, table);
|
|
562
555
|
}
|
|
563
556
|
|
|
564
557
|
return normalized;
|
|
565
558
|
}
|
|
566
559
|
|
|
560
|
+
normalizeValue(value, table) {
|
|
561
|
+
if (value === null || value === undefined) return value;
|
|
562
|
+
if (typeof value !== 'object') return value;
|
|
563
|
+
|
|
564
|
+
if (value.S !== undefined) return value.S;
|
|
565
|
+
if (value.N !== undefined) return parseFloat(value.N);
|
|
566
|
+
if (value.BOOL !== undefined) return value.BOOL;
|
|
567
|
+
if (value.NULL !== undefined) return null;
|
|
568
|
+
if (value.L !== undefined) return value.L.map((v) => this.normalizeValue(v, table));
|
|
569
|
+
if (value.M !== undefined) return this.normalizeItem(value.M, table);
|
|
570
|
+
if (value.SS !== undefined) return value.SS;
|
|
571
|
+
if (value.NS !== undefined) return value.NS.map(Number);
|
|
572
|
+
|
|
573
|
+
// plain object (already normalized, e.g. stored without DynamoDB types)
|
|
574
|
+
return value;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
marshallValue(value, table) {
|
|
578
|
+
if (value === null || value === undefined) return { NULL: true };
|
|
579
|
+
if (typeof value === 'boolean') return { BOOL: value };
|
|
580
|
+
if (typeof value === 'number') return { N: String(value) };
|
|
581
|
+
if (typeof value === 'string') return { S: value };
|
|
582
|
+
if (Array.isArray(value)) return { L: value.map((v) => this.marshallValue(v, table)) };
|
|
583
|
+
if (typeof value === 'object') return { M: this.marshallItem(value, table) };
|
|
584
|
+
return { S: String(value) };
|
|
585
|
+
}
|
|
586
|
+
|
|
567
587
|
marshallItem(item, table) {
|
|
568
588
|
const marshalled = {};
|
|
569
589
|
|
|
570
590
|
for (const [key, value] of Object.entries(item)) {
|
|
571
591
|
if (key.startsWith("_")) continue; // Pula campos internos
|
|
572
592
|
|
|
573
|
-
const type = table.attributeTypes[key];
|
|
593
|
+
const type = table ? table.attributeTypes[key] : null;
|
|
574
594
|
if (type === "S") {
|
|
575
595
|
marshalled[key] = { S: String(value) };
|
|
576
596
|
} else if (type === "N") {
|
|
577
597
|
marshalled[key] = { N: String(value) };
|
|
578
|
-
} else if (type === "BOOL") {
|
|
579
|
-
marshalled[key] = { BOOL: Boolean(value) };
|
|
580
|
-
} else if (Array.isArray(value)) {
|
|
581
|
-
marshalled[key] = { L: value.map((v) => ({ S: String(v) })) };
|
|
582
|
-
} else if (typeof value === "object") {
|
|
583
|
-
marshalled[key] = { M: this.marshallItem(value, table) };
|
|
584
598
|
} else {
|
|
585
|
-
marshalled[key] =
|
|
599
|
+
marshalled[key] = this.marshallValue(value, table);
|
|
586
600
|
}
|
|
587
601
|
}
|
|
588
602
|
|