@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.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
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
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
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
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
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
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
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
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
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
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
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
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
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
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,
|
|
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
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
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
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
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/${
|
|
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
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
return this.httpClient.get(
|
|
1338
|
-
|
|
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
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
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
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
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.
|
|
1430
|
-
*
|
|
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(
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
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 =
|
|
1473
|
-
const completed = await this.waitForCompletion(
|
|
1474
|
-
|
|
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.
|
|
1491
|
-
* files.map((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
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
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,
|
|
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.
|
|
1568
|
-
*
|
|
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.
|
|
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(
|
|
1589
|
-
super(
|
|
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,
|