@cloudizero/sdk 0.0.0-stage → 0.2.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 +207 -2
- package/dist/client.d.ts +15 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +17 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +6 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +12 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/projects.d.ts +17 -0
- package/dist/projects.d.ts.map +1 -0
- package/dist/projects.js +56 -0
- package/dist/projects.js.map +1 -0
- package/dist/storage.d.ts +65 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +362 -0
- package/dist/storage.js.map +1 -0
- package/dist/types.d.ts +248 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +40 -4
package/README.md
CHANGED
|
@@ -1,3 +1,208 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @cloudizero/sdk
|
|
2
|
+
|
|
3
|
+
> Official TypeScript SDK for the **Cloudizero** Zero-Egress Digital Asset Management & Media Delivery Platform.
|
|
4
|
+
|
|
5
|
+
Seamlessly upload, manage, and deliver media files and virtual folders directly to Cloudflare R2 storage with zero bandwidth egress penalties and instant relational indexing.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 📦 Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @cloudizero/sdk
|
|
13
|
+
# or
|
|
14
|
+
pnpm add @cloudizero/sdk
|
|
15
|
+
# or
|
|
16
|
+
yarn add @cloudizero/sdk
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 🚀 Quick Start
|
|
22
|
+
|
|
23
|
+
### 1. Initialize Client
|
|
24
|
+
|
|
25
|
+
Generate an API Key in your Cloudizero dashboard (`/api-keys`), then initialize the SDK:
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { Cloudizero } from "@cloudizero/sdk";
|
|
29
|
+
|
|
30
|
+
// 1. Zero-config (reads CLOUDIZERO_API_KEY from environment, defaults to https://api-cloudizero.wismannur.pro)
|
|
31
|
+
const cz = new Cloudizero();
|
|
32
|
+
|
|
33
|
+
// 2. Or explicit configuration (overriding baseUrl / cdnUrl if needed):
|
|
34
|
+
const czCustom = new Cloudizero({
|
|
35
|
+
apiKey: process.env.CLOUDIZERO_API_KEY!, // e.g. "cz_live_9f8a..."
|
|
36
|
+
baseUrl: "https://api-cloudizero.wismannur.pro", // default
|
|
37
|
+
cdnUrl: "https://cdn-cloudizero.wismannur.pro", // default
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## 📂 File CRUD Operations
|
|
44
|
+
|
|
45
|
+
### 1. Create / Upload File (`upload`)
|
|
46
|
+
|
|
47
|
+
#### Direct File Upload (Node.js / Next.js / Express)
|
|
48
|
+
Upload buffers, byte arrays, or streams directly from your backend services:
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import fs from "fs";
|
|
52
|
+
|
|
53
|
+
const fileBuffer = fs.readFileSync("./avatar.png");
|
|
54
|
+
|
|
55
|
+
const uploaded = await cz.storage.upload({
|
|
56
|
+
file: fileBuffer,
|
|
57
|
+
fileName: "avatar.png",
|
|
58
|
+
projectId: "ca2454ff-7f1e-421b-b134-4c800f6d58de",
|
|
59
|
+
folderId: "3b9c1e2a-...", // optional target Folder ID (or omit for root)
|
|
60
|
+
mimeType: "image/png",
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
console.log("Uploaded successfully!");
|
|
64
|
+
console.log("File ID:", uploaded.id);
|
|
65
|
+
console.log("R2 Key:", uploaded.r2Key);
|
|
66
|
+
console.log("Public URL:", uploaded.url);
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
#### Browser Upload with Real-time Progress (React / Vue / Vanilla JS)
|
|
70
|
+
```typescript
|
|
71
|
+
const handleFileInput = async (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
72
|
+
const file = event.target.files?.[0];
|
|
73
|
+
if (!file) return;
|
|
74
|
+
|
|
75
|
+
const result = await cz.storage.upload({
|
|
76
|
+
file,
|
|
77
|
+
fileName: file.name,
|
|
78
|
+
projectId: "your-project-id",
|
|
79
|
+
mimeType: file.type,
|
|
80
|
+
onProgress: ({ loaded, total, percent }) => {
|
|
81
|
+
console.log(`Upload progress: ${percent}% (${loaded}/${total} bytes)`);
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
console.log("Public CDN link:", result.url);
|
|
86
|
+
};
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 2. Read File Details (`getFile`)
|
|
90
|
+
|
|
91
|
+
Retrieve file metadata along with a temporary presigned download URL:
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
const { file, downloadUrl } = await cz.storage.getFile("file-id-here");
|
|
95
|
+
console.log("File metadata:", file);
|
|
96
|
+
console.log("Presigned download URL:", downloadUrl);
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### 3. Update File Metadata or Replace Binary (`updateFile` & `replaceFile`)
|
|
100
|
+
|
|
101
|
+
#### Update Metadata (Rename / Move Folder / Trash)
|
|
102
|
+
Renaming a file or moving it to another folder automatically moves the underlying object in Cloudflare R2 so the human-readable `r2Key` and CDN URL stay synchronized:
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
const updated = await cz.storage.updateFile({
|
|
106
|
+
fileId: "file-id-here",
|
|
107
|
+
name: "new-avatar-name.png",
|
|
108
|
+
folderId: "target-folder-id", // or null / "root" to move to project root
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
console.log("Updated R2 Key:", updated.r2Key);
|
|
112
|
+
console.log("Updated CDN URL:", updated.url);
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
#### Replace File Binary In-Place (`replaceFile`)
|
|
116
|
+
Overwrite an existing file's binary content while preserving its `fileId` (and optionally updating its filename or MIME type):
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
const newBuffer = fs.readFileSync("./avatar-v2.webp");
|
|
120
|
+
|
|
121
|
+
const replaced = await cz.storage.replaceFile({
|
|
122
|
+
fileId: "file-id-here",
|
|
123
|
+
file: newBuffer,
|
|
124
|
+
fileName: "avatar-v2.webp", // optional: omit to keep existing filename & R2 key
|
|
125
|
+
mimeType: "image/webp",
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
console.log("Replaced file URL:", replaced.url);
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### 4. Delete File (`deleteFile`)
|
|
132
|
+
|
|
133
|
+
Permanently delete a file from both Cloudflare R2 and Neon PostgreSQL:
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
await cz.storage.deleteFile("file-id-here");
|
|
137
|
+
console.log("File permanently removed from R2 & DB");
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## 📁 Folder CRUD Operations
|
|
143
|
+
|
|
144
|
+
### 1. Create Folder (`createFolder`)
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
const folder = await cz.storage.createFolder({
|
|
148
|
+
projectId: "your-project-id",
|
|
149
|
+
name: "Marketing Banners",
|
|
150
|
+
parentId: null, // optional parent folder ID for nested folders
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
console.log("Created folder:", folder.id, folder.path); // e.g. "/marketing-banners"
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### 2. Read & List Folders (`getFolder`, `listFolders`, `listContents`)
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
// Get a single folder by ID
|
|
160
|
+
const folderInfo = await cz.storage.getFolder("folder-id-here");
|
|
161
|
+
|
|
162
|
+
// List folders in project root (or pass parentId for subfolders)
|
|
163
|
+
const folders = await cz.storage.listFolders({
|
|
164
|
+
projectId: "your-project-id",
|
|
165
|
+
parentId: "root",
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
// List both folders, files, and breadcrumbs in a directory
|
|
169
|
+
const contents = await cz.storage.listContents({
|
|
170
|
+
projectId: "your-project-id",
|
|
171
|
+
folderId: folder.id, // or omit for root
|
|
172
|
+
});
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### 3. Update Folder (`updateFolder`)
|
|
176
|
+
|
|
177
|
+
Rename a folder or move it under a new parent folder. All nested subfolder paths and underlying Cloudflare R2 keys for files inside the folder tree are updated automatically:
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
const updatedFolder = await cz.storage.updateFolder({
|
|
181
|
+
folderId: "folder-id-here",
|
|
182
|
+
name: "Q4 Campaigns",
|
|
183
|
+
parentId: "parent-folder-id", // or null / "root"
|
|
184
|
+
});
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### 4. Delete Folder (`deleteFolder`)
|
|
188
|
+
|
|
189
|
+
Recursively deletes a folder, all its subfolders, and permanently removes all contained files from Cloudflare R2 and Neon DB:
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
const result = await cz.storage.deleteFolder("folder-id-here");
|
|
193
|
+
console.log(`Deleted ${result.deletedFoldersCount} folders and ${result.deletedFilesCount} files`);
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
## 🔒 Security Best Practice
|
|
199
|
+
|
|
200
|
+
* **Secret API Key (`cz_live_...`)**: Keep in server-side environment variables (`process.env.CLOUDIZERO_API_KEY`).
|
|
201
|
+
* **Project Restrictions**: When generating an API key, you can restrict it to specific projects to follow the principle of least privilege.
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## 📄 License
|
|
206
|
+
|
|
207
|
+
MIT © [Wisman Nur](https://wismannur.pro)
|
|
2
208
|
|
|
3
|
-
This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CloudizeroConfig } from "./types.js";
|
|
2
|
+
import { StorageClient } from "./storage.js";
|
|
3
|
+
import { ProjectsClient } from "./projects.js";
|
|
4
|
+
export declare class Cloudizero {
|
|
5
|
+
/**
|
|
6
|
+
* Media Storage & Ingestion methods
|
|
7
|
+
*/
|
|
8
|
+
readonly storage: StorageClient;
|
|
9
|
+
/**
|
|
10
|
+
* Project Management methods
|
|
11
|
+
*/
|
|
12
|
+
readonly projects: ProjectsClient;
|
|
13
|
+
constructor(config?: CloudizeroConfig);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,qBAAa,UAAU;IACrB;;OAEG;IACH,SAAgB,OAAO,EAAE,aAAa,CAAC;IAEvC;;OAEG;IACH,SAAgB,QAAQ,EAAE,cAAc,CAAC;gBAE7B,MAAM,GAAE,gBAAqB;CAI1C"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { StorageClient } from "./storage.js";
|
|
2
|
+
import { ProjectsClient } from "./projects.js";
|
|
3
|
+
export class Cloudizero {
|
|
4
|
+
/**
|
|
5
|
+
* Media Storage & Ingestion methods
|
|
6
|
+
*/
|
|
7
|
+
storage;
|
|
8
|
+
/**
|
|
9
|
+
* Project Management methods
|
|
10
|
+
*/
|
|
11
|
+
projects;
|
|
12
|
+
constructor(config = {}) {
|
|
13
|
+
this.storage = new StorageClient(config);
|
|
14
|
+
this.projects = new ProjectsClient(config);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,MAAM,OAAO,UAAU;IACrB;;OAEG;IACa,OAAO,CAAgB;IAEvC;;OAEG;IACa,QAAQ,CAAiB;IAEzC,YAAY,SAA2B,EAAE;QACvC,IAAI,CAAC,OAAO,GAAG,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;QACzC,IAAI,CAAC,QAAQ,GAAG,IAAI,cAAc,CAAC,MAAM,CAAC,CAAC;IAC7C,CAAC;CACF"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,eAAgB,SAAQ,KAAK;IACxC,SAAgB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChC,SAAgB,OAAO,CAAC,EAAE,OAAO,CAAC;gBAEtB,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;CAOhE"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export class CloudizeroError extends Error {
|
|
2
|
+
status;
|
|
3
|
+
details;
|
|
4
|
+
constructor(message, status, details) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = "CloudizeroError";
|
|
7
|
+
this.status = status;
|
|
8
|
+
this.details = details;
|
|
9
|
+
Object.setPrototypeOf(this, CloudizeroError.prototype);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACxB,MAAM,CAAU;IAChB,OAAO,CAAW;IAElC,YAAY,OAAe,EAAE,MAAe,EAAE,OAAiB;QAC7D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;IACzD,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { Cloudizero } from "./client.js";
|
|
2
|
+
export { StorageClient } from "./storage.js";
|
|
3
|
+
export { ProjectsClient } from "./projects.js";
|
|
4
|
+
export { CloudizeroError } from "./errors.js";
|
|
5
|
+
export type { CloudizeroConfig, UploadOptions, UpdateFileOptions, ReplaceFileOptions, UploadedFile, StorageFolder, CreateFolderOptions, ListFoldersOptions, UpdateFolderOptions, DeleteFolderResult, StorageContents, UploadPayload, Project, CreateProjectOptions, } from "./types.js";
|
|
6
|
+
//# 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,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,YAAY,EACV,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,OAAO,EACP,oBAAoB,GACrB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CloudizeroConfig, Project, CreateProjectOptions } from "./types.js";
|
|
2
|
+
export declare class ProjectsClient {
|
|
3
|
+
private readonly apiKey;
|
|
4
|
+
private readonly baseUrl;
|
|
5
|
+
constructor(config?: CloudizeroConfig);
|
|
6
|
+
/**
|
|
7
|
+
* [READ] Lists all accessible projects for the authenticated API key.
|
|
8
|
+
* If the API key is scoped to specific projects, only scoped projects are returned.
|
|
9
|
+
*/
|
|
10
|
+
list(): Promise<Project[]>;
|
|
11
|
+
/**
|
|
12
|
+
* [CREATE] Creates a new project.
|
|
13
|
+
* Requires an API key with Full Workspace Access (not scoped to specific projects).
|
|
14
|
+
*/
|
|
15
|
+
create(options: CreateProjectOptions): Promise<Project>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=projects.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projects.d.ts","sourceRoot":"","sources":["../src/projects.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAG7E,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,MAAM,GAAE,gBAAqB;IAuBzC;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAmBhC;;;OAGG;IACG,MAAM,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,OAAO,CAAC;CAqB9D"}
|
package/dist/projects.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { CloudizeroError } from "./errors.js";
|
|
2
|
+
export class ProjectsClient {
|
|
3
|
+
apiKey;
|
|
4
|
+
baseUrl;
|
|
5
|
+
constructor(config = {}) {
|
|
6
|
+
const resolvedApiKey = config.apiKey ||
|
|
7
|
+
(typeof process !== "undefined" && process.env?.CLOUDIZERO_API_KEY
|
|
8
|
+
? process.env.CLOUDIZERO_API_KEY
|
|
9
|
+
: "");
|
|
10
|
+
if (!resolvedApiKey) {
|
|
11
|
+
throw new CloudizeroError("Cloudizero API key is required. Pass it via config { apiKey: 'cz_live_...' } or define CLOUDIZERO_API_KEY in your environment.");
|
|
12
|
+
}
|
|
13
|
+
const resolvedBaseUrl = config.baseUrl ||
|
|
14
|
+
(typeof process !== "undefined" && process.env?.CLOUDIZERO_BASE_URL
|
|
15
|
+
? process.env.CLOUDIZERO_BASE_URL
|
|
16
|
+
: "https://api-cloudizero.wismannur.pro");
|
|
17
|
+
this.apiKey = resolvedApiKey;
|
|
18
|
+
this.baseUrl = resolvedBaseUrl.replace(/\/+$/, "");
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* [READ] Lists all accessible projects for the authenticated API key.
|
|
22
|
+
* If the API key is scoped to specific projects, only scoped projects are returned.
|
|
23
|
+
*/
|
|
24
|
+
async list() {
|
|
25
|
+
const res = await fetch(`${this.baseUrl}/api/projects`, {
|
|
26
|
+
headers: {
|
|
27
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
if (!res.ok) {
|
|
31
|
+
const err = await res.json().catch(() => ({}));
|
|
32
|
+
throw new CloudizeroError(err.error || `Failed to list projects (${res.status})`, res.status, err);
|
|
33
|
+
}
|
|
34
|
+
return res.json();
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* [CREATE] Creates a new project.
|
|
38
|
+
* Requires an API key with Full Workspace Access (not scoped to specific projects).
|
|
39
|
+
*/
|
|
40
|
+
async create(options) {
|
|
41
|
+
const res = await fetch(`${this.baseUrl}/api/projects`, {
|
|
42
|
+
method: "POST",
|
|
43
|
+
headers: {
|
|
44
|
+
"Content-Type": "application/json",
|
|
45
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
46
|
+
},
|
|
47
|
+
body: JSON.stringify(options),
|
|
48
|
+
});
|
|
49
|
+
if (!res.ok) {
|
|
50
|
+
const err = await res.json().catch(() => ({}));
|
|
51
|
+
throw new CloudizeroError(err.error || `Failed to create project (${res.status})`, res.status, err);
|
|
52
|
+
}
|
|
53
|
+
return res.json();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=projects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projects.js","sourceRoot":"","sources":["../src/projects.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,OAAO,cAAc;IACR,MAAM,CAAS;IACf,OAAO,CAAS;IAEjC,YAAY,SAA2B,EAAE;QACvC,MAAM,cAAc,GAClB,MAAM,CAAC,MAAM;YACb,CAAC,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,EAAE,kBAAkB;gBAChE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB;gBAChC,CAAC,CAAC,EAAE,CAAC,CAAC;QAEV,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,MAAM,IAAI,eAAe,CACvB,gIAAgI,CACjI,CAAC;QACJ,CAA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AC,CAAC;QAEH,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;YACZ,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YAC/C,MAAM,IAAI,eAAe,CACvB,GAAG,CAAC,KAAK,IAAI,6BAA6B,GAAG,CAAC,MAAM,GAAG,EACvD,GAAG,CAAC,MAAM,EACV,GAAG,CACJ,CAAC;QACJ,CAAC;QAED,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC;IACpB,CAAC;CACF"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { CloudizeroConfig, UploadOptions, UpdateFileOptions, ReplaceFileOptions, UploadedFile, StorageFolder, CreateFolderOptions, ListFoldersOptions, UpdateFolderOptions, DeleteFolderResult, StorageContents } from "./types.js";
|
|
2
|
+
export declare class StorageClient {
|
|
3
|
+
private readonly apiKey;
|
|
4
|
+
private readonly baseUrl;
|
|
5
|
+
private readonly cdnUrl?;
|
|
6
|
+
constructor(config?: CloudizeroConfig);
|
|
7
|
+
/**
|
|
8
|
+
* [CREATE] Uploads a file directly to Cloudflare R2 via presigned PUT URL and records metadata.
|
|
9
|
+
*/
|
|
10
|
+
upload(options: UploadOptions): Promise<UploadedFile>;
|
|
11
|
+
/**
|
|
12
|
+
* [READ] Gets file details and generates a presigned private download URL
|
|
13
|
+
*/
|
|
14
|
+
getFile(fileId: string): Promise<{
|
|
15
|
+
file: UploadedFile;
|
|
16
|
+
downloadUrl: string;
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* [UPDATE] Updates file metadata (rename, move folder, trash toggle) and/or replaces its binary content in R2.
|
|
20
|
+
* When renaming or moving folders, the underlying R2 object key is automatically moved to stay in sync.
|
|
21
|
+
*/
|
|
22
|
+
updateFile(options: UpdateFileOptions): Promise<UploadedFile>;
|
|
23
|
+
/**
|
|
24
|
+
* [UPDATE - BINARY REPLACE] Replaces the binary content of an existing file while preserving its fileId.
|
|
25
|
+
* Optionally updates the file name, folder, MIME type, or dimensions.
|
|
26
|
+
*/
|
|
27
|
+
replaceFile(options: ReplaceFileOptions): Promise<UploadedFile>;
|
|
28
|
+
/**
|
|
29
|
+
* [DELETE] Deletes a file permanently from Cloudflare R2 and Neon DB
|
|
30
|
+
*/
|
|
31
|
+
deleteFile(fileId: string): Promise<{
|
|
32
|
+
success: boolean;
|
|
33
|
+
message: string;
|
|
34
|
+
}>;
|
|
35
|
+
/**
|
|
36
|
+
* [CREATE] Creates a new virtual folder within a project
|
|
37
|
+
*/
|
|
38
|
+
createFolder(options: CreateFolderOptions): Promise<StorageFolder>;
|
|
39
|
+
/**
|
|
40
|
+
* [READ] Gets a single folder by its ID
|
|
41
|
+
*/
|
|
42
|
+
getFolder(folderId: string): Promise<StorageFolder>;
|
|
43
|
+
/**
|
|
44
|
+
* [READ] Lists folders within a project (or inside a specific parent folder)
|
|
45
|
+
*/
|
|
46
|
+
listFolders(options: ListFoldersOptions): Promise<StorageFolder[]>;
|
|
47
|
+
/**
|
|
48
|
+
* [UPDATE] Renames or moves a folder, recursively updating paths and R2 object keys for all nested files
|
|
49
|
+
*/
|
|
50
|
+
updateFolder(options: UpdateFolderOptions): Promise<StorageFolder>;
|
|
51
|
+
/**
|
|
52
|
+
* [DELETE] Deletes a folder and recursively removes all nested subfolders and files from R2 and Neon DB
|
|
53
|
+
*/
|
|
54
|
+
deleteFolder(folderId: string): Promise<DeleteFolderResult>;
|
|
55
|
+
/**
|
|
56
|
+
* Lists folders and files in a directory
|
|
57
|
+
*/
|
|
58
|
+
listContents(params: {
|
|
59
|
+
projectId: string;
|
|
60
|
+
folderId?: string;
|
|
61
|
+
}): Promise<StorageContents>;
|
|
62
|
+
private getByteLength;
|
|
63
|
+
private uploadBinary;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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C,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,aAAa,CAAC;IA8BxE;;OAEG;IACG,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IA2BjE;;OAEG;IACG,YAAY,CAAC,MAAM,EAAE;QACzB,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,GAAG,OAAO,CAAC,eAAe,CAAC;IA+B5B,OAAO,CAAC,aAAa;YAeP,YAAY;CA+D3B"}
|
package/dist/storage.js
ADDED
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import { CloudizeroError } from "./errors.js";
|
|
2
|
+
export class StorageClient {
|
|
3
|
+
apiKey;
|
|
4
|
+
baseUrl;
|
|
5
|
+
cdnUrl;
|
|
6
|
+
constructor(config = {}) {
|
|
7
|
+
const resolvedApiKey = config.apiKey ||
|
|
8
|
+
(typeof process !== "undefined" && process.env?.CLOUDIZERO_API_KEY
|
|
9
|
+
? process.env.CLOUDIZERO_API_KEY
|
|
10
|
+
: "");
|
|
11
|
+
if (!resolvedApiKey) {
|
|
12
|
+
throw new CloudizeroError("Cloudizero API key is required. Pass it via config { apiKey: 'cz_live_...' } or define CLOUDIZERO_API_KEY in your environment.");
|
|
13
|
+
}
|
|
14
|
+
const resolvedBaseUrl = config.baseUrl ||
|
|
15
|
+
(typeof process !== "undefined" && process.env?.CLOUDIZERO_BASE_URL
|
|
16
|
+
? process.env.CLOUDIZERO_BASE_URL
|
|
17
|
+
: "https://api-cloudizero.wismannur.pro");
|
|
18
|
+
const resolvedCdnUrl = config.cdnUrl ||
|
|
19
|
+
(typeof process !== "undefined" && process.env?.CLOUDIZERO_CDN_URL
|
|
20
|
+
? process.env.CLOUDIZERO_CDN_URL
|
|
21
|
+
: "https://cdn-cloudizero.wismannur.pro");
|
|
22
|
+
this.apiKey = resolvedApiKey;
|
|
23
|
+
this.baseUrl = resolvedBaseUrl.replace(/\/+$/, "");
|
|
24
|
+
this.cdnUrl = resolvedCdnUrl ? resolvedCdnUrl.replace(/\/+$/, "") : undefined;
|
|
25
|
+
}
|
|
26
|
+
// ==========================================
|
|
27
|
+
// FILE CRUD OPERATIONS
|
|
28
|
+
// ==========================================
|
|
29
|
+
/**
|
|
30
|
+
* [CREATE] Uploads a file directly to Cloudflare R2 via presigned PUT URL and records metadata.
|
|
31
|
+
*/
|
|
32
|
+
async upload(options) {
|
|
33
|
+
const { file, fileName, projectId, folderId, mimeType = "application/octet-stream", width, height, onProgress, } = options;
|
|
34
|
+
const fileSize = this.getByteLength(file);
|
|
35
|
+
// 1. Request Presigned Upload Ticket
|
|
36
|
+
const presignRes = await fetch(`${this.baseUrl}/api/storage/presign`, {
|
|
37
|
+
method: "POST",
|
|
38
|
+
headers: {
|
|
39
|
+
"Content-Type": "application/json",
|
|
40
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
41
|
+
},
|
|
42
|
+
body: JSON.stringify({
|
|
43
|
+
projectId,
|
|
44
|
+
folderId: folderId && folderId !== "root" ? folderId : null,
|
|
45
|
+
fileName,
|
|
46
|
+
mimeType,
|
|
47
|
+
fileSize,
|
|
48
|
+
}),
|
|
49
|
+
});
|
|
50
|
+
if (!presignRes.ok) {
|
|
51
|
+
const err = await presignRes.json().catch(() => ({}));
|
|
52
|
+
throw new CloudizeroError(err.error || `Presign failed with status ${presignRes.status}`, presignRes.status, err);
|
|
53
|
+
}
|
|
54
|
+
const { uploadUrl, r2Key, fileId, finalFileName } = await presignRes.json();
|
|
55
|
+
// 2. Direct S3 PUT Upload to Cloudflare R2
|
|
56
|
+
await this.uploadBinary(uploadUrl, file, mimeType, onProgress);
|
|
57
|
+
// 3. Record Metadata in Cloudizero
|
|
58
|
+
const completeRes = await fetch(`${this.baseUrl}/api/storage/complete`, {
|
|
59
|
+
method: "POST",
|
|
60
|
+
headers: {
|
|
61
|
+
"Content-Type": "application/json",
|
|
62
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
63
|
+
},
|
|
64
|
+
body: JSON.stringify({
|
|
65
|
+
fileId,
|
|
66
|
+
projectId,
|
|
67
|
+
folderId: folderId && folderId !== "root" ? folderId : null,
|
|
68
|
+
name: finalFileName || fileName,
|
|
69
|
+
mimeType,
|
|
70
|
+
size: fileSize,
|
|
71
|
+
width: width || null,
|
|
72
|
+
height: height || null,
|
|
73
|
+
r2Key,
|
|
74
|
+
}),
|
|
75
|
+
});
|
|
76
|
+
if (!completeRes.ok) {
|
|
77
|
+
const err = await completeRes.json().catch(() => ({}));
|
|
78
|
+
throw new CloudizeroError(err.error || `Recording file metadata failed with status ${completeRes.status}`, completeRes.status, err);
|
|
79
|
+
}
|
|
80
|
+
const recordedFile = await completeRes.json();
|
|
81
|
+
if (this.cdnUrl) {
|
|
82
|
+
recordedFile.url = `${this.cdnUrl}/${recordedFile.r2Key}`;
|
|
83
|
+
}
|
|
84
|
+
return recordedFile;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* [READ] Gets file details and generates a presigned private download URL
|
|
88
|
+
*/
|
|
89
|
+
async getFile(fileId) {
|
|
90
|
+
const res = await fetch(`${this.baseUrl}/api/storage/files?fileId=${encodeURIComponent(fileId)}`, {
|
|
91
|
+
headers: {
|
|
92
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
if (!res.ok) {
|
|
96
|
+
const err = await res.json().catch(() => ({}));
|
|
97
|
+
throw new CloudizeroError(err.error || `Failed to get file (${res.status})`, res.status, err);
|
|
98
|
+
}
|
|
99
|
+
const data = await res.json();
|
|
100
|
+
if (this.cdnUrl && data.file) {
|
|
101
|
+
data.file.url = `${this.cdnUrl}/${data.file.r2Key}`;
|
|
102
|
+
}
|
|
103
|
+
return data;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* [UPDATE] Updates file metadata (rename, move folder, trash toggle) and/or replaces its binary content in R2.
|
|
107
|
+
* When renaming or moving folders, the underlying R2 object key is automatically moved to stay in sync.
|
|
108
|
+
*/
|
|
109
|
+
async updateFile(options) {
|
|
110
|
+
const { fileId, name, folderId, isTrash, file, mimeType, width, height, onProgress, } = options;
|
|
111
|
+
const isReplacingBinary = file !== undefined;
|
|
112
|
+
const size = isReplacingBinary ? this.getByteLength(file) : undefined;
|
|
113
|
+
const res = await fetch(`${this.baseUrl}/api/storage/files`, {
|
|
114
|
+
method: "PATCH",
|
|
115
|
+
headers: {
|
|
116
|
+
"Content-Type": "application/json",
|
|
117
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
118
|
+
},
|
|
119
|
+
body: JSON.stringify({
|
|
120
|
+
fileId,
|
|
121
|
+
...(name !== undefined ? { name } : {}),
|
|
122
|
+
...(folderId !== undefined
|
|
123
|
+
? { folderId: folderId && folderId !== "root" ? folderId : null }
|
|
124
|
+
: {}),
|
|
125
|
+
...(isTrash !== undefined ? { isTrash } : {}),
|
|
126
|
+
...(mimeType !== undefined ? { mimeType } : {}),
|
|
127
|
+
...(size !== undefined ? { size } : {}),
|
|
128
|
+
...(width !== undefined ? { width } : {}),
|
|
129
|
+
...(height !== undefined ? { height } : {}),
|
|
130
|
+
...(isReplacingBinary ? { requestReplaceUploadUrl: true } : {}),
|
|
131
|
+
}),
|
|
132
|
+
});
|
|
133
|
+
if (!res.ok) {
|
|
134
|
+
const err = await res.json().catch(() => ({}));
|
|
135
|
+
throw new CloudizeroError(err.error || `Failed to update file (${res.status})`, res.status, err);
|
|
136
|
+
}
|
|
137
|
+
const data = await res.json();
|
|
138
|
+
if (isReplacingBinary && data.uploadUrl) {
|
|
139
|
+
await this.uploadBinary(data.uploadUrl, file, mimeType || data.file.mimeType || "application/octet-stream", onProgress);
|
|
140
|
+
}
|
|
141
|
+
if (this.cdnUrl && data.file) {
|
|
142
|
+
data.file.url = `${this.cdnUrl}/${data.file.r2Key}`;
|
|
143
|
+
}
|
|
144
|
+
return data.file;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* [UPDATE - BINARY REPLACE] Replaces the binary content of an existing file while preserving its fileId.
|
|
148
|
+
* Optionally updates the file name, folder, MIME type, or dimensions.
|
|
149
|
+
*/
|
|
150
|
+
async replaceFile(options) {
|
|
151
|
+
return this.updateFile({
|
|
152
|
+
fileId: options.fileId,
|
|
153
|
+
file: options.file,
|
|
154
|
+
name: options.fileName,
|
|
155
|
+
folderId: options.folderId,
|
|
156
|
+
mimeType: options.mimeType,
|
|
157
|
+
width: options.width,
|
|
158
|
+
height: options.height,
|
|
159
|
+
onProgress: options.onProgress,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* [DELETE] Deletes a file permanently from Cloudflare R2 and Neon DB
|
|
164
|
+
*/
|
|
165
|
+
async deleteFile(fileId) {
|
|
166
|
+
const res = await fetch(`${this.baseUrl}/api/storage/files?fileId=${encodeURIComponent(fileId)}`, {
|
|
167
|
+
method: "DELETE",
|
|
168
|
+
headers: {
|
|
169
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
if (!res.ok) {
|
|
173
|
+
const err = await res.json().catch(() => ({}));
|
|
174
|
+
throw new CloudizeroError(err.error || `Failed to delete file (${res.status})`, res.status, err);
|
|
175
|
+
}
|
|
176
|
+
return res.json();
|
|
177
|
+
}
|
|
178
|
+
// ==========================================
|
|
179
|
+
// FOLDER CRUD OPERATIONS
|
|
180
|
+
// ==========================================
|
|
181
|
+
/**
|
|
182
|
+
* [CREATE] Creates a new virtual folder within a project
|
|
183
|
+
*/
|
|
184
|
+
async createFolder(options) {
|
|
185
|
+
const { projectId, name, parentId, path } = options;
|
|
186
|
+
const res = await fetch(`${this.baseUrl}/api/storage/folders`, {
|
|
187
|
+
method: "POST",
|
|
188
|
+
headers: {
|
|
189
|
+
"Content-Type": "application/json",
|
|
190
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
191
|
+
},
|
|
192
|
+
body: JSON.stringify({
|
|
193
|
+
projectId,
|
|
194
|
+
name,
|
|
195
|
+
parentId: parentId && parentId !== "root" ? parentId : null,
|
|
196
|
+
...(path ? { path } : {}),
|
|
197
|
+
}),
|
|
198
|
+
});
|
|
199
|
+
if (!res.ok) {
|
|
200
|
+
const err = await res.json().catch(() => ({}));
|
|
201
|
+
throw new CloudizeroError(err.error || `Failed to create folder (${res.status})`, res.status, err);
|
|
202
|
+
}
|
|
203
|
+
return res.json();
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* [READ] Gets a single folder by its ID
|
|
207
|
+
*/
|
|
208
|
+
async getFolder(folderId) {
|
|
209
|
+
const res = await fetch(`${this.baseUrl}/api/storage/folders?folderId=${encodeURIComponent(folderId)}`, {
|
|
210
|
+
headers: {
|
|
211
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
if (!res.ok) {
|
|
215
|
+
const err = await res.json().catch(() => ({}));
|
|
216
|
+
throw new CloudizeroError(err.error || `Failed to get folder (${res.status})`, res.status, err);
|
|
217
|
+
}
|
|
218
|
+
return res.json();
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* [READ] Lists folders within a project (or inside a specific parent folder)
|
|
222
|
+
*/
|
|
223
|
+
async listFolders(options) {
|
|
224
|
+
const { projectId, parentId = "root" } = options;
|
|
225
|
+
const targetParent = parentId || "root";
|
|
226
|
+
const res = await fetch(`${this.baseUrl}/api/storage/folders?projectId=${encodeURIComponent(projectId)}&parentId=${encodeURIComponent(targetParent)}`, {
|
|
227
|
+
headers: {
|
|
228
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
229
|
+
},
|
|
230
|
+
});
|
|
231
|
+
if (!res.ok) {
|
|
232
|
+
const err = await res.json().catch(() => ({}));
|
|
233
|
+
throw new CloudizeroError(err.error || `Failed to list folders (${res.status})`, res.status, err);
|
|
234
|
+
}
|
|
235
|
+
return res.json();
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* [UPDATE] Renames or moves a folder, recursively updating paths and R2 object keys for all nested files
|
|
239
|
+
*/
|
|
240
|
+
async updateFolder(options) {
|
|
241
|
+
const { folderId, name, parentId } = options;
|
|
242
|
+
const res = await fetch(`${this.baseUrl}/api/storage/folders`, {
|
|
243
|
+
method: "PATCH",
|
|
244
|
+
headers: {
|
|
245
|
+
"Content-Type": "application/json",
|
|
246
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
247
|
+
},
|
|
248
|
+
body: JSON.stringify({
|
|
249
|
+
folderId,
|
|
250
|
+
...(name !== undefined ? { name } : {}),
|
|
251
|
+
...(parentId !== undefined
|
|
252
|
+
? { parentId: parentId && parentId !== "root" ? parentId : null }
|
|
253
|
+
: {}),
|
|
254
|
+
}),
|
|
255
|
+
});
|
|
256
|
+
if (!res.ok) {
|
|
257
|
+
const err = await res.json().catch(() => ({}));
|
|
258
|
+
throw new CloudizeroError(err.error || `Failed to update folder (${res.status})`, res.status, err);
|
|
259
|
+
}
|
|
260
|
+
return res.json();
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* [DELETE] Deletes a folder and recursively removes all nested subfolders and files from R2 and Neon DB
|
|
264
|
+
*/
|
|
265
|
+
async deleteFolder(folderId) {
|
|
266
|
+
const res = await fetch(`${this.baseUrl}/api/storage/folders?folderId=${encodeURIComponent(folderId)}`, {
|
|
267
|
+
method: "DELETE",
|
|
268
|
+
headers: {
|
|
269
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
270
|
+
},
|
|
271
|
+
});
|
|
272
|
+
if (!res.ok) {
|
|
273
|
+
const err = await res.json().catch(() => ({}));
|
|
274
|
+
throw new CloudizeroError(err.error || `Failed to delete folder (${res.status})`, res.status, err);
|
|
275
|
+
}
|
|
276
|
+
return res.json();
|
|
277
|
+
}
|
|
278
|
+
// ==========================================
|
|
279
|
+
// DIRECTORY BROWSING
|
|
280
|
+
// ==========================================
|
|
281
|
+
/**
|
|
282
|
+
* Lists folders and files in a directory
|
|
283
|
+
*/
|
|
284
|
+
async listContents(params) {
|
|
285
|
+
const { projectId, folderId = "root" } = params;
|
|
286
|
+
const res = await fetch(`${this.baseUrl}/api/storage/contents?projectId=${encodeURIComponent(projectId)}&folderId=${encodeURIComponent(folderId)}`, {
|
|
287
|
+
headers: {
|
|
288
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
289
|
+
},
|
|
290
|
+
});
|
|
291
|
+
if (!res.ok) {
|
|
292
|
+
const err = await res.json().catch(() => ({}));
|
|
293
|
+
throw new CloudizeroError(err.error || `Failed to list contents (${res.status})`, res.status, err);
|
|
294
|
+
}
|
|
295
|
+
const data = await res.json();
|
|
296
|
+
if (this.cdnUrl && data.files) {
|
|
297
|
+
data.files = data.files.map((f) => ({
|
|
298
|
+
...f,
|
|
299
|
+
url: `${this.cdnUrl}/${f.r2Key}`,
|
|
300
|
+
}));
|
|
301
|
+
}
|
|
302
|
+
return data;
|
|
303
|
+
}
|
|
304
|
+
getByteLength(file) {
|
|
305
|
+
if (typeof file === "object" && file !== null) {
|
|
306
|
+
if ("size" in file && typeof file.size === "number") {
|
|
307
|
+
return file.size;
|
|
308
|
+
}
|
|
309
|
+
if ("byteLength" in file && typeof file.byteLength === "number") {
|
|
310
|
+
return file.byteLength;
|
|
311
|
+
}
|
|
312
|
+
if ("length" in file && typeof file.length === "number") {
|
|
313
|
+
return file.length;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
return 0;
|
|
317
|
+
}
|
|
318
|
+
async uploadBinary(uploadUrl, file, mimeType, onProgress) {
|
|
319
|
+
// Browser environment with XMLHttpRequest (supports accurate progress events)
|
|
320
|
+
if (typeof window !== "undefined" && typeof XMLHttpRequest !== "undefined") {
|
|
321
|
+
return new Promise((resolve, reject) => {
|
|
322
|
+
const xhr = new XMLHttpRequest();
|
|
323
|
+
xhr.open("PUT", uploadUrl, true);
|
|
324
|
+
xhr.setRequestHeader("Content-Type", mimeType);
|
|
325
|
+
if (onProgress) {
|
|
326
|
+
xhr.upload.onprogress = (e) => {
|
|
327
|
+
if (e.lengthComputable) {
|
|
328
|
+
const percent = Math.round((e.loaded / e.total) * 100);
|
|
329
|
+
onProgress({ loaded: e.loaded, total: e.total, percent });
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
xhr.onload = () => {
|
|
334
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
335
|
+
resolve();
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
reject(new CloudizeroError(`R2 upload failed with HTTP status ${xhr.status}`, xhr.status));
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
xhr.onerror = () => reject(new CloudizeroError("Network error occurred during direct R2 upload"));
|
|
342
|
+
xhr.send(file);
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
// Node.js or non-browser environments using native fetch
|
|
346
|
+
const res = await fetch(uploadUrl, {
|
|
347
|
+
method: "PUT",
|
|
348
|
+
headers: {
|
|
349
|
+
"Content-Type": mimeType,
|
|
350
|
+
},
|
|
351
|
+
body: file,
|
|
352
|
+
});
|
|
353
|
+
if (!res.ok) {
|
|
354
|
+
throw new CloudizeroError(`R2 upload failed with HTTP status ${res.status}`, res.status);
|
|
355
|
+
}
|
|
356
|
+
if (onProgress) {
|
|
357
|
+
const size = this.getByteLength(file);
|
|
358
|
+
onProgress({ loaded: size, total: size, percent: 100 });
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
//# sourceMappingURL=storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,OAAO,aAAa;IACP,MAAM,CAAS;IACf,OAAO,CAAS;IAChB,MAAM,CAAU;IAEjC,YAAY,SAA2B,EAAE;QACvC,MAAM,cAAc,GAClB,MAAM,CAAC,MAAM;YACb,CAAC,OAA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gD,CAAC,CAAC,CAAC;gBAEhF,GAAG,CAAC,IAAI,CAAC,IAA8B,CAAC,CAAC;YAC3C,CAAC,CAAC,CAAC;QACL,CAAC;QAED,yDAAyD;QACzD,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,SAAS,EAAE;YACjC,MAAM,EAAE,KAAK;YACb,OAAO,EAAE;gBACP,cAAc,EAAE,QAAQ;aACzB;YACD,IAAI,EAAE,IAAgB;SACvB,CAAC,CAAC;QAEH,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;YACZ,MAAM,IAAI,eAAe,CACvB,qCAAqC,GAAG,CAAC,MAAM,EAAE,EACjD,GAAG,CAAC,MAAM,CACX,CAAC;QACJ,CAAC;QAED,IAAI,UAAU,EAAE,CAAC;YACf,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;YACtC,UAAU,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC;CACF"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
export interface CloudizeroConfig {
|
|
2
|
+
/**
|
|
3
|
+
* Cloudizero API Key starting with `cz_live_`.
|
|
4
|
+
* If omitted, falls back to `process.env.CLOUDIZERO_API_KEY`.
|
|
5
|
+
*/
|
|
6
|
+
apiKey?: string;
|
|
7
|
+
/**
|
|
8
|
+
* The base URL of your Cloudizero API deployment.
|
|
9
|
+
* Defaults to `process.env.CLOUDIZERO_BASE_URL` or `https://api-cloudizero.wismannur.pro`.
|
|
10
|
+
*/
|
|
11
|
+
baseUrl?: string;
|
|
12
|
+
/**
|
|
13
|
+
* The public CDN URL for serving assets (e.g. `https://cdn-cloudizero.wismannur.pro`).
|
|
14
|
+
* Defaults to `process.env.CLOUDIZERO_CDN_URL` or `https://cdn-cloudizero.wismannur.pro`.
|
|
15
|
+
*/
|
|
16
|
+
cdnUrl?: string;
|
|
17
|
+
}
|
|
18
|
+
export type UploadPayload = File | Blob | Uint8Array | ArrayBuffer | {
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
};
|
|
21
|
+
export interface UploadOptions {
|
|
22
|
+
/**
|
|
23
|
+
* File data to upload.
|
|
24
|
+
* Supports browser `File`/`Blob` and Node.js `Buffer`/`Uint8Array`.
|
|
25
|
+
*/
|
|
26
|
+
file: UploadPayload;
|
|
27
|
+
/**
|
|
28
|
+
* The name of the file (e.g. `avatar.png` or `report.pdf`)
|
|
29
|
+
*/
|
|
30
|
+
fileName: string;
|
|
31
|
+
/**
|
|
32
|
+
* The target Project ID
|
|
33
|
+
*/
|
|
34
|
+
projectId: string;
|
|
35
|
+
/**
|
|
36
|
+
* Optional target Folder ID within the project
|
|
37
|
+
*/
|
|
38
|
+
folderId?: string | null;
|
|
39
|
+
/**
|
|
40
|
+
* The MIME type of the file (e.g. `image/png`, `video/mp4`).
|
|
41
|
+
* If omitted, will default to `application/octet-stream`.
|
|
42
|
+
*/
|
|
43
|
+
mimeType?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Image width (optional metadata)
|
|
46
|
+
*/
|
|
47
|
+
width?: number | null;
|
|
48
|
+
/**
|
|
49
|
+
* Image height (optional metadata)
|
|
50
|
+
*/
|
|
51
|
+
height?: number | null;
|
|
52
|
+
/**
|
|
53
|
+
* Upload progress callback
|
|
54
|
+
*/
|
|
55
|
+
onProgress?: (progress: {
|
|
56
|
+
loaded: number;
|
|
57
|
+
total: number;
|
|
58
|
+
percent: number;
|
|
59
|
+
}) => void;
|
|
60
|
+
}
|
|
61
|
+
export interface UpdateFileOptions {
|
|
62
|
+
/**
|
|
63
|
+
* The ID of the file to update
|
|
64
|
+
*/
|
|
65
|
+
fileId: string;
|
|
66
|
+
/**
|
|
67
|
+
* Optional new file name (e.g. `hero-banner.webp`).
|
|
68
|
+
* Automatically moves/renames the underlying object in Cloudflare R2.
|
|
69
|
+
*/
|
|
70
|
+
name?: string;
|
|
71
|
+
/**
|
|
72
|
+
* Optional target Folder ID to move the file into (`null` or `"root"` moves to root).
|
|
73
|
+
* Automatically moves the underlying object in Cloudflare R2.
|
|
74
|
+
*/
|
|
75
|
+
folderId?: string | null;
|
|
76
|
+
/**
|
|
77
|
+
* Optional soft-delete trash status
|
|
78
|
+
*/
|
|
79
|
+
isTrash?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Optional binary payload to replace the file content in-place.
|
|
82
|
+
* If provided, the SDK will upload the new binary to R2 and update metadata.
|
|
83
|
+
*/
|
|
84
|
+
file?: UploadPayload;
|
|
85
|
+
/**
|
|
86
|
+
* Optional MIME type when replacing file content
|
|
87
|
+
*/
|
|
88
|
+
mimeType?: string;
|
|
89
|
+
/**
|
|
90
|
+
* Optional updated image width
|
|
91
|
+
*/
|
|
92
|
+
width?: number | null;
|
|
93
|
+
/**
|
|
94
|
+
* Optional updated image height
|
|
95
|
+
*/
|
|
96
|
+
height?: number | null;
|
|
97
|
+
/**
|
|
98
|
+
* Upload progress callback (used when `file` binary payload is provided)
|
|
99
|
+
*/
|
|
100
|
+
onProgress?: (progress: {
|
|
101
|
+
loaded: number;
|
|
102
|
+
total: number;
|
|
103
|
+
percent: number;
|
|
104
|
+
}) => void;
|
|
105
|
+
}
|
|
106
|
+
export interface ReplaceFileOptions {
|
|
107
|
+
/**
|
|
108
|
+
* The ID of the existing file to replace
|
|
109
|
+
*/
|
|
110
|
+
fileId: string;
|
|
111
|
+
/**
|
|
112
|
+
* New binary file payload
|
|
113
|
+
*/
|
|
114
|
+
file: UploadPayload;
|
|
115
|
+
/**
|
|
116
|
+
* Optional new file name (if omitted, keeps existing file name)
|
|
117
|
+
*/
|
|
118
|
+
fileName?: string;
|
|
119
|
+
/**
|
|
120
|
+
* Optional new target Folder ID (if omitted, keeps existing folder)
|
|
121
|
+
*/
|
|
122
|
+
folderId?: string | null;
|
|
123
|
+
/**
|
|
124
|
+
* Optional MIME type of the new file
|
|
125
|
+
*/
|
|
126
|
+
mimeType?: string;
|
|
127
|
+
/**
|
|
128
|
+
* Optional new width
|
|
129
|
+
*/
|
|
130
|
+
width?: number | null;
|
|
131
|
+
/**
|
|
132
|
+
* Optional new height
|
|
133
|
+
*/
|
|
134
|
+
height?: number | null;
|
|
135
|
+
/**
|
|
136
|
+
* Upload progress callback
|
|
137
|
+
*/
|
|
138
|
+
onProgress?: (progress: {
|
|
139
|
+
loaded: number;
|
|
140
|
+
total: number;
|
|
141
|
+
percent: number;
|
|
142
|
+
}) => void;
|
|
143
|
+
}
|
|
144
|
+
export interface UploadedFile {
|
|
145
|
+
id: string;
|
|
146
|
+
projectId: string;
|
|
147
|
+
folderId: string | null;
|
|
148
|
+
name: string;
|
|
149
|
+
mimeType: string;
|
|
150
|
+
size: number;
|
|
151
|
+
width: number | null;
|
|
152
|
+
height: number | null;
|
|
153
|
+
r2Key: string;
|
|
154
|
+
etag: string | null;
|
|
155
|
+
isTrash?: boolean;
|
|
156
|
+
createdAt: string;
|
|
157
|
+
updatedAt: string;
|
|
158
|
+
/**
|
|
159
|
+
* Resolved public CDN URL
|
|
160
|
+
*/
|
|
161
|
+
url?: string;
|
|
162
|
+
}
|
|
163
|
+
export interface StorageFolder {
|
|
164
|
+
id: string;
|
|
165
|
+
projectId: string;
|
|
166
|
+
parentId: string | null;
|
|
167
|
+
name: string;
|
|
168
|
+
path: string;
|
|
169
|
+
createdAt: string;
|
|
170
|
+
updatedAt: string;
|
|
171
|
+
}
|
|
172
|
+
export interface CreateFolderOptions {
|
|
173
|
+
/**
|
|
174
|
+
* Target Project ID
|
|
175
|
+
*/
|
|
176
|
+
projectId: string;
|
|
177
|
+
/**
|
|
178
|
+
* Folder display name (e.g. `avatars` or `Marketing Banners`)
|
|
179
|
+
*/
|
|
180
|
+
name: string;
|
|
181
|
+
/**
|
|
182
|
+
* Optional parent Folder ID (`null` or `"root"` for project root)
|
|
183
|
+
*/
|
|
184
|
+
parentId?: string | null;
|
|
185
|
+
/**
|
|
186
|
+
* Optional custom virtual path (auto-generated from parent path + slugified name if omitted)
|
|
187
|
+
*/
|
|
188
|
+
path?: string;
|
|
189
|
+
}
|
|
190
|
+
export interface ListFoldersOptions {
|
|
191
|
+
/**
|
|
192
|
+
* Target Project ID
|
|
193
|
+
*/
|
|
194
|
+
projectId: string;
|
|
195
|
+
/**
|
|
196
|
+
* Optional parent Folder ID (`null` or `"root"` lists root-level folders)
|
|
197
|
+
*/
|
|
198
|
+
parentId?: string | null;
|
|
199
|
+
}
|
|
200
|
+
export interface UpdateFolderOptions {
|
|
201
|
+
/**
|
|
202
|
+
* The ID of the folder to update
|
|
203
|
+
*/
|
|
204
|
+
folderId: string;
|
|
205
|
+
/**
|
|
206
|
+
* Optional new folder name.
|
|
207
|
+
* Automatically updates paths and moves underlying R2 objects for all nested files.
|
|
208
|
+
*/
|
|
209
|
+
name?: string;
|
|
210
|
+
/**
|
|
211
|
+
* Optional new parent Folder ID (`null` or `"root"` moves folder to project root).
|
|
212
|
+
* Automatically updates paths and moves underlying R2 objects for all nested files.
|
|
213
|
+
*/
|
|
214
|
+
parentId?: string | null;
|
|
215
|
+
}
|
|
216
|
+
export interface DeleteFolderResult {
|
|
217
|
+
success: boolean;
|
|
218
|
+
message: string;
|
|
219
|
+
deletedFoldersCount: number;
|
|
220
|
+
deletedFilesCount: number;
|
|
221
|
+
}
|
|
222
|
+
export interface Project {
|
|
223
|
+
id: string;
|
|
224
|
+
userId: string;
|
|
225
|
+
name: string;
|
|
226
|
+
description?: string | null;
|
|
227
|
+
sortOrder: number;
|
|
228
|
+
createdAt: string;
|
|
229
|
+
updatedAt: string;
|
|
230
|
+
}
|
|
231
|
+
export interface CreateProjectOptions {
|
|
232
|
+
name: string;
|
|
233
|
+
description?: string;
|
|
234
|
+
}
|
|
235
|
+
export interface StorageContents {
|
|
236
|
+
project: {
|
|
237
|
+
id: string;
|
|
238
|
+
name: string;
|
|
239
|
+
};
|
|
240
|
+
isRoot: boolean;
|
|
241
|
+
breadcrumbs: {
|
|
242
|
+
id: string;
|
|
243
|
+
name: string;
|
|
244
|
+
}[];
|
|
245
|
+
folders: StorageFolder[];
|
|
246
|
+
files: UploadedFile[];
|
|
247
|
+
}
|
|
248
|
+
//# 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,gBAAgB;IAC/B;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,aAAa,GACrB,IAAI,GACJ,IAAI,GACJ,UAAU,GACV,WAAW,GACX;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAAC;AAE/B,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,IAAI,EAAE,aAAa,CAAC;IAEpB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAEzB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAEtB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAEvB;;OAEG;IACH,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;CACrF;AAED,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;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B;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE;QACP,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE;QACX,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;KACd,EAAE,CAAC;IACJ,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,KAAK,EAAE,YAAY,EAAE,CAAC;CACvB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudizero/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Official TypeScript SDK for Cloudizero Zero-Egress Media Platform",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc",
|
|
21
|
+
"typecheck": "tsc --noEmit",
|
|
22
|
+
"prepublishOnly": "pnpm run build"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://cloudizero.wismannur.pro/docs",
|
|
28
|
+
"keywords": [
|
|
29
|
+
"cloudizero",
|
|
30
|
+
"dam",
|
|
31
|
+
"zero-egress",
|
|
32
|
+
"cloudflare-r2",
|
|
33
|
+
"media-upload",
|
|
34
|
+
"sdk"
|
|
35
|
+
],
|
|
36
|
+
"author": "Wisman Nur",
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"typescript": "^5.0.0"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|