@payloadcms/plugin-form-builder 1.0.15 → 1.0.16-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +17 -16
  2. package/dist/collections/FormSubmissions/hooks/createCharge.d.ts +1 -0
  3. package/dist/collections/FormSubmissions/hooks/createCharge.d.ts.map +1 -0
  4. package/dist/collections/FormSubmissions/hooks/createCharge.js +21 -55
  5. package/dist/collections/FormSubmissions/hooks/sendEmail.d.ts +1 -0
  6. package/dist/collections/FormSubmissions/hooks/sendEmail.d.ts.map +1 -0
  7. package/dist/collections/FormSubmissions/hooks/sendEmail.js +69 -124
  8. package/dist/collections/FormSubmissions/index.d.ts +1 -0
  9. package/dist/collections/FormSubmissions/index.d.ts.map +1 -0
  10. package/dist/collections/FormSubmissions/index.js +70 -66
  11. package/dist/collections/Forms/DynamicFieldSelector.d.ts +2 -1
  12. package/dist/collections/Forms/DynamicFieldSelector.d.ts.map +1 -0
  13. package/dist/collections/Forms/DynamicFieldSelector.js +69 -53
  14. package/dist/collections/Forms/DynamicPriceSelector.d.ts +2 -1
  15. package/dist/collections/Forms/DynamicPriceSelector.d.ts.map +1 -0
  16. package/dist/collections/Forms/DynamicPriceSelector.js +82 -64
  17. package/dist/collections/Forms/fields.d.ts +2 -1
  18. package/dist/collections/Forms/fields.d.ts.map +1 -0
  19. package/dist/collections/Forms/fields.js +352 -270
  20. package/dist/collections/Forms/index.d.ts +1 -0
  21. package/dist/collections/Forms/index.d.ts.map +1 -0
  22. package/dist/collections/Forms/index.js +103 -106
  23. package/dist/index.d.ts +1 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +51 -38
  26. package/dist/types.d.ts +70 -69
  27. package/dist/types.d.ts.map +1 -0
  28. package/dist/types.js +12 -8
  29. package/dist/utilities/getPaymentTotal.d.ts +1 -0
  30. package/dist/utilities/getPaymentTotal.d.ts.map +1 -0
  31. package/dist/utilities/getPaymentTotal.js +44 -34
  32. package/dist/utilities/replaceDoubleCurlys.d.ts +1 -0
  33. package/dist/utilities/replaceDoubleCurlys.d.ts.map +1 -0
  34. package/dist/utilities/replaceDoubleCurlys.js +16 -13
  35. package/dist/utilities/serializeRichText.d.ts +2 -1
  36. package/dist/utilities/serializeRichText.d.ts.map +1 -0
  37. package/dist/utilities/serializeRichText.js +83 -28
  38. package/package.json +27 -38
  39. package/types.d.ts +1 -1
  40. package/types.js +1 -1
  41. package/dist/collections/FormSubmissions/hooks/createCharge.js.map +0 -1
  42. package/dist/collections/FormSubmissions/hooks/sendEmail.js.map +0 -1
  43. package/dist/collections/FormSubmissions/index.js.map +0 -1
  44. package/dist/collections/Forms/DynamicFieldSelector.js.map +0 -1
  45. package/dist/collections/Forms/DynamicPriceSelector.js.map +0 -1
  46. package/dist/collections/Forms/fields.js.map +0 -1
  47. package/dist/collections/Forms/index.js.map +0 -1
  48. package/dist/index.js.map +0 -1
  49. package/dist/mocks/serverModule.d.ts +0 -2
  50. package/dist/mocks/serverModule.js +0 -4
  51. package/dist/mocks/serverModule.js.map +0 -1
  52. package/dist/types.js.map +0 -1
  53. package/dist/utilities/getPaymentTotal.js.map +0 -1
  54. package/dist/utilities/replaceDoubleCurlys.js.map +0 -1
  55. package/dist/utilities/serializeRichText.js.map +0 -1
package/README.md CHANGED
@@ -28,20 +28,20 @@ Core features:
28
28
  In the `plugins` array of your [Payload config](https://payloadcms.com/docs/configuration/overview), call the plugin with [options](#options):
29
29
 
30
30
  ```js
31
- import { buildConfig } from "payload/config";
32
- import formBuilder from "@payloadcms/plugin-form-builder";
31
+ import { buildConfig } from 'payload/config'
32
+ import formBuilder from '@payloadcms/plugin-form-builder'
33
33
 
34
34
  const config = buildConfig({
35
35
  collections: [
36
36
  {
37
- slug: "pages",
37
+ slug: 'pages',
38
38
  fields: [],
39
39
  },
40
40
  ],
41
41
  plugins: [formBuilder()],
42
- });
42
+ })
43
43
 
44
- export default config;
44
+ export default config
45
45
  ```
46
46
 
47
47
  ### Options
@@ -70,7 +70,7 @@ export default config;
70
70
  An array of collection slugs that, when enabled, are populated as options in form redirect fields.
71
71
 
72
72
  ```js
73
- redirectRelationships: ["pages"];
73
+ redirectRelationships: ['pages']
74
74
  ```
75
75
 
76
76
  - `handlePayment`
@@ -102,8 +102,8 @@ export default config;
102
102
  return emails.map((email) => ({
103
103
  ...email,
104
104
  html: email.html, // transform the html in any way you'd like (maybe wrap it in an html template?)
105
- }));
106
- };
105
+ }))
106
+ }
107
107
  ```
108
108
 
109
109
  - `formOverrides`
@@ -196,6 +196,7 @@ Each field represents a form input. To override default settings pass either a b
196
196
  - `message`
197
197
  - `message`: richText
198
198
  - `payment`
199
+
199
200
  - `name`: string
200
201
  - `label`: string
201
202
  - `defaultValue`: number
@@ -214,7 +215,7 @@ Each field represents a form input. To override default settings pass either a b
214
215
  You can also provide your own custom field definitions by passing a new [Payload Block](https://payloadcms.com/docs/fields/blocks#block-configs) object into `fields`. You can override or extend any existing fields by first importing the `fields` from the plugin:
215
216
 
216
217
  ```ts
217
- import { fields } from "@payloadcms/plugin-form-builder";
218
+ import { fields } from '@payloadcms/plugin-form-builder'
218
219
  ```
219
220
 
220
221
  Then merging it into your own custom field:
@@ -283,7 +284,7 @@ To actively develop or debug this plugin you can either work directly within the
283
284
  You might also need to alias these modules in your Webpack config. To do this, open your project's Payload config and add the following:
284
285
 
285
286
  ```ts
286
- import { buildConfig } from "payload/config";
287
+ import { buildConfig } from 'payload/config'
287
288
 
288
289
  export default buildConfig({
289
290
  admin: {
@@ -293,18 +294,18 @@ To actively develop or debug this plugin you can either work directly within the
293
294
  ...config.resolve,
294
295
  alias: {
295
296
  ...config.resolve.alias,
296
- react: path.join(__dirname, "../node_modules/react"),
297
- "react-dom": path.join(__dirname, "../node_modules/react-dom"),
298
- payload: path.join(__dirname, "../node_modules/payload"),
299
- "@payloadcms/plugin-form-builder": path.join(
297
+ react: path.join(__dirname, '../node_modules/react'),
298
+ 'react-dom': path.join(__dirname, '../node_modules/react-dom'),
299
+ payload: path.join(__dirname, '../node_modules/payload'),
300
+ '@payloadcms/plugin-form-builder': path.join(
300
301
  __dirname,
301
- "../../payload/plugin-form-builder/src"
302
+ '../../payload/plugin-form-builder/src',
302
303
  ),
303
304
  },
304
305
  },
305
306
  }),
306
307
  },
307
- });
308
+ })
308
309
  ```
309
310
 
310
311
  ## Troubleshooting
@@ -1,3 +1,4 @@
1
1
  import type { PluginConfig } from '../../../types';
2
2
  declare const createCharge: (beforeChangeData: any, formConfig: PluginConfig) => Promise<any>;
3
3
  export default createCharge;
4
+ //# sourceMappingURL=createCharge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createCharge.d.ts","sourceRoot":"","sources":["../../../../src/collections/FormSubmissions/hooks/createCharge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAElD,QAAA,MAAM,YAAY,qBAA4B,GAAG,cAAc,YAAY,KAAG,QAAQ,GAAG,CAcxF,CAAA;AAED,eAAe,YAAY,CAAA"}
@@ -1,58 +1,24 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return _default;
36
9
  }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- var createCharge = function (beforeChangeData, formConfig) { return __awaiter(void 0, void 0, void 0, function () {
40
- var operation, data, dataWithPaymentDetails, handlePayment;
41
- return __generator(this, function (_a) {
42
- switch (_a.label) {
43
- case 0:
44
- operation = beforeChangeData.operation, data = beforeChangeData.data;
45
- dataWithPaymentDetails = data;
46
- if (!(operation === 'create')) return [3 /*break*/, 2];
47
- handlePayment = (formConfig || {}).handlePayment;
48
- if (!(typeof handlePayment === 'function')) return [3 /*break*/, 2];
49
- return [4 /*yield*/, handlePayment(beforeChangeData)];
50
- case 1:
51
- dataWithPaymentDetails = _a.sent();
52
- _a.label = 2;
53
- case 2: return [2 /*return*/, dataWithPaymentDetails];
10
+ });
11
+ const createCharge = async (beforeChangeData, formConfig)=>{
12
+ const { data, operation } = beforeChangeData;
13
+ let dataWithPaymentDetails = data;
14
+ if (operation === 'create') {
15
+ const { handlePayment } = formConfig || {};
16
+ if (typeof handlePayment === 'function') {
17
+ dataWithPaymentDetails = await handlePayment(beforeChangeData);
54
18
  }
55
- });
56
- }); };
57
- exports.default = createCharge;
58
- //# sourceMappingURL=createCharge.js.map
19
+ }
20
+ return dataWithPaymentDetails;
21
+ };
22
+ const _default = createCharge;
23
+
24
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9jb2xsZWN0aW9ucy9Gb3JtU3VibWlzc2lvbnMvaG9va3MvY3JlYXRlQ2hhcmdlLnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB0eXBlIHsgUGx1Z2luQ29uZmlnIH0gZnJvbSAnLi4vLi4vLi4vdHlwZXMnXG5cbmNvbnN0IGNyZWF0ZUNoYXJnZSA9IGFzeW5jIChiZWZvcmVDaGFuZ2VEYXRhOiBhbnksIGZvcm1Db25maWc6IFBsdWdpbkNvbmZpZyk6IFByb21pc2U8YW55PiA9PiB7XG4gIGNvbnN0IHsgZGF0YSwgb3BlcmF0aW9uIH0gPSBiZWZvcmVDaGFuZ2VEYXRhXG5cbiAgbGV0IGRhdGFXaXRoUGF5bWVudERldGFpbHMgPSBkYXRhXG5cbiAgaWYgKG9wZXJhdGlvbiA9PT0gJ2NyZWF0ZScpIHtcbiAgICBjb25zdCB7IGhhbmRsZVBheW1lbnQgfSA9IGZvcm1Db25maWcgfHwge31cblxuICAgIGlmICh0eXBlb2YgaGFuZGxlUGF5bWVudCA9PT0gJ2Z1bmN0aW9uJykge1xuICAgICAgZGF0YVdpdGhQYXltZW50RGV0YWlscyA9IGF3YWl0IGhhbmRsZVBheW1lbnQoYmVmb3JlQ2hhbmdlRGF0YSlcbiAgICB9XG4gIH1cblxuICByZXR1cm4gZGF0YVdpdGhQYXltZW50RGV0YWlsc1xufVxuXG5leHBvcnQgZGVmYXVsdCBjcmVhdGVDaGFyZ2VcbiJdLCJuYW1lcyI6WyJjcmVhdGVDaGFyZ2UiLCJiZWZvcmVDaGFuZ2VEYXRhIiwiZm9ybUNvbmZpZyIsImRhdGEiLCJvcGVyYXRpb24iLCJkYXRhV2l0aFBheW1lbnREZXRhaWxzIiwiaGFuZGxlUGF5bWVudCJdLCJtYXBwaW5ncyI6Ijs7OzsrQkFrQkE7OztlQUFBOzs7QUFoQkEsTUFBTUEsZUFBZSxPQUFPQyxrQkFBdUJDO0lBQ2pELE1BQU0sRUFBRUMsSUFBSSxFQUFFQyxTQUFTLEVBQUUsR0FBR0g7SUFFNUIsSUFBSUkseUJBQXlCRjtJQUU3QixJQUFJQyxjQUFjLFVBQVU7UUFDMUIsTUFBTSxFQUFFRSxhQUFhLEVBQUUsR0FBR0osY0FBYyxDQUFDO1FBRXpDLElBQUksT0FBT0ksa0JBQWtCLFlBQVk7WUFDdkNELHlCQUF5QixNQUFNQyxjQUFjTDtRQUMvQztJQUNGO0lBRUEsT0FBT0k7QUFDVDtNQUVBLFdBQWVMIn0=
@@ -1,3 +1,4 @@
1
1
  import type { PluginConfig } from '../../../types';
2
2
  declare const sendEmail: (beforeChangeData: any, formConfig: PluginConfig) => Promise<any>;
3
3
  export default sendEmail;
4
+ //# sourceMappingURL=sendEmail.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sendEmail.d.ts","sourceRoot":"","sources":["../../../../src/collections/FormSubmissions/hooks/sendEmail.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAyB,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAKzE,QAAA,MAAM,SAAS,qBAA4B,GAAG,cAAc,YAAY,KAAG,QAAQ,GAAG,CAoFrF,CAAA;AAED,eAAe,SAAS,CAAA"}
@@ -1,131 +1,76 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return _default;
36
9
  }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- var replaceDoubleCurlys_1 = require("../../../utilities/replaceDoubleCurlys");
40
- var serializeRichText_1 = require("../../../utilities/serializeRichText");
41
- var sendEmail = function (beforeChangeData, formConfig) { return __awaiter(void 0, void 0, void 0, function () {
42
- var operation, data, formSubmissionID, _a, payload_1, locale, _b, formID, submissionData_1, _c, beforeEmail, formOverrides, form, emails, formattedEmails, emailsToSend, err_1, msg;
43
- return __generator(this, function (_d) {
44
- switch (_d.label) {
45
- case 0:
46
- operation = beforeChangeData.operation, data = beforeChangeData.data;
47
- if (!(operation === 'create')) return [3 /*break*/, 10];
48
- formSubmissionID = beforeChangeData.data.id, _a = beforeChangeData.req, payload_1 = _a.payload, locale = _a.locale;
49
- _b = data || {}, formID = _b.form, submissionData_1 = _b.submissionData;
50
- _c = formConfig || {}, beforeEmail = _c.beforeEmail, formOverrides = _c.formOverrides;
51
- _d.label = 1;
52
- case 1:
53
- _d.trys.push([1, 9, , 10]);
54
- return [4 /*yield*/, payload_1.findByID({
55
- id: formID,
56
- collection: (formOverrides === null || formOverrides === void 0 ? void 0 : formOverrides.slug) || 'forms',
57
- locale: locale,
58
- })];
59
- case 2:
60
- form = _d.sent();
61
- if (!form) return [3 /*break*/, 7];
62
- emails = form.emails;
63
- if (!emails) return [3 /*break*/, 6];
64
- formattedEmails = emails.map(function (email) {
65
- var message = email.message, subject = email.subject, emailTo = email.emailTo, emailCC = email.cc, emailBCC = email.bcc, emailFrom = email.emailFrom, emailReplyTo = email.replyTo;
66
- var to = (0, replaceDoubleCurlys_1.replaceDoubleCurlys)(emailTo, submissionData_1);
67
- var cc = emailCC ? (0, replaceDoubleCurlys_1.replaceDoubleCurlys)(emailCC, submissionData_1) : '';
68
- var bcc = emailBCC ? (0, replaceDoubleCurlys_1.replaceDoubleCurlys)(emailBCC, submissionData_1) : '';
69
- var from = (0, replaceDoubleCurlys_1.replaceDoubleCurlys)(emailFrom, submissionData_1);
70
- var replyTo = (0, replaceDoubleCurlys_1.replaceDoubleCurlys)(emailReplyTo || emailFrom, submissionData_1);
10
+ });
11
+ const _replaceDoubleCurlys = require("../../../utilities/replaceDoubleCurlys");
12
+ const _serializeRichText = require("../../../utilities/serializeRichText");
13
+ const sendEmail = async (beforeChangeData, formConfig)=>{
14
+ const { data, operation } = beforeChangeData;
15
+ if (operation === 'create') {
16
+ const { data: { id: formSubmissionID }, req: { locale, payload } } = beforeChangeData;
17
+ const { form: formID, submissionData } = data || {};
18
+ const { beforeEmail, formOverrides } = formConfig || {};
19
+ try {
20
+ const form = await payload.findByID({
21
+ id: formID,
22
+ collection: formOverrides?.slug || 'forms',
23
+ locale
24
+ });
25
+ const { emails } = form;
26
+ if (emails && emails.length) {
27
+ const formattedEmails = emails.map((email)=>{
28
+ const { bcc: emailBCC, cc: emailCC, emailFrom, emailTo, message, replyTo: emailReplyTo, subject } = email;
29
+ const to = (0, _replaceDoubleCurlys.replaceDoubleCurlys)(emailTo, submissionData);
30
+ const cc = emailCC ? (0, _replaceDoubleCurlys.replaceDoubleCurlys)(emailCC, submissionData) : '';
31
+ const bcc = emailBCC ? (0, _replaceDoubleCurlys.replaceDoubleCurlys)(emailBCC, submissionData) : '';
32
+ const from = (0, _replaceDoubleCurlys.replaceDoubleCurlys)(emailFrom, submissionData);
33
+ const replyTo = (0, _replaceDoubleCurlys.replaceDoubleCurlys)(emailReplyTo || emailFrom, submissionData);
71
34
  return {
72
- to: to,
73
- from: from,
74
- cc: cc,
75
- bcc: bcc,
76
- replyTo: replyTo,
77
- subject: (0, replaceDoubleCurlys_1.replaceDoubleCurlys)(subject, submissionData_1),
78
- html: "<div>".concat((0, serializeRichText_1.serialize)(message, submissionData_1), "</div>"),
35
+ bcc,
36
+ cc,
37
+ from,
38
+ html: `<div>${(0, _serializeRichText.serialize)(message, submissionData)}</div>`,
39
+ replyTo,
40
+ subject: (0, _replaceDoubleCurlys.replaceDoubleCurlys)(subject, submissionData),
41
+ to
79
42
  };
80
43
  });
81
- emailsToSend = formattedEmails;
82
- if (!(typeof beforeEmail === 'function')) return [3 /*break*/, 4];
83
- return [4 /*yield*/, beforeEmail(formattedEmails)];
84
- case 3:
85
- emailsToSend = _d.sent();
86
- _d.label = 4;
87
- case 4:
88
- // const log = emailsToSend.map(({ html, ...rest }) => ({ ...rest }))
89
- return [4 /*yield*/, Promise.all(emailsToSend.map(function (email) { return __awaiter(void 0, void 0, void 0, function () {
90
- var to, emailPromise, err_2;
91
- return __generator(this, function (_a) {
92
- switch (_a.label) {
93
- case 0:
94
- to = email.to;
95
- _a.label = 1;
96
- case 1:
97
- _a.trys.push([1, 3, , 4]);
98
- return [4 /*yield*/, payload_1.sendEmail(email)];
99
- case 2:
100
- emailPromise = _a.sent();
101
- return [2 /*return*/, emailPromise];
102
- case 3:
103
- err_2 = _a.sent();
104
- payload_1.logger.error({
105
- err: "Error while sending email to address: ".concat(to, ". Email not sent: ").concat(err_2),
106
- });
107
- return [3 /*break*/, 4];
108
- case 4: return [2 /*return*/];
109
- }
110
- });
111
- }); }))];
112
- case 5:
44
+ let emailsToSend = formattedEmails;
45
+ if (typeof beforeEmail === 'function') {
46
+ emailsToSend = await beforeEmail(formattedEmails);
47
+ }
113
48
  // const log = emailsToSend.map(({ html, ...rest }) => ({ ...rest }))
114
- _d.sent();
115
- _d.label = 6;
116
- case 6: return [3 /*break*/, 8];
117
- case 7:
118
- payload_1.logger.info({ msg: 'No emails to send.' });
119
- _d.label = 8;
120
- case 8: return [3 /*break*/, 10];
121
- case 9:
122
- err_1 = _d.sent();
123
- msg = "Error while sending one or more emails in form submission id: ".concat(formSubmissionID, ".");
124
- payload_1.logger.error({ err: msg });
125
- return [3 /*break*/, 10];
126
- case 10: return [2 /*return*/, data];
49
+ await Promise.all(emailsToSend.map(async (email)=>{
50
+ const { to } = email;
51
+ try {
52
+ const emailPromise = await payload.sendEmail(email);
53
+ return emailPromise;
54
+ } catch (err) {
55
+ payload.logger.error({
56
+ err: `Error while sending email to address: ${to}. Email not sent: ${err}`
57
+ });
58
+ }
59
+ }));
60
+ } else {
61
+ payload.logger.info({
62
+ msg: 'No emails to send.'
63
+ });
64
+ }
65
+ } catch (err) {
66
+ const msg = `Error while sending one or more emails in form submission id: ${formSubmissionID}.`;
67
+ payload.logger.error({
68
+ err: msg
69
+ });
127
70
  }
128
- });
129
- }); };
130
- exports.default = sendEmail;
131
- //# sourceMappingURL=sendEmail.js.map
71
+ }
72
+ return data;
73
+ };
74
+ const _default = sendEmail;
75
+
76
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9jb2xsZWN0aW9ucy9Gb3JtU3VibWlzc2lvbnMvaG9va3Mvc2VuZEVtYWlsLnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB0eXBlIHsgRW1haWwsIEZvcm1hdHRlZEVtYWlsLCBQbHVnaW5Db25maWcgfSBmcm9tICcuLi8uLi8uLi90eXBlcydcblxuaW1wb3J0IHsgcmVwbGFjZURvdWJsZUN1cmx5cyB9IGZyb20gJy4uLy4uLy4uL3V0aWxpdGllcy9yZXBsYWNlRG91YmxlQ3VybHlzJ1xuaW1wb3J0IHsgc2VyaWFsaXplIH0gZnJvbSAnLi4vLi4vLi4vdXRpbGl0aWVzL3NlcmlhbGl6ZVJpY2hUZXh0J1xuXG5jb25zdCBzZW5kRW1haWwgPSBhc3luYyA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FpbEZyb20sXG4gICAgICAgICAgICAgIGVtYWlsVG8sXG4gICAgICAgICAgICAgIG1lc3NhZ2UsXG4gICAgICAgICAgICAgIHJlcGx5VG86IGVtYWlsUmVwbHlUbyxcbiAgICAgICAgICAgICAgc3ViamVjdCxcbiAgICAgICAgICAgIH0gPSBlbWFpbFxuXG4gICAgICAgICAgICBjb25zdCB0byA9IHJlcGxhY2VEb3VibGVDdXJseXMoZW1haWxUbywgc3VibWlzc2lvbkRhdGEpXG4gICAgICAgICAgICBjb25zdCBjYyA9IGVtYWlsQ0MgPyByZXBsYWNlRG91YmxlQ3VybHlzKGVtYWlsQ0MsIHN1Ym1pc3Npb25EYXRhKSA6ICcnXG4gICAgICAgICAgICBjb25zdCBiY2MgPSBlbWFpbEJDQyA/IHJlcGxhY2VEb3VibGVDdXJseXMoZW1haWxCQ0MsIHN1Ym1pc3Npb25EYXRhKSA6ICcnXG4gICAgICAgICAgICBjb25zdCBmcm9tID0gcmVwbGFjZURvdWJsZUN1cmx5cyhlbWFpbEZyb20sIHN1Ym1pc3Npb25EYXRhKVxuICAgICAgICAgICAgY29uc3QgcmVwbHlUbyA9IHJlcGxhY2VEb3VibGVDdXJseXMoZW1haWxSZXBseVRvIHx8IGVtYWlsRnJvbSwgc3VibWlzc2lvbkRhdGEpXG5cbiAgICAgICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICAgIGJjYyxcbiAgICAgICAgICAgICAgY2MsXG4gICAgICAgICAgICAgIGZyb20sXG4gICAgICAgICAgICAgIGh0bWw6IGA8ZGl2PiR7c2VyaWFsaXplKG1lc3NhZ2UsIHN1Ym1pc3Npb25EYXRhKX08L2Rpdj5gLFxuICAgICAgICAgICAgICByZXBseVRvLFxuICAgICAgICAgICAgICBzdWJqZWN0OiByZXBsYWNlRG91YmxlQ3VybHlzKHN1YmplY3QsIHN1Ym1pc3Npb25EYXRhKSxcbiAgICAgICAgICAgICAgdG8sXG4gICAgICAgICAgICB9XG4gICAgICAgICAgfSxcbiAgICAgICAgKVxuXG4gICAgICAgIGxldCBlbWFpbHNUb1NlbmQgPSBmb3JtYXR0ZWRFbWFpbHNcblxuICAgICAgICBpZiAodHlwZW9mIGJlZm9yZUVtYWlsID09PSAnZnVuY3Rpb24nKSB7XG4gICAgICAgICAgZW1haWxzVG9TZW5kID0gYXdhaXQgYmVmb3JlRW1haWwoZm9ybWF0dGVkRW1haWxzKVxuICAgICAgICB9XG5cbiAgICAgICAgLy8gY29uc3QgbG9nID0gZW1haWxzVG9TZW5kLm1hcCgoeyBodG1sLCAuLi5yZXN0IH0pID0+ICh7IC4uLnJlc3QgfSkpXG5cbiAgICAgICAgYXdhaXQgUHJvbWlzZS5hbGwoXG4gICAgICAgICAgZW1haWxzVG9TZW5kLm1hcChhc3luYyAoZW1haWwpID0+IHtcbiAgICAgICAgICAgIGNvbnN0IHsgdG8gfSA9IGVtYWlsXG4gICAgICAgICAgICB0cnkge1xuICAgICAgICAgICAgICBjb25zdCBlbWFpbFByb21pc2UgPSBhd2FpdCBwYXlsb2FkLnNlbmRFbWFpbChlbWFpbClcbiAgICAgICAgICAgICAgcmV0dXJuIGVtYWlsUHJvbWlzZVxuICAgICAgICAgICAgfSBjYXRjaCAoZXJyOiB1bmtub3duKSB7XG4gICAgICAgICAgICAgIHBheWxvYWQubG9nZ2VyLmVycm9yKHtcbiAgICAgICAgICAgICAgICBlcnI6IGBFcnJvciB3aGlsZSBzZW5kaW5nIGVtYWlsIHRvIGFkZHJlc3M6ICR7dG99LiBFbWFpbCBub3Qgc2VudDogJHtlcnJ9YCxcbiAgICAgICAgICAgICAgfSlcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9KSxcbiAgICAgICAgKVxuICAgICAgfSBlbHNlIHtcbiAgICAgICAgcGF5bG9hZC5sb2dnZXIuaW5mbyh7IG1zZzogJ05vIGVtYWlscyB0byBzZW5kLicgfSlcbiAgICAgIH1cbiAgICB9IGNhdGNoIChlcnI6IHVua25vd24pIHtcbiAgICAgIGNvbnN0IG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DQUFDQyxLQUFLLENBQUM7Z0JBQUVGLEtBQUtJO1lBQUk7UUFDbEM7SUFDRjtJQUVBLE9BQU8zQztBQUNUO01BRUEsV0FBZUgifQ==
@@ -1,3 +1,4 @@
1
1
  import type { CollectionConfig } from 'payload/types';
2
2
  import type { PluginConfig } from '../../types';
3
3
  export declare const generateSubmissionCollection: (formConfig: PluginConfig) => CollectionConfig;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/collections/FormSubmissions/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAErD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAM/C,eAAO,MAAM,4BAA4B,eAAgB,YAAY,KAAG,gBAkIvE,CAAA"}