@phala/cloud 0.1.0 → 0.1.1-beta.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/dist/actions/{add_compose_hash.d.ts → blockchains/add_compose_hash.d.ts} +1 -2
- package/dist/actions/{deploy_app_auth.d.ts → blockchains/deploy_app_auth.d.ts} +1 -2
- package/dist/actions/{commit_cvm_compose_file_update.d.ts → cvms/commit_cvm_compose_file_update.d.ts} +10 -11
- package/dist/actions/{commit_cvm_provision.d.ts → cvms/commit_cvm_provision.d.ts} +14 -15
- package/dist/actions/{get_cvm_compose_file.d.ts → cvms/get_cvm_compose_file.d.ts} +74 -6
- package/dist/actions/cvms/get_cvm_info.d.ts +85 -0
- package/dist/actions/{get_cvm_list.d.ts → cvms/get_cvm_list.d.ts} +48 -49
- package/dist/actions/{provision_cvm.d.ts → cvms/provision_cvm.d.ts} +16 -17
- package/dist/actions/{provision_cvm_compose_file_update.d.ts → cvms/provision_cvm_compose_file_update.d.ts} +153 -18
- package/dist/actions/get_available_nodes.d.ts +0 -1
- package/dist/actions/get_current_user.d.ts +35 -16
- package/dist/actions/index.d.ts +13 -14
- package/dist/actions/{get_app_env_encrypt_pubkey.d.ts → kms/get_app_env_encrypt_pubkey.d.ts} +8 -9
- package/dist/actions/{get_kms_info.d.ts → kms/get_kms_info.d.ts} +6 -22
- package/dist/actions/{get_kms_list.d.ts → kms/get_kms_list.d.ts} +6 -35
- package/dist/actions/list-instance-types.d.ts +0 -1
- package/dist/actions/workspaces/get_workspace.d.ts +0 -1
- package/dist/actions/workspaces/list_workspaces.d.ts +0 -1
- package/dist/chunk-O5QBIXBA.mjs +1128 -0
- package/dist/client.d.ts +0 -1
- package/dist/create-client.d.ts +311 -0
- package/dist/create-client.js +1143 -0
- package/dist/create-client.mjs +74 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +870 -888
- package/dist/index.mjs +126 -1133
- package/dist/parse_dotenv.d.ts +0 -1
- package/dist/types/app_compose.d.ts +0 -1
- package/dist/types/client.d.ts +0 -1
- package/dist/types/common.d.ts +0 -1
- package/dist/types/cvm_info.d.ts +34 -35
- package/dist/types/index.d.ts +0 -1
- package/dist/types/kms_info.d.ts +0 -1
- package/dist/types/supported_chains.d.ts +0 -1
- package/dist/utils/as-hex.d.ts +0 -1
- package/dist/utils/client-factories.d.ts +0 -1
- package/dist/utils/define-action.d.ts +7 -8
- package/dist/utils/get_compose_hash.d.ts +0 -1
- package/dist/utils/get_error_message.d.ts +0 -1
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/network.d.ts +0 -1
- package/dist/utils/transaction.d.ts +0 -1
- package/dist/utils/validate-parameters.d.ts +0 -1
- package/package.json +70 -66
- package/dist/actions/add_compose_hash.d.ts.map +0 -1
- package/dist/actions/commit_cvm_compose_file_update.d.ts.map +0 -1
- package/dist/actions/commit_cvm_provision.d.ts.map +0 -1
- package/dist/actions/deploy_app_auth.d.ts.map +0 -1
- package/dist/actions/get_app_env_encrypt_pubkey.d.ts.map +0 -1
- package/dist/actions/get_available_nodes.d.ts.map +0 -1
- package/dist/actions/get_current_user.d.ts.map +0 -1
- package/dist/actions/get_cvm_compose_file.d.ts.map +0 -1
- package/dist/actions/get_cvm_info.d.ts +0 -172
- package/dist/actions/get_cvm_info.d.ts.map +0 -1
- package/dist/actions/get_cvm_list.d.ts.map +0 -1
- package/dist/actions/get_kms_info.d.ts.map +0 -1
- package/dist/actions/get_kms_list.d.ts.map +0 -1
- package/dist/actions/index.d.ts.map +0 -1
- package/dist/actions/list-instance-types.d.ts.map +0 -1
- package/dist/actions/provision_cvm.d.ts.map +0 -1
- package/dist/actions/provision_cvm_compose_file_update.d.ts.map +0 -1
- package/dist/actions/workspaces/get_workspace.d.ts.map +0 -1
- package/dist/actions/workspaces/list_workspaces.d.ts.map +0 -1
- package/dist/client.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/parse_dotenv.d.ts.map +0 -1
- package/dist/types/app_compose.d.ts.map +0 -1
- package/dist/types/client.d.ts.map +0 -1
- package/dist/types/common.d.ts.map +0 -1
- package/dist/types/cvm_info.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/kms_info.d.ts.map +0 -1
- package/dist/types/supported_chains.d.ts.map +0 -1
- package/dist/utils/as-hex.d.ts.map +0 -1
- package/dist/utils/client-factories.d.ts.map +0 -1
- package/dist/utils/define-action.d.ts.map +0 -1
- package/dist/utils/get_compose_hash.d.ts.map +0 -1
- package/dist/utils/get_error_message.d.ts.map +0 -1
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/network.d.ts.map +0 -1
- package/dist/utils/transaction.d.ts.map +0 -1
- package/dist/utils/validate-parameters.d.ts.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,442 +1,86 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
ApiErrorSchema,
|
|
3
|
+
AvailableNodesSchema,
|
|
4
|
+
CommitCvmComposeFileUpdateRequestSchema,
|
|
5
|
+
CommitCvmComposeFileUpdateSchema,
|
|
6
|
+
CommitCvmProvisionRequestSchema,
|
|
7
|
+
CommitCvmProvisionSchema,
|
|
8
|
+
CurrentUserSchema,
|
|
9
|
+
CvmInfoSchema,
|
|
10
|
+
CvmLegacyDetailSchema,
|
|
11
|
+
CvmNetworkUrlsSchema,
|
|
12
|
+
CvmNodeSchema,
|
|
13
|
+
GetAppEnvEncryptPubKeyRequestSchema,
|
|
14
|
+
GetAppEnvEncryptPubKeySchema,
|
|
15
|
+
GetCvmComposeFileRequestSchema,
|
|
16
|
+
GetCvmInfoRequestSchema,
|
|
17
|
+
GetCvmListRequestSchema,
|
|
18
|
+
GetCvmListSchema,
|
|
19
|
+
GetKmsInfoRequestSchema,
|
|
20
|
+
GetKmsListRequestSchema,
|
|
21
|
+
GetKmsListSchema,
|
|
22
|
+
InstanceTypeSchema,
|
|
23
|
+
KmsInfoSchema,
|
|
24
|
+
ListInstanceTypesRequestSchema,
|
|
25
|
+
ListWorkspacesSchema,
|
|
26
|
+
ManagedUserSchema,
|
|
27
|
+
PaginatedInstanceTypesSchema,
|
|
28
|
+
PaginationMetadataSchema,
|
|
29
|
+
ProvisionCvmComposeFileUpdateRequestSchema,
|
|
30
|
+
ProvisionCvmComposeFileUpdateResultSchema,
|
|
31
|
+
ProvisionCvmRequestSchema,
|
|
32
|
+
ProvisionCvmSchema,
|
|
33
|
+
RequestError,
|
|
34
|
+
SUPPORTED_CHAINS,
|
|
35
|
+
VmInfoSchema,
|
|
36
|
+
WorkspaceResponseSchema,
|
|
37
|
+
commitCvmComposeFileUpdate,
|
|
38
|
+
commitCvmProvision,
|
|
39
|
+
createClient,
|
|
40
|
+
defineAction,
|
|
41
|
+
defineSimpleAction,
|
|
42
|
+
getAppEnvEncryptPubKey,
|
|
43
|
+
getAvailableNodes,
|
|
44
|
+
getCurrentUser,
|
|
45
|
+
getCvmComposeFile,
|
|
46
|
+
getCvmInfo,
|
|
47
|
+
getCvmList,
|
|
48
|
+
getKmsInfo,
|
|
49
|
+
getKmsList,
|
|
50
|
+
getWorkspace,
|
|
51
|
+
listInstanceTypes,
|
|
52
|
+
listWorkspaces,
|
|
53
|
+
provisionCvm,
|
|
54
|
+
provisionCvmComposeFileUpdate,
|
|
55
|
+
safeCommitCvmComposeFileUpdate,
|
|
56
|
+
safeCommitCvmProvision,
|
|
57
|
+
safeGetAppEnvEncryptPubKey,
|
|
58
|
+
safeGetAvailableNodes,
|
|
59
|
+
safeGetCurrentUser,
|
|
60
|
+
safeGetCvmComposeFile,
|
|
61
|
+
safeGetCvmInfo,
|
|
62
|
+
safeGetCvmList,
|
|
63
|
+
safeGetKmsInfo,
|
|
64
|
+
safeGetKmsList,
|
|
65
|
+
safeGetWorkspace,
|
|
66
|
+
safeListInstanceTypes,
|
|
67
|
+
safeListWorkspaces,
|
|
68
|
+
safeProvisionCvm,
|
|
69
|
+
safeProvisionCvmComposeFileUpdate,
|
|
70
|
+
safeValidateActionParameters,
|
|
71
|
+
validateActionParameters
|
|
72
|
+
} from "./chunk-O5QBIXBA.mjs";
|
|
4
73
|
|
|
5
|
-
// src/
|
|
74
|
+
// src/actions/blockchains/deploy_app_auth.ts
|
|
6
75
|
import { z } from "zod";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
})
|
|
16
|
-
),
|
|
17
|
-
z.record(z.unknown())
|
|
18
|
-
]),
|
|
19
|
-
type: z.string().optional(),
|
|
20
|
-
code: z.string().optional()
|
|
21
|
-
});
|
|
22
|
-
var RequestError = class _RequestError extends Error {
|
|
23
|
-
constructor(message, options) {
|
|
24
|
-
super(message);
|
|
25
|
-
this.name = "RequestError";
|
|
26
|
-
this.isRequestError = true;
|
|
27
|
-
this.status = options?.status;
|
|
28
|
-
this.statusText = options?.statusText;
|
|
29
|
-
this.data = options?.data;
|
|
30
|
-
this.request = options?.request;
|
|
31
|
-
this.response = options?.response;
|
|
32
|
-
this.detail = options?.detail || message;
|
|
33
|
-
this.code = options?.code;
|
|
34
|
-
this.type = options?.type;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Create RequestError from FetchError
|
|
38
|
-
*/
|
|
39
|
-
static fromFetchError(error) {
|
|
40
|
-
const parseResult = ApiErrorSchema.safeParse(error.data);
|
|
41
|
-
if (parseResult.success) {
|
|
42
|
-
return new _RequestError(error.message, {
|
|
43
|
-
status: error.status ?? void 0,
|
|
44
|
-
statusText: error.statusText ?? void 0,
|
|
45
|
-
data: error.data,
|
|
46
|
-
request: error.request ?? void 0,
|
|
47
|
-
response: error.response ?? void 0,
|
|
48
|
-
detail: parseResult.data.detail,
|
|
49
|
-
code: parseResult.data.code ?? void 0,
|
|
50
|
-
type: parseResult.data.type ?? void 0
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
return new _RequestError(error.message, {
|
|
54
|
-
status: error.status ?? void 0,
|
|
55
|
-
statusText: error.statusText ?? void 0,
|
|
56
|
-
data: error.data,
|
|
57
|
-
request: error.request ?? void 0,
|
|
58
|
-
response: error.response ?? void 0,
|
|
59
|
-
detail: error.data?.detail || "Unknown API error",
|
|
60
|
-
code: error.status?.toString() ?? void 0
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Create RequestError from generic Error
|
|
65
|
-
*/
|
|
66
|
-
static fromError(error, request) {
|
|
67
|
-
return new _RequestError(error.message, {
|
|
68
|
-
request: request ?? void 0,
|
|
69
|
-
detail: error.message
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
// src/client.ts
|
|
75
|
-
var SUPPORTED_API_VERSIONS = ["2025-05-31"];
|
|
76
|
-
var logger = debug("phala::api-client");
|
|
77
|
-
function formatHeaders(headers) {
|
|
78
|
-
return Object.entries(headers).map(([key, value]) => ` -H "${key}: ${value}"`).join("\n");
|
|
79
|
-
}
|
|
80
|
-
function formatBody(body) {
|
|
81
|
-
if (!body) return "";
|
|
82
|
-
const bodyStr = typeof body === "string" ? body : JSON.stringify(body, null, 2);
|
|
83
|
-
return ` -d '${bodyStr.replace(/'/g, "\\'")}'`;
|
|
84
|
-
}
|
|
85
|
-
function formatResponse(status, statusText, headers, body) {
|
|
86
|
-
const headerEntries = [];
|
|
87
|
-
headers.forEach((value, key) => {
|
|
88
|
-
headerEntries.push(`${key}: ${value}`);
|
|
89
|
-
});
|
|
90
|
-
const headerStr = headerEntries.join("\n");
|
|
91
|
-
const bodyStr = typeof body === "string" ? body : JSON.stringify(body, null, 2);
|
|
92
|
-
return [
|
|
93
|
-
`< HTTP/1.1 ${status} ${statusText}`,
|
|
94
|
-
headerStr ? `< ${headerStr.replace(/\n/g, "\n< ")}` : "",
|
|
95
|
-
"",
|
|
96
|
-
bodyStr
|
|
97
|
-
].filter(Boolean).join("\n");
|
|
98
|
-
}
|
|
99
|
-
var Client = class {
|
|
100
|
-
constructor(config = {}) {
|
|
101
|
-
const resolvedConfig = {
|
|
102
|
-
...config,
|
|
103
|
-
apiKey: config.apiKey || process?.env?.PHALA_CLOUD_API_KEY,
|
|
104
|
-
baseURL: config.baseURL || process?.env?.PHALA_CLOUD_API_PREFIX || "https://cloud-api.phala.network/api/v1"
|
|
105
|
-
};
|
|
106
|
-
const version = resolvedConfig.version && SUPPORTED_API_VERSIONS.includes(resolvedConfig.version) ? resolvedConfig.version : SUPPORTED_API_VERSIONS[0];
|
|
107
|
-
this.config = resolvedConfig;
|
|
108
|
-
if (!resolvedConfig.useCookieAuth && !resolvedConfig.apiKey) {
|
|
109
|
-
throw new Error(
|
|
110
|
-
"API key is required. Provide it via config.apiKey or set PHALA_CLOUD_API_KEY environment variable."
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
const { apiKey, baseURL, timeout, headers, useCookieAuth, onResponseError, ...fetchOptions } = resolvedConfig;
|
|
114
|
-
const requestHeaders = {
|
|
115
|
-
"X-Phala-Version": version,
|
|
116
|
-
"Content-Type": "application/json"
|
|
117
|
-
};
|
|
118
|
-
if (headers && typeof headers === "object") {
|
|
119
|
-
Object.entries(headers).forEach(([key, value]) => {
|
|
120
|
-
if (typeof value === "string") {
|
|
121
|
-
requestHeaders[key] = value;
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
if (!useCookieAuth && apiKey) {
|
|
126
|
-
requestHeaders["X-API-Key"] = apiKey;
|
|
127
|
-
}
|
|
128
|
-
this.fetchInstance = ofetch.create({
|
|
129
|
-
baseURL,
|
|
130
|
-
timeout: timeout || 3e4,
|
|
131
|
-
headers: requestHeaders,
|
|
132
|
-
...useCookieAuth ? { credentials: "include" } : {},
|
|
133
|
-
...fetchOptions,
|
|
134
|
-
// Log request in cURL format
|
|
135
|
-
onRequest({ request, options }) {
|
|
136
|
-
if (logger.enabled) {
|
|
137
|
-
const method = options.method || "GET";
|
|
138
|
-
const url = typeof request === "string" ? request : request.url;
|
|
139
|
-
const fullUrl = url.startsWith("http") ? url : `${baseURL}${url}`;
|
|
140
|
-
const headerObj = {};
|
|
141
|
-
if (options.headers && typeof options.headers === "object") {
|
|
142
|
-
Object.entries(options.headers).forEach(([key, value]) => {
|
|
143
|
-
if (typeof value === "string") {
|
|
144
|
-
headerObj[key] = value;
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
const curlCommand = [
|
|
149
|
-
`> curl -X ${method} "${fullUrl}"`,
|
|
150
|
-
formatHeaders(headerObj),
|
|
151
|
-
options.body ? formatBody(options.body) : ""
|
|
152
|
-
].filter(Boolean).join("\n");
|
|
153
|
-
logger("\n=== REQUEST ===\n%s\n", curlCommand);
|
|
154
|
-
}
|
|
155
|
-
},
|
|
156
|
-
// Log response in cURL format
|
|
157
|
-
onResponse({ request, response, options }) {
|
|
158
|
-
if (logger.enabled) {
|
|
159
|
-
const method = options.method || "GET";
|
|
160
|
-
const url = typeof request === "string" ? request : request.url;
|
|
161
|
-
logger(
|
|
162
|
-
"\n=== RESPONSE [%s %s] (%dms) ===\n%s\n",
|
|
163
|
-
method,
|
|
164
|
-
url,
|
|
165
|
-
response.headers.get("x-response-time") || "?",
|
|
166
|
-
formatResponse(response.status, response.statusText, response.headers, response._data)
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
},
|
|
170
|
-
// Generic handlers for response error (similar to request.ts)
|
|
171
|
-
onResponseError: ({ request, response, options }) => {
|
|
172
|
-
console.warn(`HTTP ${response.status}: ${response.url}`);
|
|
173
|
-
if (logger.enabled) {
|
|
174
|
-
const method = options.method || "GET";
|
|
175
|
-
const url = typeof request === "string" ? request : request.url;
|
|
176
|
-
logger(
|
|
177
|
-
"\n=== ERROR RESPONSE [%s %s] ===\n%s\n",
|
|
178
|
-
method,
|
|
179
|
-
url,
|
|
180
|
-
formatResponse(response.status, response.statusText, response.headers, response._data)
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
if (onResponseError) {
|
|
184
|
-
onResponseError({ request, response, options });
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Get the underlying ofetch instance for advanced usage
|
|
191
|
-
*/
|
|
192
|
-
get raw() {
|
|
193
|
-
return this.fetchInstance;
|
|
194
|
-
}
|
|
195
|
-
// ===== Direct methods (throw on error) =====
|
|
196
|
-
/**
|
|
197
|
-
* Perform GET request (throws on error)
|
|
198
|
-
*/
|
|
199
|
-
async get(request, options) {
|
|
200
|
-
return this.fetchInstance(request, {
|
|
201
|
-
...options,
|
|
202
|
-
method: "GET"
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Perform POST request (throws on error)
|
|
207
|
-
*/
|
|
208
|
-
async post(request, body, options) {
|
|
209
|
-
return this.fetchInstance(request, {
|
|
210
|
-
...options,
|
|
211
|
-
method: "POST",
|
|
212
|
-
body
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Perform PUT request (throws on error)
|
|
217
|
-
*/
|
|
218
|
-
async put(request, body, options) {
|
|
219
|
-
return this.fetchInstance(request, {
|
|
220
|
-
...options,
|
|
221
|
-
method: "PUT",
|
|
222
|
-
body
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Perform PATCH request (throws on error)
|
|
227
|
-
*/
|
|
228
|
-
async patch(request, body, options) {
|
|
229
|
-
return this.fetchInstance(request, {
|
|
230
|
-
...options,
|
|
231
|
-
method: "PATCH",
|
|
232
|
-
body
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Perform DELETE request (throws on error)
|
|
237
|
-
*/
|
|
238
|
-
async delete(request, options) {
|
|
239
|
-
return this.fetchInstance(request, {
|
|
240
|
-
...options,
|
|
241
|
-
method: "DELETE"
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
// ===== Safe methods (return SafeResult) =====
|
|
245
|
-
/**
|
|
246
|
-
* Safe wrapper for any request method (zod-style result)
|
|
247
|
-
*/
|
|
248
|
-
async safeRequest(fn) {
|
|
249
|
-
try {
|
|
250
|
-
const data = await fn();
|
|
251
|
-
return { success: true, data };
|
|
252
|
-
} catch (error) {
|
|
253
|
-
if (error && typeof error === "object" && "data" in error) {
|
|
254
|
-
const requestError2 = RequestError.fromFetchError(error);
|
|
255
|
-
return { success: false, error: requestError2 };
|
|
256
|
-
}
|
|
257
|
-
if (error instanceof Error) {
|
|
258
|
-
const requestError2 = RequestError.fromError(error);
|
|
259
|
-
return { success: false, error: requestError2 };
|
|
260
|
-
}
|
|
261
|
-
const requestError = new RequestError("Unknown error occurred", {
|
|
262
|
-
detail: "Unknown error occurred"
|
|
263
|
-
});
|
|
264
|
-
return { success: false, error: requestError };
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* Safe GET request (returns SafeResult)
|
|
269
|
-
*/
|
|
270
|
-
async safeGet(request, options) {
|
|
271
|
-
return this.safeRequest(() => this.get(request, options));
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Safe POST request (returns SafeResult)
|
|
275
|
-
*/
|
|
276
|
-
async safePost(request, body, options) {
|
|
277
|
-
return this.safeRequest(() => this.post(request, body, options));
|
|
278
|
-
}
|
|
279
|
-
/**
|
|
280
|
-
* Safe PUT request (returns SafeResult)
|
|
281
|
-
*/
|
|
282
|
-
async safePut(request, body, options) {
|
|
283
|
-
return this.safeRequest(() => this.put(request, body, options));
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
* Safe PATCH request (returns SafeResult)
|
|
287
|
-
*/
|
|
288
|
-
async safePatch(request, body, options) {
|
|
289
|
-
return this.safeRequest(() => this.patch(request, body, options));
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Safe DELETE request (returns SafeResult)
|
|
293
|
-
*/
|
|
294
|
-
async safeDelete(request, options) {
|
|
295
|
-
return this.safeRequest(() => this.delete(request, options));
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Extend client with additional actions
|
|
299
|
-
*
|
|
300
|
-
* @example
|
|
301
|
-
* ```typescript
|
|
302
|
-
* const client = createClient({ apiKey: 'xxx' })
|
|
303
|
-
* .extend(publicActions)
|
|
304
|
-
* .extend(cvmActions)
|
|
305
|
-
*
|
|
306
|
-
* await client.getCurrentUser() // Method call instead of function call
|
|
307
|
-
* ```
|
|
308
|
-
*/
|
|
309
|
-
extend(actions) {
|
|
310
|
-
const actionsObj = typeof actions === "function" ? actions(this) : actions;
|
|
311
|
-
const extended = Object.create(this);
|
|
312
|
-
for (const [key, action] of Object.entries(actionsObj)) {
|
|
313
|
-
if (typeof action === "function") {
|
|
314
|
-
extended[key] = (...args) => action(this, ...args);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
return extended;
|
|
318
|
-
}
|
|
319
|
-
};
|
|
320
|
-
function createClient(config = {}) {
|
|
321
|
-
return new Client(config);
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
// src/types/kms_info.ts
|
|
325
|
-
import { z as z2 } from "zod";
|
|
326
|
-
|
|
327
|
-
// src/types/supported_chains.ts
|
|
328
|
-
import { anvil, base, mainnet } from "viem/chains";
|
|
329
|
-
var SUPPORTED_CHAINS = {
|
|
330
|
-
[mainnet.id]: mainnet,
|
|
331
|
-
[base.id]: base,
|
|
332
|
-
[anvil.id]: anvil
|
|
333
|
-
};
|
|
334
|
-
|
|
335
|
-
// src/types/kms_info.ts
|
|
336
|
-
var KmsInfoBaseSchema = z2.object({
|
|
337
|
-
id: z2.string(),
|
|
338
|
-
slug: z2.string().nullable(),
|
|
339
|
-
url: z2.string(),
|
|
340
|
-
version: z2.string(),
|
|
341
|
-
chain_id: z2.number().nullable(),
|
|
342
|
-
kms_contract_address: z2.string().nullable().transform((val) => val),
|
|
343
|
-
gateway_app_id: z2.string().nullable().transform((val) => val)
|
|
344
|
-
}).passthrough();
|
|
345
|
-
var KmsInfoSchema = KmsInfoBaseSchema.transform((data) => {
|
|
346
|
-
if (data.chain_id != null) {
|
|
347
|
-
const chain = SUPPORTED_CHAINS[data.chain_id];
|
|
348
|
-
if (chain) {
|
|
349
|
-
return { ...data, chain };
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
return data;
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
// src/types/cvm_info.ts
|
|
356
|
-
import { z as z3 } from "zod";
|
|
357
|
-
var VmInfoSchema = z3.object({
|
|
358
|
-
id: z3.string(),
|
|
359
|
-
name: z3.string(),
|
|
360
|
-
status: z3.string(),
|
|
361
|
-
uptime: z3.string(),
|
|
362
|
-
app_url: z3.string().nullable(),
|
|
363
|
-
app_id: z3.string(),
|
|
364
|
-
instance_id: z3.string().nullable(),
|
|
365
|
-
configuration: z3.any().optional(),
|
|
366
|
-
// TODO: add VmConfiguration schema if needed
|
|
367
|
-
exited_at: z3.string().nullable(),
|
|
368
|
-
boot_progress: z3.string().nullable(),
|
|
369
|
-
boot_error: z3.string().nullable(),
|
|
370
|
-
shutdown_progress: z3.string().nullable(),
|
|
371
|
-
image_version: z3.string().nullable()
|
|
372
|
-
});
|
|
373
|
-
var ManagedUserSchema = z3.object({
|
|
374
|
-
id: z3.number(),
|
|
375
|
-
username: z3.string()
|
|
376
|
-
});
|
|
377
|
-
var CvmNodeSchema = z3.object({
|
|
378
|
-
id: z3.number(),
|
|
379
|
-
name: z3.string(),
|
|
380
|
-
region_identifier: z3.string().optional()
|
|
381
|
-
});
|
|
382
|
-
var CvmNetworkUrlsSchema = z3.object({
|
|
383
|
-
app: z3.string(),
|
|
384
|
-
instance: z3.string()
|
|
385
|
-
});
|
|
386
|
-
var CvmInfoSchema = z3.object({
|
|
387
|
-
hosted: VmInfoSchema,
|
|
388
|
-
name: z3.string(),
|
|
389
|
-
managed_user: ManagedUserSchema.optional().nullable(),
|
|
390
|
-
node: CvmNodeSchema.optional().nullable(),
|
|
391
|
-
listed: z3.boolean().default(false),
|
|
392
|
-
status: z3.string(),
|
|
393
|
-
in_progress: z3.boolean().default(false),
|
|
394
|
-
dapp_dashboard_url: z3.string().nullable(),
|
|
395
|
-
syslog_endpoint: z3.string().nullable(),
|
|
396
|
-
allow_upgrade: z3.boolean().default(false),
|
|
397
|
-
project_id: z3.string().nullable(),
|
|
398
|
-
// HashedId is represented as string in JS
|
|
399
|
-
project_type: z3.string().nullable(),
|
|
400
|
-
billing_period: z3.string().nullable(),
|
|
401
|
-
kms_info: KmsInfoSchema.nullable(),
|
|
402
|
-
vcpu: z3.number().nullable(),
|
|
403
|
-
memory: z3.number().nullable(),
|
|
404
|
-
disk_size: z3.number().nullable(),
|
|
405
|
-
gateway_domain: z3.string().nullable(),
|
|
406
|
-
public_urls: z3.array(CvmNetworkUrlsSchema)
|
|
407
|
-
}).partial();
|
|
408
|
-
var CvmLegacyDetailSchema = z3.object({
|
|
409
|
-
id: z3.number(),
|
|
410
|
-
name: z3.string(),
|
|
411
|
-
status: z3.string(),
|
|
412
|
-
in_progress: z3.boolean(),
|
|
413
|
-
teepod_id: z3.number().nullable(),
|
|
414
|
-
teepod: CvmNodeSchema,
|
|
415
|
-
app_id: z3.string(),
|
|
416
|
-
vm_uuid: z3.string().nullable(),
|
|
417
|
-
instance_id: z3.string().nullable(),
|
|
418
|
-
vcpu: z3.number().nullable(),
|
|
419
|
-
memory: z3.number().nullable(),
|
|
420
|
-
disk_size: z3.number().nullable(),
|
|
421
|
-
base_image: z3.string(),
|
|
422
|
-
encrypted_env_pubkey: z3.string().nullable(),
|
|
423
|
-
listed: z3.boolean(),
|
|
424
|
-
project_id: z3.string().nullable(),
|
|
425
|
-
project_type: z3.string().nullable(),
|
|
426
|
-
public_sysinfo: z3.boolean(),
|
|
427
|
-
public_logs: z3.boolean(),
|
|
428
|
-
dapp_dashboard_url: z3.string().nullable(),
|
|
429
|
-
syslog_endpoint: z3.string().nullable(),
|
|
430
|
-
kms_info: KmsInfoSchema.nullable(),
|
|
431
|
-
contract_address: z3.string().nullable(),
|
|
432
|
-
deployer_address: z3.string().nullable(),
|
|
433
|
-
scheduled_delete_at: z3.string().nullable(),
|
|
434
|
-
public_urls: z3.array(CvmNetworkUrlsSchema),
|
|
435
|
-
gateway_domain: z3.string().nullable()
|
|
436
|
-
});
|
|
437
|
-
|
|
438
|
-
// src/actions/get_current_user.ts
|
|
439
|
-
import { z as z4 } from "zod";
|
|
76
|
+
import {
|
|
77
|
+
createPublicClient as createPublicClient2,
|
|
78
|
+
createWalletClient as createWalletClient2,
|
|
79
|
+
http as http2,
|
|
80
|
+
parseEventLogs,
|
|
81
|
+
parseEther
|
|
82
|
+
} from "viem";
|
|
83
|
+
import { privateKeyToAccount as privateKeyToAccount2 } from "viem/accounts";
|
|
440
84
|
|
|
441
85
|
// src/utils/index.ts
|
|
442
86
|
import { encryptEnvVars } from "@phala/dstack-sdk/encrypt-env-vars";
|
|
@@ -471,38 +115,6 @@ function asHex(value) {
|
|
|
471
115
|
throw new Error(`Invalid hex value: ${value}`);
|
|
472
116
|
}
|
|
473
117
|
|
|
474
|
-
// src/utils/validate-parameters.ts
|
|
475
|
-
function validateActionParameters(parameters) {
|
|
476
|
-
if (parameters?.schema !== void 0 && parameters?.schema !== false) {
|
|
477
|
-
if (typeof parameters.schema !== "object" || parameters.schema === null || !("parse" in parameters.schema) || typeof parameters.schema.parse !== "function") {
|
|
478
|
-
throw new Error("Invalid schema: must be a Zod schema object, false, or undefined");
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
function safeValidateActionParameters(parameters) {
|
|
483
|
-
if (parameters?.schema !== void 0 && parameters?.schema !== false) {
|
|
484
|
-
if (typeof parameters.schema !== "object" || parameters.schema === null || !("parse" in parameters.schema) || typeof parameters.schema.parse !== "function") {
|
|
485
|
-
return {
|
|
486
|
-
success: false,
|
|
487
|
-
error: {
|
|
488
|
-
name: "ZodError",
|
|
489
|
-
message: "Invalid schema: must be a Zod schema object, false, or undefined",
|
|
490
|
-
issues: [
|
|
491
|
-
{
|
|
492
|
-
code: "invalid_type",
|
|
493
|
-
expected: "object",
|
|
494
|
-
received: typeof parameters.schema,
|
|
495
|
-
path: ["schema"],
|
|
496
|
-
message: "Invalid schema: must be a Zod schema object, false, or undefined"
|
|
497
|
-
}
|
|
498
|
-
]
|
|
499
|
-
}
|
|
500
|
-
};
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
return void 0;
|
|
504
|
-
}
|
|
505
|
-
|
|
506
118
|
// src/utils/network.ts
|
|
507
119
|
var NetworkError = class extends Error {
|
|
508
120
|
constructor(message, code, details) {
|
|
@@ -1107,350 +719,7 @@ async function autoCreateClients(chain, options = {}) {
|
|
|
1107
719
|
);
|
|
1108
720
|
}
|
|
1109
721
|
|
|
1110
|
-
// src/actions/
|
|
1111
|
-
var CurrentUserSchema = z4.object({
|
|
1112
|
-
username: z4.string(),
|
|
1113
|
-
email: z4.string(),
|
|
1114
|
-
credits: z4.number(),
|
|
1115
|
-
granted_credits: z4.number(),
|
|
1116
|
-
avatar: z4.string(),
|
|
1117
|
-
team_name: z4.string(),
|
|
1118
|
-
team_tier: z4.string()
|
|
1119
|
-
}).passthrough();
|
|
1120
|
-
async function getCurrentUser(client, parameters) {
|
|
1121
|
-
validateActionParameters(parameters);
|
|
1122
|
-
const response = await client.get("/auth/me");
|
|
1123
|
-
if (parameters?.schema === false) {
|
|
1124
|
-
return response;
|
|
1125
|
-
}
|
|
1126
|
-
const schema = parameters?.schema || CurrentUserSchema;
|
|
1127
|
-
return schema.parse(response);
|
|
1128
|
-
}
|
|
1129
|
-
async function safeGetCurrentUser(client, parameters) {
|
|
1130
|
-
const parameterValidationError = safeValidateActionParameters(parameters);
|
|
1131
|
-
if (parameterValidationError) {
|
|
1132
|
-
return parameterValidationError;
|
|
1133
|
-
}
|
|
1134
|
-
const httpResult = await client.safeGet("/auth/me");
|
|
1135
|
-
if (!httpResult.success) {
|
|
1136
|
-
return httpResult;
|
|
1137
|
-
}
|
|
1138
|
-
if (parameters?.schema === false) {
|
|
1139
|
-
return { success: true, data: httpResult.data };
|
|
1140
|
-
}
|
|
1141
|
-
const schema = parameters?.schema || CurrentUserSchema;
|
|
1142
|
-
return schema.safeParse(httpResult.data);
|
|
1143
|
-
}
|
|
1144
|
-
|
|
1145
|
-
// src/actions/get_available_nodes.ts
|
|
1146
|
-
import { z as z5 } from "zod";
|
|
1147
|
-
|
|
1148
|
-
// src/utils/define-action.ts
|
|
1149
|
-
function defineSimpleAction(schema, fn) {
|
|
1150
|
-
function action(client, parameters) {
|
|
1151
|
-
return _actionImpl(client, parameters);
|
|
1152
|
-
}
|
|
1153
|
-
async function _actionImpl(client, parameters) {
|
|
1154
|
-
validateActionParameters(parameters);
|
|
1155
|
-
const response = await fn(client);
|
|
1156
|
-
if (parameters?.schema === false) {
|
|
1157
|
-
return response;
|
|
1158
|
-
}
|
|
1159
|
-
const actualSchema = parameters?.schema || schema;
|
|
1160
|
-
return actualSchema.parse(response);
|
|
1161
|
-
}
|
|
1162
|
-
function safeAction(client, parameters) {
|
|
1163
|
-
return _safeActionImpl(client, parameters);
|
|
1164
|
-
}
|
|
1165
|
-
async function _safeActionImpl(client, parameters) {
|
|
1166
|
-
const parameterValidationError = safeValidateActionParameters(parameters);
|
|
1167
|
-
if (parameterValidationError) {
|
|
1168
|
-
return parameterValidationError;
|
|
1169
|
-
}
|
|
1170
|
-
const httpResult = await (async () => {
|
|
1171
|
-
try {
|
|
1172
|
-
const data = await fn(client);
|
|
1173
|
-
return { success: true, data };
|
|
1174
|
-
} catch (error) {
|
|
1175
|
-
if (error && typeof error === "object" && "isRequestError" in error) {
|
|
1176
|
-
return { success: false, error };
|
|
1177
|
-
}
|
|
1178
|
-
if (error && typeof error === "object" && "issues" in error) {
|
|
1179
|
-
return { success: false, error };
|
|
1180
|
-
}
|
|
1181
|
-
return {
|
|
1182
|
-
success: false,
|
|
1183
|
-
error: {
|
|
1184
|
-
name: "Error",
|
|
1185
|
-
message: error instanceof Error ? error.message : String(error)
|
|
1186
|
-
}
|
|
1187
|
-
};
|
|
1188
|
-
}
|
|
1189
|
-
})();
|
|
1190
|
-
if (!httpResult.success) {
|
|
1191
|
-
return httpResult;
|
|
1192
|
-
}
|
|
1193
|
-
if (parameters?.schema === false) {
|
|
1194
|
-
return { success: true, data: httpResult.data };
|
|
1195
|
-
}
|
|
1196
|
-
const actualSchema = parameters?.schema || schema;
|
|
1197
|
-
return actualSchema.safeParse(httpResult.data);
|
|
1198
|
-
}
|
|
1199
|
-
return {
|
|
1200
|
-
action,
|
|
1201
|
-
safeAction
|
|
1202
|
-
};
|
|
1203
|
-
}
|
|
1204
|
-
function defineAction(schema, fn) {
|
|
1205
|
-
function action(client, ...args) {
|
|
1206
|
-
const [params, parameters] = args;
|
|
1207
|
-
return _actionImpl(client, params, parameters);
|
|
1208
|
-
}
|
|
1209
|
-
async function _actionImpl(client, params, parameters) {
|
|
1210
|
-
validateActionParameters(parameters);
|
|
1211
|
-
const response = await fn(client, params);
|
|
1212
|
-
if (parameters?.schema === false) {
|
|
1213
|
-
return response;
|
|
1214
|
-
}
|
|
1215
|
-
const actualSchema = parameters?.schema || schema;
|
|
1216
|
-
return actualSchema.parse(response);
|
|
1217
|
-
}
|
|
1218
|
-
function safeAction(client, ...args) {
|
|
1219
|
-
const [params, parameters] = args;
|
|
1220
|
-
return _safeActionImpl(client, params, parameters);
|
|
1221
|
-
}
|
|
1222
|
-
async function _safeActionImpl(client, params, parameters) {
|
|
1223
|
-
const parameterValidationError = safeValidateActionParameters(parameters);
|
|
1224
|
-
if (parameterValidationError) {
|
|
1225
|
-
return parameterValidationError;
|
|
1226
|
-
}
|
|
1227
|
-
const httpResult = await (async () => {
|
|
1228
|
-
try {
|
|
1229
|
-
const data = await fn(client, params);
|
|
1230
|
-
return { success: true, data };
|
|
1231
|
-
} catch (error) {
|
|
1232
|
-
if (error && typeof error === "object" && "isRequestError" in error) {
|
|
1233
|
-
return { success: false, error };
|
|
1234
|
-
}
|
|
1235
|
-
if (error && typeof error === "object" && "issues" in error) {
|
|
1236
|
-
return { success: false, error };
|
|
1237
|
-
}
|
|
1238
|
-
return {
|
|
1239
|
-
success: false,
|
|
1240
|
-
error: {
|
|
1241
|
-
name: "Error",
|
|
1242
|
-
message: error instanceof Error ? error.message : String(error)
|
|
1243
|
-
}
|
|
1244
|
-
};
|
|
1245
|
-
}
|
|
1246
|
-
})();
|
|
1247
|
-
if (!httpResult.success) {
|
|
1248
|
-
return httpResult;
|
|
1249
|
-
}
|
|
1250
|
-
if (parameters?.schema === false) {
|
|
1251
|
-
return { success: true, data: httpResult.data };
|
|
1252
|
-
}
|
|
1253
|
-
const actualSchema = parameters?.schema || schema;
|
|
1254
|
-
return actualSchema.safeParse(httpResult.data);
|
|
1255
|
-
}
|
|
1256
|
-
return {
|
|
1257
|
-
action,
|
|
1258
|
-
safeAction
|
|
1259
|
-
};
|
|
1260
|
-
}
|
|
1261
|
-
|
|
1262
|
-
// src/actions/get_available_nodes.ts
|
|
1263
|
-
var AvailableOSImageSchema = z5.object({
|
|
1264
|
-
name: z5.string(),
|
|
1265
|
-
is_dev: z5.boolean(),
|
|
1266
|
-
version: z5.union([
|
|
1267
|
-
z5.tuple([z5.number(), z5.number(), z5.number()]),
|
|
1268
|
-
z5.tuple([z5.number(), z5.number(), z5.number(), z5.number()])
|
|
1269
|
-
]),
|
|
1270
|
-
os_image_hash: z5.string().nullable().optional()
|
|
1271
|
-
}).passthrough();
|
|
1272
|
-
var TeepodCapacitySchema = z5.object({
|
|
1273
|
-
teepod_id: z5.number(),
|
|
1274
|
-
name: z5.string(),
|
|
1275
|
-
listed: z5.boolean(),
|
|
1276
|
-
resource_score: z5.number(),
|
|
1277
|
-
remaining_vcpu: z5.number(),
|
|
1278
|
-
remaining_memory: z5.number(),
|
|
1279
|
-
remaining_cvm_slots: z5.number(),
|
|
1280
|
-
images: z5.array(AvailableOSImageSchema),
|
|
1281
|
-
support_onchain_kms: z5.boolean().optional(),
|
|
1282
|
-
fmspc: z5.string().nullable().optional(),
|
|
1283
|
-
device_id: z5.string().nullable().optional(),
|
|
1284
|
-
region_identifier: z5.string().nullable().optional(),
|
|
1285
|
-
default_kms: z5.string().nullable().optional(),
|
|
1286
|
-
kms_list: z5.array(z5.string()).default([])
|
|
1287
|
-
}).passthrough();
|
|
1288
|
-
var ResourceThresholdSchema = z5.object({
|
|
1289
|
-
max_instances: z5.number().nullable().optional(),
|
|
1290
|
-
max_vcpu: z5.number().nullable().optional(),
|
|
1291
|
-
max_memory: z5.number().nullable().optional(),
|
|
1292
|
-
max_disk: z5.number().nullable().optional()
|
|
1293
|
-
}).passthrough();
|
|
1294
|
-
var AvailableNodesSchema = z5.object({
|
|
1295
|
-
tier: z5.string(),
|
|
1296
|
-
// TeamTier is string enum
|
|
1297
|
-
capacity: ResourceThresholdSchema,
|
|
1298
|
-
nodes: z5.array(TeepodCapacitySchema),
|
|
1299
|
-
kms_list: z5.array(KmsInfoSchema)
|
|
1300
|
-
}).passthrough();
|
|
1301
|
-
var { action: getAvailableNodes, safeAction: safeGetAvailableNodes } = defineSimpleAction(
|
|
1302
|
-
AvailableNodesSchema,
|
|
1303
|
-
async (client) => {
|
|
1304
|
-
return await client.get("/teepods/available");
|
|
1305
|
-
}
|
|
1306
|
-
);
|
|
1307
|
-
|
|
1308
|
-
// src/actions/provision_cvm.ts
|
|
1309
|
-
import { z as z6 } from "zod";
|
|
1310
|
-
var ProvisionCvmSchema = z6.object({
|
|
1311
|
-
app_id: z6.string().nullable().optional(),
|
|
1312
|
-
app_env_encrypt_pubkey: z6.string().nullable().optional(),
|
|
1313
|
-
compose_hash: z6.string(),
|
|
1314
|
-
fmspc: z6.string().nullable().optional(),
|
|
1315
|
-
device_id: z6.string().nullable().optional(),
|
|
1316
|
-
os_image_hash: z6.string().nullable().optional(),
|
|
1317
|
-
teepod_id: z6.number().nullable().optional(),
|
|
1318
|
-
// Will be transformed to node_id
|
|
1319
|
-
node_id: z6.number().nullable().optional(),
|
|
1320
|
-
kms_id: z6.string().nullable().optional()
|
|
1321
|
-
}).passthrough().transform((data) => {
|
|
1322
|
-
if ("teepod_id" in data && data.teepod_id !== void 0) {
|
|
1323
|
-
const { teepod_id, ...rest } = data;
|
|
1324
|
-
return { ...rest, node_id: teepod_id };
|
|
1325
|
-
}
|
|
1326
|
-
return data;
|
|
1327
|
-
});
|
|
1328
|
-
var ProvisionCvmRequestSchema = z6.object({
|
|
1329
|
-
node_id: z6.number().optional(),
|
|
1330
|
-
// recommended
|
|
1331
|
-
teepod_id: z6.number().optional(),
|
|
1332
|
-
// deprecated, for compatibility
|
|
1333
|
-
name: z6.string(),
|
|
1334
|
-
image: z6.string(),
|
|
1335
|
-
vcpu: z6.number(),
|
|
1336
|
-
memory: z6.number(),
|
|
1337
|
-
disk_size: z6.number(),
|
|
1338
|
-
compose_file: z6.object({
|
|
1339
|
-
allowed_envs: z6.array(z6.string()).optional(),
|
|
1340
|
-
pre_launch_script: z6.string().optional(),
|
|
1341
|
-
docker_compose_file: z6.string().optional(),
|
|
1342
|
-
name: z6.string().optional(),
|
|
1343
|
-
kms_enabled: z6.boolean().optional(),
|
|
1344
|
-
public_logs: z6.boolean().optional(),
|
|
1345
|
-
public_sysinfo: z6.boolean().optional(),
|
|
1346
|
-
gateway_enabled: z6.boolean().optional(),
|
|
1347
|
-
// recommended
|
|
1348
|
-
tproxy_enabled: z6.boolean().optional()
|
|
1349
|
-
// deprecated, for compatibility
|
|
1350
|
-
}),
|
|
1351
|
-
listed: z6.boolean().optional(),
|
|
1352
|
-
instance_type: z6.string().nullable().optional(),
|
|
1353
|
-
kms_id: z6.string().optional(),
|
|
1354
|
-
env_keys: z6.array(z6.string()).optional()
|
|
1355
|
-
}).passthrough();
|
|
1356
|
-
function autofillComposeFileName(appCompose) {
|
|
1357
|
-
if (appCompose.compose_file && !appCompose.compose_file.name) {
|
|
1358
|
-
return {
|
|
1359
|
-
...appCompose,
|
|
1360
|
-
compose_file: {
|
|
1361
|
-
...appCompose.compose_file,
|
|
1362
|
-
name: appCompose.name
|
|
1363
|
-
}
|
|
1364
|
-
};
|
|
1365
|
-
}
|
|
1366
|
-
return appCompose;
|
|
1367
|
-
}
|
|
1368
|
-
function handleGatewayCompatibility(appCompose) {
|
|
1369
|
-
if (!appCompose.compose_file) {
|
|
1370
|
-
return appCompose;
|
|
1371
|
-
}
|
|
1372
|
-
const composeFile = { ...appCompose.compose_file };
|
|
1373
|
-
if (typeof composeFile.gateway_enabled === "boolean" && typeof composeFile.tproxy_enabled === "boolean") {
|
|
1374
|
-
delete composeFile.tproxy_enabled;
|
|
1375
|
-
} else if (typeof composeFile.tproxy_enabled === "boolean" && typeof composeFile.gateway_enabled === "undefined") {
|
|
1376
|
-
composeFile.gateway_enabled = composeFile.tproxy_enabled;
|
|
1377
|
-
delete composeFile.tproxy_enabled;
|
|
1378
|
-
if (typeof window !== "undefined" ? window.console : globalThis.console) {
|
|
1379
|
-
console.warn(
|
|
1380
|
-
"[phala/cloud] tproxy_enabled is deprecated, please use gateway_enabled instead. See docs for migration."
|
|
1381
|
-
);
|
|
1382
|
-
}
|
|
1383
|
-
}
|
|
1384
|
-
return {
|
|
1385
|
-
...appCompose,
|
|
1386
|
-
compose_file: composeFile
|
|
1387
|
-
};
|
|
1388
|
-
}
|
|
1389
|
-
var { action: provisionCvm, safeAction: safeProvisionCvm } = defineAction(ProvisionCvmSchema, async (client, appCompose) => {
|
|
1390
|
-
const body = handleGatewayCompatibility(autofillComposeFileName(appCompose));
|
|
1391
|
-
let requestBody = { ...body };
|
|
1392
|
-
if (typeof body.node_id === "number") {
|
|
1393
|
-
requestBody = { ...body, teepod_id: body.node_id };
|
|
1394
|
-
delete requestBody.node_id;
|
|
1395
|
-
} else if (typeof body.teepod_id === "number") {
|
|
1396
|
-
console.warn("[phala/cloud] teepod_id is deprecated, please use node_id instead.");
|
|
1397
|
-
}
|
|
1398
|
-
return await client.post("/cvms/provision", requestBody);
|
|
1399
|
-
});
|
|
1400
|
-
|
|
1401
|
-
// src/actions/commit_cvm_provision.ts
|
|
1402
|
-
import { z as z7 } from "zod";
|
|
1403
|
-
var CommitCvmProvisionSchema = z7.object({
|
|
1404
|
-
id: z7.number(),
|
|
1405
|
-
name: z7.string(),
|
|
1406
|
-
status: z7.string(),
|
|
1407
|
-
teepod_id: z7.number(),
|
|
1408
|
-
teepod: z7.object({
|
|
1409
|
-
id: z7.number(),
|
|
1410
|
-
name: z7.string()
|
|
1411
|
-
}).nullable(),
|
|
1412
|
-
user_id: z7.number().nullable(),
|
|
1413
|
-
app_id: z7.string().nullable(),
|
|
1414
|
-
vm_uuid: z7.string().nullable(),
|
|
1415
|
-
instance_id: z7.string().nullable(),
|
|
1416
|
-
app_url: z7.string().nullable(),
|
|
1417
|
-
base_image: z7.string().nullable(),
|
|
1418
|
-
vcpu: z7.number(),
|
|
1419
|
-
memory: z7.number(),
|
|
1420
|
-
disk_size: z7.number(),
|
|
1421
|
-
manifest_version: z7.number().nullable(),
|
|
1422
|
-
version: z7.string().nullable(),
|
|
1423
|
-
runner: z7.string().nullable(),
|
|
1424
|
-
docker_compose_file: z7.string().nullable(),
|
|
1425
|
-
features: z7.array(z7.string()).nullable(),
|
|
1426
|
-
created_at: z7.string(),
|
|
1427
|
-
encrypted_env_pubkey: z7.string().nullable().optional(),
|
|
1428
|
-
app_auth_contract_address: z7.string().nullable().optional(),
|
|
1429
|
-
deployer_address: z7.string().nullable().optional()
|
|
1430
|
-
}).passthrough();
|
|
1431
|
-
var CommitCvmProvisionRequestSchema = z7.object({
|
|
1432
|
-
encrypted_env: z7.string().optional().nullable(),
|
|
1433
|
-
app_id: z7.string(),
|
|
1434
|
-
compose_hash: z7.string().optional(),
|
|
1435
|
-
kms_id: z7.string().optional(),
|
|
1436
|
-
contract_address: z7.string().optional(),
|
|
1437
|
-
deployer_address: z7.string().optional(),
|
|
1438
|
-
env_keys: z7.array(z7.string()).optional().nullable()
|
|
1439
|
-
}).passthrough();
|
|
1440
|
-
var { action: commitCvmProvision, safeAction: safeCommitCvmProvision } = defineAction(CommitCvmProvisionSchema, async (client, payload) => {
|
|
1441
|
-
return await client.post("/cvms", payload);
|
|
1442
|
-
});
|
|
1443
|
-
|
|
1444
|
-
// src/actions/deploy_app_auth.ts
|
|
1445
|
-
import { z as z8 } from "zod";
|
|
1446
|
-
import {
|
|
1447
|
-
createPublicClient as createPublicClient2,
|
|
1448
|
-
createWalletClient as createWalletClient2,
|
|
1449
|
-
http as http2,
|
|
1450
|
-
parseEventLogs,
|
|
1451
|
-
parseEther
|
|
1452
|
-
} from "viem";
|
|
1453
|
-
import { privateKeyToAccount as privateKeyToAccount2 } from "viem/accounts";
|
|
722
|
+
// src/actions/blockchains/deploy_app_auth.ts
|
|
1454
723
|
var kmsAuthAbi = [
|
|
1455
724
|
{
|
|
1456
725
|
inputs: [
|
|
@@ -1481,25 +750,25 @@ var kmsAuthAbi = [
|
|
|
1481
750
|
anonymous: false
|
|
1482
751
|
}
|
|
1483
752
|
];
|
|
1484
|
-
var DeployAppAuthRequestBaseSchema =
|
|
753
|
+
var DeployAppAuthRequestBaseSchema = z.object({
|
|
1485
754
|
// Chain configuration (conditionally required)
|
|
1486
|
-
chain:
|
|
1487
|
-
rpcUrl:
|
|
755
|
+
chain: z.unknown().optional(),
|
|
756
|
+
rpcUrl: z.string().optional(),
|
|
1488
757
|
// Contract configuration (required)
|
|
1489
|
-
kmsContractAddress:
|
|
758
|
+
kmsContractAddress: z.string(),
|
|
1490
759
|
// Authentication mode: either privateKey OR walletClient (required, mutually exclusive)
|
|
1491
|
-
privateKey:
|
|
1492
|
-
walletClient:
|
|
760
|
+
privateKey: z.string().optional(),
|
|
761
|
+
walletClient: z.unknown().optional(),
|
|
1493
762
|
// Public client (optional, will create default if not provided)
|
|
1494
|
-
publicClient:
|
|
763
|
+
publicClient: z.unknown().optional(),
|
|
1495
764
|
// App configuration (optional)
|
|
1496
|
-
allowAnyDevice:
|
|
1497
|
-
deviceId:
|
|
1498
|
-
composeHash:
|
|
1499
|
-
disableUpgrades:
|
|
765
|
+
allowAnyDevice: z.boolean().optional().default(false),
|
|
766
|
+
deviceId: z.string().optional().default("0000000000000000000000000000000000000000000000000000000000000000"),
|
|
767
|
+
composeHash: z.string().optional().default("0000000000000000000000000000000000000000000000000000000000000000"),
|
|
768
|
+
disableUpgrades: z.boolean().optional().default(false),
|
|
1500
769
|
// Validation configuration (optional)
|
|
1501
|
-
skipPrerequisiteChecks:
|
|
1502
|
-
minBalance:
|
|
770
|
+
skipPrerequisiteChecks: z.boolean().optional().default(false),
|
|
771
|
+
minBalance: z.string().optional()
|
|
1503
772
|
// ETH amount as string, e.g., "0.01"
|
|
1504
773
|
}).passthrough();
|
|
1505
774
|
var DeployAppAuthRequestSchema = DeployAppAuthRequestBaseSchema.refine(
|
|
@@ -1527,13 +796,13 @@ var DeployAppAuthRequestSchema = DeployAppAuthRequestBaseSchema.refine(
|
|
|
1527
796
|
path: ["chain"]
|
|
1528
797
|
}
|
|
1529
798
|
);
|
|
1530
|
-
var DeployAppAuthSchema =
|
|
1531
|
-
appId:
|
|
1532
|
-
appAuthAddress:
|
|
1533
|
-
deployer:
|
|
1534
|
-
transactionHash:
|
|
1535
|
-
blockNumber:
|
|
1536
|
-
gasUsed:
|
|
799
|
+
var DeployAppAuthSchema = z.object({
|
|
800
|
+
appId: z.string(),
|
|
801
|
+
appAuthAddress: z.string(),
|
|
802
|
+
deployer: z.string(),
|
|
803
|
+
transactionHash: z.string(),
|
|
804
|
+
blockNumber: z.bigint().optional(),
|
|
805
|
+
gasUsed: z.bigint().optional()
|
|
1537
806
|
}).passthrough();
|
|
1538
807
|
function parseDeploymentResult(receipt, deployer, kmsContractAddress) {
|
|
1539
808
|
try {
|
|
@@ -1778,8 +1047,8 @@ async function safeDeployAppAuth(request, parameters) {
|
|
|
1778
1047
|
}
|
|
1779
1048
|
}
|
|
1780
1049
|
|
|
1781
|
-
// src/actions/add_compose_hash.ts
|
|
1782
|
-
import { z as
|
|
1050
|
+
// src/actions/blockchains/add_compose_hash.ts
|
|
1051
|
+
import { z as z2 } from "zod";
|
|
1783
1052
|
import {
|
|
1784
1053
|
createPublicClient as createPublicClient3,
|
|
1785
1054
|
createWalletClient as createWalletClient3,
|
|
@@ -1803,29 +1072,29 @@ var appAuthAbi = [
|
|
|
1803
1072
|
anonymous: false
|
|
1804
1073
|
}
|
|
1805
1074
|
];
|
|
1806
|
-
var AddComposeHashRequestSchema =
|
|
1075
|
+
var AddComposeHashRequestSchema = z2.object({
|
|
1807
1076
|
// Chain configuration (conditionally required)
|
|
1808
|
-
chain:
|
|
1809
|
-
rpcUrl:
|
|
1810
|
-
appId:
|
|
1811
|
-
composeHash:
|
|
1077
|
+
chain: z2.unknown().optional(),
|
|
1078
|
+
rpcUrl: z2.string().optional(),
|
|
1079
|
+
appId: z2.string(),
|
|
1080
|
+
composeHash: z2.string(),
|
|
1812
1081
|
// Authentication mode: either privateKey OR walletClient (required, mutually exclusive)
|
|
1813
|
-
privateKey:
|
|
1814
|
-
walletClient:
|
|
1082
|
+
privateKey: z2.string().optional(),
|
|
1083
|
+
walletClient: z2.unknown().optional(),
|
|
1815
1084
|
// Public client (optional, will create default if not provided)
|
|
1816
|
-
publicClient:
|
|
1085
|
+
publicClient: z2.unknown().optional(),
|
|
1817
1086
|
// Validation configuration (optional)
|
|
1818
|
-
skipPrerequisiteChecks:
|
|
1819
|
-
minBalance:
|
|
1087
|
+
skipPrerequisiteChecks: z2.boolean().optional().default(false),
|
|
1088
|
+
minBalance: z2.string().optional(),
|
|
1820
1089
|
// ETH amount as string, e.g., "0.01"
|
|
1821
1090
|
// Transaction control options
|
|
1822
|
-
timeout:
|
|
1823
|
-
retryOptions:
|
|
1824
|
-
signal:
|
|
1091
|
+
timeout: z2.number().optional().default(12e4),
|
|
1092
|
+
retryOptions: z2.unknown().optional(),
|
|
1093
|
+
signal: z2.unknown().optional(),
|
|
1825
1094
|
// Progress callbacks
|
|
1826
|
-
onTransactionStateChange:
|
|
1827
|
-
onTransactionSubmitted:
|
|
1828
|
-
onTransactionConfirmed:
|
|
1095
|
+
onTransactionStateChange: z2.function().optional(),
|
|
1096
|
+
onTransactionSubmitted: z2.function().optional(),
|
|
1097
|
+
onTransactionConfirmed: z2.function().optional()
|
|
1829
1098
|
}).passthrough().refine(
|
|
1830
1099
|
(data) => {
|
|
1831
1100
|
const hasPrivateKey = !!data.privateKey;
|
|
@@ -1849,12 +1118,12 @@ var AddComposeHashRequestSchema = z9.object({
|
|
|
1849
1118
|
path: ["chain"]
|
|
1850
1119
|
}
|
|
1851
1120
|
);
|
|
1852
|
-
var AddComposeHashSchema =
|
|
1853
|
-
composeHash:
|
|
1854
|
-
appId:
|
|
1855
|
-
transactionHash:
|
|
1856
|
-
blockNumber:
|
|
1857
|
-
gasUsed:
|
|
1121
|
+
var AddComposeHashSchema = z2.object({
|
|
1122
|
+
composeHash: z2.string(),
|
|
1123
|
+
appId: z2.string(),
|
|
1124
|
+
transactionHash: z2.string(),
|
|
1125
|
+
blockNumber: z2.bigint().optional(),
|
|
1126
|
+
gasUsed: z2.bigint().optional()
|
|
1858
1127
|
}).passthrough();
|
|
1859
1128
|
function parseComposeHashResult(receipt, composeHash, appAuthAddress, appId) {
|
|
1860
1129
|
console.log(receipt.logs);
|
|
@@ -2045,282 +1314,6 @@ async function safeAddComposeHash(request, parameters) {
|
|
|
2045
1314
|
}
|
|
2046
1315
|
}
|
|
2047
1316
|
|
|
2048
|
-
// src/actions/get_cvm_compose_file.ts
|
|
2049
|
-
import { z as z11 } from "zod";
|
|
2050
|
-
|
|
2051
|
-
// src/types/app_compose.ts
|
|
2052
|
-
import { z as z10 } from "zod";
|
|
2053
|
-
var LooseAppComposeSchema = z10.object({
|
|
2054
|
-
allowed_envs: z10.array(z10.string()).optional(),
|
|
2055
|
-
docker_compose_file: z10.string(),
|
|
2056
|
-
features: z10.array(z10.string()).optional(),
|
|
2057
|
-
name: z10.string().optional(),
|
|
2058
|
-
manifest_version: z10.number().optional(),
|
|
2059
|
-
kms_enabled: z10.boolean().optional(),
|
|
2060
|
-
public_logs: z10.boolean().optional(),
|
|
2061
|
-
public_sysinfo: z10.boolean().optional(),
|
|
2062
|
-
tproxy_enabled: z10.boolean().optional(),
|
|
2063
|
-
pre_launch_script: z10.string().optional()
|
|
2064
|
-
}).passthrough();
|
|
2065
|
-
|
|
2066
|
-
// src/actions/get_cvm_compose_file.ts
|
|
2067
|
-
var GetCvmComposeFileRequestSchema = z11.object({
|
|
2068
|
-
id: z11.string().optional(),
|
|
2069
|
-
uuid: z11.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(),
|
|
2070
|
-
app_id: z11.string().refine(
|
|
2071
|
-
(val) => !val.startsWith("app_") && val.length === 40,
|
|
2072
|
-
"app_id should be 40 characters without prefix"
|
|
2073
|
-
).transform((val) => val.startsWith("app_") ? val : `app_${val}`).optional(),
|
|
2074
|
-
instance_id: z11.string().refine(
|
|
2075
|
-
(val) => !val.startsWith("instance_") && val.length === 40,
|
|
2076
|
-
"instance_id should be 40 characters without prefix"
|
|
2077
|
-
).transform((val) => val.startsWith("instance_") ? val : `instance_${val}`).optional()
|
|
2078
|
-
}).refine(
|
|
2079
|
-
(data) => !!(data.id || data.uuid || data.app_id || data.instance_id),
|
|
2080
|
-
"One of id, uuid, app_id, or instance_id must be provided"
|
|
2081
|
-
).transform((data) => ({
|
|
2082
|
-
cvmId: data.id || data.uuid || data.app_id || data.instance_id,
|
|
2083
|
-
_raw: data
|
|
2084
|
-
}));
|
|
2085
|
-
var { action: getCvmComposeFile, safeAction: safeGetCvmComposeFile } = defineAction(LooseAppComposeSchema, async (client, request) => {
|
|
2086
|
-
const validatedRequest = GetCvmComposeFileRequestSchema.parse(request);
|
|
2087
|
-
return await client.get(`/cvms/${validatedRequest.cvmId}/compose_file`);
|
|
2088
|
-
});
|
|
2089
|
-
|
|
2090
|
-
// src/actions/provision_cvm_compose_file_update.ts
|
|
2091
|
-
import { z as z12 } from "zod";
|
|
2092
|
-
var ProvisionCvmComposeFileUpdateRequestSchema = z12.object({
|
|
2093
|
-
id: z12.string().optional(),
|
|
2094
|
-
uuid: z12.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(),
|
|
2095
|
-
app_id: z12.string().refine(
|
|
2096
|
-
(val) => !val.startsWith("app_") && val.length === 40,
|
|
2097
|
-
"app_id should be 40 characters without prefix"
|
|
2098
|
-
).transform((val) => val.startsWith("app_") ? val : `app_${val}`).optional(),
|
|
2099
|
-
instance_id: z12.string().refine(
|
|
2100
|
-
(val) => !val.startsWith("instance_") && val.length === 40,
|
|
2101
|
-
"instance_id should be 40 characters without prefix"
|
|
2102
|
-
).transform((val) => val.startsWith("instance_") ? val : `instance_${val}`).optional(),
|
|
2103
|
-
app_compose: LooseAppComposeSchema,
|
|
2104
|
-
update_env_vars: z12.boolean().optional().nullable()
|
|
2105
|
-
}).refine(
|
|
2106
|
-
(data) => !!(data.id || data.uuid || data.app_id || data.instance_id),
|
|
2107
|
-
"One of id, uuid, app_id, or instance_id must be provided"
|
|
2108
|
-
).transform((data) => ({
|
|
2109
|
-
cvmId: data.id || data.uuid || data.app_id || data.instance_id,
|
|
2110
|
-
request: data.app_compose,
|
|
2111
|
-
update_env_vars: data.update_env_vars,
|
|
2112
|
-
_raw: data
|
|
2113
|
-
}));
|
|
2114
|
-
var ProvisionCvmComposeFileUpdateResultSchema = z12.object({
|
|
2115
|
-
app_id: z12.string().nullable(),
|
|
2116
|
-
device_id: z12.string().nullable(),
|
|
2117
|
-
compose_hash: z12.string(),
|
|
2118
|
-
kms_info: KmsInfoSchema.nullable().optional()
|
|
2119
|
-
}).passthrough();
|
|
2120
|
-
var { action: provisionCvmComposeFileUpdate, safeAction: safeProvisionCvmComposeFileUpdate } = defineAction(ProvisionCvmComposeFileUpdateResultSchema, async (client, request) => {
|
|
2121
|
-
const validatedRequest = ProvisionCvmComposeFileUpdateRequestSchema.parse(request);
|
|
2122
|
-
return await client.post(
|
|
2123
|
-
`/cvms/${validatedRequest.cvmId}/compose_file/provision`,
|
|
2124
|
-
validatedRequest.request
|
|
2125
|
-
);
|
|
2126
|
-
});
|
|
2127
|
-
|
|
2128
|
-
// src/actions/commit_cvm_compose_file_update.ts
|
|
2129
|
-
import { z as z13 } from "zod";
|
|
2130
|
-
var CommitCvmComposeFileUpdateRequestSchema = z13.object({
|
|
2131
|
-
id: z13.string().optional(),
|
|
2132
|
-
uuid: z13.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(),
|
|
2133
|
-
app_id: z13.string().refine(
|
|
2134
|
-
(val) => !val.startsWith("app_") && val.length === 40,
|
|
2135
|
-
"app_id should be 40 characters without prefix"
|
|
2136
|
-
).transform((val) => val.startsWith("app_") ? val : `app_${val}`).optional(),
|
|
2137
|
-
instance_id: z13.string().refine(
|
|
2138
|
-
(val) => !val.startsWith("instance_") && val.length === 40,
|
|
2139
|
-
"instance_id should be 40 characters without prefix"
|
|
2140
|
-
).transform((val) => val.startsWith("instance_") ? val : `instance_${val}`).optional(),
|
|
2141
|
-
compose_hash: z13.string().min(1, "Compose hash is required"),
|
|
2142
|
-
encrypted_env: z13.string().optional(),
|
|
2143
|
-
env_keys: z13.array(z13.string()).optional(),
|
|
2144
|
-
update_env_vars: z13.boolean().optional().nullable()
|
|
2145
|
-
}).refine(
|
|
2146
|
-
(data) => !!(data.id || data.uuid || data.app_id || data.instance_id),
|
|
2147
|
-
"One of id, uuid, app_id, or instance_id must be provided"
|
|
2148
|
-
).transform((data) => ({
|
|
2149
|
-
cvmId: data.id || data.uuid || data.app_id || data.instance_id,
|
|
2150
|
-
compose_hash: data.compose_hash,
|
|
2151
|
-
encrypted_env: data.encrypted_env,
|
|
2152
|
-
env_keys: data.env_keys,
|
|
2153
|
-
update_env_vars: !!data.update_env_vars,
|
|
2154
|
-
_raw: data
|
|
2155
|
-
}));
|
|
2156
|
-
var CommitCvmComposeFileUpdateSchema = z13.any().transform(() => void 0);
|
|
2157
|
-
var { action: commitCvmComposeFileUpdate, safeAction: safeCommitCvmComposeFileUpdate } = defineAction(
|
|
2158
|
-
CommitCvmComposeFileUpdateSchema,
|
|
2159
|
-
async (client, request) => {
|
|
2160
|
-
const validatedRequest = CommitCvmComposeFileUpdateRequestSchema.parse(request);
|
|
2161
|
-
return await client.patch(`/cvms/${validatedRequest.cvmId}/compose_file`, {
|
|
2162
|
-
compose_hash: validatedRequest.compose_hash,
|
|
2163
|
-
encrypted_env: validatedRequest.encrypted_env,
|
|
2164
|
-
env_keys: validatedRequest.env_keys
|
|
2165
|
-
});
|
|
2166
|
-
}
|
|
2167
|
-
);
|
|
2168
|
-
|
|
2169
|
-
// src/actions/get_app_env_encrypt_pubkey.ts
|
|
2170
|
-
import { z as z14 } from "zod";
|
|
2171
|
-
var GetAppEnvEncryptPubKeyRequestSchema = z14.object({
|
|
2172
|
-
kms: z14.string().min(1, "KMS ID or slug is required"),
|
|
2173
|
-
app_id: z14.string().refine(
|
|
2174
|
-
(val) => val.length === 40 || val.startsWith("0x") && val.length === 42,
|
|
2175
|
-
"App ID must be exactly 40 characters or 42 characters with 0x prefix"
|
|
2176
|
-
)
|
|
2177
|
-
}).strict();
|
|
2178
|
-
var GetAppEnvEncryptPubKeySchema = z14.object({
|
|
2179
|
-
public_key: z14.string(),
|
|
2180
|
-
signature: z14.string()
|
|
2181
|
-
}).strict();
|
|
2182
|
-
var { action: getAppEnvEncryptPubKey, safeAction: safeGetAppEnvEncryptPubKey } = defineAction(GetAppEnvEncryptPubKeySchema, async (client, payload) => {
|
|
2183
|
-
const validatedRequest = GetAppEnvEncryptPubKeyRequestSchema.parse(payload);
|
|
2184
|
-
return await client.get(`/kms/${validatedRequest.kms}/pubkey/${validatedRequest.app_id}`);
|
|
2185
|
-
});
|
|
2186
|
-
|
|
2187
|
-
// src/actions/get_cvm_info.ts
|
|
2188
|
-
import { z as z15 } from "zod";
|
|
2189
|
-
var GetCvmInfoRequestSchema = z15.object({
|
|
2190
|
-
id: z15.string().optional(),
|
|
2191
|
-
uuid: z15.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(),
|
|
2192
|
-
app_id: z15.string().refine(
|
|
2193
|
-
(val) => !val.startsWith("app_") && val.length === 40,
|
|
2194
|
-
"app_id should be 40 characters without prefix"
|
|
2195
|
-
).transform((val) => val.startsWith("app_") ? val : `app_${val}`).optional(),
|
|
2196
|
-
instance_id: z15.string().refine(
|
|
2197
|
-
(val) => !val.startsWith("instance_") && val.length === 40,
|
|
2198
|
-
"instance_id should be 40 characters without prefix"
|
|
2199
|
-
).transform((val) => val.startsWith("instance_") ? val : `instance_${val}`).optional()
|
|
2200
|
-
}).refine(
|
|
2201
|
-
(data) => !!(data.id || data.uuid || data.app_id || data.instance_id),
|
|
2202
|
-
"One of id, uuid, app_id, or instance_id must be provided"
|
|
2203
|
-
).transform((data) => ({
|
|
2204
|
-
cvmId: data.id || data.uuid || data.app_id || data.instance_id,
|
|
2205
|
-
_raw: data
|
|
2206
|
-
}));
|
|
2207
|
-
var { action: getCvmInfo, safeAction: safeGetCvmInfo } = defineAction(CvmLegacyDetailSchema, async (client, request) => {
|
|
2208
|
-
const validatedRequest = GetCvmInfoRequestSchema.parse(request);
|
|
2209
|
-
return await client.get(`/cvms/${validatedRequest.cvmId}`);
|
|
2210
|
-
});
|
|
2211
|
-
|
|
2212
|
-
// src/actions/get_cvm_list.ts
|
|
2213
|
-
import { z as z16 } from "zod";
|
|
2214
|
-
var GetCvmListRequestSchema = z16.object({
|
|
2215
|
-
page: z16.number().int().min(1).optional(),
|
|
2216
|
-
page_size: z16.number().int().min(1).optional(),
|
|
2217
|
-
node_id: z16.number().int().min(1).optional()
|
|
2218
|
-
}).strict();
|
|
2219
|
-
var GetCvmListSchema = z16.object({
|
|
2220
|
-
items: z16.array(CvmInfoSchema),
|
|
2221
|
-
total: z16.number(),
|
|
2222
|
-
page: z16.number(),
|
|
2223
|
-
page_size: z16.number(),
|
|
2224
|
-
pages: z16.number()
|
|
2225
|
-
}).strict();
|
|
2226
|
-
var { action: getCvmList, safeAction: safeGetCvmList } = defineAction(GetCvmListSchema, async (client, request) => {
|
|
2227
|
-
const validatedRequest = GetCvmListRequestSchema.parse(request ?? {});
|
|
2228
|
-
return await client.get("/cvms/paginated", { params: validatedRequest });
|
|
2229
|
-
});
|
|
2230
|
-
|
|
2231
|
-
// src/actions/get_kms_info.ts
|
|
2232
|
-
import { z as z17 } from "zod";
|
|
2233
|
-
var GetKmsInfoRequestSchema = z17.object({
|
|
2234
|
-
kms_id: z17.string().min(1, "KMS ID is required")
|
|
2235
|
-
});
|
|
2236
|
-
var { action: getKmsInfo, safeAction: safeGetKmsInfo } = defineAction(KmsInfoSchema, async (client, request) => {
|
|
2237
|
-
const validatedRequest = GetKmsInfoRequestSchema.parse(request);
|
|
2238
|
-
return await client.get(`/kms/${validatedRequest.kms_id}`);
|
|
2239
|
-
});
|
|
2240
|
-
|
|
2241
|
-
// src/actions/get_kms_list.ts
|
|
2242
|
-
import { z as z18 } from "zod";
|
|
2243
|
-
var GetKmsListRequestSchema = z18.object({
|
|
2244
|
-
page: z18.number().int().min(1).optional(),
|
|
2245
|
-
page_size: z18.number().int().min(1).optional(),
|
|
2246
|
-
is_onchain: z18.boolean().optional()
|
|
2247
|
-
}).strict();
|
|
2248
|
-
var GetKmsListSchema = z18.object({
|
|
2249
|
-
items: z18.array(KmsInfoSchema),
|
|
2250
|
-
total: z18.number(),
|
|
2251
|
-
page: z18.number(),
|
|
2252
|
-
page_size: z18.number(),
|
|
2253
|
-
pages: z18.number()
|
|
2254
|
-
}).strict();
|
|
2255
|
-
var { action: getKmsList, safeAction: safeGetKmsList } = defineAction(GetKmsListSchema, async (client, request) => {
|
|
2256
|
-
const validatedRequest = GetKmsListRequestSchema.parse(request ?? {});
|
|
2257
|
-
return await client.get("/kms", { params: validatedRequest });
|
|
2258
|
-
});
|
|
2259
|
-
|
|
2260
|
-
// src/actions/workspaces/list_workspaces.ts
|
|
2261
|
-
import { z as z19 } from "zod";
|
|
2262
|
-
var WorkspaceResponseSchema = z19.object({
|
|
2263
|
-
id: z19.string(),
|
|
2264
|
-
name: z19.string(),
|
|
2265
|
-
slug: z19.string().nullable(),
|
|
2266
|
-
tier: z19.string(),
|
|
2267
|
-
role: z19.string(),
|
|
2268
|
-
created_at: z19.string()
|
|
2269
|
-
}).passthrough();
|
|
2270
|
-
var PaginationMetadataSchema = z19.object({
|
|
2271
|
-
has_more: z19.boolean(),
|
|
2272
|
-
next_cursor: z19.string().nullable(),
|
|
2273
|
-
total: z19.number().nullable()
|
|
2274
|
-
}).passthrough();
|
|
2275
|
-
var ListWorkspacesSchema = z19.object({
|
|
2276
|
-
data: z19.array(WorkspaceResponseSchema),
|
|
2277
|
-
pagination: PaginationMetadataSchema
|
|
2278
|
-
}).passthrough();
|
|
2279
|
-
var { action: listWorkspaces, safeAction: safeListWorkspaces } = defineAction(ListWorkspacesSchema, async (client, request) => {
|
|
2280
|
-
const queryParams = new URLSearchParams();
|
|
2281
|
-
if (request?.cursor) queryParams.append("cursor", request.cursor);
|
|
2282
|
-
if (request?.limit) queryParams.append("limit", request.limit.toString());
|
|
2283
|
-
const url = queryParams.toString() ? `/workspaces?${queryParams.toString()}` : "/workspaces";
|
|
2284
|
-
return await client.get(url);
|
|
2285
|
-
});
|
|
2286
|
-
|
|
2287
|
-
// src/actions/workspaces/get_workspace.ts
|
|
2288
|
-
var { action: getWorkspace, safeAction: safeGetWorkspace } = defineAction(WorkspaceResponseSchema, async (client, teamSlug) => {
|
|
2289
|
-
return await client.get(`/workspaces/${teamSlug}`);
|
|
2290
|
-
});
|
|
2291
|
-
|
|
2292
|
-
// src/actions/list-instance-types.ts
|
|
2293
|
-
import { z as z20 } from "zod";
|
|
2294
|
-
var ListInstanceTypesRequestSchema = z20.object({
|
|
2295
|
-
page: z20.number().int().min(1).optional().default(1),
|
|
2296
|
-
page_size: z20.number().int().min(1).max(1e3).optional().default(100)
|
|
2297
|
-
}).strict();
|
|
2298
|
-
var InstanceTypeSchema = z20.object({
|
|
2299
|
-
id: z20.string(),
|
|
2300
|
-
name: z20.string(),
|
|
2301
|
-
description: z20.string(),
|
|
2302
|
-
vcpu: z20.number(),
|
|
2303
|
-
memory_mb: z20.number(),
|
|
2304
|
-
hourly_rate: z20.string(),
|
|
2305
|
-
requires_gpu: z20.boolean(),
|
|
2306
|
-
public: z20.boolean(),
|
|
2307
|
-
enabled: z20.boolean()
|
|
2308
|
-
}).passthrough();
|
|
2309
|
-
var PaginatedInstanceTypesSchema = z20.object({
|
|
2310
|
-
items: z20.array(InstanceTypeSchema),
|
|
2311
|
-
total: z20.number(),
|
|
2312
|
-
page: z20.number(),
|
|
2313
|
-
page_size: z20.number(),
|
|
2314
|
-
pages: z20.number()
|
|
2315
|
-
}).strict();
|
|
2316
|
-
var { action: listInstanceTypes, safeAction: safeListInstanceTypes } = defineAction(PaginatedInstanceTypesSchema, async (client, request) => {
|
|
2317
|
-
const validatedRequest = ListInstanceTypesRequestSchema.parse(request ?? {});
|
|
2318
|
-
const queryParams = new URLSearchParams();
|
|
2319
|
-
queryParams.append("page", validatedRequest.page.toString());
|
|
2320
|
-
queryParams.append("page_size", validatedRequest.page_size.toString());
|
|
2321
|
-
return await client.get(`/api/instance-types?${queryParams.toString()}`);
|
|
2322
|
-
});
|
|
2323
|
-
|
|
2324
1317
|
// src/parse_dotenv.ts
|
|
2325
1318
|
var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm;
|
|
2326
1319
|
function parseEnv(input) {
|