@thefittingroom/sdk 0.0.8 → 0.0.10
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 +30 -10
- package/dist/esm/api/shop.d.ts +5 -1
- package/dist/esm/api/utils.d.ts +1 -1
- package/dist/esm/firebase/firebase-user.d.ts +1 -1
- package/dist/esm/index.js +20 -8
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +180 -180
- package/dist/esm/index.min.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -58,30 +58,50 @@ const shop = initShop(brandId, env)
|
|
|
58
58
|
await shop.onInit()
|
|
59
59
|
|
|
60
60
|
// Login user with session
|
|
61
|
-
shop.user.login(
|
|
61
|
+
shop.user.login(email, password)
|
|
62
62
|
|
|
63
63
|
// Logout current user
|
|
64
64
|
shop.user.logout()
|
|
65
65
|
|
|
66
|
-
//
|
|
66
|
+
// In order for the user to create an avatar, they'll need to download the mobile application.
|
|
67
|
+
// This will send an SMS to the given phone number with a link to the iOS app
|
|
67
68
|
// No spaces and must include country code e.g. +18005551234
|
|
68
69
|
shop.submitTelephoneNumber(tel)
|
|
70
|
+
|
|
71
|
+
// await for the avatar creation
|
|
72
|
+
// Returns boolean on whether the avatar is created or not after the configured `avatarTimeout` period
|
|
73
|
+
shop.awaitAvatarCreated()
|
|
69
74
|
```
|
|
70
75
|
|
|
71
76
|
#### Shop
|
|
72
77
|
|
|
78
|
+
We'll make references to `sku` several times here. This is the unique identifier that matches a styles particular size
|
|
79
|
+
from your inventory to our system.
|
|
80
|
+
|
|
73
81
|
```typescript
|
|
74
|
-
//
|
|
75
|
-
|
|
82
|
+
// A good first step would be to ensure your style and size exists in the fitting room system before executing any of the
|
|
83
|
+
// following functions. You'll get back some data about the style(s), such as the ID of the style, which you can use
|
|
84
|
+
// for the getRecommendedSizes function below.
|
|
85
|
+
// ids: number[] or skus: string[]
|
|
86
|
+
// At least one parameter must not be null
|
|
87
|
+
shop.getStyles(ids, skus)
|
|
76
88
|
|
|
77
|
-
//
|
|
78
|
-
|
|
89
|
+
// get recommended sizes for a particular style
|
|
90
|
+
// The styleID can be extracted from the previous getStyles function call.
|
|
91
|
+
const sizeRecommendation = shop.getRecommendedSizes(styleID)
|
|
79
92
|
|
|
80
|
-
// get recommended sizes for
|
|
81
|
-
|
|
93
|
+
// get recommended sizes label for a particular style
|
|
94
|
+
// returns: { recommendedSizeLabel, availableSizeLabels }
|
|
95
|
+
// recommendedSizeLabel: string
|
|
96
|
+
// availableSizeLabels: string[]
|
|
97
|
+
const { recommendedSizeLabel, availableSizeLabels } = shop.getRecommendedSizesLabels(styleID)
|
|
82
98
|
|
|
83
|
-
//
|
|
84
|
-
|
|
99
|
+
// Once the user has downloaded the mobile application and has created an avatar, they may now virtually try on a size.
|
|
100
|
+
// The size they try on must be one of the recommended sizes from the previous function call. or an error will get returned.
|
|
101
|
+
// returns frames: types.TryOnFrames
|
|
102
|
+
// These `frames` are images that can be used to cycle through the VTO 360 degrees.
|
|
103
|
+
// NOTE: this process can take a minute or two
|
|
104
|
+
const frames = await this.shop.tryOn(sku)
|
|
85
105
|
```
|
|
86
106
|
|
|
87
107
|
#### Errors
|
package/dist/esm/api/shop.d.ts
CHANGED
|
@@ -12,7 +12,11 @@ export declare class TfrShop {
|
|
|
12
12
|
onInit(): Promise<boolean>;
|
|
13
13
|
tryOn(colorwaySizeAssetSku: string): Promise<types.TryOnFrames>;
|
|
14
14
|
awaitAvatarCreated(): Promise<boolean>;
|
|
15
|
-
getRecommendedSizes(
|
|
15
|
+
getRecommendedSizes(styleId: string): Promise<SizeRecommendation>;
|
|
16
|
+
getRecommendedSizesLabels(styleId: string): Promise<{
|
|
17
|
+
recommendedSizeLabel: string;
|
|
18
|
+
availableSizeLabels: string[];
|
|
19
|
+
}>;
|
|
16
20
|
getStyles(ids: number[], skus: string[]): Promise<Map<number, types.FirestoreStyle>>;
|
|
17
21
|
submitTelephoneNumber(tel: string): Promise<void>;
|
|
18
22
|
private awaitColorwaySizeAssetFrames;
|
package/dist/esm/api/utils.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const testImage: (url: string) => Promise<boolean>;
|
|
@@ -11,7 +11,7 @@ export declare class FirebaseUser {
|
|
|
11
11
|
setUser(user: firebaseAuth.User): void;
|
|
12
12
|
getToken(): Promise<string>;
|
|
13
13
|
getUserProfile(): Promise<DocumentData>;
|
|
14
|
-
watchUserProfileForChanges(predicate: (data: QuerySnapshot<DocumentData>) => boolean
|
|
14
|
+
watchUserProfileForChanges(predicate: (data: QuerySnapshot<DocumentData>) => Promise<boolean>, timeout: number): Promise<DocumentData>;
|
|
15
15
|
login(username: string, password: string): Promise<void>;
|
|
16
16
|
logout(): Promise<void>;
|
|
17
17
|
sendPasswordResetEmail(email: string): Promise<void>;
|
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* thefittingroom v0.0.
|
|
2
|
+
* thefittingroom v0.0.10 (2023-07-31T23:26:47.153Z)
|
|
3
3
|
* Copyright 2022-present, TheFittingRoom, Inc. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
@@ -22824,8 +22824,8 @@ class FirebaseUser {
|
|
|
22824
22824
|
const q = sl(Ta(this.firestore, 'users'), rl(Eh(), '==', this.id));
|
|
22825
22825
|
const cancel = setTimeout(() => unsub(), timeout);
|
|
22826
22826
|
return new Promise((resolve) => {
|
|
22827
|
-
unsub = jl(q, (snapshot) => {
|
|
22828
|
-
if (!predicate(snapshot))
|
|
22827
|
+
unsub = jl(q, async (snapshot) => {
|
|
22828
|
+
if (!(await predicate(snapshot)))
|
|
22829
22829
|
return;
|
|
22830
22830
|
clearTimeout(cancel);
|
|
22831
22831
|
unsub();
|
|
@@ -22941,7 +22941,7 @@ class Fetcher {
|
|
|
22941
22941
|
}
|
|
22942
22942
|
}
|
|
22943
22943
|
|
|
22944
|
-
const
|
|
22944
|
+
const testImage = (url) => {
|
|
22945
22945
|
const img = new Image();
|
|
22946
22946
|
img.src = url;
|
|
22947
22947
|
return new Promise((resolve) => {
|
|
@@ -22993,11 +22993,11 @@ class TfrShop {
|
|
|
22993
22993
|
const userProfile = snapshot.docs[0].data();
|
|
22994
22994
|
return userProfile.avatar_status === 'CREATED';
|
|
22995
22995
|
}
|
|
22996
|
-
async getRecommendedSizes(
|
|
22996
|
+
async getRecommendedSizes(styleId) {
|
|
22997
22997
|
if (!this.isLoggedIn)
|
|
22998
22998
|
throw new UserNotLoggedInError();
|
|
22999
22999
|
try {
|
|
23000
|
-
const res = await Fetcher.Get(this.user, `/styles/${
|
|
23000
|
+
const res = await Fetcher.Get(this.user, `/styles/${styleId}/recommendation`);
|
|
23001
23001
|
const json = await res.json();
|
|
23002
23002
|
return json;
|
|
23003
23003
|
}
|
|
@@ -23007,6 +23007,12 @@ class TfrShop {
|
|
|
23007
23007
|
throw error;
|
|
23008
23008
|
}
|
|
23009
23009
|
}
|
|
23010
|
+
async getRecommendedSizesLabels(styleId) {
|
|
23011
|
+
const sizeRecommendation = await this.getRecommendedSizes(styleId);
|
|
23012
|
+
const recommendedSizeLabel = sizeRecommendation.recommended_sizes.label || sizeRecommendation.recommended_sizes.size_value.size;
|
|
23013
|
+
const availableSizeLabels = sizeRecommendation.available_sizes.map((size) => size.label || size.size_value.size);
|
|
23014
|
+
return { recommendedSizeLabel, availableSizeLabels };
|
|
23015
|
+
}
|
|
23010
23016
|
async getStyles(ids, skus) {
|
|
23011
23017
|
const constraints = [rl('brand_id', '==', this.brandId)];
|
|
23012
23018
|
if ((ids === null || ids === void 0 ? void 0 : ids.length) > 0)
|
|
@@ -23035,7 +23041,13 @@ class TfrShop {
|
|
|
23035
23041
|
var _a, _b, _c, _d;
|
|
23036
23042
|
if (!this.isLoggedIn)
|
|
23037
23043
|
throw new UserNotLoggedInError();
|
|
23038
|
-
const predicate = (data) => {
|
|
23044
|
+
const predicate = async (data) => {
|
|
23045
|
+
var _a, _b, _c, _d;
|
|
23046
|
+
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;
|
|
23047
|
+
if (!(frames === null || frames === void 0 ? void 0 : frames.length))
|
|
23048
|
+
return false;
|
|
23049
|
+
return testImage(frames[0]);
|
|
23050
|
+
};
|
|
23039
23051
|
const userProfile = (await this.user.watchUserProfileForChanges(predicate, TfrShop.vtoTimeout));
|
|
23040
23052
|
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))
|
|
23041
23053
|
throw new NoFramesFoundError();
|
|
@@ -23104,7 +23116,7 @@ class TfrShop {
|
|
|
23104
23116
|
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) || [];
|
|
23105
23117
|
if (!frames.length)
|
|
23106
23118
|
throw new NoFramesFoundError();
|
|
23107
|
-
const testedImage = await
|
|
23119
|
+
const testedImage = await testImage(frames[0]);
|
|
23108
23120
|
if (!testedImage)
|
|
23109
23121
|
throw new NoFramesFoundError();
|
|
23110
23122
|
return frames;
|