@gigadrive/sdk 0.7.28 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -21
- package/dist/index.d.mts +867 -836
- package/dist/index.d.ts +867 -836
- package/dist/index.js +327 -233
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +325 -233
- 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;
|
|
@@ -1012,11 +1018,15 @@ var sizeOf = (data) => {
|
|
|
1012
1018
|
if (data instanceof ArrayBuffer) return data.byteLength;
|
|
1013
1019
|
throw new Error("Cannot determine upload size. Pass a File, Blob, Buffer, Uint8Array, or ArrayBuffer.");
|
|
1014
1020
|
};
|
|
1015
|
-
var toTusFile = (data) => {
|
|
1016
|
-
if (
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1021
|
+
var toTusFile = async (data) => {
|
|
1022
|
+
if (!isNode()) {
|
|
1023
|
+
if (typeof Blob !== "undefined" && data instanceof Blob) return data;
|
|
1024
|
+
const bytes2 = data instanceof Uint8Array ? data : new Uint8Array(data);
|
|
1025
|
+
return new Blob([bytes2]);
|
|
1026
|
+
}
|
|
1027
|
+
const { Buffer } = await import("buffer");
|
|
1028
|
+
const bytes = typeof Blob !== "undefined" && data instanceof Blob ? new Uint8Array(await data.arrayBuffer()) : data instanceof Uint8Array ? data : new Uint8Array(data);
|
|
1029
|
+
return Buffer.isBuffer(data) ? data : Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
1020
1030
|
};
|
|
1021
1031
|
var buildChecksums = (input, sha256) => {
|
|
1022
1032
|
const checksums = { sha256 };
|
|
@@ -1037,7 +1047,7 @@ var resolveUploadSource = async (input, options = {}) => {
|
|
|
1037
1047
|
const size = input.contentLength ?? sizeOf(input.data);
|
|
1038
1048
|
const sha256 = input.checksumSha256 ?? (hash ? (await computeChecksums(await toBytes(input.data))).sha256 : "");
|
|
1039
1049
|
return {
|
|
1040
|
-
tusFile: toTusFile(input.data),
|
|
1050
|
+
tusFile: await toTusFile(input.data),
|
|
1041
1051
|
size,
|
|
1042
1052
|
contentType,
|
|
1043
1053
|
checksums: buildChecksums(input, sha256),
|
|
@@ -1139,230 +1149,283 @@ var toUploadError = (error) => {
|
|
|
1139
1149
|
throw new UploadError(error instanceof Error ? error.message : "The upload failed.", error);
|
|
1140
1150
|
};
|
|
1141
1151
|
|
|
1152
|
+
// src/resources/storage-context.ts
|
|
1153
|
+
var resolveStorageApplicationId = (defaultApplicationId, explicitApplicationId) => {
|
|
1154
|
+
const applicationId = explicitApplicationId ?? defaultApplicationId;
|
|
1155
|
+
if (applicationId) return applicationId;
|
|
1156
|
+
throw new ConfigurationError(
|
|
1157
|
+
"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."
|
|
1158
|
+
);
|
|
1159
|
+
};
|
|
1160
|
+
var resolveStorageBucketReference = (input) => {
|
|
1161
|
+
const hasBucket = typeof input.bucket === "string";
|
|
1162
|
+
const hasBucketId = typeof input.bucketId === "string";
|
|
1163
|
+
if (hasBucket === hasBucketId) {
|
|
1164
|
+
throw new ConfigurationError(
|
|
1165
|
+
"Provide exactly one storage bucket reference using `bucket` or deprecated `bucketId`."
|
|
1166
|
+
);
|
|
1167
|
+
}
|
|
1168
|
+
return hasBucket ? input.bucket : input.bucketId;
|
|
1169
|
+
};
|
|
1170
|
+
var encodeStorageBucketReference = (bucketRef) => encodeURIComponent(bucketRef);
|
|
1171
|
+
|
|
1142
1172
|
// src/resources/storage-buckets.ts
|
|
1143
1173
|
var StorageBucketsResource = class extends BaseResource {
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
* ```
|
|
1156
|
-
*/
|
|
1157
|
-
async list(applicationId, query) {
|
|
1174
|
+
constructor(httpClient, defaultApplicationId) {
|
|
1175
|
+
super(httpClient);
|
|
1176
|
+
this.defaultApplicationId = defaultApplicationId;
|
|
1177
|
+
}
|
|
1178
|
+
defaultApplicationId;
|
|
1179
|
+
async list(applicationIdOrQuery, legacyQuery) {
|
|
1180
|
+
const applicationId = resolveStorageApplicationId(
|
|
1181
|
+
this.defaultApplicationId,
|
|
1182
|
+
typeof applicationIdOrQuery === "string" ? applicationIdOrQuery : void 0
|
|
1183
|
+
);
|
|
1184
|
+
const query = typeof applicationIdOrQuery === "string" ? legacyQuery : applicationIdOrQuery;
|
|
1158
1185
|
return this.httpClient.get(`/applications/${applicationId}/storage/buckets`, {
|
|
1159
1186
|
query
|
|
1160
1187
|
});
|
|
1161
1188
|
}
|
|
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) {
|
|
1189
|
+
async create(applicationIdOrData, legacyData) {
|
|
1190
|
+
const applicationId = resolveStorageApplicationId(
|
|
1191
|
+
this.defaultApplicationId,
|
|
1192
|
+
typeof applicationIdOrData === "string" ? applicationIdOrData : void 0
|
|
1193
|
+
);
|
|
1194
|
+
const data = typeof applicationIdOrData === "string" ? legacyData : applicationIdOrData;
|
|
1180
1195
|
return this.httpClient.post(`/applications/${applicationId}/storage/buckets`, data);
|
|
1181
1196
|
}
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
return this.httpClient.get(`/applications/${applicationId}/storage/buckets/${bucketId}`);
|
|
1197
|
+
async get(applicationIdOrBucketRef, bucketRefOrOptions, legacyOptions) {
|
|
1198
|
+
const explicitApplication = typeof bucketRefOrOptions === "string";
|
|
1199
|
+
const applicationId = resolveStorageApplicationId(
|
|
1200
|
+
this.defaultApplicationId,
|
|
1201
|
+
explicitApplication ? applicationIdOrBucketRef : void 0
|
|
1202
|
+
);
|
|
1203
|
+
const bucketRef = explicitApplication ? bucketRefOrOptions : applicationIdOrBucketRef;
|
|
1204
|
+
const options = explicitApplication ? legacyOptions : bucketRefOrOptions;
|
|
1205
|
+
return this.httpClient.get(
|
|
1206
|
+
`/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}`,
|
|
1207
|
+
{
|
|
1208
|
+
query: { environment: options?.environment }
|
|
1209
|
+
}
|
|
1210
|
+
);
|
|
1197
1211
|
}
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
return this.httpClient.delete(`/applications/${applicationId}/storage/buckets/${bucketId}`);
|
|
1212
|
+
async delete(applicationIdOrBucketRef, bucketRefOrOptions, legacyOptions) {
|
|
1213
|
+
const explicitApplication = typeof bucketRefOrOptions === "string";
|
|
1214
|
+
const applicationId = resolveStorageApplicationId(
|
|
1215
|
+
this.defaultApplicationId,
|
|
1216
|
+
explicitApplication ? applicationIdOrBucketRef : void 0
|
|
1217
|
+
);
|
|
1218
|
+
const bucketRef = explicitApplication ? bucketRefOrOptions : applicationIdOrBucketRef;
|
|
1219
|
+
const options = explicitApplication ? legacyOptions : bucketRefOrOptions;
|
|
1220
|
+
return this.httpClient.delete(
|
|
1221
|
+
`/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}`,
|
|
1222
|
+
{ query: { environment: options?.environment } }
|
|
1223
|
+
);
|
|
1211
1224
|
}
|
|
1212
1225
|
};
|
|
1213
1226
|
|
|
1214
1227
|
// src/resources/storage-objects.ts
|
|
1215
1228
|
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
|
-
});
|
|
1229
|
+
constructor(httpClient, defaultApplicationId) {
|
|
1230
|
+
super(httpClient);
|
|
1231
|
+
this.defaultApplicationId = defaultApplicationId;
|
|
1232
|
+
}
|
|
1233
|
+
defaultApplicationId;
|
|
1234
|
+
async list(applicationIdOrBucketRef, bucketRefOrQuery, legacyQuery) {
|
|
1235
|
+
const explicitApplication = typeof bucketRefOrQuery === "string";
|
|
1236
|
+
const applicationId = resolveStorageApplicationId(
|
|
1237
|
+
this.defaultApplicationId,
|
|
1238
|
+
explicitApplication ? applicationIdOrBucketRef : void 0
|
|
1239
|
+
);
|
|
1240
|
+
const bucketRef = explicitApplication ? bucketRefOrQuery : applicationIdOrBucketRef;
|
|
1241
|
+
const query = explicitApplication ? legacyQuery : bucketRefOrQuery;
|
|
1242
|
+
return this.httpClient.get(
|
|
1243
|
+
`/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/objects`,
|
|
1244
|
+
{
|
|
1245
|
+
query
|
|
1246
|
+
}
|
|
1247
|
+
);
|
|
1237
1248
|
}
|
|
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}`);
|
|
1249
|
+
async get(applicationIdOrBucketRef, bucketRefOrObjectId, objectIdOrOptions, legacyOptions) {
|
|
1250
|
+
const explicitApplication = typeof objectIdOrOptions === "string";
|
|
1251
|
+
const applicationId = resolveStorageApplicationId(
|
|
1252
|
+
this.defaultApplicationId,
|
|
1253
|
+
explicitApplication ? applicationIdOrBucketRef : void 0
|
|
1254
|
+
);
|
|
1255
|
+
const bucketRef = explicitApplication ? bucketRefOrObjectId : applicationIdOrBucketRef;
|
|
1256
|
+
const objectId = explicitApplication ? objectIdOrOptions : bucketRefOrObjectId;
|
|
1257
|
+
const options = explicitApplication ? legacyOptions : objectIdOrOptions;
|
|
1258
|
+
return this.httpClient.get(
|
|
1259
|
+
`/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/objects/${objectId}`,
|
|
1260
|
+
{ query: { environment: options?.environment } }
|
|
1261
|
+
);
|
|
1254
1262
|
}
|
|
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) {
|
|
1263
|
+
async getByKey(applicationIdOrBucketRef, bucketRefOrKey, keyOrOptions, legacyOptions) {
|
|
1264
|
+
const explicitApplication = typeof keyOrOptions === "string";
|
|
1265
|
+
const applicationId = resolveStorageApplicationId(
|
|
1266
|
+
this.defaultApplicationId,
|
|
1267
|
+
explicitApplication ? applicationIdOrBucketRef : void 0
|
|
1268
|
+
);
|
|
1269
|
+
const bucketRef = explicitApplication ? bucketRefOrKey : applicationIdOrBucketRef;
|
|
1270
|
+
const key = explicitApplication ? keyOrOptions : bucketRefOrKey;
|
|
1271
|
+
const options = explicitApplication ? legacyOptions : keyOrOptions;
|
|
1267
1272
|
let cursor;
|
|
1268
1273
|
do {
|
|
1269
|
-
const page = await this.list(applicationId,
|
|
1274
|
+
const page = await this.list(applicationId, bucketRef, {
|
|
1275
|
+
environment: options?.environment,
|
|
1276
|
+
prefix: key,
|
|
1277
|
+
cursor
|
|
1278
|
+
});
|
|
1270
1279
|
const match = page.items.find((object) => object.key === key);
|
|
1271
1280
|
if (match) return match;
|
|
1272
1281
|
cursor = page.nextCursor;
|
|
1273
1282
|
} while (cursor);
|
|
1274
1283
|
return null;
|
|
1275
1284
|
}
|
|
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}`);
|
|
1285
|
+
async delete(applicationIdOrBucketRef, bucketRefOrObjectId, objectIdOrOptions, legacyOptions) {
|
|
1286
|
+
const explicitApplication = typeof objectIdOrOptions === "string";
|
|
1287
|
+
const applicationId = resolveStorageApplicationId(
|
|
1288
|
+
this.defaultApplicationId,
|
|
1289
|
+
explicitApplication ? applicationIdOrBucketRef : void 0
|
|
1290
|
+
);
|
|
1291
|
+
const bucketRef = explicitApplication ? bucketRefOrObjectId : applicationIdOrBucketRef;
|
|
1292
|
+
const objectId = explicitApplication ? objectIdOrOptions : bucketRefOrObjectId;
|
|
1293
|
+
const options = explicitApplication ? legacyOptions : objectIdOrOptions;
|
|
1294
|
+
return this.httpClient.delete(
|
|
1295
|
+
`/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/objects/${objectId}`,
|
|
1296
|
+
{ query: { environment: options?.environment } }
|
|
1297
|
+
);
|
|
1290
1298
|
}
|
|
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) {
|
|
1299
|
+
async getAccessUrl(applicationIdOrBucketRef, bucketRefOrObjectId, objectIdOrOptions, legacyOptions) {
|
|
1300
|
+
const explicitApplication = typeof objectIdOrOptions === "string";
|
|
1301
|
+
const applicationId = resolveStorageApplicationId(
|
|
1302
|
+
this.defaultApplicationId,
|
|
1303
|
+
explicitApplication ? applicationIdOrBucketRef : void 0
|
|
1304
|
+
);
|
|
1305
|
+
const bucketRef = explicitApplication ? bucketRefOrObjectId : applicationIdOrBucketRef;
|
|
1306
|
+
const objectId = explicitApplication ? objectIdOrOptions : bucketRefOrObjectId;
|
|
1307
|
+
const options = explicitApplication ? legacyOptions : objectIdOrOptions;
|
|
1314
1308
|
return this.httpClient.get(
|
|
1315
|
-
`/applications/${applicationId}/storage/buckets/${
|
|
1316
|
-
{ query: { expiresInSeconds: options?.expiresInSeconds } }
|
|
1309
|
+
`/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/objects/${objectId}/access-url`,
|
|
1310
|
+
{ query: { environment: options?.environment, expiresInSeconds: options?.expiresInSeconds } }
|
|
1311
|
+
);
|
|
1312
|
+
}
|
|
1313
|
+
};
|
|
1314
|
+
|
|
1315
|
+
// src/resources/storage-trash.ts
|
|
1316
|
+
var StorageTrashResource = class extends BaseResource {
|
|
1317
|
+
constructor(httpClient, defaultApplicationId) {
|
|
1318
|
+
super(httpClient);
|
|
1319
|
+
this.defaultApplicationId = defaultApplicationId;
|
|
1320
|
+
}
|
|
1321
|
+
defaultApplicationId;
|
|
1322
|
+
async list(applicationIdOrBucketRef, bucketRefOrQuery, legacyQuery) {
|
|
1323
|
+
const explicitApplication = typeof bucketRefOrQuery === "string";
|
|
1324
|
+
const applicationId = resolveStorageApplicationId(
|
|
1325
|
+
this.defaultApplicationId,
|
|
1326
|
+
explicitApplication ? applicationIdOrBucketRef : void 0
|
|
1327
|
+
);
|
|
1328
|
+
const bucketRef = explicitApplication ? bucketRefOrQuery : applicationIdOrBucketRef;
|
|
1329
|
+
const query = explicitApplication ? legacyQuery : bucketRefOrQuery;
|
|
1330
|
+
return this.httpClient.get(
|
|
1331
|
+
`/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/trash`,
|
|
1332
|
+
{ query }
|
|
1333
|
+
);
|
|
1334
|
+
}
|
|
1335
|
+
async restore(applicationIdOrBucketRef, bucketRefOrObjectId, objectIdOrOptions, legacyOptions) {
|
|
1336
|
+
const explicitApplication = typeof objectIdOrOptions === "string";
|
|
1337
|
+
const applicationId = resolveStorageApplicationId(
|
|
1338
|
+
this.defaultApplicationId,
|
|
1339
|
+
explicitApplication ? applicationIdOrBucketRef : void 0
|
|
1340
|
+
);
|
|
1341
|
+
const bucketRef = explicitApplication ? bucketRefOrObjectId : applicationIdOrBucketRef;
|
|
1342
|
+
const objectId = explicitApplication ? objectIdOrOptions : bucketRefOrObjectId;
|
|
1343
|
+
const options = explicitApplication ? legacyOptions : objectIdOrOptions;
|
|
1344
|
+
return this.httpClient.post(
|
|
1345
|
+
`/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/trash/${objectId}/restore`,
|
|
1346
|
+
void 0,
|
|
1347
|
+
{ query: { environment: options?.environment } }
|
|
1348
|
+
);
|
|
1349
|
+
}
|
|
1350
|
+
async purge(applicationIdOrBucketRef, bucketRefOrObjectId, objectIdOrOptions, legacyOptions) {
|
|
1351
|
+
const explicitApplication = typeof objectIdOrOptions === "string";
|
|
1352
|
+
const applicationId = resolveStorageApplicationId(
|
|
1353
|
+
this.defaultApplicationId,
|
|
1354
|
+
explicitApplication ? applicationIdOrBucketRef : void 0
|
|
1355
|
+
);
|
|
1356
|
+
const bucketRef = explicitApplication ? bucketRefOrObjectId : applicationIdOrBucketRef;
|
|
1357
|
+
const objectId = explicitApplication ? objectIdOrOptions : bucketRefOrObjectId;
|
|
1358
|
+
const options = explicitApplication ? legacyOptions : objectIdOrOptions;
|
|
1359
|
+
return this.httpClient.delete(
|
|
1360
|
+
`/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/trash/${objectId}`,
|
|
1361
|
+
{ query: { environment: options?.environment } }
|
|
1362
|
+
);
|
|
1363
|
+
}
|
|
1364
|
+
async empty(applicationIdOrBucketRef, bucketRefOrOptions, legacyOptions) {
|
|
1365
|
+
const explicitApplication = typeof bucketRefOrOptions === "string";
|
|
1366
|
+
const applicationId = resolveStorageApplicationId(
|
|
1367
|
+
this.defaultApplicationId,
|
|
1368
|
+
explicitApplication ? applicationIdOrBucketRef : void 0
|
|
1369
|
+
);
|
|
1370
|
+
const bucketRef = explicitApplication ? bucketRefOrOptions : applicationIdOrBucketRef;
|
|
1371
|
+
const options = explicitApplication ? legacyOptions : bucketRefOrOptions;
|
|
1372
|
+
return this.httpClient.delete(
|
|
1373
|
+
`/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/trash`,
|
|
1374
|
+
{ query: { environment: options?.environment } }
|
|
1317
1375
|
);
|
|
1318
1376
|
}
|
|
1319
1377
|
};
|
|
1320
1378
|
|
|
1321
1379
|
// src/resources/storage-upload-sessions.ts
|
|
1322
1380
|
var StorageUploadSessionsResource = class extends BaseResource {
|
|
1323
|
-
constructor(httpClient, transport = tusUploadTransport) {
|
|
1381
|
+
constructor(httpClient, transport = tusUploadTransport, defaultApplicationId) {
|
|
1324
1382
|
super(httpClient);
|
|
1325
1383
|
this.transport = transport;
|
|
1384
|
+
this.defaultApplicationId = defaultApplicationId;
|
|
1326
1385
|
}
|
|
1327
1386
|
transport;
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
return this.httpClient.get(
|
|
1338
|
-
|
|
1339
|
-
|
|
1387
|
+
defaultApplicationId;
|
|
1388
|
+
async list(applicationIdOrBucketRef, bucketRefOrQuery, legacyQuery) {
|
|
1389
|
+
const explicitApplication = typeof bucketRefOrQuery === "string";
|
|
1390
|
+
const applicationId = resolveStorageApplicationId(
|
|
1391
|
+
this.defaultApplicationId,
|
|
1392
|
+
explicitApplication ? applicationIdOrBucketRef : void 0
|
|
1393
|
+
);
|
|
1394
|
+
const bucketRef = explicitApplication ? bucketRefOrQuery : applicationIdOrBucketRef;
|
|
1395
|
+
const query = explicitApplication ? legacyQuery : bucketRefOrQuery;
|
|
1396
|
+
return this.httpClient.get(
|
|
1397
|
+
`/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/uploads`,
|
|
1398
|
+
{ query }
|
|
1399
|
+
);
|
|
1340
1400
|
}
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1401
|
+
async create(applicationIdOrBucketRef, bucketRefOrData, dataOrOptions, legacyOptions) {
|
|
1402
|
+
const explicitApplication = typeof bucketRefOrData === "string";
|
|
1403
|
+
const applicationId = resolveStorageApplicationId(
|
|
1404
|
+
this.defaultApplicationId,
|
|
1405
|
+
explicitApplication ? applicationIdOrBucketRef : void 0
|
|
1406
|
+
);
|
|
1407
|
+
const bucketRef = explicitApplication ? bucketRefOrData : applicationIdOrBucketRef;
|
|
1408
|
+
const data = explicitApplication ? dataOrOptions : bucketRefOrData;
|
|
1409
|
+
const options = explicitApplication ? legacyOptions : dataOrOptions;
|
|
1410
|
+
return this.httpClient.post(
|
|
1411
|
+
`/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/uploads`,
|
|
1412
|
+
data,
|
|
1413
|
+
{ query: { environment: options?.environment } }
|
|
1414
|
+
);
|
|
1354
1415
|
}
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1416
|
+
async get(applicationIdOrBucketRef, bucketRefOrSessionId, sessionIdOrOptions, legacyOptions) {
|
|
1417
|
+
const explicitApplication = typeof sessionIdOrOptions === "string";
|
|
1418
|
+
const applicationId = resolveStorageApplicationId(
|
|
1419
|
+
this.defaultApplicationId,
|
|
1420
|
+
explicitApplication ? applicationIdOrBucketRef : void 0
|
|
1421
|
+
);
|
|
1422
|
+
const bucketRef = explicitApplication ? bucketRefOrSessionId : applicationIdOrBucketRef;
|
|
1423
|
+
const sessionId = explicitApplication ? sessionIdOrOptions : bucketRefOrSessionId;
|
|
1424
|
+
const options = explicitApplication ? legacyOptions : sessionIdOrOptions;
|
|
1425
|
+
return this.httpClient.get(
|
|
1426
|
+
`/applications/${applicationId}/storage/buckets/${encodeStorageBucketReference(bucketRef)}/uploads/${sessionId}`,
|
|
1427
|
+
{ query: { environment: options?.environment } }
|
|
1428
|
+
);
|
|
1366
1429
|
}
|
|
1367
1430
|
/**
|
|
1368
1431
|
* Upload bytes directly to a pre-existing signed upload URL — for example, a
|
|
@@ -1396,19 +1459,24 @@ var StorageUploadSessionsResource = class extends BaseResource {
|
|
|
1396
1459
|
// src/resources/application-storage.ts
|
|
1397
1460
|
var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
1398
1461
|
var ApplicationStorageResource = class {
|
|
1462
|
+
constructor(httpClient, transport = tusUploadTransport, defaultApplicationId) {
|
|
1463
|
+
this.defaultApplicationId = defaultApplicationId;
|
|
1464
|
+
this.transport = transport;
|
|
1465
|
+
this.buckets = new StorageBucketsResource(httpClient, defaultApplicationId);
|
|
1466
|
+
this.objects = new StorageObjectsResource(httpClient, defaultApplicationId);
|
|
1467
|
+
this.uploadSessions = new StorageUploadSessionsResource(httpClient, transport, defaultApplicationId);
|
|
1468
|
+
this.trash = new StorageTrashResource(httpClient, defaultApplicationId);
|
|
1469
|
+
}
|
|
1470
|
+
defaultApplicationId;
|
|
1399
1471
|
/** Create, list, get, and delete storage buckets. */
|
|
1400
1472
|
buckets;
|
|
1401
1473
|
/** List, get, delete objects, and generate access URLs. */
|
|
1402
1474
|
objects;
|
|
1403
1475
|
/** Low-level upload sessions and direct-to-URL byte uploads. */
|
|
1404
1476
|
uploadSessions;
|
|
1477
|
+
/** Lists, restores, and permanently purges soft-deleted objects. */
|
|
1478
|
+
trash;
|
|
1405
1479
|
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
1480
|
/**
|
|
1413
1481
|
* Upload a file to a storage bucket. Handles the full flow: computes the
|
|
1414
1482
|
* required SHA-256 checksum, creates an upload session, uploads the bytes with
|
|
@@ -1426,14 +1494,18 @@ var ApplicationStorageResource = class {
|
|
|
1426
1494
|
*
|
|
1427
1495
|
* @example
|
|
1428
1496
|
* ```ts
|
|
1429
|
-
* const { session, url, object } = await client.
|
|
1430
|
-
*
|
|
1497
|
+
* const { session, url, object } = await client.storage.upload({
|
|
1498
|
+
* bucket: 'reports', key: 'q1.pdf', path: './q1.pdf',
|
|
1431
1499
|
* waitForCompletion: true,
|
|
1432
1500
|
* });
|
|
1433
1501
|
* console.log(object?.contentLength, 'bytes available at', url);
|
|
1434
1502
|
* ```
|
|
1435
1503
|
*/
|
|
1436
1504
|
async upload(input) {
|
|
1505
|
+
const applicationId = resolveStorageApplicationId(this.defaultApplicationId, input.applicationId);
|
|
1506
|
+
const bucketRef = resolveStorageBucketReference(input);
|
|
1507
|
+
const completionOptions = typeof input.waitForCompletion === "object" ? input.waitForCompletion : void 0;
|
|
1508
|
+
const environment = input.environment ?? completionOptions?.environment;
|
|
1437
1509
|
const resolved = await resolveUploadSource({
|
|
1438
1510
|
key: input.key,
|
|
1439
1511
|
data: input.data,
|
|
@@ -1445,14 +1517,19 @@ var ApplicationStorageResource = class {
|
|
|
1445
1517
|
checksumSha1: input.checksumSha1,
|
|
1446
1518
|
checksumMd5: input.checksumMd5
|
|
1447
1519
|
});
|
|
1448
|
-
const { session, upload } = await this.uploadSessions.create(
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1520
|
+
const { session, upload } = await this.uploadSessions.create(
|
|
1521
|
+
applicationId,
|
|
1522
|
+
bucketRef,
|
|
1523
|
+
{
|
|
1524
|
+
key: input.key,
|
|
1525
|
+
contentLength: resolved.size,
|
|
1526
|
+
checksumSha256: resolved.checksums.sha256,
|
|
1527
|
+
contentType: resolved.contentType,
|
|
1528
|
+
checksumSha1: resolved.checksums.sha1,
|
|
1529
|
+
checksumMd5: resolved.checksums.md5
|
|
1530
|
+
},
|
|
1531
|
+
{ environment }
|
|
1532
|
+
);
|
|
1456
1533
|
await runResolvedUpload(
|
|
1457
1534
|
this.transport,
|
|
1458
1535
|
upload.url,
|
|
@@ -1469,9 +1546,12 @@ var ApplicationStorageResource = class {
|
|
|
1469
1546
|
{ "Tus-Resumable": "1.0.0", ...upload.headers }
|
|
1470
1547
|
).catch(toUploadError);
|
|
1471
1548
|
if (input.waitForCompletion) {
|
|
1472
|
-
const options =
|
|
1473
|
-
const completed = await this.waitForCompletion(
|
|
1474
|
-
|
|
1549
|
+
const options = completionOptions ?? {};
|
|
1550
|
+
const completed = await this.waitForCompletion(applicationId, bucketRef, session.id, {
|
|
1551
|
+
...options,
|
|
1552
|
+
environment
|
|
1553
|
+
});
|
|
1554
|
+
const object = await this.objects.getByKey(applicationId, bucketRef, input.key, { environment }) ?? void 0;
|
|
1475
1555
|
return { session: completed, url: upload.publicObjectUrl, object };
|
|
1476
1556
|
}
|
|
1477
1557
|
return { session, url: upload.publicObjectUrl };
|
|
@@ -1487,8 +1567,8 @@ var ApplicationStorageResource = class {
|
|
|
1487
1567
|
*
|
|
1488
1568
|
* @example
|
|
1489
1569
|
* ```ts
|
|
1490
|
-
* const results = await client.
|
|
1491
|
-
* files.map((f) => ({
|
|
1570
|
+
* const results = await client.storage.uploadBatch(
|
|
1571
|
+
* files.map((f) => ({ bucket: 'uploads', key: f.name, data: f })),
|
|
1492
1572
|
* { concurrency: 6, onProgress: (done, total) => console.log(`${done}/${total}`) },
|
|
1493
1573
|
* );
|
|
1494
1574
|
* const failed = results.filter((r) => r.error);
|
|
@@ -1515,22 +1595,22 @@ var ApplicationStorageResource = class {
|
|
|
1515
1595
|
await Promise.all(Array.from({ length: Math.min(concurrency, inputs.length) }, () => worker()));
|
|
1516
1596
|
return results;
|
|
1517
1597
|
}
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
*/
|
|
1528
|
-
async waitForCompletion(applicationId, bucketId, sessionId, options) {
|
|
1598
|
+
async waitForCompletion(applicationIdOrBucketRef, bucketRefOrSessionId, sessionIdOrOptions, legacyOptions) {
|
|
1599
|
+
const explicitApplication = typeof sessionIdOrOptions === "string";
|
|
1600
|
+
const applicationId = resolveStorageApplicationId(
|
|
1601
|
+
this.defaultApplicationId,
|
|
1602
|
+
explicitApplication ? applicationIdOrBucketRef : void 0
|
|
1603
|
+
);
|
|
1604
|
+
const bucketRef = explicitApplication ? bucketRefOrSessionId : applicationIdOrBucketRef;
|
|
1605
|
+
const sessionId = explicitApplication ? sessionIdOrOptions : bucketRefOrSessionId;
|
|
1606
|
+
const options = explicitApplication ? legacyOptions : sessionIdOrOptions;
|
|
1529
1607
|
const timeoutMs = options?.timeoutMs ?? 6e4;
|
|
1530
1608
|
const pollIntervalMs = options?.pollIntervalMs ?? 1e3;
|
|
1531
1609
|
const deadline = Date.now() + timeoutMs;
|
|
1532
1610
|
for (; ; ) {
|
|
1533
|
-
const session = await this.uploadSessions.get(applicationId,
|
|
1611
|
+
const session = await this.uploadSessions.get(applicationId, bucketRef, sessionId, {
|
|
1612
|
+
environment: options?.environment
|
|
1613
|
+
});
|
|
1534
1614
|
if (session.state === "completed") return session;
|
|
1535
1615
|
if (session.state === "failed" || session.state === "expired") {
|
|
1536
1616
|
throw new UploadError(`Upload session ${session.state}.`);
|
|
@@ -1564,15 +1644,14 @@ var ApplicationsResource = class extends BaseResource {
|
|
|
1564
1644
|
* @example
|
|
1565
1645
|
* ```ts
|
|
1566
1646
|
* // Upload a file
|
|
1567
|
-
* const { url } = await client.
|
|
1568
|
-
*
|
|
1569
|
-
* bucketId: 'bucket-id',
|
|
1647
|
+
* const { url } = await client.storage.upload({
|
|
1648
|
+
* bucket: 'assets',
|
|
1570
1649
|
* key: 'images/logo.png',
|
|
1571
1650
|
* data: fileData,
|
|
1572
1651
|
* });
|
|
1573
1652
|
*
|
|
1574
1653
|
* // List objects in a bucket
|
|
1575
|
-
* const { items } = await client.
|
|
1654
|
+
* const { items } = await client.storage.objects.list('assets');
|
|
1576
1655
|
* ```
|
|
1577
1656
|
*/
|
|
1578
1657
|
storage;
|
|
@@ -1585,10 +1664,10 @@ var ApplicationsResource = class extends BaseResource {
|
|
|
1585
1664
|
* ```
|
|
1586
1665
|
*/
|
|
1587
1666
|
requests;
|
|
1588
|
-
constructor(
|
|
1589
|
-
super(
|
|
1667
|
+
constructor(httpClient, defaultApplicationId) {
|
|
1668
|
+
super(httpClient);
|
|
1590
1669
|
this.envVars = new ApplicationEnvVarsResource(this.httpClient);
|
|
1591
|
-
this.storage = new ApplicationStorageResource(this.httpClient);
|
|
1670
|
+
this.storage = new ApplicationStorageResource(this.httpClient, void 0, defaultApplicationId);
|
|
1592
1671
|
this.requests = new ApplicationRequestsResource(this.httpClient);
|
|
1593
1672
|
}
|
|
1594
1673
|
/**
|
|
@@ -2298,6 +2377,15 @@ var GigadriveClient = class {
|
|
|
2298
2377
|
organizations;
|
|
2299
2378
|
/** Application management (list, environment variables, storage). */
|
|
2300
2379
|
applications;
|
|
2380
|
+
/**
|
|
2381
|
+
* Context-bound file storage operations.
|
|
2382
|
+
*
|
|
2383
|
+
* Deployed workloads receive their application context through
|
|
2384
|
+
* `GIGADRIVE_APPLICATION_ID`; management clients can set
|
|
2385
|
+
* {@link GigadriveClientConfig.applicationId}. This is the same resource as
|
|
2386
|
+
* {@link applications}.storage.
|
|
2387
|
+
*/
|
|
2388
|
+
storage;
|
|
2301
2389
|
/** Deployment lifecycle (create, upload, status, logs). */
|
|
2302
2390
|
deployments;
|
|
2303
2391
|
/** AI Gateway — OpenAI-compatible chat completions and model listing. */
|
|
@@ -2310,12 +2398,14 @@ var GigadriveClient = class {
|
|
|
2310
2398
|
imageOptimization;
|
|
2311
2399
|
constructor(config = {}) {
|
|
2312
2400
|
const baseUrl = config.baseUrl ?? readEnv("GIGADRIVE_API_BASE_URL") ?? DEFAULT_BASE_URL2;
|
|
2401
|
+
const applicationId = config.applicationId ?? readEnv("GIGADRIVE_APPLICATION_ID");
|
|
2313
2402
|
const fetchFn = config.fetch ?? globalThis.fetch.bind(globalThis);
|
|
2314
2403
|
const credentialProvider = resolveCredentialProvider({ ...config, baseUrl, fetch: fetchFn });
|
|
2315
2404
|
const tokenManager = new TokenManager(credentialProvider);
|
|
2316
2405
|
const httpClient = new HttpClient(baseUrl, tokenManager, fetchFn);
|
|
2317
2406
|
this.organizations = new OrganizationsResource(httpClient);
|
|
2318
|
-
this.applications = new ApplicationsResource(httpClient);
|
|
2407
|
+
this.applications = new ApplicationsResource(httpClient, applicationId);
|
|
2408
|
+
this.storage = this.applications.storage;
|
|
2319
2409
|
this.deployments = new DeploymentsResource(httpClient);
|
|
2320
2410
|
this.aiGateway = new AiGatewayResource(httpClient);
|
|
2321
2411
|
this.apiKeys = new ApiKeysResource(httpClient);
|
|
@@ -2349,6 +2439,7 @@ export {
|
|
|
2349
2439
|
ApplicationStorageResource,
|
|
2350
2440
|
ApplicationsResource,
|
|
2351
2441
|
AuthenticationError,
|
|
2442
|
+
ConfigurationError,
|
|
2352
2443
|
DeploymentsResource,
|
|
2353
2444
|
GigadriveClient,
|
|
2354
2445
|
GigadriveError,
|
|
@@ -2361,6 +2452,7 @@ export {
|
|
|
2361
2452
|
StickySessionsResource,
|
|
2362
2453
|
StorageBucketsResource,
|
|
2363
2454
|
StorageObjectsResource,
|
|
2455
|
+
StorageTrashResource,
|
|
2364
2456
|
StorageUploadSessionsResource,
|
|
2365
2457
|
UploadError,
|
|
2366
2458
|
UploadSessionExpiredError,
|