@langwatch/server 3.1.0-beta.3 → 3.1.0-beta.5
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/langwatch/ee/admin/ImpersonationBanner.tsx +61 -0
- package/langwatch/ee/admin/ImpersonationSwitchBackMenuItem.tsx +30 -0
- package/langwatch/ee/admin/__tests__/ImpersonationBanner.integration.test.tsx +82 -0
- package/langwatch/ee/admin/__tests__/impersonation.service.unit.test.ts +231 -0
- package/langwatch/ee/admin/backoffice/BackofficeTable.tsx +200 -0
- package/langwatch/ee/admin/backoffice/__tests__/adminClient.unit.test.ts +147 -0
- package/langwatch/ee/admin/backoffice/__tests__/dateInputToISO.unit.test.ts +42 -0
- package/langwatch/ee/admin/backoffice/__tests__/userVisibility.unit.test.ts +174 -0
- package/langwatch/ee/admin/backoffice/adminClient.ts +114 -0
- package/langwatch/ee/admin/backoffice/resources/OrganizationFeaturesView.tsx +373 -0
- package/langwatch/ee/admin/backoffice/resources/OrganizationsView.tsx +677 -0
- package/langwatch/ee/admin/backoffice/resources/ProjectsView.tsx +647 -0
- package/langwatch/ee/admin/backoffice/resources/SubscriptionsView.tsx +628 -0
- package/langwatch/ee/admin/backoffice/resources/UsersView.tsx +556 -0
- package/langwatch/ee/admin/backoffice/useAdminResource.ts +104 -0
- package/langwatch/ee/admin/backoffice/userVisibility.ts +105 -0
- package/langwatch/ee/admin/impersonation.service.ts +170 -0
- package/langwatch/ee/admin/isAdmin.ts +9 -0
- package/langwatch/ee/admin/routes/admin.ts +531 -0
- package/langwatch/ee/admin/safeSelects.ts +64 -0
- package/langwatch/ee/billing/__tests__/customerService.unit.test.ts +183 -0
- package/langwatch/ee/billing/__tests__/growthSeatEvent.unit.test.ts +213 -0
- package/langwatch/ee/billing/__tests__/licensePurchaseHandler.unit.test.ts +250 -0
- package/langwatch/ee/billing/__tests__/notification.service.unit.test.ts +768 -0
- package/langwatch/ee/billing/__tests__/planLimits.unit.test.ts +19 -0
- package/langwatch/ee/billing/__tests__/planProvider.unit.test.ts +440 -0
- package/langwatch/ee/billing/__tests__/planTypes.unit.test.ts +32 -0
- package/langwatch/ee/billing/__tests__/pricing.unit.test.ts +54 -0
- package/langwatch/ee/billing/__tests__/seatEventSubscription.unit.test.ts +717 -0
- package/langwatch/ee/billing/__tests__/stripe.integration.test.ts +344 -0
- package/langwatch/ee/billing/__tests__/stripePrices.types.unit.test.ts +27 -0
- package/langwatch/ee/billing/__tests__/stripePricesLoader.unit.test.ts +72 -0
- package/langwatch/ee/billing/__tests__/subscription.service.unit.test.ts +730 -0
- package/langwatch/ee/billing/__tests__/subscriptionItemCalculator.unit.test.ts +176 -0
- package/langwatch/ee/billing/__tests__/usage-limit.service.unit.test.ts +706 -0
- package/langwatch/ee/billing/__tests__/usageReportingService.integration.test.ts +421 -0
- package/langwatch/ee/billing/__tests__/usageReportingService.unit.test.ts +515 -0
- package/langwatch/ee/billing/__tests__/webhookService.unit.test.ts +958 -0
- package/langwatch/ee/billing/currencyRouter.ts +18 -0
- package/langwatch/ee/billing/errors.ts +129 -0
- package/langwatch/ee/billing/index.ts +67 -0
- package/langwatch/ee/billing/middleware.ts +17 -0
- package/langwatch/ee/billing/notifications/notification.service.ts +651 -0
- package/langwatch/ee/billing/notifications/repositories/notification.repository.ts +51 -0
- package/langwatch/ee/billing/notifications/types.ts +9 -0
- package/langwatch/ee/billing/notifications/usage-limit.service.ts +622 -0
- package/langwatch/ee/billing/nurturing/hooks/activityTracking.ts +90 -0
- package/langwatch/ee/billing/nurturing/hooks/activityTracking.unit.test.ts +237 -0
- package/langwatch/ee/billing/nurturing/hooks/featureAdoption.ts +120 -0
- package/langwatch/ee/billing/nurturing/hooks/featureAdoption.unit.test.ts +324 -0
- package/langwatch/ee/billing/nurturing/hooks/index.ts +17 -0
- package/langwatch/ee/billing/nurturing/hooks/productInterest.ts +68 -0
- package/langwatch/ee/billing/nurturing/hooks/productInterest.unit.test.ts +138 -0
- package/langwatch/ee/billing/nurturing/hooks/promptCreation.integration.test.ts +288 -0
- package/langwatch/ee/billing/nurturing/hooks/promptCreation.ts +131 -0
- package/langwatch/ee/billing/nurturing/hooks/promptCreation.unit.test.ts +134 -0
- package/langwatch/ee/billing/nurturing/hooks/signupIdentification.ts +101 -0
- package/langwatch/ee/billing/nurturing/hooks/signupIdentification.unit.test.ts +317 -0
- package/langwatch/ee/billing/nurturing/hooks/subscriptionSync.ts +49 -0
- package/langwatch/ee/billing/nurturing/hooks/subscriptionSync.unit.test.ts +170 -0
- package/langwatch/ee/billing/nurturing/hooks/userSync.ts +143 -0
- package/langwatch/ee/billing/nurturing/hooks/userSync.unit.test.ts +307 -0
- package/langwatch/ee/billing/nurturing/nurturing.service.ts +179 -0
- package/langwatch/ee/billing/nurturing/nurturing.service.unit.test.ts +266 -0
- package/langwatch/ee/billing/nurturing/nurturing.service.wiring.unit.test.ts +109 -0
- package/langwatch/ee/billing/nurturing/types.ts +125 -0
- package/langwatch/ee/billing/planLimits.ts +190 -0
- package/langwatch/ee/billing/planProvider.ts +119 -0
- package/langwatch/ee/billing/planTypes.ts +53 -0
- package/langwatch/ee/billing/pricing.ts +57 -0
- package/langwatch/ee/billing/services/billableEventsQuery.ts +248 -0
- package/langwatch/ee/billing/services/customerService.ts +90 -0
- package/langwatch/ee/billing/services/licensePurchaseHandler.ts +73 -0
- package/langwatch/ee/billing/services/seatEventSubscription.ts +351 -0
- package/langwatch/ee/billing/services/seatSyncService.ts +34 -0
- package/langwatch/ee/billing/services/subscription.repository.ts +203 -0
- package/langwatch/ee/billing/services/subscription.service.ts +549 -0
- package/langwatch/ee/billing/services/subscriptionItemCalculator.ts +249 -0
- package/langwatch/ee/billing/services/usageReportingService.ts +301 -0
- package/langwatch/ee/billing/services/webhookService.ts +858 -0
- package/langwatch/ee/billing/stripe/stripeCatalog.json +1781 -0
- package/langwatch/ee/billing/stripe/stripeClient.ts +13 -0
- package/langwatch/ee/billing/stripe/stripePriceCatalog.ts +70 -0
- package/langwatch/ee/billing/stripe/stripePrices.types.ts +118 -0
- package/langwatch/ee/billing/subscriptionRouter.ts +202 -0
- package/langwatch/ee/billing/types.ts +102 -0
- package/langwatch/ee/billing/utils/currency.ts +99 -0
- package/langwatch/ee/billing/utils/growthSeatEvent.ts +137 -0
- package/langwatch/ee/licensing/__tests__/constants.unit.test.ts +56 -0
- package/langwatch/ee/licensing/__tests__/defaults.unit.test.ts +192 -0
- package/langwatch/ee/licensing/__tests__/fixtures/testKeys.ts +86 -0
- package/langwatch/ee/licensing/__tests__/fixtures/testLicenses.ts +92 -0
- package/langwatch/ee/licensing/__tests__/licenseGenerationService.unit.test.ts +232 -0
- package/langwatch/ee/licensing/__tests__/licenseHandler.integration.test.ts +419 -0
- package/langwatch/ee/licensing/__tests__/planMapping.unit.test.ts +195 -0
- package/langwatch/ee/licensing/__tests__/planTemplates.unit.test.ts +193 -0
- package/langwatch/ee/licensing/__tests__/signing.unit.test.ts +164 -0
- package/langwatch/ee/licensing/__tests__/validation.unit.test.ts +281 -0
- package/langwatch/ee/licensing/client.ts +29 -0
- package/langwatch/ee/licensing/constants.ts +195 -0
- package/langwatch/ee/licensing/defaults.ts +55 -0
- package/langwatch/ee/licensing/errors.ts +11 -0
- package/langwatch/ee/licensing/index.ts +52 -0
- package/langwatch/ee/licensing/licenseGenerationService.ts +87 -0
- package/langwatch/ee/licensing/licenseHandler.ts +308 -0
- package/langwatch/ee/licensing/planInfo.ts +46 -0
- package/langwatch/ee/licensing/planMapping.ts +37 -0
- package/langwatch/ee/licensing/planTemplates.ts +109 -0
- package/langwatch/ee/licensing/server.ts +43 -0
- package/langwatch/ee/licensing/signing.ts +43 -0
- package/langwatch/ee/licensing/types.ts +156 -0
- package/langwatch/ee/licensing/validation.ts +107 -0
- package/langwatch/ee/managed-providers/ManagedModelProviderAlert.tsx +29 -0
- package/langwatch/ee/managed-providers/managedBedrockConfig.ts +226 -0
- package/langwatch/ee/saas/ExtraFooterComponents.tsx +169 -0
- package/langwatch/package.json +1 -1
- package/langwatch_nlp/uv.lock +179 -5
- package/package.json +1 -1
- package/packages/server/dist/cli.cjs +192 -142
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import type Stripe from "stripe";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
calculateQuantityForPrice,
|
|
5
|
+
createItemsToAdd,
|
|
6
|
+
getItemsToUpdate,
|
|
7
|
+
prices,
|
|
8
|
+
} from "../services/subscriptionItemCalculator";
|
|
9
|
+
import { PlanTypes } from "../planTypes";
|
|
10
|
+
|
|
11
|
+
const createSubscriptionItem = (
|
|
12
|
+
id: string,
|
|
13
|
+
priceId: string,
|
|
14
|
+
): Stripe.SubscriptionItem =>
|
|
15
|
+
({
|
|
16
|
+
id,
|
|
17
|
+
price: { id: priceId },
|
|
18
|
+
}) as Stripe.SubscriptionItem;
|
|
19
|
+
|
|
20
|
+
describe("subscriptionItemCalculator", () => {
|
|
21
|
+
describe("getItemsToUpdate()", () => {
|
|
22
|
+
it("updates launch items and deletes stale items from other plans", () => {
|
|
23
|
+
const items = getItemsToUpdate({
|
|
24
|
+
currentItems: [
|
|
25
|
+
createSubscriptionItem("launch-base", prices.LAUNCH),
|
|
26
|
+
createSubscriptionItem("launch-users", prices.LAUNCH_USERS),
|
|
27
|
+
createSubscriptionItem("launch-traces", prices.LAUNCH_TRACES_10K),
|
|
28
|
+
createSubscriptionItem("stale-acc-users", prices.ACCELERATE_USERS),
|
|
29
|
+
],
|
|
30
|
+
plan: PlanTypes.LAUNCH,
|
|
31
|
+
tracesToAdd: 45_000,
|
|
32
|
+
membersToAdd: 8,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
expect(items).toEqual([
|
|
36
|
+
{ id: "launch-traces", quantity: 2 },
|
|
37
|
+
{ id: "launch-users", quantity: 5 },
|
|
38
|
+
{ id: "launch-base", quantity: 1 },
|
|
39
|
+
{ id: "stale-acc-users", deleted: true },
|
|
40
|
+
]);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("switches from launch to accelerate and removes launch-specific items", () => {
|
|
44
|
+
const items = getItemsToUpdate({
|
|
45
|
+
currentItems: [
|
|
46
|
+
createSubscriptionItem("launch-base", prices.LAUNCH),
|
|
47
|
+
createSubscriptionItem("launch-users", prices.LAUNCH_USERS),
|
|
48
|
+
createSubscriptionItem("launch-traces", prices.LAUNCH_TRACES_10K),
|
|
49
|
+
],
|
|
50
|
+
plan: PlanTypes.ACCELERATE,
|
|
51
|
+
tracesToAdd: 250_000,
|
|
52
|
+
membersToAdd: 9,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
expect(items).toEqual([
|
|
56
|
+
{ price: prices.ACCELERATE_TRACES_100K, quantity: 2 },
|
|
57
|
+
{ price: prices.ACCELERATE_USERS, quantity: 4 },
|
|
58
|
+
{ price: prices.ACCELERATE, quantity: 1 },
|
|
59
|
+
{ id: "launch-base", deleted: true },
|
|
60
|
+
{ id: "launch-users", deleted: true },
|
|
61
|
+
{ id: "launch-traces", deleted: true },
|
|
62
|
+
]);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("keeps PRO behavior without add-on item updates", () => {
|
|
66
|
+
const items = getItemsToUpdate({
|
|
67
|
+
currentItems: [createSubscriptionItem("pro-base", prices.PRO)],
|
|
68
|
+
plan: PlanTypes.PRO,
|
|
69
|
+
tracesToAdd: 10_000,
|
|
70
|
+
membersToAdd: 5,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
expect(items).toEqual([{ price: prices.PRO, quantity: 1 }]);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("returns empty for FREE downgrade", () => {
|
|
77
|
+
const items = getItemsToUpdate({ currentItems: [], plan: PlanTypes.FREE, tracesToAdd: 1_000, membersToAdd: 2 });
|
|
78
|
+
|
|
79
|
+
expect(items).toEqual([]);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("marks zero quantity add-ons as deleted", () => {
|
|
83
|
+
const items = getItemsToUpdate({
|
|
84
|
+
currentItems: [
|
|
85
|
+
createSubscriptionItem("launch-base", prices.LAUNCH),
|
|
86
|
+
createSubscriptionItem("launch-traces", prices.LAUNCH_TRACES_10K),
|
|
87
|
+
],
|
|
88
|
+
plan: PlanTypes.LAUNCH,
|
|
89
|
+
tracesToAdd: 20_000,
|
|
90
|
+
membersToAdd: 3,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
expect(items).toEqual([
|
|
94
|
+
{ id: "launch-traces", quantity: 0, deleted: true },
|
|
95
|
+
{ id: "launch-base", quantity: 1 },
|
|
96
|
+
]);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe("createItemsToAdd()", () => {
|
|
101
|
+
it("creates launch add-on items when usage exceeds plan limits", () => {
|
|
102
|
+
const items = createItemsToAdd(
|
|
103
|
+
PlanTypes.LAUNCH,
|
|
104
|
+
{ quantity: 40_000 },
|
|
105
|
+
{ quantity: 8 },
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
expect(items).toEqual([
|
|
109
|
+
{ price: prices.LAUNCH_USERS, quantity: 5 },
|
|
110
|
+
{ price: prices.LAUNCH_TRACES_10K, quantity: 2 },
|
|
111
|
+
]);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("creates accelerate add-on items with 100K traces buckets", () => {
|
|
115
|
+
const items = createItemsToAdd(
|
|
116
|
+
PlanTypes.ACCELERATE,
|
|
117
|
+
{ quantity: 250_000 },
|
|
118
|
+
{ quantity: 8 },
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
expect(items).toEqual([
|
|
122
|
+
{ price: prices.ACCELERATE_USERS, quantity: 3 },
|
|
123
|
+
{ price: prices.ACCELERATE_TRACES_100K, quantity: 2 },
|
|
124
|
+
]);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("returns no add-ons for plans without add-on prices", () => {
|
|
128
|
+
expect(
|
|
129
|
+
createItemsToAdd(
|
|
130
|
+
PlanTypes.GROWTH,
|
|
131
|
+
{ quantity: 200_000 },
|
|
132
|
+
{ quantity: 50 },
|
|
133
|
+
),
|
|
134
|
+
).toEqual([]);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe("calculateQuantityForPrice()", () => {
|
|
139
|
+
it("calculates quantity for user add-ons", () => {
|
|
140
|
+
expect(
|
|
141
|
+
calculateQuantityForPrice({ priceId: prices.LAUNCH_USERS, quantity: 4, plan: PlanTypes.LAUNCH }),
|
|
142
|
+
).toBe(7);
|
|
143
|
+
expect(
|
|
144
|
+
calculateQuantityForPrice({
|
|
145
|
+
priceId: prices.ACCELERATE_ANNUAL_USERS,
|
|
146
|
+
quantity: 4,
|
|
147
|
+
plan: PlanTypes.ACCELERATE_ANNUAL,
|
|
148
|
+
}),
|
|
149
|
+
).toBe(9);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("calculates quantity for 10K traces add-ons", () => {
|
|
153
|
+
expect(
|
|
154
|
+
calculateQuantityForPrice({
|
|
155
|
+
priceId: prices.LAUNCH_TRACES_10K,
|
|
156
|
+
quantity: 3,
|
|
157
|
+
plan: PlanTypes.LAUNCH,
|
|
158
|
+
}),
|
|
159
|
+
).toBe(50_000);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("calculates quantity for 100K traces add-ons", () => {
|
|
163
|
+
expect(
|
|
164
|
+
calculateQuantityForPrice({
|
|
165
|
+
priceId: prices.ACCELERATE_TRACES_100K,
|
|
166
|
+
quantity: 2,
|
|
167
|
+
plan: PlanTypes.ACCELERATE,
|
|
168
|
+
}),
|
|
169
|
+
).toBe(220_000);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("returns 0 for unknown price ids", () => {
|
|
173
|
+
expect(calculateQuantityForPrice({ priceId: "unknown", quantity: 10, plan: PlanTypes.PRO })).toBe(0);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
});
|