@staticbackend/backend 1.0.0 → 1.1.1
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/dist/backend.d.ts +69 -3
- package/dist/backend.js +100 -7
- package/package.json +2 -2
package/dist/backend.d.ts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
export interface ListParam {
|
|
2
|
+
page: number;
|
|
3
|
+
size: number;
|
|
4
|
+
descending: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface EmailData {
|
|
7
|
+
fromName: string;
|
|
8
|
+
from: string;
|
|
9
|
+
to: string;
|
|
10
|
+
subject: string;
|
|
11
|
+
body: string;
|
|
12
|
+
replyTo: string;
|
|
13
|
+
}
|
|
1
14
|
export declare class Backend {
|
|
2
15
|
private baseURL;
|
|
3
16
|
private pubKey;
|
|
@@ -12,11 +25,39 @@ export declare class Backend {
|
|
|
12
25
|
ok: boolean;
|
|
13
26
|
content: any;
|
|
14
27
|
}>;
|
|
28
|
+
changePassword(token: string, email: string, oldPass: string, newPass: string): Promise<{
|
|
29
|
+
ok: boolean;
|
|
30
|
+
content: any;
|
|
31
|
+
}>;
|
|
32
|
+
getPasswordResetCode(rootToken: string, email: string): Promise<{
|
|
33
|
+
ok: boolean;
|
|
34
|
+
content: any;
|
|
35
|
+
}>;
|
|
36
|
+
resetPassword(email: string, code: string, newPass: string): Promise<{
|
|
37
|
+
ok: boolean;
|
|
38
|
+
content: any;
|
|
39
|
+
}>;
|
|
40
|
+
sudoGetToken(rootToken: string, accountId: string): Promise<{
|
|
41
|
+
ok: boolean;
|
|
42
|
+
content: any;
|
|
43
|
+
}>;
|
|
44
|
+
cacheGet(rootToken: string, key: string): Promise<{
|
|
45
|
+
ok: boolean;
|
|
46
|
+
content: any;
|
|
47
|
+
}>;
|
|
48
|
+
cacheSet(rootToken: string, key: string, value: any): Promise<{
|
|
49
|
+
ok: boolean;
|
|
50
|
+
content: any;
|
|
51
|
+
}>;
|
|
15
52
|
create(token: string, repo: string, doc: any): Promise<{
|
|
16
53
|
ok: boolean;
|
|
17
54
|
content: any;
|
|
18
55
|
}>;
|
|
19
|
-
|
|
56
|
+
createBulk(token: string, repo: string, docs: Array<any>): Promise<{
|
|
57
|
+
ok: boolean;
|
|
58
|
+
content: any;
|
|
59
|
+
}>;
|
|
60
|
+
list(token: string, repo: string, param?: ListParam): Promise<{
|
|
20
61
|
ok: boolean;
|
|
21
62
|
content: any;
|
|
22
63
|
}>;
|
|
@@ -24,7 +65,7 @@ export declare class Backend {
|
|
|
24
65
|
ok: boolean;
|
|
25
66
|
content: any;
|
|
26
67
|
}>;
|
|
27
|
-
query(token: string, repo: string, filters: any): Promise<{
|
|
68
|
+
query(token: string, repo: string, filters: any, param?: ListParam): Promise<{
|
|
28
69
|
ok: boolean;
|
|
29
70
|
content: any;
|
|
30
71
|
}>;
|
|
@@ -36,7 +77,23 @@ export declare class Backend {
|
|
|
36
77
|
ok: boolean;
|
|
37
78
|
content: any;
|
|
38
79
|
}>;
|
|
39
|
-
|
|
80
|
+
sudoList(rootToken: string, repo: string, param?: ListParam): Promise<{
|
|
81
|
+
ok: boolean;
|
|
82
|
+
content: any;
|
|
83
|
+
}>;
|
|
84
|
+
sudoGetById(rootToken: string, repo: string, id: string): Promise<{
|
|
85
|
+
ok: boolean;
|
|
86
|
+
content: any;
|
|
87
|
+
}>;
|
|
88
|
+
sudoUpdate(rootToken: string, repo: string, id: string, doc: any): Promise<{
|
|
89
|
+
ok: boolean;
|
|
90
|
+
content: any;
|
|
91
|
+
}>;
|
|
92
|
+
sudoQuery(rootToken: string, repo: string, filters: any, param?: ListParam): Promise<{
|
|
93
|
+
ok: boolean;
|
|
94
|
+
content: any;
|
|
95
|
+
}>;
|
|
96
|
+
increase(token: string, repo: string, id: string, field: string, n: number): Promise<{
|
|
40
97
|
ok: boolean;
|
|
41
98
|
content: any;
|
|
42
99
|
}>;
|
|
@@ -44,4 +101,13 @@ export declare class Backend {
|
|
|
44
101
|
ok: boolean;
|
|
45
102
|
content: any;
|
|
46
103
|
}>;
|
|
104
|
+
deleteFile(token: string, id: string): Promise<{
|
|
105
|
+
ok: boolean;
|
|
106
|
+
content: any;
|
|
107
|
+
}>;
|
|
108
|
+
sendMail(rootToken: string, data: EmailData): Promise<{
|
|
109
|
+
ok: boolean;
|
|
110
|
+
content: any;
|
|
111
|
+
}>;
|
|
112
|
+
private listParamToQuerystring;
|
|
47
113
|
}
|
package/dist/backend.js
CHANGED
|
@@ -18,7 +18,16 @@ class Backend {
|
|
|
18
18
|
this.pubKey = "";
|
|
19
19
|
this.pubKey = key;
|
|
20
20
|
if (region) {
|
|
21
|
-
|
|
21
|
+
if (region == "dev") {
|
|
22
|
+
this.baseURL = "http://localhost:8099";
|
|
23
|
+
}
|
|
24
|
+
else if (region.length > 3) {
|
|
25
|
+
// for self-hosted base URL
|
|
26
|
+
this.baseURL = region;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
this.baseURL = `https://${region}.staticbackend.com`;
|
|
30
|
+
}
|
|
22
31
|
}
|
|
23
32
|
}
|
|
24
33
|
rawreq(ct, token, method, path, body) {
|
|
@@ -71,14 +80,54 @@ class Backend {
|
|
|
71
80
|
return yield this.req("", "POST", "/login", body);
|
|
72
81
|
});
|
|
73
82
|
}
|
|
83
|
+
changePassword(token, email, oldPass, newPass) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
const body = { email: email, oldPassword: oldPass, newPassword: newPass };
|
|
86
|
+
return yield this.req(token, "POST", "/user/changepw", body);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
getPasswordResetCode(rootToken, email) {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
const path = `/password/resetcode?${encodeURIComponent(email)}`;
|
|
92
|
+
return yield this.req(rootToken, "GET", path);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
resetPassword(email, code, newPass) {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
const body = { email: email, code: code, password: newPass };
|
|
98
|
+
return yield this.req("", "POST", "/password/reset", body);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
sudoGetToken(rootToken, accountId) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
return yield this.req(rootToken, "GET", `/sudogettoken/${accountId}`);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
cacheGet(rootToken, key) {
|
|
107
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
return yield this.req(rootToken, "GET", `/sudo/cache?key=${key}`);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
cacheSet(rootToken, key, value) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
const body = { key: key, value: JSON.stringify(value) };
|
|
114
|
+
return yield this.req(rootToken, "POST", "/sudo/cache", body);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
74
117
|
create(token, repo, doc) {
|
|
75
118
|
return __awaiter(this, void 0, void 0, function* () {
|
|
76
119
|
return yield this.req(token, "POST", `/db/${repo}`, doc);
|
|
77
120
|
});
|
|
78
121
|
}
|
|
79
|
-
|
|
122
|
+
createBulk(token, repo, docs) {
|
|
80
123
|
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
return yield this.req(token, "
|
|
124
|
+
return yield this.req(token, "POST", `/db/${repo}?bulk=1`, docs);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
list(token, repo, param) {
|
|
128
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
const qs = this.listParamToQuerystring(param);
|
|
130
|
+
return yield this.req(token, "GET", `/db/${repo}${qs}`);
|
|
82
131
|
});
|
|
83
132
|
}
|
|
84
133
|
getById(token, repo, id) {
|
|
@@ -86,9 +135,10 @@ class Backend {
|
|
|
86
135
|
return yield this.req(token, "GET", `/db/${repo}/${id}`);
|
|
87
136
|
});
|
|
88
137
|
}
|
|
89
|
-
query(token, repo, filters) {
|
|
138
|
+
query(token, repo, filters, param) {
|
|
90
139
|
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
-
|
|
140
|
+
const qs = this.listParamToQuerystring(param);
|
|
141
|
+
return yield this.req(token, "POST", `/query/${repo}${qs}`, filters);
|
|
92
142
|
});
|
|
93
143
|
}
|
|
94
144
|
update(token, repo, id, doc) {
|
|
@@ -101,9 +151,32 @@ class Backend {
|
|
|
101
151
|
return yield this.req(token, "DELETE", `/db/${repo}/${id}`);
|
|
102
152
|
});
|
|
103
153
|
}
|
|
104
|
-
|
|
154
|
+
sudoList(rootToken, repo, param) {
|
|
155
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
156
|
+
const qs = this.listParamToQuerystring(param);
|
|
157
|
+
return yield this.req(rootToken, "GET", `/sudo/${repo}${qs}`);
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
sudoGetById(rootToken, repo, id) {
|
|
161
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
162
|
+
return yield this.req(rootToken, "GET", `/sudo/${repo}/${id}`);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
sudoUpdate(rootToken, repo, id, doc) {
|
|
166
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
167
|
+
return yield this.req(rootToken, "PUT", `/sudo/${repo}/${id}`, doc);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
sudoQuery(rootToken, repo, filters, param) {
|
|
171
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
172
|
+
const qs = this.listParamToQuerystring(param);
|
|
173
|
+
return yield this.req(rootToken, "POST", `/sudoquery/${repo}${qs}`, filters);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
increase(token, repo, id, field, n) {
|
|
105
177
|
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
-
|
|
178
|
+
const body = { field: field, range: n };
|
|
179
|
+
return yield this.req(token, "PUT", `/inc/${repo}/${id}`, body);
|
|
107
180
|
});
|
|
108
181
|
}
|
|
109
182
|
storeFile(token, size, buf) {
|
|
@@ -117,5 +190,25 @@ class Backend {
|
|
|
117
190
|
return yield this.rawreq(ct, token, "POST", "/storage/upload", fd);
|
|
118
191
|
});
|
|
119
192
|
}
|
|
193
|
+
deleteFile(token, id) {
|
|
194
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
195
|
+
return yield this.req(token, "GET", `/sudostorage/delete?id=${id}`);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
sendMail(rootToken, data) {
|
|
199
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
200
|
+
return yield this.req(rootToken, "POST", "/sudo/sendmail", data);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
listParamToQuerystring(param) {
|
|
204
|
+
var qs = "";
|
|
205
|
+
if (param) {
|
|
206
|
+
qs = `?page=${param.page}&size=${param.size}`;
|
|
207
|
+
if (param.descending) {
|
|
208
|
+
qs += "&desc=true";
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return qs;
|
|
212
|
+
}
|
|
120
213
|
}
|
|
121
214
|
exports.Backend = Backend;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@staticbackend/backend",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Client library for StaticBackend API",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"homepage": "https://github.com/staticbackendhq/backend-node#readme",
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/node": "^14.14.13",
|
|
25
|
-
"typescript": "^4.
|
|
25
|
+
"typescript": "^4.4.4"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"form-data": "^3.0.0",
|