@weaverse/hydrogen 5.25.0 → 6.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.
Files changed (80) hide show
  1. package/dist/index.js +23 -2444
  2. package/dist/index.mjs +4 -2407
  3. package/dist/internal.js +64 -0
  4. package/dist/internal.js.map +1 -0
  5. package/dist/internal.mjs +16 -0
  6. package/dist/internal.mjs.map +1 -0
  7. package/dist/next-server.js +14 -0
  8. package/dist/next-server.mjs +2 -0
  9. package/dist/next.js +119 -0
  10. package/dist/next.mjs +5 -0
  11. package/dist/react-router.js +68 -0
  12. package/dist/react-router.mjs +5 -0
  13. package/dist/react.js +26 -0
  14. package/dist/react.mjs +2 -0
  15. package/dist/translation-store-BpPWqZ0B.js +548 -0
  16. package/dist/translation-store-BpPWqZ0B.js.map +1 -0
  17. package/dist/translation-store-C42QdI0e.mjs +441 -0
  18. package/dist/translation-store-C42QdI0e.mjs.map +1 -0
  19. package/dist/types/WeaverseHydrogenRoot.d.ts +7 -7
  20. package/dist/types/WeaverseHydrogenRoot.d.ts.map +1 -1
  21. package/dist/types/components/index.d.ts +2 -2
  22. package/dist/types/components/main.d.ts +2 -2
  23. package/dist/types/hooks/translation-context.d.ts +2 -8
  24. package/dist/types/hooks/translation-context.d.ts.map +1 -1
  25. package/dist/types/index.d.ts +12 -33
  26. package/dist/types/index.d.ts.map +1 -1
  27. package/dist/types/internal.d.ts +24 -0
  28. package/dist/types/internal.d.ts.map +1 -0
  29. package/dist/types/next-server.d.ts +8 -0
  30. package/dist/types/next-server.d.ts.map +1 -0
  31. package/dist/types/next.d.ts +12 -0
  32. package/dist/types/next.d.ts.map +1 -0
  33. package/dist/types/react-router.d.ts +18 -0
  34. package/dist/types/react-router.d.ts.map +1 -0
  35. package/dist/types/react.d.ts +11 -0
  36. package/dist/types/react.d.ts.map +1 -0
  37. package/dist/types/seo.d.ts +4 -4
  38. package/dist/types/seo.d.ts.map +1 -1
  39. package/dist/types/types.d.ts +88 -68
  40. package/dist/types/types.d.ts.map +1 -1
  41. package/dist/types/utils/index.d.ts +4 -5
  42. package/dist/types/utils/index.d.ts.map +1 -1
  43. package/dist/types/utils/nested-key.d.ts +9 -0
  44. package/dist/types/utils/nested-key.d.ts.map +1 -0
  45. package/dist/types/utils/normalize-page-url.d.ts +1 -1
  46. package/dist/types/utils/product-options.d.ts +18 -0
  47. package/dist/types/utils/product-options.d.ts.map +1 -0
  48. package/dist/types/utils/use-studio.d.ts +1 -1
  49. package/dist/types/utils/use-studio.d.ts.map +1 -1
  50. package/dist/types/utils/use-theme-settings-store.d.ts +8 -8
  51. package/dist/types/utils/use-theme-settings-store.d.ts.map +1 -1
  52. package/dist/types/weaverse-client.d.ts +14 -16
  53. package/dist/types/weaverse-client.d.ts.map +1 -1
  54. package/dist/weaverse-client-Clu3u7md.mjs +1966 -0
  55. package/dist/weaverse-client-Clu3u7md.mjs.map +1 -0
  56. package/dist/weaverse-client-yC4TYuVV.js +2073 -0
  57. package/dist/weaverse-client-yC4TYuVV.js.map +1 -0
  58. package/package.json +44 -6
  59. package/readme.md +44 -24
  60. package/src/WeaverseHydrogenRoot.tsx +18 -15
  61. package/src/components/index.ts +2 -2
  62. package/src/components/main.tsx +2 -2
  63. package/src/hooks/translation-context.tsx +3 -28
  64. package/src/index.ts +42 -81
  65. package/src/internal.ts +64 -0
  66. package/src/next-server.ts +13 -0
  67. package/src/next.ts +35 -0
  68. package/src/react-router.ts +52 -0
  69. package/src/react.ts +16 -0
  70. package/src/seo.ts +5 -5
  71. package/src/types.ts +104 -74
  72. package/src/utils/index.ts +15 -14
  73. package/src/utils/nested-key.ts +28 -0
  74. package/src/utils/normalize-page-url.ts +1 -1
  75. package/src/utils/product-options.ts +28 -0
  76. package/src/utils/use-studio.ts +1 -1
  77. package/src/utils/use-theme-settings-store.ts +7 -7
  78. package/src/weaverse-client.ts +88 -96
  79. package/dist/index.js.map +0 -1
  80. package/dist/index.mjs.map +0 -1
package/src/types.ts CHANGED
@@ -1,12 +1,9 @@
1
1
  import type {
2
+ CacheInstance,
2
3
  CachingStrategy,
3
- HydrogenContext,
4
- I18nBase,
4
+ I18nConfig,
5
+ StorefrontClient,
5
6
  } from '@shopify/hydrogen'
6
- import type {
7
- AppLoadContext,
8
- LoaderFunctionArgs as RemixOxygenLoaderArgs,
9
- } from '@shopify/remix-oxygen'
10
7
  import type {
11
8
  ElementData,
12
9
  PositionInputValue,
@@ -38,7 +35,11 @@ import type {
38
35
  import { isValidSchema } from '@weaverse/schema'
39
36
  import type * as React from 'react'
40
37
  import type { ForwardRefExoticComponent } from 'react'
41
- import type { NavigateFunction } from 'react-router'
38
+ import type {
39
+ AppLoadContext,
40
+ LoaderFunctionArgs,
41
+ NavigateFunction,
42
+ } from 'react-router'
42
43
  import type { TranslationStore } from './utils/translation-store'
43
44
  import type { ThemeSettingsStore } from './utils/use-theme-settings-store'
44
45
  import type { WeaverseHydrogen } from './WeaverseHydrogenRoot'
@@ -65,7 +66,7 @@ export type {
65
66
  }
66
67
 
67
68
  /** Arguments passed to a component's server-side loader. */
68
- export type ComponentLoaderArgs<T = any, _E = any> = {
69
+ export type WeaverseComponentLoaderArgs<T = any, _E = any> = {
69
70
  /** Persisted component data merged with schema defaults. */
70
71
  data: T
71
72
  /** Request-scoped client available to the component loader. */
@@ -79,7 +80,7 @@ export interface WeaverseRouteAppLoadContext extends AppLoadContext {
79
80
  }
80
81
 
81
82
  /** React Router loader arguments whose app context includes the Weaverse client. */
82
- export interface RouteLoaderArgs extends RemixOxygenLoaderArgs {
83
+ export interface RouteLoaderArgs extends LoaderFunctionArgs {
83
84
  /** Request-scoped application context with the initialized Weaverse client. */
84
85
  context: WeaverseRouteAppLoadContext
85
86
  }
@@ -88,15 +89,15 @@ export interface RouteLoaderArgs extends RemixOxygenLoaderArgs {
88
89
  export type ComponentDataValue = string | number | boolean | undefined | null
89
90
 
90
91
  /** Reference to a direct child component instance. */
91
- export interface HydrogenChildComponentReference {
92
+ export interface WeaverseChildComponentReference {
92
93
  /** Unique identifier of the child component instance. */
93
94
  id: string
94
95
  }
95
96
 
96
97
  /** Serialized component instance returned in a Weaverse page. */
97
- export interface HydrogenComponentData extends ElementData {
98
+ export interface WeaverseComponentData extends ElementData {
98
99
  /** References to direct child component instances. */
99
- children?: HydrogenChildComponentReference[]
100
+ children?: WeaverseChildComponentReference[]
100
101
  /** ISO timestamp recording when the component instance was created. */
101
102
  createdAt?: string
102
103
  /** Persisted component setting values and structured payloads. */
@@ -115,10 +116,10 @@ export interface HydrogenComponentData extends ElementData {
115
116
  * Optimized: Use Zod-inferred SchemaType directly instead of extending
116
117
  * This ensures perfect type consistency with the schema validation
117
118
  */
118
- export type HydrogenComponentSchema = SchemaType
119
+ export type WeaverseComponentSchema = SchemaType
119
120
 
120
121
  /** Props supplied by Weaverse when rendering a registered Hydrogen component. */
121
- export interface HydrogenComponentProps<L = any> extends WeaverseElement {
122
+ export interface WeaverseComponentProps<L = any> extends WeaverseElement {
122
123
  /** Rendered child component instances. */
123
124
  children?: React.JSX.Element[]
124
125
  /** Optional CSS class passed through by the renderer. */
@@ -143,13 +144,13 @@ export type WeaverseLoaderRequestInfo = {
143
144
  }
144
145
 
145
146
  /** Published theme setting values keyed by schema setting name. */
146
- export type HydrogenThemeSettings = {
147
+ export type WeaverseThemeSettings = {
147
148
  /** Published theme setting value keyed by schema setting name. */
148
149
  [key: string]: any
149
150
  }
150
151
 
151
152
  /** Project metadata returned with a Weaverse page payload. */
152
- export type HydrogenProjectType = {
153
+ export type WeaverseProjectType = {
153
154
  /** Unique Weaverse project identifier. */
154
155
  id: string
155
156
  /** Identifier of the Shopify shop connected to the project. */
@@ -163,9 +164,9 @@ export type HydrogenProjectType = {
163
164
  /** Runtime services and project metadata exposed to Weaverse integrations. */
164
165
  export type WeaverseInternal = {
165
166
  /** Route assignment for the rendered Weaverse page. */
166
- pageAssignment: HydrogenPageAssignment
167
+ pageAssignment: WeaversePageAssignment
167
168
  /** Metadata for the active Weaverse project. */
168
- project: HydrogenProjectType
169
+ project: WeaverseProjectType
169
170
  /** React Router navigation function, attached in design mode. */
170
171
  navigate: NavigateFunction
171
172
  /** Revalidates the active React Router data routes. */
@@ -189,21 +190,21 @@ export type HydrogenComponentPresets = SchemaComponentPresets
189
190
  export type HydrogenElement = {
190
191
  /** React renderer for this registered component type. */
191
192
  Component:
192
- | ForwardRefExoticComponent<HydrogenComponentProps>
193
- | ((props: HydrogenComponentProps) => React.JSX.Element)
193
+ | ForwardRefExoticComponent<WeaverseComponentProps>
194
+ | ((props: WeaverseComponentProps) => React.JSX.Element)
194
195
  /** Unique component type matching the component schema. */
195
196
  type: string
196
197
  /** Component schema used for settings, defaults, and availability. */
197
- schema?: HydrogenComponentSchema
198
+ schema?: WeaverseComponentSchema
198
199
  /** Optional data loader function for server-side data fetching. */
199
- loader?: (args: ComponentLoaderArgs) => Promise<unknown>
200
+ loader?: (args: WeaverseComponentLoaderArgs) => Promise<unknown>
200
201
  }
201
202
 
202
203
  /** Initialization parameters for a request-scoped {@link WeaverseHydrogen} runtime. */
203
204
  export interface WeaverseHydrogenParams
204
205
  extends Omit<WeaverseCoreParams, 'ItemConstructor'> {
205
206
  /** Page content used to initialize component instances. */
206
- data: HydrogenPageData
207
+ data: WeaversePageData
207
208
  /** Route loader data made available to component data bindings. */
208
209
  dataContext?: Record<string, unknown> | null
209
210
  /** Runtime services and metadata available to integrations. */
@@ -242,13 +243,13 @@ export interface WeaverseHydrogenParams
242
243
  }
243
244
 
244
245
  /** Export shape for a renderable component, its schema, and optional loader. */
245
- export type HydrogenComponent<T extends HydrogenComponentProps = any> = {
246
+ export type WeaverseComponent<T extends WeaverseComponentProps = any> = {
246
247
  /** React renderer exported by the component module. */
247
248
  default: ForwardRefExoticComponent<T> | ((props: T) => React.JSX.Element)
248
249
  /** Schema exported by the component module. */
249
- schema: HydrogenComponentSchema
250
+ schema: WeaverseComponentSchema
250
251
  /** Optional data loader function for server-side data fetching. */
251
- loader?: (args: ComponentLoaderArgs) => Promise<unknown>
252
+ loader?: (args: WeaverseComponentLoaderArgs) => Promise<unknown>
252
253
  }
253
254
 
254
255
  /** Weaverse Studio query parameters recognized by the Hydrogen runtime. */
@@ -307,7 +308,7 @@ export type WeaverseProjectConfigs = {
307
308
  }
308
309
 
309
310
  /** Assignment describing which project page handles a storefront route. */
310
- export type HydrogenPageAssignment = {
311
+ export type WeaversePageAssignment = {
311
312
  /** Project identifier owning the assigned page. */
312
313
  projectId: string
313
314
  /** Storefront page type matched by the assignment. */
@@ -327,7 +328,7 @@ export type HydrogenPageAssignment = {
327
328
  }
328
329
  }
329
330
 
330
- /** Complete payload returned by {@link WeaverseClient.loadPage}. */
331
+ /** Complete payload returned by `WeaverseClient.loadPage()`. */
331
332
  export type WeaverseLoaderData = {
332
333
  /** Resolved runtime configuration and normalized request details. */
333
334
  configs: Omit<WeaverseProjectConfigs, 'publicEnv'> & {
@@ -335,21 +336,21 @@ export type WeaverseLoaderData = {
335
336
  requestInfo: WeaverseLoaderRequestInfo
336
337
  }
337
338
  /** Published page content to render. */
338
- page: HydrogenPageData
339
+ page: WeaversePageData
339
340
  /** Metadata for the project supplying the page. */
340
- project: HydrogenProjectType
341
+ project: WeaverseProjectType
341
342
  /** Route assignment that selected the page, when available. */
342
- pageAssignment?: HydrogenPageAssignment
343
+ pageAssignment?: WeaversePageAssignment
343
344
  }
344
345
 
345
346
  /** Published Weaverse page content consumed by the Hydrogen renderer. */
346
- export interface HydrogenPageData extends WeaverseProjectDataType {
347
+ export interface WeaversePageData extends WeaverseProjectDataType {
347
348
  /** Internal cache identifier attached by the content API when available. */
348
349
  __cacheId?: string
349
350
  /** Unique page identifier. */
350
351
  id: string
351
352
  /** Serialized component instances belonging to the page. */
352
- items: HydrogenComponentData[]
353
+ items: WeaverseComponentData[]
353
354
  /** Human-readable page name. */
354
355
  name: string
355
356
  /**
@@ -364,7 +365,7 @@ export interface HydrogenPageData extends WeaverseProjectDataType {
364
365
  }
365
366
 
366
367
  /** Locale metadata used when requesting localized Weaverse content. */
367
- export type WeaverseI18n = I18nBase & {
368
+ export type WeaverseI18n = I18nConfig & {
368
369
  /** Human-readable locale label displayed in Studio. */
369
370
  label?: string
370
371
  /** Locale path prefix used by the storefront router. */
@@ -374,7 +375,7 @@ export type WeaverseI18n = I18nBase & {
374
375
  }
375
376
 
376
377
  /** Theme metadata, global settings, and localization configuration. */
377
- export type HydrogenThemeSchema = {
378
+ export type WeaverseThemeSchema = {
378
379
  /** Theme identity, author, and support metadata. */
379
380
  info: {
380
381
  /** Human-readable theme name. */
@@ -463,11 +464,11 @@ export type FetchProjectRequestBody = {
463
464
  /** Project content response before it is normalized into loader data. */
464
465
  export type FetchProjectPayload = {
465
466
  /** Published or draft page content; absent when no page matches. */
466
- page?: HydrogenPageData
467
+ page?: WeaversePageData
467
468
  /** Project metadata; absent in some error responses. */
468
- project?: HydrogenProjectType
469
+ project?: WeaverseProjectType
469
470
  /** Assignment that selected the page, when one matched. */
470
- pageAssignment?: HydrogenPageAssignment
471
+ pageAssignment?: WeaversePageAssignment
471
472
  /** API error message, when the request could not be fulfilled. */
472
473
  error?: string
473
474
  /** Additional fields returned by compatible API versions. */
@@ -552,18 +553,36 @@ export function isProjectIdFunction(
552
553
  * **Request Context Access**:
553
554
  * Functions access request via closure from constructor arguments.
554
555
  */
555
- export type WeaverseClientArgs = HydrogenContext & {
556
+ export type WeaverseClientArgs = {
557
+ /**
558
+ * Request-scoped Hydrogen Storefront API client. Section loaders reach it
559
+ * as `weaverse.storefront`; its `i18n` selects the content locale.
560
+ */
561
+ storefront: WeaverseStorefront
562
+
563
+ /** Runtime environment variables, such as the Oxygen worker `env`. */
564
+ env: WeaverseEnv
565
+
566
+ /** Keeps the runtime alive for background cache writes and refreshes. */
567
+ waitUntil?: (promise: Promise<unknown>) => void
568
+
569
+ /**
570
+ * Customer Account API client, when the storefront has one. Weaverse only
571
+ * passes it through to section loaders.
572
+ */
573
+ customerAccount?: unknown
574
+
556
575
  /**
557
576
  * React components registered with Weaverse CMS.
558
577
  * Each component must have a schema defining its properties and settings.
559
578
  */
560
- components: HydrogenComponent[]
579
+ components: WeaverseComponent[]
561
580
 
562
581
  /**
563
582
  * Theme schema defining global theme settings (colors, fonts, layouts).
564
583
  * Used to generate default theme configuration and validate theme data.
565
584
  */
566
- themeSchema: HydrogenThemeSchema
585
+ themeSchema: WeaverseThemeSchema
567
586
 
568
587
  /**
569
588
  * Incoming HTTP request object from React Router loader.
@@ -572,10 +591,10 @@ export type WeaverseClientArgs = HydrogenContext & {
572
591
  request: Request
573
592
 
574
593
  /**
575
- * Hydrogen cache instance for content caching.
576
- *Supports multi-tenant caching with project-specific cache keys.
594
+ * Hydrogen cache instance for content caching, such as the worker's
595
+ * `caches.open('hydrogen-v1')`. Cache keys include the project ID.
577
596
  */
578
- cache: Cache
597
+ cache: CacheInstance
579
598
 
580
599
  /**
581
600
  * Project identifier for loading content from Weaverse CMS.
@@ -626,6 +645,33 @@ export type WeaverseClientArgs = HydrogenContext & {
626
645
  throwPageLoadFailures?: boolean
627
646
  }
628
647
 
648
+ /** Per-call options the storefront client accepts in addition to Hydrogen's. */
649
+ export type WeaverseStorefrontCallOptions = {
650
+ /** Caching strategy for this Storefront API request. */
651
+ cache?: CachingStrategy
652
+ }
653
+
654
+ /** Storefront API client accepted by `WeaverseClient`, with a per-call `cache` option. */
655
+ export type WeaverseStorefront = StorefrontClient<WeaverseStorefrontCallOptions>
656
+
657
+ /** Environment variables read by Weaverse, plus any other storefront variables. */
658
+ export interface WeaverseEnv {
659
+ /** Shopify store domain exposed to Studio. */
660
+ PUBLIC_STORE_DOMAIN?: string
661
+ /** Public Storefront API token exposed to Studio. */
662
+ PUBLIC_STOREFRONT_API_TOKEN?: string
663
+ /** Weaverse API key. */
664
+ WEAVERSE_API_KEY?: string
665
+ /** Weaverse Studio host, e.g. `https://studio.weaverse.io`. */
666
+ WEAVERSE_HOST?: string
667
+ /** Default Weaverse project ID. */
668
+ WEAVERSE_PROJECT_ID?: string
669
+ /** Base URL of the Weaverse public content API. */
670
+ WEAVERSE_PUBLIC_API_BASE?: string
671
+ /** Any other storefront variable. */
672
+ [key: string]: string | undefined
673
+ }
674
+
629
675
  /** Product selected through a Weaverse resource-picker setting. */
630
676
  export type WeaverseProduct = WeaverseResourcePickerData
631
677
  /** Collection selected through a Weaverse resource-picker setting. */
@@ -646,11 +692,11 @@ export type WithCacheFetchResponse<T> = {
646
692
  }
647
693
 
648
694
  /** Theme configuration returned by the Weaverse project API. */
649
- export type ThemeSettingsResponse = {
695
+ export type WeaverseThemeSettingsResponse = {
650
696
  /** Published theme setting values. */
651
- theme?: HydrogenThemeSettings
697
+ theme?: WeaverseThemeSettings
652
698
  /** Theme schema included for Studio editing. */
653
- schema?: HydrogenThemeSchema
699
+ schema?: WeaverseThemeSchema
654
700
  /** Storefront-safe environment values included in design mode. */
655
701
  publicEnv?: PublicEnv
656
702
  /** Theme's default locale JSON from `themeSchema.i18n.staticContent`. */
@@ -728,7 +774,7 @@ export type WeaverseLoadFailureKind =
728
774
  | 'configuration'
729
775
 
730
776
  /**
731
- * Error thrown by {@link WeaverseClient.loadPage} when the client is created
777
+ * Error thrown by `WeaverseClient.loadPage()` when the client is created
732
778
  * with `throwPageLoadFailures: true` and the page cannot be loaded.
733
779
  *
734
780
  * Genuine absence is not an error: a missing project still resolves to `null`
@@ -825,7 +871,7 @@ export function hasError(response: unknown): response is WeaverseErrorResponse {
825
871
  /** Checks whether a value contains a theme settings object. */
826
872
  export function isThemeSettingsResponse(
827
873
  data: unknown
828
- ): data is ThemeSettingsResponse {
874
+ ): data is WeaverseThemeSettingsResponse {
829
875
  if (typeof data !== 'object' || data === null) {
830
876
  return false
831
877
  }
@@ -842,7 +888,7 @@ export function isThemeSettingsResponse(
842
888
  * Enhanced type utilities for better development experience
843
889
  */
844
890
  export type HydrogenSchemaValidationResult =
845
- SchemaValidationResult<HydrogenComponentSchema>
891
+ SchemaValidationResult<WeaverseComponentSchema>
846
892
 
847
893
  /**
848
894
  * Type guard to check if a schema is valid.
@@ -850,19 +896,19 @@ export type HydrogenSchemaValidationResult =
850
896
  * comprehensive Zod-based validation with the ElementSchema.
851
897
  *
852
898
  * @param schema - Unknown value to validate
853
- * @returns True if schema is a valid HydrogenComponentSchema
899
+ * @returns True if schema is a valid WeaverseComponentSchema
854
900
  *
855
901
  * @example
856
902
  * ```typescript
857
903
  * if (isValidHydrogenSchema(userInput)) {
858
- * // userInput is now typed as HydrogenComponentSchema
904
+ * // userInput is now typed as WeaverseComponentSchema
859
905
  * console.log(userInput.type)
860
906
  * }
861
907
  * ```
862
908
  */
863
909
  export function isValidHydrogenSchema(
864
910
  schema: unknown
865
- ): schema is HydrogenComponentSchema {
911
+ ): schema is WeaverseComponentSchema {
866
912
  // Use the comprehensive validation from @weaverse/schema package
867
913
  return isValidSchema(schema)
868
914
  }
@@ -905,10 +951,10 @@ export type CreateHydrogenSchemaOptions = {
905
951
  }
906
952
 
907
953
  // Extended window interface for hydrogen-specific globals
954
+ // `__weaverse`/`__weaverses` are typed where they are used: the Next.js
955
+ // adapter declares the same globals with its own runtime type.
908
956
  declare global {
909
957
  interface Window {
910
- __weaverse?: WeaverseHydrogen
911
- __weaverses?: Record<string, WeaverseHydrogen>
912
958
  __weaverseThemeSettingsStore?: ThemeSettingsStore
913
959
  }
914
960
  }
@@ -934,28 +980,12 @@ export function hasWeaverseStudio(
934
980
  return 'weaverseStudio' in window && typeof window.weaverseStudio === 'object'
935
981
  }
936
982
 
937
- declare module '@shopify/remix-oxygen' {
983
+ declare module 'react-router' {
938
984
  interface AppLoadContext {
939
985
  weaverse: WeaverseClient
940
986
  }
941
- }
942
-
943
- declare module '@shopify/hydrogen' {
944
- interface HydrogenEnv {
945
- CUSTOM_COLLECTION_BANNER_METAFIELD: string
946
- JUDGEME_PRIVATE_API_TOKEN: string
947
- KLAVIYO_PRIVATE_API_TOKEN: string
948
- METAOBJECT_COLOR_NAME_KEY: string
949
- METAOBJECT_COLOR_VALUE_KEY: string
950
- METAOBJECT_COLORS_TYPE: string
951
- PUBLIC_GOOGLE_GTM_ID: string
952
- PUBLIC_SHOPIFY_INBOX_SHOP_ID: string
953
- PUBLIC_STORE_DOMAIN: string
954
- PUBLIC_STOREFRONT_API_TOKEN: string
955
- WEAVERSE_API_KEY: string
956
- WEAVERSE_HOST?: string
957
- WEAVERSE_PROJECT_ID: string
958
- WEAVERSE_PUBLIC_API_BASE?: string
987
+ interface RouterContextProvider {
988
+ weaverse: WeaverseClient
959
989
  }
960
990
  }
961
991
 
@@ -1,11 +1,11 @@
1
- import type { HydrogenEnv } from '@shopify/hydrogen'
2
1
  import type {
3
- HydrogenComponent,
4
- HydrogenComponentSchema,
5
- HydrogenThemeSchema,
2
+ WeaverseComponent,
3
+ WeaverseComponentSchema,
4
+ WeaverseEnv,
6
5
  WeaverseLoaderData,
7
6
  WeaverseProjectConfigs,
8
7
  WeaverseStudioQueries,
8
+ WeaverseThemeSchema,
9
9
  } from '../types'
10
10
  import { isTrustedStudioHost } from './studio-script-src'
11
11
 
@@ -101,7 +101,7 @@ export function getRequestQueries<T = Record<string, string | boolean>>(
101
101
  */
102
102
  export function getWeaverseConfigs(
103
103
  request: Request,
104
- env: HydrogenEnv
104
+ env: WeaverseEnv
105
105
  ): WeaverseProjectConfigs {
106
106
  let queries = getRequestQueries<WeaverseStudioQueries>(request)
107
107
  let {
@@ -112,7 +112,8 @@ export function getWeaverseConfigs(
112
112
  PUBLIC_STORE_DOMAIN,
113
113
  PUBLIC_STOREFRONT_API_TOKEN,
114
114
  } = env || {}
115
- let envFromProcess = (typeof process !== 'undefined' && process.env) || {}
115
+ let envFromProcess: WeaverseEnv =
116
+ (typeof process !== 'undefined' && process.env) || {}
116
117
  let {
117
118
  weaverseProjectId,
118
119
  weaverseHost,
@@ -180,7 +181,7 @@ export function getWeaverseConfigs(
180
181
  * WeakMap allows garbage collection when schema objects are no longer referenced.
181
182
  */
182
183
  const schemaDefaultsCache = new WeakMap<
183
- HydrogenComponentSchema | HydrogenThemeSchema,
184
+ WeaverseComponentSchema | WeaverseThemeSchema,
184
185
  Record<string, any>
185
186
  >()
186
187
 
@@ -192,7 +193,7 @@ const schemaDefaultsCache = new WeakMap<
192
193
  * @returns Default data object extracted from schema inputs
193
194
  */
194
195
  export function generateDataFromSchema(
195
- schema: HydrogenComponentSchema | HydrogenThemeSchema
196
+ schema: WeaverseComponentSchema | WeaverseThemeSchema
196
197
  ) {
197
198
  // Check cache first for performance
198
199
  const cached = schemaDefaultsCache.get(schema)
@@ -207,11 +208,11 @@ export function generateDataFromSchema(
207
208
 
208
209
  // Type guard to check if it's a component schema
209
210
  const isComponentSchema = (
210
- s: HydrogenComponentSchema | HydrogenThemeSchema
211
- ): s is HydrogenComponentSchema => 'type' in s && typeof s.type === 'string'
211
+ s: WeaverseComponentSchema | WeaverseThemeSchema
212
+ ): s is WeaverseComponentSchema => 'type' in s && typeof s.type === 'string'
212
213
 
213
214
  if (isComponentSchema(schema)) {
214
- // Handle HydrogenComponentSchema
215
+ // Handle WeaverseComponentSchema
215
216
  if (schema.settings) {
216
217
  inspectorGroups = schema.settings
217
218
  }
@@ -236,7 +237,7 @@ export function generateDataFromSchema(
236
237
  }
237
238
  }
238
239
  } else {
239
- // Handle HydrogenThemeSchema
240
+ // Handle WeaverseThemeSchema
240
241
  if (schema.settings) {
241
242
  inspectorGroups = schema.settings
242
243
  }
@@ -279,7 +280,7 @@ export function generateDataFromSchema(
279
280
 
280
281
  function recursivelyAddDataItem(
281
282
  type: string,
282
- components: HydrogenComponent<any>[],
283
+ components: WeaverseComponent<any>[],
283
284
  items: any[],
284
285
  initData?: object
285
286
  ) {
@@ -309,7 +310,7 @@ function recursivelyAddDataItem(
309
310
  /** Creates synthetic loader data for previewing one registered component type. */
310
311
  export function getPreviewData(
311
312
  type: string,
312
- components: HydrogenComponent[],
313
+ components: WeaverseComponent[],
313
314
  weaverseHost: string
314
315
  ) {
315
316
  let items = []
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Traverse a nested object by dot-path.
3
+ *
4
+ * @example
5
+ * getNestedKey({ cart: { title: 'Cart' } }, 'cart.title') // => 'Cart'
6
+ * getNestedKey({}, 'cart.title', 'fallback') // => 'fallback'
7
+ */
8
+ export function getNestedKey(
9
+ obj: Record<string, unknown>,
10
+ path: string,
11
+ fallback?: string
12
+ ): string | undefined {
13
+ const keys = path.split('.')
14
+ let current: unknown = obj
15
+
16
+ for (const key of keys) {
17
+ if (current == null || typeof current !== 'object') {
18
+ return fallback
19
+ }
20
+ current = (current as Record<string, unknown>)[key]
21
+ }
22
+
23
+ if (typeof current === 'string') {
24
+ return current
25
+ }
26
+
27
+ return fallback
28
+ }
@@ -7,7 +7,7 @@ const KEPT_PARAM_RE = /^(?:__revisionId|isDesignMode|weaverse)/
7
7
  /**
8
8
  * Normalize the storefront URL sent in the Builder page API request body.
9
9
  *
10
- * The POST body participates in the `withCache` cache key, so a raw
10
+ * The POST body participates in Hydrogen's cached fetch key, so a raw
11
11
  * `request.url` fragments the cache by every marketing/tracking param:
12
12
  * each distinct `?utm_…`/`fbclid` URL is a guaranteed Builder round-trip
13
13
  * even when the resolved page is identical — precisely the paid/social
@@ -0,0 +1,28 @@
1
+ import {
2
+ getSelectedProductOptions as hydrogen_getSelectedProductOptions,
3
+ type SelectedOption,
4
+ } from '@shopify/hydrogen'
5
+
6
+ /**
7
+ * Filter out Weaverse-specific query parameters from product options.
8
+ * Removes `isDesignMode` and any parameters starting with `weaverse` prefix.
9
+ *
10
+ * @param request - The incoming HTTP request
11
+ * @returns Filtered product options for Shopify Hydrogen
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * export async function loader({ request }: LoaderFunctionArgs) {
16
+ * const selectedOptions = getSelectedProductOptions(request)
17
+ * // Use selectedOptions for product queries without Weaverse params
18
+ * }
19
+ * ```
20
+ */
21
+ export function getSelectedProductOptions(request: Request): SelectedOption[] {
22
+ let options = hydrogen_getSelectedProductOptions({
23
+ searchParams: new URL(request.url).searchParams,
24
+ })
25
+ return options.filter(
26
+ ({ name }) => name !== 'isDesignMode' && !name.startsWith('weaverse')
27
+ )
28
+ }
@@ -7,7 +7,7 @@ import {
7
7
  useRevalidator,
8
8
  } from 'react-router'
9
9
  import { useTranslation } from '../hooks/translation-context'
10
- import type { WeaverseHydrogen } from '../index'
10
+ import type { WeaverseHydrogen } from '../internal'
11
11
  import { hasWeaverseStudio } from '../types'
12
12
  import { getStudioScriptSrc, resolveStudioScriptSrc } from './studio-script-src'
13
13
  import { useThemeSettingsStore } from './use-theme-settings-store'
@@ -2,9 +2,9 @@ import { isBrowser } from '@weaverse/react'
2
2
  import { createContext, useContext, useEffect, useRef } from 'react'
3
3
  import { useRouteLoaderData } from 'react-router'
4
4
  import type {
5
- HydrogenThemeSchema,
6
- HydrogenThemeSettings,
7
5
  PublicEnv,
6
+ WeaverseThemeSchema,
7
+ WeaverseThemeSettings,
8
8
  } from '../types'
9
9
 
10
10
  /** Root-loader theme data used to initialize a {@link ThemeSettingsStore}. */
@@ -12,17 +12,17 @@ export interface WeaverseThemeData {
12
12
  /** Storefront-safe environment values, when available. */
13
13
  publicEnv?: PublicEnv
14
14
  /** Theme schema exposed to Studio, when available. */
15
- schema?: HydrogenThemeSchema
15
+ schema?: WeaverseThemeSchema
16
16
  /** Published theme setting values. */
17
- theme: HydrogenThemeSettings
17
+ theme: WeaverseThemeSettings
18
18
  }
19
19
 
20
20
  /** Mutable, subscribable store for theme settings received from the root loader. */
21
21
  export class ThemeSettingsStore {
22
22
  /** Current merged theme setting values. */
23
- settings: HydrogenThemeSettings = {}
23
+ settings: WeaverseThemeSettings = {}
24
24
  /** Theme schema exposed to Studio, when available. */
25
- schema?: HydrogenThemeSchema
25
+ schema?: WeaverseThemeSchema
26
26
  /** Storefront-safe environment values, when available. */
27
27
  publicEnv?: PublicEnv
28
28
  private listeners: Set<() => void> = new Set()
@@ -41,7 +41,7 @@ export class ThemeSettingsStore {
41
41
  }
42
42
 
43
43
  /** Merges setting changes into the current snapshot and notifies subscribers. */
44
- updateThemeSettings = (newSettings: HydrogenThemeSettings) => {
44
+ updateThemeSettings = (newSettings: WeaverseThemeSettings) => {
45
45
  if (this.isDestroyed) {
46
46
  console.warn('ThemeSettingsStore: Cannot update destroyed store')
47
47
  return