@furo/open-models 1.1.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Fetcher.js CHANGED
@@ -27,6 +27,7 @@ export class Fetcher {
27
27
  method: this.method,
28
28
  signal,
29
29
  headers: this.API_OPTIONS.headers,
30
+ redirect: 'follow'
30
31
  };
31
32
  this.timeout = this.API_OPTIONS.timeout || 300000; // chrome default timeout
32
33
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Fetcher.js","sourceRoot":"","sources":["../src/Fetcher.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,uBAAuB,EACvB,mBAAmB,GACpB,MAAM,UAAU,CAAC;AA0FlB,MAAM,OAAO,OAAO;IAgClB;;;;;;OAMG;IACH,YACE,OAAoB;IACpB,SAAS;IACT,MAAc;IACd,eAAe;IACf,IAAY,EACZ,SAA2B;QArC7B;;WAEG;QACI,cAAS,GAAY,KAAK,CAAC;QAQ1B,oBAAe,GAAuC,IAAI,GAAG,EAGlE,CAAC;QAyBF,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,IAAI,CAAC,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;QAC7C,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC;QACxC,IAAI,CAAC,WAAW,GAAG;YACjB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,MAAM;YACN,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,OAAO;SAClC,CAAC;QAEF,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,IAAI,MAAM,CAAC,CAAC,yBAAyB;IAC9E,CAAC;IAEM,iBAAiB,CAAC,EAAe;QACtC,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C,EAAE,CAAC,CAAC;gBAC9C,CAAC;YACH,CAAC,CAAC,CAAC;YACH,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;gBAClB,aAAa,GAAG,GAAG,aAAa,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YACzD,CAAC;YAED,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;gBAC5B,aAAa,GAAG,IAAI,CAAC,SAAS,CAC5B,IAAI,CAAC,WAAW,CAAC,kBAAkB;oBACjC,CAAC,CAAC,uBAAuB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;oBACzC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CACnB,CAAC;YACJ,CAAC;QACH,CAAC;QAED,aAAa,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,UAAU,GAAG,aAAa,EAAE,CAAC;QAE/F,OAAO;YACL,aAAa;YACb,aAAa;SACd,CAAC;IACJ,CAAC;CA+EF","sourcesContent":["import {\n deepJsonNameToProtoName,\n deepProtoNameToJsonName,\n protoNameToJsonName,\n} from './Mapper';\n\nexport interface IApiOptions {\n // leave empty to connect to the same host which delivers your files, otherwise set something like http://localhost:3000\n serverAddr: string;\n ApiBaseURL: string;\n headers?: Headers;\n timeout?: number;\n PreserveProtoNames: boolean;\n}\n\ninterface Handlers<REQ, RES> {\n /**\n * The `onResponse` handler is triggered, when we have a successful response.\n * @param response\n * @param serverResponse\n */\n onResponse?: (response: RES, serverResponse: Response) => void;\n\n /**\n * The `onResponseError` handler is triggered on any received status >=400.\n * @param parsedResponse - The parsed response body from the server.\n * @param serverResponse\n */\n onResponseError?: (parsedResponse: unknown, serverResponse: Response) => void;\n\n /**\n * The `onRequestStarted` handler is triggered, whenever a request is started.\n * @param req - The request object\n */\n onRequestStarted?: (req: REQ) => void;\n\n /**\n * The `onRequestFinished` handler is triggered, whenever a request is finished or aborted.\n * @param req - The request object\n */\n onRequestFinished?: (req: REQ) => void;\n\n /**\n * The `onRequestAborted` handler is triggered, whenever a request is aborted.\n * An abort can be triggered by\n * - calling `abortPendingRequest`.\n * - triggering the request again, while you have a pending request.\n * - by reaching the request timeout.\n *\n * The timeout can be set in the OPEN_MODELS_OPTIONS, the default is 600s aka 5min.\n *\n * @param req\n */\n onRequestAborted?: (req: REQ) => void;\n\n /**\n * The `onResponseRaw` handler is triggered, when we have a successful response.\n *\n * @param serverResponse\n */\n onResponseRaw?: (serverResponse: Response) => void;\n\n /**\n * The `onResponseErrorRaw` handler is triggered on any 400\n * @param serverResponse\n */\n onResponseErrorRaw?: (serverResponse: Response) => void;\n\n /**\n * The `onParseError` handler is triggered, when the content could not be parsed, according to the `content-type` header of the response.\n *\n * @param error\n * @param serverResponse\n */\n onResponseParseError?: (error: unknown, serverResponse: Response) => void;\n /**\n * The `onParseError` handler is triggered, when the content of the error could not be parsed, according to the `content-type` header of the response.\n *\n * @param error\n * @param serverResponse\n */\n onResponseErrorParseError?: (\n error: unknown,\n serverResponse: Response,\n ) => void;\n\n /**\n * The `onFatalError` handler is triggered when nothing could be caught with the cather.\n * This should not happen.\n * @param error\n */\n onFatalError?: (error: unknown) => void;\n}\n\nexport class Fetcher<REQ, RES> {\n public timeout: number;\n\n /**\n * Contains the response from the last request. Also on errors.\n */\n public lastResponse: Response | undefined;\n\n /**\n * Indicator for a pending request. Maybe you are also interested on the `onRequestStarted` and `onRequestFinished` callback methods.\n */\n public isLoading: boolean = false;\n\n private path: string;\n\n private requestInit: RequestInit;\n\n private method: string;\n\n private responseHandler: Map<string, (r: Response) => void> = new Map<\n string,\n (r: Response) => void\n >();\n\n private abortController: AbortController;\n\n private timeoutId: ReturnType<typeof setTimeout> | number | undefined;\n\n private bodyField: keyof REQ | '*' | undefined;\n\n private API_OPTIONS: IApiOptions;\n\n /**\n *\n * @param options\n * @param method\n * @param path\n * @param bodyField\n */\n constructor(\n options: IApiOptions,\n // method\n method: string,\n // options path\n path: string,\n bodyField?: keyof REQ | '*',\n ) {\n this.API_OPTIONS = options;\n this.path = path;\n this.bodyField = bodyField;\n this.method = method;\n\n this.abortController = new AbortController();\n const { signal } = this.abortController;\n this.requestInit = {\n method: this.method,\n signal,\n headers: this.API_OPTIONS.headers,\n };\n\n this.timeout = this.API_OPTIONS.timeout || 300000; // chrome default timeout\n }\n\n public setRequestOptions(ri: RequestInit) {\n const { signal } = this.abortController;\n this.requestInit = {\n method: this.method,\n headers: this.API_OPTIONS.headers,\n signal,\n ...ri,\n };\n }\n\n /**\n * setHandlers let you bind all handlers at once.\n * @param handlers\n */\n public setHandlers(handlers: Handlers<REQ, RES>) {\n this.onResponse = handlers.onResponse;\n this.onResponseError = handlers.onResponseError;\n this.onRequestStarted = handlers.onRequestStarted;\n this.onRequestFinished = handlers.onRequestFinished;\n this.onRequestAborted = handlers.onRequestAborted;\n this.onResponseRaw = handlers.onResponseRaw;\n this.onResponseErrorRaw = handlers.onResponseErrorRaw;\n this.onResponseParseError = handlers.onResponseParseError;\n this.onResponseErrorParseError = handlers.onResponseErrorParseError;\n this.onFatalError = handlers.onFatalError;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n public abortPendingRequest(reason: any): void {\n if (!this.isLoading) {\n return;\n }\n clearTimeout(this.timeoutId);\n this.isLoading = false;\n this.abortController.abort(reason);\n\n if (this.onRequestAborted) {\n this.onRequestAborted(reason);\n }\n }\n\n public invoke(rqo: REQ, options?: RequestInit) {\n this.abortController = new AbortController();\n const { signal } = this.abortController;\n\n this.requestInit = {\n method: this.method,\n signal,\n headers: this.API_OPTIONS.headers,\n };\n\n if (options) {\n this.setRequestOptions(options);\n }\n\n if (this.isLoading) {\n this.isLoading = false;\n this.abortPendingRequest('invoke triggered before response');\n }\n\n this.isLoading = true;\n\n const { evaluatedPath, evaluatedBody } = this.buildPathAndBodyfield(\n this.path,\n this.bodyField,\n rqo,\n );\n if (evaluatedBody) {\n this.requestInit.body = evaluatedBody;\n }\n\n clearTimeout(this.timeoutId);\n const request = new Request(evaluatedPath, this.requestInit);\n this.timeoutId = setTimeout(() => {\n this.abortController.abort(`Timeout of ${this.timeout}ms reached`);\n if (this.onRequestAborted) {\n this.onRequestAborted(rqo);\n }\n // eslint-disable-next-line no-console\n console.error(\n `RequestService fetch aborted: Timeout of ${this.timeout}ms reached`,\n );\n }, this.timeout);\n\n if (this.onRequestStarted) {\n this.onRequestStarted(rqo);\n }\n\n fetch(request)\n .then(response => {\n this._reworkRequest(response);\n if (this.onRequestFinished) {\n this.onRequestFinished(rqo);\n }\n })\n .catch(err => {\n this.isLoading = false;\n\n if (err.name === 'AbortError') {\n if (this.onRequestAborted) {\n this.onRequestAborted(rqo);\n }\n if (this.onRequestFinished) {\n this.onRequestFinished(rqo);\n }\n // eslint-disable-next-line no-console\n console.error('RequestService fetch aborted: ', err);\n } else {\n if (this.onRequestFinished) {\n this.onRequestFinished(rqo);\n }\n\n if (this.onFatalError) {\n this.onFatalError(err);\n }\n }\n });\n }\n\n /**\n * Succeeded is true if the request succeeded. The request succeeded if it\n * loaded without error, wasn't aborted, and the status code is ≥ 200, and\n * < 300, or if the status code is 0.\n */\n\n /**\n * Errorhandling according to Google rest-api-v3 Status Codes\n * (https://developers.google.com/maps-booking/reference/rest-api-v3/status_codes)\n *\n * Dispatches event `response-error` and a specific error event with status code\n * @private\n */\n _reworkRequest(response: Response) {\n /**\n * The status code 0 is accepted as a success because some schemes - e.g.\n * file:// - don't provide status codes.\n */\n this.isLoading = false;\n clearTimeout(this.timeoutId);\n const status = response.status || 0;\n\n if (status === 0 || (status >= 200 && status < 300)) {\n /**\n * Loaded without error, fires event `response` with full response object\n */\n this.lastResponse = response;\n\n if (this.onResponseRaw) {\n this.onResponseRaw(response);\n }\n\n /**\n * parses response object according to response heaader informationen `content-type`\n * you will find the supported content-types in the declaration area\n */\n\n this._parseResponse(response)\n .then(r => {\n if (this.onResponse) {\n this.onResponse(r as RES, response);\n }\n })\n .catch(error => {\n if (this.onResponseParseError) {\n this.onResponseParseError(error, response);\n }\n });\n } else {\n /**\n * Error detected\n */\n this.lastResponse = response;\n if (this.onResponseErrorRaw) {\n this.onResponseErrorRaw(response);\n }\n\n /**\n * parses response object according to response heaader `content-type`\n */\n this._parseResponse(response)\n .then(r => {\n if (this.onResponseError) {\n this.onResponseError(r, response);\n }\n })\n /**\n * error parsing is not possible, empty response\n * the dispatched event will have the raw error object in the event detail\n */\n .catch(error => {\n if (this.onResponseErrorParseError) {\n this.onResponseErrorParseError(error, response);\n }\n });\n }\n }\n\n /**\n * parses response object according to lastRequest heaader informationen `content-type`\n * you will find the supported content-types in the declaration area\n * response Fetch API response object [https://developer.mozilla.org/en-US/docs/Web/API/Response]\n * Default response handler is json!\n * @param response\n * @private\n */\n // eslint-disable-next-line class-methods-use-this\n _parseResponse(response: Response) {\n return new Promise((resolve, reject) => {\n if (response) {\n this.responseHandler.set('text/plain', r => {\n r.text()\n .then(text => {\n resolve(text);\n })\n .catch(err => {\n reject(err);\n });\n });\n\n this.responseHandler.set('text/html', r => {\n r.text()\n .then(text => {\n resolve(text);\n })\n .catch(err => {\n reject(err);\n });\n });\n this.responseHandler.set('application/json', r => {\n r.json()\n .then(json => {\n // convert to literal type when needed\n resolve(\n this.API_OPTIONS.PreserveProtoNames\n ? deepProtoNameToJsonName(json)\n : json,\n );\n })\n .catch(err => {\n reject(err);\n });\n });\n this.responseHandler.set('application/octet-stream', r => {\n r.arrayBuffer()\n .then(buffer => {\n resolve(buffer);\n })\n .catch(err => {\n reject(err);\n });\n });\n this.responseHandler.set('application/pdf', r => {\n r.blob()\n .then(blob => {\n resolve(blob);\n })\n .catch(err => {\n reject(err);\n });\n });\n this.responseHandler.set('image/jpeg', r => {\n r.blob()\n .then(blob => {\n resolve(blob);\n })\n .catch(err => {\n reject(err);\n });\n });\n\n const contentType = response.headers.get('content-type');\n let handler = contentType?.split(';')[0].trim();\n if (handler === undefined) {\n handler = 'application/json';\n }\n let typeHandler = this.responseHandler.get(handler);\n\n if (typeHandler === undefined) {\n // eslint-disable-next-line no-console\n console.error('No parser for', handler);\n typeHandler = this.responseHandler.get('application/json');\n }\n\n if (typeHandler) {\n typeHandler(response);\n }\n } else {\n reject(new Error('no response'));\n }\n });\n }\n\n private buildPathAndBodyfield(\n path: string,\n bodyField: keyof REQ | '*' | undefined,\n rqo: REQ,\n ): {\n evaluatedPath: string;\n evaluatedBody: string | undefined;\n } {\n // use the rules specified here https://docs.solo.io/gloo-edge/latest/reference/api/github.com/solo-io/solo-kit/api/external/google/api/http.proto.sk/\n // find all fields in path\n let evaluatedPath = path;\n let evaluatedBody;\n\n const keysForBodyOrQueryParams: Map<string, keyof REQ> = new Map();\n Object.keys(rqo as object).forEach(key => {\n keysForBodyOrQueryParams.set(key, key as keyof REQ);\n });\n\n const fields = [...path.matchAll(/\\{([^}]+)}/g)];\n // replace url templates with values\n // /v1/cube/{id} => /v1/cube/12\n fields.forEach(field => {\n // TODO: check if qp is always set as proto name\n const rqoKey = protoNameToJsonName(field[1]) as keyof REQ;\n const rqoValue = rqo[rqoKey];\n evaluatedPath = evaluatedPath.replace(field[0], `${rqoValue}`);\n keysForBodyOrQueryParams.delete(rqoKey as string);\n });\n\n if (bodyField === '*') {\n // build body object\n const body: { [key: string]: unknown } = {};\n keysForBodyOrQueryParams.forEach(key => {\n body[key as string] = rqo[key];\n });\n evaluatedBody = JSON.stringify(body);\n } else {\n // build query params\n const params: string[] = [];\n if (bodyField !== undefined) {\n keysForBodyOrQueryParams.delete(bodyField as string);\n }\n keysForBodyOrQueryParams.forEach(key => {\n if (Array.isArray(rqo[key])) {\n (rqo[key] as unknown[]).forEach(e => {\n params.push(`${key as string}=${e}`);\n });\n } else {\n params.push(`${key as string}=${rqo[key]}`);\n }\n });\n if (params.length) {\n evaluatedPath = `${evaluatedPath}?${params.join('&')}`;\n }\n\n if (bodyField !== undefined) {\n evaluatedBody = JSON.stringify(\n this.API_OPTIONS.PreserveProtoNames\n ? deepJsonNameToProtoName(rqo[bodyField])\n : rqo[bodyField],\n );\n }\n }\n\n evaluatedPath = `${this.API_OPTIONS.serverAddr}${this.API_OPTIONS.ApiBaseURL}${evaluatedPath}`;\n\n return {\n evaluatedPath,\n evaluatedBody,\n };\n }\n\n /**\n * The `onResponse` handler is triggered, when we have a successful response.\n * @param response\n * @param serverResponse\n */\n onResponse?: (response: RES, serverResponse: Response) => void;\n\n /**\n * The `onResponseError` handler is triggered on any received status >=400.\n * @param parsedResponse - The parsed response body from the server.\n * @param serverResponse\n */\n onResponseError?: (parsedResponse: unknown, serverResponse: Response) => void;\n\n /**\n * The `onRequestStarted` handler is triggered, whenever a request is started.\n * @param req - The request object\n */\n onRequestStarted?: (req: REQ) => void;\n\n /**\n * The `onRequestFinished` handler is triggered, whenever a request is finished or aborted.\n * @param req - The request object\n */\n onRequestFinished?: (req: REQ) => void;\n\n /**\n * The `onRequestAborted` handler is triggered, whenever a request is aborted.\n * An abort can be triggered by\n * - calling `abortPendingRequest`.\n * - triggering the request again, while you have a pending request.\n * - by reaching the request timeout.\n *\n * The timeout can be set in the OPEN_MODELS_OPTIONS, the default is 600s aka 5min.\n *\n * @param req\n */\n onRequestAborted?: (req: REQ) => void;\n\n /**\n * The `onResponseRaw` handler is triggered, when we have a successful response.\n *\n * @param serverResponse\n */\n onResponseRaw?: (serverResponse: Response) => void;\n\n /**\n * The `onResponseErrorRaw` handler is triggered on any 400\n * @param serverResponse\n */\n onResponseErrorRaw?: (serverResponse: Response) => void;\n\n /**\n * The `onParseError` handler is triggered, when the content could not be parsed, according to the `content-type` header of the response.\n *\n * @param error\n * @param serverResponse\n */\n onResponseParseError?: (error: unknown, serverResponse: Response) => void;\n\n /**\n * The `onParseError` handler is triggered, when the content of the error could not be parsed, according to the `content-type` header of the response.\n *\n * @param error\n * @param serverResponse\n */\n onResponseErrorParseError?: (\n error: unknown,\n serverResponse: Response,\n ) => void;\n\n /**\n * The `onFatalError` handler is triggered when nothing could be caught with the cather.\n * This should not happen.\n * @param error\n */\n onFatalError?: (error: unknown) => void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SAAS,CAC5B,IAAI,CAAC,WAAW,CAAC,kBAAkB;oBACjC,CAAC,CAAC,uBAAuB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;oBACzC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CACnB,CAAC;YACJ,CAAC;QACH,CAAC;QAED,aAAa,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,UAAU,GAAG,aAAa,EAAE,CAAC;QAE/F,OAAO;YACL,aAAa;YACb,aAAa;SACd,CAAC;IACJ,CAAC;CA+EF","sourcesContent":["import {\n deepJsonNameToProtoName,\n deepProtoNameToJsonName,\n protoNameToJsonName,\n} from './Mapper';\n\nexport interface IApiOptions {\n // leave empty to connect to the same host which delivers your files, otherwise set something like http://localhost:3000\n serverAddr: string;\n ApiBaseURL: string;\n headers?: Headers;\n timeout?: number;\n PreserveProtoNames: boolean;\n}\n\ninterface Handlers<REQ, RES> {\n /**\n * The `onResponse` handler is triggered, when we have a successful response.\n * @param response\n * @param serverResponse\n */\n onResponse?: (response: RES, serverResponse: Response) => void;\n\n /**\n * The `onResponseError` handler is triggered on any received status >=400.\n * @param parsedResponse - The parsed response body from the server.\n * @param serverResponse\n */\n onResponseError?: (parsedResponse: unknown, serverResponse: Response) => void;\n\n /**\n * The `onRequestStarted` handler is triggered, whenever a request is started.\n * @param req - The request object\n */\n onRequestStarted?: (req: REQ) => void;\n\n /**\n * The `onRequestFinished` handler is triggered, whenever a request is finished or aborted.\n * @param req - The request object\n */\n onRequestFinished?: (req: REQ) => void;\n\n /**\n * The `onRequestAborted` handler is triggered, whenever a request is aborted.\n * An abort can be triggered by\n * - calling `abortPendingRequest`.\n * - triggering the request again, while you have a pending request.\n * - by reaching the request timeout.\n *\n * The timeout can be set in the OPEN_MODELS_OPTIONS, the default is 600s aka 5min.\n *\n * @param req\n */\n onRequestAborted?: (req: REQ) => void;\n\n /**\n * The `onResponseRaw` handler is triggered, when we have a successful response.\n *\n * @param serverResponse\n */\n onResponseRaw?: (serverResponse: Response) => void;\n\n /**\n * The `onResponseErrorRaw` handler is triggered on any 400\n * @param serverResponse\n */\n onResponseErrorRaw?: (serverResponse: Response) => void;\n\n /**\n * The `onParseError` handler is triggered, when the content could not be parsed, according to the `content-type` header of the response.\n *\n * @param error\n * @param serverResponse\n */\n onResponseParseError?: (error: unknown, serverResponse: Response) => void;\n /**\n * The `onParseError` handler is triggered, when the content of the error could not be parsed, according to the `content-type` header of the response.\n *\n * @param error\n * @param serverResponse\n */\n onResponseErrorParseError?: (\n error: unknown,\n serverResponse: Response,\n ) => void;\n\n /**\n * The `onFatalError` handler is triggered when nothing could be caught with the cather.\n * This should not happen.\n * @param error\n */\n onFatalError?: (error: unknown) => void;\n}\n\nexport class Fetcher<REQ, RES> {\n public timeout: number;\n\n /**\n * Contains the response from the last request. Also on errors.\n */\n public lastResponse: Response | undefined;\n\n /**\n * Indicator for a pending request. Maybe you are also interested on the `onRequestStarted` and `onRequestFinished` callback methods.\n */\n public isLoading: boolean = false;\n\n private path: string;\n\n private requestInit: RequestInit;\n\n private method: string;\n\n private responseHandler: Map<string, (r: Response) => void> = new Map<\n string,\n (r: Response) => void\n >();\n\n private abortController: AbortController;\n\n private timeoutId: ReturnType<typeof setTimeout> | number | undefined;\n\n private bodyField: keyof REQ | '*' | undefined;\n\n private API_OPTIONS: IApiOptions;\n\n /**\n *\n * @param options\n * @param method\n * @param path\n * @param bodyField\n */\n constructor(\n options: IApiOptions,\n // method\n method: string,\n // options path\n path: string,\n bodyField?: keyof REQ | '*',\n ) {\n this.API_OPTIONS = options;\n this.path = path;\n this.bodyField = bodyField;\n this.method = method;\n\n this.abortController = new AbortController();\n const { signal } = this.abortController;\n this.requestInit = {\n method: this.method,\n signal,\n headers: this.API_OPTIONS.headers,\n redirect:'follow'\n };\n\n this.timeout = this.API_OPTIONS.timeout || 300000; // chrome default timeout\n }\n\n public setRequestOptions(ri: RequestInit) {\n const { signal } = this.abortController;\n this.requestInit = {\n method: this.method,\n headers: this.API_OPTIONS.headers,\n signal,\n ...ri,\n };\n }\n\n /**\n * setHandlers let you bind all handlers at once.\n * @param handlers\n */\n public setHandlers(handlers: Handlers<REQ, RES>) {\n this.onResponse = handlers.onResponse;\n this.onResponseError = handlers.onResponseError;\n this.onRequestStarted = handlers.onRequestStarted;\n this.onRequestFinished = handlers.onRequestFinished;\n this.onRequestAborted = handlers.onRequestAborted;\n this.onResponseRaw = handlers.onResponseRaw;\n this.onResponseErrorRaw = handlers.onResponseErrorRaw;\n this.onResponseParseError = handlers.onResponseParseError;\n this.onResponseErrorParseError = handlers.onResponseErrorParseError;\n this.onFatalError = handlers.onFatalError;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n public abortPendingRequest(reason: any): void {\n if (!this.isLoading) {\n return;\n }\n clearTimeout(this.timeoutId);\n this.isLoading = false;\n this.abortController.abort(reason);\n\n if (this.onRequestAborted) {\n this.onRequestAborted(reason);\n }\n }\n\n public invoke(rqo: REQ, options?: RequestInit) {\n this.abortController = new AbortController();\n const { signal } = this.abortController;\n\n this.requestInit = {\n method: this.method,\n signal,\n headers: this.API_OPTIONS.headers,\n };\n\n if (options) {\n this.setRequestOptions(options);\n }\n\n if (this.isLoading) {\n this.isLoading = false;\n this.abortPendingRequest('invoke triggered before response');\n }\n\n this.isLoading = true;\n\n const { evaluatedPath, evaluatedBody } = this.buildPathAndBodyfield(\n this.path,\n this.bodyField,\n rqo,\n );\n if (evaluatedBody) {\n this.requestInit.body = evaluatedBody;\n }\n\n clearTimeout(this.timeoutId);\n const request = new Request(evaluatedPath, this.requestInit);\n this.timeoutId = setTimeout(() => {\n this.abortController.abort(`Timeout of ${this.timeout}ms reached`);\n if (this.onRequestAborted) {\n this.onRequestAborted(rqo);\n }\n // eslint-disable-next-line no-console\n console.error(\n `RequestService fetch aborted: Timeout of ${this.timeout}ms reached`,\n );\n }, this.timeout);\n\n if (this.onRequestStarted) {\n this.onRequestStarted(rqo);\n }\n\n fetch(request)\n .then(response => {\n this._reworkRequest(response);\n if (this.onRequestFinished) {\n this.onRequestFinished(rqo);\n }\n })\n .catch(err => {\n this.isLoading = false;\n\n if (err.name === 'AbortError') {\n if (this.onRequestAborted) {\n this.onRequestAborted(rqo);\n }\n if (this.onRequestFinished) {\n this.onRequestFinished(rqo);\n }\n // eslint-disable-next-line no-console\n console.error('RequestService fetch aborted: ', err);\n } else {\n if (this.onRequestFinished) {\n this.onRequestFinished(rqo);\n }\n\n if (this.onFatalError) {\n this.onFatalError(err);\n }\n }\n });\n }\n\n /**\n * Succeeded is true if the request succeeded. The request succeeded if it\n * loaded without error, wasn't aborted, and the status code is ≥ 200, and\n * < 300, or if the status code is 0.\n */\n\n /**\n * Errorhandling according to Google rest-api-v3 Status Codes\n * (https://developers.google.com/maps-booking/reference/rest-api-v3/status_codes)\n *\n * Dispatches event `response-error` and a specific error event with status code\n * @private\n */\n _reworkRequest(response: Response) {\n /**\n * The status code 0 is accepted as a success because some schemes - e.g.\n * file:// - don't provide status codes.\n */\n this.isLoading = false;\n clearTimeout(this.timeoutId);\n const status = response.status || 0;\n\n if (status === 0 || (status >= 200 && status < 300)) {\n /**\n * Loaded without error, fires event `response` with full response object\n */\n this.lastResponse = response;\n\n if (this.onResponseRaw) {\n this.onResponseRaw(response);\n }\n\n /**\n * parses response object according to response heaader informationen `content-type`\n * you will find the supported content-types in the declaration area\n */\n\n this._parseResponse(response)\n .then(r => {\n if (this.onResponse) {\n this.onResponse(r as RES, response);\n }\n })\n .catch(error => {\n if (this.onResponseParseError) {\n this.onResponseParseError(error, response);\n }\n });\n } else {\n /**\n * Error detected\n */\n this.lastResponse = response;\n if (this.onResponseErrorRaw) {\n this.onResponseErrorRaw(response);\n }\n\n /**\n * parses response object according to response heaader `content-type`\n */\n this._parseResponse(response)\n .then(r => {\n if (this.onResponseError) {\n this.onResponseError(r, response);\n }\n })\n /**\n * error parsing is not possible, empty response\n * the dispatched event will have the raw error object in the event detail\n */\n .catch(error => {\n if (this.onResponseErrorParseError) {\n this.onResponseErrorParseError(error, response);\n }\n });\n }\n }\n\n /**\n * parses response object according to lastRequest heaader informationen `content-type`\n * you will find the supported content-types in the declaration area\n * response Fetch API response object [https://developer.mozilla.org/en-US/docs/Web/API/Response]\n * Default response handler is json!\n * @param response\n * @private\n */\n // eslint-disable-next-line class-methods-use-this\n _parseResponse(response: Response) {\n return new Promise((resolve, reject) => {\n if (response) {\n this.responseHandler.set('text/plain', r => {\n r.text()\n .then(text => {\n resolve(text);\n })\n .catch(err => {\n reject(err);\n });\n });\n\n this.responseHandler.set('text/html', r => {\n r.text()\n .then(text => {\n resolve(text);\n })\n .catch(err => {\n reject(err);\n });\n });\n this.responseHandler.set('application/json', r => {\n r.json()\n .then(json => {\n // convert to literal type when needed\n resolve(\n this.API_OPTIONS.PreserveProtoNames\n ? deepProtoNameToJsonName(json)\n : json,\n );\n })\n .catch(err => {\n reject(err);\n });\n });\n this.responseHandler.set('application/octet-stream', r => {\n r.arrayBuffer()\n .then(buffer => {\n resolve(buffer);\n })\n .catch(err => {\n reject(err);\n });\n });\n this.responseHandler.set('application/pdf', r => {\n r.blob()\n .then(blob => {\n resolve(blob);\n })\n .catch(err => {\n reject(err);\n });\n });\n this.responseHandler.set('image/jpeg', r => {\n r.blob()\n .then(blob => {\n resolve(blob);\n })\n .catch(err => {\n reject(err);\n });\n });\n\n const contentType = response.headers.get('content-type');\n let handler = contentType?.split(';')[0].trim();\n if (handler === undefined) {\n handler = 'application/json';\n }\n let typeHandler = this.responseHandler.get(handler);\n\n if (typeHandler === undefined) {\n // eslint-disable-next-line no-console\n console.error('No parser for', handler);\n typeHandler = this.responseHandler.get('application/json');\n }\n\n if (typeHandler) {\n typeHandler(response);\n }\n } else {\n reject(new Error('no response'));\n }\n });\n }\n\n private buildPathAndBodyfield(\n path: string,\n bodyField: keyof REQ | '*' | undefined,\n rqo: REQ,\n ): {\n evaluatedPath: string;\n evaluatedBody: string | undefined;\n } {\n // use the rules specified here https://docs.solo.io/gloo-edge/latest/reference/api/github.com/solo-io/solo-kit/api/external/google/api/http.proto.sk/\n // find all fields in path\n let evaluatedPath = path;\n let evaluatedBody;\n\n const keysForBodyOrQueryParams: Map<string, keyof REQ> = new Map();\n Object.keys(rqo as object).forEach(key => {\n keysForBodyOrQueryParams.set(key, key as keyof REQ);\n });\n\n const fields = [...path.matchAll(/\\{([^}]+)}/g)];\n // replace url templates with values\n // /v1/cube/{id} => /v1/cube/12\n fields.forEach(field => {\n // TODO: check if qp is always set as proto name\n const rqoKey = protoNameToJsonName(field[1]) as keyof REQ;\n const rqoValue = rqo[rqoKey];\n evaluatedPath = evaluatedPath.replace(field[0], `${rqoValue}`);\n keysForBodyOrQueryParams.delete(rqoKey as string);\n });\n\n if (bodyField === '*') {\n // build body object\n const body: { [key: string]: unknown } = {};\n keysForBodyOrQueryParams.forEach(key => {\n body[key as string] = rqo[key];\n });\n evaluatedBody = JSON.stringify(body);\n } else {\n // build query params\n const params: string[] = [];\n if (bodyField !== undefined) {\n keysForBodyOrQueryParams.delete(bodyField as string);\n }\n keysForBodyOrQueryParams.forEach(key => {\n if (Array.isArray(rqo[key])) {\n (rqo[key] as unknown[]).forEach(e => {\n params.push(`${key as string}=${e}`);\n });\n } else {\n params.push(`${key as string}=${rqo[key]}`);\n }\n });\n if (params.length) {\n evaluatedPath = `${evaluatedPath}?${params.join('&')}`;\n }\n\n if (bodyField !== undefined) {\n evaluatedBody = JSON.stringify(\n this.API_OPTIONS.PreserveProtoNames\n ? deepJsonNameToProtoName(rqo[bodyField])\n : rqo[bodyField],\n );\n }\n }\n\n evaluatedPath = `${this.API_OPTIONS.serverAddr}${this.API_OPTIONS.ApiBaseURL}${evaluatedPath}`;\n\n return {\n evaluatedPath,\n evaluatedBody,\n };\n }\n\n /**\n * The `onResponse` handler is triggered, when we have a successful response.\n * @param response\n * @param serverResponse\n */\n onResponse?: (response: RES, serverResponse: Response) => void;\n\n /**\n * The `onResponseError` handler is triggered on any received status >=400.\n * @param parsedResponse - The parsed response body from the server.\n * @param serverResponse\n */\n onResponseError?: (parsedResponse: unknown, serverResponse: Response) => void;\n\n /**\n * The `onRequestStarted` handler is triggered, whenever a request is started.\n * @param req - The request object\n */\n onRequestStarted?: (req: REQ) => void;\n\n /**\n * The `onRequestFinished` handler is triggered, whenever a request is finished or aborted.\n * @param req - The request object\n */\n onRequestFinished?: (req: REQ) => void;\n\n /**\n * The `onRequestAborted` handler is triggered, whenever a request is aborted.\n * An abort can be triggered by\n * - calling `abortPendingRequest`.\n * - triggering the request again, while you have a pending request.\n * - by reaching the request timeout.\n *\n * The timeout can be set in the OPEN_MODELS_OPTIONS, the default is 600s aka 5min.\n *\n * @param req\n */\n onRequestAborted?: (req: REQ) => void;\n\n /**\n * The `onResponseRaw` handler is triggered, when we have a successful response.\n *\n * @param serverResponse\n */\n onResponseRaw?: (serverResponse: Response) => void;\n\n /**\n * The `onResponseErrorRaw` handler is triggered on any 400\n * @param serverResponse\n */\n onResponseErrorRaw?: (serverResponse: Response) => void;\n\n /**\n * The `onParseError` handler is triggered, when the content could not be parsed, according to the `content-type` header of the response.\n *\n * @param error\n * @param serverResponse\n */\n onResponseParseError?: (error: unknown, serverResponse: Response) => void;\n\n /**\n * The `onParseError` handler is triggered, when the content of the error could not be parsed, according to the `content-type` header of the response.\n *\n * @param error\n * @param serverResponse\n */\n onResponseErrorParseError?: (\n error: unknown,\n serverResponse: Response,\n ) => void;\n\n /**\n * The `onFatalError` handler is triggered when nothing could be caught with the cather.\n * This should not happen.\n * @param error\n */\n onFatalError?: (error: unknown) => void;\n}\n"]}
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "homepage": "https://github.com/eclipse/eclipsefuro-web/tree/main/packages",
6
6
  "repository": "git@github.com:eclipse/eclipsefuro-web.git",
7
7
  "author": "eclipse furo",
8
- "version": "1.1.2",
8
+ "version": "1.2.0",
9
9
  "type": "module",
10
10
  "main": "dist/index.js",
11
11
  "module": "dist/index.js",
@@ -81,5 +81,5 @@
81
81
  "prettier --write"
82
82
  ]
83
83
  },
84
- "gitHead": "dc0306208c31bd8538ecac525cd078edfc6f185d"
84
+ "gitHead": "f4f3a0d86e2aa2be937c875ef15c86d9c71fe93a"
85
85
  }