@thefittingroom/sdk 0.0.9 → 0.0.11
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 +6 -0
- package/dist/esm/api/utils.d.ts +1 -1
- package/dist/esm/firebase/firebase-user.d.ts +4 -1
- package/dist/esm/helpers/errors.d.ts +3 -0
- package/dist/esm/index.js +28 -7
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +2 -2
- package/dist/esm/index.min.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -63,6 +63,11 @@ shop.user.login(email, password)
|
|
|
63
63
|
// Logout current user
|
|
64
64
|
shop.user.logout()
|
|
65
65
|
|
|
66
|
+
// Set the brand userId, the internal userId used by the shop/brand
|
|
67
|
+
// This is a required field for requesting a VTO
|
|
68
|
+
// string | number
|
|
69
|
+
shop.user.setBrandUserId(brandUserId)
|
|
70
|
+
|
|
66
71
|
// In order for the user to create an avatar, they'll need to download the mobile application.
|
|
67
72
|
// This will send an SMS to the given phone number with a link to the iOS app
|
|
68
73
|
// No spaces and must include country code e.g. +18005551234
|
|
@@ -113,4 +118,5 @@ UserNotLoggedInError
|
|
|
113
118
|
NoColorwaySizeAssetsFoundError
|
|
114
119
|
NoStylesFoundError
|
|
115
120
|
RecommendedAvailableSizesError
|
|
121
|
+
BrandUserIdNotSetError
|
|
116
122
|
```
|
package/dist/esm/api/utils.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const testImage: (url: string) => Promise<boolean>;
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import * as firebase from 'firebase/app';
|
|
2
2
|
import * as firebaseAuth from 'firebase/auth';
|
|
3
3
|
import { DocumentData, Firestore, QuerySnapshot } from 'firebase/firestore';
|
|
4
|
+
export type BrandUserId = string | number;
|
|
4
5
|
export declare class FirebaseUser {
|
|
5
6
|
private readonly firestore;
|
|
7
|
+
brandUserId: BrandUserId;
|
|
6
8
|
private user;
|
|
7
9
|
private readonly auth;
|
|
8
10
|
constructor(firestore: Firestore, app: firebase.FirebaseApp);
|
|
9
11
|
get id(): string;
|
|
10
12
|
onInit(): Promise<boolean>;
|
|
11
13
|
setUser(user: firebaseAuth.User): void;
|
|
14
|
+
setBrandUserId(brandUserId: BrandUserId): void;
|
|
12
15
|
getToken(): Promise<string>;
|
|
13
16
|
getUserProfile(): Promise<DocumentData>;
|
|
14
|
-
watchUserProfileForChanges(predicate: (data: QuerySnapshot<DocumentData>) => boolean
|
|
17
|
+
watchUserProfileForChanges(predicate: (data: QuerySnapshot<DocumentData>) => Promise<boolean>, timeout: number): Promise<DocumentData>;
|
|
15
18
|
login(username: string, password: string): Promise<void>;
|
|
16
19
|
logout(): Promise<void>;
|
|
17
20
|
sendPasswordResetEmail(email: string): Promise<void>;
|
|
@@ -29,4 +29,7 @@ export declare class RecommendedAvailableSizesError extends Error {
|
|
|
29
29
|
available_sizes: string[];
|
|
30
30
|
constructor(recommended_size: string, available_sizes: string[]);
|
|
31
31
|
}
|
|
32
|
+
export declare class BrandUserIdNotSetError extends Error {
|
|
33
|
+
constructor();
|
|
34
|
+
}
|
|
32
35
|
export declare const AvatarNotCreated = "avatar not created";
|
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* thefittingroom v0.0.
|
|
2
|
+
* thefittingroom v0.0.11 (2023-09-04T22:52:56.755Z)
|
|
3
3
|
* Copyright 2022-present, TheFittingRoom, Inc. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
@@ -22768,6 +22768,12 @@ class RecommendedAvailableSizesError extends Error {
|
|
|
22768
22768
|
this.available_sizes = available_sizes;
|
|
22769
22769
|
}
|
|
22770
22770
|
}
|
|
22771
|
+
class BrandUserIdNotSetError extends Error {
|
|
22772
|
+
constructor() {
|
|
22773
|
+
super('brand user id not set');
|
|
22774
|
+
this.name = 'BrandUserIdNotSetError';
|
|
22775
|
+
}
|
|
22776
|
+
}
|
|
22771
22777
|
// Backend responses
|
|
22772
22778
|
const AvatarNotCreated = 'avatar not created';
|
|
22773
22779
|
|
|
@@ -22780,12 +22786,14 @@ var errors = /*#__PURE__*/Object.freeze({
|
|
|
22780
22786
|
NoColorwaySizeAssetsFoundError: NoColorwaySizeAssetsFoundError,
|
|
22781
22787
|
NoStylesFoundError: NoStylesFoundError,
|
|
22782
22788
|
RecommendedAvailableSizesError: RecommendedAvailableSizesError,
|
|
22789
|
+
BrandUserIdNotSetError: BrandUserIdNotSetError,
|
|
22783
22790
|
AvatarNotCreated: AvatarNotCreated
|
|
22784
22791
|
});
|
|
22785
22792
|
|
|
22786
22793
|
class FirebaseUser {
|
|
22787
22794
|
constructor(firestore, app) {
|
|
22788
22795
|
this.firestore = firestore;
|
|
22796
|
+
this.brandUserId = null;
|
|
22789
22797
|
this.auth = getAuth(app);
|
|
22790
22798
|
this.auth.setPersistence(browserLocalPersistence);
|
|
22791
22799
|
}
|
|
@@ -22805,6 +22813,9 @@ class FirebaseUser {
|
|
|
22805
22813
|
setUser(user) {
|
|
22806
22814
|
this.user = user;
|
|
22807
22815
|
}
|
|
22816
|
+
setBrandUserId(brandUserId) {
|
|
22817
|
+
this.brandUserId = brandUserId;
|
|
22818
|
+
}
|
|
22808
22819
|
async getToken() {
|
|
22809
22820
|
var _a;
|
|
22810
22821
|
if (!((_a = this.user) === null || _a === void 0 ? void 0 : _a.uid))
|
|
@@ -22824,8 +22835,8 @@ class FirebaseUser {
|
|
|
22824
22835
|
const q = sl(Ta(this.firestore, 'users'), rl(Eh(), '==', this.id));
|
|
22825
22836
|
const cancel = setTimeout(() => unsub(), timeout);
|
|
22826
22837
|
return new Promise((resolve) => {
|
|
22827
|
-
unsub = jl(q, (snapshot) => {
|
|
22828
|
-
if (!predicate(snapshot))
|
|
22838
|
+
unsub = jl(q, async (snapshot) => {
|
|
22839
|
+
if (!(await predicate(snapshot)))
|
|
22829
22840
|
return;
|
|
22830
22841
|
clearTimeout(cancel);
|
|
22831
22842
|
unsub();
|
|
@@ -22941,7 +22952,7 @@ class Fetcher {
|
|
|
22941
22952
|
}
|
|
22942
22953
|
}
|
|
22943
22954
|
|
|
22944
|
-
const
|
|
22955
|
+
const testImage = (url) => {
|
|
22945
22956
|
const img = new Image();
|
|
22946
22957
|
img.src = url;
|
|
22947
22958
|
return new Promise((resolve) => {
|
|
@@ -23041,7 +23052,13 @@ class TfrShop {
|
|
|
23041
23052
|
var _a, _b, _c, _d;
|
|
23042
23053
|
if (!this.isLoggedIn)
|
|
23043
23054
|
throw new UserNotLoggedInError();
|
|
23044
|
-
const predicate = (data) => {
|
|
23055
|
+
const predicate = async (data) => {
|
|
23056
|
+
var _a, _b, _c, _d;
|
|
23057
|
+
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;
|
|
23058
|
+
if (!(frames === null || frames === void 0 ? void 0 : frames.length))
|
|
23059
|
+
return false;
|
|
23060
|
+
return testImage(frames[0]);
|
|
23061
|
+
};
|
|
23045
23062
|
const userProfile = (await this.user.watchUserProfileForChanges(predicate, TfrShop.vtoTimeout));
|
|
23046
23063
|
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))
|
|
23047
23064
|
throw new NoFramesFoundError();
|
|
@@ -23102,7 +23119,11 @@ class TfrShop {
|
|
|
23102
23119
|
async requestColorwaySizeAssetFrames(colorwaySizeAssetId) {
|
|
23103
23120
|
if (!this.isLoggedIn)
|
|
23104
23121
|
throw new UserNotLoggedInError();
|
|
23105
|
-
|
|
23122
|
+
if (!this.user.brandUserId)
|
|
23123
|
+
throw new BrandUserIdNotSetError();
|
|
23124
|
+
await Fetcher.Post(this.user, `/colorway-size-assets/${colorwaySizeAssetId}/frames`, {
|
|
23125
|
+
brand_user_id: String(this.user.brandUserId),
|
|
23126
|
+
});
|
|
23106
23127
|
}
|
|
23107
23128
|
async getColorwaySizeAssetFrames(colorwaySizeAssetSKU) {
|
|
23108
23129
|
var _a, _b, _c;
|
|
@@ -23110,7 +23131,7 @@ class TfrShop {
|
|
|
23110
23131
|
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) || [];
|
|
23111
23132
|
if (!frames.length)
|
|
23112
23133
|
throw new NoFramesFoundError();
|
|
23113
|
-
const testedImage = await
|
|
23134
|
+
const testedImage = await testImage(frames[0]);
|
|
23114
23135
|
if (!testedImage)
|
|
23115
23136
|
throw new NoFramesFoundError();
|
|
23116
23137
|
return frames;
|