@amaster.ai/s3-client 1.1.0-beta.17

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Amaster Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # @amaster.ai/s3-client
2
+
3
+ Type-safe client for interacting with Amaster S3 storage service.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @amaster.ai/s3-client
9
+ # or
10
+ pnpm add @amaster.ai/s3-client
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```typescript
16
+ import { createS3Client } from '@amaster.ai/s3-client';
17
+
18
+ const s3Client = createS3Client();
19
+
20
+ // 1. Upload a file
21
+ const fileInput = document.querySelector('input[type="file"]');
22
+ if (fileInput.files.length > 0) {
23
+ const file = fileInput.files[0];
24
+ const uploadResult = await s3Client.upload(file);
25
+
26
+ if (uploadResult.data) {
27
+ console.log('Uploaded:', uploadResult.data.url);
28
+ console.log('Key:', uploadResult.data.key);
29
+ }
30
+ }
31
+
32
+ // 2. Get file metadata
33
+ const metadata = await s3Client.getMetadata('uploads/image.png');
34
+ if (metadata.data) {
35
+ console.log('Type:', metadata.data.contentType);
36
+ console.log('Size:', metadata.data.contentLength);
37
+ }
38
+
39
+ // 3. Download a file
40
+ const downloadResult = await s3Client.download('uploads/image.png');
41
+ if (downloadResult.data) {
42
+ // result.data is a Blob
43
+ const url = URL.createObjectURL(downloadResult.data);
44
+ window.open(url);
45
+ }
46
+ ```
47
+
48
+ ## API Reference
49
+
50
+ ### `createS3Client(http?: HttpClient)`
51
+
52
+ Creates a new instance of the S3 client. Optionally accepts a custom HTTP client.
53
+
54
+ ### `upload(file: File | Blob)`
55
+
56
+ Uploads a file to the storage.
57
+
58
+ - **Parameters**:
59
+ - `file`: `File` or `Blob` object to upload.
60
+ - **Returns**: `Promise<ClientResult<UploadRes>>`
61
+
62
+ ### `download(filename: string)`
63
+
64
+ Downloads a file as a Blob.
65
+
66
+ - **Parameters**:
67
+ - `filename`: The key/path of the file to download.
68
+ - **Returns**: `Promise<ClientResult<Blob>>`
69
+
70
+ ### `getMetadata(key: string)`
71
+
72
+ Retrieves metadata for a specific file.
73
+
74
+ - **Parameters**:
75
+ - `key`: The key/path of the file.
76
+ - **Returns**: `Promise<ClientResult<S3Metadata>>`
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ 'use strict';var httpClient=require('@amaster.ai/http-client');var a="/api/storage";function l(e=httpClient.createHttpClient()){return {async download(t){return t?await e.request({url:`${a}/download`,method:"get",params:{filename:t},responseType:"blob"}):{data:null,error:{message:"Filename is required",status:400},status:400}},async getMetadata(t){return t?e.request({url:`${a}/metadata`,method:"get",params:{key:t}}):{data:null,error:{message:"Key is required",status:400},status:400}},async upload(t){if(!t)return {data:null,error:{message:"File is required",status:400},status:400};let r=new FormData;return r.append("file",t),e.request({url:`${a}/upload`,method:"post",data:r,headers:{"Content-Type":"multipart/form-data"}})}}}exports.createS3Client=l;//# sourceMappingURL=index.cjs.map
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/s3-client.ts"],"names":["BASE_URL","createS3Client","http","createHttpClient","filename","key","file","formData"],"mappings":"+DAGA,IAAMA,CAAAA,CAAW,cAAA,CAEV,SAASC,CAAAA,CAAeC,CAAAA,CAAmBC,2BAAAA,EAAiB,CAAa,CAC9E,OAAO,CACL,MAAM,QAAA,CAASC,CAAAA,CAA+C,CAC5D,OAAKA,CAAAA,CAQU,MAAMF,EAAK,OAAA,CAAc,CACtC,GAAA,CAAK,CAAA,EAAGF,CAAQ,CAAA,SAAA,CAAA,CAChB,MAAA,CAAQ,KAAA,CACR,OAAQ,CAAE,QAAA,CAAAI,CAAS,CAAA,CACnB,YAAA,CAAc,MAChB,CAAC,CAAA,CAZQ,CACL,IAAA,CAAM,IAAA,CACN,KAAA,CAAO,CAAE,OAAA,CAAS,sBAAA,CAAwB,MAAA,CAAQ,GAAI,EACtD,MAAA,CAAQ,GACV,CAWJ,CAAA,CAEA,MAAM,WAAA,CAAYC,CAAAA,CAAgD,CAChE,OAAKA,CAAAA,CAQEH,CAAAA,CAAK,OAAA,CAAoB,CAC9B,GAAA,CAAK,CAAA,EAAGF,CAAQ,CAAA,SAAA,CAAA,CAChB,OAAQ,KAAA,CACR,MAAA,CAAQ,CAAE,GAAA,CAAAK,CAAI,CAChB,CAAC,CAAA,CAXQ,CACL,IAAA,CAAM,IAAA,CACN,KAAA,CAAO,CAAE,OAAA,CAAS,iBAAA,CAAmB,MAAA,CAAQ,GAAI,EACjD,MAAA,CAAQ,GACV,CAQJ,CAAA,CAEA,MAAM,MAAA,CAAOC,CAAAA,CAAqD,CAChE,GAAI,CAACA,CAAAA,CACH,OAAO,CACL,IAAA,CAAM,IAAA,CACN,KAAA,CAAO,CAAE,QAAS,kBAAA,CAAoB,MAAA,CAAQ,GAAI,CAAA,CAClD,MAAA,CAAQ,GACV,CAAA,CAGF,IAAMC,EAAW,IAAI,QAAA,CACrB,OAAAA,CAAAA,CAAS,MAAA,CAAO,MAAA,CAAQD,CAAI,CAAA,CAErBJ,EAAK,OAAA,CAAmB,CAC7B,GAAA,CAAK,CAAA,EAAGF,CAAQ,CAAA,OAAA,CAAA,CAChB,MAAA,CAAQ,MAAA,CACR,KAAMO,CAAAA,CACN,OAAA,CAAS,CACP,cAAA,CAAgB,qBAClB,CACF,CAAC,CACH,CACF,CACF","file":"index.cjs","sourcesContent":["import { type ClientResult, createHttpClient, type HttpClient } from \"@amaster.ai/http-client\";\nimport type { S3Client, S3Metadata, UploadRes } from \"./types\";\n\nconst BASE_URL = \"/api/storage\";\n\nexport function createS3Client(http: HttpClient = createHttpClient()): S3Client {\n return {\n async download(filename: string): Promise<ClientResult<Blob>> {\n if (!filename) {\n return {\n data: null,\n error: { message: \"Filename is required\", status: 400 },\n status: 400,\n };\n }\n\n const result = await http.request<Blob>({\n url: `${BASE_URL}/download`,\n method: \"get\",\n params: { filename },\n responseType: \"blob\",\n });\n\n return result;\n },\n\n async getMetadata(key: string): Promise<ClientResult<S3Metadata>> {\n if (!key) {\n return {\n data: null,\n error: { message: \"Key is required\", status: 400 },\n status: 400,\n };\n }\n\n return http.request<S3Metadata>({\n url: `${BASE_URL}/metadata`,\n method: \"get\",\n params: { key },\n });\n },\n\n async upload(file: File | Blob): Promise<ClientResult<UploadRes>> {\n if (!file) {\n return {\n data: null,\n error: { message: \"File is required\", status: 400 },\n status: 400,\n };\n }\n\n const formData = new FormData();\n formData.append(\"file\", file);\n\n return http.request<UploadRes>({\n url: `${BASE_URL}/upload`,\n method: \"post\",\n data: formData,\n headers: {\n \"Content-Type\": \"multipart/form-data\",\n },\n });\n },\n };\n}\n"]}
@@ -0,0 +1,33 @@
1
+ import { ClientResult, HttpClient } from '@amaster.ai/http-client';
2
+
3
+ interface UploadRes {
4
+ key: string;
5
+ url: string;
6
+ }
7
+ interface S3Metadata {
8
+ contentType?: string;
9
+ contentLength?: number;
10
+ lastModified?: string;
11
+ [key: string]: any;
12
+ }
13
+ type S3Client = {
14
+ /**
15
+ * Download a file
16
+ * @param filename - The name of the file to download
17
+ */
18
+ download(filename: string): Promise<ClientResult<Blob>>;
19
+ /**
20
+ * Get metadata for a file
21
+ * @param key - The key of the file
22
+ */
23
+ getMetadata(key: string): Promise<ClientResult<S3Metadata>>;
24
+ /**
25
+ * Upload a file
26
+ * @param file - The file to upload (File or Blob)
27
+ */
28
+ upload(file: File | Blob): Promise<ClientResult<UploadRes>>;
29
+ };
30
+
31
+ declare function createS3Client(http?: HttpClient): S3Client;
32
+
33
+ export { type S3Client, type S3Metadata, type UploadRes, createS3Client };
@@ -0,0 +1,33 @@
1
+ import { ClientResult, HttpClient } from '@amaster.ai/http-client';
2
+
3
+ interface UploadRes {
4
+ key: string;
5
+ url: string;
6
+ }
7
+ interface S3Metadata {
8
+ contentType?: string;
9
+ contentLength?: number;
10
+ lastModified?: string;
11
+ [key: string]: any;
12
+ }
13
+ type S3Client = {
14
+ /**
15
+ * Download a file
16
+ * @param filename - The name of the file to download
17
+ */
18
+ download(filename: string): Promise<ClientResult<Blob>>;
19
+ /**
20
+ * Get metadata for a file
21
+ * @param key - The key of the file
22
+ */
23
+ getMetadata(key: string): Promise<ClientResult<S3Metadata>>;
24
+ /**
25
+ * Upload a file
26
+ * @param file - The file to upload (File or Blob)
27
+ */
28
+ upload(file: File | Blob): Promise<ClientResult<UploadRes>>;
29
+ };
30
+
31
+ declare function createS3Client(http?: HttpClient): S3Client;
32
+
33
+ export { type S3Client, type S3Metadata, type UploadRes, createS3Client };
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import {createHttpClient}from'@amaster.ai/http-client';var a="/api/storage";function l(e=createHttpClient()){return {async download(t){return t?await e.request({url:`${a}/download`,method:"get",params:{filename:t},responseType:"blob"}):{data:null,error:{message:"Filename is required",status:400},status:400}},async getMetadata(t){return t?e.request({url:`${a}/metadata`,method:"get",params:{key:t}}):{data:null,error:{message:"Key is required",status:400},status:400}},async upload(t){if(!t)return {data:null,error:{message:"File is required",status:400},status:400};let r=new FormData;return r.append("file",t),e.request({url:`${a}/upload`,method:"post",data:r,headers:{"Content-Type":"multipart/form-data"}})}}}export{l as createS3Client};//# sourceMappingURL=index.js.map
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/s3-client.ts"],"names":["BASE_URL","createS3Client","http","createHttpClient","filename","key","file","formData"],"mappings":"uDAGA,IAAMA,CAAAA,CAAW,cAAA,CAEV,SAASC,CAAAA,CAAeC,CAAAA,CAAmBC,gBAAAA,EAAiB,CAAa,CAC9E,OAAO,CACL,MAAM,QAAA,CAASC,CAAAA,CAA+C,CAC5D,OAAKA,CAAAA,CAQU,MAAMF,EAAK,OAAA,CAAc,CACtC,GAAA,CAAK,CAAA,EAAGF,CAAQ,CAAA,SAAA,CAAA,CAChB,MAAA,CAAQ,KAAA,CACR,OAAQ,CAAE,QAAA,CAAAI,CAAS,CAAA,CACnB,YAAA,CAAc,MAChB,CAAC,CAAA,CAZQ,CACL,IAAA,CAAM,IAAA,CACN,KAAA,CAAO,CAAE,OAAA,CAAS,sBAAA,CAAwB,MAAA,CAAQ,GAAI,EACtD,MAAA,CAAQ,GACV,CAWJ,CAAA,CAEA,MAAM,WAAA,CAAYC,CAAAA,CAAgD,CAChE,OAAKA,CAAAA,CAQEH,CAAAA,CAAK,OAAA,CAAoB,CAC9B,GAAA,CAAK,CAAA,EAAGF,CAAQ,CAAA,SAAA,CAAA,CAChB,OAAQ,KAAA,CACR,MAAA,CAAQ,CAAE,GAAA,CAAAK,CAAI,CAChB,CAAC,CAAA,CAXQ,CACL,IAAA,CAAM,IAAA,CACN,KAAA,CAAO,CAAE,OAAA,CAAS,iBAAA,CAAmB,MAAA,CAAQ,GAAI,EACjD,MAAA,CAAQ,GACV,CAQJ,CAAA,CAEA,MAAM,MAAA,CAAOC,CAAAA,CAAqD,CAChE,GAAI,CAACA,CAAAA,CACH,OAAO,CACL,IAAA,CAAM,IAAA,CACN,KAAA,CAAO,CAAE,QAAS,kBAAA,CAAoB,MAAA,CAAQ,GAAI,CAAA,CAClD,MAAA,CAAQ,GACV,CAAA,CAGF,IAAMC,EAAW,IAAI,QAAA,CACrB,OAAAA,CAAAA,CAAS,MAAA,CAAO,MAAA,CAAQD,CAAI,CAAA,CAErBJ,EAAK,OAAA,CAAmB,CAC7B,GAAA,CAAK,CAAA,EAAGF,CAAQ,CAAA,OAAA,CAAA,CAChB,MAAA,CAAQ,MAAA,CACR,KAAMO,CAAAA,CACN,OAAA,CAAS,CACP,cAAA,CAAgB,qBAClB,CACF,CAAC,CACH,CACF,CACF","file":"index.js","sourcesContent":["import { type ClientResult, createHttpClient, type HttpClient } from \"@amaster.ai/http-client\";\nimport type { S3Client, S3Metadata, UploadRes } from \"./types\";\n\nconst BASE_URL = \"/api/storage\";\n\nexport function createS3Client(http: HttpClient = createHttpClient()): S3Client {\n return {\n async download(filename: string): Promise<ClientResult<Blob>> {\n if (!filename) {\n return {\n data: null,\n error: { message: \"Filename is required\", status: 400 },\n status: 400,\n };\n }\n\n const result = await http.request<Blob>({\n url: `${BASE_URL}/download`,\n method: \"get\",\n params: { filename },\n responseType: \"blob\",\n });\n\n return result;\n },\n\n async getMetadata(key: string): Promise<ClientResult<S3Metadata>> {\n if (!key) {\n return {\n data: null,\n error: { message: \"Key is required\", status: 400 },\n status: 400,\n };\n }\n\n return http.request<S3Metadata>({\n url: `${BASE_URL}/metadata`,\n method: \"get\",\n params: { key },\n });\n },\n\n async upload(file: File | Blob): Promise<ClientResult<UploadRes>> {\n if (!file) {\n return {\n data: null,\n error: { message: \"File is required\", status: 400 },\n status: 400,\n };\n }\n\n const formData = new FormData();\n formData.append(\"file\", file);\n\n return http.request<UploadRes>({\n url: `${BASE_URL}/upload`,\n method: \"post\",\n data: formData,\n headers: {\n \"Content-Type\": \"multipart/form-data\",\n },\n });\n },\n };\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@amaster.ai/s3-client",
3
+ "version": "1.1.0-beta.17",
4
+ "description": "S3 storage client for file upload, download and management",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs",
13
+ "types": "./dist/index.d.ts"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "README.md"
19
+ ],
20
+ "keywords": [
21
+ "s3",
22
+ "storage",
23
+ "client",
24
+ "upload",
25
+ "download",
26
+ "typescript"
27
+ ],
28
+ "author": "Amaster Team",
29
+ "license": "MIT",
30
+ "publishConfig": {
31
+ "access": "public",
32
+ "registry": "https://registry.npmjs.org/"
33
+ },
34
+ "dependencies": {
35
+ "@amaster.ai/http-client": "1.1.0-beta.17"
36
+ },
37
+ "peerDependencies": {
38
+ "axios": "^1.11.0"
39
+ },
40
+ "devDependencies": {
41
+ "axios": "^1.11.0",
42
+ "tsup": "^8.3.5",
43
+ "typescript": "~5.7.2",
44
+ "vitest": "^2.1.8"
45
+ },
46
+ "scripts": {
47
+ "build": "tsup",
48
+ "dev": "tsup --watch",
49
+ "clean": "rm -rf dist *.tsbuildinfo",
50
+ "test": "vitest run",
51
+ "test:watch": "vitest",
52
+ "type-check": "tsc --noEmit"
53
+ }
54
+ }