@punks/backend-entity-manager 0.0.413 → 0.0.414

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.
@@ -1,6 +1,6 @@
1
1
  import { EntryValidationResult } from "../abstractions/serializer";
2
2
  export declare const fieldRequiredValidator: <TSheetItem>(item: TSheetItem, selector: (item: TSheetItem) => any) => EntryValidationResult;
3
- export declare const fieldTextValidator: <TSheetItem>(item: TSheetItem, selector: (item: TSheetItem) => any, params: {
3
+ export declare const fieldTextValidator: <TSheetItem>(item: TSheetItem, selector: (item: TSheetItem) => string | string[], params: {
4
4
  required?: boolean;
5
5
  minLength?: number;
6
6
  maxLength?: number;
package/dist/esm/index.js CHANGED
@@ -40969,19 +40969,17 @@ const fieldRequiredValidator = (item, selector) => {
40969
40969
  };
40970
40970
  const fieldTextValidator = (item, selector, params) => {
40971
40971
  const value = selector(item);
40972
+ const values = Array.isArray(value) ? value : [value];
40972
40973
  const isRequiredValid = params.required
40973
- ? typeof value === "string" && value.length >= 0
40974
+ ? values.length > 0 &&
40975
+ values.every((v) => typeof v === "string" && v.length > 0)
40974
40976
  : true;
40975
- const length = typeof value === "string" ? value.length : 0;
40976
- const isMinLengthValid = length >= (params.minLength ?? 0);
40977
- const isMaxLengthValid = length <= (params.maxLength ?? Infinity);
40978
- const isRegexValid = ((!params.required && !value) ||
40979
- (typeof value === "string" && params.regex?.test(value))) ??
40980
- true;
40981
- return {
40982
- isValid: isMinLengthValid && isMaxLengthValid && isRegexValid && isRequiredValid,
40983
- validationErrors: [
40984
- ...(isRequiredValid ? [] : [{ errorCode: "required" }]),
40977
+ const validateSingle = (v) => {
40978
+ const length = v.length;
40979
+ const isMinLengthValid = length >= (params.minLength ?? 0);
40980
+ const isMaxLengthValid = length <= (params.maxLength ?? Infinity);
40981
+ const isRegexValid = params.regex?.test(v) ?? true;
40982
+ return [
40985
40983
  ...(isMinLengthValid
40986
40984
  ? []
40987
40985
  : [
@@ -41001,6 +40999,14 @@ const fieldTextValidator = (item, selector, params) => {
41001
40999
  ...(isRegexValid
41002
41000
  ? []
41003
41001
  : [{ errorCode: params.regexErrorCode ?? "regex" }]),
41002
+ ];
41003
+ };
41004
+ const allErrors = values.flatMap(validateSingle);
41005
+ return {
41006
+ isValid: isRequiredValid && allErrors.length === 0,
41007
+ validationErrors: [
41008
+ ...(isRequiredValid ? [] : [{ errorCode: "required" }]),
41009
+ ...allErrors,
41004
41010
  ],
41005
41011
  };
41006
41012
  };
@@ -41162,6 +41168,9 @@ let SendgridEmailProvider = class SendgridEmailProvider {
41162
41168
  this.client.setApiKey(sendgridSettings.value.apiKey);
41163
41169
  }
41164
41170
  async sendTemplatedEmail(input, template) {
41171
+ if (!input.to?.length && !input.cc?.length && !input.bcc?.length) {
41172
+ throw new Error(`No recipient specified for email ${input.templateId}`);
41173
+ }
41165
41174
  const processedPayload = await template.processPayload(input.payload);
41166
41175
  const templateData = await template.getTemplateData(processedPayload);
41167
41176
  if (templateData.type === "html") {