@shopify/hydrogen 0.14.0 → 0.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/CHANGELOG.md +124 -0
  2. package/dist/esnext/client.d.ts +4 -0
  3. package/dist/esnext/client.js +4 -0
  4. package/dist/esnext/components/CartProvider/CartProvider.client.js +23 -0
  5. package/dist/esnext/components/DevTools.d.ts +1 -0
  6. package/dist/esnext/components/DevTools.js +128 -0
  7. package/dist/esnext/components/Link/Link.client.js +1 -1
  8. package/dist/esnext/constants.d.ts +6 -0
  9. package/dist/esnext/constants.js +6 -0
  10. package/dist/esnext/entry-client.js +7 -4
  11. package/dist/esnext/entry-server.d.ts +1 -1
  12. package/dist/esnext/entry-server.js +29 -15
  13. package/dist/esnext/foundation/Analytics/Analytics.client.d.ts +3 -0
  14. package/dist/esnext/foundation/Analytics/Analytics.client.js +28 -0
  15. package/dist/esnext/foundation/Analytics/Analytics.server.d.ts +1 -0
  16. package/dist/esnext/foundation/Analytics/Analytics.server.js +38 -0
  17. package/dist/esnext/foundation/Analytics/ClientAnalytics.d.ts +24 -0
  18. package/dist/esnext/foundation/Analytics/ClientAnalytics.js +91 -0
  19. package/dist/esnext/foundation/Analytics/ServerAnalyticsRoute.server.d.ts +2 -0
  20. package/dist/esnext/foundation/Analytics/ServerAnalyticsRoute.server.js +33 -0
  21. package/dist/esnext/foundation/Analytics/const.d.ts +8 -0
  22. package/dist/esnext/foundation/Analytics/const.js +8 -0
  23. package/dist/esnext/foundation/Analytics/hook.d.ts +1 -0
  24. package/dist/esnext/foundation/Analytics/hook.js +7 -0
  25. package/dist/esnext/foundation/Analytics/index.d.ts +2 -0
  26. package/dist/esnext/foundation/Analytics/index.js +2 -0
  27. package/dist/esnext/foundation/Analytics/types.d.ts +5 -0
  28. package/dist/esnext/foundation/Analytics/types.js +1 -0
  29. package/dist/esnext/foundation/Analytics/utils.d.ts +1 -0
  30. package/dist/esnext/foundation/Analytics/utils.js +8 -0
  31. package/dist/esnext/foundation/Boomerang/Boomerang.client.js +3 -1
  32. package/dist/esnext/foundation/Route/Route.server.js +4 -0
  33. package/dist/esnext/foundation/Router/BrowserRouter.client.js +68 -15
  34. package/dist/esnext/foundation/ServerRequestProvider/ServerRequestProvider.js +1 -1
  35. package/dist/esnext/foundation/ShopifyProvider/types.d.ts +2 -5
  36. package/dist/esnext/foundation/fetchSync/client/fetchSync.d.ts +10 -0
  37. package/dist/esnext/foundation/fetchSync/client/fetchSync.js +27 -0
  38. package/dist/esnext/foundation/fetchSync/server/fetchSync.d.ts +8 -0
  39. package/dist/esnext/foundation/fetchSync/server/fetchSync.js +27 -0
  40. package/dist/esnext/foundation/fetchSync/types.d.ts +5 -0
  41. package/dist/esnext/foundation/fetchSync/types.js +1 -0
  42. package/dist/esnext/foundation/useQuery/hooks.d.ts +4 -2
  43. package/dist/esnext/foundation/useQuery/hooks.js +10 -6
  44. package/dist/esnext/foundation/useUrl/useUrl.js +8 -1
  45. package/dist/esnext/framework/Hydration/ServerComponentRequest.server.d.ts +1 -0
  46. package/dist/esnext/framework/Hydration/ServerComponentRequest.server.js +11 -5
  47. package/dist/esnext/framework/cache/in-memory.js +5 -5
  48. package/dist/esnext/framework/cache.d.ts +1 -2
  49. package/dist/esnext/framework/cache.js +67 -22
  50. package/dist/esnext/framework/plugin.js +10 -0
  51. package/dist/esnext/framework/plugins/vite-plugin-css-modules-rsc.js +1 -1
  52. package/dist/esnext/framework/plugins/vite-plugin-hydrogen-config.js +11 -2
  53. package/dist/esnext/hooks/useShopQuery/hooks.js +32 -25
  54. package/dist/esnext/index.d.ts +2 -0
  55. package/dist/esnext/index.js +2 -0
  56. package/dist/esnext/types.d.ts +6 -1
  57. package/dist/esnext/utilities/apiRoutes.d.ts +2 -3
  58. package/dist/esnext/utilities/apiRoutes.js +14 -9
  59. package/dist/esnext/utilities/hash.d.ts +2 -0
  60. package/dist/esnext/utilities/hash.js +7 -0
  61. package/dist/esnext/utilities/log/log-cache-api-status.js +1 -1
  62. package/dist/esnext/utilities/log/log-cache-header.js +1 -1
  63. package/dist/esnext/utilities/log/log-query-timeline.js +1 -1
  64. package/dist/esnext/utilities/storefrontApi.d.ts +4 -0
  65. package/dist/esnext/utilities/storefrontApi.js +21 -0
  66. package/dist/esnext/utilities/suspense.d.ts +5 -0
  67. package/dist/esnext/utilities/suspense.js +32 -0
  68. package/dist/esnext/utilities/template.js +1 -1
  69. package/dist/esnext/version.d.ts +1 -1
  70. package/dist/esnext/version.js +1 -1
  71. package/dist/node/constants.d.ts +6 -0
  72. package/dist/node/constants.js +7 -1
  73. package/dist/node/entry-server.d.ts +1 -1
  74. package/dist/node/entry-server.js +28 -17
  75. package/dist/node/foundation/Analytics/Analytics.client.d.ts +3 -0
  76. package/dist/node/foundation/Analytics/Analytics.client.js +32 -0
  77. package/dist/node/foundation/Analytics/Analytics.server.d.ts +1 -0
  78. package/dist/node/foundation/Analytics/Analytics.server.js +45 -0
  79. package/dist/node/foundation/Analytics/ClientAnalytics.d.ts +24 -0
  80. package/dist/node/foundation/Analytics/ClientAnalytics.js +94 -0
  81. package/dist/node/foundation/Analytics/ServerAnalyticsRoute.server.d.ts +2 -0
  82. package/dist/node/foundation/Analytics/ServerAnalyticsRoute.server.js +37 -0
  83. package/dist/node/foundation/Analytics/const.d.ts +8 -0
  84. package/dist/node/foundation/Analytics/const.js +11 -0
  85. package/dist/node/foundation/Analytics/hook.d.ts +1 -0
  86. package/dist/node/foundation/Analytics/hook.js +11 -0
  87. package/dist/node/foundation/Analytics/index.d.ts +2 -0
  88. package/dist/node/foundation/Analytics/index.js +7 -0
  89. package/dist/node/foundation/Analytics/types.d.ts +5 -0
  90. package/dist/node/foundation/Analytics/types.js +2 -0
  91. package/dist/node/foundation/Analytics/utils.d.ts +1 -0
  92. package/dist/node/foundation/Analytics/utils.js +12 -0
  93. package/dist/node/foundation/Router/BrowserRouter.client.js +67 -14
  94. package/dist/node/foundation/ServerRequestProvider/ServerRequestProvider.js +2 -2
  95. package/dist/node/foundation/ShopifyProvider/types.d.ts +2 -5
  96. package/dist/node/framework/Hydration/ServerComponentRequest.server.d.ts +1 -0
  97. package/dist/node/framework/Hydration/ServerComponentRequest.server.js +13 -7
  98. package/dist/node/framework/cache/in-memory.js +5 -5
  99. package/dist/node/framework/cache.d.ts +1 -2
  100. package/dist/node/framework/cache.js +71 -27
  101. package/dist/node/framework/plugin.js +10 -0
  102. package/dist/node/framework/plugins/vite-plugin-css-modules-rsc.js +1 -1
  103. package/dist/node/framework/plugins/vite-plugin-hydrogen-config.js +11 -2
  104. package/dist/node/types.d.ts +6 -1
  105. package/dist/node/utilities/apiRoutes.d.ts +2 -3
  106. package/dist/node/utilities/apiRoutes.js +14 -9
  107. package/dist/node/utilities/flattenConnection/flattenConnection.d.ts +6 -0
  108. package/dist/node/utilities/flattenConnection/flattenConnection.js +15 -0
  109. package/dist/node/utilities/flattenConnection/index.d.ts +1 -0
  110. package/dist/node/utilities/flattenConnection/index.js +5 -0
  111. package/dist/node/utilities/hash.d.ts +2 -0
  112. package/dist/node/utilities/hash.js +11 -0
  113. package/dist/node/utilities/image_size.d.ts +30 -0
  114. package/dist/node/utilities/image_size.js +110 -0
  115. package/dist/node/utilities/index.d.ts +11 -0
  116. package/dist/node/utilities/index.js +32 -0
  117. package/dist/node/utilities/isClient/index.d.ts +1 -0
  118. package/dist/node/utilities/isClient/index.js +5 -0
  119. package/dist/node/utilities/isClient/isClient.d.ts +4 -0
  120. package/dist/node/utilities/isClient/isClient.js +10 -0
  121. package/dist/node/utilities/isServer/index.d.ts +1 -0
  122. package/dist/node/utilities/isServer/index.js +5 -0
  123. package/dist/node/utilities/isServer/isServer.d.ts +4 -0
  124. package/dist/node/utilities/isServer/isServer.js +11 -0
  125. package/dist/node/utilities/load_script.d.ts +3 -0
  126. package/dist/node/utilities/load_script.js +27 -0
  127. package/dist/node/utilities/log/log-cache-api-status.js +1 -1
  128. package/dist/node/utilities/log/log-cache-header.js +2 -2
  129. package/dist/node/utilities/log/log-query-timeline.js +2 -2
  130. package/dist/node/utilities/measurement.d.ts +3 -0
  131. package/dist/node/utilities/measurement.js +103 -0
  132. package/dist/node/utilities/parseMetafieldValue/index.d.ts +1 -0
  133. package/dist/node/utilities/parseMetafieldValue/index.js +5 -0
  134. package/dist/node/utilities/parseMetafieldValue/parseMetafieldValue.d.ts +6 -0
  135. package/dist/node/utilities/parseMetafieldValue/parseMetafieldValue.js +39 -0
  136. package/dist/node/utilities/storefrontApi.d.ts +4 -0
  137. package/dist/node/utilities/storefrontApi.js +25 -0
  138. package/dist/node/utilities/suspense.d.ts +12 -0
  139. package/dist/node/utilities/suspense.js +64 -0
  140. package/dist/node/utilities/template.js +1 -1
  141. package/dist/node/utilities/video_parameters.d.ts +47 -0
  142. package/dist/node/utilities/video_parameters.js +27 -0
  143. package/dist/node/version.d.ts +1 -1
  144. package/dist/node/version.js +1 -1
  145. package/package.json +1 -1
  146. package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-plugin.js +9 -21
  147. package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-writer.browser.development.server.js +51 -47
  148. package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-writer.browser.production.min.server.js +30 -29
  149. package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-writer.node.development.server.js +51 -47
  150. package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-writer.node.production.min.server.js +17 -17
  151. package/vendor/react-server-dom-vite/esm/react-server-dom-vite-client-proxy.js +55 -45
  152. package/vendor/react-server-dom-vite/esm/react-server-dom-vite-plugin.js +9 -21
  153. package/vendor/react-server-dom-vite/esm/react-server-dom-vite-writer.browser.server.js +51 -47
  154. package/vendor/react-server-dom-vite/esm/react-server-dom-vite-writer.node.server.js +51 -47
  155. package/vendor/react-server-dom-vite/package.json +3 -3
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isServer = void 0;
4
+ var isServer_1 = require("./isServer");
5
+ Object.defineProperty(exports, "isServer", { enumerable: true, get: function () { return isServer_1.isServer; } });
@@ -0,0 +1,4 @@
1
+ /** The `isServer` utility is a function that returns a `boolean` indicating
2
+ * if the code was run on the server.
3
+ */
4
+ export declare function isServer(): boolean;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isServer = void 0;
4
+ const isClient_1 = require("../isClient");
5
+ /** The `isServer` utility is a function that returns a `boolean` indicating
6
+ * if the code was run on the server.
7
+ */
8
+ function isServer() {
9
+ return !(0, isClient_1.isClient)();
10
+ }
11
+ exports.isServer = isServer;
@@ -0,0 +1,3 @@
1
+ export declare function loadScript(src: string, options?: {
2
+ module?: boolean;
3
+ }): Promise<boolean>;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadScript = void 0;
4
+ const SCRIPTS_LOADED = {};
5
+ function loadScript(src, options) {
6
+ const isScriptLoaded = SCRIPTS_LOADED[src];
7
+ if (isScriptLoaded) {
8
+ return isScriptLoaded;
9
+ }
10
+ const promise = new Promise((resolve, reject) => {
11
+ const script = document.createElement('script');
12
+ if (options === null || options === void 0 ? void 0 : options.module) {
13
+ script.type = 'module';
14
+ }
15
+ script.src = src;
16
+ script.onload = () => {
17
+ resolve(true);
18
+ };
19
+ script.onerror = () => {
20
+ reject(false);
21
+ };
22
+ document.body.appendChild(script);
23
+ });
24
+ SCRIPTS_LOADED[src] = promise;
25
+ return promise;
26
+ }
27
+ exports.loadScript = loadScript;
@@ -8,6 +8,6 @@ function logCacheApiStatus(status, url) {
8
8
  if (!_1.log.options().showCacheApiStatus) {
9
9
  return;
10
10
  }
11
- _1.log.debug((0, kolorist_1.gray)(`[Cache] ${status === null || status === void 0 ? void 0 : status.padEnd(6)} query ${(0, utils_1.findQueryName)(url)}`));
11
+ _1.log.debug((0, kolorist_1.gray)(`[Cache] ${status === null || status === void 0 ? void 0 : status.padEnd(8)} query ${(0, utils_1.findQueryName)(url)}`));
12
12
  }
13
13
  exports.logCacheApiStatus = logCacheApiStatus;
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.logCacheControlHeaders = exports.collectQueryCacheControlHeaders = void 0;
4
- const cache_1 = require("../../framework/cache");
4
+ const hash_1 = require("../hash");
5
5
  const utils_1 = require("./utils");
6
6
  const kolorist_1 = require("kolorist");
7
7
  const log_1 = require("./log");
8
8
  const color = kolorist_1.gray;
9
9
  function collectQueryCacheControlHeaders(request, queryKey, cacheControlHeader) {
10
10
  request.ctx.queryCacheControl.push({
11
- name: (0, utils_1.findQueryName)((0, cache_1.hashKey)(queryKey)),
11
+ name: (0, utils_1.findQueryName)((0, hash_1.hashKey)(queryKey)),
12
12
  header: cacheControlHeader,
13
13
  });
14
14
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.logQueryTimings = exports.collectQueryTimings = void 0;
4
- const cache_1 = require("../../framework/cache");
4
+ const hash_1 = require("../hash");
5
5
  const utils_1 = require("./utils");
6
6
  const kolorist_1 = require("kolorist");
7
7
  const log_1 = require("./log");
@@ -15,7 +15,7 @@ const TIMING_MAPPING = {
15
15
  };
16
16
  function collectQueryTimings(request, queryKey, timingType, duration) {
17
17
  request.ctx.queryTimings.push({
18
- name: (0, utils_1.findQueryName)((0, cache_1.hashKey)(queryKey)),
18
+ name: (0, utils_1.findQueryName)((0, hash_1.hashKey)(queryKey)),
19
19
  timingType,
20
20
  timestamp: (0, timing_1.getTime)(),
21
21
  duration,
@@ -0,0 +1,3 @@
1
+ import { Measurement } from '../types';
2
+ export declare function getMeasurementAsString(measurement: Measurement, locale?: string, options?: Intl.NumberFormatOptions): string;
3
+ export declare function getMeasurementAsParts(measurement: Measurement, locale?: string, options?: Intl.NumberFormatOptions): Intl.NumberFormatPart[];
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getMeasurementAsParts = exports.getMeasurementAsString = void 0;
4
+ const UNIT_MAPPING = {
5
+ // Dimension
6
+ mm: 'millimeter',
7
+ cm: 'centimeter',
8
+ m: 'meter',
9
+ in: 'inch',
10
+ ft: 'foot',
11
+ yd: 'yard',
12
+ // Volume
13
+ ml: 'milliliter',
14
+ l: 'liter',
15
+ us_fl_oz: 'fluid-ounce',
16
+ us_gal: 'gallon',
17
+ // Weight
18
+ kg: 'kilogram',
19
+ g: 'gram',
20
+ lb: 'pound',
21
+ oz: 'ounce',
22
+ };
23
+ function getMeasurementAsString(measurement, locale = 'en-us', options = {}) {
24
+ let measure = {
25
+ value: measurement.value,
26
+ unit: UNIT_MAPPING[measurement.unit],
27
+ };
28
+ if (measure.unit == null) {
29
+ measure = convertToSupportedUnit(measurement.value, measurement.unit);
30
+ }
31
+ return new Intl.NumberFormat(locale, {
32
+ ...options,
33
+ unit: measure.unit,
34
+ style: 'unit',
35
+ }).format(measure.value);
36
+ }
37
+ exports.getMeasurementAsString = getMeasurementAsString;
38
+ function getMeasurementAsParts(measurement, locale = 'en-us', options = {}) {
39
+ let measure = {
40
+ value: measurement.value,
41
+ unit: UNIT_MAPPING[measurement.unit],
42
+ };
43
+ if (measure.unit == null) {
44
+ measure = convertToSupportedUnit(measurement.value, measurement.unit);
45
+ }
46
+ return new Intl.NumberFormat(locale, {
47
+ ...options,
48
+ unit: measure.unit,
49
+ style: 'unit',
50
+ }).formatToParts(measure.value);
51
+ }
52
+ exports.getMeasurementAsParts = getMeasurementAsParts;
53
+ function convertToSupportedUnit(value, unit) {
54
+ switch (unit) {
55
+ case 'cl':
56
+ return {
57
+ value: value / 1000,
58
+ unit: 'liter',
59
+ };
60
+ case 'm3':
61
+ return {
62
+ value: value * 1000,
63
+ unit: 'liter',
64
+ };
65
+ case 'us_pt':
66
+ return {
67
+ value: value * 0.125,
68
+ unit: 'gallon',
69
+ };
70
+ case 'us_qt':
71
+ return {
72
+ value: value * 0.5,
73
+ unit: 'gallon',
74
+ };
75
+ case 'us_oz':
76
+ return {
77
+ value: value / 128,
78
+ unit: 'gallon',
79
+ };
80
+ case 'imp_pt':
81
+ return {
82
+ value: value / 6.661,
83
+ unit: 'gallon',
84
+ };
85
+ case 'imp_qt':
86
+ return {
87
+ value: value / 3.331,
88
+ unit: 'gallon',
89
+ };
90
+ case 'imp_gal':
91
+ return {
92
+ value: value / 1.201,
93
+ unit: 'gallon',
94
+ };
95
+ case 'imp_fl_oz':
96
+ return {
97
+ value: value * 0.96076,
98
+ unit: 'fluid-ounce',
99
+ };
100
+ default:
101
+ throw new Error(`Unit not supported: ${unit}`);
102
+ }
103
+ }
@@ -0,0 +1 @@
1
+ export { parseMetafieldValue } from './parseMetafieldValue';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseMetafieldValue = void 0;
4
+ var parseMetafieldValue_1 = require("./parseMetafieldValue");
5
+ Object.defineProperty(exports, "parseMetafieldValue", { enumerable: true, get: function () { return parseMetafieldValue_1.parseMetafieldValue; } });
@@ -0,0 +1,6 @@
1
+ import type { Metafield } from '../../storefront-api-types';
2
+ import type { PartialDeep } from 'type-fest';
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`.
5
+ */
6
+ export declare function parseMetafieldValue(metafield: PartialDeep<Metafield>): any;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseMetafieldValue = void 0;
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`.
6
+ */
7
+ function parseMetafieldValue(metafield) {
8
+ if (metafield.value == null) {
9
+ return metafield.value;
10
+ }
11
+ switch (metafield.type) {
12
+ case 'boolean':
13
+ return metafield.value == 'true';
14
+ case 'number_integer':
15
+ return parseInt(metafield.value);
16
+ case 'number_decimal':
17
+ return parseFloat(metafield.value);
18
+ case 'date':
19
+ case 'date_time':
20
+ return new Date(metafield.value);
21
+ case 'json':
22
+ case 'weight':
23
+ case 'dimension':
24
+ case 'volume':
25
+ case 'rating':
26
+ return JSON.parse(metafield.value);
27
+ case 'color':
28
+ case 'single_line_text_field':
29
+ case 'multi_line_text_field':
30
+ case 'product_reference':
31
+ case 'page_reference':
32
+ case 'variant_reference':
33
+ case 'file_reference':
34
+ case 'url':
35
+ default:
36
+ return metafield.value;
37
+ }
38
+ }
39
+ exports.parseMetafieldValue = parseMetafieldValue;
@@ -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;
@@ -0,0 +1,12 @@
1
+ import { QueryKey } from '../types';
2
+ /**
3
+ * Wrap the fetch promise in a way that React Suspense understands.
4
+ * Essentially, keep throwing something until you have legit data.
5
+ */
6
+ export declare function wrapPromise<T>(promise: Promise<T>): {
7
+ read: () => T;
8
+ };
9
+ declare type Await<T> = T extends Promise<infer V> ? V : never;
10
+ export declare const suspendFunction: <Fn extends () => Promise<unknown>>(key: QueryKey, fn: Fn) => Await<ReturnType<Fn>>;
11
+ export declare const preloadFunction: (key: QueryKey, fn: () => Promise<unknown>) => unknown;
12
+ export {};
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.preloadFunction = exports.suspendFunction = exports.wrapPromise = void 0;
4
+ const hash_1 = require("./hash");
5
+ /**
6
+ * Wrap the fetch promise in a way that React Suspense understands.
7
+ * Essentially, keep throwing something until you have legit data.
8
+ */
9
+ function wrapPromise(promise) {
10
+ let status = 'pending';
11
+ let response;
12
+ const suspender = promise.then((res) => {
13
+ status = 'success';
14
+ response = res;
15
+ }, (err) => {
16
+ status = 'error';
17
+ response = err;
18
+ });
19
+ const read = () => {
20
+ switch (status) {
21
+ case 'pending':
22
+ throw suspender;
23
+ case 'error':
24
+ throw response;
25
+ default:
26
+ return response;
27
+ }
28
+ };
29
+ return { read };
30
+ }
31
+ exports.wrapPromise = wrapPromise;
32
+ const browserCache = {};
33
+ /**
34
+ * Perform an async function in a synchronous way for Suspense support.
35
+ * To be used only in the client.
36
+ * Inspired by https://github.com/pmndrs/suspend-react
37
+ */
38
+ function query(key, fn, preload = false) {
39
+ const stringKey = (0, hash_1.hashKey)(key);
40
+ if (browserCache[stringKey]) {
41
+ const entry = browserCache[stringKey];
42
+ if (preload)
43
+ return undefined;
44
+ if (entry.error)
45
+ throw entry.error;
46
+ if (entry.response)
47
+ return entry.response;
48
+ if (!preload)
49
+ throw entry.promise;
50
+ }
51
+ const entry = {
52
+ promise: fn()
53
+ .then((response) => (entry.response = response))
54
+ .catch((error) => (entry.error = error)),
55
+ };
56
+ browserCache[stringKey] = entry;
57
+ if (!preload)
58
+ throw entry.promise;
59
+ return undefined;
60
+ }
61
+ const suspendFunction = (key, fn) => query(key, fn);
62
+ exports.suspendFunction = suspendFunction;
63
+ const preloadFunction = (key, fn) => query(key, fn, true);
64
+ exports.preloadFunction = preloadFunction;
@@ -9,7 +9,7 @@ function stripScriptsFromTemplate(template) {
9
9
  var _a;
10
10
  const bootstrapScripts = [];
11
11
  const bootstrapModules = [];
12
- const scripts = template.matchAll(/<script.+?src="(?<script>([^"]+?))".*?><\/script>/g);
12
+ const scripts = template.matchAll(/<script\n*?.+?src="(?<script>([^"]+?))"\n*.*?><\/script>/g);
13
13
  for (const match of scripts) {
14
14
  const scriptName = (_a = match.groups) === null || _a === void 0 ? void 0 : _a.script;
15
15
  if (!scriptName)
@@ -0,0 +1,47 @@
1
+ export interface YouTube {
2
+ autoplay?: 0 | 1;
3
+ cc_lang_pref?: string;
4
+ cc_load_policy?: 1;
5
+ color?: 'red' | 'white';
6
+ controls?: 0 | 1;
7
+ disablekb?: 0 | 1;
8
+ enablejsapi?: 0 | 1;
9
+ end?: number;
10
+ fs?: 0 | 1;
11
+ hl?: string;
12
+ iv_load_policy?: 1 | 3;
13
+ list?: string;
14
+ list_type?: 'playlist' | 'user_uploads';
15
+ loop?: 0 | 1;
16
+ modest_branding?: 1;
17
+ origin?: string;
18
+ playlist?: string;
19
+ plays_inline?: 0 | 1;
20
+ rel?: 0 | 1;
21
+ start?: number;
22
+ widget_referrer?: string;
23
+ }
24
+ declare type VimeoBoolean = 0 | 1 | boolean;
25
+ export interface Vimeo {
26
+ autopause?: VimeoBoolean;
27
+ autoplay?: VimeoBoolean;
28
+ background?: VimeoBoolean;
29
+ byline?: VimeoBoolean;
30
+ color?: string;
31
+ controls?: VimeoBoolean;
32
+ dnt?: VimeoBoolean;
33
+ loop?: VimeoBoolean;
34
+ muted?: VimeoBoolean;
35
+ pip?: VimeoBoolean;
36
+ playsinline?: VimeoBoolean;
37
+ portrait?: VimeoBoolean;
38
+ quality?: '240p' | '360p' | '540p' | '720p' | '1080p' | '2k' | '4k';
39
+ speed?: VimeoBoolean;
40
+ '#t'?: string;
41
+ texttrack?: string;
42
+ title?: VimeoBoolean;
43
+ transparent?: VimeoBoolean;
44
+ }
45
+ export declare function addParametersToEmbeddedVideoUrl(url: string, parameters?: YouTube | Vimeo): string;
46
+ export declare function useEmbeddedVideoUrl(url: string, parameters?: YouTube | Vimeo): string;
47
+ export {};
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useEmbeddedVideoUrl = exports.addParametersToEmbeddedVideoUrl = void 0;
4
+ const react_1 = require("react");
5
+ function addParametersToEmbeddedVideoUrl(url, parameters) {
6
+ if (parameters == null) {
7
+ return url;
8
+ }
9
+ const params = Object.keys(parameters).reduce((accumulator, param) => {
10
+ const value = parameters[param];
11
+ if (value == null) {
12
+ return accumulator;
13
+ }
14
+ return accumulator + `&${param}=${value}`;
15
+ }, '');
16
+ return `${url}?${params}`;
17
+ }
18
+ exports.addParametersToEmbeddedVideoUrl = addParametersToEmbeddedVideoUrl;
19
+ function useEmbeddedVideoUrl(url, parameters) {
20
+ return (0, react_1.useMemo)(() => {
21
+ if (!parameters) {
22
+ return url;
23
+ }
24
+ return addParametersToEmbeddedVideoUrl(url, parameters);
25
+ }, [url, parameters]);
26
+ }
27
+ exports.useEmbeddedVideoUrl = useEmbeddedVideoUrl;
@@ -1 +1 @@
1
- export declare const LIB_VERSION = "0.14.0";
1
+ export declare const LIB_VERSION = "0.16.1";
@@ -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.14.0';
4
+ exports.LIB_VERSION = '0.16.1';
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "engines": {
8
8
  "node": ">=14"
9
9
  },
10
- "version": "0.14.0",
10
+ "version": "0.16.1",
11
11
  "description": "Modern custom Shopify storefronts",
12
12
  "license": "MIT",
13
13
  "main": "dist/esnext/index.js",
@@ -82,25 +82,14 @@ function ReactFlightVitePlugin() {
82
82
  var CLIENT_COMPONENT_GLOB = '**/*.client.[jt]s?(x)';
83
83
  var importerPath = path.dirname(id);
84
84
  var importerToRootPath = vite.normalizePath(path.relative(importerPath, config.root));
85
-
86
- var _ref2 = importerToRootPath.match(/(\.\.\/)+(\.\.)?/) || [],
87
- importerToRootNested = _ref2[0];
88
-
89
- var userPrefix = path.normalize(path.join(importerPath, importerToRootNested.replace(/\/?$/, path.sep)));
90
85
  var userGlob = path.join(importerToRootPath, CLIENT_COMPONENT_GLOB);
91
- var importers = [[userGlob, userPrefix]];
86
+ var importers = [userGlob];
92
87
  clientComponentPaths.forEach(function (componentPath) {
93
- var libPrefix = componentPath + path.sep;
94
- var libGlob = path.join(path.relative(importerPath, componentPath), CLIENT_COMPONENT_GLOB);
95
- importers.push([libGlob, libPrefix]);
88
+ importers.push(path.join(path.relative(importerPath, componentPath), CLIENT_COMPONENT_GLOB));
96
89
  });
97
- var injectedGlobs = "Object.assign(Object.create(null), " + importers.map(function (_ref3) {
98
- var glob = _ref3[0],
99
- prefix = _ref3[1];
90
+ var injectedGlobs = "Object.assign(Object.create(null), " + importers.map(function (glob) {
100
91
  return (// Mark the globs to modify the result after Vite resolves them.
101
- // The prefix is used later to turn relative imports
102
- // into absolute imports, and then into hashes.
103
- "/* HASH_BEGIN " + vite.normalizePath(prefix) + " */ " + ("import.meta.glob('" + vite.normalizePath(glob) + "') /* HASH_END */")
92
+ "/* HASH_BEGIN */ " + ("import.meta.glob('" + vite.normalizePath(glob) + "') /* HASH_END */")
104
93
  );
105
94
  }).join(', ') + ");";
106
95
  return code.replace(INJECTING_RE, injectedGlobs);
@@ -157,8 +146,8 @@ async function proxyClientComponent(filepath, src) {
157
146
  exportStatements.forEach(function (key) {
158
147
  var isDefault = key === DEFAULT_EXPORT;
159
148
  var componentName = isDefault ? getComponentFilename(filepath) : key;
160
- proxyCode += "export " + (isDefault ? DEFAULT_EXPORT : "const " + componentName + " =") + " wrapInClientProxy({ name: '" + componentName + "', id: '" + getComponentId(filepath) + "', component: allImports['" + key + "'], named: " + // eslint-disable-next-line react-internal/safe-string-coercion
161
- String(!isDefault) + " });\n";
149
+ proxyCode += "export " + (isDefault ? DEFAULT_EXPORT : "const " + componentName + " =") + " wrapInClientProxy({ name: '" + componentName + "', id: '" + getComponentId(filepath) + "', value: allImports['" + key + "'], isDefault: " + // eslint-disable-next-line react-internal/safe-string-coercion
150
+ String(isDefault) + " });\n";
162
151
  });
163
152
  return proxyCode;
164
153
  }
@@ -168,11 +157,10 @@ var hashImportsPlugin = {
168
157
  transform: function (code, id) {
169
158
  // Turn relative import paths to lossy hashes
170
159
  if (rscViteFileRE.test(id)) {
171
- var nestedRE = /\.\.\//gm;
172
- return code.replace(/\/\*\s*HASH_BEGIN\s*(.+?)\s*\*\/\s*([^]+?)\/\*\s*HASH_END\s*\*\//gm, function (_, prefix, imports) {
160
+ return code.replace(/\/\*\s*HASH_BEGIN\s*\*\/\s*([^]+?)\/\*\s*HASH_END\s*\*\//gm, function (_, imports) {
173
161
  return imports.trim().replace(/"([^"]+?)":/gm, function (__, relativePath) {
174
- var absolutePath = prefix + relativePath.replace(nestedRE, '');
175
- return "\"" + getComponentId(absolutePath) + "\":";
162
+ var absolutePath = path.resolve(path.dirname(id.split('?')[0]), relativePath);
163
+ return "\"" + getComponentId(vite.normalizePath(absolutePath)) + "\":";
176
164
  });
177
165
  });
178
166
  }