All files / packages / shared/src system.ts

100% Statements 4/4
100% Branches 0/0
100% Functions 0/0
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40      4x         4x                                               4x           4x  
import { z } from 'zod'
import type { Endpoint } from './endpoint'
 
export const HealthSchema = z.object({ status: z.literal('ok') })
 
export type Health = z.infer<typeof HealthSchema>
 
// The SPA reads this from the Worker at start, so one build serves every environment (design 2.4).
export const PublicConfigSchema = z.object({
  environment: z.enum(['local', 'dev', 'staging', 'production']),
  firebase: z.object({
    projectId: z.string(),
    apiKey: z.string(),
    authDomain: z.string(),
    // FCM web push (M4): public too, the browser needs them to ask for a push token.
    messagingSenderId: z.string(),
    appId: z.string(),
    vapidKey: z.string(),
  }),
  // Branch previews sign in through the dev host, which is the one host Firebase and Google know.
  signIn: z
    .object({
      /** On a preview: the dev site that signs in on its behalf. */
      brokerUrl: z.url({ protocol: /^https$/ }).optional(),
      /** On dev: a regex for the origins the broker may hand a Google ID token to. */
      brokerReturnPattern: z.string().min(1).optional(),
    })
    .optional(),
})
 
export type PublicConfig = z.infer<typeof PublicConfigSchema>
 
export const SYSTEM_API = {
  health: { method: 'GET', path: '/healthz', response: HealthSchema },
  config: { method: 'GET', path: '/api/config', response: PublicConfigSchema },
} as const satisfies Record<string, Endpoint>
 
// The Swagger page and its JSON: not endpoints, they have no zod body.
export const API_DOCS = { page: '/api/docs', openApi: '/api/docs/openapi.json' } as const