@phala/cloud 0.0.1 → 0.0.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/dist/actions/add_compose_hash.d.ts +63 -0
- package/dist/actions/add_compose_hash.d.ts.map +1 -0
- package/dist/actions/commit_cvm_compose_file_update.d.ts +143 -0
- package/dist/actions/commit_cvm_compose_file_update.d.ts.map +1 -0
- package/dist/actions/commit_cvm_provision.d.ts +209 -0
- package/dist/actions/commit_cvm_provision.d.ts.map +1 -0
- package/dist/actions/deploy_app_auth.d.ts +164 -0
- package/dist/actions/deploy_app_auth.d.ts.map +1 -0
- package/dist/actions/get_app_env_encrypt_pubkey.d.ts +30 -0
- package/dist/actions/get_app_env_encrypt_pubkey.d.ts.map +1 -0
- package/dist/actions/get_available_nodes.d.ts +572 -0
- package/dist/actions/get_available_nodes.d.ts.map +1 -0
- package/dist/actions/get_current_user.d.ts +92 -0
- package/dist/actions/get_current_user.d.ts.map +1 -0
- package/dist/actions/get_cvm_compose_file.d.ts +190 -0
- package/dist/actions/get_cvm_compose_file.d.ts.map +1 -0
- package/dist/actions/get_cvm_info.d.ts +73 -0
- package/dist/actions/get_cvm_info.d.ts.map +1 -0
- package/dist/actions/get_cvm_list.d.ts +392 -0
- package/dist/actions/get_cvm_list.d.ts.map +1 -0
- package/dist/actions/get_kms_info.d.ts +34 -0
- package/dist/actions/get_kms_info.d.ts.map +1 -0
- package/dist/actions/get_kms_list.d.ts +82 -0
- package/dist/actions/get_kms_list.d.ts.map +1 -0
- package/dist/actions/index.d.ts +15 -0
- package/dist/actions/index.d.ts.map +1 -0
- package/dist/actions/provision_cvm.d.ts +228 -0
- package/dist/actions/provision_cvm.d.ts.map +1 -0
- package/dist/actions/provision_cvm_compose_file_update.d.ts +313 -0
- package/dist/actions/provision_cvm_compose_file_update.d.ts.map +1 -0
- package/dist/client.d.ts +80 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/index.d.ts +9 -2978
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +91 -20
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +89 -18
- package/dist/index.mjs.map +1 -0
- package/dist/parse_dotenv.d.ts +14 -0
- package/dist/parse_dotenv.d.ts.map +1 -0
- package/dist/types/client.d.ts +126 -0
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/common.d.ts +17 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/cvm_info.d.ts +486 -0
- package/dist/types/cvm_info.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/kms_info.d.ts +28 -0
- package/dist/types/kms_info.d.ts.map +1 -0
- package/dist/utils/as-hex.d.ts +17 -0
- package/dist/utils/as-hex.d.ts.map +1 -0
- package/dist/utils/client-factories.d.ts +44 -0
- package/dist/utils/client-factories.d.ts.map +1 -0
- package/dist/utils/get_compose_hash.d.ts +15 -0
- package/dist/utils/get_compose_hash.d.ts.map +1 -0
- package/dist/utils/get_error_message.d.ts +3 -0
- package/dist/utils/get_error_message.d.ts.map +1 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/network.d.ts +101 -0
- package/dist/utils/network.d.ts.map +1 -0
- package/dist/utils/transaction.d.ts +81 -0
- package/dist/utils/transaction.d.ts.map +1 -0
- package/dist/utils/validate-parameters.d.ts +20 -0
- package/dist/utils/validate-parameters.d.ts.map +1 -0
- package/package.json +10 -4
- package/dist/index.d.mts +0 -2978
package/dist/index.mjs
CHANGED
|
@@ -71,13 +71,15 @@ var RequestError = class _RequestError extends Error {
|
|
|
71
71
|
};
|
|
72
72
|
|
|
73
73
|
// src/client.ts
|
|
74
|
+
var SUPPORTED_API_VERSIONS = ["2025-05-31"];
|
|
74
75
|
var Client = class {
|
|
75
76
|
constructor(config = {}) {
|
|
76
77
|
const resolvedConfig = {
|
|
77
78
|
...config,
|
|
78
|
-
apiKey: config.apiKey || process
|
|
79
|
-
baseURL: config.baseURL || process
|
|
79
|
+
apiKey: config.apiKey || process?.env?.PHALA_CLOUD_API_KEY,
|
|
80
|
+
baseURL: config.baseURL || process?.env?.PHALA_CLOUD_API_PREFIX || "https://cloud-api.phala.network/api/v1"
|
|
80
81
|
};
|
|
82
|
+
const version = resolvedConfig.version && SUPPORTED_API_VERSIONS.includes(resolvedConfig.version) ? resolvedConfig.version : SUPPORTED_API_VERSIONS[0];
|
|
81
83
|
this.config = resolvedConfig;
|
|
82
84
|
if (!resolvedConfig.apiKey) {
|
|
83
85
|
throw new Error(
|
|
@@ -90,6 +92,7 @@ var Client = class {
|
|
|
90
92
|
timeout: timeout || 3e4,
|
|
91
93
|
headers: {
|
|
92
94
|
"X-API-Key": apiKey,
|
|
95
|
+
"X-Phala-Version": version,
|
|
93
96
|
"Content-Type": "application/json",
|
|
94
97
|
...headers || {}
|
|
95
98
|
},
|
|
@@ -1226,6 +1229,7 @@ var kmsAuthAbi = [
|
|
|
1226
1229
|
var DeployAppAuthRequestBaseSchema = z7.object({
|
|
1227
1230
|
// Chain configuration (conditionally required)
|
|
1228
1231
|
chain: z7.unknown().optional(),
|
|
1232
|
+
rpcUrl: z7.string().optional(),
|
|
1229
1233
|
// Contract configuration (required)
|
|
1230
1234
|
kmsContractAddress: z7.string(),
|
|
1231
1235
|
// Authentication mode: either privateKey OR walletClient (required, mutually exclusive)
|
|
@@ -1319,6 +1323,7 @@ async function deployAppAuth(request, parameters) {
|
|
|
1319
1323
|
const validatedRequest = DeployAppAuthRequestSchema.parse(request);
|
|
1320
1324
|
const {
|
|
1321
1325
|
chain,
|
|
1326
|
+
rpcUrl,
|
|
1322
1327
|
kmsContractAddress,
|
|
1323
1328
|
privateKey,
|
|
1324
1329
|
walletClient: providedWalletClient,
|
|
@@ -1357,7 +1362,7 @@ async function deployAppAuth(request, parameters) {
|
|
|
1357
1362
|
}
|
|
1358
1363
|
publicClient = createPublicClient2({
|
|
1359
1364
|
chain,
|
|
1360
|
-
transport: http2()
|
|
1365
|
+
transport: http2(rpcUrl)
|
|
1361
1366
|
});
|
|
1362
1367
|
}
|
|
1363
1368
|
if (!chain) {
|
|
@@ -1366,7 +1371,7 @@ async function deployAppAuth(request, parameters) {
|
|
|
1366
1371
|
walletClient = createWalletClient2({
|
|
1367
1372
|
account,
|
|
1368
1373
|
chain,
|
|
1369
|
-
transport: http2()
|
|
1374
|
+
transport: http2(rpcUrl)
|
|
1370
1375
|
});
|
|
1371
1376
|
deployerAddress = account.address;
|
|
1372
1377
|
chainId = chain.id;
|
|
@@ -1386,7 +1391,7 @@ async function deployAppAuth(request, parameters) {
|
|
|
1386
1391
|
}
|
|
1387
1392
|
publicClient = createPublicClient2({
|
|
1388
1393
|
chain,
|
|
1389
|
-
transport: http2()
|
|
1394
|
+
transport: http2(rpcUrl)
|
|
1390
1395
|
});
|
|
1391
1396
|
}
|
|
1392
1397
|
if (!walletClient.account?.address) {
|
|
@@ -1546,8 +1551,7 @@ var appAuthAbi = [
|
|
|
1546
1551
|
var AddComposeHashRequestSchema = z8.object({
|
|
1547
1552
|
// Chain configuration (conditionally required)
|
|
1548
1553
|
chain: z8.unknown().optional(),
|
|
1549
|
-
|
|
1550
|
-
kmsContractAddress: z8.string(),
|
|
1554
|
+
rpcUrl: z8.string().optional(),
|
|
1551
1555
|
appId: z8.string(),
|
|
1552
1556
|
composeHash: z8.string(),
|
|
1553
1557
|
// Authentication mode: either privateKey OR walletClient (required, mutually exclusive)
|
|
@@ -1638,6 +1642,7 @@ async function addComposeHash(request, parameters) {
|
|
|
1638
1642
|
const validatedRequest = AddComposeHashRequestSchema.parse(request);
|
|
1639
1643
|
const {
|
|
1640
1644
|
chain,
|
|
1645
|
+
rpcUrl,
|
|
1641
1646
|
appId,
|
|
1642
1647
|
composeHash,
|
|
1643
1648
|
privateKey,
|
|
@@ -1663,13 +1668,13 @@ async function addComposeHash(request, parameters) {
|
|
|
1663
1668
|
publicClient = providedPublicClient;
|
|
1664
1669
|
} else {
|
|
1665
1670
|
if (!chain) throw new Error("Chain required when creating publicClient");
|
|
1666
|
-
publicClient = createPublicClient3({ chain, transport: http3() });
|
|
1671
|
+
publicClient = createPublicClient3({ chain, transport: http3(rpcUrl) });
|
|
1667
1672
|
}
|
|
1668
1673
|
if (!chain) throw new Error("Chain required when creating walletClient");
|
|
1669
1674
|
walletClient = createWalletClient3({
|
|
1670
1675
|
account,
|
|
1671
1676
|
chain,
|
|
1672
|
-
transport: http3()
|
|
1677
|
+
transport: http3(rpcUrl)
|
|
1673
1678
|
});
|
|
1674
1679
|
address = account.address;
|
|
1675
1680
|
chainId = chain.id;
|
|
@@ -1679,7 +1684,7 @@ async function addComposeHash(request, parameters) {
|
|
|
1679
1684
|
publicClient = providedPublicClient;
|
|
1680
1685
|
} else {
|
|
1681
1686
|
if (!chain) throw new Error("Chain required when creating publicClient");
|
|
1682
|
-
publicClient = createPublicClient3({ chain, transport: http3() });
|
|
1687
|
+
publicClient = createPublicClient3({ chain, transport: http3(rpcUrl) });
|
|
1683
1688
|
}
|
|
1684
1689
|
if (!walletClient.account?.address) {
|
|
1685
1690
|
throw new Error("WalletClient must have an account with address");
|
|
@@ -1973,7 +1978,10 @@ async function safeCommitCvmComposeFileUpdate(client, request, parameters) {
|
|
|
1973
1978
|
import { z as z12 } from "zod";
|
|
1974
1979
|
var GetAppEnvEncryptPubKeyRequestSchema = z12.object({
|
|
1975
1980
|
kms: z12.string().min(1, "KMS ID or slug is required"),
|
|
1976
|
-
app_id: z12.string().
|
|
1981
|
+
app_id: z12.string().refine(
|
|
1982
|
+
(val) => val.length === 40 || val.startsWith("0x") && val.length === 42,
|
|
1983
|
+
"App ID must be exactly 40 characters or 42 characters with 0x prefix"
|
|
1984
|
+
)
|
|
1977
1985
|
}).strict();
|
|
1978
1986
|
var GetAppEnvEncryptPubKeySchema = z12.object({
|
|
1979
1987
|
public_key: z12.string(),
|
|
@@ -2079,9 +2087,37 @@ var CvmInfoSchema = z13.object({
|
|
|
2079
2087
|
gateway_domain: z13.string().nullable(),
|
|
2080
2088
|
public_urls: z13.array(CvmNetworkUrlsSchema)
|
|
2081
2089
|
}).partial();
|
|
2090
|
+
var CvmLegacyDetailSchema = z13.object({
|
|
2091
|
+
id: z13.number(),
|
|
2092
|
+
name: z13.string(),
|
|
2093
|
+
status: z13.string(),
|
|
2094
|
+
in_progress: z13.boolean(),
|
|
2095
|
+
teepod_id: z13.number().nullable(),
|
|
2096
|
+
teepod: CvmNodeSchema,
|
|
2097
|
+
app_id: z13.string(),
|
|
2098
|
+
vm_uuid: z13.string().nullable(),
|
|
2099
|
+
instance_id: z13.string().nullable(),
|
|
2100
|
+
vcpu: z13.number().nullable(),
|
|
2101
|
+
memory: z13.number().nullable(),
|
|
2102
|
+
disk_size: z13.number().nullable(),
|
|
2103
|
+
base_image: z13.string(),
|
|
2104
|
+
encrypted_env_pubkey: z13.string().nullable(),
|
|
2105
|
+
listed: z13.boolean(),
|
|
2106
|
+
project_id: z13.string().nullable(),
|
|
2107
|
+
project_type: z13.string().nullable(),
|
|
2108
|
+
public_sysinfo: z13.boolean(),
|
|
2109
|
+
public_logs: z13.boolean(),
|
|
2110
|
+
dapp_dashboard_url: z13.string().nullable(),
|
|
2111
|
+
syslog_endpoint: z13.string().nullable(),
|
|
2112
|
+
kms_info: KMSInfoSchema.nullable(),
|
|
2113
|
+
contract_address: z13.string().nullable(),
|
|
2114
|
+
deployer_address: z13.string().nullable(),
|
|
2115
|
+
scheduled_delete_at: z13.string().nullable(),
|
|
2116
|
+
public_urls: z13.array(CvmNetworkUrlsSchema),
|
|
2117
|
+
gateway_domain: z13.string().nullable()
|
|
2118
|
+
});
|
|
2082
2119
|
|
|
2083
2120
|
// src/actions/get_cvm_info.ts
|
|
2084
|
-
var GetCvmInfoSchema = CvmInfoSchema;
|
|
2085
2121
|
var GetCvmInfoRequestSchema = z14.object({
|
|
2086
2122
|
id: z14.string().optional(),
|
|
2087
2123
|
uuid: z14.string().regex(/^[0-9a-f]{8}[-]?[0-9a-f]{4}[-]?4[0-9a-f]{3}[-]?[89ab][0-9a-f]{3}[-]?[0-9a-f]{12}$/i).optional(),
|
|
@@ -2107,7 +2143,7 @@ async function getCvmInfo(client, request, parameters) {
|
|
|
2107
2143
|
if (parameters?.schema === false) {
|
|
2108
2144
|
return response;
|
|
2109
2145
|
}
|
|
2110
|
-
const schema = parameters?.schema ||
|
|
2146
|
+
const schema = parameters?.schema || CvmLegacyDetailSchema;
|
|
2111
2147
|
return schema.parse(response);
|
|
2112
2148
|
}
|
|
2113
2149
|
async function safeGetCvmInfo(client, request, parameters) {
|
|
@@ -2129,7 +2165,7 @@ async function safeGetCvmInfo(client, request, parameters) {
|
|
|
2129
2165
|
data: httpResult.data
|
|
2130
2166
|
};
|
|
2131
2167
|
}
|
|
2132
|
-
const schema = parameters?.schema ||
|
|
2168
|
+
const schema = parameters?.schema || CvmLegacyDetailSchema;
|
|
2133
2169
|
const validationResult = schema.safeParse(httpResult.data);
|
|
2134
2170
|
return validationResult;
|
|
2135
2171
|
}
|
|
@@ -2266,10 +2302,43 @@ async function safeGetKmsList(client, request, parameters) {
|
|
|
2266
2302
|
return validationResult;
|
|
2267
2303
|
}
|
|
2268
2304
|
|
|
2305
|
+
// src/parse_dotenv.ts
|
|
2306
|
+
var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm;
|
|
2307
|
+
function parseEnv(input) {
|
|
2308
|
+
const obj = {};
|
|
2309
|
+
let lines = input.toString();
|
|
2310
|
+
lines = lines.replace(/\r\n?/gm, "\n");
|
|
2311
|
+
let match;
|
|
2312
|
+
while ((match = LINE.exec(lines)) != null) {
|
|
2313
|
+
const key = match[1];
|
|
2314
|
+
if (!key) continue;
|
|
2315
|
+
let value = match[2] || "";
|
|
2316
|
+
value = value.trim();
|
|
2317
|
+
const maybeQuote = value[0];
|
|
2318
|
+
value = value.replace(/^(['"`])([\s\S]*)\1$/gm, "$2");
|
|
2319
|
+
if (maybeQuote === '"') {
|
|
2320
|
+
value = value.replace(/\\n/g, "\n");
|
|
2321
|
+
value = value.replace(/\\r/g, "\r");
|
|
2322
|
+
}
|
|
2323
|
+
obj[key] = value;
|
|
2324
|
+
}
|
|
2325
|
+
return obj;
|
|
2326
|
+
}
|
|
2327
|
+
function parseEnvVars(input) {
|
|
2328
|
+
const parsed = parseEnv(input);
|
|
2329
|
+
const result = [];
|
|
2330
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
2331
|
+
result.push({ key, value });
|
|
2332
|
+
}
|
|
2333
|
+
return result;
|
|
2334
|
+
}
|
|
2335
|
+
|
|
2269
2336
|
// src/index.ts
|
|
2270
|
-
import {
|
|
2271
|
-
|
|
2272
|
-
|
|
2337
|
+
import {
|
|
2338
|
+
encryptEnvVars as encryptEnvVars2
|
|
2339
|
+
} from "@phala/dstack-sdk/encrypt-env-vars";
|
|
2340
|
+
import { getComposeHash as getComposeHash2 } from "@phala/dstack-sdk/get-compose-hash";
|
|
2341
|
+
import { verifyEnvEncryptPublicKey } from "@phala/dstack-sdk/verify-env-encrypt-public-key";
|
|
2273
2342
|
export {
|
|
2274
2343
|
AddComposeHashSchema,
|
|
2275
2344
|
ApiErrorSchema,
|
|
@@ -2279,11 +2348,11 @@ export {
|
|
|
2279
2348
|
CommitCvmProvisionRequestSchema,
|
|
2280
2349
|
CommitCvmProvisionSchema,
|
|
2281
2350
|
CurrentUserSchema,
|
|
2351
|
+
CvmLegacyDetailSchema,
|
|
2282
2352
|
DeployAppAuthRequestSchema,
|
|
2283
2353
|
DeployAppAuthSchema,
|
|
2284
2354
|
GetAppEnvEncryptPubKeySchema,
|
|
2285
2355
|
GetCvmComposeFileResultSchema,
|
|
2286
|
-
GetCvmInfoSchema,
|
|
2287
2356
|
GetCvmListSchema,
|
|
2288
2357
|
GetKmsListSchema,
|
|
2289
2358
|
NetworkError,
|
|
@@ -2324,6 +2393,8 @@ export {
|
|
|
2324
2393
|
getErrorMessage,
|
|
2325
2394
|
getKmsInfo,
|
|
2326
2395
|
getKmsList,
|
|
2396
|
+
parseEnv,
|
|
2397
|
+
parseEnvVars,
|
|
2327
2398
|
provisionCvm,
|
|
2328
2399
|
provisionCvmComposeFileUpdate,
|
|
2329
2400
|
safeAddComposeHash,
|