@xylex-group/athena 2.4.1 → 2.7.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.
Files changed (49) hide show
  1. package/README.md +52 -1
  2. package/bin/athena-js.js +0 -0
  3. package/dist/browser.cjs +2642 -56
  4. package/dist/browser.cjs.map +1 -1
  5. package/dist/browser.d.cts +8 -7
  6. package/dist/browser.d.ts +8 -7
  7. package/dist/browser.js +2635 -57
  8. package/dist/browser.js.map +1 -1
  9. package/dist/cli/index.cjs +1648 -239
  10. package/dist/cli/index.cjs.map +1 -1
  11. package/dist/cli/index.d.cts +3 -3
  12. package/dist/cli/index.d.ts +3 -3
  13. package/dist/cli/index.js +1648 -239
  14. package/dist/cli/index.js.map +1 -1
  15. package/dist/cookies.cjs +10 -3
  16. package/dist/cookies.cjs.map +1 -1
  17. package/dist/cookies.d.cts +1 -174
  18. package/dist/cookies.d.ts +1 -174
  19. package/dist/cookies.js +10 -3
  20. package/dist/cookies.js.map +1 -1
  21. package/dist/index-CVcQCGyG.d.cts +174 -0
  22. package/dist/index-CVcQCGyG.d.ts +174 -0
  23. package/dist/index.cjs +2642 -56
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +8 -7
  26. package/dist/index.d.ts +8 -7
  27. package/dist/index.js +2635 -57
  28. package/dist/index.js.map +1 -1
  29. package/dist/model-form-AKYrgede.d.ts +2772 -0
  30. package/dist/model-form-ehfqLuG7.d.cts +2772 -0
  31. package/dist/{pipeline-CR4V15jF.d.ts → pipeline-BUsR9XlO.d.ts} +1 -1
  32. package/dist/{pipeline-DZeExYMA.d.cts → pipeline-BfCWSRYl.d.cts} +1 -1
  33. package/dist/react-email-BQzmXBDE.d.cts +304 -0
  34. package/dist/react-email-BrVRp80B.d.ts +304 -0
  35. package/dist/react.cjs +178 -71
  36. package/dist/react.cjs.map +1 -1
  37. package/dist/react.d.cts +22 -5
  38. package/dist/react.d.ts +22 -5
  39. package/dist/react.js +92 -5
  40. package/dist/react.js.map +1 -1
  41. package/dist/{types-D1JvL21V.d.cts → types-BSIsyss1.d.cts} +1 -1
  42. package/dist/{types-09Q4D86N.d.cts → types-BsyRW49r.d.cts} +3 -3
  43. package/dist/{types-09Q4D86N.d.ts → types-BsyRW49r.d.ts} +3 -3
  44. package/dist/{types-DU3gNdFv.d.ts → types-t_TVqnmp.d.ts} +1 -1
  45. package/package.json +22 -21
  46. package/dist/model-form-4LPnOPAF.d.cts +0 -1383
  47. package/dist/model-form-CO4-LmNC.d.ts +0 -1383
  48. package/dist/react-email-6mOyxBo4.d.cts +0 -657
  49. package/dist/react-email-Buhcpglm.d.ts +0 -657
package/dist/cli/index.js CHANGED
@@ -1495,16 +1495,23 @@ var getSessionCookie = (request, config) => {
1495
1495
  const { cookieName = "session_token", cookiePrefix = "athena-auth" } = {};
1496
1496
  const parsedCookie = parseCookies(cookies);
1497
1497
  const getCookie = (name) => parsedCookie.get(name) || parsedCookie.get(`${SECURE_COOKIE_PREFIX}${name}`);
1498
- const sessionToken = getCookie(`${cookiePrefix}.${cookieName}`) || getCookie(`${cookiePrefix}-${cookieName}`);
1499
- if (sessionToken) {
1500
- return sessionToken;
1498
+ const candidateCookieNames = Array.from(/* @__PURE__ */ new Set([
1499
+ cookieName,
1500
+ cookieName.replace(/_/g, "-"),
1501
+ cookieName.replace(/-/g, "_")
1502
+ ])).filter(Boolean);
1503
+ for (const candidateName of candidateCookieNames) {
1504
+ const sessionToken = getCookie(`${cookiePrefix}.${candidateName}`) || getCookie(`${cookiePrefix}-${candidateName}`);
1505
+ if (sessionToken) {
1506
+ return sessionToken;
1507
+ }
1501
1508
  }
1502
1509
  return null;
1503
1510
  };
1504
1511
 
1505
1512
  // package.json
1506
1513
  var package_default = {
1507
- version: "2.4.1"
1514
+ version: "2.7.0"
1508
1515
  };
1509
1516
 
1510
1517
  // src/sdk-version.ts
@@ -3243,240 +3250,1634 @@ function createAuthClient(config = {}) {
3243
3250
  delete: (input, options) => postGeneric("/admin/email-template/delete", input, options)
3244
3251
  }
3245
3252
  },
3246
- emailTemplate: {
3247
- get: (input, options) => getWithQuery("/admin/email-template/get", input, options),
3248
- create: async (input, options) => postGeneric(
3249
- "/admin/email-template/create",
3250
- await resolveAdminEmailTemplatePayload("/admin/email-template/create", input),
3251
- options
3252
- ),
3253
- delete: (input, options) => postGeneric("/admin/email-template/delete", input, options),
3254
- list: (input, options) => getWithQuery("/admin/email-template/list", input, options),
3255
- update: async (input, options) => postGeneric(
3256
- "/admin/email-template/update",
3257
- await resolveAdminEmailTemplatePayload("/admin/email-template/update", input),
3258
- options
3259
- )
3253
+ emailTemplate: {
3254
+ get: (input, options) => getWithQuery("/admin/email-template/get", input, options),
3255
+ create: async (input, options) => postGeneric(
3256
+ "/admin/email-template/create",
3257
+ await resolveAdminEmailTemplatePayload("/admin/email-template/create", input),
3258
+ options
3259
+ ),
3260
+ delete: (input, options) => postGeneric("/admin/email-template/delete", input, options),
3261
+ list: (input, options) => getWithQuery("/admin/email-template/list", input, options),
3262
+ update: async (input, options) => postGeneric(
3263
+ "/admin/email-template/update",
3264
+ await resolveAdminEmailTemplatePayload("/admin/email-template/update", input),
3265
+ options
3266
+ )
3267
+ }
3268
+ },
3269
+ apiKey: {
3270
+ create: (input, options) => postGeneric("/api-key/create", input, options),
3271
+ get: (input, options) => getWithQuery("/api-key/get", input, options),
3272
+ update: (input, options) => postGeneric("/api-key/update", input, options),
3273
+ delete: (input, options) => postGeneric("/api-key/delete", input, options),
3274
+ list: (input, options) => getWithQuery("/api-key/list", input, options),
3275
+ verify: (input, options) => postGeneric("/api-key/verify", input, options),
3276
+ deleteAllExpired: (input, options) => executePostWithOptionalInput(
3277
+ resolvedConfig,
3278
+ { endpoint: "/api-key/delete-all-expired-api-keys", method: "POST" },
3279
+ input,
3280
+ options
3281
+ )
3282
+ },
3283
+ signIn: {
3284
+ email: (input, options) => postGeneric("/sign-in/email", input, options),
3285
+ username: (input, options) => postGeneric("/sign-in/username", input, options),
3286
+ social: (input, options) => postGeneric("/sign-in/social", input, options)
3287
+ },
3288
+ signUp: {
3289
+ email: (input, options) => postGeneric("/sign-up/email", input, options)
3290
+ },
3291
+ organization,
3292
+ callback: {
3293
+ provider: (input, options) => {
3294
+ const { payload, fetchOptions } = extractFetchOptions(input);
3295
+ const parsed = payload;
3296
+ const provider = String(parsed?.provider ?? "").trim();
3297
+ if (!provider) {
3298
+ throw new Error("callback.provider requires a non-empty provider value");
3299
+ }
3300
+ const code = String(parsed?.code ?? "").trim();
3301
+ const state = String(parsed?.state ?? "").trim();
3302
+ if (!code || !state) {
3303
+ throw new Error("callback.provider requires non-empty code and state values");
3304
+ }
3305
+ const endpoint = `/callback/${encodeURIComponent(provider)}`;
3306
+ return request({
3307
+ endpoint,
3308
+ method: "GET",
3309
+ query: {
3310
+ code,
3311
+ state
3312
+ },
3313
+ fetchOptions
3314
+ }, options);
3315
+ }
3316
+ }
3317
+ };
3318
+ return {
3319
+ baseUrl: normalizedBaseUrl,
3320
+ request,
3321
+ signIn: {
3322
+ email: (input, options) => executePostWithCompatibleInput(
3323
+ resolvedConfig,
3324
+ { endpoint: "/sign-in/email", method: "POST" },
3325
+ input,
3326
+ options
3327
+ ),
3328
+ username: (input, options) => executePostWithCompatibleInput(
3329
+ resolvedConfig,
3330
+ { endpoint: "/sign-in/username", method: "POST" },
3331
+ input,
3332
+ options
3333
+ ),
3334
+ social: (input, options) => executePostWithCompatibleInput(
3335
+ resolvedConfig,
3336
+ { endpoint: "/sign-in/social", method: "POST" },
3337
+ input,
3338
+ options
3339
+ )
3340
+ },
3341
+ signUp: {
3342
+ email: (input, options) => executePostWithCompatibleInput(
3343
+ resolvedConfig,
3344
+ { endpoint: "/sign-up/email", method: "POST" },
3345
+ input,
3346
+ options
3347
+ )
3348
+ },
3349
+ signOut,
3350
+ logout: signOut,
3351
+ getSession: (input, options) => executeGetWithCompatibleInput(
3352
+ resolvedConfig,
3353
+ { endpoint: "/get-session", method: "GET" },
3354
+ input,
3355
+ options
3356
+ ),
3357
+ listSessions: (input, options) => executeGetWithCompatibleInput(
3358
+ resolvedConfig,
3359
+ { endpoint: "/list-sessions", method: "GET" },
3360
+ input,
3361
+ options
3362
+ ),
3363
+ revokeSession,
3364
+ clearSession: revokeSession,
3365
+ revokeSessions,
3366
+ clearSessions: revokeSessions,
3367
+ revokeOtherSessions,
3368
+ clearOtherSessions: revokeOtherSessions,
3369
+ forgetPassword: (input, options) => executePostWithCompatibleInput(
3370
+ resolvedConfig,
3371
+ { endpoint: "/forget-password", method: "POST" },
3372
+ input,
3373
+ options
3374
+ ),
3375
+ resetPassword: (input, options) => executePostWithCompatibleInput(
3376
+ resolvedConfig,
3377
+ { endpoint: "/reset-password", method: "POST" },
3378
+ input,
3379
+ options
3380
+ ),
3381
+ resolveResetPasswordToken,
3382
+ verifyEmail: (input, options) => {
3383
+ const { payload, fetchOptions } = extractFetchOptions(input);
3384
+ const mergedOptions = mergeCallOptions(fetchOptions, options);
3385
+ const query = payload;
3386
+ return callAuthEndpoint(
3387
+ resolvedConfig,
3388
+ { endpoint: "/verify-email", method: "GET" },
3389
+ void 0,
3390
+ query ? {
3391
+ token: query.token,
3392
+ callbackURL: query.callbackURL
3393
+ } : void 0,
3394
+ mergedOptions
3395
+ );
3396
+ },
3397
+ sendVerificationEmail: (input, options) => executePostWithCompatibleInput(
3398
+ resolvedConfig,
3399
+ { endpoint: "/send-verification-email", method: "POST" },
3400
+ input,
3401
+ options
3402
+ ),
3403
+ changeEmail: (input, options) => executePostWithCompatibleInput(
3404
+ resolvedConfig,
3405
+ { endpoint: "/change-email", method: "POST" },
3406
+ input,
3407
+ options
3408
+ ),
3409
+ changePassword: (input, options) => executePostWithCompatibleInput(
3410
+ resolvedConfig,
3411
+ { endpoint: "/change-password", method: "POST" },
3412
+ input,
3413
+ options
3414
+ ),
3415
+ updateUser: (input, options) => executePostWithCompatibleInput(
3416
+ resolvedConfig,
3417
+ { endpoint: "/update-user", method: "POST" },
3418
+ input,
3419
+ options
3420
+ ),
3421
+ deleteUser,
3422
+ deleteUserCallback,
3423
+ linkSocial: (input, options) => executePostWithCompatibleInput(
3424
+ resolvedConfig,
3425
+ { endpoint: "/link-social", method: "POST" },
3426
+ input,
3427
+ options
3428
+ ),
3429
+ listAccounts: (input, options) => executeGetWithCompatibleInput(
3430
+ resolvedConfig,
3431
+ { endpoint: "/list-accounts", method: "GET" },
3432
+ input,
3433
+ options
3434
+ ),
3435
+ unlinkAccount: (input, options) => executePostWithCompatibleInput(
3436
+ resolvedConfig,
3437
+ { endpoint: "/unlink-account", method: "POST" },
3438
+ input,
3439
+ options
3440
+ ),
3441
+ refreshToken: (input, options) => executePostWithCompatibleInput(
3442
+ resolvedConfig,
3443
+ { endpoint: "/refresh-token", method: "POST" },
3444
+ input,
3445
+ options
3446
+ ),
3447
+ getAccessToken: (input, options) => executePostWithCompatibleInput(
3448
+ resolvedConfig,
3449
+ { endpoint: "/get-access-token", method: "POST" },
3450
+ input,
3451
+ options
3452
+ ),
3453
+ organization,
3454
+ auth
3455
+ };
3456
+ }
3457
+
3458
+ // src/db/module.ts
3459
+ function createDbModule(input) {
3460
+ const db = {
3461
+ from(table, options) {
3462
+ return input.from(table, options);
3463
+ },
3464
+ select(table, columns, options) {
3465
+ return input.from(table).select(columns, options);
3466
+ },
3467
+ insert(table, values, options) {
3468
+ return Array.isArray(values) ? input.from(table).insert(values, options) : input.from(table).insert(values, options);
3469
+ },
3470
+ upsert(table, values, options) {
3471
+ return Array.isArray(values) ? input.from(table).upsert(values, options) : input.from(table).upsert(values, options);
3472
+ },
3473
+ update(table, values, options) {
3474
+ return input.from(table).update(values, options);
3475
+ },
3476
+ delete(table, options) {
3477
+ return input.from(table).delete(options);
3478
+ },
3479
+ rpc(fn, args, options) {
3480
+ return input.rpc(fn, args, options);
3481
+ },
3482
+ query(query, options) {
3483
+ return input.query(query, options);
3484
+ }
3485
+ };
3486
+ return db;
3487
+ }
3488
+
3489
+ // src/storage/file.ts
3490
+ function createStorageFileModule(base, config = {}) {
3491
+ const upload = async (input, options) => {
3492
+ const sources = normalizeUploadSources(input);
3493
+ validateUploadConstraints(sources, input);
3494
+ const uploadRequests = sources.map((source, index) => {
3495
+ const storageKey = resolveUploadStorageKey(input, source, index, options, config);
3496
+ return {
3497
+ source,
3498
+ uploadRequest: {
3499
+ s3_id: input.s3_id,
3500
+ bucket: input.bucket,
3501
+ storage_key: storageKey,
3502
+ name: input.name ?? source.fileName,
3503
+ original_name: input.original_name ?? source.fileName,
3504
+ resource_id: input.resource_id ?? input.resourceId,
3505
+ mime_type: input.mime_type ?? source.contentType,
3506
+ content_type: input.content_type ?? source.contentType,
3507
+ size_bytes: source.sizeBytes,
3508
+ public: input.public,
3509
+ metadata: input.metadata
3510
+ }
3511
+ };
3512
+ });
3513
+ input.onProgress?.(createProgressSnapshot("preparing", sources, 0, 0, 0));
3514
+ const uploadUrls = uploadRequests.length === 1 ? [await base.createStorageUploadUrl(uploadRequests[0].uploadRequest, options)] : (await base.createStorageUploadUrls({ files: uploadRequests.map((request) => request.uploadRequest) }, options)).files;
3515
+ const aggregateLoaded = new Array(uploadRequests.length).fill(0);
3516
+ const uploaded = [];
3517
+ for (let index = 0; index < uploadRequests.length; index += 1) {
3518
+ const request = uploadRequests[index];
3519
+ const uploadUrl = uploadUrls[index];
3520
+ const response = await putUploadBody(uploadUrl.upload.url, request.source, input, options, (progress) => {
3521
+ aggregateLoaded[index] = progress.loaded;
3522
+ input.onProgress?.(createProgressSnapshot("uploading", sources, index, progress.loaded, sum(aggregateLoaded)));
3523
+ });
3524
+ uploaded.push({
3525
+ file: uploadUrl.file,
3526
+ upload: uploadUrl.upload,
3527
+ source: request.source.source,
3528
+ fileName: request.source.fileName,
3529
+ storage_key: request.uploadRequest.storage_key,
3530
+ response
3531
+ });
3532
+ aggregateLoaded[index] = request.source.sizeBytes;
3533
+ input.onProgress?.(createProgressSnapshot("complete", sources, index, request.source.sizeBytes, sum(aggregateLoaded)));
3534
+ }
3535
+ return {
3536
+ files: uploaded,
3537
+ count: uploaded.length
3538
+ };
3539
+ };
3540
+ const download = ((input, queryOrOptions, maybeOptions) => {
3541
+ const { fileIds, query, options } = normalizeDownloadArgs(input, queryOrOptions, maybeOptions);
3542
+ const downloads = fileIds.map((fileId) => base.getStorageFileProxy(fileId, query, options));
3543
+ return Array.isArray(input) || isRecord5(input) && Array.isArray(input.fileIds) ? Promise.all(downloads) : downloads[0];
3544
+ });
3545
+ const deleteFile = ((input, options) => {
3546
+ if (Array.isArray(input)) {
3547
+ return Promise.all(input.map((fileId) => base.deleteStorageFile(fileId, options)));
3548
+ }
3549
+ return base.deleteStorageFile(input, options);
3550
+ });
3551
+ return {
3552
+ upload,
3553
+ download,
3554
+ list(input, options) {
3555
+ const prefix = resolveStoragePath(input.prefix ?? "", input, options, config);
3556
+ return base.listStorageFiles(
3557
+ {
3558
+ s3_id: input.s3_id,
3559
+ prefix
3560
+ },
3561
+ options
3562
+ );
3563
+ },
3564
+ delete: deleteFile
3565
+ };
3566
+ }
3567
+ function resolveStoragePath(path, input, options, config = {}) {
3568
+ const context = createPathContext(input, options, config);
3569
+ const prefixPath = input.prefixPath ?? config.prefixPath;
3570
+ const prefix = typeof prefixPath === "function" ? prefixPath(context) : prefixPath;
3571
+ return joinStoragePath(renderStorageTemplate(prefix ?? "", context), renderStorageTemplate(path, context));
3572
+ }
3573
+ function resolveUploadStorageKey(input, source, index, options, config) {
3574
+ const explicitKey = input.storage_key ?? input.storageKey;
3575
+ const keyTemplate = input.storageKeyTemplate;
3576
+ const fallbackName = source.fileName;
3577
+ const context = createPathContext(input, options, config);
3578
+ const key = keyTemplate ? renderStorageTemplate(keyTemplate, {
3579
+ ...context,
3580
+ vars: {
3581
+ ...context.vars,
3582
+ index,
3583
+ fileName: source.fileName,
3584
+ name: source.fileName
3585
+ }
3586
+ }) : explicitKey ?? fallbackName;
3587
+ return resolveStoragePath(key, input, options, config);
3588
+ }
3589
+ function normalizeUploadSources(input) {
3590
+ const files = toArray(input.files);
3591
+ if (files.length === 0) {
3592
+ throw new Error("athena.storage.file.upload requires at least one file");
3593
+ }
3594
+ return files.map((source, index) => {
3595
+ const fileName = input.fileName ?? sourceName(source) ?? `file-${index + 1}`;
3596
+ const sizeBytes = sourceSize(source);
3597
+ const contentType = input.content_type ?? input.mime_type ?? sourceContentType(source);
3598
+ return {
3599
+ source,
3600
+ fileName,
3601
+ sizeBytes,
3602
+ contentType
3603
+ };
3604
+ });
3605
+ }
3606
+ function validateUploadConstraints(sources, input) {
3607
+ const maxFiles = input.maxFiles ?? 1;
3608
+ if (sources.length > maxFiles) {
3609
+ throw new Error(`athena.storage.file.upload accepts at most ${maxFiles} file${maxFiles === 1 ? "" : "s"} for this call`);
3610
+ }
3611
+ const maxFileSizeBytes = input.maxFileSizeBytes ?? (input.maxFileSizeMb === void 0 ? void 0 : Math.floor(input.maxFileSizeMb * 1024 * 1024));
3612
+ if (maxFileSizeBytes !== void 0) {
3613
+ const tooLarge = sources.find((source) => source.sizeBytes > maxFileSizeBytes);
3614
+ if (tooLarge) {
3615
+ throw new Error(`athena.storage.file.upload rejected ${tooLarge.fileName}: file exceeds ${maxFileSizeBytes} bytes`);
3616
+ }
3617
+ }
3618
+ const allowedExtensions = normalizeExtensions(input.allowedExtensions ?? input.extensions);
3619
+ if (allowedExtensions.size > 0) {
3620
+ const invalid = sources.find((source) => !allowedExtensions.has(fileExtension(source.fileName)));
3621
+ if (invalid) {
3622
+ throw new Error(`athena.storage.file.upload rejected ${invalid.fileName}: extension is not allowed`);
3623
+ }
3624
+ }
3625
+ }
3626
+ async function putUploadBody(url, source, input, options, onProgress) {
3627
+ const headers = new Headers(input.uploadHeaders);
3628
+ if (source.contentType && !headers.has("Content-Type")) {
3629
+ headers.set("Content-Type", source.contentType);
3630
+ }
3631
+ if (typeof XMLHttpRequest !== "undefined") {
3632
+ return putUploadBodyWithXhr(url, source, headers, options, onProgress);
3633
+ }
3634
+ onProgress({ loaded: 0 });
3635
+ const response = await fetch(url, {
3636
+ method: "PUT",
3637
+ headers,
3638
+ body: source.source,
3639
+ signal: options?.signal
3640
+ });
3641
+ if (!response.ok) {
3642
+ throw new Error(`athena.storage.file.upload failed with status ${response.status}`);
3643
+ }
3644
+ onProgress({ loaded: source.sizeBytes });
3645
+ return response;
3646
+ }
3647
+ function putUploadBodyWithXhr(url, source, headers, options, onProgress) {
3648
+ const Xhr = XMLHttpRequest;
3649
+ if (Xhr === void 0) {
3650
+ return Promise.reject(new Error("athena.storage.file.upload requires XMLHttpRequest in this runtime"));
3651
+ }
3652
+ return new Promise((resolve3, reject) => {
3653
+ const xhr = new Xhr();
3654
+ const abort = () => xhr.abort();
3655
+ xhr.open("PUT", url);
3656
+ headers.forEach((value, key) => xhr.setRequestHeader(key, value));
3657
+ xhr.upload.onprogress = (event) => {
3658
+ onProgress({ loaded: event.loaded });
3659
+ };
3660
+ xhr.onload = () => {
3661
+ if (options?.signal) {
3662
+ options.signal.removeEventListener("abort", abort);
3663
+ }
3664
+ if (xhr.status < 200 || xhr.status >= 300) {
3665
+ reject(new Error(`athena.storage.file.upload failed with status ${xhr.status}`));
3666
+ return;
3667
+ }
3668
+ onProgress({ loaded: source.sizeBytes });
3669
+ resolve3(new Response(xhr.response, {
3670
+ status: xhr.status,
3671
+ statusText: xhr.statusText,
3672
+ headers: parseXhrHeaders(xhr.getAllResponseHeaders())
3673
+ }));
3674
+ };
3675
+ xhr.onerror = () => {
3676
+ if (options?.signal) {
3677
+ options.signal.removeEventListener("abort", abort);
3678
+ }
3679
+ reject(new Error("athena.storage.file.upload failed with a network error"));
3680
+ };
3681
+ xhr.onabort = () => {
3682
+ if (options?.signal) {
3683
+ options.signal.removeEventListener("abort", abort);
3684
+ }
3685
+ reject(new DOMException("Upload aborted", "AbortError"));
3686
+ };
3687
+ if (options?.signal) {
3688
+ if (options.signal.aborted) {
3689
+ abort();
3690
+ return;
3691
+ }
3692
+ options.signal.addEventListener("abort", abort, { once: true });
3693
+ }
3694
+ xhr.send(source.source);
3695
+ });
3696
+ }
3697
+ function normalizeDownloadArgs(input, queryOrOptions, maybeOptions) {
3698
+ if (typeof input === "string") {
3699
+ return { fileIds: [input], query: queryOrOptions, options: maybeOptions };
3700
+ }
3701
+ if (Array.isArray(input)) {
3702
+ return { fileIds: [...input], query: queryOrOptions, options: maybeOptions };
3703
+ }
3704
+ const downloadInput = input;
3705
+ const { fileId, fileIds, ...query } = downloadInput;
3706
+ return {
3707
+ fileIds: fileIds ? [...fileIds] : fileId ? [fileId] : [],
3708
+ query,
3709
+ options: queryOrOptions
3710
+ };
3711
+ }
3712
+ function createPathContext(input, options, config) {
3713
+ const organizationId = input.organizationId ?? input.organization_id ?? options?.organizationId ?? void 0;
3714
+ const userId = input.userId ?? input.user_id ?? options?.userId ?? void 0;
3715
+ const resourceId = input.resourceId ?? input.resource_id ?? void 0;
3716
+ const vars = {
3717
+ ...config.vars ?? {},
3718
+ ...input.vars ?? {}
3719
+ };
3720
+ if (organizationId !== void 0) {
3721
+ vars.organizationId = organizationId;
3722
+ vars.organization_id = organizationId;
3723
+ }
3724
+ if (userId !== void 0) {
3725
+ vars.userId = userId;
3726
+ vars.user_id = userId;
3727
+ }
3728
+ if (resourceId !== void 0) {
3729
+ vars.resourceId = resourceId;
3730
+ vars.resource_id = resourceId;
3731
+ }
3732
+ return {
3733
+ vars,
3734
+ env: {
3735
+ ...readProcessEnv(),
3736
+ ...config.env ?? {},
3737
+ ...input.env ?? {}
3738
+ },
3739
+ organizationId,
3740
+ organization_id: organizationId,
3741
+ userId,
3742
+ user_id: userId,
3743
+ resourceId,
3744
+ resource_id: resourceId
3745
+ };
3746
+ }
3747
+ function renderStorageTemplate(template, context) {
3748
+ return template.replace(/\$\{([^}]+)\}|\{([^}]+)\}/g, (_match, shellToken, braceToken) => {
3749
+ const token = (shellToken ?? braceToken ?? "").trim();
3750
+ if (!token) return "";
3751
+ const value = resolveTemplateToken(token, context);
3752
+ return value === void 0 || value === null ? "" : String(value);
3753
+ });
3754
+ }
3755
+ function resolveTemplateToken(token, context) {
3756
+ if (token.startsWith("env.")) {
3757
+ return context.env[token.slice(4)];
3758
+ }
3759
+ if (token in context.vars) {
3760
+ return context.vars[token];
3761
+ }
3762
+ return context.env[token];
3763
+ }
3764
+ function joinStoragePath(...parts) {
3765
+ return parts.map((part) => part.trim().replace(/^\/+|\/+$/g, "")).filter(Boolean).join("/");
3766
+ }
3767
+ function toArray(files) {
3768
+ if (isUploadSource(files)) return [files];
3769
+ return Array.from(files);
3770
+ }
3771
+ function isUploadSource(value) {
3772
+ return value instanceof Blob || value instanceof ArrayBuffer || value instanceof Uint8Array;
3773
+ }
3774
+ function sourceName(source) {
3775
+ return isRecord5(source) && typeof source.name === "string" && source.name.trim() ? source.name.trim() : void 0;
3776
+ }
3777
+ function sourceSize(source) {
3778
+ if (source instanceof Blob) return source.size;
3779
+ return source.byteLength;
3780
+ }
3781
+ function sourceContentType(source) {
3782
+ return source instanceof Blob && source.type.trim() ? source.type.trim() : void 0;
3783
+ }
3784
+ function normalizeExtensions(extensions) {
3785
+ return new Set((extensions ?? []).map((extension) => extension.replace(/^\./, "").toLowerCase()).filter(Boolean));
3786
+ }
3787
+ function fileExtension(fileName) {
3788
+ const lastDot = fileName.lastIndexOf(".");
3789
+ return lastDot === -1 ? "" : fileName.slice(lastDot + 1).toLowerCase();
3790
+ }
3791
+ function createProgressSnapshot(phase, sources, fileIndex, loaded, aggregateLoaded) {
3792
+ const total = sources[fileIndex]?.sizeBytes ?? 0;
3793
+ const aggregateTotal = sources.reduce((totalBytes, source) => totalBytes + source.sizeBytes, 0);
3794
+ return {
3795
+ phase,
3796
+ fileIndex,
3797
+ fileCount: sources.length,
3798
+ fileName: sources[fileIndex]?.fileName ?? "",
3799
+ loaded,
3800
+ total,
3801
+ percent: total > 0 ? Math.round(loaded / total * 100) : 100,
3802
+ aggregateLoaded,
3803
+ aggregateTotal,
3804
+ aggregatePercent: aggregateTotal > 0 ? Math.round(aggregateLoaded / aggregateTotal * 100) : 100
3805
+ };
3806
+ }
3807
+ function sum(values) {
3808
+ return values.reduce((total, value) => total + value, 0);
3809
+ }
3810
+ function parseXhrHeaders(raw) {
3811
+ const headers = new Headers();
3812
+ for (const line of raw.trim().split(/[\r\n]+/)) {
3813
+ const index = line.indexOf(":");
3814
+ if (index === -1) continue;
3815
+ headers.set(line.slice(0, index).trim(), line.slice(index + 1).trim());
3816
+ }
3817
+ return headers;
3818
+ }
3819
+ function readProcessEnv() {
3820
+ const processLike = globalThis.process;
3821
+ return processLike?.env ?? {};
3822
+ }
3823
+ function isRecord5(value) {
3824
+ return Boolean(value) && typeof value === "object";
3825
+ }
3826
+
3827
+ // src/storage/module.ts
3828
+ var storageSdkManifest = {
3829
+ methods: [
3830
+ {
3831
+ name: "listStorageCatalogs",
3832
+ method: "GET",
3833
+ path: "/storage/catalogs",
3834
+ responseEnvelope: "raw",
3835
+ responseType: "{ data: S3CatalogItem[] }"
3836
+ },
3837
+ {
3838
+ name: "createStorageCatalog",
3839
+ method: "POST",
3840
+ path: "/storage/catalogs",
3841
+ requestType: "CreateStorageCatalogRequest",
3842
+ responseEnvelope: "raw",
3843
+ responseType: "S3CatalogItem"
3844
+ },
3845
+ {
3846
+ name: "updateStorageCatalog",
3847
+ method: "PATCH",
3848
+ path: "/storage/catalogs/{id}",
3849
+ pathParams: ["id"],
3850
+ requestType: "UpdateStorageCatalogRequest",
3851
+ responseEnvelope: "raw",
3852
+ responseType: "S3CatalogItem"
3853
+ },
3854
+ {
3855
+ name: "deleteStorageCatalog",
3856
+ method: "DELETE",
3857
+ path: "/storage/catalogs/{id}",
3858
+ pathParams: ["id"],
3859
+ responseEnvelope: "raw",
3860
+ responseType: "{ id: string; deleted: boolean }"
3861
+ },
3862
+ {
3863
+ name: "listStorageCredentials",
3864
+ method: "GET",
3865
+ path: "/storage/credentials",
3866
+ responseEnvelope: "raw",
3867
+ responseType: "{ data: S3CredentialListItem[] }"
3868
+ },
3869
+ {
3870
+ name: "createStorageUploadUrl",
3871
+ method: "POST",
3872
+ path: "/storage/files/upload-url",
3873
+ requestType: "CreateStorageUploadUrlRequest",
3874
+ responseEnvelope: "athena",
3875
+ responseType: "StorageUploadUrlResponse"
3876
+ },
3877
+ {
3878
+ name: "createStorageUploadUrls",
3879
+ method: "POST",
3880
+ path: "/storage/files/upload-urls",
3881
+ requestType: "CreateStorageUploadUrlsRequest",
3882
+ responseEnvelope: "athena",
3883
+ responseType: "StorageBatchUploadUrlResponse"
3884
+ },
3885
+ {
3886
+ name: "listStorageFiles",
3887
+ method: "POST",
3888
+ path: "/storage/files/list",
3889
+ requestType: "ListStorageFilesRequest",
3890
+ responseEnvelope: "athena",
3891
+ responseType: "StorageListFilesResponse"
3892
+ },
3893
+ {
3894
+ name: "getStorageFile",
3895
+ method: "GET",
3896
+ path: "/storage/files/{file_id}",
3897
+ pathParams: ["file_id"],
3898
+ responseEnvelope: "athena",
3899
+ responseType: "StorageFileMutationResponse"
3900
+ },
3901
+ {
3902
+ name: "getStorageFileUrl",
3903
+ method: "GET",
3904
+ path: "/storage/files/{file_id}/url",
3905
+ pathParams: ["file_id"],
3906
+ queryParams: ["purpose"],
3907
+ responseEnvelope: "athena",
3908
+ responseType: "PresignedFileUrlResponse"
3909
+ },
3910
+ {
3911
+ name: "getStorageFileProxy",
3912
+ method: "GET",
3913
+ path: "/storage/files/{file_id}/proxy",
3914
+ pathParams: ["file_id"],
3915
+ queryParams: ["purpose"],
3916
+ responseEnvelope: "raw",
3917
+ responseType: "Response",
3918
+ binary: true
3919
+ },
3920
+ {
3921
+ name: "updateStorageFile",
3922
+ method: "PATCH",
3923
+ path: "/storage/files/{file_id}",
3924
+ pathParams: ["file_id"],
3925
+ requestType: "UpdateStorageFileRequest",
3926
+ responseEnvelope: "athena",
3927
+ responseType: "StorageFileMutationResponse"
3928
+ },
3929
+ {
3930
+ name: "deleteStorageFile",
3931
+ method: "DELETE",
3932
+ path: "/storage/files/{file_id}",
3933
+ pathParams: ["file_id"],
3934
+ responseEnvelope: "athena",
3935
+ responseType: "StorageFileMutationResponse"
3936
+ },
3937
+ {
3938
+ name: "setStorageFileVisibility",
3939
+ method: "PATCH",
3940
+ path: "/storage/files/{file_id}/visibility",
3941
+ pathParams: ["file_id"],
3942
+ requestType: "SetStorageFileVisibilityRequest",
3943
+ responseEnvelope: "athena",
3944
+ responseType: "StorageFileMutationResponse"
3945
+ },
3946
+ {
3947
+ name: "deleteStorageFolder",
3948
+ method: "POST",
3949
+ path: "/storage/folders/delete",
3950
+ requestType: "DeleteStorageFolderRequest",
3951
+ responseEnvelope: "athena",
3952
+ responseType: "StorageFolderMutationResponse"
3953
+ },
3954
+ {
3955
+ name: "moveStorageFolder",
3956
+ method: "POST",
3957
+ path: "/storage/folders/move",
3958
+ requestType: "MoveStorageFolderRequest",
3959
+ responseEnvelope: "athena",
3960
+ responseType: "StorageFolderMutationResponse"
3961
+ }
3962
+ ]
3963
+ };
3964
+ var AthenaStorageError = class extends Error {
3965
+ code;
3966
+ athenaCode;
3967
+ kind;
3968
+ category;
3969
+ retryable;
3970
+ status;
3971
+ endpoint;
3972
+ method;
3973
+ requestId;
3974
+ hint;
3975
+ causeDetail;
3976
+ raw;
3977
+ normalized;
3978
+ __athenaNormalizedError;
3979
+ constructor(input) {
3980
+ super(input.message, { cause: input.cause });
3981
+ this.name = "AthenaStorageError";
3982
+ this.code = input.code;
3983
+ this.status = input.status;
3984
+ this.endpoint = input.endpoint;
3985
+ this.method = input.method;
3986
+ this.requestId = input.requestId;
3987
+ this.hint = input.hint;
3988
+ this.causeDetail = causeToString(input.cause);
3989
+ this.raw = input.raw ?? null;
3990
+ this.normalized = normalizeStorageErrorInput(input);
3991
+ this.__athenaNormalizedError = this.normalized;
3992
+ this.athenaCode = this.normalized.code;
3993
+ this.kind = this.normalized.kind;
3994
+ this.category = this.normalized.category;
3995
+ this.retryable = this.normalized.retryable;
3996
+ Object.defineProperty(this, "__athenaNormalizedError", {
3997
+ value: this.normalized,
3998
+ enumerable: false,
3999
+ configurable: false,
4000
+ writable: false
4001
+ });
4002
+ }
4003
+ toDetails() {
4004
+ return {
4005
+ code: this.code,
4006
+ athenaCode: this.athenaCode,
4007
+ kind: this.kind,
4008
+ category: this.category,
4009
+ retryable: this.retryable,
4010
+ message: this.message,
4011
+ status: this.status,
4012
+ endpoint: this.endpoint,
4013
+ method: this.method,
4014
+ requestId: this.requestId,
4015
+ hint: this.hint,
4016
+ cause: this.causeDetail,
4017
+ raw: this.raw
4018
+ };
4019
+ }
4020
+ };
4021
+ function isRecord6(value) {
4022
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
4023
+ }
4024
+ function causeToString(cause) {
4025
+ if (cause === void 0 || cause === null) return void 0;
4026
+ if (typeof cause === "string") return cause;
4027
+ if (cause instanceof Error && cause.message.trim()) return cause.message.trim();
4028
+ try {
4029
+ return JSON.stringify(cause);
4030
+ } catch {
4031
+ return String(cause);
4032
+ }
4033
+ }
4034
+ function storageGatewayCode(code) {
4035
+ if (code === "INVALID_URL") return "INVALID_URL";
4036
+ if (code === "NETWORK_ERROR") return "NETWORK_ERROR";
4037
+ if (code === "INVALID_JSON" || code === "INVALID_ATHENA_ENVELOPE") return "INVALID_JSON";
4038
+ if (code === "HTTP_ERROR") return "HTTP_ERROR";
4039
+ return "UNKNOWN_ERROR";
4040
+ }
4041
+ function headerValue(headers, names) {
4042
+ for (const name of names) {
4043
+ const value = headers.get(name);
4044
+ if (value?.trim()) return value.trim();
4045
+ }
4046
+ return void 0;
4047
+ }
4048
+ function storageOperationFromEndpoint(endpoint, method) {
4049
+ const endpointPath = String(endpoint).split("?")[0];
4050
+ for (const candidate of storageSdkManifest.methods) {
4051
+ if (candidate.method !== method) continue;
4052
+ const pattern = `^${candidate.path.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/\\\{[^/]+\\\}/g, "[^/]+")}$`;
4053
+ if (new RegExp(pattern).test(endpointPath)) {
4054
+ return candidate.name;
4055
+ }
4056
+ }
4057
+ return `storage:${method.toLowerCase()}`;
4058
+ }
4059
+ function normalizeStorageErrorInput(input) {
4060
+ return normalizeAthenaError(
4061
+ {
4062
+ data: null,
4063
+ error: {
4064
+ message: input.message,
4065
+ gatewayCode: storageGatewayCode(input.code),
4066
+ status: input.status,
4067
+ raw: input.raw ?? input.cause ?? null
4068
+ },
4069
+ errorDetails: {
4070
+ code: storageGatewayCode(input.code),
4071
+ message: input.message,
4072
+ status: input.status,
4073
+ endpoint: input.endpoint,
4074
+ method: input.method,
4075
+ requestId: input.requestId,
4076
+ hint: input.hint,
4077
+ cause: causeToString(input.cause)
4078
+ },
4079
+ raw: input.raw ?? input.cause ?? null,
4080
+ status: input.status
4081
+ },
4082
+ { operation: storageOperationFromEndpoint(input.endpoint, input.method) }
4083
+ );
4084
+ }
4085
+ function createAthenaStorageError(input) {
4086
+ return new AthenaStorageError(input);
4087
+ }
4088
+ async function notifyStorageError(error, options, runtimeOptions) {
4089
+ const handlers = [runtimeOptions?.onError, options?.onError].filter(
4090
+ (handler) => typeof handler === "function"
4091
+ );
4092
+ for (const handler of handlers) {
4093
+ try {
4094
+ await handler(error);
4095
+ } catch {
4096
+ }
4097
+ }
4098
+ }
4099
+ async function rejectStorageError(input, options, runtimeOptions) {
4100
+ const error = createAthenaStorageError(input);
4101
+ await notifyStorageError(error, options, runtimeOptions);
4102
+ throw error;
4103
+ }
4104
+ function parseResponseBody3(rawText, contentType) {
4105
+ if (!rawText) {
4106
+ return { parsed: null, parseFailed: false };
4107
+ }
4108
+ const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
4109
+ const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
4110
+ if (!looksJson) {
4111
+ return { parsed: rawText, parseFailed: false };
4112
+ }
4113
+ try {
4114
+ return { parsed: JSON.parse(rawText), parseFailed: false };
4115
+ } catch {
4116
+ return { parsed: rawText, parseFailed: true };
4117
+ }
4118
+ }
4119
+ function appendQuery(path, query) {
4120
+ if (!query) return path;
4121
+ const params = new URLSearchParams();
4122
+ for (const [key, value] of Object.entries(query)) {
4123
+ if (value === void 0 || value === null) continue;
4124
+ params.set(key, String(value));
4125
+ }
4126
+ const queryText = params.toString();
4127
+ return queryText ? `${path}?${queryText}` : path;
4128
+ }
4129
+ function storagePath(path) {
4130
+ return path;
4131
+ }
4132
+ function withPathParam(path, name, value) {
4133
+ return path.replace(`{${name}}`, encodeURIComponent(value));
4134
+ }
4135
+ function resolveErrorMessage3(payload, fallback) {
4136
+ if (isRecord6(payload)) {
4137
+ const message = payload.message ?? payload.error ?? payload.details;
4138
+ if (typeof message === "string" && message.trim()) {
4139
+ return message.trim();
4140
+ }
4141
+ }
4142
+ if (typeof payload === "string" && payload.trim()) {
4143
+ return payload.trim();
4144
+ }
4145
+ return fallback;
4146
+ }
4147
+ function resolveErrorHint2(payload) {
4148
+ if (!isRecord6(payload)) return void 0;
4149
+ const hint = payload.hint ?? payload.suggestion;
4150
+ return typeof hint === "string" && hint.trim() ? hint.trim() : void 0;
4151
+ }
4152
+ function resolveErrorCause(payload) {
4153
+ if (!isRecord6(payload)) return void 0;
4154
+ const cause = payload.cause ?? payload.reason;
4155
+ return typeof cause === "string" && cause.trim() ? cause.trim() : void 0;
4156
+ }
4157
+ function storageCodeFromUnknown(error) {
4158
+ if (isAthenaGatewayError(error)) {
4159
+ if (error.code === "INVALID_URL") return "INVALID_URL";
4160
+ if (error.code === "NETWORK_ERROR") return "NETWORK_ERROR";
4161
+ if (error.code === "INVALID_JSON") return "INVALID_JSON";
4162
+ if (error.code === "HTTP_ERROR") return "HTTP_ERROR";
4163
+ }
4164
+ return "UNKNOWN_ERROR";
4165
+ }
4166
+ async function callStorageEndpoint(gateway, endpoint, method, envelope, payload, options, runtimeOptions) {
4167
+ let url;
4168
+ let headers;
4169
+ try {
4170
+ const baseUrl = options?.baseUrl ? normalizeAthenaGatewayBaseUrl(options.baseUrl) : gateway.baseUrl;
4171
+ url = buildAthenaGatewayUrl(baseUrl, endpoint);
4172
+ headers = gateway.buildHeaders(options);
4173
+ } catch (error) {
4174
+ return rejectStorageError(
4175
+ {
4176
+ code: storageCodeFromUnknown(error),
4177
+ message: error instanceof Error ? error.message : `Athena storage ${method} ${endpoint} failed before sending the request`,
4178
+ status: isAthenaGatewayError(error) ? error.status : 0,
4179
+ endpoint,
4180
+ method,
4181
+ raw: error,
4182
+ requestId: isAthenaGatewayError(error) ? error.requestId : void 0,
4183
+ hint: isAthenaGatewayError(error) ? error.hint : void 0,
4184
+ cause: error
4185
+ },
4186
+ options,
4187
+ runtimeOptions
4188
+ );
4189
+ }
4190
+ const requestInit = {
4191
+ method,
4192
+ headers,
4193
+ signal: options?.signal
4194
+ };
4195
+ if (payload !== void 0 && method !== "GET") {
4196
+ requestInit.body = JSON.stringify(payload);
4197
+ }
4198
+ let response;
4199
+ try {
4200
+ response = await fetch(url, requestInit);
4201
+ } catch (error) {
4202
+ const message = error instanceof Error ? error.message : String(error);
4203
+ return rejectStorageError(
4204
+ {
4205
+ code: "NETWORK_ERROR",
4206
+ message: `Network error while calling Athena storage ${method} ${endpoint}: ${message}`,
4207
+ status: 0,
4208
+ endpoint,
4209
+ method,
4210
+ cause: error
4211
+ },
4212
+ options,
4213
+ runtimeOptions
4214
+ );
4215
+ }
4216
+ let rawText;
4217
+ try {
4218
+ rawText = await response.text();
4219
+ } catch (error) {
4220
+ return rejectStorageError(
4221
+ {
4222
+ code: "NETWORK_ERROR",
4223
+ message: `Athena storage ${method} ${endpoint} response body could not be read`,
4224
+ status: response.status,
4225
+ endpoint,
4226
+ method,
4227
+ requestId: headerValue(response.headers, ["x-athena-request-id", "x-request-id", "request-id"]),
4228
+ cause: error
4229
+ },
4230
+ options,
4231
+ runtimeOptions
4232
+ );
4233
+ }
4234
+ const parsedBody = parseResponseBody3(rawText ?? "", response.headers.get("content-type"));
4235
+ const requestId = headerValue(response.headers, ["x-athena-request-id", "x-request-id", "request-id"]);
4236
+ if (parsedBody.parseFailed) {
4237
+ return rejectStorageError(
4238
+ {
4239
+ code: "INVALID_JSON",
4240
+ message: `Athena storage ${method} ${endpoint} returned malformed JSON`,
4241
+ status: response.status,
4242
+ endpoint,
4243
+ method,
4244
+ requestId,
4245
+ raw: parsedBody.parsed
4246
+ },
4247
+ options,
4248
+ runtimeOptions
4249
+ );
4250
+ }
4251
+ if (!response.ok) {
4252
+ return rejectStorageError(
4253
+ {
4254
+ code: "HTTP_ERROR",
4255
+ message: resolveErrorMessage3(
4256
+ parsedBody.parsed,
4257
+ `Athena storage ${method} ${endpoint} failed with status ${response.status}`
4258
+ ),
4259
+ status: response.status,
4260
+ endpoint,
4261
+ method,
4262
+ requestId,
4263
+ hint: resolveErrorHint2(parsedBody.parsed),
4264
+ cause: resolveErrorCause(parsedBody.parsed),
4265
+ raw: parsedBody.parsed
4266
+ },
4267
+ options,
4268
+ runtimeOptions
4269
+ );
4270
+ }
4271
+ if (envelope === "athena") {
4272
+ if (!isRecord6(parsedBody.parsed) || !("data" in parsedBody.parsed)) {
4273
+ return rejectStorageError(
4274
+ {
4275
+ code: "INVALID_ATHENA_ENVELOPE",
4276
+ message: `Athena storage ${method} ${endpoint} returned an invalid Athena envelope`,
4277
+ status: response.status,
4278
+ endpoint,
4279
+ method,
4280
+ requestId,
4281
+ raw: parsedBody.parsed
4282
+ },
4283
+ options,
4284
+ runtimeOptions
4285
+ );
4286
+ }
4287
+ return parsedBody.parsed.data;
4288
+ }
4289
+ return parsedBody.parsed;
4290
+ }
4291
+ async function callStorageBinaryEndpoint(gateway, endpoint, method, options, runtimeOptions) {
4292
+ let url;
4293
+ let headers;
4294
+ try {
4295
+ const baseUrl = options?.baseUrl ? normalizeAthenaGatewayBaseUrl(options.baseUrl) : gateway.baseUrl;
4296
+ url = buildAthenaGatewayUrl(baseUrl, endpoint);
4297
+ headers = gateway.buildHeaders(options);
4298
+ } catch (error) {
4299
+ return rejectStorageError(
4300
+ {
4301
+ code: storageCodeFromUnknown(error),
4302
+ message: error instanceof Error ? error.message : `Athena storage ${method} ${endpoint} failed before sending the request`,
4303
+ status: isAthenaGatewayError(error) ? error.status : 0,
4304
+ endpoint,
4305
+ method,
4306
+ raw: error,
4307
+ requestId: isAthenaGatewayError(error) ? error.requestId : void 0,
4308
+ hint: isAthenaGatewayError(error) ? error.hint : void 0,
4309
+ cause: error
4310
+ },
4311
+ options,
4312
+ runtimeOptions
4313
+ );
4314
+ }
4315
+ let response;
4316
+ try {
4317
+ response = await fetch(url, {
4318
+ method,
4319
+ headers,
4320
+ signal: options?.signal
4321
+ });
4322
+ } catch (error) {
4323
+ const message = error instanceof Error ? error.message : String(error);
4324
+ return rejectStorageError(
4325
+ {
4326
+ code: "NETWORK_ERROR",
4327
+ message: `Network error while calling Athena storage ${method} ${endpoint}: ${message}`,
4328
+ status: 0,
4329
+ endpoint,
4330
+ method,
4331
+ cause: error
4332
+ },
4333
+ options,
4334
+ runtimeOptions
4335
+ );
4336
+ }
4337
+ if (response.ok) {
4338
+ return response;
4339
+ }
4340
+ const requestId = headerValue(response.headers, ["x-athena-request-id", "x-request-id", "request-id"]);
4341
+ let rawErrorBody = null;
4342
+ try {
4343
+ const rawText = await response.text();
4344
+ const parsedBody = parseResponseBody3(rawText ?? "", response.headers.get("content-type"));
4345
+ rawErrorBody = parsedBody.parsed;
4346
+ } catch (error) {
4347
+ return rejectStorageError(
4348
+ {
4349
+ code: "NETWORK_ERROR",
4350
+ message: `Athena storage ${method} ${endpoint} error response body could not be read`,
4351
+ status: response.status,
4352
+ endpoint,
4353
+ method,
4354
+ requestId,
4355
+ cause: error
4356
+ },
4357
+ options,
4358
+ runtimeOptions
4359
+ );
4360
+ }
4361
+ return rejectStorageError(
4362
+ {
4363
+ code: "HTTP_ERROR",
4364
+ message: resolveErrorMessage3(
4365
+ rawErrorBody,
4366
+ `Athena storage ${method} ${endpoint} failed with status ${response.status}`
4367
+ ),
4368
+ status: response.status,
4369
+ endpoint,
4370
+ method,
4371
+ requestId,
4372
+ hint: resolveErrorHint2(rawErrorBody),
4373
+ cause: resolveErrorCause(rawErrorBody),
4374
+ raw: rawErrorBody
4375
+ },
4376
+ options,
4377
+ runtimeOptions
4378
+ );
4379
+ }
4380
+ function isBlobBody(body) {
4381
+ return typeof Blob !== "undefined" && body instanceof Blob;
4382
+ }
4383
+ function isReadableStreamBody(body) {
4384
+ return typeof ReadableStream !== "undefined" && body instanceof ReadableStream;
4385
+ }
4386
+ async function putPresignedUploadBody(uploadUrl, uploadHeaders, body, options) {
4387
+ const headers = new Headers(uploadHeaders);
4388
+ Object.entries(options?.headers ?? {}).forEach(([key, value]) => headers.set(key, value));
4389
+ if (!headers.has("Content-Type") && isBlobBody(body) && body.type) {
4390
+ headers.set("Content-Type", body.type);
4391
+ }
4392
+ const init = {
4393
+ method: "PUT",
4394
+ headers,
4395
+ body,
4396
+ signal: options?.signal
4397
+ };
4398
+ if (isReadableStreamBody(body)) {
4399
+ init.duplex = "half";
4400
+ }
4401
+ return fetch(uploadUrl, init);
4402
+ }
4403
+ function attachManagedUpload(upload) {
4404
+ const headers = {};
4405
+ return {
4406
+ ...upload,
4407
+ method: "PUT",
4408
+ headers,
4409
+ expiresAt: upload.expires_at,
4410
+ put(body, options) {
4411
+ return putPresignedUploadBody(upload.url, headers, body, options);
4412
+ }
4413
+ };
4414
+ }
4415
+ function attachUploadHelper(response) {
4416
+ return {
4417
+ ...response,
4418
+ upload: attachManagedUpload(response.upload)
4419
+ };
4420
+ }
4421
+ function attachUploadHelpers(response) {
4422
+ return {
4423
+ files: response.files.map(attachUploadHelper)
4424
+ };
4425
+ }
4426
+ function normalizeUploadUrlRequest(input) {
4427
+ const s3_id = input.s3_id ?? input.s3Id;
4428
+ const storage_key = input.storage_key ?? input.storageKey;
4429
+ if (!s3_id?.trim()) {
4430
+ throw new Error("athena.storage.file.upload requires s3_id or s3Id");
4431
+ }
4432
+ if (!storage_key?.trim()) {
4433
+ throw new Error("athena.storage.file.upload requires storage_key or storageKey");
4434
+ }
4435
+ const fileName = input.fileName?.trim();
4436
+ const originalName = input.originalName?.trim();
4437
+ return {
4438
+ s3_id,
4439
+ bucket: input.bucket,
4440
+ storage_key,
4441
+ name: input.name ?? fileName,
4442
+ original_name: input.original_name ?? originalName ?? fileName,
4443
+ resource_id: input.resource_id ?? input.resourceId,
4444
+ mime_type: input.mime_type ?? input.mimeType,
4445
+ content_type: input.content_type ?? input.contentType,
4446
+ size_bytes: input.size_bytes ?? input.sizeBytes,
4447
+ file_id: input.file_id ?? input.fileId,
4448
+ public: input.public,
4449
+ visibility: input.visibility,
4450
+ metadata: input.metadata
4451
+ };
4452
+ }
4453
+ async function callStorageUploadBinaryEndpoint(gateway, endpoint, body, options, runtimeOptions) {
4454
+ let url;
4455
+ let headers;
4456
+ try {
4457
+ const baseUrl = options?.baseUrl ? normalizeAthenaGatewayBaseUrl(options.baseUrl) : gateway.baseUrl;
4458
+ url = buildAthenaGatewayUrl(baseUrl, endpoint);
4459
+ headers = gateway.buildHeaders(options);
4460
+ } catch (error) {
4461
+ return rejectStorageError(
4462
+ {
4463
+ code: storageCodeFromUnknown(error),
4464
+ message: error instanceof Error ? error.message : `Athena storage PUT ${endpoint} failed before sending the request`,
4465
+ status: isAthenaGatewayError(error) ? error.status : 0,
4466
+ endpoint,
4467
+ method: "PUT",
4468
+ raw: error,
4469
+ requestId: isAthenaGatewayError(error) ? error.requestId : void 0,
4470
+ hint: isAthenaGatewayError(error) ? error.hint : void 0,
4471
+ cause: error
4472
+ },
4473
+ options,
4474
+ runtimeOptions
4475
+ );
4476
+ }
4477
+ delete headers["Content-Type"];
4478
+ delete headers["content-type"];
4479
+ if (isBlobBody(body) && body.type) {
4480
+ headers["Content-Type"] = body.type;
4481
+ }
4482
+ const requestInit = {
4483
+ method: "PUT",
4484
+ headers,
4485
+ body,
4486
+ signal: options?.signal
4487
+ };
4488
+ if (isReadableStreamBody(body)) {
4489
+ requestInit.duplex = "half";
4490
+ }
4491
+ let response;
4492
+ try {
4493
+ response = await fetch(url, requestInit);
4494
+ } catch (error) {
4495
+ const message = error instanceof Error ? error.message : String(error);
4496
+ return rejectStorageError(
4497
+ {
4498
+ code: "NETWORK_ERROR",
4499
+ message: `Network error while calling Athena storage PUT ${endpoint}: ${message}`,
4500
+ status: 0,
4501
+ endpoint,
4502
+ method: "PUT",
4503
+ cause: error
4504
+ },
4505
+ options,
4506
+ runtimeOptions
4507
+ );
4508
+ }
4509
+ let rawText;
4510
+ try {
4511
+ rawText = await response.text();
4512
+ } catch (error) {
4513
+ return rejectStorageError(
4514
+ {
4515
+ code: "NETWORK_ERROR",
4516
+ message: `Athena storage PUT ${endpoint} response body could not be read`,
4517
+ status: response.status,
4518
+ endpoint,
4519
+ method: "PUT",
4520
+ requestId: headerValue(response.headers, ["x-athena-request-id", "x-request-id", "request-id"]),
4521
+ cause: error
4522
+ },
4523
+ options,
4524
+ runtimeOptions
4525
+ );
4526
+ }
4527
+ const parsedBody = parseResponseBody3(rawText ?? "", response.headers.get("content-type"));
4528
+ const requestId = headerValue(response.headers, ["x-athena-request-id", "x-request-id", "request-id"]);
4529
+ if (parsedBody.parseFailed) {
4530
+ return rejectStorageError(
4531
+ {
4532
+ code: "INVALID_JSON",
4533
+ message: `Athena storage PUT ${endpoint} returned malformed JSON`,
4534
+ status: response.status,
4535
+ endpoint,
4536
+ method: "PUT",
4537
+ requestId,
4538
+ raw: parsedBody.parsed
4539
+ },
4540
+ options,
4541
+ runtimeOptions
4542
+ );
4543
+ }
4544
+ if (!response.ok) {
4545
+ return rejectStorageError(
4546
+ {
4547
+ code: "HTTP_ERROR",
4548
+ message: resolveErrorMessage3(
4549
+ parsedBody.parsed,
4550
+ `Athena storage PUT ${endpoint} failed with status ${response.status}`
4551
+ ),
4552
+ status: response.status,
4553
+ endpoint,
4554
+ method: "PUT",
4555
+ requestId,
4556
+ hint: resolveErrorHint2(parsedBody.parsed),
4557
+ cause: resolveErrorCause(parsedBody.parsed),
4558
+ raw: parsedBody.parsed
4559
+ },
4560
+ options,
4561
+ runtimeOptions
4562
+ );
4563
+ }
4564
+ if (!isRecord6(parsedBody.parsed) || !("data" in parsedBody.parsed)) {
4565
+ return rejectStorageError(
4566
+ {
4567
+ code: "INVALID_ATHENA_ENVELOPE",
4568
+ message: `Athena storage PUT ${endpoint} returned an invalid Athena envelope`,
4569
+ status: response.status,
4570
+ endpoint,
4571
+ method: "PUT",
4572
+ requestId,
4573
+ raw: parsedBody.parsed
4574
+ },
4575
+ options,
4576
+ runtimeOptions
4577
+ );
4578
+ }
4579
+ return parsedBody.parsed.data;
4580
+ }
4581
+ function createStorageModule(gateway, runtimeOptions) {
4582
+ const callRaw = (path, method, payload, options) => callStorageEndpoint(
4583
+ gateway,
4584
+ storagePath(path),
4585
+ method,
4586
+ "raw",
4587
+ payload,
4588
+ options,
4589
+ runtimeOptions
4590
+ );
4591
+ const callAthena2 = (path, method, payload, options) => callStorageEndpoint(
4592
+ gateway,
4593
+ storagePath(path),
4594
+ method,
4595
+ "athena",
4596
+ payload,
4597
+ options,
4598
+ runtimeOptions
4599
+ );
4600
+ const base = {
4601
+ listStorageCatalogs(options) {
4602
+ return callRaw("/storage/catalogs", "GET", void 0, options);
4603
+ },
4604
+ createStorageCatalog(input, options) {
4605
+ return callRaw("/storage/catalogs", "POST", input, options);
4606
+ },
4607
+ updateStorageCatalog(id, input, options) {
4608
+ return callRaw(withPathParam("/storage/catalogs/{id}", "id", id), "PATCH", input, options);
4609
+ },
4610
+ deleteStorageCatalog(id, options) {
4611
+ return callRaw(withPathParam("/storage/catalogs/{id}", "id", id), "DELETE", void 0, options);
4612
+ },
4613
+ listStorageCredentials(options) {
4614
+ return callRaw("/storage/credentials", "GET", void 0, options);
4615
+ },
4616
+ createStorageUploadUrl(input, options) {
4617
+ return callAthena2("/storage/files/upload-url", "POST", input, options);
4618
+ },
4619
+ createStorageUploadUrls(input, options) {
4620
+ return callAthena2("/storage/files/upload-urls", "POST", input, options);
4621
+ },
4622
+ listStorageFiles(input, options) {
4623
+ return callAthena2("/storage/files/list", "POST", input, options);
4624
+ },
4625
+ getStorageFile(fileId, options) {
4626
+ return callAthena2(withPathParam("/storage/files/{file_id}", "file_id", fileId), "GET", void 0, options);
4627
+ },
4628
+ getStorageFileUrl(fileId, query, options) {
4629
+ const path = appendQuery(
4630
+ withPathParam("/storage/files/{file_id}/url", "file_id", fileId),
4631
+ query
4632
+ );
4633
+ return callAthena2(path, "GET", void 0, options);
4634
+ },
4635
+ getStorageFileProxy(fileId, query, options) {
4636
+ const path = appendQuery(
4637
+ withPathParam("/storage/files/{file_id}/proxy", "file_id", fileId),
4638
+ query
4639
+ );
4640
+ return callStorageBinaryEndpoint(gateway, storagePath(path), "GET", options, runtimeOptions);
4641
+ },
4642
+ updateStorageFile(fileId, input, options) {
4643
+ return callAthena2(withPathParam("/storage/files/{file_id}", "file_id", fileId), "PATCH", input, options);
4644
+ },
4645
+ deleteStorageFile(fileId, options) {
4646
+ return callAthena2(withPathParam("/storage/files/{file_id}", "file_id", fileId), "DELETE", void 0, options);
4647
+ },
4648
+ setStorageFileVisibility(fileId, input, options) {
4649
+ return callAthena2(withPathParam("/storage/files/{file_id}/visibility", "file_id", fileId), "PATCH", input, options);
4650
+ },
4651
+ deleteStorageFolder(input, options) {
4652
+ return callAthena2("/storage/folders/delete", "POST", input, options);
4653
+ },
4654
+ moveStorageFolder(input, options) {
4655
+ return callAthena2("/storage/folders/move", "POST", input, options);
4656
+ }
4657
+ };
4658
+ const fileFacade = createStorageFileModule(base, runtimeOptions);
4659
+ const fileUpload = ((input, options) => {
4660
+ if (isRecord6(input) && "files" in input) {
4661
+ return fileFacade.upload(input, options);
4662
+ }
4663
+ return base.createStorageUploadUrl(
4664
+ normalizeUploadUrlRequest(input),
4665
+ options
4666
+ ).then(attachUploadHelper);
4667
+ });
4668
+ const fileDelete = ((input, options) => fileFacade.delete(input, options));
4669
+ const file = {
4670
+ ...fileFacade,
4671
+ upload: fileUpload,
4672
+ uploadMany(input, options) {
4673
+ return base.createStorageUploadUrls(
4674
+ { files: input.files.map(normalizeUploadUrlRequest) },
4675
+ options
4676
+ ).then(attachUploadHelpers);
4677
+ },
4678
+ confirmUpload(fileId, input, options) {
4679
+ return callAthena2(withPathParam("/storage/files/{file_id}/confirm-upload", "file_id", fileId), "POST", input ?? {}, options);
4680
+ },
4681
+ uploadBinary(fileId, body, options) {
4682
+ return callStorageUploadBinaryEndpoint(
4683
+ gateway,
4684
+ storagePath(withPathParam("/storage/files/{file_id}/upload", "file_id", fileId)),
4685
+ body,
4686
+ options,
4687
+ runtimeOptions
4688
+ );
4689
+ },
4690
+ search(input, options) {
4691
+ return callAthena2("/storage/files/search", "POST", input, options);
4692
+ },
4693
+ get(fileId, options) {
4694
+ return base.getStorageFile(fileId, options);
4695
+ },
4696
+ update(fileId, input, options) {
4697
+ return base.updateStorageFile(fileId, input, options);
4698
+ },
4699
+ delete: fileDelete,
4700
+ deleteMany(input, options) {
4701
+ return callAthena2("/storage/files/delete-many", "POST", input, options);
4702
+ },
4703
+ updateMany(input, options) {
4704
+ return callAthena2("/storage/files/update-many", "POST", input, options);
4705
+ },
4706
+ restore(fileId, options) {
4707
+ return callAthena2(withPathParam("/storage/files/{file_id}/restore", "file_id", fileId), "POST", {}, options);
4708
+ },
4709
+ purge(fileId, options) {
4710
+ return callAthena2(withPathParam("/storage/files/{file_id}/purge", "file_id", fileId), "DELETE", void 0, options);
4711
+ },
4712
+ copy(fileId, input, options) {
4713
+ return callAthena2(withPathParam("/storage/files/{file_id}/copy", "file_id", fileId), "POST", input, options);
4714
+ },
4715
+ url(fileId, query, options) {
4716
+ return base.getStorageFileUrl(fileId, query, options);
4717
+ },
4718
+ publicUrl(fileId, options) {
4719
+ return callAthena2(withPathParam("/storage/files/{file_id}/public-url", "file_id", fileId), "GET", void 0, options);
4720
+ },
4721
+ proxy(fileId, query, options) {
4722
+ return base.getStorageFileProxy(fileId, query, options);
4723
+ },
4724
+ visibility: {
4725
+ set(fileId, input, options) {
4726
+ return base.setStorageFileVisibility(fileId, input, options);
4727
+ },
4728
+ setMany(input, options) {
4729
+ return callAthena2("/storage/files/visibility-many", "POST", input, options);
3260
4730
  }
4731
+ }
4732
+ };
4733
+ const credentials = {
4734
+ list(options) {
4735
+ return base.listStorageCredentials(options);
4736
+ }
4737
+ };
4738
+ const catalog = {
4739
+ list(options) {
4740
+ return base.listStorageCatalogs(options);
3261
4741
  },
3262
- apiKey: {
3263
- create: (input, options) => postGeneric("/api-key/create", input, options),
3264
- get: (input, options) => getWithQuery("/api-key/get", input, options),
3265
- update: (input, options) => postGeneric("/api-key/update", input, options),
3266
- delete: (input, options) => postGeneric("/api-key/delete", input, options),
3267
- list: (input, options) => getWithQuery("/api-key/list", input, options),
3268
- verify: (input, options) => postGeneric("/api-key/verify", input, options),
3269
- deleteAllExpired: (input, options) => executePostWithOptionalInput(
3270
- resolvedConfig,
3271
- { endpoint: "/api-key/delete-all-expired-api-keys", method: "POST" },
3272
- input,
3273
- options
3274
- )
4742
+ create(input, options) {
4743
+ return base.createStorageCatalog(input, options);
3275
4744
  },
3276
- signIn: {
3277
- email: (input, options) => postGeneric("/sign-in/email", input, options),
3278
- username: (input, options) => postGeneric("/sign-in/username", input, options),
3279
- social: (input, options) => postGeneric("/sign-in/social", input, options)
4745
+ update(id, input, options) {
4746
+ return base.updateStorageCatalog(id, input, options);
3280
4747
  },
3281
- signUp: {
3282
- email: (input, options) => postGeneric("/sign-up/email", input, options)
4748
+ delete(id, options) {
4749
+ return base.deleteStorageCatalog(id, options);
4750
+ }
4751
+ };
4752
+ const folder = {
4753
+ list(input, options) {
4754
+ return callAthena2("/storage/folders/list", "POST", input, options);
3283
4755
  },
3284
- organization,
3285
- callback: {
3286
- provider: (input, options) => {
3287
- const { payload, fetchOptions } = extractFetchOptions(input);
3288
- const parsed = payload;
3289
- const provider = String(parsed?.provider ?? "").trim();
3290
- if (!provider) {
3291
- throw new Error("callback.provider requires a non-empty provider value");
3292
- }
3293
- const code = String(parsed?.code ?? "").trim();
3294
- const state = String(parsed?.state ?? "").trim();
3295
- if (!code || !state) {
3296
- throw new Error("callback.provider requires non-empty code and state values");
3297
- }
3298
- const endpoint = `/callback/${encodeURIComponent(provider)}`;
3299
- return request({
3300
- endpoint,
3301
- method: "GET",
3302
- query: {
3303
- code,
3304
- state
3305
- },
3306
- fetchOptions
3307
- }, options);
3308
- }
4756
+ tree(input, options) {
4757
+ return callAthena2("/storage/folders/tree", "POST", input, options);
4758
+ },
4759
+ delete(input, options) {
4760
+ return base.deleteStorageFolder(input, options);
4761
+ },
4762
+ move(input, options) {
4763
+ return base.moveStorageFolder(input, options);
3309
4764
  }
3310
4765
  };
3311
- return {
3312
- baseUrl: normalizedBaseUrl,
3313
- request,
3314
- signIn: {
3315
- email: (input, options) => executePostWithCompatibleInput(
3316
- resolvedConfig,
3317
- { endpoint: "/sign-in/email", method: "POST" },
3318
- input,
3319
- options
3320
- ),
3321
- username: (input, options) => executePostWithCompatibleInput(
3322
- resolvedConfig,
3323
- { endpoint: "/sign-in/username", method: "POST" },
3324
- input,
3325
- options
3326
- ),
3327
- social: (input, options) => executePostWithCompatibleInput(
3328
- resolvedConfig,
3329
- { endpoint: "/sign-in/social", method: "POST" },
3330
- input,
3331
- options
3332
- )
4766
+ const permission = {
4767
+ list(input, options) {
4768
+ return callAthena2("/storage/permissions/list", "POST", input, options);
3333
4769
  },
3334
- signUp: {
3335
- email: (input, options) => executePostWithCompatibleInput(
3336
- resolvedConfig,
3337
- { endpoint: "/sign-up/email", method: "POST" },
3338
- input,
3339
- options
3340
- )
4770
+ grant(input, options) {
4771
+ return callAthena2("/storage/permissions/grant", "POST", input, options);
3341
4772
  },
3342
- signOut,
3343
- logout: signOut,
3344
- getSession: (input, options) => executeGetWithCompatibleInput(
3345
- resolvedConfig,
3346
- { endpoint: "/get-session", method: "GET" },
3347
- input,
3348
- options
3349
- ),
3350
- listSessions: (input, options) => executeGetWithCompatibleInput(
3351
- resolvedConfig,
3352
- { endpoint: "/list-sessions", method: "GET" },
3353
- input,
3354
- options
3355
- ),
3356
- revokeSession,
3357
- clearSession: revokeSession,
3358
- revokeSessions,
3359
- clearSessions: revokeSessions,
3360
- revokeOtherSessions,
3361
- clearOtherSessions: revokeOtherSessions,
3362
- forgetPassword: (input, options) => executePostWithCompatibleInput(
3363
- resolvedConfig,
3364
- { endpoint: "/forget-password", method: "POST" },
3365
- input,
3366
- options
3367
- ),
3368
- resetPassword: (input, options) => executePostWithCompatibleInput(
3369
- resolvedConfig,
3370
- { endpoint: "/reset-password", method: "POST" },
3371
- input,
3372
- options
3373
- ),
3374
- resolveResetPasswordToken,
3375
- verifyEmail: (input, options) => {
3376
- const { payload, fetchOptions } = extractFetchOptions(input);
3377
- const mergedOptions = mergeCallOptions(fetchOptions, options);
3378
- const query = payload;
3379
- return callAuthEndpoint(
3380
- resolvedConfig,
3381
- { endpoint: "/verify-email", method: "GET" },
3382
- void 0,
3383
- query ? {
3384
- token: query.token,
3385
- callbackURL: query.callbackURL
3386
- } : void 0,
3387
- mergedOptions
3388
- );
4773
+ revoke(input, options) {
4774
+ return callAthena2("/storage/permissions/revoke", "POST", input, options);
3389
4775
  },
3390
- sendVerificationEmail: (input, options) => executePostWithCompatibleInput(
3391
- resolvedConfig,
3392
- { endpoint: "/send-verification-email", method: "POST" },
3393
- input,
3394
- options
3395
- ),
3396
- changeEmail: (input, options) => executePostWithCompatibleInput(
3397
- resolvedConfig,
3398
- { endpoint: "/change-email", method: "POST" },
3399
- input,
3400
- options
3401
- ),
3402
- changePassword: (input, options) => executePostWithCompatibleInput(
3403
- resolvedConfig,
3404
- { endpoint: "/change-password", method: "POST" },
3405
- input,
3406
- options
3407
- ),
3408
- updateUser: (input, options) => executePostWithCompatibleInput(
3409
- resolvedConfig,
3410
- { endpoint: "/update-user", method: "POST" },
3411
- input,
3412
- options
3413
- ),
3414
- deleteUser,
3415
- deleteUserCallback,
3416
- linkSocial: (input, options) => executePostWithCompatibleInput(
3417
- resolvedConfig,
3418
- { endpoint: "/link-social", method: "POST" },
3419
- input,
3420
- options
3421
- ),
3422
- listAccounts: (input, options) => executeGetWithCompatibleInput(
3423
- resolvedConfig,
3424
- { endpoint: "/list-accounts", method: "GET" },
3425
- input,
3426
- options
3427
- ),
3428
- unlinkAccount: (input, options) => executePostWithCompatibleInput(
3429
- resolvedConfig,
3430
- { endpoint: "/unlink-account", method: "POST" },
3431
- input,
3432
- options
3433
- ),
3434
- refreshToken: (input, options) => executePostWithCompatibleInput(
3435
- resolvedConfig,
3436
- { endpoint: "/refresh-token", method: "POST" },
3437
- input,
3438
- options
3439
- ),
3440
- getAccessToken: (input, options) => executePostWithCompatibleInput(
3441
- resolvedConfig,
3442
- { endpoint: "/get-access-token", method: "POST" },
3443
- input,
3444
- options
3445
- ),
3446
- organization,
3447
- auth
4776
+ check(input, options) {
4777
+ return callAthena2("/storage/permissions/check", "POST", input, options);
4778
+ }
3448
4779
  };
3449
- }
3450
-
3451
- // src/db/module.ts
3452
- function createDbModule(input) {
3453
- const db = {
3454
- from(table, options) {
3455
- return input.from(table, options);
4780
+ const objectFolder = {
4781
+ create(input, options) {
4782
+ return callAthena2("/storage/objects/folder", "POST", input, options);
3456
4783
  },
3457
- select(table, columns, options) {
3458
- return input.from(table).select(columns, options);
4784
+ delete(input, options) {
4785
+ return callAthena2("/storage/objects/folder/delete", "POST", input, options);
3459
4786
  },
3460
- insert(table, values, options) {
3461
- return Array.isArray(values) ? input.from(table).insert(values, options) : input.from(table).insert(values, options);
4787
+ rename(input, options) {
4788
+ return callAthena2("/storage/objects/folder/rename", "POST", input, options);
4789
+ }
4790
+ };
4791
+ const object = {
4792
+ list(input, options) {
4793
+ return callAthena2("/storage/objects", "POST", input, options);
3462
4794
  },
3463
- upsert(table, values, options) {
3464
- return Array.isArray(values) ? input.from(table).upsert(values, options) : input.from(table).upsert(values, options);
4795
+ head(input, options) {
4796
+ return callAthena2("/storage/objects/head", "POST", input, options);
3465
4797
  },
3466
- update(table, values, options) {
3467
- return input.from(table).update(values, options);
4798
+ exists(input, options) {
4799
+ return callAthena2("/storage/objects/exists", "POST", input, options);
3468
4800
  },
3469
- delete(table, options) {
3470
- return input.from(table).delete(options);
4801
+ validate(input, options) {
4802
+ return callAthena2("/storage/objects/validate", "POST", input, options);
3471
4803
  },
3472
- rpc(fn, args, options) {
3473
- return input.rpc(fn, args, options);
4804
+ update(input, options) {
4805
+ return callAthena2("/storage/objects/update", "POST", input, options);
3474
4806
  },
3475
- query(query, options) {
3476
- return input.query(query, options);
4807
+ copy(input, options) {
4808
+ return callAthena2("/storage/objects/copy", "POST", input, options);
4809
+ },
4810
+ url(input, options) {
4811
+ return callAthena2("/storage/objects/url", "POST", input, options);
4812
+ },
4813
+ publicUrl(input, options) {
4814
+ return callAthena2("/storage/objects/public-url", "POST", input, options);
4815
+ },
4816
+ delete(input, options) {
4817
+ return callAthena2("/storage/objects/delete", "POST", input, options);
4818
+ },
4819
+ uploadUrl(input, options) {
4820
+ return callAthena2("/storage/objects/upload-url", "POST", input, options);
4821
+ },
4822
+ folder: objectFolder
4823
+ };
4824
+ const bucket = {
4825
+ list(input, options) {
4826
+ return callAthena2("/storage/buckets/list", "POST", input, options);
4827
+ },
4828
+ create(input, options) {
4829
+ return callAthena2("/storage/buckets/create", "POST", input, options);
4830
+ },
4831
+ delete(input, options) {
4832
+ return callAthena2("/storage/buckets/delete", "POST", input, options);
4833
+ },
4834
+ cors: {
4835
+ get(input, options) {
4836
+ return callAthena2("/storage/buckets/cors", "POST", input, options);
4837
+ },
4838
+ set(input, options) {
4839
+ return callAthena2("/storage/buckets/cors/set", "POST", input, options);
4840
+ },
4841
+ delete(input, options) {
4842
+ return callAthena2("/storage/buckets/cors/delete", "POST", input, options);
4843
+ }
3477
4844
  }
3478
4845
  };
3479
- return db;
4846
+ const multipart = {
4847
+ create(input, options) {
4848
+ return callAthena2("/storage/multipart/create", "POST", input, options);
4849
+ },
4850
+ signPart(input, options) {
4851
+ return callAthena2("/storage/multipart/sign-part", "POST", input, options);
4852
+ },
4853
+ complete(input, options) {
4854
+ return callAthena2("/storage/multipart/complete", "POST", input, options);
4855
+ },
4856
+ abort(input, options) {
4857
+ return callAthena2("/storage/multipart/abort", "POST", input, options);
4858
+ },
4859
+ listParts(input, options) {
4860
+ return callAthena2("/storage/multipart/list-parts", "POST", input, options);
4861
+ }
4862
+ };
4863
+ const audit = {
4864
+ list(input, options) {
4865
+ return callAthena2("/storage/audit/list", "POST", input, options);
4866
+ }
4867
+ };
4868
+ return {
4869
+ ...base,
4870
+ credentials,
4871
+ catalog,
4872
+ file,
4873
+ folder,
4874
+ permission,
4875
+ object,
4876
+ bucket,
4877
+ multipart,
4878
+ audit,
4879
+ delete: file.delete
4880
+ };
3480
4881
  }
3481
4882
 
3482
4883
  // src/query-ast.ts
@@ -3506,7 +4907,7 @@ var BOOLEAN_SAFE_OPERATORS = /* @__PURE__ */ new Set([
3506
4907
  "ilike",
3507
4908
  "is"
3508
4909
  ]);
3509
- function isRecord5(value) {
4910
+ function isRecord7(value) {
3510
4911
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
3511
4912
  }
3512
4913
  function isUuidString(value) {
@@ -3519,7 +4920,7 @@ function shouldUseUuidTextComparison(column, value) {
3519
4920
  return typeof value === "string" && isUuidString(value) && isUuidIdentifierColumn(column);
3520
4921
  }
3521
4922
  function isRelationSelectNode(value) {
3522
- return isRecord5(value) && isRecord5(value.select);
4923
+ return isRecord7(value) && isRecord7(value.select);
3523
4924
  }
3524
4925
  function normalizeIdentifier(value, label) {
3525
4926
  const normalized = value.trim();
@@ -3575,7 +4976,7 @@ function compileRelationToken(key, node) {
3575
4976
  return `${prefix}${relationToken}(${nested})`;
3576
4977
  }
3577
4978
  function compileSelectShape(select) {
3578
- if (!isRecord5(select)) {
4979
+ if (!isRecord7(select)) {
3579
4980
  throw new Error("findMany select must be an object");
3580
4981
  }
3581
4982
  const tokens = [];
@@ -3599,7 +5000,7 @@ function compileSelectShape(select) {
3599
5000
  return tokens.join(",");
3600
5001
  }
3601
5002
  function selectShapeUsesRelationSchema(select) {
3602
- if (!isRecord5(select)) {
5003
+ if (!isRecord7(select)) {
3603
5004
  return false;
3604
5005
  }
3605
5006
  for (const rawValue of Object.values(select)) {
@@ -3617,7 +5018,7 @@ function selectShapeUsesRelationSchema(select) {
3617
5018
  }
3618
5019
  function compileColumnWhere(column, input) {
3619
5020
  const normalizedColumn = normalizeIdentifier(column, "where column");
3620
- if (!isRecord5(input)) {
5021
+ if (!isRecord7(input)) {
3621
5022
  return [buildGatewayCondition("eq", normalizedColumn, input)];
3622
5023
  }
3623
5024
  const conditions = [];
@@ -3645,7 +5046,7 @@ function compileColumnWhere(column, input) {
3645
5046
  return conditions;
3646
5047
  }
3647
5048
  function compileBooleanExpressionTerms(clause, label) {
3648
- if (!isRecord5(clause)) {
5049
+ if (!isRecord7(clause)) {
3649
5050
  throw new Error(`findMany where.${label} clauses must be objects`);
3650
5051
  }
3651
5052
  const entries = Object.entries(clause).filter(([, value]) => value !== void 0);
@@ -3654,7 +5055,7 @@ function compileBooleanExpressionTerms(clause, label) {
3654
5055
  }
3655
5056
  const [rawColumn, rawValue] = entries[0];
3656
5057
  const column = normalizeIdentifier(rawColumn, `where.${label} column`);
3657
- if (!isRecord5(rawValue)) {
5058
+ if (!isRecord7(rawValue)) {
3658
5059
  return [`${column}.eq.${stringifyFilterValue(rawValue)}`];
3659
5060
  }
3660
5061
  const operatorEntries = Object.entries(rawValue).filter(([, value]) => value !== void 0);
@@ -3678,7 +5079,7 @@ function compileWhere(where) {
3678
5079
  if (where === void 0) {
3679
5080
  return void 0;
3680
5081
  }
3681
- if (!isRecord5(where)) {
5082
+ if (!isRecord7(where)) {
3682
5083
  throw new Error("findMany where must be an object");
3683
5084
  }
3684
5085
  const conditions = [];
@@ -3728,7 +5129,7 @@ function compileOrderBy(orderBy) {
3728
5129
  if (orderBy === void 0) {
3729
5130
  return void 0;
3730
5131
  }
3731
- if (!isRecord5(orderBy)) {
5132
+ if (!isRecord7(orderBy)) {
3732
5133
  throw new Error("findMany orderBy must be an object");
3733
5134
  }
3734
5135
  if ("column" in orderBy) {
@@ -3903,11 +5304,11 @@ function toFindManyAstOrder(order) {
3903
5304
  ascending: order.direction !== "descending"
3904
5305
  };
3905
5306
  }
3906
- function isRecord6(value) {
5307
+ function isRecord8(value) {
3907
5308
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
3908
5309
  }
3909
5310
  function normalizeFindManyAstColumnPredicate(value) {
3910
- if (!isRecord6(value)) {
5311
+ if (!isRecord8(value)) {
3911
5312
  return {
3912
5313
  eq: value
3913
5314
  };
@@ -3931,7 +5332,7 @@ function normalizeFindManyAstBooleanOperand(clause) {
3931
5332
  return normalized;
3932
5333
  }
3933
5334
  function normalizeFindManyAstWhere(where) {
3934
- if (!where || !isRecord6(where)) {
5335
+ if (!where || !isRecord8(where)) {
3935
5336
  return where;
3936
5337
  }
3937
5338
  const normalized = {};
@@ -3945,7 +5346,7 @@ function normalizeFindManyAstWhere(where) {
3945
5346
  );
3946
5347
  continue;
3947
5348
  }
3948
- if (key === "not" && isRecord6(value)) {
5349
+ if (key === "not" && isRecord8(value)) {
3949
5350
  normalized.not = normalizeFindManyAstBooleanOperand(
3950
5351
  value
3951
5352
  );
@@ -3956,7 +5357,7 @@ function normalizeFindManyAstWhere(where) {
3956
5357
  return normalized;
3957
5358
  }
3958
5359
  function predicateRequiresUuidQueryFallback(column, value) {
3959
- if (!isRecord6(value)) {
5360
+ if (!isRecord8(value)) {
3960
5361
  return shouldUseUuidTextComparison(column, value);
3961
5362
  }
3962
5363
  const eqValue = value.eq;
@@ -3974,7 +5375,7 @@ function booleanOperandRequiresUuidQueryFallback(clause) {
3974
5375
  return false;
3975
5376
  }
3976
5377
  function findManyAstWhereRequiresLegacyTransport(where) {
3977
- if (!where || !isRecord6(where)) {
5378
+ if (!where || !isRecord8(where)) {
3978
5379
  return false;
3979
5380
  }
3980
5381
  for (const [key, value] of Object.entries(where)) {
@@ -3989,7 +5390,7 @@ function findManyAstWhereRequiresLegacyTransport(where) {
3989
5390
  }
3990
5391
  continue;
3991
5392
  }
3992
- if (key === "not" && isRecord6(value)) {
5393
+ if (key === "not" && isRecord8(value)) {
3993
5394
  if (booleanOperandRequiresUuidQueryFallback(value)) {
3994
5395
  return true;
3995
5396
  }
@@ -4191,7 +5592,7 @@ async function executeExperimentalRead(experimental, runner) {
4191
5592
  throw error;
4192
5593
  }
4193
5594
  }
4194
- function isRecord7(value) {
5595
+ function isRecord9(value) {
4195
5596
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
4196
5597
  }
4197
5598
  function firstNonEmptyString2(...values) {
@@ -4203,8 +5604,8 @@ function firstNonEmptyString2(...values) {
4203
5604
  return void 0;
4204
5605
  }
4205
5606
  function resolveStructuredErrorPayload2(raw) {
4206
- if (!isRecord7(raw)) return null;
4207
- return isRecord7(raw.error) ? raw.error : raw;
5607
+ if (!isRecord9(raw)) return null;
5608
+ return isRecord9(raw.error) ? raw.error : raw;
4208
5609
  }
4209
5610
  function resolveStructuredErrorDetails(payload, message) {
4210
5611
  if (!payload || !("details" in payload)) {
@@ -4220,7 +5621,7 @@ function resolveStructuredErrorDetails(payload, message) {
4220
5621
  return details;
4221
5622
  }
4222
5623
  function createResultError(response, result, normalized) {
4223
- const rawRecord = isRecord7(response.raw) ? response.raw : null;
5624
+ const rawRecord = isRecord9(response.raw) ? response.raw : null;
4224
5625
  const payload = resolveStructuredErrorPayload2(response.raw);
4225
5626
  const message = firstNonEmptyString2(
4226
5627
  response.error,
@@ -5683,7 +7084,7 @@ function createClientFromConfig(config) {
5683
7084
  };
5684
7085
  const query = createQueryBuilder(gateway, formatGatewayResult, config.experimental, queryTracer);
5685
7086
  const db = createDbModule({ from, rpc, query });
5686
- return {
7087
+ const sdkClient = {
5687
7088
  from,
5688
7089
  db,
5689
7090
  rpc,
@@ -5691,6 +7092,14 @@ function createClientFromConfig(config) {
5691
7092
  verifyConnection: gateway.verifyConnection,
5692
7093
  auth: auth.auth
5693
7094
  };
7095
+ if (config.experimental?.athenaStorageBackend) {
7096
+ const storageClient = {
7097
+ ...sdkClient,
7098
+ storage: createStorageModule(gateway, config.experimental.storage)
7099
+ };
7100
+ return storageClient;
7101
+ }
7102
+ return sdkClient;
5694
7103
  }
5695
7104
  var DEFAULT_BACKEND = { type: "athena" };
5696
7105
  function toBackendConfig(b) {