@trigger.dev/platform 1.3.1 → 1.4.0

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/dist/index.js CHANGED
@@ -1,926 +1,786 @@
1
- // src/v3/schemas/planDefinitions.ts
2
1
  import { z } from "zod";
3
- var ExceedableLimit = z.object({
4
- number: z.number(),
5
- canExceed: z.boolean().optional()
6
- });
7
- var EnvironmentBasedLimit = z.object({
8
- production: z.number(),
9
- staging: z.number(),
10
- preview: z.number(),
11
- development: z.number(),
12
- canExceed: z.boolean().optional(),
13
- // Legacy, return the `production` value
14
- number: z.number()
15
- });
16
- var BatchRateLimitConfig = z.object({
17
- type: z.string(),
18
- interval: z.string(),
19
- maxTokens: z.number(),
20
- refillRate: z.number()
21
- });
22
- var BatchQueueConcurrencyConfig = z.object({
23
- processingConcurrency: z.number()
24
- });
25
- var QueueSizeLimits = z.object({
26
- development: z.number(),
27
- deployed: z.number()
28
- });
29
- var Limits = z.object({
30
- includedUsage: z.number(),
31
- concurrentRuns: EnvironmentBasedLimit,
32
- teamMembers: ExceedableLimit,
33
- schedules: ExceedableLimit,
34
- logRetentionDays: ExceedableLimit,
35
- queryPeriodDays: ExceedableLimit,
36
- alerts: ExceedableLimit,
37
- hasStagingEnvironment: z.boolean(),
38
- realtimeConcurrentConnections: ExceedableLimit,
39
- branches: ExceedableLimit,
40
- branchesDev: ExceedableLimit,
41
- support: z.enum(["community", "slack"]),
42
- batchRateLimitConfig: BatchRateLimitConfig.optional(),
43
- batchQueueConcurrencyConfig: BatchQueueConcurrencyConfig.optional(),
44
- metricDashboards: ExceedableLimit,
45
- metricWidgetsPerDashboard: ExceedableLimit,
46
- queueSizeLimits: QueueSizeLimits.optional(),
47
- hasPrivateNetworking: z.boolean().optional(),
48
- privateLinkConnectionLimit: z.number().optional(),
49
- hasSso: z.boolean().optional(),
50
- // Duration string (e.g. "30d", "1y"). When set, the org gets a
51
- // dedicated S2 stream basin with this retention; when omitted, the
52
- // org's streams flow to the shared global basin.
53
- streamBasinRetention: z.string().optional()
54
- });
55
- var commonMetadata = {
56
- title: z.string(),
57
- code: z.string()
2
+ //#region src/v3/schemas/planDefinitions.ts
3
+ const ExceedableLimit = z.object({
4
+ number: z.number(),
5
+ canExceed: z.boolean().optional()
6
+ });
7
+ const EnvironmentBasedLimit = z.object({
8
+ production: z.number(),
9
+ staging: z.number(),
10
+ preview: z.number(),
11
+ development: z.number(),
12
+ canExceed: z.boolean().optional(),
13
+ number: z.number()
14
+ });
15
+ const BatchRateLimitConfig = z.object({
16
+ type: z.string(),
17
+ interval: z.string(),
18
+ maxTokens: z.number(),
19
+ refillRate: z.number()
20
+ });
21
+ const BatchQueueConcurrencyConfig = z.object({ processingConcurrency: z.number() });
22
+ /**
23
+ * Hosted webhook limits, synced into Organization.webhookLimitsConfig on plan changes. The webapp
24
+ * falls back to its env defaults for any field that isn't set.
25
+ */
26
+ const WebhookLimitsConfig = z.object({
27
+ maxWaitersPerEnvironment: z.number(),
28
+ maxWaitersPerEndpoint: z.number(),
29
+ concurrency: z.number(),
30
+ deliveryRetentionDays: z.number(),
31
+ deliveryRetentionStrict: z.boolean().optional(),
32
+ endpointRateLimitTokens: z.number().optional(),
33
+ endpointRateLimitWindowSeconds: z.number().optional(),
34
+ environmentRateLimitTokens: z.number().optional(),
35
+ environmentRateLimitWindowSeconds: z.number().optional()
36
+ });
37
+ const QueueSizeLimits = z.object({
38
+ development: z.number(),
39
+ deployed: z.number()
40
+ });
41
+ const Limits = z.object({
42
+ includedUsage: z.number(),
43
+ concurrentRuns: EnvironmentBasedLimit,
44
+ teamMembers: ExceedableLimit,
45
+ schedules: ExceedableLimit,
46
+ logRetentionDays: ExceedableLimit,
47
+ queryPeriodDays: ExceedableLimit,
48
+ alerts: ExceedableLimit,
49
+ hasStagingEnvironment: z.boolean(),
50
+ realtimeConcurrentConnections: ExceedableLimit,
51
+ branches: ExceedableLimit,
52
+ branchesDev: ExceedableLimit,
53
+ support: z.enum(["community", "slack"]),
54
+ batchRateLimitConfig: BatchRateLimitConfig.optional(),
55
+ batchQueueConcurrencyConfig: BatchQueueConcurrencyConfig.optional(),
56
+ webhookLimitsConfig: WebhookLimitsConfig.optional(),
57
+ metricDashboards: ExceedableLimit,
58
+ metricWidgetsPerDashboard: ExceedableLimit,
59
+ agentMessages: ExceedableLimit.optional(),
60
+ agentWatchMaxHours: ExceedableLimit.optional(),
61
+ agentWatchers: ExceedableLimit.optional(),
62
+ declaredSchedulesPerDeploy: ExceedableLimit.optional(),
63
+ queueSizeLimits: QueueSizeLimits.optional(),
64
+ hasPrivateNetworking: z.boolean().optional(),
65
+ privateLinkConnectionLimit: z.number().optional(),
66
+ hasSso: z.boolean().optional(),
67
+ streamBasinRetention: z.string().optional()
68
+ });
69
+ const commonMetadata = {
70
+ title: z.string(),
71
+ code: z.string()
58
72
  };
59
- var pricingLookup = {
60
- tierPriceCode: z.string(),
61
- usagePriceCode: z.string(),
62
- usageCouponCode: z.string().optional()
73
+ const pricingLookup = {
74
+ tierPriceCode: z.string(),
75
+ usagePriceCode: z.string(),
76
+ usageCouponCode: z.string().optional()
63
77
  };
64
- var FreePlanDefinition = z.object({
65
- ...commonMetadata,
66
- type: z.literal("free"),
67
- limits: Limits
68
- });
69
- var PaidPlanDefinition = z.object({
70
- ...commonMetadata,
71
- type: z.literal("paid"),
72
- tierPrice: z.number(),
73
- stripe: z.object(pricingLookup),
74
- limits: Limits
75
- });
76
- var EnterprisePlanDefinition = z.object({
77
- ...commonMetadata,
78
- type: z.literal("enterprise"),
79
- limits: Limits
80
- });
81
- var PlanDefinitionSchema = z.discriminatedUnion("type", [
82
- FreePlanDefinition,
83
- PaidPlanDefinition,
84
- EnterprisePlanDefinition
78
+ const FreePlanDefinition = z.object({
79
+ ...commonMetadata,
80
+ type: z.literal("free"),
81
+ limits: Limits
82
+ });
83
+ const PaidPlanDefinition = z.object({
84
+ ...commonMetadata,
85
+ type: z.literal("paid"),
86
+ tierPrice: z.number(),
87
+ stripe: z.object(pricingLookup),
88
+ limits: Limits
89
+ });
90
+ const EnterprisePlanDefinition = z.object({
91
+ ...commonMetadata,
92
+ type: z.literal("enterprise"),
93
+ limits: Limits
94
+ });
95
+ const PlanDefinitionSchema = z.discriminatedUnion("type", [
96
+ FreePlanDefinition,
97
+ PaidPlanDefinition,
98
+ EnterprisePlanDefinition
85
99
  ]);
86
- var MachineDefinition = z.object({
87
- code: z.string(),
88
- title: z.string(),
89
- cpu: z.number(),
90
- memory: z.number(),
91
- centsPerMs: z.number()
92
- });
93
- var Plans = z.object({
94
- free: FreePlanDefinition,
95
- hobby: PaidPlanDefinition,
96
- pro: PaidPlanDefinition,
97
- enterprise: EnterprisePlanDefinition
98
- });
99
- var AddOnPricing = z.object({
100
- /** The step size - must purchase in multiples of this amount */
101
- stepSize: z.number(),
102
- /** Price per step in cents */
103
- centsPerStep: z.number()
104
- });
105
- var PlansResult = z.object({
106
- plans: Plans,
107
- usagePricing: z.object({
108
- centsPerRunInvocation: z.number(),
109
- machines: z.record(z.string(), MachineDefinition),
110
- defaultMachine: z.string()
111
- }),
112
- addOnPricing: z.object({
113
- concurrency: AddOnPricing,
114
- branches: AddOnPricing,
115
- seats: AddOnPricing,
116
- schedules: AddOnPricing
117
- })
118
- });
119
- var AddOnDefinition = z.object({
120
- code: z.enum(["concurrency", "branches", "seats", "schedules"]),
121
- priceCode: z.string(),
122
- pricing: AddOnPricing
123
- });
124
- var AddOn = z.object({
125
- purchased: z.number(),
126
- quota: z.number().optional()
127
- });
128
- var AddOns = z.object({
129
- concurrentRuns: AddOn.optional(),
130
- branches: AddOn.optional(),
131
- seats: AddOn.optional(),
132
- schedules: AddOn.optional()
133
- });
134
-
135
- // src/v3/schemas/subscription.ts
136
- import { z as z2 } from "zod";
137
- var FreeTierStatus = z2.enum(["requires_connect", "approved", "rejected"]);
138
- var SubscriptionResult = z2.object({
139
- freeTierStatus: FreeTierStatus,
140
- isPaying: z2.boolean(),
141
- showSelfServe: z2.boolean().default(true),
142
- canceledAt: z2.string().optional(),
143
- plan: PlanDefinitionSchema.optional(),
144
- addOns: AddOns.optional()
145
- });
146
- var CurrentPlan = z2.object({
147
- //todo remove this after the next deploy
148
- subscription: z2.any(),
149
- v3Subscription: SubscriptionResult
150
- });
151
-
152
- // src/v3/schemas/subscribe.ts
153
- import { z as z3 } from "zod";
154
- var SetPaidPlanBodySchema = z3.object({
155
- type: z3.literal("paid"),
156
- planCode: z3.string(),
157
- userId: z3.string()
158
- });
159
- var SetFreePlanBodySchema = z3.object({
160
- type: z3.literal("free"),
161
- userId: z3.string()
162
- });
163
- var SetPlanBodySchema = z3.discriminatedUnion("type", [
164
- SetPaidPlanBodySchema,
165
- SetFreePlanBodySchema
100
+ const MachineDefinition = z.object({
101
+ code: z.string(),
102
+ title: z.string(),
103
+ cpu: z.number(),
104
+ memory: z.number(),
105
+ centsPerMs: z.number()
106
+ });
107
+ const Plans = z.object({
108
+ free: FreePlanDefinition,
109
+ hobby: PaidPlanDefinition,
110
+ pro: PaidPlanDefinition,
111
+ enterprise: EnterprisePlanDefinition
112
+ });
113
+ /** The pricing per step of the add-on, e.g. $10 for 50 units */
114
+ const AddOnPricing = z.object({
115
+ /** The step size - must purchase in multiples of this amount */
116
+ stepSize: z.number(),
117
+ /** Price per step in cents */
118
+ centsPerStep: z.number()
119
+ });
120
+ const PlansResult = z.object({
121
+ plans: Plans,
122
+ usagePricing: z.object({
123
+ centsPerRunInvocation: z.number(),
124
+ machines: z.record(z.string(), MachineDefinition),
125
+ defaultMachine: z.string()
126
+ }),
127
+ addOnPricing: z.object({
128
+ concurrency: AddOnPricing,
129
+ branches: AddOnPricing,
130
+ seats: AddOnPricing,
131
+ schedules: AddOnPricing
132
+ })
133
+ });
134
+ const AddOnDefinition = z.object({
135
+ code: z.enum([
136
+ "concurrency",
137
+ "branches",
138
+ "seats",
139
+ "schedules"
140
+ ]),
141
+ priceCode: z.string(),
142
+ pricing: AddOnPricing
143
+ });
144
+ const AddOn = z.object({
145
+ purchased: z.number(),
146
+ quota: z.number().optional()
147
+ });
148
+ const AddOns = z.object({
149
+ concurrentRuns: AddOn.optional(),
150
+ branches: AddOn.optional(),
151
+ seats: AddOn.optional(),
152
+ schedules: AddOn.optional()
153
+ });
154
+ //#endregion
155
+ //#region src/v3/schemas/subscription.ts
156
+ const FreeTierStatus = z.enum([
157
+ "requires_connect",
158
+ "approved",
159
+ "rejected"
166
160
  ]);
167
- var FreeConnectRequiredSchema = z3.object({
168
- action: z3.literal("free_connect_required"),
169
- connectUrl: z3.string().url()
170
- });
171
- var FreeConnectedSchema = z3.object({
172
- action: z3.literal("free_connected"),
173
- accepted: z3.boolean()
174
- });
175
- var UpdatedSubscriptionResultSchema = z3.object({
176
- action: z3.literal("updated_subscription"),
177
- subscription: z3.object({
178
- planCode: z3.string()
179
- })
180
- });
181
- var CreateSubscriptionFlowStartSchema = z3.object({
182
- action: z3.literal("create_subscription_flow_start"),
183
- subscription: z3.object({
184
- planCode: z3.string()
185
- }),
186
- checkoutUrl: z3.string().url()
187
- });
188
- var CanceledSubscriptionResultSchema = z3.object({
189
- action: z3.literal("canceled_subscription")
190
- });
191
- var SubscribeResultSchema = z3.discriminatedUnion("action", [
192
- FreeConnectRequiredSchema,
193
- FreeConnectedSchema,
194
- CreateSubscriptionFlowStartSchema,
195
- UpdatedSubscriptionResultSchema,
196
- CanceledSubscriptionResultSchema
161
+ const SubscriptionResult = z.object({
162
+ freeTierStatus: FreeTierStatus,
163
+ isPaying: z.boolean(),
164
+ showSelfServe: z.boolean().default(true),
165
+ canceledAt: z.string().optional(),
166
+ plan: PlanDefinitionSchema.optional(),
167
+ addOns: AddOns.optional()
168
+ });
169
+ const CurrentPlan = z.object({
170
+ subscription: z.any(),
171
+ v3Subscription: SubscriptionResult
172
+ });
173
+ //#endregion
174
+ //#region src/v3/schemas/subscribe.ts
175
+ const SetPaidPlanBodySchema = z.object({
176
+ type: z.literal("paid"),
177
+ planCode: z.string(),
178
+ userId: z.string()
179
+ });
180
+ const SetFreePlanBodySchema = z.object({
181
+ type: z.literal("free"),
182
+ userId: z.string()
183
+ });
184
+ const SetPlanBodySchema = z.discriminatedUnion("type", [SetPaidPlanBodySchema, SetFreePlanBodySchema]);
185
+ const FreeConnectRequiredSchema = z.object({
186
+ action: z.literal("free_connect_required"),
187
+ connectUrl: z.string().url()
188
+ });
189
+ const FreeConnectedSchema = z.object({
190
+ action: z.literal("free_connected"),
191
+ accepted: z.boolean()
192
+ });
193
+ const UpdatedSubscriptionResultSchema = z.object({
194
+ action: z.literal("updated_subscription"),
195
+ subscription: z.object({ planCode: z.string() })
196
+ });
197
+ const CreateSubscriptionFlowStartSchema = z.object({
198
+ action: z.literal("create_subscription_flow_start"),
199
+ subscription: z.object({ planCode: z.string() }),
200
+ checkoutUrl: z.string().url()
201
+ });
202
+ const CanceledSubscriptionResultSchema = z.object({ action: z.literal("canceled_subscription") });
203
+ const SubscribeResultSchema = z.discriminatedUnion("action", [
204
+ FreeConnectRequiredSchema,
205
+ FreeConnectedSchema,
206
+ CreateSubscriptionFlowStartSchema,
207
+ UpdatedSubscriptionResultSchema,
208
+ CanceledSubscriptionResultSchema
197
209
  ]);
198
- var SetAddOnBody = z3.object({
199
- type: z3.enum(["concurrency", "branches", "seats", "schedules"]),
200
- amount: z3.number()
201
- });
202
- var SetAddOnResult = z3.discriminatedUnion("result", [
203
- z3.object({
204
- result: z3.literal("error"),
205
- error: z3.string()
206
- }),
207
- z3.object({
208
- result: z3.literal("success"),
209
- type: z3.string(),
210
- amount: z3.number(),
211
- subscription: z3.object({
212
- id: z3.string()
213
- })
214
- }),
215
- z3.object({
216
- result: z3.literal("max_quota_reached"),
217
- type: z3.string(),
218
- maxQuota: z3.number()
219
- })
210
+ const SetAddOnBody = z.object({
211
+ type: z.enum([
212
+ "concurrency",
213
+ "branches",
214
+ "seats",
215
+ "schedules"
216
+ ]),
217
+ amount: z.number()
218
+ });
219
+ const SetAddOnResult = z.discriminatedUnion("result", [
220
+ z.object({
221
+ result: z.literal("error"),
222
+ error: z.string()
223
+ }),
224
+ z.object({
225
+ result: z.literal("success"),
226
+ type: z.string(),
227
+ amount: z.number(),
228
+ subscription: z.object({ id: z.string() })
229
+ }),
230
+ z.object({
231
+ result: z.literal("max_quota_reached"),
232
+ type: z.string(),
233
+ maxQuota: z.number()
234
+ })
220
235
  ]);
221
-
222
- // src/v3/schemas/portal.ts
223
- import { z as z4 } from "zod";
224
- var CustomerPortalRequestBodySchema = z4.object({
225
- returnUrl: z4.string()
226
- });
227
- var CustomerPortalSchema = z4.object({
228
- customerPortalUrl: z4.string().optional()
229
- });
230
-
231
- // src/v3/schemas/error.ts
232
- import { z as z5 } from "zod";
233
- var ErrorSchema = z5.object({
234
- error: z5.string(),
235
- code: z5.string().optional()
236
+ const CancelSubscriptionResponse = z.object({
237
+ outcome: z.enum([
238
+ "canceled",
239
+ "already_canceled",
240
+ "no_subscription"
241
+ ]),
242
+ cancelAt: z.string().nullable()
243
+ });
244
+ //#endregion
245
+ //#region src/v3/schemas/portal.ts
246
+ const CustomerPortalRequestBodySchema = z.object({ returnUrl: z.string() });
247
+ const CustomerPortalSchema = z.object({ customerPortalUrl: z.string().optional() });
248
+ //#endregion
249
+ //#region src/v3/schemas/error.ts
250
+ const ErrorSchema = z.object({
251
+ error: z.string(),
252
+ code: z.string().optional()
236
253
  }).passthrough();
237
-
238
- // src/v3/schemas/usage.ts
239
- import { z as z6 } from "zod";
240
- var UsageParams = z6.object({
241
- from: z6.coerce.date(),
242
- to: z6.coerce.date()
243
- });
244
- var UsageResult = z6.object({
245
- cents: z6.number()
246
- });
247
- var Window = z6.enum(["MINUTE", "HOUR", "DAY"]);
248
- var UsageSeriesParams = z6.object({
249
- from: z6.coerce.date(),
250
- to: z6.coerce.date(),
251
- /** defaults to DAY */
252
- window: Window.optional(),
253
- timezone: z6.string().optional()
254
- //these don't work at the moment because you can't group by items that aren't defined in the meter group by
255
- // groupByEnvironmentType: BooleanParam.optional(),
256
- // groupByTaskIdentifier: BooleanParam.optional(),
257
- });
258
- var UsageSeriesResult = z6.object({
259
- from: z6.string(),
260
- to: z6.string(),
261
- window: Window.optional(),
262
- data: z6.object({
263
- value: z6.number(),
264
- windowStart: z6.string(),
265
- windowEnd: z6.string()
266
- //these don't work at the moment
267
- // groupBy: z
268
- // .object({
269
- // environmentType: z.string().optional(),
270
- // taskIdentifer: z.string().optional(),
271
- // })
272
- // .optional(),
273
- }).array()
274
- });
275
- var ReportComputeUsageEvent = z6.object({
276
- durationMs: z6.number()
277
- });
278
- var ReportUsagePlan = z6.object({
279
- type: z6.string(),
280
- code: z6.string(),
281
- isPaying: z6.boolean()
282
- });
283
- var ReportUsageResult = z6.object({
284
- hasAccess: z6.boolean(),
285
- balance: z6.number().optional(),
286
- usage: z6.number().optional(),
287
- overage: z6.number().optional(),
288
- plan: ReportUsagePlan.optional(),
289
- limitState: z6.literal("grace").optional(),
290
- reason: z6.enum(["free_tier_exceeded", "billing_limit"]).optional()
291
- });
292
- var MAX_INVOCATION_COST_IN_CENTS = 1e4;
293
- var ReportInvocationUsageEvent = z6.object({
294
- organizationId: z6.string().min(1).max(128),
295
- costInCents: z6.number().finite().min(0).max(MAX_INVOCATION_COST_IN_CENTS),
296
- additionalData: z6.record(z6.string(), z6.any()).optional()
297
- });
298
- var ReportInvocationUsageResult = z6.discriminatedUnion("success", [
299
- z6.object({
300
- success: z6.literal(true)
301
- }),
302
- z6.object({
303
- success: z6.literal(false),
304
- error: z6.string()
305
- })
254
+ //#endregion
255
+ //#region src/v3/schemas/usage.ts
256
+ const UsageParams = z.object({
257
+ from: z.coerce.date(),
258
+ to: z.coerce.date()
259
+ });
260
+ const UsageResult = z.object({ cents: z.number() });
261
+ const Window = z.enum([
262
+ "MINUTE",
263
+ "HOUR",
264
+ "DAY"
306
265
  ]);
307
-
308
- // src/v3/schemas/billingAlerts.ts
309
- import { z as z7 } from "zod";
310
- var BillingAlertDefinition = z7.object({
311
- amount: z7.number(),
312
- emails: z7.array(z7.string()),
313
- alertLevels: z7.array(z7.number())
314
- });
315
- var BillingAlertsResult = BillingAlertDefinition;
316
- var UpdateBillingAlertsRequest = z7.object({
317
- amount: z7.number().positive(),
318
- emails: z7.array(z7.string()),
319
- alertLevels: z7.array(z7.number())
320
- });
321
-
322
- // src/v3/schemas/billingLimit.ts
323
- import { z as z8 } from "zod";
324
- var BillingLimitState = z8.discriminatedUnion("status", [
325
- z8.object({
326
- status: z8.literal("ok")
327
- }),
328
- z8.object({
329
- status: z8.literal("grace"),
330
- hitAt: z8.string(),
331
- graceEndsAt: z8.string()
332
- }),
333
- z8.object({
334
- status: z8.literal("rejected"),
335
- hitAt: z8.string(),
336
- graceEndsAt: z8.string()
337
- })
266
+ const UsageSeriesParams = z.object({
267
+ from: z.coerce.date(),
268
+ to: z.coerce.date(),
269
+ /** defaults to DAY */
270
+ window: Window.optional(),
271
+ timezone: z.string().optional()
272
+ });
273
+ const UsageSeriesResult = z.object({
274
+ from: z.string(),
275
+ to: z.string(),
276
+ window: Window.optional(),
277
+ data: z.object({
278
+ value: z.number(),
279
+ windowStart: z.string(),
280
+ windowEnd: z.string()
281
+ }).array()
282
+ });
283
+ const ReportComputeUsageEvent = z.object({ durationMs: z.number() });
284
+ const ReportUsagePlan = z.object({
285
+ type: z.string(),
286
+ code: z.string(),
287
+ isPaying: z.boolean()
288
+ });
289
+ const ReportUsageResult = z.object({
290
+ hasAccess: z.boolean(),
291
+ balance: z.number().optional(),
292
+ usage: z.number().optional(),
293
+ overage: z.number().optional(),
294
+ plan: ReportUsagePlan.optional(),
295
+ limitState: z.literal("grace").optional(),
296
+ reason: z.enum(["free_tier_exceeded", "billing_limit"]).optional()
297
+ });
298
+ /** Upper bound for a single invocation base charge ($100). */
299
+ const MAX_INVOCATION_COST_IN_CENTS = 1e4;
300
+ const ReportInvocationUsageEvent = z.object({
301
+ organizationId: z.string().min(1).max(128),
302
+ costInCents: z.number().finite().min(0).max(MAX_INVOCATION_COST_IN_CENTS),
303
+ additionalData: z.record(z.string(), z.any()).optional()
304
+ });
305
+ const ReportInvocationUsageResult = z.discriminatedUnion("success", [z.object({ success: z.literal(true) }), z.object({
306
+ success: z.literal(false),
307
+ error: z.string()
308
+ })]);
309
+ const BillingAlertsResult = z.object({
310
+ amount: z.number(),
311
+ emails: z.array(z.string()),
312
+ alertLevels: z.array(z.number())
313
+ });
314
+ const UpdateBillingAlertsRequest = z.object({
315
+ amount: z.number().positive(),
316
+ emails: z.array(z.string()),
317
+ alertLevels: z.array(z.number())
318
+ });
319
+ //#endregion
320
+ //#region src/v3/schemas/billingLimit.ts
321
+ const BillingLimitState = z.discriminatedUnion("status", [
322
+ z.object({ status: z.literal("ok") }),
323
+ z.object({
324
+ status: z.literal("grace"),
325
+ hitAt: z.string(),
326
+ graceEndsAt: z.string()
327
+ }),
328
+ z.object({
329
+ status: z.literal("rejected"),
330
+ hitAt: z.string(),
331
+ graceEndsAt: z.string()
332
+ })
338
333
  ]);
339
- var billingLimitConfiguredFields = {
340
- isConfigured: z8.literal(true),
341
- cancelInProgressRuns: z8.boolean(),
342
- limitState: BillingLimitState,
343
- effectiveAmountCents: z8.number().int().nonnegative().nullable(),
344
- gracePeriodMs: z8.number().int().nonnegative()
334
+ const billingLimitConfiguredFields = {
335
+ isConfigured: z.literal(true),
336
+ cancelInProgressRuns: z.boolean(),
337
+ limitState: BillingLimitState,
338
+ effectiveAmountCents: z.number().int().nonnegative().nullable(),
339
+ gracePeriodMs: z.number().int().nonnegative()
345
340
  };
346
- var BillingLimitUnconfigured = z8.object({
347
- isConfigured: z8.literal(false),
348
- gracePeriodMs: z8.number().int().nonnegative()
349
- });
350
- var BillingLimitConfiguredNone = z8.object({
351
- ...billingLimitConfiguredFields,
352
- mode: z8.literal("none")
353
- });
354
- var BillingLimitConfiguredPlan = z8.object({
355
- ...billingLimitConfiguredFields,
356
- mode: z8.literal("plan")
357
- });
358
- var BillingLimitConfiguredCustom = z8.object({
359
- ...billingLimitConfiguredFields,
360
- mode: z8.literal("custom"),
361
- amountCents: z8.number().int().positive()
362
- });
363
- var BillingLimitResult = z8.union([
364
- BillingLimitUnconfigured,
365
- BillingLimitConfiguredNone,
366
- BillingLimitConfiguredPlan,
367
- BillingLimitConfiguredCustom
341
+ const BillingLimitUnconfigured = z.object({
342
+ isConfigured: z.literal(false),
343
+ gracePeriodMs: z.number().int().nonnegative()
344
+ });
345
+ const BillingLimitConfiguredNone = z.object({
346
+ ...billingLimitConfiguredFields,
347
+ mode: z.literal("none")
348
+ });
349
+ const BillingLimitConfiguredPlan = z.object({
350
+ ...billingLimitConfiguredFields,
351
+ mode: z.literal("plan")
352
+ });
353
+ const BillingLimitConfiguredCustom = z.object({
354
+ ...billingLimitConfiguredFields,
355
+ mode: z.literal("custom"),
356
+ amountCents: z.number().int().positive()
357
+ });
358
+ const BillingLimitResult = z.union([
359
+ BillingLimitUnconfigured,
360
+ BillingLimitConfiguredNone,
361
+ BillingLimitConfiguredPlan,
362
+ BillingLimitConfiguredCustom
368
363
  ]);
369
- var UpdateBillingLimitRequest = z8.discriminatedUnion("mode", [
370
- z8.object({
371
- mode: z8.literal("none"),
372
- cancelInProgressRuns: z8.boolean()
373
- }),
374
- z8.object({
375
- mode: z8.literal("plan"),
376
- cancelInProgressRuns: z8.boolean()
377
- }),
378
- z8.object({
379
- mode: z8.literal("custom"),
380
- amountCents: z8.number().int().positive(),
381
- cancelInProgressRuns: z8.boolean()
382
- })
364
+ const UpdateBillingLimitRequest = z.discriminatedUnion("mode", [
365
+ z.object({
366
+ mode: z.literal("none"),
367
+ cancelInProgressRuns: z.boolean()
368
+ }),
369
+ z.object({
370
+ mode: z.literal("plan"),
371
+ cancelInProgressRuns: z.boolean()
372
+ }),
373
+ z.object({
374
+ mode: z.literal("custom"),
375
+ amountCents: z.number().int().positive(),
376
+ cancelInProgressRuns: z.boolean()
377
+ })
383
378
  ]);
384
- var ResolveBillingLimitRequest = z8.discriminatedUnion("action", [
385
- z8.object({
386
- action: z8.literal("increase"),
387
- newAmountCents: z8.number().int().positive(),
388
- resumeMode: z8.enum(["queue", "new_only"])
389
- }),
390
- z8.object({
391
- action: z8.literal("remove"),
392
- resumeMode: z8.enum(["queue", "new_only"])
393
- })
379
+ const ResolveBillingLimitRequest = z.discriminatedUnion("action", [z.object({
380
+ action: z.literal("increase"),
381
+ newAmountCents: z.number().int().positive(),
382
+ resumeMode: z.enum(["queue", "new_only"])
383
+ }), z.object({
384
+ action: z.literal("remove"),
385
+ resumeMode: z.enum(["queue", "new_only"])
386
+ })]);
387
+ const BillingLimitActiveOrg = z.object({
388
+ orgId: z.string(),
389
+ limitState: z.enum(["grace", "rejected"])
390
+ });
391
+ const BillingLimitsActiveResult = z.object({ orgs: z.array(BillingLimitActiveOrg) });
392
+ const BillingLimitPendingResolveOrg = z.object({
393
+ organizationId: z.string(),
394
+ resumeMode: z.enum(["queue", "new_only"]),
395
+ resolvedAt: z.string()
396
+ });
397
+ const BillingLimitsPendingResolvesResult = z.object({ orgs: z.array(BillingLimitPendingResolveOrg) });
398
+ //#endregion
399
+ //#region src/v3/schemas/registryCredentials.ts
400
+ const RegistryCredentialsResponseSchema = z.object({
401
+ username: z.string(),
402
+ password: z.string(),
403
+ expiresAt: z.string().datetime(),
404
+ repositoryUri: z.string()
405
+ });
406
+ //#endregion
407
+ //#region src/v3/schemas/enqueueBuild.ts
408
+ const EnqueueBuildOptionsSchema = z.object({
409
+ skipPromotion: z.boolean().optional(),
410
+ configFilePath: z.string().optional(),
411
+ fromBundle: z.boolean().optional()
412
+ });
413
+ const EnqueueBuildRequestSchema = z.union([z.object({
414
+ deploymentId: z.string(),
415
+ artifactKey: z.string(),
416
+ options: EnqueueBuildOptionsSchema
417
+ }), z.object({
418
+ deploymentId: z.string(),
419
+ github: z.object({
420
+ commitSha: z.string().regex(/^[0-9a-f]{40}$/, "commitSha must be a full lowercase git SHA"),
421
+ ref: z.string().min(1).max(255)
422
+ }),
423
+ options: EnqueueBuildOptionsSchema
424
+ })]);
425
+ const EnqueueBuildResponseSchema = z.object({ buildId: z.string() });
426
+ const EnqueueBuildErrorCodeSchema = z.enum([
427
+ "DEPLOYMENT_NOT_PENDING",
428
+ "NO_CONNECTED_REPOSITORY",
429
+ "ATOMIC_PRODUCTION_REQUIRES_VERCEL",
430
+ "COMMIT_NOT_FOUND",
431
+ "GITHUB_UNAVAILABLE"
394
432
  ]);
395
- var BillingLimitActiveOrg = z8.object({
396
- orgId: z8.string(),
397
- limitState: z8.enum(["grace", "rejected"])
398
- });
399
- var BillingLimitsActiveResult = z8.object({
400
- orgs: z8.array(BillingLimitActiveOrg)
401
- });
402
- var BillingLimitPendingResolveOrg = z8.object({
403
- organizationId: z8.string(),
404
- resumeMode: z8.enum(["queue", "new_only"]),
405
- resolvedAt: z8.string()
406
- });
407
- var BillingLimitsPendingResolvesResult = z8.object({
408
- orgs: z8.array(BillingLimitPendingResolveOrg)
409
- });
410
-
411
- // src/v3/schemas/registryCredentials.ts
412
- import { z as z9 } from "zod";
413
- var RegistryCredentialsResponseSchema = z9.object({
414
- username: z9.string(),
415
- password: z9.string(),
416
- expiresAt: z9.string().datetime(),
417
- repositoryUri: z9.string()
418
- });
419
-
420
- // src/v3/schemas/enqueueBuild.ts
421
- import { z as z10 } from "zod";
422
- var EnqueueBuildRequestSchema = z10.object({
423
- deploymentId: z10.string(),
424
- artifactKey: z10.string(),
425
- options: z10.object({
426
- skipPromotion: z10.boolean().optional(),
427
- configFilePath: z10.string().optional()
428
- })
429
- });
430
- var EnqueueBuildResponseSchema = z10.object({
431
- buildId: z10.string()
432
- });
433
-
434
- // src/v3/schemas/initialDeployment.ts
435
- import { z as z11 } from "zod";
436
- var TriggerInitialDeploymentRequestSchema = z11.object({
437
- environment: z11.enum(["prod", "staging", "preview"])
438
- });
439
- var TriggerInitialDeploymentResponseSchema = z11.object({
440
- ok: z11.boolean()
441
- });
442
-
443
- // src/v3/schemas/privateLink.ts
444
- import { z as z12 } from "zod";
445
- var PrivateLinkConnectionStatus = z12.enum([
446
- "PENDING",
447
- "PROVISIONING",
448
- "ACTIVE",
449
- "ERROR",
450
- "DELETING"
433
+ //#endregion
434
+ //#region src/v3/schemas/initialDeployment.ts
435
+ const TriggerInitialDeploymentRequestSchema = z.object({
436
+ environment: z.enum([
437
+ "prod",
438
+ "staging",
439
+ "preview"
440
+ ]),
441
+ branch: z.string().min(1).max(255).optional()
442
+ });
443
+ const TriggerInitialDeploymentResponseSchema = z.object({ ok: z.boolean() });
444
+ //#endregion
445
+ //#region src/v3/schemas/privateLink.ts
446
+ const PrivateLinkConnectionStatus = z.enum([
447
+ "PENDING",
448
+ "PROVISIONING",
449
+ "ACTIVE",
450
+ "ERROR",
451
+ "DELETING"
451
452
  ]);
452
- var PrivateLinkConnection = z12.object({
453
- id: z12.string(),
454
- friendlyId: z12.string(),
455
- name: z12.string(),
456
- organizationId: z12.string(),
457
- endpointServiceName: z12.string(),
458
- targetRegion: z12.string(),
459
- status: PrivateLinkConnectionStatus,
460
- statusMessage: z12.string().nullable(),
461
- endpointDnsName: z12.string().nullable(),
462
- endpointIps: z12.array(z12.string()).nullable(),
463
- provisionedAt: z12.string().nullable(),
464
- createdAt: z12.string(),
465
- updatedAt: z12.string()
466
- });
467
- var PrivateLinkConnectionList = z12.object({
468
- connections: z12.array(PrivateLinkConnection)
469
- });
470
- var CreatePrivateLinkConnectionBody = z12.object({
471
- name: z12.string().min(1).max(100).regex(
472
- /^[a-zA-Z][a-zA-Z0-9 _-]*$/,
473
- "Must start with a letter and contain only letters, numbers, spaces, hyphens, or underscores"
474
- ),
475
- endpointServiceName: z12.string().regex(
476
- /^com\.amazonaws\.vpce\..+\.vpce-svc-.+$/,
477
- "Must be a valid VPC Endpoint Service name (com.amazonaws.vpce.<region>.vpce-svc-*)"
478
- ),
479
- // Region support is dynamic (driven by the billing service's env vars), so
480
- // this validates the AWS region *format* only; the authoritative check that
481
- // the region is actually configured happens server-side against the set of
482
- // regions discovered from env vars.
483
- targetRegion: z12.string().regex(/^[a-z]{2}-[a-z]+-\d+$/, "Must be a valid AWS region")
484
- });
485
- var DeletePrivateLinkResult = z12.object({
486
- success: z12.boolean()
487
- });
488
- var PrivateLinkRegionsResult = z12.object({
489
- availableRegions: z12.array(z12.string()),
490
- activeRegions: z12.array(z12.string())
491
- });
492
-
493
- // src/v3/schemas/promoCodes.ts
494
- import { z as z13 } from "zod";
495
- var ValidatePromoCodeBodySchema = z13.object({
496
- code: z13.string()
497
- });
498
- var ValidatePromoCodeResult = z13.object({
499
- valid: z13.boolean(),
500
- amountInCents: z13.number().optional(),
501
- expiresAt: z13.string().datetime().nullable().optional()
502
- });
503
- var ApplyPromoCodeBodySchema = z13.object({
504
- code: z13.string(),
505
- userId: z13.string()
506
- });
507
- var ApplyPromoCodeResult = z13.object({
508
- applied: z13.boolean(),
509
- amountInCents: z13.number().optional(),
510
- expiresAt: z13.string().datetime().nullable().optional(),
511
- // Present when applied is false, e.g. "already_redeemed" or "invalid".
512
- reason: z13.string().optional()
513
- });
514
- var PromoCreditsResult = z13.object({
515
- promoCredits: z13.object({
516
- grantedCents: z13.number(),
517
- remainingCents: z13.number(),
518
- expiresAt: z13.string().datetime().nullable()
519
- }).nullable()
520
- });
521
-
522
- // src/v3/client/index.ts
453
+ const PrivateLinkConnection = z.object({
454
+ id: z.string(),
455
+ friendlyId: z.string(),
456
+ name: z.string(),
457
+ organizationId: z.string(),
458
+ endpointServiceName: z.string(),
459
+ targetRegion: z.string(),
460
+ status: PrivateLinkConnectionStatus,
461
+ statusMessage: z.string().nullable(),
462
+ endpointDnsName: z.string().nullable(),
463
+ endpointIps: z.array(z.string()).nullable(),
464
+ provisionedAt: z.string().nullable(),
465
+ createdAt: z.string(),
466
+ updatedAt: z.string()
467
+ });
468
+ const PrivateLinkConnectionList = z.object({ connections: z.array(PrivateLinkConnection) });
469
+ const CreatePrivateLinkConnectionBody = z.object({
470
+ name: z.string().min(1).max(100).regex(/^[a-zA-Z][a-zA-Z0-9 _-]*$/, "Must start with a letter and contain only letters, numbers, spaces, hyphens, or underscores"),
471
+ endpointServiceName: z.string().regex(/^com\.amazonaws\.vpce\..+\.vpce-svc-.+$/, "Must be a valid VPC Endpoint Service name (com.amazonaws.vpce.<region>.vpce-svc-*)"),
472
+ targetRegion: z.string().regex(/^[a-z]{2}-[a-z]+-\d+$/, "Must be a valid AWS region")
473
+ });
474
+ const DeletePrivateLinkResult = z.object({ success: z.boolean() });
475
+ const PrivateLinkRegionsResult = z.object({
476
+ availableRegions: z.array(z.string()),
477
+ activeRegions: z.array(z.string())
478
+ });
479
+ //#endregion
480
+ //#region src/v3/schemas/promoCodes.ts
481
+ const ValidatePromoCodeBodySchema = z.object({ code: z.string() });
482
+ const ValidatePromoCodeResult = z.object({
483
+ valid: z.boolean(),
484
+ amountInCents: z.number().optional(),
485
+ expiresAt: z.string().datetime().nullable().optional()
486
+ });
487
+ const ApplyPromoCodeBodySchema = z.object({
488
+ code: z.string(),
489
+ userId: z.string()
490
+ });
491
+ const ApplyPromoCodeResult = z.object({
492
+ applied: z.boolean(),
493
+ amountInCents: z.number().optional(),
494
+ expiresAt: z.string().datetime().nullable().optional(),
495
+ reason: z.string().optional()
496
+ });
497
+ const PromoCreditsResult = z.object({ promoCredits: z.object({
498
+ grantedCents: z.number(),
499
+ remainingCents: z.number(),
500
+ expiresAt: z.string().datetime().nullable()
501
+ }).nullable() });
502
+ //#endregion
503
+ //#region src/v3/client/index.ts
523
504
  var BillingClient = class {
524
- constructor(config) {
525
- this.config = config;
526
- }
527
- async plans() {
528
- return await this.fetch(`/api/v1/plans/v3`, PlansResult);
529
- }
530
- async currentPlan(orgId) {
531
- return await this.fetch(`/api/v1/orgs/${orgId}`, CurrentPlan);
532
- }
533
- async usage(orgId, params) {
534
- const search = objectToSearchParams(params);
535
- return await this.fetch(`/api/v1/orgs/${orgId}/usage?${search == null ? void 0 : search.toString()}`, UsageResult);
536
- }
537
- async usageSeries(orgId, params) {
538
- const search = objectToSearchParams(params);
539
- return await this.fetch(
540
- `/api/v1/orgs/${orgId}/usage/series?${search == null ? void 0 : search.toString()}`,
541
- UsageSeriesResult
542
- );
543
- }
544
- async setPlan(orgId, body) {
545
- return await this.fetch(`/api/v1/orgs/${orgId}/v3/subscription`, SubscribeResultSchema, {
546
- method: "POST",
547
- headers: {
548
- "Content-Type": "application/json"
549
- },
550
- body: JSON.stringify(body)
551
- });
552
- }
553
- async setAddOn(orgId, body) {
554
- return await this.fetch(`/api/v1/orgs/${orgId}/v3/subscription/addon`, SetAddOnResult, {
555
- method: "POST",
556
- headers: {
557
- "Content-Type": "application/json"
558
- },
559
- body: JSON.stringify(body)
560
- });
561
- }
562
- async validatePromoCode(code) {
563
- return await this.fetch(`/api/v1/promo-codes/validate`, ValidatePromoCodeResult, {
564
- method: "POST",
565
- headers: {
566
- "Content-Type": "application/json"
567
- },
568
- body: JSON.stringify({ code })
569
- });
570
- }
571
- async applyPromoCode(orgId, body) {
572
- return await this.fetch(`/api/v1/orgs/${orgId}/promo/apply`, ApplyPromoCodeResult, {
573
- method: "POST",
574
- headers: {
575
- "Content-Type": "application/json"
576
- },
577
- body: JSON.stringify(body)
578
- });
579
- }
580
- async promoCredits(orgId) {
581
- return await this.fetch(`/api/v1/orgs/${orgId}/promo/credits`, PromoCreditsResult);
582
- }
583
- async createPortalSession(orgId, body) {
584
- return await this.fetch(`/api/v1/orgs/${orgId}/v3/subscription/portal`, CustomerPortalSchema, {
585
- method: "POST",
586
- headers: {
587
- "Content-Type": "application/json"
588
- },
589
- body: JSON.stringify(body)
590
- });
591
- }
592
- /**
593
- *
594
- * @param event The data is in the body, not using a JWT
595
- * @returns details about usage
596
- */
597
- async reportInvocationUsage(event) {
598
- return await this.fetch(`/api/v1/usage/ingest/invocation`, ReportInvocationUsageResult, {
599
- method: "POST",
600
- headers: {
601
- "Content-Type": "application/json"
602
- },
603
- body: JSON.stringify(event)
604
- });
605
- }
606
- /**
607
- * Generates registry credentials for a project. This is used to push images to a project's container repository.
608
- *
609
- * @param projectId The ID of the project
610
- * @param region The region to generate credentials for
611
- * @returns The registry credentials
612
- */
613
- async generateRegistryCredentials(projectId, region) {
614
- return await this.fetch(
615
- `/api/v1/projects/${projectId}/generate-registry-credentials`,
616
- RegistryCredentialsResponseSchema,
617
- {
618
- method: "POST",
619
- headers: {
620
- "Content-Type": "application/json"
621
- },
622
- body: JSON.stringify({ region })
623
- }
624
- );
625
- }
626
- /**
627
- * Enqueues a build for a project deployment.
628
- *
629
- * @param projectId The ID of the project
630
- * @param body The enqueue build request containing the deployment ID
631
- * @returns The build ID
632
- */
633
- async enqueueBuild(projectId, body) {
634
- return await this.fetch(
635
- `/api/v1/projects/${projectId}/enqueue-build`,
636
- EnqueueBuildResponseSchema,
637
- {
638
- method: "POST",
639
- headers: {
640
- "Content-Type": "application/json"
641
- },
642
- body: JSON.stringify(body)
643
- }
644
- );
645
- }
646
- /**
647
- *
648
- * @param event The data is in the body, not using a JWT
649
- * @returns details about usage
650
- */
651
- async getEntitlement(orgId) {
652
- return await this.fetch(`/api/v1/orgs/${orgId}/usage/entitlement`, ReportUsageResult);
653
- }
654
- async getBillingAlerts(orgId) {
655
- return await this.fetch(`/api/v1/orgs/${orgId}/billing-alerts`, BillingAlertsResult);
656
- }
657
- async updateBillingAlerts(orgId, body) {
658
- return await this.fetch(`/api/v1/orgs/${orgId}/billing-alerts`, BillingAlertsResult, {
659
- method: "POST",
660
- headers: {
661
- "Content-Type": "application/json"
662
- },
663
- body: JSON.stringify(body)
664
- });
665
- }
666
- async getBillingLimit(orgId) {
667
- return await this.fetch(`/api/v1/orgs/${orgId}/billing-limit`, BillingLimitResult);
668
- }
669
- async updateBillingLimit(orgId, body) {
670
- return await this.fetch(`/api/v1/orgs/${orgId}/billing-limit`, BillingLimitResult, {
671
- method: "PUT",
672
- headers: {
673
- "Content-Type": "application/json"
674
- },
675
- body: JSON.stringify(body)
676
- });
677
- }
678
- async resolveBillingLimit(orgId, body) {
679
- return await this.fetch(`/api/v1/orgs/${orgId}/billing-limit/resolve`, BillingLimitResult, {
680
- method: "POST",
681
- headers: {
682
- "Content-Type": "application/json"
683
- },
684
- body: JSON.stringify(body)
685
- });
686
- }
687
- async getActiveBillingLimits() {
688
- return await this.fetch(`/api/v1/billing-limits/active`, BillingLimitsActiveResult);
689
- }
690
- async getPrivateLinks(orgId) {
691
- return await this.fetch(`/api/v1/orgs/${orgId}/private-connections`, PrivateLinkConnectionList);
692
- }
693
- async createPrivateLink(orgId, body) {
694
- return await this.fetch(`/api/v1/orgs/${orgId}/private-connections`, PrivateLinkConnection, {
695
- method: "POST",
696
- headers: {
697
- "Content-Type": "application/json"
698
- },
699
- body: JSON.stringify(body)
700
- });
701
- }
702
- async deletePrivateLink(orgId, connectionId) {
703
- return await this.fetch(
704
- `/api/v1/orgs/${orgId}/private-connections/${connectionId}`,
705
- DeletePrivateLinkResult,
706
- {
707
- method: "DELETE"
708
- }
709
- );
710
- }
711
- async getPrivateLinkRegions(orgId) {
712
- return await this.fetch(
713
- `/api/v1/orgs/${orgId}/private-connections/regions`,
714
- PrivateLinkRegionsResult
715
- );
716
- }
717
- async triggerInitialDeployment(projectId, body) {
718
- return await this.fetch(
719
- `/api/v1/projects/${projectId}/initial-deployment`,
720
- TriggerInitialDeploymentResponseSchema,
721
- {
722
- method: "POST",
723
- headers: {
724
- "Content-Type": "application/json"
725
- },
726
- body: JSON.stringify(body)
727
- }
728
- );
729
- }
730
- async fetch(path, schema, requestInit) {
731
- const response = await fetch(`${this.config.url}${path}`, {
732
- ...requestInit,
733
- headers: {
734
- ...requestInit == null ? void 0 : requestInit.headers,
735
- Authorization: `Bearer ${this.config.apiKey}`
736
- }
737
- });
738
- if (!response.ok) {
739
- let parsedError;
740
- try {
741
- parsedError = ErrorSchema.parse(await response.json());
742
- } catch {
743
- parsedError = { error: `http_${response.status}` };
744
- }
745
- return {
746
- success: false,
747
- ...parsedError
748
- };
749
- }
750
- const json = await response.json();
751
- const parsed = schema.parse(json);
752
- return {
753
- success: true,
754
- ...parsed
755
- };
756
- }
505
+ constructor(config) {
506
+ this.config = config;
507
+ }
508
+ async plans() {
509
+ return await this.fetch(`/api/v1/plans/v3`, PlansResult);
510
+ }
511
+ async currentPlan(orgId) {
512
+ return await this.fetch(`/api/v1/orgs/${orgId}`, CurrentPlan);
513
+ }
514
+ async usage(orgId, params) {
515
+ const search = objectToSearchParams(params);
516
+ return await this.fetch(`/api/v1/orgs/${orgId}/usage?${search?.toString()}`, UsageResult);
517
+ }
518
+ async usageSeries(orgId, params) {
519
+ const search = objectToSearchParams(params);
520
+ return await this.fetch(`/api/v1/orgs/${orgId}/usage/series?${search?.toString()}`, UsageSeriesResult);
521
+ }
522
+ async setPlan(orgId, body) {
523
+ return await this.fetch(`/api/v1/orgs/${orgId}/v3/subscription`, SubscribeResultSchema, {
524
+ method: "POST",
525
+ headers: { "Content-Type": "application/json" },
526
+ body: JSON.stringify(body)
527
+ });
528
+ }
529
+ async cancelSubscription(orgId) {
530
+ return await this.fetch(`/api/v1/orgs/${orgId}/v3/subscription/cancel`, CancelSubscriptionResponse, { method: "POST" });
531
+ }
532
+ async setAddOn(orgId, body) {
533
+ return await this.fetch(`/api/v1/orgs/${orgId}/v3/subscription/addon`, SetAddOnResult, {
534
+ method: "POST",
535
+ headers: { "Content-Type": "application/json" },
536
+ body: JSON.stringify(body)
537
+ });
538
+ }
539
+ async validatePromoCode(code) {
540
+ return await this.fetch(`/api/v1/promo-codes/validate`, ValidatePromoCodeResult, {
541
+ method: "POST",
542
+ headers: { "Content-Type": "application/json" },
543
+ body: JSON.stringify({ code })
544
+ });
545
+ }
546
+ async applyPromoCode(orgId, body) {
547
+ return await this.fetch(`/api/v1/orgs/${orgId}/promo/apply`, ApplyPromoCodeResult, {
548
+ method: "POST",
549
+ headers: { "Content-Type": "application/json" },
550
+ body: JSON.stringify(body)
551
+ });
552
+ }
553
+ async promoCredits(orgId) {
554
+ return await this.fetch(`/api/v1/orgs/${orgId}/promo/credits`, PromoCreditsResult);
555
+ }
556
+ async createPortalSession(orgId, body) {
557
+ return await this.fetch(`/api/v1/orgs/${orgId}/v3/subscription/portal`, CustomerPortalSchema, {
558
+ method: "POST",
559
+ headers: { "Content-Type": "application/json" },
560
+ body: JSON.stringify(body)
561
+ });
562
+ }
563
+ /**
564
+ *
565
+ * @param event The data is in the body, not using a JWT
566
+ * @returns details about usage
567
+ */
568
+ async reportInvocationUsage(event) {
569
+ return await this.fetch(`/api/v1/usage/ingest/invocation`, ReportInvocationUsageResult, {
570
+ method: "POST",
571
+ headers: { "Content-Type": "application/json" },
572
+ body: JSON.stringify(event)
573
+ });
574
+ }
575
+ /**
576
+ * Generates registry credentials for a project. This is used to push images to a project's container repository.
577
+ *
578
+ * @param projectId The ID of the project
579
+ * @param region The region to generate credentials for
580
+ * @returns The registry credentials
581
+ */
582
+ async generateRegistryCredentials(projectId, region) {
583
+ return await this.fetch(`/api/v1/projects/${projectId}/generate-registry-credentials`, RegistryCredentialsResponseSchema, {
584
+ method: "POST",
585
+ headers: { "Content-Type": "application/json" },
586
+ body: JSON.stringify({ region })
587
+ });
588
+ }
589
+ /**
590
+ * Enqueues a build for a project deployment.
591
+ *
592
+ * @param projectId The ID of the project
593
+ * @param body The enqueue build request containing the deployment ID
594
+ * @returns The build ID
595
+ */
596
+ async enqueueBuild(projectId, body) {
597
+ return await this.fetch(`/api/v1/projects/${projectId}/enqueue-build`, EnqueueBuildResponseSchema, {
598
+ method: "POST",
599
+ headers: { "Content-Type": "application/json" },
600
+ body: JSON.stringify(body)
601
+ });
602
+ }
603
+ /**
604
+ *
605
+ * @param event The data is in the body, not using a JWT
606
+ * @returns details about usage
607
+ */
608
+ async getEntitlement(orgId) {
609
+ return await this.fetch(`/api/v1/orgs/${orgId}/usage/entitlement`, ReportUsageResult);
610
+ }
611
+ async getBillingAlerts(orgId) {
612
+ return await this.fetch(`/api/v1/orgs/${orgId}/billing-alerts`, BillingAlertsResult);
613
+ }
614
+ async updateBillingAlerts(orgId, body) {
615
+ return await this.fetch(`/api/v1/orgs/${orgId}/billing-alerts`, BillingAlertsResult, {
616
+ method: "POST",
617
+ headers: { "Content-Type": "application/json" },
618
+ body: JSON.stringify(body)
619
+ });
620
+ }
621
+ async getBillingLimit(orgId) {
622
+ return await this.fetch(`/api/v1/orgs/${orgId}/billing-limit`, BillingLimitResult);
623
+ }
624
+ async updateBillingLimit(orgId, body) {
625
+ return await this.fetch(`/api/v1/orgs/${orgId}/billing-limit`, BillingLimitResult, {
626
+ method: "PUT",
627
+ headers: { "Content-Type": "application/json" },
628
+ body: JSON.stringify(body)
629
+ });
630
+ }
631
+ async resolveBillingLimit(orgId, body) {
632
+ return await this.fetch(`/api/v1/orgs/${orgId}/billing-limit/resolve`, BillingLimitResult, {
633
+ method: "POST",
634
+ headers: { "Content-Type": "application/json" },
635
+ body: JSON.stringify(body)
636
+ });
637
+ }
638
+ async getActiveBillingLimits() {
639
+ return await this.fetch(`/api/v1/billing-limits/active`, BillingLimitsActiveResult);
640
+ }
641
+ async getPrivateLinks(orgId) {
642
+ return await this.fetch(`/api/v1/orgs/${orgId}/private-connections`, PrivateLinkConnectionList);
643
+ }
644
+ async createPrivateLink(orgId, body) {
645
+ return await this.fetch(`/api/v1/orgs/${orgId}/private-connections`, PrivateLinkConnection, {
646
+ method: "POST",
647
+ headers: { "Content-Type": "application/json" },
648
+ body: JSON.stringify(body)
649
+ });
650
+ }
651
+ async deletePrivateLink(orgId, connectionId) {
652
+ return await this.fetch(`/api/v1/orgs/${orgId}/private-connections/${connectionId}`, DeletePrivateLinkResult, { method: "DELETE" });
653
+ }
654
+ async getPrivateLinkRegions(orgId) {
655
+ return await this.fetch(`/api/v1/orgs/${orgId}/private-connections/regions`, PrivateLinkRegionsResult);
656
+ }
657
+ async triggerInitialDeployment(projectId, body) {
658
+ return await this.fetch(`/api/v1/projects/${projectId}/initial-deployment`, TriggerInitialDeploymentResponseSchema, {
659
+ method: "POST",
660
+ headers: { "Content-Type": "application/json" },
661
+ body: JSON.stringify(body)
662
+ });
663
+ }
664
+ async fetch(path, schema, requestInit) {
665
+ const response = await fetch(`${this.config.url}${path}`, {
666
+ ...requestInit,
667
+ headers: {
668
+ ...requestInit?.headers,
669
+ Authorization: `Bearer ${this.config.apiKey}`
670
+ }
671
+ });
672
+ if (!response.ok) {
673
+ let parsedError;
674
+ try {
675
+ parsedError = ErrorSchema.parse(await response.json());
676
+ } catch {
677
+ parsedError = { error: `http_${response.status}` };
678
+ }
679
+ return {
680
+ success: false,
681
+ ...parsedError
682
+ };
683
+ }
684
+ const json = await response.json();
685
+ return {
686
+ success: true,
687
+ ...schema.parse(json)
688
+ };
689
+ }
757
690
  };
758
691
  function objectToSearchParams(obj) {
759
- if (!obj)
760
- return void 0;
761
- const searchParams = new URLSearchParams();
762
- Object.entries(obj).forEach(([key, value]) => {
763
- if (value === void 0)
764
- return;
765
- if (Array.isArray(value)) {
766
- const values = value.map((d) => {
767
- if (d instanceof Date)
768
- return d.toISOString();
769
- return d;
770
- });
771
- searchParams.append(key, values.join(","));
772
- } else {
773
- const v = value instanceof Date ? value.toISOString() : value;
774
- searchParams.append(key, v.toString());
775
- }
776
- });
777
- return searchParams;
692
+ if (!obj) return void 0;
693
+ const searchParams = new URLSearchParams();
694
+ Object.entries(obj).forEach(([key, value]) => {
695
+ if (value === void 0) return;
696
+ if (Array.isArray(value)) {
697
+ const values = value.map((d) => {
698
+ if (d instanceof Date) return d.toISOString();
699
+ return d;
700
+ });
701
+ searchParams.append(key, values.join(","));
702
+ } else {
703
+ const v = value instanceof Date ? value.toISOString() : value;
704
+ searchParams.append(key, v.toString());
705
+ }
706
+ });
707
+ return searchParams;
778
708
  }
779
-
780
- // src/v3/machineDefinition.ts
781
- function machineDefinition({
782
- code,
783
- title,
784
- cpu,
785
- memory,
786
- centsPerVCpuSecond: centsPerVCpuSecond2,
787
- centsPerGbRamSecond: centsPerGbRamSecond2
788
- }) {
789
- const centsPerSecond = cpu * centsPerVCpuSecond2 + memory * centsPerGbRamSecond2;
790
- const centsPerMs = centsPerSecond / 1e3;
791
- return {
792
- code,
793
- title,
794
- cpu,
795
- memory,
796
- centsPerMs
797
- };
709
+ //#endregion
710
+ //#region src/v3/machineDefinition.ts
711
+ function machineDefinition({ code, title, cpu, memory, centsPerVCpuSecond, centsPerGbRamSecond }) {
712
+ return {
713
+ code,
714
+ title,
715
+ cpu,
716
+ memory,
717
+ centsPerMs: (cpu * centsPerVCpuSecond + memory * centsPerGbRamSecond) / 1e3
718
+ };
798
719
  }
799
-
800
- // src/v3/machinePresets.ts
801
- var centsPerVCpuSecond = Number(process.env.CENTS_PER_VCPU_SECOND ?? 0);
802
- var centsPerGbRamSecond = Number(process.env.CENTS_PER_GB_RAM_SECOND ?? 0);
803
- var machines = {
804
- micro: machineDefinition({
805
- code: "micro",
806
- title: "Micro",
807
- cpu: 0.25,
808
- memory: 0.25,
809
- centsPerVCpuSecond,
810
- centsPerGbRamSecond
811
- }),
812
- "small-1x": machineDefinition({
813
- code: "small-1x",
814
- title: "Small 1x",
815
- cpu: 0.5,
816
- memory: 0.5,
817
- centsPerVCpuSecond,
818
- centsPerGbRamSecond
819
- }),
820
- "small-2x": machineDefinition({
821
- code: "small-2x",
822
- title: "Small 2x",
823
- cpu: 1,
824
- memory: 1,
825
- centsPerVCpuSecond,
826
- centsPerGbRamSecond
827
- }),
828
- "medium-1x": machineDefinition({
829
- code: "medium-1x",
830
- title: "Medium 1x",
831
- cpu: 1,
832
- memory: 2,
833
- centsPerVCpuSecond,
834
- centsPerGbRamSecond
835
- }),
836
- "medium-2x": machineDefinition({
837
- code: "medium-2x",
838
- title: "Medium 2x",
839
- cpu: 2,
840
- memory: 4,
841
- centsPerVCpuSecond,
842
- centsPerGbRamSecond
843
- }),
844
- "large-1x": machineDefinition({
845
- code: "large-1x",
846
- title: "Large 1x",
847
- cpu: 4,
848
- memory: 8,
849
- centsPerVCpuSecond,
850
- centsPerGbRamSecond
851
- }),
852
- "large-2x": machineDefinition({
853
- code: "large-2x",
854
- title: "Large 2x",
855
- cpu: 8,
856
- memory: 16,
857
- centsPerVCpuSecond,
858
- centsPerGbRamSecond
859
- })
860
- };
861
- var defaultMachine = "small-1x";
862
- export {
863
- AddOn,
864
- AddOnDefinition,
865
- AddOns,
866
- ApplyPromoCodeBodySchema,
867
- ApplyPromoCodeResult,
868
- BillingAlertsResult,
869
- BillingClient,
870
- BillingLimitActiveOrg,
871
- BillingLimitConfiguredCustom,
872
- BillingLimitConfiguredNone,
873
- BillingLimitConfiguredPlan,
874
- BillingLimitPendingResolveOrg,
875
- BillingLimitResult,
876
- BillingLimitState,
877
- BillingLimitUnconfigured,
878
- BillingLimitsActiveResult,
879
- BillingLimitsPendingResolvesResult,
880
- CreatePrivateLinkConnectionBody,
881
- CurrentPlan,
882
- CustomerPortalRequestBodySchema,
883
- CustomerPortalSchema,
884
- DeletePrivateLinkResult,
885
- EnqueueBuildRequestSchema,
886
- EnqueueBuildResponseSchema,
887
- ErrorSchema,
888
- FreeConnectRequiredSchema,
889
- FreeConnectedSchema,
890
- MAX_INVOCATION_COST_IN_CENTS,
891
- PlanDefinitionSchema,
892
- Plans,
893
- PlansResult,
894
- PrivateLinkConnection,
895
- PrivateLinkConnectionList,
896
- PrivateLinkConnectionStatus,
897
- PrivateLinkRegionsResult,
898
- PromoCreditsResult,
899
- RegistryCredentialsResponseSchema,
900
- ReportComputeUsageEvent,
901
- ReportInvocationUsageEvent,
902
- ReportInvocationUsageResult,
903
- ReportUsagePlan,
904
- ReportUsageResult,
905
- ResolveBillingLimitRequest,
906
- SetAddOnBody,
907
- SetAddOnResult,
908
- SetPlanBodySchema,
909
- SubscribeResultSchema,
910
- SubscriptionResult,
911
- TriggerInitialDeploymentRequestSchema,
912
- TriggerInitialDeploymentResponseSchema,
913
- UpdateBillingAlertsRequest,
914
- UpdateBillingLimitRequest,
915
- UsageParams,
916
- UsageResult,
917
- UsageSeriesParams,
918
- UsageSeriesResult,
919
- ValidatePromoCodeBodySchema,
920
- ValidatePromoCodeResult,
921
- defaultMachine,
922
- machineDefinition,
923
- machines,
924
- objectToSearchParams
720
+ //#endregion
721
+ //#region src/v3/machinePresets.ts
722
+ const centsPerVCpuSecond = Number(process.env.CENTS_PER_VCPU_SECOND ?? 0);
723
+ const centsPerGbRamSecond = Number(process.env.CENTS_PER_GB_RAM_SECOND ?? 0);
724
+ const machines = {
725
+ micro: machineDefinition({
726
+ code: "micro",
727
+ title: "Micro",
728
+ cpu: .25,
729
+ memory: .25,
730
+ centsPerVCpuSecond,
731
+ centsPerGbRamSecond
732
+ }),
733
+ "small-1x": machineDefinition({
734
+ code: "small-1x",
735
+ title: "Small 1x",
736
+ cpu: .5,
737
+ memory: .5,
738
+ centsPerVCpuSecond,
739
+ centsPerGbRamSecond
740
+ }),
741
+ "small-2x": machineDefinition({
742
+ code: "small-2x",
743
+ title: "Small 2x",
744
+ cpu: 1,
745
+ memory: 1,
746
+ centsPerVCpuSecond,
747
+ centsPerGbRamSecond
748
+ }),
749
+ "medium-1x": machineDefinition({
750
+ code: "medium-1x",
751
+ title: "Medium 1x",
752
+ cpu: 1,
753
+ memory: 2,
754
+ centsPerVCpuSecond,
755
+ centsPerGbRamSecond
756
+ }),
757
+ "medium-2x": machineDefinition({
758
+ code: "medium-2x",
759
+ title: "Medium 2x",
760
+ cpu: 2,
761
+ memory: 4,
762
+ centsPerVCpuSecond,
763
+ centsPerGbRamSecond
764
+ }),
765
+ "large-1x": machineDefinition({
766
+ code: "large-1x",
767
+ title: "Large 1x",
768
+ cpu: 4,
769
+ memory: 8,
770
+ centsPerVCpuSecond,
771
+ centsPerGbRamSecond
772
+ }),
773
+ "large-2x": machineDefinition({
774
+ code: "large-2x",
775
+ title: "Large 2x",
776
+ cpu: 8,
777
+ memory: 16,
778
+ centsPerVCpuSecond,
779
+ centsPerGbRamSecond
780
+ })
925
781
  };
782
+ const defaultMachine = "small-1x";
783
+ //#endregion
784
+ export { AddOn, AddOnDefinition, AddOns, ApplyPromoCodeBodySchema, ApplyPromoCodeResult, BillingAlertsResult, BillingClient, BillingLimitActiveOrg, BillingLimitConfiguredCustom, BillingLimitConfiguredNone, BillingLimitConfiguredPlan, BillingLimitPendingResolveOrg, BillingLimitResult, BillingLimitState, BillingLimitUnconfigured, BillingLimitsActiveResult, BillingLimitsPendingResolvesResult, CancelSubscriptionResponse, CreatePrivateLinkConnectionBody, CurrentPlan, CustomerPortalRequestBodySchema, CustomerPortalSchema, DeletePrivateLinkResult, EnqueueBuildErrorCodeSchema, EnqueueBuildRequestSchema, EnqueueBuildResponseSchema, ErrorSchema, FreeConnectRequiredSchema, FreeConnectedSchema, MAX_INVOCATION_COST_IN_CENTS, PlanDefinitionSchema, Plans, PlansResult, PrivateLinkConnection, PrivateLinkConnectionList, PrivateLinkConnectionStatus, PrivateLinkRegionsResult, PromoCreditsResult, RegistryCredentialsResponseSchema, ReportComputeUsageEvent, ReportInvocationUsageEvent, ReportInvocationUsageResult, ReportUsagePlan, ReportUsageResult, ResolveBillingLimitRequest, SetAddOnBody, SetAddOnResult, SetPlanBodySchema, SubscribeResultSchema, SubscriptionResult, TriggerInitialDeploymentRequestSchema, TriggerInitialDeploymentResponseSchema, UpdateBillingAlertsRequest, UpdateBillingLimitRequest, UsageParams, UsageResult, UsageSeriesParams, UsageSeriesResult, ValidatePromoCodeBodySchema, ValidatePromoCodeResult, defaultMachine, machineDefinition, machines, objectToSearchParams };
785
+
926
786
  //# sourceMappingURL=index.js.map