-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathapi.ts
More file actions
1600 lines (1365 loc) · 48.4 KB
/
api.ts
File metadata and controls
1600 lines (1365 loc) · 48.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { z } from "zod";
import { DeserializedJsonSchema } from "../../schemas/json.js";
import {
FlushedRunMetadata,
GitMeta,
MachinePresetName,
SerializedError,
TaskRunError,
} from "./common.js";
import { BackgroundWorkerMetadata } from "./resources.js";
import { DequeuedMessage, MachineResources } from "./runEngine.js";
export const RunEngineVersion = z.union([z.literal("V1"), z.literal("V2")]);
export const WhoAmIResponseSchema = z.object({
userId: z.string(),
email: z.string().email(),
dashboardUrl: z.string(),
project: z
.object({
name: z.string(),
url: z.string(),
orgTitle: z.string(),
})
.optional(),
});
export type WhoAmIResponse = z.infer<typeof WhoAmIResponseSchema>;
export const GetProjectResponseBody = z.object({
id: z.string(),
externalRef: z
.string()
.describe(
"The external reference for the project, also known as the project ref, a unique identifier starting with proj_"
),
name: z.string(),
slug: z.string(),
createdAt: z.coerce.date(),
organization: z.object({
id: z.string(),
title: z.string(),
slug: z.string(),
createdAt: z.coerce.date(),
}),
});
export type GetProjectResponseBody = z.infer<typeof GetProjectResponseBody>;
export const GetProjectsResponseBody = z.array(GetProjectResponseBody);
export type GetProjectsResponseBody = z.infer<typeof GetProjectsResponseBody>;
export const GetOrgsResponseBody = z.array(
z.object({
id: z.string(),
title: z.string(),
slug: z.string(),
createdAt: z.coerce.date(),
})
);
export type GetOrgsResponseBody = z.infer<typeof GetOrgsResponseBody>;
export const CreateProjectRequestBody = z.object({
name: z
.string()
.trim()
.min(1, "Name is required")
.max(255, "Name must be less than 255 characters"),
});
export type CreateProjectRequestBody = z.infer<typeof CreateProjectRequestBody>;
export const GetProjectEnvResponse = z.object({
apiKey: z.string(),
name: z.string(),
apiUrl: z.string(),
projectId: z.string(),
});
export type GetProjectEnvResponse = z.infer<typeof GetProjectEnvResponse>;
// Zod schema for the response body type
export const GetWorkerTaskResponse = z.object({
id: z.string(),
slug: z.string(),
filePath: z.string(),
triggerSource: z.string(),
createdAt: z.coerce.date(),
payloadSchema: z.any().nullish(),
});
export const GetWorkerByTagResponse = z.object({
worker: z.object({
id: z.string(),
version: z.string(),
engine: z.string().nullish(),
sdkVersion: z.string().nullish(),
cliVersion: z.string().nullish(),
tasks: z.array(GetWorkerTaskResponse),
}),
urls: z.object({
runs: z.string(),
}),
});
export type GetWorkerByTagResponse = z.infer<typeof GetWorkerByTagResponse>;
export const GetJWTRequestBody = z.object({
claims: z
.object({
scopes: z.array(z.string()).default([]),
})
.optional(),
expirationTime: z.union([z.number(), z.string()]).optional(),
});
export type GetJWTRequestBody = z.infer<typeof GetJWTRequestBody>;
export const GetJWTResponse = z.object({
token: z.string(),
});
export type GetJWTResponse = z.infer<typeof GetJWTResponse>;
export const CreateBackgroundWorkerRequestBody = z.object({
localOnly: z.boolean(),
metadata: BackgroundWorkerMetadata,
engine: RunEngineVersion.optional(),
supportsLazyAttempts: z.boolean().optional(),
buildPlatform: z.string().optional(),
targetPlatform: z.string().optional(),
});
export type CreateBackgroundWorkerRequestBody = z.infer<typeof CreateBackgroundWorkerRequestBody>;
export const CreateBackgroundWorkerResponse = z.object({
id: z.string(),
version: z.string(),
contentHash: z.string(),
});
export type CreateBackgroundWorkerResponse = z.infer<typeof CreateBackgroundWorkerResponse>;
//an array of 1, 2, or 3 strings
const RunTag = z.string().max(128, "Tags must be less than 128 characters");
export const RunTags = z.union([RunTag, RunTag.array()]);
export type RunTags = z.infer<typeof RunTags>;
/** Stores the original user-provided idempotency key and scope */
export const IdempotencyKeyOptionsSchema = z.object({
key: z.string(),
scope: z.enum(["run", "attempt", "global"]),
});
export type IdempotencyKeyOptionsSchema = z.infer<typeof IdempotencyKeyOptionsSchema>;
export const TriggerTaskRequestBody = z.object({
payload: z.any(),
context: z.any(),
options: z
.object({
/** @deprecated engine v1 only */
dependentAttempt: z.string().optional(),
/** @deprecated engine v1 only */
parentAttempt: z.string().optional(),
/** @deprecated engine v1 only */
dependentBatch: z.string().optional(),
/**
* If triggered in a batch, this is the BatchTaskRun id
*/
parentBatch: z.string().optional(),
/**
* RunEngine v2
* If triggered inside another run, the parentRunId is the friendly ID of the parent run.
*/
parentRunId: z.string().optional(),
/**
* RunEngine v2
* Should be `true` if `triggerAndWait` or `batchTriggerAndWait`
*/
resumeParentOnCompletion: z.boolean().optional(),
/**
* Locks the version to the passed value.
* Automatically set when using `triggerAndWait` or `batchTriggerAndWait`
*/
lockToVersion: z.string().optional(),
queue: z
.object({
name: z.string(),
// @deprecated, this is now specified on the queue
concurrencyLimit: z.number().int().optional(),
})
.optional(),
concurrencyKey: z.string().optional(),
delay: z.string().or(z.coerce.date()).optional(),
idempotencyKey: z.string().optional(),
idempotencyKeyTTL: z.string().optional(),
/** The original user-provided idempotency key and scope */
idempotencyKeyOptions: IdempotencyKeyOptionsSchema.optional(),
machine: MachinePresetName.optional(),
maxAttempts: z.number().int().optional(),
maxDuration: z.number().optional(),
metadata: z.any(),
metadataType: z.string().optional(),
payloadType: z.string().optional(),
tags: RunTags.optional(),
test: z.boolean().optional(),
ttl: z.string().or(z.number().nonnegative().int()).optional(),
priority: z.number().optional(),
bulkActionId: z.string().optional(),
region: z.string().optional(),
debounce: z
.object({
key: z.string().max(512),
delay: z.string(),
mode: z.enum(["leading", "trailing"]).optional(),
maxDelay: z.string().optional(),
})
.optional(),
})
.optional(),
});
export type TriggerTaskRequestBody = z.infer<typeof TriggerTaskRequestBody>;
export const TriggerTaskResponse = z.object({
id: z.string(),
isCached: z.boolean().optional(),
});
export type TriggerTaskResponse = z.infer<typeof TriggerTaskResponse>;
export const BatchTriggerTaskRequestBody = z.object({
items: TriggerTaskRequestBody.array(),
dependentAttempt: z.string().optional(),
});
export type BatchTriggerTaskRequestBody = z.infer<typeof BatchTriggerTaskRequestBody>;
export const BatchTriggerTaskItem = z.object({
task: z.string(),
payload: z.any(),
context: z.any(),
options: z
.object({
concurrencyKey: z.string().optional(),
delay: z.string().or(z.coerce.date()).optional(),
idempotencyKey: z.string().optional(),
idempotencyKeyTTL: z.string().optional(),
/** The original user-provided idempotency key and scope */
idempotencyKeyOptions: IdempotencyKeyOptionsSchema.optional(),
lockToVersion: z.string().optional(),
machine: MachinePresetName.optional(),
maxAttempts: z.number().int().optional(),
maxDuration: z.number().optional(),
metadata: z.any(),
metadataType: z.string().optional(),
parentAttempt: z.string().optional(),
payloadType: z.string().optional(),
queue: z
.object({
name: z.string(),
})
.optional(),
tags: RunTags.optional(),
test: z.boolean().optional(),
ttl: z.string().or(z.number().nonnegative().int()).optional(),
priority: z.number().optional(),
region: z.string().optional(),
debounce: z
.object({
key: z.string().max(512),
delay: z.string(),
mode: z.enum(["leading", "trailing"]).optional(),
maxDelay: z.string().optional(),
})
.optional(),
})
.optional(),
});
export type BatchTriggerTaskItem = z.infer<typeof BatchTriggerTaskItem>;
export const BatchTriggerTaskV2RequestBody = z.object({
items: BatchTriggerTaskItem.array(),
/** @deprecated engine v1 only */
dependentAttempt: z.string().optional(),
/**
* RunEngine v2
* If triggered inside another run, the parentRunId is the friendly ID of the parent run.
*/
parentRunId: z.string().optional(),
/**
* RunEngine v2
* Should be `true` if `triggerAndWait` or `batchTriggerAndWait`
*/
resumeParentOnCompletion: z.boolean().optional(),
});
export type BatchTriggerTaskV2RequestBody = z.infer<typeof BatchTriggerTaskV2RequestBody>;
export const BatchTriggerTaskV2Response = z.object({
id: z.string(),
isCached: z.boolean(),
idempotencyKey: z.string().optional(),
runs: z.array(
z.object({
id: z.string(),
taskIdentifier: z.string(),
isCached: z.boolean(),
idempotencyKey: z.string().optional(),
})
),
});
export type BatchTriggerTaskV2Response = z.infer<typeof BatchTriggerTaskV2Response>;
export const BatchTriggerTaskV3RequestBody = z.object({
items: BatchTriggerTaskItem.array(),
/**
* RunEngine v2
* If triggered inside another run, the parentRunId is the friendly ID of the parent run.
*/
parentRunId: z.string().optional(),
/**
* RunEngine v2
* Should be `true` if `triggerAndWait` or `batchTriggerAndWait`
*/
resumeParentOnCompletion: z.boolean().optional(),
});
export type BatchTriggerTaskV3RequestBody = z.infer<typeof BatchTriggerTaskV3RequestBody>;
export const BatchTriggerTaskV3Response = z.object({
id: z.string(),
runCount: z.number(),
});
export type BatchTriggerTaskV3Response = z.infer<typeof BatchTriggerTaskV3Response>;
// ============================================================================
// 2-Phase Batch API (v3) - Streaming NDJSON Support
// ============================================================================
/**
* Phase 1: Create batch request body
* Creates the batch record and optionally blocks parent run for batchTriggerAndWait
*/
export const CreateBatchRequestBody = z.object({
/** Expected number of items in the batch */
runCount: z.number().int().positive(),
/** Parent run ID for batchTriggerAndWait (friendly ID) */
parentRunId: z.string().optional(),
/** Whether to resume parent on completion (true for batchTriggerAndWait) */
resumeParentOnCompletion: z.boolean().optional(),
/** Idempotency key for the batch */
idempotencyKey: z.string().optional(),
/** The original user-provided idempotency key and scope */
idempotencyKeyOptions: IdempotencyKeyOptionsSchema.optional(),
});
export type CreateBatchRequestBody = z.infer<typeof CreateBatchRequestBody>;
/**
* Phase 1: Create batch response
*/
export const CreateBatchResponse = z.object({
/** The batch ID (friendly ID) */
id: z.string(),
/** The expected run count */
runCount: z.number(),
/** Whether this response came from a cached/idempotent batch */
isCached: z.boolean(),
/** The idempotency key if provided */
idempotencyKey: z.string().optional(),
});
export type CreateBatchResponse = z.infer<typeof CreateBatchResponse>;
/**
* Phase 2: Individual item in the NDJSON stream
* Each line in the NDJSON body should match this schema
*/
export const BatchItemNDJSON = z.object({
/** Zero-based index of this item (used for idempotency and ordering) */
index: z.number().int().nonnegative(),
/** The task identifier to trigger */
task: z.string(),
/** The payload for this task run */
payload: z.unknown().optional(),
/** Options for this specific item */
options: z.record(z.unknown()).optional(),
});
export type BatchItemNDJSON = z.infer<typeof BatchItemNDJSON>;
/**
* Phase 2: Stream items response
* Returned after the NDJSON stream completes
*/
export const StreamBatchItemsResponse = z.object({
/** The batch ID */
id: z.string(),
/** Number of items successfully accepted */
itemsAccepted: z.number(),
/** Number of items that were deduplicated (already enqueued) */
itemsDeduplicated: z.number(),
/** Whether the batch was sealed and is ready for processing.
* If false, the batch needs more items before processing can start.
* Clients should check this field and retry with missing items if needed. */
sealed: z.boolean(),
/** Total items currently enqueued (only present when sealed=false to help with retries) */
enqueuedCount: z.number().optional(),
/** Expected total item count (only present when sealed=false to help with retries) */
expectedCount: z.number().optional(),
});
export type StreamBatchItemsResponse = z.infer<typeof StreamBatchItemsResponse>;
export const BatchTriggerTaskResponse = z.object({
batchId: z.string(),
runs: z.string().array(),
});
export type BatchTriggerTaskResponse = z.infer<typeof BatchTriggerTaskResponse>;
export const GetBatchResponseBody = z.object({
id: z.string(),
items: z.array(
z.object({
id: z.string(),
taskRunId: z.string(),
status: z.enum(["PENDING", "CANCELED", "COMPLETED", "FAILED"]),
})
),
});
export type GetBatchResponseBody = z.infer<typeof GetBatchResponseBody>;
export const AddTagsRequestBody = z.object({
tags: RunTags,
});
export type AddTagsRequestBody = z.infer<typeof AddTagsRequestBody>;
export const RescheduleRunRequestBody = z.object({
delay: z.string().or(z.coerce.date()),
});
export type RescheduleRunRequestBody = z.infer<typeof RescheduleRunRequestBody>;
export const GetEnvironmentVariablesResponseBody = z.object({
variables: z.record(z.string()),
});
export type GetEnvironmentVariablesResponseBody = z.infer<
typeof GetEnvironmentVariablesResponseBody
>;
export const StartDeploymentIndexingRequestBody = z.object({
imageReference: z.string(),
selfHosted: z.boolean().optional(),
});
export type StartDeploymentIndexingRequestBody = z.infer<typeof StartDeploymentIndexingRequestBody>;
export const StartDeploymentIndexingResponseBody = z.object({
id: z.string(),
contentHash: z.string(),
});
export type StartDeploymentIndexingResponseBody = z.infer<
typeof StartDeploymentIndexingResponseBody
>;
export const FinalizeDeploymentRequestBody = z.object({
skipPromotion: z.boolean().optional(),
imageDigest: z.string().optional(),
skipPushToRegistry: z.boolean().optional(),
});
export type FinalizeDeploymentRequestBody = z.infer<typeof FinalizeDeploymentRequestBody>;
export const BuildServerMetadata = z.object({
buildId: z.string().optional(),
isNativeBuild: z.boolean().optional(),
artifactKey: z.string().optional(),
skipPromotion: z.boolean().optional(),
configFilePath: z.string().optional(),
skipEnqueue: z.boolean().optional(),
});
export type BuildServerMetadata = z.infer<typeof BuildServerMetadata>;
export const ProgressDeploymentRequestBody = z.object({
contentHash: z.string().optional(),
gitMeta: GitMeta.optional(),
runtime: z.string().optional(),
buildServerMetadata: BuildServerMetadata.optional(),
});
export type ProgressDeploymentRequestBody = z.infer<typeof ProgressDeploymentRequestBody>;
export const CancelDeploymentRequestBody = z.object({
reason: z.string().max(200, "Reason must be less than 200 characters").optional(),
});
export type CancelDeploymentRequestBody = z.infer<typeof CancelDeploymentRequestBody>;
export const ExternalBuildData = z.object({
buildId: z.string(),
buildToken: z.string(),
projectId: z.string(),
});
export type ExternalBuildData = z.infer<typeof ExternalBuildData>;
const anyString = z.custom<string & {}>((v) => typeof v === "string");
export const DeploymentTriggeredVia = z
.enum([
"cli:manual",
"cli:ci_other",
"cli:github_actions",
"cli:gitlab_ci",
"cli:circleci",
"cli:jenkins",
"cli:azure_pipelines",
"cli:bitbucket_pipelines",
"cli:travis_ci",
"cli:buildkite",
"git_integration:github",
"dashboard",
])
.or(anyString);
export type DeploymentTriggeredVia = z.infer<typeof DeploymentTriggeredVia>;
export const UpsertBranchRequestBody = z.object({
git: GitMeta.optional(),
env: z.enum(["preview"]),
branch: z.string(),
});
export type UpsertBranchRequestBody = z.infer<typeof UpsertBranchRequestBody>;
export const UpsertBranchResponseBody = z.object({
id: z.string(),
});
export type UpsertBranchResponseBody = z.infer<typeof UpsertBranchResponseBody>;
export const CreateArtifactRequestBody = z.object({
type: z.enum(["deployment_context"]).default("deployment_context"),
contentType: z.string().default("application/gzip"),
contentLength: z.number().optional(),
});
export type CreateArtifactRequestBody = z.infer<typeof CreateArtifactRequestBody>;
export const CreateArtifactResponseBody = z.object({
artifactKey: z.string(),
uploadUrl: z.string(),
uploadFields: z.record(z.string()),
expiresAt: z.string().datetime(),
});
export type CreateArtifactResponseBody = z.infer<typeof CreateArtifactResponseBody>;
export const InitializeDeploymentResponseBody = z.object({
id: z.string(),
contentHash: z.string(),
shortCode: z.string(),
version: z.string(),
imageTag: z.string(),
imagePlatform: z.string(),
externalBuildData: ExternalBuildData.optional().nullable(),
eventStream: z
.object({
s2: z.object({
basin: z.string(),
stream: z.string(),
accessToken: z.string(),
}),
})
.optional(),
});
export type InitializeDeploymentResponseBody = z.infer<typeof InitializeDeploymentResponseBody>;
const InitializeDeploymentRequestBodyBase = z.object({
contentHash: z.string(),
userId: z.string().optional(),
/** @deprecated This is now determined by the webapp. This is only used to warn users with old CLI versions. */
selfHosted: z.boolean().optional(),
gitMeta: GitMeta.optional(),
type: z.enum(["MANAGED", "UNMANAGED", "V1"]).optional(),
runtime: z.string().optional(),
initialStatus: z.enum(["PENDING", "BUILDING"]).optional(),
isLocalBuild: z.boolean().optional(),
triggeredVia: DeploymentTriggeredVia.optional(),
buildId: z.string().optional(),
});
type BaseOutput = z.output<typeof InitializeDeploymentRequestBodyBase>;
type NativeBuildOutput = BaseOutput & {
isNativeBuild: true;
skipPromotion?: boolean;
artifactKey?: string;
configFilePath?: string;
skipEnqueue?: boolean;
};
type NonNativeBuildOutput = BaseOutput & {
isNativeBuild: false;
skipPromotion?: never;
artifactKey?: never;
configFilePath?: never;
skipEnqueue?: never;
};
const InitializeDeploymentRequestBodyFull = InitializeDeploymentRequestBodyBase.extend({
isNativeBuild: z.boolean().default(false),
skipPromotion: z.boolean().optional(),
artifactKey: z.string().optional(),
configFilePath: z.string().optional(),
skipEnqueue: z.boolean().optional().default(false),
});
export const InitializeDeploymentRequestBody = InitializeDeploymentRequestBodyFull.transform(
(data): NativeBuildOutput | NonNativeBuildOutput => {
if (data.isNativeBuild) {
return { ...data, isNativeBuild: true as const };
}
const { skipPromotion, artifactKey, configFilePath, skipEnqueue, ...rest } = data;
return { ...rest, isNativeBuild: false as const };
}
);
export type InitializeDeploymentRequestBody = z.infer<typeof InitializeDeploymentRequestBody>;
export const RemoteBuildProviderStatusResponseBody = z.object({
status: z.enum(["operational", "degraded", "unknown"]),
message: z.string(),
});
export type RemoteBuildProviderStatusResponseBody = z.infer<
typeof RemoteBuildProviderStatusResponseBody
>;
export const GenerateRegistryCredentialsResponseBody = z.object({
username: z.string(),
password: z.string(),
expiresAt: z.string(),
repositoryUri: z.string(),
});
export type GenerateRegistryCredentialsResponseBody = z.infer<
typeof GenerateRegistryCredentialsResponseBody
>;
export const DeploymentErrorData = z.object({
name: z.string(),
message: z.string(),
stack: z.string().optional(),
stderr: z.string().optional(),
});
export type DeploymentErrorData = z.infer<typeof DeploymentErrorData>;
export const FailDeploymentRequestBody = z.object({
error: DeploymentErrorData,
});
export type FailDeploymentRequestBody = z.infer<typeof FailDeploymentRequestBody>;
export const FailDeploymentResponseBody = z.object({
id: z.string(),
});
export type FailDeploymentResponseBody = z.infer<typeof FailDeploymentResponseBody>;
export const PromoteDeploymentResponseBody = z.object({
id: z.string(),
version: z.string(),
shortCode: z.string(),
});
export type PromoteDeploymentResponseBody = z.infer<typeof PromoteDeploymentResponseBody>;
export const GetDeploymentResponseBody = z.object({
id: z.string(),
status: z.enum([
"PENDING",
"INSTALLING",
"BUILDING",
"DEPLOYING",
"DEPLOYED",
"FAILED",
"CANCELED",
"TIMED_OUT",
]),
contentHash: z.string(),
shortCode: z.string(),
version: z.string(),
imageReference: z.string().nullish(),
imagePlatform: z.string(),
commitSHA: z.string().nullish(),
externalBuildData: ExternalBuildData.optional().nullable(),
errorData: DeploymentErrorData.nullish(),
worker: z
.object({
id: z.string(),
version: z.string(),
tasks: z.array(
z.object({
id: z.string(),
slug: z.string(),
filePath: z.string(),
exportName: z.string().optional(),
})
),
})
.optional(),
integrationDeployments: z
.array(
z.object({
id: z.string(),
integrationName: z.string(),
integrationDeploymentId: z.string(),
commitSHA: z.string(),
createdAt: z.coerce.date(),
})
)
.nullish(),
});
export type GetDeploymentResponseBody = z.infer<typeof GetDeploymentResponseBody>;
export const GetLatestDeploymentResponseBody = GetDeploymentResponseBody.omit({
worker: true,
});
export type GetLatestDeploymentResponseBody = z.infer<typeof GetLatestDeploymentResponseBody>;
export const DeploymentLogEvent = z.object({
type: z.literal("log"),
data: z.object({
level: z.enum(["debug", "info", "warn", "error"]).optional().default("info"),
message: z.string(),
}),
});
export const DeploymentFinalizedEvent = z.object({
type: z.literal("finalized"),
data: z.object({
result: z.enum(["succeeded", "failed", "timed_out", "canceled"]).or(anyString),
message: z.string().optional(),
}),
});
export const DeploymentEvent = z.discriminatedUnion("type", [
DeploymentLogEvent,
DeploymentFinalizedEvent,
]);
export type DeploymentEvent = z.infer<typeof DeploymentEvent>;
export type DeploymentLogEvent = z.infer<typeof DeploymentLogEvent>;
export type DeploymentFinalizedEvent = z.infer<typeof DeploymentFinalizedEvent>;
export const DeploymentEventFromString = z
.string()
.transform((s, ctx) => {
try {
return JSON.parse(s);
} catch {
ctx.addIssue({ code: z.ZodIssueCode.custom, message: "Invalid JSON" });
return z.NEVER;
}
})
.pipe(DeploymentEvent);
export const CreateUploadPayloadUrlResponseBody = z.object({
presignedUrl: z.string(),
});
export const WorkersListResponseBody = z
.object({
type: z.string(),
name: z.string(),
description: z.string().nullish(),
latestVersion: z.string().nullish(),
lastHeartbeatAt: z.string().nullish(),
isDefault: z.boolean(),
updatedAt: z.coerce.date(),
})
.array();
export type WorkersListResponseBody = z.infer<typeof WorkersListResponseBody>;
export const WorkersCreateRequestBody = z.object({
name: z.string().optional(),
description: z.string().optional(),
});
export type WorkersCreateRequestBody = z.infer<typeof WorkersCreateRequestBody>;
export const WorkersCreateResponseBody = z.object({
workerGroup: z.object({
name: z.string(),
description: z.string().nullish(),
}),
token: z.object({
plaintext: z.string(),
}),
});
export type WorkersCreateResponseBody = z.infer<typeof WorkersCreateResponseBody>;
export const DevConfigResponseBody = z.object({
environmentId: z.string(),
dequeueIntervalWithRun: z.number(),
dequeueIntervalWithoutRun: z.number(),
maxConcurrentRuns: z.number(),
engineUrl: z.string(),
});
export type DevConfigResponseBody = z.infer<typeof DevConfigResponseBody>;
export const DevDequeueRequestBody = z.object({
currentWorker: z.string(),
oldWorkers: z.string().array(),
maxResources: MachineResources.optional(),
});
export type DevDequeueRequestBody = z.infer<typeof DevDequeueRequestBody>;
export const DevDequeueResponseBody = z.object({
dequeuedMessages: DequeuedMessage.array(),
});
export type DevDequeueResponseBody = z.infer<typeof DevDequeueResponseBody>;
export type CreateUploadPayloadUrlResponseBody = z.infer<typeof CreateUploadPayloadUrlResponseBody>;
export const ReplayRunResponse = z.object({
id: z.string(),
});
export type ReplayRunResponse = z.infer<typeof ReplayRunResponse>;
export const CanceledRunResponse = z.object({
id: z.string(),
});
export type CanceledRunResponse = z.infer<typeof CanceledRunResponse>;
export const ResetIdempotencyKeyResponse = z.object({
id: z.string(),
});
export type ResetIdempotencyKeyResponse = z.infer<typeof ResetIdempotencyKeyResponse>;
export const ScheduleType = z.union([z.literal("DECLARATIVE"), z.literal("IMPERATIVE")]);
export const ScheduledTaskPayload = z.object({
/** The schedule id associated with this run (you can have many schedules for the same task).
You can use this to remove the schedule, update it, etc */
scheduleId: z.string(),
/** The type of schedule – `"DECLARATIVE"` or `"IMPERATIVE"`.
*
* **DECLARATIVE** – defined inline on your `schedules.task` using the `cron` property. They can only be created, updated or deleted by modifying the `cron` property on your task.
*
* **IMPERATIVE** – created using the `schedules.create` functions or in the dashboard.
*/
type: ScheduleType,
/** When the task was scheduled to run.
* Note this will be slightly different from `new Date()` because it takes a few ms to run the task.
*
* This date is UTC. To output it as a string with a timezone you would do this:
* ```ts
* const formatted = payload.timestamp.toLocaleString("en-US", {
timeZone: payload.timezone,
});
``` */
timestamp: z.date(),
/** When the task was last run (it has been).
This can be undefined if it's never been run. This date is UTC. */
lastTimestamp: z.date().optional(),
/** You can optionally provide an external id when creating the schedule.
Usually you would use a userId or some other unique identifier.
This defaults to undefined if you didn't provide one. */
externalId: z.string().optional(),
/** The IANA timezone the schedule is set to. The default is UTC.
* You can see the full list of supported timezones here: https://cloud.trigger.dev/timezones
*/
timezone: z.string(),
/** The next 5 dates this task is scheduled to run */
upcoming: z.array(z.date()),
});
export type ScheduledTaskPayload = z.infer<typeof ScheduledTaskPayload>;
export const CreateScheduleOptions = z.object({
/** The id of the task you want to attach to. */
task: z.string(),
/** The schedule in CRON format.
*
* ```txt
* * * * * *
┬ ┬ ┬ ┬ ┬
│ │ │ │ |
│ │ │ │ └ day of week (0 - 7, 1L - 7L) (0 or 7 is Sun)
│ │ │ └───── month (1 - 12)
│ │ └────────── day of month (1 - 31, L)
│ └─────────────── hour (0 - 23)
└──────────────────── minute (0 - 59)
* ```
"L" means the last. In the "day of week" field, 1L means the last Monday of the month. In the day of month field, L means the last day of the month.
*/
cron: z.string(),
/** You can only create one schedule with this key. If you use it twice, the second call will update the schedule.
*
* This is required to prevent you from creating duplicate schedules. */
deduplicationKey: z.string(),
/** Optionally, you can specify your own IDs (like a user ID) and then use it inside the run function of your task.
*
* This allows you to have per-user CRON tasks.
*/
externalId: z.string().optional(),
/** Optionally, you can specify a timezone in the IANA format. If unset it will use UTC.
* If specified then the CRON will be evaluated in that timezone and will respect daylight savings.
*
* If you set the CRON to `0 0 * * *` and the timezone to `America/New_York` then the task will run at midnight in New York time, no matter whether it's daylight savings or not.
*
* You can see the full list of supported timezones here: https://cloud.trigger.dev/timezones
*
* @example "America/New_York", "Europe/London", "Asia/Tokyo", "Africa/Cairo"
*
*/
timezone: z.string().optional(),
});
export type CreateScheduleOptions = z.infer<typeof CreateScheduleOptions>;
export const UpdateScheduleOptions = CreateScheduleOptions.omit({ deduplicationKey: true });
export type UpdateScheduleOptions = z.infer<typeof UpdateScheduleOptions>;
export const ScheduleGenerator = z.object({
type: z.literal("CRON"),
expression: z.string(),
description: z.string(),
});
export type ScheduleGenerator = z.infer<typeof ScheduleGenerator>;
export const ScheduleObject = z.object({
id: z.string(),
type: ScheduleType,
task: z.string(),
active: z.boolean(),
deduplicationKey: z.string().nullish(),
externalId: z.string().nullish(),
generator: ScheduleGenerator,
timezone: z.string(),
nextRun: z.coerce.date().nullish(),
environments: z.array(
z.object({
id: z.string(),
type: z.string(),
userName: z.string().nullish(),
})
),
});
export type ScheduleObject = z.infer<typeof ScheduleObject>;
export const DeletedScheduleObject = z.object({
id: z.string(),
});
export type DeletedScheduleObject = z.infer<typeof DeletedScheduleObject>;
export const ListSchedulesResult = z.object({
data: z.array(ScheduleObject),
pagination: z.object({
currentPage: z.number(),
totalPages: z.number(),
count: z.number(),
}),
});
export type ListSchedulesResult = z.infer<typeof ListSchedulesResult>;
export const ListScheduleOptions = z.object({
page: z.number().optional(),
perPage: z.number().optional(),
});
export type ListScheduleOptions = z.infer<typeof ListScheduleOptions>;