@seamapi/webhook
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -1,13 +0,6 @@ | ||
import type { SeamEvent } from 'seamapi-types'; | ||
export type SeamWebhookEvent = Distribute<SeamEvent['event_type']>; | ||
import type { SeamEvent } from '@seamapi/types/connect'; | ||
export declare class SeamWebhook { | ||
#private; | ||
constructor(secret: string); | ||
verify(payload: string, headers: Record<string, string>): SeamWebhookEvent; | ||
verify(payload: string, headers: Record<string, string>): SeamEvent; | ||
} | ||
type Distribute<EventType> = EventType extends SeamEvent['event_type'] ? { | ||
event_type: EventType; | ||
} & Extract<SeamEvent, { | ||
event_type: EventType; | ||
}>['payload'] : never; | ||
export {}; |
The MIT License (MIT) | ||
Copyright (c) 2021-2023 Seam Labs, Inc. | ||
Copyright (c) 2021-2024 Seam Labs, Inc. | ||
@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of |
{ | ||
"name": "@seamapi/webhook", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Webhook SDK for the Seam API written in TypeScript.", | ||
@@ -69,6 +69,6 @@ "type": "module", | ||
"peerDependencies": { | ||
"seamapi-types": "^2.0.0" | ||
"@seamapi/types": "^1.166.0" | ||
}, | ||
"peerDependenciesMeta": { | ||
"seamapi-types": { | ||
"@seamapi/types": { | ||
"optional": true | ||
@@ -81,2 +81,3 @@ } | ||
"devDependencies": { | ||
"@seamapi/types": "^1.166.0", | ||
"@types/node": "^20.8.10", | ||
@@ -93,3 +94,2 @@ "ava": "^6.0.1", | ||
"prettier": "^3.0.0", | ||
"seamapi-types": "^2.0.0", | ||
"tsc-alias": "^1.8.2", | ||
@@ -96,0 +96,0 @@ "tsup": "^8.0.1", |
@@ -30,6 +30,7 @@ # Seam Webhook SDK | ||
_This is a low-level package meant for applications and libraries with particular dependency requirements. | ||
Before using this package, ensure you understand the installation and updating instructions. | ||
This SDK is entirely contained in the [seam package]. Seam recommends using that package instead | ||
for simpler dependency management._ | ||
> [!IMPORTANT] | ||
> This is a low-level package meant for applications and libraries with particular dependency requirements. | ||
> Before using this package, ensure you understand the installation and updating instructions. | ||
> This SDK is entirely contained in the [seam package]. | ||
> Seam recommends using that package instead for simpler dependency management. | ||
@@ -59,3 +60,3 @@ Add this as a dependency to your project using [npm] with | ||
This package depends on [seamapi-types] for the latest TypeScript types. | ||
This package depends on [@seamapi/types] for the latest TypeScript types. | ||
New versions of this SDK are generally not released when new types are published. | ||
@@ -67,3 +68,3 @@ Unless your project frequently runs a blanket `npm update`, | ||
``` | ||
$ npm install -D seamapi-types | ||
$ npm install -D @seamapi/types | ||
``` | ||
@@ -74,7 +75,5 @@ | ||
``` | ||
$ npm install -D seamapi-types | ||
$ npm install -D @seamapi/types@latest | ||
``` | ||
[seamapi-types]: https://github.com/seamapi/seamapi-types/ | ||
## Usage | ||
@@ -85,5 +84,8 @@ | ||
_This example is for [Express], see the [Svix docs for more examples in specific frameworks](https://docs.svix.com/receiving/verifying-payloads/how)._ | ||
> [!TIP] | ||
> This example is for [Express], see the [Svix docs for more examples in specific frameworks](https://docs.svix.com/receiving/verifying-payloads/how). | ||
```js | ||
import { env } from 'node:process' | ||
import { SeamWebhook } from '@seamapi/webhook' | ||
@@ -93,7 +95,5 @@ import express from 'express' | ||
import { storeEvent } from './store-event.js' | ||
const app = express() | ||
const webhook = new SeamWebhook(process.env.SEAM_WEBHOOK_SECRET) | ||
const webhook = new SeamWebhook(env.SEAM_WEBHOOK_SECRET) | ||
@@ -106,7 +106,6 @@ app.post( | ||
try { | ||
data = webhook.verify(payload, headers) | ||
data = webhook.verify(req.body, req.headers) | ||
} catch { | ||
return res.status(400).send() | ||
} | ||
storeEvent(data, (err) => { | ||
@@ -120,2 +119,11 @@ if (err != null) { | ||
) | ||
const storeEvent = (data, callback) => { | ||
console.log(data) | ||
callback() | ||
} | ||
app.listen(8080, () => { | ||
console.log('Ready to receive webhooks at http://localhost:8080/webhook') | ||
}) | ||
``` | ||
@@ -122,0 +130,0 @@ |
@@ -1,7 +0,4 @@ | ||
import type { SeamEvent } from 'seamapi-types' | ||
import type { SeamEvent } from '@seamapi/types/connect' | ||
import { Webhook } from 'svix' | ||
// UPSTREAM: This type should come from @seamapi/types. | ||
export type SeamWebhookEvent = Distribute<SeamEvent['event_type']> | ||
export class SeamWebhook { | ||
@@ -14,11 +11,5 @@ readonly #webhook: Webhook | ||
verify(payload: string, headers: Record<string, string>): SeamWebhookEvent { | ||
return this.#webhook.verify(payload, headers) as SeamWebhookEvent | ||
verify(payload: string, headers: Record<string, string>): SeamEvent { | ||
return this.#webhook.verify(payload, headers) as SeamEvent | ||
} | ||
} | ||
type Distribute<EventType> = EventType extends SeamEvent['event_type'] | ||
? { | ||
event_type: EventType | ||
} & Extract<SeamEvent, { event_type: EventType }>['payload'] | ||
: never |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
259
16833
79