PaymentProvidable
import { PaymentProvidable } from '@payments/driver/schemas/PaymentProvidable.schema'Location
- PaymentProvidable.schema.ts
Zod Schema
What the schema would look like when defined with z.object() in Zod V3:
const PaymentProvidable = z.object({
userId: z
.string()
.index()
.describe("Auth provider user ID the plan is associated with"),
provider: z
.enum(["stripe", "revenuecat", "polar", "lemonsqueezy", "paddle", "clerk", "custom"])
.describe("Payment provider / driver name, e.g. 'stripe' or 'revenuecat'"),
})(💡 Could be handy to copy-paste this schema info into an AI chat assistant)
Type Definition
You can extract the TypeScript type from the schema using z.input(), z.output() or z.infer() methods. e.g.:
type PaymentProvidable = z.input<typeof PaymentProvidable>What the resulting TypeScript type would look like:
{
/** Auth provider user ID the plan is associated with */
userId: string;
/** Payment provider / driver name, e.g. 'stripe' or 'revenuecat' */
provider: "stripe" | "revenuecat" | "polar" | "lemonsqueezy" | "paddle" | "clerk" | "custom";
}(💡 Could be handy to copy-paste this type info into an AI chat assistant)
Usage - Validation
To validate data against this schema, you have a few options:
// Throws if invalid
const paymentProvidable = PaymentProvidable.parse(data)
// Returns { success: boolean, data?: T, error?: ZodError }
const paymentProvidable = PaymentProvidable.safeParse(data)
This might be useful for parsing API input data or validating form data before submission.
You can also directly integrate this schema with form state managers like our own:
Usage - Form State
import { useFormState } from '@green-stack/forms/useFormState'
const formState = useFormState(PaymentProvidable, {
initialValues: { /* ... */ }, // Provide initial values?
validateOnMount: true, // Validate on component mount?
})
Learn more about using schemas for form state in our Form Management Docs.
Usage - Component Props / Docs
Another potential use case for the ‘PaymentProvidable’ schema is to type component props, provide default values and generate documentation for that component:
export const PaymentProvidableComponentProps = PaymentProvidable.extend({
// Add any additional props here
})
export type PaymentProvidableComponentProps = z.input<typeof PaymentProvidableComponentProps>
/* --- <PaymentProvidableComponent/> --------------- */
export const PaymentProvidableComponent = (rawProps: PaymentProvidableComponentProps) => {
// Extract the props and apply defaults + infer resulting type
const props = ComponentProps.applyDefaults(rawProps)
// ... rest of the component logic ...
}
/* --- Documentation --------------- */
export const documentationProps = PaymentProvidableComponentProps.documentationProps('PaymentProvidableComponent')
Other
Disclaimer - Automatic Docgen
These dynamic schema docs were auto-generated with npm run regenerate-docs. This happens automatically for schema files in any \schemas\ folder. You can opt-out of this by adding // export const optOut = true somewhere in the file.
