Skip to content

Commit

Permalink
Usage
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed Oct 24, 2024
1 parent 90c8bd0 commit f5e2ee7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Hand-crafted from their docs, with JSDoc when appropriate and nullability manual
import { Webhook } from "@puzzmo/revenue-cat-webhook-types"

const handler = (req: Webhook) => {
switch (req.type) {
switch (req.event.type) {
case "INITIAL_PURCHASE":
// req as WebhookInitialPurchase
break
Expand Down
30 changes: 17 additions & 13 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@
*
* @see https://www.revenuecat.com/docs/integrations/webhooks/event-types-and-fields
*/
export type Webhook =
| WebhookInitialPurchase
| WebhookRenewal
| WebhookCancellation
| WebhookUnCancellation
| WebhookNonRenewingPurchase
| WebhookExpiration
| WebhookSubscriptionPaused
| WebhookBillingIssue
| WebhookProductChange
| WebhookSubscriptionExtended
| WebhookTemporaryEntitlementGrant
export type Webhook = {
api_version: string
event:
| WebhookInitialPurchase
| WebhookRenewal
| WebhookCancellation
| WebhookUnCancellation
| WebhookNonRenewingPurchase
| WebhookExpiration
| WebhookSubscriptionPaused
| WebhookBillingIssue
| WebhookProductChange
| WebhookSubscriptionExtended
| WebhookTemporaryEntitlementGrant
}

// Initially based on the samples from https://www.revenuecat.com/docs/integrations/webhooks/sample-events
// There is generally a base object which most webhooks use, and then have a unique type and one-or-more unique fields.
Expand Down Expand Up @@ -48,6 +51,7 @@ interface WebhookBase {
currency: string
price: number
price_in_purchased_currency: number
renewal_number: null | number
subscriber_attributes: Attributes
store: Store
takehome_percentage?: number
Expand Down Expand Up @@ -126,7 +130,7 @@ export interface WebhookBillingIssue extends WebhookBase {
*/
export interface WebhookProductChange extends WebhookBase {
type: "PRODUCT_CHANGE"
new_product_id: string
new_product_id?: string
}

/**
Expand Down
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
{
"name": "@puzzmo/revenue-cat-webhook-types",
"version": "0.1.0",
"version": "0.3.0",
"description": "TypeScript types for RevenueCat Webhooks. Hand-crafted from their docs, with JSDoc when appropriate and nullability manually added.",
"repository": {
"url": "https://github.com/puzzmo-com/revenue-cat-webhook-types"
},
"license": "MIT",
"publishConfig": {
"provenance": true
}
"license": "MIT"
}

0 comments on commit f5e2ee7

Please sign in to comment.