@okendo/shopify-hydrogen 1.3.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/LICENSE.txt +1 -1
  2. package/README.md +376 -464
  3. package/dist/cjs/index.js +1 -0
  4. package/dist/cjs/types/components/OkendoProvider/OkendoProvider.d.ts +36 -0
  5. package/dist/cjs/types/components/OkendoProvider/index.d.ts +1 -0
  6. package/dist/cjs/types/components/OkendoReviews/OkendoReviews.d.ts +11 -0
  7. package/dist/cjs/types/components/OkendoReviews/index.d.ts +1 -0
  8. package/dist/cjs/types/components/OkendoStarRating/OkendoStarRating.d.ts +11 -0
  9. package/dist/cjs/types/components/OkendoStarRating/index.d.ts +1 -0
  10. package/dist/cjs/types/components/index.d.ts +3 -0
  11. package/dist/cjs/types/fragments/fragments.d.ts +2 -0
  12. package/dist/cjs/types/fragments/index.d.ts +1 -0
  13. package/dist/cjs/types/index.d.ts +2 -0
  14. package/dist/cjs/types/internal/OkendoWidget/OkendoWidget.d.ts +12 -0
  15. package/dist/cjs/types/internal/types.d.ts +3 -0
  16. package/dist/esm/index.js +1 -0
  17. package/dist/esm/types/components/OkendoProvider/OkendoProvider.d.ts +36 -0
  18. package/dist/esm/types/components/OkendoProvider/index.d.ts +1 -0
  19. package/dist/esm/types/components/OkendoReviews/OkendoReviews.d.ts +11 -0
  20. package/dist/esm/types/components/OkendoReviews/index.d.ts +1 -0
  21. package/dist/esm/types/components/OkendoStarRating/OkendoStarRating.d.ts +11 -0
  22. package/dist/esm/types/components/OkendoStarRating/index.d.ts +1 -0
  23. package/dist/esm/types/components/index.d.ts +3 -0
  24. package/dist/esm/types/fragments/fragments.d.ts +2 -0
  25. package/dist/esm/types/fragments/index.d.ts +1 -0
  26. package/dist/esm/types/index.d.ts +2 -0
  27. package/dist/esm/types/internal/OkendoWidget/OkendoWidget.d.ts +12 -0
  28. package/dist/esm/types/internal/types.d.ts +3 -0
  29. package/dist/esm/types/internal/utils.d.ts +6 -0
  30. package/dist/index.d.ts +64 -0
  31. package/package.json +46 -63
  32. package/dist/esnext/client-components/OkendoClientStarRating.client.d.ts +0 -4
  33. package/dist/esnext/client-components/OkendoClientStarRating.client.js +0 -24
  34. package/dist/esnext/client-components/OkendoWidget.client.d.ts +0 -13
  35. package/dist/esnext/client-components/OkendoWidget.client.js +0 -23
  36. package/dist/esnext/client-components/index.d.ts +0 -1
  37. package/dist/esnext/client-components/index.js +0 -1
  38. package/dist/esnext/client.d.ts +0 -1
  39. package/dist/esnext/client.js +0 -1
  40. package/dist/esnext/components/OkendoProvider.server.d.ts +0 -15
  41. package/dist/esnext/components/OkendoProvider.server.js +0 -69
  42. package/dist/esnext/components/OkendoReviewsWidget.server.d.ts +0 -6
  43. package/dist/esnext/components/OkendoReviewsWidget.server.js +0 -61
  44. package/dist/esnext/components/OkendoStarRating.server.d.ts +0 -4
  45. package/dist/esnext/components/OkendoStarRating.server.js +0 -46
  46. package/dist/esnext/components/index.d.ts +0 -3
  47. package/dist/esnext/components/index.js +0 -3
  48. package/dist/esnext/fragments/index.d.ts +0 -1
  49. package/dist/esnext/fragments/index.js +0 -11
  50. package/dist/esnext/framework/index.d.ts +0 -0
  51. package/dist/esnext/framework/index.js +0 -1
  52. package/dist/esnext/framework/plugins/plugin.d.ts +0 -7
  53. package/dist/esnext/framework/plugins/plugin.js +0 -7
  54. package/dist/esnext/framework/plugins/suppressModuleWarning.d.ts +0 -3
  55. package/dist/esnext/framework/plugins/suppressModuleWarning.js +0 -18
  56. package/dist/esnext/index.d.ts +0 -4
  57. package/dist/esnext/index.js +0 -4
  58. package/dist/esnext/models/starRating.d.ts +0 -12
  59. package/dist/esnext/models/starRating.js +0 -1
  60. package/dist/esnext/shared/errorUtils.d.ts +0 -3
  61. package/dist/esnext/shared/errorUtils.js +0 -9
  62. package/dist/esnext/shared/logger.d.ts +0 -14
  63. package/dist/esnext/shared/logger.js +0 -7
  64. package/dist/esnext/shared/productUtils.js +0 -15
  65. package/dist/esnext/shared/server/requestUtils.d.ts +0 -7
  66. package/dist/esnext/shared/server/requestUtils.js +0 -4
  67. package/dist/esnext/shared/sharedTypes.d.ts +0 -5
  68. package/dist/esnext/shared/sharedTypes.js +0 -1
  69. package/dist/node/framework/index.d.ts +0 -0
  70. package/dist/node/framework/index.js +0 -1
  71. package/dist/node/framework/plugins/plugin.d.ts +0 -4
  72. package/dist/node/framework/plugins/plugin.js +0 -12
  73. package/dist/node/framework/plugins/suppressModuleWarning.d.ts +0 -3
  74. package/dist/node/framework/plugins/suppressModuleWarning.js +0 -20
  75. package/plugin.cjs +0 -1
  76. /package/dist/{esnext/shared/productUtils.d.ts → cjs/types/internal/utils.d.ts} +0 -0
@@ -0,0 +1 @@
1
+ "use strict";var t=require("react");const e=({dataAttributes:e,metafieldContent:n=""})=>{const r=t.useRef(null),s=()=>{r.current&&window.okeWidgetApi.initWidget(r.current)};return t.useEffect((()=>(window.okeWidgetApi&&r.current?s():document.addEventListener("oke-script-loaded",s),()=>{document.removeEventListener("oke-script-loaded",s)})),[e]),t.createElement("div",{ref:r,key:JSON.stringify(e),...e,dangerouslySetInnerHTML:{__html:n}})},n=/^[0-9]*$/;function r(t){if(t)return`shopify-${n.test(t)?t:t.split("/").slice(-1)[0]}`}exports.OKENDO_PRODUCT_REVIEWS_FRAGMENT='#graphql\n\tfragment OkendoReviewsSnippet on Product {\n\t\tokendoReviewsSnippet: metafield(\n\t\t\tnamespace: "okendo"\n\t\t\tkey: "ReviewsWidgetSnippet"\n\t\t) {\n\t\t\tvalue\n\t\t}\n\t}\n',exports.OKENDO_PRODUCT_STAR_RATING_FRAGMENT='#graphql\n\tfragment OkendoStarRatingSnippet on Product {\n\t\tokendoStarRatingSnippet: metafield(\n\t\t\tnamespace: "okendo"\n\t\t\tkey: "StarRatingSnippet"\n\t\t) {\n\t\t\tvalue\n\t\t}\n\t}\n',exports.OkendoProvider=({okendoProviderData:e,productUrlFormatter:n})=>{if(!e)return null;const{reviewsHeaderConfig:r,cssVariables:s,customCss:i,initScriptContents:o,preRenderStyleTags:a,starSymbols:d}=e,l="function"==typeof n?n.toString():"string"==typeof n?n:"(product) =>\n\t\t\t\t\tproduct && product.productHandle\n\t\t\t\t\t\t? \"/products/\" + product.productHandle + \"/\" + (product.variantId ? '?variantId=' + product.variantId : '')\n\t\t\t\t\t\t: undefined",c=(s??"").replace('<style id="oke-css-vars">',"").replace("</style>",""),p=i?i.replace('<style id="oke-reviews-custom-css">',"").replace("</style>",""):"";return t.createElement("div",null,t.createElement("script",{id:"oke-reviews-settings",type:"application/json",dangerouslySetInnerHTML:{__html:JSON.stringify(r)}}),t.createElement("style",{id:"oke-css-vars",dangerouslySetInnerHTML:{__html:c}}),p&&t.createElement("style",{id:"oke-reviews-custom-css",dangerouslySetInnerHTML:{__html:p}}),o&&t.createElement("script",{dangerouslySetInnerHTML:{__html:o}}),t.createElement("script",{type:"text/javascript",dangerouslySetInnerHTML:{__html:`window.okeProductUrlFormatter = ${l.toString()}`}}),a&&t.createElement("div",{dangerouslySetInnerHTML:{__html:a}}),d&&t.createElement("div",{dangerouslySetInnerHTML:{__html:d}}))},exports.OkendoReviews=({productId:n,okendoReviewsSnippet:s})=>{const i={"data-oke-widget":"","data-oke-reviews-product-id":r(n)};return t.createElement(e,{dataAttributes:i,metafieldContent:s?.value})},exports.OkendoStarRating=({productId:n,okendoStarRatingSnippet:s})=>{const i={"data-oke-star-rating":"","data-oke-reviews-product-id":r(n)};return t.createElement(e,{dataAttributes:i,metafieldContent:s?.value})},exports.getOkendoProviderData=async({context:t,subscriberId:e,apiDomain:n,cdnDomain:r})=>{const s=`https://${n||"api.okendo.io/v1"}/stores/${e}/widget_plus_settings`,i=await fetch(s);if(!i.ok)return console.error(`Failed to retrieve subscriber settings for subscriber ID '${e}'.`),null;const{reviewsHeaderConfig:o,cssVariables:a,customCss:d,starSymbols:l}=await i.json(),c=await fetch(`https://${r||"cdn-static.okendo.io"}/reviews-widget-plus/js/okendo-reviews.js`);if(!c.ok)return console.error("Failed to retrieve widget initialisation script."),null;const p=await c.text(),{shop:{widgetPreRenderStyleTags:u}}=await t.storefront.query('#graphql\n\t\tquery metafields {\n\t\t\tshop {\n\t\t\t\twidgetPreRenderStyleTags: metafield(\n\t\t\t\t\tnamespace: "okendo"\n\t\t\t\t\tkey: "WidgetPreRenderStyleTags"\n\t\t\t\t) {\n\t\t\t\t\tvalue\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t'),g=u?.value??"";return g||console.warn("Failed to retrieve pre-rendered widget style settings."),{reviewsHeaderConfig:o,cssVariables:a,customCss:d,initScriptContents:p,preRenderStyleTags:g,starSymbols:l}};
@@ -0,0 +1,36 @@
1
+ import type { Storefront } from "@shopify/hydrogen";
2
+ import { type FC } from "react";
3
+ interface OkendoProviderData {
4
+ reviewsHeaderConfig: Record<string, unknown>;
5
+ cssVariables: string;
6
+ customCss?: string;
7
+ initScriptContents: string;
8
+ preRenderStyleTags: string;
9
+ starSymbols: string;
10
+ }
11
+ export declare const getOkendoProviderData: ({ context, subscriberId, apiDomain, cdnDomain, }: {
12
+ context: {
13
+ storefront: Storefront;
14
+ };
15
+ subscriberId: string;
16
+ apiDomain?: string | undefined;
17
+ cdnDomain?: string | undefined;
18
+ }) => Promise<{
19
+ reviewsHeaderConfig: import("@okendo/reviews-common").WidgetPlus.ReviewsHeaderConfig;
20
+ cssVariables: string;
21
+ customCss: string | undefined;
22
+ initScriptContents: string;
23
+ preRenderStyleTags: string;
24
+ starSymbols: string;
25
+ } | null>;
26
+ interface ReviewProduct {
27
+ productHandle?: string;
28
+ productId: string;
29
+ variantId?: string;
30
+ }
31
+ interface OkendoProviderProps {
32
+ okendoProviderData: Partial<OkendoProviderData> | null;
33
+ productUrlFormatter?: (product: ReviewProduct) => string;
34
+ }
35
+ export declare const OkendoProvider: FC<OkendoProviderProps>;
36
+ export {};
@@ -0,0 +1 @@
1
+ export * from "./OkendoProvider";
@@ -0,0 +1,11 @@
1
+ import { type FC } from "react";
2
+ import { type MetafieldValue } from "../../internal/types";
3
+ export interface WithOkendoReviewsSnippet {
4
+ okendoReviewsSnippet: MetafieldValue;
5
+ }
6
+ interface OkendoReviewsProps {
7
+ productId: string;
8
+ okendoReviewsSnippet?: MetafieldValue;
9
+ }
10
+ export declare const OkendoReviews: FC<OkendoReviewsProps>;
11
+ export {};
@@ -0,0 +1 @@
1
+ export * from "./OkendoReviews";
@@ -0,0 +1,11 @@
1
+ import { type FC } from "react";
2
+ import { type MetafieldValue } from "../../internal/types";
3
+ export interface WithOkendoStarRatingSnippet {
4
+ okendoStarRatingSnippet: MetafieldValue;
5
+ }
6
+ interface OkendoStarRatingProps {
7
+ productId: string;
8
+ okendoStarRatingSnippet?: MetafieldValue;
9
+ }
10
+ export declare const OkendoStarRating: FC<OkendoStarRatingProps>;
11
+ export {};
@@ -0,0 +1 @@
1
+ export * from "./OkendoStarRating";
@@ -0,0 +1,3 @@
1
+ export * from "./OkendoProvider";
2
+ export * from "./OkendoReviews";
3
+ export * from "./OkendoStarRating";
@@ -0,0 +1,2 @@
1
+ export declare const OKENDO_PRODUCT_STAR_RATING_FRAGMENT = "#graphql\n\tfragment OkendoStarRatingSnippet on Product {\n\t\tokendoStarRatingSnippet: metafield(\n\t\t\tnamespace: \"okendo\"\n\t\t\tkey: \"StarRatingSnippet\"\n\t\t) {\n\t\t\tvalue\n\t\t}\n\t}\n";
2
+ export declare const OKENDO_PRODUCT_REVIEWS_FRAGMENT = "#graphql\n\tfragment OkendoReviewsSnippet on Product {\n\t\tokendoReviewsSnippet: metafield(\n\t\t\tnamespace: \"okendo\"\n\t\t\tkey: \"ReviewsWidgetSnippet\"\n\t\t) {\n\t\t\tvalue\n\t\t}\n\t}\n";
@@ -0,0 +1 @@
1
+ export * from "./fragments";
@@ -0,0 +1,2 @@
1
+ export * from "./components";
2
+ export * from "./fragments";
@@ -0,0 +1,12 @@
1
+ import type { ReviewsWidgetPlus } from "@okendo/reviews-widget-plus/dist-utils/ReviewsWidgetPlus";
2
+ import { type FC } from "react";
3
+ export interface OkendoWidgetProps {
4
+ dataAttributes: Record<string, unknown>;
5
+ metafieldContent?: string;
6
+ }
7
+ declare global {
8
+ interface Window {
9
+ okeWidgetApi: ReviewsWidgetPlus.WidgetWindowApi;
10
+ }
11
+ }
12
+ export declare const OkendoWidget: FC<OkendoWidgetProps>;
@@ -0,0 +1,3 @@
1
+ export interface MetafieldValue {
2
+ value: string;
3
+ }
@@ -0,0 +1 @@
1
+ import t,{useRef as e,useEffect as n}from"react";const r=async({context:t,subscriberId:e,apiDomain:n,cdnDomain:r})=>{const i=`https://${n||"api.okendo.io/v1"}/stores/${e}/widget_plus_settings`,o=await fetch(i);if(!o.ok)return console.error(`Failed to retrieve subscriber settings for subscriber ID '${e}'.`),null;const{reviewsHeaderConfig:s,cssVariables:a,customCss:d,starSymbols:l}=await o.json(),c=await fetch(`https://${r||"cdn-static.okendo.io"}/reviews-widget-plus/js/okendo-reviews.js`);if(!c.ok)return console.error("Failed to retrieve widget initialisation script."),null;const p=await c.text(),{shop:{widgetPreRenderStyleTags:u}}=await t.storefront.query('#graphql\n\t\tquery metafields {\n\t\t\tshop {\n\t\t\t\twidgetPreRenderStyleTags: metafield(\n\t\t\t\t\tnamespace: "okendo"\n\t\t\t\t\tkey: "WidgetPreRenderStyleTags"\n\t\t\t\t) {\n\t\t\t\t\tvalue\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t'),m=u?.value??"";return m||console.warn("Failed to retrieve pre-rendered widget style settings."),{reviewsHeaderConfig:s,cssVariables:a,customCss:d,initScriptContents:p,preRenderStyleTags:m,starSymbols:l}},i=({okendoProviderData:e,productUrlFormatter:n})=>{if(!e)return null;const{reviewsHeaderConfig:r,cssVariables:i,customCss:o,initScriptContents:s,preRenderStyleTags:a,starSymbols:d}=e,l="function"==typeof n?n.toString():"string"==typeof n?n:"(product) =>\n\t\t\t\t\tproduct && product.productHandle\n\t\t\t\t\t\t? \"/products/\" + product.productHandle + \"/\" + (product.variantId ? '?variantId=' + product.variantId : '')\n\t\t\t\t\t\t: undefined",c=(i??"").replace('<style id="oke-css-vars">',"").replace("</style>",""),p=o?o.replace('<style id="oke-reviews-custom-css">',"").replace("</style>",""):"";return t.createElement("div",null,t.createElement("script",{id:"oke-reviews-settings",type:"application/json",dangerouslySetInnerHTML:{__html:JSON.stringify(r)}}),t.createElement("style",{id:"oke-css-vars",dangerouslySetInnerHTML:{__html:c}}),p&&t.createElement("style",{id:"oke-reviews-custom-css",dangerouslySetInnerHTML:{__html:p}}),s&&t.createElement("script",{dangerouslySetInnerHTML:{__html:s}}),t.createElement("script",{type:"text/javascript",dangerouslySetInnerHTML:{__html:`window.okeProductUrlFormatter = ${l.toString()}`}}),a&&t.createElement("div",{dangerouslySetInnerHTML:{__html:a}}),d&&t.createElement("div",{dangerouslySetInnerHTML:{__html:d}}))},o=({dataAttributes:r,metafieldContent:i=""})=>{const o=e(null),s=()=>{o.current&&window.okeWidgetApi.initWidget(o.current)};return n((()=>(window.okeWidgetApi&&o.current?s():document.addEventListener("oke-script-loaded",s),()=>{document.removeEventListener("oke-script-loaded",s)})),[r]),t.createElement("div",{ref:o,key:JSON.stringify(r),...r,dangerouslySetInnerHTML:{__html:i}})},s=/^[0-9]*$/;function a(t){if(t)return`shopify-${s.test(t)?t:t.split("/").slice(-1)[0]}`}const d=({productId:e,okendoReviewsSnippet:n})=>{const r={"data-oke-widget":"","data-oke-reviews-product-id":a(e)};return t.createElement(o,{dataAttributes:r,metafieldContent:n?.value})},l=({productId:e,okendoStarRatingSnippet:n})=>{const r={"data-oke-star-rating":"","data-oke-reviews-product-id":a(e)};return t.createElement(o,{dataAttributes:r,metafieldContent:n?.value})},c='#graphql\n\tfragment OkendoStarRatingSnippet on Product {\n\t\tokendoStarRatingSnippet: metafield(\n\t\t\tnamespace: "okendo"\n\t\t\tkey: "StarRatingSnippet"\n\t\t) {\n\t\t\tvalue\n\t\t}\n\t}\n',p='#graphql\n\tfragment OkendoReviewsSnippet on Product {\n\t\tokendoReviewsSnippet: metafield(\n\t\t\tnamespace: "okendo"\n\t\t\tkey: "ReviewsWidgetSnippet"\n\t\t) {\n\t\t\tvalue\n\t\t}\n\t}\n';export{p as OKENDO_PRODUCT_REVIEWS_FRAGMENT,c as OKENDO_PRODUCT_STAR_RATING_FRAGMENT,i as OkendoProvider,d as OkendoReviews,l as OkendoStarRating,r as getOkendoProviderData};
@@ -0,0 +1,36 @@
1
+ import type { Storefront } from "@shopify/hydrogen";
2
+ import { type FC } from "react";
3
+ interface OkendoProviderData {
4
+ reviewsHeaderConfig: Record<string, unknown>;
5
+ cssVariables: string;
6
+ customCss?: string;
7
+ initScriptContents: string;
8
+ preRenderStyleTags: string;
9
+ starSymbols: string;
10
+ }
11
+ export declare const getOkendoProviderData: ({ context, subscriberId, apiDomain, cdnDomain, }: {
12
+ context: {
13
+ storefront: Storefront;
14
+ };
15
+ subscriberId: string;
16
+ apiDomain?: string | undefined;
17
+ cdnDomain?: string | undefined;
18
+ }) => Promise<{
19
+ reviewsHeaderConfig: import("@okendo/reviews-common").WidgetPlus.ReviewsHeaderConfig;
20
+ cssVariables: string;
21
+ customCss: string | undefined;
22
+ initScriptContents: string;
23
+ preRenderStyleTags: string;
24
+ starSymbols: string;
25
+ } | null>;
26
+ interface ReviewProduct {
27
+ productHandle?: string;
28
+ productId: string;
29
+ variantId?: string;
30
+ }
31
+ interface OkendoProviderProps {
32
+ okendoProviderData: Partial<OkendoProviderData> | null;
33
+ productUrlFormatter?: (product: ReviewProduct) => string;
34
+ }
35
+ export declare const OkendoProvider: FC<OkendoProviderProps>;
36
+ export {};
@@ -0,0 +1 @@
1
+ export * from "./OkendoProvider";
@@ -0,0 +1,11 @@
1
+ import { type FC } from "react";
2
+ import { type MetafieldValue } from "../../internal/types";
3
+ export interface WithOkendoReviewsSnippet {
4
+ okendoReviewsSnippet: MetafieldValue;
5
+ }
6
+ interface OkendoReviewsProps {
7
+ productId: string;
8
+ okendoReviewsSnippet?: MetafieldValue;
9
+ }
10
+ export declare const OkendoReviews: FC<OkendoReviewsProps>;
11
+ export {};
@@ -0,0 +1 @@
1
+ export * from "./OkendoReviews";
@@ -0,0 +1,11 @@
1
+ import { type FC } from "react";
2
+ import { type MetafieldValue } from "../../internal/types";
3
+ export interface WithOkendoStarRatingSnippet {
4
+ okendoStarRatingSnippet: MetafieldValue;
5
+ }
6
+ interface OkendoStarRatingProps {
7
+ productId: string;
8
+ okendoStarRatingSnippet?: MetafieldValue;
9
+ }
10
+ export declare const OkendoStarRating: FC<OkendoStarRatingProps>;
11
+ export {};
@@ -0,0 +1 @@
1
+ export * from "./OkendoStarRating";
@@ -0,0 +1,3 @@
1
+ export * from "./OkendoProvider";
2
+ export * from "./OkendoReviews";
3
+ export * from "./OkendoStarRating";
@@ -0,0 +1,2 @@
1
+ export declare const OKENDO_PRODUCT_STAR_RATING_FRAGMENT = "#graphql\n\tfragment OkendoStarRatingSnippet on Product {\n\t\tokendoStarRatingSnippet: metafield(\n\t\t\tnamespace: \"okendo\"\n\t\t\tkey: \"StarRatingSnippet\"\n\t\t) {\n\t\t\tvalue\n\t\t}\n\t}\n";
2
+ export declare const OKENDO_PRODUCT_REVIEWS_FRAGMENT = "#graphql\n\tfragment OkendoReviewsSnippet on Product {\n\t\tokendoReviewsSnippet: metafield(\n\t\t\tnamespace: \"okendo\"\n\t\t\tkey: \"ReviewsWidgetSnippet\"\n\t\t) {\n\t\t\tvalue\n\t\t}\n\t}\n";
@@ -0,0 +1 @@
1
+ export * from "./fragments";
@@ -0,0 +1,2 @@
1
+ export * from "./components";
2
+ export * from "./fragments";
@@ -0,0 +1,12 @@
1
+ import type { ReviewsWidgetPlus } from "@okendo/reviews-widget-plus/dist-utils/ReviewsWidgetPlus";
2
+ import { type FC } from "react";
3
+ export interface OkendoWidgetProps {
4
+ dataAttributes: Record<string, unknown>;
5
+ metafieldContent?: string;
6
+ }
7
+ declare global {
8
+ interface Window {
9
+ okeWidgetApi: ReviewsWidgetPlus.WidgetWindowApi;
10
+ }
11
+ }
12
+ export declare const OkendoWidget: FC<OkendoWidgetProps>;
@@ -0,0 +1,3 @@
1
+ export interface MetafieldValue {
2
+ value: string;
3
+ }
@@ -0,0 +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;
@@ -0,0 +1,64 @@
1
+ import * as _okendo_reviews_common from '@okendo/reviews-common';
2
+ import { Storefront } from '@shopify/hydrogen';
3
+ import { FC } from 'react';
4
+
5
+ interface OkendoProviderData {
6
+ reviewsHeaderConfig: Record<string, unknown>;
7
+ cssVariables: string;
8
+ customCss?: string;
9
+ initScriptContents: string;
10
+ preRenderStyleTags: string;
11
+ starSymbols: string;
12
+ }
13
+ declare const getOkendoProviderData: ({ context, subscriberId, apiDomain, cdnDomain, }: {
14
+ context: {
15
+ storefront: Storefront;
16
+ };
17
+ subscriberId: string;
18
+ apiDomain?: string | undefined;
19
+ cdnDomain?: string | undefined;
20
+ }) => Promise<{
21
+ reviewsHeaderConfig: _okendo_reviews_common.WidgetPlus.ReviewsHeaderConfig;
22
+ cssVariables: string;
23
+ customCss: string | undefined;
24
+ initScriptContents: string;
25
+ preRenderStyleTags: string;
26
+ starSymbols: string;
27
+ } | null>;
28
+ interface ReviewProduct {
29
+ productHandle?: string;
30
+ productId: string;
31
+ variantId?: string;
32
+ }
33
+ interface OkendoProviderProps {
34
+ okendoProviderData: Partial<OkendoProviderData> | null;
35
+ productUrlFormatter?: (product: ReviewProduct) => string;
36
+ }
37
+ declare const OkendoProvider: FC<OkendoProviderProps>;
38
+
39
+ interface MetafieldValue {
40
+ value: string;
41
+ }
42
+
43
+ interface WithOkendoReviewsSnippet {
44
+ okendoReviewsSnippet: MetafieldValue;
45
+ }
46
+ interface OkendoReviewsProps {
47
+ productId: string;
48
+ okendoReviewsSnippet?: MetafieldValue;
49
+ }
50
+ declare const OkendoReviews: FC<OkendoReviewsProps>;
51
+
52
+ interface WithOkendoStarRatingSnippet {
53
+ okendoStarRatingSnippet: MetafieldValue;
54
+ }
55
+ interface OkendoStarRatingProps {
56
+ productId: string;
57
+ okendoStarRatingSnippet?: MetafieldValue;
58
+ }
59
+ declare const OkendoStarRating: FC<OkendoStarRatingProps>;
60
+
61
+ declare const OKENDO_PRODUCT_STAR_RATING_FRAGMENT = "#graphql\n\tfragment OkendoStarRatingSnippet on Product {\n\t\tokendoStarRatingSnippet: metafield(\n\t\t\tnamespace: \"okendo\"\n\t\t\tkey: \"StarRatingSnippet\"\n\t\t) {\n\t\t\tvalue\n\t\t}\n\t}\n";
62
+ declare const OKENDO_PRODUCT_REVIEWS_FRAGMENT = "#graphql\n\tfragment OkendoReviewsSnippet on Product {\n\t\tokendoReviewsSnippet: metafield(\n\t\t\tnamespace: \"okendo\"\n\t\t\tkey: \"ReviewsWidgetSnippet\"\n\t\t) {\n\t\t\tvalue\n\t\t}\n\t}\n";
63
+
64
+ export { OKENDO_PRODUCT_REVIEWS_FRAGMENT, OKENDO_PRODUCT_STAR_RATING_FRAGMENT, OkendoProvider, OkendoReviews, OkendoStarRating, WithOkendoReviewsSnippet, WithOkendoStarRatingSnippet, getOkendoProviderData };
package/package.json CHANGED
@@ -1,65 +1,48 @@
1
1
  {
2
- "name": "@okendo/shopify-hydrogen",
3
- "version": "1.3.0",
4
- "description": "A component library containing Okendo Reviews React components.",
5
- "main": "dist/esnext/index.js",
6
- "engines": {
7
- "node": ">=14"
8
- },
9
- "exports": {
10
- ".": "./dist/esnext/index.js",
11
- "./plugin": {
12
- "import": "./dist/esnext/framework/plugins/plugin.js",
13
- "require": "./dist/node/framework/plugins/plugin.js"
14
- },
15
- "./client": {
16
- "import": {
17
- "types": "./dist/esnext/client.d.ts",
18
- "default": "./dist/esnext/client.js"
19
- },
20
- "node": {
21
- "types": "./dist/esnext/client.d.ts",
22
- "default": "./dist/esnext/client.js"
23
- }
24
- },
25
- "./plugin.cjs": "./plugin.cjs",
26
- "./package.json": "./package.json",
27
- "./*": "./dist/esnext/*.js"
28
- },
29
- "types": "dist/esnext/index.d.ts",
30
- "files": [
31
- "dist",
32
- "plugin.cjs"
33
- ],
34
- "scripts": {
35
- "build": "rimraf dist/ && npm run build:esm && npm run build:plugin:cjs",
36
- "build:plugin:cjs": "tsc --p tsconfig.plugin.cjs.json",
37
- "build:esm": "tsc --p tsconfig.esm.json",
38
- "prepublishOnly": "npm run build",
39
- "eslint": "eslint 'src/**/*.{ts,tsx}'",
40
- "eslint-fix": "npm run eslint -- --fix"
41
- },
42
- "author": "Okendo",
43
- "license": "SEE LICENSE IN LICENSE.txt",
44
- "devDependencies": {
45
- "@okendo/reviews-widget-plus": "^0.53.1",
46
- "@okendo/tsconfig": "0.0.2",
47
- "@shopify/hydrogen": "^1.2.0",
48
- "@types/node": "^17.0.35",
49
- "@types/react": "^18.0.14",
50
- "@types/react-dom": "^18.0.5",
51
- "@typescript-eslint/eslint-plugin": "^5.38.1",
52
- "@typescript-eslint/parser": "^5.38.1",
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",
57
- "ncp": "^2.0.0",
58
- "rimraf": "^3.0.2",
59
- "typescript": "^4.7.4",
60
- "vite": "^2.9.0"
61
- },
62
- "peerDependencies": {
63
- "@shopify/hydrogen": "1.2.x"
64
- }
2
+ "name": "@okendo/shopify-hydrogen",
3
+ "version": "2.0.0",
4
+ "description": "Okendo React components for Shopify Hydrogen 2 (Remix)",
5
+ "author": "Okendo",
6
+ "license": "SEE LICENSE IN LICENSE.txt",
7
+ "engines": {
8
+ "node": ">=16.14"
9
+ },
10
+ "main": "dist/cjs/index.js",
11
+ "module": "dist/esm/index.js",
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "types": "dist/index.d.ts",
16
+ "scripts": {
17
+ "build": "npm run eslint -- --max-warnings=0 && rimraf dist && rollup -c",
18
+ "eslint": "eslint src"
19
+ },
20
+ "devDependencies": {
21
+ "@okendo/reviews-common": "^5.38.0",
22
+ "@okendo/reviews-widget-plus": "^0.67.0",
23
+ "@okendo/tsconfig": "0.0.2",
24
+ "@rollup/plugin-commonjs": "^24.1.0",
25
+ "@rollup/plugin-node-resolve": "^15.0.2",
26
+ "@rollup/plugin-terser": "^0.4.1",
27
+ "@rollup/plugin-typescript": "^11.1.0",
28
+ "@types/react": "^18.0.20",
29
+ "@types/react-dom": "^18.0.6",
30
+ "@typescript-eslint/eslint-plugin": "^5.58.0",
31
+ "@typescript-eslint/parser": "^5.58.0",
32
+ "eslint": "^8.20.0",
33
+ "eslint-config-prettier": "^8.8.0",
34
+ "eslint-plugin-react": "^7.32.2",
35
+ "eslint-plugin-react-hooks": "^4.6.0",
36
+ "prettier": "2.8.7",
37
+ "rimraf": "^5.0.0",
38
+ "rollup": "^3.20.2",
39
+ "rollup-plugin-dts": "^5.3.0",
40
+ "rollup-plugin-peer-deps-external": "^2.2.4",
41
+ "typescript": "^4.9.5"
42
+ },
43
+ "peerDependencies": {
44
+ "@shopify/hydrogen": "^2023.1.6",
45
+ "@shopify/remix-oxygen": "^1.0.4",
46
+ "react": "^18.2.0"
47
+ }
65
48
  }
@@ -1,4 +0,0 @@
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 +0,0 @@
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 +0,0 @@
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 +0,0 @@
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 +0,0 @@
1
- export * from './OkendoClientStarRating.client';
@@ -1 +0,0 @@
1
- export * from './OkendoClientStarRating.client';
@@ -1 +0,0 @@
1
- export * from './client-components';
@@ -1 +0,0 @@
1
- export * from './client-components';
@@ -1,15 +0,0 @@
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,69 +0,0 @@
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.
41
- const query = gql `
42
- query metafields {
43
- shop {
44
- widgetPreRenderStyleTags: metafield(namespace: "okendo", key: "WidgetPreRenderStyleTags") {
45
- value
46
- }
47
- }
48
- }
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 +0,0 @@
1
- import { FC } from 'react';
2
- export declare const OkendoReviewsWidget: FC<OkendoReviewsWidgetProps>;
3
- interface OkendoReviewsWidgetProps {
4
- productId?: string;
5
- }
6
- export default OkendoReviewsWidget;