@streamoid/catalogix-chat 0.2.19 → 0.2.21

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
@@ -75,7 +75,7 @@ declare const catalogixManifest: readonly [{
75
75
  readonly overflow: "auto";
76
76
  readonly marginTop: "8px";
77
77
  readonly paddingBottom: "16px";
78
- readonly height: "600px";
78
+ readonly maxHeight: "600px";
79
79
  readonly position: "relative";
80
80
  readonly width: "100%";
81
81
  };
@@ -186,11 +186,12 @@ interface EditFeedProps {
186
186
  sourceMp: string;
187
187
  marketplaceOv: number | string;
188
188
  transformedUrl: string;
189
+ mappingKey: string;
189
190
  submitted?: boolean;
190
191
  submittedValues?: Record<string, unknown>;
191
192
  onSubmit: (values: Record<string, unknown>, message?: string) => void;
192
193
  }
193
- declare function EditFeed({ criticalIssues: initialCriticalIssues, rawErrorData: initialRawErrorData, dataIssuesRaw: initialDataIssuesRaw, columns: initialColumns, skuField, storeId, feedFileType, downloadUrl, userId, mappingObj, sourceMp, marketplaceOv, transformedUrl: initialTransformedUrl, submitted, submittedValues, onSubmit, }: EditFeedProps): react_jsx_runtime.JSX.Element;
194
+ declare function EditFeed({ criticalIssues: initialCriticalIssues, rawErrorData: initialRawErrorData, dataIssuesRaw: initialDataIssuesRaw, columns: initialColumns, skuField, storeId, feedFileType, downloadUrl, userId, mappingObj, sourceMp, marketplaceOv, transformedUrl: initialTransformedUrl, mappingKey, submitted, submittedValues, onSubmit, }: EditFeedProps): react_jsx_runtime.JSX.Element;
194
195
 
195
196
  interface ProductAutomationProps {
196
197
  storeId: string;
package/dist/index.js CHANGED
@@ -3125,66 +3125,33 @@ function buildDataIssueMap(issues) {
3125
3125
  }
3126
3126
  return map;
3127
3127
  }
3128
- function rowsToCsvBlob(rows, columns) {
3129
- const escape = (v) => {
3130
- if (v.includes(",") || v.includes('"') || v.includes("\n")) {
3131
- return `"${v.replace(/"/g, '""')}"`;
3132
- }
3133
- return v;
3134
- };
3135
- const lines = [columns.map(escape).join(",")];
3136
- for (const row of rows) {
3137
- lines.push(columns.map((c) => escape(row[c] ?? "")).join(","));
3138
- }
3139
- return new Blob([lines.join("\n")], { type: "text/csv" });
3140
- }
3141
- async function uploadCorrectedCsv(storeId, csvBlob, fileName) {
3128
+ async function validateRow(storeId, mappingKey, rowData) {
3142
3129
  const { catalogixBaseUrl } = getApiConfig();
3143
- const form = new FormData();
3144
- form.append("file_type", "csv");
3145
- form.append("file_data", csvBlob, fileName);
3146
- form.append("data", JSON.stringify({ fileName, size: csvBlob.size / 1024 }));
3147
- const resp = await fetch(
3148
- `${catalogixBaseUrl}/api/v1/store/${storeId}/feed/onboard`,
3149
- { method: "POST", credentials: "include", body: form }
3130
+ const params = new URLSearchParams({ mapping_key: mappingKey });
3131
+ return fetchJson(
3132
+ `${catalogixBaseUrl}/api/v1/feed/${storeId}/validate/row?${params}`,
3133
+ {
3134
+ method: "POST",
3135
+ headers: { "Content-Type": "application/json" },
3136
+ body: JSON.stringify([rowData])
3137
+ }
3150
3138
  );
3151
- if (!resp.ok) throw new Error(`Upload failed: ${resp.status}`);
3152
- const json = await resp.json();
3153
- return json.data.download_url;
3154
3139
  }
3155
- async function validateFeed(storeId, fileUrl, feedFileType, clientFeedUrl, userId, mappingObj, sourceMp, marketplaceOv, reValidate) {
3140
+ async function mergeFeed(fileUrl, feedFormat, changes) {
3156
3141
  const { catalogixBaseUrl } = getApiConfig();
3157
3142
  const params = new URLSearchParams({
3158
3143
  file_url: fileUrl,
3159
- feed_format: feedFileType,
3160
- client_feed_url: clientFeedUrl,
3161
- catalogix_user_id: userId,
3162
- re_validate: String(reValidate)
3144
+ feed_format: feedFormat
3163
3145
  });
3164
3146
  return fetchJson(
3165
- `${catalogixBaseUrl}/api/v1/feed/${storeId}/validate/v2?${params}`,
3147
+ `${catalogixBaseUrl}/api/v1/feed/merge?${params}`,
3166
3148
  {
3167
3149
  method: "POST",
3168
3150
  headers: { "Content-Type": "application/json" },
3169
- body: JSON.stringify({
3170
- mapping: {
3171
- ...mappingObj,
3172
- catalogix_user_id: userId,
3173
- mp: sourceMp,
3174
- template: reValidate ? null : "",
3175
- source_ov: reValidate ? marketplaceOv : String(marketplaceOv)
3176
- }
3177
- })
3151
+ body: JSON.stringify(changes)
3178
3152
  }
3179
3153
  );
3180
3154
  }
3181
- async function fetchValidationErrors(issueFilesUrl) {
3182
- const { catalogixBaseUrl } = getApiConfig();
3183
- const params = new URLSearchParams({ excelUrl: issueFilesUrl });
3184
- return fetchJson(
3185
- `${catalogixBaseUrl}/api/v1/format-sheet-data-for-mapping?${params}`
3186
- );
3187
- }
3188
3155
  function EditableCell2({
3189
3156
  value,
3190
3157
  hasError,
@@ -3285,13 +3252,16 @@ function SubmittedSummary({
3285
3252
  submittedValues
3286
3253
  }) {
3287
3254
  const cancelled = !!submittedValues?.cancelled;
3288
- return /* @__PURE__ */ jsxs11(Card, { className: "p-4", children: [
3289
- /* @__PURE__ */ jsxs11("div", { className: "flex items-center gap-2 mb-2", children: [
3290
- cancelled ? /* @__PURE__ */ jsx22(X2, { className: "h-4 w-4 text-muted-foreground" }) : /* @__PURE__ */ jsx22(Check3, { className: "h-4 w-4 text-green-600" }),
3291
- /* @__PURE__ */ jsx22("span", { className: "font-medium text-sm", children: cancelled ? "Feed correction cancelled" : "Feed corrections validated" })
3292
- ] }),
3293
- !cancelled && !!submittedValues?.transformedUrl && /* @__PURE__ */ jsx22("p", { className: "text-xs text-muted-foreground", children: "Validation passed. Proceeding with upload." })
3294
- ] });
3255
+ return /* @__PURE__ */ jsx22("div", { className: "max-w-[50%] py-2 animate-in fade-in duration-300", children: /* @__PURE__ */ jsxs11("div", { className: cn(
3256
+ "rounded-md border p-2.5 flex items-start gap-2",
3257
+ cancelled ? "bg-muted/20 border-border" : "bg-emerald-50/50 border-emerald-200 dark:bg-muted/20 dark:border-border"
3258
+ ), children: [
3259
+ /* @__PURE__ */ jsx22("div", { className: cn("mt-px", cancelled ? "text-muted-foreground" : "text-emerald-500"), children: cancelled ? /* @__PURE__ */ jsx22(X2, { className: "w-4 h-4" }) : /* @__PURE__ */ jsx22(Check3, { className: "w-4 h-4" }) }),
3260
+ /* @__PURE__ */ jsxs11("div", { className: "flex-1 min-w-0", children: [
3261
+ /* @__PURE__ */ jsx22("p", { className: "text-xs font-medium leading-tight", children: cancelled ? "Feed correction cancelled" : "Submitted \u2014 Feed Corrections" }),
3262
+ !cancelled && !!submittedValues?.transformedUrl && /* @__PURE__ */ jsx22("p", { className: "mt-1 text-[11px] leading-snug text-muted-foreground", children: "Validation passed. Proceeding with upload." })
3263
+ ] })
3264
+ ] }) });
3295
3265
  }
3296
3266
  function EditFeed({
3297
3267
  criticalIssues: initialCriticalIssues,
@@ -3307,6 +3277,7 @@ function EditFeed({
3307
3277
  sourceMp,
3308
3278
  marketplaceOv,
3309
3279
  transformedUrl: initialTransformedUrl,
3280
+ mappingKey,
3310
3281
  submitted,
3311
3282
  submittedValues,
3312
3283
  onSubmit
@@ -3323,6 +3294,9 @@ function EditFeed({
3323
3294
  return out;
3324
3295
  })
3325
3296
  );
3297
+ const [rowNumbers, setRowNumbers] = useState8(
3298
+ () => initialRawErrorData.map((r) => Number(r.row_number ?? 0))
3299
+ );
3326
3300
  const [criticalIssues, setCriticalIssues] = useState8(initialCriticalIssues);
3327
3301
  const [dataIssuesRaw, setDataIssuesRaw] = useState8(initialDataIssuesRaw);
3328
3302
  const [columns] = useState8(
@@ -3364,77 +3338,64 @@ function EditFeed({
3364
3338
  setIsLoading(true);
3365
3339
  setErrorMsg("");
3366
3340
  try {
3367
- setStatusMsg("Building corrected CSV...");
3368
- const csvBlob = rowsToCsvBlob(rows, columns);
3369
- const fileName = `corrected_${Date.now()}.csv`;
3370
- setStatusMsg("Uploading corrected feed...");
3371
- const newFileUrl = await uploadCorrectedCsv(storeId, csvBlob, fileName);
3372
- setStatusMsg("Re-validating feed...");
3373
- const result = await validateFeed(
3374
- storeId,
3375
- newFileUrl,
3376
- feedFileType,
3377
- downloadUrl,
3378
- userId,
3379
- mappingObj,
3380
- sourceMp,
3381
- marketplaceOv,
3382
- true
3383
- );
3384
- const data = result.data;
3385
- if (data.validation) {
3386
- setStatusMsg("Validation passed!");
3387
- onSubmit(
3388
- { transformedUrl: data.transformed_url },
3389
- "Feed corrections validated successfully."
3390
- );
3341
+ const editedRowIndices = /* @__PURE__ */ new Set();
3342
+ for (const key of editedCells) {
3343
+ const idx = parseInt(key.split(":")[0], 10);
3344
+ editedRowIndices.add(idx);
3345
+ }
3346
+ if (editedRowIndices.size === 0) {
3347
+ setErrorMsg("No cells have been edited. Please fix the highlighted values first.");
3348
+ setIsLoading(false);
3391
3349
  return;
3392
3350
  }
3393
- setStatusMsg("Validation still failing \u2014 fetching new errors...");
3394
- const issueUrl = data.errors?.issue_files_url;
3395
- if (issueUrl) {
3396
- const errResp = await fetchValidationErrors(issueUrl);
3397
- const newRaw = errResp.data.raw_error_data ?? [];
3398
- const newRows = newRaw.map((r) => {
3399
- const out = {};
3400
- for (const [k, v] of Object.entries(r)) {
3401
- if (k !== "row_number") out[k] = String(v ?? "");
3351
+ const failedRows = [];
3352
+ for (const rowIdx of editedRowIndices) {
3353
+ const rowNum = rowNumbers[rowIdx];
3354
+ setStatusMsg(`Validating row ${rowIdx + 1} of ${rows.length}...`);
3355
+ const fullRowData = { ...rows[rowIdx], row_number: rowNum };
3356
+ const result = await validateRow(storeId, mappingKey, fullRowData);
3357
+ if (!result.data.validation) {
3358
+ failedRows.push({ rowIdx, errors: result.data.errors });
3359
+ }
3360
+ }
3361
+ if (failedRows.length > 0) {
3362
+ const newCritical = [];
3363
+ for (const { rowIdx, errors } of failedRows) {
3364
+ const sku = rows[rowIdx][skuField] ?? "";
3365
+ for (const err of errors) {
3366
+ if (err["Invalid Value"] || err["Invalid Attribute"]) {
3367
+ newCritical.push({
3368
+ rowNumber: rowNumbers[rowIdx],
3369
+ columnNumber: err["Column Number"] || void 0,
3370
+ skuCode: err["SKU Code"] || sku,
3371
+ errorMessage: [err["Invalid Attribute"], err["Invalid Value"]].filter(Boolean).join(": ")
3372
+ });
3373
+ }
3402
3374
  }
3403
- return out;
3404
- });
3405
- setRows(newRows);
3375
+ }
3376
+ if (newCritical.length > 0) setCriticalIssues(newCritical);
3406
3377
  setEditedCells(/* @__PURE__ */ new Set());
3407
- const newCritical = (errResp.data.critical_issues ?? []).map(
3408
- (ci) => {
3409
- let errMsgRaw = String(ci.error_message ?? "");
3410
- errMsgRaw = errMsgRaw.replace(/^[{' ]+|[}' ]+$/g, "");
3411
- return {
3412
- rowNumber: ci["Row Number"],
3413
- columnNumber: ci["Column Number"],
3414
- skuCode: String(ci["SKU Code"] ?? ""),
3415
- errorMessage: errMsgRaw
3416
- };
3417
- }
3418
- );
3419
- setCriticalIssues(newCritical);
3420
- const newDataIssues = (errResp.data.data_issues_raw ?? []).map(
3421
- (di) => ({
3422
- rowNumber: String(di["Row Number"] ?? ""),
3423
- skuCode: String(di["SKU Code"] ?? ""),
3424
- missingAttributes: String(
3425
- di["Attribute Required For Listing"] ?? ""
3426
- )
3427
- })
3428
- );
3429
- setDataIssuesRaw(newDataIssues);
3430
- setErrorMsg(
3431
- "Validation still has errors. Please fix the remaining issues and try again."
3432
- );
3433
- } else {
3434
3378
  setErrorMsg(
3435
- "Validation failed but no detailed error info was returned."
3379
+ `${failedRows.length} row(s) still have errors. Please fix the remaining issues and try again.`
3436
3380
  );
3381
+ return;
3382
+ }
3383
+ setStatusMsg("Merging corrections into feed...");
3384
+ const changes = {};
3385
+ for (const key of editedCells) {
3386
+ const [idxStr, col] = [key.split(":")[0], key.slice(key.indexOf(":") + 1)];
3387
+ const rowIdx = parseInt(idxStr, 10);
3388
+ const rowNum = String(rowNumbers[rowIdx]);
3389
+ if (!changes[rowNum]) changes[rowNum] = {};
3390
+ changes[rowNum][col] = rows[rowIdx][col] ?? "";
3437
3391
  }
3392
+ const mergeResult = await mergeFeed(transformedUrl, feedFileType, changes);
3393
+ const newFileUrl = mergeResult.data.new_file_url;
3394
+ setStatusMsg("Validation passed!");
3395
+ onSubmit(
3396
+ { transformedUrl: newFileUrl },
3397
+ "Feed corrections validated successfully."
3398
+ );
3438
3399
  } catch (err) {
3439
3400
  setErrorMsg(
3440
3401
  `Error: ${err instanceof Error ? err.message : String(err)}`
@@ -3445,17 +3406,17 @@ function EditFeed({
3445
3406
  }
3446
3407
  }, [
3447
3408
  rows,
3409
+ rowNumbers,
3448
3410
  columns,
3411
+ editedCells,
3449
3412
  storeId,
3450
3413
  feedFileType,
3451
- downloadUrl,
3452
- userId,
3453
- mappingObj,
3454
- sourceMp,
3455
- marketplaceOv,
3414
+ mappingKey,
3415
+ transformedUrl,
3416
+ skuField,
3456
3417
  onSubmit
3457
3418
  ]);
3458
- return /* @__PURE__ */ jsxs11("div", { className: "flex flex-col gap-3 h-full", children: [
3419
+ return /* @__PURE__ */ jsxs11("div", { className: "flex flex-col gap-3", children: [
3459
3420
  /* @__PURE__ */ jsx22("div", { className: "flex items-center justify-between px-1", children: /* @__PURE__ */ jsxs11("div", { className: "flex items-center gap-2", children: [
3460
3421
  /* @__PURE__ */ jsx22(AlertTriangle2, { className: "h-4 w-4 text-destructive" }),
3461
3422
  /* @__PURE__ */ jsx22("span", { className: "font-medium text-sm", children: "Feed Validation Issues" }),
@@ -3478,7 +3439,7 @@ function EditFeed({
3478
3439
  /* @__PURE__ */ jsx22(AlertTriangle2, { className: "h-3 w-3 shrink-0" }),
3479
3440
  errorMsg
3480
3441
  ] }),
3481
- /* @__PURE__ */ jsx22("div", { className: "flex-1 overflow-auto border rounded-md", children: /* @__PURE__ */ jsxs11(Table, { children: [
3442
+ /* @__PURE__ */ jsx22("div", { className: "overflow-auto border rounded-md max-h-[400px]", children: /* @__PURE__ */ jsxs11(Table, { children: [
3482
3443
  /* @__PURE__ */ jsx22(TableHeader, { className: "sticky top-0 bg-muted/80 backdrop-blur-sm z-10", children: /* @__PURE__ */ jsxs11(TableRow, { children: [
3483
3444
  /* @__PURE__ */ jsx22(TableHead, { className: "w-8 text-center", children: "#" }),
3484
3445
  columns.map((col) => /* @__PURE__ */ jsx22(TableHead, { children: col }, col))
@@ -4705,6 +4666,7 @@ function CatalogixChat(props) {
4705
4666
  sourceMp: uiProps.sourceMp ?? "SMP",
4706
4667
  marketplaceOv: uiProps.marketplaceOv ?? 34,
4707
4668
  transformedUrl: uiProps.transformedUrl ?? "",
4669
+ mappingKey: uiProps.mappingKey ?? "",
4708
4670
  submitted: props.submitted,
4709
4671
  submittedValues: props.submittedValues,
4710
4672
  onSubmit: (values, msg) => onSubmit(values, msg)
@@ -4817,7 +4779,7 @@ var catalogixManifest = [
4817
4779
  overflow: "auto",
4818
4780
  marginTop: "8px",
4819
4781
  paddingBottom: "16px",
4820
- height: "600px",
4782
+ maxHeight: "600px",
4821
4783
  position: "relative",
4822
4784
  width: "100%"
4823
4785
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamoid/catalogix-chat",
3
- "version": "0.2.19",
3
+ "version": "0.2.21",
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",