@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 +2 -2
- package/dist/billing.cjs +49 -6
- package/dist/billing.cjs.map +1 -1
- package/dist/billing.d.cts +3 -1
- package/dist/billing.d.ts +3 -1
- package/dist/billing.js +49 -6
- package/dist/billing.js.map +1 -1
- package/dist/browser.cjs +43 -6
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +4 -4
- package/dist/browser.d.ts +4 -4
- package/dist/browser.js +43 -6
- package/dist/browser.js.map +1 -1
- package/dist/{compute-Cnw6rwSB.d.ts → compute-BbgMH6Ef.d.ts} +1 -1
- package/dist/{compute-Ckyn8ils.d.cts → compute-yAqGf5hM.d.cts} +1 -1
- package/dist/compute.cjs +8 -2
- package/dist/compute.cjs.map +1 -1
- package/dist/compute.d.cts +2 -2
- package/dist/compute.d.ts +2 -2
- package/dist/compute.js +8 -2
- package/dist/compute.js.map +1 -1
- package/dist/{helpers-Dj2ME5rp.d.ts → helpers-CnlJ5yPE.d.cts} +5 -1
- package/dist/{helpers-DZL2bg9p.d.cts → helpers-GWlLS3gz.d.ts} +5 -1
- package/dist/{index-U2vKBrry.d.cts → index-Bac4HjC0.d.cts} +17 -1
- package/dist/{index-U2vKBrry.d.ts → index-Bac4HjC0.d.ts} +17 -1
- package/dist/index.cjs +50 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +50 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/billing.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Address, Hex, WalletClient, PublicClient } from 'viem';
|
|
2
|
-
import {
|
|
2
|
+
import { a6 as SubscriptionOpts, a4 as SubscribeResponse, a0 as ProductSubscriptionResponse, g as CancelResponse, M as PaymentMethodsResponse, m as CreditPurchaseResponse } from './index-Bac4HjC0.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Main Billing namespace entry point
|
|
@@ -33,6 +33,8 @@ interface BillingModule {
|
|
|
33
33
|
getTopUpInfo: () => Promise<TopUpInfo>;
|
|
34
34
|
/** Purchase credits with USDC on-chain */
|
|
35
35
|
topUp: (opts: TopUpOpts) => Promise<TopUpResult>;
|
|
36
|
+
getPaymentMethods: () => Promise<PaymentMethodsResponse>;
|
|
37
|
+
purchaseCredits: (amountCents: number, paymentMethodId?: string) => Promise<CreditPurchaseResponse>;
|
|
36
38
|
}
|
|
37
39
|
interface BillingModuleConfig {
|
|
38
40
|
verbose?: boolean;
|
package/dist/billing.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Address, Hex, WalletClient, PublicClient } from 'viem';
|
|
2
|
-
import {
|
|
2
|
+
import { a6 as SubscriptionOpts, a4 as SubscribeResponse, a0 as ProductSubscriptionResponse, g as CancelResponse, M as PaymentMethodsResponse, m as CreditPurchaseResponse } from './index-Bac4HjC0.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Main Billing namespace entry point
|
|
@@ -33,6 +33,8 @@ interface BillingModule {
|
|
|
33
33
|
getTopUpInfo: () => Promise<TopUpInfo>;
|
|
34
34
|
/** Purchase credits with USDC on-chain */
|
|
35
35
|
topUp: (opts: TopUpOpts) => Promise<TopUpResult>;
|
|
36
|
+
getPaymentMethods: () => Promise<PaymentMethodsResponse>;
|
|
37
|
+
purchaseCredits: (amountCents: number, paymentMethodId?: string) => Promise<CreditPurchaseResponse>;
|
|
36
38
|
}
|
|
37
39
|
interface BillingModuleConfig {
|
|
38
40
|
verbose?: boolean;
|
package/dist/billing.js
CHANGED
|
@@ -283,6 +283,20 @@ var BillingApiClient = class {
|
|
|
283
283
|
const endpoint = `${this.config.billingApiServerURL}/products/${productId}/subscription`;
|
|
284
284
|
await this.makeAuthenticatedRequest(endpoint, "DELETE", productId);
|
|
285
285
|
}
|
|
286
|
+
async getPaymentMethods() {
|
|
287
|
+
const endpoint = `${this.config.billingApiServerURL}/v1/payment-methods`;
|
|
288
|
+
const resp = await this.makeAuthenticatedRequest(endpoint, "GET", "compute");
|
|
289
|
+
return resp.json();
|
|
290
|
+
}
|
|
291
|
+
async purchaseCredits(amountCents, paymentMethodId) {
|
|
292
|
+
const endpoint = `${this.config.billingApiServerURL}/v1/credits/purchase`;
|
|
293
|
+
const body = { amountCents };
|
|
294
|
+
if (paymentMethodId) {
|
|
295
|
+
body.paymentMethodId = paymentMethodId;
|
|
296
|
+
}
|
|
297
|
+
const resp = await this.makeAuthenticatedRequest(endpoint, "POST", "compute", body);
|
|
298
|
+
return resp.json();
|
|
299
|
+
}
|
|
286
300
|
// ==========================================================================
|
|
287
301
|
// Internal Methods
|
|
288
302
|
// ==========================================================================
|
|
@@ -292,10 +306,22 @@ var BillingApiClient = class {
|
|
|
292
306
|
* Uses session auth if useSession is true, otherwise uses EIP-712 signature auth.
|
|
293
307
|
*/
|
|
294
308
|
async makeAuthenticatedRequest(url, method, productId, body) {
|
|
295
|
-
if (this.
|
|
296
|
-
|
|
309
|
+
if (this.options.verbose) {
|
|
310
|
+
console.debug(`[BillingAPI] ${method} ${url}`);
|
|
311
|
+
if (body) {
|
|
312
|
+
console.debug(`[BillingAPI] Payload:`, JSON.stringify(body, null, 2));
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
const resp = this.useSession ? await this.makeSessionAuthenticatedRequest(url, method, body) : await this.makeSignatureAuthenticatedRequest(url, method, productId, body);
|
|
316
|
+
if (this.options.verbose) {
|
|
317
|
+
const data = await resp.json();
|
|
318
|
+
console.debug(`[BillingAPI] Response:`, JSON.stringify(data, null, 2));
|
|
319
|
+
return {
|
|
320
|
+
json: async () => data,
|
|
321
|
+
text: async () => JSON.stringify(data)
|
|
322
|
+
};
|
|
297
323
|
}
|
|
298
|
-
return
|
|
324
|
+
return resp;
|
|
299
325
|
}
|
|
300
326
|
/**
|
|
301
327
|
* Make a request using session-based authentication (cookies)
|
|
@@ -489,7 +515,13 @@ function getEnvironmentConfig(environment, chainID) {
|
|
|
489
515
|
return {
|
|
490
516
|
...env,
|
|
491
517
|
chainID: BigInt(resolvedChainID),
|
|
492
|
-
...apiUrlOverride ? { userApiServerURL: apiUrlOverride } : {}
|
|
518
|
+
...apiUrlOverride ? { userApiServerURL: apiUrlOverride } : {},
|
|
519
|
+
...process.env.ECLOUD_USER_API_URL && {
|
|
520
|
+
userApiServerURL: process.env.ECLOUD_USER_API_URL
|
|
521
|
+
},
|
|
522
|
+
...process.env.ECLOUD_RPC_URL && {
|
|
523
|
+
defaultRPCURL: process.env.ECLOUD_RPC_URL
|
|
524
|
+
}
|
|
493
525
|
};
|
|
494
526
|
}
|
|
495
527
|
function getBillingEnvironmentConfig(build) {
|
|
@@ -501,7 +533,12 @@ function getBillingEnvironmentConfig(build) {
|
|
|
501
533
|
if (apiUrlOverride) {
|
|
502
534
|
return { billingApiServerURL: apiUrlOverride };
|
|
503
535
|
}
|
|
504
|
-
return
|
|
536
|
+
return {
|
|
537
|
+
...config,
|
|
538
|
+
...process.env.ECLOUD_BILLING_API_URL && {
|
|
539
|
+
billingApiServerURL: process.env.ECLOUD_BILLING_API_URL
|
|
540
|
+
}
|
|
541
|
+
};
|
|
505
542
|
}
|
|
506
543
|
function getBuildType() {
|
|
507
544
|
const buildTimeType = true ? "dev"?.toLowerCase() : void 0;
|
|
@@ -2044,7 +2081,7 @@ function createBillingModule(config) {
|
|
|
2044
2081
|
const address = walletClient.account.address;
|
|
2045
2082
|
const logger = getLogger(verbose);
|
|
2046
2083
|
const billingEnvConfig = getBillingEnvironmentConfig(getBuildType());
|
|
2047
|
-
const billingApi = new BillingApiClient(billingEnvConfig, walletClient);
|
|
2084
|
+
const billingApi = new BillingApiClient(billingEnvConfig, walletClient, { verbose });
|
|
2048
2085
|
const environmentConfig = getEnvironmentConfig(environment);
|
|
2049
2086
|
const usdcCreditsAddress = environmentConfig.usdcCreditsAddress;
|
|
2050
2087
|
if (!usdcCreditsAddress) {
|
|
@@ -2208,6 +2245,12 @@ function createBillingModule(config) {
|
|
|
2208
2245
|
};
|
|
2209
2246
|
}
|
|
2210
2247
|
);
|
|
2248
|
+
},
|
|
2249
|
+
async getPaymentMethods() {
|
|
2250
|
+
return billingApi.getPaymentMethods();
|
|
2251
|
+
},
|
|
2252
|
+
async purchaseCredits(amountCents, paymentMethodId) {
|
|
2253
|
+
return billingApi.purchaseCredits(amountCents, paymentMethodId);
|
|
2211
2254
|
}
|
|
2212
2255
|
};
|
|
2213
2256
|
return module;
|