@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/dist/index.mjs CHANGED
@@ -11,6 +11,12 @@ var AuthenticationError = class extends GigadriveError {
11
11
  this.name = "AuthenticationError";
12
12
  }
13
13
  };
14
+ var ConfigurationError = class extends GigadriveError {
15
+ constructor(message) {
16
+ super(message);
17
+ this.name = "ConfigurationError";
18
+ }
19
+ };
14
20
  var ApiError = class extends GigadriveError {
15
21
  /** The HTTP status code of the failed response (e.g. 404, 500). */
16
22
  status;
@@ -1139,230 +1145,283 @@ var toUploadError = (error) => {
1139
1145
  throw new UploadError(error instanceof Error ? error.message : "The upload failed.", error);
1140
1146
  };
1141
1147
 
1148
+ // src/resources/storage-context.ts
1149
+ var resolveStorageApplicationId = (defaultApplicationId, explicitApplicationId) => {
1150
+ const applicationId = explicitApplicationId ?? defaultApplicationId;
1151
+ if (applicationId) return applicationId;
1152
+ throw new ConfigurationError(
1153
+ "No application context is configured. Pass an application ID to this call, set GigadriveClientConfig.applicationId, or run inside a Gigadrive deployment with GIGADRIVE_APPLICATION_ID."
1154
+ );
1155
+ };
1156
+ var resolveStorageBucketReference = (input) => {
1157
+ const hasBucket = typeof input.bucket === "string";
1158
+ const hasBucketId = typeof input.bucketId === "string";
1159
+ if (hasBucket === hasBucketId) {
1160
+ throw new ConfigurationError(
1161
+ "Provide exactly one storage bucket reference using `bucket` or deprecated `bucketId`."
1162
+ );
1163
+ }
1164
+ return hasBucket ? input.bucket : input.bucketId;
1165
+ };
1166
+ var encodeStorageBucketReference = (bucketRef) => encodeURIComponent(bucketRef);
1167
+
1142
1168
  // src/resources/storage-buckets.ts
1143
1169
  var StorageBucketsResource = class extends BaseResource {
1144
- /**
1145
- * List all storage buckets for an application.
1146
- *
1147
- * @param applicationId - The application ID (UUID).
1148
- * @param query - Optional pagination parameters.
1149
- * @returns A paginated list of storage buckets.
1150
- *
1151
- * @example
1152
- * ```ts
1153
- * const { items, total } = await client.applications.storage.buckets.list('app-id');
1154
- * console.log(`${total} buckets found`);
1155
- * ```
1156
- */
1157
- async list(applicationId, query) {
1170
+ constructor(httpClient, defaultApplicationId) {
1171
+ super(httpClient);
1172
+ this.defaultApplicationId = defaultApplicationId;
1173
+ }
1174
+ defaultApplicationId;
1175
+ async list(applicationIdOrQuery, legacyQuery) {
1176
+ const applicationId = resolveStorageApplicationId(
1177
+ this.defaultApplicationId,
1178
+ typeof applicationIdOrQuery === "string" ? applicationIdOrQuery : void 0
1179
+ );
1180
+ const query = typeof applicationIdOrQuery === "string" ? legacyQuery : applicationIdOrQuery;
1158
1181
  return this.httpClient.get(`/applications/${applicationId}/storage/buckets`, {
1159
1182
  query
1160
1183
  });
1161
1184
  }
1162
- /**
1163
- * Create a new storage bucket.
1164
- *
1165
- * @param applicationId - The application ID (UUID).
1166
- * @param data - Bucket name, environment, and optional slug/visibility.
1167
- * @returns The newly created bucket.
1168
- *
1169
- * @example
1170
- * ```ts
1171
- * const bucket = await client.applications.storage.buckets.create('app-id', {
1172
- * name: 'Assets',
1173
- * environmentId: 'env-id',
1174
- * visibility: 'public',
1175
- * });
1176
- * console.log(`Bucket CDN: https://${bucket.cdnHostname}`);
1177
- * ```
1178
- */
1179
- async create(applicationId, data) {
1185
+ async create(applicationIdOrData, legacyData) {
1186
+ const applicationId = resolveStorageApplicationId(
1187
+ this.defaultApplicationId,
1188
+ typeof applicationIdOrData === "string" ? applicationIdOrData : void 0
1189
+ );
1190
+ const data = typeof applicationIdOrData === "string" ? legacyData : applicationIdOrData;
1180
1191
  return this.httpClient.post(`/applications/${applicationId}/storage/buckets`, data);
1181
1192
  }
1182
- /**
1183
- * Get a storage bucket by ID.
1184
- *
1185
- * @param applicationId - The application ID (UUID).
1186
- * @param bucketId - The bucket ID (UUID).
1187
- * @returns The bucket details.
1188
- *
1189
- * @example
1190
- * ```ts
1191
- * const bucket = await client.applications.storage.buckets.get('app-id', 'bucket-id');
1192
- * console.log(`${bucket.name} (${bucket.visibility})`);
1193
- * ```
1194
- */
1195
- async get(applicationId, bucketId) {
1196
- return this.httpClient.get(`/applications/${applicationId}/storage/buckets/${bucketId}`);
1193
+ async get(applicationIdOrBucketRef, bucketRefOrOptions, legacyOptions) {
1194
+ const explicitApplication = typeof bucketRefOrOptions === "string";
1195
+ const applicationId = resolveStorageApplicationId(
1196
+ this.defaultApplicationId,
1197
+ explicitApplication ? applicationIdOrBucketRef : void 0
1198
+ );
1199
+ const bucketRef = explicitApplication ? bucketRefOrOptions : applicationIdOrBucketRef;
1200
+ const options = explicitApplication ? legacyOptions : bucketRefOrOptions;
1201
+ return this.httpClient.get(
1202
+ `/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}`,
1203
+ {
1204
+ query: { environment: options?.environment }
1205
+ }
1206
+ );
1197
1207
  }
1198
- /**
1199
- * Permanently delete a storage bucket and all its objects.
1200
- *
1201
- * @param applicationId - The application ID (UUID).
1202
- * @param bucketId - The bucket ID (UUID).
1203
- *
1204
- * @example
1205
- * ```ts
1206
- * await client.applications.storage.buckets.delete('app-id', 'bucket-id');
1207
- * ```
1208
- */
1209
- async delete(applicationId, bucketId) {
1210
- return this.httpClient.delete(`/applications/${applicationId}/storage/buckets/${bucketId}`);
1208
+ async delete(applicationIdOrBucketRef, bucketRefOrOptions, legacyOptions) {
1209
+ const explicitApplication = typeof bucketRefOrOptions === "string";
1210
+ const applicationId = resolveStorageApplicationId(
1211
+ this.defaultApplicationId,
1212
+ explicitApplication ? applicationIdOrBucketRef : void 0
1213
+ );
1214
+ const bucketRef = explicitApplication ? bucketRefOrOptions : applicationIdOrBucketRef;
1215
+ const options = explicitApplication ? legacyOptions : bucketRefOrOptions;
1216
+ return this.httpClient.delete(
1217
+ `/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}`,
1218
+ { query: { environment: options?.environment } }
1219
+ );
1211
1220
  }
1212
1221
  };
1213
1222
 
1214
1223
  // src/resources/storage-objects.ts
1215
1224
  var StorageObjectsResource = class extends BaseResource {
1216
- /**
1217
- * List objects in a storage bucket, optionally filtered by key prefix and
1218
- * grouped into virtual folders by a delimiter.
1219
- *
1220
- * @param applicationId - The application ID (UUID).
1221
- * @param bucketId - The bucket ID (UUID).
1222
- * @param query - Optional prefix/delimiter/cursor/limit parameters.
1223
- * @returns A page of objects plus any common (folder) prefixes and a `nextCursor`.
1224
- *
1225
- * @example
1226
- * ```ts
1227
- * // List the "images/" folder, one level deep
1228
- * const { items, commonPrefixes, nextCursor } = await client.applications.storage.objects.list(
1229
- * 'app-id', 'bucket-id', { prefix: 'images/', limit: 100 },
1230
- * );
1231
- * ```
1232
- */
1233
- async list(applicationId, bucketId, query) {
1234
- return this.httpClient.get(`/applications/${applicationId}/storage/buckets/${bucketId}/objects`, {
1235
- query
1236
- });
1225
+ constructor(httpClient, defaultApplicationId) {
1226
+ super(httpClient);
1227
+ this.defaultApplicationId = defaultApplicationId;
1228
+ }
1229
+ defaultApplicationId;
1230
+ async list(applicationIdOrBucketRef, bucketRefOrQuery, legacyQuery) {
1231
+ const explicitApplication = typeof bucketRefOrQuery === "string";
1232
+ const applicationId = resolveStorageApplicationId(
1233
+ this.defaultApplicationId,
1234
+ explicitApplication ? applicationIdOrBucketRef : void 0
1235
+ );
1236
+ const bucketRef = explicitApplication ? bucketRefOrQuery : applicationIdOrBucketRef;
1237
+ const query = explicitApplication ? legacyQuery : bucketRefOrQuery;
1238
+ return this.httpClient.get(
1239
+ `/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/objects`,
1240
+ {
1241
+ query
1242
+ }
1243
+ );
1237
1244
  }
1238
- /**
1239
- * Get metadata for a specific object by its object ID.
1240
- *
1241
- * @param applicationId - The application ID (UUID).
1242
- * @param bucketId - The bucket ID (UUID).
1243
- * @param objectId - The object ID (UUID) — not the object key. Use {@link getByKey} to resolve a key.
1244
- * @returns The object metadata.
1245
- *
1246
- * @example
1247
- * ```ts
1248
- * const obj = await client.applications.storage.objects.get('app-id', 'bucket-id', 'object-id');
1249
- * console.log(`${obj.key}: ${obj.contentLength} bytes, type: ${obj.contentType}`);
1250
- * ```
1251
- */
1252
- async get(applicationId, bucketId, objectId) {
1253
- return this.httpClient.get(`/applications/${applicationId}/storage/buckets/${bucketId}/objects/${objectId}`);
1245
+ async get(applicationIdOrBucketRef, bucketRefOrObjectId, objectIdOrOptions, legacyOptions) {
1246
+ const explicitApplication = typeof objectIdOrOptions === "string";
1247
+ const applicationId = resolveStorageApplicationId(
1248
+ this.defaultApplicationId,
1249
+ explicitApplication ? applicationIdOrBucketRef : void 0
1250
+ );
1251
+ const bucketRef = explicitApplication ? bucketRefOrObjectId : applicationIdOrBucketRef;
1252
+ const objectId = explicitApplication ? objectIdOrOptions : bucketRefOrObjectId;
1253
+ const options = explicitApplication ? legacyOptions : objectIdOrOptions;
1254
+ return this.httpClient.get(
1255
+ `/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/objects/${objectId}`,
1256
+ { query: { environment: options?.environment } }
1257
+ );
1254
1258
  }
1255
- /**
1256
- * Resolve an object by its key (path) instead of its ID. Convenience over
1257
- * {@link list} — lists with the key as the prefix and returns the exact match,
1258
- * paging through results until found, or `null` if no object with that key
1259
- * exists. (The API has no get-by-key endpoint.)
1260
- *
1261
- * @param applicationId - The application ID (UUID).
1262
- * @param bucketId - The bucket ID (UUID).
1263
- * @param key - The object key/path (e.g. `"images/photo.jpg"`).
1264
- * @returns The matching object, or `null` if not found.
1265
- */
1266
- async getByKey(applicationId, bucketId, key) {
1259
+ async getByKey(applicationIdOrBucketRef, bucketRefOrKey, keyOrOptions, legacyOptions) {
1260
+ const explicitApplication = typeof keyOrOptions === "string";
1261
+ const applicationId = resolveStorageApplicationId(
1262
+ this.defaultApplicationId,
1263
+ explicitApplication ? applicationIdOrBucketRef : void 0
1264
+ );
1265
+ const bucketRef = explicitApplication ? bucketRefOrKey : applicationIdOrBucketRef;
1266
+ const key = explicitApplication ? keyOrOptions : bucketRefOrKey;
1267
+ const options = explicitApplication ? legacyOptions : keyOrOptions;
1267
1268
  let cursor;
1268
1269
  do {
1269
- const page = await this.list(applicationId, bucketId, { prefix: key, delimiter: "", cursor });
1270
+ const page = await this.list(applicationId, bucketRef, {
1271
+ environment: options?.environment,
1272
+ prefix: key,
1273
+ cursor
1274
+ });
1270
1275
  const match = page.items.find((object) => object.key === key);
1271
1276
  if (match) return match;
1272
1277
  cursor = page.nextCursor;
1273
1278
  } while (cursor);
1274
1279
  return null;
1275
1280
  }
1276
- /**
1277
- * Permanently delete an object from a storage bucket.
1278
- *
1279
- * @param applicationId - The application ID (UUID).
1280
- * @param bucketId - The bucket ID (UUID).
1281
- * @param objectId - The object ID (UUID) — not the object key.
1282
- *
1283
- * @example
1284
- * ```ts
1285
- * await client.applications.storage.objects.delete('app-id', 'bucket-id', 'object-id');
1286
- * ```
1287
- */
1288
- async delete(applicationId, bucketId, objectId) {
1289
- return this.httpClient.delete(`/applications/${applicationId}/storage/buckets/${bucketId}/objects/${objectId}`);
1281
+ async delete(applicationIdOrBucketRef, bucketRefOrObjectId, objectIdOrOptions, legacyOptions) {
1282
+ const explicitApplication = typeof objectIdOrOptions === "string";
1283
+ const applicationId = resolveStorageApplicationId(
1284
+ this.defaultApplicationId,
1285
+ explicitApplication ? applicationIdOrBucketRef : void 0
1286
+ );
1287
+ const bucketRef = explicitApplication ? bucketRefOrObjectId : applicationIdOrBucketRef;
1288
+ const objectId = explicitApplication ? objectIdOrOptions : bucketRefOrObjectId;
1289
+ const options = explicitApplication ? legacyOptions : objectIdOrOptions;
1290
+ return this.httpClient.delete(
1291
+ `/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/objects/${objectId}`,
1292
+ { query: { environment: options?.environment } }
1293
+ );
1290
1294
  }
1291
- /**
1292
- * Get an access URL for a storage object. For objects in public buckets,
1293
- * returns a stable CDN URL. For private buckets, returns a time-limited
1294
- * signed URL.
1295
- *
1296
- * @param applicationId - The application ID (UUID).
1297
- * @param bucketId - The bucket ID (UUID).
1298
- * @param objectId - The object ID (UUID) — not the object key.
1299
- * @param options - Optional `expiresInSeconds` for signed URLs (60–86400).
1300
- * @returns The access URL and its type/expiry.
1301
- *
1302
- * @example
1303
- * ```ts
1304
- * const access = await client.applications.storage.objects.getAccessUrl('app-id', 'bucket-id', 'object-id', {
1305
- * expiresInSeconds: 3600,
1306
- * });
1307
- * if (access.accessType === 'signed') {
1308
- * console.log(`Signed URL expires at ${access.expiresAt}`);
1309
- * }
1310
- * console.log(`Download: ${access.url}`);
1311
- * ```
1312
- */
1313
- async getAccessUrl(applicationId, bucketId, objectId, options) {
1295
+ async getAccessUrl(applicationIdOrBucketRef, bucketRefOrObjectId, objectIdOrOptions, legacyOptions) {
1296
+ const explicitApplication = typeof objectIdOrOptions === "string";
1297
+ const applicationId = resolveStorageApplicationId(
1298
+ this.defaultApplicationId,
1299
+ explicitApplication ? applicationIdOrBucketRef : void 0
1300
+ );
1301
+ const bucketRef = explicitApplication ? bucketRefOrObjectId : applicationIdOrBucketRef;
1302
+ const objectId = explicitApplication ? objectIdOrOptions : bucketRefOrObjectId;
1303
+ const options = explicitApplication ? legacyOptions : objectIdOrOptions;
1314
1304
  return this.httpClient.get(
1315
- `/applications/${applicationId}/storage/buckets/${bucketId}/objects/${objectId}/access-url`,
1316
- { query: { expiresInSeconds: options?.expiresInSeconds } }
1305
+ `/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/objects/${objectId}/access-url`,
1306
+ { query: { environment: options?.environment, expiresInSeconds: options?.expiresInSeconds } }
1307
+ );
1308
+ }
1309
+ };
1310
+
1311
+ // src/resources/storage-trash.ts
1312
+ var StorageTrashResource = class extends BaseResource {
1313
+ constructor(httpClient, defaultApplicationId) {
1314
+ super(httpClient);
1315
+ this.defaultApplicationId = defaultApplicationId;
1316
+ }
1317
+ defaultApplicationId;
1318
+ async list(applicationIdOrBucketRef, bucketRefOrQuery, legacyQuery) {
1319
+ const explicitApplication = typeof bucketRefOrQuery === "string";
1320
+ const applicationId = resolveStorageApplicationId(
1321
+ this.defaultApplicationId,
1322
+ explicitApplication ? applicationIdOrBucketRef : void 0
1323
+ );
1324
+ const bucketRef = explicitApplication ? bucketRefOrQuery : applicationIdOrBucketRef;
1325
+ const query = explicitApplication ? legacyQuery : bucketRefOrQuery;
1326
+ return this.httpClient.get(
1327
+ `/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/trash`,
1328
+ { query }
1329
+ );
1330
+ }
1331
+ async restore(applicationIdOrBucketRef, bucketRefOrObjectId, objectIdOrOptions, legacyOptions) {
1332
+ const explicitApplication = typeof objectIdOrOptions === "string";
1333
+ const applicationId = resolveStorageApplicationId(
1334
+ this.defaultApplicationId,
1335
+ explicitApplication ? applicationIdOrBucketRef : void 0
1336
+ );
1337
+ const bucketRef = explicitApplication ? bucketRefOrObjectId : applicationIdOrBucketRef;
1338
+ const objectId = explicitApplication ? objectIdOrOptions : bucketRefOrObjectId;
1339
+ const options = explicitApplication ? legacyOptions : objectIdOrOptions;
1340
+ return this.httpClient.post(
1341
+ `/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/trash/${objectId}/restore`,
1342
+ void 0,
1343
+ { query: { environment: options?.environment } }
1344
+ );
1345
+ }
1346
+ async purge(applicationIdOrBucketRef, bucketRefOrObjectId, objectIdOrOptions, legacyOptions) {
1347
+ const explicitApplication = typeof objectIdOrOptions === "string";
1348
+ const applicationId = resolveStorageApplicationId(
1349
+ this.defaultApplicationId,
1350
+ explicitApplication ? applicationIdOrBucketRef : void 0
1351
+ );
1352
+ const bucketRef = explicitApplication ? bucketRefOrObjectId : applicationIdOrBucketRef;
1353
+ const objectId = explicitApplication ? objectIdOrOptions : bucketRefOrObjectId;
1354
+ const options = explicitApplication ? legacyOptions : objectIdOrOptions;
1355
+ return this.httpClient.delete(
1356
+ `/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/trash/${objectId}`,
1357
+ { query: { environment: options?.environment } }
1358
+ );
1359
+ }
1360
+ async empty(applicationIdOrBucketRef, bucketRefOrOptions, legacyOptions) {
1361
+ const explicitApplication = typeof bucketRefOrOptions === "string";
1362
+ const applicationId = resolveStorageApplicationId(
1363
+ this.defaultApplicationId,
1364
+ explicitApplication ? applicationIdOrBucketRef : void 0
1365
+ );
1366
+ const bucketRef = explicitApplication ? bucketRefOrOptions : applicationIdOrBucketRef;
1367
+ const options = explicitApplication ? legacyOptions : bucketRefOrOptions;
1368
+ return this.httpClient.delete(
1369
+ `/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/trash`,
1370
+ { query: { environment: options?.environment } }
1317
1371
  );
1318
1372
  }
1319
1373
  };
1320
1374
 
1321
1375
  // src/resources/storage-upload-sessions.ts
1322
1376
  var StorageUploadSessionsResource = class extends BaseResource {
1323
- constructor(httpClient, transport = tusUploadTransport) {
1377
+ constructor(httpClient, transport = tusUploadTransport, defaultApplicationId) {
1324
1378
  super(httpClient);
1325
1379
  this.transport = transport;
1380
+ this.defaultApplicationId = defaultApplicationId;
1326
1381
  }
1327
1382
  transport;
1328
- /**
1329
- * List upload sessions for a bucket.
1330
- *
1331
- * @param applicationId - The application ID (UUID).
1332
- * @param bucketId - The bucket ID (UUID).
1333
- * @param query - Optional pagination parameters.
1334
- * @returns A paginated list of upload sessions.
1335
- */
1336
- async list(applicationId, bucketId, query) {
1337
- return this.httpClient.get(`/applications/${applicationId}/storage/buckets/${bucketId}/uploads`, {
1338
- query
1339
- });
1383
+ defaultApplicationId;
1384
+ async list(applicationIdOrBucketRef, bucketRefOrQuery, legacyQuery) {
1385
+ const explicitApplication = typeof bucketRefOrQuery === "string";
1386
+ const applicationId = resolveStorageApplicationId(
1387
+ this.defaultApplicationId,
1388
+ explicitApplication ? applicationIdOrBucketRef : void 0
1389
+ );
1390
+ const bucketRef = explicitApplication ? bucketRefOrQuery : applicationIdOrBucketRef;
1391
+ const query = explicitApplication ? legacyQuery : bucketRefOrQuery;
1392
+ return this.httpClient.get(
1393
+ `/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/uploads`,
1394
+ { query }
1395
+ );
1340
1396
  }
1341
- /**
1342
- * Create an upload session. Returns the session metadata and a signed upload
1343
- * URL for sending file data. This is the low-level method — for most use
1344
- * cases prefer `client.applications.storage.upload()` which also computes the
1345
- * required SHA-256 checksum for you.
1346
- *
1347
- * @param applicationId - The application ID (UUID).
1348
- * @param bucketId - The bucket ID (UUID).
1349
- * @param data - Object key, content length, SHA-256 checksum, and optional content type / extra checksums.
1350
- * @returns The session and resumable upload instructions (URL, method, headers).
1351
- */
1352
- async create(applicationId, bucketId, data) {
1353
- return this.httpClient.post(`/applications/${applicationId}/storage/buckets/${bucketId}/uploads`, data);
1397
+ async create(applicationIdOrBucketRef, bucketRefOrData, dataOrOptions, legacyOptions) {
1398
+ const explicitApplication = typeof bucketRefOrData === "string";
1399
+ const applicationId = resolveStorageApplicationId(
1400
+ this.defaultApplicationId,
1401
+ explicitApplication ? applicationIdOrBucketRef : void 0
1402
+ );
1403
+ const bucketRef = explicitApplication ? bucketRefOrData : applicationIdOrBucketRef;
1404
+ const data = explicitApplication ? dataOrOptions : bucketRefOrData;
1405
+ const options = explicitApplication ? legacyOptions : dataOrOptions;
1406
+ return this.httpClient.post(
1407
+ `/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/uploads`,
1408
+ data,
1409
+ { query: { environment: options?.environment } }
1410
+ );
1354
1411
  }
1355
- /**
1356
- * Get an upload session by ID. Use this to track server-side processing after
1357
- * an upload (poll until `state === 'completed'`).
1358
- *
1359
- * @param applicationId - The application ID (UUID).
1360
- * @param bucketId - The bucket ID (UUID).
1361
- * @param sessionId - The upload session ID (UUID).
1362
- * @returns The current session state.
1363
- */
1364
- async get(applicationId, bucketId, sessionId) {
1365
- return this.httpClient.get(`/applications/${applicationId}/storage/buckets/${bucketId}/uploads/${sessionId}`);
1412
+ async get(applicationIdOrBucketRef, bucketRefOrSessionId, sessionIdOrOptions, legacyOptions) {
1413
+ const explicitApplication = typeof sessionIdOrOptions === "string";
1414
+ const applicationId = resolveStorageApplicationId(
1415
+ this.defaultApplicationId,
1416
+ explicitApplication ? applicationIdOrBucketRef : void 0
1417
+ );
1418
+ const bucketRef = explicitApplication ? bucketRefOrSessionId : applicationIdOrBucketRef;
1419
+ const sessionId = explicitApplication ? sessionIdOrOptions : bucketRefOrSessionId;
1420
+ const options = explicitApplication ? legacyOptions : sessionIdOrOptions;
1421
+ return this.httpClient.get(
1422
+ `/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/uploads/${sessionId}`,
1423
+ { query: { environment: options?.environment } }
1424
+ );
1366
1425
  }
1367
1426
  /**
1368
1427
  * Upload bytes directly to a pre-existing signed upload URL — for example, a
@@ -1396,19 +1455,24 @@ var StorageUploadSessionsResource = class extends BaseResource {
1396
1455
  // src/resources/application-storage.ts
1397
1456
  var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
1398
1457
  var ApplicationStorageResource = class {
1458
+ constructor(httpClient, transport = tusUploadTransport, defaultApplicationId) {
1459
+ this.defaultApplicationId = defaultApplicationId;
1460
+ this.transport = transport;
1461
+ this.buckets = new StorageBucketsResource(httpClient, defaultApplicationId);
1462
+ this.objects = new StorageObjectsResource(httpClient, defaultApplicationId);
1463
+ this.uploadSessions = new StorageUploadSessionsResource(httpClient, transport, defaultApplicationId);
1464
+ this.trash = new StorageTrashResource(httpClient, defaultApplicationId);
1465
+ }
1466
+ defaultApplicationId;
1399
1467
  /** Create, list, get, and delete storage buckets. */
1400
1468
  buckets;
1401
1469
  /** List, get, delete objects, and generate access URLs. */
1402
1470
  objects;
1403
1471
  /** Low-level upload sessions and direct-to-URL byte uploads. */
1404
1472
  uploadSessions;
1473
+ /** Lists, restores, and permanently purges soft-deleted objects. */
1474
+ trash;
1405
1475
  transport;
1406
- constructor(httpClient, transport = tusUploadTransport) {
1407
- this.transport = transport;
1408
- this.buckets = new StorageBucketsResource(httpClient);
1409
- this.objects = new StorageObjectsResource(httpClient);
1410
- this.uploadSessions = new StorageUploadSessionsResource(httpClient, transport);
1411
- }
1412
1476
  /**
1413
1477
  * Upload a file to a storage bucket. Handles the full flow: computes the
1414
1478
  * required SHA-256 checksum, creates an upload session, uploads the bytes with
@@ -1426,14 +1490,18 @@ var ApplicationStorageResource = class {
1426
1490
  *
1427
1491
  * @example
1428
1492
  * ```ts
1429
- * const { session, url, object } = await client.applications.storage.upload({
1430
- * applicationId, bucketId, key: 'reports/q1.pdf', path: './q1.pdf',
1493
+ * const { session, url, object } = await client.storage.upload({
1494
+ * bucket: 'reports', key: 'q1.pdf', path: './q1.pdf',
1431
1495
  * waitForCompletion: true,
1432
1496
  * });
1433
1497
  * console.log(object?.contentLength, 'bytes available at', url);
1434
1498
  * ```
1435
1499
  */
1436
1500
  async upload(input) {
1501
+ const applicationId = resolveStorageApplicationId(this.defaultApplicationId, input.applicationId);
1502
+ const bucketRef = resolveStorageBucketReference(input);
1503
+ const completionOptions = typeof input.waitForCompletion === "object" ? input.waitForCompletion : void 0;
1504
+ const environment = input.environment ?? completionOptions?.environment;
1437
1505
  const resolved = await resolveUploadSource({
1438
1506
  key: input.key,
1439
1507
  data: input.data,
@@ -1445,14 +1513,19 @@ var ApplicationStorageResource = class {
1445
1513
  checksumSha1: input.checksumSha1,
1446
1514
  checksumMd5: input.checksumMd5
1447
1515
  });
1448
- const { session, upload } = await this.uploadSessions.create(input.applicationId, input.bucketId, {
1449
- key: input.key,
1450
- contentLength: resolved.size,
1451
- checksumSha256: resolved.checksums.sha256,
1452
- contentType: resolved.contentType,
1453
- checksumSha1: resolved.checksums.sha1,
1454
- checksumMd5: resolved.checksums.md5
1455
- });
1516
+ const { session, upload } = await this.uploadSessions.create(
1517
+ applicationId,
1518
+ bucketRef,
1519
+ {
1520
+ key: input.key,
1521
+ contentLength: resolved.size,
1522
+ checksumSha256: resolved.checksums.sha256,
1523
+ contentType: resolved.contentType,
1524
+ checksumSha1: resolved.checksums.sha1,
1525
+ checksumMd5: resolved.checksums.md5
1526
+ },
1527
+ { environment }
1528
+ );
1456
1529
  await runResolvedUpload(
1457
1530
  this.transport,
1458
1531
  upload.url,
@@ -1469,9 +1542,12 @@ var ApplicationStorageResource = class {
1469
1542
  { "Tus-Resumable": "1.0.0", ...upload.headers }
1470
1543
  ).catch(toUploadError);
1471
1544
  if (input.waitForCompletion) {
1472
- const options = typeof input.waitForCompletion === "object" ? input.waitForCompletion : void 0;
1473
- const completed = await this.waitForCompletion(input.applicationId, input.bucketId, session.id, options);
1474
- const object = await this.objects.getByKey(input.applicationId, input.bucketId, input.key) ?? void 0;
1545
+ const options = completionOptions ?? {};
1546
+ const completed = await this.waitForCompletion(applicationId, bucketRef, session.id, {
1547
+ ...options,
1548
+ environment
1549
+ });
1550
+ const object = await this.objects.getByKey(applicationId, bucketRef, input.key, { environment }) ?? void 0;
1475
1551
  return { session: completed, url: upload.publicObjectUrl, object };
1476
1552
  }
1477
1553
  return { session, url: upload.publicObjectUrl };
@@ -1487,8 +1563,8 @@ var ApplicationStorageResource = class {
1487
1563
  *
1488
1564
  * @example
1489
1565
  * ```ts
1490
- * const results = await client.applications.storage.uploadBatch(
1491
- * files.map((f) => ({ applicationId, bucketId, key: `uploads/${f.name}`, data: f })),
1566
+ * const results = await client.storage.uploadBatch(
1567
+ * files.map((f) => ({ bucket: 'uploads', key: f.name, data: f })),
1492
1568
  * { concurrency: 6, onProgress: (done, total) => console.log(`${done}/${total}`) },
1493
1569
  * );
1494
1570
  * const failed = results.filter((r) => r.error);
@@ -1515,22 +1591,22 @@ var ApplicationStorageResource = class {
1515
1591
  await Promise.all(Array.from({ length: Math.min(concurrency, inputs.length) }, () => worker()));
1516
1592
  return results;
1517
1593
  }
1518
- /**
1519
- * Poll an upload session until the object is finalized server-side.
1520
- *
1521
- * @param applicationId - The application ID (UUID).
1522
- * @param bucketId - The bucket ID (UUID).
1523
- * @param sessionId - The upload session ID (UUID).
1524
- * @param options - Timeout and polling interval.
1525
- * @returns The completed session.
1526
- * @throws {@link UploadError} if the session fails, expires, or the timeout elapses.
1527
- */
1528
- async waitForCompletion(applicationId, bucketId, sessionId, options) {
1594
+ async waitForCompletion(applicationIdOrBucketRef, bucketRefOrSessionId, sessionIdOrOptions, legacyOptions) {
1595
+ const explicitApplication = typeof sessionIdOrOptions === "string";
1596
+ const applicationId = resolveStorageApplicationId(
1597
+ this.defaultApplicationId,
1598
+ explicitApplication ? applicationIdOrBucketRef : void 0
1599
+ );
1600
+ const bucketRef = explicitApplication ? bucketRefOrSessionId : applicationIdOrBucketRef;
1601
+ const sessionId = explicitApplication ? sessionIdOrOptions : bucketRefOrSessionId;
1602
+ const options = explicitApplication ? legacyOptions : sessionIdOrOptions;
1529
1603
  const timeoutMs = options?.timeoutMs ?? 6e4;
1530
1604
  const pollIntervalMs = options?.pollIntervalMs ?? 1e3;
1531
1605
  const deadline = Date.now() + timeoutMs;
1532
1606
  for (; ; ) {
1533
- const session = await this.uploadSessions.get(applicationId, bucketId, sessionId);
1607
+ const session = await this.uploadSessions.get(applicationId, bucketRef, sessionId, {
1608
+ environment: options?.environment
1609
+ });
1534
1610
  if (session.state === "completed") return session;
1535
1611
  if (session.state === "failed" || session.state === "expired") {
1536
1612
  throw new UploadError(`Upload session ${session.state}.`);
@@ -1564,15 +1640,14 @@ var ApplicationsResource = class extends BaseResource {
1564
1640
  * @example
1565
1641
  * ```ts
1566
1642
  * // Upload a file
1567
- * const { url } = await client.applications.storage.upload({
1568
- * applicationId: 'app-id',
1569
- * bucketId: 'bucket-id',
1643
+ * const { url } = await client.storage.upload({
1644
+ * bucket: 'assets',
1570
1645
  * key: 'images/logo.png',
1571
1646
  * data: fileData,
1572
1647
  * });
1573
1648
  *
1574
1649
  * // List objects in a bucket
1575
- * const { items } = await client.applications.storage.objects.list('app-id', 'bucket-id');
1650
+ * const { items } = await client.storage.objects.list('assets');
1576
1651
  * ```
1577
1652
  */
1578
1653
  storage;
@@ -1585,10 +1660,10 @@ var ApplicationsResource = class extends BaseResource {
1585
1660
  * ```
1586
1661
  */
1587
1662
  requests;
1588
- constructor(...args) {
1589
- super(...args);
1663
+ constructor(httpClient, defaultApplicationId) {
1664
+ super(httpClient);
1590
1665
  this.envVars = new ApplicationEnvVarsResource(this.httpClient);
1591
- this.storage = new ApplicationStorageResource(this.httpClient);
1666
+ this.storage = new ApplicationStorageResource(this.httpClient, void 0, defaultApplicationId);
1592
1667
  this.requests = new ApplicationRequestsResource(this.httpClient);
1593
1668
  }
1594
1669
  /**
@@ -2298,6 +2373,15 @@ var GigadriveClient = class {
2298
2373
  organizations;
2299
2374
  /** Application management (list, environment variables, storage). */
2300
2375
  applications;
2376
+ /**
2377
+ * Context-bound file storage operations.
2378
+ *
2379
+ * Deployed workloads receive their application context through
2380
+ * `GIGADRIVE_APPLICATION_ID`; management clients can set
2381
+ * {@link GigadriveClientConfig.applicationId}. This is the same resource as
2382
+ * {@link applications}.storage.
2383
+ */
2384
+ storage;
2301
2385
  /** Deployment lifecycle (create, upload, status, logs). */
2302
2386
  deployments;
2303
2387
  /** AI Gateway — OpenAI-compatible chat completions and model listing. */
@@ -2310,12 +2394,14 @@ var GigadriveClient = class {
2310
2394
  imageOptimization;
2311
2395
  constructor(config = {}) {
2312
2396
  const baseUrl = config.baseUrl ?? readEnv("GIGADRIVE_API_BASE_URL") ?? DEFAULT_BASE_URL2;
2397
+ const applicationId = config.applicationId ?? readEnv("GIGADRIVE_APPLICATION_ID");
2313
2398
  const fetchFn = config.fetch ?? globalThis.fetch.bind(globalThis);
2314
2399
  const credentialProvider = resolveCredentialProvider({ ...config, baseUrl, fetch: fetchFn });
2315
2400
  const tokenManager = new TokenManager(credentialProvider);
2316
2401
  const httpClient = new HttpClient(baseUrl, tokenManager, fetchFn);
2317
2402
  this.organizations = new OrganizationsResource(httpClient);
2318
- this.applications = new ApplicationsResource(httpClient);
2403
+ this.applications = new ApplicationsResource(httpClient, applicationId);
2404
+ this.storage = this.applications.storage;
2319
2405
  this.deployments = new DeploymentsResource(httpClient);
2320
2406
  this.aiGateway = new AiGatewayResource(httpClient);
2321
2407
  this.apiKeys = new ApiKeysResource(httpClient);
@@ -2349,6 +2435,7 @@ export {
2349
2435
  ApplicationStorageResource,
2350
2436
  ApplicationsResource,
2351
2437
  AuthenticationError,
2438
+ ConfigurationError,
2352
2439
  DeploymentsResource,
2353
2440
  GigadriveClient,
2354
2441
  GigadriveError,
@@ -2361,6 +2448,7 @@ export {
2361
2448
  StickySessionsResource,
2362
2449
  StorageBucketsResource,
2363
2450
  StorageObjectsResource,
2451
+ StorageTrashResource,
2364
2452
  StorageUploadSessionsResource,
2365
2453
  UploadError,
2366
2454
  UploadSessionExpiredError,