@thefittingroom/sdk 2.0.0 → 2.0.2
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/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/api/fetcher.d.ts +12 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/api/fetcher.js +49 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/api/fetcher.js.map +1 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/api/requests.d.ts +155 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/api/requests.js +3 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/api/requests.js.map +1 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/api/responses.d.ts +130 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/api/responses.js +2 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/api/responses.js.map +1 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/api/shop.d.ts +33 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/api/shop.js +261 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/api/shop.js.map +1 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/api/utils.d.ts +1 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/api/utils.js +9 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/api/utils.js.map +1 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/firebase/firebase-error.d.ts +2 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/firebase/firebase-error.js +10 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/firebase/firebase-error.js.map +1 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/firebase/firebase-user.d.ts +26 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/firebase/firebase-user.js +122 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/firebase/firebase-user.js.map +1 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/firebase/firebase.d.ts +15 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/firebase/firebase.js +40 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/firebase/firebase.js.map +1 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/helpers/async.d.ts +2 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/helpers/async.js +3 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/helpers/async.js.map +1 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/helpers/config.d.ts +22 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/helpers/config.js +70 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/helpers/config.js.map +1 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/helpers/date.d.ts +6 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/helpers/date.js +5 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/helpers/date.js.map +1 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/helpers/errors.d.ts +32 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/helpers/errors.js +47 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/helpers/errors.js.map +1 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/index.d.ts +8 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/index.js +6 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/index.js.map +1 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/types/index.d.ts +89 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/types/index.js +8 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/types/index.js.map +1 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/types/measurement.d.ts +292 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/types/measurement.js +377 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/types/measurement.js.map +1 -0
- package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/tsconfig.tsbuildinfo +1 -0
- package/LICENSE +373 -0
- package/README.md +67 -73
- package/dist/esm/firebase/firebase.d.ts +2 -2
- package/dist/esm/index.js +23044 -23183
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +366 -265
- package/dist/esm/index.min.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +17 -24
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FirebaseUser } from '../firebase/firebase-user';
|
|
2
|
+
export declare class Fetcher {
|
|
3
|
+
private static get endpoint();
|
|
4
|
+
private static Fetch;
|
|
5
|
+
private static getUrl;
|
|
6
|
+
private static getHeaders;
|
|
7
|
+
static Get(user: FirebaseUser, endpointPath: string, useToken?: boolean): Promise<Response>;
|
|
8
|
+
static Post(user: FirebaseUser, endpointPath: string, body?: Record<string, any>, useToken?: boolean): Promise<Response>;
|
|
9
|
+
static Put(user: FirebaseUser, endpointPath: string, body: Record<string, any>, useToken?: boolean): Promise<Response>;
|
|
10
|
+
static Patch(user: FirebaseUser, endpointPath: string, body: Record<string, any>, useToken?: boolean): Promise<Response>;
|
|
11
|
+
static Delete(user: FirebaseUser, endpointPath: string, body: Record<string, any>, useToken?: boolean): Promise<Response>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Config } from '../helpers/config';
|
|
2
|
+
export class Fetcher {
|
|
3
|
+
static get endpoint() {
|
|
4
|
+
const api = Config.getInstance().api;
|
|
5
|
+
return api.url;
|
|
6
|
+
}
|
|
7
|
+
static async Fetch({ user, endpointPath, method, body, useToken = true }) {
|
|
8
|
+
const url = this.getUrl(endpointPath, useToken);
|
|
9
|
+
const headers = await this.getHeaders(user, useToken);
|
|
10
|
+
const config = { method, headers, credentials: 'omit' };
|
|
11
|
+
if (body)
|
|
12
|
+
config.body = JSON.stringify(body);
|
|
13
|
+
const res = await fetch(url, config);
|
|
14
|
+
if (res.ok)
|
|
15
|
+
return res;
|
|
16
|
+
if (res.status === 500)
|
|
17
|
+
throw new Error(res.statusText);
|
|
18
|
+
const json = await res.json();
|
|
19
|
+
return Promise.reject(json);
|
|
20
|
+
}
|
|
21
|
+
static getUrl(endpointPath, useToken) {
|
|
22
|
+
return useToken ? `${this.endpoint}/v1${endpointPath}` : this.endpoint + endpointPath;
|
|
23
|
+
}
|
|
24
|
+
static async getHeaders(user, useToken) {
|
|
25
|
+
if (!useToken)
|
|
26
|
+
return { 'Content-Type': 'application/json' };
|
|
27
|
+
const token = await user.getToken();
|
|
28
|
+
return {
|
|
29
|
+
'Content-Type': 'application/json',
|
|
30
|
+
Authorization: `Bearer ${token}`,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
static Get(user, endpointPath, useToken) {
|
|
34
|
+
return this.Fetch({ user, endpointPath, method: 'GET', body: null, useToken });
|
|
35
|
+
}
|
|
36
|
+
static Post(user, endpointPath, body = null, useToken) {
|
|
37
|
+
return this.Fetch({ user, endpointPath, method: 'POST', body, useToken });
|
|
38
|
+
}
|
|
39
|
+
static Put(user, endpointPath, body, useToken) {
|
|
40
|
+
return this.Fetch({ user, endpointPath, method: 'PUT', body, useToken });
|
|
41
|
+
}
|
|
42
|
+
static Patch(user, endpointPath, body, useToken) {
|
|
43
|
+
return this.Fetch({ user, endpointPath, method: 'PATCH', body, useToken });
|
|
44
|
+
}
|
|
45
|
+
static Delete(user, endpointPath, body, useToken) {
|
|
46
|
+
return this.Fetch({ user, endpointPath, method: 'DELETE', body, useToken });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=fetcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetcher.js","sourceRoot":"","sources":["../../../src/api/fetcher.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
export interface BodyMeasurement {
|
|
2
|
+
avatar_id: number;
|
|
3
|
+
position: number;
|
|
4
|
+
value: number;
|
|
5
|
+
}
|
|
6
|
+
export interface Avatar {
|
|
7
|
+
BrandID: string;
|
|
8
|
+
HeightCM: string;
|
|
9
|
+
WeightKG: string;
|
|
10
|
+
Gender: string;
|
|
11
|
+
BodyType: string;
|
|
12
|
+
SkinToneHex: string;
|
|
13
|
+
SkinToneFac: string;
|
|
14
|
+
FrameCount: string;
|
|
15
|
+
Video?: any;
|
|
16
|
+
}
|
|
17
|
+
export interface UpdateAvatarWebhook {
|
|
18
|
+
waist: number;
|
|
19
|
+
hip: number;
|
|
20
|
+
bust: number;
|
|
21
|
+
under_bust: number;
|
|
22
|
+
right_hip_x: number;
|
|
23
|
+
right_hip_y: number;
|
|
24
|
+
right_hip_z: number;
|
|
25
|
+
left_hip_x: number;
|
|
26
|
+
left_hip_y: number;
|
|
27
|
+
left_hip_z: number;
|
|
28
|
+
right_waist_x: number;
|
|
29
|
+
right_waist_y: number;
|
|
30
|
+
right_waist_z: number;
|
|
31
|
+
left_waist_x: number;
|
|
32
|
+
left_waist_y: number;
|
|
33
|
+
left_waist_z: number;
|
|
34
|
+
right_shoulder_x: number;
|
|
35
|
+
right_shoulder_y: number;
|
|
36
|
+
right_shoulder_z: number;
|
|
37
|
+
left_shoulder_x: number;
|
|
38
|
+
left_shoulder_y: number;
|
|
39
|
+
left_shoulder_z: number;
|
|
40
|
+
frames_storage_path: string;
|
|
41
|
+
object_storage_path: string;
|
|
42
|
+
}
|
|
43
|
+
export interface Brand {
|
|
44
|
+
name: string;
|
|
45
|
+
business_number: string;
|
|
46
|
+
logo_storage_path: string;
|
|
47
|
+
country_code: string;
|
|
48
|
+
about: string;
|
|
49
|
+
why_tfr: string;
|
|
50
|
+
specialty: string;
|
|
51
|
+
phone_number: string;
|
|
52
|
+
}
|
|
53
|
+
export interface Collection {
|
|
54
|
+
external_id: string;
|
|
55
|
+
name: string;
|
|
56
|
+
description: string;
|
|
57
|
+
}
|
|
58
|
+
export interface PatchColorwaySizeAsset {
|
|
59
|
+
Sku: string;
|
|
60
|
+
}
|
|
61
|
+
export interface ColorwaySizeAsset {
|
|
62
|
+
Sku: string;
|
|
63
|
+
File?: any;
|
|
64
|
+
}
|
|
65
|
+
export interface UpdateColorwaySizeAssetWebhook {
|
|
66
|
+
avatar_id: number;
|
|
67
|
+
frames_storage_path: string;
|
|
68
|
+
frame_count: number;
|
|
69
|
+
}
|
|
70
|
+
export interface Invitation {
|
|
71
|
+
email: string;
|
|
72
|
+
first_name: string;
|
|
73
|
+
last_name: string;
|
|
74
|
+
brand_id: number;
|
|
75
|
+
}
|
|
76
|
+
export interface GarmentMeasurement {
|
|
77
|
+
measurement_location: string;
|
|
78
|
+
value: number;
|
|
79
|
+
tolerance: number;
|
|
80
|
+
}
|
|
81
|
+
export interface Size {
|
|
82
|
+
size_value_id: number;
|
|
83
|
+
label: string;
|
|
84
|
+
garment_measurements: GarmentMeasurement[];
|
|
85
|
+
}
|
|
86
|
+
export interface Colorway {
|
|
87
|
+
name: string;
|
|
88
|
+
}
|
|
89
|
+
export interface Style {
|
|
90
|
+
brand_style_id: string;
|
|
91
|
+
collection_id?: number;
|
|
92
|
+
name: string;
|
|
93
|
+
description: string;
|
|
94
|
+
sale_type: string;
|
|
95
|
+
garment_category_id: number;
|
|
96
|
+
sizes: Size[];
|
|
97
|
+
colorways: Colorway[];
|
|
98
|
+
}
|
|
99
|
+
export interface StylePatch {
|
|
100
|
+
publish: boolean;
|
|
101
|
+
}
|
|
102
|
+
export interface User {
|
|
103
|
+
first_name: string;
|
|
104
|
+
last_name: string;
|
|
105
|
+
date_of_birth: string;
|
|
106
|
+
job: string;
|
|
107
|
+
}
|
|
108
|
+
export interface InvitedUser {
|
|
109
|
+
token: string;
|
|
110
|
+
password: string;
|
|
111
|
+
}
|
|
112
|
+
export interface Joint {
|
|
113
|
+
id: number;
|
|
114
|
+
name: string;
|
|
115
|
+
side: string;
|
|
116
|
+
x: number;
|
|
117
|
+
y: number;
|
|
118
|
+
z: number;
|
|
119
|
+
}
|
|
120
|
+
export interface Joints {
|
|
121
|
+
right_hip_x: number;
|
|
122
|
+
right_hip_y: number;
|
|
123
|
+
right_hip_z: number;
|
|
124
|
+
left_hip_x: number;
|
|
125
|
+
left_hip_y: number;
|
|
126
|
+
left_hip_z: number;
|
|
127
|
+
right_waist_x: number;
|
|
128
|
+
right_waist_y: number;
|
|
129
|
+
right_waist_z: number;
|
|
130
|
+
left_waist_x: number;
|
|
131
|
+
left_waist_y: number;
|
|
132
|
+
left_waist_z: number;
|
|
133
|
+
right_shoulder_x: number;
|
|
134
|
+
right_shoulder_y: number;
|
|
135
|
+
right_shoulder_z: number;
|
|
136
|
+
left_shoulder_x: number;
|
|
137
|
+
left_shoulder_y: number;
|
|
138
|
+
left_shoulder_z: number;
|
|
139
|
+
}
|
|
140
|
+
export interface FramesRequest {
|
|
141
|
+
user_id: string;
|
|
142
|
+
avatar_id: number;
|
|
143
|
+
gender: string;
|
|
144
|
+
garment_id: number;
|
|
145
|
+
colorway_id: number;
|
|
146
|
+
size_id: number;
|
|
147
|
+
avatar: string;
|
|
148
|
+
garment: string;
|
|
149
|
+
material: string;
|
|
150
|
+
textures: string;
|
|
151
|
+
hex_value: string;
|
|
152
|
+
color_value: number;
|
|
153
|
+
frame_count: number;
|
|
154
|
+
joints: Joints;
|
|
155
|
+
}
|
package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/api/requests.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requests.js","sourceRoot":"","sources":["../../../src/api/requests.ts"],"names":[],"mappings":"AAAA,uCAAuC"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { Fit } from '../types/measurement';
|
|
2
|
+
export interface BodyMeasurement {
|
|
3
|
+
id: number;
|
|
4
|
+
position: number;
|
|
5
|
+
value: number;
|
|
6
|
+
}
|
|
7
|
+
export interface Avatar {
|
|
8
|
+
id: number;
|
|
9
|
+
user_id?: string;
|
|
10
|
+
brand_id?: number;
|
|
11
|
+
recorded_video_storage_path?: string;
|
|
12
|
+
height_cm?: number;
|
|
13
|
+
weight_kg?: number;
|
|
14
|
+
gender?: string;
|
|
15
|
+
skin_tone_hex?: string;
|
|
16
|
+
skin_tone_fac?: number;
|
|
17
|
+
body_measurements?: BodyMeasurement[];
|
|
18
|
+
}
|
|
19
|
+
export interface Brand {
|
|
20
|
+
id: number;
|
|
21
|
+
name: string;
|
|
22
|
+
business_number: string;
|
|
23
|
+
logo_storage_path: string;
|
|
24
|
+
country_code: string;
|
|
25
|
+
about: string;
|
|
26
|
+
why_tfr: string;
|
|
27
|
+
specialty: string;
|
|
28
|
+
phone_number: string;
|
|
29
|
+
}
|
|
30
|
+
export interface Collection {
|
|
31
|
+
id: number;
|
|
32
|
+
brand_id: number;
|
|
33
|
+
external_id: string;
|
|
34
|
+
name: string;
|
|
35
|
+
description: string;
|
|
36
|
+
}
|
|
37
|
+
export interface ColorwaySizeAsset {
|
|
38
|
+
id: number;
|
|
39
|
+
sku: string;
|
|
40
|
+
size_id: number;
|
|
41
|
+
colorway_id: number;
|
|
42
|
+
folder_storage_path: string;
|
|
43
|
+
obj_file_name: string;
|
|
44
|
+
mtl_file_name: string;
|
|
45
|
+
texture_folder_name: string;
|
|
46
|
+
}
|
|
47
|
+
export interface ID {
|
|
48
|
+
id: number;
|
|
49
|
+
}
|
|
50
|
+
export interface UserID {
|
|
51
|
+
user_id: string;
|
|
52
|
+
}
|
|
53
|
+
export interface UpdatedAt {
|
|
54
|
+
updated_at: any;
|
|
55
|
+
}
|
|
56
|
+
export interface IsPublished {
|
|
57
|
+
is_published: boolean;
|
|
58
|
+
}
|
|
59
|
+
export interface Invitation {
|
|
60
|
+
email: string;
|
|
61
|
+
first_name: string;
|
|
62
|
+
last_name: string;
|
|
63
|
+
expires_at?: any;
|
|
64
|
+
}
|
|
65
|
+
export interface SizeRecommendationIDs {
|
|
66
|
+
recommended_size_id: number;
|
|
67
|
+
available_size_ids: number[];
|
|
68
|
+
}
|
|
69
|
+
export interface MeasurementLocationFits {
|
|
70
|
+
measurement_location: string;
|
|
71
|
+
fit: Fit;
|
|
72
|
+
fit_label?: string;
|
|
73
|
+
}
|
|
74
|
+
export interface Fits {
|
|
75
|
+
size_id: number;
|
|
76
|
+
measurement_location_fits: MeasurementLocationFits[];
|
|
77
|
+
}
|
|
78
|
+
export interface SizeRecommendation {
|
|
79
|
+
recommended_size: Size;
|
|
80
|
+
available_sizes: Size[];
|
|
81
|
+
fits: Fits[];
|
|
82
|
+
}
|
|
83
|
+
export interface GarmentMeasurement {
|
|
84
|
+
id: number;
|
|
85
|
+
measurement_location: string;
|
|
86
|
+
value: number;
|
|
87
|
+
tolerance: number;
|
|
88
|
+
}
|
|
89
|
+
export interface Size {
|
|
90
|
+
id: number;
|
|
91
|
+
size_value: SizeValue;
|
|
92
|
+
label?: string;
|
|
93
|
+
garment_measurements?: GarmentMeasurement[];
|
|
94
|
+
}
|
|
95
|
+
export interface SizeValue {
|
|
96
|
+
id: any;
|
|
97
|
+
size: string;
|
|
98
|
+
size_system: string;
|
|
99
|
+
}
|
|
100
|
+
export interface GarmentCategory {
|
|
101
|
+
id: number;
|
|
102
|
+
garment_category: string;
|
|
103
|
+
garment_subcategory: string;
|
|
104
|
+
}
|
|
105
|
+
export interface Colorway {
|
|
106
|
+
id: number;
|
|
107
|
+
name: string;
|
|
108
|
+
}
|
|
109
|
+
export interface Style {
|
|
110
|
+
id: number;
|
|
111
|
+
brand_id?: number;
|
|
112
|
+
brand_style_id: string;
|
|
113
|
+
collection_id: number;
|
|
114
|
+
name?: string;
|
|
115
|
+
description?: string;
|
|
116
|
+
sale_type?: string;
|
|
117
|
+
garment_category?: GarmentCategory;
|
|
118
|
+
sizes: Size[];
|
|
119
|
+
colorways: Colorway[];
|
|
120
|
+
is_published: boolean;
|
|
121
|
+
}
|
|
122
|
+
export interface User {
|
|
123
|
+
id: string;
|
|
124
|
+
brand_id: number;
|
|
125
|
+
first_name: string;
|
|
126
|
+
last_name: string;
|
|
127
|
+
email: string;
|
|
128
|
+
date_of_birth: any;
|
|
129
|
+
job: string;
|
|
130
|
+
}
|
package/.rollup.cache/home/codeliger/code/thefittingroom/shop-sdk/dist/esm/api/responses.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responses.js","sourceRoot":"","sources":["../../../src/api/responses.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Firebase } from '../firebase/firebase';
|
|
2
|
+
import * as types from '../types';
|
|
3
|
+
import { SizeRecommendation } from './responses';
|
|
4
|
+
export declare class TfrShop {
|
|
5
|
+
private readonly brandId;
|
|
6
|
+
private readonly firebase;
|
|
7
|
+
private measurementLocations;
|
|
8
|
+
constructor(brandId: number, firebase: Firebase);
|
|
9
|
+
get user(): import("..").FirebaseUser;
|
|
10
|
+
get isLoggedIn(): boolean;
|
|
11
|
+
onInit(): Promise<boolean>;
|
|
12
|
+
getRecommendedSizes(styleId: string): Promise<SizeRecommendation>;
|
|
13
|
+
submitTelephoneNumber(tel: string): Promise<void>;
|
|
14
|
+
getColorwaySizeAssetFromSku(colorwaySizeAssetSku: string): Promise<types.FirestoreColorwaySizeAsset>;
|
|
15
|
+
getColorwaySizeAssetFromBrandStyleId(brandStyleId: number): Promise<types.FirestoreColorwaySizeAsset>;
|
|
16
|
+
getMeasurementLocationsFromSku(sku: string, filledLocations?: string[]): Promise<string[]>;
|
|
17
|
+
getMeasurementLocationsFromBrandStyleId(brandStyleId: number, filledLocations?: string[]): Promise<string[]>;
|
|
18
|
+
getStyleByBrandStyleId(brandStyleId: string): Promise<types.FirestoreStyleCategory>;
|
|
19
|
+
private getColorwaySizeAssets;
|
|
20
|
+
getStyle(styleId: number): Promise<types.FirestoreStyleCategory>;
|
|
21
|
+
getMeasurementLocationName(location: string): string;
|
|
22
|
+
getMeasurementLocationSortOrder(location: string): number;
|
|
23
|
+
tryOn(styleId: number, sizeId: number): Promise<types.TryOnFrames>;
|
|
24
|
+
private getColorwaySizeAssetSkuFromStyleIdAndSizeId;
|
|
25
|
+
private getGetTaxonomy;
|
|
26
|
+
private getMeasurementLocations;
|
|
27
|
+
private fetchMeasurementLocations;
|
|
28
|
+
private requestThenGetColorwaySizeAssetFrames;
|
|
29
|
+
private awaitColorwaySizeAssetFrames;
|
|
30
|
+
private requestColorwaySizeAssetFrames;
|
|
31
|
+
private getColorwaySizeAssetFrames;
|
|
32
|
+
}
|
|
33
|
+
export declare const initShop: (brandId: number, env?: string) => TfrShop;
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { where } from 'firebase/firestore';
|
|
2
|
+
import { Firebase } from '../firebase/firebase';
|
|
3
|
+
import { getFirebaseError } from '../firebase/firebase-error';
|
|
4
|
+
import { asyncTry } from '../helpers/async';
|
|
5
|
+
import { Config } from '../helpers/config';
|
|
6
|
+
import * as Errors from '../helpers/errors';
|
|
7
|
+
import { Fetcher } from './fetcher';
|
|
8
|
+
import { testImage } from './utils';
|
|
9
|
+
export class TfrShop {
|
|
10
|
+
constructor(brandId, firebase) {
|
|
11
|
+
this.brandId = brandId;
|
|
12
|
+
this.firebase = firebase;
|
|
13
|
+
this.measurementLocations = new Map();
|
|
14
|
+
}
|
|
15
|
+
get user() {
|
|
16
|
+
return this.firebase.user;
|
|
17
|
+
}
|
|
18
|
+
get isLoggedIn() {
|
|
19
|
+
return !this.firebase || Boolean(this.user.id);
|
|
20
|
+
}
|
|
21
|
+
async onInit() {
|
|
22
|
+
await this.getMeasurementLocations();
|
|
23
|
+
return this.firebase.onInit(this.brandId);
|
|
24
|
+
}
|
|
25
|
+
async getRecommendedSizes(styleId) {
|
|
26
|
+
var _a, _b;
|
|
27
|
+
if (!this.isLoggedIn)
|
|
28
|
+
throw new Errors.UserNotLoggedInError();
|
|
29
|
+
try {
|
|
30
|
+
const res = await Fetcher.Get(this.user, `/styles/${styleId}/recommendation`);
|
|
31
|
+
const data = (await res.json());
|
|
32
|
+
if (!((_a = data === null || data === void 0 ? void 0 : data.fits) === null || _a === void 0 ? void 0 : _a.length) || !((_b = data === null || data === void 0 ? void 0 : data.recommended_size) === null || _b === void 0 ? void 0 : _b.id))
|
|
33
|
+
return null;
|
|
34
|
+
return data;
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
if ((error === null || error === void 0 ? void 0 : error.error) === Errors.AvatarNotCreated)
|
|
38
|
+
throw new Errors.AvatarNotCreatedError();
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async submitTelephoneNumber(tel) {
|
|
43
|
+
const sanitizedTel = tel.replace(/[^\+0-9]/g, '');
|
|
44
|
+
const res = await Fetcher.Post(this.user, '/ios-app-link', { phone_number: sanitizedTel }, false);
|
|
45
|
+
console.log(res);
|
|
46
|
+
}
|
|
47
|
+
async getColorwaySizeAssetFromSku(colorwaySizeAssetSku) {
|
|
48
|
+
const assets = await this.getColorwaySizeAssets(null, [colorwaySizeAssetSku]);
|
|
49
|
+
if (!(assets === null || assets === void 0 ? void 0 : assets.size))
|
|
50
|
+
throw new Errors.NoColorwaySizeAssetsFoundError();
|
|
51
|
+
return Array.from(assets.values())[0];
|
|
52
|
+
}
|
|
53
|
+
async getColorwaySizeAssetFromBrandStyleId(brandStyleId) {
|
|
54
|
+
const assets = await this.getColorwaySizeAssets(brandStyleId);
|
|
55
|
+
if (!(assets === null || assets === void 0 ? void 0 : assets.size))
|
|
56
|
+
throw new Errors.NoColorwaySizeAssetsFoundError();
|
|
57
|
+
return Array.from(assets.values())[0];
|
|
58
|
+
}
|
|
59
|
+
async getMeasurementLocationsFromSku(sku, filledLocations = []) {
|
|
60
|
+
console.log({ sku });
|
|
61
|
+
const asset = await this.getColorwaySizeAssetFromSku(sku);
|
|
62
|
+
if (!asset)
|
|
63
|
+
throw new Error('No colorway size asset found for sku');
|
|
64
|
+
const styleCategory = await this.getStyle(asset.style_id);
|
|
65
|
+
if (!styleCategory)
|
|
66
|
+
throw new Error('Style category not found for style id');
|
|
67
|
+
const taxonomy = await this.getGetTaxonomy(styleCategory.style_garment_category_id);
|
|
68
|
+
if (!taxonomy)
|
|
69
|
+
throw new Error('Taxonomy not found for style garment category id');
|
|
70
|
+
const filteredLocations = !filledLocations.length
|
|
71
|
+
? taxonomy.measurement_locations.female
|
|
72
|
+
: taxonomy.measurement_locations.female.filter((location) => filledLocations.includes(location));
|
|
73
|
+
const locationsWithSortOrder = filteredLocations.map((location) => {
|
|
74
|
+
return this.measurementLocations.has(location)
|
|
75
|
+
? this.measurementLocations.get(location)
|
|
76
|
+
: { name: location, sort_order: Infinity };
|
|
77
|
+
});
|
|
78
|
+
return locationsWithSortOrder
|
|
79
|
+
.sort((a, b) => (a.sort_order < b.sort_order ? -1 : 0))
|
|
80
|
+
.map((location) => location.name);
|
|
81
|
+
}
|
|
82
|
+
async getMeasurementLocationsFromBrandStyleId(brandStyleId, filledLocations = []) {
|
|
83
|
+
const asset = await this.getColorwaySizeAssetFromBrandStyleId(brandStyleId);
|
|
84
|
+
if (!asset)
|
|
85
|
+
throw new Error('No colorway size asset found for brand style id');
|
|
86
|
+
const styleCategory = await this.getStyle(asset.style_id);
|
|
87
|
+
if (!styleCategory)
|
|
88
|
+
throw new Error('Style category not found for style id');
|
|
89
|
+
const taxonomy = await this.getGetTaxonomy(styleCategory.style_garment_category_id);
|
|
90
|
+
if (!taxonomy)
|
|
91
|
+
throw new Error('Taxonomy not found for style garment category id');
|
|
92
|
+
const filteredLocations = !filledLocations.length
|
|
93
|
+
? taxonomy.measurement_locations.female
|
|
94
|
+
: taxonomy.measurement_locations.female.filter((location) => filledLocations.includes(location));
|
|
95
|
+
const locationsWithSortOrder = filteredLocations.map((location) => {
|
|
96
|
+
return this.measurementLocations.has(location)
|
|
97
|
+
? this.measurementLocations.get(location)
|
|
98
|
+
: { name: location, sort_order: Infinity };
|
|
99
|
+
});
|
|
100
|
+
return locationsWithSortOrder
|
|
101
|
+
.sort((a, b) => (a.sort_order < b.sort_order ? -1 : 0))
|
|
102
|
+
.map((location) => location.name);
|
|
103
|
+
}
|
|
104
|
+
async getStyleByBrandStyleId(brandStyleId) {
|
|
105
|
+
var _a, _b;
|
|
106
|
+
try {
|
|
107
|
+
const constraints = [where('brand_id', '==', this.brandId)];
|
|
108
|
+
constraints.push(where('brand_style_id', '==', brandStyleId));
|
|
109
|
+
const querySnapshot = await this.firebase.getDocs('styles', constraints);
|
|
110
|
+
return (_b = (_a = querySnapshot.docs) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.data();
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
return getFirebaseError(error);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async getColorwaySizeAssets(styleId, skus) {
|
|
117
|
+
const constraints = [where('brand_id', '==', this.brandId)];
|
|
118
|
+
if (styleId)
|
|
119
|
+
constraints.push(where('style_id', '==', styleId));
|
|
120
|
+
if ((skus === null || skus === void 0 ? void 0 : skus.length) > 0)
|
|
121
|
+
constraints.push(where('sku', 'in', skus));
|
|
122
|
+
try {
|
|
123
|
+
const querySnapshot = await this.firebase.getDocs('colorway_size_assets', constraints);
|
|
124
|
+
const colorwaySizeAssets = new Map();
|
|
125
|
+
querySnapshot.forEach((doc) => {
|
|
126
|
+
const colorwaySizeAsset = doc.data();
|
|
127
|
+
colorwaySizeAssets.set(colorwaySizeAsset.id, colorwaySizeAsset);
|
|
128
|
+
});
|
|
129
|
+
return colorwaySizeAssets;
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
return getFirebaseError(error);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
async getStyle(styleId) {
|
|
136
|
+
try {
|
|
137
|
+
const doc = await this.firebase.getDoc('styles', String(styleId));
|
|
138
|
+
return doc;
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
return getFirebaseError(error);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
getMeasurementLocationName(location) {
|
|
145
|
+
return this.measurementLocations.has(location) ? this.measurementLocations.get(location).name : location;
|
|
146
|
+
}
|
|
147
|
+
getMeasurementLocationSortOrder(location) {
|
|
148
|
+
return this.measurementLocations.has(location) ? this.measurementLocations.get(location).sort_order : Infinity;
|
|
149
|
+
}
|
|
150
|
+
async tryOn(styleId, sizeId) {
|
|
151
|
+
if (!this.isLoggedIn)
|
|
152
|
+
throw new Errors.UserNotLoggedInError();
|
|
153
|
+
const colorwaySizeAssetSku = await this.getColorwaySizeAssetSkuFromStyleIdAndSizeId(styleId, sizeId);
|
|
154
|
+
try {
|
|
155
|
+
const frames = await this.getColorwaySizeAssetFrames(colorwaySizeAssetSku);
|
|
156
|
+
return frames;
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
if (!(error instanceof Errors.NoFramesFoundError))
|
|
160
|
+
throw error;
|
|
161
|
+
return this.requestThenGetColorwaySizeAssetFrames(colorwaySizeAssetSku);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
async getColorwaySizeAssetSkuFromStyleIdAndSizeId(styleId, sizeId) {
|
|
165
|
+
var _a, _b, _c;
|
|
166
|
+
try {
|
|
167
|
+
const constraints = [where('brand_id', '==', this.brandId)];
|
|
168
|
+
constraints.push(where('style_id', '==', styleId));
|
|
169
|
+
constraints.push(where('size_id', '==', sizeId));
|
|
170
|
+
const querySnapshot = await this.firebase.getDocs('colorway_size_assets', constraints);
|
|
171
|
+
return (_c = (_b = (_a = querySnapshot.docs) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.data()) === null || _c === void 0 ? void 0 : _c.sku;
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
return getFirebaseError(error);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
async getGetTaxonomy(styleId) {
|
|
178
|
+
try {
|
|
179
|
+
const doc = await this.firebase.getDoc('style_garment_categories', String(styleId));
|
|
180
|
+
return doc;
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
return getFirebaseError(error);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
async getMeasurementLocations() {
|
|
187
|
+
const locations = await this.fetchMeasurementLocations();
|
|
188
|
+
locations.forEach((location) => {
|
|
189
|
+
this.measurementLocations.set(location.name, { name: location.garment_label, sort_order: location.sort_order });
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
async fetchMeasurementLocations() {
|
|
193
|
+
try {
|
|
194
|
+
const docs = await this.firebase.getDocs('measurement_locations', []);
|
|
195
|
+
return docs.docs.map((doc) => doc.data());
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
return getFirebaseError(error);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
async requestThenGetColorwaySizeAssetFrames(colorwaySizeAssetSku) {
|
|
202
|
+
const [error, colorwaySizeAsset] = await asyncTry(this.getColorwaySizeAssetFromSku(colorwaySizeAssetSku));
|
|
203
|
+
if (error)
|
|
204
|
+
throw error;
|
|
205
|
+
try {
|
|
206
|
+
try {
|
|
207
|
+
this.requestColorwaySizeAssetFrames(colorwaySizeAsset.id);
|
|
208
|
+
}
|
|
209
|
+
catch (_a) { }
|
|
210
|
+
return this.awaitColorwaySizeAssetFrames(colorwaySizeAssetSku);
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
if ((error === null || error === void 0 ? void 0 : error.error) === Errors.AvatarNotCreated)
|
|
214
|
+
throw new Errors.AvatarNotCreatedError();
|
|
215
|
+
throw new Errors.NoStylesFoundError();
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
async awaitColorwaySizeAssetFrames(colorwaySizeAssetSKU) {
|
|
219
|
+
var _a, _b, _c, _d;
|
|
220
|
+
if (!this.isLoggedIn)
|
|
221
|
+
throw new Errors.UserNotLoggedInError();
|
|
222
|
+
const callback = async (data) => {
|
|
223
|
+
var _a, _b, _c, _d;
|
|
224
|
+
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;
|
|
225
|
+
if (!(frames === null || frames === void 0 ? void 0 : frames.length))
|
|
226
|
+
return false;
|
|
227
|
+
return testImage(frames[0]);
|
|
228
|
+
};
|
|
229
|
+
const userProfile = (await this.user.watchUserProfileForFrames(callback));
|
|
230
|
+
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))
|
|
231
|
+
throw new Errors.NoFramesFoundError();
|
|
232
|
+
return userProfile.vto[this.brandId][colorwaySizeAssetSKU].frames;
|
|
233
|
+
}
|
|
234
|
+
async requestColorwaySizeAssetFrames(colorwaySizeAssetId) {
|
|
235
|
+
if (!this.isLoggedIn)
|
|
236
|
+
throw new Errors.UserNotLoggedInError();
|
|
237
|
+
if (!this.user.brandUserId)
|
|
238
|
+
throw new Errors.BrandUserIdNotSetError();
|
|
239
|
+
await Fetcher.Post(this.user, `/colorway-size-assets/${colorwaySizeAssetId}/frames`, {
|
|
240
|
+
brand_user_id: String(this.user.brandUserId),
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
async getColorwaySizeAssetFrames(colorwaySizeAssetSKU) {
|
|
244
|
+
var _a, _b, _c;
|
|
245
|
+
const userProfile = await this.user.getUserProfile();
|
|
246
|
+
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) || [];
|
|
247
|
+
if (!frames.length)
|
|
248
|
+
throw new Errors.NoFramesFoundError();
|
|
249
|
+
const testedImage = await testImage(frames[0]);
|
|
250
|
+
if (!testedImage)
|
|
251
|
+
throw new Errors.NoFramesFoundError();
|
|
252
|
+
return frames;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
export const initShop = (brandId, env = 'dev') => {
|
|
256
|
+
if (env === 'dev' || env === 'development')
|
|
257
|
+
console.warn('TfrShop is in development mode');
|
|
258
|
+
Config.getInstance().setEnv(env);
|
|
259
|
+
return new TfrShop(brandId, new Firebase());
|
|
260
|
+
};
|
|
261
|
+
//# sourceMappingURL=shop.js.map
|