@swan-admin/swan-ai-measurements 1.0.61 → 1.0.63
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.d.ts +34 -0
- package/dist/auth.js +88 -0
- package/dist/constants.d.ts +31 -0
- package/dist/constants.js +43 -0
- package/dist/custom.d.ts +8 -0
- package/dist/custom.js +43 -0
- package/dist/fileUpload.d.ts +22 -0
- package/dist/fileUpload.js +147 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +37 -0
- package/dist/measurement.d.ts +26 -0
- package/dist/measurement.js +175 -0
- package/dist/poseDetection.d.ts +15 -0
- package/dist/poseDetection.js +72 -0
- package/dist/tryOn.d.ts +40 -0
- package/dist/tryOn.js +185 -0
- package/dist/utils.d.ts +12 -0
- package/dist/utils.js +70 -0
- package/package.json +25 -26
- package/src/auth.ts +114 -0
- package/src/constants.ts +63 -0
- package/src/custom.ts +30 -0
- package/{fileUpload.js → src/fileUpload.ts} +40 -64
- package/src/index.ts +29 -0
- package/src/measurement.ts +202 -0
- package/src/poseDetection.ts +72 -0
- package/src/tryOn.ts +203 -0
- package/src/utils.ts +68 -0
- package/tsconfig.json +16 -0
- package/auth.js +0 -151
- package/constants.js +0 -42
- package/custom.js +0 -54
- package/index.js +0 -64
- package/measurement.js +0 -211
- package/poseDetection.js +0 -80
- package/tryOn.js +0 -252
- package/utils.js +0 -57
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AxiosResponse } from "axios";
|
|
2
|
+
interface RegisterUserParams {
|
|
3
|
+
email: string;
|
|
4
|
+
appVerifyUrl: string;
|
|
5
|
+
gender?: string;
|
|
6
|
+
height?: number;
|
|
7
|
+
username?: string;
|
|
8
|
+
}
|
|
9
|
+
interface AddUserParams {
|
|
10
|
+
scanId: string;
|
|
11
|
+
email: string;
|
|
12
|
+
name?: string;
|
|
13
|
+
height: number;
|
|
14
|
+
gender: string;
|
|
15
|
+
offsetMarketingConsent?: boolean;
|
|
16
|
+
}
|
|
17
|
+
interface AuthSocketParams {
|
|
18
|
+
email: string;
|
|
19
|
+
scanId: string;
|
|
20
|
+
onError?: (event: Event) => void;
|
|
21
|
+
onSuccess?: (data: any) => void;
|
|
22
|
+
onClose?: () => void;
|
|
23
|
+
onOpen?: () => void;
|
|
24
|
+
}
|
|
25
|
+
export default class Auth {
|
|
26
|
+
#private;
|
|
27
|
+
constructor(accessKey: string);
|
|
28
|
+
registerUser({ email, appVerifyUrl, gender, height, username }: RegisterUserParams): Promise<AxiosResponse>;
|
|
29
|
+
verifyToken(token: string): Promise<AxiosResponse>;
|
|
30
|
+
addUser({ scanId, email, name, height, gender, offsetMarketingConsent }: AddUserParams): Promise<AxiosResponse>;
|
|
31
|
+
getUserDetail(email: string): Promise<AxiosResponse>;
|
|
32
|
+
handleAuthSocket({ email, scanId, onError, onSuccess, onClose, onOpen }: AuthSocketParams): void;
|
|
33
|
+
}
|
|
34
|
+
export {};
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
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");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
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");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
var _Auth_socketRef, _Auth_accessKey;
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const axios_1 = __importDefault(require("axios"));
|
|
19
|
+
const constants_1 = require("./constants");
|
|
20
|
+
const utils_1 = require("./utils");
|
|
21
|
+
class Auth {
|
|
22
|
+
constructor(accessKey) {
|
|
23
|
+
_Auth_socketRef.set(this, void 0);
|
|
24
|
+
_Auth_accessKey.set(this, void 0);
|
|
25
|
+
__classPrivateFieldSet(this, _Auth_accessKey, accessKey, "f");
|
|
26
|
+
}
|
|
27
|
+
registerUser({ email, appVerifyUrl, gender, height, username }) {
|
|
28
|
+
if (!(0, utils_1.checkParameters)(email, appVerifyUrl)) {
|
|
29
|
+
throw new Error(constants_1.REQUIRED_MESSAGE);
|
|
30
|
+
}
|
|
31
|
+
let body = { username, email, appVerifyUrl };
|
|
32
|
+
if (gender && height) {
|
|
33
|
+
body = Object.assign(Object.assign({}, body), { attributes: { gender, height } });
|
|
34
|
+
}
|
|
35
|
+
return axios_1.default.post(`${constants_1.APP_AUTH_BASE_URL}${constants_1.API_ENDPOINTS.REGISTER_USER}`, body, {
|
|
36
|
+
headers: { "X-Api-Key": __classPrivateFieldGet(this, _Auth_accessKey, "f") },
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
verifyToken(token) {
|
|
40
|
+
if (!(0, utils_1.checkParameters)(token)) {
|
|
41
|
+
throw new Error(constants_1.REQUIRED_MESSAGE);
|
|
42
|
+
}
|
|
43
|
+
return axios_1.default.post(`${constants_1.APP_AUTH_BASE_URL}${constants_1.API_ENDPOINTS.VERIFY_USER}`, null, {
|
|
44
|
+
params: { token },
|
|
45
|
+
headers: { "X-Api-Key": __classPrivateFieldGet(this, _Auth_accessKey, "f") },
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
addUser({ scanId, email, name, height, gender, offsetMarketingConsent }) {
|
|
49
|
+
if (!(0, utils_1.checkParameters)(scanId, email, height, gender)) {
|
|
50
|
+
throw new Error(constants_1.REQUIRED_MESSAGE);
|
|
51
|
+
}
|
|
52
|
+
return axios_1.default.post(`${constants_1.APP_AUTH_BASE_URL}${constants_1.API_ENDPOINTS.ADD_USER}`, { scan_id: scanId, email, name, offsetMarketingConsent, attributes: JSON.stringify({ height, gender }) }, { headers: { "X-Api-Key": __classPrivateFieldGet(this, _Auth_accessKey, "f") } });
|
|
53
|
+
}
|
|
54
|
+
getUserDetail(email) {
|
|
55
|
+
if (!(0, utils_1.checkParameters)(email)) {
|
|
56
|
+
throw new Error(constants_1.REQUIRED_MESSAGE);
|
|
57
|
+
}
|
|
58
|
+
return axios_1.default.get(`${constants_1.APP_BASE_URL}${constants_1.API_ENDPOINTS.GET_USER_DETAIL}/${email}`, {
|
|
59
|
+
headers: { "X-Api-Key": __classPrivateFieldGet(this, _Auth_accessKey, "f") },
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
handleAuthSocket({ email, scanId, onError, onSuccess, onClose, onOpen }) {
|
|
63
|
+
if (!(0, utils_1.checkParameters)(email, scanId)) {
|
|
64
|
+
throw new Error(constants_1.REQUIRED_MESSAGE);
|
|
65
|
+
}
|
|
66
|
+
if (__classPrivateFieldGet(this, _Auth_socketRef, "f"))
|
|
67
|
+
__classPrivateFieldGet(this, _Auth_socketRef, "f").close();
|
|
68
|
+
__classPrivateFieldSet(this, _Auth_socketRef, new WebSocket(`${constants_1.APP_AUTH_WEBSOCKET_URL}${constants_1.API_ENDPOINTS.AUTH}`), "f");
|
|
69
|
+
const detailObj = { email, scanId };
|
|
70
|
+
__classPrivateFieldGet(this, _Auth_socketRef, "f").onopen = () => {
|
|
71
|
+
var _a;
|
|
72
|
+
(_a = __classPrivateFieldGet(this, _Auth_socketRef, "f")) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify(detailObj));
|
|
73
|
+
onOpen === null || onOpen === void 0 ? void 0 : onOpen();
|
|
74
|
+
};
|
|
75
|
+
__classPrivateFieldGet(this, _Auth_socketRef, "f").onmessage = (event) => {
|
|
76
|
+
const data = JSON.parse(event.data);
|
|
77
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
|
|
78
|
+
};
|
|
79
|
+
__classPrivateFieldGet(this, _Auth_socketRef, "f").onclose = () => {
|
|
80
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
81
|
+
};
|
|
82
|
+
__classPrivateFieldGet(this, _Auth_socketRef, "f").onerror = (event) => {
|
|
83
|
+
onError === null || onError === void 0 ? void 0 : onError(event);
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
_Auth_socketRef = new WeakMap(), _Auth_accessKey = new WeakMap();
|
|
88
|
+
exports.default = Auth;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare const APP_BASE_URL: string;
|
|
2
|
+
export declare const APP_AUTH_BASE_URL: string;
|
|
3
|
+
export declare const APP_AUTH_WEBSOCKET_URL: string;
|
|
4
|
+
export declare const APP_TRY_ON_WEBSOCKET_URL: string;
|
|
5
|
+
export declare const APP_RECOMMENDATION_WEBSOCKET_URL: string;
|
|
6
|
+
export declare const APP_POSE_DETECTION_WEBSOCKET_URL: string;
|
|
7
|
+
export declare const UPPY_FILE_UPLOAD_ENDPOINT: {
|
|
8
|
+
UPLOAD_START: string;
|
|
9
|
+
UPLOAD_COMPLETE: string;
|
|
10
|
+
UPLOAD_SIGN_PART: string;
|
|
11
|
+
UPLOAD_ABORT: string;
|
|
12
|
+
};
|
|
13
|
+
export declare const API_ENDPOINTS: {
|
|
14
|
+
[key: string]: string;
|
|
15
|
+
};
|
|
16
|
+
export interface ObjMetaData {
|
|
17
|
+
gender: string;
|
|
18
|
+
scan_id: string;
|
|
19
|
+
email: string;
|
|
20
|
+
focal_length: string;
|
|
21
|
+
height: string;
|
|
22
|
+
customer_store_url: string;
|
|
23
|
+
clothes_fit: string;
|
|
24
|
+
scan_type: string;
|
|
25
|
+
callback_url: string;
|
|
26
|
+
}
|
|
27
|
+
type RequiredMetaDataKeys = keyof ObjMetaData;
|
|
28
|
+
export declare const requiredMetaData: RequiredMetaDataKeys[];
|
|
29
|
+
export declare const REQUIRED_MESSAGE: string;
|
|
30
|
+
export declare const REQUIRED_MESSAGE_FOR_META_DATA: string;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.REQUIRED_MESSAGE_FOR_META_DATA = exports.REQUIRED_MESSAGE = exports.requiredMetaData = exports.API_ENDPOINTS = exports.UPPY_FILE_UPLOAD_ENDPOINT = exports.APP_POSE_DETECTION_WEBSOCKET_URL = exports.APP_RECOMMENDATION_WEBSOCKET_URL = exports.APP_TRY_ON_WEBSOCKET_URL = exports.APP_AUTH_WEBSOCKET_URL = exports.APP_AUTH_BASE_URL = exports.APP_BASE_URL = void 0;
|
|
4
|
+
exports.APP_BASE_URL = "https://fitview-server-staging.ft2a64raup4pg.us-east-1.cs.amazonlightsail.com";
|
|
5
|
+
exports.APP_AUTH_BASE_URL = "https://staging.api.getswan.co";
|
|
6
|
+
exports.APP_AUTH_WEBSOCKET_URL = "wss://staging.wsnotify.api.getswan.co";
|
|
7
|
+
exports.APP_TRY_ON_WEBSOCKET_URL = "wss://bucbzczxjk.execute-api.ap-south-1.amazonaws.com";
|
|
8
|
+
exports.APP_RECOMMENDATION_WEBSOCKET_URL = "wss://staging.wsnotify.api.getswan.co/scanning";
|
|
9
|
+
exports.APP_POSE_DETECTION_WEBSOCKET_URL = "https://posedetect-service-staging.ft2a64raup4pg.us-east-1.cs.amazonlightsail.com";
|
|
10
|
+
exports.UPPY_FILE_UPLOAD_ENDPOINT = {
|
|
11
|
+
UPLOAD_START: "/upload/start",
|
|
12
|
+
UPLOAD_COMPLETE: "/upload/complete",
|
|
13
|
+
UPLOAD_SIGN_PART: "/upload/signpart",
|
|
14
|
+
UPLOAD_ABORT: "/upload/abort",
|
|
15
|
+
};
|
|
16
|
+
exports.API_ENDPOINTS = {
|
|
17
|
+
GET_USER_DETAIL: "/api/user",
|
|
18
|
+
REGISTER_USER: "/auth/register",
|
|
19
|
+
VERIFY_USER: "/auth/verify",
|
|
20
|
+
ADD_USER: "/user",
|
|
21
|
+
CUSTOM_CUSTOMER: "/customers/custom",
|
|
22
|
+
MODEL: "/model",
|
|
23
|
+
TRY_ON_SCAN: "/tryon/scan",
|
|
24
|
+
TRY_ON_IMAGE_UPLOAD: "/tryon/user-image-urls/upload",
|
|
25
|
+
TRY_ON_IMAGE_DOWNLOAD: "/tryon/user-image-urls/download",
|
|
26
|
+
TRY_ON_IMAGE_URLS: "/tryon/user-image-urls",
|
|
27
|
+
TRY_ON_RESULT_IMAGE_DOWNLOAD: "/tryon/result-image-urls/download",
|
|
28
|
+
TRY_ON: "/tryon",
|
|
29
|
+
AUTH: "/auth",
|
|
30
|
+
};
|
|
31
|
+
exports.requiredMetaData = [
|
|
32
|
+
"gender",
|
|
33
|
+
"scan_id",
|
|
34
|
+
"email",
|
|
35
|
+
"focal_length",
|
|
36
|
+
"height",
|
|
37
|
+
"customer_store_url",
|
|
38
|
+
"scan_type",
|
|
39
|
+
"callback_url",
|
|
40
|
+
"clothes_fit",
|
|
41
|
+
];
|
|
42
|
+
exports.REQUIRED_MESSAGE = "Please verify required parameters";
|
|
43
|
+
exports.REQUIRED_MESSAGE_FOR_META_DATA = "Please verify required parameters in meta data";
|
package/dist/custom.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AxiosResponse } from "axios";
|
|
2
|
+
declare class Custom {
|
|
3
|
+
#private;
|
|
4
|
+
constructor(accessKey: string);
|
|
5
|
+
getCustomCustomerConfig: (store_url: string) => Promise<AxiosResponse<any>>;
|
|
6
|
+
getModelUrl: (id: string) => Promise<AxiosResponse<any>>;
|
|
7
|
+
}
|
|
8
|
+
export default Custom;
|
package/dist/custom.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
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");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
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");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
var _Custom_accessKey;
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const axios_1 = __importDefault(require("axios"));
|
|
19
|
+
const constants_1 = require("./constants");
|
|
20
|
+
const utils_1 = require("./utils");
|
|
21
|
+
class Custom {
|
|
22
|
+
constructor(accessKey) {
|
|
23
|
+
_Custom_accessKey.set(this, void 0);
|
|
24
|
+
this.getCustomCustomerConfig = (store_url) => {
|
|
25
|
+
if ((0, utils_1.checkParameters)(store_url) === false) {
|
|
26
|
+
throw new Error(constants_1.REQUIRED_MESSAGE);
|
|
27
|
+
}
|
|
28
|
+
return axios_1.default.get(`${constants_1.APP_AUTH_BASE_URL}${constants_1.API_ENDPOINTS.CUSTOM_CUSTOMER}`, {
|
|
29
|
+
params: { store_url },
|
|
30
|
+
headers: { "X-Api-Key": __classPrivateFieldGet(this, _Custom_accessKey, "f") },
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
this.getModelUrl = (id) => {
|
|
34
|
+
if ((0, utils_1.checkParameters)(id) === false) {
|
|
35
|
+
throw new Error(constants_1.REQUIRED_MESSAGE);
|
|
36
|
+
}
|
|
37
|
+
return axios_1.default.get(`${constants_1.APP_AUTH_BASE_URL}${constants_1.API_ENDPOINTS.MODEL}/${id}`, { headers: { "X-Api-Key": __classPrivateFieldGet(this, _Custom_accessKey, "f") } });
|
|
38
|
+
};
|
|
39
|
+
__classPrivateFieldSet(this, _Custom_accessKey, accessKey, "f");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
_Custom_accessKey = new WeakMap();
|
|
43
|
+
exports.default = Custom;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
interface ObjMetaData {
|
|
2
|
+
gender: string;
|
|
3
|
+
scan_id: string;
|
|
4
|
+
email: string;
|
|
5
|
+
focal_length: string;
|
|
6
|
+
height: string;
|
|
7
|
+
customer_store_url: string;
|
|
8
|
+
clothes_fit: string;
|
|
9
|
+
scan_type: string;
|
|
10
|
+
callback_url: string;
|
|
11
|
+
}
|
|
12
|
+
interface UploadOptions {
|
|
13
|
+
file: any;
|
|
14
|
+
arrayMetaData: ObjMetaData[];
|
|
15
|
+
scanId: string;
|
|
16
|
+
}
|
|
17
|
+
export default class FileUpload {
|
|
18
|
+
#private;
|
|
19
|
+
constructor(accessKey: string);
|
|
20
|
+
uploadFile({ file, arrayMetaData, scanId }: UploadOptions): Promise<unknown>;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,147 @@
|
|
|
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
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
35
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
36
|
+
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");
|
|
37
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
38
|
+
};
|
|
39
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
40
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
41
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
42
|
+
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");
|
|
43
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
44
|
+
};
|
|
45
|
+
var _FileUpload_instances, _FileUpload_uppyIns, _FileUpload_accessKey, _FileUpload_Uppy, _FileUpload_AwsS3Multipart, _FileUpload_initializeModules;
|
|
46
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
|
+
const constants_1 = require("./constants");
|
|
48
|
+
const utils_1 = require("./utils");
|
|
49
|
+
class FileUpload {
|
|
50
|
+
constructor(accessKey) {
|
|
51
|
+
_FileUpload_instances.add(this);
|
|
52
|
+
_FileUpload_uppyIns.set(this, void 0);
|
|
53
|
+
_FileUpload_accessKey.set(this, void 0);
|
|
54
|
+
_FileUpload_Uppy.set(this, void 0);
|
|
55
|
+
_FileUpload_AwsS3Multipart.set(this, void 0);
|
|
56
|
+
__classPrivateFieldGet(this, _FileUpload_instances, "m", _FileUpload_initializeModules).call(this);
|
|
57
|
+
__classPrivateFieldSet(this, _FileUpload_accessKey, accessKey, "f");
|
|
58
|
+
}
|
|
59
|
+
uploadFile(_a) {
|
|
60
|
+
return __awaiter(this, arguments, void 0, function* ({ file, arrayMetaData, scanId }) {
|
|
61
|
+
if ((0, utils_1.checkParameters)(file, arrayMetaData, scanId) === false) {
|
|
62
|
+
throw new Error(constants_1.REQUIRED_MESSAGE);
|
|
63
|
+
}
|
|
64
|
+
if ((0, utils_1.checkMetaDataValue)(arrayMetaData) === false) {
|
|
65
|
+
throw new Error(constants_1.REQUIRED_MESSAGE_FOR_META_DATA);
|
|
66
|
+
}
|
|
67
|
+
if (!__classPrivateFieldGet(this, _FileUpload_Uppy, "f") || !__classPrivateFieldGet(this, _FileUpload_AwsS3Multipart, "f")) {
|
|
68
|
+
yield __classPrivateFieldGet(this, _FileUpload_instances, "m", _FileUpload_initializeModules).call(this);
|
|
69
|
+
}
|
|
70
|
+
return new Promise((resolve, reject) => {
|
|
71
|
+
if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
|
|
72
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
|
|
73
|
+
}
|
|
74
|
+
__classPrivateFieldSet(this, _FileUpload_uppyIns, new (__classPrivateFieldGet(this, _FileUpload_Uppy, "f"))({ autoProceed: true }), "f");
|
|
75
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").use(__classPrivateFieldGet(this, _FileUpload_AwsS3Multipart, "f"), {
|
|
76
|
+
limit: 10,
|
|
77
|
+
retryDelays: [0, 1000, 3000, 5000],
|
|
78
|
+
getChunkSize: () => 5 * 1024 * 1024,
|
|
79
|
+
createMultipartUpload: (file) => {
|
|
80
|
+
const objectKey = `${scanId}.${file.extension}`;
|
|
81
|
+
return (0, utils_1.fetchData)({
|
|
82
|
+
path: constants_1.UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_START,
|
|
83
|
+
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
84
|
+
body: {
|
|
85
|
+
objectKey,
|
|
86
|
+
contentType: file.type,
|
|
87
|
+
objectMetadata: arrayMetaData,
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
completeMultipartUpload: (file, { uploadId, key, parts }) => (0, utils_1.fetchData)({
|
|
92
|
+
path: constants_1.UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
|
|
93
|
+
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
94
|
+
body: {
|
|
95
|
+
uploadId,
|
|
96
|
+
objectKey: key,
|
|
97
|
+
parts,
|
|
98
|
+
originalFileName: file.name,
|
|
99
|
+
},
|
|
100
|
+
}),
|
|
101
|
+
signPart: (file, partData) => (0, utils_1.fetchData)({
|
|
102
|
+
path: constants_1.UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
|
|
103
|
+
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
104
|
+
body: {
|
|
105
|
+
objectKey: partData.key,
|
|
106
|
+
uploadId: partData.uploadId,
|
|
107
|
+
partNumber: partData.partNumber,
|
|
108
|
+
},
|
|
109
|
+
}),
|
|
110
|
+
abortMultipartUpload: (file, { uploadId, key }) => (0, utils_1.fetchData)({
|
|
111
|
+
path: constants_1.UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_ABORT,
|
|
112
|
+
apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
|
|
113
|
+
body: {
|
|
114
|
+
uploadId,
|
|
115
|
+
objectKey: key,
|
|
116
|
+
originalFileName: file.name,
|
|
117
|
+
},
|
|
118
|
+
}),
|
|
119
|
+
});
|
|
120
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").addFile({
|
|
121
|
+
source: "manual",
|
|
122
|
+
name: file.name,
|
|
123
|
+
type: file.type,
|
|
124
|
+
data: file,
|
|
125
|
+
});
|
|
126
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-error", (file, error, response) => {
|
|
127
|
+
reject(error);
|
|
128
|
+
});
|
|
129
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-success", () => {
|
|
130
|
+
resolve({ message: "file uploaded successfully" });
|
|
131
|
+
});
|
|
132
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("complete", (result) => {
|
|
133
|
+
if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
|
|
134
|
+
__classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
_FileUpload_uppyIns = new WeakMap(), _FileUpload_accessKey = new WeakMap(), _FileUpload_Uppy = new WeakMap(), _FileUpload_AwsS3Multipart = new WeakMap(), _FileUpload_instances = new WeakSet(), _FileUpload_initializeModules = function _FileUpload_initializeModules() {
|
|
142
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
+
__classPrivateFieldSet(this, _FileUpload_Uppy, (yield Promise.resolve().then(() => __importStar(require("@uppy/core")))).default, "f");
|
|
144
|
+
__classPrivateFieldSet(this, _FileUpload_AwsS3Multipart, (yield Promise.resolve().then(() => __importStar(require("@uppy/aws-s3-multipart")))).default, "f");
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
exports.default = FileUpload;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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";
|
|
7
|
+
declare class Swan {
|
|
8
|
+
#private;
|
|
9
|
+
auth: Auth;
|
|
10
|
+
custom: Custom;
|
|
11
|
+
fileUpload: FileUpload;
|
|
12
|
+
measurement: Measurement;
|
|
13
|
+
poseDetection: PoseDetection;
|
|
14
|
+
tryOn: TryOn;
|
|
15
|
+
constructor(accessKey: string);
|
|
16
|
+
}
|
|
17
|
+
export default Swan;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
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");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
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");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
var _Swan_accessKey;
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const auth_1 = __importDefault(require("./auth"));
|
|
19
|
+
const custom_1 = __importDefault(require("./custom"));
|
|
20
|
+
const fileUpload_1 = __importDefault(require("./fileUpload"));
|
|
21
|
+
const measurement_1 = __importDefault(require("./measurement"));
|
|
22
|
+
const poseDetection_1 = __importDefault(require("./poseDetection"));
|
|
23
|
+
const tryOn_1 = __importDefault(require("./tryOn"));
|
|
24
|
+
class Swan {
|
|
25
|
+
constructor(accessKey) {
|
|
26
|
+
_Swan_accessKey.set(this, void 0);
|
|
27
|
+
__classPrivateFieldSet(this, _Swan_accessKey, accessKey, "f");
|
|
28
|
+
this.auth = new auth_1.default(__classPrivateFieldGet(this, _Swan_accessKey, "f"));
|
|
29
|
+
this.custom = new custom_1.default(__classPrivateFieldGet(this, _Swan_accessKey, "f"));
|
|
30
|
+
this.fileUpload = new fileUpload_1.default(__classPrivateFieldGet(this, _Swan_accessKey, "f"));
|
|
31
|
+
this.measurement = new measurement_1.default(__classPrivateFieldGet(this, _Swan_accessKey, "f"));
|
|
32
|
+
this.poseDetection = new poseDetection_1.default(__classPrivateFieldGet(this, _Swan_accessKey, "f"));
|
|
33
|
+
this.tryOn = new tryOn_1.default(__classPrivateFieldGet(this, _Swan_accessKey, "f"));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
_Swan_accessKey = new WeakMap();
|
|
37
|
+
exports.default = Swan;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AxiosResponse } from "axios";
|
|
2
|
+
interface TryOnSocketOptions {
|
|
3
|
+
shopDomain: string;
|
|
4
|
+
scanId: string;
|
|
5
|
+
productName: string;
|
|
6
|
+
onError?: (error: any) => void;
|
|
7
|
+
onSuccess?: (data: any) => void;
|
|
8
|
+
onClose?: () => void;
|
|
9
|
+
onOpen?: () => void;
|
|
10
|
+
}
|
|
11
|
+
interface MeasurementSocketOptions {
|
|
12
|
+
scanId: string;
|
|
13
|
+
onError?: (error: any) => void;
|
|
14
|
+
onSuccess?: (data: any) => void;
|
|
15
|
+
onClose?: () => void;
|
|
16
|
+
onOpen?: () => void;
|
|
17
|
+
}
|
|
18
|
+
declare class Measurement {
|
|
19
|
+
#private;
|
|
20
|
+
constructor(accessKey: string);
|
|
21
|
+
getMeasurementResult(scanId: string): Promise<AxiosResponse<any>>;
|
|
22
|
+
getTryOnMeasurements({ scanId, shopDomain, productName }: TryOnSocketOptions): Promise<AxiosResponse<any>>;
|
|
23
|
+
handleTryOnSocket(options: TryOnSocketOptions): void;
|
|
24
|
+
handleMeasurementSocket(options: MeasurementSocketOptions): void;
|
|
25
|
+
}
|
|
26
|
+
export default Measurement;
|