backend-manager 3.2.172 → 3.2.174
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 +3 -3
- package/src/cli/cli.js +27 -11
- package/src/manager/helpers/assistant.js +51 -76
- package/src/manager/index.js +22 -1
- package/dist/cli/cli.js +0 -1534
- package/dist/manager/functions/core/actions/api/admin/backup.js +0 -338
- package/dist/manager/functions/core/actions/api/admin/create-post.js +0 -388
- package/dist/manager/functions/core/actions/api/admin/cron.js +0 -37
- package/dist/manager/functions/core/actions/api/admin/database-read.js +0 -35
- package/dist/manager/functions/core/actions/api/admin/database-write.js +0 -39
- package/dist/manager/functions/core/actions/api/admin/edit-post.js +0 -158
- package/dist/manager/functions/core/actions/api/admin/firestore-query.js +0 -165
- package/dist/manager/functions/core/actions/api/admin/firestore-read.js +0 -38
- package/dist/manager/functions/core/actions/api/admin/firestore-write.js +0 -54
- package/dist/manager/functions/core/actions/api/admin/get-stats.js +0 -269
- package/dist/manager/functions/core/actions/api/admin/payment-processor.js +0 -57
- package/dist/manager/functions/core/actions/api/admin/run-hook.js +0 -95
- package/dist/manager/functions/core/actions/api/admin/send-notification.js +0 -197
- package/dist/manager/functions/core/actions/api/admin/sync-users.js +0 -125
- package/dist/manager/functions/core/actions/api/admin/templates/post.html +0 -16
- package/dist/manager/functions/core/actions/api/firebase/get-providers.js +0 -102
- package/dist/manager/functions/core/actions/api/general/emails/general:download-app-link.js +0 -21
- package/dist/manager/functions/core/actions/api/general/fetch-post.js +0 -99
- package/dist/manager/functions/core/actions/api/general/generate-uuid.js +0 -41
- package/dist/manager/functions/core/actions/api/general/send-email.js +0 -112
- package/dist/manager/functions/core/actions/api/handler/create-post.js +0 -146
- package/dist/manager/functions/core/actions/api/special/setup-electron-manager-client.js +0 -103
- package/dist/manager/functions/core/actions/api/template.js +0 -33
- package/dist/manager/functions/core/actions/api/test/authenticate.js +0 -22
- package/dist/manager/functions/core/actions/api/test/create-test-accounts.js +0 -27
- package/dist/manager/functions/core/actions/api/test/lab.js +0 -55
- package/dist/manager/functions/core/actions/api/test/redirect.js +0 -26
- package/dist/manager/functions/core/actions/api/test/webhook.js +0 -30
- package/dist/manager/functions/core/actions/api/user/create-custom-token.js +0 -32
- package/dist/manager/functions/core/actions/api/user/delete.js +0 -68
- package/dist/manager/functions/core/actions/api/user/get-active-sessions.js +0 -45
- package/dist/manager/functions/core/actions/api/user/get-subscription-info.js +0 -49
- package/dist/manager/functions/core/actions/api/user/oauth2/discord.js +0 -114
- package/dist/manager/functions/core/actions/api/user/oauth2/google.js +0 -99
- package/dist/manager/functions/core/actions/api/user/oauth2.js +0 -476
- package/dist/manager/functions/core/actions/api/user/regenerate-api-keys.js +0 -54
- package/dist/manager/functions/core/actions/api/user/resolve.js +0 -32
- package/dist/manager/functions/core/actions/api/user/sign-out-all-sessions.js +0 -118
- package/dist/manager/functions/core/actions/api/user/sign-up copy.js +0 -544
- package/dist/manager/functions/core/actions/api/user/sign-up.js +0 -99
- package/dist/manager/functions/core/actions/api/user/submit-feedback.js +0 -96
- package/dist/manager/functions/core/actions/api/user/validate-settings.js +0 -86
- package/dist/manager/functions/core/actions/api.js +0 -354
- package/dist/manager/functions/core/actions/create-post-handler.js +0 -184
- package/dist/manager/functions/core/actions/generate-uuid.js +0 -62
- package/dist/manager/functions/core/actions/sign-up-handler.js +0 -205
- package/dist/manager/functions/core/admin/create-post.js +0 -206
- package/dist/manager/functions/core/admin/firestore-write.js +0 -72
- package/dist/manager/functions/core/admin/get-stats.js +0 -218
- package/dist/manager/functions/core/admin/query.js +0 -198
- package/dist/manager/functions/core/admin/send-notification.js +0 -206
- package/dist/manager/functions/core/cron/daily/ghostii-auto-publisher.js +0 -377
- package/dist/manager/functions/core/cron/daily/reset-usage.js +0 -197
- package/dist/manager/functions/core/cron/daily.js +0 -114
- package/dist/manager/functions/core/events/auth/before-create.js +0 -124
- package/dist/manager/functions/core/events/auth/before-signin.js +0 -62
- package/dist/manager/functions/core/events/auth/on-create copy.js +0 -121
- package/dist/manager/functions/core/events/auth/on-create.js +0 -564
- package/dist/manager/functions/core/events/auth/on-delete.js +0 -72
- package/dist/manager/functions/core/events/firestore/on-subscription.js +0 -107
- package/dist/manager/functions/test/authenticate.js +0 -38
- package/dist/manager/functions/test/create-test-accounts.js +0 -144
- package/dist/manager/functions/test/webhook.js +0 -37
- package/dist/manager/functions/wrappers/mailchimp/addToList.js +0 -25
- package/dist/manager/helpers/analytics copy.js +0 -217
- package/dist/manager/helpers/analytics.js +0 -467
- package/dist/manager/helpers/api-manager.js +0 -324
- package/dist/manager/helpers/assistant.js +0 -1043
- package/dist/manager/helpers/metadata.js +0 -32
- package/dist/manager/helpers/middleware.js +0 -154
- package/dist/manager/helpers/roles.js +0 -69
- package/dist/manager/helpers/settings.js +0 -158
- package/dist/manager/helpers/subscription-resolver-new.js +0 -828
- package/dist/manager/helpers/subscription-resolver.js +0 -842
- package/dist/manager/helpers/usage.js +0 -381
- package/dist/manager/helpers/user.js +0 -198
- package/dist/manager/helpers/utilities.js +0 -292
- package/dist/manager/index.js +0 -1076
- package/dist/manager/libraries/openai.js +0 -460
- package/dist/manager/routes/restart/index.js +0 -52
- package/dist/manager/routes/test/index.js +0 -43
- package/dist/manager/schemas/restart.js +0 -13
- package/dist/manager/schemas/test.js +0 -13
- package/dist/require.js +0 -3
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
const pushid = require('pushid');
|
|
2
|
-
const fetch = require('wonderful-fetch');
|
|
3
|
-
const powertools = require('node-powertools');
|
|
4
|
-
const { get } = require('lodash');
|
|
5
|
-
|
|
6
|
-
function Module() {
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
Module.prototype.main = function () {
|
|
11
|
-
const self = this;
|
|
12
|
-
const Manager = self.Manager;
|
|
13
|
-
const Api = self.Api;
|
|
14
|
-
const assistant = self.assistant;
|
|
15
|
-
const payload = self.payload;
|
|
16
|
-
|
|
17
|
-
return new Promise(async function(resolve, reject) {
|
|
18
|
-
Api.resolveUser({adminRequired: true})
|
|
19
|
-
.then(async (user) => {
|
|
20
|
-
|
|
21
|
-
const docId = pushid();
|
|
22
|
-
const request = payload.data.payload;
|
|
23
|
-
|
|
24
|
-
// Preprocess
|
|
25
|
-
const decision = {
|
|
26
|
-
promptReview: false,
|
|
27
|
-
reviewURL: null,
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// If rating is like or love and like feedback is more than dislike feedback
|
|
31
|
-
if (
|
|
32
|
-
['like', 'love'].includes(request.rating)
|
|
33
|
-
&& request.like.length >= request.dislike.length + 10
|
|
34
|
-
) {
|
|
35
|
-
decision.promptReview = true;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Get app data
|
|
39
|
-
fetch(`https://us-central1-itw-creative-works.cloudfunctions.net/getApp`, {
|
|
40
|
-
method: 'post',
|
|
41
|
-
response: 'json',
|
|
42
|
-
body: {
|
|
43
|
-
id: Manager.config.app.id,
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
.then((response) => {
|
|
47
|
-
response.reviews = response.reviews || {};
|
|
48
|
-
response.reviews.enabled = typeof response.reviews.enabled === 'undefined' ? true : response.reviews.enabled;
|
|
49
|
-
response.reviews.sites = response.reviews.sites || [];
|
|
50
|
-
|
|
51
|
-
// If reviews are enabled and there are review sites, prompt review
|
|
52
|
-
if (response.reviews.enabled && response.reviews.sites.length > 0) {
|
|
53
|
-
decision.reviewURL = powertools.random(response.reviews.sites);
|
|
54
|
-
} else {
|
|
55
|
-
decision.promptReview = false;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
assistant.log('Feedback submitted', docId, {appReviewData: response.reviews, request: request, decision: decision});
|
|
59
|
-
|
|
60
|
-
// Save feedback to firestore
|
|
61
|
-
self.libraries.admin.firestore().doc(`feedback/${docId}`)
|
|
62
|
-
.set({
|
|
63
|
-
created: assistant.meta.startTime,
|
|
64
|
-
feedback: request,
|
|
65
|
-
decision: decision,
|
|
66
|
-
owner: {
|
|
67
|
-
uid: get(user, 'auth.uid', null),
|
|
68
|
-
},
|
|
69
|
-
metadata: Manager.Metadata().set({tag: 'user:submit-feedback'}),
|
|
70
|
-
}, {merge: true})
|
|
71
|
-
.then(r => {
|
|
72
|
-
return resolve({
|
|
73
|
-
data: {
|
|
74
|
-
review: decision,
|
|
75
|
-
originalRequest: request,
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
})
|
|
79
|
-
.catch((e) => {
|
|
80
|
-
return reject(assistant.errorify(`Failed to save feedback: ${e.message}`, {code: 500, sentry: true}));
|
|
81
|
-
})
|
|
82
|
-
})
|
|
83
|
-
.catch((e) => {
|
|
84
|
-
return reject(assistant.errorify(`Failed to get app: ${e.message}`, {code: 500, sentry: true}));
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
})
|
|
88
|
-
.catch((e) => {
|
|
89
|
-
return reject(e);
|
|
90
|
-
})
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
module.exports = Module;
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
const _ = require('lodash')
|
|
2
|
-
const jetpack = require('fs-jetpack')
|
|
3
|
-
const powertools = require('node-powertools')
|
|
4
|
-
const path = require('path')
|
|
5
|
-
|
|
6
|
-
function Module() {
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
Module.prototype.main = function () {
|
|
11
|
-
const self = this;
|
|
12
|
-
|
|
13
|
-
// Set shortcuts
|
|
14
|
-
const Manager = self.Manager;
|
|
15
|
-
const Api = self.Api;
|
|
16
|
-
const assistant = self.assistant;
|
|
17
|
-
const payload = self.payload;
|
|
18
|
-
|
|
19
|
-
return new Promise(async function(resolve, reject) {
|
|
20
|
-
Api.resolveUser({adminRequired: true})
|
|
21
|
-
.then(async (user) => {
|
|
22
|
-
|
|
23
|
-
payload.data.payload.defaultsPath = payload.data.payload.defaultsPath || '';
|
|
24
|
-
payload.data.payload.existingSettings = payload.data.payload.existingSettings || {};
|
|
25
|
-
payload.data.payload.newSettings = payload.data.payload.newSettings || {};
|
|
26
|
-
|
|
27
|
-
const settings = _.merge({}, payload.data.payload.existingSettings, payload.data.payload.newSettings);
|
|
28
|
-
|
|
29
|
-
const resolvedPath = path.join(Manager.cwd, `defaults.js`);
|
|
30
|
-
|
|
31
|
-
// Check if the file exists
|
|
32
|
-
if (!jetpack.exists(resolvedPath)) {
|
|
33
|
-
return reject(assistant.errorify(`Defaults file at ${resolvedPath} does not exist, please add it manually.`, {code: 500, sentry: true}));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Load the file
|
|
37
|
-
try {
|
|
38
|
-
const defaults = _.get(require(resolvedPath)(), payload.data.payload.defaultsPath);
|
|
39
|
-
const combined = combine(defaults.all, defaults[user.plan.id] || {})
|
|
40
|
-
|
|
41
|
-
assistant.log('Combined settings', combined)
|
|
42
|
-
|
|
43
|
-
return resolve({data: powertools.defaults(settings, combined)});
|
|
44
|
-
} catch (e) {
|
|
45
|
-
return reject(assistant.errorify(`Unable to load file at ${resolvedPath}: ${e}`, {code: 500, sentry: true}));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
})
|
|
49
|
-
.catch(e => {
|
|
50
|
-
return reject(e);
|
|
51
|
-
})
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
function isObject(value) {
|
|
57
|
-
return value && typeof value === 'object' && !Array.isArray(value);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function combine(one, two) {
|
|
61
|
-
const done = [];
|
|
62
|
-
|
|
63
|
-
// Iterate through the keys of the second object
|
|
64
|
-
powertools.getKeys(two)
|
|
65
|
-
.forEach(path => {
|
|
66
|
-
const pathMinusLast = path.split('.').slice(0, -1).join('.');
|
|
67
|
-
const valueAtPath = _.get(two, path);
|
|
68
|
-
const valueAtParent = _.get(two, pathMinusLast);
|
|
69
|
-
|
|
70
|
-
if (
|
|
71
|
-
done.includes(pathMinusLast)
|
|
72
|
-
|| isObject(valueAtPath)
|
|
73
|
-
) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// If the path is an object, merge the two object using lodash
|
|
78
|
-
_.set(one, pathMinusLast, valueAtParent)
|
|
79
|
-
|
|
80
|
-
done.push(pathMinusLast);
|
|
81
|
-
})
|
|
82
|
-
return one;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
module.exports = Module;
|
|
@@ -1,354 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const _ = require('lodash');
|
|
3
|
-
const jetpack = require('fs-jetpack');
|
|
4
|
-
const powertools = require('node-powertools');
|
|
5
|
-
|
|
6
|
-
function Module() {
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
Module.prototype.init = function (Manager, data) {
|
|
11
|
-
const self = this;
|
|
12
|
-
self.Manager = Manager;
|
|
13
|
-
self.libraries = Manager.libraries;
|
|
14
|
-
self.assistant = Manager.Assistant({req: data.req, res: data.res})
|
|
15
|
-
self.req = data.req;
|
|
16
|
-
self.res = data.res;
|
|
17
|
-
self.payload = {
|
|
18
|
-
response: {
|
|
19
|
-
status: 200,
|
|
20
|
-
data: {},
|
|
21
|
-
error: null,
|
|
22
|
-
},
|
|
23
|
-
data: {},
|
|
24
|
-
user: {},
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
// Fix the two required
|
|
28
|
-
const resolved = self.resolveCommand(self.assistant.request.data.command);
|
|
29
|
-
self.assistant.request.data.command = resolved.command;
|
|
30
|
-
self.assistant.request.data.payload = self.assistant.request.data.payload || {};
|
|
31
|
-
self.assistant.request.data.options = self.assistant.request.data.options || {};
|
|
32
|
-
|
|
33
|
-
if (Manager.options.log) {
|
|
34
|
-
self.assistant.log(`Executing (log): ${resolved.command}`, self.assistant.request, JSON.stringify(self.assistant.request))
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return self;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
Module.prototype.main = function() {
|
|
41
|
-
const self = this;
|
|
42
|
-
const Manager = self.Manager;
|
|
43
|
-
const libraries = self.libraries;
|
|
44
|
-
const assistant = self.assistant;
|
|
45
|
-
const req = self.req;
|
|
46
|
-
const res = self.res;
|
|
47
|
-
|
|
48
|
-
return new Promise(async function(resolve, reject) {
|
|
49
|
-
return libraries.cors(req, res, async () => {
|
|
50
|
-
self.payload.data = assistant.request.data;
|
|
51
|
-
self.payload.user = await assistant.authenticate();
|
|
52
|
-
|
|
53
|
-
// Quit if OPTIONS request
|
|
54
|
-
if (self.assistant.request.method === 'OPTIONS') {
|
|
55
|
-
return resolve();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Resolve command
|
|
59
|
-
const resolved = self.resolveCommand(self.payload.data.command);
|
|
60
|
-
|
|
61
|
-
self.assistant.log(`Executing: ${resolved.command}`, self.payload, JSON.stringify(self.payload))
|
|
62
|
-
self.assistant.log(`Resolved URL: ${Manager.project.functionsUrl}?command=${encodeURIComponent(resolved.command)}&payload=${encodeURIComponent(JSON.stringify(self.assistant.request.data.payload))}`)
|
|
63
|
-
|
|
64
|
-
// Set up options
|
|
65
|
-
self.payload.data.options = self.payload.data.options || {};
|
|
66
|
-
self.payload.data.options.delay = self.payload.data.options.delay || 0;
|
|
67
|
-
|
|
68
|
-
// Delay
|
|
69
|
-
if (self.payload.data.options.delay > 0) {
|
|
70
|
-
let delay = Math.floor(self.payload.data.options.delay / 1000);
|
|
71
|
-
|
|
72
|
-
await powertools.poll(() => {
|
|
73
|
-
self.assistant.log(`Delaying for ${delay--} seconds...`);
|
|
74
|
-
}, {interval: 1000, timeout: self.payload.data.options.delay})
|
|
75
|
-
.catch(e => e);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (!resolved.exists) {
|
|
79
|
-
self.payload.response.status = 400;
|
|
80
|
-
self.payload.response.error = new Error(`${self.payload.data.command} is not a valid command`);
|
|
81
|
-
} else {
|
|
82
|
-
await self.import(resolved.command)
|
|
83
|
-
.then(async lib => {
|
|
84
|
-
try {
|
|
85
|
-
// Call main function
|
|
86
|
-
await lib.main()
|
|
87
|
-
.then(result => {
|
|
88
|
-
result = result || {};
|
|
89
|
-
// console.log('---result', result);
|
|
90
|
-
// console.log('---self.payload.response.data', self.payload.response.data);
|
|
91
|
-
self.payload.response.status = result.status || self.payload.response.status || 200;
|
|
92
|
-
self.payload.response.data = result.data || self.payload.response.data || {};
|
|
93
|
-
self.payload.response.redirect = result.redirect || self.payload.response.redirect || null;
|
|
94
|
-
})
|
|
95
|
-
.catch(e => {
|
|
96
|
-
// console.log('---e', e);
|
|
97
|
-
self.payload.response.status = e && e.code ? e.code : 500;
|
|
98
|
-
self.payload.response.error = e || new Error('Unknown error occured');
|
|
99
|
-
})
|
|
100
|
-
} catch (e) {
|
|
101
|
-
self.payload.response.status = e && e.code ? e.code : 500;
|
|
102
|
-
self.payload.response.error = e || new Error('Unknown error occured');
|
|
103
|
-
}
|
|
104
|
-
})
|
|
105
|
-
.catch(e => {
|
|
106
|
-
self.payload.response.status = 400;
|
|
107
|
-
self.payload.response.error = new Error(`Failed to import: ${e}`);
|
|
108
|
-
})
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// Fix status
|
|
112
|
-
self.payload.response.status = _fixStatus(self.payload.response.status);
|
|
113
|
-
|
|
114
|
-
// Set status
|
|
115
|
-
res.status(self.payload.response.status)
|
|
116
|
-
|
|
117
|
-
// Send response
|
|
118
|
-
if (self.payload.response.status >= 200 && self.payload.response.status < 399) {
|
|
119
|
-
self.assistant.log(`Finished ${resolved.command} (status=${self.payload.response.status})`, self.payload, JSON.stringify(self.payload))
|
|
120
|
-
|
|
121
|
-
if (self.payload.response.redirect) {
|
|
122
|
-
res.redirect(self.payload.response.redirect);
|
|
123
|
-
return resolve();
|
|
124
|
-
} else {
|
|
125
|
-
res.json(self.payload.response.data);
|
|
126
|
-
return resolve();
|
|
127
|
-
}
|
|
128
|
-
} else {
|
|
129
|
-
self.assistant.error(`Error executing ${resolved.command} @ ${resolved.path} (status=${self.payload.response.status}):`, self.payload.response.error)
|
|
130
|
-
res.send(`${self.payload.response.error}`)
|
|
131
|
-
return reject(self.payload.response.error);
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
Module.prototype.import = function (command, payload, user, response) {
|
|
138
|
-
const self = this;
|
|
139
|
-
|
|
140
|
-
return new Promise(function(resolve, reject) {
|
|
141
|
-
const resolved = self.resolveCommand(command);
|
|
142
|
-
|
|
143
|
-
try {
|
|
144
|
-
const lib = new (require(resolved.path))();
|
|
145
|
-
|
|
146
|
-
// Initialize
|
|
147
|
-
lib.Api = self;
|
|
148
|
-
lib.Manager = self.Manager;
|
|
149
|
-
lib.libraries = self.Manager.libraries;
|
|
150
|
-
lib.assistant = self.assistant;
|
|
151
|
-
lib.payload = _.cloneDeep({
|
|
152
|
-
data: {
|
|
153
|
-
// command: '?',
|
|
154
|
-
payload: payload ? payload : self.payload.data.payload,
|
|
155
|
-
},
|
|
156
|
-
user: user ? user : self.payload.user,
|
|
157
|
-
response: response ? response : self.payload.response,
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
if (self.payload.data.backendManagerKey) {
|
|
161
|
-
lib.payload.data.backendManagerKey = self.payload.data.backendManagerKey;
|
|
162
|
-
} else if (self.payload.data.authenticationToken) {
|
|
163
|
-
lib.payload.data.authenticationToken = self.payload.data.authenticationToken;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// Set itself to the instance
|
|
167
|
-
self.lib = lib;
|
|
168
|
-
|
|
169
|
-
// console.log('***** import() lib.payload 4', lib.payload);
|
|
170
|
-
|
|
171
|
-
// lib.payload = {};
|
|
172
|
-
//
|
|
173
|
-
// // Set payload and user if it's provided
|
|
174
|
-
// lib.payload.data.payload = payload ? _.cloneDeep(payload) : lib.payload.data.payload;
|
|
175
|
-
// lib.payload.user = user ? _.cloneDeep(user) : lib.payload.user;
|
|
176
|
-
// lib.payload.response = response ? _.cloneDeep(response) : lib.payload.response;
|
|
177
|
-
|
|
178
|
-
return resolve(lib);
|
|
179
|
-
} catch (e) {
|
|
180
|
-
return reject(e);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
Module.prototype.resolveCommand = function (command) {
|
|
187
|
-
const self = this;
|
|
188
|
-
const originalCommand = command;
|
|
189
|
-
|
|
190
|
-
command = command || '';
|
|
191
|
-
|
|
192
|
-
// Start
|
|
193
|
-
if (false) {
|
|
194
|
-
|
|
195
|
-
// General
|
|
196
|
-
} else if (command === 'general:generate-uuid' || command === 'generate-uuid') {
|
|
197
|
-
command = 'general:generate-uuid';
|
|
198
|
-
|
|
199
|
-
// User
|
|
200
|
-
} else if (command === 'user:create-custom-token' || command === 'create-custom-token') { // rename: user:create-custom-token
|
|
201
|
-
command = 'user:create-custom-token';
|
|
202
|
-
} else if (command === 'user:delete' || command === 'delete-user') { // rename: user:delete
|
|
203
|
-
command = 'user:delete';
|
|
204
|
-
} else if (command === 'user:sign-out-all-sessions' || command === 'sign-out-all-sessions') { // rename: user:sign-out-all-sessions
|
|
205
|
-
command = 'user:sign-out-all-sessions';
|
|
206
|
-
} else if (command === 'user:get-subscription-info' || command === 'get-user-subscription-info') { // rename: user:get-subscription-info
|
|
207
|
-
command = 'user:get-subscription-info';
|
|
208
|
-
} else if (command === 'user:sign-up' || command === 'sign-up') {
|
|
209
|
-
command = 'user:sign-up';
|
|
210
|
-
|
|
211
|
-
// Handler
|
|
212
|
-
} else if (command === 'handler:create-post') {
|
|
213
|
-
command = 'handler:create-post';
|
|
214
|
-
|
|
215
|
-
// Admin
|
|
216
|
-
} else if (command === 'admin:create-post') {
|
|
217
|
-
command = 'admin:create-post';
|
|
218
|
-
} else if (command === 'admin:get-stats') {
|
|
219
|
-
command = 'admin:get-stats';
|
|
220
|
-
} else if (command === 'admin:send-notification') {
|
|
221
|
-
command = 'admin:send-notification';
|
|
222
|
-
} else if (command === 'admin:firestore-read' || command === 'firestore-read') {
|
|
223
|
-
command = 'admin:firestore-read';
|
|
224
|
-
} else if (command === 'admin:firestore-write' || command === 'firestore-write') {
|
|
225
|
-
command = 'admin:firestore-write';
|
|
226
|
-
} else if (command === 'admin:firestore-query' || command === 'firestore-query') {
|
|
227
|
-
command = 'admin:firestore-query';
|
|
228
|
-
} else if (command === 'admin:payment-processor' || command === 'payment-processor') { // rename: admin:payment-processor
|
|
229
|
-
command = 'admin:payment-processor';
|
|
230
|
-
|
|
231
|
-
// Special
|
|
232
|
-
// } else if (command === 'special:setup-electron-manager-client' || command === 'setup-electron-manager-client') {
|
|
233
|
-
// command = 'special:setup-electron-manager-client';
|
|
234
|
-
|
|
235
|
-
// Test
|
|
236
|
-
// } else if (command === 'test:authenticate' || command === 'authenticate') {
|
|
237
|
-
// command = 'test:authenticate';
|
|
238
|
-
// } else if (command === 'test:create-test-accounts' || command === 'create-test-accounts') {
|
|
239
|
-
// command = 'test:create-test-accounts';
|
|
240
|
-
// } else if (command === 'test:webhook' || command === 'webhook') {
|
|
241
|
-
// command = 'test:webhook';
|
|
242
|
-
|
|
243
|
-
// End
|
|
244
|
-
} else {
|
|
245
|
-
// command = 'error:error';
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// Check local path
|
|
249
|
-
const resolvedPath = self.resolveApiPath(command);
|
|
250
|
-
|
|
251
|
-
// if (!command || command === 'error:error') {
|
|
252
|
-
if (!resolvedPath) {
|
|
253
|
-
self.assistant.log(`This command does not exist: ${originalCommand} => ${command} @ ${resolvedPath}`)
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
return {
|
|
257
|
-
command: command,
|
|
258
|
-
path: resolvedPath,
|
|
259
|
-
exists: !!resolvedPath,
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
Module.prototype.resolveUser = function (options) {
|
|
264
|
-
const self = this;
|
|
265
|
-
|
|
266
|
-
return new Promise(async function(resolve, reject) {
|
|
267
|
-
let user = null;
|
|
268
|
-
|
|
269
|
-
options = options || {};
|
|
270
|
-
options.uid = typeof options.uid !== 'undefined' ? options.uid : _.get(self.payload, 'data.payload.uid');
|
|
271
|
-
options.admin = typeof options.admin !== 'undefined' ? options.admin : _.get(self.payload, 'user.roles.admin');
|
|
272
|
-
options.adminRequired = typeof options.adminRequired !== 'undefined' ? options.adminRequired : true;
|
|
273
|
-
|
|
274
|
-
if (options.uid) {
|
|
275
|
-
if (options.adminRequired && !options.admin) {
|
|
276
|
-
user = self.assistant.errorify('Admin required', {code: 401});
|
|
277
|
-
} else {
|
|
278
|
-
await self.libraries.admin.firestore().doc(`users/${options.uid}`)
|
|
279
|
-
.get()
|
|
280
|
-
.then(async function (doc) {
|
|
281
|
-
const data = doc.data();
|
|
282
|
-
if (data) {
|
|
283
|
-
user = data;
|
|
284
|
-
} else {
|
|
285
|
-
user = self.assistant.errorify(`User does not exist: ${options.uid}`, {code: 400});
|
|
286
|
-
}
|
|
287
|
-
})
|
|
288
|
-
.catch(function (e) {
|
|
289
|
-
user = self.assistant.errorify(e, {code: 500});
|
|
290
|
-
})
|
|
291
|
-
}
|
|
292
|
-
} else if (self.payload.user.authenticated) {
|
|
293
|
-
user = self.payload.user;
|
|
294
|
-
} else if (_.get(self.lib, 'payload.user.authenticated')) {
|
|
295
|
-
user = self.lib.payload.user;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
if (user instanceof Error) {
|
|
299
|
-
return reject(user);
|
|
300
|
-
} else if (!user) {
|
|
301
|
-
return reject(self.assistant.errorify('Unable to resolve user', {code: 500}));
|
|
302
|
-
} else {
|
|
303
|
-
return resolve(user);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
});
|
|
307
|
-
};
|
|
308
|
-
|
|
309
|
-
function _fixStatus(status) {
|
|
310
|
-
if (typeof status === 'number') {
|
|
311
|
-
return status;
|
|
312
|
-
} else {
|
|
313
|
-
if (status === 'ok') {
|
|
314
|
-
return 200
|
|
315
|
-
} else {
|
|
316
|
-
return 500
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
function resolveBasePath(basePath, command) {
|
|
322
|
-
const sanitizedCommand = command.replace(/\.\.\//g, '').replace(/\:/, '/');
|
|
323
|
-
const resolvedPath = path.join(basePath, `${sanitizedCommand}.js`);
|
|
324
|
-
|
|
325
|
-
return resolvedPath;
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
Module.prototype.resolveApiPath = function (command) {
|
|
329
|
-
const self = this;
|
|
330
|
-
|
|
331
|
-
// Set shortcuts
|
|
332
|
-
const Manager = self.Manager;
|
|
333
|
-
const libraries = self.libraries;
|
|
334
|
-
const assistant = self.assistant;
|
|
335
|
-
const req = self.req;
|
|
336
|
-
const res = self.res;
|
|
337
|
-
|
|
338
|
-
// Set paths
|
|
339
|
-
const projectBasePath = path.join(Manager.cwd, 'routes/api');
|
|
340
|
-
const localBasePath = './api/';
|
|
341
|
-
|
|
342
|
-
const projectPath = resolveBasePath(projectBasePath, command);
|
|
343
|
-
const localPath = path.join(__dirname, resolveBasePath(localBasePath, command));
|
|
344
|
-
|
|
345
|
-
if (jetpack.exists(projectPath)) {
|
|
346
|
-
return projectPath;
|
|
347
|
-
} else if (jetpack.exists(localPath)) {
|
|
348
|
-
return localPath;
|
|
349
|
-
} else {
|
|
350
|
-
return null;
|
|
351
|
-
}
|
|
352
|
-
};
|
|
353
|
-
|
|
354
|
-
module.exports = Module;
|