From 3787573828456d92592aae8b19fffc0799aae28d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20No=C3=ABl?= Date: Tue, 12 May 2020 11:28:32 +0200 Subject: [PATCH 01/14] updated server.url doc + remove server.admin.build doc (#6173) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Noël --- docs/3.0.0-beta.x/concepts/configurations.md | 26 +++++++++----------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/docs/3.0.0-beta.x/concepts/configurations.md b/docs/3.0.0-beta.x/concepts/configurations.md index 2da9b5ea42..f2bbf1df44 100644 --- a/docs/3.0.0-beta.x/concepts/configurations.md +++ b/docs/3.0.0-beta.x/concepts/configurations.md @@ -168,20 +168,18 @@ module.exports = ({ env }) => ({ **Available options** -| Property | Description | Type | Default | -| ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- | ----------- | -| `host` | Host name | string | `localhost` | -| `port` | Port on which the server should be running. | integer | `1337` | -| `emitErrors` | Enable errors to be emitted to `koa` when they happen in order to attach custom logic or use error reporting services. | boolean | | -| `url` | Url of the server. Enable proxy support such as Apache or Nginx, example: `https://mywebsite.com/api`. Default value: `http://${host}:${port}`. | string | | -| `cron` | Cron configuration (powered by [`node-schedule`](https://github.com/node-schedule/node-schedule)) | Object | | -| `cron.enabled` | Enable or disable CRON tasks to schedule jobs at specific dates. | boolean | `false` | -| `admin` | Admin panel configuration | Object | | -| `admin.url` | Url of your admin panel. Default value: `/admin`. Note: If the url is relative, it will be concatenated with `url`. | string | `/admin` | -| `admin.autoOpen` | Enable or disabled administration opening on start. | boolean | `true` | -| `admin.watchIgnoreFiles` | Add custom files that should not be watched during development. See more [here](https://github.com/paulmillr/chokidar#path-filtering) (property `ignored`). | Array(string) | `[]`. | -| `admin.build` | Admin panel build configuration | Object | | -| `admin.build.backend` | URL that the admin panel and plugins will request | string | | +| Property | Description | Type | Default | +| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------- | ----------- | +| `host` | Host name | string | `localhost` | +| `port` | Port on which the server should be running. | integer | `1337` | +| `emitErrors` | Enable errors to be emitted to `koa` when they happen in order to attach custom logic or use error reporting services. | boolean | `false | +| `url` | Url of the server. Enable proxy support such as Apache or Nginx, example: `https://mywebsite.com/api`. The url can be relative, if so, it is used with `http://${host}:${port}` as the base url. | string | `''` | +| `cron` | Cron configuration (powered by [`node-schedule`](https://github.com/node-schedule/node-schedule)) | Object | | +| `cron.enabled` | Enable or disable CRON tasks to schedule jobs at specific dates. | boolean | `false` | +| `admin` | Admin panel configuration | Object | | +| `admin.url` | Url of your admin panel. Default value: `/admin`. Note: If the url is relative, it will be concatenated with `url`. | string | `/admin` | +| `admin.autoOpen` | Enable or disabled administration opening on start. | boolean | `true` | +| `admin.watchIgnoreFiles` | Add custom files that should not be watched during development. See more [here](https://github.com/paulmillr/chokidar#path-filtering) (property `ignored`). | Array(string) | `[]`. | ## Functions From 5400f3e1dd86ff0776fd58e163787926d5871497 Mon Sep 17 00:00:00 2001 From: soupette Date: Wed, 13 May 2020 17:21:17 +0200 Subject: [PATCH 02/14] Remove email plugin admin files Signed-off-by: soupette --- .../admin/src/components/PluginCard/index.js | 10 +- .../containers/InstalledPluginsPage/Row.js | 20 +- .../admin/src/components/EditForm/Wrapper.js | 24 --- .../admin/src/components/EditForm/index.js | 97 --------- .../admin/src/containers/App/index.js | 36 ---- .../src/containers/ConfigPage/actions.js | 77 ------- .../src/containers/ConfigPage/constants.js | 16 -- .../admin/src/containers/ConfigPage/index.js | 190 ------------------ .../src/containers/ConfigPage/reducer.js | 67 ------ .../admin/src/containers/ConfigPage/saga.js | 51 ----- .../src/containers/ConfigPage/selectors.js | 32 --- .../admin/src/containers/Initializer/index.js | 28 --- .../Initializer/tests/index.test.js | 19 -- .../strapi-plugin-email/admin/src/index.js | 15 +- .../admin/src/lifecycles.js | 13 -- .../strapi-plugin-email/admin/src/reducers.js | 8 - .../admin/src/translations/ar.json | 4 - .../admin/src/translations/cs.json | 11 - .../admin/src/translations/de.json | 11 - .../admin/src/translations/en.json | 11 - .../admin/src/translations/es.json | 11 - .../admin/src/translations/fr.json | 11 - .../admin/src/translations/index.js | 43 ---- .../admin/src/translations/it.json | 11 - .../admin/src/translations/ja.json | 11 - .../admin/src/translations/ko.json | 11 - .../admin/src/translations/nl.json | 11 - .../admin/src/translations/pl.json | 11 - .../admin/src/translations/pt-BR.json | 11 - .../admin/src/translations/pt.json | 11 - .../admin/src/translations/ru.json | 11 - .../admin/src/translations/sk.json | 11 - .../admin/src/translations/tr.json | 11 - .../admin/src/translations/vi.json | 11 - .../admin/src/translations/zh-Hans.json | 11 - .../admin/src/translations/zh.json | 11 - 36 files changed, 9 insertions(+), 939 deletions(-) delete mode 100644 packages/strapi-plugin-email/admin/src/components/EditForm/Wrapper.js delete mode 100644 packages/strapi-plugin-email/admin/src/components/EditForm/index.js delete mode 100644 packages/strapi-plugin-email/admin/src/containers/App/index.js delete mode 100644 packages/strapi-plugin-email/admin/src/containers/ConfigPage/actions.js delete mode 100644 packages/strapi-plugin-email/admin/src/containers/ConfigPage/constants.js delete mode 100644 packages/strapi-plugin-email/admin/src/containers/ConfigPage/index.js delete mode 100644 packages/strapi-plugin-email/admin/src/containers/ConfigPage/reducer.js delete mode 100644 packages/strapi-plugin-email/admin/src/containers/ConfigPage/saga.js delete mode 100644 packages/strapi-plugin-email/admin/src/containers/ConfigPage/selectors.js delete mode 100644 packages/strapi-plugin-email/admin/src/containers/Initializer/index.js delete mode 100644 packages/strapi-plugin-email/admin/src/containers/Initializer/tests/index.test.js delete mode 100644 packages/strapi-plugin-email/admin/src/lifecycles.js delete mode 100644 packages/strapi-plugin-email/admin/src/reducers.js delete mode 100644 packages/strapi-plugin-email/admin/src/translations/ar.json delete mode 100644 packages/strapi-plugin-email/admin/src/translations/cs.json delete mode 100644 packages/strapi-plugin-email/admin/src/translations/de.json delete mode 100644 packages/strapi-plugin-email/admin/src/translations/en.json delete mode 100644 packages/strapi-plugin-email/admin/src/translations/es.json delete mode 100644 packages/strapi-plugin-email/admin/src/translations/fr.json delete mode 100644 packages/strapi-plugin-email/admin/src/translations/index.js delete mode 100644 packages/strapi-plugin-email/admin/src/translations/it.json delete mode 100644 packages/strapi-plugin-email/admin/src/translations/ja.json delete mode 100644 packages/strapi-plugin-email/admin/src/translations/ko.json delete mode 100644 packages/strapi-plugin-email/admin/src/translations/nl.json delete mode 100644 packages/strapi-plugin-email/admin/src/translations/pl.json delete mode 100644 packages/strapi-plugin-email/admin/src/translations/pt-BR.json delete mode 100644 packages/strapi-plugin-email/admin/src/translations/pt.json delete mode 100644 packages/strapi-plugin-email/admin/src/translations/ru.json delete mode 100644 packages/strapi-plugin-email/admin/src/translations/sk.json delete mode 100644 packages/strapi-plugin-email/admin/src/translations/tr.json delete mode 100644 packages/strapi-plugin-email/admin/src/translations/vi.json delete mode 100644 packages/strapi-plugin-email/admin/src/translations/zh-Hans.json delete mode 100644 packages/strapi-plugin-email/admin/src/translations/zh.json diff --git a/packages/strapi-admin/admin/src/components/PluginCard/index.js b/packages/strapi-admin/admin/src/components/PluginCard/index.js index 83943978e2..a25c630d8d 100644 --- a/packages/strapi-admin/admin/src/components/PluginCard/index.js +++ b/packages/strapi-admin/admin/src/components/PluginCard/index.js @@ -11,8 +11,6 @@ import { Button, PopUpWarning } from 'strapi-helper-plugin'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import Wrapper from './Wrapper'; -const PLUGINS_WITH_CONFIG = ['email']; - /* eslint-disable react/no-unused-state */ class PluginCard extends React.Component { state = { @@ -92,13 +90,7 @@ class PluginCard extends React.Component { ? 'app.components.PluginCard.Button.label.install' : 'app.components.PluginCard.Button.label.download'; - // Display settings link for a selection of plugins. - const settingsComponent = PLUGINS_WITH_CONFIG.includes(this.props.plugin.id) && ( -
- - -
- ); + const settingsComponent = null; const descriptions = { short: diff --git a/packages/strapi-admin/admin/src/containers/InstalledPluginsPage/Row.js b/packages/strapi-admin/admin/src/containers/InstalledPluginsPage/Row.js index 80bb1a8f89..f70dbac81f 100644 --- a/packages/strapi-admin/admin/src/containers/InstalledPluginsPage/Row.js +++ b/packages/strapi-admin/admin/src/containers/InstalledPluginsPage/Row.js @@ -3,31 +3,17 @@ import PropTypes from 'prop-types'; import { IconLinks } from '@buffetjs/core'; import { useGlobalContext, PopUpWarning } from 'strapi-helper-plugin'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { useHistory } from 'react-router-dom'; -import { faTrashAlt, faCog } from '@fortawesome/free-solid-svg-icons'; + +import { faTrashAlt } from '@fortawesome/free-solid-svg-icons'; import Text from '../../components/Text'; import CustomRow from './CustomRow'; import LogoContainer from './Logo'; -const PLUGINS_WITH_CONFIG = ['email']; - const Row = ({ logo, name, description, isRequired, id, icon, onConfirm }) => { - const { currentEnvironment, formatMessage } = useGlobalContext(); + const { formatMessage } = useGlobalContext(); const [isOpen, setIsOpen] = useState(false); - const { push } = useHistory(); const links = []; - if (PLUGINS_WITH_CONFIG.includes(id)) { - links.push({ - icon: , - onClick: () => { - const settingsPath = `/plugins/${id}/configurations/${currentEnvironment}`; - - push(settingsPath); - }, - }); - } - const handleClickConfirm = () => { handleToggle(); onConfirm(id); diff --git a/packages/strapi-plugin-email/admin/src/components/EditForm/Wrapper.js b/packages/strapi-plugin-email/admin/src/components/EditForm/Wrapper.js deleted file mode 100644 index 2b64aedeb8..0000000000 --- a/packages/strapi-plugin-email/admin/src/components/EditForm/Wrapper.js +++ /dev/null @@ -1,24 +0,0 @@ -import styled from 'styled-components'; - -const Wrapper = styled.div` - background: #ffffff; - padding: 45px 30px 22px 30px; - border-radius: 2px; - box-shadow: 0 2px 4px #e3e9f3; - - .inputStyle { - max-width: 358px; - } - - .input-wrapper { - margin-bottom: 1.1rem; - } - - .subFormWrapper { - margin-bottom: 14px; - padding: 23px 30px 0 30px; - background-color: #fafafb; - } -`; - -export default Wrapper; diff --git a/packages/strapi-plugin-email/admin/src/components/EditForm/index.js b/packages/strapi-plugin-email/admin/src/components/EditForm/index.js deleted file mode 100644 index 7b93e79792..0000000000 --- a/packages/strapi-plugin-email/admin/src/components/EditForm/index.js +++ /dev/null @@ -1,97 +0,0 @@ -/** - * - * EditForm - * - */ - -import React from 'react'; -import { findIndex, get, isEmpty, map } from 'lodash'; -import PropTypes from 'prop-types'; -import { InputsIndex as Input } from 'strapi-helper-plugin'; -import Wrapper from './Wrapper'; - -class EditForm extends React.Component { - getProviderForm = () => - get( - this.props.settings, - ['providers', this.props.selectedProviderIndex, 'auth'], - {} - ); - - generateSelectOptions = () => - Object.keys(get(this.props.settings, 'providers', {})).reduce( - (acc, current) => { - const option = { - id: get(this.props.settings, ['providers', current, 'name']), - value: get(this.props.settings, ['providers', current, 'provider']), - }; - acc.push(option); - - return acc; - }, - [] - ); - - render() { - return ( - -
- -
- {!isEmpty(this.getProviderForm()) && ( -
-
- {map(this.getProviderForm(), (value, key) => ( - - ))} -
-
- )} -
- ); - } -} - -EditForm.defaultProps = { - settings: { - providers: [], - }, -}; - -EditForm.propTypes = { - didCheckErrors: PropTypes.bool.isRequired, - formErrors: PropTypes.array.isRequired, - modifiedData: PropTypes.object.isRequired, - onChange: PropTypes.func.isRequired, - selectedProviderIndex: PropTypes.number.isRequired, - settings: PropTypes.object, -}; - -export default EditForm; diff --git a/packages/strapi-plugin-email/admin/src/containers/App/index.js b/packages/strapi-plugin-email/admin/src/containers/App/index.js deleted file mode 100644 index d3d2f6a150..0000000000 --- a/packages/strapi-plugin-email/admin/src/containers/App/index.js +++ /dev/null @@ -1,36 +0,0 @@ -/** - * - * This component is the skeleton around the actual pages, and should only - * contain code that should be seen on all pages. (e.g. navigation bar) - * - */ - -import React from 'react'; -import { Switch, Route } from 'react-router-dom'; - -import pluginId from '../../pluginId'; - -// Containers -import ConfigPage from '../ConfigPage'; - -function App() { - return ( -
- - - - - -
- ); -} - -export default App; diff --git a/packages/strapi-plugin-email/admin/src/containers/ConfigPage/actions.js b/packages/strapi-plugin-email/admin/src/containers/ConfigPage/actions.js deleted file mode 100644 index 95780ecc63..0000000000 --- a/packages/strapi-plugin-email/admin/src/containers/ConfigPage/actions.js +++ /dev/null @@ -1,77 +0,0 @@ -/** - * - * - * ConfigPage actions - * - */ - -import { - GET_SETTINGS, - GET_SETTINGS_SUCCEEDED, - ON_CANCEL, - ON_CHANGE, - SET_ERRORS, - SUBMIT, - SUBMIT_ERROR, - SUBMIT_SUCCEEDED, -} from './constants'; - -export function getSettings(env) { - return { - type: GET_SETTINGS, - env, - }; -} - -export function getSettingsSucceeded(settings, appEnvironments) { - return { - type: GET_SETTINGS_SUCCEEDED, - appEnvironments, - settings, - initialData: settings.config, - }; -} - -export function onCancel() { - return { - type: ON_CANCEL, - }; -} - -export function onChange({ target }) { - const keys = ['modifiedData'].concat(target.name.split('.')); - const value = target.value; - - return { - type: ON_CHANGE, - keys, - value, - }; -} - -export function setErrors(errors) { - return { - type: SET_ERRORS, - errors, - }; -} - -export function submit() { - return { - type: SUBMIT, - }; -} - -export function submitError(errors) { - return { - type: SUBMIT_ERROR, - errors, - }; -} - -export function submitSucceeded(data) { - return { - type: SUBMIT_SUCCEEDED, - data, - }; -} diff --git a/packages/strapi-plugin-email/admin/src/containers/ConfigPage/constants.js b/packages/strapi-plugin-email/admin/src/containers/ConfigPage/constants.js deleted file mode 100644 index 7aef718f7c..0000000000 --- a/packages/strapi-plugin-email/admin/src/containers/ConfigPage/constants.js +++ /dev/null @@ -1,16 +0,0 @@ -/** - * - * ConfigPage constants - * - */ - -export const GET_ENV = 'Email/ConfigPage/GET_ENV'; -export const GET_ENV_SUCCEEDED = 'Email/ConfigPage/GET_ENV_SUCCEEDED'; -export const GET_SETTINGS = 'Email/ConfigPage/GET_SETTINGS'; -export const GET_SETTINGS_SUCCEEDED = 'Email/ConfigPage/GET_SETTINGS_SUCCEEDED'; -export const ON_CANCEL = 'Email/ConfigPage/ON_CANCEL'; -export const ON_CHANGE = 'Email/ConfigPage/ON_CHANGE'; -export const SET_ERRORS = 'Email/ConfigPage/SET_ERRORS'; -export const SUBMIT = 'Email/ConfigPage/SUBMIT'; -export const SUBMIT_ERROR = 'Email/ConfigPage/SUBMIT_ERROR'; -export const SUBMIT_SUCCEEDED = 'Email/ConfigPage/SUBMIT_SUCCEEDED'; diff --git a/packages/strapi-plugin-email/admin/src/containers/ConfigPage/index.js b/packages/strapi-plugin-email/admin/src/containers/ConfigPage/index.js deleted file mode 100644 index 9680f7ca0d..0000000000 --- a/packages/strapi-plugin-email/admin/src/containers/ConfigPage/index.js +++ /dev/null @@ -1,190 +0,0 @@ -/** - * - * ConfigPage - * - */ - -import React from 'react'; -import PropTypes from 'prop-types'; -import { connect } from 'react-redux'; -import { bindActionCreators, compose } from 'redux'; -import { findIndex, get, isEmpty } from 'lodash'; -import { Header } from '@buffetjs/custom'; -// You can find these components in either -// ./node_modules/strapi-helper-plugin/lib/src -// or strapi/packages/strapi-helper-plugin/lib/src -import { ContainerFluid, HeaderNav, GlobalContext } from 'strapi-helper-plugin'; -import pluginId from '../../pluginId'; -// Plugin's components -import EditForm from '../../components/EditForm'; -import { getSettings, onCancel, onChange, setErrors, submit } from './actions'; -import saga from './saga'; -import selectConfigPage from './selectors'; - -class ConfigPage extends React.Component { - pluginHeaderActions = [ - { - color: 'cancel', - label: this.context.formatMessage({ id: 'app.components.Button.cancel' }), - onClick: this.props.onCancel, - type: 'button', - key: 'button-cancel', - }, - { - color: 'success', - label: this.context.formatMessage({ id: 'app.components.Button.save' }), - onClick: this.handleSubmit, - type: 'submit', - key: 'button-submit', - }, - ]; - - componentDidMount() { - this.getSettings(this.props); - } - - componentDidUpdate(prevProps) { - // Get new settings on navigation change - if (prevProps.match.params.env !== this.props.match.params.env) { - this.getSettings(this.props); - } - - // Redirect the user to the email list after modifying is provider - if (prevProps.submitSuccess !== this.props.submitSuccess) { - this.props.history.push(`/plugins/email/configurations/${this.props.match.params.env}`); - } - } - - getSelectedProviderIndex = () => - findIndex(this.props.settings.providers, [ - 'provider', - get(this.props.modifiedData, 'provider'), - ]); - - /** - * Get Settings depending on the props - * @param {Object} props - * @return {Func} calls the saga that gets the current settings - */ - getSettings = props => { - const { - match: { - params: { env }, - }, - } = props; - this.props.getSettings(env); - }; - - generateLinks = () => { - const headerNavLinks = this.props.appEnvironments - .reduce((acc, current) => { - const link = Object.assign(current, { - to: `/plugins/email/configurations/${current.name}`, - }); - acc.push(link); - - return acc; - }, []) - .sort(link => link.name === 'production'); - - return headerNavLinks; - }; - - handleSubmit = e => { - e.preventDefault(); - const formErrors = Object.keys( - get(this.props.settings, ['providers', this.getSelectedProviderIndex(), 'auth'], {}) - ).reduce((acc, current) => { - if (isEmpty(get(this.props.modifiedData, current, ''))) { - acc.push({ - name: current, - errors: [{ id: 'components.Input.error.validation.required' }], - }); - } - - return acc; - }, []); - - if (!isEmpty(formErrors)) { - return this.props.setErrors(formErrors); - } - - return this.props.submit(); - }; - - static contextType = GlobalContext; - - render() { - const { formatMessage } = this.context; - - return ( -
-
- -
- - - - -
- ); - } -} - -ConfigPage.defaultProps = { - appEnvironments: [], - formErrors: [], - settings: { - providers: [], - }, -}; - -ConfigPage.propTypes = { - appEnvironments: PropTypes.array, - didCheckErrors: PropTypes.bool.isRequired, - formErrors: PropTypes.array, - getSettings: PropTypes.func.isRequired, - history: PropTypes.object.isRequired, - match: PropTypes.object.isRequired, - modifiedData: PropTypes.object.isRequired, - onCancel: PropTypes.func.isRequired, - onChange: PropTypes.func.isRequired, - setErrors: PropTypes.func.isRequired, - settings: PropTypes.object, - submit: PropTypes.func.isRequired, - submitSuccess: PropTypes.bool.isRequired, -}; - -function mapDispatchToProps(dispatch) { - return bindActionCreators( - { - getSettings, - onCancel, - onChange, - setErrors, - submit, - }, - dispatch - ); -} - -const mapStateToProps = selectConfigPage(); - -const withConnect = connect(mapStateToProps, mapDispatchToProps); - -const withSaga = strapi.injectSaga({ key: 'configPage', saga, pluginId }); - -export default compose(withSaga, withConnect)(ConfigPage); diff --git a/packages/strapi-plugin-email/admin/src/containers/ConfigPage/reducer.js b/packages/strapi-plugin-email/admin/src/containers/ConfigPage/reducer.js deleted file mode 100644 index 4e93baf56e..0000000000 --- a/packages/strapi-plugin-email/admin/src/containers/ConfigPage/reducer.js +++ /dev/null @@ -1,67 +0,0 @@ -/** - * - * ConfigPage reducer - * - */ - -import { fromJS, List, Map } from 'immutable'; - -import { - GET_SETTINGS, - GET_SETTINGS_SUCCEEDED, - ON_CANCEL, - ON_CHANGE, - SET_ERRORS, - SUBMIT_ERROR, - SUBMIT_SUCCEEDED, -} from './constants'; - -const initialState = fromJS({ - appEnvironments: List([]), - didCheckErrors: false, - env: '', - formErrors: List([]), - initialData: Map({}), - modifiedData: Map({}), - settings: {}, - submitSuccess: false, -}); - -function configPageReducer(state = initialState, action) { - switch (action.type) { - case GET_SETTINGS: - return state.update('env', () => action.env); - case GET_SETTINGS_SUCCEEDED: - return state - .update('appEnvironments', () => List(action.appEnvironments)) - .update('didCheckErrors', (v) => v = !v) - .update('formErrors', () => List([])) - .update('initialData', () => Map(action.initialData)) - .update('modifiedData', () => Map(action.initialData)) - .update('settings', () => action.settings); - case ON_CANCEL: - return state - .update('didCheckErrors', (v) => v = !v) - .update('formErrors', () => List([])) - .update('modifiedData', () => state.get('initialData')); - case ON_CHANGE: - return state - .updateIn(action.keys, () => action.value); - case SET_ERRORS: - case SUBMIT_ERROR: - return state - .update('didCheckErrors', (v) => v = !v) - .update('formErrors', () => List(action.errors)); - case SUBMIT_SUCCEEDED: - return state - .update('didCheckErrors', (v) => v = !v) - .update('formErrors', () => List([])) - .update('initialData', () => Map(action.data)) - .update('modifiedData', () => Map(action.data)) - .update('submitSuccess', (v) => v = !v); - default: - return state; - } -} - -export default configPageReducer; diff --git a/packages/strapi-plugin-email/admin/src/containers/ConfigPage/saga.js b/packages/strapi-plugin-email/admin/src/containers/ConfigPage/saga.js deleted file mode 100644 index 17c27d13fa..0000000000 --- a/packages/strapi-plugin-email/admin/src/containers/ConfigPage/saga.js +++ /dev/null @@ -1,51 +0,0 @@ -// import { LOCATION_CHANGE } from 'react-router-redux'; -import { all, call, fork, put, select, takeLatest } from 'redux-saga/effects'; -import { request } from 'strapi-helper-plugin'; -import { getSettingsSucceeded, submitSucceeded } from './actions'; -import { GET_SETTINGS, SUBMIT } from './constants'; -import { makeSelectEnv, makeSelectModifiedData } from './selectors'; - -export function* settingsGet(action) { - try { - const requestURL = `/email/settings/${action.env}`; - const response = yield all([ - call(request, requestURL, { method: 'GET' }), - call(request, '/email/environments', { method: 'GET' }), - ]); - - yield put(getSettingsSucceeded(response[0], response[1].environments)); - } catch (err) { - strapi.notification.error('notification.error'); - } -} - -export function* submit() { - try { - const env = yield select(makeSelectEnv()); - let body = yield select(makeSelectModifiedData()); - - if (body.provider === 'local') { - body = { - enabled: body.enabled, - provider: 'local', - sizeLimit: body.sizeLimit, - }; - } - const requestURL = `/email/settings/${env}`; - yield call(request, requestURL, { method: 'PUT', body }); - - // Update reducer with optimisticResponse - strapi.notification.success('email.notification.config.success'); - yield put(submitSucceeded(body)); - } catch (err) { - strapi.notification.error('notification.error'); - // TODO handle error PUT - } -} - -function* defaultSaga() { - yield fork(takeLatest, GET_SETTINGS, settingsGet); - yield fork(takeLatest, SUBMIT, submit); -} - -export default defaultSaga; diff --git a/packages/strapi-plugin-email/admin/src/containers/ConfigPage/selectors.js b/packages/strapi-plugin-email/admin/src/containers/ConfigPage/selectors.js deleted file mode 100644 index 2659d39aa5..0000000000 --- a/packages/strapi-plugin-email/admin/src/containers/ConfigPage/selectors.js +++ /dev/null @@ -1,32 +0,0 @@ -import { createSelector } from 'reselect'; -import pluginId from '../../pluginId'; - -/** - * Direct selector to the configPage state domain - */ -const selectConfigPageDomain = () => state => state.get(`${pluginId}_configPage`); - -/** - * Default selector used by ConfigPage - */ - -const selectConfigPage = () => createSelector( - selectConfigPageDomain(), - (substate) => substate.toJS(), -); - -const makeSelectEnv = () => createSelector( - selectConfigPageDomain(), - (substate) => substate.get('env'), -); - -const makeSelectModifiedData = () => createSelector( - selectConfigPageDomain(), - (substate) => substate.get('modifiedData').toJS(), -); - -export default selectConfigPage; -export { - makeSelectEnv, - makeSelectModifiedData, -}; diff --git a/packages/strapi-plugin-email/admin/src/containers/Initializer/index.js b/packages/strapi-plugin-email/admin/src/containers/Initializer/index.js deleted file mode 100644 index a6e8b3ff6a..0000000000 --- a/packages/strapi-plugin-email/admin/src/containers/Initializer/index.js +++ /dev/null @@ -1,28 +0,0 @@ -/** - * - * Initializer - * - */ - -import React from 'react'; -import PropTypes from 'prop-types'; - -import pluginId from '../../pluginId'; - -class Initializer extends React.PureComponent { - // eslint-disable-line react/prefer-stateless-function - componentDidMount() { - // Emit the event 'pluginReady' - this.props.updatePlugin(pluginId, 'isReady', true); - } - - render() { - return null; - } -} - -Initializer.propTypes = { - updatePlugin: PropTypes.func.isRequired, -}; - -export default Initializer; diff --git a/packages/strapi-plugin-email/admin/src/containers/Initializer/tests/index.test.js b/packages/strapi-plugin-email/admin/src/containers/Initializer/tests/index.test.js deleted file mode 100644 index 9e7f798b81..0000000000 --- a/packages/strapi-plugin-email/admin/src/containers/Initializer/tests/index.test.js +++ /dev/null @@ -1,19 +0,0 @@ -import React from 'react'; -import { mount, shallow } from 'enzyme'; - -import Initializer from '../index'; - -describe('', () => { - it('Should not crash', () => { - const updatePlugin = jest.fn(); - shallow(); - }); - - it('should call the updatePlugin props when mounted', () => { - const updatePlugin = jest.fn(); - - const wrapper = mount(); - - expect(wrapper.prop('updatePlugin')).toHaveBeenCalledWith('email', 'isReady', true); - }); -}); diff --git a/packages/strapi-plugin-email/admin/src/index.js b/packages/strapi-plugin-email/admin/src/index.js index 586e95a855..2cd8f6ce12 100644 --- a/packages/strapi-plugin-email/admin/src/index.js +++ b/packages/strapi-plugin-email/admin/src/index.js @@ -8,11 +8,6 @@ import pluginPkg from '../../package.json'; import pluginId from './pluginId'; import pluginLogo from './assets/images/logo.svg'; -import App from './containers/App'; -import Initializer from './containers/Initializer'; -import lifecycles from './lifecycles'; -import reducers from './reducers'; -import trads from './translations'; export default strapi => { const pluginDescription = pluginPkg.strapi.description || pluginPkg.description; @@ -23,19 +18,19 @@ export default strapi => { description: pluginDescription, icon: pluginPkg.strapi.icon, id: pluginId, - initializer: Initializer, + isReady: true, + initializer: () => null, injectedComponents: [], isRequired: pluginPkg.strapi.required || false, layout: null, - lifecycles, + lifecycles: () => {}, leftMenuLinks: [], leftMenuSections: [], - mainComponent: App, + mainComponent: null, name: pluginPkg.strapi.name, pluginLogo, preventComponentRendering: false, - reducers, - trads, + trads: {}, }; return strapi.registerPlugin(plugin); diff --git a/packages/strapi-plugin-email/admin/src/lifecycles.js b/packages/strapi-plugin-email/admin/src/lifecycles.js deleted file mode 100644 index 9a875051e1..0000000000 --- a/packages/strapi-plugin-email/admin/src/lifecycles.js +++ /dev/null @@ -1,13 +0,0 @@ -/* - * - * SET THE HOOKS TO ENABLE THE MAGIC OF STRAPI. - * ------------------------------------------- - * - * Secure, customise and enhance your project by setting - * the hooks via this file. - * - */ - -function lifecycles() {} - -export default lifecycles; diff --git a/packages/strapi-plugin-email/admin/src/reducers.js b/packages/strapi-plugin-email/admin/src/reducers.js deleted file mode 100644 index c17b6e52b9..0000000000 --- a/packages/strapi-plugin-email/admin/src/reducers.js +++ /dev/null @@ -1,8 +0,0 @@ -import configPageReducer from './containers/ConfigPage/reducer'; -import pluginId from './pluginId'; - -const reducers = { - [`${pluginId}_configPage`]: configPageReducer, -}; - -export default reducers; diff --git a/packages/strapi-plugin-email/admin/src/translations/ar.json b/packages/strapi-plugin-email/admin/src/translations/ar.json deleted file mode 100644 index 4aa9cc3237..0000000000 --- a/packages/strapi-plugin-email/admin/src/translations/ar.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "plugin.description.long": "إرسال بريد.", - "plugin.description.short": "إرسال بريد." -} \ No newline at end of file diff --git a/packages/strapi-plugin-email/admin/src/translations/cs.json b/packages/strapi-plugin-email/admin/src/translations/cs.json deleted file mode 100644 index bc0857abc3..0000000000 --- a/packages/strapi-plugin-email/admin/src/translations/cs.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "ConfigPage.description": "Nastavení zásuvný modul odesílání e-mailů", - "ConfigPage.title": "E-mail - Nastavení", - "EditForm.Input.number.label": "Maximální povolená velikost (v MB)", - "EditForm.Input.select.inputDescription": "E-maily mohou být odeslány výchozím (Sendmail) nebo externím poskytovatelem.", - "EditForm.Input.select.label": "Poskytovatelé", - "EditForm.Input.toggle.label": "Povolit odesílání e-mailů", - "notification.config.success": "Nastavení bylo uloženo", - "plugin.description.long": "Odeslat e-maily.", - "plugin.description.short": "Odeslat e-maily." -} \ No newline at end of file diff --git a/packages/strapi-plugin-email/admin/src/translations/de.json b/packages/strapi-plugin-email/admin/src/translations/de.json deleted file mode 100644 index 81ca8f8bce..0000000000 --- a/packages/strapi-plugin-email/admin/src/translations/de.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "ConfigPage.description": "E-Mail-Plugin konfigurieren", - "ConfigPage.title": "E-Mail - Einstellungen", - "EditForm.Input.number.label": "Maximal zulässige Größe (in MB)", - "EditForm.Input.select.inputDescription": "E-Mails können mit dem Standardanbieter (Sendmail) oder einem externen Anbieter versendet werden", - "EditForm.Input.select.label": "Anbieter", - "EditForm.Input.toggle.label": "E-Mail-Versand aktivieren", - "notification.config.success": "Die Einstellungen wurden aktualisiert", - "plugin.description.long": "Zum Versand von E-Mails.", - "plugin.description.short": "Zum Versand von E-Mails." -} \ No newline at end of file diff --git a/packages/strapi-plugin-email/admin/src/translations/en.json b/packages/strapi-plugin-email/admin/src/translations/en.json deleted file mode 100644 index 02fc39111b..0000000000 --- a/packages/strapi-plugin-email/admin/src/translations/en.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "ConfigPage.description": "Configure the email plugin", - "ConfigPage.title": "Email - Settings", - "EditForm.Input.number.label": "Maximum size allowed (in MB)", - "EditForm.Input.select.inputDescription": "Emails can be sent with the default provider (Sendmail) or an external provider", - "EditForm.Input.select.label": "Providers", - "EditForm.Input.toggle.label": "Enable email send", - "notification.config.success": "The settings has been updated", - "plugin.description.long": "Send emails.", - "plugin.description.short": "Send emails." -} \ No newline at end of file diff --git a/packages/strapi-plugin-email/admin/src/translations/es.json b/packages/strapi-plugin-email/admin/src/translations/es.json deleted file mode 100644 index f6eef20b8a..0000000000 --- a/packages/strapi-plugin-email/admin/src/translations/es.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "ConfigPage.description": "Configurar el plugin de correo electrónico", - "ConfigPage.title": "Correo electrónico - Configuración", - "EditForm.Input.number.label": "Tamaño máximo permitido (en MB)", - "EditForm.Input.select.inputDescription": "Los correos electrónicos se pueden enviar con el proveedor predeterminado (Sendmail) o con un proveedor externo.", - "EditForm.Input.select.label": "Proveedores", - "EditForm.Input.toggle.label": "Habilitar envío de correo electrónico", - "notification.config.success": "Se ha actualizado la configuración", - "plugin.description.long": "Enviar correos electrónicos.", - "plugin.description.short": "Enviar correos electrónicos." -} \ No newline at end of file diff --git a/packages/strapi-plugin-email/admin/src/translations/fr.json b/packages/strapi-plugin-email/admin/src/translations/fr.json deleted file mode 100644 index 17a1af7a45..0000000000 --- a/packages/strapi-plugin-email/admin/src/translations/fr.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "ConfigPage.description": "Configurer le plugin email", - "ConfigPage.title": "E-mail - Paramètres", - "EditForm.Input.number.label": "Taille maximale autorisée (en MB)", - "EditForm.Input.select.inputDescription": "Les e-mails peuvent être envoyés avec le fournisseur par défaut (Sendmail) ou un fournisseur externe.", - "EditForm.Input.select.label": "Fournisseurs", - "EditForm.Input.toggle.label": "Activer l'envoi d'e-mails", - "notification.config.success": "Les paramètres ont été mis à jour.", - "plugin.description.long": "Envoyez des emails", - "plugin.description.short": "Envoyez des emails" -} diff --git a/packages/strapi-plugin-email/admin/src/translations/index.js b/packages/strapi-plugin-email/admin/src/translations/index.js deleted file mode 100644 index ad81cf9323..0000000000 --- a/packages/strapi-plugin-email/admin/src/translations/index.js +++ /dev/null @@ -1,43 +0,0 @@ -import ar from './ar.json'; -import cs from './cs.json'; -import de from './de.json'; -import en from './en.json'; -import es from './es.json'; -import fr from './fr.json'; -import it from './it.json'; -import ja from './ja.json'; -import ko from './ko.json'; -import nl from './nl.json'; -import pl from './pl.json'; -import ptBR from './pt-BR.json'; -import pt from './pt.json'; -import ru from './ru.json'; -import tr from './tr.json'; -import vi from './vi.json'; -import zhHans from './zh-Hans.json'; -import zh from './zh.json'; -import sk from './sk.json'; - -const trads = { - ar, - cs, - de, - en, - es, - fr, - it, - ja, - ko, - nl, - pl, - 'pt-BR': ptBR, - pt, - ru, - tr, - vi, - 'zh-Hans': zhHans, - zh, - sk, -}; - -export default trads; diff --git a/packages/strapi-plugin-email/admin/src/translations/it.json b/packages/strapi-plugin-email/admin/src/translations/it.json deleted file mode 100644 index 3487a2e976..0000000000 --- a/packages/strapi-plugin-email/admin/src/translations/it.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "ConfigPage.description": "Configura il plugin Email", - "ConfigPage.title": "Email - Impostazioni", - "EditForm.Input.number.label": "Dimensione massima consentita (in MB)", - "EditForm.Input.select.inputDescription": "Le e-mail possono essere inviate con il provider predefinito (Sendmail) o un provider esterno", - "EditForm.Input.select.label": "Providers", - "EditForm.Input.toggle.label": "Abilita invio email", - "notification.config.success": "Le impostazioni sono state aggiornate", - "plugin.description.long": "Invia le email.", - "plugin.description.short": "Invia le email." -} \ No newline at end of file diff --git a/packages/strapi-plugin-email/admin/src/translations/ja.json b/packages/strapi-plugin-email/admin/src/translations/ja.json deleted file mode 100644 index ab5972a2c7..0000000000 --- a/packages/strapi-plugin-email/admin/src/translations/ja.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "ConfigPage.description": "Eメールプラグインを設定する", - "ConfigPage.title": "Eメール - 設定", - "EditForm.Input.number.label": "許可される最大サイズ(MB単位)", - "EditForm.Input.select.inputDescription": "電子メールは、デフォルトのプロバイダ(Sendmail)または外部プロバイダ", - "EditForm.Input.select.label": "プロバイダー", - "EditForm.Input.toggle.label": "メール送信を有効にする", - "notification.config.success": "設定が更新されました", - "plugin.description.long": "メールを送る", - "plugin.description.short": "メールを送る" -} \ No newline at end of file diff --git a/packages/strapi-plugin-email/admin/src/translations/ko.json b/packages/strapi-plugin-email/admin/src/translations/ko.json deleted file mode 100644 index b35b92d1f6..0000000000 --- a/packages/strapi-plugin-email/admin/src/translations/ko.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "ConfigPage.description": "이메일 플러그인을 설정합니다.", - "ConfigPage.title": "이메일 설정", - "EditForm.Input.number.label": "최대 허용 크기(MB)", - "EditForm.Input.select.inputDescription": "이메일을 기본 프로바이더(Sendmail) 또는 외부 프로바이더를 통해 전동합니다.", - "EditForm.Input.select.label": "프로바이더(Providers)", - "EditForm.Input.toggle.label": "이메일 전송 허용", - "notification.config.success": "설정을 업데이트 했습니다.", - "plugin.description.long": "이메일을 전송합니다.", - "plugin.description.short": "이메일을 전송합니다." -} \ No newline at end of file diff --git a/packages/strapi-plugin-email/admin/src/translations/nl.json b/packages/strapi-plugin-email/admin/src/translations/nl.json deleted file mode 100644 index 1e25ffbcad..0000000000 --- a/packages/strapi-plugin-email/admin/src/translations/nl.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "ConfigPage.description": "Configureer de e-mail extensie", - "ConfigPage.title": "E-mail - Instellingen", - "EditForm.Input.number.label": "Maximum grootte toegestaan (in MB)", - "EditForm.Input.select.inputDescription": "E-mails kunnen worden verstuurd via de standaard leverancier (Sendmail) of via een externe leverancier", - "EditForm.Input.select.label": "Leveranciers", - "EditForm.Input.toggle.label": "E-mail versturen inschakelen", - "notification.config.success": "De instellingen zijn opgeslagen.", - "plugin.description.long": "Verstuur e-mails.", - "plugin.description.short": "Verstuur e-mails." -} \ No newline at end of file diff --git a/packages/strapi-plugin-email/admin/src/translations/pl.json b/packages/strapi-plugin-email/admin/src/translations/pl.json deleted file mode 100644 index 5cd502ecb9..0000000000 --- a/packages/strapi-plugin-email/admin/src/translations/pl.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "ConfigPage.description": "Skonfiguruj plugin email", - "ConfigPage.title": "Email - Ustawienia", - "EditForm.Input.number.label": "Maksymalny dozwolony rozmiar (w MB)", - "EditForm.Input.select.inputDescription": "E-maile mogą być wysyłane z wykorzystaniem domyślnego (Sendmail) albo zewnętrznego dostawcy", - "EditForm.Input.select.label": "Dostawcy", - "EditForm.Input.toggle.label": "Włącz wysyłkę e-maili", - "notification.config.success": "Ustawienia zostały zaktualizowane", - "plugin.description.long": "Wysyłaj E-maile", - "plugin.description.short": "Wysyłaj E-maile" -} diff --git a/packages/strapi-plugin-email/admin/src/translations/pt-BR.json b/packages/strapi-plugin-email/admin/src/translations/pt-BR.json deleted file mode 100644 index bc472b448c..0000000000 --- a/packages/strapi-plugin-email/admin/src/translations/pt-BR.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "ConfigPage.description": "Configure a extensão do email", - "ConfigPage.title": "E-mail - Definições", - "EditForm.Input.number.label": "Tamanho máximo permitido (em MB)", - "EditForm.Input.select.inputDescription": "Os emails podem ser enviados com o provedor predefinido (Sendmail) ou por um provedor externo", - "EditForm.Input.select.label": "Provedores", - "EditForm.Input.toggle.label": "Ativar envio de email", - "notification.config.success": "As configurações foram atualizadas", - "plugin.description.long": "Enviar emails.", - "plugin.description.short": "Enviar emails." -} \ No newline at end of file diff --git a/packages/strapi-plugin-email/admin/src/translations/pt.json b/packages/strapi-plugin-email/admin/src/translations/pt.json deleted file mode 100644 index dd3213d2e3..0000000000 --- a/packages/strapi-plugin-email/admin/src/translations/pt.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "ConfigPage.description": "Configure a extensão do email", - "ConfigPage.title": "Email - Definições", - "EditForm.Input.number.label": "Tamanho máximo permitido (em MB)", - "EditForm.Input.select.inputDescription": "Os emails podem ser enviados com o provedor predefinido (Sendmail) ou por um provedor externo", - "EditForm.Input.select.label": "Provedores", - "EditForm.Input.toggle.label": "Activar envio de email", - "notification.config.success": "As configurações foram actualizadas", - "plugin.description.long": "Enviar emails.", - "plugin.description.short": "Enviar emails." -} \ No newline at end of file diff --git a/packages/strapi-plugin-email/admin/src/translations/ru.json b/packages/strapi-plugin-email/admin/src/translations/ru.json deleted file mode 100644 index 80f16edb2e..0000000000 --- a/packages/strapi-plugin-email/admin/src/translations/ru.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "ConfigPage.description": "Настройка плагина email", - "ConfigPage.title": "Email - Настройки", - "EditForm.Input.number.label": "Максимально допустимый размер (в МБ)", - "EditForm.Input.select.inputDescription": "Письма могут быть отправлены стандартным способом (Sendmail) или с помощью внешних провайдеров", - "EditForm.Input.select.label": "Провайдеры", - "EditForm.Input.toggle.label": "Активировать отправку писем", - "notification.config.success": "Настройки успешно обновлены", - "plugin.description.long": "Отправка почты.", - "plugin.description.short": "Отправка почты." -} diff --git a/packages/strapi-plugin-email/admin/src/translations/sk.json b/packages/strapi-plugin-email/admin/src/translations/sk.json deleted file mode 100644 index b369729538..0000000000 --- a/packages/strapi-plugin-email/admin/src/translations/sk.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "ConfigPage.description": "Nastavenia odosielania e-mailov", - "ConfigPage.title": "Email - Nastavenia", - "EditForm.Input.number.label": "Maximálna povolená veľkosť (v MB)", - "EditForm.Input.select.inputDescription": "E-maily môžu byť posielané cez Sendmail alebo externého poskytovateľa", - "EditForm.Input.select.label": "Poskytovatelia", - "EditForm.Input.toggle.label": "Povoliť odosielanie emailov", - "notification.config.success": "Nastavenia boli upravené", - "plugin.description.long": "Posielanie e-mailov.", - "plugin.description.short": "Posielanie e-mailov." -} \ No newline at end of file diff --git a/packages/strapi-plugin-email/admin/src/translations/tr.json b/packages/strapi-plugin-email/admin/src/translations/tr.json deleted file mode 100644 index 0306a093d1..0000000000 --- a/packages/strapi-plugin-email/admin/src/translations/tr.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "ConfigPage.description": "E-posta eklentisini yapılandırma", - "ConfigPage.title": "E-posta - Ayarlar", - "EditForm.Input.number.label": "İzin verilen maksimum boyut (MB cinsinden)", - "EditForm.Input.select.inputDescription": "E-postalar varsayılan sağlayıcı (Sendmail) veya harici bir sağlayıcıyla gönderilebilir", - "EditForm.Input.select.label": "Sağlayıcıları", - "EditForm.Input.toggle.label": "E-posta gönderimini etkinleştir", - "notification.config.success": "Ayarlar güncellendi", - "plugin.description.long": "E-posta gönder.", - "plugin.description.short": "E-posta gönder." -} \ No newline at end of file diff --git a/packages/strapi-plugin-email/admin/src/translations/vi.json b/packages/strapi-plugin-email/admin/src/translations/vi.json deleted file mode 100644 index f36cdf7669..0000000000 --- a/packages/strapi-plugin-email/admin/src/translations/vi.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "ConfigPage.description": "Cấu hình email plugin", - "ConfigPage.title": "Email - Các cài đặt", - "EditForm.Input.number.label": "Kích thước tối đa được phép (MB)", - "EditForm.Input.select.inputDescription": "Các Email có thể được gửi với nhà cung cấp mặc định (Sendmail) hoặc là nhà cung cấp bên ngoài", - "EditForm.Input.select.label": "Các nhà cung cấp", - "EditForm.Input.toggle.label": "Kích hoạt gửi email", - "notification.config.success": "Các cài đặt đã được cập nhật", - "plugin.description.long": "Gửi các email.", - "plugin.description.short": "Gửi các email." -} \ No newline at end of file diff --git a/packages/strapi-plugin-email/admin/src/translations/zh-Hans.json b/packages/strapi-plugin-email/admin/src/translations/zh-Hans.json deleted file mode 100644 index c4ad1d2d8e..0000000000 --- a/packages/strapi-plugin-email/admin/src/translations/zh-Hans.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "ConfigPage.description": "配置电子邮件插件", - "ConfigPage.title": "电子邮件 - 设置", - "EditForm.Input.number.label": "最大文件限制 (单位:MB)", - "EditForm.Input.select.inputDescription": "可以使用默认提供商(Sendmail)或外部提供商发送电子邮件", - "EditForm.Input.select.label": "提供商", - "EditForm.Input.toggle.label": "启用电子邮件发送", - "notification.config.success": "设置已更新", - "plugin.description.long": "发送电子邮件。", - "plugin.description.short": "发送电子邮件。" -} \ No newline at end of file diff --git a/packages/strapi-plugin-email/admin/src/translations/zh.json b/packages/strapi-plugin-email/admin/src/translations/zh.json deleted file mode 100644 index d9101fd955..0000000000 --- a/packages/strapi-plugin-email/admin/src/translations/zh.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "ConfigPage.description": "設定郵件擴充功能", - "ConfigPage.title": "郵件 - 設定", - "EditForm.Input.number.label": "最大大小 (MB)", - "EditForm.Input.select.inputDescription": "可以使用預設 (Sendmail) 或其他套件寄送郵件", - "EditForm.Input.select.label": "套件", - "EditForm.Input.toggle.label": "啟動寄信功能", - "notification.config.success": "設定已經更新", - "plugin.description.long": "寄送電子郵件", - "plugin.description.short": "寄送電子郵件" -} \ No newline at end of file From 4395f72df51d63cf0dc412e1fde4a1fe967f8a58 Mon Sep 17 00:00:00 2001 From: soupette Date: Thu, 14 May 2020 01:54:36 +0200 Subject: [PATCH 03/14] Add email plugin description Signed-off-by: soupette --- .../strapi-plugin-email/admin/src/index.js | 3 +- .../admin/src/translations/ar.json | 4 ++ .../admin/src/translations/cs.json | 4 ++ .../admin/src/translations/de.json | 4 ++ .../admin/src/translations/en.json | 4 ++ .../admin/src/translations/es.json | 4 ++ .../admin/src/translations/fr.json | 4 ++ .../admin/src/translations/index.js | 43 +++++++++++++++++++ .../admin/src/translations/it.json | 4 ++ .../admin/src/translations/ja.json | 4 ++ .../admin/src/translations/ko.json | 4 ++ .../admin/src/translations/nl.json | 4 ++ .../admin/src/translations/pl.json | 4 ++ .../admin/src/translations/pt-BR.json | 4 ++ .../admin/src/translations/pt.json | 4 ++ .../admin/src/translations/ru.json | 4 ++ .../admin/src/translations/sk.json | 4 ++ .../admin/src/translations/tr.json | 4 ++ .../admin/src/translations/vi.json | 4 ++ .../admin/src/translations/zh-Hans.json | 4 ++ .../admin/src/translations/zh.json | 4 ++ 21 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 packages/strapi-plugin-email/admin/src/translations/ar.json create mode 100644 packages/strapi-plugin-email/admin/src/translations/cs.json create mode 100644 packages/strapi-plugin-email/admin/src/translations/de.json create mode 100644 packages/strapi-plugin-email/admin/src/translations/en.json create mode 100644 packages/strapi-plugin-email/admin/src/translations/es.json create mode 100644 packages/strapi-plugin-email/admin/src/translations/fr.json create mode 100644 packages/strapi-plugin-email/admin/src/translations/index.js create mode 100644 packages/strapi-plugin-email/admin/src/translations/it.json create mode 100644 packages/strapi-plugin-email/admin/src/translations/ja.json create mode 100644 packages/strapi-plugin-email/admin/src/translations/ko.json create mode 100644 packages/strapi-plugin-email/admin/src/translations/nl.json create mode 100644 packages/strapi-plugin-email/admin/src/translations/pl.json create mode 100644 packages/strapi-plugin-email/admin/src/translations/pt-BR.json create mode 100644 packages/strapi-plugin-email/admin/src/translations/pt.json create mode 100644 packages/strapi-plugin-email/admin/src/translations/ru.json create mode 100644 packages/strapi-plugin-email/admin/src/translations/sk.json create mode 100644 packages/strapi-plugin-email/admin/src/translations/tr.json create mode 100644 packages/strapi-plugin-email/admin/src/translations/vi.json create mode 100644 packages/strapi-plugin-email/admin/src/translations/zh-Hans.json create mode 100644 packages/strapi-plugin-email/admin/src/translations/zh.json diff --git a/packages/strapi-plugin-email/admin/src/index.js b/packages/strapi-plugin-email/admin/src/index.js index 2cd8f6ce12..96f3a98c42 100644 --- a/packages/strapi-plugin-email/admin/src/index.js +++ b/packages/strapi-plugin-email/admin/src/index.js @@ -8,6 +8,7 @@ import pluginPkg from '../../package.json'; import pluginId from './pluginId'; import pluginLogo from './assets/images/logo.svg'; +import trads from './translations'; export default strapi => { const pluginDescription = pluginPkg.strapi.description || pluginPkg.description; @@ -30,7 +31,7 @@ export default strapi => { name: pluginPkg.strapi.name, pluginLogo, preventComponentRendering: false, - trads: {}, + trads, }; return strapi.registerPlugin(plugin); diff --git a/packages/strapi-plugin-email/admin/src/translations/ar.json b/packages/strapi-plugin-email/admin/src/translations/ar.json new file mode 100644 index 0000000000..4aa9cc3237 --- /dev/null +++ b/packages/strapi-plugin-email/admin/src/translations/ar.json @@ -0,0 +1,4 @@ +{ + "plugin.description.long": "إرسال بريد.", + "plugin.description.short": "إرسال بريد." +} \ No newline at end of file diff --git a/packages/strapi-plugin-email/admin/src/translations/cs.json b/packages/strapi-plugin-email/admin/src/translations/cs.json new file mode 100644 index 0000000000..08d24ce7ac --- /dev/null +++ b/packages/strapi-plugin-email/admin/src/translations/cs.json @@ -0,0 +1,4 @@ +{ + "plugin.description.long": "Odeslat e-maily.", + "plugin.description.short": "Odeslat e-maily." +} diff --git a/packages/strapi-plugin-email/admin/src/translations/de.json b/packages/strapi-plugin-email/admin/src/translations/de.json new file mode 100644 index 0000000000..f623cb6ec1 --- /dev/null +++ b/packages/strapi-plugin-email/admin/src/translations/de.json @@ -0,0 +1,4 @@ +{ + "plugin.description.long": "Zum Versand von E-Mails.", + "plugin.description.short": "Zum Versand von E-Mails." +} diff --git a/packages/strapi-plugin-email/admin/src/translations/en.json b/packages/strapi-plugin-email/admin/src/translations/en.json new file mode 100644 index 0000000000..e8306274ff --- /dev/null +++ b/packages/strapi-plugin-email/admin/src/translations/en.json @@ -0,0 +1,4 @@ +{ + "plugin.description.long": "Send emails.", + "plugin.description.short": "Send emails." +} diff --git a/packages/strapi-plugin-email/admin/src/translations/es.json b/packages/strapi-plugin-email/admin/src/translations/es.json new file mode 100644 index 0000000000..59f646b7eb --- /dev/null +++ b/packages/strapi-plugin-email/admin/src/translations/es.json @@ -0,0 +1,4 @@ +{ + "plugin.description.long": "Enviar correos electrónicos.", + "plugin.description.short": "Enviar correos electrónicos." +} diff --git a/packages/strapi-plugin-email/admin/src/translations/fr.json b/packages/strapi-plugin-email/admin/src/translations/fr.json new file mode 100644 index 0000000000..13770c40ed --- /dev/null +++ b/packages/strapi-plugin-email/admin/src/translations/fr.json @@ -0,0 +1,4 @@ +{ + "plugin.description.long": "Envoyez des emails", + "plugin.description.short": "Envoyez des emails" +} diff --git a/packages/strapi-plugin-email/admin/src/translations/index.js b/packages/strapi-plugin-email/admin/src/translations/index.js new file mode 100644 index 0000000000..ad81cf9323 --- /dev/null +++ b/packages/strapi-plugin-email/admin/src/translations/index.js @@ -0,0 +1,43 @@ +import ar from './ar.json'; +import cs from './cs.json'; +import de from './de.json'; +import en from './en.json'; +import es from './es.json'; +import fr from './fr.json'; +import it from './it.json'; +import ja from './ja.json'; +import ko from './ko.json'; +import nl from './nl.json'; +import pl from './pl.json'; +import ptBR from './pt-BR.json'; +import pt from './pt.json'; +import ru from './ru.json'; +import tr from './tr.json'; +import vi from './vi.json'; +import zhHans from './zh-Hans.json'; +import zh from './zh.json'; +import sk from './sk.json'; + +const trads = { + ar, + cs, + de, + en, + es, + fr, + it, + ja, + ko, + nl, + pl, + 'pt-BR': ptBR, + pt, + ru, + tr, + vi, + 'zh-Hans': zhHans, + zh, + sk, +}; + +export default trads; diff --git a/packages/strapi-plugin-email/admin/src/translations/it.json b/packages/strapi-plugin-email/admin/src/translations/it.json new file mode 100644 index 0000000000..ca9b88ba9c --- /dev/null +++ b/packages/strapi-plugin-email/admin/src/translations/it.json @@ -0,0 +1,4 @@ +{ + "plugin.description.long": "Invia le email.", + "plugin.description.short": "Invia le email." +} diff --git a/packages/strapi-plugin-email/admin/src/translations/ja.json b/packages/strapi-plugin-email/admin/src/translations/ja.json new file mode 100644 index 0000000000..2a0e05e63a --- /dev/null +++ b/packages/strapi-plugin-email/admin/src/translations/ja.json @@ -0,0 +1,4 @@ +{ + "plugin.description.long": "メールを送る", + "plugin.description.short": "メールを送る" +} diff --git a/packages/strapi-plugin-email/admin/src/translations/ko.json b/packages/strapi-plugin-email/admin/src/translations/ko.json new file mode 100644 index 0000000000..98cf6de4ac --- /dev/null +++ b/packages/strapi-plugin-email/admin/src/translations/ko.json @@ -0,0 +1,4 @@ +{ + "plugin.description.long": "이메일을 전송합니다.", + "plugin.description.short": "이메일을 전송합니다." +} diff --git a/packages/strapi-plugin-email/admin/src/translations/nl.json b/packages/strapi-plugin-email/admin/src/translations/nl.json new file mode 100644 index 0000000000..511cbe9217 --- /dev/null +++ b/packages/strapi-plugin-email/admin/src/translations/nl.json @@ -0,0 +1,4 @@ +{ + "plugin.description.long": "Verstuur e-mails.", + "plugin.description.short": "Verstuur e-mails." +} diff --git a/packages/strapi-plugin-email/admin/src/translations/pl.json b/packages/strapi-plugin-email/admin/src/translations/pl.json new file mode 100644 index 0000000000..a1e773f0ed --- /dev/null +++ b/packages/strapi-plugin-email/admin/src/translations/pl.json @@ -0,0 +1,4 @@ +{ + "plugin.description.long": "Wysyłaj E-maile", + "plugin.description.short": "Wysyłaj E-maile" +} diff --git a/packages/strapi-plugin-email/admin/src/translations/pt-BR.json b/packages/strapi-plugin-email/admin/src/translations/pt-BR.json new file mode 100644 index 0000000000..3635948105 --- /dev/null +++ b/packages/strapi-plugin-email/admin/src/translations/pt-BR.json @@ -0,0 +1,4 @@ +{ + "plugin.description.long": "Enviar emails.", + "plugin.description.short": "Enviar emails." +} diff --git a/packages/strapi-plugin-email/admin/src/translations/pt.json b/packages/strapi-plugin-email/admin/src/translations/pt.json new file mode 100644 index 0000000000..3635948105 --- /dev/null +++ b/packages/strapi-plugin-email/admin/src/translations/pt.json @@ -0,0 +1,4 @@ +{ + "plugin.description.long": "Enviar emails.", + "plugin.description.short": "Enviar emails." +} diff --git a/packages/strapi-plugin-email/admin/src/translations/ru.json b/packages/strapi-plugin-email/admin/src/translations/ru.json new file mode 100644 index 0000000000..e5478c6da0 --- /dev/null +++ b/packages/strapi-plugin-email/admin/src/translations/ru.json @@ -0,0 +1,4 @@ +{ + "plugin.description.long": "Отправка почты.", + "plugin.description.short": "Отправка почты." +} diff --git a/packages/strapi-plugin-email/admin/src/translations/sk.json b/packages/strapi-plugin-email/admin/src/translations/sk.json new file mode 100644 index 0000000000..beefc1d6c2 --- /dev/null +++ b/packages/strapi-plugin-email/admin/src/translations/sk.json @@ -0,0 +1,4 @@ +{ + "plugin.description.long": "Posielanie e-mailov.", + "plugin.description.short": "Posielanie e-mailov." +} diff --git a/packages/strapi-plugin-email/admin/src/translations/tr.json b/packages/strapi-plugin-email/admin/src/translations/tr.json new file mode 100644 index 0000000000..859a50587a --- /dev/null +++ b/packages/strapi-plugin-email/admin/src/translations/tr.json @@ -0,0 +1,4 @@ +{ + "plugin.description.long": "E-posta gönder.", + "plugin.description.short": "E-posta gönder." +} diff --git a/packages/strapi-plugin-email/admin/src/translations/vi.json b/packages/strapi-plugin-email/admin/src/translations/vi.json new file mode 100644 index 0000000000..0ae7e6b925 --- /dev/null +++ b/packages/strapi-plugin-email/admin/src/translations/vi.json @@ -0,0 +1,4 @@ +{ + "plugin.description.long": "Gửi các email.", + "plugin.description.short": "Gửi các email." +} diff --git a/packages/strapi-plugin-email/admin/src/translations/zh-Hans.json b/packages/strapi-plugin-email/admin/src/translations/zh-Hans.json new file mode 100644 index 0000000000..9842d4937c --- /dev/null +++ b/packages/strapi-plugin-email/admin/src/translations/zh-Hans.json @@ -0,0 +1,4 @@ +{ + "plugin.description.long": "发送电子邮件。", + "plugin.description.short": "发送电子邮件。" +} diff --git a/packages/strapi-plugin-email/admin/src/translations/zh.json b/packages/strapi-plugin-email/admin/src/translations/zh.json new file mode 100644 index 0000000000..fbcb019336 --- /dev/null +++ b/packages/strapi-plugin-email/admin/src/translations/zh.json @@ -0,0 +1,4 @@ +{ + "plugin.description.long": "寄送電子郵件", + "plugin.description.short": "寄送電子郵件" +} From 471d9ef89cb48f405e692b575c94203623b8f203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20No=C3=ABl?= Date: Thu, 14 May 2020 11:26:19 +0200 Subject: [PATCH 04/14] move email settings from db to files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Noël --- docs/3.0.0-beta.x/plugins/email.md | 2 + examples/getstarted/config/plugins.js | 7 ++ packages/strapi-admin/controllers/Auth.js | 12 +--- .../config/functions/bootstrap.js | 52 ++++---------- .../strapi-plugin-email/config/routes.json | 24 ------- .../strapi-plugin-email/controllers/Email.js | 47 +------------ .../1.0.0/overrides/email-Email.json | 19 ++++-- .../strapi-plugin-email/services/Email.js | 68 ++----------------- .../lib/index.js | 37 ++-------- .../lib/index.js | 48 ++++--------- .../lib/index.js | 32 ++------- .../lib/index.js | 24 +------ .../package.json | 2 +- yarn.lock | 2 +- 14 files changed, 74 insertions(+), 302 deletions(-) diff --git a/docs/3.0.0-beta.x/plugins/email.md b/docs/3.0.0-beta.x/plugins/email.md index fd440bd3c0..a142801786 100644 --- a/docs/3.0.0-beta.x/plugins/email.md +++ b/docs/3.0.0-beta.x/plugins/email.md @@ -11,6 +11,8 @@ By using the following function, strapi will use the configured provider to send await strapi.plugins['email'].services.email.send({ to: 'paulbocuse@strapi.io', from: 'joelrobuchon@strapi.io', + cc: 'lauralumale@strapi.io', + bcc: 'arthurpapailhau@strapi.io', replyTo: 'no-reply@strapi.io', subject: 'Use strapi email provider successfully', text: 'Hello world!', diff --git a/examples/getstarted/config/plugins.js b/examples/getstarted/config/plugins.js index 7d573a4302..b149020dba 100644 --- a/examples/getstarted/config/plugins.js +++ b/examples/getstarted/config/plugins.js @@ -3,4 +3,11 @@ module.exports = { amountLimit: 5, depthLimit: 10, }, + email: { + provider: { + name: 'mailgun', + defaultFrom: '', + defaultReplyTo: '', + }, + }, }; diff --git a/packages/strapi-admin/controllers/Auth.js b/packages/strapi-admin/controllers/Auth.js index eff1d77af9..9117478336 100644 --- a/packages/strapi-admin/controllers/Auth.js +++ b/packages/strapi-admin/controllers/Auth.js @@ -316,11 +316,6 @@ module.exports = { const resetPasswordToken = crypto.randomBytes(64).toString('hex'); const settings = { - from: { - name: 'Administration Panel', - email: 'no-reply@strapi.io', - }, - response_email: '', object: 'Reset password', message: `

We heard that you lost your password. Sorry about that!

@@ -335,12 +330,7 @@ module.exports = { // Send an email to the admin. await strapi.plugins['email'].services.email.send({ to: admin.email, - from: - settings.from.email || settings.from.name - ? `${settings.from.name} <${settings.from.email}>` - : undefined, - replyTo: settings.response_email, - subject: settings.object, + subject: 'Reset password', text: settings.message, html: settings.message, }); diff --git a/packages/strapi-plugin-email/config/functions/bootstrap.js b/packages/strapi-plugin-email/config/functions/bootstrap.js index b12522a575..fc9a6c4303 100644 --- a/packages/strapi-plugin-email/config/functions/bootstrap.js +++ b/packages/strapi-plugin-email/config/functions/bootstrap.js @@ -1,44 +1,22 @@ 'use strict'; -/** - * An asynchronous bootstrap function that runs before - * your application gets started. - * - * This gives you an opportunity to set up your data model, - * run jobs, or perform some special logic. - */ const _ = require('lodash'); -module.exports = async () => { - // set plugin store - const pluginStore = strapi.store({ - environment: strapi.config.environment, - type: 'plugin', - name: 'email', - }); +const createProvider = providerConfig => { + const providerName = _.toLower(providerConfig.name); + try { + const providerInstance = require(`strapi-provider-email-${providerName}`).init(providerConfig); - strapi.plugins.email.config.providers = []; - - const installedProviders = Object.keys(strapi.config.info.dependencies) - .filter(d => d.includes('strapi-provider-email-')) - .concat('strapi-provider-email-sendmail'); - - for (let installedProvider of _.uniq(installedProviders)) { - strapi.plugins.email.config.providers.push(require(installedProvider)); - } - - // if provider config does not exist set one by default - const config = await pluginStore.get({ key: 'provider' }); - - if (!config) { - const provider = _.find(strapi.plugins.email.config.providers, { - provider: 'sendmail', - }); - - const value = _.assign({}, provider, { - // TODO: set other default settings here - }); - - await pluginStore.set({ key: 'provider', value }); + return providerInstance; + } catch (err) { + strapi.log.error(err); + throw new Error( + `The provider package isn't installed. Please run \`npm install strapi-provider-email-${providerName}\`` + ); } }; + +module.exports = async () => { + const providerConfig = _.get(strapi.plugins, 'email.config.provider', {}); + strapi.plugins.email.provider = createProvider(providerConfig); +}; diff --git a/packages/strapi-plugin-email/config/routes.json b/packages/strapi-plugin-email/config/routes.json index 1362cf7d0a..ae167a7680 100644 --- a/packages/strapi-plugin-email/config/routes.json +++ b/packages/strapi-plugin-email/config/routes.json @@ -12,30 +12,6 @@ "name": "Email" } } - }, - { - "method": "GET", - "path": "/environments", - "handler": "Email.getEnvironments", - "config": { - "policies": [] - } - }, - { - "method": "GET", - "path": "/settings/:environment", - "handler": "Email.getSettings", - "config": { - "policies": [] - } - }, - { - "method": "PUT", - "path": "/settings/:environment", - "handler": "Email.updateSettings", - "config": { - "policies": [] - } } ] } diff --git a/packages/strapi-plugin-email/controllers/Email.js b/packages/strapi-plugin-email/controllers/Email.js index 62e163f463..9a6bad64af 100644 --- a/packages/strapi-plugin-email/controllers/Email.js +++ b/packages/strapi-plugin-email/controllers/Email.js @@ -7,17 +7,8 @@ */ module.exports = { send: async ctx => { - // Retrieve provider configuration. - const config = await strapi - .store({ - environment: strapi.config.environment, - type: 'plugin', - name: 'email', - }) - .get({ key: 'provider' }); - // Verify if the file email is enable. - if (config.enabled === false) { + if (strapi.plugins.email.enabled === false) { strapi.log.error('Email is disabled'); return ctx.badRequest(null, [ { @@ -33,43 +24,9 @@ module.exports = { let options = ctx.request.body; - await strapi.plugins.email.services.email.send(options, config); + await strapi.plugins.email.services.email.send(options); // Send 200 `ok` ctx.send({}); }, - - getEnvironments: async ctx => { - const envs = ['development', 'staging', 'production']; - - ctx.send({ - environments: envs.map(env => ({ - name: env, - active: env === strapi.config.environment, - })), - }); - }, - - getSettings: async ctx => { - let config = await strapi.plugins.email.services.email.getProviderConfig( - ctx.params.environment - ); - - ctx.send({ - providers: strapi.plugins.email.config.providers, - config, - }); - }, - - updateSettings: async ctx => { - await strapi - .store({ - environment: ctx.params.environment, - type: 'plugin', - name: 'email', - }) - .set({ key: 'provider', value: ctx.request.body }); - - ctx.send({ ok: true }); - }, }; diff --git a/packages/strapi-plugin-email/documentation/1.0.0/overrides/email-Email.json b/packages/strapi-plugin-email/documentation/1.0.0/overrides/email-Email.json index a7a7a7e452..397c733296 100644 --- a/packages/strapi-plugin-email/documentation/1.0.0/overrides/email-Email.json +++ b/packages/strapi-plugin-email/documentation/1.0.0/overrides/email-Email.json @@ -3,7 +3,7 @@ "/email/": { "post": { "deprecated": false, - "description": "Send an email using the provider defined through the dashboard", + "description": "Send an email", "requestBody": { "content": { "application/json": { @@ -17,11 +17,22 @@ "to": { "type": "string", "format": "email", - "example": "user@example.com" + "example": "user1@example.com" }, - "reply_to": { + "cc": { + "type": "string", + "format": "email", + "example": "user2@example.com" + }, + "bcc": { + "type": "string", + "format": "email", + "example": "user3@example.com" + }, + "replyTo": { "type": "string", "format": "email" + "example": "user4@example.com" }, "subject": { "type": "string", @@ -53,4 +64,4 @@ "name": "Email" } ] -} \ No newline at end of file +} diff --git a/packages/strapi-plugin-email/services/Email.js b/packages/strapi-plugin-email/services/Email.js index df9d912aff..57585023e9 100644 --- a/packages/strapi-plugin-email/services/Email.js +++ b/packages/strapi-plugin-email/services/Email.js @@ -1,72 +1,12 @@ 'use strict'; -/** - * Email.js service - * - * @description: A set of functions similar to controller's actions to avoid code duplication. - */ - -const _ = require('lodash'); - -const createDefaultEnvConfig = async env => { - const pluginStore = strapi.store({ - environment: env, - type: 'plugin', - name: 'email', - }); - - const provider = _.find(strapi.plugins.email.config.providers, { - provider: 'sendmail', - }); - const value = _.assign({}, provider, {}); - - await pluginStore.set({ key: 'provider', value }); - return await strapi - .store({ - environment: env, - type: 'plugin', - name: 'email', - }) - .get({ key: 'provider' }); -}; - -const getProviderConfig = async env => { - let config = await strapi - .store({ - environment: env, - type: 'plugin', - name: 'email', - }) - .get({ key: 'provider' }); - - if (!config) { - config = await createDefaultEnvConfig(env); - } - - return config; +const getProviderConfig = () => { + return strapi.plugins.email.config; }; module.exports = { getProviderConfig, - async send(options, config) { - // Get email provider settings to configure the provider to use. - if (!config) { - config = await getProviderConfig(strapi.config.environment); - } - - const provider = _.find(strapi.plugins.email.config.providers, { - provider: config.provider, - }); - - if (!provider) { - throw new Error( - `The provider package isn't installed. Please run \`npm install strapi-provider-email-${config.provider}\`` - ); - } - - const actions = await provider.init(config); - - // Execute email function of the provider for all files. - return actions.send(options); + async send(options) { + return strapi.plugins.email.provider.send(options); }, }; diff --git a/packages/strapi-provider-email-amazon-ses/lib/index.js b/packages/strapi-provider-email-amazon-ses/lib/index.js index bb9dc84a18..7041ea6ccf 100644 --- a/packages/strapi-provider-email-amazon-ses/lib/index.js +++ b/packages/strapi-provider-email-amazon-ses/lib/index.js @@ -11,36 +11,11 @@ const nodeSES = require('node-ses'); /* eslint-disable no-unused-vars */ module.exports = { - provider: 'amazon-ses', - name: 'Amazon SES', - auth: { - amazon_ses_default_from: { - label: 'Default From', - type: 'text', - }, - amazon_ses_default_replyto: { - label: 'Default Reply-To', - type: 'text', - }, - amazon_ses_api_key: { - label: 'Amazon Access key ID', - type: 'text', - }, - amazon_ses_secret: { - label: 'Amazon Secret access key', - type: 'text', - }, - amazon_ses_endpoint: { - label: 'Amazon end-point uri', - type: 'text', - }, - }, - init: config => { var client = nodeSES.createClient({ - key: config.amazon_ses_api_key, - secret: config.amazon_ses_secret, - amazon: config.amazon_ses_endpoint, + key: config.apiKey, + secret: config.secret, + amazon: config.endpoint, }); return { @@ -48,14 +23,16 @@ module.exports = { return new Promise((resolve, reject) => { // Default values. options = _.isObject(options) ? options : {}; - options.from = config.amazon_ses_default_from || options.from; - options.replyTo = config.amazon_ses_default_replyto || options.replyTo; + options.from = options.from || config.defaultFrom; + options.replyTo = options.replyTo || config.defaultReplyTo; options.text = options.text || options.html; options.html = options.html || options.text; let msg = { from: options.from, to: options.to, + cc: options.cc, + bcc: options.bcc, replyTo: options.replyTo, subject: options.subject, altText: options.text, diff --git a/packages/strapi-provider-email-mailgun/lib/index.js b/packages/strapi-provider-email-mailgun/lib/index.js index 2c3af2ce5e..6152a017b7 100644 --- a/packages/strapi-provider-email-mailgun/lib/index.js +++ b/packages/strapi-provider-email-mailgun/lib/index.js @@ -11,35 +11,11 @@ const mailgunFactory = require('mailgun-js'); /* eslint-disable no-unused-vars */ module.exports = { - provider: 'mailgun', - name: 'Mailgun', - auth: { - mailgun_default_from: { - label: 'Mailgun Default From', - type: 'text', - }, - mailgun_default_replyto: { - label: 'Mailgun Default Reply-To', - type: 'text', - }, - mailgun_api_key: { - label: 'Mailgun API Key', - type: 'text', - }, - mailgun_api_host: { - label: 'Mailgun API Host', - type: 'text', - }, - mailgun_domain: { - label: 'Mailgun Domain', - type: 'text', - }, - }, init: config => { const mailgun = mailgunFactory({ - apiKey: config.mailgun_api_key, - host: config.mailgun_api_host, - domain: config.mailgun_domain, + apiKey: config.apiKey, + host: config.apiHost, + domain: config.domain, mute: false, }); @@ -50,18 +26,18 @@ module.exports = { options = isObject(options) ? options : {}; let msg = { - from: options.from || config.mailgun_default_from, + from: options.from || config.defaultFrom, to: options.to, + cc: options.cc, + bcc: options.bcc, subject: options.subject, - ...(options.text && { text: options.text }), - ...(options.html && { html: options.html }), - ...(options.template && { template: options.template }), - ...(options['h:X-Mailgun-Variables'] && { - 'h:X-Mailgun-Variables': options['h:X-Mailgun-Variables'], - }), - ...(options.attachment && { attachment: options.attachment }), + 'h:Reply-To': options.replyTo || config.defaultReplyTo, + text: options.text, + html: options.html, + template: options.template, + 'h:X-Mailgun-Variables': options['h:X-Mailgun-Variables'], + attachment: options.attachment, }; - msg['h:Reply-To'] = options.replyTo || config.mailgun_default_replyto; mailgun.messages().send(msg, function(err) { if (err) { diff --git a/packages/strapi-provider-email-sendgrid/lib/index.js b/packages/strapi-provider-email-sendgrid/lib/index.js index 383a94f5c4..d7f27acbcb 100644 --- a/packages/strapi-provider-email-sendgrid/lib/index.js +++ b/packages/strapi-provider-email-sendgrid/lib/index.js @@ -6,44 +6,22 @@ /* eslint-disable prefer-template */ // Public node modules. -const _ = require('lodash'); const sendgrid = require('@sendgrid/mail'); /* eslint-disable no-unused-vars */ module.exports = { - provider: 'sendgrid', - name: 'Sendgrid', - auth: { - sendgrid_default_from: { - label: 'Sendgrid Default From', - type: 'text', - }, - sendgrid_default_replyto: { - label: 'Sendgrid Default Reply-To', - type: 'text', - }, - sendgrid_api_key: { - label: 'Sendgrid API Key', - type: 'text', - }, - }, init: config => { - sendgrid.setApiKey(config.sendgrid_api_key); + sendgrid.setApiKey(config.apiKey); return { send: options => { return new Promise((resolve, reject) => { - // Default values. - options = _.isObject(options) ? options : {}; - options.from = options.from || config.sendgrid_default_from; - options.replyTo = options.replyTo || config.sendgrid_default_replyto; - options.text = options.text || options.html; - options.html = options.html || options.text; - let msg = { - from: options.from, + from: options.from || config.defaultFrom, to: options.to, - replyTo: options.replyTo, + cc: options.cc, + bcc: options.bcc, + replyTo: options.replyTo || config.defaultReplyTo, subject: options.subject, text: options.text, html: options.html, diff --git a/packages/strapi-provider-email-sendmail/lib/index.js b/packages/strapi-provider-email-sendmail/lib/index.js index bdb98ba3b2..998c22f70e 100644 --- a/packages/strapi-provider-email-sendmail/lib/index.js +++ b/packages/strapi-provider-email-sendmail/lib/index.js @@ -5,41 +5,21 @@ */ // Public node modules. -const _ = require('lodash'); const sendmail = require('sendmail')({ silent: true, }); /* eslint-disable no-unused-vars */ module.exports = { - provider: 'sendmail', - name: 'Sendmail', - auth: { - sendmail_default_from: { - label: 'Sendmail Default From', - type: 'text', - }, - sendmail_default_replyto: { - label: 'Sendmail Default Reply-To', - type: 'text', - }, - }, init: config => { return { send: options => { return new Promise((resolve, reject) => { - // Default values. - options = _.isObject(options) ? options : {}; - options.from = options.from || config.sendmail_default_from; - options.replyTo = options.replyTo || config.sendmail_default_replyto; - options.text = options.text || options.html; - options.html = options.html || options.text; - sendmail( { - from: options.from, + from: options.from || config.defaultFrom, to: options.to, - replyTo: options.replyTo, + replyTo: options.replyTo || config.defaultReplyTo, subject: options.subject, text: options.text, html: options.html, diff --git a/packages/strapi-provider-email-sendmail/package.json b/packages/strapi-provider-email-sendmail/package.json index 2d4227614f..d2d45bdd5f 100644 --- a/packages/strapi-provider-email-sendmail/package.json +++ b/packages/strapi-provider-email-sendmail/package.json @@ -13,7 +13,7 @@ "main": "./lib", "dependencies": { "lodash": "^4.17.11", - "sendmail": "^1.2.0" + "sendmail": "^1.6.1" }, "strapi": { "isProvider": true diff --git a/yarn.lock b/yarn.lock index bde4967788..5894f6a967 100644 --- a/yarn.lock +++ b/yarn.lock @@ -16421,7 +16421,7 @@ send@0.17.1: range-parser "~1.2.1" statuses "~1.5.0" -sendmail@^1.2.0: +sendmail@^1.6.1: version "1.6.1" resolved "https://registry.yarnpkg.com/sendmail/-/sendmail-1.6.1.tgz#6be92fb4be70d1d9ad102030aeb1e737bd512159" integrity sha512-lIhvnjSi5e5jL8wA1GPP6j2QVlx6JOEfmdn0QIfmuJdmXYGmJ375kcOU0NSm/34J+nypm4sa1AXrYE5w3uNIIA== From 0fe0f34895bb6d5e9c3d77a6f2766d014569d0f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20No=C3=ABl?= Date: Thu, 14 May 2020 16:55:08 +0200 Subject: [PATCH 05/14] update email settings configuration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Noël --- .../migration-guide-beta.19-to-beta.20.md | 2 +- docs/3.0.0-beta.x/plugins/email.md | 56 +++++++++++-------- .../README.md | 45 +++++++++++++++ .../strapi-provider-email-mailgun/README.md | 43 ++++++++++++++ .../strapi-provider-email-sendgrid/README.md | 43 +++++++++++++- .../strapi-provider-email-sendmail/README.md | 39 +++++++++++++ 6 files changed, 203 insertions(+), 25 deletions(-) diff --git a/docs/3.0.0-beta.x/migration-guide/migration-guide-beta.19-to-beta.20.md b/docs/3.0.0-beta.x/migration-guide/migration-guide-beta.19-to-beta.20.md index e171494367..42d801a0c5 100644 --- a/docs/3.0.0-beta.x/migration-guide/migration-guide-beta.19-to-beta.20.md +++ b/docs/3.0.0-beta.x/migration-guide/migration-guide-beta.19-to-beta.20.md @@ -12,7 +12,7 @@ Update your package.json accordingly: ```json { - //... + // ... "dependencies": { "strapi": "3.0.0-beta.20", "strapi-admin": "3.0.0-beta.20", diff --git a/docs/3.0.0-beta.x/plugins/email.md b/docs/3.0.0-beta.x/plugins/email.md index a142801786..2b189b45fc 100644 --- a/docs/3.0.0-beta.x/plugins/email.md +++ b/docs/3.0.0-beta.x/plugins/email.md @@ -22,15 +22,9 @@ await strapi.plugins['email'].services.email.send({ ## Configure the plugin -The plugin provides you a settings page where you can define the email provider you want to use. -You will also be able to add some configuration. +### Install the provider you want -- Click on **Plugins** in the left menu -- Click on the cog button on the **Email** plugin line - -## Install new providers - -By default Strapi provides a local email system. You might want to send email with a third party. +By default Strapi provides a local email system ([sendmail](https://www.npmjs.com/package/sendmail)). If you want to use a third party to send emails, you need to install the correct provider module. Otherwise you can skip this part and continue to [Configure your provider](#configure-your-provider). You can check all the available providers developed by the community on npmjs.org - [Providers list](https://www.npmjs.com/search?q=strapi-provider-email-) @@ -56,28 +50,44 @@ npm install strapi-provider-email-sendgrid@beta --save :::: -::: tip -If the provider is not in the mono repo, you probably don't need `@beta` depending if the creator published it with this tag or not. -::: +**Note:** If the provider is not in the mono repo, you probably don't need `@beta` depending if the creator published it with this tag or not. -Then, visit [http://localhost:1337/admin/plugins/email/configurations/development](http://localhost:1337/admin/plugins/email/configurations/development) on your web browser and configure the provider. +### Configure your provider + +After installing your provider you will need to add some settings in `config/plugins.js`. Check the README of each provider to know what configuration settings the provider needs. + +Here is an example of a configuration made for the provider [strapi-provider-email-sendgrid](https://www.npmjs.com/package/strapi-provider-email-sendgrid). + +**Path —** `./config/plugins.js`. + +```js +module.exports = ({ env }) => ({ + // ... + email: { + provider: { + name: 'sendgrid', + enabled: true, + defaultFrom: 'myemail@protonmail.com', + defaultReplyTo: 'myemail@protonmail.com', + apiKey: env('SENDGRID_API_KEY'), + }, + }, + // ... +}); +``` + +::: tip +If you're using a different provider depending on your environment, you can specify the correct configuration in `config/env/${yourEnvironment}/plugins.js`. More info here: [Environments](../concepts/configurations#environments) +::: ## Create new provider -If you want to create your own, make sure the name starts with `strapi-provider-email-` (duplicating an existing one will be easier), modify the `auth` config object and customize the `send` function. +If you want to create your own, make sure the name starts with `strapi-provider-email-` (duplicating an existing one will be easier) and customize the `send` function. Default template ```js module.exports = { - provider: 'provider-id', - name: 'display name', - auth: { - config_1: { - label: 'My Config 1', - type: 'text', - }, - }, init: config => { return { send: async options => {}, @@ -88,7 +98,7 @@ module.exports = { In the `send` function you will have access to: -- `config` that contains configurations you setup in your admin panel +- `config` that contains configurations written in `plugins.js` - `options` that contains options you send when you call the `send` function from the email plugin service To use it you will have to publish it on **npm**. @@ -149,6 +159,6 @@ Error: SMTP code:550 msg:550-5.7.1 [87.88.179.13] The IP you're using to send ma 550 5.7.1 https://support.google.com/mail/?p=NotAuthorizedError 30si2132728pjz.75 - gsmtp ``` -To fix it, I suggest you to use another email provider that uses third party to send emails. +To fix it, we suggest you to use another email provider that uses third party to send emails. When using a third party provider, you avoid having to setup a mail server on your server and get extra features such as email analytics. diff --git a/packages/strapi-provider-email-amazon-ses/README.md b/packages/strapi-provider-email-amazon-ses/README.md index 533eeed3a8..3cc4670a78 100644 --- a/packages/strapi-provider-email-amazon-ses/README.md +++ b/packages/strapi-provider-email-amazon-ses/README.md @@ -9,3 +9,48 @@ - [Strapi website](http://strapi.io/) - [Strapi community on Slack](http://slack.strapi.io) - [Strapi news on Twitter](https://twitter.com/strapijs) + +## Prerequisites + +You need to have the plugin `strapi-plugin-email` installed in you Strapi project. + +## Installation + +```bash +# using yarn +yarn add strapi-provider-email-amazon-ses + +# using npm +npm install strapi-provider-email-amazon-ses --save +``` + +## Configuration + +| Variable | Type | Description | Required | Default | +| -------------- | ----------------------- | ---------------------------------------------- | -------- | --------------------------------------- | +| name | string | The name of the provider you use | yes | | +| key | string | Api key given by Amazon SES | yes | | +| secret | string | Secret given by Amazon SES | yes | | +| enabled | boolean | Enable the possibility to send emails | no | true | +| defaultFrom | string | Sender mail address | no | undefined | +| defaultReplyTo | string \| array | Address or addresses the receiver can reply to | no | undefined | +| endpoint | string | Amazon endpoint uri | no | 'https://email.us-east-1.amazonaws.com' | + +### Example + +**Path -** `config/plugins.js` + +```js +module.exports = ({ env }) => ({ + // ... + email: { + name: 'amazon-ses', + key: env('AWS_SES_KEY'), + secret: env('AWS_SES_SECRET'), + defaultFrom: 'myemail@protonmail.com', + defaultReplyTo: 'myemail@protonmail.com', + endpoint: 'https://email.us-east-1.amazonaws.com', + }, + // ... +}); +``` diff --git a/packages/strapi-provider-email-mailgun/README.md b/packages/strapi-provider-email-mailgun/README.md index 8e9970583e..11ae9363bd 100644 --- a/packages/strapi-provider-email-mailgun/README.md +++ b/packages/strapi-provider-email-mailgun/README.md @@ -9,3 +9,46 @@ - [Strapi website](http://strapi.io/) - [Strapi community on Slack](http://slack.strapi.io) - [Strapi news on Twitter](https://twitter.com/strapijs) + +## Prerequisites + +You need to have the plugin `strapi-plugin-email` installed in you Strapi project. + +## Installation + +```bash +# using yarn +yarn add strapi-provider-email-mailgun + +# using npm +npm install strapi-provider-email-mailgun --save +``` + +## Configuration + +| Variable | Type | Description | Required | Default | +| -------------- | ----------------------- | ---------------------------------------------- | -------- | --------- | +| name | string | The name of the provider you use | yes | | +| apiKey | string | Api key given by Mailgun | yes | | +| enabled | boolean | Enable the possibility to send emails | no | true | +| defaultFrom | string | Sender mail address | no | undefined | +| defaultReplyTo | string \| array | Address or addresses the receiver can reply to | no | undefined | +| host | string | | | | +| domain | string | | | | + +### Example + +**Path -** `config/plugins.js` + +```js +module.exports = ({ env }) => ({ + // ... + email: { + name: 'mailgun', + apiKey: env('MAILGUN_API_KEY'), + defaultFrom: 'myemail@protonmail.com', + defaultReplyTo: 'myemail@protonmail.com', + }, + // ... +}); +``` diff --git a/packages/strapi-provider-email-sendgrid/README.md b/packages/strapi-provider-email-sendgrid/README.md index 6f219e1ac0..5679cd184d 100644 --- a/packages/strapi-provider-email-sendgrid/README.md +++ b/packages/strapi-provider-email-sendgrid/README.md @@ -1,4 +1,4 @@ -# strapi-provider-email-sendmail +# strapi-provider-email-sendgrid ## Resources @@ -9,3 +9,44 @@ - [Strapi website](http://strapi.io/) - [Strapi community on Slack](http://slack.strapi.io) - [Strapi news on Twitter](https://twitter.com/strapijs) + +## Prerequisites + +You need to have the plugin `strapi-plugin-email` installed in you Strapi project. + +## Installation + +```bash +# using yarn +yarn add strapi-provider-email-sendgrid + +# using npm +npm install strapi-provider-email-sendgrid --save +``` + +## Configuration + +| Variable | Type | Description | Required | Default | +| -------------- | ----------------------- | ---------------------------------------------- | -------- | --------- | +| name | string | The name of the provider you use | yes | | +| apiKey | string | Api key given by Sendgrid | yes | | +| enabled | boolean | Enable the possibility to send emails | no | true | +| defaultFrom | string | Sender mail address | no | undefined | +| defaultReplyTo | string \| array | Address or addresses the receiver can reply to | no | undefined | + +### Example + +**Path -** `config/plugins.js` + +```js +module.exports = ({ env }) => ({ + // ... + email: { + name: 'sendgrid', + apiKey: env('SENDGRID_API_KEY'), + defaultFrom: 'myemail@protonmail.com', + defaultReplyTo: 'myemail@protonmail.com', + }, + // ... +}); +``` diff --git a/packages/strapi-provider-email-sendmail/README.md b/packages/strapi-provider-email-sendmail/README.md index 6f219e1ac0..c06e319577 100644 --- a/packages/strapi-provider-email-sendmail/README.md +++ b/packages/strapi-provider-email-sendmail/README.md @@ -9,3 +9,42 @@ - [Strapi website](http://strapi.io/) - [Strapi community on Slack](http://slack.strapi.io) - [Strapi news on Twitter](https://twitter.com/strapijs) + +## Prerequisites + +You need to have the plugin `strapi-plugin-email` installed in you Strapi project. + +## Installation + +```bash +# using yarn +yarn add strapi-provider-email-sendmail + +# using npm +npm install strapi-provider-email-sendmail --save +``` + +## Configuration + +| Variable | Type | Description | Required | Default | +| -------------- | ----------------------- | ---------------------------------------------- | -------- | --------- | +| name | string | The name of the provider you use | yes | | +| enabled | boolean | Enable the possibility to send emails | no | true | +| defaultFrom | string | Sender mail address | no | undefined | +| defaultReplyTo | string \| array | Address or addresses the receiver can reply to | no | undefined | + +### Example + +**Path -** `config/plugins.js` + +```js +module.exports = ({ env }) => ({ + // ... + email: { + name: 'sendmail', + defaultFrom: 'myemail@protonmail.com', + defaultReplyTo: 'myemail@protonmail.com', + }, + // ... +}); +``` From 83f847f359cbaede76f9e911676318a031c7270b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20No=C3=ABl?= Date: Thu, 14 May 2020 18:11:24 +0200 Subject: [PATCH 06/14] change config format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Noël --- docs/3.0.0-beta.x/plugins/email.md | 7 ++--- examples/getstarted/config/plugins.js | 7 ++--- examples/getstarted/package.json | 2 +- .../config/functions/bootstrap.js | 17 +++++----- .../strapi-plugin-email/controllers/Email.js | 16 ---------- .../README.md | 31 ++++++++++--------- .../strapi-provider-email-mailgun/README.md | 27 ++++++++-------- .../strapi-provider-email-sendgrid/README.md | 23 +++++++------- .../strapi-provider-email-sendmail/README.md | 19 ++++++------ 9 files changed, 67 insertions(+), 82 deletions(-) diff --git a/docs/3.0.0-beta.x/plugins/email.md b/docs/3.0.0-beta.x/plugins/email.md index 2b189b45fc..2da4900a2c 100644 --- a/docs/3.0.0-beta.x/plugins/email.md +++ b/docs/3.0.0-beta.x/plugins/email.md @@ -64,12 +64,11 @@ Here is an example of a configuration made for the provider [strapi-provider-ema module.exports = ({ env }) => ({ // ... email: { - provider: { - name: 'sendgrid', - enabled: true, + provider: 'sendgrid', + providerOptions: { + apiKey: env('SENDGRID_API_KEY'), defaultFrom: 'myemail@protonmail.com', defaultReplyTo: 'myemail@protonmail.com', - apiKey: env('SENDGRID_API_KEY'), }, }, // ... diff --git a/examples/getstarted/config/plugins.js b/examples/getstarted/config/plugins.js index b149020dba..525132cf51 100644 --- a/examples/getstarted/config/plugins.js +++ b/examples/getstarted/config/plugins.js @@ -4,10 +4,9 @@ module.exports = { depthLimit: 10, }, email: { - provider: { - name: 'mailgun', - defaultFrom: '', - defaultReplyTo: '', + provider: 'sendmail', + providerOptions: { + defaultFrom: 'strapi@strapi.io', }, }, }; diff --git a/examples/getstarted/package.json b/examples/getstarted/package.json index da05ce7b7a..d0270cb529 100644 --- a/examples/getstarted/package.json +++ b/examples/getstarted/package.json @@ -27,7 +27,7 @@ "strapi-plugin-graphql": "3.0.0-beta.20.3", "strapi-plugin-upload": "3.0.0-beta.20.3", "strapi-plugin-users-permissions": "3.0.0-beta.20.3", - "strapi-provider-email-mailgun": "3.0.0-beta.20.3", + "strapi-provider-email-sendmail": "3.0.0-beta.20.3", "strapi-provider-upload-aws-s3": "3.0.0-beta.20.3", "strapi-provider-upload-cloudinary": "3.0.0-beta.20.3", "strapi-utils": "3.0.0-beta.20.3" diff --git a/packages/strapi-plugin-email/config/functions/bootstrap.js b/packages/strapi-plugin-email/config/functions/bootstrap.js index fc9a6c4303..00f87eb627 100644 --- a/packages/strapi-plugin-email/config/functions/bootstrap.js +++ b/packages/strapi-plugin-email/config/functions/bootstrap.js @@ -2,21 +2,20 @@ const _ = require('lodash'); -const createProvider = providerConfig => { - const providerName = _.toLower(providerConfig.name); +const createProvider = emailConfig => { + const providerName = _.toLower(emailConfig.provider); + let provider; try { - const providerInstance = require(`strapi-provider-email-${providerName}`).init(providerConfig); - - return providerInstance; + provider = require(`strapi-provider-email-${providerName}`); } catch (err) { - strapi.log.error(err); throw new Error( - `The provider package isn't installed. Please run \`npm install strapi-provider-email-${providerName}\`` + `The provider package isn't installed. Please run \`npm install strapi-provider-email-${providerName}\` --save` ); } + return provider.init(emailConfig.providerOptions); }; module.exports = async () => { - const providerConfig = _.get(strapi.plugins, 'email.config.provider', {}); - strapi.plugins.email.provider = createProvider(providerConfig); + const emailConfig = _.get(strapi.plugins, 'email.config', {}); + strapi.plugins.email.provider = createProvider(emailConfig); }; diff --git a/packages/strapi-plugin-email/controllers/Email.js b/packages/strapi-plugin-email/controllers/Email.js index 9a6bad64af..5c84829647 100644 --- a/packages/strapi-plugin-email/controllers/Email.js +++ b/packages/strapi-plugin-email/controllers/Email.js @@ -7,23 +7,7 @@ */ module.exports = { send: async ctx => { - // Verify if the file email is enable. - if (strapi.plugins.email.enabled === false) { - strapi.log.error('Email is disabled'); - return ctx.badRequest(null, [ - { - messages: [{ id: 'Email.status.disabled', message: 'Emails disabled' }], - }, - ]); - } - - // Something is wrong - if (ctx.status === 400) { - return; - } - let options = ctx.request.body; - await strapi.plugins.email.services.email.send(options); // Send 200 `ok` diff --git a/packages/strapi-provider-email-amazon-ses/README.md b/packages/strapi-provider-email-amazon-ses/README.md index 3cc4670a78..4e0a2585bd 100644 --- a/packages/strapi-provider-email-amazon-ses/README.md +++ b/packages/strapi-provider-email-amazon-ses/README.md @@ -26,15 +26,14 @@ npm install strapi-provider-email-amazon-ses --save ## Configuration -| Variable | Type | Description | Required | Default | -| -------------- | ----------------------- | ---------------------------------------------- | -------- | --------------------------------------- | -| name | string | The name of the provider you use | yes | | -| key | string | Api key given by Amazon SES | yes | | -| secret | string | Secret given by Amazon SES | yes | | -| enabled | boolean | Enable the possibility to send emails | no | true | -| defaultFrom | string | Sender mail address | no | undefined | -| defaultReplyTo | string \| array | Address or addresses the receiver can reply to | no | undefined | -| endpoint | string | Amazon endpoint uri | no | 'https://email.us-east-1.amazonaws.com' | +| Variable | Type | Description | Required | Default | +| ------------------------------ | ----------------------- | ---------------------------------------------- | -------- | --------------------------------------- | +| provider | string | The name of the provider you use | yes | | +| providerOptions.key | string | Api key given by Amazon SES | yes | | +| providerOptions.secret | string | Secret given by Amazon SES | yes | | +| providerOptions.defaultFrom | string | Sender mail address | no | undefined | +| providerOptions.defaultReplyTo | string \| array | Address or addresses the receiver can reply to | no | undefined | +| providerOptions.endpoint | string | Amazon endpoint uri | no | 'https://email.us-east-1.amazonaws.com' | ### Example @@ -44,12 +43,14 @@ npm install strapi-provider-email-amazon-ses --save module.exports = ({ env }) => ({ // ... email: { - name: 'amazon-ses', - key: env('AWS_SES_KEY'), - secret: env('AWS_SES_SECRET'), - defaultFrom: 'myemail@protonmail.com', - defaultReplyTo: 'myemail@protonmail.com', - endpoint: 'https://email.us-east-1.amazonaws.com', + provider: 'amazon-ses', + providerOptions: { + key: env('AWS_SES_KEY'), + secret: env('AWS_SES_SECRET'), + defaultFrom: 'myemail@protonmail.com', + defaultReplyTo: 'myemail@protonmail.com', + endpoint: 'https://email.us-east-1.amazonaws.com', + }, }, // ... }); diff --git a/packages/strapi-provider-email-mailgun/README.md b/packages/strapi-provider-email-mailgun/README.md index 11ae9363bd..090c81ae6e 100644 --- a/packages/strapi-provider-email-mailgun/README.md +++ b/packages/strapi-provider-email-mailgun/README.md @@ -26,15 +26,14 @@ npm install strapi-provider-email-mailgun --save ## Configuration -| Variable | Type | Description | Required | Default | -| -------------- | ----------------------- | ---------------------------------------------- | -------- | --------- | -| name | string | The name of the provider you use | yes | | -| apiKey | string | Api key given by Mailgun | yes | | -| enabled | boolean | Enable the possibility to send emails | no | true | -| defaultFrom | string | Sender mail address | no | undefined | -| defaultReplyTo | string \| array | Address or addresses the receiver can reply to | no | undefined | -| host | string | | | | -| domain | string | | | | +| Variable | Type | Description | Required | Default | +| ------------------------------ | ----------------------- | ---------------------------------------------- | -------- | --------- | +| provider | string | The name of the provider you use | yes | | +| providerOptions.apiKey | string | Api key given by Mailgun | yes | | +| providerOptions.defaultFrom | string | Sender mail address | no | undefined | +| providerOptions.defaultReplyTo | string \| array | Address or addresses the receiver can reply to | no | undefined | +| providerOptions.host | string | | | | +| providerOptions.domain | string | | | | ### Example @@ -44,10 +43,12 @@ npm install strapi-provider-email-mailgun --save module.exports = ({ env }) => ({ // ... email: { - name: 'mailgun', - apiKey: env('MAILGUN_API_KEY'), - defaultFrom: 'myemail@protonmail.com', - defaultReplyTo: 'myemail@protonmail.com', + provider: 'mailgun', + providerOptions: { + apiKey: env('MAILGUN_API_KEY'), + defaultFrom: 'myemail@protonmail.com', + defaultReplyTo: 'myemail@protonmail.com', + }, }, // ... }); diff --git a/packages/strapi-provider-email-sendgrid/README.md b/packages/strapi-provider-email-sendgrid/README.md index 5679cd184d..17daaa455e 100644 --- a/packages/strapi-provider-email-sendgrid/README.md +++ b/packages/strapi-provider-email-sendgrid/README.md @@ -26,13 +26,12 @@ npm install strapi-provider-email-sendgrid --save ## Configuration -| Variable | Type | Description | Required | Default | -| -------------- | ----------------------- | ---------------------------------------------- | -------- | --------- | -| name | string | The name of the provider you use | yes | | -| apiKey | string | Api key given by Sendgrid | yes | | -| enabled | boolean | Enable the possibility to send emails | no | true | -| defaultFrom | string | Sender mail address | no | undefined | -| defaultReplyTo | string \| array | Address or addresses the receiver can reply to | no | undefined | +| Variable | Type | Description | Required | Default | +| ------------------------------ | ----------------------- | ---------------------------------------------- | -------- | --------- | +| provider | string | The name of the provider you use | yes | | +| providerOptions.apiKey | string | Api key given by Sendgrid | yes | | +| providerOptions.defaultFrom | string | Sender mail address | no | undefined | +| providerOptions.defaultReplyTo | string \| array | Address or addresses the receiver can reply to | no | undefined | ### Example @@ -42,10 +41,12 @@ npm install strapi-provider-email-sendgrid --save module.exports = ({ env }) => ({ // ... email: { - name: 'sendgrid', - apiKey: env('SENDGRID_API_KEY'), - defaultFrom: 'myemail@protonmail.com', - defaultReplyTo: 'myemail@protonmail.com', + provider: 'sendgrid', + providerOptions: { + apiKey: env('SENDGRID_API_KEY'), + defaultFrom: 'myemail@protonmail.com', + defaultReplyTo: 'myemail@protonmail.com', + }, }, // ... }); diff --git a/packages/strapi-provider-email-sendmail/README.md b/packages/strapi-provider-email-sendmail/README.md index c06e319577..687708ff4d 100644 --- a/packages/strapi-provider-email-sendmail/README.md +++ b/packages/strapi-provider-email-sendmail/README.md @@ -26,12 +26,11 @@ npm install strapi-provider-email-sendmail --save ## Configuration -| Variable | Type | Description | Required | Default | -| -------------- | ----------------------- | ---------------------------------------------- | -------- | --------- | -| name | string | The name of the provider you use | yes | | -| enabled | boolean | Enable the possibility to send emails | no | true | -| defaultFrom | string | Sender mail address | no | undefined | -| defaultReplyTo | string \| array | Address or addresses the receiver can reply to | no | undefined | +| Variable | Type | Description | Required | Default | +| ------------------------------ | ----------------------- | ---------------------------------------------- | -------- | --------- | +| provider | string | The name of the provider you use | yes | | +| providerOptions.defaultFrom | string | Sender mail address | no | undefined | +| providerOptions.defaultReplyTo | string \| array | Address or addresses the receiver can reply to | no | undefined | ### Example @@ -41,9 +40,11 @@ npm install strapi-provider-email-sendmail --save module.exports = ({ env }) => ({ // ... email: { - name: 'sendmail', - defaultFrom: 'myemail@protonmail.com', - defaultReplyTo: 'myemail@protonmail.com', + provider: 'sendmail', + providerOptions: { + defaultFrom: 'myemail@protonmail.com', + defaultReplyTo: 'myemail@protonmail.com', + }, }, // ... }); From d8f1449e7328c3be561da5a150a461361bc0b73b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20No=C3=ABl?= Date: Fri, 15 May 2020 15:05:35 +0200 Subject: [PATCH 07/14] change config format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Noël --- docs/3.0.0-beta.x/plugins/email.md | 9 +++-- .../config/functions/bootstrap.js | 2 +- .../README.md | 19 ++++----- .../lib/index.js | 40 ++++++------------- .../strapi-provider-email-mailgun/README.md | 17 ++++---- .../lib/index.js | 37 ++++++----------- .../strapi-provider-email-sendgrid/README.md | 16 +++++--- .../lib/index.js | 34 ++++++---------- .../strapi-provider-email-sendmail/README.md | 14 ++++--- .../lib/index.js | 34 ++++++++-------- 10 files changed, 97 insertions(+), 125 deletions(-) diff --git a/docs/3.0.0-beta.x/plugins/email.md b/docs/3.0.0-beta.x/plugins/email.md index 2da4900a2c..51b4ddfcf9 100644 --- a/docs/3.0.0-beta.x/plugins/email.md +++ b/docs/3.0.0-beta.x/plugins/email.md @@ -50,8 +50,6 @@ npm install strapi-provider-email-sendgrid@beta --save :::: -**Note:** If the provider is not in the mono repo, you probably don't need `@beta` depending if the creator published it with this tag or not. - ### Configure your provider After installing your provider you will need to add some settings in `config/plugins.js`. Check the README of each provider to know what configuration settings the provider needs. @@ -67,6 +65,8 @@ module.exports = ({ env }) => ({ provider: 'sendgrid', providerOptions: { apiKey: env('SENDGRID_API_KEY'), + }, + settings: { defaultFrom: 'myemail@protonmail.com', defaultReplyTo: 'myemail@protonmail.com', }, @@ -87,7 +87,7 @@ Default template ```js module.exports = { - init: config => { + init: (providerOptions = {}, settings = {}) => { return { send: async options => {}, }; @@ -97,7 +97,8 @@ module.exports = { In the `send` function you will have access to: -- `config` that contains configurations written in `plugins.js` +- `providerOptions` that contains configurations written in `plugins.js` +- `settings` that contains configurations written in `plugins.js` - `options` that contains options you send when you call the `send` function from the email plugin service To use it you will have to publish it on **npm**. diff --git a/packages/strapi-plugin-email/config/functions/bootstrap.js b/packages/strapi-plugin-email/config/functions/bootstrap.js index 00f87eb627..44feb44541 100644 --- a/packages/strapi-plugin-email/config/functions/bootstrap.js +++ b/packages/strapi-plugin-email/config/functions/bootstrap.js @@ -12,7 +12,7 @@ const createProvider = emailConfig => { `The provider package isn't installed. Please run \`npm install strapi-provider-email-${providerName}\` --save` ); } - return provider.init(emailConfig.providerOptions); + return provider.init(emailConfig.providerOptions, emailConfig.settings); }; module.exports = async () => { diff --git a/packages/strapi-provider-email-amazon-ses/README.md b/packages/strapi-provider-email-amazon-ses/README.md index 4e0a2585bd..2361dc18bf 100644 --- a/packages/strapi-provider-email-amazon-ses/README.md +++ b/packages/strapi-provider-email-amazon-ses/README.md @@ -26,14 +26,13 @@ npm install strapi-provider-email-amazon-ses --save ## Configuration -| Variable | Type | Description | Required | Default | -| ------------------------------ | ----------------------- | ---------------------------------------------- | -------- | --------------------------------------- | -| provider | string | The name of the provider you use | yes | | -| providerOptions.key | string | Api key given by Amazon SES | yes | | -| providerOptions.secret | string | Secret given by Amazon SES | yes | | -| providerOptions.defaultFrom | string | Sender mail address | no | undefined | -| providerOptions.defaultReplyTo | string \| array | Address or addresses the receiver can reply to | no | undefined | -| providerOptions.endpoint | string | Amazon endpoint uri | no | 'https://email.us-east-1.amazonaws.com' | +| Variable | Type | Description | Required | Default | +| ----------------------- | ----------------------- | -------------------------------------------------------------------------------------------------------------------------- | -------- | --------- | +| provider | string | The name of the provider you use | yes | | +| providerOptions | object | Will be directly given to `createClient` function. Please refer to [node-ses](https://www.npmjs.com/package/node-ses) doc. | yes | | +| settings | object | Settings | no | {} | +| settings.defaultFrom | string | Default sender mail address | no | undefined | +| settings.defaultReplyTo | string \| array | Default address or addresses the receiver is asked to reply to | no | undefined | ### Example @@ -47,9 +46,11 @@ module.exports = ({ env }) => ({ providerOptions: { key: env('AWS_SES_KEY'), secret: env('AWS_SES_SECRET'), + amazon: 'https://email.us-east-1.amazonaws.com', + }, + settings: { defaultFrom: 'myemail@protonmail.com', defaultReplyTo: 'myemail@protonmail.com', - endpoint: 'https://email.us-east-1.amazonaws.com', }, }, // ... diff --git a/packages/strapi-provider-email-amazon-ses/lib/index.js b/packages/strapi-provider-email-amazon-ses/lib/index.js index 7041ea6ccf..7f430d4734 100644 --- a/packages/strapi-provider-email-amazon-ses/lib/index.js +++ b/packages/strapi-provider-email-amazon-ses/lib/index.js @@ -1,42 +1,26 @@ 'use strict'; -/** - * Module dependencies - */ - -/* eslint-disable prefer-template */ -// Public node modules. -const _ = require('lodash'); const nodeSES = require('node-ses'); -/* eslint-disable no-unused-vars */ module.exports = { - init: config => { - var client = nodeSES.createClient({ - key: config.apiKey, - secret: config.secret, - amazon: config.endpoint, - }); + init: (providerOptions = {}, settings = {}) => { + var client = nodeSES.createClient({ ...providerOptions }); return { send: options => { return new Promise((resolve, reject) => { - // Default values. - options = _.isObject(options) ? options : {}; - options.from = options.from || config.defaultFrom; - options.replyTo = options.replyTo || config.defaultReplyTo; - options.text = options.text || options.html; - options.html = options.html || options.text; + const { from, to, cc, bcc, replyTo, subject, text, html, ...rest } = options; let msg = { - from: options.from, - to: options.to, - cc: options.cc, - bcc: options.bcc, - replyTo: options.replyTo, - subject: options.subject, - altText: options.text, - message: options.html, + from: from || settings.defaultFrom, + to, + cc, + bcc, + replyTo: replyTo || settings.defaultReplyTo, + subject, + text, + html, + ...rest, }; client.sendEmail(msg, function(err) { diff --git a/packages/strapi-provider-email-mailgun/README.md b/packages/strapi-provider-email-mailgun/README.md index 090c81ae6e..fc55b1c37c 100644 --- a/packages/strapi-provider-email-mailgun/README.md +++ b/packages/strapi-provider-email-mailgun/README.md @@ -26,14 +26,13 @@ npm install strapi-provider-email-mailgun --save ## Configuration -| Variable | Type | Description | Required | Default | -| ------------------------------ | ----------------------- | ---------------------------------------------- | -------- | --------- | -| provider | string | The name of the provider you use | yes | | -| providerOptions.apiKey | string | Api key given by Mailgun | yes | | -| providerOptions.defaultFrom | string | Sender mail address | no | undefined | -| providerOptions.defaultReplyTo | string \| array | Address or addresses the receiver can reply to | no | undefined | -| providerOptions.host | string | | | | -| providerOptions.domain | string | | | | +| Variable | Type | Description | Required | Default | +| ----------------------- | ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | -------- | --------- | +| provider | string | The name of the provider you use | yes | | +| providerOptions | object | Will be directly given to the `require('mailgun-js')`. Please refer to [mailgun-js](https://www.npmjs.com/package/mailgun-js) doc. | yes | | +| settings | object | Settings | no | {} | +| settings.defaultFrom | string | Default sender mail address | no | undefined | +| settings.defaultReplyTo | string \| array | Default address or addresses the receiver is asked to reply to | no | undefined | ### Example @@ -46,6 +45,8 @@ module.exports = ({ env }) => ({ provider: 'mailgun', providerOptions: { apiKey: env('MAILGUN_API_KEY'), + }, + settings: { defaultFrom: 'myemail@protonmail.com', defaultReplyTo: 'myemail@protonmail.com', }, diff --git a/packages/strapi-provider-email-mailgun/lib/index.js b/packages/strapi-provider-email-mailgun/lib/index.js index 6152a017b7..f43d670b21 100644 --- a/packages/strapi-provider-email-mailgun/lib/index.js +++ b/packages/strapi-provider-email-mailgun/lib/index.js @@ -1,42 +1,29 @@ 'use strict'; -/** - * Module dependencies - */ - -/* eslint-disable prefer-template */ -// Public node modules. -const isObject = require('lodash/isObject'); const mailgunFactory = require('mailgun-js'); -/* eslint-disable no-unused-vars */ module.exports = { - init: config => { + init: (providerOptions = {}, settings = {}) => { const mailgun = mailgunFactory({ - apiKey: config.apiKey, - host: config.apiHost, - domain: config.domain, mute: false, + ...providerOptions, }); return { send: options => { return new Promise((resolve, reject) => { - // Default values. - options = isObject(options) ? options : {}; + const { from, to, cc, bcc, replyTo, subject, text, html, ...rest } = options; let msg = { - from: options.from || config.defaultFrom, - to: options.to, - cc: options.cc, - bcc: options.bcc, - subject: options.subject, - 'h:Reply-To': options.replyTo || config.defaultReplyTo, - text: options.text, - html: options.html, - template: options.template, - 'h:X-Mailgun-Variables': options['h:X-Mailgun-Variables'], - attachment: options.attachment, + from: from || settings.defaultFrom, + to, + cc, + bcc, + 'h:Reply-To': replyTo || settings.defaultReplyTo, + subject, + text, + html, + ...rest, }; mailgun.messages().send(msg, function(err) { diff --git a/packages/strapi-provider-email-sendgrid/README.md b/packages/strapi-provider-email-sendgrid/README.md index 17daaa455e..4de04427cc 100644 --- a/packages/strapi-provider-email-sendgrid/README.md +++ b/packages/strapi-provider-email-sendgrid/README.md @@ -26,12 +26,14 @@ npm install strapi-provider-email-sendgrid --save ## Configuration -| Variable | Type | Description | Required | Default | -| ------------------------------ | ----------------------- | ---------------------------------------------- | -------- | --------- | -| provider | string | The name of the provider you use | yes | | -| providerOptions.apiKey | string | Api key given by Sendgrid | yes | | -| providerOptions.defaultFrom | string | Sender mail address | no | undefined | -| providerOptions.defaultReplyTo | string \| array | Address or addresses the receiver can reply to | no | undefined | +| Variable | Type | Description | Required | Default | +| ----------------------- | ----------------------- | ----------------------------------------------------------------------------------------------------------------------- | -------- | --------- | +| provider | string | The name of the provider you use | yes | | +| providerOptions | object | Provider options | yes | | +| providerOptions.apiKey | object | Api key given to the function setApiKey. Please refer to [@sendgrid/mail](https://www.npmjs.com/package/@sendgrid/mail) | yes | | +| settings | object | Settings | no | {} | +| settings.defaultFrom | string | Default sender mail address | no | undefined | +| settings.defaultReplyTo | string \| array | Default address or addresses the receiver is asked to reply to | no | undefined | ### Example @@ -44,6 +46,8 @@ module.exports = ({ env }) => ({ provider: 'sendgrid', providerOptions: { apiKey: env('SENDGRID_API_KEY'), + }, + settings: { defaultFrom: 'myemail@protonmail.com', defaultReplyTo: 'myemail@protonmail.com', }, diff --git a/packages/strapi-provider-email-sendgrid/lib/index.js b/packages/strapi-provider-email-sendgrid/lib/index.js index d7f27acbcb..ed6283f4ce 100644 --- a/packages/strapi-provider-email-sendgrid/lib/index.js +++ b/packages/strapi-provider-email-sendgrid/lib/index.js @@ -1,34 +1,26 @@ 'use strict'; -/** - * Module dependencies - */ - -/* eslint-disable prefer-template */ -// Public node modules. const sendgrid = require('@sendgrid/mail'); -/* eslint-disable no-unused-vars */ module.exports = { - init: config => { - sendgrid.setApiKey(config.apiKey); + init: (providerOptions = {}, settings = {}) => { + sendgrid.setApiKey(providerOptions.apiKey); return { send: options => { return new Promise((resolve, reject) => { + const { from, to, cc, bcc, replyTo, subject, text, html, ...rest } = options; + let msg = { - from: options.from || config.defaultFrom, - to: options.to, - cc: options.cc, - bcc: options.bcc, - replyTo: options.replyTo || config.defaultReplyTo, - subject: options.subject, - text: options.text, - html: options.html, - templateId: options.templateId, - dynamic_template_data: options.dynamic_template_data, - sendAt: options.sendAt, - batchId: options.batchId, + from: from || settings.defaultFrom, + to, + cc, + bcc, + replyTo: replyTo || settings.defaultReplyTo, + subject, + text, + html, + ...rest, }; sendgrid.send(msg, function(err) { diff --git a/packages/strapi-provider-email-sendmail/README.md b/packages/strapi-provider-email-sendmail/README.md index 687708ff4d..bcfa7bc8a6 100644 --- a/packages/strapi-provider-email-sendmail/README.md +++ b/packages/strapi-provider-email-sendmail/README.md @@ -26,11 +26,13 @@ npm install strapi-provider-email-sendmail --save ## Configuration -| Variable | Type | Description | Required | Default | -| ------------------------------ | ----------------------- | ---------------------------------------------- | -------- | --------- | -| provider | string | The name of the provider you use | yes | | -| providerOptions.defaultFrom | string | Sender mail address | no | undefined | -| providerOptions.defaultReplyTo | string \| array | Address or addresses the receiver can reply to | no | undefined | +| Variable | Type | Description | Required | Default | +| ----------------------- | ----------------------- | ------------------------------------------------------------------------------------------------------------------------ | -------- | --------- | +| provider | string | The name of the provider you use | yes | | +| providerOptions | object | Will be directly given to `require('sendmail')`. Please refer to [sendmail](https://www.npmjs.com/package/sendmail) doc. | no | {} | +| settings | object | Settings | no | {} | +| settings.defaultFrom | string | Default sender mail address | no | undefined | +| settings.defaultReplyTo | string \| array | Default address or addresses the receiver is asked to reply to | no | undefined | ### Example @@ -41,7 +43,7 @@ module.exports = ({ env }) => ({ // ... email: { provider: 'sendmail', - providerOptions: { + settings: { defaultFrom: 'myemail@protonmail.com', defaultReplyTo: 'myemail@protonmail.com', }, diff --git a/packages/strapi-provider-email-sendmail/lib/index.js b/packages/strapi-provider-email-sendmail/lib/index.js index 998c22f70e..dd7d12e29a 100644 --- a/packages/strapi-provider-email-sendmail/lib/index.js +++ b/packages/strapi-provider-email-sendmail/lib/index.js @@ -1,29 +1,29 @@ 'use strict'; -/** - * Module dependencies - */ +const sendmailFactory = require('sendmail'); -// Public node modules. -const sendmail = require('sendmail')({ - silent: true, -}); - -/* eslint-disable no-unused-vars */ module.exports = { - init: config => { + init: (providerOptions = {}, settings = {}) => { + const sendmail = sendmailFactory({ + silent: true, + ...providerOptions, + }); return { send: options => { return new Promise((resolve, reject) => { + const { from, to, cc, bcc, replyTo, subject, text, html, ...rest } = options; + sendmail( { - from: options.from || config.defaultFrom, - to: options.to, - replyTo: options.replyTo || config.defaultReplyTo, - subject: options.subject, - text: options.text, - html: options.html, - attachments: options.attachments, + from: from || settings.defaultFrom, + to, + cc, + bcc, + replyTo: replyTo || settings.defaultReplyTo, + subject, + text, + html, + ...rest, }, function(err) { if (err) { From 8821f42694baaa3931d7512e3f26c721bb082d8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20No=C3=ABl?= Date: Fri, 15 May 2020 15:46:59 +0200 Subject: [PATCH 08/14] update email settings getstarted MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Noël --- examples/getstarted/config/plugins.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/getstarted/config/plugins.js b/examples/getstarted/config/plugins.js index 525132cf51..5ac068494c 100644 --- a/examples/getstarted/config/plugins.js +++ b/examples/getstarted/config/plugins.js @@ -5,7 +5,7 @@ module.exports = { }, email: { provider: 'sendmail', - providerOptions: { + settings: { defaultFrom: 'strapi@strapi.io', }, }, From bc3cee4c5457e09934c6d66af5b628a02929a6f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20No=C3=ABl?= Date: Fri, 15 May 2020 16:22:05 +0200 Subject: [PATCH 09/14] sanatize email options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Noël --- examples/getstarted/.gitignore | 1 + examples/getstarted/config/plugins.js | 10 +++-- examples/getstarted/package.json | 2 +- .../lib/index.js | 3 ++ .../lib/index.js | 3 ++ .../lib/index.js | 3 ++ .../lib/index.js | 40 ++++++++++--------- 7 files changed, 39 insertions(+), 23 deletions(-) diff --git a/examples/getstarted/.gitignore b/examples/getstarted/.gitignore index 9823e80eb3..a96be48f07 100644 --- a/examples/getstarted/.gitignore +++ b/examples/getstarted/.gitignore @@ -82,6 +82,7 @@ ssl nbproject public/uploads/* !public/uploads/.gitkeep +.env ############################ # Node.js diff --git a/examples/getstarted/config/plugins.js b/examples/getstarted/config/plugins.js index 5ac068494c..c61580b705 100644 --- a/examples/getstarted/config/plugins.js +++ b/examples/getstarted/config/plugins.js @@ -1,12 +1,16 @@ -module.exports = { +module.exports = ({ env }) => ({ graphql: { amountLimit: 5, depthLimit: 10, }, email: { - provider: 'sendmail', + provider: 'mailgun', + providerOptions: { + apiKey: env('MAILGUN_API_KEY'), + domain: env('MAILGUN_DOMAIN'), + }, settings: { defaultFrom: 'strapi@strapi.io', }, }, -}; +}); diff --git a/examples/getstarted/package.json b/examples/getstarted/package.json index d0270cb529..da05ce7b7a 100644 --- a/examples/getstarted/package.json +++ b/examples/getstarted/package.json @@ -27,7 +27,7 @@ "strapi-plugin-graphql": "3.0.0-beta.20.3", "strapi-plugin-upload": "3.0.0-beta.20.3", "strapi-plugin-users-permissions": "3.0.0-beta.20.3", - "strapi-provider-email-sendmail": "3.0.0-beta.20.3", + "strapi-provider-email-mailgun": "3.0.0-beta.20.3", "strapi-provider-upload-aws-s3": "3.0.0-beta.20.3", "strapi-provider-upload-cloudinary": "3.0.0-beta.20.3", "strapi-utils": "3.0.0-beta.20.3" diff --git a/packages/strapi-provider-email-amazon-ses/lib/index.js b/packages/strapi-provider-email-amazon-ses/lib/index.js index 7f430d4734..5c49cda5b8 100644 --- a/packages/strapi-provider-email-amazon-ses/lib/index.js +++ b/packages/strapi-provider-email-amazon-ses/lib/index.js @@ -1,6 +1,7 @@ 'use strict'; const nodeSES = require('node-ses'); +const _ = require('lodash'); module.exports = { init: (providerOptions = {}, settings = {}) => { @@ -23,6 +24,8 @@ module.exports = { ...rest, }; + msg = _.pickBy(msg, value => typeof value !== 'undefined'); + client.sendEmail(msg, function(err) { if (err) { reject([{ messages: [{ id: 'Auth.form.error.email.invalid' }] }]); diff --git a/packages/strapi-provider-email-mailgun/lib/index.js b/packages/strapi-provider-email-mailgun/lib/index.js index f43d670b21..a45c17b237 100644 --- a/packages/strapi-provider-email-mailgun/lib/index.js +++ b/packages/strapi-provider-email-mailgun/lib/index.js @@ -1,6 +1,7 @@ 'use strict'; const mailgunFactory = require('mailgun-js'); +const _ = require('lodash'); module.exports = { init: (providerOptions = {}, settings = {}) => { @@ -26,6 +27,8 @@ module.exports = { ...rest, }; + msg = _.pickBy(msg, value => typeof value !== 'undefined'); + mailgun.messages().send(msg, function(err) { if (err) { reject([{ messages: [{ id: 'Auth.form.error.email.invalid' }] }]); diff --git a/packages/strapi-provider-email-sendgrid/lib/index.js b/packages/strapi-provider-email-sendgrid/lib/index.js index ed6283f4ce..1a9376deb4 100644 --- a/packages/strapi-provider-email-sendgrid/lib/index.js +++ b/packages/strapi-provider-email-sendgrid/lib/index.js @@ -1,6 +1,7 @@ 'use strict'; const sendgrid = require('@sendgrid/mail'); +const _ = require('lodash'); module.exports = { init: (providerOptions = {}, settings = {}) => { @@ -23,6 +24,8 @@ module.exports = { ...rest, }; + msg = _.pickBy(msg, value => typeof value !== 'undefined'); + sendgrid.send(msg, function(err) { if (err) { reject([{ messages: [{ id: 'Auth.form.error.email.invalid' }] }]); diff --git a/packages/strapi-provider-email-sendmail/lib/index.js b/packages/strapi-provider-email-sendmail/lib/index.js index dd7d12e29a..ed957af4eb 100644 --- a/packages/strapi-provider-email-sendmail/lib/index.js +++ b/packages/strapi-provider-email-sendmail/lib/index.js @@ -1,6 +1,7 @@ 'use strict'; const sendmailFactory = require('sendmail'); +const _ = require('lodash'); module.exports = { init: (providerOptions = {}, settings = {}) => { @@ -13,26 +14,27 @@ module.exports = { return new Promise((resolve, reject) => { const { from, to, cc, bcc, replyTo, subject, text, html, ...rest } = options; - sendmail( - { - from: from || settings.defaultFrom, - to, - cc, - bcc, - replyTo: replyTo || settings.defaultReplyTo, - subject, - text, - html, - ...rest, - }, - function(err) { - if (err) { - reject([{ messages: [{ id: 'Auth.form.error.email.invalid' }] }]); - } else { - resolve(); - } + let msg = { + from: from || settings.defaultFrom, + to, + cc, + bcc, + replyTo: replyTo || settings.defaultReplyTo, + subject, + text, + html, + ...rest, + }; + + msg = _.pickBy(msg, value => typeof value !== 'undefined'); + + sendmail(msg, err => { + if (err) { + reject([{ messages: [{ id: 'Auth.form.error.email.invalid' }] }]); + } else { + resolve(); } - ); + }); }); }, }; From 20aedc0e68680b6257da1c6c4613cbae666fa9a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20No=C3=ABl?= Date: Fri, 15 May 2020 17:15:24 +0200 Subject: [PATCH 10/14] refactor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Noël --- packages/strapi-provider-email-amazon-ses/lib/index.js | 6 ++---- packages/strapi-provider-email-amazon-ses/package.json | 4 ++-- packages/strapi-provider-email-mailgun/lib/index.js | 6 ++---- packages/strapi-provider-email-mailgun/package.json | 4 ++-- packages/strapi-provider-email-sendgrid/lib/index.js | 6 ++---- packages/strapi-provider-email-sendgrid/package.json | 2 +- packages/strapi-provider-email-sendmail/lib/index.js | 6 ++---- packages/strapi-provider-email-sendmail/package.json | 4 ++-- packages/strapi-utils/lib/index.js | 2 ++ packages/strapi-utils/lib/objectFormatting.js | 9 +++++++++ 10 files changed, 26 insertions(+), 23 deletions(-) create mode 100644 packages/strapi-utils/lib/objectFormatting.js diff --git a/packages/strapi-provider-email-amazon-ses/lib/index.js b/packages/strapi-provider-email-amazon-ses/lib/index.js index 5c49cda5b8..6ba859b495 100644 --- a/packages/strapi-provider-email-amazon-ses/lib/index.js +++ b/packages/strapi-provider-email-amazon-ses/lib/index.js @@ -1,7 +1,7 @@ 'use strict'; const nodeSES = require('node-ses'); -const _ = require('lodash'); +const { removeUndefined } = require('strapi-utils'); module.exports = { init: (providerOptions = {}, settings = {}) => { @@ -24,9 +24,7 @@ module.exports = { ...rest, }; - msg = _.pickBy(msg, value => typeof value !== 'undefined'); - - client.sendEmail(msg, function(err) { + client.sendEmail(removeUndefined(msg), function(err) { if (err) { reject([{ messages: [{ id: 'Auth.form.error.email.invalid' }] }]); } else { diff --git a/packages/strapi-provider-email-amazon-ses/package.json b/packages/strapi-provider-email-amazon-ses/package.json index ed631de4c3..48fcdb29e9 100644 --- a/packages/strapi-provider-email-amazon-ses/package.json +++ b/packages/strapi-provider-email-amazon-ses/package.json @@ -14,8 +14,8 @@ }, "main": "./lib", "dependencies": { - "lodash": "^4.17.11", - "node-ses": "^3.0.0" + "node-ses": "^3.0.0", + "strapi-utils": "^3.0.0-beta.20.3" }, "author": { "email": "nikolay@tsenkov.net", diff --git a/packages/strapi-provider-email-mailgun/lib/index.js b/packages/strapi-provider-email-mailgun/lib/index.js index a45c17b237..092aa8b7f4 100644 --- a/packages/strapi-provider-email-mailgun/lib/index.js +++ b/packages/strapi-provider-email-mailgun/lib/index.js @@ -1,7 +1,7 @@ 'use strict'; const mailgunFactory = require('mailgun-js'); -const _ = require('lodash'); +const { removeUndefined } = require('strapi-utils'); module.exports = { init: (providerOptions = {}, settings = {}) => { @@ -27,9 +27,7 @@ module.exports = { ...rest, }; - msg = _.pickBy(msg, value => typeof value !== 'undefined'); - - mailgun.messages().send(msg, function(err) { + mailgun.messages().send(removeUndefined(msg), function(err) { if (err) { reject([{ messages: [{ id: 'Auth.form.error.email.invalid' }] }]); } else { diff --git a/packages/strapi-provider-email-mailgun/package.json b/packages/strapi-provider-email-mailgun/package.json index af1eaa92d7..3b7eb70672 100644 --- a/packages/strapi-provider-email-mailgun/package.json +++ b/packages/strapi-provider-email-mailgun/package.json @@ -13,8 +13,8 @@ }, "main": "./lib", "dependencies": { - "lodash": "^4.17.11", - "mailgun-js": "0.22.0" + "mailgun-js": "0.22.0", + "strapi-utils": "^3.0.0-beta.20.3" }, "strapi": { "isProvider": true diff --git a/packages/strapi-provider-email-sendgrid/lib/index.js b/packages/strapi-provider-email-sendgrid/lib/index.js index 1a9376deb4..4b28736ff6 100644 --- a/packages/strapi-provider-email-sendgrid/lib/index.js +++ b/packages/strapi-provider-email-sendgrid/lib/index.js @@ -1,7 +1,7 @@ 'use strict'; const sendgrid = require('@sendgrid/mail'); -const _ = require('lodash'); +const { removeUndefined } = require('strapi-utils'); module.exports = { init: (providerOptions = {}, settings = {}) => { @@ -24,9 +24,7 @@ module.exports = { ...rest, }; - msg = _.pickBy(msg, value => typeof value !== 'undefined'); - - sendgrid.send(msg, function(err) { + sendgrid.send(removeUndefined(msg), function(err) { if (err) { reject([{ messages: [{ id: 'Auth.form.error.email.invalid' }] }]); } else { diff --git a/packages/strapi-provider-email-sendgrid/package.json b/packages/strapi-provider-email-sendgrid/package.json index 63aa80821f..eb89ee3ad5 100644 --- a/packages/strapi-provider-email-sendgrid/package.json +++ b/packages/strapi-provider-email-sendgrid/package.json @@ -14,7 +14,7 @@ "main": "./lib", "dependencies": { "@sendgrid/mail": "6.4.0", - "lodash": "^4.17.11" + "strapi-utils": "^3.0.0-beta.20.3" }, "strapi": { "isProvider": true diff --git a/packages/strapi-provider-email-sendmail/lib/index.js b/packages/strapi-provider-email-sendmail/lib/index.js index ed957af4eb..84d49f8bc3 100644 --- a/packages/strapi-provider-email-sendmail/lib/index.js +++ b/packages/strapi-provider-email-sendmail/lib/index.js @@ -1,7 +1,7 @@ 'use strict'; const sendmailFactory = require('sendmail'); -const _ = require('lodash'); +const { removeUndefined } = require('strapi-utils'); module.exports = { init: (providerOptions = {}, settings = {}) => { @@ -26,9 +26,7 @@ module.exports = { ...rest, }; - msg = _.pickBy(msg, value => typeof value !== 'undefined'); - - sendmail(msg, err => { + sendmail(removeUndefined(msg), err => { if (err) { reject([{ messages: [{ id: 'Auth.form.error.email.invalid' }] }]); } else { diff --git a/packages/strapi-provider-email-sendmail/package.json b/packages/strapi-provider-email-sendmail/package.json index d2d45bdd5f..4fd77107dc 100644 --- a/packages/strapi-provider-email-sendmail/package.json +++ b/packages/strapi-provider-email-sendmail/package.json @@ -12,8 +12,8 @@ }, "main": "./lib", "dependencies": { - "lodash": "^4.17.11", - "sendmail": "^1.6.1" + "sendmail": "^1.6.1", + "strapi-utils": "^3.0.0-beta.20.3" }, "strapi": { "isProvider": true diff --git a/packages/strapi-utils/lib/index.js b/packages/strapi-utils/lib/index.js index c1d3f610e0..60038a846a 100644 --- a/packages/strapi-utils/lib/index.js +++ b/packages/strapi-utils/lib/index.js @@ -21,6 +21,7 @@ const { getCommonBeginning, escapeQuery, } = require('./stringFormatting'); +const { removeUndefined } = require('./objectFormatting'); const { getConfigUrls } = require('./config'); module.exports = { @@ -41,4 +42,5 @@ module.exports = { getCommonBeginning, getConfigUrls, escapeQuery, + removeUndefined, }; diff --git a/packages/strapi-utils/lib/objectFormatting.js b/packages/strapi-utils/lib/objectFormatting.js new file mode 100644 index 0000000000..1d8a5899e2 --- /dev/null +++ b/packages/strapi-utils/lib/objectFormatting.js @@ -0,0 +1,9 @@ +'use strict'; + +const _ = require('lodash'); + +const removeUndefined = obj => _.pickBy(obj, value => typeof value !== 'undefined'); + +module.exports = { + removeUndefined, +}; From 978549febe29332a557de459b88d85a3f8123cad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20No=C3=ABl?= Date: Fri, 15 May 2020 17:17:21 +0200 Subject: [PATCH 11/14] remove ^ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Noël --- packages/strapi-provider-email-amazon-ses/package.json | 2 +- packages/strapi-provider-email-mailgun/package.json | 2 +- packages/strapi-provider-email-sendgrid/package.json | 2 +- packages/strapi-provider-email-sendmail/package.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/strapi-provider-email-amazon-ses/package.json b/packages/strapi-provider-email-amazon-ses/package.json index 48fcdb29e9..aafc739fe5 100644 --- a/packages/strapi-provider-email-amazon-ses/package.json +++ b/packages/strapi-provider-email-amazon-ses/package.json @@ -15,7 +15,7 @@ "main": "./lib", "dependencies": { "node-ses": "^3.0.0", - "strapi-utils": "^3.0.0-beta.20.3" + "strapi-utils": "3.0.0-beta.20.3" }, "author": { "email": "nikolay@tsenkov.net", diff --git a/packages/strapi-provider-email-mailgun/package.json b/packages/strapi-provider-email-mailgun/package.json index 3b7eb70672..686dfc7f11 100644 --- a/packages/strapi-provider-email-mailgun/package.json +++ b/packages/strapi-provider-email-mailgun/package.json @@ -14,7 +14,7 @@ "main": "./lib", "dependencies": { "mailgun-js": "0.22.0", - "strapi-utils": "^3.0.0-beta.20.3" + "strapi-utils": "3.0.0-beta.20.3" }, "strapi": { "isProvider": true diff --git a/packages/strapi-provider-email-sendgrid/package.json b/packages/strapi-provider-email-sendgrid/package.json index eb89ee3ad5..f5eed18dcf 100644 --- a/packages/strapi-provider-email-sendgrid/package.json +++ b/packages/strapi-provider-email-sendgrid/package.json @@ -14,7 +14,7 @@ "main": "./lib", "dependencies": { "@sendgrid/mail": "6.4.0", - "strapi-utils": "^3.0.0-beta.20.3" + "strapi-utils": "3.0.0-beta.20.3" }, "strapi": { "isProvider": true diff --git a/packages/strapi-provider-email-sendmail/package.json b/packages/strapi-provider-email-sendmail/package.json index 4fd77107dc..b2d40a2831 100644 --- a/packages/strapi-provider-email-sendmail/package.json +++ b/packages/strapi-provider-email-sendmail/package.json @@ -13,7 +13,7 @@ "main": "./lib", "dependencies": { "sendmail": "^1.6.1", - "strapi-utils": "^3.0.0-beta.20.3" + "strapi-utils": "3.0.0-beta.20.3" }, "strapi": { "isProvider": true From aea700efc3e9f88a560fb781162d902dd39e93c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20No=C3=ABl?= Date: Fri, 15 May 2020 19:22:45 +0200 Subject: [PATCH 12/14] add default settings to plugin email MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Noël --- packages/strapi-plugin-email/config/settings.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 packages/strapi-plugin-email/config/settings.js diff --git a/packages/strapi-plugin-email/config/settings.js b/packages/strapi-plugin-email/config/settings.js new file mode 100644 index 0000000000..609aa3752e --- /dev/null +++ b/packages/strapi-plugin-email/config/settings.js @@ -0,0 +1,7 @@ +module.exports = { + provider: 'sendmail', + providerOptions: {}, + settings: { + defaultFrom: 'Strapi ', + }, +}; From 73849b8415b1053615685de1b445abd513f16047 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20No=C3=ABl?= Date: Fri, 15 May 2020 19:29:18 +0200 Subject: [PATCH 13/14] change emails in doc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Noël --- docs/3.0.0-beta.x/plugins/email.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/3.0.0-beta.x/plugins/email.md b/docs/3.0.0-beta.x/plugins/email.md index 51b4ddfcf9..bfdddef7a1 100644 --- a/docs/3.0.0-beta.x/plugins/email.md +++ b/docs/3.0.0-beta.x/plugins/email.md @@ -11,9 +11,9 @@ By using the following function, strapi will use the configured provider to send await strapi.plugins['email'].services.email.send({ to: 'paulbocuse@strapi.io', from: 'joelrobuchon@strapi.io', - cc: 'lauralumale@strapi.io', - bcc: 'arthurpapailhau@strapi.io', - replyTo: 'no-reply@strapi.io', + cc: 'helenedarroze@strapi.io', + bcc: 'ghislainearabian@strapi.io', + replyTo: 'annesophiepic@strapi.io', subject: 'Use strapi email provider successfully', text: 'Hello world!', html: 'Hello world!', @@ -67,8 +67,8 @@ module.exports = ({ env }) => ({ apiKey: env('SENDGRID_API_KEY'), }, settings: { - defaultFrom: 'myemail@protonmail.com', - defaultReplyTo: 'myemail@protonmail.com', + defaultFrom: 'juliasedefdjian@strapi.io', + defaultReplyTo: 'juliasedefdjian@strapi.io', }, }, // ... From f2dd146bf488c27c839b40f91d7ae651a06730f3 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Fri, 15 May 2020 19:41:56 +0200 Subject: [PATCH 14/14] Clear getstarted config Signed-off-by: Alexandre Bodin --- examples/getstarted/config/plugins.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/examples/getstarted/config/plugins.js b/examples/getstarted/config/plugins.js index c61580b705..9dcf205c0d 100644 --- a/examples/getstarted/config/plugins.js +++ b/examples/getstarted/config/plugins.js @@ -3,14 +3,4 @@ module.exports = ({ env }) => ({ amountLimit: 5, depthLimit: 10, }, - email: { - provider: 'mailgun', - providerOptions: { - apiKey: env('MAILGUN_API_KEY'), - domain: env('MAILGUN_DOMAIN'), - }, - settings: { - defaultFrom: 'strapi@strapi.io', - }, - }, });