@terpjs/contract 0.30.0 → 0.32.0

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/openapi.json CHANGED
@@ -337,6 +337,96 @@
337
337
  "title": "AccessToken",
338
338
  "type": "object"
339
339
  },
340
+ "AuditActionCount": {
341
+ "description": "How many events in the window record one action.",
342
+ "properties": {
343
+ "action": {
344
+ "title": "Action",
345
+ "type": "string"
346
+ },
347
+ "count": {
348
+ "title": "Count",
349
+ "type": "integer"
350
+ }
351
+ },
352
+ "required": [
353
+ "action",
354
+ "count"
355
+ ],
356
+ "title": "AuditActionCount",
357
+ "type": "object"
358
+ },
359
+ "AuditActivityRead": {
360
+ "description": "The trail's activity over the last ``days`` calendar days, counted in one time zone.\n\n``days`` runs oldest first and ends today, with a zero for a day that holds nothing, so a\nchart can draw it as it comes. ``previous_days`` is the same number of days just before,\nfor a comparison. The two breakdowns and ``total`` cover ``days`` only, and\n``by_target_type`` is the most changed types, most first.",
361
+ "properties": {
362
+ "by_action": {
363
+ "items": {
364
+ "$ref": "#/components/schemas/AuditActionCount"
365
+ },
366
+ "title": "By Action",
367
+ "type": "array"
368
+ },
369
+ "by_target_type": {
370
+ "items": {
371
+ "$ref": "#/components/schemas/AuditTargetCount"
372
+ },
373
+ "title": "By Target Type",
374
+ "type": "array"
375
+ },
376
+ "days": {
377
+ "items": {
378
+ "$ref": "#/components/schemas/AuditDayCount"
379
+ },
380
+ "title": "Days",
381
+ "type": "array"
382
+ },
383
+ "previous_days": {
384
+ "items": {
385
+ "$ref": "#/components/schemas/AuditDayCount"
386
+ },
387
+ "title": "Previous Days",
388
+ "type": "array"
389
+ },
390
+ "time_zone": {
391
+ "title": "Time Zone",
392
+ "type": "string"
393
+ },
394
+ "total": {
395
+ "title": "Total",
396
+ "type": "integer"
397
+ }
398
+ },
399
+ "required": [
400
+ "time_zone",
401
+ "days",
402
+ "previous_days",
403
+ "by_action",
404
+ "by_target_type",
405
+ "total"
406
+ ],
407
+ "title": "AuditActivityRead",
408
+ "type": "object"
409
+ },
410
+ "AuditDayCount": {
411
+ "description": "How many events one calendar day of the requested time zone holds.",
412
+ "properties": {
413
+ "count": {
414
+ "title": "Count",
415
+ "type": "integer"
416
+ },
417
+ "date": {
418
+ "format": "date",
419
+ "title": "Date",
420
+ "type": "string"
421
+ }
422
+ },
423
+ "required": [
424
+ "date",
425
+ "count"
426
+ ],
427
+ "title": "AuditDayCount",
428
+ "type": "object"
429
+ },
340
430
  "AuditEventRead": {
341
431
  "properties": {
342
432
  "action": {
@@ -410,6 +500,25 @@
410
500
  "title": "AuditEventRead",
411
501
  "type": "object"
412
502
  },
503
+ "AuditTargetCount": {
504
+ "description": "How many events in the window are about records of one type.",
505
+ "properties": {
506
+ "count": {
507
+ "title": "Count",
508
+ "type": "integer"
509
+ },
510
+ "target_type": {
511
+ "title": "Target Type",
512
+ "type": "string"
513
+ }
514
+ },
515
+ "required": [
516
+ "target_type",
517
+ "count"
518
+ ],
519
+ "title": "AuditTargetCount",
520
+ "type": "object"
521
+ },
413
522
  "CurrentUser": {
414
523
  "description": "The authenticated caller's own identity \u2014 the ``/me`` (who-am-I) response.\n\nThe frontend's session contract pairs this with :class:`AccessToken`. It is the\nserver-validated current identity (resolved through the wired principal provider \u2014\nthe revocable one in the bundled stack), so it reflects the live store, not just the\ntoken's claims. The caller's role is on the wire as both the numeric ``role_rank``\n(the comparable primitive, ADR 0004 / 0022) and a human-readable ``role_name``.",
415
524
  "properties": {
@@ -1639,6 +1748,44 @@
1639
1748
  "get": {
1640
1749
  "operationId": "audit.list_events",
1641
1750
  "parameters": [
1751
+ {
1752
+ "description": "Only events about records of this type -- the model's name, e.g. 'User'.",
1753
+ "in": "query",
1754
+ "name": "target_type",
1755
+ "required": false,
1756
+ "schema": {
1757
+ "anyOf": [
1758
+ {
1759
+ "maxLength": 128,
1760
+ "type": "string"
1761
+ },
1762
+ {
1763
+ "type": "null"
1764
+ }
1765
+ ],
1766
+ "description": "Only events about records of this type -- the model's name, e.g. 'User'.",
1767
+ "title": "Target Type"
1768
+ }
1769
+ },
1770
+ {
1771
+ "description": "Only events about the record with this id.",
1772
+ "in": "query",
1773
+ "name": "target_id",
1774
+ "required": false,
1775
+ "schema": {
1776
+ "anyOf": [
1777
+ {
1778
+ "maxLength": 128,
1779
+ "type": "string"
1780
+ },
1781
+ {
1782
+ "type": "null"
1783
+ }
1784
+ ],
1785
+ "description": "Only events about the record with this id.",
1786
+ "title": "Target Id"
1787
+ }
1788
+ },
1642
1789
  {
1643
1790
  "description": "Rows to skip.",
1644
1791
  "in": "query",
@@ -1695,6 +1842,68 @@
1695
1842
  ]
1696
1843
  }
1697
1844
  },
1845
+ "/api/v1/audit/activity": {
1846
+ "get": {
1847
+ "operationId": "audit.read_activity",
1848
+ "parameters": [
1849
+ {
1850
+ "description": "How many calendar days to count, ending today; the days before are counted too.",
1851
+ "in": "query",
1852
+ "name": "days",
1853
+ "required": false,
1854
+ "schema": {
1855
+ "default": 30,
1856
+ "description": "How many calendar days to count, ending today; the days before are counted too.",
1857
+ "maximum": 90,
1858
+ "minimum": 1,
1859
+ "title": "Days",
1860
+ "type": "integer"
1861
+ }
1862
+ },
1863
+ {
1864
+ "description": "The IANA time zone whose calendar days are counted, e.g. 'Europe/Amsterdam'.",
1865
+ "in": "query",
1866
+ "name": "time_zone",
1867
+ "required": false,
1868
+ "schema": {
1869
+ "default": "UTC",
1870
+ "description": "The IANA time zone whose calendar days are counted, e.g. 'Europe/Amsterdam'.",
1871
+ "maxLength": 64,
1872
+ "minLength": 1,
1873
+ "pattern": "^[A-Za-z][A-Za-z0-9_+-]*(/[A-Za-z0-9_+-]+)*$",
1874
+ "title": "Time Zone",
1875
+ "type": "string"
1876
+ }
1877
+ }
1878
+ ],
1879
+ "responses": {
1880
+ "200": {
1881
+ "content": {
1882
+ "application/json": {
1883
+ "schema": {
1884
+ "$ref": "#/components/schemas/AuditActivityRead"
1885
+ }
1886
+ }
1887
+ },
1888
+ "description": "Successful Response"
1889
+ },
1890
+ "422": {
1891
+ "content": {
1892
+ "application/json": {
1893
+ "schema": {
1894
+ "$ref": "#/components/schemas/HTTPValidationError"
1895
+ }
1896
+ }
1897
+ },
1898
+ "description": "Validation Error"
1899
+ }
1900
+ },
1901
+ "summary": "View how much the audit trail records per day",
1902
+ "tags": [
1903
+ "audit"
1904
+ ]
1905
+ }
1906
+ },
1698
1907
  "/api/v1/auth/login": {
1699
1908
  "post": {
1700
1909
  "operationId": "auth.login",
@@ -2209,6 +2418,24 @@
2209
2418
  "title": "Email"
2210
2419
  }
2211
2420
  },
2421
+ {
2422
+ "description": "Filter to active accounts (true) or deactivated ones (false).",
2423
+ "in": "query",
2424
+ "name": "is_active",
2425
+ "required": false,
2426
+ "schema": {
2427
+ "anyOf": [
2428
+ {
2429
+ "type": "boolean"
2430
+ },
2431
+ {
2432
+ "type": "null"
2433
+ }
2434
+ ],
2435
+ "description": "Filter to active accounts (true) or deactivated ones (false).",
2436
+ "title": "Is Active"
2437
+ }
2438
+ },
2212
2439
  {
2213
2440
  "description": "Rows to skip.",
2214
2441
  "in": "query",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terpjs/contract",
3
- "version": "0.30.0",
3
+ "version": "0.32.0",
4
4
  "type": "module",
5
5
  "description": "Terp frontend contract \u2014 the OpenAPI-generated TypeScript client, design tokens, and the stack-agnostic module/route/nav + auth types.",
6
6
  "exports": {
@@ -23,7 +23,7 @@
23
23
  "devDependencies": {
24
24
  "openapi-typescript": "^7.13.0",
25
25
  "style-dictionary": "^5.5.5",
26
- "vitest": "^5.0.0"
26
+ "vitest": "^5.0.2"
27
27
  },
28
28
  "dependencies": {
29
29
  "openapi-fetch": "^0.17.0",
@@ -48,6 +48,24 @@ const AA_NORMAL_TEXT = 4.5;
48
48
  */
49
49
  const UI_COMPONENT = 3;
50
50
 
51
+ /**
52
+ * The APCA lightness contrast (Lc) each way of reading a text pairing must reach, beside the
53
+ * WCAG ratio rather than instead of it (ADR 0170). WCAG 2's ratio flatters light text on a dark
54
+ * ground, so a dark theme can pass AA everywhere and still set its secondary text at a level
55
+ * APCA rates as hard to read; Lc is measured the way a reader perceives it in both polarities.
56
+ *
57
+ * Published with the algorithm's version because an Lc means nothing without its constants:
58
+ * a consumer measuring with another APCA build would hold the same palette to different
59
+ * numbers. The floors are APCA's own levels: 90 its preferred level for fluent text, 75 its
60
+ * minimum for body text, 60 its minimum for content text that is not read as body text, which
61
+ * is how this sheet reads a count or a position. Every theme is held to them, the
62
+ * high-contrast one included, because the reading belongs to the text and not to the palette.
63
+ */
64
+ const APCA = {
65
+ version: "0.0.98G-4g",
66
+ minimumLc: { body: 90, secondary: 75, incidental: 60 },
67
+ };
68
+
51
69
  const registry = read("themes.json");
52
70
  const themes = registry.themes;
53
71
  const base = themes.find((theme) => theme.name === registry.base);
@@ -63,9 +81,24 @@ if (!themes.some((theme) => theme.name === registry.systemDark)) {
63
81
  if (registry.systemDark === registry.base) {
64
82
  throw new Error("themes.json: systemDark must not be the base theme");
65
83
  }
84
+ // Every name a theme answers to: its own, then the names it had before a rename. An alias is a
85
+ // data-theme value like any other, so it must be one, and no two themes may claim one name --
86
+ // the selector would then paint whichever block came last.
87
+ const namesOf = (theme) => [theme.name, ...(theme.aliases ?? [])];
88
+ const claimed = new Map();
89
+ for (const theme of themes) {
90
+ for (const name of namesOf(theme)) {
91
+ if (claimed.has(name)) {
92
+ throw new Error(`themes.json: "${name}" names both ${claimed.get(name)} and ${theme.name}`);
93
+ }
94
+ claimed.set(name, theme.name);
95
+ }
96
+ }
66
97
  for (const theme of themes) {
67
- if (!/^[a-z][a-z0-9-]*$/.test(theme.name)) {
68
- throw new Error(`themes.json: "${theme.name}" is not usable as a data-theme value`);
98
+ for (const name of namesOf(theme)) {
99
+ if (!/^[a-z][a-z0-9-]*$/.test(name)) {
100
+ throw new Error(`themes.json: "${name}" is not usable as a data-theme value`);
101
+ }
69
102
  }
70
103
  if (theme.appearance !== "light" && theme.appearance !== "dark") {
71
104
  throw new Error(`themes.json: ${theme.name} appearance must be "light" or "dark"`);
@@ -142,9 +175,11 @@ const appearanceSwitch = (appearance) =>
142
175
  const themeBlocks = overlays
143
176
  .map(
144
177
  (theme) => `
145
- /* ${theme.label}: an explicit choice via <html data-theme="${theme.name}">.
178
+ /* ${theme.label}: an explicit choice via <html data-theme="${theme.name}">${
179
+ theme.aliases?.length ? `, or its earlier name${theme.aliases.length > 1 ? "s" : ""} ${theme.aliases.map((alias) => `"${alias}"`).join(", ")}` : ""
180
+ }.
146
181
  ${theme.description} */
147
- [data-theme='${theme.name}'] {
182
+ ${namesOf(theme).map((name) => `[data-theme='${name}']`).join(",\n")} {
148
183
  color-scheme: ${theme.appearance};
149
184
  ${appearanceSwitch(theme.appearance)}
150
185
  ${compiled.get(theme.name)}
@@ -233,9 +268,12 @@ const manifest = {
233
268
  // alone rather than hard-coding the list it happens to know about.
234
269
  base: registry.base,
235
270
  systemDark: registry.systemDark,
236
- themes: themes.map(({ name, label, appearance, description, minimumContrast }) => ({
271
+ themes: themes.map(({ name, label, appearance, description, minimumContrast, aliases }) => ({
237
272
  name,
238
273
  label,
274
+ // The names this theme had before a rename. Accept them wherever a theme is named, and map
275
+ // them to `name`; the stylesheet already paints them as this theme.
276
+ aliases: aliases ?? [],
239
277
  appearance,
240
278
  description,
241
279
  // The ratio this theme's declared text pairings must reach, published as a NUMBER on every
@@ -264,6 +302,8 @@ const manifest = {
264
302
  // The floor for the `nonTextPairs` section below — flat across themes, unlike the per-theme
265
303
  // text floor above. Named at the top level so the two sections cannot be read as sharing a bar.
266
304
  nonTextMinimumContrast: UI_COMPONENT,
305
+ // The second bar a text pairing is held to, keyed by the `reading` each pairing declares.
306
+ apca: APCA,
267
307
  textPairs: pairs.textPairs,
268
308
  // Both sections, because a consumer that can only see the text pairings would read the
269
309
  // absence of a boundary pairing as "no requirement" rather than "held elsewhere".
package/src/schema.d.ts CHANGED
@@ -141,6 +141,23 @@ export interface paths {
141
141
  patch?: never;
142
142
  trace?: never;
143
143
  };
144
+ "/api/v1/audit/activity": {
145
+ parameters: {
146
+ query?: never;
147
+ header?: never;
148
+ path?: never;
149
+ cookie?: never;
150
+ };
151
+ /** View how much the audit trail records per day */
152
+ get: operations["audit.read_activity"];
153
+ put?: never;
154
+ post?: never;
155
+ delete?: never;
156
+ options?: never;
157
+ head?: never;
158
+ patch?: never;
159
+ trace?: never;
160
+ };
144
161
  "/api/v1/auth/login": {
145
162
  parameters: {
146
163
  query?: never;
@@ -531,6 +548,52 @@ export interface components {
531
548
  */
532
549
  token_type: string;
533
550
  };
551
+ /**
552
+ * AuditActionCount
553
+ * @description How many events in the window record one action.
554
+ */
555
+ AuditActionCount: {
556
+ /** Action */
557
+ action: string;
558
+ /** Count */
559
+ count: number;
560
+ };
561
+ /**
562
+ * AuditActivityRead
563
+ * @description The trail's activity over the last ``days`` calendar days, counted in one time zone.
564
+ *
565
+ * ``days`` runs oldest first and ends today, with a zero for a day that holds nothing, so a
566
+ * chart can draw it as it comes. ``previous_days`` is the same number of days just before,
567
+ * for a comparison. The two breakdowns and ``total`` cover ``days`` only, and
568
+ * ``by_target_type`` is the most changed types, most first.
569
+ */
570
+ AuditActivityRead: {
571
+ /** By Action */
572
+ by_action: components["schemas"]["AuditActionCount"][];
573
+ /** By Target Type */
574
+ by_target_type: components["schemas"]["AuditTargetCount"][];
575
+ /** Days */
576
+ days: components["schemas"]["AuditDayCount"][];
577
+ /** Previous Days */
578
+ previous_days: components["schemas"]["AuditDayCount"][];
579
+ /** Time Zone */
580
+ time_zone: string;
581
+ /** Total */
582
+ total: number;
583
+ };
584
+ /**
585
+ * AuditDayCount
586
+ * @description How many events one calendar day of the requested time zone holds.
587
+ */
588
+ AuditDayCount: {
589
+ /** Count */
590
+ count: number;
591
+ /**
592
+ * Date
593
+ * Format: date
594
+ */
595
+ date: string;
596
+ };
534
597
  /** AuditEventRead */
535
598
  AuditEventRead: {
536
599
  /** Action */
@@ -558,6 +621,16 @@ export interface components {
558
621
  /** Target Type */
559
622
  target_type: string;
560
623
  };
624
+ /**
625
+ * AuditTargetCount
626
+ * @description How many events in the window are about records of one type.
627
+ */
628
+ AuditTargetCount: {
629
+ /** Count */
630
+ count: number;
631
+ /** Target Type */
632
+ target_type: string;
633
+ };
561
634
  /**
562
635
  * CurrentUser
563
636
  * @description The authenticated caller's own identity — the ``/me`` (who-am-I) response.
@@ -1225,6 +1298,10 @@ export interface operations {
1225
1298
  "audit.list_events": {
1226
1299
  parameters: {
1227
1300
  query?: {
1301
+ /** @description Only events about records of this type -- the model's name, e.g. 'User'. */
1302
+ target_type?: string | null;
1303
+ /** @description Only events about the record with this id. */
1304
+ target_id?: string | null;
1228
1305
  /** @description Rows to skip. */
1229
1306
  skip?: number;
1230
1307
  /** @description Maximum rows to return. */
@@ -1256,6 +1333,40 @@ export interface operations {
1256
1333
  };
1257
1334
  };
1258
1335
  };
1336
+ "audit.read_activity": {
1337
+ parameters: {
1338
+ query?: {
1339
+ /** @description How many calendar days to count, ending today; the days before are counted too. */
1340
+ days?: number;
1341
+ /** @description The IANA time zone whose calendar days are counted, e.g. 'Europe/Amsterdam'. */
1342
+ time_zone?: string;
1343
+ };
1344
+ header?: never;
1345
+ path?: never;
1346
+ cookie?: never;
1347
+ };
1348
+ requestBody?: never;
1349
+ responses: {
1350
+ /** @description Successful Response */
1351
+ 200: {
1352
+ headers: {
1353
+ [name: string]: unknown;
1354
+ };
1355
+ content: {
1356
+ "application/json": components["schemas"]["AuditActivityRead"];
1357
+ };
1358
+ };
1359
+ /** @description Validation Error */
1360
+ 422: {
1361
+ headers: {
1362
+ [name: string]: unknown;
1363
+ };
1364
+ content: {
1365
+ "application/json": components["schemas"]["HTTPValidationError"];
1366
+ };
1367
+ };
1368
+ };
1369
+ };
1259
1370
  "auth.login": {
1260
1371
  parameters: {
1261
1372
  query?: never;
@@ -1615,6 +1726,8 @@ export interface operations {
1615
1726
  query?: {
1616
1727
  /** @description Filter to users whose email contains this text (case-insensitive). */
1617
1728
  email?: string | null;
1729
+ /** @description Filter to active accounts (true) or deactivated ones (false). */
1730
+ is_active?: boolean | null;
1618
1731
  /** @description Rows to skip. */
1619
1732
  skip?: number;
1620
1733
  /** @description Maximum rows to return. */