@swan-admin/swan-ai-measurements 1.0.68 → 1.0.70
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/auth.js +17 -17
- package/dist/custom.js +8 -8
- package/dist/esm/auth.js +2 -2
- package/dist/esm/custom.js +2 -2
- package/dist/esm/fileUpload.d.ts +0 -1
- package/dist/esm/fileUpload.js +8 -22
- package/dist/esm/index.d.ts +6 -6
- package/dist/esm/index.js +6 -6
- package/dist/esm/measurement.js +2 -2
- package/dist/esm/poseDetection.js +1 -1
- package/dist/esm/tryOn.js +2 -2
- package/dist/esm/utils.d.ts +1 -1
- package/dist/esm/utils.js +1 -1
- package/dist/fileUpload.d.ts +0 -1
- package/dist/fileUpload.js +18 -53
- package/dist/index.d.ts +6 -6
- package/dist/index.js +12 -12
- package/dist/measurement.js +14 -14
- package/dist/poseDetection.js +2 -2
- package/dist/tryOn.js +18 -18
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +3 -3
- package/package.json +58 -57
- package/src/auth.ts +2 -2
- package/src/custom.ts +2 -2
- package/src/fileUpload.ts +6 -20
- package/src/index.ts +6 -6
- package/src/measurement.ts +2 -2
- package/src/poseDetection.ts +1 -1
- package/src/tryOn.ts +2 -2
- package/src/utils.ts +1 -1
package/dist/auth.js
CHANGED
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const axios_1 = __importDefault(require("axios"));
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const constants_js_1 = require("./constants.js");
|
|
8
|
+
const utils_js_1 = require("./utils.js");
|
|
9
9
|
class Auth {
|
|
10
10
|
#socketRef;
|
|
11
11
|
#accessKey;
|
|
@@ -13,47 +13,47 @@ class Auth {
|
|
|
13
13
|
this.#accessKey = accessKey;
|
|
14
14
|
}
|
|
15
15
|
registerUser({ email, appVerifyUrl, gender, height, username }) {
|
|
16
|
-
if (!(0,
|
|
17
|
-
throw new Error(
|
|
16
|
+
if (!(0, utils_js_1.checkParameters)(email, appVerifyUrl)) {
|
|
17
|
+
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
18
18
|
}
|
|
19
19
|
let body = { username, email, appVerifyUrl };
|
|
20
20
|
if (gender && height) {
|
|
21
21
|
body = { ...body, attributes: { gender, height } };
|
|
22
22
|
}
|
|
23
|
-
return axios_1.default.post(`${
|
|
23
|
+
return axios_1.default.post(`${constants_js_1.APP_AUTH_BASE_URL}${constants_js_1.API_ENDPOINTS.REGISTER_USER}`, body, {
|
|
24
24
|
headers: { "X-Api-Key": this.#accessKey },
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
verifyToken(token) {
|
|
28
|
-
if (!(0,
|
|
29
|
-
throw new Error(
|
|
28
|
+
if (!(0, utils_js_1.checkParameters)(token)) {
|
|
29
|
+
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
30
30
|
}
|
|
31
|
-
return axios_1.default.post(`${
|
|
31
|
+
return axios_1.default.post(`${constants_js_1.APP_AUTH_BASE_URL}${constants_js_1.API_ENDPOINTS.VERIFY_USER}`, null, {
|
|
32
32
|
params: { token },
|
|
33
33
|
headers: { "X-Api-Key": this.#accessKey },
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
36
|
addUser({ scanId, email, name, height, gender, offsetMarketingConsent }) {
|
|
37
|
-
if (!(0,
|
|
38
|
-
throw new Error(
|
|
37
|
+
if (!(0, utils_js_1.checkParameters)(scanId, email, height, gender)) {
|
|
38
|
+
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
39
39
|
}
|
|
40
|
-
return axios_1.default.post(`${
|
|
40
|
+
return axios_1.default.post(`${constants_js_1.APP_AUTH_BASE_URL}${constants_js_1.API_ENDPOINTS.ADD_USER}`, { scan_id: scanId, email, name, offsetMarketingConsent, attributes: JSON.stringify({ height, gender }) }, { headers: { "X-Api-Key": this.#accessKey } });
|
|
41
41
|
}
|
|
42
42
|
getUserDetail(email) {
|
|
43
|
-
if (!(0,
|
|
44
|
-
throw new Error(
|
|
43
|
+
if (!(0, utils_js_1.checkParameters)(email)) {
|
|
44
|
+
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
45
45
|
}
|
|
46
|
-
return axios_1.default.get(`${
|
|
46
|
+
return axios_1.default.get(`${constants_js_1.APP_BASE_URL}${constants_js_1.API_ENDPOINTS.GET_USER_DETAIL}/${email}`, {
|
|
47
47
|
headers: { "X-Api-Key": this.#accessKey },
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
handleAuthSocket({ email, scanId, onError, onSuccess, onClose, onOpen }) {
|
|
51
|
-
if (!(0,
|
|
52
|
-
throw new Error(
|
|
51
|
+
if (!(0, utils_js_1.checkParameters)(email, scanId)) {
|
|
52
|
+
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
53
53
|
}
|
|
54
54
|
if (this.#socketRef)
|
|
55
55
|
this.#socketRef.close();
|
|
56
|
-
this.#socketRef = new WebSocket(`${
|
|
56
|
+
this.#socketRef = new WebSocket(`${constants_js_1.APP_AUTH_WEBSOCKET_URL}${constants_js_1.API_ENDPOINTS.AUTH}`);
|
|
57
57
|
const detailObj = { email, scanId };
|
|
58
58
|
this.#socketRef.onopen = () => {
|
|
59
59
|
this.#socketRef?.send(JSON.stringify(detailObj));
|
package/dist/custom.js
CHANGED
|
@@ -4,27 +4,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const axios_1 = __importDefault(require("axios"));
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const constants_js_1 = require("./constants.js");
|
|
8
|
+
const utils_js_1 = require("./utils.js");
|
|
9
9
|
class Custom {
|
|
10
10
|
#accessKey;
|
|
11
11
|
constructor(accessKey) {
|
|
12
12
|
this.#accessKey = accessKey;
|
|
13
13
|
}
|
|
14
14
|
getCustomCustomerConfig = (store_url) => {
|
|
15
|
-
if ((0,
|
|
16
|
-
throw new Error(
|
|
15
|
+
if ((0, utils_js_1.checkParameters)(store_url) === false) {
|
|
16
|
+
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
17
17
|
}
|
|
18
|
-
return axios_1.default.get(`${
|
|
18
|
+
return axios_1.default.get(`${constants_js_1.APP_AUTH_BASE_URL}${constants_js_1.API_ENDPOINTS.CUSTOM_CUSTOMER}`, {
|
|
19
19
|
params: { store_url },
|
|
20
20
|
headers: { "X-Api-Key": this.#accessKey },
|
|
21
21
|
});
|
|
22
22
|
};
|
|
23
23
|
getModelUrl = (id) => {
|
|
24
|
-
if ((0,
|
|
25
|
-
throw new Error(
|
|
24
|
+
if ((0, utils_js_1.checkParameters)(id) === false) {
|
|
25
|
+
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
26
26
|
}
|
|
27
|
-
return axios_1.default.get(`${
|
|
27
|
+
return axios_1.default.get(`${constants_js_1.APP_AUTH_BASE_URL}${constants_js_1.API_ENDPOINTS.MODEL}/${id}`, { headers: { "X-Api-Key": this.#accessKey } });
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
exports.default = Custom;
|
package/dist/esm/auth.js
CHANGED
|
@@ -11,8 +11,8 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
11
11
|
};
|
|
12
12
|
var _Auth_socketRef, _Auth_accessKey;
|
|
13
13
|
import axios from "axios";
|
|
14
|
-
import { API_ENDPOINTS, APP_AUTH_BASE_URL, APP_AUTH_WEBSOCKET_URL, APP_BASE_URL, REQUIRED_MESSAGE } from "./constants";
|
|
15
|
-
import { checkParameters } from "./utils";
|
|
14
|
+
import { API_ENDPOINTS, APP_AUTH_BASE_URL, APP_AUTH_WEBSOCKET_URL, APP_BASE_URL, REQUIRED_MESSAGE } from "./constants.js";
|
|
15
|
+
import { checkParameters } from "./utils.js";
|
|
16
16
|
class Auth {
|
|
17
17
|
constructor(accessKey) {
|
|
18
18
|
_Auth_socketRef.set(this, void 0);
|
package/dist/esm/custom.js
CHANGED
|
@@ -11,8 +11,8 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
11
11
|
};
|
|
12
12
|
var _Custom_accessKey;
|
|
13
13
|
import axios from "axios";
|
|
14
|
-
import { API_ENDPOINTS, APP_AUTH_BASE_URL, REQUIRED_MESSAGE } from "./constants";
|
|
15
|
-
import { checkParameters } from "./utils";
|
|
14
|
+
import { API_ENDPOINTS, APP_AUTH_BASE_URL, REQUIRED_MESSAGE } from "./constants.js";
|
|
15
|
+
import { checkParameters } from "./utils.js";
|
|
16
16
|
class Custom {
|
|
17
17
|
constructor(accessKey) {
|
|
18
18
|
_Custom_accessKey.set(this, void 0);
|
package/dist/esm/fileUpload.d.ts
CHANGED
package/dist/esm/fileUpload.js
CHANGED
|
@@ -18,30 +18,17 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
18
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");
|
|
19
19
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
20
20
|
};
|
|
21
|
-
var _FileUpload_uppyIns, _FileUpload_accessKey
|
|
22
|
-
import { REQUIRED_MESSAGE, REQUIRED_MESSAGE_FOR_META_DATA, UPPY_FILE_UPLOAD_ENDPOINT } from "./constants";
|
|
23
|
-
import { checkMetaDataValue, checkParameters, fetchData } from "./utils";
|
|
21
|
+
var _FileUpload_uppyIns, _FileUpload_accessKey;
|
|
22
|
+
import { REQUIRED_MESSAGE, REQUIRED_MESSAGE_FOR_META_DATA, UPPY_FILE_UPLOAD_ENDPOINT } from "./constants.js";
|
|
23
|
+
import { checkMetaDataValue, checkParameters, fetchData } from "./utils.js";
|
|
24
|
+
const Uppy = require("fix-esm").require("@uppy/core");
|
|
25
|
+
const AwsS3Multipart = require("fix-esm").require("@uppy/aws-s3-multipart");
|
|
24
26
|
class FileUpload {
|
|
25
27
|
constructor(accessKey) {
|
|
26
28
|
_FileUpload_uppyIns.set(this, void 0);
|
|
27
29
|
_FileUpload_accessKey.set(this, void 0);
|
|
28
|
-
_FileUpload_Uppy.set(this, void 0);
|
|
29
|
-
_FileUpload_AwsS3Multipart.set(this, void 0);
|
|
30
30
|
__classPrivateFieldSet(this, _FileUpload_accessKey, accessKey, "f");
|
|
31
31
|
}
|
|
32
|
-
initializeModules() {
|
|
33
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
if (!__classPrivateFieldGet(this, _FileUpload_Uppy, "f") || !__classPrivateFieldGet(this, _FileUpload_AwsS3Multipart, "f")) {
|
|
35
|
-
// const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
|
|
36
|
-
const Uppy = () => import("@uppy/core").then(({ default: Uppy }) => Uppy);
|
|
37
|
-
const AwsS3Multipart = () => import("@uppy/aws-s3-multipart").then(({ default: AwsS3Multipart }) => AwsS3Multipart);
|
|
38
|
-
// const { default: Uppy } = await import("@uppy/core");
|
|
39
|
-
// const { default: AwsS3Multipart } = await import("@uppy/aws-s3-multipart");
|
|
40
|
-
__classPrivateFieldSet(this, _FileUpload_Uppy, Uppy, "f");
|
|
41
|
-
__classPrivateFieldSet(this, _FileUpload_AwsS3Multipart, AwsS3Multipart, "f");
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
32
|
uploadFile(_a) {
|
|
46
33
|
return __awaiter(this, arguments, void 0, function* ({ file, arrayMetaData, scanId }) {
|
|
47
34
|
if (!checkParameters(file, arrayMetaData, scanId)) {
|
|
@@ -50,13 +37,12 @@ class FileUpload {
|
|
|
50
37
|
if (!checkMetaDataValue(arrayMetaData)) {
|
|
51
38
|
throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
|
|
52
39
|
}
|
|
53
|
-
yield this.initializeModules();
|
|
54
40
|
return new Promise((resolve, reject) => {
|
|
55
41
|
if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
|
|
56
42
|
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
|
|
57
43
|
}
|
|
58
|
-
__classPrivateFieldSet(this, _FileUpload_uppyIns, new (
|
|
59
|
-
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").use(
|
|
44
|
+
__classPrivateFieldSet(this, _FileUpload_uppyIns, new Uppy.default({ autoProceed: true }), "f");
|
|
45
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").use(AwsS3Multipart.default, {
|
|
60
46
|
limit: 10,
|
|
61
47
|
retryDelays: [0, 1000, 3000, 5000],
|
|
62
48
|
getChunkSize: () => 5 * 1024 * 1024,
|
|
@@ -122,5 +108,5 @@ class FileUpload {
|
|
|
122
108
|
});
|
|
123
109
|
}
|
|
124
110
|
}
|
|
125
|
-
_FileUpload_uppyIns = new WeakMap(), _FileUpload_accessKey = new WeakMap()
|
|
111
|
+
_FileUpload_uppyIns = new WeakMap(), _FileUpload_accessKey = new WeakMap();
|
|
126
112
|
export default FileUpload;
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import Auth from "./auth";
|
|
2
|
-
import Custom from "./custom";
|
|
3
|
-
import FileUpload from "./fileUpload";
|
|
4
|
-
import Measurement from "./measurement";
|
|
5
|
-
import PoseDetection from "./poseDetection";
|
|
6
|
-
import TryOn from "./tryOn";
|
|
1
|
+
import Auth from "./auth.js";
|
|
2
|
+
import Custom from "./custom.js";
|
|
3
|
+
import FileUpload from "./fileUpload.js";
|
|
4
|
+
import Measurement from "./measurement.js";
|
|
5
|
+
import PoseDetection from "./poseDetection.js";
|
|
6
|
+
import TryOn from "./tryOn.js";
|
|
7
7
|
declare class Swan {
|
|
8
8
|
#private;
|
|
9
9
|
auth: Auth;
|
package/dist/esm/index.js
CHANGED
|
@@ -10,12 +10,12 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
12
|
var _Swan_accessKey;
|
|
13
|
-
import Auth from "./auth";
|
|
14
|
-
import Custom from "./custom";
|
|
15
|
-
import FileUpload from "./fileUpload";
|
|
16
|
-
import Measurement from "./measurement";
|
|
17
|
-
import PoseDetection from "./poseDetection";
|
|
18
|
-
import TryOn from "./tryOn";
|
|
13
|
+
import Auth from "./auth.js";
|
|
14
|
+
import Custom from "./custom.js";
|
|
15
|
+
import FileUpload from "./fileUpload.js";
|
|
16
|
+
import Measurement from "./measurement.js";
|
|
17
|
+
import PoseDetection from "./poseDetection.js";
|
|
18
|
+
import TryOn from "./tryOn.js";
|
|
19
19
|
class Swan {
|
|
20
20
|
constructor(accessKey) {
|
|
21
21
|
_Swan_accessKey.set(this, void 0);
|
package/dist/esm/measurement.js
CHANGED
|
@@ -20,8 +20,8 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
20
20
|
};
|
|
21
21
|
var _Measurement_instances, _Measurement_tryOnSocketRef, _Measurement_measurementSocketRef, _Measurement_timerPollingRef, _Measurement_timerWaitingRef, _Measurement_count, _Measurement_accessKey, _Measurement_getMeasurementsCheck, _Measurement_handlePolling, _Measurement_disconnectSocket, _Measurement_handleTimeOut;
|
|
22
22
|
import axios from "axios";
|
|
23
|
-
import { API_ENDPOINTS, APP_AUTH_BASE_URL, APP_RECOMMENDATION_WEBSOCKET_URL, APP_TRY_ON_WEBSOCKET_URL, REQUIRED_MESSAGE } from "./constants";
|
|
24
|
-
import { checkParameters } from "./utils";
|
|
23
|
+
import { API_ENDPOINTS, APP_AUTH_BASE_URL, APP_RECOMMENDATION_WEBSOCKET_URL, APP_TRY_ON_WEBSOCKET_URL, REQUIRED_MESSAGE } from "./constants.js";
|
|
24
|
+
import { checkParameters } from "./utils.js";
|
|
25
25
|
class Measurement {
|
|
26
26
|
constructor(accessKey) {
|
|
27
27
|
_Measurement_instances.add(this);
|
|
@@ -11,7 +11,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
11
11
|
};
|
|
12
12
|
var _PoseDetection_socketRef, _PoseDetection_accessKey;
|
|
13
13
|
import { io } from "socket.io-client";
|
|
14
|
-
import { APP_POSE_DETECTION_WEBSOCKET_URL } from "./constants";
|
|
14
|
+
import { APP_POSE_DETECTION_WEBSOCKET_URL } from "./constants.js";
|
|
15
15
|
class PoseDetection {
|
|
16
16
|
constructor(accessKey) {
|
|
17
17
|
_PoseDetection_socketRef.set(this, null);
|
package/dist/esm/tryOn.js
CHANGED
|
@@ -20,8 +20,8 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
20
20
|
};
|
|
21
21
|
var _TryOn_instances, _TryOn_tryOnSocketRef, _TryOn_timerWaitingRef, _TryOn_accessKey, _TryOn_getSignedUrl, _TryOn_s3Upload, _TryOn_disconnectSocket, _TryOn_handleTimeOut, _TryOn_handleGetTryOnResult;
|
|
22
22
|
import axios from "axios";
|
|
23
|
-
import { API_ENDPOINTS, APP_AUTH_BASE_URL, APP_AUTH_WEBSOCKET_URL, REQUIRED_MESSAGE } from "./constants";
|
|
24
|
-
import { checkParameters } from "./utils";
|
|
23
|
+
import { API_ENDPOINTS, APP_AUTH_BASE_URL, APP_AUTH_WEBSOCKET_URL, REQUIRED_MESSAGE } from "./constants.js";
|
|
24
|
+
import { checkParameters } from "./utils.js";
|
|
25
25
|
class TryOn {
|
|
26
26
|
constructor(accessKey) {
|
|
27
27
|
_TryOn_instances.add(this);
|
package/dist/esm/utils.d.ts
CHANGED
package/dist/esm/utils.js
CHANGED
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import axios from "axios";
|
|
11
|
-
import { APP_AUTH_BASE_URL, requiredMetaData } from "./constants";
|
|
11
|
+
import { APP_AUTH_BASE_URL, requiredMetaData } from "./constants.js";
|
|
12
12
|
export function fetchData(options) {
|
|
13
13
|
return __awaiter(this, void 0, void 0, function* () {
|
|
14
14
|
const { path, body, queryParams, baseUrl = APP_AUTH_BASE_URL, apiKey = "", headers = { "X-Api-Key": apiKey, "Content-Type": "application/json" }, } = options;
|
package/dist/fileUpload.d.ts
CHANGED
package/dist/fileUpload.js
CHANGED
|
@@ -1,70 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const
|
|
27
|
-
const
|
|
3
|
+
const constants_js_1 = require("./constants.js");
|
|
4
|
+
const utils_js_1 = require("./utils.js");
|
|
5
|
+
const Uppy = require("fix-esm").require("@uppy/core");
|
|
6
|
+
const AwsS3Multipart = require("fix-esm").require("@uppy/aws-s3-multipart");
|
|
28
7
|
class FileUpload {
|
|
29
8
|
#uppyIns;
|
|
30
9
|
#accessKey;
|
|
31
|
-
#Uppy;
|
|
32
|
-
#AwsS3Multipart;
|
|
33
10
|
constructor(accessKey) {
|
|
34
11
|
this.#accessKey = accessKey;
|
|
35
12
|
}
|
|
36
|
-
async initializeModules() {
|
|
37
|
-
if (!this.#Uppy || !this.#AwsS3Multipart) {
|
|
38
|
-
// const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
|
|
39
|
-
const Uppy = () => Promise.resolve().then(() => __importStar(require("@uppy/core"))).then(({ default: Uppy }) => Uppy);
|
|
40
|
-
const AwsS3Multipart = () => Promise.resolve().then(() => __importStar(require("@uppy/aws-s3-multipart"))).then(({ default: AwsS3Multipart }) => AwsS3Multipart);
|
|
41
|
-
// const { default: Uppy } = await import("@uppy/core");
|
|
42
|
-
// const { default: AwsS3Multipart } = await import("@uppy/aws-s3-multipart");
|
|
43
|
-
this.#Uppy = Uppy;
|
|
44
|
-
this.#AwsS3Multipart = AwsS3Multipart;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
13
|
async uploadFile({ file, arrayMetaData, scanId }) {
|
|
48
|
-
if (!(0,
|
|
49
|
-
throw new Error(
|
|
14
|
+
if (!(0, utils_js_1.checkParameters)(file, arrayMetaData, scanId)) {
|
|
15
|
+
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
50
16
|
}
|
|
51
|
-
if (!(0,
|
|
52
|
-
throw new Error(
|
|
17
|
+
if (!(0, utils_js_1.checkMetaDataValue)(arrayMetaData)) {
|
|
18
|
+
throw new Error(constants_js_1.REQUIRED_MESSAGE_FOR_META_DATA);
|
|
53
19
|
}
|
|
54
|
-
await this.initializeModules();
|
|
55
20
|
return new Promise((resolve, reject) => {
|
|
56
21
|
if (this.#uppyIns) {
|
|
57
22
|
this.#uppyIns.close();
|
|
58
23
|
}
|
|
59
|
-
this.#uppyIns = new
|
|
60
|
-
this.#uppyIns.use(
|
|
24
|
+
this.#uppyIns = new Uppy.default({ autoProceed: true });
|
|
25
|
+
this.#uppyIns.use(AwsS3Multipart.default, {
|
|
61
26
|
limit: 10,
|
|
62
27
|
retryDelays: [0, 1000, 3000, 5000],
|
|
63
28
|
getChunkSize: () => 5 * 1024 * 1024,
|
|
64
29
|
createMultipartUpload: (file) => {
|
|
65
30
|
const objectKey = `${scanId}.${file.extension}`;
|
|
66
|
-
return (0,
|
|
67
|
-
path:
|
|
31
|
+
return (0, utils_js_1.fetchData)({
|
|
32
|
+
path: constants_js_1.UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_START,
|
|
68
33
|
apiKey: this.#accessKey,
|
|
69
34
|
body: {
|
|
70
35
|
objectKey,
|
|
@@ -73,8 +38,8 @@ class FileUpload {
|
|
|
73
38
|
},
|
|
74
39
|
});
|
|
75
40
|
},
|
|
76
|
-
completeMultipartUpload: (file, { uploadId, key, parts }) => (0,
|
|
77
|
-
path:
|
|
41
|
+
completeMultipartUpload: (file, { uploadId, key, parts }) => (0, utils_js_1.fetchData)({
|
|
42
|
+
path: constants_js_1.UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
|
|
78
43
|
apiKey: this.#accessKey,
|
|
79
44
|
body: {
|
|
80
45
|
uploadId,
|
|
@@ -83,8 +48,8 @@ class FileUpload {
|
|
|
83
48
|
originalFileName: file.name,
|
|
84
49
|
},
|
|
85
50
|
}),
|
|
86
|
-
signPart: (file, partData) => (0,
|
|
87
|
-
path:
|
|
51
|
+
signPart: (file, partData) => (0, utils_js_1.fetchData)({
|
|
52
|
+
path: constants_js_1.UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
|
|
88
53
|
apiKey: this.#accessKey,
|
|
89
54
|
body: {
|
|
90
55
|
objectKey: partData.key,
|
|
@@ -92,8 +57,8 @@ class FileUpload {
|
|
|
92
57
|
partNumber: partData.partNumber,
|
|
93
58
|
},
|
|
94
59
|
}),
|
|
95
|
-
abortMultipartUpload: (file, { uploadId, key }) => (0,
|
|
96
|
-
path:
|
|
60
|
+
abortMultipartUpload: (file, { uploadId, key }) => (0, utils_js_1.fetchData)({
|
|
61
|
+
path: constants_js_1.UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_ABORT,
|
|
97
62
|
apiKey: this.#accessKey,
|
|
98
63
|
body: {
|
|
99
64
|
uploadId,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import Auth from "./auth";
|
|
2
|
-
import Custom from "./custom";
|
|
3
|
-
import FileUpload from "./fileUpload";
|
|
4
|
-
import Measurement from "./measurement";
|
|
5
|
-
import PoseDetection from "./poseDetection";
|
|
6
|
-
import TryOn from "./tryOn";
|
|
1
|
+
import Auth from "./auth.js";
|
|
2
|
+
import Custom from "./custom.js";
|
|
3
|
+
import FileUpload from "./fileUpload.js";
|
|
4
|
+
import Measurement from "./measurement.js";
|
|
5
|
+
import PoseDetection from "./poseDetection.js";
|
|
6
|
+
import TryOn from "./tryOn.js";
|
|
7
7
|
declare class Swan {
|
|
8
8
|
#private;
|
|
9
9
|
auth: Auth;
|
package/dist/index.js
CHANGED
|
@@ -3,12 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
6
|
+
const auth_js_1 = __importDefault(require("./auth.js"));
|
|
7
|
+
const custom_js_1 = __importDefault(require("./custom.js"));
|
|
8
|
+
const fileUpload_js_1 = __importDefault(require("./fileUpload.js"));
|
|
9
|
+
const measurement_js_1 = __importDefault(require("./measurement.js"));
|
|
10
|
+
const poseDetection_js_1 = __importDefault(require("./poseDetection.js"));
|
|
11
|
+
const tryOn_js_1 = __importDefault(require("./tryOn.js"));
|
|
12
12
|
class Swan {
|
|
13
13
|
#accessKey;
|
|
14
14
|
auth;
|
|
@@ -19,12 +19,12 @@ class Swan {
|
|
|
19
19
|
tryOn;
|
|
20
20
|
constructor(accessKey) {
|
|
21
21
|
this.#accessKey = accessKey;
|
|
22
|
-
this.auth = new
|
|
23
|
-
this.custom = new
|
|
24
|
-
this.fileUpload = new
|
|
25
|
-
this.measurement = new
|
|
26
|
-
this.poseDetection = new
|
|
27
|
-
this.tryOn = new
|
|
22
|
+
this.auth = new auth_js_1.default(this.#accessKey);
|
|
23
|
+
this.custom = new custom_js_1.default(this.#accessKey);
|
|
24
|
+
this.fileUpload = new fileUpload_js_1.default(this.#accessKey);
|
|
25
|
+
this.measurement = new measurement_js_1.default(this.#accessKey);
|
|
26
|
+
this.poseDetection = new poseDetection_js_1.default(this.#accessKey);
|
|
27
|
+
this.tryOn = new tryOn_js_1.default(this.#accessKey);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
exports.default = Swan;
|
package/dist/measurement.js
CHANGED
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const axios_1 = __importDefault(require("axios"));
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const constants_js_1 = require("./constants.js");
|
|
8
|
+
const utils_js_1 = require("./utils.js");
|
|
9
9
|
class Measurement {
|
|
10
10
|
#tryOnSocketRef = null;
|
|
11
11
|
#measurementSocketRef = null;
|
|
@@ -17,28 +17,28 @@ class Measurement {
|
|
|
17
17
|
this.#accessKey = accessKey;
|
|
18
18
|
}
|
|
19
19
|
getMeasurementResult(scanId) {
|
|
20
|
-
if (!(0,
|
|
21
|
-
throw new Error(
|
|
20
|
+
if (!(0, utils_js_1.checkParameters)(scanId)) {
|
|
21
|
+
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
22
22
|
}
|
|
23
|
-
const url = `${
|
|
23
|
+
const url = `${constants_js_1.APP_AUTH_BASE_URL}/measurements?scanId=${scanId}`;
|
|
24
24
|
return axios_1.default.get(url, {
|
|
25
25
|
headers: { "X-Api-Key": this.#accessKey },
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
getTryOnMeasurements({ scanId, shopDomain, productName }) {
|
|
29
|
-
if (!(0,
|
|
30
|
-
throw new Error(
|
|
29
|
+
if (!(0, utils_js_1.checkParameters)(scanId, shopDomain, productName)) {
|
|
30
|
+
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
31
31
|
}
|
|
32
|
-
const tryOnUrl = `${
|
|
32
|
+
const tryOnUrl = `${constants_js_1.APP_AUTH_BASE_URL}${constants_js_1.API_ENDPOINTS.TRY_ON_SCAN}/${scanId}/shop/${shopDomain}/product/${productName}`;
|
|
33
33
|
return axios_1.default.get(tryOnUrl, { headers: { "X-Api-Key": this.#accessKey } });
|
|
34
34
|
}
|
|
35
35
|
handleTryOnSocket(options) {
|
|
36
36
|
const { shopDomain, scanId, productName, onError, onSuccess, onClose, onOpen } = options;
|
|
37
|
-
if (!(0,
|
|
38
|
-
throw new Error(
|
|
37
|
+
if (!(0, utils_js_1.checkParameters)(shopDomain, scanId, productName)) {
|
|
38
|
+
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
39
39
|
}
|
|
40
40
|
this.#tryOnSocketRef?.close();
|
|
41
|
-
const url = `${
|
|
41
|
+
const url = `${constants_js_1.APP_TRY_ON_WEBSOCKET_URL}/develop?store_url=${shopDomain}&product_name=${productName}&scan_id=${scanId}`;
|
|
42
42
|
this.#tryOnSocketRef = new WebSocket(url);
|
|
43
43
|
this.#tryOnSocketRef.onopen = () => {
|
|
44
44
|
onOpen?.();
|
|
@@ -115,12 +115,12 @@ class Measurement {
|
|
|
115
115
|
}
|
|
116
116
|
handleMeasurementSocket(options) {
|
|
117
117
|
const { scanId, onError, onSuccess, onClose, onOpen } = options;
|
|
118
|
-
if (!(0,
|
|
119
|
-
throw new Error(
|
|
118
|
+
if (!(0, utils_js_1.checkParameters)(scanId)) {
|
|
119
|
+
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
120
120
|
}
|
|
121
121
|
setTimeout(() => {
|
|
122
122
|
this.#disconnectSocket();
|
|
123
|
-
const url = `${
|
|
123
|
+
const url = `${constants_js_1.APP_RECOMMENDATION_WEBSOCKET_URL}?scanId=${scanId}`;
|
|
124
124
|
this.#measurementSocketRef = new WebSocket(url);
|
|
125
125
|
this.#measurementSocketRef.onopen = () => {
|
|
126
126
|
onOpen?.();
|
package/dist/poseDetection.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const socket_io_client_1 = require("socket.io-client");
|
|
4
|
-
const
|
|
4
|
+
const constants_js_1 = require("./constants.js");
|
|
5
5
|
class PoseDetection {
|
|
6
6
|
#socketRef = null;
|
|
7
7
|
#accessKey;
|
|
@@ -10,7 +10,7 @@ class PoseDetection {
|
|
|
10
10
|
}
|
|
11
11
|
connect() {
|
|
12
12
|
return new Promise((resolve, reject) => {
|
|
13
|
-
this.#socketRef = (0, socket_io_client_1.io)(
|
|
13
|
+
this.#socketRef = (0, socket_io_client_1.io)(constants_js_1.APP_POSE_DETECTION_WEBSOCKET_URL, {
|
|
14
14
|
auth: {
|
|
15
15
|
token: this.#accessKey,
|
|
16
16
|
},
|
package/dist/tryOn.js
CHANGED
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const axios_1 = __importDefault(require("axios"));
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const constants_js_1 = require("./constants.js");
|
|
8
|
+
const utils_js_1 = require("./utils.js");
|
|
9
9
|
class TryOn {
|
|
10
10
|
#tryOnSocketRef = null;
|
|
11
11
|
#timerWaitingRef = null;
|
|
@@ -33,7 +33,7 @@ class TryOn {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
#getSignedUrl(payload) {
|
|
36
|
-
return axios_1.default.post(`${
|
|
36
|
+
return axios_1.default.post(`${constants_js_1.APP_AUTH_BASE_URL}${constants_js_1.API_ENDPOINTS.TRY_ON_IMAGE_UPLOAD}`, payload, {
|
|
37
37
|
headers: {
|
|
38
38
|
"Content-Type": "application/json",
|
|
39
39
|
"X-Api-Key": this.#accessKey,
|
|
@@ -48,18 +48,18 @@ class TryOn {
|
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
getUploadedFiles(userId) {
|
|
51
|
-
if ((0,
|
|
52
|
-
throw new Error(
|
|
51
|
+
if ((0, utils_js_1.checkParameters)(userId) === false) {
|
|
52
|
+
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
53
53
|
}
|
|
54
|
-
return axios_1.default.post(`${
|
|
54
|
+
return axios_1.default.post(`${constants_js_1.APP_AUTH_BASE_URL}${constants_js_1.API_ENDPOINTS.TRY_ON_IMAGE_DOWNLOAD}?userId=${userId}`, null, {
|
|
55
55
|
headers: { "X-Api-Key": this.#accessKey },
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
58
|
deleteImage({ userId, fileName }) {
|
|
59
|
-
if ((0,
|
|
60
|
-
throw new Error(
|
|
59
|
+
if ((0, utils_js_1.checkParameters)(userId, fileName) === false) {
|
|
60
|
+
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
61
61
|
}
|
|
62
|
-
return axios_1.default.delete(`${
|
|
62
|
+
return axios_1.default.delete(`${constants_js_1.APP_AUTH_BASE_URL}${constants_js_1.API_ENDPOINTS.TRY_ON_IMAGE_URLS}?userId=${userId}&file=${fileName}`, {
|
|
63
63
|
headers: { "X-Api-Key": this.#accessKey },
|
|
64
64
|
});
|
|
65
65
|
}
|
|
@@ -76,11 +76,11 @@ class TryOn {
|
|
|
76
76
|
}, 120000);
|
|
77
77
|
};
|
|
78
78
|
handleTryOnWebSocket = ({ shopDomain, userId, productName, onError, onSuccess, onClose, onOpen }) => {
|
|
79
|
-
if ((0,
|
|
80
|
-
throw new Error(
|
|
79
|
+
if ((0, utils_js_1.checkParameters)(shopDomain, userId, productName) === false) {
|
|
80
|
+
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
81
81
|
}
|
|
82
82
|
this.#disconnectSocket();
|
|
83
|
-
const url = `${
|
|
83
|
+
const url = `${constants_js_1.APP_AUTH_WEBSOCKET_URL}${constants_js_1.API_ENDPOINTS.TRY_ON}/?store_url=${shopDomain}&product_name=${productName}&scan_id=${userId}`;
|
|
84
84
|
this.#tryOnSocketRef = new WebSocket(url);
|
|
85
85
|
this.#tryOnSocketRef.onopen = async () => {
|
|
86
86
|
onOpen?.();
|
|
@@ -115,11 +115,11 @@ class TryOn {
|
|
|
115
115
|
};
|
|
116
116
|
};
|
|
117
117
|
handleForLatestImage = async ({ userId, shopDomain, productName, onError }) => {
|
|
118
|
-
if ((0,
|
|
119
|
-
throw new Error(
|
|
118
|
+
if ((0, utils_js_1.checkParameters)(shopDomain, userId, productName) === false) {
|
|
119
|
+
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
120
120
|
}
|
|
121
121
|
try {
|
|
122
|
-
const url = `${
|
|
122
|
+
const url = `${constants_js_1.APP_AUTH_BASE_URL}${constants_js_1.API_ENDPOINTS.TRY_ON}/?scan_id=${userId}&store_url=${shopDomain}&product_name=${productName}`;
|
|
123
123
|
const res = await axios_1.default.post(url, null, {
|
|
124
124
|
headers: { "X-Api-Key": this.#accessKey },
|
|
125
125
|
});
|
|
@@ -147,10 +147,10 @@ class TryOn {
|
|
|
147
147
|
}
|
|
148
148
|
};
|
|
149
149
|
getTryOnResult = ({ userId, shopDomain, productName }) => {
|
|
150
|
-
if ((0,
|
|
151
|
-
throw new Error(
|
|
150
|
+
if ((0, utils_js_1.checkParameters)(shopDomain, userId, productName) === false) {
|
|
151
|
+
throw new Error(constants_js_1.REQUIRED_MESSAGE);
|
|
152
152
|
}
|
|
153
|
-
const url = `${
|
|
153
|
+
const url = `${constants_js_1.APP_AUTH_BASE_URL}${constants_js_1.API_ENDPOINTS.TRY_ON_RESULT_IMAGE_DOWNLOAD}?scan_id=${userId}&store_url=${shopDomain}&product_name=${productName}`;
|
|
154
154
|
return axios_1.default.post(url, null, {
|
|
155
155
|
headers: { "X-Api-Key": this.#accessKey },
|
|
156
156
|
});
|
package/dist/utils.d.ts
CHANGED
package/dist/utils.js
CHANGED
|
@@ -5,9 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.checkMetaDataValue = exports.checkParameters = exports.fetchData = void 0;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const
|
|
8
|
+
const constants_js_1 = require("./constants.js");
|
|
9
9
|
async function fetchData(options) {
|
|
10
|
-
const { path, body, queryParams, baseUrl =
|
|
10
|
+
const { path, body, queryParams, baseUrl = constants_js_1.APP_AUTH_BASE_URL, apiKey = "", headers = { "X-Api-Key": apiKey, "Content-Type": "application/json" }, } = options;
|
|
11
11
|
const apiUrl = `${baseUrl}${path}${queryParams ? `?${new URLSearchParams(queryParams)}` : ""}`;
|
|
12
12
|
try {
|
|
13
13
|
const res = await axios_1.default.post(apiUrl, body, { headers });
|
|
@@ -33,7 +33,7 @@ function checkParameters(...args) {
|
|
|
33
33
|
}
|
|
34
34
|
exports.checkParameters = checkParameters;
|
|
35
35
|
function checkMetaDataValue(arr) {
|
|
36
|
-
for (const key of
|
|
36
|
+
for (const key of constants_js_1.requiredMetaData) {
|
|
37
37
|
let hasRequiredKey = false;
|
|
38
38
|
for (const obj of arr) {
|
|
39
39
|
if (obj.hasOwnProperty(key) && obj[key] !== undefined && obj[key] !== null && obj[key] !== "" && typeof obj[key] !== "number") {
|
package/package.json
CHANGED
|
@@ -1,57 +1,58 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@swan-admin/swan-ai-measurements",
|
|
3
|
-
"version": "1.0.
|
|
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.
|
|
18
|
-
"@uppy/core": "^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
|
-
},
|
|
25
|
-
"scripts": {
|
|
26
|
-
"start": "nodemon dist/index.js",
|
|
27
|
-
"build": "tsc && tsc --project tsconfig.esm.json",
|
|
28
|
-
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
29
|
-
"start:dev": "nodemon src/index.ts",
|
|
30
|
-
"start:debug": "nodemon --inspect-brk src/index.ts",
|
|
31
|
-
"start:prod": "node dist/index.js",
|
|
32
|
-
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
|
33
|
-
"test": "jest",
|
|
34
|
-
"test:watch": "jest --watch",
|
|
35
|
-
"test:cov": "jest --coverage",
|
|
36
|
-
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
|
37
|
-
"test:e2e": "jest --config ./test/jest-e2e.json"
|
|
38
|
-
},
|
|
39
|
-
"repository": {
|
|
40
|
-
"type": "git",
|
|
41
|
-
"url": "https://github.com/paras-swan/swan-ai-measurements.git"
|
|
42
|
-
},
|
|
43
|
-
"keywords": [
|
|
44
|
-
"swan",
|
|
45
|
-
"ai",
|
|
46
|
-
"fitview"
|
|
47
|
-
],
|
|
48
|
-
"author": "paras",
|
|
49
|
-
"license": "ISC",
|
|
50
|
-
"bugs": {
|
|
51
|
-
"url": "https://github.com/paras-swan/swan-ai-measurements/issues"
|
|
52
|
-
},
|
|
53
|
-
"homepage": "https://github.com/paras-swan/swan-ai-measurements#readme",
|
|
54
|
-
"devDependencies": {
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@swan-admin/swan-ai-measurements",
|
|
3
|
+
"version": "1.0.70",
|
|
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
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"start": "nodemon dist/index.js",
|
|
27
|
+
"build": "tsc && tsc --project tsconfig.esm.json",
|
|
28
|
+
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
29
|
+
"start:dev": "nodemon src/index.ts",
|
|
30
|
+
"start:debug": "nodemon --inspect-brk src/index.ts",
|
|
31
|
+
"start:prod": "node dist/index.js",
|
|
32
|
+
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
|
33
|
+
"test": "jest",
|
|
34
|
+
"test:watch": "jest --watch",
|
|
35
|
+
"test:cov": "jest --coverage",
|
|
36
|
+
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
|
37
|
+
"test:e2e": "jest --config ./test/jest-e2e.json"
|
|
38
|
+
},
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "https://github.com/paras-swan/swan-ai-measurements.git"
|
|
42
|
+
},
|
|
43
|
+
"keywords": [
|
|
44
|
+
"swan",
|
|
45
|
+
"ai",
|
|
46
|
+
"fitview"
|
|
47
|
+
],
|
|
48
|
+
"author": "paras",
|
|
49
|
+
"license": "ISC",
|
|
50
|
+
"bugs": {
|
|
51
|
+
"url": "https://github.com/paras-swan/swan-ai-measurements/issues"
|
|
52
|
+
},
|
|
53
|
+
"homepage": "https://github.com/paras-swan/swan-ai-measurements#readme",
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"fix-esm": "^1.0.1",
|
|
56
|
+
"nodemon": "^3.1.0"
|
|
57
|
+
}
|
|
58
|
+
}
|
package/src/auth.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import axios, { AxiosResponse } from "axios";
|
|
2
|
-
import { API_ENDPOINTS, APP_AUTH_BASE_URL, APP_AUTH_WEBSOCKET_URL, APP_BASE_URL, REQUIRED_MESSAGE } from "./constants";
|
|
3
|
-
import { checkParameters } from "./utils";
|
|
2
|
+
import { API_ENDPOINTS, APP_AUTH_BASE_URL, APP_AUTH_WEBSOCKET_URL, APP_BASE_URL, REQUIRED_MESSAGE } from "./constants.js";
|
|
3
|
+
import { checkParameters } from "./utils.js";
|
|
4
4
|
|
|
5
5
|
interface RegisterUserParams {
|
|
6
6
|
email: string;
|
package/src/custom.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import axios, { AxiosResponse } from "axios";
|
|
2
|
-
import { API_ENDPOINTS, APP_AUTH_BASE_URL, REQUIRED_MESSAGE } from "./constants";
|
|
3
|
-
import { checkParameters } from "./utils";
|
|
2
|
+
import { API_ENDPOINTS, APP_AUTH_BASE_URL, REQUIRED_MESSAGE } from "./constants.js";
|
|
3
|
+
import { checkParameters } from "./utils.js";
|
|
4
4
|
|
|
5
5
|
class Custom {
|
|
6
6
|
#accessKey: string;
|
package/src/fileUpload.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { REQUIRED_MESSAGE, REQUIRED_MESSAGE_FOR_META_DATA, UPPY_FILE_UPLOAD_ENDPOINT } from "./constants";
|
|
2
|
-
import { checkMetaDataValue, checkParameters, fetchData } from "./utils";
|
|
3
|
-
|
|
1
|
+
import { REQUIRED_MESSAGE, REQUIRED_MESSAGE_FOR_META_DATA, UPPY_FILE_UPLOAD_ENDPOINT } from "./constants.js";
|
|
2
|
+
import { checkMetaDataValue, checkParameters, fetchData } from "./utils.js";
|
|
3
|
+
const Uppy = require("fix-esm").require("@uppy/core");
|
|
4
|
+
const AwsS3Multipart = require("fix-esm").require("@uppy/aws-s3-multipart");
|
|
4
5
|
interface ObjMetaData {
|
|
5
6
|
gender: string;
|
|
6
7
|
scan_id: string;
|
|
@@ -22,25 +23,11 @@ interface UploadOptions {
|
|
|
22
23
|
export default class FileUpload {
|
|
23
24
|
#uppyIns: any;
|
|
24
25
|
#accessKey: string;
|
|
25
|
-
#Uppy: any;
|
|
26
|
-
#AwsS3Multipart: any;
|
|
27
26
|
|
|
28
27
|
constructor(accessKey: string) {
|
|
29
28
|
this.#accessKey = accessKey;
|
|
30
29
|
}
|
|
31
30
|
|
|
32
|
-
async initializeModules() {
|
|
33
|
-
if (!this.#Uppy || !this.#AwsS3Multipart) {
|
|
34
|
-
// const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
|
|
35
|
-
const Uppy = () => import("@uppy/core").then(({ default: Uppy }) => Uppy);
|
|
36
|
-
const AwsS3Multipart = () => import("@uppy/aws-s3-multipart").then(({ default: AwsS3Multipart }) => AwsS3Multipart);
|
|
37
|
-
// const { default: Uppy } = await import("@uppy/core");
|
|
38
|
-
// const { default: AwsS3Multipart } = await import("@uppy/aws-s3-multipart");
|
|
39
|
-
this.#Uppy = Uppy;
|
|
40
|
-
this.#AwsS3Multipart = AwsS3Multipart;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
31
|
async uploadFile({ file, arrayMetaData, scanId }: UploadOptions) {
|
|
45
32
|
if (!checkParameters(file, arrayMetaData, scanId)) {
|
|
46
33
|
throw new Error(REQUIRED_MESSAGE);
|
|
@@ -48,14 +35,13 @@ export default class FileUpload {
|
|
|
48
35
|
if (!checkMetaDataValue(arrayMetaData)) {
|
|
49
36
|
throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
|
|
50
37
|
}
|
|
51
|
-
await this.initializeModules();
|
|
52
38
|
|
|
53
39
|
return new Promise((resolve, reject) => {
|
|
54
40
|
if (this.#uppyIns) {
|
|
55
41
|
this.#uppyIns.close();
|
|
56
42
|
}
|
|
57
|
-
this.#uppyIns = new
|
|
58
|
-
this.#uppyIns.use(
|
|
43
|
+
this.#uppyIns = new Uppy.default({ autoProceed: true });
|
|
44
|
+
this.#uppyIns.use(AwsS3Multipart.default, {
|
|
59
45
|
limit: 10,
|
|
60
46
|
retryDelays: [0, 1000, 3000, 5000],
|
|
61
47
|
getChunkSize: () => 5 * 1024 * 1024,
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import Auth from "./auth";
|
|
2
|
-
import Custom from "./custom";
|
|
3
|
-
import FileUpload from "./fileUpload";
|
|
4
|
-
import Measurement from "./measurement";
|
|
5
|
-
import PoseDetection from "./poseDetection";
|
|
6
|
-
import TryOn from "./tryOn";
|
|
1
|
+
import Auth from "./auth.js";
|
|
2
|
+
import Custom from "./custom.js";
|
|
3
|
+
import FileUpload from "./fileUpload.js";
|
|
4
|
+
import Measurement from "./measurement.js";
|
|
5
|
+
import PoseDetection from "./poseDetection.js";
|
|
6
|
+
import TryOn from "./tryOn.js";
|
|
7
7
|
|
|
8
8
|
class Swan {
|
|
9
9
|
#accessKey: string;
|
package/src/measurement.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import axios, { AxiosResponse } from "axios";
|
|
2
|
-
import { API_ENDPOINTS, APP_AUTH_BASE_URL, APP_RECOMMENDATION_WEBSOCKET_URL, APP_TRY_ON_WEBSOCKET_URL, REQUIRED_MESSAGE } from "./constants";
|
|
3
|
-
import { checkParameters } from "./utils";
|
|
2
|
+
import { API_ENDPOINTS, APP_AUTH_BASE_URL, APP_RECOMMENDATION_WEBSOCKET_URL, APP_TRY_ON_WEBSOCKET_URL, REQUIRED_MESSAGE } from "./constants.js";
|
|
3
|
+
import { checkParameters } from "./utils.js";
|
|
4
4
|
|
|
5
5
|
interface TryOnSocketOptions {
|
|
6
6
|
shopDomain: string;
|
package/src/poseDetection.ts
CHANGED
package/src/tryOn.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import axios, { AxiosResponse } from "axios";
|
|
2
|
-
import { API_ENDPOINTS, APP_AUTH_BASE_URL, APP_AUTH_WEBSOCKET_URL, REQUIRED_MESSAGE } from "./constants";
|
|
3
|
-
import { checkParameters } from "./utils";
|
|
2
|
+
import { API_ENDPOINTS, APP_AUTH_BASE_URL, APP_AUTH_WEBSOCKET_URL, REQUIRED_MESSAGE } from "./constants.js";
|
|
3
|
+
import { checkParameters } from "./utils.js";
|
|
4
4
|
|
|
5
5
|
interface UploadFileParams {
|
|
6
6
|
files: File[];
|
package/src/utils.ts
CHANGED