@thefittingroom/shop-ui 0.0.14 → 0.0.16
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 +7 -1
- package/dist/esm/components/locale.d.ts +1 -0
- package/dist/esm/index.js +41 -9
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +3 -3
- package/dist/esm/tfr.d.ts +1 -0
- package/index.html +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ const hooks: TfrHooks = {
|
|
|
27
27
|
onLoading: () => {},
|
|
28
28
|
onLoadingComplete: () => {},
|
|
29
29
|
onVtoReady: (frames: string[]) => {},
|
|
30
|
-
onError: () => {},
|
|
30
|
+
onError: (error: string) => {},
|
|
31
31
|
onLogin: () => {},
|
|
32
32
|
onLogout: () => {},
|
|
33
33
|
}
|
|
@@ -39,8 +39,14 @@ const modalDivId: string = 'tfr-modal'
|
|
|
39
39
|
const tfr = await initFittingRoom(shopId, modalDivId, hooks)
|
|
40
40
|
|
|
41
41
|
// on page nav to new product
|
|
42
|
+
// * Required for VTO
|
|
42
43
|
tfr.setSku(sku)
|
|
43
44
|
|
|
45
|
+
// on user login to brand site
|
|
46
|
+
// * Required for VTO
|
|
47
|
+
// e.g. uuid, email address, username, internal database Id
|
|
48
|
+
tft.setBrandUserId(brandUserId)
|
|
49
|
+
|
|
44
50
|
// close the modal
|
|
45
51
|
tfr.close()
|
|
46
52
|
```
|
package/dist/esm/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* thefittingroom v0.0.
|
|
2
|
+
* thefittingroom v0.0.16 (2023-09-05T16:47:56.281Z)
|
|
3
3
|
* Copyright 2022-present, TheFittingRoom, Inc. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
/*!
|
|
6
|
-
* thefittingroom v0.0.
|
|
6
|
+
* thefittingroom v0.0.11 (2023-09-04T22:52:56.755Z)
|
|
7
7
|
* Copyright 2022-present, TheFittingRoom, Inc. All rights reserved.
|
|
8
8
|
*/
|
|
9
9
|
/**
|
|
@@ -22772,6 +22772,12 @@ class RecommendedAvailableSizesError extends Error {
|
|
|
22772
22772
|
this.available_sizes = available_sizes;
|
|
22773
22773
|
}
|
|
22774
22774
|
}
|
|
22775
|
+
class BrandUserIdNotSetError extends Error {
|
|
22776
|
+
constructor() {
|
|
22777
|
+
super('brand user id not set');
|
|
22778
|
+
this.name = 'BrandUserIdNotSetError';
|
|
22779
|
+
}
|
|
22780
|
+
}
|
|
22775
22781
|
// Backend responses
|
|
22776
22782
|
const AvatarNotCreated = 'avatar not created';
|
|
22777
22783
|
|
|
@@ -22784,12 +22790,14 @@ var errors = /*#__PURE__*/Object.freeze({
|
|
|
22784
22790
|
NoColorwaySizeAssetsFoundError: NoColorwaySizeAssetsFoundError,
|
|
22785
22791
|
NoStylesFoundError: NoStylesFoundError,
|
|
22786
22792
|
RecommendedAvailableSizesError: RecommendedAvailableSizesError,
|
|
22793
|
+
BrandUserIdNotSetError: BrandUserIdNotSetError,
|
|
22787
22794
|
AvatarNotCreated: AvatarNotCreated
|
|
22788
22795
|
});
|
|
22789
22796
|
|
|
22790
22797
|
class FirebaseUser {
|
|
22791
22798
|
constructor(firestore, app) {
|
|
22792
22799
|
this.firestore = firestore;
|
|
22800
|
+
this.brandUserId = null;
|
|
22793
22801
|
this.auth = getAuth(app);
|
|
22794
22802
|
this.auth.setPersistence(browserLocalPersistence);
|
|
22795
22803
|
}
|
|
@@ -22809,6 +22817,9 @@ class FirebaseUser {
|
|
|
22809
22817
|
setUser(user) {
|
|
22810
22818
|
this.user = user;
|
|
22811
22819
|
}
|
|
22820
|
+
setBrandUserId(brandUserId) {
|
|
22821
|
+
this.brandUserId = brandUserId;
|
|
22822
|
+
}
|
|
22812
22823
|
async getToken() {
|
|
22813
22824
|
var _a;
|
|
22814
22825
|
if (!((_a = this.user) === null || _a === void 0 ? void 0 : _a.uid))
|
|
@@ -22828,8 +22839,8 @@ class FirebaseUser {
|
|
|
22828
22839
|
const q = sl(Ta(this.firestore, 'users'), rl(Eh(), '==', this.id));
|
|
22829
22840
|
const cancel = setTimeout(() => unsub(), timeout);
|
|
22830
22841
|
return new Promise((resolve) => {
|
|
22831
|
-
unsub = jl(q, (snapshot) => {
|
|
22832
|
-
if (!predicate(snapshot))
|
|
22842
|
+
unsub = jl(q, async (snapshot) => {
|
|
22843
|
+
if (!(await predicate(snapshot)))
|
|
22833
22844
|
return;
|
|
22834
22845
|
clearTimeout(cancel);
|
|
22835
22846
|
unsub();
|
|
@@ -22945,7 +22956,7 @@ class Fetcher {
|
|
|
22945
22956
|
}
|
|
22946
22957
|
}
|
|
22947
22958
|
|
|
22948
|
-
const
|
|
22959
|
+
const testImage = (url) => {
|
|
22949
22960
|
const img = new Image();
|
|
22950
22961
|
img.src = url;
|
|
22951
22962
|
return new Promise((resolve) => {
|
|
@@ -23045,7 +23056,13 @@ class TfrShop {
|
|
|
23045
23056
|
var _a, _b, _c, _d;
|
|
23046
23057
|
if (!this.isLoggedIn)
|
|
23047
23058
|
throw new UserNotLoggedInError();
|
|
23048
|
-
const predicate = (data) => {
|
|
23059
|
+
const predicate = async (data) => {
|
|
23060
|
+
var _a, _b, _c, _d;
|
|
23061
|
+
const frames = (_d = (_c = (_b = (_a = data.docs[0].data()) === null || _a === void 0 ? void 0 : _a.vto) === null || _b === void 0 ? void 0 : _b[this.brandId]) === null || _c === void 0 ? void 0 : _c[colorwaySizeAssetSKU]) === null || _d === void 0 ? void 0 : _d.frames;
|
|
23062
|
+
if (!(frames === null || frames === void 0 ? void 0 : frames.length))
|
|
23063
|
+
return false;
|
|
23064
|
+
return testImage(frames[0]);
|
|
23065
|
+
};
|
|
23049
23066
|
const userProfile = (await this.user.watchUserProfileForChanges(predicate, TfrShop.vtoTimeout));
|
|
23050
23067
|
if (!((_d = (_c = (_b = (_a = userProfile === null || userProfile === void 0 ? void 0 : userProfile.vto) === null || _a === void 0 ? void 0 : _a[this.brandId]) === null || _b === void 0 ? void 0 : _b[colorwaySizeAssetSKU]) === null || _c === void 0 ? void 0 : _c.frames) === null || _d === void 0 ? void 0 : _d.length))
|
|
23051
23068
|
throw new NoFramesFoundError();
|
|
@@ -23106,7 +23123,11 @@ class TfrShop {
|
|
|
23106
23123
|
async requestColorwaySizeAssetFrames(colorwaySizeAssetId) {
|
|
23107
23124
|
if (!this.isLoggedIn)
|
|
23108
23125
|
throw new UserNotLoggedInError();
|
|
23109
|
-
|
|
23126
|
+
if (!this.user.brandUserId)
|
|
23127
|
+
throw new BrandUserIdNotSetError();
|
|
23128
|
+
await Fetcher.Post(this.user, `/colorway-size-assets/${colorwaySizeAssetId}/frames`, {
|
|
23129
|
+
brand_user_id: String(this.user.brandUserId),
|
|
23130
|
+
});
|
|
23110
23131
|
}
|
|
23111
23132
|
async getColorwaySizeAssetFrames(colorwaySizeAssetSKU) {
|
|
23112
23133
|
var _a, _b, _c;
|
|
@@ -23114,7 +23135,7 @@ class TfrShop {
|
|
|
23114
23135
|
const frames = ((_c = (_b = (_a = userProfile === null || userProfile === void 0 ? void 0 : userProfile.vto) === null || _a === void 0 ? void 0 : _a[this.brandId]) === null || _b === void 0 ? void 0 : _b[colorwaySizeAssetSKU]) === null || _c === void 0 ? void 0 : _c.frames) || [];
|
|
23115
23136
|
if (!frames.length)
|
|
23116
23137
|
throw new NoFramesFoundError();
|
|
23117
|
-
const testedImage = await
|
|
23138
|
+
const testedImage = await testImage(frames[0]);
|
|
23118
23139
|
if (!testedImage)
|
|
23119
23140
|
throw new NoFramesFoundError();
|
|
23120
23141
|
return frames;
|
|
@@ -23185,6 +23206,7 @@ const InitImageSlider = (sliderID, onChange) => {
|
|
|
23185
23206
|
var L = {
|
|
23186
23207
|
AssociatedEmail: 'If there is an account associated with that email, We have sent a link to reset your password.',
|
|
23187
23208
|
BackToSignIn: 'Back to sign in',
|
|
23209
|
+
BrandUserIdNotSet: 'User not logged in to brand site.',
|
|
23188
23210
|
CreateAvatarSc: 'Scan the QR code/click link to download our app and create an avatar:',
|
|
23189
23211
|
DontHaveAcc: "Don't have an account?",
|
|
23190
23212
|
DontHaveAvatar: "Whoops! Looks like you don't have an avatar yet.",
|
|
@@ -36275,6 +36297,9 @@ class FittingRoom {
|
|
|
36275
36297
|
this.nav.onError(L.SomethingWentWrong);
|
|
36276
36298
|
}
|
|
36277
36299
|
}
|
|
36300
|
+
setBrandUserId(brandUserId) {
|
|
36301
|
+
this.tfrShop.user.setBrandUserId(brandUserId);
|
|
36302
|
+
}
|
|
36278
36303
|
async submitTel(tel) {
|
|
36279
36304
|
try {
|
|
36280
36305
|
await this.tfrShop.submitTelephoneNumber(tel);
|
|
@@ -36302,6 +36327,8 @@ class FittingRoom {
|
|
|
36302
36327
|
return `${trySizes}. ${L.WeRecommendSize} ${recommendedSizeLabel}.`;
|
|
36303
36328
|
}
|
|
36304
36329
|
async tryOn() {
|
|
36330
|
+
if (!this.shop.isLoggedIn)
|
|
36331
|
+
return this.nav.toScan();
|
|
36305
36332
|
try {
|
|
36306
36333
|
if (this.hooks.onLoading)
|
|
36307
36334
|
this.hooks.onLoading();
|
|
@@ -36311,12 +36338,17 @@ class FittingRoom {
|
|
|
36311
36338
|
this.hooks.onVtoReady(frames);
|
|
36312
36339
|
}
|
|
36313
36340
|
catch (error) {
|
|
36341
|
+
if (error instanceof errors.BrandUserIdNotSetError)
|
|
36342
|
+
return this.nav.onError(L.BrandUserIdNotSet);
|
|
36314
36343
|
if (error instanceof errors.AvatarNotCreatedError)
|
|
36315
36344
|
return this.nav.onError(L.DontHaveAvatar);
|
|
36316
36345
|
if (error instanceof errors.RecommendedAvailableSizesError)
|
|
36317
36346
|
return this.nav.onSizeError(error.recommended_size, error.available_sizes);
|
|
36318
|
-
if (error instanceof errors.UserNotLoggedInError)
|
|
36347
|
+
if (error instanceof errors.UserNotLoggedInError) {
|
|
36348
|
+
if (this.hooks.onLoadingComplete)
|
|
36349
|
+
this.hooks.onLoadingComplete();
|
|
36319
36350
|
return this.nav.toScan();
|
|
36351
|
+
}
|
|
36320
36352
|
console.error(error.message);
|
|
36321
36353
|
this.nav.onError(L.SomethingWentWrong);
|
|
36322
36354
|
}
|