drapcode-developer-sdk 1.0.0

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 ADDED
@@ -0,0 +1,128 @@
1
+ # Drapcode APIs Documentation
2
+
3
+ The `Drapcode APIs` class provides methods for interacting with the Drapcode API. This documentation outlines how to use the class and its available methods.
4
+
5
+ ## Initialization
6
+
7
+ To use the `DrapcodeApis` class, you need to instantiate it with the required parameters:
8
+
9
+ ```
10
+ npm install drapcode-developer-sdk
11
+ ```
12
+
13
+ ```typescript
14
+ import { DrapcodeApis } from 'drapcode-developer-sdk';
15
+
16
+ const api = new DrapcodeApis(project_seo_name, xApiKey, authorization, environment);
17
+ ```
18
+
19
+ **project_seo_name (Required):** The SEO name of your Drapcode project.
20
+
21
+ **xApiKey (Optional)**: Your Developer API key to authorize API calls, if enabled.
22
+
23
+ **authorization (Optional)**: Authorization token for authentication, if applicable.
24
+
25
+ **environment (Optional)**: The environment (PRODUCTION, PREVIEW, BETA, ALPHA). Defaults to PRODUCTION if not provided.
26
+ ### Example:
27
+ ```
28
+ const drapcodeApi = new DrapcodeApis("singhaniya-computer-7138");
29
+ ```
30
+ # Methods
31
+
32
+ ## getAllItems(collectionName: string)
33
+ Retrieves all items from a specified collection.
34
+
35
+ **collectionName:** The name of the collection to retrieve items from
36
+ ### Example:
37
+ ```
38
+ const items = await drapcodeApi.getAllItems("users");
39
+ ```
40
+
41
+ Retrieves items from the "users" collection.
42
+
43
+ ## createItem(collectionName: string, body: JSON)
44
+ Creates a new item in the specified collection.
45
+
46
+ **collectionName:** The name of the collection to create the item in.
47
+ **body:** The data of the item to be created.
48
+ ### Example:
49
+ ```
50
+ await drapcodeApi.createItem("users", {
51
+ "name": "Pk",
52
+ "age": 23
53
+ });
54
+ ```
55
+ Creates a new item in the "users" collection with the provided data.
56
+
57
+ ## getItemsWithFilter(collectionName: string, filterUuid: string)
58
+
59
+ Retrieves items from a collection based on a filter UUID.
60
+
61
+ **collectionName:** The name of the collection to retrieve items from.
62
+ **filterUuid:** The UUID of the filter to apply.
63
+
64
+ ### Example:
65
+ ```
66
+ const filteredItems = await drapcodeApi.getItemsWithFilter("users", "15263");
67
+ ```
68
+
69
+ Retrieves items from the "users" collection based on the filter UUID "15263".
70
+
71
+ ## getItemsCountWithFilter(collectionName: string, filterUuid: string)
72
+ Retrieves the count of items from a collection based on a filter UUID.
73
+
74
+ **collectionName:** The name of the collection to retrieve items from.
75
+ **filterUuid:** The UUID of the filter to apply.
76
+
77
+ ### Example:
78
+ ```
79
+ const itemCount = await drapcodeApi.getItemsCountWithFilter("users", "15263");
80
+ ```
81
+ Retrieves the count of items from the "users" collection based on the filter UUID "15263".
82
+
83
+ ## getItemWithUuid(collectionName: string, itemUuid: string)
84
+ Retrieves a specific item from a collection based on its UUID.
85
+
86
+ **collectionName:** The name of the collection to retrieve the item from.
87
+ **itemUuid:** The UUID of the item to retrieve.
88
+ ### Example:
89
+ ```
90
+ const item = await drapcodeApi.getItemWithUuid("users", "3487-383");
91
+ ```
92
+ Retrieves a specific item from the "users" collection with the UUID "3487-383".
93
+
94
+ ## updateItemWithUuid(collectionName: string, itemUuid: string, body: any)
95
+ Updates a specific item in a collection based on its UUID.
96
+
97
+ **collectionName:** The name of the collection containing the item.
98
+ **itemUuid:** The UUID of the item to update.
99
+ **body:** The updated data for the item.
100
+ ### Example:
101
+ ```
102
+ await drapcodeApi.updateItemWithUuid("users", "3487-383", {"name": "Drapcode"});
103
+ ```
104
+ Updates the item in the "users" collection with the UUID "3487-383" with the provided data.
105
+
106
+ ## deleteItemWithUuid(collectionName: string, itemUuid: string)
107
+ Deletes a specific item from a collection based on its UUID.
108
+
109
+ **collectionName:** The name of the collection containing the item.
110
+ **itemUuid:** The UUID of the item to delete.
111
+ ### Example:
112
+ ```
113
+ await drapcodeApi.deleteItemWithUuid("users", "3487-383");
114
+ ```
115
+ Deletes the item with the UUID "3487-383" from the "users" collection.
116
+
117
+ ## sendEmail(templateId: string, sendTo: string)
118
+ Sends an email using the specified email template ID.
119
+
120
+ **templateId:** The ID of the email template to use.
121
+ **sendTo:** The email address to send the email to.
122
+ ### Example:
123
+ ```
124
+ await drapcodeApi.sendEmail("345-678", "support@drapcode.com");
125
+ ```
126
+ Sends an email using the template ID "345-678" to the email address "support@drapcode.com".
127
+
128
+ For better experience, utilize async/await syntax when using these methods.
@@ -0,0 +1,20 @@
1
+ export declare class DrapcodeApis {
2
+ private project_seo_name;
3
+ private xApiKey;
4
+ private authorization;
5
+ private environment;
6
+ private API_PATH;
7
+ constructor(project_seo_name: string, xApiKey?: string, authorization?: string, environment?: string);
8
+ private getBaseUrl;
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[]>;
20
+ }
package/build/index.js ADDED
@@ -0,0 +1,151 @@
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.DrapcodeApis = void 0;
40
+ var methods_1 = require("./methods/methods");
41
+ var DrapcodeApis = /** @class */ (function () {
42
+ function DrapcodeApis(project_seo_name, xApiKey, authorization, environment) {
43
+ if (xApiKey === void 0) { xApiKey = ""; }
44
+ if (authorization === void 0) { authorization = ""; }
45
+ if (environment === void 0) { environment = 'PRODUCTION'; }
46
+ this.API_PATH = 'drapcode.io/api/v1/developer';
47
+ this.project_seo_name = project_seo_name;
48
+ this.xApiKey = xApiKey;
49
+ this.authorization = authorization;
50
+ this.environment = environment;
51
+ }
52
+ DrapcodeApis.prototype.getBaseUrl = function () {
53
+ switch (this.environment) {
54
+ case 'PRODUCTION':
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);
62
+ default:
63
+ return "https://".concat(this.project_seo_name, ".api.").concat(this.API_PATH);
64
+ }
65
+ };
66
+ DrapcodeApis.prototype.getHeaders = function () {
67
+ var headers = {
68
+ 'Content-Type': 'application/json',
69
+ 'Accept': 'application/json',
70
+ };
71
+ if (this.xApiKey) {
72
+ headers['x-api-key'] = this.xApiKey;
73
+ }
74
+ if (this.authorization) {
75
+ headers['Authorization'] = this.authorization;
76
+ }
77
+ return headers;
78
+ };
79
+ DrapcodeApis.prototype.getAllItems = function (collectionName) {
80
+ return __awaiter(this, void 0, void 0, function () {
81
+ return __generator(this, function (_a) {
82
+ return [2 /*return*/, (0, methods_1.getAllItems)(this.getBaseUrl(), this.getHeaders(), collectionName)];
83
+ });
84
+ });
85
+ };
86
+ DrapcodeApis.prototype.createItem = function (collectionName, body) {
87
+ return __awaiter(this, void 0, void 0, function () {
88
+ return __generator(this, function (_a) {
89
+ return [2 /*return*/, (0, methods_1.createItem)(this.getBaseUrl(), this.getHeaders(), collectionName, body)];
90
+ });
91
+ });
92
+ };
93
+ DrapcodeApis.prototype.getItemsWithFilter = function (collectionName, filterUuid) {
94
+ return __awaiter(this, void 0, void 0, function () {
95
+ return __generator(this, function (_a) {
96
+ return [2 /*return*/, (0, methods_1.getItemsWithFilter)(this.getBaseUrl(), this.getHeaders(), collectionName, filterUuid)];
97
+ });
98
+ });
99
+ };
100
+ DrapcodeApis.prototype.getItemsCountWithFilter = function (collectionName, filterUuid) {
101
+ return __awaiter(this, void 0, void 0, function () {
102
+ return __generator(this, function (_a) {
103
+ return [2 /*return*/, (0, methods_1.getItemsCountWithFilter)(this.getBaseUrl(), this.getHeaders(), collectionName, filterUuid)];
104
+ });
105
+ });
106
+ };
107
+ DrapcodeApis.prototype.getItemWithUuid = function (collectionName, itemUuid) {
108
+ return __awaiter(this, void 0, void 0, function () {
109
+ return __generator(this, function (_a) {
110
+ return [2 /*return*/, (0, methods_1.getItemWithUuid)(this.getBaseUrl(), this.getHeaders(), collectionName, itemUuid)];
111
+ });
112
+ });
113
+ };
114
+ DrapcodeApis.prototype.updateItemWithUuid = function (collectionName, itemUuid, body) {
115
+ return __awaiter(this, void 0, void 0, function () {
116
+ return __generator(this, function (_a) {
117
+ return [2 /*return*/, (0, methods_1.updateItemWithUuid)(this.getBaseUrl(), this.getHeaders(), collectionName, itemUuid, body)];
118
+ });
119
+ });
120
+ };
121
+ DrapcodeApis.prototype.deleteItemWithUuid = function (collectionName, itemUuid) {
122
+ return __awaiter(this, void 0, void 0, function () {
123
+ return __generator(this, function (_a) {
124
+ return [2 /*return*/, (0, methods_1.deleteItemWithUuid)(this.getBaseUrl(), this.getHeaders(), collectionName, itemUuid)];
125
+ });
126
+ });
127
+ };
128
+ DrapcodeApis.prototype.bulkDeleteItems = function (collectionName, body) {
129
+ return __awaiter(this, void 0, void 0, function () {
130
+ return __generator(this, function (_a) {
131
+ return [2 /*return*/, (0, methods_1.bulkDeleteItems)(this.getBaseUrl(), this.getHeaders(), collectionName, body)];
132
+ });
133
+ });
134
+ };
135
+ DrapcodeApis.prototype.getItemsByids = function (collectionName, body) {
136
+ return __awaiter(this, void 0, void 0, function () {
137
+ return __generator(this, function (_a) {
138
+ return [2 /*return*/, (0, methods_1.getItemsByids)(this.getBaseUrl(), this.getHeaders(), collectionName, body)];
139
+ });
140
+ });
141
+ };
142
+ DrapcodeApis.prototype.sendEmail = function (templateId, sendTo) {
143
+ return __awaiter(this, void 0, void 0, function () {
144
+ return __generator(this, function (_a) {
145
+ return [2 /*return*/, (0, methods_1.sendEmail)(this.getBaseUrl(), this.getHeaders(), templateId, sendTo)];
146
+ });
147
+ });
148
+ };
149
+ return DrapcodeApis;
150
+ }());
151
+ exports.DrapcodeApis = DrapcodeApis;
@@ -0,0 +1,19 @@
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>;
11
+ /**
12
+ * {
13
+ * code,
14
+ * success
15
+ * data,
16
+ * error,
17
+ * message,
18
+ * }
19
+ */
@@ -0,0 +1,316 @@
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.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
+ var createErrorResponse = function (error) {
45
+ if (error.response && error.response.status === 404) {
46
+ var responseData = error.response.data;
47
+ var finalData = void 0;
48
+ if (responseData == 'This url does not exist. Please publish again.') {
49
+ finalData = "Please check your project name or publish again.";
50
+ }
51
+ else if (responseData.message) {
52
+ finalData = responseData.message;
53
+ }
54
+ else {
55
+ finalData = responseData !== "" ? responseData : "Not found";
56
+ }
57
+ return {
58
+ code: error.response.status,
59
+ success: false,
60
+ data: finalData,
61
+ error: '',
62
+ message: '',
63
+ };
64
+ }
65
+ else if (error.response && error.response.status === 401) {
66
+ var responseData = error.response;
67
+ return {
68
+ code: responseData.status,
69
+ success: false,
70
+ data: responseData.data.message,
71
+ error: '',
72
+ message: '',
73
+ };
74
+ }
75
+ else if (error.response && error.response.status === 400) {
76
+ var responseData = error.response;
77
+ return {
78
+ code: responseData.status,
79
+ success: false,
80
+ data: "Please Check Your Credentials",
81
+ error: '',
82
+ message: '',
83
+ };
84
+ }
85
+ return {
86
+ code: error.response.code,
87
+ success: false,
88
+ data: "",
89
+ error: 'Please check your project name or publish again.',
90
+ message: '',
91
+ };
92
+ };
93
+ var getAllItems = function (baseurl, headers, collectionName) { return __awaiter(void 0, void 0, void 0, function () {
94
+ var url, response, error_1;
95
+ return __generator(this, function (_a) {
96
+ switch (_a.label) {
97
+ case 0:
98
+ _a.trys.push([0, 2, , 3]);
99
+ url = "".concat(baseurl, "/collection/").concat(collectionName, "/items");
100
+ return [4 /*yield*/, axios_1.default.get(url, { headers: headers })];
101
+ case 1:
102
+ 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: '' }];
107
+ case 2:
108
+ error_1 = _a.sent();
109
+ return [2 /*return*/, createErrorResponse(error_1)];
110
+ case 3: return [2 /*return*/];
111
+ }
112
+ });
113
+ }); };
114
+ exports.getAllItems = getAllItems;
115
+ var createItem = function (baseurl, headers, collectionName, body) { return __awaiter(void 0, void 0, void 0, function () {
116
+ var url, response, error_2;
117
+ return __generator(this, function (_a) {
118
+ switch (_a.label) {
119
+ case 0:
120
+ _a.trys.push([0, 2, , 3]);
121
+ url = "".concat(baseurl, "/collection/").concat(collectionName, "/items");
122
+ return [4 /*yield*/, axios_1.default.post(url, body, {
123
+ headers: headers
124
+ })];
125
+ case 1:
126
+ 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:
132
+ error_2 = _a.sent();
133
+ return [2 /*return*/, createErrorResponse(error_2)];
134
+ case 3: return [2 /*return*/];
135
+ }
136
+ });
137
+ }); };
138
+ exports.createItem = createItem;
139
+ var getItemsWithFilter = function (baseurl, headers, collectionName, filterUuid) { return __awaiter(void 0, void 0, void 0, function () {
140
+ var url, response, error_3;
141
+ return __generator(this, function (_a) {
142
+ switch (_a.label) {
143
+ case 0:
144
+ _a.trys.push([0, 2, , 3]);
145
+ url = "".concat(baseurl, "/collection/").concat(collectionName, "/filter/").concat(filterUuid, "/items");
146
+ return [4 /*yield*/, axios_1.default.get(url, {
147
+ headers: headers
148
+ })];
149
+ case 1:
150
+ response = _a.sent();
151
+ return [2 /*return*/, { success: true, data: response.data, error: '', message: '' }];
152
+ case 2:
153
+ error_3 = _a.sent();
154
+ return [2 /*return*/, createErrorResponse(error_3)];
155
+ case 3: return [2 /*return*/];
156
+ }
157
+ });
158
+ }); };
159
+ exports.getItemsWithFilter = getItemsWithFilter;
160
+ var getItemsCountWithFilter = function (baseurl, headers, collectionName, filterUuid) { return __awaiter(void 0, void 0, void 0, function () {
161
+ var url, response, error_4;
162
+ return __generator(this, function (_a) {
163
+ switch (_a.label) {
164
+ case 0:
165
+ _a.trys.push([0, 2, , 3]);
166
+ url = "".concat(baseurl, "/collection/").concat(collectionName, "/filter/").concat(filterUuid, "/count");
167
+ return [4 /*yield*/, axios_1.default.get(url, {
168
+ headers: headers
169
+ })];
170
+ case 1:
171
+ response = _a.sent();
172
+ return [2 /*return*/, { success: true, data: response.data, error: '', message: '' }];
173
+ case 2:
174
+ error_4 = _a.sent();
175
+ return [2 /*return*/, createErrorResponse(error_4)];
176
+ case 3: return [2 /*return*/];
177
+ }
178
+ });
179
+ }); };
180
+ exports.getItemsCountWithFilter = getItemsCountWithFilter;
181
+ var getItemWithUuid = function (baseurl, headers, collectionName, itemUuid) { return __awaiter(void 0, void 0, void 0, function () {
182
+ var url, response, error_5;
183
+ return __generator(this, function (_a) {
184
+ switch (_a.label) {
185
+ case 0:
186
+ _a.trys.push([0, 2, , 3]);
187
+ url = "".concat(baseurl, "/collection/").concat(collectionName, "/item/").concat(itemUuid);
188
+ return [4 /*yield*/, axios_1.default.get(url, {
189
+ headers: headers
190
+ })];
191
+ case 1:
192
+ response = _a.sent();
193
+ return [2 /*return*/, { success: true, data: response.data, error: '', message: '' }];
194
+ case 2:
195
+ error_5 = _a.sent();
196
+ return [2 /*return*/, createErrorResponse(error_5)];
197
+ case 3: return [2 /*return*/];
198
+ }
199
+ });
200
+ }); };
201
+ exports.getItemWithUuid = getItemWithUuid;
202
+ var updateItemWithUuid = function (baseurl, headers, collectionName, itemUuid, body) { return __awaiter(void 0, void 0, void 0, function () {
203
+ var url, response, error_6;
204
+ return __generator(this, function (_a) {
205
+ switch (_a.label) {
206
+ case 0:
207
+ _a.trys.push([0, 2, , 3]);
208
+ url = "".concat(baseurl, "/collection/").concat(collectionName, "/item/").concat(itemUuid);
209
+ return [4 /*yield*/, axios_1.default.put(url, body, {
210
+ headers: headers
211
+ })];
212
+ case 1:
213
+ response = _a.sent();
214
+ return [2 /*return*/, { success: true, data: response.data, error: '', message: '' }];
215
+ case 2:
216
+ error_6 = _a.sent();
217
+ return [2 /*return*/, createErrorResponse(error_6)];
218
+ case 3: return [2 /*return*/];
219
+ }
220
+ });
221
+ }); };
222
+ exports.updateItemWithUuid = updateItemWithUuid;
223
+ 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) {
228
+ case 0:
229
+ _b.trys.push([0, 2, , 3]);
230
+ url = "".concat(baseurl, "/collection/").concat(collectionName, "/item/").concat(itemUuid);
231
+ return [4 /*yield*/, axios_1.default.delete(url, {
232
+ headers: headers
233
+ })];
234
+ 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: '' }];
237
+ case 2:
238
+ error_7 = _b.sent();
239
+ return [2 /*return*/, createErrorResponse(error_7)];
240
+ case 3: return [2 /*return*/];
241
+ }
242
+ });
243
+ }); };
244
+ exports.deleteItemWithUuid = deleteItemWithUuid;
245
+ var bulkDeleteItems = function (baseurl, headers, collectionName, body) { return __awaiter(void 0, void 0, void 0, function () {
246
+ var url, response, error_8;
247
+ return __generator(this, function (_a) {
248
+ switch (_a.label) {
249
+ case 0:
250
+ _a.trys.push([0, 2, , 3]);
251
+ url = "".concat(baseurl, "/collection/").concat(collectionName, "/bulkDelete");
252
+ return [4 /*yield*/, axios_1.default.post(url, body, {
253
+ headers: headers
254
+ })];
255
+ case 1:
256
+ response = _a.sent();
257
+ return [2 /*return*/, { success: true, data: response.data, error: '', message: '' }];
258
+ case 2:
259
+ error_8 = _a.sent();
260
+ return [2 /*return*/, createErrorResponse(error_8)];
261
+ case 3: return [2 /*return*/];
262
+ }
263
+ });
264
+ }); };
265
+ exports.bulkDeleteItems = bulkDeleteItems;
266
+ var getItemsByids = function (baseurl, headers, collectionName, body) { return __awaiter(void 0, void 0, void 0, function () {
267
+ var url, response, error_9;
268
+ return __generator(this, function (_a) {
269
+ switch (_a.label) {
270
+ case 0:
271
+ _a.trys.push([0, 2, , 3]);
272
+ url = "".concat(baseurl, "/collection/").concat(collectionName, "/itemsbyids");
273
+ return [4 /*yield*/, axios_1.default.post(url, body, {
274
+ headers: headers
275
+ })];
276
+ case 1:
277
+ response = _a.sent();
278
+ return [2 /*return*/, { success: true, data: response.data, error: '', message: '' }];
279
+ case 2:
280
+ error_9 = _a.sent();
281
+ return [2 /*return*/, createErrorResponse(error_9)];
282
+ case 3: return [2 /*return*/];
283
+ }
284
+ });
285
+ }); };
286
+ exports.getItemsByids = getItemsByids;
287
+ var sendEmail = function (baseurl, headers, templateId, sendTo) { return __awaiter(void 0, void 0, void 0, function () {
288
+ var url, response, error_10;
289
+ return __generator(this, function (_a) {
290
+ switch (_a.label) {
291
+ case 0:
292
+ _a.trys.push([0, 2, , 3]);
293
+ url = "".concat(baseurl, "/sendEmail/").concat(templateId, "/user/").concat(sendTo);
294
+ return [4 /*yield*/, axios_1.default.post(url, "", {
295
+ headers: headers
296
+ })];
297
+ case 1:
298
+ response = _a.sent();
299
+ return [2 /*return*/, { success: true, data: response.data, error: '', message: '' }];
300
+ case 2:
301
+ error_10 = _a.sent();
302
+ return [2 /*return*/, createErrorResponse(error_10)];
303
+ case 3: return [2 /*return*/];
304
+ }
305
+ });
306
+ }); };
307
+ exports.sendEmail = sendEmail;
308
+ /**
309
+ * {
310
+ * code,
311
+ * success
312
+ * data,
313
+ * error,
314
+ * message,
315
+ * }
316
+ */
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "drapcode-developer-sdk",
3
+ "version": "1.0.0",
4
+ "main": "build/index.js",
5
+ "types": "build/index.d.ts",
6
+ "files": [
7
+ "build/**/*"
8
+ ],
9
+ "scripts": {
10
+ "clean": "del ./build/*",
11
+ "link-lib": "npm link drapcode-constant drapcode-logger",
12
+ "build": "npm run clean && npm run link-lib && tsc"
13
+ },
14
+ "keywords": [],
15
+ "author": "",
16
+ "license": "ISC",
17
+ "devDependencies": {
18
+ "@types/express": "^4.17.21",
19
+ "@types/lodash": "^4.14.179",
20
+ "del-cli": "^5.0.0",
21
+ "typescript": "^4.0.2"
22
+ },
23
+ "dependencies": {
24
+ "axios": "^1.1.2",
25
+ "express": "^4.17.1"
26
+ },
27
+ "description": ""
28
+ }