backend-manager 2.5.67 → 2.5.69
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 +1 -1
- package/src/manager/functions/core/actions/api/admin/create-post.js +1 -0
- package/src/manager/functions/core/actions/api/admin/database-read.js +3 -0
- package/src/manager/functions/core/actions/api/admin/database-write.js +3 -0
- package/src/manager/functions/core/actions/api/admin/firestore-query.js +3 -1
- package/src/manager/functions/core/actions/api/admin/firestore-read.js +16 -19
- package/src/manager/functions/core/actions/api/admin/firestore-write.js +12 -10
- package/src/manager/functions/core/actions/api/admin/get-stats.js +33 -31
- package/src/manager/helpers/user.js +4 -4
package/package.json
CHANGED
|
@@ -15,6 +15,7 @@ Module.prototype.main = function () {
|
|
|
15
15
|
const payload = self.payload;
|
|
16
16
|
|
|
17
17
|
return new Promise(async function(resolve, reject) {
|
|
18
|
+
// Perform checks
|
|
18
19
|
if (!payload.user.roles.admin && !payload.user.roles.blogger) {
|
|
19
20
|
return reject(assistant.errorManager(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
|
|
20
21
|
}
|
|
@@ -10,15 +10,18 @@ Module.prototype.main = function () {
|
|
|
10
10
|
const payload = self.payload;
|
|
11
11
|
|
|
12
12
|
return new Promise(async function(resolve, reject) {
|
|
13
|
+
// Set defaults
|
|
13
14
|
payload.data.payload.path = `${payload.data.payload.path || ''}`;
|
|
14
15
|
payload.data.payload.options = payload.data.payload.options || {};
|
|
15
16
|
|
|
17
|
+
// Perform checks
|
|
16
18
|
if (!payload.user.roles.admin) {
|
|
17
19
|
return reject(assistant.errorManager(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
|
|
18
20
|
} else if (!payload.data.payload.path) {
|
|
19
21
|
return reject(assistant.errorManager(`<path> parameter required`, {code: 400, sentry: false, send: false, log: false}).error)
|
|
20
22
|
}
|
|
21
23
|
|
|
24
|
+
// Read from Firestore
|
|
22
25
|
self.libraries.admin.database().ref(payload.data.payload.path)
|
|
23
26
|
.on('value', (snapshot) => {
|
|
24
27
|
const data = snapshot.val();
|
|
@@ -10,16 +10,19 @@ Module.prototype.main = function () {
|
|
|
10
10
|
const payload = self.payload;
|
|
11
11
|
|
|
12
12
|
return new Promise(async function(resolve, reject) {
|
|
13
|
+
// Set defaults
|
|
13
14
|
payload.data.payload.path = `${payload.data.payload.path || ''}`;
|
|
14
15
|
payload.data.payload.document = payload.data.payload.document || {};
|
|
15
16
|
payload.data.payload.options = payload.data.payload.options || {};
|
|
16
17
|
|
|
18
|
+
// Perform checks
|
|
17
19
|
if (payload.user.roles.admin) {
|
|
18
20
|
return reject(assistant.errorManager(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
|
|
19
21
|
} else if (!payload.data.payload.path) {
|
|
20
22
|
return reject(assistant.errorManager(`<path> parameter required`, {code: 400, sentry: false, send: false, log: false}).error);
|
|
21
23
|
}
|
|
22
24
|
|
|
25
|
+
// Write to Firestore
|
|
23
26
|
self.libraries.admin.database().ref(payload.data.payload.path)
|
|
24
27
|
.set(payload.data.payload.document)
|
|
25
28
|
.then(() => {
|
|
@@ -13,11 +13,12 @@ Module.prototype.main = function () {
|
|
|
13
13
|
const payload = self.payload;
|
|
14
14
|
|
|
15
15
|
return new Promise(async function(resolve, reject) {
|
|
16
|
-
|
|
16
|
+
// Perform checks
|
|
17
17
|
if (!payload.user.roles.admin) {
|
|
18
18
|
return reject(assistant.errorManager(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
// Run queries
|
|
21
22
|
self.docs = [];
|
|
22
23
|
assistant.log('Queries', payload.data.payload.queries);
|
|
23
24
|
let queries = powertools.arrayify(payload.data.payload.queries || []);
|
|
@@ -28,6 +29,7 @@ Module.prototype.main = function () {
|
|
|
28
29
|
promises.push(self.runQuery(queries[i]))
|
|
29
30
|
}
|
|
30
31
|
|
|
32
|
+
// Get the results
|
|
31
33
|
await Promise.all(promises)
|
|
32
34
|
.then((r) => {
|
|
33
35
|
return resolve({data: self.docs});
|
|
@@ -10,29 +10,26 @@ Module.prototype.main = function () {
|
|
|
10
10
|
const payload = self.payload;
|
|
11
11
|
|
|
12
12
|
return new Promise(async function(resolve, reject) {
|
|
13
|
+
// Set defaults
|
|
14
|
+
payload.data.payload.path = `${payload.data.payload.path || ''}`;
|
|
15
|
+
payload.data.payload.options = payload.data.payload.options || {};
|
|
13
16
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
payload.data.payload.path = `${payload.data.payload.path || ''}`;
|
|
17
|
-
payload.data.payload.options = payload.data.payload.options || {};
|
|
18
|
-
|
|
19
|
-
if (!payload.data.payload.path) {
|
|
20
|
-
return reject(assistant.errorManager(`<path> parameter required`, {code: 400, sentry: false, send: false, log: false}).error)
|
|
21
|
-
} else {
|
|
22
|
-
await self.libraries.admin.firestore().doc(payload.data.payload.path)
|
|
23
|
-
.get()
|
|
24
|
-
.then(doc => {
|
|
25
|
-
return resolve({data: doc.data()});
|
|
26
|
-
})
|
|
27
|
-
.catch(e => {
|
|
28
|
-
return reject(assistant.errorManager(e, {code: 500, sentry: false, send: false, log: false}).error)
|
|
29
|
-
})
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
} else {
|
|
17
|
+
// Perform checks
|
|
18
|
+
if (!payload.user.roles.admin) {
|
|
33
19
|
return reject(assistant.errorManager(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
|
|
20
|
+
} else if (!payload.data.payload.path) {
|
|
21
|
+
return reject(assistant.errorManager(`<path> parameter required`, {code: 400, sentry: false, send: false, log: false}).error)
|
|
34
22
|
}
|
|
35
23
|
|
|
24
|
+
// Read from Firestore
|
|
25
|
+
await self.libraries.admin.firestore().doc(payload.data.payload.path)
|
|
26
|
+
.get()
|
|
27
|
+
.then(doc => {
|
|
28
|
+
return resolve({data: doc.data()});
|
|
29
|
+
})
|
|
30
|
+
.catch(e => {
|
|
31
|
+
return reject(assistant.errorManager(e, {code: 500, sentry: false, send: false, log: false}).error)
|
|
32
|
+
})
|
|
36
33
|
});
|
|
37
34
|
|
|
38
35
|
};
|
|
@@ -10,26 +10,28 @@ Module.prototype.main = function () {
|
|
|
10
10
|
const payload = self.payload;
|
|
11
11
|
|
|
12
12
|
return new Promise(async function(resolve, reject) {
|
|
13
|
-
|
|
13
|
+
// Set defaults
|
|
14
14
|
payload.data.payload.path = `${payload.data.payload.path || ''}`;
|
|
15
15
|
payload.data.payload.document = payload.data.payload.document || {};
|
|
16
16
|
payload.data.payload.options = payload.data.payload.options || {};
|
|
17
17
|
payload.data.payload.options.merge = typeof payload.data.payload.options.merge === 'undefined' ? true : payload.data.payload.options.merge;
|
|
18
18
|
|
|
19
|
+
// Perform checks
|
|
19
20
|
if (!payload.user.roles.admin) {
|
|
20
21
|
return reject(assistant.errorManager(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
|
|
21
22
|
} else if (!payload.data.payload.path) {
|
|
22
23
|
return reject(assistant.errorManager(`Path parameter required.`, {code: 400, sentry: false, send: false, log: false}).error)
|
|
23
|
-
} else {
|
|
24
|
-
await self.libraries.admin.firestore().doc(payload.data.payload.path)
|
|
25
|
-
.set(payload.data.payload.document, payload.data.payload.options)
|
|
26
|
-
.then(r => {
|
|
27
|
-
return resolve({data: {path: payload.data.payload.path}});
|
|
28
|
-
})
|
|
29
|
-
.catch(e => {
|
|
30
|
-
return reject(assistant.errorManager(e, {code: 500, sentry: false, send: false, log: false}).error)
|
|
31
|
-
})
|
|
32
24
|
}
|
|
25
|
+
|
|
26
|
+
// Write to Firestore
|
|
27
|
+
await self.libraries.admin.firestore().doc(payload.data.payload.path)
|
|
28
|
+
.set(payload.data.payload.document, payload.data.payload.options)
|
|
29
|
+
.then(r => {
|
|
30
|
+
return resolve({data: {path: payload.data.payload.path}});
|
|
31
|
+
})
|
|
32
|
+
.catch(e => {
|
|
33
|
+
return reject(assistant.errorManager(e, {code: 500, sentry: false, send: false, log: false}).error)
|
|
34
|
+
})
|
|
33
35
|
});
|
|
34
36
|
|
|
35
37
|
};
|
|
@@ -12,47 +12,49 @@ Module.prototype.main = function () {
|
|
|
12
12
|
const payload = self.payload;
|
|
13
13
|
|
|
14
14
|
return new Promise(async function(resolve, reject) {
|
|
15
|
-
|
|
15
|
+
// Load libraries
|
|
16
16
|
_ = Manager.require('lodash')
|
|
17
17
|
|
|
18
|
+
// Perform checks
|
|
18
19
|
if (!payload.user.roles.admin) {
|
|
19
20
|
return reject(assistant.errorManager(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
|
|
20
|
-
}
|
|
21
|
-
const stats = self.libraries.admin.firestore().doc(`meta/stats`)
|
|
22
|
-
await stats
|
|
23
|
-
.get()
|
|
24
|
-
.then(async (doc) => {
|
|
25
|
-
let data = doc.data() || {};
|
|
26
|
-
|
|
27
|
-
// Only update if requested
|
|
28
|
-
if (payload.data.payload.update) {
|
|
29
|
-
await self.updateStats(data)
|
|
30
|
-
.catch(e => data = e)
|
|
31
|
-
}
|
|
21
|
+
}
|
|
32
22
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
23
|
+
// Get stats
|
|
24
|
+
const stats = self.libraries.admin.firestore().doc(`meta/stats`)
|
|
25
|
+
await stats
|
|
26
|
+
.get()
|
|
27
|
+
.then(async (doc) => {
|
|
28
|
+
let data = doc.data() || {};
|
|
36
29
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
.then(doc => {
|
|
41
|
-
data = doc.data() || {};
|
|
42
|
-
})
|
|
30
|
+
// Only update if requested
|
|
31
|
+
if (payload.data.payload.update) {
|
|
32
|
+
await self.updateStats(data)
|
|
43
33
|
.catch(e => data = e)
|
|
34
|
+
}
|
|
44
35
|
|
|
36
|
+
if (data instanceof Error) {
|
|
37
|
+
return reject(assistant.errorManager(data, {code: 500, sentry: false, send: false, log: false}).error)
|
|
38
|
+
}
|
|
45
39
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
40
|
+
// Retrieve the stats again after updating
|
|
41
|
+
await stats
|
|
42
|
+
.get()
|
|
43
|
+
.then(doc => {
|
|
44
|
+
data = doc.data() || {};
|
|
45
|
+
})
|
|
46
|
+
.catch(e => data = e)
|
|
49
47
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
48
|
+
|
|
49
|
+
if (data instanceof Error) {
|
|
50
|
+
return reject(assistant.errorManager(data, {code: 500, sentry: false, send: false, log: false}).error)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return resolve({data: data})
|
|
54
|
+
})
|
|
55
|
+
.catch(function (e) {
|
|
56
|
+
return reject(assistant.errorManager(`Failed to get: ${e}`, {code: 500, sentry: false, send: false, log: false}).error)
|
|
57
|
+
})
|
|
56
58
|
});
|
|
57
59
|
|
|
58
60
|
};
|
|
@@ -37,10 +37,10 @@ function User(settings, options) {
|
|
|
37
37
|
},
|
|
38
38
|
trial: {
|
|
39
39
|
activated: _.get(settings, 'plan.trial.activated', useDefaults ? false : null),
|
|
40
|
-
|
|
41
|
-
timestamp: _.get(settings, 'plan.trial.
|
|
42
|
-
timestampUNIX: _.get(settings, 'plan.trial.
|
|
43
|
-
}
|
|
40
|
+
expires: {
|
|
41
|
+
timestamp: _.get(settings, 'plan.trial.expires.timestamp', useDefaults ? oldDate : null),
|
|
42
|
+
timestampUNIX: _.get(settings, 'plan.trial.expires.timestampUNIX', useDefaults ? oldDateUNIX : null),
|
|
43
|
+
},
|
|
44
44
|
},
|
|
45
45
|
limits: {
|
|
46
46
|
// devices: _.get(settings, 'plan.limits.devices', null),
|