Skip to content
This repository was archived by the owner on Nov 15, 2024. It is now read-only.

Commit 84f5df8

Browse files
committed
Use type package
1 parent d3f9487 commit 84f5df8

File tree

12 files changed

+38
-159
lines changed

12 files changed

+38
-159
lines changed

docs/classes/SeamWebhook.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Create a new instance of SeamWebhook.
5050

5151
### verify
5252

53-
**verify**(`payload`, `headers`): [`SeamEvent`](../modules.md#seamevent)
53+
**verify**(`payload`, `headers`): [`SeamWebhookEvent`](../modules.md#seamwebhookevent)
5454

5555
Verify a payload received from a webhook and return the typed event.
5656

@@ -63,7 +63,7 @@ Verify a payload received from a webhook and return the typed event.
6363

6464
#### Returns
6565

66-
[`SeamEvent`](../modules.md#seamevent)
66+
[`SeamWebhookEvent`](../modules.md#seamwebhookevent)
6767

6868
event
6969

docs/interfaces/CommonDeviceEvent.md

Lines changed: 0 additions & 37 deletions
This file was deleted.

docs/modules.md

Lines changed: 4 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
- [ActionAttemptGetResponse](interfaces/ActionAttemptGetResponse.md)
3333
- [ActionAttemptResultTypeMap](interfaces/ActionAttemptResultTypeMap.md)
3434
- [ActionAttemptWithError](interfaces/ActionAttemptWithError.md)
35-
- [CommonDeviceEvent](interfaces/CommonDeviceEvent.md)
3635
- [ConnectWebview](interfaces/ConnectWebview.md)
3736
- [ConnectWebviewCreateRequest](interfaces/ConnectWebviewCreateRequest.md)
3837
- [ConnectWebviewCreateResponse](interfaces/ConnectWebviewCreateResponse.md)
@@ -69,18 +68,12 @@
6968
- [ActionType](modules.md#actiontype)
7069
- [AnyDevice](modules.md#anydevice)
7170
- [CommonDeviceProperties](modules.md#commondeviceproperties)
72-
- [CreateAccessCodeEvent](modules.md#createaccesscodeevent)
73-
- [DeviceConnectedEvent](modules.md#deviceconnectedevent)
74-
- [DeviceDisconnectEvent](modules.md#devicedisconnectevent)
75-
- [DeviceLowBatteryEvent](modules.md#devicelowbatteryevent)
76-
- [DeviceTamperEvent](modules.md#devicetamperevent)
7771
- [DeviceType](modules.md#devicetype)
7872
- [DeviceUpdateRequest](modules.md#deviceupdaterequest)
7973
- [LockDevice](modules.md#lockdevice)
8074
- [LockDeviceType](modules.md#lockdevicetype)
81-
- [NoiseDetectedEvent](modules.md#noisedetectedevent)
8275
- [NoiseDetectionDeviceType](modules.md#noisedetectiondevicetype)
83-
- [SeamEvent](modules.md#seamevent)
76+
- [SeamWebhookEvent](modules.md#seamwebhookevent)
8477
- [SuccessfulAPIResponse](modules.md#successfulapiresponse)
8578

8679
### Functions
@@ -201,56 +194,6 @@ ___
201194

202195
___
203196

204-
### CreateAccessCodeEvent
205-
206-
Ƭ **CreateAccessCodeEvent**: [`CommonDeviceEvent`](interfaces/CommonDeviceEvent.md)<``"access_codes.created"``, { `access_code_id`: `string` }\>
207-
208-
#### Defined in
209-
210-
[src/types/webhook-events.ts:21](https://github.com/seamapi/seamapi-javascript/blob/main/src/types/webhook-events.ts#L21)
211-
212-
___
213-
214-
### DeviceConnectedEvent
215-
216-
Ƭ **DeviceConnectedEvent**: [`CommonDeviceEvent`](interfaces/CommonDeviceEvent.md)<``"device.connected"``\>
217-
218-
#### Defined in
219-
220-
[src/types/webhook-events.ts:14](https://github.com/seamapi/seamapi-javascript/blob/main/src/types/webhook-events.ts#L14)
221-
222-
___
223-
224-
### DeviceDisconnectEvent
225-
226-
Ƭ **DeviceDisconnectEvent**: [`CommonDeviceEvent`](interfaces/CommonDeviceEvent.md)<``"devices.disconnected"``\>
227-
228-
#### Defined in
229-
230-
[src/types/webhook-events.ts:15](https://github.com/seamapi/seamapi-javascript/blob/main/src/types/webhook-events.ts#L15)
231-
232-
___
233-
234-
### DeviceLowBatteryEvent
235-
236-
Ƭ **DeviceLowBatteryEvent**: [`CommonDeviceEvent`](interfaces/CommonDeviceEvent.md)<``"devices.triggered_low_battery"``\>
237-
238-
#### Defined in
239-
240-
[src/types/webhook-events.ts:17](https://github.com/seamapi/seamapi-javascript/blob/main/src/types/webhook-events.ts#L17)
241-
242-
___
243-
244-
### DeviceTamperEvent
245-
246-
Ƭ **DeviceTamperEvent**: [`CommonDeviceEvent`](interfaces/CommonDeviceEvent.md)<``"devices.tampered"``\>
247-
248-
#### Defined in
249-
250-
[src/types/webhook-events.ts:16](https://github.com/seamapi/seamapi-javascript/blob/main/src/types/webhook-events.ts#L16)
251-
252-
___
253-
254197
### DeviceType
255198

256199
Ƭ **DeviceType**: [`LockDeviceType`](modules.md#lockdevicetype) \| [`NoiseDetectionDeviceType`](modules.md#noisedetectiondevicetype)
@@ -300,16 +243,6 @@ ___
300243

301244
___
302245

303-
### NoiseDetectedEvent
304-
305-
Ƭ **NoiseDetectedEvent**: [`CommonDeviceEvent`](interfaces/CommonDeviceEvent.md)<``"noise_thresholds.detected_noise"``\>
306-
307-
#### Defined in
308-
309-
[src/types/webhook-events.ts:29](https://github.com/seamapi/seamapi-javascript/blob/main/src/types/webhook-events.ts#L29)
310-
311-
___
312-
313246
### NoiseDetectionDeviceType
314247

315248
Ƭ **NoiseDetectionDeviceType**: ``"noiseaware_activity_zone"``
@@ -320,13 +253,13 @@ ___
320253

321254
___
322255

323-
### SeamEvent
256+
### SeamWebhookEvent
324257

325-
Ƭ **SeamEvent**: [`DeviceConnectedEvent`](modules.md#deviceconnectedevent) \| [`DeviceDisconnectEvent`](modules.md#devicedisconnectevent) \| [`DeviceTamperEvent`](modules.md#devicetamperevent) \| [`DeviceLowBatteryEvent`](modules.md#devicelowbatteryevent) \| [`CreateAccessCodeEvent`](modules.md#createaccesscodeevent) \| [`NoiseDetectedEvent`](modules.md#noisedetectedevent)
258+
Ƭ **SeamWebhookEvent**: `Distribute`<`SeamEvent`[``"event_type"``]\>
326259

327260
#### Defined in
328261

329-
[src/types/webhook-events.ts:32](https://github.com/seamapi/seamapi-javascript/blob/main/src/types/webhook-events.ts#L32)
262+
[src/types/webhook-events.ts:10](https://github.com/seamapi/seamapi-javascript/blob/main/src/types/webhook-events.ts#L10)
330263

331264
___
332265

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"cjs-wrapper.js"
3636
],
3737
"dependencies": {
38+
"@seamapi/seam-connect-public-types": "1.0.0",
3839
"axios": "0.25.0",
3940
"change-case": "4.1.2",
4041
"eventemitter3": "4.0.7",

src/cli/lib/interactive-login/panes/initiate-two-factor-pane.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import prompts from "prompts"
2+
import { TwoFactorOption } from "@seamapi/seam-connect-public-types"
23
import { PaneImplementation } from "./types"
34

4-
const formatOption = (option: any) => {
5+
const formatOption = (option: TwoFactorOption) => {
56
switch (option.method) {
67
case "otp":
78
return `📱 authenticator app`
@@ -14,15 +15,15 @@ const formatOption = (option: any) => {
1415
}
1516
}
1617

17-
const initiateTwoFactorPane: PaneImplementation = {
18+
const initiateTwoFactorPane: PaneImplementation<"initiate_two_factor_pane"> = {
1819
name: "initiate_two_factor_pane",
1920
getInput: async ({ options }) => {
2021
const { id } = await prompts(
2122
{
2223
type: "select",
2324
name: "id",
2425
message: "Select a 2FA option",
25-
choices: options.map((o: any) => ({
26+
choices: options.map((o) => ({
2627
title: formatOption(o),
2728
value: o.id,
2829
})),

src/cli/lib/interactive-login/panes/login-pane.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import prompts from "prompts"
22
import { formatErrorMsg } from "../utils"
33
import { PaneImplementation } from "./types"
44

5-
const loginPane: PaneImplementation = {
5+
const loginPane: PaneImplementation<"login_pane"> = {
66
name: "login_pane",
77
getInput: async (props) => {
88
let userIdentifier

src/cli/lib/interactive-login/panes/search-and-select-pane.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { PaneImplementation } from "./types"
22
import prompts from "prompts"
33

4-
const searchAndSelectPane: PaneImplementation = {
4+
const searchAndSelectPane: PaneImplementation<"search_and_select_pane"> = {
55
name: "search_and_select_pane",
66
getInput: async ({ title, options }) => {
77
const { selection } = await prompts(
88
{
99
name: "selection",
1010
type: "autocomplete",
1111
message: title,
12-
choices: options.map((o: any) => ({
12+
choices: options.map((o) => ({
1313
title: o.label,
1414
value: o.value,
1515
})),

src/cli/lib/interactive-login/panes/two-factor-pane.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import prompts from "prompts"
22
import { PaneImplementation } from "./types"
33

4-
const twoFactorPane: PaneImplementation = {
4+
const twoFactorPane: PaneImplementation<"two_factor_pane"> = {
55
name: "two_factor_pane",
66
getInput: async ({ code_length }) => {
77
const { code } = await prompts(
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
export interface PaneImplementation {
2-
name: string
3-
getInput: (props: any) => Promise<any>
1+
import { AnyPane } from "@seamapi/seam-connect-public-types"
2+
3+
export interface PaneImplementation<PaneName extends AnyPane["name"]> {
4+
name: PaneName
5+
getInput: (
6+
props: Extract<AnyPane, { name: PaneName }>["render_props"]
7+
) => Promise<Extract<AnyPane, { name: PaneName }>["submit_props"]>
48
}

src/types/webhook-events.ts

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,10 @@
1-
// todo: remove this file when we move to a monorepo?
2-
export interface CommonDeviceEvent<
3-
EventType extends string,
4-
Payload extends Record<string, unknown> | {} = {}
5-
> {
6-
event_type: EventType
7-
data: Payload & {
8-
workspace_id: string
9-
device_id: string
10-
}
11-
}
1+
import { SeamEvent } from "@seamapi/seam-connect-public-types"
122

13-
// Devices
14-
export type DeviceConnectedEvent = CommonDeviceEvent<"device.connected">
15-
export type DeviceDisconnectEvent = CommonDeviceEvent<"devices.disconnected">
16-
export type DeviceTamperEvent = CommonDeviceEvent<"devices.tampered">
17-
export type DeviceLowBatteryEvent =
18-
CommonDeviceEvent<"devices.triggered_low_battery">
3+
type Distribute<EventType> = EventType extends SeamEvent["event_type"]
4+
? {
5+
event_type: EventType
6+
data: Extract<SeamEvent, { event_type: EventType }>["payload"]
7+
}
8+
: never
199

20-
// Access codes
21-
export type CreateAccessCodeEvent = CommonDeviceEvent<
22-
"access_codes.created",
23-
{
24-
access_code_id: string
25-
}
26-
>
27-
28-
// Noise thresholds
29-
export type NoiseDetectedEvent =
30-
CommonDeviceEvent<"noise_thresholds.detected_noise">
31-
32-
export type SeamEvent =
33-
| DeviceConnectedEvent
34-
| DeviceDisconnectEvent
35-
| DeviceTamperEvent
36-
| DeviceLowBatteryEvent
37-
| CreateAccessCodeEvent
38-
| NoiseDetectedEvent
10+
export type SeamWebhookEvent = Distribute<SeamEvent["event_type"]>

0 commit comments

Comments
 (0)