@@ -7,17 +7,112 @@ Webhook SDK for the Seam API written in TypeScript.
77
88## Description
99
10- TODO
10+ [ Seam] makes it easy to integrate IoT devices with your applications.
11+ This is an official SDK for the Seam API.
12+ Please refer to the official [ Seam Docs] to get started.
13+
14+ The Seam API implements webhooks using [ Svix] .
15+ This SDK exports a thin wrapper around the svix package
16+ Use it to parse and validate Seam webhook events
17+ with full TypeScript support for Seam event types.
18+
19+ Refer to the [ Svix docs on Consuming Webhooks] for
20+ an in-depth guide on best-practices for handling webhooks
21+ in your application.
22+
23+ [ Seam ] : https://www.seam.co/
24+ [ Seam Docs ] : https://docs.seam.co/latest/
25+ [ Svix ] : https://www.svix.com/
26+ [ Svix docs on Consuming Webhooks ] : https://docs.svix.com/receiving/introduction
1127
1228## Installation
1329
30+ _ This is a low-level package meant for applications and libraries with particular dependency requirements.
31+ Before using this package, ensure you understand the installation and updating instructions.
32+ This SDK is entirely contained in the [ seamapi] package. Seam recommends using that package instead
33+ for simpler dependency management._
34+
1435Add this as a dependency to your project using [ npm] with
1536
1637```
1738$ npm install @seamapi/webhook
1839```
1940
2041[ npm ] : https://www.npmjs.com/
42+ [ seamapi ] : https://www.npmjs.com/package/seamapi
43+
44+ ### Optional Peer Dependencies for TypeScript
45+
46+ This package has optional peer dependencies for TypeScript users.
47+ Recent versions of npm will automatically install peer dependencies by default.
48+ For those users, no additional steps are necessary for full TypeScript support,
49+ however users should still explicitly install the latest types (see the next section).
50+
51+ Other package managers require peer dependencies to be added manually.
52+ Refer to any warnings generated by your package manager
53+ about missing peer dependencies and install them as needed.
54+ Refer to the next section for keeping the types updated.
55+
56+ #### Keeping up with the latest types
57+
58+ This package depends on [ seamapi-types] for the latest TypeScript types.
59+ New versions of this SDK are generally not released when new types are published.
60+ Unless your project frequently runs a blanket ` npm update ` ,
61+ the types will become outdated with the Seam API over time.
62+ Thus, users of this package should explicitly install the types with
63+
64+ ```
65+ $ npm install -D seamapi-types
66+ ```
67+
68+ and update them when consuming new API features with
69+
70+ ```
71+ $ npm install -D seamapi-types
72+ ```
73+
74+ [ seamapi-types ] : https://github.com/seamapi/seamapi-types/
75+
76+ ## Usage
77+
78+ First, create a webhook using the Seam API or Seam Console
79+ and obtain a Seam webhook secret.
80+
81+ _ This example is for [ Express] , see the [ Svix docs for more examples in specific frameworks] ( https://docs.svix.com/receiving/verifying-payloads/how ) ._
82+
83+ ``` js
84+ import { SeamWebhook } from ' @seamapi/webhook'
85+ import express from ' express'
86+ import bodyParser from ' body-parser'
87+
88+ import { storeEvent } from ' ./store-event.js'
89+
90+ const app = express ()
91+
92+ const webhook = new SeamWebhook (process .env .SEAM_WEBHOOK_SECRET )
93+
94+ app .post (
95+ ' /webhook' ,
96+ bodyParser .raw ({ type: ' application/json' }),
97+ (req , res ) => {
98+ let data
99+ try {
100+ data = webhook .verify (payload, headers)
101+ } catch {
102+ return res .status (400 ).send ()
103+ }
104+
105+ storeEvent (data, (err ) => {
106+ if (err != null ) {
107+ return res .status (500 ).send ()
108+ }
109+ res .status (204 ).send ()
110+ })
111+ },
112+ )
113+ ```
114+
115+ [ Express ] : https://expressjs.com/
21116
22117## Development and Testing
23118
0 commit comments