backend-manager 3.2.153 → 3.2.155

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.153",
3
+ "version": "3.2.155",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -61,7 +61,7 @@
61
61
  "moment": "^2.30.1",
62
62
  "nanoid": "^3.3.7",
63
63
  "node-fetch": "^2.7.0",
64
- "node-powertools": "^1.4.1",
64
+ "node-powertools": "^1.4.2",
65
65
  "npm-api": "^1.0.1",
66
66
  "paypal-server-api": "^2.0.6",
67
67
  "pushid": "^1.0.0",
@@ -83,8 +83,8 @@ Module.prototype.main = function () {
83
83
  // Fix other values
84
84
  payload.data.payload.author = payload.data.payload.author || 'alex';
85
85
  payload.data.payload.affiliate = payload.data.payload.affiliate || '';
86
- payload.data.payload.tags = payload.data.payload.tags || '';
87
- payload.data.payload.categories = payload.data.payload.categories || '';
86
+ payload.data.payload.tags = payload.data.payload.tags || [];
87
+ payload.data.payload.categories = payload.data.payload.categories || [];
88
88
 
89
89
  // Fix even more values
90
90
  payload.data.payload.layout = payload.data.payload.layout || 'app/blog/post';
@@ -12,4 +12,5 @@ post:
12
12
  categories: {categories}
13
13
  affiliate-search-term: {affiliate}
14
14
  ---
15
+
15
16
  {body}
@@ -4,12 +4,20 @@ const powertools = require('node-powertools');
4
4
  const moment = require('moment');
5
5
  const JSON5 = require('json5');
6
6
 
7
+ // const PROMPT = `
8
+ // Company: {app.name}: {app.brand.description}
9
+ // Date: {date}
10
+ // Instructions: {prompt}
11
+
12
+ // Use the following information to find a topic related to our company:
13
+ // {suggestion}
14
+ // `
7
15
  const PROMPT = `
8
16
  Company: {app.name}: {app.brand.description}
9
17
  Date: {date}
10
18
  Instructions: {prompt}
11
19
 
12
- Use the following information to find a topic related to our company:
20
+ Use the following information to find a topic for our company blog (it can be about our company OR any topic that would be relevant to our website and business BUT not about a competitor):
13
21
  {suggestion}
14
22
  `
15
23
 
@@ -51,9 +59,11 @@ Module.prototype.main = function (assistant, context) {
51
59
 
52
60
  // Fix settings
53
61
  settings.articles = settings.articles || 0;
54
- settings.sources = settings.sources || [];
55
- settings.links = settings.links || [];
62
+ settings.sources = randomize(settings.sources || []);
63
+ settings.links = randomize(settings.links || []);
56
64
  settings.prompt = settings.prompt || '';
65
+ settings.chance = settings.chance || 1.0;
66
+ settings.author = settings.author || 'alex';
57
67
  settings.app = await self.getAppData(appId).catch((e) => e);
58
68
 
59
69
  // Check for errors
@@ -73,6 +83,12 @@ Module.prototype.main = function (assistant, context) {
73
83
  continue;
74
84
  }
75
85
 
86
+ // Quit if the chance is not met
87
+ const chance = Math.random();
88
+ if (chance > settings.chance) {
89
+ assistant.log(`Quitting because the chance is not met (${chance} <= ${settings.chance})`);
90
+ }
91
+
76
92
  // Harvest articles
77
93
  const result = await self.harvest(settings).catch((e) => e);
78
94
  if (result instanceof Error) {
@@ -302,7 +318,9 @@ Module.prototype.uploadPost = function (settings, article) {
302
318
  headerImageURL: article.headerImageUrl,
303
319
  body: article.body,
304
320
  id: self.postId++,
305
- author: 'alex',
321
+ author: settings.author,
322
+ categories: article.categories,
323
+ tags: article.keywords,
306
324
  path: 'ghostii',
307
325
  githubUser: settings.app.github.user,
308
326
  githubRepo: settings.app.github.repo,
@@ -320,7 +338,7 @@ const extractBodyContent = (text, contentType, url) => {
320
338
  // Try JSON
321
339
  if (parsed) {
322
340
  // If it's from rss.app, extract the content
323
- if (url.includes('rss.app') && parsed.items) {
341
+ if (parsed.items) {
324
342
  return parsed.items.map((i) => `${i.title}: ${i.content_text}`).join('\n');
325
343
  }
326
344
 
@@ -350,4 +368,9 @@ function tryParse(json) {
350
368
  }
351
369
  };
352
370
 
371
+ // Randomize array
372
+ function randomize(array) {
373
+ return array.sort(() => Math.random() - 0.5);
374
+ }
375
+
353
376
  module.exports = Module;
@@ -46,6 +46,13 @@ Settings.prototype.resolve = function (assistant, schema, settings, options) {
46
46
  // Resolve settings
47
47
  self.settings = powertools.defaults(settings, schema);
48
48
 
49
+ // If schema is not an object, throw an error
50
+ if (!schema || typeof schema !== 'object') {
51
+ throw assistant.errorify(`Invalid schema provided`, {code: 400});
52
+ }
53
+ // console.log('---schema', schema);
54
+ // console.log('---self.settings', self.settings);
55
+
49
56
  // Iterate each key and check for some things
50
57
  processSchema(schema, (path, schemaNode) => {
51
58
  const originalValue = _.get(settings, path);
@@ -638,7 +638,7 @@ Manager.prototype.setupFunctions = function (exporter, options) {
638
638
  // Setup functions
639
639
  exporter.bm_api =
640
640
  self.libraries.functions
641
- .runWith({memory: '256MB', timeoutSeconds: 190})
641
+ .runWith({memory: '256MB', timeoutSeconds: 60 * 5})
642
642
  // TODO: Replace this with new API
643
643
  .https.onRequest(async (req, res) => self._process((new (require(`${core}/actions/api.js`))()).init(self, { req: req, res: res, })));
644
644
 
@@ -849,7 +849,7 @@ Manager.prototype.setupFunctions = function (exporter, options) {
849
849
  // Setup cron jobs
850
850
  exporter.bm_cronDaily =
851
851
  self.libraries.functions
852
- .runWith({ memory: '256MB', timeoutSeconds: 190 })
852
+ .runWith({ memory: '256MB', timeoutSeconds: 60 * 5})
853
853
  .pubsub.schedule('every 24 hours')
854
854
  .onRun(async (context) => self._process((new (require(`${core}/cron/daily.js`))()).init(self, { context: context, })));
855
855
  };
@@ -40,8 +40,12 @@
40
40
  '$app',
41
41
  // Add more sources here
42
42
  ],
43
- links: [],
43
+ links: [
44
+ // ...
45
+ ],
44
46
  prompt: '',
47
+ chance: 1.0,
48
+ author: 'alex',
45
49
  }
46
50
  ],
47
51
  }