From fc7536ff3155991238fe4a8d16f94c85d6c2e5fa Mon Sep 17 00:00:00 2001 From: Jesse Shawl Date: Thu, 21 Mar 2024 17:37:14 -0500 Subject: [PATCH 1/5] add type input --- src/mail.js | 4 ++-- src/mail.test.js | 8 +++++++- src/test.js | 5 +++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/mail.js b/src/mail.js index e84fd4a..d18f3f4 100644 --- a/src/mail.js +++ b/src/mail.js @@ -1,9 +1,9 @@ -export const payload = ({ subject, to, body, attachments }) => ({ +export const payload = ({ subject, to, type, body, attachments }) => ({ // https://docs.sendgrid.com/api-reference/mail-send/mail-send#body attachments, content: [ { - type: 'text/plain', + type: type ?? 'text/plain', value: body ?? ' ', }, ], diff --git a/src/mail.test.js b/src/mail.test.js index 3bf0290..62b1507 100644 --- a/src/mail.test.js +++ b/src/mail.test.js @@ -7,7 +7,7 @@ const fixture = { attachments: input.attachments, content: [ { - type: 'text/plain', + type: 'text/html', value: input.body, }, ], @@ -48,6 +48,12 @@ describe('mail', () => { }); describe('payload', () => { + it('supports a type', () => { + input.type = 'text/html' + expect(payload(input).content[0].type).toBe('text/html') + input.type = 'text/plain' + expect(payload(input).content[0].type).toBe('text/plain') + }) it('supports multiple recipients', () => { expect( payload({ to: 'one@example.com,two@example.com' }).personalizations[0].to, diff --git a/src/test.js b/src/test.js index d1f2b02..3e07184 100644 --- a/src/test.js +++ b/src/test.js @@ -6,9 +6,10 @@ export const input = { filename: 'hello.txt', }, ], - body: 'this is the body', + body: '

an html body

', subject: 'hello', to: 'ex@mple.com', + type: 'text/html' }; -export const inputUrlEncoded = `to=${input.to}&subject=${input.subject}&body=${input.body}&attachments[][type]=text/plain&attachments[][content]=aGVsbG8sIHdvcmxkIQ==&attachments[][filename]=hello.txt`; +export const inputUrlEncoded = `to=${input.to}&subject=${input.subject}&body=${input.body}&attachments[][type]=text/plain&attachments[][content]=aGVsbG8sIHdvcmxkIQ==&attachments[][filename]=hello.txt&type=text/html`; From b0a85cb8b4a88dc95fb2e5990dbabfcf40a50931 Mon Sep 17 00:00:00 2001 From: Jesse Shawl Date: Thu, 21 Mar 2024 17:43:47 -0500 Subject: [PATCH 2/5] format --- src/mail.test.js | 10 +++++----- src/test.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/mail.test.js b/src/mail.test.js index 62b1507..4247d16 100644 --- a/src/mail.test.js +++ b/src/mail.test.js @@ -49,11 +49,11 @@ describe('mail', () => { describe('payload', () => { it('supports a type', () => { - input.type = 'text/html' - expect(payload(input).content[0].type).toBe('text/html') - input.type = 'text/plain' - expect(payload(input).content[0].type).toBe('text/plain') - }) + input.type = 'text/html'; + expect(payload(input).content[0].type).toBe('text/html'); + input.type = 'text/plain'; + expect(payload(input).content[0].type).toBe('text/plain'); + }); it('supports multiple recipients', () => { expect( payload({ to: 'one@example.com,two@example.com' }).personalizations[0].to, diff --git a/src/test.js b/src/test.js index 3e07184..3df2830 100644 --- a/src/test.js +++ b/src/test.js @@ -9,7 +9,7 @@ export const input = { body: '

an html body

', subject: 'hello', to: 'ex@mple.com', - type: 'text/html' + type: 'text/html', }; export const inputUrlEncoded = `to=${input.to}&subject=${input.subject}&body=${input.body}&attachments[][type]=text/plain&attachments[][content]=aGVsbG8sIHdvcmxkIQ==&attachments[][filename]=hello.txt&type=text/html`; From d7ee57e0e755922569ab3f7b944b5b61672514d9 Mon Sep 17 00:00:00 2001 From: Jesse Shawl Date: Thu, 21 Mar 2024 18:04:32 -0500 Subject: [PATCH 3/5] deploy to staging --- .github/workflows/node.js.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 0bf6435..e46b18c 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -23,6 +23,18 @@ jobs: - run: npm run lint - run: npm run format:check - run: npm test + deploy_staging: + runs-on: ubuntu-latest + needs: test + if: github.ref != 'refs/heads/main' + environment: staging + steps: + - uses: actions/checkout@v4 + - name: Deploy + run: npx wrangler deploy -e staging + env: + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} deploy: runs-on: ubuntu-latest needs: test From 0b90bcc55d8d04cf2cc6b75fc720bf77766d2b83 Mon Sep 17 00:00:00 2001 From: Jesse Shawl Date: Thu, 21 Mar 2024 18:06:20 -0500 Subject: [PATCH 4/5] add staging env --- wrangler.toml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/wrangler.toml b/wrangler.toml index 2cf3e7e..463e3cf 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -4,4 +4,9 @@ compatibility_date = "2024-03-04" compatibility_flags = ["nodejs_compat"] routes = [ { pattern = "www.cinotify.cc/api/*", zone_id = "8b83258726802e1e77310bd3b08dfefa" } +] + +[env.staging] +routes = [ + { pattern = "staging.cinotify.cc/api/*", zone_id = "8b83258726802e1e77310bd3b08dfefa" } ] \ No newline at end of file From 8feca5e1b0a6776f0dd11000118c28808b5730c0 Mon Sep 17 00:00:00 2001 From: Jesse Shawl Date: Thu, 21 Mar 2024 18:10:20 -0500 Subject: [PATCH 5/5] set environment url --- .github/workflows/node.js.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index e46b18c..9b9b429 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -27,7 +27,9 @@ jobs: runs-on: ubuntu-latest needs: test if: github.ref != 'refs/heads/main' - environment: staging + environment: + name: staging + url: https://staging.cinotify.cc/api/notify steps: - uses: actions/checkout@v4 - name: Deploy @@ -39,7 +41,9 @@ jobs: runs-on: ubuntu-latest needs: test if: github.ref == 'refs/heads/main' - environment: production + environment: + name: production + url: https://www.cinotify.cc/api/notify steps: - uses: actions/checkout@v4 - name: Deploy