@thefittingroom/sdk 1.0.3 → 1.1.1

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/README.md CHANGED
@@ -72,10 +72,6 @@ shop.user.setBrandUserId(brandUserId)
72
72
  // This will send an SMS to the given phone number with a link to the iOS app
73
73
  // No spaces and must include country code e.g. +18005551234
74
74
  shop.submitTelephoneNumber(tel)
75
-
76
- // await for the avatar creation
77
- // Returns boolean on whether the avatar is created or not after the configured `avatarTimeout` period
78
- shop.awaitAvatarCreated()
79
75
  ```
80
76
 
81
77
  #### Shop
@@ -84,39 +80,32 @@ We'll make references to `sku` several times here. This is the unique identifier
84
80
  from your inventory to our system.
85
81
 
86
82
  ```typescript
83
+ // get the garment measurement locations for a particular style
84
+ // This is used to pre-populate the size recommendation table with data before the user is logged into The Fitting Room
85
+ // sku: string
86
+ // returns: string[]
87
+ const locations = await shop.getMeasurementLocationsFromSku(sku)
88
+
87
89
  // A good first step would be to ensure your style and size exists in the fitting room system before executing any of the
88
- // following functions. You'll get back some data about the style(s), such as the ID of the style, which you can use
90
+ // following functions. You'll get back some data about the style, such as the ID of the style, which you can use
89
91
  // for the getRecommendedSizes function below.
90
- // ids: number[] or skus: string[]
91
- // At least one parameter must not be null
92
- shop.getStyles(ids, skus)
92
+ // sku: string
93
+ // returns: FirestoreColorwaySizeAsset
94
+ const colorwaySizeAsset = await shop.getColorwaySizeAssetFromSku(sku)
93
95
 
94
96
  // get recommended sizes for a particular style
95
- // The styleID can be extracted from the previous getStyles function call.
96
- const sizeRecommendation = shop.getRecommendedSizes(styleID)
97
-
98
- // get recommended sizes label for a particular style
99
- // returns: { recommendedSizeLabel, availableSizeLabels }
100
- // recommendedSizeLabel: string
101
- // availableSizeLabels: string[]
102
- const { recommendedSizeLabel, availableSizeLabels } = shop.getRecommendedSizesLabels(styleID)
103
-
104
- // Once the user has downloaded the mobile application and has created an avatar, they may now virtually try on a size.
105
- // The size they try on must be one of the recommended sizes from the previous function call. or an error will get returned.
106
- // returns frames: types.TryOnFrames
107
- // These `frames` are images that can be used to cycle through the VTO 360 degrees.
108
- // NOTE: this process can take a minute or two
109
- const frames = await this.shop.tryOn(sku)
97
+ // The styleId can be extracted from the previous getColorwaySizeAssetFromSku function call.
98
+ // styleId: string
99
+ // returns: SizeRecommendation
100
+ const sizeRecommendation = shop.getRecommendedSizes(styleId)
110
101
  ```
111
102
 
103
+ [Types Reference](https://github.com/TheFittingRoom/shop-sdk/blob/main/src/types/index.ts)
104
+
112
105
  #### Errors
113
106
 
114
107
  ```typescript
115
- NoFramesFoundError
116
- RequestTimeoutError
108
+ AvatarNotCreatedError
117
109
  UserNotLoggedInError
118
110
  NoColorwaySizeAssetsFoundError
119
- NoStylesFoundError
120
- RecommendedAvailableSizesError
121
- BrandUserIdNotSetError
122
111
  ```
@@ -11,8 +11,9 @@ export declare class TfrShop {
11
11
  getRecommendedSizes(styleId: string): Promise<SizeRecommendation>;
12
12
  submitTelephoneNumber(tel: string): Promise<void>;
13
13
  getColorwaySizeAssetFromSku(colorwaySizeAssetSku: string): Promise<types.FirestoreColorwaySizeAsset>;
14
- getMeasurementLocationsFromSku(sku: string): Promise<any>;
14
+ getMeasurementLocationsFromSku(sku: string): Promise<string[]>;
15
15
  private getColorwaySizeAssets;
16
16
  private getStyleCategory;
17
+ private getGetTaxonomy;
17
18
  }
18
19
  export declare const initShop: (brandId: number, env?: string) => TfrShop;
@@ -1,6 +1,7 @@
1
1
  import * as firebase from 'firebase/app';
2
2
  import * as firebaseAuth from 'firebase/auth';
3
- import { DocumentData, Firestore, QuerySnapshot } from 'firebase/firestore';
3
+ import { Firestore } from 'firebase/firestore';
4
+ import { FirestoreUser } from '../types';
4
5
  export type BrandUserId = string | number;
5
6
  export declare class FirebaseUser {
6
7
  private readonly firestore;
@@ -13,8 +14,8 @@ export declare class FirebaseUser {
13
14
  setUser(user: firebaseAuth.User): void;
14
15
  setBrandUserId(brandUserId: BrandUserId): void;
15
16
  getToken(): Promise<string>;
16
- getUserProfile(): Promise<DocumentData>;
17
- watchUserProfileForChanges(predicate: (data: QuerySnapshot<DocumentData>) => Promise<boolean>, timeout: number): Promise<DocumentData>;
17
+ getUserProfile(): Promise<import("@firebase/firestore").DocumentData>;
18
+ watchUserProfileForChanges(callback: (data: FirestoreUser) => void): () => void;
18
19
  login(username: string, password: string): Promise<void>;
19
20
  logout(): Promise<void>;
20
21
  sendPasswordResetEmail(email: string): Promise<void>;
@@ -1,35 +1,13 @@
1
1
  export interface ErrorResponse {
2
2
  error: string;
3
3
  }
4
- export interface ErrorOutsideRecommendedSizes {
5
- error: string;
6
- recommended_size_id: number;
7
- available_size_ids: number[];
8
- }
9
4
  export declare class AvatarNotCreatedError extends Error {
10
5
  constructor();
11
6
  }
12
- export declare class NoFramesFoundError extends Error {
13
- constructor();
14
- }
15
- export declare class RequestTimeoutError extends Error {
16
- constructor();
17
- }
18
7
  export declare class UserNotLoggedInError extends Error {
19
8
  constructor();
20
9
  }
21
10
  export declare class NoColorwaySizeAssetsFoundError extends Error {
22
11
  constructor();
23
12
  }
24
- export declare class NoStylesFoundError extends Error {
25
- constructor();
26
- }
27
- export declare class RecommendedAvailableSizesError extends Error {
28
- recommended_size: string;
29
- available_sizes: string[];
30
- constructor(recommended_size: string, available_sizes: string[]);
31
- }
32
- export declare class BrandUserIdNotSetError extends Error {
33
- constructor();
34
- }
35
13
  export declare const AvatarNotCreated = "avatar not created";
package/dist/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * thefittingroom v1.0.3 (2024-02-16T14:55:02.187Z)
2
+ * thefittingroom v1.1.1 (2024-04-05T18:35:16.880Z)
3
3
  * Copyright 2022-present, TheFittingRoom, Inc. All rights reserved.
4
4
  */
5
5
  // Code generated by tygo. DO NOT EDIT.
@@ -22740,18 +22740,6 @@ class AvatarNotCreatedError extends Error {
22740
22740
  this.name = 'AvatarNotCreatedError';
22741
22741
  }
22742
22742
  }
22743
- class NoFramesFoundError extends Error {
22744
- constructor() {
22745
- super('no frames found');
22746
- this.name = 'NoFramesFoundError';
22747
- }
22748
- }
22749
- class RequestTimeoutError extends Error {
22750
- constructor() {
22751
- super('request timeout');
22752
- this.name = 'RequestTimeoutError';
22753
- }
22754
- }
22755
22743
  class UserNotLoggedInError extends Error {
22756
22744
  constructor() {
22757
22745
  super('user not logged in');
@@ -22764,39 +22752,14 @@ class NoColorwaySizeAssetsFoundError extends Error {
22764
22752
  this.name = 'NoColorwaySizeAssetsFoundError';
22765
22753
  }
22766
22754
  }
22767
- class NoStylesFoundError extends Error {
22768
- constructor() {
22769
- super('no styles found');
22770
- this.name = 'NoStylesFoundError';
22771
- }
22772
- }
22773
- class RecommendedAvailableSizesError extends Error {
22774
- constructor(recommended_size, available_sizes) {
22775
- super('recommended available sizes error');
22776
- this.name = 'RecommendedAvailableSizesError';
22777
- this.recommended_size = recommended_size;
22778
- this.available_sizes = available_sizes;
22779
- }
22780
- }
22781
- class BrandUserIdNotSetError extends Error {
22782
- constructor() {
22783
- super('brand user id not set');
22784
- this.name = 'BrandUserIdNotSetError';
22785
- }
22786
- }
22787
22755
  // Backend responses
22788
22756
  const AvatarNotCreated = 'avatar not created';
22789
22757
 
22790
22758
  var errors = /*#__PURE__*/Object.freeze({
22791
22759
  __proto__: null,
22792
22760
  AvatarNotCreatedError: AvatarNotCreatedError,
22793
- NoFramesFoundError: NoFramesFoundError,
22794
- RequestTimeoutError: RequestTimeoutError,
22795
22761
  UserNotLoggedInError: UserNotLoggedInError,
22796
22762
  NoColorwaySizeAssetsFoundError: NoColorwaySizeAssetsFoundError,
22797
- NoStylesFoundError: NoStylesFoundError,
22798
- RecommendedAvailableSizesError: RecommendedAvailableSizesError,
22799
- BrandUserIdNotSetError: BrandUserIdNotSetError,
22800
22763
  AvatarNotCreated: AvatarNotCreated
22801
22764
  });
22802
22765
 
@@ -22840,19 +22803,11 @@ class FirebaseUser {
22840
22803
  const userProfile = await Ol(Aa(this.firestore, 'users', this.id));
22841
22804
  return userProfile.data();
22842
22805
  }
22843
- watchUserProfileForChanges(predicate, timeout) {
22806
+ watchUserProfileForChanges(callback) {
22844
22807
  let unsub;
22845
22808
  const q = sl(Ta(this.firestore, 'users'), rl(Eh(), '==', this.id));
22846
- const cancel = setTimeout(() => unsub(), timeout);
22847
- return new Promise((resolve) => {
22848
- unsub = jl(q, async (snapshot) => {
22849
- if (!(await predicate(snapshot)))
22850
- return;
22851
- clearTimeout(cancel);
22852
- unsub();
22853
- resolve(snapshot.docs[0].data());
22854
- });
22855
- });
22809
+ unsub = jl(q, (snapshot) => callback(snapshot.docs[0].data()));
22810
+ return () => unsub();
22856
22811
  }
22857
22812
  async login(username, password) {
22858
22813
  if (this.auth.currentUser)
@@ -23376,7 +23331,8 @@ class TfrShop {
23376
23331
  var _a;
23377
23332
  const asset = await this.getColorwaySizeAssetFromSku(sku);
23378
23333
  const styleCategory = await this.getStyleCategory(asset.style_id);
23379
- const classificationLocation = ((_a = Taxonomy[styleCategory.category]) === null || _a === void 0 ? void 0 : _a[styleCategory.sub_category]) || null;
23334
+ const taxonomy = await this.getGetTaxonomy(styleCategory.style_garment_category_id);
23335
+ const classificationLocation = ((_a = Taxonomy[taxonomy.style_category]) === null || _a === void 0 ? void 0 : _a[taxonomy.garment_category]) || null;
23380
23336
  return classificationLocation
23381
23337
  ? ClassificationLocations[classificationLocation].map((location) => MeasurementLocationName[location])
23382
23338
  : null;
@@ -23402,7 +23358,16 @@ class TfrShop {
23402
23358
  }
23403
23359
  async getStyleCategory(styleId) {
23404
23360
  try {
23405
- const doc = await this.firebase.getDoc('style_categories', String(styleId));
23361
+ const doc = await this.firebase.getDoc('styles', String(styleId));
23362
+ return doc;
23363
+ }
23364
+ catch (error) {
23365
+ return getFirebaseError(error);
23366
+ }
23367
+ }
23368
+ async getGetTaxonomy(styleId) {
23369
+ try {
23370
+ const doc = await this.firebase.getDoc('style_garment_categories', String(styleId));
23406
23371
  return doc;
23407
23372
  }
23408
23373
  catch (error) {