@bifravst/http-api-mock 1.2.4 → 1.3.1

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.
@@ -3,7 +3,7 @@ type MockResponseFn = (methodPathQuery: string, response: Partial<{
3
3
  headers: Headers;
4
4
  status: number;
5
5
  body: string;
6
- }>) => Promise<void>;
6
+ }>, keep?: boolean) => Promise<void>;
7
7
  export declare const mockResponse: (db: DynamoDBClient, responsesTable: string) => MockResponseFn;
8
8
  export type HttpAPIMock = {
9
9
  response: MockResponseFn;
package/dist/src/mock.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { registerResponse } from './responses.js';
2
- export const mockResponse = (db, responsesTable) => async (methodPathQuery, response) => {
2
+ export const mockResponse = (db, responsesTable) => async (methodPathQuery, response, keep) => {
3
3
  const [method, pathWithQuery] = methodPathQuery.split(' ', 2);
4
4
  if (!/^[A-Z]+$/.test(method ?? ''))
5
5
  throw new Error(`Invalid method ${method} in ${methodPathQuery}!`);
@@ -23,6 +23,7 @@ export const mockResponse = (db, responsesTable) => async (methodPathQuery, resp
23
23
  queryParams: new URLSearchParams(query),
24
24
  body: bodyParts.length > 0 ? bodyParts.join('\n') : undefined,
25
25
  statusCode: response.status,
26
+ keep,
26
27
  });
27
28
  };
28
29
  export const mock = ({ db, responsesTable, }) => ({
@@ -14,7 +14,7 @@ export const registerResponse = async (db, responsesTable, response) => {
14
14
  ? URLSearchParamsToObject(response.queryParams)
15
15
  : undefined,
16
16
  ttl: response.ttl,
17
- keep: response.ttl,
17
+ keep: response.keep,
18
18
  }, { removeUndefinedValues: true }),
19
19
  }));
20
20
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bifravst/http-api-mock",
3
- "version": "1.2.4",
3
+ "version": "1.3.1",
4
4
  "description": "Helper functions for AWS lambdas written in TypeScript.",
5
5
  "exports": {
6
6
  "./*": {
@@ -83,10 +83,10 @@
83
83
  ],
84
84
  "prettier": "@bifravst/prettier-config",
85
85
  "dependencies": {
86
- "@aws-sdk/client-cloudformation": "^3.555.0",
87
- "@aws-sdk/client-dynamodb": "^3.554.0",
88
- "@aws-sdk/client-sts": "^3.554.0",
89
- "@aws-sdk/util-dynamodb": "^3.554.0",
86
+ "@aws-sdk/client-cloudformation": "^3.556.0",
87
+ "@aws-sdk/client-dynamodb": "^3.556.0",
88
+ "@aws-sdk/client-sts": "^3.556.0",
89
+ "@aws-sdk/util-dynamodb": "^3.556.0",
90
90
  "@bifravst/aws-cdk-lambda-helpers": "^1.4.1",
91
91
  "@bifravst/run": "^1.2.0",
92
92
  "@nordicsemiconductor/cloudformation-helpers": "^9.0.3",
@@ -97,7 +97,7 @@
97
97
  "tsx": "^4.7.2"
98
98
  },
99
99
  "devDependencies": {
100
- "@bifravst/eslint-config-typescript": "6.0.22",
100
+ "@bifravst/eslint-config-typescript": "6.0.23",
101
101
  "@bifravst/prettier-config": "1.0.0",
102
102
  "@commitlint/config-conventional": "19.2.2",
103
103
  "@types/aws-lambda": "8.10.137",
package/src/mock.ts CHANGED
@@ -10,11 +10,12 @@ type MockResponseFn = (
10
10
  status: number
11
11
  body: string
12
12
  }>,
13
+ keep?: boolean,
13
14
  ) => Promise<void>
14
15
 
15
16
  export const mockResponse =
16
17
  (db: DynamoDBClient, responsesTable: string): MockResponseFn =>
17
- async (methodPathQuery, response) => {
18
+ async (methodPathQuery, response, keep) => {
18
19
  const [method, pathWithQuery] = methodPathQuery.split(' ', 2)
19
20
  if (!/^[A-Z]+$/.test(method ?? ''))
20
21
  throw new Error(`Invalid method ${method} in ${methodPathQuery}!`)
@@ -41,6 +42,7 @@ export const mockResponse =
41
42
  queryParams: new URLSearchParams(query),
42
43
  body: bodyParts.length > 0 ? bodyParts.join('\n') : undefined,
43
44
  statusCode: response.status,
45
+ keep,
44
46
  })
45
47
  }
46
48
 
package/src/responses.ts CHANGED
@@ -40,7 +40,7 @@ export const registerResponse = async (
40
40
  ? URLSearchParamsToObject(response.queryParams)
41
41
  : undefined,
42
42
  ttl: response.ttl,
43
- keep: response.ttl,
43
+ keep: response.keep,
44
44
  },
45
45
  { removeUndefinedValues: true },
46
46
  ),