@thefittingroom/sdk 0.0.5 → 0.0.6

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 ADDED
@@ -0,0 +1,94 @@
1
+ # The Fitting Room - Shop SDK
2
+
3
+ ### Installation
4
+
5
+ ```bash
6
+ npm i @thefittingroom/shop-sdk
7
+ ```
8
+
9
+ or
10
+
11
+ ```bash
12
+ yarn @thefittingroom/shop-sdk
13
+ ```
14
+
15
+ ### Build
16
+
17
+ ```bash
18
+ npm run build
19
+ ```
20
+
21
+ or
22
+
23
+ ```bash
24
+ yarn build
25
+ ```
26
+
27
+ ### Development
28
+
29
+ ```bash
30
+ npm run watch
31
+ ```
32
+
33
+ or
34
+
35
+ ```bash
36
+ yarn watch
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ ```typescript
42
+ import { initShop } from '@thefittingroom/sdk'
43
+
44
+ // Your brandId: Number
45
+ const brandId = 9001
46
+
47
+ // The environment: 'development', 'dev', 'production', 'prod'
48
+ const env = 'dev'
49
+ const shop = initShop(brandId, env)
50
+ await shop.onInit()
51
+ ```
52
+
53
+ ### Shop API
54
+
55
+ #### Auth
56
+
57
+ ```typescript
58
+ // Login user with session
59
+ shop.user.login(username, password)
60
+
61
+ // Logout current user
62
+ shop.user.logout()
63
+
64
+ // Submit telephone number for link to iOS app
65
+ // No spaces and must include country code e.g. +18005551234
66
+ shop.submitTelephoneNumber(tel)
67
+ ```
68
+
69
+ #### Shop
70
+
71
+ ```typescript
72
+ // returns frames: types.TryOnFrames
73
+ shop.tryOn(colorwaySizeAssetSku)
74
+
75
+ // await for the avatar creation
76
+ shop.awaitAvatarCreated()
77
+
78
+ // get recommended sizes for use
79
+ shop.getRecommendedSizes()
80
+
81
+ // get available styles by ids: number[] or skus: string[]
82
+ shop.getStyles(ids, skus)
83
+ ```
84
+
85
+ #### Errors
86
+
87
+ ```typescript
88
+ NoFramesFoundError
89
+ RequestTimeoutError
90
+ UserNotLoggedInError
91
+ NoColorwaySizeAssetsFoundError
92
+ NoStylesFoundError
93
+ RecommendedAvailableSizesError
94
+ ```
@@ -1,6 +1,6 @@
1
1
  import { FirebaseUser } from '../firebase/firebase-user';
2
2
  export declare class Fetcher {
3
- private static endpoint;
3
+ private static get endpoint();
4
4
  private static Fetch;
5
5
  private static getUrl;
6
6
  private static getHeaders;
@@ -10,7 +10,7 @@ export declare class TfrShop {
10
10
  get user(): import("..").FirebaseUser;
11
11
  get isLoggedIn(): boolean;
12
12
  onInit(): Promise<boolean>;
13
- tryOn(colorwaySizeAssetSku: string): Promise<types.TryOnFrames>;
13
+ tryOn(colorwaySizeAssetSku: string): Promise<any>;
14
14
  awaitAvatarCreated(): Promise<boolean>;
15
15
  getRecommendedSizes(brandStyleId: string): Promise<SizeRecommendation>;
16
16
  getStyles(ids: number[], skus: string[]): Promise<Map<number, types.FirestoreStyle>>;
@@ -1 +1,2 @@
1
1
  export declare const asyncTry: <T>(promise: Promise<T>) => Promise<[Error, T] | [Error]>;
2
+ export declare const asyncWait: (ms: number) => Promise<unknown>;
@@ -16,7 +16,7 @@ export declare class Config {
16
16
  url: string;
17
17
  };
18
18
  get config(): {
19
- avatarTimeout: string;
20
- vtoTimeout: string;
19
+ avatarTimeout: number;
20
+ vtoTimeout: number;
21
21
  };
22
22
  }
package/dist/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * thefittingroom v0.0.3 (2023-07-18T18:14:19.719Z)
2
+ * thefittingroom v0.0.6 (2023-07-18T23:18:09.529Z)
3
3
  * Copyright 2022-present, TheFittingRoom, Inc. All rights reserved.
4
4
  */
5
5
  /**
@@ -16350,8 +16350,8 @@ const devKeys = {
16350
16350
  url: "https://tfr.dev.thefittingroom.xyz",
16351
16351
  },
16352
16352
  config: {
16353
- avatarTimeout: "120000",
16354
- vtoTimeout: "120000",
16353
+ avatarTimeout: Number("120000"),
16354
+ vtoTimeout: Number("120000"),
16355
16355
  },
16356
16356
  };
16357
16357
  const prodKeys = {
@@ -16367,8 +16367,8 @@ const prodKeys = {
16367
16367
  url: "https://tfr.p.thefittingroom.xyz",
16368
16368
  },
16369
16369
  config: {
16370
- avatarTimeout: "120000",
16371
- vtoTimeout: "120000",
16370
+ avatarTimeout: Number("120000"),
16371
+ vtoTimeout: Number("120000"),
16372
16372
  },
16373
16373
  };
16374
16374
 
@@ -22862,9 +22862,10 @@ const getFirebaseError = (e) => {
22862
22862
  };
22863
22863
 
22864
22864
  const asyncTry = (promise) => promise.then((data) => [null, data]).catch((error) => [error]);
22865
+ const asyncWait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
22865
22866
 
22866
22867
  class Fetcher {
22867
- static endpoint() {
22868
+ static get endpoint() {
22868
22869
  const api = Config.getInstance().api;
22869
22870
  return api.url;
22870
22871
  }
@@ -22994,10 +22995,18 @@ class TfrShop {
22994
22995
  const res = await Fetcher.Post(this.user, '/ios-app-link', { phone_number: sanitizedTel }, false);
22995
22996
  console.log(res);
22996
22997
  }
22997
- awaitColorwaySizeAssetFrames(colorwaySizeAssetSKU) {
22998
+ async awaitColorwaySizeAssetFrames(colorwaySizeAssetSKU) {
22998
22999
  if (!this.isLoggedIn)
22999
23000
  throw new UserNotLoggedInError();
23000
- return this.getColorwaySizeAssetFrames(colorwaySizeAssetSKU);
23001
+ console.log('polling');
23002
+ try {
23003
+ const frames = await this.getColorwaySizeAssetFrames(colorwaySizeAssetSKU);
23004
+ return frames;
23005
+ }
23006
+ catch (_a) {
23007
+ await asyncWait(1500);
23008
+ return this.awaitColorwaySizeAssetFrames(colorwaySizeAssetSKU);
23009
+ }
23001
23010
  }
23002
23011
  async requestThenGetColorwaySizeAssetFrames(colorwaySizeAssetSku) {
23003
23012
  var _a, _b;
@@ -23066,6 +23075,8 @@ class TfrShop {
23066
23075
  return frames;
23067
23076
  }
23068
23077
  }
23078
+ TfrShop.avatarTimeout = 120000;
23079
+ TfrShop.vtoTimeout = 120000;
23069
23080
  const initShop = (brandId, env = 'dev') => {
23070
23081
  if (env === 'dev' || env === 'development')
23071
23082
  console.warn('TfrShop is in development mode');