@bifravst/http-api-mock 1.2.1 → 1.2.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.
@@ -2,7 +2,7 @@ import {
2
2
  DeleteItemCommand,
3
3
  DynamoDBClient,
4
4
  PutItemCommand,
5
- QueryCommand,
5
+ ScanCommand,
6
6
  } from '@aws-sdk/client-dynamodb'
7
7
  import { marshall, unmarshall } from '@aws-sdk/util-dynamodb'
8
8
  import type {
@@ -56,17 +56,16 @@ export const handler = async (
56
56
  console.debug(
57
57
  `Checking if response exists for ${event.httpMethod} ${pathWithQuery}...`,
58
58
  )
59
- // Query using httpMethod and path only
59
+ // Scan using httpMethod and path only so query strings can be partially matched
60
60
  const { Items } = await db.send(
61
- new QueryCommand({
61
+ new ScanCommand({
62
62
  TableName: process.env.RESPONSES_TABLE_NAME,
63
- KeyConditionExpression: 'methodPathQuery = :methodPathQuery',
63
+ FilterExpression: 'begins_with(methodPathQuery, :methodPath)',
64
64
  ExpressionAttributeValues: {
65
- [':methodPathQuery']: {
66
- S: `${event.httpMethod} ${pathWithQuery}`,
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}`)
@@ -1,4 +1,4 @@
1
- import { DeleteItemCommand, DynamoDBClient, PutItemCommand, QueryCommand, } from '@aws-sdk/client-dynamodb';
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,16 +30,15 @@ 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
- // Query using httpMethod and path only
34
- const { Items } = await db.send(new QueryCommand({
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
- KeyConditionExpression: 'methodPathQuery = :methodPathQuery',
36
+ FilterExpression: 'begins_with(methodPathQuery, :methodPath)',
37
37
  ExpressionAttributeValues: {
38
- [':methodPathQuery']: {
39
- S: `${event.httpMethod} ${pathWithQuery}`,
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bifravst/http-api-mock",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "Helper functions for AWS lambdas written in TypeScript.",
5
5
  "exports": {
6
6
  "./*": {