portals-sdk
v0.3.2
Published
End-user JavaScript/TypeScript client for the Embeddables v1 API.
Readme
portals-sdk
End-user JavaScript/TypeScript client for the Embeddables portals public API
(/portals/v1/public/*). Portal apps use Core authentication re-exposed as
client.auth and use this package to read profiles, manage usage and symptom logs,
read Shopify order mirror data,
and create outbound messages — without importing internal Embeddables workspace
packages.
For AI agents: how to change the package in
docs/sdk/portals-sdk.md(rules shared across every SDK indocs/sdk/sdk.md); routing inAGENTS.md. This file is for human/npm consumers.
Install
pnpm add portals-sdk @embeddables/core @sentry/react
# or
npm install portals-sdk @embeddables/core @sentry/reactPeer (install alongside this package): @sentry/react.
hono and zod ship as dependencies.
Quick start (live)
import { initEmbeddables } from '@embeddables/core'
import { initPortals } from 'portals-sdk'
const core = initEmbeddables({
projectId: '…',
forms: [],
experiments: [],
publishableKey: 'pk_live_…', // from admin-web-app-worker → Settings → Portal / SDK
})
const client = initPortals(core)
await client.auth.requestOtp({ phone: '+15551234567' })
// complete OTP in your UI, then:
await client.auth.verifyOtp({ phone: '+15551234567', token: '123456' })
const profile = await client.profile.get()
await client.messages.create({ text: 'Hello from the portal' })
const orders = await client.orders.list() // Shopify mirror + trackings[]For sandbox provisioning, configure auth.sandboxUser on initEmbeddables.
Authentication is available through client.auth.
Mock mode (local UI dev)
Pass mock in portals options to run fully offline — no Embeddables backend
required. Core does not need a publishable key in mock mode:
import { initEmbeddables } from '@embeddables/core'
import { initPortals, defineMockPersona } from 'portals-sdk'
const core = initEmbeddables({
projectId: '…',
forms: [],
experiments: [],
})
const persona = defineMockPersona({
id: 'active-streak',
label: 'Active Streak',
// … fixtures: profile, messages, usageLogs, shopifyOrders, etc.
})
const client = initPortals(core, {
mock: { personas: [persona], initialPersonaId: persona.id },
})Optional devtools bar (persona switcher, virtual date/time):
import { mountPortalsMockDevBar } from 'portals-sdk/devtools'
if (import.meta.env.DEV) {
mountPortalsMockDevBar(client)
}Monitoring (optional)
import { initSentryMonitoring } from 'portals-sdk/monitoring'
await initSentryMonitoring({
dsn: import.meta.env.VITE_SENTRY_DSN,
environment: 'production',
portal: 'my-brand-portal',
})Events go to the portals-sdk Sentry project. See root
README.md for DSN and trace propagation setup.
Build from source (monorepo)
The SDK uses Hono RPC typing: client.ts imports PortalsPublicAppType from
backend-worker at build time so client methods stay in sync with portal
routes without hand-written response types. That is a dev-only workspace
dependency — tsdown inlines resolved types into published .d.ts, so npm
consumers never install backend-worker.
Build order (each package emits dist/*.d.ts for the next):
pnpm --filter @embeddables/core build
pnpm --filter @embeddables/shared-types build
pnpm --filter backend-worker build
pnpm --filter portals-sdk buildPublished artifacts are ESM + CJS + .d.ts under dist/.
Slim PortalsPublicAppType-only type extraction is deferred unless compile
time becomes a measured problem.
Local API override
Set at consumer build time (Vite VITE_*):
| Variable | Purpose |
| ---------------------- | ------------------ |
| VITE_PORTALS_API_URL | Backend API origin |
Defaults target production; unset vars work when core supplies a publishable
key for live mode. A Dev or local host needs the same origin on both clients:
initEmbeddables({ baseUrl }) and initPortals(core, { baseUrl }). Omitting
baseUrl still honors VITE_PORTALS_API_URL for Portal requests only.
