@aletheia-dev/core 0.1.0 → 0.2.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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @aletheia-dev/core
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#10](https://github.com/akhiljames/aletheia/pull/10) [`1b1c13f`](https://github.com/akhiljames/aletheia/commit/1b1c13f230b10d8d4704196b510edc164d14e7e9) Thanks [@akhiljames](https://github.com/akhiljames)! - New `PolicyPack` schema and helpers (`policy-pack.ts`): a portable set of rules, rule sets,
8
+ workflows, collection flows and lists (with rows, capped at `POLICY_PACK_MAX_LIST_ROWS`) built
9
+ from the same input schemas the `PUT` routes accept, plus `PolicyPackKeyRef`
10
+ (`<kind>:<key>`), `parsePolicyPackKeyRef`, `policyPackKeyRefs` and `policyPackCounts`. It is the
11
+ body of `POST /definitions/import` and the response of `GET /definitions/export`.
12
+
3
13
  ## 0.1.0
4
14
 
5
15
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -120,12 +120,28 @@ __export(src_exports, {
120
120
  NotFoundError: () => NotFoundError,
121
121
  NotImplementedError: () => NotImplementedError,
122
122
  OutcomeChange: () => OutcomeChange,
123
+ POLICY_PACK_GROUPS: () => POLICY_PACK_GROUPS,
124
+ POLICY_PACK_GROUP_KINDS: () => POLICY_PACK_GROUP_KINDS,
125
+ POLICY_PACK_MAX_LIST_ROWS: () => POLICY_PACK_MAX_LIST_ROWS,
123
126
  PluginCallback: () => PluginCallback,
124
127
  PluginCallbackSignal: () => PluginCallbackSignal,
125
128
  PluginCallbackStatus: () => PluginCallbackStatus,
126
129
  PluginDefinition: () => PluginDefinition,
127
130
  PluginInvocation: () => PluginInvocation,
128
131
  PluginInvocationStatus: () => PluginInvocationStatus,
132
+ PolicyPack: () => PolicyPack,
133
+ PolicyPackCollectionFlow: () => PolicyPackCollectionFlow,
134
+ PolicyPackDefinitions: () => PolicyPackDefinitions,
135
+ PolicyPackImportResult: () => PolicyPackImportResult,
136
+ PolicyPackImportedDefinition: () => PolicyPackImportedDefinition,
137
+ PolicyPackImportedList: () => PolicyPackImportedList,
138
+ PolicyPackItemKind: () => PolicyPackItemKind,
139
+ PolicyPackKeyRef: () => PolicyPackKeyRef,
140
+ PolicyPackList: () => PolicyPackList,
141
+ PolicyPackName: () => PolicyPackName,
142
+ PolicyPackRule: () => PolicyPackRule,
143
+ PolicyPackRuleSet: () => PolicyPackRuleSet,
144
+ PolicyPackWorkflow: () => PolicyPackWorkflow,
129
145
  RemoveListEntriesInput: () => RemoveListEntriesInput,
130
146
  RuleDefinition: () => RuleDefinition,
131
147
  RuleEvaluation: () => RuleEvaluation,
@@ -184,6 +200,9 @@ __export(src_exports, {
184
200
  getPath: () => getPath,
185
201
  noopLogger: () => noopLogger,
186
202
  normalizeListValue: () => normalizeListValue,
203
+ parsePolicyPackKeyRef: () => parsePolicyPackKeyRef,
204
+ policyPackCounts: () => policyPackCounts,
205
+ policyPackKeyRefs: () => policyPackKeyRefs,
187
206
  stepTargets: () => stepTargets,
188
207
  systemContext: () => systemContext,
189
208
  temporalWorkflowId: () => temporalWorkflowId
@@ -1410,6 +1429,109 @@ var AuditFilter = import_zod21.z.object({
1410
1429
  to: import_zod21.z.coerce.date().optional()
1411
1430
  });
1412
1431
 
1432
+ // src/policy-pack.ts
1433
+ var import_zod22 = require("zod");
1434
+ var POLICY_PACK_MAX_LIST_ROWS = 1e4;
1435
+ var PolicyPackRule = UpsertRuleDefinitionInput.extend({ key: DefinitionKey });
1436
+ var PolicyPackRuleSet = UpsertRuleSetInput.extend({ key: DefinitionKey });
1437
+ var PolicyPackWorkflow = UpsertWorkflowDefinitionInput.extend({ key: DefinitionKey });
1438
+ var PolicyPackCollectionFlow = UpsertCollectionFlowInput.extend({ key: DefinitionKey });
1439
+ var PolicyPackList = UpsertListInput.extend({
1440
+ key: DefinitionKey,
1441
+ rows: import_zod22.z.array(NewListEntry).max(POLICY_PACK_MAX_LIST_ROWS).default([])
1442
+ });
1443
+ var POLICY_PACK_GROUPS = [
1444
+ "lists",
1445
+ "rules",
1446
+ "ruleSets",
1447
+ "collectionFlows",
1448
+ "workflows"
1449
+ ];
1450
+ var PolicyPackItemKind = import_zod22.z.enum([...DefinitionKind.options, "list"]);
1451
+ var POLICY_PACK_GROUP_KINDS = {
1452
+ lists: "list",
1453
+ rules: "rule",
1454
+ ruleSets: "rule_set",
1455
+ collectionFlows: "collection_flow",
1456
+ workflows: "workflow"
1457
+ };
1458
+ var PolicyPackDefinitions = import_zod22.z.object({
1459
+ rules: import_zod22.z.array(PolicyPackRule).default([]),
1460
+ ruleSets: import_zod22.z.array(PolicyPackRuleSet).default([]),
1461
+ workflows: import_zod22.z.array(PolicyPackWorkflow).default([]),
1462
+ collectionFlows: import_zod22.z.array(PolicyPackCollectionFlow).default([]),
1463
+ lists: import_zod22.z.array(PolicyPackList).default([])
1464
+ }).superRefine((definitions, ctx) => {
1465
+ for (const group of POLICY_PACK_GROUPS) {
1466
+ const seen = /* @__PURE__ */ new Set();
1467
+ definitions[group].forEach((item, index) => {
1468
+ if (seen.has(item.key)) {
1469
+ ctx.addIssue({
1470
+ code: "custom",
1471
+ path: [group, index, "key"],
1472
+ message: `duplicate ${POLICY_PACK_GROUP_KINDS[group].replace(/_/g, " ")} "${item.key}"`
1473
+ });
1474
+ }
1475
+ seen.add(item.key);
1476
+ });
1477
+ }
1478
+ });
1479
+ var PolicyPackName = import_zod22.z.string().min(1).max(100).regex(/^[a-z0-9][a-z0-9_-]*$/, 'pack names are lowercase letters, digits, "_" or "-"');
1480
+ var PolicyPack = import_zod22.z.object({
1481
+ name: PolicyPackName,
1482
+ version: import_zod22.z.string().min(1).max(50),
1483
+ description: import_zod22.z.string().max(2e3).optional(),
1484
+ definitions: PolicyPackDefinitions
1485
+ });
1486
+ function policyPackCounts(pack) {
1487
+ return {
1488
+ lists: pack.definitions.lists.length,
1489
+ rules: pack.definitions.rules.length,
1490
+ ruleSets: pack.definitions.ruleSets.length,
1491
+ collectionFlows: pack.definitions.collectionFlows.length,
1492
+ workflows: pack.definitions.workflows.length
1493
+ };
1494
+ }
1495
+ var PolicyPackKeyRef = import_zod22.z.object({ kind: PolicyPackItemKind, key: DefinitionKey });
1496
+ function parsePolicyPackKeyRef(value) {
1497
+ const separator = value.indexOf(":");
1498
+ const kind = separator === -1 ? "" : value.slice(0, separator);
1499
+ const key = separator === -1 ? value : value.slice(separator + 1);
1500
+ return PolicyPackKeyRef.parse({ kind, key });
1501
+ }
1502
+ function policyPackKeyRefs(pack) {
1503
+ return POLICY_PACK_GROUPS.flatMap(
1504
+ (group) => pack.definitions[group].map((item) => `${POLICY_PACK_GROUP_KINDS[group]}:${item.key}`)
1505
+ );
1506
+ }
1507
+ var PolicyPackImportedDefinition = import_zod22.z.object({
1508
+ kind: DefinitionKind,
1509
+ key: DefinitionKey,
1510
+ id: Id,
1511
+ version: import_zod22.z.number().int().positive(),
1512
+ status: DefinitionStatus,
1513
+ /** Set when the tenant requires approvals and `publish=true` opened a request instead. */
1514
+ approvalId: Id.nullable()
1515
+ });
1516
+ var PolicyPackImportedList = import_zod22.z.object({
1517
+ key: DefinitionKey,
1518
+ id: Id,
1519
+ created: import_zod22.z.boolean(),
1520
+ added: import_zod22.z.number().int().nonnegative(),
1521
+ skipped: import_zod22.z.number().int().nonnegative(),
1522
+ invalid: import_zod22.z.number().int().nonnegative()
1523
+ });
1524
+ var PolicyPackImportResult = import_zod22.z.object({
1525
+ name: PolicyPackName,
1526
+ version: import_zod22.z.string(),
1527
+ /** Whether `publish=true` was requested. */
1528
+ publish: import_zod22.z.boolean(),
1529
+ /** With `publish=true` and approvals required: versions are `pending_approval`, not published. */
1530
+ approvalRequired: import_zod22.z.boolean(),
1531
+ definitions: import_zod22.z.array(PolicyPackImportedDefinition),
1532
+ lists: import_zod22.z.array(PolicyPackImportedList)
1533
+ });
1534
+
1413
1535
  // src/errors.ts
1414
1536
  var AletheiaError = class extends Error {
1415
1537
  constructor(message, code, status = 500, details) {
@@ -1564,12 +1686,28 @@ var noopLogger = {
1564
1686
  NotFoundError,
1565
1687
  NotImplementedError,
1566
1688
  OutcomeChange,
1689
+ POLICY_PACK_GROUPS,
1690
+ POLICY_PACK_GROUP_KINDS,
1691
+ POLICY_PACK_MAX_LIST_ROWS,
1567
1692
  PluginCallback,
1568
1693
  PluginCallbackSignal,
1569
1694
  PluginCallbackStatus,
1570
1695
  PluginDefinition,
1571
1696
  PluginInvocation,
1572
1697
  PluginInvocationStatus,
1698
+ PolicyPack,
1699
+ PolicyPackCollectionFlow,
1700
+ PolicyPackDefinitions,
1701
+ PolicyPackImportResult,
1702
+ PolicyPackImportedDefinition,
1703
+ PolicyPackImportedList,
1704
+ PolicyPackItemKind,
1705
+ PolicyPackKeyRef,
1706
+ PolicyPackList,
1707
+ PolicyPackName,
1708
+ PolicyPackRule,
1709
+ PolicyPackRuleSet,
1710
+ PolicyPackWorkflow,
1573
1711
  RemoveListEntriesInput,
1574
1712
  RuleDefinition,
1575
1713
  RuleEvaluation,
@@ -1628,6 +1766,9 @@ var noopLogger = {
1628
1766
  getPath,
1629
1767
  noopLogger,
1630
1768
  normalizeListValue,
1769
+ parsePolicyPackKeyRef,
1770
+ policyPackCounts,
1771
+ policyPackKeyRefs,
1631
1772
  stepTargets,
1632
1773
  systemContext,
1633
1774
  temporalWorkflowId