@rr-vault/sdk 1.0.3 → 1.0.5
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 +115 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +5 -6
- package/dist/config.js.map +1 -1
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
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, app-based access, and scalable infrastructure.
|
|
4
|
+
|
|
5
|
+
Built on top of Cloudflare R2 (S3-compatible), it provides a simplified interface with **Automatic Lazy Validation** against your backend API.
|
|
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` and `secretKey`. These will be validated automatically when you perform your first operation.
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { RRVault } from '@rr-vault/sdk';
|
|
26
|
+
|
|
27
|
+
RRVault.config({
|
|
28
|
+
appId: 'your-app-id',
|
|
29
|
+
secretKey: 'your-secret-key'
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 2. Upload a File
|
|
34
|
+
The validation happens automatically during the first upload. If the credentials are invalid, an error will be thrown.
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
try {
|
|
38
|
+
const fileContent = Buffer.from("Hello RR-Vault!"); // Or a File blob in browser
|
|
39
|
+
|
|
40
|
+
const result = await RRVault.upload(fileContent, "myfile.txt", {
|
|
41
|
+
folder: "documents",
|
|
42
|
+
contentType: "text/plain"
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
console.log("Upload Success:", result.url);
|
|
46
|
+
console.log("Storage Key:", result.key);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.error("Upload failed:", error.message);
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 3. Delete a File
|
|
53
|
+
Delete files using their unique storage key.
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
const result = await RRVault.delete("documents/171165...-myfile.txt");
|
|
57
|
+
|
|
58
|
+
if (result.success) {
|
|
59
|
+
console.log("File deleted successfully");
|
|
60
|
+
} else {
|
|
61
|
+
console.log("Delete failed:", result.message);
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## 🛡️ Automatic Lazy Validation
|
|
68
|
+
The SDK uses a "Lazy Validation" mechanism to stay fast and efficient:
|
|
69
|
+
- `RRVault.config()` only stores credentials locally.
|
|
70
|
+
- The **first call** to `upload()` or `delete()` triggers a validation request to the backend.
|
|
71
|
+
- Results are cached for the duration of the session, so subsequent calls are instantaneous.
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## 🛠️ API Reference
|
|
76
|
+
|
|
77
|
+
### `RRVault.config(options: RRVaultConfig)`
|
|
78
|
+
Sets up the SDK credentials.
|
|
79
|
+
- `appId`: Your application ID.
|
|
80
|
+
- `secretKey`: Your secret key.
|
|
81
|
+
|
|
82
|
+
### `RRVault.upload(file, fileName, options?)`
|
|
83
|
+
Uploads a file to the cloud.
|
|
84
|
+
- `file`: Buffer, Blob, or Uint8Array.
|
|
85
|
+
- `fileName`: Original name of the file.
|
|
86
|
+
- `options`:
|
|
87
|
+
- `folder`: (Optional) Virtual folder path.
|
|
88
|
+
- `contentType`: (Optional) MIME type of the file.
|
|
89
|
+
- `metadata`: (Optional) Key-value pairs for storage metadata.
|
|
90
|
+
|
|
91
|
+
### `RRVault.delete(key)`
|
|
92
|
+
Deletes a file by its key.
|
|
93
|
+
- `key`: The storage key returned during upload.
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## 📄 Types
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
export interface UploadResult {
|
|
101
|
+
key: string; // Unique storage path
|
|
102
|
+
url: string; // Public delivery URL
|
|
103
|
+
etag?: string; // AWS S3 entity tag
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface DeleteResult {
|
|
107
|
+
success: boolean;
|
|
108
|
+
message?: string;
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## ⚖️ License
|
|
115
|
+
ISC License. Built with ❤️ by Md. Ridoy Babu.
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAkBrD,wBAAgB,SAAS,CAAC,SAAS,EAAE,aAAa,QAGjD;AAED,wBAAgB,SAAS,IAAI,QAAQ,CASpC;AAMD;;GAEG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC,CAmBvD;AAED;;;GAGG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC,CAWvD"}
|
package/dist/config.js
CHANGED
|
@@ -4,6 +4,9 @@ const R2_INTERNAL = {
|
|
|
4
4
|
accountId: "cc0a96d7f01e9dd678a07a57dd665897",
|
|
5
5
|
bucketName: "rr-vault",
|
|
6
6
|
publicUrl: "https://pub-52b747d8c2c34c10bc750a3beaaf1ca4.r2.dev",
|
|
7
|
+
// আপনার রিয়াল Cloudflare R2 ক্রেডেনশিয়াল এখানে দিন:
|
|
8
|
+
accessKeyId: "e23c8e4f75168abdd8e2e6af3bf11f4b",
|
|
9
|
+
secretAccessKey: "90bc656fdb5759fa695ada337377481f825eb5aae0981def6a3c69d0394547e9"
|
|
7
10
|
};
|
|
8
11
|
let userConfig = null;
|
|
9
12
|
let validationPerformed = false;
|
|
@@ -16,11 +19,7 @@ export function getConfig() {
|
|
|
16
19
|
throw new Error("RRVault: SDK not configured. Please call RRVault.config() first.");
|
|
17
20
|
}
|
|
18
21
|
// Map user-facing appId/secretKey to internal R2 credentials
|
|
19
|
-
return {
|
|
20
|
-
...R2_INTERNAL,
|
|
21
|
-
accessKeyId: userConfig.appId,
|
|
22
|
-
secretAccessKey: userConfig.secretKey,
|
|
23
|
-
};
|
|
22
|
+
return { ...R2_INTERNAL };
|
|
24
23
|
}
|
|
25
24
|
/**
|
|
26
25
|
* Validates the configuration by hitting an external API.
|
|
@@ -35,7 +34,7 @@ export async function validateConfig() {
|
|
|
35
34
|
secretKey: userConfig.secretKey,
|
|
36
35
|
});
|
|
37
36
|
// Expecting response format: { valid: boolean }
|
|
38
|
-
return response.status === 200 && response.data.valid === true;
|
|
37
|
+
return (response.status === 200 || response.status === 201) && response.data.valid === true;
|
|
39
38
|
}
|
|
40
39
|
catch (error) {
|
|
41
40
|
console.error("RRVault Validation Error:", error.message);
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,kBAAkB,GAAG,uCAAuC,CAAC;AAEnE,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE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AC,CAAC;QAC1D,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB;IACrC,IAAI,mBAAmB;QAAE,OAAO;IAEhC,MAAM,OAAO,GAAG,MAAM,cAAc,EAAE,CAAC;IACvC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,kFAAkF,CACnF,CAAC;IACJ,CAAC;IAED,mBAAmB,GAAG,IAAI,CAAC;AAC7B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rr-vault/sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
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
5
|
"keywords": [],
|
|
6
6
|
"homepage": "https://github.com/mdrezuanislamridoy/rr-vault-sdk#readme",
|