@moogodev/client 0.0.0-stage → 0.1.1

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,54 @@
1
- # Temporary Holding Version
1
+ # @moogodev/client
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 JavaScript/TypeScript client for Moogo object storage.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @moogodev/client
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { MoogoClient, createClientFromEnv } from '@moogodev/client';
15
+
16
+ // Reads from environment variables:
17
+ // MOOGO_API_URL, MOOGO_PROJECT_ID, MOOGO_BUCKET_ACCESS_KEY_ID, MOOGO_BUCKET_SECRET_KEY
18
+ const client = createClientFromEnv();
19
+
20
+ // Upload with custom Cache-Control
21
+ const response = await client.upload('avatars/user.png', fileBlob, {
22
+ contentType: 'image/png',
23
+ cacheControl: 'public, max-age=31536000, immutable',
24
+ onProgress: (loaded, total) => console.log(`${loaded}/${total}`),
25
+ });
26
+
27
+ console.log(response.object.public_url);
28
+ ```
29
+
30
+ ## Features
31
+
32
+ - **Full TypeScript support** — complete type definitions for all API responses
33
+ - **Cursor-based pagination** — stable `nextCursor` + `total` for listings
34
+ - **Range requests** — `206 Partial Content`, `416 Range Not Satisfiable`, `If-Range`
35
+ - **Custom Cache-Control** — send `Cache-Control` header on upload to override defaults
36
+ - **Presigned URLs** — GET (download) and PUT (browser direct upload)
37
+ - **Signed uploads** — returns upload URL + object metadata
38
+ - **Bucket operations** — list, create, update, delete, get info, toggle public
39
+ - **Credential management** — list, create, rotate, revoke storage credentials
40
+ - **Rate-limit handling** — `X-RateLimit-Reset` header parsing, `RateLimitedError` with `retryAfter`/`resetAt`
41
+ - **Typed errors** — all API error codes as distinct classes
42
+ - **Zero dependencies** — uses Web Crypto API (native in Node 18+, browsers, edge runtimes)
43
+ - **Works everywhere** — Node 18+, Deno, Bun, Cloudflare Workers, Vercel Edge, browsers (via bundler)
44
+
45
+ ## Documentation
46
+
47
+ - [Full API Reference](https://moogo.dev/docs/javascript-client)
48
+ - [Object Storage API](https://moogo.dev/docs/object-storage)
49
+ - [Rate Limits](https://moogo.dev/docs/limits)
50
+ - [Error Codes](https://moogo.dev/docs/errors)
51
+
52
+ ## License
53
+
54
+ MIT
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Moogo JavaScript/TypeScript Client
3
+ * Official client for Moogo object storage API.
4
+ */
5
+ import type { ClientConfig, Bucket, CreateBucketRequest, UpdateBucketRequest, BucketInfoResponse, ObjectResponse, UploadResponse, ListObjectsQuery, ListObjectsResponse, PresignedUrlRequest, PresignedUrlResponse, SignedUploadResponse, StorageCredential, CreateCredentialRequest, CreateCredentialResponse, RotateCredentialResponse } from './types.js';
6
+ /**
7
+ * Moogo client for object storage operations.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { MoogoClient } from '@moogodev/client';
12
+ *
13
+ * const client = new MoogoClient({
14
+ * baseUrl: 'https://api.moogo.dev',
15
+ * projectId: 'your-project-id',
16
+ * accessKeyId: 'your-access-key',
17
+ * secretKey: 'your-secret-key',
18
+ * });
19
+ *
20
+ * // Upload a file
21
+ * const response = await client.upload('avatars/user.png', fileBlob, {
22
+ * contentType: 'image/png',
23
+ * cacheControl: 'public, max-age=31536000, immutable',
24
+ * });
25
+ *
26
+ * // List objects
27
+ * const { objects, nextCursor } = await client.listObjects({ prefix: 'avatars/' });
28
+ * ```
29
+ */
30
+ export declare class MoogoClient {
31
+ private readonly baseUrl;
32
+ private readonly projectId;
33
+ private readonly accessKeyId;
34
+ private readonly secretKey;
35
+ private readonly fetchImpl;
36
+ private readonly timeout;
37
+ constructor(config: ClientConfig);
38
+ /** Build the bucket catalog path */
39
+ private getCatalogPath;
40
+ /** Build the credentials path */
41
+ private getCredentialsPath;
42
+ /** Create authorization header using AWS Signature V4-like scheme */
43
+ private createAuthHeader;
44
+ private hashBody;
45
+ private hashString;
46
+ private getSigningKey;
47
+ private hmacSha256;
48
+ /** Execute a request with auth and error handling */
49
+ private request;
50
+ /** List all buckets in the project */
51
+ listBuckets(): Promise<Bucket[]>;
52
+ /** Get bucket info including usage stats */
53
+ getBucketInfo(bucketId: string): Promise<BucketInfoResponse>;
54
+ /** Create a new bucket */
55
+ createBucket(request: CreateBucketRequest): Promise<Bucket>;
56
+ /** Update bucket settings */
57
+ updateBucket(bucketId: string, request: UpdateBucketRequest): Promise<Bucket>;
58
+ /** Delete a bucket and all its objects */
59
+ deleteBucket(bucketId: string): Promise<void>;
60
+ /** Toggle bucket public/private (fans out to all objects) */
61
+ setBucketPublic(bucketId: string, isPublic: boolean): Promise<Bucket>;
62
+ /**
63
+ * Upload an object to a bucket.
64
+ *
65
+ * @param key - Object key (path within bucket)
66
+ * @param data - File data (Blob, File, Uint8Array, ReadableStream, or string)
67
+ * @param options - Upload options
68
+ */
69
+ upload(key: string, data: Blob | File | Uint8Array | ReadableStream<Uint8Array> | string, options?: {
70
+ bucket?: string;
71
+ contentType?: string;
72
+ cacheControl?: string;
73
+ onProgress?: (loaded: number, total: number) => void;
74
+ signal?: AbortSignal;
75
+ }): Promise<UploadResponse>;
76
+ /** Wrap a Blob with progress tracking */
77
+ private wrapWithProgress;
78
+ /** Download an object */
79
+ download(key: string, options?: {
80
+ bucket?: string;
81
+ signal?: AbortSignal;
82
+ range?: {
83
+ start: number;
84
+ end?: number;
85
+ };
86
+ }): Promise<Response>;
87
+ /** Download object as blob */
88
+ downloadBlob(key: string, options?: Parameters<typeof this.download>[1]): Promise<Blob>;
89
+ /** Download object as text */
90
+ downloadText(key: string, options?: Parameters<typeof this.download>[1]): Promise<string>;
91
+ /** Download object as ArrayBuffer */
92
+ downloadArrayBuffer(key: string, options?: Parameters<typeof this.download>[1]): Promise<ArrayBuffer>;
93
+ /** Get object metadata (HEAD request) */
94
+ headObject(key: string, options?: {
95
+ bucket?: string;
96
+ signal?: AbortSignal;
97
+ }): Promise<{
98
+ headers: Headers;
99
+ exists: boolean;
100
+ }>;
101
+ /** Delete an object */
102
+ deleteObject(key: string, options?: {
103
+ bucket?: string;
104
+ signal?: AbortSignal;
105
+ }): Promise<void>;
106
+ /** List objects in a bucket */
107
+ listObjects(query?: ListObjectsQuery): Promise<ListObjectsResponse>;
108
+ /** Get a presigned URL for an object */
109
+ getPresignedUrl(key: string, request: PresignedUrlRequest, options?: {
110
+ bucket?: string;
111
+ signal?: AbortSignal;
112
+ }): Promise<PresignedUrlResponse>;
113
+ /** Create a signed upload URL (returns upload URL + object metadata) */
114
+ createSignedUpload(key: string, request: PresignedUrlRequest & {
115
+ content_type?: string;
116
+ }, options?: {
117
+ bucket?: string;
118
+ signal?: AbortSignal;
119
+ }): Promise<SignedUploadResponse>;
120
+ /** Update object metadata (visibility, key) */
121
+ updateObject(key: string, updates: {
122
+ is_public?: boolean;
123
+ new_key?: string;
124
+ }, options?: {
125
+ bucket?: string;
126
+ signal?: AbortSignal;
127
+ }): Promise<ObjectResponse>;
128
+ /** List storage credentials */
129
+ listCredentials(): Promise<StorageCredential[]>;
130
+ /** Create a new storage credential */
131
+ createCredential(request: CreateCredentialRequest): Promise<CreateCredentialResponse>;
132
+ /** Rotate a credential (generates new secret) */
133
+ rotateCredential(credentialId: string): Promise<RotateCredentialResponse>;
134
+ /** Revoke a credential */
135
+ revokeCredential(credentialId: string): Promise<void>;
136
+ /** Get the public URL for an object (if published) */
137
+ getPublicUrl(key: string, publicUrlBase?: string): string;
138
+ /** Get the authenticated download URL for an object */
139
+ getAuthenticatedUrl(key: string): string;
140
+ /** Check if an object exists (efficient HEAD) */
141
+ objectExists(key: string, options?: {
142
+ bucket?: string;
143
+ }): Promise<boolean>;
144
+ /** Get object size without downloading */
145
+ getObjectSize(key: string, options?: {
146
+ bucket?: string;
147
+ }): Promise<number | null>;
148
+ /** Get object ETag */
149
+ getObjectETag(key: string, options?: {
150
+ bucket?: string;
151
+ }): Promise<string | null>;
152
+ }
153
+ /** Convenience function to create a client from environment variables */
154
+ export declare function createClientFromEnv(env?: Record<string, string | undefined>): MoogoClient;
155
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +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,EAEzB,MAAM,YAAY,CAAC;AAUpB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAe;IACzC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,MAAM,EAAE,YAAY;IAchC,oCAAoC;IACpC,OAAO,CAAC,cAAc;IAItB,iCAAiC;IACjC,OAAO,CAAC,kBAAkB;IAI1B,qEAAqE;YACvD,gBAAgB;YAkDhB,QAAQ;YAOR,UAAU;YAIV,aAAa;YAkBb,UAAU;IAOxB,qDAAqD;YACvC,OAAO;IA2ErB,sCAAsC;IAChC,WAAW,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAKtC,4CAA4C;IACtC,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAQlE,0BAA0B;IACpB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,M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