package.cjs.cypress-utils.utils.email.js.map Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of neeto-commons-frontend Show documentation
Show all versions of neeto-commons-frontend Show documentation
A package encapsulating common code across neeto projects including initializers, utility functions, common components and hooks and so on.
{"version":3,"file":"email.js","names":["hostname","username","Cypress","env","token","authUrl","concat","headers","Authorization","getSession","cy","request","url","method","getDraftId","_ref","apiUrl","accountId","body","JSON","stringify","using","methodCalls","filter","name","then","_ref2","data","wrap","ids","as","getIdentityId","_ref3","_ref4","identities","list","identityId","find","_ref5","email","id","composeEmail","_ref6","draftId","emailDetails","subject","to","senderName","draftObject","from","keywords","$draft","mailboxIds","_defineProperty2","bodyValues","value","charset","textBody","partId","type","create","draft","onSuccessDestroyEmail","sendIt","emailId","checkForEnvs","Error","sendEmail","_ref7","session","primaryAccounts","get","exports","emailUtils"],"sources":["../../../../src/cypress-utils/utils/email.js"],"sourcesContent":["const hostname = \"api.fastmail.com\";\nconst username = Cypress.env(\"FASTMAIL_USERNAME\") || \"[email protected]\";\nconst token = Cypress.env(\"FASTMAIL_TOKEN\");\n\nconst authUrl = `https://${hostname}/.well-known/jmap`;\nconst headers = {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${token}`,\n};\n\nconst getSession = () => cy.request({ url: authUrl, method: \"GET\", headers });\n\nconst getDraftId = ({ apiUrl, accountId }) => {\n cy.request({\n url: apiUrl,\n method: \"POST\",\n headers,\n body: JSON.stringify({\n using: [\"urn:ietf:params:jmap:core\", \"urn:ietf:params:jmap:mail\"],\n methodCalls: [\n [\"Mailbox/query\", { accountId, filter: { name: \"Drafts\" } }, \"a\"],\n ],\n }),\n }).then(({ body: data }) =>\n cy.wrap(data[\"methodResponses\"][0][1].ids[0]).as(\"draftId\")\n );\n};\n\nconst getIdentityId = ({ apiUrl, accountId }) => {\n cy.request({\n url: apiUrl,\n method: \"POST\",\n headers,\n body: JSON.stringify({\n using: [\n \"urn:ietf:params:jmap:core\",\n \"urn:ietf:params:jmap:mail\",\n \"urn:ietf:params:jmap:submission\",\n ],\n methodCalls: [[\"Identity/get\", { accountId, ids: null }, \"a\"]],\n }),\n }).then(({ body: data }) => {\n const identities = data[\"methodResponses\"][0][1].list;\n const identityId = identities.find(({ email }) => email === username).id;\n cy.wrap(identityId).as(\"identityId\");\n });\n};\n\nconst composeEmail = ({\n apiUrl,\n accountId,\n draftId,\n identityId,\n emailDetails,\n}) => {\n const { subject, body, to, senderName } = emailDetails;\n\n const draftObject = {\n from: [{ email: username, name: senderName }],\n to: [{ email: to }],\n subject,\n keywords: { $draft: true },\n mailboxIds: { [draftId]: true },\n bodyValues: { body: { value: body, charset: \"utf-8\" } },\n textBody: [{ partId: \"body\", type: \"text/plain\" }],\n };\n\n cy.request({\n url: apiUrl,\n method: \"POST\",\n headers,\n body: JSON.stringify({\n using: [\n \"urn:ietf:params:jmap:core\",\n \"urn:ietf:params:jmap:mail\",\n \"urn:ietf:params:jmap:submission\",\n ],\n methodCalls: [\n [\"Email/set\", { accountId, create: { draft: draftObject } }, \"a\"],\n [\n \"EmailSubmission/set\",\n {\n accountId,\n onSuccessDestroyEmail: [\"#sendIt\"],\n create: { sendIt: { emailId: \"#draft\", identityId } },\n },\n \"b\",\n ],\n ],\n }),\n });\n};\n\nconst checkForEnvs = () => {\n if (!username || !token) {\n throw new Error(\n \"Please provide CYPRESS_FASTMAIL_USERNAME and CYPRESS_FASTMAIL_TOKEN as environment variables\"\n );\n }\n};\n\nexport const sendEmail = emailDetails => {\n checkForEnvs();\n getSession().then(({ body: session }) => {\n const { apiUrl, primaryAccounts } = session;\n const accountId = primaryAccounts[\"urn:ietf:params:jmap:mail\"];\n getDraftId({ apiUrl, accountId });\n getIdentityId({ apiUrl, accountId });\n cy.get(\"@draftId\").then(draftId => {\n cy.get(\"@identityId\").then(identityId =>\n composeEmail({ apiUrl, accountId, draftId, identityId, emailDetails })\n );\n });\n });\n};\n\nexport const emailUtils = { sendEmail };\n"],"mappings":";;;;;;;;AAA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