drapcode-developer-sdk 1.0.4 → 1.0.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.
- package/README.md +26 -1
- package/build/index.d.ts +18 -5
- package/build/index.js +20 -3
- package/build/methods/methods.d.ts +16 -5
- package/build/methods/methods.js +59 -38
- package/build/utils/crypt.d.ts +2 -0
- package/build/utils/crypt.js +99 -0
- package/build/utils/index.d.ts +26 -0
- package/build/utils/index.js +112 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ const api = new DrapcodeApis(
|
|
|
32
32
|
### Example:
|
|
33
33
|
|
|
34
34
|
```
|
|
35
|
-
const drapcodeApi = new DrapcodeApis("test-project-7138");
|
|
35
|
+
const drapcodeApi = new DrapcodeApis("test-project-7138",xApiKey, authorization, environment);
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
# Methods
|
|
@@ -161,3 +161,28 @@ await drapcodeApi.sendEmail("345-678", "support@drapcode.com");
|
|
|
161
161
|
Sends an email using the template ID "345-678" to the email address "support@drapcode.com".
|
|
162
162
|
|
|
163
163
|
For better experience, utilize async/await syntax when using these methods.
|
|
164
|
+
|
|
165
|
+
## Encryption Related
|
|
166
|
+
|
|
167
|
+
We have two methods related to encryption.
|
|
168
|
+
|
|
169
|
+
1. encryptData
|
|
170
|
+
2. decryptData
|
|
171
|
+
|
|
172
|
+
### Encrypt Data
|
|
173
|
+
|
|
174
|
+
```
|
|
175
|
+
await encryptData(content, publicKey)
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
**content:** Content/Text you want to encrypt.
|
|
179
|
+
**publicKey:** Public key, which will be used to encrypt data.
|
|
180
|
+
|
|
181
|
+
### Decrypt Data
|
|
182
|
+
|
|
183
|
+
```
|
|
184
|
+
await decryptData(content, publicKey)
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
**content:** Content/Text you want to decrypt.
|
|
188
|
+
**publicKey:** Public key, which was used to decrypt data.
|
package/build/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ 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<{
|
|
10
|
+
getAllItems(collectionName: string, reqQuery: any): Promise<{
|
|
11
11
|
code: any;
|
|
12
12
|
success: boolean;
|
|
13
13
|
data: any;
|
|
@@ -19,18 +19,21 @@ export declare class DrapcodeApis {
|
|
|
19
19
|
error: any;
|
|
20
20
|
message: any;
|
|
21
21
|
data: string;
|
|
22
|
+
totalItems?: undefined;
|
|
23
|
+
totalPages?: undefined;
|
|
22
24
|
}>;
|
|
23
25
|
createItem(collectionName: string, body: any): Promise<{
|
|
24
|
-
code: any;
|
|
25
26
|
success: boolean;
|
|
26
|
-
data:
|
|
27
|
+
data: string;
|
|
27
28
|
error: string;
|
|
28
29
|
message: string;
|
|
30
|
+
code?: undefined;
|
|
29
31
|
} | {
|
|
32
|
+
code: any;
|
|
30
33
|
success: boolean;
|
|
31
|
-
data:
|
|
34
|
+
data: any;
|
|
32
35
|
error: string;
|
|
33
|
-
message:
|
|
36
|
+
message: any;
|
|
34
37
|
}>;
|
|
35
38
|
getItemsWithFilter(collectionName: string, filterUuid: string): Promise<{
|
|
36
39
|
code: any;
|
|
@@ -44,6 +47,8 @@ export declare class DrapcodeApis {
|
|
|
44
47
|
error: any;
|
|
45
48
|
message: any;
|
|
46
49
|
data: string;
|
|
50
|
+
totalItems?: undefined;
|
|
51
|
+
totalPages?: undefined;
|
|
47
52
|
}>;
|
|
48
53
|
getItemsCountWithFilter(collectionName: string, filterUuid: string): Promise<{
|
|
49
54
|
code: any;
|
|
@@ -57,6 +62,8 @@ export declare class DrapcodeApis {
|
|
|
57
62
|
error: any;
|
|
58
63
|
message: any;
|
|
59
64
|
data: string;
|
|
65
|
+
totalItems?: undefined;
|
|
66
|
+
totalPages?: undefined;
|
|
60
67
|
}>;
|
|
61
68
|
getItemWithUuid(collectionName: string, itemUuid: string): Promise<{
|
|
62
69
|
code: any;
|
|
@@ -70,6 +77,8 @@ export declare class DrapcodeApis {
|
|
|
70
77
|
error: any;
|
|
71
78
|
message: any;
|
|
72
79
|
data: string;
|
|
80
|
+
totalItems?: undefined;
|
|
81
|
+
totalPages?: undefined;
|
|
73
82
|
}>;
|
|
74
83
|
updateItemWithUuid(collectionName: string, itemUuid: string, body: any): Promise<{
|
|
75
84
|
code: any;
|
|
@@ -83,6 +92,8 @@ export declare class DrapcodeApis {
|
|
|
83
92
|
error: any;
|
|
84
93
|
message: any;
|
|
85
94
|
data: string;
|
|
95
|
+
totalItems?: undefined;
|
|
96
|
+
totalPages?: undefined;
|
|
86
97
|
}>;
|
|
87
98
|
deleteItemWithUuid(collectionName: string, itemUuid: string): Promise<{
|
|
88
99
|
code: any;
|
|
@@ -128,3 +139,5 @@ export declare class DrapcodeApis {
|
|
|
128
139
|
message: string;
|
|
129
140
|
}>;
|
|
130
141
|
}
|
|
142
|
+
export * from "./utils/index";
|
|
143
|
+
export * from "./utils/crypt";
|
package/build/index.js
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
17
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
18
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -50,7 +64,7 @@ var DrapcodeApis = /** @class */ (function () {
|
|
|
50
64
|
this.environment = environment;
|
|
51
65
|
}
|
|
52
66
|
DrapcodeApis.prototype.getBaseUrl = function () {
|
|
53
|
-
switch (this.environment) {
|
|
67
|
+
switch (this.environment.toUpperCase()) {
|
|
54
68
|
case "PRODUCTION":
|
|
55
69
|
return "https://".concat(this.project_seo_name, ".api.").concat(this.API_PATH);
|
|
56
70
|
case "PREVIEW":
|
|
@@ -74,12 +88,13 @@ var DrapcodeApis = /** @class */ (function () {
|
|
|
74
88
|
if (this.authorization) {
|
|
75
89
|
headers["Authorization"] = this.authorization;
|
|
76
90
|
}
|
|
91
|
+
console.log("here is header", headers);
|
|
77
92
|
return headers;
|
|
78
93
|
};
|
|
79
|
-
DrapcodeApis.prototype.getAllItems = function (collectionName) {
|
|
94
|
+
DrapcodeApis.prototype.getAllItems = function (collectionName, reqQuery) {
|
|
80
95
|
return __awaiter(this, void 0, void 0, function () {
|
|
81
96
|
return __generator(this, function (_a) {
|
|
82
|
-
return [2 /*return*/, (0, methods_1.getAllItems)(this.getBaseUrl(), this.getHeaders(), collectionName)];
|
|
97
|
+
return [2 /*return*/, (0, methods_1.getAllItems)(this.getBaseUrl(), this.getHeaders(), collectionName, reqQuery)];
|
|
83
98
|
});
|
|
84
99
|
});
|
|
85
100
|
};
|
|
@@ -149,3 +164,5 @@ var DrapcodeApis = /** @class */ (function () {
|
|
|
149
164
|
return DrapcodeApis;
|
|
150
165
|
}());
|
|
151
166
|
exports.DrapcodeApis = DrapcodeApis;
|
|
167
|
+
__exportStar(require("./utils/index"), exports);
|
|
168
|
+
__exportStar(require("./utils/crypt"), exports);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const getAllItems: (baseurl: string, headers: Record<string, string>, collectionName: string) => Promise<{
|
|
1
|
+
export declare const getAllItems: (baseurl: string, headers: Record<string, string>, collectionName: string, reqQuery: any) => Promise<{
|
|
2
2
|
code: any;
|
|
3
3
|
success: boolean;
|
|
4
4
|
data: any;
|
|
@@ -10,18 +10,21 @@ export declare const getAllItems: (baseurl: string, headers: Record<string, stri
|
|
|
10
10
|
error: any;
|
|
11
11
|
message: any;
|
|
12
12
|
data: string;
|
|
13
|
+
totalItems?: undefined;
|
|
14
|
+
totalPages?: undefined;
|
|
13
15
|
}>;
|
|
14
16
|
export declare const createItem: (baseurl: string, headers: Record<string, string>, collectionName: string, body: any) => Promise<{
|
|
15
|
-
code: any;
|
|
16
17
|
success: boolean;
|
|
17
|
-
data:
|
|
18
|
+
data: string;
|
|
18
19
|
error: string;
|
|
19
20
|
message: string;
|
|
21
|
+
code?: undefined;
|
|
20
22
|
} | {
|
|
23
|
+
code: any;
|
|
21
24
|
success: boolean;
|
|
22
|
-
data:
|
|
25
|
+
data: any;
|
|
23
26
|
error: string;
|
|
24
|
-
message:
|
|
27
|
+
message: any;
|
|
25
28
|
}>;
|
|
26
29
|
export declare const getItemsWithFilter: (baseurl: string, headers: Record<string, string>, collectionName: string, filterUuid: string) => Promise<{
|
|
27
30
|
code: any;
|
|
@@ -35,6 +38,8 @@ export declare const getItemsWithFilter: (baseurl: string, headers: Record<strin
|
|
|
35
38
|
error: any;
|
|
36
39
|
message: any;
|
|
37
40
|
data: string;
|
|
41
|
+
totalItems?: undefined;
|
|
42
|
+
totalPages?: undefined;
|
|
38
43
|
}>;
|
|
39
44
|
export declare const getItemsCountWithFilter: (baseurl: string, headers: Record<string, string>, collectionName: string, filterUuid: string) => Promise<{
|
|
40
45
|
code: any;
|
|
@@ -48,6 +53,8 @@ export declare const getItemsCountWithFilter: (baseurl: string, headers: Record<
|
|
|
48
53
|
error: any;
|
|
49
54
|
message: any;
|
|
50
55
|
data: string;
|
|
56
|
+
totalItems?: undefined;
|
|
57
|
+
totalPages?: undefined;
|
|
51
58
|
}>;
|
|
52
59
|
export declare const getItemWithUuid: (baseurl: string, headers: Record<string, string>, collectionName: string, itemUuid: string) => Promise<{
|
|
53
60
|
code: any;
|
|
@@ -61,6 +68,8 @@ export declare const getItemWithUuid: (baseurl: string, headers: Record<string,
|
|
|
61
68
|
error: any;
|
|
62
69
|
message: any;
|
|
63
70
|
data: string;
|
|
71
|
+
totalItems?: undefined;
|
|
72
|
+
totalPages?: undefined;
|
|
64
73
|
}>;
|
|
65
74
|
export declare const updateItemWithUuid: (baseurl: string, headers: Record<string, string>, collectionName: string, itemUuid: string, body: any) => Promise<{
|
|
66
75
|
code: any;
|
|
@@ -74,6 +83,8 @@ export declare const updateItemWithUuid: (baseurl: string, headers: Record<strin
|
|
|
74
83
|
error: any;
|
|
75
84
|
message: any;
|
|
76
85
|
data: string;
|
|
86
|
+
totalItems?: undefined;
|
|
87
|
+
totalPages?: undefined;
|
|
77
88
|
}>;
|
|
78
89
|
export declare const deleteItemWithUuid: (baseurl: string, headers: Record<string, string>, collectionName: string, itemUuid: string) => Promise<{
|
|
79
90
|
code: any;
|
package/build/methods/methods.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -38,6 +49,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
38
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
50
|
exports.sendEmail = exports.getItemsByids = exports.bulkDeleteItems = exports.deleteItemWithUuid = exports.updateItemWithUuid = exports.getItemWithUuid = exports.getItemsCountWithFilter = exports.getItemsWithFilter = exports.createItem = exports.getAllItems = void 0;
|
|
40
51
|
var createErrorResponse = function (error) {
|
|
52
|
+
var _a;
|
|
41
53
|
if (error.response && error.response.status === 404) {
|
|
42
54
|
var responseData = error.response.data;
|
|
43
55
|
var finalData = void 0;
|
|
@@ -71,7 +83,7 @@ var createErrorResponse = function (error) {
|
|
|
71
83
|
else if (error.response && error.response.status === 400) {
|
|
72
84
|
var responseData = error.response;
|
|
73
85
|
return {
|
|
74
|
-
code: responseData.status,
|
|
86
|
+
code: responseData === null || responseData === void 0 ? void 0 : responseData.status,
|
|
75
87
|
success: false,
|
|
76
88
|
data: "Please Check Your Credentials",
|
|
77
89
|
error: "",
|
|
@@ -79,7 +91,7 @@ var createErrorResponse = function (error) {
|
|
|
79
91
|
};
|
|
80
92
|
}
|
|
81
93
|
return {
|
|
82
|
-
code: error.response.code,
|
|
94
|
+
code: (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.code,
|
|
83
95
|
success: false,
|
|
84
96
|
data: "",
|
|
85
97
|
error: "Please check your project name or publish again.",
|
|
@@ -87,47 +99,56 @@ var createErrorResponse = function (error) {
|
|
|
87
99
|
};
|
|
88
100
|
};
|
|
89
101
|
var processResponse = function (result) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
}
|
|
102
|
+
var _a, _b;
|
|
103
|
+
var defaultMessages = {
|
|
104
|
+
401: "Unauthorized",
|
|
105
|
+
404: "Not Found",
|
|
106
|
+
409: "Conflict",
|
|
107
|
+
500: "Internal Server Error",
|
|
108
|
+
};
|
|
109
|
+
if ((result === null || result === void 0 ? void 0 : result.status) === "FAILED") {
|
|
110
|
+
var statusCode = ((_a = result === null || result === void 0 ? void 0 : result.error) === null || _a === void 0 ? void 0 : _a.errStatus) || 400;
|
|
111
|
+
var errorMessage = ((_b = result === null || result === void 0 ? void 0 : result.error) === null || _b === void 0 ? void 0 : _b.message) || defaultMessages[statusCode] || "API Failed";
|
|
103
112
|
return {
|
|
104
|
-
code:
|
|
113
|
+
code: statusCode,
|
|
105
114
|
success: false,
|
|
106
|
-
error:
|
|
107
|
-
message:
|
|
108
|
-
data:
|
|
115
|
+
error: errorMessage,
|
|
116
|
+
message: errorMessage,
|
|
117
|
+
data: "",
|
|
109
118
|
};
|
|
110
119
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
return { code: 200, success: true, error: "", message: "", data: result };
|
|
120
|
+
if ((result === null || result === void 0 ? void 0 : result.code) && (result === null || result === void 0 ? void 0 : result.code) !== 200) {
|
|
121
|
+
var errorMessage = (result === null || result === void 0 ? void 0 : result.data) || defaultMessages[result === null || result === void 0 ? void 0 : result.code] || "An error occurred";
|
|
122
|
+
return {
|
|
123
|
+
code: result.code,
|
|
124
|
+
success: false,
|
|
125
|
+
error: errorMessage,
|
|
126
|
+
message: errorMessage,
|
|
127
|
+
data: "",
|
|
128
|
+
};
|
|
122
129
|
}
|
|
130
|
+
return {
|
|
131
|
+
code: 200,
|
|
132
|
+
success: true,
|
|
133
|
+
error: "",
|
|
134
|
+
message: "",
|
|
135
|
+
data: (result === null || result === void 0 ? void 0 : result.result) || result,
|
|
136
|
+
totalItems: (result === null || result === void 0 ? void 0 : result.totalItems) || 0,
|
|
137
|
+
totalPages: (result === null || result === void 0 ? void 0 : result.totalPages) || 0,
|
|
138
|
+
};
|
|
123
139
|
};
|
|
124
|
-
var getAllItems = function (baseurl, headers, collectionName) { return __awaiter(void 0, void 0, void 0, function () {
|
|
125
|
-
var url, response, result, error_1;
|
|
140
|
+
var getAllItems = function (baseurl, headers, collectionName, reqQuery) { return __awaiter(void 0, void 0, void 0, function () {
|
|
141
|
+
var queryParams, url, response, result, error_1;
|
|
126
142
|
return __generator(this, function (_a) {
|
|
127
143
|
switch (_a.label) {
|
|
128
144
|
case 0:
|
|
129
145
|
_a.trys.push([0, 3, , 4]);
|
|
130
|
-
|
|
146
|
+
queryParams = new URLSearchParams(__assign(__assign(__assign(__assign({}, ((reqQuery === null || reqQuery === void 0 ? void 0 : reqQuery.sortField) && { sortField: reqQuery.sortField })), ((reqQuery === null || reqQuery === void 0 ? void 0 : reqQuery.sortOrder) && { sortOrder: reqQuery.sortOrder })), ((reqQuery === null || reqQuery === void 0 ? void 0 : reqQuery.searchTerm) && { searchTerm: reqQuery.searchTerm })), ((reqQuery === null || reqQuery === void 0 ? void 0 : reqQuery.isPagination) && {
|
|
147
|
+
page: reqQuery.page,
|
|
148
|
+
limit: reqQuery.limit,
|
|
149
|
+
})));
|
|
150
|
+
url = "".concat(baseurl, "/collection/").concat(collectionName, "/items?").concat(queryParams.toString());
|
|
151
|
+
console.log("Generated URL:", url, headers, "Query:", reqQuery);
|
|
131
152
|
return [4 /*yield*/, fetch(url, { method: "GET", headers: headers })];
|
|
132
153
|
case 1:
|
|
133
154
|
response = _a.sent();
|
|
@@ -168,11 +189,11 @@ var createItem = function (baseurl, headers, collectionName, body) { return __aw
|
|
|
168
189
|
case 3:
|
|
169
190
|
result = _a.sent();
|
|
170
191
|
return [2 /*return*/, {
|
|
171
|
-
code: result.code,
|
|
192
|
+
code: result === null || result === void 0 ? void 0 : result.code,
|
|
172
193
|
success: true,
|
|
173
|
-
data: result,
|
|
194
|
+
data: result === null || result === void 0 ? void 0 : result.data,
|
|
174
195
|
error: "",
|
|
175
|
-
message: "",
|
|
196
|
+
message: result.message || "",
|
|
176
197
|
}];
|
|
177
198
|
case 4: return [3 /*break*/, 6];
|
|
178
199
|
case 5:
|
|
@@ -310,8 +331,8 @@ var deleteItemWithUuid = function (baseurl, headers, collectionName, itemUuid) {
|
|
|
310
331
|
case 2:
|
|
311
332
|
result = _a.sent();
|
|
312
333
|
return [2 /*return*/, {
|
|
313
|
-
code: result.code,
|
|
314
|
-
success: result.code == 200 ? true : false,
|
|
334
|
+
code: result === null || result === void 0 ? void 0 : result.code,
|
|
335
|
+
success: (result === null || result === void 0 ? void 0 : result.code) == 200 ? true : false,
|
|
315
336
|
data: result.message,
|
|
316
337
|
error: "",
|
|
317
338
|
message: "",
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.decryptData = exports.encryptData = void 0;
|
|
43
|
+
var crypto_1 = __importDefault(require("crypto"));
|
|
44
|
+
var defaultAlgorithm = "aes-256-cbc";
|
|
45
|
+
var encryptData = function (data, key) { return __awaiter(void 0, void 0, void 0, function () {
|
|
46
|
+
var iv, keyBuffer, cipher, encryptedDataBuffer, result;
|
|
47
|
+
return __generator(this, function (_a) {
|
|
48
|
+
try {
|
|
49
|
+
iv = Buffer.from("i4mboZDwaNEC38YCzi77lw==", "base64");
|
|
50
|
+
keyBuffer = Buffer.from(key, "base64");
|
|
51
|
+
cipher = crypto_1.default.createCipheriv(defaultAlgorithm, keyBuffer, iv);
|
|
52
|
+
encryptedDataBuffer = cipher.update("".concat(data));
|
|
53
|
+
encryptedDataBuffer = Buffer.concat([encryptedDataBuffer, cipher.final()]);
|
|
54
|
+
result = encryptedDataBuffer.toString("base64");
|
|
55
|
+
return [2 /*return*/, handleExtraString(result, true)];
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
console.error("\n Error: ", error);
|
|
59
|
+
return [2 /*return*/, data];
|
|
60
|
+
}
|
|
61
|
+
return [2 /*return*/];
|
|
62
|
+
});
|
|
63
|
+
}); };
|
|
64
|
+
exports.encryptData = encryptData;
|
|
65
|
+
var decryptData = function (data, key) { return __awaiter(void 0, void 0, void 0, function () {
|
|
66
|
+
var iv, encryptedData, keyBuffer, decipher, decryptedBuffer;
|
|
67
|
+
return __generator(this, function (_a) {
|
|
68
|
+
try {
|
|
69
|
+
data = handleExtraString(data, false);
|
|
70
|
+
iv = Buffer.from("i4mboZDwaNEC38YCzi77lw==", "base64");
|
|
71
|
+
encryptedData = Buffer.from(data, "base64");
|
|
72
|
+
keyBuffer = Buffer.from(key, "base64");
|
|
73
|
+
decipher = crypto_1.default.createDecipheriv(defaultAlgorithm, keyBuffer, iv);
|
|
74
|
+
decryptedBuffer = decipher.update(encryptedData);
|
|
75
|
+
decryptedBuffer = Buffer.concat([decryptedBuffer, decipher.final()]);
|
|
76
|
+
return [2 /*return*/, decryptedBuffer.toString()];
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
console.error("\n Error: ", error);
|
|
80
|
+
return [2 /*return*/, data];
|
|
81
|
+
}
|
|
82
|
+
return [2 /*return*/];
|
|
83
|
+
});
|
|
84
|
+
}); };
|
|
85
|
+
exports.decryptData = decryptData;
|
|
86
|
+
var handleExtraString = function (key, append) {
|
|
87
|
+
if (append === void 0) { append = true; }
|
|
88
|
+
if (append) {
|
|
89
|
+
var start = crypto_1.default.randomBytes(2).toString("hex");
|
|
90
|
+
var end = crypto_1.default.randomBytes(2).toString("hex");
|
|
91
|
+
key = "".concat(start).concat(key).concat(end);
|
|
92
|
+
return key;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
key = key.substring(4, key.length);
|
|
96
|
+
key = key.substring(0, key.length - 4);
|
|
97
|
+
return key;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare enum MethodTypes {
|
|
2
|
+
POST = "post",
|
|
3
|
+
GET = "get",
|
|
4
|
+
PATCH = "patch",
|
|
5
|
+
PUT = "put",
|
|
6
|
+
DELETE = "delete"
|
|
7
|
+
}
|
|
8
|
+
export type APIData = {
|
|
9
|
+
method: MethodTypes;
|
|
10
|
+
url: string;
|
|
11
|
+
headers: any;
|
|
12
|
+
body: object;
|
|
13
|
+
};
|
|
14
|
+
export declare const makeAPICall: (apiData: APIData) => Promise<{
|
|
15
|
+
status: number;
|
|
16
|
+
error: null;
|
|
17
|
+
headers: Headers;
|
|
18
|
+
data: any;
|
|
19
|
+
message?: undefined;
|
|
20
|
+
} | {
|
|
21
|
+
status: number;
|
|
22
|
+
error: any;
|
|
23
|
+
message: any;
|
|
24
|
+
headers?: undefined;
|
|
25
|
+
data?: undefined;
|
|
26
|
+
}>;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.makeAPICall = exports.MethodTypes = void 0;
|
|
40
|
+
var ErrorTypes = {
|
|
41
|
+
INVALID_DATA: "Given data is not valid",
|
|
42
|
+
MISSING_URL: "Provided URL is not valid",
|
|
43
|
+
};
|
|
44
|
+
var MethodTypes;
|
|
45
|
+
(function (MethodTypes) {
|
|
46
|
+
MethodTypes["POST"] = "post";
|
|
47
|
+
MethodTypes["GET"] = "get";
|
|
48
|
+
MethodTypes["PATCH"] = "patch";
|
|
49
|
+
MethodTypes["PUT"] = "put";
|
|
50
|
+
MethodTypes["DELETE"] = "delete";
|
|
51
|
+
})(MethodTypes = exports.MethodTypes || (exports.MethodTypes = {}));
|
|
52
|
+
var makeAPICall = function (apiData) { return __awaiter(void 0, void 0, void 0, function () {
|
|
53
|
+
var method, url, headers, body, response, bodyMethods, extra, error_1;
|
|
54
|
+
var _a;
|
|
55
|
+
return __generator(this, function (_b) {
|
|
56
|
+
switch (_b.label) {
|
|
57
|
+
case 0:
|
|
58
|
+
console.log("API call started");
|
|
59
|
+
_b.label = 1;
|
|
60
|
+
case 1:
|
|
61
|
+
_b.trys.push([1, 4, , 5]);
|
|
62
|
+
if (!apiData) {
|
|
63
|
+
return [2 /*return*/, { status: 402, error: {}, message: ErrorTypes.INVALID_DATA }];
|
|
64
|
+
}
|
|
65
|
+
method = apiData.method, url = apiData.url, headers = apiData.headers, body = apiData.body;
|
|
66
|
+
if (!url) {
|
|
67
|
+
return [2 /*return*/, { status: 402, error: {}, message: ErrorTypes.MISSING_URL }];
|
|
68
|
+
}
|
|
69
|
+
if (!method) {
|
|
70
|
+
method = MethodTypes.GET;
|
|
71
|
+
}
|
|
72
|
+
response = null;
|
|
73
|
+
bodyMethods = [
|
|
74
|
+
MethodTypes.POST,
|
|
75
|
+
MethodTypes.PATCH,
|
|
76
|
+
MethodTypes.PUT,
|
|
77
|
+
];
|
|
78
|
+
extra = { method: method };
|
|
79
|
+
if (headers) {
|
|
80
|
+
extra.headers = headers;
|
|
81
|
+
}
|
|
82
|
+
if (body) {
|
|
83
|
+
extra.body = body;
|
|
84
|
+
}
|
|
85
|
+
return [4 /*yield*/, fetch(url, extra)];
|
|
86
|
+
case 2:
|
|
87
|
+
response = _b.sent();
|
|
88
|
+
if (!(response === null || response === void 0 ? void 0 : response.ok)) {
|
|
89
|
+
return [2 /*return*/, {
|
|
90
|
+
status: response === null || response === void 0 ? void 0 : response.status,
|
|
91
|
+
error: {},
|
|
92
|
+
message: response.statusText,
|
|
93
|
+
}];
|
|
94
|
+
}
|
|
95
|
+
console.log("API call finished");
|
|
96
|
+
_a = {
|
|
97
|
+
status: response.status,
|
|
98
|
+
error: null,
|
|
99
|
+
headers: response.headers
|
|
100
|
+
};
|
|
101
|
+
return [4 /*yield*/, response.json()];
|
|
102
|
+
case 3: return [2 /*return*/, (_a.data = _b.sent(),
|
|
103
|
+
_a)];
|
|
104
|
+
case 4:
|
|
105
|
+
error_1 = _b.sent();
|
|
106
|
+
console.log("error", error_1);
|
|
107
|
+
return [2 /*return*/, { status: 402, error: error_1, message: error_1.message }];
|
|
108
|
+
case 5: return [2 /*return*/];
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}); };
|
|
112
|
+
exports.makeAPICall = makeAPICall;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drapcode-developer-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"main": "build/index.js",
|
|
5
5
|
"types": "build/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"url": "https://github.com/Drapcode/developer-sdk.git"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
+
"@types/node": "^22.12.0",
|
|
25
26
|
"del-cli": "^5.0.0",
|
|
26
27
|
"typescript": "^4.0.2"
|
|
27
28
|
},
|
|
28
|
-
"dependencies": {},
|
|
29
29
|
"description": ""
|
|
30
30
|
}
|