@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/dist/index.js CHANGED
@@ -1218,6 +1218,109 @@ var AuditFilter = z21.object({
1218
1218
  to: z21.coerce.date().optional()
1219
1219
  });
1220
1220
 
1221
+ // src/policy-pack.ts
1222
+ import { z as z22 } from "zod";
1223
+ var POLICY_PACK_MAX_LIST_ROWS = 1e4;
1224
+ var PolicyPackRule = UpsertRuleDefinitionInput.extend({ key: DefinitionKey });
1225
+ var PolicyPackRuleSet = UpsertRuleSetInput.extend({ key: DefinitionKey });
1226
+ var PolicyPackWorkflow = UpsertWorkflowDefinitionInput.extend({ key: DefinitionKey });
1227
+ var PolicyPackCollectionFlow = UpsertCollectionFlowInput.extend({ key: DefinitionKey });
1228
+ var PolicyPackList = UpsertListInput.extend({
1229
+ key: DefinitionKey,
1230
+ rows: z22.array(NewListEntry).max(POLICY_PACK_MAX_LIST_ROWS).default([])
1231
+ });
1232
+ var POLICY_PACK_GROUPS = [
1233
+ "lists",
1234
+ "rules",
1235
+ "ruleSets",
1236
+ "collectionFlows",
1237
+ "workflows"
1238
+ ];
1239
+ var PolicyPackItemKind = z22.enum([...DefinitionKind.options, "list"]);
1240
+ var POLICY_PACK_GROUP_KINDS = {
1241
+ lists: "list",
1242
+ rules: "rule",
1243
+ ruleSets: "rule_set",
1244
+ collectionFlows: "collection_flow",
1245
+ workflows: "workflow"
1246
+ };
1247
+ var PolicyPackDefinitions = z22.object({
1248
+ rules: z22.array(PolicyPackRule).default([]),
1249
+ ruleSets: z22.array(PolicyPackRuleSet).default([]),
1250
+ workflows: z22.array(PolicyPackWorkflow).default([]),
1251
+ collectionFlows: z22.array(PolicyPackCollectionFlow).default([]),
1252
+ lists: z22.array(PolicyPackList).default([])
1253
+ }).superRefine((definitions, ctx) => {
1254
+ for (const group of POLICY_PACK_GROUPS) {
1255
+ const seen = /* @__PURE__ */ new Set();
1256
+ definitions[group].forEach((item, index) => {
1257
+ if (seen.has(item.key)) {
1258
+ ctx.addIssue({
1259
+ code: "custom",
1260
+ path: [group, index, "key"],
1261
+ message: `duplicate ${POLICY_PACK_GROUP_KINDS[group].replace(/_/g, " ")} "${item.key}"`
1262
+ });
1263
+ }
1264
+ seen.add(item.key);
1265
+ });
1266
+ }
1267
+ });
1268
+ var PolicyPackName = z22.string().min(1).max(100).regex(/^[a-z0-9][a-z0-9_-]*$/, 'pack names are lowercase letters, digits, "_" or "-"');
1269
+ var PolicyPack = z22.object({
1270
+ name: PolicyPackName,
1271
+ version: z22.string().min(1).max(50),
1272
+ description: z22.string().max(2e3).optional(),
1273
+ definitions: PolicyPackDefinitions
1274
+ });
1275
+ function policyPackCounts(pack) {
1276
+ return {
1277
+ lists: pack.definitions.lists.length,
1278
+ rules: pack.definitions.rules.length,
1279
+ ruleSets: pack.definitions.ruleSets.length,
1280
+ collectionFlows: pack.definitions.collectionFlows.length,
1281
+ workflows: pack.definitions.workflows.length
1282
+ };
1283
+ }
1284
+ var PolicyPackKeyRef = z22.object({ kind: PolicyPackItemKind, key: DefinitionKey });
1285
+ function parsePolicyPackKeyRef(value) {
1286
+ const separator = value.indexOf(":");
1287
+ const kind = separator === -1 ? "" : value.slice(0, separator);
1288
+ const key = separator === -1 ? value : value.slice(separator + 1);
1289
+ return PolicyPackKeyRef.parse({ kind, key });
1290
+ }
1291
+ function policyPackKeyRefs(pack) {
1292
+ return POLICY_PACK_GROUPS.flatMap(
1293
+ (group) => pack.definitions[group].map((item) => `${POLICY_PACK_GROUP_KINDS[group]}:${item.key}`)
1294
+ );
1295
+ }
1296
+ var PolicyPackImportedDefinition = z22.object({
1297
+ kind: DefinitionKind,
1298
+ key: DefinitionKey,
1299
+ id: Id,
1300
+ version: z22.number().int().positive(),
1301
+ status: DefinitionStatus,
1302
+ /** Set when the tenant requires approvals and `publish=true` opened a request instead. */
1303
+ approvalId: Id.nullable()
1304
+ });
1305
+ var PolicyPackImportedList = z22.object({
1306
+ key: DefinitionKey,
1307
+ id: Id,
1308
+ created: z22.boolean(),
1309
+ added: z22.number().int().nonnegative(),
1310
+ skipped: z22.number().int().nonnegative(),
1311
+ invalid: z22.number().int().nonnegative()
1312
+ });
1313
+ var PolicyPackImportResult = z22.object({
1314
+ name: PolicyPackName,
1315
+ version: z22.string(),
1316
+ /** Whether `publish=true` was requested. */
1317
+ publish: z22.boolean(),
1318
+ /** With `publish=true` and approvals required: versions are `pending_approval`, not published. */
1319
+ approvalRequired: z22.boolean(),
1320
+ definitions: z22.array(PolicyPackImportedDefinition),
1321
+ lists: z22.array(PolicyPackImportedList)
1322
+ });
1323
+
1221
1324
  // src/errors.ts
1222
1325
  var AletheiaError = class extends Error {
1223
1326
  constructor(message, code, status = 500, details) {
@@ -1371,12 +1474,28 @@ export {
1371
1474
  NotFoundError,
1372
1475
  NotImplementedError,
1373
1476
  OutcomeChange,
1477
+ POLICY_PACK_GROUPS,
1478
+ POLICY_PACK_GROUP_KINDS,
1479
+ POLICY_PACK_MAX_LIST_ROWS,
1374
1480
  PluginCallback,
1375
1481
  PluginCallbackSignal,
1376
1482
  PluginCallbackStatus,
1377
1483
  PluginDefinition,
1378
1484
  PluginInvocation,
1379
1485
  PluginInvocationStatus,
1486
+ PolicyPack,
1487
+ PolicyPackCollectionFlow,
1488
+ PolicyPackDefinitions,
1489
+ PolicyPackImportResult,
1490
+ PolicyPackImportedDefinition,
1491
+ PolicyPackImportedList,
1492
+ PolicyPackItemKind,
1493
+ PolicyPackKeyRef,
1494
+ PolicyPackList,
1495
+ PolicyPackName,
1496
+ PolicyPackRule,
1497
+ PolicyPackRuleSet,
1498
+ PolicyPackWorkflow,
1380
1499
  RemoveListEntriesInput,
1381
1500
  RuleDefinition,
1382
1501
  RuleEvaluation,
@@ -1435,6 +1554,9 @@ export {
1435
1554
  getPath,
1436
1555
  noopLogger,
1437
1556
  normalizeListValue,
1557
+ parsePolicyPackKeyRef,
1558
+ policyPackCounts,
1559
+ policyPackKeyRefs,
1438
1560
  stepTargets,
1439
1561
  systemContext,
1440
1562
  temporalWorkflowId