@swan-admin/swan-ai-measurements 1.1.6 → 1.1.7

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.
@@ -1,37 +1,37 @@
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
-
8
- See the<a href="https://www.swanvision.ai/docs">SWAN API docs</a> for Node.js.
9
-
10
-
11
- Requirements
12
- -------------------
13
- Node 20 or higher.
14
-
15
- Usage
16
- -------------------
17
-
18
- ##### Installation
19
-
20
- npm i @swan-admin/swan-ai-measurements
21
-
22
- ##### Create Customer
23
-
24
- swan.custom.createCustomer({name, store_url, location, email, emailsTier_1, emailsTier_2})
25
-
26
- ##### Upload file
27
-
28
- swan.fileUpload.uploadFile({ file, objMetaData, scanId })
29
-
30
- ##### Get measurements
31
-
32
- swan.measurement.getMeasurementResult(scanId)
33
-
34
-
35
- Support
36
- ------------------
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
+
8
+ See the<a href="https://www.swanvision.ai/docs">SWAN API docs</a> for Node.js.
9
+
10
+
11
+ Requirements
12
+ -------------------
13
+ Node 20 or higher.
14
+
15
+ Usage
16
+ -------------------
17
+
18
+ ##### Installation
19
+
20
+ npm i @swan-admin/swan-ai-measurements
21
+
22
+ ##### Create Customer
23
+
24
+ swan.custom.createCustomer({name, store_url, location, email, emailsTier_1, emailsTier_2})
25
+
26
+ ##### Upload file
27
+
28
+ swan.fileUpload.uploadFile({ file, objMetaData, scanId })
29
+
30
+ ##### Get measurements
31
+
32
+ swan.measurement.getMeasurementResult(scanId)
33
+
34
+
35
+ Support
36
+ ------------------
37
37
  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.
@@ -14,13 +14,13 @@ export declare const API_ENDPOINTS: {
14
14
  };
15
15
  export interface ObjMetaData {
16
16
  gender: string;
17
- scan_id: string;
17
+ scan_id?: string;
18
18
  email: string;
19
19
  focal_length: string;
20
20
  height: string;
21
21
  customer_store_url: string;
22
22
  clothes_fit: string;
23
- scan_type: string;
23
+ scan_type?: string;
24
24
  callback_url: string;
25
25
  }
26
26
  type RequiredMetaDataKeys = keyof ObjMetaData;
package/dist/constants.js CHANGED
@@ -2,12 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
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;
4
4
  exports.STAGING_URL = {
5
- APP_AUTH_BASE_URL: "https://staging.api.getswan.co",
5
+ APP_AUTH_BASE_URL: "https://staging.api.swanvision.ai/",
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.getswan.co",
10
+ APP_AUTH_BASE_URL: "https://api.swanvision.ai",
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
  };
@@ -39,12 +39,10 @@ exports.API_ENDPOINTS = {
39
39
  };
40
40
  exports.requiredMetaData = [
41
41
  "gender",
42
- "scan_id",
43
42
  "email",
44
43
  "focal_length",
45
44
  "height",
46
45
  "customer_store_url",
47
- "scan_type",
48
46
  "callback_url",
49
47
  "clothes_fit",
50
48
  ];
package/dist/custom.d.ts CHANGED
@@ -1,15 +1,16 @@
1
1
  import { AxiosResponse } from "axios";
2
+ interface CreateCustomer {
3
+ name: string;
4
+ storeUrl: string;
5
+ location: string;
6
+ email: string;
7
+ emailsTier_1: string;
8
+ emailsTier_2: string;
9
+ }
2
10
  declare class Custom {
3
11
  #private;
4
12
  constructor(accessKey: string, stagingUrl?: boolean);
5
- createCustomer(payload: {
6
- name: string;
7
- storeUrl: string;
8
- location: string;
9
- email: string;
10
- emailsTier_1: string;
11
- emailsTier_2: string;
12
- }): Promise<AxiosResponse<any>>;
13
+ createCustomer(payload: CreateCustomer): Promise<AxiosResponse<any>>;
13
14
  getCustomCustomerConfig: (store_url: string) => Promise<AxiosResponse<any>>;
14
15
  getModelUrl: (id: string) => Promise<AxiosResponse<any>>;
15
16
  }
@@ -14,13 +14,13 @@ export declare const API_ENDPOINTS: {
14
14
  };
15
15
  export interface ObjMetaData {
16
16
  gender: string;
17
- scan_id: string;
17
+ scan_id?: string;
18
18
  email: string;
19
19
  focal_length: string;
20
20
  height: string;
21
21
  customer_store_url: string;
22
22
  clothes_fit: string;
23
- scan_type: string;
23
+ scan_type?: string;
24
24
  callback_url: string;
25
25
  }
26
26
  type RequiredMetaDataKeys = keyof ObjMetaData;
@@ -1,10 +1,10 @@
1
1
  export const STAGING_URL = {
2
- APP_AUTH_BASE_URL: "https://staging.api.getswan.co",
2
+ APP_AUTH_BASE_URL: "https://staging.api.swanvision.ai/",
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.getswan.co",
7
+ APP_AUTH_BASE_URL: "https://api.swanvision.ai",
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
  };
@@ -36,12 +36,10 @@ export const API_ENDPOINTS = {
36
36
  };
37
37
  export const requiredMetaData = [
38
38
  "gender",
39
- "scan_id",
40
39
  "email",
41
40
  "focal_length",
42
41
  "height",
43
42
  "customer_store_url",
44
- "scan_type",
45
43
  "callback_url",
46
44
  "clothes_fit",
47
45
  ];
@@ -1,15 +1,16 @@
1
1
  import { AxiosResponse } from "axios";
2
+ interface CreateCustomer {
3
+ name: string;
4
+ storeUrl: string;
5
+ location: string;
6
+ email: string;
7
+ emailsTier_1: string;
8
+ emailsTier_2: string;
9
+ }
2
10
  declare class Custom {
3
11
  #private;
4
12
  constructor(accessKey: string, stagingUrl?: boolean);
5
- createCustomer(payload: {
6
- name: string;
7
- storeUrl: string;
8
- location: string;
9
- email: string;
10
- emailsTier_1: string;
11
- emailsTier_2: string;
12
- }): Promise<AxiosResponse<any>>;
13
+ createCustomer(payload: CreateCustomer): Promise<AxiosResponse<any>>;
13
14
  getCustomCustomerConfig: (store_url: string) => Promise<AxiosResponse<any>>;
14
15
  getModelUrl: (id: string) => Promise<AxiosResponse<any>>;
15
16
  }
@@ -11,7 +11,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
11
11
  };
12
12
  var _Custom_accessKey, _Custom_stagingUrl;
13
13
  import axios from "axios";
14
- import { API_ENDPOINTS, APP_AUTH_BASE_URL, REQUIRED_MESSAGE, } from "./constants.js";
14
+ import { API_ENDPOINTS, APP_AUTH_BASE_URL, REQUIRED_MESSAGE } from "./constants.js";
15
15
  import { checkParameters, getUrl } from "./utils.js";
16
16
  class Custom {
17
17
  constructor(accessKey, stagingUrl = false) {
@@ -1,17 +1,17 @@
1
1
  interface ObjMetaData {
2
2
  gender: string;
3
- scan_id: string;
3
+ scan_id?: string;
4
4
  email: string;
5
5
  focal_length: string;
6
6
  height: string;
7
7
  customer_store_url: string;
8
8
  clothes_fit: string;
9
- scan_type: string;
9
+ scan_type?: string;
10
10
  callback_url: string;
11
11
  }
12
12
  interface UploadOptions {
13
13
  file: File;
14
- arrayMetaData: ObjMetaData[];
14
+ arrayMetaData: Partial<ObjMetaData>[];
15
15
  scanId: string;
16
16
  }
17
17
  export default class FileUpload {
@@ -1,169 +1,206 @@
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); }); }
1
+ var __awaiter =
2
+ (this && this.__awaiter) ||
3
+ function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) {
5
+ return value instanceof P
6
+ ? value
7
+ : new P(function (resolve) {
8
+ resolve(value);
9
+ });
10
+ }
3
11
  return new (P || (P = Promise))(function (resolve, reject) {
4
- 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());
12
+ function fulfilled(value) {
13
+ try {
14
+ step(generator.next(value));
15
+ } catch (e) {
16
+ reject(e);
17
+ }
18
+ }
19
+ function rejected(value) {
20
+ try {
21
+ step(generator["throw"](value));
22
+ } catch (e) {
23
+ reject(e);
24
+ }
25
+ }
26
+ function step(result) {
27
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
28
+ }
29
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
30
  });
9
- };
10
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
31
+ };
32
+ var __classPrivateFieldSet =
33
+ (this && this.__classPrivateFieldSet) ||
34
+ function (receiver, state, value, kind, f) {
11
35
  if (kind === "m") throw new TypeError("Private method is not writable");
12
36
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
13
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) 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) {
37
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
38
+ throw new TypeError("Cannot write private member to an object whose class did not declare it");
39
+ return kind === "a" ? f.call(receiver, value) : f ? (f.value = value) : state.set(receiver, value), value;
40
+ };
41
+ var __classPrivateFieldGet =
42
+ (this && this.__classPrivateFieldGet) ||
43
+ function (receiver, state, kind, f) {
17
44
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
18
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
45
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
46
+ throw new TypeError("Cannot read private member from an object whose class did not declare it");
19
47
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
20
- };
48
+ };
21
49
  var _FileUpload_uppyIns, _FileUpload_accessKey, _FileUpload_stagingUrl;
22
50
  import axios from "axios";
23
51
  import { REQUIRED_MESSAGE, REQUIRED_MESSAGE_FOR_META_DATA, FILE_UPLOAD_ENDPOINT, APP_AUTH_BASE_URL } from "./constants.js";
24
- import { checkMetaDataValue, checkParameters, fetchData, getFileChunks, getUrl } from "./utils.js";
25
- import Uppy from "@uppy/core";
52
+ import { addScanType, checkMetaDataValue, checkParameters, fetchData, getFileChunks, getUrl } from "./utils.js";
53
+ import Uppy from "@uppy/core";
26
54
  import AwsS3Multipart from "@uppy/aws-s3-multipart";
27
55
  class FileUpload {
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
- return new Promise((resolve, reject) => {
44
- if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
45
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
46
- }
47
- __classPrivateFieldSet(this, _FileUpload_uppyIns, new Uppy({ autoProceed: true }), "f");
48
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").use(AwsS3Multipart, {
49
- limit: 10,
50
- retryDelays: [0, 1000, 3000, 5000],
51
- companionUrl: getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f") }),
52
- getChunkSize: () => 5 * 1024 * 1024,
53
- createMultipartUpload: (file) => {
54
- const objectKey = `${scanId}.${file.extension}`;
55
- return fetchData({
56
- path: FILE_UPLOAD_ENDPOINT.UPLOAD_START,
57
- apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
58
- stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
59
- body: {
60
- objectKey,
61
- contentType: file.type,
62
- objectMetadata: arrayMetaData,
63
- },
64
- });
65
- },
66
- completeMultipartUpload: (file, { uploadId, key, parts }) => fetchData({
67
- path: FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
68
- apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
69
- stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
70
- body: {
71
- uploadId,
72
- objectKey: key,
73
- parts,
74
- originalFileName: file.name,
75
- },
76
- }),
77
- signPart: (file, partData) => fetchData({
78
- path: FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
79
- stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
80
- apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
81
- body: {
82
- objectKey: partData.key,
83
- uploadId: partData.uploadId,
84
- partNumber: partData.partNumber,
85
- },
86
- }),
87
- });
88
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").addFile({
89
- source: "manual",
90
- name: file.name,
91
- type: file.type,
92
- data: file,
93
- });
94
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-error", (file, error, response) => {
95
- reject(error);
96
- });
97
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("upload-success", () => {
98
- resolve({ message: "file uploaded successfully" });
99
- });
100
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").on("complete", (result) => {
101
- if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
102
- __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
103
- }
104
- });
56
+ constructor(accessKey, stagingUrl = false) {
57
+ _FileUpload_uppyIns.set(this, void 0);
58
+ _FileUpload_accessKey.set(this, void 0);
59
+ _FileUpload_stagingUrl.set(this, void 0);
60
+ __classPrivateFieldSet(this, _FileUpload_accessKey, accessKey, "f");
61
+ __classPrivateFieldSet(this, _FileUpload_stagingUrl, stagingUrl, "f");
62
+ }
63
+ uploadFileFrontend(_a) {
64
+ return __awaiter(this, arguments, void 0, function* ({ file, arrayMetaData, scanId }) {
65
+ if (!checkParameters(file, arrayMetaData, scanId)) {
66
+ throw new Error(REQUIRED_MESSAGE);
67
+ }
68
+ if (!checkMetaDataValue(arrayMetaData)) {
69
+ throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
70
+ }
71
+ arrayMetaData = addScanType(arrayMetaData, scanId);
72
+ return new Promise((resolve, reject) => {
73
+ if (__classPrivateFieldGet(this, _FileUpload_uppyIns, "f")) {
74
+ __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").close();
75
+ }
76
+ __classPrivateFieldSet(this, _FileUpload_uppyIns, new Uppy({ autoProceed: true }), "f");
77
+ __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").use(AwsS3Multipart, {
78
+ limit: 10,
79
+ retryDelays: [0, 1000, 3000, 5000],
80
+ companionUrl: getUrl({ urlName: APP_AUTH_BASE_URL, stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f") }),
81
+ getChunkSize: () => 5 * 1024 * 1024,
82
+ createMultipartUpload: (file) => {
83
+ const objectKey = `${scanId}.${file.extension}`;
84
+ return fetchData({
85
+ path: FILE_UPLOAD_ENDPOINT.UPLOAD_START,
86
+ apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
87
+ stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
88
+ body: {
89
+ objectKey,
90
+ contentType: file.type,
91
+ objectMetadata: arrayMetaData,
92
+ },
105
93
  });
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
+ }),
106
118
  });
107
- }
108
- uploadFile(_a) {
109
- return __awaiter(this, arguments, void 0, function* ({ file, arrayMetaData, scanId }) {
110
- if (!checkParameters(file, arrayMetaData, scanId)) {
111
- throw new Error(REQUIRED_MESSAGE);
112
- }
113
- if (!checkMetaDataValue(arrayMetaData)) {
114
- throw new Error(REQUIRED_MESSAGE_FOR_META_DATA);
115
- }
116
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
117
- var _b;
118
- try {
119
- const res = yield fetchData({
120
- path: FILE_UPLOAD_ENDPOINT.UPLOAD_START,
121
- apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
122
- stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
123
- body: {
124
- objectKey: file.name,
125
- contentType: file.type,
126
- objectMetadata: arrayMetaData,
127
- },
128
- throwError: true,
129
- });
130
- const totalChunks = getFileChunks(file);
131
- const parts = [];
132
- for (let i = 0; i < totalChunks.length; i++) {
133
- const data = yield fetchData({
134
- path: FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
135
- apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
136
- stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
137
- body: {
138
- objectKey: res === null || res === void 0 ? void 0 : res.key,
139
- uploadId: res === null || res === void 0 ? void 0 : res.uploadId,
140
- partNumber: i + 1,
141
- },
142
- throwError: true,
143
- });
144
- 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") } });
145
- parts.push({ PartNumber: i + 1, ETag: (_b = val === null || val === void 0 ? void 0 : val.headers) === null || _b === void 0 ? void 0 : _b.etag });
146
- }
147
- const completeValue = yield fetchData({
148
- path: FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
149
- apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
150
- stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
151
- body: {
152
- uploadId: res === null || res === void 0 ? void 0 : res.uploadId,
153
- objectKey: res === null || res === void 0 ? void 0 : res.key,
154
- parts,
155
- originalFileName: file.name,
156
- },
157
- throwError: true,
158
- });
159
- resolve({ message: "successfully uploaded", data: completeValue });
160
- }
161
- catch (error) {
162
- reject(error);
163
- }
164
- }));
119
+ __classPrivateFieldGet(this, _FileUpload_uppyIns, "f").addFile({
120
+ source: "manual",
121
+ name: file.name,
122
+ type: file.type,
123
+ data: file,
165
124
  });
166
- }
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
+ });
136
+ });
137
+ });
138
+ }
139
+ uploadFile(_a) {
140
+ return __awaiter(this, arguments, void 0, function* ({ file, arrayMetaData, scanId }) {
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
+ return new Promise((resolve, reject) =>
148
+ __awaiter(this, void 0, void 0, function* () {
149
+ var _b;
150
+ try {
151
+ const res = yield fetchData({
152
+ path: FILE_UPLOAD_ENDPOINT.UPLOAD_START,
153
+ apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
154
+ stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
155
+ body: {
156
+ objectKey: file.name,
157
+ contentType: file.type,
158
+ objectMetadata: arrayMetaData,
159
+ },
160
+ throwError: true,
161
+ });
162
+ const totalChunks = getFileChunks(file);
163
+ const parts = [];
164
+ for (let i = 0; i < totalChunks.length; i++) {
165
+ const data = yield fetchData({
166
+ path: FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
167
+ apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
168
+ stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
169
+ body: {
170
+ objectKey: res === null || res === void 0 ? void 0 : res.key,
171
+ uploadId: res === null || res === void 0 ? void 0 : res.uploadId,
172
+ partNumber: i + 1,
173
+ },
174
+ throwError: true,
175
+ });
176
+ const val = yield axios.put(data === null || data === void 0 ? void 0 : data.url, totalChunks[i], {
177
+ headers: { "Content-Type": file.type, "X-Api-Key": __classPrivateFieldGet(this, _FileUpload_accessKey, "f") },
178
+ });
179
+ parts.push({
180
+ PartNumber: i + 1,
181
+ ETag: (_b = val === null || val === void 0 ? void 0 : val.headers) === null || _b === void 0 ? void 0 : _b.etag,
182
+ });
183
+ }
184
+ const completeValue = yield fetchData({
185
+ path: FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
186
+ apiKey: __classPrivateFieldGet(this, _FileUpload_accessKey, "f"),
187
+ stagingUrl: __classPrivateFieldGet(this, _FileUpload_stagingUrl, "f"),
188
+ body: {
189
+ uploadId: res === null || res === void 0 ? void 0 : res.uploadId,
190
+ objectKey: res === null || res === void 0 ? void 0 : res.key,
191
+ parts,
192
+ originalFileName: file.name,
193
+ },
194
+ throwError: true,
195
+ });
196
+ resolve({ message: "successfully uploaded", data: completeValue });
197
+ } catch (error) {
198
+ reject(error);
199
+ }
200
+ })
201
+ );
202
+ });
203
+ }
167
204
  }
168
- _FileUpload_uppyIns = new WeakMap(), _FileUpload_accessKey = new WeakMap(), _FileUpload_stagingUrl = new WeakMap();
205
+ (_FileUpload_uppyIns = new WeakMap()), (_FileUpload_accessKey = new WeakMap()), (_FileUpload_stagingUrl = new WeakMap());
169
206
  export default FileUpload;
@@ -12,6 +12,6 @@ declare class Swan {
12
12
  measurement: Measurement;
13
13
  poseDetection: PoseDetection;
14
14
  tryOn: TryOn;
15
- constructor(accessKey: string, prod?: boolean);
15
+ constructor(accessKey: string, stagingUrl?: boolean);
16
16
  }
17
17
  export default Swan;
package/dist/esm/index.js CHANGED
@@ -17,11 +17,11 @@ import Measurement from "./measurement.js";
17
17
  import PoseDetection from "./poseDetection.js";
18
18
  import TryOn from "./tryOn.js";
19
19
  class Swan {
20
- constructor(accessKey, prod = false) {
20
+ constructor(accessKey, stagingUrl = false) {
21
21
  _Swan_accessKey.set(this, void 0);
22
22
  _Swan_stagingUrl.set(this, void 0);
23
23
  __classPrivateFieldSet(this, _Swan_accessKey, accessKey, "f");
24
- __classPrivateFieldSet(this, _Swan_stagingUrl, prod, "f");
24
+ __classPrivateFieldSet(this, _Swan_stagingUrl, stagingUrl, "f");
25
25
  this.auth = new Auth(__classPrivateFieldGet(this, _Swan_accessKey, "f"), __classPrivateFieldGet(this, _Swan_stagingUrl, "f"));
26
26
  this.custom = new Custom(__classPrivateFieldGet(this, _Swan_accessKey, "f"), __classPrivateFieldGet(this, _Swan_stagingUrl, "f"));
27
27
  this.fileUpload = new FileUpload(__classPrivateFieldGet(this, _Swan_accessKey, "f"), __classPrivateFieldGet(this, _Swan_stagingUrl, "f"));
@@ -11,7 +11,8 @@ export interface FetchDataOptions {
11
11
  }
12
12
  export declare function fetchData(options: FetchDataOptions): Promise<any>;
13
13
  export declare function checkParameters(...args: any[]): boolean;
14
- export declare function checkMetaDataValue(arr: ObjMetaData[]): boolean;
14
+ export declare function checkMetaDataValue(arr: Partial<ObjMetaData>[]): boolean;
15
+ export declare const addScanType: (arr: Partial<ObjMetaData>[], scan_id: string) => Partial<ObjMetaData>[];
15
16
  export declare function getFileChunks(file: File, chunkSize?: number): Blob[];
16
17
  export declare const getUrl: ({ urlName, stagingUrl }: {
17
18
  urlName: string;