0.8.1 โ€ข Published 3 months ago

submitjson v0.8.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

submitjson

npm npm package minimized gzipped size (select exports)

JavaScript client for Submit JSON written in TypeScript. Works in modern browsers, as well as runtimes like Node.js v18+, Bun, Deno, and Edge Runtime.

Quick start

If you haven't already, sign up for a Submit JSON account.

Install the client with a package manager:

npm install submitjson # || pnpm add submitjson || yarn add submitjson

Import and create a new client instance

import SubmitJSON from 'submitjson'

const sj = new SubmitJSON({
  apiKey: 'sjk_xxxxxxxxxxxxxx',
  endpoint: 'XxXxXxXxX'
})

const data = await sj.submit({
  name: 'Yo Yoerson',
  message: 'Yo',
  powerLevel: 9001,
})

console.log('Submission', data)

Table of Contents

Configuration

  • Details

    Import and create a new Submit JSON client instance. We recommend including your endpoint here for easier submit calls down the line. Pass in default options per client to override the current endpoint settings.

  • Type

    interface SubmitJSONConfig {
      apiKey: string
      endpoint?: string
      options: SubmitOptions
    }
    
    interface SubmitOptions {
      emailNotification?: boolean
      emailTo?: string
      emailSubject?: string
      emailReplyTo?: string
      emailBranding?: boolean
      submissionFormat?: 'pretty' | 'raw'
      submissionSound?: 'none' | 'beep' | 'blip' | 'block' | 'coin' | 'ding' | 'dink' | 'honk' | 'jump' | 'ping' | 'pong' | 'snare'
      recaptchaToken?: string
      turnstileToken?: string
      hcaptchaToken?: string
    }
    
    class SubmitJSON {
      constructor(config: SubmitJSONConfig)
      submit(data, options, endpoint): Promise<Submission>
    }
  • Example

    // ~/submitjson.ts
    import SubmitJSON from 'submitjson'
    
    export const sj = new SubmitJSON({
      apiKey: 'sjk_xxxxxxxxxxxxxx',
      endpoint: 'XxXxXxXxX',
      options: { // set defaults for this client & override endpoint settings
        emailNotification: true,
        submissionFormat: 'raw',
        submissionSound: 'none',
      },
    })

API

submit()

  • Details

    POST your data to an endpoint and get notified in real time.

    submit() takes three arguments:

    1. The data (must be a valid JSON object, JSON string, or FormData)
    2. Optional configuration to override the endpoint's default settings. If this argument is a string it is treated as the endpoint for submitting data
    3. An optional endpoint.
  • Type

    function submit(
      data: Record<string, unknown> | string | FormData,
      options?: SubmitOptions,
      endpoint?: string
    ): Promise<Submission>
  • Example with all configuration options

    import SubmitJSON from 'submitjson'
    
    const sj = new SubmitJSON({
      apiKey: 'sjk_xxxxxxxxxxxxxx',
      endpoint: 'XxXxXxXxX',
    })
    
    const data = await sj.submit({
      name: 'Yo Yoerson',
      message: 'Yo',
      powerLevel: 9001,
    }, {
      emailNotification: true,
      emailTo: 'yo@yoerson.com',
      emailReplyTo: 'diff@differson.com',
      emailBranding: false,
      emailSubject: 'My custom subject line',
      submissionFormat: 'pretty',
      submissionSound: 'ping',
      recaptchaToken: 'xxxxxxxxxxx'
    }, 'YyYyYyYyY') // overrides the endpoint set in the configuration
    
    console.log('Submission', data)
  • Example with multiple clients

    Initialize multiple clients for a seperation of concerns.

    // submitjson.ts
    import SubmitJSON from 'submitjson'
    
    export const contactForm = new SubmitJSON({
      apiKey: 'sjk_xxxxxxxxxxxxxx',
      endpoint: 'XxXxXxXxX',
    })
    
    export const userSignupNotification = new SubmitJSON({
      apiKey: 'sjk_xxxxxxxxxxxxxx',
      endpoint: 'ZzZzZzZzZ',
    })
    // somewhere else in your code
    const data = { name: 'Yo Yoerson', message: 'Yo' }
    await contactForm.submit(data)
    await userSignupNotification.submit(data)

Submit JSON Links

License

MIT License ยฉ 2023 Submit JSON

0.8.1

3 months ago

0.8.0

3 months ago

0.7.0

4 months ago

0.6.0

4 months ago

0.5.1

4 months ago

0.5.0

5 months ago

0.4.1

5 months ago

0.4.0

6 months ago

0.3.0

6 months ago

0.2.0

6 months ago

0.1.0

6 months ago

0.0.2

6 months ago

0.0.1

6 months ago