@autometa/http 1.3.0 → 1.4.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @autometa/http
2
2
 
3
+ ## 1.4.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 16634f7: fix(HTTP): dynamic headers not passable nor resolving
8
+
9
+ ## 1.4.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 7e9d2bc: feat: Table Documents
14
+
15
+ Introduces a new way of handling tables which are horizontal (HTable) or vertical (VTable) which maps
16
+ the headers of a table to an object properties, defined using a class.
17
+
18
+ [docs](https://bendat.github.io/autometa/docs/cucumber/test_runner/datatables#table-documents)
19
+
20
+ ### Patch Changes
21
+
22
+ - Updated dependencies [7e9d2bc]
23
+ - @autometa/dto-builder@0.13.0
24
+
3
25
  ## 1.3.0
4
26
 
5
27
  ### Minor Changes
package/dist/esm/index.js CHANGED
@@ -42,8 +42,8 @@ var HTTPResponse = class _HTTPResponse {
42
42
  Object.assign(newResponse, response);
43
43
  return response;
44
44
  }
45
- decompose(transformFn) {
46
- const value = getDecompositionValue(this.data, transformFn);
45
+ decompose(transformFnOrVal) {
46
+ const value = getDecompositionValue(this.data, transformFnOrVal);
47
47
  return new HTTPResponseBuilder().status(this.status).statusText(this.statusText).headers(this.headers).request(this.request).data(value).build();
48
48
  }
49
49
  };
@@ -160,12 +160,12 @@ var HTTPRequest = class _HTTPRequest {
160
160
  *
161
161
  * Note characters may be converted to escape codes. I.e (space => %20) and (comma => %2C)
162
162
  *
163
- * N.B this method estimates what the url will be. The actual value
163
+ * N.B this getter estimates what the url will be. The actual value
164
164
  * might be different depending on your underlying HTTPClient and
165
165
  * configuration. For example, query parameters might
166
166
  * use different array formats.
167
167
  */
168
- fullUrl() {
168
+ get fullUrl() {
169
169
  return urlJoinP(this.baseUrl, this.route, this.params);
170
170
  }
171
171
  /**
@@ -199,10 +199,10 @@ var _HTTPRequestBuilder = class _HTTPRequestBuilder {
199
199
  get request() {
200
200
  return __privateGet(this, _request);
201
201
  }
202
- resolveDynamicHeaders() {
202
+ async resolveDynamicHeaders() {
203
203
  for (const [name, value] of __privateGet(this, _dynamicHeaders)) {
204
204
  try {
205
- __privateGet(this, _request).headers[name] = String(value());
205
+ __privateGet(this, _request).headers[name] = String(await value());
206
206
  } catch (e) {
207
207
  const cause = e;
208
208
  const msg = `Failed to resolve dynamic header "${name}":
@@ -243,9 +243,10 @@ ${cause}`;
243
243
  }
244
244
  header(name, value) {
245
245
  if (typeof value === "function") {
246
- value = value();
246
+ __privateGet(this, _dynamicHeaders).set(name, value);
247
247
  }
248
- __privateGet(this, _request).headers[name] = String(value);
248
+ const val = Array.isArray(value) ? value.join(",") : String(value);
249
+ __privateGet(this, _request).headers[name] = val;
249
250
  return this;
250
251
  }
251
252
  headers(dict) {
@@ -963,7 +964,7 @@ _request2 = new WeakMap();
963
964
  _metaConfig = new WeakMap();
964
965
  _makeRequest = new WeakSet();
965
966
  makeRequest_fn = async function(builder, options) {
966
- const request = builder.resolveDynamicHeaders().build();
967
+ const request = (await builder.resolveDynamicHeaders()).build();
967
968
  const meta = __privateGet(this, _metaConfig).derive().build();
968
969
  await this.runOnSendHooks(meta, request);
969
970
  const result = await this.client.request(request, options);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/http-response.ts","../../src/axios-client.ts","../../src/http-client.ts","../../src/http.ts","../../src/default-client-factory.ts","../../src/http-request.ts","../../src/schema.map.ts","../../src/request-meta.config.ts","../../src/transform-response.ts","../../src/default-schema.ts"],"sourcesContent":["import { HTTPRequest } from \"./http-request\";\nimport { StatusCode } from \"./types\";\n\nexport class HTTPResponse<T = unknown> {\n status: StatusCode;\n statusText: string;\n data: T;\n headers: Record<string, string>;\n request: HTTPRequest<unknown>;\n\n constructor() {\n this.headers = {};\n }\n\n static fromRaw<T>(response: HTTPResponse<T>) {\n const newResponse = new HTTPResponse<T>();\n Object.assign(newResponse, response);\n return response;\n }\n\n /**\n * Decomposes a response, creating an exact copy of the current response,\n * but with a new data value. The data can be provided directly as is, or it\n * can be generated through a callback function which receives the current\n * response data as an argument.\n *\n * ```ts\n * const response = await http.get(\"/products\");\n *\n * // direct value\n * const products = response.data;\n * const firstProduct = response.decompose(products[0]);\n * // callback transformer\n * const secondProduct = response.decompose((products) => products[1]);\n * // callback transformer with destructuring\n * const secondProduct = response.decompose(([product]) => product);\n * ```\n * @param value \n */\n decompose<K>(value: K): HTTPResponse<K>;\n decompose<K>(transformFn: (response: T) => K): HTTPResponse<K>;\n decompose<K>(transformFn: K | ((response: T) => K)): HTTPResponse<K> {\n const value = getDecompositionValue<T>(this.data, transformFn);\n return new HTTPResponseBuilder()\n .status(this.status)\n .statusText(this.statusText)\n .headers(this.headers)\n .request(this.request)\n .data(value)\n .build() as HTTPResponse<K>;\n }\n}\n\nfunction getDecompositionValue<T>(data: unknown, transformFn: unknown): T {\n return typeof transformFn === \"function\" ? transformFn(data) : transformFn;\n}\n\nexport class HTTPResponseBuilder {\n #response = new HTTPResponse();\n\n static create() {\n return new HTTPResponseBuilder();\n }\n\n derive() {\n return HTTPResponseBuilder.create()\n .data(this.#response.data)\n .headers(this.#response.headers)\n .request(this.#response.request)\n .status(this.#response.status)\n .statusText(this.#response.statusText);\n }\n\n status(code: StatusCode) {\n this.#response.status = code;\n return this;\n }\n\n statusText(text: string) {\n this.#response.statusText = text;\n return this;\n }\n\n data<T>(data: T) {\n this.#response.data = data;\n return this;\n }\n\n headers(dict: Record<string, string>) {\n this.#response.headers = dict;\n return this;\n }\n\n header(name: string, value: string) {\n this.#response.headers[name] = value;\n return this;\n }\n\n request(request: HTTPRequest<unknown>) {\n this.#response.request = request;\n return this;\n }\n\n build() {\n return this.#response;\n }\n}\n","import { HTTPRequest } from \"./http-request\";\nimport { HTTPResponse, HTTPResponseBuilder } from \"./http-response\";\nimport { HTTPAdditionalOptions, StatusCode } from \"./types\";\nimport axios, { AxiosRequestConfig } from \"axios\";\nimport { HTTPClient } from \"./http-client\";\n\n@HTTPClient.Use()\nexport class AxiosClient extends HTTPClient {\n async request<TRequestType, TResponseType>(\n request: HTTPRequest<TRequestType>,\n options: HTTPAdditionalOptions<AxiosRequestConfig>\n ): Promise<HTTPResponse<TResponseType>> {\n const { baseUrl, route, params, headers, method, data } = request;\n const url = [baseUrl, ...route].join(\"/\");\n const axiosRequest: AxiosRequestConfig = {\n url,\n params,\n headers,\n method: method,\n data,\n validateStatus: function (status) {\n return status >= 0 && status < 600;\n },\n ...options\n };\n const response = await axios(axiosRequest);\n return HTTPResponseBuilder.create()\n .status(response.status as StatusCode)\n .statusText(response.statusText)\n .data(response.data)\n .headers(response.headers as Record<string, string>)\n .request(request)\n .build() as HTTPResponse<TResponseType>;\n }\n}\n","import { HTTPRequest } from \"./http-request\";\nimport { HTTPResponse } from \"./http-response\";\nimport { HTTPAdditionalOptions } from \"./types\";\nimport { Class } from \"@autometa/types\";\nexport let defaultClient: Class<HTTPClient>;\nexport abstract class HTTPClient {\n static Use(): (target: Class<HTTPClient>) => void\n static Use(client?: Class<HTTPClient>) {\n if (client) {\n defaultClient = client\n }\n return function (target: Class<HTTPClient>) {\n defaultClient = target\n };\n }\n abstract request<TRequestType, TResponseType>(\n request: HTTPRequest<TRequestType>,\n options?: HTTPAdditionalOptions<unknown>\n ): Promise<HTTPResponse<TResponseType>>;\n}\n","import { Fixture, INJECTION_SCOPE } from \"@autometa/injection\";\nimport { AxiosClient } from \"./axios-client\";\nimport { HTTPClient } from \"./http-client\";\nimport { defaultClientFactory } from \"./default-client-factory\";\nimport { HTTPRequest, HTTPRequestBuilder } from \"./http-request\";\nimport { HTTPResponse } from \"./http-response\";\nimport { MetaConfig, MetaConfigBuilder } from \"./request-meta.config\";\nimport {\n HTTPAdditionalOptions,\n RequestHook,\n ResponseHook,\n SchemaParser,\n StatusCode\n} from \"./types\";\nimport { transformResponse } from \"./transform-response\";\nimport { AutomationError } from \"@autometa/errors\";\n\n/**\n * The HTTP fixture allows requests to be built and sent to a server. In general,\n * there are 2 modes of operation:\n *\n * * Shared Chain: The shared chain is used to configure the client for all requests, such as\n * routes this instance will always be used. When a shared chain method is called, it returns\n * the same instance of HTTP which can be further chained to configure the client.\n * * Request Chain: The request chain is used to configure a single request, inheriting values\n * set by the shared chain. When called, a new HTTP client instance is created and inherits the values\n * set by it's parent.\n *\n * The 2 modes are intended to simplify configuring an object through an inheritance chain. For example,\n * assume we have an API with 2 controller routes, `/product` and `/seller`. We can set up a Base Client\n * which consumes the HTTP fixture and configures it with the base url of our API.\n *\n * Inheritors can further configure their HTTP instance's routes.\n *\n * ```ts\n * \\@Constructor(HTTP)\n * export class BaseClient {\n * constructor(protected readonly http: HTTP) {\n * this.http.url(\"https://api.example.com\");\n * }\n * }\n *\n * export class ProductClient extends BaseClient {\n * constructor(http: HTTP) {\n * super(http);\n * this.http.sharedRoute(\"product\");\n * }\n * getProduct(id: number) {\n * return this.http.route(id).get();\n * }\n *\n * export class SellerClient extends BaseClient {\n * constructor(http: HTTP) {\n * super(http);\n * this.http.sharedRoute(\"seller\");\n * }\n *\n * getSeller(id: number) {\n * return this.http.route(id).get();\n * }\n * }\n * ```\n *\n * 'Schemas' can also be configured. A Schema is a function or an object with a `parse` method, which\n * takes a response data payload and returns a validated object. Schemas are mapped to\n * HTTP Status Codes, and if configured to be required the request will fail if no schema is found\n * matching that code.\n *\n * Defining a schema function:\n *\n * ```\n * // user.schema.ts\n * export function UserSchema(data: unknown) {\n * if(typeof data !== \"object\") {\n * throw new Error(\"Expected an object\");\n * }\n *\n * if(typeof data.name !== \"string\") {\n * throw new Error(\"Expected a string\");\n * }\n *\n * return data as { name: string };\n * }\n *\n * // user.controller.ts\n * \\@Fixture(INJECTION_SCOPE.TRANSIENT)\n * export class UserController extends BaseController {\n * constructor(private readonly http: HTTP) {\n * super(http);\n * this.http\n * .sharedRoute(\"user\")\n * .sharedSchema(ErrorSchema, { from: 400, to: 499 });\n * }\n *\n * getUser(id: number) {\n * return this.http.route(id).schema(UserSchema, 200).get();\n * // or\n * return this.http\n * .route(id)\n * .schema(UserSchema, { from: 200, to: 299 })\n * .get();\n * // or\n * return this.http\n * .route(id)\n * .schema(UserSchema, 200, 201, 202)\n * .get();\n * }\n * }\n * ```\n *\n * Validation libraries which use a `.parse` or `.validation`, method, such as Zod or MyZod, can also be used as schemas:\n *\n * ```ts\n * // user.schema.ts\n * import { z } from \"myzod\";\n *\n * export const UserSchema = z.object({\n * name: z.string()\n * });\n *\n * // user.controller.ts\n * \\@Fixture(INJECTION_SCOPE.TRANSIENT)\n * export class UserController extends BaseController {\n * constructor(private readonly http: HTTP) {\n * super(http);\n * this.http\n * .sharedRoute(\"user\")\n * .sharedSchema(ErrorSchema, { from: 400, to: 499 })\n * }\n *\n * getUser(id: number) {\n * return this.http.route(id).schema(UserSchema, 200).get();\n * }\n * }\n * ```\n */\n@Fixture(INJECTION_SCOPE.TRANSIENT)\nexport class HTTP {\n #request: HTTPRequestBuilder<HTTPRequest<unknown>>;\n #metaConfig: MetaConfigBuilder;\n constructor(\n private readonly client: HTTPClient = defaultClientFactory(),\n builder: HTTPRequestBuilder<\n HTTPRequest<unknown>\n > = new HTTPRequestBuilder(),\n metaConfig: MetaConfigBuilder = new MetaConfigBuilder()\n ) {\n this.#request = builder.derive();\n this.#metaConfig = metaConfig.derive();\n }\n\n static create(\n client: HTTPClient = new AxiosClient(),\n builder: HTTPRequestBuilder<\n HTTPRequest<unknown>\n > = new HTTPRequestBuilder(),\n metaConfig: MetaConfigBuilder = new MetaConfigBuilder()\n ) {\n return new HTTP(client, builder, metaConfig);\n }\n\n /**\n * Sets the base url of the request for this client, such as\n * `https://api.example.com`, and could include always-used routes like\n * the api version, such as `/v1` or `/api/v1` at the end.\n *\n * ```ts\n *\n * \\@Fixture(INJECTION_SCOPE.TRANSIENT)\n * export abstract class BaseClient {\n * constructor(protected readonly http: HTTP) {\n * this.http.url(\"https://api.example.com\");\n * }\n * }\n * ```\n * @param url\n * @returns\n */\n url(url: string) {\n this.#request.url(url);\n return this;\n }\n\n /**\n * If set to true, all requests derived from this client will require a schema be defined\n * matching any response status code. If set to false, a schema will still be used for validation\n * if defined, or the unadulterated original body will be returned if no schema matches.\n *\n * @param required Whether or not a schema is required for all responses.\n * @returns This instance of HTTP.\n */\n requireSchema(required: boolean) {\n this.#metaConfig.requireSchema(required);\n return this;\n }\n\n /**\n * If set to true, all requests derived from this client will allow plain text\n * responses. If set to false, plain text responses will throw an serialization error.\n *\n * Useful when an endpoint returns a HTML or plain text response. If the plain text\n * is the value of `true` or `false`, or a number, it will be parsed into the\n * appropriate type.\n *\n * This method is a shared chain method, and will return the same instance of HTTP.\n *\n * @param allow Whether or not plain text responses are allowed.\n * @returns This instance of HTTP.\n */\n sharedAllowPlainText(allow: boolean) {\n this.#metaConfig.allowPlainText(allow);\n return this;\n }\n\n /**\n * If set to true, all requests derived from this client will allow plain text\n * responses. If set to false, plain text responses will throw an serialization error.\n *\n * Useful when an endpoint returns a HTML or plain text response. If the plain text\n * is the value of `true` or `false`, or a number, it will be parsed into the\n * appropriate type.\n *\n * This method is a request chain method, and will return a new instance of HTTP.\n *\n * @param allow Whether or not plain text responses are allowed.\n * @returns A new child instance of HTTP derived from this one.\n */\n allowPlainText(allow: boolean) {\n return HTTP.create(\n this.client,\n this.#request.derive(),\n this.#metaConfig.derive().allowPlainText(allow)\n );\n }\n\n /**\n * Attaches a route to the request, such as `/product` or `/user`. Subsequent calls\n * to this method will append the route to the existing route, such as `/product/1`.\n *\n * Numbers will be converted to strings automatically. Routes can be defined one\n * at a time or as a spread argument.\n *\n * ```ts\n * constructor(http: HTTP) {\n * super(http);\n * this.http.sharedRoute(\"user\", id).get();\n * }\n *\n * // or\n *\n * constructor(http: HTTP) {\n * super(http);\n * this.http\n * .sharedRoute(\"user\")\n * .sharedRoute(id)\n * .get();\n * }\n * ```\n *\n * This method is a shared chain method, and will return the same instance of HTTP. All\n * child clients will inherit the routes defined by this method. Useful to configure\n * in the constructor body.\n *\n * @param route A route or spread list of routes to append to the request.\n * @returns This instance of HTTP.\n */\n sharedRoute(...route: (string | number | boolean)[]) {\n this.#request.route(...route.map((r) => r.toString()));\n return this;\n }\n\n /**\n * Attaches a route to the request, such as `/product` or `/user`. Subsequent calls\n * to this method will append the route to the existing route, such as `/product/1`.\n *\n * Numbers will be converted to strings automatically. Routes can be defined one\n * at a time or as a spread argument.\n *\n * ```ts\n * getUser(id: number) {\n * return this.http.route(\"user\", id).get();\n * }\n *\n * // or\n *\n * getUser(id: number) {\n * return this.http\n * .route(\"user\")\n * .route(id)\n * .get();\n * }\n * ```\n *\n * This method is a request chain method, and will return a new instance of HTTP, inheriting\n * any routes previously defined and appending the new route. Useful to configure\n * in class methods as part of finalizing a request.\n *\n * @param route A route or spread list of routes to append to the request.\n * @returns A new child instance of HTTP derived from this one.\n */\n route(...route: (string | number | boolean)[]) {\n const mapped = route.map((r) => String(r));\n return HTTP.create(this.client, this.#request.derive().route(...mapped));\n }\n\n /**\n * Attaches a shared schema mapping for all requests by this client. Schemas are\n * mapped to HTTP Status Codes, and if configured to be required the request will fail\n * if no schema is found matching that code.\n *\n * The status code mapping can be defined as a single code, a range of codes, or a spread list.\n *\n * ```ts\n * \\@Fixture(INJECTION_SCOPE.TRANSIENT)\n * export class UserController extends BaseController {\n * constructor(private readonly http: HTTP) {\n * super(http);\n * this.http\n * .sharedRoute(\"user\")\n * .sharedSchema(UserSchema, 200)\n * .sharedSchema(EmptySchema, 201, 204)\n * .sharedSchema(ErrorSchema, { from: 400, to: 499 });\n * }\n * }\n * ```\n *\n * This method is a shared chain method, and will return the same instance of HTTP. All\n * child clients will inherit the schemas defined by this method. Useful to configure\n * in the constructor body.\n *\n * @param parser The schema parser to use for this mapping.\n * @param codes A single status code, a range of status codes, or a spread list of status codes.\n * @returns This instance of HTTP.\n */\n sharedSchema(parser: SchemaParser, ...codes: StatusCode[]): HTTP;\n sharedSchema(\n parser: SchemaParser,\n ...range: { from: StatusCode; to: StatusCode }[]\n ): HTTP;\n sharedSchema(\n parser: SchemaParser,\n ...args: (StatusCode | { from: StatusCode; to: StatusCode })[]\n ): HTTP {\n this.#metaConfig.schema(parser, ...args);\n return this;\n }\n\n /**\n * Attaches a schema mapping for this request. Schemas are\n * mapped to HTTP Status Codes, and if configured to be required the request will fail\n * if no schema is found matching that code.\n *\n * The status code mapping can be defined as a single code, a range of codes, or a spread list.\n *\n * ```ts\n * \\@Fixture(INJECTION_SCOPE.TRANSIENT)\n * export class UserController extends BaseController {\n * constructor(private readonly http: HTTP) {\n * super(http);\n * this.http\n * .sharedRoute(\"user\")\n * .schema(ErrorSchema, { from: 400, to: 499 });\n * }\n *\n * getUser(id: number) {\n * return this.http.route(id).schema(UserSchema, 200).get();\n * }\n *\n * getUsers(...ids: number[]) {\n * return this.http\n * .route(\"users\")\n * .schema(UserSchema, { from: 200, to: 299 })\n * .schema(UserSchema, 200)\n * .get();\n * }\n * ```\n *\n * This method is a request chain method, and will return a new instance of HTTP, inheriting\n * any schemas previously defined and appending the new schema. Useful to configure\n * in class methods as part of finalizing a request.\n *\n * @param parser The schema parser to use for this mapping.\n * @param codes A single status code, a range of status codes, or a spread list of status codes.\n * @returns A new child instance of HTTP derived from this one.\n */\n schema(parser: SchemaParser, ...codes: StatusCode[]): HTTP;\n schema(\n parser: SchemaParser,\n ...range: { from: StatusCode; to: StatusCode }[]\n ): HTTP;\n schema(\n parser: SchemaParser,\n ...args: (StatusCode | { from: StatusCode; to: StatusCode })[]\n ): HTTP {\n return HTTP.create(\n this.client,\n this.#request.derive(),\n this.#metaConfig.derive().schema(parser, ...args)\n );\n }\n\n /**\n * Attaches a shared query string parameter to all requests by this client. Query string\n * parameters are key-value pairs which are appended to the request url, such as\n * `https://api.example.com?name=John&age=30`.\n *\n * This method is a shared chain method, and will return the same instance of HTTP. All\n * child clients will inherit the query string parameters defined by this method. Useful to configure\n * in the constructor body.\n *\n * @param name The name of the query string parameter.\n * @param value The value of the query string parameter.\n * @returns This instance of HTTP.\n */\n sharedParam(name: string, value: Record<string, unknown>): HTTP;\n sharedParam(name: string, ...value: (string | number | boolean)[]): HTTP;\n sharedParam(\n name: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n value: any\n ): HTTP {\n this.#request.param(name, value);\n return this;\n }\n\n /**\n * `onSend` is a pre-request hook which will be executed in order of definition\n * immediately before the request is sent. This hook can be used to analyze or\n * log the request state.\n *\n * ```ts\n *\n * \\@Fixture(INJECTION_SCOPE.TRANSIENT)\n * export class UserController extends BaseController {\n * constructor(private readonly http: HTTP) {\n * super(http);\n * this.http\n * .sharedRoute(\"user\")\n * .sharedOnSend(\"log request\",\n * (request) => console.log(JSON.stringify(request, null, 2))\n * );\n * }\n * }\n * ```\n *\n * This method is a shared chain method, and will return the same instance of HTTP. All\n * child clients will inherit the onSend hooks defined by this method. Useful to configure\n * in the constructor body.\n *\n * @param description A description of the hook, used for debugging.\n * @param hook The hook to execute.\n * @returns This instance of HTTP.\n */\n sharedOnSend(description: string, hook: RequestHook) {\n this.#metaConfig.onBeforeSend(description, hook);\n return this;\n }\n\n /**\n * `onReceive` is a post-request hook which will be executed in order of definition\n * immediately after the response is received. This hook can be used to analyze or\n * log the response state.\n *\n * ```ts\n *\n * \\@Fixture(INJECTION_SCOPE.TRANSIENT)\n * export class UserController extends BaseController {\n * constructor(private readonly http: HTTP) {\n * super(http);\n * this.http\n * .sharedRoute(\"user\")\n * .sharedOnReceive(\"log response\",\n * (response) => console.log(JSON.stringify(response, null, 2))\n * );\n * }\n * }\n * ```\n *\n * This method is a shared chain method, and will return the same instance of HTTP. All\n * child clients will inherit the onReceive hooks defined by this method. Useful to configure\n * in the constructor body.\n *\n * @param description A description of the hook, used for debugging.\n * @param hook The hook to execute.\n * @returns This instance of HTTP.\n */\n sharedOnReceive(description: string, hook: ResponseHook<unknown>) {\n this.#metaConfig.onReceiveResponse(description, hook);\n return this;\n }\n\n /**\n * Attaches a query string parameter object to the request. Query string\n * parameters are key-value pairs which are appended to the request url, such as\n * `https://api.example.com?name=John&age=30`.\n *\n * This method is a shared chain method, and will return the same instance of HTTP. All\n * child clients will inherit the query string parameters defined by this method. Useful to configure\n * in the constructor body.\n *\n * ```ts\n * constructor(http: HTTP) {\n * super(http);\n * this.http\n * .sharedParams({ 'is-test': \"true\" })\n * ```\n * @param name The name of the query string parameter.\n * @param value The value of the query string parameter.\n * @returns This instance of HTTP.\n */\n sharedParams(dict: Record<string, unknown>) {\n this.#request.params(dict);\n return this;\n }\n\n /**\n * Attaches a query string parameter to the request. Query string\n * parameters are key-value pairs which are appended to the request url, such as\n * `https://api.example.com?name=John&age=30`.\n *\n * This method is a request chain method, and will return a new instance of HTTP, inheriting\n * any query string parameters previously defined and appending the new parameter. Useful to configure\n * in class methods as part of finalizing a request.\n *\n * ```ts\n * getUser(id: number) {\n * return this.http\n * .route(id)\n * .param(\"name\", \"John\")\n * .param(\"age\", 30)\n * ```\n *\n * Note: Numbers and Booleans will be converted to strings automatically.\n *\n * @param name The name of the query string parameter.\n * @param value The value of the query string parameter.\n * @returns A new child instance of HTTP derived from this one.\n */\n param(name: string, value: Record<string, unknown>): HTTP;\n param(name: string, ...value: (string | number | boolean)[]): HTTP;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n param(name: string, value: any) {\n return HTTP.create(this.client, this.#request.derive().param(name, value));\n }\n\n /**\n * Attaches a query string parameter object to the request. Query string\n * parameters are key-value pairs which are appended to the request url, such as\n * `https://api.example.com?name=John&age=30`.\n *\n * This method is a shared chain method, and will return the same instance of HTTP. All\n * child clients will inherit the query string parameters defined by this method. Useful to configure\n * in the constructor body.\n *\n * ```ts\n * getUser(id: number) {\n * return this.http\n * .route(id)\n * .param({ name: \"John\", age: \"30\" })\n *\n * @param name The name of the query string parameter.\n * @param value The value of the query string parameter.\n * @returns This instance of HTTP.\n */\n params(dict: Record<string, string>) {\n this.#request.params(dict);\n return HTTP.create(this.client, this.#request.derive().params(dict));\n }\n\n /**\n * Attaches a shared data payload to this client. The data payload is the body of the request,\n * and can be any type. If the data payload is an object, it will be serialized to JSON.\n *\n * This method is a shared chain method, and will return the same instance of HTTP. All\n * child clients will inherit the data payload defined by this method. Useful to configure\n * in the constructor body.\n *\n * @param data The data payload to attach to the request.\n * @returns This instance of HTTP.\n */\n sharedData<T>(data: T) {\n this.#request.data(data);\n return this;\n }\n\n /**\n * Attaches a shared header to this client. Headers are string:string key-value pairs which are\n * sent with the request, such as `Content-Type: application/json`.\n *\n * Numbers, Booleans and Null will be converted to string values automatically.\n *\n * A Factory function can also be provided to generate the header value at the time of request.\n *\n * This method is a shared chain method, and will return the same instance of HTTP. All\n * child clients will inherit the header defined by this method. Useful to configure\n * in the constructor body.\n *\n * @param name The name of the header.\n * @param value The value of the header.\n */\n sharedHeader(\n name: string,\n value:\n | string\n | number\n | boolean\n | null\n | (() => string | number | boolean | null)\n ) {\n this.#request.header(name, value);\n return this;\n }\n\n header(name: string, value: string) {\n return HTTP.create(this.client, this.#request.derive().header(name, value));\n }\n\n /**\n * Attaches a data payload to this request. The data payload is the body of the request,\n * and can be any type. If the data payload is an object, it will be serialized to JSON.\n *\n * This method is a request chain method, and will return a new instance of HTTP, inheriting\n * any data payload previously defined and appending the new payload. Useful to configure\n * in class methods as part of finalizing a request.\n *\n * @param data The data payload to attach to the request.\n * @returns A new child instance of HTTP derived from this one.\n */\n data<T>(data: T) {\n this.#request.data(data);\n return HTTP.create(this.client, this.#request.derive().data(data));\n }\n\n /**\n * `onSend` is a pre-request hook which will be executed in order of definition\n * immediately before the request is sent. This hook can be used to modify the request,\n * or to log the state of a request before final send-off.\n *\n * ```ts\n *\n * \\@Fixture(INJECTION_SCOPE.TRANSIENT)\n * export class UserController extends BaseController {\n * constructor(private readonly http: HTTP) {\n * super(http);\n * }\n *\n * getUser(id: number) {\n * return this.http\n * .route(id)\n * .onSend(\"log request\",\n * (request) => console.log(JSON.stringify(request, null, 2)\n * )\n * .get();\n * }\n * ```\n *\n * This method is a request chain method, and will return a new instance of HTTP, inheriting\n * any onSend hooks previously defined and appending the new hook. Useful to configure\n * in class methods as part of finalizing a request.\n *\n * @param description A description of the hook, used for debugging.\n * @param hook The hook to execute.\n * @returns A new child instance of HTTP derived from this one.\n */\n onSend(description: string, hook: RequestHook) {\n return HTTP.create(\n this.client,\n this.#request.derive(),\n this.#metaConfig.derive().onBeforeSend(description, hook)\n );\n }\n\n /**\n * `onReceive` is a post-request hook which will be executed in order of definition\n * immediately after the response is received. This hook can be used to modify the response,\n * or to log the state of a response after it is received.\n *\n * ```ts\n *\n * \\@Fixture(INJECTION_SCOPE.TRANSIENT)\n * export class UserController extends BaseController {\n * constructor(private readonly http: HTTP) {\n * super(http);\n * }\n *\n * getUser(id: number) {\n * return this.http\n * .route(id)\n * .onReceive(\"log response\",\n * (response) => console.log(JSON.stringify(response, null, 2)\n * )\n * .get();\n * }\n * ```\n *\n * This method is a request chain method, and will return a new instance of HTTP, inheriting\n * any onReceive hooks previously defined and appending the new hook. Useful to configure\n * in class methods as part of finalizing a request.\n *\n * @param description A description of the hook, used for debugging.\n * @param hook The hook to execute.\n * @returns A new child instance of HTTP derived from this one.\n */\n onReceive(description: string, hook: ResponseHook<unknown>) {\n return HTTP.create(\n this.client,\n this.#request.derive(),\n this.#metaConfig.derive().onReceiveResponse(description, hook)\n );\n }\n\n /**\n * Executes the current request state as a GET request.\n *\n * @param options Additional options to pass to the underlying http client, such\n * as e.g Axios configuration values.\n * @returns A promise which resolves to the response.\n */\n get<TResponseType>(options?: HTTPAdditionalOptions<unknown>) {\n return this.#makeRequest(\n this.#request.derive().method(\"GET\"),\n options\n ) as Promise<HTTPResponse<TResponseType>>;\n }\n\n /**\n * Executes the current request state as a POST request.\n *\n * @param data The data payload to attach to the request.\n * @param options Additional options to pass to the underlying http client, such\n * as e.g Axios configuration values.\n * @returns A promise which resolves to the response.\n */\n post<TResponseType>(options?: HTTPAdditionalOptions<unknown>) {\n return this.#makeRequest(\n this.#request.derive().method(\"POST\"),\n options\n ) as Promise<HTTPResponse<TResponseType>>;\n }\n\n /**\n * Executes the current request state as a DELETE request.\n *\n * @param options Additional options to pass to the underlying http client, such\n * as e.g Axios configuration values.\n * @returns A promise which resolves to the response.\n * as e.g Axios configuration values.\n */\n delete<TResponseType>(options?: HTTPAdditionalOptions<unknown>) {\n return this.#makeRequest(\n this.#request.derive().method(\"DELETE\"),\n options\n ) as Promise<HTTPResponse<TResponseType>>;\n }\n\n /**\n * Executes the current request state as a PUT request.\n *\n * @param options Additional options to pass to the underlying http client, such\n * as e.g Axios configuration values.\n * @returns A promise which resolves to the response.\n */\n put<TResponseType>(options?: HTTPAdditionalOptions<unknown>) {\n return this.#makeRequest(\n this.#request.derive().method(\"PUT\"),\n options\n ) as Promise<HTTPResponse<TResponseType>>;\n }\n /**\n * Executes the current request state as a PATCH request.\n *\n * @param options Additional options to pass to the underlying http client, such\n * as e.g Axios configuration values.\n * @returns A promise which resolves to the response.\n */\n patch<TResponseType>(options?: HTTPAdditionalOptions<unknown>) {\n return this.#makeRequest(\n this.#request.derive().method(\"PATCH\"),\n options\n ) as Promise<HTTPResponse<TResponseType>>;\n }\n\n head<TResponseType>(options?: HTTPAdditionalOptions<unknown>) {\n return this.#makeRequest(\n this.#request.derive().method(\"HEAD\"),\n options\n ) as Promise<HTTPResponse<TResponseType>>;\n }\n\n options<TResponseType>(options?: HTTPAdditionalOptions<unknown>) {\n return this.#makeRequest(\n this.#request.derive().method(\"OPTIONS\"),\n options\n ) as Promise<HTTPResponse<TResponseType>>;\n }\n\n trace<TResponseType>(options?: HTTPAdditionalOptions<unknown>) {\n return this.#makeRequest(\n this.#request.derive().method(\"TRACE\"),\n options\n ) as Promise<HTTPResponse<TResponseType>>;\n }\n\n connect<TResponseType>(options?: HTTPAdditionalOptions<unknown>) {\n return this.#makeRequest(\n this.#request.derive().method(\"CONNECT\"),\n options\n ) as Promise<HTTPResponse<TResponseType>>;\n }\n\n async #makeRequest(\n builder: HTTPRequestBuilder<HTTPRequest<unknown>>,\n options?: HTTPAdditionalOptions<unknown>\n ) {\n const request = builder.resolveDynamicHeaders().build();\n const meta = this.#metaConfig.derive().build();\n await this.runOnSendHooks(meta, request);\n const result = await this.client.request<unknown, string>(request, options);\n result.data = transformResponse(meta.allowPlainText, result.data);\n await this.runOnReceiveHooks(meta, result);\n const validated = this.#validateResponse(result, meta);\n return validated;\n }\n\n private async runOnSendHooks(\n meta: MetaConfig,\n request: HTTPRequest<unknown>\n ) {\n for (const [description, hook] of meta.onSend) {\n try {\n await hook(request);\n } catch (e) {\n const cause = e as Error;\n const msg = `An error occurred while sending a request in hook: '${description}'`;\n throw new AutomationError(msg, { cause });\n }\n }\n }\n private async runOnReceiveHooks(\n meta: MetaConfig,\n response: HTTPResponse<unknown>\n ) {\n for (const [description, hook] of meta.onReceive) {\n try {\n await hook(response);\n } catch (e) {\n const cause = e as Error;\n const msg = `An error occurred while receiving a response in hook: '${description}'`;\n throw new AutomationError(msg, { cause });\n }\n }\n }\n\n #validateResponse<T>(\n response: HTTPResponse<unknown>,\n meta: MetaConfig\n ): HTTPResponse<T> {\n const { status, data } = response;\n const validated = meta.schemas.validate(\n status,\n data,\n meta.requireSchema\n ) as T;\n response.data = validated;\n return response as HTTPResponse<T>;\n }\n}\n","import { Class } from \"@autometa/types\";\nimport { defaultClient, type HTTPClient } from \"./http-client\";\n\nexport function defaultClientFactory() {\n const type = defaultClient as Class<HTTPClient>;\n return new type();\n}\n","import { RequestConfig, RequestConfigBasic } from \"./request.config\";\nimport { HTTPMethod } from \"./types\";\nimport { urlJoinP } from \"url-join-ts\";\nexport class HTTPRequest<T = unknown> implements RequestConfig<T> {\n headers: Record<string, string> = {};\n params: Record<string, string | string[] | Record<string, unknown>> = {};\n baseUrl?: string;\n route: string[] = [];\n method: HTTPMethod;\n data: T;\n\n constructor(config?: RequestConfigBasic) {\n Object.assign(this, config);\n }\n\n /**\n * Returns the full URL of the request, including the base url,\n * routes, and query parameters.\n *\n * ```ts\n * console.log(request.fullUrl())// https://example.com/foo?bar=baz?array=1,2,3\n * ```\n *\n * Note characters may be converted to escape codes. I.e (space => %20) and (comma => %2C)\n *\n * N.B this method estimates what the url will be. The actual value\n * might be different depending on your underlying HTTPClient and\n * configuration. For example, query parameters might\n * use different array formats.\n */\n fullUrl() {\n return urlJoinP(this.baseUrl, this.route, this.params);\n }\n\n /**\n * Returns a new independent copy of the request.\n */\n static derive(original: HTTPRequest<unknown>) {\n const request = new HTTPRequest();\n request.headers = { ...original.headers };\n request.params = { ...original.params };\n request.baseUrl = original.baseUrl;\n request.route = [...original.route];\n request.method = original.method;\n request.data = original.data;\n return request;\n }\n}\n\nexport class HTTPRequestBuilder<T extends HTTPRequest<unknown>> {\n #request: T;\n #dynamicHeaders = new Map<string, () => string | number | boolean | null>();\n\n constructor(request: T | (() => T) = () => new HTTPRequest() as T) {\n if (typeof request === \"function\") {\n this.#request = request();\n return;\n }\n this.#request = request;\n }\n\n static create<T extends HTTPRequest<unknown>>() {\n return new HTTPRequestBuilder<T>();\n }\n\n get request() {\n return this.#request;\n }\n\n resolveDynamicHeaders() {\n for (const [name, value] of this.#dynamicHeaders) {\n try {\n this.#request.headers[name] = String(value());\n } catch (e) {\n const cause = e as Error;\n const msg = `Failed to resolve dynamic header \"${name}\": \n${cause}`;\n throw new Error(msg);\n }\n }\n return this;\n }\n\n url(url: string) {\n this.#request.baseUrl = url;\n return this;\n }\n\n route(...route: string[]) {\n this.#request.route.push(...route);\n return this;\n }\n\n param(\n name: string,\n value:\n | string\n | number\n | boolean\n | (string | number | boolean)[]\n | Record<string, string | number | boolean>\n ) {\n if (Array.isArray(value)) {\n const asStr = value.map(String);\n this.#request.params[name] = asStr;\n return this;\n }\n if (!Array.isArray(value) && typeof value === \"object\") {\n this.#request.params[name] = value;\n return this;\n }\n this.#request.params[name] = String(value);\n return this;\n }\n\n params(dict: Record<string, unknown>) {\n Object.assign(this.#request.params, dict);\n return this;\n }\n\n data<T>(data: T) {\n this.#request.data = data;\n return this;\n }\n\n header(\n name: string,\n value:\n | string\n | number\n | boolean\n | null\n | (() => string | number | boolean | null)\n ) {\n if (typeof value === \"function\") {\n value = value();\n }\n this.#request.headers[name] = String(value);\n return this;\n }\n\n headers(dict: Record<string, string>) {\n Object.assign(this.#request.headers, dict);\n return this;\n }\n\n get() {\n return this.#request;\n }\n\n method(method: HTTPMethod) {\n this.#request.method = method;\n return this;\n }\n\n derive(): HTTPRequestBuilder<T> {\n const request = HTTPRequest.derive(this.#request);\n return new HTTPRequestBuilder(request) as HTTPRequestBuilder<T>;\n }\n\n build(): HTTPRequest<T> {\n return this.#request as HTTPRequest<T>;\n }\n}\n","import { SchemaParser, StatusCode } from \"./types\";\nexport class SchemaMap {\n #map: Map<StatusCode, SchemaParser>;\n constructor(map?: Map<StatusCode, SchemaParser> | SchemaMap) {\n if (map instanceof SchemaMap) {\n this.#map = new Map(map.#map);\n return;\n }\n this.#map = new Map(map);\n }\n\n derive() {\n return new SchemaMap(this.#map);\n }\n\n registerStatus(parser: SchemaParser, ...codes: StatusCode[]) {\n codes.forEach((code) => {\n if (this.#map.has(code)) {\n const msg = `Status code ${code} is already registered with a parser`;\n throw new Error(msg);\n }\n this.#map.set(code, parser);\n });\n }\n\n registerRange(parser: SchemaParser, from: StatusCode, to: StatusCode) {\n for (let i = from; i <= to; i++) {\n if (this.#map.has(i)) {\n throw new Error(`Status code ${i} is already registered with a parser`);\n }\n this.#map.set(i, parser);\n }\n }\n\n validate(status: StatusCode, data: unknown, requireSchema: boolean) {\n const parser = this.getParser(status, requireSchema);\n if (\"parse\" in parser) {\n return parser.parse(data);\n }\n if('validate' in parser) {\n return parser.validate(data);\n }\n try {\n return parser(data);\n } catch (e) {\n const msg = `Failed to schema parse response data for status code ${status} with data:\n \n${JSON.stringify(data, null, 2)}}`;\n throw new Error(msg);\n }\n }\n\n getParser(status: StatusCode, requireSchema: boolean) {\n const parser = this.#map.get(status);\n if (!parser && requireSchema) {\n const msg = `No parser registered for status code ${status} but 'requireSchema' is true`;\n throw new Error(msg);\n }\n if (parser) {\n return parser;\n }\n return (data: unknown) => data;\n }\n\n toObject() {\n return Object.fromEntries(this.#map) as Record<StatusCode, SchemaParser>;\n }\n}\n","import { SchemaMap } from \"./schema.map\";\nimport { RequestHook, ResponseHook, SchemaParser, StatusCode } from \"./types\";\n\nexport interface SchemaConfig {\n schemas: SchemaMap;\n requireSchema: boolean;\n allowPlainText: boolean;\n}\n\nexport interface HTTPHooks {\n onSend: [string, RequestHook][];\n onReceive: [string, ResponseHook<unknown>][];\n}\n\n// export type MetaConfig = SchemaConfig & HTTPHooks;\n\nexport class MetaConfig implements SchemaConfig, HTTPHooks {\n schemas: SchemaMap;\n requireSchema: boolean;\n allowPlainText: boolean;\n onSend: [string, RequestHook][] = [];\n onReceive: [string, ResponseHook<unknown>][] = [];\n throwOnServerError: boolean;\n}\n\nexport class MetaConfigBuilder {\n #schemaMap = new SchemaMap();\n #requireSchema = false;\n #allowPlainText = false;\n #onBeforeSend: [string, RequestHook][] = [];\n #onAfterSend: [string, ResponseHook<unknown>][] = [];\n #throwOnServerError = false;\n\n schemaMap(map: SchemaMap) {\n this.#schemaMap = map;\n return this;\n }\n\n schema(parser: SchemaParser, ...codes: StatusCode[]): MetaConfigBuilder;\n schema(\n parser: SchemaParser,\n ...range: { from: StatusCode; to: StatusCode }[]\n ): MetaConfigBuilder;\n schema(\n parser: SchemaParser,\n ...args: (StatusCode | { from: StatusCode; to: StatusCode })[]\n ): MetaConfigBuilder;\n schema(\n parser: SchemaParser,\n ...args: (StatusCode | { from: StatusCode; to: StatusCode })[]\n ) {\n args.forEach((arg) => {\n if (typeof arg === \"number\") {\n this.#schemaMap.registerStatus(parser, arg);\n } else {\n this.#schemaMap.registerRange(parser, arg.from, arg.to);\n }\n });\n\n return this;\n }\n\n requireSchema(value: boolean) {\n this.#requireSchema = value;\n return this;\n }\n\n allowPlainText(value: boolean) {\n this.#allowPlainText = value;\n return this;\n }\n\n onBeforeSend(description: string, hook: RequestHook) {\n this.#onBeforeSend.push([description, hook]);\n return this;\n }\n\n #setOnSend(hooks: [string, RequestHook][]) {\n this.#onBeforeSend = hooks;\n return this;\n }\n\n throwOnServerError(value: boolean) {\n this.#throwOnServerError = value;\n return this;\n }\n\n onReceiveResponse(description: string, hook: ResponseHook<unknown>) {\n this.#onAfterSend.push([description, hook]);\n return this;\n }\n\n #setOnReceive(hooks: [string, ResponseHook<unknown>][]) {\n this.#onAfterSend = hooks;\n return this;\n }\n\n build() {\n const config = new MetaConfig();\n config.schemas = this.#schemaMap.derive();\n config.requireSchema = this.#requireSchema;\n config.allowPlainText = this.#allowPlainText;\n config.onSend = this.#onBeforeSend;\n config.onReceive = this.#onAfterSend;\n return config;\n }\n\n derive() {\n return new MetaConfigBuilder()\n .schemaMap(this.#schemaMap.derive())\n .requireSchema(this.#requireSchema)\n .allowPlainText(this.#allowPlainText)\n .throwOnServerError(this.#throwOnServerError)\n .#setOnSend(this.#onBeforeSend)\n .#setOnReceive(this.#onAfterSend);\n }\n}\n","import { AutomationError } from \"@autometa/errors\";\nimport isJson from \"@stdlib/assert-is-json\";\nimport { highlight } from \"cli-highlight\";\n\nexport function transformResponse(\n allowPlainText: boolean,\n data: null | undefined | string\n) {\n if (data === null) {\n return null;\n }\n if (data === undefined) {\n return undefined;\n }\n if (data === \"\") {\n return data;\n }\n if (isJson(data)) {\n return JSON.parse(data);\n }\n if (typeof data === \"string\" && [\"true\", \"false\"].includes(data)) {\n return JSON.parse(data);\n }\n if (typeof data === \"string\" && /^\\d*\\.?\\d+$/.test(data)) {\n return JSON.parse(data);\n }\n\n if (typeof data === \"object\") {\n return data;\n }\n if (allowPlainText) {\n return data;\n }\n\n const response = highlight(data, { language: \"html\" });\n const message = [\n `Could not parse a response as json, and this request was not configured to allow plain text responses.`,\n `To allow plain text responses, use the 'allowPlainText' method on the HTTP client.`,\n \"\",\n response\n ];\n throw new AutomationError(message.join(\"\\n\"));\n}\n","import isJson from \"@stdlib/assert-is-json\";\n\n/**\n * Schema which does not care about data validation.\n *\n * Useful if `requireSchema` is set to true, but a specific\n * endpoints response does not matter.\n * @param data\n * @returns\n */\nexport function AnySchema(data: unknown) {\n return data;\n}\n\n/**\n * Schema which validates that a response is empty. This can mean\n * the data payload was `null`, `undefined` or the string `'null'`.\n *\n * Useful if `requireSchema` is set to true, but a specific\n * endpoints response should be null or not defined.\n * @param data\n * @returns\n */\nexport function EmptySchema(data: unknown) {\n if (data !== null && data !== undefined && data !== \"null\") {\n throw new Error(`Expected null but got <${typeof data}> for ${data}`);\n }\n return data === \"null\" ? null : data;\n}\n\n/**\n * Schema which validates a response was null.\n *\n * Useful if `requireSchema` is set to true, but a specific\n * endpoints response should be null.\n * @param data\n * @returns\n */\nexport function NullSchema(data: unknown) {\n if (data !== null && data !== \"null\") {\n throw new Error(`Expected null but got <${typeof data}> for ${data}`);\n }\n return null;\n}\n\n/**\n * Schema which validates a response was undefined.\n *\n * Useful if `requireSchema` is set to true, but a specific\n * endpoints response should be undefined.\n *\n * @param data\n * @returns\n */\nexport function UndefinedSchema(data: unknown) {\n if (data !== undefined) {\n throw new Error(`Expected undefined but got <${typeof data}> for ${data}`);\n }\n return undefined;\n}\n\n/**\n * Schema which validates a response was a boolean, or a string of value\n * `'true'` or `'false'`.\n *\n * Useful if `requireSchema` is set to true, but a specific\n * endpoints response should be a boolean.\n *\n * @param data\n * @returns\n */\nexport function BooleanSchema(data: unknown) {\n if (\n !(typeof data === \"boolean\") &&\n [\"true\", \"false\"].includes(String(data)) === false\n ) {\n throw new Error(`Expected boolean but got <${typeof data}> for ${data}`);\n }\n return JSON.parse(data as string);\n}\n\n/**\n * Schema which validates a response was a number, or a string of value\n * of a number.\n *\n * Useful if `requireSchema` is set to true, but a specific\n * endpoints response should be a number.\n *\n * @param data\n * @returns\n */\nexport function NumberSchema(data: unknown) {\n if (\n !(typeof data === \"number\") &&\n /^\\d*\\.?\\d+$/.test(String(data)) === false\n ) {\n throw new Error(`Expected number but got <${typeof data}> for ${data}`);\n }\n return JSON.parse(data as string);\n}\n\n/**\n * Schema which validates a response was a string.\n *\n * Useful if `requireSchema` is set to true, but a specific\n * endpoints response should be a string.\n *\n * @param data\n * @returns\n */\nexport function StringSchema(data: unknown) {\n if (typeof data !== \"string\") {\n throw new Error(`Expected string but got <${typeof data}> for ${data}`);\n }\n return data;\n}\n\n\nexport function JSONSchema<T = unknown>(data: unknown) {\n if(typeof data === 'object') {\n return data as T;\n }\n if (!isJson(data)) {\n throw new Error(`Expected JSON but got <${typeof data}> for ${data}`);\n }\n const result = JSON.parse(data);\n return result;\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGO,IAAM,eAAN,MAAM,cAA0B;AAAA,EAOrC,cAAc;AACZ,SAAK,UAAU,CAAC;AAAA,EAClB;AAAA,EAEA,OAAO,QAAW,UAA2B;AAC3C,UAAM,cAAc,IAAI,cAAgB;AACxC,WAAO,OAAO,aAAa,QAAQ;AACnC,WAAO;AAAA,EACT;AAAA,EAuBA,UAAa,aAAwD;AACnE,UAAM,QAAQ,sBAAyB,KAAK,MAAM,WAAW;AAC7D,WAAO,IAAI,oBAAoB,EAC5B,OAAO,KAAK,MAAM,EAClB,WAAW,KAAK,UAAU,EAC1B,QAAQ,KAAK,OAAO,EACpB,QAAQ,KAAK,OAAO,EACpB,KAAK,KAAK,EACV,MAAM;AAAA,EACX;AACF;AAEA,SAAS,sBAAyB,MAAe,aAAyB;AACxE,SAAO,OAAO,gBAAgB,aAAa,YAAY,IAAI,IAAI;AACjE;AAvDA;AAyDO,IAAM,uBAAN,MAAM,qBAAoB;AAAA,EAA1B;AACL,kCAAY,IAAI,aAAa;AAAA;AAAA,EAE7B,OAAO,SAAS;AACd,WAAO,IAAI,qBAAoB;AAAA,EACjC;AAAA,EAEA,SAAS;AACP,WAAO,qBAAoB,OAAO,EAC/B,KAAK,mBAAK,WAAU,IAAI,EACxB,QAAQ,mBAAK,WAAU,OAAO,EAC9B,QAAQ,mBAAK,WAAU,OAAO,EAC9B,OAAO,mBAAK,WA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AE,SAAS,OAAO,IAAI,CAAC,MAAM,OAC7C;AACA,UAAM,IAAI,MAAM,6BAA6B,OAAO,IAAI,SAAS,IAAI,EAAE;AAAA,EACzE;AACA,SAAO,KAAK,MAAM,IAAc;AAClC;AAYO,SAAS,aAAa,MAAe;AAC1C,MACE,EAAE,OAAO,SAAS,aAClB,cAAc,KAAK,OAAO,IAAI,CAAC,MAAM,OACrC;AACA,UAAM,IAAI,MAAM,4BAA4B,OAAO,IAAI,SAAS,IAAI,EAAE;AAAA,EACxE;AACA,SAAO,KAAK,MAAM,IAAc;AAClC;AAWO,SAAS,aAAa,MAAe;AAC1C,MAAI,OAAO,SAAS,UAAU;AAC5B,UAAM,IAAI,MAAM,4BAA4B,OAAO,IAAI,SAAS,IAAI,EAAE;AAAA,EACxE;AACA,SAAO;AACT;AAGO,SAAS,WAAwB,MAAe;AACrD,MAAG,OAAO,SAAS,UAAU;AAC3B,WAAO;AAAA,EACT;AACA,MAAI,CAACA,QAAO,IAAI,GAAG;AACjB,UAAM,IAAI,MAAM,0BAA0B,OAAO,IAAI,SAAS,IAAI,EAAE;AAAA,EACtE;AACA,QAAM,SAAS,KAAK,MAAM,IAAI;AAC9B,SAAO;AACT;","names":["AutomationError","_request","AutomationError","isJson"]}
1
+ {"version":3,"sources":["../../src/http-response.ts","../../src/axios-client.ts","../../src/http-client.ts","../../src/http.ts","../../src/default-client-factory.ts","../../src/http-request.ts","../../src/schema.map.ts","../../src/request-meta.config.ts","../../src/transform-response.ts","../../src/default-schema.ts"],"sourcesContent":["import { HTTPRequest } from \"./http-request\";\nimport { StatusCode } from \"./types\";\n\nexport class HTTPResponse<T = unknown> {\n status: StatusCode;\n statusText: string;\n data: T;\n headers: Record<string, string>;\n request: HTTPRequest<unknown>;\n\n constructor() {\n this.headers = {};\n }\n\n static fromRaw<T>(response: HTTPResponse<T>) {\n const newResponse = new HTTPResponse<T>();\n Object.assign(newResponse, response);\n return response;\n }\n\n /**\n * Decomposes a response, creating an exact copy of the current response,\n * but with a new data value. The data can be provided directly as is, or it\n * can be generated through a callback function which receives the current\n * response data as an argument.\n *\n * ```ts\n * const response = await http.get(\"/products\");\n *\n * // direct value\n * const products = response.data;\n * const firstProduct = response.decompose(products[0]);\n * // callback transformer\n * const secondProduct = response.decompose((products) => products[1]);\n * // callback transformer with destructuring\n * const secondProduct = response.decompose(([product]) => product);\n * ```\n * @param value\n */\n decompose<K>(value: K): HTTPResponse<K>;\n decompose<K>(transformFn: (response: T) => K): HTTPResponse<K>;\n decompose<K>(transformFnOrVal: K | ((response: T) => K)): HTTPResponse<K> {\n const value = getDecompositionValue<T>(this.data, transformFnOrVal);\n return new HTTPResponseBuilder()\n .status(this.status)\n .statusText(this.statusText)\n .headers(this.headers)\n .request(this.request)\n .data(value)\n .build() as HTTPResponse<K>;\n }\n}\n\nfunction getDecompositionValue<T>(data: unknown, transformFn: unknown): T {\n return typeof transformFn === \"function\" ? transformFn(data) : transformFn;\n}\n\nexport class HTTPResponseBuilder {\n #response = new HTTPResponse();\n\n static create() {\n return new HTTPResponseBuilder();\n }\n\n derive() {\n return HTTPResponseBuilder.create()\n .data(this.#response.data)\n .headers(this.#response.headers)\n .request(this.#response.request)\n .status(this.#response.status)\n .statusText(this.#response.statusText);\n }\n\n status(code: StatusCode) {\n this.#response.status = code;\n return this;\n }\n\n statusText(text: string) {\n this.#response.statusText = text;\n return this;\n }\n\n data<T>(data: T) {\n this.#response.data = data;\n return this;\n }\n\n headers(dict: Record<string, string>) {\n this.#response.headers = dict;\n return this;\n }\n\n header(name: string, value: string) {\n this.#response.headers[name] = value;\n return this;\n }\n\n request(request: HTTPRequest<unknown>) {\n this.#response.request = request;\n return this;\n }\n\n build() {\n return this.#response;\n }\n}\n","import { HTTPRequest } from \"./http-request\";\nimport { HTTPResponse, HTTPResponseBuilder } from \"./http-response\";\nimport { HTTPAdditionalOptions, StatusCode } from \"./types\";\nimport axios, { AxiosRequestConfig } from \"axios\";\nimport { HTTPClient } from \"./http-client\";\n\n@HTTPClient.Use()\nexport class AxiosClient extends HTTPClient {\n async request<TRequestType, TResponseType>(\n request: HTTPRequest<TRequestType>,\n options: HTTPAdditionalOptions<AxiosRequestConfig>\n ): Promise<HTTPResponse<TResponseType>> {\n const { baseUrl, route, params, headers, method, data } = request;\n const url = [baseUrl, ...route].join(\"/\");\n const axiosRequest: AxiosRequestConfig = {\n url,\n params,\n headers,\n method: method,\n data,\n validateStatus: function (status) {\n return status >= 0 && status < 600;\n },\n ...options\n };\n const response = await axios(axiosRequest);\n return HTTPResponseBuilder.create()\n .status(response.status as StatusCode)\n .statusText(response.statusText)\n .data(response.data)\n .headers(response.headers as Record<string, string>)\n .request(request)\n .build() as HTTPResponse<TResponseType>;\n }\n}\n","import { HTTPRequest } from \"./http-request\";\nimport { HTTPResponse } from \"./http-response\";\nimport { HTTPAdditionalOptions } from \"./types\";\nimport { Class } from \"@autometa/types\";\nexport let defaultClient: Class<HTTPClient>;\nexport abstract class HTTPClient {\n static Use(): (target: Class<HTTPClient>) => void\n static Use(client?: Class<HTTPClient>) {\n if (client) {\n defaultClient = client\n }\n return function (target: Class<HTTPClient>) {\n defaultClient = target\n };\n }\n abstract request<TRequestType, TResponseType>(\n request: HTTPRequest<TRequestType>,\n options?: HTTPAdditionalOptions<unknown>\n ): Promise<HTTPResponse<TResponseType>>;\n}\n","import { Fixture, INJECTION_SCOPE } from \"@autometa/injection\";\nimport { AxiosClient } from \"./axios-client\";\nimport { HTTPClient } from \"./http-client\";\nimport { defaultClientFactory } from \"./default-client-factory\";\nimport { HTTPRequest, HTTPRequestBuilder } from \"./http-request\";\nimport { HTTPResponse } from \"./http-response\";\nimport { MetaConfig, MetaConfigBuilder } from \"./request-meta.config\";\nimport {\n HTTPAdditionalOptions,\n RequestHook,\n ResponseHook,\n SchemaParser,\n StatusCode\n} from \"./types\";\nimport { transformResponse } from \"./transform-response\";\nimport { AutomationError } from \"@autometa/errors\";\n\n/**\n * The HTTP fixture allows requests to be built and sent to a server. In general,\n * there are 2 modes of operation:\n *\n * * Shared Chain: The shared chain is used to configure the client for all requests, such as\n * routes this instance will always be used. When a shared chain method is called, it returns\n * the same instance of HTTP which can be further chained to configure the client.\n * * Request Chain: The request chain is used to configure a single request, inheriting values\n * set by the shared chain. When called, a new HTTP client instance is created and inherits the values\n * set by it's parent.\n *\n * The 2 modes are intended to simplify configuring an object through an inheritance chain. For example,\n * assume we have an API with 2 controller routes, `/product` and `/seller`. We can set up a Base Client\n * which consumes the HTTP fixture and configures it with the base url of our API.\n *\n * Inheritors can further configure their HTTP instance's routes.\n *\n * ```ts\n * \\@Constructor(HTTP)\n * export class BaseClient {\n * constructor(protected readonly http: HTTP) {\n * this.http.url(\"https://api.example.com\");\n * }\n * }\n *\n * export class ProductClient extends BaseClient {\n * constructor(http: HTTP) {\n * super(http);\n * this.http.sharedRoute(\"product\");\n * }\n * getProduct(id: number) {\n * return this.http.route(id).get();\n * }\n *\n * export class SellerClient extends BaseClient {\n * constructor(http: HTTP) {\n * super(http);\n * this.http.sharedRoute(\"seller\");\n * }\n *\n * getSeller(id: number) {\n * return this.http.route(id).get();\n * }\n * }\n * ```\n *\n * 'Schemas' can also be configured. A Schema is a function or an object with a `parse` method, which\n * takes a response data payload and returns a validated object. Schemas are mapped to\n * HTTP Status Codes, and if configured to be required the request will fail if no schema is found\n * matching that code.\n *\n * Defining a schema function:\n *\n * ```\n * // user.schema.ts\n * export function UserSchema(data: unknown) {\n * if(typeof data !== \"object\") {\n * throw new Error(\"Expected an object\");\n * }\n *\n * if(typeof data.name !== \"string\") {\n * throw new Error(\"Expected a string\");\n * }\n *\n * return data as { name: string };\n * }\n *\n * // user.controller.ts\n * \\@Fixture(INJECTION_SCOPE.TRANSIENT)\n * export class UserController extends BaseController {\n * constructor(private readonly http: HTTP) {\n * super(http);\n * this.http\n * .sharedRoute(\"user\")\n * .sharedSchema(ErrorSchema, { from: 400, to: 499 });\n * }\n *\n * getUser(id: number) {\n * return this.http.route(id).schema(UserSchema, 200).get();\n * // or\n * return this.http\n * .route(id)\n * .schema(UserSchema, { from: 200, to: 299 })\n * .get();\n * // or\n * return this.http\n * .route(id)\n * .schema(UserSchema, 200, 201, 202)\n * .get();\n * }\n * }\n * ```\n *\n * Validation libraries which use a `.parse` or `.validation`, method, such as Zod or MyZod, can also be used as schemas:\n *\n * ```ts\n * // user.schema.ts\n * import { z } from \"myzod\";\n *\n * export const UserSchema = z.object({\n * name: z.string()\n * });\n *\n * // user.controller.ts\n * \\@Fixture(INJECTION_SCOPE.TRANSIENT)\n * export class UserController extends BaseController {\n * constructor(private readonly http: HTTP) {\n * super(http);\n * this.http\n * .sharedRoute(\"user\")\n * .sharedSchema(ErrorSchema, { from: 400, to: 499 })\n * }\n *\n * getUser(id: number) {\n * return this.http.route(id).schema(UserSchema, 200).get();\n * }\n * }\n * ```\n */\n@Fixture(INJECTION_SCOPE.TRANSIENT)\nexport class HTTP {\n #request: HTTPRequestBuilder<HTTPRequest<unknown>>;\n #metaConfig: MetaConfigBuilder;\n constructor(\n private readonly client: HTTPClient = defaultClientFactory(),\n builder: HTTPRequestBuilder<\n HTTPRequest<unknown>\n > = new HTTPRequestBuilder(),\n metaConfig: MetaConfigBuilder = new MetaConfigBuilder()\n ) {\n this.#request = builder.derive();\n this.#metaConfig = metaConfig.derive();\n }\n\n static create(\n client: HTTPClient = new AxiosClient(),\n builder: HTTPRequestBuilder<\n HTTPRequest<unknown>\n > = new HTTPRequestBuilder(),\n metaConfig: MetaConfigBuilder = new MetaConfigBuilder()\n ) {\n return new HTTP(client, builder, metaConfig);\n }\n\n /**\n * Sets the base url of the request for this client, such as\n * `https://api.example.com`, and could include always-used routes like\n * the api version, such as `/v1` or `/api/v1` at the end.\n *\n * ```ts\n *\n * \\@Fixture(INJECTION_SCOPE.TRANSIENT)\n * export abstract class BaseClient {\n * constructor(protected readonly http: HTTP) {\n * this.http.url(\"https://api.example.com\");\n * }\n * }\n * ```\n * @param url\n * @returns\n */\n url(url: string) {\n this.#request.url(url);\n return this;\n }\n\n /**\n * If set to true, all requests derived from this client will require a schema be defined\n * matching any response status code. If set to false, a schema will still be used for validation\n * if defined, or the unadulterated original body will be returned if no schema matches.\n *\n * @param required Whether or not a schema is required for all responses.\n * @returns This instance of HTTP.\n */\n requireSchema(required: boolean) {\n this.#metaConfig.requireSchema(required);\n return this;\n }\n\n /**\n * If set to true, all requests derived from this client will allow plain text\n * responses. If set to false, plain text responses will throw an serialization error.\n *\n * Useful when an endpoint returns a HTML or plain text response. If the plain text\n * is the value of `true` or `false`, or a number, it will be parsed into the\n * appropriate type.\n *\n * This method is a shared chain method, and will return the same instance of HTTP.\n *\n * @param allow Whether or not plain text responses are allowed.\n * @returns This instance of HTTP.\n */\n sharedAllowPlainText(allow: boolean) {\n this.#metaConfig.allowPlainText(allow);\n return this;\n }\n\n /**\n * If set to true, all requests derived from this client will allow plain text\n * responses. If set to false, plain text responses will throw an serialization error.\n *\n * Useful when an endpoint returns a HTML or plain text response. If the plain text\n * is the value of `true` or `false`, or a number, it will be parsed into the\n * appropriate type.\n *\n * This method is a request chain method, and will return a new instance of HTTP.\n *\n * @param allow Whether or not plain text responses are allowed.\n * @returns A new child instance of HTTP derived from this one.\n */\n allowPlainText(allow: boolean) {\n return HTTP.create(\n this.client,\n this.#request.derive(),\n this.#metaConfig.derive().allowPlainText(allow)\n );\n }\n\n /**\n * Attaches a route to the request, such as `/product` or `/user`. Subsequent calls\n * to this method will append the route to the existing route, such as `/product/1`.\n *\n * Numbers will be converted to strings automatically. Routes can be defined one\n * at a time or as a spread argument.\n *\n * ```ts\n * constructor(http: HTTP) {\n * super(http);\n * this.http.sharedRoute(\"user\", id).get();\n * }\n *\n * // or\n *\n * constructor(http: HTTP) {\n * super(http);\n * this.http\n * .sharedRoute(\"user\")\n * .sharedRoute(id)\n * .get();\n * }\n * ```\n *\n * This method is a shared chain method, and will return the same instance of HTTP. All\n * child clients will inherit the routes defined by this method. Useful to configure\n * in the constructor body.\n *\n * @param route A route or spread list of routes to append to the request.\n * @returns This instance of HTTP.\n */\n sharedRoute(...route: (string | number | boolean)[]) {\n this.#request.route(...route.map((r) => r.toString()));\n return this;\n }\n\n /**\n * Attaches a route to the request, such as `/product` or `/user`. Subsequent calls\n * to this method will append the route to the existing route, such as `/product/1`.\n *\n * Numbers will be converted to strings automatically. Routes can be defined one\n * at a time or as a spread argument.\n *\n * ```ts\n * getUser(id: number) {\n * return this.http.route(\"user\", id).get();\n * }\n *\n * // or\n *\n * getUser(id: number) {\n * return this.http\n * .route(\"user\")\n * .route(id)\n * .get();\n * }\n * ```\n *\n * This method is a request chain method, and will return a new instance of HTTP, inheriting\n * any routes previously defined and appending the new route. Useful to configure\n * in class methods as part of finalizing a request.\n *\n * @param route A route or spread list of routes to append to the request.\n * @returns A new child instance of HTTP derived from this one.\n */\n route(...route: (string | number | boolean)[]) {\n const mapped = route.map((r) => String(r));\n return HTTP.create(this.client, this.#request.derive().route(...mapped));\n }\n\n /**\n * Attaches a shared schema mapping for all requests by this client. Schemas are\n * mapped to HTTP Status Codes, and if configured to be required the request will fail\n * if no schema is found matching that code.\n *\n * The status code mapping can be defined as a single code, a range of codes, or a spread list.\n *\n * ```ts\n * \\@Fixture(INJECTION_SCOPE.TRANSIENT)\n * export class UserController extends BaseController {\n * constructor(private readonly http: HTTP) {\n * super(http);\n * this.http\n * .sharedRoute(\"user\")\n * .sharedSchema(UserSchema, 200)\n * .sharedSchema(EmptySchema, 201, 204)\n * .sharedSchema(ErrorSchema, { from: 400, to: 499 });\n * }\n * }\n * ```\n *\n * This method is a shared chain method, and will return the same instance of HTTP. All\n * child clients will inherit the schemas defined by this method. Useful to configure\n * in the constructor body.\n *\n * @param parser The schema parser to use for this mapping.\n * @param codes A single status code, a range of status codes, or a spread list of status codes.\n * @returns This instance of HTTP.\n */\n sharedSchema(parser: SchemaParser, ...codes: StatusCode[]): HTTP;\n sharedSchema(\n parser: SchemaParser,\n ...range: { from: StatusCode; to: StatusCode }[]\n ): HTTP;\n sharedSchema(\n parser: SchemaParser,\n ...args: (StatusCode | { from: StatusCode; to: StatusCode })[]\n ): HTTP {\n this.#metaConfig.schema(parser, ...args);\n return this;\n }\n\n /**\n * Attaches a schema mapping for this request. Schemas are\n * mapped to HTTP Status Codes, and if configured to be required the request will fail\n * if no schema is found matching that code.\n *\n * The status code mapping can be defined as a single code, a range of codes, or a spread list.\n *\n * ```ts\n * \\@Fixture(INJECTION_SCOPE.TRANSIENT)\n * export class UserController extends BaseController {\n * constructor(private readonly http: HTTP) {\n * super(http);\n * this.http\n * .sharedRoute(\"user\")\n * .schema(ErrorSchema, { from: 400, to: 499 });\n * }\n *\n * getUser(id: number) {\n * return this.http.route(id).schema(UserSchema, 200).get();\n * }\n *\n * getUsers(...ids: number[]) {\n * return this.http\n * .route(\"users\")\n * .schema(UserSchema, { from: 200, to: 299 })\n * .schema(UserSchema, 200)\n * .get();\n * }\n * ```\n *\n * This method is a request chain method, and will return a new instance of HTTP, inheriting\n * any schemas previously defined and appending the new schema. Useful to configure\n * in class methods as part of finalizing a request.\n *\n * @param parser The schema parser to use for this mapping.\n * @param codes A single status code, a range of status codes, or a spread list of status codes.\n * @returns A new child instance of HTTP derived from this one.\n */\n schema(parser: SchemaParser, ...codes: StatusCode[]): HTTP;\n schema(\n parser: SchemaParser,\n ...range: { from: StatusCode; to: StatusCode }[]\n ): HTTP;\n schema(\n parser: SchemaParser,\n ...args: (StatusCode | { from: StatusCode; to: StatusCode })[]\n ): HTTP {\n return HTTP.create(\n this.client,\n this.#request.derive(),\n this.#metaConfig.derive().schema(parser, ...args)\n );\n }\n\n /**\n * Attaches a shared query string parameter to all requests by this client. Query string\n * parameters are key-value pairs which are appended to the request url, such as\n * `https://api.example.com?name=John&age=30`.\n *\n * This method is a shared chain method, and will return the same instance of HTTP. All\n * child clients will inherit the query string parameters defined by this method. Useful to configure\n * in the constructor body.\n *\n * @param name The name of the query string parameter.\n * @param value The value of the query string parameter.\n * @returns This instance of HTTP.\n */\n sharedParam(name: string, value: Record<string, unknown>): HTTP;\n sharedParam(name: string, ...value: (string | number | boolean)[]): HTTP;\n sharedParam(\n name: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n value: any\n ): HTTP {\n this.#request.param(name, value);\n return this;\n }\n\n /**\n * `onSend` is a pre-request hook which will be executed in order of definition\n * immediately before the request is sent. This hook can be used to analyze or\n * log the request state.\n *\n * ```ts\n *\n * \\@Fixture(INJECTION_SCOPE.TRANSIENT)\n * export class UserController extends BaseController {\n * constructor(private readonly http: HTTP) {\n * super(http);\n * this.http\n * .sharedRoute(\"user\")\n * .sharedOnSend(\"log request\",\n * (request) => console.log(JSON.stringify(request, null, 2))\n * );\n * }\n * }\n * ```\n *\n * This method is a shared chain method, and will return the same instance of HTTP. All\n * child clients will inherit the onSend hooks defined by this method. Useful to configure\n * in the constructor body.\n *\n * @param description A description of the hook, used for debugging.\n * @param hook The hook to execute.\n * @returns This instance of HTTP.\n */\n sharedOnSend(description: string, hook: RequestHook) {\n this.#metaConfig.onBeforeSend(description, hook);\n return this;\n }\n\n /**\n * `onReceive` is a post-request hook which will be executed in order of definition\n * immediately after the response is received. This hook can be used to analyze or\n * log the response state.\n *\n * ```ts\n *\n * \\@Fixture(INJECTION_SCOPE.TRANSIENT)\n * export class UserController extends BaseController {\n * constructor(private readonly http: HTTP) {\n * super(http);\n * this.http\n * .sharedRoute(\"user\")\n * .sharedOnReceive(\"log response\",\n * (response) => console.log(JSON.stringify(response, null, 2))\n * );\n * }\n * }\n * ```\n *\n * This method is a shared chain method, and will return the same instance of HTTP. All\n * child clients will inherit the onReceive hooks defined by this method. Useful to configure\n * in the constructor body.\n *\n * @param description A description of the hook, used for debugging.\n * @param hook The hook to execute.\n * @returns This instance of HTTP.\n */\n sharedOnReceive(description: string, hook: ResponseHook<unknown>) {\n this.#metaConfig.onReceiveResponse(description, hook);\n return this;\n }\n\n /**\n * Attaches a query string parameter object to the request. Query string\n * parameters are key-value pairs which are appended to the request url, such as\n * `https://api.example.com?name=John&age=30`.\n *\n * This method is a shared chain method, and will return the same instance of HTTP. All\n * child clients will inherit the query string parameters defined by this method. Useful to configure\n * in the constructor body.\n *\n * ```ts\n * constructor(http: HTTP) {\n * super(http);\n * this.http\n * .sharedParams({ 'is-test': \"true\" })\n * ```\n * @param name The name of the query string parameter.\n * @param value The value of the query string parameter.\n * @returns This instance of HTTP.\n */\n sharedParams(dict: Record<string, unknown>) {\n this.#request.params(dict);\n return this;\n }\n\n /**\n * Attaches a query string parameter to the request. Query string\n * parameters are key-value pairs which are appended to the request url, such as\n * `https://api.example.com?name=John&age=30`.\n *\n * This method is a request chain method, and will return a new instance of HTTP, inheriting\n * any query string parameters previously defined and appending the new parameter. Useful to configure\n * in class methods as part of finalizing a request.\n *\n * ```ts\n * getUser(id: number) {\n * return this.http\n * .route(id)\n * .param(\"name\", \"John\")\n * .param(\"age\", 30)\n * ```\n *\n * Note: Numbers and Booleans will be converted to strings automatically.\n *\n * @param name The name of the query string parameter.\n * @param value The value of the query string parameter.\n * @returns A new child instance of HTTP derived from this one.\n */\n param(name: string, value: Record<string, unknown>): HTTP;\n param(name: string, ...value: (string | number | boolean)[]): HTTP;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n param(name: string, value: any) {\n return HTTP.create(this.client, this.#request.derive().param(name, value));\n }\n\n /**\n * Attaches a query string parameter object to the request. Query string\n * parameters are key-value pairs which are appended to the request url, such as\n * `https://api.example.com?name=John&age=30`.\n *\n * This method is a shared chain method, and will return the same instance of HTTP. All\n * child clients will inherit the query string parameters defined by this method. Useful to configure\n * in the constructor body.\n *\n * ```ts\n * getUser(id: number) {\n * return this.http\n * .route(id)\n * .param({ name: \"John\", age: \"30\" })\n *\n * @param name The name of the query string parameter.\n * @param value The value of the query string parameter.\n * @returns This instance of HTTP.\n */\n params(dict: Record<string, string>) {\n this.#request.params(dict);\n return HTTP.create(this.client, this.#request.derive().params(dict));\n }\n\n /**\n * Attaches a shared data payload to this client. The data payload is the body of the request,\n * and can be any type. If the data payload is an object, it will be serialized to JSON.\n *\n * This method is a shared chain method, and will return the same instance of HTTP. All\n * child clients will inherit the data payload defined by this method. Useful to configure\n * in the constructor body.\n *\n * @param data The data payload to attach to the request.\n * @returns This instance of HTTP.\n */\n sharedData<T>(data: T) {\n this.#request.data(data);\n return this;\n }\n\n /**\n * Attaches a shared header to this client. Headers are string:string key-value pairs which are\n * sent with the request, such as `Content-Type: application/json`.\n *\n * Numbers, Booleans and Null will be converted to string values automatically.\n *\n * A Factory function can also be provided to generate the header value at the time of request.\n *\n * This method is a shared chain method, and will return the same instance of HTTP. All\n * child clients will inherit the header defined by this method. Useful to configure\n * in the constructor body.\n *\n * @param name The name of the header.\n * @param value The value of the header.\n */\n sharedHeader(\n name: string,\n value:\n | string\n | number\n | boolean\n | null\n | (string | number | boolean)[]\n | (() => string | number | boolean | null)\n | (() => Promise<string | number | boolean | null>)\n ) {\n this.#request.header(name, value);\n return this;\n }\n\n header(\n name: string,\n value:\n | string\n | number\n | boolean\n | null\n | (string | number | boolean)[]\n | (() => string | number | boolean | null)\n | (() => Promise<string | number | boolean | null>)\n ) {\n return HTTP.create(this.client, this.#request.derive().header(name, value));\n }\n\n /**\n * Attaches a data payload to this request. The data payload is the body of the request,\n * and can be any type. If the data payload is an object, it will be serialized to JSON.\n *\n * This method is a request chain method, and will return a new instance of HTTP, inheriting\n * any data payload previously defined and appending the new payload. Useful to configure\n * in class methods as part of finalizing a request.\n *\n * @param data The data payload to attach to the request.\n * @returns A new child instance of HTTP derived from this one.\n */\n data<T>(data: T) {\n this.#request.data(data);\n return HTTP.create(this.client, this.#request.derive().data(data));\n }\n\n /**\n * `onSend` is a pre-request hook which will be executed in order of definition\n * immediately before the request is sent. This hook can be used to modify the request,\n * or to log the state of a request before final send-off.\n *\n * ```ts\n *\n * \\@Fixture(INJECTION_SCOPE.TRANSIENT)\n * export class UserController extends BaseController {\n * constructor(private readonly http: HTTP) {\n * super(http);\n * }\n *\n * getUser(id: number) {\n * return this.http\n * .route(id)\n * .onSend(\"log request\",\n * (request) => console.log(JSON.stringify(request, null, 2)\n * )\n * .get();\n * }\n * ```\n *\n * This method is a request chain method, and will return a new instance of HTTP, inheriting\n * any onSend hooks previously defined and appending the new hook. Useful to configure\n * in class methods as part of finalizing a request.\n *\n * @param description A description of the hook, used for debugging.\n * @param hook The hook to execute.\n * @returns A new child instance of HTTP derived from this one.\n */\n onSend(description: string, hook: RequestHook) {\n return HTTP.create(\n this.client,\n this.#request.derive(),\n this.#metaConfig.derive().onBeforeSend(description, hook)\n );\n }\n\n /**\n * `onReceive` is a post-request hook which will be executed in order of definition\n * immediately after the response is received. This hook can be used to modify the response,\n * or to log the state of a response after it is received.\n *\n * ```ts\n *\n * \\@Fixture(INJECTION_SCOPE.TRANSIENT)\n * export class UserController extends BaseController {\n * constructor(private readonly http: HTTP) {\n * super(http);\n * }\n *\n * getUser(id: number) {\n * return this.http\n * .route(id)\n * .onReceive(\"log response\",\n * (response) => console.log(JSON.stringify(response, null, 2)\n * )\n * .get();\n * }\n * ```\n *\n * This method is a request chain method, and will return a new instance of HTTP, inheriting\n * any onReceive hooks previously defined and appending the new hook. Useful to configure\n * in class methods as part of finalizing a request.\n *\n * @param description A description of the hook, used for debugging.\n * @param hook The hook to execute.\n * @returns A new child instance of HTTP derived from this one.\n */\n onReceive(description: string, hook: ResponseHook<unknown>) {\n return HTTP.create(\n this.client,\n this.#request.derive(),\n this.#metaConfig.derive().onReceiveResponse(description, hook)\n );\n }\n\n /**\n * Executes the current request state as a GET request.\n *\n * @param options Additional options to pass to the underlying http client, such\n * as e.g Axios configuration values.\n * @returns A promise which resolves to the response.\n */\n get<TResponseType>(options?: HTTPAdditionalOptions<unknown>) {\n return this.#makeRequest(\n this.#request.derive().method(\"GET\"),\n options\n ) as Promise<HTTPResponse<TResponseType>>;\n }\n\n /**\n * Executes the current request state as a POST request.\n *\n * @param data The data payload to attach to the request.\n * @param options Additional options to pass to the underlying http client, such\n * as e.g Axios configuration values.\n * @returns A promise which resolves to the response.\n */\n post<TResponseType>(options?: HTTPAdditionalOptions<unknown>) {\n return this.#makeRequest(\n this.#request.derive().method(\"POST\"),\n options\n ) as Promise<HTTPResponse<TResponseType>>;\n }\n\n /**\n * Executes the current request state as a DELETE request.\n *\n * @param options Additional options to pass to the underlying http client, such\n * as e.g Axios configuration values.\n * @returns A promise which resolves to the response.\n * as e.g Axios configuration values.\n */\n delete<TResponseType>(options?: HTTPAdditionalOptions<unknown>) {\n return this.#makeRequest(\n this.#request.derive().method(\"DELETE\"),\n options\n ) as Promise<HTTPResponse<TResponseType>>;\n }\n\n /**\n * Executes the current request state as a PUT request.\n *\n * @param options Additional options to pass to the underlying http client, such\n * as e.g Axios configuration values.\n * @returns A promise which resolves to the response.\n */\n put<TResponseType>(options?: HTTPAdditionalOptions<unknown>) {\n return this.#makeRequest(\n this.#request.derive().method(\"PUT\"),\n options\n ) as Promise<HTTPResponse<TResponseType>>;\n }\n /**\n * Executes the current request state as a PATCH request.\n *\n * @param options Additional options to pass to the underlying http client, such\n * as e.g Axios configuration values.\n * @returns A promise which resolves to the response.\n */\n patch<TResponseType>(options?: HTTPAdditionalOptions<unknown>) {\n return this.#makeRequest(\n this.#request.derive().method(\"PATCH\"),\n options\n ) as Promise<HTTPResponse<TResponseType>>;\n }\n\n head<TResponseType>(options?: HTTPAdditionalOptions<unknown>) {\n return this.#makeRequest(\n this.#request.derive().method(\"HEAD\"),\n options\n ) as Promise<HTTPResponse<TResponseType>>;\n }\n\n options<TResponseType>(options?: HTTPAdditionalOptions<unknown>) {\n return this.#makeRequest(\n this.#request.derive().method(\"OPTIONS\"),\n options\n ) as Promise<HTTPResponse<TResponseType>>;\n }\n\n trace<TResponseType>(options?: HTTPAdditionalOptions<unknown>) {\n return this.#makeRequest(\n this.#request.derive().method(\"TRACE\"),\n options\n ) as Promise<HTTPResponse<TResponseType>>;\n }\n\n connect<TResponseType>(options?: HTTPAdditionalOptions<unknown>) {\n return this.#makeRequest(\n this.#request.derive().method(\"CONNECT\"),\n options\n ) as Promise<HTTPResponse<TResponseType>>;\n }\n\n async #makeRequest(\n builder: HTTPRequestBuilder<HTTPRequest<unknown>>,\n options?: HTTPAdditionalOptions<unknown>\n ) {\n const request = (await builder.resolveDynamicHeaders()).build();\n const meta = this.#metaConfig.derive().build();\n await this.runOnSendHooks(meta, request);\n const result = await this.client.request<unknown, string>(request, options);\n result.data = transformResponse(meta.allowPlainText, result.data);\n await this.runOnReceiveHooks(meta, result);\n const validated = this.#validateResponse(result, meta);\n return validated;\n }\n\n private async runOnSendHooks(\n meta: MetaConfig,\n request: HTTPRequest<unknown>\n ) {\n for (const [description, hook] of meta.onSend) {\n try {\n await hook(request);\n } catch (e) {\n const cause = e as Error;\n const msg = `An error occurred while sending a request in hook: '${description}'`;\n throw new AutomationError(msg, { cause });\n }\n }\n }\n private async runOnReceiveHooks(\n meta: MetaConfig,\n response: HTTPResponse<unknown>\n ) {\n for (const [description, hook] of meta.onReceive) {\n try {\n await hook(response);\n } catch (e) {\n const cause = e as Error;\n const msg = `An error occurred while receiving a response in hook: '${description}'`;\n throw new AutomationError(msg, { cause });\n }\n }\n }\n\n #validateResponse<T>(\n response: HTTPResponse<unknown>,\n meta: MetaConfig\n ): HTTPResponse<T> {\n const { status, data } = response;\n const validated = meta.schemas.validate(\n status,\n data,\n meta.requireSchema\n ) as T;\n response.data = validated;\n return response as HTTPResponse<T>;\n }\n}\n","import { Class } from \"@autometa/types\";\nimport { defaultClient, type HTTPClient } from \"./http-client\";\n\nexport function defaultClientFactory() {\n const type = defaultClient as Class<HTTPClient>;\n return new type();\n}\n","import { RequestConfig, RequestConfigBasic } from \"./request.config\";\nimport { HTTPMethod } from \"./types\";\nimport { urlJoinP } from \"url-join-ts\";\nexport class HTTPRequest<T = unknown> implements RequestConfig<T> {\n headers: Record<string, string> = {};\n params: Record<string, string | string[] | Record<string, unknown>> = {};\n baseUrl?: string;\n route: string[] = [];\n method: HTTPMethod;\n data: T;\n\n constructor(config?: RequestConfigBasic) {\n Object.assign(this, config);\n }\n\n /**\n * Returns the full URL of the request, including the base url,\n * routes, and query parameters.\n *\n * ```ts\n * console.log(request.fullUrl())// https://example.com/foo?bar=baz?array=1,2,3\n * ```\n *\n * Note characters may be converted to escape codes. I.e (space => %20) and (comma => %2C)\n *\n * N.B this getter estimates what the url will be. The actual value\n * might be different depending on your underlying HTTPClient and\n * configuration. For example, query parameters might\n * use different array formats.\n */\n get fullUrl() {\n return urlJoinP(this.baseUrl, this.route, this.params);\n }\n\n /**\n * Returns a new independent copy of the request.\n */\n static derive(original: HTTPRequest<unknown>) {\n const request = new HTTPRequest();\n request.headers = { ...original.headers };\n request.params = { ...original.params };\n request.baseUrl = original.baseUrl;\n request.route = [...original.route];\n request.method = original.method;\n request.data = original.data;\n return request;\n }\n}\n\nexport class HTTPRequestBuilder<T extends HTTPRequest<unknown>> {\n #request: T;\n #dynamicHeaders = new Map<\n string,\n | (() => string | number | boolean | null)\n | (() => Promise<string | number | boolean | null>)\n >();\n\n constructor(request: T | (() => T) = () => new HTTPRequest() as T) {\n if (typeof request === \"function\") {\n this.#request = request();\n return;\n }\n this.#request = request;\n }\n\n static create<T extends HTTPRequest<unknown>>() {\n return new HTTPRequestBuilder<T>();\n }\n\n get request() {\n return this.#request;\n }\n\n async resolveDynamicHeaders() {\n for (const [name, value] of this.#dynamicHeaders) {\n try {\n this.#request.headers[name] = String(await value());\n } catch (e) {\n const cause = e as Error;\n const msg = `Failed to resolve dynamic header \"${name}\": \n${cause}`;\n throw new Error(msg);\n }\n }\n return this;\n }\n\n url(url: string) {\n this.#request.baseUrl = url;\n return this;\n }\n\n route(...route: string[]) {\n this.#request.route.push(...route);\n return this;\n }\n\n param(\n name: string,\n value:\n | string\n | number\n | boolean\n | (string | number | boolean)[]\n | Record<string, string | number | boolean>\n ) {\n if (Array.isArray(value)) {\n const asStr = value.map(String);\n this.#request.params[name] = asStr;\n return this;\n }\n if (!Array.isArray(value) && typeof value === \"object\") {\n this.#request.params[name] = value;\n return this;\n }\n this.#request.params[name] = String(value);\n return this;\n }\n\n params(dict: Record<string, unknown>) {\n Object.assign(this.#request.params, dict);\n return this;\n }\n\n data<T>(data: T) {\n this.#request.data = data;\n return this;\n }\n\n header(\n name: string,\n value:\n | string\n | number\n | boolean\n | null\n | (string | number | boolean)[]\n | (() => string | number | boolean | null)\n | (() => Promise<string | number | boolean | null>)\n ) {\n if (typeof value === \"function\") {\n this.#dynamicHeaders.set(name, value);\n }\n const val = Array.isArray(value) ? value.join(\",\") : String(value);\n this.#request.headers[name] = val;\n return this;\n }\n\n headers(dict: Record<string, string>) {\n Object.assign(this.#request.headers, dict);\n return this;\n }\n\n get() {\n return this.#request;\n }\n\n method(method: HTTPMethod) {\n this.#request.method = method;\n return this;\n }\n\n derive(): HTTPRequestBuilder<T> {\n const request = HTTPRequest.derive(this.#request);\n return new HTTPRequestBuilder(request) as HTTPRequestBuilder<T>;\n }\n\n build(): HTTPRequest<T> {\n return this.#request as HTTPRequest<T>;\n }\n}\n","import { SchemaParser, StatusCode } from \"./types\";\nexport class SchemaMap {\n #map: Map<StatusCode, SchemaParser>;\n constructor(map?: Map<StatusCode, SchemaParser> | SchemaMap) {\n if (map instanceof SchemaMap) {\n this.#map = new Map(map.#map);\n return;\n }\n this.#map = new Map(map);\n }\n\n derive() {\n return new SchemaMap(this.#map);\n }\n\n registerStatus(parser: SchemaParser, ...codes: StatusCode[]) {\n codes.forEach((code) => {\n if (this.#map.has(code)) {\n const msg = `Status code ${code} is already registered with a parser`;\n throw new Error(msg);\n }\n this.#map.set(code, parser);\n });\n }\n\n registerRange(parser: SchemaParser, from: StatusCode, to: StatusCode) {\n for (let i = from; i <= to; i++) {\n if (this.#map.has(i)) {\n throw new Error(`Status code ${i} is already registered with a parser`);\n }\n this.#map.set(i, parser);\n }\n }\n\n validate(status: StatusCode, data: unknown, requireSchema: boolean) {\n const parser = this.getParser(status, requireSchema);\n if (\"parse\" in parser) {\n return parser.parse(data);\n }\n if('validate' in parser) {\n return parser.validate(data);\n }\n try {\n return parser(data);\n } catch (e) {\n const msg = `Failed to schema parse response data for status code ${status} with data:\n \n${JSON.stringify(data, null, 2)}}`;\n throw new Error(msg);\n }\n }\n\n getParser(status: StatusCode, requireSchema: boolean) {\n const parser = this.#map.get(status);\n if (!parser && requireSchema) {\n const msg = `No parser registered for status code ${status} but 'requireSchema' is true`;\n throw new Error(msg);\n }\n if (parser) {\n return parser;\n }\n return (data: unknown) => data;\n }\n\n toObject() {\n return Object.fromEntries(this.#map) as Record<StatusCode, SchemaParser>;\n }\n}\n","import { SchemaMap } from \"./schema.map\";\nimport { RequestHook, ResponseHook, SchemaParser, StatusCode } from \"./types\";\n\nexport interface SchemaConfig {\n schemas: SchemaMap;\n requireSchema: boolean;\n allowPlainText: boolean;\n}\n\nexport interface HTTPHooks {\n onSend: [string, RequestHook][];\n onReceive: [string, ResponseHook<unknown>][];\n}\n\n// export type MetaConfig = SchemaConfig & HTTPHooks;\n\nexport class MetaConfig implements SchemaConfig, HTTPHooks {\n schemas: SchemaMap;\n requireSchema: boolean;\n allowPlainText: boolean;\n onSend: [string, RequestHook][] = [];\n onReceive: [string, ResponseHook<unknown>][] = [];\n throwOnServerError: boolean;\n}\n\nexport class MetaConfigBuilder {\n #schemaMap = new SchemaMap();\n #requireSchema = false;\n #allowPlainText = false;\n #onBeforeSend: [string, RequestHook][] = [];\n #onAfterSend: [string, ResponseHook<unknown>][] = [];\n #throwOnServerError = false;\n\n schemaMap(map: SchemaMap) {\n this.#schemaMap = map;\n return this;\n }\n\n schema(parser: SchemaParser, ...codes: StatusCode[]): MetaConfigBuilder;\n schema(\n parser: SchemaParser,\n ...range: { from: StatusCode; to: StatusCode }[]\n ): MetaConfigBuilder;\n schema(\n parser: SchemaParser,\n ...args: (StatusCode | { from: StatusCode; to: StatusCode })[]\n ): MetaConfigBuilder;\n schema(\n parser: SchemaParser,\n ...args: (StatusCode | { from: StatusCode; to: StatusCode })[]\n ) {\n args.forEach((arg) => {\n if (typeof arg === \"number\") {\n this.#schemaMap.registerStatus(parser, arg);\n } else {\n this.#schemaMap.registerRange(parser, arg.from, arg.to);\n }\n });\n\n return this;\n }\n\n requireSchema(value: boolean) {\n this.#requireSchema = value;\n return this;\n }\n\n allowPlainText(value: boolean) {\n this.#allowPlainText = value;\n return this;\n }\n\n onBeforeSend(description: string, hook: RequestHook) {\n this.#onBeforeSend.push([description, hook]);\n return this;\n }\n\n #setOnSend(hooks: [string, RequestHook][]) {\n this.#onBeforeSend = hooks;\n return this;\n }\n\n throwOnServerError(value: boolean) {\n this.#throwOnServerError = value;\n return this;\n }\n\n onReceiveResponse(description: string, hook: ResponseHook<unknown>) {\n this.#onAfterSend.push([description, hook]);\n return this;\n }\n\n #setOnReceive(hooks: [string, ResponseHook<unknown>][]) {\n this.#onAfterSend = hooks;\n return this;\n }\n\n build() {\n const config = new MetaConfig();\n config.schemas = this.#schemaMap.derive();\n config.requireSchema = this.#requireSchema;\n config.allowPlainText = this.#allowPlainText;\n config.onSend = this.#onBeforeSend;\n config.onReceive = this.#onAfterSend;\n return config;\n }\n\n derive() {\n return new MetaConfigBuilder()\n .schemaMap(this.#schemaMap.derive())\n .requireSchema(this.#requireSchema)\n .allowPlainText(this.#allowPlainText)\n .throwOnServerError(this.#throwOnServerError)\n .#setOnSend(this.#onBeforeSend)\n .#setOnReceive(this.#onAfterSend);\n }\n}\n","import { AutomationError } from \"@autometa/errors\";\nimport isJson from \"@stdlib/assert-is-json\";\nimport { highlight } from \"cli-highlight\";\n\nexport function transformResponse(\n allowPlainText: boolean,\n data: null | undefined | string\n) {\n if (data === null) {\n return null;\n }\n if (data === undefined) {\n return undefined;\n }\n if (data === \"\") {\n return data;\n }\n if (isJson(data)) {\n return JSON.parse(data);\n }\n if (typeof data === \"string\" && [\"true\", \"false\"].includes(data)) {\n return JSON.parse(data);\n }\n if (typeof data === \"string\" && /^\\d*\\.?\\d+$/.test(data)) {\n return JSON.parse(data);\n }\n\n if (typeof data === \"object\") {\n return data;\n }\n if (allowPlainText) {\n return data;\n }\n\n const response = highlight(data, { language: \"html\" });\n const message = [\n `Could not parse a response as json, and this request was not configured to allow plain text responses.`,\n `To allow plain text responses, use the 'allowPlainText' method on the HTTP client.`,\n \"\",\n response\n ];\n throw new AutomationError(message.join(\"\\n\"));\n}\n","import isJson from \"@stdlib/assert-is-json\";\n\n/**\n * Schema which does not care about data validation.\n *\n * Useful if `requireSchema` is set to true, but a specific\n * endpoints response does not matter.\n * @param data\n * @returns\n */\nexport function AnySchema(data: unknown) {\n return data;\n}\n\n/**\n * Schema which validates that a response is empty. This can mean\n * the data payload was `null`, `undefined` or the string `'null'`.\n *\n * Useful if `requireSchema` is set to true, but a specific\n * endpoints response should be null or not defined.\n * @param data\n * @returns\n */\nexport function EmptySchema(data: unknown) {\n if (data !== null && data !== undefined && data !== \"null\") {\n throw new Error(`Expected null but got <${typeof data}> for ${data}`);\n }\n return data === \"null\" ? null : data;\n}\n\n/**\n * Schema which validates a response was null.\n *\n * Useful if `requireSchema` is set to true, but a specific\n * endpoints response should be null.\n * @param data\n * @returns\n */\nexport function NullSchema(data: unknown) {\n if (data !== null && data !== \"null\") {\n throw new Error(`Expected null but got <${typeof data}> for ${data}`);\n }\n return null;\n}\n\n/**\n * Schema which validates a response was undefined.\n *\n * Useful if `requireSchema` is set to true, but a specific\n * endpoints response should be undefined.\n *\n * @param data\n * @returns\n */\nexport function UndefinedSchema(data: unknown) {\n if (data !== undefined) {\n throw new Error(`Expected undefined but got <${typeof data}> for ${data}`);\n }\n return undefined;\n}\n\n/**\n * Schema which validates a response was a boolean, or a string of value\n * `'true'` or `'false'`.\n *\n * Useful if `requireSchema` is set to true, but a specific\n * endpoints response should be a boolean.\n *\n * @param data\n * @returns\n */\nexport function BooleanSchema(data: unknown) {\n if (\n !(typeof data === \"boolean\") &&\n [\"true\", \"false\"].includes(String(data)) === false\n ) {\n throw new Error(`Expected boolean but got <${typeof data}> for ${data}`);\n }\n return JSON.parse(data as string);\n}\n\n/**\n * Schema which validates a response was a number, or a string of value\n * of a number.\n *\n * Useful if `requireSchema` is set to true, but a specific\n * endpoints response should be a number.\n *\n * @param data\n * @returns\n */\nexport function NumberSchema(data: unknown) {\n if (\n !(typeof data === \"number\") &&\n /^\\d*\\.?\\d+$/.test(String(data)) === false\n ) {\n throw new Error(`Expected number but got <${typeof data}> for ${data}`);\n }\n return JSON.parse(data as string);\n}\n\n/**\n * Schema which validates a response was a string.\n *\n * Useful if `requireSchema` is set to true, but a specific\n * endpoints response should be a string.\n *\n * @param data\n * @returns\n */\nexport function StringSchema(data: unknown) {\n if (typeof data !== \"string\") {\n throw new Error(`Expected string but got <${typeof data}> for ${data}`);\n }\n return data;\n}\n\n\nexport function JSONSchema<T = unknown>(data: unknown) {\n if(typeof data === 'object') {\n return data as T;\n }\n if (!isJson(data)) {\n throw new Error(`Expected JSON but got <${typeof data}> for ${data}`);\n }\n const result = JSON.parse(data);\n return result;\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGO,IAAM,eAAN,MAAM,cAA0B;AAAA,EAOrC,cAAc;AACZ,SAAK,UAAU,CAAC;AAAA,EAClB;AAAA,EAEA,OAAO,QAAW,UAA2B;AAC3C,UAAM,cAAc,IAAI,cAAgB;AACxC,WAAO,OAAO,aAAa,QAAQ;AACnC,WAAO;AAAA,EACT;AAAA,EAuBA,UAAa,kBAA6D;AACxE,UAAM,QAAQ,sBAAyB,KAAK,MAAM,gBAAgB;AAClE,WAAO,IAAI,oBAAoB,EAC5B,OAAO,KAAK,MAAM,EAClB,WAAW,KAAK,UAAU,EAC1B,QAAQ,KAAK,OAAO,EACpB,QAAQ,KAAK,OAAO,EACpB,KAAK,KAAK,EACV,MAAM;AAAA,EACX;AACF;AAEA,SAAS,sBAAyB,MAAe,aAAyB;AACxE,SAAO,OAAO,gBAAgB,aAAa,YAAY,IAAI,IAAI;AACjE;AAvDA;AAyDO,IAAM,uBAAN,MAAM,qBAAoB;AAAA,EAA1B;AACL,kCAAY,IAAI,aAAa;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SAAS,QAAQ,SAAS,QAAQ;AACpC,UAAM,IAAI,MAAM,0BAA0B,OAAO,IAAI,SAAS,IAAI,EAAE;AAAA,EACtE;AACA,SAAO;AACT;AAWO,SAAS,gBAAgB,MAAe;AAC7C,MAAI,SAAS,QAAW;AACtB,UAAM,IAAI,MAAM,+BAA+B,OAAO,IAAI,SAAS,IAAI,EAAE;AAAA,EAC3E;AACA,SAAO;AACT;AAYO,SAAS,cAAc,MAAe;AAC3C,MACE,EAAE,OAAO,SAAS,cAClB,CAAC,QAAQ,OAAO,EAAE,SAAS,OAAO,IAAI,CAAC,MAAM,OAC7C;AACA,UAAM,IAAI,MAAM,6BAA6B,OAAO,IAAI,SAAS,IAAI,EAAE;AAAA,EACzE;AACA,SAAO,KAAK,MAAM,IAAc;AAClC;AAYO,SAAS,aAAa,MAAe;AAC1C,MACE,EAAE,OAAO,SAAS,aAClB,cAAc,KAAK,OAAO,IAAI,CAAC,MAAM,OACrC;AACA,UAAM,IAAI,MAAM,4BAA4B,OAAO,IAAI,SAAS,IAAI,EAAE;AAAA,EACxE;AACA,SAAO,KAAK,MAAM,IAAc;AAClC;AAWO,SAAS,aAAa,MAAe;AAC1C,MAAI,OAAO,SAAS,UAAU;AAC5B,UAAM,IAAI,MAAM,4BAA4B,OAAO,IAAI,SAAS,IAAI,EAAE;AAAA,EACxE;AACA,SAAO;AACT;AAGO,SAAS,WAAwB,MAAe;AACrD,MAAG,OAAO,SAAS,UAAU;AAC3B,WAAO;AAAA,EACT;AACA,MAAI,CAACA,QAAO,IAAI,GAAG;AACjB,UAAM,IAAI,MAAM,0BAA0B,OAAO,IAAI,SAAS,IAAI,EAAE;AAAA,EACtE;AACA,QAAM,SAAS,KAAK,MAAM,IAAI;AAC9B,SAAO;AACT;","names":["AutomationError","_request","AutomationError","isJson"]}
package/dist/index.d.cts CHANGED
@@ -68,7 +68,23 @@ interface RequestBaseConfig {
68
68
  baseUrl?: string;
69
69
  route?: string[];
70
70
  method: HTTPMethod;
71
- fullUrl(): string;
71
+ /**
72
+ * Returns the full URL of the request, including the base url,
73
+ * routes, and query parameters.
74
+ *
75
+ * ```ts
76
+ * console.log(request.fullUrl())// https://example.com/foo?bar=baz?array=1,2,3
77
+ * ```
78
+ *
79
+ * Note characters may be converted to escape codes. I.e (space => %20) and (comma => %2C)
80
+ *
81
+ * N.B this method estimates what the url will be. The actual value
82
+ * might be different depending on your underlying HTTPClient and
83
+ * configuration. For example, query parameters might
84
+ * use different array formats.
85
+ * @returns The full url of the request
86
+ */
87
+ get fullUrl(): string;
72
88
  }
73
89
  interface RequestData<T = unknown> {
74
90
  data: T;
@@ -94,12 +110,12 @@ declare class HTTPRequest<T = unknown> implements RequestConfig<T> {
94
110
  *
95
111
  * Note characters may be converted to escape codes. I.e (space => %20) and (comma => %2C)
96
112
  *
97
- * N.B this method estimates what the url will be. The actual value
113
+ * N.B this getter estimates what the url will be. The actual value
98
114
  * might be different depending on your underlying HTTPClient and
99
115
  * configuration. For example, query parameters might
100
116
  * use different array formats.
101
117
  */
102
- fullUrl(): string;
118
+ get fullUrl(): string;
103
119
  /**
104
120
  * Returns a new independent copy of the request.
105
121
  */
@@ -110,13 +126,13 @@ declare class HTTPRequestBuilder<T extends HTTPRequest<unknown>> {
110
126
  constructor(request?: T | (() => T));
111
127
  static create<T extends HTTPRequest<unknown>>(): HTTPRequestBuilder<T>;
112
128
  get request(): T;
113
- resolveDynamicHeaders(): this;
129
+ resolveDynamicHeaders(): Promise<this>;
114
130
  url(url: string): this;
115
131
  route(...route: string[]): this;
116
132
  param(name: string, value: string | number | boolean | (string | number | boolean)[] | Record<string, string | number | boolean>): this;
117
133
  params(dict: Record<string, unknown>): this;
118
134
  data<T>(data: T): this;
119
- header(name: string, value: string | number | boolean | null | (() => string | number | boolean | null)): this;
135
+ header(name: string, value: string | number | boolean | null | (string | number | boolean)[] | (() => string | number | boolean | null) | (() => Promise<string | number | boolean | null>)): this;
120
136
  headers(dict: Record<string, string>): this;
121
137
  get(): T;
122
138
  method(method: HTTPMethod): this;
@@ -891,8 +907,8 @@ declare class HTTP {
891
907
  * @param name The name of the header.
892
908
  * @param value The value of the header.
893
909
  */
894
- sharedHeader(name: string, value: string | number | boolean | null | (() => string | number | boolean | null)): this;
895
- header(name: string, value: string): HTTP;
910
+ sharedHeader(name: string, value: string | number | boolean | null | (string | number | boolean)[] | (() => string | number | boolean | null) | (() => Promise<string | number | boolean | null>)): this;
911
+ header(name: string, value: string | number | boolean | null | (string | number | boolean)[] | (() => string | number | boolean | null) | (() => Promise<string | number | boolean | null>)): HTTP;
896
912
  /**
897
913
  * Attaches a data payload to this request. The data payload is the body of the request,
898
914
  * and can be any type. If the data payload is an object, it will be serialized to JSON.
package/dist/index.d.ts CHANGED
@@ -68,7 +68,23 @@ interface RequestBaseConfig {
68
68
  baseUrl?: string;
69
69
  route?: string[];
70
70
  method: HTTPMethod;
71
- fullUrl(): string;
71
+ /**
72
+ * Returns the full URL of the request, including the base url,
73
+ * routes, and query parameters.
74
+ *
75
+ * ```ts
76
+ * console.log(request.fullUrl())// https://example.com/foo?bar=baz?array=1,2,3
77
+ * ```
78
+ *
79
+ * Note characters may be converted to escape codes. I.e (space => %20) and (comma => %2C)
80
+ *
81
+ * N.B this method estimates what the url will be. The actual value
82
+ * might be different depending on your underlying HTTPClient and
83
+ * configuration. For example, query parameters might
84
+ * use different array formats.
85
+ * @returns The full url of the request
86
+ */
87
+ get fullUrl(): string;
72
88
  }
73
89
  interface RequestData<T = unknown> {
74
90
  data: T;
@@ -94,12 +110,12 @@ declare class HTTPRequest<T = unknown> implements RequestConfig<T> {
94
110
  *
95
111
  * Note characters may be converted to escape codes. I.e (space => %20) and (comma => %2C)
96
112
  *
97
- * N.B this method estimates what the url will be. The actual value
113
+ * N.B this getter estimates what the url will be. The actual value
98
114
  * might be different depending on your underlying HTTPClient and
99
115
  * configuration. For example, query parameters might
100
116
  * use different array formats.
101
117
  */
102
- fullUrl(): string;
118
+ get fullUrl(): string;
103
119
  /**
104
120
  * Returns a new independent copy of the request.
105
121
  */
@@ -110,13 +126,13 @@ declare class HTTPRequestBuilder<T extends HTTPRequest<unknown>> {
110
126
  constructor(request?: T | (() => T));
111
127
  static create<T extends HTTPRequest<unknown>>(): HTTPRequestBuilder<T>;
112
128
  get request(): T;
113
- resolveDynamicHeaders(): this;
129
+ resolveDynamicHeaders(): Promise<this>;
114
130
  url(url: string): this;
115
131
  route(...route: string[]): this;
116
132
  param(name: string, value: string | number | boolean | (string | number | boolean)[] | Record<string, string | number | boolean>): this;
117
133
  params(dict: Record<string, unknown>): this;
118
134
  data<T>(data: T): this;
119
- header(name: string, value: string | number | boolean | null | (() => string | number | boolean | null)): this;
135
+ header(name: string, value: string | number | boolean | null | (string | number | boolean)[] | (() => string | number | boolean | null) | (() => Promise<string | number | boolean | null>)): this;
120
136
  headers(dict: Record<string, string>): this;
121
137
  get(): T;
122
138
  method(method: HTTPMethod): this;
@@ -891,8 +907,8 @@ declare class HTTP {
891
907
  * @param name The name of the header.
892
908
  * @param value The value of the header.
893
909
  */
894
- sharedHeader(name: string, value: string | number | boolean | null | (() => string | number | boolean | null)): this;
895
- header(name: string, value: string): HTTP;
910
+ sharedHeader(name: string, value: string | number | boolean | null | (string | number | boolean)[] | (() => string | number | boolean | null) | (() => Promise<string | number | boolean | null>)): this;
911
+ header(name: string, value: string | number | boolean | null | (string | number | boolean)[] | (() => string | number | boolean | null) | (() => Promise<string | number | boolean | null>)): HTTP;
896
912
  /**
897
913
  * Attaches a data payload to this request. The data payload is the body of the request,
898
914
  * and can be any type. If the data payload is an object, it will be serialized to JSON.
package/dist/index.js CHANGED
@@ -90,8 +90,8 @@ var HTTPResponse = class _HTTPResponse {
90
90
  Object.assign(newResponse, response);
91
91
  return response;
92
92
  }
93
- decompose(transformFn) {
94
- const value = getDecompositionValue(this.data, transformFn);
93
+ decompose(transformFnOrVal) {
94
+ const value = getDecompositionValue(this.data, transformFnOrVal);
95
95
  return new HTTPResponseBuilder().status(this.status).statusText(this.statusText).headers(this.headers).request(this.request).data(value).build();
96
96
  }
97
97
  };
@@ -208,12 +208,12 @@ var HTTPRequest = class _HTTPRequest {
208
208
  *
209
209
  * Note characters may be converted to escape codes. I.e (space => %20) and (comma => %2C)
210
210
  *
211
- * N.B this method estimates what the url will be. The actual value
211
+ * N.B this getter estimates what the url will be. The actual value
212
212
  * might be different depending on your underlying HTTPClient and
213
213
  * configuration. For example, query parameters might
214
214
  * use different array formats.
215
215
  */
216
- fullUrl() {
216
+ get fullUrl() {
217
217
  return (0, import_url_join_ts.urlJoinP)(this.baseUrl, this.route, this.params);
218
218
  }
219
219
  /**
@@ -247,10 +247,10 @@ var _HTTPRequestBuilder = class _HTTPRequestBuilder {
247
247
  get request() {
248
248
  return __privateGet(this, _request);
249
249
  }
250
- resolveDynamicHeaders() {
250
+ async resolveDynamicHeaders() {
251
251
  for (const [name, value] of __privateGet(this, _dynamicHeaders)) {
252
252
  try {
253
- __privateGet(this, _request).headers[name] = String(value());
253
+ __privateGet(this, _request).headers[name] = String(await value());
254
254
  } catch (e) {
255
255
  const cause = e;
256
256
  const msg = `Failed to resolve dynamic header "${name}":
@@ -291,9 +291,10 @@ ${cause}`;
291
291
  }
292
292
  header(name, value) {
293
293
  if (typeof value === "function") {
294
- value = value();
294
+ __privateGet(this, _dynamicHeaders).set(name, value);
295
295
  }
296
- __privateGet(this, _request).headers[name] = String(value);
296
+ const val = Array.isArray(value) ? value.join(",") : String(value);
297
+ __privateGet(this, _request).headers[name] = val;
297
298
  return this;
298
299
  }
299
300
  headers(dict) {
@@ -1011,7 +1012,7 @@ _request2 = new WeakMap();
1011
1012
  _metaConfig = new WeakMap();
1012
1013
  _makeRequest = new WeakSet();
1013
1014
  makeRequest_fn = async function(builder, options) {
1014
- const request = builder.resolveDynamicHeaders().build();
1015
+ const request = (await builder.resolveDynamicHeaders()).build();
1015
1016
  const meta = __privateGet(this, _metaConfig).derive().build();
1016
1017
  await this.runOnSendHooks(meta, request);
1017
1018
  const result = await this.client.request(request, options);