@bigbinary/neeto-playwright-commons 1.12.9 → 1.12.11

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/index.cjs.js CHANGED
@@ -114,10 +114,6 @@ const THIRD_PARTY_ROUTES = {
114
114
  const NEETO_ROUTES = {
115
115
  imageUploader: "/neeto_image_uploader_engine",
116
116
  };
117
- const FASTMAIL_ROUTES = {
118
- authorize: "https://api.fastmail.com/.well-known/jmap",
119
- api: "https://api.fastmail.com/jmap/api/",
120
- };
121
117
 
122
118
  const ENVIRONMENT = {
123
119
  development: "development",
@@ -3475,6 +3471,12 @@ const getImagePathAndName = (localImagePath) => {
3475
3471
  class CustomCommands {
3476
3472
  constructor(page, request, baseURL = process.env.BASE_URL) {
3477
3473
  this.waitUntilTimeout = (timeout) => new Promise(resolve => setTimeout(resolve, timeout));
3474
+ this.initializeCsrfToken = async () => {
3475
+ this.csrfToken = await this.page
3476
+ .locator("[name='csrf-token']")
3477
+ .getAttribute("content");
3478
+ return this.csrfToken;
3479
+ };
3478
3480
  this.interceptMultipleResponses = ({ responseUrl = "", responseStatus = 200, times = 1, baseUrl, customPageContext, timeout = 35000, } = {}) => {
3479
3481
  const pageContext = customPageContext !== null && customPageContext !== void 0 ? customPageContext : this.page;
3480
3482
  return Promise.all([...new Array(times)].map(() => pageContext.waitForResponse((response) => {
@@ -3556,9 +3558,8 @@ class CustomCommands {
3556
3558
  ]);
3557
3559
  };
3558
3560
  this.apiRequest = async ({ url, failOnStatusCode = true, headers: additionalHeaders, body: data, method = "get", params = {}, ...otherOptions }) => {
3559
- const csrfToken = await this.page
3560
- .locator("[name='csrf-token']")
3561
- .getAttribute("content");
3561
+ var _a;
3562
+ const csrfToken = (_a = this.csrfToken) !== null && _a !== void 0 ? _a : (await this.initializeCsrfToken());
3562
3563
  const requestOptions = {
3563
3564
  failOnStatusCode,
3564
3565
  headers: {
@@ -11607,24 +11608,23 @@ conventions.NAMESPACE;
11607
11608
  var domParser = domParser$1;
11608
11609
  var DOMParser = domParser.DOMParser;
11609
11610
 
11610
- const dateTimeOneHourAgo = () => new Date(new Date().valueOf() - 60 * 60 * 1000);
11611
- class MailerUtils {
11611
+ class FastmailApi {
11612
11612
  constructor(neetoPlaywrightUtilities) {
11613
11613
  this.neetoPlaywrightUtilities = neetoPlaywrightUtilities;
11614
11614
  this.authorizeAndSetAccountId = async () => {
11615
11615
  const response = await this.neetoPlaywrightUtilities.apiRequest({
11616
11616
  method: "get",
11617
- url: FASTMAIL_ROUTES.authorize,
11618
- headers: this.fastmailHeaders,
11617
+ url: "https://api.fastmail.com/.well-known/jmap",
11618
+ headers: this.headers,
11619
11619
  });
11620
11620
  const { primaryAccounts: { "urn:ietf:params:jmap:mail": accountId }, } = await response.json();
11621
11621
  this.accountId = accountId;
11622
11622
  };
11623
- this.fastmailApiRequest = async (method, body) => {
11623
+ this.apiRequest = async (method, body) => {
11624
11624
  const response = await this.neetoPlaywrightUtilities.apiRequest({
11625
11625
  method: "post",
11626
- url: FASTMAIL_ROUTES.api,
11627
- headers: this.fastmailHeaders,
11626
+ url: "https://api.fastmail.com/jmap/api/",
11627
+ headers: this.headers,
11628
11628
  data: {
11629
11629
  using: ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
11630
11630
  methodCalls: [[method, { accountId: this.accountId, ...body }, "0"]],
@@ -11632,6 +11632,19 @@ class MailerUtils {
11632
11632
  });
11633
11633
  return response === null || response === void 0 ? void 0 : response.json();
11634
11634
  };
11635
+ if (!process.env.NEETO_AUTOMATION_FASTMAIL_API_KEY)
11636
+ throw new Error("Please set the environment variable NEETO_AUTOMATION_FASTMAIL_API_KEYS. Credentials can be found in the Automation Credentials vault in the BigBinary 1Password account.");
11637
+ this.headers = {
11638
+ "Content-Type": "application/json",
11639
+ Authorization: `Bearer ${process.env.NEETO_AUTOMATION_FASTMAIL_API_KEY}`,
11640
+ };
11641
+ }
11642
+ }
11643
+
11644
+ const dateTimeOneHourAgo = () => new Date(new Date().valueOf() - 60 * 60 * 1000);
11645
+ class MailerUtils {
11646
+ constructor(neetoPlaywrightUtilities) {
11647
+ this.neetoPlaywrightUtilities = neetoPlaywrightUtilities;
11635
11648
  this.queryEmail = async (messageSearchCriteria, { receivedAfter = dateTimeOneHourAgo(), page = 1, itemsPerPage = 50, }) => {
11636
11649
  const limit = itemsPerPage;
11637
11650
  const position = (page - 1) * itemsPerPage;
@@ -11643,7 +11656,7 @@ class MailerUtils {
11643
11656
  limit,
11644
11657
  position,
11645
11658
  };
11646
- const { methodResponses: [[, { ids, total }]], } = await this.fastmailApiRequest("Email/query", body);
11659
+ const { methodResponses: [[, { ids, total }]], } = await this.fastmailApi.apiRequest("Email/query", body);
11647
11660
  return { ids, total };
11648
11661
  };
11649
11662
  this.getEmails = async (ids) => {
@@ -11652,7 +11665,7 @@ class MailerUtils {
11652
11665
  bodyProperties: ["type"],
11653
11666
  fetchHTMLBodyValues: true,
11654
11667
  };
11655
- const { methodResponses: [[, { list }]], } = await this.fastmailApiRequest("Email/get", messageDetailsBody);
11668
+ const { methodResponses: [[, { list }]], } = await this.fastmailApi.apiRequest("Email/get", messageDetailsBody);
11656
11669
  const formattedList = list.map((listItem) => {
11657
11670
  var _a;
11658
11671
  const { id, from, to, bodyValues, cc, bcc, replyTo, receivedAt, subject, } = listItem;
@@ -11722,12 +11735,7 @@ class MailerUtils {
11722
11735
  this.generateRandomEmail = () => faker.faker.internet.email({
11723
11736
  provider: process.env.FASTMAIL_DOMAIN_NAME,
11724
11737
  });
11725
- if (!process.env.NEETO_AUTOMATION_FASTMAIL_API_KEY)
11726
- throw new Error("Please set the environment variable NEETO_AUTOMATION_FASTMAIL_API_KEYS. Credentials can be found in the Automation Credentials vault in the BigBinary 1Password account.");
11727
- this.fastmailHeaders = {
11728
- "Content-Type": "application/json",
11729
- Authorization: `Bearer ${process.env.NEETO_AUTOMATION_FASTMAIL_API_KEY}`,
11730
- };
11738
+ this.fastmailApi = new FastmailApi(neetoPlaywrightUtilities);
11731
11739
  }
11732
11740
  }
11733
11741
 
@@ -11786,7 +11794,7 @@ const commands = {
11786
11794
  },
11787
11795
  mailerUtils: async ({ neetoPlaywrightUtilities }, use) => {
11788
11796
  const mailerUtils = new MailerUtils(neetoPlaywrightUtilities);
11789
- await mailerUtils.authorizeAndSetAccountId();
11797
+ await mailerUtils.fastmailApi.authorizeAndSetAccountId();
11790
11798
  await use(mailerUtils);
11791
11799
  },
11792
11800
  };
@@ -24985,8 +24993,21 @@ const MERGE_TAGS_SELECTORS = {
24985
24993
  destinationTagRow: "neeto-tags-merge-destination-tags",
24986
24994
  };
24987
24995
 
24996
+ class TagsApi {
24997
+ constructor(neetoPlaywrightUtilities) {
24998
+ this.neetoPlaywrightUtilities = neetoPlaywrightUtilities;
24999
+ this.create = ({ body, tagsRequestUrl, }) => this.neetoPlaywrightUtilities.apiRequest({
25000
+ url: tagsRequestUrl,
25001
+ body,
25002
+ method: "post",
25003
+ });
25004
+ }
25005
+ }
25006
+
24988
25007
  class TagsPage {
24989
25008
  constructor(page, neetoPlaywrightUtilities) {
25009
+ this.page = page;
25010
+ this.neetoPlaywrightUtilities = neetoPlaywrightUtilities;
24990
25011
  this.searchAndVerifyTags = async (tagName) => {
24991
25012
  await this.page.getByTestId(TAGS_SELECTORS.searchTextField).fill(tagName);
24992
25013
  await test$1.expect(this.page.getByRole("row", { name: tagName })).toBeVisible();
@@ -25054,11 +25075,7 @@ class TagsPage {
25054
25075
  await this.neetoPlaywrightUtilities.verifyToast();
25055
25076
  await test$1.expect(this.page.getByRole("row", { name: tagName })).toBeHidden();
25056
25077
  };
25057
- this.addTagsViaRequest = ({ name, description = "", tagsRequestUrl, }) => this.neetoPlaywrightUtilities.apiRequest({
25058
- url: tagsRequestUrl,
25059
- body: { name, description },
25060
- method: "post",
25061
- });
25078
+ this.addTagsViaRequest = ({ name, description = "", tagsRequestUrl, }) => this.tagsApi.create({ body: { name, description }, tagsRequestUrl });
25062
25079
  this.navigateToMergeTagsPage = async () => {
25063
25080
  await this.page.getByTestId(MERGE_TAGS_SELECTORS.mergeTagsButton).click();
25064
25081
  await this.neetoPlaywrightUtilities.waitForPageLoad();
@@ -25090,9 +25107,8 @@ class TagsPage {
25090
25107
  await test$1.expect(this.page.getByText(sourceTagName)).toBeHidden();
25091
25108
  await test$1.expect(this.page.getByText(destinationTagName)).toBeVisible();
25092
25109
  };
25093
- this.page = page;
25094
- this.neetoPlaywrightUtilities = neetoPlaywrightUtilities;
25095
25110
  this.t = playwrightI18nextFixture.getI18nInstance().t;
25111
+ this.tagsApi = new TagsApi(neetoPlaywrightUtilities);
25096
25112
  }
25097
25113
  }
25098
25114
 
@@ -157291,7 +157307,6 @@ exports.ENVIRONMENT = ENVIRONMENT;
157291
157307
  exports.EXPANDED_FONT_SIZE = EXPANDED_FONT_SIZE;
157292
157308
  exports.EditorPage = EditorPage;
157293
157309
  exports.EmbedBase = EmbedBase;
157294
- exports.FASTMAIL_ROUTES = FASTMAIL_ROUTES;
157295
157310
  exports.FONT_SIZE_SELECTORS = FONT_SIZE_SELECTORS;
157296
157311
  exports.GLOBAL_TRANSLATIONS_PATTERN = GLOBAL_TRANSLATIONS_PATTERN;
157297
157312
  exports.GOOGLE_CALENDAR_DATE_FORMAT = GOOGLE_CALENDAR_DATE_FORMAT;