@omnibase/core-js 0.5.10 → 0.7.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 +64 -198
- package/dist/chunk-4VFICD7B.js +563 -0
- package/dist/chunk-4WXOODCF.js +579 -0
- package/dist/chunk-5MDBFHTF.js +555 -0
- package/dist/chunk-6OGESVXW.js +651 -0
- package/dist/chunk-BZSZVT4V.js +152 -0
- package/dist/chunk-CUBJFCZH.js +579 -0
- package/dist/chunk-I6DMWC32.js +129 -0
- package/dist/chunk-IVPULXIA.js +150 -0
- package/dist/chunk-LCEBQTB7.js +563 -0
- package/dist/chunk-LMDKQ6Z2.js +706 -0
- package/dist/chunk-NBPRDG6O.js +643 -0
- package/dist/chunk-QPW6G4PA.js +490 -0
- package/dist/chunk-QXPPBLH4.js +556 -0
- package/dist/chunk-V56G36FZ.js +558 -0
- package/dist/chunk-ZBRAIBZZ.js +658 -0
- package/dist/chunk-ZYLNNK7H.js +555 -0
- package/dist/database/index.cjs +215 -1
- package/dist/database/index.d.cts +194 -1
- package/dist/database/index.d.ts +194 -1
- package/dist/database/index.js +214 -1
- package/dist/index.cjs +449 -185
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +105 -4
- package/dist/payments/index.cjs +22 -74
- package/dist/payments/index.d.cts +554 -245
- package/dist/payments/index.d.ts +554 -245
- package/dist/payments/index.js +1 -1
- package/dist/storage/index.cjs +153 -0
- package/dist/storage/index.d.cts +3 -0
- package/dist/storage/index.d.ts +3 -0
- package/dist/storage/index.js +6 -0
- package/dist/tenants/index.cjs +200 -109
- package/dist/tenants/index.d.cts +1 -1
- package/dist/tenants/index.d.ts +1 -1
- package/dist/tenants/index.js +1 -1
- package/package.json +17 -12
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// src/storage/index.ts
|
|
2
|
+
var Bucket = class {
|
|
3
|
+
constructor(client, name) {
|
|
4
|
+
this.client = client;
|
|
5
|
+
this.name = name;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Upload a file to the bucket
|
|
9
|
+
*
|
|
10
|
+
* @param path - Path within the bucket (will be prefixed with tenant_id)
|
|
11
|
+
* @param file - File or Blob to upload
|
|
12
|
+
* @param options - Upload options including custom metadata
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const result = await storage.bucket('user-uploads').upload(
|
|
17
|
+
* 'documents/report.pdf',
|
|
18
|
+
* file,
|
|
19
|
+
* {
|
|
20
|
+
* metadata: {
|
|
21
|
+
* department: 'engineering',
|
|
22
|
+
* project: 'Q4-review',
|
|
23
|
+
* tags: ['important', 'quarterly']
|
|
24
|
+
* }
|
|
25
|
+
* }
|
|
26
|
+
* );
|
|
27
|
+
*
|
|
28
|
+
* // Upload file to S3 using pre-signed URL
|
|
29
|
+
* await fetch(result.upload_url, {
|
|
30
|
+
* method: 'PUT',
|
|
31
|
+
* body: file
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
async upload(path, file, options) {
|
|
36
|
+
const metadata = {
|
|
37
|
+
// File metadata
|
|
38
|
+
filename: file instanceof File ? file.name : "blob",
|
|
39
|
+
size: file.size,
|
|
40
|
+
mime_type: file.type,
|
|
41
|
+
uploaded_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
42
|
+
// Merge custom metadata
|
|
43
|
+
...options?.metadata || {}
|
|
44
|
+
};
|
|
45
|
+
const response = await this.client.fetch("/api/v1/storage/upload", {
|
|
46
|
+
method: "POST",
|
|
47
|
+
headers: {
|
|
48
|
+
"Content-Type": "application/json"
|
|
49
|
+
},
|
|
50
|
+
body: JSON.stringify({
|
|
51
|
+
bucket: this.name,
|
|
52
|
+
path,
|
|
53
|
+
metadata
|
|
54
|
+
})
|
|
55
|
+
});
|
|
56
|
+
if (!response.ok) {
|
|
57
|
+
const error = await response.json().catch(() => ({ error: "Upload failed" }));
|
|
58
|
+
throw new Error(error.error || "Failed to get upload URL");
|
|
59
|
+
}
|
|
60
|
+
const responseData = await response.json();
|
|
61
|
+
const result = responseData.data;
|
|
62
|
+
const uploadResponse = await fetch(result.upload_url, {
|
|
63
|
+
method: "PUT",
|
|
64
|
+
body: file,
|
|
65
|
+
headers: {
|
|
66
|
+
"Content-Type": file.type
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
if (!uploadResponse.ok) {
|
|
70
|
+
throw new Error("Failed to upload file to storage");
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Download a file from the bucket
|
|
76
|
+
*
|
|
77
|
+
* @param path - Path to the file (including tenant_id prefix)
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* const { download_url } = await storage.bucket('user-uploads')
|
|
82
|
+
* .download('tenant-123/documents/report.pdf');
|
|
83
|
+
*
|
|
84
|
+
* // Download the file
|
|
85
|
+
* const response = await fetch(download_url);
|
|
86
|
+
* const blob = await response.blob();
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
async download(path) {
|
|
90
|
+
const response = await this.client.fetch("/api/v1/storage/download", {
|
|
91
|
+
method: "POST",
|
|
92
|
+
headers: {
|
|
93
|
+
"Content-Type": "application/json"
|
|
94
|
+
},
|
|
95
|
+
body: JSON.stringify({
|
|
96
|
+
bucket: this.name,
|
|
97
|
+
path
|
|
98
|
+
})
|
|
99
|
+
});
|
|
100
|
+
if (!response.ok) {
|
|
101
|
+
const error = await response.json().catch(() => ({ error: "Download failed" }));
|
|
102
|
+
throw new Error(error.error || "Failed to get download URL");
|
|
103
|
+
}
|
|
104
|
+
const responseData = await response.json();
|
|
105
|
+
return responseData.data;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Delete a file from the bucket
|
|
109
|
+
*
|
|
110
|
+
* @param path - Path to the file (including tenant_id prefix)
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* await storage.bucket('user-uploads')
|
|
115
|
+
* .delete('tenant-123/documents/report.pdf');
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
async delete(path) {
|
|
119
|
+
const response = await this.client.fetch("/api/v1/storage/object", {
|
|
120
|
+
method: "DELETE",
|
|
121
|
+
headers: {
|
|
122
|
+
"Content-Type": "application/json"
|
|
123
|
+
},
|
|
124
|
+
body: JSON.stringify({
|
|
125
|
+
bucket: this.name,
|
|
126
|
+
path
|
|
127
|
+
})
|
|
128
|
+
});
|
|
129
|
+
if (!response.ok) {
|
|
130
|
+
const error = await response.json().catch(() => ({ error: "Delete failed" }));
|
|
131
|
+
throw new Error(error.error || "Failed to delete file");
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
var StorageClient = class {
|
|
136
|
+
constructor(client) {
|
|
137
|
+
this.client = client;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Get a bucket reference for file operations
|
|
141
|
+
*
|
|
142
|
+
* @param name - Bucket name (e.g., 'public', 'user-uploads', 'avatars')
|
|
143
|
+
*/
|
|
144
|
+
bucket(name) {
|
|
145
|
+
return new Bucket(this.client, name);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export {
|
|
150
|
+
Bucket,
|
|
151
|
+
StorageClient
|
|
152
|
+
};
|