@constructor-io/constructorio-ui-autocomplete 1.14.1 → 1.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.debounceDescription = exports.termsWithImagesAndCountsDescription = exports.filteredSuggestionsDescription = exports.termsWithGroupSuggestionsDescription = exports.advancedParametersDefaultDescription = exports.advancedParametersDescription = exports.customStylesDescription = exports.multipleSectionsDescription = exports.openOnFocusDescription = exports.zeroStateSectionsDescription = exports.onSubmitDefault = exports.onSubmitDescription = exports.onChangeDescription = exports.onFocusDescription = exports.customSectionDescription = exports.displaySearchTermHighlightsDescription = exports.recommendationsDescription = exports.sectionOrderDescription = exports.numResultsDescription = exports.contentDescription = exports.productsDescription = exports.searchSuggestionsDescription = exports.placeholderDescription = exports.cioJsClientDescription = exports.apiKeyDescription = exports.fullFeaturedAndStyledExampleDescription = exports.zeroStateDescription = exports.userEventsDescription = exports.sectionsDescription = exports.hookDescription = exports.componentDescription = exports.apiKey = void 0;
3
+ exports.debounceDescription = exports.termsWithImagesAndCountsDescription = exports.filteredSuggestionsDescription = exports.termsWithGroupSuggestionsDescription = exports.advancedParametersDefaultDescription = exports.advancedParametersDescription = exports.customStylesDescription = exports.multipleSectionsDescription = exports.openOnFocusDescription = exports.zeroStateSectionsDescription = exports.onSubmitDefault = exports.onSubmitDescription = exports.onChangeDescription = exports.onFocusDescription = exports.customSectionDescription = exports.displaySearchTermHighlightsDescription = exports.recommendationsDescription = exports.sectionOrderDescription = exports.numResultsDescription = exports.contentDescription = exports.productsDescription = exports.searchSuggestionsDescription = exports.placeholderDescription = exports.cioJsClientOptionsDescription = exports.cioJsClientDescription = exports.apiKeyDescription = exports.fullFeaturedAndStyledExampleDescription = exports.zeroStateDescription = exports.userEventsDescription = exports.sectionsDescription = exports.hookDescription = exports.componentDescription = exports.apiKey = void 0;
4
4
  // Autocomplete key index
5
5
  exports.apiKey = 'key_M57QS8SMPdLdLx4x';
6
6
  /// //////////////////////////////
@@ -102,6 +102,7 @@ exports.apiKeyDescription = `Pass an \`apiKey\` to request results from construc
102
102
  exports.cioJsClientDescription = `If you are already using an instance of the \`ConstructorIOClient\`, you can pass a \`cioJsClient\` instead of an \`apiKey\` to request results from constructor's servers
103
103
 
104
104
  > Note: when we say \`cioJsClient\`, we are referring to an instance of the [constructorio-client-javascript](https://www.npmjs.com/package/@constructor-io/constructorio-client-javascript)`;
105
+ exports.cioJsClientOptionsDescription = `If you don't want to create an instance of the \`ConstructorIOClient\` but still want to customize some of the options, you can pass a \`cioJsClientOptions\` object. You can learn more about the possible values [here under the parameters section](https://constructor-io.github.io/constructorio-client-javascript/ConstructorIO.html).`;
105
106
  exports.placeholderDescription = `Pass a \`placeholder\` to override the default input field placeholder text shown to users before they start typing their query`;
106
107
  exports.searchSuggestionsDescription = `Override default \`sections\` to only suggest search terms`;
107
108
  exports.productsDescription = `Override default \`sections\` to only suggested products`;
@@ -21,10 +21,10 @@ exports.defaultSections = [
21
21
  },
22
22
  ];
23
23
  const useCioAutocomplete = (options) => {
24
- const { onSubmit, onChange, openOnFocus, apiKey, cioJsClient, placeholder = 'What can we help you find today?', sections = exports.defaultSections, zeroStateSections, autocompleteClassName = 'cio-autocomplete', advancedParameters, } = options;
24
+ const { onSubmit, onChange, openOnFocus, apiKey, cioJsClient, cioJsClientOptions, placeholder = 'What can we help you find today?', sections = exports.defaultSections, zeroStateSections, autocompleteClassName = 'cio-autocomplete', advancedParameters, } = options;
25
25
  const [query, setQuery] = (0, react_1.useState)('');
26
26
  const previousQuery = (0, usePrevious_1.default)(query);
27
- const cioClient = (0, useCioClient_1.default)({ apiKey, cioJsClient });
27
+ const cioClient = (0, useCioClient_1.default)({ apiKey, cioJsClient, cioJsClientOptions });
28
28
  // Get autocomplete sections (autocomplete + recommendations + custom)
29
29
  const { activeSections, activeSectionsWithData, zeroStateActiveSections, request } = (0, useSections_1.default)(query, cioClient, sections, zeroStateSections, advancedParameters);
30
30
  // Get dropdown items array from active sections (autocomplete + recommendations + custom)
@@ -2,11 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const react_1 = require("react");
4
4
  const utils_1 = require("../utils");
5
- const useCioClient = ({ apiKey, cioJsClient }) => {
5
+ const useCioClient = ({ apiKey, cioJsClient, cioJsClientOptions }) => {
6
6
  if (!apiKey && !cioJsClient) {
7
7
  // eslint-disable-next-line no-console
8
8
  console.error('Either apiKey or cioJsClient is required');
9
9
  }
10
- return (0, react_1.useMemo)(() => cioJsClient || (0, utils_1.getCioClient)(apiKey), [apiKey, cioJsClient]);
10
+ return (0, react_1.useMemo)(() => cioJsClient || (0, utils_1.getCioClient)(apiKey, cioJsClientOptions), [apiKey, cioJsClient, cioJsClientOptions]);
11
11
  };
12
12
  exports.default = useCioClient;
@@ -6,7 +6,7 @@ const useDebounce_1 = tslib_1.__importDefault(require("./useDebounce"));
6
6
  const transformResponse = (response, options) => {
7
7
  const { numTermsWithGroupSuggestions, numGroupsSuggestedPerTerm } = options;
8
8
  const newSectionsData = {};
9
- Object.keys(response.sections).forEach((section) => {
9
+ Object.keys((response === null || response === void 0 ? void 0 : response.sections) || {}).forEach((section) => {
10
10
  newSectionsData[section] = [];
11
11
  const sectionItems = response.sections[section].map((item) => {
12
12
  var _a;
package/lib/cjs/utils.js CHANGED
@@ -110,13 +110,9 @@ const disableStoryActions = (story) => {
110
110
  story.parameters.actions = { argTypesRegex: null };
111
111
  };
112
112
  exports.disableStoryActions = disableStoryActions;
113
- const getCioClient = (apiKey) => {
114
- if (apiKey) {
115
- const cioClient = new constructorio_client_javascript_1.default({
116
- apiKey,
117
- sendTrackingEvents: true,
118
- version: `cio-ui-autocomplete-${version_1.default}`,
119
- });
113
+ const getCioClient = (apiKey, cioJsClientOptions) => {
114
+ if (apiKey && typeof window !== 'undefined') {
115
+ const cioClient = new constructorio_client_javascript_1.default(Object.assign({ apiKey, sendTrackingEvents: true, version: `cio-ui-autocomplete-${version_1.default}` }, cioJsClientOptions));
120
116
  // eslint-disable-next-line no-console
121
117
  cioClient.tracker.on('error', (error) => console.error(error));
122
118
  return cioClient;
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = '1.14.0';
3
+ exports.default = '1.15.1';
@@ -99,6 +99,7 @@ export const apiKeyDescription = `Pass an \`apiKey\` to request results from con
99
99
  export const cioJsClientDescription = `If you are already using an instance of the \`ConstructorIOClient\`, you can pass a \`cioJsClient\` instead of an \`apiKey\` to request results from constructor's servers
100
100
 
101
101
  > Note: when we say \`cioJsClient\`, we are referring to an instance of the [constructorio-client-javascript](https://www.npmjs.com/package/@constructor-io/constructorio-client-javascript)`;
102
+ export const cioJsClientOptionsDescription = `If you don't want to create an instance of the \`ConstructorIOClient\` but still want to customize some of the options, you can pass a \`cioJsClientOptions\` object. You can learn more about the possible values [here under the parameters section](https://constructor-io.github.io/constructorio-client-javascript/ConstructorIO.html).`;
102
103
  export const placeholderDescription = `Pass a \`placeholder\` to override the default input field placeholder text shown to users before they start typing their query`;
103
104
  export const searchSuggestionsDescription = `Override default \`sections\` to only suggest search terms`;
104
105
  export const productsDescription = `Override default \`sections\` to only suggested products`;
@@ -17,10 +17,10 @@ export const defaultSections = [
17
17
  },
18
18
  ];
19
19
  const useCioAutocomplete = (options) => {
20
- const { onSubmit, onChange, openOnFocus, apiKey, cioJsClient, placeholder = 'What can we help you find today?', sections = defaultSections, zeroStateSections, autocompleteClassName = 'cio-autocomplete', advancedParameters, } = options;
20
+ const { onSubmit, onChange, openOnFocus, apiKey, cioJsClient, cioJsClientOptions, placeholder = 'What can we help you find today?', sections = defaultSections, zeroStateSections, autocompleteClassName = 'cio-autocomplete', advancedParameters, } = options;
21
21
  const [query, setQuery] = useState('');
22
22
  const previousQuery = usePrevious(query);
23
- const cioClient = useCioClient({ apiKey, cioJsClient });
23
+ const cioClient = useCioClient({ apiKey, cioJsClient, cioJsClientOptions });
24
24
  // Get autocomplete sections (autocomplete + recommendations + custom)
25
25
  const { activeSections, activeSectionsWithData, zeroStateActiveSections, request } = useSections(query, cioClient, sections, zeroStateSections, advancedParameters);
26
26
  // Get dropdown items array from active sections (autocomplete + recommendations + custom)
@@ -1,10 +1,10 @@
1
1
  import { useMemo } from 'react';
2
2
  import { getCioClient } from '../utils';
3
- const useCioClient = ({ apiKey, cioJsClient }) => {
3
+ const useCioClient = ({ apiKey, cioJsClient, cioJsClientOptions }) => {
4
4
  if (!apiKey && !cioJsClient) {
5
5
  // eslint-disable-next-line no-console
6
6
  console.error('Either apiKey or cioJsClient is required');
7
7
  }
8
- return useMemo(() => cioJsClient || getCioClient(apiKey), [apiKey, cioJsClient]);
8
+ return useMemo(() => cioJsClient || getCioClient(apiKey, cioJsClientOptions), [apiKey, cioJsClient, cioJsClientOptions]);
9
9
  };
10
10
  export default useCioClient;
@@ -3,7 +3,7 @@ import useDebounce from './useDebounce';
3
3
  const transformResponse = (response, options) => {
4
4
  const { numTermsWithGroupSuggestions, numGroupsSuggestedPerTerm } = options;
5
5
  const newSectionsData = {};
6
- Object.keys(response.sections).forEach((section) => {
6
+ Object.keys(response?.sections || {}).forEach((section) => {
7
7
  newSectionsData[section] = [];
8
8
  const sectionItems = response.sections[section].map((item) => ({
9
9
  ...item,
package/lib/mjs/utils.js CHANGED
@@ -93,12 +93,13 @@ export const disableStoryActions = (story) => {
93
93
  // eslint-disable-next-line
94
94
  story.parameters.actions = { argTypesRegex: null };
95
95
  };
96
- export const getCioClient = (apiKey) => {
97
- if (apiKey) {
96
+ export const getCioClient = (apiKey, cioJsClientOptions) => {
97
+ if (apiKey && typeof window !== 'undefined') {
98
98
  const cioClient = new ConstructorIOClient({
99
99
  apiKey,
100
100
  sendTrackingEvents: true,
101
101
  version: `cio-ui-autocomplete-${version}`,
102
+ ...cioJsClientOptions,
102
103
  });
103
104
  // eslint-disable-next-line no-console
104
105
  cioClient.tracker.on('error', (error) => console.error(error));
@@ -1 +1 @@
1
- export default '1.14.0';
1
+ export default '1.15.1';
@@ -8,6 +8,7 @@ export declare const zeroStateDescription = "- when the text input field has no
8
8
  export declare const fullFeaturedAndStyledExampleDescription = "Using the default options, the library displays clean and minimal visual elements, with the intent of making it easy for consumers to easily extend and customize the styles to suit unique needs. The example below shows a full featured and styled example to demonstrate what is possible using Constructor.io's advanced Autocomplete UI library.";
9
9
  export declare const apiKeyDescription = "Pass an `apiKey` to request results from constructor's servers";
10
10
  export declare const cioJsClientDescription = "If you are already using an instance of the `ConstructorIOClient`, you can pass a `cioJsClient` instead of an `apiKey` to request results from constructor's servers\n\n> Note: when we say `cioJsClient`, we are referring to an instance of the [constructorio-client-javascript](https://www.npmjs.com/package/@constructor-io/constructorio-client-javascript)";
11
+ export declare const cioJsClientOptionsDescription = "If you don't want to create an instance of the `ConstructorIOClient` but still want to customize some of the options, you can pass a `cioJsClientOptions` object. You can learn more about the possible values [here under the parameters section](https://constructor-io.github.io/constructorio-client-javascript/ConstructorIO.html).";
11
12
  export declare const placeholderDescription = "Pass a `placeholder` to override the default input field placeholder text shown to users before they start typing their query";
12
13
  export declare const searchSuggestionsDescription = "Override default `sections` to only suggest search terms";
13
14
  export declare const productsDescription = "Override default `sections` to only suggested products";
@@ -1,11 +1,12 @@
1
1
  import { GetItemPropsOptions } from 'downshift';
2
2
  import { ReactNode } from 'react';
3
3
  import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
4
- import { IAutocompleteParameters, SearchSuggestion as SearchSuggestionFromClient, Product as ProductFromClient, Item as ItemBase, AutocompleteRequestType } from '@constructor-io/constructorio-client-javascript/lib/types';
4
+ import { IAutocompleteParameters, SearchSuggestion as SearchSuggestionFromClient, Product as ProductFromClient, Item as ItemBase, AutocompleteRequestType, ConstructorClientOptions } from '@constructor-io/constructorio-client-javascript/lib/types';
5
5
  export type { IAutocompleteParameters } from '@constructor-io/constructorio-client-javascript/lib/types';
6
6
  export type CioClientConfig = {
7
7
  apiKey?: string;
8
8
  cioJsClient?: ConstructorIOClient;
9
+ cioJsClientOptions?: ConstructorClientOptions;
9
10
  };
10
11
  export interface AdvancedParametersBase {
11
12
  numTermsWithGroupSuggestions?: number;
@@ -1,5 +1,5 @@
1
1
  import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
2
- import { AutocompleteRequestType } from '@constructor-io/constructorio-client-javascript/lib/types';
2
+ import { AutocompleteRequestType, ConstructorClientOptions } from '@constructor-io/constructorio-client-javascript/lib/types';
3
3
  import { OnSubmit, Item, Section, UserDefinedSection, SectionsData } from './types';
4
4
  export type GetItemPosition = (args: {
5
5
  item: Item;
@@ -36,7 +36,7 @@ export declare const stringifyWithDefaults: (obj: {
36
36
  onSubmit: OnSubmit;
37
37
  }) => string;
38
38
  export declare const disableStoryActions: (story: any) => void;
39
- export declare const getCioClient: (apiKey?: string) => ConstructorIOClient | null;
39
+ export declare const getCioClient: (apiKey?: string, cioJsClientOptions?: ConstructorClientOptions) => ConstructorIOClient | null;
40
40
  export declare const getActiveSectionsWithData: (activeSections: UserDefinedSection[], sectionResults: SectionsData) => Section[];
41
41
  export declare const escapeRegExp: (string: string) => string;
42
42
  export {};
@@ -1,2 +1,2 @@
1
- declare const _default: "1.14.0";
1
+ declare const _default: "1.15.1";
2
2
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-ui-autocomplete",
3
- "version": "1.14.1",
3
+ "version": "1.15.1",
4
4
  "description": "Constructor.io Autocomplete UI library for web applications",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -37,9 +37,6 @@
37
37
  "test-storybook:ci": "start-server-and-test storybook:ci http://localhost:6006 test-storybook",
38
38
  "build-storybook": "storybook build -o 'docs'",
39
39
  "serve-built-storybook": "npx http-server docs",
40
- "verify-node-version": "chmod +x ./scripts/verify-node-version.sh && ./scripts/verify-node-version.sh",
41
- "preversion": "node ./src/generateVersion.js",
42
- "version": "npm run verify-node-version && npm run build-storybook && git add -u ./docs && git add ./docs/* && git add ./src/version.ts && npm run compile",
43
40
  "compile": "rm -rf lib && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && npm run copy-styles && vite build"
44
41
  },
45
42
  "author": "constructor.io",