@thefittingroom/shop-ui 0.0.3 → 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.dev +0 -1
- package/.env.prod +0 -1
- package/README.md +2 -1
- package/dist/esm/index.js +38 -19
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +80 -81
- package/dist/esm/init.d.ts +1 -1
- package/package.json +4 -4
package/.env.dev
CHANGED
package/.env.prod
CHANGED
package/README.md
CHANGED
|
@@ -35,7 +35,8 @@ const hooks: TfrHooks = {
|
|
|
35
35
|
// the div id to contain the modal elements
|
|
36
36
|
const modalDivId: string = 'tfr-modal'
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
// initFittingRoom is an async function and must be awaited
|
|
39
|
+
const tfr = await initFittingRoom(shopId, modalDivId, hooks)
|
|
39
40
|
|
|
40
41
|
// on page nav to new product
|
|
41
42
|
tfr.setSku(sku)
|
package/dist/esm/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* thefittingroom v0.0.
|
|
2
|
+
* thefittingroom v0.0.5 (2023-07-19T15:33:11.693Z)
|
|
3
3
|
* Copyright 2022-present, TheFittingRoom, Inc. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
/*!
|
|
6
|
-
* thefittingroom v0.0.
|
|
6
|
+
* thefittingroom v0.0.7 (2023-07-19T15:29:31.094Z)
|
|
7
7
|
* Copyright 2022-present, TheFittingRoom, Inc. All rights reserved.
|
|
8
8
|
*/
|
|
9
9
|
/**
|
|
@@ -22813,6 +22813,20 @@ class FirebaseUser {
|
|
|
22813
22813
|
const userProfile = await Ol(Aa(this.firestore, 'users', this.id));
|
|
22814
22814
|
return userProfile.data();
|
|
22815
22815
|
}
|
|
22816
|
+
watchUserProfileForChanges(predicate, timeout) {
|
|
22817
|
+
let unsub;
|
|
22818
|
+
const q = sl(Ta(this.firestore, 'users'), rl(Eh(), '==', this.id));
|
|
22819
|
+
const cancel = setTimeout(() => unsub(), timeout);
|
|
22820
|
+
return new Promise((resolve) => {
|
|
22821
|
+
unsub = jl(q, (snapshot) => {
|
|
22822
|
+
if (!predicate(snapshot))
|
|
22823
|
+
return;
|
|
22824
|
+
clearTimeout(cancel);
|
|
22825
|
+
unsub();
|
|
22826
|
+
resolve(snapshot.docs[0].data());
|
|
22827
|
+
});
|
|
22828
|
+
});
|
|
22829
|
+
}
|
|
22816
22830
|
async login(username, password) {
|
|
22817
22831
|
if (this.auth.currentUser)
|
|
22818
22832
|
await this.auth.signOut();
|
|
@@ -22833,9 +22847,15 @@ class FirebaseUser {
|
|
|
22833
22847
|
|
|
22834
22848
|
class Firebase {
|
|
22835
22849
|
constructor() {
|
|
22836
|
-
this.promisefyOnSnapshot = (q) => {
|
|
22850
|
+
this.promisefyOnSnapshot = (q, unsubscribeWhenData) => {
|
|
22837
22851
|
let unsub;
|
|
22838
|
-
const promise = new Promise((resolve) =>
|
|
22852
|
+
const promise = new Promise((resolve) => {
|
|
22853
|
+
unsub = jl(q, (snapshot) => {
|
|
22854
|
+
resolve(snapshot);
|
|
22855
|
+
if (unsubscribeWhenData)
|
|
22856
|
+
unsub();
|
|
22857
|
+
});
|
|
22858
|
+
});
|
|
22839
22859
|
return { promise, unsubscribe: () => unsub() };
|
|
22840
22860
|
};
|
|
22841
22861
|
const firebaseKeys = Config.getInstance().firebase;
|
|
@@ -22846,9 +22866,9 @@ class Firebase {
|
|
|
22846
22866
|
onInit() {
|
|
22847
22867
|
return this.user.onInit();
|
|
22848
22868
|
}
|
|
22849
|
-
query(collectionName, constraint) {
|
|
22869
|
+
query(collectionName, constraint, unsubscribeWhenData = true) {
|
|
22850
22870
|
const q = sl(Ta(this.firestore, collectionName), constraint);
|
|
22851
|
-
return this.promisefyOnSnapshot(q);
|
|
22871
|
+
return this.promisefyOnSnapshot(q, unsubscribeWhenData);
|
|
22852
22872
|
}
|
|
22853
22873
|
getDocs(collectionName, constraints) {
|
|
22854
22874
|
const q = sl(Ta(this.firestore, collectionName), ...constraints);
|
|
@@ -22866,7 +22886,6 @@ const getFirebaseError = (e) => {
|
|
|
22866
22886
|
};
|
|
22867
22887
|
|
|
22868
22888
|
const asyncTry = (promise) => promise.then((data) => [null, data]).catch((error) => [error]);
|
|
22869
|
-
const asyncWait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
22870
22889
|
|
|
22871
22890
|
class Fetcher {
|
|
22872
22891
|
static get endpoint() {
|
|
@@ -23000,17 +23019,14 @@ class TfrShop {
|
|
|
23000
23019
|
console.log(res);
|
|
23001
23020
|
}
|
|
23002
23021
|
async awaitColorwaySizeAssetFrames(colorwaySizeAssetSKU) {
|
|
23022
|
+
var _a, _b, _c, _d;
|
|
23003
23023
|
if (!this.isLoggedIn)
|
|
23004
23024
|
throw new UserNotLoggedInError();
|
|
23005
|
-
|
|
23006
|
-
|
|
23007
|
-
|
|
23008
|
-
|
|
23009
|
-
|
|
23010
|
-
catch (_a) {
|
|
23011
|
-
await asyncWait(1500);
|
|
23012
|
-
return this.awaitColorwaySizeAssetFrames(colorwaySizeAssetSKU);
|
|
23013
|
-
}
|
|
23025
|
+
const predicate = (data) => { var _a, _b, _c; return Boolean((_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]); };
|
|
23026
|
+
const userProfile = (await this.user.watchUserProfileForChanges(predicate, TfrShop.vtoTimeout));
|
|
23027
|
+
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))
|
|
23028
|
+
throw new NoFramesFoundError();
|
|
23029
|
+
return userProfile.vto[this.brandId][colorwaySizeAssetSKU].frames;
|
|
23014
23030
|
}
|
|
23015
23031
|
async requestThenGetColorwaySizeAssetFrames(colorwaySizeAssetSku) {
|
|
23016
23032
|
var _a, _b;
|
|
@@ -36162,7 +36178,7 @@ class FittingRoom {
|
|
|
36162
36178
|
this.shopId = shopId;
|
|
36163
36179
|
this.hooks = hooks;
|
|
36164
36180
|
this.nav = new FittingRoomNav(modalDivId, this.signIn.bind(this), this.forgotPassword.bind(this), this.submitTel.bind(this));
|
|
36165
|
-
this.tfrShop = initShop(Number(this.shopId),
|
|
36181
|
+
this.tfrShop = initShop(Number(this.shopId), process.env.NODE_ENV);
|
|
36166
36182
|
}
|
|
36167
36183
|
get sku() {
|
|
36168
36184
|
return this.nav.sku;
|
|
@@ -36171,7 +36187,6 @@ class FittingRoom {
|
|
|
36171
36187
|
return this.tfrShop;
|
|
36172
36188
|
}
|
|
36173
36189
|
async onInit() {
|
|
36174
|
-
console.log('INIT');
|
|
36175
36190
|
const loggedIn = await this.tfrShop.onInit();
|
|
36176
36191
|
if (loggedIn && this.hooks.onLogin)
|
|
36177
36192
|
this.hooks.onLogin();
|
|
@@ -36264,7 +36279,11 @@ class FittingRoom {
|
|
|
36264
36279
|
}
|
|
36265
36280
|
}
|
|
36266
36281
|
|
|
36267
|
-
const initFittingRoom = (shopId, modalDivId, hooks) =>
|
|
36282
|
+
const initFittingRoom = async (shopId, modalDivId, hooks) => {
|
|
36283
|
+
const tfr = new FittingRoom(shopId, modalDivId, hooks);
|
|
36284
|
+
await tfr.onInit();
|
|
36285
|
+
return tfr;
|
|
36286
|
+
};
|
|
36268
36287
|
|
|
36269
36288
|
export { VTO_TIMEOUT_MS, initFittingRoom };
|
|
36270
36289
|
//# sourceMappingURL=index.js.map
|