backend-manager 2.5.49 → 2.5.50

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.5.49",
3
+ "version": "2.5.50",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -18,52 +18,57 @@ Module.prototype.main = function () {
18
18
 
19
19
  payload.data.payload.deletionRegex = payload.data.payload.deletionRegex ? powertools.regexify(payload.data.payload.deletionRegex) : payload.data.payload.deletionRegex;
20
20
 
21
- if (!payload.user.roles.admin) {
21
+ if (!payload.user.roles.admin && assistant.meta.environment === 'production') {
22
22
  return reject(assistant.errorManager(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
23
- } else {
24
- // https://googleapis.dev/nodejs/firestore/latest/v1.FirestoreAdminClient.html#exportDocuments
25
- // https://firebase.google.com/docs/firestore/solutions/schedule-export#firebase-cli
26
- // https://levelup.gitconnected.com/how-to-back-up-firestore-easily-and-automatically-eab6bf0d7e1f
27
- const client = new self.libraries.admin.firestore.v1.FirestoreAdminClient({
28
- // credential: Manager.libraries.admin.credential.cert(
29
- // require(Manager.project.serviceAccountPath)
30
- // ),
31
- });
32
- const projectId = Manager.project.projectId;
33
- const resourceZone = Manager.project.resourceZone;
34
- const databaseName = client.databasePath(projectId, '(default)');
35
- const bucketName = `bm-backup-firestore-${projectId}`;
36
- const bucketAddress = `gs://${bucketName}`;
37
-
38
- await self.createBucket(bucketName, resourceZone);
39
- // await self.deleteOldFiles(bucketName, resourceZone);
40
-
41
- client.exportDocuments({
42
- name: databaseName,
43
- outputUriPrefix: bucketAddress,
44
- // Leave collectionIds empty to export all collections
45
- // or set to a list of collection IDs to export,
46
- collectionIds: []
47
- })
48
- .then(async (responses) => {
23
+ }
49
24
 
50
- await self._setMetaStats();
25
+ // https://googleapis.dev/nodejs/firestore/latest/v1.FirestoreAdminClient.html#exportDocuments
26
+ // https://firebase.google.com/docs/firestore/solutions/schedule-export#firebase-cli
27
+ // https://levelup.gitconnected.com/how-to-back-up-firestore-easily-and-automatically-eab6bf0d7e1f
28
+ const client = new self.libraries.admin.firestore.v1.FirestoreAdminClient({
29
+ // credential: Manager.libraries.admin.credential.cert(
30
+ // require(Manager.project.serviceAccountPath)
31
+ // ),
32
+ });
33
+ const projectId = Manager.project.projectId;
34
+ const resourceZone = Manager.project.resourceZone;
35
+ const databaseName = client.databasePath(projectId, '(default)');
36
+ const bucketName = `bm-backup-firestore-${projectId}`;
37
+ const bucketAddress = `gs://${bucketName}`;
38
+
39
+ await self.createBucket(bucketName, resourceZone);
40
+ // await self.deleteOldFiles(bucketName, resourceZone);
41
+
42
+ client.exportDocuments({
43
+ name: databaseName,
44
+ outputUriPrefix: bucketAddress,
45
+ // Leave collectionIds empty to export all collections
46
+ // or set to a list of collection IDs to export,
47
+ collectionIds: []
48
+ })
49
+ .then(async (responses) => {
51
50
 
52
- const response = responses[0];
53
- assistant.log('Saved backup successfully:', response.metadata.outputUriPrefix, {environment: 'development'})
51
+ const response = responses[0];
52
+ const meta = {
53
+
54
+ }
55
+
56
+ assistant.log('Saved backup successfully:', response.metadata.outputUriPrefix, meta, {environment: 'development'})
57
+
58
+ await self._setMetaStats(null, meta);
59
+
60
+ return resolve(response['name']);
61
+ })
62
+ .catch(async (e) => {
63
+ await self._setMetaStats(e);
64
+ return reject(assistant.errorManager(e, {code: 500, sentry: false, send: false, log: true}).error)
65
+ });
54
66
 
55
- return resolve(response['name']);
56
- })
57
- .catch(async (e) => {
58
- await self._setMetaStats(e);
59
- return reject(assistant.errorManager(e, {code: 500, sentry: false, send: false, log: true}).error)
60
- });
61
- }
62
67
  });
63
68
 
64
69
  };
65
70
 
66
- Module.prototype._setMetaStats = function (error) {
71
+ Module.prototype._setMetaStats = function (error, meta) {
67
72
  const self = this;
68
73
  const Manager = self.Manager;
69
74
  const Api = self.Api;
@@ -91,7 +91,7 @@ Module.prototype.main = function () {
91
91
  await self.libraries.admin.firestore().doc(`meta/stats`)
92
92
  .update({
93
93
  syncUsers: {
94
- lastPageToken: batch.pageToken
94
+ lastPageToken: batch.pageToken,
95
95
  }
96
96
  })
97
97
  .then(r => {
@@ -38,17 +38,18 @@ Module.prototype.main = function() {
38
38
  }),
39
39
 
40
40
  // Sync Firestore users to the database
41
- fetch(`${Manager.project.functionsUrl}/bm_api`, {
42
- method: 'post',
43
- response: 'json',
44
- body: {
45
- backendManagerKey: Manager.config.backend_manager.key,
46
- command: 'admin:sync-users',
47
- }
48
- })
49
- .then(response => {
50
- assistant.log(`Successfully executed sync-users:`, response, {environment: 'production'})
51
- }),
41
+ // TODO: This is not working becaues the pageToken is not relative any more when its saved...
42
+ // fetch(`${Manager.project.functionsUrl}/bm_api`, {
43
+ // method: 'post',
44
+ // response: 'json',
45
+ // body: {
46
+ // backendManagerKey: Manager.config.backend_manager.key,
47
+ // command: 'admin:sync-users',
48
+ // }
49
+ // })
50
+ // .then(response => {
51
+ // assistant.log(`Successfully executed sync-users:`, response, {environment: 'production'})
52
+ // }),
52
53
 
53
54
  // More daily processes
54
55
  // ...
@@ -177,7 +177,7 @@ Manager.prototype.init = function (exporter, options) {
177
177
  const serviceAccount = require(self.project.serviceAccountPath);
178
178
  self.libraries.initializedAdmin = self.libraries.admin.initializeApp({
179
179
  credential: self.libraries.admin.credential.cert(serviceAccount),
180
- databaseURL: self.project.databaseURL,
180
+ databaseURL: self.project.databaseURL || `https://${self.project.projectId}.firebaseio.com`,
181
181
  }, options.uniqueAppName);
182
182
 
183
183
  // const loadedProjectId = get(self.libraries.initializedAdmin, 'options_.credential.projectId', null);
@@ -32,5 +32,11 @@
32
32
  "messagingSenderId": "123",
33
33
  "appId": "1:123:web:456",
34
34
  "measurementId": "G-0123456789"
35
+ },
36
+ "settings": {
37
+ "syncUsers": {
38
+ "enabled": true,
39
+ "batchSize": 10
40
+ }
35
41
  }
36
42
  }