@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 +80 -21
- package/dist/index.d.mts +867 -836
- package/dist/index.d.ts +867 -836
- package/dist/index.js +317 -227
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +315 -227
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -43,6 +43,7 @@ __export(src_exports, {
|
|
|
43
43
|
ApplicationStorageResource: () => ApplicationStorageResource,
|
|
44
44
|
ApplicationsResource: () => ApplicationsResource,
|
|
45
45
|
AuthenticationError: () => AuthenticationError,
|
|
46
|
+
ConfigurationError: () => ConfigurationError,
|
|
46
47
|
DeploymentsResource: () => DeploymentsResource,
|
|
47
48
|
GigadriveClient: () => GigadriveClient,
|
|
48
49
|
GigadriveError: () => GigadriveError,
|
|
@@ -55,6 +56,7 @@ __export(src_exports, {
|
|
|
55
56
|
StickySessionsResource: () => StickySessionsResource,
|
|
56
57
|
StorageBucketsResource: () => StorageBucketsResource,
|
|
57
58
|
StorageObjectsResource: () => StorageObjectsResource,
|
|
59
|
+
StorageTrashResource: () => StorageTrashResource,
|
|
58
60
|
StorageUploadSessionsResource: () => StorageUploadSessionsResource,
|
|
59
61
|
UploadError: () => UploadError,
|
|
60
62
|
UploadSessionExpiredError: () => UploadSessionExpiredError,
|
|
@@ -77,6 +79,12 @@ var AuthenticationError = class extends GigadriveError {
|
|
|
77
79
|
this.name = "AuthenticationError";
|
|
78
80
|
}
|
|
79
81
|
};
|
|
82
|
+
var ConfigurationError = class extends GigadriveError {
|
|
83
|
+
constructor(message) {
|
|
84
|
+
super(message);
|
|
85
|
+
this.name = "ConfigurationError";
|
|
86
|
+
}
|
|
87
|
+
};
|
|
80
88
|
var ApiError = class extends GigadriveError {
|
|
81
89
|
/** The HTTP status code of the failed response (e.g. 404, 500). */
|
|
82
90
|
status;
|
|
@@ -1205,230 +1213,283 @@ var toUploadError = (error) => {
|
|
|
1205
1213
|
throw new UploadError(error instanceof Error ? error.message : "The upload failed.", error);
|
|
1206
1214
|
};
|
|
1207
1215
|
|
|
1216
|
+
// src/resources/storage-context.ts
|
|
1217
|
+
var resolveStorageApplicationId = (defaultApplicationId, explicitApplicationId) => {
|
|
1218
|
+
const applicationId = explicitApplicationId ?? defaultApplicationId;
|
|
1219
|
+
if (applicationId) return applicationId;
|
|
1220
|
+
throw new ConfigurationError(
|
|
1221
|
+
"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."
|
|
1222
|
+
);
|
|
1223
|
+
};
|
|
1224
|
+
var resolveStorageBucketReference = (input) => {
|
|
1225
|
+
const hasBucket = typeof input.bucket === "string";
|
|
1226
|
+
const hasBucketId = typeof input.bucketId === "string";
|
|
1227
|
+
if (hasBucket === hasBucketId) {
|
|
1228
|
+
throw new ConfigurationError(
|
|
1229
|
+
"Provide exactly one storage bucket reference using `bucket` or deprecated `bucketId`."
|
|
1230
|
+
);
|
|
1231
|
+
}
|
|
1232
|
+
return hasBucket ? input.bucket : input.bucketId;
|
|
1233
|
+
};
|
|
1234
|
+
var encodeStorageBucketReference = (bucketRef) => encodeURIComponent(bucketRef);
|
|
1235
|
+
|
|
1208
1236
|
// src/resources/storage-buckets.ts
|
|
1209
1237
|
var StorageBucketsResource = class extends BaseResource {
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
* ```
|
|
1222
|
-
*/
|
|
1223
|
-
async list(applicationId, query) {
|
|
1238
|
+
constructor(httpClient, defaultApplicationId) {
|
|
1239
|
+
super(httpClient);
|
|
1240
|
+
this.defaultApplicationId = defaultApplicationId;
|
|
1241
|
+
}
|
|
1242
|
+
defaultApplicationId;
|
|
1243
|
+
async list(applicationIdOrQuery, legacyQuery) {
|
|
1244
|
+
const applicationId = resolveStorageApplicationId(
|
|
1245
|
+
this.defaultApplicationId,
|
|
1246
|
+
typeof applicationIdOrQuery === "string" ? applicationIdOrQuery : void 0
|
|
1247
|
+
);
|
|
1248
|
+
const query = typeof applicationIdOrQuery === "string" ? legacyQuery : applicationIdOrQuery;
|
|
1224
1249
|
return this.httpClient.get(`/applications/${applicationId}/storage/buckets`, {
|
|
1225
1250
|
query
|
|
1226
1251
|
});
|
|
1227
1252
|
}
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
*
|
|
1235
|
-
* @example
|
|
1236
|
-
* ```ts
|
|
1237
|
-
* const bucket = await client.applications.storage.buckets.create('app-id', {
|
|
1238
|
-
* name: 'Assets',
|
|
1239
|
-
* environmentId: 'env-id',
|
|
1240
|
-
* visibility: 'public',
|
|
1241
|
-
* });
|
|
1242
|
-
* console.log(`Bucket CDN: https://${bucket.cdnHostname}`);
|
|
1243
|
-
* ```
|
|
1244
|
-
*/
|
|
1245
|
-
async create(applicationId, data) {
|
|
1253
|
+
async create(applicationIdOrData, legacyData) {
|
|
1254
|
+
const applicationId = resolveStorageApplicationId(
|
|
1255
|
+
this.defaultApplicationId,
|
|
1256
|
+
typeof applicationIdOrData === "string" ? applicationIdOrData : void 0
|
|
1257
|
+
);
|
|
1258
|
+
const data = typeof applicationIdOrData === "string" ? legacyData : applicationIdOrData;
|
|
1246
1259
|
return this.httpClient.post(`/applications/${applicationId}/storage/buckets`, data);
|
|
1247
1260
|
}
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
return this.httpClient.get(`/applications/${applicationId}/storage/buckets/${bucketId}`);
|
|
1261
|
+
async get(applicationIdOrBucketRef, bucketRefOrOptions, legacyOptions) {
|
|
1262
|
+
const explicitApplication = typeof bucketRefOrOptions === "string";
|
|
1263
|
+
const applicationId = resolveStorageApplicationId(
|
|
1264
|
+
this.defaultApplicationId,
|
|
1265
|
+
explicitApplication ? applicationIdOrBucketRef : void 0
|
|
1266
|
+
);
|
|
1267
|
+
const bucketRef = explicitApplication ? bucketRefOrOptions : applicationIdOrBucketRef;
|
|
1268
|
+
const options = explicitApplication ? legacyOptions : bucketRefOrOptions;
|
|
1269
|
+
return this.httpClient.get(
|
|
1270
|
+
`/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}`,
|
|
1271
|
+
{
|
|
1272
|
+
query: { environment: options?.environment }
|
|
1273
|
+
}
|
|
1274
|
+
);
|
|
1263
1275
|
}
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
return this.httpClient.delete(`/applications/${applicationId}/storage/buckets/${bucketId}`);
|
|
1276
|
+
async delete(applicationIdOrBucketRef, bucketRefOrOptions, legacyOptions) {
|
|
1277
|
+
const explicitApplication = typeof bucketRefOrOptions === "string";
|
|
1278
|
+
const applicationId = resolveStorageApplicationId(
|
|
1279
|
+
this.defaultApplicationId,
|
|
1280
|
+
explicitApplication ? applicationIdOrBucketRef : void 0
|
|
1281
|
+
);
|
|
1282
|
+
const bucketRef = explicitApplication ? bucketRefOrOptions : applicationIdOrBucketRef;
|
|
1283
|
+
const options = explicitApplication ? legacyOptions : bucketRefOrOptions;
|
|
1284
|
+
return this.httpClient.delete(
|
|
1285
|
+
`/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}`,
|
|
1286
|
+
{ query: { environment: options?.environment } }
|
|
1287
|
+
);
|
|
1277
1288
|
}
|
|
1278
1289
|
};
|
|
1279
1290
|
|
|
1280
1291
|
// src/resources/storage-objects.ts
|
|
1281
1292
|
var StorageObjectsResource = class extends BaseResource {
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
query
|
|
1302
|
-
});
|
|
1293
|
+
constructor(httpClient, defaultApplicationId) {
|
|
1294
|
+
super(httpClient);
|
|
1295
|
+
this.defaultApplicationId = defaultApplicationId;
|
|
1296
|
+
}
|
|
1297
|
+
defaultApplicationId;
|
|
1298
|
+
async list(applicationIdOrBucketRef, bucketRefOrQuery, legacyQuery) {
|
|
1299
|
+
const explicitApplication = typeof bucketRefOrQuery === "string";
|
|
1300
|
+
const applicationId = resolveStorageApplicationId(
|
|
1301
|
+
this.defaultApplicationId,
|
|
1302
|
+
explicitApplication ? applicationIdOrBucketRef : void 0
|
|
1303
|
+
);
|
|
1304
|
+
const bucketRef = explicitApplication ? bucketRefOrQuery : applicationIdOrBucketRef;
|
|
1305
|
+
const query = explicitApplication ? legacyQuery : bucketRefOrQuery;
|
|
1306
|
+
return this.httpClient.get(
|
|
1307
|
+
`/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/objects`,
|
|
1308
|
+
{
|
|
1309
|
+
query
|
|
1310
|
+
}
|
|
1311
|
+
);
|
|
1303
1312
|
}
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
*/
|
|
1318
|
-
async get(applicationId, bucketId, objectId) {
|
|
1319
|
-
return this.httpClient.get(`/applications/${applicationId}/storage/buckets/${bucketId}/objects/${objectId}`);
|
|
1313
|
+
async get(applicationIdOrBucketRef, bucketRefOrObjectId, objectIdOrOptions, legacyOptions) {
|
|
1314
|
+
const explicitApplication = typeof objectIdOrOptions === "string";
|
|
1315
|
+
const applicationId = resolveStorageApplicationId(
|
|
1316
|
+
this.defaultApplicationId,
|
|
1317
|
+
explicitApplication ? applicationIdOrBucketRef : void 0
|
|
1318
|
+
);
|
|
1319
|
+
const bucketRef = explicitApplication ? bucketRefOrObjectId : applicationIdOrBucketRef;
|
|
1320
|
+
const objectId = explicitApplication ? objectIdOrOptions : bucketRefOrObjectId;
|
|
1321
|
+
const options = explicitApplication ? legacyOptions : objectIdOrOptions;
|
|
1322
|
+
return this.httpClient.get(
|
|
1323
|
+
`/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/objects/${objectId}`,
|
|
1324
|
+
{ query: { environment: options?.environment } }
|
|
1325
|
+
);
|
|
1320
1326
|
}
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
* @returns The matching object, or `null` if not found.
|
|
1331
|
-
*/
|
|
1332
|
-
async getByKey(applicationId, bucketId, key) {
|
|
1327
|
+
async getByKey(applicationIdOrBucketRef, bucketRefOrKey, keyOrOptions, legacyOptions) {
|
|
1328
|
+
const explicitApplication = typeof keyOrOptions === "string";
|
|
1329
|
+
const applicationId = resolveStorageApplicationId(
|
|
1330
|
+
this.defaultApplicationId,
|
|
1331
|
+
explicitApplication ? applicationIdOrBucketRef : void 0
|
|
1332
|
+
);
|
|
1333
|
+
const bucketRef = explicitApplication ? bucketRefOrKey : applicationIdOrBucketRef;
|
|
1334
|
+
const key = explicitApplication ? keyOrOptions : bucketRefOrKey;
|
|
1335
|
+
const options = explicitApplication ? legacyOptions : keyOrOptions;
|
|
1333
1336
|
let cursor;
|
|
1334
1337
|
do {
|
|
1335
|
-
const page = await this.list(applicationId,
|
|
1338
|
+
const page = await this.list(applicationId, bucketRef, {
|
|
1339
|
+
environment: options?.environment,
|
|
1340
|
+
prefix: key,
|
|
1341
|
+
cursor
|
|
1342
|
+
});
|
|
1336
1343
|
const match = page.items.find((object) => object.key === key);
|
|
1337
1344
|
if (match) return match;
|
|
1338
1345
|
cursor = page.nextCursor;
|
|
1339
1346
|
} while (cursor);
|
|
1340
1347
|
return null;
|
|
1341
1348
|
}
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
return this.httpClient.delete(`/applications/${applicationId}/storage/buckets/${bucketId}/objects/${objectId}`);
|
|
1349
|
+
async delete(applicationIdOrBucketRef, bucketRefOrObjectId, objectIdOrOptions, legacyOptions) {
|
|
1350
|
+
const explicitApplication = typeof objectIdOrOptions === "string";
|
|
1351
|
+
const applicationId = resolveStorageApplicationId(
|
|
1352
|
+
this.defaultApplicationId,
|
|
1353
|
+
explicitApplication ? applicationIdOrBucketRef : void 0
|
|
1354
|
+
);
|
|
1355
|
+
const bucketRef = explicitApplication ? bucketRefOrObjectId : applicationIdOrBucketRef;
|
|
1356
|
+
const objectId = explicitApplication ? objectIdOrOptions : bucketRefOrObjectId;
|
|
1357
|
+
const options = explicitApplication ? legacyOptions : objectIdOrOptions;
|
|
1358
|
+
return this.httpClient.delete(
|
|
1359
|
+
`/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/objects/${objectId}`,
|
|
1360
|
+
{ query: { environment: options?.environment } }
|
|
1361
|
+
);
|
|
1356
1362
|
}
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
* @returns The access URL and its type/expiry.
|
|
1367
|
-
*
|
|
1368
|
-
* @example
|
|
1369
|
-
* ```ts
|
|
1370
|
-
* const access = await client.applications.storage.objects.getAccessUrl('app-id', 'bucket-id', 'object-id', {
|
|
1371
|
-
* expiresInSeconds: 3600,
|
|
1372
|
-
* });
|
|
1373
|
-
* if (access.accessType === 'signed') {
|
|
1374
|
-
* console.log(`Signed URL expires at ${access.expiresAt}`);
|
|
1375
|
-
* }
|
|
1376
|
-
* console.log(`Download: ${access.url}`);
|
|
1377
|
-
* ```
|
|
1378
|
-
*/
|
|
1379
|
-
async getAccessUrl(applicationId, bucketId, objectId, options) {
|
|
1363
|
+
async getAccessUrl(applicationIdOrBucketRef, bucketRefOrObjectId, objectIdOrOptions, legacyOptions) {
|
|
1364
|
+
const explicitApplication = typeof objectIdOrOptions === "string";
|
|
1365
|
+
const applicationId = resolveStorageApplicationId(
|
|
1366
|
+
this.defaultApplicationId,
|
|
1367
|
+
explicitApplication ? applicationIdOrBucketRef : void 0
|
|
1368
|
+
);
|
|
1369
|
+
const bucketRef = explicitApplication ? bucketRefOrObjectId : applicationIdOrBucketRef;
|
|
1370
|
+
const objectId = explicitApplication ? objectIdOrOptions : bucketRefOrObjectId;
|
|
1371
|
+
const options = explicitApplication ? legacyOptions : objectIdOrOptions;
|
|
1380
1372
|
return this.httpClient.get(
|
|
1381
|
-
`/applications/${applicationId}/storage/buckets/${
|
|
1382
|
-
{ query: { expiresInSeconds: options?.expiresInSeconds } }
|
|
1373
|
+
`/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/objects/${objectId}/access-url`,
|
|
1374
|
+
{ query: { environment: options?.environment, expiresInSeconds: options?.expiresInSeconds } }
|
|
1375
|
+
);
|
|
1376
|
+
}
|
|
1377
|
+
};
|
|
1378
|
+
|
|
1379
|
+
// src/resources/storage-trash.ts
|
|
1380
|
+
var StorageTrashResource = class extends BaseResource {
|
|
1381
|
+
constructor(httpClient, defaultApplicationId) {
|
|
1382
|
+
super(httpClient);
|
|
1383
|
+
this.defaultApplicationId = defaultApplicationId;
|
|
1384
|
+
}
|
|
1385
|
+
defaultApplicationId;
|
|
1386
|
+
async list(applicationIdOrBucketRef, bucketRefOrQuery, legacyQuery) {
|
|
1387
|
+
const explicitApplication = typeof bucketRefOrQuery === "string";
|
|
1388
|
+
const applicationId = resolveStorageApplicationId(
|
|
1389
|
+
this.defaultApplicationId,
|
|
1390
|
+
explicitApplication ? applicationIdOrBucketRef : void 0
|
|
1391
|
+
);
|
|
1392
|
+
const bucketRef = explicitApplication ? bucketRefOrQuery : applicationIdOrBucketRef;
|
|
1393
|
+
const query = explicitApplication ? legacyQuery : bucketRefOrQuery;
|
|
1394
|
+
return this.httpClient.get(
|
|
1395
|
+
`/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/trash`,
|
|
1396
|
+
{ query }
|
|
1397
|
+
);
|
|
1398
|
+
}
|
|
1399
|
+
async restore(applicationIdOrBucketRef, bucketRefOrObjectId, objectIdOrOptions, legacyOptions) {
|
|
1400
|
+
const explicitApplication = typeof objectIdOrOptions === "string";
|
|
1401
|
+
const applicationId = resolveStorageApplicationId(
|
|
1402
|
+
this.defaultApplicationId,
|
|
1403
|
+
explicitApplication ? applicationIdOrBucketRef : void 0
|
|
1404
|
+
);
|
|
1405
|
+
const bucketRef = explicitApplication ? bucketRefOrObjectId : applicationIdOrBucketRef;
|
|
1406
|
+
const objectId = explicitApplication ? objectIdOrOptions : bucketRefOrObjectId;
|
|
1407
|
+
const options = explicitApplication ? legacyOptions : objectIdOrOptions;
|
|
1408
|
+
return this.httpClient.post(
|
|
1409
|
+
`/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/trash/${objectId}/restore`,
|
|
1410
|
+
void 0,
|
|
1411
|
+
{ query: { environment: options?.environment } }
|
|
1412
|
+
);
|
|
1413
|
+
}
|
|
1414
|
+
async purge(applicationIdOrBucketRef, bucketRefOrObjectId, objectIdOrOptions, legacyOptions) {
|
|
1415
|
+
const explicitApplication = typeof objectIdOrOptions === "string";
|
|
1416
|
+
const applicationId = resolveStorageApplicationId(
|
|
1417
|
+
this.defaultApplicationId,
|
|
1418
|
+
explicitApplication ? applicationIdOrBucketRef : void 0
|
|
1419
|
+
);
|
|
1420
|
+
const bucketRef = explicitApplication ? bucketRefOrObjectId : applicationIdOrBucketRef;
|
|
1421
|
+
const objectId = explicitApplication ? objectIdOrOptions : bucketRefOrObjectId;
|
|
1422
|
+
const options = explicitApplication ? legacyOptions : objectIdOrOptions;
|
|
1423
|
+
return this.httpClient.delete(
|
|
1424
|
+
`/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/trash/${objectId}`,
|
|
1425
|
+
{ query: { environment: options?.environment } }
|
|
1426
|
+
);
|
|
1427
|
+
}
|
|
1428
|
+
async empty(applicationIdOrBucketRef, bucketRefOrOptions, legacyOptions) {
|
|
1429
|
+
const explicitApplication = typeof bucketRefOrOptions === "string";
|
|
1430
|
+
const applicationId = resolveStorageApplicationId(
|
|
1431
|
+
this.defaultApplicationId,
|
|
1432
|
+
explicitApplication ? applicationIdOrBucketRef : void 0
|
|
1433
|
+
);
|
|
1434
|
+
const bucketRef = explicitApplication ? bucketRefOrOptions : applicationIdOrBucketRef;
|
|
1435
|
+
const options = explicitApplication ? legacyOptions : bucketRefOrOptions;
|
|
1436
|
+
return this.httpClient.delete(
|
|
1437
|
+
`/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/trash`,
|
|
1438
|
+
{ query: { environment: options?.environment } }
|
|
1383
1439
|
);
|
|
1384
1440
|
}
|
|
1385
1441
|
};
|
|
1386
1442
|
|
|
1387
1443
|
// src/resources/storage-upload-sessions.ts
|
|
1388
1444
|
var StorageUploadSessionsResource = class extends BaseResource {
|
|
1389
|
-
constructor(httpClient, transport = tusUploadTransport) {
|
|
1445
|
+
constructor(httpClient, transport = tusUploadTransport, defaultApplicationId) {
|
|
1390
1446
|
super(httpClient);
|
|
1391
1447
|
this.transport = transport;
|
|
1448
|
+
this.defaultApplicationId = defaultApplicationId;
|
|
1392
1449
|
}
|
|
1393
1450
|
transport;
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
return this.httpClient.get(
|
|
1404
|
-
|
|
1405
|
-
|
|
1451
|
+
defaultApplicationId;
|
|
1452
|
+
async list(applicationIdOrBucketRef, bucketRefOrQuery, legacyQuery) {
|
|
1453
|
+
const explicitApplication = typeof bucketRefOrQuery === "string";
|
|
1454
|
+
const applicationId = resolveStorageApplicationId(
|
|
1455
|
+
this.defaultApplicationId,
|
|
1456
|
+
explicitApplication ? applicationIdOrBucketRef : void 0
|
|
1457
|
+
);
|
|
1458
|
+
const bucketRef = explicitApplication ? bucketRefOrQuery : applicationIdOrBucketRef;
|
|
1459
|
+
const query = explicitApplication ? legacyQuery : bucketRefOrQuery;
|
|
1460
|
+
return this.httpClient.get(
|
|
1461
|
+
`/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/uploads`,
|
|
1462
|
+
{ query }
|
|
1463
|
+
);
|
|
1406
1464
|
}
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1465
|
+
async create(applicationIdOrBucketRef, bucketRefOrData, dataOrOptions, legacyOptions) {
|
|
1466
|
+
const explicitApplication = typeof bucketRefOrData === "string";
|
|
1467
|
+
const applicationId = resolveStorageApplicationId(
|
|
1468
|
+
this.defaultApplicationId,
|
|
1469
|
+
explicitApplication ? applicationIdOrBucketRef : void 0
|
|
1470
|
+
);
|
|
1471
|
+
const bucketRef = explicitApplication ? bucketRefOrData : applicationIdOrBucketRef;
|
|
1472
|
+
const data = explicitApplication ? dataOrOptions : bucketRefOrData;
|
|
1473
|
+
const options = explicitApplication ? legacyOptions : dataOrOptions;
|
|
1474
|
+
return this.httpClient.post(
|
|
1475
|
+
`/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/uploads`,
|
|
1476
|
+
data,
|
|
1477
|
+
{ query: { environment: options?.environment } }
|
|
1478
|
+
);
|
|
1420
1479
|
}
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1480
|
+
async get(applicationIdOrBucketRef, bucketRefOrSessionId, sessionIdOrOptions, legacyOptions) {
|
|
1481
|
+
const explicitApplication = typeof sessionIdOrOptions === "string";
|
|
1482
|
+
const applicationId = resolveStorageApplicationId(
|
|
1483
|
+
this.defaultApplicationId,
|
|
1484
|
+
explicitApplication ? applicationIdOrBucketRef : void 0
|
|
1485
|
+
);
|
|
1486
|
+
const bucketRef = explicitApplication ? bucketRefOrSessionId : applicationIdOrBucketRef;
|
|
1487
|
+
const sessionId = explicitApplication ? sessionIdOrOptions : bucketRefOrSessionId;
|
|
1488
|
+
const options = explicitApplication ? legacyOptions : sessionIdOrOptions;
|
|
1489
|
+
return this.httpClient.get(
|
|
1490
|
+
`/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/uploads/${sessionId}`,
|
|
1491
|
+
{ query: { environment: options?.environment } }
|
|
1492
|
+
);
|
|
1432
1493
|
}
|
|
1433
1494
|
/**
|
|
1434
1495
|
* Upload bytes directly to a pre-existing signed upload URL — for example, a
|
|
@@ -1462,19 +1523,24 @@ var StorageUploadSessionsResource = class extends BaseResource {
|
|
|
1462
1523
|
// src/resources/application-storage.ts
|
|
1463
1524
|
var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
1464
1525
|
var ApplicationStorageResource = class {
|
|
1526
|
+
constructor(httpClient, transport = tusUploadTransport, defaultApplicationId) {
|
|
1527
|
+
this.defaultApplicationId = defaultApplicationId;
|
|
1528
|
+
this.transport = transport;
|
|
1529
|
+
this.buckets = new StorageBucketsResource(httpClient, defaultApplicationId);
|
|
1530
|
+
this.objects = new StorageObjectsResource(httpClient, defaultApplicationId);
|
|
1531
|
+
this.uploadSessions = new StorageUploadSessionsResource(httpClient, transport, defaultApplicationId);
|
|
1532
|
+
this.trash = new StorageTrashResource(httpClient, defaultApplicationId);
|
|
1533
|
+
}
|
|
1534
|
+
defaultApplicationId;
|
|
1465
1535
|
/** Create, list, get, and delete storage buckets. */
|
|
1466
1536
|
buckets;
|
|
1467
1537
|
/** List, get, delete objects, and generate access URLs. */
|
|
1468
1538
|
objects;
|
|
1469
1539
|
/** Low-level upload sessions and direct-to-URL byte uploads. */
|
|
1470
1540
|
uploadSessions;
|
|
1541
|
+
/** Lists, restores, and permanently purges soft-deleted objects. */
|
|
1542
|
+
trash;
|
|
1471
1543
|
transport;
|
|
1472
|
-
constructor(httpClient, transport = tusUploadTransport) {
|
|
1473
|
-
this.transport = transport;
|
|
1474
|
-
this.buckets = new StorageBucketsResource(httpClient);
|
|
1475
|
-
this.objects = new StorageObjectsResource(httpClient);
|
|
1476
|
-
this.uploadSessions = new StorageUploadSessionsResource(httpClient, transport);
|
|
1477
|
-
}
|
|
1478
1544
|
/**
|
|
1479
1545
|
* Upload a file to a storage bucket. Handles the full flow: computes the
|
|
1480
1546
|
* required SHA-256 checksum, creates an upload session, uploads the bytes with
|
|
@@ -1492,14 +1558,18 @@ var ApplicationStorageResource = class {
|
|
|
1492
1558
|
*
|
|
1493
1559
|
* @example
|
|
1494
1560
|
* ```ts
|
|
1495
|
-
* const { session, url, object } = await client.
|
|
1496
|
-
*
|
|
1561
|
+
* const { session, url, object } = await client.storage.upload({
|
|
1562
|
+
* bucket: 'reports', key: 'q1.pdf', path: './q1.pdf',
|
|
1497
1563
|
* waitForCompletion: true,
|
|
1498
1564
|
* });
|
|
1499
1565
|
* console.log(object?.contentLength, 'bytes available at', url);
|
|
1500
1566
|
* ```
|
|
1501
1567
|
*/
|
|
1502
1568
|
async upload(input) {
|
|
1569
|
+
const applicationId = resolveStorageApplicationId(this.defaultApplicationId, input.applicationId);
|
|
1570
|
+
const bucketRef = resolveStorageBucketReference(input);
|
|
1571
|
+
const completionOptions = typeof input.waitForCompletion === "object" ? input.waitForCompletion : void 0;
|
|
1572
|
+
const environment = input.environment ?? completionOptions?.environment;
|
|
1503
1573
|
const resolved = await resolveUploadSource({
|
|
1504
1574
|
key: input.key,
|
|
1505
1575
|
data: input.data,
|
|
@@ -1511,14 +1581,19 @@ var ApplicationStorageResource = class {
|
|
|
1511
1581
|
checksumSha1: input.checksumSha1,
|
|
1512
1582
|
checksumMd5: input.checksumMd5
|
|
1513
1583
|
});
|
|
1514
|
-
const { session, upload } = await this.uploadSessions.create(
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1584
|
+
const { session, upload } = await this.uploadSessions.create(
|
|
1585
|
+
applicationId,
|
|
1586
|
+
bucketRef,
|
|
1587
|
+
{
|
|
1588
|
+
key: input.key,
|
|
1589
|
+
contentLength: resolved.size,
|
|
1590
|
+
checksumSha256: resolved.checksums.sha256,
|
|
1591
|
+
contentType: resolved.contentType,
|
|
1592
|
+
checksumSha1: resolved.checksums.sha1,
|
|
1593
|
+
checksumMd5: resolved.checksums.md5
|
|
1594
|
+
},
|
|
1595
|
+
{ environment }
|
|
1596
|
+
);
|
|
1522
1597
|
await runResolvedUpload(
|
|
1523
1598
|
this.transport,
|
|
1524
1599
|
upload.url,
|
|
@@ -1535,9 +1610,12 @@ var ApplicationStorageResource = class {
|
|
|
1535
1610
|
{ "Tus-Resumable": "1.0.0", ...upload.headers }
|
|
1536
1611
|
).catch(toUploadError);
|
|
1537
1612
|
if (input.waitForCompletion) {
|
|
1538
|
-
const options =
|
|
1539
|
-
const completed = await this.waitForCompletion(
|
|
1540
|
-
|
|
1613
|
+
const options = completionOptions ?? {};
|
|
1614
|
+
const completed = await this.waitForCompletion(applicationId, bucketRef, session.id, {
|
|
1615
|
+
...options,
|
|
1616
|
+
environment
|
|
1617
|
+
});
|
|
1618
|
+
const object = await this.objects.getByKey(applicationId, bucketRef, input.key, { environment }) ?? void 0;
|
|
1541
1619
|
return { session: completed, url: upload.publicObjectUrl, object };
|
|
1542
1620
|
}
|
|
1543
1621
|
return { session, url: upload.publicObjectUrl };
|
|
@@ -1553,8 +1631,8 @@ var ApplicationStorageResource = class {
|
|
|
1553
1631
|
*
|
|
1554
1632
|
* @example
|
|
1555
1633
|
* ```ts
|
|
1556
|
-
* const results = await client.
|
|
1557
|
-
* files.map((f) => ({
|
|
1634
|
+
* const results = await client.storage.uploadBatch(
|
|
1635
|
+
* files.map((f) => ({ bucket: 'uploads', key: f.name, data: f })),
|
|
1558
1636
|
* { concurrency: 6, onProgress: (done, total) => console.log(`${done}/${total}`) },
|
|
1559
1637
|
* );
|
|
1560
1638
|
* const failed = results.filter((r) => r.error);
|
|
@@ -1581,22 +1659,22 @@ var ApplicationStorageResource = class {
|
|
|
1581
1659
|
await Promise.all(Array.from({ length: Math.min(concurrency, inputs.length) }, () => worker()));
|
|
1582
1660
|
return results;
|
|
1583
1661
|
}
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
*/
|
|
1594
|
-
async waitForCompletion(applicationId, bucketId, sessionId, options) {
|
|
1662
|
+
async waitForCompletion(applicationIdOrBucketRef, bucketRefOrSessionId, sessionIdOrOptions, legacyOptions) {
|
|
1663
|
+
const explicitApplication = typeof sessionIdOrOptions === "string";
|
|
1664
|
+
const applicationId = resolveStorageApplicationId(
|
|
1665
|
+
this.defaultApplicationId,
|
|
1666
|
+
explicitApplication ? applicationIdOrBucketRef : void 0
|
|
1667
|
+
);
|
|
1668
|
+
const bucketRef = explicitApplication ? bucketRefOrSessionId : applicationIdOrBucketRef;
|
|
1669
|
+
const sessionId = explicitApplication ? sessionIdOrOptions : bucketRefOrSessionId;
|
|
1670
|
+
const options = explicitApplication ? legacyOptions : sessionIdOrOptions;
|
|
1595
1671
|
const timeoutMs = options?.timeoutMs ?? 6e4;
|
|
1596
1672
|
const pollIntervalMs = options?.pollIntervalMs ?? 1e3;
|
|
1597
1673
|
const deadline = Date.now() + timeoutMs;
|
|
1598
1674
|
for (; ; ) {
|
|
1599
|
-
const session = await this.uploadSessions.get(applicationId,
|
|
1675
|
+
const session = await this.uploadSessions.get(applicationId, bucketRef, sessionId, {
|
|
1676
|
+
environment: options?.environment
|
|
1677
|
+
});
|
|
1600
1678
|
if (session.state === "completed") return session;
|
|
1601
1679
|
if (session.state === "failed" || session.state === "expired") {
|
|
1602
1680
|
throw new UploadError(`Upload session ${session.state}.`);
|
|
@@ -1630,15 +1708,14 @@ var ApplicationsResource = class extends BaseResource {
|
|
|
1630
1708
|
* @example
|
|
1631
1709
|
* ```ts
|
|
1632
1710
|
* // Upload a file
|
|
1633
|
-
* const { url } = await client.
|
|
1634
|
-
*
|
|
1635
|
-
* bucketId: 'bucket-id',
|
|
1711
|
+
* const { url } = await client.storage.upload({
|
|
1712
|
+
* bucket: 'assets',
|
|
1636
1713
|
* key: 'images/logo.png',
|
|
1637
1714
|
* data: fileData,
|
|
1638
1715
|
* });
|
|
1639
1716
|
*
|
|
1640
1717
|
* // List objects in a bucket
|
|
1641
|
-
* const { items } = await client.
|
|
1718
|
+
* const { items } = await client.storage.objects.list('assets');
|
|
1642
1719
|
* ```
|
|
1643
1720
|
*/
|
|
1644
1721
|
storage;
|
|
@@ -1651,10 +1728,10 @@ var ApplicationsResource = class extends BaseResource {
|
|
|
1651
1728
|
* ```
|
|
1652
1729
|
*/
|
|
1653
1730
|
requests;
|
|
1654
|
-
constructor(
|
|
1655
|
-
super(
|
|
1731
|
+
constructor(httpClient, defaultApplicationId) {
|
|
1732
|
+
super(httpClient);
|
|
1656
1733
|
this.envVars = new ApplicationEnvVarsResource(this.httpClient);
|
|
1657
|
-
this.storage = new ApplicationStorageResource(this.httpClient);
|
|
1734
|
+
this.storage = new ApplicationStorageResource(this.httpClient, void 0, defaultApplicationId);
|
|
1658
1735
|
this.requests = new ApplicationRequestsResource(this.httpClient);
|
|
1659
1736
|
}
|
|
1660
1737
|
/**
|
|
@@ -2364,6 +2441,15 @@ var GigadriveClient = class {
|
|
|
2364
2441
|
organizations;
|
|
2365
2442
|
/** Application management (list, environment variables, storage). */
|
|
2366
2443
|
applications;
|
|
2444
|
+
/**
|
|
2445
|
+
* Context-bound file storage operations.
|
|
2446
|
+
*
|
|
2447
|
+
* Deployed workloads receive their application context through
|
|
2448
|
+
* `GIGADRIVE_APPLICATION_ID`; management clients can set
|
|
2449
|
+
* {@link GigadriveClientConfig.applicationId}. This is the same resource as
|
|
2450
|
+
* {@link applications}.storage.
|
|
2451
|
+
*/
|
|
2452
|
+
storage;
|
|
2367
2453
|
/** Deployment lifecycle (create, upload, status, logs). */
|
|
2368
2454
|
deployments;
|
|
2369
2455
|
/** AI Gateway — OpenAI-compatible chat completions and model listing. */
|
|
@@ -2376,12 +2462,14 @@ var GigadriveClient = class {
|
|
|
2376
2462
|
imageOptimization;
|
|
2377
2463
|
constructor(config = {}) {
|
|
2378
2464
|
const baseUrl = config.baseUrl ?? readEnv("GIGADRIVE_API_BASE_URL") ?? DEFAULT_BASE_URL2;
|
|
2465
|
+
const applicationId = config.applicationId ?? readEnv("GIGADRIVE_APPLICATION_ID");
|
|
2379
2466
|
const fetchFn = config.fetch ?? globalThis.fetch.bind(globalThis);
|
|
2380
2467
|
const credentialProvider = resolveCredentialProvider({ ...config, baseUrl, fetch: fetchFn });
|
|
2381
2468
|
const tokenManager = new TokenManager(credentialProvider);
|
|
2382
2469
|
const httpClient = new HttpClient(baseUrl, tokenManager, fetchFn);
|
|
2383
2470
|
this.organizations = new OrganizationsResource(httpClient);
|
|
2384
|
-
this.applications = new ApplicationsResource(httpClient);
|
|
2471
|
+
this.applications = new ApplicationsResource(httpClient, applicationId);
|
|
2472
|
+
this.storage = this.applications.storage;
|
|
2385
2473
|
this.deployments = new DeploymentsResource(httpClient);
|
|
2386
2474
|
this.aiGateway = new AiGatewayResource(httpClient);
|
|
2387
2475
|
this.apiKeys = new ApiKeysResource(httpClient);
|
|
@@ -2416,6 +2504,7 @@ async function* paginate(fetchPage) {
|
|
|
2416
2504
|
ApplicationStorageResource,
|
|
2417
2505
|
ApplicationsResource,
|
|
2418
2506
|
AuthenticationError,
|
|
2507
|
+
ConfigurationError,
|
|
2419
2508
|
DeploymentsResource,
|
|
2420
2509
|
GigadriveClient,
|
|
2421
2510
|
GigadriveError,
|
|
@@ -2428,6 +2517,7 @@ async function* paginate(fetchPage) {
|
|
|
2428
2517
|
StickySessionsResource,
|
|
2429
2518
|
StorageBucketsResource,
|
|
2430
2519
|
StorageObjectsResource,
|
|
2520
|
+
StorageTrashResource,
|
|
2431
2521
|
StorageUploadSessionsResource,
|
|
2432
2522
|
UploadError,
|
|
2433
2523
|
UploadSessionExpiredError,
|