@swan-admin/swan-ai-measurements 1.1.17 → 1.1.19
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/dist/constants.js +1 -1
- package/dist/esm/constants.js +1 -1
- package/dist/esm/fileUpload.js +189 -153
- package/dist/esm/tryOn.js +14 -2
- package/dist/tryOn.js +14 -2
- package/package.json +1 -1
- package/src/constants.ts +1 -1
- package/src/tryOn.ts +14 -2
package/dist/constants.js
CHANGED
|
@@ -21,7 +21,7 @@ exports.APP_AUTH_BASE_URL = "APP_AUTH_BASE_URL";
|
|
|
21
21
|
exports.APP_BASE_WEBSOCKET_URL = "APP_BASE_WEBSOCKET_URL";
|
|
22
22
|
exports.APP_POSE_DETECTION_WEBSOCKET_URL = "APP_POSE_DETECTION_WEBSOCKET_URL";
|
|
23
23
|
exports.API_ENDPOINTS = {
|
|
24
|
-
GET_USER_DETAIL: "/
|
|
24
|
+
GET_USER_DETAIL: "/user",
|
|
25
25
|
REGISTER_USER: "/auth/register",
|
|
26
26
|
VERIFY_USER: "/auth/verify",
|
|
27
27
|
ADD_USER: "/user",
|
package/dist/esm/constants.js
CHANGED
|
@@ -18,7 +18,7 @@ export const APP_AUTH_BASE_URL = "APP_AUTH_BASE_URL";
|
|
|
18
18
|
export const APP_BASE_WEBSOCKET_URL = "APP_BASE_WEBSOCKET_URL";
|
|
19
19
|
export const APP_POSE_DETECTION_WEBSOCKET_URL = "APP_POSE_DETECTION_WEBSOCKET_URL";
|
|
20
20
|
export const API_ENDPOINTS = {
|
|
21
|
-
GET_USER_DETAIL: "/
|
|
21
|
+
GET_USER_DETAIL: "/user",
|
|
22
22
|
REGISTER_USER: "/auth/register",
|
|
23
23
|
VERIFY_USER: "/auth/verify",
|
|
24
24
|
ADD_USER: "/user",
|
package/dist/esm/fileUpload.js
CHANGED
|
@@ -1,23 +1,51 @@
|
|
|
1
|
-
var __awaiter =
|
|
2
|
-
|
|
1
|
+
var __awaiter =
|
|
2
|
+
(this && this.__awaiter) ||
|
|
3
|
+
function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) {
|
|
5
|
+
return value instanceof P
|
|
6
|
+
? value
|
|
7
|
+
: new P(function (resolve) {
|
|
8
|
+
resolve(value);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
3
11
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
12
|
+
function fulfilled(value) {
|
|
13
|
+
try {
|
|
14
|
+
step(generator.next(value));
|
|
15
|
+
} catch (e) {
|
|
16
|
+
reject(e);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function rejected(value) {
|
|
20
|
+
try {
|
|
21
|
+
step(generator["throw"](value));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function step(result) {
|
|
27
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
28
|
+
}
|
|
29
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
30
|
});
|
|
9
|
-
};
|
|
10
|
-
var __classPrivateFieldSet =
|
|
31
|
+
};
|
|
32
|
+
var __classPrivateFieldSet =
|
|
33
|
+
(this && this.__classPrivateFieldSet) ||
|
|
34
|
+
function (receiver, state, value, kind, f) {
|
|
11
35
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
12
36
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
13
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
37
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
38
|
+
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
39
|
+
return kind === "a" ? f.call(receiver, value) : f ? (f.value = value) : state.set(receiver, value), value;
|
|
40
|
+
};
|
|
41
|
+
var __classPrivateFieldGet =
|
|
42
|
+
(this && this.__classPrivateFieldGet) ||
|
|
43
|
+
function (receiver, state, kind, f) {
|
|
17
44
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
18
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
45
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
46
|
+
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
19
47
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
20
|
-
};
|
|
48
|
+
};
|
|
21
49
|
var _FileUpload_uppyIns, _FileUpload_accessKey, _FileUpload_stagingUrl;
|
|
22
50
|
import axios from "axios";
|
|
23
51
|
import { REQUIRED_MESSAGE, REQUIRED_MESSAGE_FOR_META_DATA, FILE_UPLOAD_ENDPOINT, APP_AUTH_BASE_URL } from "./constants.js";
|
|
@@ -25,147 +53,155 @@ import { addScanType, checkMetaDataValue, checkParameters, fetchData, getFileChu
|
|
|
25
53
|
import Uppy from "@uppy/core";
|
|
26
54
|
import AwsS3Multipart from "@uppy/aws-s3-multipart";
|
|
27
55
|
class FileUpload {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
});
|
|
66
|
-
},
|
|
67
|
-
completeMultipartUpload: (file, { uploadId, key, parts }) => fetchData({
|
|
68
|
-
path: FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
|
|
69
|
-
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
70
|
-
stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
|
|
71
|
-
body: {
|
|
72
|
-
uploadId,
|
|
73
|
-
objectKey: key,
|
|
74
|
-
parts,
|
|
75
|
-
originalFileName: file.name,
|
|
76
|
-
},
|
|
77
|
-
}),
|
|
78
|
-
signPart: (file, partData) => fetchData({
|
|
79
|
-
path: FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
|
|
80
|
-
stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
|
|
81
|
-
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
82
|
-
body: {
|
|
83
|
-
objectKey: partData.key,
|
|
84
|
-
uploadId: partData.uploadId,
|
|
85
|
-
partNumber: partData.partNumber,
|
|
86
|
-
},
|
|
87
|
-
}),
|
|
88
|
-
});
|
|
89
|
-
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").addFile({
|
|
90
|
-
source: "manual",
|
|
91
|
-
name: file.name,
|
|
92
|
-
type: file.type,
|
|
93
|
-
data: file,
|
|
94
|
-
});
|
|
95
|
-
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-error", (file, error, response) => {
|
|
96
|
-
reject(error);
|
|
97
|
-
});
|
|
98
|
-
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-success", () => {
|
|
99
|
-
resolve({ message: "file uploaded successfully" });
|
|
100
|
-
});
|
|
101
|
-
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("complete", (result) => {
|
|
102
|
-
if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
|
|
103
|
-
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
|
|
104
|
-
}
|
|
105
|
-
});
|
|
56
|
+
constructor(accessKey, stagingUrl = false) {
|
|
57
|
+
_FileUpload_uppyIns.set(this, void 0);
|
|
58
|
+
_FileUpload_accessKey.set(this, void 0);
|
|
59
|
+
_FileUpload_stagingUrl.set(this, void 0);
|
|
60
|
+
__classPrivateFieldSet(this, _FileUpload_accessKey, accessKey, "f");
|
|
61
|
+
__classPrivateFieldSet(this, _FileUpload_stagingUrl, stagingUrl, "f");
|
|
62
|
+
}
|
|
63
|
+
uploadFileFrontend(_a) {
|
|
64
|
+
return __awaiter(this, arguments, void 0, function* ({ file, arrayMetaData, scanId }) {
|
|
65
|
+
if (!checkParameters(file, arrayMetaData, scanId)) {
|
|
66
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
67
|
+
}
|
|
68
|
+
if (!checkMetaDataValue(arrayMetaData)) {
|
|
69
|
+
throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
|
|
70
|
+
}
|
|
71
|
+
arrayMetaData = addScanType(arrayMetaData, scanId);
|
|
72
|
+
return new Promise((resolve, reject) => {
|
|
73
|
+
if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
|
|
74
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
|
|
75
|
+
}
|
|
76
|
+
__classPrivateFieldSet(this, _FileUpload_uppyIns, new Uppy({ autoProceed: true }), "f");
|
|
77
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").use(AwsS3Multipart, {
|
|
78
|
+
limit: 10,
|
|
79
|
+
retryDelays: [0, 1000, 3000, 5000],
|
|
80
|
+
companionUrl: getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f") }),
|
|
81
|
+
getChunkSize: () => 5 * 1024 * 1024,
|
|
82
|
+
createMultipartUpload: (file) => {
|
|
83
|
+
const objectKey = `${scanId}.${file.extension}`;
|
|
84
|
+
return fetchData({
|
|
85
|
+
path: FILE_UPLOAD_ENDPOINT.UPLOAD_START,
|
|
86
|
+
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
87
|
+
stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
|
|
88
|
+
body: {
|
|
89
|
+
objectKey,
|
|
90
|
+
contentType: file.type,
|
|
91
|
+
objectMetadata: arrayMetaData,
|
|
92
|
+
},
|
|
106
93
|
});
|
|
94
|
+
},
|
|
95
|
+
completeMultipartUpload: (file, { uploadId, key, parts }) =>
|
|
96
|
+
fetchData({
|
|
97
|
+
path: FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
|
|
98
|
+
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
99
|
+
stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
|
|
100
|
+
body: {
|
|
101
|
+
uploadId,
|
|
102
|
+
objectKey: key,
|
|
103
|
+
parts,
|
|
104
|
+
originalFileName: file.name,
|
|
105
|
+
},
|
|
106
|
+
}),
|
|
107
|
+
signPart: (file, partData) =>
|
|
108
|
+
fetchData({
|
|
109
|
+
path: FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
|
|
110
|
+
stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
|
|
111
|
+
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
112
|
+
body: {
|
|
113
|
+
objectKey: partData.key,
|
|
114
|
+
uploadId: partData.uploadId,
|
|
115
|
+
partNumber: partData.partNumber,
|
|
116
|
+
},
|
|
117
|
+
}),
|
|
107
118
|
});
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
if (!checkMetaDataValue(arrayMetaData)) {
|
|
115
|
-
throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
|
|
116
|
-
}
|
|
117
|
-
arrayMetaData = addScanType(arrayMetaData, scanId);
|
|
118
|
-
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
119
|
-
var _b;
|
|
120
|
-
try {
|
|
121
|
-
const res = yield fetchData({
|
|
122
|
-
path: FILE_UPLOAD_ENDPOINT.UPLOAD_START,
|
|
123
|
-
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
124
|
-
stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
|
|
125
|
-
body: {
|
|
126
|
-
objectKey: file.name,
|
|
127
|
-
contentType: file.type,
|
|
128
|
-
objectMetadata: arrayMetaData,
|
|
129
|
-
},
|
|
130
|
-
throwError: true,
|
|
131
|
-
});
|
|
132
|
-
const totalChunks = getFileChunks(file);
|
|
133
|
-
const parts = [];
|
|
134
|
-
for (let i = 0; i < totalChunks.length; i++) {
|
|
135
|
-
const data = yield fetchData({
|
|
136
|
-
path: FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
|
|
137
|
-
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
138
|
-
stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
|
|
139
|
-
body: {
|
|
140
|
-
objectKey: res === null || res === void 0 ? void 0 : res.key,
|
|
141
|
-
uploadId: res === null || res === void 0 ? void 0 : res.uploadId,
|
|
142
|
-
partNumber: i + 1,
|
|
143
|
-
},
|
|
144
|
-
throwError: true,
|
|
145
|
-
});
|
|
146
|
-
const val = yield axios.put(data === null || data === void 0 ? void 0 : data.url, totalChunks[i], { headers: { "Content-Type": file.type, "X-Api-Key": __classPrivateFieldGet(this, _FileUpload_accessKey, "f") } });
|
|
147
|
-
parts.push({ PartNumber: i + 1, ETag: (_b = val === null || val === void 0 ? void 0 : val.headers) === null || _b === void 0 ? void 0 : _b.etag });
|
|
148
|
-
}
|
|
149
|
-
const completeValue = yield fetchData({
|
|
150
|
-
path: FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
|
|
151
|
-
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
152
|
-
stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
|
|
153
|
-
body: {
|
|
154
|
-
uploadId: res === null || res === void 0 ? void 0 : res.uploadId,
|
|
155
|
-
objectKey: res === null || res === void 0 ? void 0 : res.key,
|
|
156
|
-
parts,
|
|
157
|
-
originalFileName: file.name,
|
|
158
|
-
},
|
|
159
|
-
throwError: true,
|
|
160
|
-
});
|
|
161
|
-
resolve({ message: "successfully uploaded", data: completeValue });
|
|
162
|
-
}
|
|
163
|
-
catch (error) {
|
|
164
|
-
reject(error);
|
|
165
|
-
}
|
|
166
|
-
}));
|
|
119
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").addFile({
|
|
120
|
+
source: "manual",
|
|
121
|
+
name: file.name,
|
|
122
|
+
type: file.type,
|
|
123
|
+
data: file,
|
|
167
124
|
});
|
|
168
|
-
|
|
125
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-error", (file, error, response) => {
|
|
126
|
+
reject(error);
|
|
127
|
+
});
|
|
128
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-success", () => {
|
|
129
|
+
resolve({ message: "file uploaded successfully" });
|
|
130
|
+
});
|
|
131
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("complete", (result) => {
|
|
132
|
+
if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
|
|
133
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
uploadFile(_a) {
|
|
140
|
+
return __awaiter(this, arguments, void 0, function* ({ file, arrayMetaData, scanId }) {
|
|
141
|
+
if (!checkParameters(file, arrayMetaData, scanId)) {
|
|
142
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
143
|
+
}
|
|
144
|
+
if (!checkMetaDataValue(arrayMetaData)) {
|
|
145
|
+
throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
|
|
146
|
+
}
|
|
147
|
+
arrayMetaData = addScanType(arrayMetaData, scanId);
|
|
148
|
+
return new Promise((resolve, reject) =>
|
|
149
|
+
__awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
var _b;
|
|
151
|
+
try {
|
|
152
|
+
const res = yield fetchData({
|
|
153
|
+
path: FILE_UPLOAD_ENDPOINT.UPLOAD_START,
|
|
154
|
+
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
155
|
+
stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
|
|
156
|
+
body: {
|
|
157
|
+
objectKey: file.name,
|
|
158
|
+
contentType: file.type,
|
|
159
|
+
objectMetadata: arrayMetaData,
|
|
160
|
+
},
|
|
161
|
+
throwError: true,
|
|
162
|
+
});
|
|
163
|
+
const totalChunks = getFileChunks(file);
|
|
164
|
+
const parts = [];
|
|
165
|
+
for (let i = 0; i < totalChunks.length; i++) {
|
|
166
|
+
const data = yield fetchData({
|
|
167
|
+
path: FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
|
|
168
|
+
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
169
|
+
stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
|
|
170
|
+
body: {
|
|
171
|
+
objectKey: res === null || res === void 0 ? void 0 : res.key,
|
|
172
|
+
uploadId: res === null || res === void 0 ? void 0 : res.uploadId,
|
|
173
|
+
partNumber: i + 1,
|
|
174
|
+
},
|
|
175
|
+
throwError: true,
|
|
176
|
+
});
|
|
177
|
+
const val = yield axios.put(data === null || data === void 0 ? void 0 : data.url, totalChunks[i], {
|
|
178
|
+
headers: { "Content-Type": file.type, "X-Api-Key": __classPrivateFieldGet(this, _FileUpload_accessKey, "f") },
|
|
179
|
+
});
|
|
180
|
+
parts.push({
|
|
181
|
+
PartNumber: i + 1,
|
|
182
|
+
ETag: (_b = val === null || val === void 0 ? void 0 : val.headers) === null || _b === void 0 ? void 0 : _b.etag,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
const completeValue = yield fetchData({
|
|
186
|
+
path: FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
|
|
187
|
+
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
188
|
+
stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
|
|
189
|
+
body: {
|
|
190
|
+
uploadId: res === null || res === void 0 ? void 0 : res.uploadId,
|
|
191
|
+
objectKey: res === null || res === void 0 ? void 0 : res.key,
|
|
192
|
+
parts,
|
|
193
|
+
originalFileName: file.name,
|
|
194
|
+
},
|
|
195
|
+
throwError: true,
|
|
196
|
+
});
|
|
197
|
+
resolve({ message: "successfully uploaded", data: completeValue });
|
|
198
|
+
} catch (error) {
|
|
199
|
+
reject(error);
|
|
200
|
+
}
|
|
201
|
+
})
|
|
202
|
+
);
|
|
203
|
+
});
|
|
204
|
+
}
|
|
169
205
|
}
|
|
170
|
-
_FileUpload_uppyIns = new WeakMap(), _FileUpload_accessKey = new WeakMap(), _FileUpload_stagingUrl = new WeakMap();
|
|
206
|
+
(_FileUpload_uppyIns = new WeakMap()), (_FileUpload_accessKey = new WeakMap()), (_FileUpload_stagingUrl = new WeakMap());
|
|
171
207
|
export default FileUpload;
|
package/dist/esm/tryOn.js
CHANGED
|
@@ -40,7 +40,7 @@ class TryOn {
|
|
|
40
40
|
__classPrivateFieldSet(this, _TryOn_timerWaitingRef, setTimeout(() => {
|
|
41
41
|
__classPrivateFieldGet(this, _TryOn_handleGetTryOnResult, "f").call(this, { shopDomain, userId, productName, onSuccess, onError });
|
|
42
42
|
__classPrivateFieldGet(this, _TryOn_disconnectSocket, "f").call(this);
|
|
43
|
-
},
|
|
43
|
+
}, 138000), "f");
|
|
44
44
|
});
|
|
45
45
|
this.handleTryOnWebSocket = ({ shopDomain, userId, productName, onError, onSuccess, onClose, onOpen }) => {
|
|
46
46
|
if (checkParameters(shopDomain, userId, productName) === false) {
|
|
@@ -62,7 +62,7 @@ class TryOn {
|
|
|
62
62
|
__classPrivateFieldGet(this, _TryOn_tryOnSocketRef, "f").onmessage = (event) => {
|
|
63
63
|
const data = JSON.parse(event.data);
|
|
64
64
|
if ((data === null || data === void 0 ? void 0 : data.status) === "success") {
|
|
65
|
-
|
|
65
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
|
|
66
66
|
}
|
|
67
67
|
else {
|
|
68
68
|
onError === null || onError === void 0 ? void 0 : onError(data);
|
|
@@ -129,6 +129,12 @@ class TryOn {
|
|
|
129
129
|
uploadFile(_a) {
|
|
130
130
|
return __awaiter(this, arguments, void 0, function* ({ files, userId }) {
|
|
131
131
|
var _b;
|
|
132
|
+
if (checkParameters(files, userId) === false) {
|
|
133
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
134
|
+
}
|
|
135
|
+
if ((files === null || files === void 0 ? void 0 : files.length) > 2) {
|
|
136
|
+
throw new Error("Cannot allow more than 2 files.");
|
|
137
|
+
}
|
|
132
138
|
try {
|
|
133
139
|
const payload = {
|
|
134
140
|
userId,
|
|
@@ -166,6 +172,9 @@ class TryOn {
|
|
|
166
172
|
}
|
|
167
173
|
}
|
|
168
174
|
_TryOn_tryOnSocketRef = new WeakMap(), _TryOn_timerWaitingRef = new WeakMap(), _TryOn_accessKey = new WeakMap(), _TryOn_stagingUrl = new WeakMap(), _TryOn_disconnectSocket = new WeakMap(), _TryOn_handleTimeOut = new WeakMap(), _TryOn_handleGetTryOnResult = new WeakMap(), _TryOn_instances = new WeakSet(), _TryOn_getSignedUrl = function _TryOn_getSignedUrl(payload) {
|
|
175
|
+
if (checkParameters(payload) === false) {
|
|
176
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
177
|
+
}
|
|
169
178
|
return axios.post(`${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: __classPrivateFieldGet(this, _TryOn_stagingUrl, "f") })}${API_ENDPOINTS.TRY_ON_IMAGE_UPLOAD}`, payload, {
|
|
170
179
|
headers: {
|
|
171
180
|
"Content-Type": "application/json",
|
|
@@ -173,6 +182,9 @@ _TryOn_tryOnSocketRef = new WeakMap(), _TryOn_timerWaitingRef = new WeakMap(), _
|
|
|
173
182
|
},
|
|
174
183
|
});
|
|
175
184
|
}, _TryOn_s3Upload = function _TryOn_s3Upload(url, file) {
|
|
185
|
+
if (checkParameters(url, file) === false) {
|
|
186
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
187
|
+
}
|
|
176
188
|
return axios.put(url, file, {
|
|
177
189
|
headers: {
|
|
178
190
|
"Content-Type": file.type,
|
package/dist/tryOn.js
CHANGED
|
@@ -16,6 +16,12 @@ class TryOn {
|
|
|
16
16
|
this.#stagingUrl = stagingUrl;
|
|
17
17
|
}
|
|
18
18
|
async uploadFile({ files, userId }) {
|
|
19
|
+
if ((0, utils_js_1.checkParameters)(files, userId) === false) {
|
|
20
|
+
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
21
|
+
}
|
|
22
|
+
if (files?.length > 2) {
|
|
23
|
+
throw new Error("Cannot allow more than 2 files.");
|
|
24
|
+
}
|
|
19
25
|
try {
|
|
20
26
|
const payload = {
|
|
21
27
|
userId,
|
|
@@ -35,6 +41,9 @@ class TryOn {
|
|
|
35
41
|
}
|
|
36
42
|
}
|
|
37
43
|
#getSignedUrl(payload) {
|
|
44
|
+
if ((0, utils_js_1.checkParameters)(payload) === false) {
|
|
45
|
+
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
46
|
+
}
|
|
38
47
|
return axios_1.default.post(`${(0, utils_js_1.getUrl)({ urlName: constants_js_1.APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl })}${constants_js_1.API_ENDPOINTS.TRY_ON_IMAGE_UPLOAD}`, payload, {
|
|
39
48
|
headers: {
|
|
40
49
|
"Content-Type": "application/json",
|
|
@@ -43,6 +52,9 @@ class TryOn {
|
|
|
43
52
|
});
|
|
44
53
|
}
|
|
45
54
|
#s3Upload(url, file) {
|
|
55
|
+
if ((0, utils_js_1.checkParameters)(url, file) === false) {
|
|
56
|
+
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
57
|
+
}
|
|
46
58
|
return axios_1.default.put(url, file, {
|
|
47
59
|
headers: {
|
|
48
60
|
"Content-Type": file.type,
|
|
@@ -75,7 +87,7 @@ class TryOn {
|
|
|
75
87
|
this.#timerWaitingRef = setTimeout(() => {
|
|
76
88
|
this.#handleGetTryOnResult({ shopDomain, userId, productName, onSuccess, onError });
|
|
77
89
|
this.#disconnectSocket();
|
|
78
|
-
},
|
|
90
|
+
}, 138000);
|
|
79
91
|
};
|
|
80
92
|
handleTryOnWebSocket = ({ shopDomain, userId, productName, onError, onSuccess, onClose, onOpen }) => {
|
|
81
93
|
if ((0, utils_js_1.checkParameters)(shopDomain, userId, productName) === false) {
|
|
@@ -97,7 +109,7 @@ class TryOn {
|
|
|
97
109
|
this.#tryOnSocketRef.onmessage = (event) => {
|
|
98
110
|
const data = JSON.parse(event.data);
|
|
99
111
|
if (data?.status === "success") {
|
|
100
|
-
|
|
112
|
+
onSuccess?.(data);
|
|
101
113
|
}
|
|
102
114
|
else {
|
|
103
115
|
onError?.(data);
|
package/package.json
CHANGED
package/src/constants.ts
CHANGED
|
@@ -28,7 +28,7 @@ export const APP_POSE_DETECTION_WEBSOCKET_URL = "APP_POSE_DETECTION_WEBSOCKET_UR
|
|
|
28
28
|
export const API_ENDPOINTS: {
|
|
29
29
|
[key: string]: string;
|
|
30
30
|
} = {
|
|
31
|
-
GET_USER_DETAIL: "/
|
|
31
|
+
GET_USER_DETAIL: "/user",
|
|
32
32
|
REGISTER_USER: "/auth/register",
|
|
33
33
|
VERIFY_USER: "/auth/verify",
|
|
34
34
|
ADD_USER: "/user",
|
package/src/tryOn.ts
CHANGED
|
@@ -54,6 +54,12 @@ class TryOn {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
async uploadFile({ files, userId }: UploadFileParams): Promise<string> {
|
|
57
|
+
if (checkParameters(files, userId) === false) {
|
|
58
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
59
|
+
}
|
|
60
|
+
if (files?.length > 2) {
|
|
61
|
+
throw new Error("Cannot allow more than 2 files.");
|
|
62
|
+
}
|
|
57
63
|
try {
|
|
58
64
|
const payload = {
|
|
59
65
|
userId,
|
|
@@ -73,6 +79,9 @@ class TryOn {
|
|
|
73
79
|
}
|
|
74
80
|
|
|
75
81
|
#getSignedUrl(payload: { userId: string; userImages: string[] }): Promise<AxiosResponse<any>> {
|
|
82
|
+
if (checkParameters(payload) === false) {
|
|
83
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
84
|
+
}
|
|
76
85
|
return axios.post(`${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: this.#stagingUrl })}${API_ENDPOINTS.TRY_ON_IMAGE_UPLOAD}`, payload, {
|
|
77
86
|
headers: {
|
|
78
87
|
"Content-Type": "application/json",
|
|
@@ -82,6 +91,9 @@ class TryOn {
|
|
|
82
91
|
}
|
|
83
92
|
|
|
84
93
|
#s3Upload(url: string, file: File): Promise<AxiosResponse<any>> {
|
|
94
|
+
if (checkParameters(url, file) === false) {
|
|
95
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
96
|
+
}
|
|
85
97
|
return axios.put(url, file, {
|
|
86
98
|
headers: {
|
|
87
99
|
"Content-Type": file.type,
|
|
@@ -125,7 +137,7 @@ class TryOn {
|
|
|
125
137
|
this.#timerWaitingRef = setTimeout(() => {
|
|
126
138
|
this.#handleGetTryOnResult({ shopDomain, userId, productName, onSuccess, onError });
|
|
127
139
|
this.#disconnectSocket();
|
|
128
|
-
},
|
|
140
|
+
}, 138000);
|
|
129
141
|
};
|
|
130
142
|
|
|
131
143
|
handleTryOnWebSocket = ({ shopDomain, userId, productName, onError, onSuccess, onClose, onOpen }: HandleTryOnWebSocketParams): void => {
|
|
@@ -149,7 +161,7 @@ class TryOn {
|
|
|
149
161
|
this.#tryOnSocketRef.onmessage = (event) => {
|
|
150
162
|
const data = JSON.parse(event.data);
|
|
151
163
|
if (data?.status === "success") {
|
|
152
|
-
|
|
164
|
+
onSuccess?.(data);
|
|
153
165
|
} else {
|
|
154
166
|
onError?.(data);
|
|
155
167
|
}
|