@bigbinary/neeto-commons-frontend 2.1.9 → 2.1.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.
@@ -391,6 +391,12 @@ type Environments = {
391
391
  isNightly: boolean;
392
392
  tld: string;
393
393
  };
394
+ type SendEmailPropsType = {
395
+ to: string;
396
+ subject: string;
397
+ body: string;
398
+ senderName: string;
399
+ };
394
400
  export const memberUtils: {
395
401
  addMemberViaRequest: (props: AddMemberViaRequestPropsType) => void;
396
402
  addMemberViaUI: (props: AddMemberViaUIPropsType) => void;
@@ -419,6 +425,9 @@ export const navigationUtils: {
419
425
  openProfileOrHelpCenter: (props: OpenProfileOrHelpCenterPropTypes) => void;
420
426
  openWhatsNewPane: (props: OpenWhatsNewPanePropTypes) => void;
421
427
  };
428
+ export const emailUtils: {
429
+ sendEmail: (props: SendEmailPropsType) => void;
430
+ };
422
431
 
423
432
  // exporting all selectors
424
433
 
package/cypress-utils.js CHANGED
@@ -1388,5 +1388,160 @@ var verifyCrossSiteScript = function verifyCrossSiteScript(inputSelector, submit
1388
1388
  cy.get(commonSelectors.windowAlert).should("not.exist");
1389
1389
  };
1390
1390
 
1391
- export { authUtils, chatWidgetSelectors, commonSelectors, commonTexts, createOrganization, dataCy, dataTestId, dateUtils, env, environment, getTestTitle, getUrl, helpIconSelectors, helpIconTexts, initCustomCommands, initializeCredentials, isStagingEnv, joinHyphenCase, loginSelectors, memberFormErrorTexts, memberFormSelectors, memberSelectors, memberTableTexts, memberTexts, memberUtils, navigationUtils, profileSelectors, profileTexts, setListCount, signUpSelectors, signUpTexts, tableSelectors, verifyCrossSiteScript, verifyListCount };
1391
+ var hostname = "api.fastmail.com";
1392
+ var username = Cypress.env("CYPRESS_FASTMAIL_USERNAME") || "cypress@mixarrow.com";
1393
+ var token = Cypress.env("CYPRESS_FASTMAIL_TOKEN");
1394
+ var authUrl = "https://".concat(hostname, "/.well-known/jmap");
1395
+ var headers = {
1396
+ "Content-Type": "application/json",
1397
+ Authorization: "Bearer ".concat(token)
1398
+ };
1399
+ var getSession = function getSession() {
1400
+ return cy.request({
1401
+ url: authUrl,
1402
+ method: "GET",
1403
+ headers: headers
1404
+ });
1405
+ };
1406
+ var getDraftId = function getDraftId(_ref) {
1407
+ var apiUrl = _ref.apiUrl,
1408
+ accountId = _ref.accountId;
1409
+ cy.request({
1410
+ url: apiUrl,
1411
+ method: "POST",
1412
+ headers: headers,
1413
+ body: JSON.stringify({
1414
+ using: ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
1415
+ methodCalls: [["Mailbox/query", {
1416
+ accountId: accountId,
1417
+ filter: {
1418
+ name: "Drafts"
1419
+ }
1420
+ }, "a"]]
1421
+ })
1422
+ }).then(function (_ref2) {
1423
+ var data = _ref2.body;
1424
+ return cy.wrap(data["methodResponses"][0][1].ids[0]).as("draftId");
1425
+ });
1426
+ };
1427
+ var getIdentityId = function getIdentityId(_ref3) {
1428
+ var apiUrl = _ref3.apiUrl,
1429
+ accountId = _ref3.accountId;
1430
+ cy.request({
1431
+ url: apiUrl,
1432
+ method: "POST",
1433
+ headers: headers,
1434
+ body: JSON.stringify({
1435
+ using: ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail", "urn:ietf:params:jmap:submission"],
1436
+ methodCalls: [["Identity/get", {
1437
+ accountId: accountId,
1438
+ ids: null
1439
+ }, "a"]]
1440
+ })
1441
+ }).then(function (_ref4) {
1442
+ var data = _ref4.body;
1443
+ var identities = data["methodResponses"][0][1].list;
1444
+ var identityId = identities.find(function (_ref5) {
1445
+ var email = _ref5.email;
1446
+ return email === username;
1447
+ }).id;
1448
+ cy.wrap(identityId).as("identityId");
1449
+ });
1450
+ };
1451
+ var composeEmail = function composeEmail(_ref6) {
1452
+ var apiUrl = _ref6.apiUrl,
1453
+ accountId = _ref6.accountId,
1454
+ draftId = _ref6.draftId,
1455
+ identityId = _ref6.identityId,
1456
+ emailDetails = _ref6.emailDetails;
1457
+ var subject = emailDetails.subject,
1458
+ body = emailDetails.body,
1459
+ to = emailDetails.to,
1460
+ senderName = emailDetails.senderName;
1461
+ var draftObject = {
1462
+ from: [{
1463
+ email: username,
1464
+ name: senderName
1465
+ }],
1466
+ to: [{
1467
+ email: to
1468
+ }],
1469
+ subject: subject,
1470
+ keywords: {
1471
+ $draft: true
1472
+ },
1473
+ mailboxIds: _defineProperty({}, draftId, true),
1474
+ bodyValues: {
1475
+ body: {
1476
+ value: body,
1477
+ charset: "utf-8"
1478
+ }
1479
+ },
1480
+ textBody: [{
1481
+ partId: "body",
1482
+ type: "text/plain"
1483
+ }]
1484
+ };
1485
+ cy.request({
1486
+ url: apiUrl,
1487
+ method: "POST",
1488
+ headers: headers,
1489
+ body: JSON.stringify({
1490
+ using: ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail", "urn:ietf:params:jmap:submission"],
1491
+ methodCalls: [["Email/set", {
1492
+ accountId: accountId,
1493
+ create: {
1494
+ draft: draftObject
1495
+ }
1496
+ }, "a"], ["EmailSubmission/set", {
1497
+ accountId: accountId,
1498
+ onSuccessDestroyEmail: ["#sendIt"],
1499
+ create: {
1500
+ sendIt: {
1501
+ emailId: "#draft",
1502
+ identityId: identityId
1503
+ }
1504
+ }
1505
+ }, "b"]]
1506
+ })
1507
+ });
1508
+ };
1509
+ var checkForEnvs = function checkForEnvs() {
1510
+ if (!username || !token) {
1511
+ throw new Error("Please provide CYPRESS_FASTMAIL_USERNAME and CYPRESS_FASTMAIL_TOKEN as environment variables");
1512
+ }
1513
+ };
1514
+ var sendEmail = function sendEmail(emailDetails) {
1515
+ checkForEnvs();
1516
+ getSession().then(function (_ref7) {
1517
+ var session = _ref7.body;
1518
+ var apiUrl = session.apiUrl,
1519
+ primaryAccounts = session.primaryAccounts;
1520
+ var accountId = primaryAccounts["urn:ietf:params:jmap:mail"];
1521
+ getDraftId({
1522
+ apiUrl: apiUrl,
1523
+ accountId: accountId
1524
+ });
1525
+ getIdentityId({
1526
+ apiUrl: apiUrl,
1527
+ accountId: accountId
1528
+ });
1529
+ cy.get("@draftId").then(function (draftId) {
1530
+ cy.get("@identityId").then(function (identityId) {
1531
+ return composeEmail({
1532
+ apiUrl: apiUrl,
1533
+ accountId: accountId,
1534
+ draftId: draftId,
1535
+ identityId: identityId,
1536
+ emailDetails: emailDetails
1537
+ });
1538
+ });
1539
+ });
1540
+ });
1541
+ };
1542
+ var emailUtils = {
1543
+ sendEmail: sendEmail
1544
+ };
1545
+
1546
+ export { authUtils, chatWidgetSelectors, commonSelectors, commonTexts, createOrganization, dataCy, dataTestId, dateUtils, emailUtils, env, environment, getTestTitle, getUrl, helpIconSelectors, helpIconTexts, initCustomCommands, initializeCredentials, isStagingEnv, joinHyphenCase, loginSelectors, memberFormErrorTexts, memberFormSelectors, memberSelectors, memberTableTexts, memberTexts, memberUtils, navigationUtils, profileSelectors, profileTexts, sendEmail, setListCount, signUpSelectors, signUpTexts, tableSelectors, verifyCrossSiteScript, verifyListCount };
1392
1547
  //# sourceMappingURL=cypress-utils.js.map