@thefittingroom/sdk 0.0.6 → 0.0.7
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 +3 -1
- package/dist/esm/api/shop.d.ts +1 -1
- package/dist/esm/firebase/firebase-user.d.ts +3 -2
- package/dist/esm/firebase/firebase.d.ts +1 -1
- package/dist/esm/index.js +31 -15
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +79 -80
- package/dist/esm/index.min.js.map +1 -1
- package/dist/esm/types/index.d.ts +29 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -47,7 +47,6 @@ const brandId = 9001
|
|
|
47
47
|
// The environment: 'development', 'dev', 'production', 'prod'
|
|
48
48
|
const env = 'dev'
|
|
49
49
|
const shop = initShop(brandId, env)
|
|
50
|
-
await shop.onInit()
|
|
51
50
|
```
|
|
52
51
|
|
|
53
52
|
### Shop API
|
|
@@ -55,6 +54,9 @@ await shop.onInit()
|
|
|
55
54
|
#### Auth
|
|
56
55
|
|
|
57
56
|
```typescript
|
|
57
|
+
// Hook used to check authentication, return isLoggedIn Promise<boolean>
|
|
58
|
+
await shop.onInit()
|
|
59
|
+
|
|
58
60
|
// Login user with session
|
|
59
61
|
shop.user.login(username, password)
|
|
60
62
|
|
package/dist/esm/api/shop.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export declare class TfrShop {
|
|
|
10
10
|
get user(): import("..").FirebaseUser;
|
|
11
11
|
get isLoggedIn(): boolean;
|
|
12
12
|
onInit(): Promise<boolean>;
|
|
13
|
-
tryOn(colorwaySizeAssetSku: string): Promise<
|
|
13
|
+
tryOn(colorwaySizeAssetSku: string): Promise<types.TryOnFrames>;
|
|
14
14
|
awaitAvatarCreated(): Promise<boolean>;
|
|
15
15
|
getRecommendedSizes(brandStyleId: string): Promise<SizeRecommendation>;
|
|
16
16
|
getStyles(ids: number[], skus: string[]): Promise<Map<number, types.FirestoreStyle>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as firebase from 'firebase/app';
|
|
2
2
|
import * as firebaseAuth from 'firebase/auth';
|
|
3
|
-
import { Firestore } from 'firebase/firestore';
|
|
3
|
+
import { DocumentData, Firestore, QuerySnapshot } from 'firebase/firestore';
|
|
4
4
|
export declare class FirebaseUser {
|
|
5
5
|
private readonly firestore;
|
|
6
6
|
private user;
|
|
@@ -10,7 +10,8 @@ export declare class FirebaseUser {
|
|
|
10
10
|
onInit(): Promise<boolean>;
|
|
11
11
|
setUser(user: firebaseAuth.User): void;
|
|
12
12
|
getToken(): Promise<string>;
|
|
13
|
-
getUserProfile(): Promise<
|
|
13
|
+
getUserProfile(): Promise<DocumentData>;
|
|
14
|
+
watchUserProfileForChanges(predicate: (data: QuerySnapshot<DocumentData>) => boolean, timeout: number): Promise<DocumentData>;
|
|
14
15
|
login(username: string, password: string): Promise<void>;
|
|
15
16
|
logout(): Promise<void>;
|
|
16
17
|
sendPasswordResetEmail(email: string): Promise<void>;
|
|
@@ -5,7 +5,7 @@ export declare class Firebase {
|
|
|
5
5
|
readonly firestore: Firestore;
|
|
6
6
|
constructor();
|
|
7
7
|
onInit(): Promise<boolean>;
|
|
8
|
-
query(collectionName: string, constraint: QueryFieldFilterConstraint): {
|
|
8
|
+
query(collectionName: string, constraint: QueryFieldFilterConstraint, unsubscribeWhenData?: boolean): {
|
|
9
9
|
promise: Promise<QuerySnapshot<DocumentData>>;
|
|
10
10
|
unsubscribe: () => void;
|
|
11
11
|
};
|
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* thefittingroom v0.0.
|
|
2
|
+
* thefittingroom v0.0.7 (2023-07-19T15:29:31.094Z)
|
|
3
3
|
* Copyright 2022-present, TheFittingRoom, Inc. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
@@ -22809,6 +22809,20 @@ class FirebaseUser {
|
|
|
22809
22809
|
const userProfile = await Ol(Aa(this.firestore, 'users', this.id));
|
|
22810
22810
|
return userProfile.data();
|
|
22811
22811
|
}
|
|
22812
|
+
watchUserProfileForChanges(predicate, timeout) {
|
|
22813
|
+
let unsub;
|
|
22814
|
+
const q = sl(Ta(this.firestore, 'users'), rl(Eh(), '==', this.id));
|
|
22815
|
+
const cancel = setTimeout(() => unsub(), timeout);
|
|
22816
|
+
return new Promise((resolve) => {
|
|
22817
|
+
unsub = jl(q, (snapshot) => {
|
|
22818
|
+
if (!predicate(snapshot))
|
|
22819
|
+
return;
|
|
22820
|
+
clearTimeout(cancel);
|
|
22821
|
+
unsub();
|
|
22822
|
+
resolve(snapshot.docs[0].data());
|
|
22823
|
+
});
|
|
22824
|
+
});
|
|
22825
|
+
}
|
|
22812
22826
|
async login(username, password) {
|
|
22813
22827
|
if (this.auth.currentUser)
|
|
22814
22828
|
await this.auth.signOut();
|
|
@@ -22829,9 +22843,15 @@ class FirebaseUser {
|
|
|
22829
22843
|
|
|
22830
22844
|
class Firebase {
|
|
22831
22845
|
constructor() {
|
|
22832
|
-
this.promisefyOnSnapshot = (q) => {
|
|
22846
|
+
this.promisefyOnSnapshot = (q, unsubscribeWhenData) => {
|
|
22833
22847
|
let unsub;
|
|
22834
|
-
const promise = new Promise((resolve) =>
|
|
22848
|
+
const promise = new Promise((resolve) => {
|
|
22849
|
+
unsub = jl(q, (snapshot) => {
|
|
22850
|
+
resolve(snapshot);
|
|
22851
|
+
if (unsubscribeWhenData)
|
|
22852
|
+
unsub();
|
|
22853
|
+
});
|
|
22854
|
+
});
|
|
22835
22855
|
return { promise, unsubscribe: () => unsub() };
|
|
22836
22856
|
};
|
|
22837
22857
|
const firebaseKeys = Config.getInstance().firebase;
|
|
@@ -22842,9 +22862,9 @@ class Firebase {
|
|
|
22842
22862
|
onInit() {
|
|
22843
22863
|
return this.user.onInit();
|
|
22844
22864
|
}
|
|
22845
|
-
query(collectionName, constraint) {
|
|
22865
|
+
query(collectionName, constraint, unsubscribeWhenData = true) {
|
|
22846
22866
|
const q = sl(Ta(this.firestore, collectionName), constraint);
|
|
22847
|
-
return this.promisefyOnSnapshot(q);
|
|
22867
|
+
return this.promisefyOnSnapshot(q, unsubscribeWhenData);
|
|
22848
22868
|
}
|
|
22849
22869
|
getDocs(collectionName, constraints) {
|
|
22850
22870
|
const q = sl(Ta(this.firestore, collectionName), ...constraints);
|
|
@@ -22862,7 +22882,6 @@ const getFirebaseError = (e) => {
|
|
|
22862
22882
|
};
|
|
22863
22883
|
|
|
22864
22884
|
const asyncTry = (promise) => promise.then((data) => [null, data]).catch((error) => [error]);
|
|
22865
|
-
const asyncWait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
22866
22885
|
|
|
22867
22886
|
class Fetcher {
|
|
22868
22887
|
static get endpoint() {
|
|
@@ -22996,17 +23015,14 @@ class TfrShop {
|
|
|
22996
23015
|
console.log(res);
|
|
22997
23016
|
}
|
|
22998
23017
|
async awaitColorwaySizeAssetFrames(colorwaySizeAssetSKU) {
|
|
23018
|
+
var _a, _b, _c, _d;
|
|
22999
23019
|
if (!this.isLoggedIn)
|
|
23000
23020
|
throw new UserNotLoggedInError();
|
|
23001
|
-
|
|
23002
|
-
|
|
23003
|
-
|
|
23004
|
-
|
|
23005
|
-
|
|
23006
|
-
catch (_a) {
|
|
23007
|
-
await asyncWait(1500);
|
|
23008
|
-
return this.awaitColorwaySizeAssetFrames(colorwaySizeAssetSKU);
|
|
23009
|
-
}
|
|
23021
|
+
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]); };
|
|
23022
|
+
const userProfile = (await this.user.watchUserProfileForChanges(predicate, TfrShop.vtoTimeout));
|
|
23023
|
+
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))
|
|
23024
|
+
throw new NoFramesFoundError();
|
|
23025
|
+
return userProfile.vto[this.brandId][colorwaySizeAssetSKU].frames;
|
|
23010
23026
|
}
|
|
23011
23027
|
async requestThenGetColorwaySizeAssetFrames(colorwaySizeAssetSku) {
|
|
23012
23028
|
var _a, _b;
|