@layr-labs/ecloud-sdk 1.0.0-dev.2 → 1.0.0-dev.3

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-dev.2
2
- commit=44b22091b826ce951383ff8a7fb2136c010abb56
1
+ version=1.0.0-dev.3
2
+ commit=6bdd35bcdef2b55443165112b1eb91ff4cc06e27
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)
@@ -523,7 +549,13 @@ function getEnvironmentConfig(environment, chainID) {
523
549
  return {
524
550
  ...env,
525
551
  chainID: BigInt(resolvedChainID),
526
- ...apiUrlOverride ? { userApiServerURL: apiUrlOverride } : {}
552
+ ...apiUrlOverride ? { userApiServerURL: apiUrlOverride } : {},
553
+ ...process.env.ECLOUD_USER_API_URL && {
554
+ userApiServerURL: process.env.ECLOUD_USER_API_URL
555
+ },
556
+ ...process.env.ECLOUD_RPC_URL && {
557
+ defaultRPCURL: process.env.ECLOUD_RPC_URL
558
+ }
527
559
  };
528
560
  }
529
561
  function getBillingEnvironmentConfig(build) {
@@ -535,7 +567,12 @@ function getBillingEnvironmentConfig(build) {
535
567
  if (apiUrlOverride) {
536
568
  return { billingApiServerURL: apiUrlOverride };
537
569
  }
538
- return config;
570
+ return {
571
+ ...config,
572
+ ...process.env.ECLOUD_BILLING_API_URL && {
573
+ billingApiServerURL: process.env.ECLOUD_BILLING_API_URL
574
+ }
575
+ };
539
576
  }
540
577
  function getBuildType() {
541
578
  const buildTimeType = true ? "dev"?.toLowerCase() : void 0;
@@ -2078,7 +2115,7 @@ function createBillingModule(config) {
2078
2115
  const address = walletClient.account.address;
2079
2116
  const logger = getLogger(verbose);
2080
2117
  const billingEnvConfig = getBillingEnvironmentConfig(getBuildType());
2081
- const billingApi = new BillingApiClient(billingEnvConfig, walletClient);
2118
+ const billingApi = new BillingApiClient(billingEnvConfig, walletClient, { verbose });
2082
2119
  const environmentConfig = getEnvironmentConfig(environment);
2083
2120
  const usdcCreditsAddress = environmentConfig.usdcCreditsAddress;
2084
2121
  if (!usdcCreditsAddress) {
@@ -2242,6 +2279,12 @@ function createBillingModule(config) {
2242
2279
  };
2243
2280
  }
2244
2281
  );
2282
+ },
2283
+ async getPaymentMethods() {
2284
+ return billingApi.getPaymentMethods();
2285
+ },
2286
+ async purchaseCredits(amountCents, paymentMethodId) {
2287
+ return billingApi.purchaseCredits(amountCents, paymentMethodId);
2245
2288
  }
2246
2289
  };
2247
2290
  return module2;