@layr-labs/ecloud-sdk 0.2.2-dev → 0.3.0-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,3 +1,137 @@
1
+ var __getOwnPropNames = Object.getOwnPropertyNames;
2
+ var __esm = (fn, res) => function __init() {
3
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
4
+ };
5
+
6
+ // src/client/common/auth/session.ts
7
+ function stripHexPrefix2(hex) {
8
+ return hex.startsWith("0x") ? hex.slice(2) : hex;
9
+ }
10
+ async function parseErrorResponse(response) {
11
+ try {
12
+ const data = await response.json();
13
+ return data.error || response.statusText;
14
+ } catch {
15
+ return response.statusText;
16
+ }
17
+ }
18
+ async function loginToComputeApi(config, request) {
19
+ let response;
20
+ try {
21
+ response = await fetch(`${config.baseUrl}/auth/siwe/login`, {
22
+ method: "POST",
23
+ credentials: "include",
24
+ // Include cookies for session management
25
+ headers: {
26
+ "Content-Type": "application/json"
27
+ },
28
+ body: JSON.stringify({
29
+ message: request.message,
30
+ signature: stripHexPrefix2(request.signature)
31
+ })
32
+ });
33
+ } catch (error) {
34
+ throw new SessionError(
35
+ `Network error connecting to ${config.baseUrl}: ${error instanceof Error ? error.message : String(error)}`,
36
+ "NETWORK_ERROR"
37
+ );
38
+ }
39
+ if (!response.ok) {
40
+ const errorMessage = await parseErrorResponse(response);
41
+ const status = response.status;
42
+ if (status === 400) {
43
+ if (errorMessage.toLowerCase().includes("siwe")) {
44
+ throw new SessionError(`Invalid SIWE message: ${errorMessage}`, "INVALID_MESSAGE", status);
45
+ }
46
+ throw new SessionError(`Bad request: ${errorMessage}`, "INVALID_MESSAGE", status);
47
+ }
48
+ if (status === 401) {
49
+ throw new SessionError(`Invalid signature: ${errorMessage}`, "INVALID_SIGNATURE", status);
50
+ }
51
+ throw new SessionError(`Login failed: ${errorMessage}`, "UNKNOWN", status);
52
+ }
53
+ const data = await response.json();
54
+ return {
55
+ success: data.success,
56
+ address: data.address
57
+ };
58
+ }
59
+ async function getComputeApiSession(config) {
60
+ let response;
61
+ try {
62
+ response = await fetch(`${config.baseUrl}/auth/session`, {
63
+ method: "GET",
64
+ credentials: "include",
65
+ // Include cookies for session management
66
+ headers: {
67
+ "Content-Type": "application/json"
68
+ }
69
+ });
70
+ } catch {
71
+ return {
72
+ authenticated: false
73
+ };
74
+ }
75
+ if (response.status === 401) {
76
+ return {
77
+ authenticated: false
78
+ };
79
+ }
80
+ if (!response.ok) {
81
+ const errorMessage = await parseErrorResponse(response);
82
+ throw new SessionError(`Failed to get session: ${errorMessage}`, "UNKNOWN", response.status);
83
+ }
84
+ const data = await response.json();
85
+ return {
86
+ authenticated: data.authenticated,
87
+ address: data.address,
88
+ chainId: data.chain_id
89
+ };
90
+ }
91
+ async function logoutFromComputeApi(config) {
92
+ let response;
93
+ try {
94
+ response = await fetch(`${config.baseUrl}/auth/logout`, {
95
+ method: "POST",
96
+ credentials: "include",
97
+ // Include cookies for session management
98
+ headers: {
99
+ "Content-Type": "application/json"
100
+ }
101
+ });
102
+ } catch (error) {
103
+ throw new SessionError(
104
+ `Network error connecting to ${config.baseUrl}: ${error instanceof Error ? error.message : String(error)}`,
105
+ "NETWORK_ERROR"
106
+ );
107
+ }
108
+ if (response.status === 401) {
109
+ return;
110
+ }
111
+ if (!response.ok) {
112
+ const errorMessage = await parseErrorResponse(response);
113
+ throw new SessionError(`Logout failed: ${errorMessage}`, "UNKNOWN", response.status);
114
+ }
115
+ }
116
+ async function isSessionValid(config) {
117
+ const session = await getComputeApiSession(config);
118
+ return session.authenticated;
119
+ }
120
+ var SessionError;
121
+ var init_session = __esm({
122
+ "src/client/common/auth/session.ts"() {
123
+ "use strict";
124
+ SessionError = class extends Error {
125
+ constructor(message, code, statusCode) {
126
+ super(message);
127
+ this.code = code;
128
+ this.statusCode = statusCode;
129
+ this.name = "SessionError";
130
+ }
131
+ };
132
+ }
133
+ });
134
+
1
135
  // src/client/modules/compute/app/index.ts
2
136
  import { parseAbi as parseAbi2, encodeFunctionData as encodeFunctionData3 } from "viem";
3
137
 
@@ -4413,130 +4547,8 @@ async function calculateBillingAuthSignature(options) {
4413
4547
  return { signature, expiry };
4414
4548
  }
4415
4549
 
4416
- // src/client/common/auth/session.ts
4417
- var SessionError = class extends Error {
4418
- constructor(message, code, statusCode) {
4419
- super(message);
4420
- this.code = code;
4421
- this.statusCode = statusCode;
4422
- this.name = "SessionError";
4423
- }
4424
- };
4425
- function stripHexPrefix2(hex) {
4426
- return hex.startsWith("0x") ? hex.slice(2) : hex;
4427
- }
4428
- async function parseErrorResponse(response) {
4429
- try {
4430
- const data = await response.json();
4431
- return data.error || response.statusText;
4432
- } catch {
4433
- return response.statusText;
4434
- }
4435
- }
4436
- async function loginToComputeApi(config, request) {
4437
- let response;
4438
- try {
4439
- response = await fetch(`${config.baseUrl}/auth/siwe/login`, {
4440
- method: "POST",
4441
- credentials: "include",
4442
- // Include cookies for session management
4443
- headers: {
4444
- "Content-Type": "application/json"
4445
- },
4446
- body: JSON.stringify({
4447
- message: request.message,
4448
- signature: stripHexPrefix2(request.signature)
4449
- })
4450
- });
4451
- } catch (error) {
4452
- throw new SessionError(
4453
- `Network error connecting to ${config.baseUrl}: ${error instanceof Error ? error.message : String(error)}`,
4454
- "NETWORK_ERROR"
4455
- );
4456
- }
4457
- if (!response.ok) {
4458
- const errorMessage = await parseErrorResponse(response);
4459
- const status = response.status;
4460
- if (status === 400) {
4461
- if (errorMessage.toLowerCase().includes("siwe")) {
4462
- throw new SessionError(`Invalid SIWE message: ${errorMessage}`, "INVALID_MESSAGE", status);
4463
- }
4464
- throw new SessionError(`Bad request: ${errorMessage}`, "INVALID_MESSAGE", status);
4465
- }
4466
- if (status === 401) {
4467
- throw new SessionError(`Invalid signature: ${errorMessage}`, "INVALID_SIGNATURE", status);
4468
- }
4469
- throw new SessionError(`Login failed: ${errorMessage}`, "UNKNOWN", status);
4470
- }
4471
- const data = await response.json();
4472
- return {
4473
- success: data.success,
4474
- address: data.address
4475
- };
4476
- }
4477
- async function getComputeApiSession(config) {
4478
- let response;
4479
- try {
4480
- response = await fetch(`${config.baseUrl}/auth/session`, {
4481
- method: "GET",
4482
- credentials: "include",
4483
- // Include cookies for session management
4484
- headers: {
4485
- "Content-Type": "application/json"
4486
- }
4487
- });
4488
- } catch {
4489
- return {
4490
- authenticated: false
4491
- };
4492
- }
4493
- if (response.status === 401) {
4494
- return {
4495
- authenticated: false
4496
- };
4497
- }
4498
- if (!response.ok) {
4499
- const errorMessage = await parseErrorResponse(response);
4500
- throw new SessionError(`Failed to get session: ${errorMessage}`, "UNKNOWN", response.status);
4501
- }
4502
- const data = await response.json();
4503
- return {
4504
- authenticated: data.authenticated,
4505
- address: data.address,
4506
- chainId: data.chain_id
4507
- };
4508
- }
4509
- async function logoutFromComputeApi(config) {
4510
- let response;
4511
- try {
4512
- response = await fetch(`${config.baseUrl}/auth/logout`, {
4513
- method: "POST",
4514
- credentials: "include",
4515
- // Include cookies for session management
4516
- headers: {
4517
- "Content-Type": "application/json"
4518
- }
4519
- });
4520
- } catch (error) {
4521
- throw new SessionError(
4522
- `Network error connecting to ${config.baseUrl}: ${error instanceof Error ? error.message : String(error)}`,
4523
- "NETWORK_ERROR"
4524
- );
4525
- }
4526
- if (response.status === 401) {
4527
- return;
4528
- }
4529
- if (!response.ok) {
4530
- const errorMessage = await parseErrorResponse(response);
4531
- throw new SessionError(`Logout failed: ${errorMessage}`, "UNKNOWN", response.status);
4532
- }
4533
- }
4534
- async function isSessionValid(config) {
4535
- const session = await getComputeApiSession(config);
4536
- return session.authenticated;
4537
- }
4538
-
4539
4550
  // src/client/common/utils/userapi.ts
4551
+ init_session();
4540
4552
  function isJsonObject(value) {
4541
4553
  return typeof value === "object" && value !== null && !Array.isArray(value);
4542
4554
  }
@@ -4553,7 +4565,7 @@ var CanViewAppLogsPermission = "0x2fd3f2fe";
4553
4565
  var CanViewSensitiveAppInfoPermission = "0x0e67b22f";
4554
4566
  var CanUpdateAppProfilePermission = "0x036fef61";
4555
4567
  function getDefaultClientId() {
4556
- const version = true ? "0.2.2-dev" : "0.0.0";
4568
+ const version = true ? "0.3.0-dev" : "0.0.0";
4557
4569
  return `ecloud-sdk/v${version}`;
4558
4570
  }
4559
4571
  var UserApiClient = class {
@@ -5461,21 +5473,214 @@ function isSubscriptionActive(status) {
5461
5473
 
5462
5474
  // src/client/common/utils/billingapi.ts
5463
5475
  import axios2 from "axios";
5476
+
5477
+ // src/client/common/auth/billingSession.ts
5478
+ var BillingSessionError = class extends Error {
5479
+ constructor(message, code, statusCode) {
5480
+ super(message);
5481
+ this.code = code;
5482
+ this.statusCode = statusCode;
5483
+ this.name = "BillingSessionError";
5484
+ }
5485
+ };
5486
+ function stripHexPrefix3(hex) {
5487
+ return hex.startsWith("0x") ? hex.slice(2) : hex;
5488
+ }
5489
+ async function parseErrorResponse2(response) {
5490
+ try {
5491
+ const data = await response.json();
5492
+ return data.error || response.statusText;
5493
+ } catch {
5494
+ return response.statusText;
5495
+ }
5496
+ }
5497
+ async function loginToBillingApi(config, request) {
5498
+ let response;
5499
+ try {
5500
+ response = await fetch(`${config.baseUrl}/auth/siwe/login`, {
5501
+ method: "POST",
5502
+ credentials: "include",
5503
+ // Include cookies for session management
5504
+ headers: {
5505
+ "Content-Type": "application/json"
5506
+ },
5507
+ body: JSON.stringify({
5508
+ message: request.message,
5509
+ signature: stripHexPrefix3(request.signature)
5510
+ })
5511
+ });
5512
+ } catch (error) {
5513
+ throw new BillingSessionError(
5514
+ `Network error connecting to ${config.baseUrl}: ${error instanceof Error ? error.message : String(error)}`,
5515
+ "NETWORK_ERROR"
5516
+ );
5517
+ }
5518
+ if (!response.ok) {
5519
+ const errorMessage = await parseErrorResponse2(response);
5520
+ const status = response.status;
5521
+ if (status === 400) {
5522
+ if (errorMessage.toLowerCase().includes("siwe")) {
5523
+ throw new BillingSessionError(`Invalid SIWE message: ${errorMessage}`, "INVALID_MESSAGE", status);
5524
+ }
5525
+ throw new BillingSessionError(`Bad request: ${errorMessage}`, "INVALID_MESSAGE", status);
5526
+ }
5527
+ if (status === 401) {
5528
+ throw new BillingSessionError(`Invalid signature: ${errorMessage}`, "INVALID_SIGNATURE", status);
5529
+ }
5530
+ throw new BillingSessionError(`Login failed: ${errorMessage}`, "UNKNOWN", status);
5531
+ }
5532
+ const data = await response.json();
5533
+ return {
5534
+ success: data.success,
5535
+ address: data.address
5536
+ };
5537
+ }
5538
+ async function getBillingApiSession(config) {
5539
+ let response;
5540
+ try {
5541
+ response = await fetch(`${config.baseUrl}/auth/session`, {
5542
+ method: "GET",
5543
+ credentials: "include",
5544
+ // Include cookies for session management
5545
+ headers: {
5546
+ "Content-Type": "application/json"
5547
+ }
5548
+ });
5549
+ } catch {
5550
+ return {
5551
+ authenticated: false
5552
+ };
5553
+ }
5554
+ if (response.status === 401) {
5555
+ return {
5556
+ authenticated: false
5557
+ };
5558
+ }
5559
+ if (!response.ok) {
5560
+ const errorMessage = await parseErrorResponse2(response);
5561
+ throw new BillingSessionError(`Failed to get session: ${errorMessage}`, "UNKNOWN", response.status);
5562
+ }
5563
+ const data = await response.json();
5564
+ return {
5565
+ authenticated: data.authenticated,
5566
+ address: data.address,
5567
+ chainId: data.chainId,
5568
+ authenticatedAt: data.authenticatedAt
5569
+ };
5570
+ }
5571
+ async function logoutFromBillingApi(config) {
5572
+ let response;
5573
+ try {
5574
+ response = await fetch(`${config.baseUrl}/auth/logout`, {
5575
+ method: "POST",
5576
+ credentials: "include",
5577
+ // Include cookies for session management
5578
+ headers: {
5579
+ "Content-Type": "application/json"
5580
+ }
5581
+ });
5582
+ } catch (error) {
5583
+ throw new BillingSessionError(
5584
+ `Network error connecting to ${config.baseUrl}: ${error instanceof Error ? error.message : String(error)}`,
5585
+ "NETWORK_ERROR"
5586
+ );
5587
+ }
5588
+ if (response.status === 401) {
5589
+ return;
5590
+ }
5591
+ if (!response.ok) {
5592
+ const errorMessage = await parseErrorResponse2(response);
5593
+ throw new BillingSessionError(`Logout failed: ${errorMessage}`, "UNKNOWN", response.status);
5594
+ }
5595
+ }
5596
+
5597
+ // src/client/common/utils/billingapi.ts
5464
5598
  var BillingApiClient = class {
5465
- constructor(config, walletClient) {
5599
+ constructor(config, walletClient, options = {}) {
5466
5600
  this.config = config;
5467
5601
  this.walletClient = walletClient;
5602
+ this.options = options;
5603
+ this.useSession = options.useSession ?? false;
5604
+ if (!this.useSession && !walletClient) {
5605
+ throw new Error("WalletClient is required when not using session authentication");
5606
+ }
5468
5607
  }
5469
5608
  /**
5470
5609
  * Get the address of the connected wallet
5610
+ * Returns undefined if using session auth without a wallet client
5471
5611
  */
5472
5612
  get address() {
5473
- const account = this.walletClient.account;
5613
+ const account = this.walletClient?.account;
5474
5614
  if (!account) {
5475
- throw new Error("WalletClient must have an account attached");
5615
+ if (!this.useSession) {
5616
+ throw new Error("WalletClient must have an account attached");
5617
+ }
5618
+ return void 0;
5476
5619
  }
5477
5620
  return account.address;
5478
5621
  }
5622
+ /**
5623
+ * Get the base URL of the billing API
5624
+ */
5625
+ get baseUrl() {
5626
+ return this.config.billingApiServerURL;
5627
+ }
5628
+ // ==========================================================================
5629
+ // SIWE Session Methods
5630
+ // ==========================================================================
5631
+ /**
5632
+ * Login to the billing API using SIWE
5633
+ *
5634
+ * This establishes a session with the billing API by verifying the SIWE message
5635
+ * and signature. On success, a session cookie is set in the browser.
5636
+ *
5637
+ * @param request - Login request containing SIWE message and signature
5638
+ * @returns Login result with the authenticated address
5639
+ *
5640
+ * @example
5641
+ * ```typescript
5642
+ * const { message } = createSiweMessage({
5643
+ * address: userAddress,
5644
+ * chainId: 11155111,
5645
+ * domain: window.location.host,
5646
+ * uri: window.location.origin,
5647
+ * });
5648
+ *
5649
+ * const signature = await signMessageAsync({ message });
5650
+ * const result = await billingClient.siweLogin({ message, signature });
5651
+ * ```
5652
+ */
5653
+ async siweLogin(request) {
5654
+ return loginToBillingApi({ baseUrl: this.baseUrl }, request);
5655
+ }
5656
+ /**
5657
+ * Logout from the billing API
5658
+ *
5659
+ * This destroys the current session and clears the session cookie.
5660
+ */
5661
+ async siweLogout() {
5662
+ return logoutFromBillingApi({ baseUrl: this.baseUrl });
5663
+ }
5664
+ /**
5665
+ * Get the current session status from the billing API
5666
+ *
5667
+ * @returns Session information including authentication status and address
5668
+ */
5669
+ async getSession() {
5670
+ return getBillingApiSession({ baseUrl: this.baseUrl });
5671
+ }
5672
+ /**
5673
+ * Check if there is a valid session
5674
+ *
5675
+ * @returns True if session is authenticated, false otherwise
5676
+ */
5677
+ async isSessionValid() {
5678
+ const session = await this.getSession();
5679
+ return session.authenticated;
5680
+ }
5681
+ // ==========================================================================
5682
+ // Subscription Methods
5683
+ // ==========================================================================
5479
5684
  async createSubscription(productId = "compute", options) {
5480
5685
  const endpoint = `${this.config.billingApiServerURL}/products/${productId}/subscription`;
5481
5686
  const body = options ? {
@@ -5494,10 +5699,72 @@ var BillingApiClient = class {
5494
5699
  const endpoint = `${this.config.billingApiServerURL}/products/${productId}/subscription`;
5495
5700
  await this.makeAuthenticatedRequest(endpoint, "DELETE", productId);
5496
5701
  }
5702
+ // ==========================================================================
5703
+ // Internal Methods
5704
+ // ==========================================================================
5497
5705
  /**
5498
5706
  * Make an authenticated request to the billing API
5707
+ *
5708
+ * Uses session auth if useSession is true, otherwise uses EIP-712 signature auth.
5499
5709
  */
5500
5710
  async makeAuthenticatedRequest(url, method, productId, body) {
5711
+ if (this.useSession) {
5712
+ return this.makeSessionAuthenticatedRequest(url, method, body);
5713
+ }
5714
+ return this.makeSignatureAuthenticatedRequest(url, method, productId, body);
5715
+ }
5716
+ /**
5717
+ * Make a request using session-based authentication (cookies)
5718
+ */
5719
+ async makeSessionAuthenticatedRequest(url, method, body) {
5720
+ const headers = {};
5721
+ if (body) {
5722
+ headers["Content-Type"] = "application/json";
5723
+ }
5724
+ try {
5725
+ const response = await fetch(url, {
5726
+ method,
5727
+ credentials: "include",
5728
+ // Include cookies for session management
5729
+ headers,
5730
+ body: body ? JSON.stringify(body) : void 0
5731
+ });
5732
+ const status = response.status;
5733
+ const statusText = status >= 200 && status < 300 ? "OK" : "Error";
5734
+ if (status < 200 || status >= 300) {
5735
+ let errorBody;
5736
+ try {
5737
+ errorBody = await response.text();
5738
+ } catch {
5739
+ errorBody = statusText;
5740
+ }
5741
+ throw new Error(`BillingAPI request failed: ${status} ${statusText} - ${errorBody}`);
5742
+ }
5743
+ const responseData = await response.json();
5744
+ return {
5745
+ json: async () => responseData,
5746
+ text: async () => JSON.stringify(responseData)
5747
+ };
5748
+ } catch (error) {
5749
+ if (error.name === "TypeError" || error.message?.includes("fetch")) {
5750
+ throw new Error(
5751
+ `Failed to connect to BillingAPI at ${url}: ${error.message}
5752
+ Please check:
5753
+ 1. Your internet connection
5754
+ 2. The API server is accessible: ${this.config.billingApiServerURL}
5755
+ 3. Firewall/proxy settings`
5756
+ );
5757
+ }
5758
+ throw error;
5759
+ }
5760
+ }
5761
+ /**
5762
+ * Make a request using EIP-712 signature authentication
5763
+ */
5764
+ async makeSignatureAuthenticatedRequest(url, method, productId, body) {
5765
+ if (!this.walletClient) {
5766
+ throw new Error("WalletClient is required for signature authentication");
5767
+ }
5501
5768
  const expiry = BigInt(Math.floor(Date.now() / 1e3) + 5 * 60);
5502
5769
  const { signature } = await calculateBillingAuthSignature({
5503
5770
  walletClient: this.walletClient,
@@ -7512,7 +7779,10 @@ function createBillingModule(config) {
7512
7779
  };
7513
7780
  }
7514
7781
  logger.debug(`Creating subscription for ${productId}...`);
7515
- const result = await billingApi.createSubscription(productId);
7782
+ const result = await billingApi.createSubscription(productId, {
7783
+ successUrl: opts?.successUrl,
7784
+ cancelUrl: opts?.cancelUrl
7785
+ });
7516
7786
  logger.debug(`Checkout URL: ${result.checkoutUrl}`);
7517
7787
  return {
7518
7788
  type: "checkout_created",
@@ -7604,9 +7874,22 @@ async function requestWithRetry(config) {
7604
7874
  }
7605
7875
  var BuildApiClient = class {
7606
7876
  constructor(options) {
7607
- this.baseUrl = options.baseUrl.replace(/\/+$/, "");
7877
+ let url = options.baseUrl;
7878
+ while (url.endsWith("/")) {
7879
+ url = url.slice(0, -1);
7880
+ }
7881
+ this.baseUrl = url;
7608
7882
  this.clientId = options.clientId;
7609
7883
  this.walletClient = options.walletClient;
7884
+ this.useSession = options.useSession ?? false;
7885
+ this.billingSessionId = options.billingSessionId;
7886
+ }
7887
+ /**
7888
+ * Update the billing session ID.
7889
+ * Call this after logging into the billing API to enable session-based auth for builds.
7890
+ */
7891
+ setBillingSessionId(sessionId) {
7892
+ this.billingSessionId = sessionId;
7610
7893
  }
7611
7894
  /**
7612
7895
  * Get the address of the connected wallet
@@ -7618,8 +7901,17 @@ var BuildApiClient = class {
7618
7901
  }
7619
7902
  return account.address;
7620
7903
  }
7904
+ /**
7905
+ * Submit a new build request.
7906
+ * Supports two auth modes (session auth is tried first when billingSessionId is available):
7907
+ * 1. Session-based auth: X-Billing-Session header (forwarded billing_session cookie)
7908
+ * 2. Signature-based auth: Authorization + X-Account + X-eigenx-expiry headers (requires walletClient)
7909
+ */
7621
7910
  async submitBuild(payload) {
7622
- return this.authenticatedJsonRequest("/builds", "POST", payload);
7911
+ if (this.useSession && this.billingSessionId) {
7912
+ return this.billingSessionAuthJsonRequest("/builds", "POST", payload);
7913
+ }
7914
+ return this.signatureAuthJsonRequest("/builds", "POST", payload);
7623
7915
  }
7624
7916
  async getBuild(buildId) {
7625
7917
  return this.publicJsonRequest(`/builds/${encodeURIComponent(buildId)}`);
@@ -7630,8 +7922,11 @@ var BuildApiClient = class {
7630
7922
  async verify(identifier) {
7631
7923
  return this.publicJsonRequest(`/builds/verify/${encodeURIComponent(identifier)}`);
7632
7924
  }
7925
+ /**
7926
+ * Get build logs. Supports session auth (identity verification only, no billing check).
7927
+ */
7633
7928
  async getLogs(buildId) {
7634
- return this.authenticatedTextRequest(`/builds/${encodeURIComponent(buildId)}/logs`);
7929
+ return this.sessionOrSignatureTextRequest(`/builds/${encodeURIComponent(buildId)}/logs`);
7635
7930
  }
7636
7931
  async listBuilds(params) {
7637
7932
  const res = await requestWithRetry({
@@ -7639,7 +7934,9 @@ var BuildApiClient = class {
7639
7934
  method: "GET",
7640
7935
  params,
7641
7936
  headers: this.clientId ? { "x-client-id": this.clientId } : void 0,
7642
- timeout: 6e4
7937
+ timeout: 6e4,
7938
+ validateStatus: () => true,
7939
+ withCredentials: this.useSession
7643
7940
  });
7644
7941
  if (res.status < 200 || res.status >= 300) throw buildApiHttpError(res);
7645
7942
  return res.data;
@@ -7649,12 +7946,18 @@ var BuildApiClient = class {
7649
7946
  url: `${this.baseUrl}${path8}`,
7650
7947
  method: "GET",
7651
7948
  headers: this.clientId ? { "x-client-id": this.clientId } : void 0,
7652
- timeout: 6e4
7949
+ timeout: 6e4,
7950
+ validateStatus: () => true,
7951
+ withCredentials: this.useSession
7653
7952
  });
7654
7953
  if (res.status < 200 || res.status >= 300) throw buildApiHttpError(res);
7655
7954
  return res.data;
7656
7955
  }
7657
- async authenticatedJsonRequest(path8, method, body) {
7956
+ /**
7957
+ * Make a request that ALWAYS requires signature auth (for billing verification).
7958
+ * Used for endpoints like POST /builds that need to verify subscription status.
7959
+ */
7960
+ async signatureAuthJsonRequest(path8, method, body) {
7658
7961
  if (!this.walletClient?.account) {
7659
7962
  throw new Error("WalletClient with account required for authenticated requests");
7660
7963
  }
@@ -7676,32 +7979,69 @@ var BuildApiClient = class {
7676
7979
  method,
7677
7980
  headers,
7678
7981
  data: body,
7679
- timeout: 6e4
7982
+ timeout: 6e4,
7983
+ validateStatus: () => true,
7984
+ withCredentials: this.useSession
7680
7985
  });
7681
7986
  if (res.status < 200 || res.status >= 300) throw buildApiHttpError(res);
7682
7987
  return res.data;
7683
7988
  }
7684
- async authenticatedTextRequest(path8) {
7685
- if (!this.walletClient?.account) {
7686
- throw new Error("WalletClient with account required for authenticated requests");
7989
+ /**
7990
+ * Make a request using billing session auth (for billing verification without wallet signature).
7991
+ * Forwards the billing_session cookie value via X-Billing-Session header.
7992
+ * Used for endpoints that need to verify subscription status when using session-based auth.
7993
+ */
7994
+ async billingSessionAuthJsonRequest(path8, method, body) {
7995
+ if (!this.billingSessionId) {
7996
+ throw new Error("billingSessionId required for session-based billing auth");
7687
7997
  }
7688
- const headers = {};
7998
+ const headers = {
7999
+ "Content-Type": "application/json",
8000
+ "X-Billing-Session": this.billingSessionId
8001
+ };
7689
8002
  if (this.clientId) headers["x-client-id"] = this.clientId;
7690
- const expiry = BigInt(Math.floor(Date.now() / 1e3) + 60);
7691
- const { signature } = await calculateBillingAuthSignature({
7692
- walletClient: this.walletClient,
7693
- product: "compute",
7694
- expiry
8003
+ const res = await requestWithRetry({
8004
+ url: `${this.baseUrl}${path8}`,
8005
+ method,
8006
+ headers,
8007
+ data: body,
8008
+ timeout: 6e4,
8009
+ validateStatus: () => true,
8010
+ withCredentials: this.useSession
7695
8011
  });
7696
- headers.Authorization = `Bearer ${signature}`;
7697
- headers["X-eigenx-expiry"] = expiry.toString();
7698
- headers["X-Account"] = this.address;
8012
+ if (res.status < 200 || res.status >= 300) throw buildApiHttpError(res);
8013
+ return res.data;
8014
+ }
8015
+ /**
8016
+ * Make an authenticated request that can use session OR signature auth.
8017
+ * When useSession is true, relies on cookies for identity verification.
8018
+ * Used for endpoints that only need identity verification (not billing).
8019
+ */
8020
+ async sessionOrSignatureTextRequest(path8) {
8021
+ const headers = {};
8022
+ if (this.clientId) headers["x-client-id"] = this.clientId;
8023
+ if (!this.useSession) {
8024
+ if (!this.walletClient?.account) {
8025
+ throw new Error("WalletClient with account required for authenticated requests");
8026
+ }
8027
+ const expiry = BigInt(Math.floor(Date.now() / 1e3) + 60);
8028
+ const { signature } = await calculateBillingAuthSignature({
8029
+ walletClient: this.walletClient,
8030
+ product: "compute",
8031
+ expiry
8032
+ });
8033
+ headers.Authorization = `Bearer ${signature}`;
8034
+ headers["X-eigenx-expiry"] = expiry.toString();
8035
+ headers["X-Account"] = this.address;
8036
+ }
7699
8037
  const res = await requestWithRetry({
7700
8038
  url: `${this.baseUrl}${path8}`,
7701
8039
  method: "GET",
7702
8040
  headers,
7703
8041
  timeout: 6e4,
7704
- responseType: "text"
8042
+ responseType: "text",
8043
+ validateStatus: () => true,
8044
+ withCredentials: this.useSession
7705
8045
  });
7706
8046
  if (res.status < 200 || res.status >= 300) throw buildApiHttpError(res);
7707
8047
  return typeof res.data === "string" ? res.data : JSON.stringify(res.data);
@@ -8268,6 +8608,9 @@ function isSiweMessageNotYetValid(params) {
8268
8608
  return /* @__PURE__ */ new Date() < params.notBefore;
8269
8609
  }
8270
8610
 
8611
+ // src/client/common/auth/index.ts
8612
+ init_session();
8613
+
8271
8614
  // src/client/common/utils/instance.ts
8272
8615
  async function getCurrentInstanceType(preflightCtx, appID, logger, clientId) {
8273
8616
  try {