-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add subscription schemas and contracts (MDK-401) #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
+225
−12
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4770609
feat: add subscription schemas and contracts
NatElkins 44e2082
feat: add customer schemas and contracts
NatElkins e58ddde
fix: require email in CustomerSchema for subscription communication
NatElkins 97bafff
feat: add prepare script for git installs
NatElkins 3d8ca7c
fix: allow nullable email in Customer schema
NatElkins f22d5de
fix: add datetime validation to ISO date fields, remove hasActiveSubs…
NatElkins 631f90c
fix: make customerEmail nullable in SubscriptionSchema
NatElkins d050ad3
Merge main into mdk-401
NatElkins 919e292
fix: format code with biome
NatElkins fa94a4c
fix: add customer to sdkContract
NatElkins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { oc } from "@orpc/contract"; | ||
| import { z } from "zod"; | ||
| import { SubscriptionSchema } from "../schemas/subscription"; | ||
|
|
||
| export const CreateRenewalCheckoutInputSchema = z.object({ | ||
| subscriptionId: z.string(), | ||
| }); | ||
|
|
||
| export const CreateRenewalCheckoutOutputSchema = z.object({ | ||
| checkoutId: z.string(), | ||
| }); | ||
|
|
||
| export const CancelSubscriptionInputSchema = z.object({ | ||
| subscriptionId: z.string(), | ||
| }); | ||
|
|
||
| export const CancelSubscriptionOutputSchema = z.object({ | ||
| ok: z.boolean(), | ||
| }); | ||
|
|
||
| export const GetSubscriptionInputSchema = z.object({ | ||
| subscriptionId: z.string(), | ||
| }); | ||
|
|
||
| export type CreateRenewalCheckout = z.infer< | ||
| typeof CreateRenewalCheckoutInputSchema | ||
| >; | ||
| export type CancelSubscriptionInput = z.infer< | ||
| typeof CancelSubscriptionInputSchema | ||
| >; | ||
| export type GetSubscriptionInput = z.infer<typeof GetSubscriptionInputSchema>; | ||
|
|
||
| export const createRenewalCheckoutContract = oc | ||
| .input(CreateRenewalCheckoutInputSchema) | ||
| .output(CreateRenewalCheckoutOutputSchema); | ||
|
|
||
| export const cancelSubscriptionContract = oc | ||
| .input(CancelSubscriptionInputSchema) | ||
| .output(CancelSubscriptionOutputSchema); | ||
|
|
||
| export const getSubscriptionContract = oc | ||
| .input(GetSubscriptionInputSchema) | ||
| .output(SubscriptionSchema); | ||
|
|
||
| export const subscription = { | ||
| createRenewalCheckout: createRenewalCheckoutContract, | ||
| cancel: cancelSubscriptionContract, | ||
| get: getSubscriptionContract, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { z } from "zod"; | ||
| import { CurrencySchema } from "./currency"; | ||
|
|
||
| export const SubscriptionStatusSchema = z.enum([ | ||
| "active", | ||
| "past_due", | ||
| "canceled", | ||
| ]); | ||
|
|
||
| export const RecurringIntervalSchema = z.enum(["MONTH", "QUARTER", "YEAR"]); | ||
|
|
||
| export const SubscriptionSchema = z.object({ | ||
| id: z.string(), | ||
| customerId: z.string(), | ||
| customerEmail: z.string().nullable(), | ||
| productId: z.string(), | ||
| amount: z.number(), | ||
| currency: CurrencySchema, | ||
| recurringInterval: RecurringIntervalSchema, | ||
| status: SubscriptionStatusSchema, | ||
| currentPeriodStart: z.string().datetime(), | ||
| currentPeriodEnd: z.string().datetime(), | ||
| cancelAtPeriodEnd: z.boolean().optional(), | ||
| endsAt: z.string().datetime().optional(), | ||
| endedAt: z.string().datetime().optional(), | ||
| canceledAt: z.string().datetime().optional(), | ||
| startedAt: z.string().datetime(), | ||
| }); | ||
|
|
||
| export const SubscriptionWebhookEventSchema = z.enum([ | ||
| "subscription.created", | ||
| "subscription.renewed", | ||
| "subscription.canceled", | ||
| "subscription.payment_failed", | ||
| ]); | ||
|
|
||
| export const SubscriptionWebhookPayloadSchema = z.object({ | ||
| handler: z.literal("webhooks"), | ||
| event: SubscriptionWebhookEventSchema, | ||
| subscription: SubscriptionSchema, | ||
| }); | ||
|
|
||
| export type Subscription = z.infer<typeof SubscriptionSchema>; | ||
| export type SubscriptionStatus = z.infer<typeof SubscriptionStatusSchema>; | ||
| export type RecurringInterval = z.infer<typeof RecurringIntervalSchema>; | ||
| export type SubscriptionWebhookEvent = z.infer< | ||
| typeof SubscriptionWebhookEventSchema | ||
| >; | ||
| export type SubscriptionWebhookPayload = z.infer< | ||
| typeof SubscriptionWebhookPayloadSchema | ||
| >; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.