@trigger.dev/platform 1.3.1 → 1.3.2

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,743 @@
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
+ const QueueSizeLimits = z.object({
23
+ development: z.number(),
24
+ deployed: z.number()
25
+ });
26
+ const Limits = z.object({
27
+ includedUsage: z.number(),
28
+ concurrentRuns: EnvironmentBasedLimit,
29
+ teamMembers: ExceedableLimit,
30
+ schedules: ExceedableLimit,
31
+ logRetentionDays: ExceedableLimit,
32
+ queryPeriodDays: ExceedableLimit,
33
+ alerts: ExceedableLimit,
34
+ hasStagingEnvironment: z.boolean(),
35
+ realtimeConcurrentConnections: ExceedableLimit,
36
+ branches: ExceedableLimit,
37
+ branchesDev: ExceedableLimit,
38
+ support: z.enum(["community", "slack"]),
39
+ batchRateLimitConfig: BatchRateLimitConfig.optional(),
40
+ batchQueueConcurrencyConfig: BatchQueueConcurrencyConfig.optional(),
41
+ metricDashboards: ExceedableLimit,
42
+ metricWidgetsPerDashboard: ExceedableLimit,
43
+ agentMessages: ExceedableLimit.optional(),
44
+ agentWatchMaxHours: ExceedableLimit.optional(),
45
+ agentWatchers: ExceedableLimit.optional(),
46
+ queueSizeLimits: QueueSizeLimits.optional(),
47
+ hasPrivateNetworking: z.boolean().optional(),
48
+ privateLinkConnectionLimit: z.number().optional(),
49
+ hasSso: z.boolean().optional(),
50
+ streamBasinRetention: z.string().optional()
51
+ });
52
+ const commonMetadata = {
53
+ title: z.string(),
54
+ code: z.string()
58
55
  };
59
- var pricingLookup = {
60
- tierPriceCode: z.string(),
61
- usagePriceCode: z.string(),
62
- usageCouponCode: z.string().optional()
56
+ const pricingLookup = {
57
+ tierPriceCode: z.string(),
58
+ usagePriceCode: z.string(),
59
+ usageCouponCode: z.string().optional()
63
60
  };
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
61
+ const FreePlanDefinition = z.object({
62
+ ...commonMetadata,
63
+ type: z.literal("free"),
64
+ limits: Limits
65
+ });
66
+ const PaidPlanDefinition = z.object({
67
+ ...commonMetadata,
68
+ type: z.literal("paid"),
69
+ tierPrice: z.number(),
70
+ stripe: z.object(pricingLookup),
71
+ limits: Limits
72
+ });
73
+ const EnterprisePlanDefinition = z.object({
74
+ ...commonMetadata,
75
+ type: z.literal("enterprise"),
76
+ limits: Limits
77
+ });
78
+ const PlanDefinitionSchema = z.discriminatedUnion("type", [
79
+ FreePlanDefinition,
80
+ PaidPlanDefinition,
81
+ EnterprisePlanDefinition
85
82
  ]);
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
83
+ const MachineDefinition = z.object({
84
+ code: z.string(),
85
+ title: z.string(),
86
+ cpu: z.number(),
87
+ memory: z.number(),
88
+ centsPerMs: z.number()
89
+ });
90
+ const Plans = z.object({
91
+ free: FreePlanDefinition,
92
+ hobby: PaidPlanDefinition,
93
+ pro: PaidPlanDefinition,
94
+ enterprise: EnterprisePlanDefinition
95
+ });
96
+ /** The pricing per step of the add-on, e.g. $10 for 50 units */
97
+ const AddOnPricing = z.object({
98
+ /** The step size - must purchase in multiples of this amount */
99
+ stepSize: z.number(),
100
+ /** Price per step in cents */
101
+ centsPerStep: z.number()
102
+ });
103
+ const PlansResult = z.object({
104
+ plans: Plans,
105
+ usagePricing: z.object({
106
+ centsPerRunInvocation: z.number(),
107
+ machines: z.record(z.string(), MachineDefinition),
108
+ defaultMachine: z.string()
109
+ }),
110
+ addOnPricing: z.object({
111
+ concurrency: AddOnPricing,
112
+ branches: AddOnPricing,
113
+ seats: AddOnPricing,
114
+ schedules: AddOnPricing
115
+ })
116
+ });
117
+ const AddOnDefinition = z.object({
118
+ code: z.enum([
119
+ "concurrency",
120
+ "branches",
121
+ "seats",
122
+ "schedules"
123
+ ]),
124
+ priceCode: z.string(),
125
+ pricing: AddOnPricing
126
+ });
127
+ const AddOn = z.object({
128
+ purchased: z.number(),
129
+ quota: z.number().optional()
130
+ });
131
+ const AddOns = z.object({
132
+ concurrentRuns: AddOn.optional(),
133
+ branches: AddOn.optional(),
134
+ seats: AddOn.optional(),
135
+ schedules: AddOn.optional()
136
+ });
137
+ //#endregion
138
+ //#region src/v3/schemas/subscription.ts
139
+ const FreeTierStatus = z.enum([
140
+ "requires_connect",
141
+ "approved",
142
+ "rejected"
166
143
  ]);
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
144
+ const SubscriptionResult = z.object({
145
+ freeTierStatus: FreeTierStatus,
146
+ isPaying: z.boolean(),
147
+ showSelfServe: z.boolean().default(true),
148
+ canceledAt: z.string().optional(),
149
+ plan: PlanDefinitionSchema.optional(),
150
+ addOns: AddOns.optional()
151
+ });
152
+ const CurrentPlan = z.object({
153
+ subscription: z.any(),
154
+ v3Subscription: SubscriptionResult
155
+ });
156
+ //#endregion
157
+ //#region src/v3/schemas/subscribe.ts
158
+ const SetPaidPlanBodySchema = z.object({
159
+ type: z.literal("paid"),
160
+ planCode: z.string(),
161
+ userId: z.string()
162
+ });
163
+ const SetFreePlanBodySchema = z.object({
164
+ type: z.literal("free"),
165
+ userId: z.string()
166
+ });
167
+ const SetPlanBodySchema = z.discriminatedUnion("type", [SetPaidPlanBodySchema, SetFreePlanBodySchema]);
168
+ const FreeConnectRequiredSchema = z.object({
169
+ action: z.literal("free_connect_required"),
170
+ connectUrl: z.string().url()
171
+ });
172
+ const FreeConnectedSchema = z.object({
173
+ action: z.literal("free_connected"),
174
+ accepted: z.boolean()
175
+ });
176
+ const UpdatedSubscriptionResultSchema = z.object({
177
+ action: z.literal("updated_subscription"),
178
+ subscription: z.object({ planCode: z.string() })
179
+ });
180
+ const CreateSubscriptionFlowStartSchema = z.object({
181
+ action: z.literal("create_subscription_flow_start"),
182
+ subscription: z.object({ planCode: z.string() }),
183
+ checkoutUrl: z.string().url()
184
+ });
185
+ const CanceledSubscriptionResultSchema = z.object({ action: z.literal("canceled_subscription") });
186
+ const SubscribeResultSchema = z.discriminatedUnion("action", [
187
+ FreeConnectRequiredSchema,
188
+ FreeConnectedSchema,
189
+ CreateSubscriptionFlowStartSchema,
190
+ UpdatedSubscriptionResultSchema,
191
+ CanceledSubscriptionResultSchema
197
192
  ]);
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
- })
193
+ const SetAddOnBody = z.object({
194
+ type: z.enum([
195
+ "concurrency",
196
+ "branches",
197
+ "seats",
198
+ "schedules"
199
+ ]),
200
+ amount: z.number()
201
+ });
202
+ const SetAddOnResult = z.discriminatedUnion("result", [
203
+ z.object({
204
+ result: z.literal("error"),
205
+ error: z.string()
206
+ }),
207
+ z.object({
208
+ result: z.literal("success"),
209
+ type: z.string(),
210
+ amount: z.number(),
211
+ subscription: z.object({ id: z.string() })
212
+ }),
213
+ z.object({
214
+ result: z.literal("max_quota_reached"),
215
+ type: z.string(),
216
+ maxQuota: z.number()
217
+ })
220
218
  ]);
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()
219
+ //#endregion
220
+ //#region src/v3/schemas/portal.ts
221
+ const CustomerPortalRequestBodySchema = z.object({ returnUrl: z.string() });
222
+ const CustomerPortalSchema = z.object({ customerPortalUrl: z.string().optional() });
223
+ //#endregion
224
+ //#region src/v3/schemas/error.ts
225
+ const ErrorSchema = z.object({
226
+ error: z.string(),
227
+ code: z.string().optional()
236
228
  }).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
- })
229
+ //#endregion
230
+ //#region src/v3/schemas/usage.ts
231
+ const UsageParams = z.object({
232
+ from: z.coerce.date(),
233
+ to: z.coerce.date()
234
+ });
235
+ const UsageResult = z.object({ cents: z.number() });
236
+ const Window = z.enum([
237
+ "MINUTE",
238
+ "HOUR",
239
+ "DAY"
306
240
  ]);
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
- })
241
+ const UsageSeriesParams = z.object({
242
+ from: z.coerce.date(),
243
+ to: z.coerce.date(),
244
+ /** defaults to DAY */
245
+ window: Window.optional(),
246
+ timezone: z.string().optional()
247
+ });
248
+ const UsageSeriesResult = z.object({
249
+ from: z.string(),
250
+ to: z.string(),
251
+ window: Window.optional(),
252
+ data: z.object({
253
+ value: z.number(),
254
+ windowStart: z.string(),
255
+ windowEnd: z.string()
256
+ }).array()
257
+ });
258
+ const ReportComputeUsageEvent = z.object({ durationMs: z.number() });
259
+ const ReportUsagePlan = z.object({
260
+ type: z.string(),
261
+ code: z.string(),
262
+ isPaying: z.boolean()
263
+ });
264
+ const ReportUsageResult = z.object({
265
+ hasAccess: z.boolean(),
266
+ balance: z.number().optional(),
267
+ usage: z.number().optional(),
268
+ overage: z.number().optional(),
269
+ plan: ReportUsagePlan.optional(),
270
+ limitState: z.literal("grace").optional(),
271
+ reason: z.enum(["free_tier_exceeded", "billing_limit"]).optional()
272
+ });
273
+ /** Upper bound for a single invocation base charge ($100). */
274
+ const MAX_INVOCATION_COST_IN_CENTS = 1e4;
275
+ const ReportInvocationUsageEvent = z.object({
276
+ organizationId: z.string().min(1).max(128),
277
+ costInCents: z.number().finite().min(0).max(MAX_INVOCATION_COST_IN_CENTS),
278
+ additionalData: z.record(z.string(), z.any()).optional()
279
+ });
280
+ const ReportInvocationUsageResult = z.discriminatedUnion("success", [z.object({ success: z.literal(true) }), z.object({
281
+ success: z.literal(false),
282
+ error: z.string()
283
+ })]);
284
+ const BillingAlertsResult = z.object({
285
+ amount: z.number(),
286
+ emails: z.array(z.string()),
287
+ alertLevels: z.array(z.number())
288
+ });
289
+ const UpdateBillingAlertsRequest = z.object({
290
+ amount: z.number().positive(),
291
+ emails: z.array(z.string()),
292
+ alertLevels: z.array(z.number())
293
+ });
294
+ //#endregion
295
+ //#region src/v3/schemas/billingLimit.ts
296
+ const BillingLimitState = z.discriminatedUnion("status", [
297
+ z.object({ status: z.literal("ok") }),
298
+ z.object({
299
+ status: z.literal("grace"),
300
+ hitAt: z.string(),
301
+ graceEndsAt: z.string()
302
+ }),
303
+ z.object({
304
+ status: z.literal("rejected"),
305
+ hitAt: z.string(),
306
+ graceEndsAt: z.string()
307
+ })
338
308
  ]);
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()
309
+ const billingLimitConfiguredFields = {
310
+ isConfigured: z.literal(true),
311
+ cancelInProgressRuns: z.boolean(),
312
+ limitState: BillingLimitState,
313
+ effectiveAmountCents: z.number().int().nonnegative().nullable(),
314
+ gracePeriodMs: z.number().int().nonnegative()
345
315
  };
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
316
+ const BillingLimitUnconfigured = z.object({
317
+ isConfigured: z.literal(false),
318
+ gracePeriodMs: z.number().int().nonnegative()
319
+ });
320
+ const BillingLimitConfiguredNone = z.object({
321
+ ...billingLimitConfiguredFields,
322
+ mode: z.literal("none")
323
+ });
324
+ const BillingLimitConfiguredPlan = z.object({
325
+ ...billingLimitConfiguredFields,
326
+ mode: z.literal("plan")
327
+ });
328
+ const BillingLimitConfiguredCustom = z.object({
329
+ ...billingLimitConfiguredFields,
330
+ mode: z.literal("custom"),
331
+ amountCents: z.number().int().positive()
332
+ });
333
+ const BillingLimitResult = z.union([
334
+ BillingLimitUnconfigured,
335
+ BillingLimitConfiguredNone,
336
+ BillingLimitConfiguredPlan,
337
+ BillingLimitConfiguredCustom
368
338
  ]);
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
- })
339
+ const UpdateBillingLimitRequest = z.discriminatedUnion("mode", [
340
+ z.object({
341
+ mode: z.literal("none"),
342
+ cancelInProgressRuns: z.boolean()
343
+ }),
344
+ z.object({
345
+ mode: z.literal("plan"),
346
+ cancelInProgressRuns: z.boolean()
347
+ }),
348
+ z.object({
349
+ mode: z.literal("custom"),
350
+ amountCents: z.number().int().positive(),
351
+ cancelInProgressRuns: z.boolean()
352
+ })
383
353
  ]);
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
- })
354
+ const ResolveBillingLimitRequest = z.discriminatedUnion("action", [z.object({
355
+ action: z.literal("increase"),
356
+ newAmountCents: z.number().int().positive(),
357
+ resumeMode: z.enum(["queue", "new_only"])
358
+ }), z.object({
359
+ action: z.literal("remove"),
360
+ resumeMode: z.enum(["queue", "new_only"])
361
+ })]);
362
+ const BillingLimitActiveOrg = z.object({
363
+ orgId: z.string(),
364
+ limitState: z.enum(["grace", "rejected"])
365
+ });
366
+ const BillingLimitsActiveResult = z.object({ orgs: z.array(BillingLimitActiveOrg) });
367
+ const BillingLimitPendingResolveOrg = z.object({
368
+ organizationId: z.string(),
369
+ resumeMode: z.enum(["queue", "new_only"]),
370
+ resolvedAt: z.string()
371
+ });
372
+ const BillingLimitsPendingResolvesResult = z.object({ orgs: z.array(BillingLimitPendingResolveOrg) });
373
+ //#endregion
374
+ //#region src/v3/schemas/registryCredentials.ts
375
+ const RegistryCredentialsResponseSchema = z.object({
376
+ username: z.string(),
377
+ password: z.string(),
378
+ expiresAt: z.string().datetime(),
379
+ repositoryUri: z.string()
380
+ });
381
+ //#endregion
382
+ //#region src/v3/schemas/enqueueBuild.ts
383
+ const EnqueueBuildRequestSchema = z.object({
384
+ deploymentId: z.string(),
385
+ artifactKey: z.string(),
386
+ options: z.object({
387
+ skipPromotion: z.boolean().optional(),
388
+ configFilePath: z.string().optional(),
389
+ fromBundle: z.boolean().optional()
390
+ })
391
+ });
392
+ const EnqueueBuildResponseSchema = z.object({ buildId: z.string() });
393
+ //#endregion
394
+ //#region src/v3/schemas/initialDeployment.ts
395
+ const TriggerInitialDeploymentRequestSchema = z.object({
396
+ environment: z.enum([
397
+ "prod",
398
+ "staging",
399
+ "preview"
400
+ ]),
401
+ branch: z.string().min(1).max(255).optional()
402
+ });
403
+ const TriggerInitialDeploymentResponseSchema = z.object({ ok: z.boolean() });
404
+ //#endregion
405
+ //#region src/v3/schemas/privateLink.ts
406
+ const PrivateLinkConnectionStatus = z.enum([
407
+ "PENDING",
408
+ "PROVISIONING",
409
+ "ACTIVE",
410
+ "ERROR",
411
+ "DELETING"
394
412
  ]);
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"
451
- ]);
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
413
+ const PrivateLinkConnection = z.object({
414
+ id: z.string(),
415
+ friendlyId: z.string(),
416
+ name: z.string(),
417
+ organizationId: z.string(),
418
+ endpointServiceName: z.string(),
419
+ targetRegion: z.string(),
420
+ status: PrivateLinkConnectionStatus,
421
+ statusMessage: z.string().nullable(),
422
+ endpointDnsName: z.string().nullable(),
423
+ endpointIps: z.array(z.string()).nullable(),
424
+ provisionedAt: z.string().nullable(),
425
+ createdAt: z.string(),
426
+ updatedAt: z.string()
427
+ });
428
+ const PrivateLinkConnectionList = z.object({ connections: z.array(PrivateLinkConnection) });
429
+ const CreatePrivateLinkConnectionBody = z.object({
430
+ 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"),
431
+ endpointServiceName: z.string().regex(/^com\.amazonaws\.vpce\..+\.vpce-svc-.+$/, "Must be a valid VPC Endpoint Service name (com.amazonaws.vpce.<region>.vpce-svc-*)"),
432
+ targetRegion: z.string().regex(/^[a-z]{2}-[a-z]+-\d+$/, "Must be a valid AWS region")
433
+ });
434
+ const DeletePrivateLinkResult = z.object({ success: z.boolean() });
435
+ const PrivateLinkRegionsResult = z.object({
436
+ availableRegions: z.array(z.string()),
437
+ activeRegions: z.array(z.string())
438
+ });
439
+ //#endregion
440
+ //#region src/v3/schemas/promoCodes.ts
441
+ const ValidatePromoCodeBodySchema = z.object({ code: z.string() });
442
+ const ValidatePromoCodeResult = z.object({
443
+ valid: z.boolean(),
444
+ amountInCents: z.number().optional(),
445
+ expiresAt: z.string().datetime().nullable().optional()
446
+ });
447
+ const ApplyPromoCodeBodySchema = z.object({
448
+ code: z.string(),
449
+ userId: z.string()
450
+ });
451
+ const ApplyPromoCodeResult = z.object({
452
+ applied: z.boolean(),
453
+ amountInCents: z.number().optional(),
454
+ expiresAt: z.string().datetime().nullable().optional(),
455
+ reason: z.string().optional()
456
+ });
457
+ const PromoCreditsResult = z.object({ promoCredits: z.object({
458
+ grantedCents: z.number(),
459
+ remainingCents: z.number(),
460
+ expiresAt: z.string().datetime().nullable()
461
+ }).nullable() });
462
+ //#endregion
463
+ //#region src/v3/client/index.ts
523
464
  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
- }
465
+ constructor(config) {
466
+ this.config = config;
467
+ }
468
+ async plans() {
469
+ return await this.fetch(`/api/v1/plans/v3`, PlansResult);
470
+ }
471
+ async currentPlan(orgId) {
472
+ return await this.fetch(`/api/v1/orgs/${orgId}`, CurrentPlan);
473
+ }
474
+ async usage(orgId, params) {
475
+ const search = objectToSearchParams(params);
476
+ return await this.fetch(`/api/v1/orgs/${orgId}/usage?${search?.toString()}`, UsageResult);
477
+ }
478
+ async usageSeries(orgId, params) {
479
+ const search = objectToSearchParams(params);
480
+ return await this.fetch(`/api/v1/orgs/${orgId}/usage/series?${search?.toString()}`, UsageSeriesResult);
481
+ }
482
+ async setPlan(orgId, body) {
483
+ return await this.fetch(`/api/v1/orgs/${orgId}/v3/subscription`, SubscribeResultSchema, {
484
+ method: "POST",
485
+ headers: { "Content-Type": "application/json" },
486
+ body: JSON.stringify(body)
487
+ });
488
+ }
489
+ async setAddOn(orgId, body) {
490
+ return await this.fetch(`/api/v1/orgs/${orgId}/v3/subscription/addon`, SetAddOnResult, {
491
+ method: "POST",
492
+ headers: { "Content-Type": "application/json" },
493
+ body: JSON.stringify(body)
494
+ });
495
+ }
496
+ async validatePromoCode(code) {
497
+ return await this.fetch(`/api/v1/promo-codes/validate`, ValidatePromoCodeResult, {
498
+ method: "POST",
499
+ headers: { "Content-Type": "application/json" },
500
+ body: JSON.stringify({ code })
501
+ });
502
+ }
503
+ async applyPromoCode(orgId, body) {
504
+ return await this.fetch(`/api/v1/orgs/${orgId}/promo/apply`, ApplyPromoCodeResult, {
505
+ method: "POST",
506
+ headers: { "Content-Type": "application/json" },
507
+ body: JSON.stringify(body)
508
+ });
509
+ }
510
+ async promoCredits(orgId) {
511
+ return await this.fetch(`/api/v1/orgs/${orgId}/promo/credits`, PromoCreditsResult);
512
+ }
513
+ async createPortalSession(orgId, body) {
514
+ return await this.fetch(`/api/v1/orgs/${orgId}/v3/subscription/portal`, CustomerPortalSchema, {
515
+ method: "POST",
516
+ headers: { "Content-Type": "application/json" },
517
+ body: JSON.stringify(body)
518
+ });
519
+ }
520
+ /**
521
+ *
522
+ * @param event The data is in the body, not using a JWT
523
+ * @returns details about usage
524
+ */
525
+ async reportInvocationUsage(event) {
526
+ return await this.fetch(`/api/v1/usage/ingest/invocation`, ReportInvocationUsageResult, {
527
+ method: "POST",
528
+ headers: { "Content-Type": "application/json" },
529
+ body: JSON.stringify(event)
530
+ });
531
+ }
532
+ /**
533
+ * Generates registry credentials for a project. This is used to push images to a project's container repository.
534
+ *
535
+ * @param projectId The ID of the project
536
+ * @param region The region to generate credentials for
537
+ * @returns The registry credentials
538
+ */
539
+ async generateRegistryCredentials(projectId, region) {
540
+ return await this.fetch(`/api/v1/projects/${projectId}/generate-registry-credentials`, RegistryCredentialsResponseSchema, {
541
+ method: "POST",
542
+ headers: { "Content-Type": "application/json" },
543
+ body: JSON.stringify({ region })
544
+ });
545
+ }
546
+ /**
547
+ * Enqueues a build for a project deployment.
548
+ *
549
+ * @param projectId The ID of the project
550
+ * @param body The enqueue build request containing the deployment ID
551
+ * @returns The build ID
552
+ */
553
+ async enqueueBuild(projectId, body) {
554
+ return await this.fetch(`/api/v1/projects/${projectId}/enqueue-build`, EnqueueBuildResponseSchema, {
555
+ method: "POST",
556
+ headers: { "Content-Type": "application/json" },
557
+ body: JSON.stringify(body)
558
+ });
559
+ }
560
+ /**
561
+ *
562
+ * @param event The data is in the body, not using a JWT
563
+ * @returns details about usage
564
+ */
565
+ async getEntitlement(orgId) {
566
+ return await this.fetch(`/api/v1/orgs/${orgId}/usage/entitlement`, ReportUsageResult);
567
+ }
568
+ async getBillingAlerts(orgId) {
569
+ return await this.fetch(`/api/v1/orgs/${orgId}/billing-alerts`, BillingAlertsResult);
570
+ }
571
+ async updateBillingAlerts(orgId, body) {
572
+ return await this.fetch(`/api/v1/orgs/${orgId}/billing-alerts`, BillingAlertsResult, {
573
+ method: "POST",
574
+ headers: { "Content-Type": "application/json" },
575
+ body: JSON.stringify(body)
576
+ });
577
+ }
578
+ async getBillingLimit(orgId) {
579
+ return await this.fetch(`/api/v1/orgs/${orgId}/billing-limit`, BillingLimitResult);
580
+ }
581
+ async updateBillingLimit(orgId, body) {
582
+ return await this.fetch(`/api/v1/orgs/${orgId}/billing-limit`, BillingLimitResult, {
583
+ method: "PUT",
584
+ headers: { "Content-Type": "application/json" },
585
+ body: JSON.stringify(body)
586
+ });
587
+ }
588
+ async resolveBillingLimit(orgId, body) {
589
+ return await this.fetch(`/api/v1/orgs/${orgId}/billing-limit/resolve`, BillingLimitResult, {
590
+ method: "POST",
591
+ headers: { "Content-Type": "application/json" },
592
+ body: JSON.stringify(body)
593
+ });
594
+ }
595
+ async getActiveBillingLimits() {
596
+ return await this.fetch(`/api/v1/billing-limits/active`, BillingLimitsActiveResult);
597
+ }
598
+ async getPrivateLinks(orgId) {
599
+ return await this.fetch(`/api/v1/orgs/${orgId}/private-connections`, PrivateLinkConnectionList);
600
+ }
601
+ async createPrivateLink(orgId, body) {
602
+ return await this.fetch(`/api/v1/orgs/${orgId}/private-connections`, PrivateLinkConnection, {
603
+ method: "POST",
604
+ headers: { "Content-Type": "application/json" },
605
+ body: JSON.stringify(body)
606
+ });
607
+ }
608
+ async deletePrivateLink(orgId, connectionId) {
609
+ return await this.fetch(`/api/v1/orgs/${orgId}/private-connections/${connectionId}`, DeletePrivateLinkResult, { method: "DELETE" });
610
+ }
611
+ async getPrivateLinkRegions(orgId) {
612
+ return await this.fetch(`/api/v1/orgs/${orgId}/private-connections/regions`, PrivateLinkRegionsResult);
613
+ }
614
+ async triggerInitialDeployment(projectId, body) {
615
+ return await this.fetch(`/api/v1/projects/${projectId}/initial-deployment`, TriggerInitialDeploymentResponseSchema, {
616
+ method: "POST",
617
+ headers: { "Content-Type": "application/json" },
618
+ body: JSON.stringify(body)
619
+ });
620
+ }
621
+ async fetch(path, schema, requestInit) {
622
+ const response = await fetch(`${this.config.url}${path}`, {
623
+ ...requestInit,
624
+ headers: {
625
+ ...requestInit?.headers,
626
+ Authorization: `Bearer ${this.config.apiKey}`
627
+ }
628
+ });
629
+ if (!response.ok) {
630
+ let parsedError;
631
+ try {
632
+ parsedError = ErrorSchema.parse(await response.json());
633
+ } catch {
634
+ parsedError = { error: `http_${response.status}` };
635
+ }
636
+ return {
637
+ success: false,
638
+ ...parsedError
639
+ };
640
+ }
641
+ const json = await response.json();
642
+ return {
643
+ success: true,
644
+ ...schema.parse(json)
645
+ };
646
+ }
757
647
  };
758
648
  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;
649
+ if (!obj) return void 0;
650
+ const searchParams = new URLSearchParams();
651
+ Object.entries(obj).forEach(([key, value]) => {
652
+ if (value === void 0) return;
653
+ if (Array.isArray(value)) {
654
+ const values = value.map((d) => {
655
+ if (d instanceof Date) return d.toISOString();
656
+ return d;
657
+ });
658
+ searchParams.append(key, values.join(","));
659
+ } else {
660
+ const v = value instanceof Date ? value.toISOString() : value;
661
+ searchParams.append(key, v.toString());
662
+ }
663
+ });
664
+ return searchParams;
778
665
  }
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
- };
666
+ //#endregion
667
+ //#region src/v3/machineDefinition.ts
668
+ function machineDefinition({ code, title, cpu, memory, centsPerVCpuSecond, centsPerGbRamSecond }) {
669
+ return {
670
+ code,
671
+ title,
672
+ cpu,
673
+ memory,
674
+ centsPerMs: (cpu * centsPerVCpuSecond + memory * centsPerGbRamSecond) / 1e3
675
+ };
798
676
  }
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
677
+ //#endregion
678
+ //#region src/v3/machinePresets.ts
679
+ const centsPerVCpuSecond = Number(process.env.CENTS_PER_VCPU_SECOND ?? 0);
680
+ const centsPerGbRamSecond = Number(process.env.CENTS_PER_GB_RAM_SECOND ?? 0);
681
+ const machines = {
682
+ micro: machineDefinition({
683
+ code: "micro",
684
+ title: "Micro",
685
+ cpu: .25,
686
+ memory: .25,
687
+ centsPerVCpuSecond,
688
+ centsPerGbRamSecond
689
+ }),
690
+ "small-1x": machineDefinition({
691
+ code: "small-1x",
692
+ title: "Small 1x",
693
+ cpu: .5,
694
+ memory: .5,
695
+ centsPerVCpuSecond,
696
+ centsPerGbRamSecond
697
+ }),
698
+ "small-2x": machineDefinition({
699
+ code: "small-2x",
700
+ title: "Small 2x",
701
+ cpu: 1,
702
+ memory: 1,
703
+ centsPerVCpuSecond,
704
+ centsPerGbRamSecond
705
+ }),
706
+ "medium-1x": machineDefinition({
707
+ code: "medium-1x",
708
+ title: "Medium 1x",
709
+ cpu: 1,
710
+ memory: 2,
711
+ centsPerVCpuSecond,
712
+ centsPerGbRamSecond
713
+ }),
714
+ "medium-2x": machineDefinition({
715
+ code: "medium-2x",
716
+ title: "Medium 2x",
717
+ cpu: 2,
718
+ memory: 4,
719
+ centsPerVCpuSecond,
720
+ centsPerGbRamSecond
721
+ }),
722
+ "large-1x": machineDefinition({
723
+ code: "large-1x",
724
+ title: "Large 1x",
725
+ cpu: 4,
726
+ memory: 8,
727
+ centsPerVCpuSecond,
728
+ centsPerGbRamSecond
729
+ }),
730
+ "large-2x": machineDefinition({
731
+ code: "large-2x",
732
+ title: "Large 2x",
733
+ cpu: 8,
734
+ memory: 16,
735
+ centsPerVCpuSecond,
736
+ centsPerGbRamSecond
737
+ })
925
738
  };
739
+ const defaultMachine = "small-1x";
740
+ //#endregion
741
+ export { AddOn, AddOnDefinition, AddOns, ApplyPromoCodeBodySchema, ApplyPromoCodeResult, BillingAlertsResult, BillingClient, BillingLimitActiveOrg, BillingLimitConfiguredCustom, BillingLimitConfiguredNone, BillingLimitConfiguredPlan, BillingLimitPendingResolveOrg, BillingLimitResult, BillingLimitState, BillingLimitUnconfigured, BillingLimitsActiveResult, BillingLimitsPendingResolvesResult, CreatePrivateLinkConnectionBody, CurrentPlan, CustomerPortalRequestBodySchema, CustomerPortalSchema, DeletePrivateLinkResult, 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 };
742
+
926
743
  //# sourceMappingURL=index.js.map