@punks/backend-entity-manager 0.0.413 → 0.0.415

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/cjs/index.js CHANGED
@@ -198,9 +198,21 @@ class EntitySeeder {
198
198
  }
199
199
  }
200
200
 
201
- const normalizeSheetColumn = (column) => column.replace(/ /g, "").toLowerCase();
202
201
  const DEFAULT_DELIMITER$1 = ";";
203
202
  const DEFAULT_ARRAY_SEPARATOR$1 = "|";
203
+ const normalizeSheetColumn = (column) => column.replace(/ /g, "").toLowerCase();
204
+ const getRealSeparator = (separator) => {
205
+ if (!separator)
206
+ return DEFAULT_ARRAY_SEPARATOR$1;
207
+ if (typeof separator === "string")
208
+ return separator;
209
+ if (separator instanceof RegExp) {
210
+ const separators = separator.source.split("|");
211
+ if (separators.length > 1)
212
+ return separators[0];
213
+ }
214
+ return DEFAULT_ARRAY_SEPARATOR$1;
215
+ };
204
216
  const splitArrayColumn = (value, separator) => value
205
217
  ?.toString()
206
218
  .split(separator ?? DEFAULT_ARRAY_SEPARATOR$1)
@@ -208,7 +220,7 @@ const splitArrayColumn = (value, separator) => value
208
220
  const joinArrayColumn$1 = (value, separator) => value
209
221
  ?.map((x) => x.toString().trim())
210
222
  .filter((x) => x)
211
- .join(separator ?? DEFAULT_ARRAY_SEPARATOR$1);
223
+ .join(getRealSeparator(separator));
212
224
  class EntitySerializer {
213
225
  constructor(services, options) {
214
226
  this.services = services;
@@ -40984,19 +40996,17 @@ const fieldRequiredValidator = (item, selector) => {
40984
40996
  };
40985
40997
  const fieldTextValidator = (item, selector, params) => {
40986
40998
  const value = selector(item);
40999
+ const values = Array.isArray(value) ? value : [value];
40987
41000
  const isRequiredValid = params.required
40988
- ? typeof value === "string" && value.length >= 0
41001
+ ? values.length > 0 &&
41002
+ values.every((v) => typeof v === "string" && v.length > 0)
40989
41003
  : true;
40990
- const length = typeof value === "string" ? value.length : 0;
40991
- const isMinLengthValid = length >= (params.minLength ?? 0);
40992
- const isMaxLengthValid = length <= (params.maxLength ?? Infinity);
40993
- const isRegexValid = ((!params.required && !value) ||
40994
- (typeof value === "string" && params.regex?.test(value))) ??
40995
- true;
40996
- return {
40997
- isValid: isMinLengthValid && isMaxLengthValid && isRegexValid && isRequiredValid,
40998
- validationErrors: [
40999
- ...(isRequiredValid ? [] : [{ errorCode: "required" }]),
41004
+ const validateSingle = (v) => {
41005
+ const length = v.length;
41006
+ const isMinLengthValid = length >= (params.minLength ?? 0);
41007
+ const isMaxLengthValid = length <= (params.maxLength ?? Infinity);
41008
+ const isRegexValid = params.regex?.test(v) ?? true;
41009
+ return [
41000
41010
  ...(isMinLengthValid
41001
41011
  ? []
41002
41012
  : [
@@ -41016,6 +41026,14 @@ const fieldTextValidator = (item, selector, params) => {
41016
41026
  ...(isRegexValid
41017
41027
  ? []
41018
41028
  : [{ errorCode: params.regexErrorCode ?? "regex" }]),
41029
+ ];
41030
+ };
41031
+ const allErrors = values.flatMap(validateSingle);
41032
+ return {
41033
+ isValid: isRequiredValid && allErrors.length === 0,
41034
+ validationErrors: [
41035
+ ...(isRequiredValid ? [] : [{ errorCode: "required" }]),
41036
+ ...allErrors,
41019
41037
  ],
41020
41038
  };
41021
41039
  };
@@ -41177,6 +41195,9 @@ let SendgridEmailProvider = class SendgridEmailProvider {
41177
41195
  this.client.setApiKey(sendgridSettings.value.apiKey);
41178
41196
  }
41179
41197
  async sendTemplatedEmail(input, template) {
41198
+ if (!input.to?.length && !input.cc?.length && !input.bcc?.length) {
41199
+ throw new Error(`No recipient specified for email ${input.templateId}`);
41200
+ }
41180
41201
  const processedPayload = await template.processPayload(input.payload);
41181
41202
  const templateData = await template.getTemplateData(processedPayload);
41182
41203
  if (templateData.type === "html") {