@trigger.dev/platform 1.0.11
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/LICENSE +21 -0
- package/dist/v2/index.cjs +414 -0
- package/dist/v2/index.cjs.map +1 -0
- package/dist/v2/index.d.cts +1557 -0
- package/dist/v2/index.d.ts +1557 -0
- package/dist/v2/index.js +373 -0
- package/dist/v2/index.js.map +1 -0
- package/dist/v3/index.cjs +477 -0
- package/dist/v3/index.cjs.map +1 -0
- package/dist/v3/index.d.cts +5730 -0
- package/dist/v3/index.d.ts +5730 -0
- package/dist/v3/index.js +428 -0
- package/dist/v3/index.js.map +1 -0
- package/package.json +57 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Trigger.dev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/v2/index.ts
|
|
21
|
+
var v2_exports = {};
|
|
22
|
+
__export(v2_exports, {
|
|
23
|
+
ActiveSubscriptionSchema: () => ActiveSubscriptionSchema,
|
|
24
|
+
BillingClient: () => BillingClient,
|
|
25
|
+
BracketSchema: () => BracketSchema,
|
|
26
|
+
CurrentPlanSchema: () => CurrentPlanSchema,
|
|
27
|
+
CustomerPortalRequestBodySchema: () => CustomerPortalRequestBodySchema,
|
|
28
|
+
CustomerPortalSchema: () => CustomerPortalSchema,
|
|
29
|
+
ErrorSchema: () => ErrorSchema,
|
|
30
|
+
PlanDefinitionSchema: () => PlanDefinitionSchema,
|
|
31
|
+
PlanSchema: () => PlanSchema,
|
|
32
|
+
PlansSchema: () => PlansSchema,
|
|
33
|
+
PricedMetricSchema: () => PricedMetricSchema,
|
|
34
|
+
RunPricingSchema: () => RunPricingSchema2,
|
|
35
|
+
SetPlanBodySchema: () => SetPlanBodySchema,
|
|
36
|
+
SubscribeResultSchema: () => SubscribeResultSchema,
|
|
37
|
+
estimate: () => estimate
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(v2_exports);
|
|
40
|
+
|
|
41
|
+
// src/v2/schemas/planDefinitions.ts
|
|
42
|
+
var import_zod = require("zod");
|
|
43
|
+
var BracketSchema = import_zod.z.object({
|
|
44
|
+
code: import_zod.z.string(),
|
|
45
|
+
upto: import_zod.z.number(),
|
|
46
|
+
tierCost: import_zod.z.number()
|
|
47
|
+
});
|
|
48
|
+
var PlanDefinitionSchema = import_zod.z.object({
|
|
49
|
+
title: import_zod.z.string(),
|
|
50
|
+
code: import_zod.z.string(),
|
|
51
|
+
concurrentRuns: import_zod.z.object({
|
|
52
|
+
pricing: import_zod.z.object({
|
|
53
|
+
tiers: import_zod.z.array(BracketSchema)
|
|
54
|
+
}).optional(),
|
|
55
|
+
freeAllowance: import_zod.z.number().optional()
|
|
56
|
+
}).optional(),
|
|
57
|
+
runs: import_zod.z.object({
|
|
58
|
+
pricing: import_zod.z.object({
|
|
59
|
+
code: import_zod.z.string()
|
|
60
|
+
}).optional(),
|
|
61
|
+
freeAllowance: import_zod.z.number().optional()
|
|
62
|
+
}).optional()
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// src/v2/schemas/pricing.ts
|
|
66
|
+
var import_zod2 = require("zod");
|
|
67
|
+
var GraduatedPriceSchema = import_zod2.z.object({
|
|
68
|
+
type: import_zod2.z.literal("graduated"),
|
|
69
|
+
brackets: import_zod2.z.array(
|
|
70
|
+
import_zod2.z.object({
|
|
71
|
+
upto: import_zod2.z.number().optional(),
|
|
72
|
+
flatCost: import_zod2.z.number(),
|
|
73
|
+
perUnitCost: import_zod2.z.number()
|
|
74
|
+
})
|
|
75
|
+
)
|
|
76
|
+
});
|
|
77
|
+
var VolumePriceSchema = import_zod2.z.object({
|
|
78
|
+
type: import_zod2.z.literal("volume"),
|
|
79
|
+
brackets: import_zod2.z.array(
|
|
80
|
+
import_zod2.z.object({
|
|
81
|
+
upto: import_zod2.z.number().optional(),
|
|
82
|
+
flatCost: import_zod2.z.number(),
|
|
83
|
+
perUnitCost: import_zod2.z.number()
|
|
84
|
+
})
|
|
85
|
+
)
|
|
86
|
+
});
|
|
87
|
+
var FixedPriceSchema = import_zod2.z.object({
|
|
88
|
+
type: import_zod2.z.literal("fixed"),
|
|
89
|
+
cost: import_zod2.z.number()
|
|
90
|
+
});
|
|
91
|
+
var PricedMetricSchema = import_zod2.z.discriminatedUnion("type", [
|
|
92
|
+
FixedPriceSchema,
|
|
93
|
+
GraduatedPriceSchema,
|
|
94
|
+
VolumePriceSchema
|
|
95
|
+
]);
|
|
96
|
+
|
|
97
|
+
// src/v2/schemas/usage.ts
|
|
98
|
+
var import_zod3 = require("zod");
|
|
99
|
+
var RunPricingSchema = import_zod3.z.object({
|
|
100
|
+
pricing: import_zod3.z.object({
|
|
101
|
+
code: import_zod3.z.string()
|
|
102
|
+
}).optional(),
|
|
103
|
+
freeAllowance: import_zod3.z.number().optional()
|
|
104
|
+
});
|
|
105
|
+
var ActiveSubscriptionSchema = import_zod3.z.object({
|
|
106
|
+
isPaying: import_zod3.z.boolean(),
|
|
107
|
+
plan: import_zod3.z.object({
|
|
108
|
+
title: import_zod3.z.string(),
|
|
109
|
+
code: import_zod3.z.string(),
|
|
110
|
+
concurrentRuns: import_zod3.z.object({
|
|
111
|
+
pricing: import_zod3.z.object({
|
|
112
|
+
code: import_zod3.z.string(),
|
|
113
|
+
upto: import_zod3.z.number().optional(),
|
|
114
|
+
tierCost: import_zod3.z.number().optional()
|
|
115
|
+
}).optional(),
|
|
116
|
+
freeAllowance: import_zod3.z.number().optional()
|
|
117
|
+
}),
|
|
118
|
+
runs: RunPricingSchema.optional()
|
|
119
|
+
}),
|
|
120
|
+
limits: import_zod3.z.object({
|
|
121
|
+
runs: import_zod3.z.number().optional(),
|
|
122
|
+
concurrentRuns: import_zod3.z.number().optional()
|
|
123
|
+
}),
|
|
124
|
+
canceledAt: import_zod3.z.string().optional()
|
|
125
|
+
});
|
|
126
|
+
var CurrentPlanSchema = import_zod3.z.object({
|
|
127
|
+
subscription: ActiveSubscriptionSchema.optional()
|
|
128
|
+
});
|
|
129
|
+
var SetPaidPlanBodySchema = import_zod3.z.object({
|
|
130
|
+
type: import_zod3.z.literal("paid"),
|
|
131
|
+
planCode: import_zod3.z.string(),
|
|
132
|
+
concurrentRunBracket: import_zod3.z.string()
|
|
133
|
+
});
|
|
134
|
+
var SetFreePlanBodySchema = import_zod3.z.object({
|
|
135
|
+
type: import_zod3.z.literal("free")
|
|
136
|
+
});
|
|
137
|
+
var SetPlanBodySchema = import_zod3.z.discriminatedUnion("type", [
|
|
138
|
+
SetPaidPlanBodySchema,
|
|
139
|
+
SetFreePlanBodySchema
|
|
140
|
+
]);
|
|
141
|
+
|
|
142
|
+
// src/v2/schemas/plans.ts
|
|
143
|
+
var import_zod4 = require("zod");
|
|
144
|
+
var RunPriceBracketSchema = import_zod4.z.object({
|
|
145
|
+
upto: import_zod4.z.number().optional(),
|
|
146
|
+
unitCost: import_zod4.z.number()
|
|
147
|
+
});
|
|
148
|
+
var RunPricingSchema2 = import_zod4.z.object({
|
|
149
|
+
pricing: import_zod4.z.object({
|
|
150
|
+
code: import_zod4.z.string(),
|
|
151
|
+
brackets: import_zod4.z.array(RunPriceBracketSchema)
|
|
152
|
+
}).optional(),
|
|
153
|
+
freeAllowance: import_zod4.z.number().optional()
|
|
154
|
+
});
|
|
155
|
+
var PlanSchema = import_zod4.z.object({
|
|
156
|
+
title: import_zod4.z.string(),
|
|
157
|
+
code: import_zod4.z.string(),
|
|
158
|
+
concurrentRuns: import_zod4.z.object({
|
|
159
|
+
pricing: import_zod4.z.object({
|
|
160
|
+
tiers: import_zod4.z.array(
|
|
161
|
+
import_zod4.z.object({
|
|
162
|
+
code: import_zod4.z.string(),
|
|
163
|
+
upto: import_zod4.z.number(),
|
|
164
|
+
tierCost: import_zod4.z.number()
|
|
165
|
+
})
|
|
166
|
+
)
|
|
167
|
+
}).optional(),
|
|
168
|
+
freeAllowance: import_zod4.z.number().optional()
|
|
169
|
+
}).optional(),
|
|
170
|
+
runs: RunPricingSchema2.optional()
|
|
171
|
+
});
|
|
172
|
+
var PlansSchema = import_zod4.z.object({
|
|
173
|
+
free: PlanSchema,
|
|
174
|
+
paid: PlanSchema,
|
|
175
|
+
enterprise: PlanSchema
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
// src/v2/schemas/subscribe.ts
|
|
179
|
+
var import_zod5 = require("zod");
|
|
180
|
+
var UpdatedSubscriptionResultSchema = import_zod5.z.object({
|
|
181
|
+
action: import_zod5.z.literal("updated_subscription"),
|
|
182
|
+
subscription: import_zod5.z.object({
|
|
183
|
+
planCode: import_zod5.z.string(),
|
|
184
|
+
concurrentRunBracket: import_zod5.z.string()
|
|
185
|
+
})
|
|
186
|
+
});
|
|
187
|
+
var CreateSubscriptionFlowStartSchema = import_zod5.z.object({
|
|
188
|
+
action: import_zod5.z.literal("create_subscription_flow_start"),
|
|
189
|
+
subscription: import_zod5.z.object({
|
|
190
|
+
planCode: import_zod5.z.string(),
|
|
191
|
+
concurrentRunBracket: import_zod5.z.string()
|
|
192
|
+
}),
|
|
193
|
+
checkoutUrl: import_zod5.z.string().url()
|
|
194
|
+
});
|
|
195
|
+
var CanceledSubscriptionResultSchema = import_zod5.z.object({
|
|
196
|
+
action: import_zod5.z.literal("canceled_subscription")
|
|
197
|
+
});
|
|
198
|
+
var SubscribeResultSchema = import_zod5.z.discriminatedUnion("action", [
|
|
199
|
+
CreateSubscriptionFlowStartSchema,
|
|
200
|
+
UpdatedSubscriptionResultSchema,
|
|
201
|
+
CanceledSubscriptionResultSchema
|
|
202
|
+
]);
|
|
203
|
+
|
|
204
|
+
// src/v2/schemas/portal.ts
|
|
205
|
+
var import_zod6 = require("zod");
|
|
206
|
+
var CustomerPortalRequestBodySchema = import_zod6.z.object({
|
|
207
|
+
returnUrl: import_zod6.z.string()
|
|
208
|
+
});
|
|
209
|
+
var CustomerPortalSchema = import_zod6.z.object({
|
|
210
|
+
customerPortalUrl: import_zod6.z.string().optional()
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
// src/v2/schemas/error.ts
|
|
214
|
+
var import_zod7 = require("zod");
|
|
215
|
+
var ErrorSchema = import_zod7.z.object({
|
|
216
|
+
error: import_zod7.z.string()
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
// src/v2/cost.ts
|
|
220
|
+
function planCost({
|
|
221
|
+
usage,
|
|
222
|
+
plan
|
|
223
|
+
}) {
|
|
224
|
+
var _a, _b;
|
|
225
|
+
if (plan.concurrentRuns === void 0 && plan.runs === void 0) {
|
|
226
|
+
return void 0;
|
|
227
|
+
}
|
|
228
|
+
let concurrentRunCost = 0;
|
|
229
|
+
if (plan.concurrentRuns !== void 0) {
|
|
230
|
+
const concurrentUsage = usage["concurrent_runs"] ?? 0;
|
|
231
|
+
if (plan.concurrentRuns.freeAllowance !== void 0) {
|
|
232
|
+
if (concurrentUsage > plan.concurrentRuns.freeAllowance) {
|
|
233
|
+
return void 0;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
const result = calculateVolumeCost({
|
|
237
|
+
usage: concurrentUsage,
|
|
238
|
+
pricedMetric: {
|
|
239
|
+
type: "volume",
|
|
240
|
+
brackets: ((_a = plan.concurrentRuns.pricing) == null ? void 0 : _a.tiers.map((b) => ({
|
|
241
|
+
upto: b.upto ?? 0,
|
|
242
|
+
flatCost: b.tierCost,
|
|
243
|
+
perUnitCost: 0
|
|
244
|
+
}))) ?? []
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
concurrentRunCost += result ?? 0;
|
|
248
|
+
}
|
|
249
|
+
let runsCost = 0;
|
|
250
|
+
if (plan.runs !== void 0) {
|
|
251
|
+
const runUsage = usage["runs"] ?? 0;
|
|
252
|
+
if (plan.runs.freeAllowance !== void 0) {
|
|
253
|
+
if (runUsage > plan.runs.freeAllowance) {
|
|
254
|
+
return void 0;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const result = calculateGraduatedCost({
|
|
258
|
+
usage: runUsage,
|
|
259
|
+
pricedMetric: {
|
|
260
|
+
type: "graduated",
|
|
261
|
+
brackets: ((_b = plan.runs.pricing) == null ? void 0 : _b.brackets.map((b) => ({
|
|
262
|
+
upto: b.upto ?? 0,
|
|
263
|
+
perUnitCost: b.unitCost,
|
|
264
|
+
flatCost: 0
|
|
265
|
+
}))) ?? []
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
runsCost += (result == null ? void 0 : result.total) ?? 0;
|
|
269
|
+
}
|
|
270
|
+
return {
|
|
271
|
+
runsCost,
|
|
272
|
+
concurrentRunCost,
|
|
273
|
+
total: runsCost + concurrentRunCost
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
function calculateGraduatedCost({
|
|
277
|
+
usage,
|
|
278
|
+
pricedMetric
|
|
279
|
+
}) {
|
|
280
|
+
if (pricedMetric.brackets.length === 0) {
|
|
281
|
+
return void 0;
|
|
282
|
+
}
|
|
283
|
+
const result = { brackets: [], total: 0 };
|
|
284
|
+
for (let index = 0; index < pricedMetric.brackets.length; index++) {
|
|
285
|
+
const bracket = pricedMetric.brackets[index];
|
|
286
|
+
const previousBracket = pricedMetric.brackets[index - 1];
|
|
287
|
+
const from = (previousBracket == null ? void 0 : previousBracket.upto) ?? 0;
|
|
288
|
+
if (usage >= from) {
|
|
289
|
+
const usageAboveBracket = Math.max(usage - from, 0);
|
|
290
|
+
let usageInsideBracket = usageAboveBracket;
|
|
291
|
+
if (bracket.upto) {
|
|
292
|
+
usageInsideBracket = Math.min(usageAboveBracket, bracket.upto - from);
|
|
293
|
+
}
|
|
294
|
+
const bracketCost = bracket.flatCost + bracket.perUnitCost * usageInsideBracket;
|
|
295
|
+
result.brackets.push({
|
|
296
|
+
from,
|
|
297
|
+
to: bracket.upto,
|
|
298
|
+
amount: usageInsideBracket,
|
|
299
|
+
cost: bracketCost
|
|
300
|
+
});
|
|
301
|
+
result.total += bracketCost;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return result;
|
|
305
|
+
}
|
|
306
|
+
function calculateVolumeCost({
|
|
307
|
+
usage,
|
|
308
|
+
pricedMetric
|
|
309
|
+
}) {
|
|
310
|
+
for (let index = 0; index < pricedMetric.brackets.length; index++) {
|
|
311
|
+
const bracket = pricedMetric.brackets[index];
|
|
312
|
+
const previousBracket = pricedMetric.brackets[index - 1];
|
|
313
|
+
const from = (previousBracket == null ? void 0 : previousBracket.upto) ?? 0;
|
|
314
|
+
if (usage >= from && (bracket.upto === void 0 || usage <= bracket.upto)) {
|
|
315
|
+
return bracket.flatCost + bracket.perUnitCost * usage;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// src/v2/estimate.ts
|
|
321
|
+
function estimate({
|
|
322
|
+
usage,
|
|
323
|
+
plans
|
|
324
|
+
}) {
|
|
325
|
+
let result;
|
|
326
|
+
for (const plan of plans) {
|
|
327
|
+
const cost = planCost({ usage, plan });
|
|
328
|
+
if (cost !== void 0 && (result === void 0 || cost.total < result.cost.total)) {
|
|
329
|
+
result = { plan: { code: plan.code }, cost };
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return result;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// src/v2/client/index.ts
|
|
336
|
+
var BillingClient = class {
|
|
337
|
+
constructor(config) {
|
|
338
|
+
this.config = config;
|
|
339
|
+
}
|
|
340
|
+
async plans() {
|
|
341
|
+
return await this.fetch(`/api/v1/plans`, PlansSchema);
|
|
342
|
+
}
|
|
343
|
+
async currentPlan(orgId) {
|
|
344
|
+
return await this.fetch(`/api/v1/orgs/${orgId}`, CurrentPlanSchema);
|
|
345
|
+
}
|
|
346
|
+
async setPlan(orgId, body) {
|
|
347
|
+
return await this.fetch(
|
|
348
|
+
`/api/v1/orgs/${orgId}/subscription`,
|
|
349
|
+
SubscribeResultSchema,
|
|
350
|
+
{
|
|
351
|
+
method: "POST",
|
|
352
|
+
headers: {
|
|
353
|
+
"Content-Type": "application/json"
|
|
354
|
+
},
|
|
355
|
+
body: JSON.stringify(body)
|
|
356
|
+
}
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
async createPortalSession(orgId, body) {
|
|
360
|
+
return await this.fetch(
|
|
361
|
+
`/api/v1/orgs/${orgId}/subscription/portal`,
|
|
362
|
+
CustomerPortalSchema,
|
|
363
|
+
{
|
|
364
|
+
method: "POST",
|
|
365
|
+
headers: {
|
|
366
|
+
"Content-Type": "application/json"
|
|
367
|
+
},
|
|
368
|
+
body: JSON.stringify(body)
|
|
369
|
+
}
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
async fetch(path, schema, requestInit) {
|
|
373
|
+
const response = await fetch(`${this.config.url}${path}`, {
|
|
374
|
+
...requestInit,
|
|
375
|
+
headers: {
|
|
376
|
+
...requestInit == null ? void 0 : requestInit.headers,
|
|
377
|
+
Authorization: `Bearer ${this.config.apiKey}`
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
if (!response.ok) {
|
|
381
|
+
const json2 = await response.json();
|
|
382
|
+
const parsedError = ErrorSchema.parse(json2);
|
|
383
|
+
return {
|
|
384
|
+
success: false,
|
|
385
|
+
error: parsedError.error
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
const json = await response.json();
|
|
389
|
+
const parsed = schema.parse(json);
|
|
390
|
+
return {
|
|
391
|
+
success: true,
|
|
392
|
+
...parsed
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
397
|
+
0 && (module.exports = {
|
|
398
|
+
ActiveSubscriptionSchema,
|
|
399
|
+
BillingClient,
|
|
400
|
+
BracketSchema,
|
|
401
|
+
CurrentPlanSchema,
|
|
402
|
+
CustomerPortalRequestBodySchema,
|
|
403
|
+
CustomerPortalSchema,
|
|
404
|
+
ErrorSchema,
|
|
405
|
+
PlanDefinitionSchema,
|
|
406
|
+
PlanSchema,
|
|
407
|
+
PlansSchema,
|
|
408
|
+
PricedMetricSchema,
|
|
409
|
+
RunPricingSchema,
|
|
410
|
+
SetPlanBodySchema,
|
|
411
|
+
SubscribeResultSchema,
|
|
412
|
+
estimate
|
|
413
|
+
});
|
|
414
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/v2/index.ts","../../src/v2/schemas/planDefinitions.ts","../../src/v2/schemas/pricing.ts","../../src/v2/schemas/usage.ts","../../src/v2/schemas/plans.ts","../../src/v2/schemas/subscribe.ts","../../src/v2/schemas/portal.ts","../../src/v2/schemas/error.ts","../../src/v2/cost.ts","../../src/v2/estimate.ts","../../src/v2/client/index.ts"],"sourcesContent":["export * from \"./schemas\";\nexport * from \"./estimate\";\nexport * from \"./client\";\n","import { z } from \"zod\";\n\nexport const BracketSchema = z.object({\n code: z.string(),\n upto: z.number(),\n tierCost: z.number(),\n});\n\nexport const PlanDefinitionSchema = z.object({\n title: z.string(),\n code: z.string(),\n concurrentRuns: z\n .object({\n pricing: z\n .object({\n tiers: z.array(BracketSchema),\n })\n .optional(),\n freeAllowance: z.number().optional(),\n })\n .optional(),\n runs: z\n .object({\n pricing: z\n .object({\n code: z.string(),\n })\n .optional(),\n freeAllowance: z.number().optional(),\n })\n .optional(),\n});\n\nexport type PlanDefinition = z.infer<typeof PlanDefinitionSchema>;\n","import { z } from \"zod\";\n\nconst GraduatedPriceSchema = z.object({\n type: z.literal(\"graduated\"),\n brackets: z.array(\n z.object({\n upto: z.number().optional(),\n flatCost: z.number(),\n perUnitCost: z.number(),\n })\n ),\n});\n\nconst VolumePriceSchema = z.object({\n type: z.literal(\"volume\"),\n brackets: z.array(\n z.object({\n upto: z.number().optional(),\n flatCost: z.number(),\n perUnitCost: z.number(),\n })\n ),\n});\n\nconst FixedPriceSchema = z.object({\n type: z.literal(\"fixed\"),\n cost: z.number(),\n});\n\nexport const PricedMetricSchema = z.discriminatedUnion(\"type\", [\n FixedPriceSchema,\n GraduatedPriceSchema,\n VolumePriceSchema,\n]);\n\nexport type PricedMetric = z.infer<typeof PricedMetricSchema>;\n","import { z } from \"zod\";\n\nconst RunPricingSchema = z.object({\n pricing: z\n .object({\n code: z.string(),\n })\n .optional(),\n freeAllowance: z.number().optional(),\n});\n\nexport const ActiveSubscriptionSchema = z.object({\n isPaying: z.boolean(),\n plan: z.object({\n title: z.string(),\n code: z.string(),\n concurrentRuns: z.object({\n pricing: z\n .object({\n code: z.string(),\n upto: z.number().optional(),\n tierCost: z.number().optional(),\n })\n .optional(),\n freeAllowance: z.number().optional(),\n }),\n runs: RunPricingSchema.optional(),\n }),\n limits: z.object({\n runs: z.number().optional(),\n concurrentRuns: z.number().optional(),\n }),\n canceledAt: z.string().optional(),\n});\n\nexport type ActiveSubscription = z.infer<typeof ActiveSubscriptionSchema>;\n\nexport const CurrentPlanSchema = z.object({\n subscription: ActiveSubscriptionSchema.optional(),\n});\n\nexport type CurrentPlan = z.infer<typeof CurrentPlanSchema>;\n\nconst SetPaidPlanBodySchema = z.object({\n type: z.literal(\"paid\"),\n planCode: z.string(),\n concurrentRunBracket: z.string(),\n});\n\nconst SetFreePlanBodySchema = z.object({\n type: z.literal(\"free\"),\n});\n\nexport const SetPlanBodySchema = z.discriminatedUnion(\"type\", [\n SetPaidPlanBodySchema,\n SetFreePlanBodySchema,\n]);\n\nexport type SetPlanBody = z.infer<typeof SetPlanBodySchema>;\n","import { z } from \"zod\";\n\nconst RunPriceBracketSchema = z.object({\n upto: z.number().optional(),\n unitCost: z.number(),\n});\n\nexport type RunPriceBracket = z.infer<typeof RunPriceBracketSchema>;\n\nexport const RunPricingSchema = z.object({\n pricing: z\n .object({\n code: z.string(),\n brackets: z.array(RunPriceBracketSchema),\n })\n .optional(),\n freeAllowance: z.number().optional(),\n});\n\nexport const PlanSchema = z.object({\n title: z.string(),\n code: z.string(),\n concurrentRuns: z\n .object({\n pricing: z\n .object({\n tiers: z.array(\n z.object({\n code: z.string(),\n upto: z.number(),\n tierCost: z.number(),\n })\n ),\n })\n .optional(),\n freeAllowance: z.number().optional(),\n })\n .optional(),\n runs: RunPricingSchema.optional(),\n});\n\nexport type Plan = z.infer<typeof PlanSchema>;\n\nexport const PlansSchema = z.object({\n free: PlanSchema,\n paid: PlanSchema,\n enterprise: PlanSchema,\n});\n\nexport type Plans = z.infer<typeof PlansSchema>;\n","import { z } from \"zod\";\n\nconst UpdatedSubscriptionResultSchema = z.object({\n action: z.literal(\"updated_subscription\"),\n subscription: z.object({\n planCode: z.string(),\n concurrentRunBracket: z.string(),\n }),\n});\n\nexport type UpdatedSubscriptionResult = z.infer<\n typeof UpdatedSubscriptionResultSchema\n>;\n\nconst CreateSubscriptionFlowStartSchema = z.object({\n action: z.literal(\"create_subscription_flow_start\"),\n subscription: z.object({\n planCode: z.string(),\n concurrentRunBracket: z.string(),\n }),\n checkoutUrl: z.string().url(),\n});\n\nexport type CreateSubscriptionFlowStart = z.infer<\n typeof CreateSubscriptionFlowStartSchema\n>;\n\nconst CanceledSubscriptionResultSchema = z.object({\n action: z.literal(\"canceled_subscription\"),\n});\n\nexport type CanceledSubscriptionResult = z.infer<\n typeof CanceledSubscriptionResultSchema\n>;\n\nexport const SubscribeResultSchema = z.discriminatedUnion(\"action\", [\n CreateSubscriptionFlowStartSchema,\n UpdatedSubscriptionResultSchema,\n CanceledSubscriptionResultSchema,\n]);\n\nexport type SubscribeResult = z.infer<typeof SubscribeResultSchema>;\n","import { z } from \"zod\";\n\nexport const CustomerPortalRequestBodySchema = z.object({\n returnUrl: z.string(),\n});\n\nexport type CustomerPortalRequestBody = z.infer<\n typeof CustomerPortalRequestBodySchema\n>;\n\nexport const CustomerPortalSchema = z.object({\n customerPortalUrl: z.string().optional(),\n});\n\nexport type CustomerPortal = z.infer<typeof CustomerPortalSchema>;\n","import { z } from \"zod\";\n\nexport const ErrorSchema = z.object({\n error: z.string(),\n});\n\nexport type Error = z.infer<typeof ErrorSchema>;\n","import { Plan } from \"./schemas\";\nimport { PricedMetric } from \"./schemas/pricing\";\n\nexport type PlanCostResult = {\n runsCost: number;\n concurrentRunCost: number;\n total: number;\n};\n\nexport function planCost({\n usage,\n plan,\n}: {\n usage: Record<string, number>;\n plan: Plan;\n}): PlanCostResult | undefined {\n if (plan.concurrentRuns === undefined && plan.runs === undefined) {\n return undefined;\n }\n\n let concurrentRunCost = 0;\n if (plan.concurrentRuns !== undefined) {\n const concurrentUsage = usage[\"concurrent_runs\"] ?? 0;\n\n //if over the free allowance, return undefined because we can't use this plan\n if (plan.concurrentRuns.freeAllowance !== undefined) {\n if (concurrentUsage > plan.concurrentRuns.freeAllowance) {\n return undefined;\n }\n }\n\n const result = calculateVolumeCost({\n usage: concurrentUsage,\n pricedMetric: {\n type: \"volume\",\n brackets:\n plan.concurrentRuns.pricing?.tiers.map((b) => ({\n upto: b.upto ?? 0,\n flatCost: b.tierCost,\n perUnitCost: 0,\n })) ?? [],\n },\n });\n concurrentRunCost += result ?? 0;\n }\n\n let runsCost = 0;\n if (plan.runs !== undefined) {\n const runUsage = usage[\"runs\"] ?? 0;\n\n //if over the free allowance, return undefined because we can't use this plan\n if (plan.runs.freeAllowance !== undefined) {\n if (runUsage > plan.runs.freeAllowance) {\n return undefined;\n }\n }\n\n const result = calculateGraduatedCost({\n usage: runUsage,\n pricedMetric: {\n type: \"graduated\",\n brackets:\n plan.runs.pricing?.brackets.map((b) => ({\n upto: b.upto ?? 0,\n perUnitCost: b.unitCost,\n flatCost: 0,\n })) ?? [],\n },\n });\n runsCost += result?.total ?? 0;\n }\n\n return {\n runsCost,\n concurrentRunCost,\n total: runsCost + concurrentRunCost,\n };\n}\n\nexport function calculatePricedMetricCost({\n usage,\n pricedMetric,\n}: {\n usage: number;\n pricedMetric: PricedMetric;\n}): number | undefined {\n switch (pricedMetric.type) {\n case \"fixed\":\n return pricedMetric.cost;\n case \"graduated\":\n return calculateGraduatedCost({ usage, pricedMetric })?.total;\n case \"volume\":\n return calculateVolumeCost({ usage, pricedMetric });\n }\n}\n\ntype GraduatedResult = {\n brackets: {\n from: number;\n to?: number;\n amount: number;\n cost: number;\n }[];\n total: number;\n};\n\nexport function calculateGraduatedCost({\n usage,\n pricedMetric,\n}: {\n usage: number;\n pricedMetric: PricedMetric & { type: \"graduated\" };\n}): GraduatedResult | undefined {\n if (pricedMetric.brackets.length === 0) {\n return undefined;\n }\n\n const result: GraduatedResult = { brackets: [], total: 0 };\n\n //each bracket has a price and a range. The cumulative cost is the sum of each bracket costs.\n //You should only add the cost based on the usage that falls within the range of that bracket.\n for (let index = 0; index < pricedMetric.brackets.length; index++) {\n const bracket = pricedMetric.brackets[index];\n const previousBracket = pricedMetric.brackets[index - 1];\n const from = previousBracket?.upto ?? 0;\n\n if (usage >= from) {\n const usageAboveBracket = Math.max(usage - from, 0);\n let usageInsideBracket = usageAboveBracket;\n if (bracket.upto) {\n usageInsideBracket = Math.min(usageAboveBracket, bracket.upto - from);\n }\n const bracketCost =\n bracket.flatCost + bracket.perUnitCost * usageInsideBracket;\n\n result.brackets.push({\n from: from,\n to: bracket.upto,\n amount: usageInsideBracket,\n cost: bracketCost,\n });\n result.total += bracketCost;\n }\n }\n return result;\n}\n\nexport function calculateVolumeCost({\n usage,\n pricedMetric,\n}: {\n usage: number;\n pricedMetric: PricedMetric & { type: \"volume\" };\n}): number | undefined {\n for (let index = 0; index < pricedMetric.brackets.length; index++) {\n const bracket = pricedMetric.brackets[index];\n const previousBracket = pricedMetric.brackets[index - 1];\n const from = previousBracket?.upto ?? 0;\n\n if (\n usage >= from &&\n (bracket.upto === undefined || usage <= bracket.upto)\n ) {\n return bracket.flatCost + bracket.perUnitCost * usage;\n }\n }\n}\n","import { PlanCostResult, planCost } from \"./cost\";\nimport { Plan } from \"./schemas\";\n\ntype EstimateResult = { plan: { code: string }; cost: PlanCostResult };\n\nexport function estimate({\n usage,\n plans,\n}: {\n usage: Record<string, number>;\n plans: Plan[];\n}): EstimateResult | undefined {\n let result: EstimateResult | undefined;\n for (const plan of plans) {\n const cost = planCost({ usage, plan });\n if (\n cost !== undefined &&\n (result === undefined || cost.total < result.cost.total)\n ) {\n result = { plan: { code: plan.code }, cost };\n }\n }\n\n return result;\n}\n","import { ZodType, z } from \"zod\";\nimport {\n CurrentPlanSchema,\n CustomerPortalRequestBody,\n CustomerPortalSchema,\n ErrorSchema,\n PlansSchema,\n SetPlanBody,\n SubscribeResultSchema,\n} from \"../schemas\";\n\ntype BillingClientConfig = {\n url: string;\n apiKey: string;\n};\n\ntype SuccessResult<TSchema extends ZodType> = {\n success: true;\n} & z.infer<TSchema>;\n\ntype ErrorResult = {\n success: false;\n error: string;\n};\n\ntype Result<TSchema extends ZodType> = SuccessResult<TSchema> | ErrorResult;\n\nexport type PlansResponse = Result<typeof PlansSchema>;\nexport type CurrentPlanResponse = Result<typeof CurrentPlanSchema>;\nexport type SetPlanResponse = Result<typeof SubscribeResultSchema>;\nexport type CustomerPortalResponse = Result<typeof CustomerPortalSchema>;\n\nexport class BillingClient {\n constructor(private readonly config: BillingClientConfig) {}\n\n async plans(): Promise<PlansResponse> {\n return await this.fetch(`/api/v1/plans`, PlansSchema);\n }\n\n async currentPlan(orgId: string): Promise<CurrentPlanResponse> {\n return await this.fetch(`/api/v1/orgs/${orgId}`, CurrentPlanSchema);\n }\n\n async setPlan(orgId: string, body: SetPlanBody): Promise<SetPlanResponse> {\n return await this.fetch(\n `/api/v1/orgs/${orgId}/subscription`,\n SubscribeResultSchema,\n {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(body),\n }\n );\n }\n\n async createPortalSession(\n orgId: string,\n body: CustomerPortalRequestBody\n ): Promise<CustomerPortalResponse> {\n return await this.fetch(\n `/api/v1/orgs/${orgId}/subscription/portal`,\n CustomerPortalSchema,\n {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(body),\n }\n );\n }\n\n async fetch<TSchema extends ZodType = z.ZodTypeAny>(\n path: string,\n schema: TSchema,\n requestInit?: RequestInit\n ): Promise<Result<TSchema>> {\n const response = await fetch(`${this.config.url}${path}`, {\n ...requestInit,\n headers: {\n ...requestInit?.headers,\n Authorization: `Bearer ${this.config.apiKey}`,\n },\n });\n\n if (!response.ok) {\n const json = await response.json();\n const parsedError = ErrorSchema.parse(json);\n return {\n success: false,\n error: parsedError.error,\n };\n }\n\n const json = await response.json();\n const parsed = schema.parse(json);\n return {\n success: true,\n ...parsed,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,iBAAkB;AAEX,IAAM,gBAAgB,aAAE,OAAO;AAAA,EACpC,MAAM,aAAE,OAAO;AAAA,EACf,MAAM,aAAE,OAAO;AAAA,EACf,UAAU,aAAE,OAAO;AACrB,CAAC;AAEM,IAAM,uBAAuB,aAAE,OAAO;AAAA,EAC3C,OAAO,aAAE,OAAO;AAAA,EAChB,MAAM,aAAE,OAAO;AAAA,EACf,gBAAgB,aACb,OAAO;AAAA,IACN,SAAS,aACN,OAAO;AAAA,MACN,OAAO,aAAE,MAAM,aAAa;AAAA,IAC9B,CAAC,EACA,SAAS;AAAA,IACZ,eAAe,aAAE,OAAO,EAAE,SAAS;AAAA,EACrC,CAAC,EACA,SAAS;AAAA,EACZ,MAAM,aACH,OAAO;AAAA,IACN,SAAS,aACN,OAAO;AAAA,MACN,MAAM,aAAE,OAAO;AAAA,IACjB,CAAC,EACA,SAAS;AAAA,IACZ,eAAe,aAAE,OAA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AAG,2CAAa;AAAA,QAChB,eAAe,UAAU,KAAK,OAAO,MAAM;AAAA,MAC7C;AAAA,IACF,CAAC;AAED,QAAI,CAAC,SAAS,IAAI;AAChB,YAAMC,QAAO,MAAM,SAAS,KAAK;AACjC,YAAM,cAAc,YAAY,MAAMA,KAAI;AAC1C,aAAO;AAAA,QACL,SAAS;AAAA,QACT,OAAO,YAAY;AAAA,MACrB;AAAA,IACF;AAEA,UAAM,OAAO,MAAM,SAAS,KAAK;AACjC,UAAM,SAAS,OAAO,MAAM,IAAI;AAChC,WAAO;AAAA,MACL,SAAS;AAAA,MACT,GAAG;AAAA,IACL;AAAA,EACF;AACF;","names":["RunPricingSchema","import_zod","import_zod","import_zod","RunPricingSchema","import_zod","import_zod","import_zod","json"]}
|