@swan-admin/swan-ai-measurements 1.1.18 → 1.1.20
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.d.ts +1 -0
- package/dist/constants.js +5 -4
- package/dist/esm/constants.d.ts +1 -0
- package/dist/esm/constants.js +4 -3
- package/dist/esm/fileUpload.js +154 -190
- package/dist/esm/tryOn.d.ts +14 -11
- package/dist/esm/tryOn.js +80 -32
- package/dist/esm/utils.d.ts +1 -0
- package/dist/esm/utils.js +4 -0
- package/dist/tryOn.d.ts +14 -11
- package/dist/tryOn.js +78 -30
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +6 -1
- package/package.json +58 -58
- package/src/auth.ts +116 -116
- package/src/constants.ts +64 -63
- package/src/custom.ts +57 -57
- package/src/fileUpload.ts +168 -168
- package/src/index.ts +30 -30
- package/src/measurement.ts +209 -209
- package/src/poseDetection.ts +70 -70
- package/src/tryOn.ts +101 -41
- package/src/utils.ts +113 -107
- 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.d.ts
CHANGED
|
@@ -27,4 +27,5 @@ type RequiredMetaDataKeys = keyof ObjMetaData;
|
|
|
27
27
|
export declare const requiredMetaData: RequiredMetaDataKeys[];
|
|
28
28
|
export declare const REQUIRED_MESSAGE: string;
|
|
29
29
|
export declare const REQUIRED_MESSAGE_FOR_META_DATA: string;
|
|
30
|
+
export declare const REQUIRED_ERROR_MESSAGE_INVALID_EMAIL = "Invalid Email";
|
|
30
31
|
export {};
|
package/dist/constants.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.REQUIRED_MESSAGE_FOR_META_DATA = exports.REQUIRED_MESSAGE = exports.requiredMetaData = exports.API_ENDPOINTS = exports.APP_POSE_DETECTION_WEBSOCKET_URL = exports.APP_BASE_WEBSOCKET_URL = exports.APP_AUTH_BASE_URL = exports.FILE_UPLOAD_ENDPOINT = exports.PROD_URL = exports.STAGING_URL = void 0;
|
|
3
|
+
exports.REQUIRED_ERROR_MESSAGE_INVALID_EMAIL = exports.REQUIRED_MESSAGE_FOR_META_DATA = exports.REQUIRED_MESSAGE = exports.requiredMetaData = exports.API_ENDPOINTS = exports.APP_POSE_DETECTION_WEBSOCKET_URL = exports.APP_BASE_WEBSOCKET_URL = exports.APP_AUTH_BASE_URL = exports.FILE_UPLOAD_ENDPOINT = exports.PROD_URL = exports.STAGING_URL = void 0;
|
|
4
4
|
exports.STAGING_URL = {
|
|
5
|
-
APP_AUTH_BASE_URL: "https://staging.api.
|
|
5
|
+
APP_AUTH_BASE_URL: "https://staging.api.getswan.co",
|
|
6
6
|
APP_BASE_WEBSOCKET_URL: "wss://staging.wsnotify.api.getswan.co",
|
|
7
7
|
APP_POSE_DETECTION_WEBSOCKET_URL: "https://posedetect-service-staging.ft2a64raup4pg.us-east-1.cs.amazonlightsail.com",
|
|
8
8
|
};
|
|
9
9
|
exports.PROD_URL = {
|
|
10
|
-
APP_AUTH_BASE_URL: "https://api.
|
|
10
|
+
APP_AUTH_BASE_URL: "https://api.getswan.co",
|
|
11
11
|
APP_BASE_WEBSOCKET_URL: "wss://wsnotify.api.getswan.co",
|
|
12
12
|
APP_POSE_DETECTION_WEBSOCKET_URL: "https://posedetect-service.uvcn97hn133d6.eu-west-1.cs.amazonlightsail.com",
|
|
13
13
|
};
|
|
@@ -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",
|
|
@@ -40,3 +40,4 @@ exports.API_ENDPOINTS = {
|
|
|
40
40
|
exports.requiredMetaData = ["gender", "focal_length", "height", "customer_store_url", "callback_url", "clothes_fit"];
|
|
41
41
|
exports.REQUIRED_MESSAGE = "Please verify required parameters";
|
|
42
42
|
exports.REQUIRED_MESSAGE_FOR_META_DATA = "Please verify required parameters in meta data";
|
|
43
|
+
exports.REQUIRED_ERROR_MESSAGE_INVALID_EMAIL = "Invalid Email";
|
package/dist/esm/constants.d.ts
CHANGED
|
@@ -27,4 +27,5 @@ type RequiredMetaDataKeys = keyof ObjMetaData;
|
|
|
27
27
|
export declare const requiredMetaData: RequiredMetaDataKeys[];
|
|
28
28
|
export declare const REQUIRED_MESSAGE: string;
|
|
29
29
|
export declare const REQUIRED_MESSAGE_FOR_META_DATA: string;
|
|
30
|
+
export declare const REQUIRED_ERROR_MESSAGE_INVALID_EMAIL = "Invalid Email";
|
|
30
31
|
export {};
|
package/dist/esm/constants.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export const STAGING_URL = {
|
|
2
|
-
APP_AUTH_BASE_URL: "https://staging.api.
|
|
2
|
+
APP_AUTH_BASE_URL: "https://staging.api.getswan.co",
|
|
3
3
|
APP_BASE_WEBSOCKET_URL: "wss://staging.wsnotify.api.getswan.co",
|
|
4
4
|
APP_POSE_DETECTION_WEBSOCKET_URL: "https://posedetect-service-staging.ft2a64raup4pg.us-east-1.cs.amazonlightsail.com",
|
|
5
5
|
};
|
|
6
6
|
export const PROD_URL = {
|
|
7
|
-
APP_AUTH_BASE_URL: "https://api.
|
|
7
|
+
APP_AUTH_BASE_URL: "https://api.getswan.co",
|
|
8
8
|
APP_BASE_WEBSOCKET_URL: "wss://wsnotify.api.getswan.co",
|
|
9
9
|
APP_POSE_DETECTION_WEBSOCKET_URL: "https://posedetect-service.uvcn97hn133d6.eu-west-1.cs.amazonlightsail.com",
|
|
10
10
|
};
|
|
@@ -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",
|
|
@@ -37,3 +37,4 @@ export const API_ENDPOINTS = {
|
|
|
37
37
|
export const requiredMetaData = ["gender", "focal_length", "height", "customer_store_url", "callback_url", "clothes_fit"];
|
|
38
38
|
export const REQUIRED_MESSAGE = "Please verify required parameters";
|
|
39
39
|
export const REQUIRED_MESSAGE_FOR_META_DATA = "Please verify required parameters in meta data";
|
|
40
|
+
export const REQUIRED_ERROR_MESSAGE_INVALID_EMAIL = "Invalid Email";
|
package/dist/esm/fileUpload.js
CHANGED
|
@@ -1,207 +1,171 @@
|
|
|
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
23
|
import { REQUIRED_MESSAGE, REQUIRED_MESSAGE_FOR_META_DATA, FILE_UPLOAD_ENDPOINT, APP_AUTH_BASE_URL } from "./constants.js";
|
|
52
24
|
import { addScanType, checkMetaDataValue, checkParameters, fetchData, getFileChunks, getUrl } from "./utils.js";
|
|
53
|
-
import
|
|
25
|
+
import Uppy from "@uppy/core";
|
|
54
26
|
import AwsS3Multipart from "@uppy/aws-s3-multipart";
|
|
55
27
|
class FileUpload {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
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 }) {
|
|
37
|
+
if (!checkParameters(file, arrayMetaData, scanId)) {
|
|
38
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
39
|
+
}
|
|
40
|
+
if (!checkMetaDataValue(arrayMetaData)) {
|
|
41
|
+
throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
|
|
42
|
+
}
|
|
43
|
+
arrayMetaData = addScanType(arrayMetaData, scanId);
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
|
|
46
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
|
|
47
|
+
}
|
|
48
|
+
__classPrivateFieldSet(this, _FileUpload_uppyIns, new Uppy({ autoProceed: true }), "f");
|
|
49
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").use(AwsS3Multipart, {
|
|
50
|
+
limit: 10,
|
|
51
|
+
retryDelays: [0, 1000, 3000, 5000],
|
|
52
|
+
companionUrl: getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f") }),
|
|
53
|
+
getChunkSize: () => 5 * 1024 * 1024,
|
|
54
|
+
createMultipartUpload: (file) => {
|
|
55
|
+
const objectKey = `${scanId}.${file.extension}`;
|
|
56
|
+
return fetchData({
|
|
57
|
+
path: FILE_UPLOAD_ENDPOINT.UPLOAD_START,
|
|
58
|
+
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
59
|
+
stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
|
|
60
|
+
body: {
|
|
61
|
+
objectKey,
|
|
62
|
+
contentType: file.type,
|
|
63
|
+
objectMetadata: arrayMetaData,
|
|
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
|
+
});
|
|
93
106
|
});
|
|
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
|
-
}),
|
|
118
|
-
});
|
|
119
|
-
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").addFile({
|
|
120
|
-
source: "manual",
|
|
121
|
-
name: file.name,
|
|
122
|
-
type: file.type,
|
|
123
|
-
data: file,
|
|
124
|
-
});
|
|
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
107
|
});
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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
|
-
});
|
|
108
|
+
}
|
|
109
|
+
uploadFile(_a) {
|
|
110
|
+
return __awaiter(this, arguments, void 0, function* ({ file, arrayMetaData, scanId }) {
|
|
111
|
+
if (!checkParameters(file, arrayMetaData, scanId)) {
|
|
112
|
+
throw new Error(REQUIRED_MESSAGE);
|
|
184
113
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
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
|
+
}));
|
|
167
|
+
});
|
|
168
|
+
}
|
|
205
169
|
}
|
|
206
|
-
|
|
170
|
+
_FileUpload_uppyIns = new WeakMap(), _FileUpload_accessKey = new WeakMap(), _FileUpload_stagingUrl = new WeakMap();
|
|
207
171
|
export default FileUpload;
|
package/dist/esm/tryOn.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { AxiosResponse } from "axios";
|
|
2
2
|
interface UploadFileParams {
|
|
3
3
|
files: File[];
|
|
4
|
-
|
|
4
|
+
userEmail: string;
|
|
5
5
|
}
|
|
6
6
|
interface DeleteImageParams {
|
|
7
|
-
|
|
7
|
+
userEmail: string;
|
|
8
8
|
fileName: string;
|
|
9
9
|
}
|
|
10
10
|
interface HandleTryOnWebSocketParams {
|
|
11
|
+
userEmail: string;
|
|
11
12
|
shopDomain: string;
|
|
12
|
-
|
|
13
|
+
tryonId: string;
|
|
13
14
|
productName: string;
|
|
14
15
|
onError?: (error: any) => void;
|
|
15
16
|
onSuccess?: (data: any) => void;
|
|
@@ -18,23 +19,25 @@ interface HandleTryOnWebSocketParams {
|
|
|
18
19
|
}
|
|
19
20
|
interface HandleForLatestImageParams {
|
|
20
21
|
shopDomain: string;
|
|
21
|
-
|
|
22
|
+
userEmail: string;
|
|
22
23
|
productName: string;
|
|
24
|
+
firstImageName: string;
|
|
25
|
+
secondImageName: string;
|
|
23
26
|
onError?: (error: any) => void;
|
|
24
27
|
}
|
|
25
28
|
interface GetTryOnResultParams {
|
|
26
29
|
shopDomain: string;
|
|
27
|
-
|
|
30
|
+
userEmail: string;
|
|
28
31
|
productName: string;
|
|
29
32
|
}
|
|
30
33
|
declare class TryOn {
|
|
31
34
|
#private;
|
|
32
35
|
constructor(accessKey: string, stagingUrl?: boolean);
|
|
33
|
-
uploadFile({ files,
|
|
34
|
-
getUploadedFiles(
|
|
35
|
-
deleteImage({
|
|
36
|
-
handleTryOnWebSocket: ({ shopDomain,
|
|
37
|
-
|
|
38
|
-
getTryOnResult: ({
|
|
36
|
+
uploadFile({ files, userEmail }: UploadFileParams): Promise<string>;
|
|
37
|
+
getUploadedFiles(userEmail: string): Promise<AxiosResponse<any>>;
|
|
38
|
+
deleteImage({ userEmail, fileName }: DeleteImageParams): Promise<AxiosResponse<any>>;
|
|
39
|
+
handleTryOnWebSocket: ({ userEmail, shopDomain, tryonId, productName, onError, onSuccess, onClose, onOpen }: HandleTryOnWebSocketParams) => void;
|
|
40
|
+
handleSumbmitTryOn: ({ userEmail, shopDomain, productName, firstImageName, secondImageName, onError }: HandleForLatestImageParams) => Promise<any>;
|
|
41
|
+
getTryOnResult: ({ userEmail, shopDomain, productName }: GetTryOnResultParams) => Promise<AxiosResponse<any>>;
|
|
39
42
|
}
|
|
40
43
|
export default TryOn;
|