Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace SeamWebookEvent with SeamEvent #6

Merged
merged 5 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/generate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ jobs:
uses: ./.github/actions/setup
with:
install_dependencies: 'false'
- name: Sync @seamapi/types version in peerDependencies
run: |
sudo apt-get install -y jq moreutils
jq '.peerDependencies."@seamapi/types" = .devDependencies."@seamapi/types"' package.json | sponge package.json
- name: Normalize package-lock.json
run: npm install
- name: Commit
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ in your application.

## Installation

_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.
Add this as a dependency to your project using [npm] with

Expand All @@ -55,30 +56,29 @@ Refer to the next section for keeping the types updated.

#### Keeping up with the latest types

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.
Unless your project frequently runs a blanket `npm update`,
the types will become outdated with the Seam API over time.
Thus, users of this package should explicitly install the types with

```
$ npm install -D seamapi-types
$ npm install -D @seamapi/types
```

and update them when consuming new API features with

```
$ npm install -D seamapi-types
$ npm install -D @seamapi/types@latest
```

[seamapi-types]: https://github.com/seamapi/seamapi-types/

## Usage

First, create a webhook using the Seam API or Seam Console
and obtain a Seam webhook secret.

_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 { SeamWebhook } from '@seamapi/webhook'
Expand Down
52 changes: 26 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 3 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,18 @@
"npm": ">= 9.0.0"
},
"peerDependencies": {
"seamapi-types": "^1.42.0",
"type-fest": "^4.0.0"
"@seamapi/types": "^1.166.0"
},
"peerDependenciesMeta": {
"seamapi-types": {
"optional": true
},
"type-fest": {
"@seamapi/types": {
"optional": true
}
},
"dependencies": {
"svix": "^1.15.0"
},
"devDependencies": {
"@seamapi/types": "^1.166.0",
"@types/node": "^20.8.10",
"ava": "^6.0.1",
"c8": "^9.0.0",
Expand All @@ -92,11 +89,9 @@
"eslint-plugin-simple-import-sort": "^12.0.0",
"eslint-plugin-unused-imports": "^3.0.0",
"prettier": "^3.0.0",
"seamapi-types": "^1.42.0",
"tsc-alias": "^1.8.2",
"tsup": "^8.0.1",
"tsx": "^4.6.2",
"type-fest": "^4.14.0",
"typescript": "^5.1.0"
}
}
15 changes: 3 additions & 12 deletions src/lib/seam-webhook.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
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 {
readonly #webhook: Webhook

constructor(secret: string) {
this.#webhook = new Webhook(secret)
}

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
Loading