@layr-labs/ecloud-sdk 0.3.0-dev.0 → 0.3.1-dev
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 +4 -273
- package/dist/billing.cjs.map +1 -1
- package/dist/billing.d.cts +1 -1
- package/dist/billing.d.ts +1 -1
- package/dist/billing.js +4 -275
- package/dist/billing.js.map +1 -1
- package/dist/browser.cjs +173 -569
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +12 -53
- package/dist/browser.d.ts +12 -53
- package/dist/browser.js +173 -569
- package/dist/browser.js.map +1 -1
- package/dist/{compute-BcJuIxc1.d.ts → compute-BYhSs8en.d.ts} +1 -1
- package/dist/{compute-oD9uqLtr.d.cts → compute-Bpjb3hYD.d.cts} +1 -1
- package/dist/compute.cjs +154 -240
- 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 +154 -242
- package/dist/compute.js.map +1 -1
- package/dist/{helpers-Cp8qGRTb.d.ts → helpers-CEvhJz7f.d.cts} +5 -249
- package/dist/{helpers-BNGcO-VX.d.cts → helpers-CQuBwQnu.d.ts} +5 -249
- package/dist/{index-5y9NG_Id.d.cts → index-DeQzn_yM.d.cts} +1 -9
- package/dist/{index-5y9NG_Id.d.ts → index-DeQzn_yM.d.ts} +1 -9
- package/dist/index.cjs +229 -646
- 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 +228 -647
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/VERSION
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
version=0.3.
|
|
2
|
-
commit=
|
|
1
|
+
version=0.3.1-dev
|
|
2
|
+
commit=549da0a4121d064a66af11f15a509934858d9e2d
|
package/dist/billing.cjs
CHANGED
|
@@ -5,9 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __esm = (fn, res) => function __init() {
|
|
9
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
-
};
|
|
11
8
|
var __export = (target, all) => {
|
|
12
9
|
for (var name in all)
|
|
13
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -30,13 +27,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
27
|
));
|
|
31
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
29
|
|
|
33
|
-
// src/client/common/auth/session.ts
|
|
34
|
-
var init_session = __esm({
|
|
35
|
-
"src/client/common/auth/session.ts"() {
|
|
36
|
-
"use strict";
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
|
|
40
30
|
// src/billing.ts
|
|
41
31
|
var billing_exports = {};
|
|
42
32
|
__export(billing_exports, {
|
|
@@ -84,213 +74,22 @@ async function calculateBillingAuthSignature(options) {
|
|
|
84
74
|
return { signature, expiry };
|
|
85
75
|
}
|
|
86
76
|
|
|
87
|
-
// src/client/common/auth/billingSession.ts
|
|
88
|
-
var BillingSessionError = class extends Error {
|
|
89
|
-
constructor(message, code, statusCode) {
|
|
90
|
-
super(message);
|
|
91
|
-
this.code = code;
|
|
92
|
-
this.statusCode = statusCode;
|
|
93
|
-
this.name = "BillingSessionError";
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
function stripHexPrefix(hex) {
|
|
97
|
-
return hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
98
|
-
}
|
|
99
|
-
async function parseErrorResponse(response) {
|
|
100
|
-
try {
|
|
101
|
-
const data = await response.json();
|
|
102
|
-
return data.error || response.statusText;
|
|
103
|
-
} catch {
|
|
104
|
-
return response.statusText;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
async function loginToBillingApi(config, request) {
|
|
108
|
-
let response;
|
|
109
|
-
try {
|
|
110
|
-
response = await fetch(`${config.baseUrl}/auth/siwe/login`, {
|
|
111
|
-
method: "POST",
|
|
112
|
-
credentials: "include",
|
|
113
|
-
// Include cookies for session management
|
|
114
|
-
headers: {
|
|
115
|
-
"Content-Type": "application/json"
|
|
116
|
-
},
|
|
117
|
-
body: JSON.stringify({
|
|
118
|
-
message: request.message,
|
|
119
|
-
signature: stripHexPrefix(request.signature)
|
|
120
|
-
})
|
|
121
|
-
});
|
|
122
|
-
} catch (error) {
|
|
123
|
-
throw new BillingSessionError(
|
|
124
|
-
`Network error connecting to ${config.baseUrl}: ${error instanceof Error ? error.message : String(error)}`,
|
|
125
|
-
"NETWORK_ERROR"
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
if (!response.ok) {
|
|
129
|
-
const errorMessage = await parseErrorResponse(response);
|
|
130
|
-
const status = response.status;
|
|
131
|
-
if (status === 400) {
|
|
132
|
-
if (errorMessage.toLowerCase().includes("siwe")) {
|
|
133
|
-
throw new BillingSessionError(`Invalid SIWE message: ${errorMessage}`, "INVALID_MESSAGE", status);
|
|
134
|
-
}
|
|
135
|
-
throw new BillingSessionError(`Bad request: ${errorMessage}`, "INVALID_MESSAGE", status);
|
|
136
|
-
}
|
|
137
|
-
if (status === 401) {
|
|
138
|
-
throw new BillingSessionError(`Invalid signature: ${errorMessage}`, "INVALID_SIGNATURE", status);
|
|
139
|
-
}
|
|
140
|
-
throw new BillingSessionError(`Login failed: ${errorMessage}`, "UNKNOWN", status);
|
|
141
|
-
}
|
|
142
|
-
const data = await response.json();
|
|
143
|
-
return {
|
|
144
|
-
success: data.success,
|
|
145
|
-
address: data.address
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
async function getBillingApiSession(config) {
|
|
149
|
-
let response;
|
|
150
|
-
try {
|
|
151
|
-
response = await fetch(`${config.baseUrl}/auth/session`, {
|
|
152
|
-
method: "GET",
|
|
153
|
-
credentials: "include",
|
|
154
|
-
// Include cookies for session management
|
|
155
|
-
headers: {
|
|
156
|
-
"Content-Type": "application/json"
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
} catch {
|
|
160
|
-
return {
|
|
161
|
-
authenticated: false
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
if (response.status === 401) {
|
|
165
|
-
return {
|
|
166
|
-
authenticated: false
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
if (!response.ok) {
|
|
170
|
-
const errorMessage = await parseErrorResponse(response);
|
|
171
|
-
throw new BillingSessionError(`Failed to get session: ${errorMessage}`, "UNKNOWN", response.status);
|
|
172
|
-
}
|
|
173
|
-
const data = await response.json();
|
|
174
|
-
return {
|
|
175
|
-
authenticated: data.authenticated,
|
|
176
|
-
address: data.address,
|
|
177
|
-
chainId: data.chainId,
|
|
178
|
-
authenticatedAt: data.authenticatedAt
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
async function logoutFromBillingApi(config) {
|
|
182
|
-
let response;
|
|
183
|
-
try {
|
|
184
|
-
response = await fetch(`${config.baseUrl}/auth/logout`, {
|
|
185
|
-
method: "POST",
|
|
186
|
-
credentials: "include",
|
|
187
|
-
// Include cookies for session management
|
|
188
|
-
headers: {
|
|
189
|
-
"Content-Type": "application/json"
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
} catch (error) {
|
|
193
|
-
throw new BillingSessionError(
|
|
194
|
-
`Network error connecting to ${config.baseUrl}: ${error instanceof Error ? error.message : String(error)}`,
|
|
195
|
-
"NETWORK_ERROR"
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
if (response.status === 401) {
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
if (!response.ok) {
|
|
202
|
-
const errorMessage = await parseErrorResponse(response);
|
|
203
|
-
throw new BillingSessionError(`Logout failed: ${errorMessage}`, "UNKNOWN", response.status);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
77
|
// src/client/common/utils/billingapi.ts
|
|
208
78
|
var BillingApiClient = class {
|
|
209
|
-
constructor(config, walletClient
|
|
79
|
+
constructor(config, walletClient) {
|
|
210
80
|
this.config = config;
|
|
211
81
|
this.walletClient = walletClient;
|
|
212
|
-
this.options = options;
|
|
213
|
-
this.useSession = options.useSession ?? false;
|
|
214
|
-
if (!this.useSession && !walletClient) {
|
|
215
|
-
throw new Error("WalletClient is required when not using session authentication");
|
|
216
|
-
}
|
|
217
82
|
}
|
|
218
83
|
/**
|
|
219
84
|
* Get the address of the connected wallet
|
|
220
|
-
* Returns undefined if using session auth without a wallet client
|
|
221
85
|
*/
|
|
222
86
|
get address() {
|
|
223
|
-
const account = this.walletClient
|
|
87
|
+
const account = this.walletClient.account;
|
|
224
88
|
if (!account) {
|
|
225
|
-
|
|
226
|
-
throw new Error("WalletClient must have an account attached");
|
|
227
|
-
}
|
|
228
|
-
return void 0;
|
|
89
|
+
throw new Error("WalletClient must have an account attached");
|
|
229
90
|
}
|
|
230
91
|
return account.address;
|
|
231
92
|
}
|
|
232
|
-
/**
|
|
233
|
-
* Get the base URL of the billing API
|
|
234
|
-
*/
|
|
235
|
-
get baseUrl() {
|
|
236
|
-
return this.config.billingApiServerURL;
|
|
237
|
-
}
|
|
238
|
-
// ==========================================================================
|
|
239
|
-
// SIWE Session Methods
|
|
240
|
-
// ==========================================================================
|
|
241
|
-
/**
|
|
242
|
-
* Login to the billing API using SIWE
|
|
243
|
-
*
|
|
244
|
-
* This establishes a session with the billing API by verifying the SIWE message
|
|
245
|
-
* and signature. On success, a session cookie is set in the browser.
|
|
246
|
-
*
|
|
247
|
-
* @param request - Login request containing SIWE message and signature
|
|
248
|
-
* @returns Login result with the authenticated address
|
|
249
|
-
*
|
|
250
|
-
* @example
|
|
251
|
-
* ```typescript
|
|
252
|
-
* const { message } = createSiweMessage({
|
|
253
|
-
* address: userAddress,
|
|
254
|
-
* chainId: 11155111,
|
|
255
|
-
* domain: window.location.host,
|
|
256
|
-
* uri: window.location.origin,
|
|
257
|
-
* });
|
|
258
|
-
*
|
|
259
|
-
* const signature = await signMessageAsync({ message });
|
|
260
|
-
* const result = await billingClient.siweLogin({ message, signature });
|
|
261
|
-
* ```
|
|
262
|
-
*/
|
|
263
|
-
async siweLogin(request) {
|
|
264
|
-
return loginToBillingApi({ baseUrl: this.baseUrl }, request);
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* Logout from the billing API
|
|
268
|
-
*
|
|
269
|
-
* This destroys the current session and clears the session cookie.
|
|
270
|
-
*/
|
|
271
|
-
async siweLogout() {
|
|
272
|
-
return logoutFromBillingApi({ baseUrl: this.baseUrl });
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* Get the current session status from the billing API
|
|
276
|
-
*
|
|
277
|
-
* @returns Session information including authentication status and address
|
|
278
|
-
*/
|
|
279
|
-
async getSession() {
|
|
280
|
-
return getBillingApiSession({ baseUrl: this.baseUrl });
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* Check if there is a valid session
|
|
284
|
-
*
|
|
285
|
-
* @returns True if session is authenticated, false otherwise
|
|
286
|
-
*/
|
|
287
|
-
async isSessionValid() {
|
|
288
|
-
const session = await this.getSession();
|
|
289
|
-
return session.authenticated;
|
|
290
|
-
}
|
|
291
|
-
// ==========================================================================
|
|
292
|
-
// Subscription Methods
|
|
293
|
-
// ==========================================================================
|
|
294
93
|
async createSubscription(productId = "compute", options) {
|
|
295
94
|
const endpoint = `${this.config.billingApiServerURL}/products/${productId}/subscription`;
|
|
296
95
|
const body = options ? {
|
|
@@ -309,72 +108,10 @@ var BillingApiClient = class {
|
|
|
309
108
|
const endpoint = `${this.config.billingApiServerURL}/products/${productId}/subscription`;
|
|
310
109
|
await this.makeAuthenticatedRequest(endpoint, "DELETE", productId);
|
|
311
110
|
}
|
|
312
|
-
// ==========================================================================
|
|
313
|
-
// Internal Methods
|
|
314
|
-
// ==========================================================================
|
|
315
111
|
/**
|
|
316
112
|
* Make an authenticated request to the billing API
|
|
317
|
-
*
|
|
318
|
-
* Uses session auth if useSession is true, otherwise uses EIP-712 signature auth.
|
|
319
113
|
*/
|
|
320
114
|
async makeAuthenticatedRequest(url, method, productId, body) {
|
|
321
|
-
if (this.useSession) {
|
|
322
|
-
return this.makeSessionAuthenticatedRequest(url, method, body);
|
|
323
|
-
}
|
|
324
|
-
return this.makeSignatureAuthenticatedRequest(url, method, productId, body);
|
|
325
|
-
}
|
|
326
|
-
/**
|
|
327
|
-
* Make a request using session-based authentication (cookies)
|
|
328
|
-
*/
|
|
329
|
-
async makeSessionAuthenticatedRequest(url, method, body) {
|
|
330
|
-
const headers = {};
|
|
331
|
-
if (body) {
|
|
332
|
-
headers["Content-Type"] = "application/json";
|
|
333
|
-
}
|
|
334
|
-
try {
|
|
335
|
-
const response = await fetch(url, {
|
|
336
|
-
method,
|
|
337
|
-
credentials: "include",
|
|
338
|
-
// Include cookies for session management
|
|
339
|
-
headers,
|
|
340
|
-
body: body ? JSON.stringify(body) : void 0
|
|
341
|
-
});
|
|
342
|
-
const status = response.status;
|
|
343
|
-
const statusText = status >= 200 && status < 300 ? "OK" : "Error";
|
|
344
|
-
if (status < 200 || status >= 300) {
|
|
345
|
-
let errorBody;
|
|
346
|
-
try {
|
|
347
|
-
errorBody = await response.text();
|
|
348
|
-
} catch {
|
|
349
|
-
errorBody = statusText;
|
|
350
|
-
}
|
|
351
|
-
throw new Error(`BillingAPI request failed: ${status} ${statusText} - ${errorBody}`);
|
|
352
|
-
}
|
|
353
|
-
const responseData = await response.json();
|
|
354
|
-
return {
|
|
355
|
-
json: async () => responseData,
|
|
356
|
-
text: async () => JSON.stringify(responseData)
|
|
357
|
-
};
|
|
358
|
-
} catch (error) {
|
|
359
|
-
if (error.name === "TypeError" || error.message?.includes("fetch")) {
|
|
360
|
-
throw new Error(
|
|
361
|
-
`Failed to connect to BillingAPI at ${url}: ${error.message}
|
|
362
|
-
Please check:
|
|
363
|
-
1. Your internet connection
|
|
364
|
-
2. The API server is accessible: ${this.config.billingApiServerURL}
|
|
365
|
-
3. Firewall/proxy settings`
|
|
366
|
-
);
|
|
367
|
-
}
|
|
368
|
-
throw error;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
/**
|
|
372
|
-
* Make a request using EIP-712 signature authentication
|
|
373
|
-
*/
|
|
374
|
-
async makeSignatureAuthenticatedRequest(url, method, productId, body) {
|
|
375
|
-
if (!this.walletClient) {
|
|
376
|
-
throw new Error("WalletClient is required for signature authentication");
|
|
377
|
-
}
|
|
378
115
|
const expiry = BigInt(Math.floor(Date.now() / 1e3) + 5 * 60);
|
|
379
116
|
const { signature } = await calculateBillingAuthSignature({
|
|
380
117
|
walletClient: this.walletClient,
|
|
@@ -520,9 +257,6 @@ var import_accounts = require("viem/accounts");
|
|
|
520
257
|
// src/client/common/constants.ts
|
|
521
258
|
var import_chains = require("viem/chains");
|
|
522
259
|
|
|
523
|
-
// src/client/common/utils/userapi.ts
|
|
524
|
-
init_session();
|
|
525
|
-
|
|
526
260
|
// src/client/common/utils/billing.ts
|
|
527
261
|
function isSubscriptionActive(status) {
|
|
528
262
|
return status === "active" || status === "trialing";
|
|
@@ -763,10 +497,7 @@ function createBillingModule(config) {
|
|
|
763
497
|
};
|
|
764
498
|
}
|
|
765
499
|
logger.debug(`Creating subscription for ${productId}...`);
|
|
766
|
-
const result = await billingApi.createSubscription(productId
|
|
767
|
-
successUrl: opts?.successUrl,
|
|
768
|
-
cancelUrl: opts?.cancelUrl
|
|
769
|
-
});
|
|
500
|
+
const result = await billingApi.createSubscription(productId);
|
|
770
501
|
logger.debug(`Checkout URL: ${result.checkoutUrl}`);
|
|
771
502
|
return {
|
|
772
503
|
type: "checkout_created",
|