@phala/cloud 0.2.1-beta.3 → 0.2.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/LICENSE +201 -0
- package/dist/actions/apps/get_app_cvms.d.ts +30 -0
- package/dist/actions/apps/get_app_info.d.ts +30 -0
- package/dist/actions/apps/get_app_list.d.ts +74 -0
- package/dist/actions/apps/get_app_revision_detail.d.ts +48 -0
- package/dist/actions/apps/get_app_revisions.d.ts +42 -0
- package/dist/actions/cvms/commit_cvm_compose_file_update.d.ts +7 -7
- package/dist/actions/cvms/commit_cvm_provision.d.ts +31 -31
- package/dist/actions/cvms/delete_cvm.d.ts +10 -7
- package/dist/actions/cvms/get_available_os_images.d.ts +10 -7
- package/dist/actions/cvms/get_cvm_attestation.d.ts +10 -7
- package/dist/actions/cvms/get_cvm_compose_file.d.ts +18 -15
- package/dist/actions/cvms/get_cvm_containers_stats.d.ts +14 -11
- package/dist/actions/cvms/get_cvm_docker_compose.d.ts +10 -7
- package/dist/actions/cvms/get_cvm_info.d.ts +19 -35
- package/dist/actions/cvms/get_cvm_list.d.ts +11 -537
- package/dist/actions/cvms/get_cvm_network.d.ts +10 -7
- package/dist/actions/cvms/get_cvm_prelaunch_script.d.ts +42 -0
- package/dist/actions/cvms/get_cvm_state.d.ts +10 -7
- package/dist/actions/cvms/get_cvm_stats.d.ts +10 -7
- package/dist/actions/cvms/get_cvm_status_batch.d.ts +167 -0
- package/dist/actions/cvms/provision_cvm.d.ts +404 -21
- package/dist/actions/cvms/provision_cvm_compose_file_update.d.ts +32 -32
- package/dist/actions/cvms/restart_cvm.d.ts +17 -14
- package/dist/actions/cvms/shutdown_cvm.d.ts +18 -15
- package/dist/actions/cvms/start_cvm.d.ts +18 -15
- package/dist/actions/cvms/stop_cvm.d.ts +18 -15
- package/dist/actions/cvms/update_cvm_envs.d.ts +426 -0
- package/dist/actions/cvms/update_cvm_resources.d.ts +13 -10
- package/dist/actions/cvms/update_cvm_visibility.d.ts +33 -14
- package/dist/actions/cvms/update_docker_compose.d.ts +420 -0
- package/dist/actions/cvms/update_os_image.d.ts +9 -6
- package/dist/actions/cvms/update_prelaunch_script.d.ts +417 -0
- package/dist/actions/cvms/watch_cvm_state.d.ts +1 -1
- package/dist/actions/get_available_nodes.d.ts +6 -6
- package/dist/actions/get_current_user.d.ts +36 -89
- package/dist/actions/index.d.ts +14 -2
- package/dist/actions/kms/get_app_env_encrypt_pubkey.d.ts +6 -6
- package/dist/actions/kms/get_kms_info.d.ts +6 -6
- package/dist/actions/kms/get_kms_list.d.ts +6 -6
- package/dist/actions/kms/next_app_ids.d.ts +6 -6
- package/dist/actions/list-instance-types.d.ts +16 -16
- package/dist/actions/workspaces/get_workspace.d.ts +6 -6
- package/dist/actions/workspaces/get_workspace_nodes.d.ts +266 -0
- package/dist/actions/workspaces/get_workspace_quotas.d.ts +1169 -0
- package/dist/actions/workspaces/list_workspaces.d.ts +6 -6
- package/dist/client.d.ts +49 -9
- package/dist/create-client.d.ts +87 -36
- package/dist/credentials/current_user_v20251028.d.ts +30 -0
- package/dist/credentials/current_user_v20260121.d.ts +276 -0
- package/dist/credentials/index.d.ts +4 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1782 -633
- package/dist/index.mjs +1693 -626
- package/dist/types/app_info_v20251028.d.ts +1266 -0
- package/dist/types/app_info_v20260121.d.ts +3293 -0
- package/dist/types/app_revision.d.ts +453 -0
- package/dist/types/client.d.ts +40 -2
- package/dist/types/cvm_id.d.ts +45 -10
- package/dist/types/cvm_info.d.ts +16 -502
- package/dist/types/cvm_info_v20251028.d.ts +988 -0
- package/dist/types/cvm_info_v20260121.d.ts +1264 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/version-mappings.d.ts +38 -0
- package/dist/utils/define-action.d.ts +15 -14
- package/dist/utils/errors.d.ts +2 -2
- package/dist/utils/hostname.d.ts +77 -0
- package/dist/utils/index.d.ts +1 -0
- package/package.json +2 -2
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
export * from "./client";
|
|
2
2
|
export * from "./kms_info";
|
|
3
3
|
export * from "./cvm_info";
|
|
4
|
+
export * from "./cvm_info_v20251028";
|
|
5
|
+
export * from "./cvm_info_v20260121";
|
|
4
6
|
export * from "./cvm_id";
|
|
5
7
|
export * from "./common";
|
|
6
8
|
export * from "./supported_chains";
|
|
9
|
+
export * from "./version-mappings";
|
|
10
|
+
export * from "./app_info_v20251028";
|
|
11
|
+
export * from "./app_info_v20260121";
|
|
12
|
+
export * from "./app_revision";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Version-specific type mappings for API responses
|
|
3
|
+
*
|
|
4
|
+
* This file contains conditional types that map API versions to their
|
|
5
|
+
* corresponding response types, enabling TypeScript to infer the correct
|
|
6
|
+
* types based on the client's API version.
|
|
7
|
+
*/
|
|
8
|
+
import type { CurrentUserV20260121 } from "../credentials/current_user_v20260121";
|
|
9
|
+
import type { CurrentUserV20251028 } from "../credentials/current_user_v20251028";
|
|
10
|
+
import type { DstackAppListResponseV20251028, DstackAppWithCvmResponseV20251028 } from "./app_info_v20251028";
|
|
11
|
+
import type { DstackAppListResponseV20260121, DstackAppWithCvmResponseV20260121 } from "./app_info_v20260121";
|
|
12
|
+
import type { ApiVersion } from "./client";
|
|
13
|
+
import type { CvmDetailV20251028, CvmInfoV20251028, PaginatedCvmInfosV20251028 } from "./cvm_info_v20251028";
|
|
14
|
+
import type { CvmInfoDetailV20260121, CvmInfoV20260121, PaginatedCvmInfosV20260121 } from "./cvm_info_v20260121";
|
|
15
|
+
/**
|
|
16
|
+
* Maps API version to the auth/me response type
|
|
17
|
+
*/
|
|
18
|
+
export type GetCurrentUserResponse<V extends ApiVersion> = V extends "2026-01-21" ? CurrentUserV20260121 : V extends "2025-10-28" ? CurrentUserV20251028 : CurrentUserV20260121;
|
|
19
|
+
/**
|
|
20
|
+
* Maps API version to the paginated CVM list response type
|
|
21
|
+
*/
|
|
22
|
+
export type GetCvmListResponse<V extends ApiVersion> = V extends "2026-01-21" ? PaginatedCvmInfosV20260121 : V extends "2025-10-28" ? PaginatedCvmInfosV20251028 : PaginatedCvmInfosV20260121;
|
|
23
|
+
/**
|
|
24
|
+
* Maps API version to the CVM info detail response type
|
|
25
|
+
*/
|
|
26
|
+
export type GetCvmInfoResponse<V extends ApiVersion> = V extends "2026-01-21" ? CvmInfoDetailV20260121 : V extends "2025-10-28" ? CvmDetailV20251028 : CvmInfoDetailV20260121;
|
|
27
|
+
/**
|
|
28
|
+
* Maps API version to the app list response type
|
|
29
|
+
*/
|
|
30
|
+
export type GetAppListResponse<V extends ApiVersion> = V extends "2026-01-21" ? DstackAppListResponseV20260121 : V extends "2025-10-28" ? DstackAppListResponseV20251028 : DstackAppListResponseV20260121;
|
|
31
|
+
/**
|
|
32
|
+
* Maps API version to the app info response type
|
|
33
|
+
*/
|
|
34
|
+
export type GetAppInfoResponse<V extends ApiVersion> = V extends "2026-01-21" ? DstackAppWithCvmResponseV20260121 : V extends "2025-10-28" ? DstackAppWithCvmResponseV20251028 : DstackAppWithCvmResponseV20260121;
|
|
35
|
+
/**
|
|
36
|
+
* Maps API version to the app CVMs list response type
|
|
37
|
+
*/
|
|
38
|
+
export type GetAppCvmsResponse<V extends ApiVersion> = V extends "2026-01-21" ? CvmInfoV20260121[] : V extends "2025-10-28" ? CvmInfoV20251028[] : CvmInfoV20260121[];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { type Client, type SafeResult } from "../client";
|
|
3
|
+
import type { ApiVersion } from "../types/client";
|
|
3
4
|
/**
|
|
4
5
|
* Defines an action that takes no additional parameters (only client + optional schema)
|
|
5
6
|
*
|
|
@@ -8,51 +9,51 @@ import { type Client, type SafeResult } from "../client";
|
|
|
8
9
|
* - action(client, { schema: CustomSchema }) → returns z.infer<CustomSchema>
|
|
9
10
|
* - action(client, { schema: false }) → returns unknown
|
|
10
11
|
*/
|
|
11
|
-
export declare function defineSimpleAction<TSchema extends z.ZodTypeAny, TReturnOverride = never>(schema: TSchema, fn: (client: Client) => Promise<unknown>): {
|
|
12
|
+
export declare function defineSimpleAction<TSchema extends z.ZodTypeAny, TReturnOverride = never>(schema: TSchema, fn: (client: Client<ApiVersion>) => Promise<unknown>): {
|
|
12
13
|
action: {
|
|
13
|
-
(client: Client
|
|
14
|
+
(client: Client<ApiVersion>, parameters: {
|
|
14
15
|
schema: false;
|
|
15
16
|
}): Promise<unknown>;
|
|
16
|
-
<T extends z.ZodTypeAny>(client: Client
|
|
17
|
+
<T extends z.ZodTypeAny>(client: Client<ApiVersion>, parameters: {
|
|
17
18
|
schema: T;
|
|
18
19
|
}): Promise<z.infer<T>>;
|
|
19
|
-
(client: Client): Promise<[TReturnOverride] extends [never] ? z.TypeOf<TSchema> : TReturnOverride>;
|
|
20
|
+
(client: Client<ApiVersion>): Promise<[TReturnOverride] extends [never] ? z.TypeOf<TSchema> : TReturnOverride>;
|
|
20
21
|
};
|
|
21
22
|
safeAction: {
|
|
22
|
-
(client: Client
|
|
23
|
+
(client: Client<ApiVersion>, parameters: {
|
|
23
24
|
schema: false;
|
|
24
25
|
}): Promise<SafeResult<unknown>>;
|
|
25
|
-
<T extends z.ZodTypeAny>(client: Client
|
|
26
|
+
<T extends z.ZodTypeAny>(client: Client<ApiVersion>, parameters: {
|
|
26
27
|
schema: T;
|
|
27
28
|
}): Promise<SafeResult<z.infer<T>>>;
|
|
28
|
-
(client: Client): Promise<SafeResult<[TReturnOverride] extends [never] ? z.TypeOf<TSchema> : TReturnOverride>>;
|
|
29
|
+
(client: Client<ApiVersion>): Promise<SafeResult<[TReturnOverride] extends [never] ? z.TypeOf<TSchema> : TReturnOverride>>;
|
|
29
30
|
};
|
|
30
31
|
};
|
|
31
32
|
/**
|
|
32
33
|
* Defines an action with parameters
|
|
33
34
|
*/
|
|
34
|
-
export declare function defineAction<TParams, TSchema extends z.ZodTypeAny, TReturnOverride = never>(schema: TSchema, fn: (client: Client
|
|
35
|
+
export declare function defineAction<TParams, TSchema extends z.ZodTypeAny, TReturnOverride = never>(schema: TSchema, fn: (client: Client<ApiVersion>, params: TParams) => Promise<unknown>): {
|
|
35
36
|
action: {
|
|
36
|
-
(client: Client
|
|
37
|
-
<T extends z.ZodTypeAny>(client: Client
|
|
37
|
+
(client: Client<ApiVersion>, ...args: (undefined extends TParams ? true : false) extends true ? [params?: TParams] : [params: TParams]): Promise<[TReturnOverride] extends [never] ? z.TypeOf<TSchema> : TReturnOverride>;
|
|
38
|
+
<T extends z.ZodTypeAny>(client: Client<ApiVersion>, ...args: (undefined extends TParams ? true : false) extends true ? [params?: TParams, parameters?: {
|
|
38
39
|
schema: T;
|
|
39
40
|
}] : [params: TParams, parameters: {
|
|
40
41
|
schema: T;
|
|
41
42
|
}]): Promise<z.infer<T>>;
|
|
42
|
-
(client: Client
|
|
43
|
+
(client: Client<ApiVersion>, ...args: (undefined extends TParams ? true : false) extends true ? [params?: TParams, parameters?: {
|
|
43
44
|
schema: false;
|
|
44
45
|
}] : [params: TParams, parameters: {
|
|
45
46
|
schema: false;
|
|
46
47
|
}]): Promise<unknown>;
|
|
47
48
|
};
|
|
48
49
|
safeAction: {
|
|
49
|
-
(client: Client
|
|
50
|
-
<T extends z.ZodTypeAny>(client: Client
|
|
50
|
+
(client: Client<ApiVersion>, ...args: (undefined extends TParams ? true : false) extends true ? [params?: TParams] : [params: TParams]): Promise<SafeResult<[TReturnOverride] extends [never] ? z.TypeOf<TSchema> : TReturnOverride>>;
|
|
51
|
+
<T extends z.ZodTypeAny>(client: Client<ApiVersion>, ...args: (undefined extends TParams ? true : false) extends true ? [params?: TParams, parameters?: {
|
|
51
52
|
schema: T;
|
|
52
53
|
}] : [params: TParams, parameters: {
|
|
53
54
|
schema: T;
|
|
54
55
|
}]): Promise<SafeResult<z.infer<T>>>;
|
|
55
|
-
(client: Client
|
|
56
|
+
(client: Client<ApiVersion>, ...args: (undefined extends TParams ? true : false) extends true ? [params?: TParams, parameters?: {
|
|
56
57
|
schema: false;
|
|
57
58
|
}] : [params: TParams, parameters: {
|
|
58
59
|
schema: false;
|
package/dist/utils/errors.d.ts
CHANGED
|
@@ -364,8 +364,8 @@ export declare class ResourceError extends BusinessError {
|
|
|
364
364
|
* // - Alternatively, specify CPU and memory requirements manually
|
|
365
365
|
* //
|
|
366
366
|
* // Learn more:
|
|
367
|
-
* // - View available instance types: https://cloud.phala.
|
|
368
|
-
* // - Contact support: https://cloud.phala.
|
|
367
|
+
* // - View available instance types: https://cloud.phala.com/instances
|
|
368
|
+
* // - Contact support: https://cloud.phala.com/support
|
|
369
369
|
* ```
|
|
370
370
|
*/
|
|
371
371
|
export declare function formatStructuredError(error: ResourceError, options?: {
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CVM Hostname/Name utilities
|
|
3
|
+
*
|
|
4
|
+
* RFC 1123 Hostname Format with Phala Cloud requirements:
|
|
5
|
+
* - 5-63 characters (min 5 for generated names like "a-xyz")
|
|
6
|
+
* - Must start with letter (a-z, A-Z)
|
|
7
|
+
* - Can contain letters, numbers, and hyphens
|
|
8
|
+
* - Cannot end with hyphen
|
|
9
|
+
* - Cannot have consecutive hyphens
|
|
10
|
+
* - Uppercase letters are auto-converted to lowercase by convertToHostname()
|
|
11
|
+
*
|
|
12
|
+
* Pattern: ^[a-zA-Z](?!.*--)([a-zA-Z0-9-]*[a-zA-Z0-9])?$
|
|
13
|
+
* Note: Validator accepts both cases; conversion to lowercase happens in convertToHostname()
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Validate hostname format (RFC 1123 with letter-first requirement)
|
|
17
|
+
*
|
|
18
|
+
* Accepts both uppercase and lowercase letters. Actual names should be normalized
|
|
19
|
+
* using convertToHostname() before storing/display.
|
|
20
|
+
*
|
|
21
|
+
* @param name - Name to validate
|
|
22
|
+
* @returns true if valid hostname format (5-63 chars, starts with letter, no consecutive hyphens)
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* isValidHostname("my-app") // true
|
|
26
|
+
* isValidHostname("MyApp") // true (validator accepts uppercase)
|
|
27
|
+
* isValidHostname("123app") // false (starts with number)
|
|
28
|
+
* isValidHostname("-app") // false (starts with hyphen)
|
|
29
|
+
* isValidHostname("app-") // false (ends with hyphen)
|
|
30
|
+
* isValidHostname("app--test") // false (consecutive hyphens not allowed)
|
|
31
|
+
*/
|
|
32
|
+
export declare function isValidHostname(name: string): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Convert any string to hostname-compliant format (RFC 1123)
|
|
35
|
+
*
|
|
36
|
+
* Handles multiple naming styles:
|
|
37
|
+
* - camelCase: MyApp → my-app
|
|
38
|
+
* - snake_case: my_app → my-app
|
|
39
|
+
* - i18n chars: 我的应用 → fallback (dstack-app-{timestamp}-{random})
|
|
40
|
+
* - special chars: my app!@# → my-app
|
|
41
|
+
*
|
|
42
|
+
* @param input - Input string to convert
|
|
43
|
+
* @returns Valid hostname format (5-63 chars, RFC 1123)
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* convertToHostname("MyAwesomeProject") // "my-awesome-project"
|
|
47
|
+
* convertToHostname("my_python_project") // "my-python-project"
|
|
48
|
+
* convertToHostname("我的应用") // "dstack-app-{timestamp}-{random}"
|
|
49
|
+
* convertToHostname("test") // "dstack-app-test"
|
|
50
|
+
*/
|
|
51
|
+
export declare function convertToHostname(input: string): string;
|
|
52
|
+
/**
|
|
53
|
+
* Generate a random hostname with fallback pattern
|
|
54
|
+
* Used when input cannot be reasonably converted
|
|
55
|
+
*
|
|
56
|
+
* Pattern: dstack-app-{base36-timestamp}-{random}
|
|
57
|
+
* Example: dstack-app-1y8a2b3c-4d5e
|
|
58
|
+
*
|
|
59
|
+
* @returns Valid random hostname
|
|
60
|
+
*/
|
|
61
|
+
export declare function generateFallbackHostname(): string;
|
|
62
|
+
/**
|
|
63
|
+
* Generate a default CVM name with prefix and random suffix
|
|
64
|
+
*
|
|
65
|
+
* Pattern: {prefix}-{random5chars}
|
|
66
|
+
* - Always valid RFC 1123 format
|
|
67
|
+
* - Easy to recognize (prefix + random)
|
|
68
|
+
* - Consistent across platforms
|
|
69
|
+
*
|
|
70
|
+
* @param prefix - Descriptive prefix (default: "dstack-app")
|
|
71
|
+
* @returns Valid CVM name
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* generateDefaultCvmName() // "dstack-app-a1b2c"
|
|
75
|
+
* generateDefaultCvmName("my-project") // "my-project-x9y8z"
|
|
76
|
+
*/
|
|
77
|
+
export declare function generateDefaultCvmName(prefix?: string): string;
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { encryptEnvVars } from "@phala/dstack-sdk/encrypt-env-vars";
|
|
|
2
2
|
export { getComposeHash, dumpAppCompose, preprocessAppCompose, sortObject, withComposeMethods, type AppCompose, type AppComposeWithMethods, type SortableValue, type SortableObject, type SortableArray, } from "./get_compose_hash";
|
|
3
3
|
export { asHex } from "./as-hex";
|
|
4
4
|
export { validateActionParameters, safeValidateActionParameters } from "./validate-parameters";
|
|
5
|
+
export { isValidHostname, convertToHostname, generateFallbackHostname, generateDefaultCvmName, } from "./hostname";
|
|
5
6
|
export { parseApiError, PhalaCloudError, RequestError, ValidationError, AuthError, BusinessError, ServerError, UnknownError, ResourceError, formatValidationErrors, formatErrorMessage, formatStructuredError, getErrorMessage, getValidationFields, type ValidationErrorItem, type StructuredErrorDetail, type ErrorLink, type StructuredErrorResponse, ApiErrorSchema, type ApiError, } from "./errors";
|
|
6
7
|
export { createNetworkClients, extractNetworkClients, checkNetworkStatus, checkBalance, validateNetworkPrerequisites, waitForTransactionReceipt, executeTransaction, NetworkError, WalletError, TransactionError, type NetworkConfig, type WalletConnection, type NetworkClients, type BalanceCheckResult, type TransactionOptions, type TransactionResult, } from "./network";
|
|
7
8
|
export { createTransactionTracker, executeBatchTransactions, executeTransactionWithRetry, estimateTransactionGas, type TransactionState, type TransactionStatus, type TransactionTracker, type BatchTransactionOptions, type BatchTransactionResult, type RetryOptions, type GasEstimationOptions, } from "./transaction";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phala/cloud",
|
|
3
|
-
"version": "0.2.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "TypeScript SDK for Phala Cloud API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@types/debug": "^4.1.12",
|
|
51
51
|
"@types/node": "^20.10.0",
|
|
52
52
|
"dotenv": "^16.5.0",
|
|
53
|
-
"tsup": "^8.
|
|
53
|
+
"tsup": "^8.5.1",
|
|
54
54
|
"typescript": "^5.3.0",
|
|
55
55
|
"vitest": "^1.0.0"
|
|
56
56
|
},
|