{"version":3,"file":"index.cjs","names":["ZMimeTypeApplication","ZHttpMethod","ZHttpRequestBuilder","_request","duplicate","other","headers","structuredClone","method","url","_method","body","undefined","get","post","json","put","delete","patch","options","head","timeout","ms","header","key","value","content","type","bind","JSON","copy","build","ZHttpCodeClient","ZHttpCodeClientNames","ZHttpCodeClientDescriptions","ZHttpCodeInformationalResponse","ZHttpCodeInformationalResponseNames","ZHttpCodeInformationalResponseDescriptions","ZHttpCodeRedirection","ZHttpCodeRedirectionNames","ZHttpCodeRedirectionDescriptions","ZHttpCodeServer","ZHttpCodeServerNames","ZHttpCodeServerDescriptions","ZHttpCodeSuccess","ZHttpCodeSuccessNames","ZHttpCodeSuccessDescriptions","ZHttpCodeClientDescriptions","ZHttpCodeClientNames","ZHttpCodeInformationalResponseDescriptions","ZHttpCodeInformationalResponseNames","ZHttpCodeRedirectionDescriptions","ZHttpCodeRedirectionNames","ZHttpCodeServerDescriptions","ZHttpCodeServerNames","ZHttpCodeSuccessDescriptions","ZHttpCodeSuccessNames","ZHttpCodeCategory","ZHttpCodeSeverity","getHttpCodeName","code","getHttpCodeDescription","getHttpCodeSeverity","_code","getHttpCodeCategory","ZHttpCodeSuccess","ZHttpResultBuilder","_result","data","status","OK","headers","code","build","isBodyInit","obj","Blob","ArrayBuffer","isView","FormData","URLSearchParams","ReadableStream","toBodyInit","JSON","stringify","fromContentType","res","contentType","headers","get","startsWith","endsWith","json","formData","text","blob","getHttpCodeName","ZHttpResultError","Error","status","headers","data","result","fetch","ZHttpCodeClient","ZHttpCodeServer","ZHttpResultBuilder","isBodyInit","fromContentType","ZHttpResultError","ZHttpService","request","req","res","url","method","body","JSON","stringify","headers","redirect","data","result","status","build","ok","Promise","resolve","reject","e","message","InternalServerError","code","NotFound","ZHttpCodeClient","ZHttpResultBuilder","ZHttpResultError","ZHttpServiceMock","_mapping","set","endpoint","verb","invoke","request","req","endpointConfig","url","result","method","notFound","status","NotFound","build","Promise","reject","errorThreshold","intermediate","resolve"],"sources":["../src/request/http-request.mts","../src/result/http-code-client.mts","../src/result/http-code-informational-response.mts","../src/result/http-code-redirection.mts","../src/result/http-code-server.mts","../src/result/http-code-success.mts","../src/result/http-code.mts","../src/result/http-result.mts","../src/util/body-init.mts","../src/util/content-type.mts","../src/service/http-result-error.mts","../src/service/http-service.mts","../src/service/http-service-mock.mts"],"sourcesContent":["import { ZMimeTypeApplication } from \"@zthun/webigail-url\";\n\n/**\n * Represents an available method for an http invocation.\n */\nexport enum ZHttpMethod {\n  /**\n   * GET\n   *\n   * Used for reads\n   */\n  Get = \"GET\",\n\n  /**\n   * PUT\n   *\n   * Used for updates and can combine creates.\n   */\n  Put = \"PUT\",\n\n  /**\n   * POST\n   *\n   * Use for create.\n   */\n  Post = \"POST\",\n\n  /**\n   * DELETE.\n   *\n   * Used for....delete..duh.\n   */\n  Delete = \"DELETE\",\n\n  /**\n   * PATCH.\n   *\n   * Used for updates but only\n   * partials of objects.\n   */\n  Patch = \"PATCH\",\n\n  /**\n   * OPTIONS\n   *\n   * Used to retrieve the available methods and\n   * accessors for a single api.  Normally used\n   * by the browser.\n   */\n  Options = \"OPTIONS\",\n\n  /**\n   * HEAD\n   *\n   * Used for metadata.\n   */\n  Head = \"HEAD\",\n}\n\n/**\n * Represents a http request.\n */\nexport interface IZHttpRequest<TBody = any> {\n  /**\n   * The method, or verb, to invoke the request with.\n   */\n  method: ZHttpMethod;\n\n  /**\n   * The url to target.\n   */\n  url: string;\n\n  /**\n   * The post body.\n   *\n   * Only should really be used for POST style\n   * calls which accept a body.\n   */\n  body?: TBody;\n\n  /**\n   * Request headers.\n   */\n  headers?: Record<string, string>;\n\n  /**\n   * The timeout before the rest method fails\n   */\n  timeout?: number;\n}\n\n/**\n * Represents a builder for an http request.\n */\nexport class ZHttpRequestBuilder<TBody = any> {\n  private _request: IZHttpRequest<TBody>;\n\n  /**\n   * Duplicates a request, keeping it's structure intact.\n   *\n   * The underlying headers will be duplicated, but everything\n   * else will be a shallow copy to preserve the body in the\n   * case that it is a blob or other binary structure.\n   *\n   * @param other -\n   *        The request to duplicate.\n   *\n   * @returns\n   *        The duplicated object.\n   */\n  public static duplicate<TBody>(\n    other: IZHttpRequest<TBody>,\n  ): IZHttpRequest<TBody> {\n    return { ...other, headers: structuredClone(other.headers) };\n  }\n\n  /**\n   * Initializes a new instance of this object.\n   */\n  public constructor() {\n    this._request = {\n      method: ZHttpMethod.Get,\n      url: \"\",\n    };\n  }\n\n  /**\n   * Sets the method.\n   *\n   * @param method -\n   *        The method to set.\n   * @param body -\n   *        The post, put, or patch body.\n   *\n   * @returns\n   *        This object.\n   */\n  private _method(method: ZHttpMethod, body?: TBody): this {\n    this._request.method = method;\n\n    this._request.body = body;\n\n    if (this._request.body === undefined) {\n      delete this._request.body;\n    }\n    return this;\n  }\n\n  /**\n   * Constructs a get request.\n   *\n   * @returns\n   *        This object.\n   */\n  public get() {\n    return this._method(ZHttpMethod.Get);\n  }\n\n  /**\n   * Constructs a post request.\n   *\n   * @returns\n   *        This object.\n   */\n  public post(body?: TBody) {\n    return this._method(ZHttpMethod.Post, body).json();\n  }\n\n  /**\n   * Constructs a put request.\n   *\n   * @returns\n   *        This object.\n   */\n  public put(body?: TBody) {\n    return this._method(ZHttpMethod.Put, body).json();\n  }\n\n  /**\n   * Constructs a delete request.\n   *\n   * @returns\n   *        This object.\n   */\n  public delete() {\n    return this._method(ZHttpMethod.Delete);\n  }\n\n  /**\n   * Constructs a patch request.\n   *\n   * @returns\n   *        This object.\n   */\n  public patch(body?: TBody) {\n    return this._method(ZHttpMethod.Patch, body).json();\n  }\n\n  /**\n   * Constructs a options request.\n   *\n   * @returns\n   *        This object.\n   */\n  public options() {\n    return this._method(ZHttpMethod.Options);\n  }\n\n  /**\n   * Constructs a head request.\n   *\n   * @returns\n   *        This object.\n   */\n  public head() {\n    return this._method(ZHttpMethod.Head);\n  }\n\n  /**\n   * Sets the url to make the request from.\n   *\n   * @param url -\n   *        The url to make the request to.\n   *\n   * @returns\n   *        This object.\n   */\n  public url(url: string): this {\n    this._request.url = url;\n    return this;\n  }\n\n  /**\n   * Sets the timeout for the url.\n   *\n   * @param ms -\n   *        The total number of milliseconds to wait.\n   *\n   * @returns\n   *        The object.\n   */\n  public timeout(ms: number): this {\n    this._request.timeout = ms;\n    return this;\n  }\n\n  /**\n   * Sets the headers.\n   *\n   * @param headers -\n   *        The headers to set.\n   *\n   * @returns\n   *        This object.\n   */\n  public headers(headers: Record<string, string>): this {\n    this._request.headers = headers;\n    return this;\n  }\n\n  /**\n   * Sets an individual header.\n   *\n   * @param key -\n   *        The header key to set.\n   * @param value -\n   *        The value to set.\n   *\n   * @returns\n   *        This object.\n   */\n  public header(key: string, value: string | number | boolean | null): this {\n    this._request.headers = this._request.headers || {};\n\n    if (value == null) {\n      delete this._request.headers[key];\n    } else {\n      this._request.headers[key] = `${value}`;\n    }\n\n    return this;\n  }\n\n  /**\n   * Sets the content type header.\n   *\n   * @param type -\n   *        The content mime type.\n   *\n   * @returns\n   *        This object.\n   */\n  public content(type: string) {\n    return this.header(\"Content-Type\", type);\n  }\n\n  /**\n   * Sets the content type to json.\n   *\n   * @returns\n   *        This object.\n   */\n  public json = this.content.bind(this, ZMimeTypeApplication.JSON);\n\n  /**\n   * Copies other to this object.\n   *\n   * @param other -\n   *        The request to copy.\n   *\n   * @returns\n   *        This object.\n   */\n  public copy(other: IZHttpRequest): this {\n    this._request = ZHttpRequestBuilder.duplicate(other);\n    return this;\n  }\n\n  /**\n   * Returns the constructed request.\n   *\n   * @returns\n   *        The constructed request.\n   */\n  public build(): IZHttpRequest {\n    return ZHttpRequestBuilder.duplicate(this._request);\n  }\n}\n","/**\n * This class of status code is intended for situations in which the error seems to have been caused by the client.\n *\n * Except when responding to a HEAD request, the server should include an entity containing an explanation\n * of the error situation, and whether it is a temporary or permanent condition. These status codes are applicable\n * to any request method. User agents should display any included entity to the user.\n */\nexport enum ZHttpCodeClient {\n  /**\n   * The server cannot or will not process the request due to an apparent client error\n   * (e.g., malformed request syntax, size too large, invalid request message framing,\n   * or deceptive request routing).\n   */\n  BadRequest = 400,\n  /**\n   * Similar to 403 Forbidden, but specifically for use when authentication is required and has failed\n   * or has not yet been provided.\n   *\n   * The response must include a WWW-Authenticate header field containing a challenge applicable to the\n   * requested resource. See Basic access authentication and Digest access authentication.  401\n   * semantically means \"unauthenticated\",[35] i.e. the user does not have the necessary credentials.\n   *\n   * Note: Some sites issue HTTP 401 when an IP address is banned from the website (usually the website domain)\n   * and that specific address is refused permission to access a website.\n   */\n  Unauthorized = 401,\n  /**\n   * Reserved for future use.\n   *\n   * The original intention was that this code might be used as part of some form of digital cash or\n   * micro-payment scheme, as proposed for example by GNU Taler, but that has not yet happened, and\n   * this code is not usually used. Google Developers API uses this status if a particular developer\n   * has exceeded the daily limit on requests\n   */\n  PaymentRequired = 402,\n  /**\n   * The request was valid, but the server is refusing action.\n   *\n   * The user might not have the necessary permissions for a resource, or may need an account of some sort.\n   */\n  Forbidden = 403,\n  /**\n   * The requested resource could not be found but may be available in the future.\n   *\n   * Subsequent requests by the client are permissible.\n   */\n  NotFound = 404,\n  /**\n   * A request method is not supported for the requested resource; for example, a GET\n   * request on a form that requires data to be presented via POST, or a PUT request on\n   * a read-only resource.\n   */\n  MethodNotAllowed = 405,\n  /**\n   * The requested resource is capable of generating only content not acceptable according\n   * to the Accept headers sent in the request.\n   */\n  NotAcceptable = 406,\n  /**\n   * The client must first authenticate itself with the proxy.\n   */\n  ProxyAuthenticationRequired = 407,\n  /**\n   * The server timed out waiting for the request.\n   *\n   * According to HTTP specifications: \"The client did not produce a request within the\n   * time that the server was prepared to wait. The client MAY repeat the request without\n   * modifications at any later time.\n   */\n  RequestTimeout = 408,\n  /**\n   * Indicates that the request could not be processed because of conflict in the request, such\n   * as an edit conflict between multiple simultaneous updates.\n   */\n  Conflict = 409,\n  /**\n   * Indicates that the resource requested is no longer available and will not be available again.\n   *\n   * This should be used when a resource has been intentionally removed and the resource should be\n   * purged. Upon receiving a 410 status code, the client should not request the resource in the\n   * future. Clients such as search engines should remove the resource from their indices.  Most use\n   * cases do not require clients and search engines to purge the resource, and a \"404 Not Found\" may\n   * be used instead.\n   */\n  Gone = 410,\n  /**\n   * The request did not specify the length of its content, which is required by the requested resource.\n   */\n  LengthRequired = 411,\n  /**\n   * The server does not meet one of the preconditions that the requester put on the request.\n   */\n  PreconditionFailed = 412,\n  /**\n   * The request is larger than the server is willing or able to process. Previously called\n   * \"Request Entity Too Large\".\n   */\n  PayloadTooLarge = 413,\n  /**\n   * The URI provided was too long for the server to process.\n   *\n   * Often the result of too much data being encoded as a query-string of\n   * a GET request, in which case it should be converted to a POST request.\n   * Called \"Request-URI Too Long\" previously.\n   */\n  URITooLong = 414,\n  /**\n   * The request entity has a media type which the server or resource does not support.\n   *\n   * For example, the client uploads an image as image/svg+xml, but the server requires that\n   * images use a different format.\n   */\n  UnsupportedMediaType = 415,\n  /**\n   * The client has asked for a portion of the file (byte serving), but the server cannot supply that portion.\n   *\n   * For example, if the client asked for a part of the file that lies beyond the end of the file.\n   * Called \"Requested Range Not Satisfiable\" previously.\n   */\n  RangeNotSatisfiable = 416,\n  /**\n   * The server cannot meet the requirements of the Expect request-header field.\n   */\n  ExpectationFailed = 417,\n  /**\n   * This code was defined in 1998 as one of the traditional IETF April Fools' jokes, in RFC 2324, Hyper\n   * Text Coffee Pot Control Protocol, and is not expected to be implemented by actual HTTP servers.\n   *\n   * The RFC specifies this code should be returned by teapots requested to brew coffee.  This HTTP\n   * status is used as an Easter egg in some websites, including Google.com.\n   */\n  ImATeapot = 418,\n  /**\n   * The request was directed at a server that is not able to produce a response[53] (for example because of connection reuse).\n   */\n  MisdirectedRequest = 421,\n  /**\n   * The request was well-formed but was unable to be followed due to semantic errors.\n   */\n  UnProcessableEntity = 422,\n  /**\n   * The resource that is being accessed is locked.\n   */\n  Locked = 423,\n  /**\n   * The request failed because it depended on another request and that request failed.\n   */\n  FailedDependency = 424,\n  /**\n   * The client should switch to a different protocol such as TLS/1.0, given in the Upgrade header field.\n   */\n  UpgradeRequired = 426,\n  /**\n   * The origin server requires the request to be conditional.\n   *\n   * Intended to prevent the 'lost update' problem, where a client GETs a resource's state, modifies it,\n   * and PUTs it back to the server, when meanwhile a third party has modified the state on the server,\n   * leading to a conflict.\n   */\n  PreconditionRequired = 428,\n  /**\n   * The user has sent too many requests in a given amount of time. Intended for use with rate-limiting schemes.\n   */\n  TooManyRequests = 429,\n  /**\n   * The server is unwilling to process the request because either an individual header field, or all the\n   * header fields collectively, are too large.[\n   */\n  RequestHeaderFieldsTooLarge = 431,\n  /**\n   * A server operator has received a legal demand to deny access to a resource or to a set of resources that includes the\n   * requested resource.\n   *\n   * The code 451 was chosen as a reference to the novel Fahrenheit 451.\n   */\n  UnavailableForLegalReasons = 451,\n}\n\n/**\n * English friendly names of the codes.\n */\nexport const ZHttpCodeClientNames: Record<ZHttpCodeClient, string> = {\n  [ZHttpCodeClient.BadRequest]: \"Bad Request\",\n  [ZHttpCodeClient.Unauthorized]: \"Unauthorized\",\n  [ZHttpCodeClient.PaymentRequired]: \"Payment Required\",\n  [ZHttpCodeClient.Forbidden]: \"Forbidden\",\n  [ZHttpCodeClient.NotFound]: \"Not Found\",\n  [ZHttpCodeClient.MethodNotAllowed]: \"Method not Allowed\",\n  [ZHttpCodeClient.NotAcceptable]: \"Not Acceptable\",\n  [ZHttpCodeClient.ProxyAuthenticationRequired]:\n    \"Proxy Authentication Required\",\n  [ZHttpCodeClient.RequestTimeout]: \"Request Timeout\",\n  [ZHttpCodeClient.Conflict]: \"Conflict\",\n  [ZHttpCodeClient.Gone]: \"Gone\",\n  [ZHttpCodeClient.LengthRequired]: \"Length Required\",\n  [ZHttpCodeClient.PreconditionFailed]: \"Precondition Failed\",\n  [ZHttpCodeClient.PayloadTooLarge]: \"Payload Too Large\",\n  [ZHttpCodeClient.URITooLong]: \"URI Too Long\",\n  [ZHttpCodeClient.UnsupportedMediaType]: \"Unsupported Media Type\",\n  [ZHttpCodeClient.RangeNotSatisfiable]: \"Range Not Satisfiable\",\n  [ZHttpCodeClient.ExpectationFailed]: \"Expectation Failed\",\n  [ZHttpCodeClient.ImATeapot]: \"I am a Teapot\",\n  [ZHttpCodeClient.MisdirectedRequest]: \"Misdirected Requested\",\n  [ZHttpCodeClient.UnProcessableEntity]: \"Entity Not Processable\",\n  [ZHttpCodeClient.Locked]: \"Locked\",\n  [ZHttpCodeClient.FailedDependency]: \"Failed Dependency\",\n  [ZHttpCodeClient.UpgradeRequired]: \"Upgrade Required\",\n  [ZHttpCodeClient.PreconditionRequired]: \"Precondition Required\",\n  [ZHttpCodeClient.TooManyRequests]: \"Too Many Requests\",\n  [ZHttpCodeClient.RequestHeaderFieldsTooLarge]:\n    \"Request Header Fields Too Large\",\n  [ZHttpCodeClient.UnavailableForLegalReasons]: \"Unavailable for Legal Reasons\",\n};\n\n/**\n * English friendly descriptions of HttpClientCodes\n */\nexport const ZHttpCodeClientDescriptions: Record<ZHttpCodeClient, string> = {\n  [ZHttpCodeClient.BadRequest]: \"A bad request was sent.\",\n  [ZHttpCodeClient.Unauthorized]:\n    \"You are not authenticated and cannot view this content.\",\n  [ZHttpCodeClient.PaymentRequired]: \"Payment is required\",\n  [ZHttpCodeClient.Forbidden]: \"You are not authorized to view this content.\",\n  [ZHttpCodeClient.NotFound]:\n    \"The resource you are looking for could not be found.\",\n  [ZHttpCodeClient.MethodNotAllowed]:\n    \"The requested operation was not allowed.\",\n  [ZHttpCodeClient.NotAcceptable]:\n    \"The requested resource is not capable of generating the content for you.\",\n  [ZHttpCodeClient.ProxyAuthenticationRequired]:\n    \"You must first authenticate your self with the proxy.\",\n  [ZHttpCodeClient.RequestTimeout]:\n    \"The server timed out waiting for a request.  Please try again.\",\n  [ZHttpCodeClient.Conflict]:\n    \"There was a conflict with request.  Try something else.\",\n  [ZHttpCodeClient.Gone]: \"The resource you requested is no longer available.\",\n  [ZHttpCodeClient.LengthRequired]:\n    \"Your request did not specify the length of its content, which is required by the requested resource.\",\n  [ZHttpCodeClient.PreconditionFailed]:\n    \"The server did not meet the requirements that was required to meet the request.\",\n  [ZHttpCodeClient.PayloadTooLarge]:\n    \"The request is too large and the server cannot handle it.\",\n  [ZHttpCodeClient.URITooLong]:\n    \"The URI provided was too long for the server to process.\",\n  [ZHttpCodeClient.UnsupportedMediaType]:\n    \"The media type requested is not supported by the server.\",\n  [ZHttpCodeClient.RangeNotSatisfiable]:\n    \"A portion of the file was requested by the server cannot supply said portion.\",\n  [ZHttpCodeClient.ExpectationFailed]:\n    \"The server cannot meet the requirements of the expectation made of it.\",\n  [ZHttpCodeClient.ImATeapot]:\n    \"Short and stout.  Here is my handle, here is my spout.  When I get all steamed up, hear me shout.  Tip me over and pour me out!\",\n  [ZHttpCodeClient.MisdirectedRequest]:\n    \"The request was directed at the server, but the server cannot produce a response.\",\n  [ZHttpCodeClient.UnProcessableEntity]:\n    \"The request was well-formed but was unable to be followed due to semantic errors.\",\n  [ZHttpCodeClient.Locked]: \"The resource that is being accessed is locked.\",\n  [ZHttpCodeClient.FailedDependency]:\n    \"The request failed because it depended on another request and that request failed.\",\n  [ZHttpCodeClient.UpgradeRequired]:\n    \"The client needs to switch to a different protocol.\",\n  [ZHttpCodeClient.PreconditionRequired]:\n    \"The origin server requires the request to be conditional.\",\n  [ZHttpCodeClient.TooManyRequests]:\n    \"The user has sent too many requests in a given amount of time.\",\n  [ZHttpCodeClient.RequestHeaderFieldsTooLarge]:\n    \"The request cannot be processed because the collective header fields are too large.\",\n  [ZHttpCodeClient.UnavailableForLegalReasons]: \"Call your lawyer!\",\n};\n","/**\n * An informational response indicates that the request was received and understood.\n *\n * It is issued on a provisional basis while request processing continues. It alerts the\n * client to wait for a final response. The message consists only of the status line and\n * optional header fields, and is terminated by an empty line. As the HTTP/1.0 standard\n * did not define any 1xx status codes, servers must not[note 1] send a 1xx response to\n * an HTTP/1.0 compliant client except under experimental conditions.[4]\n */\nexport enum ZHttpCodeInformationalResponse {\n  /**\n   * The server has received the request headers and the client should proceed to send the\n   * request body (in the case of a request for which a body needs to be sent; for example, a\n   * POST request).\n   *\n   * Sending a large request body to a server after a request has been rejected\n   * for inappropriate headers would be inefficient. To have a server check the request's headers,\n   * a client must send Expect: 100-continue as a header in its initial request and receive a 100 Continue status\n   * code in response before sending the body. If the client receives an error code such as 403 (Forbidden) or 405\n   * (Method Not Allowed) then it shouldn't send the request's body. The response 417 Expectation Failed indicates\n   * that the request should be repeated without the Expect header as it indicates that the server doesn't support\n   * expectations (this is the case, for example, of HTTP/1.0 servers).\n   */\n  Continue = 100,\n  /**\n   * The requester has asked the server to switch protocols and the server has agreed to do so.\n   */\n  SwitchingProtocols = 101,\n  /**\n   * A WebDAV request may contain many sub-requests involving file operations, requiring a long time to\n   * complete the request. This code indicates that the server has received and is processing the request,\n   * but no response is available yet.  This prevents the client from timing out and assuming the request was lost.\n   */\n  Processing = 102,\n  /**\n   * Used to return some response headers before final HTTP message.\n   */\n  EarlyHints = 103,\n}\n\n/**\n * English friendly names of the codes.\n */\nexport const ZHttpCodeInformationalResponseNames: Record<\n  ZHttpCodeInformationalResponse,\n  string\n> = {\n  [ZHttpCodeInformationalResponse.Continue]: \"Continue\",\n  [ZHttpCodeInformationalResponse.SwitchingProtocols]: \"Switching Protocols\",\n  [ZHttpCodeInformationalResponse.Processing]: \"Processing\",\n  [ZHttpCodeInformationalResponse.EarlyHints]: \"Early Hints\",\n};\n\n/**\n * English friendly descriptions of the codes.\n */\nexport const ZHttpCodeInformationalResponseDescriptions: Record<\n  ZHttpCodeInformationalResponse,\n  string\n> = {\n  [ZHttpCodeInformationalResponse.Continue]:\n    \"The client should continue to send the request body.\",\n  [ZHttpCodeInformationalResponse.SwitchingProtocols]:\n    \"The requestor has asked the server to switch protocols and the server has agreed to do so.\",\n  [ZHttpCodeInformationalResponse.Processing]:\n    \"The server has received and is processing the request, but a response is not available yet.\",\n  [ZHttpCodeInformationalResponse.EarlyHints]:\n    \"There are some early response headers available for you before the final message.\",\n};\n","/**\n * This class of status code indicates the client must take additional action to complete the request.\n *\n * Many of these status codes are used in URL redirection. A user agent may carry out the additional\n * action with no user interaction only if the method used in the second request is GET or HEAD.\n * A user agent may automatically redirect a request. A user agent should detect and intervene\n * to prevent cyclical redirects.\n */\nexport enum ZHttpCodeRedirection {\n  /**\n   * Indicates multiple options for the resource from which the client may choose\n   * (via agent-driven content negotiation).\n   *\n   * For example, this code could be used to present multiple video format options, to\n   * list files with different filename extensions, or to suggest word-sense disambiguation.\n   */\n  MultipleChoices = 300,\n  /**\n   * This and all future requests should be directed to the given URI.\n   */\n  MovedPermanently = 301,\n  /**\n   * Tells the client to look at (browse to) another url. 302 has been superseded by 303 and 307.\n   * This is an example of industry practice contradicting the standard. The HTTP/1.0 specification (RFC 1945)\n   * required the client to perform a temporary redirect (the original describing phrase was \"Moved Temporarily\"),\n   * [22] but popular browsers implemented 302 with the functionality of a 303 See Other. Therefore, HTTP/1.1\n   * added status codes 303 and 307 to distinguish between the two behaviors.[23] However, some Web applications\n   * and frameworks use the 302 status code as if it were the 303.\n   */\n  Found = 302,\n  /**\n   * The response to the request can be found under another URI using the GET method.\n   *\n   * When received in response to a POST (or PUT/DELETE), the client should presume\n   * that the server has received the data and should issue a new GET request to\n   * the given URI.\n   */\n  SeeOther = 303,\n  /**\n   * Indicates that the resource has not been modified since the version specified by the request headers\n   * If-Modified-Since or If-None-Match. In such case, there is no need to retransmit the resource since\n   * the client still has a previously-downloaded copy.\n   */\n  NotModified = 304,\n  /**\n   * The requested resource is available only through a proxy, the address for which is provided in the response.\n   *\n   * Many HTTP clients (such as Mozilla[27] and Internet Explorer) do not correctly handle responses with\n   * this status code, primarily for security reasons.\n   */\n  UseProxy = 305,\n  /**\n   * No longer used. Originally meant \"Subsequent requests should use the specified proxy.\n   */\n  SwitchProxy = 306,\n  /**\n   * In this case, the request should be repeated with another URI; however, future requests\n   * should still use the original URI.\n   *\n   * In contrast to how 302 was historically implemented, the request method is not allowed to be\n   * changed when reissuing the original request. For example, a POST request should be repeated using\n   * another POST request.\n   */\n  TemporaryRedirect = 307,\n  /**\n   * The request and all future requests should be repeated using another URI.\n   *\n   * 307 and 308 parallel the behaviors of 302 and 301, but do not allow the HTTP method to change.\n   * So, for example, submitting a form to a permanently redirected resource may continue smoothly.\n   */\n  PermanentRedirect = 308,\n}\n\n/**\n * English friendly names of the redirection codes.\n */\nexport const ZHttpCodeRedirectionNames: Record<ZHttpCodeRedirection, string> = {\n  [ZHttpCodeRedirection.MultipleChoices]: \"Multiple Choices\",\n  [ZHttpCodeRedirection.MovedPermanently]: \"Moved Permanently\",\n  [ZHttpCodeRedirection.Found]: \"Found\",\n  [ZHttpCodeRedirection.SeeOther]: \"See Other\",\n  [ZHttpCodeRedirection.NotModified]: \"Not Modified\",\n  [ZHttpCodeRedirection.UseProxy]: \"Use Proxy\",\n  [ZHttpCodeRedirection.SwitchProxy]: \"Switch Proxy\",\n  [ZHttpCodeRedirection.TemporaryRedirect]: \"Temporary Redirect\",\n  [ZHttpCodeRedirection.PermanentRedirect]: \"Permanent Redirect\",\n};\n\n/**\n * English friendly descriptions of the redirection codes.\n */\nexport const ZHttpCodeRedirectionDescriptions: Record<\n  ZHttpCodeRedirection,\n  string\n> = {\n  [ZHttpCodeRedirection.MultipleChoices]:\n    \"Indicates multiple options for the resource from which the client may choose.\",\n  [ZHttpCodeRedirection.MovedPermanently]:\n    \"This and all future requests should be directed to the given URI.\",\n  [ZHttpCodeRedirection.Found]: \"Tells the client to look at another url\",\n  [ZHttpCodeRedirection.SeeOther]:\n    \"The response to the request can be found under another URI using the GET method.\",\n  [ZHttpCodeRedirection.NotModified]:\n    \"Indicates that the resource has not been modified since the version specified by the request headers If-Modified-Since or If-None-Match.\",\n  [ZHttpCodeRedirection.UseProxy]:\n    \"The requested resource is available only through a proxy, the address for which is provided in the response.\",\n  [ZHttpCodeRedirection.SwitchProxy]:\n    'No longer used. Originally meant \"Subsequent requests should use the specified proxy.',\n  [ZHttpCodeRedirection.TemporaryRedirect]:\n    \"In this case, the request should be repeated with another URI; however, future requests should still use the original URI.\",\n  [ZHttpCodeRedirection.PermanentRedirect]:\n    \"The request and all future requests should be repeated using another URI.\",\n};\n","/**\n * The server failed to fulfil a request.\n *\n * Response status codes beginning with the digit \"5\" indicate\n * cases in which the server is aware that it has encountered an\n * error or is otherwise incapable of performing the request. Except\n * when responding to a HEAD request, the server should include an entity\n * containing an explanation of the error situation, and indicate whether it\n * is a temporary or permanent condition. Likewise, user agents should\n * display any included entity to the user. These response codes are applicable\n * to any request method.\n */\nexport enum ZHttpCodeServer {\n  /**\n   * A generic error message, given when an unexpected condition was encountered\n   * and no more specific message is suitable.\n   */\n  InternalServerError = 500,\n  /**\n   * The server either does not recognize the request method, or it lacks the ability to\n   * fulfil the request. Usually this implies future availability (e.g., a new feature of\n   * a web-service API).\n   */\n  NotImplemented = 501,\n  /**\n   * The server was acting as a gateway or proxy and received an invalid response\n   * from the upstream server.\n   */\n  BadGateway = 502,\n  /**\n   * The server is currently unavailable (because it is overloaded or down for maintenance).\n   * Generally, this is a temporary state.\n   */\n  ServiceUnavailable = 503,\n  /**\n   * The server was acting as a gateway or proxy and did not receive a timely response from\n   * the upstream server.\n   */\n  GatewayTimeout = 504,\n  /**\n   * The server does not support the HTTP protocol version used in the request.\n   */\n  HttpVersionNotSupported = 505,\n  /**\n   * Transparent content negotiation for the request results in a circular reference.\n   */\n  VariantAlsoNegotiates = 506,\n  /**\n   * The server is unable to store the representation needed to complete the request.\n   */\n  InsufficientStorage = 507,\n  /**\n   * The server detected an infinite loop while processing the request.\n   */\n  LoopDetected = 508,\n  /**\n   * Further extensions to the request are required for the server to fulfil it.\n   */\n  NotExtended = 510,\n  /**\n   * The client needs to authenticate to gain network access. Intended for use by\n   * intercepting proxies used to control access to the network.\n   */\n  NetworkAuthenticationRequired = 511,\n}\n\n/**\n * English friendly names of the server codes.\n */\nexport const ZHttpCodeServerNames: Record<ZHttpCodeServer, string> = {\n  [ZHttpCodeServer.InternalServerError]: \"Internal Server Error\",\n  [ZHttpCodeServer.NotImplemented]: \"Not Implemented\",\n  [ZHttpCodeServer.BadGateway]: \"Bad Gateway\",\n  [ZHttpCodeServer.ServiceUnavailable]: \"Service Unavailable\",\n  [ZHttpCodeServer.GatewayTimeout]: \"Gateway Timeout\",\n  [ZHttpCodeServer.HttpVersionNotSupported]: \"HTTP Version Not Supported\",\n  [ZHttpCodeServer.VariantAlsoNegotiates]: \"Variant Also Negotiates\",\n  [ZHttpCodeServer.InsufficientStorage]: \"Insufficient Storage\",\n  [ZHttpCodeServer.LoopDetected]: \"Loop Detected\",\n  [ZHttpCodeServer.NotExtended]: \"Not Extended\",\n  [ZHttpCodeServer.NetworkAuthenticationRequired]:\n    \"Network Authentication Required\",\n};\n\n/**\n * English friendly names of the server codes.\n */\nexport const ZHttpCodeServerDescriptions: Record<ZHttpCodeServer, string> = {\n  [ZHttpCodeServer.InternalServerError]:\n    \"An unexpected condition was encountered on the server.\",\n  [ZHttpCodeServer.NotImplemented]:\n    \"The server either does not recognize the request method, or it lacks the ability to fulfil the request. Usually this implies future availability (e.g., a new feature of a web-service API).\",\n  [ZHttpCodeServer.BadGateway]:\n    \" The server was acting as a gateway or proxy and received an invalid response from the upstream server.\",\n  [ZHttpCodeServer.ServiceUnavailable]:\n    \"The server is currently unavailable (because it is overloaded or down for maintenance). Generally, this is a temporary state.\",\n  [ZHttpCodeServer.GatewayTimeout]:\n    \"The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.\",\n  [ZHttpCodeServer.HttpVersionNotSupported]:\n    \"The server does not support the HTTP protocol version used in the request.\",\n  [ZHttpCodeServer.VariantAlsoNegotiates]:\n    \" Transparent content negotiation for the request results in a circular reference.\",\n  [ZHttpCodeServer.InsufficientStorage]:\n    \"The server is unable to store the representation needed to complete the request.\",\n  [ZHttpCodeServer.LoopDetected]:\n    \"The server detected an infinite loop while processing the request.\",\n  [ZHttpCodeServer.NotExtended]:\n    \"Further extensions to the request are required for the server to fulfil it.\",\n  [ZHttpCodeServer.NetworkAuthenticationRequired]:\n    \"The client needs to authenticate to gain network access.\",\n};\n","/**\n * This class of status codes indicates the action requested by\n * the client was received, understood and accepted.\n */\nexport enum ZHttpCodeSuccess {\n  /**\n   * Standard response for successful HTTP requests.\n   *\n   * The actual response will depend on the request method used. In a GET\n   * request, the response will contain an entity corresponding to the\n   * requested resource. In a POST request, the response will contain an\n   * entity describing or containing the result of the action.\n   */\n  OK = 200,\n\n  /**\n   * The request has been fulfilled, resulting in the creation of a new resource.\n   */\n  Created = 201,\n\n  /**\n   * The request has been accepted for processing, but the processing has not been completed.\n   *\n   * The request might or might not be eventually acted upon, and may be disallowed when processing occurs.\n   */\n  Accepted = 202,\n\n  /**\n   * The server is a transforming proxy (e.g. a Web accelerator) that received a 200 OK from its origin,\n   * but is returning a modified version of the origin's response.\n   */\n  NonAuthoritativeInformation = 203,\n\n  /**\n   * The server successfully processed the request and is not returning any content.\n   */\n  NoContent = 204,\n\n  /**\n   * The server successfully processed the request, but is not returning any content.\n   *\n   * Unlike a 204 response, this response requires that the requester reset the document view.\n   */\n  ResetContent = 205,\n\n  /**\n   * The server is delivering only part of the resource (byte serving) due to a range header\n   * sent by the client.\n   *\n   * The range header is used by HTTP clients to enable resuming of interrupted downloads, or\n   * split a download into multiple simultaneous streams.\n   */\n  PartialContent = 206,\n\n  /**\n   * The message body that follows is by default an XML message and can contain a number of separate\n   * response codes, depending on how many sub-requests were made.\n   */\n  MultiStatus = 207,\n\n  /**\n   * The members of a DAV binding have already been enumerated in a preceding part of the\n   * response, and are not being included again.\n   */\n  AlreadyReported = 208,\n\n  /**\n   * The server has fulfilled a request for the resource, and the response is a representation of the result\n   * of one or more instance-manipulations applied to the current instance.\n   */\n  IMUsed = 226,\n}\n\n/**\n * Friendly english names of success codes.\n */\nexport const ZHttpCodeSuccessNames: Record<ZHttpCodeSuccess, string> = {\n  [ZHttpCodeSuccess.OK]: \"OK\",\n  [ZHttpCodeSuccess.Created]: \"Created\",\n  [ZHttpCodeSuccess.Accepted]: \"Accepted\",\n  [ZHttpCodeSuccess.NonAuthoritativeInformation]:\n    \"Non-Authoritative Information\",\n  [ZHttpCodeSuccess.NoContent]: \"No Content\",\n  [ZHttpCodeSuccess.ResetContent]: \"Reset Content\",\n  [ZHttpCodeSuccess.PartialContent]: \"Partial Content\",\n  [ZHttpCodeSuccess.MultiStatus]: \"Multi Status\",\n  [ZHttpCodeSuccess.AlreadyReported]: \"Already Reported\",\n  [ZHttpCodeSuccess.IMUsed]: \"IM Used\",\n};\n\n/**\n * Friendly english descriptions of success codes.\n */\nexport const ZHttpCodeSuccessDescriptions: Record<ZHttpCodeSuccess, string> = {\n  [ZHttpCodeSuccess.OK]: \"The request was successful.\",\n  [ZHttpCodeSuccess.Created]:\n    \"The request has been fulfilled, resulting in the creation of a new resource.\",\n  [ZHttpCodeSuccess.Accepted]:\n    \"The request has been accepted for processing, but the processing has not been completed.\",\n  [ZHttpCodeSuccess.NonAuthoritativeInformation]:\n    \"The server is a transforming proxy that received an OK from its origin,but is returning a modified version of the response.\",\n  [ZHttpCodeSuccess.NoContent]:\n    \"The server successfully processed the request and is not returning any content.\",\n  [ZHttpCodeSuccess.ResetContent]:\n    \"The server successfully processed the request, but is not returning any content.  The document view must be refreshed.\",\n  [ZHttpCodeSuccess.PartialContent]:\n    \"he server is delivering only part of the resource due to a range header sent by the client.\",\n  [ZHttpCodeSuccess.MultiStatus]:\n    \"The message body that follows is by default an XML message and can contain a number of separate response codes, depending on how many sub-requests were made.\",\n  [ZHttpCodeSuccess.AlreadyReported]:\n    \"The members of a DAV binding have already been enumerated in a preceding part of the response, and are not being included again.\",\n  [ZHttpCodeSuccess.IMUsed]:\n    \"The server has fulfilled a request for the resource, and the response is a representation of the result of one or more instance-manipulations applied to the current instance.\",\n};\n","import type { ZHttpCodeClient } from \"./http-code-client.mjs\";\nimport {\n  ZHttpCodeClientDescriptions,\n  ZHttpCodeClientNames,\n} from \"./http-code-client.mjs\";\nimport type { ZHttpCodeInformationalResponse } from \"./http-code-informational-response.mjs\";\nimport {\n  ZHttpCodeInformationalResponseDescriptions,\n  ZHttpCodeInformationalResponseNames,\n} from \"./http-code-informational-response.mjs\";\nimport type { ZHttpCodeRedirection } from \"./http-code-redirection.mjs\";\nimport {\n  ZHttpCodeRedirectionDescriptions,\n  ZHttpCodeRedirectionNames,\n} from \"./http-code-redirection.mjs\";\nimport type { ZHttpCodeServer } from \"./http-code-server.mjs\";\nimport {\n  ZHttpCodeServerDescriptions,\n  ZHttpCodeServerNames,\n} from \"./http-code-server.mjs\";\nimport type { ZHttpCodeSuccess } from \"./http-code-success.mjs\";\nimport {\n  ZHttpCodeSuccessDescriptions,\n  ZHttpCodeSuccessNames,\n} from \"./http-code-success.mjs\";\n\n/**\n * Represents a category of http code.\n */\nexport type ZHttpCode =\n  | ZHttpCodeInformationalResponse\n  | ZHttpCodeSuccess\n  | ZHttpCodeRedirection\n  | ZHttpCodeClient\n  | ZHttpCodeServer;\n\n/**\n * Represents the category name for an http code.\n */\nexport enum ZHttpCodeCategory {\n  /**\n   * Error codes 100-199.\n   */\n  InformationalResponse = \"Informational Response\",\n  /**\n   * Error codes 200-299.\n   */\n  Success = \"Success\",\n  /**\n   * Error codes 300-399.\n   */\n  Redirection = \"Redirection\",\n  /**\n   * Error codes 400-499.\n   */\n  Client = \"Client Error\",\n  /**\n   * Error codes 500-599.\n   */\n  Server = \"Server Error\",\n}\n\n/**\n * Represents a classification of severity for a code.\n */\nexport enum ZHttpCodeSeverity {\n  /**\n   * Covers information response (100-199) and redirection codes (300-399).\n   */\n  Info = \"info\",\n  /**\n   * Covers the success codes (200-299)\n   */\n  Success = \"success\",\n  /**\n   * Covers client errors (400-499).\n   */\n  Warning = \"warning\",\n  /**\n   * Covers server errors (500-599).\n   */\n  Error = \"error\",\n}\n\n/**\n * Gets the english friendly name of a code.\n *\n * @param code -\n *        The code to retrieve the name for.\n *\n * @returns\n *        The english friendly name of a code.\n */\nexport function getHttpCodeName(code: ZHttpCode): string {\n  return (\n    ZHttpCodeInformationalResponseNames[code] ||\n    ZHttpCodeSuccessNames[code] ||\n    ZHttpCodeRedirectionNames[code] ||\n    ZHttpCodeClientNames[code] ||\n    ZHttpCodeServerNames[code]\n  );\n}\n\n/**\n * Gets the english friendly description of a code.\n *\n * @param code -\n *        The code to retrieve the description for.\n *\n * @returns\n *        The english friendly description of a code.\n */\nexport function getHttpCodeDescription(code: ZHttpCode) {\n  return (\n    ZHttpCodeInformationalResponseDescriptions[code] ||\n    ZHttpCodeSuccessDescriptions[code] ||\n    ZHttpCodeRedirectionDescriptions[code] ||\n    ZHttpCodeClientDescriptions[code] ||\n    ZHttpCodeServerDescriptions[code]\n  );\n}\n\n/**\n * Gets the severity of a code.\n *\n * @param code -\n *        The severity of a code.\n *\n * @returns\n *        The severity of a code.\n */\nexport function getHttpCodeSeverity(code: ZHttpCode): ZHttpCodeSeverity {\n  const _code = +code;\n\n  if (_code >= 200 && _code < 300) {\n    return ZHttpCodeSeverity.Success;\n  }\n\n  if (_code >= 400 && _code < 500) {\n    return ZHttpCodeSeverity.Warning;\n  }\n\n  if (_code >= 500) {\n    return ZHttpCodeSeverity.Error;\n  }\n\n  return ZHttpCodeSeverity.Info;\n}\n\n/**\n * Gets the category of a code.\n *\n * @param code -\n *        The category of a code.\n *\n * @returns\n *        The code category.\n */\nexport function getHttpCodeCategory(code: ZHttpCode): ZHttpCodeCategory {\n  const _code = +code;\n\n  if (_code >= 100 && _code < 200) {\n    return ZHttpCodeCategory.InformationalResponse;\n  }\n\n  if (_code >= 200 && _code < 300) {\n    return ZHttpCodeCategory.Success;\n  }\n\n  if (_code >= 300 && _code < 400) {\n    return ZHttpCodeCategory.Redirection;\n  }\n\n  if (_code >= 400 && _code < 500) {\n    return ZHttpCodeCategory.Client;\n  }\n\n  return ZHttpCodeCategory.Server;\n}\n","import type { ZHttpCode } from \"./http-code.mjs\";\nimport { ZHttpCodeSuccess } from \"./http-code-success.mjs\";\n\n/**\n * Represents a result from an http request.\n */\nexport interface IZHttpResult<TResult = any> {\n  /**\n   * The status code.\n   */\n  status: ZHttpCode;\n\n  /**\n   * The set of headers that was returned.\n   */\n  headers: Record<string, any>;\n\n  /**\n   * The actual body result of the invocation.\n   */\n  data: TResult;\n}\n\n/**\n * Represents a builder for an IZHttpResult class.\n */\nexport class ZHttpResultBuilder<TData = any> {\n  private _result: IZHttpResult<TData>;\n\n  /**\n   * Initializes a new instance of this object.\n   *\n   * @param data -\n   *        The data result.\n   */\n  public constructor(data: TData) {\n    this._result = {\n      status: ZHttpCodeSuccess.OK,\n      headers: {},\n      data,\n    };\n  }\n\n  /**\n   * Sets the data.\n   *\n   * @param data -\n   *        The data to set.\n   *\n   * @returns\n   *        This object.\n   */\n  public data(data: TData): this {\n    this._result.data = data;\n    return this;\n  }\n\n  /**\n   * Sets the status code and the english description.\n   *\n   * @param code -\n   *        The code to set.\n   *\n   * @returns\n   *        This object.\n   */\n  public status(code: ZHttpCode): this {\n    this._result.status = code;\n    return this;\n  }\n\n  /**\n   * Sets the return headers.\n   *\n   * @param headers -\n   *        The headers to set.\n   *\n   * @returns\n   *        This object.\n   */\n  public headers(headers: Record<string, any> = {}): this {\n    this._result.headers = headers;\n    return this;\n  }\n\n  /**\n   * Returns the built up result.\n   *\n   * @returns\n   *        A shallow copy of the built up result.\n   */\n  public build(): IZHttpResult {\n    return { ...this._result };\n  }\n}\n","/**\n * A method that determines if an object conforms to a Request BodyInit shape.\n *\n * See the BodyInit interface for more information about the possible\n * shapes.\n *\n * @param obj -\n *        The object to test.\n *\n * @returns\n *        True if obj is a BodyInit shape, false otherwise.\n */\nexport function isBodyInit(obj: any): obj is BodyInit {\n  return (\n    obj == null ||\n    typeof obj === \"string\" ||\n    obj instanceof Blob ||\n    obj instanceof ArrayBuffer ||\n    ArrayBuffer.isView(obj) ||\n    obj instanceof FormData ||\n    obj instanceof URLSearchParams ||\n    obj instanceof ReadableStream\n  );\n}\n\n/**\n * A helper method that converts an object to a BodyInit.\n *\n * If obj is not a BodyInit supported object, then it will\n * simply be converted to JSON.\n *\n * @param obj -\n *        The object to convert.\n *\n * @returns\n *        Obj as a body init serialization.  If obj is not\n *        compatible with a BodyInit shape, then it is converted\n *        to JSON.\n */\nexport function toBodyInit(obj: any): BodyInit {\n  return isBodyInit(obj) ? obj : JSON.stringify(obj);\n}\n","/**\n * A helper method that takes an HTTP Fetch Response and converts the body data based on its\n * content type.\n *\n * This will favor a blob as the default type.\n */\nexport function fromContentType(res: Response): Promise<any> {\n  const contentType = res.headers.get(\"content-type\");\n\n  if (\n    contentType?.startsWith(\"application/json\") ||\n    contentType?.endsWith(\"+json\")\n  ) {\n    return res.json();\n  }\n\n  if (contentType?.startsWith(\"multipart/form-data\")) {\n    return res.formData();\n  }\n\n  if (contentType?.startsWith(\"text\") || contentType?.endsWith(\"+xml\")) {\n    return res.text();\n  }\n\n  return res.blob();\n}\n","import { getHttpCodeName, type ZHttpCode } from \"../result/http-code.mjs\";\nimport type { IZHttpResult } from \"../result/http-result.mjs\";\n\nexport class ZHttpResultError extends Error implements IZHttpResult {\n  public readonly status: ZHttpCode;\n  public readonly headers: Record<string, any>;\n  public readonly data: any;\n\n  public constructor(result: IZHttpResult) {\n    super(getHttpCodeName(result.status));\n\n    this.status = result.status;\n    this.headers = result.headers;\n    this.data = result.data;\n  }\n}\n","import fetch from \"cross-fetch\";\n\nimport type { IZHttpRequest } from \"../request/http-request.mjs\";\nimport { ZHttpCodeClient } from \"../result/http-code-client.mjs\";\nimport { ZHttpCodeServer } from \"../result/http-code-server.mjs\";\nimport type { IZHttpResult } from \"../result/http-result.mjs\";\nimport { ZHttpResultBuilder } from \"../result/http-result.mjs\";\nimport { isBodyInit } from \"../util/body-init.mjs\";\nimport { fromContentType } from \"../util/content-type.mjs\";\nimport { ZHttpResultError } from \"./http-result-error.mjs\";\n\n/**\n * Represents a service that makes http invocations.\n */\nexport interface IZHttpService {\n  /**\n   * Makes the request.\n   *\n   * @param req -\n   *        The request object to make.\n   *\n   * @returns\n   *        A promise that resolves the request if a 200 code is returned, or\n   *        rejects if a 400 or 500 code is returned.  The request is\n   *        rerouted if a 300 code is returned.\n   */\n  request<TResult = any, TBody = any>(\n    req: IZHttpRequest<TBody>,\n  ): Promise<IZHttpResult<TResult>>;\n}\n\n/**\n * Represents an axios based implementation of the http service.\n */\nexport class ZHttpService implements IZHttpService {\n  /**\n   * Invokes the request with a real http service.\n   *\n   * @param req -\n   *        The request information to make.\n   */\n  public async request<TResult = any, TBody = any>(\n    req: IZHttpRequest<TBody>,\n  ): Promise<IZHttpResult<TResult>> {\n    try {\n      const res = await fetch(req.url, {\n        method: req.method,\n        body: isBodyInit(req.body) ? req.body : JSON.stringify(req.body),\n        headers: req.headers,\n        redirect: \"follow\",\n      });\n\n      const data = await fromContentType(res);\n      const result = new ZHttpResultBuilder(data)\n        .headers(res.headers)\n        .status(res.status)\n        .build();\n      return res.ok\n        ? Promise.resolve(result)\n        : Promise.reject(new ZHttpResultError(result));\n    } catch (e) {\n      let result = new ZHttpResultBuilder(e.message)\n        .headers()\n        .status(ZHttpCodeServer.InternalServerError);\n\n      if (e.code === \"ENOTFOUND\") {\n        // The request was made, but some DNS lookup failed.\n        result = result.status(ZHttpCodeClient.NotFound);\n      }\n\n      return Promise.reject(new ZHttpResultError(result.build()));\n    }\n  }\n}\n","import type { IZHttpRequest, ZHttpMethod } from \"../request/http-request.mjs\";\nimport { ZHttpCodeClient } from \"../result/http-code-client.mjs\";\nimport type { IZHttpResult } from \"../result/http-result.mjs\";\nimport { ZHttpResultBuilder } from \"../result/http-result.mjs\";\nimport { ZHttpResultError } from \"./http-result-error.mjs\";\nimport type { IZHttpService } from \"./http-service.mjs\";\n\n/**\n * Represents a mock http service that can be useful for demos,\n * testing, and pre-api implementations.\n */\nexport class ZHttpServiceMock implements IZHttpService {\n  private _mapping: {\n    [endpoint: string]: {\n      [verb: string]: (\n        req: IZHttpRequest,\n      ) => IZHttpResult | Promise<IZHttpResult>;\n    };\n  } = {};\n\n  /**\n   * Sets the result of a given endpoint.\n   *\n   * @param endpoint -\n   *        The endpoint to set.\n   * @param verb -\n   *        The endpoint verb to respond to.\n   * @param invoke -\n   *        The result method.  If this is falsy, then the endpoint is removed.\n   */\n  public set<TResult = any>(\n    endpoint: string,\n    verb: ZHttpMethod,\n    invoke:\n      | IZHttpResult<TResult>\n      | ((\n          req: IZHttpRequest,\n        ) => IZHttpResult<TResult> | Promise<IZHttpResult<TResult>>),\n  ) {\n    this._mapping[endpoint] = this._mapping[endpoint] || {};\n    this._mapping[endpoint][verb] =\n      typeof invoke === \"function\" ? invoke : () => invoke;\n  }\n\n  /**\n   * Invokes the request given the allowed api implementations.\n   *\n   * @param req -\n   *        The request that has been made.\n   *\n   * @returns\n   *        A promise that resolves with the given result if the status code is less than 400.\n   *        Any status code above 400 will result in a rejected promise.\n   */\n  public async request<TResult = any, TBody = any>(\n    req: IZHttpRequest<TBody>,\n  ): Promise<IZHttpResult<TResult>> {\n    const endpointConfig = this._mapping[req.url];\n    const result = endpointConfig?.[req.method];\n\n    if (result == null) {\n      const notFound = new ZHttpResultBuilder(null)\n        .status(ZHttpCodeClient.NotFound)\n        .build();\n      return Promise.reject(new ZHttpResultError(notFound));\n    }\n\n    const errorThreshold = 400;\n    const intermediate = await result(req);\n    return +intermediate.status < errorThreshold\n      ? Promise.resolve(intermediate)\n      : Promise.reject(new ZHttpResultError(intermediate));\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAKA,IAAO,cAAKC,yBAAAA,aAAAA;;;;;GAKT,aAAA,SAAA;;;;;GAOA,aAAA,SAAA;;;;;GAOA,aAAA,UAAA;;;;;GAOA,aAAA,YAAA;;;;;;GAQA,aAAA,WAAA;;;;;;;GASA,aAAA,aAAA;;;;;GAOA,aAAA,UAAA;QAlDSA;;;;GA0FZ,IAAaC,sBAAb,MAAaA,oBAAAA;CACHC;;;;;;;;;;;;;IAeR,OAAcC,UACZC,OACsB;AACtB,SAAO;GAAE,GAAGA;GAAOC,SAASC,gBAAgBF,MAAM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