identityscope 0.0.0-stage → 0.28.3

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 (333) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +917 -3
  3. package/SECURITY.md +56 -0
  4. package/dist/core/audit-readiness.d.ts +158 -0
  5. package/dist/core/audit-readiness.js +357 -0
  6. package/dist/core/audit-readiness.js.map +1 -0
  7. package/dist/core/certs.d.ts +68 -0
  8. package/dist/core/certs.js +132 -0
  9. package/dist/core/certs.js.map +1 -0
  10. package/dist/core/checks.d.ts +133 -0
  11. package/dist/core/checks.js +512 -0
  12. package/dist/core/checks.js.map +1 -0
  13. package/dist/core/cloud-rules.d.ts +20 -0
  14. package/dist/core/cloud-rules.js +44 -0
  15. package/dist/core/cloud-rules.js.map +1 -0
  16. package/dist/core/compare.d.ts +45 -0
  17. package/dist/core/compare.js +372 -0
  18. package/dist/core/compare.js.map +1 -0
  19. package/dist/core/conditions.d.ts +10 -0
  20. package/dist/core/conditions.js +201 -0
  21. package/dist/core/conditions.js.map +1 -0
  22. package/dist/core/credentials.d.ts +71 -0
  23. package/dist/core/credentials.js +211 -0
  24. package/dist/core/credentials.js.map +1 -0
  25. package/dist/core/datasets.d.ts +53 -0
  26. package/dist/core/datasets.js +596 -0
  27. package/dist/core/datasets.js.map +1 -0
  28. package/dist/core/definition.d.ts +32 -0
  29. package/dist/core/definition.js +301 -0
  30. package/dist/core/definition.js.map +1 -0
  31. package/dist/core/discover.d.ts +32 -0
  32. package/dist/core/discover.js +105 -0
  33. package/dist/core/discover.js.map +1 -0
  34. package/dist/core/engine.d.ts +18 -0
  35. package/dist/core/engine.js +290 -0
  36. package/dist/core/engine.js.map +1 -0
  37. package/dist/core/fields.d.ts +16 -0
  38. package/dist/core/fields.js +132 -0
  39. package/dist/core/fields.js.map +1 -0
  40. package/dist/core/governance-trail.d.ts +211 -0
  41. package/dist/core/governance-trail.js +557 -0
  42. package/dist/core/governance-trail.js.map +1 -0
  43. package/dist/core/http-transport.d.ts +66 -0
  44. package/dist/core/http-transport.js +247 -0
  45. package/dist/core/http-transport.js.map +1 -0
  46. package/dist/core/index.d.ts +13 -0
  47. package/dist/core/index.js +16 -0
  48. package/dist/core/index.js.map +1 -0
  49. package/dist/core/insights.d.ts +176 -0
  50. package/dist/core/insights.js +417 -0
  51. package/dist/core/insights.js.map +1 -0
  52. package/dist/core/joiner-evidence.d.ts +98 -0
  53. package/dist/core/joiner-evidence.js +254 -0
  54. package/dist/core/joiner-evidence.js.map +1 -0
  55. package/dist/core/lab/credential-map.d.ts +50 -0
  56. package/dist/core/lab/credential-map.js +163 -0
  57. package/dist/core/lab/credential-map.js.map +1 -0
  58. package/dist/core/lab/javadate.d.ts +7 -0
  59. package/dist/core/lab/javadate.js +307 -0
  60. package/dist/core/lab/javadate.js.map +1 -0
  61. package/dist/core/lab/jsonpath.d.ts +11 -0
  62. package/dist/core/lab/jsonpath.js +273 -0
  63. package/dist/core/lab/jsonpath.js.map +1 -0
  64. package/dist/core/lab/policy-preview.d.ts +43 -0
  65. package/dist/core/lab/policy-preview.js +78 -0
  66. package/dist/core/lab/policy-preview.js.map +1 -0
  67. package/dist/core/lab/rfc5646.d.ts +2 -0
  68. package/dist/core/lab/rfc5646.js +421 -0
  69. package/dist/core/lab/rfc5646.js.map +1 -0
  70. package/dist/core/lab/transform-impact.d.ts +63 -0
  71. package/dist/core/lab/transform-impact.js +138 -0
  72. package/dist/core/lab/transform-impact.js.map +1 -0
  73. package/dist/core/lab/transform-people.d.ts +61 -0
  74. package/dist/core/lab/transform-people.js +132 -0
  75. package/dist/core/lab/transform-people.js.map +1 -0
  76. package/dist/core/lab/transforms.d.ts +79 -0
  77. package/dist/core/lab/transforms.js +738 -0
  78. package/dist/core/lab/transforms.js.map +1 -0
  79. package/dist/core/lab/velocity.d.ts +33 -0
  80. package/dist/core/lab/velocity.js +874 -0
  81. package/dist/core/lab/velocity.js.map +1 -0
  82. package/dist/core/lab/workflow-health.d.ts +80 -0
  83. package/dist/core/lab/workflow-health.js +234 -0
  84. package/dist/core/lab/workflow-health.js.map +1 -0
  85. package/dist/core/lab/workflows.d.ts +87 -0
  86. package/dist/core/lab/workflows.js +568 -0
  87. package/dist/core/lab/workflows.js.map +1 -0
  88. package/dist/core/lifecycle-gaps.d.ts +192 -0
  89. package/dist/core/lifecycle-gaps.js +389 -0
  90. package/dist/core/lifecycle-gaps.js.map +1 -0
  91. package/dist/core/logs.d.ts +145 -0
  92. package/dist/core/logs.js +342 -0
  93. package/dist/core/logs.js.map +1 -0
  94. package/dist/core/lookup.d.ts +129 -0
  95. package/dist/core/lookup.js +289 -0
  96. package/dist/core/lookup.js.map +1 -0
  97. package/dist/core/model-insights.d.ts +247 -0
  98. package/dist/core/model-insights.js +474 -0
  99. package/dist/core/model-insights.js.map +1 -0
  100. package/dist/core/narrow.d.ts +23 -0
  101. package/dist/core/narrow.js +137 -0
  102. package/dist/core/narrow.js.map +1 -0
  103. package/dist/core/nerm.d.ts +154 -0
  104. package/dist/core/nerm.js +397 -0
  105. package/dist/core/nerm.js.map +1 -0
  106. package/dist/core/operations-watch.d.ts +232 -0
  107. package/dist/core/operations-watch.js +491 -0
  108. package/dist/core/operations-watch.js.map +1 -0
  109. package/dist/core/output/csv.d.ts +6 -0
  110. package/dist/core/output/csv.js +22 -0
  111. package/dist/core/output/csv.js.map +1 -0
  112. package/dist/core/output/html.d.ts +11 -0
  113. package/dist/core/output/html.js +66 -0
  114. package/dist/core/output/html.js.map +1 -0
  115. package/dist/core/output/xlsx.d.ts +3 -0
  116. package/dist/core/output/xlsx.js +130 -0
  117. package/dist/core/output/xlsx.js.map +1 -0
  118. package/dist/core/output/zip.d.ts +16 -0
  119. package/dist/core/output/zip.js +106 -0
  120. package/dist/core/output/zip.js.map +1 -0
  121. package/dist/core/ownership.d.ts +39 -0
  122. package/dist/core/ownership.js +100 -0
  123. package/dist/core/ownership.js.map +1 -0
  124. package/dist/core/patterns.d.ts +11 -0
  125. package/dist/core/patterns.js +31 -0
  126. package/dist/core/patterns.js.map +1 -0
  127. package/dist/core/preview.d.ts +96 -0
  128. package/dist/core/preview.js +173 -0
  129. package/dist/core/preview.js.map +1 -0
  130. package/dist/core/roles.d.ts +125 -0
  131. package/dist/core/roles.js +420 -0
  132. package/dist/core/roles.js.map +1 -0
  133. package/dist/core/tenant.d.ts +67 -0
  134. package/dist/core/tenant.js +194 -0
  135. package/dist/core/tenant.js.map +1 -0
  136. package/dist/core/threat-signals.d.ts +112 -0
  137. package/dist/core/threat-signals.js +250 -0
  138. package/dist/core/threat-signals.js.map +1 -0
  139. package/dist/core/threat-watch.d.ts +144 -0
  140. package/dist/core/threat-watch.js +282 -0
  141. package/dist/core/threat-watch.js.map +1 -0
  142. package/dist/core/transport.d.ts +82 -0
  143. package/dist/core/transport.js +312 -0
  144. package/dist/core/transport.js.map +1 -0
  145. package/dist/core/types.d.ts +137 -0
  146. package/dist/core/types.js +10 -0
  147. package/dist/core/types.js.map +1 -0
  148. package/dist/core/warnings.d.ts +236 -0
  149. package/dist/core/warnings.js +504 -0
  150. package/dist/core/warnings.js.map +1 -0
  151. package/dist/demo/tenant.d.ts +1572 -0
  152. package/dist/demo/tenant.js +1023 -0
  153. package/dist/demo/tenant.js.map +1 -0
  154. package/dist/node/attribute-history.d.ts +22 -0
  155. package/dist/node/attribute-history.js +86 -0
  156. package/dist/node/attribute-history.js.map +1 -0
  157. package/dist/node/changes.d.ts +20 -0
  158. package/dist/node/changes.js +78 -0
  159. package/dist/node/changes.js.map +1 -0
  160. package/dist/node/cli.d.ts +2 -0
  161. package/dist/node/cli.js +291 -0
  162. package/dist/node/cli.js.map +1 -0
  163. package/dist/node/config.d.ts +72 -0
  164. package/dist/node/config.js +203 -0
  165. package/dist/node/config.js.map +1 -0
  166. package/dist/node/credentials.d.ts +13 -0
  167. package/dist/node/credentials.js +24 -0
  168. package/dist/node/credentials.js.map +1 -0
  169. package/dist/node/delivery.d.ts +10 -0
  170. package/dist/node/delivery.js +105 -0
  171. package/dist/node/delivery.js.map +1 -0
  172. package/dist/node/doctor.d.ts +2 -0
  173. package/dist/node/doctor.js +151 -0
  174. package/dist/node/doctor.js.map +1 -0
  175. package/dist/node/drift.d.ts +31 -0
  176. package/dist/node/drift.js +56 -0
  177. package/dist/node/drift.js.map +1 -0
  178. package/dist/node/evidence.d.ts +42 -0
  179. package/dist/node/evidence.js +129 -0
  180. package/dist/node/evidence.js.map +1 -0
  181. package/dist/node/exceptions.d.ts +30 -0
  182. package/dist/node/exceptions.js +83 -0
  183. package/dist/node/exceptions.js.map +1 -0
  184. package/dist/node/history.d.ts +35 -0
  185. package/dist/node/history.js +74 -0
  186. package/dist/node/history.js.map +1 -0
  187. package/dist/node/index.d.ts +7 -0
  188. package/dist/node/index.js +8 -0
  189. package/dist/node/index.js.map +1 -0
  190. package/dist/node/keep.d.ts +9 -0
  191. package/dist/node/keep.js +39 -0
  192. package/dist/node/keep.js.map +1 -0
  193. package/dist/node/loader.d.ts +7 -0
  194. package/dist/node/loader.js +35 -0
  195. package/dist/node/loader.js.map +1 -0
  196. package/dist/node/log-files.d.ts +16 -0
  197. package/dist/node/log-files.js +93 -0
  198. package/dist/node/log-files.js.map +1 -0
  199. package/dist/node/monthly.d.ts +41 -0
  200. package/dist/node/monthly.js +108 -0
  201. package/dist/node/monthly.js.map +1 -0
  202. package/dist/node/oauth-login.d.ts +45 -0
  203. package/dist/node/oauth-login.js +121 -0
  204. package/dist/node/oauth-login.js.map +1 -0
  205. package/dist/node/packs.d.ts +32 -0
  206. package/dist/node/packs.js +43 -0
  207. package/dist/node/packs.js.map +1 -0
  208. package/dist/node/privileged-seen.d.ts +11 -0
  209. package/dist/node/privileged-seen.js +41 -0
  210. package/dist/node/privileged-seen.js.map +1 -0
  211. package/dist/node/recipients.d.ts +17 -0
  212. package/dist/node/recipients.js +51 -0
  213. package/dist/node/recipients.js.map +1 -0
  214. package/dist/node/runner.d.ts +51 -0
  215. package/dist/node/runner.js +298 -0
  216. package/dist/node/runner.js.map +1 -0
  217. package/dist/node/runtime.d.ts +12 -0
  218. package/dist/node/runtime.js +13 -0
  219. package/dist/node/runtime.js.map +1 -0
  220. package/dist/node/schedules.d.ts +87 -0
  221. package/dist/node/schedules.js +141 -0
  222. package/dist/node/schedules.js.map +1 -0
  223. package/dist/node/secrets.d.ts +37 -0
  224. package/dist/node/secrets.js +219 -0
  225. package/dist/node/secrets.js.map +1 -0
  226. package/dist/node/support.d.ts +14 -0
  227. package/dist/node/support.js +133 -0
  228. package/dist/node/support.js.map +1 -0
  229. package/dist/node/tenants.d.ts +93 -0
  230. package/dist/node/tenants.js +255 -0
  231. package/dist/node/tenants.js.map +1 -0
  232. package/dist/node/ui-page.d.ts +1 -0
  233. package/dist/node/ui-page.js +3 -0
  234. package/dist/node/ui-page.js.map +1 -0
  235. package/dist/node/ui-server.d.ts +48 -0
  236. package/dist/node/ui-server.js +2665 -0
  237. package/dist/node/ui-server.js.map +1 -0
  238. package/dist/node/write.d.ts +9 -0
  239. package/dist/node/write.js +53 -0
  240. package/dist/node/write.js.map +1 -0
  241. package/dist/reports/builtin.generated.d.ts +1 -0
  242. package/dist/reports/builtin.generated.js +49 -0
  243. package/dist/reports/builtin.generated.js.map +1 -0
  244. package/dist/reports/library.d.ts +6 -0
  245. package/dist/reports/library.js +18 -0
  246. package/dist/reports/library.js.map +1 -0
  247. package/launcher/IdentityScope.cmd +11 -0
  248. package/package.json +69 -4
  249. package/reports/access-profile-members.yaml +29 -0
  250. package/reports/access-profile-membership-counts.yaml +17 -0
  251. package/reports/access-profiles-without-owner.yaml +16 -0
  252. package/reports/access-request-audit-trail.yaml +36 -0
  253. package/reports/accounts-by-source.yaml +19 -0
  254. package/reports/active-identities-without-manager.yaml +22 -0
  255. package/reports/aggregation-failures.yaml +29 -0
  256. package/reports/aggregation-history.yaml +27 -0
  257. package/reports/all-sources.yaml +16 -0
  258. package/reports/application-accounts.yaml +32 -0
  259. package/reports/application-entitlements.yaml +31 -0
  260. package/reports/campaign-progress.yaml +23 -0
  261. package/reports/certification-decisions.yaml +31 -0
  262. package/reports/direct-reports-per-manager.yaml +20 -0
  263. package/reports/disabled-accounts-of-active-people.yaml +33 -0
  264. package/reports/duplicate-emails.yaml +16 -0
  265. package/reports/entitlement-holders.yaml +35 -0
  266. package/reports/entitlements-held-by-inactive-identities.yaml +31 -0
  267. package/reports/entitlements-without-owner.yaml +28 -0
  268. package/reports/identities-by-lifecycle-state.yaml +15 -0
  269. package/reports/identities-missing-key-attributes.yaml +27 -0
  270. package/reports/identities-with-processing-errors.yaml +19 -0
  271. package/reports/identity-attribute-mappings.yaml +27 -0
  272. package/reports/machine-accounts.yaml +28 -0
  273. package/reports/managers-and-direct-reports.yaml +23 -0
  274. package/reports/most-access.yaml +18 -0
  275. package/reports/new-identities.yaml +24 -0
  276. package/reports/old-passwords.yaml +35 -0
  277. package/reports/pending-reviews-by-reviewer.yaml +20 -0
  278. package/reports/person-access.yaml +31 -0
  279. package/reports/privileged-access.yaml +29 -0
  280. package/reports/provisioning-error-causes.yaml +27 -0
  281. package/reports/provisioning-errors.yaml +32 -0
  282. package/reports/provisioning-failures.yaml +28 -0
  283. package/reports/recent-access-requests.yaml +22 -0
  284. package/reports/recent-activity.yaml +32 -0
  285. package/reports/recent-leavers.yaml +34 -0
  286. package/reports/role-members.yaml +29 -0
  287. package/reports/role-membership-counts.yaml +18 -0
  288. package/reports/roles-without-owner.yaml +17 -0
  289. package/reports/sources-needing-attention.yaml +23 -0
  290. package/reports/stuck-access-requests.yaml +29 -0
  291. package/reports/team-access.yaml +30 -0
  292. package/reports/terminated-users-with-active-accounts.yaml +46 -0
  293. package/reports/uncorrelated-accounts.yaml +38 -0
  294. package/ui/js/00-setup.js +6 -0
  295. package/ui/js/01-small-helpers.js +143 -0
  296. package/ui/js/02-connection.js +150 -0
  297. package/ui/js/03-health-check.js +17 -0
  298. package/ui/js/04-library.js +135 -0
  299. package/ui/js/05-pickers.js +163 -0
  300. package/ui/js/06-report-view.js +157 -0
  301. package/ui/js/07-fields.js +85 -0
  302. package/ui/js/08-designer.js +360 -0
  303. package/ui/js/09-yaml.js +22 -0
  304. package/ui/js/10-instant-check.js +171 -0
  305. package/ui/js/11-lookup.js +161 -0
  306. package/ui/js/12-tenant.js +115 -0
  307. package/ui/js/13-source-configuration-and-diagnostics.js +64 -0
  308. package/ui/js/14-certifications.js +68 -0
  309. package/ui/js/15-monthly-report.js +24 -0
  310. package/ui/js/16-ownership.js +39 -0
  311. package/ui/js/17-compare-tenants.js +102 -0
  312. package/ui/js/18-audit.js +181 -0
  313. package/ui/js/19-insights.js +108 -0
  314. package/ui/js/20-role-mining.js +35 -0
  315. package/ui/js/21-share-reports.js +45 -0
  316. package/ui/js/22-partner-overview-all-customer-tenants.js +228 -0
  317. package/ui/js/23-in-app-guidance.js +217 -0
  318. package/ui/js/24-role-tools.js +220 -0
  319. package/ui/js/25-schedules.js +264 -0
  320. package/ui/js/26-start.js +7 -0
  321. package/ui/js/27-warnings.js +224 -0
  322. package/ui/js/28-audit-readiness.js +99 -0
  323. package/ui/js/29-lifecycle.js +182 -0
  324. package/ui/js/30-labs.js +265 -0
  325. package/ui/js/31-build.js +203 -0
  326. package/ui/js/32-lab-examples.js +148 -0
  327. package/ui/js/33-finder.js +89 -0
  328. package/ui/js/34-governance.js +129 -0
  329. package/ui/js/35-watch.js +266 -0
  330. package/ui/js/36-model.js +247 -0
  331. package/ui/js/37-logs-and-watch.js +224 -0
  332. package/ui/shell.html +112 -0
  333. package/ui/style.css +350 -0
@@ -0,0 +1,30 @@
1
+ export interface AcceptedException {
2
+ id: string;
3
+ tenant: string;
4
+ check: string;
5
+ checkLabel: string;
6
+ /** The row's key, as the instant check shows it (for example "svc_backup | Active Directory"). */
7
+ key: string;
8
+ reason: string;
9
+ acceptedBy: string;
10
+ /** Last day it applies (YYYY-MM-DD). */
11
+ until: string;
12
+ created: string;
13
+ /** Set when someone ended it early. */
14
+ ended?: string;
15
+ endedBy?: string;
16
+ }
17
+ export declare function readExceptions(home: string): AcceptedException[];
18
+ export type ExceptionState = 'in force' | 'expired' | 'ended';
19
+ export declare function stateOf(e: AcceptedException, now?: Date): ExceptionState;
20
+ /** Check id → keys of exceptions in force for this tenant. */
21
+ export declare function acceptedFor(home: string, tenant: string, now?: Date): Record<string, string[]>;
22
+ export declare function validateException(b: Record<string, unknown>, checks: {
23
+ id: string;
24
+ label: string;
25
+ }[], now?: Date): {
26
+ value?: Omit<AcceptedException, 'id' | 'tenant' | 'created'>;
27
+ problems: string[];
28
+ };
29
+ export declare function addException(home: string, tenant: string, v: Omit<AcceptedException, 'id' | 'tenant' | 'created'>, now?: Date): AcceptedException;
30
+ export declare function endException(home: string, id: string, by: string, now?: Date): AcceptedException | undefined;
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Accepted exceptions: a known finding that someone with authority accepted,
3
+ * with a reason and an end date. Kept on this computer (exceptions.json,
4
+ * owner-only), per tenant. Ended or expired exceptions stay in the file as a
5
+ * record; they simply no longer apply.
6
+ */
7
+ import { randomUUID } from 'node:crypto';
8
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
9
+ import { join } from 'node:path';
10
+ const file = (home) => join(home, 'exceptions.json');
11
+ export function readExceptions(home) {
12
+ try {
13
+ return existsSync(file(home)) ? JSON.parse(readFileSync(file(home), 'utf8')) : [];
14
+ }
15
+ catch {
16
+ return [];
17
+ }
18
+ }
19
+ const write = (home, list) => writeFileSync(file(home), JSON.stringify(list, null, 2), { mode: 0o600 });
20
+ export function stateOf(e, now = new Date()) {
21
+ if (e.ended)
22
+ return 'ended';
23
+ return e.until >= now.toISOString().slice(0, 10) ? 'in force' : 'expired';
24
+ }
25
+ /** Check id → keys of exceptions in force for this tenant. */
26
+ export function acceptedFor(home, tenant, now = new Date()) {
27
+ const out = {};
28
+ for (const e of readExceptions(home))
29
+ if (e.tenant === tenant && stateOf(e, now) === 'in force')
30
+ (out[e.check] ??= []).push(e.key);
31
+ return out;
32
+ }
33
+ export function validateException(b, checks, now = new Date()) {
34
+ const problems = [];
35
+ const check = checks.find((c) => c.id === b['check']);
36
+ if (!check)
37
+ problems.push('Unknown check');
38
+ const key = String(b['key'] ?? '').trim();
39
+ if (!key || key.length > 500)
40
+ problems.push('The item to accept is missing or too long');
41
+ const reason = String(b['reason'] ?? '').trim();
42
+ if (reason.length < 5 || reason.length > 500)
43
+ problems.push('Give a reason of 5 to 500 characters');
44
+ const acceptedBy = String(b['acceptedBy'] ?? '').trim();
45
+ if (acceptedBy.length < 2 || acceptedBy.length > 120)
46
+ problems.push('Say who accepted it (2 to 120 characters)');
47
+ const until = String(b['until'] ?? '').trim();
48
+ const today = now.toISOString().slice(0, 10);
49
+ const max = new Date(now.getTime() + 2 * 366 * 86_400_000).toISOString().slice(0, 10);
50
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(until) || Number.isNaN(Date.parse(until)))
51
+ problems.push('Give an end date');
52
+ else if (until < today)
53
+ problems.push('The end date is in the past');
54
+ else if (until > max)
55
+ problems.push('Accept for at most two years; review it again then');
56
+ if (problems.length)
57
+ return { problems };
58
+ return { value: { check: check.id, checkLabel: check.label, key, reason, acceptedBy, until }, problems };
59
+ }
60
+ export function addException(home, tenant, v, now = new Date()) {
61
+ const list = readExceptions(home);
62
+ // Accepting the same item again replaces the one in force.
63
+ for (const e of list)
64
+ if (e.tenant === tenant && e.check === v.check && e.key === v.key && stateOf(e, now) === 'in force') {
65
+ e.ended = now.toISOString();
66
+ e.endedBy = `${v.acceptedBy} (replaced)`;
67
+ }
68
+ const e = { id: randomUUID(), tenant, created: now.toISOString(), ...v };
69
+ list.push(e);
70
+ write(home, list);
71
+ return e;
72
+ }
73
+ export function endException(home, id, by, now = new Date()) {
74
+ const list = readExceptions(home);
75
+ const e = list.find((x) => x.id === id);
76
+ if (!e || e.ended)
77
+ return e;
78
+ e.ended = now.toISOString();
79
+ e.endedBy = by.slice(0, 120) || 'unknown';
80
+ write(home, list);
81
+ return e;
82
+ }
83
+ //# sour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CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,SAAS,CAAC;IAC1C,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAClB,OAAO,CAAC,CAAC;AACX,CAAC"}
@@ -0,0 +1,35 @@
1
+ import type { CheckPrevious, CheckResult, CheckStatus } from '../core/checks.js';
2
+ /**
3
+ * Local memory of past checks and scheduled runs, per tenant: the numbers for
4
+ * trends, the status, and identifiers of rows already seen (to tell what is
5
+ * new). It holds no report data beyond those identifiers. Owner-only file.
6
+ */
7
+ export interface TrendPoint {
8
+ at: string;
9
+ value: number | null;
10
+ status: CheckStatus;
11
+ }
12
+ export declare class History {
13
+ private readonly file;
14
+ private data;
15
+ constructor(file: string);
16
+ private static read;
17
+ private tenant;
18
+ save(): void;
19
+ previousChecks(tenant: string): Record<string, CheckPrevious & {
20
+ status?: CheckStatus;
21
+ }>;
22
+ recordChecks(tenant: string, results: CheckResult[], at?: string): void;
23
+ trends(tenant: string): Record<string, {
24
+ points: TrendPoint[];
25
+ status?: CheckStatus;
26
+ summary?: string;
27
+ }>;
28
+ jobMemory(tenant: string, job: string): {
29
+ at: string;
30
+ keys: string[];
31
+ status?: CheckStatus;
32
+ statuses?: Record<string, CheckStatus>;
33
+ };
34
+ rememberJob(tenant: string, job: string, keys: string[], statuses?: Record<string, CheckStatus>): void;
35
+ }
@@ -0,0 +1,74 @@
1
+ import { chmodSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
2
+ import { dirname } from 'node:path';
3
+ const MAX_POINTS = 400;
4
+ export class History {
5
+ file;
6
+ data;
7
+ constructor(file) {
8
+ this.file = file;
9
+ this.data = History.read(file);
10
+ }
11
+ static read(file) {
12
+ try {
13
+ const d = JSON.parse(readFileSync(file, 'utf8'));
14
+ if (d && d.version === 1 && d.tenants)
15
+ return d;
16
+ }
17
+ catch {
18
+ /* no history yet */
19
+ }
20
+ return { version: 1, tenants: {} };
21
+ }
22
+ tenant(t) {
23
+ const key = t.toLowerCase();
24
+ return (this.data.tenants[key] ??= { checks: {}, jobs: {} });
25
+ }
26
+ save() {
27
+ mkdirSync(dirname(this.file), { recursive: true });
28
+ const tmp = `${this.file}.tmp`;
29
+ writeFileSync(tmp, JSON.stringify(this.data), { mode: 0o600 });
30
+ renameSync(tmp, this.file);
31
+ try {
32
+ chmodSync(this.file, 0o600);
33
+ }
34
+ catch {
35
+ /* Windows */
36
+ }
37
+ }
38
+ previousChecks(tenant) {
39
+ const out = {};
40
+ for (const [id, m] of Object.entries(this.tenant(tenant).checks)) {
41
+ const last = m.points[m.points.length - 1];
42
+ out[id] = { value: last?.value ?? null, keys: m.keys, status: m.status };
43
+ }
44
+ return out;
45
+ }
46
+ recordChecks(tenant, results, at = new Date().toISOString()) {
47
+ const t = this.tenant(tenant);
48
+ for (const r of results) {
49
+ const m = (t.checks[r.id] ??= { points: [] });
50
+ m.points.push({ at, value: r.value, status: r.status });
51
+ if (m.points.length > MAX_POINTS)
52
+ m.points.splice(0, m.points.length - MAX_POINTS);
53
+ if (r.status !== 'error')
54
+ m.keys = r.keys;
55
+ m.status = r.status;
56
+ m.summary = r.summary;
57
+ }
58
+ this.save();
59
+ }
60
+ trends(tenant) {
61
+ const out = {};
62
+ for (const [id, m] of Object.entries(this.tenant(tenant).checks))
63
+ out[id] = { points: m.points, status: m.status, summary: m.summary };
64
+ return out;
65
+ }
66
+ jobMemory(tenant, job) {
67
+ return this.tenant(tenant).jobs[job];
68
+ }
69
+ rememberJob(tenant, job, keys, statuses) {
70
+ this.tenant(tenant).jobs[job] = { at: new Date().toISOString(), keys: keys.slice(0, 5000), statuses };
71
+ this.save();
72
+ }
73
+ }
74
+ //# sourceMappingURL=history.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/node/history.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC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0 +1,7 @@
1
+ export * from '../core/index.js';
2
+ export { loadConfig, parseConfig, ConfigError, type RunnerConfig, type Job } from './config.js';
3
+ export { runJob, runOnce, startScheduler, type JobOutcome, type RunnerDeps } from './runner.js';
4
+ export { sendEmail, sendWebhook, createMailer, type Mailer } from './delivery.js';
5
+ export { loadReport, listCustom } from './loader.js';
6
+ export { credentialsFromEnv, transportFor } from './credentials.js';
7
+ export { writeOutputs, render, FORMATS, type Format } from './write.js';
@@ -0,0 +1,8 @@
1
+ export * from '../core/index.js';
2
+ export { loadConfig, parseConfig, ConfigError } from './config.js';
3
+ export { runJob, runOnce, startScheduler } from './runner.js';
4
+ export { sendEmail, sendWebhook, createMailer } from './delivery.js';
5
+ export { loadReport, listCustom } from './loader.js';
6
+ export { credentialsFromEnv, transportFor } from './credentials.js';
7
+ export { writeOutputs, render, FORMATS } from './write.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAA+B,MAAM,aAAa,CAAC;AAChG,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,EAAoC,MAAM,aAAa,CAAC;AAChG,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAe,MAAM,eAAe,CAAC;AAClF,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,EAAe,MAAM,YAAY,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { CountPoint } from '../core/warnings.js';
2
+ /** Keeps one count per day per tenant, at most three years. */
3
+ export declare function recordCount(home: string, tenant: string, p: CountPoint): CountPoint[];
4
+ export declare const readCounts: (home: string, tenant: string) => CountPoint[];
5
+ /** Returns the IDs that are new since the last look (none on the first look) and remembers the current ones. */
6
+ export declare function newAdmins(home: string, tenant: string, ids: string[], at: string): {
7
+ fresh: Set<string>;
8
+ since: string | null;
9
+ };
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Small things kept on this computer per tenant, for the Warnings page:
3
+ * identity counts over time (for the forecast) and who held ISC admin rights
4
+ * at the last look (to mark new ones). Owner-only files, no secrets.
5
+ */
6
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
7
+ import { join } from 'node:path';
8
+ function read(file, fallback) {
9
+ try {
10
+ return existsSync(file) ? JSON.parse(readFileSync(file, 'utf8')) : fallback;
11
+ }
12
+ catch {
13
+ return fallback;
14
+ }
15
+ }
16
+ const write = (file, v) => writeFileSync(file, JSON.stringify(v, null, 2), { mode: 0o600 });
17
+ /** Keeps one count per day per tenant, at most three years. */
18
+ export function recordCount(home, tenant, p) {
19
+ const file = join(home, 'identity-counts.json');
20
+ const all = read(file, {});
21
+ const list = (all[tenant] ?? []).filter((x) => x.date !== p.date);
22
+ list.push(p);
23
+ list.sort((a, b) => a.date.localeCompare(b.date));
24
+ all[tenant] = list.slice(-1100);
25
+ write(file, all);
26
+ return all[tenant];
27
+ }
28
+ export const readCounts = (home, tenant) => read(join(home, 'identity-counts.json'), {})[tenant] ?? [];
29
+ /** Returns the IDs that are new since the last look (none on the first look) and remembers the current ones. */
30
+ export function newAdmins(home, tenant, ids, at) {
31
+ const file = join(home, 'isc-admins-seen.json');
32
+ const all = read(file, {});
33
+ const prev = all[tenant];
34
+ const fresh = new Set(prev ? ids.filter((i) => !prev.ids.includes(i)) : []);
35
+ all[tenant] = { ids: [...new Set(ids)], at };
36
+ write(file, all);
37
+ return { fresh, since: prev?.at ?? null };
38
+ }
39
+ //# sourceMappingURL=keep.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keep.js","sourceRoot":"","sources":["../../src/node/keep.ts"],"names":[],"mappings":"AAAA;;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I,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC;IAChC,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACjB,OAAO,GAAG,CAAC,MAAM,CAAE,CAAC;AACtB,CAAC;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,MAAc,EAAgB,EAAE,CAAC,IAAI,CAA+B,IAAI,CAAC,IAAI,EAAE,sBAAsB,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;AAEnK,gHAAgH;AAChH,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,MAAc,EAAE,GAAa,EAAE,EAAU;IAC/E,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,sBAAsB,CAAC,CAAC;IAChD,MAAM,GAAG,GAAG,IAAI,CAAgD,IAAI,EAAE,EAAE,CAAC,CAAC;IAC1E,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC;IACzB,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAC5E,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC;IAC7C,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACjB,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC;AAC5C,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { ReportDefinition } from '../core/types.js';
2
+ /** Finds a report by file path, by id in the given folders, or among the built-in reports. */
3
+ export declare function loadReport(ref: string, dirs?: string[]): ReportDefinition;
4
+ export declare function listCustom(dir: string): {
5
+ file: string;
6
+ definition: ReportDefinition;
7
+ }[];
@@ -0,0 +1,35 @@
1
+ import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
2
+ import { extname, join, resolve } from 'node:path';
3
+ import { parseDefinition } from '../core/definition.js';
4
+ import { builtinReports, findBuiltin } from '../reports/library.js';
5
+ /** Finds a report by file path, by id in the given folders, or among the built-in reports. */
6
+ export function loadReport(ref, dirs = []) {
7
+ if (/\.ya?ml$/i.test(ref) || existsSync(ref)) {
8
+ const path = resolve(ref);
9
+ if (!existsSync(path))
10
+ throw new Error(`Report file not found: ${ref}`);
11
+ return parseDefinition(readFileSync(path, 'utf8'), path);
12
+ }
13
+ for (const d of dirs) {
14
+ const custom = listCustom(d).find((r) => r.definition.id === ref);
15
+ if (custom)
16
+ return custom.definition;
17
+ }
18
+ const builtin = findBuiltin(ref);
19
+ if (builtin)
20
+ return builtin;
21
+ const known = [...dirs.flatMap((d) => listCustom(d).map((r) => r.definition.id)), ...builtinReports().map((r) => r.id)];
22
+ throw new Error(`Unknown report "${ref}". Available: ${known.join(', ')}`);
23
+ }
24
+ export function listCustom(dir) {
25
+ if (!existsSync(dir) || !statSync(dir).isDirectory())
26
+ return [];
27
+ return readdirSync(dir)
28
+ .filter((f) => ['.yaml', '.yml'].includes(extname(f).toLowerCase()))
29
+ .sort()
30
+ .map((f) => {
31
+ const file = join(dir, f);
32
+ return { file, definition: parseDefinition(readFileSync(file, 'utf8'), file) };
33
+ });
34
+ }
35
+ //# sourceMappingURL=loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/node/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,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,iBAAiB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC7E,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE;QAAE,OAAO,EAAE,CAAC;IAChE,OAAO,WAAW,CAAC,GAAG,CAAC;SACpB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;SACnE,IAAI,EAAE;SACN,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACT,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QAC1B,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,eAAe,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC;IACjF,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { Readable } from 'node:stream';
2
+ /** The files to read for a path: the file itself, or the log files of a folder, oldest first. */
3
+ export declare function logFilesAt(path: string): {
4
+ file: string;
5
+ size: number;
6
+ }[];
7
+ /**
8
+ * Lines of a stream; gzip is unpacked when `gzip` is set. A "line" longer than 4 MB is not a log
9
+ * line (a binary file, say): it is passed on as a short marker instead of being held in memory.
10
+ */
11
+ export declare function linesOfStream(input: Readable, gzip?: boolean): AsyncGenerator<string>;
12
+ /** Lines of every file, with progress by size. */
13
+ export declare function linesOfFiles(files: {
14
+ file: string;
15
+ size: number;
16
+ }[], onProgress?: (m: string) => void): AsyncGenerator<string>;
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Reads log files from this computer, line by line: one file or every log file in a folder,
3
+ * plain or gzip. Used by the ccg.log reader. Nothing is copied or kept.
4
+ */
5
+ import { createReadStream, readdirSync, statSync } from 'node:fs';
6
+ import { join } from 'node:path';
7
+ import { StringDecoder } from 'node:string_decoder';
8
+ import { createGunzip } from 'node:zlib';
9
+ const LOG_FILE = /\.(log|txt|json|jsonl)(\.\d+)?(\.gz)?$|\.log\.[\w-]+$/i;
10
+ const MAX_FILES = 60;
11
+ /** The files to read for a path: the file itself, or the log files of a folder, oldest first. */
12
+ export function logFilesAt(path) {
13
+ let st;
14
+ try {
15
+ st = statSync(path);
16
+ }
17
+ catch {
18
+ throw Object.assign(new Error('There is no file or folder at that path on this computer.'), { status: 400 });
19
+ }
20
+ if (st.isFile())
21
+ return [{ file: path, size: st.size }];
22
+ if (!st.isDirectory())
23
+ throw Object.assign(new Error('That path is neither a file nor a folder.'), { status: 400 });
24
+ const found = readdirSync(path)
25
+ .filter((f) => LOG_FILE.test(f))
26
+ .map((f) => {
27
+ const full = join(path, f);
28
+ try {
29
+ const s = statSync(full);
30
+ return s.isFile() ? { file: full, size: s.size, at: s.mtimeMs } : undefined;
31
+ }
32
+ catch {
33
+ return undefined;
34
+ }
35
+ })
36
+ .filter((x) => !!x)
37
+ .sort((a, b) => a.at - b.at);
38
+ if (!found.length)
39
+ throw Object.assign(new Error('That folder holds no log files (.log, .log.1, .gz, .txt, .json).'), { status: 400 });
40
+ return found.slice(-MAX_FILES).map(({ file, size }) => ({ file, size }));
41
+ }
42
+ const MAX_LINE = 4 * 1024 * 1024;
43
+ /**
44
+ * Lines of a stream; gzip is unpacked when `gzip` is set. A "line" longer than 4 MB is not a log
45
+ * line (a binary file, say): it is passed on as a short marker instead of being held in memory.
46
+ */
47
+ export async function* linesOfStream(input, gzip = false) {
48
+ const src = gzip ? input.pipe(createGunzip()) : input;
49
+ const decoder = new StringDecoder('utf8');
50
+ let pending = '';
51
+ let skipping = false;
52
+ for await (const chunk of src) {
53
+ pending += decoder.write(chunk);
54
+ let nl;
55
+ while ((nl = pending.indexOf('\n')) >= 0) {
56
+ const line = pending.slice(0, nl);
57
+ pending = pending.slice(nl + 1);
58
+ if (skipping) {
59
+ skipping = false;
60
+ yield '(line too long)';
61
+ }
62
+ else
63
+ yield line.endsWith('\r') ? line.slice(0, -1) : line;
64
+ }
65
+ if (pending.length > MAX_LINE) {
66
+ pending = '';
67
+ skipping = true;
68
+ }
69
+ }
70
+ pending += decoder.end();
71
+ if (skipping)
72
+ yield '(line too long)';
73
+ else if (pending)
74
+ yield pending;
75
+ }
76
+ /** Lines of every file, with progress by size. */
77
+ export async function* linesOfFiles(files, onProgress) {
78
+ const total = files.reduce((n, f) => n + f.size, 0) || 1;
79
+ let done = 0;
80
+ let n = 0;
81
+ for (const [i, f] of files.entries()) {
82
+ const stream = createReadStream(f.file);
83
+ let seen = 0;
84
+ stream.on('data', (c) => (seen += c.length));
85
+ for await (const line of linesOfStream(stream, /\.gz$/i.test(f.file))) {
86
+ yield line;
87
+ if (++n % 50_000 === 0)
88
+ onProgress?.(`Reading file ${i + 1} of ${files.length}... ${Math.round(((done + seen) / total) * 100)}%`);
89
+ }
90
+ done += f.size;
91
+ }
92
+ }
93
+ //# sourceMappingURL=log-files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log-files.js","sourceRoot":"","sources":["../../src/node/log-files.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,MAAM,QAAQ,GAAG,wDAAwD,CAAC;AAC1E,MAAM,SAAS,GAAG,EAAE,CAAC;AAErB,iGAAiG;AACjG,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,IAAI,EAAE,CAAC;IACP,IAAI,CAAC;QACH,EAAE,GAAG,QAAQ,CAAC,IAAI,C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AC,CAAC,EAAE,CAAC;YACtE,MAAM,IAAI,CAAC;YACX,IAAI,EAAE,CAAC,GAAG,MAAM,KAAK,CAAC;gBAAE,UAAU,EAAE,CAAC,gBAAgB,CAAC,GAAG,CAAC,OAAO,KAAK,CAAC,MAAM,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;QACpI,CAAC;QACD,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC;IACjB,CAAC;AACH,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * The monthly management report: how the daily checks moved during a month,
3
+ * from the local history the instant check keeps, plus a current snapshot of
4
+ * the tenant. Produced as data (for the screen) and as a standalone HTML page
5
+ * (to send or print to PDF).
6
+ */
7
+ import { type CheckStatus } from '../core/checks.js';
8
+ import type { TenantCounts } from '../core/tenant.js';
9
+ import type { History } from './history.js';
10
+ export interface MonthlyCheck {
11
+ id: string;
12
+ label: string;
13
+ unit: string;
14
+ start: number | null;
15
+ end: number | null;
16
+ change: number | null;
17
+ changePercent: number | null;
18
+ best: number | null;
19
+ worst: number | null;
20
+ daysChecked: number;
21
+ daysRed: number;
22
+ daysAmber: number;
23
+ /** Last value of each day checked. */
24
+ days: {
25
+ day: string;
26
+ value: number | null;
27
+ status: CheckStatus;
28
+ }[];
29
+ }
30
+ export interface MonthlyData {
31
+ tenant: string;
32
+ month: string;
33
+ monthLabel: string;
34
+ months: string[];
35
+ checks: MonthlyCheck[];
36
+ highlights: string[];
37
+ snapshot?: TenantCounts[];
38
+ generatedAt: string;
39
+ }
40
+ export declare function monthlyData(history: History, tenant: string, month?: string, snapshot?: TenantCounts[]): MonthlyData;
41
+ export declare function monthlyHtml(d: MonthlyData): string;
@@ -0,0 +1,108 @@
1
+ /**
2
+ * The monthly management report: how the daily checks moved during a month,
3
+ * from the local history the instant check keeps, plus a current snapshot of
4
+ * the tenant. Produced as data (for the screen) and as a standalone HTML page
5
+ * (to send or print to PDF).
6
+ */
7
+ import { CHECKS } from '../core/checks.js';
8
+ import { escapeHtml } from '../core/output/html.js';
9
+ const monthLabel = (m) => new Date(`${m}-01T12:00:00Z`).toLocaleString('en-US', { month: 'long', year: 'numeric', timeZone: 'UTC' });
10
+ const fmt = (n) => n.toLocaleString('en-US');
11
+ export function monthlyData(history, tenant, month, snapshot) {
12
+ const trends = history.trends(tenant);
13
+ const months = new Set();
14
+ for (const t of Object.values(trends))
15
+ for (const p of t.points)
16
+ months.add(p.at.slice(0, 7));
17
+ const sorted = [...months].sort().reverse();
18
+ const m = month && /^\d{4}-\d{2}$/.test(month) ? month : sorted[0] ?? new Date().toISOString().slice(0, 7);
19
+ const checks = [];
20
+ for (const spec of CHECKS) {
21
+ const pts = (trends[spec.id]?.points ?? []).filter((p) => p.at.startsWith(m));
22
+ const byDay = new Map();
23
+ for (const p of pts)
24
+ byDay.set(p.at.slice(0, 10), p);
25
+ const days = [...byDay.entries()].sort((a, b) => a[0].localeCompare(b[0])).map(([day, p]) => ({ day, value: p.value, status: p.status }));
26
+ const values = days.map((d) => d.value).filter((v) => v !== null);
27
+ const start = values[0] ?? null;
28
+ const end = values[values.length - 1] ?? null;
29
+ const change = start !== null && end !== null ? end - start : null;
30
+ checks.push({
31
+ id: spec.id,
32
+ label: spec.label,
33
+ unit: spec.unit,
34
+ start,
35
+ end,
36
+ change,
37
+ changePercent: change !== null && start ? Math.round((change / start) * 100) : null,
38
+ best: values.length ? Math.min(...values) : null,
39
+ worst: values.length ? Math.max(...values) : null,
40
+ daysChecked: days.length,
41
+ daysRed: days.filter((d) => d.status === 'bad').length,
42
+ daysAmber: days.filter((d) => d.status === 'warn').length,
43
+ days,
44
+ });
45
+ }
46
+ const highlights = [];
47
+ const measured = checks.filter((c) => c.daysChecked > 0);
48
+ if (!measured.length)
49
+ highlights.push('No checks were recorded in this month. Schedule the instant check daily to build the history this report is made from.');
50
+ for (const c of measured) {
51
+ if (c.change === null || c.start === null || c.end === null)
52
+ continue;
53
+ if (c.change < 0)
54
+ highlights.push(`${c.label} went down from ${fmt(c.start)} to ${fmt(c.end)}${c.changePercent !== null ? ` (${c.changePercent}%)` : ''}.`);
55
+ else if (c.change > 0)
56
+ highlights.push(`${c.label} went up from ${fmt(c.start)} to ${fmt(c.end)}${c.changePercent !== null ? ` (+${c.changePercent}%)` : ''}.`);
57
+ }
58
+ const clean = measured.filter((c) => c.daysRed === 0 && c.daysAmber === 0).map((c) => c.label);
59
+ if (clean.length)
60
+ highlights.push(`No problems all month: ${clean.join(', ')}.`);
61
+ const worst = [...measured].sort((a, b) => b.daysRed - a.daysRed)[0];
62
+ if (worst && worst.daysRed)
63
+ highlights.push(`Most days in red: ${worst.label} (${worst.daysRed} of ${worst.daysChecked} days checked).`);
64
+ return { tenant, month: m, monthLabel: monthLabel(m), months: sorted, checks, highlights, snapshot, generatedAt: new Date().toISOString() };
65
+ }
66
+ function chart(c) {
67
+ const w = 220;
68
+ const h = 46;
69
+ const vals = c.days.filter((d) => d.value !== null);
70
+ if (vals.length < 2)
71
+ return '<span style="color:#94a3b8;font-size:12px">not enough checks for a chart</span>';
72
+ const max = Math.max(...vals.map((d) => d.value));
73
+ const min = Math.min(...vals.map((d) => d.value));
74
+ const span = max - min || 1;
75
+ const pts = vals.map((d, i) => `${((i * (w - 4)) / (vals.length - 1) + 2).toFixed(1)},${(h - 3 - ((d.value - min) / span) * (h - 6)).toFixed(1)}`).join(' ');
76
+ return `<svg width="${w}" height="${h}" viewBox="0 0 ${w} ${h}"><polyline points="${pts}" fill="none" stroke="#2457d6" stroke-width="2" stroke-linejoin="round"/></svg>`;
77
+ }
78
+ export function monthlyHtml(d) {
79
+ const rows = d.checks
80
+ .map((c) => {
81
+ const ch = c.change === null ? '—' : c.change === 0 ? 'no change' : `${c.change > 0 ? '+' : '−'}${fmt(Math.abs(c.change))}${c.changePercent !== null ? ` (${c.changePercent > 0 ? '+' : ''}${c.changePercent}%)` : ''}`;
82
+ const color = c.change === null || c.change === 0 ? '#334155' : c.change < 0 ? '#067647' : '#b42318';
83
+ return `<tr><td><b>${escapeHtml(c.label)}</b><div class="u">${escapeHtml(c.unit)}</div></td><td class="n">${c.start === null ? '—' : fmt(c.start)}</td><td class="n">${c.end === null ? '—' : fmt(c.end)}</td><td class="n" style="color:${color}">${ch}</td><td class="n">${c.daysChecked}</td><td class="n">${c.daysRed ? `<span class="red">${c.daysRed}</span>` : 0} / ${c.daysAmber ? `<span class="amber">${c.daysAmber}</span>` : 0}</td><td>${chart(c)}</td></tr>`;
84
+ })
85
+ .join('');
86
+ const snap = d.snapshot?.length
87
+ ? `<h2>The tenant today</h2><div class="grid">${d.snapshot.map((s) => `<div class="k"><b>${s.count === null ? '—' : fmt(s.count)}</b><span>${escapeHtml(s.label)}</span></div>`).join('')}</div>`
88
+ : '';
89
+ return `<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>Identity operations report: ${escapeHtml(d.monthLabel)}</title>
90
+ <style>
91
+ body{font:14px/1.5 "Segoe UI",-apple-system,Roboto,Arial,sans-serif;color:#0f172a;max-width:1000px;margin:32px auto;padding:0 24px}
92
+ h1{font-size:24px;margin:0 0 4px}h2{font-size:16px;margin:28px 0 10px}.sub{color:#64748b;margin:0 0 20px}
93
+ ul.h{background:#f3f6fb;border-radius:10px;padding:14px 18px 14px 34px;margin:0}ul.h li{margin:4px 0}
94
+ table{border-collapse:collapse;width:100%;font-size:13px}th,td{border-bottom:1px solid #e3e8ef;padding:8px 10px;text-align:left;vertical-align:middle}th{background:#f6f8fb;font-size:12px;color:#334155}
95
+ td.n{text-align:right;font-variant-numeric:tabular-nums;white-space:nowrap}.u{color:#64748b;font-size:12px}.red{color:#b42318;font-weight:700}.amber{color:#8a5a00;font-weight:700}
96
+ .grid{display:grid;grid-template-columns:repeat(4,1fr);gap:10px}.k{border:1px solid #e3e8ef;border-radius:10px;padding:10px 12px}.k b{display:block;font-size:20px}.k span{color:#64748b;font-size:12px}
97
+ .foot{color:#94a3b8;font-size:12px;margin-top:28px}@media print{body{margin:0}}
98
+ </style></head><body>
99
+ <h1>Identity operations report: ${escapeHtml(d.monthLabel)}</h1>
100
+ <p class="sub">${escapeHtml(d.tenant)} · generated ${escapeHtml(d.generatedAt.slice(0, 16).replace('T', ' '))} UTC by identityscope</p>
101
+ <h2>Highlights</h2><ul class="h">${d.highlights.map((h) => `<li>${escapeHtml(h)}</li>`).join('')}</ul>
102
+ <h2>Daily checks during the month</h2>
103
+ <table><thead><tr><th>Check</th><th>First day</th><th>Last day</th><th>Change</th><th>Days checked</th><th>Days red / amber</th><th>Trend</th></tr></thead><tbody>${rows}</tbody></table>
104
+ ${snap}
105
+ <p class="foot">Lower is better for every check. Numbers come from the instant checks recorded on the computer that runs identityscope (one value per day: the last check of the day). Read-only: nothing was changed in the tenant.</p>
106
+ </body></html>`;
107
+ }
108
+ //# sourceMappingURL=monthly.js.map