@okendo/shopify-hydrogen 1.2.2 → 1.2.4

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 (43) hide show
  1. package/dist/esnext/client-components/OkendoClientStarRating.client.d.ts +4 -4
  2. package/dist/esnext/client-components/OkendoClientStarRating.client.js +24 -25
  3. package/dist/esnext/client-components/OkendoWidget.client.d.ts +13 -13
  4. package/dist/esnext/client-components/OkendoWidget.client.js +23 -24
  5. package/dist/esnext/client-components/index.d.ts +1 -1
  6. package/dist/esnext/client-components/index.js +1 -1
  7. package/dist/esnext/client.d.ts +1 -1
  8. package/dist/esnext/client.js +1 -1
  9. package/dist/esnext/components/OkendoProvider.server.d.ts +15 -15
  10. package/dist/esnext/components/OkendoProvider.server.js +68 -65
  11. package/dist/esnext/components/OkendoReviewsWidget.server.d.ts +6 -6
  12. package/dist/esnext/components/OkendoReviewsWidget.server.js +46 -44
  13. package/dist/esnext/components/OkendoStarRating.server.d.ts +4 -4
  14. package/dist/esnext/components/OkendoStarRating.server.js +38 -36
  15. package/dist/esnext/components/index.d.ts +3 -3
  16. package/dist/esnext/components/index.js +3 -3
  17. package/dist/esnext/fragments/index.d.ts +1 -1
  18. package/dist/esnext/fragments/index.js +2 -2
  19. package/dist/esnext/framework/index.js +1 -1
  20. package/dist/esnext/framework/plugins/plugin.d.ts +7 -7
  21. package/dist/esnext/framework/plugins/plugin.js +7 -7
  22. package/dist/esnext/framework/plugins/suppressModuleWarning.d.ts +3 -3
  23. package/dist/esnext/framework/plugins/suppressModuleWarning.js +18 -18
  24. package/dist/esnext/index.d.ts +4 -4
  25. package/dist/esnext/index.js +4 -4
  26. package/dist/esnext/models/starRating.d.ts +12 -12
  27. package/dist/esnext/models/starRating.js +1 -1
  28. package/dist/esnext/shared/errorUtils.d.ts +3 -3
  29. package/dist/esnext/shared/errorUtils.js +9 -9
  30. package/dist/esnext/shared/logger.d.ts +14 -14
  31. package/dist/esnext/shared/logger.js +7 -7
  32. package/dist/esnext/shared/productUtils.d.ts +6 -6
  33. package/dist/esnext/shared/productUtils.js +15 -15
  34. package/dist/esnext/shared/server/requestUtils.d.ts +7 -11
  35. package/dist/esnext/shared/server/requestUtils.js +4 -8
  36. package/dist/esnext/shared/sharedTypes.d.ts +5 -5
  37. package/dist/esnext/shared/sharedTypes.js +1 -1
  38. package/dist/node/framework/index.js +1 -1
  39. package/dist/node/framework/plugins/plugin.d.ts +4 -4
  40. package/dist/node/framework/plugins/plugin.js +12 -12
  41. package/dist/node/framework/plugins/suppressModuleWarning.d.ts +3 -3
  42. package/dist/node/framework/plugins/suppressModuleWarning.js +20 -20
  43. package/package.json +9 -2
@@ -1,4 +1,4 @@
1
- import React from 'react';
2
- import type { OkendoClientStarRatingProps } from '../models/starRating';
3
- export declare const OkendoClientStarRating: React.FunctionComponent<OkendoClientStarRatingProps>;
4
- export default OkendoClientStarRating;
1
+ import { FC } from 'react';
2
+ import type { OkendoClientStarRatingProps } from '../models/starRating';
3
+ export declare const OkendoClientStarRating: FC<OkendoClientStarRatingProps>;
4
+ export default OkendoClientStarRating;
@@ -1,25 +1,24 @@
1
- import React from 'react';
2
- import { OkendoWidgetClient } from './OkendoWidget.client';
3
- import { getOkendoProductId } from '../shared/productUtils';
4
- import { widgetConfigurationError, widgetMetafieldError } from '../shared/errorUtils';
5
- import { logger } from '../shared/logger';
6
- export const OkendoClientStarRating = (props) => {
7
- const { productId, okendoStarRatingSnippet } = props;
8
- const okendoProductId = getOkendoProductId(productId);
9
- if (!okendoProductId) {
10
- logger.error(widgetConfigurationError('OkendoClientStarRating', 'productId was not provided'));
11
- return null;
12
- }
13
- if (!okendoStarRatingSnippet?.value) {
14
- logger.warn(widgetMetafieldError('OkendoStarRating', 'StarRatingSnippet'));
15
- }
16
- const dataAttributes = {
17
- 'data-oke-star-rating': '',
18
- 'data-oke-reviews-product-id': okendoProductId
19
- };
20
- if (okendoStarRatingSnippet?.value) {
21
- dataAttributes['data-oke-rendered'] = '';
22
- }
23
- return (React.createElement(OkendoWidgetClient, { dataAttributes: dataAttributes, metafieldContent: okendoStarRatingSnippet?.value }));
24
- };
25
- export default OkendoClientStarRating;
1
+ import React from 'react';
2
+ import { OkendoWidgetClient } from './OkendoWidget.client';
3
+ import { getOkendoProductId } from '../shared/productUtils';
4
+ import { widgetConfigurationError, widgetMetafieldError } from '../shared/errorUtils';
5
+ import { logger } from '../shared/logger';
6
+ export const OkendoClientStarRating = ({ productId, okendoStarRatingSnippet }) => {
7
+ const okendoProductId = getOkendoProductId(productId);
8
+ if (!okendoProductId) {
9
+ logger.error(widgetConfigurationError('OkendoClientStarRating', 'productId was not provided'));
10
+ return null;
11
+ }
12
+ if (!okendoStarRatingSnippet?.value) {
13
+ logger.warn(widgetMetafieldError('OkendoStarRating', 'StarRatingSnippet'));
14
+ }
15
+ const dataAttributes = {
16
+ 'data-oke-star-rating': '',
17
+ 'data-oke-reviews-product-id': okendoProductId
18
+ };
19
+ if (okendoStarRatingSnippet?.value) {
20
+ dataAttributes['data-oke-rendered'] = '';
21
+ }
22
+ return (React.createElement(OkendoWidgetClient, { dataAttributes: dataAttributes, metafieldContent: okendoStarRatingSnippet?.value }));
23
+ };
24
+ export default OkendoClientStarRating;
@@ -1,13 +1,13 @@
1
- import React from 'react';
2
- import type { ReviewsWidgetPlus } from '@okendo/reviews-widget-plus/dist-utils/ReviewsWidgetPlus';
3
- import type { SKO } from '../shared/sharedTypes';
4
- export declare const OkendoWidgetClient: React.FunctionComponent<OkendoWidgetClientProps>;
5
- export interface OkendoWidgetClientProps {
6
- dataAttributes: SKO;
7
- metafieldContent?: string;
8
- }
9
- declare global {
10
- interface Window {
11
- okeWidgetApi: ReviewsWidgetPlus.WidgetWindowApi;
12
- }
13
- }
1
+ import { FC } from 'react';
2
+ import type { ReviewsWidgetPlus } from '@okendo/reviews-widget-plus/dist-utils/ReviewsWidgetPlus';
3
+ import type { SKO } from '../shared/sharedTypes';
4
+ export declare const OkendoWidgetClient: FC<OkendoWidgetClientProps>;
5
+ export interface OkendoWidgetClientProps {
6
+ dataAttributes: SKO;
7
+ metafieldContent?: string;
8
+ }
9
+ declare global {
10
+ interface Window {
11
+ okeWidgetApi: ReviewsWidgetPlus.WidgetWindowApi;
12
+ }
13
+ }
@@ -1,24 +1,23 @@
1
- import React, { useEffect, useRef } from 'react';
2
- export const OkendoWidgetClient = (props) => {
3
- const { dataAttributes, metafieldContent = '' } = props;
4
- const widgetContainer = useRef(null);
5
- const initializeWidget = () => {
6
- if (widgetContainer.current) {
7
- // `forceReinitialisation` must be true because we can expect `data-oke-rendered`
8
- // to be present on already-initialised widget snippets.
9
- window.okeWidgetApi.initWidget(widgetContainer.current, true);
10
- }
11
- };
12
- useEffect(() => {
13
- if (window.okeWidgetApi && widgetContainer.current) {
14
- initializeWidget();
15
- }
16
- else {
17
- document.addEventListener('oke-script-loaded', initializeWidget);
18
- }
19
- return () => {
20
- document.removeEventListener('oke-script-loaded', initializeWidget);
21
- };
22
- }, [dataAttributes]);
23
- return (React.createElement("div", { ref: widgetContainer, ...dataAttributes, dangerouslySetInnerHTML: { __html: metafieldContent } }));
24
- };
1
+ import React, { useEffect, useRef } from 'react';
2
+ export const OkendoWidgetClient = ({ dataAttributes, metafieldContent = '' }) => {
3
+ const widgetContainer = useRef(null);
4
+ const initializeWidget = () => {
5
+ if (widgetContainer.current) {
6
+ // `forceReinitialisation` must be true because we can expect `data-oke-rendered`
7
+ // to be present on already-initialised widget snippets.
8
+ window.okeWidgetApi.initWidget(widgetContainer.current, true);
9
+ }
10
+ };
11
+ useEffect(() => {
12
+ if (window.okeWidgetApi && widgetContainer.current) {
13
+ initializeWidget();
14
+ }
15
+ else {
16
+ document.addEventListener('oke-script-loaded', initializeWidget);
17
+ }
18
+ return () => {
19
+ document.removeEventListener('oke-script-loaded', initializeWidget);
20
+ };
21
+ }, [dataAttributes]);
22
+ return (React.createElement("div", { ref: widgetContainer, key: JSON.stringify(dataAttributes), ...dataAttributes, dangerouslySetInnerHTML: { __html: metafieldContent } }));
23
+ };
@@ -1 +1 @@
1
- export * from './OkendoClientStarRating.client';
1
+ export * from './OkendoClientStarRating.client';
@@ -1 +1 @@
1
- export * from './OkendoClientStarRating.client';
1
+ export * from './OkendoClientStarRating.client';
@@ -1 +1 @@
1
- export * from './client-components';
1
+ export * from './client-components';
@@ -1 +1 @@
1
- export * from './client-components';
1
+ export * from './client-components';
@@ -1,15 +1,15 @@
1
- import React from 'react';
2
- export declare const OkendoProvider: React.FunctionComponent<OkendoProviderProps>;
3
- interface OkendoProviderProps {
4
- apiDomain?: string;
5
- cdnDomain?: string;
6
- children?: React.ReactNode;
7
- productUrlFormatOverride?: (product: ReviewProduct) => string;
8
- subscriberId: string;
9
- }
10
- interface ReviewProduct {
11
- productHandle?: string;
12
- productId: string;
13
- variantId?: string;
14
- }
15
- export {};
1
+ import React, { FC } from 'react';
2
+ export declare const OkendoProvider: FC<OkendoProviderProps>;
3
+ interface OkendoProviderProps {
4
+ apiDomain?: string;
5
+ cdnDomain?: string;
6
+ children?: React.ReactNode;
7
+ productUrlFormatOverride?: (product: ReviewProduct) => string;
8
+ subscriberId: string;
9
+ }
10
+ interface ReviewProduct {
11
+ productHandle?: string;
12
+ productId: string;
13
+ variantId?: string;
14
+ }
15
+ export {};
@@ -1,68 +1,71 @@
1
- import React from 'react';
2
- import { fetchSync, useShopQuery, gql, CacheShort } from '@shopify/hydrogen';
3
- import { Head } from '@shopify/hydrogen';
4
- import { okendoError } from '../shared/errorUtils';
5
- import { setInOkendoRequestContext } from '../shared/server/requestUtils';
6
- import { logger } from '../shared/logger';
7
- const kDefaultOkendoApiDomain = 'api.okendo.io/v1';
8
- const kDefaultOkendoCdnDomain = 'cdn-static.okendo.io';
9
- export const OkendoProvider = (props) => {
10
- const { apiDomain, cdnDomain, children, productUrlFormatOverride, subscriberId } = props;
11
- // Download subscriber widget plus settings.
12
- const url = `https://${apiDomain ?? kDefaultOkendoApiDomain}/stores/${subscriberId}/widget_plus_settings`;
13
- const settingsResponse = fetchSync(url, { preload: true });
14
- if (!settingsResponse.ok) {
15
- logger.error(okendoError('Failed to retrieve subscriber settings. Please check your environment variables.'));
16
- setInOkendoRequestContext('setupFailed', true);
17
- return null;
18
- }
19
- const { cssVariables, customCss, reviewsHeaderConfig, starSymbols } = settingsResponse.json();
20
- const cssVariablesNormalized = cssVariables.replace('<style id="oke-css-vars">', '').replace('</style>', '');
21
- const customCssNormalized = customCss ? customCss.replace('<style id="oke-reviews-custom-css">', '').replace('</style>', '') : '';
22
- // Download contents of widget initialisation script.
23
- const initScriptResponse = fetchSync(`https://${cdnDomain ?? kDefaultOkendoCdnDomain}/reviews-widget-plus/js/okendo-reviews.js`, {
24
- cache: CacheShort(),
25
- preload: true
26
- });
27
- if (!initScriptResponse.ok) {
28
- logger.error(okendoError('Failed to retrieve widget initialization script.'));
29
- setInOkendoRequestContext('setupFailed', true);
30
- return null;
31
- }
32
- const initScriptContents = initScriptResponse.text();
33
- // Set up product URL formatter.
34
- const productUrlFormatter = typeof productUrlFormatOverride === 'function'
35
- ? productUrlFormatOverride
36
- : (product) => product?.productHandle
37
- ? `/products/${product.productHandle}/${product.variantId ? '?variantId=' + product.variantId : ''}`
38
- : undefined;
39
- // Get pre-rendered style settings.
1
+ import React from 'react';
2
+ import { fetchSync, useShopQuery, gql, CacheShort } from '@shopify/hydrogen';
3
+ import { Head } from '@shopify/hydrogen';
4
+ import { okendoError } from '../shared/errorUtils';
5
+ import { useOkendoRequestContext } from '../shared/server/requestUtils';
6
+ import { logger } from '../shared/logger';
7
+ const kDefaultOkendoApiDomain = 'api.okendo.io/v1';
8
+ const kDefaultOkendoCdnDomain = 'cdn-static.okendo.io';
9
+ export const OkendoProvider = ({ apiDomain, cdnDomain, children, productUrlFormatOverride, subscriberId }) => {
10
+ const okendoRequestContext = useOkendoRequestContext();
11
+ // Download subscriber widget plus settings.
12
+ const url = `https://${apiDomain ?? kDefaultOkendoApiDomain}/stores/${subscriberId}/widget_plus_settings`;
13
+ const settingsResponse = fetchSync(url, { preload: true });
14
+ if (!settingsResponse.ok) {
15
+ logger.error(okendoError('Failed to retrieve subscriber settings. Please check your environment variables.'));
16
+ okendoRequestContext.setupFailed = true;
17
+ return null;
18
+ }
19
+ const { cssVariables, customCss, reviewsHeaderConfig, starSymbols } = settingsResponse.json();
20
+ const cssVariablesNormalized = cssVariables.replace('<style id="oke-css-vars">', '').replace('</style>', '');
21
+ const customCssNormalized = customCss ? customCss.replace('<style id="oke-reviews-custom-css">', '').replace('</style>', '') : '';
22
+ // Download contents of widget initialisation script.
23
+ const initScriptResponse = fetchSync(`https://${cdnDomain ?? kDefaultOkendoCdnDomain}/reviews-widget-plus/js/okendo-reviews.js`, {
24
+ cache: CacheShort(),
25
+ preload: true
26
+ });
27
+ if (!initScriptResponse.ok) {
28
+ logger.error(okendoError('Failed to retrieve widget initialization script.'));
29
+ okendoRequestContext.setupFailed = true;
30
+ return null;
31
+ }
32
+ const initScriptContents = initScriptResponse.text();
33
+ return React.createElement(OkendoProviderContent, { productUrlFormatOverride: productUrlFormatOverride, subscriberId: subscriberId, reviewsHeaderConfig: reviewsHeaderConfig, starSymbols: starSymbols, cssVariablesNormalized: cssVariablesNormalized, customCssNormalized: customCssNormalized, initScriptContents: initScriptContents }, children);
34
+ };
35
+ const OkendoProviderContent = ({ children, productUrlFormatOverride, subscriberId, reviewsHeaderConfig, starSymbols, cssVariablesNormalized, customCssNormalized, initScriptContents, }) => {
36
+ // Set up product URL formatter.
37
+ const productUrlFormatter = typeof productUrlFormatOverride === 'function'
38
+ ? productUrlFormatOverride
39
+ : (product) => product?.productHandle
40
+ ? `/products/${product.productHandle}/${product.variantId ? '?variantId=' + product.variantId : ''}`
41
+ : undefined;
42
+ // Get pre-rendered style settings.
40
43
  const query = gql `
41
- query metafields {
42
- shop {
43
- widgetPreRenderStyleTags: metafield(namespace: "okendo", key: "WidgetPreRenderStyleTags") {
44
- value
44
+ query metafields {
45
+ shop {
46
+ widgetPreRenderStyleTags: metafield(namespace: "okendo", key: "WidgetPreRenderStyleTags") {
47
+ value
48
+ }
45
49
  }
46
50
  }
47
- }
48
- `;
49
- const { data: { shop: { widgetPreRenderStyleTags } } } = useShopQuery({
50
- query: query,
51
- preload: true
52
- });
53
- const preRenderStyleTags = widgetPreRenderStyleTags?.value ?? '';
54
- if (!preRenderStyleTags) {
55
- logger.warn(okendoError('Failed to retrieve pre-rendered widget style settings.'));
56
- }
57
- return (React.createElement(React.Fragment, null,
58
- React.createElement(Head, null,
59
- React.createElement("script", { id: "oke-reviews-settings", type: "application/json" }, JSON.stringify(reviewsHeaderConfig)),
60
- React.createElement("style", { id: "oke-css-vars" }, cssVariablesNormalized),
61
- customCssNormalized && React.createElement("style", { id: "oke-reviews-custom-css" }, customCssNormalized),
62
- React.createElement("meta", { name: "oke:subscriber_id", content: subscriberId }),
63
- React.createElement("script", null, initScriptContents),
64
- productUrlFormatter && React.createElement("script", { type: "text/javascript" }, `window.okeProductUrlFormatter = ${productUrlFormatter}`)),
65
- preRenderStyleTags && React.createElement("div", { dangerouslySetInnerHTML: { __html: preRenderStyleTags } }),
66
- React.createElement("div", { dangerouslySetInnerHTML: { __html: starSymbols } }),
67
- children));
68
- };
51
+ `;
52
+ const { data: { shop: { widgetPreRenderStyleTags } } } = useShopQuery({
53
+ query,
54
+ preload: true
55
+ });
56
+ const preRenderStyleTags = widgetPreRenderStyleTags?.value ?? '';
57
+ if (!preRenderStyleTags) {
58
+ logger.warn(okendoError('Failed to retrieve pre-rendered widget style settings.'));
59
+ }
60
+ return (React.createElement(React.Fragment, null,
61
+ React.createElement(Head, null,
62
+ React.createElement("script", { id: "oke-reviews-settings", type: "application/json" }, JSON.stringify(reviewsHeaderConfig)),
63
+ React.createElement("style", { id: "oke-css-vars" }, cssVariablesNormalized),
64
+ customCssNormalized && React.createElement("style", { id: "oke-reviews-custom-css" }, customCssNormalized),
65
+ React.createElement("meta", { name: "oke:subscriber_id", content: subscriberId }),
66
+ React.createElement("script", null, initScriptContents),
67
+ productUrlFormatter && React.createElement("script", { type: "text/javascript" }, `window.okeProductUrlFormatter = ${productUrlFormatter}`)),
68
+ preRenderStyleTags && React.createElement("div", { dangerouslySetInnerHTML: { __html: preRenderStyleTags } }),
69
+ React.createElement("div", { dangerouslySetInnerHTML: { __html: starSymbols } }),
70
+ children));
71
+ };
@@ -1,6 +1,6 @@
1
- import React from 'react';
2
- export declare const OkendoReviewsWidget: React.FunctionComponent<OkendoReviewsWidgetProps>;
3
- interface OkendoReviewsWidgetProps {
4
- productId?: string;
5
- }
6
- export default OkendoReviewsWidget;
1
+ import { FC } from 'react';
2
+ export declare const OkendoReviewsWidget: FC<OkendoReviewsWidgetProps>;
3
+ interface OkendoReviewsWidgetProps {
4
+ productId?: string;
5
+ }
6
+ export default OkendoReviewsWidget;
@@ -1,25 +1,27 @@
1
- import React from 'react';
2
- import { useShopQuery, gql } from '@shopify/hydrogen';
3
- import { OkendoWidgetClient } from '../client-components/OkendoWidget.client';
4
- import { widgetMetafieldError } from '../shared/errorUtils';
5
- import { getOkendoProductId } from '../shared/productUtils';
6
- import { useOkendoRequestContext } from '../shared/server/requestUtils';
7
- import { logger } from '../shared/logger';
8
- export const OkendoReviewsWidget = (props) => {
9
- const { setupFailed } = useOkendoRequestContext();
10
- if (setupFailed) {
11
- return null;
12
- }
13
- const { productId } = props;
14
- const productQuery = productId
1
+ import React from 'react';
2
+ import { useShopQuery, gql } from '@shopify/hydrogen';
3
+ import { OkendoWidgetClient } from '../client-components/OkendoWidget.client';
4
+ import { widgetMetafieldError } from '../shared/errorUtils';
5
+ import { getOkendoProductId } from '../shared/productUtils';
6
+ import { useOkendoRequestContext } from '../shared/server/requestUtils';
7
+ import { logger } from '../shared/logger';
8
+ export const OkendoReviewsWidget = (props) => {
9
+ const { setupFailed } = useOkendoRequestContext();
10
+ if (setupFailed) {
11
+ return null;
12
+ }
13
+ return React.createElement(OkendoReviewsWidgetContent, { ...props });
14
+ };
15
+ const OkendoReviewsWidgetContent = ({ productId }) => {
16
+ const productQuery = productId
15
17
  ? `
16
18
  product(id: $productId) {
17
19
  reviewsWidgetSnippet: metafield(namespace: "okendo", key: "ReviewsWidgetSnippet") {
18
20
  value
19
21
  }
20
22
  }
21
- `
22
- : '';
23
+ `
24
+ : '';
23
25
  const query = gql `
24
26
  query metafields${productId ? '($productId: ID!)' : ''} {
25
27
  ${productQuery}
@@ -29,31 +31,31 @@ export const OkendoReviewsWidget = (props) => {
29
31
  }
30
32
  }
31
33
  }
32
- `;
33
- const { data: { product, shop } } = useShopQuery({
34
- query: query,
35
- preload: true,
36
- variables: {
37
- productId
38
- }
39
- });
40
- if (productId && !product?.reviewsWidgetSnippet?.value) {
41
- logger.warn(widgetMetafieldError('OkendoReviewsWidget', 'ReviewsWidgetSnippet'));
42
- }
43
- if (!shop?.widgetPreRenderBodyStyleTags?.value) {
44
- logger.warn(widgetMetafieldError('OkendoReviewsWidget', 'WidgetPreRenderBodyStyleTags'));
45
- }
46
- const dataAttributes = {
47
- 'data-oke-widget': ''
48
- };
49
- if (productId) {
50
- const okendoProductId = getOkendoProductId(productId);
51
- if (okendoProductId) {
52
- dataAttributes['data-oke-reviews-product-id'] = okendoProductId;
53
- }
54
- }
55
- return (React.createElement(React.Fragment, null,
56
- React.createElement("div", { dangerouslySetInnerHTML: { __html: shop?.widgetPreRenderBodyStyleTags?.value ?? '' } }),
57
- React.createElement(OkendoWidgetClient, { dataAttributes: dataAttributes, metafieldContent: product?.reviewsWidgetSnippet?.value ?? '' })));
58
- };
59
- export default OkendoReviewsWidget;
34
+ `;
35
+ const { data: { product, shop } } = useShopQuery({
36
+ query,
37
+ preload: true,
38
+ variables: {
39
+ productId
40
+ }
41
+ });
42
+ if (productId && !product?.reviewsWidgetSnippet?.value) {
43
+ logger.warn(widgetMetafieldError('OkendoReviewsWidget', 'ReviewsWidgetSnippet'));
44
+ }
45
+ if (!shop?.widgetPreRenderBodyStyleTags?.value) {
46
+ logger.warn(widgetMetafieldError('OkendoReviewsWidget', 'WidgetPreRenderBodyStyleTags'));
47
+ }
48
+ const dataAttributes = {
49
+ 'data-oke-widget': ''
50
+ };
51
+ if (productId) {
52
+ const okendoProductId = getOkendoProductId(productId);
53
+ if (okendoProductId) {
54
+ dataAttributes['data-oke-reviews-product-id'] = okendoProductId;
55
+ }
56
+ }
57
+ return (React.createElement(React.Fragment, null,
58
+ React.createElement("div", { dangerouslySetInnerHTML: { __html: shop?.widgetPreRenderBodyStyleTags?.value ?? '' } }),
59
+ React.createElement(OkendoWidgetClient, { dataAttributes: dataAttributes, metafieldContent: product?.reviewsWidgetSnippet?.value ?? '' })));
60
+ };
61
+ export default OkendoReviewsWidget;
@@ -1,4 +1,4 @@
1
- import React from 'react';
2
- import type { OkendoStarRatingProps } from '../models/starRating';
3
- export declare const OkendoStarRating: React.FunctionComponent<OkendoStarRatingProps>;
4
- export default OkendoStarRating;
1
+ import { FC } from 'react';
2
+ import type { OkendoStarRatingProps } from '../models/starRating';
3
+ export declare const OkendoStarRating: FC<OkendoStarRatingProps>;
4
+ export default OkendoStarRating;
@@ -1,21 +1,23 @@
1
- import React from 'react';
2
- import { useShopQuery, gql } from '@shopify/hydrogen';
3
- import { OkendoWidgetClient } from '../client-components/OkendoWidget.client';
4
- import { widgetConfigurationError, widgetMetafieldError } from '../shared/errorUtils';
5
- import { getOkendoProductId } from '../shared/productUtils';
6
- import { useOkendoRequestContext } from '../shared/server/requestUtils';
7
- import { logger } from '../shared/logger';
8
- export const OkendoStarRating = (props) => {
9
- const { setupFailed } = useOkendoRequestContext();
10
- if (setupFailed) {
11
- return null;
12
- }
13
- const { productId } = props;
14
- const okendoProductId = getOkendoProductId(productId);
15
- if (!okendoProductId) {
16
- logger.error(widgetConfigurationError('OkendoStarRating', 'productId was not provided'));
17
- return null;
18
- }
1
+ import React from 'react';
2
+ import { useShopQuery, gql } from '@shopify/hydrogen';
3
+ import { OkendoWidgetClient } from '../client-components/OkendoWidget.client';
4
+ import { widgetConfigurationError, widgetMetafieldError } from '../shared/errorUtils';
5
+ import { getOkendoProductId } from '../shared/productUtils';
6
+ import { useOkendoRequestContext } from '../shared/server/requestUtils';
7
+ import { logger } from '../shared/logger';
8
+ export const OkendoStarRating = (props) => {
9
+ const { setupFailed } = useOkendoRequestContext();
10
+ if (setupFailed) {
11
+ return null;
12
+ }
13
+ const okendoProductId = getOkendoProductId(props.productId);
14
+ if (!okendoProductId) {
15
+ logger.error(widgetConfigurationError('OkendoStarRating', 'productId was not provided'));
16
+ return null;
17
+ }
18
+ return React.createElement(OkendoStarRatingContent, { ...props, okendoProductId: okendoProductId });
19
+ };
20
+ const OkendoStarRatingContent = ({ productId, okendoProductId }) => {
19
21
  const query = gql `
20
22
  query metafields($productId: ID!) {
21
23
  product(id: $productId) {
@@ -24,21 +26,21 @@ export const OkendoStarRating = (props) => {
24
26
  }
25
27
  }
26
28
  }
27
- `;
28
- const { data: { product: { starRatingSnippet } } } = useShopQuery({
29
- query: query,
30
- preload: true,
31
- variables: {
32
- productId
33
- }
34
- });
35
- if (!starRatingSnippet?.value) {
36
- logger.warn(widgetMetafieldError('OkendoStarRating', 'StarRatingSnippet'));
37
- }
38
- const dataAttributes = {
39
- 'data-oke-star-rating': '',
40
- 'data-oke-reviews-product-id': okendoProductId
41
- };
42
- return (React.createElement(OkendoWidgetClient, { dataAttributes: dataAttributes, metafieldContent: starRatingSnippet?.value }));
43
- };
44
- export default OkendoStarRating;
29
+ `;
30
+ const { data: { product: { starRatingSnippet } } } = useShopQuery({
31
+ query,
32
+ preload: true,
33
+ variables: {
34
+ productId
35
+ }
36
+ });
37
+ if (!starRatingSnippet?.value) {
38
+ logger.warn(widgetMetafieldError('OkendoStarRating', 'StarRatingSnippet'));
39
+ }
40
+ const dataAttributes = {
41
+ 'data-oke-star-rating': '',
42
+ 'data-oke-reviews-product-id': okendoProductId
43
+ };
44
+ return (React.createElement(OkendoWidgetClient, { dataAttributes: dataAttributes, metafieldContent: starRatingSnippet?.value }));
45
+ };
46
+ export default OkendoStarRating;
@@ -1,3 +1,3 @@
1
- export * from './OkendoProvider.server';
2
- export * from './OkendoReviewsWidget.server';
3
- export * from './OkendoStarRating.server';
1
+ export * from './OkendoProvider.server';
2
+ export * from './OkendoReviewsWidget.server';
3
+ export * from './OkendoStarRating.server';
@@ -1,3 +1,3 @@
1
- export * from './OkendoProvider.server';
2
- export * from './OkendoReviewsWidget.server';
3
- export * from './OkendoStarRating.server';
1
+ export * from './OkendoProvider.server';
2
+ export * from './OkendoReviewsWidget.server';
3
+ export * from './OkendoStarRating.server';
@@ -1 +1 @@
1
- export declare const OKENDO_PRODUCT_STAR_RATING_FRAGMENT: string;
1
+ export declare const OKENDO_PRODUCT_STAR_RATING_FRAGMENT: string;
@@ -1,4 +1,4 @@
1
- import { gql } from '@shopify/hydrogen';
1
+ import { gql } from '@shopify/hydrogen';
2
2
  export const OKENDO_PRODUCT_STAR_RATING_FRAGMENT = gql `
3
3
  fragment OkendoStarRatingSnippet on Product {
4
4
  okendoStarRatingSnippet: metafield(
@@ -8,4 +8,4 @@ export const OKENDO_PRODUCT_STAR_RATING_FRAGMENT = gql `
8
8
  value
9
9
  }
10
10
  }
11
- `;
11
+ `;
@@ -1 +1 @@
1
- "use strict";
1
+ "use strict";
@@ -1,7 +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;
1
+ import type { Plugin } from 'vite';
2
+ declare const okendoPlugin: {
3
+ (): Plugin[];
4
+ default: any;
5
+ };
6
+ export = okendoPlugin;
7
+ export default okendoPlugin;
@@ -1,7 +1,7 @@
1
- import suppressModuleWarning from './suppressModuleWarning';
2
- const okendoPlugin = () => {
3
- return [
4
- suppressModuleWarning()
5
- ];
6
- };
7
- export default okendoPlugin; // For ESM
1
+ import suppressModuleWarning from './suppressModuleWarning';
2
+ const okendoPlugin = () => {
3
+ return [
4
+ suppressModuleWarning()
5
+ ];
6
+ };
7
+ export default okendoPlugin; // For ESM
@@ -1,3 +1,3 @@
1
- import { Plugin } from 'vite';
2
- declare const _default: () => Plugin;
3
- export default _default;
1
+ import { Plugin } from 'vite';
2
+ declare const _default: () => Plugin;
3
+ export default _default;
@@ -1,18 +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
+ /* 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,4 +1,4 @@
1
- export * from './components';
2
- export * from './fragments';
3
- export * from './shared/server/requestUtils';
4
- export * from './shared/sharedTypes';
1
+ export * from './components';
2
+ export * from './fragments';
3
+ export * from './shared/server/requestUtils';
4
+ export * from './shared/sharedTypes';
@@ -1,4 +1,4 @@
1
- export * from './components';
2
- export * from './fragments';
3
- export * from './shared/server/requestUtils';
4
- export * from './shared/sharedTypes';
1
+ export * from './components';
2
+ export * from './fragments';
3
+ export * from './shared/server/requestUtils';
4
+ export * from './shared/sharedTypes';
@@ -1,12 +1,12 @@
1
- import type { Metafield } from '@shopify/hydrogen/dist/esnext/storefront-api-types';
2
- export interface OkendoClientStarRatingProps extends OkendoStarRatingProps {
3
- okendoStarRatingSnippet?: Pick<Metafield, 'value'>;
4
- }
5
- export interface OkendoStarRatingProps {
6
- productId: string;
7
- }
8
- export interface OkendoStarRatingMetafields {
9
- product: {
10
- starRatingSnippet?: Pick<Metafield, 'value'>;
11
- };
12
- }
1
+ import type { Metafield } from '@shopify/hydrogen/dist/esnext/storefront-api-types';
2
+ export interface OkendoClientStarRatingProps extends OkendoStarRatingProps {
3
+ okendoStarRatingSnippet?: Pick<Metafield, 'value'>;
4
+ }
5
+ export interface OkendoStarRatingProps {
6
+ productId: string;
7
+ }
8
+ export interface OkendoStarRatingMetafields {
9
+ product: {
10
+ starRatingSnippet?: Pick<Metafield, 'value'>;
11
+ };
12
+ }
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,3 +1,3 @@
1
- export declare function okendoError(message: string): string;
2
- export declare function widgetConfigurationError(widgetName: string, message: string): string;
3
- export declare function widgetMetafieldError(widgetName: string, metafieldName: string): string;
1
+ export declare function okendoError(message: string): string;
2
+ export declare function widgetConfigurationError(widgetName: string, message: string): string;
3
+ export declare function widgetMetafieldError(widgetName: string, metafieldName: string): string;
@@ -1,9 +1,9 @@
1
- export function okendoError(message) {
2
- return `Okendo: ${message}`;
3
- }
4
- export function widgetConfigurationError(widgetName, message) {
5
- return okendoError(`${widgetName} error: ${message}`);
6
- }
7
- export function widgetMetafieldError(widgetName, metafieldName) {
8
- return okendoError(`${widgetName} error: Failed to retrieve metafield '${metafieldName}'.`);
9
- }
1
+ export function okendoError(message) {
2
+ return `Okendo: ${message}`;
3
+ }
4
+ export function widgetConfigurationError(widgetName, message) {
5
+ return okendoError(`${widgetName} error: ${message}`);
6
+ }
7
+ export function widgetMetafieldError(widgetName, metafieldName) {
8
+ return okendoError(`${widgetName} error: Failed to retrieve metafield '${metafieldName}'.`);
9
+ }
@@ -1,14 +1,14 @@
1
- export declare const logger: {
2
- log: {
3
- (...data: any[]): void;
4
- (message?: any, ...optionalParams: any[]): void;
5
- };
6
- warn: {
7
- (...data: any[]): void;
8
- (message?: any, ...optionalParams: any[]): void;
9
- };
10
- error: {
11
- (...data: any[]): void;
12
- (message?: any, ...optionalParams: any[]): void;
13
- };
14
- };
1
+ export declare const logger: {
2
+ log: {
3
+ (...data: any[]): void;
4
+ (message?: any, ...optionalParams: any[]): void;
5
+ };
6
+ warn: {
7
+ (...data: any[]): void;
8
+ (message?: any, ...optionalParams: any[]): void;
9
+ };
10
+ error: {
11
+ (...data: any[]): void;
12
+ (message?: any, ...optionalParams: any[]): void;
13
+ };
14
+ };
@@ -1,7 +1,7 @@
1
- const isProduction = process.env.NODE_ENV === 'production';
2
- const noop = () => undefined;
3
- export const logger = {
4
- log: isProduction ? noop : console.log,
5
- warn: isProduction ? noop : console.warn,
6
- error: console.error
7
- };
1
+ const isProduction = process.env.NODE_ENV === 'production';
2
+ const noop = () => undefined;
3
+ export const logger = {
4
+ log: isProduction ? noop : console.info,
5
+ warn: isProduction ? noop : console.warn,
6
+ error: console.error
7
+ };
@@ -1,6 +1,6 @@
1
- /**
2
- * Gets the product ID with Okendo formatting.
3
- * @param productId The Shopify Product ID e.g. gid://shopify/Product/10079785100.
4
- * @returns The product ID in Okendo formatting.
5
- */
6
- export declare function getOkendoProductId(productId: string): string | undefined;
1
+ /**
2
+ * Gets the product ID with Okendo formatting.
3
+ * @param productId The Shopify Product ID e.g. gid://shopify/Product/10079785100.
4
+ * @returns The product ID in Okendo formatting.
5
+ */
6
+ export declare function getOkendoProductId(productId: string): string | undefined;
@@ -1,15 +1,15 @@
1
- const kProductIdRegex = /^[0-9]*$/;
2
- /**
3
- * Gets the product ID with Okendo formatting.
4
- * @param productId The Shopify Product ID e.g. gid://shopify/Product/10079785100.
5
- * @returns The product ID in Okendo formatting.
6
- */
7
- export function getOkendoProductId(productId) {
8
- if (!productId) {
9
- return;
10
- }
11
- // Supports Shopify's GraphQL Id syntax e.g. gid://shopify/Product/10079785100
12
- return `shopify-${kProductIdRegex.test(productId)
13
- ? productId
14
- : productId.split('/').slice(-1)[0]}`;
15
- }
1
+ const kProductIdRegex = /^[0-9]*$/;
2
+ /**
3
+ * Gets the product ID with Okendo formatting.
4
+ * @param productId The Shopify Product ID e.g. gid://shopify/Product/10079785100.
5
+ * @returns The product ID in Okendo formatting.
6
+ */
7
+ export function getOkendoProductId(productId) {
8
+ if (!productId) {
9
+ return;
10
+ }
11
+ // Supports Shopify's GraphQL Id syntax e.g. gid://shopify/Product/10079785100
12
+ return `shopify-${kProductIdRegex.test(productId)
13
+ ? productId
14
+ : productId.split('/').slice(-1)[0]}`;
15
+ }
@@ -1,11 +1,7 @@
1
- import type { SKO } from '../sharedTypes';
2
- export declare function setInOkendoRequestContext(key: keyof OkendoRequestContextKeys, value: RequestContextSafeType | RequestContextSafeType[]): void;
3
- export declare function useOkendoRequestContext(): OkendoRequestContext;
4
- interface OkendoRequestContextKeys {
5
- setupFailed: boolean;
6
- }
7
- export interface OkendoRequestContext extends OkendoRequestContextKeysWithSKO {
8
- }
9
- declare type OkendoRequestContextKeysWithSKO = OkendoRequestContextKeys & SKO;
10
- declare type RequestContextSafeType = string | number | boolean;
11
- export {};
1
+ export declare function useOkendoRequestContext(): OkendoRequestContext;
2
+ declare type RequestContextSafeType = string | number | boolean;
3
+ declare type RequestContext = Record<string, RequestContextSafeType>;
4
+ export interface OkendoRequestContext extends RequestContext {
5
+ setupFailed: boolean;
6
+ }
7
+ export {};
@@ -1,8 +1,4 @@
1
- import { useRequestContext } from '@shopify/hydrogen';
2
- export function setInOkendoRequestContext(key, value) {
3
- const okendoRequestContext = useOkendoRequestContext();
4
- okendoRequestContext[key] = value;
5
- }
6
- export function useOkendoRequestContext() {
7
- return useRequestContext('okendo');
8
- }
1
+ import { useRequestContext } from '@shopify/hydrogen';
2
+ export function useOkendoRequestContext() {
3
+ return useRequestContext('okendo');
4
+ }
@@ -1,5 +1,5 @@
1
- import type { Metafield } from '@shopify/hydrogen/dist/esnext/storefront-api-types';
2
- export declare type SKO = Record<string, unknown>;
3
- export declare type OkendoProductFragment = {
4
- okendoStarRatingSnippet?: Pick<Metafield, 'value'>;
5
- };
1
+ import type { Metafield } from '@shopify/hydrogen/dist/esnext/storefront-api-types';
2
+ export declare type SKO = Record<string, unknown>;
3
+ export declare type OkendoProductFragment = {
4
+ okendoStarRatingSnippet?: Pick<Metafield, 'value'>;
5
+ };
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1 +1 @@
1
- "use strict";
1
+ "use strict";
@@ -1,4 +1,4 @@
1
- import type { Plugin } from 'vite';
2
- declare const okendoPlugin: () => Plugin[];
3
- export = okendoPlugin;
4
- export default okendoPlugin;
1
+ import type { Plugin } from 'vite';
2
+ declare const okendoPlugin: () => Plugin[];
3
+ export = okendoPlugin;
4
+ export default okendoPlugin;
@@ -1,12 +1,12 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- const suppressModuleWarning_1 = __importDefault(require("./suppressModuleWarning"));
6
- const okendoPlugin = () => {
7
- return [
8
- (0, suppressModuleWarning_1.default)()
9
- ];
10
- };
11
- exports.default = okendoPlugin; // For ESM
12
- module.exports = okendoPlugin;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const suppressModuleWarning_1 = __importDefault(require("./suppressModuleWarning"));
6
+ const okendoPlugin = () => {
7
+ return [
8
+ (0, suppressModuleWarning_1.default)()
9
+ ];
10
+ };
11
+ exports.default = okendoPlugin; // For ESM
12
+ module.exports = okendoPlugin;
@@ -1,3 +1,3 @@
1
- import { Plugin } from 'vite';
2
- declare const _default: () => Plugin;
3
- export default _default;
1
+ import { Plugin } from 'vite';
2
+ declare const _default: () => Plugin;
3
+ export default _default;
@@ -1,20 +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
- };
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@okendo/shopify-hydrogen",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "A component library containing Okendo Reviews React components.",
5
5
  "main": "dist/esnext/index.js",
6
6
  "engines": {
@@ -35,7 +35,9 @@
35
35
  "build": "rimraf dist/ && npm run build:esm && npm run build:plugin:cjs",
36
36
  "build:plugin:cjs": "tsc --p tsconfig.plugin.cjs.json",
37
37
  "build:esm": "tsc --p tsconfig.esm.json",
38
- "prepublishOnly": "npm run build"
38
+ "prepublishOnly": "npm run build",
39
+ "eslint": "eslint 'src/**/*.{ts,tsx}'",
40
+ "eslint-fix": "npm run eslint -- --fix"
39
41
  },
40
42
  "author": "Okendo",
41
43
  "license": "SEE LICENSE IN LICENSE.txt",
@@ -46,7 +48,12 @@
46
48
  "@types/node": "^17.0.35",
47
49
  "@types/react": "^18.0.14",
48
50
  "@types/react-dom": "^18.0.5",
51
+ "@typescript-eslint/eslint-plugin": "^5.38.1",
52
+ "@typescript-eslint/parser": "^5.38.1",
49
53
  "dotenv": "^16.0.1",
54
+ "eslint": "^8.24.0",
55
+ "eslint-plugin-react": "^7.31.8",
56
+ "eslint-plugin-react-hooks": "^4.6.0",
50
57
  "ncp": "^2.0.0",
51
58
  "rimraf": "^3.0.2",
52
59
  "typescript": "^4.7.4",