@swan-admin/swan-ai-measurements 1.1.32 → 1.1.34
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 +33 -33
- package/dist/constants.js +1 -0
- package/dist/esm/constants.js +1 -0
- package/dist/esm/fileUpload.js +203 -163
- package/dist/esm/tryOn.d.ts +1 -0
- package/dist/esm/tryOn.js +10 -2
- package/dist/esm/utils.js +3 -4
- package/dist/fileUpload.js +2 -4
- package/dist/tryOn.d.ts +1 -0
- package/dist/tryOn.js +10 -2
- package/dist/utils.js +3 -4
- package/package.json +58 -58
- package/src/auth.ts +116 -116
- package/src/constants.ts +66 -65
- package/src/custom.ts +57 -57
- package/src/fileUpload.ts +181 -183
- package/src/index.ts +30 -30
- package/src/measurement.ts +226 -226
- package/src/poseDetection.ts +70 -70
- package/src/tryOn.ts +264 -251
- package/src/utils.ts +113 -114
- package/tsconfig.json +17 -17
package/Readme.md
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
## SWAN Node.js Library
|
|
2
|
-
|
|
3
|
-
Swan is an AI Fitting Room that lets shoppers size & try on clothes virtually. For clothing brands and online retailers, Swan powers completely personalised sales – increasing conversion & reducing expensive returns.
|
|
4
|
-
|
|
5
|
-
## Documentation
|
|
6
|
-
|
|
7
|
-
See the <a href="https://www.swanvision.ai/docs">SWAN API docs</a> for Node.js.
|
|
8
|
-
|
|
9
|
-
## Requirements
|
|
10
|
-
|
|
11
|
-
Node 20 or higher.
|
|
12
|
-
|
|
13
|
-
## Usage
|
|
14
|
-
|
|
15
|
-
##### Installation
|
|
16
|
-
|
|
17
|
-
npm i @swan-admin/swan-ai-measurements
|
|
18
|
-
|
|
19
|
-
##### Create Customer
|
|
20
|
-
|
|
21
|
-
swan.custom.createCustomer({name, store_url, location, email, emailsTier_1, emailsTier_2})
|
|
22
|
-
|
|
23
|
-
##### Upload file
|
|
24
|
-
|
|
25
|
-
swan.fileUpload.uploadFile({ file, arrayMetaData, scanId })
|
|
26
|
-
|
|
27
|
-
##### Get measurements
|
|
28
|
-
|
|
29
|
-
swan.measurement.getMeasurementResult(scanId)
|
|
30
|
-
|
|
31
|
-
## Support
|
|
32
|
-
|
|
33
|
-
New features and bug fixes are released on the latest major version of the SWAN package. If you are on an older major version, we recommend that you upgrade to the latest in order to use the new features and bug fixes including those for security vulnerabilities. Older major versions of the package will continue to be available for use, but will not be receiving any updates.
|
|
1
|
+
## SWAN Node.js Library
|
|
2
|
+
|
|
3
|
+
Swan is an AI Fitting Room that lets shoppers size & try on clothes virtually. For clothing brands and online retailers, Swan powers completely personalised sales – increasing conversion & reducing expensive returns.
|
|
4
|
+
|
|
5
|
+
## Documentation
|
|
6
|
+
|
|
7
|
+
See the <a href="https://www.swanvision.ai/docs">SWAN API docs</a> for Node.js.
|
|
8
|
+
|
|
9
|
+
## Requirements
|
|
10
|
+
|
|
11
|
+
Node 20 or higher.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
##### Installation
|
|
16
|
+
|
|
17
|
+
npm i @swan-admin/swan-ai-measurements
|
|
18
|
+
|
|
19
|
+
##### Create Customer
|
|
20
|
+
|
|
21
|
+
swan.custom.createCustomer({name, store_url, location, email, emailsTier_1, emailsTier_2})
|
|
22
|
+
|
|
23
|
+
##### Upload file
|
|
24
|
+
|
|
25
|
+
swan.fileUpload.uploadFile({ file, arrayMetaData, scanId })
|
|
26
|
+
|
|
27
|
+
##### Get measurements
|
|
28
|
+
|
|
29
|
+
swan.measurement.getMeasurementResult(scanId)
|
|
30
|
+
|
|
31
|
+
## Support
|
|
32
|
+
|
|
33
|
+
New features and bug fixes are released on the latest major version of the SWAN package. If you are on an older major version, we recommend that you upgrade to the latest in order to use the new features and bug fixes including those for security vulnerabilities. Older major versions of the package will continue to be available for use, but will not be receiving any updates.
|
package/dist/constants.js
CHANGED
|
@@ -37,6 +37,7 @@ exports.API_ENDPOINTS = {
|
|
|
37
37
|
AUTH: "/auth",
|
|
38
38
|
SCANNING: "/scanning",
|
|
39
39
|
RECOMMENDATION: "/recommendation",
|
|
40
|
+
TRY_ON_SHARE: "/tryon/share",
|
|
40
41
|
};
|
|
41
42
|
exports.requiredMetaData = ["gender", "focal_length", "height", "customer_store_url", "callback_url", "clothes_fit"];
|
|
42
43
|
exports.REQUIRED_MESSAGE = "Please verify required parameters";
|
package/dist/esm/constants.js
CHANGED
|
@@ -34,6 +34,7 @@ export const API_ENDPOINTS = {
|
|
|
34
34
|
AUTH: "/auth",
|
|
35
35
|
SCANNING: "/scanning",
|
|
36
36
|
RECOMMENDATION: "/recommendation",
|
|
37
|
+
TRY_ON_SHARE: "/tryon/share",
|
|
37
38
|
};
|
|
38
39
|
export const requiredMetaData = ["gender", "focal_length", "height", "customer_store_url", "callback_url", "clothes_fit"];
|
|
39
40
|
export const REQUIRED_MESSAGE = "Please verify required parameters";
|
package/dist/esm/fileUpload.js
CHANGED
|
@@ -1,179 +1,219 @@
|
|
|
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
|
-
import {
|
|
51
|
+
import {
|
|
52
|
+
REQUIRED_MESSAGE,
|
|
53
|
+
REQUIRED_MESSAGE_FOR_META_DATA,
|
|
54
|
+
FILE_UPLOAD_ENDPOINT,
|
|
55
|
+
APP_AUTH_BASE_URL,
|
|
56
|
+
REQUIRED_ERROR_MESSAGE_INVALID_EMAIL,
|
|
57
|
+
} from "./constants.js";
|
|
24
58
|
import { addScanType, checkMetaDataValue, checkParameters, fetchData, getFileChunks, getUrl, isValidEmail } from "./utils.js";
|
|
25
|
-
import
|
|
59
|
+
import Uppy from "@uppy/core";
|
|
26
60
|
import AwsS3Multipart from "@uppy/aws-s3-multipart";
|
|
27
61
|
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
|
-
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
},
|
|
71
|
-
completeMultipartUpload: (file, { uploadId, key, parts }) => fetchData({
|
|
72
|
-
path: FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
|
|
73
|
-
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
74
|
-
stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
|
|
75
|
-
body: {
|
|
76
|
-
uploadId,
|
|
77
|
-
objectKey: key,
|
|
78
|
-
parts,
|
|
79
|
-
originalFileName: file.name,
|
|
80
|
-
},
|
|
81
|
-
}),
|
|
82
|
-
signPart: (file, partData) => fetchData({
|
|
83
|
-
path: FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
|
|
84
|
-
stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
|
|
85
|
-
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
86
|
-
body: {
|
|
87
|
-
objectKey: partData.key,
|
|
88
|
-
uploadId: partData.uploadId,
|
|
89
|
-
partNumber: partData.partNumber,
|
|
90
|
-
},
|
|
91
|
-
}),
|
|
92
|
-
});
|
|
93
|
-
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").addFile({
|
|
94
|
-
source: "manual",
|
|
95
|
-
name: file.name,
|
|
96
|
-
type: file.type,
|
|
97
|
-
data: file,
|
|
98
|
-
});
|
|
99
|
-
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-error", (file, error, response) => {
|
|
100
|
-
reject(error);
|
|
101
|
-
});
|
|
102
|
-
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-success", () => {
|
|
103
|
-
resolve({ message: "file uploaded successfully" });
|
|
104
|
-
});
|
|
105
|
-
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("complete", (result) => {
|
|
106
|
-
if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
|
|
107
|
-
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
|
|
108
|
-
}
|
|
109
|
-
});
|
|
62
|
+
constructor(accessKey, stagingUrl = false) {
|
|
63
|
+
_FileUpload_uppyIns.set(this, void 0);
|
|
64
|
+
_FileUpload_accessKey.set(this, void 0);
|
|
65
|
+
_FileUpload_stagingUrl.set(this, void 0);
|
|
66
|
+
__classPrivateFieldSet(this, _FileUpload_accessKey, accessKey, "f");
|
|
67
|
+
__classPrivateFieldSet(this, _FileUpload_stagingUrl, stagingUrl, "f");
|
|
68
|
+
}
|
|
69
|
+
uploadFileFrontend(_a) {
|
|
70
|
+
return __awaiter(this, arguments, void 0, function* ({ file, arrayMetaData, scanId, email }) {
|
|
71
|
+
if (!checkParameters(file, arrayMetaData, scanId, email)) {
|
|
72
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
73
|
+
}
|
|
74
|
+
if (!isValidEmail(email.trim())) {
|
|
75
|
+
throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
|
|
76
|
+
}
|
|
77
|
+
if (!checkMetaDataValue(arrayMetaData)) {
|
|
78
|
+
throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
|
|
79
|
+
}
|
|
80
|
+
arrayMetaData = addScanType(arrayMetaData, scanId, email);
|
|
81
|
+
return new Promise((resolve, reject) => {
|
|
82
|
+
if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
|
|
83
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
|
|
84
|
+
}
|
|
85
|
+
__classPrivateFieldSet(this, _FileUpload_uppyIns, new Uppy({ autoProceed: true }), "f");
|
|
86
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").use(AwsS3Multipart, {
|
|
87
|
+
limit: 10,
|
|
88
|
+
retryDelays: [0, 1000, 3000, 5000],
|
|
89
|
+
companionUrl: getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f") }),
|
|
90
|
+
getChunkSize: () => 5 * 1024 * 1024,
|
|
91
|
+
createMultipartUpload: (file) => {
|
|
92
|
+
const objectKey = `${scanId}.${file.extension}`;
|
|
93
|
+
return fetchData({
|
|
94
|
+
path: FILE_UPLOAD_ENDPOINT.UPLOAD_START,
|
|
95
|
+
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
96
|
+
stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
|
|
97
|
+
body: {
|
|
98
|
+
objectKey,
|
|
99
|
+
contentType: file.type,
|
|
100
|
+
objectMetadata: arrayMetaData,
|
|
101
|
+
},
|
|
110
102
|
});
|
|
103
|
+
},
|
|
104
|
+
completeMultipartUpload: (file, { uploadId, key, parts }) =>
|
|
105
|
+
fetchData({
|
|
106
|
+
path: FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
|
|
107
|
+
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
108
|
+
stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
|
|
109
|
+
body: {
|
|
110
|
+
uploadId,
|
|
111
|
+
objectKey: key,
|
|
112
|
+
parts,
|
|
113
|
+
originalFileName: file.name,
|
|
114
|
+
},
|
|
115
|
+
}),
|
|
116
|
+
signPart: (file, partData) =>
|
|
117
|
+
fetchData({
|
|
118
|
+
path: FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
|
|
119
|
+
stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
|
|
120
|
+
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
121
|
+
body: {
|
|
122
|
+
objectKey: partData.key,
|
|
123
|
+
uploadId: partData.uploadId,
|
|
124
|
+
partNumber: partData.partNumber,
|
|
125
|
+
},
|
|
126
|
+
}),
|
|
111
127
|
});
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
throw new Error(REQUIRED_MESSAGE);
|
|
118
|
-
}
|
|
119
|
-
if (!isValidEmail(email)) {
|
|
120
|
-
throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
|
|
121
|
-
}
|
|
122
|
-
if (!checkMetaDataValue(arrayMetaData)) {
|
|
123
|
-
throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
|
|
124
|
-
}
|
|
125
|
-
arrayMetaData = addScanType(arrayMetaData, scanId, email);
|
|
126
|
-
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
127
|
-
var _b;
|
|
128
|
-
try {
|
|
129
|
-
const res = yield fetchData({
|
|
130
|
-
path: FILE_UPLOAD_ENDPOINT.UPLOAD_START,
|
|
131
|
-
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
132
|
-
stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
|
|
133
|
-
body: {
|
|
134
|
-
objectKey: file.name,
|
|
135
|
-
contentType: file.type,
|
|
136
|
-
objectMetadata: arrayMetaData,
|
|
137
|
-
},
|
|
138
|
-
throwError: true,
|
|
139
|
-
});
|
|
140
|
-
const totalChunks = getFileChunks(file);
|
|
141
|
-
const parts = [];
|
|
142
|
-
for (let i = 0; i < totalChunks.length; i++) {
|
|
143
|
-
const data = yield fetchData({
|
|
144
|
-
path: FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
|
|
145
|
-
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
146
|
-
stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
|
|
147
|
-
body: {
|
|
148
|
-
objectKey: res === null || res === void 0 ? void 0 : res.key,
|
|
149
|
-
uploadId: res === null || res === void 0 ? void 0 : res.uploadId,
|
|
150
|
-
partNumber: i + 1,
|
|
151
|
-
},
|
|
152
|
-
throwError: true,
|
|
153
|
-
});
|
|
154
|
-
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") } });
|
|
155
|
-
parts.push({ PartNumber: i + 1, ETag: (_b = val === null || val === void 0 ? void 0 : val.headers) === null || _b === void 0 ? void 0 : _b.etag });
|
|
156
|
-
}
|
|
157
|
-
const completeValue = yield fetchData({
|
|
158
|
-
path: FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
|
|
159
|
-
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
160
|
-
stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
|
|
161
|
-
body: {
|
|
162
|
-
uploadId: res === null || res === void 0 ? void 0 : res.uploadId,
|
|
163
|
-
objectKey: res === null || res === void 0 ? void 0 : res.key,
|
|
164
|
-
parts,
|
|
165
|
-
originalFileName: file.name,
|
|
166
|
-
},
|
|
167
|
-
throwError: true,
|
|
168
|
-
});
|
|
169
|
-
resolve({ message: "successfully uploaded", data: completeValue });
|
|
170
|
-
}
|
|
171
|
-
catch (error) {
|
|
172
|
-
reject(error);
|
|
173
|
-
}
|
|
174
|
-
}));
|
|
128
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").addFile({
|
|
129
|
+
source: "manual",
|
|
130
|
+
name: file.name,
|
|
131
|
+
type: file.type,
|
|
132
|
+
data: file,
|
|
175
133
|
});
|
|
176
|
-
|
|
134
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-error", (file, error, response) => {
|
|
135
|
+
reject(error);
|
|
136
|
+
});
|
|
137
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-success", () => {
|
|
138
|
+
resolve({ message: "file uploaded successfully" });
|
|
139
|
+
});
|
|
140
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("complete", (result) => {
|
|
141
|
+
if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
|
|
142
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
uploadFile(_a) {
|
|
149
|
+
return __awaiter(this, arguments, void 0, function* ({ file, arrayMetaData, scanId, email }) {
|
|
150
|
+
if (!checkParameters(file, arrayMetaData, scanId, email)) {
|
|
151
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
152
|
+
}
|
|
153
|
+
if (!isValidEmail(email.trim())) {
|
|
154
|
+
throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
|
|
155
|
+
}
|
|
156
|
+
if (!checkMetaDataValue(arrayMetaData)) {
|
|
157
|
+
throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
|
|
158
|
+
}
|
|
159
|
+
arrayMetaData = addScanType(arrayMetaData, scanId, email);
|
|
160
|
+
return new Promise((resolve, reject) =>
|
|
161
|
+
__awaiter(this, void 0, void 0, function* () {
|
|
162
|
+
var _b;
|
|
163
|
+
try {
|
|
164
|
+
const res = yield fetchData({
|
|
165
|
+
path: FILE_UPLOAD_ENDPOINT.UPLOAD_START,
|
|
166
|
+
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
167
|
+
stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
|
|
168
|
+
body: {
|
|
169
|
+
objectKey: file.name,
|
|
170
|
+
contentType: file.type,
|
|
171
|
+
objectMetadata: arrayMetaData,
|
|
172
|
+
},
|
|
173
|
+
throwError: true,
|
|
174
|
+
});
|
|
175
|
+
const totalChunks = getFileChunks(file);
|
|
176
|
+
const parts = [];
|
|
177
|
+
for (let i = 0; i < totalChunks.length; i++) {
|
|
178
|
+
const data = yield fetchData({
|
|
179
|
+
path: FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
|
|
180
|
+
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
181
|
+
stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
|
|
182
|
+
body: {
|
|
183
|
+
objectKey: res === null || res === void 0 ? void 0 : res.key,
|
|
184
|
+
uploadId: res === null || res === void 0 ? void 0 : res.uploadId,
|
|
185
|
+
partNumber: i + 1,
|
|
186
|
+
},
|
|
187
|
+
throwError: true,
|
|
188
|
+
});
|
|
189
|
+
const val = yield axios.put(data === null || data === void 0 ? void 0 : data.url, totalChunks[i], {
|
|
190
|
+
headers: { "Content-Type": file.type, "X-Api-Key": __classPrivateFieldGet(this, _FileUpload_accessKey, "f") },
|
|
191
|
+
});
|
|
192
|
+
parts.push({
|
|
193
|
+
PartNumber: i + 1,
|
|
194
|
+
ETag: (_b = val === null || val === void 0 ? void 0 : val.headers) === null || _b === void 0 ? void 0 : _b.etag,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
const completeValue = yield fetchData({
|
|
198
|
+
path: FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
|
|
199
|
+
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
200
|
+
stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
|
|
201
|
+
body: {
|
|
202
|
+
uploadId: res === null || res === void 0 ? void 0 : res.uploadId,
|
|
203
|
+
objectKey: res === null || res === void 0 ? void 0 : res.key,
|
|
204
|
+
parts,
|
|
205
|
+
originalFileName: file.name,
|
|
206
|
+
},
|
|
207
|
+
throwError: true,
|
|
208
|
+
});
|
|
209
|
+
resolve({ message: "successfully uploaded", data: completeValue });
|
|
210
|
+
} catch (error) {
|
|
211
|
+
reject(error);
|
|
212
|
+
}
|
|
213
|
+
})
|
|
214
|
+
);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
177
217
|
}
|
|
178
|
-
_FileUpload_uppyIns = new WeakMap(), _FileUpload_accessKey = new WeakMap(), _FileUpload_stagingUrl = new WeakMap();
|
|
218
|
+
(_FileUpload_uppyIns = new WeakMap()), (_FileUpload_accessKey = new WeakMap()), (_FileUpload_stagingUrl = new WeakMap());
|
|
179
219
|
export default FileUpload;
|
package/dist/esm/tryOn.d.ts
CHANGED
|
@@ -38,6 +38,7 @@ declare class TryOn {
|
|
|
38
38
|
deleteImage({ userEmail, fileName }: DeleteImageParams): Promise<AxiosResponse<any>>;
|
|
39
39
|
handleTryOnWebSocket: ({ userEmail, shopDomain, tryonId, productName, onError, onSuccess, onClose, onOpen }: HandleTryOnWebSocketParams) => void;
|
|
40
40
|
handleTryOnSubmit({ userEmail, shopDomain, productName, firstImageName, secondImageName, }: HandleForLatestImageParams): Promise<AxiosResponse<any>>;
|
|
41
|
+
getShareLink(tryonId: string): Promise<AxiosResponse<any, any>>;
|
|
41
42
|
getTryOnResult: ({ userEmail, shopDomain, productName }: GetTryOnResultParams) => Promise<AxiosResponse<any>>;
|
|
42
43
|
}
|
|
43
44
|
export default TryOn;
|
package/dist/esm/tryOn.js
CHANGED
|
@@ -43,9 +43,12 @@ class TryOn {
|
|
|
43
43
|
}, 138000), "f");
|
|
44
44
|
});
|
|
45
45
|
this.handleTryOnWebSocket = ({ userEmail, shopDomain, tryonId, productName, onError, onSuccess, onClose, onOpen }) => {
|
|
46
|
-
if (checkParameters(shopDomain, tryonId, productName) === false) {
|
|
46
|
+
if (checkParameters(shopDomain, tryonId, productName, userEmail) === false) {
|
|
47
47
|
throw new Error(REQUIRED_MESSAGE);
|
|
48
48
|
}
|
|
49
|
+
if (!isValidEmail(userEmail.trim())) {
|
|
50
|
+
throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
|
|
51
|
+
}
|
|
49
52
|
__classPrivateFieldGet(this, _TryOn_disconnectSocket, "f").call(this);
|
|
50
53
|
const url = `${getUrl({ urlName: APP_BASE_WEBSOCKET_URL, stagingUrl: __classPrivateFieldGet(this, _TryOn_stagingUrl, "f") })}${API_ENDPOINTS.TRY_ON}?tryonId=${tryonId}`;
|
|
51
54
|
__classPrivateFieldSet(this, _TryOn_tryOnSocketRef, new WebSocket(url), "f");
|
|
@@ -169,7 +172,7 @@ class TryOn {
|
|
|
169
172
|
if (checkParameters(shopDomain, userEmail, productName, firstImageName, secondImageName) === false) {
|
|
170
173
|
throw new Error(REQUIRED_MESSAGE);
|
|
171
174
|
}
|
|
172
|
-
if (!isValidEmail(userEmail)) {
|
|
175
|
+
if (!isValidEmail(userEmail.trim())) {
|
|
173
176
|
throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
|
|
174
177
|
}
|
|
175
178
|
const payload = {
|
|
@@ -183,6 +186,11 @@ class TryOn {
|
|
|
183
186
|
headers: { "X-Api-Key": __classPrivateFieldGet(this, _TryOn_accessKey, "f") },
|
|
184
187
|
});
|
|
185
188
|
}
|
|
189
|
+
getShareLink(tryonId) {
|
|
190
|
+
return axios.post(`${getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: __classPrivateFieldGet(this, _TryOn_stagingUrl, "f") })}${API_ENDPOINTS.TRY_ON_SHARE}`, { tryonId }, {
|
|
191
|
+
headers: { "X-Api-Key": __classPrivateFieldGet(this, _TryOn_accessKey, "f") },
|
|
192
|
+
});
|
|
193
|
+
}
|
|
186
194
|
}
|
|
187
195
|
_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) {
|
|
188
196
|
if (checkParameters(payload) === false) {
|
package/dist/esm/utils.js
CHANGED
|
@@ -66,10 +66,9 @@ export function checkMetaDataValue(arr) {
|
|
|
66
66
|
return true;
|
|
67
67
|
}
|
|
68
68
|
export const addScanType = (arr, scan_id, email) => {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
69
|
+
const scanType = arr.find((el) => el.scan_type);
|
|
70
|
+
if (!scanType) {
|
|
71
|
+
arr.push({ scan_type: "clothing_scan" });
|
|
73
72
|
}
|
|
74
73
|
arr.push({ scan_id });
|
|
75
74
|
arr.push({ email });
|
package/dist/fileUpload.js
CHANGED
|
@@ -17,11 +17,10 @@ class FileUpload {
|
|
|
17
17
|
this.#stagingUrl = stagingUrl;
|
|
18
18
|
}
|
|
19
19
|
async uploadFileFrontend({ file, arrayMetaData, scanId, email }) {
|
|
20
|
-
email = email.trim();
|
|
21
20
|
if (!(0, utils_js_1.checkParameters)(file, arrayMetaData, scanId, email)) {
|
|
22
21
|
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
23
22
|
}
|
|
24
|
-
if (!(0, utils_js_1.isValidEmail)(email)) {
|
|
23
|
+
if (!(0, utils_js_1.isValidEmail)(email.trim())) {
|
|
25
24
|
throw new Error(constants_js_1.REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
|
|
26
25
|
}
|
|
27
26
|
if (!(0, utils_js_1.checkMetaDataValue)(arrayMetaData)) {
|
|
@@ -93,11 +92,10 @@ class FileUpload {
|
|
|
93
92
|
});
|
|
94
93
|
}
|
|
95
94
|
async uploadFile({ file, arrayMetaData, scanId, email }) {
|
|
96
|
-
email = email.trim();
|
|
97
95
|
if (!(0, utils_js_1.checkParameters)(file, arrayMetaData, scanId, email)) {
|
|
98
96
|
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
99
97
|
}
|
|
100
|
-
if (!(0, utils_js_1.isValidEmail)(email)) {
|
|
98
|
+
if (!(0, utils_js_1.isValidEmail)(email.trim())) {
|
|
101
99
|
throw new Error(constants_js_1.REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
|
|
102
100
|
}
|
|
103
101
|
if (!(0, utils_js_1.checkMetaDataValue)(arrayMetaData)) {
|
package/dist/tryOn.d.ts
CHANGED
|
@@ -38,6 +38,7 @@ declare class TryOn {
|
|
|
38
38
|
deleteImage({ userEmail, fileName }: DeleteImageParams): Promise<AxiosResponse<any>>;
|
|
39
39
|
handleTryOnWebSocket: ({ userEmail, shopDomain, tryonId, productName, onError, onSuccess, onClose, onOpen }: HandleTryOnWebSocketParams) => void;
|
|
40
40
|
handleTryOnSubmit({ userEmail, shopDomain, productName, firstImageName, secondImageName, }: HandleForLatestImageParams): Promise<AxiosResponse<any>>;
|
|
41
|
+
getShareLink(tryonId: string): Promise<AxiosResponse<any, any>>;
|
|
41
42
|
getTryOnResult: ({ userEmail, shopDomain, productName }: GetTryOnResultParams) => Promise<AxiosResponse<any>>;
|
|
42
43
|
}
|
|
43
44
|
export default TryOn;
|
package/dist/tryOn.js
CHANGED
|
@@ -107,9 +107,12 @@ class TryOn {
|
|
|
107
107
|
}, 138000);
|
|
108
108
|
};
|
|
109
109
|
handleTryOnWebSocket = ({ userEmail, shopDomain, tryonId, productName, onError, onSuccess, onClose, onOpen }) => {
|
|
110
|
-
if ((0, utils_js_1.checkParameters)(shopDomain, tryonId, productName) === false) {
|
|
110
|
+
if ((0, utils_js_1.checkParameters)(shopDomain, tryonId, productName, userEmail) === false) {
|
|
111
111
|
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
112
112
|
}
|
|
113
|
+
if (!(0, utils_js_1.isValidEmail)(userEmail.trim())) {
|
|
114
|
+
throw new Error(constants_js_1.REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
|
|
115
|
+
}
|
|
113
116
|
this.#disconnectSocket();
|
|
114
117
|
const url = `${(0, utils_js_1.getUrl)({ urlName: constants_js_1.APP_BASE_WEBSOCKET_URL, stagingUrl: this.#stagingUrl })}${constants_js_1.API_ENDPOINTS.TRY_ON}?tryonId=${tryonId}`;
|
|
115
118
|
this.#tryOnSocketRef = new WebSocket(url);
|
|
@@ -143,7 +146,7 @@ class TryOn {
|
|
|
143
146
|
if ((0, utils_js_1.checkParameters)(shopDomain, userEmail, productName, firstImageName, secondImageName) === false) {
|
|
144
147
|
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
145
148
|
}
|
|
146
|
-
if (!(0, utils_js_1.isValidEmail)(userEmail)) {
|
|
149
|
+
if (!(0, utils_js_1.isValidEmail)(userEmail.trim())) {
|
|
147
150
|
throw new Error(constants_js_1.REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
|
|
148
151
|
}
|
|
149
152
|
const payload = {
|
|
@@ -166,6 +169,11 @@ class TryOn {
|
|
|
166
169
|
onError?.(error);
|
|
167
170
|
}
|
|
168
171
|
};
|
|
172
|
+
getShareLink(tryonId) {
|
|
173
|
+
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_SHARE}`, { tryonId }, {
|
|
174
|
+
headers: { "X-Api-Key": this.#accessKey },
|
|
175
|
+
});
|
|
176
|
+
}
|
|
169
177
|
getTryOnResult = ({ userEmail, shopDomain, productName }) => {
|
|
170
178
|
if ((0, utils_js_1.checkParameters)(shopDomain, userEmail, productName) === false) {
|
|
171
179
|
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
package/dist/utils.js
CHANGED
|
@@ -64,10 +64,9 @@ function checkMetaDataValue(arr) {
|
|
|
64
64
|
}
|
|
65
65
|
exports.checkMetaDataValue = checkMetaDataValue;
|
|
66
66
|
const addScanType = (arr, scan_id, email) => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
67
|
+
const scanType = arr.find((el) => el.scan_type);
|
|
68
|
+
if (!scanType) {
|
|
69
|
+
arr.push({ scan_type: "clothing_scan" });
|
|
71
70
|
}
|
|
72
71
|
arr.push({ scan_id });
|
|
73
72
|
arr.push({ email });
|