@streamoid/catalogix-chat 0.2.22 → 0.2.24

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/dist/index.d.ts CHANGED
@@ -89,6 +89,7 @@ declare const catalogixManifest: readonly [{
89
89
  */
90
90
  interface ApiConfig {
91
91
  catalogixBaseUrl: string;
92
+ catalogingBaseUrl: string;
92
93
  keplerProxyPrefix: string;
93
94
  }
94
95
  declare function configureApi(config: Partial<ApiConfig>): void;
package/dist/index.js CHANGED
@@ -1,9 +1,10 @@
1
1
  // src/CatalogixChat.tsx
2
- import { useEffect as useEffect8 } from "react";
2
+ import { useEffect as useEffect9 } from "react";
3
3
 
4
4
  // src/api.ts
5
5
  var _config = {
6
6
  catalogixBaseUrl: "",
7
+ catalogingBaseUrl: "https://cataloging.streamoid.com",
7
8
  keplerProxyPrefix: "/kepler-api"
8
9
  };
9
10
  function configureApi(config) {
@@ -3078,12 +3079,13 @@ function MapAttributesChat({
3078
3079
  }
3079
3080
 
3080
3081
  // src/EditFeed/index.tsx
3081
- import React8, { useState as useState8, useMemo as useMemo6, useCallback as useCallback6 } from "react";
3082
+ import React8, { useState as useState8, useMemo as useMemo6, useCallback as useCallback6, useRef as useRef5, useEffect as useEffect6 } from "react";
3082
3083
  import {
3083
3084
  AlertTriangle as AlertTriangle2,
3084
3085
  Check as Check3,
3085
3086
  ChevronDown as ChevronDown3,
3086
3087
  ChevronRight as ChevronRight3,
3088
+ HelpCircle,
3087
3089
  Pencil as Pencil3,
3088
3090
  Send as Send2,
3089
3091
  Loader2 as Loader26,
@@ -3152,19 +3154,101 @@ async function mergeFeed(fileUrl, feedFormat, changes) {
3152
3154
  }
3153
3155
  );
3154
3156
  }
3157
+ async function fetchValidValues(sourceMp, marketplaceOv, category, attribute) {
3158
+ const { catalogingBaseUrl } = getApiConfig();
3159
+ const params = new URLSearchParams({
3160
+ response_style: "light",
3161
+ category,
3162
+ attribute
3163
+ });
3164
+ const url = `${catalogingBaseUrl}/marketplaces/${sourceMp}/versions/${marketplaceOv}/structure?${params}`;
3165
+ const resp = await fetchJson(url);
3166
+ return resp[attribute] ?? Object.values(resp)[0] ?? [];
3167
+ }
3155
3168
  function EditableCell2({
3156
3169
  value,
3157
3170
  hasError,
3158
3171
  errorMessage,
3159
3172
  onChange,
3160
- readOnly
3173
+ readOnly,
3174
+ onFetchSuggestions
3161
3175
  }) {
3162
3176
  const [editing, setEditing] = useState8(false);
3163
3177
  const [draft, setDraft] = useState8(value);
3178
+ const [showSuggestions, setShowSuggestions] = useState8(false);
3179
+ const [suggestions, setSuggestions] = useState8(null);
3180
+ const [loadingSuggestions, setLoadingSuggestions] = useState8(false);
3181
+ const suggestionsRef = useRef5(null);
3182
+ useEffect6(() => {
3183
+ if (!showSuggestions) return;
3184
+ const handler = (e) => {
3185
+ if (suggestionsRef.current && !suggestionsRef.current.contains(e.target)) {
3186
+ setShowSuggestions(false);
3187
+ }
3188
+ };
3189
+ document.addEventListener("mousedown", handler);
3190
+ return () => document.removeEventListener("mousedown", handler);
3191
+ }, [showSuggestions]);
3192
+ const handleToggleSuggestions = useCallback6(
3193
+ async (e) => {
3194
+ e.stopPropagation();
3195
+ if (showSuggestions) {
3196
+ setShowSuggestions(false);
3197
+ return;
3198
+ }
3199
+ setShowSuggestions(true);
3200
+ if (suggestions !== null || !onFetchSuggestions) return;
3201
+ setLoadingSuggestions(true);
3202
+ try {
3203
+ const vals = await onFetchSuggestions();
3204
+ setSuggestions(vals);
3205
+ } catch {
3206
+ setSuggestions([]);
3207
+ } finally {
3208
+ setLoadingSuggestions(false);
3209
+ }
3210
+ },
3211
+ [showSuggestions, suggestions, onFetchSuggestions]
3212
+ );
3213
+ const selectSuggestion = useCallback6(
3214
+ (val) => {
3215
+ onChange(val);
3216
+ setDraft(val);
3217
+ setShowSuggestions(false);
3218
+ },
3219
+ [onChange]
3220
+ );
3164
3221
  const commit = useCallback6(() => {
3165
3222
  setEditing(false);
3166
3223
  if (draft !== value) onChange(draft);
3167
3224
  }, [draft, value, onChange]);
3225
+ const suggestionsPanel = showSuggestions && hasError && onFetchSuggestions ? /* @__PURE__ */ jsx22(
3226
+ "div",
3227
+ {
3228
+ ref: suggestionsRef,
3229
+ className: "absolute left-0 top-full z-20 mt-1 rounded border bg-popover p-1.5 shadow-md max-w-[280px]",
3230
+ children: loadingSuggestions ? /* @__PURE__ */ jsxs11("div", { className: "flex items-center gap-1.5 text-[10px] text-muted-foreground px-1 py-0.5", children: [
3231
+ /* @__PURE__ */ jsx22(Loader26, { className: "h-3 w-3 animate-spin" }),
3232
+ "Loading valid values\u2026"
3233
+ ] }) : suggestions && suggestions.length > 0 ? /* @__PURE__ */ jsx22("div", { className: "flex flex-wrap gap-1 max-h-[120px] overflow-auto", children: suggestions.map((s) => /* @__PURE__ */ jsx22(
3234
+ "button",
3235
+ {
3236
+ type: "button",
3237
+ onClick: (e) => {
3238
+ e.stopPropagation();
3239
+ selectSuggestion(s);
3240
+ },
3241
+ className: cn(
3242
+ "inline-flex items-center rounded-md border px-1.5 py-0.5 text-[10px] font-medium transition-colors",
3243
+ "hover:bg-primary hover:text-primary-foreground cursor-pointer",
3244
+ "border-border bg-muted/40 text-foreground"
3245
+ ),
3246
+ children: s
3247
+ },
3248
+ s
3249
+ )) }) : /* @__PURE__ */ jsx22("p", { className: "text-[10px] text-muted-foreground px-1 py-0.5", children: "No valid values found." })
3250
+ }
3251
+ ) : null;
3168
3252
  if (readOnly) {
3169
3253
  return /* @__PURE__ */ jsxs11(
3170
3254
  "div",
@@ -3182,26 +3266,29 @@ function EditableCell2({
3182
3266
  );
3183
3267
  }
3184
3268
  if (editing) {
3185
- return /* @__PURE__ */ jsx22(
3186
- Input,
3187
- {
3188
- autoFocus: true,
3189
- value: draft,
3190
- onChange: (e) => setDraft(e.target.value),
3191
- onBlur: commit,
3192
- onKeyDown: (e) => {
3193
- if (e.key === "Enter") commit();
3194
- if (e.key === "Escape") {
3195
- setDraft(value);
3196
- setEditing(false);
3197
- }
3198
- },
3199
- className: cn(
3200
- "h-7 text-sm rounded px-1.5",
3201
- hasError && "border-destructive focus-visible:ring-destructive/30"
3202
- )
3203
- }
3204
- );
3269
+ return /* @__PURE__ */ jsxs11("div", { className: "relative", children: [
3270
+ /* @__PURE__ */ jsx22(
3271
+ Input,
3272
+ {
3273
+ autoFocus: true,
3274
+ value: draft,
3275
+ onChange: (e) => setDraft(e.target.value),
3276
+ onBlur: commit,
3277
+ onKeyDown: (e) => {
3278
+ if (e.key === "Enter") commit();
3279
+ if (e.key === "Escape") {
3280
+ setDraft(value);
3281
+ setEditing(false);
3282
+ }
3283
+ },
3284
+ className: cn(
3285
+ "h-7 text-sm rounded px-1.5",
3286
+ hasError && "border-destructive focus-visible:ring-destructive/30"
3287
+ )
3288
+ }
3289
+ ),
3290
+ suggestionsPanel
3291
+ ] });
3205
3292
  }
3206
3293
  return /* @__PURE__ */ jsxs11(
3207
3294
  "div",
@@ -3218,7 +3305,18 @@ function EditableCell2({
3218
3305
  children: [
3219
3306
  /* @__PURE__ */ jsx22("span", { className: "truncate max-w-[160px]", children: value }),
3220
3307
  /* @__PURE__ */ jsx22(Pencil3, { className: "h-3 w-3 shrink-0 opacity-0 group-hover:opacity-70 transition-opacity" }),
3221
- hasError && errorMessage && /* @__PURE__ */ jsx22("div", { className: "absolute left-0 top-full z-10 mt-1 hidden group-hover:block", children: /* @__PURE__ */ jsx22("div", { className: "rounded bg-destructive px-2 py-1 text-[10px] text-destructive-foreground shadow-md max-w-[260px] whitespace-normal", children: errorMessage }) })
3308
+ hasError && onFetchSuggestions && /* @__PURE__ */ jsx22(
3309
+ "button",
3310
+ {
3311
+ type: "button",
3312
+ onClick: handleToggleSuggestions,
3313
+ className: "shrink-0 rounded p-0.5 hover:bg-destructive/20 transition-colors",
3314
+ title: "Show valid values",
3315
+ children: /* @__PURE__ */ jsx22(HelpCircle, { className: "h-3 w-3" })
3316
+ }
3317
+ ),
3318
+ hasError && errorMessage && !showSuggestions && /* @__PURE__ */ jsx22("div", { className: "absolute left-0 top-full z-10 mt-1 hidden group-hover:block", children: /* @__PURE__ */ jsx22("div", { className: "rounded bg-destructive px-2 py-1 text-[10px] text-destructive-foreground shadow-md max-w-[260px] whitespace-normal", children: errorMessage }) }),
3319
+ suggestionsPanel
3222
3320
  ]
3223
3321
  }
3224
3322
  );
@@ -3474,7 +3572,13 @@ function EditFeed({
3474
3572
  hasError: !!cellErr,
3475
3573
  errorMessage: cellErr,
3476
3574
  onChange: (val) => handleCellChange(rowIdx, col, val),
3477
- readOnly: isLoading
3575
+ readOnly: isLoading,
3576
+ onFetchSuggestions: cellErr ? () => fetchValidValues(
3577
+ sourceMp,
3578
+ marketplaceOv,
3579
+ row["Category"] ?? "",
3580
+ col
3581
+ ) : void 0
3478
3582
  }
3479
3583
  ) }, col);
3480
3584
  })
@@ -3525,7 +3629,7 @@ function EditFeed({
3525
3629
  }
3526
3630
 
3527
3631
  // src/Automations/ProductAutomation.tsx
3528
- import { useState as useState10, useEffect as useEffect6, useCallback as useCallback8, useRef as useRef5 } from "react";
3632
+ import { useState as useState10, useEffect as useEffect7, useCallback as useCallback8, useRef as useRef6 } from "react";
3529
3633
  import { ArrowLeft as ArrowLeft3, Search as Search4, Loader2 as Loader28, ChevronDown as ChevronDown4, Play } from "lucide-react";
3530
3634
 
3531
3635
  // src/Automations/api.ts
@@ -4014,14 +4118,14 @@ function ProductAutomation({
4014
4118
  const [loadingOptions, setLoadingOptions] = useState10({});
4015
4119
  const [schemaLoading, setSchemaLoading] = useState10(false);
4016
4120
  const [applying, setApplying] = useState10(false);
4017
- const configsRef = useRef5(configs);
4121
+ const configsRef = useRef6(configs);
4018
4122
  configsRef.current = configs;
4019
- const optionsRef = useRef5(options);
4123
+ const optionsRef = useRef6(options);
4020
4124
  optionsRef.current = options;
4021
- const loadingOptionsRef = useRef5(loadingOptions);
4125
+ const loadingOptionsRef = useRef6(loadingOptions);
4022
4126
  loadingOptionsRef.current = loadingOptions;
4023
4127
  const productsCount = selectedProducts.includes("all") ? excludedProducts.length === 0 ? totalProducts : totalProducts - excludedProducts.length : productsCountProp;
4024
- useEffect6(() => {
4128
+ useEffect7(() => {
4025
4129
  setLoading(true);
4026
4130
  fetchAutomationList(storeId, "product", true).then((data) => {
4027
4131
  const groups = {};
@@ -4037,7 +4141,7 @@ function ProductAutomation({
4037
4141
  if (sorted.length > 0) setExpandedGroups([sorted[0]]);
4038
4142
  }).catch(console.error).finally(() => setLoading(false));
4039
4143
  }, [storeId]);
4040
- useEffect6(() => {
4144
+ useEffect7(() => {
4041
4145
  if (!selected) {
4042
4146
  setSchema([]);
4043
4147
  setConfigs({});
@@ -4056,7 +4160,7 @@ function ProductAutomation({
4056
4160
  configsRef.current = defaults;
4057
4161
  }).catch(console.error).finally(() => setSchemaLoading(false));
4058
4162
  }, [selected, storeId]);
4059
- useEffect6(() => {
4163
+ useEffect7(() => {
4060
4164
  if (schema.length === 0) return;
4061
4165
  const flatItems = schema.flatMap((s) => s.mapping_parameters ?? [s]);
4062
4166
  for (const item of flatItems) {
@@ -4312,7 +4416,7 @@ function formatTimeSaved(totalSeconds) {
4312
4416
  }
4313
4417
 
4314
4418
  // src/Automations/StoreAutomation.tsx
4315
- import { useState as useState11, useEffect as useEffect7, useCallback as useCallback9, useRef as useRef6 } from "react";
4419
+ import { useState as useState11, useEffect as useEffect8, useCallback as useCallback9, useRef as useRef7 } from "react";
4316
4420
  import { ArrowLeft as ArrowLeft4, Settings } from "lucide-react";
4317
4421
  import { Fragment as Fragment6, jsx as jsx25, jsxs as jsxs14 } from "react/jsx-runtime";
4318
4422
  function StoreAutomation({
@@ -4326,7 +4430,7 @@ function StoreAutomation({
4326
4430
  const [automations, setAutomations] = useState11([]);
4327
4431
  const [selectedConfigs, setSelectedConfigs] = useState11({ ...enabledAutomations });
4328
4432
  const [selectedAutomation, setSelectedAutomation] = useState11(null);
4329
- useEffect7(() => {
4433
+ useEffect8(() => {
4330
4434
  setLoading(true);
4331
4435
  fetchAutomationList(storeId, "default").then((data) => {
4332
4436
  setAutomations(
@@ -4461,11 +4565,11 @@ function AutomationConfigEditor({
4461
4565
  );
4462
4566
  const [options, setOptions] = useState11({});
4463
4567
  const [loadingOptions, setLoadingOptions] = useState11({});
4464
- const configsRef = useRef6(configs);
4568
+ const configsRef = useRef7(configs);
4465
4569
  configsRef.current = configs;
4466
- const optionsRef = useRef6(options);
4570
+ const optionsRef = useRef7(options);
4467
4571
  optionsRef.current = options;
4468
- useEffect7(() => {
4572
+ useEffect8(() => {
4469
4573
  if (!automation.isEnabled) return;
4470
4574
  setSchemaLoading(true);
4471
4575
  fetchAutomationSchema(storeId, automation.automation, "default").then((items) => {
@@ -4480,7 +4584,7 @@ function AutomationConfigEditor({
4480
4584
  }
4481
4585
  }).catch(console.error).finally(() => setSchemaLoading(false));
4482
4586
  }, [storeId, automation, initialConfigs]);
4483
- useEffect7(() => {
4587
+ useEffect8(() => {
4484
4588
  if (schema.length === 0) return;
4485
4589
  for (const item of schema) {
4486
4590
  if (!item.curl) continue;
@@ -4611,7 +4715,7 @@ function CatalogixChat(props) {
4611
4715
  const filters = uiProps.filters ?? {};
4612
4716
  const selectedPageRange = uiProps.selectedPageRange ?? [];
4613
4717
  const enabledAutomations = uiProps.enabledAutomations ?? {};
4614
- useEffect8(() => {
4718
+ useEffect9(() => {
4615
4719
  configureApi({ catalogixBaseUrl });
4616
4720
  }, [catalogixBaseUrl]);
4617
4721
  if (section === "select_products") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamoid/catalogix-chat",
3
- "version": "0.2.22",
3
+ "version": "0.2.24",
4
4
  "description": "Catalogix chat components for the Streamoid chat host — store creation, product selection, automations",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",