backend-manager 2.3.17 → 2.3.20

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backend-manager",
3
- "version": "2.3.17",
3
+ "version": "2.3.20",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -66,4 +66,4 @@
66
66
  "src/",
67
67
  "templates/"
68
68
  ]
69
- }
69
+ }
@@ -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;
@@ -32,8 +32,10 @@ Manager.prototype.init = function (exporter, options) {
32
32
  // Set options defaults
33
33
  options = options || {};
34
34
  options.initialize = typeof options.initialize === 'undefined' ? true : options.initialize;
35
+ options.log = typeof options.log === 'undefined' ? false : options.log;
35
36
  options.setupFunctions = typeof options.setupFunctions === 'undefined' ? true : options.setupFunctions;
36
- options.setupLocalDatabase = typeof options.setupLocalDatabase === 'undefined' ? false : options.setupLocalDatabase;
37
+ options.setupFunctionsLegacy = typeof options.setupFunctionsLegacy === 'undefined' ? true : options.setupFunctionsLegacy;
38
+ options.initializeLocalStorage = typeof options.initializeLocalStorage === 'undefined' ? false : options.initializeLocalStorage;
37
39
  options.sentry = typeof options.sentry === 'undefined' ? true : options.sentry;
38
40
  options.reportErrorsInDev = typeof options.reportErrorsInDev === 'undefined' ? false : options.reportErrorsInDev;
39
41
  options.firebaseConfig = options.firebaseConfig;
@@ -85,6 +87,10 @@ Manager.prototype.init = function (exporter, options) {
85
87
  require('firebase-functions/lib/logger/compat');
86
88
  }
87
89
 
90
+ if (options.log) {
91
+ self.assistant.log('process.env', process.env, {environment: 'production'})
92
+ }
93
+
88
94
  // Setup sentry
89
95
  if (self.options.sentry) {
90
96
  const sentryRelease = `${get(self.config, 'app.id') || self.project.projectId}@${self.package.version}`;
@@ -112,14 +118,19 @@ Manager.prototype.init = function (exporter, options) {
112
118
  // Setup options features
113
119
  if (self.options.initialize) {
114
120
  // console.log('Initializing:', self.project);
121
+ // console.log('----process.env.GOOGLE_APPLICATION_CREDENTIALS', process.env.GOOGLE_APPLICATION_CREDENTIALS);
115
122
  try {
116
- // console.log('----self.project.databaseURL', self.project.databaseURL);
117
- self.libraries.initializedAdmin = self.libraries.admin.initializeApp({
118
- credential: self.libraries.admin.credential.cert(
119
- require(path.resolve(self.cwd, options.serviceAccountPath))
120
- ),
121
- databaseURL: self.project.databaseURL,
122
- }, options.uniqueAppName);
123
+ // console.log('---process.env.GOOGLE_APPLICATION_CREDENTIALS', process.env.GOOGLE_APPLICATION_CREDENTIALS);
124
+ if (process.env.GOOGLE_APPLICATION_CREDENTIALS) {
125
+ self.libraries.initializedAdmin = self.libraries.admin.initializeApp();
126
+ } else {
127
+ self.libraries.initializedAdmin = self.libraries.admin.initializeApp({
128
+ credential: self.libraries.admin.credential.cert(
129
+ require(path.resolve(self.cwd, options.serviceAccountPath))
130
+ ),
131
+ databaseURL: self.project.databaseURL,
132
+ }, options.uniqueAppName);
133
+ }
123
134
  } catch (e) {
124
135
  console.error('Failed to call .initializeApp()', e);
125
136
  }
@@ -142,127 +153,174 @@ Manager.prototype.init = function (exporter, options) {
142
153
  });
143
154
  });
144
155
 
145
- exporter.bm_signUpHandler =
146
- self.libraries.functions
147
- .runWith({memory: '256MB', timeoutSeconds: 60})
148
- .https.onRequest(async (req, res) => {
149
- const Module = require(`${core}/actions/sign-up-handler.js`);
150
- Module.init(self, { req: req, res: res, });
156
+ if (options.setupFunctionsLegacy) {
157
+ exporter.bm_signUpHandler =
158
+ self.libraries.functions
159
+ .runWith({memory: '256MB', timeoutSeconds: 60})
160
+ .https.onRequest(async (req, res) => {
161
+ const Module = require(`${core}/actions/sign-up-handler.js`);
162
+ Module.init(self, { req: req, res: res, });
151
163
 
152
- return self._preProcess(Module)
153
- .then(r => Module.main())
154
- .catch(e => {
155
- self.assistant.error(e, {environment: 'production'});
156
- return res.status(500).send(e.message);
164
+ return self._preProcess(Module)
165
+ .then(r => Module.main())
166
+ .catch(e => {
167
+ self.assistant.error(e, {environment: 'production'});
168
+ return res.status(500).send(e.message);
169
+ });
157
170
  });
158
- });
159
171
 
160
- // Admin
161
- exporter.bm_createPost =
162
- self.libraries.functions
163
- .runWith({memory: '256MB', timeoutSeconds: 60})
164
- .https.onRequest(async (req, res) => {
165
- const Module = require(`${core}/admin/create-post.js`);
166
- Module.init(self, { req: req, res: res, });
172
+ // Admin
173
+ exporter.bm_createPost =
174
+ self.libraries.functions
175
+ .runWith({memory: '256MB', timeoutSeconds: 60})
176
+ .https.onRequest(async (req, res) => {
177
+ const Module = require(`${core}/admin/create-post.js`);
178
+ Module.init(self, { req: req, res: res, });
167
179
 
168
- return self._preProcess(Module)
169
- .then(r => Module.main())
170
- .catch(e => {
171
- self.assistant.error(e, {environment: 'production'});
172
- return res.status(500).send(e.message);
180
+ return self._preProcess(Module)
181
+ .then(r => Module.main())
182
+ .catch(e => {
183
+ self.assistant.error(e, {environment: 'production'});
184
+ return res.status(500).send(e.message);
185
+ });
173
186
  });
174
- });
175
187
 
176
- exporter.bm_firestoreWrite =
177
- self.libraries.functions
178
- .runWith({memory: '256MB', timeoutSeconds: 60})
179
- .https.onRequest(async (req, res) => {
180
- const Module = require(`${core}/admin/firestore-write.js`);
181
- Module.init(self, { req: req, res: res, });
188
+ exporter.bm_firestoreWrite =
189
+ self.libraries.functions
190
+ .runWith({memory: '256MB', timeoutSeconds: 60})
191
+ .https.onRequest(async (req, res) => {
192
+ const Module = require(`${core}/admin/firestore-write.js`);
193
+ Module.init(self, { req: req, res: res, });
182
194
 
183
- return self._preProcess(Module)
184
- .then(r => Module.main())
185
- .catch(e => {
186
- self.assistant.error(e, {environment: 'production'});
187
- return res.status(500).send(e.message);
195
+ return self._preProcess(Module)
196
+ .then(r => Module.main())
197
+ .catch(e => {
198
+ self.assistant.error(e, {environment: 'production'});
199
+ return res.status(500).send(e.message);
200
+ });
188
201
  });
189
- });
190
202
 
191
- exporter.bm_getStats =
192
- self.libraries.functions
193
- .runWith({memory: '256MB', timeoutSeconds: 420})
194
- .https.onRequest(async (req, res) => {
195
- const Module = require(`${core}/admin/get-stats.js`);
196
- Module.init(self, { req: req, res: res, });
203
+ exporter.bm_getStats =
204
+ self.libraries.functions
205
+ .runWith({memory: '256MB', timeoutSeconds: 420})
206
+ .https.onRequest(async (req, res) => {
207
+ const Module = require(`${core}/admin/get-stats.js`);
208
+ Module.init(self, { req: req, res: res, });
197
209
 
198
- return self._preProcess(Module)
199
- .then(r => Module.main())
200
- .catch(e => {
201
- self.assistant.error(e, {environment: 'production'});
202
- return res.status(500).send(e.message);
210
+ return self._preProcess(Module)
211
+ .then(r => Module.main())
212
+ .catch(e => {
213
+ self.assistant.error(e, {environment: 'production'});
214
+ return res.status(500).send(e.message);
215
+ });
203
216
  });
204
- });
205
217
 
206
- exporter.bm_sendNotification =
207
- self.libraries.functions
208
- .runWith({memory: '1GB', timeoutSeconds: 420})
209
- .https.onRequest(async (req, res) => {
210
- const Module = require(`${core}/admin/send-notification.js`);
211
- Module.init(self, { req: req, res: res, });
218
+ exporter.bm_sendNotification =
219
+ self.libraries.functions
220
+ .runWith({memory: '1GB', timeoutSeconds: 420})
221
+ .https.onRequest(async (req, res) => {
222
+ const Module = require(`${core}/admin/send-notification.js`);
223
+ Module.init(self, { req: req, res: res, });
212
224
 
213
- return self._preProcess(Module)
214
- .then(r => Module.main())
215
- .catch(e => {
216
- self.assistant.error(e, {environment: 'production'});
217
- return res.status(500).send(e.message);
225
+ return self._preProcess(Module)
226
+ .then(r => Module.main())
227
+ .catch(e => {
228
+ self.assistant.error(e, {environment: 'production'});
229
+ return res.status(500).send(e.message);
230
+ });
218
231
  });
219
- });
220
232
 
221
- exporter.bm_query =
222
- self.libraries.functions
223
- .runWith({memory: '256MB', timeoutSeconds: 60})
224
- .https.onRequest(async (req, res) => {
225
- const Module = require(`${core}/admin/query.js`);
226
- Module.init(self, { req: req, res: res, });
233
+ exporter.bm_query =
234
+ self.libraries.functions
235
+ .runWith({memory: '256MB', timeoutSeconds: 60})
236
+ .https.onRequest(async (req, res) => {
237
+ const Module = require(`${core}/admin/query.js`);
238
+ Module.init(self, { req: req, res: res, });
227
239
 
228
- return self._preProcess(Module)
229
- .then(r => Module.main())
230
- .catch(e => {
231
- self.assistant.error(e, {environment: 'production'});
232
- return res.status(500).send(e.message);
240
+ return self._preProcess(Module)
241
+ .then(r => Module.main())
242
+ .catch(e => {
243
+ self.assistant.error(e, {environment: 'production'});
244
+ return res.status(500).send(e.message);
245
+ });
233
246
  });
234
- });
235
247
 
236
- exporter.bm_createPostHandler =
237
- self.libraries.functions
238
- .runWith({memory: '256MB', timeoutSeconds: 60})
239
- .https.onRequest(async (req, res) => {
240
- const Module = require(`${core}/actions/create-post-handler.js`);
241
- Module.init(self, { req: req, res: res, });
248
+ exporter.bm_createPostHandler =
249
+ self.libraries.functions
250
+ .runWith({memory: '256MB', timeoutSeconds: 60})
251
+ .https.onRequest(async (req, res) => {
252
+ const Module = require(`${core}/actions/create-post-handler.js`);
253
+ Module.init(self, { req: req, res: res, });
242
254
 
243
- return self._preProcess(Module)
244
- .then(r => Module.main())
245
- .catch(e => {
246
- self.assistant.error(e, {environment: 'production'});
247
- return res.status(500).send(e.message);
255
+ return self._preProcess(Module)
256
+ .then(r => Module.main())
257
+ .catch(e => {
258
+ self.assistant.error(e, {environment: 'production'});
259
+ return res.status(500).send(e.message);
260
+ });
248
261
  });
249
- });
250
262
 
251
- exporter.bm_generateUuid =
252
- self.libraries.functions
253
- .runWith({memory: '256MB', timeoutSeconds: 60})
254
- .https.onRequest(async (req, res) => {
255
- const Module = require(`${core}/actions/generate-uuid.js`);
256
- Module.init(self, { req: req, res: res, });
263
+ exporter.bm_generateUuid =
264
+ self.libraries.functions
265
+ .runWith({memory: '256MB', timeoutSeconds: 60})
266
+ .https.onRequest(async (req, res) => {
267
+ const Module = require(`${core}/actions/generate-uuid.js`);
268
+ Module.init(self, { req: req, res: res, });
257
269
 
258
- return self._preProcess(Module)
259
- .then(r => Module.main())
260
- .catch(e => {
261
- self.assistant.error(e, {environment: 'production'});
262
- return res.status(500).send(e.message);
270
+ return self._preProcess(Module)
271
+ .then(r => Module.main())
272
+ .catch(e => {
273
+ self.assistant.error(e, {environment: 'production'});
274
+ return res.status(500).send(e.message);
275
+ });
263
276
  });
264
- });
265
277
 
278
+ // Test
279
+ exporter.bm_test_authenticate =
280
+ self.libraries.functions
281
+ .runWith({memory: '256MB', timeoutSeconds: 60})
282
+ .https.onRequest(async (req, res) => {
283
+ const Module = require(`${test}/authenticate.js`);
284
+ Module.init(self, { req: req, res: res, });
285
+
286
+ return self._preProcess(Module)
287
+ .then(r => Module.main())
288
+ .catch(e => {
289
+ self.assistant.error(e, {environment: 'production'});
290
+ return res.status(500).send(e.message);
291
+ });
292
+ });
293
+
294
+ exporter.bm_test_createTestAccounts =
295
+ self.libraries.functions
296
+ .runWith({memory: '256MB', timeoutSeconds: 60})
297
+ .https.onRequest(async (req, res) => {
298
+ const Module = require(`${test}/create-test-accounts.js`);
299
+ Module.init(self, { req: req, res: res, });
300
+
301
+ return self._preProcess(Module)
302
+ .then(r => Module.main())
303
+ .catch(e => {
304
+ self.assistant.error(e, {environment: 'production'});
305
+ return res.status(500).send(e.message);
306
+ });
307
+ });
308
+
309
+ exporter.bm_test_webhook =
310
+ self.libraries.functions
311
+ .runWith({memory: '256MB', timeoutSeconds: 60})
312
+ .https.onRequest(async (req, res) => {
313
+ const Module = require(`${test}/webhook.js`);
314
+ Module.init(self, { req: req, res: res, });
315
+
316
+ return self._preProcess(Module)
317
+ .then(r => Module.main())
318
+ .catch(e => {
319
+ self.assistant.error(e, {environment: 'production'});
320
+ return res.status(500).send(e.message);
321
+ });
322
+ });
323
+ }
266
324
 
267
325
  // Events
268
326
  exporter.bm_authOnCreate =
@@ -308,53 +366,6 @@ Manager.prototype.init = function (exporter, options) {
308
366
  self.assistant.error(e, {environment: 'production'});
309
367
  });
310
368
  });
311
-
312
-
313
- // Test
314
- exporter.bm_test_authenticate =
315
- self.libraries.functions
316
- .runWith({memory: '256MB', timeoutSeconds: 60})
317
- .https.onRequest(async (req, res) => {
318
- const Module = require(`${test}/authenticate.js`);
319
- Module.init(self, { req: req, res: res, });
320
-
321
- return self._preProcess(Module)
322
- .then(r => Module.main())
323
- .catch(e => {
324
- self.assistant.error(e, {environment: 'production'});
325
- return res.status(500).send(e.message);
326
- });
327
- });
328
-
329
- exporter.bm_test_createTestAccounts =
330
- self.libraries.functions
331
- .runWith({memory: '256MB', timeoutSeconds: 60})
332
- .https.onRequest(async (req, res) => {
333
- const Module = require(`${test}/create-test-accounts.js`);
334
- Module.init(self, { req: req, res: res, });
335
-
336
- return self._preProcess(Module)
337
- .then(r => Module.main())
338
- .catch(e => {
339
- self.assistant.error(e, {environment: 'production'});
340
- return res.status(500).send(e.message);
341
- });
342
- });
343
-
344
- exporter.bm_test_webhook =
345
- self.libraries.functions
346
- .runWith({memory: '256MB', timeoutSeconds: 60})
347
- .https.onRequest(async (req, res) => {
348
- const Module = require(`${test}/webhook.js`);
349
- Module.init(self, { req: req, res: res, });
350
-
351
- return self._preProcess(Module)
352
- .then(r => Module.main())
353
- .catch(e => {
354
- self.assistant.error(e, {environment: 'production'});
355
- return res.status(500).send(e.message);
356
- });
357
- });
358
369
  }
359
370
 
360
371
  // Set dotenv
@@ -365,7 +376,7 @@ Manager.prototype.init = function (exporter, options) {
365
376
  }
366
377
 
367
378
  // Setup LocalDatabase
368
- if (options.setupLocalDatabase) {
379
+ if (options.initializeLocalStorage) {
369
380
  self.storage();
370
381
  }
371
382