Skip to content

Commit

Permalink
Fix and update webhooks module
Browse files Browse the repository at this point in the history
  • Loading branch information
frankie567 committed Feb 5, 2025
1 parent 2ea8f23 commit c18229e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .genignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
src/webhooks/
src/webhooks.ts
src/webhooks.test.ts
jest.config.js
File renamed without changes.
7 changes: 4 additions & 3 deletions src/webhooks/index.test.ts → src/webhooks.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { randomUUID } from "crypto";
import { Webhook } from "standardwebhooks"
import { validateEvent, WebhookVerificationError } from "./index.js";
import { WebhookCheckoutCreatedPayload$inboundSchema } from "../models/components/webhookcheckoutcreatedpayload.js";
import { SDKValidationError } from "../models/errors/sdkvalidationerror.js";

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

const ORGANIZATION_ID = randomUUID().toString();
const PRODUCT_ID = randomUUID().toString();
Expand Down Expand Up @@ -76,6 +76,7 @@ const checkoutCreated = {
attached_custom_fields: [],
custom_field_data: {},
payment_processor: 'stripe',
customer_metadata: {},
}
};

Expand Down
51 changes: 32 additions & 19 deletions src/webhooks/index.ts → src/webhooks.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
import { Webhook, WebhookVerificationError as _WebhookVerificationError } from "standardwebhooks"

import {
WebhookBenefitCreatedPayload$inboundSchema
} from '../models/components/webhookbenefitcreatedpayload.js'
import { WebhookBenefitGrantCreatedPayload$inboundSchema } from "../models/components/webhookbenefitgrantcreatedpayload.js";
import { WebhookBenefitGrantRevokedPayload$inboundSchema } from "../models/components/webhookbenefitgrantrevokedpayload.js";
import { WebhookBenefitGrantUpdatedPayload$inboundSchema } from "../models/components/webhookbenefitgrantupdatedpayload.js";
import { WebhookBenefitUpdatedPayload$inboundSchema } from "../models/components/webhookbenefitupdatedpayload.js";
import { WebhookCheckoutCreatedPayload$inboundSchema } from "../models/components/webhookcheckoutcreatedpayload.js";
import { WebhookCheckoutUpdatedPayload$inboundSchema } from "../models/components/webhookcheckoutupdatedpayload.js";
import { WebhookOrderCreatedPayload$inboundSchema } from "../models/components/webhookordercreatedpayload.js";
import { WebhookOrganizationUpdatedPayload$inboundSchema } from "../models/components/webhookorganizationupdatedpayload.js";
import { WebhookPledgeCreatedPayload$inboundSchema } from "../models/components/webhookpledgecreatedpayload.js";
import { WebhookPledgeUpdatedPayload$inboundSchema } from "../models/components/webhookpledgeupdatedpayload.js";
import { WebhookProductCreatedPayload$inboundSchema } from "../models/components/webhookproductcreatedpayload.js";
import { WebhookProductUpdatedPayload$inboundSchema } from "../models/components/webhookproductupdatedpayload.js";
import { WebhookSubscriptionActivePayload$inboundSchema } from "../models/components/webhooksubscriptionactivepayload.js";
import { WebhookSubscriptionCanceledPayload$inboundSchema } from "../models/components/webhooksubscriptioncanceledpayload.js";
import { WebhookSubscriptionCreatedPayload$inboundSchema } from "../models/components/webhooksubscriptioncreatedpayload.js";
import { WebhookSubscriptionRevokedPayload$inboundSchema } from "../models/components/webhooksubscriptionrevokedpayload.js";
import { WebhookSubscriptionUpdatedPayload$inboundSchema } from "../models/components/webhooksubscriptionupdatedpayload.js";
import { SDKValidationError } from "../models/errors/sdkvalidationerror.js";
} from './models/components/webhookbenefitcreatedpayload.js'
import { WebhookBenefitGrantCreatedPayload$inboundSchema } from "./models/components/webhookbenefitgrantcreatedpayload.js";
import { WebhookBenefitGrantRevokedPayload$inboundSchema } from "./models/components/webhookbenefitgrantrevokedpayload.js";
import { WebhookBenefitGrantUpdatedPayload$inboundSchema } from "./models/components/webhookbenefitgrantupdatedpayload.js";
import { WebhookBenefitUpdatedPayload$inboundSchema } from "./models/components/webhookbenefitupdatedpayload.js";
import { WebhookCheckoutCreatedPayload$inboundSchema } from "./models/components/webhookcheckoutcreatedpayload.js";
import { WebhookCheckoutUpdatedPayload$inboundSchema } from "./models/components/webhookcheckoutupdatedpayload.js";
import { WebhookOrderCreatedPayload$inboundSchema } from "./models/components/webhookordercreatedpayload.js";
import { WebhookOrderRefundedPayload$inboundSchema } from "./models/components/webhookorderrefundedpayload.js";
import { WebhookOrganizationUpdatedPayload$inboundSchema } from "./models/components/webhookorganizationupdatedpayload.js";
import { WebhookPledgeCreatedPayload$inboundSchema } from "./models/components/webhookpledgecreatedpayload.js";
import { WebhookPledgeUpdatedPayload$inboundSchema } from "./models/components/webhookpledgeupdatedpayload.js";
import { WebhookProductCreatedPayload$inboundSchema } from "./models/components/webhookproductcreatedpayload.js";
import { WebhookProductUpdatedPayload$inboundSchema } from "./models/components/webhookproductupdatedpayload.js";
import { WebhookRefundCreatedPayload$inboundSchema } from "./models/components/webhookrefundcreatedpayload.js";
import { WebhookRefundUpdatedPayload$inboundSchema } from "./models/components/webhookrefundupdatedpayload.js";
import { WebhookSubscriptionActivePayload$inboundSchema } from "./models/components/webhooksubscriptionactivepayload.js";
import { WebhookSubscriptionCanceledPayload$inboundSchema } from "./models/components/webhooksubscriptioncanceledpayload.js";
import { WebhookSubscriptionCreatedPayload$inboundSchema } from "./models/components/webhooksubscriptioncreatedpayload.js";
import { WebhookSubscriptionRevokedPayload$inboundSchema } from "./models/components/webhooksubscriptionrevokedpayload.js";
import { WebhookSubscriptionUncanceledPayload$inboundSchema} from "./models/components/webhooksubscriptionuncanceledpayload.js";
import { WebhookSubscriptionUpdatedPayload$inboundSchema } from "./models/components/webhooksubscriptionupdatedpayload.js";
import { SDKValidationError } from "./models/errors/sdkvalidationerror.js";


class WebhookVerificationError extends Error {
Expand Down Expand Up @@ -48,6 +53,8 @@ const parseEvent = (parsed: any) => {
return WebhookCheckoutUpdatedPayload$inboundSchema.parse(parsed);
case 'order.created':
return WebhookOrderCreatedPayload$inboundSchema.parse(parsed);
case 'order.refunded':
return WebhookOrderRefundedPayload$inboundSchema.parse(parsed);
case 'organization.updated':
return WebhookOrganizationUpdatedPayload$inboundSchema.parse(parsed);
case 'pledge.created':
Expand All @@ -58,6 +65,10 @@ const parseEvent = (parsed: any) => {
return WebhookProductCreatedPayload$inboundSchema.parse(parsed);
case 'product.updated':
return WebhookProductUpdatedPayload$inboundSchema.parse(parsed);
case 'refund.created':
return WebhookRefundCreatedPayload$inboundSchema.parse(parsed);
case 'refund.updated':
return WebhookRefundUpdatedPayload$inboundSchema.parse(parsed);
case 'subscription.active':
return WebhookSubscriptionActivePayload$inboundSchema.parse(parsed);
case 'subscription.canceled':
Expand All @@ -66,6 +77,8 @@ const parseEvent = (parsed: any) => {
return WebhookSubscriptionCreatedPayload$inboundSchema.parse(parsed);
case 'subscription.revoked':
return WebhookSubscriptionRevokedPayload$inboundSchema.parse(parsed);
case 'subscription.uncanceled':
return WebhookSubscriptionUncanceledPayload$inboundSchema.parse(parsed);
case 'subscription.updated':
return WebhookSubscriptionUpdatedPayload$inboundSchema.parse(parsed);
default:
Expand Down

0 comments on commit c18229e

Please sign in to comment.