@shopify/hydrogen 0.15.0 → 0.17.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 (140) hide show
  1. package/CHANGELOG.md +113 -1
  2. package/dist/esnext/FileSessionStorage.d.ts +1 -0
  3. package/dist/esnext/FileSessionStorage.js +1 -0
  4. package/dist/esnext/client.d.ts +3 -2
  5. package/dist/esnext/client.js +3 -2
  6. package/dist/esnext/components/CartProvider/CartProvider.client.d.ts +1 -1
  7. package/dist/esnext/components/CartProvider/CartProvider.client.js +3 -3
  8. package/dist/esnext/components/ExternalVideo/ExternalVideo.d.ts +2 -2
  9. package/dist/esnext/components/ExternalVideo/ExternalVideo.js +1 -1
  10. package/dist/esnext/components/Image/Image.d.ts +2 -2
  11. package/dist/esnext/components/Image/Image.js +1 -1
  12. package/dist/esnext/components/Link/Link.client.d.ts +1 -1
  13. package/dist/esnext/components/Link/Link.client.js +3 -3
  14. package/dist/esnext/components/LocalizationProvider/LocalizationClientProvider.client.js +4 -4
  15. package/dist/esnext/components/LocalizationProvider/LocalizationProvider.server.d.ts +2 -2
  16. package/dist/esnext/components/LocalizationProvider/LocalizationProvider.server.js +2 -2
  17. package/dist/esnext/components/MediaFile/MediaFile.d.ts +2 -2
  18. package/dist/esnext/components/MediaFile/MediaFile.js +1 -1
  19. package/dist/esnext/components/Metafield/Metafield.client.d.ts +8 -4
  20. package/dist/esnext/components/Metafield/Metafield.client.js +6 -2
  21. package/dist/esnext/components/ModelViewer/ModelViewer.client.d.ts +3 -3
  22. package/dist/esnext/components/ModelViewer/ModelViewer.client.js +1 -1
  23. package/dist/esnext/components/Money/Money.client.d.ts +2 -2
  24. package/dist/esnext/components/Money/Money.client.js +1 -1
  25. package/dist/esnext/components/ProductDescription/ProductDescription.client.d.ts +1 -1
  26. package/dist/esnext/components/ProductDescription/ProductDescription.client.js +1 -1
  27. package/dist/esnext/components/ProductMetafield/ProductMetafield.client.d.ts +3 -3
  28. package/dist/esnext/components/ProductMetafield/ProductMetafield.client.js +1 -1
  29. package/dist/esnext/components/ProductPrice/ProductPrice.client.d.ts +1 -1
  30. package/dist/esnext/components/ProductPrice/ProductPrice.client.js +1 -1
  31. package/dist/esnext/components/ProductProvider/ProductProvider.client.d.ts +1 -1
  32. package/dist/esnext/components/ProductTitle/ProductTitle.client.d.ts +1 -1
  33. package/dist/esnext/components/ProductTitle/ProductTitle.client.js +1 -1
  34. package/dist/esnext/components/UnitPrice/UnitPrice.client.d.ts +4 -4
  35. package/dist/esnext/components/UnitPrice/UnitPrice.client.js +2 -2
  36. package/dist/esnext/components/Video/Video.d.ts +2 -2
  37. package/dist/esnext/components/Video/Video.js +1 -1
  38. package/dist/esnext/constants.d.ts +4 -0
  39. package/dist/esnext/constants.js +4 -0
  40. package/dist/esnext/entry-client.js +4 -4
  41. package/dist/esnext/entry-server.d.ts +1 -1
  42. package/dist/esnext/entry-server.js +12 -5
  43. package/dist/esnext/foundation/Analytics/Analytics.server.js +4 -2
  44. package/dist/esnext/foundation/AnalyticsErrorBoundary.client.d.ts +4 -0
  45. package/dist/esnext/foundation/AnalyticsErrorBoundary.client.js +8 -0
  46. package/dist/esnext/foundation/Cookie/Cookie.d.ts +48 -0
  47. package/dist/esnext/foundation/Cookie/Cookie.js +66 -0
  48. package/dist/esnext/foundation/CookieSessionStorage/CookieSessionStorage.d.ts +5 -0
  49. package/dist/esnext/foundation/CookieSessionStorage/CookieSessionStorage.js +31 -0
  50. package/dist/esnext/foundation/FileSessionStorage/FileSessionStorage.d.ts +6 -0
  51. package/dist/esnext/foundation/FileSessionStorage/FileSessionStorage.js +148 -0
  52. package/dist/esnext/foundation/MemorySessionStorage/MemorySessionStorage.d.ts +5 -0
  53. package/dist/esnext/foundation/MemorySessionStorage/MemorySessionStorage.js +53 -0
  54. package/dist/esnext/foundation/Router/BrowserRouter.client.js +8 -8
  55. package/dist/esnext/foundation/ServerPropsProvider/ServerPropsProvider.d.ts +40 -0
  56. package/dist/esnext/foundation/ServerPropsProvider/ServerPropsProvider.js +76 -0
  57. package/dist/esnext/foundation/ServerPropsProvider/index.d.ts +2 -0
  58. package/dist/esnext/foundation/ServerPropsProvider/index.js +1 -0
  59. package/dist/esnext/foundation/index.d.ts +1 -1
  60. package/dist/esnext/foundation/index.js +1 -1
  61. package/dist/esnext/foundation/session/session.d.ts +27 -0
  62. package/dist/esnext/foundation/session/session.js +37 -0
  63. package/dist/esnext/foundation/useQuery/hooks.d.ts +3 -3
  64. package/dist/esnext/foundation/useQuery/hooks.js +1 -1
  65. package/dist/esnext/foundation/useServerProps/index.d.ts +1 -0
  66. package/dist/esnext/foundation/useServerProps/index.js +1 -0
  67. package/dist/esnext/foundation/useServerProps/use-server-props.d.ts +21 -0
  68. package/dist/esnext/foundation/useServerProps/use-server-props.js +35 -0
  69. package/dist/esnext/foundation/useSession/useSession.d.ts +2 -0
  70. package/dist/esnext/foundation/useSession/useSession.js +8 -0
  71. package/dist/esnext/foundation/useUrl/useUrl.js +8 -1
  72. package/dist/esnext/framework/Hydration/ServerComponentRequest.server.d.ts +2 -0
  73. package/dist/esnext/framework/plugins/vite-plugin-hydrogen-config.js +27 -12
  74. package/dist/esnext/hooks/useMoney/hooks.d.ts +1 -1
  75. package/dist/esnext/hooks/useMoney/hooks.js +1 -1
  76. package/dist/esnext/hooks/useParsedMetafields/useParsedMetafields.d.ts +2 -2
  77. package/dist/esnext/hooks/useParsedMetafields/useParsedMetafields.js +2 -2
  78. package/dist/esnext/hooks/useShopQuery/hooks.d.ts +2 -2
  79. package/dist/esnext/hooks/useShopQuery/hooks.js +5 -17
  80. package/dist/esnext/index.d.ts +4 -0
  81. package/dist/esnext/index.js +4 -0
  82. package/dist/esnext/storefront-api-types.d.ts +31 -13
  83. package/dist/esnext/storefront-api-types.js +14 -2
  84. package/dist/esnext/types.d.ts +2 -0
  85. package/dist/esnext/utilities/apiRoutes.d.ts +4 -3
  86. package/dist/esnext/utilities/apiRoutes.js +35 -8
  87. package/dist/esnext/utilities/flattenConnection/flattenConnection.d.ts +1 -1
  88. package/dist/esnext/utilities/flattenConnection/flattenConnection.js +1 -1
  89. package/dist/esnext/utilities/parseMetafieldValue/parseMetafieldValue.d.ts +1 -1
  90. package/dist/esnext/utilities/parseMetafieldValue/parseMetafieldValue.js +1 -1
  91. package/dist/esnext/utilities/storefrontApi.d.ts +4 -0
  92. package/dist/esnext/utilities/storefrontApi.js +21 -0
  93. package/dist/esnext/version.d.ts +1 -1
  94. package/dist/esnext/version.js +1 -1
  95. package/dist/node/constants.d.ts +4 -0
  96. package/dist/node/constants.js +5 -1
  97. package/dist/node/entry-server.d.ts +1 -1
  98. package/dist/node/entry-server.js +12 -5
  99. package/dist/node/foundation/Analytics/Analytics.server.js +27 -2
  100. package/dist/node/foundation/AnalyticsErrorBoundary.client.d.ts +4 -0
  101. package/dist/node/foundation/AnalyticsErrorBoundary.client.js +14 -0
  102. package/dist/node/foundation/Router/BrowserRouter.client.js +8 -8
  103. package/dist/node/foundation/ServerPropsProvider/ServerPropsProvider.d.ts +40 -0
  104. package/dist/node/foundation/ServerPropsProvider/ServerPropsProvider.js +101 -0
  105. package/dist/node/foundation/ServerPropsProvider/index.d.ts +2 -0
  106. package/dist/node/foundation/ServerPropsProvider/index.js +6 -0
  107. package/dist/node/foundation/session/session.d.ts +27 -0
  108. package/dist/node/foundation/session/session.js +43 -0
  109. package/dist/node/foundation/useServerProps/use-server-props.d.ts +21 -0
  110. package/dist/node/foundation/useServerProps/use-server-props.js +40 -0
  111. package/dist/node/framework/Hydration/ServerComponentRequest.server.d.ts +2 -0
  112. package/dist/node/framework/plugins/vite-plugin-hydrogen-config.js +27 -12
  113. package/dist/node/storefront-api-types.d.ts +31 -13
  114. package/dist/node/storefront-api-types.js +14 -2
  115. package/dist/node/types.d.ts +2 -0
  116. package/dist/node/utilities/apiRoutes.d.ts +4 -3
  117. package/dist/node/utilities/apiRoutes.js +35 -8
  118. package/dist/node/utilities/flattenConnection/flattenConnection.d.ts +1 -1
  119. package/dist/node/utilities/flattenConnection/flattenConnection.js +1 -1
  120. package/dist/node/utilities/parseMetafieldValue/parseMetafieldValue.d.ts +1 -1
  121. package/dist/node/utilities/parseMetafieldValue/parseMetafieldValue.js +1 -1
  122. package/dist/node/utilities/storefrontApi.d.ts +4 -0
  123. package/dist/node/utilities/storefrontApi.js +25 -0
  124. package/dist/node/version.d.ts +1 -1
  125. package/dist/node/version.js +1 -1
  126. package/package.json +4 -1
  127. package/dist/esnext/foundation/ServerStateProvider/index.d.ts +0 -2
  128. package/dist/esnext/foundation/ServerStateProvider/index.js +0 -1
  129. package/dist/esnext/foundation/useServerState/index.d.ts +0 -1
  130. package/dist/esnext/foundation/useServerState/index.js +0 -1
  131. package/dist/esnext/foundation/useServerState/use-server-state.d.ts +0 -16
  132. package/dist/esnext/foundation/useServerState/use-server-state.js +0 -20
  133. package/dist/node/foundation/ServerStateProvider/ServerStateProvider.d.ts +0 -30
  134. package/dist/node/foundation/ServerStateProvider/ServerStateProvider.js +0 -77
  135. package/dist/node/foundation/ServerStateProvider/index.d.ts +0 -2
  136. package/dist/node/foundation/ServerStateProvider/index.js +0 -6
  137. package/dist/node/foundation/useServerState/index.d.ts +0 -1
  138. package/dist/node/foundation/useServerState/index.js +0 -5
  139. package/dist/node/foundation/useServerState/use-server-state.d.ts +0 -16
  140. package/dist/node/foundation/useServerState/use-server-state.js +0 -24
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.emptySyncSessionImplementation = exports.emptySessionImplementation = exports.getSyncSessionApi = void 0;
4
+ const suspense_1 = require("../../utilities/suspense");
5
+ function getSyncSessionApi(request, componentResponse, log, session) {
6
+ const sessionPromises = {};
7
+ return session
8
+ ? {
9
+ get() {
10
+ if (!sessionPromises.getPromise) {
11
+ sessionPromises.getPromise = (0, suspense_1.wrapPromise)(session.get(request));
12
+ }
13
+ return sessionPromises.getPromise.read();
14
+ },
15
+ }
16
+ : (0, exports.emptySyncSessionImplementation)(log);
17
+ }
18
+ exports.getSyncSessionApi = getSyncSessionApi;
19
+ const emptySessionImplementation = function (log) {
20
+ return {
21
+ async get() {
22
+ log.warn('No session adapter has been configured!');
23
+ return {};
24
+ },
25
+ async set(key, value) {
26
+ log.warn('No session adapter has been configured!');
27
+ },
28
+ async destroy() {
29
+ log.warn('No session adapter has been configured!');
30
+ return;
31
+ },
32
+ };
33
+ };
34
+ exports.emptySessionImplementation = emptySessionImplementation;
35
+ const emptySyncSessionImplementation = function (log) {
36
+ return {
37
+ get() {
38
+ log.warn('No session adapter has been configured!');
39
+ return {};
40
+ },
41
+ };
42
+ };
43
+ exports.emptySyncSessionImplementation = emptySyncSessionImplementation;
@@ -0,0 +1,21 @@
1
+ import { ServerPropsContextValue, InternalServerPropsContextValue } from '../ServerPropsProvider/ServerPropsProvider';
2
+ /**
3
+ * The `useServerProps` hook allows you to manage the [server props](https://shopify.dev/custom-storefronts/hydrogen/framework/server-props) passed to your server components when using Hydrogen as a React Server Component framework. The server props get cleared when you navigate from one route to another.
4
+ *
5
+ * ## Return value
6
+ *
7
+ * The `useServerProps` hook returns an object with the following keys:
8
+ *
9
+ * | Key | Description |
10
+ * | ---------------- | -------------------------------------------------------------------------------------- |
11
+ * | `serverProps` | The current server props. |
12
+ * | `setServerProps` | A function used to modify server props. |
13
+ * | `pending` | Whether a [transition is pending](https://github.com/reactwg/react-18/discussions/41). |
14
+ *
15
+ */
16
+ export declare function useServerProps(): ServerPropsContextValue;
17
+ /**
18
+ * Internal-only hook to manage server state, including to set location server state
19
+ * @internal
20
+ */
21
+ export declare function useInternalServerProps(): InternalServerPropsContextValue;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useInternalServerProps = exports.useServerProps = void 0;
4
+ const react_1 = require("react");
5
+ const ServerPropsProvider_1 = require("../ServerPropsProvider/ServerPropsProvider");
6
+ /**
7
+ * The `useServerProps` hook allows you to manage the [server props](https://shopify.dev/custom-storefronts/hydrogen/framework/server-props) passed to your server components when using Hydrogen as a React Server Component framework. The server props get cleared when you navigate from one route to another.
8
+ *
9
+ * ## Return value
10
+ *
11
+ * The `useServerProps` hook returns an object with the following keys:
12
+ *
13
+ * | Key | Description |
14
+ * | ---------------- | -------------------------------------------------------------------------------------- |
15
+ * | `serverProps` | The current server props. |
16
+ * | `setServerProps` | A function used to modify server props. |
17
+ * | `pending` | Whether a [transition is pending](https://github.com/reactwg/react-18/discussions/41). |
18
+ *
19
+ */
20
+ function useServerProps() {
21
+ const internalServerPropsContext = (0, react_1.useContext)(ServerPropsProvider_1.ServerPropsContext);
22
+ if (!internalServerPropsContext) {
23
+ return {};
24
+ }
25
+ return {
26
+ serverProps: internalServerPropsContext.serverProps,
27
+ setServerProps: internalServerPropsContext.setServerProps,
28
+ pending: internalServerPropsContext.pending,
29
+ };
30
+ }
31
+ exports.useServerProps = useServerProps;
32
+ /**
33
+ * Internal-only hook to manage server state, including to set location server state
34
+ * @internal
35
+ */
36
+ function useInternalServerProps() {
37
+ var _a;
38
+ return ((_a = (0, react_1.useContext)(ServerPropsProvider_1.ServerPropsContext)) !== null && _a !== void 0 ? _a : {});
39
+ }
40
+ exports.useInternalServerProps = useInternalServerProps;
@@ -3,6 +3,7 @@ import type { QueryCacheControlHeaders } from '../../utilities/log/log-cache-hea
3
3
  import type { QueryTiming } from '../../utilities/log/log-query-timeline';
4
4
  import type { PreloadOptions, QueryKey } from '../../types';
5
5
  import { HelmetData as HeadData } from 'react-helmet-async';
6
+ import { SessionSyncApi } from '../../foundation/session/session';
6
7
  export declare type PreloadQueryEntry = {
7
8
  key: QueryKey;
8
9
  fetcher: () => Promise<unknown>;
@@ -37,6 +38,7 @@ export declare class ServerComponentRequest extends Request {
37
38
  analyticsData: any;
38
39
  router: RouterContextData;
39
40
  buyerIpHeader?: string;
41
+ session?: SessionSyncApi;
40
42
  [key: string]: any;
41
43
  };
42
44
  constructor(input: any);
@@ -1,10 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = () => {
4
+ const rollupOptions = {
5
+ output: {},
6
+ };
7
+ if (process.env.WORKER) {
8
+ /**
9
+ * By default, SSR dedupe logic gets bundled which runs `require('module')`.
10
+ * We don't want this in our workers runtime, because `require` is not supported.
11
+ */
12
+ rollupOptions.output = {
13
+ format: 'es',
14
+ };
15
+ }
16
+ if (!process.env.LOCAL_DEV) {
17
+ /**
18
+ * Ofuscate production asset name - To prevent ad blocker logics that blocks
19
+ * certain files due to how it is named.
20
+ */
21
+ rollupOptions.output = {
22
+ chunkFileNames: '[hash].js',
23
+ };
24
+ }
4
25
  return {
5
26
  name: 'vite-plugin-hydrogen-config',
6
27
  config: async (config, env) => {
7
- var _a, _b;
28
+ var _a, _b, _c;
8
29
  return ({
9
30
  resolve: {
10
31
  alias: {
@@ -15,17 +36,9 @@ exports.default = () => {
15
36
  build: {
16
37
  minify: (_b = (_a = config.build) === null || _a === void 0 ? void 0 : _a.minify) !== null && _b !== void 0 ? _b : 'esbuild',
17
38
  sourcemap: true,
18
- /**
19
- * By default, SSR dedupe logic gets bundled which runs `require('module')`.
20
- * We don't want this in our workers runtime, because `require` is not supported.
21
- */
22
- rollupOptions: process.env.WORKER
23
- ? {
24
- output: {
25
- format: 'es',
26
- },
27
- }
28
- : {},
39
+ rollupOptions: ((_c = config.build) === null || _c === void 0 ? void 0 : _c.rollupOptions)
40
+ ? Object.assign(rollupOptions, config.build.rollupOptions)
41
+ : rollupOptions,
29
42
  },
30
43
  ssr: {
31
44
  /**
@@ -66,6 +79,8 @@ exports.default = () => {
66
79
  'react',
67
80
  'react-dom/client',
68
81
  'react-server-dom-vite/client-proxy',
82
+ // https://github.com/vitejs/vite/issues/6215
83
+ 'react/jsx-runtime',
69
84
  ],
70
85
  },
71
86
  define: {
@@ -26,7 +26,7 @@ export declare type Scalars = {
26
26
  Float: number;
27
27
  /**
28
28
  * Represents an [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601)-encoded date and time string.
29
- * For example, 3:30 pm on September 7, 2019 in the time zone of UTC (Coordinated Universal Time) is
29
+ * For example, 3:50 pm on September 7, 2019 in the time zone of UTC (Coordinated Universal Time) is
30
30
  * represented as `"2019-09-07T15:50:00Z`".
31
31
  *
32
32
  */
@@ -423,7 +423,10 @@ export declare type Cart = Node & {
423
423
  createdAt: Scalars['DateTime'];
424
424
  /** The delivery groups available for the cart, based on the default address of the logged-in customer. */
425
425
  deliveryGroups: CartDeliveryGroupConnection;
426
- /** The discount codes that have been applied to the cart. */
426
+ /**
427
+ * The case-insensitive discount codes that the customer added at checkout.
428
+ *
429
+ */
427
430
  discountCodes: Array<CartDiscountCode>;
428
431
  /** The estimated costs that the buyer will pay at checkout. The estimated costs are subject to change and changes will be reflected at checkout. The `estimatedCost` field uses the `buyerIdentity` field to determine [international pricing](https://shopify.dev/api/examples/international-pricing#create-a-cart). */
429
432
  estimatedCost: CartEstimatedCost;
@@ -621,9 +624,9 @@ export declare enum CartErrorCode {
621
624
  */
622
625
  export declare type CartEstimatedCost = {
623
626
  __typename?: 'CartEstimatedCost';
624
- /** The estimated amount, before taxes and discounts, for the customer to pay at checkout. */
627
+ /** The estimated amount, before taxes and discounts, for the customer to pay. */
625
628
  subtotalAmount: MoneyV2;
626
- /** The estimated total amount for the customer to pay at checkout. */
629
+ /** The estimated total amount for the customer to pay. */
627
630
  totalAmount: MoneyV2;
628
631
  /** The estimated duty amount for the customer to pay at checkout. */
629
632
  totalDutyAmount?: Maybe<MoneyV2>;
@@ -636,7 +639,10 @@ export declare type CartInput = {
636
639
  attributes?: InputMaybe<Array<AttributeInput>>;
637
640
  /** The customer associated with the cart. Used to determine [international pricing](https://shopify.dev/api/examples/international-pricing#create-a-checkout). Buyer identity should match the customer's shipping address. */
638
641
  buyerIdentity?: InputMaybe<CartBuyerIdentityInput>;
639
- /** The discount codes to apply to the cart. */
642
+ /**
643
+ * The case-insensitive discount codes that the customer added at checkout.
644
+ *
645
+ */
640
646
  discountCodes?: InputMaybe<Array<Scalars['String']>>;
641
647
  /** A list of merchandise lines to add to the cart. */
642
648
  lines?: InputMaybe<Array<CartLineInput>>;
@@ -777,7 +783,7 @@ export declare type Checkout = Node & {
777
783
  completedAt?: Maybe<Scalars['DateTime']>;
778
784
  /** The date and time when the checkout was created. */
779
785
  createdAt: Scalars['DateTime'];
780
- /** The currency code for the Checkout. */
786
+ /** The currency code for the checkout. */
781
787
  currencyCode: CurrencyCode;
782
788
  /** A list of extra information that is added to the checkout. */
783
789
  customAttributes: Array<Attribute>;
@@ -830,9 +836,9 @@ export declare type Checkout = Node & {
830
836
  subtotalPrice: Scalars['Money'];
831
837
  /** Price of the checkout before duties, shipping and taxes. */
832
838
  subtotalPriceV2: MoneyV2;
833
- /** Specifies if the Checkout is tax exempt. */
839
+ /** Whether the checkout is tax exempt. */
834
840
  taxExempt: Scalars['Boolean'];
835
- /** Specifies if taxes are included in the line item and shipping line prices. */
841
+ /** Whether taxes are included in the line item and shipping line prices. */
836
842
  taxesIncluded: Scalars['Boolean'];
837
843
  /** The sum of all the duties applied to the line items in the checkout. */
838
844
  totalDuties?: Maybe<MoneyV2>;
@@ -1653,7 +1659,13 @@ export declare type Country = {
1653
1659
  /** The unit system used in the country. */
1654
1660
  unitSystem: UnitSystem;
1655
1661
  };
1656
- /** ISO 3166-1 alpha-2 country codes with some differences. */
1662
+ /**
1663
+ * The code designating a country, which generally follows ISO 3166-1 alpha-2 guidelines.
1664
+ * If a territory doesn't have a country code value in the `CountryCode` enum, it might be considered a subdivision
1665
+ * of another country. For example, the territories associated with Spain are represented by the country code `ES`,
1666
+ * and the territories associated with the United States of America are represented by the country code `US`.
1667
+ *
1668
+ */
1657
1669
  export declare enum CountryCode {
1658
1670
  /** Ascension Island. */
1659
1671
  Ac = "AC",
@@ -3105,7 +3117,13 @@ export declare type Filter = {
3105
3117
  /** The list of values for this filter. */
3106
3118
  values: Array<FilterValue>;
3107
3119
  };
3108
- /** Denotes the type of data this filter group represents. */
3120
+ /**
3121
+ * The type of data that the filter group represents.
3122
+ *
3123
+ * For more information, refer to [Filter products in a collection with the Storefront API]
3124
+ * (https://shopify.dev/api/examples/filter-products).
3125
+ *
3126
+ */
3109
3127
  export declare enum FilterType {
3110
3128
  /** A boolean value. */
3111
3129
  Boolean = "BOOLEAN",
@@ -3204,7 +3222,7 @@ export declare type GenericFile = Node & {
3204
3222
  alt?: Maybe<Scalars['String']>;
3205
3223
  /** A globally-unique identifier. */
3206
3224
  id: Scalars['ID'];
3207
- /** The mime type of the file. */
3225
+ /** The MIME type of the file. */
3208
3226
  mimeType?: Maybe<Scalars['String']>;
3209
3227
  /** The size of the original file in bytes. */
3210
3228
  originalFileSize?: Maybe<Scalars['Int']>;
@@ -5781,9 +5799,9 @@ export declare type SellingPlan = {
5781
5799
  id: Scalars['ID'];
5782
5800
  /** The name of the selling plan. For example, '6 weeks of prepaid granola, delivered weekly'. */
5783
5801
  name: Scalars['String'];
5784
- /** Represents the selling plan options available in the drop-down list in the storefront. For example, 'Delivery every week' or 'Delivery every 2 weeks' specifies the delivery frequency options for the product. */
5802
+ /** The selling plan options available in the drop-down list in the storefront. For example, 'Delivery every week' or 'Delivery every 2 weeks' specifies the delivery frequency options for the product. */
5785
5803
  options: Array<SellingPlanOption>;
5786
- /** Represents how a selling plan affects pricing when a variant is purchased with a selling plan. */
5804
+ /** The price adjustments that a selling plan makes when a variant is purchased with a selling plan. */
5787
5805
  priceAdjustments: Array<SellingPlanPriceAdjustment>;
5788
5806
  /** Whether purchasing the selling plan will result in multiple deliveries. */
5789
5807
  recurringDeliveries: Scalars['Boolean'];
@@ -173,7 +173,13 @@ var CollectionSortKeys;
173
173
  /** Sort by the `updated_at` value. */
174
174
  CollectionSortKeys["UpdatedAt"] = "UPDATED_AT";
175
175
  })(CollectionSortKeys = exports.CollectionSortKeys || (exports.CollectionSortKeys = {}));
176
- /** ISO 3166-1 alpha-2 country codes with some differences. */
176
+ /**
177
+ * The code designating a country, which generally follows ISO 3166-1 alpha-2 guidelines.
178
+ * If a territory doesn't have a country code value in the `CountryCode` enum, it might be considered a subdivision
179
+ * of another country. For example, the territories associated with Spain are represented by the country code `ES`,
180
+ * and the territories associated with the United States of America are represented by the country code `US`.
181
+ *
182
+ */
177
183
  var CountryCode;
178
184
  (function (CountryCode) {
179
185
  /** Ascension Island. */
@@ -1104,7 +1110,13 @@ var DiscountApplicationTargetType;
1104
1110
  /** The discount applies onto shipping lines. */
1105
1111
  DiscountApplicationTargetType["ShippingLine"] = "SHIPPING_LINE";
1106
1112
  })(DiscountApplicationTargetType = exports.DiscountApplicationTargetType || (exports.DiscountApplicationTargetType = {}));
1107
- /** Denotes the type of data this filter group represents. */
1113
+ /**
1114
+ * The type of data that the filter group represents.
1115
+ *
1116
+ * For more information, refer to [Filter products in a collection with the Storefront API]
1117
+ * (https://shopify.dev/api/examples/filter-products).
1118
+ *
1119
+ */
1108
1120
  var FilterType;
1109
1121
  (function (FilterType) {
1110
1122
  /** A boolean value. */
@@ -4,6 +4,7 @@ import type { Logger } from './utilities/log/log';
4
4
  import type { ServerComponentRequest } from './framework/Hydration/ServerComponentRequest.server';
5
5
  import type { ServerComponentResponse } from './framework/Hydration/ServerComponentResponse.server';
6
6
  import type { Metafield, ProductVariant, Product, MediaImage } from './storefront-api-types';
7
+ import type { SessionStorageAdapter } from './foundation/session/session';
7
8
  declare type CommonOptions = {
8
9
  App: any;
9
10
  routes?: ImportGlobEagerOutput;
@@ -42,6 +43,7 @@ export declare type ServerHandlerConfig = {
42
43
  routes?: ImportGlobEagerOutput;
43
44
  shopifyConfig: ShopifyConfig;
44
45
  serverAnalyticsConnectors?: Array<ServerAnalyticsConnector>;
46
+ session?: (log: Logger) => SessionStorageAdapter;
45
47
  };
46
48
  export declare type ClientHandlerConfig = {
47
49
  shopifyConfig: ShopifyConfig;
@@ -1,9 +1,12 @@
1
1
  import { ImportGlobEagerOutput, ShopifyConfig } from '../types';
2
+ import type { ServerComponentRequest } from '../framework/Hydration/ServerComponentRequest.server';
2
3
  import type { ASTNode } from 'graphql';
4
+ import { SessionApi, SessionStorageAdapter } from '../foundation/session/session';
3
5
  declare type RouteParams = Record<string, string>;
4
6
  declare type RequestOptions = {
5
7
  params: RouteParams;
6
8
  queryShop: (args: QueryShopArgs) => Promise<any>;
9
+ session: SessionApi | null;
7
10
  };
8
11
  declare type ResourceGetter = (request: Request, requestOptions: RequestOptions) => Promise<Response | Object | String>;
9
12
  interface HydrogenApiRoute {
@@ -29,8 +32,6 @@ interface QueryShopArgs {
29
32
  query: ASTNode | string;
30
33
  /** An object of the variables for the GraphQL query. */
31
34
  variables?: Record<string, any>;
32
- /** A string corresponding to a valid locale identifier like `en-us` used to make the request. */
33
- locale?: string;
34
35
  }
35
- export declare function renderApiRoute(request: Request, route: ApiRouteMatch, shopifyConfig: ShopifyConfig): Promise<Response | Request>;
36
+ export declare function renderApiRoute(request: ServerComponentRequest, route: ApiRouteMatch, shopifyConfig: ShopifyConfig, session?: SessionStorageAdapter): Promise<Response | Request>;
36
37
  export {};
@@ -4,6 +4,8 @@ exports.renderApiRoute = exports.getApiRouteFromURL = exports.getApiRoutes = voi
4
4
  const matchPath_1 = require("./matchPath");
5
5
  const log_1 = require("../utilities/log/");
6
6
  const fetch_1 = require("./fetch");
7
+ const storefrontApi_1 = require("./storefrontApi");
8
+ const session_1 = require("../foundation/session/session");
7
9
  let memoizedRoutes = [];
8
10
  let memoizedPages = {};
9
11
  function getApiRoutes(pages, topLevelPath = '*') {
@@ -69,30 +71,49 @@ function getApiRouteFromURL(url, routes) {
69
71
  };
70
72
  }
71
73
  exports.getApiRouteFromURL = getApiRouteFromURL;
72
- function queryShopBuilder(shopifyConfig) {
73
- return async function queryShop({ query, variables, locale, }) {
74
- var _a;
75
- const { storeDomain, storefrontApiVersion, storefrontToken, defaultLocale } = shopifyConfig;
74
+ function queryShopBuilder(shopifyConfig, request) {
75
+ return async function queryShop({ query, variables, }) {
76
+ const { storeDomain, storefrontApiVersion, storefrontToken } = shopifyConfig;
77
+ const buyerIp = request.getBuyerIp();
78
+ const extraHeaders = (0, storefrontApi_1.getStorefrontApiRequestHeaders)({
79
+ buyerIp,
80
+ storefrontToken,
81
+ });
76
82
  const fetcher = (0, fetch_1.fetchBuilder)(`https://${storeDomain}/api/${storefrontApiVersion}/graphql.json`, {
77
83
  method: 'POST',
78
84
  body: (0, fetch_1.graphqlRequestBody)(query, variables),
79
85
  headers: {
80
- 'X-Shopify-Storefront-Access-Token': storefrontToken,
81
- 'Accept-Language': (_a = locale) !== null && _a !== void 0 ? _a : defaultLocale,
82
86
  'Content-Type': 'application/json',
87
+ ...extraHeaders,
83
88
  },
84
89
  });
85
90
  return await fetcher();
86
91
  };
87
92
  }
88
- async function renderApiRoute(request, route, shopifyConfig) {
93
+ async function renderApiRoute(request, route, shopifyConfig, session) {
89
94
  var _a;
90
95
  let response;
91
96
  const log = (0, log_1.getLoggerWithContext)(request);
97
+ let cookieToSet = '';
92
98
  try {
93
99
  response = await route.resource(request, {
94
100
  params: route.params,
95
- queryShop: queryShopBuilder(shopifyConfig),
101
+ queryShop: queryShopBuilder(shopifyConfig, request),
102
+ session: session
103
+ ? {
104
+ async get() {
105
+ return session.get(request);
106
+ },
107
+ async set(key, value) {
108
+ const data = await session.get(request);
109
+ data[key] = value;
110
+ cookieToSet = await session.set(request, data);
111
+ },
112
+ async destroy() {
113
+ cookieToSet = await session.destroy(request);
114
+ },
115
+ }
116
+ : (0, session_1.emptySessionImplementation)(log),
96
117
  });
97
118
  if (!(response instanceof Response || response instanceof Request)) {
98
119
  if (typeof response === 'string' || response instanceof String) {
@@ -106,6 +127,12 @@ async function renderApiRoute(request, route, shopifyConfig) {
106
127
  });
107
128
  }
108
129
  }
130
+ if (!response) {
131
+ response = new Response(null);
132
+ }
133
+ if (cookieToSet) {
134
+ response.headers.set('Set-Cookie', cookieToSet);
135
+ }
109
136
  }
110
137
  catch (e) {
111
138
  log.error(e);
@@ -1,6 +1,6 @@
1
1
  import type { GraphQLConnection } from '../../types';
2
2
  import type { PartialDeep } from 'type-fest';
3
3
  /**
4
- * The `flattenConnection` utility transforms a connection object from the Storefront API (for example, [Product-related connections](/api/storefront/reference/products/product)) into a flat array of nodes.
4
+ * The `flattenConnection` utility transforms a connection object from the Storefront API (for example, [Product-related connections](https://shopify.dev/api/storefront/reference/products/product)) into a flat array of nodes.
5
5
  */
6
6
  export declare function flattenConnection<T>(connection: PartialDeep<GraphQLConnection<T>>): PartialDeep<T>[];
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.flattenConnection = void 0;
4
4
  /**
5
- * The `flattenConnection` utility transforms a connection object from the Storefront API (for example, [Product-related connections](/api/storefront/reference/products/product)) into a flat array of nodes.
5
+ * The `flattenConnection` utility transforms a connection object from the Storefront API (for example, [Product-related connections](https://shopify.dev/api/storefront/reference/products/product)) into a flat array of nodes.
6
6
  */
7
7
  function flattenConnection(connection) {
8
8
  return (connection.edges || []).map((edge) => {
@@ -1,6 +1,6 @@
1
1
  import type { Metafield } from '../../storefront-api-types';
2
2
  import type { PartialDeep } from 'type-fest';
3
3
  /**
4
- * The `parseMetafieldValue` function parses a [Metafield](/api/storefront/reference/common-objects/metafield)'s `value` from a string into a sensible type corresponding to the [Metafield](/api/storefront/reference/common-objects/metafield)'s `type`.
4
+ * The `parseMetafieldValue` function parses a [Metafield](https://shopify.dev/api/storefront/reference/common-objects/metafield)'s `value` from a string into a sensible type corresponding to the [Metafield](https://shopify.dev/api/storefront/reference/common-objects/metafield)'s `type`.
5
5
  */
6
6
  export declare function parseMetafieldValue(metafield: PartialDeep<Metafield>): any;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseMetafieldValue = void 0;
4
4
  /**
5
- * The `parseMetafieldValue` function parses a [Metafield](/api/storefront/reference/common-objects/metafield)'s `value` from a string into a sensible type corresponding to the [Metafield](/api/storefront/reference/common-objects/metafield)'s `type`.
5
+ * The `parseMetafieldValue` function parses a [Metafield](https://shopify.dev/api/storefront/reference/common-objects/metafield)'s `value` from a string into a sensible type corresponding to the [Metafield](https://shopify.dev/api/storefront/reference/common-objects/metafield)'s `type`.
6
6
  */
7
7
  function parseMetafieldValue(metafield) {
8
8
  if (metafield.value == null) {
@@ -0,0 +1,4 @@
1
+ export declare function getStorefrontApiRequestHeaders({ buyerIp, storefrontToken, }: {
2
+ buyerIp?: string | null;
3
+ storefrontToken: string;
4
+ }): Record<string, any>;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getStorefrontApiRequestHeaders = void 0;
4
+ const constants_1 = require("../constants");
5
+ function getStorefrontApiRequestHeaders({ buyerIp, storefrontToken, }) {
6
+ var _a;
7
+ const headers = {};
8
+ const secretToken = typeof Oxygen !== 'undefined'
9
+ ? (_a = Oxygen === null || Oxygen === void 0 ? void 0 : Oxygen.env) === null || _a === void 0 ? void 0 : _a[constants_1.OXYGEN_SECRET_TOKEN_ENVIRONMENT_VARIABLE]
10
+ : null;
11
+ /**
12
+ * Only pass one type of storefront token at a time.
13
+ */
14
+ if (secretToken) {
15
+ headers[constants_1.STOREFRONT_API_SECRET_TOKEN_HEADER] = secretToken;
16
+ }
17
+ else {
18
+ headers[constants_1.STOREFRONT_API_PUBLIC_TOKEN_HEADER] = storefrontToken;
19
+ }
20
+ if (buyerIp) {
21
+ headers[constants_1.STOREFRONT_API_BUYER_IP_HEADER] = buyerIp;
22
+ }
23
+ return headers;
24
+ }
25
+ exports.getStorefrontApiRequestHeaders = getStorefrontApiRequestHeaders;
@@ -1 +1 @@
1
- export declare const LIB_VERSION = "0.15.0";
1
+ export declare const LIB_VERSION = "0.17.0";
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LIB_VERSION = void 0;
4
- exports.LIB_VERSION = '0.15.0';
4
+ exports.LIB_VERSION = '0.17.0';
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "engines": {
8
8
  "node": ">=14"
9
9
  },
10
- "version": "0.15.0",
10
+ "version": "0.17.0",
11
11
  "description": "Modern custom Shopify storefronts",
12
12
  "license": "MIT",
13
13
  "main": "dist/esnext/index.js",
@@ -71,6 +71,7 @@
71
71
  "@types/react": "^17.0.3",
72
72
  "@types/react-dom": "^17.0.3",
73
73
  "@types/ws": "^8.2.0",
74
+ "@types/uuid": "^8.3.4",
74
75
  "babel-loader": "^8.2.2",
75
76
  "cpy-cli": "3.1.1",
76
77
  "mkdirp": "^1.0.4",
@@ -101,6 +102,8 @@
101
102
  "dependencies": {
102
103
  "@vitejs/plugin-react": "^1.3.0",
103
104
  "abort-controller": "^3.0.0",
105
+ "worktop": "^0.7.3",
106
+ "uuid": "^8.3.2",
104
107
  "body-parser": "^1.19.2",
105
108
  "connect": "^3.7.0",
106
109
  "es-module-lexer": "^0.10.0",
@@ -1,2 +0,0 @@
1
- export { ServerStateProvider, ServerStateContext } from './ServerStateProvider';
2
- export type { ServerState, ServerStateContextValue } from './ServerStateProvider';
@@ -1 +0,0 @@
1
- export { ServerStateProvider, ServerStateContext } from './ServerStateProvider';
@@ -1 +0,0 @@
1
- export { useServerState } from './use-server-state';
@@ -1 +0,0 @@
1
- export { useServerState } from './use-server-state';
@@ -1,16 +0,0 @@
1
- import { ServerStateContextValue } from '../ServerStateProvider';
2
- /**
3
- * The `useServerState` hook allows you to [manage server state](/custom-storefronts/hydrogen/framework/server-state) when using Hydrogen as a React Server Component framework.
4
- *
5
- * ## Return value
6
- *
7
- * The `useServerState` hook returns an object with the following keys:
8
- *
9
- * | Key | Description |
10
- * | -------------- | ------------------------------------------------------------------------------------------------------------- |
11
- * | `serverState` | The current server state. |
12
- * | `setServerState` | A function used to modify server state. |
13
- * | `pending` | Whether a [transition is pending](https://github.com/reactwg/react-18/discussions/41). |
14
- *
15
- */
16
- export declare function useServerState(): ServerStateContextValue;
@@ -1,20 +0,0 @@
1
- import { useContext } from 'react';
2
- import { ServerStateContext, } from '../ServerStateProvider';
3
- /**
4
- * The `useServerState` hook allows you to [manage server state](/custom-storefronts/hydrogen/framework/server-state) when using Hydrogen as a React Server Component framework.
5
- *
6
- * ## Return value
7
- *
8
- * The `useServerState` hook returns an object with the following keys:
9
- *
10
- * | Key | Description |
11
- * | -------------- | ------------------------------------------------------------------------------------------------------------- |
12
- * | `serverState` | The current server state. |
13
- * | `setServerState` | A function used to modify server state. |
14
- * | `pending` | Whether a [transition is pending](https://github.com/reactwg/react-18/discussions/41). |
15
- *
16
- */
17
- export function useServerState() {
18
- var _a;
19
- return ((_a = useContext(ServerStateContext)) !== null && _a !== void 0 ? _a : {});
20
- }
@@ -1,30 +0,0 @@
1
- import React, { ReactNode } from 'react';
2
- declare global {
3
- var __DEV__: boolean;
4
- }
5
- export interface ServerState {
6
- pathname: string;
7
- search: string;
8
- [key: string]: any;
9
- }
10
- declare type ServerStateSetterInput = ((prev: ServerState) => Partial<ServerState>) | Partial<ServerState> | string;
11
- export interface ServerStateSetter {
12
- (input: ServerStateSetterInput, propValue?: any): void;
13
- }
14
- interface ProposedServerStateSetter {
15
- (input: ServerStateSetterInput, propValue?: any): ServerState;
16
- }
17
- export interface ServerStateContextValue {
18
- pending: boolean;
19
- serverState: ServerState;
20
- setServerState: ServerStateSetter;
21
- getProposedServerState: ProposedServerStateSetter;
22
- }
23
- export declare const ServerStateContext: React.Context<ServerStateContextValue>;
24
- interface ServerStateProviderProps {
25
- serverState: ServerState;
26
- setServerState: React.Dispatch<React.SetStateAction<ServerState>>;
27
- children: ReactNode;
28
- }
29
- export declare function ServerStateProvider({ serverState, setServerState, children, }: ServerStateProviderProps): JSX.Element;
30
- export {};