backend-manager 3.2.173 → 3.2.175
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": "3.2.
|
|
3
|
+
"version": "3.2.175",
|
|
4
4
|
"description": "Quick tools for developing Firebase functions",
|
|
5
5
|
"main": "src/manager/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@firebase/rules-unit-testing": "^2.0.7",
|
|
45
|
-
"@google-cloud/storage": "^7.11.
|
|
45
|
+
"@google-cloud/storage": "^7.11.3",
|
|
46
46
|
"@octokit/rest": "^19.0.13",
|
|
47
47
|
"@sendgrid/mail": "^7.7.0",
|
|
48
48
|
"@sentry/node": "^6.19.7",
|
|
@@ -52,13 +52,13 @@
|
|
|
52
52
|
"cors": "^2.8.5",
|
|
53
53
|
"dotenv": "^16.4.5",
|
|
54
54
|
"express": "^4.19.2",
|
|
55
|
-
"firebase-admin": "^12.
|
|
55
|
+
"firebase-admin": "^12.2.0",
|
|
56
56
|
"firebase-functions": "^5.0.1",
|
|
57
57
|
"fs-jetpack": "^5.1.0",
|
|
58
|
-
"glob": "^
|
|
58
|
+
"glob": "^11.0.0",
|
|
59
59
|
"hcaptcha": "^0.1.1",
|
|
60
60
|
"inquirer": "^8.2.5",
|
|
61
|
-
"itwcw-package-analytics": "^1.0.
|
|
61
|
+
"itwcw-package-analytics": "^1.0.6",
|
|
62
62
|
"json5": "^2.2.3",
|
|
63
63
|
"jwt-decode": "^3.1.2",
|
|
64
64
|
"lodash": "^4.17.21",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"moment": "^2.30.1",
|
|
70
70
|
"nanoid": "^3.3.7",
|
|
71
71
|
"node-fetch": "^2.7.0",
|
|
72
|
-
"node-powertools": "^1.4.
|
|
72
|
+
"node-powertools": "^1.4.5",
|
|
73
73
|
"npm-api": "^1.0.1",
|
|
74
74
|
"paypal-server-api": "^2.0.14",
|
|
75
75
|
"pushid": "^1.0.0",
|
|
@@ -85,6 +85,6 @@
|
|
|
85
85
|
"yargs": "^17.7.2"
|
|
86
86
|
},
|
|
87
87
|
"devDependencies": {
|
|
88
|
-
"prepare-package": "^1.1.
|
|
88
|
+
"prepare-package": "^1.1.13"
|
|
89
89
|
}
|
|
90
|
-
}
|
|
90
|
+
}
|
|
@@ -434,8 +434,8 @@ Module.prototype.sendWelcomeEmail = function (user) {
|
|
|
434
434
|
I'm Ian, the founder and CEO of <strong>${Manager.config.brand.name}</strong>, and I'm thrilled to have you with us.
|
|
435
435
|
Your journey begins today, and we are committed to supporting you every step of the way.
|
|
436
436
|
<br><br>
|
|
437
|
+
We are dedicated to ensuring your experience is exceptional.
|
|
437
438
|
Feel free to reply directly to this email with any questions you may have.
|
|
438
|
-
Our team and I are dedicated to ensuring your experience is exceptional.
|
|
439
439
|
<br><br>
|
|
440
440
|
Thank you for choosing <strong>${Manager.config.brand.name}</strong>. Here's to new beginnings!
|
|
441
441
|
`
|
|
@@ -88,10 +88,10 @@ function Analytics(Manager, options) {
|
|
|
88
88
|
: 'None',
|
|
89
89
|
},
|
|
90
90
|
country: {
|
|
91
|
-
value: self.request.country
|
|
91
|
+
value: self.request.country,
|
|
92
92
|
},
|
|
93
93
|
city: {
|
|
94
|
-
value: self.request.city
|
|
94
|
+
value: self.request.city,
|
|
95
95
|
},
|
|
96
96
|
gender: {
|
|
97
97
|
value: authUser?.personal?.gender
|
|
@@ -228,7 +228,7 @@ Analytics.prototype.event = function (payload) {
|
|
|
228
228
|
payload = payload || {};
|
|
229
229
|
|
|
230
230
|
// Fix event name
|
|
231
|
-
payload.name =
|
|
231
|
+
payload.name = `${payload.name}`
|
|
232
232
|
// Replace anything not a letter, number, or underscore with an underscore
|
|
233
233
|
.replace(/[^a-zA-Z0-9_]/g, '_')
|
|
234
234
|
// Remove leading and trailing underscores
|
|
@@ -4,6 +4,17 @@ const _ = require('lodash');
|
|
|
4
4
|
const uuid = require('uuid');
|
|
5
5
|
let JSON5;
|
|
6
6
|
|
|
7
|
+
const LOG_LEVELS = {
|
|
8
|
+
error: 'error',
|
|
9
|
+
warn: 'warn',
|
|
10
|
+
info: 'info',
|
|
11
|
+
debug: 'debug',
|
|
12
|
+
log: 'log',
|
|
13
|
+
notice: 'NOTICE',
|
|
14
|
+
critical: 'CRITICAL',
|
|
15
|
+
emergency: 'EMERGENCY'
|
|
16
|
+
};
|
|
17
|
+
|
|
7
18
|
function BackendAssistant() {
|
|
8
19
|
const self = this;
|
|
9
20
|
|
|
@@ -12,7 +23,24 @@ function BackendAssistant() {
|
|
|
12
23
|
self.initialized = false;
|
|
13
24
|
|
|
14
25
|
// Add log methods
|
|
15
|
-
|
|
26
|
+
Object.keys(LOG_LEVELS)
|
|
27
|
+
.forEach((level) => {
|
|
28
|
+
// Skip log because it is already a method
|
|
29
|
+
// if (level === 'log') {
|
|
30
|
+
// return;
|
|
31
|
+
// }
|
|
32
|
+
|
|
33
|
+
// Add log method
|
|
34
|
+
BackendAssistant.prototype[level] = function() {
|
|
35
|
+
const self = this;
|
|
36
|
+
const args = Array.prototype.slice.call(arguments);
|
|
37
|
+
|
|
38
|
+
// Prepend level to args
|
|
39
|
+
args.unshift(level);
|
|
40
|
+
// self.log.apply(this, args);
|
|
41
|
+
self._log.apply(this, args);
|
|
42
|
+
};
|
|
43
|
+
});
|
|
16
44
|
|
|
17
45
|
return self;
|
|
18
46
|
}
|
|
@@ -33,12 +61,14 @@ function tryParse(input) {
|
|
|
33
61
|
BackendAssistant.prototype.init = function (ref, options) {
|
|
34
62
|
const self = this;
|
|
35
63
|
|
|
64
|
+
// Set options
|
|
36
65
|
options = options || {};
|
|
37
66
|
options.accept = options.accept || 'json';
|
|
38
67
|
options.showOptionsLog = typeof options.showOptionsLog !== 'undefined' ? options.showOptionsLog : false;
|
|
39
68
|
options.optionsLogString = typeof options.optionsLogString !== 'undefined' ? options.optionsLogString : '\n\n\n\n\n';
|
|
40
69
|
options.fileSavePath = options.fileSavePath || process.env.npm_package_name || '';
|
|
41
70
|
|
|
71
|
+
// Set now
|
|
42
72
|
const now = new Date();
|
|
43
73
|
|
|
44
74
|
// Attached libraries - used in .errorify()
|
|
@@ -236,96 +266,41 @@ BackendAssistant.prototype.logProd = function () {
|
|
|
236
266
|
self._log.apply(self, args);
|
|
237
267
|
};
|
|
238
268
|
|
|
239
|
-
BackendAssistant.prototype.
|
|
269
|
+
BackendAssistant.prototype._log = function () {
|
|
240
270
|
const self = this;
|
|
271
|
+
const logs = [...arguments];
|
|
272
|
+
const prefix = self.logPrefix ? ` ${self.logPrefix}:` : ':';
|
|
241
273
|
|
|
242
|
-
|
|
274
|
+
// Prepend log prefix log string
|
|
275
|
+
logs.unshift(`[${self.tag} @ ${new Date().toISOString()}]${prefix}`);
|
|
243
276
|
|
|
244
|
-
|
|
245
|
-
|
|
277
|
+
// Get the log level
|
|
278
|
+
const level = logs[1];
|
|
246
279
|
|
|
247
|
-
|
|
248
|
-
|
|
280
|
+
// Pass along arguments to console.log
|
|
281
|
+
if (LOG_LEVELS[level]) {
|
|
282
|
+
logs.splice(1, 1);
|
|
249
283
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
const args = Array.prototype.slice.call(arguments);
|
|
255
|
-
|
|
256
|
-
// Prepend level to args
|
|
257
|
-
args.unshift(level);
|
|
258
|
-
self.log.apply(this, args);
|
|
259
|
-
};
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
BackendAssistant.prototype._log = function () {
|
|
264
|
-
const self = this;
|
|
265
|
-
|
|
266
|
-
// 1. Convert args to a normal array
|
|
267
|
-
const logs = [...Array.prototype.slice.call(arguments)];
|
|
268
|
-
|
|
269
|
-
// Add log prefix
|
|
270
|
-
const prefix = self.logPrefix
|
|
271
|
-
? ` ${self.logPrefix}:`
|
|
272
|
-
: ':';
|
|
273
|
-
|
|
274
|
-
// 2. Prepend log prefix log string
|
|
275
|
-
logs.unshift(
|
|
276
|
-
`[${self.tag} @ ${new Date().toISOString()}]${prefix}`
|
|
277
|
-
);
|
|
278
|
-
|
|
279
|
-
// 3. Pass along arguments to console.log
|
|
280
|
-
if (logs[1] === 'error') {
|
|
281
|
-
logs.splice(1,1)
|
|
282
|
-
console.error.apply(console, logs);
|
|
283
|
-
} else if (logs[1] === 'warn') {
|
|
284
|
-
logs.splice(1,1)
|
|
285
|
-
console.warn.apply(console, logs);
|
|
286
|
-
} else if (logs[1] === 'info') {
|
|
287
|
-
logs.splice(1,1)
|
|
288
|
-
console.info.apply(console, logs);
|
|
289
|
-
} else if (logs[1] === 'debug') {
|
|
290
|
-
logs.splice(1,1)
|
|
291
|
-
console.debug.apply(console, logs);
|
|
292
|
-
} else if (logs[1] === 'notice') {
|
|
293
|
-
logs.splice(1,1)
|
|
294
|
-
if (self.isDevelopment()) {
|
|
295
|
-
console.log.apply(console, logs);
|
|
296
|
-
} else {
|
|
297
|
-
self.ref.functions.logger.write({
|
|
298
|
-
severity: 'NOTICE',
|
|
299
|
-
message: logs,
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
} else if (logs[1] === 'critical') {
|
|
303
|
-
logs.splice(1,1)
|
|
304
|
-
if (isDevelopment) {
|
|
284
|
+
// Determine how to log
|
|
285
|
+
if (level in console) {
|
|
286
|
+
console[level].apply(console, logs);
|
|
287
|
+
} else if (self.isDevelopment()) {
|
|
305
288
|
console.log.apply(console, logs);
|
|
306
289
|
} else {
|
|
307
290
|
self.ref.functions.logger.write({
|
|
308
|
-
severity:
|
|
291
|
+
severity: LOG_LEVELS[level].toUpperCase(),
|
|
309
292
|
message: logs,
|
|
310
293
|
});
|
|
311
294
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
if (
|
|
315
|
-
|
|
316
|
-
} else {
|
|
317
|
-
self.ref.functions.logger.write({
|
|
318
|
-
severity: 'EMERGENCY',
|
|
319
|
-
message: logs,
|
|
320
|
-
});
|
|
295
|
+
|
|
296
|
+
// Write with wonderful-log
|
|
297
|
+
if (self.Manager?.libraries?.logger?.[level]) {
|
|
298
|
+
self.Manager?.libraries?.logger?.[level](...logs)
|
|
321
299
|
}
|
|
322
|
-
} else if (logs[1] === 'log') {
|
|
323
|
-
logs.splice(1,1)
|
|
324
|
-
console.log.apply(console, logs);
|
|
325
300
|
} else {
|
|
326
301
|
console.log.apply(console, logs);
|
|
327
302
|
}
|
|
328
|
-
}
|
|
303
|
+
};
|
|
329
304
|
|
|
330
305
|
BackendAssistant.prototype.setLogPrefix = function (s) {
|
|
331
306
|
const self = this;
|
package/src/manager/index.js
CHANGED
|
@@ -70,6 +70,7 @@ Manager.prototype.init = function (exporter, options) {
|
|
|
70
70
|
options.assistant = options.assistant || {};
|
|
71
71
|
options.cwd = typeof options.cwd === 'undefined' ? process.cwd() : options.cwd;
|
|
72
72
|
options.projectPackageDirectory = typeof options.projectPackageDirectory === 'undefined' ? undefined : options.projectPackageDirectory;
|
|
73
|
+
options.logSavePath = typeof options.logSavePath === 'undefined' ? false : options.logSavePath;
|
|
73
74
|
// options.assistant.optionsLogString = options.assistant.optionsLogString || undefined;
|
|
74
75
|
|
|
75
76
|
// Load libraries
|
|
@@ -87,6 +88,7 @@ Manager.prototype.init = function (exporter, options) {
|
|
|
87
88
|
localDatabase: null,
|
|
88
89
|
User: null,
|
|
89
90
|
Analytics: null,
|
|
91
|
+
logger: null,
|
|
90
92
|
};
|
|
91
93
|
|
|
92
94
|
// Set properties
|
|
@@ -118,8 +120,27 @@ Manager.prototype.init = function (exporter, options) {
|
|
|
118
120
|
// Get app ID
|
|
119
121
|
const appId = self.config?.app?.id;
|
|
120
122
|
|
|
123
|
+
// Set log
|
|
124
|
+
if (options.logSavePath) {
|
|
125
|
+
self.libraries.logger = new (require('wonderful-log'))({
|
|
126
|
+
console: {
|
|
127
|
+
enabled: false,
|
|
128
|
+
},
|
|
129
|
+
file: {
|
|
130
|
+
enabled: true,
|
|
131
|
+
path: options.logSavePath,
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
121
136
|
// Init assistant
|
|
122
|
-
self.assistant = self.Assistant().init(
|
|
137
|
+
self.assistant = self.Assistant().init({
|
|
138
|
+
req: null,
|
|
139
|
+
res: null,
|
|
140
|
+
admin: self.libraries.admin,
|
|
141
|
+
functions: self.libraries.functions,
|
|
142
|
+
Manager: self,
|
|
143
|
+
}, options.assistant);
|
|
123
144
|
|
|
124
145
|
// Set more properties (need to wait for assistant to determine if DEV)
|
|
125
146
|
self.project.functionsUrl = self.assistant.isDevelopment()
|
|
@@ -4,6 +4,8 @@ const powertools = require('node-powertools');
|
|
|
4
4
|
const _ = require('lodash');
|
|
5
5
|
const JSON5 = require('json5');
|
|
6
6
|
|
|
7
|
+
// Constants
|
|
8
|
+
const DEFAULT_MODEL = 'gpt-4o';
|
|
7
9
|
const TOKEN_COST_TABLE = {
|
|
8
10
|
// May 13th, 2024
|
|
9
11
|
'gpt-4o': {
|
|
@@ -142,7 +144,7 @@ OpenAI.prototype.request = function (options) {
|
|
|
142
144
|
return new Promise(async function(resolve, reject) {
|
|
143
145
|
options = _.merge({}, options);
|
|
144
146
|
|
|
145
|
-
options.model = typeof options.model === 'undefined' ?
|
|
147
|
+
options.model = typeof options.model === 'undefined' ? DEFAULT_MODEL : options.model;
|
|
146
148
|
options.timeout = typeof options.timeout === 'undefined' ? 120000 : options.timeout;
|
|
147
149
|
options.moderate = typeof options.moderate === 'undefined' ? true : options.moderate;
|
|
148
150
|
options.log = typeof options.log === 'undefined' ? false : options.log;
|