backend-manager 3.2.169 → 3.2.171
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/LICENSE +1 -1
- package/README.md +1 -1
- package/dist/cli/cli.js +1534 -0
- package/dist/manager/functions/core/actions/api/admin/backup.js +338 -0
- package/dist/manager/functions/core/actions/api/admin/create-post.js +388 -0
- package/dist/manager/functions/core/actions/api/admin/cron.js +37 -0
- package/dist/manager/functions/core/actions/api/admin/database-read.js +35 -0
- package/dist/manager/functions/core/actions/api/admin/database-write.js +39 -0
- package/dist/manager/functions/core/actions/api/admin/edit-post.js +158 -0
- package/dist/manager/functions/core/actions/api/admin/firestore-query.js +165 -0
- package/dist/manager/functions/core/actions/api/admin/firestore-read.js +38 -0
- package/dist/manager/functions/core/actions/api/admin/firestore-write.js +54 -0
- package/dist/manager/functions/core/actions/api/admin/get-stats.js +269 -0
- package/dist/manager/functions/core/actions/api/admin/payment-processor.js +57 -0
- package/dist/manager/functions/core/actions/api/admin/run-hook.js +95 -0
- package/dist/manager/functions/core/actions/api/admin/send-notification.js +197 -0
- package/dist/manager/functions/core/actions/api/admin/sync-users.js +125 -0
- package/dist/manager/functions/core/actions/api/admin/templates/post.html +16 -0
- package/dist/manager/functions/core/actions/api/firebase/get-providers.js +102 -0
- package/dist/manager/functions/core/actions/api/general/emails/general:download-app-link.js +21 -0
- package/dist/manager/functions/core/actions/api/general/fetch-post.js +99 -0
- package/dist/manager/functions/core/actions/api/general/generate-uuid.js +41 -0
- package/dist/manager/functions/core/actions/api/general/send-email.js +112 -0
- package/dist/manager/functions/core/actions/api/handler/create-post.js +146 -0
- package/dist/manager/functions/core/actions/api/special/setup-electron-manager-client.js +103 -0
- package/dist/manager/functions/core/actions/api/template.js +33 -0
- package/dist/manager/functions/core/actions/api/test/authenticate.js +22 -0
- package/dist/manager/functions/core/actions/api/test/create-test-accounts.js +27 -0
- package/dist/manager/functions/core/actions/api/test/lab.js +55 -0
- package/dist/manager/functions/core/actions/api/test/redirect.js +26 -0
- package/dist/manager/functions/core/actions/api/test/webhook.js +30 -0
- package/dist/manager/functions/core/actions/api/user/create-custom-token.js +32 -0
- package/dist/manager/functions/core/actions/api/user/delete.js +68 -0
- package/dist/manager/functions/core/actions/api/user/get-active-sessions.js +45 -0
- package/dist/manager/functions/core/actions/api/user/get-subscription-info.js +49 -0
- package/dist/manager/functions/core/actions/api/user/oauth2/discord.js +114 -0
- package/dist/manager/functions/core/actions/api/user/oauth2/google.js +99 -0
- package/dist/manager/functions/core/actions/api/user/oauth2.js +476 -0
- package/dist/manager/functions/core/actions/api/user/regenerate-api-keys.js +54 -0
- package/dist/manager/functions/core/actions/api/user/resolve.js +32 -0
- package/dist/manager/functions/core/actions/api/user/sign-out-all-sessions.js +118 -0
- package/dist/manager/functions/core/actions/api/user/sign-up copy.js +544 -0
- package/dist/manager/functions/core/actions/api/user/sign-up.js +99 -0
- package/dist/manager/functions/core/actions/api/user/submit-feedback.js +96 -0
- package/dist/manager/functions/core/actions/api/user/validate-settings.js +86 -0
- package/dist/manager/functions/core/actions/api.js +354 -0
- package/dist/manager/functions/core/actions/create-post-handler.js +184 -0
- package/dist/manager/functions/core/actions/generate-uuid.js +62 -0
- package/dist/manager/functions/core/actions/sign-up-handler.js +205 -0
- package/dist/manager/functions/core/admin/create-post.js +206 -0
- package/dist/manager/functions/core/admin/firestore-write.js +72 -0
- package/dist/manager/functions/core/admin/get-stats.js +218 -0
- package/dist/manager/functions/core/admin/query.js +198 -0
- package/dist/manager/functions/core/admin/send-notification.js +206 -0
- package/dist/manager/functions/core/cron/daily/ghostii-auto-publisher.js +377 -0
- package/dist/manager/functions/core/cron/daily/reset-usage.js +197 -0
- package/dist/manager/functions/core/cron/daily.js +114 -0
- package/dist/manager/functions/core/events/auth/before-create.js +124 -0
- package/dist/manager/functions/core/events/auth/before-signin.js +62 -0
- package/dist/manager/functions/core/events/auth/on-create copy.js +121 -0
- package/dist/manager/functions/core/events/auth/on-create.js +564 -0
- package/dist/manager/functions/core/events/auth/on-delete.js +72 -0
- package/dist/manager/functions/core/events/firestore/on-subscription.js +107 -0
- package/dist/manager/functions/test/authenticate.js +38 -0
- package/dist/manager/functions/test/create-test-accounts.js +144 -0
- package/dist/manager/functions/test/webhook.js +37 -0
- package/dist/manager/functions/wrappers/mailchimp/addToList.js +25 -0
- package/dist/manager/helpers/analytics copy.js +217 -0
- package/dist/manager/helpers/analytics.js +467 -0
- package/dist/manager/helpers/api-manager.js +324 -0
- package/dist/manager/helpers/assistant.js +1043 -0
- package/dist/manager/helpers/metadata.js +32 -0
- package/dist/manager/helpers/middleware.js +154 -0
- package/dist/manager/helpers/roles.js +69 -0
- package/dist/manager/helpers/settings.js +158 -0
- package/dist/manager/helpers/subscription-resolver-new.js +828 -0
- package/dist/manager/helpers/subscription-resolver.js +842 -0
- package/dist/manager/helpers/usage.js +381 -0
- package/dist/manager/helpers/user.js +198 -0
- package/dist/manager/helpers/utilities.js +292 -0
- package/dist/manager/index.js +1076 -0
- package/dist/manager/libraries/openai.js +460 -0
- package/dist/manager/routes/restart/index.js +52 -0
- package/dist/manager/routes/test/index.js +43 -0
- package/dist/manager/schemas/restart.js +13 -0
- package/dist/manager/schemas/test.js +13 -0
- package/dist/require.js +3 -0
- package/package.json +19 -9
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
|
|
16
|
+
Api.resolveUser({adminRequired: true})
|
|
17
|
+
.then(async (user) => {
|
|
18
|
+
const uid = _.get(user, 'auth.uid', null);
|
|
19
|
+
const id = _.get(payload.data.payload, 'id', 'app');
|
|
20
|
+
const session = `sessions/${id}`;
|
|
21
|
+
|
|
22
|
+
assistant.log(`Getting active sessions for ${uid} @ ${session}`)
|
|
23
|
+
|
|
24
|
+
await self.libraries.admin.database().ref(session)
|
|
25
|
+
.orderByChild('uid')
|
|
26
|
+
.equalTo(uid)
|
|
27
|
+
.once('value')
|
|
28
|
+
.then(async (snap) => {
|
|
29
|
+
const data = snap.val() || {};
|
|
30
|
+
return resolve({data: data});
|
|
31
|
+
})
|
|
32
|
+
.catch(e => {
|
|
33
|
+
return reject(assistant.errorify(`Session query error: ${e}`, {code: 500}));
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
})
|
|
37
|
+
.catch(e => {
|
|
38
|
+
return reject(e);
|
|
39
|
+
})
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
module.exports = Module;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const _ = require('lodash')
|
|
2
|
+
const powertools = require('node-powertools')
|
|
3
|
+
|
|
4
|
+
function Module() {
|
|
5
|
+
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
Module.prototype.main = function () {
|
|
9
|
+
const self = this;
|
|
10
|
+
const Manager = self.Manager;
|
|
11
|
+
const Api = self.Api;
|
|
12
|
+
const assistant = self.assistant;
|
|
13
|
+
const payload = self.payload;
|
|
14
|
+
|
|
15
|
+
return new Promise(async function(resolve, reject) {
|
|
16
|
+
const oldDate = powertools.timestamp(new Date(0), {output: 'string'})
|
|
17
|
+
const oldDateUNIX = powertools.timestamp(oldDate, {output: 'unix'});
|
|
18
|
+
|
|
19
|
+
Api.resolveUser({adminRequired: false})
|
|
20
|
+
.then(async (user) => {
|
|
21
|
+
const result = {
|
|
22
|
+
plan: {
|
|
23
|
+
id: _.get(user, 'plan.id', 'unknown'),
|
|
24
|
+
expires: {
|
|
25
|
+
timestamp: _.get(user, 'plan.expires.timestamp', oldDate),
|
|
26
|
+
timestampUNIX: _.get(user, 'plan.expires.timestampUNIX', oldDateUNIX),
|
|
27
|
+
},
|
|
28
|
+
trial: {
|
|
29
|
+
activated: _.get(user, 'plan.trial.activated', false),
|
|
30
|
+
date: {
|
|
31
|
+
timestamp: _.get(user, 'plan.trial.date.timestamp', oldDate),
|
|
32
|
+
timestampUNIX: _.get(user, 'plan.trial.date.timestampUNIX', oldDateUNIX),
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
payment: {
|
|
36
|
+
active: _.get(user, 'plan.payment.active', false),
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return resolve({data: result});
|
|
41
|
+
})
|
|
42
|
+
.catch(e => {
|
|
43
|
+
return reject(e);
|
|
44
|
+
})
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
module.exports = Module;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
const decode = require('jwt-decode')
|
|
2
|
+
const _ = require('lodash')
|
|
3
|
+
const fetch = require('wonderful-fetch')
|
|
4
|
+
|
|
5
|
+
function OAuth2() {
|
|
6
|
+
const self = this;
|
|
7
|
+
self.provider = 'discord';
|
|
8
|
+
self.name = 'Discord';
|
|
9
|
+
self.urls = {
|
|
10
|
+
// var oauthURL = 'https://discord.com/api/oauth2/authorize?client_id=701375931918581810&redirect_uri=URL&response_type=code&scope=identify';
|
|
11
|
+
|
|
12
|
+
authorize: 'https://discord.com/api/oauth2/authorize',
|
|
13
|
+
tokenize: 'https://discord.com/api/oauth2/token',
|
|
14
|
+
refresh: 'https://discord.com/api/oauth2/token',
|
|
15
|
+
status: '',
|
|
16
|
+
removeAccess: 'https://discord.com/channels/@me',
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
OAuth2.prototype.buildUrl = function (state, url) {
|
|
21
|
+
const self = this;
|
|
22
|
+
const Manager = self.Manager;
|
|
23
|
+
const assistant = self.assistant;
|
|
24
|
+
|
|
25
|
+
return new Promise(async function(resolve, reject) {
|
|
26
|
+
if (state === 'authorize') {
|
|
27
|
+
// do something with url
|
|
28
|
+
return resolve()
|
|
29
|
+
} else {
|
|
30
|
+
return resolve()
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
OAuth2.prototype.verifyIdentity = function (tokenizeResult) {
|
|
36
|
+
const self = this;
|
|
37
|
+
const Manager = self.Manager;
|
|
38
|
+
const assistant = self.assistant;
|
|
39
|
+
|
|
40
|
+
return new Promise(async function(resolve, reject) {
|
|
41
|
+
|
|
42
|
+
const identityResponse = await fetch('https://discord.com/api/users/@me', {
|
|
43
|
+
timeout: 60000,
|
|
44
|
+
response: 'json',
|
|
45
|
+
tries: 1,
|
|
46
|
+
log: true,
|
|
47
|
+
cacheBreaker: false,
|
|
48
|
+
headers: {
|
|
49
|
+
authorization: `${tokenizeResult.token_type} ${tokenizeResult.access_token}`,
|
|
50
|
+
},
|
|
51
|
+
})
|
|
52
|
+
.then(json => json)
|
|
53
|
+
.catch(e => e)
|
|
54
|
+
|
|
55
|
+
assistant.log('identityResponse', identityResponse);
|
|
56
|
+
|
|
57
|
+
if (identityResponse instanceof Error) {
|
|
58
|
+
return reject(identityResponse);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Check if exists
|
|
62
|
+
Manager.libraries.admin.firestore().collection(`users`)
|
|
63
|
+
.where(`oauth2.${self.provider}.identity.id`, '==', identityResponse.id)
|
|
64
|
+
.get()
|
|
65
|
+
.then(async (snap) => {
|
|
66
|
+
if (snap.size === 0) {
|
|
67
|
+
return resolve(identityResponse);
|
|
68
|
+
} else {
|
|
69
|
+
return reject(new Error(`This ${self.name} account is already connected to a ${Manager.config.brand.name} account`));
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
.catch((e) => {
|
|
73
|
+
return reject(e);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// OAuth2.prototype.verifyConnection = function (newUrl, token) {
|
|
80
|
+
// const self = this;
|
|
81
|
+
// const Manager = self.Manager;
|
|
82
|
+
// const assistant = self.assistant;
|
|
83
|
+
//
|
|
84
|
+
// return new Promise(async function(resolve, reject) {
|
|
85
|
+
//
|
|
86
|
+
// fetch(newUrl, {
|
|
87
|
+
// method: 'post',
|
|
88
|
+
// timeout: 60000,
|
|
89
|
+
// response: 'json',
|
|
90
|
+
// tries: 1,
|
|
91
|
+
// log: true,
|
|
92
|
+
// cacheBreaker: false,
|
|
93
|
+
// body: {
|
|
94
|
+
// id_token: token,
|
|
95
|
+
// }
|
|
96
|
+
// })
|
|
97
|
+
// .then(json => {
|
|
98
|
+
// // console.log('---json', json);
|
|
99
|
+
// return resolve('connected');
|
|
100
|
+
// })
|
|
101
|
+
// .catch(e => {
|
|
102
|
+
// try {
|
|
103
|
+
// const parsed = JSON.parse(e.message);
|
|
104
|
+
// return reject(new Error(`${parsed.error}: ${parsed.error_description}`))
|
|
105
|
+
// } catch (e2) {
|
|
106
|
+
// return reject(e);
|
|
107
|
+
// }
|
|
108
|
+
// })
|
|
109
|
+
//
|
|
110
|
+
// });
|
|
111
|
+
// };
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
module.exports = OAuth2;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
const decode = require('jwt-decode')
|
|
2
|
+
const _ = require('lodash')
|
|
3
|
+
const fetch = require('wonderful-fetch')
|
|
4
|
+
|
|
5
|
+
function OAuth2() {
|
|
6
|
+
const self = this;
|
|
7
|
+
self.provider = 'google';
|
|
8
|
+
self.name = 'Google';
|
|
9
|
+
self.urls = {
|
|
10
|
+
authorize: 'https://accounts.google.com/o/oauth2/v2/auth',
|
|
11
|
+
tokenize: 'https://oauth2.googleapis.com/token',
|
|
12
|
+
refresh: 'https://oauth2.googleapis.com/token',
|
|
13
|
+
// status: 'https://oauth2.googleapis.com/tokeninfo?id_token={token}'
|
|
14
|
+
status: 'https://oauth2.googleapis.com/tokeninfo',
|
|
15
|
+
removeAccess: 'https://myaccount.google.com/security',
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
OAuth2.prototype.buildUrl = function (state, url) {
|
|
20
|
+
const self = this;
|
|
21
|
+
const Manager = self.Manager;
|
|
22
|
+
const assistant = self.assistant;
|
|
23
|
+
|
|
24
|
+
return new Promise(async function(resolve, reject) {
|
|
25
|
+
if (state === 'authorize') {
|
|
26
|
+
// do something with url
|
|
27
|
+
// url.searchParams.set('prompt', typeof payload.data.payload.prompt === 'undefined' ? 'consent' : payload.data.payload.prompt)
|
|
28
|
+
// url.searchParams.set('prompt', 'consent')
|
|
29
|
+
return resolve()
|
|
30
|
+
} else {
|
|
31
|
+
return resolve()
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
OAuth2.prototype.verifyIdentity = function (tokenizeResult) {
|
|
37
|
+
const self = this;
|
|
38
|
+
const Manager = self.Manager;
|
|
39
|
+
const assistant = self.assistant;
|
|
40
|
+
|
|
41
|
+
return new Promise(async function(resolve, reject) {
|
|
42
|
+
const decoded = decode(tokenizeResult.id_token);
|
|
43
|
+
|
|
44
|
+
// console.log('---decoded', decoded);
|
|
45
|
+
|
|
46
|
+
// Check if exists
|
|
47
|
+
Manager.libraries.admin.firestore().collection(`users`)
|
|
48
|
+
.where(`oauth2.${self.provider}.identity.email`, '==', decoded.email)
|
|
49
|
+
.get()
|
|
50
|
+
.then(async (snap) => {
|
|
51
|
+
if (snap.size === 0) {
|
|
52
|
+
return resolve(decoded);
|
|
53
|
+
} else {
|
|
54
|
+
return reject(new Error(`This ${self.name} account is already connected to a ${Manager.config.brand.name} account`));
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
.catch((e) => {
|
|
58
|
+
return reject(e);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// OAuth2.prototype.verifyConnection = function (newUrl, token) {
|
|
65
|
+
// const self = this;
|
|
66
|
+
// const Manager = self.Manager;
|
|
67
|
+
// const assistant = self.assistant;
|
|
68
|
+
//
|
|
69
|
+
// return new Promise(async function(resolve, reject) {
|
|
70
|
+
//
|
|
71
|
+
// fetch(newUrl, {
|
|
72
|
+
// method: 'post',
|
|
73
|
+
// timeout: 60000,
|
|
74
|
+
// response: 'json',
|
|
75
|
+
// tries: 1,
|
|
76
|
+
// log: true,
|
|
77
|
+
// cacheBreaker: false,
|
|
78
|
+
// body: {
|
|
79
|
+
// id_token: token,
|
|
80
|
+
// }
|
|
81
|
+
// })
|
|
82
|
+
// .then(json => {
|
|
83
|
+
// // console.log('---json', json);
|
|
84
|
+
// return resolve('connected');
|
|
85
|
+
// })
|
|
86
|
+
// .catch(e => {
|
|
87
|
+
// try {
|
|
88
|
+
// const parsed = JSON.parse(e.message);
|
|
89
|
+
// return reject(new Error(`${parsed.error}: ${parsed.error_description}`))
|
|
90
|
+
// } catch (e2) {
|
|
91
|
+
// return reject(e);
|
|
92
|
+
// }
|
|
93
|
+
// })
|
|
94
|
+
//
|
|
95
|
+
// });
|
|
96
|
+
// };
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
module.exports = OAuth2;
|