UNPKG

wcz-layout

Version:

69 lines (54 loc) • 4.07 kB
--- name: services description: "Use when a feature needs a built-in wcz-layout backend service: file upload, download, thumbnails; approval requests, approvers and flows; PeopleSoft employee, manager, department lookups; sending email; or AI features: translating text into several languages with language detection, and extracting fields from an uploaded PDF or image. Also when an app calls another downstream REST API that wcz-layout has no service for." metadata: type: integration library: wcz-layout --- ## Info You can read about each service in the links below. Services are categorized as either client or server exports, depending on their intended usage. - **Client exports** — TanStack Query options from `wcz-layout/data/client`. - **Server exports** — Direct service operations from `wcz-layout/data/server`; import them only in server code. - Client exports marked `server fn (RPC)` are TanStack Start server functions callable from the client; use them as `queryFn` in a TanStack DB collection. - Invalidating mutation options take `{ queryClient }`. - Access `queryClient` with `Route.useRouteContext()` in a route file, or `useRouteContext({ from: "path" })` in a component. - To read about a service, open the linked file in the **File** column directly. ## Import Paths - Client exports: `wcz-layout/data/client` - Server exports: `wcz-layout/data/server` - Schemas & Models: `wcz-layout/models` - In service docs, inputs are referenced by schema name (`Schema`) and return values by model type (`Model` = `z.infer<typeof Schema>`); both are defined in each doc's **Schemas/Models** section. ## Services | Service | File | Summary | | ---------- | ----------------------------------- | ------------------------------------------------------------------------ | | file | [file.md](docs/file.md) | File metadata, thumbnails, binary download/open, upload, update, delete | | approval | [approval.md](docs/approval.md) | Approval request lifecycle, approvers, flows, statuses, step results | | peoplesoft | [peoplesoft.md](docs/peoplesoft.md) | Employee, manager, department, and company general manager lookups | | email | [email.md](docs/email.md) | Server-only email sending with optional file attachment references | | layout | [layout.md](docs/layout.md) | Layout app AI: translation with language detection, file data extraction | ## Custom API When the app needs a downstream REST API that no service above covers, build the client with `createApi` from `wcz-layout/data/server`. It resolves the base URL from env, attaches the signed-in user's token for the scope and turns error responses into `Error(message)`. It is server-only: call it inside a server function handler, never at module scope. 1. `src/env.ts`: add `MY_API_BASE_URL: z.url()` to `serverEnv` (the key must contain `BASE_URL`). 2. `src/lib/auth/scopes.ts`: add `myApi: "api://wistron.com/my-api/access_as_user"`. 3. `src/lib/schemas/<name>.ts`: Zod input schemas and response models. 4. `src/server/actions/<name>.ts`: one server function per endpoint, gated with `authMiddleware` (the token belongs to the signed-in user); see **server-functions**. ```ts import { createServerFn } from "@tanstack/react-start"; import { createApi } from "wcz-layout/data/server"; import { authMiddleware } from "wcz-layout/middleware"; import { MyModelSchema, type MyModel } from "~/lib/schemas/inventory"; const myApi = () => createApi({ baseURL: "MY_API_BASE_URL", scopeKey: "myApi" }); export const getItem = createServerFn({ method: "GET" }) .validator(MyModelSchema) .middleware([authMiddleware()]) .handler(async ({ data }) => { const api = await myApi(); const { data: item } = await api.get<MyModel>(`/items/${encodeURIComponent(data.id)}`); return item; }); ``` Wrap reads in `queryOptions` and writes in `mutationOptions`, the same shape as the built-in client exports.