@droz-js/sdk 0.5.7 → 0.5.8

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@droz-js/sdk",
3
3
  "description": "Droz SDK",
4
- "version": "0.5.7",
4
+ "version": "0.5.8",
5
5
  "private": false,
6
6
  "exports": {
7
7
  ".": "./src/index.js",
@@ -32,4 +32,4 @@
32
32
  "src/**/*.d.ts",
33
33
  "README.md"
34
34
  ]
35
- }
35
+ }
@@ -4,6 +4,7 @@ export declare const Casasbahia: new (options?: import("./client/http").HttpClie
4
4
  forTenant(tenant: string): any;
5
5
  withAuthorization(authorization: import("./client/helpers").AuthorizationProvider): any;
6
6
  withCustomHeaders(headers: () => Record<string, string>): any;
7
+ withHttpRequestExecutor(httpRequestExecutor: import("./client/http").HttpRequestExecutor): any;
7
8
  } & {
8
9
  getCasasBahiaInstance(variables: import("./sdks/casasbahia").Exact<{
9
10
  id: string;
@@ -4,6 +4,7 @@ export declare const ChatWidget: new (options?: import("./client/http").HttpClie
4
4
  forTenant(tenant: string): any;
5
5
  withAuthorization(authorization: import("./client/helpers").AuthorizationProvider): any;
6
6
  withCustomHeaders(headers: () => Record<string, string>): any;
7
+ withHttpRequestExecutor(httpRequestExecutor: import("./client/http").HttpRequestExecutor): any;
7
8
  } & {
8
9
  getChatWidget(variables: import("./sdks/chatwidget").Exact<{
9
10
  id: string;
@@ -42,6 +42,11 @@ function toAuthorizationProvider(type, ...values) {
42
42
  if (type == 'Bearer') {
43
43
  return `Bearer ${values[0]}`;
44
44
  }
45
+ // used on zendesk where it uses a proxy to authenticate
46
+ // and the authentication header is like `Basic {{settings.token}}`
47
+ if (type === 'BasicRaw') {
48
+ return `Basic ${values.join(':')}`;
49
+ }
45
50
  throw new SdkConfigurationError(`Invalid authentication type '${type}'`);
46
51
  }
47
52
  exports.toAuthorizationProvider = toAuthorizationProvider;
@@ -3,10 +3,23 @@ type HeadersProvider = () => Record<string, string>;
3
3
  export interface HttpClientOptions {
4
4
  debug?: boolean;
5
5
  }
6
+ export interface HttpRequest {
7
+ url: string;
8
+ method: string;
9
+ headers: Record<string, string>;
10
+ body: string;
11
+ }
12
+ export interface HttpResponse {
13
+ status: number;
14
+ json: () => Promise<any>;
15
+ text: () => Promise<string>;
16
+ }
17
+ export type HttpRequestExecutor = (request: HttpRequest) => Promise<HttpResponse>;
6
18
  export declare function HttpClientBuilder<Sdk>(serviceName: string, getSdk: GetSdk<Sdk>): new (options?: HttpClientOptions) => {
7
19
  readonly http: any;
8
20
  forTenant(tenant: string): any;
9
21
  withAuthorization(authorization: AuthorizationProvider): any;
10
22
  withCustomHeaders(headers: HeadersProvider): any;
23
+ withHttpRequestExecutor(httpRequestExecutor: HttpRequestExecutor): any;
11
24
  } & Sdk;
12
25
  export {};
@@ -24,6 +24,13 @@ function emptyAsyncIterator() {
24
24
  }
25
25
  };
26
26
  }
27
+ async function fetchHttpRequestExecutor(request) {
28
+ return await fetch(request.url, {
29
+ method: request.method,
30
+ headers: request.headers,
31
+ body: request.body
32
+ });
33
+ }
27
34
  function buildArgs(req) {
28
35
  const names = [].concat(req).map(each => each.operationName);
29
36
  const uniques = [...new Set(names)].join(',');
@@ -35,6 +42,7 @@ class HttpRequester {
35
42
  tenant;
36
43
  authorization;
37
44
  customHeaders;
45
+ httpRequestExecutor = fetchHttpRequestExecutor;
38
46
  constructor(serviceName, options) {
39
47
  this.serviceName = serviceName;
40
48
  this.options = options;
@@ -48,6 +56,9 @@ class HttpRequester {
48
56
  withCustomHeaders(headers) {
49
57
  this.customHeaders = headers;
50
58
  }
59
+ withHttpRequestExecutor(httpRequestExecutor) {
60
+ this.httpRequestExecutor = httpRequestExecutor;
61
+ }
51
62
  build() {
52
63
  return this.requester.bind(this);
53
64
  }
@@ -89,7 +100,8 @@ class HttpRequester {
89
100
  console.log('[Droz SDK]:batch', { args, endpoint, headers, body });
90
101
  }
91
102
  // make POST request
92
- const response = await fetch(`${endpoint}?${args}`, {
103
+ const response = await this.httpRequestExecutor({
104
+ url: `${endpoint}?${args}`,
93
105
  method: 'POST',
94
106
  headers,
95
107
  body
@@ -127,6 +139,10 @@ function HttpClientBuilder(serviceName, getSdk) {
127
139
  this.http.withCustomHeaders(headers);
128
140
  return this;
129
141
  }
142
+ withHttpRequestExecutor(httpRequestExecutor) {
143
+ this.http.withHttpRequestExecutor(httpRequestExecutor);
144
+ return this;
145
+ }
130
146
  }
131
147
  return Client;
132
148
  }
@@ -4,6 +4,7 @@ export declare const DrozAdmin: new (options?: import("./client/http").HttpClien
4
4
  forTenant(tenant: string): any;
5
5
  withAuthorization(authorization: import("./client/helpers").AuthorizationProvider): any;
6
6
  withCustomHeaders(headers: () => Record<string, string>): any;
7
+ withHttpRequestExecutor(httpRequestExecutor: import("./client/http").HttpRequestExecutor): any;
7
8
  } & {
8
9
  getAmplifyConfig(variables?: import("./sdks/drozcommons").Exact<{
9
10
  forDev?: boolean;
package/src/drozbot.d.ts CHANGED
@@ -4,6 +4,7 @@ export declare const DrozBot: new (options?: import("./client/http").HttpClientO
4
4
  forTenant(tenant: string): any;
5
5
  withAuthorization(authorization: import("./client/helpers").AuthorizationProvider): any;
6
6
  withCustomHeaders(headers: () => Record<string, string>): any;
7
+ withHttpRequestExecutor(httpRequestExecutor: import("./client/http").HttpRequestExecutor): any;
7
8
  } & {
8
9
  getDrozBotInstance(variables: import("./sdks/drozbot").Exact<{
9
10
  id: string;
package/src/drozchat.d.ts CHANGED
@@ -4,6 +4,7 @@ export declare const DrozChat: new (options?: import("./client/http").HttpClient
4
4
  forTenant(tenant: string): any;
5
5
  withAuthorization(authorization: import("./client/helpers").AuthorizationProvider): any;
6
6
  withCustomHeaders(headers: () => Record<string, string>): any;
7
+ withHttpRequestExecutor(httpRequestExecutor: import("./client/http").HttpRequestExecutor): any;
7
8
  } & {
8
9
  getDrozChatChannel(variables: import("./sdks/drozchat").Exact<{
9
10
  id: string;
package/src/droznexo.d.ts CHANGED
@@ -4,6 +4,7 @@ export declare const DrozNexo: new (options?: import("./client/http").HttpClient
4
4
  forTenant(tenant: string): any;
5
5
  withAuthorization(authorization: import("./client/helpers").AuthorizationProvider): any;
6
6
  withCustomHeaders(headers: () => Record<string, string>): any;
7
+ withHttpRequestExecutor(httpRequestExecutor: import("./client/http").HttpRequestExecutor): any;
7
8
  } & {
8
9
  listDrozNexoSuggestions(variables?: import("./sdks/droznexo").Exact<{
9
10
  [key: string]: never;
@@ -4,6 +4,7 @@ export declare const MercadoLivre: new (options?: import("./client/http").HttpCl
4
4
  forTenant(tenant: string): any;
5
5
  withAuthorization(authorization: import("./client/helpers").AuthorizationProvider): any;
6
6
  withCustomHeaders(headers: () => Record<string, string>): any;
7
+ withHttpRequestExecutor(httpRequestExecutor: import("./client/http").HttpRequestExecutor): any;
7
8
  } & {
8
9
  getMercadoLivreInstance(variables: import("./sdks/mercadolivre").Exact<{
9
10
  id: string;
package/src/nucleus.d.ts CHANGED
@@ -6,6 +6,7 @@ declare const Nucleus_base: new (options?: import("./client/http").HttpClientOpt
6
6
  forTenant(tenant: string): any;
7
7
  withAuthorization(authorization: import("./client/helpers").AuthorizationProvider): any;
8
8
  withCustomHeaders(headers: () => Record<string, string>): any;
9
+ withHttpRequestExecutor(httpRequestExecutor: import("./client/http").HttpRequestExecutor): any;
9
10
  } & {
10
11
  getMe(variables?: import("./sdks/nucleus").Exact<{
11
12
  [key: string]: never;
@@ -4,6 +4,7 @@ export declare const Reclameaqui: new (options?: import("./client/http").HttpCli
4
4
  forTenant(tenant: string): any;
5
5
  withAuthorization(authorization: import("./client/helpers").AuthorizationProvider): any;
6
6
  withCustomHeaders(headers: () => Record<string, string>): any;
7
+ withHttpRequestExecutor(httpRequestExecutor: import("./client/http").HttpRequestExecutor): any;
7
8
  } & {
8
9
  getReclameAquiInstance(variables: import("./sdks/reclameaqui").Exact<{
9
10
  id: string;
package/src/zendesk.d.ts CHANGED
@@ -4,6 +4,7 @@ export declare const Zendesk: new (options?: import("./client/http").HttpClientO
4
4
  forTenant(tenant: string): any;
5
5
  withAuthorization(authorization: import("./client/helpers").AuthorizationProvider): any;
6
6
  withCustomHeaders(headers: () => Record<string, string>): any;
7
+ withHttpRequestExecutor(httpRequestExecutor: import("./client/http").HttpRequestExecutor): any;
7
8
  } & {
8
9
  getZendeskInstance(variables: import("./sdks/zendesk").Exact<{
9
10
  id: string;