@phala/cloud 0.1.1-beta.3 → 0.1.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.
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { type Client } from "../../client";
|
|
3
|
-
import { LooseAppComposeSchema } from "../../types/app_compose";
|
|
4
3
|
import { type CvmIdInput } from "../../types/cvm_id";
|
|
5
4
|
/**
|
|
6
5
|
* Get CVM compose file configuration
|
|
@@ -69,7 +68,7 @@ import { type CvmIdInput } from "../../types/cvm_id";
|
|
|
69
68
|
* }
|
|
70
69
|
* ```
|
|
71
70
|
*/
|
|
72
|
-
export declare const GetCvmComposeFileResultSchema: z.ZodObject<{
|
|
71
|
+
export declare const GetCvmComposeFileResultSchema: z.ZodEffects<z.ZodObject<{
|
|
73
72
|
allowed_envs: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
74
73
|
docker_compose_file: z.ZodString;
|
|
75
74
|
features: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
@@ -108,8 +107,39 @@ export declare const GetCvmComposeFileResultSchema: z.ZodObject<{
|
|
|
108
107
|
pre_launch_script: z.ZodOptional<z.ZodString>;
|
|
109
108
|
env_pubkey: z.ZodOptional<z.ZodString>;
|
|
110
109
|
salt: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
110
|
+
}, z.ZodTypeAny, "passthrough">>, {
|
|
111
|
+
docker_compose_file: string;
|
|
112
|
+
name?: string | undefined;
|
|
113
|
+
public_sysinfo?: boolean | undefined;
|
|
114
|
+
public_logs?: boolean | undefined;
|
|
115
|
+
manifest_version?: number | undefined;
|
|
116
|
+
features?: string[] | undefined;
|
|
117
|
+
allowed_envs?: string[] | undefined;
|
|
118
|
+
pre_launch_script?: string | undefined;
|
|
119
|
+
kms_enabled?: boolean | undefined;
|
|
120
|
+
tproxy_enabled?: boolean | undefined;
|
|
121
|
+
env_pubkey?: string | undefined;
|
|
122
|
+
salt?: string | null | undefined;
|
|
123
|
+
} & {
|
|
124
|
+
[k: string]: unknown;
|
|
125
|
+
} & {
|
|
126
|
+
getHash: () => string;
|
|
127
|
+
toString: () => string;
|
|
128
|
+
}, z.objectInputType<{
|
|
129
|
+
allowed_envs: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
130
|
+
docker_compose_file: z.ZodString;
|
|
131
|
+
features: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
132
|
+
name: z.ZodOptional<z.ZodString>;
|
|
133
|
+
manifest_version: z.ZodOptional<z.ZodNumber>;
|
|
134
|
+
kms_enabled: z.ZodOptional<z.ZodBoolean>;
|
|
135
|
+
public_logs: z.ZodOptional<z.ZodBoolean>;
|
|
136
|
+
public_sysinfo: z.ZodOptional<z.ZodBoolean>;
|
|
137
|
+
tproxy_enabled: z.ZodOptional<z.ZodBoolean>;
|
|
138
|
+
pre_launch_script: z.ZodOptional<z.ZodString>;
|
|
139
|
+
env_pubkey: z.ZodOptional<z.ZodString>;
|
|
140
|
+
salt: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
111
141
|
}, z.ZodTypeAny, "passthrough">>;
|
|
112
|
-
export declare const CvmComposeFileSchema: z.ZodObject<{
|
|
142
|
+
export declare const CvmComposeFileSchema: z.ZodEffects<z.ZodObject<{
|
|
113
143
|
allowed_envs: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
114
144
|
docker_compose_file: z.ZodString;
|
|
115
145
|
features: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
@@ -148,9 +178,40 @@ export declare const CvmComposeFileSchema: z.ZodObject<{
|
|
|
148
178
|
pre_launch_script: z.ZodOptional<z.ZodString>;
|
|
149
179
|
env_pubkey: z.ZodOptional<z.ZodString>;
|
|
150
180
|
salt: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
181
|
+
}, z.ZodTypeAny, "passthrough">>, {
|
|
182
|
+
docker_compose_file: string;
|
|
183
|
+
name?: string | undefined;
|
|
184
|
+
public_sysinfo?: boolean | undefined;
|
|
185
|
+
public_logs?: boolean | undefined;
|
|
186
|
+
manifest_version?: number | undefined;
|
|
187
|
+
features?: string[] | undefined;
|
|
188
|
+
allowed_envs?: string[] | undefined;
|
|
189
|
+
pre_launch_script?: string | undefined;
|
|
190
|
+
kms_enabled?: boolean | undefined;
|
|
191
|
+
tproxy_enabled?: boolean | undefined;
|
|
192
|
+
env_pubkey?: string | undefined;
|
|
193
|
+
salt?: string | null | undefined;
|
|
194
|
+
} & {
|
|
195
|
+
[k: string]: unknown;
|
|
196
|
+
} & {
|
|
197
|
+
getHash: () => string;
|
|
198
|
+
toString: () => string;
|
|
199
|
+
}, z.objectInputType<{
|
|
200
|
+
allowed_envs: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
201
|
+
docker_compose_file: z.ZodString;
|
|
202
|
+
features: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
203
|
+
name: z.ZodOptional<z.ZodString>;
|
|
204
|
+
manifest_version: z.ZodOptional<z.ZodNumber>;
|
|
205
|
+
kms_enabled: z.ZodOptional<z.ZodBoolean>;
|
|
206
|
+
public_logs: z.ZodOptional<z.ZodBoolean>;
|
|
207
|
+
public_sysinfo: z.ZodOptional<z.ZodBoolean>;
|
|
208
|
+
tproxy_enabled: z.ZodOptional<z.ZodBoolean>;
|
|
209
|
+
pre_launch_script: z.ZodOptional<z.ZodString>;
|
|
210
|
+
env_pubkey: z.ZodOptional<z.ZodString>;
|
|
211
|
+
salt: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
151
212
|
}, z.ZodTypeAny, "passthrough">>;
|
|
152
213
|
export type CvmComposeFile = z.infer<typeof CvmComposeFileSchema>;
|
|
153
|
-
export type GetCvmComposeFileResult = z.infer<typeof
|
|
214
|
+
export type GetCvmComposeFileResult = z.infer<typeof GetCvmComposeFileResultSchema>;
|
|
154
215
|
export declare const GetCvmComposeFileRequestSchema: z.ZodEffects<z.ZodEffects<z.ZodObject<{
|
|
155
216
|
id: z.ZodOptional<z.ZodString>;
|
|
156
217
|
uuid: z.ZodOptional<z.ZodString>;
|
|
@@ -171,20 +232,25 @@ export declare const GetCvmComposeFileRequestSchema: z.ZodEffects<z.ZodEffects<z
|
|
|
171
232
|
}, any>;
|
|
172
233
|
export type GetCvmComposeFileRequest = CvmIdInput;
|
|
173
234
|
declare const getCvmComposeFile: {
|
|
174
|
-
(client: Client, params: CvmIdInput): Promise<
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
manifest_version
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
env_pubkey
|
|
186
|
-
salt
|
|
187
|
-
}
|
|
235
|
+
(client: Client, params: CvmIdInput): Promise<{
|
|
236
|
+
docker_compose_file: string;
|
|
237
|
+
name?: string | undefined;
|
|
238
|
+
public_sysinfo?: boolean | undefined;
|
|
239
|
+
public_logs?: boolean | undefined;
|
|
240
|
+
manifest_version?: number | undefined;
|
|
241
|
+
features?: string[] | undefined;
|
|
242
|
+
allowed_envs?: string[] | undefined;
|
|
243
|
+
pre_launch_script?: string | undefined;
|
|
244
|
+
kms_enabled?: boolean | undefined;
|
|
245
|
+
tproxy_enabled?: boolean | undefined;
|
|
246
|
+
env_pubkey?: string | undefined;
|
|
247
|
+
salt?: string | null | undefined;
|
|
248
|
+
} & {
|
|
249
|
+
[k: string]: unknown;
|
|
250
|
+
} & {
|
|
251
|
+
getHash: () => string;
|
|
252
|
+
toString: () => string;
|
|
253
|
+
}>;
|
|
188
254
|
<T extends z.ZodTypeAny>(client: Client, params: CvmIdInput, parameters: {
|
|
189
255
|
schema: T;
|
|
190
256
|
}): Promise<z.TypeOf<T>>;
|
|
@@ -192,20 +258,25 @@ declare const getCvmComposeFile: {
|
|
|
192
258
|
schema: false;
|
|
193
259
|
}): Promise<unknown>;
|
|
194
260
|
}, safeGetCvmComposeFile: {
|
|
195
|
-
(client: Client, params: CvmIdInput): Promise<import("../..").SafeResult<
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
manifest_version
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
env_pubkey
|
|
207
|
-
salt
|
|
208
|
-
}
|
|
261
|
+
(client: Client, params: CvmIdInput): Promise<import("../..").SafeResult<{
|
|
262
|
+
docker_compose_file: string;
|
|
263
|
+
name?: string | undefined;
|
|
264
|
+
public_sysinfo?: boolean | undefined;
|
|
265
|
+
public_logs?: boolean | undefined;
|
|
266
|
+
manifest_version?: number | undefined;
|
|
267
|
+
features?: string[] | undefined;
|
|
268
|
+
allowed_envs?: string[] | undefined;
|
|
269
|
+
pre_launch_script?: string | undefined;
|
|
270
|
+
kms_enabled?: boolean | undefined;
|
|
271
|
+
tproxy_enabled?: boolean | undefined;
|
|
272
|
+
env_pubkey?: string | undefined;
|
|
273
|
+
salt?: string | null | undefined;
|
|
274
|
+
} & {
|
|
275
|
+
[k: string]: unknown;
|
|
276
|
+
} & {
|
|
277
|
+
getHash: () => string;
|
|
278
|
+
toString: () => string;
|
|
279
|
+
}>>;
|
|
209
280
|
<T extends z.ZodTypeAny>(client: Client, params: CvmIdInput, parameters: {
|
|
210
281
|
schema: T;
|
|
211
282
|
}): Promise<import("../..").SafeResult<z.TypeOf<T>>>;
|
package/dist/index.js
CHANGED
|
@@ -109,6 +109,7 @@ __export(index_exports, {
|
|
|
109
109
|
defineSimpleAction: () => defineSimpleAction,
|
|
110
110
|
deleteCvm: () => deleteCvm,
|
|
111
111
|
deployAppAuth: () => deployAppAuth,
|
|
112
|
+
dumpAppCompose: () => dumpAppCompose,
|
|
112
113
|
encryptEnvVars: () => import_encrypt_env_vars2.encryptEnvVars,
|
|
113
114
|
estimateTransactionGas: () => estimateTransactionGas,
|
|
114
115
|
executeBatchTransactions: () => executeBatchTransactions,
|
|
@@ -117,7 +118,7 @@ __export(index_exports, {
|
|
|
117
118
|
extractNetworkClients: () => extractNetworkClients,
|
|
118
119
|
getAppEnvEncryptPubKey: () => getAppEnvEncryptPubKey,
|
|
119
120
|
getAvailableNodes: () => getAvailableNodes,
|
|
120
|
-
getComposeHash: () =>
|
|
121
|
+
getComposeHash: () => import_get_compose_hash3.getComposeHash,
|
|
121
122
|
getCurrentUser: () => getCurrentUser,
|
|
122
123
|
getCvmAttestation: () => getCvmAttestation,
|
|
123
124
|
getCvmComposeFile: () => getCvmComposeFile,
|
|
@@ -135,6 +136,7 @@ __export(index_exports, {
|
|
|
135
136
|
listWorkspaces: () => listWorkspaces,
|
|
136
137
|
parseEnv: () => parseEnv,
|
|
137
138
|
parseEnvVars: () => parseEnvVars,
|
|
139
|
+
preprocessAppCompose: () => preprocessAppCompose,
|
|
138
140
|
provisionCvm: () => provisionCvm,
|
|
139
141
|
provisionCvmComposeFileUpdate: () => provisionCvmComposeFileUpdate,
|
|
140
142
|
refineCvmId: () => refineCvmId,
|
|
@@ -170,6 +172,7 @@ __export(index_exports, {
|
|
|
170
172
|
safeUpdateCvmVisibility: () => safeUpdateCvmVisibility,
|
|
171
173
|
safeValidateActionParameters: () => safeValidateActionParameters,
|
|
172
174
|
shutdownCvm: () => shutdownCvm,
|
|
175
|
+
sortObject: () => sortObject,
|
|
173
176
|
startCvm: () => startCvm,
|
|
174
177
|
stopCvm: () => stopCvm,
|
|
175
178
|
switchToNetwork: () => switchToNetwork,
|
|
@@ -178,7 +181,8 @@ __export(index_exports, {
|
|
|
178
181
|
validateActionParameters: () => validateActionParameters,
|
|
179
182
|
validateNetworkPrerequisites: () => validateNetworkPrerequisites,
|
|
180
183
|
verifyEnvEncryptPublicKey: () => import_verify_env_encrypt_public_key.verifyEnvEncryptPublicKey,
|
|
181
|
-
waitForTransactionReceipt: () => waitForTransactionReceipt
|
|
184
|
+
waitForTransactionReceipt: () => waitForTransactionReceipt,
|
|
185
|
+
withComposeMethods: () => withComposeMethods
|
|
182
186
|
});
|
|
183
187
|
module.exports = __toCommonJS(index_exports);
|
|
184
188
|
|
|
@@ -1039,18 +1043,6 @@ var ProvisionCvmRequestSchema = import_zod10.z.object({
|
|
|
1039
1043
|
kms_id: import_zod10.z.string().optional(),
|
|
1040
1044
|
env_keys: import_zod10.z.array(import_zod10.z.string()).optional()
|
|
1041
1045
|
}).passthrough();
|
|
1042
|
-
function autofillComposeFileName(appCompose) {
|
|
1043
|
-
if (appCompose.compose_file && !appCompose.compose_file.name) {
|
|
1044
|
-
return {
|
|
1045
|
-
...appCompose,
|
|
1046
|
-
compose_file: {
|
|
1047
|
-
...appCompose.compose_file,
|
|
1048
|
-
name: appCompose.name
|
|
1049
|
-
}
|
|
1050
|
-
};
|
|
1051
|
-
}
|
|
1052
|
-
return appCompose;
|
|
1053
|
-
}
|
|
1054
1046
|
function handleGatewayCompatibility(appCompose) {
|
|
1055
1047
|
if (!appCompose.compose_file) {
|
|
1056
1048
|
return appCompose;
|
|
@@ -1073,7 +1065,7 @@ function handleGatewayCompatibility(appCompose) {
|
|
|
1073
1065
|
};
|
|
1074
1066
|
}
|
|
1075
1067
|
var { action: provisionCvm, safeAction: safeProvisionCvm } = defineAction(ProvisionCvmSchema, async (client, appCompose) => {
|
|
1076
|
-
const body = handleGatewayCompatibility(
|
|
1068
|
+
const body = handleGatewayCompatibility(appCompose);
|
|
1077
1069
|
let requestBody = { ...body };
|
|
1078
1070
|
if (typeof body.node_id === "number") {
|
|
1079
1071
|
requestBody = { ...body, teepod_id: body.node_id };
|
|
@@ -1144,9 +1136,61 @@ var LooseAppComposeSchema = import_zod12.z.object({
|
|
|
1144
1136
|
salt: import_zod12.z.string().optional().nullable()
|
|
1145
1137
|
}).passthrough();
|
|
1146
1138
|
|
|
1139
|
+
// src/utils/get_compose_hash.ts
|
|
1140
|
+
var import_crypto = __toESM(require("crypto"));
|
|
1141
|
+
function sortObject(obj) {
|
|
1142
|
+
if (obj === void 0 || obj === null) {
|
|
1143
|
+
return obj;
|
|
1144
|
+
}
|
|
1145
|
+
if (Array.isArray(obj)) {
|
|
1146
|
+
return obj.map(sortObject);
|
|
1147
|
+
} else if (obj && typeof obj === "object" && obj.constructor === Object) {
|
|
1148
|
+
return Object.keys(obj).sort().reduce((result, key) => {
|
|
1149
|
+
const value = obj[key];
|
|
1150
|
+
result[key] = sortObject(value);
|
|
1151
|
+
return result;
|
|
1152
|
+
}, {});
|
|
1153
|
+
}
|
|
1154
|
+
return obj;
|
|
1155
|
+
}
|
|
1156
|
+
function preprocessAppCompose(dic) {
|
|
1157
|
+
const obj = { ...dic };
|
|
1158
|
+
if (obj.runner === "bash" && "docker_compose_file" in obj) {
|
|
1159
|
+
delete obj.docker_compose_file;
|
|
1160
|
+
} else if (obj.runner === "docker-compose" && "bash_script" in obj) {
|
|
1161
|
+
delete obj.bash_script;
|
|
1162
|
+
}
|
|
1163
|
+
if ("pre_launch_script" in obj && !obj.pre_launch_script) {
|
|
1164
|
+
delete obj.pre_launch_script;
|
|
1165
|
+
}
|
|
1166
|
+
return obj;
|
|
1167
|
+
}
|
|
1168
|
+
function dumpAppCompose(dic) {
|
|
1169
|
+
const ordered = sortObject(dic);
|
|
1170
|
+
let json = JSON.stringify(ordered, null, 4);
|
|
1171
|
+
json = json.replace(/": /g, '":');
|
|
1172
|
+
return json;
|
|
1173
|
+
}
|
|
1174
|
+
function getComposeHash(app_compose) {
|
|
1175
|
+
const preprocessed = preprocessAppCompose(app_compose);
|
|
1176
|
+
const manifest_str = dumpAppCompose(preprocessed);
|
|
1177
|
+
return import_crypto.default.createHash("sha256").update(manifest_str, "utf8").digest("hex");
|
|
1178
|
+
}
|
|
1179
|
+
function withComposeMethods(compose) {
|
|
1180
|
+
const appCompose = compose;
|
|
1181
|
+
return {
|
|
1182
|
+
...compose,
|
|
1183
|
+
getHash: () => getComposeHash(appCompose),
|
|
1184
|
+
toString: () => dumpAppCompose(preprocessAppCompose(appCompose))
|
|
1185
|
+
};
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1147
1188
|
// src/actions/cvms/get_cvm_compose_file.ts
|
|
1189
|
+
var GetCvmComposeFileResultSchema = LooseAppComposeSchema.transform(
|
|
1190
|
+
(data) => withComposeMethods(data)
|
|
1191
|
+
);
|
|
1148
1192
|
var GetCvmComposeFileRequestSchema = CvmIdSchema;
|
|
1149
|
-
var { action: getCvmComposeFile, safeAction: safeGetCvmComposeFile } = defineAction(
|
|
1193
|
+
var { action: getCvmComposeFile, safeAction: safeGetCvmComposeFile } = defineAction(GetCvmComposeFileResultSchema, async (client, request) => {
|
|
1150
1194
|
const { cvmId } = GetCvmComposeFileRequestSchema.parse(request);
|
|
1151
1195
|
return await client.get(`/cvms/${cvmId}/compose_file`);
|
|
1152
1196
|
});
|
|
@@ -2847,7 +2891,7 @@ function parseEnvVars(input) {
|
|
|
2847
2891
|
|
|
2848
2892
|
// src/index.ts
|
|
2849
2893
|
var import_encrypt_env_vars2 = require("@phala/dstack-sdk/encrypt-env-vars");
|
|
2850
|
-
var
|
|
2894
|
+
var import_get_compose_hash3 = require("@phala/dstack-sdk/get-compose-hash");
|
|
2851
2895
|
var import_verify_env_encrypt_public_key = require("@phala/dstack-sdk/verify-env-encrypt-public-key");
|
|
2852
2896
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2853
2897
|
0 && (module.exports = {
|
|
@@ -2930,6 +2974,7 @@ var import_verify_env_encrypt_public_key = require("@phala/dstack-sdk/verify-env
|
|
|
2930
2974
|
defineSimpleAction,
|
|
2931
2975
|
deleteCvm,
|
|
2932
2976
|
deployAppAuth,
|
|
2977
|
+
dumpAppCompose,
|
|
2933
2978
|
encryptEnvVars,
|
|
2934
2979
|
estimateTransactionGas,
|
|
2935
2980
|
executeBatchTransactions,
|
|
@@ -2956,6 +3001,7 @@ var import_verify_env_encrypt_public_key = require("@phala/dstack-sdk/verify-env
|
|
|
2956
3001
|
listWorkspaces,
|
|
2957
3002
|
parseEnv,
|
|
2958
3003
|
parseEnvVars,
|
|
3004
|
+
preprocessAppCompose,
|
|
2959
3005
|
provisionCvm,
|
|
2960
3006
|
provisionCvmComposeFileUpdate,
|
|
2961
3007
|
refineCvmId,
|
|
@@ -2991,6 +3037,7 @@ var import_verify_env_encrypt_public_key = require("@phala/dstack-sdk/verify-env
|
|
|
2991
3037
|
safeUpdateCvmVisibility,
|
|
2992
3038
|
safeValidateActionParameters,
|
|
2993
3039
|
shutdownCvm,
|
|
3040
|
+
sortObject,
|
|
2994
3041
|
startCvm,
|
|
2995
3042
|
stopCvm,
|
|
2996
3043
|
switchToNetwork,
|
|
@@ -2999,5 +3046,6 @@ var import_verify_env_encrypt_public_key = require("@phala/dstack-sdk/verify-env
|
|
|
2999
3046
|
validateActionParameters,
|
|
3000
3047
|
validateNetworkPrerequisites,
|
|
3001
3048
|
verifyEnvEncryptPublicKey,
|
|
3002
|
-
waitForTransactionReceipt
|
|
3049
|
+
waitForTransactionReceipt,
|
|
3050
|
+
withComposeMethods
|
|
3003
3051
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -855,18 +855,6 @@ var ProvisionCvmRequestSchema = z10.object({
|
|
|
855
855
|
kms_id: z10.string().optional(),
|
|
856
856
|
env_keys: z10.array(z10.string()).optional()
|
|
857
857
|
}).passthrough();
|
|
858
|
-
function autofillComposeFileName(appCompose) {
|
|
859
|
-
if (appCompose.compose_file && !appCompose.compose_file.name) {
|
|
860
|
-
return {
|
|
861
|
-
...appCompose,
|
|
862
|
-
compose_file: {
|
|
863
|
-
...appCompose.compose_file,
|
|
864
|
-
name: appCompose.name
|
|
865
|
-
}
|
|
866
|
-
};
|
|
867
|
-
}
|
|
868
|
-
return appCompose;
|
|
869
|
-
}
|
|
870
858
|
function handleGatewayCompatibility(appCompose) {
|
|
871
859
|
if (!appCompose.compose_file) {
|
|
872
860
|
return appCompose;
|
|
@@ -889,7 +877,7 @@ function handleGatewayCompatibility(appCompose) {
|
|
|
889
877
|
};
|
|
890
878
|
}
|
|
891
879
|
var { action: provisionCvm, safeAction: safeProvisionCvm } = defineAction(ProvisionCvmSchema, async (client, appCompose) => {
|
|
892
|
-
const body = handleGatewayCompatibility(
|
|
880
|
+
const body = handleGatewayCompatibility(appCompose);
|
|
893
881
|
let requestBody = { ...body };
|
|
894
882
|
if (typeof body.node_id === "number") {
|
|
895
883
|
requestBody = { ...body, teepod_id: body.node_id };
|
|
@@ -960,9 +948,61 @@ var LooseAppComposeSchema = z12.object({
|
|
|
960
948
|
salt: z12.string().optional().nullable()
|
|
961
949
|
}).passthrough();
|
|
962
950
|
|
|
951
|
+
// src/utils/get_compose_hash.ts
|
|
952
|
+
import crypto from "crypto";
|
|
953
|
+
function sortObject(obj) {
|
|
954
|
+
if (obj === void 0 || obj === null) {
|
|
955
|
+
return obj;
|
|
956
|
+
}
|
|
957
|
+
if (Array.isArray(obj)) {
|
|
958
|
+
return obj.map(sortObject);
|
|
959
|
+
} else if (obj && typeof obj === "object" && obj.constructor === Object) {
|
|
960
|
+
return Object.keys(obj).sort().reduce((result, key) => {
|
|
961
|
+
const value = obj[key];
|
|
962
|
+
result[key] = sortObject(value);
|
|
963
|
+
return result;
|
|
964
|
+
}, {});
|
|
965
|
+
}
|
|
966
|
+
return obj;
|
|
967
|
+
}
|
|
968
|
+
function preprocessAppCompose(dic) {
|
|
969
|
+
const obj = { ...dic };
|
|
970
|
+
if (obj.runner === "bash" && "docker_compose_file" in obj) {
|
|
971
|
+
delete obj.docker_compose_file;
|
|
972
|
+
} else if (obj.runner === "docker-compose" && "bash_script" in obj) {
|
|
973
|
+
delete obj.bash_script;
|
|
974
|
+
}
|
|
975
|
+
if ("pre_launch_script" in obj && !obj.pre_launch_script) {
|
|
976
|
+
delete obj.pre_launch_script;
|
|
977
|
+
}
|
|
978
|
+
return obj;
|
|
979
|
+
}
|
|
980
|
+
function dumpAppCompose(dic) {
|
|
981
|
+
const ordered = sortObject(dic);
|
|
982
|
+
let json = JSON.stringify(ordered, null, 4);
|
|
983
|
+
json = json.replace(/": /g, '":');
|
|
984
|
+
return json;
|
|
985
|
+
}
|
|
986
|
+
function getComposeHash(app_compose) {
|
|
987
|
+
const preprocessed = preprocessAppCompose(app_compose);
|
|
988
|
+
const manifest_str = dumpAppCompose(preprocessed);
|
|
989
|
+
return crypto.createHash("sha256").update(manifest_str, "utf8").digest("hex");
|
|
990
|
+
}
|
|
991
|
+
function withComposeMethods(compose) {
|
|
992
|
+
const appCompose = compose;
|
|
993
|
+
return {
|
|
994
|
+
...compose,
|
|
995
|
+
getHash: () => getComposeHash(appCompose),
|
|
996
|
+
toString: () => dumpAppCompose(preprocessAppCompose(appCompose))
|
|
997
|
+
};
|
|
998
|
+
}
|
|
999
|
+
|
|
963
1000
|
// src/actions/cvms/get_cvm_compose_file.ts
|
|
1001
|
+
var GetCvmComposeFileResultSchema = LooseAppComposeSchema.transform(
|
|
1002
|
+
(data) => withComposeMethods(data)
|
|
1003
|
+
);
|
|
964
1004
|
var GetCvmComposeFileRequestSchema = CvmIdSchema;
|
|
965
|
-
var { action: getCvmComposeFile, safeAction: safeGetCvmComposeFile } = defineAction(
|
|
1005
|
+
var { action: getCvmComposeFile, safeAction: safeGetCvmComposeFile } = defineAction(GetCvmComposeFileResultSchema, async (client, request) => {
|
|
966
1006
|
const { cvmId } = GetCvmComposeFileRequestSchema.parse(request);
|
|
967
1007
|
return await client.get(`/cvms/${cvmId}/compose_file`);
|
|
968
1008
|
});
|
|
@@ -2764,6 +2804,7 @@ export {
|
|
|
2764
2804
|
defineSimpleAction,
|
|
2765
2805
|
deleteCvm,
|
|
2766
2806
|
deployAppAuth,
|
|
2807
|
+
dumpAppCompose,
|
|
2767
2808
|
encryptEnvVars2 as encryptEnvVars,
|
|
2768
2809
|
estimateTransactionGas,
|
|
2769
2810
|
executeBatchTransactions,
|
|
@@ -2790,6 +2831,7 @@ export {
|
|
|
2790
2831
|
listWorkspaces,
|
|
2791
2832
|
parseEnv,
|
|
2792
2833
|
parseEnvVars,
|
|
2834
|
+
preprocessAppCompose,
|
|
2793
2835
|
provisionCvm,
|
|
2794
2836
|
provisionCvmComposeFileUpdate,
|
|
2795
2837
|
refineCvmId,
|
|
@@ -2825,6 +2867,7 @@ export {
|
|
|
2825
2867
|
safeUpdateCvmVisibility,
|
|
2826
2868
|
safeValidateActionParameters,
|
|
2827
2869
|
shutdownCvm,
|
|
2870
|
+
sortObject,
|
|
2828
2871
|
startCvm,
|
|
2829
2872
|
stopCvm,
|
|
2830
2873
|
switchToNetwork,
|
|
@@ -2833,5 +2876,6 @@ export {
|
|
|
2833
2876
|
validateActionParameters,
|
|
2834
2877
|
validateNetworkPrerequisites,
|
|
2835
2878
|
verifyEnvEncryptPublicKey,
|
|
2836
|
-
waitForTransactionReceipt
|
|
2879
|
+
waitForTransactionReceipt,
|
|
2880
|
+
withComposeMethods
|
|
2837
2881
|
};
|
|
@@ -1,14 +1,31 @@
|
|
|
1
|
-
type SortableValue = string | number | boolean | null | undefined | SortableObject | SortableArray;
|
|
2
|
-
interface SortableObject {
|
|
1
|
+
export type SortableValue = string | number | boolean | null | undefined | SortableObject | SortableArray;
|
|
2
|
+
export interface SortableObject {
|
|
3
3
|
[key: string]: SortableValue;
|
|
4
4
|
}
|
|
5
|
-
interface SortableArray extends Array<SortableValue> {
|
|
5
|
+
export interface SortableArray extends Array<SortableValue> {
|
|
6
6
|
}
|
|
7
|
+
export declare function sortObject(obj: SortableValue): SortableValue;
|
|
7
8
|
export interface AppCompose extends SortableObject {
|
|
8
9
|
runner?: string;
|
|
9
10
|
docker_compose_file?: string;
|
|
10
11
|
bash_script?: string;
|
|
11
12
|
pre_launch_script?: string;
|
|
12
13
|
}
|
|
14
|
+
export declare function preprocessAppCompose(dic: AppCompose): AppCompose;
|
|
15
|
+
export declare function dumpAppCompose(dic: AppCompose): string;
|
|
13
16
|
export declare function getComposeHash(app_compose: AppCompose): string;
|
|
14
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Attach utility methods to an AppCompose-compatible object
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const compose = withComposeMethods(rawCompose);
|
|
23
|
+
* console.log(compose.getHash());
|
|
24
|
+
* console.log(compose.dump());
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function withComposeMethods<T extends Record<string, unknown>>(compose: T): T & {
|
|
28
|
+
getHash: () => string;
|
|
29
|
+
toString: () => string;
|
|
30
|
+
};
|
|
31
|
+
export type AppComposeWithMethods = ReturnType<typeof withComposeMethods>;
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { encryptEnvVars } from "@phala/dstack-sdk/encrypt-env-vars";
|
|
2
|
-
export { getComposeHash, type AppCompose } from "./get_compose_hash";
|
|
2
|
+
export { getComposeHash, dumpAppCompose, preprocessAppCompose, sortObject, withComposeMethods, type AppCompose, type AppComposeWithMethods, type SortableValue, type SortableObject, type SortableArray, } from "./get_compose_hash";
|
|
3
3
|
export { getErrorMessage } from "./get_error_message";
|
|
4
4
|
export { asHex } from "./as-hex";
|
|
5
5
|
export { validateActionParameters, safeValidateActionParameters } from "./validate-parameters";
|