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