drapcode-developer-sdk 1.0.1 → 1.0.3

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/README.md CHANGED
@@ -25,12 +25,12 @@ const api = new DrapcodeApis(project_seo_name, xApiKey, authorization, environme
25
25
  **environment (Optional)**: The environment (PRODUCTION, PREVIEW, BETA, ALPHA). Defaults to PRODUCTION if not provided.
26
26
  ### Example:
27
27
  ```
28
- const drapcodeApi = new DrapcodeApis("singhaniya-computer-7138");
28
+ const drapcodeApi = new DrapcodeApis("test-project-7138");
29
29
  ```
30
30
  # Methods
31
31
 
32
32
  ## getAllItems(collectionName: string)
33
- Retrieves all items from a specified collection.
33
+ Retrieves all items from a specified collection. The items will come under 'data' JSON path.
34
34
 
35
35
  **collectionName:** The name of the collection to retrieve items from
36
36
  ### Example:
@@ -48,8 +48,8 @@ Creates a new item in the specified collection.
48
48
  ### Example:
49
49
  ```
50
50
  await drapcodeApi.createItem("users", {
51
- "name": "Pk",
52
- "age": 23
51
+ "name": "John Doe",
52
+ "age": 25
53
53
  });
54
54
  ```
55
55
  Creates a new item in the "users" collection with the provided data.
package/build/index.d.ts CHANGED
@@ -7,14 +7,124 @@ export declare class DrapcodeApis {
7
7
  constructor(project_seo_name: string, xApiKey?: string, authorization?: string, environment?: string);
8
8
  private getBaseUrl;
9
9
  private getHeaders;
10
- getAllItems(collectionName: string): Promise<any>;
11
- createItem(collectionName: string, body: any): Promise<any[]>;
12
- getItemsWithFilter(collectionName: string, filterUuid: string): Promise<any[]>;
13
- getItemsCountWithFilter(collectionName: string, filterUuid: string): Promise<any[]>;
14
- getItemWithUuid(collectionName: string, itemUuid: string): Promise<any[]>;
15
- updateItemWithUuid(collectionName: string, itemUuid: string, body: any): Promise<any[]>;
16
- deleteItemWithUuid(collectionName: string, itemUuid: string): Promise<any[]>;
17
- bulkDeleteItems(collectionName: string, body: any): Promise<any[]>;
18
- getItemsByids(collectionName: string, body: any): Promise<any[]>;
19
- sendEmail(templateId: string, sendTo: string): Promise<any[]>;
10
+ getAllItems(collectionName: string): Promise<{
11
+ code: any;
12
+ success: boolean;
13
+ data: any;
14
+ error: string;
15
+ message: string;
16
+ } | {
17
+ code: any;
18
+ success: boolean;
19
+ error: any;
20
+ message: any;
21
+ data: string;
22
+ }>;
23
+ createItem(collectionName: string, body: any): Promise<{
24
+ code: any;
25
+ success: boolean;
26
+ data: any;
27
+ error: string;
28
+ message: string;
29
+ } | {
30
+ success: boolean;
31
+ data: string;
32
+ error: string;
33
+ message: string;
34
+ }>;
35
+ getItemsWithFilter(collectionName: string, filterUuid: string): Promise<{
36
+ code: any;
37
+ success: boolean;
38
+ data: any;
39
+ error: string;
40
+ message: string;
41
+ } | {
42
+ code: any;
43
+ success: boolean;
44
+ error: any;
45
+ message: any;
46
+ data: string;
47
+ }>;
48
+ getItemsCountWithFilter(collectionName: string, filterUuid: string): Promise<{
49
+ code: any;
50
+ success: boolean;
51
+ data: any;
52
+ error: string;
53
+ message: string;
54
+ } | {
55
+ code: any;
56
+ success: boolean;
57
+ error: any;
58
+ message: any;
59
+ data: string;
60
+ }>;
61
+ getItemWithUuid(collectionName: string, itemUuid: string): Promise<{
62
+ code: any;
63
+ success: boolean;
64
+ data: any;
65
+ error: string;
66
+ message: string;
67
+ } | {
68
+ code: any;
69
+ success: boolean;
70
+ error: any;
71
+ message: any;
72
+ data: string;
73
+ }>;
74
+ updateItemWithUuid(collectionName: string, itemUuid: string, body: any): Promise<{
75
+ code: any;
76
+ success: boolean;
77
+ data: any;
78
+ error: string;
79
+ message: string;
80
+ } | {
81
+ code: any;
82
+ success: boolean;
83
+ error: any;
84
+ message: any;
85
+ data: string;
86
+ }>;
87
+ deleteItemWithUuid(collectionName: string, itemUuid: string): Promise<{
88
+ code: any;
89
+ success: boolean;
90
+ data: any;
91
+ error: string;
92
+ message: string;
93
+ }>;
94
+ bulkDeleteItems(collectionName: string, body: any): Promise<{
95
+ code: any;
96
+ success: boolean;
97
+ data: any;
98
+ error: string;
99
+ message: string;
100
+ } | {
101
+ success: boolean;
102
+ data: any;
103
+ error: string;
104
+ message: string;
105
+ }>;
106
+ getItemsByids(collectionName: string, body: any): Promise<{
107
+ code: any;
108
+ success: boolean;
109
+ data: any;
110
+ error: string;
111
+ message: string;
112
+ } | {
113
+ success: boolean;
114
+ data: any;
115
+ error: string;
116
+ message: string;
117
+ }>;
118
+ sendEmail(templateId: string, sendTo: string): Promise<{
119
+ code: any;
120
+ success: boolean;
121
+ data: any;
122
+ error: string;
123
+ message: string;
124
+ } | {
125
+ success: boolean;
126
+ data: any;
127
+ error: string;
128
+ message: string;
129
+ }>;
20
130
  }
package/build/index.js CHANGED
@@ -42,8 +42,8 @@ var DrapcodeApis = /** @class */ (function () {
42
42
  function DrapcodeApis(project_seo_name, xApiKey, authorization, environment) {
43
43
  if (xApiKey === void 0) { xApiKey = ""; }
44
44
  if (authorization === void 0) { authorization = ""; }
45
- if (environment === void 0) { environment = 'PRODUCTION'; }
46
- this.API_PATH = 'drapcode.io/api/v1/developer';
45
+ if (environment === void 0) { environment = "PRODUCTION"; }
46
+ this.API_PATH = "drapcode.io/api/v1/developer";
47
47
  this.project_seo_name = project_seo_name;
48
48
  this.xApiKey = xApiKey;
49
49
  this.authorization = authorization;
@@ -51,28 +51,28 @@ var DrapcodeApis = /** @class */ (function () {
51
51
  }
52
52
  DrapcodeApis.prototype.getBaseUrl = function () {
53
53
  switch (this.environment) {
54
- case 'PRODUCTION':
54
+ case "PRODUCTION":
55
55
  return "https://".concat(this.project_seo_name, ".api.").concat(this.API_PATH);
56
- case 'PREVIEW':
57
- return "https://".concat(this.project_seo_name, ".preview.").concat(this.API_PATH);
58
- case 'BETA':
59
- return "https://".concat(this.project_seo_name, ".beta.").concat(this.API_PATH);
60
- case 'ALPHA':
61
- return "https://".concat(this.project_seo_name, ".alpha.").concat(this.API_PATH);
56
+ case "PREVIEW":
57
+ return "https://".concat(this.project_seo_name, ".api.preview.").concat(this.API_PATH);
58
+ case "BETA":
59
+ return "https://".concat(this.project_seo_name, ".api.beta.").concat(this.API_PATH);
60
+ case "ALPHA":
61
+ return "https://".concat(this.project_seo_name, ".api.alpha.").concat(this.API_PATH);
62
62
  default:
63
63
  return "https://".concat(this.project_seo_name, ".api.").concat(this.API_PATH);
64
64
  }
65
65
  };
66
66
  DrapcodeApis.prototype.getHeaders = function () {
67
67
  var headers = {
68
- 'Content-Type': 'application/json',
69
- 'Accept': 'application/json',
68
+ "Content-Type": "application/json",
69
+ Accept: "application/json",
70
70
  };
71
71
  if (this.xApiKey) {
72
- headers['x-api-key'] = this.xApiKey;
72
+ headers["x-api-key"] = this.xApiKey;
73
73
  }
74
74
  if (this.authorization) {
75
- headers['Authorization'] = this.authorization;
75
+ headers["Authorization"] = this.authorization;
76
76
  }
77
77
  return headers;
78
78
  };
@@ -1,13 +1,123 @@
1
- export declare const getAllItems: (baseurl: string, headers: Record<string, string>, collectionName: string) => Promise<any>;
2
- export declare const createItem: (baseurl: string, headers: Record<string, string>, collectionName: string, body: any) => Promise<any>;
3
- export declare const getItemsWithFilter: (baseurl: string, headers: Record<string, string>, collectionName: string, filterUuid: string) => Promise<any>;
4
- export declare const getItemsCountWithFilter: (baseurl: string, headers: Record<string, string>, collectionName: string, filterUuid: string) => Promise<any>;
5
- export declare const getItemWithUuid: (baseurl: string, headers: Record<string, string>, collectionName: string, itemUuid: string) => Promise<any>;
6
- export declare const updateItemWithUuid: (baseurl: string, headers: Record<string, string>, collectionName: string, itemUuid: string, body: any) => Promise<any>;
7
- export declare const deleteItemWithUuid: (baseurl: string, headers: Record<string, string>, collectionName: string, itemUuid: string) => Promise<any>;
8
- export declare const bulkDeleteItems: (baseurl: string, headers: Record<string, string>, collectionName: string, body: any) => Promise<any>;
9
- export declare const getItemsByids: (baseurl: string, headers: Record<string, string>, collectionName: string, body: any) => Promise<any>;
10
- export declare const sendEmail: (baseurl: string, headers: Record<string, string>, templateId: string, sendTo: any) => Promise<any>;
1
+ export declare const getAllItems: (baseurl: string, headers: Record<string, string>, collectionName: string) => Promise<{
2
+ code: any;
3
+ success: boolean;
4
+ data: any;
5
+ error: string;
6
+ message: string;
7
+ } | {
8
+ code: any;
9
+ success: boolean;
10
+ error: any;
11
+ message: any;
12
+ data: string;
13
+ }>;
14
+ export declare const createItem: (baseurl: string, headers: Record<string, string>, collectionName: string, body: any) => Promise<{
15
+ code: any;
16
+ success: boolean;
17
+ data: any;
18
+ error: string;
19
+ message: string;
20
+ } | {
21
+ success: boolean;
22
+ data: string;
23
+ error: string;
24
+ message: string;
25
+ }>;
26
+ export declare const getItemsWithFilter: (baseurl: string, headers: Record<string, string>, collectionName: string, filterUuid: string) => Promise<{
27
+ code: any;
28
+ success: boolean;
29
+ data: any;
30
+ error: string;
31
+ message: string;
32
+ } | {
33
+ code: any;
34
+ success: boolean;
35
+ error: any;
36
+ message: any;
37
+ data: string;
38
+ }>;
39
+ export declare const getItemsCountWithFilter: (baseurl: string, headers: Record<string, string>, collectionName: string, filterUuid: string) => Promise<{
40
+ code: any;
41
+ success: boolean;
42
+ data: any;
43
+ error: string;
44
+ message: string;
45
+ } | {
46
+ code: any;
47
+ success: boolean;
48
+ error: any;
49
+ message: any;
50
+ data: string;
51
+ }>;
52
+ export declare const getItemWithUuid: (baseurl: string, headers: Record<string, string>, collectionName: string, itemUuid: string) => Promise<{
53
+ code: any;
54
+ success: boolean;
55
+ data: any;
56
+ error: string;
57
+ message: string;
58
+ } | {
59
+ code: any;
60
+ success: boolean;
61
+ error: any;
62
+ message: any;
63
+ data: string;
64
+ }>;
65
+ export declare const updateItemWithUuid: (baseurl: string, headers: Record<string, string>, collectionName: string, itemUuid: string, body: any) => Promise<{
66
+ code: any;
67
+ success: boolean;
68
+ data: any;
69
+ error: string;
70
+ message: string;
71
+ } | {
72
+ code: any;
73
+ success: boolean;
74
+ error: any;
75
+ message: any;
76
+ data: string;
77
+ }>;
78
+ export declare const deleteItemWithUuid: (baseurl: string, headers: Record<string, string>, collectionName: string, itemUuid: string) => Promise<{
79
+ code: any;
80
+ success: boolean;
81
+ data: any;
82
+ error: string;
83
+ message: string;
84
+ }>;
85
+ export declare const bulkDeleteItems: (baseurl: string, headers: Record<string, string>, collectionName: string, body: any) => Promise<{
86
+ code: any;
87
+ success: boolean;
88
+ data: any;
89
+ error: string;
90
+ message: string;
91
+ } | {
92
+ success: boolean;
93
+ data: any;
94
+ error: string;
95
+ message: string;
96
+ }>;
97
+ export declare const getItemsByids: (baseurl: string, headers: Record<string, string>, collectionName: string, body: any) => Promise<{
98
+ code: any;
99
+ success: boolean;
100
+ data: any;
101
+ error: string;
102
+ message: string;
103
+ } | {
104
+ success: boolean;
105
+ data: any;
106
+ error: string;
107
+ message: string;
108
+ }>;
109
+ export declare const sendEmail: (baseurl: string, headers: Record<string, string>, templateId: string, sendTo: any) => Promise<{
110
+ code: any;
111
+ success: boolean;
112
+ data: any;
113
+ error: string;
114
+ message: string;
115
+ } | {
116
+ success: boolean;
117
+ data: any;
118
+ error: string;
119
+ message: string;
120
+ }>;
11
121
  /**
12
122
  * {
13
123
  * code,
@@ -16,4 +126,4 @@ export declare const sendEmail: (baseurl: string, headers: Record<string, string
16
126
  * error,
17
127
  * message,
18
128
  * }
19
- */
129
+ */
@@ -35,17 +35,13 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
36
  }
37
37
  };
38
- var __importDefault = (this && this.__importDefault) || function (mod) {
39
- return (mod && mod.__esModule) ? mod : { "default": mod };
40
- };
41
38
  Object.defineProperty(exports, "__esModule", { value: true });
42
39
  exports.sendEmail = exports.getItemsByids = exports.bulkDeleteItems = exports.deleteItemWithUuid = exports.updateItemWithUuid = exports.getItemWithUuid = exports.getItemsCountWithFilter = exports.getItemsWithFilter = exports.createItem = exports.getAllItems = void 0;
43
- var axios_1 = __importDefault(require("axios"));
44
40
  var createErrorResponse = function (error) {
45
41
  if (error.response && error.response.status === 404) {
46
42
  var responseData = error.response.data;
47
43
  var finalData = void 0;
48
- if (responseData == 'This url does not exist. Please publish again.') {
44
+ if (responseData == "This url does not exist. Please publish again.") {
49
45
  finalData = "Please check your project name or publish again.";
50
46
  }
51
47
  else if (responseData.message) {
@@ -58,8 +54,8 @@ var createErrorResponse = function (error) {
58
54
  code: error.response.status,
59
55
  success: false,
60
56
  data: finalData,
61
- error: '',
62
- message: '',
57
+ error: "",
58
+ message: "",
63
59
  };
64
60
  }
65
61
  else if (error.response && error.response.status === 401) {
@@ -68,8 +64,8 @@ var createErrorResponse = function (error) {
68
64
  code: responseData.status,
69
65
  success: false,
70
66
  data: responseData.data.message,
71
- error: '',
72
- message: '',
67
+ error: "",
68
+ message: "",
73
69
  };
74
70
  }
75
71
  else if (error.response && error.response.status === 400) {
@@ -78,229 +74,329 @@ var createErrorResponse = function (error) {
78
74
  code: responseData.status,
79
75
  success: false,
80
76
  data: "Please Check Your Credentials",
81
- error: '',
82
- message: '',
77
+ error: "",
78
+ message: "",
83
79
  };
84
80
  }
85
81
  return {
86
82
  code: error.response.code,
87
83
  success: false,
88
84
  data: "",
89
- error: 'Please check your project name or publish again.',
90
- message: '',
85
+ error: "Please check your project name or publish again.",
86
+ message: "",
91
87
  };
92
88
  };
89
+ var processResponse = function (result) {
90
+ console.log("result", result);
91
+ if (result.status === "FAILED") {
92
+ if (result.error) {
93
+ if (result.error.errStatus === 401) {
94
+ return {
95
+ code: result.error.errStatus,
96
+ success: false,
97
+ error: result.error.message,
98
+ message: result.error.message,
99
+ data: "",
100
+ };
101
+ }
102
+ }
103
+ return {
104
+ code: 400,
105
+ success: false,
106
+ error: "API Failed",
107
+ message: "",
108
+ data: result,
109
+ };
110
+ }
111
+ else {
112
+ if (result.code === 404) {
113
+ return {
114
+ code: result.code,
115
+ success: false,
116
+ error: result.data ? result.data : result,
117
+ message: result.data ? result.data : result,
118
+ data: "",
119
+ };
120
+ }
121
+ return { code: 200, success: true, error: "", message: "", data: result };
122
+ }
123
+ };
93
124
  var getAllItems = function (baseurl, headers, collectionName) { return __awaiter(void 0, void 0, void 0, function () {
94
- var url, response, error_1;
125
+ var url, response, result, error_1;
95
126
  return __generator(this, function (_a) {
96
127
  switch (_a.label) {
97
128
  case 0:
98
- _a.trys.push([0, 2, , 3]);
129
+ _a.trys.push([0, 3, , 4]);
99
130
  url = "".concat(baseurl, "/collection/").concat(collectionName, "/items");
100
- return [4 /*yield*/, axios_1.default.get(url, { headers: headers })];
131
+ return [4 /*yield*/, fetch(url, { method: "GET", headers: headers })];
101
132
  case 1:
102
133
  response = _a.sent();
103
- if (response.data && response.data.code === 404) {
104
- return [2 /*return*/, { success: false, data: response.data.data, error: '', message: '' }];
105
- }
106
- return [2 /*return*/, { success: true, data: response.data, error: '', message: '' }];
134
+ return [4 /*yield*/, response.json()];
107
135
  case 2:
136
+ result = _a.sent();
137
+ return [2 /*return*/, processResponse(result)];
138
+ case 3:
108
139
  error_1 = _a.sent();
109
140
  return [2 /*return*/, createErrorResponse(error_1)];
110
- case 3: return [2 /*return*/];
141
+ case 4: return [2 /*return*/];
111
142
  }
112
143
  });
113
144
  }); };
114
145
  exports.getAllItems = getAllItems;
115
146
  var createItem = function (baseurl, headers, collectionName, body) { return __awaiter(void 0, void 0, void 0, function () {
116
- var url, response, error_2;
147
+ var url, response, result, error_2;
117
148
  return __generator(this, function (_a) {
118
149
  switch (_a.label) {
119
150
  case 0:
120
- _a.trys.push([0, 2, , 3]);
151
+ _a.trys.push([0, 5, , 6]);
121
152
  url = "".concat(baseurl, "/collection/").concat(collectionName, "/items");
122
- return [4 /*yield*/, axios_1.default.post(url, body, {
123
- headers: headers
153
+ return [4 /*yield*/, fetch(url, {
154
+ method: "POST",
155
+ headers: headers,
156
+ body: JSON.stringify(body),
124
157
  })];
125
158
  case 1:
126
159
  response = _a.sent();
127
- if (response.data && response.data.code === 404) {
128
- return [2 /*return*/, { success: false, data: response.data.data, error: '', message: '' }];
129
- }
130
- return [2 /*return*/, { success: true, data: response.data, error: '', message: '' }];
131
- case 2:
160
+ if (!(response.status && response.status === 404)) return [3 /*break*/, 2];
161
+ return [2 /*return*/, {
162
+ success: false,
163
+ data: "Collection Not Found",
164
+ error: "",
165
+ message: "",
166
+ }];
167
+ case 2: return [4 /*yield*/, response.json()];
168
+ case 3:
169
+ result = _a.sent();
170
+ return [2 /*return*/, {
171
+ code: result.code,
172
+ success: true,
173
+ data: result,
174
+ error: "",
175
+ message: "",
176
+ }];
177
+ case 4: return [3 /*break*/, 6];
178
+ case 5:
132
179
  error_2 = _a.sent();
133
180
  return [2 /*return*/, createErrorResponse(error_2)];
134
- case 3: return [2 /*return*/];
181
+ case 6: return [2 /*return*/];
135
182
  }
136
183
  });
137
184
  }); };
138
185
  exports.createItem = createItem;
139
186
  var getItemsWithFilter = function (baseurl, headers, collectionName, filterUuid) { return __awaiter(void 0, void 0, void 0, function () {
140
- var url, response, error_3;
187
+ var url, response, result, error_3;
141
188
  return __generator(this, function (_a) {
142
189
  switch (_a.label) {
143
190
  case 0:
144
- _a.trys.push([0, 2, , 3]);
191
+ _a.trys.push([0, 3, , 4]);
145
192
  url = "".concat(baseurl, "/collection/").concat(collectionName, "/filter/").concat(filterUuid, "/items");
146
- return [4 /*yield*/, axios_1.default.get(url, {
147
- headers: headers
148
- })];
193
+ return [4 /*yield*/, fetch(url, { method: "GET", headers: headers })];
149
194
  case 1:
150
195
  response = _a.sent();
151
- return [2 /*return*/, { success: true, data: response.data, error: '', message: '' }];
196
+ return [4 /*yield*/, response.json()];
152
197
  case 2:
198
+ result = _a.sent();
199
+ return [2 /*return*/, processResponse(result)];
200
+ case 3:
153
201
  error_3 = _a.sent();
154
202
  return [2 /*return*/, createErrorResponse(error_3)];
155
- case 3: return [2 /*return*/];
203
+ case 4: return [2 /*return*/];
156
204
  }
157
205
  });
158
206
  }); };
159
207
  exports.getItemsWithFilter = getItemsWithFilter;
160
208
  var getItemsCountWithFilter = function (baseurl, headers, collectionName, filterUuid) { return __awaiter(void 0, void 0, void 0, function () {
161
- var url, response, error_4;
209
+ var url, response, result, error_4;
162
210
  return __generator(this, function (_a) {
163
211
  switch (_a.label) {
164
212
  case 0:
165
- _a.trys.push([0, 2, , 3]);
213
+ _a.trys.push([0, 3, , 4]);
166
214
  url = "".concat(baseurl, "/collection/").concat(collectionName, "/filter/").concat(filterUuid, "/count");
167
- return [4 /*yield*/, axios_1.default.get(url, {
168
- headers: headers
169
- })];
215
+ return [4 /*yield*/, fetch(url, { method: "GET", headers: headers })];
170
216
  case 1:
171
217
  response = _a.sent();
172
- return [2 /*return*/, { success: true, data: response.data, error: '', message: '' }];
218
+ return [4 /*yield*/, response.json()];
173
219
  case 2:
220
+ result = _a.sent();
221
+ return [2 /*return*/, processResponse(result)];
222
+ case 3:
174
223
  error_4 = _a.sent();
175
224
  return [2 /*return*/, createErrorResponse(error_4)];
176
- case 3: return [2 /*return*/];
225
+ case 4: return [2 /*return*/];
177
226
  }
178
227
  });
179
228
  }); };
180
229
  exports.getItemsCountWithFilter = getItemsCountWithFilter;
181
230
  var getItemWithUuid = function (baseurl, headers, collectionName, itemUuid) { return __awaiter(void 0, void 0, void 0, function () {
182
- var url, response, error_5;
231
+ var url, response, result, error_5;
183
232
  return __generator(this, function (_a) {
184
233
  switch (_a.label) {
185
234
  case 0:
186
- _a.trys.push([0, 2, , 3]);
235
+ _a.trys.push([0, 5, , 6]);
187
236
  url = "".concat(baseurl, "/collection/").concat(collectionName, "/item/").concat(itemUuid);
188
- return [4 /*yield*/, axios_1.default.get(url, {
189
- headers: headers
190
- })];
237
+ return [4 /*yield*/, fetch(url, { method: "GET", headers: headers })];
191
238
  case 1:
192
239
  response = _a.sent();
193
- return [2 /*return*/, { success: true, data: response.data, error: '', message: '' }];
194
- case 2:
240
+ if (!(response.status && response.status === 404)) return [3 /*break*/, 2];
241
+ return [2 /*return*/, {
242
+ code: response.status,
243
+ success: false,
244
+ data: "Please Check ItemUuid OR Collection Name",
245
+ error: "",
246
+ message: "",
247
+ }];
248
+ case 2: return [4 /*yield*/, response.json()];
249
+ case 3:
250
+ result = _a.sent();
251
+ return [2 /*return*/, processResponse(result)];
252
+ case 4: return [3 /*break*/, 6];
253
+ case 5:
195
254
  error_5 = _a.sent();
196
255
  return [2 /*return*/, createErrorResponse(error_5)];
197
- case 3: return [2 /*return*/];
256
+ case 6: return [2 /*return*/];
198
257
  }
199
258
  });
200
259
  }); };
201
260
  exports.getItemWithUuid = getItemWithUuid;
202
261
  var updateItemWithUuid = function (baseurl, headers, collectionName, itemUuid, body) { return __awaiter(void 0, void 0, void 0, function () {
203
- var url, response, error_6;
262
+ var url, response, result, error_6;
204
263
  return __generator(this, function (_a) {
205
264
  switch (_a.label) {
206
265
  case 0:
207
- _a.trys.push([0, 2, , 3]);
266
+ _a.trys.push([0, 5, , 6]);
208
267
  url = "".concat(baseurl, "/collection/").concat(collectionName, "/item/").concat(itemUuid);
209
- return [4 /*yield*/, axios_1.default.put(url, body, {
210
- headers: headers
268
+ return [4 /*yield*/, fetch(url, {
269
+ method: "PUT",
270
+ headers: headers,
271
+ body: JSON.stringify(body),
211
272
  })];
212
273
  case 1:
213
274
  response = _a.sent();
214
- return [2 /*return*/, { success: true, data: response.data, error: '', message: '' }];
215
- case 2:
275
+ if (!(response.status && response.status === 404)) return [3 /*break*/, 2];
276
+ return [2 /*return*/, {
277
+ code: response.status,
278
+ success: false,
279
+ data: "Please Check ItemUuid OR Collection Name",
280
+ error: "",
281
+ message: "",
282
+ }];
283
+ case 2: return [4 /*yield*/, response.json()];
284
+ case 3:
285
+ result = _a.sent();
286
+ return [2 /*return*/, processResponse(result)];
287
+ case 4: return [3 /*break*/, 6];
288
+ case 5:
216
289
  error_6 = _a.sent();
217
290
  return [2 /*return*/, createErrorResponse(error_6)];
218
- case 3: return [2 /*return*/];
291
+ case 6: return [2 /*return*/];
219
292
  }
220
293
  });
221
294
  }); };
222
295
  exports.updateItemWithUuid = updateItemWithUuid;
223
296
  var deleteItemWithUuid = function (baseurl, headers, collectionName, itemUuid) { return __awaiter(void 0, void 0, void 0, function () {
224
- var url, response, error_7;
225
- var _a;
226
- return __generator(this, function (_b) {
227
- switch (_b.label) {
297
+ var url, response, result, error_7;
298
+ return __generator(this, function (_a) {
299
+ switch (_a.label) {
228
300
  case 0:
229
- _b.trys.push([0, 2, , 3]);
301
+ _a.trys.push([0, 3, , 4]);
230
302
  url = "".concat(baseurl, "/collection/").concat(collectionName, "/item/").concat(itemUuid);
231
- return [4 /*yield*/, axios_1.default.delete(url, {
232
- headers: headers
303
+ return [4 /*yield*/, fetch(url, {
304
+ method: "DELETE",
305
+ headers: headers,
233
306
  })];
234
307
  case 1:
235
- response = _b.sent();
236
- return [2 /*return*/, { success: true, data: (_a = response.data) === null || _a === void 0 ? void 0 : _a.message, error: '', message: '' }];
308
+ response = _a.sent();
309
+ return [4 /*yield*/, response.json()];
237
310
  case 2:
238
- error_7 = _b.sent();
311
+ result = _a.sent();
312
+ return [2 /*return*/, {
313
+ code: result.code,
314
+ success: result.code == 200 ? true : false,
315
+ data: result.message,
316
+ error: "",
317
+ message: "",
318
+ }];
319
+ case 3:
320
+ error_7 = _a.sent();
239
321
  return [2 /*return*/, createErrorResponse(error_7)];
240
- case 3: return [2 /*return*/];
322
+ case 4: return [2 /*return*/];
241
323
  }
242
324
  });
243
325
  }); };
244
326
  exports.deleteItemWithUuid = deleteItemWithUuid;
245
327
  var bulkDeleteItems = function (baseurl, headers, collectionName, body) { return __awaiter(void 0, void 0, void 0, function () {
246
- var url, response, error_8;
328
+ var url, response, result, error_8;
247
329
  return __generator(this, function (_a) {
248
330
  switch (_a.label) {
249
331
  case 0:
250
- _a.trys.push([0, 2, , 3]);
332
+ _a.trys.push([0, 3, , 4]);
251
333
  url = "".concat(baseurl, "/collection/").concat(collectionName, "/bulkDelete");
252
- return [4 /*yield*/, axios_1.default.post(url, body, {
253
- headers: headers
334
+ return [4 /*yield*/, fetch(url, {
335
+ method: "POST",
336
+ headers: headers,
337
+ body: body,
254
338
  })];
255
339
  case 1:
256
340
  response = _a.sent();
257
- return [2 /*return*/, { success: true, data: response.data, error: '', message: '' }];
341
+ return [4 /*yield*/, response.json()];
258
342
  case 2:
343
+ result = _a.sent();
344
+ return [2 /*return*/, { success: true, data: result.data, error: "", message: "" }];
345
+ case 3:
259
346
  error_8 = _a.sent();
260
347
  return [2 /*return*/, createErrorResponse(error_8)];
261
- case 3: return [2 /*return*/];
348
+ case 4: return [2 /*return*/];
262
349
  }
263
350
  });
264
351
  }); };
265
352
  exports.bulkDeleteItems = bulkDeleteItems;
266
353
  var getItemsByids = function (baseurl, headers, collectionName, body) { return __awaiter(void 0, void 0, void 0, function () {
267
- var url, response, error_9;
354
+ var url, response, result, error_9;
268
355
  return __generator(this, function (_a) {
269
356
  switch (_a.label) {
270
357
  case 0:
271
- _a.trys.push([0, 2, , 3]);
358
+ _a.trys.push([0, 3, , 4]);
272
359
  url = "".concat(baseurl, "/collection/").concat(collectionName, "/itemsbyids");
273
- return [4 /*yield*/, axios_1.default.post(url, body, {
274
- headers: headers
360
+ return [4 /*yield*/, fetch(url, {
361
+ method: "POST",
362
+ headers: headers,
363
+ body: body,
275
364
  })];
276
365
  case 1:
277
366
  response = _a.sent();
278
- return [2 /*return*/, { success: true, data: response.data, error: '', message: '' }];
367
+ return [4 /*yield*/, response.json()];
279
368
  case 2:
369
+ result = _a.sent();
370
+ return [2 /*return*/, { success: true, data: result.data, error: "", message: "" }];
371
+ case 3:
280
372
  error_9 = _a.sent();
281
373
  return [2 /*return*/, createErrorResponse(error_9)];
282
- case 3: return [2 /*return*/];
374
+ case 4: return [2 /*return*/];
283
375
  }
284
376
  });
285
377
  }); };
286
378
  exports.getItemsByids = getItemsByids;
287
379
  var sendEmail = function (baseurl, headers, templateId, sendTo) { return __awaiter(void 0, void 0, void 0, function () {
288
- var url, response, error_10;
380
+ var url, response, result, error_10;
289
381
  return __generator(this, function (_a) {
290
382
  switch (_a.label) {
291
383
  case 0:
292
- _a.trys.push([0, 2, , 3]);
384
+ _a.trys.push([0, 3, , 4]);
293
385
  url = "".concat(baseurl, "/sendEmail/").concat(templateId, "/user/").concat(sendTo);
294
- return [4 /*yield*/, axios_1.default.post(url, "", {
295
- headers: headers
386
+ return [4 /*yield*/, fetch(url, {
387
+ method: "POST",
388
+ headers: headers,
296
389
  })];
297
390
  case 1:
298
391
  response = _a.sent();
299
- return [2 /*return*/, { success: true, data: response.data, error: '', message: '' }];
392
+ return [4 /*yield*/, response.json()];
300
393
  case 2:
394
+ result = _a.sent();
395
+ return [2 /*return*/, { success: true, data: result, error: "", message: "" }];
396
+ case 3:
301
397
  error_10 = _a.sent();
302
398
  return [2 /*return*/, createErrorResponse(error_10)];
303
- case 3: return [2 /*return*/];
399
+ case 4: return [2 /*return*/];
304
400
  }
305
401
  });
306
402
  }); };
@@ -313,4 +409,4 @@ exports.sendEmail = sendEmail;
313
409
  * error,
314
410
  * message,
315
411
  * }
316
- */
412
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drapcode-developer-sdk",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "main": "build/index.js",
5
5
  "types": "build/index.d.ts",
6
6
  "files": [
@@ -8,27 +8,23 @@
8
8
  ],
9
9
  "scripts": {
10
10
  "clean": "del ./build/*",
11
- "link-lib": "npm link drapcode-constant drapcode-logger",
12
- "build": "npm run clean && npm run link-lib && tsc"
11
+ "build": "npm run clean && tsc"
13
12
  },
14
13
  "keywords": [
15
14
  "drapcode",
16
15
  "developer",
17
- "sdk",
18
- "axios",
19
- "express"
16
+ "sdk"
20
17
  ],
21
18
  "author": "Drapcode",
22
19
  "license": "ISC",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/Drapcode/developer-sdk.git"
23
+ },
23
24
  "devDependencies": {
24
- "@types/express": "^4.17.21",
25
- "@types/lodash": "^4.14.179",
26
25
  "del-cli": "^5.0.0",
27
26
  "typescript": "^4.0.2"
28
27
  },
29
- "dependencies": {
30
- "axios": "^1.1.2",
31
- "express": "^4.17.1"
32
- },
28
+ "dependencies": {},
33
29
  "description": ""
34
30
  }