drapcode-developer-sdk 1.0.5 → 1.0.7
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 +57 -0
- package/build/index.d.ts +8 -7
- package/build/index.js +5 -2
- package/build/methods/methods.d.ts +7 -7
- package/build/methods/methods.js +48 -35
- package/build/utils/constants.d.ts +25 -0
- package/build/utils/constants.js +16 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -51,6 +51,63 @@ const items = await drapcodeApi.getAllItems("users");
|
|
|
51
51
|
|
|
52
52
|
Retrieves items from the "users" collection.
|
|
53
53
|
|
|
54
|
+
## Pagination and Search
|
|
55
|
+
|
|
56
|
+
### getAllItems(collectionName: string, reqQuery: SearchPaginate, query: Query[])
|
|
57
|
+
|
|
58
|
+
Retrieves all items from a specified collection. The items will come under 'data' JSON path.
|
|
59
|
+
|
|
60
|
+
**collectionName:** The name of the collection to retrieve items from. Required
|
|
61
|
+
**reqQuery:** Search and Pagination options. Optional, must pass null, in case of query
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
sortField:"",
|
|
65
|
+
sortOrder:"",
|
|
66
|
+
searchTerm:"",
|
|
67
|
+
isPagination: true|false
|
|
68
|
+
page: 1, //Greater than 0 and isPagination must be true
|
|
69
|
+
limit: 1 //Greater than 0 and isPagination must be true
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**query**: Filter on basis of query. Optional
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
{
|
|
76
|
+
field: field_name
|
|
77
|
+
condition: QueryCondition
|
|
78
|
+
value: value
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
//QueryCondition
|
|
84
|
+
EQUALS,
|
|
85
|
+
IS_NOT_NULL,
|
|
86
|
+
IS_NULL,
|
|
87
|
+
LIKE,
|
|
88
|
+
LESS_THAN_EQUALS_TO,
|
|
89
|
+
GREATER_THAN_EQUALS_TO,
|
|
90
|
+
LESS_THAN,
|
|
91
|
+
GREATER_THAN,
|
|
92
|
+
IN_LIST,
|
|
93
|
+
NOT_IN_LIST
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Example
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
// 1
|
|
100
|
+
const reqQuery = {isPaginate: true, page:1, limit: 100}
|
|
101
|
+
const items = await drapcodeApi.getAllItems("users", reqQuery);
|
|
102
|
+
// 2
|
|
103
|
+
const query = {field: "userName", condition: "EQUALS", value: "test@test.com"}
|
|
104
|
+
const queries = [query]
|
|
105
|
+
const items = await drapcodeApi.getAllItems("users", null, queries);
|
|
106
|
+
// 3
|
|
107
|
+
const items = await drapcodeApi.getAllItems("users", reqQuery, queries);
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
|
|
54
111
|
## createItem(collectionName: string, body: JSON)
|
|
55
112
|
|
|
56
113
|
Creates a new item in the specified collection.
|
package/build/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Query, SearchPaginate } from "./utils/constants";
|
|
1
2
|
export declare class DrapcodeApis {
|
|
2
3
|
private project_seo_name;
|
|
3
4
|
private xApiKey;
|
|
@@ -7,7 +8,7 @@ export declare class DrapcodeApis {
|
|
|
7
8
|
constructor(project_seo_name: string, xApiKey?: string, authorization?: string, environment?: string);
|
|
8
9
|
private getBaseUrl;
|
|
9
10
|
private getHeaders;
|
|
10
|
-
getAllItems(collectionName: string, reqQuery
|
|
11
|
+
getAllItems(collectionName: string, reqQuery?: SearchPaginate | any, query?: Query[] | []): Promise<{
|
|
11
12
|
code: any;
|
|
12
13
|
success: boolean;
|
|
13
14
|
data: any;
|
|
@@ -23,18 +24,17 @@ export declare class DrapcodeApis {
|
|
|
23
24
|
totalPages?: undefined;
|
|
24
25
|
}>;
|
|
25
26
|
createItem(collectionName: string, body: any): Promise<{
|
|
27
|
+
code: any;
|
|
26
28
|
success: boolean;
|
|
27
|
-
data:
|
|
29
|
+
data: any;
|
|
28
30
|
error: string;
|
|
29
31
|
message: string;
|
|
30
|
-
code?: undefined;
|
|
31
32
|
} | {
|
|
32
|
-
code: any;
|
|
33
33
|
success: boolean;
|
|
34
|
-
data:
|
|
34
|
+
data: string;
|
|
35
35
|
error: string;
|
|
36
|
-
message:
|
|
37
|
-
}>;
|
|
36
|
+
message: string;
|
|
37
|
+
} | undefined>;
|
|
38
38
|
getItemsWithFilter(collectionName: string, filterUuid: string): Promise<{
|
|
39
39
|
code: any;
|
|
40
40
|
success: boolean;
|
|
@@ -141,3 +141,4 @@ export declare class DrapcodeApis {
|
|
|
141
141
|
}
|
|
142
142
|
export * from "./utils/index";
|
|
143
143
|
export * from "./utils/crypt";
|
|
144
|
+
export * from "./utils/constants";
|
package/build/index.js
CHANGED
|
@@ -91,10 +91,12 @@ var DrapcodeApis = /** @class */ (function () {
|
|
|
91
91
|
console.log("here is header", headers);
|
|
92
92
|
return headers;
|
|
93
93
|
};
|
|
94
|
-
DrapcodeApis.prototype.getAllItems = function (collectionName, reqQuery) {
|
|
94
|
+
DrapcodeApis.prototype.getAllItems = function (collectionName, reqQuery, query) {
|
|
95
|
+
if (reqQuery === void 0) { reqQuery = null; }
|
|
96
|
+
if (query === void 0) { query = []; }
|
|
95
97
|
return __awaiter(this, void 0, void 0, function () {
|
|
96
98
|
return __generator(this, function (_a) {
|
|
97
|
-
return [2 /*return*/, (0, methods_1.getAllItems)(this.getBaseUrl(), this.getHeaders(), collectionName, reqQuery)];
|
|
99
|
+
return [2 /*return*/, (0, methods_1.getAllItems)(this.getBaseUrl(), this.getHeaders(), collectionName, reqQuery, query)];
|
|
98
100
|
});
|
|
99
101
|
});
|
|
100
102
|
};
|
|
@@ -166,3 +168,4 @@ var DrapcodeApis = /** @class */ (function () {
|
|
|
166
168
|
exports.DrapcodeApis = DrapcodeApis;
|
|
167
169
|
__exportStar(require("./utils/index"), exports);
|
|
168
170
|
__exportStar(require("./utils/crypt"), exports);
|
|
171
|
+
__exportStar(require("./utils/constants"), exports);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { Query, SearchPaginate } from "../utils/constants";
|
|
2
|
+
export declare const getAllItems: (baseurl: string, headers: Record<string, string>, collectionName: string, reqQuery: SearchPaginate, query: Query[]) => Promise<{
|
|
2
3
|
code: any;
|
|
3
4
|
success: boolean;
|
|
4
5
|
data: any;
|
|
@@ -14,18 +15,17 @@ export declare const getAllItems: (baseurl: string, headers: Record<string, stri
|
|
|
14
15
|
totalPages?: undefined;
|
|
15
16
|
}>;
|
|
16
17
|
export declare const createItem: (baseurl: string, headers: Record<string, string>, collectionName: string, body: any) => Promise<{
|
|
18
|
+
code: any;
|
|
17
19
|
success: boolean;
|
|
18
|
-
data:
|
|
20
|
+
data: any;
|
|
19
21
|
error: string;
|
|
20
22
|
message: string;
|
|
21
|
-
code?: undefined;
|
|
22
23
|
} | {
|
|
23
|
-
code: any;
|
|
24
24
|
success: boolean;
|
|
25
|
-
data:
|
|
25
|
+
data: string;
|
|
26
26
|
error: string;
|
|
27
|
-
message:
|
|
28
|
-
}>;
|
|
27
|
+
message: string;
|
|
28
|
+
} | undefined>;
|
|
29
29
|
export declare const getItemsWithFilter: (baseurl: string, headers: Record<string, string>, collectionName: string, filterUuid: string) => Promise<{
|
|
30
30
|
code: any;
|
|
31
31
|
success: boolean;
|
package/build/methods/methods.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
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
|
-
};
|
|
13
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -48,6 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
48
37
|
};
|
|
49
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
39
|
exports.sendEmail = exports.getItemsByids = exports.bulkDeleteItems = exports.deleteItemWithUuid = exports.updateItemWithUuid = exports.getItemWithUuid = exports.getItemsCountWithFilter = exports.getItemsWithFilter = exports.createItem = exports.getAllItems = void 0;
|
|
40
|
+
var constants_1 = require("../utils/constants");
|
|
51
41
|
var createErrorResponse = function (error) {
|
|
52
42
|
var _a;
|
|
53
43
|
if (error.response && error.response.status === 404) {
|
|
@@ -137,18 +127,34 @@ var processResponse = function (result) {
|
|
|
137
127
|
totalPages: (result === null || result === void 0 ? void 0 : result.totalPages) || 0,
|
|
138
128
|
};
|
|
139
129
|
};
|
|
140
|
-
var getAllItems = function (baseurl, headers, collectionName, reqQuery) { return __awaiter(void 0, void 0, void 0, function () {
|
|
141
|
-
var
|
|
130
|
+
var getAllItems = function (baseurl, headers, collectionName, reqQuery, query) { return __awaiter(void 0, void 0, void 0, function () {
|
|
131
|
+
var queryParams_1, url, response, result, error_1;
|
|
142
132
|
return __generator(this, function (_a) {
|
|
143
133
|
switch (_a.label) {
|
|
144
134
|
case 0:
|
|
145
135
|
_a.trys.push([0, 3, , 4]);
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
136
|
+
queryParams_1 = new URLSearchParams();
|
|
137
|
+
console.log("headers :>> ", headers);
|
|
138
|
+
console.log("query :>> ", query);
|
|
139
|
+
console.log("reqQuery :>> ", reqQuery);
|
|
140
|
+
if (reqQuery === null || reqQuery === void 0 ? void 0 : reqQuery.sortField)
|
|
141
|
+
queryParams_1.append("sortField", reqQuery.sortField);
|
|
142
|
+
if (reqQuery === null || reqQuery === void 0 ? void 0 : reqQuery.sortOrder)
|
|
143
|
+
queryParams_1.append("sortOrder", reqQuery.sortOrder);
|
|
144
|
+
if (reqQuery === null || reqQuery === void 0 ? void 0 : reqQuery.searchTerm)
|
|
145
|
+
queryParams_1.append("searchTerm", reqQuery.searchTerm);
|
|
146
|
+
if (reqQuery === null || reqQuery === void 0 ? void 0 : reqQuery.isPagination) {
|
|
147
|
+
queryParams_1.append("page", reqQuery.page);
|
|
148
|
+
queryParams_1.append("limit", reqQuery.limit);
|
|
149
|
+
}
|
|
150
|
+
query.map(function (query) {
|
|
151
|
+
var conditionString = constants_1.QueryOperation[query.condition];
|
|
152
|
+
var field = encodeURIComponent(query.field);
|
|
153
|
+
var value = encodeURIComponent(query.value);
|
|
154
|
+
queryParams_1.append("".concat(field, ":").concat(conditionString), "".concat(value));
|
|
155
|
+
});
|
|
156
|
+
url = "".concat(baseurl, "/collection/").concat(collectionName, "/items?").concat(queryParams_1.toString());
|
|
157
|
+
console.log("Generated URL:", url);
|
|
152
158
|
return [4 /*yield*/, fetch(url, { method: "GET", headers: headers })];
|
|
153
159
|
case 1:
|
|
154
160
|
response = _a.sent();
|
|
@@ -158,6 +164,7 @@ var getAllItems = function (baseurl, headers, collectionName, reqQuery) { return
|
|
|
158
164
|
return [2 /*return*/, processResponse(result)];
|
|
159
165
|
case 3:
|
|
160
166
|
error_1 = _a.sent();
|
|
167
|
+
console.log("error :>> ", error_1);
|
|
161
168
|
return [2 /*return*/, createErrorResponse(error_1)];
|
|
162
169
|
case 4: return [2 /*return*/];
|
|
163
170
|
}
|
|
@@ -169,8 +176,9 @@ var createItem = function (baseurl, headers, collectionName, body) { return __aw
|
|
|
169
176
|
return __generator(this, function (_a) {
|
|
170
177
|
switch (_a.label) {
|
|
171
178
|
case 0:
|
|
172
|
-
_a.trys.push([0,
|
|
179
|
+
_a.trys.push([0, 4, , 5]);
|
|
173
180
|
url = "".concat(baseurl, "/collection/").concat(collectionName, "/items");
|
|
181
|
+
console.log("url :>> ", url);
|
|
174
182
|
return [4 /*yield*/, fetch(url, {
|
|
175
183
|
method: "POST",
|
|
176
184
|
headers: headers,
|
|
@@ -178,28 +186,33 @@ var createItem = function (baseurl, headers, collectionName, body) { return __aw
|
|
|
178
186
|
})];
|
|
179
187
|
case 1:
|
|
180
188
|
response = _a.sent();
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
189
|
+
console.log("response.status :>> ", response.status);
|
|
190
|
+
if (response.status && response.status === 404) {
|
|
191
|
+
return [2 /*return*/, {
|
|
192
|
+
success: false,
|
|
193
|
+
data: "Collection Not Found",
|
|
194
|
+
error: "",
|
|
195
|
+
message: "",
|
|
196
|
+
}];
|
|
197
|
+
}
|
|
198
|
+
if (!(response.status &&
|
|
199
|
+
(response.status === 200 || response.status === 201))) return [3 /*break*/, 3];
|
|
200
|
+
return [4 /*yield*/, response.json()];
|
|
201
|
+
case 2:
|
|
190
202
|
result = _a.sent();
|
|
203
|
+
console.log("result :>> ", result);
|
|
191
204
|
return [2 /*return*/, {
|
|
192
|
-
code:
|
|
205
|
+
code: response.status,
|
|
193
206
|
success: true,
|
|
194
|
-
data: result
|
|
207
|
+
data: result,
|
|
195
208
|
error: "",
|
|
196
|
-
message:
|
|
209
|
+
message: "",
|
|
197
210
|
}];
|
|
198
|
-
case
|
|
199
|
-
case
|
|
211
|
+
case 3: return [3 /*break*/, 5];
|
|
212
|
+
case 4:
|
|
200
213
|
error_2 = _a.sent();
|
|
201
214
|
return [2 /*return*/, createErrorResponse(error_2)];
|
|
202
|
-
case
|
|
215
|
+
case 5: return [2 /*return*/];
|
|
203
216
|
}
|
|
204
217
|
});
|
|
205
218
|
}); };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare enum QueryOperation {
|
|
2
|
+
EQUALS = "EQUALS",
|
|
3
|
+
IS_NOT_NULL = "IS_NOT_NULL",
|
|
4
|
+
IS_NULL = "IS_NULL",
|
|
5
|
+
LIKE = "LIKE",
|
|
6
|
+
LESS_THAN_EQUALS_TO = "LESS_THAN_EQUALS_TO",
|
|
7
|
+
GREATER_THAN_EQUALS_TO = "GREATER_THAN_EQUALS_TO",
|
|
8
|
+
LESS_THAN = "LESS_THAN",
|
|
9
|
+
GREATER_THAN = "GREATER_THAN",
|
|
10
|
+
IN_LIST = "IN_LIST",
|
|
11
|
+
NOT_IN_LIST = "NOT_IN_LIST"
|
|
12
|
+
}
|
|
13
|
+
export type Query = {
|
|
14
|
+
field: string;
|
|
15
|
+
condition: QueryOperation;
|
|
16
|
+
value: string;
|
|
17
|
+
};
|
|
18
|
+
export type SearchPaginate = {
|
|
19
|
+
sortField?: string;
|
|
20
|
+
sortOrder?: string;
|
|
21
|
+
searchTerm?: string | any;
|
|
22
|
+
isPagination?: boolean;
|
|
23
|
+
page?: number | string | any;
|
|
24
|
+
limit?: number | string | any;
|
|
25
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QueryOperation = void 0;
|
|
4
|
+
var QueryOperation;
|
|
5
|
+
(function (QueryOperation) {
|
|
6
|
+
QueryOperation["EQUALS"] = "EQUALS";
|
|
7
|
+
QueryOperation["IS_NOT_NULL"] = "IS_NOT_NULL";
|
|
8
|
+
QueryOperation["IS_NULL"] = "IS_NULL";
|
|
9
|
+
QueryOperation["LIKE"] = "LIKE";
|
|
10
|
+
QueryOperation["LESS_THAN_EQUALS_TO"] = "LESS_THAN_EQUALS_TO";
|
|
11
|
+
QueryOperation["GREATER_THAN_EQUALS_TO"] = "GREATER_THAN_EQUALS_TO";
|
|
12
|
+
QueryOperation["LESS_THAN"] = "LESS_THAN";
|
|
13
|
+
QueryOperation["GREATER_THAN"] = "GREATER_THAN";
|
|
14
|
+
QueryOperation["IN_LIST"] = "IN_LIST";
|
|
15
|
+
QueryOperation["NOT_IN_LIST"] = "NOT_IN_LIST";
|
|
16
|
+
})(QueryOperation = exports.QueryOperation || (exports.QueryOperation = {}));
|