@okendo/shopify-hydrogen 1.2.2 → 1.2.3

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.
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import { FC } from 'react';
2
2
  import type { OkendoClientStarRatingProps } from '../models/starRating';
3
- export declare const OkendoClientStarRating: React.FunctionComponent<OkendoClientStarRatingProps>;
3
+ export declare const OkendoClientStarRating: FC<OkendoClientStarRatingProps>;
4
4
  export default OkendoClientStarRating;
@@ -3,8 +3,7 @@ import { OkendoWidgetClient } from './OkendoWidget.client';
3
3
  import { getOkendoProductId } from '../shared/productUtils';
4
4
  import { widgetConfigurationError, widgetMetafieldError } from '../shared/errorUtils';
5
5
  import { logger } from '../shared/logger';
6
- export const OkendoClientStarRating = (props) => {
7
- const { productId, okendoStarRatingSnippet } = props;
6
+ export const OkendoClientStarRating = ({ productId, okendoStarRatingSnippet }) => {
8
7
  const okendoProductId = getOkendoProductId(productId);
9
8
  if (!okendoProductId) {
10
9
  logger.error(widgetConfigurationError('OkendoClientStarRating', 'productId was not provided'));
@@ -1,7 +1,7 @@
1
- import React from 'react';
1
+ import { FC } from 'react';
2
2
  import type { ReviewsWidgetPlus } from '@okendo/reviews-widget-plus/dist-utils/ReviewsWidgetPlus';
3
3
  import type { SKO } from '../shared/sharedTypes';
4
- export declare const OkendoWidgetClient: React.FunctionComponent<OkendoWidgetClientProps>;
4
+ export declare const OkendoWidgetClient: FC<OkendoWidgetClientProps>;
5
5
  export interface OkendoWidgetClientProps {
6
6
  dataAttributes: SKO;
7
7
  metafieldContent?: string;
@@ -1,6 +1,5 @@
1
1
  import React, { useEffect, useRef } from 'react';
2
- export const OkendoWidgetClient = (props) => {
3
- const { dataAttributes, metafieldContent = '' } = props;
2
+ export const OkendoWidgetClient = ({ dataAttributes, metafieldContent = '' }) => {
4
3
  const widgetContainer = useRef(null);
5
4
  const initializeWidget = () => {
6
5
  if (widgetContainer.current) {
@@ -1,5 +1,5 @@
1
- import React from 'react';
2
- export declare const OkendoProvider: React.FunctionComponent<OkendoProviderProps>;
1
+ import React, { FC } from 'react';
2
+ export declare const OkendoProvider: FC<OkendoProviderProps>;
3
3
  interface OkendoProviderProps {
4
4
  apiDomain?: string;
5
5
  cdnDomain?: string;
@@ -2,18 +2,18 @@ import React from 'react';
2
2
  import { fetchSync, useShopQuery, gql, CacheShort } from '@shopify/hydrogen';
3
3
  import { Head } from '@shopify/hydrogen';
4
4
  import { okendoError } from '../shared/errorUtils';
5
- import { setInOkendoRequestContext } from '../shared/server/requestUtils';
5
+ import { useOkendoRequestContext } from '../shared/server/requestUtils';
6
6
  import { logger } from '../shared/logger';
7
7
  const kDefaultOkendoApiDomain = 'api.okendo.io/v1';
8
8
  const kDefaultOkendoCdnDomain = 'cdn-static.okendo.io';
9
- export const OkendoProvider = (props) => {
10
- const { apiDomain, cdnDomain, children, productUrlFormatOverride, subscriberId } = props;
9
+ export const OkendoProvider = ({ apiDomain, cdnDomain, children, productUrlFormatOverride, subscriberId }) => {
10
+ const okendoRequestContext = useOkendoRequestContext();
11
11
  // Download subscriber widget plus settings.
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
- setInOkendoRequestContext('setupFailed', true);
16
+ okendoRequestContext.setupFailed = true;
17
17
  return null;
18
18
  }
19
19
  const { cssVariables, customCss, reviewsHeaderConfig, starSymbols } = settingsResponse.json();
@@ -26,10 +26,13 @@ export const OkendoProvider = (props) => {
26
26
  });
27
27
  if (!initScriptResponse.ok) {
28
28
  logger.error(okendoError('Failed to retrieve widget initialization script.'));
29
- setInOkendoRequestContext('setupFailed', true);
29
+ okendoRequestContext.setupFailed = true;
30
30
  return null;
31
31
  }
32
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, }) => {
33
36
  // Set up product URL formatter.
34
37
  const productUrlFormatter = typeof productUrlFormatOverride === 'function'
35
38
  ? productUrlFormatOverride
@@ -38,16 +41,16 @@ export const OkendoProvider = (props) => {
38
41
  : undefined;
39
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
- `;
51
+ `;
49
52
  const { data: { shop: { widgetPreRenderStyleTags } } } = useShopQuery({
50
- query: query,
53
+ query,
51
54
  preload: true
52
55
  });
53
56
  const preRenderStyleTags = widgetPreRenderStyleTags?.value ?? '';
@@ -1,5 +1,5 @@
1
- import React from 'react';
2
- export declare const OkendoReviewsWidget: React.FunctionComponent<OkendoReviewsWidgetProps>;
1
+ import { FC } from 'react';
2
+ export declare const OkendoReviewsWidget: FC<OkendoReviewsWidgetProps>;
3
3
  interface OkendoReviewsWidgetProps {
4
4
  productId?: string;
5
5
  }
@@ -10,7 +10,9 @@ export const OkendoReviewsWidget = (props) => {
10
10
  if (setupFailed) {
11
11
  return null;
12
12
  }
13
- const { productId } = props;
13
+ return React.createElement(OkendoReviewsWidgetContent, { ...props });
14
+ };
15
+ const OkendoReviewsWidgetContent = ({ productId }) => {
14
16
  const productQuery = productId
15
17
  ? `
16
18
  product(id: $productId) {
@@ -31,7 +33,7 @@ export const OkendoReviewsWidget = (props) => {
31
33
  }
32
34
  `;
33
35
  const { data: { product, shop } } = useShopQuery({
34
- query: query,
36
+ query,
35
37
  preload: true,
36
38
  variables: {
37
39
  productId
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import { FC } from 'react';
2
2
  import type { OkendoStarRatingProps } from '../models/starRating';
3
- export declare const OkendoStarRating: React.FunctionComponent<OkendoStarRatingProps>;
3
+ export declare const OkendoStarRating: FC<OkendoStarRatingProps>;
4
4
  export default OkendoStarRating;
@@ -10,12 +10,14 @@ export const OkendoStarRating = (props) => {
10
10
  if (setupFailed) {
11
11
  return null;
12
12
  }
13
- const { productId } = props;
14
- const okendoProductId = getOkendoProductId(productId);
13
+ const okendoProductId = getOkendoProductId(props.productId);
15
14
  if (!okendoProductId) {
16
15
  logger.error(widgetConfigurationError('OkendoStarRating', 'productId was not provided'));
17
16
  return null;
18
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) {
@@ -26,7 +28,7 @@ export const OkendoStarRating = (props) => {
26
28
  }
27
29
  `;
28
30
  const { data: { product: { starRatingSnippet } } } = useShopQuery({
29
- query: query,
31
+ query,
30
32
  preload: true,
31
33
  variables: {
32
34
  productId
@@ -1,7 +1,7 @@
1
1
  const isProduction = process.env.NODE_ENV === 'production';
2
2
  const noop = () => undefined;
3
3
  export const logger = {
4
- log: isProduction ? noop : console.log,
4
+ log: isProduction ? noop : console.info,
5
5
  warn: isProduction ? noop : console.warn,
6
6
  error: console.error
7
7
  };
@@ -1,11 +1,7 @@
1
- import type { SKO } from '../sharedTypes';
2
- export declare function setInOkendoRequestContext(key: keyof OkendoRequestContextKeys, value: RequestContextSafeType | RequestContextSafeType[]): void;
3
1
  export declare function useOkendoRequestContext(): OkendoRequestContext;
4
- interface OkendoRequestContextKeys {
2
+ declare type RequestContextSafeType = string | number | boolean;
3
+ declare type RequestContext = Record<string, RequestContextSafeType>;
4
+ export interface OkendoRequestContext extends RequestContext {
5
5
  setupFailed: boolean;
6
6
  }
7
- export interface OkendoRequestContext extends OkendoRequestContextKeysWithSKO {
8
- }
9
- declare type OkendoRequestContextKeysWithSKO = OkendoRequestContextKeys & SKO;
10
- declare type RequestContextSafeType = string | number | boolean;
11
7
  export {};
@@ -1,8 +1,4 @@
1
1
  import { useRequestContext } from '@shopify/hydrogen';
2
- export function setInOkendoRequestContext(key, value) {
3
- const okendoRequestContext = useOkendoRequestContext();
4
- okendoRequestContext[key] = value;
5
- }
6
2
  export function useOkendoRequestContext() {
7
3
  return useRequestContext('okendo');
8
4
  }
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.3",
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",