backend-manager 2.3.16 → 2.3.19
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/package.json
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const _ = require('lodash')
|
|
2
|
+
|
|
3
|
+
function Module() {
|
|
4
|
+
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
Module.prototype.main = function () {
|
|
8
|
+
const self = this;
|
|
9
|
+
const Manager = self.Manager;
|
|
10
|
+
const Api = self.Api;
|
|
11
|
+
const assistant = self.assistant;
|
|
12
|
+
const payload = self.payload;
|
|
13
|
+
|
|
14
|
+
return new Promise(async function(resolve, reject) {
|
|
15
|
+
self.Api.resolveUser({adminRequired: true})
|
|
16
|
+
.then(async (user) => {
|
|
17
|
+
// return resolve({data: {success: true}});
|
|
18
|
+
// return reject(assistant.errorManager(`Failed to delete user: ${e}`, {code: 400, sentry: false, send: false, log: false}).error)
|
|
19
|
+
console.log('---payload', payload);
|
|
20
|
+
})
|
|
21
|
+
.catch(e => {
|
|
22
|
+
return reject(e);
|
|
23
|
+
})
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
module.exports = Module;
|
package/src/manager/index.js
CHANGED
|
@@ -15,6 +15,10 @@ function Manager(exporter, options) {
|
|
|
15
15
|
self.libraries = {};
|
|
16
16
|
self.handlers = {};
|
|
17
17
|
|
|
18
|
+
self._internal = {
|
|
19
|
+
storage: {},
|
|
20
|
+
};
|
|
21
|
+
|
|
18
22
|
return self;
|
|
19
23
|
}
|
|
20
24
|
|
|
@@ -29,12 +33,14 @@ Manager.prototype.init = function (exporter, options) {
|
|
|
29
33
|
options = options || {};
|
|
30
34
|
options.initialize = typeof options.initialize === 'undefined' ? true : options.initialize;
|
|
31
35
|
options.setupFunctions = typeof options.setupFunctions === 'undefined' ? true : options.setupFunctions;
|
|
32
|
-
options.
|
|
36
|
+
options.setupFunctionsLegacy = typeof options.setupFunctionsLegacy === 'undefined' ? true : options.setupFunctionsLegacy;
|
|
37
|
+
options.initializeLocalStorage = typeof options.initializeLocalStorage === 'undefined' ? false : options.initializeLocalStorage;
|
|
33
38
|
options.sentry = typeof options.sentry === 'undefined' ? true : options.sentry;
|
|
34
39
|
options.reportErrorsInDev = typeof options.reportErrorsInDev === 'undefined' ? false : options.reportErrorsInDev;
|
|
35
40
|
options.firebaseConfig = options.firebaseConfig;
|
|
36
41
|
options.useFirebaseLogger = typeof options.useFirebaseLogger === 'undefined' ? true : options.useFirebaseLogger;
|
|
37
|
-
options.serviceAccountPath = typeof options.serviceAccountPath === 'undefined' ? 'service-account.json' : options.serviceAccountPath;
|
|
42
|
+
// options.serviceAccountPath = typeof options.serviceAccountPath === 'undefined' ? 'service-account.json' : options.serviceAccountPath;
|
|
43
|
+
options.serviceAccountPath = typeof options.serviceAccountPath === 'undefined' ? undefined : options.serviceAccountPath;
|
|
38
44
|
options.uniqueAppName = options.uniqueAppName || undefined;
|
|
39
45
|
options.assistant = options.assistant || {};
|
|
40
46
|
// options.assistant.optionsLogString = options.assistant.optionsLogString || undefined;
|
|
@@ -109,13 +115,16 @@ Manager.prototype.init = function (exporter, options) {
|
|
|
109
115
|
if (self.options.initialize) {
|
|
110
116
|
// console.log('Initializing:', self.project);
|
|
111
117
|
try {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
118
|
+
if (options.serviceAccountPath && options.uniqueAppName) {
|
|
119
|
+
self.libraries.initializedAdmin = self.libraries.admin.initializeApp({
|
|
120
|
+
credential: self.libraries.admin.credential.cert(
|
|
121
|
+
require(path.resolve(self.cwd, options.serviceAccountPath))
|
|
122
|
+
),
|
|
123
|
+
databaseURL: self.project.databaseURL,
|
|
124
|
+
}, options.uniqueAppName);
|
|
125
|
+
} else {
|
|
126
|
+
self.libraries.initializedAdmin = self.libraries.admin.initializeApp();
|
|
127
|
+
}
|
|
119
128
|
} catch (e) {
|
|
120
129
|
console.error('Failed to call .initializeApp()', e);
|
|
121
130
|
}
|
|
@@ -138,127 +147,174 @@ Manager.prototype.init = function (exporter, options) {
|
|
|
138
147
|
});
|
|
139
148
|
});
|
|
140
149
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
150
|
+
if (options.setupFunctionsLegacy) {
|
|
151
|
+
exporter.bm_signUpHandler =
|
|
152
|
+
self.libraries.functions
|
|
153
|
+
.runWith({memory: '256MB', timeoutSeconds: 60})
|
|
154
|
+
.https.onRequest(async (req, res) => {
|
|
155
|
+
const Module = require(`${core}/actions/sign-up-handler.js`);
|
|
156
|
+
Module.init(self, { req: req, res: res, });
|
|
147
157
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
158
|
+
return self._preProcess(Module)
|
|
159
|
+
.then(r => Module.main())
|
|
160
|
+
.catch(e => {
|
|
161
|
+
self.assistant.error(e, {environment: 'production'});
|
|
162
|
+
return res.status(500).send(e.message);
|
|
163
|
+
});
|
|
153
164
|
});
|
|
154
|
-
});
|
|
155
165
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
166
|
+
// Admin
|
|
167
|
+
exporter.bm_createPost =
|
|
168
|
+
self.libraries.functions
|
|
169
|
+
.runWith({memory: '256MB', timeoutSeconds: 60})
|
|
170
|
+
.https.onRequest(async (req, res) => {
|
|
171
|
+
const Module = require(`${core}/admin/create-post.js`);
|
|
172
|
+
Module.init(self, { req: req, res: res, });
|
|
163
173
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
174
|
+
return self._preProcess(Module)
|
|
175
|
+
.then(r => Module.main())
|
|
176
|
+
.catch(e => {
|
|
177
|
+
self.assistant.error(e, {environment: 'production'});
|
|
178
|
+
return res.status(500).send(e.message);
|
|
179
|
+
});
|
|
169
180
|
});
|
|
170
|
-
});
|
|
171
181
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
182
|
+
exporter.bm_firestoreWrite =
|
|
183
|
+
self.libraries.functions
|
|
184
|
+
.runWith({memory: '256MB', timeoutSeconds: 60})
|
|
185
|
+
.https.onRequest(async (req, res) => {
|
|
186
|
+
const Module = require(`${core}/admin/firestore-write.js`);
|
|
187
|
+
Module.init(self, { req: req, res: res, });
|
|
178
188
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
189
|
+
return self._preProcess(Module)
|
|
190
|
+
.then(r => Module.main())
|
|
191
|
+
.catch(e => {
|
|
192
|
+
self.assistant.error(e, {environment: 'production'});
|
|
193
|
+
return res.status(500).send(e.message);
|
|
194
|
+
});
|
|
184
195
|
});
|
|
185
|
-
});
|
|
186
196
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
197
|
+
exporter.bm_getStats =
|
|
198
|
+
self.libraries.functions
|
|
199
|
+
.runWith({memory: '256MB', timeoutSeconds: 420})
|
|
200
|
+
.https.onRequest(async (req, res) => {
|
|
201
|
+
const Module = require(`${core}/admin/get-stats.js`);
|
|
202
|
+
Module.init(self, { req: req, res: res, });
|
|
193
203
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
204
|
+
return self._preProcess(Module)
|
|
205
|
+
.then(r => Module.main())
|
|
206
|
+
.catch(e => {
|
|
207
|
+
self.assistant.error(e, {environment: 'production'});
|
|
208
|
+
return res.status(500).send(e.message);
|
|
209
|
+
});
|
|
199
210
|
});
|
|
200
|
-
});
|
|
201
211
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
212
|
+
exporter.bm_sendNotification =
|
|
213
|
+
self.libraries.functions
|
|
214
|
+
.runWith({memory: '1GB', timeoutSeconds: 420})
|
|
215
|
+
.https.onRequest(async (req, res) => {
|
|
216
|
+
const Module = require(`${core}/admin/send-notification.js`);
|
|
217
|
+
Module.init(self, { req: req, res: res, });
|
|
208
218
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
219
|
+
return self._preProcess(Module)
|
|
220
|
+
.then(r => Module.main())
|
|
221
|
+
.catch(e => {
|
|
222
|
+
self.assistant.error(e, {environment: 'production'});
|
|
223
|
+
return res.status(500).send(e.message);
|
|
224
|
+
});
|
|
214
225
|
});
|
|
215
|
-
});
|
|
216
226
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
227
|
+
exporter.bm_query =
|
|
228
|
+
self.libraries.functions
|
|
229
|
+
.runWith({memory: '256MB', timeoutSeconds: 60})
|
|
230
|
+
.https.onRequest(async (req, res) => {
|
|
231
|
+
const Module = require(`${core}/admin/query.js`);
|
|
232
|
+
Module.init(self, { req: req, res: res, });
|
|
223
233
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
234
|
+
return self._preProcess(Module)
|
|
235
|
+
.then(r => Module.main())
|
|
236
|
+
.catch(e => {
|
|
237
|
+
self.assistant.error(e, {environment: 'production'});
|
|
238
|
+
return res.status(500).send(e.message);
|
|
239
|
+
});
|
|
229
240
|
});
|
|
230
|
-
});
|
|
231
241
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
242
|
+
exporter.bm_createPostHandler =
|
|
243
|
+
self.libraries.functions
|
|
244
|
+
.runWith({memory: '256MB', timeoutSeconds: 60})
|
|
245
|
+
.https.onRequest(async (req, res) => {
|
|
246
|
+
const Module = require(`${core}/actions/create-post-handler.js`);
|
|
247
|
+
Module.init(self, { req: req, res: res, });
|
|
238
248
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
249
|
+
return self._preProcess(Module)
|
|
250
|
+
.then(r => Module.main())
|
|
251
|
+
.catch(e => {
|
|
252
|
+
self.assistant.error(e, {environment: 'production'});
|
|
253
|
+
return res.status(500).send(e.message);
|
|
254
|
+
});
|
|
244
255
|
});
|
|
245
|
-
});
|
|
246
256
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
257
|
+
exporter.bm_generateUuid =
|
|
258
|
+
self.libraries.functions
|
|
259
|
+
.runWith({memory: '256MB', timeoutSeconds: 60})
|
|
260
|
+
.https.onRequest(async (req, res) => {
|
|
261
|
+
const Module = require(`${core}/actions/generate-uuid.js`);
|
|
262
|
+
Module.init(self, { req: req, res: res, });
|
|
253
263
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
264
|
+
return self._preProcess(Module)
|
|
265
|
+
.then(r => Module.main())
|
|
266
|
+
.catch(e => {
|
|
267
|
+
self.assistant.error(e, {environment: 'production'});
|
|
268
|
+
return res.status(500).send(e.message);
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
// Test
|
|
273
|
+
exporter.bm_test_authenticate =
|
|
274
|
+
self.libraries.functions
|
|
275
|
+
.runWith({memory: '256MB', timeoutSeconds: 60})
|
|
276
|
+
.https.onRequest(async (req, res) => {
|
|
277
|
+
const Module = require(`${test}/authenticate.js`);
|
|
278
|
+
Module.init(self, { req: req, res: res, });
|
|
279
|
+
|
|
280
|
+
return self._preProcess(Module)
|
|
281
|
+
.then(r => Module.main())
|
|
282
|
+
.catch(e => {
|
|
283
|
+
self.assistant.error(e, {environment: 'production'});
|
|
284
|
+
return res.status(500).send(e.message);
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
exporter.bm_test_createTestAccounts =
|
|
289
|
+
self.libraries.functions
|
|
290
|
+
.runWith({memory: '256MB', timeoutSeconds: 60})
|
|
291
|
+
.https.onRequest(async (req, res) => {
|
|
292
|
+
const Module = require(`${test}/create-test-accounts.js`);
|
|
293
|
+
Module.init(self, { req: req, res: res, });
|
|
294
|
+
|
|
295
|
+
return self._preProcess(Module)
|
|
296
|
+
.then(r => Module.main())
|
|
297
|
+
.catch(e => {
|
|
298
|
+
self.assistant.error(e, {environment: 'production'});
|
|
299
|
+
return res.status(500).send(e.message);
|
|
300
|
+
});
|
|
259
301
|
});
|
|
260
|
-
});
|
|
261
302
|
|
|
303
|
+
exporter.bm_test_webhook =
|
|
304
|
+
self.libraries.functions
|
|
305
|
+
.runWith({memory: '256MB', timeoutSeconds: 60})
|
|
306
|
+
.https.onRequest(async (req, res) => {
|
|
307
|
+
const Module = require(`${test}/webhook.js`);
|
|
308
|
+
Module.init(self, { req: req, res: res, });
|
|
309
|
+
|
|
310
|
+
return self._preProcess(Module)
|
|
311
|
+
.then(r => Module.main())
|
|
312
|
+
.catch(e => {
|
|
313
|
+
self.assistant.error(e, {environment: 'production'});
|
|
314
|
+
return res.status(500).send(e.message);
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
}
|
|
262
318
|
|
|
263
319
|
// Events
|
|
264
320
|
exporter.bm_authOnCreate =
|
|
@@ -304,53 +360,6 @@ Manager.prototype.init = function (exporter, options) {
|
|
|
304
360
|
self.assistant.error(e, {environment: 'production'});
|
|
305
361
|
});
|
|
306
362
|
});
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
// Test
|
|
310
|
-
exporter.bm_test_authenticate =
|
|
311
|
-
self.libraries.functions
|
|
312
|
-
.runWith({memory: '256MB', timeoutSeconds: 60})
|
|
313
|
-
.https.onRequest(async (req, res) => {
|
|
314
|
-
const Module = require(`${test}/authenticate.js`);
|
|
315
|
-
Module.init(self, { req: req, res: res, });
|
|
316
|
-
|
|
317
|
-
return self._preProcess(Module)
|
|
318
|
-
.then(r => Module.main())
|
|
319
|
-
.catch(e => {
|
|
320
|
-
self.assistant.error(e, {environment: 'production'});
|
|
321
|
-
return res.status(500).send(e.message);
|
|
322
|
-
});
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
exporter.bm_test_createTestAccounts =
|
|
326
|
-
self.libraries.functions
|
|
327
|
-
.runWith({memory: '256MB', timeoutSeconds: 60})
|
|
328
|
-
.https.onRequest(async (req, res) => {
|
|
329
|
-
const Module = require(`${test}/create-test-accounts.js`);
|
|
330
|
-
Module.init(self, { req: req, res: res, });
|
|
331
|
-
|
|
332
|
-
return self._preProcess(Module)
|
|
333
|
-
.then(r => Module.main())
|
|
334
|
-
.catch(e => {
|
|
335
|
-
self.assistant.error(e, {environment: 'production'});
|
|
336
|
-
return res.status(500).send(e.message);
|
|
337
|
-
});
|
|
338
|
-
});
|
|
339
|
-
|
|
340
|
-
exporter.bm_test_webhook =
|
|
341
|
-
self.libraries.functions
|
|
342
|
-
.runWith({memory: '256MB', timeoutSeconds: 60})
|
|
343
|
-
.https.onRequest(async (req, res) => {
|
|
344
|
-
const Module = require(`${test}/webhook.js`);
|
|
345
|
-
Module.init(self, { req: req, res: res, });
|
|
346
|
-
|
|
347
|
-
return self._preProcess(Module)
|
|
348
|
-
.then(r => Module.main())
|
|
349
|
-
.catch(e => {
|
|
350
|
-
self.assistant.error(e, {environment: 'production'});
|
|
351
|
-
return res.status(500).send(e.message);
|
|
352
|
-
});
|
|
353
|
-
});
|
|
354
363
|
}
|
|
355
364
|
|
|
356
365
|
// Set dotenv
|
|
@@ -361,22 +370,8 @@ Manager.prototype.init = function (exporter, options) {
|
|
|
361
370
|
}
|
|
362
371
|
|
|
363
372
|
// Setup LocalDatabase
|
|
364
|
-
if (options.
|
|
365
|
-
|
|
366
|
-
const FileSync = require('lowdb/adapters/FileSync');
|
|
367
|
-
// const dbPath = path.resolve(process.cwd(), './.data/db.json');
|
|
368
|
-
const dbPath = './.data/db.json';
|
|
369
|
-
const adapter = new FileSync(dbPath);
|
|
370
|
-
const jetpack = require('fs-jetpack');
|
|
371
|
-
|
|
372
|
-
try {
|
|
373
|
-
if (!jetpack.exists(dbPath)) {
|
|
374
|
-
jetpack.write(dbPath, {});
|
|
375
|
-
}
|
|
376
|
-
self.libraries.localDatabase = low(adapter);
|
|
377
|
-
} catch (e) {
|
|
378
|
-
console.error('Could not load .data', e);
|
|
379
|
-
}
|
|
373
|
+
if (options.initializeLocalStorage) {
|
|
374
|
+
self.storage();
|
|
380
375
|
}
|
|
381
376
|
|
|
382
377
|
return self;
|
|
@@ -478,6 +473,49 @@ Manager.prototype.ApiManager = function () {
|
|
|
478
473
|
return new self.libraries.ApiManager(self, ...arguments);
|
|
479
474
|
};
|
|
480
475
|
|
|
476
|
+
Manager.prototype.storage = function (options) {
|
|
477
|
+
const self = this;
|
|
478
|
+
options = options || {};
|
|
479
|
+
options.name = options.name || 'main';
|
|
480
|
+
|
|
481
|
+
if (!self._internal.storage[options.name]) {
|
|
482
|
+
const low = require('lowdb');
|
|
483
|
+
const FileSync = require('lowdb/adapters/FileSync');
|
|
484
|
+
const dbPath = `./.data/${options.name}.json`;
|
|
485
|
+
const adapter = new FileSync(dbPath);
|
|
486
|
+
const jetpack = require('fs-jetpack');
|
|
487
|
+
|
|
488
|
+
options.clearInvalid = typeof options.clearInvalid === 'undefined'
|
|
489
|
+
? true
|
|
490
|
+
: options.clearInvalid;
|
|
491
|
+
|
|
492
|
+
function _setup() {
|
|
493
|
+
if (!jetpack.exists(dbPath)) {
|
|
494
|
+
jetpack.write(dbPath, {});
|
|
495
|
+
}
|
|
496
|
+
self._internal.storage[options.name] = low(adapter);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
try {
|
|
500
|
+
_setup()
|
|
501
|
+
} catch (e) {
|
|
502
|
+
console.error(`Could not storage: ${dbPath}`, e);
|
|
503
|
+
|
|
504
|
+
try {
|
|
505
|
+
if (options.clearInvalid) {
|
|
506
|
+
console.log(`Clearing invalud storage: ${dbPath}`);
|
|
507
|
+
jetpack.write(dbPath, {});
|
|
508
|
+
}
|
|
509
|
+
_setup()
|
|
510
|
+
} catch (e) {
|
|
511
|
+
console.error(`Failed to clear invalid storage: ${dbPath}`, e);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
return self._internal.storage[options.name]
|
|
517
|
+
};
|
|
518
|
+
|
|
481
519
|
// Manager.prototype.LocalDatabase = function () {
|
|
482
520
|
// const self = this;
|
|
483
521
|
// if (!self.libraries.LocalDatabase) {
|