@primestyleai/tryon 5.7.6 → 5.7.8

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.
@@ -307,14 +307,6 @@ function getCachedSize(profile, productId) {
307
307
  if (profile.lastEditedAt && profile.lastEditedAt > entry.savedAt) return null;
308
308
  return entry;
309
309
  }
310
- function readEnv(key) {
311
- try {
312
- if (typeof process === "undefined" || !process || !process.env) return void 0;
313
- return process.env[key];
314
- } catch {
315
- return void 0;
316
- }
317
- }
318
310
  function detectLocale() {
319
311
  if (typeof navigator === "undefined") return "US";
320
312
  const lang = navigator.language || "";
@@ -335,12 +327,22 @@ function detectLocale() {
335
327
  return map[lang.split("-")[0].toLowerCase()] || "US";
336
328
  }
337
329
  function getApiKey() {
338
- const key = readEnv("NEXT_PUBLIC_PRIMESTYLE_API_KEY") ?? "";
330
+ let key = "";
331
+ try {
332
+ key = process.env.NEXT_PUBLIC_PRIMESTYLE_API_KEY ?? "";
333
+ } catch {
334
+ }
339
335
  if (!key) throw new PrimeStyleError("Missing NEXT_PUBLIC_PRIMESTYLE_API_KEY", "MISSING_API_KEY");
340
336
  return key;
341
337
  }
342
338
  function getApiUrl(override) {
343
- return override || readEnv("NEXT_PUBLIC_PRIMESTYLE_API_URL") || "http://localhost:4000";
339
+ if (override) return override;
340
+ let envUrl = "";
341
+ try {
342
+ envUrl = process.env.NEXT_PUBLIC_PRIMESTYLE_API_URL ?? "";
343
+ } catch {
344
+ }
345
+ return envUrl || "http://localhost:4000";
344
346
  }
345
347
  async function recommendForProduct(input) {
346
348
  const log = (...args) => console.log("[ps-sdk:recommend]", ...args);
@@ -1,3 +1,17 @@
1
1
  export declare function detectLocale(): string;
2
+ /**
3
+ * Read `process.env.NEXT_PUBLIC_PRIMESTYLE_API_KEY`.
4
+ *
5
+ * IMPORTANT: this MUST be a literal `process.env.X` access, NOT a
6
+ * dynamic property read like `process.env[key]`. Bundlers (Next.js
7
+ * SWC, Vite `define`, Webpack DefinePlugin) only perform STATIC
8
+ * replacement of literal property accesses. A dynamic access escapes
9
+ * the replacement and falls through to a runtime `process` lookup,
10
+ * which throws `ReferenceError: process is not defined` in any
11
+ * pure-browser context (Shopify storefront, etc.).
12
+ *
13
+ * The try/catch is the runtime safety net for environments that
14
+ * neither replace at build time NOR provide a `process` shim.
15
+ */
2
16
  export declare function getApiKey(): string;
3
17
  export declare function getApiUrl(override?: string): string;
@@ -9762,15 +9762,6 @@ function addSizeToHistory(profileId, entry) {
9762
9762
  saveProfiles(profiles);
9763
9763
  return profiles[idx];
9764
9764
  }
9765
- var define_process_env_default = {};
9766
- function readEnv(key) {
9767
- try {
9768
- if (typeof process === "undefined" || !process || !define_process_env_default) return void 0;
9769
- return define_process_env_default[key];
9770
- } catch {
9771
- return void 0;
9772
- }
9773
- }
9774
9765
  function detectLocale() {
9775
9766
  if (typeof navigator === "undefined") return "US";
9776
9767
  const lang = navigator.language || "";
@@ -9791,12 +9782,22 @@ function detectLocale() {
9791
9782
  return map[lang.split("-")[0].toLowerCase()] || "US";
9792
9783
  }
9793
9784
  function getApiKey() {
9794
- const key = readEnv("NEXT_PUBLIC_PRIMESTYLE_API_KEY") ?? "";
9785
+ let key = "";
9786
+ try {
9787
+ key = "shopify-proxy";
9788
+ } catch {
9789
+ }
9795
9790
  if (!key) throw new PrimeStyleError("Missing NEXT_PUBLIC_PRIMESTYLE_API_KEY", "MISSING_API_KEY");
9796
9791
  return key;
9797
9792
  }
9798
9793
  function getApiUrl(override) {
9799
- return override || readEnv("NEXT_PUBLIC_PRIMESTYLE_API_URL") || "http://localhost:4000";
9794
+ if (override) return override;
9795
+ let envUrl = "";
9796
+ try {
9797
+ envUrl = "";
9798
+ } catch {
9799
+ }
9800
+ return envUrl || "http://localhost:4000";
9800
9801
  }
9801
9802
  async function recommendForProduct(input) {
9802
9803
  const log = (...args) => console.log("[ps-sdk:recommend]", ...args);
@@ -21036,7 +21037,28 @@ function buildPropsFromDataAttrs(data) {
21036
21037
  console.log(`${TAG} built props`, props);
21037
21038
  return props;
21038
21039
  }
21039
- function mount(el2) {
21040
+ async function fetchSizeGuideForProduct(proxyUrl, productId) {
21041
+ try {
21042
+ const url = `${proxyUrl}/api/v1/sizeguide-lookup?productId=${encodeURIComponent(productId)}`;
21043
+ console.log(`${TAG} fetching size guide ${url}`);
21044
+ const res = await fetch(url, { method: "GET" });
21045
+ if (!res.ok) {
21046
+ console.warn(`${TAG} size guide lookup failed: ${res.status}`);
21047
+ return null;
21048
+ }
21049
+ const data = await res.json();
21050
+ if (data.found && data.sizeGuide) {
21051
+ console.log(`${TAG} ✓ size guide loaded for product ${productId}`, data.sizeGuide);
21052
+ return data.sizeGuide;
21053
+ }
21054
+ console.log(`${TAG} no size guide stored for product ${productId}`);
21055
+ return null;
21056
+ } catch (e) {
21057
+ console.warn(`${TAG} size guide fetch threw`, e);
21058
+ return null;
21059
+ }
21060
+ }
21061
+ async function mount(el2) {
21040
21062
  if (MOUNTED.has(el2)) {
21041
21063
  console.log(`${TAG} already mounted on`, el2);
21042
21064
  return;
@@ -21045,6 +21067,12 @@ function mount(el2) {
21045
21067
  const data = readDataAttrs(el2);
21046
21068
  console.log(`${TAG} read data attributes`, data);
21047
21069
  const props = buildPropsFromDataAttrs(data);
21070
+ if (!props.sizeGuideData && props.productId && props.apiUrl) {
21071
+ const fetched = await fetchSizeGuideForProduct(props.apiUrl, props.productId);
21072
+ if (fetched) {
21073
+ props.sizeGuideData = fetched;
21074
+ }
21075
+ }
21048
21076
  try {
21049
21077
  const root = createRoot(el2);
21050
21078
  root.render(reactExports.createElement(PrimeStyleTryon, props));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primestyleai/tryon",
3
- "version": "5.7.6",
3
+ "version": "5.7.8",
4
4
  "description": "PrimeStyle Virtual Try-On SDK — React component & Web Component",
5
5
  "type": "module",
6
6
  "main": "dist/primestyle-tryon.js",