@okendo/shopify-hydrogen 0.0.11 → 1.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 (49) hide show
  1. package/LICENSE.txt +3 -0
  2. package/README.md +2 -5
  3. package/dist/esnext/components/OkendoProvider.server.d.ts +0 -2
  4. package/dist/esnext/components/OkendoProvider.server.js +10 -11
  5. package/dist/esnext/components/OkendoReviewsWidget.server.js +4 -6
  6. package/dist/esnext/components/OkendoStarRating.server.js +2 -3
  7. package/dist/esnext/components/OkendoWidget.client.js +0 -1
  8. package/dist/esnext/components/index.js +0 -1
  9. package/dist/esnext/framework/index.d.ts +0 -0
  10. package/dist/esnext/framework/index.js +1 -0
  11. package/dist/{node/plugin → esnext/framework/plugins}/extendViteOptimizeDeps.d.ts +0 -0
  12. package/dist/esnext/framework/plugins/extendViteOptimizeDeps.js +10 -0
  13. package/dist/esnext/framework/plugins/plugin.d.ts +7 -0
  14. package/dist/esnext/framework/plugins/plugin.js +9 -0
  15. package/dist/esnext/framework/plugins/suppressModuleWarning.d.ts +3 -0
  16. package/dist/esnext/framework/plugins/suppressModuleWarning.js +18 -0
  17. package/dist/esnext/index.js +0 -1
  18. package/dist/esnext/shared/errorUtils.js +0 -1
  19. package/dist/esnext/shared/index.js +0 -1
  20. package/dist/esnext/shared/productUtils.js +0 -1
  21. package/dist/esnext/shared/requestUtils.d.ts +1 -2
  22. package/dist/esnext/shared/requestUtils.js +4 -7
  23. package/dist/esnext/shared/sharedTypes.js +0 -1
  24. package/dist/node/framework/index.d.ts +0 -0
  25. package/dist/node/framework/index.js +1 -0
  26. package/dist/node/framework/plugins/extendViteOptimizeDeps.d.ts +2 -0
  27. package/dist/node/{plugin → framework/plugins}/extendViteOptimizeDeps.js +0 -1
  28. package/dist/node/framework/plugins/plugin.d.ts +4 -0
  29. package/dist/node/framework/plugins/plugin.js +14 -0
  30. package/dist/node/framework/plugins/suppressModuleWarning.d.ts +3 -0
  31. package/dist/node/framework/plugins/suppressModuleWarning.js +20 -0
  32. package/package.json +21 -7
  33. package/plugin.cjs +1 -0
  34. package/dist/esnext/components/OkendoProvider.server.js.map +0 -1
  35. package/dist/esnext/components/OkendoReviewsWidget.server.js.map +0 -1
  36. package/dist/esnext/components/OkendoStarRating.server.js.map +0 -1
  37. package/dist/esnext/components/OkendoWidget.client.js.map +0 -1
  38. package/dist/esnext/components/index.js.map +0 -1
  39. package/dist/esnext/index.js.map +0 -1
  40. package/dist/esnext/shared/errorUtils.js.map +0 -1
  41. package/dist/esnext/shared/index.js.map +0 -1
  42. package/dist/esnext/shared/productUtils.js.map +0 -1
  43. package/dist/esnext/shared/requestUtils.js.map +0 -1
  44. package/dist/esnext/shared/sharedTypes.js.map +0 -1
  45. package/dist/node/plugin/extendViteOptimizeDeps.js.map +0 -1
  46. package/dist/node/plugin/index.d.ts +0 -3
  47. package/dist/node/plugin/index.js +0 -9
  48. package/dist/node/plugin/index.js.map +0 -1
  49. package/plugin.js +0 -1
package/LICENSE.txt ADDED
@@ -0,0 +1,3 @@
1
+ UNLICENSED
2
+
3
+ Please contact support@okendo.io for licensing.
package/README.md CHANGED
@@ -325,19 +325,18 @@ mutation {
325
325
  ```
326
326
 
327
327
  5. Open **App.server.jsx** and import `OkendoProvider`.
328
- 6. Include the `OkendoProvider` as shown below, passing through the `request` prop from the main `App` and your `subscriberId` from your Vite environment variables.
328
+ 6. Include the `OkendoProvider` as shown below, passing through your `subscriberId` from your Vite environment variables.
329
329
 
330
330
  ```tsx
331
331
  /* App.server.jsx */
332
332
  import {OkendoProvider} from '@okendo/shopify-hydrogen';
333
333
 
334
- function App({request}) {
334
+ function App() {
335
335
  return (
336
336
  <Suspense fallback={<LoadingFallback />}>
337
337
  <ShopifyProvider>
338
338
  <!-- *** Include OkendoProvider HERE *** -->
339
339
  <OkendoProvider
340
- request={request}
341
340
  subscriberId={import.meta.env.VITE_OKENDO_SUBSCRIBER_ID}
342
341
  />
343
342
  <ServerCartProvider>
@@ -358,7 +357,6 @@ mutation {
358
357
 
359
358
  ``` tsx
360
359
  <OkendoProvider
361
- request={request}
362
360
  subscriberId={okendoSubscriberId}
363
361
  />
364
362
  ```
@@ -405,7 +403,6 @@ It will provide:
405
403
 
406
404
  | Name | Type | Description | Required |
407
405
  | ------------------------------------- | ----------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
408
- | <code>request</code> | <code>HydrogenRequest</code> | The request passed into <code>App.server.jsx</code> | yes |
409
406
  | <code>subscriberId</code> | <code>string</code> | The Okendo subscriber ID. | yes |
410
407
  | <code>apiDomain</code> | <code>string</code> | To override the default Okendo API Domain. (Default: <code>api.okendo.io/v1</code>) | no |
411
408
  | <code>cdnDomain</code> | <code>string</code> | To override the default Okendo CDN domain. (Default: <code>cdn-static.okendo.io</code>) | no |
@@ -1,12 +1,10 @@
1
1
  import React from 'react';
2
- import { HydrogenRequest } from '@shopify/hydrogen/dist/esnext/foundation/HydrogenRequest/HydrogenRequest.server';
3
2
  export declare const OkendoProvider: React.FunctionComponent<OkendoProviderProps>;
4
3
  interface OkendoProviderProps {
5
4
  apiDomain?: string;
6
5
  cdnDomain?: string;
7
6
  children?: React.ReactNode;
8
7
  productUrlFormatOverride?: (product: ReviewProduct) => string;
9
- request: HydrogenRequest;
10
8
  subscriberId: string;
11
9
  }
12
10
  interface ReviewProduct {
@@ -1,38 +1,38 @@
1
1
  import React from 'react';
2
2
  import parse from 'html-react-parser';
3
- import { fetchSync, useShopQuery, gql, CacheMinutes } from '@shopify/hydrogen';
4
- import { Head } from '@shopify/hydrogen/client';
3
+ import { fetchSync, useShopQuery, gql, CacheShort } from '@shopify/hydrogen';
4
+ import { Head } from '@shopify/hydrogen';
5
5
  import { okendoError, setInOkendoRequestContext } from '../shared';
6
6
  const kDefaultOkendoApiDomain = 'api.okendo.io/v1';
7
7
  const kDefaultOkendoCdnDomain = 'cdn-static.okendo.io';
8
8
  export const OkendoProvider = (props) => {
9
- const { apiDomain, cdnDomain, children, productUrlFormatOverride, request, subscriberId } = props;
9
+ const { apiDomain, cdnDomain, children, productUrlFormatOverride, subscriberId } = props;
10
10
  // Download subscriber widget plus settings.
11
- const url = `https://${apiDomain !== null && apiDomain !== void 0 ? apiDomain : kDefaultOkendoApiDomain}/stores/${subscriberId}/widget_plus_settings`;
11
+ const url = `https://${apiDomain ?? kDefaultOkendoApiDomain}/stores/${subscriberId}/widget_plus_settings`;
12
12
  const settingsResponse = fetchSync(url, { preload: true });
13
13
  if (!settingsResponse.response.ok) {
14
14
  console.error(okendoError('Failed to retrieve subscriber settings. Please check your environment variables.'));
15
- setInOkendoRequestContext(request, 'setupFailed', true);
15
+ setInOkendoRequestContext('setupFailed', true);
16
16
  return null;
17
17
  }
18
18
  const { cssVariables, customCss, reviewsHeaderConfig, starSymbols } = settingsResponse.json();
19
19
  const cssVariablesNormalized = cssVariables.replace('<style id="oke-css-vars">', '').replace('</style>', '');
20
20
  const customCssNormalized = customCss ? customCss.replace('<style id="oke-reviews-custom-css">', '').replace('</style>', '') : '';
21
21
  // Download contents of widget initialisation script.
22
- const initScriptResponse = fetchSync(`https://${cdnDomain !== null && cdnDomain !== void 0 ? cdnDomain : kDefaultOkendoCdnDomain}/reviews-widget-plus/js/okendo-reviews.js`, {
23
- cache: CacheMinutes(),
22
+ const initScriptResponse = fetchSync(`https://${cdnDomain ?? kDefaultOkendoCdnDomain}/reviews-widget-plus/js/okendo-reviews.js`, {
23
+ cache: CacheShort(),
24
24
  preload: true
25
25
  });
26
26
  if (!initScriptResponse.response.ok) {
27
27
  console.error(okendoError('Failed to retrieve widget initialization script.'));
28
- setInOkendoRequestContext(request, 'setupFailed', true);
28
+ setInOkendoRequestContext('setupFailed', true);
29
29
  return null;
30
30
  }
31
31
  const initScriptContents = initScriptResponse.text();
32
32
  // Set up product URL formatter.
33
33
  const productUrlFormatter = typeof productUrlFormatOverride === 'function'
34
34
  ? productUrlFormatOverride
35
- : (product) => (product === null || product === void 0 ? void 0 : product.productHandle)
35
+ : (product) => product?.productHandle
36
36
  ? `/products/${product.productHandle}/${product.variantId ? '?variantId=' + product.variantId : ''}`
37
37
  : undefined;
38
38
  // Get pre-rendered style settings.
@@ -49,7 +49,7 @@ export const OkendoProvider = (props) => {
49
49
  query: query,
50
50
  preload: true
51
51
  });
52
- const preRenderStyleTags = (widgetPreRenderStyleTags === null || widgetPreRenderStyleTags === void 0 ? void 0 : widgetPreRenderStyleTags.value) ? parse(widgetPreRenderStyleTags.value) : '';
52
+ const preRenderStyleTags = widgetPreRenderStyleTags?.value ? parse(widgetPreRenderStyleTags.value) : '';
53
53
  if (!preRenderStyleTags) {
54
54
  console.warn(okendoError('Failed to retrieve pre-rendered widget style settings.'));
55
55
  }
@@ -65,4 +65,3 @@ export const OkendoProvider = (props) => {
65
65
  parse(starSymbols),
66
66
  children));
67
67
  };
68
- //# sourceMappingURL=OkendoProvider.server.js.map
@@ -4,7 +4,6 @@ import { useShopQuery, gql } from '@shopify/hydrogen';
4
4
  import { OkendoWidgetClient } from './OkendoWidget.client';
5
5
  import { getOkendoProductId, useOkendoRequestContext, widgetMetafieldError } from '../shared';
6
6
  export const OkendoReviewsWidget = (props) => {
7
- var _a, _b, _c, _d, _e, _f;
8
7
  const { setupFailed } = useOkendoRequestContext();
9
8
  if (setupFailed) {
10
9
  return null;
@@ -36,10 +35,10 @@ export const OkendoReviewsWidget = (props) => {
36
35
  productId
37
36
  }
38
37
  });
39
- if (productId && !((_a = product === null || product === void 0 ? void 0 : product.reviewsWidgetSnippet) === null || _a === void 0 ? void 0 : _a.value)) {
38
+ if (productId && !product?.reviewsWidgetSnippet?.value) {
40
39
  console.warn(widgetMetafieldError('OkendoReviewsWidget', 'ReviewsWidgetSnippet'));
41
40
  }
42
- if (!((_b = shop === null || shop === void 0 ? void 0 : shop.widgetPreRenderBodyStyleTags) === null || _b === void 0 ? void 0 : _b.value)) {
41
+ if (!shop?.widgetPreRenderBodyStyleTags?.value) {
43
42
  console.warn(widgetMetafieldError('OkendoReviewsWidget', 'WidgetPreRenderBodyStyleTags'));
44
43
  }
45
44
  const dataAttributes = {
@@ -52,8 +51,7 @@ export const OkendoReviewsWidget = (props) => {
52
51
  }
53
52
  }
54
53
  return (React.createElement(React.Fragment, null,
55
- parse((_d = (_c = shop === null || shop === void 0 ? void 0 : shop.widgetPreRenderBodyStyleTags) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : ''),
56
- React.createElement(OkendoWidgetClient, { dataAttributes: dataAttributes, metafieldContent: (_f = (_e = product === null || product === void 0 ? void 0 : product.reviewsWidgetSnippet) === null || _e === void 0 ? void 0 : _e.value) !== null && _f !== void 0 ? _f : '' })));
54
+ parse(shop?.widgetPreRenderBodyStyleTags?.value ?? ''),
55
+ React.createElement(OkendoWidgetClient, { dataAttributes: dataAttributes, metafieldContent: product?.reviewsWidgetSnippet?.value ?? '' })));
57
56
  };
58
57
  export default OkendoReviewsWidget;
59
- //# sourceMappingURL=OkendoReviewsWidget.server.js.map
@@ -29,7 +29,7 @@ export const OkendoStarRating = (props) => {
29
29
  productId
30
30
  }
31
31
  });
32
- if (!(starRatingSnippet === null || starRatingSnippet === void 0 ? void 0 : starRatingSnippet.value)) {
32
+ if (!starRatingSnippet?.value) {
33
33
  console.warn(widgetMetafieldError('OkendoStarRating', 'StarRatingSnippet'));
34
34
  }
35
35
  const dataAttributes = {
@@ -37,7 +37,6 @@ export const OkendoStarRating = (props) => {
37
37
  'data-oke-reviews-product-id': okendoProductId,
38
38
  'data-oke-scroll-disabled': 'true'
39
39
  };
40
- return (React.createElement(OkendoWidgetClient, { dataAttributes: dataAttributes, metafieldContent: starRatingSnippet === null || starRatingSnippet === void 0 ? void 0 : starRatingSnippet.value }));
40
+ return (React.createElement(OkendoWidgetClient, { dataAttributes: dataAttributes, metafieldContent: starRatingSnippet?.value }));
41
41
  };
42
42
  export default OkendoStarRating;
43
- //# sourceMappingURL=OkendoStarRating.server.js.map
@@ -17,4 +17,3 @@ export const OkendoWidgetClient = (props) => {
17
17
  }, []);
18
18
  return (React.createElement("div", { ref: widgetContainer, ...dataAttributes, dangerouslySetInnerHTML: { __html: metafieldContent } }));
19
19
  };
20
- //# sourceMappingURL=OkendoWidget.client.js.map
@@ -1,4 +1,3 @@
1
1
  export * from './OkendoReviewsWidget.server';
2
2
  export * from './OkendoStarRating.server';
3
3
  export * from './OkendoProvider.server';
4
- //# sourceMappingURL=index.js.map
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,10 @@
1
+ export const extendViteOptimizeDeps = () => ({
2
+ name: 'vite-plugin-okendo-extend-optimize-deps',
3
+ config: () => ({
4
+ optimizeDeps: {
5
+ include: [
6
+ '@okendo/shopify-hydrogen > html-react-parser'
7
+ ]
8
+ }
9
+ })
10
+ });
@@ -0,0 +1,7 @@
1
+ import type { Plugin } from 'vite';
2
+ declare const okendoPlugin: {
3
+ (): Plugin[];
4
+ default: any;
5
+ };
6
+ export = okendoPlugin;
7
+ export default okendoPlugin;
@@ -0,0 +1,9 @@
1
+ import { extendViteOptimizeDeps } from './extendViteOptimizeDeps';
2
+ import suppressModuleWarning from './suppressModuleWarning';
3
+ const okendoPlugin = () => {
4
+ return [
5
+ extendViteOptimizeDeps(),
6
+ suppressModuleWarning()
7
+ ];
8
+ };
9
+ export default okendoPlugin; // For ESM
@@ -0,0 +1,3 @@
1
+ import { Plugin } from 'vite';
2
+ declare const _default: () => Plugin;
3
+ export default _default;
@@ -0,0 +1,18 @@
1
+ /* Inspired by Hydrogen 1.0.0 source hydrogen\packages\hydrogen\src\framework\plugins\vite-plugin-hydrogen-suppress-warnings.ts */
2
+ export default () => {
3
+ return {
4
+ name: 'okendo:suppress-warnings',
5
+ configResolved(config) {
6
+ // TODO: Fix the actual issues that cause these warnings
7
+ const filterOut = (msg) => msg.startsWith("@okendo/shopify-hydrogen doesn't appear to be written in CJS");
8
+ for (const method of ['warn', 'warnOnce']) {
9
+ const original = config.logger[method];
10
+ config.logger[method] = (msg, ...args) => {
11
+ if (filterOut(msg))
12
+ return;
13
+ return original(msg, ...args);
14
+ };
15
+ }
16
+ },
17
+ };
18
+ };
@@ -1,3 +1,2 @@
1
1
  export * from './components';
2
2
  export * from './shared';
3
- //# sourceMappingURL=index.js.map
@@ -7,4 +7,3 @@ export function widgetConfigurationError(widgetName, message) {
7
7
  export function widgetMetafieldError(widgetName, metafieldName) {
8
8
  return okendoError(`${widgetName} error: Failed to retrieve metafield '${metafieldName}'.`);
9
9
  }
10
- //# sourceMappingURL=errorUtils.js.map
@@ -2,4 +2,3 @@ export * from './errorUtils';
2
2
  export * from './productUtils';
3
3
  export * from './requestUtils';
4
4
  export * from './sharedTypes';
5
- //# sourceMappingURL=index.js.map
@@ -13,4 +13,3 @@ export function getOkendoProductId(productId) {
13
13
  ? productId
14
14
  : productId.split('/').slice(-1)[0]}`;
15
15
  }
16
- //# sourceMappingURL=productUtils.js.map
@@ -1,6 +1,5 @@
1
- import { HydrogenRequest } from '@shopify/hydrogen/dist/esnext/foundation/HydrogenRequest/HydrogenRequest.server';
2
1
  import { SKO } from './sharedTypes';
3
- export declare function setInOkendoRequestContext(request: HydrogenRequest, key: keyof OkendoRequestContextKeys, value: RequestContextSafeType | RequestContextSafeType[]): void;
2
+ export declare function setInOkendoRequestContext(key: keyof OkendoRequestContextKeys, value: RequestContextSafeType | RequestContextSafeType[]): void;
4
3
  export declare function useOkendoRequestContext(): OkendoRequestContext;
5
4
  interface OkendoRequestContextKeys {
6
5
  setupFailed: boolean;
@@ -1,11 +1,8 @@
1
- import { useServerRequest } from '@shopify/hydrogen/dist/esnext/foundation/ServerRequestProvider';
2
- export function setInOkendoRequestContext(request, key, value) {
3
- const okendoRequestContext = request.ctx.okendoRequestContext || {};
1
+ import { useRequestContext } from '@shopify/hydrogen';
2
+ export function setInOkendoRequestContext(key, value) {
3
+ const okendoRequestContext = useOkendoRequestContext();
4
4
  okendoRequestContext[key] = value;
5
- request.ctx.okendoRequestContext = okendoRequestContext;
6
5
  }
7
6
  export function useOkendoRequestContext() {
8
- const { ctx: { okendoRequestContext } } = useServerRequest();
9
- return okendoRequestContext || {};
7
+ return useRequestContext('okendo');
10
8
  }
11
- //# sourceMappingURL=requestUtils.js.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=sharedTypes.js.map
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,2 @@
1
+ import type { Plugin } from 'vite';
2
+ export declare const extendViteOptimizeDeps: () => Plugin;
@@ -12,4 +12,3 @@ const extendViteOptimizeDeps = () => ({
12
12
  })
13
13
  });
14
14
  exports.extendViteOptimizeDeps = extendViteOptimizeDeps;
15
- //# sourceMappingURL=extendViteOptimizeDeps.js.map
@@ -0,0 +1,4 @@
1
+ import type { Plugin } from 'vite';
2
+ declare const okendoPlugin: () => Plugin[];
3
+ export = okendoPlugin;
4
+ export default okendoPlugin;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const extendViteOptimizeDeps_1 = require("./extendViteOptimizeDeps");
6
+ const suppressModuleWarning_1 = __importDefault(require("./suppressModuleWarning"));
7
+ const okendoPlugin = () => {
8
+ return [
9
+ (0, extendViteOptimizeDeps_1.extendViteOptimizeDeps)(),
10
+ (0, suppressModuleWarning_1.default)()
11
+ ];
12
+ };
13
+ exports.default = okendoPlugin; // For ESM
14
+ module.exports = okendoPlugin;
@@ -0,0 +1,3 @@
1
+ import { Plugin } from 'vite';
2
+ declare const _default: () => Plugin;
3
+ export default _default;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /* Inspired by Hydrogen 1.0.0 source hydrogen\packages\hydrogen\src\framework\plugins\vite-plugin-hydrogen-suppress-warnings.ts */
4
+ exports.default = () => {
5
+ return {
6
+ name: 'okendo:suppress-warnings',
7
+ configResolved(config) {
8
+ // TODO: Fix the actual issues that cause these warnings
9
+ const filterOut = (msg) => msg.startsWith("@okendo/shopify-hydrogen doesn't appear to be written in CJS");
10
+ for (const method of ['warn', 'warnOnce']) {
11
+ const original = config.logger[method];
12
+ config.logger[method] = (msg, ...args) => {
13
+ if (filterOut(msg))
14
+ return;
15
+ return original(msg, ...args);
16
+ };
17
+ }
18
+ },
19
+ };
20
+ };
package/package.json CHANGED
@@ -1,29 +1,43 @@
1
1
  {
2
2
  "name": "@okendo/shopify-hydrogen",
3
- "version": "0.0.11",
3
+ "version": "1.0.0",
4
4
  "description": "A component library containing Okendo Reviews React components.",
5
5
  "main": "dist/esnext/index.js",
6
+ "engines": {
7
+ "node": ">=14"
8
+ },
9
+ "exports": {
10
+ ".": "./dist/esnext/index.js",
11
+ "./plugin": {
12
+ "import": "./dist/esnext/framework/plugins/plugin.js",
13
+ "require": "./dist/node/framework/plugins/plugin.js"
14
+ },
15
+ "./plugin.cjs": "./plugin.cjs",
16
+ "./package.json": "./package.json",
17
+ "./*": "./dist/esnext/*.js"
18
+ },
19
+ "types": "dist/esnext/index.d.ts",
6
20
  "files": [
7
21
  "dist",
8
- "plugin.js"
22
+ "plugin.cjs"
9
23
  ],
10
24
  "scripts": {
11
- "build": "rimraf dist/ && npm run build:plugin:cjs && npm run build:esm",
25
+ "build": "rimraf dist/ && npm run build:esm && npm run build:plugin:cjs",
12
26
  "build:plugin:cjs": "tsc --p tsconfig.plugin.cjs.json",
13
27
  "build:esm": "tsc --p tsconfig.esm.json",
14
28
  "prepublishOnly": "npm run build"
15
29
  },
16
30
  "author": "Okendo",
17
- "license": "MIT",
31
+ "license": "SEE LICENSE IN LICENSE.txt",
18
32
  "dependencies": {
19
33
  "html-react-parser": "^1.4.13"
20
34
  },
21
35
  "devDependencies": {
22
36
  "@okendo/reviews-widget-plus": "^0.39.0",
23
37
  "@okendo/tsconfig": "0.0.2",
24
- "@shopify/hydrogen": "^0.23.0",
38
+ "@shopify/hydrogen": "^1.0.0",
25
39
  "@types/node": "^17.0.35",
26
- "@types/react": "^18.0.9",
40
+ "@types/react": "^18.0.14",
27
41
  "@types/react-dom": "^18.0.5",
28
42
  "dotenv": "^16.0.1",
29
43
  "rimraf": "^3.0.2",
@@ -31,6 +45,6 @@
31
45
  "vite": "^2.9.0"
32
46
  },
33
47
  "peerDependencies": {
34
- "@shopify/hydrogen": "0.23.x"
48
+ "@shopify/hydrogen": "1.0.x"
35
49
  }
36
50
  }
package/plugin.cjs ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/node/framework/plugin');
@@ -1 +0,0 @@
1
- {"version":3,"file":"OkendoProvider.server.js","sourceRoot":"","sources":["../../../src/components/OkendoProvider.server.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,MAAM,mBAAmB,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAIhD,OAAO,EAAE,WAAW,EAAE,yBAAyB,EAAO,MAAM,WAAW,CAAC;AAExE,MAAM,uBAAuB,GAAG,kBAAkB,CAAC;AACnD,MAAM,uBAAuB,GAAG,sBAAsB,CAAC;AAEvD,MAAM,CAAC,MAAM,cAAc,GAAiD,CAAC,KAAK,EAAsB,EAAE;IACtG,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,wBAAwB,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC;IAElG,4CAA4C;IAC5C,MAAM,GAAG,GAAG,WAAW,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,uBAAuB,WAAW,YAAY,uBAAuB,CAAC;IAC1G,MAAM,gBAAgB,GAAG,SAAS,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IAE3D,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC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C,CAAA","sourcesContent":["import React from 'react';\nimport parse from 'html-react-parser';\nimport { fetchSync, useShopQuery, gql, CacheMinutes } from '@shopify/hydrogen';\nimport { Head } from '@shopify/hydrogen/client';\nimport { HydrogenRequest } from '@shopify/hydrogen/dist/esnext/foundation/HydrogenRequest/HydrogenRequest.server';\nimport type { Metafield } from '@shopify/hydrogen/dist/esnext/storefront-api-types';\n\nimport { okendoError, setInOkendoRequestContext, SKO } from '../shared';\n\nconst kDefaultOkendoApiDomain = 'api.okendo.io/v1';\nconst kDefaultOkendoCdnDomain = 'cdn-static.okendo.io';\n\nexport const OkendoProvider: React.FunctionComponent<OkendoProviderProps> = (props): JSX.Element | null => {\n const { apiDomain, cdnDomain, children, productUrlFormatOverride, request, subscriberId } = props;\n\n // Download subscriber widget plus settings.\n const url = `https://${apiDomain ?? kDefaultOkendoApiDomain}/stores/${subscriberId}/widget_plus_settings`;\n const settingsResponse = fetchSync(url, { preload: true });\n\n if (!settingsResponse.response.ok) {\n console.error(okendoError('Failed to retrieve subscriber settings. Please check your environment variables.'));\n setInOkendoRequestContext(request, 'setupFailed', true);\n return null;\n }\n\n const { cssVariables, customCss, reviewsHeaderConfig, starSymbols } = settingsResponse.json() as WidgetPlusSettingsResponse;\n const cssVariablesNormalized = cssVariables.replace('<style id=\"oke-css-vars\">', '').replace('</style>', '');\n const customCssNormalized = customCss ? customCss.replace('<style id=\"oke-reviews-custom-css\">', '').replace('</style>', '') : '';\n\n // Download contents of widget initialisation script.\n const initScriptResponse = fetchSync(`https://${cdnDomain ?? kDefaultOkendoCdnDomain}/reviews-widget-plus/js/okendo-reviews.js`, {\n cache: CacheMinutes(),\n preload: true\n });\n\n if (!initScriptResponse.response.ok) {\n console.error(okendoError('Failed to retrieve widget initialization script.'));\n setInOkendoRequestContext(request, 'setupFailed', true);\n return null;\n }\n\n const initScriptContents = initScriptResponse.text();\n\n // Set up product URL formatter.\n const productUrlFormatter = typeof productUrlFormatOverride === 'function'\n ? productUrlFormatOverride\n : (product: ReviewProduct) =>\n product?.productHandle\n ? `/products/${product.productHandle}/${product.variantId ? '?variantId=' + product.variantId : ''}`\n : undefined;\n\n // Get pre-rendered style settings.\n const query = gql`\n query metafields {\n shop {\n widgetPreRenderStyleTags: metafield(namespace: \"okendo\", key: \"WidgetPreRenderStyleTags\") {\n value\n }\n }\n }\n `;\n\n const {\n data: { shop: { widgetPreRenderStyleTags } }\n } = useShopQuery<OkendoProviderMetafields>({\n query: query,\n preload: true\n });\n\n const preRenderStyleTags = widgetPreRenderStyleTags?.value ? parse(widgetPreRenderStyleTags.value) : '';\n\n if (!preRenderStyleTags) {\n console.warn(okendoError('Failed to retrieve pre-rendered widget style settings.'));\n }\n\n return (\n <>\n <Head>\n <script id=\"oke-reviews-settings\" type=\"application/json\">{JSON.stringify(reviewsHeaderConfig)}</script>\n <style id=\"oke-css-vars\">{cssVariablesNormalized}</style>\n {customCssNormalized && <style id=\"oke-reviews-custom-css\">{customCssNormalized}</style>}\n <meta name=\"oke:subscriber_id\" content={subscriberId} />\n <script>{initScriptContents}</script>\n {productUrlFormatter && <script type=\"text/javascript\">{`window.okeProductUrlFormatter = ${productUrlFormatter}`}</script>}\n </Head>\n {preRenderStyleTags}\n {parse(starSymbols)}\n {children}\n </>\n );\n}\n\ninterface OkendoProviderProps {\n apiDomain?: string;\n cdnDomain?: string;\n children?: React.ReactNode;\n productUrlFormatOverride?: (product: ReviewProduct) => string;\n request: HydrogenRequest;\n subscriberId: string;\n}\n\ninterface OkendoProviderMetafields {\n shop: {\n widgetPreRenderStyleTags?: Pick<Metafield, 'value'>\n };\n}\n\ninterface ReviewProduct {\n productHandle?: string;\n productId: string;\n variantId?: string;\n}\n\ninterface WidgetPlusSettingsResponse {\n reviewsHeaderConfig: SKO;\n cssVariables: string;\n starSymbols: string;\n customCss?: string;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"OkendoReviewsWidget.server.js","sourceRoot":"","sources":["../../../src/components/OkendoReviewsWidget.server.tsx"],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AAO,CAAC,IAAI,CAAC,oBAAoB,CAAC,qBAAqB,EAAE,8BAA8B,CAAC,CAAC,CAAC;KAC7F;IAED,MAAM,cAAc,GAAQ;QACxB,iBAAiB,EAAE,EAAE;KACxB,CAAC;IAEF,IAAI,SAAS,EAAE;QACX,MAAM,eAAe,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAC;QACtD,IAAI,eAAe,EAAE;YACjB,cAAc,CAAC,6BAA6B,CAAC,GAAG,eAAe,CAAC;SACnE;KACJ;IAED,OAAO,CACH;QACK,KAAK,CAAC,MAAA,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,4BAA4B,0CAAE,KAAK,mCAAI,EAAE,CAAC;QACvD,oBAAC,kBAAkB,IAAC,cAAc,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,oBAAoB,0CAAE,KAAK,mCAAI,EAAE,GAAI,CACrH,CACN,CAAC;AACN,CAAC,CAAC;AAeF,eAAe,mBAAmB,CAAC","sourcesContent":["import React from 'react';\nimport parse from 'html-react-parser';\nimport { useShopQuery, gql } from '@shopify/hydrogen';\nimport type { Metafield } from '@shopify/hydrogen/dist/esnext/storefront-api-types';\n\nimport { OkendoWidgetClient } from './OkendoWidget.client';\nimport { getOkendoProductId, SKO, useOkendoRequestContext, widgetMetafieldError } from '../shared';\n\nexport const OkendoReviewsWidget: React.FunctionComponent<OkendoReviewsWidgetProps> = (props): React.ReactElement | null => {\n const { setupFailed } = useOkendoRequestContext();\n if (setupFailed) {\n return null;\n }\n\n const { productId } = props;\n\n const productQuery = productId\n ? `\n product(id: $productId) {\n reviewsWidgetSnippet: metafield(namespace: \"okendo\", key: \"ReviewsWidgetSnippet\") {\n value\n }\n }\n `\n : '';\n\n const query = gql`\n query metafields${productId ? '($productId: ID!)' : ''} {\n ${productQuery}\n shop {\n widgetPreRenderBodyStyleTags: metafield(namespace: \"okendo\", key: \"WidgetPreRenderBodyStyleTags\") {\n value\n }\n }\n }\n `;\n\n const {\n data: { product, shop }\n } = useShopQuery<OkendoReviewsWidgetMetafields>({\n query: query,\n preload: true,\n variables: {\n productId\n }\n });\n\n if (productId && !product?.reviewsWidgetSnippet?.value) {\n console.warn(widgetMetafieldError('OkendoReviewsWidget', 'ReviewsWidgetSnippet'));\n }\n\n if (!shop?.widgetPreRenderBodyStyleTags?.value) {\n console.warn(widgetMetafieldError('OkendoReviewsWidget', 'WidgetPreRenderBodyStyleTags'));\n }\n\n const dataAttributes: SKO = {\n 'data-oke-widget': ''\n };\n\n if (productId) {\n const okendoProductId = getOkendoProductId(productId);\n if (okendoProductId) {\n dataAttributes['data-oke-reviews-product-id'] = okendoProductId;\n }\n }\n\n return (\n <>\n {parse(shop?.widgetPreRenderBodyStyleTags?.value ?? '')}\n <OkendoWidgetClient dataAttributes={dataAttributes} metafieldContent={product?.reviewsWidgetSnippet?.value ?? ''} />\n </>\n );\n};\n\ninterface OkendoReviewsWidgetProps {\n productId?: string;\n}\n\ninterface OkendoReviewsWidgetMetafields {\n product: {\n reviewsWidgetSnippet?: Pick<Metafield, 'value'>;\n };\n shop: {\n widgetPreRenderBodyStyleTags?: Pick<Metafield, 'value'>;\n };\n}\n\nexport default OkendoReviewsWidget;\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"OkendoStarRating.server.js","sourceRoot":"","sources":["../../../src/components/OkendoStarRating.server.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAGtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAExH,MAAM,CAAC,MAAM,gBAAgB,GAAmD,CAAC,KAAK,EAA6B,EAAE;IACjH,MAAM,EAAE,WAAW,EAAE,GAAG,uBAAuB,EAAE,CAAC;IAClD,IAAI,WAAW,EAAE;QACb,OAAO,IAAI,CAAC;KACf;IAED,MAAM,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC;IAE5B,MAAM,eAAe,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAC;IACtD,IAAI,CAAC,eAAe,EAAE;QAClB,OAAO,CAAC,KAAK,CAAC,wBAAwB,CAAC,kBAAkB,EAAE,4BAA4B,CAAC,CAAC,CAAC;QAC1F,OAAO,IAAI,CAAC;KACf;IAED,MAAM,KAAK,GAAG,GAAG,CAAA;;;;;;;;KAQhB,CAAC;IAEF,MAAM,EACF,IAAI,EAAE,EACF,OAAO,EAAE,EAAE,iBAAiB,EAAE,EACjC,EACJ,GAAG,YAAY,CAA6B;QACzC,KAAK,EAAE,KAAK;QACZ,OAAO,EAAE,IAAI;QACb,SAAS,EAAE;YACP,SAAS;SACZ;KACJ,CAAC,CAAC;IAEH,IAAI,CAAC,CAAA,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,KAAK,CAAA,EAAE;QAC3B,OAAO,CAAC,IAAI,CAAC,oBAAoB,CAAC,kBAAkB,EAAE,mBAAmB,CAAC,CAAC,CAAC;KAC/E;IAED,MAAM,cAAc,GAAG;QACnB,sBAAsB,EAAE,EAAE;QAC1B,6BAA6B,EAAE,eAAe;QAC9C,0BAA0B,EAAE,MAAM;KACrC,CAAC;IAEF,OAAO,CACH,oBAAC,kBAAkB,IAAC,cAAc,EAAE,cAAc,EAAE,gBAAgB,EAAE,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,KAAK,GAAI,CACrG,CAAC;AACN,CAAC,CAAC;AAYF,eAAe,gBAAgB,CAAC","sourcesContent":["import React from 'react';\nimport { useShopQuery, gql } from '@shopify/hydrogen';\nimport type { Metafield } from '@shopify/hydrogen/dist/esnext/storefront-api-types';\n\nimport { OkendoWidgetClient } from './OkendoWidget.client';\nimport { getOkendoProductId, useOkendoRequestContext, widgetConfigurationError, widgetMetafieldError } from '../shared';\n\nexport const OkendoStarRating: React.FunctionComponent<OkendoStarRatingProps> = (props): React.ReactElement | null => {\n const { setupFailed } = useOkendoRequestContext();\n if (setupFailed) {\n return null;\n }\n\n const { productId } = props;\n\n const okendoProductId = getOkendoProductId(productId);\n if (!okendoProductId) {\n console.error(widgetConfigurationError('OkendoStarRating', 'productId was not provided'));\n return null;\n }\n\n const query = gql`\n query metafields($productId: ID!) {\n product(id: $productId) {\n starRatingSnippet: metafield(namespace: \"okendo\", key: \"StarRatingSnippet\") {\n value\n }\n }\n }\n `;\n\n const {\n data: {\n product: { starRatingSnippet }\n }\n } = useShopQuery<OkendoStarRatingMetafields>({\n query: query,\n preload: true,\n variables: {\n productId\n }\n });\n\n if (!starRatingSnippet?.value) {\n console.warn(widgetMetafieldError('OkendoStarRating', 'StarRatingSnippet'));\n }\n\n const dataAttributes = {\n 'data-oke-star-rating': '',\n 'data-oke-reviews-product-id': okendoProductId,\n 'data-oke-scroll-disabled': 'true'\n };\n\n return (\n <OkendoWidgetClient dataAttributes={dataAttributes} metafieldContent={starRatingSnippet?.value} />\n );\n};\n\ninterface OkendoStarRatingProps {\n productId: string;\n}\n\ninterface OkendoStarRatingMetafields {\n product: {\n starRatingSnippet?: Pick<Metafield, 'value'>;\n };\n}\n\nexport default OkendoStarRating;\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"OkendoWidget.client.js","sourceRoot":"","sources":["../../../src/components/OkendoWidget.client.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAIjD,MAAM,CAAC,MAAM,kBAAkB,GAAqD,CAAC,KAAK,EAAE,EAAE;IAC1F,MAAM,EAAE,cAAc,EAAE,gBAAgB,GAAG,EAAE,EAAE,GAAG,KAAK,CAAC;IACxD,MAAM,eAAe,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAErD,MAAM,uBAAuB,GAAG,GAAG,EAAE;QACjC,IAAI,eAAe,CAAC,OAAO,EAAE;YACzB,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;SAC3D;IACL,CAAC,CAAC;IAEF,SAAS,CAAC,GAAG,EAAE;QACX,IAAI,MAAM,CAAC,YAAY,EAAE;YACrB,uBAAuB,EAAE,CAAC;SAC7B;aACI;YACD,MAAM,CAAC,gBAAgB,CAAC,mBAAmB,EAAE,uBAAuB,CAAC,CAAC;SACzE;IACL,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CACH,6BAAK,GAAG,EAAE,eAAe,KAAM,cAAc,EAAE,uBAAuB,EAAE,EAAE,MAAM,EAAE,gBAAgB,EAAE,GAAQ,CAC/G,CAAC;AACN,CAAC,CAAA","sourcesContent":["import React, { useEffect, useRef } from 'react';\nimport type { ReviewsWidgetPlus } from '@okendo/reviews-widget-plus/dist-utils/ReviewsWidgetPlus';\nimport type { SKO } from '../shared';\n\nexport const OkendoWidgetClient: React.FunctionComponent<OkendoWidgetClientProps> = (props) => {\n const { dataAttributes, metafieldContent = '' } = props;\n const widgetContainer = useRef<HTMLDivElement>(null);\n\n const initialiseReviewsWidget = () => {\n if (widgetContainer.current) {\n window.okeWidgetApi.initWidget(widgetContainer.current);\n }\n };\n\n useEffect(() => {\n if (window.okeWidgetApi) {\n initialiseReviewsWidget();\n }\n else {\n window.addEventListener('oke-script-loaded', initialiseReviewsWidget);\n }\n }, []);\n\n return (\n <div ref={widgetContainer} {...dataAttributes} dangerouslySetInnerHTML={{ __html: metafieldContent }}></div>\n );\n}\n\nexport interface OkendoWidgetClientProps {\n dataAttributes: SKO;\n metafieldContent?: string;\n}\n\ndeclare global {\n interface Window {\n okeWidgetApi: ReviewsWidgetPlus.WidgetWindowApi;\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC","sourcesContent":["export * from './OkendoReviewsWidget.server';\nexport * from './OkendoStarRating.server';\nexport * from './OkendoProvider.server';\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC","sourcesContent":["export * from './components';\nexport * from './shared';\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"errorUtils.js","sourceRoot":"","sources":["../../../src/shared/errorUtils.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,WAAW,CAAC,OAAe;IACvC,OAAO,WAAW,OAAO,EAAE,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,UAAkB,EAAE,OAAe;IACxE,OAAO,WAAW,CAAC,GAAG,UAAU,WAAW,OAAO,EAAE,CAAC,CAAC;AAC1D,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,UAAkB,EAAE,aAAqB;IAC1E,OAAO,WAAW,CAAC,GAAG,UAAU,yCAAyC,aAAa,IAAI,CAAC,CAAC;AAChG,CAAC","sourcesContent":["export function okendoError(message: string): string {\n return `Okendo: ${message}`;\n}\n\nexport function widgetConfigurationError(widgetName: string, message: string): string {\n return okendoError(`${widgetName} error: ${message}`);\n}\n\nexport function widgetMetafieldError(widgetName: string, metafieldName: string): string {\n return okendoError(`${widgetName} error: Failed to retrieve metafield '${metafieldName}'.`);\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/shared/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC","sourcesContent":["export * from './errorUtils';\nexport * from './productUtils';\nexport * from './requestUtils';\nexport * from './sharedTypes';\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"productUtils.js","sourceRoot":"","sources":["../../../src/shared/productUtils.ts"],"names":[],"mappings":"AAAA,MAAM,eAAe,GAAG,UAAU,CAAC;AAEnC;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,SAAiB;IAChD,IAAI,CAAC,SAAS,EAAE;QACZ,OAAO;KACV;IAED,8EAA8E;IAC9E,OAAO,WAAW,eAAe,CAAC,IAAI,CAAC,SAAS,CAAC;QAC7C,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAClC,EAAE,CAAC;AACX,CAAC","sourcesContent":["const kProductIdRegex = /^[0-9]*$/;\n\n/**\n * Gets the product ID with Okendo formatting.\n * @param productId The Shopify Product ID e.g. gid://shopify/Product/10079785100.\n * @returns The product ID in Okendo formatting.\n */\nexport function getOkendoProductId(productId: string): string | undefined {\n if (!productId) {\n return;\n }\n\n // Supports Shopify's GraphQL Id syntax e.g. gid://shopify/Product/10079785100\n return `shopify-${kProductIdRegex.test(productId)\n ? productId\n : productId.split('/').slice(-1)[0]\n }`;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"requestUtils.js","sourceRoot":"","sources":["../../../src/shared/requestUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gEAAgE,CAAC;AAIlG,MAAM,UAAU,yBAAyB,CAAC,OAAwB,EAAE,GAAmC,EAAE,KAAwD;IAC7J,MAAM,oBAAoB,GAAyB,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,EAAE,CAAC;IAC1F,oBAAoB,CAAC,GAAG,CAAC,GAAG,KAAY,CAAC;IACzC,OAAO,CAAC,GAAG,CAAC,oBAAoB,GAAG,oBAAoB,CAAC;AAC5D,CAAC;AAED,MAAM,UAAU,uBAAuB;IACnC,MAAM,EAAE,GAAG,EAAE,EAAE,oBAAoB,EAAE,EAAE,GAAG,gBAAgB,EAAE,CAAC;IAC7D,OAAO,oBAAoB,IAAI,EAAE,CAAC;AACtC,CAAC","sourcesContent":["import { HydrogenRequest } from '@shopify/hydrogen/dist/esnext/foundation/HydrogenRequest/HydrogenRequest.server';\nimport { useServerRequest } from '@shopify/hydrogen/dist/esnext/foundation/ServerRequestProvider';\n\nimport { SKO } from './sharedTypes';\n\nexport function setInOkendoRequestContext(request: HydrogenRequest, key: keyof OkendoRequestContextKeys, value: RequestContextSafeType | RequestContextSafeType[]): void {\n const okendoRequestContext: OkendoRequestContext = request.ctx.okendoRequestContext || {};\n okendoRequestContext[key] = value as any;\n request.ctx.okendoRequestContext = okendoRequestContext;\n}\n\nexport function useOkendoRequestContext(): OkendoRequestContext {\n const { ctx: { okendoRequestContext } } = useServerRequest();\n return okendoRequestContext || {};\n}\n\ninterface OkendoRequestContextKeys {\n setupFailed: boolean;\n}\n\nexport interface OkendoRequestContext extends OkendoRequestContextKeysWithSKO { }\n\ntype OkendoRequestContextKeysWithSKO = OkendoRequestContextKeys & SKO;\n\ntype RequestContextSafeType = string | number | boolean;\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"sharedTypes.js","sourceRoot":"","sources":["../../../src/shared/sharedTypes.ts"],"names":[],"mappings":"","sourcesContent":["export type SKO = Record<string, unknown>;\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"extendViteOptimizeDeps.js","sourceRoot":"","sources":["../../../src/plugins/extendViteOptimizeDeps.ts"],"names":[],"mappings":";;;AAEO,MAAM,sBAAsB,GAAG,GAAW,EAAE,CAAC,CAAC;IACjD,IAAI,EAAE,yCAAyC;IAC/C,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;QACX,YAAY,EAAE;YACV,OAAO,EAAE;gBACL,8CAA8C;aACjD;SACJ;KACJ,CAAC;CACL,CAAC,CAAC;AATU,QAAA,sBAAsB,0BAShC","sourcesContent":["import type { Plugin } from 'vite';\n\nexport const extendViteOptimizeDeps = (): Plugin => ({\n name: 'vite-plugin-okendo-extend-optimize-deps',\n config: () => ({\n optimizeDeps: {\n include: [\n '@okendo/shopify-hydrogen > html-react-parser'\n ]\n }\n })\n});\n"]}
@@ -1,3 +0,0 @@
1
- import type { Plugin } from 'vite';
2
- declare const _default: () => Plugin[];
3
- export default _default;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const extendViteOptimizeDeps_1 = require("./extendViteOptimizeDeps");
4
- exports.default = () => {
5
- return [
6
- (0, extendViteOptimizeDeps_1.extendViteOptimizeDeps)()
7
- ];
8
- };
9
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/index.ts"],"names":[],"mappings":";;AAEA,qEAAkE;AAElE,kBAAe,GAAG,EAAE;IAChB,OAAO;QACH,IAAA,+CAAsB,GAAE;KACf,CAAC;AAClB,CAAC,CAAC","sourcesContent":["import type { Plugin } from 'vite';\n\nimport { extendViteOptimizeDeps } from './extendViteOptimizeDeps';\n\nexport default () => {\n return [\n extendViteOptimizeDeps()\n ] as Plugin[];\n};\n"]}
package/plugin.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require('./dist/node/plugin');