@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,195 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { mapToPlanInfo } from "../planMapping";
|
|
3
|
+
import { DEFAULT_LIMIT, DEFAULT_MEMBERS_LITE } from "../constants";
|
|
4
|
+
import type { LicenseData } from "../types";
|
|
5
|
+
|
|
6
|
+
describe("mapToPlanInfo", () => {
|
|
7
|
+
const createLicenseData = (
|
|
8
|
+
planOverrides: Partial<LicenseData["plan"]> = {}
|
|
9
|
+
): LicenseData => ({
|
|
10
|
+
licenseId: "lic-test-001",
|
|
11
|
+
version: 1,
|
|
12
|
+
organizationName: "Test Org",
|
|
13
|
+
email: "test@example.com",
|
|
14
|
+
issuedAt: new Date().toISOString(),
|
|
15
|
+
expiresAt: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000).toISOString(),
|
|
16
|
+
plan: {
|
|
17
|
+
type: "PRO",
|
|
18
|
+
name: "Pro",
|
|
19
|
+
maxMembers: 10,
|
|
20
|
+
maxProjects: 99,
|
|
21
|
+
maxMessagesPerMonth: 100_000,
|
|
22
|
+
evaluationsCredit: 100,
|
|
23
|
+
maxWorkflows: 50,
|
|
24
|
+
maxPrompts: 50,
|
|
25
|
+
maxEvaluators: 50,
|
|
26
|
+
maxScenarios: 50,
|
|
27
|
+
canPublish: true,
|
|
28
|
+
...planOverrides,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("maps license plan type and name correctly", () => {
|
|
33
|
+
const licenseData = createLicenseData({
|
|
34
|
+
type: "ENTERPRISE",
|
|
35
|
+
name: "Enterprise Plan",
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const result = mapToPlanInfo(licenseData);
|
|
39
|
+
|
|
40
|
+
expect(result.type).toBe("ENTERPRISE");
|
|
41
|
+
expect(result.name).toBe("Enterprise Plan");
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("maps all numeric limits correctly", () => {
|
|
45
|
+
const licenseData = createLicenseData({
|
|
46
|
+
maxMembers: 5,
|
|
47
|
+
maxProjects: 10,
|
|
48
|
+
maxMessagesPerMonth: 50000,
|
|
49
|
+
evaluationsCredit: 100,
|
|
50
|
+
maxWorkflows: 25,
|
|
51
|
+
maxPrompts: 30,
|
|
52
|
+
maxEvaluators: 35,
|
|
53
|
+
maxScenarios: 40,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const result = mapToPlanInfo(licenseData);
|
|
57
|
+
|
|
58
|
+
expect(result.maxMembers).toBe(5);
|
|
59
|
+
expect(result.maxProjects).toBe(10);
|
|
60
|
+
expect(result.maxMessagesPerMonth).toBe(50000);
|
|
61
|
+
expect(result.maxWorkflows).toBe(25);
|
|
62
|
+
expect(result.maxPrompts).toBe(30);
|
|
63
|
+
expect(result.maxEvaluators).toBe(35);
|
|
64
|
+
expect(result.maxScenarios).toBe(40);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("maps canPublish flag correctly when true", () => {
|
|
68
|
+
const licenseData = createLicenseData({ canPublish: true });
|
|
69
|
+
|
|
70
|
+
const result = mapToPlanInfo(licenseData);
|
|
71
|
+
|
|
72
|
+
expect(result.canPublish).toBe(true);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("maps canPublish flag correctly when false", () => {
|
|
76
|
+
const licenseData = createLicenseData({ canPublish: false });
|
|
77
|
+
|
|
78
|
+
const result = mapToPlanInfo(licenseData);
|
|
79
|
+
|
|
80
|
+
expect(result.canPublish).toBe(false);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("sets free flag to false for licensed plans", () => {
|
|
84
|
+
const licenseData = createLicenseData();
|
|
85
|
+
|
|
86
|
+
const result = mapToPlanInfo(licenseData);
|
|
87
|
+
|
|
88
|
+
expect(result.free).toBe(false);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("sets overrideAddingLimitations to false", () => {
|
|
92
|
+
const licenseData = createLicenseData();
|
|
93
|
+
|
|
94
|
+
const result = mapToPlanInfo(licenseData);
|
|
95
|
+
|
|
96
|
+
expect(result.overrideAddingLimitations).toBe(false);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("sets prices to zero for self-hosted", () => {
|
|
100
|
+
const licenseData = createLicenseData();
|
|
101
|
+
|
|
102
|
+
const result = mapToPlanInfo(licenseData);
|
|
103
|
+
|
|
104
|
+
expect(result.prices).toEqual({ USD: 0, EUR: 0 });
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("maps maxMembersLite when provided", () => {
|
|
108
|
+
const licenseData = createLicenseData({ maxMembersLite: 10 });
|
|
109
|
+
|
|
110
|
+
const result = mapToPlanInfo(licenseData);
|
|
111
|
+
|
|
112
|
+
expect(result.maxMembersLite).toBe(10);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("defaults maxMembersLite to 1 when not provided", () => {
|
|
116
|
+
const licenseData = createLicenseData();
|
|
117
|
+
|
|
118
|
+
const result = mapToPlanInfo(licenseData);
|
|
119
|
+
|
|
120
|
+
expect(result.maxMembersLite).toBe(DEFAULT_MEMBERS_LITE);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("uses DEFAULT_LIMIT for optional fields not in older licenses", () => {
|
|
124
|
+
// Simulate an older license that doesn't have the new optional fields
|
|
125
|
+
const oldLicenseData: LicenseData = {
|
|
126
|
+
licenseId: "lic-old-001",
|
|
127
|
+
version: 1,
|
|
128
|
+
organizationName: "Legacy Org",
|
|
129
|
+
email: "legacy@example.com",
|
|
130
|
+
issuedAt: new Date().toISOString(),
|
|
131
|
+
expiresAt: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000).toISOString(),
|
|
132
|
+
plan: {
|
|
133
|
+
type: "PRO",
|
|
134
|
+
name: "Pro",
|
|
135
|
+
maxMembers: 10,
|
|
136
|
+
maxProjects: 99,
|
|
137
|
+
maxMessagesPerMonth: 100_000,
|
|
138
|
+
evaluationsCredit: 100,
|
|
139
|
+
maxWorkflows: 50,
|
|
140
|
+
canPublish: true,
|
|
141
|
+
// Note: maxPrompts, maxEvaluators, maxScenarios, maxMembersLite are NOT provided
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const result = mapToPlanInfo(oldLicenseData);
|
|
146
|
+
|
|
147
|
+
// Should use DEFAULT_LIMIT for missing optional fields
|
|
148
|
+
expect(result.maxPrompts).toBe(DEFAULT_LIMIT);
|
|
149
|
+
expect(result.maxEvaluators).toBe(DEFAULT_LIMIT);
|
|
150
|
+
expect(result.maxScenarios).toBe(DEFAULT_LIMIT);
|
|
151
|
+
expect(result.maxMembersLite).toBe(DEFAULT_MEMBERS_LITE);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("maps usageUnit from license data", () => {
|
|
155
|
+
const licenseData = createLicenseData({ usageUnit: "events" });
|
|
156
|
+
|
|
157
|
+
const result = mapToPlanInfo(licenseData);
|
|
158
|
+
|
|
159
|
+
expect(result.usageUnit).toBe("events");
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("defaults usageUnit to traces for legacy licenses", () => {
|
|
163
|
+
const oldLicenseData: LicenseData = {
|
|
164
|
+
licenseId: "lic-old-002",
|
|
165
|
+
version: 1,
|
|
166
|
+
organizationName: "Legacy Org",
|
|
167
|
+
email: "legacy@example.com",
|
|
168
|
+
issuedAt: new Date().toISOString(),
|
|
169
|
+
expiresAt: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000).toISOString(),
|
|
170
|
+
plan: {
|
|
171
|
+
type: "PRO",
|
|
172
|
+
name: "Pro",
|
|
173
|
+
maxMembers: 10,
|
|
174
|
+
maxProjects: 99,
|
|
175
|
+
maxMessagesPerMonth: 100_000,
|
|
176
|
+
evaluationsCredit: 100,
|
|
177
|
+
maxWorkflows: 50,
|
|
178
|
+
canPublish: true,
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
const result = mapToPlanInfo(oldLicenseData);
|
|
183
|
+
|
|
184
|
+
expect(result.usageUnit).toBe("traces");
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it("uses DEFAULT_LIMIT which is JSON-serializable", () => {
|
|
188
|
+
// Ensure DEFAULT_LIMIT can be serialized (not Infinity)
|
|
189
|
+
const serialized = JSON.stringify({ limit: DEFAULT_LIMIT });
|
|
190
|
+
const parsed = JSON.parse(serialized);
|
|
191
|
+
|
|
192
|
+
expect(parsed.limit).toBe(DEFAULT_LIMIT);
|
|
193
|
+
expect(Number.isFinite(DEFAULT_LIMIT)).toBe(true);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { GROWTH_TEMPLATE, PRO_TEMPLATE, ENTERPRISE_TEMPLATE, getPlanTemplate } from "../planTemplates";
|
|
3
|
+
import { DEFAULT_LIMIT } from "../constants";
|
|
4
|
+
|
|
5
|
+
describe("PRO_TEMPLATE", () => {
|
|
6
|
+
it("has type PRO", () => {
|
|
7
|
+
expect(PRO_TEMPLATE.type).toBe("PRO");
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("has name Pro", () => {
|
|
11
|
+
expect(PRO_TEMPLATE.name).toBe("Pro");
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("has maxMembers of 10", () => {
|
|
15
|
+
expect(PRO_TEMPLATE.maxMembers).toBe(10);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("has maxProjects of 20", () => {
|
|
19
|
+
expect(PRO_TEMPLATE.maxProjects).toBe(20);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("has maxMessagesPerMonth of 100000", () => {
|
|
23
|
+
expect(PRO_TEMPLATE.maxMessagesPerMonth).toBe(100000);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("has maxWorkflows of 50", () => {
|
|
27
|
+
expect(PRO_TEMPLATE.maxWorkflows).toBe(50);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("has maxPrompts of 50", () => {
|
|
31
|
+
expect(PRO_TEMPLATE.maxPrompts).toBe(50);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("has maxEvaluators of 50", () => {
|
|
35
|
+
expect(PRO_TEMPLATE.maxEvaluators).toBe(50);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("has maxScenarios of 50", () => {
|
|
39
|
+
expect(PRO_TEMPLATE.maxScenarios).toBe(50);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("has maxOnlineEvaluations of 50", () => {
|
|
43
|
+
expect(PRO_TEMPLATE.maxOnlineEvaluations).toBe(50);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("has canPublish true", () => {
|
|
47
|
+
expect(PRO_TEMPLATE.canPublish).toBe(true);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("has usageUnit of traces", () => {
|
|
51
|
+
expect(PRO_TEMPLATE.usageUnit).toBe("traces");
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe("ENTERPRISE_TEMPLATE", () => {
|
|
56
|
+
it("has type ENTERPRISE", () => {
|
|
57
|
+
expect(ENTERPRISE_TEMPLATE.type).toBe("ENTERPRISE");
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("has name Enterprise", () => {
|
|
61
|
+
expect(ENTERPRISE_TEMPLATE.name).toBe("Enterprise");
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("has maxMembers of 100", () => {
|
|
65
|
+
expect(ENTERPRISE_TEMPLATE.maxMembers).toBe(100);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("has maxProjects of 500", () => {
|
|
69
|
+
expect(ENTERPRISE_TEMPLATE.maxProjects).toBe(500);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("has maxMessagesPerMonth of 10000000", () => {
|
|
73
|
+
expect(ENTERPRISE_TEMPLATE.maxMessagesPerMonth).toBe(10000000);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("has maxWorkflows of 1000", () => {
|
|
77
|
+
expect(ENTERPRISE_TEMPLATE.maxWorkflows).toBe(1000);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("has maxPrompts of 1000", () => {
|
|
81
|
+
expect(ENTERPRISE_TEMPLATE.maxPrompts).toBe(1000);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("has maxEvaluators of 1000", () => {
|
|
85
|
+
expect(ENTERPRISE_TEMPLATE.maxEvaluators).toBe(1000);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("has maxScenarios of 1000", () => {
|
|
89
|
+
expect(ENTERPRISE_TEMPLATE.maxScenarios).toBe(1000);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("has maxOnlineEvaluations of 1000", () => {
|
|
93
|
+
expect(ENTERPRISE_TEMPLATE.maxOnlineEvaluations).toBe(1000);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("has canPublish true", () => {
|
|
97
|
+
expect(ENTERPRISE_TEMPLATE.canPublish).toBe(true);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("has usageUnit of traces", () => {
|
|
101
|
+
expect(ENTERPRISE_TEMPLATE.usageUnit).toBe("traces");
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe("GROWTH_TEMPLATE", () => {
|
|
106
|
+
describe("when inspecting plan identity", () => {
|
|
107
|
+
it("has type GROWTH", () => {
|
|
108
|
+
expect(GROWTH_TEMPLATE.type).toBe("GROWTH");
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("has name Growth", () => {
|
|
112
|
+
expect(GROWTH_TEMPLATE.name).toBe("Growth");
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
describe("when inspecting member limits", () => {
|
|
117
|
+
it("does not preset maxMembers", () => {
|
|
118
|
+
expect(GROWTH_TEMPLATE).not.toHaveProperty("maxMembers");
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
describe("when inspecting feature limits", () => {
|
|
123
|
+
it("sets all other limits to unlimited (DEFAULT_LIMIT)", () => {
|
|
124
|
+
const unlimitedFields = [
|
|
125
|
+
"maxMembersLite",
|
|
126
|
+
"maxTeams",
|
|
127
|
+
"maxProjects",
|
|
128
|
+
"maxMessagesPerMonth",
|
|
129
|
+
"maxWorkflows",
|
|
130
|
+
"maxPrompts",
|
|
131
|
+
"maxEvaluators",
|
|
132
|
+
"maxScenarios",
|
|
133
|
+
"maxAgents",
|
|
134
|
+
"maxExperiments",
|
|
135
|
+
"maxOnlineEvaluations",
|
|
136
|
+
"maxDatasets",
|
|
137
|
+
"maxDashboards",
|
|
138
|
+
"maxCustomGraphs",
|
|
139
|
+
"maxAutomations",
|
|
140
|
+
] as const;
|
|
141
|
+
|
|
142
|
+
for (const field of unlimitedFields) {
|
|
143
|
+
expect(GROWTH_TEMPLATE[field], `${field} is not DEFAULT_LIMIT`).toBe(
|
|
144
|
+
DEFAULT_LIMIT
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("has canPublish true", () => {
|
|
150
|
+
expect(GROWTH_TEMPLATE.canPublish).toBe(true);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("has usageUnit of events", () => {
|
|
154
|
+
expect(GROWTH_TEMPLATE.usageUnit).toBe("events");
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
describe("getPlanTemplate", () => {
|
|
160
|
+
describe("when called with a known plan type", () => {
|
|
161
|
+
it("returns GROWTH template for GROWTH type", () => {
|
|
162
|
+
const template = getPlanTemplate("GROWTH");
|
|
163
|
+
|
|
164
|
+
expect(template).toEqual(GROWTH_TEMPLATE);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("returns PRO template for PRO type", () => {
|
|
168
|
+
const template = getPlanTemplate("PRO");
|
|
169
|
+
|
|
170
|
+
expect(template).toEqual(PRO_TEMPLATE);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it("returns ENTERPRISE template for ENTERPRISE type", () => {
|
|
174
|
+
const template = getPlanTemplate("ENTERPRISE");
|
|
175
|
+
|
|
176
|
+
expect(template).toEqual(ENTERPRISE_TEMPLATE);
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
describe("when called with an unknown plan type", () => {
|
|
181
|
+
it("returns null for CUSTOM type", () => {
|
|
182
|
+
const template = getPlanTemplate("CUSTOM");
|
|
183
|
+
|
|
184
|
+
expect(template).toBeNull();
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it("returns null for unknown plan type", () => {
|
|
188
|
+
const template = getPlanTemplate("UNKNOWN");
|
|
189
|
+
|
|
190
|
+
expect(template).toBeNull();
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
});
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
signLicense,
|
|
4
|
+
encodeLicenseKey,
|
|
5
|
+
generateLicenseId,
|
|
6
|
+
} from "../signing";
|
|
7
|
+
import { parseLicenseKey, verifySignature } from "../validation";
|
|
8
|
+
import { TEST_PRIVATE_KEY, TEST_PUBLIC_KEY } from "./fixtures/testKeys";
|
|
9
|
+
import type { LicenseData } from "../types";
|
|
10
|
+
|
|
11
|
+
const createTestLicenseData = (overrides: Partial<LicenseData> = {}): LicenseData => ({
|
|
12
|
+
licenseId: "test-lic-001",
|
|
13
|
+
version: 1,
|
|
14
|
+
organizationName: "Test Org",
|
|
15
|
+
email: "test@test.com",
|
|
16
|
+
issuedAt: "2024-01-01T00:00:00Z",
|
|
17
|
+
expiresAt: "2030-12-31T23:59:59Z",
|
|
18
|
+
plan: {
|
|
19
|
+
type: "PRO",
|
|
20
|
+
name: "Pro",
|
|
21
|
+
maxMembers: 10,
|
|
22
|
+
maxProjects: 20,
|
|
23
|
+
maxMessagesPerMonth: 100000,
|
|
24
|
+
evaluationsCredit: 500,
|
|
25
|
+
maxWorkflows: 50,
|
|
26
|
+
maxPrompts: 50,
|
|
27
|
+
maxEvaluators: 50,
|
|
28
|
+
maxScenarios: 50,
|
|
29
|
+
canPublish: true,
|
|
30
|
+
},
|
|
31
|
+
...overrides,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe("signLicense", () => {
|
|
35
|
+
it("creates RSA-SHA256 signature from license data", () => {
|
|
36
|
+
const licenseData = createTestLicenseData();
|
|
37
|
+
|
|
38
|
+
const signedLicense = signLicense(licenseData, TEST_PRIVATE_KEY);
|
|
39
|
+
|
|
40
|
+
expect(signedLicense.data).toEqual(licenseData);
|
|
41
|
+
expect(signedLicense.signature).toBeDefined();
|
|
42
|
+
expect(typeof signedLicense.signature).toBe("string");
|
|
43
|
+
expect(signedLicense.signature.length).toBeGreaterThan(0);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("produces valid signature that can be verified with public key", () => {
|
|
47
|
+
const licenseData = createTestLicenseData();
|
|
48
|
+
|
|
49
|
+
const signedLicense = signLicense(licenseData, TEST_PRIVATE_KEY);
|
|
50
|
+
const isValid = verifySignature(signedLicense, TEST_PUBLIC_KEY);
|
|
51
|
+
|
|
52
|
+
expect(isValid).toBe(true);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("produces different signatures for different license data", () => {
|
|
56
|
+
const licenseData1 = createTestLicenseData({ organizationName: "Org A" });
|
|
57
|
+
const licenseData2 = createTestLicenseData({ organizationName: "Org B" });
|
|
58
|
+
|
|
59
|
+
const signed1 = signLicense(licenseData1, TEST_PRIVATE_KEY);
|
|
60
|
+
const signed2 = signLicense(licenseData2, TEST_PRIVATE_KEY);
|
|
61
|
+
|
|
62
|
+
expect(signed1.signature).not.toBe(signed2.signature);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("produces consistent signatures for same license data", () => {
|
|
66
|
+
const licenseData = createTestLicenseData();
|
|
67
|
+
|
|
68
|
+
const signed1 = signLicense(licenseData, TEST_PRIVATE_KEY);
|
|
69
|
+
const signed2 = signLicense(licenseData, TEST_PRIVATE_KEY);
|
|
70
|
+
|
|
71
|
+
expect(signed1.signature).toBe(signed2.signature);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("throws error for invalid private key", () => {
|
|
75
|
+
const licenseData = createTestLicenseData();
|
|
76
|
+
const invalidKey = "not-a-valid-key";
|
|
77
|
+
|
|
78
|
+
expect(() => signLicense(licenseData, invalidKey)).toThrow();
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe("encodeLicenseKey", () => {
|
|
83
|
+
it("produces valid base64 string", () => {
|
|
84
|
+
const licenseData = createTestLicenseData();
|
|
85
|
+
const signedLicense = signLicense(licenseData, TEST_PRIVATE_KEY);
|
|
86
|
+
|
|
87
|
+
const encodedKey = encodeLicenseKey(signedLicense);
|
|
88
|
+
|
|
89
|
+
expect(typeof encodedKey).toBe("string");
|
|
90
|
+
// Valid base64 should only contain alphanumeric, +, /, and =
|
|
91
|
+
expect(encodedKey).toMatch(/^[A-Za-z0-9+/=]+$/);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("produces decodable JSON with data and signature fields", () => {
|
|
95
|
+
const licenseData = createTestLicenseData();
|
|
96
|
+
const signedLicense = signLicense(licenseData, TEST_PRIVATE_KEY);
|
|
97
|
+
|
|
98
|
+
const encodedKey = encodeLicenseKey(signedLicense);
|
|
99
|
+
const decoded = Buffer.from(encodedKey, "base64").toString("utf-8");
|
|
100
|
+
const parsed = JSON.parse(decoded);
|
|
101
|
+
|
|
102
|
+
expect(parsed).toHaveProperty("data");
|
|
103
|
+
expect(parsed).toHaveProperty("signature");
|
|
104
|
+
expect(parsed.data).toEqual(licenseData);
|
|
105
|
+
expect(parsed.signature).toBe(signedLicense.signature);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("produces key that can be parsed by parseLicenseKey", () => {
|
|
109
|
+
const licenseData = createTestLicenseData();
|
|
110
|
+
const signedLicense = signLicense(licenseData, TEST_PRIVATE_KEY);
|
|
111
|
+
|
|
112
|
+
const encodedKey = encodeLicenseKey(signedLicense);
|
|
113
|
+
const parsedLicense = parseLicenseKey(encodedKey);
|
|
114
|
+
|
|
115
|
+
expect(parsedLicense).not.toBeNull();
|
|
116
|
+
expect(parsedLicense?.data).toEqual(licenseData);
|
|
117
|
+
expect(parsedLicense?.signature).toBe(signedLicense.signature);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("produces key that validates successfully", () => {
|
|
121
|
+
const licenseData = createTestLicenseData();
|
|
122
|
+
const signedLicense = signLicense(licenseData, TEST_PRIVATE_KEY);
|
|
123
|
+
|
|
124
|
+
const encodedKey = encodeLicenseKey(signedLicense);
|
|
125
|
+
const parsedLicense = parseLicenseKey(encodedKey);
|
|
126
|
+
|
|
127
|
+
expect(parsedLicense).not.toBeNull();
|
|
128
|
+
if (parsedLicense) {
|
|
129
|
+
const isValid = verifySignature(parsedLicense, TEST_PUBLIC_KEY);
|
|
130
|
+
expect(isValid).toBe(true);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
describe("generateLicenseId", () => {
|
|
136
|
+
it("produces unique IDs", () => {
|
|
137
|
+
const id1 = generateLicenseId();
|
|
138
|
+
const id2 = generateLicenseId();
|
|
139
|
+
|
|
140
|
+
expect(id1).not.toBe(id2);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("produces IDs starting with lic- prefix", () => {
|
|
144
|
+
const id = generateLicenseId();
|
|
145
|
+
|
|
146
|
+
expect(id).toMatch(/^lic-/);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("produces IDs of consistent format", () => {
|
|
150
|
+
const id = generateLicenseId();
|
|
151
|
+
|
|
152
|
+
// Format: lic-{uuid} or similar unique identifier
|
|
153
|
+
expect(id.length).toBeGreaterThan(4); // "lic-" + at least 1 character
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("produces 100 unique IDs without collision", () => {
|
|
157
|
+
const ids = new Set<string>();
|
|
158
|
+
for (let i = 0; i < 100; i++) {
|
|
159
|
+
ids.add(generateLicenseId());
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
expect(ids.size).toBe(100);
|
|
163
|
+
});
|
|
164
|
+
});
|