@thefittingroom/sdk 0.0.1-alpha.10 → 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/.env.example +21 -12
- package/README.md +94 -0
- package/dist/esm/api/fetcher.d.ts +8 -5
- package/dist/esm/api/shop.d.ts +9 -6
- package/dist/esm/firebase/firebase-user.d.ts +1 -1
- package/dist/esm/firebase/firebase.d.ts +3 -4
- package/dist/esm/helpers/async.d.ts +1 -0
- package/dist/esm/helpers/config.d.ts +22 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +156 -53
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +184 -185
- package/dist/esm/index.min.js.map +1 -1
- package/package.json +8 -45
- package/.env.dev +0 -14
- package/.env.prod +0 -14
package/.env.example
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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=
|
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,9 +1,12 @@
|
|
|
1
1
|
import { FirebaseUser } from '../firebase/firebase-user';
|
|
2
2
|
export declare class Fetcher {
|
|
3
|
+
private static get endpoint();
|
|
3
4
|
private static Fetch;
|
|
4
|
-
static
|
|
5
|
-
static
|
|
6
|
-
static
|
|
7
|
-
static
|
|
8
|
-
static
|
|
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
|
}
|
package/dist/esm/api/shop.d.ts
CHANGED
|
@@ -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
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
private static avatarTimeout;
|
|
8
|
+
static vtoTimeout: number;
|
|
9
|
+
constructor(brandId: number, firebase: Firebase);
|
|
10
|
+
get user(): import("..").FirebaseUser;
|
|
10
11
|
get isLoggedIn(): boolean;
|
|
11
|
-
|
|
12
|
+
onInit(): Promise<boolean>;
|
|
13
|
+
tryOn(colorwaySizeAssetSku: string): Promise<any>;
|
|
12
14
|
awaitAvatarCreated(): Promise<boolean>;
|
|
13
|
-
|
|
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<
|
|
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
|
-
|
|
6
|
-
private readonly firestore;
|
|
5
|
+
readonly firestore: Firestore;
|
|
7
6
|
constructor();
|
|
8
|
-
onInit(): Promise<
|
|
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: number;
|
|
20
|
+
vtoTimeout: number;
|
|
21
|
+
};
|
|
22
|
+
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -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.
|
|
2
|
+
* thefittingroom v0.0.6 (2023-07-18T23:18:09.529Z)
|
|
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: Number("120000"),
|
|
16354
|
+
vtoTimeout: Number("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: Number("120000"),
|
|
16371
|
+
vtoTimeout: Number("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
|
-
|
|
22733
|
-
|
|
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
|
-
|
|
22781
|
-
|
|
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) {
|
|
@@ -22811,15 +22862,16 @@ const getFirebaseError = (e) => {
|
|
|
22811
22862
|
};
|
|
22812
22863
|
|
|
22813
22864
|
const asyncTry = (promise) => promise.then((data) => [null, data]).catch((error) => [error]);
|
|
22865
|
+
const asyncWait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
22814
22866
|
|
|
22815
22867
|
class Fetcher {
|
|
22816
|
-
static
|
|
22817
|
-
const
|
|
22818
|
-
|
|
22819
|
-
|
|
22820
|
-
|
|
22821
|
-
|
|
22822
|
-
|
|
22868
|
+
static get endpoint() {
|
|
22869
|
+
const api = Config.getInstance().api;
|
|
22870
|
+
return api.url;
|
|
22871
|
+
}
|
|
22872
|
+
static async Fetch({ user, endpointPath, method, body, useToken = true }) {
|
|
22873
|
+
const url = this.getUrl(endpointPath, useToken);
|
|
22874
|
+
const headers = await this.getHeaders(user, useToken);
|
|
22823
22875
|
const config = { method, headers, credentials: 'include' };
|
|
22824
22876
|
if (body)
|
|
22825
22877
|
config.body = JSON.stringify(body);
|
|
@@ -22831,20 +22883,32 @@ class Fetcher {
|
|
|
22831
22883
|
const json = await res.json();
|
|
22832
22884
|
return Promise.reject(json);
|
|
22833
22885
|
}
|
|
22834
|
-
static
|
|
22835
|
-
return this.
|
|
22886
|
+
static getUrl(endpointPath, useToken) {
|
|
22887
|
+
return useToken ? `${this.endpoint}/v1${endpointPath}` : this.endpoint + endpointPath;
|
|
22888
|
+
}
|
|
22889
|
+
static async getHeaders(user, useToken) {
|
|
22890
|
+
if (!useToken)
|
|
22891
|
+
return { 'Content-Type': 'application/json' };
|
|
22892
|
+
const token = await user.getToken();
|
|
22893
|
+
return {
|
|
22894
|
+
'Content-Type': 'application/json',
|
|
22895
|
+
Authorization: `Bearer ${token}`,
|
|
22896
|
+
};
|
|
22897
|
+
}
|
|
22898
|
+
static Get(user, endpointPath, useToken) {
|
|
22899
|
+
return this.Fetch({ user, endpointPath, method: 'GET', body: null, useToken });
|
|
22836
22900
|
}
|
|
22837
|
-
static Post(user, endpointPath, body = null) {
|
|
22838
|
-
return this.Fetch({ user, endpointPath, method: 'POST', body });
|
|
22901
|
+
static Post(user, endpointPath, body = null, useToken) {
|
|
22902
|
+
return this.Fetch({ user, endpointPath, method: 'POST', body, useToken });
|
|
22839
22903
|
}
|
|
22840
|
-
static Put(user, endpointPath, body) {
|
|
22841
|
-
return this.Fetch({ user, endpointPath, method: 'PUT', body });
|
|
22904
|
+
static Put(user, endpointPath, body, useToken) {
|
|
22905
|
+
return this.Fetch({ user, endpointPath, method: 'PUT', body, useToken });
|
|
22842
22906
|
}
|
|
22843
|
-
static Patch(user, endpointPath, body) {
|
|
22844
|
-
return this.Fetch({ user, endpointPath, method: 'PATCH', body });
|
|
22907
|
+
static Patch(user, endpointPath, body, useToken) {
|
|
22908
|
+
return this.Fetch({ user, endpointPath, method: 'PATCH', body, useToken });
|
|
22845
22909
|
}
|
|
22846
|
-
static Delete(user, endpointPath, body) {
|
|
22847
|
-
return this.Fetch({ user, endpointPath, method: 'DELETE', body });
|
|
22910
|
+
static Delete(user, endpointPath, body, useToken) {
|
|
22911
|
+
return this.Fetch({ user, endpointPath, method: 'DELETE', body, useToken });
|
|
22848
22912
|
}
|
|
22849
22913
|
}
|
|
22850
22914
|
|
|
@@ -22861,6 +22925,9 @@ class TfrShop {
|
|
|
22861
22925
|
constructor(brandId, firebase) {
|
|
22862
22926
|
this.brandId = brandId;
|
|
22863
22927
|
this.firebase = firebase;
|
|
22928
|
+
const config = Config.getInstance().config;
|
|
22929
|
+
TfrShop.avatarTimeout = config.avatarTimeout ? Number(config.avatarTimeout) : 120000;
|
|
22930
|
+
TfrShop.vtoTimeout = config.vtoTimeout ? Number(config.vtoTimeout) : 120000;
|
|
22864
22931
|
}
|
|
22865
22932
|
get user() {
|
|
22866
22933
|
return this.firebase.user;
|
|
@@ -22868,6 +22935,9 @@ class TfrShop {
|
|
|
22868
22935
|
get isLoggedIn() {
|
|
22869
22936
|
return !this.firebase || Boolean(this.user.id);
|
|
22870
22937
|
}
|
|
22938
|
+
onInit() {
|
|
22939
|
+
return this.firebase.onInit();
|
|
22940
|
+
}
|
|
22871
22941
|
async tryOn(colorwaySizeAssetSku) {
|
|
22872
22942
|
if (!this.isLoggedIn)
|
|
22873
22943
|
throw new UserNotLoggedInError();
|
|
@@ -22876,8 +22946,8 @@ class TfrShop {
|
|
|
22876
22946
|
return frames;
|
|
22877
22947
|
}
|
|
22878
22948
|
catch (error) {
|
|
22879
|
-
if (error instanceof NoFramesFoundError)
|
|
22880
|
-
throw
|
|
22949
|
+
if (!(error instanceof NoFramesFoundError))
|
|
22950
|
+
throw error;
|
|
22881
22951
|
return this.requestThenGetColorwaySizeAssetFrames(colorwaySizeAssetSku);
|
|
22882
22952
|
}
|
|
22883
22953
|
}
|
|
@@ -22888,13 +22958,13 @@ class TfrShop {
|
|
|
22888
22958
|
const cancel = setTimeout(() => {
|
|
22889
22959
|
unsubscribe();
|
|
22890
22960
|
throw new RequestTimeoutError();
|
|
22891
|
-
}, TfrShop.
|
|
22961
|
+
}, TfrShop.avatarTimeout);
|
|
22892
22962
|
const snapshot = await promise;
|
|
22893
22963
|
clearTimeout(cancel);
|
|
22894
22964
|
const userProfile = snapshot.docs[0].data();
|
|
22895
22965
|
return userProfile.avatar_status === 'CREATED';
|
|
22896
22966
|
}
|
|
22897
|
-
async
|
|
22967
|
+
async getRecommendedSizes(brandStyleId) {
|
|
22898
22968
|
if (!this.isLoggedIn)
|
|
22899
22969
|
throw new UserNotLoggedInError();
|
|
22900
22970
|
const res = await Fetcher.Get(this.user, `/styles/${brandStyleId}/recommendation`);
|
|
@@ -22920,10 +22990,23 @@ class TfrShop {
|
|
|
22920
22990
|
return getFirebaseError(error);
|
|
22921
22991
|
}
|
|
22922
22992
|
}
|
|
22923
|
-
|
|
22993
|
+
async submitTelephoneNumber(tel) {
|
|
22994
|
+
const sanitizedTel = tel.replace(/[^\+0-9]/g, '');
|
|
22995
|
+
const res = await Fetcher.Post(this.user, '/ios-app-link', { phone_number: sanitizedTel }, false);
|
|
22996
|
+
console.log(res);
|
|
22997
|
+
}
|
|
22998
|
+
async awaitColorwaySizeAssetFrames(colorwaySizeAssetSKU) {
|
|
22924
22999
|
if (!this.isLoggedIn)
|
|
22925
23000
|
throw new UserNotLoggedInError();
|
|
22926
|
-
|
|
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
|
+
}
|
|
22927
23010
|
}
|
|
22928
23011
|
async requestThenGetColorwaySizeAssetFrames(colorwaySizeAssetSku) {
|
|
22929
23012
|
var _a, _b;
|
|
@@ -22992,8 +23075,26 @@ class TfrShop {
|
|
|
22992
23075
|
return frames;
|
|
22993
23076
|
}
|
|
22994
23077
|
}
|
|
22995
|
-
TfrShop.
|
|
22996
|
-
|
|
23078
|
+
TfrShop.avatarTimeout = 120000;
|
|
23079
|
+
TfrShop.vtoTimeout = 120000;
|
|
23080
|
+
const initShop = (brandId, env = 'dev') => {
|
|
23081
|
+
if (env === 'dev' || env === 'development')
|
|
23082
|
+
console.warn('TfrShop is in development mode');
|
|
23083
|
+
Config.getInstance().setEnv(env);
|
|
23084
|
+
return new TfrShop(brandId, new Firebase());
|
|
23085
|
+
};
|
|
23086
|
+
|
|
23087
|
+
// Code generated by tygo. DO NOT EDIT.
|
|
23088
|
+
|
|
23089
|
+
var requests = /*#__PURE__*/Object.freeze({
|
|
23090
|
+
__proto__: null
|
|
23091
|
+
});
|
|
23092
|
+
|
|
23093
|
+
// Code generated by tygo. DO NOT EDIT.
|
|
23094
|
+
|
|
23095
|
+
var responses = /*#__PURE__*/Object.freeze({
|
|
23096
|
+
__proto__: null
|
|
23097
|
+
});
|
|
22997
23098
|
|
|
22998
23099
|
var AvatarState;
|
|
22999
23100
|
(function (AvatarState) {
|
|
@@ -23007,5 +23108,7 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
23007
23108
|
get AvatarState () { return AvatarState; }
|
|
23008
23109
|
});
|
|
23009
23110
|
|
|
23010
|
-
|
|
23111
|
+
const VTO_TIMEOUT_MS = TfrShop.vtoTimeout;
|
|
23112
|
+
|
|
23113
|
+
export { errors as Errors, VTO_TIMEOUT_MS, initShop, requests, responses, index as types };
|
|
23011
23114
|
//# sourceMappingURL=index.js.map
|