@weaverse/hydrogen 5.17.0 → 5.18.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.
- package/dist/index.js +83 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +83 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types/WeaverseHydrogenRoot.d.ts +218 -0
- package/dist/types/WeaverseHydrogenRoot.d.ts.map +1 -0
- package/dist/types/components/index.d.ts +4 -0
- package/dist/types/components/index.d.ts.map +1 -0
- package/dist/types/components/main.d.ts +7 -0
- package/dist/types/components/main.d.ts.map +1 -0
- package/dist/types/hooks/theme-text-context.d.ts +2 -0
- package/dist/types/hooks/theme-text-context.d.ts.map +1 -0
- package/dist/types/hooks/translation-context.d.ts +138 -0
- package/dist/types/hooks/translation-context.d.ts.map +1 -0
- package/dist/types/hooks/use-weaverse-data-context.d.ts +29 -0
- package/dist/types/hooks/use-weaverse-data-context.d.ts.map +1 -0
- package/dist/types/index.d.ts +99 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/seo.d.ts +43 -0
- package/dist/types/seo.d.ts.map +1 -0
- package/dist/types/types.d.ts +826 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +44 -0
- package/dist/types/utils/index.d.ts.map +1 -0
- package/dist/types/utils/normalize-page-url.d.ts +16 -0
- package/dist/types/utils/normalize-page-url.d.ts.map +1 -0
- package/dist/types/utils/pick-weaverse-data.d.ts +44 -0
- package/dist/types/utils/pick-weaverse-data.d.ts.map +1 -0
- package/dist/types/utils/pixel.d.ts +16 -0
- package/dist/types/utils/pixel.d.ts.map +1 -0
- package/dist/types/utils/studio-request-info.d.ts +17 -0
- package/dist/types/utils/studio-request-info.d.ts.map +1 -0
- package/dist/types/utils/studio-script-src.d.ts +78 -0
- package/dist/types/utils/studio-script-src.d.ts.map +1 -0
- package/dist/types/utils/sync-reused-instance.d.ts +21 -0
- package/dist/types/utils/sync-reused-instance.d.ts.map +1 -0
- package/dist/types/utils/theme-text-store.d.ts +2 -0
- package/dist/types/utils/theme-text-store.d.ts.map +1 -0
- package/dist/types/utils/translation-store.d.ts +40 -0
- package/dist/types/utils/translation-store.d.ts.map +1 -0
- package/dist/types/utils/use-studio.d.ts +33 -0
- package/dist/types/utils/use-studio.d.ts.map +1 -0
- package/dist/types/utils/use-theme-settings-store.d.ts +39 -0
- package/dist/types/utils/use-theme-settings-store.d.ts.map +1 -0
- package/dist/types/weaverse-client.d.ts +227 -0
- package/dist/types/weaverse-client.d.ts.map +1 -0
- package/package.json +7 -6
- package/src/WeaverseHydrogenRoot.tsx +649 -0
- package/src/components/index.ts +10 -0
- package/src/components/main.tsx +28 -0
- package/src/hooks/theme-text-context.tsx +14 -0
- package/src/hooks/translation-context.tsx +275 -0
- package/src/hooks/use-weaverse-data-context.ts +69 -0
- package/src/index.ts +179 -0
- package/src/seo.ts +125 -0
- package/src/types.ts +1020 -0
- package/src/utils/index.ts +351 -0
- package/src/utils/normalize-page-url.ts +44 -0
- package/src/utils/pick-weaverse-data.ts +89 -0
- package/src/utils/pixel.ts +71 -0
- package/src/utils/studio-request-info.ts +66 -0
- package/src/utils/studio-script-src.ts +162 -0
- package/src/utils/sync-reused-instance.ts +57 -0
- package/src/utils/theme-text-store.ts +1 -0
- package/src/utils/translation-store.ts +65 -0
- package/src/utils/use-studio.ts +168 -0
- package/src/utils/use-theme-settings-store.ts +160 -0
- package/src/weaverse-client.ts +1179 -0
- package/dist/index.d.mts +0 -1269
- package/dist/index.d.ts +0 -1269
|
@@ -0,0 +1,826 @@
|
|
|
1
|
+
import type { CachingStrategy, HydrogenContext, I18nBase } from '@shopify/hydrogen';
|
|
2
|
+
import type { AppLoadContext, LoaderFunctionArgs as RemixOxygenLoaderArgs } from '@shopify/remix-oxygen';
|
|
3
|
+
import type { ElementData, PositionInputValue, WeaverseCoreParams, WeaverseElement, WeaverseImage, WeaverseProjectDataType, WeaverseResourcePickerData, WeaverseVideo } from '@weaverse/react';
|
|
4
|
+
import type { BasicInput, ComponentAvailabilityContext, ComponentGroup, HeadingInput, InputType, InspectorGroup, PageSEOData, PageType, Resolvable, ComponentPresets as SchemaComponentPresets, SchemaType, SchemaValidationIssue, SchemaValidationResult } from '@weaverse/schema';
|
|
5
|
+
import type * as React from 'react';
|
|
6
|
+
import type { ForwardRefExoticComponent } from 'react';
|
|
7
|
+
import type { NavigateFunction } from 'react-router';
|
|
8
|
+
import type { TranslationStore } from './utils/translation-store';
|
|
9
|
+
import type { ThemeSettingsStore } from './utils/use-theme-settings-store';
|
|
10
|
+
import type { WeaverseHydrogen } from './WeaverseHydrogenRoot';
|
|
11
|
+
import type { WeaverseClient } from './weaverse-client';
|
|
12
|
+
export type { CachingStrategy } from '@shopify/hydrogen';
|
|
13
|
+
export type { BasicInput, ComponentAvailabilityContext, ComponentGroup, HeadingInput, InputType, InspectorGroup, PageType, PositionInputValue, Resolvable, SchemaValidationIssue, SchemaValidationResult, WeaverseImage, WeaverseVideo, };
|
|
14
|
+
/** Arguments passed to a component's server-side loader. */
|
|
15
|
+
export type ComponentLoaderArgs<T = any, _E = any> = {
|
|
16
|
+
/** Persisted component data merged with schema defaults. */
|
|
17
|
+
data: T;
|
|
18
|
+
/** Request-scoped client available to the component loader. */
|
|
19
|
+
weaverse: WeaverseClient;
|
|
20
|
+
};
|
|
21
|
+
/** Application load context initialized with a request-scoped Weaverse client. */
|
|
22
|
+
export interface WeaverseRouteAppLoadContext extends AppLoadContext {
|
|
23
|
+
/** Client used to load Weaverse content for the current request. */
|
|
24
|
+
weaverse: WeaverseClient;
|
|
25
|
+
}
|
|
26
|
+
/** React Router loader arguments whose app context includes the Weaverse client. */
|
|
27
|
+
export interface RouteLoaderArgs extends RemixOxygenLoaderArgs {
|
|
28
|
+
/** Request-scoped application context with the initialized Weaverse client. */
|
|
29
|
+
context: WeaverseRouteAppLoadContext;
|
|
30
|
+
}
|
|
31
|
+
/** Primitive value accepted in a component's persisted data. */
|
|
32
|
+
export type ComponentDataValue = string | number | boolean | undefined | null;
|
|
33
|
+
/** Reference to a direct child component instance. */
|
|
34
|
+
export interface HydrogenChildComponentReference {
|
|
35
|
+
/** Unique identifier of the child component instance. */
|
|
36
|
+
id: string;
|
|
37
|
+
}
|
|
38
|
+
/** Serialized component instance returned in a Weaverse page. */
|
|
39
|
+
export interface HydrogenComponentData extends ElementData {
|
|
40
|
+
/** References to direct child component instances. */
|
|
41
|
+
children?: HydrogenChildComponentReference[];
|
|
42
|
+
/** ISO timestamp recording when the component instance was created. */
|
|
43
|
+
createdAt?: string;
|
|
44
|
+
/** Persisted component setting values and structured payloads. */
|
|
45
|
+
data?: Record<string, ComponentDataValue | Record<string, unknown>>;
|
|
46
|
+
/** ISO timestamp recording soft deletion, when applicable. */
|
|
47
|
+
deletedAt?: string;
|
|
48
|
+
/** Unique component instance identifier. */
|
|
49
|
+
id: string;
|
|
50
|
+
/** Registered component type used to select its renderer. */
|
|
51
|
+
type: string;
|
|
52
|
+
/** ISO timestamp recording the latest component update. */
|
|
53
|
+
updatedAt?: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Optimized: Use Zod-inferred SchemaType directly instead of extending
|
|
57
|
+
* This ensures perfect type consistency with the schema validation
|
|
58
|
+
*/
|
|
59
|
+
export type HydrogenComponentSchema = SchemaType;
|
|
60
|
+
/** Props supplied by Weaverse when rendering a registered Hydrogen component. */
|
|
61
|
+
export interface HydrogenComponentProps<L = any> extends WeaverseElement {
|
|
62
|
+
/** Rendered child component instances. */
|
|
63
|
+
children?: React.JSX.Element[];
|
|
64
|
+
/** Optional CSS class passed through by the renderer. */
|
|
65
|
+
className?: string;
|
|
66
|
+
/** Result returned by the component's server-side loader. */
|
|
67
|
+
loaderData?: L;
|
|
68
|
+
}
|
|
69
|
+
/** Normalized request details attached to loader data for Studio navigation. */
|
|
70
|
+
export type WeaverseLoaderRequestInfo = {
|
|
71
|
+
/** URL search string, including the leading question mark when present. */
|
|
72
|
+
search: string;
|
|
73
|
+
/** Storefront request pathname. */
|
|
74
|
+
pathname: string;
|
|
75
|
+
/** Parsed request query parameters. */
|
|
76
|
+
queries: {
|
|
77
|
+
/** Query parameter value keyed by parameter name. */
|
|
78
|
+
[key: string]: string | boolean;
|
|
79
|
+
};
|
|
80
|
+
/** Locale used to load the page. */
|
|
81
|
+
i18n: WeaverseI18n;
|
|
82
|
+
};
|
|
83
|
+
/** Published theme setting values keyed by schema setting name. */
|
|
84
|
+
export type HydrogenThemeSettings = {
|
|
85
|
+
/** Published theme setting value keyed by schema setting name. */
|
|
86
|
+
[key: string]: any;
|
|
87
|
+
};
|
|
88
|
+
/** Project metadata returned with a Weaverse page payload. */
|
|
89
|
+
export type HydrogenProjectType = {
|
|
90
|
+
/** Unique Weaverse project identifier. */
|
|
91
|
+
id: string;
|
|
92
|
+
/** Identifier of the Shopify shop connected to the project. */
|
|
93
|
+
weaverseShopId: string;
|
|
94
|
+
/** Human-readable project name. */
|
|
95
|
+
name: string;
|
|
96
|
+
/** Additional project metadata returned by the content API. */
|
|
97
|
+
[key: string]: any;
|
|
98
|
+
};
|
|
99
|
+
/** Runtime services and project metadata exposed to Weaverse integrations. */
|
|
100
|
+
export type WeaverseInternal = {
|
|
101
|
+
/** Route assignment for the rendered Weaverse page. */
|
|
102
|
+
pageAssignment: HydrogenPageAssignment;
|
|
103
|
+
/** Metadata for the active Weaverse project. */
|
|
104
|
+
project: HydrogenProjectType;
|
|
105
|
+
/** React Router navigation function, attached in design mode. */
|
|
106
|
+
navigate: NavigateFunction;
|
|
107
|
+
/** Revalidates the active React Router data routes. */
|
|
108
|
+
revalidate: () => void;
|
|
109
|
+
/** Mutable theme settings store used by Studio. */
|
|
110
|
+
themeSettingsStore: ThemeSettingsStore;
|
|
111
|
+
/** Mutable translation store used by Studio, when translations are enabled. */
|
|
112
|
+
translationStore?: TranslationStore | null;
|
|
113
|
+
/** @deprecated Use translationStore instead. */
|
|
114
|
+
themeTextStore?: TranslationStore | null;
|
|
115
|
+
/** Active-locale merchant translation overrides. */
|
|
116
|
+
merchantOverrides?: Record<string, unknown> | null;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Optimized: Use direct type alias to maintain consistency
|
|
120
|
+
*/
|
|
121
|
+
export type HydrogenComponentPresets = SchemaComponentPresets;
|
|
122
|
+
/** Registered runtime definition for a Hydrogen component type. */
|
|
123
|
+
export type HydrogenElement = {
|
|
124
|
+
/** React renderer for this registered component type. */
|
|
125
|
+
Component: ForwardRefExoticComponent<HydrogenComponentProps> | ((props: HydrogenComponentProps) => React.JSX.Element);
|
|
126
|
+
/** Unique component type matching the component schema. */
|
|
127
|
+
type: string;
|
|
128
|
+
/** Component schema used for settings, defaults, and availability. */
|
|
129
|
+
schema?: HydrogenComponentSchema;
|
|
130
|
+
/** Optional data loader function for server-side data fetching. */
|
|
131
|
+
loader?: (args: ComponentLoaderArgs) => Promise<unknown>;
|
|
132
|
+
};
|
|
133
|
+
/** Initialization parameters for a request-scoped {@link WeaverseHydrogen} runtime. */
|
|
134
|
+
export interface WeaverseHydrogenParams extends Omit<WeaverseCoreParams, 'ItemConstructor'> {
|
|
135
|
+
/** Page content used to initialize component instances. */
|
|
136
|
+
data: HydrogenPageData;
|
|
137
|
+
/** Route loader data made available to component data bindings. */
|
|
138
|
+
dataContext?: Record<string, unknown> | null;
|
|
139
|
+
/** Runtime services and metadata available to integrations. */
|
|
140
|
+
internal: Partial<WeaverseInternal>;
|
|
141
|
+
/** Whether the page is running inside the visual editor. */
|
|
142
|
+
isDesignMode?: boolean;
|
|
143
|
+
/** Whether a component preview is being rendered. */
|
|
144
|
+
isPreviewMode?: boolean;
|
|
145
|
+
/** Whether a saved page revision is being previewed. */
|
|
146
|
+
isRevisionPreview?: boolean;
|
|
147
|
+
/** Identifier of the page being rendered. */
|
|
148
|
+
pageId: string;
|
|
149
|
+
/** Identifier of the Weaverse project supplying content. */
|
|
150
|
+
projectId: string;
|
|
151
|
+
/** Normalized URL and locale information for this request. */
|
|
152
|
+
requestInfo: WeaverseLoaderRequestInfo;
|
|
153
|
+
/** Component type requested by section preview mode. */
|
|
154
|
+
sectionType?: string;
|
|
155
|
+
/** Base URL used for public Weaverse API requests. */
|
|
156
|
+
weaverseApiBase: string;
|
|
157
|
+
/**
|
|
158
|
+
* API key read from environment/configuration for storefront requests or
|
|
159
|
+
* supplied by Studio requests while editing and previewing.
|
|
160
|
+
*/
|
|
161
|
+
weaverseApiKey: string;
|
|
162
|
+
/** Origin used for Weaverse Studio assets and editor communication. */
|
|
163
|
+
weaverseHost: string;
|
|
164
|
+
/**
|
|
165
|
+
* Public data API origin. Keep `weaverseHost` for Studio scripts/editor
|
|
166
|
+
* assets; point this at the Cloudflare proxy (`https://api.weaverse.io`)
|
|
167
|
+
* when edge caching is enabled.
|
|
168
|
+
*/
|
|
169
|
+
weaversePublicApiBase?: string;
|
|
170
|
+
/** Optional Studio asset version used by preview integrations. */
|
|
171
|
+
weaverseVersion?: string;
|
|
172
|
+
}
|
|
173
|
+
/** Export shape for a renderable component, its schema, and optional loader. */
|
|
174
|
+
export type HydrogenComponent<T extends HydrogenComponentProps = any> = {
|
|
175
|
+
/** React renderer exported by the component module. */
|
|
176
|
+
default: ForwardRefExoticComponent<T> | ((props: T) => React.JSX.Element);
|
|
177
|
+
/** Schema exported by the component module. */
|
|
178
|
+
schema: HydrogenComponentSchema;
|
|
179
|
+
/** Optional data loader function for server-side data fetching. */
|
|
180
|
+
loader?: (args: ComponentLoaderArgs) => Promise<unknown>;
|
|
181
|
+
};
|
|
182
|
+
/** Weaverse Studio query parameters recognized by the Hydrogen runtime. */
|
|
183
|
+
export type WeaverseStudioQueries = {
|
|
184
|
+
/** Project identifier selected by Studio for this request. */
|
|
185
|
+
weaverseProjectId: string;
|
|
186
|
+
/** API key passed by Studio for design and preview requests. */
|
|
187
|
+
weaverseApiKey: string;
|
|
188
|
+
/** Studio origin serving editor assets and APIs. */
|
|
189
|
+
weaverseHost: string;
|
|
190
|
+
/** Studio asset version requested by the editor. */
|
|
191
|
+
weaverseVersion: string;
|
|
192
|
+
/** Whether the request is for the visual editor. */
|
|
193
|
+
isDesignMode: boolean;
|
|
194
|
+
/** Whether the request renders a component preview. */
|
|
195
|
+
isPreviewMode?: boolean;
|
|
196
|
+
/** Component type requested for section preview. */
|
|
197
|
+
sectionType?: string;
|
|
198
|
+
};
|
|
199
|
+
/** Storefront-safe environment values exposed with theme settings. */
|
|
200
|
+
export type PublicEnv = {
|
|
201
|
+
/** Public Shopify storefront domain. */
|
|
202
|
+
PUBLIC_STORE_DOMAIN: string;
|
|
203
|
+
/** Public Storefront API access token. */
|
|
204
|
+
PUBLIC_STOREFRONT_API_TOKEN: string;
|
|
205
|
+
};
|
|
206
|
+
/** Resolved project, API endpoint, and rendering-mode configuration. */
|
|
207
|
+
export type WeaverseProjectConfigs = {
|
|
208
|
+
/** Identifier of the Weaverse project supplying content. */
|
|
209
|
+
projectId: string;
|
|
210
|
+
/** Origin used for Studio assets and editor communication. */
|
|
211
|
+
weaverseHost: string;
|
|
212
|
+
/** Base URL used for public Weaverse content API requests. */
|
|
213
|
+
weaverseApiBase: string;
|
|
214
|
+
/** Explicit public data API origin, when separately configured. */
|
|
215
|
+
weaversePublicApiBase?: string;
|
|
216
|
+
/**
|
|
217
|
+
* API key read from environment/configuration for storefront requests or
|
|
218
|
+
* supplied by Studio requests while editing and previewing.
|
|
219
|
+
*/
|
|
220
|
+
weaverseApiKey: string;
|
|
221
|
+
/** Optional Studio asset version. */
|
|
222
|
+
weaverseVersion?: string;
|
|
223
|
+
/** Whether the request is running inside the visual editor. */
|
|
224
|
+
isDesignMode?: boolean;
|
|
225
|
+
/** Whether the request renders a component preview. */
|
|
226
|
+
isPreviewMode?: boolean;
|
|
227
|
+
/** Whether the request previews a saved page revision. */
|
|
228
|
+
isRevisionPreview?: boolean;
|
|
229
|
+
/** Component type requested for section preview. */
|
|
230
|
+
sectionType?: string;
|
|
231
|
+
/** Storefront-safe environment values exposed with theme settings. */
|
|
232
|
+
publicEnv?: PublicEnv;
|
|
233
|
+
};
|
|
234
|
+
/** Assignment describing which project page handles a storefront route. */
|
|
235
|
+
export type HydrogenPageAssignment = {
|
|
236
|
+
/** Project identifier owning the assigned page. */
|
|
237
|
+
projectId: string;
|
|
238
|
+
/** Storefront page type matched by the assignment. */
|
|
239
|
+
type: PageType;
|
|
240
|
+
/** Route or resource handle matched by the assignment. */
|
|
241
|
+
handle: string;
|
|
242
|
+
/** Locale matched by the assignment. */
|
|
243
|
+
locale: string;
|
|
244
|
+
/** Inheritance details when the assignment comes from another project. */
|
|
245
|
+
meta?: {
|
|
246
|
+
/** Whether the assignment was inherited. */
|
|
247
|
+
inherited: boolean;
|
|
248
|
+
/** Project identifier where the assignment originated. */
|
|
249
|
+
sourceProjectId: string;
|
|
250
|
+
/** Number of inheritance levels traversed. */
|
|
251
|
+
depth: number;
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
|
+
/** Complete payload returned by {@link WeaverseClient.loadPage}. */
|
|
255
|
+
export type WeaverseLoaderData = {
|
|
256
|
+
/** Resolved runtime configuration and normalized request details. */
|
|
257
|
+
configs: Omit<WeaverseProjectConfigs, 'publicEnv'> & {
|
|
258
|
+
/** Normalized URL and locale information for the request. */
|
|
259
|
+
requestInfo: WeaverseLoaderRequestInfo;
|
|
260
|
+
};
|
|
261
|
+
/** Published page content to render. */
|
|
262
|
+
page: HydrogenPageData;
|
|
263
|
+
/** Metadata for the project supplying the page. */
|
|
264
|
+
project: HydrogenProjectType;
|
|
265
|
+
/** Route assignment that selected the page, when available. */
|
|
266
|
+
pageAssignment?: HydrogenPageAssignment;
|
|
267
|
+
};
|
|
268
|
+
/** Published Weaverse page content consumed by the Hydrogen renderer. */
|
|
269
|
+
export interface HydrogenPageData extends WeaverseProjectDataType {
|
|
270
|
+
/** Internal cache identifier attached by the content API when available. */
|
|
271
|
+
__cacheId?: string;
|
|
272
|
+
/** Unique page identifier. */
|
|
273
|
+
id: string;
|
|
274
|
+
/** Serialized component instances belonging to the page. */
|
|
275
|
+
items: HydrogenComponentData[];
|
|
276
|
+
/** Human-readable page name. */
|
|
277
|
+
name: string;
|
|
278
|
+
/**
|
|
279
|
+
* Page-level SEO metadata published by Weaverse Builder. `null` when
|
|
280
|
+
* the page has no `PageSeo` row; absent on revision snapshots that
|
|
281
|
+
* predate the SEO feature. Themes should treat both as "no Weaverse
|
|
282
|
+
* override".
|
|
283
|
+
*/
|
|
284
|
+
seo?: PageSEOData | null;
|
|
285
|
+
/** Additional page fields supplied by the content API. */
|
|
286
|
+
[key: string]: any;
|
|
287
|
+
}
|
|
288
|
+
/** Locale metadata used when requesting localized Weaverse content. */
|
|
289
|
+
export type WeaverseI18n = I18nBase & {
|
|
290
|
+
/** Human-readable locale label displayed in Studio. */
|
|
291
|
+
label?: string;
|
|
292
|
+
/** Locale path prefix used by the storefront router. */
|
|
293
|
+
pathPrefix?: string;
|
|
294
|
+
/** Additional locale metadata supplied by the storefront. */
|
|
295
|
+
[key: string]: any;
|
|
296
|
+
};
|
|
297
|
+
/** Theme metadata, global settings, and localization configuration. */
|
|
298
|
+
export type HydrogenThemeSchema = {
|
|
299
|
+
/** Theme identity, author, and support metadata. */
|
|
300
|
+
info: {
|
|
301
|
+
/** Human-readable theme name. */
|
|
302
|
+
name: string;
|
|
303
|
+
/** Theme version displayed in Studio. */
|
|
304
|
+
version: string;
|
|
305
|
+
/** Theme author name. */
|
|
306
|
+
author: string;
|
|
307
|
+
/** URL of the theme author's profile image. */
|
|
308
|
+
authorProfilePhoto: string;
|
|
309
|
+
/** URL of the theme documentation. */
|
|
310
|
+
documentationUrl: string;
|
|
311
|
+
/** URL where merchants can request theme support. */
|
|
312
|
+
supportUrl: string;
|
|
313
|
+
};
|
|
314
|
+
/** @deprecated Use settings instead. */
|
|
315
|
+
inspector?: InspectorGroup[];
|
|
316
|
+
/** Groups of global theme settings exposed in Studio. */
|
|
317
|
+
settings?: InspectorGroup[];
|
|
318
|
+
/** Theme localization configuration. */
|
|
319
|
+
i18n?: {
|
|
320
|
+
/** Strategy used to encode the locale in storefront URLs. */
|
|
321
|
+
urlStructure: 'url-path' | 'subdomain' | 'top-level-domain';
|
|
322
|
+
/** Locale used when no localized route is selected. */
|
|
323
|
+
defaultLocale: WeaverseI18n;
|
|
324
|
+
/** Locales enabled for the connected Shopify shop. */
|
|
325
|
+
shopLocales: WeaverseI18n[];
|
|
326
|
+
/** Default-locale static translation content. */
|
|
327
|
+
staticContent?: Record<string, unknown>;
|
|
328
|
+
/** Enable the translation UI in the builder. */
|
|
329
|
+
translation?: boolean;
|
|
330
|
+
};
|
|
331
|
+
};
|
|
332
|
+
/** Request body sent to the Weaverse project content endpoint. */
|
|
333
|
+
export type FetchProjectRequestBody = {
|
|
334
|
+
/** Identifier of the project to load. */
|
|
335
|
+
projectId: string;
|
|
336
|
+
/** Normalized storefront URL being resolved. */
|
|
337
|
+
url: string;
|
|
338
|
+
/** Storefront locale for localized content. */
|
|
339
|
+
i18n?: WeaverseI18n;
|
|
340
|
+
/** Optional route-specific page lookup parameters. */
|
|
341
|
+
params?: {
|
|
342
|
+
/** Storefront page type to load. */
|
|
343
|
+
type?: PageType;
|
|
344
|
+
/** Locale override for this page lookup. */
|
|
345
|
+
locale?: string;
|
|
346
|
+
/** Resource or custom-page handle to load. */
|
|
347
|
+
handle?: string;
|
|
348
|
+
};
|
|
349
|
+
/** Whether draft editor content should be returned. */
|
|
350
|
+
isDesignMode?: boolean;
|
|
351
|
+
};
|
|
352
|
+
/** Project content response before it is normalized into loader data. */
|
|
353
|
+
export type FetchProjectPayload = {
|
|
354
|
+
/** Published or draft page content; absent when no page matches. */
|
|
355
|
+
page?: HydrogenPageData;
|
|
356
|
+
/** Project metadata; absent in some error responses. */
|
|
357
|
+
project?: HydrogenProjectType;
|
|
358
|
+
/** Assignment that selected the page, when one matched. */
|
|
359
|
+
pageAssignment?: HydrogenPageAssignment;
|
|
360
|
+
/** API error message, when the request could not be fulfilled. */
|
|
361
|
+
error?: string;
|
|
362
|
+
/** Additional fields returned by compatible API versions. */
|
|
363
|
+
[key: string]: any;
|
|
364
|
+
};
|
|
365
|
+
/**
|
|
366
|
+
* Project identifier value - can be static string or dynamic function.
|
|
367
|
+
*
|
|
368
|
+
* **Static String**: Direct project ID reference
|
|
369
|
+
* ```ts
|
|
370
|
+
* 'project-abc-123'
|
|
371
|
+
* ```
|
|
372
|
+
*
|
|
373
|
+
* **Synchronous Function**: Returns project ID based on request context
|
|
374
|
+
* ```ts
|
|
375
|
+
* () => {
|
|
376
|
+
* const host = new URL(request.url).hostname
|
|
377
|
+
* return PROJECT_MAP[host] || 'default-project'
|
|
378
|
+
* }
|
|
379
|
+
* ```
|
|
380
|
+
*
|
|
381
|
+
* **Asynchronous Function**: Async project resolution (must be awaited before passing)
|
|
382
|
+
* ```ts
|
|
383
|
+
* async () => {
|
|
384
|
+
* return await database.getProjectId(userId)
|
|
385
|
+
* }
|
|
386
|
+
* ```
|
|
387
|
+
*/
|
|
388
|
+
export type ProjectIdValue = string | (() => string) | (() => Promise<string>);
|
|
389
|
+
/**
|
|
390
|
+
* Type guard for detecting function-based projectId.
|
|
391
|
+
*
|
|
392
|
+
* Used internally by WeaverseClient constructor to determine
|
|
393
|
+
* if projectId needs evaluation or can be used directly.
|
|
394
|
+
*/
|
|
395
|
+
export declare function isProjectIdFunction(projectId: ProjectIdValue | undefined): projectId is (() => string) | (() => Promise<string>);
|
|
396
|
+
/**
|
|
397
|
+
* Extended WeaverseClient constructor arguments supporting multi-project architecture.
|
|
398
|
+
*
|
|
399
|
+
* @example Static project (existing pattern - backward compatible)
|
|
400
|
+
* ```ts
|
|
401
|
+
* const weaverse = new WeaverseClient({
|
|
402
|
+
* ...hydrogenContext,
|
|
403
|
+
* projectId: 'project-default-123'
|
|
404
|
+
* })
|
|
405
|
+
* ```
|
|
406
|
+
*
|
|
407
|
+
* @example Dynamic project selection (new capability)
|
|
408
|
+
* ```ts
|
|
409
|
+
* const weaverse = new WeaverseClient({
|
|
410
|
+
* ...hydrogenContext,
|
|
411
|
+
* projectId: () => {
|
|
412
|
+
* const origin = new URL(request.url).origin
|
|
413
|
+
* if (origin === 'https://mystore.se') return process.env.WEAVERSE_PROJECT_SWEDEN!
|
|
414
|
+
* if (origin === 'https://mystore.fr') return process.env.WEAVERSE_PROJECT_FRANCE!
|
|
415
|
+
* return process.env.WEAVERSE_PROJECT_ID!
|
|
416
|
+
* }
|
|
417
|
+
* })
|
|
418
|
+
* ```
|
|
419
|
+
*
|
|
420
|
+
* **Priority Chain** (highest to lowest):
|
|
421
|
+
* 1. URL query parameter: `?weaverseProjectId=...` (design mode, preview mode)
|
|
422
|
+
* 2. Function result (if function provided)
|
|
423
|
+
* 3. Explicit string value (if string provided)
|
|
424
|
+
* 4. Environment variable: `WEAVERSE_PROJECT_ID` (Hydrogen env or process.env)
|
|
425
|
+
* 5. Empty string (triggers validation error in methods)
|
|
426
|
+
*
|
|
427
|
+
* **Function Requirements**:
|
|
428
|
+
* - Must return non-empty string
|
|
429
|
+
* - Can access request via closure for routing decisions
|
|
430
|
+
* - Evaluated once per WeaverseClient instance (request-scoped)
|
|
431
|
+
* - Async functions must be awaited before passing to constructor
|
|
432
|
+
* - Should handle edge cases (missing headers, invalid domains, etc.)
|
|
433
|
+
*
|
|
434
|
+
* **Request Context Access**:
|
|
435
|
+
* Functions access request via closure from constructor arguments.
|
|
436
|
+
*/
|
|
437
|
+
export type WeaverseClientArgs = HydrogenContext & {
|
|
438
|
+
/**
|
|
439
|
+
* React components registered with Weaverse CMS.
|
|
440
|
+
* Each component must have a schema defining its properties and settings.
|
|
441
|
+
*/
|
|
442
|
+
components: HydrogenComponent[];
|
|
443
|
+
/**
|
|
444
|
+
* Theme schema defining global theme settings (colors, fonts, layouts).
|
|
445
|
+
* Used to generate default theme configuration and validate theme data.
|
|
446
|
+
*/
|
|
447
|
+
themeSchema: HydrogenThemeSchema;
|
|
448
|
+
/**
|
|
449
|
+
* Incoming HTTP request object from React Router loader.
|
|
450
|
+
* Provides access to URL, headers, cookies for dynamic routing decisions.
|
|
451
|
+
*/
|
|
452
|
+
request: Request;
|
|
453
|
+
/**
|
|
454
|
+
* Hydrogen cache instance for content caching.
|
|
455
|
+
*Supports multi-tenant caching with project-specific cache keys.
|
|
456
|
+
*/
|
|
457
|
+
cache: Cache;
|
|
458
|
+
/**
|
|
459
|
+
* Project identifier for loading content from Weaverse CMS.
|
|
460
|
+
*
|
|
461
|
+
* **Value Types**:
|
|
462
|
+
* - Static string: 'project-123' (existing usage)
|
|
463
|
+
* - Synchronous function: () => determineProject(request)
|
|
464
|
+
* - Asynchronous function: async () => await getProject(request) (must be awaited)
|
|
465
|
+
*
|
|
466
|
+
* **Backward Compatibility**:
|
|
467
|
+
* - Optional parameter (defaults to environment variable)
|
|
468
|
+
* - Existing code without projectId continues to work unchanged
|
|
469
|
+
*
|
|
470
|
+
* **Cache Isolation**:
|
|
471
|
+
* ProjectId is included in cache keys to prevent cross-project content pollution.
|
|
472
|
+
* Each project's content is cached separately, ensuring multi-tenant isolation.
|
|
473
|
+
*/
|
|
474
|
+
projectId?: ProjectIdValue;
|
|
475
|
+
/**
|
|
476
|
+
* Fetch timeout in milliseconds for API requests.
|
|
477
|
+
* Defaults to 10000ms (10 seconds) if not specified.
|
|
478
|
+
* Useful for adjusting based on network conditions or deployment environment.
|
|
479
|
+
*
|
|
480
|
+
* @default 10000
|
|
481
|
+
* @example
|
|
482
|
+
* ```typescript
|
|
483
|
+
* new WeaverseClient({
|
|
484
|
+
* // ... other args
|
|
485
|
+
* fetchTimeoutMs: 5000 // 5 second timeout
|
|
486
|
+
* })
|
|
487
|
+
* ```
|
|
488
|
+
*/
|
|
489
|
+
fetchTimeoutMs?: number;
|
|
490
|
+
};
|
|
491
|
+
/** Product selected through a Weaverse resource-picker setting. */
|
|
492
|
+
export type WeaverseProduct = WeaverseResourcePickerData;
|
|
493
|
+
/** Collection selected through a Weaverse resource-picker setting. */
|
|
494
|
+
export type WeaverseCollection = WeaverseResourcePickerData;
|
|
495
|
+
/** Blog selected through a Weaverse resource-picker setting. */
|
|
496
|
+
export type WeaverseBlog = WeaverseResourcePickerData;
|
|
497
|
+
/** Article selected through a Weaverse resource-picker setting. */
|
|
498
|
+
export type WeaverseArticle = WeaverseResourcePickerData;
|
|
499
|
+
/** Metaobject selected through a Weaverse resource-picker setting. */
|
|
500
|
+
export type WeaverseMetaObject = WeaverseResourcePickerData;
|
|
501
|
+
/** Response returned by Hydrogen's cached fetch helper. */
|
|
502
|
+
export type WithCacheFetchResponse<T> = {
|
|
503
|
+
/** Parsed response payload. */
|
|
504
|
+
data: T;
|
|
505
|
+
/** Underlying Fetch API response. */
|
|
506
|
+
response: Response;
|
|
507
|
+
};
|
|
508
|
+
/** Theme configuration returned by the Weaverse project API. */
|
|
509
|
+
export type ThemeSettingsResponse = {
|
|
510
|
+
/** Published theme setting values. */
|
|
511
|
+
theme?: HydrogenThemeSettings;
|
|
512
|
+
/** Theme schema included for Studio editing. */
|
|
513
|
+
schema?: HydrogenThemeSchema;
|
|
514
|
+
/** Storefront-safe environment values included in design mode. */
|
|
515
|
+
publicEnv?: PublicEnv;
|
|
516
|
+
/** Theme's default locale JSON from `themeSchema.i18n.staticContent`. */
|
|
517
|
+
staticContent?: Record<string, unknown>;
|
|
518
|
+
/** Locale-specific merchant overrides from the API. */
|
|
519
|
+
merchantOverrides?: Record<string, unknown>;
|
|
520
|
+
/** Diagnostic message when loading fell back to schema defaults. */
|
|
521
|
+
_error?: string;
|
|
522
|
+
/** Whether remote theme settings failed to load. */
|
|
523
|
+
_loadFailed?: boolean;
|
|
524
|
+
};
|
|
525
|
+
/**
|
|
526
|
+
* Legacy data-or-error response shape retained for compatibility.
|
|
527
|
+
*
|
|
528
|
+
* The client's current direct-fetch implementation uses
|
|
529
|
+
* {@link WithCacheFetchResponse} internally instead of returning this shape.
|
|
530
|
+
*/
|
|
531
|
+
export type DirectFetchResponse<T = unknown> = {
|
|
532
|
+
/** Parsed payload when the legacy request succeeded. */
|
|
533
|
+
data?: T;
|
|
534
|
+
/** Error message when the legacy request failed. */
|
|
535
|
+
error?: string;
|
|
536
|
+
};
|
|
537
|
+
/** Predicate used to decide whether a fetched response may be cached. */
|
|
538
|
+
export type CacheResponseValidator<T = unknown> = (response: WithCacheFetchResponse<T> | T) => boolean;
|
|
539
|
+
/** Error raised by Weaverse requests with a stable code and optional context. */
|
|
540
|
+
export declare class WeaverseError extends Error {
|
|
541
|
+
/** Machine-readable error code. */
|
|
542
|
+
readonly code: string;
|
|
543
|
+
/** HTTP status associated with the failure, when available. */
|
|
544
|
+
readonly statusCode?: number;
|
|
545
|
+
/** Structured diagnostic details for logging and error handling. */
|
|
546
|
+
readonly context?: Record<string, unknown>;
|
|
547
|
+
/** Creates a Weaverse request error with a stable code and diagnostics. */
|
|
548
|
+
constructor(message: string, code?: string, statusCode?: number, context?: Record<string, unknown>);
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Validation result type for project ID validation.
|
|
552
|
+
* Returns validation status with optional error message.
|
|
553
|
+
*/
|
|
554
|
+
export type ProjectIdValidationResult = {
|
|
555
|
+
/** Whether the project identifier passed validation. */
|
|
556
|
+
valid: boolean;
|
|
557
|
+
/** Validation error message when `valid` is false. */
|
|
558
|
+
error?: string;
|
|
559
|
+
};
|
|
560
|
+
/** Published custom page entry suitable for sitemap generation. */
|
|
561
|
+
export interface CustomPageEntry {
|
|
562
|
+
/** Suggested sitemap update frequency. */
|
|
563
|
+
changeFrequency?: 'daily' | 'weekly' | 'monthly';
|
|
564
|
+
/** Weaverse custom page handle. */
|
|
565
|
+
handle: string;
|
|
566
|
+
/** ISO timestamp of the latest published update. */
|
|
567
|
+
lastModified: string;
|
|
568
|
+
/** Locale code, or `null` for the project's default locale. */
|
|
569
|
+
locale: string | null;
|
|
570
|
+
/** Storefront path for the custom page. */
|
|
571
|
+
path: string;
|
|
572
|
+
/** Optional sitemap priority from zero to one. */
|
|
573
|
+
priority?: number;
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* Type guards for response validation
|
|
577
|
+
*/
|
|
578
|
+
export declare function isWithCacheFetchResponse<T>(response: unknown): response is WithCacheFetchResponse<T>;
|
|
579
|
+
/** Checks whether a value contains the required project response fields. */
|
|
580
|
+
export declare function isFetchProjectPayload(payload: unknown): payload is FetchProjectPayload;
|
|
581
|
+
/** Response containing an error message returned by a Weaverse request. */
|
|
582
|
+
export interface WeaverseErrorResponse {
|
|
583
|
+
/** Human-readable request failure message. */
|
|
584
|
+
error: string;
|
|
585
|
+
}
|
|
586
|
+
/** Checks whether a response contains a string error message. */
|
|
587
|
+
export declare function hasError(response: unknown): response is WeaverseErrorResponse;
|
|
588
|
+
/** Checks whether a value contains a theme settings object. */
|
|
589
|
+
export declare function isThemeSettingsResponse(data: unknown): data is ThemeSettingsResponse;
|
|
590
|
+
/**
|
|
591
|
+
* Enhanced type utilities for better development experience
|
|
592
|
+
*/
|
|
593
|
+
export type HydrogenSchemaValidationResult = SchemaValidationResult<HydrogenComponentSchema>;
|
|
594
|
+
/**
|
|
595
|
+
* Type guard to check if a schema is valid.
|
|
596
|
+
* Leverages validation from @weaverse/schema package which provides
|
|
597
|
+
* comprehensive Zod-based validation with the ElementSchema.
|
|
598
|
+
*
|
|
599
|
+
* @param schema - Unknown value to validate
|
|
600
|
+
* @returns True if schema is a valid HydrogenComponentSchema
|
|
601
|
+
*
|
|
602
|
+
* @example
|
|
603
|
+
* ```typescript
|
|
604
|
+
* if (isValidHydrogenSchema(userInput)) {
|
|
605
|
+
* // userInput is now typed as HydrogenComponentSchema
|
|
606
|
+
* console.log(userInput.type)
|
|
607
|
+
* }
|
|
608
|
+
* ```
|
|
609
|
+
*/
|
|
610
|
+
export declare function isValidHydrogenSchema(schema: unknown): schema is HydrogenComponentSchema;
|
|
611
|
+
/** Type-safe component schema authoring options. */
|
|
612
|
+
export type CreateHydrogenSchemaOptions = {
|
|
613
|
+
/** Human-readable component title displayed in Studio. */
|
|
614
|
+
title: string;
|
|
615
|
+
/** Unique component type used for registration and persisted items. */
|
|
616
|
+
type: string;
|
|
617
|
+
/** Maximum number of instances allowed in the containing scope. */
|
|
618
|
+
limit?: number;
|
|
619
|
+
/** Inspector groups defining editable component settings. */
|
|
620
|
+
settings?: InspectorGroup[];
|
|
621
|
+
/** Component types allowed as direct children. */
|
|
622
|
+
childTypes?: string[];
|
|
623
|
+
/**
|
|
624
|
+
* Legacy page and placement availability restrictions.
|
|
625
|
+
*
|
|
626
|
+
* @deprecated Use `enabled` instead. Convert the arrays to checks in an
|
|
627
|
+
* `enabled` resolver, for example:
|
|
628
|
+
* `enabled: ({page, group}) => pages.includes(page.type) &&
|
|
629
|
+
* (groups.includes('*') || groups.includes(group))`.
|
|
630
|
+
*/
|
|
631
|
+
enabledOn?: {
|
|
632
|
+
/** Page types where the component can be inserted. */
|
|
633
|
+
pages?: PageType[];
|
|
634
|
+
/** Placement groups where the component can be inserted; `*` allows all. */
|
|
635
|
+
groups?: ('*' | 'header' | 'footer' | 'body')[];
|
|
636
|
+
};
|
|
637
|
+
/** Static or context-aware component availability rule. */
|
|
638
|
+
enabled?: Resolvable<boolean, ComponentAvailabilityContext>;
|
|
639
|
+
/** Default component data and optional nested component presets. */
|
|
640
|
+
presets?: {
|
|
641
|
+
/** Components inserted as children by the preset. */
|
|
642
|
+
children?: SchemaComponentPresets[];
|
|
643
|
+
/** Additional default setting value keyed by setting name. */
|
|
644
|
+
[key: string]: any;
|
|
645
|
+
};
|
|
646
|
+
};
|
|
647
|
+
declare global {
|
|
648
|
+
interface Window {
|
|
649
|
+
__weaverse?: WeaverseHydrogen;
|
|
650
|
+
__weaverses?: Record<string, WeaverseHydrogen>;
|
|
651
|
+
__weaverseThemeSettingsStore?: ThemeSettingsStore;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
/** Browser bridge exposed by Weaverse Studio in design and preview modes. */
|
|
655
|
+
export interface WeaverseStudio {
|
|
656
|
+
/** Connects Studio to a newly created Hydrogen runtime. */
|
|
657
|
+
init: (weaverse: WeaverseHydrogen) => void;
|
|
658
|
+
/** Refreshes Studio after the active runtime configuration changes. */
|
|
659
|
+
refreshStudio: (params: WeaverseHydrogenParams) => void;
|
|
660
|
+
}
|
|
661
|
+
/** Browser window after the Weaverse Studio bridge has initialized. */
|
|
662
|
+
export interface WeaverseStudioWindow extends Window {
|
|
663
|
+
/** Studio bridge used to initialize and refresh the Hydrogen runtime. */
|
|
664
|
+
weaverseStudio: WeaverseStudio;
|
|
665
|
+
}
|
|
666
|
+
/** Checks whether the browser window exposes the Weaverse Studio bridge. */
|
|
667
|
+
export declare function hasWeaverseStudio(window: Window): window is WeaverseStudioWindow;
|
|
668
|
+
declare module '@shopify/remix-oxygen' {
|
|
669
|
+
interface AppLoadContext {
|
|
670
|
+
weaverse: WeaverseClient;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
declare module '@shopify/hydrogen' {
|
|
674
|
+
interface HydrogenEnv {
|
|
675
|
+
CUSTOM_COLLECTION_BANNER_METAFIELD: string;
|
|
676
|
+
JUDGEME_PRIVATE_API_TOKEN: string;
|
|
677
|
+
KLAVIYO_PRIVATE_API_TOKEN: string;
|
|
678
|
+
METAOBJECT_COLOR_NAME_KEY: string;
|
|
679
|
+
METAOBJECT_COLOR_VALUE_KEY: string;
|
|
680
|
+
METAOBJECT_COLORS_TYPE: string;
|
|
681
|
+
PUBLIC_GOOGLE_GTM_ID: string;
|
|
682
|
+
PUBLIC_SHOPIFY_INBOX_SHOP_ID: string;
|
|
683
|
+
PUBLIC_STORE_DOMAIN: string;
|
|
684
|
+
PUBLIC_STOREFRONT_API_TOKEN: string;
|
|
685
|
+
WEAVERSE_API_KEY: string;
|
|
686
|
+
WEAVERSE_HOST?: string;
|
|
687
|
+
WEAVERSE_PROJECT_ID: string;
|
|
688
|
+
WEAVERSE_PUBLIC_API_BASE?: string;
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
692
|
+
* Parameters for loadPage method supporting route-level project override.
|
|
693
|
+
*
|
|
694
|
+
* @example Basic usage (uses client-level project)
|
|
695
|
+
* ```ts
|
|
696
|
+
* const weaverseData = await weaverse.loadPage({
|
|
697
|
+
* type: 'PRODUCT',
|
|
698
|
+
* handle: params.productHandle
|
|
699
|
+
* })
|
|
700
|
+
* ```
|
|
701
|
+
*
|
|
702
|
+
* @example Route-level project override
|
|
703
|
+
* ```ts
|
|
704
|
+
* export async function loader({ params, context }: LoaderFunctionArgs) {
|
|
705
|
+
* const { weaverse } = context
|
|
706
|
+
*
|
|
707
|
+
* // Use special campaign project for this route only
|
|
708
|
+
* const weaverseData = await weaverse.loadPage({
|
|
709
|
+
* type: 'PRODUCT',
|
|
710
|
+
* handle: params.productHandle,
|
|
711
|
+
* projectId: process.env.WEAVERSE_PROJECT_CAMPAIGN // Override
|
|
712
|
+
* })
|
|
713
|
+
*
|
|
714
|
+
* return { weaverseData }
|
|
715
|
+
* }
|
|
716
|
+
* ```
|
|
717
|
+
*/
|
|
718
|
+
export type LoadPageParams = {
|
|
719
|
+
/**
|
|
720
|
+
* Page type to load from Weaverse CMS.
|
|
721
|
+
*
|
|
722
|
+
* Determines which template to use for rendering the page.
|
|
723
|
+
* Falls back to 'INDEX' if not specified or if page type doesn't exist.
|
|
724
|
+
*
|
|
725
|
+
* @default 'INDEX'
|
|
726
|
+
*/
|
|
727
|
+
type?: PageType;
|
|
728
|
+
/**
|
|
729
|
+
* Locale for internationalization.
|
|
730
|
+
*
|
|
731
|
+
* Format: IETF BCP 47 language tag (e.g., 'en-US', 'fr-FR', 'de-DE')
|
|
732
|
+
* Used to load locale-specific content and translations.
|
|
733
|
+
*/
|
|
734
|
+
locale?: string;
|
|
735
|
+
/**
|
|
736
|
+
* Page handle for dynamic pages.
|
|
737
|
+
*
|
|
738
|
+
* Identifies specific resource within page type:
|
|
739
|
+
* - Product handle: 'red-sneakers'
|
|
740
|
+
* - Collection handle: 'summer-sale'
|
|
741
|
+
* - Page handle: 'about-us'
|
|
742
|
+
* - Article handle: 'how-to-style-sneakers'
|
|
743
|
+
*/
|
|
744
|
+
handle?: string;
|
|
745
|
+
/**
|
|
746
|
+
* Cache strategy override for this specific page load.
|
|
747
|
+
*
|
|
748
|
+
* Overrides default cache strategy for special use cases:
|
|
749
|
+
* - Fresh content for checkout pages (no cache)
|
|
750
|
+
* - Long-lived cache for static pages (1 hour+)
|
|
751
|
+
* - Short-lived cache for frequently updated content (5 minutes)
|
|
752
|
+
*/
|
|
753
|
+
strategy?: CachingStrategy;
|
|
754
|
+
/**
|
|
755
|
+
* Optional project override for this specific page load.
|
|
756
|
+
*
|
|
757
|
+
* **Precedence**: Route-level projectId takes precedence over client-level projectId.
|
|
758
|
+
*
|
|
759
|
+
* **Use Cases**:
|
|
760
|
+
* - Campaign landing pages with custom content
|
|
761
|
+
* - VIP customer experiences with dedicated projects
|
|
762
|
+
* - A/B testing specific pages without changing global config
|
|
763
|
+
* - Seasonal promotions with limited-time content
|
|
764
|
+
*
|
|
765
|
+
* **Validation**:
|
|
766
|
+
* - Must be non-empty string
|
|
767
|
+
* - Validated before API call
|
|
768
|
+
* - Falls back to client-level projectId if undefined
|
|
769
|
+
* - Does NOT support function (string only)
|
|
770
|
+
*
|
|
771
|
+
* **Cache Isolation**:
|
|
772
|
+
* Override projectId is included in cache key, ensuring separate caches
|
|
773
|
+
* for different projects even on the same route.
|
|
774
|
+
*
|
|
775
|
+
* @example Campaign page override
|
|
776
|
+
* ```ts
|
|
777
|
+
* const campaignData = await weaverse.loadPage({
|
|
778
|
+
* type: 'PAGE',
|
|
779
|
+
* handle: 'summer-sale',
|
|
780
|
+
* projectId: process.env.WEAVERSE_PROJECT_CAMPAIGN
|
|
781
|
+
* })
|
|
782
|
+
* ```
|
|
783
|
+
*/
|
|
784
|
+
projectId?: string;
|
|
785
|
+
};
|
|
786
|
+
/** A single translated field for one item. */
|
|
787
|
+
export interface TranslationMapEntry {
|
|
788
|
+
/** Source-locale value used to detect subsequent content changes. */
|
|
789
|
+
originalValue: string;
|
|
790
|
+
/** Localized value rendered for the target locale. */
|
|
791
|
+
translatedValue: string;
|
|
792
|
+
}
|
|
793
|
+
/** Per-item translation fields, keyed by field name */
|
|
794
|
+
export type TranslationItemEntry = {
|
|
795
|
+
/** Translation entry keyed by component field name. */
|
|
796
|
+
[key: string]: TranslationMapEntry;
|
|
797
|
+
};
|
|
798
|
+
/**
|
|
799
|
+
* Translation map sent from the builder alongside page data in design mode.
|
|
800
|
+
* Keyed by item ID, each value maps field names to translation entries.
|
|
801
|
+
*/
|
|
802
|
+
export type TranslationMap = {
|
|
803
|
+
/** Translated fields keyed by component instance identifier. */
|
|
804
|
+
[itemId: string]: TranslationItemEntry;
|
|
805
|
+
};
|
|
806
|
+
/** A single translation entry for save payloads. */
|
|
807
|
+
export interface TranslationEntry {
|
|
808
|
+
/** Marks an existing translation for deletion. */
|
|
809
|
+
deleted?: boolean;
|
|
810
|
+
/** Identifier of the component instance owning the field. */
|
|
811
|
+
itemId: string;
|
|
812
|
+
/** Dot-path to the translated component field. */
|
|
813
|
+
key: string;
|
|
814
|
+
/** Source-locale value used to detect content changes. */
|
|
815
|
+
originalValue: string;
|
|
816
|
+
/** Localized value to persist. */
|
|
817
|
+
translatedValue: string;
|
|
818
|
+
}
|
|
819
|
+
/** Result of collecting translation changes for the save flow */
|
|
820
|
+
export type TranslationChanges = {
|
|
821
|
+
/** Builder language identifier receiving the changes. */
|
|
822
|
+
languageId: string;
|
|
823
|
+
/** Translation entries to create, update, or delete. */
|
|
824
|
+
entries: TranslationEntry[];
|
|
825
|
+
};
|
|
826
|
+
//# sourceMappingURL=types.d.ts.map
|