@rr-vault/r2 1.0.0

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/README.md ADDED
@@ -0,0 +1,117 @@
1
+ # @rr-vault/sdk 🚀
2
+
3
+ **RR-Vault SDK** is a developer-first cloud storage client designed for securely uploading, managing, and delivering files using API keys and app-based access.
4
+
5
+ This SDK acts as a **Secure Thin Client**. Instead of storing cloud credentials (like R2/S3 keys) on the client-side, it proxies all requests through your backend API, ensuring your infrastructure remains 100% private.
6
+
7
+ ---
8
+
9
+ ## 📦 Installation
10
+
11
+ Install the package via npm:
12
+
13
+ ```bash
14
+ npm install @rr-vault/sdk
15
+ ```
16
+
17
+ ---
18
+
19
+ ## ⚡ Quick Start
20
+
21
+ ### 1. Configure the SDK
22
+ Initialize the SDK with your `appId`, `apiKey`, and `secretKey`. These will be sent to your backend with every request for verification.
23
+
24
+ ```typescript
25
+ import { RRVault } from '@rr-vault/sdk';
26
+
27
+ RRVault.config({
28
+ appId: 'your-app-id',
29
+ apiKey: 'your-api-key',
30
+ secretKey: 'your-secret-key'
31
+ });
32
+ ```
33
+
34
+ ### 2. Upload a File
35
+ The SDK sends the file and your credentials to your backend API (`/api/v1/upload`). Your backend then handles the actual storage logic.
36
+
37
+ ```typescript
38
+ try {
39
+ const fileContent = Buffer.from("Hello RR-Vault!"); // Or a File/Blob/Uint8Array
40
+
41
+ const result = await RRVault.upload(fileContent, "myfile.txt", {
42
+ folder: "documents",
43
+ contentType: "text/plain"
44
+ });
45
+
46
+ console.log("Upload Success:", result.url);
47
+ console.log("Storage Key:", result.key);
48
+ } catch (error) {
49
+ console.error("Upload failed:", error.message);
50
+ }
51
+ ```
52
+
53
+ ### 3. Delete a File
54
+ Delete files securely by sending a delete request through your proxy.
55
+
56
+ ```typescript
57
+ const result = await RRVault.delete("documents/171165...-myfile.txt");
58
+
59
+ if (result.success) {
60
+ console.log("File deleted successfully");
61
+ } else {
62
+ console.log("Delete failed:", result.message);
63
+ }
64
+ ```
65
+
66
+ ---
67
+
68
+ ## 🛡️ Security Architecture
69
+ The SDK implements a **Zero-Secret Client Policy**:
70
+ - **No Cloud Keys:** Access Key IDs and Secret Access Keys for R2/S3 are **NEVER** stored in the SDK or frontend code.
71
+ - **Backend Proxy:** All operations (`upload`, `delete`) are routed through your server.
72
+ - **Centralized Validation:** Your backend validates the `appId` and `secretKey` before interacting with the storage provider.
73
+
74
+ ---
75
+
76
+ ## 🛠️ API Reference
77
+
78
+ ### `RRVault.config(options: RRVaultConfig)`
79
+ Sets up the SDK credentials.
80
+ - `appId`: Your application ID.
81
+ - `apiKey`: Your application API key.
82
+ - `secretKey`: Your secret key.
83
+
84
+ ### `RRVault.upload(file, fileName, options?)`
85
+ Uploads a file via your backend proxy.
86
+ - `file`: Buffer, Blob, or Uint8Array.
87
+ - `fileName`: Original name of the file.
88
+ - `options`:
89
+ - `folder`: (Optional) Virtual folder path.
90
+ - `contentType`: (Optional) MIME type.
91
+ - `metadata`: (Optional) Key-value pairs for storage metadata.
92
+
93
+ ### `RRVault.delete(key)`
94
+ Deletes a file by its key via your backend proxy.
95
+ - `key`: The storage key returned during upload.
96
+
97
+ ---
98
+
99
+ ## 📄 Types
100
+
101
+ ```typescript
102
+ export interface UploadResult {
103
+ key: string; // Unique storage path
104
+ url: string; // Public delivery URL
105
+ etag?: string; // entity tag
106
+ }
107
+
108
+ export interface DeleteResult {
109
+ success: boolean;
110
+ message?: string;
111
+ }
112
+ ```
113
+
114
+ ---
115
+
116
+ ## ⚖️ License
117
+ ISC License. Built with ❤️ by Md. Ridoy Babu.
@@ -0,0 +1,5 @@
1
+ import { RRVaultConfig } from "./types.js";
2
+ export declare function setConfig(newConfig: RRVaultConfig): void;
3
+ export declare function getUserConfig(): RRVaultConfig;
4
+ export declare function getApiUrl(): string;
5
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAM3C,wBAAgB,SAAS,CAAC,SAAS,EAAE,aAAa,QAEjD;AAED,wBAAgB,aAAa,IAAI,aAAa,CAO7C;AAED,wBAAgB,SAAS,IAAI,MAAM,CAElC"}
package/dist/config.js ADDED
@@ -0,0 +1,15 @@
1
+ const VALIDATION_API_URL = "http://localhost:8888/api/v1/validate";
2
+ let userConfig = null;
3
+ export function setConfig(newConfig) {
4
+ userConfig = { ...newConfig };
5
+ }
6
+ export function getUserConfig() {
7
+ if (!userConfig) {
8
+ throw new Error("RRVault: SDK not configured. Please call RRVault.config() first.");
9
+ }
10
+ return userConfig;
11
+ }
12
+ export function getApiUrl() {
13
+ return VALIDATION_API_URL;
14
+ }
15
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAEA,MAAM,kBAAkB,GAAG,uCAAuC,CAAC;AAEnE,IAAI,UAAU,GAAyB,IAAI,CAAC;AAE5C,MAAM,UAAU,SAAS,CAAC,SAAwB;IAChD,UAAU,GAAG,EAAE,GAAG,SAAS,EAAE,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,aAAa;IAC3B,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CACb,kEAAkE,CACnE,CAAC;IACJ,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,SAAS;IACvB,OAAO,kBAAkB,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { setConfig } from "./config.js";
2
+ import { upload, deleteFile } from "./s3.js";
3
+ import { RRVaultConfig, UploadOptions, UploadResult, DeleteResult } from "./types.js";
4
+ export declare class RRVault {
5
+ static config(config: RRVaultConfig): void;
6
+ static upload(file: any, fileName: string, options?: UploadOptions): Promise<UploadResult>;
7
+ static delete(key: string): Promise<DeleteResult>;
8
+ }
9
+ export { setConfig as config, upload, deleteFile };
10
+ export type { RRVaultConfig, UploadOptions, UploadResult, DeleteResult };
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEtF,qBAAa,OAAO;IAElB,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa;WAItB,MAAM,CACjB,IAAI,EAAE,GAAG,EACT,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,YAAY,CAAC;WAIX,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;CAGxD;AAED,OAAO,EACL,SAAS,IAAI,MAAM,EACnB,MAAM,EACN,UAAU,EACX,CAAC;AAEF,YAAY,EACV,aAAa,EACb,aAAa,EACb,YAAY,EACZ,YAAY,EACb,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ import { setConfig } from "./config.js";
2
+ import { upload, deleteFile } from "./s3.js";
3
+ export class RRVault {
4
+ static config(config) {
5
+ setConfig(config);
6
+ }
7
+ static async upload(file, fileName, options = {}) {
8
+ return await upload(file, fileName, options);
9
+ }
10
+ static async delete(key) {
11
+ return await deleteFile(key);
12
+ }
13
+ }
14
+ export { setConfig as config, upload, deleteFile };
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAG7C,MAAM,OAAO,OAAO;IAElB,MAAM,CAAC,MAAM,CAAC,MAAqB;QACjC,SAAS,CAAC,MAAM,CAAC,CAAC;IACpB,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM,CACjB,IAAS,EACT,QAAgB,EAChB,UAAyB,EAAE;QAE3B,OAAO,MAAM,MAAM,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAW;QAC7B,OAAO,MAAM,UAAU,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;CACF;AAED,OAAO,EACL,SAAS,IAAI,MAAM,EACnB,MAAM,EACN,UAAU,EACX,CAAC"}
package/dist/s3.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import { UploadOptions, UploadResult, DeleteResult } from "./types.js";
2
+ /**
3
+ * Upload a file to RR-Vault via backend proxy
4
+ */
5
+ export declare function upload(file: any, fileName: string, options?: UploadOptions): Promise<UploadResult>;
6
+ /**
7
+ * Delete a file from RR-Vault via backend proxy
8
+ */
9
+ export declare function deleteFile(key: string): Promise<DeleteResult>;
10
+ //# sourceMappingURL=s3.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"s3.d.ts","sourceRoot":"","sources":["../src/s3.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAGvE;;GAEG;AACH,wBAAsB,MAAM,CAC1B,IAAI,EAAE,GAAG,EACT,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,YAAY,CAAC,CA+BvB;AAED;;GAEG;AACH,wBAAsB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAuBnE"}
package/dist/s3.js ADDED
@@ -0,0 +1,62 @@
1
+ import axios from "axios";
2
+ import { getUserConfig, getApiUrl } from "./config.js";
3
+ /**
4
+ * Upload a file to RR-Vault via backend proxy
5
+ */
6
+ export async function upload(file, fileName, options = {}) {
7
+ const config = getUserConfig();
8
+ const apiUrl = getApiUrl();
9
+ const formData = new FormData();
10
+ formData.append("file", file);
11
+ formData.append("fileName", fileName);
12
+ formData.append("appId", config.appId);
13
+ formData.append("apiKey", config.apiKey);
14
+ formData.append("secretKey", config.secretKey);
15
+ if (options.folder)
16
+ formData.append("folder", options.folder);
17
+ if (options.contentType)
18
+ formData.append("contentType", options.contentType);
19
+ if (options.cacheControl)
20
+ formData.append("cacheControl", options.cacheControl);
21
+ if (options.metadata) {
22
+ formData.append("metadata", JSON.stringify(options.metadata));
23
+ }
24
+ try {
25
+ const response = await axios.post(apiUrl, formData, {
26
+ headers: {
27
+ "Content-Type": "multipart/form-data",
28
+ },
29
+ });
30
+ return response.data;
31
+ }
32
+ catch (error) {
33
+ throw new Error(`RRVault Upload Failed: ${error.response?.data?.message || error.message}`);
34
+ }
35
+ }
36
+ /**
37
+ * Delete a file from RR-Vault via backend proxy
38
+ */
39
+ export async function deleteFile(key) {
40
+ const config = getUserConfig();
41
+ const apiUrl = getApiUrl();
42
+ try {
43
+ const response = await axios({
44
+ method: "DELETE",
45
+ url: apiUrl,
46
+ data: {
47
+ key,
48
+ appId: config.appId,
49
+ apiKey: config.apiKey,
50
+ secretKey: config.secretKey,
51
+ },
52
+ });
53
+ return response.data;
54
+ }
55
+ catch (error) {
56
+ return {
57
+ success: false,
58
+ message: error.response?.data?.message || error.message || "Failed to delete file",
59
+ };
60
+ }
61
+ }
62
+ //# sourceMappingURL=s3.js.map
package/dist/s3.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"s3.js","sourceRoot":"","sources":["../src/s3.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAIvD;;GAE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,IAAI,CAAC;IACvB,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CACb,0BAA0B,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,CAC3E,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,GAAW;IAC1C,MAAM,MAAM,GAAG,aAAa,EAAE,CAAC;IAC/B,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAE3B,IAAI,CAAC;QACH,MAAM,QAAQ,GAAgC,MAAM,KAAK,CAAC;YACxD,MAAM,EAAE,QAAQ;YAChB,GAAG,EAAE,MAAM;YACX,IAAI,EAAE;gBACJ,GAAG;gBACH,KAAK,EAAE,MAAM,CAAC,KAAK;gBACnB,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,SAAS,EAAE,MAAM,CAAC,SAAS;aAC5B;SACF,CAAC,CAAC;QAEH,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,OAAO;YACL,OAAO,EAAE,KAAK;YACd,OAAO,EAAE,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,IAAI,KAAK,CAAC,OAAO,IAAI,uBAAuB;SACnF,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,21 @@
1
+ export interface RRVaultConfig {
2
+ appId: string;
3
+ apiKey: string;
4
+ secretKey: string;
5
+ }
6
+ export interface UploadOptions {
7
+ folder?: string;
8
+ contentType?: string;
9
+ metadata?: Record<string, string>;
10
+ cacheControl?: string;
11
+ }
12
+ export interface UploadResult {
13
+ key: string;
14
+ url: string;
15
+ etag?: string;
16
+ }
17
+ export interface DeleteResult {
18
+ success: boolean;
19
+ message?: string;
20
+ }
21
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CAErB;AAED,MAAM,WAAW,aAAa;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,YAAY;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@rr-vault/r2",
3
+ "version": "1.0.0",
4
+ "description": "\"RR-Vault SDK is a developer-first cloud storage client for securely uploading, managing, and delivering files using API keys, app-based access, and scalable infrastructure.\"",
5
+ "keywords": [],
6
+ "homepage": "https://github.com/mdrezuanislamridoy/rr-vault-sdk#readme",
7
+ "bugs": {
8
+ "url": "https://github.com/mdrezuanislamridoy/rr-vault-sdk/issues"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/mdrezuanislamridoy/rr-vault-sdk.git"
13
+ },
14
+ "license": "ISC",
15
+ "author": "Ridoy781 <ridoy.babu.781@gmail.com>",
16
+ "type": "module",
17
+ "main": "./dist/index.js",
18
+ "types": "./dist/index.d.ts",
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "scripts": {
23
+ "build": "tsc",
24
+ "prepublishOnly": "npm run build",
25
+ "test": "echo \"Error: no test specified\" && exit 1"
26
+ },
27
+
28
+ "devDependencies": {
29
+ "@types/node": "^25.5.0",
30
+ "typescript": "^6.0.2"
31
+ },
32
+ "dependencies": {
33
+ "axios": "^1.14.0"
34
+ }
35
+ }