@primestyleai/tryon 5.6.20 → 5.6.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/react/index.js +51 -9
- package/package.json +1 -1
package/dist/react/index.js
CHANGED
|
@@ -325,11 +325,23 @@ function getApiUrl(override) {
|
|
|
325
325
|
return override || process.env.NEXT_PUBLIC_PRIMESTYLE_API_URL || "http://localhost:4000";
|
|
326
326
|
}
|
|
327
327
|
async function recommendForProduct(input) {
|
|
328
|
+
const log = (...args) => console.log("[ps-sdk:recommend]", ...args);
|
|
328
329
|
const profile = input.profile ?? getActiveProfile();
|
|
329
|
-
if (!profile)
|
|
330
|
+
if (!profile) {
|
|
331
|
+
log("no active profile — returning null");
|
|
332
|
+
return null;
|
|
333
|
+
}
|
|
334
|
+
log("start", {
|
|
335
|
+
productId: input.productId,
|
|
336
|
+
profileId: profile.id,
|
|
337
|
+
profileName: profile.name,
|
|
338
|
+
hasMeasurements: !!profile.measurements && Object.keys(profile.measurements || {}).length,
|
|
339
|
+
measurementsCount: Object.keys(profile.measurements || {}).length
|
|
340
|
+
});
|
|
330
341
|
if (!input.skipCache) {
|
|
331
342
|
const cached = getCachedSize(profile, input.productId);
|
|
332
343
|
if (cached) {
|
|
344
|
+
log("cache HIT", { recommendedSize: cached.recommendedSize, hasSectionsFull: !!cached.sectionsFull });
|
|
333
345
|
const reconstructedRaw = cached.sectionsFull ? {
|
|
334
346
|
recommendedSize: cached.recommendedSize,
|
|
335
347
|
confidence: cached.confidence || "high",
|
|
@@ -357,14 +369,19 @@ async function recommendForProduct(input) {
|
|
|
357
369
|
};
|
|
358
370
|
}
|
|
359
371
|
}
|
|
372
|
+
log("cache MISS — calling backend");
|
|
360
373
|
let apiKey;
|
|
361
374
|
try {
|
|
362
375
|
apiKey = input.apiKey ?? getApiKey();
|
|
363
|
-
} catch {
|
|
376
|
+
} catch (e) {
|
|
377
|
+
log("no api key — aborting", e);
|
|
364
378
|
return null;
|
|
365
379
|
}
|
|
366
380
|
const apiUrl = (input.apiUrl ?? getApiUrl()).replace(/\/+$/, "");
|
|
367
|
-
if (!apiKey)
|
|
381
|
+
if (!apiKey) {
|
|
382
|
+
log("no api key — aborting");
|
|
383
|
+
return null;
|
|
384
|
+
}
|
|
368
385
|
let sizeGuide = null;
|
|
369
386
|
if (input.sizeGuideData != null) {
|
|
370
387
|
try {
|
|
@@ -376,9 +393,17 @@ async function recommendForProduct(input) {
|
|
|
376
393
|
sizeGuideRaw: input.sizeGuideData
|
|
377
394
|
})
|
|
378
395
|
});
|
|
379
|
-
if (sgRes.ok)
|
|
380
|
-
|
|
396
|
+
if (sgRes.ok) {
|
|
397
|
+
sizeGuide = await sgRes.json();
|
|
398
|
+
log("sizeguide OK", { found: sizeGuide?.found, sectionCount: Object.keys(sizeGuide?.sections || {}).length });
|
|
399
|
+
} else {
|
|
400
|
+
log("sizeguide FAILED", sgRes.status, sgRes.statusText);
|
|
401
|
+
}
|
|
402
|
+
} catch (e) {
|
|
403
|
+
log("sizeguide threw", e);
|
|
381
404
|
}
|
|
405
|
+
} else {
|
|
406
|
+
log("no sizeGuideData provided");
|
|
382
407
|
}
|
|
383
408
|
const measurements = {
|
|
384
409
|
gender: profile.gender,
|
|
@@ -407,6 +432,7 @@ async function recommendForProduct(input) {
|
|
|
407
432
|
if (sizeGuide && sizeGuide.found) {
|
|
408
433
|
payload.sizeGuide = sizeGuide;
|
|
409
434
|
}
|
|
435
|
+
log("calling /sizing/recommend", { measurements: Object.keys(measurements), hasSizeGuide: !!payload.sizeGuide });
|
|
410
436
|
let result = null;
|
|
411
437
|
try {
|
|
412
438
|
const res = await fetch(`${apiUrl}/api/v1/sizing/recommend`, {
|
|
@@ -414,12 +440,24 @@ async function recommendForProduct(input) {
|
|
|
414
440
|
headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}` },
|
|
415
441
|
body: JSON.stringify(payload)
|
|
416
442
|
});
|
|
417
|
-
if (!res.ok)
|
|
443
|
+
if (!res.ok) {
|
|
444
|
+
log("recommend FAILED", res.status, res.statusText);
|
|
445
|
+
return null;
|
|
446
|
+
}
|
|
418
447
|
result = await res.json();
|
|
419
|
-
|
|
448
|
+
log("recommend OK", {
|
|
449
|
+
recommendedSize: result?.recommendedSize,
|
|
450
|
+
sectionKeys: result?.sections ? Object.keys(result.sections) : null,
|
|
451
|
+
sections: result?.sections
|
|
452
|
+
});
|
|
453
|
+
} catch (e) {
|
|
454
|
+
log("recommend threw", e);
|
|
455
|
+
return null;
|
|
456
|
+
}
|
|
457
|
+
if (!result || !result.recommendedSize) {
|
|
458
|
+
log("recommend returned no recommendedSize — bailing");
|
|
420
459
|
return null;
|
|
421
460
|
}
|
|
422
|
-
if (!result || !result.recommendedSize) return null;
|
|
423
461
|
const sectionsMap = result.sections ? Object.fromEntries(
|
|
424
462
|
Object.entries(result.sections).map(([name, sec]) => [name, sec.recommendedSize])
|
|
425
463
|
) : void 0;
|
|
@@ -11506,15 +11544,19 @@ function usePrimeStyleSize(input) {
|
|
|
11506
11544
|
let cancelled = false;
|
|
11507
11545
|
setLoading(true);
|
|
11508
11546
|
setNoProfile(false);
|
|
11547
|
+
console.log("[ps-sdk:hook] usePrimeStyleSize start", { productId: input.productId });
|
|
11509
11548
|
recommendForProduct(input).then((res) => {
|
|
11510
11549
|
if (cancelled) return;
|
|
11511
11550
|
if (res === null) {
|
|
11551
|
+
console.log("[ps-sdk:hook] usePrimeStyleSize → null (no profile or recommendation failed)");
|
|
11512
11552
|
setNoProfile(true);
|
|
11513
11553
|
setResult(null);
|
|
11514
11554
|
} else {
|
|
11555
|
+
console.log("[ps-sdk:hook] usePrimeStyleSize → result", { recommendedSize: res.recommendedSize, hasRaw: !!res.raw });
|
|
11515
11556
|
setResult(res);
|
|
11516
11557
|
}
|
|
11517
|
-
}).catch(() => {
|
|
11558
|
+
}).catch((e) => {
|
|
11559
|
+
console.log("[ps-sdk:hook] usePrimeStyleSize threw", e);
|
|
11518
11560
|
if (!cancelled) setResult(null);
|
|
11519
11561
|
}).finally(() => {
|
|
11520
11562
|
if (!cancelled) setLoading(false);
|