@thefittingroom/sdk 1.1.6 → 1.1.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.
@@ -1,4 +1,4 @@
1
- import { Fit, MeasurementLocation } from '../types/measurement';
1
+ import { Fit } from '../types/measurement';
2
2
  export interface BodyMeasurement {
3
3
  id: number;
4
4
  position: number;
@@ -67,7 +67,7 @@ export interface SizeRecommendationIDs {
67
67
  available_size_ids: number[];
68
68
  }
69
69
  export interface MeasurementLocationFits {
70
- measurement_location: MeasurementLocation;
70
+ measurement_location: string;
71
71
  fit: Fit;
72
72
  }
73
73
  export interface Fits {
@@ -4,6 +4,7 @@ import { SizeRecommendation } from './responses';
4
4
  export declare class TfrShop {
5
5
  private readonly brandId;
6
6
  private readonly firebase;
7
+ private measurementLocations;
7
8
  constructor(brandId: number, firebase: Firebase);
8
9
  get user(): import("..").FirebaseUser;
9
10
  get isLoggedIn(): boolean;
@@ -13,7 +14,9 @@ export declare class TfrShop {
13
14
  getColorwaySizeAssetFromSku(colorwaySizeAssetSku: string): Promise<types.FirestoreColorwaySizeAsset>;
14
15
  getMeasurementLocationsFromSku(sku: string): Promise<string[]>;
15
16
  private getColorwaySizeAssets;
16
- private getStyleCategory;
17
+ getStyle(styleId: number): Promise<types.FirestoreStyleCategory>;
17
18
  private getGetTaxonomy;
19
+ private getMeasurementLocations;
20
+ private fetchMeasurementLocations;
18
21
  }
19
22
  export declare const initShop: (brandId: number, env?: string) => TfrShop;
package/dist/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * thefittingroom v1.1.6 (2024-05-16T02:58:10.847Z)
2
+ * thefittingroom v1.1.8 (2024-06-20T17:59:34.232Z)
3
3
  * Copyright 2022-present, TheFittingRoom, Inc. All rights reserved.
4
4
  */
5
5
  // Code generated by tygo. DO NOT EDIT.
@@ -22872,6 +22872,172 @@ const getFirebaseError = (e) => {
22872
22872
  }
22873
22873
  };
22874
22874
 
22875
+ class Fetcher {
22876
+ static get endpoint() {
22877
+ const api = Config.getInstance().api;
22878
+ return api.url;
22879
+ }
22880
+ static async Fetch({ user, endpointPath, method, body, useToken = true }) {
22881
+ const url = this.getUrl(endpointPath, useToken);
22882
+ const headers = await this.getHeaders(user, useToken);
22883
+ const config = { method, headers, credentials: 'include' };
22884
+ if (body)
22885
+ config.body = JSON.stringify(body);
22886
+ const res = await fetch(url, config);
22887
+ if (res.ok)
22888
+ return res;
22889
+ if (res.status === 500)
22890
+ throw new Error(res.statusText);
22891
+ const json = await res.json();
22892
+ return Promise.reject(json);
22893
+ }
22894
+ static getUrl(endpointPath, useToken) {
22895
+ return useToken ? `${this.endpoint}/v1${endpointPath}` : this.endpoint + endpointPath;
22896
+ }
22897
+ static async getHeaders(user, useToken) {
22898
+ if (!useToken)
22899
+ return { 'Content-Type': 'application/json' };
22900
+ const token = await user.getToken();
22901
+ return {
22902
+ 'Content-Type': 'application/json',
22903
+ Authorization: `Bearer ${token}`,
22904
+ };
22905
+ }
22906
+ static Get(user, endpointPath, useToken) {
22907
+ return this.Fetch({ user, endpointPath, method: 'GET', body: null, useToken });
22908
+ }
22909
+ static Post(user, endpointPath, body = null, useToken) {
22910
+ return this.Fetch({ user, endpointPath, method: 'POST', body, useToken });
22911
+ }
22912
+ static Put(user, endpointPath, body, useToken) {
22913
+ return this.Fetch({ user, endpointPath, method: 'PUT', body, useToken });
22914
+ }
22915
+ static Patch(user, endpointPath, body, useToken) {
22916
+ return this.Fetch({ user, endpointPath, method: 'PATCH', body, useToken });
22917
+ }
22918
+ static Delete(user, endpointPath, body, useToken) {
22919
+ return this.Fetch({ user, endpointPath, method: 'DELETE', body, useToken });
22920
+ }
22921
+ }
22922
+
22923
+ class TfrShop {
22924
+ constructor(brandId, firebase) {
22925
+ this.brandId = brandId;
22926
+ this.firebase = firebase;
22927
+ this.measurementLocations = new Map();
22928
+ }
22929
+ get user() {
22930
+ return this.firebase.user;
22931
+ }
22932
+ get isLoggedIn() {
22933
+ return !this.firebase || Boolean(this.user.id);
22934
+ }
22935
+ async onInit() {
22936
+ await this.getMeasurementLocations();
22937
+ return this.firebase.onInit();
22938
+ }
22939
+ async getRecommendedSizes(styleId) {
22940
+ var _a, _b;
22941
+ if (!this.isLoggedIn)
22942
+ throw new UserNotLoggedInError();
22943
+ try {
22944
+ const res = await Fetcher.Get(this.user, `/styles/${styleId}/recommendation`);
22945
+ const data = (await res.json());
22946
+ 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))
22947
+ return null;
22948
+ return data;
22949
+ }
22950
+ catch (error) {
22951
+ if ((error === null || error === void 0 ? void 0 : error.error) === AvatarNotCreated)
22952
+ throw new AvatarNotCreatedError();
22953
+ throw error;
22954
+ }
22955
+ }
22956
+ async submitTelephoneNumber(tel) {
22957
+ const sanitizedTel = tel.replace(/[^\+0-9]/g, '');
22958
+ const res = await Fetcher.Post(this.user, '/ios-app-link', { phone_number: sanitizedTel }, false);
22959
+ console.log(res);
22960
+ }
22961
+ async getColorwaySizeAssetFromSku(colorwaySizeAssetSku) {
22962
+ const assets = await this.getColorwaySizeAssets(null, [colorwaySizeAssetSku]);
22963
+ if (!(assets === null || assets === void 0 ? void 0 : assets.size))
22964
+ throw new NoColorwaySizeAssetsFoundError();
22965
+ return Array.from(assets.values())[0];
22966
+ }
22967
+ async getMeasurementLocationsFromSku(sku) {
22968
+ const asset = await this.getColorwaySizeAssetFromSku(sku);
22969
+ if (!asset)
22970
+ throw new Error('No colorway size asset found for sku');
22971
+ const styleCategory = await this.getStyle(asset.style_id);
22972
+ if (!styleCategory)
22973
+ throw new Error('Style category not found for style id');
22974
+ const taxonomy = await this.getGetTaxonomy(styleCategory.style_garment_category_id);
22975
+ if (!taxonomy)
22976
+ throw new Error('Taxonomy not found for style garment category id');
22977
+ return taxonomy.garment_measurement_locations.female.map((location) => {
22978
+ return this.measurementLocations.has(location) ? this.measurementLocations.get(location) : location;
22979
+ });
22980
+ }
22981
+ async getColorwaySizeAssets(styleId, skus) {
22982
+ const constraints = [rl('brand_id', '==', this.brandId)];
22983
+ if (styleId)
22984
+ constraints.push(rl('style_id', '==', styleId));
22985
+ if ((skus === null || skus === void 0 ? void 0 : skus.length) > 0)
22986
+ constraints.push(rl('sku', 'in', skus));
22987
+ try {
22988
+ const querySnapshot = await this.firebase.getDocs('colorway_size_assets', constraints);
22989
+ const colorwaySizeAssets = new Map();
22990
+ querySnapshot.forEach((doc) => {
22991
+ const colorwaySizeAsset = doc.data();
22992
+ colorwaySizeAssets.set(colorwaySizeAsset.id, colorwaySizeAsset);
22993
+ });
22994
+ return colorwaySizeAssets;
22995
+ }
22996
+ catch (error) {
22997
+ return getFirebaseError(error);
22998
+ }
22999
+ }
23000
+ async getStyle(styleId) {
23001
+ try {
23002
+ const doc = await this.firebase.getDoc('styles', String(styleId));
23003
+ return doc;
23004
+ }
23005
+ catch (error) {
23006
+ return getFirebaseError(error);
23007
+ }
23008
+ }
23009
+ async getGetTaxonomy(styleId) {
23010
+ try {
23011
+ const doc = await this.firebase.getDoc('style_garment_categories', String(styleId));
23012
+ return doc;
23013
+ }
23014
+ catch (error) {
23015
+ return getFirebaseError(error);
23016
+ }
23017
+ }
23018
+ async getMeasurementLocations() {
23019
+ const locations = await this.fetchMeasurementLocations();
23020
+ locations.forEach((location) => {
23021
+ this.measurementLocations.set(location.name, location.label);
23022
+ });
23023
+ }
23024
+ async fetchMeasurementLocations() {
23025
+ try {
23026
+ const docs = await this.firebase.getDocs('garment_measurement_locations', []);
23027
+ return docs.docs.map((doc) => doc.data());
23028
+ }
23029
+ catch (error) {
23030
+ return getFirebaseError(error);
23031
+ }
23032
+ }
23033
+ }
23034
+ const initShop = (brandId, env = 'dev') => {
23035
+ if (env === 'dev' || env === 'development')
23036
+ console.warn('TfrShop is in development mode');
23037
+ Config.getInstance().setEnv(env);
23038
+ return new TfrShop(brandId, new Firebase());
23039
+ };
23040
+
22875
23041
  var MeasurementLocation;
22876
23042
  (function (MeasurementLocation) {
22877
23043
  MeasurementLocation["ACROSS_BACK"] = "across_back";
@@ -23226,6 +23392,12 @@ var Fit;
23226
23392
  Fit["SLIGHTLY_LOOSE"] = "slightly_loose";
23227
23393
  Fit["LOOSE"] = "loose";
23228
23394
  Fit["OVERSIZED"] = "oversized";
23395
+ Fit["TOO_SHORT"] = "too_short";
23396
+ Fit["SHORT"] = "short";
23397
+ Fit["SLIGHTLY_SHORT"] = "slightly_short";
23398
+ Fit["SLIGHTLY_LONG"] = "slightly_long";
23399
+ Fit["LONG"] = "long";
23400
+ Fit["TOO_LONG"] = "too_long";
23229
23401
  })(Fit || (Fit = {}));
23230
23402
  const FitNames = {
23231
23403
  [Fit.TOO_TIGHT]: 'Too Tight',
@@ -23235,157 +23407,12 @@ const FitNames = {
23235
23407
  [Fit.SLIGHTLY_LOOSE]: 'Slightly Loose',
23236
23408
  [Fit.LOOSE]: 'Loose',
23237
23409
  [Fit.OVERSIZED]: 'Oversized',
23238
- };
23239
-
23240
- class Fetcher {
23241
- static get endpoint() {
23242
- const api = Config.getInstance().api;
23243
- return api.url;
23244
- }
23245
- static async Fetch({ user, endpointPath, method, body, useToken = true }) {
23246
- const url = this.getUrl(endpointPath, useToken);
23247
- const headers = await this.getHeaders(user, useToken);
23248
- const config = { method, headers, credentials: 'include' };
23249
- if (body)
23250
- config.body = JSON.stringify(body);
23251
- const res = await fetch(url, config);
23252
- if (res.ok)
23253
- return res;
23254
- if (res.status === 500)
23255
- throw new Error(res.statusText);
23256
- const json = await res.json();
23257
- return Promise.reject(json);
23258
- }
23259
- static getUrl(endpointPath, useToken) {
23260
- return useToken ? `${this.endpoint}/v1${endpointPath}` : this.endpoint + endpointPath;
23261
- }
23262
- static async getHeaders(user, useToken) {
23263
- if (!useToken)
23264
- return { 'Content-Type': 'application/json' };
23265
- const token = await user.getToken();
23266
- return {
23267
- 'Content-Type': 'application/json',
23268
- Authorization: `Bearer ${token}`,
23269
- };
23270
- }
23271
- static Get(user, endpointPath, useToken) {
23272
- return this.Fetch({ user, endpointPath, method: 'GET', body: null, useToken });
23273
- }
23274
- static Post(user, endpointPath, body = null, useToken) {
23275
- return this.Fetch({ user, endpointPath, method: 'POST', body, useToken });
23276
- }
23277
- static Put(user, endpointPath, body, useToken) {
23278
- return this.Fetch({ user, endpointPath, method: 'PUT', body, useToken });
23279
- }
23280
- static Patch(user, endpointPath, body, useToken) {
23281
- return this.Fetch({ user, endpointPath, method: 'PATCH', body, useToken });
23282
- }
23283
- static Delete(user, endpointPath, body, useToken) {
23284
- return this.Fetch({ user, endpointPath, method: 'DELETE', body, useToken });
23285
- }
23286
- }
23287
-
23288
- class TfrShop {
23289
- constructor(brandId, firebase) {
23290
- this.brandId = brandId;
23291
- this.firebase = firebase;
23292
- }
23293
- get user() {
23294
- return this.firebase.user;
23295
- }
23296
- get isLoggedIn() {
23297
- return !this.firebase || Boolean(this.user.id);
23298
- }
23299
- onInit() {
23300
- return this.firebase.onInit();
23301
- }
23302
- async getRecommendedSizes(styleId) {
23303
- var _a, _b;
23304
- if (!this.isLoggedIn)
23305
- throw new UserNotLoggedInError();
23306
- try {
23307
- const res = await Fetcher.Get(this.user, `/styles/${styleId}/recommendation`);
23308
- const data = (await res.json());
23309
- 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))
23310
- return null;
23311
- return data;
23312
- }
23313
- catch (error) {
23314
- if ((error === null || error === void 0 ? void 0 : error.error) === AvatarNotCreated)
23315
- throw new AvatarNotCreatedError();
23316
- throw error;
23317
- }
23318
- }
23319
- async submitTelephoneNumber(tel) {
23320
- const sanitizedTel = tel.replace(/[^\+0-9]/g, '');
23321
- const res = await Fetcher.Post(this.user, '/ios-app-link', { phone_number: sanitizedTel }, false);
23322
- console.log(res);
23323
- }
23324
- async getColorwaySizeAssetFromSku(colorwaySizeAssetSku) {
23325
- const assets = await this.getColorwaySizeAssets(null, [colorwaySizeAssetSku]);
23326
- if (!(assets === null || assets === void 0 ? void 0 : assets.size))
23327
- throw new NoColorwaySizeAssetsFoundError();
23328
- return Array.from(assets.values())[0];
23329
- }
23330
- async getMeasurementLocationsFromSku(sku) {
23331
- var _a;
23332
- const asset = await this.getColorwaySizeAssetFromSku(sku);
23333
- if (!asset)
23334
- throw new Error('No colorway size asset found for sku');
23335
- const styleCategory = await this.getStyleCategory(asset.style_id);
23336
- if (!styleCategory)
23337
- throw new Error('Style category not found for style id');
23338
- const taxonomy = await this.getGetTaxonomy(styleCategory.style_garment_category_id);
23339
- if (!taxonomy)
23340
- throw new Error('Taxonomy not found for style garment category id');
23341
- const classificationLocation = ((_a = Taxonomy[taxonomy.style_category]) === null || _a === void 0 ? void 0 : _a[taxonomy.garment_category]) || null;
23342
- return classificationLocation
23343
- ? ClassificationLocations[classificationLocation].map((location) => MeasurementLocationName[location])
23344
- : null;
23345
- }
23346
- async getColorwaySizeAssets(styleId, skus) {
23347
- const constraints = [rl('brand_id', '==', this.brandId)];
23348
- if (styleId)
23349
- constraints.push(rl('style_id', '==', styleId));
23350
- if ((skus === null || skus === void 0 ? void 0 : skus.length) > 0)
23351
- constraints.push(rl('sku', 'in', skus));
23352
- try {
23353
- const querySnapshot = await this.firebase.getDocs('colorway_size_assets', constraints);
23354
- const colorwaySizeAssets = new Map();
23355
- querySnapshot.forEach((doc) => {
23356
- const colorwaySizeAsset = doc.data();
23357
- colorwaySizeAssets.set(colorwaySizeAsset.id, colorwaySizeAsset);
23358
- });
23359
- return colorwaySizeAssets;
23360
- }
23361
- catch (error) {
23362
- return getFirebaseError(error);
23363
- }
23364
- }
23365
- async getStyleCategory(styleId) {
23366
- try {
23367
- const doc = await this.firebase.getDoc('styles', String(styleId));
23368
- return doc;
23369
- }
23370
- catch (error) {
23371
- return getFirebaseError(error);
23372
- }
23373
- }
23374
- async getGetTaxonomy(styleId) {
23375
- try {
23376
- const doc = await this.firebase.getDoc('style_garment_categories', String(styleId));
23377
- return doc;
23378
- }
23379
- catch (error) {
23380
- return getFirebaseError(error);
23381
- }
23382
- }
23383
- }
23384
- const initShop = (brandId, env = 'dev') => {
23385
- if (env === 'dev' || env === 'development')
23386
- console.warn('TfrShop is in development mode');
23387
- Config.getInstance().setEnv(env);
23388
- return new TfrShop(brandId, new Firebase());
23410
+ [Fit.TOO_SHORT]: 'Too Short',
23411
+ [Fit.SHORT]: 'Short',
23412
+ [Fit.SLIGHTLY_SHORT]: 'Slightly Short',
23413
+ [Fit.SLIGHTLY_LONG]: 'Slightly Long',
23414
+ [Fit.LONG]: 'Long',
23415
+ [Fit.TOO_LONG]: 'Too Long',
23389
23416
  };
23390
23417
 
23391
23418
  var AvatarState;