http-snapshotter 0.6.0-beta.2 → 0.6.1-beta.2
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/index.js +14 -4
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -96,7 +96,7 @@ let snapshotDirectory = null;
|
|
|
96
96
|
* @typedef {import('diff').Change} DiffChange
|
|
97
97
|
*/
|
|
98
98
|
|
|
99
|
-
const dynamodbHostNameRegex = /^(?:dynamodb
|
|
99
|
+
const dynamodbHostNameRegex = /^(?:\d+\.)?(?:dynamodb|ddb)\.([^.]+)\.amazonaws\.com$/;
|
|
100
100
|
|
|
101
101
|
/**
|
|
102
102
|
* Stable JSON stringify with sorted keys for deterministic hashing
|
|
@@ -119,11 +119,18 @@ async function defaultSnapshotFileNameGenerator(request) {
|
|
|
119
119
|
let filePrefix;
|
|
120
120
|
|
|
121
121
|
const url = new URL(request.url);
|
|
122
|
-
const
|
|
123
|
-
|
|
122
|
+
const dynamodbRegion = url.hostname.match(dynamodbHostNameRegex)?.[1] || '';
|
|
123
|
+
const normalizedRequestUrl = (() => {
|
|
124
|
+
if (!dynamodbRegion) return request.url;
|
|
125
|
+
const normalizedUrl = new URL(request.url);
|
|
126
|
+
normalizedUrl.hostname = `dynamodb.${dynamodbRegion}.amazonaws.com`;
|
|
127
|
+
return normalizedUrl.toString();
|
|
128
|
+
})();
|
|
129
|
+
|
|
130
|
+
if (dynamodbRegion) {
|
|
124
131
|
filePrefix = [
|
|
125
132
|
'dynamodb',
|
|
126
|
-
|
|
133
|
+
dynamodbRegion, // e.g. eu-west-1
|
|
127
134
|
slugify(request.headers?.get?.('x-amz-target')?.split?.('.')?.pop?.() || ''), // e.g. get-item, put-item
|
|
128
135
|
slugify(JSON.parse(await request.clone().text())?.TableName),
|
|
129
136
|
].filter(Boolean).join('-');
|
|
@@ -149,6 +156,9 @@ async function defaultSnapshotFileNameGenerator(request) {
|
|
|
149
156
|
}
|
|
150
157
|
return request.clone().text();
|
|
151
158
|
}
|
|
159
|
+
if (key === 'url') {
|
|
160
|
+
return normalizedRequestUrl;
|
|
161
|
+
}
|
|
152
162
|
//@ts-ignore
|
|
153
163
|
return request[key];
|
|
154
164
|
}),
|