@thefittingroom/shop-ui 0.0.1 → 0.0.3
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 +31 -57
- package/dist/esm/index.js +24 -12
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +4 -4
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -1,75 +1,49 @@
|
|
|
1
|
-
# The Fitting Room - Shop
|
|
1
|
+
# The Fitting Room - Shop UI
|
|
2
|
+
|
|
3
|
+
Modal UI for The Fitting Room. Provides UI hooks to integrate into the parent UI.
|
|
2
4
|
|
|
3
5
|
## Installation
|
|
4
6
|
|
|
5
7
|
```bash
|
|
6
|
-
|
|
7
|
-
ASSETS_URL=https://assets.dev.thefittingroom.xyz/shop-sdk/assets
|
|
8
|
-
|
|
9
|
-
# build everytime changes are detected
|
|
10
|
-
npm run dev:rollup
|
|
11
|
-
# run a live server on localhost:3030 and disable cors
|
|
12
|
-
npx live-server --host=localhost --port=3030 --cors
|
|
8
|
+
npm i @thefittingroom/shop-ui
|
|
13
9
|
```
|
|
14
10
|
|
|
15
|
-
|
|
11
|
+
or
|
|
16
12
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
## Merges on main branch
|
|
13
|
+
```bash
|
|
14
|
+
yarn @thefittingroom/shop-ui
|
|
15
|
+
```
|
|
21
16
|
|
|
22
|
-
|
|
23
|
-
You can access the development builds by using a commit sha on main like this:
|
|
17
|
+
## Usage
|
|
24
18
|
|
|
25
|
-
|
|
19
|
+
```typescript
|
|
20
|
+
import { initFittingRoom } from '@thefittingroom/shop-ui'
|
|
26
21
|
|
|
27
|
-
|
|
22
|
+
// Your brandId: Number
|
|
23
|
+
const shopId: number = 9001
|
|
28
24
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
// UI Hooks
|
|
26
|
+
const hooks: TfrHooks = {
|
|
27
|
+
onLoading: () => {},
|
|
28
|
+
onLoadingComplete: () => {},
|
|
29
|
+
onAvatarReady: (frames: string[]) => {},
|
|
30
|
+
onError: () => {},
|
|
31
|
+
onLogin: () => {},
|
|
32
|
+
onLogout: () => {},
|
|
33
|
+
}
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
InitLocale()
|
|
35
|
+
// the div id to contain the modal elements
|
|
36
|
+
const modalDivId: string = 'tfr-modal'
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
let tfr = InitFittingRoom(1, 'tfr-tryon-modal')
|
|
38
|
+
const tfr = initFittingRoom(shopId, modalDivId, hooks)
|
|
40
39
|
|
|
41
|
-
//
|
|
42
|
-
|
|
43
|
-
signout.addEventListener('click', () => {
|
|
44
|
-
// pass an empty sku to the onSignout since its not being used in a modal
|
|
45
|
-
// call the onSignout function wrapper to return a promise
|
|
46
|
-
// wait for the promise
|
|
47
|
-
// shows signed out modal by default
|
|
48
|
-
tfr
|
|
49
|
-
.onSignout('')()
|
|
50
|
-
.then(() => {
|
|
51
|
-
// do something after signing out of the fitting room
|
|
52
|
-
})
|
|
53
|
-
})
|
|
40
|
+
// on page nav to new product
|
|
41
|
+
tfr.setSku(sku)
|
|
54
42
|
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
tfr.TryOn('5003-007-08')
|
|
58
|
-
})
|
|
43
|
+
// close the modal
|
|
44
|
+
tfr.close()
|
|
59
45
|
```
|
|
60
46
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
You can call `SetLocale` to change the language of the sdk without using url searchParams.
|
|
64
|
-
|
|
65
|
-
```javascript
|
|
66
|
-
SetLocale('en')
|
|
67
|
-
.then(() => {
|
|
68
|
-
// do something after setting the locale
|
|
69
|
-
})
|
|
70
|
-
.catch((err) => {
|
|
71
|
-
// handle error
|
|
72
|
-
})
|
|
73
|
-
```
|
|
47
|
+
Several low level methods are exposed via `tfr.shop`
|
|
74
48
|
|
|
75
|
-
|
|
49
|
+
See [@thefittingroom/sdk](https://github.com/TheFittingRoom/shop-sdk/tree/main)
|
package/dist/esm/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* thefittingroom v0.0.
|
|
2
|
+
* thefittingroom v0.0.3 (2023-07-18T23:19:14.875Z)
|
|
3
3
|
* Copyright 2022-present, TheFittingRoom, Inc. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
/*!
|
|
6
|
-
* thefittingroom v0.0.
|
|
6
|
+
* thefittingroom v0.0.6 (2023-07-18T23:18:09.529Z)
|
|
7
7
|
* Copyright 2022-present, TheFittingRoom, Inc. All rights reserved.
|
|
8
8
|
*/
|
|
9
9
|
/**
|
|
@@ -16354,8 +16354,8 @@ const devKeys = {
|
|
|
16354
16354
|
url: "https://tfr.dev.thefittingroom.xyz",
|
|
16355
16355
|
},
|
|
16356
16356
|
config: {
|
|
16357
|
-
avatarTimeout: "120000",
|
|
16358
|
-
vtoTimeout: "120000",
|
|
16357
|
+
avatarTimeout: Number("120000"),
|
|
16358
|
+
vtoTimeout: Number("120000"),
|
|
16359
16359
|
},
|
|
16360
16360
|
};
|
|
16361
16361
|
const prodKeys = {
|
|
@@ -16371,8 +16371,8 @@ const prodKeys = {
|
|
|
16371
16371
|
url: "https://tfr.p.thefittingroom.xyz",
|
|
16372
16372
|
},
|
|
16373
16373
|
config: {
|
|
16374
|
-
avatarTimeout: "120000",
|
|
16375
|
-
vtoTimeout: "120000",
|
|
16374
|
+
avatarTimeout: Number("120000"),
|
|
16375
|
+
vtoTimeout: Number("120000"),
|
|
16376
16376
|
},
|
|
16377
16377
|
};
|
|
16378
16378
|
|
|
@@ -22866,9 +22866,10 @@ const getFirebaseError = (e) => {
|
|
|
22866
22866
|
};
|
|
22867
22867
|
|
|
22868
22868
|
const asyncTry = (promise) => promise.then((data) => [null, data]).catch((error) => [error]);
|
|
22869
|
+
const asyncWait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
22869
22870
|
|
|
22870
22871
|
class Fetcher {
|
|
22871
|
-
static endpoint() {
|
|
22872
|
+
static get endpoint() {
|
|
22872
22873
|
const api = Config.getInstance().api;
|
|
22873
22874
|
return api.url;
|
|
22874
22875
|
}
|
|
@@ -22998,10 +22999,18 @@ class TfrShop {
|
|
|
22998
22999
|
const res = await Fetcher.Post(this.user, '/ios-app-link', { phone_number: sanitizedTel }, false);
|
|
22999
23000
|
console.log(res);
|
|
23000
23001
|
}
|
|
23001
|
-
awaitColorwaySizeAssetFrames(colorwaySizeAssetSKU) {
|
|
23002
|
+
async awaitColorwaySizeAssetFrames(colorwaySizeAssetSKU) {
|
|
23002
23003
|
if (!this.isLoggedIn)
|
|
23003
23004
|
throw new UserNotLoggedInError();
|
|
23004
|
-
|
|
23005
|
+
console.log('polling');
|
|
23006
|
+
try {
|
|
23007
|
+
const frames = await this.getColorwaySizeAssetFrames(colorwaySizeAssetSKU);
|
|
23008
|
+
return frames;
|
|
23009
|
+
}
|
|
23010
|
+
catch (_a) {
|
|
23011
|
+
await asyncWait(1500);
|
|
23012
|
+
return this.awaitColorwaySizeAssetFrames(colorwaySizeAssetSKU);
|
|
23013
|
+
}
|
|
23005
23014
|
}
|
|
23006
23015
|
async requestThenGetColorwaySizeAssetFrames(colorwaySizeAssetSku) {
|
|
23007
23016
|
var _a, _b;
|
|
@@ -23070,6 +23079,8 @@ class TfrShop {
|
|
|
23070
23079
|
return frames;
|
|
23071
23080
|
}
|
|
23072
23081
|
}
|
|
23082
|
+
TfrShop.avatarTimeout = 120000;
|
|
23083
|
+
TfrShop.vtoTimeout = 120000;
|
|
23073
23084
|
const initShop = (brandId, env = 'dev') => {
|
|
23074
23085
|
if (env === 'dev' || env === 'development')
|
|
23075
23086
|
console.warn('TfrShop is in development mode');
|
|
@@ -36151,7 +36162,7 @@ class FittingRoom {
|
|
|
36151
36162
|
this.shopId = shopId;
|
|
36152
36163
|
this.hooks = hooks;
|
|
36153
36164
|
this.nav = new FittingRoomNav(modalDivId, this.signIn.bind(this), this.forgotPassword.bind(this), this.submitTel.bind(this));
|
|
36154
|
-
this.tfrShop = initShop(Number(this.shopId), "
|
|
36165
|
+
this.tfrShop = initShop(Number(this.shopId), "prod");
|
|
36155
36166
|
}
|
|
36156
36167
|
get sku() {
|
|
36157
36168
|
return this.nav.sku;
|
|
@@ -36160,6 +36171,7 @@ class FittingRoom {
|
|
|
36160
36171
|
return this.tfrShop;
|
|
36161
36172
|
}
|
|
36162
36173
|
async onInit() {
|
|
36174
|
+
console.log('INIT');
|
|
36163
36175
|
const loggedIn = await this.tfrShop.onInit();
|
|
36164
36176
|
if (loggedIn && this.hooks.onLogin)
|
|
36165
36177
|
this.hooks.onLogin();
|
|
@@ -36195,7 +36207,8 @@ class FittingRoom {
|
|
|
36195
36207
|
this.nav.onNotCreated();
|
|
36196
36208
|
break;
|
|
36197
36209
|
case AvatarState.PENDING:
|
|
36198
|
-
this.
|
|
36210
|
+
if (this.hooks.onLoading)
|
|
36211
|
+
this.hooks.onLoading();
|
|
36199
36212
|
break;
|
|
36200
36213
|
case AvatarState.CREATED:
|
|
36201
36214
|
console.debug('avatar_state: created');
|
|
@@ -36231,7 +36244,6 @@ class FittingRoom {
|
|
|
36231
36244
|
try {
|
|
36232
36245
|
if (this.hooks.onLoading)
|
|
36233
36246
|
this.hooks.onLoading();
|
|
36234
|
-
this.nav.onLoading();
|
|
36235
36247
|
const frames = await this.tfrShop.tryOn(this.sku);
|
|
36236
36248
|
this.nav.close();
|
|
36237
36249
|
if (this.hooks.onAvatarReady)
|