@autometa/http 1.4.20 → 2.0.0-rc.0

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 (55) hide show
  1. package/README.md +107 -2
  2. package/dist/assertions/http-adapters.d.ts +35 -0
  3. package/dist/assertions/http-assertions-plugin.d.ts +16 -0
  4. package/dist/assertions/http-ensure.d.ts +42 -0
  5. package/dist/axios-transport.d.ts +22 -0
  6. package/dist/default-schema.d.ts +8 -0
  7. package/dist/fetch-transport.d.ts +21 -0
  8. package/dist/http-request.d.ts +109 -0
  9. package/dist/http-response.d.ts +77 -0
  10. package/dist/http.d.ts +300 -0
  11. package/dist/index.cjs +2076 -0
  12. package/dist/index.cjs.map +1 -0
  13. package/dist/index.d.ts +15 -1116
  14. package/dist/index.js +1727 -845
  15. package/dist/index.js.map +1 -1
  16. package/dist/plugins.d.ts +43 -0
  17. package/dist/request-meta.config.d.ts +56 -0
  18. package/dist/schema.map.d.ts +11 -0
  19. package/dist/transform-response.d.ts +1 -0
  20. package/dist/transport.d.ts +11 -0
  21. package/dist/types.d.ts +39 -0
  22. package/package.json +31 -31
  23. package/.eslintignore +0 -3
  24. package/.eslintrc.cjs +0 -4
  25. package/.turbo/turbo-lint$colon$fix.log +0 -4
  26. package/.turbo/turbo-prettify.log +0 -5
  27. package/.turbo/turbo-test.log +0 -120
  28. package/CHANGELOG.md +0 -335
  29. package/dist/esm/index.js +0 -1117
  30. package/dist/esm/index.js.map +0 -1
  31. package/dist/index.d.cts +0 -1116
  32. package/src/axios-client.ts +0 -35
  33. package/src/default-client-factory.axios.spec.ts +0 -9
  34. package/src/default-client-factory.other.spec.ts +0 -13
  35. package/src/default-client-factory.ts +0 -7
  36. package/src/default-schema.spec.ts +0 -74
  37. package/src/default-schema.ts +0 -127
  38. package/src/http-client.ts +0 -20
  39. package/src/http-request.spec.ts +0 -172
  40. package/src/http-request.ts +0 -201
  41. package/src/http-response.ts +0 -107
  42. package/src/http.spec.ts +0 -189
  43. package/src/http.ts +0 -907
  44. package/src/index.ts +0 -13
  45. package/src/node_modules/.vitest/deps/_metadata.json +0 -8
  46. package/src/node_modules/.vitest/deps/package.json +0 -3
  47. package/src/node_modules/.vitest/results.json +0 -1
  48. package/src/request-meta.config.spec.ts +0 -81
  49. package/src/request-meta.config.ts +0 -134
  50. package/src/request.config.ts +0 -34
  51. package/src/schema.map.spec.ts +0 -50
  52. package/src/schema.map.ts +0 -68
  53. package/src/transform-response.ts +0 -43
  54. package/src/types.ts +0 -37
  55. package/tsup.config.ts +0 -14
@@ -0,0 +1,39 @@
1
+ import type { HTTPRequest } from "./http-request";
2
+ import type { HTTPResponse } from "./http-response";
3
+ type Enumerate<N extends number, Acc extends number[] = []> = Acc["length"] extends N ? Acc[number] : Enumerate<N, [...Acc, Acc["length"]]>;
4
+ type IntRange<From extends number, To extends number> = Exclude<Enumerate<To>, Enumerate<From>> | From;
5
+ export type HTTPMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS" | "TRACE" | "CONNECT";
6
+ export type HTTPAdditionalOptions<T = Record<string, unknown>> = Partial<T> & Record<string, unknown>;
7
+ export type SchemaParser = {
8
+ parse: (data: unknown) => unknown;
9
+ } | {
10
+ validate: (data: unknown) => unknown;
11
+ } | ((data: unknown) => unknown);
12
+ export type StatusCode = IntRange<100, 600>;
13
+ export type RequestHook = <T = unknown>(state: HTTPRequest<T>) => unknown;
14
+ export type ResponseHook<T> = (state: HTTPResponse<T>) => unknown;
15
+ export interface HTTPRetryContext {
16
+ error: unknown;
17
+ attempt: number;
18
+ request: HTTPRequest<unknown>;
19
+ response?: HTTPResponse<unknown>;
20
+ }
21
+ export type HTTPRetryPredicate = (context: HTTPRetryContext) => boolean | Promise<boolean>;
22
+ export interface HTTPRetryOptions {
23
+ attempts: number;
24
+ delay?: number | ((attempt: number) => number | Promise<number>);
25
+ retryOn?: HTTPRetryPredicate;
26
+ }
27
+ export type QueryParamPrimitive = string | number | boolean | null | undefined;
28
+ export type QueryParamValue = QueryParamPrimitive | QueryParamValue[] | {
29
+ [key: string]: QueryParamValue;
30
+ };
31
+ export type QueryParamSerializer = (params: Record<string, QueryParamValue>) => string;
32
+ export type QueryParamArrayFormat = "repeat" | "brackets" | "indices" | "comma" | "json";
33
+ export type QueryParamObjectFormat = "brackets" | "dot" | "json";
34
+ export interface QueryParamSerializationOptions {
35
+ arrayFormat?: QueryParamArrayFormat;
36
+ objectFormat?: QueryParamObjectFormat;
37
+ serializer?: QueryParamSerializer | null;
38
+ }
39
+ export {};
package/package.json CHANGED
@@ -1,57 +1,57 @@
1
1
  {
2
2
  "name": "@autometa/http",
3
- "version": "1.4.20",
4
- "description": "An Axios Based HTTP Client for Autometa",
3
+ "version": "2.0.0-rc.0",
4
+ "description": "",
5
5
  "type": "module",
6
- "main": "dist/index.js",
7
- "module": "dist/esm/index.js",
6
+ "main": "dist/index.cjs",
7
+ "module": "dist/index.js",
8
8
  "types": "dist/index.d.ts",
9
+ "files": [
10
+ "dist"
11
+ ],
9
12
  "exports": {
10
- "import": "./dist/esm/index.js",
11
- "require": "./dist/index.js",
12
- "default": "./dist/esm/index.js",
13
+ "import": "./dist/index.js",
14
+ "require": "./dist/index.cjs",
15
+ "default": "./dist/index.js",
13
16
  "types": "./dist/index.d.ts"
14
17
  },
15
18
  "license": "MIT",
19
+ "dependencies": {
20
+ "cli-highlight": "^2.1.11",
21
+ "url-join-ts": "^1.0.5",
22
+ "@autometa/assertions": "1.0.0-rc.0",
23
+ "@autometa/errors": "1.0.0-rc.0",
24
+ "@autometa/status-codes": "1.0.0-rc.0"
25
+ },
16
26
  "devDependencies": {
17
27
  "@types/node": "^18.11.18",
18
- "@types/uuid": "^9.0.1",
19
28
  "@typescript-eslint/eslint-plugin": "^5.54.1",
20
29
  "@typescript-eslint/parser": "^5.54.1",
21
- "@vitest/coverage-v8": "^1.4.0",
22
30
  "eslint": "^8.37.0",
23
31
  "eslint-config-prettier": "^8.3.0",
24
- "myzod": "^1.10.2",
25
32
  "rimraf": "^4.1.2",
26
33
  "tsup": "^7.2.0",
27
34
  "typescript": "^4.9.5",
28
35
  "vitest": "1.4.0",
29
- "@autometa/types": "^0.4.1",
30
36
  "eslint-config-custom": "0.6.0",
31
- "tsconfig": "0.7.0"
32
- },
33
- "dependencies": {
34
- "@stdlib/assert-is-json": "^0.1.1",
35
- "@types/qs": "^6.9.11",
36
- "axios": "^1.5.1",
37
- "class-transformer": "^0.5.1",
38
- "cli-highlight": "^2.1.11",
39
- "reflect-metadata": "^0.1.13",
40
- "ts-retry": "^4.2.3",
41
- "url-join-ts": "^1.0.5",
42
- "@autometa/app": "^0.4.2",
43
- "@autometa/dto-builder": "^0.13.11",
44
- "@autometa/errors": "^0.2.2",
45
- "@autometa/injection": "^0.1.5",
46
- "@autometa/status-codes": "^0.4.1"
37
+ "tsconfig": "0.7.0",
38
+ "tsup-config": "0.1.0"
47
39
  },
48
40
  "scripts": {
41
+ "type-check": "tsc --noEmit -p tsconfig.dev.json",
42
+ "type-check:watch": "tsc --noEmit --watch -p tsconfig.dev.json",
43
+ "build": "tsup && pnpm run build:types",
44
+ "build:types": "rimraf tsconfig.types.tsbuildinfo && tsc --build tsconfig.types.json",
45
+ "build:watch": "tsup --watch",
46
+ "dev": "tsup --watch",
49
47
  "test": "vitest run --passWithNoTests",
50
- "prettify": "prettier --config .prettierrc 'src/**/*.ts' --write",
48
+ "test:watch": "vitest --passWithNoTests",
49
+ "test:ui": "vitest --ui --passWithNoTests",
50
+ "test:integration": "vitest run --config vitest.integration.config.ts --passWithNoTests",
51
+ "coverage": "vitest run --coverage --passWithNoTests",
51
52
  "lint": "eslint . --max-warnings 0",
52
53
  "lint:fix": "eslint . --fix",
53
- "clean": "rimraf dist",
54
- "build": "tsup",
55
- "build:watch": "tsup --watch"
54
+ "prettify": "prettier --config .prettierrc 'src/**/*.ts' --write",
55
+ "clean": "rimraf dist"
56
56
  }
57
57
  }
package/.eslintignore DELETED
@@ -1,3 +0,0 @@
1
- /dist
2
- /out
3
- node_modules
package/.eslintrc.cjs DELETED
@@ -1,4 +0,0 @@
1
- module.exports = {
2
- root: true,
3
- extends: ["custom"],
4
- };
@@ -1,4 +0,0 @@
1
-
2
- > @autometa/http@1.4.15 lint:fix /Users/ben.aherne/Documents/GitHub/autometa/packages/http
3
- > eslint . --fix "--max-warnings=0"
4
-
@@ -1,5 +0,0 @@
1
-
2
- > @autometa/http@1.4.13 prettify /Users/ben.aherne/Documents/GitHub/autometa/packages/http
3
- > prettier --config .prettierrc 'src/**/*.ts' --write
4
-
5
-  ELIFECYCLE  Command failed.
@@ -1,120 +0,0 @@
1
-
2
- > @autometa/http@1.4.17 test /Users/ben.aherne/Documents/GitHub/autometa/packages/http
3
- > vitest run --passWithNoTests
4
-
5
-
6
- RUN v1.4.0 /Users/ben.aherne/Documents/GitHub/autometa/packages/http
7
-
8
- ✓ src/schema.map.spec.ts (5 tests) 3ms
9
- ✓ src/default-client-factory.other.spec.ts (1 test) 2ms
10
- ✓ src/request-meta.config.spec.ts (8 tests) 5ms
11
- ✓ src/http-request.spec.ts (11 tests) 4ms
12
- ✓ src/default-schema.spec.ts (13 tests) 4ms
13
- ✓ src/default-client-factory.axios.spec.ts (1 test) 2ms
14
- stdout | src/http.spec.ts > HTTP > resolving dynamic headers > should resolve dynamic headers
15
- HTTPRequest {
16
- headers: { foo: 'bar' },
17
- params: {},
18
- route: [],
19
- baseUrl: undefined,
20
- method: 'GET',
21
- data: undefined
22
- }
23
-
24
- stdout | src/http.spec.ts > HTTP > allowPlainText > should throw an error when allowPlainText is false
25
- HTTPRequest {
26
- headers: {},
27
- params: {},
28
- route: [],
29
- baseUrl: undefined,
30
- method: 'GET',
31
- data: undefined
32
- }
33
-
34
- stdout | src/http.spec.ts > HTTP > allowPlainText > should return the response when allowPlainText is true
35
- HTTPRequest {
36
- headers: {},
37
- params: {},
38
- route: [],
39
- baseUrl: undefined,
40
- method: 'GET',
41
- data: undefined
42
- }
43
-
44
- stdout | src/http.spec.ts > HTTP > hooks > onSend > should call the hook when the request is sent
45
- HTTPRequest {
46
- headers: {},
47
- params: {},
48
- route: [],
49
- baseUrl: undefined,
50
- method: 'GET',
51
- data: undefined
52
- }
53
-
54
- stdout | src/http.spec.ts > HTTP > hooks > onReceive > should call the hook when the response is received
55
- HTTPRequest {
56
- headers: {},
57
- params: {},
58
- route: [],
59
- baseUrl: undefined,
60
- method: 'GET',
61
- data: undefined
62
- }
63
-
64
- stdout | src/http.spec.ts > HTTP > hooks > onReceive > should propagate errors from the hook
65
- HTTPRequest {
66
- headers: {},
67
- params: {},
68
- route: [],
69
- baseUrl: undefined,
70
- method: 'GET',
71
- data: undefined
72
- }
73
-
74
- stdout | src/http.spec.ts > HTTP > schemas > should throw an error if there is no schema and requireSchema is true
75
- HTTPRequest {
76
- headers: {},
77
- params: {},
78
- route: [],
79
- baseUrl: undefined,
80
- method: 'GET',
81
- data: undefined
82
- }
83
-
84
- stdout | src/http.spec.ts > HTTP > schemas > should throw an error if the response status does not match a schema
85
- HTTPRequest {
86
- headers: {},
87
- params: {},
88
- route: [],
89
- baseUrl: undefined,
90
- method: 'GET',
91
- data: undefined
92
- }
93
-
94
- stdout | src/http.spec.ts > HTTP > schemas > should return the response if the status matches a schema
95
- HTTPRequest {
96
- headers: {},
97
- params: {},
98
- route: [],
99
- baseUrl: undefined,
100
- method: 'GET',
101
- data: undefined
102
- }
103
-
104
- stdout | src/http.spec.ts > HTTP > schemas > should return the validated response if the status matches a schema
105
- HTTPRequest {
106
- headers: {},
107
- params: {},
108
- route: [],
109
- baseUrl: undefined,
110
- method: 'GET',
111
- data: undefined
112
- }
113
-
114
- ✓ src/http.spec.ts (13 tests) 35ms
115
-
116
- Test Files 7 passed (7)
117
- Tests 52 passed (52)
118
- Start at 13:56:48
119
- Duration 5.28s (transform 2.17s, setup 169ms, collect 5.60s, tests 55ms, environment 7ms, prepare 4.76s)
120
-
package/CHANGELOG.md DELETED
@@ -1,335 +0,0 @@
1
- # @autometa/http
2
-
3
- ## 1.4.20
4
-
5
- ### Patch Changes
6
-
7
- - Updated dependencies [8df323c]
8
- - @autometa/injection@0.1.5
9
- - @autometa/dto-builder@0.13.11
10
- - @autometa/app@0.4.2
11
-
12
- ## 1.4.19
13
-
14
- ### Patch Changes
15
-
16
- - Updated dependencies [da669a3]
17
- - @autometa/injection@0.1.4
18
- - @autometa/app@0.4.1
19
- - @autometa/dto-builder@0.13.10
20
-
21
- ## 1.4.18
22
-
23
- ### Patch Changes
24
-
25
- - Updated dependencies [7440e9f]
26
- - @autometa/app@0.4.0
27
-
28
- ## 1.4.17
29
-
30
- ### Patch Changes
31
-
32
- - Updated dependencies [1d3f84e]
33
- - @autometa/app@0.3.5
34
-
35
- ## 1.4.16
36
-
37
- ### Patch Changes
38
-
39
- - f60af5c: fix(http): dynamic headers could not be replaced with static headers
40
-
41
- ## 1.4.15
42
-
43
- ### Patch Changes
44
-
45
- - fdc17af: fix: params setter only accept string values
46
-
47
- ## 1.4.14
48
-
49
- ### Patch Changes
50
-
51
- - d759d5c: fix: value.replace is not a function when allowPlainText is false
52
-
53
- ## 1.4.13
54
-
55
- ### Patch Changes
56
-
57
- - Updated dependencies [603d0d0]
58
- - @autometa/dto-builder@0.13.9
59
-
60
- ## 1.4.12
61
-
62
- ### Patch Changes
63
-
64
- - 0a250f4: regression
65
-
66
- ## 1.4.11
67
-
68
- ### Patch Changes
69
-
70
- - b579743: fix(http): options not derived
71
-
72
- ## 1.4.10
73
-
74
- ### Patch Changes
75
-
76
- - dbc0eda: feat(http): allow client options to be created with `sharedOptions`
77
-
78
- ## 1.4.9
79
-
80
- ### Patch Changes
81
-
82
- - 2aee2a4: fix(http): spread and array parameters not passed correctly
83
- - 2aee2a4: fix(http): spread and array parameters not passed correctly
84
- - Updated dependencies [2aee2a4]
85
- - @autometa/injection@0.1.3
86
- - @autometa/dto-builder@0.13.8
87
- - @autometa/app@0.3.4
88
-
89
- ## 1.4.8
90
-
91
- ### Patch Changes
92
-
93
- - 536004e: fix: injection errors and http client hooks
94
-
95
- - The new dependency injection library sometimes returned class prototypes instead of class instances due to inconsistent caching of decorated types.
96
- - HTTP client hooks were not executing when certain builder methods were called.
97
-
98
- - Updated dependencies [536004e]
99
- - Updated dependencies [bac2661]
100
- - @autometa/dto-builder@0.13.7
101
- - @autometa/injection@0.1.2
102
- - @autometa/app@0.3.3
103
-
104
- ## 1.4.7
105
-
106
- ### Patch Changes
107
-
108
- - cccedea: fix(http): dynamic headers not deriving and resolving correctly
109
- - Updated dependencies [cccedea]
110
- - @autometa/dto-builder@0.13.6
111
-
112
- ## 1.4.6
113
-
114
- ### Patch Changes
115
-
116
- - Updated dependencies [db87a56]
117
- - @autometa/dto-builder@0.13.5
118
-
119
- ## 1.4.5
120
-
121
- ### Patch Changes
122
-
123
- - Updated dependencies [ae7e34f]
124
- - @autometa/dto-builder@0.13.4
125
-
126
- ## 1.4.4
127
-
128
- ### Patch Changes
129
-
130
- - Updated dependencies
131
- - @autometa/dto-builder@0.13.3
132
-
133
- ## 1.4.3
134
-
135
- ### Patch Changes
136
-
137
- - Updated dependencies
138
- - @autometa/dto-builder@0.13.2
139
-
140
- ## 1.4.2
141
-
142
- ### Patch Changes
143
-
144
- - Updated dependencies [95512a3]
145
- - @autometa/dto-builder@0.13.1
146
-
147
- ## 1.4.1
148
-
149
- ### Patch Changes
150
-
151
- - 16634f7: fix(HTTP): dynamic headers not passable nor resolving
152
-
153
- ## 1.4.0
154
-
155
- ### Minor Changes
156
-
157
- - 7e9d2bc: feat: Table Documents
158
-
159
- Introduces a new way of handling tables which are horizontal (HTable) or vertical (VTable) which maps
160
- the headers of a table to an object properties, defined using a class.
161
-
162
- [docs](https://bendat.github.io/autometa/docs/cucumber/test_runner/datatables#table-documents)
163
-
164
- ### Patch Changes
165
-
166
- - Updated dependencies [7e9d2bc]
167
- - @autometa/dto-builder@0.13.0
168
-
169
- ## 1.3.0
170
-
171
- ### Minor Changes
172
-
173
- - 82168a2: fix: `onRecievedResponse` hook not running when response failed schema validation
174
-
175
- - Renamed hooks to `onSend` and `onRecieve`
176
- - Rewrote HTTP fixture logic to be constructable and derivable.
177
- - `new HTTP().sharedRoute('v1')` constructs a single instance of HTTP with route `v1`
178
- - `new HTTP().sharedRoute('v1').route('user') derives a new HTTP fixture which inherits 'v1' and adds 'user' locally.
179
- - Support for list based params with `paramList` and `sharedParamList`
180
- - Added default schemas for use with simple response types like null, boolean, number etc
181
-
182
- ### Patch Changes
183
-
184
- - Updated dependencies [d563916]
185
- - @autometa/dto-builder@0.12.0
186
- - @autometa/injection@0.1.1
187
- - @autometa/app@0.3.2
188
-
189
- ## 1.2.1
190
-
191
- ### Patch Changes
192
-
193
- - Updated dependencies [6c4bb8d]
194
- - @autometa/app@0.3.1
195
-
196
- ## 1.2.0
197
-
198
- ### Minor Changes
199
-
200
- - 98d911f: feat: replace tsyringe with custom DI solution
201
-
202
- ### Patch Changes
203
-
204
- - Updated dependencies [98d911f]
205
- - @autometa/injection@0.1.0
206
- - @autometa/app@0.3.0
207
-
208
- ## 1.1.0
209
-
210
- ### Minor Changes
211
-
212
- - 4bbe6fc: feat: support factory function for shared headers
213
-
214
- ## 1.0.14
215
-
216
- ### Patch Changes
217
-
218
- - Updated dependencies [3fe2ad4]
219
- - @autometa/errors@0.2.2
220
- - @autometa/app@0.2.4
221
-
222
- ## 1.0.13
223
-
224
- ### Patch Changes
225
-
226
- - Updated dependencies [3493bb6]
227
- - @autometa/errors@0.2.1
228
- - @autometa/app@0.2.3
229
-
230
- ## 1.0.12
231
-
232
- ### Patch Changes
233
-
234
- - Updated dependencies [8ec0cdc]
235
- - @autometa/app@0.2.2
236
-
237
- ## 1.0.11
238
-
239
- ### Patch Changes
240
-
241
- - @autometa/app@0.2.1
242
-
243
- ## 1.0.10
244
-
245
- ### Patch Changes
246
-
247
- - Updated dependencies [b5ce008]
248
- - Updated dependencies [8f116d9]
249
- - @autometa/errors@0.2.0
250
- - @autometa/app@0.2.0
251
-
252
- ## 1.0.9
253
-
254
- ### Patch Changes
255
-
256
- - a7b715a: fix: return empty string bodies without allowPlainText
257
-
258
- ## 1.0.8
259
-
260
- ### Patch Changes
261
-
262
- - 3390c77: fix: RequestState uses objects instead of maps
263
-
264
- ## 1.0.7
265
-
266
- ### Patch Changes
267
-
268
- - b992a2b: fix: HTTPResponse should be exported
269
-
270
- ## 1.0.6
271
-
272
- ### Patch Changes
273
-
274
- - 469f0cb: refactor: http client refactor
275
-
276
- ## 1.0.5
277
-
278
- ### Patch Changes
279
-
280
- - 3a8b32f: fix: improper handling of strings when parsing
281
-
282
- ## 1.0.4
283
-
284
- ### Patch Changes
285
-
286
- - 79a672d: fix: JSON.parse responses
287
-
288
- ## 1.0.3
289
-
290
- ### Patch Changes
291
-
292
- - ef91448: fix: http client return undefined
293
-
294
- ## 1.0.2
295
-
296
- ### Patch Changes
297
-
298
- - 9870641: fix: allow empty plaintext response without flagging it
299
-
300
- ## 1.0.1
301
-
302
- ### Patch Changes
303
-
304
- - e9a8dc8: fix: parsing numbers from raw response string
305
-
306
- ## 1.0.0
307
-
308
- ### Major Changes
309
-
310
- - c7b973f: fix: onRecieve hooks not executing if schema validation fails
311
-
312
- ## 0.1.2
313
-
314
- ### Patch Changes
315
-
316
- - 815b324: Fix: incorrectly imported cli-highlight package
317
-
318
- ## 0.1.1
319
-
320
- ### Patch Changes
321
-
322
- - 2ec3670: fix: http client accepts any input and converts it to a string
323
-
324
- ## 0.1.0
325
-
326
- ### Minor Changes
327
-
328
- - 04ed85d: feat: added HTP client based on axios
329
-
330
- ### Patch Changes
331
-
332
- - Updated dependencies [04ed85d]
333
- - @autometa/status-codes@0.4.1
334
- - @autometa/errors@0.1.4
335
- - @autometa/app@0.1.13