@usereactify/search 5.53.0 → 5.55.0-beta.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/CHANGELOG.md +19 -0
- package/dist/package.json +2 -2
- package/dist/src/components/ClearAll/ClearAll.d.ts +1 -1
- package/dist/src/components/ClearAll/ClearAll.js +3 -2
- package/dist/src/components/ClearAll/ClearAll.js.map +1 -1
- package/dist/src/components/ClearAll/index.js +5 -1
- package/dist/src/components/ClearAll/index.js.map +1 -1
- package/dist/src/components/CustomComponent/CustomComponent.d.ts +1 -1
- package/dist/src/components/CustomComponent/index.js +5 -1
- package/dist/src/components/CustomComponent/index.js.map +1 -1
- package/dist/src/components/Example/ExampleClearAll.d.ts +1 -1
- package/dist/src/components/Example/ExampleFilterList.d.ts +1 -1
- package/dist/src/components/Example/ExampleFilterRange.d.ts +1 -1
- package/dist/src/components/Example/ExampleFilterSlider.d.ts +1 -1
- package/dist/src/components/Example/ExampleFiltersSelected.d.ts +1 -1
- package/dist/src/components/Example/ExampleHookUseResults.js.map +1 -1
- package/dist/src/components/Example/ExampleResultCardCallout.d.ts +1 -1
- package/dist/src/components/Example/ExampleResultCardProduct.d.ts +1 -1
- package/dist/src/components/Example/ExampleResultPaginationInfiniteScroll.d.ts +1 -1
- package/dist/src/components/Example/ExampleResultPaginationInfiniteScroll.js.map +1 -1
- package/dist/src/components/Example/ExampleResultPaginationLoadMore.d.ts +1 -1
- package/dist/src/components/Example/ExampleResultPaginationNextPrev.d.ts +1 -1
- package/dist/src/components/Example/ExampleResultPaginationNumbered.d.ts +1 -1
- package/dist/src/components/Example/ExampleSearch.d.ts +1 -1
- package/dist/src/components/Example/ExampleSortBy.d.ts +1 -1
- package/dist/src/components/Example/ExampleStats.d.ts +1 -1
- package/dist/src/components/Example/ExampleSuggestions.d.ts +1 -1
- package/dist/src/components/Example/index.js +5 -1
- package/dist/src/components/Example/index.js.map +1 -1
- package/dist/src/components/Filter/Filter.d.ts +1 -1
- package/dist/src/components/Filter/Filter.js.map +1 -1
- package/dist/src/components/Filter/Filters.d.ts +1 -1
- package/dist/src/components/Filter/FiltersSelected.d.ts +1 -1
- package/dist/src/components/Filter/FiltersSelected.js +3 -2
- package/dist/src/components/Filter/FiltersSelected.js.map +1 -1
- package/dist/src/components/Filter/index.js +5 -1
- package/dist/src/components/Filter/index.js.map +1 -1
- package/dist/src/components/ReactifySearchProvider/ReactifySearchProvider.d.ts +1 -1
- package/dist/src/components/ReactifySearchProvider/ReactifySearchProvider.js +5 -1
- package/dist/src/components/ReactifySearchProvider/ReactifySearchProvider.js.map +1 -1
- package/dist/src/components/ReactifySearchProvider/index.js +5 -1
- package/dist/src/components/ReactifySearchProvider/index.js.map +1 -1
- package/dist/src/components/Result/ResultCardCallout.d.ts +1 -1
- package/dist/src/components/Result/ResultCardCallout.js.map +1 -1
- package/dist/src/components/Result/ResultCardProduct.d.ts +1 -1
- package/dist/src/components/Result/ResultCardProduct.js.map +1 -1
- package/dist/src/components/Result/ResultPaginationInfiniteScroll.d.ts +1 -1
- package/dist/src/components/Result/ResultPaginationLoadMore.d.ts +1 -1
- package/dist/src/components/Result/ResultPaginationNextPrev.d.ts +1 -1
- package/dist/src/components/Result/ResultPaginationNumbered.d.ts +1 -1
- package/dist/src/components/Result/ResultPaginationNumbered.js.map +1 -1
- package/dist/src/components/Result/ResultStateProvider.d.ts +1 -1
- package/dist/src/components/Result/Results.d.ts +2 -2
- package/dist/src/components/Result/Results.js.map +1 -1
- package/dist/src/components/Result/index.js +5 -1
- package/dist/src/components/Result/index.js.map +1 -1
- package/dist/src/components/Search/Search.d.ts +1 -1
- package/dist/src/components/Search/index.js +5 -1
- package/dist/src/components/Search/index.js.map +1 -1
- package/dist/src/components/Sensor/SensorCollection.js.map +1 -1
- package/dist/src/components/Sensor/SensorInventoryAvailable.js.map +1 -1
- package/dist/src/components/Sensor/SensorPublished.js.map +1 -1
- package/dist/src/components/Sensor/SensorSearchTerm.js.map +1 -1
- package/dist/src/components/Sensor/SensorSort.js.map +1 -1
- package/dist/src/components/Sensor/Sensors.d.ts +1 -1
- package/dist/src/components/Sensor/Sensors.js.map +1 -1
- package/dist/src/components/Sensor/index.js +5 -1
- package/dist/src/components/Sensor/index.js.map +1 -1
- package/dist/src/components/SortBy/SortBy.d.ts +1 -1
- package/dist/src/components/SortBy/index.js +5 -1
- package/dist/src/components/SortBy/index.js.map +1 -1
- package/dist/src/components/Stats/Stats.d.ts +1 -1
- package/dist/src/components/Stats/index.js +5 -1
- package/dist/src/components/Stats/index.js.map +1 -1
- package/dist/src/components/Suggestions/Suggestions.d.ts +1 -1
- package/dist/src/components/Suggestions/Suggestions.js.map +1 -1
- package/dist/src/components/Suggestions/index.js +5 -1
- package/dist/src/components/Suggestions/index.js.map +1 -1
- package/dist/src/components/Utility/UtilityAuthenticatedReactiveBase.d.ts +1 -1
- package/dist/src/components/Utility/index.js +5 -1
- package/dist/src/components/Utility/index.js.map +1 -1
- package/dist/src/components/index.js +5 -1
- package/dist/src/components/index.js.map +1 -1
- package/dist/src/hooks/index.js +5 -1
- package/dist/src/hooks/index.js.map +1 -1
- package/dist/src/hooks/reactivesearch/index.js +5 -1
- package/dist/src/hooks/reactivesearch/index.js.map +1 -1
- package/dist/src/hooks/reactivesearch/useReactiveBaseProps.js.map +1 -1
- package/dist/src/hooks/useAnalytics.d.ts +1 -1
- package/dist/src/hooks/useAnalytics.js +2 -2
- package/dist/src/hooks/useAnalytics.js.map +1 -1
- package/dist/src/hooks/useConfig.d.ts +1 -1
- package/dist/src/hooks/useConfig.js +1 -12
- package/dist/src/hooks/useConfig.js.map +1 -1
- package/dist/src/hooks/useCuration.d.ts +1 -1
- package/dist/src/hooks/useCuration.js.map +1 -1
- package/dist/src/hooks/useDebugger.d.ts +1 -0
- package/dist/src/hooks/useDebugger.js +12 -1
- package/dist/src/hooks/useDebugger.js.map +1 -1
- package/dist/src/hooks/useFilterListProps.js.map +1 -1
- package/dist/src/hooks/useFilterRangeProps.js +4 -3
- package/dist/src/hooks/useFilterRangeProps.js.map +1 -1
- package/dist/src/hooks/useFilterSliderProps.js +4 -3
- package/dist/src/hooks/useFilterSliderProps.js.map +1 -1
- package/dist/src/hooks/useFilters.d.ts +2 -2
- package/dist/src/hooks/useFilters.js +0 -3
- package/dist/src/hooks/useFilters.js.map +1 -1
- package/dist/src/hooks/useFlags.js +2 -4
- package/dist/src/hooks/useFlags.js.map +1 -1
- package/dist/src/hooks/useIndices.d.ts +1 -1
- package/dist/src/hooks/useIndices.js.map +1 -1
- package/dist/src/hooks/usePagination.d.ts +3 -3
- package/dist/src/hooks/usePagination.js.map +1 -1
- package/dist/src/hooks/usePaginationLoadable.js.map +1 -1
- package/dist/src/hooks/useProductPrice.js.map +1 -1
- package/dist/src/hooks/useReactifySearchContext.d.ts +21 -21
- package/dist/src/hooks/useResults.d.ts +1 -9
- package/dist/src/hooks/useResults.js +9 -7
- package/dist/src/hooks/useResults.js.map +1 -1
- package/dist/src/hooks/useSearch.d.ts +10 -3
- package/dist/src/hooks/useSearch.js +11 -5
- package/dist/src/hooks/useSearch.js.map +1 -1
- package/dist/src/hooks/useSortBy.d.ts +2 -2
- package/dist/src/hooks/useSortBy.js +0 -2
- package/dist/src/hooks/useSortBy.js.map +1 -1
- package/dist/src/index.js +5 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/types/config.d.ts +10 -10
- package/dist/src/types/elastic.d.ts +6 -6
- package/dist/src/types/elastic.js +2 -2
- package/dist/src/types/elastic.js.map +1 -1
- package/dist/src/types/firestore.d.ts +6 -6
- package/dist/src/types/firestore.js +15 -15
- package/dist/src/types/firestore.js.map +1 -1
- package/dist/src/types/graphql.d.ts +3204 -3204
- package/dist/src/types/graphql.js +445 -445
- package/dist/src/types/graphql.js.map +1 -1
- package/dist/src/types/index.js +5 -1
- package/dist/src/types/index.js.map +1 -1
- package/dist/src/types/shopify.d.ts +14 -14
- package/dist/src/types/shopify.js +7 -7
- package/dist/src/types/shopify.js.map +1 -1
- package/dist/src/utility/config.js.map +1 -1
- package/dist/src/utility/curation.js.map +1 -1
- package/dist/src/utility/debug.d.ts +2 -1
- package/dist/src/utility/debug.js +1 -0
- package/dist/src/utility/debug.js.map +1 -1
- package/dist/src/utility/filters.js.map +1 -1
- package/dist/src/utility/index.js +5 -1
- package/dist/src/utility/index.js.map +1 -1
- package/dist/src/utility/liquid.js +3 -3
- package/dist/src/utility/liquid.js.map +1 -1
- package/dist/src/utility/props.d.ts +7 -8
- package/dist/src/utility/props.js +6 -6
- package/dist/src/utility/props.js.map +1 -1
- package/dist/src/utility/sortOption.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIndices.js","sourceRoot":"","sources":["../../../src/hooks/useIndices.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAA0B;AAC1B,yEAAsE;AAO/D,MAAM,UAAU,GAAG,GAAe,EAAE;IACzC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,IAAA,mDAAwB,GAAE,CAAC;IACvD,MAAM,QAAQ,GAAG,OAAO,CAAC,sBAAsB,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC;IAE9E,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,eAAK,CAAC,QAAQ,CAAwB,EAAE,CAAC,CAAC;IAExE,MAAM,eAAe,GAAkC,CAAC,SAAS,EAAE,EAAE;QACnE,IAAI,kBAAkB,GAAG,SAAS,CAAC;QACnC,IAAI;
|
|
1
|
+
{"version":3,"file":"useIndices.js","sourceRoot":"","sources":["../../../src/hooks/useIndices.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAA0B;AAC1B,yEAAsE;AAO/D,MAAM,UAAU,GAAG,GAAe,EAAE;IACzC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,IAAA,mDAAwB,GAAE,CAAC;IACvD,MAAM,QAAQ,GAAG,OAAO,CAAC,sBAAsB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nC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CACpC,CAAC;QACJ,CAAC,CAAA,CAAC,EAAE,CAAC;IACP,CAAC,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEtB,OAAO;QACL,OAAO,EAAE,OAAO;QAChB,eAAe,EAAE,eAAe;KACjC,CAAC;AACJ,CAAC,CAAC;AAhDW,QAAA,UAAU,cAgDrB","sourcesContent":["import React from \"react\";\nimport { useReactifySearchContext } from \"./useReactifySearchContext\";\n\nexport type UseIndices = {\n indices: Array<string>;\n indexNameFormat: (indexName: string) => string;\n};\n\nexport const useIndices = (): UseIndices => {\n const { config, options } = useReactifySearchContext();\n const shopName = options.shopifyPermanentDomain.replace(\".myshopify.com\", \"\");\n\n const [indices, setIndices] = React.useState<UseIndices[\"indices\"]>([]);\n\n const indexNameFormat: UseIndices[\"indexNameFormat\"] = (indexName) => {\n let indexNameFormatted = indexName;\n try {\n const indexDate = indexName.split(`${shopName}-`)[1];\n\n indexNameFormatted = `${shopName} ${new Date(\n parseInt(indexDate)\n ).toLocaleString()} (${indexDate})`;\n } catch (error) {\n console.error(error);\n }\n\n return indexNameFormatted;\n };\n\n React.useEffect(() => {\n (async () => {\n const response: Array<{ index: string }> = await fetch(\n `${config.endpoint}/_cat/indices?format=json`,\n {\n headers: {\n \"x-reactify-index\": config.index,\n \"x-reactify-skip-cache\": \"true\",\n },\n }\n ).then((response) => response.json());\n\n const regexp = new RegExp(`${shopName}-[0-9]`);\n\n setIndices(\n response\n .map((item) => item.index)\n .filter((item) => regexp.test(item))\n .sort((a, b) => (a > b ? -1 : 1))\n );\n })();\n }, [config.endpoint]);\n\n return {\n indices: indices,\n indexNameFormat: indexNameFormat,\n };\n};\n"]}
|
|
@@ -16,9 +16,9 @@ export declare const usePagination: (input: ReactivesearchPaginationProps) => {
|
|
|
16
16
|
/** Function to build a URL for a specific page number, useful for Href links */
|
|
17
17
|
buildPagePath: (page: number) => string;
|
|
18
18
|
/** Function to change to the next page, if an event is provided the preventDefault() method will be called */
|
|
19
|
-
handleNextPage: (event?: React.SyntheticEvent
|
|
19
|
+
handleNextPage: (event?: React.SyntheticEvent) => void;
|
|
20
20
|
/** Function to change to the previous page, if an event is provided the preventDefault() method will be called */
|
|
21
|
-
handlePreviousPage: (event?: React.SyntheticEvent
|
|
21
|
+
handlePreviousPage: (event?: React.SyntheticEvent) => void;
|
|
22
22
|
/** Function to change to any page, if an event is provided the preventDefault() method will be called */
|
|
23
|
-
handlePageChange: (pageNumber: number, event?: React.SyntheticEvent
|
|
23
|
+
handlePageChange: (pageNumber: number, event?: React.SyntheticEvent) => void;
|
|
24
24
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePagination.js","sourceRoot":"","sources":["../../../src/hooks/usePagination.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAG1B,oCAAwC;AACxC,wCAAmC;AAE5B,MAAM,aAAa,GAAG,CAC3B,KAAoC,EAsBpC,EAAE;IACF,MAAM,EAAE,KAAK,EAAE,GAAG,IAAA,oBAAY,GAAE,CAAC;IAEjC,MAAM,aAAa,GAAG,eAAK,CAAC,WAAW,CAAC,CAAC,IAAY,EAAE,EAAE;QACvD,MAAM,WAAW,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;QAElF,OAAO,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC;YAClC,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,WAAW,EAAE,QAAQ,IAAI,EAAE,CAAC;YAClD,CAAC,CAAC,GAAG,WAAW,GAAG,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,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,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;IAC3C,IAAI,IAAI,GAAa,EAAE,CAAC;IACxB,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,UAAU,IAAI,CAAC,IAAI,WAAW,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC;QAChD,KAAK,GAAG,CAAC,CAAC;IACZ,CAAC;SAAM,CAAC;QACN,IAAI,UAAU,GAAG,MAAM,IAAI,WAAW,EAAE,CAAC;YACvC,KAAK;gBACH,WAAW,GAAG,CAAC,KAAK,UAAU;oBAC5B,CAAC,CAAC,WAAW,GAAG,CAAC,WAAW,GAAG,CAAC,CAAC;oBACjC,CAAC,CAAC,WAAW,GAAG,CAAC,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC;QAC5C,CAAC;aAAM,CAAC;YACN,KAAK,GAAG,WAAW,GAAG,MAAM,CAAC;QAC/B,CAAC;IACH,CAAC;IACD,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QACxD,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACd,CAAC,CAAC","sourcesContent":["import React from \"react\";\n\nimport { ReactivesearchPaginationProps } from \"../types\";\nimport { useAnalytics } from \"../hooks\";\nimport { debug } from \"../utility\";\n\nexport const usePagination = (\n input: ReactivesearchPaginationProps\n): {\n /** The current page number, indexed from 0 */\n currentPage: number;\n /** The total amount of pages */\n totalPages: number;\n /** The total amount of pages to show within pagination components */\n pagesToShow: Array<number>;\n /** If there is a next page */\n hasNextPage: boolean;\n /** If there is a previous page */\n hasPreviousPage: boolean;\n /** The _actual_ current page number, indexed from 1 */\n actualCurrentPage: number;\n /** Function to build a URL for a specific page number, useful for Href links */\n buildPagePath: (page: number) => string;\n /** Function to change to the next page, if an event is provided the preventDefault() method will be called */\n handleNextPage: (event?: React.SyntheticEvent) => void;\n /** Function to change to the previous page, if an event is provided the preventDefault() method will be called */\n handlePreviousPage: (event?: React.SyntheticEvent) => void;\n /** Function to change to any page, if an event is provided the preventDefault() method will be called */\n handlePageChange: (pageNumber: number, event?: React.SyntheticEvent) => void;\n} => {\n const { track } = useAnalytics();\n\n const buildPagePath = React.useCallback((page: number) => {\n const currentPath = typeof window !== \"undefined\" ? window.location.pathname : \"\";\n\n return currentPath.includes(\"page=\")\n ? currentPath.replace(/page=\\d+/g, `page=${page}`)\n : `${currentPath}${currentPath.includes(\"?\") ? \"&\" : \"?\"}page=${page}`;\n }, []);\n\n const pagesToShow = React.useMemo(\n () => getPages(input.pages, input.totalPages, input.currentPage),\n [input.pages, input.totalPages, input.currentPage]\n );\n\n // default input.currentPage is zero-indexed, actualCurrentPage is one-indexed\n const actualCurrentPage = React.useMemo(\n () => input.currentPage + 1,\n [input.currentPage]\n );\n\n const hasNextPage = React.useMemo(\n () => actualCurrentPage < input.totalPages,\n [actualCurrentPage, input.totalPages]\n );\n\n const hasPreviousPage = React.useMemo(\n () => actualCurrentPage > 1,\n [actualCurrentPage]\n );\n\n const hasPage = React.useCallback(\n (pageNumber: number) => {\n return pageNumber >= 0 && pageNumber < input.totalPages;\n },\n [input.totalPages]\n );\n\n const handlePageChange = React.useCallback<\n ReturnType<typeof usePagination>[\"handlePageChange\"]\n >(\n (pageNumber, event) => {\n debug.log(\"usePagination\", \"handlePageChange[pageNumber]\", pageNumber);\n event?.preventDefault();\n if (!hasPage(pageNumber)) {\n return;\n }\n input.setPage(pageNumber);\n track({\n eventName: \"paginationChange\",\n payload: {\n page: pageNumber,\n source: window.location.pathname.includes(\"/search\")\n ? \"search\"\n : \"collection\",\n },\n });\n },\n [input.setPage, track]\n );\n\n const handleNextPage = React.useCallback<\n ReturnType<typeof usePagination>[\"handleNextPage\"]\n >(\n (event) => {\n debug.log(\"usePagination\", \"handleNextPage\", input.currentPage + 1);\n handlePageChange(input.currentPage + 1, event);\n },\n [hasNextPage, input.currentPage, handlePageChange]\n );\n\n const handlePreviousPage = React.useCallback<\n ReturnType<typeof usePagination>[\"handlePreviousPage\"]\n >(\n (event) => {\n debug.log(\"usePagination\", \"handlePreviousPage\", input.currentPage - 1);\n handlePageChange(input.currentPage - 1, event);\n },\n [hasPreviousPage, input.currentPage, handlePageChange]\n );\n\n return React.useMemo(\n () => ({\n currentPage: input.currentPage,\n totalPages: input.totalPages,\n pagesToShow,\n hasNextPage,\n buildPagePath,\n hasPreviousPage,\n actualCurrentPage,\n handleNextPage,\n handlePreviousPage,\n handlePageChange,\n }),\n [\n input.currentPage,\n input.totalPages,\n pagesToShow,\n hasNextPage,\n buildPagePath,\n hasPreviousPage,\n actualCurrentPage,\n handleNextPage,\n handlePreviousPage,\n handlePageChange,\n ]\n );\n};\n\n// get a list of pages to display buttons for\n// @todo this is super hacky and needs to be cleaned up\nconst getPages = (pages: number, totalPages: number, currentPage: number) => {\n const pagesToShow = pages > totalPages ? totalPages : pages;\n const buffer = Math.floor(pagesToShow / 2);\n let list: number[] = [];\n let start = 0;\n if (totalPages <= 5 || currentPage < buffer + 1) {\n start = 0;\n } else {\n if (totalPages - buffer <= currentPage) {\n start =\n currentPage + 1 === totalPages\n ? currentPage - (pagesToShow - 1)\n : currentPage - (buffer + buffer / 2);\n } else {\n start = currentPage - buffer;\n }\n }\n Array.apply(null, Array(pagesToShow)).map((item, index) => {\n list.push(start + index);\n });\n return list;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePaginationLoadable.js","sourceRoot":"","sources":["../../../src/hooks/usePaginationLoadable.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAG1B,wBAA6C;AAC7C,wCAAmC;AAE5B,MAAM,qBAAqB,GAAG,CACnC,KAAgC,EAchC,EAAE;IACF,MAAM,aAAa,GAAG,IAAA,eAAY,GAAE,C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AAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC;oBAClD,CAAC,CAAC,QAAQ;oBACV,CAAC,CAAC,YAAY;aACjB;SACF,CAAC,CAAC;IACL,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC;IAE1E,OAAO,eAAK,CAAC,OAAO,CAClB,GAAG,EAAE,CAAC,CAAC;QACL,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,OAAO;QACP,cAAc;QACd,WAAW,EAAE,KAAK,CAAC,WAAW;KAC/B,CAAC,EACF,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,KAAK,CAAC,WAAW,CAAC,CAC5D,CAAC;AACJ,CAAC,CAAC;AArDW,QAAA,qBAAqB,yBAqDhC","sourcesContent":["import React from \"react\";\n\nimport { ReactivesearchResultProps } from \"../types\";\nimport { useAnalytics, useFilters } from \".\";\nimport { debug } from \"../utility\";\n\nexport const usePaginationLoadable = (\n input: ReactivesearchResultProps\n): {\n loading: boolean;\n hasMore: boolean;\n handleLoadMore: () => void;\n resultStats: {\n time: number;\n hidden: number;\n promoted: number;\n currentPage: number;\n numberOfPages: number;\n numberOfResults?: number;\n displayedResults: number;\n };\n} => {\n const analyticsHook = useAnalytics();\n const { filterStack } = useFilters();\n\n const hasMore =\n input.resultStats.displayedResults !== input.resultStats.numberOfResults;\n\n const handleLoadMore = React.useCallback(() => {\n debug.log(\"usePaginationLoadable\", \"handleLoadMore\");\n\n if (!hasMore) {\n return;\n }\n\n input.loadMore();\n analyticsHook.track({\n eventName: \"paginationChange\",\n payload: {\n page:\n Math.ceil(\n input.resultStats.displayedResults / (filterStack?.pageSize || 20)\n ) + 1,\n source: window.location.pathname.includes(\"/search\")\n ? \"search\"\n : \"collection\",\n },\n });\n }, [input.loadMore, analyticsHook.track, input.resultStats, filterStack]);\n\n return React.useMemo(\n () => ({\n loading: input.loading,\n hasMore,\n handleLoadMore,\n resultStats: input.resultStats,\n }),\n [input.loading, hasMore, handleLoadMore, input.resultStats]\n );\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useProductPrice.js","sourceRoot":"","sources":["../../../src/hooks/useProductPrice.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,8DAAmC;AAI5B,MAAM,eAAe,GAAG,CAAC,OAAuB,EAOrD,EAAE;IACF,OAAO,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;;QACxB,MAAM,OAAO,GAAG,MAAA,OAAO,CAAC,QAAQ,0CAAG,CAAC,CAAC,CAAC;QAEtC,IAAI,CAAC,OAAO,EAAE;
|
|
1
|
+
{"version":3,"file":"useProductPrice.js","sourceRoot":"","sources":["../../../src/hooks/useProductPrice.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,8DAAmC;AAI5B,MAAM,eAAe,GAAG,CAAC,OAAuB,EAOrD,EAAE;IACF,OAAO,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;;QACxB,MAAM,OAAO,GAAG,MAAA,OAAO,CAAC,QAAQ,0CAAG,CAAC,CAAC,CAAC;QAEtC,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO;gBACL,MAAM,EAAE,KAAK;gBACb,KAAK,EAAE,SAAS;gBAChB,YAAY,EAAE,KAAK;gBACnB,cAAc,EAAE,SAAS;aAC1B,CAAC;QACJ,CAAC;QAED,wCAAwC;QACxC,MAAM,QAAQ,GAAG,MAAA,OAAO,CAAC,kBAAkB,0CAAG,CAAC,CAAC,CAAC;QAEjD,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;YACjC,OAAO;gBACL,MAAM,EAAE,KAAK;gBACb,KAAK,EAAE,SAAS;gBAChB,YAAY,EAAE,KAAK;gBACnB,cAAc,EAAE,SAAS;aAC1B,CAAC;QACJ,CAAC;QAED,MAAM,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CAAC;QAC3B,WAAW,GAAG,MAAM,WAAW,EAAE,CAAC;IACpC,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC","sourcesContent":["import React from \"react\";\nimport currency from \"currency.js\";\n\nimport { ElasticProduct } from \"../types/elastic\";\n\nexport const useProductPrice = (product: ElasticProduct): {\n price?: currency;\n onSale: boolean;\n currencyCode: string;\n compareAtPrice?: currency;\n formattedPrice?: string;\n formattedCompareAtPrice?: string;\n} => {\n return React.useMemo(() => {\n const variant = product.variants?.[0];\n\n if (!variant) {\n return {\n onSale: false,\n price: undefined,\n currencyCode: \"AUD\",\n compareAtPrice: undefined,\n };\n }\n\n // @todo select the appropriate currency\n const priceSet = variant.presentment_prices?.[0];\n\n if (!priceSet || !priceSet.price) {\n return {\n onSale: false,\n price: undefined,\n currencyCode: \"AUD\",\n compareAtPrice: undefined,\n };\n }\n\n const currencyCode = priceSet.price.currency_code ?? \"AUD\";\n\n const price = priceSet.price.amount\n ? currency(priceSet.price.amount)\n : undefined;\n\n const formattedPrice = price ? formatPrice(price, currencyCode) : undefined;\n\n const compareAtPrice = priceSet.compare_at_price?.amount\n ? currency(priceSet.compare_at_price.amount)\n : undefined;\n\n const formattedCompareAtPrice = compareAtPrice\n ? formatPrice(compareAtPrice, currencyCode)\n : undefined;\n\n const onSale =\n !!compareAtPrice && !!price && compareAtPrice.intValue > price.intValue;\n\n return {\n price,\n onSale,\n currencyCode,\n compareAtPrice,\n formattedPrice,\n formattedCompareAtPrice,\n };\n }, [product]);\n};\n\nconst formatPrice = (price: currency, currencyCode: string): string => {\n let priceString = new Intl.NumberFormat(\"en-AU\", {\n style: \"currency\",\n currency: currencyCode,\n }).format(price.value);\n\n if (\"AUD\" === currencyCode) {\n priceString = `AU ${priceString}`;\n }\n\n return priceString;\n};\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { Config, ConfigRedirect, ReactivesearchResultProps } from "../types";
|
|
3
3
|
import { Flags } from "./useFlags";
|
|
4
|
-
export
|
|
4
|
+
export type ReactifySearchMode = "search" | "collection" | "instant-search";
|
|
5
5
|
export declare const ReactifySearchContext: React.Context<{
|
|
6
6
|
config: Config;
|
|
7
7
|
options: {
|
|
@@ -9,20 +9,20 @@ export declare const ReactifySearchContext: React.Context<{
|
|
|
9
9
|
mode: ReactifySearchMode;
|
|
10
10
|
index: string;
|
|
11
11
|
shopifyPermanentDomain: string;
|
|
12
|
-
market?: string
|
|
13
|
-
filtersHandle?: string
|
|
14
|
-
credentials?: string
|
|
15
|
-
onRedirect?: (
|
|
12
|
+
market?: string;
|
|
13
|
+
filtersHandle?: string;
|
|
14
|
+
credentials?: string;
|
|
15
|
+
onRedirect?: (type: "redirect" | "search", url: string) => void;
|
|
16
16
|
theme: Record<string, unknown>;
|
|
17
|
-
additionalComponentIds?: string
|
|
18
|
-
includeFields?: string
|
|
19
|
-
excludeFields?: string
|
|
20
|
-
flags?: Record<Flags, boolean
|
|
21
|
-
query?: Record<string, string
|
|
17
|
+
additionalComponentIds?: Array<string>;
|
|
18
|
+
includeFields?: Array<string>;
|
|
19
|
+
excludeFields?: Array<string>;
|
|
20
|
+
flags?: Record<Flags, boolean>;
|
|
21
|
+
query?: Record<string, string>;
|
|
22
22
|
preload?: {
|
|
23
23
|
config: Config;
|
|
24
24
|
state: unknown;
|
|
25
|
-
}
|
|
25
|
+
};
|
|
26
26
|
} & ({
|
|
27
27
|
mode: "search";
|
|
28
28
|
} | {
|
|
@@ -56,20 +56,20 @@ export declare const useReactifySearchContext: () => {
|
|
|
56
56
|
mode: ReactifySearchMode;
|
|
57
57
|
index: string;
|
|
58
58
|
shopifyPermanentDomain: string;
|
|
59
|
-
market?: string
|
|
60
|
-
filtersHandle?: string
|
|
61
|
-
credentials?: string
|
|
62
|
-
onRedirect?: (
|
|
59
|
+
market?: string;
|
|
60
|
+
filtersHandle?: string;
|
|
61
|
+
credentials?: string;
|
|
62
|
+
onRedirect?: (type: "redirect" | "search", url: string) => void;
|
|
63
63
|
theme: Record<string, unknown>;
|
|
64
|
-
additionalComponentIds?: string
|
|
65
|
-
includeFields?: string
|
|
66
|
-
excludeFields?: string
|
|
67
|
-
flags?: Record<Flags, boolean
|
|
68
|
-
query?: Record<string, string
|
|
64
|
+
additionalComponentIds?: Array<string>;
|
|
65
|
+
includeFields?: Array<string>;
|
|
66
|
+
excludeFields?: Array<string>;
|
|
67
|
+
flags?: Record<Flags, boolean>;
|
|
68
|
+
query?: Record<string, string>;
|
|
69
69
|
preload?: {
|
|
70
70
|
config: Config;
|
|
71
71
|
state: unknown;
|
|
72
|
-
}
|
|
72
|
+
};
|
|
73
73
|
} & ({
|
|
74
74
|
mode: "search";
|
|
75
75
|
} | {
|
|
@@ -8,15 +8,7 @@ export declare const useResults: () => {
|
|
|
8
8
|
/** Function for setting the current results */
|
|
9
9
|
setResults: (value: ReactivesearchResultProps["data"]) => void;
|
|
10
10
|
/** All of the current result stats */
|
|
11
|
-
resultStats?:
|
|
12
|
-
time: number;
|
|
13
|
-
hidden: number;
|
|
14
|
-
promoted: number;
|
|
15
|
-
currentPage: number;
|
|
16
|
-
numberOfPages: number;
|
|
17
|
-
numberOfResults?: number | undefined;
|
|
18
|
-
displayedResults: number;
|
|
19
|
-
} | undefined;
|
|
11
|
+
resultStats?: ReactivesearchResultProps["resultStats"];
|
|
20
12
|
/** Function for setting the current result stats */
|
|
21
13
|
setResultStats: (value: ReactivesearchResultProps["resultStats"]) => void;
|
|
22
14
|
};
|
|
@@ -6,8 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.useResults = void 0;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
8
|
const utility_1 = require("../utility");
|
|
9
|
+
const useReactifySearchContext_1 = require("./useReactifySearchContext");
|
|
9
10
|
/** This hook must never be used to render results */
|
|
10
11
|
const useResults = () => {
|
|
12
|
+
const context = (0, useReactifySearchContext_1.useReactifySearchContext)();
|
|
11
13
|
const [results, setResults] = react_1.default.useState([]);
|
|
12
14
|
const [resultStats, setResultStats] = react_1.default.useState();
|
|
13
15
|
const loading = react_1.default.useMemo(() => {
|
|
@@ -17,24 +19,24 @@ const useResults = () => {
|
|
|
17
19
|
const handler = (event) => {
|
|
18
20
|
setResults(event.detail);
|
|
19
21
|
};
|
|
20
|
-
window.addEventListener(`@usereactify/search:results:update`, handler);
|
|
21
|
-
return () => window.removeEventListener(`@usereactify/search:results:update`, handler);
|
|
22
|
+
window.addEventListener(`@usereactify/search:${context.options.mode}:results:update`, handler);
|
|
23
|
+
return () => window.removeEventListener(`@usereactify/search:${context.options.mode}:results:update`, handler);
|
|
22
24
|
}, []);
|
|
23
25
|
react_1.default.useEffect(() => {
|
|
24
26
|
const handler = (event) => {
|
|
25
27
|
setResultStats(event.detail);
|
|
26
28
|
};
|
|
27
|
-
window.addEventListener(`@usereactify/search:resultStats:update`, handler);
|
|
28
|
-
return () => window.removeEventListener(`@usereactify/search:resultStats:update`, handler);
|
|
29
|
-
}, []);
|
|
29
|
+
window.addEventListener(`@usereactify/search:${context.options.mode}:resultStats:update`, handler);
|
|
30
|
+
return () => window.removeEventListener(`@usereactify/search:${context.options.mode}:resultStats:update`, handler);
|
|
31
|
+
}, [context.options.mode]);
|
|
30
32
|
const handleSetResults = (value) => {
|
|
31
|
-
const event = new CustomEvent(`@usereactify/search:results:update`, {
|
|
33
|
+
const event = new CustomEvent(`@usereactify/search:${context.options.mode}:results:update`, {
|
|
32
34
|
detail: value
|
|
33
35
|
});
|
|
34
36
|
window.dispatchEvent(event);
|
|
35
37
|
};
|
|
36
38
|
const handleSetResultStats = (value) => {
|
|
37
|
-
const event = new CustomEvent(`@usereactify/search:resultStats:update`, {
|
|
39
|
+
const event = new CustomEvent(`@usereactify/search:${context.options.mode}:resultStats:update`, {
|
|
38
40
|
detail: value
|
|
39
41
|
});
|
|
40
42
|
window.dispatchEvent(event);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useResults.js","sourceRoot":"","sources":["../../../src/hooks/useResults.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAG1B,wCAAmC;
|
|
1
|
+
{"version":3,"file":"useResults.js","sourceRoot":"","sources":["../../../src/hooks/useResults.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAG1B,wCAAmC;AACnC,yEAAsE;AAEtE,qDAAqD;AAC9C,MAAM,UAAU,GAAG,GAWxB,EAAE;IACF,MAAM,OAAO,GAAG,IAAA,mDAAwB,GAAE,CAAC;IAC3C,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,eAAK,CAAC,QAAQ,CAE1C,EAAE,CAAC,CAAC;IACN,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GACjC,eAAK,CAAC,QAAQ,EAA4C,CAAC;IAE7D,MAAM,OAAO,GAAG,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QACjC,OAAO,OAAO,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,eAAe,CAAA,KAAK,WAAW,CAAC;IAC7D,CAAC,EAAE,CAAC,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,eAAe,CAAC,CAAC,CAAC;IAEnC,eAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,MAAM,OAAO,GAAG,CACd,KAAkC,EAClC,EAAE;YACF,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC3B,CAAC,CAAC;QACF,MAAM,CAAC,gBAAgB,CACrB,uBAAuB,OAAO,CAAC,OAAO,CAAC,IAAI,iBAAiB,EAC5D,OAAwB,CACzB,CAAC;QAEF,OAAO,GAAG,EAAE,CACV,MAAM,CAAC,mBAAmB,CACxB,uBAAuB,OAAO,CAAC,OAAO,CAAC,IAAI,iBAAiB,EAC5D,OAAwB,CACzB,CAAC;IACN,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,eAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,MAAM,OAAO,GAAG,CACd,K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FrB","sourcesContent":["import React from \"react\";\n\nimport { ReactivesearchResultProps } from \"../types\";\nimport { debug } from \"../utility\";\nimport { useReactifySearchContext } from \"./useReactifySearchContext\";\n\n/** This hook must never be used to render results */\nexport const useResults = (): {\n /** Equals true until first load has completed */\n loading: boolean;\n /** All of the current results */\n results: ReactivesearchResultProps[\"data\"];\n /** Function for setting the current results */\n setResults: (value: ReactivesearchResultProps[\"data\"]) => void;\n /** All of the current result stats */\n resultStats?: ReactivesearchResultProps[\"resultStats\"];\n /** Function for setting the current result stats */\n setResultStats: (value: ReactivesearchResultProps[\"resultStats\"]) => void;\n} => {\n const context = useReactifySearchContext();\n const [results, setResults] = React.useState<\n ReactivesearchResultProps[\"data\"]\n >([]);\n const [resultStats, setResultStats] =\n React.useState<ReactivesearchResultProps[\"resultStats\"]>();\n\n const loading = React.useMemo(() => {\n return typeof resultStats?.numberOfResults === \"undefined\";\n }, [resultStats?.numberOfResults]);\n\n React.useEffect(() => {\n const handler = (\n event: CustomEvent<typeof results>\n ) => {\n setResults(event.detail);\n };\n window.addEventListener(\n `@usereactify/search:${context.options.mode}:results:update`,\n handler as EventListener\n );\n\n return () =>\n window.removeEventListener(\n `@usereactify/search:${context.options.mode}:results:update`,\n handler as EventListener\n );\n }, []);\n\n React.useEffect(() => {\n const handler = (\n event: CustomEvent<typeof resultStats>\n ) => {\n setResultStats(event.detail);\n };\n window.addEventListener(\n `@usereactify/search:${context.options.mode}:resultStats:update`,\n handler as EventListener\n );\n\n return () =>\n window.removeEventListener(\n `@usereactify/search:${context.options.mode}:resultStats:update`,\n handler as EventListener\n );\n }, [context.options.mode]);\n\n const handleSetResults = (value: typeof results) => {\n const event = new CustomEvent<typeof results>(`@usereactify/search:${context.options.mode}:results:update`, {\n detail: value\n });\n window.dispatchEvent(event);\n }\n\n const handleSetResultStats = (value: typeof resultStats) => {\n const event = new CustomEvent<typeof resultStats>(`@usereactify/search:${context.options.mode}:resultStats:update`, {\n detail: value\n });\n window.dispatchEvent(event);\n }\n\n debug.hook(\"useResults\", \"results\", results);\n debug.hook(\"useResults\", \"resultStats\", resultStats);\n\n return {\n loading: loading,\n results: results,\n setResults: handleSetResults,\n resultStats: resultStats,\n setResultStats: handleSetResultStats,\n };\n};\n"]}
|
|
@@ -4,11 +4,18 @@ export declare const useSearch: () => {
|
|
|
4
4
|
/** The current search term */
|
|
5
5
|
searchTerm: string;
|
|
6
6
|
/** Function for changing the current search term */
|
|
7
|
-
setSearchTerm: (searchTerm?: string
|
|
7
|
+
setSearchTerm: (searchTerm?: string) => void;
|
|
8
8
|
/** Function for navigating to the search page, includes logic for redirects */
|
|
9
|
-
submitSearchTerm: (searchTerm?: string
|
|
9
|
+
submitSearchTerm: (searchTerm?: string) => void;
|
|
10
10
|
/** Function for retrieving search results for an opensearch query */
|
|
11
|
-
submitSearchQuery: (searchBody: any, searchHeaders: Record<string, string>) => Promise<
|
|
11
|
+
submitSearchQuery: (searchBody: any, searchHeaders: Record<string, string>) => Promise<{
|
|
12
|
+
results: Array<ElasticProduct>;
|
|
13
|
+
resultStats: {
|
|
14
|
+
time: number;
|
|
15
|
+
numberOfResults: number;
|
|
16
|
+
displayedResults: number;
|
|
17
|
+
};
|
|
18
|
+
}>;
|
|
12
19
|
/** Used to determine if instant search results should be displayed */
|
|
13
20
|
showInstantSearchResults: boolean;
|
|
14
21
|
/** Used to manually set the "showInstantSearchResults" value */
|
|
@@ -19,7 +19,7 @@ const utility_1 = require("../utility");
|
|
|
19
19
|
const useSearch = () => {
|
|
20
20
|
const { options, config, search } = (0, hooks_1.useReactifySearchContext)();
|
|
21
21
|
const handleSubmitSearchQuery = react_1.default.useCallback((searchBody, searchHeaders) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
-
var _a, _b;
|
|
22
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
23
23
|
utility_1.debug.log("useSearch", "submitSearchQuery[body]", searchBody);
|
|
24
24
|
utility_1.debug.log("useSearch", "submitSearchQuery[headers]", searchHeaders);
|
|
25
25
|
const response = yield fetch(`${config.endpoint}/${config.index}/_search`, {
|
|
@@ -34,10 +34,16 @@ const useSearch = () => {
|
|
|
34
34
|
return error;
|
|
35
35
|
});
|
|
36
36
|
utility_1.debug.log("useSearch", "submitSearchQuery[response]", response);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
const value = {
|
|
38
|
+
results: (_c = (_b = (_a = response.hits) === null || _a === void 0 ? void 0 : _a.hits) === null || _b === void 0 ? void 0 : _b.map((item) => item._source)) !== null && _c !== void 0 ? _c : [],
|
|
39
|
+
resultStats: {
|
|
40
|
+
time: (_d = response.took) !== null && _d !== void 0 ? _d : NaN,
|
|
41
|
+
numberOfResults: (_g = (_f = (_e = response.hits) === null || _e === void 0 ? void 0 : _e.total) === null || _f === void 0 ? void 0 : _f.value) !== null && _g !== void 0 ? _g : NaN,
|
|
42
|
+
displayedResults: (_k = (_j = (_h = response.hits) === null || _h === void 0 ? void 0 : _h.hits) === null || _j === void 0 ? void 0 : _j.length) !== null && _k !== void 0 ? _k : NaN,
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
utility_1.debug.log("useSearch", "submitSearchQuery[value]", value);
|
|
46
|
+
return value;
|
|
41
47
|
}), [config.endpoint, config.index]);
|
|
42
48
|
const handleSubmitSearchTerm = react_1.default.useCallback((searchTerm = search.searchTerm) => {
|
|
43
49
|
utility_1.debug.log("useSearch", "submitSearchTerm[query]", searchTerm);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSearch.js","sourceRoot":"","sources":["../../../src/hooks/useSearch.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAA0B;AAE1B,oCAAoD;AACpD,wCAAmC;
|
|
1
|
+
{"version":3,"file":"useSearch.js","sourceRoot":"","sources":["../../../src/hooks/useSearch.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAA0B;AAE1B,oCAAoD;AACpD,wCAAm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gBACd,CAAC,CAAC,aAAa,kBAAkB,CAAC,UAAU,CAAC,EAAE,CAClD,CAAC;QACJ,CAAC;aAAM,IAAI,QAAQ,EAAE,CAAC;YACpB,MAAM,CAAC,QAAQ,CAAC,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC;QACtC,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,QAAQ,CAAC,IAAI,GAAG,aAAa,kBAAkB,CAAC,UAAU,CAAC,EAAE,CAAC;QACvE,CAAC;IACH,CAAC,EACD,CAAC,MAAM,CAAC,UAAU,CAAC,CACpB,CAAC;IAEF,MAAM,mBAAmB,GAAG,eAAK,CAAC,WAAW,CAC3C,CAAC,aAAqB,EAAE,EAAE,EAAE;QAC1B,eAAK,CAAC,GAAG,CAAC,WAAW,EAAE,2BAA2B,EAAE,UAAU,CAAC,CAAC;QAEhE,MAAM,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IACnC,CAAC,EACD,CAAC,MAAM,CAAC,UAAU,CAAC,CACpB,CAAC;IAEF,OAAO;QACL,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,aAAa,EAAE,mBAAmB;QAClC,gBAAgB,EAAE,sBAAsB;QACxC,iBAAiB,EAAE,uBAAuB;QAC1C,wBAAwB,EAAE,CAAC,CAAC,MAAM,CAAC,wBAAwB,IAAI,CAAC,CAAC,MAAM,CAAC,UAAU;QAClF,2BAA2B,EAAE,MAAM,CAAC,2BAA2B;QAC/D,cAAc,EAAE,MAAM,CAAC,cAAc;KACtC,CAAC;AACJ,CAAC,CAAC;AApHW,QAAA,SAAS,aAoHpB","sourcesContent":["import React from \"react\";\n\nimport { useReactifySearchContext } from \"../hooks\";\nimport { debug } from \"../utility\";\nimport { ConfigRedirect, ElasticProduct } from \"../types\";\n\n\nexport const useSearch = (): {\n /** The current search term */\n searchTerm: string;\n /** Function for changing the current search term */\n setSearchTerm: (searchTerm?: string) => void;\n /** Function for navigating to the search page, includes logic for redirects */\n submitSearchTerm: (searchTerm?: string) => void;\n /** Function for retrieving search results for an opensearch query */\n submitSearchQuery: (searchBody: any, searchHeaders: Record<string, string>) => Promise<{\n results: Array<ElasticProduct>;\n resultStats: {\n time: number;\n numberOfResults: number;\n displayedResults: number;\n };\n }>;\n /** Used to determine if instant search results should be displayed */\n showInstantSearchResults: boolean;\n /** Used to manually set the \"showInstantSearchResults\" value */\n setShowInstantSearchResults: React.Dispatch<React.SetStateAction<boolean>>;\n /** Contains any matching redirect for the current search term */\n searchRedirect: ConfigRedirect | undefined;\n} => {\n const { options, config, search } = useReactifySearchContext();\n\n const handleSubmitSearchQuery = React.useCallback<ReturnType<typeof useSearch>[\"submitSearchQuery\"]>(\n async (searchBody, searchHeaders) => {\n debug.log(\"useSearch\", \"submitSearchQuery[body]\", searchBody);\n debug.log(\"useSearch\", \"submitSearchQuery[headers]\", searchHeaders);\n \n const response = await fetch(`${config.endpoint}/${config.index}/_search`, {\n method: \"POST\",\n body: JSON.stringify(searchBody),\n headers: searchHeaders,\n }).then((response) => {\n debug.log(\"useSearch\", \"submitSearchQuery[status]\", response.status);\n \n return response.json();\n }).catch((error) => {\n debug.log(\"useSearch\", \"submitSearchQuery[error]\", error);\n\n return error;\n })\n\n debug.log(\"useSearch\", \"submitSearchQuery[response]\", response);\n\n const value: Awaited<ReturnType<ReturnType<typeof useSearch>[\"submitSearchQuery\"]>> = {\n results: response.hits?.hits?.map((item: { _source: ElasticProduct; }) => item._source) ?? [],\n resultStats: {\n time: response.took ?? NaN,\n numberOfResults: response.hits?.total?.value ?? NaN,\n displayedResults: response.hits?.hits?.length ?? NaN,\n },\n };\n\n debug.log(\"useSearch\", \"submitSearchQuery[value]\", value);\n\n return value;\n },\n [config.endpoint, config.index]\n );\n\n const handleSubmitSearchTerm = React.useCallback(\n (searchTerm: string = search.searchTerm) => {\n debug.log(\"useSearch\", \"submitSearchTerm[query]\", searchTerm);\n\n if (!searchTerm) {\n return;\n }\n\n const redirect = config.redirects.find(\n (redirect) =>\n redirect.query.trim().toLowerCase() ===\n searchTerm.trim().toLowerCase()\n );\n\n if (redirect) {\n debug.log(\"useSearch\", \"submitSearchTerm[redirect]\", redirect);\n }\n\n search.setShowInstantSearchResults(false);\n\n if (options.onRedirect) {\n options.onRedirect(\n redirect ? \"redirect\" : \"search\",\n redirect\n ? redirect.url\n : `/search?q=${encodeURIComponent(searchTerm)}`\n );\n } else if (redirect) {\n window.location.href = redirect.url;\n } else {\n window.location.href = `/search?q=${encodeURIComponent(searchTerm)}`;\n }\n },\n [search.searchTerm]\n );\n\n const handleSetSearchTerm = React.useCallback(\n (searchTerm: string = \"\") => {\n debug.log(\"useSearch\", \"setSearchTerm[searchTerm]\", searchTerm);\n\n search.setSearchTerm(searchTerm);\n },\n [search.searchTerm]\n );\n\n return {\n searchTerm: search.searchTerm,\n setSearchTerm: handleSetSearchTerm,\n submitSearchTerm: handleSubmitSearchTerm,\n submitSearchQuery: handleSubmitSearchQuery,\n showInstantSearchResults: !!search.showInstantSearchResults && !!search.searchTerm,\n setShowInstantSearchResults: search.setShowInstantSearchResults,\n searchRedirect: search.searchRedirect,\n };\n};\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ConfigSort } from "../types";
|
|
2
2
|
export declare const useSortBy: () => {
|
|
3
3
|
/** The currently selected sort option */
|
|
4
|
-
sortOption?: ConfigSort
|
|
4
|
+
sortOption?: ConfigSort;
|
|
5
5
|
/** All of the available sort options */
|
|
6
6
|
sortOptions: Array<ConfigSort>;
|
|
7
7
|
/** Function for changing the current sort option */
|
|
8
|
-
setSortOption: (sortOptionHandle: string, ignoreHistoryState?: boolean
|
|
8
|
+
setSortOption: (sortOptionHandle: string, ignoreHistoryState?: boolean) => void;
|
|
9
9
|
};
|
|
@@ -47,8 +47,6 @@ const useSortBy = () => {
|
|
|
47
47
|
},
|
|
48
48
|
});
|
|
49
49
|
}, [typeof window === "undefined" ? "" : window.location.href]);
|
|
50
|
-
utility_1.debug.hook("useSortBy", "sortOption", sortOption);
|
|
51
|
-
utility_1.debug.hook("useSortBy", "sortOptions", sortOptions);
|
|
52
50
|
return {
|
|
53
51
|
sortOptions,
|
|
54
52
|
sortOption,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSortBy.js","sourceRoot":"","sources":["../../../src/hooks/useSortBy.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAG1B,oCAAkE;AAClE,wCAAmC;AACnC,sDAAsE;AAE/D,MAAM,SAAS,GAAG,GAUvB,EAAE;IACF,MAAM,qBAAqB,GAAG,IAAA,gCAAwB,GAAE,CAAC;IACzD,MAAM,EAAE,KAAK,EAAE,GAAG,IAAA,oBAAY,GAAE,CAAC;IAEjC,MAAM,WAAW,GAAG,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QACrC,OAAO,IAAA,2BAAc,EAAC;YACpB,QAAQ,EAAE,qBAAqB,CAAC,OAAO;YACvC,MAAM,EAAE,qBAAqB,CAAC,MAAM;SACrC,CAAC,CAAC;IACL,CAAC,EAAE,CAAC,qBAAqB,CAAC,OAAO,EAAE,qBAAqB,CAAC,MAAM,CAAC,CAAC,CAAC;IAElE,MAAM,UAAU,GAAG,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QACpC,OAAO,IAAA,0BAAa,EAAC;YACnB,QAAQ,EAAE,qBAAqB,CAAC,OAAO;YACvC,MAAM,EAAE,qBAAqB,CAAC,MAAM;YACpC,UAAU,EAAE,qBAAqB,CAAC,MAAM,CAAC,UAAU;SACpD,CAAC,CAAA;IACJ,CAAC,EAAE,CAAC,qBAAqB,CAAC,OAAO,EAAE,qBAAqB,CAAC,MAAM,EAAE,qBAAqB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;IAE3G,MAAM,aAAa,GAAG,eAAK,CAAC,WAAW,CACrC,CAAC,gBAAwB,EAAE,kBAAkB,GAAG,KAAK,EAAE,EAAE;QACvD,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;
|
|
1
|
+
{"version":3,"file":"use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AE7D,IAAI,CAAC,kBAAkB,EAAE,CAAC;YACxB,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YAC1C,IAAI,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;gBACjC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;YACjD,CAAC;iBAAM,CAAC;gBACN,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;YACpD,CAAC;YACD,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,EAAE,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;QACnD,CAAC;QAED,KAAK,CAAC;YACJ,SAAS,EAAE,YAAY;YACvB,OAAO,EAAE;gBACP,IAAI,EAAE,gBAAgB;aACvB;SACF,CAAC,CAAC;IACL,CAAC,EACD,CAAC,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAC5D,CAAC;IAEF,OAAO;QACL,WAAW;QACX,UAAU;QACV,aAAa;KACd,CAAC;AACJ,CAAC,CAAC;AApEW,QAAA,SAAS,aAoEpB","sourcesContent":["import React from \"react\";\n\nimport { ConfigSort } from \"../types\";\nimport { useAnalytics, useReactifySearchContext } from \"../hooks\";\nimport { debug } from \"../utility\";\nimport { getSortOption, getSortOptions } from \"../utility/sortOption\";\n\nexport const useSortBy = (): {\n /** The currently selected sort option */\n sortOption?: ConfigSort;\n /** All of the available sort options */\n sortOptions: Array<ConfigSort>;\n /** Function for changing the current sort option */\n setSortOption: (\n sortOptionHandle: string,\n ignoreHistoryState?: boolean\n ) => void;\n} => {\n const reactifySearchContext = useReactifySearchContext();\n const { track } = useAnalytics();\n\n const sortOptions = React.useMemo(() => {\n return getSortOptions({\n provider: reactifySearchContext.options,\n config: reactifySearchContext.config,\n });\n }, [reactifySearchContext.options, reactifySearchContext.config]);\n\n const sortOption = React.useMemo(() => {\n return getSortOption({\n provider: reactifySearchContext.options,\n config: reactifySearchContext.config,\n sortOption: reactifySearchContext.sortby.sortOption,\n })\n }, [reactifySearchContext.options, reactifySearchContext.config, reactifySearchContext.sortby.sortOption]);\n\n const setSortOption = React.useCallback(\n (sortOptionHandle: string, ignoreHistoryState = false) => {\n if (typeof window === \"undefined\") {\n return;\n }\n\n debug.log(\n \"useSortBy\",\n \"setSortOption[sortOptionHandle]\",\n sortOptionHandle\n );\n\n reactifySearchContext.sortby.setSortOption(sortOptionHandle);\n\n if (!ignoreHistoryState) {\n const url = new URL(window.location.href);\n if (url.searchParams.has(\"sort\")) {\n url.searchParams.set(\"sort\", sortOptionHandle);\n } else {\n url.searchParams.append(\"sort\", sortOptionHandle);\n }\n window.history.pushState({}, \"\", url.toString());\n }\n\n track({\n eventName: \"sortChange\",\n payload: {\n type: sortOptionHandle,\n },\n });\n },\n [typeof window === \"undefined\" ? \"\" : window.location.href]\n );\n\n return {\n sortOptions,\n sortOption,\n setSortOption,\n };\n};\n"]}
|
package/dist/src/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,uCAAkC;AAClC,mEAAkC;AAElC,eAAK,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,sBAAG,CAAC,IAAI,KAAK,sBAAG,CAAC,OAAO,EAAE,CAAC,CAAC;AAEpD,+CAA6B;AAC7B,0CAAwB;AACxB,0CAAwB;AACxB,mDAAiC;AACjC,mDAAiC;AACjC,mDAAiC;AACjC,kDAAgC","sourcesContent":["import { debug } from \"./utility\";\nimport pkg from \"../package.json\";\n\ndebug.log(\"package\", `${pkg.name} v${pkg.version}`);\n\nexport * from \"./components\";\nexport * from \"./hooks\";\nexport * from \"./types\";\nexport * from \"./utility/liquid\";\nexport * from \"./utility/server\";\nexport * from \"./utility/config\";\nexport * from \"./utility/props\";"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Sort, FilterGroup, FilterFacet, Redirect, Relevance, Curation, Market, Antonym, Synonym, Callout, MerchandisingCalloutAutofillBehaviour } from "./firestore";
|
|
2
|
-
export
|
|
2
|
+
export type Config = {
|
|
3
3
|
index: string;
|
|
4
4
|
endpoint: string;
|
|
5
5
|
cluster: string;
|
|
@@ -29,17 +29,17 @@ export declare type Config = {
|
|
|
29
29
|
collection: Array<unknown>;
|
|
30
30
|
};
|
|
31
31
|
};
|
|
32
|
-
export
|
|
33
|
-
export
|
|
34
|
-
export
|
|
35
|
-
export
|
|
36
|
-
export
|
|
37
|
-
export
|
|
38
|
-
export
|
|
32
|
+
export type ConfigAntonym = Omit<Antonym, "enabled">;
|
|
33
|
+
export type ConfigSynonym = Omit<Synonym, "enabled">;
|
|
34
|
+
export type ConfigCallout = Omit<Callout, "enabled">;
|
|
35
|
+
export type ConfigSort = Omit<Sort, "enabled">;
|
|
36
|
+
export type ConfigField = Omit<Relevance, "enabled">;
|
|
37
|
+
export type ConfigRedirect = Omit<Redirect, "enabled" | "keywords">;
|
|
38
|
+
export type ConfigFilter = Omit<FilterGroup, "enabled" | "keywords"> & {
|
|
39
39
|
options: Omit<FilterFacet, "enabled">[];
|
|
40
40
|
};
|
|
41
|
-
export
|
|
42
|
-
export
|
|
41
|
+
export type ConfigFilterFacet = Omit<FilterFacet, "enabled">;
|
|
42
|
+
export type ConfigCuration = Omit<Curation, "keywords" | "boosting" | "longRunningTask" | "callouts"> & {
|
|
43
43
|
boosting: {
|
|
44
44
|
groupings: Array<(NonNullable<NonNullable<Curation["boosting"]>["groupings"]>[0] & {
|
|
45
45
|
query: string;
|
|
@@ -4,7 +4,7 @@ export declare enum ElasticDocumentType {
|
|
|
4
4
|
Callout = "callout",
|
|
5
5
|
Product = "product"
|
|
6
6
|
}
|
|
7
|
-
export
|
|
7
|
+
export type ElasticDocument = ElasticCallout | ElasticProduct;
|
|
8
8
|
export interface ElasticCallout {
|
|
9
9
|
type: ElasticDocumentType.Callout;
|
|
10
10
|
key: string;
|
|
@@ -180,7 +180,7 @@ export interface ElasticCuration {
|
|
|
180
180
|
searchTerm?: string;
|
|
181
181
|
collectionHandle?: string;
|
|
182
182
|
}
|
|
183
|
-
export
|
|
183
|
+
export type ElasticBulkOperationUpdate = [
|
|
184
184
|
{
|
|
185
185
|
update: {
|
|
186
186
|
_index: string;
|
|
@@ -199,7 +199,7 @@ export declare type ElasticBulkOperationUpdate = [
|
|
|
199
199
|
doc_as_upsert?: true;
|
|
200
200
|
}
|
|
201
201
|
];
|
|
202
|
-
export
|
|
202
|
+
export type ElasticBulkOperationIndex = [
|
|
203
203
|
{
|
|
204
204
|
index: {
|
|
205
205
|
_index: string;
|
|
@@ -208,13 +208,13 @@ export declare type ElasticBulkOperationIndex = [
|
|
|
208
208
|
},
|
|
209
209
|
ElasticDocument
|
|
210
210
|
];
|
|
211
|
-
export
|
|
212
|
-
export
|
|
211
|
+
export type ElasticBulkOperation = ElasticBulkOperationUpdate | ElasticBulkOperationIndex;
|
|
212
|
+
export type ElasticSearchResult<T = ElasticDocument> = {
|
|
213
213
|
hits: {
|
|
214
214
|
hits: Array<ElasticHit<T>>;
|
|
215
215
|
};
|
|
216
216
|
};
|
|
217
|
-
export
|
|
217
|
+
export type ElasticHit<T = ElasticDocument> = {
|
|
218
218
|
_id: string;
|
|
219
219
|
_source: T;
|
|
220
220
|
_score: number | null;
|
|
@@ -5,7 +5,7 @@ var ElasticDocumentType;
|
|
|
5
5
|
(function (ElasticDocumentType) {
|
|
6
6
|
ElasticDocumentType["Callout"] = "callout";
|
|
7
7
|
ElasticDocumentType["Product"] = "product";
|
|
8
|
-
})(ElasticDocumentType
|
|
8
|
+
})(ElasticDocumentType || (exports.ElasticDocumentType = ElasticDocumentType = {}));
|
|
9
9
|
var ElasticDataType;
|
|
10
10
|
(function (ElasticDataType) {
|
|
11
11
|
ElasticDataType["Text"] = "text";
|
|
@@ -15,5 +15,5 @@ var ElasticDataType;
|
|
|
15
15
|
ElasticDataType["Nested"] = "nested";
|
|
16
16
|
ElasticDataType["Keyword"] = "keyword";
|
|
17
17
|
ElasticDataType["Boolean"] = "boolean";
|
|
18
|
-
})(ElasticDataType
|
|
18
|
+
})(ElasticDataType || (exports.ElasticDataType = ElasticDataType = {}));
|
|
19
19
|
//# sourceMappingURL=elastic.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"elastic.js","sourceRoot":"","sources":["../../../src/types/elastic.ts"],"names":[],"mappings":";;;AAOA,IAAY,mBAGX;AAHD,WAAY,mBAAmB;IAC7B,0CAAmB,CAAA;IACnB,0CAAmB,CAAA;AACrB,CAAC,EAHW,mBAAmB,
|
|
1
|
+
{"version":3,"file":"elastic.js","sourceRoot":"","sources":["../../../src/types/elastic.ts"],"names":[],"mappings":";;;AAOA,IAAY,mBAGX;AAHD,WAAY,mBAAmB;IAC7B,0CAAmB,CAAA;IACnB,0CAAmB,CAAA;AACrB,CAAC,EAHW,mBAAmB,mCAAnB,mBAAmB,QAG9B;AAkOD,IAAY,eAQX;AARD,WAAY,eAAe;IACzB,gCAAa,CAAA;IACb,gCAAa,CAAA;IACb,gCAAa,CAAA;IACb,kCAAe,CAAA;IACf,oCAAiB,CAAA;IACjB,sCAAmB,CAAA;IACnB,sCAAmB,CAAA;AACrB,CAAC,EARW,eAAe,+BAAf,eAAe,QAQ1B","sourcesContent":["import { Callout } from \"./firestore\";\nimport {\n Maybe,\n ProductVariantInventoryPolicy,\n MetafieldValueType,\n} from \"./graphql\";\n\nexport enum ElasticDocumentType {\n Callout = \"callout\",\n Product = \"product\",\n}\n\nexport type ElasticDocument = ElasticCallout | ElasticProduct;\n\nexport interface ElasticCallout {\n type: ElasticDocumentType.Callout;\n key: string;\n callout: Omit<Callout, \"keywords\">;\n /** elastic callouts are always published */\n published: true;\n /** elastic callouts are always attached to one curation */\n curations: [ElasticCuration] | [];\n}\n\nexport interface ElasticProduct {\n type: ElasticDocumentType.Product;\n /** the log id from which this product was last uploaded */\n lastLogId: string;\n /** legacy resource id */\n id: number;\n storefrontId: string;\n title: string;\n description: string;\n vendor: string;\n product_type: string;\n handle: string;\n url: string;\n tags: Array<string>;\n collection_titles: Array<string>;\n /** tag prefixes defined in tagKeys are split to their own attributes */\n [key: `tags_${string}`]: Array<string> | undefined;\n /** decimal number e.g. 99.95 */\n price_min: number;\n /** decimal number e.g. 99.95 */\n price_max: number;\n /** array of option names e.g. [\"Colour\", \"Size\"] */\n options: Array<string>;\n /** @todo it would be better to use ProductStatus directly, which has uppercase */\n status: \"active\" | \"archived\" | \"draft\";\n published: boolean;\n /** ISO 8601 datetime */\n published_at: Maybe<string>;\n /** ISO 8601 datetime */\n updated_at: string;\n /** ISO 8601 datetime */\n created_at: string;\n tracks_inventory: boolean;\n /** originalSrc URL for featured image */\n image: Maybe<string>;\n /** array of images (undefined if images are disabled in sync settings) */\n images?: Array<ElasticImage>;\n /** array of variants attached to product (undefined if variants are disabled in sync settings) */\n variants?: Array<ElasticVariant>;\n /** price ranges from presentment prices (undefined if presentment prices or variants are disabled in sync settings) */\n presentment_price_ranges?: {\n min_variant_price: Array<ElasticPresentmentPrice>;\n max_variant_price: Array<ElasticPresentmentPrice>;\n };\n /** array of variant skus (undefined if variants are disabled in sync settings) */\n variant_skus?: Array<string>;\n /** combined array of option values from all option types (undefined if variants are disabled in sync settings) */\n variant_options?: Array<string>;\n /** array of collections which this product belongs to (undefined if collections are disabled in sync settings) */\n collections?: Array<ElasticCollection>;\n /** array of whitelisted metafields (undefined if metafields are disabled in sync settings) */\n metafields?: Array<ElasticMetafield>;\n /** decimal number e.g. 99.95 (undefined if variants are disabled in sync settings) */\n discount_amount?: number;\n /** combined inventory for all variants (undefined if variants are disabled in sync settings) */\n inventory_total?: number;\n /** number of days since published, null if unpublished */\n published_days: Maybe<number>;\n /** collection of curations that this product is attached to */\n curations?: Array<ElasticCuration>;\n /** related products **/\n related?: Array<ElasticProductRelated>;\n}\n\nexport interface ElasticProductRelated {\n createdAt: string;\n description: string;\n featuredImage: {\n originalSrc: \"https://cdn.shopify.com/s/files/1/0614/3977/0777/p…71d6-e7fd-4f5f-aa99-c722e2832d01.jpg?v=1660776345\";\n };\n handle: string;\n id: string;\n images: Array<ElasticImage>;\n legacyResourceId: string;\n metafields?: Array<ElasticMetafield>;\n options: Array<{\n name: string;\n }>;\n priceRangeV2: {\n maxVariantPrice: {\n amount: string;\n };\n minVariantPrice: {\n amount: string;\n };\n };\n productType: string;\n publishedAt: string;\n status: \"ACTIVE\" | \"ARCHIVED\" | \"DRAFT\";\n storefrontId: string;\n tags: Array<string>;\n title: string;\n tracksInventory: boolean;\n updatedAt: string;\n variants: Array<ElasticVariant>;\n vendor: string;\n __typename: \"Product\";\n}\n\nexport interface ElasticVariant {\n /** legacy resource id */\n id: number;\n storefrontId: string;\n title: string;\n sku: Maybe<string>;\n barcode: Maybe<string>;\n /** array of presentment prices (undefined if presentment prices are disabled in sync settings) */\n presentment_prices?: Array<{\n price: ElasticPresentmentPrice;\n compare_at_price: Maybe<ElasticPresentmentPrice>;\n }>;\n /** decimal number e.g. 99.95 */\n price: number;\n /** decimal number e.g. 99.95 */\n compare_at_price: Maybe<number>;\n /** value string for option 1 e.g. Blue */\n option1: Maybe<string>;\n /** value string for option 2 e.g. Medium */\n option2: Maybe<string>;\n /** value string for option 3 */\n option3: Maybe<string>;\n /** sort position within the product */\n position: number;\n inventory_policy: ProductVariantInventoryPolicy;\n inventory_quantity: number;\n available: boolean;\n /** array of images (only available if this variant has been merged from another product and if images are enabled in sync settings) */\n images?: Array<ElasticImage>;\n}\n\nexport interface ElasticCollection {\n /** legacy resource id */\n id: number;\n storefrontId: string;\n handle: string;\n title: string;\n position: number;\n}\n\nexport interface ElasticMetafield {\n key: string;\n type: string;\n value: string;\n namespace: string;\n /**\n * Legacy valueType attribute which is no longer provided by Shopify. We still\n * populate this field to prevent any frontends breaking which rely on it.\n *\n * @see https://shopify.dev/apps/metafields/definitions/types\n */\n value_type: MetafieldValueType;\n}\n\nexport interface ElasticPresentmentPrice {\n /** decimal number e.g. 99.95 */\n amount: number;\n currency_code: string;\n}\n\nexport interface ElasticImage {\n /** originalSrc URL */\n src: string;\n /** alt text */\n alt: Maybe<string>;\n}\n\nexport interface ElasticCuration {\n id: string;\n hidden: boolean;\n position?: number;\n searchTerm?: string;\n collectionHandle?: string;\n}\n\n// non-exhaustive type for bulk request\n// https://www.elastic.co/guide/en/elasticsearch/reference/7.x/docs-bulk.html\nexport type ElasticBulkOperationUpdate = [\n { update: { _index: string; _id: string } },\n {\n script?: {\n lang: \"painless\";\n source: string;\n params?: Record<string, any>;\n };\n upsert?: Partial<ElasticProduct>;\n scripted_upsert?: true;\n doc?: Partial<ElasticProduct>;\n doc_as_upsert?: true;\n }\n];\n\nexport type ElasticBulkOperationIndex = [\n { index: { _index: string; _id: string } },\n ElasticDocument\n];\n\nexport type ElasticBulkOperation =\n | ElasticBulkOperationUpdate\n | ElasticBulkOperationIndex;\n\nexport type ElasticSearchResult<T = ElasticDocument> = {\n hits: {\n hits: Array<ElasticHit<T>>;\n };\n};\n\nexport type ElasticHit<T = ElasticDocument> = {\n _id: string;\n _source: T;\n _score: number | null;\n};\n\nexport enum ElasticDataType {\n Text = \"text\",\n Long = \"long\",\n Date = \"date\",\n Float = \"float\",\n Nested = \"nested\",\n Keyword = \"keyword\",\n Boolean = \"boolean\",\n}\n\nexport interface ElasticProperty {\n analyzer?: string;\n type: ElasticDataType;\n ignore_above?: number;\n fields?: { [key: string]: ElasticField };\n properties?: { [key: string]: ElasticProperty };\n}\n\nexport interface ElasticField {\n type: ElasticDataType;\n ignore_above?: number;\n}\n"]}
|