@@ -2,135 +2,209 @@ import { z } from "zod";
22import { MachinePresetName , TaskRunError } from "./common.js" ;
33import { RunStatus } from "./api.js" ;
44import { RuntimeEnvironmentTypeSchema } from "../../schemas/api.js" ;
5+ import { OutOfMemoryError } from "../errors.js" ;
56
7+ /** Represents a failed run alert webhook payload */
68const AlertWebhookRunFailedObject = z . object ( {
9+ /** Task information */
710 task : z . object ( {
11+ /** Unique identifier for the task */
812 id : z . string ( ) ,
13+ /** File path where the task is defined */
914 filePath : z . string ( ) ,
15+ /** Name of the exported task function */
1016 exportName : z . string ( ) ,
17+ /** Version of the task */
1118 version : z . string ( ) ,
19+ /** Version of the SDK used */
1220 sdkVersion : z . string ( ) ,
21+ /** Version of the CLI used */
1322 cliVersion : z . string ( ) ,
1423 } ) ,
24+ /** Run information */
1525 run : z . object ( {
26+ /** Unique identifier for the run */
1627 id : z . string ( ) ,
28+ /** Run number */
1729 number : z . number ( ) ,
30+ /** Current status of the run */
1831 status : RunStatus ,
32+ /** When the run was created */
1933 createdAt : z . coerce . date ( ) ,
34+ /** When the run started executing */
2035 startedAt : z . coerce . date ( ) . optional ( ) ,
36+ /** When the run finished executing */
2137 completedAt : z . coerce . date ( ) . optional ( ) ,
38+ /** Whether this is a test run */
2239 isTest : z . boolean ( ) ,
40+ /** Idempotency key for the run */
2341 idempotencyKey : z . string ( ) ,
42+ /** Associated tags */
2443 tags : z . array ( z . string ( ) ) ,
44+ /** Error information */
2545 error : TaskRunError ,
26- machine : MachinePresetName ,
46+ /** Whether the run was an out-of-memory error */
47+ isOutOfMemoryError : z . boolean ( ) ,
48+ /** Machine preset used for the run */
49+ machine : z . string ( ) ,
50+ /** URL to view the run in the dashboard */
2751 dashboardUrl : z . string ( ) ,
2852 } ) ,
53+ /** Environment information */
2954 environment : z . object ( {
55+ /** Environment ID */
3056 id : z . string ( ) ,
57+ /** Environment type */
3158 type : RuntimeEnvironmentTypeSchema ,
59+ /** Environment slug */
3260 slug : z . string ( ) ,
3361 } ) ,
62+ /** Organization information */
3463 organization : z . object ( {
64+ /** Organization ID */
3565 id : z . string ( ) ,
66+ /** Organization slug */
3667 slug : z . string ( ) ,
68+ /** Organization name */
3769 name : z . string ( ) ,
3870 } ) ,
71+ /** Project information */
3972 project : z . object ( {
73+ /** Project ID */
4074 id : z . string ( ) ,
75+ /** Project reference */
4176 ref : z . string ( ) ,
77+ /** Project slug */
4278 slug : z . string ( ) ,
79+ /** Project name */
4380 name : z . string ( ) ,
4481 } ) ,
4582} ) ;
4683export type AlertWebhookRunFailedObject = z . infer < typeof AlertWebhookRunFailedObject > ;
4784
85+ /** Represents a deployment error */
4886export const DeployError = z . object ( {
87+ /** Error name */
4988 name : z . string ( ) ,
89+ /** Error message */
5090 message : z . string ( ) ,
91+ /** Error stack trace */
5192 stack : z . string ( ) . optional ( ) ,
93+ /** Standard error output */
5294 stderr : z . string ( ) . optional ( ) ,
5395} ) ;
5496export type DeployError = z . infer < typeof DeployError > ;
5597
98+ /** Represents a deployment alert webhook payload */
5699export const AlertWebhookDeploymentObject = z . discriminatedUnion ( "success" , [
100+ /** Successful deployment */
57101 z . object ( {
58102 success : z . literal ( true ) ,
59103 deployment : z . object ( {
104+ /** Deployment ID */
60105 id : z . string ( ) ,
106+ /** Deployment status */
61107 status : z . string ( ) ,
108+ /** Deployment version */
62109 version : z . string ( ) ,
110+ /** Short code identifier */
63111 shortCode : z . string ( ) ,
112+ /** When the deployment completed */
64113 deployedAt : z . coerce . date ( ) ,
65114 } ) ,
115+ /** Deployed tasks */
66116 tasks : z . array (
67117 z . object ( {
118+ /** Task ID */
68119 id : z . string ( ) ,
120+ /** File path where the task is defined */
69121 filePath : z . string ( ) ,
122+ /** Name of the exported task function */
70123 exportName : z . string ( ) ,
124+ /** Source of the trigger */
71125 triggerSource : z . string ( ) ,
72126 } )
73127 ) ,
128+ /** Environment information */
74129 environment : z . object ( {
75130 id : z . string ( ) ,
76131 type : RuntimeEnvironmentTypeSchema ,
77132 slug : z . string ( ) ,
78133 } ) ,
134+ /** Organization information */
79135 organization : z . object ( {
80136 id : z . string ( ) ,
81137 slug : z . string ( ) ,
82138 name : z . string ( ) ,
83139 } ) ,
140+ /** Project information */
84141 project : z . object ( {
85142 id : z . string ( ) ,
86143 ref : z . string ( ) ,
87144 slug : z . string ( ) ,
88145 name : z . string ( ) ,
89146 } ) ,
90147 } ) ,
148+ /** Failed deployment */
91149 z . object ( {
92150 success : z . literal ( false ) ,
93151 deployment : z . object ( {
152+ /** Deployment ID */
94153 id : z . string ( ) ,
154+ /** Deployment status */
95155 status : z . string ( ) ,
156+ /** Deployment version */
96157 version : z . string ( ) ,
158+ /** Short code identifier */
97159 shortCode : z . string ( ) ,
160+ /** When the deployment failed */
98161 failedAt : z . coerce . date ( ) ,
99162 } ) ,
163+ /** Environment information */
100164 environment : z . object ( {
101165 id : z . string ( ) ,
102166 type : RuntimeEnvironmentTypeSchema ,
103167 slug : z . string ( ) ,
104168 } ) ,
169+ /** Organization information */
105170 organization : z . object ( {
106171 id : z . string ( ) ,
107172 slug : z . string ( ) ,
108173 name : z . string ( ) ,
109174 } ) ,
175+ /** Project information */
110176 project : z . object ( {
111177 id : z . string ( ) ,
112178 ref : z . string ( ) ,
113179 slug : z . string ( ) ,
114180 name : z . string ( ) ,
115181 } ) ,
182+ /** Error information */
116183 error : DeployError ,
117184 } ) ,
118185] ) ;
119186
120187export type AlertWebhookDeploymentObject = z . infer < typeof AlertWebhookDeploymentObject > ;
121188
189+ /** Common properties for all webhooks */
122190const commonProperties = {
191+ /** Webhook ID */
123192 id : z . string ( ) ,
193+ /** When the webhook was created */
124194 created : z . coerce . date ( ) ,
195+ /** Version of the webhook */
125196 webhookVersion : z . string ( ) ,
126197} ;
127198
199+ /** Represents all possible webhook types */
128200export const Webhook = z . discriminatedUnion ( "type" , [
201+ /** Run failed alert webhook */
129202 z . object ( {
130203 ...commonProperties ,
131204 type : z . literal ( "alert.run.failed" ) ,
132205 object : AlertWebhookRunFailedObject ,
133206 } ) ,
207+ /** Deployment finished alert webhook */
134208 z . object ( {
135209 ...commonProperties ,
136210 type : z . literal ( "alert.deployment.finished" ) ,
0 commit comments