@phala/cloud 0.2.4 → 0.2.8

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.
Files changed (49) hide show
  1. package/dist/actions/apps/check_app_cvms_is_allowed.d.ts +164 -0
  2. package/dist/actions/apps/check_app_is_allowed.d.ts +109 -0
  3. package/dist/actions/apps/get_app_attestation.d.ts +963 -0
  4. package/dist/actions/apps/get_app_device_allowlist.d.ts +108 -0
  5. package/dist/actions/blockchains/abi/dstack_app.d.ts +131 -0
  6. package/dist/actions/blockchains/add_device.d.ts +62 -0
  7. package/dist/actions/blockchains/check_compose_hash_allowed.d.ts +43 -0
  8. package/dist/actions/blockchains/check_device_allowed.d.ts +44 -0
  9. package/dist/actions/blockchains/check_on_chain_prerequisites.d.ts +59 -0
  10. package/dist/actions/blockchains/get_allowed_devices.d.ts +65 -0
  11. package/dist/actions/blockchains/remove_device.d.ts +62 -0
  12. package/dist/actions/blockchains/set_allow_any_device.d.ts +62 -0
  13. package/dist/actions/cvms/check_cvm_is_allowed.d.ts +145 -0
  14. package/dist/actions/cvms/commit_cvm_provision.d.ts +19 -0
  15. package/dist/actions/cvms/commit_cvm_update.d.ts +100 -0
  16. package/dist/actions/cvms/confirm_cvm_patch.d.ts +92 -0
  17. package/dist/actions/cvms/get_cvm_attestation.d.ts +220 -0
  18. package/dist/actions/cvms/get_cvm_compose_file.d.ts +16 -0
  19. package/dist/actions/cvms/patch_cvm.d.ts +447 -0
  20. package/dist/actions/cvms/provision_cvm.d.ts +26 -1
  21. package/dist/actions/cvms/provision_cvm_compose_file_update.d.ts +26 -0
  22. package/dist/actions/cvms/refresh_cvm_instance_id.d.ts +93 -0
  23. package/dist/actions/cvms/refresh_cvm_instance_ids.d.ts +194 -0
  24. package/dist/actions/cvms/replicate_cvm.d.ts +126 -0
  25. package/dist/actions/cvms/restart_cvm.d.ts +2 -2
  26. package/dist/actions/cvms/shutdown_cvm.d.ts +2 -2
  27. package/dist/actions/cvms/start_cvm.d.ts +2 -2
  28. package/dist/actions/cvms/stop_cvm.d.ts +2 -2
  29. package/dist/actions/index.d.ts +22 -1
  30. package/dist/actions/kms/get_kms_onchain_detail.d.ts +688 -0
  31. package/dist/actions/os_images/get_os_images.d.ts +217 -0
  32. package/dist/actions/workspaces/get_workspace.d.ts +2 -0
  33. package/dist/actions/workspaces/list_workspaces.d.ts +18 -0
  34. package/dist/client.d.ts +5 -0
  35. package/dist/create-client.d.ts +30 -0
  36. package/dist/index.js +1909 -365
  37. package/dist/index.mjs +1843 -363
  38. package/dist/types/app_compose.d.ts +5 -0
  39. package/dist/types/app_info_v20260121.d.ts +158 -6
  40. package/dist/types/cvm_info.d.ts +3 -3
  41. package/dist/types/cvm_info_v20260121.d.ts +82 -4
  42. package/dist/utils/error_codes.d.ts +48 -0
  43. package/dist/utils/errors.d.ts +9 -0
  44. package/dist/utils/index.d.ts +2 -1
  45. package/dist/utils/verify-webhook.d.ts +35 -0
  46. package/dist/webhook.d.ts +11 -0
  47. package/dist/webhook.js +68 -0
  48. package/dist/webhook.mjs +40 -0
  49. package/package.json +7 -2
@@ -30,7 +30,7 @@ export declare const VMSchema: z.ZodObject<{
30
30
  vm_uuid: z.ZodNullable<z.ZodString>;
31
31
  instance_id: z.ZodNullable<z.ZodString>;
32
32
  app_url: z.ZodNullable<z.ZodOptional<z.ZodString>>;
33
- base_image: z.ZodNullable<z.ZodString>;
33
+ base_image: z.ZodNullable<z.ZodOptional<z.ZodString>>;
34
34
  vcpu: z.ZodNumber;
35
35
  memory: z.ZodNumber;
36
36
  disk_size: z.ZodNumber;
@@ -52,7 +52,6 @@ export declare const VMSchema: z.ZodObject<{
52
52
  disk_size: number;
53
53
  teepod_id: number;
54
54
  vm_uuid: string | null;
55
- base_image: string | null;
56
55
  encrypted_env_pubkey: string | null;
57
56
  created_at: string;
58
57
  version?: string | null | undefined;
@@ -62,6 +61,7 @@ export declare const VMSchema: z.ZodObject<{
62
61
  id: number;
63
62
  region_identifier?: string | null | undefined;
64
63
  } | null | undefined;
64
+ base_image?: string | null | undefined;
65
65
  user_id?: number | null | undefined;
66
66
  docker_compose_file?: string | null | undefined;
67
67
  features?: string[] | null | undefined;
@@ -78,7 +78,6 @@ export declare const VMSchema: z.ZodObject<{
78
78
  disk_size: number;
79
79
  teepod_id: number;
80
80
  vm_uuid: string | null;
81
- base_image: string | null;
82
81
  encrypted_env_pubkey: string | null;
83
82
  created_at: string;
84
83
  version?: string | null | undefined;
@@ -88,6 +87,7 @@ export declare const VMSchema: z.ZodObject<{
88
87
  id: number;
89
88
  region_identifier?: string | null | undefined;
90
89
  } | null | undefined;
90
+ base_image?: string | null | undefined;
91
91
  user_id?: number | null | undefined;
92
92
  docker_compose_file?: string | null | undefined;
93
93
  features?: string[] | null | undefined;
@@ -83,7 +83,7 @@ export declare const CvmOsInfoV20260121Schema: z.ZodObject<{
83
83
  os_image_hash?: string | null | undefined;
84
84
  }>;
85
85
  export type CvmOsInfoV20260121 = z.infer<typeof CvmOsInfoV20260121Schema>;
86
- export declare const CvmKmsInfoV20260121Schema: z.ZodObject<{
86
+ export declare const CvmKmsInfoV20260121Schema: z.ZodEffects<z.ZodObject<{
87
87
  chain_id: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
88
88
  dstack_kms_address: z.ZodOptional<z.ZodNullable<z.ZodString>>;
89
89
  dstack_app_address: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -104,6 +104,20 @@ export declare const CvmKmsInfoV20260121Schema: z.ZodObject<{
104
104
  dstack_kms_address?: string | null | undefined;
105
105
  dstack_app_address?: string | null | undefined;
106
106
  rpc_endpoint?: string | null | undefined;
107
+ }>, {
108
+ chain_id?: number | null | undefined;
109
+ encrypted_env_pubkey?: string | null | undefined;
110
+ deployer_address?: string | null | undefined;
111
+ dstack_kms_address?: string | null | undefined;
112
+ dstack_app_address?: string | null | undefined;
113
+ rpc_endpoint?: string | null | undefined;
114
+ }, {
115
+ chain_id?: number | null | undefined;
116
+ encrypted_env_pubkey?: string | null | undefined;
117
+ deployer_address?: string | null | undefined;
118
+ dstack_kms_address?: string | null | undefined;
119
+ dstack_app_address?: string | null | undefined;
120
+ rpc_endpoint?: string | null | undefined;
107
121
  }>;
108
122
  export type CvmKmsInfoV20260121 = z.infer<typeof CvmKmsInfoV20260121Schema>;
109
123
  export declare const CvmProgressInfoV20260121Schema: z.ZodObject<{
@@ -194,6 +208,7 @@ export declare const CvmInfoV20260121Schema: z.ZodObject<{
194
208
  name: z.ZodString;
195
209
  app_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
196
210
  vm_uuid: z.ZodOptional<z.ZodNullable<z.ZodString>>;
211
+ instance_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
197
212
  resource: z.ZodObject<{
198
213
  instance_type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
199
214
  vcpu: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
@@ -264,7 +279,7 @@ export declare const CvmInfoV20260121Schema: z.ZodObject<{
264
279
  os_image_hash?: string | null | undefined;
265
280
  }>>>;
266
281
  kms_type: z.ZodOptional<z.ZodNullable<z.ZodEnum<["phala", "ethereum", "base", "legacy"]>>>;
267
- kms_info: z.ZodOptional<z.ZodNullable<z.ZodObject<{
282
+ kms_info: z.ZodOptional<z.ZodNullable<z.ZodEffects<z.ZodObject<{
268
283
  chain_id: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
269
284
  dstack_kms_address: z.ZodOptional<z.ZodNullable<z.ZodString>>;
270
285
  dstack_app_address: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -285,6 +300,20 @@ export declare const CvmInfoV20260121Schema: z.ZodObject<{
285
300
  dstack_kms_address?: string | null | undefined;
286
301
  dstack_app_address?: string | null | undefined;
287
302
  rpc_endpoint?: string | null | undefined;
303
+ }>, {
304
+ chain_id?: number | null | undefined;
305
+ encrypted_env_pubkey?: string | null | undefined;
306
+ deployer_address?: string | null | undefined;
307
+ dstack_kms_address?: string | null | undefined;
308
+ dstack_app_address?: string | null | undefined;
309
+ rpc_endpoint?: string | null | undefined;
310
+ }, {
311
+ chain_id?: number | null | undefined;
312
+ encrypted_env_pubkey?: string | null | undefined;
313
+ deployer_address?: string | null | undefined;
314
+ dstack_kms_address?: string | null | undefined;
315
+ dstack_app_address?: string | null | undefined;
316
+ rpc_endpoint?: string | null | undefined;
288
317
  }>>>;
289
318
  status: z.ZodString;
290
319
  progress: z.ZodOptional<z.ZodNullable<z.ZodObject<{
@@ -327,6 +356,7 @@ export declare const CvmInfoV20260121Schema: z.ZodObject<{
327
356
  public_tcbinfo: z.ZodOptional<z.ZodBoolean>;
328
357
  gateway_enabled: z.ZodOptional<z.ZodBoolean>;
329
358
  secure_time: z.ZodOptional<z.ZodBoolean>;
359
+ listed: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
330
360
  storage_fs: z.ZodOptional<z.ZodString>;
331
361
  workspace: z.ZodOptional<z.ZodNullable<z.ZodObject<{
332
362
  object_type: z.ZodLiteral<"workspace">;
@@ -367,6 +397,7 @@ export declare const CvmInfoV20260121Schema: z.ZodObject<{
367
397
  status: string;
368
398
  name: string;
369
399
  id: string;
400
+ listed: boolean;
370
401
  resource: {
371
402
  vcpu?: number | null | undefined;
372
403
  billing_period?: "skip" | "hourly" | "monthly" | null | undefined;
@@ -389,6 +420,7 @@ export declare const CvmInfoV20260121Schema: z.ZodObject<{
389
420
  avatar_url?: string | null | undefined;
390
421
  } | null | undefined;
391
422
  app_id?: string | null | undefined;
423
+ instance_id?: string | null | undefined;
392
424
  kms_info?: {
393
425
  chain_id?: number | null | undefined;
394
426
  encrypted_env_pubkey?: string | null | undefined;
@@ -462,6 +494,8 @@ export declare const CvmInfoV20260121Schema: z.ZodObject<{
462
494
  avatar_url?: string | null | undefined;
463
495
  } | null | undefined;
464
496
  app_id?: string | null | undefined;
497
+ instance_id?: string | null | undefined;
498
+ listed?: boolean | undefined;
465
499
  kms_info?: {
466
500
  chain_id?: number | null | undefined;
467
501
  encrypted_env_pubkey?: string | null | undefined;
@@ -518,6 +552,7 @@ export declare const CvmInfoDetailV20260121Schema: z.ZodObject<{
518
552
  name: z.ZodString;
519
553
  app_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
520
554
  vm_uuid: z.ZodOptional<z.ZodNullable<z.ZodString>>;
555
+ instance_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
521
556
  resource: z.ZodObject<{
522
557
  instance_type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
523
558
  vcpu: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
@@ -588,7 +623,7 @@ export declare const CvmInfoDetailV20260121Schema: z.ZodObject<{
588
623
  os_image_hash?: string | null | undefined;
589
624
  }>>>;
590
625
  kms_type: z.ZodOptional<z.ZodNullable<z.ZodEnum<["phala", "ethereum", "base", "legacy"]>>>;
591
- kms_info: z.ZodOptional<z.ZodNullable<z.ZodObject<{
626
+ kms_info: z.ZodOptional<z.ZodNullable<z.ZodEffects<z.ZodObject<{
592
627
  chain_id: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
593
628
  dstack_kms_address: z.ZodOptional<z.ZodNullable<z.ZodString>>;
594
629
  dstack_app_address: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -609,6 +644,20 @@ export declare const CvmInfoDetailV20260121Schema: z.ZodObject<{
609
644
  dstack_kms_address?: string | null | undefined;
610
645
  dstack_app_address?: string | null | undefined;
611
646
  rpc_endpoint?: string | null | undefined;
647
+ }>, {
648
+ chain_id?: number | null | undefined;
649
+ encrypted_env_pubkey?: string | null | undefined;
650
+ deployer_address?: string | null | undefined;
651
+ dstack_kms_address?: string | null | undefined;
652
+ dstack_app_address?: string | null | undefined;
653
+ rpc_endpoint?: string | null | undefined;
654
+ }, {
655
+ chain_id?: number | null | undefined;
656
+ encrypted_env_pubkey?: string | null | undefined;
657
+ deployer_address?: string | null | undefined;
658
+ dstack_kms_address?: string | null | undefined;
659
+ dstack_app_address?: string | null | undefined;
660
+ rpc_endpoint?: string | null | undefined;
612
661
  }>>>;
613
662
  status: z.ZodString;
614
663
  progress: z.ZodOptional<z.ZodNullable<z.ZodObject<{
@@ -651,6 +700,7 @@ export declare const CvmInfoDetailV20260121Schema: z.ZodObject<{
651
700
  public_tcbinfo: z.ZodOptional<z.ZodBoolean>;
652
701
  gateway_enabled: z.ZodOptional<z.ZodBoolean>;
653
702
  secure_time: z.ZodOptional<z.ZodBoolean>;
703
+ listed: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
654
704
  storage_fs: z.ZodOptional<z.ZodString>;
655
705
  workspace: z.ZodOptional<z.ZodNullable<z.ZodObject<{
656
706
  object_type: z.ZodLiteral<"workspace">;
@@ -693,6 +743,7 @@ export declare const CvmInfoDetailV20260121Schema: z.ZodObject<{
693
743
  status: string;
694
744
  name: string;
695
745
  id: string;
746
+ listed: boolean;
696
747
  resource: {
697
748
  vcpu?: number | null | undefined;
698
749
  billing_period?: "skip" | "hourly" | "monthly" | null | undefined;
@@ -715,6 +766,7 @@ export declare const CvmInfoDetailV20260121Schema: z.ZodObject<{
715
766
  avatar_url?: string | null | undefined;
716
767
  } | null | undefined;
717
768
  app_id?: string | null | undefined;
769
+ instance_id?: string | null | undefined;
718
770
  kms_info?: {
719
771
  chain_id?: number | null | undefined;
720
772
  encrypted_env_pubkey?: string | null | undefined;
@@ -789,6 +841,8 @@ export declare const CvmInfoDetailV20260121Schema: z.ZodObject<{
789
841
  avatar_url?: string | null | undefined;
790
842
  } | null | undefined;
791
843
  app_id?: string | null | undefined;
844
+ instance_id?: string | null | undefined;
845
+ listed?: boolean | undefined;
792
846
  kms_info?: {
793
847
  chain_id?: number | null | undefined;
794
848
  encrypted_env_pubkey?: string | null | undefined;
@@ -847,6 +901,7 @@ export declare const PaginatedCvmInfosV20260121Schema: z.ZodObject<{
847
901
  name: z.ZodString;
848
902
  app_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
849
903
  vm_uuid: z.ZodOptional<z.ZodNullable<z.ZodString>>;
904
+ instance_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
850
905
  resource: z.ZodObject<{
851
906
  instance_type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
852
907
  vcpu: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
@@ -917,7 +972,7 @@ export declare const PaginatedCvmInfosV20260121Schema: z.ZodObject<{
917
972
  os_image_hash?: string | null | undefined;
918
973
  }>>>;
919
974
  kms_type: z.ZodOptional<z.ZodNullable<z.ZodEnum<["phala", "ethereum", "base", "legacy"]>>>;
920
- kms_info: z.ZodOptional<z.ZodNullable<z.ZodObject<{
975
+ kms_info: z.ZodOptional<z.ZodNullable<z.ZodEffects<z.ZodObject<{
921
976
  chain_id: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
922
977
  dstack_kms_address: z.ZodOptional<z.ZodNullable<z.ZodString>>;
923
978
  dstack_app_address: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -938,6 +993,20 @@ export declare const PaginatedCvmInfosV20260121Schema: z.ZodObject<{
938
993
  dstack_kms_address?: string | null | undefined;
939
994
  dstack_app_address?: string | null | undefined;
940
995
  rpc_endpoint?: string | null | undefined;
996
+ }>, {
997
+ chain_id?: number | null | undefined;
998
+ encrypted_env_pubkey?: string | null | undefined;
999
+ deployer_address?: string | null | undefined;
1000
+ dstack_kms_address?: string | null | undefined;
1001
+ dstack_app_address?: string | null | undefined;
1002
+ rpc_endpoint?: string | null | undefined;
1003
+ }, {
1004
+ chain_id?: number | null | undefined;
1005
+ encrypted_env_pubkey?: string | null | undefined;
1006
+ deployer_address?: string | null | undefined;
1007
+ dstack_kms_address?: string | null | undefined;
1008
+ dstack_app_address?: string | null | undefined;
1009
+ rpc_endpoint?: string | null | undefined;
941
1010
  }>>>;
942
1011
  status: z.ZodString;
943
1012
  progress: z.ZodOptional<z.ZodNullable<z.ZodObject<{
@@ -980,6 +1049,7 @@ export declare const PaginatedCvmInfosV20260121Schema: z.ZodObject<{
980
1049
  public_tcbinfo: z.ZodOptional<z.ZodBoolean>;
981
1050
  gateway_enabled: z.ZodOptional<z.ZodBoolean>;
982
1051
  secure_time: z.ZodOptional<z.ZodBoolean>;
1052
+ listed: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
983
1053
  storage_fs: z.ZodOptional<z.ZodString>;
984
1054
  workspace: z.ZodOptional<z.ZodNullable<z.ZodObject<{
985
1055
  object_type: z.ZodLiteral<"workspace">;
@@ -1020,6 +1090,7 @@ export declare const PaginatedCvmInfosV20260121Schema: z.ZodObject<{
1020
1090
  status: string;
1021
1091
  name: string;
1022
1092
  id: string;
1093
+ listed: boolean;
1023
1094
  resource: {
1024
1095
  vcpu?: number | null | undefined;
1025
1096
  billing_period?: "skip" | "hourly" | "monthly" | null | undefined;
@@ -1042,6 +1113,7 @@ export declare const PaginatedCvmInfosV20260121Schema: z.ZodObject<{
1042
1113
  avatar_url?: string | null | undefined;
1043
1114
  } | null | undefined;
1044
1115
  app_id?: string | null | undefined;
1116
+ instance_id?: string | null | undefined;
1045
1117
  kms_info?: {
1046
1118
  chain_id?: number | null | undefined;
1047
1119
  encrypted_env_pubkey?: string | null | undefined;
@@ -1115,6 +1187,8 @@ export declare const PaginatedCvmInfosV20260121Schema: z.ZodObject<{
1115
1187
  avatar_url?: string | null | undefined;
1116
1188
  } | null | undefined;
1117
1189
  app_id?: string | null | undefined;
1190
+ instance_id?: string | null | undefined;
1191
+ listed?: boolean | undefined;
1118
1192
  kms_info?: {
1119
1193
  chain_id?: number | null | undefined;
1120
1194
  encrypted_env_pubkey?: string | null | undefined;
@@ -1174,6 +1248,7 @@ export declare const PaginatedCvmInfosV20260121Schema: z.ZodObject<{
1174
1248
  status: string;
1175
1249
  name: string;
1176
1250
  id: string;
1251
+ listed: boolean;
1177
1252
  resource: {
1178
1253
  vcpu?: number | null | undefined;
1179
1254
  billing_period?: "skip" | "hourly" | "monthly" | null | undefined;
@@ -1196,6 +1271,7 @@ export declare const PaginatedCvmInfosV20260121Schema: z.ZodObject<{
1196
1271
  avatar_url?: string | null | undefined;
1197
1272
  } | null | undefined;
1198
1273
  app_id?: string | null | undefined;
1274
+ instance_id?: string | null | undefined;
1199
1275
  kms_info?: {
1200
1276
  chain_id?: number | null | undefined;
1201
1277
  encrypted_env_pubkey?: string | null | undefined;
@@ -1275,6 +1351,8 @@ export declare const PaginatedCvmInfosV20260121Schema: z.ZodObject<{
1275
1351
  avatar_url?: string | null | undefined;
1276
1352
  } | null | undefined;
1277
1353
  app_id?: string | null | undefined;
1354
+ instance_id?: string | null | undefined;
1355
+ listed?: boolean | undefined;
1278
1356
  kms_info?: {
1279
1357
  chain_id?: number | null | undefined;
1280
1358
  encrypted_env_pubkey?: string | null | undefined;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Phala Cloud API structured error codes.
3
+ *
4
+ * Use with ResourceError.errorCode to match specific errors:
5
+ * ```typescript
6
+ * if (error instanceof ResourceError && error.errorCode === ErrorCodes.CVM_APP_ID_CONFLICT) {
7
+ * // handle idempotency conflict
8
+ * }
9
+ * ```
10
+ */
11
+ export declare const ErrorCodes: {
12
+ readonly NODE_NOT_FOUND: "ERR-01-001";
13
+ readonly COMPOSE_FILE_REQUIRED: "ERR-01-002";
14
+ readonly INVALID_COMPOSE_FILE: "ERR-01-003";
15
+ readonly DUPLICATE_CVM_NAME: "ERR-01-004";
16
+ readonly HASH_REGISTRATION_REQUIRED: "ERR-01-005";
17
+ readonly HASH_INVALID_OR_EXPIRED: "ERR-01-006";
18
+ readonly TX_VERIFICATION_FAILED: "ERR-01-007";
19
+ readonly HASH_NOT_ALLOWED: "ERR-01-008";
20
+ readonly INSTANCE_TYPE_NOT_FOUND: "ERR-02-001";
21
+ readonly RESOURCE_NOT_AVAILABLE: "ERR-02-002";
22
+ readonly INSUFFICIENT_VCPU: "ERR-02-003";
23
+ readonly INSUFFICIENT_MEMORY: "ERR-02-004";
24
+ readonly INSUFFICIENT_SLOTS: "ERR-02-005";
25
+ readonly GPU_ALLOCATION_ERROR: "ERR-02-006";
26
+ readonly INSUFFICIENT_GPU: "ERR-02-007";
27
+ readonly INVALID_REQUEST: "ERR-02-008";
28
+ readonly INCOMPATIBLE_CONFIG: "ERR-02-009";
29
+ readonly IMAGE_NOT_FOUND: "ERR-02-010";
30
+ readonly KMS_NOT_FOUND: "ERR-02-011";
31
+ readonly TEEPOD_NOT_ACCESSIBLE: "ERR-02-012";
32
+ readonly OS_IMAGE_NOT_COMPATIBLE: "ERR-02-013";
33
+ readonly NODE_CAPACITY_NOT_CONFIGURED: "ERR-02-014";
34
+ readonly QUOTA_EXCEEDED: "ERR-02-015";
35
+ readonly CVM_NOT_FOUND: "ERR-03-001";
36
+ readonly MULTIPLE_CVMS_SAME_NAME: "ERR-03-002";
37
+ readonly CVM_NOT_IN_WORKSPACE: "ERR-03-003";
38
+ readonly CVM_ACCESS_DENIED: "ERR-03-005";
39
+ readonly REPLICA_IMAGE_NOT_AVAILABLE: "ERR-03-006";
40
+ readonly CVM_APP_ID_CONFLICT: "ERR-03-007";
41
+ readonly INSUFFICIENT_BALANCE: "ERR-04-001";
42
+ readonly MAX_CVM_LIMIT: "ERR-04-002";
43
+ readonly RESOURCE_LIMIT_EXCEEDED: "ERR-04-003";
44
+ readonly TOKEN_LIMIT_EXCEEDED: "ERR-05-001";
45
+ readonly TOKEN_RATE_LIMIT: "ERR-05-002";
46
+ readonly OAUTH_EMAIL_INVALID: "ERR-06-001";
47
+ };
48
+ export type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
@@ -376,3 +376,12 @@ export declare function formatStructuredError(error: ResourceError, options?: {
376
376
  /** Show links (default: true) */
377
377
  showLinks?: boolean;
378
378
  }): string;
379
+ /**
380
+ * Check if an error is a conflict error (409).
381
+ */
382
+ export declare function isConflictError(error: PhalaCloudError): boolean;
383
+ /**
384
+ * Check if an error is an app_id conflict from idempotent CVM creation.
385
+ * This means the app_id already has an active CVM with a different compose_hash.
386
+ */
387
+ export declare function isAppIdConflictError(error: PhalaCloudError): error is ResourceError;
@@ -3,7 +3,8 @@ export { getComposeHash, dumpAppCompose, preprocessAppCompose, sortObject, withC
3
3
  export { asHex } from "./as-hex";
4
4
  export { validateActionParameters, safeValidateActionParameters } from "./validate-parameters";
5
5
  export { isValidHostname, convertToHostname, generateFallbackHostname, generateDefaultCvmName, } from "./hostname";
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
+ export { parseApiError, PhalaCloudError, RequestError, ValidationError, AuthError, BusinessError, ServerError, UnknownError, ResourceError, formatValidationErrors, formatErrorMessage, formatStructuredError, getErrorMessage, isConflictError, isAppIdConflictError, getValidationFields, type ValidationErrorItem, type StructuredErrorDetail, type ErrorLink, type StructuredErrorResponse, ApiErrorSchema, type ApiError, } from "./errors";
7
+ export { ErrorCodes, type ErrorCode } from "./error_codes";
7
8
  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";
8
9
  export { createTransactionTracker, executeBatchTransactions, executeTransactionWithRetry, estimateTransactionGas, type TransactionState, type TransactionStatus, type TransactionTracker, type BatchTransactionOptions, type BatchTransactionResult, type RetryOptions, type GasEstimationOptions, } from "./transaction";
9
10
  export { createClientsFromPrivateKey, createClientsFromBrowser, autoCreateClients, switchToNetwork, addNetwork, } from "./client-factories";
@@ -0,0 +1,35 @@
1
+ /** Webhook event envelope */
2
+ export interface WebhookEvent<T = unknown> {
3
+ id: string;
4
+ event: string;
5
+ version: string;
6
+ created_at: string;
7
+ workspace: {
8
+ id: string;
9
+ name: string;
10
+ };
11
+ data: T;
12
+ }
13
+ /**
14
+ * Verify an HMAC-SHA256 webhook signature.
15
+ *
16
+ * @returns true if signature is valid and timestamp is within tolerance
17
+ */
18
+ export declare function verifyWebhookSignature(params: {
19
+ secret: string;
20
+ timestamp: string;
21
+ body: string;
22
+ signature: string;
23
+ toleranceSeconds?: number;
24
+ }): boolean;
25
+ /**
26
+ * Parse and verify a webhook event from HTTP request headers and body.
27
+ *
28
+ * @throws Error if signature is invalid, timestamp is expired, or headers are missing
29
+ */
30
+ export declare function parseWebhookEvent<T = unknown>(params: {
31
+ headers: Record<string, string | string[] | undefined>;
32
+ body: string;
33
+ secret: string;
34
+ toleranceSeconds?: number;
35
+ }): WebhookEvent<T>;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Webhook signature verification utilities.
3
+ *
4
+ * Exported separately from the main entry point because these
5
+ * depend on `node:crypto` and must not be included in browser bundles.
6
+ *
7
+ * Usage:
8
+ * import { verifyWebhookSignature, parseWebhookEvent } from "@phala/cloud/webhook";
9
+ */
10
+ export { verifyWebhookSignature, parseWebhookEvent } from "./utils/verify-webhook";
11
+ export type { WebhookEvent } from "./utils/verify-webhook";
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/webhook.ts
21
+ var webhook_exports = {};
22
+ __export(webhook_exports, {
23
+ parseWebhookEvent: () => parseWebhookEvent,
24
+ verifyWebhookSignature: () => verifyWebhookSignature
25
+ });
26
+ module.exports = __toCommonJS(webhook_exports);
27
+
28
+ // src/utils/verify-webhook.ts
29
+ var import_node_crypto = require("crypto");
30
+ function verifyWebhookSignature(params) {
31
+ const { secret, timestamp, body, signature, toleranceSeconds = 300 } = params;
32
+ const ts = Number.parseInt(timestamp, 10);
33
+ if (Number.isNaN(ts)) return false;
34
+ const now = Math.floor(Date.now() / 1e3);
35
+ if (Math.abs(now - ts) > toleranceSeconds) return false;
36
+ const expected = `sha256=${(0, import_node_crypto.createHmac)("sha256", secret).update(`${timestamp}.${body}`).digest("hex")}`;
37
+ const expectedBuf = Buffer.from(expected, "utf-8");
38
+ const actualBuf = Buffer.from(signature, "utf-8");
39
+ if (expectedBuf.length !== actualBuf.length) return false;
40
+ return (0, import_node_crypto.timingSafeEqual)(expectedBuf, actualBuf);
41
+ }
42
+ function parseWebhookEvent(params) {
43
+ const { headers, body, secret, toleranceSeconds } = params;
44
+ const normalised = {};
45
+ for (const [key, value] of Object.entries(headers)) {
46
+ const resolved = Array.isArray(value) ? value[0] : value;
47
+ if (resolved != null) {
48
+ normalised[key.toLowerCase()] = resolved;
49
+ }
50
+ }
51
+ const timestamp = normalised["x-webhook-timestamp"];
52
+ const signature = normalised["x-webhook-signature"];
53
+ if (!timestamp || !signature) {
54
+ throw new Error(
55
+ "Missing required webhook headers: X-Webhook-Timestamp and X-Webhook-Signature"
56
+ );
57
+ }
58
+ const valid = verifyWebhookSignature({ secret, timestamp, body, signature, toleranceSeconds });
59
+ if (!valid) {
60
+ throw new Error("Invalid webhook signature or expired timestamp");
61
+ }
62
+ return JSON.parse(body);
63
+ }
64
+ // Annotate the CommonJS export names for ESM import in node:
65
+ 0 && (module.exports = {
66
+ parseWebhookEvent,
67
+ verifyWebhookSignature
68
+ });
@@ -0,0 +1,40 @@
1
+ // src/utils/verify-webhook.ts
2
+ import { createHmac, timingSafeEqual } from "crypto";
3
+ function verifyWebhookSignature(params) {
4
+ const { secret, timestamp, body, signature, toleranceSeconds = 300 } = params;
5
+ const ts = Number.parseInt(timestamp, 10);
6
+ if (Number.isNaN(ts)) return false;
7
+ const now = Math.floor(Date.now() / 1e3);
8
+ if (Math.abs(now - ts) > toleranceSeconds) return false;
9
+ const expected = `sha256=${createHmac("sha256", secret).update(`${timestamp}.${body}`).digest("hex")}`;
10
+ const expectedBuf = Buffer.from(expected, "utf-8");
11
+ const actualBuf = Buffer.from(signature, "utf-8");
12
+ if (expectedBuf.length !== actualBuf.length) return false;
13
+ return timingSafeEqual(expectedBuf, actualBuf);
14
+ }
15
+ function parseWebhookEvent(params) {
16
+ const { headers, body, secret, toleranceSeconds } = params;
17
+ const normalised = {};
18
+ for (const [key, value] of Object.entries(headers)) {
19
+ const resolved = Array.isArray(value) ? value[0] : value;
20
+ if (resolved != null) {
21
+ normalised[key.toLowerCase()] = resolved;
22
+ }
23
+ }
24
+ const timestamp = normalised["x-webhook-timestamp"];
25
+ const signature = normalised["x-webhook-signature"];
26
+ if (!timestamp || !signature) {
27
+ throw new Error(
28
+ "Missing required webhook headers: X-Webhook-Timestamp and X-Webhook-Signature"
29
+ );
30
+ }
31
+ const valid = verifyWebhookSignature({ secret, timestamp, body, signature, toleranceSeconds });
32
+ if (!valid) {
33
+ throw new Error("Invalid webhook signature or expired timestamp");
34
+ }
35
+ return JSON.parse(body);
36
+ }
37
+ export {
38
+ parseWebhookEvent,
39
+ verifyWebhookSignature
40
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phala/cloud",
3
- "version": "0.2.4",
3
+ "version": "0.2.8",
4
4
  "description": "TypeScript SDK for Phala Cloud API",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -11,11 +11,16 @@
11
11
  "import": "./dist/index.mjs",
12
12
  "require": "./dist/index.js"
13
13
  },
14
+ "./webhook": {
15
+ "types": "./dist/webhook.d.ts",
16
+ "import": "./dist/webhook.mjs",
17
+ "require": "./dist/webhook.js"
18
+ },
14
19
  "./package.json": "./package.json"
15
20
  },
16
21
  "files": ["dist/**/*", "!dist/**/*.map", "README.md", "LICENSE"],
17
22
  "scripts": {
18
- "build": "tsup src/index.ts --format cjs,esm && tsc --emitDeclarationOnly --declaration --outDir dist",
23
+ "build": "tsup src/index.ts src/webhook.ts --format cjs,esm && tsc --emitDeclarationOnly --declaration --outDir dist",
19
24
  "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
20
25
  "fmt": "biome format --write",
21
26
  "test": "vitest --run --exclude '**/*.e2e.test.ts'",