@swan-admin/swan-ai-measurements 1.1.23 → 1.1.24
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/esm/fileUpload.js +163 -205
- package/dist/esm/tryOn.js +4 -2
- package/dist/tryOn.js +4 -2
- package/package.json +58 -58
- package/src/auth.ts +116 -116
- package/src/constants.ts +64 -64
- package/src/custom.ts +57 -57
- package/src/fileUpload.ts +183 -183
- package/src/index.ts +30 -30
- package/src/measurement.ts +209 -209
- package/src/poseDetection.ts +70 -70
- package/src/tryOn.ts +258 -256
- package/src/utils.ts +114 -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/esm/fileUpload.js
CHANGED
|
@@ -1,221 +1,179 @@
|
|
|
1
|
-
var __awaiter =
|
|
2
|
-
|
|
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
|
-
}
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
11
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
|
|
15
|
-
|
|
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());
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
8
|
});
|
|
31
|
-
|
|
32
|
-
var __classPrivateFieldSet =
|
|
33
|
-
(this && this.__classPrivateFieldSet) ||
|
|
34
|
-
function (receiver, state, value, kind, f) {
|
|
9
|
+
};
|
|
10
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
35
11
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
36
12
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
37
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
var __classPrivateFieldGet =
|
|
42
|
-
(this && this.__classPrivateFieldGet) ||
|
|
43
|
-
function (receiver, state, kind, f) {
|
|
13
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
14
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
15
|
+
};
|
|
16
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
44
17
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
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");
|
|
18
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
47
19
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
48
|
-
|
|
20
|
+
};
|
|
49
21
|
var _FileUpload_uppyIns, _FileUpload_accessKey, _FileUpload_stagingUrl;
|
|
50
22
|
import axios from "axios";
|
|
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";
|
|
23
|
+
import { REQUIRED_MESSAGE, REQUIRED_MESSAGE_FOR_META_DATA, FILE_UPLOAD_ENDPOINT, APP_AUTH_BASE_URL, REQUIRED_ERROR_MESSAGE_INVALID_EMAIL, } from "./constants.js";
|
|
58
24
|
import { addScanType, checkMetaDataValue, checkParameters, fetchData, getFileChunks, getUrl, isValidEmail } from "./utils.js";
|
|
59
|
-
import
|
|
25
|
+
import Uppy from "@uppy/core";
|
|
60
26
|
import AwsS3Multipart from "@uppy/aws-s3-multipart";
|
|
61
27
|
class FileUpload {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
28
|
+
constructor(accessKey, stagingUrl = false) {
|
|
29
|
+
_FileUpload_uppyIns.set(this, void 0);
|
|
30
|
+
_FileUpload_accessKey.set(this, void 0);
|
|
31
|
+
_FileUpload_stagingUrl.set(this, void 0);
|
|
32
|
+
__classPrivateFieldSet(this, _FileUpload_accessKey, accessKey, "f");
|
|
33
|
+
__classPrivateFieldSet(this, _FileUpload_stagingUrl, stagingUrl, "f");
|
|
34
|
+
}
|
|
35
|
+
uploadFileFrontend(_a) {
|
|
36
|
+
return __awaiter(this, arguments, void 0, function* ({ file, arrayMetaData, scanId, email }) {
|
|
37
|
+
email = email.trim();
|
|
38
|
+
if (!checkParameters(file, arrayMetaData, scanId, email)) {
|
|
39
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
40
|
+
}
|
|
41
|
+
if (!isValidEmail(email)) {
|
|
42
|
+
throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
|
|
43
|
+
}
|
|
44
|
+
if (!checkMetaDataValue(arrayMetaData)) {
|
|
45
|
+
throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
|
|
46
|
+
}
|
|
47
|
+
arrayMetaData = addScanType(arrayMetaData, scanId, email);
|
|
48
|
+
return new Promise((resolve, reject) => {
|
|
49
|
+
if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
|
|
50
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
|
|
51
|
+
}
|
|
52
|
+
__classPrivateFieldSet(this, _FileUpload_uppyIns, new Uppy({ autoProceed: true }), "f");
|
|
53
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").use(AwsS3Multipart, {
|
|
54
|
+
limit: 10,
|
|
55
|
+
retryDelays: [0, 1000, 3000, 5000],
|
|
56
|
+
companionUrl: getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f") }),
|
|
57
|
+
getChunkSize: () => 5 * 1024 * 1024,
|
|
58
|
+
createMultipartUpload: (file) => {
|
|
59
|
+
const objectKey = `${scanId}.${file.extension}`;
|
|
60
|
+
return fetchData({
|
|
61
|
+
path: FILE_UPLOAD_ENDPOINT.UPLOAD_START,
|
|
62
|
+
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
63
|
+
stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
|
|
64
|
+
body: {
|
|
65
|
+
objectKey,
|
|
66
|
+
contentType: file.type,
|
|
67
|
+
objectMetadata: arrayMetaData,
|
|
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
|
+
});
|
|
103
110
|
});
|
|
104
|
-
},
|
|
105
|
-
completeMultipartUpload: (file, { uploadId, key, parts }) =>
|
|
106
|
-
fetchData({
|
|
107
|
-
path: FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
|
|
108
|
-
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
109
|
-
stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
|
|
110
|
-
body: {
|
|
111
|
-
uploadId,
|
|
112
|
-
objectKey: key,
|
|
113
|
-
parts,
|
|
114
|
-
originalFileName: file.name,
|
|
115
|
-
},
|
|
116
|
-
}),
|
|
117
|
-
signPart: (file, partData) =>
|
|
118
|
-
fetchData({
|
|
119
|
-
path: FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
|
|
120
|
-
stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
|
|
121
|
-
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
122
|
-
body: {
|
|
123
|
-
objectKey: partData.key,
|
|
124
|
-
uploadId: partData.uploadId,
|
|
125
|
-
partNumber: partData.partNumber,
|
|
126
|
-
},
|
|
127
|
-
}),
|
|
128
|
-
});
|
|
129
|
-
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").addFile({
|
|
130
|
-
source: "manual",
|
|
131
|
-
name: file.name,
|
|
132
|
-
type: file.type,
|
|
133
|
-
data: file,
|
|
134
|
-
});
|
|
135
|
-
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-error", (file, error, response) => {
|
|
136
|
-
reject(error);
|
|
137
|
-
});
|
|
138
|
-
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-success", () => {
|
|
139
|
-
resolve({ message: "file uploaded successfully" });
|
|
140
|
-
});
|
|
141
|
-
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("complete", (result) => {
|
|
142
|
-
if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
|
|
143
|
-
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
|
|
144
|
-
}
|
|
145
111
|
});
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
if (!checkParameters(file, arrayMetaData, scanId, email)) {
|
|
153
|
-
throw new Error(REQUIRED_MESSAGE);
|
|
154
|
-
}
|
|
155
|
-
if (!isValidEmail(email)) {
|
|
156
|
-
throw new Error(REQUIRED_ERROR_MESSAGE_INVALID_EMAIL);
|
|
157
|
-
}
|
|
158
|
-
if (!checkMetaDataValue(arrayMetaData)) {
|
|
159
|
-
throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
|
|
160
|
-
}
|
|
161
|
-
arrayMetaData = addScanType(arrayMetaData, scanId, email);
|
|
162
|
-
return new Promise((resolve, reject) =>
|
|
163
|
-
__awaiter(this, void 0, void 0, function* () {
|
|
164
|
-
var _b;
|
|
165
|
-
try {
|
|
166
|
-
const res = yield fetchData({
|
|
167
|
-
path: FILE_UPLOAD_ENDPOINT.UPLOAD_START,
|
|
168
|
-
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
169
|
-
stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
|
|
170
|
-
body: {
|
|
171
|
-
objectKey: file.name,
|
|
172
|
-
contentType: file.type,
|
|
173
|
-
objectMetadata: arrayMetaData,
|
|
174
|
-
},
|
|
175
|
-
throwError: true,
|
|
176
|
-
});
|
|
177
|
-
const totalChunks = getFileChunks(file);
|
|
178
|
-
const parts = [];
|
|
179
|
-
for (let i = 0; i < totalChunks.length; i++) {
|
|
180
|
-
const data = yield fetchData({
|
|
181
|
-
path: FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
|
|
182
|
-
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
183
|
-
stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
|
|
184
|
-
body: {
|
|
185
|
-
objectKey: res === null || res === void 0 ? void 0 : res.key,
|
|
186
|
-
uploadId: res === null || res === void 0 ? void 0 : res.uploadId,
|
|
187
|
-
partNumber: i + 1,
|
|
188
|
-
},
|
|
189
|
-
throwError: true,
|
|
190
|
-
});
|
|
191
|
-
const val = yield axios.put(data === null || data === void 0 ? void 0 : data.url, totalChunks[i], {
|
|
192
|
-
headers: { "Content-Type": file.type, "X-Api-Key": __classPrivateFieldGet(this, _FileUpload_accessKey, "f") },
|
|
193
|
-
});
|
|
194
|
-
parts.push({
|
|
195
|
-
PartNumber: i + 1,
|
|
196
|
-
ETag: (_b = val === null || val === void 0 ? void 0 : val.headers) === null || _b === void 0 ? void 0 : _b.etag,
|
|
197
|
-
});
|
|
112
|
+
}
|
|
113
|
+
uploadFile(_a) {
|
|
114
|
+
return __awaiter(this, arguments, void 0, function* ({ file, arrayMetaData, scanId, email }) {
|
|
115
|
+
email = email.trim();
|
|
116
|
+
if (!checkParameters(file, arrayMetaData, scanId, email)) {
|
|
117
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
198
118
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
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
|
+
}));
|
|
175
|
+
});
|
|
176
|
+
}
|
|
219
177
|
}
|
|
220
|
-
|
|
178
|
+
_FileUpload_uppyIns = new WeakMap(), _FileUpload_accessKey = new WeakMap(), _FileUpload_stagingUrl = new WeakMap();
|
|
221
179
|
export default FileUpload;
|
package/dist/esm/tryOn.js
CHANGED
|
@@ -127,10 +127,11 @@ class TryOn {
|
|
|
127
127
|
payload.userImages.push(files[1].name);
|
|
128
128
|
}
|
|
129
129
|
const signedUrlRes = yield __classPrivateFieldGet(this, _TryOn_instances, "m", _TryOn_getSignedUrl).call(this, payload);
|
|
130
|
+
let s3UploadResult;
|
|
130
131
|
for (const file of files) {
|
|
131
|
-
yield __classPrivateFieldGet(this, _TryOn_instances, "m", _TryOn_s3Upload).call(this, signedUrlRes.data.uploadUrls[file.name].url, file);
|
|
132
|
+
s3UploadResult = yield __classPrivateFieldGet(this, _TryOn_instances, "m", _TryOn_s3Upload).call(this, signedUrlRes.data.uploadUrls[file.name].url, file);
|
|
132
133
|
}
|
|
133
|
-
return
|
|
134
|
+
return `uploaded successfully! and ${s3UploadResult}`;
|
|
134
135
|
}
|
|
135
136
|
catch (error) {
|
|
136
137
|
throw error;
|
|
@@ -203,6 +204,7 @@ _TryOn_tryOnSocketRef = new WeakMap(), _TryOn_timerWaitingRef = new WeakMap(), _
|
|
|
203
204
|
if (checkParameters(url, file) === false) {
|
|
204
205
|
throw new Error(REQUIRED_MESSAGE);
|
|
205
206
|
}
|
|
207
|
+
console.log("s3 being called========", url, file);
|
|
206
208
|
return axios.put(url, file, {
|
|
207
209
|
headers: {
|
|
208
210
|
"Content-Type": file.type,
|
package/dist/tryOn.js
CHANGED
|
@@ -35,10 +35,11 @@ class TryOn {
|
|
|
35
35
|
payload.userImages.push(files[1].name);
|
|
36
36
|
}
|
|
37
37
|
const signedUrlRes = await this.#getSignedUrl(payload);
|
|
38
|
+
let s3UploadResult;
|
|
38
39
|
for (const file of files) {
|
|
39
|
-
await this.#s3Upload(signedUrlRes.data.uploadUrls[file.name].url, file);
|
|
40
|
+
s3UploadResult = await this.#s3Upload(signedUrlRes.data.uploadUrls[file.name].url, file);
|
|
40
41
|
}
|
|
41
|
-
return
|
|
42
|
+
return `uploaded successfully! and ${s3UploadResult}`;
|
|
42
43
|
}
|
|
43
44
|
catch (error) {
|
|
44
45
|
throw error;
|
|
@@ -59,6 +60,7 @@ class TryOn {
|
|
|
59
60
|
if ((0, utils_js_1.checkParameters)(url, file) === false) {
|
|
60
61
|
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
61
62
|
}
|
|
63
|
+
console.log("s3 being called========", url, file);
|
|
62
64
|
return axios_1.default.put(url, file, {
|
|
63
65
|
headers: {
|
|
64
66
|
"Content-Type": file.type,
|
package/package.json
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@swan-admin/swan-ai-measurements",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "provides ai measurement suggestion",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/esm/index.js",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"require": "./dist/index.js",
|
|
11
|
-
"import": "./dist/esm/index.js"
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
"dependencies": {
|
|
15
|
-
"@types/axios": "^0.14.0",
|
|
16
|
-
"@types/node": "^20.12.12",
|
|
17
|
-
"@uppy/aws-s3-multipart": "^3.11.1",
|
|
18
|
-
"@uppy/core": "^3.11.3",
|
|
19
|
-
"axios": "^1.6.7",
|
|
20
|
-
"socket.io": "^4.7.5",
|
|
21
|
-
"socket.io-client": "^4.7.5",
|
|
22
|
-
"tslib": "^2.6.2",
|
|
23
|
-
"typescript": "^5.4.5",
|
|
24
|
-
"fix-esm": "^1.0.1"
|
|
25
|
-
},
|
|
26
|
-
"scripts": {
|
|
27
|
-
"start": "nodemon dist/index.js",
|
|
28
|
-
"build": "tsc && tsc --project tsconfig.esm.json",
|
|
29
|
-
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
30
|
-
"start:dev": "nodemon src/index.ts",
|
|
31
|
-
"start:debug": "nodemon --inspect-brk src/index.ts",
|
|
32
|
-
"start:prod": "node dist/index.js",
|
|
33
|
-
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
|
34
|
-
"test": "jest",
|
|
35
|
-
"test:watch": "jest --watch",
|
|
36
|
-
"test:cov": "jest --coverage",
|
|
37
|
-
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
|
38
|
-
"test:e2e": "jest --config ./test/jest-e2e.json"
|
|
39
|
-
},
|
|
40
|
-
"repository": {
|
|
41
|
-
"type": "git",
|
|
42
|
-
"url": "https://github.com/Syze/swan-ai-measurements.git"
|
|
43
|
-
},
|
|
44
|
-
"keywords": [
|
|
45
|
-
"swan",
|
|
46
|
-
"ai",
|
|
47
|
-
"fitview"
|
|
48
|
-
],
|
|
49
|
-
"author": "paras",
|
|
50
|
-
"license": "ISC",
|
|
51
|
-
"bugs": {
|
|
52
|
-
"url": "https://github.com/Syze/swan-ai-measurements.git/issues"
|
|
53
|
-
},
|
|
54
|
-
"homepage": "https://github.com/Syze/swan-ai-measurements.git#readme",
|
|
55
|
-
"devDependencies": {
|
|
56
|
-
"nodemon": "^3.1.0"
|
|
57
|
-
}
|
|
58
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@swan-admin/swan-ai-measurements",
|
|
3
|
+
"version": "1.1.24",
|
|
4
|
+
"description": "provides ai measurement suggestion",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"require": "./dist/index.js",
|
|
11
|
+
"import": "./dist/esm/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@types/axios": "^0.14.0",
|
|
16
|
+
"@types/node": "^20.12.12",
|
|
17
|
+
"@uppy/aws-s3-multipart": "^3.11.1",
|
|
18
|
+
"@uppy/core": "^3.11.3",
|
|
19
|
+
"axios": "^1.6.7",
|
|
20
|
+
"socket.io": "^4.7.5",
|
|
21
|
+
"socket.io-client": "^4.7.5",
|
|
22
|
+
"tslib": "^2.6.2",
|
|
23
|
+
"typescript": "^5.4.5",
|
|
24
|
+
"fix-esm": "^1.0.1"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"start": "nodemon dist/index.js",
|
|
28
|
+
"build": "tsc && tsc --project tsconfig.esm.json",
|
|
29
|
+
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
30
|
+
"start:dev": "nodemon src/index.ts",
|
|
31
|
+
"start:debug": "nodemon --inspect-brk src/index.ts",
|
|
32
|
+
"start:prod": "node dist/index.js",
|
|
33
|
+
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
|
34
|
+
"test": "jest",
|
|
35
|
+
"test:watch": "jest --watch",
|
|
36
|
+
"test:cov": "jest --coverage",
|
|
37
|
+
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
|
38
|
+
"test:e2e": "jest --config ./test/jest-e2e.json"
|
|
39
|
+
},
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "https://github.com/Syze/swan-ai-measurements.git"
|
|
43
|
+
},
|
|
44
|
+
"keywords": [
|
|
45
|
+
"swan",
|
|
46
|
+
"ai",
|
|
47
|
+
"fitview"
|
|
48
|
+
],
|
|
49
|
+
"author": "paras",
|
|
50
|
+
"license": "ISC",
|
|
51
|
+
"bugs": {
|
|
52
|
+
"url": "https://github.com/Syze/swan-ai-measurements.git/issues"
|
|
53
|
+
},
|
|
54
|
+
"homepage": "https://github.com/Syze/swan-ai-measurements.git#readme",
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"nodemon": "^3.1.0"
|
|
57
|
+
}
|
|
58
|
+
}
|