@samva/webhooks 0.34.0 → 0.36.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # `@samva/webhooks`
2
2
 
3
- Samva is the email API for your app: transactional and campaign sending, inbound mail, and webhooks behind one API.
3
+ Samva is the email and WhatsApp API for your app: transactional and campaign sending, inbound replies threaded into conversations, programmable mailboxes, and signed webhooks. Small businesses use the same platform to answer their customers in Samva Mail.
4
4
 
5
5
  Verify signed Samva webhook deliveries in Node.js, Bun, Cloudflare Workers, and other Web
6
6
  Crypto-compatible runtimes.
package/dist/effect.js CHANGED
@@ -1,6 +1,6 @@
1
- import { _ as WebhookTimestampError, c as signWebhook, f as InvalidWebhookHeadersError, g as WebhookSignatureError, h as WebhookCryptoError, i as WEBHOOK_TIMESTAMP_HEADER, l as verifyWebhookAt, m as MalformedWebhookPayloadError, n as WEBHOOK_ID_HEADER, o as generateWebhookSecret, p as InvalidWebhookSecretError, r as WEBHOOK_SIGNATURE_HEADER, t as DEFAULT_TOLERANCE_SECONDS, v as WebhookVerificationError, y as isKnownEvent } from "./protocol-Di63Knu8.js";
2
- import { t as WebhookEventJsonSchemas } from "./json-schemas.gen-eaxxbAJh.js";
3
- import { ContactConsentChangedEventSchema, ContactCreatedEventSchema, ContactDeletedEventSchema, ContactResubscribedEventSchema, ContactSubscribedEventSchema, ContactUnsubscribedEventSchema, ContactUpdatedEventSchema, ConversationArchivedEventSchema, ConversationCreatedEventSchema, ConversationUpdatedEventSchema, DomainUpdatedEventSchema, DomainWarmingUpdatedEventSchema, FlowRegistrationUpdatedEventSchema, JourneyWebhookEventSchema, MailboxActionPendingApprovalEventSchema, MailboxActionResolvedEventSchema, MailboxMessageDeliveredEventSchema, MailboxMessageDiscardedEventSchema, MailboxMessageFailedEventSchema, MailboxMessageQuarantinedEventSchema, MailboxMessageReadEventSchema, MailboxMessageReceivedEventSchema, MailboxMessageReleasedEventSchema, MailboxMessageSentEventSchema, MessageBouncedEventSchema, MessageClickedEventSchema, MessageComplainedEventSchema, MessageDeliveredEventSchema, MessageFailedEventSchema, MessageOpenedEventSchema, MessageReadEventSchema, MessageReceivedEventSchema, MessageSentEventSchema, SamvaWebhookEventSchema, TemplateRegistrationUpdatedEventSchema, WebhookCreatedEventSchema, WebhookDeletedEventSchema, WebhookTestEventSchema, WebhookUpdatedEventSchema, WhatsappNumberConnectedEventSchema } from "./schemas.gen.js";
1
+ import { _ as WebhookTimestampError, c as signWebhook, f as InvalidWebhookHeadersError, g as WebhookSignatureError, h as WebhookCryptoError, i as WEBHOOK_TIMESTAMP_HEADER, l as verifyWebhookAt, m as MalformedWebhookPayloadError, n as WEBHOOK_ID_HEADER, o as generateWebhookSecret, p as InvalidWebhookSecretError, r as WEBHOOK_SIGNATURE_HEADER, t as DEFAULT_TOLERANCE_SECONDS, v as WebhookVerificationError, y as isKnownEvent } from "./protocol-Cqf7JfeH.js";
2
+ import { t as WebhookEventJsonSchemas } from "./json-schemas.gen-C5nX_b5f.js";
3
+ import { ContactConsentChangedEventSchema, ContactCreatedEventSchema, ContactDeletedEventSchema, ContactResubscribedEventSchema, ContactSubscribedEventSchema, ContactUnsubscribedEventSchema, ContactUpdatedEventSchema, ConversationArchivedEventSchema, ConversationCreatedEventSchema, ConversationUpdatedEventSchema, DomainUpdatedEventSchema, DomainWarmingUpdatedEventSchema, EmailSendingPausedEventSchema, EmailSendingResumedEventSchema, FlowRegistrationUpdatedEventSchema, JourneyWebhookEventSchema, MailboxActionPendingApprovalEventSchema, MailboxActionResolvedEventSchema, MailboxMessageDeliveredEventSchema, MailboxMessageDiscardedEventSchema, MailboxMessageFailedEventSchema, MailboxMessageQuarantinedEventSchema, MailboxMessageReadEventSchema, MailboxMessageReceivedEventSchema, MailboxMessageReleasedEventSchema, MailboxMessageSentEventSchema, MessageBouncedEventSchema, MessageClickedEventSchema, MessageComplainedEventSchema, MessageDeliveredEventSchema, MessageFailedEventSchema, MessageOpenedEventSchema, MessageReadEventSchema, MessageReceivedEventSchema, MessageSentEventSchema, SamvaWebhookEventSchema, TemplateRegistrationUpdatedEventSchema, WebhookCreatedEventSchema, WebhookDeletedEventSchema, WebhookTestEventSchema, WebhookUpdatedEventSchema, WhatsappNumberConnectedEventSchema } from "./schemas.gen.js";
4
4
  import { Clock, Effect } from "effect";
5
5
  // src/effect.ts
6
6
  /**
@@ -74,6 +74,6 @@ const verifyRequest = Effect.fn("Webhooks.verifyRequest")(function* (request, se
74
74
  nowMilliseconds
75
75
  });
76
76
  });
77
- export { ContactConsentChangedEventSchema, ContactCreatedEventSchema, ContactDeletedEventSchema, ContactResubscribedEventSchema, ContactSubscribedEventSchema, ContactUnsubscribedEventSchema, ContactUpdatedEventSchema, ConversationArchivedEventSchema, ConversationCreatedEventSchema, ConversationUpdatedEventSchema, DEFAULT_TOLERANCE_SECONDS, DomainUpdatedEventSchema, DomainWarmingUpdatedEventSchema, FlowRegistrationUpdatedEventSchema, InvalidWebhookHeadersError, InvalidWebhookSecretError, JourneyWebhookEventSchema, MailboxActionPendingApprovalEventSchema, MailboxActionResolvedEventSchema, MailboxMessageDeliveredEventSchema, MailboxMessageDiscardedEventSchema, MailboxMessageFailedEventSchema, MailboxMessageQuarantinedEventSchema, MailboxMessageReadEventSchema, MailboxMessageReceivedEventSchema, MailboxMessageReleasedEventSchema, MailboxMessageSentEventSchema, MalformedWebhookPayloadError, MessageBouncedEventSchema, MessageClickedEventSchema, MessageComplainedEventSchema, MessageDeliveredEventSchema, MessageFailedEventSchema, MessageOpenedEventSchema, MessageReadEventSchema, MessageReceivedEventSchema, MessageSentEventSchema, SamvaWebhookEventSchema, TemplateRegistrationUpdatedEventSchema, WEBHOOK_ID_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_TIMESTAMP_HEADER, WebhookCreatedEventSchema, WebhookCryptoError, WebhookDeletedEventSchema, WebhookEventJsonSchemas, WebhookSignatureError, WebhookTestEventSchema, WebhookTimestampError, WebhookUpdatedEventSchema, WebhookVerificationError, WhatsappNumberConnectedEventSchema, generateWebhookSecret, isKnownEvent, signWebhook, verify, verifyRequest };
77
+ export { ContactConsentChangedEventSchema, ContactCreatedEventSchema, ContactDeletedEventSchema, ContactResubscribedEventSchema, ContactSubscribedEventSchema, ContactUnsubscribedEventSchema, ContactUpdatedEventSchema, ConversationArchivedEventSchema, ConversationCreatedEventSchema, ConversationUpdatedEventSchema, DEFAULT_TOLERANCE_SECONDS, DomainUpdatedEventSchema, DomainWarmingUpdatedEventSchema, EmailSendingPausedEventSchema, EmailSendingResumedEventSchema, FlowRegistrationUpdatedEventSchema, InvalidWebhookHeadersError, InvalidWebhookSecretError, JourneyWebhookEventSchema, MailboxActionPendingApprovalEventSchema, MailboxActionResolvedEventSchema, MailboxMessageDeliveredEventSchema, MailboxMessageDiscardedEventSchema, MailboxMessageFailedEventSchema, MailboxMessageQuarantinedEventSchema, MailboxMessageReadEventSchema, MailboxMessageReceivedEventSchema, MailboxMessageReleasedEventSchema, MailboxMessageSentEventSchema, MalformedWebhookPayloadError, MessageBouncedEventSchema, MessageClickedEventSchema, MessageComplainedEventSchema, MessageDeliveredEventSchema, MessageFailedEventSchema, MessageOpenedEventSchema, MessageReadEventSchema, MessageReceivedEventSchema, MessageSentEventSchema, SamvaWebhookEventSchema, TemplateRegistrationUpdatedEventSchema, WEBHOOK_ID_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_TIMESTAMP_HEADER, WebhookCreatedEventSchema, WebhookCryptoError, WebhookDeletedEventSchema, WebhookEventJsonSchemas, WebhookSignatureError, WebhookTestEventSchema, WebhookTimestampError, WebhookUpdatedEventSchema, WebhookVerificationError, WhatsappNumberConnectedEventSchema, generateWebhookSecret, isKnownEvent, signWebhook, verify, verifyRequest };
78
78
 
79
79
  //# sourceMappingURL=effect.js.map
@@ -2756,6 +2756,88 @@ const WebhookEventJsonSchemas = {
2756
2756
  ],
2757
2757
  additionalProperties: true
2758
2758
  },
2759
+ "email.sending.paused": {
2760
+ type: "object",
2761
+ properties: {
2762
+ type: {
2763
+ type: "string",
2764
+ enum: ["email.sending.paused"]
2765
+ },
2766
+ timestamp: { type: "string" },
2767
+ data: {
2768
+ type: "object",
2769
+ properties: {
2770
+ organizationId: {
2771
+ type: "string",
2772
+ pattern: "^org_[0-9a-hjkmnp-tv-z]{16,24}$"
2773
+ },
2774
+ namespaceId: { anyOf: [{
2775
+ type: "string",
2776
+ pattern: "^ns_[0-9a-hjkmnp-tv-z]{16,24}$"
2777
+ }, { type: "null" }] },
2778
+ channel: {
2779
+ type: "string",
2780
+ enum: ["email"]
2781
+ },
2782
+ occurredAt: { type: "string" }
2783
+ },
2784
+ required: [
2785
+ "organizationId",
2786
+ "namespaceId",
2787
+ "channel",
2788
+ "occurredAt"
2789
+ ],
2790
+ additionalProperties: true
2791
+ }
2792
+ },
2793
+ required: [
2794
+ "type",
2795
+ "timestamp",
2796
+ "data"
2797
+ ],
2798
+ additionalProperties: true
2799
+ },
2800
+ "email.sending.resumed": {
2801
+ type: "object",
2802
+ properties: {
2803
+ type: {
2804
+ type: "string",
2805
+ enum: ["email.sending.resumed"]
2806
+ },
2807
+ timestamp: { type: "string" },
2808
+ data: {
2809
+ type: "object",
2810
+ properties: {
2811
+ organizationId: {
2812
+ type: "string",
2813
+ pattern: "^org_[0-9a-hjkmnp-tv-z]{16,24}$"
2814
+ },
2815
+ namespaceId: { anyOf: [{
2816
+ type: "string",
2817
+ pattern: "^ns_[0-9a-hjkmnp-tv-z]{16,24}$"
2818
+ }, { type: "null" }] },
2819
+ channel: {
2820
+ type: "string",
2821
+ enum: ["email"]
2822
+ },
2823
+ occurredAt: { type: "string" }
2824
+ },
2825
+ required: [
2826
+ "organizationId",
2827
+ "namespaceId",
2828
+ "channel",
2829
+ "occurredAt"
2830
+ ],
2831
+ additionalProperties: true
2832
+ }
2833
+ },
2834
+ required: [
2835
+ "type",
2836
+ "timestamp",
2837
+ "data"
2838
+ ],
2839
+ additionalProperties: true
2840
+ },
2759
2841
  "template.registration.updated": {
2760
2842
  type: "object",
2761
2843
  properties: {
@@ -3146,9 +3228,9 @@ const WebhookEventJsonSchemas = {
3146
3228
  channel: {
3147
3229
  type: "string",
3148
3230
  enum: [
3149
- "email",
3231
+ "sms",
3150
3232
  "whatsapp",
3151
- "sms"
3233
+ "email"
3152
3234
  ],
3153
3235
  description: "Deliveries recorded before this field existed omit it; they are email."
3154
3236
  },
@@ -3344,9 +3426,9 @@ const WebhookEventJsonSchemas = {
3344
3426
  channel: {
3345
3427
  type: "string",
3346
3428
  enum: [
3347
- "email",
3429
+ "sms",
3348
3430
  "whatsapp",
3349
- "sms"
3431
+ "email"
3350
3432
  ],
3351
3433
  description: "Deliveries recorded before this field existed omit it; they are email."
3352
3434
  },
@@ -3467,9 +3549,15 @@ const WebhookEventJsonSchemas = {
3467
3549
  "changeThreadState",
3468
3550
  "call",
3469
3551
  "extensionRequest",
3470
- "toolCall"
3552
+ "toolCall",
3553
+ "handoff"
3471
3554
  ]
3472
3555
  },
3556
+ reviewRound: {
3557
+ type: "integer",
3558
+ maximum: 9007199254740991,
3559
+ exclusiveMinimum: 0
3560
+ },
3473
3561
  state: {
3474
3562
  type: "string",
3475
3563
  enum: ["approvalRequired"],
@@ -3478,38 +3566,168 @@ const WebhookEventJsonSchemas = {
3478
3566
  decision: {
3479
3567
  type: "object",
3480
3568
  properties: {
3569
+ id: {
3570
+ type: "string",
3571
+ pattern: "^pdec_[0-9a-hjkmnp-tv-z]{16,24}$"
3572
+ },
3573
+ reviewRound: {
3574
+ type: "integer",
3575
+ maximum: 9007199254740991,
3576
+ exclusiveMinimum: 0
3577
+ },
3578
+ requirement: {
3579
+ type: "string",
3580
+ enum: [
3581
+ "run",
3582
+ "model",
3583
+ "person",
3584
+ "never"
3585
+ ]
3586
+ },
3587
+ decider: {
3588
+ type: "string",
3589
+ enum: [
3590
+ "rule",
3591
+ "model",
3592
+ "person",
3593
+ "agent"
3594
+ ]
3595
+ },
3481
3596
  outcome: {
3482
3597
  type: "string",
3483
3598
  enum: [
3484
3599
  "allow",
3485
- "requireApproval",
3486
- "deny"
3600
+ "hold",
3601
+ "refuse"
3487
3602
  ]
3488
3603
  },
3489
- reason: { anyOf: [{ type: "string" }, { type: "null" }] },
3490
- policyId: { anyOf: [{
3604
+ reason: {
3605
+ type: "string",
3606
+ minLength: 1
3607
+ },
3608
+ scopes: {
3609
+ type: "array",
3610
+ items: {
3611
+ type: "object",
3612
+ properties: {
3613
+ kind: {
3614
+ type: "string",
3615
+ enum: [
3616
+ "organization",
3617
+ "mailbox",
3618
+ "agent",
3619
+ "apiKey"
3620
+ ]
3621
+ },
3622
+ id: {
3623
+ type: "string",
3624
+ minLength: 1
3625
+ }
3626
+ },
3627
+ required: ["kind", "id"],
3628
+ additionalProperties: true
3629
+ }
3630
+ },
3631
+ rule: { anyOf: [{
3632
+ type: "object",
3633
+ properties: {
3634
+ scope: {
3635
+ type: "object",
3636
+ properties: {
3637
+ kind: {
3638
+ type: "string",
3639
+ enum: [
3640
+ "organization",
3641
+ "mailbox",
3642
+ "agent",
3643
+ "apiKey"
3644
+ ]
3645
+ },
3646
+ id: {
3647
+ type: "string",
3648
+ minLength: 1
3649
+ }
3650
+ },
3651
+ required: ["kind", "id"],
3652
+ additionalProperties: true
3653
+ },
3654
+ index: {
3655
+ type: "integer",
3656
+ minimum: 0,
3657
+ maximum: 9007199254740991
3658
+ }
3659
+ },
3660
+ required: ["scope", "index"],
3661
+ additionalProperties: true
3662
+ }, { type: "null" }] },
3663
+ guard: { anyOf: [{
3491
3664
  type: "string",
3492
- pattern: "^mbxpol_[0-9a-hjkmnp-tv-z]{16,24}$"
3665
+ minLength: 1
3493
3666
  }, { type: "null" }] },
3494
- source: { anyOf: [{
3667
+ guardReason: { anyOf: [{
3495
3668
  type: "string",
3496
- enum: [
3497
- "grant",
3498
- "installation",
3499
- "policy"
3500
- ]
3669
+ minLength: 1
3501
3670
  }, { type: "null" }] },
3502
- decidedAt: { type: "string" }
3671
+ resolution: { anyOf: [{
3672
+ type: "object",
3673
+ properties: {
3674
+ by: {
3675
+ type: "string",
3676
+ pattern: "^user_[0-9a-hjkmnp-tv-z]{16,24}$"
3677
+ },
3678
+ at: { type: "string" },
3679
+ as: {
3680
+ type: "string",
3681
+ enum: [
3682
+ "approved",
3683
+ "edited",
3684
+ "denied",
3685
+ "alwaysAllowed"
3686
+ ]
3687
+ },
3688
+ diff: { anyOf: [{
3689
+ type: "object",
3690
+ properties: {
3691
+ text: { anyOf: [{
3692
+ type: "object",
3693
+ properties: {
3694
+ before: { anyOf: [{ type: "string" }, { type: "null" }] },
3695
+ after: { anyOf: [{ type: "string" }, { type: "null" }] }
3696
+ },
3697
+ required: ["before", "after"],
3698
+ additionalProperties: true
3699
+ }, { type: "null" }] },
3700
+ html: { anyOf: [{
3701
+ type: "object",
3702
+ properties: {
3703
+ before: { anyOf: [{ type: "string" }, { type: "null" }] },
3704
+ after: { anyOf: [{ type: "string" }, { type: "null" }] }
3705
+ },
3706
+ required: ["before", "after"],
3707
+ additionalProperties: true
3708
+ }, { type: "null" }] }
3709
+ },
3710
+ additionalProperties: true
3711
+ }, { type: "null" }] }
3712
+ },
3713
+ required: [
3714
+ "by",
3715
+ "at",
3716
+ "as"
3717
+ ],
3718
+ additionalProperties: true
3719
+ }, { type: "null" }] }
3503
3720
  },
3504
3721
  required: [
3722
+ "id",
3723
+ "reviewRound",
3724
+ "requirement",
3725
+ "decider",
3505
3726
  "outcome",
3506
3727
  "reason",
3507
- "policyId",
3508
- "source",
3509
- "decidedAt"
3728
+ "scopes"
3510
3729
  ],
3511
- additionalProperties: true,
3512
- description: "Deliveries recorded before this field existed omit it."
3730
+ additionalProperties: true
3513
3731
  },
3514
3732
  threadId: { anyOf: [{
3515
3733
  type: "string",
@@ -3556,6 +3774,8 @@ const WebhookEventJsonSchemas = {
3556
3774
  required: [
3557
3775
  "id",
3558
3776
  "type",
3777
+ "reviewRound",
3778
+ "decision",
3559
3779
  "threadId",
3560
3780
  "reason",
3561
3781
  "proposedBy",
@@ -3664,9 +3884,15 @@ const WebhookEventJsonSchemas = {
3664
3884
  "changeThreadState",
3665
3885
  "call",
3666
3886
  "extensionRequest",
3667
- "toolCall"
3887
+ "toolCall",
3888
+ "handoff"
3668
3889
  ]
3669
3890
  },
3891
+ reviewRound: {
3892
+ type: "integer",
3893
+ maximum: 9007199254740991,
3894
+ exclusiveMinimum: 0
3895
+ },
3670
3896
  threadId: { anyOf: [{
3671
3897
  type: "string",
3672
3898
  pattern: "^thread_[0-9a-hjkmnp-tv-z]{16,24}$"
@@ -3711,6 +3937,7 @@ const WebhookEventJsonSchemas = {
3711
3937
  required: [
3712
3938
  "id",
3713
3939
  "type",
3940
+ "reviewRound",
3714
3941
  "threadId",
3715
3942
  "proposedBy",
3716
3943
  "createdAt"
@@ -3972,9 +4199,9 @@ const WebhookEventJsonSchemas = {
3972
4199
  channel: {
3973
4200
  type: "string",
3974
4201
  enum: [
3975
- "email",
4202
+ "sms",
3976
4203
  "whatsapp",
3977
- "sms"
4204
+ "email"
3978
4205
  ],
3979
4206
  description: "Deliveries recorded before this field existed omit it; they are email."
3980
4207
  },
@@ -4234,9 +4461,9 @@ const WebhookEventJsonSchemas = {
4234
4461
  channel: {
4235
4462
  type: "string",
4236
4463
  enum: [
4237
- "email",
4464
+ "sms",
4238
4465
  "whatsapp",
4239
- "sms"
4466
+ "email"
4240
4467
  ],
4241
4468
  description: "The channel an endpoint, thread, or message belongs to."
4242
4469
  },
@@ -4306,9 +4533,9 @@ const WebhookEventJsonSchemas = {
4306
4533
  channel: {
4307
4534
  type: "string",
4308
4535
  enum: [
4309
- "email",
4536
+ "sms",
4310
4537
  "whatsapp",
4311
- "sms"
4538
+ "email"
4312
4539
  ],
4313
4540
  description: "The channel an endpoint, thread, or message belongs to."
4314
4541
  },
@@ -4378,9 +4605,9 @@ const WebhookEventJsonSchemas = {
4378
4605
  channel: {
4379
4606
  type: "string",
4380
4607
  enum: [
4381
- "email",
4608
+ "sms",
4382
4609
  "whatsapp",
4383
- "sms"
4610
+ "email"
4384
4611
  ],
4385
4612
  description: "The channel an endpoint, thread, or message belongs to."
4386
4613
  },
@@ -4495,4 +4722,4 @@ const WebhookEventJsonSchemas = {
4495
4722
  };
4496
4723
  export { WebhookEventJsonSchemas as t };
4497
4724
 
4498
- //# sourceMappingURL=json-schemas.gen-eaxxbAJh.js.map
4725
+ //# sourceMappingURL=json-schemas.gen-C5nX_b5f.js.map
package/dist/promise.js CHANGED
@@ -1,5 +1,5 @@
1
- import { _ as WebhookTimestampError, c as signWebhook, f as InvalidWebhookHeadersError, g as WebhookSignatureError, h as WebhookCryptoError, i as WEBHOOK_TIMESTAMP_HEADER, l as verifyWebhookAt, m as MalformedWebhookPayloadError, n as WEBHOOK_ID_HEADER, o as generateWebhookSecret, p as InvalidWebhookSecretError, r as WEBHOOK_SIGNATURE_HEADER, s as readWebhookHeaders, t as DEFAULT_TOLERANCE_SECONDS, v as WebhookVerificationError, y as isKnownEvent } from "./protocol-Di63Knu8.js";
2
- import { t as WebhookEventJsonSchemas } from "./json-schemas.gen-eaxxbAJh.js";
1
+ import { _ as WebhookTimestampError, c as signWebhook, f as InvalidWebhookHeadersError, g as WebhookSignatureError, h as WebhookCryptoError, i as WEBHOOK_TIMESTAMP_HEADER, l as verifyWebhookAt, m as MalformedWebhookPayloadError, n as WEBHOOK_ID_HEADER, o as generateWebhookSecret, p as InvalidWebhookSecretError, r as WEBHOOK_SIGNATURE_HEADER, s as readWebhookHeaders, t as DEFAULT_TOLERANCE_SECONDS, v as WebhookVerificationError, y as isKnownEvent } from "./protocol-Cqf7JfeH.js";
2
+ import { t as WebhookEventJsonSchemas } from "./json-schemas.gen-C5nX_b5f.js";
3
3
  // src/promise.ts
4
4
  /**
5
5
  * Verifies a Samva webhook delivery from its body and header values, then returns its ID and