@layr-labs/ecloud-sdk 1.0.0-devep1 → 1.0.0-devep3

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/VERSION CHANGED
@@ -1,2 +1,2 @@
1
- version=1.0.0-devep1
2
- commit=b210c1e7e17be9d0847834901bd986b0a3742456
1
+ version=1.0.0-devep3
2
+ commit=ae7213bb77bd5448778a2774d92c43d3d9a7cb67
package/dist/billing.cjs CHANGED
@@ -317,6 +317,20 @@ var BillingApiClient = class {
317
317
  const endpoint = `${this.config.billingApiServerURL}/products/${productId}/subscription`;
318
318
  await this.makeAuthenticatedRequest(endpoint, "DELETE", productId);
319
319
  }
320
+ async getPaymentMethods() {
321
+ const endpoint = `${this.config.billingApiServerURL}/v1/payment-methods`;
322
+ const resp = await this.makeAuthenticatedRequest(endpoint, "GET", "compute");
323
+ return resp.json();
324
+ }
325
+ async purchaseCredits(amountCents, paymentMethodId) {
326
+ const endpoint = `${this.config.billingApiServerURL}/v1/credits/purchase`;
327
+ const body = { amountCents };
328
+ if (paymentMethodId) {
329
+ body.paymentMethodId = paymentMethodId;
330
+ }
331
+ const resp = await this.makeAuthenticatedRequest(endpoint, "POST", "compute", body);
332
+ return resp.json();
333
+ }
320
334
  // ==========================================================================
321
335
  // Internal Methods
322
336
  // ==========================================================================
@@ -326,10 +340,22 @@ var BillingApiClient = class {
326
340
  * Uses session auth if useSession is true, otherwise uses EIP-712 signature auth.
327
341
  */
328
342
  async makeAuthenticatedRequest(url, method, productId, body) {
329
- if (this.useSession) {
330
- return this.makeSessionAuthenticatedRequest(url, method, body);
343
+ if (this.options.verbose) {
344
+ console.debug(`[BillingAPI] ${method} ${url}`);
345
+ if (body) {
346
+ console.debug(`[BillingAPI] Payload:`, JSON.stringify(body, null, 2));
347
+ }
348
+ }
349
+ const resp = this.useSession ? await this.makeSessionAuthenticatedRequest(url, method, body) : await this.makeSignatureAuthenticatedRequest(url, method, productId, body);
350
+ if (this.options.verbose) {
351
+ const data = await resp.json();
352
+ console.debug(`[BillingAPI] Response:`, JSON.stringify(data, null, 2));
353
+ return {
354
+ json: async () => data,
355
+ text: async () => JSON.stringify(data)
356
+ };
331
357
  }
332
- return this.makeSignatureAuthenticatedRequest(url, method, productId, body);
358
+ return resp;
333
359
  }
334
360
  /**
335
361
  * Make a request using session-based authentication (cookies)
@@ -456,6 +482,9 @@ var BILLING_ENVIRONMENTS = {
456
482
  billingApiServerURL: "https://billingapi.eigencloud.xyz"
457
483
  }
458
484
  };
485
+ var PLATFORM_ENV_TESTNET_SEPOLIA = "testnet-sepolia";
486
+ var PLATFORM_ENV_MAINNET_ETHEREUM = "mainnet-ethereum";
487
+ var DEFAULT_APP_BASE_DOMAIN = "eigencloud.xyz";
459
488
  var ENVIRONMENTS = {
460
489
  "sepolia-dev": {
461
490
  name: "sepolia",
@@ -466,7 +495,9 @@ var ENVIRONMENTS = {
466
495
  kmsServerURL: "http://10.128.0.57:8080",
467
496
  userApiServerURL: "https://userapi-compute-sepolia-dev.eigencloud.xyz",
468
497
  defaultRPCURL: "https://ethereum-sepolia-rpc.publicnode.com",
469
- usdcCreditsAddress: "0xbdA3897c3A428763B59015C64AB766c288C97376"
498
+ usdcCreditsAddress: "0xbdA3897c3A428763B59015C64AB766c288C97376",
499
+ platformEnv: PLATFORM_ENV_TESTNET_SEPOLIA,
500
+ appBaseDomain: DEFAULT_APP_BASE_DOMAIN
470
501
  },
471
502
  sepolia: {
472
503
  name: "sepolia",
@@ -478,7 +509,9 @@ var ENVIRONMENTS = {
478
509
  userApiServerURL: "https://userapi-compute-sepolia-prod.eigencloud.xyz",
479
510
  defaultRPCURL: "https://ethereum-sepolia-rpc.publicnode.com",
480
511
  billingRPCURL: "https://ethereum-rpc.publicnode.com",
481
- usdcCreditsAddress: "0xed9c88640ca9149Bd9f7ee6620074af10F2E145d"
512
+ usdcCreditsAddress: "0xed9c88640ca9149Bd9f7ee6620074af10F2E145d",
513
+ platformEnv: PLATFORM_ENV_TESTNET_SEPOLIA,
514
+ appBaseDomain: DEFAULT_APP_BASE_DOMAIN
482
515
  },
483
516
  "mainnet-alpha": {
484
517
  name: "mainnet-alpha",
@@ -489,7 +522,9 @@ var ENVIRONMENTS = {
489
522
  kmsServerURL: "http://10.128.0.2:8080",
490
523
  userApiServerURL: "https://userapi-compute.eigencloud.xyz",
491
524
  defaultRPCURL: "https://ethereum-rpc.publicnode.com",
492
- usdcCreditsAddress: "0xed9c88640ca9149Bd9f7ee6620074af10F2E145d"
525
+ usdcCreditsAddress: "0xed9c88640ca9149Bd9f7ee6620074af10F2E145d",
526
+ platformEnv: PLATFORM_ENV_MAINNET_ETHEREUM,
527
+ appBaseDomain: DEFAULT_APP_BASE_DOMAIN
493
528
  }
494
529
  };
495
530
  var CHAIN_ID_TO_ENVIRONMENT = {
@@ -523,7 +558,13 @@ function getEnvironmentConfig(environment, chainID) {
523
558
  return {
524
559
  ...env,
525
560
  chainID: BigInt(resolvedChainID),
526
- ...apiUrlOverride ? { userApiServerURL: apiUrlOverride } : {}
561
+ ...apiUrlOverride ? { userApiServerURL: apiUrlOverride } : {},
562
+ ...process.env.ECLOUD_USER_API_URL && {
563
+ userApiServerURL: process.env.ECLOUD_USER_API_URL
564
+ },
565
+ ...process.env.ECLOUD_RPC_URL && {
566
+ defaultRPCURL: process.env.ECLOUD_RPC_URL
567
+ }
527
568
  };
528
569
  }
529
570
  function getBillingEnvironmentConfig(build) {
@@ -535,7 +576,12 @@ function getBillingEnvironmentConfig(build) {
535
576
  if (apiUrlOverride) {
536
577
  return { billingApiServerURL: apiUrlOverride };
537
578
  }
538
- return config;
579
+ return {
580
+ ...config,
581
+ ...process.env.ECLOUD_BILLING_API_URL && {
582
+ billingApiServerURL: process.env.ECLOUD_BILLING_API_URL
583
+ }
584
+ };
539
585
  }
540
586
  function getBuildType() {
541
587
  const buildTimeType = true ? "dev"?.toLowerCase() : void 0;
@@ -2078,7 +2124,7 @@ function createBillingModule(config) {
2078
2124
  const address = walletClient.account.address;
2079
2125
  const logger = getLogger(verbose);
2080
2126
  const billingEnvConfig = getBillingEnvironmentConfig(getBuildType());
2081
- const billingApi = new BillingApiClient(billingEnvConfig, walletClient);
2127
+ const billingApi = new BillingApiClient(billingEnvConfig, walletClient, { verbose });
2082
2128
  const environmentConfig = getEnvironmentConfig(environment);
2083
2129
  const usdcCreditsAddress = environmentConfig.usdcCreditsAddress;
2084
2130
  if (!usdcCreditsAddress) {
@@ -2242,6 +2288,12 @@ function createBillingModule(config) {
2242
2288
  };
2243
2289
  }
2244
2290
  );
2291
+ },
2292
+ async getPaymentMethods() {
2293
+ return billingApi.getPaymentMethods();
2294
+ },
2295
+ async purchaseCredits(amountCents, paymentMethodId) {
2296
+ return billingApi.purchaseCredits(amountCents, paymentMethodId);
2245
2297
  }
2246
2298
  };
2247
2299
  return module2;