@layr-labs/ecloud-sdk 0.2.0-dev.3 → 0.2.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 +34 -37
- package/dist/billing.cjs.map +1 -1
- package/dist/billing.d.cts +6 -3
- package/dist/billing.d.ts +6 -3
- package/dist/billing.js +511 -4
- package/dist/billing.js.map +1 -1
- package/dist/browser.cjs +2990 -0
- package/dist/browser.cjs.map +1 -0
- package/dist/browser.d.cts +42 -0
- package/dist/browser.d.ts +42 -0
- package/dist/browser.js +2922 -0
- package/dist/browser.js.map +1 -0
- package/dist/{compute-CF2HOXed.d.ts → compute-B85ikS78.d.ts} +15 -96
- package/dist/{compute-CbmjA8kJ.d.cts → compute-CC0R7HEu.d.cts} +15 -96
- package/dist/compute.cjs +655 -841
- 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 +6797 -7
- package/dist/compute.js.map +1 -1
- package/dist/eip7702-CXCYfOnk.d.ts +400 -0
- package/dist/eip7702-DeqoCP5b.d.cts +400 -0
- package/dist/{index-D2QufVB9.d.ts → index-D5oW73Dx.d.cts} +105 -15
- package/dist/{index-D2QufVB9.d.cts → index-D5oW73Dx.d.ts} +105 -15
- package/dist/index.cjs +1404 -1554
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +123 -388
- package/dist/index.d.ts +123 -388
- package/dist/index.js +7632 -124
- package/dist/index.js.map +1 -1
- package/package.json +6 -1
- package/dist/chunk-OUCNETHL.js +0 -434
- package/dist/chunk-OUCNETHL.js.map +0 -1
- package/dist/chunk-QN7KAUOB.js +0 -744
- package/dist/chunk-QN7KAUOB.js.map +0 -1
- package/dist/chunk-R44OVMCY.js +0 -6719
- package/dist/chunk-R44OVMCY.js.map +0 -1
package/dist/chunk-QN7KAUOB.js
DELETED
|
@@ -1,744 +0,0 @@
|
|
|
1
|
-
// src/client/common/config/environment.ts
|
|
2
|
-
var SEPOLIA_CHAIN_ID = 11155111;
|
|
3
|
-
var MAINNET_CHAIN_ID = 1;
|
|
4
|
-
var CommonAddresses = {
|
|
5
|
-
ERC7702Delegator: "0x63c0c19a282a1b52b07dd5a65b58948a07dae32b"
|
|
6
|
-
};
|
|
7
|
-
var ChainAddresses = {
|
|
8
|
-
[MAINNET_CHAIN_ID]: {
|
|
9
|
-
PermissionController: "0x25E5F8B1E7aDf44518d35D5B2271f114e081f0E5"
|
|
10
|
-
},
|
|
11
|
-
[SEPOLIA_CHAIN_ID]: {
|
|
12
|
-
PermissionController: "0x44632dfBdCb6D3E21EF613B0ca8A6A0c618F5a37"
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
var BILLING_ENVIRONMENTS = {
|
|
16
|
-
dev: {
|
|
17
|
-
billingApiServerURL: "https://billingapi-dev.eigencloud.xyz"
|
|
18
|
-
},
|
|
19
|
-
prod: {
|
|
20
|
-
billingApiServerURL: "https://billingapi.eigencloud.xyz"
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
var ENVIRONMENTS = {
|
|
24
|
-
"sepolia-dev": {
|
|
25
|
-
name: "sepolia",
|
|
26
|
-
build: "dev",
|
|
27
|
-
appControllerAddress: "0xa86DC1C47cb2518327fB4f9A1627F51966c83B92",
|
|
28
|
-
permissionControllerAddress: ChainAddresses[SEPOLIA_CHAIN_ID].PermissionController,
|
|
29
|
-
erc7702DelegatorAddress: CommonAddresses.ERC7702Delegator,
|
|
30
|
-
kmsServerURL: "http://10.128.0.57:8080",
|
|
31
|
-
userApiServerURL: "https://userapi-compute-sepolia-dev.eigencloud.xyz",
|
|
32
|
-
defaultRPCURL: "https://ethereum-sepolia-rpc.publicnode.com"
|
|
33
|
-
},
|
|
34
|
-
sepolia: {
|
|
35
|
-
name: "sepolia",
|
|
36
|
-
build: "prod",
|
|
37
|
-
appControllerAddress: "0x0dd810a6ffba6a9820a10d97b659f07d8d23d4E2",
|
|
38
|
-
permissionControllerAddress: ChainAddresses[SEPOLIA_CHAIN_ID].PermissionController,
|
|
39
|
-
erc7702DelegatorAddress: CommonAddresses.ERC7702Delegator,
|
|
40
|
-
kmsServerURL: "http://10.128.15.203:8080",
|
|
41
|
-
userApiServerURL: "https://userapi-compute-sepolia-prod.eigencloud.xyz",
|
|
42
|
-
defaultRPCURL: "https://ethereum-sepolia-rpc.publicnode.com"
|
|
43
|
-
},
|
|
44
|
-
"mainnet-alpha": {
|
|
45
|
-
name: "mainnet-alpha",
|
|
46
|
-
build: "prod",
|
|
47
|
-
appControllerAddress: "0xc38d35Fc995e75342A21CBd6D770305b142Fbe67",
|
|
48
|
-
permissionControllerAddress: ChainAddresses[MAINNET_CHAIN_ID].PermissionController,
|
|
49
|
-
erc7702DelegatorAddress: CommonAddresses.ERC7702Delegator,
|
|
50
|
-
kmsServerURL: "http://10.128.0.2:8080",
|
|
51
|
-
userApiServerURL: "https://userapi-compute.eigencloud.xyz",
|
|
52
|
-
defaultRPCURL: "https://ethereum-rpc.publicnode.com"
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
var CHAIN_ID_TO_ENVIRONMENT = {
|
|
56
|
-
[SEPOLIA_CHAIN_ID.toString()]: "sepolia",
|
|
57
|
-
[MAINNET_CHAIN_ID.toString()]: "mainnet-alpha"
|
|
58
|
-
};
|
|
59
|
-
function getEnvironmentConfig(environment, chainID) {
|
|
60
|
-
const env = ENVIRONMENTS[environment];
|
|
61
|
-
if (!env) {
|
|
62
|
-
throw new Error(`Unknown environment: ${environment}`);
|
|
63
|
-
}
|
|
64
|
-
if (!isEnvironmentAvailable(environment)) {
|
|
65
|
-
throw new Error(
|
|
66
|
-
`Environment ${environment} is not available in this build type. Available environments: ${getAvailableEnvironments().join(", ")}`
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
if (chainID) {
|
|
70
|
-
const expectedEnv = CHAIN_ID_TO_ENVIRONMENT[chainID.toString()];
|
|
71
|
-
if (expectedEnv && expectedEnv !== environment) {
|
|
72
|
-
throw new Error(`Environment ${environment} does not match chain ID ${chainID}`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
const resolvedChainID = chainID || (environment === "sepolia" || environment === "sepolia-dev" ? SEPOLIA_CHAIN_ID : MAINNET_CHAIN_ID);
|
|
76
|
-
return {
|
|
77
|
-
...env,
|
|
78
|
-
chainID: BigInt(resolvedChainID)
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
function getBillingEnvironmentConfig(build) {
|
|
82
|
-
const config = BILLING_ENVIRONMENTS[build];
|
|
83
|
-
if (!config) {
|
|
84
|
-
throw new Error(`Unknown billing environment: ${build}`);
|
|
85
|
-
}
|
|
86
|
-
return config;
|
|
87
|
-
}
|
|
88
|
-
function getBuildType() {
|
|
89
|
-
const buildTimeType = true ? "dev"?.toLowerCase() : void 0;
|
|
90
|
-
const runtimeType = process.env.BUILD_TYPE?.toLowerCase();
|
|
91
|
-
const buildType = buildTimeType || runtimeType;
|
|
92
|
-
if (buildType === "dev") {
|
|
93
|
-
return "dev";
|
|
94
|
-
}
|
|
95
|
-
return "prod";
|
|
96
|
-
}
|
|
97
|
-
function getAvailableEnvironments() {
|
|
98
|
-
const buildType = getBuildType();
|
|
99
|
-
if (buildType === "dev") {
|
|
100
|
-
return ["sepolia-dev"];
|
|
101
|
-
}
|
|
102
|
-
return ["sepolia", "mainnet-alpha"];
|
|
103
|
-
}
|
|
104
|
-
function isEnvironmentAvailable(environment) {
|
|
105
|
-
return getAvailableEnvironments().includes(environment);
|
|
106
|
-
}
|
|
107
|
-
function isMainnet(environmentConfig) {
|
|
108
|
-
return environmentConfig.chainID === BigInt(MAINNET_CHAIN_ID);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// src/client/common/utils/helpers.ts
|
|
112
|
-
import { extractChain } from "viem";
|
|
113
|
-
import { sepolia as sepolia2 } from "viem/chains";
|
|
114
|
-
|
|
115
|
-
// src/client/common/constants.ts
|
|
116
|
-
import { sepolia, mainnet } from "viem/chains";
|
|
117
|
-
var SUPPORTED_CHAINS = [mainnet, sepolia];
|
|
118
|
-
var DOCKER_PLATFORM = "linux/amd64";
|
|
119
|
-
var REGISTRY_PROPAGATION_WAIT_SECONDS = 3;
|
|
120
|
-
var LAYERED_DOCKERFILE_NAME = "Dockerfile.eigencompute";
|
|
121
|
-
var ENV_SOURCE_SCRIPT_NAME = "compute-source-env.sh";
|
|
122
|
-
var KMS_CLIENT_BINARY_NAME = "kms-client";
|
|
123
|
-
var KMS_SIGNING_KEY_NAME = "kms-signing-public-key.pem";
|
|
124
|
-
var TLS_KEYGEN_BINARY_NAME = "tls-keygen";
|
|
125
|
-
var CADDYFILE_NAME = "Caddyfile";
|
|
126
|
-
var LAYERED_BUILD_DIR_PREFIX = "ecloud-layered-build";
|
|
127
|
-
|
|
128
|
-
// src/client/common/utils/helpers.ts
|
|
129
|
-
function getChainFromID(chainID, fallback = sepolia2) {
|
|
130
|
-
const id = Number(chainID);
|
|
131
|
-
return extractChain({ chains: SUPPORTED_CHAINS, id }) || fallback;
|
|
132
|
-
}
|
|
133
|
-
function addHexPrefix(value) {
|
|
134
|
-
return value.startsWith("0x") ? value : `0x${value}`;
|
|
135
|
-
}
|
|
136
|
-
function stripHexPrefix(value) {
|
|
137
|
-
return value.startsWith("0x") ? value.slice(2) : value;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// src/client/common/utils/userapi.ts
|
|
141
|
-
import axios from "axios";
|
|
142
|
-
import FormData from "form-data";
|
|
143
|
-
import { createPublicClient, http } from "viem";
|
|
144
|
-
|
|
145
|
-
// src/client/common/utils/auth.ts
|
|
146
|
-
import { parseAbi } from "viem";
|
|
147
|
-
var APP_CONTROLLER_ABI = parseAbi([
|
|
148
|
-
"function calculateApiPermissionDigestHash(bytes4 permission, uint256 expiry) view returns (bytes32)"
|
|
149
|
-
]);
|
|
150
|
-
async function calculatePermissionSignature(options) {
|
|
151
|
-
const { permission, expiry, appControllerAddress, publicClient, account } = options;
|
|
152
|
-
const digest = await publicClient.readContract({
|
|
153
|
-
address: appControllerAddress,
|
|
154
|
-
abi: APP_CONTROLLER_ABI,
|
|
155
|
-
functionName: "calculateApiPermissionDigestHash",
|
|
156
|
-
args: [permission, expiry]
|
|
157
|
-
});
|
|
158
|
-
const signature = await account.signMessage({
|
|
159
|
-
message: { raw: digest }
|
|
160
|
-
});
|
|
161
|
-
return { signature, digest };
|
|
162
|
-
}
|
|
163
|
-
async function calculateBillingAuthSignature(options) {
|
|
164
|
-
const { account, product, expiry } = options;
|
|
165
|
-
const signature = await account.signTypedData({
|
|
166
|
-
domain: {
|
|
167
|
-
name: "EigenCloud Billing API",
|
|
168
|
-
version: "1"
|
|
169
|
-
},
|
|
170
|
-
types: {
|
|
171
|
-
BillingAuth: [
|
|
172
|
-
{ name: "product", type: "string" },
|
|
173
|
-
{ name: "expiry", type: "uint256" }
|
|
174
|
-
]
|
|
175
|
-
},
|
|
176
|
-
primaryType: "BillingAuth",
|
|
177
|
-
message: {
|
|
178
|
-
product,
|
|
179
|
-
expiry
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
return { signature, expiry };
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// src/client/common/utils/userapi.ts
|
|
186
|
-
import { privateKeyToAccount } from "viem/accounts";
|
|
187
|
-
function isJsonObject(value) {
|
|
188
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
189
|
-
}
|
|
190
|
-
function readString(obj, key) {
|
|
191
|
-
const v = obj[key];
|
|
192
|
-
return typeof v === "string" ? v : void 0;
|
|
193
|
-
}
|
|
194
|
-
function readNumber(obj, key) {
|
|
195
|
-
const v = obj[key];
|
|
196
|
-
return typeof v === "number" && Number.isFinite(v) ? v : void 0;
|
|
197
|
-
}
|
|
198
|
-
var MAX_ADDRESS_COUNT = 5;
|
|
199
|
-
var CanViewAppLogsPermission = "0x2fd3f2fe";
|
|
200
|
-
var CanViewSensitiveAppInfoPermission = "0x0e67b22f";
|
|
201
|
-
var CanUpdateAppProfilePermission = "0x036fef61";
|
|
202
|
-
function getDefaultClientId() {
|
|
203
|
-
const version = true ? "0.2.0-dev.3" : "0.0.0";
|
|
204
|
-
return `ecloud-sdk/v${version}`;
|
|
205
|
-
}
|
|
206
|
-
var UserApiClient = class {
|
|
207
|
-
constructor(config, privateKey, rpcUrl, clientId) {
|
|
208
|
-
this.config = config;
|
|
209
|
-
if (privateKey) {
|
|
210
|
-
const privateKeyHex = addHexPrefix(privateKey);
|
|
211
|
-
this.account = privateKeyToAccount(privateKeyHex);
|
|
212
|
-
}
|
|
213
|
-
this.rpcUrl = rpcUrl;
|
|
214
|
-
this.clientId = clientId || getDefaultClientId();
|
|
215
|
-
}
|
|
216
|
-
async getInfos(appIDs, addressCount = 1) {
|
|
217
|
-
const count = Math.min(addressCount, MAX_ADDRESS_COUNT);
|
|
218
|
-
const endpoint = `${this.config.userApiServerURL}/info`;
|
|
219
|
-
const url = `${endpoint}?${new URLSearchParams({ apps: appIDs.join(",") })}`;
|
|
220
|
-
const res = await this.makeAuthenticatedRequest(url, CanViewSensitiveAppInfoPermission);
|
|
221
|
-
const result = await res.json();
|
|
222
|
-
return result.apps.map((app, i) => {
|
|
223
|
-
const evmAddresses = app.addresses?.data?.evmAddresses?.slice(0, count) || [];
|
|
224
|
-
const solanaAddresses = app.addresses?.data?.solanaAddresses?.slice(0, count) || [];
|
|
225
|
-
return {
|
|
226
|
-
address: appIDs[i],
|
|
227
|
-
status: app.app_status,
|
|
228
|
-
ip: app.ip,
|
|
229
|
-
machineType: app.machine_type,
|
|
230
|
-
profile: app.profile,
|
|
231
|
-
metrics: app.metrics,
|
|
232
|
-
evmAddresses,
|
|
233
|
-
solanaAddresses
|
|
234
|
-
};
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Get app details from UserAPI (includes releases and build/provenance info when available).
|
|
239
|
-
*
|
|
240
|
-
* Endpoint: GET /apps/:appAddress
|
|
241
|
-
*/
|
|
242
|
-
async getApp(appAddress) {
|
|
243
|
-
const endpoint = `${this.config.userApiServerURL}/apps/${appAddress}`;
|
|
244
|
-
const res = await this.makeAuthenticatedRequest(endpoint);
|
|
245
|
-
const raw = await res.json();
|
|
246
|
-
if (!isJsonObject(raw)) {
|
|
247
|
-
throw new Error("Unexpected /apps/:id response: expected object");
|
|
248
|
-
}
|
|
249
|
-
const id = readString(raw, "id");
|
|
250
|
-
if (!id) {
|
|
251
|
-
throw new Error("Unexpected /apps/:id response: missing 'id'");
|
|
252
|
-
}
|
|
253
|
-
const releasesRaw = raw.releases;
|
|
254
|
-
const releases = Array.isArray(releasesRaw) ? releasesRaw.map((r) => transformAppRelease(r)).filter((r) => !!r) : [];
|
|
255
|
-
return {
|
|
256
|
-
id,
|
|
257
|
-
creator: readString(raw, "creator"),
|
|
258
|
-
contractStatus: readString(raw, "contract_status") ?? readString(raw, "contractStatus"),
|
|
259
|
-
releases
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Get available SKUs (instance types) from UserAPI
|
|
264
|
-
*/
|
|
265
|
-
async getSKUs() {
|
|
266
|
-
const endpoint = `${this.config.userApiServerURL}/skus`;
|
|
267
|
-
const response = await this.makeAuthenticatedRequest(endpoint);
|
|
268
|
-
const result = await response.json();
|
|
269
|
-
return {
|
|
270
|
-
skus: result.skus || result.SKUs || []
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Get logs for an app
|
|
275
|
-
*/
|
|
276
|
-
async getLogs(appID) {
|
|
277
|
-
const endpoint = `${this.config.userApiServerURL}/logs/${appID}`;
|
|
278
|
-
const response = await this.makeAuthenticatedRequest(endpoint, CanViewAppLogsPermission);
|
|
279
|
-
return await response.text();
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Get statuses for apps
|
|
283
|
-
*/
|
|
284
|
-
async getStatuses(appIDs) {
|
|
285
|
-
const endpoint = `${this.config.userApiServerURL}/status`;
|
|
286
|
-
const url = `${endpoint}?${new URLSearchParams({ apps: appIDs.join(",") })}`;
|
|
287
|
-
const response = await this.makeAuthenticatedRequest(url);
|
|
288
|
-
const result = await response.json();
|
|
289
|
-
const apps = result.apps || result.Apps || [];
|
|
290
|
-
return apps.map((app, i) => ({
|
|
291
|
-
address: app.address || appIDs[i],
|
|
292
|
-
status: app.status || app.Status || ""
|
|
293
|
-
}));
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* Upload app profile information with optional image
|
|
297
|
-
*/
|
|
298
|
-
async uploadAppProfile(appAddress, name, website, description, xURL, imagePath) {
|
|
299
|
-
const endpoint = `${this.config.userApiServerURL}/apps/${appAddress}/profile`;
|
|
300
|
-
const formData = new FormData();
|
|
301
|
-
formData.append("name", name);
|
|
302
|
-
if (website) {
|
|
303
|
-
formData.append("website", website);
|
|
304
|
-
}
|
|
305
|
-
if (description) {
|
|
306
|
-
formData.append("description", description);
|
|
307
|
-
}
|
|
308
|
-
if (xURL) {
|
|
309
|
-
formData.append("xURL", xURL);
|
|
310
|
-
}
|
|
311
|
-
if (imagePath) {
|
|
312
|
-
const fs = await import("fs");
|
|
313
|
-
const path2 = await import("path");
|
|
314
|
-
const fileName = path2.basename(imagePath);
|
|
315
|
-
const fileBuffer = fs.readFileSync(imagePath);
|
|
316
|
-
formData.append("image", fileBuffer, fileName);
|
|
317
|
-
}
|
|
318
|
-
const headers = {
|
|
319
|
-
"x-client-id": this.clientId,
|
|
320
|
-
...formData.getHeaders()
|
|
321
|
-
};
|
|
322
|
-
if (this.account) {
|
|
323
|
-
const expiry = BigInt(Math.floor(Date.now() / 1e3) + 5 * 60);
|
|
324
|
-
const authHeaders = await this.generateAuthHeaders(CanUpdateAppProfilePermission, expiry);
|
|
325
|
-
Object.assign(headers, authHeaders);
|
|
326
|
-
}
|
|
327
|
-
try {
|
|
328
|
-
const response = await axios.post(endpoint, formData, {
|
|
329
|
-
headers,
|
|
330
|
-
maxRedirects: 0,
|
|
331
|
-
validateStatus: () => true,
|
|
332
|
-
// Don't throw on any status
|
|
333
|
-
maxContentLength: Infinity,
|
|
334
|
-
// Allow large file uploads
|
|
335
|
-
maxBodyLength: Infinity
|
|
336
|
-
// Allow large file uploads
|
|
337
|
-
});
|
|
338
|
-
const status = response.status;
|
|
339
|
-
if (status !== 200 && status !== 201) {
|
|
340
|
-
const body = typeof response.data === "string" ? response.data : JSON.stringify(response.data);
|
|
341
|
-
if (status === 403 && body.includes("Cloudflare") && body.includes("challenge-platform")) {
|
|
342
|
-
throw new Error(
|
|
343
|
-
`Cloudflare protection is blocking the request. This is likely due to bot detection.
|
|
344
|
-
Status: ${status}`
|
|
345
|
-
);
|
|
346
|
-
}
|
|
347
|
-
throw new Error(
|
|
348
|
-
`UserAPI request failed: ${status} ${status >= 200 && status < 300 ? "OK" : "Error"} - ${body.substring(0, 500)}${body.length > 500 ? "..." : ""}`
|
|
349
|
-
);
|
|
350
|
-
}
|
|
351
|
-
return response.data;
|
|
352
|
-
} catch (error) {
|
|
353
|
-
if (error.message?.includes("fetch failed") || error.message?.includes("ECONNREFUSED") || error.message?.includes("ENOTFOUND") || error.cause) {
|
|
354
|
-
const cause = error.cause?.message || error.cause || error.message;
|
|
355
|
-
throw new Error(
|
|
356
|
-
`Failed to connect to UserAPI at ${endpoint}: ${cause}
|
|
357
|
-
Please check:
|
|
358
|
-
1. Your internet connection
|
|
359
|
-
2. The API server is accessible: ${this.config.userApiServerURL}
|
|
360
|
-
3. Firewall/proxy settings`
|
|
361
|
-
);
|
|
362
|
-
}
|
|
363
|
-
throw error;
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
async makeAuthenticatedRequest(url, permission) {
|
|
367
|
-
const headers = {
|
|
368
|
-
"x-client-id": this.clientId
|
|
369
|
-
};
|
|
370
|
-
if (permission && this.account) {
|
|
371
|
-
const expiry = BigInt(Math.floor(Date.now() / 1e3) + 5 * 60);
|
|
372
|
-
const authHeaders = await this.generateAuthHeaders(permission, expiry);
|
|
373
|
-
Object.assign(headers, authHeaders);
|
|
374
|
-
}
|
|
375
|
-
try {
|
|
376
|
-
const response = await axios.get(url, {
|
|
377
|
-
headers,
|
|
378
|
-
maxRedirects: 0,
|
|
379
|
-
validateStatus: () => true
|
|
380
|
-
// Don't throw on any status
|
|
381
|
-
});
|
|
382
|
-
const status = response.status;
|
|
383
|
-
const statusText = status >= 200 && status < 300 ? "OK" : "Error";
|
|
384
|
-
if (status < 200 || status >= 300) {
|
|
385
|
-
const body = typeof response.data === "string" ? response.data : JSON.stringify(response.data);
|
|
386
|
-
throw new Error(`UserAPI request failed: ${status} ${statusText} - ${body}`);
|
|
387
|
-
}
|
|
388
|
-
return {
|
|
389
|
-
json: async () => response.data,
|
|
390
|
-
text: async () => typeof response.data === "string" ? response.data : JSON.stringify(response.data)
|
|
391
|
-
};
|
|
392
|
-
} catch (error) {
|
|
393
|
-
if (error.message?.includes("fetch failed") || error.message?.includes("ECONNREFUSED") || error.message?.includes("ENOTFOUND") || error.cause) {
|
|
394
|
-
const cause = error.cause?.message || error.cause || error.message;
|
|
395
|
-
throw new Error(
|
|
396
|
-
`Failed to connect to UserAPI at ${url}: ${cause}
|
|
397
|
-
Please check:
|
|
398
|
-
1. Your internet connection
|
|
399
|
-
2. The API server is accessible: ${this.config.userApiServerURL}
|
|
400
|
-
3. Firewall/proxy settings`
|
|
401
|
-
);
|
|
402
|
-
}
|
|
403
|
-
throw error;
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
/**
|
|
407
|
-
* Generate authentication headers for UserAPI requests
|
|
408
|
-
*/
|
|
409
|
-
async generateAuthHeaders(permission, expiry) {
|
|
410
|
-
if (!this.account) {
|
|
411
|
-
throw new Error("Private key required for authenticated requests");
|
|
412
|
-
}
|
|
413
|
-
if (!this.rpcUrl) {
|
|
414
|
-
throw new Error("RPC URL required for authenticated requests");
|
|
415
|
-
}
|
|
416
|
-
const chain = getChainFromID(this.config.chainID);
|
|
417
|
-
const publicClient = createPublicClient({
|
|
418
|
-
chain,
|
|
419
|
-
transport: http(this.rpcUrl)
|
|
420
|
-
});
|
|
421
|
-
const { signature } = await calculatePermissionSignature({
|
|
422
|
-
permission,
|
|
423
|
-
expiry,
|
|
424
|
-
appControllerAddress: this.config.appControllerAddress,
|
|
425
|
-
publicClient,
|
|
426
|
-
account: this.account
|
|
427
|
-
});
|
|
428
|
-
return {
|
|
429
|
-
Authorization: `Bearer ${stripHexPrefix(signature)}`,
|
|
430
|
-
"X-eigenx-expiry": expiry.toString()
|
|
431
|
-
};
|
|
432
|
-
}
|
|
433
|
-
};
|
|
434
|
-
function transformAppReleaseBuild(raw) {
|
|
435
|
-
if (!isJsonObject(raw)) return void 0;
|
|
436
|
-
const depsRaw = raw.dependencies;
|
|
437
|
-
const deps = isJsonObject(depsRaw) ? Object.fromEntries(
|
|
438
|
-
Object.entries(depsRaw).flatMap(([digest, depRaw]) => {
|
|
439
|
-
const parsed = transformAppReleaseBuild(depRaw);
|
|
440
|
-
return parsed ? [[digest, parsed]] : [];
|
|
441
|
-
})
|
|
442
|
-
) : void 0;
|
|
443
|
-
return {
|
|
444
|
-
buildId: readString(raw, "build_id") ?? readString(raw, "buildId"),
|
|
445
|
-
billingAddress: readString(raw, "billing_address") ?? readString(raw, "billingAddress"),
|
|
446
|
-
repoUrl: readString(raw, "repo_url") ?? readString(raw, "repoUrl"),
|
|
447
|
-
gitRef: readString(raw, "git_ref") ?? readString(raw, "gitRef"),
|
|
448
|
-
status: readString(raw, "status"),
|
|
449
|
-
buildType: readString(raw, "build_type") ?? readString(raw, "buildType"),
|
|
450
|
-
imageName: readString(raw, "image_name") ?? readString(raw, "imageName"),
|
|
451
|
-
imageDigest: readString(raw, "image_digest") ?? readString(raw, "imageDigest"),
|
|
452
|
-
imageUrl: readString(raw, "image_url") ?? readString(raw, "imageUrl"),
|
|
453
|
-
provenanceJson: raw.provenance_json ?? raw.provenanceJson,
|
|
454
|
-
provenanceSignature: readString(raw, "provenance_signature") ?? readString(raw, "provenanceSignature"),
|
|
455
|
-
createdAt: readString(raw, "created_at") ?? readString(raw, "createdAt"),
|
|
456
|
-
updatedAt: readString(raw, "updated_at") ?? readString(raw, "updatedAt"),
|
|
457
|
-
errorMessage: readString(raw, "error_message") ?? readString(raw, "errorMessage"),
|
|
458
|
-
dependencies: deps
|
|
459
|
-
};
|
|
460
|
-
}
|
|
461
|
-
function transformAppRelease(raw) {
|
|
462
|
-
if (!isJsonObject(raw)) return void 0;
|
|
463
|
-
return {
|
|
464
|
-
appId: readString(raw, "appId") ?? readString(raw, "app_id"),
|
|
465
|
-
rmsReleaseId: readString(raw, "rmsReleaseId") ?? readString(raw, "rms_release_id"),
|
|
466
|
-
imageDigest: readString(raw, "imageDigest") ?? readString(raw, "image_digest"),
|
|
467
|
-
registryUrl: readString(raw, "registryUrl") ?? readString(raw, "registry_url"),
|
|
468
|
-
publicEnv: readString(raw, "publicEnv") ?? readString(raw, "public_env"),
|
|
469
|
-
encryptedEnv: readString(raw, "encryptedEnv") ?? readString(raw, "encrypted_env"),
|
|
470
|
-
upgradeByTime: readNumber(raw, "upgradeByTime") ?? readNumber(raw, "upgrade_by_time"),
|
|
471
|
-
createdAt: readString(raw, "createdAt") ?? readString(raw, "created_at"),
|
|
472
|
-
createdAtBlock: readString(raw, "createdAtBlock") ?? readString(raw, "created_at_block"),
|
|
473
|
-
build: raw.build ? transformAppReleaseBuild(raw.build) : void 0
|
|
474
|
-
};
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
// src/client/common/utils/billing.ts
|
|
478
|
-
function isSubscriptionActive(status) {
|
|
479
|
-
return status === "active" || status === "trialing";
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
// src/client/common/telemetry/noop.ts
|
|
483
|
-
var NoopClient = class {
|
|
484
|
-
/**
|
|
485
|
-
* AddMetric implements the TelemetryClient interface
|
|
486
|
-
*/
|
|
487
|
-
async addMetric(_metric) {
|
|
488
|
-
}
|
|
489
|
-
/**
|
|
490
|
-
* Close implements the TelemetryClient interface
|
|
491
|
-
*/
|
|
492
|
-
async close() {
|
|
493
|
-
}
|
|
494
|
-
};
|
|
495
|
-
function isNoopClient(client) {
|
|
496
|
-
return client instanceof NoopClient;
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
// src/client/common/telemetry/posthog.ts
|
|
500
|
-
import { PostHog } from "posthog-node";
|
|
501
|
-
var PostHogClient = class {
|
|
502
|
-
constructor(environment, namespace, apiKey, endpoint) {
|
|
503
|
-
this.namespace = namespace;
|
|
504
|
-
this.appEnvironment = environment;
|
|
505
|
-
const host = endpoint || "https://us.i.posthog.com";
|
|
506
|
-
this.client = new PostHog(apiKey, {
|
|
507
|
-
host,
|
|
508
|
-
flushAt: 1,
|
|
509
|
-
// Flush immediately for CLI/SDK usage
|
|
510
|
-
flushInterval: 0
|
|
511
|
-
// Disable interval flushing
|
|
512
|
-
});
|
|
513
|
-
this.client.identify({
|
|
514
|
-
distinctId: environment.userUUID,
|
|
515
|
-
properties: {
|
|
516
|
-
os: environment.os,
|
|
517
|
-
arch: environment.arch,
|
|
518
|
-
...environment.cliVersion ? { cliVersion: environment.cliVersion } : {}
|
|
519
|
-
}
|
|
520
|
-
});
|
|
521
|
-
}
|
|
522
|
-
/**
|
|
523
|
-
* AddMetric implements the TelemetryClient interface
|
|
524
|
-
*/
|
|
525
|
-
async addMetric(metric) {
|
|
526
|
-
try {
|
|
527
|
-
const props = {
|
|
528
|
-
name: metric.name,
|
|
529
|
-
value: metric.value
|
|
530
|
-
};
|
|
531
|
-
for (const [k, v] of Object.entries(metric.dimensions)) {
|
|
532
|
-
props[k] = v;
|
|
533
|
-
}
|
|
534
|
-
this.client.capture({
|
|
535
|
-
distinctId: this.appEnvironment.userUUID,
|
|
536
|
-
event: this.namespace,
|
|
537
|
-
properties: props
|
|
538
|
-
});
|
|
539
|
-
} catch {
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
/**
|
|
543
|
-
* Close implements the TelemetryClient interface
|
|
544
|
-
*/
|
|
545
|
-
async close() {
|
|
546
|
-
try {
|
|
547
|
-
this.client.shutdown();
|
|
548
|
-
} catch {
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
};
|
|
552
|
-
function getPostHogAPIKey() {
|
|
553
|
-
if (process.env.ECLOUD_POSTHOG_KEY) {
|
|
554
|
-
return process.env.ECLOUD_POSTHOG_KEY;
|
|
555
|
-
}
|
|
556
|
-
return true ? "phc_BiKfywNft5iBI8N7MxmuVCkb4GGZj4mDFXYPmOPUAI8" : void 0;
|
|
557
|
-
}
|
|
558
|
-
function getPostHogEndpoint() {
|
|
559
|
-
return process.env.ECLOUD_POSTHOG_ENDPOINT || "https://us.i.posthog.com";
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
// src/client/common/telemetry/metricsContext.ts
|
|
563
|
-
function createMetricsContext() {
|
|
564
|
-
return {
|
|
565
|
-
startTime: /* @__PURE__ */ new Date(),
|
|
566
|
-
metrics: [],
|
|
567
|
-
properties: {}
|
|
568
|
-
};
|
|
569
|
-
}
|
|
570
|
-
function addMetric(context, name, value) {
|
|
571
|
-
addMetricWithDimensions(context, name, value, {});
|
|
572
|
-
}
|
|
573
|
-
function addMetricWithDimensions(context, name, value, dimensions) {
|
|
574
|
-
context.metrics.push({
|
|
575
|
-
name,
|
|
576
|
-
value,
|
|
577
|
-
dimensions
|
|
578
|
-
});
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
// src/client/common/telemetry/index.ts
|
|
582
|
-
import * as os from "os";
|
|
583
|
-
|
|
584
|
-
// src/client/common/telemetry/wrapper.ts
|
|
585
|
-
import { randomUUID } from "crypto";
|
|
586
|
-
function generateRandomUUID() {
|
|
587
|
-
return randomUUID();
|
|
588
|
-
}
|
|
589
|
-
async function withSDKTelemetry(options, action) {
|
|
590
|
-
if (options.skipTelemetry) {
|
|
591
|
-
return action();
|
|
592
|
-
}
|
|
593
|
-
const userUUID = options.userUUID || generateRandomUUID();
|
|
594
|
-
const environment = createAppEnvironment(userUUID);
|
|
595
|
-
const client = createTelemetryClient(environment, "ecloud-sdk", {
|
|
596
|
-
telemetryEnabled: options.telemetryEnabled,
|
|
597
|
-
apiKey: options.apiKey,
|
|
598
|
-
endpoint: options.endpoint
|
|
599
|
-
});
|
|
600
|
-
const metrics = createMetricsContext();
|
|
601
|
-
metrics.properties["source"] = "ecloud-sdk";
|
|
602
|
-
metrics.properties["function"] = options.functionName;
|
|
603
|
-
if (options.properties) {
|
|
604
|
-
Object.assign(metrics.properties, options.properties);
|
|
605
|
-
}
|
|
606
|
-
addMetric(metrics, "Count", 1);
|
|
607
|
-
let actionError;
|
|
608
|
-
let result;
|
|
609
|
-
try {
|
|
610
|
-
result = await action();
|
|
611
|
-
return result;
|
|
612
|
-
} catch (err) {
|
|
613
|
-
actionError = err instanceof Error ? err : new Error(String(err));
|
|
614
|
-
throw err;
|
|
615
|
-
} finally {
|
|
616
|
-
const resultValue = actionError ? "Failure" : "Success";
|
|
617
|
-
const dimensions = {};
|
|
618
|
-
if (actionError) {
|
|
619
|
-
dimensions["error"] = actionError.message;
|
|
620
|
-
}
|
|
621
|
-
addMetricWithDimensions(metrics, resultValue, 1, dimensions);
|
|
622
|
-
const duration = Date.now() - metrics.startTime.getTime();
|
|
623
|
-
addMetric(metrics, "DurationMilliseconds", duration);
|
|
624
|
-
try {
|
|
625
|
-
await emitMetrics(client, metrics);
|
|
626
|
-
await client.close();
|
|
627
|
-
} catch {
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
// src/client/common/telemetry/index.ts
|
|
633
|
-
function createTelemetryClient(environment, namespace, options) {
|
|
634
|
-
const telemetryEnabled = options?.telemetryEnabled === true;
|
|
635
|
-
if (!telemetryEnabled) {
|
|
636
|
-
return new NoopClient();
|
|
637
|
-
}
|
|
638
|
-
const resolvedApiKey = options?.apiKey || getPostHogAPIKey();
|
|
639
|
-
if (!resolvedApiKey) {
|
|
640
|
-
return new NoopClient();
|
|
641
|
-
}
|
|
642
|
-
const endpoint = options?.endpoint || getPostHogEndpoint();
|
|
643
|
-
try {
|
|
644
|
-
return new PostHogClient(environment, namespace, resolvedApiKey, endpoint);
|
|
645
|
-
} catch {
|
|
646
|
-
return new NoopClient();
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
function createAppEnvironment(userUUID, cliVersion, osOverride, archOverride) {
|
|
650
|
-
return {
|
|
651
|
-
userUUID,
|
|
652
|
-
cliVersion,
|
|
653
|
-
os: osOverride || os.platform(),
|
|
654
|
-
arch: archOverride || os.arch()
|
|
655
|
-
};
|
|
656
|
-
}
|
|
657
|
-
async function emitMetrics(client, context) {
|
|
658
|
-
if (isNoopClient(client)) {
|
|
659
|
-
return;
|
|
660
|
-
}
|
|
661
|
-
for (const metric of context.metrics) {
|
|
662
|
-
const dimensions = {
|
|
663
|
-
...metric.dimensions,
|
|
664
|
-
...context.properties
|
|
665
|
-
};
|
|
666
|
-
const metricWithProperties = {
|
|
667
|
-
...metric,
|
|
668
|
-
dimensions
|
|
669
|
-
};
|
|
670
|
-
try {
|
|
671
|
-
await client.addMetric(metricWithProperties);
|
|
672
|
-
} catch {
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
// src/client/common/utils/logger.ts
|
|
678
|
-
var defaultLogger = {
|
|
679
|
-
info: (...args) => console.info(...args),
|
|
680
|
-
warn: (...args) => console.warn(...args),
|
|
681
|
-
error: (...args) => console.error(...args),
|
|
682
|
-
debug: (...args) => console.debug(...args)
|
|
683
|
-
};
|
|
684
|
-
var getLogger = (verbose) => ({
|
|
685
|
-
info: (...args) => console.info(...args),
|
|
686
|
-
warn: (...args) => console.warn(...args),
|
|
687
|
-
error: (...args) => console.error(...args),
|
|
688
|
-
debug: (...args) => verbose && console.debug(...args)
|
|
689
|
-
});
|
|
690
|
-
|
|
691
|
-
// src/client/common/utils/dirname.ts
|
|
692
|
-
import * as path from "path";
|
|
693
|
-
import { fileURLToPath } from "url";
|
|
694
|
-
function getDirname() {
|
|
695
|
-
if (typeof __dirname !== "undefined") {
|
|
696
|
-
return __dirname;
|
|
697
|
-
}
|
|
698
|
-
try {
|
|
699
|
-
const metaUrl = import.meta.url;
|
|
700
|
-
return path.dirname(fileURLToPath(metaUrl));
|
|
701
|
-
} catch {
|
|
702
|
-
return process.cwd();
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
export {
|
|
707
|
-
calculateBillingAuthSignature,
|
|
708
|
-
getEnvironmentConfig,
|
|
709
|
-
getBillingEnvironmentConfig,
|
|
710
|
-
getBuildType,
|
|
711
|
-
getAvailableEnvironments,
|
|
712
|
-
isEnvironmentAvailable,
|
|
713
|
-
isMainnet,
|
|
714
|
-
defaultLogger,
|
|
715
|
-
getLogger,
|
|
716
|
-
DOCKER_PLATFORM,
|
|
717
|
-
REGISTRY_PROPAGATION_WAIT_SECONDS,
|
|
718
|
-
LAYERED_DOCKERFILE_NAME,
|
|
719
|
-
ENV_SOURCE_SCRIPT_NAME,
|
|
720
|
-
KMS_CLIENT_BINARY_NAME,
|
|
721
|
-
KMS_SIGNING_KEY_NAME,
|
|
722
|
-
TLS_KEYGEN_BINARY_NAME,
|
|
723
|
-
CADDYFILE_NAME,
|
|
724
|
-
LAYERED_BUILD_DIR_PREFIX,
|
|
725
|
-
getChainFromID,
|
|
726
|
-
addHexPrefix,
|
|
727
|
-
stripHexPrefix,
|
|
728
|
-
UserApiClient,
|
|
729
|
-
getDirname,
|
|
730
|
-
isSubscriptionActive,
|
|
731
|
-
NoopClient,
|
|
732
|
-
isNoopClient,
|
|
733
|
-
PostHogClient,
|
|
734
|
-
getPostHogAPIKey,
|
|
735
|
-
getPostHogEndpoint,
|
|
736
|
-
createMetricsContext,
|
|
737
|
-
addMetric,
|
|
738
|
-
addMetricWithDimensions,
|
|
739
|
-
createTelemetryClient,
|
|
740
|
-
createAppEnvironment,
|
|
741
|
-
emitMetrics,
|
|
742
|
-
withSDKTelemetry
|
|
743
|
-
};
|
|
744
|
-
//# sourceMappingURL=chunk-QN7KAUOB.js.map
|