drapcode-developer-sdk 1.0.5 → 1.0.6

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
@@ -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: any): Promise<{
11
+ getAllItems(collectionName: string, reqQuery?: SearchPaginate | any, query?: Query[] | []): Promise<{
11
12
  code: any;
12
13
  success: boolean;
13
14
  data: any;
@@ -141,3 +142,4 @@ export declare class DrapcodeApis {
141
142
  }
142
143
  export * from "./utils/index";
143
144
  export * from "./utils/crypt";
145
+ 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
- export declare const getAllItems: (baseurl: string, headers: Record<string, string>, collectionName: string, reqQuery: any) => Promise<{
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;
@@ -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 queryParams, url, response, result, error_1;
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
- 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);
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, "%3A").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
  }
@@ -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 = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drapcode-developer-sdk",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "main": "build/index.js",
5
5
  "types": "build/index.d.ts",
6
6
  "files": [