Skip to content

Instantiating Mail class with personalizations overrides the substitution wrapper of the provided personalizations #1430

@abetoots

Description

@abetoots

An example pseudo code:

  import { classes as sgClasses } from "@sendgrid/helpers";

  const Mail = sgClasses.Mail;
  const Personalization = sgClasses.Personalization;

  const samplePersonalization =  new Personalization();
  samplePersonalization.setTo("[email protected]");
  samplePersonalization.addSubstitution("name", "Sample");
  samplePersonalization.setSubstitutionWrappers(["%%", "%%"]);

  //sample data
  const data = {
    ...,
    personalizations: [samplePersonalization]
  };

  const mail = new Mail(data);

Expected mail structure:

//mail.toJSON() result
{
 personalizations: [
       {
        substitutions: {
          '%%name%%': 'Sample'
          }
       }
  ]
}

Actual:

//mail.toJSON() result
{
 personalizations: [
       {
        substitutions: {
          '{{%%name%%}}': 'Sample'
          }
       }
  ]
}

As you can see, it is adding the default wrappers. I found the issue is because it does not pass this line because the data is being deep cloned here

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions