Skip to content

Commit c18229e

Browse files
committed
Fix and update webhooks module
1 parent 2ea8f23 commit c18229e

File tree

4 files changed

+38
-23
lines changed

4 files changed

+38
-23
lines changed

.genignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
src/webhooks/
1+
src/webhooks.ts
2+
src/webhooks.test.ts
23
jest.config.js
File renamed without changes.

src/webhooks/index.test.ts renamed to src/webhooks.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { randomUUID } from "crypto";
22
import { Webhook } from "standardwebhooks"
3-
import { validateEvent, WebhookVerificationError } from "./index.js";
4-
import { WebhookCheckoutCreatedPayload$inboundSchema } from "../models/components/webhookcheckoutcreatedpayload.js";
5-
import { SDKValidationError } from "../models/errors/sdkvalidationerror.js";
63

4+
import { WebhookCheckoutCreatedPayload$inboundSchema } from "./models/components/webhookcheckoutcreatedpayload.js";
5+
import { SDKValidationError } from "./models/errors/sdkvalidationerror.js";
6+
import { validateEvent, WebhookVerificationError } from "./webhooks.js";
77

88
const ORGANIZATION_ID = randomUUID().toString();
99
const PRODUCT_ID = randomUUID().toString();
@@ -76,6 +76,7 @@ const checkoutCreated = {
7676
attached_custom_fields: [],
7777
custom_field_data: {},
7878
payment_processor: 'stripe',
79+
customer_metadata: {},
7980
}
8081
};
8182

src/webhooks/index.ts renamed to src/webhooks.ts

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
import { Webhook, WebhookVerificationError as _WebhookVerificationError } from "standardwebhooks"
2+
23
import {
34
WebhookBenefitCreatedPayload$inboundSchema
4-
} from '../models/components/webhookbenefitcreatedpayload.js'
5-
import { WebhookBenefitGrantCreatedPayload$inboundSchema } from "../models/components/webhookbenefitgrantcreatedpayload.js";
6-
import { WebhookBenefitGrantRevokedPayload$inboundSchema } from "../models/components/webhookbenefitgrantrevokedpayload.js";
7-
import { WebhookBenefitGrantUpdatedPayload$inboundSchema } from "../models/components/webhookbenefitgrantupdatedpayload.js";
8-
import { WebhookBenefitUpdatedPayload$inboundSchema } from "../models/components/webhookbenefitupdatedpayload.js";
9-
import { WebhookCheckoutCreatedPayload$inboundSchema } from "../models/components/webhookcheckoutcreatedpayload.js";
10-
import { WebhookCheckoutUpdatedPayload$inboundSchema } from "../models/components/webhookcheckoutupdatedpayload.js";
11-
import { WebhookOrderCreatedPayload$inboundSchema } from "../models/components/webhookordercreatedpayload.js";
12-
import { WebhookOrganizationUpdatedPayload$inboundSchema } from "../models/components/webhookorganizationupdatedpayload.js";
13-
import { WebhookPledgeCreatedPayload$inboundSchema } from "../models/components/webhookpledgecreatedpayload.js";
14-
import { WebhookPledgeUpdatedPayload$inboundSchema } from "../models/components/webhookpledgeupdatedpayload.js";
15-
import { WebhookProductCreatedPayload$inboundSchema } from "../models/components/webhookproductcreatedpayload.js";
16-
import { WebhookProductUpdatedPayload$inboundSchema } from "../models/components/webhookproductupdatedpayload.js";
17-
import { WebhookSubscriptionActivePayload$inboundSchema } from "../models/components/webhooksubscriptionactivepayload.js";
18-
import { WebhookSubscriptionCanceledPayload$inboundSchema } from "../models/components/webhooksubscriptioncanceledpayload.js";
19-
import { WebhookSubscriptionCreatedPayload$inboundSchema } from "../models/components/webhooksubscriptioncreatedpayload.js";
20-
import { WebhookSubscriptionRevokedPayload$inboundSchema } from "../models/components/webhooksubscriptionrevokedpayload.js";
21-
import { WebhookSubscriptionUpdatedPayload$inboundSchema } from "../models/components/webhooksubscriptionupdatedpayload.js";
22-
import { SDKValidationError } from "../models/errors/sdkvalidationerror.js";
5+
} from './models/components/webhookbenefitcreatedpayload.js'
6+
import { WebhookBenefitGrantCreatedPayload$inboundSchema } from "./models/components/webhookbenefitgrantcreatedpayload.js";
7+
import { WebhookBenefitGrantRevokedPayload$inboundSchema } from "./models/components/webhookbenefitgrantrevokedpayload.js";
8+
import { WebhookBenefitGrantUpdatedPayload$inboundSchema } from "./models/components/webhookbenefitgrantupdatedpayload.js";
9+
import { WebhookBenefitUpdatedPayload$inboundSchema } from "./models/components/webhookbenefitupdatedpayload.js";
10+
import { WebhookCheckoutCreatedPayload$inboundSchema } from "./models/components/webhookcheckoutcreatedpayload.js";
11+
import { WebhookCheckoutUpdatedPayload$inboundSchema } from "./models/components/webhookcheckoutupdatedpayload.js";
12+
import { WebhookOrderCreatedPayload$inboundSchema } from "./models/components/webhookordercreatedpayload.js";
13+
import { WebhookOrderRefundedPayload$inboundSchema } from "./models/components/webhookorderrefundedpayload.js";
14+
import { WebhookOrganizationUpdatedPayload$inboundSchema } from "./models/components/webhookorganizationupdatedpayload.js";
15+
import { WebhookPledgeCreatedPayload$inboundSchema } from "./models/components/webhookpledgecreatedpayload.js";
16+
import { WebhookPledgeUpdatedPayload$inboundSchema } from "./models/components/webhookpledgeupdatedpayload.js";
17+
import { WebhookProductCreatedPayload$inboundSchema } from "./models/components/webhookproductcreatedpayload.js";
18+
import { WebhookProductUpdatedPayload$inboundSchema } from "./models/components/webhookproductupdatedpayload.js";
19+
import { WebhookRefundCreatedPayload$inboundSchema } from "./models/components/webhookrefundcreatedpayload.js";
20+
import { WebhookRefundUpdatedPayload$inboundSchema } from "./models/components/webhookrefundupdatedpayload.js";
21+
import { WebhookSubscriptionActivePayload$inboundSchema } from "./models/components/webhooksubscriptionactivepayload.js";
22+
import { WebhookSubscriptionCanceledPayload$inboundSchema } from "./models/components/webhooksubscriptioncanceledpayload.js";
23+
import { WebhookSubscriptionCreatedPayload$inboundSchema } from "./models/components/webhooksubscriptioncreatedpayload.js";
24+
import { WebhookSubscriptionRevokedPayload$inboundSchema } from "./models/components/webhooksubscriptionrevokedpayload.js";
25+
import { WebhookSubscriptionUncanceledPayload$inboundSchema} from "./models/components/webhooksubscriptionuncanceledpayload.js";
26+
import { WebhookSubscriptionUpdatedPayload$inboundSchema } from "./models/components/webhooksubscriptionupdatedpayload.js";
27+
import { SDKValidationError } from "./models/errors/sdkvalidationerror.js";
2328

2429

2530
class WebhookVerificationError extends Error {
@@ -48,6 +53,8 @@ const parseEvent = (parsed: any) => {
4853
return WebhookCheckoutUpdatedPayload$inboundSchema.parse(parsed);
4954
case 'order.created':
5055
return WebhookOrderCreatedPayload$inboundSchema.parse(parsed);
56+
case 'order.refunded':
57+
return WebhookOrderRefundedPayload$inboundSchema.parse(parsed);
5158
case 'organization.updated':
5259
return WebhookOrganizationUpdatedPayload$inboundSchema.parse(parsed);
5360
case 'pledge.created':
@@ -58,6 +65,10 @@ const parseEvent = (parsed: any) => {
5865
return WebhookProductCreatedPayload$inboundSchema.parse(parsed);
5966
case 'product.updated':
6067
return WebhookProductUpdatedPayload$inboundSchema.parse(parsed);
68+
case 'refund.created':
69+
return WebhookRefundCreatedPayload$inboundSchema.parse(parsed);
70+
case 'refund.updated':
71+
return WebhookRefundUpdatedPayload$inboundSchema.parse(parsed);
6172
case 'subscription.active':
6273
return WebhookSubscriptionActivePayload$inboundSchema.parse(parsed);
6374
case 'subscription.canceled':
@@ -66,6 +77,8 @@ const parseEvent = (parsed: any) => {
6677
return WebhookSubscriptionCreatedPayload$inboundSchema.parse(parsed);
6778
case 'subscription.revoked':
6879
return WebhookSubscriptionRevokedPayload$inboundSchema.parse(parsed);
80+
case 'subscription.uncanceled':
81+
return WebhookSubscriptionUncanceledPayload$inboundSchema.parse(parsed);
6982
case 'subscription.updated':
7083
return WebhookSubscriptionUpdatedPayload$inboundSchema.parse(parsed);
7184
default:

0 commit comments

Comments
 (0)