@swan-admin/swan-ai-measurements 1.0.11 → 1.0.12

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/auth.js ADDED
@@ -0,0 +1,32 @@
1
+ import axios from "axios";
2
+ import { API_ENDPOINTS, APP_AUTH_BASE_URL, APP_BASE_URL } from "./constants.js";
3
+
4
+ export const registerUser = ({ email, appVerifyUrl, gender, height, username = "", accessKey }) => {
5
+ let body = {
6
+ username,
7
+ email,
8
+ appVerifyUrl,
9
+ };
10
+ if (gender && height) {
11
+ body = { ...body, attributes: { gender, height } };
12
+ }
13
+ return axios.post(`${APP_AUTH_BASE_URL}${API_ENDPOINTS.REGISTER_USER}`, body);
14
+ };
15
+
16
+ export function verifyUser(token, accessKey) {
17
+ return axios.post(`${APP_AUTH_BASE_URL}${API_ENDPOINTS.VERIFY_USER}`, null, {
18
+ params: { token },
19
+ });
20
+ }
21
+
22
+ export const addUser = async ({ scanId, email, name = "", height, gender, accessKey }) =>
23
+ axios.post(`${APP_AUTH_BASE_URL}${API_ENDPOINTS.ADD_USER}`, {
24
+ scan_id: scanId,
25
+ email,
26
+ name,
27
+ attributes: JSON.stringify({ height, gender }),
28
+ });
29
+
30
+ export function getUserDetail(email, accessKey) {
31
+ return axios.get(`${APP_BASE_URL}${API_ENDPOINTS.GET_USER_DETAIL}/${email}`);
32
+ }
package/constants.js CHANGED
@@ -1,5 +1,7 @@
1
1
  export const FILE_UPLOAD_URL = "https://9xc8mxwlkj.execute-api.us-east-1.amazonaws.com/staging";
2
2
  export const FILE_UPLOAD_KEY = "7a8ccc86249849be911b0d7dbc20290e";
3
+ export const APP_BASE_URL = "https://fitview-server-staging.ft2a64raup4pg.us-east-1.cs.amazonlightsail.com";
4
+ export const APP_AUTH_BASE_URL = "https://staging.api.getswan.co";
3
5
 
4
6
  export const UPPY_FILE_UPLOAD_ENDPOINT = {
5
7
  UPLOAD_START: "/upload/start",
@@ -7,3 +9,10 @@ export const UPPY_FILE_UPLOAD_ENDPOINT = {
7
9
  UPLOAD_SIGN_PART: "/upload/signpart",
8
10
  UPLOAD_ABORT: "/upload/abort",
9
11
  };
12
+
13
+ export const API_ENDPOINTS = {
14
+ GET_USER_DETAIL: "/api/user",
15
+ REGISTER_USER: "/auth/register",
16
+ VERIFY_USER: "/auth/verify",
17
+ ADD_USER: "/user",
18
+ };
package/fileUpload.js ADDED
@@ -0,0 +1,80 @@
1
+ import AwsS3Multipart from "@uppy/aws-s3-multipart";
2
+ import Uppy from "@uppy/core";
3
+ import { FILE_UPLOAD_KEY, UPPY_FILE_UPLOAD_ENDPOINT } from "./constants.js";
4
+
5
+ function uploadFile({ file, objMetaData, scanId, accessKey }) {
6
+ return new Promise((resolve, reject) => {
7
+ uppyIns = new Uppy({ autoProceed: true });
8
+ uppyIns.use(AwsS3Multipart, {
9
+ limit: 10,
10
+ retryDelays: [0, 1000, 3000, 5000],
11
+ getChunkSize: () => 5 * 1024 * 1024,
12
+ createMultipartUpload: (file) => {
13
+ const objectKey = `${scanId}.${file.extension}`;
14
+ return fetchData({
15
+ path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_START,
16
+ apiKey: FILE_UPLOAD_KEY,
17
+ body: {
18
+ objectKey,
19
+ contentType: file.type,
20
+ objectMetadata: objMetaData,
21
+ },
22
+ });
23
+ },
24
+ completeMultipartUpload: (file, { uploadId, key, parts }) =>
25
+ fetchData({
26
+ path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
27
+ apiKey: FILE_UPLOAD_KEY,
28
+ body: {
29
+ uploadId,
30
+ objectKey: key,
31
+ parts,
32
+ originalFileName: file.name,
33
+ },
34
+ }),
35
+
36
+ signPart: (file, partData) =>
37
+ fetchData({
38
+ path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
39
+ apiKey: FILE_UPLOAD_KEY,
40
+ body: {
41
+ objectKey: partData.key,
42
+ uploadId: partData.uploadId,
43
+ partNumber: partData.partNumber,
44
+ },
45
+ }),
46
+
47
+ abortMultipartUpload: (file, { uploadId, key }) =>
48
+ fetchData({
49
+ path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_ABORT,
50
+ apiKey: FILE_UPLOAD_KEY,
51
+ body: {
52
+ uploadId,
53
+ objectKey: key,
54
+ originalFileName: file.name,
55
+ },
56
+ }),
57
+ });
58
+
59
+ uppyIns.addFile({
60
+ source: "manual",
61
+ name: file.name,
62
+ type: file.type,
63
+ data: file,
64
+ });
65
+
66
+ uppyIns.on("upload-error", (file, error, response) => {
67
+ reject(error);
68
+ });
69
+ uppyIns.on("upload-success", () => {
70
+ resolve({ message: "file uploaded successfully" });
71
+ });
72
+ uppyIns.on("complete", (result) => {
73
+ if (uppyIns) {
74
+ uppyIns.close();
75
+ }
76
+ });
77
+ });
78
+ }
79
+
80
+ export default uploadFile;
package/index.js CHANGED
@@ -1,87 +1,30 @@
1
- import Uppy from "@uppy/core";
2
- import { FILE_UPLOAD_KEY, UPPY_FILE_UPLOAD_ENDPOINT } from "./constants.js";
3
- import { fetchData } from "./utils.js";
4
- import AwsS3Multipart from "@uppy/aws-s3-multipart";
1
+ import { FILE_UPLOAD_KEY } from "./constants.js";
2
+ import { addUser, getUserDetail, registerUser, verifyUser } from "./auth.js";
3
+ import uploadFile from "./fileUpload.js";
5
4
  export default class Swan {
6
5
  constructor(key) {
7
- if (key !== FILE_UPLOAD_KEY) {
6
+ if (key !== 9876543210) {
8
7
  throw new Error("wrong access key");
9
8
  }
10
9
  this.accessKey = key;
11
- this.uppyIns = null;
12
10
  }
13
- uploadFile({ file, objMetaData, scanId }) {
14
- return new Promise((resolve, reject) => {
15
- this.uppyIns = new Uppy({ autoProceed: true });
16
- this.uppyIns.use(AwsS3Multipart, {
17
- limit: 10,
18
- retryDelays: [0, 1000, 3000, 5000],
19
- getChunkSize: () => 5 * 1024 * 1024,
20
- createMultipartUpload: (file) => {
21
- const objectKey = `${scanId}.${file.extension}`;
22
- return fetchData({
23
- path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_START,
24
- apiKey: this.accessKey,
25
- body: {
26
- objectKey,
27
- contentType: file.type,
28
- objectMetadata: objMetaData,
29
- },
30
- });
31
- },
32
- completeMultipartUpload: (file, { uploadId, key, parts }) =>
33
- fetchData({
34
- path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
35
- apiKey: this.accessKey,
36
- body: {
37
- uploadId,
38
- objectKey: key,
39
- parts,
40
- originalFileName: file.name,
41
- },
42
- }),
11
+ registerUser({ email, appVerifyUrl, gender, height, username = "" }) {
12
+ return registerUser({ email, appVerifyUrl, gender, height, username, accessKey: this.accessKey });
13
+ }
43
14
 
44
- signPart: (file, partData) =>
45
- fetchData({
46
- path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
47
- apiKey: this.accessKey,
48
- body: {
49
- objectKey: partData.key,
50
- uploadId: partData.uploadId,
51
- partNumber: partData.partNumber,
52
- },
53
- }),
15
+ verifyUser(token) {
16
+ return verifyUser(token, this.accessKey);
17
+ }
54
18
 
55
- abortMultipartUpload: (file, { uploadId, key }) =>
56
- fetchData({
57
- path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_ABORT,
58
- apiKey: this.accessKey,
59
- body: {
60
- uploadId,
61
- objectKey: key,
62
- originalFileName: file.name,
63
- },
64
- }),
65
- });
19
+ addUser({ scanId, email, name = "", height, gender }) {
20
+ return addUser({ scanId, email, name, height, gender, accessKey: this.accessKey });
21
+ }
66
22
 
67
- this.uppyIns.addFile({
68
- source: "manual",
69
- name: file.name,
70
- type: file.type,
71
- data: file,
72
- });
23
+ getUserDetail(email) {
24
+ return getUserDetail(email, this.accessKey);
25
+ }
73
26
 
74
- this.uppyIns.on("upload-error", (file, error, response) => {
75
- reject(error);
76
- });
77
- this.uppyIns.on("upload-success", () => {
78
- resolve({ message: "file uploaded successfully" });
79
- });
80
- this.uppyIns.on("complete", (result) => {
81
- if (this.uppyIns) {
82
- this.uppyIns.close();
83
- }
84
- });
85
- });
27
+ uploadFile({ file, objMetaData, scanId }) {
28
+ return uploadFile({ file, objMetaData, scanId, accessKey: this.accessKey });
86
29
  }
87
30
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swan-admin/swan-ai-measurements",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "description": "provides ai measurement suggestion",
5
5
  "main": "index.js",
6
6
  "type": "module",