@droz-js/sdk
Advanced tools
Comparing version 0.5.7 to 0.5.8
{ | ||
"name": "@droz-js/sdk", | ||
"description": "Droz SDK", | ||
"version": "0.5.7", | ||
"version": "0.5.8", | ||
"private": false, | ||
@@ -35,2 +35,2 @@ "exports": { | ||
] | ||
} | ||
} |
@@ -7,2 +7,3 @@ export * from './sdks/casasbahia'; | ||
withCustomHeaders(headers: () => Record<string, string>): any; | ||
withHttpRequestExecutor(httpRequestExecutor: import("./client/http").HttpRequestExecutor): any; | ||
} & { | ||
@@ -9,0 +10,0 @@ getCasasBahiaInstance(variables: import("./sdks/casasbahia").Exact<{ |
@@ -7,2 +7,3 @@ export * from './sdks/chatwidget'; | ||
withCustomHeaders(headers: () => Record<string, string>): any; | ||
withHttpRequestExecutor(httpRequestExecutor: import("./client/http").HttpRequestExecutor): any; | ||
} & { | ||
@@ -9,0 +10,0 @@ getChatWidget(variables: import("./sdks/chatwidget").Exact<{ |
@@ -45,2 +45,7 @@ "use strict"; | ||
} | ||
// used on zendesk where it uses a proxy to authenticate | ||
// and the authentication header is like `Basic {{settings.token}}` | ||
if (type === 'BasicRaw') { | ||
return `Basic ${values.join(':')}`; | ||
} | ||
throw new SdkConfigurationError(`Invalid authentication type '${type}'`); | ||
@@ -47,0 +52,0 @@ } |
@@ -6,2 +6,14 @@ import { AuthorizationProvider, GetSdk } from './helpers'; | ||
} | ||
export interface HttpRequest { | ||
url: string; | ||
method: string; | ||
headers: Record<string, string>; | ||
body: string; | ||
} | ||
export interface HttpResponse { | ||
status: number; | ||
json: () => Promise<any>; | ||
text: () => Promise<string>; | ||
} | ||
export type HttpRequestExecutor = (request: HttpRequest) => Promise<HttpResponse>; | ||
export declare function HttpClientBuilder<Sdk>(serviceName: string, getSdk: GetSdk<Sdk>): new (options?: HttpClientOptions) => { | ||
@@ -12,3 +24,4 @@ readonly http: any; | ||
withCustomHeaders(headers: HeadersProvider): any; | ||
withHttpRequestExecutor(httpRequestExecutor: HttpRequestExecutor): any; | ||
} & Sdk; | ||
export {}; |
@@ -27,2 +27,9 @@ "use strict"; | ||
} | ||
async function fetchHttpRequestExecutor(request) { | ||
return await fetch(request.url, { | ||
method: request.method, | ||
headers: request.headers, | ||
body: request.body | ||
}); | ||
} | ||
function buildArgs(req) { | ||
@@ -39,2 +46,3 @@ const names = [].concat(req).map(each => each.operationName); | ||
customHeaders; | ||
httpRequestExecutor = fetchHttpRequestExecutor; | ||
constructor(serviceName, options) { | ||
@@ -53,2 +61,5 @@ this.serviceName = serviceName; | ||
} | ||
withHttpRequestExecutor(httpRequestExecutor) { | ||
this.httpRequestExecutor = httpRequestExecutor; | ||
} | ||
build() { | ||
@@ -95,3 +106,4 @@ return this.requester.bind(this); | ||
// make POST request | ||
const response = await fetch(`${endpoint}?${args}`, { | ||
const response = await this.httpRequestExecutor({ | ||
url: `${endpoint}?${args}`, | ||
method: 'POST', | ||
@@ -134,2 +146,6 @@ headers, | ||
} | ||
withHttpRequestExecutor(httpRequestExecutor) { | ||
this.http.withHttpRequestExecutor(httpRequestExecutor); | ||
return this; | ||
} | ||
} | ||
@@ -136,0 +152,0 @@ return Client; |
@@ -7,2 +7,3 @@ export * from './sdks/drozcommons'; | ||
withCustomHeaders(headers: () => Record<string, string>): any; | ||
withHttpRequestExecutor(httpRequestExecutor: import("./client/http").HttpRequestExecutor): any; | ||
} & { | ||
@@ -9,0 +10,0 @@ getAmplifyConfig(variables?: import("./sdks/drozcommons").Exact<{ |
@@ -7,2 +7,3 @@ export * from './sdks/drozbot'; | ||
withCustomHeaders(headers: () => Record<string, string>): any; | ||
withHttpRequestExecutor(httpRequestExecutor: import("./client/http").HttpRequestExecutor): any; | ||
} & { | ||
@@ -9,0 +10,0 @@ getDrozBotInstance(variables: import("./sdks/drozbot").Exact<{ |
@@ -7,2 +7,3 @@ export * from './sdks/drozchat'; | ||
withCustomHeaders(headers: () => Record<string, string>): any; | ||
withHttpRequestExecutor(httpRequestExecutor: import("./client/http").HttpRequestExecutor): any; | ||
} & { | ||
@@ -9,0 +10,0 @@ getDrozChatChannel(variables: import("./sdks/drozchat").Exact<{ |
@@ -7,2 +7,3 @@ export * from './sdks/droznexo'; | ||
withCustomHeaders(headers: () => Record<string, string>): any; | ||
withHttpRequestExecutor(httpRequestExecutor: import("./client/http").HttpRequestExecutor): any; | ||
} & { | ||
@@ -9,0 +10,0 @@ listDrozNexoSuggestions(variables?: import("./sdks/droznexo").Exact<{ |
@@ -7,2 +7,3 @@ export * from './sdks/mercadolivre'; | ||
withCustomHeaders(headers: () => Record<string, string>): any; | ||
withHttpRequestExecutor(httpRequestExecutor: import("./client/http").HttpRequestExecutor): any; | ||
} & { | ||
@@ -9,0 +10,0 @@ getMercadoLivreInstance(variables: import("./sdks/mercadolivre").Exact<{ |
@@ -9,2 +9,3 @@ import { CreatePresignedUploadUrlInput } from './sdks/nucleus'; | ||
withCustomHeaders(headers: () => Record<string, string>): any; | ||
withHttpRequestExecutor(httpRequestExecutor: import("./client/http").HttpRequestExecutor): any; | ||
} & { | ||
@@ -11,0 +12,0 @@ getMe(variables?: import("./sdks/nucleus").Exact<{ |
@@ -7,2 +7,3 @@ export * from './sdks/reclameaqui'; | ||
withCustomHeaders(headers: () => Record<string, string>): any; | ||
withHttpRequestExecutor(httpRequestExecutor: import("./client/http").HttpRequestExecutor): any; | ||
} & { | ||
@@ -9,0 +10,0 @@ getReclameAquiInstance(variables: import("./sdks/reclameaqui").Exact<{ |
@@ -7,2 +7,3 @@ export * from './sdks/zendesk'; | ||
withCustomHeaders(headers: () => Record<string, string>): any; | ||
withHttpRequestExecutor(httpRequestExecutor: import("./client/http").HttpRequestExecutor): any; | ||
} & { | ||
@@ -9,0 +10,0 @@ getZendeskInstance(variables: import("./sdks/zendesk").Exact<{ |
390159
8484