@geonosis/policy 2.12.0 → 3.0.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 +6 -0
- package/dist/conformance.cjs +169 -0
- package/dist/conformance.d.cts +35 -0
- package/dist/conformance.d.ts +35 -0
- package/dist/conformance.js +129 -0
- package/dist/define.cjs +118 -0
- package/dist/define.d.cts +34 -0
- package/dist/define.d.ts +34 -0
- package/dist/define.js +85 -0
- package/dist/drizzle/index.cjs +37 -32
- package/dist/drizzle/index.d.cts +20 -23
- package/dist/drizzle/index.d.ts +20 -23
- package/dist/drizzle/index.js +2 -5
- package/dist/index.cjs +79 -856
- package/dist/index.d.cts +19 -428
- package/dist/index.d.ts +19 -428
- package/dist/index.js +35 -797
- package/dist/journal-events.cjs +68 -0
- package/dist/journal-events.d.cts +26 -0
- package/dist/journal-events.d.ts +26 -0
- package/dist/journal-events.js +28 -0
- package/dist/lattice.cjs +150 -0
- package/dist/lattice.d.cts +48 -0
- package/dist/lattice.d.ts +48 -0
- package/dist/lattice.js +110 -0
- package/dist/learning.cjs +246 -0
- package/dist/learning.d.cts +121 -0
- package/dist/learning.d.ts +121 -0
- package/dist/learning.js +206 -0
- package/dist/markdown.cjs +118 -0
- package/dist/markdown.d.cts +35 -0
- package/dist/markdown.d.ts +35 -0
- package/dist/markdown.js +78 -0
- package/dist/medusa/index.cjs +39 -36
- package/dist/medusa/index.d.cts +14 -16
- package/dist/medusa/index.d.ts +14 -16
- package/dist/medusa/index.js +4 -9
- package/dist/permissions/index.cjs +49 -40
- package/dist/permissions/index.d.cts +18 -20
- package/dist/permissions/index.d.ts +18 -20
- package/dist/permissions/index.js +15 -25
- package/dist/read.cjs +111 -0
- package/dist/read.d.cts +51 -0
- package/dist/read.d.ts +51 -0
- package/dist/read.js +71 -0
- package/dist/rows.cjs +54 -0
- package/dist/rows.d.cts +11 -0
- package/dist/rows.d.ts +11 -0
- package/dist/{chunk-JICJ4XEX.js → rows.js} +0 -3
- package/dist/seed.cjs +53 -0
- package/dist/seed.d.cts +18 -0
- package/dist/seed.d.ts +18 -0
- package/dist/seed.js +13 -0
- package/dist/threshold.cjs +73 -0
- package/dist/threshold.d.cts +45 -0
- package/dist/threshold.d.ts +45 -0
- package/dist/threshold.js +33 -0
- package/dist/types.cjs +47 -0
- package/dist/{types-C-Q3r-In.d.cts → types.d.cts} +21 -23
- package/dist/{types-C-Q3r-In.d.ts → types.d.ts} +21 -23
- package/dist/types.js +7 -0
- package/package.json +3 -3
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
function __accessProp(key) {
|
|
6
|
+
return this[key];
|
|
7
|
+
}
|
|
8
|
+
var __toCommonJS = (from) => {
|
|
9
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
10
|
+
if (entry)
|
|
11
|
+
return entry;
|
|
12
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (var key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(entry, key))
|
|
16
|
+
__defProp(entry, key, {
|
|
17
|
+
get: __accessProp.bind(from, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
__moduleCache.set(from, entry);
|
|
22
|
+
return entry;
|
|
23
|
+
};
|
|
24
|
+
var __moduleCache;
|
|
25
|
+
var __returnValue = (v) => v;
|
|
26
|
+
function __exportSetter(name, newValue) {
|
|
27
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
28
|
+
}
|
|
29
|
+
var __export = (target, all) => {
|
|
30
|
+
for (var name in all)
|
|
31
|
+
__defProp(target, name, {
|
|
32
|
+
get: all[name],
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
set: __exportSetter.bind(all, name)
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// src/markdown.ts
|
|
40
|
+
var exports_markdown = {};
|
|
41
|
+
__export(exports_markdown, {
|
|
42
|
+
describePolicy: () => describePolicy,
|
|
43
|
+
generatePolicyMarkdown: () => generatePolicyMarkdown
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(exports_markdown);
|
|
46
|
+
var scopeOf = (rule) => {
|
|
47
|
+
const entries = Object.entries(rule.scope ?? {}).filter(([, value]) => value !== undefined);
|
|
48
|
+
return entries.length === 0 ? "all" : entries.map(([key, value]) => `${key}=${String(value)}`).join(", ");
|
|
49
|
+
};
|
|
50
|
+
var generatePolicyMarkdown = (policy, options = {}) => {
|
|
51
|
+
const rules = options.rules ?? policy.rules;
|
|
52
|
+
const lines = [
|
|
53
|
+
`# ${options.title ?? "Policy"}`,
|
|
54
|
+
"",
|
|
55
|
+
`> GENERATED by ${options.generator ?? "the policy kernel"} — do not hand-edit.`,
|
|
56
|
+
`> ${options.source ?? "The policy data"} beside it is what the engine reads.`,
|
|
57
|
+
"> Committed on purpose: this is the domain knowledge the business has accumulated, and it",
|
|
58
|
+
"> should arrive with a checkout.",
|
|
59
|
+
"",
|
|
60
|
+
`## Rules (${rules.length}) — enforced`,
|
|
61
|
+
"",
|
|
62
|
+
`Precedence: ${policy.tiers.map((tier) => tier.name).join(" > ")}.`,
|
|
63
|
+
"Within a tier the more specific scope wins; two equal authorities that disagree are reported,",
|
|
64
|
+
"never resolved silently.",
|
|
65
|
+
""
|
|
66
|
+
];
|
|
67
|
+
if (rules.length === 0) {
|
|
68
|
+
lines.push("_None installed. Every reader falls back to its own constant, and says so._", "");
|
|
69
|
+
} else {
|
|
70
|
+
lines.push("| Rule | Tier | Scope | Constraint | Why |", "| --- | --- | --- | --- | --- |", ...rules.map((rule) => `| \`${rule.id}\` | ${rule.tier} | ${scopeOf(rule)} | \`${rule.constraint.kind}\` = \`${JSON.stringify(rule.constraint.value)}\` | ${rule.reason} |`), "");
|
|
71
|
+
}
|
|
72
|
+
const unset = policy.unsetKinds(rules);
|
|
73
|
+
if (unset.length > 0) {
|
|
74
|
+
lines.push(`## Constraints nothing sets (${unset.length})`, "", "A reader falling back to its own default forever looks identical to one that is working.", "", ...unset.map((kind) => `- \`${kind}\``), "");
|
|
75
|
+
}
|
|
76
|
+
const unusable = [
|
|
77
|
+
...policy.unusableRules(rules).map((rule) => `- \`${rule.id}\` — ${rule.reason}`),
|
|
78
|
+
...policy.unsupportedScopes(rules).map((rule) => `- \`${rule.id}\` — scoped on ${rule.keys.join(", ")}, which this build has no key for`)
|
|
79
|
+
];
|
|
80
|
+
if (unusable.length > 0) {
|
|
81
|
+
lines.push(`## Rules this build cannot honour (${unusable.length})`, "", "Named rather than dropped: a rule the code cannot read means the policy is newer than the", "build, or older — a deployment-order problem, and the one case always worth saying aloud.", "", ...unusable, "");
|
|
82
|
+
}
|
|
83
|
+
const playbook = options.playbook;
|
|
84
|
+
if (playbook) {
|
|
85
|
+
const active = playbook.entries.filter((entry) => entry.status === "active");
|
|
86
|
+
const candidates = playbook.entries.filter((entry) => entry.status === "candidate");
|
|
87
|
+
lines.push(`## Learned playbook (v${playbook.version})`, "", `${active.length} active, ${candidates.length} candidate. An active entry that carries a`, "constraint enters the lattice at the advisory tier, where it can only fill silence.", "", ...active.map((entry) => `- **${entry.id}** — ${entry.statement}`), "");
|
|
88
|
+
}
|
|
89
|
+
return `${lines.join(`
|
|
90
|
+
`)}
|
|
91
|
+
`;
|
|
92
|
+
};
|
|
93
|
+
var describePolicy = (policy, options = {}) => {
|
|
94
|
+
const rules = options.rules ?? policy.rules;
|
|
95
|
+
const maximum = options.maxRules ?? 8;
|
|
96
|
+
const active = (options.playbook?.entries ?? []).filter((entry) => entry.status === "active");
|
|
97
|
+
if (rules.length === 0) {
|
|
98
|
+
return "No policy is installed yet — nothing is enforced, and every reader falls back to the constant compiled into it.";
|
|
99
|
+
}
|
|
100
|
+
const lines = [
|
|
101
|
+
`ACTIVE POLICY (${rules.length} rule${rules.length === 1 ? "" : "s"}, enforced — a refusal names the rule that blocked it):`,
|
|
102
|
+
...rules.slice(0, maximum).map((rule) => {
|
|
103
|
+
const scope = rule.scope && Object.keys(rule.scope).length > 0 ? ` [${scopeOf(rule)}]` : "";
|
|
104
|
+
return ` ${rule.tier}:${rule.id}${scope} — ${rule.constraint.kind}=${JSON.stringify(rule.constraint.value)} (${rule.reason})`;
|
|
105
|
+
})
|
|
106
|
+
];
|
|
107
|
+
if (rules.length > maximum) {
|
|
108
|
+
lines.push(` + ${rules.length - maximum} more — read the whole set before deciding.`);
|
|
109
|
+
}
|
|
110
|
+
lines.push(" A more specific scope beats a general one inside a tier; stronger tiers win outright.");
|
|
111
|
+
if (active.length > 0) {
|
|
112
|
+
lines.push("", "LEARNED (advisory — fills silence, never overrides a rule):");
|
|
113
|
+
for (const entry of active.slice(0, 4))
|
|
114
|
+
lines.push(` ${entry.statement}`);
|
|
115
|
+
}
|
|
116
|
+
return lines.join(`
|
|
117
|
+
`);
|
|
118
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Playbook } from './learning.cjs';
|
|
2
|
+
import type { Policy, PolicyRule } from './types.cjs';
|
|
3
|
+
/**
|
|
4
|
+
* The policy as prose, generated beside the data it renders.
|
|
5
|
+
*
|
|
6
|
+
* musa checks in `policy/policy.json` and a `POLICY.md` written from it on every change, and the
|
|
7
|
+
* argument for generating rather than writing it is in that file's own history: two of its sections
|
|
8
|
+
* were prose, and both had gone stale and were telling agents the opposite of what the code did. A
|
|
9
|
+
* markdown that has to be remembered separately drifts, and a drifted one is worse than none — it
|
|
10
|
+
* reads authoritative while the engine enforces something else.
|
|
11
|
+
*
|
|
12
|
+
* So every count, every precedence sentence and every honesty report below is DERIVED.
|
|
13
|
+
*/
|
|
14
|
+
export type PolicyMarkdownOptions = {
|
|
15
|
+
generator?: string;
|
|
16
|
+
playbook?: Playbook;
|
|
17
|
+
rules?: readonly PolicyRule[];
|
|
18
|
+
/** What a reader should edit instead of this file. */
|
|
19
|
+
source?: string;
|
|
20
|
+
title?: string;
|
|
21
|
+
};
|
|
22
|
+
export declare const generatePolicyMarkdown: (policy: Policy, options?: PolicyMarkdownOptions) => string;
|
|
23
|
+
export type DescribePolicyOptions = {
|
|
24
|
+
/** Instructions ride in EVERY context, so this stays bounded. */
|
|
25
|
+
maxRules?: number;
|
|
26
|
+
playbook?: Playbook;
|
|
27
|
+
rules?: readonly PolicyRule[];
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* The same policy, bounded, for the channel an agent is handed when it connects.
|
|
31
|
+
*
|
|
32
|
+
* Persisting policy is only half the job: an agent that has to discover the rules by tripping over
|
|
33
|
+
* them will trip over them in front of a customer.
|
|
34
|
+
*/
|
|
35
|
+
export declare const describePolicy: (policy: Policy, options?: DescribePolicyOptions) => string;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Playbook } from './learning.js';
|
|
2
|
+
import type { Policy, PolicyRule } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* The policy as prose, generated beside the data it renders.
|
|
5
|
+
*
|
|
6
|
+
* musa checks in `policy/policy.json` and a `POLICY.md` written from it on every change, and the
|
|
7
|
+
* argument for generating rather than writing it is in that file's own history: two of its sections
|
|
8
|
+
* were prose, and both had gone stale and were telling agents the opposite of what the code did. A
|
|
9
|
+
* markdown that has to be remembered separately drifts, and a drifted one is worse than none — it
|
|
10
|
+
* reads authoritative while the engine enforces something else.
|
|
11
|
+
*
|
|
12
|
+
* So every count, every precedence sentence and every honesty report below is DERIVED.
|
|
13
|
+
*/
|
|
14
|
+
export type PolicyMarkdownOptions = {
|
|
15
|
+
generator?: string;
|
|
16
|
+
playbook?: Playbook;
|
|
17
|
+
rules?: readonly PolicyRule[];
|
|
18
|
+
/** What a reader should edit instead of this file. */
|
|
19
|
+
source?: string;
|
|
20
|
+
title?: string;
|
|
21
|
+
};
|
|
22
|
+
export declare const generatePolicyMarkdown: (policy: Policy, options?: PolicyMarkdownOptions) => string;
|
|
23
|
+
export type DescribePolicyOptions = {
|
|
24
|
+
/** Instructions ride in EVERY context, so this stays bounded. */
|
|
25
|
+
maxRules?: number;
|
|
26
|
+
playbook?: Playbook;
|
|
27
|
+
rules?: readonly PolicyRule[];
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* The same policy, bounded, for the channel an agent is handed when it connects.
|
|
31
|
+
*
|
|
32
|
+
* Persisting policy is only half the job: an agent that has to discover the rules by tripping over
|
|
33
|
+
* them will trip over them in front of a customer.
|
|
34
|
+
*/
|
|
35
|
+
export declare const describePolicy: (policy: Policy, options?: DescribePolicyOptions) => string;
|
package/dist/markdown.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// src/markdown.ts
|
|
2
|
+
var scopeOf = (rule) => {
|
|
3
|
+
const entries = Object.entries(rule.scope ?? {}).filter(([, value]) => value !== undefined);
|
|
4
|
+
return entries.length === 0 ? "all" : entries.map(([key, value]) => `${key}=${String(value)}`).join(", ");
|
|
5
|
+
};
|
|
6
|
+
var generatePolicyMarkdown = (policy, options = {}) => {
|
|
7
|
+
const rules = options.rules ?? policy.rules;
|
|
8
|
+
const lines = [
|
|
9
|
+
`# ${options.title ?? "Policy"}`,
|
|
10
|
+
"",
|
|
11
|
+
`> GENERATED by ${options.generator ?? "the policy kernel"} — do not hand-edit.`,
|
|
12
|
+
`> ${options.source ?? "The policy data"} beside it is what the engine reads.`,
|
|
13
|
+
"> Committed on purpose: this is the domain knowledge the business has accumulated, and it",
|
|
14
|
+
"> should arrive with a checkout.",
|
|
15
|
+
"",
|
|
16
|
+
`## Rules (${rules.length}) — enforced`,
|
|
17
|
+
"",
|
|
18
|
+
`Precedence: ${policy.tiers.map((tier) => tier.name).join(" > ")}.`,
|
|
19
|
+
"Within a tier the more specific scope wins; two equal authorities that disagree are reported,",
|
|
20
|
+
"never resolved silently.",
|
|
21
|
+
""
|
|
22
|
+
];
|
|
23
|
+
if (rules.length === 0) {
|
|
24
|
+
lines.push("_None installed. Every reader falls back to its own constant, and says so._", "");
|
|
25
|
+
} else {
|
|
26
|
+
lines.push("| Rule | Tier | Scope | Constraint | Why |", "| --- | --- | --- | --- | --- |", ...rules.map((rule) => `| \`${rule.id}\` | ${rule.tier} | ${scopeOf(rule)} | \`${rule.constraint.kind}\` = \`${JSON.stringify(rule.constraint.value)}\` | ${rule.reason} |`), "");
|
|
27
|
+
}
|
|
28
|
+
const unset = policy.unsetKinds(rules);
|
|
29
|
+
if (unset.length > 0) {
|
|
30
|
+
lines.push(`## Constraints nothing sets (${unset.length})`, "", "A reader falling back to its own default forever looks identical to one that is working.", "", ...unset.map((kind) => `- \`${kind}\``), "");
|
|
31
|
+
}
|
|
32
|
+
const unusable = [
|
|
33
|
+
...policy.unusableRules(rules).map((rule) => `- \`${rule.id}\` — ${rule.reason}`),
|
|
34
|
+
...policy.unsupportedScopes(rules).map((rule) => `- \`${rule.id}\` — scoped on ${rule.keys.join(", ")}, which this build has no key for`)
|
|
35
|
+
];
|
|
36
|
+
if (unusable.length > 0) {
|
|
37
|
+
lines.push(`## Rules this build cannot honour (${unusable.length})`, "", "Named rather than dropped: a rule the code cannot read means the policy is newer than the", "build, or older — a deployment-order problem, and the one case always worth saying aloud.", "", ...unusable, "");
|
|
38
|
+
}
|
|
39
|
+
const playbook = options.playbook;
|
|
40
|
+
if (playbook) {
|
|
41
|
+
const active = playbook.entries.filter((entry) => entry.status === "active");
|
|
42
|
+
const candidates = playbook.entries.filter((entry) => entry.status === "candidate");
|
|
43
|
+
lines.push(`## Learned playbook (v${playbook.version})`, "", `${active.length} active, ${candidates.length} candidate. An active entry that carries a`, "constraint enters the lattice at the advisory tier, where it can only fill silence.", "", ...active.map((entry) => `- **${entry.id}** — ${entry.statement}`), "");
|
|
44
|
+
}
|
|
45
|
+
return `${lines.join(`
|
|
46
|
+
`)}
|
|
47
|
+
`;
|
|
48
|
+
};
|
|
49
|
+
var describePolicy = (policy, options = {}) => {
|
|
50
|
+
const rules = options.rules ?? policy.rules;
|
|
51
|
+
const maximum = options.maxRules ?? 8;
|
|
52
|
+
const active = (options.playbook?.entries ?? []).filter((entry) => entry.status === "active");
|
|
53
|
+
if (rules.length === 0) {
|
|
54
|
+
return "No policy is installed yet — nothing is enforced, and every reader falls back to the constant compiled into it.";
|
|
55
|
+
}
|
|
56
|
+
const lines = [
|
|
57
|
+
`ACTIVE POLICY (${rules.length} rule${rules.length === 1 ? "" : "s"}, enforced — a refusal names the rule that blocked it):`,
|
|
58
|
+
...rules.slice(0, maximum).map((rule) => {
|
|
59
|
+
const scope = rule.scope && Object.keys(rule.scope).length > 0 ? ` [${scopeOf(rule)}]` : "";
|
|
60
|
+
return ` ${rule.tier}:${rule.id}${scope} — ${rule.constraint.kind}=${JSON.stringify(rule.constraint.value)} (${rule.reason})`;
|
|
61
|
+
})
|
|
62
|
+
];
|
|
63
|
+
if (rules.length > maximum) {
|
|
64
|
+
lines.push(` + ${rules.length - maximum} more — read the whole set before deciding.`);
|
|
65
|
+
}
|
|
66
|
+
lines.push(" A more specific scope beats a general one inside a tier; stronger tiers win outright.");
|
|
67
|
+
if (active.length > 0) {
|
|
68
|
+
lines.push("", "LEARNED (advisory — fills silence, never overrides a rule):");
|
|
69
|
+
for (const entry of active.slice(0, 4))
|
|
70
|
+
lines.push(` ${entry.statement}`);
|
|
71
|
+
}
|
|
72
|
+
return lines.join(`
|
|
73
|
+
`);
|
|
74
|
+
};
|
|
75
|
+
export {
|
|
76
|
+
describePolicy,
|
|
77
|
+
generatePolicyMarkdown
|
|
78
|
+
};
|
package/dist/medusa/index.cjs
CHANGED
|
@@ -1,47 +1,52 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
2
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var
|
|
5
|
+
function __accessProp(key) {
|
|
6
|
+
return this[key];
|
|
7
|
+
}
|
|
8
|
+
var __toCommonJS = (from) => {
|
|
9
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
10
|
+
if (entry)
|
|
11
|
+
return entry;
|
|
12
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
11
13
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (
|
|
13
|
-
if (!__hasOwnProp.call(
|
|
14
|
-
__defProp(
|
|
14
|
+
for (var key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(entry, key))
|
|
16
|
+
__defProp(entry, key, {
|
|
17
|
+
get: __accessProp.bind(from, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
15
20
|
}
|
|
16
|
-
|
|
21
|
+
__moduleCache.set(from, entry);
|
|
22
|
+
return entry;
|
|
23
|
+
};
|
|
24
|
+
var __moduleCache;
|
|
25
|
+
var __returnValue = (v) => v;
|
|
26
|
+
function __exportSetter(name, newValue) {
|
|
27
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
28
|
+
}
|
|
29
|
+
var __export = (target, all) => {
|
|
30
|
+
for (var name in all)
|
|
31
|
+
__defProp(target, name, {
|
|
32
|
+
get: all[name],
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
set: __exportSetter.bind(all, name)
|
|
36
|
+
});
|
|
17
37
|
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
38
|
|
|
20
39
|
// src/medusa/index.ts
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
40
|
+
var exports_medusa = {};
|
|
41
|
+
__export(exports_medusa, {
|
|
23
42
|
configRow: () => configRow,
|
|
24
43
|
createMedusaPolicyAdapter: () => createMedusaPolicyAdapter,
|
|
25
44
|
medusaGrants: () => medusaGrants,
|
|
26
45
|
requirePermission: () => requirePermission
|
|
27
46
|
});
|
|
28
|
-
module.exports = __toCommonJS(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
var toPolicyRule = (row) => ({
|
|
32
|
-
constraint: { kind: row.constraint_kind, value: row.constraint_value },
|
|
33
|
-
id: row.rule_key,
|
|
34
|
-
// Only `false` is worth carrying: `true` is the default a policy declares, and writing it back
|
|
35
|
-
// would make a rule that never said anything indistinguishable from one that agreed.
|
|
36
|
-
...row.overridable === false ? { overridable: false } : {},
|
|
37
|
-
reason: row.reason,
|
|
38
|
-
...row.scope ? { scope: row.scope } : {},
|
|
39
|
-
tier: row.tier
|
|
40
|
-
});
|
|
41
|
-
var toPolicyRules = (rows) => rows.filter((row) => (row.status ?? "active") === "active").map(toPolicyRule);
|
|
42
|
-
|
|
43
|
-
// src/medusa/index.ts
|
|
44
|
-
var configRow = (namespace, key) => (store) => store.get(namespace, key, void 0);
|
|
47
|
+
module.exports = __toCommonJS(exports_medusa);
|
|
48
|
+
var import_rows = require("../rows.cjs");
|
|
49
|
+
var configRow = (namespace, key) => (store) => store.get(namespace, key, undefined);
|
|
45
50
|
var defaultRow = (entry, eventPrefix) => ({
|
|
46
51
|
actor_kind: "system",
|
|
47
52
|
...entry.rejected ? { error: `rejected ${JSON.stringify(entry.rejected.value)}: ${entry.rejected.reason}` } : {},
|
|
@@ -54,7 +59,7 @@ var attempt = async (what) => {
|
|
|
54
59
|
try {
|
|
55
60
|
return await what();
|
|
56
61
|
} catch {
|
|
57
|
-
return
|
|
62
|
+
return;
|
|
58
63
|
}
|
|
59
64
|
};
|
|
60
65
|
var createMedusaPolicyAdapter = (options) => {
|
|
@@ -67,7 +72,7 @@ var createMedusaPolicyAdapter = (options) => {
|
|
|
67
72
|
config: {
|
|
68
73
|
get: async (kind, query) => {
|
|
69
74
|
const binding = bindings[kind];
|
|
70
|
-
return binding ? attempt(() => binding(store(), query)) :
|
|
75
|
+
return binding ? attempt(() => binding(store(), query)) : undefined;
|
|
71
76
|
}
|
|
72
77
|
},
|
|
73
78
|
journal: {
|
|
@@ -78,9 +83,7 @@ var createMedusaPolicyAdapter = (options) => {
|
|
|
78
83
|
name: `medusa:${options.moduleKey}`,
|
|
79
84
|
rule: {
|
|
80
85
|
rules: async () => [
|
|
81
|
-
...toPolicyRules(await service().listPolicyRules?.({ status: "active" }) ?? []),
|
|
82
|
-
// Appended, never prepended: the lattice decides authority, and a list order that could
|
|
83
|
-
// stand in for it would be a second, silent one.
|
|
86
|
+
...import_rows.toPolicyRules(await service().listPolicyRules?.({ status: "active" }) ?? []),
|
|
84
87
|
...await options.extraRules?.() ?? []
|
|
85
88
|
]
|
|
86
89
|
}
|
package/dist/medusa/index.d.cts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { PermissionAction } from '../permissions/index.cjs';
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import type { PermissionAction } from '../permissions/index.cjs';
|
|
2
|
+
import type { Awaitable, PolicyAdapter, PolicyJournalEntry, PolicyQuery, PolicyRule, PolicyRuleRow } from '../types.cjs';
|
|
4
3
|
/**
|
|
5
4
|
* The Medusa store, behind the ports the kernel reads.
|
|
6
5
|
*
|
|
@@ -10,19 +9,19 @@ import { A as Awaitable, P as PolicyQuery, d as PolicyRule, p as PolicyJournalEn
|
|
|
10
9
|
* stop dragging a module, a service and three ORM models behind them.
|
|
11
10
|
*/
|
|
12
11
|
/** The bit of the container this needs — structural, so a plain object stands in for it. */
|
|
13
|
-
type MedusaContainerLike = {
|
|
12
|
+
export type MedusaContainerLike = {
|
|
14
13
|
resolve: (key: string) => unknown;
|
|
15
14
|
};
|
|
16
15
|
/** The bit of the module service this needs: the generated list, and the generated create. */
|
|
17
|
-
type MedusaPolicyServiceLike = {
|
|
16
|
+
export type MedusaPolicyServiceLike = {
|
|
18
17
|
createPolicyJournalEntries?: (data: Record<string, unknown>) => Awaitable<unknown>;
|
|
19
18
|
listPolicyRules?: (filter: Record<string, unknown>) => Awaitable<readonly PolicyRuleRow[]>;
|
|
20
19
|
};
|
|
21
20
|
/** The bit of a runtime-config service this needs. Its `get` answers with the fallback it is given. */
|
|
22
|
-
type ConfigStoreLike = {
|
|
21
|
+
export type ConfigStoreLike = {
|
|
23
22
|
get: <T>(namespace: string, key: string, fallback: T) => Awaitable<T>;
|
|
24
23
|
};
|
|
25
|
-
type ConfigStoreBinding = (store: ConfigStoreLike, query: PolicyQuery) => Awaitable<unknown>;
|
|
24
|
+
export type ConfigStoreBinding = (store: ConfigStoreLike, query: PolicyQuery) => Awaitable<unknown>;
|
|
26
25
|
/**
|
|
27
26
|
* One row of the runtime config, as the value of one kind.
|
|
28
27
|
*
|
|
@@ -31,8 +30,8 @@ type ConfigStoreBinding = (store: ConfigStoreLike, query: PolicyQuery) => Awaita
|
|
|
31
30
|
* is to hand it something no row can legitimately hold. Junk in the row is not filtered here — the
|
|
32
31
|
* KIND's schema refuses it, once, for every layer that could produce one.
|
|
33
32
|
*/
|
|
34
|
-
declare const configRow: (namespace: string, key: string) => ConfigStoreBinding;
|
|
35
|
-
type MedusaPolicyAdapterOptions = {
|
|
33
|
+
export declare const configRow: (namespace: string, key: string) => ConfigStoreBinding;
|
|
34
|
+
export type MedusaPolicyAdapterOptions = {
|
|
36
35
|
/** Which config rows stand for which kind. A kind with no binding has no admin-set value. */
|
|
37
36
|
bindings?: Record<string, ConfigStoreBinding>;
|
|
38
37
|
configStoreKey?: string;
|
|
@@ -45,9 +44,9 @@ type MedusaPolicyAdapterOptions = {
|
|
|
45
44
|
/** The row this store keeps. Overridden when its columns are not these. */
|
|
46
45
|
toRow?: (entry: PolicyJournalEntry, eventPrefix: string) => Record<string, unknown>;
|
|
47
46
|
};
|
|
48
|
-
declare const createMedusaPolicyAdapter: (options: MedusaPolicyAdapterOptions) => PolicyAdapter;
|
|
47
|
+
export declare const createMedusaPolicyAdapter: (options: MedusaPolicyAdapterOptions) => PolicyAdapter;
|
|
49
48
|
/** One role as that module holds it: an id, and the policies granted to it. */
|
|
50
|
-
type MedusaRbacRole = {
|
|
49
|
+
export type MedusaRbacRole = {
|
|
51
50
|
id: string;
|
|
52
51
|
policies?: readonly PermissionAction[];
|
|
53
52
|
};
|
|
@@ -58,7 +57,7 @@ type MedusaRbacRole = {
|
|
|
58
57
|
* and a cache, which is why nothing that uses it can be answered without a booted server; the fetch
|
|
59
58
|
* is the caller's here, and the decision is a value.
|
|
60
59
|
*/
|
|
61
|
-
declare const medusaGrants: (roles: readonly MedusaRbacRole[]) => Record<string, readonly PermissionAction[]>;
|
|
60
|
+
export declare const medusaGrants: (roles: readonly MedusaRbacRole[]) => Record<string, readonly PermissionAction[]>;
|
|
62
61
|
/**
|
|
63
62
|
* The signature a middleware advertises, deliberately NOT the framework's `MiddlewareFunction`.
|
|
64
63
|
*
|
|
@@ -67,7 +66,7 @@ declare const medusaGrants: (roles: readonly MedusaRbacRole[]) => Record<string,
|
|
|
67
66
|
* `unknown` params are contravariant-safe: this assigns to every version's, and the runtime value
|
|
68
67
|
* is unchanged.
|
|
69
68
|
*/
|
|
70
|
-
type PortableMiddleware = (request: unknown, response: unknown, next: (error?: unknown) => void) => unknown;
|
|
69
|
+
export type PortableMiddleware = (request: unknown, response: unknown, next: (error?: unknown) => void) => unknown;
|
|
71
70
|
type Wrapper = (handler: PortableMiddleware, policies: PermissionAction[]) => PortableMiddleware;
|
|
72
71
|
/**
|
|
73
72
|
* The framework's own permission check as a one-liner a route array can hold.
|
|
@@ -76,6 +75,5 @@ type Wrapper = (handler: PortableMiddleware, policies: PermissionAction[]) => Po
|
|
|
76
75
|
* that imported it would be unusable anywhere else, and would pin one of the two framework copies.
|
|
77
76
|
* The wrapped handler does nothing but continue — the wrapper itself is the gate.
|
|
78
77
|
*/
|
|
79
|
-
declare const requirePermission: (wrap: Wrapper, ...policies: PermissionAction[]) => PortableMiddleware;
|
|
80
|
-
|
|
81
|
-
export { type ConfigStoreBinding, type ConfigStoreLike, type MedusaContainerLike, type MedusaPolicyAdapterOptions, type MedusaPolicyServiceLike, type MedusaRbacRole, type PortableMiddleware, configRow, createMedusaPolicyAdapter, medusaGrants, requirePermission };
|
|
78
|
+
export declare const requirePermission: (wrap: Wrapper, ...policies: PermissionAction[]) => PortableMiddleware;
|
|
79
|
+
export {};
|
package/dist/medusa/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { PermissionAction } from '../permissions/index.js';
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import type { PermissionAction } from '../permissions/index.js';
|
|
2
|
+
import type { Awaitable, PolicyAdapter, PolicyJournalEntry, PolicyQuery, PolicyRule, PolicyRuleRow } from '../types.js';
|
|
4
3
|
/**
|
|
5
4
|
* The Medusa store, behind the ports the kernel reads.
|
|
6
5
|
*
|
|
@@ -10,19 +9,19 @@ import { A as Awaitable, P as PolicyQuery, d as PolicyRule, p as PolicyJournalEn
|
|
|
10
9
|
* stop dragging a module, a service and three ORM models behind them.
|
|
11
10
|
*/
|
|
12
11
|
/** The bit of the container this needs — structural, so a plain object stands in for it. */
|
|
13
|
-
type MedusaContainerLike = {
|
|
12
|
+
export type MedusaContainerLike = {
|
|
14
13
|
resolve: (key: string) => unknown;
|
|
15
14
|
};
|
|
16
15
|
/** The bit of the module service this needs: the generated list, and the generated create. */
|
|
17
|
-
type MedusaPolicyServiceLike = {
|
|
16
|
+
export type MedusaPolicyServiceLike = {
|
|
18
17
|
createPolicyJournalEntries?: (data: Record<string, unknown>) => Awaitable<unknown>;
|
|
19
18
|
listPolicyRules?: (filter: Record<string, unknown>) => Awaitable<readonly PolicyRuleRow[]>;
|
|
20
19
|
};
|
|
21
20
|
/** The bit of a runtime-config service this needs. Its `get` answers with the fallback it is given. */
|
|
22
|
-
type ConfigStoreLike = {
|
|
21
|
+
export type ConfigStoreLike = {
|
|
23
22
|
get: <T>(namespace: string, key: string, fallback: T) => Awaitable<T>;
|
|
24
23
|
};
|
|
25
|
-
type ConfigStoreBinding = (store: ConfigStoreLike, query: PolicyQuery) => Awaitable<unknown>;
|
|
24
|
+
export type ConfigStoreBinding = (store: ConfigStoreLike, query: PolicyQuery) => Awaitable<unknown>;
|
|
26
25
|
/**
|
|
27
26
|
* One row of the runtime config, as the value of one kind.
|
|
28
27
|
*
|
|
@@ -31,8 +30,8 @@ type ConfigStoreBinding = (store: ConfigStoreLike, query: PolicyQuery) => Awaita
|
|
|
31
30
|
* is to hand it something no row can legitimately hold. Junk in the row is not filtered here — the
|
|
32
31
|
* KIND's schema refuses it, once, for every layer that could produce one.
|
|
33
32
|
*/
|
|
34
|
-
declare const configRow: (namespace: string, key: string) => ConfigStoreBinding;
|
|
35
|
-
type MedusaPolicyAdapterOptions = {
|
|
33
|
+
export declare const configRow: (namespace: string, key: string) => ConfigStoreBinding;
|
|
34
|
+
export type MedusaPolicyAdapterOptions = {
|
|
36
35
|
/** Which config rows stand for which kind. A kind with no binding has no admin-set value. */
|
|
37
36
|
bindings?: Record<string, ConfigStoreBinding>;
|
|
38
37
|
configStoreKey?: string;
|
|
@@ -45,9 +44,9 @@ type MedusaPolicyAdapterOptions = {
|
|
|
45
44
|
/** The row this store keeps. Overridden when its columns are not these. */
|
|
46
45
|
toRow?: (entry: PolicyJournalEntry, eventPrefix: string) => Record<string, unknown>;
|
|
47
46
|
};
|
|
48
|
-
declare const createMedusaPolicyAdapter: (options: MedusaPolicyAdapterOptions) => PolicyAdapter;
|
|
47
|
+
export declare const createMedusaPolicyAdapter: (options: MedusaPolicyAdapterOptions) => PolicyAdapter;
|
|
49
48
|
/** One role as that module holds it: an id, and the policies granted to it. */
|
|
50
|
-
type MedusaRbacRole = {
|
|
49
|
+
export type MedusaRbacRole = {
|
|
51
50
|
id: string;
|
|
52
51
|
policies?: readonly PermissionAction[];
|
|
53
52
|
};
|
|
@@ -58,7 +57,7 @@ type MedusaRbacRole = {
|
|
|
58
57
|
* and a cache, which is why nothing that uses it can be answered without a booted server; the fetch
|
|
59
58
|
* is the caller's here, and the decision is a value.
|
|
60
59
|
*/
|
|
61
|
-
declare const medusaGrants: (roles: readonly MedusaRbacRole[]) => Record<string, readonly PermissionAction[]>;
|
|
60
|
+
export declare const medusaGrants: (roles: readonly MedusaRbacRole[]) => Record<string, readonly PermissionAction[]>;
|
|
62
61
|
/**
|
|
63
62
|
* The signature a middleware advertises, deliberately NOT the framework's `MiddlewareFunction`.
|
|
64
63
|
*
|
|
@@ -67,7 +66,7 @@ declare const medusaGrants: (roles: readonly MedusaRbacRole[]) => Record<string,
|
|
|
67
66
|
* `unknown` params are contravariant-safe: this assigns to every version's, and the runtime value
|
|
68
67
|
* is unchanged.
|
|
69
68
|
*/
|
|
70
|
-
type PortableMiddleware = (request: unknown, response: unknown, next: (error?: unknown) => void) => unknown;
|
|
69
|
+
export type PortableMiddleware = (request: unknown, response: unknown, next: (error?: unknown) => void) => unknown;
|
|
71
70
|
type Wrapper = (handler: PortableMiddleware, policies: PermissionAction[]) => PortableMiddleware;
|
|
72
71
|
/**
|
|
73
72
|
* The framework's own permission check as a one-liner a route array can hold.
|
|
@@ -76,6 +75,5 @@ type Wrapper = (handler: PortableMiddleware, policies: PermissionAction[]) => Po
|
|
|
76
75
|
* that imported it would be unusable anywhere else, and would pin one of the two framework copies.
|
|
77
76
|
* The wrapped handler does nothing but continue — the wrapper itself is the gate.
|
|
78
77
|
*/
|
|
79
|
-
declare const requirePermission: (wrap: Wrapper, ...policies: PermissionAction[]) => PortableMiddleware;
|
|
80
|
-
|
|
81
|
-
export { type ConfigStoreBinding, type ConfigStoreLike, type MedusaContainerLike, type MedusaPolicyAdapterOptions, type MedusaPolicyServiceLike, type MedusaRbacRole, type PortableMiddleware, configRow, createMedusaPolicyAdapter, medusaGrants, requirePermission };
|
|
78
|
+
export declare const requirePermission: (wrap: Wrapper, ...policies: PermissionAction[]) => PortableMiddleware;
|
|
79
|
+
export {};
|
package/dist/medusa/index.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
toPolicyRules
|
|
3
|
-
} from "../chunk-JICJ4XEX.js";
|
|
4
|
-
|
|
5
1
|
// src/medusa/index.ts
|
|
6
|
-
|
|
2
|
+
import { toPolicyRules } from "../rows.js";
|
|
3
|
+
var configRow = (namespace, key) => (store) => store.get(namespace, key, undefined);
|
|
7
4
|
var defaultRow = (entry, eventPrefix) => ({
|
|
8
5
|
actor_kind: "system",
|
|
9
6
|
...entry.rejected ? { error: `rejected ${JSON.stringify(entry.rejected.value)}: ${entry.rejected.reason}` } : {},
|
|
@@ -16,7 +13,7 @@ var attempt = async (what) => {
|
|
|
16
13
|
try {
|
|
17
14
|
return await what();
|
|
18
15
|
} catch {
|
|
19
|
-
return
|
|
16
|
+
return;
|
|
20
17
|
}
|
|
21
18
|
};
|
|
22
19
|
var createMedusaPolicyAdapter = (options) => {
|
|
@@ -29,7 +26,7 @@ var createMedusaPolicyAdapter = (options) => {
|
|
|
29
26
|
config: {
|
|
30
27
|
get: async (kind, query) => {
|
|
31
28
|
const binding = bindings[kind];
|
|
32
|
-
return binding ? attempt(() => binding(store(), query)) :
|
|
29
|
+
return binding ? attempt(() => binding(store(), query)) : undefined;
|
|
33
30
|
}
|
|
34
31
|
},
|
|
35
32
|
journal: {
|
|
@@ -41,8 +38,6 @@ var createMedusaPolicyAdapter = (options) => {
|
|
|
41
38
|
rule: {
|
|
42
39
|
rules: async () => [
|
|
43
40
|
...toPolicyRules(await service().listPolicyRules?.({ status: "active" }) ?? []),
|
|
44
|
-
// Appended, never prepended: the lattice decides authority, and a list order that could
|
|
45
|
-
// stand in for it would be a second, silent one.
|
|
46
41
|
...await options.extraRules?.() ?? []
|
|
47
42
|
]
|
|
48
43
|
}
|