@strapi/email 5.0.0-rc.12 → 5.0.0-rc.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/server/index.js
CHANGED
|
@@ -28,7 +28,7 @@ const createProvider = (emailConfig) => {
|
|
|
28
28
|
try {
|
|
29
29
|
modulePath = require.resolve(`@strapi/provider-email-${providerName}`);
|
|
30
30
|
} catch (error) {
|
|
31
|
-
if (error
|
|
31
|
+
if (error !== null && typeof error === "object" && "code" in error && error.code === "MODULE_NOT_FOUND") {
|
|
32
32
|
modulePath = providerName;
|
|
33
33
|
} else {
|
|
34
34
|
throw error;
|
package/dist/server/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../server/src/bootstrap.ts","../../server/src/services/email.ts","../../server/src/services/index.ts","../../server/src/routes/admin.ts","../../server/src/routes/content-api.ts","../../server/src/routes/index.ts","../../server/src/controllers/email.ts","../../server/src/controllers/index.ts","../../server/src/config.ts","../../server/src/index.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\nimport type { EmailConfig, SendOptions } from './types';\n\ninterface EmailProvider {\n send: (options: SendOptions) => Promise<any>;\n}\n\ninterface EmailProviderModule {\n init: (\n options: EmailConfig['providerOptions'],\n settings: EmailConfig['settings']\n ) => EmailProvider;\n name?: string;\n provider?: string;\n}\n\nconst createProvider = (emailConfig: EmailConfig) => {\n const providerName = emailConfig.provider.toLowerCase();\n let provider: EmailProviderModule;\n\n let modulePath: string;\n try {\n modulePath = require.resolve(`@strapi/provider-email-${providerName}`);\n } catch (error) {\n if (error instanceof Error && 'code' in error && error.code === 'MODULE_NOT_FOUND') {\n modulePath = providerName;\n } else {\n throw error;\n }\n }\n\n try {\n provider = require(modulePath);\n } catch (err) {\n throw new Error(`Could not load email provider \"${providerName}\".`);\n }\n\n return provider.init(emailConfig.providerOptions, emailConfig.settings);\n};\n\nexport const bootstrap = async ({ strapi }: { strapi: Core.Strapi }) => {\n const emailConfig: EmailConfig = strapi.config.get('plugin::email');\n strapi.plugin('email').provider = createProvider(emailConfig);\n\n // Add permissions\n const actions = [\n {\n section: 'settings',\n category: 'email',\n displayName: 'Access the Email Settings page',\n uid: 'settings.read',\n pluginName: 'email',\n },\n ];\n\n await strapi.service('admin::permission').actionProvider.registerMany(actions);\n};\n","import * as _ from 'lodash';\nimport { objects, template } from '@strapi/utils';\n\nimport type {\n EmailConfig,\n EmailOptions,\n EmailTemplate,\n EmailTemplateData,\n SendOptions,\n} from '../types';\n\nconst { createStrictInterpolationRegExp } = template;\n\nconst getProviderSettings = (): EmailConfig => strapi.config.get('plugin::email');\n\nconst send = async (options: SendOptions) => strapi.plugin('email').provider.send(options);\n\n/**\n * fill subject, text and html using lodash template\n * @param {object} emailOptions - to, from and replyto...\n * @param {object} emailTemplate - object containing attributes to fill\n * @param {object} data - data used to fill the template\n * @returns {{ subject, text, subject }}\n */\nconst sendTemplatedEmail = (\n emailOptions: EmailOptions,\n emailTemplate: EmailTemplate,\n data: EmailTemplateData\n) => {\n const attributes = ['subject', 'text', 'html'];\n const missingAttributes = _.difference(attributes, Object.keys(emailTemplate));\n\n if (missingAttributes.length > 0) {\n throw new Error(\n `Following attributes are missing from your email template : ${missingAttributes.join(', ')}`\n );\n }\n\n const allowedInterpolationVariables = objects.keysDeep(data);\n const interpolate = createStrictInterpolationRegExp(allowedInterpolationVariables, 'g');\n\n const templatedAttributes = attributes.reduce(\n (compiled, attribute) =>\n emailTemplate[attribute]\n ? Object.assign(compiled, {\n [attribute]: _.template(emailTemplate[attribute], {\n interpolate,\n })(data),\n })\n : compiled,\n {}\n );\n\n return strapi.plugin('email').provider.send({ ...emailOptions, ...templatedAttributes });\n};\n\nconst emailService = () => ({\n getProviderSettings,\n send,\n sendTemplatedEmail,\n});\n\nexport default emailService;\n","import email from './email';\n\nexport const services = { email };\n","export default {\n type: 'admin',\n routes: [\n {\n method: 'POST',\n path: '/',\n handler: 'email.send',\n config: {\n policies: ['admin::isAuthenticatedAdmin'],\n },\n },\n {\n method: 'POST',\n path: '/test',\n handler: 'email.test',\n config: {\n policies: [\n 'admin::isAuthenticatedAdmin',\n { name: 'admin::hasPermissions', config: { actions: ['plugin::email.settings.read'] } },\n ],\n },\n },\n {\n method: 'GET',\n path: '/settings',\n handler: 'email.getSettings',\n config: {\n policies: [\n 'admin::isAuthenticatedAdmin',\n { name: 'admin::hasPermissions', config: { actions: ['plugin::email.settings.read'] } },\n ],\n },\n },\n ],\n};\n","export default {\n type: 'content-api',\n routes: [\n {\n method: 'POST',\n path: '/',\n handler: 'email.send',\n },\n ],\n};\n","import admin from './admin';\nimport contentApi from './content-api';\n\nexport const routes = {\n admin,\n 'content-api': contentApi,\n};\n","import { pick } from 'lodash/fp';\nimport { errors } from '@strapi/utils';\n\nimport type Koa from 'koa';\nimport type {} from 'koa-body';\nimport type { EmailConfig, SendOptions } from '../types';\n\nconst { ApplicationError } = errors;\n\n/**\n * Email.js controller\n *\n * @description: A set of functions called \"actions\" of the `email` plugin.\n */\nconst emailController = {\n async send(ctx: Koa.Context) {\n const options = ctx.request.body as SendOptions;\n\n try {\n await strapi.plugin('email').service('email').send(options);\n } catch (error) {\n if (error instanceof Error) {\n if ('statusCode' in error && error.statusCode === 400) {\n throw new ApplicationError(error.message);\n } else {\n throw new Error(`Couldn't send email: ${error.message}.`);\n }\n }\n }\n\n // Send 200 `ok`\n ctx.send({});\n },\n\n async test(ctx: Koa.Context) {\n const { to } = ctx.request.body as Pick<SendOptions, 'to'>;\n\n if (!to) {\n throw new ApplicationError('No recipient(s) are given');\n }\n\n const email: SendOptions = {\n to,\n subject: `Strapi test mail to: ${to}`,\n text: `Great! You have correctly configured the Strapi email plugin with the ${strapi.config.get(\n 'plugin::email.provider'\n )} provider. \\r\\nFor documentation on how to use the email plugin checkout: https://docs.strapi.io/developer-docs/latest/plugins/email.html`,\n };\n\n try {\n await strapi.plugin('email').service('email').send(email);\n } catch (error) {\n if (error instanceof Error) {\n if ('statusCode' in error && error.statusCode === 400) {\n throw new ApplicationError(error.message);\n } else {\n throw new Error(`Couldn't send test email: ${error.message}.`);\n }\n }\n }\n\n // Send 200 `ok`\n ctx.send({});\n },\n\n async getSettings(ctx: Koa.Context) {\n const config: EmailConfig = strapi.plugin('email').service('email').getProviderSettings();\n\n ctx.send({\n config: pick(\n ['provider', 'settings.defaultFrom', 'settings.defaultReplyTo', 'settings.testAddress'],\n config\n ),\n });\n },\n};\n\nexport default emailController;\n","import email from './email';\n\nexport const controllers = { email };\n","import type { StrapiConfig } from './types';\n\nexport const config: StrapiConfig = {\n default: {\n provider: 'sendmail',\n providerOptions: {},\n settings: {\n defaultFrom: 'Strapi <no-reply@strapi.io>',\n },\n },\n validator() {},\n};\n","import { bootstrap } from './bootstrap';\nimport { services } from './services';\nimport { routes } from './routes';\nimport { controllers } from './controllers';\nimport { config } from './config';\n\nexport default {\n bootstrap,\n services,\n routes,\n controllers,\n config,\n};\n"],"names":["strapi","template","_","objects","email","errors","config","pick"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAgBA,MAAM,iBAAiB,CAAC,gBAA6B;AAC7C,QAAA,eAAe,YAAY,SAAS,YAAY;AAClD,MAAA;AAEA,MAAA;AACA,MAAA;AACF,iBAAa,QAAQ,QAAQ,0BAA0B,YAAY,EAAE;AAAA,WAC9D,OAAO;AACd,QAAI,iBAAiB,SAAS,UAAU,SAAS,MAAM,SAAS,oBAAoB;AACrE,mBAAA;AAAA,IAAA,OACR;AACC,YAAA;AAAA,IACR;AAAA,EACF;AAEI,MAAA;AACF,eAAW,QAAQ,UAAU;AAAA,WACtB,KAAK;AACZ,UAAM,IAAI,MAAM,kCAAkC,YAAY,IAAI;AAAA,EACpE;AAEA,SAAO,SAAS,KAAK,YAAY,iBAAiB,YAAY,QAAQ;AACxE;AAEO,MAAM,YAAY,OAAO,EAAE,QAAAA,cAAsC;AACtE,QAAM,cAA2BA,QAAO,OAAO,IAAI,eAAe;AAClE,EAAAA,QAAO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
+
{"version":3,"file":"index.js","sources":["../../server/src/bootstrap.ts","../../server/src/services/email.ts","../../server/src/services/index.ts","../../server/src/routes/admin.ts","../../server/src/routes/content-api.ts","../../server/src/routes/index.ts","../../server/src/controllers/email.ts","../../server/src/controllers/index.ts","../../server/src/config.ts","../../server/src/index.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\nimport type { EmailConfig, SendOptions } from './types';\n\ninterface EmailProvider {\n send: (options: SendOptions) => Promise<any>;\n}\n\ninterface EmailProviderModule {\n init: (\n options: EmailConfig['providerOptions'],\n settings: EmailConfig['settings']\n ) => EmailProvider;\n name?: string;\n provider?: string;\n}\n\nconst createProvider = (emailConfig: EmailConfig) => {\n const providerName = emailConfig.provider.toLowerCase();\n let provider: EmailProviderModule;\n\n let modulePath: string;\n try {\n modulePath = require.resolve(`@strapi/provider-email-${providerName}`);\n } catch (error) {\n if (\n error !== null &&\n typeof error === 'object' &&\n 'code' in error &&\n error.code === 'MODULE_NOT_FOUND'\n ) {\n modulePath = providerName;\n } else {\n throw error;\n }\n }\n\n try {\n provider = require(modulePath);\n } catch (err) {\n throw new Error(`Could not load email provider \"${providerName}\".`);\n }\n\n return provider.init(emailConfig.providerOptions, emailConfig.settings);\n};\n\nexport const bootstrap = async ({ strapi }: { strapi: Core.Strapi }) => {\n const emailConfig: EmailConfig = strapi.config.get('plugin::email');\n strapi.plugin('email').provider = createProvider(emailConfig);\n\n // Add permissions\n const actions = [\n {\n section: 'settings',\n category: 'email',\n displayName: 'Access the Email Settings page',\n uid: 'settings.read',\n pluginName: 'email',\n },\n ];\n\n await strapi.service('admin::permission').actionProvider.registerMany(actions);\n};\n","import * as _ from 'lodash';\nimport { objects, template } from '@strapi/utils';\n\nimport type {\n EmailConfig,\n EmailOptions,\n EmailTemplate,\n EmailTemplateData,\n SendOptions,\n} from '../types';\n\nconst { createStrictInterpolationRegExp } = template;\n\nconst getProviderSettings = (): EmailConfig => strapi.config.get('plugin::email');\n\nconst send = async (options: SendOptions) => strapi.plugin('email').provider.send(options);\n\n/**\n * fill subject, text and html using lodash template\n * @param {object} emailOptions - to, from and replyto...\n * @param {object} emailTemplate - object containing attributes to fill\n * @param {object} data - data used to fill the template\n * @returns {{ subject, text, subject }}\n */\nconst sendTemplatedEmail = (\n emailOptions: EmailOptions,\n emailTemplate: EmailTemplate,\n data: EmailTemplateData\n) => {\n const attributes = ['subject', 'text', 'html'];\n const missingAttributes = _.difference(attributes, Object.keys(emailTemplate));\n\n if (missingAttributes.length > 0) {\n throw new Error(\n `Following attributes are missing from your email template : ${missingAttributes.join(', ')}`\n );\n }\n\n const allowedInterpolationVariables = objects.keysDeep(data);\n const interpolate = createStrictInterpolationRegExp(allowedInterpolationVariables, 'g');\n\n const templatedAttributes = attributes.reduce(\n (compiled, attribute) =>\n emailTemplate[attribute]\n ? Object.assign(compiled, {\n [attribute]: _.template(emailTemplate[attribute], {\n interpolate,\n })(data),\n })\n : compiled,\n {}\n );\n\n return strapi.plugin('email').provider.send({ ...emailOptions, ...templatedAttributes });\n};\n\nconst emailService = () => ({\n getProviderSettings,\n send,\n sendTemplatedEmail,\n});\n\nexport default emailService;\n","import email from './email';\n\nexport const services = { email };\n","export default {\n type: 'admin',\n routes: [\n {\n method: 'POST',\n path: '/',\n handler: 'email.send',\n config: {\n policies: ['admin::isAuthenticatedAdmin'],\n },\n },\n {\n method: 'POST',\n path: '/test',\n handler: 'email.test',\n config: {\n policies: [\n 'admin::isAuthenticatedAdmin',\n { name: 'admin::hasPermissions', config: { actions: ['plugin::email.settings.read'] } },\n ],\n },\n },\n {\n method: 'GET',\n path: '/settings',\n handler: 'email.getSettings',\n config: {\n policies: [\n 'admin::isAuthenticatedAdmin',\n { name: 'admin::hasPermissions', config: { actions: ['plugin::email.settings.read'] } },\n ],\n },\n },\n ],\n};\n","export default {\n type: 'content-api',\n routes: [\n {\n method: 'POST',\n path: '/',\n handler: 'email.send',\n },\n ],\n};\n","import admin from './admin';\nimport contentApi from './content-api';\n\nexport const routes = {\n admin,\n 'content-api': contentApi,\n};\n","import { pick } from 'lodash/fp';\nimport { errors } from '@strapi/utils';\n\nimport type Koa from 'koa';\nimport type {} from 'koa-body';\nimport type { EmailConfig, SendOptions } from '../types';\n\nconst { ApplicationError } = errors;\n\n/**\n * Email.js controller\n *\n * @description: A set of functions called \"actions\" of the `email` plugin.\n */\nconst emailController = {\n async send(ctx: Koa.Context) {\n const options = ctx.request.body as SendOptions;\n\n try {\n await strapi.plugin('email').service('email').send(options);\n } catch (error) {\n if (error instanceof Error) {\n if ('statusCode' in error && error.statusCode === 400) {\n throw new ApplicationError(error.message);\n } else {\n throw new Error(`Couldn't send email: ${error.message}.`);\n }\n }\n }\n\n // Send 200 `ok`\n ctx.send({});\n },\n\n async test(ctx: Koa.Context) {\n const { to } = ctx.request.body as Pick<SendOptions, 'to'>;\n\n if (!to) {\n throw new ApplicationError('No recipient(s) are given');\n }\n\n const email: SendOptions = {\n to,\n subject: `Strapi test mail to: ${to}`,\n text: `Great! You have correctly configured the Strapi email plugin with the ${strapi.config.get(\n 'plugin::email.provider'\n )} provider. \\r\\nFor documentation on how to use the email plugin checkout: https://docs.strapi.io/developer-docs/latest/plugins/email.html`,\n };\n\n try {\n await strapi.plugin('email').service('email').send(email);\n } catch (error) {\n if (error instanceof Error) {\n if ('statusCode' in error && error.statusCode === 400) {\n throw new ApplicationError(error.message);\n } else {\n throw new Error(`Couldn't send test email: ${error.message}.`);\n }\n }\n }\n\n // Send 200 `ok`\n ctx.send({});\n },\n\n async getSettings(ctx: Koa.Context) {\n const config: EmailConfig = strapi.plugin('email').service('email').getProviderSettings();\n\n ctx.send({\n config: pick(\n ['provider', 'settings.defaultFrom', 'settings.defaultReplyTo', 'settings.testAddress'],\n config\n ),\n });\n },\n};\n\nexport default emailController;\n","import email from './email';\n\nexport const controllers = { email };\n","import type { StrapiConfig } from './types';\n\nexport const config: StrapiConfig = {\n default: {\n provider: 'sendmail',\n providerOptions: {},\n settings: {\n defaultFrom: 'Strapi <no-reply@strapi.io>',\n },\n },\n validator() {},\n};\n","import { bootstrap } from './bootstrap';\nimport { services } from './services';\nimport { routes } from './routes';\nimport { controllers } from './controllers';\nimport { config } from './config';\n\nexport default {\n bootstrap,\n services,\n routes,\n controllers,\n config,\n};\n"],"names":["strapi","template","_","objects","email","errors","config","pick"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAgBA,MAAM,iBAAiB,CAAC,gBAA6B;AAC7C,QAAA,eAAe,YAAY,SAAS,YAAY;AAClD,MAAA;AAEA,MAAA;AACA,MAAA;AACF,iBAAa,QAAQ,QAAQ,0BAA0B,YAAY,EAAE;AAAA,WAC9D,OAAO;AAEZ,QAAA,UAAU,QACV,OAAO,UAAU,YACjB,UAAU,SACV,MAAM,SAAS,oBACf;AACa,mBAAA;AAAA,IAAA,OACR;AACC,YAAA;AAAA,IACR;AAAA,EACF;AAEI,MAAA;AACF,eAAW,QAAQ,UAAU;AAAA,WACtB,KAAK;AACZ,UAAM,IAAI,MAAM,kCAAkC,YAAY,IAAI;AAAA,EACpE;AAEA,SAAO,SAAS,KAAK,YAAY,iBAAiB,YAAY,QAAQ;AACxE;AAEO,MAAM,YAAY,OAAO,EAAE,QAAAA,cAAsC;AACtE,QAAM,cAA2BA,QAAO,OAAO,IAAI,eAAe;AAClE,EAAAA,QAAO,OAAO,OAAO,EAAE,WAAW,eAAe,WAAW;AAG5D,QAAM,UAAU;AAAA,IACd;AAAA,MACE,SAAS;AAAA,MACT,UAAU;AAAA,MACV,aAAa;AAAA,MACb,KAAK;AAAA,MACL,YAAY;AAAA,IACd;AAAA,EAAA;AAGF,QAAMA,QAAO,QAAQ,mBAAmB,EAAE,eAAe,aAAa,OAAO;AAC/E;AClDA,MAAM,EAAE,gCAAoC,IAAAC;AAE5C,MAAM,sBAAsB,MAAmB,OAAO,OAAO,IAAI,eAAe;AAEhF,MAAM,OAAO,OAAO,YAAyB,OAAO,OAAO,OAAO,EAAE,SAAS,KAAK,OAAO;AASzF,MAAM,qBAAqB,C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AAO;AACd,UAAI,iBAAiB,OAAO;AAC1B,YAAI,gBAAgB,SAAS,MAAM,eAAe,KAAK;AAC/C,gBAAA,IAAI,iBAAiB,MAAM,OAAO;AAAA,QAAA,OACnC;AACL,gBAAM,IAAI,MAAM,6BAA6B,MAAM,OAAO,GAAG;AAAA,QAC/D;AAAA,MACF;AAAA,IACF;AAGI,QAAA,KAAK,CAAA,CAAE;AAAA,EACb;AAAA,EAEA,MAAM,YAAY,KAAkB;AAC5B,UAAAC,UAAsB,OAAO,OAAO,OAAO,EAAE,QAAQ,OAAO,EAAE;AAEpE,QAAI,KAAK;AAAA,MACP,QAAQC,GAAA;AAAA,QACN,CAAC,YAAY,wBAAwB,2BAA2B,sBAAsB;AAAA,QACtFD;AAAA,MACF;AAAA,IAAA,CACD;AAAA,EACH;AACF;ACzEa,MAAA,cAAc,EAAEF,OAAAA,gBAAM;ACA5B,MAAM,SAAuB;AAAA,EAClC,SAAS;AAAA,IACP,UAAU;AAAA,IACV,iBAAiB,CAAC;AAAA,IAClB,UAAU;AAAA,MACR,aAAa;AAAA,IACf;AAAA,EACF;AAAA,EACA,YAAY;AAAA,EAAC;AACf;ACLA,MAAe,QAAA;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;;"}
|
package/dist/server/index.mjs
CHANGED
|
@@ -8,7 +8,7 @@ const createProvider = (emailConfig) => {
|
|
|
8
8
|
try {
|
|
9
9
|
modulePath = require.resolve(`@strapi/provider-email-${providerName}`);
|
|
10
10
|
} catch (error) {
|
|
11
|
-
if (error
|
|
11
|
+
if (error !== null && typeof error === "object" && "code" in error && error.code === "MODULE_NOT_FOUND") {
|
|
12
12
|
modulePath = providerName;
|
|
13
13
|
} else {
|
|
14
14
|
throw error;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../server/src/bootstrap.ts","../../server/src/services/email.ts","../../server/src/services/index.ts","../../server/src/routes/admin.ts","../../server/src/routes/content-api.ts","../../server/src/routes/index.ts","../../server/src/controllers/email.ts","../../server/src/controllers/index.ts","../../server/src/config.ts","../../server/src/index.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\nimport type { EmailConfig, SendOptions } from './types';\n\ninterface EmailProvider {\n send: (options: SendOptions) => Promise<any>;\n}\n\ninterface EmailProviderModule {\n init: (\n options: EmailConfig['providerOptions'],\n settings: EmailConfig['settings']\n ) => EmailProvider;\n name?: string;\n provider?: string;\n}\n\nconst createProvider = (emailConfig: EmailConfig) => {\n const providerName = emailConfig.provider.toLowerCase();\n let provider: EmailProviderModule;\n\n let modulePath: string;\n try {\n modulePath = require.resolve(`@strapi/provider-email-${providerName}`);\n } catch (error) {\n if (error instanceof Error && 'code' in error && error.code === 'MODULE_NOT_FOUND') {\n modulePath = providerName;\n } else {\n throw error;\n }\n }\n\n try {\n provider = require(modulePath);\n } catch (err) {\n throw new Error(`Could not load email provider \"${providerName}\".`);\n }\n\n return provider.init(emailConfig.providerOptions, emailConfig.settings);\n};\n\nexport const bootstrap = async ({ strapi }: { strapi: Core.Strapi }) => {\n const emailConfig: EmailConfig = strapi.config.get('plugin::email');\n strapi.plugin('email').provider = createProvider(emailConfig);\n\n // Add permissions\n const actions = [\n {\n section: 'settings',\n category: 'email',\n displayName: 'Access the Email Settings page',\n uid: 'settings.read',\n pluginName: 'email',\n },\n ];\n\n await strapi.service('admin::permission').actionProvider.registerMany(actions);\n};\n","import * as _ from 'lodash';\nimport { objects, template } from '@strapi/utils';\n\nimport type {\n EmailConfig,\n EmailOptions,\n EmailTemplate,\n EmailTemplateData,\n SendOptions,\n} from '../types';\n\nconst { createStrictInterpolationRegExp } = template;\n\nconst getProviderSettings = (): EmailConfig => strapi.config.get('plugin::email');\n\nconst send = async (options: SendOptions) => strapi.plugin('email').provider.send(options);\n\n/**\n * fill subject, text and html using lodash template\n * @param {object} emailOptions - to, from and replyto...\n * @param {object} emailTemplate - object containing attributes to fill\n * @param {object} data - data used to fill the template\n * @returns {{ subject, text, subject }}\n */\nconst sendTemplatedEmail = (\n emailOptions: EmailOptions,\n emailTemplate: EmailTemplate,\n data: EmailTemplateData\n) => {\n const attributes = ['subject', 'text', 'html'];\n const missingAttributes = _.difference(attributes, Object.keys(emailTemplate));\n\n if (missingAttributes.length > 0) {\n throw new Error(\n `Following attributes are missing from your email template : ${missingAttributes.join(', ')}`\n );\n }\n\n const allowedInterpolationVariables = objects.keysDeep(data);\n const interpolate = createStrictInterpolationRegExp(allowedInterpolationVariables, 'g');\n\n const templatedAttributes = attributes.reduce(\n (compiled, attribute) =>\n emailTemplate[attribute]\n ? Object.assign(compiled, {\n [attribute]: _.template(emailTemplate[attribute], {\n interpolate,\n })(data),\n })\n : compiled,\n {}\n );\n\n return strapi.plugin('email').provider.send({ ...emailOptions, ...templatedAttributes });\n};\n\nconst emailService = () => ({\n getProviderSettings,\n send,\n sendTemplatedEmail,\n});\n\nexport default emailService;\n","import email from './email';\n\nexport const services = { email };\n","export default {\n type: 'admin',\n routes: [\n {\n method: 'POST',\n path: '/',\n handler: 'email.send',\n config: {\n policies: ['admin::isAuthenticatedAdmin'],\n },\n },\n {\n method: 'POST',\n path: '/test',\n handler: 'email.test',\n config: {\n policies: [\n 'admin::isAuthenticatedAdmin',\n { name: 'admin::hasPermissions', config: { actions: ['plugin::email.settings.read'] } },\n ],\n },\n },\n {\n method: 'GET',\n path: '/settings',\n handler: 'email.getSettings',\n config: {\n policies: [\n 'admin::isAuthenticatedAdmin',\n { name: 'admin::hasPermissions', config: { actions: ['plugin::email.settings.read'] } },\n ],\n },\n },\n ],\n};\n","export default {\n type: 'content-api',\n routes: [\n {\n method: 'POST',\n path: '/',\n handler: 'email.send',\n },\n ],\n};\n","import admin from './admin';\nimport contentApi from './content-api';\n\nexport const routes = {\n admin,\n 'content-api': contentApi,\n};\n","import { pick } from 'lodash/fp';\nimport { errors } from '@strapi/utils';\n\nimport type Koa from 'koa';\nimport type {} from 'koa-body';\nimport type { EmailConfig, SendOptions } from '../types';\n\nconst { ApplicationError } = errors;\n\n/**\n * Email.js controller\n *\n * @description: A set of functions called \"actions\" of the `email` plugin.\n */\nconst emailController = {\n async send(ctx: Koa.Context) {\n const options = ctx.request.body as SendOptions;\n\n try {\n await strapi.plugin('email').service('email').send(options);\n } catch (error) {\n if (error instanceof Error) {\n if ('statusCode' in error && error.statusCode === 400) {\n throw new ApplicationError(error.message);\n } else {\n throw new Error(`Couldn't send email: ${error.message}.`);\n }\n }\n }\n\n // Send 200 `ok`\n ctx.send({});\n },\n\n async test(ctx: Koa.Context) {\n const { to } = ctx.request.body as Pick<SendOptions, 'to'>;\n\n if (!to) {\n throw new ApplicationError('No recipient(s) are given');\n }\n\n const email: SendOptions = {\n to,\n subject: `Strapi test mail to: ${to}`,\n text: `Great! You have correctly configured the Strapi email plugin with the ${strapi.config.get(\n 'plugin::email.provider'\n )} provider. \\r\\nFor documentation on how to use the email plugin checkout: https://docs.strapi.io/developer-docs/latest/plugins/email.html`,\n };\n\n try {\n await strapi.plugin('email').service('email').send(email);\n } catch (error) {\n if (error instanceof Error) {\n if ('statusCode' in error && error.statusCode === 400) {\n throw new ApplicationError(error.message);\n } else {\n throw new Error(`Couldn't send test email: ${error.message}.`);\n }\n }\n }\n\n // Send 200 `ok`\n ctx.send({});\n },\n\n async getSettings(ctx: Koa.Context) {\n const config: EmailConfig = strapi.plugin('email').service('email').getProviderSettings();\n\n ctx.send({\n config: pick(\n ['provider', 'settings.defaultFrom', 'settings.defaultReplyTo', 'settings.testAddress'],\n config\n ),\n });\n },\n};\n\nexport default emailController;\n","import email from './email';\n\nexport const controllers = { email };\n","import type { StrapiConfig } from './types';\n\nexport const config: StrapiConfig = {\n default: {\n provider: 'sendmail',\n providerOptions: {},\n settings: {\n defaultFrom: 'Strapi <no-reply@strapi.io>',\n },\n },\n validator() {},\n};\n","import { bootstrap } from './bootstrap';\nimport { services } from './services';\nimport { routes } from './routes';\nimport { controllers } from './controllers';\nimport { config } from './config';\n\nexport default {\n bootstrap,\n services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;AAAA,MACF;AAAA,IACF;AAGI,QAAA,KAAK,CAAA,CAAE;AAAA,EACb;AAAA,EAEA,MAAM,YAAY,KAAkB;AAC5B,UAAAC,UAAsB,OAAO,OAAO,OAAO,EAAE,QAAQ,OAAO,EAAE;AAEpE,QAAI,KAAK;AAAA,MACP,QAAQ;AAAA,QACN,CAAC,YAAY,wBAAwB,2BAA2B,sBAAsB;AAAA,QACtFA;AAAA,MACF;AAAA,IAAA,CACD;AAAA,EACH;AACF;ACzEa,MAAA,cAAc,EAAED,OAAAA,gBAAM;ACA5B,MAAM,SAAuB;AAAA,EAClC,SAAS;AAAA,IACP,UAAU;AAAA,IACV,iBAAiB,CAAC;AAAA,IAClB,UAAU;AAAA,MACR,aAAa;AAAA,IACf;AAAA,EACF;AAAA,EACA,YAAY;AAAA,EAAC;AACf;ACLA,MAAe,QAAA;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../server/src/bootstrap.ts","../../server/src/services/email.ts","../../server/src/services/index.ts","../../server/src/routes/admin.ts","../../server/src/routes/content-api.ts","../../server/src/routes/index.ts","../../server/src/controllers/email.ts","../../server/src/controllers/index.ts","../../server/src/config.ts","../../server/src/index.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\nimport type { EmailConfig, SendOptions } from './types';\n\ninterface EmailProvider {\n send: (options: SendOptions) => Promise<any>;\n}\n\ninterface EmailProviderModule {\n init: (\n options: EmailConfig['providerOptions'],\n settings: EmailConfig['settings']\n ) => EmailProvider;\n name?: string;\n provider?: string;\n}\n\nconst createProvider = (emailConfig: EmailConfig) => {\n const providerName = emailConfig.provider.toLowerCase();\n let provider: EmailProviderModule;\n\n let modulePath: string;\n try {\n modulePath = require.resolve(`@strapi/provider-email-${providerName}`);\n } catch (error) {\n if (\n error !== null &&\n typeof error === 'object' &&\n 'code' in error &&\n error.code === 'MODULE_NOT_FOUND'\n ) {\n modulePath = providerName;\n } else {\n throw error;\n }\n }\n\n try {\n provider = require(modulePath);\n } catch (err) {\n throw new Error(`Could not load email provider \"${providerName}\".`);\n }\n\n return provider.init(emailConfig.providerOptions, emailConfig.settings);\n};\n\nexport const bootstrap = async ({ strapi }: { strapi: Core.Strapi }) => {\n const emailConfig: EmailConfig = strapi.config.get('plugin::email');\n strapi.plugin('email').provider = createProvider(emailConfig);\n\n // Add permissions\n const actions = [\n {\n section: 'settings',\n category: 'email',\n displayName: 'Access the Email Settings page',\n uid: 'settings.read',\n pluginName: 'email',\n },\n ];\n\n await strapi.service('admin::permission').actionProvider.registerMany(actions);\n};\n","import * as _ from 'lodash';\nimport { objects, template } from '@strapi/utils';\n\nimport type {\n EmailConfig,\n EmailOptions,\n EmailTemplate,\n EmailTemplateData,\n SendOptions,\n} from '../types';\n\nconst { createStrictInterpolationRegExp } = template;\n\nconst getProviderSettings = (): EmailConfig => strapi.config.get('plugin::email');\n\nconst send = async (options: SendOptions) => strapi.plugin('email').provider.send(options);\n\n/**\n * fill subject, text and html using lodash template\n * @param {object} emailOptions - to, from and replyto...\n * @param {object} emailTemplate - object containing attributes to fill\n * @param {object} data - data used to fill the template\n * @returns {{ subject, text, subject }}\n */\nconst sendTemplatedEmail = (\n emailOptions: EmailOptions,\n emailTemplate: EmailTemplate,\n data: EmailTemplateData\n) => {\n const attributes = ['subject', 'text', 'html'];\n const missingAttributes = _.difference(attributes, Object.keys(emailTemplate));\n\n if (missingAttributes.length > 0) {\n throw new Error(\n `Following attributes are missing from your email template : ${missingAttributes.join(', ')}`\n );\n }\n\n const allowedInterpolationVariables = objects.keysDeep(data);\n const interpolate = createStrictInterpolationRegExp(allowedInterpolationVariables, 'g');\n\n const templatedAttributes = attributes.reduce(\n (compiled, attribute) =>\n emailTemplate[attribute]\n ? Object.assign(compiled, {\n [attribute]: _.template(emailTemplate[attribute], {\n interpolate,\n })(data),\n })\n : compiled,\n {}\n );\n\n return strapi.plugin('email').provider.send({ ...emailOptions, ...templatedAttributes });\n};\n\nconst emailService = () => ({\n getProviderSettings,\n send,\n sendTemplatedEmail,\n});\n\nexport default emailService;\n","import email from './email';\n\nexport const services = { email };\n","export default {\n type: 'admin',\n routes: [\n {\n method: 'POST',\n path: '/',\n handler: 'email.send',\n config: {\n policies: ['admin::isAuthenticatedAdmin'],\n },\n },\n {\n method: 'POST',\n path: '/test',\n handler: 'email.test',\n config: {\n policies: [\n 'admin::isAuthenticatedAdmin',\n { name: 'admin::hasPermissions', config: { actions: ['plugin::email.settings.read'] } },\n ],\n },\n },\n {\n method: 'GET',\n path: '/settings',\n handler: 'email.getSettings',\n config: {\n policies: [\n 'admin::isAuthenticatedAdmin',\n { name: 'admin::hasPermissions', config: { actions: ['plugin::email.settings.read'] } },\n ],\n },\n },\n ],\n};\n","export default {\n type: 'content-api',\n routes: [\n {\n method: 'POST',\n path: '/',\n handler: 'email.send',\n },\n ],\n};\n","import admin from './admin';\nimport contentApi from './content-api';\n\nexport const routes = {\n admin,\n 'content-api': contentApi,\n};\n","import { pick } from 'lodash/fp';\nimport { errors } from '@strapi/utils';\n\nimport type Koa from 'koa';\nimport type {} from 'koa-body';\nimport type { EmailConfig, SendOptions } from '../types';\n\nconst { ApplicationError } = errors;\n\n/**\n * Email.js controller\n *\n * @description: A set of functions called \"actions\" of the `email` plugin.\n */\nconst emailController = {\n async send(ctx: Koa.Context) {\n const options = ctx.request.body as SendOptions;\n\n try {\n await strapi.plugin('email').service('email').send(options);\n } catch (error) {\n if (error instanceof Error) {\n if ('statusCode' in error && error.statusCode === 400) {\n throw new ApplicationError(error.message);\n } else {\n throw new Error(`Couldn't send email: ${error.message}.`);\n }\n }\n }\n\n // Send 200 `ok`\n ctx.send({});\n },\n\n async test(ctx: Koa.Context) {\n const { to } = ctx.request.body as Pick<SendOptions, 'to'>;\n\n if (!to) {\n throw new ApplicationError('No recipient(s) are given');\n }\n\n const email: SendOptions = {\n to,\n subject: `Strapi test mail to: ${to}`,\n text: `Great! You have correctly configured the Strapi email plugin with the ${strapi.config.get(\n 'plugin::email.provider'\n )} provider. \\r\\nFor documentation on how to use the email plugin checkout: https://docs.strapi.io/developer-docs/latest/plugins/email.html`,\n };\n\n try {\n await strapi.plugin('email').service('email').send(email);\n } catch (error) {\n if (error instanceof Error) {\n if ('statusCode' in error && error.statusCode === 400) {\n throw new ApplicationError(error.message);\n } else {\n throw new Error(`Couldn't send test email: ${error.message}.`);\n }\n }\n }\n\n // Send 200 `ok`\n ctx.send({});\n },\n\n async getSettings(ctx: Koa.Context) {\n const config: EmailConfig = strapi.plugin('email').service('email').getProviderSettings();\n\n ctx.send({\n config: pick(\n ['provider', 'settings.defaultFrom', 'settings.defaultReplyTo', 'settings.testAddress'],\n config\n ),\n });\n },\n};\n\nexport default emailController;\n","import email from './email';\n\nexport const controllers = { email };\n","import type { StrapiConfig } from './types';\n\nexport const config: StrapiConfig = {\n default: {\n provider: 'sendmail',\n providerOptions: {},\n settings: {\n defaultFrom: 'Strapi <no-reply@strapi.io>',\n },\n },\n validator() {},\n};\n","import { bootstrap } from './bootstrap';\nimport { services } from './services';\nimport { routes } from './routes';\nimport { controllers } from './controllers';\nimport { config } from './config';\n\nexport default {\n bootstrap,\n services,\n routes,\n controllers,\n config,\n};\n"],"names":["strapi","email","config"],"mappings":";;;AAgBA,MAAM,iBAAiB,CAAC,gBAA6B;AAC7C,QAAA,eAAe,YAAY,SAAS,YAAY;AAClD,MAAA;AAEA,MAAA;AACA,MAAA;AACF,iBAAa,QAAQ,QAAQ,0BAA0B,YAAY,EAAE;AAAA,WAC9D,OAAO;AAEZ,QAAA,UAAU,QACV,OAAO,UAAU,YACjB,UAAU,SACV,MAAM,SAAS,oBACf;AACa,mBAAA;AAAA,IAAA,OACR;AACC,YAAA;AAAA,IACR;AAAA,EACF;AAEI,MAAA;AACF,eAAW,QAAQ,UAAU;AAAA,WACtB,KAAK;AACZ,UAAM,IAAI,MAAM,kCAAkC,YAAY,IAAI;AAAA,EACpE;AAEA,SAAO,SAAS,KAAK,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,EACA,YAAY;AAAA,EAAC;AACf;ACLA,MAAe,QAAA;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../../server/src/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../../server/src/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AA6C1C,eAAO,MAAM,SAAS,eAAsB;IAAE,MAAM,EAAE,KAAK,MAAM,CAAA;CAAE,kBAgBlE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/email",
|
|
3
|
-
"version": "5.0.0-rc.
|
|
3
|
+
"version": "5.0.0-rc.13",
|
|
4
4
|
"description": "Easily configure your Strapi application to send emails.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -52,19 +52,19 @@
|
|
|
52
52
|
"watch": "pack-up watch"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@strapi/design-system": "2.0.0-rc.
|
|
56
|
-
"@strapi/icons": "2.0.0-rc.
|
|
57
|
-
"@strapi/provider-email-sendmail": "5.0.0-rc.
|
|
58
|
-
"@strapi/utils": "5.0.0-rc.
|
|
55
|
+
"@strapi/design-system": "2.0.0-rc.10",
|
|
56
|
+
"@strapi/icons": "2.0.0-rc.10",
|
|
57
|
+
"@strapi/provider-email-sendmail": "5.0.0-rc.13",
|
|
58
|
+
"@strapi/utils": "5.0.0-rc.13",
|
|
59
59
|
"lodash": "4.17.21",
|
|
60
60
|
"react-intl": "6.6.2",
|
|
61
61
|
"react-query": "3.39.3",
|
|
62
62
|
"yup": "0.32.9"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@strapi/admin": "5.0.0-rc.
|
|
65
|
+
"@strapi/admin": "5.0.0-rc.13",
|
|
66
66
|
"@strapi/pack-up": "5.0.0",
|
|
67
|
-
"@strapi/types": "5.0.0-rc.
|
|
67
|
+
"@strapi/types": "5.0.0-rc.13",
|
|
68
68
|
"@testing-library/react": "15.0.7",
|
|
69
69
|
"@types/koa": "2.13.4",
|
|
70
70
|
"@types/lodash": "^4.14.191",
|
|
@@ -95,5 +95,5 @@
|
|
|
95
95
|
"required": true,
|
|
96
96
|
"kind": "plugin"
|
|
97
97
|
},
|
|
98
|
-
"gitHead": "
|
|
98
|
+
"gitHead": "cbc694f62f14f82d2931f7a407ea458a831045c9"
|
|
99
99
|
}
|