@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
@@ -1,61 +0,0 @@
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
- ? `
18
- product(id: $productId) {
19
- reviewsWidgetSnippet: metafield(namespace: "okendo", key: "ReviewsWidgetSnippet") {
20
- value
21
- }
22
- }
23
- `
24
- : '';
25
- const query = gql `
26
- query metafields${productId ? '($productId: ID!)' : ''} {
27
- ${productQuery}
28
- shop {
29
- widgetPreRenderBodyStyleTags: metafield(namespace: "okendo", key: "WidgetPreRenderBodyStyleTags") {
30
- value
31
- }
32
- }
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;
@@ -1,4 +0,0 @@
1
- import { FC } from 'react';
2
- import type { OkendoStarRatingProps } from '../models/starRating';
3
- export declare const OkendoStarRating: FC<OkendoStarRatingProps>;
4
- export default OkendoStarRating;
@@ -1,46 +0,0 @@
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
- const query = gql `
22
- query metafields($productId: ID!) {
23
- product(id: $productId) {
24
- starRatingSnippet: metafield(namespace: "okendo", key: "StarRatingSnippet") {
25
- value
26
- }
27
- }
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;
@@ -1,3 +0,0 @@
1
- export * from './OkendoProvider.server';
2
- export * from './OkendoReviewsWidget.server';
3
- export * from './OkendoStarRating.server';
@@ -1,3 +0,0 @@
1
- export * from './OkendoProvider.server';
2
- export * from './OkendoReviewsWidget.server';
3
- export * from './OkendoStarRating.server';
@@ -1 +0,0 @@
1
- export declare const OKENDO_PRODUCT_STAR_RATING_FRAGMENT: string;
@@ -1,11 +0,0 @@
1
- import { gql } from '@shopify/hydrogen';
2
- export const OKENDO_PRODUCT_STAR_RATING_FRAGMENT = gql `
3
- fragment OkendoStarRatingSnippet on Product {
4
- okendoStarRatingSnippet: metafield(
5
- namespace: "okendo"
6
- key: "StarRatingSnippet"
7
- ) {
8
- value
9
- }
10
- }
11
- `;
File without changes
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,7 +0,0 @@
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 +0,0 @@
1
- import suppressModuleWarning from './suppressModuleWarning';
2
- const okendoPlugin = () => {
3
- return [
4
- suppressModuleWarning()
5
- ];
6
- };
7
- export default okendoPlugin; // For ESM
@@ -1,3 +0,0 @@
1
- import { Plugin } from 'vite';
2
- declare const _default: () => Plugin;
3
- export default _default;
@@ -1,18 +0,0 @@
1
- /* Inspired by Hydrogen 1.0.0 source hydrogen\packages\hydrogen\src\framework\plugins\vite-plugin-hydrogen-suppress-warnings.ts */
2
- export default () => {
3
- return {
4
- name: 'okendo:suppress-warnings',
5
- configResolved(config) {
6
- // TODO: Fix the actual issues that cause these warnings
7
- const filterOut = (msg) => msg.startsWith("@okendo/shopify-hydrogen doesn't appear to be written in CJS");
8
- for (const method of ['warn', 'warnOnce']) {
9
- const original = config.logger[method];
10
- config.logger[method] = (msg, ...args) => {
11
- if (filterOut(msg))
12
- return;
13
- return original(msg, ...args);
14
- };
15
- }
16
- },
17
- };
18
- };
@@ -1,4 +0,0 @@
1
- export * from './components';
2
- export * from './fragments';
3
- export * from './shared/server/requestUtils';
4
- export * from './shared/sharedTypes';
@@ -1,4 +0,0 @@
1
- export * from './components';
2
- export * from './fragments';
3
- export * from './shared/server/requestUtils';
4
- export * from './shared/sharedTypes';
@@ -1,12 +0,0 @@
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 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
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 +0,0 @@
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 +0,0 @@
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 +0,0 @@
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,15 +0,0 @@
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 +0,0 @@
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 +0,0 @@
1
- import { useRequestContext } from '@shopify/hydrogen';
2
- export function useOkendoRequestContext() {
3
- return useRequestContext('okendo');
4
- }
@@ -1,5 +0,0 @@
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 +0,0 @@
1
- export {};
File without changes
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,4 +0,0 @@
1
- import type { Plugin } from 'vite';
2
- declare const okendoPlugin: () => Plugin[];
3
- export = okendoPlugin;
4
- export default okendoPlugin;
@@ -1,12 +0,0 @@
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 +0,0 @@
1
- import { Plugin } from 'vite';
2
- declare const _default: () => Plugin;
3
- export default _default;
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /* Inspired by Hydrogen 1.0.0 source hydrogen\packages\hydrogen\src\framework\plugins\vite-plugin-hydrogen-suppress-warnings.ts */
4
- exports.default = () => {
5
- return {
6
- name: 'okendo:suppress-warnings',
7
- configResolved(config) {
8
- // TODO: Fix the actual issues that cause these warnings
9
- const filterOut = (msg) => msg.startsWith("@okendo/shopify-hydrogen doesn't appear to be written in CJS");
10
- for (const method of ['warn', 'warnOnce']) {
11
- const original = config.logger[method];
12
- config.logger[method] = (msg, ...args) => {
13
- if (filterOut(msg))
14
- return;
15
- return original(msg, ...args);
16
- };
17
- }
18
- },
19
- };
20
- };
package/plugin.cjs DELETED
@@ -1 +0,0 @@
1
- module.exports = require('./dist/node/framework/plugin');