@okendo/shopify-hydrogen 1.2.4 → 1.3.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.
- package/dist/esnext/client-components/OkendoClientStarRating.client.d.ts +4 -4
- package/dist/esnext/client-components/OkendoClientStarRating.client.js +24 -24
- package/dist/esnext/client-components/OkendoWidget.client.d.ts +13 -13
- package/dist/esnext/client-components/OkendoWidget.client.js +23 -23
- package/dist/esnext/client-components/index.d.ts +1 -1
- package/dist/esnext/client-components/index.js +1 -1
- package/dist/esnext/client.d.ts +1 -1
- package/dist/esnext/client.js +1 -1
- package/dist/esnext/components/OkendoProvider.server.d.ts +15 -15
- package/dist/esnext/components/OkendoProvider.server.js +61 -63
- package/dist/esnext/components/OkendoReviewsWidget.server.d.ts +6 -6
- package/dist/esnext/components/OkendoReviewsWidget.server.js +46 -46
- package/dist/esnext/components/OkendoStarRating.server.d.ts +4 -4
- package/dist/esnext/components/OkendoStarRating.server.js +38 -38
- package/dist/esnext/components/index.d.ts +3 -3
- package/dist/esnext/components/index.js +3 -3
- package/dist/esnext/fragments/index.d.ts +1 -1
- package/dist/esnext/fragments/index.js +2 -2
- package/dist/esnext/framework/index.js +1 -1
- package/dist/esnext/framework/plugins/plugin.d.ts +7 -7
- package/dist/esnext/framework/plugins/plugin.js +7 -7
- package/dist/esnext/framework/plugins/suppressModuleWarning.d.ts +3 -3
- package/dist/esnext/framework/plugins/suppressModuleWarning.js +18 -18
- package/dist/esnext/index.d.ts +4 -4
- package/dist/esnext/index.js +4 -4
- package/dist/esnext/models/starRating.d.ts +12 -12
- package/dist/esnext/models/starRating.js +1 -1
- package/dist/esnext/shared/errorUtils.d.ts +3 -3
- package/dist/esnext/shared/errorUtils.js +9 -9
- package/dist/esnext/shared/logger.d.ts +14 -14
- package/dist/esnext/shared/logger.js +7 -7
- package/dist/esnext/shared/productUtils.d.ts +6 -6
- package/dist/esnext/shared/productUtils.js +15 -15
- package/dist/esnext/shared/server/requestUtils.d.ts +7 -7
- package/dist/esnext/shared/server/requestUtils.js +4 -4
- package/dist/esnext/shared/sharedTypes.d.ts +5 -5
- package/dist/esnext/shared/sharedTypes.js +1 -1
- package/dist/node/framework/index.js +1 -1
- package/dist/node/framework/plugins/plugin.d.ts +4 -4
- package/dist/node/framework/plugins/plugin.js +12 -12
- package/dist/node/framework/plugins/suppressModuleWarning.d.ts +3 -3
- package/dist/node/framework/plugins/suppressModuleWarning.js +20 -20
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FC } from 'react';
|
|
2
|
-
import type { OkendoClientStarRatingProps } from '../models/starRating';
|
|
3
|
-
export declare const OkendoClientStarRating: FC<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,24 +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 = ({ 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
|
+
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 { 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
|
+
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,23 +1,23 @@
|
|
|
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
|
+
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';
|
package/dist/esnext/client.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './client-components';
|
|
1
|
+
export * from './client-components';
|
package/dist/esnext/client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './client-components';
|
|
1
|
+
export * from './client-components';
|
|
@@ -1,15 +1,15 @@
|
|
|
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
|
+
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,45 +1,43 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { useOkendoRequestContext } from '../shared/server/requestUtils';
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
: undefined;
|
|
42
|
-
// Get pre-rendered style settings.
|
|
1
|
+
import { CacheCustom, Head, fetchSync, gql, useShopQuery } from '@shopify/hydrogen';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { okendoError } from '../shared/errorUtils';
|
|
4
|
+
import { logger } from '../shared/logger';
|
|
5
|
+
import { useOkendoRequestContext } from '../shared/server/requestUtils';
|
|
6
|
+
const kDefaultOkendoApiDomain = 'api.okendo.io/v1';
|
|
7
|
+
const kDefaultOkendoCdnDomain = 'cdn-static.okendo.io';
|
|
8
|
+
export const OkendoProvider = ({ apiDomain, cdnDomain, children, productUrlFormatOverride, subscriberId }) => {
|
|
9
|
+
const okendoRequestContext = useOkendoRequestContext();
|
|
10
|
+
// Download subscriber widget plus settings.
|
|
11
|
+
const url = `https://${apiDomain ?? kDefaultOkendoApiDomain}/stores/${subscriberId}/widget_plus_settings`;
|
|
12
|
+
const settingsResponse = fetchSync(url, { cache: CacheCustom({ maxAge: 60, staleWhileRevalidate: 300 }) });
|
|
13
|
+
if (!settingsResponse.ok) {
|
|
14
|
+
logger.error(okendoError('Failed to retrieve subscriber settings. Please check your environment variables.'));
|
|
15
|
+
okendoRequestContext.setupFailed = true;
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const { cssVariables, customCss, reviewsHeaderConfig, starSymbols } = settingsResponse.json();
|
|
19
|
+
const cssVariablesNormalized = cssVariables.replace('<style id="oke-css-vars">', '').replace('</style>', '');
|
|
20
|
+
const customCssNormalized = customCss ? customCss.replace('<style id="oke-reviews-custom-css">', '').replace('</style>', '') : '';
|
|
21
|
+
// Download contents of widget initialisation script.
|
|
22
|
+
const initScriptResponse = fetchSync(`https://${cdnDomain ?? kDefaultOkendoCdnDomain}/reviews-widget-plus/js/okendo-reviews.js`, {
|
|
23
|
+
cache: CacheCustom({ maxAge: 60, staleWhileRevalidate: 300 })
|
|
24
|
+
});
|
|
25
|
+
if (!initScriptResponse.ok) {
|
|
26
|
+
logger.error(okendoError('Failed to retrieve widget initialization script.'));
|
|
27
|
+
okendoRequestContext.setupFailed = true;
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const initScriptContents = initScriptResponse.text();
|
|
31
|
+
return React.createElement(OkendoProviderContent, { productUrlFormatOverride: productUrlFormatOverride, subscriberId: subscriberId, reviewsHeaderConfig: reviewsHeaderConfig, starSymbols: starSymbols, cssVariablesNormalized: cssVariablesNormalized, customCssNormalized: customCssNormalized, initScriptContents: initScriptContents }, children);
|
|
32
|
+
};
|
|
33
|
+
const OkendoProviderContent = ({ children, productUrlFormatOverride, subscriberId, reviewsHeaderConfig, starSymbols, cssVariablesNormalized, customCssNormalized, initScriptContents, }) => {
|
|
34
|
+
// Set up product URL formatter.
|
|
35
|
+
const productUrlFormatter = typeof productUrlFormatOverride === 'function'
|
|
36
|
+
? productUrlFormatOverride
|
|
37
|
+
: (product) => product?.productHandle
|
|
38
|
+
? `/products/${product.productHandle}/${product.variantId ? '?variantId=' + product.variantId : ''}`
|
|
39
|
+
: undefined;
|
|
40
|
+
// Get pre-rendered style settings.
|
|
43
41
|
const query = gql `
|
|
44
42
|
query metafields {
|
|
45
43
|
shop {
|
|
@@ -48,24 +46,24 @@ const OkendoProviderContent = ({ children, productUrlFormatOverride, subscriberI
|
|
|
48
46
|
}
|
|
49
47
|
}
|
|
50
48
|
}
|
|
51
|
-
`;
|
|
52
|
-
const { data: { shop: { widgetPreRenderStyleTags } } } = useShopQuery({
|
|
53
|
-
query,
|
|
54
|
-
|
|
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
|
-
};
|
|
49
|
+
`;
|
|
50
|
+
const { data: { shop: { widgetPreRenderStyleTags } } } = useShopQuery({
|
|
51
|
+
query,
|
|
52
|
+
cache: CacheCustom({ maxAge: 60, staleWhileRevalidate: 300 })
|
|
53
|
+
});
|
|
54
|
+
const preRenderStyleTags = widgetPreRenderStyleTags?.value ?? '';
|
|
55
|
+
if (!preRenderStyleTags) {
|
|
56
|
+
logger.warn(okendoError('Failed to retrieve pre-rendered widget style settings.'));
|
|
57
|
+
}
|
|
58
|
+
return (React.createElement(React.Fragment, null,
|
|
59
|
+
React.createElement(Head, null,
|
|
60
|
+
React.createElement("script", { id: "oke-reviews-settings", type: "application/json" }, JSON.stringify(reviewsHeaderConfig)),
|
|
61
|
+
React.createElement("style", { id: "oke-css-vars" }, cssVariablesNormalized),
|
|
62
|
+
customCssNormalized && React.createElement("style", { id: "oke-reviews-custom-css" }, customCssNormalized),
|
|
63
|
+
React.createElement("meta", { name: "oke:subscriber_id", content: subscriberId }),
|
|
64
|
+
React.createElement("script", null, initScriptContents),
|
|
65
|
+
productUrlFormatter && React.createElement("script", { type: "text/javascript" }, `window.okeProductUrlFormatter = ${productUrlFormatter}`)),
|
|
66
|
+
preRenderStyleTags && React.createElement("div", { dangerouslySetInnerHTML: { __html: preRenderStyleTags } }),
|
|
67
|
+
React.createElement("div", { dangerouslySetInnerHTML: { __html: starSymbols } }),
|
|
68
|
+
children));
|
|
69
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { FC } from 'react';
|
|
2
|
-
export declare const OkendoReviewsWidget: FC<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,27 +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
|
-
return React.createElement(OkendoReviewsWidgetContent, { ...props });
|
|
14
|
-
};
|
|
15
|
-
const OkendoReviewsWidgetContent = ({ productId }) => {
|
|
16
|
-
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
|
|
17
17
|
? `
|
|
18
18
|
product(id: $productId) {
|
|
19
19
|
reviewsWidgetSnippet: metafield(namespace: "okendo", key: "ReviewsWidgetSnippet") {
|
|
20
20
|
value
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
`
|
|
24
|
-
: '';
|
|
23
|
+
`
|
|
24
|
+
: '';
|
|
25
25
|
const query = gql `
|
|
26
26
|
query metafields${productId ? '($productId: ID!)' : ''} {
|
|
27
27
|
${productQuery}
|
|
@@ -31,31 +31,31 @@ const OkendoReviewsWidgetContent = ({ productId }) => {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
}
|
|
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;
|
|
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 { FC } from 'react';
|
|
2
|
-
import type { OkendoStarRatingProps } from '../models/starRating';
|
|
3
|
-
export declare const OkendoStarRating: FC<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,23 +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 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 }) => {
|
|
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 }) => {
|
|
21
21
|
const query = gql `
|
|
22
22
|
query metafields($productId: ID!) {
|
|
23
23
|
product(id: $productId) {
|
|
@@ -26,21 +26,21 @@ const OkendoStarRatingContent = ({ productId, okendoProductId }) => {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
}
|
|
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;
|
|
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
|
+
};
|
package/dist/esnext/index.d.ts
CHANGED
|
@@ -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';
|
package/dist/esnext/index.js
CHANGED
|
@@ -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.info,
|
|
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,7 +1,7 @@
|
|
|
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
|
+
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,4 +1,4 @@
|
|
|
1
|
-
import { useRequestContext } from '@shopify/hydrogen';
|
|
2
|
-
export function useOkendoRequestContext() {
|
|
3
|
-
return useRequestContext('okendo');
|
|
4
|
-
}
|
|
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
|
+
};
|