backend-manager 3.2.153 → 3.2.154

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.154",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -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,10 @@ 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;
57
66
  settings.app = await self.getAppData(appId).catch((e) => e);
58
67
 
59
68
  // Check for errors
@@ -73,6 +82,12 @@ Module.prototype.main = function (assistant, context) {
73
82
  continue;
74
83
  }
75
84
 
85
+ // Quit if the chance is not met
86
+ const chance = Math.random();
87
+ if (chance > settings.chance) {
88
+ assistant.log(`Quitting because the chance is not met (${chance} <= ${settings.chance})`);
89
+ }
90
+
76
91
  // Harvest articles
77
92
  const result = await self.harvest(settings).catch((e) => e);
78
93
  if (result instanceof Error) {
@@ -320,7 +335,7 @@ const extractBodyContent = (text, contentType, url) => {
320
335
  // Try JSON
321
336
  if (parsed) {
322
337
  // If it's from rss.app, extract the content
323
- if (url.includes('rss.app') && parsed.items) {
338
+ if (parsed.items) {
324
339
  return parsed.items.map((i) => `${i.title}: ${i.content_text}`).join('\n');
325
340
  }
326
341
 
@@ -350,4 +365,9 @@ function tryParse(json) {
350
365
  }
351
366
  };
352
367
 
368
+ // Randomize array
369
+ function randomize(array) {
370
+ return array.sort(() => Math.random() - 0.5);
371
+ }
372
+
353
373
  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
  };
@@ -42,6 +42,7 @@
42
42
  ],
43
43
  links: [],
44
44
  prompt: '',
45
+ chance: 1.0,
45
46
  }
46
47
  ],
47
48
  }