@influxdata/oats
Advanced tools
Comparing version 0.4.0 to 0.5.0
@@ -44,3 +44,3 @@ "use strict"; | ||
options: RequestOptions = {} | ||
): Promise<${resultName(pathOp)}> => | ||
): Promise<${resultName(pathOp)}> => | ||
request( | ||
@@ -71,3 +71,22 @@ "${pathOp.operation.toUpperCase()}", | ||
const request = async ( | ||
export type RequestHandler = ( | ||
url: string, | ||
query: string, | ||
init: RequestInit | ||
) => {url: string, query: string, init: RequestInit} | ||
export type ResponseHandler = ( | ||
status: number, | ||
headers: Headers, | ||
data: any | ||
) => {status: number, headers: Headers, data: any} | ||
const RequestContext = function( | ||
requestHandler: RequestHandler, | ||
responseHandler: ResponseHandler | ||
) { | ||
this.requestHandler = requestHandler | ||
this.responseHandler = responseHandler | ||
} | ||
RequestContext.prototype.request = async function( | ||
method: string, | ||
@@ -77,3 +96,3 @@ url: string, | ||
options: RequestOptions = {} | ||
): Promise<any> => { | ||
): Promise<any> { | ||
const requestHeaders = new Headers(params.headers) | ||
@@ -95,10 +114,16 @@ const contentType = requestHeaders.get("Content-Type") || "" | ||
const response = await fetch(\`\${url}\${query}\`, { | ||
const { | ||
url: middlewareUrl, | ||
query: middlewareQuery, | ||
init, | ||
} = this.requestHandler(url, query, { | ||
method, | ||
body, | ||
credentials: "same-origin", | ||
credentials: 'same-origin', | ||
signal: options.signal, | ||
headers: requestHeaders | ||
headers: requestHeaders, | ||
}) | ||
const response = await fetch(\`\${middlewareUrl}\${middlewareQuery}\`, init) | ||
const { status, headers } = response | ||
@@ -117,6 +142,26 @@ const responseContentType = headers.get("Content-Type") || "" | ||
return { status, headers, data } | ||
return this.responseHandler(status, headers, data) | ||
} | ||
RequestContext.prototype.setRequestHandler = function(requestHandler: RequestHandler) { | ||
this.requestHandler = requestHandler | ||
} | ||
RequestContext.prototype.setResponseHandler = function(responseHandler: ResponseHandler) { | ||
this.responseHandler = responseHandler | ||
} | ||
const rc = new RequestContext( | ||
(url, query, init) => { | ||
return {url, query, init} | ||
}, | ||
(status, headers, data) => { | ||
return {status, headers, data} | ||
} | ||
) | ||
const request = rc.request.bind(rc) | ||
export const setRequestHandler = rc.setRequestHandler.bind(rc) | ||
export const setResponseHandler = rc.setResponseHandler.bind(rc) | ||
`.trim(); | ||
@@ -123,0 +168,0 @@ } |
{ | ||
"name": "@influxdata/oats", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43106
714
1