@gigadrive/sdk 0.7.28 → 0.8.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
@@ -64,6 +64,11 @@ variables (constructor values take precedence):
64
64
  | Refresh token | `clientId` + `refreshToken` | `GIGADRIVE_CLIENT_ID` + `GIGADRIVE_REFRESH_TOKEN` |
65
65
  | Authorization code + PKCE | `clientId` + `onAuthorizationUrl` | — |
66
66
 
67
+ Context-bound storage calls also resolve an application UUID from
68
+ `applicationId` in the constructor or `GIGADRIVE_APPLICATION_ID`. Gigadrive
69
+ injects the latter with workload credentials, so deployed server code normally
70
+ needs no SDK configuration.
71
+
67
72
  ```ts
68
73
  // Custom fetch / base URL (e.g. for tests or non-standard runtimes)
69
74
  const client = new GigadriveClient({ bearerToken: 'eyJ...', fetch: myFetch });
@@ -92,26 +97,75 @@ The URL is routing authority, not user authentication. Applications still own
92
97
  authorization and room membership. State remains in one MicroVM's memory, URLs
93
98
  expire, and deploys do not migrate that in-memory state to a new version.
94
99
 
95
- ## File uploads
100
+ ## File storage
101
+
102
+ Bucket `name` is the canonical REST and IaC identifier. Names are immutable,
103
+ lowercase, URL-safe, and unique within an environment. The returned bucket
104
+ `slug` remains the global CDN/S3 identifier and should not be passed to these
105
+ REST helpers.
106
+
107
+ Declare buckets for each deployment environment under `services.storage` in
108
+ `gigadrive.yaml`. Mapping keys are the canonical bucket names; `null` or an
109
+ empty object uses private visibility. The deployment determines the environment
110
+ and generates each global CDN/S3 slug.
111
+
112
+ ```yaml
113
+ version: 4
114
+ services:
115
+ storage:
116
+ buckets:
117
+ assets:
118
+ visibility: public
119
+ uploads: null
120
+ ```
121
+
122
+ Inside a deployed workload, application and environment context are inferred:
123
+
124
+ ```ts
125
+ import { GigadriveClient } from '@gigadrive/sdk';
126
+
127
+ const client = new GigadriveClient();
128
+ const { items } = await client.storage.objects.list('assets');
129
+ ```
130
+
131
+ Management callers can configure the application and select an environment by
132
+ slug or UUID:
133
+
134
+ ```ts
135
+ const client = new GigadriveClient({ applicationId, clientId, clientSecret });
136
+ const bucket = await client.storage.buckets.create({
137
+ name: 'assets',
138
+ environment: 'production',
139
+ visibility: 'public',
140
+ });
141
+
142
+ const { items } = await client.storage.objects.list(bucket.name, {
143
+ environment: 'production',
144
+ });
145
+ ```
146
+
147
+ Existing `client.applications.storage` calls, explicit `applicationId`
148
+ arguments, and bucket UUIDs remain available as deprecated compatibility
149
+ paths.
150
+
151
+ ### File uploads
96
152
 
97
153
  The high-level `upload()` computes the required SHA-256 checksum, infers the
98
154
  content type from the key, creates the upload session, and uploads the bytes
99
- resumably — in one call.
155
+ with resumable transfer — in one call.
100
156
 
101
157
  ```ts
102
158
  // Node.js — upload straight from a file path (size, checksum, type inferred)
103
- const { url } = await client.applications.storage.upload({
104
- applicationId,
105
- bucketId,
159
+ const { url } = await client.storage.upload({
160
+ bucket: 'reports',
106
161
  key: 'reports/q1.pdf',
107
162
  path: './q1-report.pdf',
108
163
  });
109
164
 
110
165
  // Browser — upload a File with progress and cancellation
111
166
  const controller = new AbortController();
112
- const { url } = await client.applications.storage.upload({
113
- applicationId,
114
- bucketId,
167
+ const { url } = await client.storage.upload({
168
+ bucket: 'uploads',
115
169
  key: `uploads/${file.name}`,
116
170
  data: file,
117
171
  onProgress: (sent, total) => console.log(`${Math.round((sent / total) * 100)}%`),
@@ -119,9 +173,8 @@ const { url } = await client.applications.storage.upload({
119
173
  });
120
174
 
121
175
  // Wait until the object is finalized server-side, then read it back
122
- const { object } = await client.applications.storage.upload({
123
- applicationId,
124
- bucketId,
176
+ const { object } = await client.storage.upload({
177
+ bucket: 'avatars',
125
178
  key: 'avatars/user-1.png',
126
179
  data: bytes,
127
180
  waitForCompletion: true,
@@ -133,29 +186,37 @@ Accepted inputs: browser `File`/`Blob`, Node `Buffer`/`Uint8Array`/`ArrayBuffer`
133
186
  a Node filesystem `path`, or a Node readable `stream` (with `contentLength` and
134
187
  `checksumSha256`).
135
188
 
136
- ### Many files at once
189
+ #### Many files at once
137
190
 
138
191
  ```ts
139
- const results = await client.applications.storage.uploadBatch(
140
- files.map((f) => ({ applicationId, bucketId, key: `uploads/${f.name}`, data: f })),
192
+ const results = await client.storage.uploadBatch(
193
+ files.map((f) => ({ bucket: 'uploads', key: f.name, data: f })),
141
194
  { concurrency: 6, onProgress: (done, total) => console.log(`${done}/${total}`) }
142
195
  );
143
196
  const failed = results.filter((r) => r.error);
144
197
  ```
145
198
 
146
- ### Working with objects
199
+ ### Working with objects and trash
147
200
 
148
201
  ```ts
149
202
  // List a "folder" one level deep
150
- const { items, commonPrefixes } = await client.applications.storage.objects.list(applicationId, bucketId, {
203
+ const { items, commonPrefixes } = await client.storage.objects.list('assets', {
151
204
  prefix: 'images/',
152
205
  limit: 100,
153
206
  });
154
207
 
155
208
  // Signed download URL for a private object
156
- const { url } = await client.applications.storage.objects.getAccessUrl(applicationId, bucketId, objectId, {
209
+ const { url } = await client.storage.objects.getAccessUrl('assets', objectId, {
157
210
  expiresInSeconds: 3600,
158
211
  });
212
+
213
+ // Delete moves an object to trash; restore or permanently purge it later
214
+ await client.storage.objects.delete('assets', objectId);
215
+ await client.storage.trash.restore('assets', objectId);
216
+ await client.storage.trash.purge('assets', objectId);
217
+
218
+ // Permanently purge every trashed object in the bucket
219
+ const { purgedCount } = await client.storage.trash.empty('assets');
159
220
  ```
160
221
 
161
222
  ## AI Gateway
@@ -194,9 +255,7 @@ the `paginate` helper:
194
255
  ```ts
195
256
  import { paginate } from '@gigadrive/sdk';
196
257
 
197
- for await (const object of paginate((cursor) =>
198
- client.applications.storage.objects.list(applicationId, bucketId, { cursor })
199
- )) {
258
+ for await (const object of paginate((cursor) => client.storage.objects.list('assets', { cursor }))) {
200
259
  console.log(object.key);
201
260
  }
202
261
  ```
@@ -204,7 +263,7 @@ for await (const object of paginate((cursor) =>
204
263
  ## Errors
205
264
 
206
265
  All errors extend `GigadriveError`. Notable subclasses: `ApiError` (with `status`
207
- and optional `code`), `AuthenticationError`, `UploadError`, and
266
+ and optional `code`), `AuthenticationError`, `ConfigurationError`, `UploadError`, and
208
267
  `UploadSessionExpiredError`.
209
268
 
210
269
  ```ts