drapcode-developer-sdk 1.0.2 → 1.0.4
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 +52 -17
- package/build/index.d.ts +120 -10
- package/build/index.js +13 -13
- package/build/methods/methods.d.ts +121 -11
- package/build/methods/methods.js +186 -90
- package/package.json +4 -12
package/README.md
CHANGED
|
@@ -11,9 +11,14 @@ npm install drapcode-developer-sdk
|
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
```typescript
|
|
14
|
-
import { DrapcodeApis } from
|
|
14
|
+
import { DrapcodeApis } from "drapcode-developer-sdk";
|
|
15
15
|
|
|
16
|
-
const api = new DrapcodeApis(
|
|
16
|
+
const api = new DrapcodeApis(
|
|
17
|
+
project_seo_name,
|
|
18
|
+
xApiKey,
|
|
19
|
+
authorization,
|
|
20
|
+
environment
|
|
21
|
+
);
|
|
17
22
|
```
|
|
18
23
|
|
|
19
24
|
**project_seo_name (Required):** The SEO name of your Drapcode project.
|
|
@@ -22,18 +27,24 @@ const api = new DrapcodeApis(project_seo_name, xApiKey, authorization, environme
|
|
|
22
27
|
|
|
23
28
|
**authorization (Optional)**: Authorization token for authentication, if applicable.
|
|
24
29
|
|
|
25
|
-
**environment (Optional)**: The environment (PRODUCTION, PREVIEW,
|
|
26
|
-
|
|
30
|
+
**environment (Optional)**: The environment (PRODUCTION, PREVIEW, SANDBOX, UAT). Defaults to PRODUCTION if not provided.
|
|
31
|
+
|
|
32
|
+
### Example:
|
|
33
|
+
|
|
27
34
|
```
|
|
28
|
-
const drapcodeApi = new DrapcodeApis("
|
|
35
|
+
const drapcodeApi = new DrapcodeApis("test-project-7138");
|
|
29
36
|
```
|
|
37
|
+
|
|
30
38
|
# Methods
|
|
31
39
|
|
|
32
40
|
## getAllItems(collectionName: string)
|
|
33
|
-
Retrieves all items from a specified collection.
|
|
34
41
|
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
Retrieves all items from a specified collection. The items will come under 'data' JSON path.
|
|
43
|
+
|
|
44
|
+
**collectionName:** The name of the collection to retrieve items from
|
|
45
|
+
|
|
46
|
+
### Example:
|
|
47
|
+
|
|
37
48
|
```
|
|
38
49
|
const items = await drapcodeApi.getAllItems("users");
|
|
39
50
|
```
|
|
@@ -41,17 +52,21 @@ const items = await drapcodeApi.getAllItems("users");
|
|
|
41
52
|
Retrieves items from the "users" collection.
|
|
42
53
|
|
|
43
54
|
## createItem(collectionName: string, body: JSON)
|
|
55
|
+
|
|
44
56
|
Creates a new item in the specified collection.
|
|
45
57
|
|
|
46
58
|
**collectionName:** The name of the collection to create the item in.
|
|
47
59
|
**body:** The data of the item to be created.
|
|
48
|
-
|
|
60
|
+
|
|
61
|
+
### Example:
|
|
62
|
+
|
|
49
63
|
```
|
|
50
64
|
await drapcodeApi.createItem("users", {
|
|
51
|
-
"name": "
|
|
52
|
-
"age":
|
|
65
|
+
"name": "John Doe",
|
|
66
|
+
"age": 25
|
|
53
67
|
});
|
|
54
68
|
```
|
|
69
|
+
|
|
55
70
|
Creates a new item in the "users" collection with the provided data.
|
|
56
71
|
|
|
57
72
|
## getItemsWithFilter(collectionName: string, filterUuid: string)
|
|
@@ -61,7 +76,8 @@ Retrieves items from a collection based on a filter UUID.
|
|
|
61
76
|
**collectionName:** The name of the collection to retrieve items from.
|
|
62
77
|
**filterUuid:** The UUID of the filter to apply.
|
|
63
78
|
|
|
64
|
-
### Example:
|
|
79
|
+
### Example:
|
|
80
|
+
|
|
65
81
|
```
|
|
66
82
|
const filteredItems = await drapcodeApi.getItemsWithFilter("users", "15263");
|
|
67
83
|
```
|
|
@@ -69,60 +85,79 @@ const filteredItems = await drapcodeApi.getItemsWithFilter("users", "15263");
|
|
|
69
85
|
Retrieves items from the "users" collection based on the filter UUID "15263".
|
|
70
86
|
|
|
71
87
|
## getItemsCountWithFilter(collectionName: string, filterUuid: string)
|
|
88
|
+
|
|
72
89
|
Retrieves the count of items from a collection based on a filter UUID.
|
|
73
90
|
|
|
74
91
|
**collectionName:** The name of the collection to retrieve items from.
|
|
75
92
|
**filterUuid:** The UUID of the filter to apply.
|
|
76
93
|
|
|
77
|
-
### Example:
|
|
94
|
+
### Example:
|
|
95
|
+
|
|
78
96
|
```
|
|
79
97
|
const itemCount = await drapcodeApi.getItemsCountWithFilter("users", "15263");
|
|
80
98
|
```
|
|
99
|
+
|
|
81
100
|
Retrieves the count of items from the "users" collection based on the filter UUID "15263".
|
|
82
101
|
|
|
83
102
|
## getItemWithUuid(collectionName: string, itemUuid: string)
|
|
103
|
+
|
|
84
104
|
Retrieves a specific item from a collection based on its UUID.
|
|
85
105
|
|
|
86
106
|
**collectionName:** The name of the collection to retrieve the item from.
|
|
87
107
|
**itemUuid:** The UUID of the item to retrieve.
|
|
88
|
-
|
|
108
|
+
|
|
109
|
+
### Example:
|
|
110
|
+
|
|
89
111
|
```
|
|
90
112
|
const item = await drapcodeApi.getItemWithUuid("users", "3487-383");
|
|
91
113
|
```
|
|
114
|
+
|
|
92
115
|
Retrieves a specific item from the "users" collection with the UUID "3487-383".
|
|
93
116
|
|
|
94
117
|
## updateItemWithUuid(collectionName: string, itemUuid: string, body: any)
|
|
118
|
+
|
|
95
119
|
Updates a specific item in a collection based on its UUID.
|
|
96
120
|
|
|
97
121
|
**collectionName:** The name of the collection containing the item.
|
|
98
122
|
**itemUuid:** The UUID of the item to update.
|
|
99
123
|
**body:** The updated data for the item.
|
|
100
|
-
|
|
124
|
+
|
|
125
|
+
### Example:
|
|
126
|
+
|
|
101
127
|
```
|
|
102
128
|
await drapcodeApi.updateItemWithUuid("users", "3487-383", {"name": "Drapcode"});
|
|
103
129
|
```
|
|
130
|
+
|
|
104
131
|
Updates the item in the "users" collection with the UUID "3487-383" with the provided data.
|
|
105
132
|
|
|
106
133
|
## deleteItemWithUuid(collectionName: string, itemUuid: string)
|
|
134
|
+
|
|
107
135
|
Deletes a specific item from a collection based on its UUID.
|
|
108
136
|
|
|
109
137
|
**collectionName:** The name of the collection containing the item.
|
|
110
138
|
**itemUuid:** The UUID of the item to delete.
|
|
111
|
-
|
|
139
|
+
|
|
140
|
+
### Example:
|
|
141
|
+
|
|
112
142
|
```
|
|
113
143
|
await drapcodeApi.deleteItemWithUuid("users", "3487-383");
|
|
114
144
|
```
|
|
145
|
+
|
|
115
146
|
Deletes the item with the UUID "3487-383" from the "users" collection.
|
|
116
147
|
|
|
117
148
|
## sendEmail(templateId: string, sendTo: string)
|
|
149
|
+
|
|
118
150
|
Sends an email using the specified email template ID.
|
|
119
151
|
|
|
120
152
|
**templateId:** The ID of the email template to use.
|
|
121
153
|
**sendTo:** The email address to send the email to.
|
|
122
|
-
|
|
154
|
+
|
|
155
|
+
### Example:
|
|
156
|
+
|
|
123
157
|
```
|
|
124
158
|
await drapcodeApi.sendEmail("345-678", "support@drapcode.com");
|
|
125
159
|
```
|
|
160
|
+
|
|
126
161
|
Sends an email using the template ID "345-678" to the email address "support@drapcode.com".
|
|
127
162
|
|
|
128
163
|
For better experience, utilize async/await syntax when using these methods.
|
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<
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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 =
|
|
46
|
-
this.API_PATH =
|
|
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
|
|
54
|
+
case "PRODUCTION":
|
|
55
55
|
return "https://".concat(this.project_seo_name, ".api.").concat(this.API_PATH);
|
|
56
|
-
case
|
|
57
|
-
return "https://".concat(this.project_seo_name, ".preview.").concat(this.API_PATH);
|
|
58
|
-
case
|
|
59
|
-
return "https://".concat(this.project_seo_name, ".
|
|
60
|
-
case
|
|
61
|
-
return "https://".concat(this.project_seo_name, ".
|
|
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.sandbox.").concat(this.API_PATH);
|
|
60
|
+
case "ALPHA":
|
|
61
|
+
return "https://".concat(this.project_seo_name, ".api.uat.").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
|
-
|
|
69
|
-
|
|
68
|
+
"Content-Type": "application/json",
|
|
69
|
+
Accept: "application/json",
|
|
70
70
|
};
|
|
71
71
|
if (this.xApiKey) {
|
|
72
|
-
headers[
|
|
72
|
+
headers["x-api-key"] = this.xApiKey;
|
|
73
73
|
}
|
|
74
74
|
if (this.authorization) {
|
|
75
|
-
headers[
|
|
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<
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
+
*/
|
package/build/methods/methods.js
CHANGED
|
@@ -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 ==
|
|
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:
|
|
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,
|
|
129
|
+
_a.trys.push([0, 3, , 4]);
|
|
99
130
|
url = "".concat(baseurl, "/collection/").concat(collectionName, "/items");
|
|
100
|
-
return [4 /*yield*/,
|
|
131
|
+
return [4 /*yield*/, fetch(url, { method: "GET", headers: headers })];
|
|
101
132
|
case 1:
|
|
102
133
|
response = _a.sent();
|
|
103
|
-
|
|
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
|
|
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,
|
|
151
|
+
_a.trys.push([0, 5, , 6]);
|
|
121
152
|
url = "".concat(baseurl, "/collection/").concat(collectionName, "/items");
|
|
122
|
-
return [4 /*yield*/,
|
|
123
|
-
|
|
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.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
|
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,
|
|
191
|
+
_a.trys.push([0, 3, , 4]);
|
|
145
192
|
url = "".concat(baseurl, "/collection/").concat(collectionName, "/filter/").concat(filterUuid, "/items");
|
|
146
|
-
return [4 /*yield*/,
|
|
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 [
|
|
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
|
|
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,
|
|
213
|
+
_a.trys.push([0, 3, , 4]);
|
|
166
214
|
url = "".concat(baseurl, "/collection/").concat(collectionName, "/filter/").concat(filterUuid, "/count");
|
|
167
|
-
return [4 /*yield*/,
|
|
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 [
|
|
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
|
|
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,
|
|
235
|
+
_a.trys.push([0, 5, , 6]);
|
|
187
236
|
url = "".concat(baseurl, "/collection/").concat(collectionName, "/item/").concat(itemUuid);
|
|
188
|
-
return [4 /*yield*/,
|
|
189
|
-
headers: headers
|
|
190
|
-
})];
|
|
237
|
+
return [4 /*yield*/, fetch(url, { method: "GET", headers: headers })];
|
|
191
238
|
case 1:
|
|
192
239
|
response = _a.sent();
|
|
193
|
-
|
|
194
|
-
|
|
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
|
|
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,
|
|
266
|
+
_a.trys.push([0, 5, , 6]);
|
|
208
267
|
url = "".concat(baseurl, "/collection/").concat(collectionName, "/item/").concat(itemUuid);
|
|
209
|
-
return [4 /*yield*/,
|
|
210
|
-
|
|
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
|
-
|
|
215
|
-
|
|
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
|
|
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
|
-
|
|
226
|
-
|
|
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
|
-
|
|
301
|
+
_a.trys.push([0, 3, , 4]);
|
|
230
302
|
url = "".concat(baseurl, "/collection/").concat(collectionName, "/item/").concat(itemUuid);
|
|
231
|
-
return [4 /*yield*/,
|
|
232
|
-
|
|
303
|
+
return [4 /*yield*/, fetch(url, {
|
|
304
|
+
method: "DELETE",
|
|
305
|
+
headers: headers,
|
|
233
306
|
})];
|
|
234
307
|
case 1:
|
|
235
|
-
response =
|
|
236
|
-
return [
|
|
308
|
+
response = _a.sent();
|
|
309
|
+
return [4 /*yield*/, response.json()];
|
|
237
310
|
case 2:
|
|
238
|
-
|
|
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
|
|
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,
|
|
332
|
+
_a.trys.push([0, 3, , 4]);
|
|
251
333
|
url = "".concat(baseurl, "/collection/").concat(collectionName, "/bulkDelete");
|
|
252
|
-
return [4 /*yield*/,
|
|
253
|
-
|
|
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 [
|
|
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
|
|
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,
|
|
358
|
+
_a.trys.push([0, 3, , 4]);
|
|
272
359
|
url = "".concat(baseurl, "/collection/").concat(collectionName, "/itemsbyids");
|
|
273
|
-
return [4 /*yield*/,
|
|
274
|
-
|
|
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 [
|
|
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
|
|
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,
|
|
384
|
+
_a.trys.push([0, 3, , 4]);
|
|
293
385
|
url = "".concat(baseurl, "/sendEmail/").concat(templateId, "/user/").concat(sendTo);
|
|
294
|
-
return [4 /*yield*/,
|
|
295
|
-
|
|
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 [
|
|
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
|
|
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.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"main": "build/index.js",
|
|
5
5
|
"types": "build/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -8,15 +8,12 @@
|
|
|
8
8
|
],
|
|
9
9
|
"scripts": {
|
|
10
10
|
"clean": "del ./build/*",
|
|
11
|
-
"
|
|
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",
|
|
@@ -25,14 +22,9 @@
|
|
|
25
22
|
"url": "https://github.com/Drapcode/developer-sdk.git"
|
|
26
23
|
},
|
|
27
24
|
"devDependencies": {
|
|
28
|
-
"@types/express": "^4.17.21",
|
|
29
|
-
"@types/lodash": "^4.14.179",
|
|
30
25
|
"del-cli": "^5.0.0",
|
|
31
26
|
"typescript": "^4.0.2"
|
|
32
27
|
},
|
|
33
|
-
"dependencies": {
|
|
34
|
-
"axios": "^1.1.2",
|
|
35
|
-
"express": "^4.17.1"
|
|
36
|
-
},
|
|
28
|
+
"dependencies": {},
|
|
37
29
|
"description": ""
|
|
38
30
|
}
|