@moogodev/client 0.1.5 → 0.1.7
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/dist/client.d.ts +3 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +37 -14
- package/dist/errors.js +5 -5
- package/dist/esm/client.d.ts +3 -1
- package/dist/esm/client.d.ts.map +1 -1
- package/dist/esm/client.js +37 -14
- package/dist/esm/errors.js +5 -5
- package/package.json +1 -1
- package/src/client.ts +40 -14
- package/src/errors.ts +5 -5
package/dist/client.d.ts
CHANGED
|
@@ -54,8 +54,10 @@ export declare class MoogoClient {
|
|
|
54
54
|
private requestSQL;
|
|
55
55
|
/** List all buckets in the project */
|
|
56
56
|
listBuckets(): Promise<Bucket[]>;
|
|
57
|
-
/** Get bucket info including usage stats */
|
|
57
|
+
/** Get bucket info including usage stats (by bucket ID) */
|
|
58
58
|
getBucketInfo(bucketId: string): Promise<BucketInfoResponse>;
|
|
59
|
+
/** Get bucket info by name (resolves name to ID) */
|
|
60
|
+
getBucketInfoByName(bucketName: string): Promise<BucketInfoResponse>;
|
|
59
61
|
/** Create a new bucket */
|
|
60
62
|
createBucket(request: CreateBucketRequest): Promise<Bucket>;
|
|
61
63
|
/** Update bucket settings */
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,MAAM,EACN,mBAAmB,EACnB,mBAAmB,EAEnB,kBAAkB,EAClB,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,EAEjB,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EAGxB,YAAY,EACZ,aAAa,EACb,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,mBAA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AC;IAOlG,oCAAoC;IAC9B,IAAI,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,GAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAO,GAAG,OAAO,CAAC,YAAY,CAAC;IAO/F,uDAAuD;IACjD,WAAW,CAAC,OAAO,EAAE,kBAAkB,EAAE,OAAO,GAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAO,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAOpH,0DAA0D;IACpD,WAAW,CAAC,OAAO,GAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAO,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,IAAI,CAAC;QAAC,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC;CAO/G;AAED,mFAAmF;AACnF,wBAAgB,mBAAmB,CAAC,MAAM,EAAE;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,GAAG,WAAW,CASd;AAED,iFAAiF;AACjF,wBAAgB,eAAe,CAAC,MAAM,EAAE;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,GAAG,WAAW,CAQd;AAED,yEAAyE;AACzE,wBAAgB,mBAAmB,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,WAAW,CAsCzF"}
|
package/dist/client.js
CHANGED
|
@@ -232,11 +232,20 @@ class MoogoClient {
|
|
|
232
232
|
const response = await this.requestStorage('GET', this.getCatalogPath());
|
|
233
233
|
return response.buckets;
|
|
234
234
|
}
|
|
235
|
-
/** Get bucket info including usage stats */
|
|
235
|
+
/** Get bucket info including usage stats (by bucket ID) */
|
|
236
236
|
async getBucketInfo(bucketId) {
|
|
237
237
|
const response = await this.requestStorage('GET', `${this.getCatalogPath()}/${bucketId}`);
|
|
238
238
|
return response;
|
|
239
239
|
}
|
|
240
|
+
/** Get bucket info by name (resolves name to ID) */
|
|
241
|
+
async getBucketInfoByName(bucketName) {
|
|
242
|
+
const buckets = await this.listBuckets();
|
|
243
|
+
const bucket = buckets.find(b => b.name === bucketName);
|
|
244
|
+
if (!bucket) {
|
|
245
|
+
throw new Error(`Bucket not found: ${bucketName}`);
|
|
246
|
+
}
|
|
247
|
+
return this.getBucketInfo(bucket.id);
|
|
248
|
+
}
|
|
240
249
|
/** Create a new bucket */
|
|
241
250
|
async createBucket(request) {
|
|
242
251
|
const response = await this.requestStorage('POST', this.getCatalogPath(), { body: JSON.stringify(request) });
|
|
@@ -266,7 +275,7 @@ class MoogoClient {
|
|
|
266
275
|
*/
|
|
267
276
|
async upload(key, data, options = {}) {
|
|
268
277
|
const { bucket = 'default', contentType, cacheControl, onProgress, signal } = options;
|
|
269
|
-
const path = `/p/${this.projectId}/${encodeURIComponent(key)}`;
|
|
278
|
+
const path = `/p/${this.projectId}/bucket/${encodeURIComponent(key)}`;
|
|
270
279
|
const query = {};
|
|
271
280
|
if (bucket !== 'default')
|
|
272
281
|
query.bucket = bucket;
|
|
@@ -362,7 +371,7 @@ class MoogoClient {
|
|
|
362
371
|
/** Download an object */
|
|
363
372
|
async download(key, options = {}) {
|
|
364
373
|
const { bucket = 'default', signal, range } = options;
|
|
365
|
-
const path = `/p/${this.projectId}/${encodeURIComponent(key)}`;
|
|
374
|
+
const path = `/p/${this.projectId}/bucket/${encodeURIComponent(key)}`;
|
|
366
375
|
const query = {};
|
|
367
376
|
if (bucket !== 'default')
|
|
368
377
|
query.bucket = bucket;
|
|
@@ -423,7 +432,7 @@ class MoogoClient {
|
|
|
423
432
|
/** Get object metadata (HEAD request) */
|
|
424
433
|
async headObject(key, options = {}) {
|
|
425
434
|
const { bucket = 'default', signal } = options;
|
|
426
|
-
const path = `/p/${this.projectId}/${encodeURIComponent(key)}`;
|
|
435
|
+
const path = `/p/${this.projectId}/bucket/${encodeURIComponent(key)}`;
|
|
427
436
|
const query = {};
|
|
428
437
|
if (bucket !== 'default')
|
|
429
438
|
query.bucket = bucket;
|
|
@@ -466,7 +475,7 @@ class MoogoClient {
|
|
|
466
475
|
/** Delete an object */
|
|
467
476
|
async deleteObject(key, options = {}) {
|
|
468
477
|
const { bucket = 'default', signal } = options;
|
|
469
|
-
const path = `/p/${this.projectId}/${encodeURIComponent(key)}`;
|
|
478
|
+
const path = `/p/${this.projectId}/bucket/${encodeURIComponent(key)}`;
|
|
470
479
|
const query = {};
|
|
471
480
|
if (bucket !== 'default')
|
|
472
481
|
query.bucket = bucket;
|
|
@@ -494,7 +503,7 @@ class MoogoClient {
|
|
|
494
503
|
/** Get a presigned URL for an object */
|
|
495
504
|
async getPresignedUrl(key, request, options = {}) {
|
|
496
505
|
const { bucket = 'default', signal } = options;
|
|
497
|
-
const path = `/p/${this.projectId}/${encodeURIComponent(key)}/sign`;
|
|
506
|
+
const path = `/p/${this.projectId}/bucket/${encodeURIComponent(key)}/sign`;
|
|
498
507
|
const query = {};
|
|
499
508
|
if (bucket !== 'default')
|
|
500
509
|
query.bucket = bucket;
|
|
@@ -507,7 +516,7 @@ class MoogoClient {
|
|
|
507
516
|
/** Create a signed upload URL (returns upload URL + object metadata) */
|
|
508
517
|
async createSignedUpload(key, request, options = {}) {
|
|
509
518
|
const { bucket = 'default', signal } = options;
|
|
510
|
-
const path = `/p/${this.projectId}/${encodeURIComponent(key)}/sign-upload`;
|
|
519
|
+
const path = `/p/${this.projectId}/bucket/${encodeURIComponent(key)}/sign-upload`;
|
|
511
520
|
const query = {};
|
|
512
521
|
if (bucket !== 'default')
|
|
513
522
|
query.bucket = bucket;
|
|
@@ -520,7 +529,7 @@ class MoogoClient {
|
|
|
520
529
|
/** Update object metadata (visibility, key) */
|
|
521
530
|
async updateObject(key, updates, options = {}) {
|
|
522
531
|
const { bucket = 'default', signal } = options;
|
|
523
|
-
const path = `/p/${this.projectId}/${encodeURIComponent(key)}`;
|
|
532
|
+
const path = `/p/${this.projectId}/bucket/${encodeURIComponent(key)}`;
|
|
524
533
|
const query = {};
|
|
525
534
|
if (bucket !== 'default')
|
|
526
535
|
query.bucket = bucket;
|
|
@@ -630,11 +639,24 @@ function createSQLClient(config) {
|
|
|
630
639
|
/** Convenience function to create a client from environment variables */
|
|
631
640
|
function createClientFromEnv(env) {
|
|
632
641
|
const getEnv = (key) => env?.[key] ?? process.env[key];
|
|
633
|
-
//
|
|
634
|
-
|
|
635
|
-
const
|
|
642
|
+
// Deprecation warnings for old env var names (log once per process)
|
|
643
|
+
const warned = new Set();
|
|
644
|
+
const warnDeprecated = (oldKey, newKey) => {
|
|
645
|
+
if (process.env[oldKey] && !process.env[newKey] && !warned.has(oldKey)) {
|
|
646
|
+
console.warn(`[moogo] Deprecation: ${oldKey} is deprecated, use ${newKey} instead`);
|
|
647
|
+
warned.add(oldKey);
|
|
648
|
+
}
|
|
649
|
+
};
|
|
650
|
+
warnDeprecated('MOOGO_API_URL', 'MOOGO_BASE_URL');
|
|
651
|
+
warnDeprecated('MOOGO_BUCKET_ENDPOINT', 'MOOGO_BASE_URL');
|
|
652
|
+
warnDeprecated('MOOGO_BUCKET_ACCESS_KEY_ID', 'MOOGO_STORAGE_ACCESS_KEY_ID');
|
|
653
|
+
warnDeprecated('MOOGO_BUCKET_SECRET_KEY', 'MOOGO_STORAGE_SECRET_KEY');
|
|
654
|
+
warnDeprecated('MOOGO_PROJECT_KEY', 'MOOGO_SQL_KEY');
|
|
655
|
+
// Resolve base URL: new names first, then legacy
|
|
656
|
+
const rawBase = getEnv('MOOGO_BASE_URL') || getEnv('MOOGO_API_URL') || getEnv('MOOGO_BUCKET_ENDPOINT') || 'https://api.moogo.dev';
|
|
636
657
|
const baseUrl = rawBase.replace(/\/p\/[^/]+\/bucket.*$/, '').replace(/\/+$/, '');
|
|
637
|
-
|
|
658
|
+
// SQL key (new name first)
|
|
659
|
+
const projectKey = getEnv('MOOGO_SQL_KEY') || getEnv('MOOGO_PROJECT_KEY');
|
|
638
660
|
if (projectKey) {
|
|
639
661
|
return new MoogoClient({
|
|
640
662
|
baseUrl,
|
|
@@ -642,10 +664,11 @@ function createClientFromEnv(env) {
|
|
|
642
664
|
projectKey,
|
|
643
665
|
});
|
|
644
666
|
}
|
|
667
|
+
// Storage keys (new names first)
|
|
645
668
|
return new MoogoClient({
|
|
646
669
|
baseUrl,
|
|
647
670
|
projectId: getEnv('MOOGO_PROJECT_ID'),
|
|
648
|
-
accessKeyId: getEnv('MOOGO_BUCKET_ACCESS_KEY_ID'),
|
|
649
|
-
secretKey: getEnv('MOOGO_BUCKET_SECRET_KEY'),
|
|
671
|
+
accessKeyId: getEnv('MOOGO_STORAGE_ACCESS_KEY_ID') || getEnv('MOOGO_BUCKET_ACCESS_KEY_ID'),
|
|
672
|
+
secretKey: getEnv('MOOGO_STORAGE_SECRET_KEY') || getEnv('MOOGO_BUCKET_SECRET_KEY'),
|
|
650
673
|
});
|
|
651
674
|
}
|
package/dist/errors.js
CHANGED
|
@@ -94,7 +94,7 @@ class BodyTooLargeError extends MoogoError {
|
|
|
94
94
|
exports.BodyTooLargeError = BodyTooLargeError;
|
|
95
95
|
class ObjectTooLargeError extends MoogoError {
|
|
96
96
|
constructor(detail) {
|
|
97
|
-
super('object_too_large', 'Object over the bucket max size', 413, detail);
|
|
97
|
+
super('object_too_large', 'Object over the bucket max size. Check bucket max_object_size_bytes (default 250 MB). Use `PATCH /buckets/{id}` to increase, or split the file.', 413, detail);
|
|
98
98
|
this.name = 'ObjectTooLargeError';
|
|
99
99
|
Object.setPrototypeOf(this, ObjectTooLargeError.prototype);
|
|
100
100
|
}
|
|
@@ -110,7 +110,7 @@ class UnsupportedMediaTypeError extends MoogoError {
|
|
|
110
110
|
exports.UnsupportedMediaTypeError = UnsupportedMediaTypeError;
|
|
111
111
|
class QuotaExceededError extends MoogoError {
|
|
112
112
|
constructor(detail) {
|
|
113
|
-
super('quota_exceeded', 'Project or bucket storage would go over quota', 409, detail);
|
|
113
|
+
super('quota_exceeded', 'Project or bucket storage would go over quota. Delete objects or run `moogo db vacuum` / `POST /maintenance` to reclaim space.', 409, detail);
|
|
114
114
|
this.name = 'QuotaExceededError';
|
|
115
115
|
Object.setPrototypeOf(this, QuotaExceededError.prototype);
|
|
116
116
|
}
|
|
@@ -134,7 +134,7 @@ class LinkExpiredError extends MoogoError {
|
|
|
134
134
|
exports.LinkExpiredError = LinkExpiredError;
|
|
135
135
|
class NotFoundError extends MoogoError {
|
|
136
136
|
constructor(detail) {
|
|
137
|
-
super('not_found', 'Bucket/object missing or not published', 404, detail);
|
|
137
|
+
super('not_found', 'Bucket/object missing or not published. For public URLs: ensure object is published (PATCH is_public: true) and check key spelling. Private objects return 404 on /pub/ routes.', 404, detail);
|
|
138
138
|
this.name = 'NotFoundError';
|
|
139
139
|
Object.setPrototypeOf(this, NotFoundError.prototype);
|
|
140
140
|
}
|
|
@@ -160,7 +160,7 @@ class RateLimitedError extends MoogoError {
|
|
|
160
160
|
retryAfter;
|
|
161
161
|
resetAt;
|
|
162
162
|
constructor(retryAfter, resetAt, detail) {
|
|
163
|
-
super('rate_limited',
|
|
163
|
+
super('rate_limited', `Too many requests. Retry after ${retryAfter}s (reset at ${resetAt ? new Date(resetAt * 1000).toISOString() : 'unknown'}). Use X-RateLimit-Reset header for precise timing.`, 429, detail);
|
|
164
164
|
this.name = 'RateLimitedError';
|
|
165
165
|
this.retryAfter = retryAfter;
|
|
166
166
|
this.resetAt = resetAt;
|
|
@@ -203,7 +203,7 @@ class UnauthorizedError extends MoogoError {
|
|
|
203
203
|
constructor(detail) {
|
|
204
204
|
const hint = detail
|
|
205
205
|
? detail
|
|
206
|
-
: 'Authentication required.
|
|
206
|
+
: 'Authentication required. Storage: set MOOGO_BASE_URL (or MOOGO_API_URL), MOOGO_PROJECT_ID, MOOGO_STORAGE_ACCESS_KEY_ID, MOOGO_STORAGE_SECRET_KEY. SQL: set MOOGO_SQL_KEY (or MOOGO_PROJECT_KEY). Old names (MOOGO_BUCKET_*) still work but deprecated.';
|
|
207
207
|
super('unauthorized', hint, 401, detail);
|
|
208
208
|
this.name = 'UnauthorizedError';
|
|
209
209
|
Object.setPrototypeOf(this, UnauthorizedError.prototype);
|
package/dist/esm/client.d.ts
CHANGED
|
@@ -54,8 +54,10 @@ export declare class MoogoClient {
|
|
|
54
54
|
private requestSQL;
|
|
55
55
|
/** List all buckets in the project */
|
|
56
56
|
listBuckets(): Promise<Bucket[]>;
|
|
57
|
-
/** Get bucket info including usage stats */
|
|
57
|
+
/** Get bucket info including usage stats (by bucket ID) */
|
|
58
58
|
getBucketInfo(bucketId: string): Promise<BucketInfoResponse>;
|
|
59
|
+
/** Get bucket info by name (resolves name to ID) */
|
|
60
|
+
getBucketInfoByName(bucketName: string): Promise<BucketInfoResponse>;
|
|
59
61
|
/** Create a new bucket */
|
|
60
62
|
createBucket(request: CreateBucketRequest): Promise<Bucket>;
|
|
61
63
|
/** Update bucket settings */
|
package/dist/esm/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,MAAM,EACN,mBAAmB,EACnB,mBAAmB,EAEnB,kBAAkB,EAClB,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,EAEjB,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EAGxB,YAAY,EACZ,aAAa,EACb,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,mBAA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AAC;IAOlG,oCAAoC;IAC9B,IAAI,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,GAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAO,GAAG,OAAO,CAAC,YAAY,CAAC;IAO/F,uDAAuD;IACjD,WAAW,CAAC,OAAO,EAAE,kBAAkB,EAAE,OAAO,GAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAO,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAOpH,0DAA0D;IACpD,WAAW,CAAC,OAAO,GAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAO,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,IAAI,CAAC;QAAC,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC;CAO/G;AAED,mFAAmF;AACnF,wBAAgB,mBAAmB,CAAC,MAAM,EAAE;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,GAAG,WAAW,CASd;AAED,iFAAiF;AACjF,wBAAgB,eAAe,CAAC,MAAM,EAAE;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,GAAG,WAAW,CAQd;AAED,yEAAyE;AACzE,wBAAgB,mBAAmB,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,WAAW,CAsCzF"}
|
package/dist/esm/client.js
CHANGED
|
@@ -226,11 +226,20 @@ export class MoogoClient {
|
|
|
226
226
|
const response = await this.requestStorage('GET', this.getCatalogPath());
|
|
227
227
|
return response.buckets;
|
|
228
228
|
}
|
|
229
|
-
/** Get bucket info including usage stats */
|
|
229
|
+
/** Get bucket info including usage stats (by bucket ID) */
|
|
230
230
|
async getBucketInfo(bucketId) {
|
|
231
231
|
const response = await this.requestStorage('GET', `${this.getCatalogPath()}/${bucketId}`);
|
|
232
232
|
return response;
|
|
233
233
|
}
|
|
234
|
+
/** Get bucket info by name (resolves name to ID) */
|
|
235
|
+
async getBucketInfoByName(bucketName) {
|
|
236
|
+
const buckets = await this.listBuckets();
|
|
237
|
+
const bucket = buckets.find(b => b.name === bucketName);
|
|
238
|
+
if (!bucket) {
|
|
239
|
+
throw new Error(`Bucket not found: ${bucketName}`);
|
|
240
|
+
}
|
|
241
|
+
return this.getBucketInfo(bucket.id);
|
|
242
|
+
}
|
|
234
243
|
/** Create a new bucket */
|
|
235
244
|
async createBucket(request) {
|
|
236
245
|
const response = await this.requestStorage('POST', this.getCatalogPath(), { body: JSON.stringify(request) });
|
|
@@ -260,7 +269,7 @@ export class MoogoClient {
|
|
|
260
269
|
*/
|
|
261
270
|
async upload(key, data, options = {}) {
|
|
262
271
|
const { bucket = 'default', contentType, cacheControl, onProgress, signal } = options;
|
|
263
|
-
const path = `/p/${this.projectId}/${encodeURIComponent(key)}`;
|
|
272
|
+
const path = `/p/${this.projectId}/bucket/${encodeURIComponent(key)}`;
|
|
264
273
|
const query = {};
|
|
265
274
|
if (bucket !== 'default')
|
|
266
275
|
query.bucket = bucket;
|
|
@@ -356,7 +365,7 @@ export class MoogoClient {
|
|
|
356
365
|
/** Download an object */
|
|
357
366
|
async download(key, options = {}) {
|
|
358
367
|
const { bucket = 'default', signal, range } = options;
|
|
359
|
-
const path = `/p/${this.projectId}/${encodeURIComponent(key)}`;
|
|
368
|
+
const path = `/p/${this.projectId}/bucket/${encodeURIComponent(key)}`;
|
|
360
369
|
const query = {};
|
|
361
370
|
if (bucket !== 'default')
|
|
362
371
|
query.bucket = bucket;
|
|
@@ -417,7 +426,7 @@ export class MoogoClient {
|
|
|
417
426
|
/** Get object metadata (HEAD request) */
|
|
418
427
|
async headObject(key, options = {}) {
|
|
419
428
|
const { bucket = 'default', signal } = options;
|
|
420
|
-
const path = `/p/${this.projectId}/${encodeURIComponent(key)}`;
|
|
429
|
+
const path = `/p/${this.projectId}/bucket/${encodeURIComponent(key)}`;
|
|
421
430
|
const query = {};
|
|
422
431
|
if (bucket !== 'default')
|
|
423
432
|
query.bucket = bucket;
|
|
@@ -460,7 +469,7 @@ export class MoogoClient {
|
|
|
460
469
|
/** Delete an object */
|
|
461
470
|
async deleteObject(key, options = {}) {
|
|
462
471
|
const { bucket = 'default', signal } = options;
|
|
463
|
-
const path = `/p/${this.projectId}/${encodeURIComponent(key)}`;
|
|
472
|
+
const path = `/p/${this.projectId}/bucket/${encodeURIComponent(key)}`;
|
|
464
473
|
const query = {};
|
|
465
474
|
if (bucket !== 'default')
|
|
466
475
|
query.bucket = bucket;
|
|
@@ -488,7 +497,7 @@ export class MoogoClient {
|
|
|
488
497
|
/** Get a presigned URL for an object */
|
|
489
498
|
async getPresignedUrl(key, request, options = {}) {
|
|
490
499
|
const { bucket = 'default', signal } = options;
|
|
491
|
-
const path = `/p/${this.projectId}/${encodeURIComponent(key)}/sign`;
|
|
500
|
+
const path = `/p/${this.projectId}/bucket/${encodeURIComponent(key)}/sign`;
|
|
492
501
|
const query = {};
|
|
493
502
|
if (bucket !== 'default')
|
|
494
503
|
query.bucket = bucket;
|
|
@@ -501,7 +510,7 @@ export class MoogoClient {
|
|
|
501
510
|
/** Create a signed upload URL (returns upload URL + object metadata) */
|
|
502
511
|
async createSignedUpload(key, request, options = {}) {
|
|
503
512
|
const { bucket = 'default', signal } = options;
|
|
504
|
-
const path = `/p/${this.projectId}/${encodeURIComponent(key)}/sign-upload`;
|
|
513
|
+
const path = `/p/${this.projectId}/bucket/${encodeURIComponent(key)}/sign-upload`;
|
|
505
514
|
const query = {};
|
|
506
515
|
if (bucket !== 'default')
|
|
507
516
|
query.bucket = bucket;
|
|
@@ -514,7 +523,7 @@ export class MoogoClient {
|
|
|
514
523
|
/** Update object metadata (visibility, key) */
|
|
515
524
|
async updateObject(key, updates, options = {}) {
|
|
516
525
|
const { bucket = 'default', signal } = options;
|
|
517
|
-
const path = `/p/${this.projectId}/${encodeURIComponent(key)}`;
|
|
526
|
+
const path = `/p/${this.projectId}/bucket/${encodeURIComponent(key)}`;
|
|
518
527
|
const query = {};
|
|
519
528
|
if (bucket !== 'default')
|
|
520
529
|
query.bucket = bucket;
|
|
@@ -623,11 +632,24 @@ export function createSQLClient(config) {
|
|
|
623
632
|
/** Convenience function to create a client from environment variables */
|
|
624
633
|
export function createClientFromEnv(env) {
|
|
625
634
|
const getEnv = (key) => env?.[key] ?? process.env[key];
|
|
626
|
-
//
|
|
627
|
-
|
|
628
|
-
const
|
|
635
|
+
// Deprecation warnings for old env var names (log once per process)
|
|
636
|
+
const warned = new Set();
|
|
637
|
+
const warnDeprecated = (oldKey, newKey) => {
|
|
638
|
+
if (process.env[oldKey] && !process.env[newKey] && !warned.has(oldKey)) {
|
|
639
|
+
console.warn(`[moogo] Deprecation: ${oldKey} is deprecated, use ${newKey} instead`);
|
|
640
|
+
warned.add(oldKey);
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
warnDeprecated('MOOGO_API_URL', 'MOOGO_BASE_URL');
|
|
644
|
+
warnDeprecated('MOOGO_BUCKET_ENDPOINT', 'MOOGO_BASE_URL');
|
|
645
|
+
warnDeprecated('MOOGO_BUCKET_ACCESS_KEY_ID', 'MOOGO_STORAGE_ACCESS_KEY_ID');
|
|
646
|
+
warnDeprecated('MOOGO_BUCKET_SECRET_KEY', 'MOOGO_STORAGE_SECRET_KEY');
|
|
647
|
+
warnDeprecated('MOOGO_PROJECT_KEY', 'MOOGO_SQL_KEY');
|
|
648
|
+
// Resolve base URL: new names first, then legacy
|
|
649
|
+
const rawBase = getEnv('MOOGO_BASE_URL') || getEnv('MOOGO_API_URL') || getEnv('MOOGO_BUCKET_ENDPOINT') || 'https://api.moogo.dev';
|
|
629
650
|
const baseUrl = rawBase.replace(/\/p\/[^/]+\/bucket.*$/, '').replace(/\/+$/, '');
|
|
630
|
-
|
|
651
|
+
// SQL key (new name first)
|
|
652
|
+
const projectKey = getEnv('MOOGO_SQL_KEY') || getEnv('MOOGO_PROJECT_KEY');
|
|
631
653
|
if (projectKey) {
|
|
632
654
|
return new MoogoClient({
|
|
633
655
|
baseUrl,
|
|
@@ -635,10 +657,11 @@ export function createClientFromEnv(env) {
|
|
|
635
657
|
projectKey,
|
|
636
658
|
});
|
|
637
659
|
}
|
|
660
|
+
// Storage keys (new names first)
|
|
638
661
|
return new MoogoClient({
|
|
639
662
|
baseUrl,
|
|
640
663
|
projectId: getEnv('MOOGO_PROJECT_ID'),
|
|
641
|
-
accessKeyId: getEnv('MOOGO_BUCKET_ACCESS_KEY_ID'),
|
|
642
|
-
secretKey: getEnv('MOOGO_BUCKET_SECRET_KEY'),
|
|
664
|
+
accessKeyId: getEnv('MOOGO_STORAGE_ACCESS_KEY_ID') || getEnv('MOOGO_BUCKET_ACCESS_KEY_ID'),
|
|
665
|
+
secretKey: getEnv('MOOGO_STORAGE_SECRET_KEY') || getEnv('MOOGO_BUCKET_SECRET_KEY'),
|
|
643
666
|
});
|
|
644
667
|
}
|
package/dist/esm/errors.js
CHANGED
|
@@ -81,7 +81,7 @@ export class BodyTooLargeError extends MoogoError {
|
|
|
81
81
|
}
|
|
82
82
|
export class ObjectTooLargeError extends MoogoError {
|
|
83
83
|
constructor(detail) {
|
|
84
|
-
super('object_too_large', 'Object over the bucket max size', 413, detail);
|
|
84
|
+
super('object_too_large', 'Object over the bucket max size. Check bucket max_object_size_bytes (default 250 MB). Use `PATCH /buckets/{id}` to increase, or split the file.', 413, detail);
|
|
85
85
|
this.name = 'ObjectTooLargeError';
|
|
86
86
|
Object.setPrototypeOf(this, ObjectTooLargeError.prototype);
|
|
87
87
|
}
|
|
@@ -95,7 +95,7 @@ export class UnsupportedMediaTypeError extends MoogoError {
|
|
|
95
95
|
}
|
|
96
96
|
export class QuotaExceededError extends MoogoError {
|
|
97
97
|
constructor(detail) {
|
|
98
|
-
super('quota_exceeded', 'Project or bucket storage would go over quota', 409, detail);
|
|
98
|
+
super('quota_exceeded', 'Project or bucket storage would go over quota. Delete objects or run `moogo db vacuum` / `POST /maintenance` to reclaim space.', 409, detail);
|
|
99
99
|
this.name = 'QuotaExceededError';
|
|
100
100
|
Object.setPrototypeOf(this, QuotaExceededError.prototype);
|
|
101
101
|
}
|
|
@@ -116,7 +116,7 @@ export class LinkExpiredError extends MoogoError {
|
|
|
116
116
|
}
|
|
117
117
|
export class NotFoundError extends MoogoError {
|
|
118
118
|
constructor(detail) {
|
|
119
|
-
super('not_found', 'Bucket/object missing or not published', 404, detail);
|
|
119
|
+
super('not_found', 'Bucket/object missing or not published. For public URLs: ensure object is published (PATCH is_public: true) and check key spelling. Private objects return 404 on /pub/ routes.', 404, detail);
|
|
120
120
|
this.name = 'NotFoundError';
|
|
121
121
|
Object.setPrototypeOf(this, NotFoundError.prototype);
|
|
122
122
|
}
|
|
@@ -139,7 +139,7 @@ export class RateLimitedError extends MoogoError {
|
|
|
139
139
|
retryAfter;
|
|
140
140
|
resetAt;
|
|
141
141
|
constructor(retryAfter, resetAt, detail) {
|
|
142
|
-
super('rate_limited',
|
|
142
|
+
super('rate_limited', `Too many requests. Retry after ${retryAfter}s (reset at ${resetAt ? new Date(resetAt * 1000).toISOString() : 'unknown'}). Use X-RateLimit-Reset header for precise timing.`, 429, detail);
|
|
143
143
|
this.name = 'RateLimitedError';
|
|
144
144
|
this.retryAfter = retryAfter;
|
|
145
145
|
this.resetAt = resetAt;
|
|
@@ -178,7 +178,7 @@ export class UnauthorizedError extends MoogoError {
|
|
|
178
178
|
constructor(detail) {
|
|
179
179
|
const hint = detail
|
|
180
180
|
? detail
|
|
181
|
-
: 'Authentication required.
|
|
181
|
+
: 'Authentication required. Storage: set MOOGO_BASE_URL (or MOOGO_API_URL), MOOGO_PROJECT_ID, MOOGO_STORAGE_ACCESS_KEY_ID, MOOGO_STORAGE_SECRET_KEY. SQL: set MOOGO_SQL_KEY (or MOOGO_PROJECT_KEY). Old names (MOOGO_BUCKET_*) still work but deprecated.';
|
|
182
182
|
super('unauthorized', hint, 401, detail);
|
|
183
183
|
this.name = 'UnauthorizedError';
|
|
184
184
|
Object.setPrototypeOf(this, UnauthorizedError.prototype);
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -304,7 +304,7 @@ export class MoogoClient {
|
|
|
304
304
|
return response.buckets;
|
|
305
305
|
}
|
|
306
306
|
|
|
307
|
-
/** Get bucket info including usage stats */
|
|
307
|
+
/** Get bucket info including usage stats (by bucket ID) */
|
|
308
308
|
async getBucketInfo(bucketId: string): Promise<BucketInfoResponse> {
|
|
309
309
|
const response = await this.requestStorage<BucketInfoResponse>(
|
|
310
310
|
'GET',
|
|
@@ -313,6 +313,16 @@ export class MoogoClient {
|
|
|
313
313
|
return response;
|
|
314
314
|
}
|
|
315
315
|
|
|
316
|
+
/** Get bucket info by name (resolves name to ID) */
|
|
317
|
+
async getBucketInfoByName(bucketName: string): Promise<BucketInfoResponse> {
|
|
318
|
+
const buckets = await this.listBuckets();
|
|
319
|
+
const bucket = buckets.find(b => b.name === bucketName);
|
|
320
|
+
if (!bucket) {
|
|
321
|
+
throw new Error(`Bucket not found: ${bucketName}`);
|
|
322
|
+
}
|
|
323
|
+
return this.getBucketInfo(bucket.id);
|
|
324
|
+
}
|
|
325
|
+
|
|
316
326
|
/** Create a new bucket */
|
|
317
327
|
async createBucket(request: CreateBucketRequest): Promise<Bucket> {
|
|
318
328
|
const response = await this.requestStorage<{ success: true; bucket: Bucket }>(
|
|
@@ -370,7 +380,7 @@ export class MoogoClient {
|
|
|
370
380
|
): Promise<UploadResponse> {
|
|
371
381
|
const { bucket = 'default', contentType, cacheControl, onProgress, signal } = options;
|
|
372
382
|
|
|
373
|
-
const path = `/p/${this.projectId}/${encodeURIComponent(key)}`;
|
|
383
|
+
const path = `/p/${this.projectId}/bucket/${encodeURIComponent(key)}`;
|
|
374
384
|
const query: Record<string, string> = {};
|
|
375
385
|
if (bucket !== 'default') query.bucket = bucket;
|
|
376
386
|
|
|
@@ -481,7 +491,7 @@ export class MoogoClient {
|
|
|
481
491
|
): Promise<Response> {
|
|
482
492
|
const { bucket = 'default', signal, range } = options;
|
|
483
493
|
|
|
484
|
-
const path = `/p/${this.projectId}/${encodeURIComponent(key)}`;
|
|
494
|
+
const path = `/p/${this.projectId}/bucket/${encodeURIComponent(key)}`;
|
|
485
495
|
const query: Record<string, string> = {};
|
|
486
496
|
if (bucket !== 'default') query.bucket = bucket;
|
|
487
497
|
|
|
@@ -556,7 +566,7 @@ export class MoogoClient {
|
|
|
556
566
|
): Promise<{ headers: Headers; exists: boolean }> {
|
|
557
567
|
const { bucket = 'default', signal } = options;
|
|
558
568
|
|
|
559
|
-
const path = `/p/${this.projectId}/${encodeURIComponent(key)}`;
|
|
569
|
+
const path = `/p/${this.projectId}/bucket/${encodeURIComponent(key)}`;
|
|
560
570
|
const query: Record<string, string> = {};
|
|
561
571
|
if (bucket !== 'default') query.bucket = bucket;
|
|
562
572
|
|
|
@@ -607,7 +617,7 @@ export class MoogoClient {
|
|
|
607
617
|
async deleteObject(key: string, options: { bucket?: string; signal?: AbortSignal } = {}): Promise<void> {
|
|
608
618
|
const { bucket = 'default', signal } = options;
|
|
609
619
|
|
|
610
|
-
const path = `/p/${this.projectId}/${encodeURIComponent(key)}`;
|
|
620
|
+
const path = `/p/${this.projectId}/bucket/${encodeURIComponent(key)}`;
|
|
611
621
|
const query: Record<string, string> = {};
|
|
612
622
|
if (bucket !== 'default') query.bucket = bucket;
|
|
613
623
|
|
|
@@ -636,7 +646,7 @@ export class MoogoClient {
|
|
|
636
646
|
): Promise<PresignedUrlResponse> {
|
|
637
647
|
const { bucket = 'default', signal } = options;
|
|
638
648
|
|
|
639
|
-
const path = `/p/${this.projectId}/${encodeURIComponent(key)}/sign`;
|
|
649
|
+
const path = `/p/${this.projectId}/bucket/${encodeURIComponent(key)}/sign`;
|
|
640
650
|
const query: Record<string, string> = {};
|
|
641
651
|
if (bucket !== 'default') query.bucket = bucket;
|
|
642
652
|
|
|
@@ -655,7 +665,7 @@ export class MoogoClient {
|
|
|
655
665
|
): Promise<SignedUploadResponse> {
|
|
656
666
|
const { bucket = 'default', signal } = options;
|
|
657
667
|
|
|
658
|
-
const path = `/p/${this.projectId}/${encodeURIComponent(key)}/sign-upload`;
|
|
668
|
+
const path = `/p/${this.projectId}/bucket/${encodeURIComponent(key)}/sign-upload`;
|
|
659
669
|
const query: Record<string, string> = {};
|
|
660
670
|
if (bucket !== 'default') query.bucket = bucket;
|
|
661
671
|
|
|
@@ -674,7 +684,7 @@ export class MoogoClient {
|
|
|
674
684
|
): Promise<ObjectResponse> {
|
|
675
685
|
const { bucket = 'default', signal } = options;
|
|
676
686
|
|
|
677
|
-
const path = `/p/${this.projectId}/${encodeURIComponent(key)}`;
|
|
687
|
+
const path = `/p/${this.projectId}/bucket/${encodeURIComponent(key)}`;
|
|
678
688
|
const query: Record<string, string> = {};
|
|
679
689
|
if (bucket !== 'default') query.bucket = bucket;
|
|
680
690
|
|
|
@@ -835,12 +845,27 @@ export function createSQLClient(config: {
|
|
|
835
845
|
export function createClientFromEnv(env?: Record<string, string | undefined>): MoogoClient {
|
|
836
846
|
const getEnv = (key: string) => env?.[key] ?? process.env[key];
|
|
837
847
|
|
|
838
|
-
//
|
|
839
|
-
|
|
840
|
-
const
|
|
848
|
+
// Deprecation warnings for old env var names (log once per process)
|
|
849
|
+
const warned = new Set<string>();
|
|
850
|
+
const warnDeprecated = (oldKey: string, newKey: string) => {
|
|
851
|
+
if (process.env[oldKey] && !process.env[newKey] && !warned.has(oldKey)) {
|
|
852
|
+
console.warn(`[moogo] Deprecation: ${oldKey} is deprecated, use ${newKey} instead`);
|
|
853
|
+
warned.add(oldKey);
|
|
854
|
+
}
|
|
855
|
+
};
|
|
856
|
+
|
|
857
|
+
warnDeprecated('MOOGO_API_URL', 'MOOGO_BASE_URL');
|
|
858
|
+
warnDeprecated('MOOGO_BUCKET_ENDPOINT', 'MOOGO_BASE_URL');
|
|
859
|
+
warnDeprecated('MOOGO_BUCKET_ACCESS_KEY_ID', 'MOOGO_STORAGE_ACCESS_KEY_ID');
|
|
860
|
+
warnDeprecated('MOOGO_BUCKET_SECRET_KEY', 'MOOGO_STORAGE_SECRET_KEY');
|
|
861
|
+
warnDeprecated('MOOGO_PROJECT_KEY', 'MOOGO_SQL_KEY');
|
|
862
|
+
|
|
863
|
+
// Resolve base URL: new names first, then legacy
|
|
864
|
+
const rawBase = getEnv('MOOGO_BASE_URL') || getEnv('MOOGO_API_URL') || getEnv('MOOGO_BUCKET_ENDPOINT') || 'https://api.moogo.dev';
|
|
841
865
|
const baseUrl = rawBase.replace(/\/p\/[^/]+\/bucket.*$/, '').replace(/\/+$/, '');
|
|
842
866
|
|
|
843
|
-
|
|
867
|
+
// SQL key (new name first)
|
|
868
|
+
const projectKey = getEnv('MOOGO_SQL_KEY') || getEnv('MOOGO_PROJECT_KEY');
|
|
844
869
|
if (projectKey) {
|
|
845
870
|
return new MoogoClient({
|
|
846
871
|
baseUrl,
|
|
@@ -848,10 +873,11 @@ export function createClientFromEnv(env?: Record<string, string | undefined>): M
|
|
|
848
873
|
projectKey,
|
|
849
874
|
});
|
|
850
875
|
}
|
|
876
|
+
// Storage keys (new names first)
|
|
851
877
|
return new MoogoClient({
|
|
852
878
|
baseUrl,
|
|
853
879
|
projectId: getEnv('MOOGO_PROJECT_ID')!,
|
|
854
|
-
accessKeyId: getEnv('MOOGO_BUCKET_ACCESS_KEY_ID')!,
|
|
855
|
-
secretKey: getEnv('MOOGO_BUCKET_SECRET_KEY')!,
|
|
880
|
+
accessKeyId: getEnv('MOOGO_STORAGE_ACCESS_KEY_ID') || getEnv('MOOGO_BUCKET_ACCESS_KEY_ID')!,
|
|
881
|
+
secretKey: getEnv('MOOGO_STORAGE_SECRET_KEY') || getEnv('MOOGO_BUCKET_SECRET_KEY')!,
|
|
856
882
|
});
|
|
857
883
|
}
|
package/src/errors.ts
CHANGED
|
@@ -102,7 +102,7 @@ export class BodyTooLargeError extends MoogoError {
|
|
|
102
102
|
|
|
103
103
|
export class ObjectTooLargeError extends MoogoError {
|
|
104
104
|
constructor(detail?: string) {
|
|
105
|
-
super('object_too_large', 'Object over the bucket max size', 413, detail);
|
|
105
|
+
super('object_too_large', 'Object over the bucket max size. Check bucket max_object_size_bytes (default 250 MB). Use `PATCH /buckets/{id}` to increase, or split the file.', 413, detail);
|
|
106
106
|
this.name = 'ObjectTooLargeError';
|
|
107
107
|
Object.setPrototypeOf(this, ObjectTooLargeError.prototype);
|
|
108
108
|
}
|
|
@@ -118,7 +118,7 @@ export class UnsupportedMediaTypeError extends MoogoError {
|
|
|
118
118
|
|
|
119
119
|
export class QuotaExceededError extends MoogoError {
|
|
120
120
|
constructor(detail?: string) {
|
|
121
|
-
super('quota_exceeded', 'Project or bucket storage would go over quota', 409, detail);
|
|
121
|
+
super('quota_exceeded', 'Project or bucket storage would go over quota. Delete objects or run `moogo db vacuum` / `POST /maintenance` to reclaim space.', 409, detail);
|
|
122
122
|
this.name = 'QuotaExceededError';
|
|
123
123
|
Object.setPrototypeOf(this, QuotaExceededError.prototype);
|
|
124
124
|
}
|
|
@@ -142,7 +142,7 @@ export class LinkExpiredError extends MoogoError {
|
|
|
142
142
|
|
|
143
143
|
export class NotFoundError extends MoogoError {
|
|
144
144
|
constructor(detail?: string) {
|
|
145
|
-
super('not_found', 'Bucket/object missing or not published', 404, detail);
|
|
145
|
+
super('not_found', 'Bucket/object missing or not published. For public URLs: ensure object is published (PATCH is_public: true) and check key spelling. Private objects return 404 on /pub/ routes.', 404, detail);
|
|
146
146
|
this.name = 'NotFoundError';
|
|
147
147
|
Object.setPrototypeOf(this, NotFoundError.prototype);
|
|
148
148
|
}
|
|
@@ -169,7 +169,7 @@ export class RateLimitedError extends MoogoError {
|
|
|
169
169
|
public readonly resetAt: number | null;
|
|
170
170
|
|
|
171
171
|
constructor(retryAfter: number, resetAt: number | null, detail?: string) {
|
|
172
|
-
super('rate_limited',
|
|
172
|
+
super('rate_limited', `Too many requests. Retry after ${retryAfter}s (reset at ${resetAt ? new Date(resetAt * 1000).toISOString() : 'unknown'}). Use X-RateLimit-Reset header for precise timing.`, 429, detail);
|
|
173
173
|
this.name = 'RateLimitedError';
|
|
174
174
|
this.retryAfter = retryAfter;
|
|
175
175
|
this.resetAt = resetAt;
|
|
@@ -213,7 +213,7 @@ export class UnauthorizedError extends MoogoError {
|
|
|
213
213
|
constructor(detail?: string) {
|
|
214
214
|
const hint = detail
|
|
215
215
|
? detail
|
|
216
|
-
: 'Authentication required.
|
|
216
|
+
: 'Authentication required. Storage: set MOOGO_BASE_URL (or MOOGO_API_URL), MOOGO_PROJECT_ID, MOOGO_STORAGE_ACCESS_KEY_ID, MOOGO_STORAGE_SECRET_KEY. SQL: set MOOGO_SQL_KEY (or MOOGO_PROJECT_KEY). Old names (MOOGO_BUCKET_*) still work but deprecated.';
|
|
217
217
|
super('unauthorized', hint, 401, detail);
|
|
218
218
|
this.name = 'UnauthorizedError';
|
|
219
219
|
Object.setPrototypeOf(this, UnauthorizedError.prototype);
|