Skip to content
4 changes: 2 additions & 2 deletions docs/src/app/docs/core-api/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ All these methods like `read` and `browse` gives you back the appropriate `Fetch
### Instantiation

```ts
import { z } from "zod/v3";
import { z } from "zod";
import { APIComposer, HTTPClient, type HTTPClientOptions } from "@ts-ghost/core-api";

const credentials: HTTPClientOptions = {
Expand Down Expand Up @@ -109,7 +109,7 @@ After instantiation you can use the `APIComposer` to build your queries with 2 a
The `browse` and `read` methods accept a config object with 2 properties: `input` and an `output`. These params mimic the way Ghost API Content is built but with the power of Zod and TypeScript they are type-safe here.

```ts
import { z } from "zod/v3";
import { z } from "zod";
import { APIComposer, HTTPClient, type HTTPClientOptions } from "@ts-ghost/core-api";

const credentials: HTTPClientOptions = {
Expand Down
5 changes: 4 additions & 1 deletion packages/ts-ghost-admin-api/src/admin-api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { z } from "zod/v3";
import { z } from "zod";
import {
adminAPICredentialsSchema,
APIComposer,
Expand All @@ -7,6 +7,7 @@ import {
baseSiteSchema,
baseTagsSchema,
BasicFetcher,
DebugOption,
emailOrIdSchema,
HTTPClientFactory,
slugOrIdSchema,
Expand All @@ -31,13 +32,15 @@ export class TSGhostAdminAPI<Version extends `v5.${string}` | `v6.${string}` = a
protected readonly url: string,
protected readonly key: string,
protected readonly version: Version,
protected readonly options?: DebugOption,
) {
const apiCredentials = adminAPICredentialsSchema.parse({
key,
version,
url,
});
this.httpClientFactory = new HTTPClientFactory({
...options,
...apiCredentials,
endpoint: "admin",
});
Expand Down
6 changes: 3 additions & 3 deletions packages/ts-ghost-admin-api/src/schemas/authors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { z } from "zod/v3";
import { z } from "zod";
import { baseAuthorsSchema } from "@ts-ghost/core-api";

export const adminAuthorsSchema = baseAuthorsSchema.merge(
Expand All @@ -23,10 +23,10 @@ export const adminAuthorsSchema = baseAuthorsSchema.merge(
description: z.string(),
created_at: z.string().nullish(),
updated_at: z.string().nullish(),
}),
})
)
.optional(),
}),
})
);

export type Author = z.infer<typeof adminAuthorsSchema>;
54 changes: 29 additions & 25 deletions packages/ts-ghost-admin-api/src/schemas/members.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,65 @@
import { z } from "zod/v3";
import { z } from "zod";
import { baseMembersSchema } from "@ts-ghost/core-api";

export const adminMembersCreateSchema = z.object({
email: z.string({ description: "The email address of the member" }).email(),
name: z.string({ description: "The name of the member" }).optional(),
note: z.string({ description: "(nullable) A note about the member" }).optional(),
geolocation: z.string({ description: "(nullable) The geolocation of the member" }).optional(),
email: z.email().meta({ description: "The email address of the member" }),
name: z.string().meta({ description: "The name of the member" }).optional(),
note: z.string().meta({ description: "(nullable) A note about the member" }).optional(),
geolocation: z.string().meta({ description: "(nullable) The geolocation of the member" }).optional(),
labels: z
.array(
z.union([
z.object({
id: z.string({ description: "The ID of the label" }),
id: z.string().meta({ description: "The ID of the label" }),
}),
z.object({
name: z.string({ description: "The name of the label" }),
name: z.string().meta({ description: "The name of the label" }),
}),
z.object({
slug: z.string({ description: "The slug of the label" }),
slug: z.string().meta({ description: "The slug of the label" }),
}),
]),
{ description: "The labels associated with the member" },
)
.meta({ description: "The labels associated with the member" })
.optional(),
products: z
.array(
z.union([
z.object({
id: z.string({ description: "The ID of the subscription" }),
id: z.string().meta({ description: "The ID of the subscription" }),
}),
z.object({
name: z.string({ description: "The name of the subscription" }),
name: z.string().meta({ description: "The name of the subscription" }),
}),
z.object({
slug: z.string({ description: "The slug of the subscription" }),
slug: z.string().meta({ description: "The slug of the subscription" }),
}),
]),
{
description: `The products associated with the member, they correspond to a stripe product.
If given the member status will be 'comped' as given away a subscription.`,
},
)
.meta({
description: `The products associated with the member, they correspond to a stripe product.
If given the member status will be 'comped' as given away a subscription.`,
})
.optional(),
// newsletters and subscribed exclude each other. `subscribed`
newsletters: z
.array(
z.union([
z.object({
id: z.string({ description: "The ID of the newsletter" }),
id: z.string().meta({ description: "The ID of the newsletter" }),
}),
z.object({
name: z.string({ description: "The name of the newsletter" }),
name: z.string().meta({ description: "The name of the newsletter" }),
}),
]),
{
description: `Specifing newsletter to subscribe to via id or name, incompatible with the \`subscribed\` property`,
},
)
.meta({
description: `Specifying newsletter to subscribe to via id or name, incompatible with the \`subscribed\` property`,
})
.optional(),
subscribed: z
.boolean({
.boolean()
.meta({
description:
"Will subscribe the user to the default Newsletter, incompatible with the `newsletters` property",
})
Expand All @@ -81,9 +82,12 @@ export const adminMembersSchema = baseMembersSchema.merge(
newsletters: z.array(
z.object({
id: z.string(),
name: z.string({ description: "Public name for the newsletter" }),
description: z.string({ description: "(nullable) Public description of the newsletter" }).nullish(),
status: z.union([z.literal("active"), z.literal("archived")], {
name: z.string().meta({ description: "Public name for the newsletter" }),
description: z
.string()
.meta({ description: "(nullable) Public description of the newsletter" })
.nullish(),
status: z.union([z.literal("active"), z.literal("archived")]).meta({
description: "active or archived - denotes if the newsletter is active or archived",
}),
}),
Expand Down
4 changes: 2 additions & 2 deletions packages/ts-ghost-admin-api/src/schemas/newsletters.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { z } from "zod/v3";
import { z } from "zod";

export const adminNewsletterCreateSchema = z.object({
name: z.string(),
description: z.string().max(3000).optional(),
sender_name: z.string(),
sender_email: z.string().email().nullish(),
sender_email: z.email().nullish(),
sender_reply_to: z.string().optional(),
status: z.union([z.literal("active"), z.literal("archived")]).optional(),
subscribe_on_signup: z.boolean().optional(),
Expand Down
7 changes: 4 additions & 3 deletions packages/ts-ghost-admin-api/src/schemas/offers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import isSlug from "validator/lib/isSlug";
import { z } from "zod/v3";
import { z } from "zod";

const baseOffersCreateSchema = z.object({
name: z.string(),
Expand All @@ -9,12 +9,13 @@ const baseOffersCreateSchema = z.object({
display_title: z.string().optional(),
display_description: z.string().optional(),
cadence: z.union([z.literal("year"), z.literal("month")]),
amount: z.number({
amount: z.number().meta({
description: "Amount of the percent or fixed amount in the smallest unit of the currency",
}),
duration: z.union([z.literal("once"), z.literal("forever"), z.literal("repeating")]),
duration_in_months: z
.number({
.number()
.meta({
description: "Number of months offer should be repeated when duration is repeating",
})
.nullish(),
Expand Down
38 changes: 19 additions & 19 deletions packages/ts-ghost-admin-api/src/schemas/pages.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { z } from "zod/v3";
import { z } from "zod";
import { basePagesSchema } from "@ts-ghost/core-api";

import { adminAuthorsSchema } from "./authors";
Expand Down Expand Up @@ -82,55 +82,55 @@ export const adminPagesCreateSchema = z.object({
.array(
z.union([
z.object({
id: z.string({ description: "The ID of the tags" }),
id: z.string().meta({ description: "The ID of the tags" }),
}),
z.object({
name: z.string({ description: "The name of the tags" }),
name: z.string().meta({ description: "The name of the tags" }),
}),
z.object({
slug: z.string({ description: "The slug of the tags" }),
slug: z.string().meta({ description: "The slug of the tags" }),
}),
]),
{
description: `The tags associated with the post array of either slug, id or name`,
},
)
.meta({
description: `The tags associated with the post array of either slug, id or name`,
})
.optional(),
tiers: z
.array(
z.union([
z.object({
id: z.string({ description: "The ID of the tiers" }),
id: z.string().meta({ description: "The ID of the tiers" }),
}),
z.object({
name: z.string({ description: "The name of the tiers" }),
name: z.string().meta({ description: "The name of the tiers" }),
}),
z.object({
slug: z.string({ description: "The slug of the tiers" }),
slug: z.string().meta({ description: "The slug of the tiers" }),
}),
]),
{
description: `The tiers associated with the post array of either slug, id or name`,
},
)
.meta({
description: `The tiers associated with the post array of either slug, id or name`,
})
.optional(),
authors: z
.array(
z.union([
z.object({
id: z.string({ description: "The ID of the author" }),
id: z.string().meta({ description: "The ID of the author" }),
}),
z.object({
name: z.string({ description: "The name of the author" }),
name: z.string().meta({ description: "The name of the author" }),
}),
z.object({
email: z.string({ description: "The email of the author" }),
email: z.string().meta({ description: "The email of the author" }),
}),
]),
{
description: `Specifing author via id, name or slug.`,
},
)
.meta({
description: `Specifying author via id, name or slug.`,
})
.optional(),
});

Expand Down
42 changes: 21 additions & 21 deletions packages/ts-ghost-admin-api/src/schemas/posts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { z } from "zod/v3";
import { z } from "zod";
import { baseEmailSchema, baseNewsletterSchema, basePostsSchema } from "@ts-ghost/core-api";

import { adminAuthorsSchema } from "./authors";
Expand Down Expand Up @@ -88,63 +88,63 @@ const basePostsCreateSchema = z.object({
.array(
z.union([
z.object({
id: z.string({ description: "The ID of the tags" }),
id: z.string().meta({ description: "The ID of the tags" }),
}),
z.object({
name: z.string({ description: "The name of the tags" }),
name: z.string().meta({ description: "The name of the tags" }),
}),
z.object({
slug: z.string({ description: "The slug of the tags" }),
slug: z.string().meta({ description: "The slug of the tags" }),
}),
]),
{
description: `The tags associated with the post array of either slug, id or name`,
},
)
.meta({
description: `The tags associated with the post array of either slug, id or name`,
})
.optional(),
tiers: z
.array(
z.union([
z.object({
id: z.string({ description: "The ID of the tiers" }),
id: z.string().meta({ description: "The ID of the tiers" }),
}),
z.object({
name: z.string({ description: "The name of the tiers" }),
name: z.string().meta({ description: "The name of the tiers" }),
}),
z.object({
slug: z.string({ description: "The slug of the tiers" }),
slug: z.string().meta({ description: "The slug of the tiers" }),
}),
]),
{
description: `The tiers associated with the post array of either slug, id or name`,
},
)
.meta({
description: `The tiers associated with the post array of either slug, id or name`,
})
.optional(),
authors: z
.array(
z.union([
z.object({
id: z.string({ description: "The ID of the author" }),
id: z.string().meta({ description: "The ID of the author" }),
}),
z.object({
name: z.string({ description: "The name of the author" }),
name: z.string().meta({ description: "The name of the author" }),
}),
z.object({
email: z.string({ description: "The email of the author" }),
email: z.string().meta({ description: "The email of the author" }),
}),
]),
{
description: `Specifing author via id, name or slug.`,
},
)
.meta({
description: `Specifying author via id, name or slug.`,
})
.optional(),
newsletter: z
.union([
z.object({
id: z.string({ description: "The ID of the newsletter" }),
id: z.string().meta({ description: "The ID of the newsletter" }),
}),
z.object({
slug: z.string({ description: "The slug of the newsletter" }),
slug: z.string().meta({ description: "The slug of the newsletter" }),
}),
])
.optional(),
Expand Down
4 changes: 2 additions & 2 deletions packages/ts-ghost-admin-api/src/schemas/tags.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { z } from "zod/v3";
import { z } from "zod";

export const adminTagsCreateSchema = z.object({
name: z.string().min(1).max(191),
slug: z.string().max(191).optional(),
description: z.string().max(500).optional(),
feature_image: z.string().url().optional(),
feature_image: z.url().optional(),
visibility: z.union([z.literal("public"), z.literal("internal")]).optional(),
meta_title: z.string().max(300).optional(),
meta_description: z.string().max(500).optional(),
Expand Down
Loading