@oneuptime/common 12.0.19 → 12.0.20

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.
Files changed (66) hide show
  1. package/Server/API/EnterpriseLicenseAPI.ts +94 -19
  2. package/Server/EnvironmentConfig.ts +17 -0
  3. package/Server/Services/ProjectService.ts +104 -0
  4. package/Server/Utils/Response.ts +2 -2
  5. package/Server/Utils/StartServer.ts +2 -2
  6. package/Server/Views/Partials/AnalyticsConsent.ejs +533 -0
  7. package/Tests/App/Dashboard/AlertEpisodeViewFields.test.tsx +465 -0
  8. package/Tests/App/Dashboard/DashboardChartWidgetZoom.test.tsx +302 -0
  9. package/Tests/App/Dashboard/DiscoveryScanWizardValidation.test.tsx +408 -0
  10. package/Tests/App/Dashboard/IncidentEpisodeViewFields.test.tsx +474 -0
  11. package/Tests/App/Dashboard/MetricSeriesInvestigateMenu.test.tsx +368 -0
  12. package/Tests/Server/API/EnterpriseLicenseReportUserCount.test.ts +763 -0
  13. package/Tests/Server/Services/ProjectServiceChangePlan.test.ts +138 -0
  14. package/Tests/Server/Services/ProjectServiceCreateSubscriptionStarted.test.ts +516 -0
  15. package/Tests/Server/Utils/ResponseRenderAnalytics.test.ts +53 -0
  16. package/Tests/Server/Views/AnalyticsConsentPartial.test.ts +241 -0
  17. package/Tests/UI/Components/Charts/ChartTooltipSorted.test.tsx +129 -0
  18. package/Tests/UI/Components/Charts/TooltipEntries.test.ts +155 -0
  19. package/Tests/UI/Components/Detail/DetailFieldErrors.test.tsx +347 -0
  20. package/Tests/UI/Components/Forms/BasicFormStepValidation.test.tsx +392 -0
  21. package/Tests/UI/Components/Forms/ValidationFormSteps.test.ts +549 -0
  22. package/Tests/Utils/EnterpriseLicenseSync.test.ts +562 -0
  23. package/Types/Analytics/RevenueEvent.ts +1 -0
  24. package/Types/Marketing/MarketingEvent.ts +49 -6
  25. package/UI/Components/Charts/Area/AreaChart.tsx +8 -1
  26. package/UI/Components/Charts/Bar/BarChart.tsx +8 -1
  27. package/UI/Components/Charts/ChartLibrary/AreaChart/AreaChart.tsx +19 -4
  28. package/UI/Components/Charts/ChartLibrary/BarChart/BarChart.tsx +20 -2
  29. package/UI/Components/Charts/ChartLibrary/LineChart/LineChart.tsx +19 -4
  30. package/UI/Components/Charts/ChartLibrary/Utils/TooltipEntries.ts +105 -0
  31. package/UI/Components/Charts/Line/LineChart.tsx +8 -1
  32. package/UI/Components/Detail/Detail.tsx +18 -1
  33. package/Utils/EnterpriseLicense/EnterpriseLicenseSync.ts +244 -0
  34. package/build/dist/Server/API/EnterpriseLicenseAPI.js +66 -12
  35. package/build/dist/Server/API/EnterpriseLicenseAPI.js.map +1 -1
  36. package/build/dist/Server/EnvironmentConfig.js +15 -0
  37. package/build/dist/Server/EnvironmentConfig.js.map +1 -1
  38. package/build/dist/Server/Services/ProjectService.js +88 -0
  39. package/build/dist/Server/Services/ProjectService.js.map +1 -1
  40. package/build/dist/Server/Utils/Response.js +2 -2
  41. package/build/dist/Server/Utils/Response.js.map +1 -1
  42. package/build/dist/Server/Utils/StartServer.js +2 -2
  43. package/build/dist/Server/Utils/StartServer.js.map +1 -1
  44. package/build/dist/Types/Analytics/RevenueEvent.js +1 -0
  45. package/build/dist/Types/Analytics/RevenueEvent.js.map +1 -1
  46. package/build/dist/Types/Marketing/MarketingEvent.js +40 -1
  47. package/build/dist/Types/Marketing/MarketingEvent.js.map +1 -1
  48. package/build/dist/UI/Components/Charts/Area/AreaChart.js +9 -1
  49. package/build/dist/UI/Components/Charts/Area/AreaChart.js.map +1 -1
  50. package/build/dist/UI/Components/Charts/Bar/BarChart.js +9 -1
  51. package/build/dist/UI/Components/Charts/Bar/BarChart.js.map +1 -1
  52. package/build/dist/UI/Components/Charts/ChartLibrary/AreaChart/AreaChart.js +22 -13
  53. package/build/dist/UI/Components/Charts/ChartLibrary/AreaChart/AreaChart.js.map +1 -1
  54. package/build/dist/UI/Components/Charts/ChartLibrary/BarChart/BarChart.js +27 -15
  55. package/build/dist/UI/Components/Charts/ChartLibrary/BarChart/BarChart.js.map +1 -1
  56. package/build/dist/UI/Components/Charts/ChartLibrary/LineChart/LineChart.js +27 -18
  57. package/build/dist/UI/Components/Charts/ChartLibrary/LineChart/LineChart.js.map +1 -1
  58. package/build/dist/UI/Components/Charts/ChartLibrary/Utils/TooltipEntries.js +71 -0
  59. package/build/dist/UI/Components/Charts/ChartLibrary/Utils/TooltipEntries.js.map +1 -0
  60. package/build/dist/UI/Components/Charts/Line/LineChart.js +9 -1
  61. package/build/dist/UI/Components/Charts/Line/LineChart.js.map +1 -1
  62. package/build/dist/UI/Components/Detail/Detail.js +17 -1
  63. package/build/dist/UI/Components/Detail/Detail.js.map +1 -1
  64. package/build/dist/Utils/EnterpriseLicense/EnterpriseLicenseSync.js +174 -0
  65. package/build/dist/Utils/EnterpriseLicense/EnterpriseLicenseSync.js.map +1 -0
  66. package/package.json +1 -1
@@ -0,0 +1,562 @@
1
+ import EnterpriseLicenseSyncUtil, {
2
+ EnterpriseLicenseSyncResult,
3
+ } from "../../Utils/EnterpriseLicense/EnterpriseLicenseSync";
4
+ import { JSONObject } from "../../Types/JSON";
5
+ import { describe, expect, it } from "@jest/globals";
6
+
7
+ /*
8
+ * The mapper that turns a license-server response into the GlobalConfig
9
+ * columns a self-hosted installation mirrors.
10
+ *
11
+ * This exists because of a real, reported bug: a customer raised their seat
12
+ * limit on oneuptime.com, their installation called home every day as
13
+ * designed, and the modal kept showing the old limit forever. The daily job
14
+ * read four fields out of the response and silently dropped userLimit, and the
15
+ * only other writer of that column is a human re-typing the license key.
16
+ *
17
+ * Every field here is three-state, and keeping those states apart IS the
18
+ * contract:
19
+ *
20
+ * key absent -> leave the stored column alone. This is what an oneuptime.com
21
+ * older than the installation looks like, and collapsing it to
22
+ * null would let a daily report wipe a valid license expiry
23
+ * and take the installation down.
24
+ * null -> the server means "no value"; write null.
25
+ * a value -> validate, then write.
26
+ *
27
+ * The absent case cannot be asserted with toBeUndefined(): reading a missing
28
+ * key and reading a key set to undefined both give undefined, and only one of
29
+ * them is safe to hand to updateOneById. Every "left alone" assertion below
30
+ * therefore goes through Object.keys / toHaveProperty.
31
+ */
32
+
33
+ const REPORTED_AT: Date = new Date("2026-08-24T10:00:00.000Z");
34
+
35
+ type SyncFunction = (payload: JSONObject) => EnterpriseLicenseSyncResult;
36
+
37
+ const sync: SyncFunction = (
38
+ payload: JSONObject,
39
+ ): EnterpriseLicenseSyncResult => {
40
+ return EnterpriseLicenseSyncUtil.getGlobalConfigUpdateFromLicenseResponse({
41
+ payload: payload,
42
+ reportedAt: REPORTED_AT,
43
+ });
44
+ };
45
+
46
+ type KeysFunction = (payload: JSONObject) => Array<string>;
47
+
48
+ const keys: KeysFunction = (payload: JSONObject): Array<string> => {
49
+ return Object.keys(sync(payload).updateData);
50
+ };
51
+
52
+ /*
53
+ * The exact body Common/Server/API/EnterpriseLicenseAPI.ts sends from
54
+ * /report-user-count for a healthy license. Kept in one place so the contract
55
+ * test at the bottom and the happy-path tests cannot drift apart.
56
+ */
57
+ type ServerResponseFunction = (overrides?: JSONObject) => JSONObject;
58
+
59
+ const serverResponse: ServerResponseFunction = (
60
+ overrides?: JSONObject,
61
+ ): JSONObject => {
62
+ return {
63
+ companyName: "Acme Inc",
64
+ expiresAt: "2027-01-01T00:00:00.000Z",
65
+ licenseKey: "the-key-the-server-knows",
66
+ userLimit: 150,
67
+ currentUserCount: 42,
68
+ userCountUpdatedAt: "2026-08-24T09:59:00.000Z",
69
+ isEvaluationLicense: false,
70
+ instances: [
71
+ {
72
+ instanceId: "instance-1",
73
+ host: "oneuptime.acme.internal",
74
+ userCount: 42,
75
+ lastReportedAt: "2026-08-24T09:59:00.000Z",
76
+ version: "12.0.19",
77
+ },
78
+ ],
79
+ token: "signed.jwt.token",
80
+ ...overrides,
81
+ };
82
+ };
83
+
84
+ describe("EnterpriseLicenseSyncUtil - the reported bug: the seat limit", () => {
85
+ it("writes a raised seat limit, which is the regression this whole file guards", () => {
86
+ const result: EnterpriseLicenseSyncResult = sync({ userLimit: 150 });
87
+
88
+ expect(result.updateData.enterpriseLicenseUserLimit).toBe(150);
89
+ expect(result.warnings).toEqual([]);
90
+ });
91
+
92
+ it("writes a lowered seat limit too - the sync is not one-directional", () => {
93
+ expect(sync({ userLimit: 5 }).updateData.enterpriseLicenseUserLimit).toBe(
94
+ 5,
95
+ );
96
+ });
97
+
98
+ it("writes an explicit null, so clearing the limit on oneuptime.com clears it here", () => {
99
+ const result: EnterpriseLicenseSyncResult = sync({ userLimit: null });
100
+
101
+ expect(Object.keys(result.updateData)).toContain(
102
+ "enterpriseLicenseUserLimit",
103
+ );
104
+ expect(result.updateData.enterpriseLicenseUserLimit).toBeNull();
105
+ expect(result.warnings).toEqual([]);
106
+ });
107
+
108
+ it("leaves the stored limit alone when the server never mentions it", () => {
109
+ // An oneuptime.com older than this build. Must be a no-op, not a clear.
110
+ expect(keys({ currentUserCount: 3 })).not.toContain(
111
+ "enterpriseLicenseUserLimit",
112
+ );
113
+ });
114
+
115
+ it("treats an explicit undefined as silence, not as a clear", () => {
116
+ expect(keys({ userLimit: undefined })).not.toContain(
117
+ "enterpriseLicenseUserLimit",
118
+ );
119
+ });
120
+
121
+ it("writes zero rather than skipping it on a truthiness check", () => {
122
+ const result: EnterpriseLicenseSyncResult = sync({ userLimit: 0 });
123
+
124
+ expect(Object.keys(result.updateData)).toContain(
125
+ "enterpriseLicenseUserLimit",
126
+ );
127
+ expect(result.updateData.enterpriseLicenseUserLimit).toBe(0);
128
+ });
129
+
130
+ it.each([
131
+ ["a numeric string", "150"],
132
+ ["NaN", Number.NaN],
133
+ ["Infinity", Number.POSITIVE_INFINITY],
134
+ ["a fraction", 12.5],
135
+ ["a negative number", -1],
136
+ ["a boolean", true],
137
+ ["an object", {}],
138
+ ["an array", [150]],
139
+ ])(
140
+ "refuses to store %s as the seat limit, and says so",
141
+ (_label: string, value: unknown) => {
142
+ const result: EnterpriseLicenseSyncResult = sync({
143
+ userLimit: value,
144
+ } as JSONObject);
145
+
146
+ expect(Object.keys(result.updateData)).not.toContain(
147
+ "enterpriseLicenseUserLimit",
148
+ );
149
+ expect(result.warnings).toHaveLength(1);
150
+ expect(result.warnings[0]).toContain("userLimit");
151
+ },
152
+ );
153
+ });
154
+
155
+ describe("EnterpriseLicenseSyncUtil - user count and its timestamp", () => {
156
+ it("stores the deduplicated count the server computed across every instance", () => {
157
+ const result: EnterpriseLicenseSyncResult = sync({
158
+ currentUserCount: 42,
159
+ userCountUpdatedAt: "2026-08-24T09:59:00.000Z",
160
+ });
161
+
162
+ expect(result.updateData.enterpriseLicenseCurrentUserCount).toBe(42);
163
+ expect(result.updateData.enterpriseLicenseUserCountUpdatedAt).toEqual(
164
+ new Date("2026-08-24T09:59:00.000Z"),
165
+ );
166
+ });
167
+
168
+ it("falls back to the caller's clock when the server sends a count but no stamp", () => {
169
+ const result: EnterpriseLicenseSyncResult = sync({ currentUserCount: 7 });
170
+
171
+ expect(result.updateData.enterpriseLicenseUserCountUpdatedAt).toEqual(
172
+ REPORTED_AT,
173
+ );
174
+ });
175
+
176
+ it("falls back to the caller's clock when the stamp is unparseable", () => {
177
+ const result: EnterpriseLicenseSyncResult = sync({
178
+ currentUserCount: 7,
179
+ userCountUpdatedAt: "last tuesday",
180
+ });
181
+
182
+ expect(result.updateData.enterpriseLicenseUserCountUpdatedAt).toEqual(
183
+ REPORTED_AT,
184
+ );
185
+ });
186
+
187
+ it("stores a count of zero", () => {
188
+ const result: EnterpriseLicenseSyncResult = sync({ currentUserCount: 0 });
189
+
190
+ expect(result.updateData.enterpriseLicenseCurrentUserCount).toBe(0);
191
+ });
192
+
193
+ it("never stamps a timestamp onto a count it did not store", () => {
194
+ /*
195
+ * A fresh stamp on a stale count is the specific lie that made this bug
196
+ * hard to see: the modal reads "last reported today" underneath a number
197
+ * from weeks ago.
198
+ */
199
+ const result: EnterpriseLicenseSyncResult = sync({
200
+ currentUserCount: "many",
201
+ userCountUpdatedAt: "2026-08-24T09:59:00.000Z",
202
+ } as JSONObject);
203
+
204
+ expect(Object.keys(result.updateData)).not.toContain(
205
+ "enterpriseLicenseCurrentUserCount",
206
+ );
207
+ expect(Object.keys(result.updateData)).not.toContain(
208
+ "enterpriseLicenseUserCountUpdatedAt",
209
+ );
210
+ });
211
+
212
+ it.each([
213
+ ["a string", "42"],
214
+ ["NaN", Number.NaN],
215
+ ["Infinity", Number.POSITIVE_INFINITY],
216
+ ["a fraction", 4.5],
217
+ ["a negative number", -3],
218
+ ])(
219
+ "keeps the previously stored usage when the count arrives as %s",
220
+ (_label: string, value: unknown) => {
221
+ const result: EnterpriseLicenseSyncResult = sync({
222
+ currentUserCount: value,
223
+ } as JSONObject);
224
+
225
+ expect(Object.keys(result.updateData)).not.toContain(
226
+ "enterpriseLicenseCurrentUserCount",
227
+ );
228
+ expect(result.warnings).toHaveLength(1);
229
+ },
230
+ );
231
+
232
+ it("keeps the previously stored usage when the server reports null", () => {
233
+ const result: EnterpriseLicenseSyncResult = sync({
234
+ currentUserCount: null,
235
+ });
236
+
237
+ expect(Object.keys(result.updateData)).not.toContain(
238
+ "enterpriseLicenseCurrentUserCount",
239
+ );
240
+ expect(result.warnings).toHaveLength(1);
241
+ });
242
+
243
+ it("leaves both usage columns alone when the server never mentions the count", () => {
244
+ expect(keys({ userLimit: 10 })).toEqual(["enterpriseLicenseUserLimit"]);
245
+ });
246
+
247
+ it("still syncs everything else when only the count is unusable", () => {
248
+ /*
249
+ * The job used to bail out entirely here, so one malformed count also cost
250
+ * the customer that day's seat limit, expiry and evaluation flag.
251
+ */
252
+ const result: EnterpriseLicenseSyncResult = sync(
253
+ serverResponse({ currentUserCount: "nope" }),
254
+ );
255
+
256
+ expect(result.updateData.enterpriseLicenseUserLimit).toBe(150);
257
+ expect(result.updateData.enterpriseLicenseExpiresAt).toEqual(
258
+ new Date("2027-01-01T00:00:00.000Z"),
259
+ );
260
+ expect(result.updateData.enterpriseLicenseIsEvaluation).toBe(false);
261
+ expect(result.updateData.enterpriseCompanyName).toBe("Acme Inc");
262
+ expect(result.updateData.enterpriseLicenseToken).toBe("signed.jwt.token");
263
+ });
264
+ });
265
+
266
+ describe("EnterpriseLicenseSyncUtil - expiry", () => {
267
+ it("stores a renewal, so extending a license on oneuptime.com reaches the installation", () => {
268
+ const result: EnterpriseLicenseSyncResult = sync({
269
+ expiresAt: "2027-01-01T00:00:00.000Z",
270
+ });
271
+
272
+ expect(result.updateData.enterpriseLicenseExpiresAt).toEqual(
273
+ new Date("2027-01-01T00:00:00.000Z"),
274
+ );
275
+ });
276
+
277
+ it("stores an expiry in the past, because an instance must be able to learn it expired", () => {
278
+ const result: EnterpriseLicenseSyncResult = sync({
279
+ expiresAt: "2020-01-01T00:00:00.000Z",
280
+ });
281
+
282
+ expect(result.updateData.enterpriseLicenseExpiresAt).toEqual(
283
+ new Date("2020-01-01T00:00:00.000Z"),
284
+ );
285
+ });
286
+
287
+ it("leaves the stored expiry alone when the server never mentions it", () => {
288
+ /*
289
+ * The compatibility case that matters most: an installation upgraded ahead
290
+ * of oneuptime.com must not have its expiry blanked and go dark.
291
+ */
292
+ expect(keys({ currentUserCount: 1 })).not.toContain(
293
+ "enterpriseLicenseExpiresAt",
294
+ );
295
+ });
296
+
297
+ it("treats an explicit null as silence - a report never strips an expiry", () => {
298
+ expect(keys({ expiresAt: null })).not.toContain(
299
+ "enterpriseLicenseExpiresAt",
300
+ );
301
+ expect(sync({ expiresAt: null }).warnings).toEqual([]);
302
+ });
303
+
304
+ it.each([
305
+ ["an unparseable string", "not a date"],
306
+ ["an empty string", ""],
307
+ ["a number", 1767225600000],
308
+ ["a boolean", true],
309
+ ])(
310
+ "keeps the stored expiry when the server sends %s, and says so",
311
+ (_label: string, value: unknown) => {
312
+ const result: EnterpriseLicenseSyncResult = sync({
313
+ expiresAt: value,
314
+ } as JSONObject);
315
+
316
+ expect(Object.keys(result.updateData)).not.toContain(
317
+ "enterpriseLicenseExpiresAt",
318
+ );
319
+ expect(result.warnings).toHaveLength(1);
320
+ expect(result.warnings[0]).toContain("expiresAt");
321
+ },
322
+ );
323
+
324
+ it("accepts a Date instance, in case the transport ever deserializes one", () => {
325
+ const expiry: Date = new Date("2027-06-01T00:00:00.000Z");
326
+
327
+ expect(
328
+ sync({ expiresAt: expiry }).updateData.enterpriseLicenseExpiresAt,
329
+ ).toEqual(expiry);
330
+ });
331
+ });
332
+
333
+ describe("EnterpriseLicenseSyncUtil - evaluation flag", () => {
334
+ it.each([
335
+ [true, true],
336
+ [false, false],
337
+ ])(
338
+ "mirrors the boolean the server sent (%s)",
339
+ (value: boolean, expected: boolean) => {
340
+ expect(
341
+ sync({ isEvaluationLicense: value }).updateData
342
+ .enterpriseLicenseIsEvaluation,
343
+ ).toBe(expected);
344
+ },
345
+ );
346
+
347
+ it("leaves the stored flag alone when the server never mentions it", () => {
348
+ expect(keys({ userLimit: 1 })).not.toContain(
349
+ "enterpriseLicenseIsEvaluation",
350
+ );
351
+ });
352
+
353
+ it.each([
354
+ ['the string "true"', "true"],
355
+ ["a number", 1],
356
+ ["null", null],
357
+ ])(
358
+ "refuses to guess at %s and keeps the stored flag",
359
+ (_label: string, value: unknown) => {
360
+ const result: EnterpriseLicenseSyncResult = sync({
361
+ isEvaluationLicense: value,
362
+ } as JSONObject);
363
+
364
+ expect(Object.keys(result.updateData)).not.toContain(
365
+ "enterpriseLicenseIsEvaluation",
366
+ );
367
+ expect(result.warnings).toHaveLength(1);
368
+ },
369
+ );
370
+ });
371
+
372
+ describe("EnterpriseLicenseSyncUtil - company name", () => {
373
+ it("stores a rename", () => {
374
+ expect(
375
+ sync({ companyName: "Acme Inc" }).updateData.enterpriseCompanyName,
376
+ ).toBe("Acme Inc");
377
+ });
378
+
379
+ it("trims what it stores", () => {
380
+ expect(
381
+ sync({ companyName: " Acme Inc " }).updateData.enterpriseCompanyName,
382
+ ).toBe("Acme Inc");
383
+ });
384
+
385
+ it.each([
386
+ ["an empty string", ""],
387
+ ["whitespace", " "],
388
+ ["null", null],
389
+ ["a number", 42],
390
+ ])(
391
+ "keeps the stored name rather than blanking the modal for %s",
392
+ (_label: string, value: unknown) => {
393
+ expect(
394
+ Object.keys(sync({ companyName: value } as JSONObject).updateData),
395
+ ).not.toContain("enterpriseCompanyName");
396
+ },
397
+ );
398
+
399
+ it("leaves the stored name alone when the server never mentions it", () => {
400
+ expect(keys({ userLimit: 1 })).not.toContain("enterpriseCompanyName");
401
+ });
402
+ });
403
+
404
+ describe("EnterpriseLicenseSyncUtil - token", () => {
405
+ it("stores a freshly signed token", () => {
406
+ expect(sync({ token: "a.b.c" }).updateData.enterpriseLicenseToken).toBe(
407
+ "a.b.c",
408
+ );
409
+ });
410
+
411
+ it.each([
412
+ ["null, as an expired license gets", null],
413
+ ["an empty string", ""],
414
+ ["a non-string", 7],
415
+ ])(
416
+ "never clears the stored token for %s",
417
+ (_label: string, value: unknown) => {
418
+ /*
419
+ * An expired license is legitimately issued no token. Clearing the stored
420
+ * one would compound an expiry the customer may be in the middle of
421
+ * renewing, and the refreshed expiresAt already tells the truth.
422
+ */
423
+ expect(
424
+ Object.keys(sync({ token: value } as JSONObject).updateData),
425
+ ).not.toContain("enterpriseLicenseToken");
426
+ },
427
+ );
428
+
429
+ it("leaves the stored token alone when the server never mentions it", () => {
430
+ expect(keys({ userLimit: 1 })).not.toContain("enterpriseLicenseToken");
431
+ });
432
+ });
433
+
434
+ describe("EnterpriseLicenseSyncUtil - instances", () => {
435
+ it("stores the instance list", () => {
436
+ const instances: Array<JSONObject> = [
437
+ { instanceId: "a", host: "a.example.com" },
438
+ ];
439
+
440
+ expect(
441
+ sync({ instances: instances } as JSONObject).updateData
442
+ .enterpriseLicenseInstances,
443
+ ).toEqual(instances);
444
+ });
445
+
446
+ it("stores an empty list, so a license that lost its instances shows none", () => {
447
+ const result: EnterpriseLicenseSyncResult = sync({ instances: [] });
448
+
449
+ expect(Object.keys(result.updateData)).toContain(
450
+ "enterpriseLicenseInstances",
451
+ );
452
+ expect(result.updateData.enterpriseLicenseInstances).toEqual([]);
453
+ });
454
+
455
+ it.each([
456
+ ["null", null],
457
+ ["an object", {}],
458
+ ["a string", "instance"],
459
+ ])(
460
+ "keeps the stored list when the server sends %s",
461
+ (_label: string, value: unknown) => {
462
+ const result: EnterpriseLicenseSyncResult = sync({
463
+ instances: value,
464
+ } as JSONObject);
465
+
466
+ expect(Object.keys(result.updateData)).not.toContain(
467
+ "enterpriseLicenseInstances",
468
+ );
469
+ expect(result.warnings).toHaveLength(1);
470
+ },
471
+ );
472
+
473
+ it("leaves the stored list alone when the server never mentions it", () => {
474
+ expect(keys({ userLimit: 1 })).not.toContain("enterpriseLicenseInstances");
475
+ });
476
+ });
477
+
478
+ describe("EnterpriseLicenseSyncUtil - what it must never write", () => {
479
+ it("never syncs the license key back onto the installation", () => {
480
+ /*
481
+ * The installation authenticates with the key it already holds. A response
482
+ * must not be able to swap it for a different one.
483
+ */
484
+ expect(keys(serverResponse())).not.toContain("enterpriseLicenseKey");
485
+ });
486
+
487
+ it("never invents columns from unknown fields", () => {
488
+ expect(
489
+ keys({ somethingNew: "from a future oneuptime.com" } as JSONObject),
490
+ ).toEqual([]);
491
+ });
492
+
493
+ it("returns an empty update for an empty response rather than a pile of nulls", () => {
494
+ const result: EnterpriseLicenseSyncResult = sync({});
495
+
496
+ expect(result.updateData).toEqual({});
497
+ expect(result.warnings).toEqual([]);
498
+ });
499
+
500
+ it("survives a null payload", () => {
501
+ const result: EnterpriseLicenseSyncResult =
502
+ EnterpriseLicenseSyncUtil.getGlobalConfigUpdateFromLicenseResponse({
503
+ payload: null as unknown as JSONObject,
504
+ reportedAt: REPORTED_AT,
505
+ });
506
+
507
+ expect(result.updateData).toEqual({});
508
+ });
509
+ });
510
+
511
+ describe("EnterpriseLicenseSyncUtil - the whole response at once", () => {
512
+ it("mirrors every field of a healthy report", () => {
513
+ const result: EnterpriseLicenseSyncResult = sync(serverResponse());
514
+
515
+ expect(result.warnings).toEqual([]);
516
+ expect(result.updateData).toEqual({
517
+ enterpriseCompanyName: "Acme Inc",
518
+ enterpriseLicenseExpiresAt: new Date("2027-01-01T00:00:00.000Z"),
519
+ enterpriseLicenseUserLimit: 150,
520
+ enterpriseLicenseCurrentUserCount: 42,
521
+ enterpriseLicenseUserCountUpdatedAt: new Date("2026-08-24T09:59:00.000Z"),
522
+ enterpriseLicenseIsEvaluation: false,
523
+ enterpriseLicenseToken: "signed.jwt.token",
524
+ enterpriseLicenseInstances: [
525
+ {
526
+ instanceId: "instance-1",
527
+ host: "oneuptime.acme.internal",
528
+ userCount: 42,
529
+ lastReportedAt: "2026-08-24T09:59:00.000Z",
530
+ version: "12.0.19",
531
+ },
532
+ ],
533
+ });
534
+ });
535
+
536
+ it("is a no-op against the response an oneuptime.com from before this change would send", () => {
537
+ /*
538
+ * The old /report-user-count body, verbatim. userLimit already shipped in
539
+ * it, so the fix works against every deployed license server; the fields
540
+ * added alongside it must simply be left alone.
541
+ */
542
+ const legacyBody: JSONObject = {
543
+ currentUserCount: 42,
544
+ userCountUpdatedAt: "2026-08-24T09:59:00.000Z",
545
+ userLimit: 150,
546
+ isEvaluationLicense: false,
547
+ instances: [],
548
+ };
549
+
550
+ const result: EnterpriseLicenseSyncResult = sync(legacyBody);
551
+
552
+ expect(result.warnings).toEqual([]);
553
+ expect(Object.keys(result.updateData).sort()).toEqual([
554
+ "enterpriseLicenseCurrentUserCount",
555
+ "enterpriseLicenseInstances",
556
+ "enterpriseLicenseIsEvaluation",
557
+ "enterpriseLicenseUserCountUpdatedAt",
558
+ "enterpriseLicenseUserLimit",
559
+ ]);
560
+ expect(result.updateData.enterpriseLicenseUserLimit).toBe(150);
561
+ });
562
+ });
@@ -12,6 +12,7 @@ export enum RevenueEventName {
12
12
  WorkspaceCreated = "workspace_created",
13
13
  MonitorCreated = "monitor_created",
14
14
  TeammateInvited = "teammate_invited",
15
+ SubscriptionStarted = "subscription_started",
15
16
  SubscriptionUpgraded = "subscription_upgraded",
16
17
  SubscriptionDowngraded = "subscription_downgraded",
17
18
  }
@@ -3,7 +3,7 @@ import { JSONObject } from "../JSON";
3
3
  /*
4
4
  * The outbound marketing event contract.
5
5
  *
6
- * OneUptime does not keep a conversion ledger. The four moments worth
6
+ * OneUptime does not keep a conversion ledger. The moments worth
7
7
  * measuring are emitted as signed webhooks at the instant they happen and are
8
8
  * not stored here afterwards, so this interface — not a database table — is
9
9
  * the whole record of what a conversion looks like.
@@ -27,6 +27,15 @@ import { JSONObject } from "../JSON";
27
27
  export enum MarketingEventType {
28
28
  SignUp = "sign_up",
29
29
  MeetingBooked = "meeting_booked",
30
+ /*
31
+ * A project's first paid subscription, created together with the project.
32
+ *
33
+ * Deliberately not a subscription_upgraded. An upgrade is a movement between
34
+ * two tiers and reports expansion; this has no previous tier at all and is
35
+ * new business. Reporting one as the other mixes net-new with expansion
36
+ * revenue, and nothing downstream could separate them again.
37
+ */
38
+ SubscriptionStarted = "subscription_started",
30
39
  SubscriptionUpgraded = "subscription_upgraded",
31
40
  SubscriptionDowngraded = "subscription_downgraded",
32
41
  /*
@@ -41,6 +50,39 @@ export enum MarketingEventType {
41
50
  EnterpriseLicenseIssued = "enterprise_license_issued",
42
51
  }
43
52
 
53
+ /*
54
+ * Which conversation a booked meeting actually is.
55
+ *
56
+ * All three Cal embeds book the same event type (oneuptimehq/demo), so without
57
+ * this the webhook cannot tell a free user's support call from a net-new
58
+ * enterprise demo — they arrive as one undifferentiated `meeting_booked`, and
59
+ * anything bidding on or reporting against that count values them identically.
60
+ *
61
+ * The browser event has carried this since the embeds were instrumented; the
62
+ * webhook did not, which meant the authoritative record was the one that could
63
+ * not make the distinction.
64
+ *
65
+ * `Unknown` is a real state, not a failure: a booking made through a Cal link
66
+ * that was not one of the instrumented embeds genuinely has no kind, and is
67
+ * still a booking worth emitting.
68
+ */
69
+ export enum MeetingBookingKind {
70
+ EnterpriseDemo = "enterprise_demo",
71
+ SupportCall = "support_call",
72
+ ArchitectureAssessment = "architecture_assessment",
73
+ Unknown = "unknown",
74
+ }
75
+
76
+ /*
77
+ * The Cal booking-metadata key the embeds write and the webhook reads. Shared
78
+ * so a rename cannot land on one side only - the failure mode there is silent,
79
+ * because a booking with no recognised kind still succeeds.
80
+ */
81
+ export const BOOKING_KIND_METADATA_KEY: string = "ou_booking_kind";
82
+
83
+ export const MeetingBookingKinds: Array<string> =
84
+ Object.values(MeetingBookingKind);
85
+
44
86
  export const MARKETING_EVENT_SCHEMA_VERSION: number = 1;
45
87
 
46
88
  /*
@@ -69,15 +111,16 @@ export interface MarketingEvent extends JSONObject {
69
111
  *
70
112
  * sign_up:{userId}
71
113
  * meeting_booked:{calBookingUid}
114
+ * subscription_started:{projectId}
72
115
  * subscription_upgraded:{projectId}:{occurredAt}
73
116
  * subscription_downgraded:{projectId}:{occurredAt}
74
117
  * enterprise_license_issued:{enterpriseLicenseId}
75
118
  *
76
- * Three of these are naturally unique — a user signs up once, a booking has
77
- * one uid, a licence row is issued once so Cal retrying a delivery or the
78
- * queue retrying a job cannot produce a second conversion. A plan change can
79
- * legitimately recur for one project, so its id carries the instant it
80
- * happened.
119
+ * Four of these are naturally unique — a user signs up once, a booking has
120
+ * one uid, a project has one first subscription, a licence row is issued
121
+ * once — so Cal retrying a delivery or the queue retrying a job cannot
122
+ * produce a second conversion. A plan change can legitimately recur for one
123
+ * project, so its id carries the instant it happened.
81
124
  */
82
125
  eventId: string;
83
126
  eventType: MarketingEventType;
@@ -181,7 +181,14 @@ const AreaChartElement: FunctionComponent<AreaInternalProps> = (
181
181
 
182
182
  return (
183
183
  <div
184
- className="relative flex flex-1"
184
+ /*
185
+ * `isolate` opens a stacking context so the recharts tooltip's
186
+ * z-index competes only inside this chart — without it the tooltip
187
+ * (zIndex 10, pinned to the chart's top edge) ties with the app
188
+ * header's sticky z-10 in the root context and paints over the
189
+ * navbar on half-scrolled charts.
190
+ */
191
+ className="relative isolate flex flex-1"
185
192
  style={props.heightInPx ? { height: `${props.heightInPx}px` } : undefined}
186
193
  >
187
194
  <AreaChart
@@ -115,7 +115,14 @@ const BarChartElement: FunctionComponent<BarInternalProps> = (
115
115
 
116
116
  return (
117
117
  <div
118
- className="relative flex flex-1"
118
+ /*
119
+ * `isolate` opens a stacking context so the recharts tooltip's
120
+ * z-index competes only inside this chart — without it the tooltip
121
+ * (zIndex 10, pinned to the chart's top edge) ties with the app
122
+ * header's sticky z-10 in the root context and paints over the
123
+ * navbar on half-scrolled charts.
124
+ */
125
+ className="relative isolate flex flex-1"
119
126
  style={props.heightInPx ? { height: `${props.heightInPx}px` } : undefined}
120
127
  >
121
128
  <BarChart