@thefittingroom/sdk 0.0.7 → 0.0.9

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
@@ -58,30 +58,50 @@ const shop = initShop(brandId, env)
58
58
  await shop.onInit()
59
59
 
60
60
  // Login user with session
61
- shop.user.login(username, password)
61
+ shop.user.login(email, password)
62
62
 
63
63
  // Logout current user
64
64
  shop.user.logout()
65
65
 
66
- // Submit telephone number for link to iOS app
66
+ // In order for the user to create an avatar, they'll need to download the mobile application.
67
+ // This will send an SMS to the given phone number with a link to the iOS app
67
68
  // No spaces and must include country code e.g. +18005551234
68
69
  shop.submitTelephoneNumber(tel)
70
+
71
+ // await for the avatar creation
72
+ // Returns boolean on whether the avatar is created or not after the configured `avatarTimeout` period
73
+ shop.awaitAvatarCreated()
69
74
  ```
70
75
 
71
76
  #### Shop
72
77
 
78
+ We'll make references to `sku` several times here. This is the unique identifier that matches a styles particular size
79
+ from your inventory to our system.
80
+
73
81
  ```typescript
74
- // returns frames: types.TryOnFrames
75
- shop.tryOn(colorwaySizeAssetSku)
82
+ // A good first step would be to ensure your style and size exists in the fitting room system before executing any of the
83
+ // following functions. You'll get back some data about the style(s), such as the ID of the style, which you can use
84
+ // for the getRecommendedSizes function below.
85
+ // ids: number[] or skus: string[]
86
+ // At least one parameter must not be null
87
+ shop.getStyles(ids, skus)
76
88
 
77
- // await for the avatar creation
78
- shop.awaitAvatarCreated()
89
+ // get recommended sizes for a particular style
90
+ // The styleID can be extracted from the previous getStyles function call.
91
+ const sizeRecommendation = shop.getRecommendedSizes(styleID)
79
92
 
80
- // get recommended sizes for use
81
- shop.getRecommendedSizes()
93
+ // get recommended sizes label for a particular style
94
+ // returns: { recommendedSizeLabel, availableSizeLabels }
95
+ // recommendedSizeLabel: string
96
+ // availableSizeLabels: string[]
97
+ const { recommendedSizeLabel, availableSizeLabels } = shop.getRecommendedSizesLabels(styleID)
82
98
 
83
- // get available styles by ids: number[] or skus: string[]
84
- shop.getStyles(ids, skus)
99
+ // Once the user has downloaded the mobile application and has created an avatar, they may now virtually try on a size.
100
+ // The size they try on must be one of the recommended sizes from the previous function call. or an error will get returned.
101
+ // returns frames: types.TryOnFrames
102
+ // These `frames` are images that can be used to cycle through the VTO 360 degrees.
103
+ // NOTE: this process can take a minute or two
104
+ const frames = await this.shop.tryOn(sku)
85
105
  ```
86
106
 
87
107
  #### Errors
@@ -12,7 +12,11 @@ export declare class TfrShop {
12
12
  onInit(): Promise<boolean>;
13
13
  tryOn(colorwaySizeAssetSku: string): Promise<types.TryOnFrames>;
14
14
  awaitAvatarCreated(): Promise<boolean>;
15
- getRecommendedSizes(brandStyleId: string): Promise<SizeRecommendation>;
15
+ getRecommendedSizes(styleId: string): Promise<SizeRecommendation>;
16
+ getRecommendedSizesLabels(styleId: string): Promise<{
17
+ recommendedSizeLabel: string;
18
+ availableSizeLabels: string[];
19
+ }>;
16
20
  getStyles(ids: number[], skus: string[]): Promise<Map<number, types.FirestoreStyle>>;
17
21
  submitTelephoneNumber(tel: string): Promise<void>;
18
22
  private awaitColorwaySizeAssetFrames;
@@ -6,6 +6,9 @@ export interface ErrorOutsideRecommendedSizes {
6
6
  recommended_size_id: number;
7
7
  available_size_ids: number[];
8
8
  }
9
+ export declare class AvatarNotCreatedError extends Error {
10
+ constructor();
11
+ }
9
12
  export declare class NoFramesFoundError extends Error {
10
13
  constructor();
11
14
  }
@@ -26,3 +29,4 @@ export declare class RecommendedAvailableSizesError extends Error {
26
29
  available_sizes: string[];
27
30
  constructor(recommended_size: string, available_sizes: string[]);
28
31
  }
32
+ export declare const AvatarNotCreated = "avatar not created";
package/dist/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * thefittingroom v0.0.7 (2023-07-19T15:29:31.094Z)
2
+ * thefittingroom v0.0.9 (2023-07-26T23:07:17.052Z)
3
3
  * Copyright 2022-present, TheFittingRoom, Inc. All rights reserved.
4
4
  */
5
5
  /**
@@ -22724,6 +22724,12 @@ function getAuth(app = getApp()) {
22724
22724
  }
22725
22725
  registerAuth("Browser" /* ClientPlatform.BROWSER */);
22726
22726
 
22727
+ class AvatarNotCreatedError extends Error {
22728
+ constructor() {
22729
+ super('Avatar not created');
22730
+ this.name = 'AvatarNotCreatedError';
22731
+ }
22732
+ }
22727
22733
  class NoFramesFoundError extends Error {
22728
22734
  constructor() {
22729
22735
  super('no frames found');
@@ -22762,15 +22768,19 @@ class RecommendedAvailableSizesError extends Error {
22762
22768
  this.available_sizes = available_sizes;
22763
22769
  }
22764
22770
  }
22771
+ // Backend responses
22772
+ const AvatarNotCreated = 'avatar not created';
22765
22773
 
22766
22774
  var errors = /*#__PURE__*/Object.freeze({
22767
22775
  __proto__: null,
22776
+ AvatarNotCreatedError: AvatarNotCreatedError,
22768
22777
  NoFramesFoundError: NoFramesFoundError,
22769
22778
  RequestTimeoutError: RequestTimeoutError,
22770
22779
  UserNotLoggedInError: UserNotLoggedInError,
22771
22780
  NoColorwaySizeAssetsFoundError: NoColorwaySizeAssetsFoundError,
22772
22781
  NoStylesFoundError: NoStylesFoundError,
22773
- RecommendedAvailableSizesError: RecommendedAvailableSizesError
22782
+ RecommendedAvailableSizesError: RecommendedAvailableSizesError,
22783
+ AvatarNotCreated: AvatarNotCreated
22774
22784
  });
22775
22785
 
22776
22786
  class FirebaseUser {
@@ -22983,12 +22993,25 @@ class TfrShop {
22983
22993
  const userProfile = snapshot.docs[0].data();
22984
22994
  return userProfile.avatar_status === 'CREATED';
22985
22995
  }
22986
- async getRecommendedSizes(brandStyleId) {
22996
+ async getRecommendedSizes(styleId) {
22987
22997
  if (!this.isLoggedIn)
22988
22998
  throw new UserNotLoggedInError();
22989
- const res = await Fetcher.Get(this.user, `/styles/${brandStyleId}/recommendation`);
22990
- const json = await res.json();
22991
- return json;
22999
+ try {
23000
+ const res = await Fetcher.Get(this.user, `/styles/${styleId}/recommendation`);
23001
+ const json = await res.json();
23002
+ return json;
23003
+ }
23004
+ catch (error) {
23005
+ if ((error === null || error === void 0 ? void 0 : error.error) === AvatarNotCreated)
23006
+ throw new AvatarNotCreatedError();
23007
+ throw error;
23008
+ }
23009
+ }
23010
+ async getRecommendedSizesLabels(styleId) {
23011
+ const sizeRecommendation = await this.getRecommendedSizes(styleId);
23012
+ const recommendedSizeLabel = sizeRecommendation.recommended_sizes.label || sizeRecommendation.recommended_sizes.size_value.size;
23013
+ const availableSizeLabels = sizeRecommendation.available_sizes.map((size) => size.label || size.size_value.size);
23014
+ return { recommendedSizeLabel, availableSizeLabels };
22992
23015
  }
22993
23016
  async getStyles(ids, skus) {
22994
23017
  const constraints = [rl('brand_id', '==', this.brandId)];
@@ -23034,6 +23057,8 @@ class TfrShop {
23034
23057
  return this.awaitColorwaySizeAssetFrames(colorwaySizeAssetSku);
23035
23058
  }
23036
23059
  catch (error) {
23060
+ if ((error === null || error === void 0 ? void 0 : error.error) === AvatarNotCreated)
23061
+ throw new AvatarNotCreatedError();
23037
23062
  if (!error.recommended_size_id)
23038
23063
  throw new Error(error);
23039
23064
  const errorOutsideRecommended = error;