@layr-labs/ecloud-sdk 0.5.0-dev.3 → 1.0.0-dev.1
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/attest.cjs +31 -9
- package/dist/attest.cjs.map +1 -1
- package/dist/attest.d.cts +3 -2
- package/dist/attest.d.ts +3 -2
- package/dist/attest.js +31 -9
- package/dist/attest.js.map +1 -1
- package/dist/billing.cjs +46 -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 +46 -6
- package/dist/billing.js.map +1 -1
- package/dist/browser.cjs +40 -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 +40 -6
- package/dist/browser.js.map +1 -1
- package/dist/{compute-Ckyn8ils.d.cts → compute-Bn6KcW3x.d.cts} +1 -1
- package/dist/{compute-Cnw6rwSB.d.ts → compute-Do2t0Fo8.d.ts} +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-DZL2bg9p.d.cts → helpers-BRamdfGn.d.ts} +5 -1
- package/dist/{helpers-Dj2ME5rp.d.ts → helpers-CfsfcGJO.d.cts} +5 -1
- package/dist/{index-U2vKBrry.d.cts → index-BbH7ZCIu.d.cts} +15 -1
- package/dist/{index-U2vKBrry.d.ts → index-BbH7ZCIu.d.ts} +15 -1
- package/dist/index.cjs +78 -16
- 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 +78 -16
- 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-BbH7ZCIu.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-BbH7ZCIu.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,19 @@ 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
|
+
}
|
|
312
|
+
const resp = this.useSession ? await this.makeSessionAuthenticatedRequest(url, method, body) : await this.makeSignatureAuthenticatedRequest(url, method, productId, body);
|
|
313
|
+
if (this.options.verbose) {
|
|
314
|
+
const data = await resp.json();
|
|
315
|
+
console.debug(`[BillingAPI] Response:`, JSON.stringify(data, null, 2));
|
|
316
|
+
return {
|
|
317
|
+
json: async () => data,
|
|
318
|
+
text: async () => JSON.stringify(data)
|
|
319
|
+
};
|
|
297
320
|
}
|
|
298
|
-
return
|
|
321
|
+
return resp;
|
|
299
322
|
}
|
|
300
323
|
/**
|
|
301
324
|
* Make a request using session-based authentication (cookies)
|
|
@@ -481,7 +504,13 @@ function getEnvironmentConfig(environment, chainID) {
|
|
|
481
504
|
const resolvedChainID = chainID || (environment === "sepolia" || environment === "sepolia-dev" ? SEPOLIA_CHAIN_ID : MAINNET_CHAIN_ID);
|
|
482
505
|
return {
|
|
483
506
|
...env,
|
|
484
|
-
chainID: BigInt(resolvedChainID)
|
|
507
|
+
chainID: BigInt(resolvedChainID),
|
|
508
|
+
...process.env.ECLOUD_USER_API_URL && {
|
|
509
|
+
userApiServerURL: process.env.ECLOUD_USER_API_URL
|
|
510
|
+
},
|
|
511
|
+
...process.env.ECLOUD_RPC_URL && {
|
|
512
|
+
defaultRPCURL: process.env.ECLOUD_RPC_URL
|
|
513
|
+
}
|
|
485
514
|
};
|
|
486
515
|
}
|
|
487
516
|
function getBillingEnvironmentConfig(build) {
|
|
@@ -489,7 +518,12 @@ function getBillingEnvironmentConfig(build) {
|
|
|
489
518
|
if (!config) {
|
|
490
519
|
throw new Error(`Unknown billing environment: ${build}`);
|
|
491
520
|
}
|
|
492
|
-
return
|
|
521
|
+
return {
|
|
522
|
+
...config,
|
|
523
|
+
...process.env.ECLOUD_BILLING_API_URL && {
|
|
524
|
+
billingApiServerURL: process.env.ECLOUD_BILLING_API_URL
|
|
525
|
+
}
|
|
526
|
+
};
|
|
493
527
|
}
|
|
494
528
|
function getBuildType() {
|
|
495
529
|
const buildTimeType = true ? "dev"?.toLowerCase() : void 0;
|
|
@@ -2032,7 +2066,7 @@ function createBillingModule(config) {
|
|
|
2032
2066
|
const address = walletClient.account.address;
|
|
2033
2067
|
const logger = getLogger(verbose);
|
|
2034
2068
|
const billingEnvConfig = getBillingEnvironmentConfig(getBuildType());
|
|
2035
|
-
const billingApi = new BillingApiClient(billingEnvConfig, walletClient);
|
|
2069
|
+
const billingApi = new BillingApiClient(billingEnvConfig, walletClient, { verbose });
|
|
2036
2070
|
const environmentConfig = getEnvironmentConfig(environment);
|
|
2037
2071
|
const usdcCreditsAddress = environmentConfig.usdcCreditsAddress;
|
|
2038
2072
|
if (!usdcCreditsAddress) {
|
|
@@ -2196,6 +2230,12 @@ function createBillingModule(config) {
|
|
|
2196
2230
|
};
|
|
2197
2231
|
}
|
|
2198
2232
|
);
|
|
2233
|
+
},
|
|
2234
|
+
async getPaymentMethods() {
|
|
2235
|
+
return billingApi.getPaymentMethods();
|
|
2236
|
+
},
|
|
2237
|
+
async purchaseCredits(amountCents, paymentMethodId) {
|
|
2238
|
+
return billingApi.purchaseCredits(amountCents, paymentMethodId);
|
|
2199
2239
|
}
|
|
2200
2240
|
};
|
|
2201
2241
|
return module;
|