@thefittingroom/sdk 0.0.1-alpha.10 → 0.0.5

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/.env.example CHANGED
@@ -1,12 +1,21 @@
1
- FIREBASE_API_KEY
2
- FIREBASE_AUTH_DOMAIN
3
- FIREBASE_PROJECT_ID
4
- FIREBASE_STORAGE_BUCKET
5
- FIREBASE_MESSAGING_SENDER_ID
6
- FIREBASE_APP_ID
7
- FIREBASE_MEASUREMENT_ID
8
- API_ENDPOINT
9
- LANGUAGE_URL
10
- ASSETS_URL
11
- VTO_TIMEOUT_MS
12
- AVATAR_TIMEOUT_MS
1
+ DEV_FIREBASE_API_KEY=
2
+ DEV_FIREBASE_AUTH_DOMAIN=
3
+ DEV_FIREBASE_PROJECT_ID=
4
+ DEV_FIREBASE_STORAGE_BUCKET=
5
+ DEV_FIREBASE_MESSAGING_SENDER_ID=
6
+ DEV_FIREBASE_APP_ID=
7
+ DEV_FIREBASE_MEASUREMENT_ID=
8
+ DEV_API_ENDPOINT=
9
+ DEV_VTO_TIMEOUT_MS=
10
+ DEV_AVATAR_TIMEOUT_MS=
11
+
12
+ PROD_FIREBASE_API_KEY=
13
+ PROD_FIREBASE_AUTH_DOMAIN=
14
+ PROD_FIREBASE_PROJECT_ID=
15
+ PROD_FIREBASE_STORAGE_BUCKET=
16
+ PROD_FIREBASE_MESSAGING_SENDER_ID=
17
+ PROD_FIREBASE_APP_ID=
18
+ PROD_FIREBASE_MEASUREMENT_ID=
19
+ PROD_API_ENDPOINT=
20
+ PROD_VTO_TIMEOUT_MS=
21
+ PROD_AVATAR_TIMEOUT_MS=
@@ -1,9 +1,12 @@
1
1
  import { FirebaseUser } from '../firebase/firebase-user';
2
2
  export declare class Fetcher {
3
+ private static endpoint;
3
4
  private static Fetch;
4
- static Get(user: FirebaseUser, endpointPath: string): Promise<Response>;
5
- static Post(user: FirebaseUser, endpointPath: string, body?: Record<string, any>): Promise<Response>;
6
- static Put(user: FirebaseUser, endpointPath: string, body: Record<string, any>): Promise<Response>;
7
- static Patch(user: FirebaseUser, endpointPath: string, body: Record<string, any>): Promise<Response>;
8
- static Delete(user: FirebaseUser, endpointPath: string, body: Record<string, any>): Promise<Response>;
5
+ private static getUrl;
6
+ private static getHeaders;
7
+ static Get(user: FirebaseUser, endpointPath: string, useToken?: boolean): Promise<Response>;
8
+ static Post(user: FirebaseUser, endpointPath: string, body?: Record<string, any>, useToken?: boolean): Promise<Response>;
9
+ static Put(user: FirebaseUser, endpointPath: string, body: Record<string, any>, useToken?: boolean): Promise<Response>;
10
+ static Patch(user: FirebaseUser, endpointPath: string, body: Record<string, any>, useToken?: boolean): Promise<Response>;
11
+ static Delete(user: FirebaseUser, endpointPath: string, body: Record<string, any>, useToken?: boolean): Promise<Response>;
9
12
  }
@@ -4,14 +4,17 @@ import { SizeRecommendation } from './responses';
4
4
  export declare class TfrShop {
5
5
  private readonly brandId;
6
6
  private readonly firebase;
7
- private static AVATAR_TIMEOUT;
8
- constructor(brandId: string, firebase: Firebase);
9
- get user(): import("../firebase/firebase-user").FirebaseUser;
7
+ private static avatarTimeout;
8
+ static vtoTimeout: number;
9
+ constructor(brandId: number, firebase: Firebase);
10
+ get user(): import("..").FirebaseUser;
10
11
  get isLoggedIn(): boolean;
12
+ onInit(): Promise<boolean>;
11
13
  tryOn(colorwaySizeAssetSku: string): Promise<types.TryOnFrames>;
12
14
  awaitAvatarCreated(): Promise<boolean>;
13
- getRecommendedSize(brandStyleId: string): Promise<SizeRecommendation>;
15
+ getRecommendedSizes(brandStyleId: string): Promise<SizeRecommendation>;
14
16
  getStyles(ids: number[], skus: string[]): Promise<Map<number, types.FirestoreStyle>>;
17
+ submitTelephoneNumber(tel: string): Promise<void>;
15
18
  private awaitColorwaySizeAssetFrames;
16
19
  private requestThenGetColorwaySizeAssetFrames;
17
20
  private getColorwaySizeAssetFromSku;
@@ -19,4 +22,4 @@ export declare class TfrShop {
19
22
  private requestColorwaySizeAssetFrames;
20
23
  private getColorwaySizeAssetFrames;
21
24
  }
22
- export declare const initShop: (brandId: string) => TfrShop;
25
+ export declare const initShop: (brandId: number, env?: string) => TfrShop;
@@ -7,7 +7,7 @@ export declare class FirebaseUser {
7
7
  private readonly auth;
8
8
  constructor(firestore: Firestore, app: firebase.FirebaseApp);
9
9
  get id(): string;
10
- onInit(): Promise<void>;
10
+ onInit(): Promise<boolean>;
11
11
  setUser(user: firebaseAuth.User): void;
12
12
  getToken(): Promise<string>;
13
13
  getUserProfile(): Promise<import("@firebase/firestore").DocumentData>;
@@ -1,11 +1,10 @@
1
- import { DocumentData, QueryFieldFilterConstraint, QuerySnapshot } from 'firebase/firestore';
1
+ import { DocumentData, Firestore, QueryFieldFilterConstraint, QuerySnapshot } from 'firebase/firestore';
2
2
  import { FirebaseUser } from './firebase-user';
3
3
  export declare class Firebase {
4
4
  user: FirebaseUser;
5
- private static readonly App;
6
- private readonly firestore;
5
+ readonly firestore: Firestore;
7
6
  constructor();
8
- onInit(): Promise<void>;
7
+ onInit(): Promise<boolean>;
9
8
  query(collectionName: string, constraint: QueryFieldFilterConstraint): {
10
9
  promise: Promise<QuerySnapshot<DocumentData>>;
11
10
  unsubscribe: () => void;
@@ -0,0 +1,22 @@
1
+ export declare class Config {
2
+ private static instance;
3
+ private env;
4
+ private constructor();
5
+ static getInstance(): Config;
6
+ setEnv(env: string): void;
7
+ get firebase(): {
8
+ apiKey: string;
9
+ authDomain: string;
10
+ projectId: string;
11
+ storageBucket: string;
12
+ messagingSenderId: string;
13
+ appId: string;
14
+ };
15
+ get api(): {
16
+ url: string;
17
+ };
18
+ get config(): {
19
+ avatarTimeout: string;
20
+ vtoTimeout: string;
21
+ };
22
+ }
@@ -2,5 +2,8 @@ export * as requests from './api/requests';
2
2
  export * as responses from './api/responses';
3
3
  export { initShop } from './api/shop';
4
4
  export type { TfrShop } from './api/shop';
5
+ export type { Firebase } from './firebase/firebase';
6
+ export type { FirebaseUser } from './firebase/firebase-user';
5
7
  export * as Errors from './helpers/errors';
6
8
  export * as types from './types';
9
+ export declare const VTO_TIMEOUT_MS: number;
package/dist/esm/index.js CHANGED
@@ -1,19 +1,7 @@
1
1
  /*!
2
- * thefittingroom v0.0.1-alpha.9 (2023-07-17T20:26:11.306Z)
2
+ * thefittingroom v0.0.3 (2023-07-18T18:14:19.719Z)
3
3
  * Copyright 2022-present, TheFittingRoom, Inc. All rights reserved.
4
4
  */
5
- // Code generated by tygo. DO NOT EDIT.
6
-
7
- var requests = /*#__PURE__*/Object.freeze({
8
- __proto__: null
9
- });
10
-
11
- // Code generated by tygo. DO NOT EDIT.
12
-
13
- var responses = /*#__PURE__*/Object.freeze({
14
- __proto__: null
15
- });
16
-
17
5
  /**
18
6
  * @license
19
7
  * Copyright 2017 Google LLC
@@ -16314,6 +16302,76 @@ var version$1 = "9.15.0";
16314
16302
  */
16315
16303
  registerVersion(name$1, version$1, 'app');
16316
16304
 
16305
+ class Config {
16306
+ constructor() { }
16307
+ static getInstance() {
16308
+ if (!Config.instance)
16309
+ Config.instance = new Config();
16310
+ return Config.instance;
16311
+ }
16312
+ setEnv(env) {
16313
+ switch (env) {
16314
+ case 'production':
16315
+ case 'prod':
16316
+ this.env = 'prod';
16317
+ break;
16318
+ case 'development':
16319
+ case 'dev':
16320
+ default:
16321
+ this.env = 'dev';
16322
+ }
16323
+ }
16324
+ get firebase() {
16325
+ if (this.env === 'prod')
16326
+ return prodKeys.firebase;
16327
+ return devKeys.firebase;
16328
+ }
16329
+ get api() {
16330
+ if (this.env === 'prod')
16331
+ return prodKeys.api;
16332
+ return devKeys.api;
16333
+ }
16334
+ get config() {
16335
+ if (this.env === 'prod')
16336
+ return prodKeys.config;
16337
+ return devKeys.config;
16338
+ }
16339
+ }
16340
+ const devKeys = {
16341
+ firebase: {
16342
+ apiKey: "AIzaSyDfjBWzpmzb-mhGN8VSURxzLg6nkzmKUD8",
16343
+ authDomain: "fittingroom-dev-5d248.firebaseapp.com",
16344
+ projectId: "fittingroom-dev-5d248",
16345
+ storageBucket: "fittingroom-dev-5d248.appspot.com",
16346
+ messagingSenderId: "2298664147",
16347
+ appId: "1:2298664147:web:340bda75cd5d25f3997026",
16348
+ },
16349
+ api: {
16350
+ url: "https://tfr.dev.thefittingroom.xyz",
16351
+ },
16352
+ config: {
16353
+ avatarTimeout: "120000",
16354
+ vtoTimeout: "120000",
16355
+ },
16356
+ };
16357
+ const prodKeys = {
16358
+ firebase: {
16359
+ apiKey: "AIzaSyA3kQ6w1vkA9l9lgY0nNACVPXe-QmP5T1Y",
16360
+ authDomain: "fittingroom-prod.firebaseapp.com",
16361
+ projectId: "fittingroom-prod",
16362
+ storageBucket: "fittingroom-prod.appspot.com",
16363
+ messagingSenderId: "965656825574",
16364
+ appId: "1:965656825574:web:933493cddc73213bd43527",
16365
+ },
16366
+ api: {
16367
+ url: "https://tfr.p.thefittingroom.xyz",
16368
+ },
16369
+ config: {
16370
+ avatarTimeout: "120000",
16371
+ vtoTimeout: "120000",
16372
+ },
16373
+ };
16374
+
16317
16375
  /******************************************************************************
16318
16376
  Copyright (c) Microsoft Corporation.
16319
16377
 
@@ -22727,11 +22785,10 @@ class FirebaseUser {
22727
22785
  }
22728
22786
  onInit() {
22729
22787
  return new Promise((resolve) => {
22730
- this.auth.onAuthStateChanged((user) => {
22788
+ const unsub = this.auth.onAuthStateChanged((user) => {
22731
22789
  this.setUser(user);
22732
- if (user)
22733
- return resolve();
22734
- throw new UserNotLoggedInError();
22790
+ resolve(Boolean(user));
22791
+ unsub();
22735
22792
  });
22736
22793
  });
22737
22794
  }
@@ -22777,8 +22834,10 @@ class Firebase {
22777
22834
  const promise = new Promise((resolve) => (unsub = jl(q, (snapshot) => resolve(snapshot))));
22778
22835
  return { promise, unsubscribe: () => unsub() };
22779
22836
  };
22780
- this.firestore = oh(Firebase.App);
22781
- this.user = new FirebaseUser(this.firestore, Firebase.App);
22837
+ const firebaseKeys = Config.getInstance().firebase;
22838
+ const firebaseApp = initializeApp(firebaseKeys);
22839
+ this.firestore = oh(firebaseApp);
22840
+ this.user = new FirebaseUser(this.firestore, firebaseApp);
22782
22841
  }
22783
22842
  onInit() {
22784
22843
  return this.user.onInit();
@@ -22792,14 +22851,6 @@ class Firebase {
22792
22851
  return Bl(q);
22793
22852
  }
22794
22853
  }
22795
- Firebase.App = initializeApp({
22796
- apiKey: "AIzaSyDfjBWzpmzb-mhGN8VSURxzLg6nkzmKUD8",
22797
- authDomain: "fittingroom-dev-5d248.firebaseapp.com",
22798
- projectId: "fittingroom-dev-5d248",
22799
- storageBucket: "fittingroom-dev-5d248.appspot.com",
22800
- messagingSenderId: "2298664147",
22801
- appId: "1:2298664147:web:340bda75cd5d25f3997026",
22802
- });
22803
22854
 
22804
22855
  const getFirebaseError = (e) => {
22805
22856
  switch (e.code) {
@@ -22813,13 +22864,13 @@ const getFirebaseError = (e) => {
22813
22864
  const asyncTry = (promise) => promise.then((data) => [null, data]).catch((error) => [error]);
22814
22865
 
22815
22866
  class Fetcher {
22816
- static async Fetch({ user, endpointPath, method, body }) {
22817
- const url = "https://tfr.dev.thefittingroom.xyz/v1" + endpointPath;
22818
- const token = await user.getToken();
22819
- const headers = {
22820
- 'Content-Type': 'application/json',
22821
- Authorization: `Bearer ${token}`,
22822
- };
22867
+ static endpoint() {
22868
+ const api = Config.getInstance().api;
22869
+ return api.url;
22870
+ }
22871
+ static async Fetch({ user, endpointPath, method, body, useToken = true }) {
22872
+ const url = this.getUrl(endpointPath, useToken);
22873
+ const headers = await this.getHeaders(user, useToken);
22823
22874
  const config = { method, headers, credentials: 'include' };
22824
22875
  if (body)
22825
22876
  config.body = JSON.stringify(body);
@@ -22831,20 +22882,32 @@ class Fetcher {
22831
22882
  const json = await res.json();
22832
22883
  return Promise.reject(json);
22833
22884
  }
22834
- static Get(user, endpointPath) {
22835
- return this.Fetch({ user, endpointPath, method: 'GET', body: null });
22885
+ static getUrl(endpointPath, useToken) {
22886
+ return useToken ? `${this.endpoint}/v1${endpointPath}` : this.endpoint + endpointPath;
22887
+ }
22888
+ static async getHeaders(user, useToken) {
22889
+ if (!useToken)
22890
+ return { 'Content-Type': 'application/json' };
22891
+ const token = await user.getToken();
22892
+ return {
22893
+ 'Content-Type': 'application/json',
22894
+ Authorization: `Bearer ${token}`,
22895
+ };
22896
+ }
22897
+ static Get(user, endpointPath, useToken) {
22898
+ return this.Fetch({ user, endpointPath, method: 'GET', body: null, useToken });
22836
22899
  }
22837
- static Post(user, endpointPath, body = null) {
22838
- return this.Fetch({ user, endpointPath, method: 'POST', body });
22900
+ static Post(user, endpointPath, body = null, useToken) {
22901
+ return this.Fetch({ user, endpointPath, method: 'POST', body, useToken });
22839
22902
  }
22840
- static Put(user, endpointPath, body) {
22841
- return this.Fetch({ user, endpointPath, method: 'PUT', body });
22903
+ static Put(user, endpointPath, body, useToken) {
22904
+ return this.Fetch({ user, endpointPath, method: 'PUT', body, useToken });
22842
22905
  }
22843
- static Patch(user, endpointPath, body) {
22844
- return this.Fetch({ user, endpointPath, method: 'PATCH', body });
22906
+ static Patch(user, endpointPath, body, useToken) {
22907
+ return this.Fetch({ user, endpointPath, method: 'PATCH', body, useToken });
22845
22908
  }
22846
- static Delete(user, endpointPath, body) {
22847
- return this.Fetch({ user, endpointPath, method: 'DELETE', body });
22909
+ static Delete(user, endpointPath, body, useToken) {
22910
+ return this.Fetch({ user, endpointPath, method: 'DELETE', body, useToken });
22848
22911
  }
22849
22912
  }
22850
22913
 
@@ -22861,6 +22924,9 @@ class TfrShop {
22861
22924
  constructor(brandId, firebase) {
22862
22925
  this.brandId = brandId;
22863
22926
  this.firebase = firebase;
22927
+ const config = Config.getInstance().config;
22928
+ TfrShop.avatarTimeout = config.avatarTimeout ? Number(config.avatarTimeout) : 120000;
22929
+ TfrShop.vtoTimeout = config.vtoTimeout ? Number(config.vtoTimeout) : 120000;
22864
22930
  }
22865
22931
  get user() {
22866
22932
  return this.firebase.user;
@@ -22868,6 +22934,9 @@ class TfrShop {
22868
22934
  get isLoggedIn() {
22869
22935
  return !this.firebase || Boolean(this.user.id);
22870
22936
  }
22937
+ onInit() {
22938
+ return this.firebase.onInit();
22939
+ }
22871
22940
  async tryOn(colorwaySizeAssetSku) {
22872
22941
  if (!this.isLoggedIn)
22873
22942
  throw new UserNotLoggedInError();
@@ -22876,8 +22945,8 @@ class TfrShop {
22876
22945
  return frames;
22877
22946
  }
22878
22947
  catch (error) {
22879
- if (error instanceof NoFramesFoundError)
22880
- throw new NoFramesFoundError();
22948
+ if (!(error instanceof NoFramesFoundError))
22949
+ throw error;
22881
22950
  return this.requestThenGetColorwaySizeAssetFrames(colorwaySizeAssetSku);
22882
22951
  }
22883
22952
  }
@@ -22888,13 +22957,13 @@ class TfrShop {
22888
22957
  const cancel = setTimeout(() => {
22889
22958
  unsubscribe();
22890
22959
  throw new RequestTimeoutError();
22891
- }, TfrShop.AVATAR_TIMEOUT);
22960
+ }, TfrShop.avatarTimeout);
22892
22961
  const snapshot = await promise;
22893
22962
  clearTimeout(cancel);
22894
22963
  const userProfile = snapshot.docs[0].data();
22895
22964
  return userProfile.avatar_status === 'CREATED';
22896
22965
  }
22897
- async getRecommendedSize(brandStyleId) {
22966
+ async getRecommendedSizes(brandStyleId) {
22898
22967
  if (!this.isLoggedIn)
22899
22968
  throw new UserNotLoggedInError();
22900
22969
  const res = await Fetcher.Get(this.user, `/styles/${brandStyleId}/recommendation`);
@@ -22920,6 +22989,11 @@ class TfrShop {
22920
22989
  return getFirebaseError(error);
22921
22990
  }
22922
22991
  }
22992
+ async submitTelephoneNumber(tel) {
22993
+ const sanitizedTel = tel.replace(/[^\+0-9]/g, '');
22994
+ const res = await Fetcher.Post(this.user, '/ios-app-link', { phone_number: sanitizedTel }, false);
22995
+ console.log(res);
22996
+ }
22923
22997
  awaitColorwaySizeAssetFrames(colorwaySizeAssetSKU) {
22924
22998
  if (!this.isLoggedIn)
22925
22999
  throw new UserNotLoggedInError();
@@ -22992,8 +23066,24 @@ class TfrShop {
22992
23066
  return frames;
22993
23067
  }
22994
23068
  }
22995
- TfrShop.AVATAR_TIMEOUT = process.env.AVATAR_TIMEOUT ? Number(process.env.AVATAR_TIMEOUT) : 10000;
22996
- const initShop = (brandId) => new TfrShop(brandId, new Firebase());
23069
+ const initShop = (brandId, env = 'dev') => {
23070
+ if (env === 'dev' || env === 'development')
23071
+ console.warn('TfrShop is in development mode');
23072
+ Config.getInstance().setEnv(env);
23073
+ return new TfrShop(brandId, new Firebase());
23074
+ };
23075
+
23076
+ // Code generated by tygo. DO NOT EDIT.
23077
+
23078
+ var requests = /*#__PURE__*/Object.freeze({
23079
+ __proto__: null
23080
+ });
23081
+
23082
+ // Code generated by tygo. DO NOT EDIT.
23083
+
23084
+ var responses = /*#__PURE__*/Object.freeze({
23085
+ __proto__: null
23086
+ });
22997
23087
 
22998
23088
  var AvatarState;
22999
23089
  (function (AvatarState) {
@@ -23007,5 +23097,7 @@ var index = /*#__PURE__*/Object.freeze({
23007
23097
  get AvatarState () { return AvatarState; }
23008
23098
  });
23009
23099
 
23010
- export { errors as Errors, initShop, requests, responses, index as types };
23100
+ const VTO_TIMEOUT_MS = TfrShop.vtoTimeout;
23101
+
23102
+ export { errors as Errors, VTO_TIMEOUT_MS, initShop, requests, responses, index as types };
23011
23103
  //# sourceMappingURL=index.js.map