@thefittingroom/shop-ui 1.1.8 → 1.1.10

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.
@@ -4,6 +4,7 @@ export type RecommendedSize = {
4
4
  size: string;
5
5
  locations: {
6
6
  fit: string;
7
+ isPerfect: boolean;
7
8
  location: string;
8
9
  }[];
9
10
  }[];
package/dist/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * thefittingroom v1.1.8 (2024-05-16T03:17:08.880Z)
2
+ * thefittingroom v1.1.10 (2024-05-17T17:05:22.690Z)
3
3
  * Copyright 2022-present, TheFittingRoom, Inc. All rights reserved.
4
4
  */
5
5
  function loadImageRecursive(imageURL, imageURLs) {
@@ -47,7 +47,7 @@ const InitImageSlider = (sliderID, onChange) => {
47
47
  };
48
48
 
49
49
  /*!
50
- * thefittingroom v1.1.5 (2024-05-16T02:24:56.143Z)
50
+ * thefittingroom v1.1.7 (2024-05-16T23:59:30.970Z)
51
51
  * Copyright 2022-present, TheFittingRoom, Inc. All rights reserved.
52
52
  */
53
53
 
@@ -22903,6 +22903,172 @@ const getFirebaseError = (e) => {
22903
22903
  }
22904
22904
  };
22905
22905
 
22906
+ class Fetcher {
22907
+ static get endpoint() {
22908
+ const api = Config.getInstance().api;
22909
+ return api.url;
22910
+ }
22911
+ static async Fetch({ user, endpointPath, method, body, useToken = true }) {
22912
+ const url = this.getUrl(endpointPath, useToken);
22913
+ const headers = await this.getHeaders(user, useToken);
22914
+ const config = { method, headers, credentials: 'include' };
22915
+ if (body)
22916
+ config.body = JSON.stringify(body);
22917
+ const res = await fetch(url, config);
22918
+ if (res.ok)
22919
+ return res;
22920
+ if (res.status === 500)
22921
+ throw new Error(res.statusText);
22922
+ const json = await res.json();
22923
+ return Promise.reject(json);
22924
+ }
22925
+ static getUrl(endpointPath, useToken) {
22926
+ return useToken ? `${this.endpoint}/v1${endpointPath}` : this.endpoint + endpointPath;
22927
+ }
22928
+ static async getHeaders(user, useToken) {
22929
+ if (!useToken)
22930
+ return { 'Content-Type': 'application/json' };
22931
+ const token = await user.getToken();
22932
+ return {
22933
+ 'Content-Type': 'application/json',
22934
+ Authorization: `Bearer ${token}`,
22935
+ };
22936
+ }
22937
+ static Get(user, endpointPath, useToken) {
22938
+ return this.Fetch({ user, endpointPath, method: 'GET', body: null, useToken });
22939
+ }
22940
+ static Post(user, endpointPath, body = null, useToken) {
22941
+ return this.Fetch({ user, endpointPath, method: 'POST', body, useToken });
22942
+ }
22943
+ static Put(user, endpointPath, body, useToken) {
22944
+ return this.Fetch({ user, endpointPath, method: 'PUT', body, useToken });
22945
+ }
22946
+ static Patch(user, endpointPath, body, useToken) {
22947
+ return this.Fetch({ user, endpointPath, method: 'PATCH', body, useToken });
22948
+ }
22949
+ static Delete(user, endpointPath, body, useToken) {
22950
+ return this.Fetch({ user, endpointPath, method: 'DELETE', body, useToken });
22951
+ }
22952
+ }
22953
+
22954
+ class TfrShop {
22955
+ constructor(brandId, firebase) {
22956
+ this.brandId = brandId;
22957
+ this.firebase = firebase;
22958
+ this.measurementLocations = new Map();
22959
+ }
22960
+ get user() {
22961
+ return this.firebase.user;
22962
+ }
22963
+ get isLoggedIn() {
22964
+ return !this.firebase || Boolean(this.user.id);
22965
+ }
22966
+ async onInit() {
22967
+ await this.getMeasurementLocations();
22968
+ return this.firebase.onInit();
22969
+ }
22970
+ async getRecommendedSizes(styleId) {
22971
+ var _a, _b;
22972
+ if (!this.isLoggedIn)
22973
+ throw new UserNotLoggedInError();
22974
+ try {
22975
+ const res = await Fetcher.Get(this.user, `/styles/${styleId}/recommendation`);
22976
+ const data = (await res.json());
22977
+ if (!((_a = data === null || data === void 0 ? void 0 : data.fits) === null || _a === void 0 ? void 0 : _a.length) || !((_b = data === null || data === void 0 ? void 0 : data.recommended_size) === null || _b === void 0 ? void 0 : _b.id))
22978
+ return null;
22979
+ return data;
22980
+ }
22981
+ catch (error) {
22982
+ if ((error === null || error === void 0 ? void 0 : error.error) === AvatarNotCreated)
22983
+ throw new AvatarNotCreatedError();
22984
+ throw error;
22985
+ }
22986
+ }
22987
+ async submitTelephoneNumber(tel) {
22988
+ const sanitizedTel = tel.replace(/[^\+0-9]/g, '');
22989
+ const res = await Fetcher.Post(this.user, '/ios-app-link', { phone_number: sanitizedTel }, false);
22990
+ console.log(res);
22991
+ }
22992
+ async getColorwaySizeAssetFromSku(colorwaySizeAssetSku) {
22993
+ const assets = await this.getColorwaySizeAssets(null, [colorwaySizeAssetSku]);
22994
+ if (!(assets === null || assets === void 0 ? void 0 : assets.size))
22995
+ throw new NoColorwaySizeAssetsFoundError();
22996
+ return Array.from(assets.values())[0];
22997
+ }
22998
+ async getMeasurementLocationsFromSku(sku) {
22999
+ const asset = await this.getColorwaySizeAssetFromSku(sku);
23000
+ if (!asset)
23001
+ throw new Error('No colorway size asset found for sku');
23002
+ const styleCategory = await this.getStyleCategory(asset.style_id);
23003
+ if (!styleCategory)
23004
+ throw new Error('Style category not found for style id');
23005
+ const taxonomy = await this.getGetTaxonomy(styleCategory.style_garment_category_id);
23006
+ if (!taxonomy)
23007
+ throw new Error('Taxonomy not found for style garment category id');
23008
+ return taxonomy.garment_measurement_locations.female.map((location) => {
23009
+ return this.measurementLocations.has(location) ? this.measurementLocations.get(location) : location;
23010
+ });
23011
+ }
23012
+ async getColorwaySizeAssets(styleId, skus) {
23013
+ const constraints = [rl('brand_id', '==', this.brandId)];
23014
+ if (styleId)
23015
+ constraints.push(rl('style_id', '==', styleId));
23016
+ if ((skus === null || skus === void 0 ? void 0 : skus.length) > 0)
23017
+ constraints.push(rl('sku', 'in', skus));
23018
+ try {
23019
+ const querySnapshot = await this.firebase.getDocs('colorway_size_assets', constraints);
23020
+ const colorwaySizeAssets = new Map();
23021
+ querySnapshot.forEach((doc) => {
23022
+ const colorwaySizeAsset = doc.data();
23023
+ colorwaySizeAssets.set(colorwaySizeAsset.id, colorwaySizeAsset);
23024
+ });
23025
+ return colorwaySizeAssets;
23026
+ }
23027
+ catch (error) {
23028
+ return getFirebaseError(error);
23029
+ }
23030
+ }
23031
+ async getStyleCategory(styleId) {
23032
+ try {
23033
+ const doc = await this.firebase.getDoc('styles', String(styleId));
23034
+ return doc;
23035
+ }
23036
+ catch (error) {
23037
+ return getFirebaseError(error);
23038
+ }
23039
+ }
23040
+ async getGetTaxonomy(styleId) {
23041
+ try {
23042
+ const doc = await this.firebase.getDoc('style_garment_categories', String(styleId));
23043
+ return doc;
23044
+ }
23045
+ catch (error) {
23046
+ return getFirebaseError(error);
23047
+ }
23048
+ }
23049
+ async getMeasurementLocations() {
23050
+ const locations = await this.fetchMeasurementLocations();
23051
+ locations.forEach((location) => {
23052
+ this.measurementLocations.set(location.name, location.label);
23053
+ });
23054
+ }
23055
+ async fetchMeasurementLocations() {
23056
+ try {
23057
+ const docs = await this.firebase.getDocs('garment_measurement_locations', []);
23058
+ return docs.docs.map((doc) => doc.data());
23059
+ }
23060
+ catch (error) {
23061
+ return getFirebaseError(error);
23062
+ }
23063
+ }
23064
+ }
23065
+ const initShop = (brandId, env = 'dev') => {
23066
+ if (env === 'dev' || env === 'development')
23067
+ console.warn('TfrShop is in development mode');
23068
+ Config.getInstance().setEnv(env);
23069
+ return new TfrShop(brandId, new Firebase());
23070
+ };
23071
+
22906
23072
  var MeasurementLocation;
22907
23073
  (function (MeasurementLocation) {
22908
23074
  MeasurementLocation["ACROSS_BACK"] = "across_back";
@@ -23257,6 +23423,12 @@ var Fit;
23257
23423
  Fit["SLIGHTLY_LOOSE"] = "slightly_loose";
23258
23424
  Fit["LOOSE"] = "loose";
23259
23425
  Fit["OVERSIZED"] = "oversized";
23426
+ Fit["TOO_SHORT"] = "too_short";
23427
+ Fit["SHORT"] = "short";
23428
+ Fit["SLIGHTLY_SHORT"] = "slightly_short";
23429
+ Fit["SLIGHTLY_LONG"] = "slightly_long";
23430
+ Fit["LONG"] = "long";
23431
+ Fit["TOO_LONG"] = "too_long";
23260
23432
  })(Fit || (Fit = {}));
23261
23433
  const FitNames = {
23262
23434
  [Fit.TOO_TIGHT]: 'Too Tight',
@@ -23266,151 +23438,12 @@ const FitNames = {
23266
23438
  [Fit.SLIGHTLY_LOOSE]: 'Slightly Loose',
23267
23439
  [Fit.LOOSE]: 'Loose',
23268
23440
  [Fit.OVERSIZED]: 'Oversized',
23269
- };
23270
-
23271
- class Fetcher {
23272
- static get endpoint() {
23273
- const api = Config.getInstance().api;
23274
- return api.url;
23275
- }
23276
- static async Fetch({ user, endpointPath, method, body, useToken = true }) {
23277
- const url = this.getUrl(endpointPath, useToken);
23278
- const headers = await this.getHeaders(user, useToken);
23279
- const config = { method, headers, credentials: 'include' };
23280
- if (body)
23281
- config.body = JSON.stringify(body);
23282
- const res = await fetch(url, config);
23283
- if (res.ok)
23284
- return res;
23285
- if (res.status === 500)
23286
- throw new Error(res.statusText);
23287
- const json = await res.json();
23288
- return Promise.reject(json);
23289
- }
23290
- static getUrl(endpointPath, useToken) {
23291
- return useToken ? `${this.endpoint}/v1${endpointPath}` : this.endpoint + endpointPath;
23292
- }
23293
- static async getHeaders(user, useToken) {
23294
- if (!useToken)
23295
- return { 'Content-Type': 'application/json' };
23296
- const token = await user.getToken();
23297
- return {
23298
- 'Content-Type': 'application/json',
23299
- Authorization: `Bearer ${token}`,
23300
- };
23301
- }
23302
- static Get(user, endpointPath, useToken) {
23303
- return this.Fetch({ user, endpointPath, method: 'GET', body: null, useToken });
23304
- }
23305
- static Post(user, endpointPath, body = null, useToken) {
23306
- return this.Fetch({ user, endpointPath, method: 'POST', body, useToken });
23307
- }
23308
- static Put(user, endpointPath, body, useToken) {
23309
- return this.Fetch({ user, endpointPath, method: 'PUT', body, useToken });
23310
- }
23311
- static Patch(user, endpointPath, body, useToken) {
23312
- return this.Fetch({ user, endpointPath, method: 'PATCH', body, useToken });
23313
- }
23314
- static Delete(user, endpointPath, body, useToken) {
23315
- return this.Fetch({ user, endpointPath, method: 'DELETE', body, useToken });
23316
- }
23317
- }
23318
-
23319
- class TfrShop {
23320
- constructor(brandId, firebase) {
23321
- this.brandId = brandId;
23322
- this.firebase = firebase;
23323
- }
23324
- get user() {
23325
- return this.firebase.user;
23326
- }
23327
- get isLoggedIn() {
23328
- return !this.firebase || Boolean(this.user.id);
23329
- }
23330
- onInit() {
23331
- return this.firebase.onInit();
23332
- }
23333
- async getRecommendedSizes(styleId) {
23334
- var _a, _b;
23335
- if (!this.isLoggedIn)
23336
- throw new UserNotLoggedInError();
23337
- try {
23338
- const res = await Fetcher.Get(this.user, `/styles/${styleId}/recommendation`);
23339
- const data = (await res.json());
23340
- if (!((_a = data === null || data === void 0 ? void 0 : data.fits) === null || _a === void 0 ? void 0 : _a.length) || !((_b = data === null || data === void 0 ? void 0 : data.recommended_size) === null || _b === void 0 ? void 0 : _b.id))
23341
- return null;
23342
- return data;
23343
- }
23344
- catch (error) {
23345
- if ((error === null || error === void 0 ? void 0 : error.error) === AvatarNotCreated)
23346
- throw new AvatarNotCreatedError();
23347
- throw error;
23348
- }
23349
- }
23350
- async submitTelephoneNumber(tel) {
23351
- const sanitizedTel = tel.replace(/[^\+0-9]/g, '');
23352
- const res = await Fetcher.Post(this.user, '/ios-app-link', { phone_number: sanitizedTel }, false);
23353
- console.log(res);
23354
- }
23355
- async getColorwaySizeAssetFromSku(colorwaySizeAssetSku) {
23356
- const assets = await this.getColorwaySizeAssets(null, [colorwaySizeAssetSku]);
23357
- if (!(assets === null || assets === void 0 ? void 0 : assets.size))
23358
- throw new NoColorwaySizeAssetsFoundError();
23359
- return Array.from(assets.values())[0];
23360
- }
23361
- async getMeasurementLocationsFromSku(sku) {
23362
- var _a;
23363
- const asset = await this.getColorwaySizeAssetFromSku(sku);
23364
- const styleCategory = await this.getStyleCategory(asset.style_id);
23365
- const taxonomy = await this.getGetTaxonomy(styleCategory.style_garment_category_id);
23366
- const classificationLocation = ((_a = Taxonomy[taxonomy.style_category]) === null || _a === void 0 ? void 0 : _a[taxonomy.garment_category]) || null;
23367
- return classificationLocation
23368
- ? ClassificationLocations[classificationLocation].map((location) => MeasurementLocationName[location])
23369
- : null;
23370
- }
23371
- async getColorwaySizeAssets(styleId, skus) {
23372
- const constraints = [rl('brand_id', '==', this.brandId)];
23373
- if (styleId)
23374
- constraints.push(rl('style_id', '==', styleId));
23375
- if ((skus === null || skus === void 0 ? void 0 : skus.length) > 0)
23376
- constraints.push(rl('sku', 'in', skus));
23377
- try {
23378
- const querySnapshot = await this.firebase.getDocs('colorway_size_assets', constraints);
23379
- const colorwaySizeAssets = new Map();
23380
- querySnapshot.forEach((doc) => {
23381
- const colorwaySizeAsset = doc.data();
23382
- colorwaySizeAssets.set(colorwaySizeAsset.id, colorwaySizeAsset);
23383
- });
23384
- return colorwaySizeAssets;
23385
- }
23386
- catch (error) {
23387
- return getFirebaseError(error);
23388
- }
23389
- }
23390
- async getStyleCategory(styleId) {
23391
- try {
23392
- const doc = await this.firebase.getDoc('styles', String(styleId));
23393
- return doc;
23394
- }
23395
- catch (error) {
23396
- return getFirebaseError(error);
23397
- }
23398
- }
23399
- async getGetTaxonomy(styleId) {
23400
- try {
23401
- const doc = await this.firebase.getDoc('style_garment_categories', String(styleId));
23402
- return doc;
23403
- }
23404
- catch (error) {
23405
- return getFirebaseError(error);
23406
- }
23407
- }
23408
- }
23409
- const initShop = (brandId, env = 'dev') => {
23410
- if (env === 'dev' || env === 'development')
23411
- console.warn('TfrShop is in development mode');
23412
- Config.getInstance().setEnv(env);
23413
- return new TfrShop(brandId, new Firebase());
23441
+ [Fit.TOO_SHORT]: 'Too Short',
23442
+ [Fit.SHORT]: 'Short',
23443
+ [Fit.SLIGHTLY_SHORT]: 'Slightly Short',
23444
+ [Fit.SLIGHTLY_LONG]: 'Slightly Long',
23445
+ [Fit.LONG]: 'Long',
23446
+ [Fit.TOO_LONG]: 'Too Long',
23414
23447
  };
23415
23448
 
23416
23449
  var AvatarState$1;
@@ -36542,7 +36575,7 @@ class SizeRecComponent {
36542
36575
  const { locations } = sizes[index];
36543
36576
  const html = locations
36544
36577
  .sort(({ location: a }, { location: b }) => (a < b ? -1 : 1))
36545
- .map(({ location, fit }) => this.renderSizeRecTableRow(location, fit))
36578
+ .map(({ location, fit, isPerfect }) => this.renderSizeRecTableRow(location, fit, isPerfect))
36546
36579
  .join('');
36547
36580
  this.tfrSizeRecTable.innerHTML = html;
36548
36581
  }
@@ -36553,10 +36586,10 @@ class SizeRecComponent {
36553
36586
  .join('');
36554
36587
  this.tfrSizeRecSelect.innerHTML = html;
36555
36588
  }
36556
- renderSizeRecTableRow(location, fit) {
36589
+ renderSizeRecTableRow(location, fit, isPerfect = false) {
36557
36590
  return `<div class="tfr-size-rec-table-row">
36558
36591
  <div class="tfr-size-rec-table-cell-left">${location}</div>
36559
- <div class="tfr-size-rec-table-cell-right ${fit === 'Perfect Fit' ? 'perfect' : ''}">
36592
+ <div class="tfr-size-rec-table-cell-right ${isPerfect ? 'perfect' : ''}">
36560
36593
  ${fit}
36561
36594
  </div>
36562
36595
  </div>`;
@@ -36621,6 +36654,7 @@ class TfrSizeRec {
36621
36654
  this.tfrShop = tfrShop;
36622
36655
  this.onSignInClick = onSignInClick;
36623
36656
  this.onSignOutClick = onSignOutClick;
36657
+ this.perfectFits = [index.Fit.PERFECT_FIT, index.Fit.SLIGHTLY_LOOSE, index.Fit.SLIGHTLY_TIGHT];
36624
36658
  this.sizeRecComponent = new SizeRecComponent(sizeRecMainDivId, this.onSignInClick, this.onSignOutClick);
36625
36659
  }
36626
36660
  get sku() {
@@ -36686,6 +36720,7 @@ class TfrSizeRec {
36686
36720
  locations: fit.measurement_location_fits.map((locationFit) => {
36687
36721
  return {
36688
36722
  fit: index.FitNames[locationFit.fit],
36723
+ isPerfect: this.perfectFits.includes(locationFit.fit),
36689
36724
  location: index.MeasurementLocationName[locationFit.measurement_location],
36690
36725
  };
36691
36726
  }),