@bifravst/http-api-mock 2.1.353 → 2.1.355

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.
Files changed (69) hide show
  1. package/npm/mock.js +27 -0
  2. package/npm/parseMockRequest.js +17 -0
  3. package/{dist/src → npm}/parseMockResponse.js +8 -10
  4. package/npm/randomString.js +2 -0
  5. package/{dist/src → npm}/requests.d.ts +1 -1
  6. package/npm/requests.js +11 -0
  7. package/{dist/src → npm}/responses.js +6 -6
  8. package/{dist/src → npm}/sortQueryString.d.ts +1 -1
  9. package/{dist/src → npm}/sortQueryString.js +11 -10
  10. package/package.json +23 -27
  11. package/cdk/App.ts +0 -26
  12. package/cdk/Stack.ts +0 -66
  13. package/cdk/http-api-mock.ts +0 -41
  14. package/cdk/resources/HttpApiMock.ts +0 -119
  15. package/cdk/resources/checkMatchingQueryParams.spec.ts +0 -67
  16. package/cdk/resources/checkMatchingQueryParams.ts +0 -40
  17. package/cdk/resources/http-api-mock-lambda.ts +0 -147
  18. package/cdk/resources/splitMockResponse.spec.ts +0 -17
  19. package/cdk/resources/splitMockResponse.ts +0 -25
  20. package/cli.js +0 -5
  21. package/dist/cdk/App.d.ts +0 -11
  22. package/dist/cdk/App.js +0 -12
  23. package/dist/cdk/Stack.d.ts +0 -20
  24. package/dist/cdk/Stack.js +0 -40
  25. package/dist/cdk/http-api-mock.d.ts +0 -1
  26. package/dist/cdk/http-api-mock.js +0 -35
  27. package/dist/cdk/resources/HttpApiMock.d.ts +0 -14
  28. package/dist/cdk/resources/HttpApiMock.js +0 -87
  29. package/dist/cdk/resources/checkMatchingQueryParams.d.ts +0 -5
  30. package/dist/cdk/resources/checkMatchingQueryParams.js +0 -33
  31. package/dist/cdk/resources/checkMatchingQueryParams.spec.d.ts +0 -1
  32. package/dist/cdk/resources/checkMatchingQueryParams.spec.js +0 -57
  33. package/dist/cdk/resources/http-api-mock-lambda.d.ts +0 -2
  34. package/dist/cdk/resources/http-api-mock-lambda.js +0 -98
  35. package/dist/cdk/resources/splitMockResponse.d.ts +0 -4
  36. package/dist/cdk/resources/splitMockResponse.js +0 -20
  37. package/dist/cdk/resources/splitMockResponse.spec.d.ts +0 -1
  38. package/dist/cdk/resources/splitMockResponse.spec.js +0 -13
  39. package/dist/src/cli.d.ts +0 -1
  40. package/dist/src/cli.js +0 -88
  41. package/dist/src/mock.js +0 -31
  42. package/dist/src/mock.spec.js +0 -36
  43. package/dist/src/parseMockRequest.js +0 -19
  44. package/dist/src/parseMockRequest.spec.js +0 -23
  45. package/dist/src/parseMockResponse.spec.js +0 -20
  46. package/dist/src/randomString.js +0 -5
  47. package/dist/src/requests.js +0 -11
  48. package/dist/src/sortQueryString.spec.js +0 -18
  49. package/src/cli.ts +0 -109
  50. package/src/mock.spec.ts +0 -52
  51. package/src/mock.ts +0 -61
  52. package/src/parseMockRequest.spec.ts +0 -30
  53. package/src/parseMockRequest.ts +0 -35
  54. package/src/parseMockResponse.spec.ts +0 -27
  55. package/src/parseMockResponse.ts +0 -35
  56. package/src/randomString.ts +0 -7
  57. package/src/requests.ts +0 -28
  58. package/src/responses.ts +0 -50
  59. package/src/sortQueryString.spec.ts +0 -38
  60. package/src/sortQueryString.ts +0 -26
  61. /package/{dist/src → npm}/mock.d.ts +0 -0
  62. /package/{dist/src → npm}/mock.spec.d.ts +0 -0
  63. /package/{dist/src → npm}/parseMockRequest.d.ts +0 -0
  64. /package/{dist/src → npm}/parseMockRequest.spec.d.ts +0 -0
  65. /package/{dist/src → npm}/parseMockResponse.d.ts +0 -0
  66. /package/{dist/src → npm}/parseMockResponse.spec.d.ts +0 -0
  67. /package/{dist/src → npm}/randomString.d.ts +0 -0
  68. /package/{dist/src → npm}/responses.d.ts +0 -0
  69. /package/{dist/src → npm}/sortQueryString.spec.d.ts +0 -0
package/src/responses.ts DELETED
@@ -1,50 +0,0 @@
1
- import { PutItemCommand, type DynamoDBClient } from '@aws-sdk/client-dynamodb'
2
- import { marshall } from '@aws-sdk/util-dynamodb'
3
- import { randomUUID } from 'node:crypto'
4
- import { sortQuery } from './sortQueryString.js'
5
-
6
- export type Response = {
7
- // e.g. 'GET'
8
- method: string
9
- // without leading slash
10
- path: string
11
- queryParams?: URLSearchParams
12
- statusCode?: number
13
- /**
14
- * Header + Body
15
- *
16
- * @see splitMockResponse
17
- */
18
- body?: string
19
- ttl?: number
20
- // Whether to delete the message after sending it
21
- keep?: boolean
22
- }
23
-
24
- export const registerResponse = async (
25
- db: DynamoDBClient,
26
- responsesTable: string,
27
- response: Response,
28
- ): Promise<void> => {
29
- await db.send(
30
- new PutItemCommand({
31
- TableName: responsesTable,
32
- Item: marshall(
33
- {
34
- responseId: randomUUID(),
35
- methodPathQuery: `${response.method} ${response.path}${response.queryParams !== undefined ? `?${sortQuery(response.queryParams)}` : ``}`,
36
- timestamp: new Date().toISOString(),
37
- statusCode: response.statusCode,
38
- body: response.body,
39
- queryParams:
40
- response.queryParams !== undefined
41
- ? Object.fromEntries(response.queryParams)
42
- : undefined,
43
- ttl: response.ttl,
44
- keep: response.keep,
45
- },
46
- { removeUndefinedValues: true },
47
- ),
48
- }),
49
- )
50
- }
@@ -1,38 +0,0 @@
1
- import assert from 'node:assert'
2
- import { describe, test as it } from 'node:test'
3
- import { URLSearchParams } from 'node:url'
4
- import { sortQuery, sortQueryString } from './sortQueryString.js'
5
-
6
- void describe('sortQueryString', () => {
7
- void it('should sort the query part of a mock URL', () =>
8
- assert.deepStrictEqual(
9
- sortQueryString(
10
- 'api.nrfcloud.com/v1/location/agps?eci=73393515&tac=132&requestType=custom&mcc=397&mnc=73&customTypes=2',
11
- ),
12
- 'api.nrfcloud.com/v1/location/agps?customTypes=2&eci=73393515&mcc=397&mnc=73&requestType=custom&tac=132',
13
- ))
14
- })
15
-
16
- void describe('sortQuery', () => {
17
- void it('should sort URLSearchParams', () =>
18
- assert.equal(
19
- sortQuery(
20
- new URLSearchParams(
21
- 'eci=73393515&tac=132&requestType=custom&mcc=397&mnc=73&customTypes=2',
22
- ),
23
- ),
24
- 'customTypes=2&eci=73393515&mcc=397&mnc=73&requestType=custom&tac=132',
25
- ))
26
- void it('should sort a Record', () =>
27
- assert.equal(
28
- sortQuery({
29
- eci: '73393515',
30
- tac: '132',
31
- requestType: 'custom',
32
- mcc: '397',
33
- mnc: '73',
34
- customTypes: '2',
35
- }),
36
- 'customTypes=2&eci=73393515&mcc=397&mnc=73&requestType=custom&tac=132',
37
- ))
38
- })
@@ -1,26 +0,0 @@
1
- import { URLSearchParams } from 'node:url'
2
-
3
- export const sortQueryString = (mockUrl: string): string => {
4
- const [host, query] = mockUrl.split('?', 2) as [string, string | undefined]
5
- if (query === undefined || (query?.length ?? 0) === 0) return host
6
- return `${host}?${sortQuery(new URLSearchParams(query))}`
7
- }
8
-
9
- export const sortQuery = (
10
- query: URLSearchParams | Record<string, string>,
11
- ): string => {
12
- const params: string[][] = []
13
- if (query instanceof URLSearchParams) {
14
- query.forEach((v, k) => {
15
- params.push([k, v])
16
- })
17
- } else {
18
- params.push(...Object.entries(query))
19
- }
20
- params.sort(([k1], [k2]) => (k1 ?? '').localeCompare(k2 ?? ''))
21
- const sortedParams = new URLSearchParams()
22
- for (const [k, v] of params) {
23
- sortedParams.append(k as string, v as string)
24
- }
25
- return sortedParams.toString()
26
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes