@staticbackend/backend 1.0.0 → 1.3.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/dist/backend.d.ts CHANGED
@@ -1,3 +1,21 @@
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
+ }
14
+ export interface ConvertData {
15
+ toPDF: boolean;
16
+ url: string;
17
+ fullpage: boolean;
18
+ }
1
19
  export declare class Backend {
2
20
  private baseURL;
3
21
  private pubKey;
@@ -12,11 +30,39 @@ export declare class Backend {
12
30
  ok: boolean;
13
31
  content: any;
14
32
  }>;
33
+ changePassword(token: string, email: string, oldPass: string, newPass: string): Promise<{
34
+ ok: boolean;
35
+ content: any;
36
+ }>;
37
+ getPasswordResetCode(rootToken: string, email: string): Promise<{
38
+ ok: boolean;
39
+ content: any;
40
+ }>;
41
+ resetPassword(email: string, code: string, newPass: string): Promise<{
42
+ ok: boolean;
43
+ content: any;
44
+ }>;
45
+ sudoGetToken(rootToken: string, accountId: string): Promise<{
46
+ ok: boolean;
47
+ content: any;
48
+ }>;
49
+ cacheGet(rootToken: string, key: string): Promise<{
50
+ ok: boolean;
51
+ content: any;
52
+ }>;
53
+ cacheSet(rootToken: string, key: string, value: any): Promise<{
54
+ ok: boolean;
55
+ content: any;
56
+ }>;
15
57
  create(token: string, repo: string, doc: any): Promise<{
16
58
  ok: boolean;
17
59
  content: any;
18
60
  }>;
19
- list(token: string, repo: string): Promise<{
61
+ createBulk(token: string, repo: string, docs: Array<any>): Promise<{
62
+ ok: boolean;
63
+ content: any;
64
+ }>;
65
+ list(token: string, repo: string, param?: ListParam): Promise<{
20
66
  ok: boolean;
21
67
  content: any;
22
68
  }>;
@@ -24,7 +70,7 @@ export declare class Backend {
24
70
  ok: boolean;
25
71
  content: any;
26
72
  }>;
27
- query(token: string, repo: string, filters: any): Promise<{
73
+ query(token: string, repo: string, filters: any, param?: ListParam): Promise<{
28
74
  ok: boolean;
29
75
  content: any;
30
76
  }>;
@@ -36,12 +82,49 @@ export declare class Backend {
36
82
  ok: boolean;
37
83
  content: any;
38
84
  }>;
39
- sudoUpdate(adminToken: string, repo: string, id: string, doc: any): Promise<{
85
+ sudoList(rootToken: string, repo: string, param?: ListParam): Promise<{
86
+ ok: boolean;
87
+ content: any;
88
+ }>;
89
+ sudoGetById(rootToken: string, repo: string, id: string): Promise<{
90
+ ok: boolean;
91
+ content: any;
92
+ }>;
93
+ sudoUpdate(rootToken: string, repo: string, id: string, doc: any): Promise<{
94
+ ok: boolean;
95
+ content: any;
96
+ }>;
97
+ sudoQuery(rootToken: string, repo: string, filters: any, param?: ListParam): Promise<{
98
+ ok: boolean;
99
+ content: any;
100
+ }>;
101
+ increase(token: string, repo: string, id: string, field: string, n: number): Promise<{
102
+ ok: boolean;
103
+ content: any;
104
+ }>;
105
+ sudoAddIndex(rootToken: string, repo: string, field: string): Promise<{
106
+ ok: boolean;
107
+ content: any;
108
+ }>;
109
+ storeFile(token: string, buf: ArrayBuffer): Promise<{
110
+ ok: boolean;
111
+ content: any;
112
+ }>;
113
+ deleteFile(token: string, id: string): Promise<{
114
+ ok: boolean;
115
+ content: any;
116
+ }>;
117
+ sendMail(rootToken: string, data: EmailData): Promise<{
118
+ ok: boolean;
119
+ content: any;
120
+ }>;
121
+ resizeImage(token: string, maxWidth: number, buf: ArrayBuffer): Promise<{
40
122
  ok: boolean;
41
123
  content: any;
42
124
  }>;
43
- storeFile(token: string, size: number, buf: ArrayBuffer): Promise<{
125
+ convertURLToX(token: string, data: ConvertData): Promise<{
44
126
  ok: boolean;
45
127
  content: any;
46
128
  }>;
129
+ private listParamToQuerystring;
47
130
  }
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
- this.baseURL = `https://${region}.staticbackend.com`;
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
- list(token, repo) {
122
+ createBulk(token, repo, docs) {
80
123
  return __awaiter(this, void 0, void 0, function* () {
81
- return yield this.req(token, "GET", `/db/${repo}`);
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
- return yield this.req(token, "POST", `/query/${repo}`, filters);
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,12 +151,41 @@ class Backend {
101
151
  return yield this.req(token, "DELETE", `/db/${repo}/${id}`);
102
152
  });
103
153
  }
104
- sudoUpdate(adminToken, repo, id, doc) {
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) {
105
166
  return __awaiter(this, void 0, void 0, function* () {
106
- return yield this.req(adminToken, "PUT", `/sudo/${repo}/${id}`, doc);
167
+ return yield this.req(rootToken, "PUT", `/sudo/${repo}/${id}`, doc);
107
168
  });
108
169
  }
109
- storeFile(token, size, buf) {
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) {
177
+ return __awaiter(this, void 0, void 0, function* () {
178
+ const body = { field: field, range: n };
179
+ return yield this.req(token, "PUT", `/inc/${repo}/${id}`, body);
180
+ });
181
+ }
182
+ sudoAddIndex(rootToken, repo, field) {
183
+ return __awaiter(this, void 0, void 0, function* () {
184
+ const qs = `?col=${repo}&field=${field}`;
185
+ return yield this.req(rootToken, "POST", `/sudo/index${qs}`, null);
186
+ });
187
+ }
188
+ storeFile(token, buf) {
110
189
  return __awaiter(this, void 0, void 0, function* () {
111
190
  let fd = new formData();
112
191
  fd.append("file", buf, {
@@ -117,5 +196,42 @@ class Backend {
117
196
  return yield this.rawreq(ct, token, "POST", "/storage/upload", fd);
118
197
  });
119
198
  }
199
+ deleteFile(token, id) {
200
+ return __awaiter(this, void 0, void 0, function* () {
201
+ return yield this.req(token, "GET", `/sudostorage/delete?id=${id}`);
202
+ });
203
+ }
204
+ sendMail(rootToken, data) {
205
+ return __awaiter(this, void 0, void 0, function* () {
206
+ return yield this.req(rootToken, "POST", "/sudo/sendmail", data);
207
+ });
208
+ }
209
+ resizeImage(token, maxWidth, buf) {
210
+ return __awaiter(this, void 0, void 0, function* () {
211
+ let fd = new formData();
212
+ fd.append("file", buf, {
213
+ contentType: "application/octect-stream",
214
+ filename: "file-upload"
215
+ });
216
+ fd.append("width", maxWidth);
217
+ const ct = `multipart/form-data; boundary=${fd.getBoundary()}`;
218
+ return yield this.rawreq(ct, token, "POST", "/extra/resizeimg", fd);
219
+ });
220
+ }
221
+ convertURLToX(token, data) {
222
+ return __awaiter(this, void 0, void 0, function* () {
223
+ return yield this.req(token, "POST", "/extra/htmltox", data);
224
+ });
225
+ }
226
+ listParamToQuerystring(param) {
227
+ var qs = "";
228
+ if (param) {
229
+ qs = `?page=${param.page}&size=${param.size}`;
230
+ if (param.descending) {
231
+ qs += "&desc=true";
232
+ }
233
+ }
234
+ return qs;
235
+ }
120
236
  }
121
237
  exports.Backend = Backend;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@staticbackend/backend",
3
- "version": "1.0.0",
3
+ "version": "1.3.0",
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.1.3"
25
+ "typescript": "^4.4.4"
26
26
  },
27
27
  "dependencies": {
28
28
  "form-data": "^3.0.0",