@@ -2,6 +2,7 @@ import { create } from "@bufbuild/protobuf";
22import { createClient } from "@connectrpc/connect" ;
33import { createConnectTransport } from "@connectrpc/connect-node" ;
44import { type HmacKey } from "@xmtp/node-sdk" ;
5+ import { z } from "zod" ;
56import {
67 Notifications ,
78 Subscription_HmacKeySchema ,
@@ -25,30 +26,35 @@ export type Topic = {
2526 hmacKeys : HmacKey [ ] ;
2627} ;
2728
28- export type WebhookNotificationBody = {
29- idempotency_key : string ;
30- message : {
31- content_topic : string ;
32- timestamp_ns : string ;
33- message : string ;
34- } ;
35- message_context : {
36- message_type : string ;
37- should_push ?: boolean ;
38- } ;
39- installation : {
40- id : string ;
41- delivery_mechanism : {
42- kind : string ;
43- token : string ;
44- } ;
45- } ;
46- subscription : {
47- created_at : string ;
48- topic : string ;
49- is_silent : boolean ;
50- } ;
51- } ;
29+ // Zod schema for webhook notification validation
30+ export const webhookNotificationBodySchema = z . object ( {
31+ idempotency_key : z . string ( ) ,
32+ message : z . object ( {
33+ content_topic : z . string ( ) ,
34+ timestamp_ns : z . string ( ) ,
35+ message : z . string ( ) ,
36+ } ) ,
37+ message_context : z . object ( {
38+ message_type : z . string ( ) ,
39+ should_push : z . boolean ( ) . optional ( ) ,
40+ } ) ,
41+ installation : z . object ( {
42+ id : z . string ( ) ,
43+ delivery_mechanism : z . object ( {
44+ kind : z . string ( ) ,
45+ token : z . string ( ) ,
46+ } ) ,
47+ } ) ,
48+ subscription : z . object ( {
49+ created_at : z . string ( ) ,
50+ topic : z . string ( ) ,
51+ is_silent : z . boolean ( ) ,
52+ } ) ,
53+ } ) ;
54+
55+ export type WebhookNotificationBody = z . infer <
56+ typeof webhookNotificationBodySchema
57+ > ;
5258
5359export async function subscribeToTopics (
5460 // The installationId we want to apply the subscription to
0 commit comments