@okendo/shopify-hydrogen 1.1.0 → 1.2.2
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.
- package/dist/esnext/client-components/OkendoClientStarRating.client.js +5 -5
- package/dist/esnext/client-components/OkendoWidget.client.js +11 -6
- package/dist/esnext/components/OkendoProvider.server.js +7 -7
- package/dist/esnext/components/OkendoReviewsWidget.server.js +4 -4
- package/dist/esnext/components/OkendoStarRating.server.js +4 -4
- package/dist/esnext/framework/plugins/plugin.js +0 -2
- package/dist/esnext/shared/logger.d.ts +14 -0
- package/dist/esnext/shared/logger.js +7 -0
- package/dist/node/framework/plugins/plugin.js +0 -2
- package/package.json +4 -7
- package/dist/esnext/framework/plugins/extendViteOptimizeDeps.d.ts +0 -2
- package/dist/esnext/framework/plugins/extendViteOptimizeDeps.js +0 -10
- package/dist/node/framework/plugins/extendViteOptimizeDeps.d.ts +0 -2
- package/dist/node/framework/plugins/extendViteOptimizeDeps.js +0 -14
|
@@ -2,23 +2,23 @@ import React from 'react';
|
|
|
2
2
|
import { OkendoWidgetClient } from './OkendoWidget.client';
|
|
3
3
|
import { getOkendoProductId } from '../shared/productUtils';
|
|
4
4
|
import { widgetConfigurationError, widgetMetafieldError } from '../shared/errorUtils';
|
|
5
|
+
import { logger } from '../shared/logger';
|
|
5
6
|
export const OkendoClientStarRating = (props) => {
|
|
6
7
|
const { productId, okendoStarRatingSnippet } = props;
|
|
7
8
|
const okendoProductId = getOkendoProductId(productId);
|
|
8
9
|
if (!okendoProductId) {
|
|
9
|
-
|
|
10
|
+
logger.error(widgetConfigurationError('OkendoClientStarRating', 'productId was not provided'));
|
|
10
11
|
return null;
|
|
11
12
|
}
|
|
12
13
|
if (!okendoStarRatingSnippet?.value) {
|
|
13
|
-
|
|
14
|
+
logger.warn(widgetMetafieldError('OkendoStarRating', 'StarRatingSnippet'));
|
|
14
15
|
}
|
|
15
16
|
const dataAttributes = {
|
|
16
17
|
'data-oke-star-rating': '',
|
|
17
|
-
'data-oke-reviews-product-id': okendoProductId
|
|
18
|
-
'data-oke-scroll-disabled': 'true'
|
|
18
|
+
'data-oke-reviews-product-id': okendoProductId
|
|
19
19
|
};
|
|
20
20
|
if (okendoStarRatingSnippet?.value) {
|
|
21
|
-
dataAttributes['data-oke-rendered'] =
|
|
21
|
+
dataAttributes['data-oke-rendered'] = '';
|
|
22
22
|
}
|
|
23
23
|
return (React.createElement(OkendoWidgetClient, { dataAttributes: dataAttributes, metafieldContent: okendoStarRatingSnippet?.value }));
|
|
24
24
|
};
|
|
@@ -2,18 +2,23 @@ import React, { useEffect, useRef } from 'react';
|
|
|
2
2
|
export const OkendoWidgetClient = (props) => {
|
|
3
3
|
const { dataAttributes, metafieldContent = '' } = props;
|
|
4
4
|
const widgetContainer = useRef(null);
|
|
5
|
-
const
|
|
5
|
+
const initializeWidget = () => {
|
|
6
6
|
if (widgetContainer.current) {
|
|
7
|
-
|
|
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);
|
|
8
10
|
}
|
|
9
11
|
};
|
|
10
12
|
useEffect(() => {
|
|
11
|
-
if (window.okeWidgetApi) {
|
|
12
|
-
|
|
13
|
+
if (window.okeWidgetApi && widgetContainer.current) {
|
|
14
|
+
initializeWidget();
|
|
13
15
|
}
|
|
14
16
|
else {
|
|
15
|
-
|
|
17
|
+
document.addEventListener('oke-script-loaded', initializeWidget);
|
|
16
18
|
}
|
|
17
|
-
|
|
19
|
+
return () => {
|
|
20
|
+
document.removeEventListener('oke-script-loaded', initializeWidget);
|
|
21
|
+
};
|
|
22
|
+
}, [dataAttributes]);
|
|
18
23
|
return (React.createElement("div", { ref: widgetContainer, ...dataAttributes, dangerouslySetInnerHTML: { __html: metafieldContent } }));
|
|
19
24
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import parse from 'html-react-parser';
|
|
3
2
|
import { fetchSync, useShopQuery, gql, CacheShort } from '@shopify/hydrogen';
|
|
4
3
|
import { Head } from '@shopify/hydrogen';
|
|
5
4
|
import { okendoError } from '../shared/errorUtils';
|
|
6
5
|
import { setInOkendoRequestContext } from '../shared/server/requestUtils';
|
|
6
|
+
import { logger } from '../shared/logger';
|
|
7
7
|
const kDefaultOkendoApiDomain = 'api.okendo.io/v1';
|
|
8
8
|
const kDefaultOkendoCdnDomain = 'cdn-static.okendo.io';
|
|
9
9
|
export const OkendoProvider = (props) => {
|
|
@@ -12,7 +12,7 @@ export const OkendoProvider = (props) => {
|
|
|
12
12
|
const url = `https://${apiDomain ?? kDefaultOkendoApiDomain}/stores/${subscriberId}/widget_plus_settings`;
|
|
13
13
|
const settingsResponse = fetchSync(url, { preload: true });
|
|
14
14
|
if (!settingsResponse.ok) {
|
|
15
|
-
|
|
15
|
+
logger.error(okendoError('Failed to retrieve subscriber settings. Please check your environment variables.'));
|
|
16
16
|
setInOkendoRequestContext('setupFailed', true);
|
|
17
17
|
return null;
|
|
18
18
|
}
|
|
@@ -25,7 +25,7 @@ export const OkendoProvider = (props) => {
|
|
|
25
25
|
preload: true
|
|
26
26
|
});
|
|
27
27
|
if (!initScriptResponse.ok) {
|
|
28
|
-
|
|
28
|
+
logger.error(okendoError('Failed to retrieve widget initialization script.'));
|
|
29
29
|
setInOkendoRequestContext('setupFailed', true);
|
|
30
30
|
return null;
|
|
31
31
|
}
|
|
@@ -50,9 +50,9 @@ export const OkendoProvider = (props) => {
|
|
|
50
50
|
query: query,
|
|
51
51
|
preload: true
|
|
52
52
|
});
|
|
53
|
-
const preRenderStyleTags = widgetPreRenderStyleTags?.value
|
|
53
|
+
const preRenderStyleTags = widgetPreRenderStyleTags?.value ?? '';
|
|
54
54
|
if (!preRenderStyleTags) {
|
|
55
|
-
|
|
55
|
+
logger.warn(okendoError('Failed to retrieve pre-rendered widget style settings.'));
|
|
56
56
|
}
|
|
57
57
|
return (React.createElement(React.Fragment, null,
|
|
58
58
|
React.createElement(Head, null,
|
|
@@ -62,7 +62,7 @@ export const OkendoProvider = (props) => {
|
|
|
62
62
|
React.createElement("meta", { name: "oke:subscriber_id", content: subscriberId }),
|
|
63
63
|
React.createElement("script", null, initScriptContents),
|
|
64
64
|
productUrlFormatter && React.createElement("script", { type: "text/javascript" }, `window.okeProductUrlFormatter = ${productUrlFormatter}`)),
|
|
65
|
-
preRenderStyleTags,
|
|
66
|
-
|
|
65
|
+
preRenderStyleTags && React.createElement("div", { dangerouslySetInnerHTML: { __html: preRenderStyleTags } }),
|
|
66
|
+
React.createElement("div", { dangerouslySetInnerHTML: { __html: starSymbols } }),
|
|
67
67
|
children));
|
|
68
68
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import parse from 'html-react-parser';
|
|
3
2
|
import { useShopQuery, gql } from '@shopify/hydrogen';
|
|
4
3
|
import { OkendoWidgetClient } from '../client-components/OkendoWidget.client';
|
|
5
4
|
import { widgetMetafieldError } from '../shared/errorUtils';
|
|
6
5
|
import { getOkendoProductId } from '../shared/productUtils';
|
|
7
6
|
import { useOkendoRequestContext } from '../shared/server/requestUtils';
|
|
7
|
+
import { logger } from '../shared/logger';
|
|
8
8
|
export const OkendoReviewsWidget = (props) => {
|
|
9
9
|
const { setupFailed } = useOkendoRequestContext();
|
|
10
10
|
if (setupFailed) {
|
|
@@ -38,10 +38,10 @@ export const OkendoReviewsWidget = (props) => {
|
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
40
|
if (productId && !product?.reviewsWidgetSnippet?.value) {
|
|
41
|
-
|
|
41
|
+
logger.warn(widgetMetafieldError('OkendoReviewsWidget', 'ReviewsWidgetSnippet'));
|
|
42
42
|
}
|
|
43
43
|
if (!shop?.widgetPreRenderBodyStyleTags?.value) {
|
|
44
|
-
|
|
44
|
+
logger.warn(widgetMetafieldError('OkendoReviewsWidget', 'WidgetPreRenderBodyStyleTags'));
|
|
45
45
|
}
|
|
46
46
|
const dataAttributes = {
|
|
47
47
|
'data-oke-widget': ''
|
|
@@ -53,7 +53,7 @@ export const OkendoReviewsWidget = (props) => {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
return (React.createElement(React.Fragment, null,
|
|
56
|
-
|
|
56
|
+
React.createElement("div", { dangerouslySetInnerHTML: { __html: shop?.widgetPreRenderBodyStyleTags?.value ?? '' } }),
|
|
57
57
|
React.createElement(OkendoWidgetClient, { dataAttributes: dataAttributes, metafieldContent: product?.reviewsWidgetSnippet?.value ?? '' })));
|
|
58
58
|
};
|
|
59
59
|
export default OkendoReviewsWidget;
|
|
@@ -4,6 +4,7 @@ import { OkendoWidgetClient } from '../client-components/OkendoWidget.client';
|
|
|
4
4
|
import { widgetConfigurationError, widgetMetafieldError } from '../shared/errorUtils';
|
|
5
5
|
import { getOkendoProductId } from '../shared/productUtils';
|
|
6
6
|
import { useOkendoRequestContext } from '../shared/server/requestUtils';
|
|
7
|
+
import { logger } from '../shared/logger';
|
|
7
8
|
export const OkendoStarRating = (props) => {
|
|
8
9
|
const { setupFailed } = useOkendoRequestContext();
|
|
9
10
|
if (setupFailed) {
|
|
@@ -12,7 +13,7 @@ export const OkendoStarRating = (props) => {
|
|
|
12
13
|
const { productId } = props;
|
|
13
14
|
const okendoProductId = getOkendoProductId(productId);
|
|
14
15
|
if (!okendoProductId) {
|
|
15
|
-
|
|
16
|
+
logger.error(widgetConfigurationError('OkendoStarRating', 'productId was not provided'));
|
|
16
17
|
return null;
|
|
17
18
|
}
|
|
18
19
|
const query = gql `
|
|
@@ -32,12 +33,11 @@ export const OkendoStarRating = (props) => {
|
|
|
32
33
|
}
|
|
33
34
|
});
|
|
34
35
|
if (!starRatingSnippet?.value) {
|
|
35
|
-
|
|
36
|
+
logger.warn(widgetMetafieldError('OkendoStarRating', 'StarRatingSnippet'));
|
|
36
37
|
}
|
|
37
38
|
const dataAttributes = {
|
|
38
39
|
'data-oke-star-rating': '',
|
|
39
|
-
'data-oke-reviews-product-id': okendoProductId
|
|
40
|
-
'data-oke-scroll-disabled': 'true'
|
|
40
|
+
'data-oke-reviews-product-id': okendoProductId
|
|
41
41
|
};
|
|
42
42
|
return (React.createElement(OkendoWidgetClient, { dataAttributes: dataAttributes, metafieldContent: starRatingSnippet?.value }));
|
|
43
43
|
};
|
|
@@ -0,0 +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
|
+
};
|
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
|
-
const extendViteOptimizeDeps_1 = require("./extendViteOptimizeDeps");
|
|
6
5
|
const suppressModuleWarning_1 = __importDefault(require("./suppressModuleWarning"));
|
|
7
6
|
const okendoPlugin = () => {
|
|
8
7
|
return [
|
|
9
|
-
(0, extendViteOptimizeDeps_1.extendViteOptimizeDeps)(),
|
|
10
8
|
(0, suppressModuleWarning_1.default)()
|
|
11
9
|
];
|
|
12
10
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@okendo/shopify-hydrogen",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "A component library containing Okendo Reviews React components.",
|
|
5
5
|
"main": "dist/esnext/index.js",
|
|
6
6
|
"engines": {
|
|
@@ -39,13 +39,10 @@
|
|
|
39
39
|
},
|
|
40
40
|
"author": "Okendo",
|
|
41
41
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
42
|
-
"dependencies": {
|
|
43
|
-
"html-react-parser": "^1.4.13"
|
|
44
|
-
},
|
|
45
42
|
"devDependencies": {
|
|
46
|
-
"@okendo/reviews-widget-plus": "^0.
|
|
43
|
+
"@okendo/reviews-widget-plus": "^0.53.1",
|
|
47
44
|
"@okendo/tsconfig": "0.0.2",
|
|
48
|
-
"@shopify/hydrogen": "^1.
|
|
45
|
+
"@shopify/hydrogen": "^1.2.0",
|
|
49
46
|
"@types/node": "^17.0.35",
|
|
50
47
|
"@types/react": "^18.0.14",
|
|
51
48
|
"@types/react-dom": "^18.0.5",
|
|
@@ -56,6 +53,6 @@
|
|
|
56
53
|
"vite": "^2.9.0"
|
|
57
54
|
},
|
|
58
55
|
"peerDependencies": {
|
|
59
|
-
"@shopify/hydrogen": "1.
|
|
56
|
+
"@shopify/hydrogen": "1.2.x"
|
|
60
57
|
}
|
|
61
58
|
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extendViteOptimizeDeps = void 0;
|
|
4
|
-
const extendViteOptimizeDeps = () => ({
|
|
5
|
-
name: 'vite-plugin-okendo-extend-optimize-deps',
|
|
6
|
-
config: () => ({
|
|
7
|
-
optimizeDeps: {
|
|
8
|
-
include: [
|
|
9
|
-
'@okendo/shopify-hydrogen > html-react-parser'
|
|
10
|
-
]
|
|
11
|
-
}
|
|
12
|
-
})
|
|
13
|
-
});
|
|
14
|
-
exports.extendViteOptimizeDeps = extendViteOptimizeDeps;
|