dff-util 1.3.3 → 1.3.5

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.
@@ -31,5 +31,6 @@ export declare class Http {
31
31
  static Token(sessionInfo: any, appKey: string, apiKey?: string, type?: RespType): Promise<any>;
32
32
  static FormUpload(url: string, file: File, isHeadersAddMultiForm?: boolean, data?: Record<string, any>, headers?: any, method?: 'POST' | 'PUT', type?: RespType): Promise<any>;
33
33
  static CloudUpload(fullUrl: string, file: File, headers?: any, method?: 'POST' | 'PUT'): Promise<Response>;
34
- static FileDownload(fullUrl: string, params: any, headers?: any, method?: string): Promise<Buffer<ArrayBuffer>>;
34
+ static FileDownload(fullUrl: string, params: any, headers?: any, method?: string): Promise<Blob>;
35
+ static ErrorWrapper(errorData: any): any;
35
36
  }
package/dist/main/http.js CHANGED
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Http = exports.HttpMethods = exports.BaseHeaders = exports.HttpHeaders = exports.RespType = void 0;
13
13
  const util_1 = require("./util");
14
+ const const_keys_1 = require("./const-keys");
14
15
  var RespType;
15
16
  (function (RespType) {
16
17
  RespType["JSON"] = "json";
@@ -76,7 +77,7 @@ class Http {
76
77
  return yield Http.RespData(response, type);
77
78
  }
78
79
  catch (error) {
79
- throw { url: fullUrl, requestId: headers['request-id'], error: error };
80
+ throw { url: fullUrl, requestId: headers['request-id'], error: Http.ErrorWrapper(error) };
80
81
  }
81
82
  });
82
83
  }
@@ -91,7 +92,7 @@ class Http {
91
92
  return yield Http.RespData(response, type);
92
93
  }
93
94
  catch (error) {
94
- throw { url: url, requestId: headers['request-id'], body: data, error: error };
95
+ throw { url: url, requestId: headers['request-id'], body: data, error: Http.ErrorWrapper(error) };
95
96
  }
96
97
  });
97
98
  }
@@ -106,7 +107,7 @@ class Http {
106
107
  return yield Http.RespData(response, type);
107
108
  }
108
109
  catch (error) {
109
- throw { url: url, requestId: headers['request-id'], body: data, error: error };
110
+ throw { url: url, requestId: headers['request-id'], body: data, error: Http.ErrorWrapper(error) };
110
111
  }
111
112
  });
112
113
  }
@@ -122,7 +123,7 @@ class Http {
122
123
  return yield Http.RespData(response, type);
123
124
  }
124
125
  catch (error) {
125
- throw { url: fullUrl, requestId: headers['request-id'], error: error };
126
+ throw { url: fullUrl, requestId: headers['request-id'], error: Http.ErrorWrapper(error) };
126
127
  }
127
128
  });
128
129
  }
@@ -139,7 +140,7 @@ class Http {
139
140
  return yield Http.RespData(response, type);
140
141
  }
141
142
  catch (error) {
142
- throw { url: fullUrl, requestId: headers['request-id'], error: error };
143
+ throw { url: fullUrl, requestId: headers['request-id'], error: Http.ErrorWrapper(error) };
143
144
  }
144
145
  });
145
146
  }
@@ -167,7 +168,7 @@ class Http {
167
168
  return yield Http.RespData(response, type);
168
169
  }
169
170
  catch (error) {
170
- throw { url: url, requestId: headers['request-id'], error: error };
171
+ throw { url: url, requestId: headers['request-id'], error: Http.ErrorWrapper(error) };
171
172
  }
172
173
  });
173
174
  }
@@ -187,7 +188,7 @@ class Http {
187
188
  return response;
188
189
  }
189
190
  catch (error) {
190
- throw { url: fullUrl, requestId: headers['request-id'], error: error };
191
+ throw { url: fullUrl, requestId: headers['request-id'], error: Http.ErrorWrapper(error) };
191
192
  }
192
193
  });
193
194
  }
@@ -200,14 +201,16 @@ class Http {
200
201
  const requestOptions = { method: method, headers: headers };
201
202
  const response = yield fetch(fullUrl, requestOptions);
202
203
  const blob = yield response.blob();
203
- const buffer = Buffer.from(yield blob.arrayBuffer());
204
- return buffer;
204
+ return blob;
205
205
  }
206
206
  catch (error) {
207
- throw { url: fullUrl, requestId: headers['request-id'], error: error };
207
+ throw { url: fullUrl, requestId: headers['request-id'], error: Http.ErrorWrapper(error) };
208
208
  }
209
209
  });
210
210
  }
211
+ static ErrorWrapper(errorData) {
212
+ return Object.assign(Object.assign({}, errorData), { message: errorData.internal_message || errorData.message || const_keys_1.ConstKeys.INVALID_DATA, main_message: errorData.message || const_keys_1.ConstKeys.INVALID_DATA });
213
+ }
211
214
  }
212
215
  exports.Http = Http;
213
216
  Http.API_BASE_URL = "";
@@ -11,16 +11,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  const index_1 = require("../index");
14
- const url = '/auth/partner/signin';
15
- const reqBody = { language: 'en-US', mobile: '111111111', provider: 'mobile', telCode: '+91' };
16
- const runHttpExample = () => __awaiter(void 0, void 0, void 0, function* () {
14
+ index_1.Http.API_BASE_URL = 'http://localhost:4000';
15
+ const signinRun = () => __awaiter(void 0, void 0, void 0, function* () {
16
+ const payload = {
17
+ userid: 'aaa@anymail.com',
18
+ password: '11111',
19
+ type: 'admin',
20
+ provider: 'email',
21
+ };
17
22
  try {
18
- const res = yield index_1.Http.Post(url, reqBody, null);
23
+ const res = yield index_1.Http.Post("/auth/signin", payload, {});
19
24
  console.log(res);
20
- return res;
21
25
  }
22
- catch (error) {
23
- console.log(error);
26
+ catch (e) {
27
+ console.error(e);
24
28
  }
25
29
  });
26
- runHttpExample();
30
+ signinRun();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dff-util",
3
- "version": "1.3.3",
3
+ "version": "1.3.5",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {