@strapi/strapi 4.10.0-beta.1 → 4.10.0

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.
Files changed (69) hide show
  1. package/bin/strapi.js +2 -468
  2. package/ee/LICENSE.txt +21 -0
  3. package/ee/index.js +3 -1
  4. package/ee/license.js +8 -7
  5. package/lib/Strapi.js +3 -0
  6. package/lib/commands/{admin-create.js → actions/admin/create-user/action.js} +2 -2
  7. package/lib/commands/actions/admin/create-user/command.js +19 -0
  8. package/lib/commands/{admin-reset.js → actions/admin/reset-user-password/action.js} +2 -2
  9. package/lib/commands/actions/admin/reset-user-password/command.js +17 -0
  10. package/lib/commands/{configurationDump.js → actions/configuration/dump/action.js} +1 -1
  11. package/lib/commands/actions/configuration/dump/command.js +17 -0
  12. package/lib/commands/{configurationRestore.js → actions/configuration/restore/action.js} +1 -1
  13. package/lib/commands/actions/configuration/restore/command.js +17 -0
  14. package/lib/commands/{console.js → actions/console/action.js} +2 -2
  15. package/lib/commands/actions/console/command.js +14 -0
  16. package/lib/commands/{content-types/list.js → actions/content-types/list/action.js} +2 -2
  17. package/lib/commands/actions/content-types/list/command.js +14 -0
  18. package/lib/commands/{controllers/list.js → actions/controllers/list/action.js} +2 -2
  19. package/lib/commands/actions/controllers/list/command.js +14 -0
  20. package/lib/commands/{develop.js → actions/develop/action.js} +3 -3
  21. package/lib/commands/actions/develop/command.js +19 -0
  22. package/lib/commands/{transfer/export.js → actions/export/action.js} +3 -2
  23. package/lib/commands/actions/export/command.js +45 -0
  24. package/lib/commands/actions/generate/command.js +18 -0
  25. package/lib/commands/{hooks/list.js → actions/hooks/list/action.js} +2 -2
  26. package/lib/commands/actions/hooks/list/command.js +14 -0
  27. package/lib/commands/{transfer/import.js → actions/import/action.js} +2 -2
  28. package/lib/commands/actions/import/command.js +97 -0
  29. package/lib/commands/{install.js → actions/install/action.js} +1 -1
  30. package/lib/commands/actions/install/command.js +14 -0
  31. package/lib/commands/{middlewares/list.js → actions/middlewares/list/action.js} +2 -2
  32. package/lib/commands/actions/middlewares/list/command.js +14 -0
  33. package/lib/commands/{new.js → actions/new/action.js} +1 -1
  34. package/lib/commands/actions/new/command.js +35 -0
  35. package/lib/commands/{policies/list.js → actions/policies/list/action.js} +2 -2
  36. package/lib/commands/actions/policies/list/command.js +14 -0
  37. package/lib/commands/{report.js → actions/report/action.js} +1 -1
  38. package/lib/commands/actions/report/command.js +17 -0
  39. package/lib/commands/{routes/list.js → actions/routes/list/action.js} +2 -2
  40. package/lib/commands/actions/routes/list/command.js +14 -0
  41. package/lib/commands/{services/list.js → actions/services/list/action.js} +2 -2
  42. package/lib/commands/actions/services/list/command.js +14 -0
  43. package/lib/commands/{start.js → actions/start/action.js} +1 -1
  44. package/lib/commands/actions/start/command.js +14 -0
  45. package/lib/commands/{opt-out-telemetry.js → actions/telemetry/disable/action.js} +1 -1
  46. package/lib/commands/actions/telemetry/disable/command.js +14 -0
  47. package/lib/commands/{opt-in-telemetry.js → actions/telemetry/enable/action.js} +1 -1
  48. package/lib/commands/actions/telemetry/enable/command.js +14 -0
  49. package/lib/commands/actions/templates/generate/command.js +14 -0
  50. package/lib/commands/{transfer/transfer.js → actions/transfer/action.js} +2 -2
  51. package/lib/commands/actions/transfer/command.js +115 -0
  52. package/lib/commands/{ts/generate-types.js → actions/ts/generate-types/action.js} +2 -2
  53. package/lib/commands/actions/ts/generate-types/command.js +21 -0
  54. package/lib/commands/{uninstall.js → actions/uninstall/action.js} +1 -1
  55. package/lib/commands/actions/uninstall/command.js +15 -0
  56. package/lib/commands/actions/version/command.js +19 -0
  57. package/lib/commands/{watchAdmin.js → actions/watch-admin/action.js} +4 -4
  58. package/lib/commands/actions/watch-admin/command.js +15 -0
  59. package/lib/commands/index.js +66 -0
  60. package/lib/commands/{transfer/utils.js → utils/data-transfer.js} +2 -2
  61. package/lib/commands/utils/helpers.js +54 -3
  62. package/lib/core/registries/custom-fields.js +19 -2
  63. package/lib/services/metrics/sender.js +1 -2
  64. package/lib/services/webhook-runner.js +4 -4
  65. package/lib/types/core/commands/index.d.ts +6 -0
  66. package/lib/utils/fetch.js +23 -0
  67. package/package.json +17 -16
  68. package/lib/commands/build.js +0 -18
  69. /package/lib/commands/{generate-template.js → actions/templates/generate/action.js} +0 -0
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ const { getLocalScript } = require('../../../utils/helpers');
4
+
5
+ /**
6
+ * `$ strapi telemetry:enable`
7
+ * @param {import('../../../../types/core/commands').AddCommandOptions} options
8
+ */
9
+ module.exports = ({ command }) => {
10
+ command
11
+ .command('telemetry:enable')
12
+ .description('Enable anonymous telemetry and metadata sending to Strapi analytics')
13
+ .action(getLocalScript('telemetry/enable'));
14
+ };
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ const { getLocalScript } = require('../../../utils/helpers');
4
+
5
+ /**
6
+ *`$ strapi templates:generate <directory>`
7
+ * @param {import('../../../../types/core/commands').AddCommandOptions} options
8
+ */
9
+ module.exports = ({ command }) => {
10
+ command
11
+ .command('templates:generate <directory>')
12
+ .description('Generate template from Strapi project')
13
+ .action(getLocalScript('templates/generate'));
14
+ };
@@ -22,8 +22,8 @@ const {
22
22
  exitMessageText,
23
23
  abortTransfer,
24
24
  getTransferTelemetryPayload,
25
- } = require('./utils');
26
- const { exitWith } = require('../utils/helpers');
25
+ } = require('../../utils/data-transfer');
26
+ const { exitWith } = require('../../utils/helpers');
27
27
 
28
28
  /**
29
29
  * @typedef TransferCommandOptions Options given to the CLI transfer command
@@ -0,0 +1,115 @@
1
+ 'use strict';
2
+
3
+ const inquirer = require('inquirer');
4
+ const { Option } = require('commander');
5
+ const { confirmMessage, forceOption, parseURL } = require('../../utils/commander');
6
+ const {
7
+ getLocalScript,
8
+ exitWith,
9
+ assertUrlHasProtocol,
10
+ ifOptions,
11
+ } = require('../../utils/helpers');
12
+ const {
13
+ excludeOption,
14
+ onlyOption,
15
+ throttleOption,
16
+ validateExcludeOnly,
17
+ } = require('../../utils/data-transfer');
18
+
19
+ /**
20
+ * `$ strapi transfer`
21
+ * @param {import('../../../types/core/commands').AddCommandOptions} options
22
+ */
23
+ module.exports = ({ command }) => {
24
+ command
25
+ .command('transfer')
26
+ .description('Transfer data from one source to another')
27
+ .allowExcessArguments(false)
28
+ .addOption(
29
+ new Option(
30
+ '--from <sourceURL>',
31
+ `URL of the remote Strapi instance to get data from`
32
+ ).argParser(parseURL)
33
+ )
34
+ .addOption(new Option('--from-token <token>', `Transfer token for the remote Strapi source`))
35
+ .addOption(
36
+ new Option(
37
+ '--to <destinationURL>',
38
+ `URL of the remote Strapi instance to send data to`
39
+ ).argParser(parseURL)
40
+ )
41
+ .addOption(new Option('--to-token <token>', `Transfer token for the remote Strapi destination`))
42
+ .addOption(forceOption)
43
+ .addOption(excludeOption)
44
+ .addOption(onlyOption)
45
+ .addOption(throttleOption)
46
+ .hook('preAction', validateExcludeOnly)
47
+ .hook(
48
+ 'preAction',
49
+ ifOptions(
50
+ (opts) => !(opts.from || opts.to) || (opts.from && opts.to),
51
+ () =>
52
+ exitWith(
53
+ 1,
54
+ 'Exactly one remote source (from) or destination (to) option must be provided'
55
+ )
56
+ )
57
+ )
58
+ // If --from is used, validate the URL and token
59
+ .hook(
60
+ 'preAction',
61
+ ifOptions(
62
+ (opts) => opts.from,
63
+ async (thisCommand) => {
64
+ assertUrlHasProtocol(thisCommand.opts().from, ['https:', 'http:']);
65
+ if (!thisCommand.opts().fromToken) {
66
+ const answers = await inquirer.prompt([
67
+ {
68
+ type: 'password',
69
+ message: 'Please enter your transfer token for the remote Strapi source',
70
+ name: 'fromToken',
71
+ },
72
+ ]);
73
+ if (!answers.fromToken?.length) {
74
+ exitWith(1, 'No token provided for remote source, aborting transfer.');
75
+ }
76
+ thisCommand.opts().fromToken = answers.fromToken;
77
+ }
78
+
79
+ await confirmMessage(
80
+ 'The transfer will delete all the local Strapi assets and its database. Are you sure you want to proceed?',
81
+ { failMessage: 'Transfer process aborted' }
82
+ )(thisCommand);
83
+ }
84
+ )
85
+ )
86
+ // If --to is used, validate the URL, token, and confirm restore
87
+ .hook(
88
+ 'preAction',
89
+ ifOptions(
90
+ (opts) => opts.to,
91
+ async (thisCommand) => {
92
+ assertUrlHasProtocol(thisCommand.opts().to, ['https:', 'http:']);
93
+ if (!thisCommand.opts().toToken) {
94
+ const answers = await inquirer.prompt([
95
+ {
96
+ type: 'password',
97
+ message: 'Please enter your transfer token for the remote Strapi destination',
98
+ name: 'toToken',
99
+ },
100
+ ]);
101
+ if (!answers.toToken?.length) {
102
+ exitWith(1, 'No token provided for remote destination, aborting transfer.');
103
+ }
104
+ thisCommand.opts().toToken = answers.toToken;
105
+ }
106
+
107
+ await confirmMessage(
108
+ 'The transfer will delete all the remote Strapi assets and its database. Are you sure you want to proceed?',
109
+ { failMessage: 'Transfer process aborted' }
110
+ )(thisCommand);
111
+ }
112
+ )
113
+ )
114
+ .action(getLocalScript('transfer'));
115
+ };
@@ -2,9 +2,9 @@
2
2
 
3
3
  const tsUtils = require('@strapi/typescript-utils');
4
4
 
5
- const strapi = require('../../index');
5
+ const strapi = require('../../../../index');
6
6
 
7
- module.exports = async function ({ outDir, file, verbose, silent }) {
7
+ module.exports = async ({ outDir, file, verbose, silent }) => {
8
8
  if (verbose && silent) {
9
9
  console.error('You cannot enable verbose and silent flags at the same time, exiting...');
10
10
  process.exit(1);
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ const { getLocalScript } = require('../../../utils/helpers');
4
+
5
+ /**
6
+ * `$ strapi ts:generate-types`
7
+ * @param {import('../../../../types/core/commands').AddCommandOptions} options
8
+ */
9
+ module.exports = ({ command }) => {
10
+ command
11
+ .command('ts:generate-types')
12
+ .description(`Generate TypeScript typings for your schemas`)
13
+ .option(
14
+ '-o, --out-dir <outDir>',
15
+ 'Specify a relative directory in which the schemas definitions will be generated'
16
+ )
17
+ .option('-f, --file <file>', 'Specify a filename to store the schemas definitions')
18
+ .option('--verbose', `Display more information about the types generation`, false)
19
+ .option('-s, --silent', `Run the generation silently, without any output`, false)
20
+ .action(getLocalScript('ts/generate-types'));
21
+ };
@@ -5,7 +5,7 @@ const { existsSync, removeSync } = require('fs-extra');
5
5
  const ora = require('ora');
6
6
  const execa = require('execa');
7
7
  const inquirer = require('inquirer');
8
- const findPackagePath = require('../load/package-path');
8
+ const findPackagePath = require('../../../load/package-path');
9
9
 
10
10
  module.exports = async (plugins, { deleteFiles }) => {
11
11
  const answers = await inquirer.prompt([
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ const { getLocalScript } = require('../../utils/helpers');
4
+
5
+ /**
6
+ * `$ strapi uninstall`
7
+ * @param {import('../../../types/core/commands').AddCommandOptions} options
8
+ */
9
+ module.exports = ({ command }) => {
10
+ command
11
+ .command('uninstall [plugins...]')
12
+ .description('Uninstall a Strapi plugin')
13
+ .option('-d, --delete-files', 'Delete files', false)
14
+ .action(getLocalScript('uninstall'));
15
+ };
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * `$ strapi version`
5
+ * @param {import('../../../types/core/commands').AddCommandOptions} options
6
+ */
7
+ module.exports = ({ command }) => {
8
+ // load the Strapi package.json to get version and other information
9
+ const packageJSON = require('../../../../package.json');
10
+
11
+ command.version(packageJSON.version, '-v, --version', 'Output the version number');
12
+ command
13
+ .command('version')
14
+ .description('Output the version of Strapi')
15
+ .action(() => {
16
+ process.stdout.write(`${packageJSON.version}\n`);
17
+ process.exit(0);
18
+ });
19
+ };
@@ -3,11 +3,11 @@
3
3
  const strapiAdmin = require('@strapi/admin');
4
4
  const { getConfigUrls, getAbsoluteServerUrl } = require('@strapi/utils');
5
5
 
6
- const getEnabledPlugins = require('../core/loaders/plugins/get-enabled-plugins');
7
- const addSlash = require('../utils/addSlash');
8
- const strapi = require('../index');
6
+ const getEnabledPlugins = require('../../../core/loaders/plugins/get-enabled-plugins');
7
+ const addSlash = require('../../../utils/addSlash');
8
+ const strapi = require('../../../index');
9
9
 
10
- module.exports = async function ({ browser }) {
10
+ module.exports = async ({ browser }) => {
11
11
  const appContext = await strapi.compile();
12
12
 
13
13
  const strapiInstance = strapi({
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ const { getLocalScript } = require('../../utils/helpers');
4
+
5
+ /**
6
+ * `$ strapi watch-admin`
7
+ * @param {import('../../../types/core/commands').AddCommandOptions} options
8
+ */
9
+ module.exports = ({ command }) => {
10
+ command
11
+ .command('watch-admin')
12
+ .option('--browser <name>', 'Open the browser', true)
13
+ .description('Start the admin development server')
14
+ .action(getLocalScript('watch-admin'));
15
+ };
@@ -0,0 +1,66 @@
1
+ 'use strict';
2
+
3
+ const { Command } = require('commander');
4
+
5
+ const strapiCommands = {
6
+ 'admin/create-user': require('./actions/admin/create-user/command'),
7
+ 'admin/reset-user-password': require('./actions/admin/reset-user-password/command'),
8
+ build: require('./actions/build/command'),
9
+ 'configuration/dump': require('./actions/configuration/dump/command'),
10
+ 'configuration/restore': require('./actions/configuration/restore/command'),
11
+ console: require('./actions/console/command'),
12
+ 'content-types/list': require('./actions/content-types/list/command'),
13
+ 'controllers/list': require('./actions/controllers/list/command'),
14
+ develop: require('./actions/develop/command'),
15
+ export: require('./actions/export/command'),
16
+ generate: require('./actions/generate/command'),
17
+ 'hooks/list': require('./actions/hooks/list/command'),
18
+ import: require('./actions/import/command'),
19
+ install: require('./actions/install/command'),
20
+ 'middlewares/list': require('./actions/middlewares/list/command'),
21
+ new: require('./actions/new/command'),
22
+ 'policies/list': require('./actions/policies/list/command'),
23
+ report: require('./actions/report/command'),
24
+ 'routes/list': require('./actions/routes/list/command'),
25
+ 'services/list': require('./actions/services/list/command'),
26
+ start: require('./actions/start/command'),
27
+ 'telemetry/disable': require('./actions/telemetry/disable/command'),
28
+ 'telemetry/enable': require('./actions/telemetry/enable/command'),
29
+ 'templates/generate': require('./actions/templates/generate/command'),
30
+ transfer: require('./actions/transfer/command'),
31
+ 'ts/generate-types': require('./actions/ts/generate-types/command'),
32
+ uninstall: require('./actions/uninstall/command'),
33
+ version: require('./actions/version/command'),
34
+ 'watch-admin': require('./actions/watch-admin/command'),
35
+ };
36
+
37
+ const buildStrapiCommand = (argv, command = new Command()) => {
38
+ // Initial program setup
39
+ command.storeOptionsAsProperties(false).allowUnknownOption(true);
40
+
41
+ // Help command
42
+ command.helpOption('-h, --help', 'Display help for command');
43
+ command.addHelpCommand('help [command]', 'Display help for command');
44
+
45
+ // Load all commands
46
+ Object.keys(strapiCommands).forEach((name) => {
47
+ try {
48
+ // Add this command to the Commander command object
49
+ strapiCommands[name]({ command, argv });
50
+ } catch (e) {
51
+ console.error(`Failed to load command ${name}`, e);
52
+ }
53
+ });
54
+
55
+ return command;
56
+ };
57
+
58
+ const runStrapiCommand = async (argv = process.argv, command = new Command()) => {
59
+ await buildStrapiCommand(argv, command).parseAsync(argv);
60
+ };
61
+
62
+ module.exports = {
63
+ runStrapiCommand,
64
+ buildStrapiCommand,
65
+ strapiCommands,
66
+ };
@@ -12,9 +12,9 @@ const {
12
12
  createLogger,
13
13
  } = require('@strapi/logger');
14
14
  const ora = require('ora');
15
- const { readableBytes, exitWith } = require('../utils/helpers');
15
+ const { readableBytes, exitWith } = require('./helpers');
16
16
  const strapi = require('../../index');
17
- const { getParseListWithChoices, parseInteger } = require('../utils/commander');
17
+ const { getParseListWithChoices, parseInteger } = require('./commander');
18
18
 
19
19
  const exitMessageText = (process, error = false) => {
20
20
  const processCapitalized = process[0].toUpperCase() + process.slice(1);
@@ -4,8 +4,10 @@
4
4
  * Helper functions for the Strapi CLI
5
5
  */
6
6
 
7
- const chalk = require('chalk');
7
+ const { yellow, red, green } = require('chalk');
8
8
  const { isString, isArray } = require('lodash/fp');
9
+ const resolveCwd = require('resolve-cwd');
10
+ const { has } = require('lodash/fp');
9
11
 
10
12
  const bytesPerKb = 1024;
11
13
  const sizes = ['B ', 'KB', 'MB', 'GB', 'TB', 'PB'];
@@ -46,9 +48,9 @@ const exitWith = (code, message = undefined, options = {}) => {
46
48
 
47
49
  const log = (message) => {
48
50
  if (code === 0) {
49
- logger.log(chalk.green(message));
51
+ logger.log(green(message));
50
52
  } else {
51
- logger.error(chalk.red(message));
53
+ logger.error(red(message));
52
54
  }
53
55
  };
54
56
 
@@ -107,9 +109,58 @@ const ifOptions = (conditionCallback, isMetCallback = () => {}, isNotMetCallback
107
109
  };
108
110
  };
109
111
 
112
+ const assertCwdContainsStrapiProject = (name) => {
113
+ const logErrorAndExit = () => {
114
+ console.log(
115
+ `You need to run ${yellow(
116
+ `strapi ${name}`
117
+ )} in a Strapi project. Make sure you are in the right directory.`
118
+ );
119
+ process.exit(1);
120
+ };
121
+
122
+ try {
123
+ const pkgJSON = require(`${process.cwd()}/package.json`);
124
+ if (!has('dependencies.@strapi/strapi', pkgJSON)) {
125
+ logErrorAndExit(name);
126
+ }
127
+ } catch (err) {
128
+ logErrorAndExit(name);
129
+ }
130
+ };
131
+
132
+ const getLocalScript =
133
+ (name) =>
134
+ (...args) => {
135
+ assertCwdContainsStrapiProject(name);
136
+
137
+ const cmdPath = resolveCwd.silent(`@strapi/strapi/lib/commands/actions/${name}/action`);
138
+ if (!cmdPath) {
139
+ console.log(
140
+ `Error loading the local ${yellow(
141
+ name
142
+ )} command. Strapi might not be installed in your "node_modules". You may need to run "yarn install".`
143
+ );
144
+ process.exit(1);
145
+ }
146
+
147
+ const script = require(cmdPath);
148
+
149
+ Promise.resolve()
150
+ .then(() => {
151
+ return script(...args);
152
+ })
153
+ .catch((error) => {
154
+ console.error(error);
155
+ process.exit(1);
156
+ });
157
+ };
158
+
110
159
  module.exports = {
111
160
  exitWith,
112
161
  assertUrlHasProtocol,
113
162
  ifOptions,
114
163
  readableBytes,
164
+ getLocalScript,
165
+ assertCwdContainsStrapiProject,
115
166
  };
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const { has } = require('lodash/fp');
3
+ const { has, isPlainObject } = require('lodash/fp');
4
4
 
5
5
  const ALLOWED_TYPES = [
6
6
  'biginteger',
@@ -44,7 +44,7 @@ const customFieldsRegistry = (strapi) => {
44
44
  throw new Error(`Custom fields require a 'name' and 'type' key`);
45
45
  }
46
46
 
47
- const { name, plugin, type } = cf;
47
+ const { name, plugin, type, inputSize } = cf;
48
48
  if (!ALLOWED_TYPES.includes(type)) {
49
49
  throw new Error(
50
50
  `Custom field type: '${type}' is not a valid Strapi type or it can't be used with a Custom Field`
@@ -56,6 +56,23 @@ const customFieldsRegistry = (strapi) => {
56
56
  throw new Error(`Custom field name: '${name}' is not a valid object key`);
57
57
  }
58
58
 
59
+ // Validate inputSize when provided
60
+ if (inputSize) {
61
+ if (
62
+ !isPlainObject(inputSize) ||
63
+ !has('default', inputSize) ||
64
+ !has('isResizable', inputSize)
65
+ ) {
66
+ throw new Error(`inputSize should be an object with 'default' and 'isResizable' keys`);
67
+ }
68
+ if (![4, 6, 8, 12].includes(inputSize.default)) {
69
+ throw new Error('Custom fields require a valid default input size');
70
+ }
71
+ if (typeof inputSize.isResizable !== 'boolean') {
72
+ throw new Error('Custom fields should specify if their input is resizable');
73
+ }
74
+ }
75
+
59
76
  // When no plugin is specified, or it isn't found in Strapi, default to global
60
77
  const uid = strapi.plugin(plugin) ? `plugin::${plugin}.${name}` : `global::${name}`;
61
78
 
@@ -4,7 +4,6 @@ const os = require('os');
4
4
  const path = require('path');
5
5
  const _ = require('lodash');
6
6
  const isDocker = require('is-docker');
7
- const fetch = require('node-fetch');
8
7
  const ciEnv = require('ci-info');
9
8
  const { isUsingTypeScriptSync } = require('@strapi/typescript-utils');
10
9
  const { env } = require('@strapi/utils');
@@ -82,7 +81,7 @@ module.exports = (strapi) => {
82
81
  };
83
82
 
84
83
  try {
85
- const res = await fetch(`${ANALYTICS_URI}/api/v2/track`, reqParams);
84
+ const res = await strapi.fetch(`${ANALYTICS_URI}/api/v2/track`, reqParams);
86
85
  return res.ok;
87
86
  } catch (err) {
88
87
  return false;
@@ -6,7 +6,6 @@
6
6
 
7
7
  const debug = require('debug')('strapi:webhook');
8
8
  const _ = require('lodash');
9
- const fetch = require('node-fetch');
10
9
 
11
10
  const WorkerQueue = require('./worker-queue');
12
11
 
@@ -15,12 +14,13 @@ const defaultConfiguration = {
15
14
  };
16
15
 
17
16
  class WebhookRunner {
18
- constructor({ eventHub, logger, configuration = {} }) {
19
- debug('Initialized webhook runer');
17
+ constructor({ eventHub, logger, configuration = {}, fetch }) {
18
+ debug('Initialized webhook runner');
20
19
  this.eventHub = eventHub;
21
20
  this.logger = logger;
22
21
  this.webhooksMap = new Map();
23
22
  this.listeners = new Map();
23
+ this.fetch = fetch;
24
24
 
25
25
  if (typeof configuration !== 'object') {
26
26
  throw new Error(
@@ -76,7 +76,7 @@ class WebhookRunner {
76
76
  run(webhook, event, info = {}) {
77
77
  const { url, headers } = webhook;
78
78
 
79
- return fetch(url, {
79
+ return this.fetch(url, {
80
80
  method: 'post',
81
81
  body: JSON.stringify({
82
82
  event,
@@ -0,0 +1,6 @@
1
+ import { Command } from 'commander';
2
+
3
+ export type AddCommandOptions = {
4
+ command: Command;
5
+ argv: Record<number, string>;
6
+ };
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ const nodeFetch = require('node-fetch');
4
+ const HttpsProxyAgent = require('https-proxy-agent');
5
+
6
+ function createStrapiFetch(strapi) {
7
+ function fetch(url, options) {
8
+ return nodeFetch(url, {
9
+ ...(fetch.agent ? { agent: fetch.agent } : {}),
10
+ ...options,
11
+ });
12
+ }
13
+
14
+ const { globalProxy: proxy } = strapi.config.get('server');
15
+
16
+ if (proxy) {
17
+ fetch.agent = new HttpsProxyAgent(proxy);
18
+ }
19
+
20
+ return fetch;
21
+ }
22
+
23
+ module.exports = createStrapiFetch;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/strapi",
3
- "version": "4.10.0-beta.1",
3
+ "version": "4.10.0",
4
4
  "description": "An open source headless CMS solution to create and manage your own API. It provides a powerful dashboard and features to make your life easier. Databases supported: MySQL, MariaDB, PostgreSQL, SQLite",
5
5
  "keywords": [
6
6
  "strapi",
@@ -81,19 +81,19 @@
81
81
  "dependencies": {
82
82
  "@koa/cors": "3.4.3",
83
83
  "@koa/router": "10.1.1",
84
- "@strapi/admin": "4.10.0-beta.1",
85
- "@strapi/data-transfer": "4.10.0-beta.1",
86
- "@strapi/database": "4.10.0-beta.1",
87
- "@strapi/generate-new": "4.10.0-beta.1",
88
- "@strapi/generators": "4.10.0-beta.1",
89
- "@strapi/logger": "4.10.0-beta.1",
90
- "@strapi/permissions": "4.10.0-beta.1",
91
- "@strapi/plugin-content-manager": "4.10.0-beta.1",
92
- "@strapi/plugin-content-type-builder": "4.10.0-beta.1",
93
- "@strapi/plugin-email": "4.10.0-beta.1",
94
- "@strapi/plugin-upload": "4.10.0-beta.1",
95
- "@strapi/typescript-utils": "4.10.0-beta.1",
96
- "@strapi/utils": "4.10.0-beta.1",
84
+ "@strapi/admin": "4.10.0",
85
+ "@strapi/data-transfer": "4.10.0",
86
+ "@strapi/database": "4.10.0",
87
+ "@strapi/generate-new": "4.10.0",
88
+ "@strapi/generators": "4.10.0",
89
+ "@strapi/logger": "4.10.0",
90
+ "@strapi/permissions": "4.10.0",
91
+ "@strapi/plugin-content-manager": "4.10.0",
92
+ "@strapi/plugin-content-type-builder": "4.10.0",
93
+ "@strapi/plugin-email": "4.10.0",
94
+ "@strapi/plugin-upload": "4.10.0",
95
+ "@strapi/typescript-utils": "4.10.0",
96
+ "@strapi/utils": "4.10.0",
97
97
  "bcryptjs": "2.4.3",
98
98
  "boxen": "5.1.2",
99
99
  "chalk": "4.1.2",
@@ -109,6 +109,7 @@
109
109
  "fs-extra": "10.0.0",
110
110
  "glob": "7.2.0",
111
111
  "http-errors": "1.8.1",
112
+ "https-proxy-agent": "5.0.1",
112
113
  "inquirer": "8.2.5",
113
114
  "is-docker": "2.2.1",
114
115
  "koa": "2.13.4",
@@ -136,11 +137,11 @@
136
137
  },
137
138
  "devDependencies": {
138
139
  "supertest": "6.3.3",
139
- "typescript": "4.6.2"
140
+ "typescript": "5.0.4"
140
141
  },
141
142
  "engines": {
142
143
  "node": ">=14.19.1 <=18.x.x",
143
144
  "npm": ">=6.0.0"
144
145
  },
145
- "gitHead": "95d581b31bee464af42e5d8db408fa578d8532c7"
146
+ "gitHead": "9b5519778faaedfb837879f9c6f7e28fdfd6750d"
146
147
  }
@@ -1,18 +0,0 @@
1
- 'use strict';
2
-
3
- const strapi = require('..');
4
- const { buildAdmin } = require('./builders');
5
-
6
- /**
7
- * `$ strapi build`
8
- */
9
- module.exports = async ({ optimization, forceBuild = true }) => {
10
- const { appDir, distDir } = await strapi.compile();
11
-
12
- await buildAdmin({
13
- forceBuild,
14
- optimization,
15
- buildDestDir: distDir,
16
- srcDir: appDir,
17
- });
18
- };