@elsoul/erpc-sdk 0.1.0 → 0.3.0
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/README.md +28 -0
- package/dist/index.cjs +405 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +137 -1
- package/dist/index.d.ts +137 -1
- package/dist/index.js +400 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -240,9 +240,82 @@ var AccountClient = class {
|
|
|
240
240
|
}
|
|
241
241
|
};
|
|
242
242
|
|
|
243
|
+
// src/catalog.ts
|
|
244
|
+
var resourceKinds = [
|
|
245
|
+
"bare-metal",
|
|
246
|
+
"solana-grpc",
|
|
247
|
+
"solana-shredstream",
|
|
248
|
+
"vps"
|
|
249
|
+
];
|
|
250
|
+
var resourceModes = [
|
|
251
|
+
"dedicated",
|
|
252
|
+
"direct",
|
|
253
|
+
"shared"
|
|
254
|
+
];
|
|
255
|
+
var objectValue = (value) => typeof value === "object" && value !== null ? value : null;
|
|
256
|
+
var stringArray = (value) => Array.isArray(value) && value.every((item) => typeof item === "string") ? value : null;
|
|
257
|
+
var parseOffering = (value) => {
|
|
258
|
+
const offering = objectValue(value);
|
|
259
|
+
if (offering === null || typeof offering.id !== "string" || typeof offering.kind !== "string" || !resourceKinds.includes(offering.kind) || typeof offering.name !== "string" || typeof offering.description !== "string" || offering.mode !== void 0 && (typeof offering.mode !== "string" || !resourceModes.includes(offering.mode))) return null;
|
|
260
|
+
const regions = stringArray(offering.regions);
|
|
261
|
+
const capabilities = stringArray(offering.capabilities);
|
|
262
|
+
if (regions === null || capabilities === null) return null;
|
|
263
|
+
const compute = offering.compute === void 0 ? void 0 : objectValue(offering.compute);
|
|
264
|
+
if (compute !== void 0 && (compute === null || compute.tenancy !== "virtual-machine" && compute.tenancy !== "bare-metal")) return null;
|
|
265
|
+
const solana = offering.solana === void 0 ? void 0 : objectValue(offering.solana);
|
|
266
|
+
if (solana !== void 0 && (solana === null || solana.transport !== "grpc" && solana.transport !== "shredstream")) return null;
|
|
267
|
+
const billing = offering.billing === void 0 ? void 0 : objectValue(offering.billing);
|
|
268
|
+
if (billing !== void 0 && (billing === null || billing.unit !== "cents-per-hour" || typeof billing.amountCents !== "number" || !Number.isInteger(billing.amountCents) || billing.amountCents < 0)) return null;
|
|
269
|
+
return {
|
|
270
|
+
id: offering.id,
|
|
271
|
+
kind: offering.kind,
|
|
272
|
+
name: offering.name,
|
|
273
|
+
description: offering.description,
|
|
274
|
+
regions,
|
|
275
|
+
capabilities,
|
|
276
|
+
...typeof offering.mode === "string" ? { mode: offering.mode } : {},
|
|
277
|
+
...compute && (compute.tenancy === "virtual-machine" || compute.tenancy === "bare-metal") ? { compute: { tenancy: compute.tenancy } } : {},
|
|
278
|
+
...solana && (solana.transport === "grpc" || solana.transport === "shredstream") ? { solana: { transport: solana.transport } } : {},
|
|
279
|
+
...billing && billing.unit === "cents-per-hour" && typeof billing.amountCents === "number" ? {
|
|
280
|
+
billing: {
|
|
281
|
+
amountCents: billing.amountCents,
|
|
282
|
+
unit: billing.unit
|
|
283
|
+
}
|
|
284
|
+
} : {}
|
|
285
|
+
};
|
|
286
|
+
};
|
|
287
|
+
var CloudCatalogClient = class {
|
|
288
|
+
#transport;
|
|
289
|
+
constructor(transport) {
|
|
290
|
+
this.#transport = transport;
|
|
291
|
+
}
|
|
292
|
+
async list(options) {
|
|
293
|
+
const response = await this.#transport.get(
|
|
294
|
+
"/v4/cloud/catalog",
|
|
295
|
+
void 0,
|
|
296
|
+
options
|
|
297
|
+
);
|
|
298
|
+
const envelope = objectValue(response);
|
|
299
|
+
const message = objectValue(envelope?.message);
|
|
300
|
+
if (envelope?.success !== true || !Array.isArray(message?.offerings)) {
|
|
301
|
+
throw new ErpcInvalidResponseError(
|
|
302
|
+
"ERPC returned an invalid Cloud catalog"
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
const offerings = message.offerings.map(parseOffering);
|
|
306
|
+
if (offerings.some((offering) => offering === null)) {
|
|
307
|
+
throw new ErpcInvalidResponseError(
|
|
308
|
+
"ERPC returned an invalid Cloud catalog"
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
return offerings;
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
|
|
243
315
|
// src/config.ts
|
|
244
316
|
var DEFAULT_ENDPOINT = "https://edge.erpc.global";
|
|
245
317
|
var DEFAULT_ACCOUNT_ENDPOINT = "https://solana-rpc.erpc.global";
|
|
318
|
+
var DEFAULT_USER_ENDPOINT = "https://user-api.erpc.global";
|
|
246
319
|
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
247
320
|
var requireFetch = (provided) => {
|
|
248
321
|
const implementation = provided ?? globalThis.fetch;
|
|
@@ -258,11 +331,13 @@ var resolveConfig = (config) => {
|
|
|
258
331
|
if (!apiKey) throw new ErpcConfigError("apiKey must not be empty");
|
|
259
332
|
let endpoint;
|
|
260
333
|
let accountEndpoint;
|
|
334
|
+
let userEndpoint;
|
|
261
335
|
try {
|
|
262
336
|
endpoint = new URL(config.endpoint ?? DEFAULT_ENDPOINT);
|
|
263
337
|
accountEndpoint = new URL(
|
|
264
338
|
config.accountEndpoint ?? DEFAULT_ACCOUNT_ENDPOINT
|
|
265
339
|
);
|
|
340
|
+
userEndpoint = new URL(config.userEndpoint ?? DEFAULT_USER_ENDPOINT);
|
|
266
341
|
} catch {
|
|
267
342
|
throw new ErpcConfigError("endpoint must be an absolute HTTP(S) URL");
|
|
268
343
|
}
|
|
@@ -272,12 +347,18 @@ var resolveConfig = (config) => {
|
|
|
272
347
|
if (accountEndpoint.protocol !== "https:" && accountEndpoint.protocol !== "http:") {
|
|
273
348
|
throw new ErpcConfigError("accountEndpoint must use HTTP or HTTPS");
|
|
274
349
|
}
|
|
350
|
+
if (userEndpoint.protocol !== "https:" && userEndpoint.protocol !== "http:") {
|
|
351
|
+
throw new ErpcConfigError("userEndpoint must use HTTP or HTTPS");
|
|
352
|
+
}
|
|
275
353
|
endpoint.search = "";
|
|
276
354
|
endpoint.hash = "";
|
|
277
355
|
endpoint.pathname = endpoint.pathname.replace(/\/+$/, "") || "/";
|
|
278
356
|
accountEndpoint.search = "";
|
|
279
357
|
accountEndpoint.hash = "";
|
|
280
358
|
accountEndpoint.pathname = accountEndpoint.pathname.replace(/\/+$/, "") || "/";
|
|
359
|
+
userEndpoint.search = "";
|
|
360
|
+
userEndpoint.hash = "";
|
|
361
|
+
userEndpoint.pathname = userEndpoint.pathname.replace(/\/+$/, "") || "/";
|
|
281
362
|
const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
282
363
|
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
283
364
|
throw new ErpcConfigError("timeoutMs must be a positive finite number");
|
|
@@ -289,6 +370,7 @@ var resolveConfig = (config) => {
|
|
|
289
370
|
fetch: requireFetch(config.fetch),
|
|
290
371
|
headers: config.headers ?? {},
|
|
291
372
|
timeoutMs,
|
|
373
|
+
userEndpoint,
|
|
292
374
|
...config.webSocket === void 0 ? {} : { webSocket: config.webSocket }
|
|
293
375
|
};
|
|
294
376
|
};
|
|
@@ -1121,6 +1203,7 @@ var HttpJsonRpcTransport = class {
|
|
|
1121
1203
|
}
|
|
1122
1204
|
throw new ErpcInvalidResponseError("ERPC returned a non-array batch response");
|
|
1123
1205
|
}
|
|
1206
|
+
const expectedIds = new Set(requests.map((request) => request.id));
|
|
1124
1207
|
const byId = /* @__PURE__ */ new Map();
|
|
1125
1208
|
for (const response of raw) {
|
|
1126
1209
|
if (!isObject2(response) || !("id" in response)) {
|
|
@@ -1130,6 +1213,16 @@ var HttpJsonRpcTransport = class {
|
|
|
1130
1213
|
if (typeof id !== "number" && typeof id !== "string") {
|
|
1131
1214
|
throw new ErpcInvalidResponseError("ERPC returned an invalid batch id");
|
|
1132
1215
|
}
|
|
1216
|
+
if (!expectedIds.has(id)) {
|
|
1217
|
+
throw new ErpcInvalidResponseError(
|
|
1218
|
+
"ERPC returned an unexpected batch response id"
|
|
1219
|
+
);
|
|
1220
|
+
}
|
|
1221
|
+
if (byId.has(id)) {
|
|
1222
|
+
throw new ErpcInvalidResponseError(
|
|
1223
|
+
`ERPC returned duplicate batch response id ${String(id)}`
|
|
1224
|
+
);
|
|
1225
|
+
}
|
|
1133
1226
|
byId.set(id, response);
|
|
1134
1227
|
}
|
|
1135
1228
|
const results = requests.map((request) => {
|
|
@@ -1196,6 +1289,91 @@ var HttpJsonRpcTransport = class {
|
|
|
1196
1289
|
}
|
|
1197
1290
|
};
|
|
1198
1291
|
|
|
1292
|
+
// src/usage.ts
|
|
1293
|
+
var YEAR_MONTH = /^\d{4}-(0[1-9]|1[0-2])$/;
|
|
1294
|
+
var objectValue2 = (value) => typeof value === "object" && value !== null ? value : null;
|
|
1295
|
+
var isTimestamp = (value) => value === null || typeof value === "string";
|
|
1296
|
+
var parseMethod = (value) => {
|
|
1297
|
+
const method = objectValue2(value);
|
|
1298
|
+
if (method === null || typeof method.count !== "number" || typeof method.creditCost !== "number" || typeof method.credits !== "number" || typeof method.method !== "string" || !isTimestamp(method.updatedAt)) return null;
|
|
1299
|
+
return {
|
|
1300
|
+
count: method.count,
|
|
1301
|
+
creditCost: method.creditCost,
|
|
1302
|
+
credits: method.credits,
|
|
1303
|
+
method: method.method,
|
|
1304
|
+
updatedAt: method.updatedAt
|
|
1305
|
+
};
|
|
1306
|
+
};
|
|
1307
|
+
var parseChain = (value) => {
|
|
1308
|
+
const chain = objectValue2(value);
|
|
1309
|
+
if (chain === null || typeof chain.chain !== "string" || typeof chain.count !== "number" || typeof chain.credits !== "number" || !Array.isArray(chain.methods) || !isTimestamp(chain.updatedAt)) return null;
|
|
1310
|
+
const methods = chain.methods.map(parseMethod);
|
|
1311
|
+
if (methods.some((method) => method === null)) return null;
|
|
1312
|
+
return {
|
|
1313
|
+
chain: chain.chain,
|
|
1314
|
+
count: chain.count,
|
|
1315
|
+
credits: chain.credits,
|
|
1316
|
+
methods,
|
|
1317
|
+
updatedAt: chain.updatedAt
|
|
1318
|
+
};
|
|
1319
|
+
};
|
|
1320
|
+
var parseApiKey = (value) => {
|
|
1321
|
+
const apiKey = objectValue2(value);
|
|
1322
|
+
if (apiKey === null || typeof apiKey.apiKeyLast4 !== "string" || typeof apiKey.apiKeyLength !== "number" || !Array.isArray(apiKey.chains) || typeof apiKey.count !== "number" || typeof apiKey.credits !== "number" || apiKey.keyId !== null && typeof apiKey.keyId !== "number" || !isTimestamp(apiKey.updatedAt)) return null;
|
|
1323
|
+
const chains = apiKey.chains.map(parseChain);
|
|
1324
|
+
if (chains.some((chain) => chain === null)) return null;
|
|
1325
|
+
return {
|
|
1326
|
+
apiKeyLast4: apiKey.apiKeyLast4,
|
|
1327
|
+
apiKeyLength: apiKey.apiKeyLength,
|
|
1328
|
+
chains,
|
|
1329
|
+
count: apiKey.count,
|
|
1330
|
+
credits: apiKey.credits,
|
|
1331
|
+
keyId: apiKey.keyId,
|
|
1332
|
+
updatedAt: apiKey.updatedAt
|
|
1333
|
+
};
|
|
1334
|
+
};
|
|
1335
|
+
var parseMonthlyUsage = (value) => {
|
|
1336
|
+
const usage = objectValue2(value);
|
|
1337
|
+
if (usage === null || !Array.isArray(usage.apiKeys) || !Array.isArray(usage.chains) || typeof usage.hasStrandedUsage !== "boolean" || typeof usage.keyCount !== "number" || typeof usage.totalCount !== "number" || typeof usage.totalCredits !== "number" || !isTimestamp(usage.updatedAt) || typeof usage.yearMonth !== "string" || !YEAR_MONTH.test(usage.yearMonth)) return null;
|
|
1338
|
+
const apiKeys = usage.apiKeys.map(parseApiKey);
|
|
1339
|
+
const chains = usage.chains.map(parseChain);
|
|
1340
|
+
if (apiKeys.some((apiKey) => apiKey === null) || chains.some((chain) => chain === null)) return null;
|
|
1341
|
+
return {
|
|
1342
|
+
apiKeys,
|
|
1343
|
+
chains,
|
|
1344
|
+
hasStrandedUsage: usage.hasStrandedUsage,
|
|
1345
|
+
keyCount: usage.keyCount,
|
|
1346
|
+
totalCount: usage.totalCount,
|
|
1347
|
+
totalCredits: usage.totalCredits,
|
|
1348
|
+
updatedAt: usage.updatedAt,
|
|
1349
|
+
yearMonth: usage.yearMonth
|
|
1350
|
+
};
|
|
1351
|
+
};
|
|
1352
|
+
var UsageClient = class {
|
|
1353
|
+
#transport;
|
|
1354
|
+
constructor(transport) {
|
|
1355
|
+
this.#transport = transport;
|
|
1356
|
+
}
|
|
1357
|
+
async getMonthlyApiKeyUsage(params = {}, options) {
|
|
1358
|
+
if (params.yearMonth !== void 0 && !YEAR_MONTH.test(params.yearMonth)) {
|
|
1359
|
+
throw new ErpcConfigError("yearMonth must use YYYY-MM format");
|
|
1360
|
+
}
|
|
1361
|
+
const response = await this.#transport.get(
|
|
1362
|
+
"/v3/user/api-keys/usage",
|
|
1363
|
+
{ yearMonth: params.yearMonth },
|
|
1364
|
+
options
|
|
1365
|
+
);
|
|
1366
|
+
const envelope = objectValue2(response);
|
|
1367
|
+
const usage = envelope?.success === true ? parseMonthlyUsage(envelope.message) : null;
|
|
1368
|
+
if (usage === null) {
|
|
1369
|
+
throw new ErpcInvalidResponseError(
|
|
1370
|
+
"ERPC returned an invalid monthly API key usage response"
|
|
1371
|
+
);
|
|
1372
|
+
}
|
|
1373
|
+
return usage;
|
|
1374
|
+
}
|
|
1375
|
+
};
|
|
1376
|
+
|
|
1199
1377
|
// src/client.ts
|
|
1200
1378
|
var createErpcClient = (config) => {
|
|
1201
1379
|
const resolved = resolveConfig(config);
|
|
@@ -1232,6 +1410,10 @@ var createErpcClient = (config) => {
|
|
|
1232
1410
|
...sharedTransport,
|
|
1233
1411
|
endpoint: resolved.accountEndpoint
|
|
1234
1412
|
});
|
|
1413
|
+
const userTransport = new RestTransport({
|
|
1414
|
+
...sharedTransport,
|
|
1415
|
+
endpoint: resolved.userEndpoint
|
|
1416
|
+
});
|
|
1235
1417
|
const solana = {
|
|
1236
1418
|
...createSolanaClient(solanaTransport),
|
|
1237
1419
|
subscriptions: new SolanaSubscriptions(solanaWebSocket)
|
|
@@ -1245,6 +1427,7 @@ var createErpcClient = (config) => {
|
|
|
1245
1427
|
ethereum,
|
|
1246
1428
|
price: new PriceClient(priceTransport),
|
|
1247
1429
|
account: new AccountClient(accountTransport),
|
|
1430
|
+
usage: new UsageClient(userTransport),
|
|
1248
1431
|
close: () => {
|
|
1249
1432
|
solana.subscriptions.close();
|
|
1250
1433
|
ethereum.subscriptions.close();
|
|
@@ -1252,6 +1435,222 @@ var createErpcClient = (config) => {
|
|
|
1252
1435
|
};
|
|
1253
1436
|
};
|
|
1254
1437
|
|
|
1255
|
-
|
|
1438
|
+
// src/credit.ts
|
|
1439
|
+
var alertLevels = [
|
|
1440
|
+
"critical",
|
|
1441
|
+
"normal",
|
|
1442
|
+
"suspended",
|
|
1443
|
+
"warning"
|
|
1444
|
+
];
|
|
1445
|
+
var objectValue3 = (value) => typeof value === "object" && value !== null ? value : null;
|
|
1446
|
+
var isDateTime = (value) => typeof value === "string" && Number.isFinite(Date.parse(value));
|
|
1447
|
+
var parseCredit = (value) => {
|
|
1448
|
+
const credit = objectValue3(value);
|
|
1449
|
+
if (credit === null || typeof credit.balanceCents !== "number" || !Number.isInteger(credit.balanceCents) || typeof credit.burnRateCentsPerHour !== "number" || !Number.isInteger(credit.burnRateCentsPerHour) || credit.burnRateCentsPerHour < 0 || credit.timeToZeroHours !== null && (typeof credit.timeToZeroHours !== "number" || !Number.isFinite(credit.timeToZeroHours) || credit.timeToZeroHours < 0) || typeof credit.alertLevel !== "string" || !alertLevels.includes(credit.alertLevel) || !isDateTime(credit.quoteTimestamp) || !isDateTime(credit.quoteExpiresAt)) return null;
|
|
1450
|
+
return {
|
|
1451
|
+
alertLevel: credit.alertLevel,
|
|
1452
|
+
balanceCents: credit.balanceCents,
|
|
1453
|
+
burnRateCentsPerHour: credit.burnRateCentsPerHour,
|
|
1454
|
+
quoteExpiresAt: credit.quoteExpiresAt,
|
|
1455
|
+
quoteTimestamp: credit.quoteTimestamp,
|
|
1456
|
+
timeToZeroHours: credit.timeToZeroHours
|
|
1457
|
+
};
|
|
1458
|
+
};
|
|
1459
|
+
var CloudCreditClient = class {
|
|
1460
|
+
#transport;
|
|
1461
|
+
constructor(transport) {
|
|
1462
|
+
this.#transport = transport;
|
|
1463
|
+
}
|
|
1464
|
+
async get(options) {
|
|
1465
|
+
const response = await this.#transport.get(
|
|
1466
|
+
"/v4/cloud/credit",
|
|
1467
|
+
void 0,
|
|
1468
|
+
options
|
|
1469
|
+
);
|
|
1470
|
+
const envelope = objectValue3(response);
|
|
1471
|
+
const credit = envelope?.success === true ? parseCredit(envelope.message) : null;
|
|
1472
|
+
if (credit === null) {
|
|
1473
|
+
throw new ErpcInvalidResponseError(
|
|
1474
|
+
"ERPC returned an invalid Cloud credit snapshot"
|
|
1475
|
+
);
|
|
1476
|
+
}
|
|
1477
|
+
return credit;
|
|
1478
|
+
}
|
|
1479
|
+
};
|
|
1480
|
+
|
|
1481
|
+
// src/resources.ts
|
|
1482
|
+
var objectValue4 = (value) => typeof value === "object" && value !== null ? value : null;
|
|
1483
|
+
var resourceKinds2 = [
|
|
1484
|
+
"bare-metal",
|
|
1485
|
+
"solana-grpc",
|
|
1486
|
+
"solana-shredstream",
|
|
1487
|
+
"vps"
|
|
1488
|
+
];
|
|
1489
|
+
var resourceModes2 = [
|
|
1490
|
+
"dedicated",
|
|
1491
|
+
"direct",
|
|
1492
|
+
"shared"
|
|
1493
|
+
];
|
|
1494
|
+
var billingStatuses = [
|
|
1495
|
+
"active",
|
|
1496
|
+
"grace-period",
|
|
1497
|
+
"inactive",
|
|
1498
|
+
"suspended"
|
|
1499
|
+
];
|
|
1500
|
+
var isDateTime2 = (value) => typeof value === "string" && Number.isFinite(Date.parse(value));
|
|
1501
|
+
var parseStatusBilling = (value) => {
|
|
1502
|
+
const billing = objectValue4(value);
|
|
1503
|
+
if (billing === null || typeof billing.status !== "string" || !billingStatuses.includes(
|
|
1504
|
+
billing.status
|
|
1505
|
+
) || billing.hourlyCredits !== void 0 && (typeof billing.hourlyCredits !== "number" || !Number.isFinite(billing.hourlyCredits) || billing.hourlyCredits < 0) || billing.nextChargeAt !== void 0 && !isDateTime2(billing.nextChargeAt) || billing.graceEndsAt !== void 0 && !isDateTime2(billing.graceEndsAt)) return null;
|
|
1506
|
+
return {
|
|
1507
|
+
status: billing.status,
|
|
1508
|
+
...typeof billing.hourlyCredits === "number" ? { hourlyCredits: billing.hourlyCredits } : {},
|
|
1509
|
+
...typeof billing.nextChargeAt === "string" ? { nextChargeAt: billing.nextChargeAt } : {},
|
|
1510
|
+
...typeof billing.graceEndsAt === "string" ? { graceEndsAt: billing.graceEndsAt } : {}
|
|
1511
|
+
};
|
|
1512
|
+
};
|
|
1513
|
+
var parseResourceStatus = (value) => {
|
|
1514
|
+
const status = objectValue4(value);
|
|
1515
|
+
if (status === null || typeof status.id !== "string" || typeof status.status !== "string") return null;
|
|
1516
|
+
const billing = status.billing === void 0 ? void 0 : parseStatusBilling(status.billing);
|
|
1517
|
+
if (status.billing !== void 0 && billing === null) return null;
|
|
1518
|
+
return {
|
|
1519
|
+
id: status.id,
|
|
1520
|
+
status: status.status,
|
|
1521
|
+
...billing ? { billing } : {}
|
|
1522
|
+
};
|
|
1523
|
+
};
|
|
1524
|
+
var parseResource = (value) => {
|
|
1525
|
+
const resource = objectValue4(value);
|
|
1526
|
+
if (resource === null || typeof resource.id !== "string" || typeof resource.kind !== "string" || !resourceKinds2.includes(resource.kind) || typeof resource.status !== "string" || resource.mode !== void 0 && (typeof resource.mode !== "string" || !resourceModes2.includes(resource.mode)) || resource.name !== void 0 && typeof resource.name !== "string" || resource.region !== void 0 && typeof resource.region !== "string" || resource.createdAt !== void 0 && typeof resource.createdAt !== "string") return null;
|
|
1527
|
+
return {
|
|
1528
|
+
id: resource.id,
|
|
1529
|
+
kind: resource.kind,
|
|
1530
|
+
status: resource.status,
|
|
1531
|
+
...typeof resource.mode === "string" ? { mode: resource.mode } : {},
|
|
1532
|
+
...typeof resource.name === "string" ? { name: resource.name } : {},
|
|
1533
|
+
...typeof resource.region === "string" ? { region: resource.region } : {},
|
|
1534
|
+
...typeof resource.createdAt === "string" ? { createdAt: resource.createdAt } : {}
|
|
1535
|
+
};
|
|
1536
|
+
};
|
|
1537
|
+
var CloudResourcesClient = class {
|
|
1538
|
+
#transport;
|
|
1539
|
+
constructor(transport) {
|
|
1540
|
+
this.#transport = transport;
|
|
1541
|
+
}
|
|
1542
|
+
async list(options) {
|
|
1543
|
+
const response = await this.#transport.get(
|
|
1544
|
+
"/v4/cloud/resources",
|
|
1545
|
+
void 0,
|
|
1546
|
+
options
|
|
1547
|
+
);
|
|
1548
|
+
const envelope = objectValue4(response);
|
|
1549
|
+
const message = objectValue4(envelope?.message);
|
|
1550
|
+
if (envelope?.success !== true || !Array.isArray(message?.resources)) {
|
|
1551
|
+
throw new ErpcInvalidResponseError(
|
|
1552
|
+
"ERPC returned an invalid Cloud resource list"
|
|
1553
|
+
);
|
|
1554
|
+
}
|
|
1555
|
+
const resources = message.resources.map(parseResource);
|
|
1556
|
+
if (resources.some((resource) => resource === null)) {
|
|
1557
|
+
throw new ErpcInvalidResponseError(
|
|
1558
|
+
"ERPC returned an invalid Cloud resource list"
|
|
1559
|
+
);
|
|
1560
|
+
}
|
|
1561
|
+
return resources;
|
|
1562
|
+
}
|
|
1563
|
+
async get(resourceId, options) {
|
|
1564
|
+
const normalizedId = resourceId.trim();
|
|
1565
|
+
if (!normalizedId) {
|
|
1566
|
+
throw new ErpcConfigError("resourceId must not be empty");
|
|
1567
|
+
}
|
|
1568
|
+
const response = await this.#transport.get(
|
|
1569
|
+
`/v4/cloud/resources/${encodeURIComponent(normalizedId)}`,
|
|
1570
|
+
void 0,
|
|
1571
|
+
options
|
|
1572
|
+
);
|
|
1573
|
+
const envelope = objectValue4(response);
|
|
1574
|
+
const message = objectValue4(envelope?.message);
|
|
1575
|
+
const resource = envelope?.success === true ? parseResource(message?.resource) : null;
|
|
1576
|
+
if (resource === null) {
|
|
1577
|
+
throw new ErpcInvalidResponseError(
|
|
1578
|
+
"ERPC returned an invalid Cloud resource"
|
|
1579
|
+
);
|
|
1580
|
+
}
|
|
1581
|
+
return resource;
|
|
1582
|
+
}
|
|
1583
|
+
async getStatus(resourceId, options) {
|
|
1584
|
+
const normalizedId = resourceId.trim();
|
|
1585
|
+
if (!normalizedId) {
|
|
1586
|
+
throw new ErpcConfigError("resourceId must not be empty");
|
|
1587
|
+
}
|
|
1588
|
+
const response = await this.#transport.get(
|
|
1589
|
+
`/v4/cloud/resources/${encodeURIComponent(normalizedId)}/status`,
|
|
1590
|
+
void 0,
|
|
1591
|
+
options
|
|
1592
|
+
);
|
|
1593
|
+
const envelope = objectValue4(response);
|
|
1594
|
+
const status = envelope?.success === true ? parseResourceStatus(envelope.message) : null;
|
|
1595
|
+
if (status === null) {
|
|
1596
|
+
throw new ErpcInvalidResponseError(
|
|
1597
|
+
"ERPC returned an invalid Cloud resource status"
|
|
1598
|
+
);
|
|
1599
|
+
}
|
|
1600
|
+
return status;
|
|
1601
|
+
}
|
|
1602
|
+
};
|
|
1603
|
+
|
|
1604
|
+
// src/cloud.ts
|
|
1605
|
+
var requireFetch2 = (provided) => {
|
|
1606
|
+
const implementation = provided ?? globalThis.fetch;
|
|
1607
|
+
if (typeof implementation !== "function") {
|
|
1608
|
+
throw new ErpcConfigError(
|
|
1609
|
+
"A Fetch API implementation is required in this runtime"
|
|
1610
|
+
);
|
|
1611
|
+
}
|
|
1612
|
+
return implementation;
|
|
1613
|
+
};
|
|
1614
|
+
var cloudEndpoint = (value) => {
|
|
1615
|
+
let endpoint;
|
|
1616
|
+
try {
|
|
1617
|
+
endpoint = new URL(value ?? DEFAULT_USER_ENDPOINT);
|
|
1618
|
+
} catch {
|
|
1619
|
+
throw new ErpcConfigError("endpoint must be an absolute HTTP(S) URL");
|
|
1620
|
+
}
|
|
1621
|
+
const isLocalHttp = endpoint.protocol === "http:" && ["127.0.0.1", "::1", "[::1]", "localhost"].includes(endpoint.hostname);
|
|
1622
|
+
if (endpoint.protocol !== "https:" && !isLocalHttp) {
|
|
1623
|
+
throw new ErpcConfigError("endpoint must use HTTPS except on localhost");
|
|
1624
|
+
}
|
|
1625
|
+
endpoint.search = "";
|
|
1626
|
+
endpoint.hash = "";
|
|
1627
|
+
endpoint.pathname = endpoint.pathname.replace(/\/+$/, "") || "/";
|
|
1628
|
+
return endpoint;
|
|
1629
|
+
};
|
|
1630
|
+
var createErpcCloudClient = (config) => {
|
|
1631
|
+
const accessToken = config.accessToken.trim();
|
|
1632
|
+
if (!accessToken) {
|
|
1633
|
+
throw new ErpcConfigError("accessToken must not be empty");
|
|
1634
|
+
}
|
|
1635
|
+
const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
1636
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
1637
|
+
throw new ErpcConfigError("timeoutMs must be a positive finite number");
|
|
1638
|
+
}
|
|
1639
|
+
const transport = new RestTransport({
|
|
1640
|
+
apiKey: accessToken,
|
|
1641
|
+
endpoint: cloudEndpoint(config.endpoint),
|
|
1642
|
+
fetch: requireFetch2(config.fetch),
|
|
1643
|
+
headers: config.headers ?? {},
|
|
1644
|
+
timeoutMs
|
|
1645
|
+
});
|
|
1646
|
+
return {
|
|
1647
|
+
catalog: new CloudCatalogClient(transport),
|
|
1648
|
+
credit: new CloudCreditClient(transport),
|
|
1649
|
+
resources: new CloudResourcesClient(transport),
|
|
1650
|
+
usage: new UsageClient(transport)
|
|
1651
|
+
};
|
|
1652
|
+
};
|
|
1653
|
+
|
|
1654
|
+
export { AccountClient, CloudCatalogClient, CloudCreditClient, CloudResourcesClient, DEFAULT_ACCOUNT_ENDPOINT, DEFAULT_ENDPOINT, DEFAULT_TIMEOUT_MS, DEFAULT_USER_ENDPOINT, ETHEREUM_RPC_METHODS, ETHEREUM_SUBSCRIPTION_METHODS, ErpcAbortedError, ErpcBatchPolicyError, ErpcConfigError, ErpcError, ErpcHttpError, ErpcInvalidResponseError, ErpcJsonRpcError, ErpcTimeoutError, ErpcTransportError, EthereumSubscriptions, PendingRpcBatchRequest, PendingRpcRequest, PriceClient, RpcSubscription, SOLANA_ANALYTICS_METHODS, SOLANA_DAS_METHODS, SOLANA_ENHANCED_SUBSCRIPTION_METHODS, SOLANA_HISTORY_METHODS, SOLANA_LEADER_METHODS, SOLANA_RPC_METHODS, SolanaSubscriptions, UsageClient, createErpcClient, createErpcCloudClient };
|
|
1256
1655
|
//# sourceMappingURL=index.js.map
|
|
1257
1656
|
//# sourceMappingURL=index.js.map
|