@punks/backend-entity-manager 0.0.412 → 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,17 +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 = (typeof value === "string" && params.regex?.test(value)) ?? true;
40979
- return {
40980
- isValid: isMinLengthValid && isMaxLengthValid && isRegexValid,
40981
- validationErrors: [
40982
- ...(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 [
40983
40983
  ...(isMinLengthValid
40984
40984
  ? []
40985
40985
  : [
@@ -40999,6 +40999,14 @@ const fieldTextValidator = (item, selector, params) => {
40999
40999
  ...(isRegexValid
41000
41000
  ? []
41001
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,
41002
41010
  ],
41003
41011
  };
41004
41012
  };
@@ -41160,6 +41168,9 @@ let SendgridEmailProvider = class SendgridEmailProvider {
41160
41168
  this.client.setApiKey(sendgridSettings.value.apiKey);
41161
41169
  }
41162
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
+ }
41163
41174
  const processedPayload = await template.processPayload(input.payload);
41164
41175
  const templateData = await template.getTemplateData(processedPayload);
41165
41176
  if (templateData.type === "html") {