Skip to content

Commit

Permalink
email notification upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanmcgowan committed Jan 3, 2024
1 parent d8cd294 commit df5f2f8
Show file tree
Hide file tree
Showing 4 changed files with 225 additions and 183 deletions.
9 changes: 9 additions & 0 deletions .changeset/stupid-apes-refuse.md
@@ -0,0 +1,9 @@
---
"submitjson": minor
---

Email notification enhancements
- You can now customize the email notification subject line with the `emailSubject` option
- You can now remove Submit JSON branding with the `emailBranding` option
- `submissionRecipient` renamed to `emailTo`

8 changes: 6 additions & 2 deletions README.md
Expand Up @@ -59,9 +59,11 @@ console.log('Submission', data)

interface SubmitOptions {
emailNotification?: boolean
emailTo?: string
emailSubject?: string
emailReplyTo?: string
emailBranding?: boolean
submissionFormat?: 'raw' | 'pretty'
submissionRecipient?: string
submissionSound?: 'none' | 'beep' | 'blip' | 'block' | 'coin' | 'ding' | 'dink' | 'honk' | 'jump' | 'ping' | 'pong' | 'snare'
}

Expand Down Expand Up @@ -125,10 +127,12 @@ console.log('Submission', data)
powerLevel: 9001,
}, {
emailNotification: true,
emailTo: 'yo@yoerson.com',
emailReplyTo: 'diff@differson.com',
emailBranding: false,
emailSubject: 'My custom subject line',
submissionFormat: 'pretty',
submissionSound: 'ping',
submissionRecipient: 'yo@yoerson.com',
}, 'YyYyYyYyY') // this overrides the endpoint set in the configuration
console.log('Submission', data)
Expand Down
14 changes: 8 additions & 6 deletions index.ts
Expand Up @@ -13,10 +13,12 @@ interface SubmitJSONConfig {

interface SubmitOptions {
emailNotification?: boolean
emailTo?: string
emailSubject?: string
emailReplyTo?: string
emailBranding?: boolean
submissionFormat?: 'raw' | 'pretty'
submissionSound?: 'none' | 'beep' | 'blip' | 'block' | 'coin' | 'ding' | 'dink' | 'honk' | 'jump' | 'ping' | 'pong' | 'snare'
submissionRecipient?: string
}

type RequestOptions = components['schemas']['SubmissionInput']['options']
Expand Down Expand Up @@ -53,7 +55,7 @@ export default class SubmitJSON {
const s = JSON.parse(data)

if (typeof s !== 'object')
throw new Error(`🕱 The string you pass in must parse into an object e.g. { your: 'string' }`)
throw new Error(`☠️ The string you pass in must parse into a valid JSON object e.g. { your: 'string' }`)

d = s
}
Expand All @@ -63,7 +65,7 @@ export default class SubmitJSON {
d = data
}
else {
throw new TypeError('🕱 The first argument must be a valid JSON object, string, or FormData')
throw new TypeError('☠️ The first argument must be a valid JSON object, string, or FormData')
}
// **HANDLE OPTIONS**
// if second param is a string assume it is an endpoint
Expand All @@ -75,7 +77,7 @@ export default class SubmitJSON {

// if no endpoint slug throw error
if (endpointSlug === undefined)
throw new Error('🕱 No endpoint defined. Add one to your client configuration or to this submit call.')
throw new Error('☠️ No endpoint defined. Add one to your client configuration or to this submit call.')

// define the body to submit in a sec
const body: RequestBody = { data: d }
Expand All @@ -94,8 +96,8 @@ export default class SubmitJSON {
// check to make sure the options are valid
if (o) {
// deletes any undefined keys
const { emailNotification, submissionFormat, submissionSound, emailReplyTo, submissionRecipient } = o
const options: RequestOptions = { emailNotification, submissionFormat, submissionSound, emailReplyTo, submissionRecipient }
const { emailNotification, submissionFormat, submissionSound, emailReplyTo, emailTo, emailSubject, emailBranding } = o
const options: RequestOptions = { emailNotification, submissionFormat, submissionSound, emailReplyTo, emailTo, emailBranding, emailSubject }
Object.keys(options).forEach(key => options && options[key as keyof SubmitOptions] === undefined && delete options[key as keyof SubmitOptions])

if (Object.keys(options).length > 0)
Expand Down

0 comments on commit df5f2f8

Please sign in to comment.