@cloudizero/sdk 0.0.0-stage → 0.1.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 CHANGED
@@ -1,3 +1,120 @@
1
- # Temporary Holding Version
1
+ # @cloudizero/sdk
2
2
 
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.
3
+ > Official TypeScript SDK for the **Cloudizero** Zero-Egress Digital Asset Management & Media Delivery Platform.
4
+
5
+ Seamlessly upload, manage, and deliver media files 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
+ const cz = new Cloudizero({
31
+ apiKey: process.env.CLOUDIZERO_API_KEY!, // e.g. "cz_live_9f8a..."
32
+ baseUrl: "https://cloudizero.wismannur.pro", // your Cloudizero deployment
33
+ cdnUrl: "https://cdn-cloudizero.wismannur.pro", // optional public CDN domain
34
+ });
35
+ ```
36
+
37
+ ---
38
+
39
+ ## 📂 Usage Examples
40
+
41
+ ### Direct File Upload (Node.js / Next.js / Express)
42
+
43
+ Upload buffers, byte arrays, or streams directly from your backend services:
44
+
45
+ ```typescript
46
+ import fs from "fs";
47
+
48
+ const fileBuffer = fs.readFileSync("./avatar.png");
49
+
50
+ const uploaded = await cz.storage.upload({
51
+ file: fileBuffer,
52
+ fileName: "avatar.png",
53
+ projectId: "ca2454ff-7f1e-421b-b134-4c800f6d58de",
54
+ folderId: "profiles", // optional virtual folder
55
+ mimeType: "image/png",
56
+ });
57
+
58
+ console.log("Uploaded successfully!");
59
+ console.log("R2 Key:", uploaded.r2Key);
60
+ console.log("Public URL:", uploaded.url);
61
+ ```
62
+
63
+ ---
64
+
65
+ ### Browser Upload with Real-time Progress (React / Vue / Vanilla JS)
66
+
67
+ ```typescript
68
+ const handleFileInput = async (event: React.ChangeEvent<HTMLInputElement>) => {
69
+ const file = event.target.files?.[0];
70
+ if (!file) return;
71
+
72
+ const result = await cz.storage.upload({
73
+ file,
74
+ fileName: file.name,
75
+ projectId: "your-project-id",
76
+ mimeType: file.type,
77
+ onProgress: ({ loaded, total, percent }) => {
78
+ console.log(`Upload progress: ${percent}% (${loaded}/${total} bytes)`);
79
+ },
80
+ });
81
+
82
+ console.log("Public CDN link:", result.url);
83
+ };
84
+ ```
85
+
86
+ ---
87
+
88
+ ### List Project Media & Folders
89
+
90
+ ```typescript
91
+ const contents = await cz.storage.listContents({
92
+ projectId: "your-project-id",
93
+ folderId: "profiles", // or omit for root
94
+ });
95
+
96
+ console.log("Folders:", contents.folders);
97
+ console.log("Files:", contents.files);
98
+ ```
99
+
100
+ ---
101
+
102
+ ### Delete Asset Permanently
103
+
104
+ ```typescript
105
+ await cz.storage.deleteFile("file-id-here");
106
+ console.log("File permanently removed from R2 & DB");
107
+ ```
108
+
109
+ ---
110
+
111
+ ## 🔒 Security Best Practice
112
+
113
+ * **Secret API Key (`cz_live_...`)**: Keep in server-side environment variables (`process.env.CLOUDIZERO_API_KEY`).
114
+ * **Project Restrictions**: When generating an API key, you can restrict it to a specific project to follow the principle of least privilege.
115
+
116
+ ---
117
+
118
+ ## 📄 License
119
+
120
+ MIT © [Wisman Nur](https://wismannur.pro)
@@ -0,0 +1,10 @@
1
+ import { CloudizeroConfig } from "./types.js";
2
+ import { StorageClient } from "./storage.js";
3
+ export declare class Cloudizero {
4
+ /**
5
+ * Media Storage & Ingestion methods
6
+ */
7
+ readonly storage: StorageClient;
8
+ constructor(config: CloudizeroConfig);
9
+ }
10
+ //# 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;AAE7C,qBAAa,UAAU;IACrB;;OAEG;IACH,SAAgB,OAAO,EAAE,aAAa,CAAC;gBAE3B,MAAM,EAAE,gBAAgB;CAGrC"}
package/dist/client.js ADDED
@@ -0,0 +1,11 @@
1
+ import { StorageClient } from "./storage.js";
2
+ export class Cloudizero {
3
+ /**
4
+ * Media Storage & Ingestion methods
5
+ */
6
+ storage;
7
+ constructor(config) {
8
+ this.storage = new StorageClient(config);
9
+ }
10
+ }
11
+ //# 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;AAE7C,MAAM,OAAO,UAAU;IACrB;;OAEG;IACa,OAAO,CAAgB;IAEvC,YAAY,MAAwB;QAClC,IAAI,CAAC,OAAO,GAAG,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ export declare class CloudizeroError extends Error {
2
+ readonly status?: number;
3
+ readonly details?: unknown;
4
+ constructor(message: string, status?: number, details?: unknown);
5
+ }
6
+ //# sourceMappingURL=errors.d.ts.map
@@ -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"}
@@ -0,0 +1,5 @@
1
+ export { Cloudizero } from "./client.js";
2
+ export { StorageClient } from "./storage.js";
3
+ export { CloudizeroError } from "./errors.js";
4
+ export type { CloudizeroConfig, UploadOptions, UploadedFile, StorageContents, UploadPayload, } from "./types.js";
5
+ //# 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,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,YAAY,EACV,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,eAAe,EACf,aAAa,GACd,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { Cloudizero } from "./client.js";
2
+ export { StorageClient } from "./storage.js";
3
+ export { CloudizeroError } from "./errors.js";
4
+ //# sourceMappingURL=index.js.map
@@ -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,eAAe,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,35 @@
1
+ import { CloudizeroConfig, UploadOptions, UploadedFile, 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
+ * Uploads a file directly to Cloudflare R2 via presigned PUT URL and records metadata.
9
+ */
10
+ upload(options: UploadOptions): Promise<UploadedFile>;
11
+ /**
12
+ * 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
+ * Deletes a file permanently from Cloudflare R2 and Neon DB
20
+ */
21
+ deleteFile(fileId: string): Promise<{
22
+ success: boolean;
23
+ message: string;
24
+ }>;
25
+ /**
26
+ * Lists folders and files in a directory
27
+ */
28
+ listContents(params: {
29
+ projectId: string;
30
+ folderId?: string;
31
+ }): Promise<StorageContents>;
32
+ private getByteLength;
33
+ private uploadBinary;
34
+ }
35
+ //# sourceMappingURL=storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,eAAe,EAChB,MAAM,YAAY,CAAC;AAGpB,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAS;gBAErB,MAAM,EAAE,gBAAgB;IASpC;;OAEG;IACG,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;IAkF3D;;OAEG;IACG,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,YAAY,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;IAwBnF;;OAEG;IACG,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAoBhF;;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"}
@@ -0,0 +1,187 @@
1
+ import { CloudizeroError } from "./errors.js";
2
+ export class StorageClient {
3
+ apiKey;
4
+ baseUrl;
5
+ cdnUrl;
6
+ constructor(config) {
7
+ if (!config.apiKey) {
8
+ throw new CloudizeroError("Cloudizero API key is required");
9
+ }
10
+ this.apiKey = config.apiKey;
11
+ this.baseUrl = (config.baseUrl || "http://localhost:7010").replace(/\/+$/, "");
12
+ this.cdnUrl = config.cdnUrl ? config.cdnUrl.replace(/\/+$/, "") : undefined;
13
+ }
14
+ /**
15
+ * Uploads a file directly to Cloudflare R2 via presigned PUT URL and records metadata.
16
+ */
17
+ async upload(options) {
18
+ const { file, fileName, projectId, folderId, mimeType = "application/octet-stream", width, height, onProgress, } = options;
19
+ const fileSize = this.getByteLength(file);
20
+ // 1. Request Presigned Upload Ticket
21
+ const presignRes = await fetch(`${this.baseUrl}/api/storage/presign`, {
22
+ method: "POST",
23
+ headers: {
24
+ "Content-Type": "application/json",
25
+ Authorization: `Bearer ${this.apiKey}`,
26
+ },
27
+ body: JSON.stringify({
28
+ projectId,
29
+ folderId: folderId && folderId !== "root" ? folderId : null,
30
+ fileName,
31
+ mimeType,
32
+ fileSize,
33
+ }),
34
+ });
35
+ if (!presignRes.ok) {
36
+ const err = await presignRes.json().catch(() => ({}));
37
+ throw new CloudizeroError(err.error || `Presign failed with status ${presignRes.status}`, presignRes.status, err);
38
+ }
39
+ const { uploadUrl, r2Key, fileId, finalFileName } = await presignRes.json();
40
+ // 2. Direct S3 PUT Upload to Cloudflare R2
41
+ await this.uploadBinary(uploadUrl, file, mimeType, onProgress);
42
+ // 3. Record Metadata in Cloudizero
43
+ const completeRes = await fetch(`${this.baseUrl}/api/storage/complete`, {
44
+ method: "POST",
45
+ headers: {
46
+ "Content-Type": "application/json",
47
+ Authorization: `Bearer ${this.apiKey}`,
48
+ },
49
+ body: JSON.stringify({
50
+ fileId,
51
+ projectId,
52
+ folderId: folderId && folderId !== "root" ? folderId : null,
53
+ name: finalFileName || fileName,
54
+ mimeType,
55
+ size: fileSize,
56
+ width: width || null,
57
+ height: height || null,
58
+ r2Key,
59
+ }),
60
+ });
61
+ if (!completeRes.ok) {
62
+ const err = await completeRes.json().catch(() => ({}));
63
+ throw new CloudizeroError(err.error || `Recording file metadata failed with status ${completeRes.status}`, completeRes.status, err);
64
+ }
65
+ const recordedFile = await completeRes.json();
66
+ if (this.cdnUrl) {
67
+ recordedFile.url = `${this.cdnUrl}/${recordedFile.r2Key}`;
68
+ }
69
+ return recordedFile;
70
+ }
71
+ /**
72
+ * Gets file details and generates a presigned private download URL
73
+ */
74
+ async getFile(fileId) {
75
+ const res = await fetch(`${this.baseUrl}/api/storage/files?fileId=${fileId}`, {
76
+ headers: {
77
+ Authorization: `Bearer ${this.apiKey}`,
78
+ },
79
+ });
80
+ if (!res.ok) {
81
+ const err = await res.json().catch(() => ({}));
82
+ throw new CloudizeroError(err.error || `Failed to get file (${res.status})`, res.status, err);
83
+ }
84
+ const data = await res.json();
85
+ if (this.cdnUrl && data.file) {
86
+ data.file.url = `${this.cdnUrl}/${data.file.r2Key}`;
87
+ }
88
+ return data;
89
+ }
90
+ /**
91
+ * Deletes a file permanently from Cloudflare R2 and Neon DB
92
+ */
93
+ async deleteFile(fileId) {
94
+ const res = await fetch(`${this.baseUrl}/api/storage/files?fileId=${fileId}`, {
95
+ method: "DELETE",
96
+ headers: {
97
+ Authorization: `Bearer ${this.apiKey}`,
98
+ },
99
+ });
100
+ if (!res.ok) {
101
+ const err = await res.json().catch(() => ({}));
102
+ throw new CloudizeroError(err.error || `Failed to delete file (${res.status})`, res.status, err);
103
+ }
104
+ return res.json();
105
+ }
106
+ /**
107
+ * Lists folders and files in a directory
108
+ */
109
+ async listContents(params) {
110
+ const { projectId, folderId = "root" } = params;
111
+ const res = await fetch(`${this.baseUrl}/api/storage/contents?projectId=${projectId}&folderId=${folderId}`, {
112
+ headers: {
113
+ Authorization: `Bearer ${this.apiKey}`,
114
+ },
115
+ });
116
+ if (!res.ok) {
117
+ const err = await res.json().catch(() => ({}));
118
+ throw new CloudizeroError(err.error || `Failed to list contents (${res.status})`, res.status, err);
119
+ }
120
+ const data = await res.json();
121
+ if (this.cdnUrl && data.files) {
122
+ data.files = data.files.map((f) => ({
123
+ ...f,
124
+ url: `${this.cdnUrl}/${f.r2Key}`,
125
+ }));
126
+ }
127
+ return data;
128
+ }
129
+ getByteLength(file) {
130
+ if (typeof file === "object" && file !== null) {
131
+ if ("size" in file && typeof file.size === "number") {
132
+ return file.size;
133
+ }
134
+ if ("byteLength" in file && typeof file.byteLength === "number") {
135
+ return file.byteLength;
136
+ }
137
+ if ("length" in file && typeof file.length === "number") {
138
+ return file.length;
139
+ }
140
+ }
141
+ return 0;
142
+ }
143
+ async uploadBinary(uploadUrl, file, mimeType, onProgress) {
144
+ // Browser environment with XMLHttpRequest (supports accurate progress events)
145
+ if (typeof window !== "undefined" && typeof XMLHttpRequest !== "undefined") {
146
+ return new Promise((resolve, reject) => {
147
+ const xhr = new XMLHttpRequest();
148
+ xhr.open("PUT", uploadUrl, true);
149
+ xhr.setRequestHeader("Content-Type", mimeType);
150
+ if (onProgress) {
151
+ xhr.upload.onprogress = (e) => {
152
+ if (e.lengthComputable) {
153
+ const percent = Math.round((e.loaded / e.total) * 100);
154
+ onProgress({ loaded: e.loaded, total: e.total, percent });
155
+ }
156
+ };
157
+ }
158
+ xhr.onload = () => {
159
+ if (xhr.status >= 200 && xhr.status < 300) {
160
+ resolve();
161
+ }
162
+ else {
163
+ reject(new CloudizeroError(`R2 upload failed with HTTP status ${xhr.status}`, xhr.status));
164
+ }
165
+ };
166
+ xhr.onerror = () => reject(new CloudizeroError("Network error occurred during direct R2 upload"));
167
+ xhr.send(file);
168
+ });
169
+ }
170
+ // Node.js or non-browser environments using native fetch
171
+ const res = await fetch(uploadUrl, {
172
+ method: "PUT",
173
+ headers: {
174
+ "Content-Type": mimeType,
175
+ },
176
+ body: file,
177
+ });
178
+ if (!res.ok) {
179
+ throw new CloudizeroError(`R2 upload failed with HTTP status ${res.status}`, res.status);
180
+ }
181
+ if (onProgress) {
182
+ const size = this.getByteLength(file);
183
+ onProgress({ loaded: size, total: size, percent: 100 });
184
+ }
185
+ }
186
+ }
187
+ //# sourceMappingURL=storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,OAAO,aAAa;IACP,MAAM,CAAS;IACf,OAAO,CAAS;IAChB,MAAM,CAAU;IAEjC,YAAY,MAAwB;QAClC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;YACnB,MAAM,IAAI,eAAe,CAAC,gCAAgC,CAAC,CAAC;QAC9D,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CA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E,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"}
@@ -0,0 +1,96 @@
1
+ export interface CloudizeroConfig {
2
+ /**
3
+ * Cloudizero API Key starting with `cz_live_`
4
+ */
5
+ apiKey: string;
6
+ /**
7
+ * The base URL of your Cloudizero deployment.
8
+ * Defaults to `https://cloudizero.com` (or current app URL).
9
+ */
10
+ baseUrl?: string;
11
+ /**
12
+ * The public CDN URL for serving assets (e.g. `https://cdn.wismannur.pro`).
13
+ * Optional; if provided, will be attached to uploaded file results as `url`.
14
+ */
15
+ cdnUrl?: string;
16
+ }
17
+ export type UploadPayload = File | Blob | Uint8Array | ArrayBuffer | {
18
+ [key: string]: unknown;
19
+ };
20
+ export interface UploadOptions {
21
+ /**
22
+ * File data to upload.
23
+ * Supports browser `File`/`Blob` and Node.js `Buffer`/`Uint8Array`.
24
+ */
25
+ file: UploadPayload;
26
+ /**
27
+ * The name of the file (e.g. `avatar.png` or `report.pdf`)
28
+ */
29
+ fileName: string;
30
+ /**
31
+ * The target Project ID
32
+ */
33
+ projectId: string;
34
+ /**
35
+ * Optional target Folder ID within the project
36
+ */
37
+ folderId?: string | null;
38
+ /**
39
+ * The MIME type of the file (e.g. `image/png`, `video/mp4`).
40
+ * If omitted, will default to `application/octet-stream`.
41
+ */
42
+ mimeType?: string;
43
+ /**
44
+ * Image width (optional metadata)
45
+ */
46
+ width?: number | null;
47
+ /**
48
+ * Image height (optional metadata)
49
+ */
50
+ height?: number | null;
51
+ /**
52
+ * Upload progress callback
53
+ */
54
+ onProgress?: (progress: {
55
+ loaded: number;
56
+ total: number;
57
+ percent: number;
58
+ }) => void;
59
+ }
60
+ export interface UploadedFile {
61
+ id: string;
62
+ projectId: string;
63
+ folderId: string | null;
64
+ name: string;
65
+ mimeType: string;
66
+ size: number;
67
+ width: number | null;
68
+ height: number | null;
69
+ r2Key: string;
70
+ etag: string | null;
71
+ createdAt: string;
72
+ updatedAt: string;
73
+ /**
74
+ * Resolved public CDN URL
75
+ */
76
+ url?: string;
77
+ }
78
+ export interface StorageContents {
79
+ project: {
80
+ id: string;
81
+ name: string;
82
+ };
83
+ isRoot: boolean;
84
+ breadcrumbs: {
85
+ id: string;
86
+ name: string;
87
+ }[];
88
+ folders: {
89
+ id: string;
90
+ name: string;
91
+ path: string;
92
+ createdAt: string;
93
+ }[];
94
+ files: UploadedFile[];
95
+ }
96
+ //# 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;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;;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;;OA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"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,46 @@
1
1
  {
2
2
  "name": "@cloudizero/sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.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
+ },
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://github.com/wismannur/cloudizero.git",
29
+ "directory": "packages/sdk"
30
+ },
31
+ "homepage": "https://cloudizero.wismannur.pro",
32
+ "keywords": [
33
+ "cloudizero",
34
+ "dam",
35
+ "zero-egress",
36
+ "cloudflare-r2",
37
+ "media-upload",
38
+ "sdk"
39
+ ],
40
+ "author": "Wisman Nur",
41
+ "license": "MIT",
42
+ "devDependencies": {
43
+ "typescript": "^5.0.0"
44
+ }
45
+ }
46
+