@cmssy/core 5.0.0

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,496 @@
1
+ import { CmssyAuthConfig, CmssyClientConfig, CmssyLayoutGroup, CmssyPageData, CmssyPageMeta, CmssyPageSummary, CmssySiteConfig, RawBlock, CmssyFormDefinition, CmssySiteLocales, BuildBlockContextExtra, CmssyBlockContext, CmssyLocaleContext, FieldControl, FieldDefinition, BlockRect, BlockSchema, BlockMeta, CmssySessionPayload, SessionCookieOptions, CmssySessionUser, CmssyAddress, CmssyCart, CmssyOrder, CmssyProduct, MyOrdersResult, FetchProductOptions, FetchProductsOptions, CmssyProductPage, FetchOrderByTokenOptions, VerifyCmssyWebhookOptions, CmssyWebhookEvent } from '@cmssy/types';
2
+ export { BlockMeta, BlockRect, BlockSchema, BuildBlockContextExtra, CmssyAddress, CmssyAuthConfig, CmssyBlockAuthContext, CmssyBlockContext, CmssyBlockMember, CmssyBlockWorkspace, CmssyBranding, CmssyCart, CmssyCartDiscount, CmssyCartItem, CmssyCartItemSnapshot, CmssyClientConfig, CmssyFormDefinition, CmssyFormField, CmssyFormSettings, CmssyFormSubmitResponse, CmssyLayoutGroup, CmssyLayoutSettings, CmssyLocaleContext, CmssyLocalizedValue, CmssyModelDefinition, CmssyModelRecord, CmssyOrder, CmssyOrderDiscount, CmssyOrderItem, CmssyOrderTaxSummaryLine, CmssyPageData, CmssyPageMeta, CmssyPageSummary, CmssyPriceTier, CmssyProduct, CmssyProductPage, CmssyProductVariant, CmssyRecordList, CmssySessionPayload, CmssySessionUser, CmssyShippingMethod, CmssySiteConfig, CmssySiteLocales, CmssyStockState, CmssyTaxSummaryLine, CmssyWebhookEvent, CmssyWebhookOrder, FetchOrderByTokenOptions, FetchProductOptions, FetchProductsOptions, FieldCondition, FieldConditionGroup, FieldConditionLogic, FieldControl, FieldDefinition, FieldType, MyOrdersResult, RawBlock, RawLayoutBlock, SessionCookieOptions, SubmitFormInput, VerifyCmssyWebhookOptions, evaluateFieldConditionGroup } from '@cmssy/types';
3
+
4
+ declare const DEFAULT_CMSSY_EDITOR_ORIGINS: string[];
5
+ declare function isDevelopment(): boolean;
6
+ declare function resolveEditorOrigin(editorOrigin: string | string[] | undefined): string | string[];
7
+ interface CmssyConfig {
8
+ /**
9
+ * Full GraphQL delivery endpoint. Defaults to the cmssy cloud endpoint
10
+ * (`https://api.cmssy.io/graphql`); set it only for self-hosted / staging.
11
+ */
12
+ apiUrl?: string;
13
+ /** Organization slug - part of the org-scoped delivery path. */
14
+ org: string;
15
+ workspaceSlug: string;
16
+ draftSecret: string;
17
+ /**
18
+ * A cmssy API token (`cs_…`) that opts this app into the editor-controlled dev
19
+ * preview. In development only, the SDK sends it on every page fetch so the
20
+ * backend can resolve the token's user and honour that user's dev-preview flag
21
+ * (toggled from the editor's dev-mode switch): flag on + a saved dev draft ⇒
22
+ * the draft overlay renders, otherwise published content. Server-only (never
23
+ * reaches the client); ignored outside development. See the Quickstart
24
+ * "Dev preview" section.
25
+ */
26
+ devToken?: string;
27
+ /**
28
+ * Origin allowed to frame your app in the editor. Defaults to
29
+ * {@link DEFAULT_CMSSY_EDITOR_ORIGINS}; set it only for self-hosted admins.
30
+ */
31
+ editorOrigin?: string | string[];
32
+ /**
33
+ * Canonical absolute site URL (e.g. https://cmssy.com), used by
34
+ * createCmssyRobots / createCmssySitemap. When omitted the helpers derive the
35
+ * origin from the request `host` header at render time (multi-domain safe).
36
+ */
37
+ siteUrl?: string;
38
+ auth?: CmssyAuthConfig;
39
+ defaultLocale?: string;
40
+ /** All languages enabled on the workspace; exposed to blocks via context.locale.enabled. */
41
+ enabledLocales?: string[];
42
+ resolveLocale?: () => string | Promise<string>;
43
+ }
44
+ /**
45
+ * Env-shaped input for {@link defineCmssyConfig}: the required string fields are
46
+ * widened to `string | undefined` so a config can pass `process.env.*` straight
47
+ * through without a `?? ""` fallback (which would mask a missing value as an
48
+ * empty string) or a cast.
49
+ */
50
+ type CmssyEnvConfig = Omit<CmssyConfig, "org" | "workspaceSlug" | "draftSecret"> & {
51
+ org?: string;
52
+ workspaceSlug?: string;
53
+ draftSecret?: string;
54
+ };
55
+ /**
56
+ * Validates an env-sourced config and returns a strictly-typed
57
+ * {@link CmssyConfig}. Pass raw `process.env.*` values; this throws a clear,
58
+ * actionable error listing any missing required variables (rendered by the
59
+ * Next.js error overlay / boundary), so the app fails fast instead of running
60
+ * with silently-empty config.
61
+ */
62
+ declare function defineCmssyConfig(config: CmssyEnvConfig): CmssyConfig;
63
+ declare function assertAuthConfig(config: CmssyConfig): CmssyAuthConfig;
64
+
65
+ /** HTTP-level failure from the cmssy API, with a machine-readable status. */
66
+ declare class CmssyRequestError extends Error {
67
+ readonly status: number;
68
+ constructor(message: string, status: number);
69
+ }
70
+ interface RetryPolicy {
71
+ /** Additional attempts after the first request (default 3). */
72
+ maxRetries?: number;
73
+ /** Exponential backoff base in ms: base * 2^attempt (default 300). */
74
+ baseDelayMs?: number;
75
+ /** Upper bound for any single wait, including Retry-After (default 3000). */
76
+ maxDelayMs?: number;
77
+ /** HTTP statuses that trigger a retry (default [429, 503]). */
78
+ retryStatuses?: number[];
79
+ }
80
+
81
+ /**
82
+ * The cmssy cloud GraphQL delivery endpoint. It is the same for every workspace,
83
+ * so consumers never need to set it - `apiUrl` defaults to this. Self-hosted /
84
+ * staging deployments override it via config.
85
+ */
86
+ declare const DEFAULT_CMSSY_API_URL = "https://api.cmssy.io/graphql";
87
+ declare function resolveApiUrl(apiUrl: string | undefined): string;
88
+ /**
89
+ * Public delivery endpoint for a workspace: the org-scoped path
90
+ * `{base}/public/{orgSlug}/{workspaceSlug}/graphql`. `apiUrl` is the GraphQL
91
+ * base (its trailing `/graphql` is stripped); the org path is what tells the
92
+ * backend which workspace to serve, so slugs only need to be unique per org.
93
+ */
94
+ declare function resolvePublicUrl(config: CmssyClientConfig): string;
95
+ interface FetchLikeResponse {
96
+ ok: boolean;
97
+ status: number;
98
+ json: () => Promise<unknown>;
99
+ headers?: {
100
+ get: (name: string) => string | null;
101
+ };
102
+ }
103
+ type FetchLike = (url: string, init: {
104
+ method: string;
105
+ headers: Record<string, string>;
106
+ body: string;
107
+ signal?: AbortSignal;
108
+ }) => Promise<FetchLikeResponse>;
109
+ interface FetchPageOptions {
110
+ previewSecret?: string;
111
+ devPreview?: boolean;
112
+ devToken?: string;
113
+ workspaceId?: string;
114
+ fetch?: FetchLike;
115
+ signal?: AbortSignal;
116
+ retry?: RetryPolicy | false;
117
+ }
118
+ declare function normalizeSlug(path: string | string[] | undefined): string;
119
+ declare function fetchPage(config: CmssyClientConfig, path: string | string[] | undefined, options?: FetchPageOptions): Promise<CmssyPageData | null>;
120
+ declare function fetchPageById(config: CmssyClientConfig, pageId: string, options?: Pick<FetchPageOptions, "fetch" | "signal" | "retry">): Promise<CmssyPageData | null>;
121
+ declare function fetchPages(config: CmssyClientConfig, options?: Pick<FetchPageOptions, "fetch" | "signal" | "retry">): Promise<CmssyPageSummary[]>;
122
+ declare function fetchPageMeta(config: CmssyClientConfig, path: string | string[] | undefined, options?: Pick<FetchPageOptions, "fetch" | "signal" | "retry">): Promise<CmssyPageMeta | null>;
123
+ declare function fetchLayouts(config: CmssyClientConfig, path: string | string[] | undefined, options?: FetchPageOptions): Promise<CmssyLayoutGroup[]>;
124
+
125
+ declare function getBlockContentForLanguage(content: unknown, locale: string, defaultLocale?: string, availableLocales?: string[]): Record<string, unknown>;
126
+ /**
127
+ * Coerce a block bucket (`style` / `advanced`) to a plain object. These buckets
128
+ * are flat (not locale-keyed) and free-form; a missing/invalid bucket becomes
129
+ * an empty object so components can destructure it safely.
130
+ */
131
+ declare function asBucket(value: unknown): Record<string, unknown>;
132
+
133
+ interface GraphqlRequestOptions {
134
+ fetch?: FetchLike;
135
+ signal?: AbortSignal;
136
+ headers?: Record<string, string>;
137
+ /**
138
+ * Route through the org-scoped public delivery path instead of the base
139
+ * `/graphql` endpoint. Set for unauthenticated public queries so the backend
140
+ * resolves the workspace from the URL rather than a global slug lookup.
141
+ */
142
+ public?: boolean;
143
+ /**
144
+ * Retry transient HTTP failures (429/503, honoring Retry-After). Off by
145
+ * default: this function also carries mutations (auth, cart, checkout),
146
+ * which must never be blind-retried. Read-only callers opt in with `{}`.
147
+ */
148
+ retry?: RetryPolicy | false;
149
+ }
150
+ declare function graphqlRequest<T>(config: CmssyClientConfig, query: string, variables: Record<string, unknown>, options?: GraphqlRequestOptions, label?: string): Promise<T>;
151
+
152
+ interface QueryScopedOptions extends GraphqlRequestOptions {
153
+ workspaceId?: string;
154
+ }
155
+ interface CmssyClient {
156
+ readonly config: CmssyClientConfig;
157
+ query<T = unknown>(document: string, variables?: Record<string, unknown>, options?: GraphqlRequestOptions): Promise<T>;
158
+ queryScoped<T = unknown>(document: string, variables?: Record<string, unknown>, options?: QueryScopedOptions): Promise<T>;
159
+ resolveWorkspaceId(options?: GraphqlRequestOptions): Promise<string>;
160
+ }
161
+ declare function createCmssyClient(input: CmssyClientConfig): CmssyClient;
162
+
163
+ declare const SITE_CONFIG_QUERY = "query PublicSiteConfig($workspaceSlug: String!) {\n public {\n siteConfig(workspaceSlug: $workspaceSlug) {\n id\n workspaceId\n siteName\n defaultLanguage\n enabledLanguages\n enabledFeatures\n notFoundPageId\n previewUrl\n branding {\n brandName\n logoUrl\n faviconUrl\n ogImageUrl\n }\n }\n }\n}";
164
+ declare const MODEL_DEFINITIONS_QUERY = "query PublicModelDefinitions($workspaceId: String!) {\n public {\n model {\n definitions(workspaceId: $workspaceId) {\n id name slug description icon color displayField recordCount\n }\n }\n }\n}";
165
+ declare const MODEL_RECORDS_QUERY = "query PublicModelRecords($workspaceId: String!, $modelSlug: String!, $filter: JSON, $sort: String, $locale: String, $limit: Int, $offset: Int, $populate: [String!]) {\n public {\n model {\n records(workspaceId: $workspaceId, modelSlug: $modelSlug, filter: $filter, sort: $sort, locale: $locale, limit: $limit, offset: $offset, populate: $populate) {\n items { id modelId data status createdAt updatedAt }\n total\n hasMore\n }\n }\n }\n}";
166
+ declare const FORM_QUERY = "query PublicForm($formId: ID!) {\n public {\n form {\n get(formId: $formId) {\n id\n name\n slug\n description\n fields {\n id name fieldType label placeholder helpText\n defaultValue width order showWhen requiredWhen\n options { value label disabled }\n validation { required minLength maxLength minValue maxValue pattern customMessage }\n }\n settings {\n actionType submitButtonLabel successMessage errorMessage\n redirectUrl requireLogin enableCaptcha\n }\n }\n }\n }\n}";
167
+ declare const SUBMIT_FORM_MUTATION = "mutation SubmitForm($formId: ID!, $input: SubmitFormInput!) {\n public {\n form {\n submit(formId: $formId, input: $input) {\n success message submissionId redirectUrl accessToken customer\n }\n }\n }\n}";
168
+
169
+ declare function fetchSiteConfig(config: CmssyClientConfig, options?: GraphqlRequestOptions): Promise<CmssySiteConfig | null>;
170
+ declare function resolveWorkspaceId(config: CmssyClientConfig, options?: GraphqlRequestOptions): Promise<string>;
171
+ /**
172
+ * Every authenticated operation needs the workspace id, and it never changes for
173
+ * a given (endpoint, workspace) pair - so it is resolved once and shared. A
174
+ * failed lookup is evicted, otherwise one bad request would be cached forever.
175
+ */
176
+ declare function cachedWorkspaceId(config: CmssyClientConfig): Promise<string>;
177
+ declare function clearWorkspaceIdCache(): void;
178
+
179
+ declare function collectFormIds(blocks: RawBlock[], locale: string, defaultLocale: string): string[];
180
+ declare function resolveForms(config: CmssyClientConfig, blocks: RawBlock[], locale: string, defaultLocale: string, options?: QueryScopedOptions): Promise<Record<string, CmssyFormDefinition>>;
181
+
182
+ declare function resolveSiteLocales(config: CmssyClientConfig, options?: GraphqlRequestOptions): Promise<CmssySiteLocales>;
183
+ declare function splitLocaleFromPath(path: string[] | undefined, siteLocales: CmssySiteLocales): {
184
+ locale: string;
185
+ path: string[] | undefined;
186
+ };
187
+
188
+ declare function buildBlockContext(locale: string, defaultLocale: string, enabledLocales?: string[], isPreview?: boolean, forms?: Record<string, CmssyFormDefinition>, extra?: BuildBlockContextExtra): CmssyBlockContext;
189
+
190
+ /**
191
+ * Rewrites an internal href to carry the active locale as a path prefix.
192
+ * External hrefs, fragments and relative paths are returned untouched. Already
193
+ * prefixed hrefs are normalized so the prefix never doubles.
194
+ */
195
+ declare function localizeHref(href: string, locale: CmssyLocaleContext): string;
196
+ /**
197
+ * Builds the href that switches the current `pathname` to `target` locale,
198
+ * preserving the rest of the path. Used by a language switcher.
199
+ */
200
+ declare function buildLocaleSwitchHref(target: string, pathname: string, locale: CmssyLocaleContext): string;
201
+ /**
202
+ * Rewrites every `<a href>` inside an HTML string with {@link localizeHref}.
203
+ * For rich-text content stored in CMS blocks where links are raw markup.
204
+ */
205
+ declare function localizeHtmlLinks(html: string, locale: CmssyLocaleContext): string;
206
+
207
+ declare const CMSSY_LOCALE_HEADER = "x-cmssy-locale";
208
+ declare function localeForPathname(config: CmssyClientConfig, pathname: string): Promise<string>;
209
+ declare function splitCmssyLocale(config: CmssyClientConfig, path: string[] | undefined): Promise<{
210
+ locale: string;
211
+ path: string[] | undefined;
212
+ }>;
213
+ /**
214
+ * Resolve the locale a path asks for. The prefix IS the language, so a routed
215
+ * path is all it takes - no request, no headers, static-safe.
216
+ */
217
+ declare function localeForPath(config: CmssyClientConfig, path: string | string[]): Promise<string>;
218
+
219
+ declare const fields: {
220
+ text: (opts?: FieldControl) => FieldDefinition;
221
+ textarea: (opts?: FieldControl) => FieldDefinition;
222
+ richText: (opts?: FieldControl) => FieldDefinition;
223
+ markdown: (opts?: FieldControl) => FieldDefinition;
224
+ number: (opts?: FieldControl) => FieldDefinition;
225
+ date: (opts?: FieldControl) => FieldDefinition;
226
+ datetime: (opts?: FieldControl) => FieldDefinition;
227
+ boolean: (opts?: FieldControl) => FieldDefinition;
228
+ color: (opts?: FieldControl) => FieldDefinition;
229
+ media: (opts?: FieldControl) => FieldDefinition;
230
+ link: (opts?: FieldControl) => FieldDefinition;
231
+ url: (opts?: FieldControl) => FieldDefinition;
232
+ email: (opts?: FieldControl) => FieldDefinition;
233
+ select: (opts?: FieldControl) => FieldDefinition;
234
+ multiselect: (opts?: FieldControl) => FieldDefinition;
235
+ radio: (opts?: FieldControl) => FieldDefinition;
236
+ repeater: (opts?: FieldControl) => FieldDefinition;
237
+ table: (opts?: FieldControl) => FieldDefinition;
238
+ json: (opts?: FieldControl) => FieldDefinition;
239
+ form: (opts?: FieldControl) => FieldDefinition;
240
+ pageSelector: (opts?: FieldControl) => FieldDefinition;
241
+ };
242
+
243
+ declare const PROTOCOL_VERSION = 2;
244
+
245
+ interface ReadyMessage {
246
+ type: "cmssy:ready";
247
+ protocolVersion: number;
248
+ blocks: Array<{
249
+ id: string;
250
+ type: string;
251
+ bounds: BlockRect;
252
+ layoutPosition?: string;
253
+ }>;
254
+ schemas: Record<string, BlockSchema>;
255
+ blockMeta?: Record<string, BlockMeta>;
256
+ }
257
+ interface BoundsMessage {
258
+ type: "cmssy:bounds";
259
+ blockId: string;
260
+ rect: BlockRect;
261
+ }
262
+ interface ClickMessage {
263
+ type: "cmssy:click";
264
+ blockId: string;
265
+ rect: BlockRect;
266
+ layoutPosition?: string;
267
+ }
268
+ interface MoveMessage {
269
+ type: "cmssy:move";
270
+ protocolVersion: number;
271
+ blockId: string;
272
+ index: number;
273
+ }
274
+ interface DragIndexMessage {
275
+ type: "cmssy:drag-index";
276
+ protocolVersion: number;
277
+ index: number;
278
+ }
279
+ type AppToEditorMessage = ReadyMessage | BoundsMessage | ClickMessage | MoveMessage | DragIndexMessage;
280
+ interface SelectMessage {
281
+ type: "cmssy:select";
282
+ protocolVersion: number;
283
+ blockId: string;
284
+ }
285
+ interface PatchMessage {
286
+ type: "cmssy:patch";
287
+ protocolVersion: number;
288
+ blockId: string;
289
+ content: Record<string, unknown>;
290
+ style?: Record<string, unknown>;
291
+ advanced?: Record<string, unknown>;
292
+ layoutPosition?: string;
293
+ }
294
+ interface ParentReadyMessage {
295
+ type: "cmssy:parent-ready";
296
+ protocolVersion: number;
297
+ }
298
+ interface InsertMessage {
299
+ type: "cmssy:insert";
300
+ protocolVersion: number;
301
+ blockId: string;
302
+ blockType: string;
303
+ content: Record<string, unknown>;
304
+ style?: Record<string, unknown>;
305
+ advanced?: Record<string, unknown>;
306
+ index: number;
307
+ }
308
+ interface ReorderMessage {
309
+ type: "cmssy:reorder";
310
+ protocolVersion: number;
311
+ blockIds: string[];
312
+ }
313
+ interface RemoveMessage {
314
+ type: "cmssy:remove";
315
+ protocolVersion: number;
316
+ blockId: string;
317
+ }
318
+ interface DragOverMessage {
319
+ type: "cmssy:drag-over";
320
+ protocolVersion: number;
321
+ y: number;
322
+ }
323
+ interface DragEndMessage {
324
+ type: "cmssy:drag-end";
325
+ protocolVersion: number;
326
+ }
327
+ type EditorToAppMessage = SelectMessage | PatchMessage | ParentReadyMessage | InsertMessage | ReorderMessage | RemoveMessage | DragOverMessage | DragEndMessage;
328
+ declare function isProtocolCompatible(version: number): boolean;
329
+
330
+ interface PostTarget {
331
+ postMessage: (message: unknown, targetOrigin: string) => void;
332
+ }
333
+ declare function normalizeOrigin(origin: string): string;
334
+ declare function postToEditor(target: PostTarget, editorOrigin: string, message: AppToEditorMessage): void;
335
+ declare function resolveInitialTarget(editorOrigin: string | string[]): string;
336
+ declare function parseEditorMessage(data: unknown, origin: string, expectedOrigin: string | string[]): EditorToAppMessage | null;
337
+
338
+ declare const CMSSY_EDIT_HEADER = "x-cmssy-edit";
339
+ declare const CMSSY_EDIT_QUERY_PARAM = "cmssyEdit";
340
+ declare const CMSSY_SECRET_QUERY_PARAM = "cmssySecret";
341
+ interface EditSearchParams {
342
+ getAll: (name: string) => string[];
343
+ get: (name: string) => string | null;
344
+ }
345
+ declare function isVerifiedEditUrl(url: {
346
+ searchParams: EditSearchParams;
347
+ }, config: {
348
+ draftSecret: string;
349
+ }): Promise<boolean>;
350
+
351
+ declare function cmssySecretsMatch(a: string, b: string): Promise<boolean>;
352
+
353
+ interface CmssyCspOptions {
354
+ /** Defaults to the cmssy cloud admin origin when unset. */
355
+ editorOrigin?: string | string[];
356
+ }
357
+ interface MutableHeaders {
358
+ headers: {
359
+ get: (name: string) => string | null;
360
+ set: (name: string, value: string) => void;
361
+ delete: (name: string) => void;
362
+ };
363
+ }
364
+ declare function toCspOrigin(origin: string): string;
365
+ declare function cmssyCspHeaders(options: CmssyCspOptions): Record<string, string>;
366
+ declare function applyCmssyCsp<T extends MutableHeaders>(response: T, options: CmssyCspOptions): T;
367
+
368
+ /**
369
+ * Resolve the default locale and the full locale list from the SDK config,
370
+ * falling back to the workspace site config (defaultLanguage / enabledLanguages)
371
+ * then "en". Shared by sitemap + metadata so their hreflang/canonical agree.
372
+ */
373
+ declare function resolveSeoLocales(config: {
374
+ defaultLocale?: string;
375
+ enabledLocales?: string[];
376
+ }, siteConfig: {
377
+ defaultLanguage?: string | null;
378
+ enabledLanguages?: string[];
379
+ } | null): {
380
+ defaultLocale: string;
381
+ locales: string[];
382
+ };
383
+ /**
384
+ * Maps a page slug to its path for a locale: the default locale gets no
385
+ * prefix, others get `/${locale}`. The homepage ("/") stays "/" (or "/${locale}").
386
+ */
387
+ declare function localizedPath(slug: string, locale: string, defaultLocale: string): string;
388
+
389
+ declare const CMSSY_SESSION_COOKIE = "cmssy_session";
390
+ declare const SESSION_MAX_AGE_SECONDS: number;
391
+ declare const MIN_SESSION_SECRET_LENGTH = 32;
392
+ declare function sealSession(payload: CmssySessionPayload, secret: string, audience?: string): Promise<string>;
393
+ declare function openSession(token: string, secret: string, audience?: string): Promise<CmssySessionPayload | null>;
394
+ declare function isAccessExpired(payload: CmssySessionPayload, now?: number): boolean;
395
+ declare function sessionCookieOptions(): SessionCookieOptions;
396
+
397
+ interface AuthMutationResult {
398
+ success: boolean;
399
+ message: string;
400
+ }
401
+ interface AuthTokenResult extends AuthMutationResult {
402
+ accessToken: string | null;
403
+ refreshToken: string | null;
404
+ accessTokenExpiresIn: number | null;
405
+ }
406
+ declare function decodeAccessClaims(accessToken: string): CmssySessionUser | null;
407
+ declare function toSessionPayload(result: AuthTokenResult): CmssySessionPayload | null;
408
+ declare function backendSignIn(config: CmssyConfig, modelSlug: string, identity: string, password: string): Promise<AuthTokenResult>;
409
+ declare function backendRegister(config: CmssyConfig, modelSlug: string, identity: string, password: string, fields: Record<string, unknown>): Promise<AuthMutationResult>;
410
+ declare function backendRefresh(config: CmssyConfig, refreshToken: string): Promise<AuthTokenResult>;
411
+ declare function backendSignOut(config: CmssyConfig, refreshToken: string): Promise<void>;
412
+ declare function backendSignOutEverywhere(config: CmssyConfig, accessToken: string): Promise<void>;
413
+ declare function backendForgotPassword(config: CmssyConfig, modelSlug: string, identity: string): Promise<AuthMutationResult>;
414
+ declare function backendResetPassword(config: CmssyConfig, token: string, newPassword: string): Promise<AuthMutationResult>;
415
+ declare function backendVerifyEmail(config: CmssyConfig, token: string): Promise<AuthMutationResult>;
416
+
417
+ interface CartRequestContext {
418
+ cartToken: string;
419
+ accessToken?: string;
420
+ }
421
+ declare function backendGetCart(config: CmssyConfig, ctx: CartRequestContext): Promise<CmssyCart | null>;
422
+ declare function backendAddToCart(config: CmssyConfig, ctx: CartRequestContext, input: {
423
+ recordId: string;
424
+ quantity: number;
425
+ variantSelections?: Record<string, string>;
426
+ notes?: string;
427
+ }): Promise<CmssyCart>;
428
+ declare function backendUpdateItem(config: CmssyConfig, ctx: CartRequestContext, input: {
429
+ itemId: string;
430
+ quantity: number;
431
+ }): Promise<CmssyCart>;
432
+ declare function backendRemoveItem(config: CmssyConfig, ctx: CartRequestContext, itemId: string): Promise<CmssyCart>;
433
+ declare function backendClearCart(config: CmssyConfig, ctx: CartRequestContext): Promise<CmssyCart>;
434
+ declare function backendApplyDiscount(config: CmssyConfig, ctx: CartRequestContext, code: string): Promise<CmssyCart>;
435
+ declare function backendRemoveDiscount(config: CmssyConfig, ctx: CartRequestContext): Promise<CmssyCart>;
436
+ declare function backendSetShippingMethod(config: CmssyConfig, ctx: CartRequestContext, shippingMethodId: string | null): Promise<CmssyCart>;
437
+ declare function backendMergeCart(config: CmssyConfig, ctx: CartRequestContext): Promise<CmssyCart>;
438
+ interface CheckoutInput {
439
+ customerEmail: string;
440
+ poNumber?: string | null;
441
+ customerNote?: string | null;
442
+ shippingAddress?: CmssyAddress | null;
443
+ }
444
+ declare function backendCheckout(config: CmssyConfig, ctx: CartRequestContext, input: CheckoutInput): Promise<CmssyOrder>;
445
+ declare function backendProduct(config: CmssyConfig, ctx: CartRequestContext, modelSlug: string, filter: Record<string, unknown>): Promise<CmssyProduct | null>;
446
+
447
+ declare function backendMyOrders(config: CmssyConfig, accessToken: string, options: {
448
+ skip?: number;
449
+ limit?: number;
450
+ }): Promise<MyOrdersResult>;
451
+ declare function backendMyOrder(config: CmssyConfig, accessToken: string, id: string): Promise<CmssyOrder | null>;
452
+ declare function backendOrderByToken(config: CmssyConfig, options: {
453
+ orderId: string;
454
+ accessToken: string;
455
+ }): Promise<CmssyOrder>;
456
+
457
+ declare const PRODUCTS_QUERY = "query Products($workspaceId: String!, $modelSlug: String!, $filter: JSON, $stockState: String, $locale: String, $limit: Int, $offset: Int, $sort: String) {\n public {\n model {\n records(workspaceId: $workspaceId, modelSlug: $modelSlug, filter: $filter, stockState: $stockState, locale: $locale, limit: $limit, offset: $offset, sort: $sort) {\n total\n hasMore\n items {\n id\n data\n priceTiers { minQty price }\n variants { id sku price inventory tiers { minQty price } selectedOptions { name value } }\n }\n }\n }\n }\n}";
458
+ /**
459
+ * A catalog read is plain data: it takes the locale it is given. Framework
460
+ * adapters are the ones that know how to find the locale of the current request
461
+ * (@cmssy/next reads it from the middleware header) and pass it in. Omitting it
462
+ * means "the workspace's default language".
463
+ */
464
+ declare function fetchProducts(config: CmssyConfig, options: FetchProductsOptions): Promise<CmssyProductPage>;
465
+ declare function fetchProduct(config: CmssyConfig, options: FetchProductOptions): Promise<CmssyProduct | null>;
466
+
467
+ declare function fetchOrderByToken(config: CmssyConfig, options: FetchOrderByTokenOptions): Promise<CmssyOrder>;
468
+
469
+ declare function fractionDigits(currency: string): number;
470
+ declare function fromMinorUnits(minor: number, currency: string): number;
471
+ declare function toMinorUnits(amount: number, currency: string): number;
472
+ declare function formatPrice(minor: number, currency: string | null | undefined): string;
473
+
474
+ /**
475
+ * Verify + parse an inbound cmssy webhook (CMS-693 / CMS-694).
476
+ *
477
+ * cmssy signs each delivery with HMAC-SHA256 over `${timestamp}.${body}`
478
+ * and sends the result in the `X-Cmssy-Signature: t=<ms>,v1=<hex>`
479
+ * header, plus a unique `X-Cmssy-Webhook-Id`. This helper recomputes the
480
+ * signature (timing-safe compare), rejects stale timestamps to bound
481
+ * replay, and returns the typed event.
482
+ *
483
+ * IMPORTANT: pass the RAW request body string (e.g. `await req.text()`),
484
+ * never a re-serialized object - the signed bytes must match exactly.
485
+ */
486
+ declare class CmssyWebhookError extends Error {
487
+ constructor(message: string);
488
+ }
489
+ /**
490
+ * Verify the signature + freshness and return the parsed event. Throws
491
+ * `CmssyWebhookError` on any failure (missing/malformed header, bad
492
+ * signature, stale timestamp, invalid JSON) - catch it and respond 400.
493
+ */
494
+ declare function verifyCmssyWebhook(options: VerifyCmssyWebhookOptions): CmssyWebhookEvent;
495
+
496
+ export { type AppToEditorMessage, type AuthMutationResult, type AuthTokenResult, type BoundsMessage, CMSSY_EDIT_HEADER, CMSSY_EDIT_QUERY_PARAM, CMSSY_LOCALE_HEADER, CMSSY_SECRET_QUERY_PARAM, CMSSY_SESSION_COOKIE, type CartRequestContext, type CheckoutInput, type ClickMessage, type CmssyClient, type CmssyConfig, type CmssyCspOptions, type CmssyEnvConfig, CmssyRequestError, CmssyWebhookError, DEFAULT_CMSSY_API_URL, DEFAULT_CMSSY_EDITOR_ORIGINS, type EditorToAppMessage, FORM_QUERY, type FetchLike, type FetchLikeResponse, type FetchPageOptions, type GraphqlRequestOptions, MIN_SESSION_SECRET_LENGTH, MODEL_DEFINITIONS_QUERY, MODEL_RECORDS_QUERY, PRODUCTS_QUERY, PROTOCOL_VERSION, type ParentReadyMessage, type PatchMessage, type PostTarget, type QueryScopedOptions, type ReadyMessage, type RetryPolicy, SESSION_MAX_AGE_SECONDS, SITE_CONFIG_QUERY, SUBMIT_FORM_MUTATION, type SelectMessage, applyCmssyCsp, asBucket, assertAuthConfig, backendAddToCart, backendApplyDiscount, backendCheckout, backendClearCart, backendForgotPassword, backendGetCart, backendMergeCart, backendMyOrder, backendMyOrders, backendOrderByToken, backendProduct, backendRefresh, backendRegister, backendRemoveDiscount, backendRemoveItem, backendResetPassword, backendSetShippingMethod, backendSignIn, backendSignOut, backendSignOutEverywhere, backendUpdateItem, backendVerifyEmail, buildBlockContext, buildLocaleSwitchHref, cachedWorkspaceId, clearWorkspaceIdCache, cmssyCspHeaders, cmssySecretsMatch, collectFormIds, createCmssyClient, decodeAccessClaims, defineCmssyConfig, fetchLayouts, fetchOrderByToken, fetchPage, fetchPageById, fetchPageMeta, fetchPages, fetchProduct, fetchProducts, fetchSiteConfig, fields, formatPrice, fractionDigits, fromMinorUnits, getBlockContentForLanguage, graphqlRequest, isAccessExpired, isDevelopment, isProtocolCompatible, isVerifiedEditUrl, localeForPath, localeForPathname, localizeHref, localizeHtmlLinks, localizedPath, normalizeOrigin, normalizeSlug, openSession, parseEditorMessage, postToEditor, resolveApiUrl, resolveEditorOrigin, resolveForms, resolveInitialTarget, resolvePublicUrl, resolveSeoLocales, resolveSiteLocales, resolveWorkspaceId, sealSession, sessionCookieOptions, splitCmssyLocale, splitLocaleFromPath, toCspOrigin, toMinorUnits, toSessionPayload, verifyCmssyWebhook };