@biab-dev/sdk 0.2.1 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,175 @@
1
+ /**
2
+ * SDK auth handler — the file a tenant developer mounts on their own site
3
+ * to handle the WorkOS callback. Cookie lives on the tenant's domain so the
4
+ * tenant's SSR can read it via standard cookie APIs.
5
+ *
6
+ * Usage (Next.js App Router):
7
+ *
8
+ * // app/api/biab-auth/[...biab]/route.ts
9
+ * import { createAuthHandler } from "@biab-dev/sdk";
10
+ *
11
+ * const handler = createAuthHandler({
12
+ * baseUrl: process.env.BIAB_PACKAGE_API_BASE_URL!,
13
+ * apiKey: process.env.BIAB_API_KEY!,
14
+ * callbackUrl: "https://my-site.com/api/biab-auth/callback",
15
+ * });
16
+ *
17
+ * export const GET = handler.GET;
18
+ * export const POST = handler.POST;
19
+ *
20
+ * Then drop <SignIn />, <SignUp />, <SignOut /> into your pages — they call
21
+ * `/api/biab-auth/sign-in?intent=sign-in` etc., which 302s through the WorkOS
22
+ * hosted page and back to `callbackUrl`. The handler exchanges the code,
23
+ * sets the session cookie, and redirects the user to `returnTo`.
24
+ */
25
+ import { BiabDevClient, } from "./client";
26
+ export const DEFAULT_AUTH_COOKIE_NAME = "biab_session";
27
+ export const DEFAULT_AUTH_BASE_PATH = "/api/biab-auth";
28
+ function buildSetCookie(name, value, opts) {
29
+ const parts = [`${name}=${value}`, "Path=/", "HttpOnly", "SameSite=Lax"];
30
+ parts.push("Secure");
31
+ if (opts.domain)
32
+ parts.push(`Domain=${opts.domain}`);
33
+ if (opts.clear) {
34
+ parts.push("Max-Age=0");
35
+ }
36
+ else if (opts.expiresAt) {
37
+ parts.push(`Expires=${opts.expiresAt.toUTCString()}`);
38
+ }
39
+ return parts.join("; ");
40
+ }
41
+ function readCookie(request, name) {
42
+ const header = request.headers.get("cookie");
43
+ if (!header)
44
+ return null;
45
+ for (const part of header.split(";")) {
46
+ const [k, ...rest] = part.trim().split("=");
47
+ if (k === name)
48
+ return rest.join("=");
49
+ }
50
+ return null;
51
+ }
52
+ /**
53
+ * `auth/start` expects `returnTo` as an absolute URL. Plain paths like `/` come
54
+ * from `defaultReturnTo` and from `<SignIn returnTo="/dashboard" />`.
55
+ */
56
+ function absolutizeReturnTo(returnTo, requestUrl) {
57
+ try {
58
+ return new URL(returnTo, requestUrl).href;
59
+ }
60
+ catch {
61
+ return new URL("/", requestUrl).href;
62
+ }
63
+ }
64
+ function decodeReturnTo(state) {
65
+ if (!state)
66
+ return null;
67
+ try {
68
+ const decoded = Buffer.from(state, "base64url").toString("utf8");
69
+ const parsed = JSON.parse(decoded);
70
+ if (typeof parsed.returnTo === "string")
71
+ return parsed.returnTo;
72
+ }
73
+ catch {
74
+ /* ignore */
75
+ }
76
+ return null;
77
+ }
78
+ export function createAuthHandler(options) {
79
+ const cookieName = options.cookieName ?? DEFAULT_AUTH_COOKIE_NAME;
80
+ const basePath = (options.basePath ?? DEFAULT_AUTH_BASE_PATH).replace(/\/$/, "");
81
+ const defaultReturnTo = options.defaultReturnTo ?? "/";
82
+ const signOutReturnTo = options.signOutReturnTo ?? "/";
83
+ const client = new BiabDevClient({
84
+ baseUrl: options.baseUrl,
85
+ apiKey: options.apiKey,
86
+ ...(options.fetch ? { fetch: options.fetch } : {}),
87
+ });
88
+ async function handle(request) {
89
+ const url = new URL(request.url);
90
+ const subroute = url.pathname.startsWith(basePath)
91
+ ? url.pathname.slice(basePath.length).replace(/^\//, "")
92
+ : url.pathname;
93
+ // /sign-in?returnTo=... and /sign-up?returnTo=...
94
+ if (subroute === "sign-in" || subroute === "sign-up") {
95
+ const rawReturnTo = url.searchParams.get("returnTo") ?? defaultReturnTo;
96
+ const start = await client.auth.start({
97
+ intent: subroute === "sign-up" ? "sign-up" : "sign-in",
98
+ returnTo: absolutizeReturnTo(rawReturnTo, request.url),
99
+ redirectUri: options.callbackUrl,
100
+ loginHint: url.searchParams.get("loginHint") ?? undefined,
101
+ });
102
+ return Response.redirect(start.url, 302);
103
+ }
104
+ // /callback?code=...&state=...
105
+ if (subroute === "callback") {
106
+ const code = url.searchParams.get("code");
107
+ if (!code) {
108
+ return new Response("Missing code", { status: 400 });
109
+ }
110
+ try {
111
+ const session = await client.auth.exchange({
112
+ code,
113
+ redirectUri: options.callbackUrl,
114
+ });
115
+ const returnTo = decodeReturnTo(url.searchParams.get("state")) ?? defaultReturnTo;
116
+ return new Response(null, {
117
+ status: 302,
118
+ headers: {
119
+ Location: returnTo,
120
+ "Set-Cookie": buildSetCookie(cookieName, session.sessionToken, {
121
+ expiresAt: new Date(session.expiresAt),
122
+ domain: options.cookieDomain,
123
+ }),
124
+ },
125
+ });
126
+ }
127
+ catch (err) {
128
+ const message = err instanceof Error ? err.message : "exchange failed";
129
+ return new Response(`Sign-in failed: ${message}`, { status: 400 });
130
+ }
131
+ }
132
+ // /sign-out
133
+ if (subroute === "sign-out") {
134
+ await client.auth.signOut().catch(() => undefined);
135
+ return new Response(null, {
136
+ status: 302,
137
+ headers: {
138
+ Location: signOutReturnTo,
139
+ "Set-Cookie": buildSetCookie(cookieName, "", {
140
+ clear: true,
141
+ domain: options.cookieDomain,
142
+ }),
143
+ },
144
+ });
145
+ }
146
+ // /me — returns the current session (or null) as JSON, scoped to this cookie.
147
+ if (subroute === "me") {
148
+ const token = readCookie(request, cookieName);
149
+ if (!token) {
150
+ return Response.json(null);
151
+ }
152
+ const me = await client.auth
153
+ .me({ sessionToken: token })
154
+ .catch(() => null);
155
+ return Response.json(me);
156
+ }
157
+ return new Response("Not found", { status: 404 });
158
+ }
159
+ return { GET: handle, POST: handle };
160
+ }
161
+ /**
162
+ * Server-side helper for tenant SSR: read the current session from the cookie.
163
+ * Returns null when the user isn't signed in.
164
+ */
165
+ export async function getTenantSession(input) {
166
+ if (!input.cookieValue)
167
+ return null;
168
+ const client = new BiabDevClient({
169
+ baseUrl: input.baseUrl,
170
+ apiKey: input.apiKey,
171
+ ...(input.fetch ? { fetch: input.fetch } : {}),
172
+ });
173
+ return client.auth.me({ sessionToken: input.cookieValue }).catch(() => null);
174
+ }
175
+ //# sourceMappingURL=auth-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-handler.js","sourceRoot":"","sources":["../src/auth-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EACN,aAAa,GAEb,MAAM,UAAU,CAAC;AAElB,MAAM,CAAC,MAAM,wBAAwB,GAAG,cAAc,CAAC;AACvD,MAAM,CAAC,MAAM,sBAAsB,GAAG,gBAAgB,CAAC;AAuCvD,SAAS,cAAc,CACtB,IAAY,EACZ,KAAa,EACb,IAAgG;IAEhG,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,IAAI,KAAK,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,cAAc,CAAC,CAAC;IACzE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACrB,IAAI,IAAI,CAAC,MAAM;QAAE,KAAK,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACrD,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;QAChB,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACzB,CAAC;SAAM,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;QAC3B,KAAK,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC;AAED,SAAS,UAAU,CAAC,OAAgB,EAAE,IAAY;IACjD,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC7C,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACzB,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,CAAC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AI,aAAa,CAAC;QAChC,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC9C,CAAC,CAAC;IACH,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,YAAY,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;AAC9E,CAAC"}
package/dist/client.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { z } from "zod";
2
- import { type AuthIntrospectResponse, type CreateCollectionInput, type CreateCollectionResponse, type CreateEmailTemplateInput, type CreateEmailTemplateResponse, type CreateEmailTemplateVersionInput, type CreateEmailTemplateVersionResponse, type DashboardSessionResponse, type ExecuteActionInput, type ExecuteActionResponse, type FollowerEditInput, type FollowerEditResponse, type FollowerJoinInput, type FollowerJoinResponse, type FollowerLeaveInput, type FollowerLeaveResponse, type FollowerMeInput, type FollowerMeResponse, type GetCollectionResponse, type GetEmailTemplateResponse, type GetSiteMarketingPageResponse, type ListCollectionsResponse, type ListEmailTemplatesInput, type ListEmailTemplatesResponse, type ListRowsInput, type ListRowsResponse, type QueryRowsInput, type QueryRowsResponse, type SiteAssetInput, type UploadSiteAssetResponse, type UpsertRowInput, type UpsertRowResponse } from "./contracts";
2
+ import { type AuthIntrospectResponse, type TenantAuthExchangeInput, type TenantAuthExchangeResponse, type TenantAuthMeResponse, type TenantAuthSignOutResponse, type TenantAuthStartInput, type TenantAuthStartResponse, type BlogSessionInput, type BlogSessionResponse, type CartSessionResponse, type ChatbotChatInput, type ChatbotChatResponse, type ChatbotConfig, type ChatbotConfigUpdateInput, type ChatbotSessionResponse, type CheckoutSessionInput, type CheckoutSessionResponse, type CreateCollectionInput, type CreateCollectionResponse, type CreateEmailTemplateInput, type CreateEmailTemplateResponse, type CreateEmailTemplateVersionInput, type CreateEmailTemplateVersionResponse, type CustomerPortalContextResponse, type CustomerPortalOtherOrgsResponse, type CustomerPortalProfile, type CustomerPortalUpdateProfileInput, type CustomerPortalUpdateProfileResponse, type DashboardSessionResponse, type ExecuteActionInput, type ExecuteActionResponse, type FollowerEditInput, type FollowerEditResponse, type FollowerJoinInput, type FollowerJoinResponse, type FollowerLeaveInput, type FollowerLeaveResponse, type FollowerMeInput, type FollowerMeResponse, type GetCollectionResponse, type GetEmailTemplateResponse, type GetSiteMarketingPageResponse, type ListCollectionsResponse, type ListEmailTemplatesInput, type ListEmailTemplatesResponse, type ListRowsInput, type ListRowsResponse, type QueryRowsInput, type QueryRowsResponse, type SiteAssetInput, type StorefrontSessionInput, type StorefrontSessionResponse, type UploadSiteAssetResponse, type UpsertRowInput, type UpsertRowResponse } from "./contracts";
3
3
  export type FetchLike = typeof fetch;
4
4
  /** Options for {@link BiabDevClient} / {@link createBiabDevClient}. */
5
5
  export type BiabDevClientOptions = {
@@ -14,6 +14,7 @@ type RequestOptions<T> = {
14
14
  query?: Record<string, string | number | boolean | undefined>;
15
15
  body?: unknown;
16
16
  responseSchema: z.ZodType<T, z.ZodTypeDef, unknown>;
17
+ headers?: HeadersInit;
17
18
  };
18
19
  /**
19
20
  * Typed client for the BIAB package HTTP API.
@@ -31,6 +32,20 @@ export declare class BiabDevClient {
31
32
  site(siteId: string): BiabDevSiteClient;
32
33
  get emailTemplates(): BiabDevEmailTemplatesClient;
33
34
  get dashboard(): BiabDevDashboardClient;
35
+ get storefront(): BiabDevStorefrontClient;
36
+ get cart(): BiabDevCartClient;
37
+ get checkout(): BiabDevCheckoutClient;
38
+ get blog(): BiabDevBlogClient;
39
+ get chatbot(): BiabDevChatbotClient;
40
+ get auth(): BiabDevAuthClient;
41
+ /**
42
+ * Customer-portal client. Pin to a specific WorkOS organization id so the
43
+ * caller never sees data from any other org (recommended). Omit
44
+ * `organizationId` to fall back to the user's currently-active session
45
+ * org — only use that on first-party hosts where the host already pins
46
+ * the org.
47
+ */
48
+ customerPortal(organizationId?: string): BiabDevCustomerPortalClient;
34
49
  introspect(): Promise<AuthIntrospectResponse>;
35
50
  request<T>(options: RequestOptions<T>): Promise<T>;
36
51
  }
@@ -116,6 +131,67 @@ export declare class BiabDevDashboardClient {
116
131
  constructor(client: BiabDevClient);
117
132
  createSession(): Promise<DashboardSessionResponse>;
118
133
  }
134
+ export declare class BiabDevStorefrontClient {
135
+ private readonly client;
136
+ constructor(client: BiabDevClient);
137
+ createSession(input?: StorefrontSessionInput): Promise<StorefrontSessionResponse>;
138
+ }
139
+ export declare class BiabDevCartClient {
140
+ private readonly client;
141
+ constructor(client: BiabDevClient);
142
+ createSession(): Promise<CartSessionResponse>;
143
+ }
144
+ export declare class BiabDevCheckoutClient {
145
+ private readonly client;
146
+ constructor(client: BiabDevClient);
147
+ createSession(input: CheckoutSessionInput): Promise<CheckoutSessionResponse>;
148
+ }
149
+ export declare class BiabDevBlogClient {
150
+ private readonly client;
151
+ constructor(client: BiabDevClient);
152
+ createSession(input?: BlogSessionInput): Promise<BlogSessionResponse>;
153
+ }
154
+ export declare class BiabDevChatbotClient {
155
+ private readonly client;
156
+ constructor(client: BiabDevClient);
157
+ /** Returns the iframe URL for `<Chatbot/>`. */
158
+ createSession(): Promise<ChatbotSessionResponse>;
159
+ /** Reads the org's persisted chatbot config (system prompt, KB, model). */
160
+ getConfig(): Promise<ChatbotConfig>;
161
+ /**
162
+ * Persists the org's chatbot config. Requires `chatbot:write` scope on the
163
+ * API key — typically only used by admin tools, not embedded widgets.
164
+ */
165
+ updateConfig(input: ChatbotConfigUpdateInput): Promise<ChatbotConfig>;
166
+ /**
167
+ * Headless chat — host owns the UI. Each request is fully org-scoped: the
168
+ * server runs the LLM with the org's saved system prompt + KB + model.
169
+ */
170
+ chat(input: ChatbotChatInput): Promise<ChatbotChatResponse>;
171
+ }
172
+ /**
173
+ * Reads the active customer-portal context (organization + user) and exposes
174
+ * profile mutations + a list of *only this user's* other customer
175
+ * relationships.
176
+ *
177
+ * @remarks
178
+ * **Privacy:** When `organizationId` is set, every request is pinned to that
179
+ * org via the `X-BIAB-Customer-Portal-Org` header. The server-side
180
+ * `customerPortalProcedure` will reject any access to a different org, so a
181
+ * customer browsing a Dominoes-branded site can never accidentally see Pizza
182
+ * Hut data even if their account is linked to both. This is the recommended
183
+ * mode for embedding the SDK on a tenant's site or app.
184
+ */
185
+ export declare class BiabDevCustomerPortalClient {
186
+ private readonly client;
187
+ private readonly organizationId;
188
+ constructor(client: BiabDevClient, organizationId: string | null);
189
+ private headers;
190
+ context(): Promise<CustomerPortalContextResponse>;
191
+ getProfile(): Promise<CustomerPortalProfile>;
192
+ updateProfile(input: CustomerPortalUpdateProfileInput): Promise<CustomerPortalUpdateProfileResponse>;
193
+ myOtherCustomerOrgs(): Promise<CustomerPortalOtherOrgsResponse>;
194
+ }
119
195
  /**
120
196
  * Creates a {@link BiabDevClient} for the given host `baseUrl` and package API key.
121
197
  *
@@ -124,5 +200,20 @@ export declare class BiabDevDashboardClient {
124
200
  * for production use yet. Prefer non-production environments until a stable major is published.
125
201
  */
126
202
  export declare function createBiabDevClient(options: BiabDevClientOptions): BiabDevClient;
203
+ /**
204
+ * Per-tenant auth: WorkOS hosted sign-in/sign-up scoped to the org bound to
205
+ * the API key. Used by the SDK's `createAuthHandler` (server) and
206
+ * `<SignIn />` / `<SignUp />` / `<SignOut />` components (client).
207
+ */
208
+ export declare class BiabDevAuthClient {
209
+ private readonly client;
210
+ constructor(client: BiabDevClient);
211
+ start(input: TenantAuthStartInput): Promise<TenantAuthStartResponse>;
212
+ exchange(input: TenantAuthExchangeInput): Promise<TenantAuthExchangeResponse>;
213
+ me(input: {
214
+ sessionToken: string;
215
+ }): Promise<TenantAuthMeResponse>;
216
+ signOut(): Promise<TenantAuthSignOutResponse>;
217
+ }
127
218
  export {};
128
219
  //# sourceMappingURL=client.d.ts.map
@@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AM,CAAA;KAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC;IASlE,OAAO,IAAI,OAAO,CAAC,yBAAyB,CAAC;CAOnD"}
package/dist/client.js CHANGED
@@ -1,4 +1,4 @@
1
- import { authIntrospectResponseSchema, createCollectionInputSchema, createCollectionResponseSchema, createEmailTemplateInputSchema, createEmailTemplateResponseSchema, createEmailTemplateVersionInputSchema, createEmailTemplateVersionResponseSchema, dashboardSessionResponseSchema, executeActionInputSchema, executeActionResponseSchema, followerEditInputSchema, followerEditResponseSchema, followerJoinInputSchema, followerJoinResponseSchema, followerLeaveInputSchema, followerLeaveResponseSchema, followerMeInputSchema, followerMeResponseSchema, getCollectionResponseSchema, getEmailTemplateResponseSchema, getSiteMarketingPageResponseSchema, listCollectionsResponseSchema, listEmailTemplatesInputSchema, listEmailTemplatesResponseSchema, listRowsInputSchema, listRowsResponseSchema, queryRowsInputSchema, queryRowsResponseSchema, siteAssetInputSchema, uploadSiteAssetResponseSchema, upsertRowInputSchema, upsertRowResponseSchema, } from "./contracts";
1
+ import { authIntrospectResponseSchema, tenantAuthExchangeInputSchema, tenantAuthExchangeResponseSchema, tenantAuthMeResponseSchema, tenantAuthSignOutResponseSchema, tenantAuthStartInputSchema, tenantAuthStartResponseSchema, blogSessionInputSchema, blogSessionResponseSchema, cartSessionResponseSchema, chatbotChatInputSchema, chatbotChatResponseSchema, chatbotConfigSchema, chatbotConfigUpdateInputSchema, chatbotSessionResponseSchema, checkoutSessionInputSchema, checkoutSessionResponseSchema, createCollectionInputSchema, createCollectionResponseSchema, createEmailTemplateInputSchema, createEmailTemplateResponseSchema, createEmailTemplateVersionInputSchema, createEmailTemplateVersionResponseSchema, customerPortalContextResponseSchema, customerPortalOtherOrgsResponseSchema, customerPortalProfileSchema, customerPortalUpdateProfileInputSchema, customerPortalUpdateProfileResponseSchema, dashboardSessionResponseSchema, executeActionInputSchema, executeActionResponseSchema, followerEditInputSchema, followerEditResponseSchema, followerJoinInputSchema, followerJoinResponseSchema, followerLeaveInputSchema, followerLeaveResponseSchema, followerMeInputSchema, followerMeResponseSchema, getCollectionResponseSchema, getEmailTemplateResponseSchema, getSiteMarketingPageResponseSchema, listCollectionsResponseSchema, listEmailTemplatesInputSchema, listEmailTemplatesResponseSchema, listRowsInputSchema, listRowsResponseSchema, queryRowsInputSchema, queryRowsResponseSchema, siteAssetInputSchema, storefrontSessionInputSchema, storefrontSessionResponseSchema, uploadSiteAssetResponseSchema, upsertRowInputSchema, upsertRowResponseSchema, } from "./contracts";
2
2
  import { BiabApiError } from "./errors";
3
3
  function buildUrl(baseUrl, path, query) {
4
4
  /**
@@ -67,6 +67,34 @@ export class BiabDevClient {
67
67
  get dashboard() {
68
68
  return new BiabDevDashboardClient(this);
69
69
  }
70
+ get storefront() {
71
+ return new BiabDevStorefrontClient(this);
72
+ }
73
+ get cart() {
74
+ return new BiabDevCartClient(this);
75
+ }
76
+ get checkout() {
77
+ return new BiabDevCheckoutClient(this);
78
+ }
79
+ get blog() {
80
+ return new BiabDevBlogClient(this);
81
+ }
82
+ get chatbot() {
83
+ return new BiabDevChatbotClient(this);
84
+ }
85
+ get auth() {
86
+ return new BiabDevAuthClient(this);
87
+ }
88
+ /**
89
+ * Customer-portal client. Pin to a specific WorkOS organization id so the
90
+ * caller never sees data from any other org (recommended). Omit
91
+ * `organizationId` to fall back to the user's currently-active session
92
+ * org — only use that on first-party hosts where the host already pins
93
+ * the org.
94
+ */
95
+ customerPortal(organizationId) {
96
+ return new BiabDevCustomerPortalClient(this, organizationId ?? null);
97
+ }
70
98
  async introspect() {
71
99
  return this.request({
72
100
  method: "POST",
@@ -85,6 +113,7 @@ export class BiabDevClient {
85
113
  ? {}
86
114
  : { "Content-Type": "application/json" }),
87
115
  ...(this.defaultHeaders ?? {}),
116
+ ...(options.headers ?? {}),
88
117
  },
89
118
  };
90
119
  if (options.body !== undefined) {
@@ -354,6 +383,169 @@ export class BiabDevDashboardClient {
354
383
  });
355
384
  }
356
385
  }
386
+ export class BiabDevStorefrontClient {
387
+ client;
388
+ constructor(client) {
389
+ this.client = client;
390
+ }
391
+ async createSession(input) {
392
+ const body = storefrontSessionInputSchema.parse(input ?? undefined);
393
+ return this.client.request({
394
+ method: "POST",
395
+ path: "storefront/session",
396
+ body: body ?? {},
397
+ responseSchema: storefrontSessionResponseSchema,
398
+ });
399
+ }
400
+ }
401
+ export class BiabDevCartClient {
402
+ client;
403
+ constructor(client) {
404
+ this.client = client;
405
+ }
406
+ async createSession() {
407
+ return this.client.request({
408
+ method: "POST",
409
+ path: "cart/session",
410
+ responseSchema: cartSessionResponseSchema,
411
+ });
412
+ }
413
+ }
414
+ export class BiabDevCheckoutClient {
415
+ client;
416
+ constructor(client) {
417
+ this.client = client;
418
+ }
419
+ async createSession(input) {
420
+ const body = checkoutSessionInputSchema.parse(input);
421
+ return this.client.request({
422
+ method: "POST",
423
+ path: "checkout/session",
424
+ body,
425
+ responseSchema: checkoutSessionResponseSchema,
426
+ });
427
+ }
428
+ }
429
+ export class BiabDevBlogClient {
430
+ client;
431
+ constructor(client) {
432
+ this.client = client;
433
+ }
434
+ async createSession(input) {
435
+ const body = blogSessionInputSchema.parse(input ?? undefined);
436
+ return this.client.request({
437
+ method: "POST",
438
+ path: "blog/session",
439
+ body: body ?? {},
440
+ responseSchema: blogSessionResponseSchema,
441
+ });
442
+ }
443
+ }
444
+ export class BiabDevChatbotClient {
445
+ client;
446
+ constructor(client) {
447
+ this.client = client;
448
+ }
449
+ /** Returns the iframe URL for `<Chatbot/>`. */
450
+ async createSession() {
451
+ return this.client.request({
452
+ method: "POST",
453
+ path: "chatbot/session",
454
+ responseSchema: chatbotSessionResponseSchema,
455
+ });
456
+ }
457
+ /** Reads the org's persisted chatbot config (system prompt, KB, model). */
458
+ async getConfig() {
459
+ return this.client.request({
460
+ method: "GET",
461
+ path: "chatbot/config",
462
+ responseSchema: chatbotConfigSchema,
463
+ });
464
+ }
465
+ /**
466
+ * Persists the org's chatbot config. Requires `chatbot:write` scope on the
467
+ * API key — typically only used by admin tools, not embedded widgets.
468
+ */
469
+ async updateConfig(input) {
470
+ const body = chatbotConfigUpdateInputSchema.parse(input);
471
+ return this.client.request({
472
+ method: "PATCH",
473
+ path: "chatbot/config",
474
+ body,
475
+ responseSchema: chatbotConfigSchema,
476
+ });
477
+ }
478
+ /**
479
+ * Headless chat — host owns the UI. Each request is fully org-scoped: the
480
+ * server runs the LLM with the org's saved system prompt + KB + model.
481
+ */
482
+ async chat(input) {
483
+ const body = chatbotChatInputSchema.parse(input);
484
+ return this.client.request({
485
+ method: "POST",
486
+ path: "chatbot/chat",
487
+ body,
488
+ responseSchema: chatbotChatResponseSchema,
489
+ });
490
+ }
491
+ }
492
+ /**
493
+ * Reads the active customer-portal context (organization + user) and exposes
494
+ * profile mutations + a list of *only this user's* other customer
495
+ * relationships.
496
+ *
497
+ * @remarks
498
+ * **Privacy:** When `organizationId` is set, every request is pinned to that
499
+ * org via the `X-BIAB-Customer-Portal-Org` header. The server-side
500
+ * `customerPortalProcedure` will reject any access to a different org, so a
501
+ * customer browsing a Dominoes-branded site can never accidentally see Pizza
502
+ * Hut data even if their account is linked to both. This is the recommended
503
+ * mode for embedding the SDK on a tenant's site or app.
504
+ */
505
+ export class BiabDevCustomerPortalClient {
506
+ client;
507
+ organizationId;
508
+ constructor(client, organizationId) {
509
+ this.client = client;
510
+ this.organizationId = organizationId;
511
+ }
512
+ headers() {
513
+ return this.organizationId
514
+ ? { "X-BIAB-Customer-Portal-Org": this.organizationId }
515
+ : {};
516
+ }
517
+ async context() {
518
+ return this.client.request({
519
+ path: "customer-portal/context",
520
+ responseSchema: customerPortalContextResponseSchema,
521
+ headers: this.headers(),
522
+ });
523
+ }
524
+ async getProfile() {
525
+ return this.client.request({
526
+ path: "customer-portal/profile",
527
+ responseSchema: customerPortalProfileSchema,
528
+ headers: this.headers(),
529
+ });
530
+ }
531
+ async updateProfile(input) {
532
+ const body = customerPortalUpdateProfileInputSchema.parse(input);
533
+ return this.client.request({
534
+ method: "POST",
535
+ path: "customer-portal/profile",
536
+ body,
537
+ responseSchema: customerPortalUpdateProfileResponseSchema,
538
+ headers: this.headers(),
539
+ });
540
+ }
541
+ async myOtherCustomerOrgs() {
542
+ return this.client.request({
543
+ path: "customer-portal/other-orgs",
544
+ responseSchema: customerPortalOtherOrgsResponseSchema,
545
+ headers: this.headers(),
546
+ });
547
+ }
548
+ }
357
549
  /**
358
550
  * Creates a {@link BiabDevClient} for the given host `baseUrl` and package API key.
359
551
  *
@@ -364,4 +556,48 @@ export class BiabDevDashboardClient {
364
556
  export function createBiabDevClient(options) {
365
557
  return new BiabDevClient(options);
366
558
  }
559
+ /**
560
+ * Per-tenant auth: WorkOS hosted sign-in/sign-up scoped to the org bound to
561
+ * the API key. Used by the SDK's `createAuthHandler` (server) and
562
+ * `<SignIn />` / `<SignUp />` / `<SignOut />` components (client).
563
+ */
564
+ export class BiabDevAuthClient {
565
+ client;
566
+ constructor(client) {
567
+ this.client = client;
568
+ }
569
+ async start(input) {
570
+ const body = tenantAuthStartInputSchema.parse(input);
571
+ return this.client.request({
572
+ method: "POST",
573
+ path: "auth/start",
574
+ body,
575
+ responseSchema: tenantAuthStartResponseSchema,
576
+ });
577
+ }
578
+ async exchange(input) {
579
+ const body = tenantAuthExchangeInputSchema.parse(input);
580
+ return this.client.request({
581
+ method: "POST",
582
+ path: "auth/exchange",
583
+ body,
584
+ responseSchema: tenantAuthExchangeResponseSchema,
585
+ });
586
+ }
587
+ async me(input) {
588
+ return this.client.request({
589
+ method: "GET",
590
+ path: "auth/me",
591
+ headers: { "x-biab-session": input.sessionToken },
592
+ responseSchema: tenantAuthMeResponseSchema,
593
+ });
594
+ }
595
+ async signOut() {
596
+ return this.client.request({
597
+ method: "POST",
598
+ path: "auth/sign-out",
599
+ responseSchema: tenantAuthSignOutResponseSchema,
600
+ });
601
+ }
602
+ }
367
603
  //# sourceMappingURL=client.js.map