@usereactify/search 5.36.1 → 5.38.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 CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [5.38.0](https://bitbucket.org/usereactify/reactify-search-ui/compare/release-v5.37.0...release-v5.38.0) (2023-10-27)
6
+
7
+
8
+ ### Features
9
+
10
+ * add retry when loading config from network ([ef84d6a](https://bitbucket.org/usereactify/reactify-search-ui/commit/ef84d6a258b94bdd460b49c2599c3bb51d0e9683))
11
+
12
+ ## [5.37.0](https://bitbucket.org/usereactify/reactify-search-ui/compare/release-v5.36.1...release-v5.37.0) (2023-10-26)
13
+
14
+
15
+ ### Features
16
+
17
+ * remove empty query string from reactivesearch url ([3a64287](https://bitbucket.org/usereactify/reactify-search-ui/commit/3a64287a40972b7ddd8bca55bb063dc48d4b1170))
18
+
5
19
  ### [5.36.1](https://bitbucket.org/usereactify/reactify-search-ui/compare/release-v5.36.0...release-v5.36.1) (2023-10-17)
6
20
 
7
21
 
package/dist/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@usereactify/search",
3
3
  "description": "React UI library for Reactify Search",
4
- "version": "5.36.1",
4
+ "version": "5.38.0",
5
5
  "license": "MIT",
6
6
  "main": "dist/src/index.js",
7
7
  "types": "dist/src/index.d.ts",
@@ -37,6 +37,12 @@ const useReactiveBaseProps = () => {
37
37
  url: options.endpoint,
38
38
  credentials: options.credentials,
39
39
  theme: options.theme,
40
+ transformRequest: (request) => {
41
+ if (request.url.endsWith("?")) {
42
+ request.url = request.url.substring(0, request.url.length - 1);
43
+ }
44
+ return request;
45
+ },
40
46
  transformResponse: (response) => __awaiter(void 0, void 0, void 0, function* () {
41
47
  var _a, _b, _c, _d;
42
48
  // support filtering inside nested aggregations by moving the inner aggregation
@@ -1 +1 @@
1
- {"version":3,"file":"useReactiveBaseProps.js","sourceRoot":"","sources":["../../../../src/hooks/reactivesearch/useReactiveBaseProps.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAA0B;AAG1B,uCAAkE;AAElE,yEAAwC;AAExC,MAAM,yBAAyB,GAAG,CAAC,QAAa,EAAE,EAAE;IAClD,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC;SACrB,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,WAAW,CAAC;SACtC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAgB,EAAE,EAAE;;QACvC,MAAA,KAAK,CAAC,OAAO,0CAAE,OAAO,CAAC,CAAC,MAAW,EAAE,EAAE;YACrC,IAAI,MAAM,CAAC,WAAW,EAAE;gBACtB,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC;gBAChD,OAAO,MAAM,CAAC,WAAW,CAAC;aAC3B;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEL,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAEK,MAAM,oBAAoB,GAAG,GAAsB,EAAE;IAC1D,MAAM,EAAE,OAAO,EAAE,GAAG,IAAA,gCAAwB,GAAE,CAAC;IAE/C,MAAM,iBAAiB,GAAG,eAAK,CAAC,OAAO,CACrC,GAAG,EAAE,CAAC,CAAC;QACL,GAAG,EAAE,OAAO,CAAC,KAAK;QAClB,GAAG,EAAE,OAAO,CAAC,QAAQ;QACrB,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,iBAAiB,EAAE,CAAO,QAAa,EAAE,EAAE;;YACzC,+EAA+E;YAC/E,uDAAuD;YACvD,EAAE;YACF,qFAAqF;YACrF,qFAAqF;YACrF,kEAAkE;YAClE,EAAE;YACF,0DAA0D;YAC1D,IACE,MAAA,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,YAAY,0CAAE,qBAAqB,0CAAE,qBAAqB,EACpE;gBACA,QAAQ,CAAC,YAAY,CAAC,qBAAqB;oBACzC,yBAAyB,CACvB,MAAA,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,YAAY,0CAAE,qBAAqB,0CACzC,qBAAqB,CAC1B,CAAC;aACL;YAED,OAAO,QAAQ,CAAC;QAClB,CAAC,CAAA;QACD,OAAO,EAAE;YACP,iBAAiB,EAAE,OAAO,CAAC,sBAAsB;YACjD,iBAAiB,EAAE,OAAO,CAAC,IAAI;YAC/B,sBAAsB,EAAE,OAAO,CAAC,QAAQ;YACxC,2BAA2B,EAAE,sBAAG,CAAC,OAAO;YACxC,eAAe,EAAE,IAAA,iBAAS,EAAC,QAAQ,CAAC;SACrC;KACF,CAAC,EACF,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,KAAK,CAAC,CACtE,CAAC;IAEF,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC;AA1CW,QAAA,oBAAoB,wBA0C/B","sourcesContent":["import React from \"react\";\nimport { ReactiveBaseProps } from \"@appbaseio/reactivesearch/lib/components/basic/ReactiveBase\";\n\nimport { getCookie, useReactifySearchContext } from \"../../hooks\";\n\nimport pkg from \"../../../package.json\";\n\nconst replaceDocCountWithParent = (response: any) => {\n Object.entries(response)\n .filter(([key]) => key !== \"doc_count\")\n .forEach(([key, value]: [string, any]) => {\n value.buckets?.forEach((bucket: any) => {\n if (bucket.parent_docs) {\n bucket.doc_count = bucket.parent_docs.doc_count;\n delete bucket.parent_docs;\n }\n });\n });\n\n return response;\n};\n\nexport const useReactiveBaseProps = (): ReactiveBaseProps => {\n const { options } = useReactifySearchContext();\n\n const reactiveBaseProps = React.useMemo<ReactiveBaseProps>(\n () => ({\n app: options.index,\n url: options.endpoint,\n credentials: options.credentials,\n theme: options.theme,\n transformResponse: async (response: any) => {\n // support filtering inside nested aggregations by moving the inner aggregation\n // up one level such that reactivesearch understands it\n //\n // see useReactiveFilterListProps > defaultQuery to see how a filter is being applied\n // to variant aggregations to ensure that only in stock sizes are displayed as filter\n // options, this involves a nested filter, which requires this fix\n //\n // https://github.com/appbaseio/reactivesearch/issues/1530\n if (\n response?.aggregations?.reactivesearch_nested?.reactify_nested_outer\n ) {\n response.aggregations.reactivesearch_nested =\n replaceDocCountWithParent(\n response?.aggregations?.reactivesearch_nested\n ?.reactify_nested_outer\n );\n }\n\n return response;\n },\n headers: {\n \"x-reactify-shop\": options.shopifyPermanentDomain,\n \"x-reactify-mode\": options.mode,\n \"x-reactify-client-id\": options.clientId,\n \"x-reactify-client-version\": pkg.version,\n \"x-reactify-ga\": getCookie(\"_rs_ga\"),\n },\n }),\n [options.index, options.endpoint, options.credentials, options.theme]\n );\n\n return reactiveBaseProps;\n};\n"]}
1
+ {"version":3,"file":"useReactiveBaseProps.js","sourceRoot":"","sources":["../../../../src/hooks/reactivesearch/useReactiveBaseProps.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAA0B;AAG1B,uCAAkE;AAElE,yEAAwC;AAExC,MAAM,yBAAyB,GAAG,CAAC,QAAa,EAAE,EAAE;IAClD,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC;SACrB,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,WAAW,CAAC;SACtC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAgB,EAAE,EAAE;;QACvC,MAAA,KAAK,CAAC,OAAO,0CAAE,OAAO,CAAC,CAAC,MAAW,EAAE,EAAE;YACrC,IAAI,MAAM,CAAC,WAAW,EAAE;gBACtB,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC;gBAChD,OAAO,MAAM,CAAC,WAAW,CAAC;aAC3B;QACH,CAAC,C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EAAE,OAAO,CAAC,IAAI;YAC/B,sBAAsB,EAAE,OAAO,CAAC,QAAQ;YACxC,2BAA2B,EAAE,sBAAG,CAAC,OAAO;YACxC,eAAe,EAAE,IAAA,iBAAS,EAAC,QAAQ,CAAC;SACrC;KACF,CAAC,EACF,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,KAAK,CAAC,CACtE,CAAC;IAEF,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC;AAhDW,QAAA,oBAAoB,wBAgD/B","sourcesContent":["import React from \"react\";\nimport { ReactiveBaseProps } from \"@appbaseio/reactivesearch/lib/components/basic/ReactiveBase\";\n\nimport { getCookie, useReactifySearchContext } from \"../../hooks\";\n\nimport pkg from \"../../../package.json\";\n\nconst replaceDocCountWithParent = (response: any) => {\n Object.entries(response)\n .filter(([key]) => key !== \"doc_count\")\n .forEach(([key, value]: [string, any]) => {\n value.buckets?.forEach((bucket: any) => {\n if (bucket.parent_docs) {\n bucket.doc_count = bucket.parent_docs.doc_count;\n delete bucket.parent_docs;\n }\n });\n });\n\n return response;\n};\n\nexport const useReactiveBaseProps = (): ReactiveBaseProps => {\n const { options } = useReactifySearchContext();\n\n const reactiveBaseProps = React.useMemo<ReactiveBaseProps>(\n () => ({\n app: options.index,\n url: options.endpoint,\n credentials: options.credentials,\n theme: options.theme,\n transformRequest: (request: any) => {\n if ((request.url as string).endsWith(\"?\")) {\n request.url = request.url.substring(0, request.url.length - 1);\n }\n return request;\n },\n transformResponse: async (response: any) => {\n // support filtering inside nested aggregations by moving the inner aggregation\n // up one level such that reactivesearch understands it\n //\n // see useReactiveFilterListProps > defaultQuery to see how a filter is being applied\n // to variant aggregations to ensure that only in stock sizes are displayed as filter\n // options, this involves a nested filter, which requires this fix\n //\n // https://github.com/appbaseio/reactivesearch/issues/1530\n if (\n response?.aggregations?.reactivesearch_nested?.reactify_nested_outer\n ) {\n response.aggregations.reactivesearch_nested =\n replaceDocCountWithParent(\n response?.aggregations?.reactivesearch_nested\n ?.reactify_nested_outer\n );\n }\n\n return response;\n },\n headers: {\n \"x-reactify-shop\": options.shopifyPermanentDomain,\n \"x-reactify-mode\": options.mode,\n \"x-reactify-client-id\": options.clientId,\n \"x-reactify-client-version\": pkg.version,\n \"x-reactify-ga\": getCookie(\"_rs_ga\"),\n },\n }),\n [options.index, options.endpoint, options.credentials, options.theme]\n );\n\n return reactiveBaseProps;\n};\n"]}
@@ -46,7 +46,14 @@ const useConfig = (shopifyPermanentDomain, configId) => {
46
46
  if (configId) {
47
47
  searchParams.set("id", configId);
48
48
  }
49
- const json = yield fetch(`https://config.search.reactify.app/?${searchParams.toString()}`).then((response) => response.json());
49
+ let json;
50
+ try {
51
+ json = yield fetch(`https://config.search.reactify.app/?${searchParams.toString()}`).then((response) => response.json());
52
+ }
53
+ catch (error) {
54
+ utility_1.debug.log("useConfig", "error loading config, retrying...");
55
+ json = yield fetch(`https://config.search.reactify.app/?${searchParams.toString()}`).then((response) => response.json());
56
+ }
50
57
  setConfig(json.body);
51
58
  utility_1.debug.log("useConfig", "loaded fresh config");
52
59
  window.sessionStorage.setItem("reactify-search:config", JSON.stringify({
@@ -1 +1 @@
1
- {"version":3,"file":"useConfig.js","sourceRoot":"","sources":["../../../src/hooks/useConfig.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAA0B;AAG1B,wCAAmC;AAE5B,MAAM,SAAS,GAAG,CACvB,sBAA8B,EAC9B,QAAiB,EAGjB,EAAE;IACF,2EAA2E;IAC3E,MAAM,YAAY,GAAG,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;;QACtC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;YACjC,OAAO;SACR;QACD,eAAK,CAAC,GAAG,CAAC,WAAW,EAAE,uBAAuB,CAAC,CAAC;QAEhD,MAAM,aAAa,GAER,IAAI,CAAC,KAAK,CACnB,MAAA,MAAM,CAAC,cAAc,CAAC,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wB,EACxB,IAAI,CAAC,SAAS,CAAC;gBACb,MAAM,EAAE,IAAI,CAAC,IAAI;aAClB,CAAC,CACH,CAAC;QACJ,CAAC,CAAA,CAAC,EAAE,CAAC;IACP,CAAC,EAAE,CAAC,sBAAsB,EAAE,QAAQ,CAAC,CAAC,CAAC;IAEvC,eAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,eAAK,CAAC,GAAG,CAAC,WAAW,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC3C,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAEb,OAAO;QACL,MAAM;KACP,CAAC;AACJ,CAAC,CAAC;AAvEW,QAAA,SAAS,aAuEpB","sourcesContent":["import React from \"react\";\n\nimport { Config } from \"../types/config\";\nimport { debug } from \"../utility\";\n\nexport const useConfig = (\n shopifyPermanentDomain: string,\n configId?: string\n): {\n config: Config | undefined;\n} => {\n // synchronously returns cached and non-expired config from session storage\n const cachedConfig = React.useMemo(() => {\n if (typeof window === \"undefined\") {\n return;\n }\n debug.log(\"useConfig\", \"checking config cache\");\n\n const sessionConfig: {\n config: Config;\n } | null = JSON.parse(\n window.sessionStorage.getItem(\"reactify-search:config\") ?? \"null\"\n );\n\n if (sessionConfig) {\n if (sessionConfig.config.cache?.enabled === false) {\n debug.log(\"useConfig\", `cache disabled, ignoring cached config`);\n return;\n }\n\n debug.log(\"useConfig\", `cache enabled, using cached config`);\n\n return sessionConfig.config;\n } else {\n debug.log(\"useConfig\", `cached config missing`);\n }\n\n return;\n }, []);\n\n const [config, setConfig] = React.useState<Config | undefined>(cachedConfig);\n\n React.useEffect(() => {\n (async () => {\n debug.log(\"useConfig\", \"loading fresh config\");\n const searchParams = new URLSearchParams();\n searchParams.set(\"shop\", shopifyPermanentDomain);\n\n if (configId) {\n searchParams.set(\"id\", configId);\n }\n\n const json = await fetch(\n `https://config.search.reactify.app/?${searchParams.toString()}`\n ).then((response) => response.json());\n\n setConfig(json.body);\n\n debug.log(\"useConfig\", \"loaded fresh config\");\n\n window.sessionStorage.setItem(\n \"reactify-search:config\",\n JSON.stringify({\n config: json.body,\n })\n );\n })();\n }, [shopifyPermanentDomain, configId]);\n\n React.useEffect(() => {\n debug.log(\"useConfig\", \"config\", config);\n }, [config]);\n\n return {\n config,\n };\n};\n"]}
1
+ {"version":3,"file":"useConfig.js","sourceRoot":"","sources":["../../../src/hooks/useConfig.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAA0B;AAG1B,wCAAmC;AAE5B,MAAM,SAAS,GAAG,CACvB,sBAA8B,EAC9B,QAAiB,EAGjB,EAAE;IACF,2EAA2E;IAC3E,MAAM,YAAY,GAAG,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;;QACtC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;YACjC,OAAO;SACR;QACD,eAAK,CAAC,GAAG,CAAC,WAAW,EAAE,uBAAuB,CAAC,CAAC;QAEhD,MAAM,aAAa,GAER,IAAI,CAAC,KAAK,CACnB,MAAA,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,wBAAwB,CAAC,mCAAI,MAAM,CAClE,CAAC;QAEF,IAAI,aAAa,EAAE;YACjB,IAAI,CAAA,MAAA,aAAa,CAAC,MAAM,CAAC,KAAK,0CAAE,OAAO,MAAK,KAAK,EAAE;gBACjD,eAAK,CAAC,GAAG,CAAC,WAAW,EAAE,wCAAwC,CAAC,CAAC;gBACjE,OAAO;aACR;YAED,eAAK,CAAC,GAAG,CAAC,WAAW,EAAE,oCAAoC,CAAC,CAAC;YAE7D,OAAO,aAAa,CAAC,MAAM,CAAC;SAC7B;aAAM;YACL,eAAK,CAAC,GAAG,CAAC,WAAW,EAAE,uBAAuB,CAAC,CAAC;SACjD;QAED,OAAO;IACT,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,eAAK,CAAC,QAAQ,CAAqB,YAAY,CAAC,CAAC;IAE7E,eAAK,C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QAAQ,EAAE,MAAM,CAAC,CAAC;IAC3C,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAEb,OAAO;QACL,MAAM;KACP,CAAC;AACJ,CAAC,CAAC;AAlFW,QAAA,SAAS,aAkFpB","sourcesContent":["import React from \"react\";\n\nimport { Config } from \"../types/config\";\nimport { debug } from \"../utility\";\n\nexport const useConfig = (\n shopifyPermanentDomain: string,\n configId?: string\n): {\n config: Config | undefined;\n} => {\n // synchronously returns cached and non-expired config from session storage\n const cachedConfig = React.useMemo(() => {\n if (typeof window === \"undefined\") {\n return;\n }\n debug.log(\"useConfig\", \"checking config cache\");\n\n const sessionConfig: {\n config: Config;\n } | null = JSON.parse(\n window.sessionStorage.getItem(\"reactify-search:config\") ?? \"null\"\n );\n\n if (sessionConfig) {\n if (sessionConfig.config.cache?.enabled === false) {\n debug.log(\"useConfig\", `cache disabled, ignoring cached config`);\n return;\n }\n\n debug.log(\"useConfig\", `cache enabled, using cached config`);\n\n return sessionConfig.config;\n } else {\n debug.log(\"useConfig\", `cached config missing`);\n }\n\n return;\n }, []);\n\n const [config, setConfig] = React.useState<Config | undefined>(cachedConfig);\n\n React.useEffect(() => {\n (async () => {\n debug.log(\"useConfig\", \"loading fresh config\");\n const searchParams = new URLSearchParams();\n searchParams.set(\"shop\", shopifyPermanentDomain);\n\n if (configId) {\n searchParams.set(\"id\", configId);\n }\n\n let json: any;\n\n try {\n json = await fetch(\n `https://config.search.reactify.app/?${searchParams.toString()}`\n ).then((response) => response.json());\n \n } catch (error) {\n debug.log(\"useConfig\", \"error loading config, retrying...\");\n\n json = await fetch(\n `https://config.search.reactify.app/?${searchParams.toString()}`\n ).then((response) => response.json());\n }\n\n setConfig(json.body);\n\n debug.log(\"useConfig\", \"loaded fresh config\");\n\n window.sessionStorage.setItem(\n \"reactify-search:config\",\n JSON.stringify({\n config: json.body,\n })\n );\n })();\n }, [shopifyPermanentDomain, configId]);\n\n React.useEffect(() => {\n debug.log(\"useConfig\", \"config\", config);\n }, [config]);\n\n return {\n config,\n };\n};\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@usereactify/search",
3
3
  "description": "React UI library for Reactify Search",
4
- "version": "5.36.1",
4
+ "version": "5.38.0",
5
5
  "license": "MIT",
6
6
  "main": "dist/src/index.js",
7
7
  "types": "dist/src/index.d.ts",