From c8c0d7868c801694349e69cf4dc7b6b5b046e139 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Tue, 7 Jan 2020 17:13:21 +0100 Subject: [PATCH 1/5] tools: Init a simple publish script --- scripts/publish.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 scripts/publish.sh diff --git a/scripts/publish.sh b/scripts/publish.sh new file mode 100755 index 0000000000..384f2421a6 --- /dev/null +++ b/scripts/publish.sh @@ -0,0 +1,24 @@ +# Force start from root folder +cd "$(dirname "$0")/.." + +set -e + +version="" + +echo "Please enter the version you want to publish" +read version + +# publish packages +./node_modules/.bin/lerna publish --no-push --dist-tag beta --exact "$version" + +# push master branch +git push origin master + +# push tag +git push origin v"$version" + +# set latest dist-tag on npm +lerna exec --stream --no-bail --no-private -- npm dist-tag add '${LERNA_PACKAGE_NAME}'@"$version" latest + +# run changelog cli +npx @sclt/program-changelog From e3e28db031951f35d38cf595e0643dac83a18f6b Mon Sep 17 00:00:00 2001 From: Saint Asky Date: Wed, 8 Jan 2020 21:07:02 +0800 Subject: [PATCH 2/5] Update auth-request.md Change axios.get to axios.post --- docs/3.0.0-beta.x/guides/auth-request.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/3.0.0-beta.x/guides/auth-request.md b/docs/3.0.0-beta.x/guides/auth-request.md index dad2f7da93..73d880b2b7 100644 --- a/docs/3.0.0-beta.x/guides/auth-request.md +++ b/docs/3.0.0-beta.x/guides/auth-request.md @@ -152,7 +152,7 @@ To do so, you will have to request the `/articles` route in **POST**. import axios from 'axios'; const {data} = await axios - .get('http://localhost:1337/articles', { + .post('http://localhost:1337/articles', { data: { title: 'my article' content: 'my super article content' From d5d80ba407ed6ddfca08143549898f4eeb3f26ed Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Fri, 10 Jan 2020 12:04:58 +0100 Subject: [PATCH 3/5] Fix missing await in file remove --- packages/strapi-plugin-upload/services/Upload.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/strapi-plugin-upload/services/Upload.js b/packages/strapi-plugin-upload/services/Upload.js index 809484c32c..ab890aafbe 100644 --- a/packages/strapi-plugin-upload/services/Upload.js +++ b/packages/strapi-plugin-upload/services/Upload.js @@ -128,7 +128,7 @@ module.exports = { await actions.delete(file); } - const media = strapi.query('file', 'upload').findOne({ + const media = await strapi.query('file', 'upload').findOne({ id: file.id, }); From 51b3dade8f8fdb94dd997b8d19abe680d431c314 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Fri, 10 Jan 2020 12:25:41 +0100 Subject: [PATCH 4/5] Default opts in Strapi() --- packages/strapi/lib/Strapi.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/strapi/lib/Strapi.js b/packages/strapi/lib/Strapi.js index 92c0f0ec53..34b9084f9a 100644 --- a/packages/strapi/lib/Strapi.js +++ b/packages/strapi/lib/Strapi.js @@ -61,7 +61,7 @@ const CONFIG_PATHS = { */ class Strapi extends EventEmitter { - constructor(opts) { + constructor(opts = {}) { super(); this.setMaxListeners(100); From d4a630a2167853f8b8147a4b204cd56fb10d703b Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Fri, 10 Jan 2020 12:42:57 +0100 Subject: [PATCH 5/5] Add defaultHeaders option to webhooks --- packages/strapi/lib/Strapi.js | 36 +++++++++++++++---- .../strapi/lib/services/webhook-runner.js | 18 ++++++++-- 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/packages/strapi/lib/Strapi.js b/packages/strapi/lib/Strapi.js index 34b9084f9a..cff440af39 100644 --- a/packages/strapi/lib/Strapi.js +++ b/packages/strapi/lib/Strapi.js @@ -86,24 +86,19 @@ class Strapi extends EventEmitter { this.dir = opts.dir || process.cwd(); this.admin = {}; this.plugins = {}; - this.config = {}; + this.config = this.initConfig(opts); // internal services. this.fs = createStrapiFs(this); this.eventHub = createEventHub(); - this.webhookRunner = createWebhookRunner({ - eventHub: this.eventHub, - logger: this.log, - }); - this.initConfig(opts); this.requireProjectBootstrap(); } initConfig({ autoReload = false, serveAdminPanel = true } = {}) { const pkgJSON = require(path.resolve(this.dir, 'package.json')); - this.config = { + const config = { serveAdminPanel, launchedAt: Date.now(), appPath: this.dir, @@ -123,6 +118,26 @@ class Strapi extends EventEmitter { installedMiddlewares: getPrefixedDeps('strapi-middleware', pkgJSON), installedHooks: getPrefixedDeps('strapi-hook', pkgJSON), }; + + Object.defineProperty(config, 'get', { + value(path, defaultValue = null) { + return _.get(config, path, defaultValue); + }, + enumerable: false, + configurable: false, + writable: false, + }); + + Object.defineProperty(config, 'set', { + value(path, value) { + return _.set(config, path, value); + }, + enumerable: false, + configurable: false, + writable: false, + }); + + return config; } requireProjectBootstrap() { @@ -368,6 +383,13 @@ class Strapi extends EventEmitter { // Usage. await utils.usage(this.config); + // init webhook runner + this.webhookRunner = createWebhookRunner({ + eventHub: this.eventHub, + logger: this.log, + configuration: this.config.get('currentEnvironment.server.webhooks', {}), + }); + // Init core store this.models['core_store'] = coreStoreModel; this.models['strapi_webhooks'] = webhookModel; diff --git a/packages/strapi/lib/services/webhook-runner.js b/packages/strapi/lib/services/webhook-runner.js index 08382fd2d1..f72f7dff58 100644 --- a/packages/strapi/lib/services/webhook-runner.js +++ b/packages/strapi/lib/services/webhook-runner.js @@ -4,19 +4,32 @@ 'use strict'; const debug = require('debug')('strapi'); +const _ = require('lodash'); const fetch = require('node-fetch'); const WorkerQueue = require('./worker-queue'); +const defaultConfiguration = { + defaultHeaders: {}, +}; + class WebhookRunner { - constructor({ eventHub, logger, queue }) { + constructor({ eventHub, logger, configuration = {} }) { debug('Initialized webhook runer'); this.eventHub = eventHub; this.logger = logger; this.webhooksMap = new Map(); this.listeners = new Map(); - this.queue = queue || new WorkerQueue({ logger, concurency: 5 }); + if (typeof configuration !== 'object') { + throw new Error( + 'Invalid configuration provided to the webhookRunner.\nCheck your server.json -> webhooks configuration' + ); + } + + this.config = _.merge(defaultConfiguration, configuration); + + this.queue = new WorkerQueue({ logger, concurency: 5 }); this.queue.subscribe(this.executeListener.bind(this)); } @@ -72,6 +85,7 @@ class WebhookRunner { ...info, }), headers: { + ...this.config.defaultHeaders, ...headers, 'X-Strapi-Event': event, 'Content-Type': 'application/json',