@bigbinary/neeto-playwright-commons 4.2.3 → 4.2.4

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 (3) hide show
  1. package/index.d.ts +12 -1
  2. package/index.js +53 -4
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -898,6 +898,7 @@ interface RailsEmail {
898
898
  htmlBody?: string;
899
899
  textBody?: string;
900
900
  receivedAt: string;
901
+ messageId?: string;
901
902
  attachments?: RailsEmailAttachment[];
902
903
  }
903
904
  interface BaseRailsEmailSearchParams {
@@ -1249,6 +1250,7 @@ interface FormattedList$1 {
1249
1250
  subject: string;
1250
1251
  attachments: Attachment$1[];
1251
1252
  blobId: string;
1253
+ messageId?: string;
1252
1254
  }
1253
1255
  interface AttachmentDetails$1 {
1254
1256
  filename: string | null;
@@ -1263,7 +1265,7 @@ declare class RailsEmailUtils {
1263
1265
  private convertRailsEmailToFormattedList;
1264
1266
  clearEmails: () => Promise<unknown>;
1265
1267
  clearStaleEmails: () => Promise<unknown>;
1266
- getLatestEmail: (searchParams: RailsEmailSearchParams) => Promise<void>;
1268
+ getLatestEmail: (searchParams: RailsEmailSearchParams) => Promise<RailsEmail | null>;
1267
1269
  listEmails: (searchParams?: RailsEmailSearchParams) => Promise<RailsEmail[]>;
1268
1270
  /**
1269
1271
  *
@@ -1403,6 +1405,10 @@ declare class RailsEmailUtils {
1403
1405
  receivedAfter,
1404
1406
  expectedEmailCount
1405
1407
  }?: Partial<FindMessageFilterOptions$1> | undefined, shouldThrowErrorOnTimeout?: boolean) => Promise<FormattedList$1 | Record<string, never>>;
1408
+ getLatestMessageId: (subject: string, {
1409
+ timeout,
1410
+ receivedAfter
1411
+ }?: Partial<FindMessageFilterOptions$1> | undefined) => Promise<string | undefined>;
1406
1412
  /**
1407
1413
  *
1408
1414
  * A helper method that is used to find the first code value from the matching email body. This method has been built to match the Neeto OTP emails.
@@ -1615,6 +1621,7 @@ interface FormattedList {
1615
1621
  subject: string;
1616
1622
  attachments: Attachment[];
1617
1623
  blobId: string;
1624
+ messageId?: string;
1618
1625
  }
1619
1626
  declare class MailerUtils {
1620
1627
  private neetoPlaywrightUtilities;
@@ -1800,6 +1807,10 @@ declare class MailerUtils {
1800
1807
  *
1801
1808
  */
1802
1809
  generateRandomEmail: () => string;
1810
+ getLatestMessageId: (subject: string, {
1811
+ timeout,
1812
+ receivedAfter
1813
+ }?: Partial<FindMessageFilterOptions> | undefined) => Promise<string | undefined>;
1803
1814
  /**
1804
1815
  *
1805
1816
  * This method is used to return an attachment from the first email matching the search criteria. It supports filtering attachments by name, by MIME content-type, or both. If no matching attachment is found, an error is thrown.
package/index.js CHANGED
@@ -351,6 +351,7 @@ class RailsEmailApiClient {
351
351
  htmlBody: raw.html_body,
352
352
  textBody: raw.text_body,
353
353
  receivedAt: raw.received_at,
354
+ ...(raw.message_id && { messageId: raw.message_id }),
354
355
  attachments: raw.attachments?.map(({ filename, mime_type, data }) => ({
355
356
  name: filename,
356
357
  type: mime_type,
@@ -69653,6 +69654,7 @@ class RailsEmailUtils {
69653
69654
  type: att.type,
69654
69655
  })) || [],
69655
69656
  blobId: "",
69657
+ ...(railsEmail.messageId && { messageId: railsEmail.messageId }),
69656
69658
  };
69657
69659
  };
69658
69660
  clearEmails = () => this.railsEmailClient.clearEmails();
@@ -69662,7 +69664,7 @@ class RailsEmailUtils {
69662
69664
  };
69663
69665
  getLatestEmail = async (searchParams) => {
69664
69666
  await this.clearStaleEmails();
69665
- await this.railsEmailClient.getLatestEmail(searchParams);
69667
+ return this.railsEmailClient.getLatestEmail(searchParams);
69666
69668
  };
69667
69669
  listEmails = (searchParams) => this.railsEmailClient.listEmails(searchParams);
69668
69670
  listMessages = async (messageSearchCriteria = {}, { receivedAfter = new Date(new Date().valueOf() - 60 * 60 * 1000), } = {}) => {
@@ -69702,6 +69704,12 @@ class RailsEmailUtils {
69702
69704
  }
69703
69705
  return email;
69704
69706
  };
69707
+ getLatestMessageId = async (subject, { timeout = 10_000, receivedAfter = new Date(new Date().valueOf() - 60 * 1000), } = {}) => {
69708
+ const email = await this.findMessage({ subject }, { timeout, receivedAfter }, false);
69709
+ if (!("messageId" in email) || !email.messageId)
69710
+ return undefined;
69711
+ return email.messageId.replace(/^<|>$/g, "");
69712
+ };
69705
69713
  findOtpFromEmail = async ({ email, subjectSubstring = OTP_EMAIL_PATTERN, timeout = 10_000, receivedAfter = new Date(), expectedEmailCount = 1, }) => {
69706
69714
  const otp = await this.neetoPlaywrightUtilities.executeRecursively({
69707
69715
  callback: async () => {
@@ -69815,7 +69823,7 @@ class MailerUtils {
69815
69823
  };
69816
69824
  const { methodResponses: [[, { list }]], } = await this.fastmailApi.apiRequest("Email/get", messageDetailsBody);
69817
69825
  const formattedList = list.map((listItem) => {
69818
- const { id, from, to, bodyValues, cc, bcc, replyTo, receivedAt, subject, attachments, blobId, } = listItem;
69826
+ const { id, from, to, bodyValues, cc, bcc, replyTo, receivedAt, subject, messageId, attachments, blobId, } = listItem;
69819
69827
  const emailBody = Object.values(pluck("value", bodyValues)).join(" ");
69820
69828
  const emailBodyWithStrippedHead = emailBody.split("</head>").at(-1);
69821
69829
  const links = emailBodyWithStrippedHead.match(LINK_REGEX);
@@ -69846,6 +69854,7 @@ class MailerUtils {
69846
69854
  subject,
69847
69855
  attachments,
69848
69856
  blobId,
69857
+ ...(messageId?.[0] && { messageId: messageId[0] }),
69849
69858
  };
69850
69859
  });
69851
69860
  return formattedList;
@@ -69866,10 +69875,10 @@ class MailerUtils {
69866
69875
  return ids;
69867
69876
  },
69868
69877
  condition: async () => {
69869
- const { total } = await this.queryEmail(messageSearchCriteria, {
69878
+ const { ids } = await this.queryEmail(messageSearchCriteria, {
69870
69879
  receivedAfter,
69871
69880
  });
69872
- return total >= expectedEmailCount;
69881
+ return ids.length >= expectedEmailCount;
69873
69882
  },
69874
69883
  timeout,
69875
69884
  }));
@@ -69926,6 +69935,46 @@ class MailerUtils {
69926
69935
  return codes?.[0];
69927
69936
  };
69928
69937
  generateRandomEmail = () => faker.internet.email({ provider: process.env.FASTMAIL_DOMAIN_NAME });
69938
+ getLatestMessageId = async (subject, { timeout = 10_000, receivedAfter = dateTimeOneHourAgo(), } = {}) => {
69939
+ if (IS_DEV_ENV) {
69940
+ return this.railsEmailUtils.getLatestMessageId(subject, {
69941
+ timeout: timeout / 3,
69942
+ receivedAfter,
69943
+ });
69944
+ }
69945
+ if (!this.accountId) {
69946
+ await this.fastmailApi.authorizeAndSetAccountId();
69947
+ }
69948
+ const messageId = (await this.neetoPlaywrightUtilities.executeRecursively({
69949
+ callback: async () => {
69950
+ const { methodResponses: [[, { ids }]], } = await this.fastmailApi.apiRequest("Email/query", {
69951
+ filter: { subject, after: receivedAfter.toISOString() },
69952
+ sort: [{ property: "receivedAt", isAscending: false }],
69953
+ limit: 1,
69954
+ });
69955
+ const emailId = ids?.[0];
69956
+ if (!emailId)
69957
+ return null;
69958
+ const { methodResponses: [[, { list }]], } = await this.fastmailApi.apiRequest("Email/get", {
69959
+ ids: [emailId],
69960
+ properties: ["messageId"],
69961
+ });
69962
+ const rawMessageId = list?.[0]?.messageId?.[0];
69963
+ if (!rawMessageId)
69964
+ return null;
69965
+ return rawMessageId.replace(/^<|>$/g, "");
69966
+ },
69967
+ condition: async () => {
69968
+ const { methodResponses: [[, { ids }]], } = await this.fastmailApi.apiRequest("Email/query", {
69969
+ filter: { subject, after: receivedAfter.toISOString() },
69970
+ limit: 1,
69971
+ });
69972
+ return ids.length >= 1;
69973
+ },
69974
+ timeout,
69975
+ }));
69976
+ return messageId || undefined;
69977
+ };
69929
69978
  getEmailAttachment = async ({ name, type }, messageSearchCriteria = {}, { timeout = 10_000, receivedAfter = dateTimeOneHourAgo(), expectedEmailCount = 1, } = {}, shouldThrowErrorOnTimeout = true) => {
69930
69979
  if (IS_DEV_ENV)
69931
69980
  return this.railsEmailUtils.getEmailAttachment({ name, type }, messageSearchCriteria, { receivedAfter, expectedEmailCount, timeout: timeout / 3 }, shouldThrowErrorOnTimeout);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/neeto-playwright-commons",
3
- "version": "4.2.3",
3
+ "version": "4.2.4",
4
4
  "description": "A package encapsulating common playwright code across neeto projects.",
5
5
  "repository": "git@github.com:bigbinary/neeto-playwright-commons.git",
6
6
  "license": "apache-2.0",