@koolbase/react-native 9.1.0 → 10.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/CHANGELOG.md +1342 -0
- package/README.md +462 -511
- package/dist/{auth-storage.d.ts → cjs/auth-storage.d.ts} +1 -1
- package/dist/cjs/index.d.ts +19 -0
- package/dist/cjs/index.js +125 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/platform.d.ts +2 -0
- package/dist/cjs/platform.js +43 -0
- package/dist/esm/auth-storage.d.ts +26 -0
- package/dist/esm/auth-storage.js +100 -0
- package/dist/esm/index.d.ts +19 -0
- package/dist/esm/index.js +106 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/platform.d.ts +2 -0
- package/dist/esm/platform.js +37 -0
- package/package.json +30 -24
- package/dist/analytics.d.ts +0 -24
- package/dist/analytics.js +0 -114
- package/dist/apple-auth.d.ts +0 -22
- package/dist/apple-auth.js +0 -74
- package/dist/auth-errors.d.ts +0 -117
- package/dist/auth-errors.js +0 -250
- package/dist/auth.d.ts +0 -199
- package/dist/auth.js +0 -794
- package/dist/cache-store.d.ts +0 -11
- package/dist/cache-store.js +0 -136
- package/dist/code-push.d.ts +0 -59
- package/dist/code-push.js +0 -255
- package/dist/database-errors.d.ts +0 -95
- package/dist/database-errors.js +0 -173
- package/dist/database.d.ts +0 -208
- package/dist/database.js +0 -508
- package/dist/device-id.d.ts +0 -1
- package/dist/device-id.js +0 -60
- package/dist/device-metadata.d.ts +0 -36
- package/dist/device-metadata.js +0 -102
- package/dist/flags.d.ts +0 -15
- package/dist/flags.js +0 -76
- package/dist/functions.d.ts +0 -8
- package/dist/functions.js +0 -70
- package/dist/index.d.ts +0 -45
- package/dist/index.js +0 -193
- package/dist/logic-engine.d.ts +0 -17
- package/dist/logic-engine.js +0 -193
- package/dist/messaging.d.ts +0 -13
- package/dist/messaging.js +0 -36
- package/dist/realtime.d.ts +0 -19
- package/dist/realtime.js +0 -148
- package/dist/record.d.ts +0 -2
- package/dist/record.js +0 -20
- package/dist/storage-errors.d.ts +0 -163
- package/dist/storage-errors.js +0 -249
- package/dist/storage.d.ts +0 -184
- package/dist/storage.js +0 -438
- package/dist/sync-engine.d.ts +0 -16
- package/dist/sync-engine.js +0 -86
- package/dist/types.d.ts +0 -470
- package/dist/types.js +0 -40
- /package/dist/{auth-storage.js → cjs/auth-storage.js} +0 -0
package/dist/storage-errors.js
DELETED
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.KoolbaseStorageMetadataInvalidError = exports.KoolbaseStorageMimeTypeError = exports.KoolbaseStorageFileTooLargeError = exports.KoolbaseStorageQuotaError = exports.KoolbaseStoragePermissionError = exports.KoolbaseStorageValidationError = exports.KoolbaseStorageNotFoundError = exports.KoolbaseStorageConflictError = exports.KoolbaseStorageError = void 0;
|
|
4
|
-
exports.koolbaseStorageError = koolbaseStorageError;
|
|
5
|
-
exports.koolbaseStorageErrorFromResponse = koolbaseStorageErrorFromResponse;
|
|
6
|
-
/**
|
|
7
|
-
* Base error type for all Koolbase storage errors. Catchable via
|
|
8
|
-
* `instanceof KoolbaseStorageError` to handle any storage-related failure
|
|
9
|
-
* generically; subclasses let you handle specific cases.
|
|
10
|
-
*/
|
|
11
|
-
class KoolbaseStorageError extends Error {
|
|
12
|
-
constructor(message, code) {
|
|
13
|
-
super(message);
|
|
14
|
-
this.code = code;
|
|
15
|
-
this.name = 'KoolbaseStorageError';
|
|
16
|
-
Object.setPrototypeOf(this, KoolbaseStorageError.prototype);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.KoolbaseStorageError = KoolbaseStorageError;
|
|
20
|
-
/**
|
|
21
|
-
* Thrown when an upload is rejected because an object already exists at
|
|
22
|
-
* the requested path — the server responds with 409 Conflict and code
|
|
23
|
-
* `path_conflict`. Catch it to give the user an "overwrite this file?"
|
|
24
|
-
* prompt, then retry the upload with `overwrite: true`.
|
|
25
|
-
*
|
|
26
|
-
* `path` is the colliding path the server rejected, surfaced from the
|
|
27
|
-
* response body for diagnostics and UI.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* try {
|
|
31
|
-
* await Koolbase.storage.upload({
|
|
32
|
-
* bucket: 'avatars',
|
|
33
|
-
* path: 'me.png',
|
|
34
|
-
* file: { uri, name, type: 'image/png' },
|
|
35
|
-
* });
|
|
36
|
-
* } catch (e) {
|
|
37
|
-
* if (e instanceof KoolbaseStorageConflictError) {
|
|
38
|
-
* const ok = await confirm(`${e.path} already exists. Overwrite?`);
|
|
39
|
-
* if (ok) {
|
|
40
|
-
* await Koolbase.storage.upload({
|
|
41
|
-
* bucket: 'avatars',
|
|
42
|
-
* path: 'me.png',
|
|
43
|
-
* file: { uri, name, type: 'image/png' },
|
|
44
|
-
* overwrite: true,
|
|
45
|
-
* });
|
|
46
|
-
* }
|
|
47
|
-
* }
|
|
48
|
-
* }
|
|
49
|
-
*/
|
|
50
|
-
class KoolbaseStorageConflictError extends KoolbaseStorageError {
|
|
51
|
-
constructor(message, path) {
|
|
52
|
-
super(message ?? 'An object already exists at this path', 'path_conflict');
|
|
53
|
-
this.path = path;
|
|
54
|
-
this.name = 'KoolbaseStorageConflictError';
|
|
55
|
-
Object.setPrototypeOf(this, KoolbaseStorageConflictError.prototype);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
exports.KoolbaseStorageConflictError = KoolbaseStorageConflictError;
|
|
59
|
-
/**
|
|
60
|
-
* Thrown when the requested bucket or object does not exist — the server
|
|
61
|
-
* responds with 404. Also surfaced for cross-tenant access attempts
|
|
62
|
-
* (Koolbase's 404-over-403 convention prevents enumeration in
|
|
63
|
-
* multi-tenant contexts).
|
|
64
|
-
*/
|
|
65
|
-
class KoolbaseStorageNotFoundError extends KoolbaseStorageError {
|
|
66
|
-
constructor(message) {
|
|
67
|
-
super(message ?? 'The requested bucket or object was not found', 'not_found');
|
|
68
|
-
this.name = 'KoolbaseStorageNotFoundError';
|
|
69
|
-
Object.setPrototypeOf(this, KoolbaseStorageNotFoundError.prototype);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
exports.KoolbaseStorageNotFoundError = KoolbaseStorageNotFoundError;
|
|
73
|
-
/**
|
|
74
|
-
* Thrown when the request is rejected as invalid — the server responds
|
|
75
|
-
* with 400 (e.g. a malformed path, missing field, invalid bucket name).
|
|
76
|
-
*/
|
|
77
|
-
class KoolbaseStorageValidationError extends KoolbaseStorageError {
|
|
78
|
-
constructor(message) {
|
|
79
|
-
super(message ?? 'The storage request was invalid', 'validation_error');
|
|
80
|
-
this.name = 'KoolbaseStorageValidationError';
|
|
81
|
-
Object.setPrototypeOf(this, KoolbaseStorageValidationError.prototype);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
exports.KoolbaseStorageValidationError = KoolbaseStorageValidationError;
|
|
85
|
-
/**
|
|
86
|
-
* Thrown when the caller is authenticated but not allowed to perform the
|
|
87
|
-
* storage operation — the server responds with 403.
|
|
88
|
-
*/
|
|
89
|
-
class KoolbaseStoragePermissionError extends KoolbaseStorageError {
|
|
90
|
-
constructor(message) {
|
|
91
|
-
super(message ?? 'You do not have permission to perform this storage action', 'permission_denied');
|
|
92
|
-
this.name = 'KoolbaseStoragePermissionError';
|
|
93
|
-
Object.setPrototypeOf(this, KoolbaseStoragePermissionError.prototype);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
exports.KoolbaseStoragePermissionError = KoolbaseStoragePermissionError;
|
|
97
|
-
/**
|
|
98
|
-
* Thrown when an upload would push the bucket past its configured
|
|
99
|
-
* `max_size_bytes` quota — the server responds with 409 Conflict and code
|
|
100
|
-
* `quota_exceeded`. The server cleans up the underlying R2 object before
|
|
101
|
-
* returning; nothing leaks. Catch this to surface a "bucket is full"
|
|
102
|
-
* message or prompt the caller to delete older files. The per-bucket
|
|
103
|
-
* quota is set at bucket creation time and is currently immutable.
|
|
104
|
-
*
|
|
105
|
-
* Distinct from {@link KoolbaseStorageConflictError} (which also uses
|
|
106
|
-
* 409 but means "path collides"); branch on the error type via
|
|
107
|
-
* `instanceof`, not on status.
|
|
108
|
-
*/
|
|
109
|
-
class KoolbaseStorageQuotaError extends KoolbaseStorageError {
|
|
110
|
-
constructor(message) {
|
|
111
|
-
super(message ?? 'Bucket quota exceeded', 'quota_exceeded');
|
|
112
|
-
this.name = 'KoolbaseStorageQuotaError';
|
|
113
|
-
Object.setPrototypeOf(this, KoolbaseStorageQuotaError.prototype);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
exports.KoolbaseStorageQuotaError = KoolbaseStorageQuotaError;
|
|
117
|
-
/**
|
|
118
|
-
* Thrown when a single file exceeds the bucket's configured
|
|
119
|
-
* `max_file_size_bytes` — the server responds with 413 Payload Too Large
|
|
120
|
-
* and code `file_too_large`. The server cleans up the underlying R2
|
|
121
|
-
* object before returning. The configured per-file limit lives on the
|
|
122
|
-
* bucket record; check `Bucket.maxFileSizeBytes` to surface a clear
|
|
123
|
-
* "files must be under X MB" message at the call site.
|
|
124
|
-
*/
|
|
125
|
-
class KoolbaseStorageFileTooLargeError extends KoolbaseStorageError {
|
|
126
|
-
constructor(message) {
|
|
127
|
-
super(message ?? 'File exceeds the bucket maximum file size', 'file_too_large');
|
|
128
|
-
this.name = 'KoolbaseStorageFileTooLargeError';
|
|
129
|
-
Object.setPrototypeOf(this, KoolbaseStorageFileTooLargeError.prototype);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
exports.KoolbaseStorageFileTooLargeError = KoolbaseStorageFileTooLargeError;
|
|
133
|
-
/**
|
|
134
|
-
* Thrown when an upload's content-type isn't in the bucket's configured
|
|
135
|
-
* `allowed_mime_types` allowlist — the server responds with 415
|
|
136
|
-
* Unsupported Media Type and code `mime_not_allowed`. The check runs at
|
|
137
|
-
* presign time, so no bytes are transferred before rejection.
|
|
138
|
-
*
|
|
139
|
-
* Allowlists support `type/*` wildcards (e.g. `image/*` matches every
|
|
140
|
-
* image content-type). A bucket with no allowlist configured accepts
|
|
141
|
-
* every type.
|
|
142
|
-
*/
|
|
143
|
-
class KoolbaseStorageMimeTypeError extends KoolbaseStorageError {
|
|
144
|
-
constructor(message) {
|
|
145
|
-
super(message ?? 'Content-type not allowed for this bucket', 'mime_not_allowed');
|
|
146
|
-
this.name = 'KoolbaseStorageMimeTypeError';
|
|
147
|
-
Object.setPrototypeOf(this, KoolbaseStorageMimeTypeError.prototype);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
exports.KoolbaseStorageMimeTypeError = KoolbaseStorageMimeTypeError;
|
|
151
|
-
/**
|
|
152
|
-
* Thrown when an object metadata payload (either at upload-confirm time
|
|
153
|
-
* or via `updateMetadata`) fails server-side validation — the server
|
|
154
|
-
* responds with 400 and code `metadata_invalid`.
|
|
155
|
-
*
|
|
156
|
-
* The `detail` field carries the specific reason from the server — e.g.
|
|
157
|
-
* `'key "foo bar": must match [a-z0-9_]+'`, `'exceeds 50 keys (got 53)'`,
|
|
158
|
-
* or `'exceeds 8192 bytes total (sum of all key + value lengths)'`. The
|
|
159
|
-
* detail names the failing key and rule so callers can fix the offending
|
|
160
|
-
* entry without guessing what shape rule was violated.
|
|
161
|
-
*
|
|
162
|
-
* Validation rules (enforced server-side):
|
|
163
|
-
* - At most 50 keys per object.
|
|
164
|
-
* - At most 8KB total (sum of byte lengths across all keys + values).
|
|
165
|
-
* - Keys: 1–64 chars, must match `[a-z0-9_]+`.
|
|
166
|
-
* - Keys with a leading underscore are reserved for system use.
|
|
167
|
-
* - Values: at most 1024 chars each.
|
|
168
|
-
*
|
|
169
|
-
* @example
|
|
170
|
-
* try {
|
|
171
|
-
* await Koolbase.storage.updateMetadata('photos', 'sunset.jpg', {
|
|
172
|
-
* tag: 'sunset',
|
|
173
|
-
* 'BAD KEY': 'oops',
|
|
174
|
-
* });
|
|
175
|
-
* } catch (e) {
|
|
176
|
-
* if (e instanceof KoolbaseStorageMetadataInvalidError) {
|
|
177
|
-
* console.warn('Metadata rejected:', e.detail);
|
|
178
|
-
* // -> 'Metadata rejected: key "BAD KEY": must match [a-z0-9_]+'
|
|
179
|
-
* }
|
|
180
|
-
* }
|
|
181
|
-
*/
|
|
182
|
-
class KoolbaseStorageMetadataInvalidError extends KoolbaseStorageError {
|
|
183
|
-
constructor(message, detail) {
|
|
184
|
-
super(message ?? 'Metadata payload is invalid', 'metadata_invalid');
|
|
185
|
-
this.detail = detail;
|
|
186
|
-
this.name = 'KoolbaseStorageMetadataInvalidError';
|
|
187
|
-
Object.setPrototypeOf(this, KoolbaseStorageMetadataInvalidError.prototype);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
exports.KoolbaseStorageMetadataInvalidError = KoolbaseStorageMetadataInvalidError;
|
|
191
|
-
/**
|
|
192
|
-
* Maps a non-2xx storage-layer response to a typed
|
|
193
|
-
* {@link KoolbaseStorageError}, preferring the server's stable `code` and
|
|
194
|
-
* falling back to the HTTP status for older or uncoded responses. Always
|
|
195
|
-
* returns an error to throw.
|
|
196
|
-
*
|
|
197
|
-
* Status-fallback note: HTTP 409 covers both path_conflict and
|
|
198
|
-
* quota_exceeded. Without a `code` field, the mapper defaults 409 to
|
|
199
|
-
* {@link KoolbaseStorageConflictError} since path collisions are the more
|
|
200
|
-
* common case. Modern Koolbase servers always emit `code`, so this only
|
|
201
|
-
* matters for very old API responses or non-Koolbase 409s.
|
|
202
|
-
*/
|
|
203
|
-
function koolbaseStorageError(status, body, fallbackMessage = 'Storage request failed') {
|
|
204
|
-
const code = body?.code;
|
|
205
|
-
const message = body?.error ?? fallbackMessage;
|
|
206
|
-
// ─── code-first ───
|
|
207
|
-
switch (code) {
|
|
208
|
-
case 'path_conflict':
|
|
209
|
-
return new KoolbaseStorageConflictError(message, body?.path);
|
|
210
|
-
case 'quota_exceeded':
|
|
211
|
-
return new KoolbaseStorageQuotaError(message);
|
|
212
|
-
case 'file_too_large':
|
|
213
|
-
return new KoolbaseStorageFileTooLargeError(message);
|
|
214
|
-
case 'mime_not_allowed':
|
|
215
|
-
return new KoolbaseStorageMimeTypeError(message);
|
|
216
|
-
case 'metadata_invalid':
|
|
217
|
-
return new KoolbaseStorageMetadataInvalidError(message, body?.detail);
|
|
218
|
-
}
|
|
219
|
-
// ─── status fallback (pre-code servers or uncoded paths) ───
|
|
220
|
-
switch (status) {
|
|
221
|
-
case 409:
|
|
222
|
-
return new KoolbaseStorageConflictError(message);
|
|
223
|
-
case 413:
|
|
224
|
-
return new KoolbaseStorageFileTooLargeError(message);
|
|
225
|
-
case 415:
|
|
226
|
-
return new KoolbaseStorageMimeTypeError(message);
|
|
227
|
-
case 404:
|
|
228
|
-
return new KoolbaseStorageNotFoundError(message);
|
|
229
|
-
case 403:
|
|
230
|
-
return new KoolbaseStoragePermissionError(message);
|
|
231
|
-
case 400:
|
|
232
|
-
return new KoolbaseStorageValidationError(message);
|
|
233
|
-
}
|
|
234
|
-
return new KoolbaseStorageError(message, code);
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Convenience wrapper over {@link koolbaseStorageError} that decodes the
|
|
238
|
-
* response body for you. Use at call sites that have the raw `Response`.
|
|
239
|
-
*/
|
|
240
|
-
async function koolbaseStorageErrorFromResponse(res, fallbackMessage = 'Storage request failed') {
|
|
241
|
-
let body = {};
|
|
242
|
-
try {
|
|
243
|
-
body = await res.json();
|
|
244
|
-
}
|
|
245
|
-
catch (_) {
|
|
246
|
-
// body wasn't JSON — fall through with empty object
|
|
247
|
-
}
|
|
248
|
-
return koolbaseStorageError(res.status, body, fallbackMessage);
|
|
249
|
-
}
|
package/dist/storage.d.ts
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { KoolbaseConfig, UploadOptions, UploadResult, KoolbaseObject, KoolbaseObjectVersion, KoolbaseImageTransform } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Koolbase storage client — uploads, downloads, and deletes via presigned
|
|
4
|
-
* Cloudflare R2 URLs.
|
|
5
|
-
*
|
|
6
|
-
* Uploads are **safe-by-default** (v5+): an upload to a path where an object
|
|
7
|
-
* already exists is rejected with {@link KoolbaseStorageConflictError} unless
|
|
8
|
-
* `overwrite: true` is passed.
|
|
9
|
-
*/
|
|
10
|
-
export declare class KoolbaseStorage {
|
|
11
|
-
private config;
|
|
12
|
-
private getToken;
|
|
13
|
-
constructor(config: KoolbaseConfig, getToken: () => Promise<string | null>);
|
|
14
|
-
private buildHeaders;
|
|
15
|
-
/**
|
|
16
|
-
* Upload a file to a bucket. Returns the object metadata and a download URL.
|
|
17
|
-
*
|
|
18
|
-
* By default (`overwrite: false`), uploads to a path where an object
|
|
19
|
-
* already exists are **rejected** with a {@link KoolbaseStorageConflictError}.
|
|
20
|
-
* Catch it to prompt the user, then retry with `overwrite: true` to replace
|
|
21
|
-
* the existing object — or with a different `path`.
|
|
22
|
-
*
|
|
23
|
-
* Set `overwrite: true` for true upsert semantics — silently replace any
|
|
24
|
-
* existing object at this path.
|
|
25
|
-
*
|
|
26
|
-
* Pass `options.metadata` to attach arbitrary user-defined key/value pairs
|
|
27
|
-
* to the object at confirm time. Subject to the limits documented on
|
|
28
|
-
* {@link KoolbaseObject.metadata}; violations throw
|
|
29
|
-
* `KoolbaseStorageMetadataInvalidError`. On the `overwrite: true` path the
|
|
30
|
-
* metadata REPLACES any prior metadata at this path (matches GCS semantics).
|
|
31
|
-
* Use {@link updateMetadata} for post-upload merge changes.
|
|
32
|
-
*
|
|
33
|
-
* **Breaking change in v5.0.0**: the default flipped from silent overwrite
|
|
34
|
-
* (legacy behavior) to safe-by-default. If you previously relied on uploads
|
|
35
|
-
* overwriting silently, pass `overwrite: true` explicitly.
|
|
36
|
-
*/
|
|
37
|
-
upload(options: UploadOptions): Promise<UploadResult>;
|
|
38
|
-
/**
|
|
39
|
-
* Apply a partial metadata update to an existing object. Returns the
|
|
40
|
-
* post-update {@link KoolbaseObject} with the merged metadata.
|
|
41
|
-
*
|
|
42
|
-
* **Merge semantics** (mirrors the server's JSONB merge):
|
|
43
|
-
*
|
|
44
|
-
* - Keys with a non-null string value are SET — added if missing,
|
|
45
|
-
* replacing any existing value at the key otherwise.
|
|
46
|
-
* - Keys with `null` are DELETED from the stored metadata.
|
|
47
|
-
* - Keys ABSENT from `metadata` are untouched — pre-existing entries
|
|
48
|
-
* for those keys remain unchanged.
|
|
49
|
-
*
|
|
50
|
-
* Validation runs server-side against the same rules as upload-time
|
|
51
|
-
* metadata; violations throw `KoolbaseStorageMetadataInvalidError`,
|
|
52
|
-
* whose `detail` field names the failing key and rule. The check is
|
|
53
|
-
* performed against the projected post-merge state, so adding a key
|
|
54
|
-
* that would push the object past the 50-key or 8KB ceiling is
|
|
55
|
-
* rejected before the row is mutated.
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* // Add a tag, update an existing key, and drop another in one call:
|
|
59
|
-
* const updated = await Koolbase.storage.updateMetadata(
|
|
60
|
-
* 'photos',
|
|
61
|
-
* 'sunset.jpg',
|
|
62
|
-
* {
|
|
63
|
-
* category: 'landscape', // SET or UPDATE
|
|
64
|
-
* tag: 'sunset', // SET or UPDATE
|
|
65
|
-
* owner: null, // DELETE
|
|
66
|
-
* }
|
|
67
|
-
* );
|
|
68
|
-
* console.log(updated.metadata);
|
|
69
|
-
* // -> { category: 'landscape', tag: 'sunset' }
|
|
70
|
-
*/
|
|
71
|
-
updateMetadata(bucket: string, path: string, metadata: Record<string, string | null>): Promise<KoolbaseObject>;
|
|
72
|
-
/**
|
|
73
|
-
* Get a signed download URL for a file.
|
|
74
|
-
*/
|
|
75
|
-
getDownloadUrl(bucket: string, path: string, versionId?: string): Promise<string>;
|
|
76
|
-
/**
|
|
77
|
-
* Build the stable public CDN URL for a file in a public bucket.
|
|
78
|
-
*
|
|
79
|
-
* Returns the URL unconditionally — no check on whether the file
|
|
80
|
-
* exists or whether the bucket is actually public. Use when you
|
|
81
|
-
* know the file is in a public bucket and want the URL without a
|
|
82
|
-
* network round-trip (build-time URL generation, server-side
|
|
83
|
-
* rendering, batch image processing, etc.).
|
|
84
|
-
*
|
|
85
|
-
* For safer construction from an Object you already have, use
|
|
86
|
-
* {@link KoolbaseStorage.publicUrlForObject} — it checks the stored
|
|
87
|
-
* `r2Bucket` value and returns `null` when the object isn't in the
|
|
88
|
-
* public R2 bucket.
|
|
89
|
-
*/
|
|
90
|
-
static publicUrl(args: {
|
|
91
|
-
projectId: string;
|
|
92
|
-
bucket: string;
|
|
93
|
-
path: string;
|
|
94
|
-
/**
|
|
95
|
-
* Optional Cloudflare Image Transformations. Adds a `/cdn-cgi/image/`
|
|
96
|
-
* URL prefix; billed against the koolbase.com zone's free monthly
|
|
97
|
-
* allocation (5,000 unique transforms/month). Each unique combination
|
|
98
|
-
* of `path` + options is cached and billed only once per calendar month.
|
|
99
|
-
*/
|
|
100
|
-
transform?: KoolbaseImageTransform;
|
|
101
|
-
}): string;
|
|
102
|
-
/**
|
|
103
|
-
* Returns the stable CDN URL for an object when its bytes physically
|
|
104
|
-
* live in the public R2 bucket, `null` otherwise.
|
|
105
|
-
*
|
|
106
|
-
* Returns `null` for:
|
|
107
|
-
* - Files in private buckets (no public URL ever)
|
|
108
|
-
* - Legacy files in public buckets whose bytes still live in the
|
|
109
|
-
* private R2 bucket from before Gap #2 (no permanent URL until
|
|
110
|
-
* they're re-uploaded)
|
|
111
|
-
*
|
|
112
|
-
* The bucket name must be supplied because {@link KoolbaseObject}
|
|
113
|
-
* carries only the bucket ID, not its name. Typically the caller
|
|
114
|
-
* already knows which bucket they queried.
|
|
115
|
-
*/
|
|
116
|
-
static publicUrlForObject(obj: KoolbaseObject, bucket: string, options?: {
|
|
117
|
-
transform?: KoolbaseImageTransform;
|
|
118
|
-
}): string | null;
|
|
119
|
-
/**
|
|
120
|
-
* Builds a named-preset CDN URL. The preset is resolved at the Cloudflare
|
|
121
|
-
* edge by the koolbase-cdn-worker, which looks up
|
|
122
|
-
* `preset:{project_id}:{preset_name}` in Workers KV and applies the stored
|
|
123
|
-
* transformation options. Presets are managed in the dashboard under
|
|
124
|
-
* Storage → Presets.
|
|
125
|
-
*
|
|
126
|
-
* Unknown preset names yield a 404 at the edge — the URL itself always
|
|
127
|
-
* constructs successfully without a network round-trip.
|
|
128
|
-
*
|
|
129
|
-
* For safer construction from an Object you already have, use
|
|
130
|
-
* {@link KoolbaseStorage.publicUrlForObjectWithPreset} — it checks the
|
|
131
|
-
* stored `r2Bucket` value and returns `null` when the object isn't in the
|
|
132
|
-
* public R2 bucket.
|
|
133
|
-
*/
|
|
134
|
-
static publicUrlWithPreset(args: {
|
|
135
|
-
projectId: string;
|
|
136
|
-
presetName: string;
|
|
137
|
-
bucket: string;
|
|
138
|
-
path: string;
|
|
139
|
-
}): string;
|
|
140
|
-
/**
|
|
141
|
-
* Returns the named-preset CDN URL for the given object, or `null` if the
|
|
142
|
-
* object isn't in the public R2 bucket.
|
|
143
|
-
*/
|
|
144
|
-
static publicUrlForObjectWithPreset(obj: KoolbaseObject, bucket: string, presetName: string): string | null;
|
|
145
|
-
/**
|
|
146
|
-
* Delete a file from a bucket.
|
|
147
|
-
*/
|
|
148
|
-
delete(bucket: string, path: string, forcePurge?: boolean): Promise<void>;
|
|
149
|
-
/**
|
|
150
|
-
* List all versions of a file path, newest-first. Returns a flat list
|
|
151
|
-
* mixing the current row (with `isCurrent: true`) and all history
|
|
152
|
-
* rows. Delete markers are included so callers can render the full
|
|
153
|
-
* timeline; filter client-side to hide them if the UI only wants
|
|
154
|
-
* restorable versions.
|
|
155
|
-
*
|
|
156
|
-
* Returns an empty array (not an error) when the path has no history
|
|
157
|
-
* and no current row.
|
|
158
|
-
*/
|
|
159
|
-
listVersions(bucket: string, path: string): Promise<KoolbaseObjectVersion[]>;
|
|
160
|
-
/**
|
|
161
|
-
* Fetch metadata for a single version by id. Works against both the
|
|
162
|
-
* current row and any history row — the response's `isCurrent` tells
|
|
163
|
-
* you which.
|
|
164
|
-
*/
|
|
165
|
-
getVersion(bucket: string, path: string, versionId: string): Promise<KoolbaseObjectVersion>;
|
|
166
|
-
/**
|
|
167
|
-
* Bring a history version back as the current version. The
|
|
168
|
-
* previously-current row (if any) is snapshotted into history first,
|
|
169
|
-
* so this operation is itself a versioned event you can undo. The
|
|
170
|
-
* restored row gets a freshly-minted version_id; the target stays in
|
|
171
|
-
* history at its original version_id.
|
|
172
|
-
*
|
|
173
|
-
* Throws if the bucket has versioning off, if the target is the
|
|
174
|
-
* already-current version, or if the target is a delete marker.
|
|
175
|
-
*/
|
|
176
|
-
restoreVersion(bucket: string, path: string, versionId: string): Promise<KoolbaseObject>;
|
|
177
|
-
/**
|
|
178
|
-
* Hard-remove a single history version — both the metadata row and
|
|
179
|
-
* the .versions/ R2 bytes (or just the row, for delete markers).
|
|
180
|
-
* Refuses to operate on the current version; use {@link delete} with
|
|
181
|
-
* `forcePurge: true` to wipe everything for a path.
|
|
182
|
-
*/
|
|
183
|
-
purgeVersion(bucket: string, path: string, versionId: string): Promise<void>;
|
|
184
|
-
}
|