@bifravst/http-api-mock 1.2.1 → 1.2.3
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.
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
DeleteItemCommand,
|
|
3
3
|
DynamoDBClient,
|
|
4
4
|
PutItemCommand,
|
|
5
|
-
|
|
5
|
+
ScanCommand,
|
|
6
6
|
} from '@aws-sdk/client-dynamodb'
|
|
7
7
|
import { marshall, unmarshall } from '@aws-sdk/util-dynamodb'
|
|
8
8
|
import type {
|
|
@@ -56,23 +56,23 @@ export const handler = async (
|
|
|
56
56
|
console.debug(
|
|
57
57
|
`Checking if response exists for ${event.httpMethod} ${pathWithQuery}...`,
|
|
58
58
|
)
|
|
59
|
-
//
|
|
59
|
+
// Scan using httpMethod and path only so query strings can be partially matched
|
|
60
60
|
const { Items } = await db.send(
|
|
61
|
-
new
|
|
61
|
+
new ScanCommand({
|
|
62
62
|
TableName: process.env.RESPONSES_TABLE_NAME,
|
|
63
|
-
|
|
63
|
+
FilterExpression: 'begins_with(methodPathQuery, :methodPath)',
|
|
64
64
|
ExpressionAttributeValues: {
|
|
65
|
-
[':
|
|
66
|
-
S: `${event.httpMethod} ${
|
|
65
|
+
[':methodPath']: {
|
|
66
|
+
S: `${event.httpMethod} ${path}`,
|
|
67
67
|
},
|
|
68
68
|
},
|
|
69
|
-
ScanIndexForward: false,
|
|
70
69
|
}),
|
|
71
70
|
)
|
|
72
71
|
console.debug(`Found response items: ${Items?.length}`)
|
|
73
72
|
|
|
74
73
|
let res: APIGatewayProxyResult | undefined
|
|
75
|
-
for (const Item of Items ?? []) {
|
|
74
|
+
for (const Item of (Items ?? []).reverse()) {
|
|
75
|
+
// use newest response first
|
|
76
76
|
const objItem = unmarshall(Item)
|
|
77
77
|
const hasExpectedQueryParams = 'queryParams' in objItem
|
|
78
78
|
const matchedQueryParams = hasExpectedQueryParams
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DeleteItemCommand, DynamoDBClient, PutItemCommand,
|
|
1
|
+
import { DeleteItemCommand, DynamoDBClient, PutItemCommand, ScanCommand, } from '@aws-sdk/client-dynamodb';
|
|
2
2
|
import { marshall, unmarshall } from '@aws-sdk/util-dynamodb';
|
|
3
3
|
import { URLSearchParams } from 'url';
|
|
4
4
|
import { checkMatchingQueryParams } from './checkMatchingQueryParams.js';
|
|
@@ -30,20 +30,20 @@ export const handler = async (event, context) => {
|
|
|
30
30
|
}));
|
|
31
31
|
// Check if response exists
|
|
32
32
|
console.debug(`Checking if response exists for ${event.httpMethod} ${pathWithQuery}...`);
|
|
33
|
-
//
|
|
34
|
-
const { Items } = await db.send(new
|
|
33
|
+
// Scan using httpMethod and path only so query strings can be partially matched
|
|
34
|
+
const { Items } = await db.send(new ScanCommand({
|
|
35
35
|
TableName: process.env.RESPONSES_TABLE_NAME,
|
|
36
|
-
|
|
36
|
+
FilterExpression: 'begins_with(methodPathQuery, :methodPath)',
|
|
37
37
|
ExpressionAttributeValues: {
|
|
38
|
-
[':
|
|
39
|
-
S: `${event.httpMethod} ${
|
|
38
|
+
[':methodPath']: {
|
|
39
|
+
S: `${event.httpMethod} ${path}`,
|
|
40
40
|
},
|
|
41
41
|
},
|
|
42
|
-
ScanIndexForward: false,
|
|
43
42
|
}));
|
|
44
43
|
console.debug(`Found response items: ${Items?.length}`);
|
|
45
44
|
let res;
|
|
46
|
-
for (const Item of Items ?? []) {
|
|
45
|
+
for (const Item of (Items ?? []).reverse()) {
|
|
46
|
+
// use newest response first
|
|
47
47
|
const objItem = unmarshall(Item);
|
|
48
48
|
const hasExpectedQueryParams = 'queryParams' in objItem;
|
|
49
49
|
const matchedQueryParams = hasExpectedQueryParams
|