-
-
Save ImTheDeveloper/3155d36c05254cf9c2d73eadc332255d to your computer and use it in GitHub Desktop.
Zod Models for Lemon Squeezy Fetching Products Request
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
import { z } from 'zod'; | |
const SPagination = z.object({ | |
currentPage: z.number(), | |
from: z.number(), | |
lastPage: z.number(), | |
perPage: z.number(), | |
to: z.number(), | |
total: z.number(), | |
}); | |
const SMeta = z.object({ | |
page: SPagination, | |
}); | |
const SJsonapi = z.object({ | |
version: z.string(), | |
}); | |
const SLinks = z.object({ | |
first: z.string(), | |
last: z.string(), | |
}); | |
const SProductRelationships = z.object({ | |
links: z.object({ | |
related: z.string(), | |
self: z.string(), | |
}), | |
}); | |
const SAttributes = z.object({ | |
product_id: z.number(), | |
name: z.string(), | |
slug: z.string(), | |
description: z.string(), | |
price: z.number(), | |
is_subscription: z.boolean(), | |
interval: z.string().nullable(), | |
interval_count: z.number().nullable(), | |
has_free_trial: z.boolean(), | |
trial_interval: z.string(), | |
trial_interval_count: z.number(), | |
pay_what_you_want: z.boolean(), | |
min_price: z.number(), | |
suggested_price: z.number(), | |
has_license_keys: z.boolean(), | |
license_activation_limit: z.number(), | |
is_license_limit_unlimited: z.boolean(), | |
license_length_value: z.number(), | |
license_length_unit: z.string(), | |
is_license_length_unlimited: z.boolean(), | |
sort: z.number(), | |
status: z.string(), | |
status_formatted: z.string(), | |
created_at: z.string(), | |
updated_at: z.string(), | |
}); | |
const SVariants = z.object({ | |
type: z.string(), | |
id: z.string(), | |
attributes: SAttributes, | |
relationships: z.object({ | |
product: SProductRelationships, | |
}), | |
links: z.object({ | |
self: z.string(), | |
}), | |
}); | |
export const SLemonSqueezyRequest = z.object({ | |
meta: SMeta, | |
jsonapi: SJsonapi, | |
links: SLinks, | |
data: z.array(SVariants), | |
}); | |
export type TLemonSqueezyRequest = z.infer<typeof SLemonSqueezyRequest>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment