@shophost/rest-api
v2.0.76
Published
`@shophost/rest-api` is the backend package for ShopHost. It provides:
Maintainers
Readme
@shophost/rest-api
@shophost/rest-api is the backend package for ShopHost. It provides:
- the core API app builder
- a Next.js route handler integration
- exported Zod/OpenAPI schemas
- a packaged Prisma schema and CLI for database sync
Installation
pnpm add @shophost/rest-api prisma @prisma/client @prisma/client-runtime-utilsPeer dependencies:
next >= 14react >= 18react-dom >= 18
Entry Points
@shophost/rest-apiExposesbuildApiApp,generateOpenApiSpec, and schema exports.@shophost/rest-api/nextExposescreateNextHandlerfor Next.js App Router route handlers.@shophost/rest-api/dbExposes packaged Prisma client helpers.@shophost/rest-api/schemasExposes reusable request/response schemas.
Next.js Usage
Create an App Router API route:
import { createNextHandler } from "@shophost/rest-api/next";
const handler = createNextHandler({
database: {
connectionString: process.env.DATABASE_URL!,
log: ["info", "warn", "error"],
},
maps: {
google: {
key: process.env.GOOGLE_PLACES_API_KEY!,
},
},
auth: {
baseURL: process.env.NEXT_PUBLIC_API_BASE_URL!,
domain: new URL(process.env.NEXT_PUBLIC_API_BASE_URL!).hostname.split(".").slice(-2).join("."),
trustedOrigins: [process.env.NEXT_PUBLIC_APP_DOMAIN!],
socialProviders: {
google: {
clientId: process.env.AUTH_GOOGLE_ID!,
clientSecret: process.env.AUTH_GOOGLE_SECRET!,
},
},
},
});
export { handler as GET, handler as POST, handler as PUT, handler as PATCH, handler as DELETE, handler as OPTIONS };You can configure Resend per organization from the admin UI under
Settings -> Integrations -> Resend.
Database Schema Sync
The published package ships the Prisma schema and a CLI so a consuming app can push the schema without copying Prisma files into the host project.
- Set
DATABASE_URLin.env.local,.env, or your shell. - Run:
pnpm exec shophost-rest-api db pushYou can also pass standard Prisma flags through:
pnpm exec shophost-rest-api db push --accept-data-loss
pnpm exec shophost-rest-api db push --url "postgresql://user:password@host:5432/dbname?sslmode=require"Schemas and Utilities
Import shared schemas:
import { CreateProductSchema, ProductSchema } from "@shophost/rest-api/schemas";Import Prisma helpers owned by this package:
import { createPrismaClient, PrismaClient } from "@shophost/rest-api/db";Generate the OpenAPI document:
import { generateOpenApiSpec } from "@shophost/rest-api";
const spec = generateOpenApiSpec();Local Development
pnpm exec nx run rest-api:prisma:generate
pnpm exec nx run rest-api:testLicense
MIT
