backend-manager 3.2.16 → 3.2.18
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
|
@@ -13,7 +13,7 @@ module.exports = function (payload, config) {
|
|
|
13
13
|
categories: ['download'],
|
|
14
14
|
subject: `Free ${config.brand.name} download link for ${payload.name || 'you'}!`,
|
|
15
15
|
template: 'd-1d730ac8cc544b7cbccc8fa4a4b3f9ce',
|
|
16
|
-
group:
|
|
16
|
+
group: 25927,
|
|
17
17
|
copy: false,
|
|
18
18
|
data: {},
|
|
19
19
|
}
|
|
@@ -13,8 +13,8 @@ Module.prototype.main = function () {
|
|
|
13
13
|
|
|
14
14
|
return new Promise(async function(resolve, reject) {
|
|
15
15
|
const Manager = self.Manager;
|
|
16
|
-
const Api = self.Api;
|
|
17
16
|
const assistant = self.assistant;
|
|
17
|
+
const Api = self.Api;
|
|
18
18
|
const payload = self.payload;
|
|
19
19
|
|
|
20
20
|
Api.resolveUser({adminRequired: true})
|
|
@@ -41,7 +41,7 @@ Module.prototype.main = function () {
|
|
|
41
41
|
const signups = usage.getUsage('signups');
|
|
42
42
|
|
|
43
43
|
// Log the signup
|
|
44
|
-
|
|
44
|
+
assistant.log(`Validating signups ${signups}/${MAX_SIGNUPS} for ip ${ip}`, user);
|
|
45
45
|
|
|
46
46
|
// If over limit, reject and delete the user
|
|
47
47
|
if (signups >= MAX_SIGNUPS) {
|
|
@@ -50,40 +50,7 @@ Module.prototype.main = function () {
|
|
|
50
50
|
await lib.main().catch(e => e);
|
|
51
51
|
})
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
fetch(`https://us-central1-itw-creative-works.cloudfunctions.net/sendEmail`, {
|
|
55
|
-
method: 'post',
|
|
56
|
-
response: 'json',
|
|
57
|
-
log: true,
|
|
58
|
-
body: {
|
|
59
|
-
backendManagerKey: Manager.config.backend_manager.key,
|
|
60
|
-
app: Manager.config.app.id,
|
|
61
|
-
to: {
|
|
62
|
-
email: Manager.config.brand.email,
|
|
63
|
-
},
|
|
64
|
-
categories: [`user/too-many-signups`],
|
|
65
|
-
subject: `Your ${Manager.config.brand.name} account has been deleted`,
|
|
66
|
-
template: 'd-57aad40b0c20466aba08feb9892910cf',
|
|
67
|
-
group: 24077,
|
|
68
|
-
data: {
|
|
69
|
-
title: 'Account deleted',
|
|
70
|
-
message: `
|
|
71
|
-
Your account at ${Manager.config.brand.name} has been deleted because you have signed up for too many accounts.
|
|
72
|
-
<br>
|
|
73
|
-
<br>
|
|
74
|
-
If you believe this is a mistake, please contact us at ${Manager.config.brand.email}.
|
|
75
|
-
`
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
})
|
|
79
|
-
.then(async (json) => {
|
|
80
|
-
self.assistant.log('sendEmail(): Success', json)
|
|
81
|
-
return resolve(json);
|
|
82
|
-
})
|
|
83
|
-
.catch(e => {
|
|
84
|
-
self.assistant.error('sendEmail(): Failed', e)
|
|
85
|
-
return resolve(e);
|
|
86
|
-
});
|
|
53
|
+
await self.sendRateEmail(user);
|
|
87
54
|
|
|
88
55
|
// Reject
|
|
89
56
|
return reject(assistant.errorify(`Too many signups from this IP (${ip}).`, {code: 429, sentry: false, send: false, log: false}));
|
|
@@ -132,13 +99,109 @@ Module.prototype.main = function () {
|
|
|
132
99
|
|
|
133
100
|
};
|
|
134
101
|
|
|
102
|
+
Module.prototype.sendRateEmail = function (user) {
|
|
103
|
+
const self = this;
|
|
104
|
+
|
|
105
|
+
return new Promise(async function(resolve, reject) {
|
|
106
|
+
const Manager = self.Manager;
|
|
107
|
+
const assistant = self.assistant;
|
|
108
|
+
|
|
109
|
+
// Send email
|
|
110
|
+
fetch(`https://us-central1-itw-creative-works.cloudfunctions.net/sendEmail`, {
|
|
111
|
+
method: 'post',
|
|
112
|
+
response: 'json',
|
|
113
|
+
log: true,
|
|
114
|
+
body: {
|
|
115
|
+
backendManagerKey: Manager.config.backend_manager.key,
|
|
116
|
+
app: Manager.config.app.id,
|
|
117
|
+
to: {
|
|
118
|
+
email: user.auth.email,
|
|
119
|
+
},
|
|
120
|
+
categories: [`account/too-many-signups`],
|
|
121
|
+
subject: `Your ${Manager.config.brand.name} account has been deleted`,
|
|
122
|
+
template: 'd-b7f8da3c98ad49a2ad1e187f3a67b546',
|
|
123
|
+
group: 25927,
|
|
124
|
+
data: {
|
|
125
|
+
title: 'Account deleted',
|
|
126
|
+
message: `
|
|
127
|
+
Your account at ${Manager.config.brand.name} has been deleted because you have signed up for too many accounts.
|
|
128
|
+
<br>
|
|
129
|
+
If you believe this is a mistake, please contact us at ${Manager.config.brand.email}.
|
|
130
|
+
<br>
|
|
131
|
+
<br>
|
|
132
|
+
<strong>User Record</strong>:
|
|
133
|
+
<br>
|
|
134
|
+
${JSON.stringify(user, null, 2)}
|
|
135
|
+
`
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
})
|
|
139
|
+
.then(async (json) => {
|
|
140
|
+
assistant.log('sendEmail(): Success', json)
|
|
141
|
+
return resolve(json);
|
|
142
|
+
})
|
|
143
|
+
.catch(e => {
|
|
144
|
+
assistant.error('sendEmail(): Failed', e)
|
|
145
|
+
return resolve(e);
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Module.prototype.sendWelcomeEmail = function (user) {
|
|
151
|
+
// const self = this;
|
|
152
|
+
|
|
153
|
+
// return new Promise(async function(resolve, reject) {
|
|
154
|
+
// const Manager = self.Manager;
|
|
155
|
+
// const assistant = self.assistant;
|
|
156
|
+
|
|
157
|
+
// // Send email
|
|
158
|
+
// fetch(`https://us-central1-itw-creative-works.cloudfunctions.net/sendEmail`, {
|
|
159
|
+
// method: 'post',
|
|
160
|
+
// response: 'json',
|
|
161
|
+
// log: true,
|
|
162
|
+
// body: {
|
|
163
|
+
// backendManagerKey: Manager.config.backend_manager.key,
|
|
164
|
+
// app: Manager.config.app.id,
|
|
165
|
+
// to: {
|
|
166
|
+
// email: user.auth.email,
|
|
167
|
+
// },
|
|
168
|
+
// categories: [`account/too-many-signups`],
|
|
169
|
+
// subject: `Your ${Manager.config.brand.name} account has been deleted`,
|
|
170
|
+
// template: 'd-b7f8da3c98ad49a2ad1e187f3a67b546',
|
|
171
|
+
// group: 25928,
|
|
172
|
+
// data: {
|
|
173
|
+
// title: 'Account deleted',
|
|
174
|
+
// message: `
|
|
175
|
+
// Your account at ${Manager.config.brand.name} has been deleted because you have signed up for too many accounts.
|
|
176
|
+
// <br>
|
|
177
|
+
// If you believe this is a mistake, please contact us at ${Manager.config.brand.email}.
|
|
178
|
+
// <br>
|
|
179
|
+
// <br>
|
|
180
|
+
// <strong>User Record</strong>:
|
|
181
|
+
// <br>
|
|
182
|
+
// ${JSON.stringify(user, null, 2)}
|
|
183
|
+
// `
|
|
184
|
+
// },
|
|
185
|
+
// },
|
|
186
|
+
// })
|
|
187
|
+
// .then(async (json) => {
|
|
188
|
+
// assistant.log('sendEmail(): Success', json)
|
|
189
|
+
// return resolve(json);
|
|
190
|
+
// })
|
|
191
|
+
// .catch(e => {
|
|
192
|
+
// assistant.error('sendEmail(): Failed', e)
|
|
193
|
+
// return resolve(e);
|
|
194
|
+
// });
|
|
195
|
+
// });
|
|
196
|
+
// }
|
|
197
|
+
|
|
135
198
|
Module.prototype.signUp = function (payload) {
|
|
136
199
|
const self = this;
|
|
137
200
|
|
|
138
201
|
return new Promise(async function(resolve, reject) {
|
|
139
202
|
const Manager = self.Manager;
|
|
140
|
-
const Api = self.Api;
|
|
141
203
|
const assistant = self.assistant;
|
|
204
|
+
const Api = self.Api;
|
|
142
205
|
|
|
143
206
|
const result = {
|
|
144
207
|
signedUp: false,
|
|
@@ -204,8 +267,8 @@ Module.prototype.updateReferral = function (payload) {
|
|
|
204
267
|
|
|
205
268
|
return new Promise(function(resolve, reject) {
|
|
206
269
|
const Manager = self.Manager;
|
|
207
|
-
const Api = self.Api;
|
|
208
270
|
const assistant = self.assistant;
|
|
271
|
+
const Api = self.Api;
|
|
209
272
|
|
|
210
273
|
const result = {
|
|
211
274
|
count: 0,
|
|
@@ -87,6 +87,9 @@ OpenAI.prototype.request = function (options) {
|
|
|
87
87
|
options.message.settings,
|
|
88
88
|
).trim();
|
|
89
89
|
const user = options.user?.auth?.uid || assistant.request.geolocation.ip;
|
|
90
|
+
const responseFormat = options.response === 'json' && !options.model.includes('gpt-3.5')
|
|
91
|
+
? { type: 'json_object' }
|
|
92
|
+
: undefined;
|
|
90
93
|
|
|
91
94
|
assistant.log('callOpenAI(): Prompt', prompt);
|
|
92
95
|
assistant.log('callOpenAI(): Message', message);
|
|
@@ -125,7 +128,7 @@ OpenAI.prototype.request = function (options) {
|
|
|
125
128
|
|
|
126
129
|
request.body = {
|
|
127
130
|
model: options.model,
|
|
128
|
-
response_format:
|
|
131
|
+
response_format: responseFormat,
|
|
129
132
|
messages: options.history.messages,
|
|
130
133
|
temperature: options.temperature,
|
|
131
134
|
max_tokens: options.maxTokens,
|
|
@@ -193,6 +196,8 @@ OpenAI.prototype.request = function (options) {
|
|
|
193
196
|
moderation: moderation,
|
|
194
197
|
})
|
|
195
198
|
} catch (e) {
|
|
199
|
+
assistant.warn('callOpenAI(): Error parsing response', r, e);
|
|
200
|
+
|
|
196
201
|
return reject(e);
|
|
197
202
|
}
|
|
198
203
|
})
|