@bifravst/http-api-mock 1.4.95 → 2.0.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.
@@ -14,7 +14,6 @@ import { URLSearchParams } from 'url'
14
14
  import { checkMatchingQueryParams } from './checkMatchingQueryParams.js'
15
15
  import { splitMockResponse } from './splitMockResponse.js'
16
16
  import { sortQueryString } from '../../src/sortQueryString.js'
17
- import { URLSearchParamsToObject } from '../../src/URLSearchParamsToObject.js'
18
17
 
19
18
  const db = new DynamoDBClient({})
20
19
 
@@ -44,7 +43,7 @@ export const handler = async (
44
43
  requestId: context.awsRequestId,
45
44
  method: event.httpMethod,
46
45
  path,
47
- query: query === undefined ? null : URLSearchParamsToObject(query),
46
+ query: query === undefined ? null : Object.fromEntries(query),
48
47
  body: event.body ?? '{}',
49
48
  headers: JSON.stringify(event.headers),
50
49
  ttl: Math.round(Date.now() / 1000) + 5 * 60,
@@ -4,7 +4,6 @@ import { URLSearchParams } from 'url';
4
4
  import { checkMatchingQueryParams } from './checkMatchingQueryParams.js';
5
5
  import { splitMockResponse } from './splitMockResponse.js';
6
6
  import { sortQueryString } from '../../src/sortQueryString.js';
7
- import { URLSearchParamsToObject } from '../../src/URLSearchParamsToObject.js';
8
7
  const db = new DynamoDBClient({});
9
8
  export const handler = async (event, context) => {
10
9
  console.log(JSON.stringify({ event }));
@@ -22,7 +21,7 @@ export const handler = async (event, context) => {
22
21
  requestId: context.awsRequestId,
23
22
  method: event.httpMethod,
24
23
  path,
25
- query: query === undefined ? null : URLSearchParamsToObject(query),
24
+ query: query === undefined ? null : Object.fromEntries(query),
26
25
  body: event.body ?? '{}',
27
26
  headers: JSON.stringify(event.headers),
28
27
  ttl: Math.round(Date.now() / 1000) + 5 * 60,
@@ -1,7 +1,6 @@
1
1
  import { PutItemCommand } from '@aws-sdk/client-dynamodb';
2
2
  import { marshall } from '@aws-sdk/util-dynamodb';
3
3
  import { sortQuery } from './sortQueryString.js';
4
- import { URLSearchParamsToObject } from './URLSearchParamsToObject.js';
5
4
  export const registerResponse = async (db, responsesTable, response) => {
6
5
  await db.send(new PutItemCommand({
7
6
  TableName: responsesTable,
@@ -11,7 +10,7 @@ export const registerResponse = async (db, responsesTable, response) => {
11
10
  statusCode: response.statusCode,
12
11
  body: response.body,
13
12
  queryParams: response.queryParams !== undefined
14
- ? URLSearchParamsToObject(response.queryParams)
13
+ ? Object.fromEntries(response.queryParams)
15
14
  : undefined,
16
15
  ttl: response.ttl,
17
16
  keep: response.keep,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bifravst/http-api-mock",
3
- "version": "1.4.95",
3
+ "version": "2.0.1",
4
4
  "description": "Helper functions for AWS lambdas written in TypeScript.",
5
5
  "exports": {
6
6
  "./*": {
@@ -83,7 +83,7 @@
83
83
  "@aws-sdk/client-dynamodb": "^3.596.0",
84
84
  "@aws-sdk/client-sts": "^3.596.0",
85
85
  "@aws-sdk/util-dynamodb": "^3.596.0",
86
- "@bifravst/aws-cdk-lambda-helpers": "^1.8.2",
86
+ "@bifravst/aws-cdk-lambda-helpers": "^1.8.3",
87
87
  "@bifravst/run": "^1.2.0",
88
88
  "@nordicsemiconductor/cloudformation-helpers": "^9.1.0",
89
89
  "@nordicsemiconductor/from-env": "^3.0.1",
package/src/responses.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { PutItemCommand, type DynamoDBClient } from '@aws-sdk/client-dynamodb'
2
2
  import { marshall } from '@aws-sdk/util-dynamodb'
3
3
  import { sortQuery } from './sortQueryString.js'
4
- import { URLSearchParamsToObject } from './URLSearchParamsToObject.js'
5
4
 
6
5
  export type Response = {
7
6
  // e.g. 'GET'
@@ -37,7 +36,7 @@ export const registerResponse = async (
37
36
  body: response.body,
38
37
  queryParams:
39
38
  response.queryParams !== undefined
40
- ? URLSearchParamsToObject(response.queryParams)
39
+ ? Object.fromEntries(response.queryParams)
41
40
  : undefined,
42
41
  ttl: response.ttl,
43
42
  keep: response.keep,
@@ -1 +0,0 @@
1
- export declare const URLSearchParamsToObject: (params: URLSearchParams) => Record<string, string>;
@@ -1,7 +0,0 @@
1
- export const URLSearchParamsToObject = (params) => {
2
- const result = {};
3
- for (const [key, value] of params.entries()) {
4
- result[key] = value;
5
- }
6
- return result;
7
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,13 +0,0 @@
1
- import { describe, it } from 'node:test';
2
- import assert from 'node:assert/strict';
3
- import { URLSearchParamsToObject } from './URLSearchParamsToObject.js';
4
- void describe('URLSearchParamsToObject()', () => {
5
- void it('should convert URLSearchParams to a plain object', () => assert.deepEqual(URLSearchParamsToObject(new URLSearchParams('eci=73393515&tac=132&requestType=custom&mcc=397&mnc=73&customTypes=2')), {
6
- eci: '73393515',
7
- tac: '132',
8
- requestType: 'custom',
9
- mcc: '397',
10
- mnc: '73',
11
- customTypes: '2',
12
- }));
13
- });
@@ -1,22 +0,0 @@
1
- import { describe, it } from 'node:test'
2
- import assert from 'node:assert/strict'
3
- import { URLSearchParamsToObject } from './URLSearchParamsToObject.js'
4
-
5
- void describe('URLSearchParamsToObject()', () => {
6
- void it('should convert URLSearchParams to a plain object', () =>
7
- assert.deepEqual(
8
- URLSearchParamsToObject(
9
- new URLSearchParams(
10
- 'eci=73393515&tac=132&requestType=custom&mcc=397&mnc=73&customTypes=2',
11
- ),
12
- ),
13
- {
14
- eci: '73393515',
15
- tac: '132',
16
- requestType: 'custom',
17
- mcc: '397',
18
- mnc: '73',
19
- customTypes: '2',
20
- },
21
- ))
22
- })
@@ -1,9 +0,0 @@
1
- export const URLSearchParamsToObject = (
2
- params: URLSearchParams,
3
- ): Record<string, string> => {
4
- const result: Record<string, string> = {}
5
- for (const [key, value] of params.entries()) {
6
- result[key] = value
7
- }
8
- return result
9
- }