@marteye/studiojs 1.1.13 → 1.1.15

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.
@@ -0,0 +1,201 @@
1
+ import { z } from "zod";
2
+ /**
3
+ |--------------------------------------------------
4
+ | START OF MEDIA CRATE CODE
5
+ |--------------------------------------------------
6
+ */
7
+ export declare const processorPayload: z.ZodObject<{
8
+ assetPath: z.ZodString;
9
+ suffix: z.ZodString;
10
+ }, "strip", z.ZodTypeAny, {
11
+ assetPath: string;
12
+ suffix: string;
13
+ }, {
14
+ assetPath: string;
15
+ suffix: string;
16
+ }>;
17
+ export declare const IMAGE_SIZES_VALUES: readonly ["small", "medium", "large"];
18
+ export declare const VIDEO_TASKS_VALUES: readonly ["compressed", "thumbnail"];
19
+ export declare const videoTaskSchema: z.ZodEnum<["compressed", "thumbnail"]>;
20
+ export declare const imageSizeSchema: z.ZodEnum<["small", "medium", "large"]>;
21
+ export type ImageSize = z.infer<typeof imageSizeSchema>;
22
+ export type ProcessorPayload = z.infer<typeof processorPayload>;
23
+ export type VideoVMPayload = ProcessorPayload & {
24
+ task: VideoTask;
25
+ };
26
+ export type VideoTask = z.infer<typeof videoTaskSchema>;
27
+ export type SupportedFileTypesNames = "image" | "video" | "file";
28
+ export type VariantProcessingState = {
29
+ fileName: string;
30
+ thumbHash: string;
31
+ path: string;
32
+ url: string;
33
+ fileType: string;
34
+ variants: Partial<Record<ImageSize | VideoTask, {
35
+ url: string;
36
+ isProcessing: boolean;
37
+ type: SupportedFileTypesNames;
38
+ }>>;
39
+ };
40
+ /**
41
+ |--------------------------------------------------
42
+ | END OF MEDIA CRATE CODE
43
+ |--------------------------------------------------
44
+ */
45
+ type MediaFinishUploadResponse = {
46
+ message: string;
47
+ mediaType: string;
48
+ process: VariantProcessingState;
49
+ };
50
+ export type MediaUploadOptions = {
51
+ marketId: string;
52
+ saleId: string;
53
+ lotId: string;
54
+ attributeId: string;
55
+ options?: {
56
+ bucket?: "raw";
57
+ parallelParts?: number;
58
+ baseUrl?: string;
59
+ progressCallback?: (progress: {
60
+ /**
61
+ * The state of the upload
62
+ */
63
+ state: "uploading" | "finished" | "failed" | "starting";
64
+ /**
65
+ * The progress of the upload
66
+ */
67
+ progress: number;
68
+ /**
69
+ * The current part number
70
+ */
71
+ currentPart?: number;
72
+ /**
73
+ * The total parts
74
+ */
75
+ totalParts?: number;
76
+ }) => void;
77
+ };
78
+ };
79
+ /**
80
+ * Starts a multipart upload process for a file
81
+ * @param {Object} params - The parameters for starting the upload
82
+ * @param {string} params.fileName - Name of the file without extension
83
+ * @param {string} params.fileMimeType - MIME type of the file
84
+ * @param {string} params.fileExtension - File extension
85
+ * @param {MediaUploadOptions} params.options - Upload options including market, sale, lot and attribute IDs
86
+ * @returns {Promise<{uploadId: string, filePath: string, fileMimeType: string, fileExtension: string, fileName: string}>}
87
+ * @throws {Error} When upload initialization fails
88
+ */
89
+ export declare const startUpload: ({ fileName, fileMimeType, fileExtension, token, options, }: {
90
+ fileName: string;
91
+ fileMimeType: string;
92
+ fileExtension: string;
93
+ token: string;
94
+ options: MediaUploadOptions;
95
+ }) => Promise<{
96
+ uploadId: string;
97
+ filePath: string;
98
+ fileMimeType: string;
99
+ fileExtension: string;
100
+ fileName: string;
101
+ }>;
102
+ export type ChunkedFile = {
103
+ partNumber: string;
104
+ chunk: string;
105
+ fileExtension: string;
106
+ fileMimeType: string;
107
+ };
108
+ /**
109
+ * Splits a file into chunks for multipart upload
110
+ * Note: Native does not have File Prototype, please implement your own chunking logic
111
+ * @param {File} file - The file to be chunked
112
+ * @param {number} chunkSize - Size of each chunk in bytes
113
+ * @returns {Array<ChunkedFile>} Array of chunked file parts
114
+ */
115
+ export declare const chunkFile: (file: File, chunkSize: number) => Array<ChunkedFile>;
116
+ /**
117
+ * Uploads a single part/chunk of a file
118
+ * @param {ChunkedFile} chunkedFile - The chunk of file to upload
119
+ * @param {string} uploadId - Upload ID from startUpload
120
+ * @param {string} filePath - Path where file will be stored
121
+ * @param {MediaUploadOptions} options - Upload options
122
+ * @returns {Promise<{partNumber: string, eTag: string}>}
123
+ * @throws {Error} When part upload fails
124
+ */
125
+ export declare const uploadPart: ({ chunkedFile, uploadId, filePath, options, token, }: {
126
+ chunkedFile: ChunkedFile;
127
+ uploadId: string;
128
+ filePath: string;
129
+ options: MediaUploadOptions;
130
+ token: string;
131
+ }) => Promise<{
132
+ partNumber: string;
133
+ eTag: string;
134
+ }>;
135
+ /**
136
+ * Completes a multipart upload by combining all parts
137
+ * @param {string} filePath - Path where file is stored
138
+ * @param {string} fileMimeType - MIME type of the file
139
+ * @param {string} uploadId - Upload ID from startUpload
140
+ * @param {Array<{partNumber: string, eTag: string}>} sections - Array of successfully uploaded parts
141
+ * @param {MediaUploadOptions} options - Upload options
142
+ * @returns {Promise<MediaFinishUploadResponse>}
143
+ * @throws {Error} When finishing upload fails
144
+ */
145
+ export declare const finishUpload: ({ filePath, fileMimeType, uploadId, sections, options, token, }: {
146
+ filePath: string;
147
+ fileMimeType: string;
148
+ uploadId: string;
149
+ sections: Array<{
150
+ partNumber: string;
151
+ eTag: string;
152
+ }>;
153
+ options: MediaUploadOptions;
154
+ token: string;
155
+ }) => Promise<MediaFinishUploadResponse>;
156
+ /**
157
+ * Cancels an in-progress multipart upload
158
+ * @param {string} uploadId - Upload ID to cancel
159
+ * @param {string} filePath - Path of the file being uploaded
160
+ * @param {string} fileMimeType - MIME type of the file
161
+ * @param {MediaUploadOptions} options - Upload options
162
+ * @returns {Promise<{data: boolean}>}
163
+ * @throws {Error} When canceling upload fails
164
+ */
165
+ export declare const cancelUpload: ({ uploadId, filePath, fileMimeType, options, token, }: {
166
+ uploadId: string;
167
+ filePath: string;
168
+ fileMimeType: string;
169
+ options: MediaUploadOptions;
170
+ token: string;
171
+ }) => Promise<{
172
+ data: boolean;
173
+ }>;
174
+ /**
175
+ * Deletes a multipart upload
176
+ * @param {string} fileUrl - The URL of the file to delete
177
+ * @returns {Promise<{data: boolean}>}
178
+ * @throws {Error} When deleting upload fails
179
+ */
180
+ export declare const deleteUpload: (fileUrl: string, token: string) => Promise<{
181
+ data: boolean;
182
+ }>;
183
+ export type FileInput = {
184
+ file: File;
185
+ uploadConfig: MediaUploadOptions;
186
+ };
187
+ export type ChunkedInput = {
188
+ fileName: string;
189
+ chunks: ChunkedFile[];
190
+ uploadConfig: MediaUploadOptions;
191
+ };
192
+ /**
193
+ * Handles the complete file upload process including chunking and progress tracking -
194
+ * WEB: Pass in a file and we will chunk it and upload it in parallel
195
+ * NATIVE: You need to chunk the file yourself.
196
+ * @param {FileInput | ChunkedInput} input - Either {file, options} or {fileName, chunks, options}
197
+ * @returns {Promise<MediaFinishUploadResponse>}
198
+ * @throws {Error} When upload fails
199
+ */
200
+ export declare const uploadFile: (input: FileInput | ChunkedInput, token: string) => Promise<MediaFinishUploadResponse>;
201
+ export {};
package/package.json CHANGED
@@ -1,15 +1,25 @@
1
1
  {
2
2
  "name": "@marteye/studiojs",
3
- "version": "1.1.13",
3
+ "version": "1.1.15",
4
4
  "description": "MartEye Studio JavaScript SDK",
5
5
  "license": "MIT",
6
+ "type": "module",
6
7
  "source": "src/index.ts",
7
8
  "main": "dist/index.js",
8
9
  "module": "dist/index.esm.js",
9
10
  "types": "dist/index.d.ts",
11
+ "browser": {
12
+ "crypto": false
13
+ },
10
14
  "files": [
11
15
  "dist"
12
16
  ],
17
+ "exports": {
18
+ ".": {
19
+ "require": "./dist/index.js",
20
+ "import": "./dist/index.esm.js"
21
+ }
22
+ },
13
23
  "scripts": {
14
24
  "clean": "rm -rf dist",
15
25
  "build": "npm run clean && rollup -c",
@@ -22,8 +32,9 @@
22
32
  "@rollup/plugin-commonjs": "^25.0.0",
23
33
  "@rollup/plugin-node-resolve": "^15.0.0",
24
34
  "@rollup/plugin-typescript": "^11.0.0",
25
- "@types/jest": "^29.4.0",
35
+ "@types/jest": "^29.5.14",
26
36
  "@types/node": "^18.14.0",
37
+ "@web-std/file": "^3.0.3",
27
38
  "dotenv": "^16.4.7",
28
39
  "jest": "^29.4.3",
29
40
  "rollup": "^4.0.0",
@@ -34,5 +45,8 @@
34
45
  },
35
46
  "jest": {
36
47
  "preset": "ts-jest"
48
+ },
49
+ "dependencies": {
50
+ "zod": "^3.24.2"
37
51
  }
38
52
  }