@layr-labs/ecloud-sdk 0.3.3 → 0.3.4

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/compute.js CHANGED
@@ -4422,7 +4422,7 @@ async function undelegate(options, logger = noopLogger) {
4422
4422
  }
4423
4423
 
4424
4424
  // src/client/common/utils/userapi.ts
4425
- import axios from "axios";
4425
+ import axios2 from "axios";
4426
4426
 
4427
4427
  // src/client/common/utils/auth.ts
4428
4428
  import { parseAbi } from "viem";
@@ -4448,6 +4448,41 @@ async function calculatePermissionSignature(options) {
4448
4448
  return { signature, digest };
4449
4449
  }
4450
4450
 
4451
+ // src/client/common/utils/retry.ts
4452
+ import axios from "axios";
4453
+ var MAX_RETRIES = 5;
4454
+ var INITIAL_BACKOFF_MS = 1e3;
4455
+ var MAX_BACKOFF_MS = 3e4;
4456
+ function sleep(ms) {
4457
+ return new Promise((resolve2) => setTimeout(resolve2, ms));
4458
+ }
4459
+ function getRetryDelay(res, attempt) {
4460
+ const backoff = Math.min(INITIAL_BACKOFF_MS * Math.pow(2, attempt), MAX_BACKOFF_MS);
4461
+ const retryAfter = res.headers["retry-after"];
4462
+ if (retryAfter) {
4463
+ const seconds = parseInt(retryAfter, 10);
4464
+ if (!isNaN(seconds) && seconds > 0) {
4465
+ return Math.min(seconds * 1e3, MAX_BACKOFF_MS);
4466
+ }
4467
+ }
4468
+ return backoff;
4469
+ }
4470
+ async function requestWithRetry(config) {
4471
+ let lastResponse;
4472
+ for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
4473
+ const res = await axios({ ...config, validateStatus: () => true });
4474
+ lastResponse = res;
4475
+ if (res.status !== 429) {
4476
+ return res;
4477
+ }
4478
+ if (attempt < MAX_RETRIES) {
4479
+ const delay = getRetryDelay(res, attempt);
4480
+ await sleep(delay);
4481
+ }
4482
+ }
4483
+ return lastResponse;
4484
+ }
4485
+
4451
4486
  // src/client/common/utils/userapi.ts
4452
4487
  init_session();
4453
4488
  function isJsonObject(value) {
@@ -4466,7 +4501,7 @@ var CanViewAppLogsPermission = "0x2fd3f2fe";
4466
4501
  var CanViewSensitiveAppInfoPermission = "0x0e67b22f";
4467
4502
  var CanUpdateAppProfilePermission = "0x036fef61";
4468
4503
  function getDefaultClientId() {
4469
- const version = true ? "0.3.3" : "0.0.0";
4504
+ const version = true ? "0.3.4" : "0.0.0";
4470
4505
  return `ecloud-sdk/v${version}`;
4471
4506
  }
4472
4507
  var UserApiClient = class {
@@ -4601,7 +4636,7 @@ var UserApiClient = class {
4601
4636
  Object.assign(headers, authHeaders);
4602
4637
  }
4603
4638
  try {
4604
- const response = await axios.post(endpoint, formData, {
4639
+ const response = await axios2.post(endpoint, formData, {
4605
4640
  headers,
4606
4641
  maxRedirects: 0,
4607
4642
  validateStatus: () => true,
@@ -4651,11 +4686,11 @@ Please check:
4651
4686
  Object.assign(headers, authHeaders);
4652
4687
  }
4653
4688
  try {
4654
- const response = await axios.get(url, {
4689
+ const response = await requestWithRetry({
4690
+ method: "GET",
4691
+ url,
4655
4692
  headers,
4656
4693
  maxRedirects: 0,
4657
- validateStatus: () => true,
4658
- // Don't throw on any status
4659
4694
  withCredentials: true
4660
4695
  // Include cookies for session auth
4661
4696
  });
@@ -4839,7 +4874,7 @@ async function watchUntilRunning(options, logger) {
4839
4874
  try {
4840
4875
  const info = await userApiClient.getInfos([appId], 1);
4841
4876
  if (info.length === 0) {
4842
- await sleep(WATCH_POLL_INTERVAL_SECONDS * 1e3);
4877
+ await sleep2(WATCH_POLL_INTERVAL_SECONDS * 1e3);
4843
4878
  continue;
4844
4879
  }
4845
4880
  const appInfo = info[0];
@@ -4848,10 +4883,10 @@ async function watchUntilRunning(options, logger) {
4848
4883
  if (stopCondition(currentStatus, currentIP)) {
4849
4884
  return currentIP || void 0;
4850
4885
  }
4851
- await sleep(WATCH_POLL_INTERVAL_SECONDS * 1e3);
4886
+ await sleep2(WATCH_POLL_INTERVAL_SECONDS * 1e3);
4852
4887
  } catch (error) {
4853
4888
  logger.warn(`Failed to fetch app info: ${error.message}`);
4854
- await sleep(WATCH_POLL_INTERVAL_SECONDS * 1e3);
4889
+ await sleep2(WATCH_POLL_INTERVAL_SECONDS * 1e3);
4855
4890
  }
4856
4891
  }
4857
4892
  }
@@ -4899,7 +4934,7 @@ async function watchUntilUpgradeComplete(options, logger) {
4899
4934
  try {
4900
4935
  const info = await userApiClient.getInfos([appId], 1);
4901
4936
  if (info.length === 0) {
4902
- await sleep(WATCH_POLL_INTERVAL_SECONDS * 1e3);
4937
+ await sleep2(WATCH_POLL_INTERVAL_SECONDS * 1e3);
4903
4938
  continue;
4904
4939
  }
4905
4940
  const appInfo = info[0];
@@ -4908,14 +4943,14 @@ async function watchUntilUpgradeComplete(options, logger) {
4908
4943
  if (stopCondition(currentStatus, currentIP)) {
4909
4944
  return;
4910
4945
  }
4911
- await sleep(WATCH_POLL_INTERVAL_SECONDS * 1e3);
4946
+ await sleep2(WATCH_POLL_INTERVAL_SECONDS * 1e3);
4912
4947
  } catch (error) {
4913
4948
  logger.warn(`Failed to fetch app info: ${error.message}`);
4914
- await sleep(WATCH_POLL_INTERVAL_SECONDS * 1e3);
4949
+ await sleep2(WATCH_POLL_INTERVAL_SECONDS * 1e3);
4915
4950
  }
4916
4951
  }
4917
4952
  }
4918
- function sleep(ms) {
4953
+ function sleep2(ms) {
4919
4954
  return new Promise((resolve2) => setTimeout(resolve2, ms));
4920
4955
  }
4921
4956
 
@@ -5139,7 +5174,7 @@ var getLogger = (verbose) => ({
5139
5174
  });
5140
5175
 
5141
5176
  // src/client/common/utils/billingapi.ts
5142
- import axios2 from "axios";
5177
+ import axios3 from "axios";
5143
5178
 
5144
5179
  // src/client/common/telemetry/noop.ts
5145
5180
  var NoopClient = class {