dkitdkit

Services

TypeScript helpers installed with each module — fetch posts, pages, submit forms — as lib/dkit/<module>.ts you own.

Overview

Services are the query and action functions in each module's lib.ts. After dkit add, they live in your app as lib/dkit/<module>.ts (plus types). UI blocks import them; you can call the same helpers from your own routes.

Naming is getBlogPosts, getBlogPostBySlug, getPageBuilderPages, and so on. List helpers take an options object (getBlogPosts({ limit, status, category })). They use your project's @/lib/dkit/client and collections only; you own and edit the files.

Directus flows and sample seed data are separate — they ship under services/ in the registry and show on each module page as Flows & seed.

Install

npx dkit add blog
# → lib/dkit/blog.ts
# → lib/dkit/blog.types.ts

import { getBlogPosts } from "@/lib/dkit/blog";

Blog & Authors

lib/dkit/blog.ts · Module page

  • function authorAvatarUrl(post: BlogPost): string | null
  • function authorName(post: BlogPost): string | null
  • function featuredImageUrl(post: BlogPost): string | null
  • async function getBlogAuthorById(id: string): Promise<BlogAuthor | null>
  • async function getBlogAuthorBySlug(
      slug: string,
      options: GetBlogBySlugOptions = {}
    ): Promise<BlogAuthor | null>
  • Authors, by name.

    async function getBlogAuthors(options: GetBlogAuthorsOptions = {}): Promise<BlogAuthor[]>
  • Categories, by title.

    async function getBlogCategories(options: GetBlogCategoriesOptions = {}): Promise<BlogCategory[]>
  • async function getBlogCategoryById(id: string): Promise<BlogCategory | null>
  • async function getBlogCategoryBySlug(slug: string): Promise<BlogCategory | null>
  • async function getBlogPostById(id: string): Promise<BlogPost | null>
  • async function getBlogPostBySlug(
      slug: string,
      options: GetBlogBySlugOptions = {}
    ): Promise<BlogPost | null>
  • Posts, newest first.

    async function getBlogPosts(options: GetBlogPostsOptions = {}): Promise<BlogPost[]>
  • function normalizeCategories(
      raw: BlogPost["categories"] | JunctionCategory[] | null | undefined
    ): BlogCategory[]

Pages (WYSIWYG)

lib/dkit/pages.ts · Module page

  • async function getPageById(id: string): Promise<SitePage | null>
  • async function getPageBySlug(
      slug: string,
      options: GetPageBySlugOptions = {}
    ): Promise<SitePage | null>
  • Pages module list helper.

    async function getPages(options: GetPagesOptions = {}): Promise<SitePage[]>

Contact form

lib/dkit/contact-form.ts · Module page

  • Create a contact-form submission (inbox). Prefer submitContactForm from UI.

    async function createContactSubmission(input: FormSubmissionInput): Promise<{ ok: true; id?: string } | { ok: false; error: string }>
  • Server Action for the contact form UI.

    async function submitContactForm(
      _prev: ContactFormState,
      formData: FormData
    ): Promise<ContactFormState>

Dynamic Page Builder

lib/dkit/page-builder.ts · Module page

  • async function getPageBuilderPageById(id: string): Promise<BuilderPage | null>
  • async function getPageBuilderPageBySlug(
      slug: string,
      options: GetPageBuilderPageBySlugOptions = {}
    ): Promise<BuilderPage | null>
  • Builder pages for the page-builder module.

    async function getPageBuilderPages(options: GetPageBuilderPagesOptions = {}): Promise<BuilderPage[]>