@geonosis/policy 1.1.0 → 1.3.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/README.md +16 -0
- package/dist/drizzle/index.cjs +86 -0
- package/dist/drizzle/index.d.cts +43 -0
- package/dist/index.cjs +832 -0
- package/dist/index.d.cts +383 -0
- package/dist/index.d.ts +9 -1
- package/dist/index.js +22 -0
- package/dist/medusa/index.cjs +91 -0
- package/dist/medusa/index.d.cts +81 -0
- package/dist/permissions/index.cjs +124 -0
- package/dist/permissions/index.d.cts +126 -0
- package/dist/types-DzC5zTZ8.d.cts +202 -0
- package/package.json +34 -10
package/README.md
CHANGED
|
@@ -105,3 +105,19 @@ consumer. It is DONE when dielime depends on the published version and has delet
|
|
|
105
105
|
every check in the conformance suite run without a booted server.
|
|
106
106
|
- **No opinion about your tiers.** Including the one that looks universal: whether an unmarked rule
|
|
107
107
|
may be overridden is `overridableByDefault`, because the two consumers answer it oppositely.
|
|
108
|
+
|
|
109
|
+
## Consumable from CommonJS
|
|
110
|
+
|
|
111
|
+
A Medusa backend is `module: Node16` CommonJS **by upstream requirement**, not by preference. This
|
|
112
|
+
package ships both builds and a `require` condition carrying its own `.d.cts`, so a static import
|
|
113
|
+
type-checks and `require()` works:
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import { definePolicy } from '@geonosis/policy' // ESM, module: Node16 or ESNext
|
|
117
|
+
const { definePolicy } = require('@geonosis/policy') // CommonJS
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
An ESM-only package is a wall for such a backend, and no amount of parity gets over it: dielime
|
|
121
|
+
measured `@geonosis/testbed` at 15/15 identical and still could not adopt it, because a static
|
|
122
|
+
import is TS1479 and `await import()` cannot serve the synchronous `describe()` registration its 107
|
|
123
|
+
suites are built on.
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/drizzle/index.ts
|
|
21
|
+
var drizzle_exports = {};
|
|
22
|
+
__export(drizzle_exports, {
|
|
23
|
+
createDrizzlePolicyAdapter: () => createDrizzlePolicyAdapter,
|
|
24
|
+
policyJournalColumns: () => policyJournalColumns,
|
|
25
|
+
policyRuleColumns: () => policyRuleColumns
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(drizzle_exports);
|
|
28
|
+
|
|
29
|
+
// src/rows.ts
|
|
30
|
+
var toPolicyRule = (row) => ({
|
|
31
|
+
constraint: { kind: row.constraint_kind, value: row.constraint_value },
|
|
32
|
+
id: row.rule_key,
|
|
33
|
+
// Only `false` is worth carrying: `true` is the default a policy declares, and writing it back
|
|
34
|
+
// would make a rule that never said anything indistinguishable from one that agreed.
|
|
35
|
+
...row.overridable === false ? { overridable: false } : {},
|
|
36
|
+
reason: row.reason,
|
|
37
|
+
...row.scope ? { scope: row.scope } : {},
|
|
38
|
+
tier: row.tier
|
|
39
|
+
});
|
|
40
|
+
var toPolicyRules = (rows) => rows.filter((row) => (row.status ?? "active") === "active").map(toPolicyRule);
|
|
41
|
+
|
|
42
|
+
// src/drizzle/index.ts
|
|
43
|
+
var policyRuleColumns = {
|
|
44
|
+
constraint_kind: "text",
|
|
45
|
+
constraint_value: "json",
|
|
46
|
+
overridable: "boolean",
|
|
47
|
+
reason: "text",
|
|
48
|
+
rule_key: "text",
|
|
49
|
+
scope: "json",
|
|
50
|
+
status: "text",
|
|
51
|
+
tier: "text"
|
|
52
|
+
};
|
|
53
|
+
var policyJournalColumns = {
|
|
54
|
+
actor_id: "text",
|
|
55
|
+
actor_kind: "text",
|
|
56
|
+
error: "text",
|
|
57
|
+
event_name: "text",
|
|
58
|
+
fell_back_to: "json",
|
|
59
|
+
op: "text",
|
|
60
|
+
subject: "text"
|
|
61
|
+
};
|
|
62
|
+
var attempt = async (what) => {
|
|
63
|
+
try {
|
|
64
|
+
return await what();
|
|
65
|
+
} catch {
|
|
66
|
+
return void 0;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
var toRow = (entry) => ({
|
|
70
|
+
actor_kind: "system",
|
|
71
|
+
...entry.rejected ? { error: `rejected ${JSON.stringify(entry.rejected.value)}: ${entry.rejected.reason}` } : {},
|
|
72
|
+
event_name: entry.event,
|
|
73
|
+
fell_back_to: { constraintKind: entry.kind, value: entry.fellBackTo },
|
|
74
|
+
...entry.op ? { op: entry.op } : {},
|
|
75
|
+
...entry.subject ? { subject: entry.subject } : {}
|
|
76
|
+
});
|
|
77
|
+
var createDrizzlePolicyAdapter = (options) => ({
|
|
78
|
+
...options.config ? { config: { get: async (kind, query) => attempt(() => options.config?.(kind, query)) } } : {},
|
|
79
|
+
...options.journal ? {
|
|
80
|
+
journal: {
|
|
81
|
+
write: async (entry) => void await attempt(() => options.journal?.(toRow(entry)))
|
|
82
|
+
}
|
|
83
|
+
} : {},
|
|
84
|
+
name: "drizzle",
|
|
85
|
+
rule: { rules: async () => toPolicyRules(await options.rules({ status: "active" }) ?? []) }
|
|
86
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { P as PolicyQuery, A as Awaitable, a as PolicyRuleRow, b as PolicyAdapter } from '../types-DzC5zTZ8.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A drizzle table, behind the ports the kernel reads.
|
|
5
|
+
*
|
|
6
|
+
* Nothing here imports `drizzle-orm`. The query is the store's — a repo whose law says queries are
|
|
7
|
+
* builders living in its own data layer would not accept one written in a dependency, and a package
|
|
8
|
+
* that carried the ORM would be unusable in the other consumer's runtime. What this contributes is
|
|
9
|
+
* the column contract, the mapping, and the posture: a store that is down answers with nothing and
|
|
10
|
+
* changes no decision.
|
|
11
|
+
*/
|
|
12
|
+
/** The columns the kernel reads. Declared once, so a table and a mapper cannot drift apart. */
|
|
13
|
+
declare const policyRuleColumns: {
|
|
14
|
+
readonly constraint_kind: "text";
|
|
15
|
+
readonly constraint_value: "json";
|
|
16
|
+
readonly overridable: "boolean";
|
|
17
|
+
readonly reason: "text";
|
|
18
|
+
readonly rule_key: "text";
|
|
19
|
+
readonly scope: "json";
|
|
20
|
+
readonly status: "text";
|
|
21
|
+
readonly tier: "text";
|
|
22
|
+
};
|
|
23
|
+
/** The journal's columns. There is no `rejected` one: a rejection is written into `error`. */
|
|
24
|
+
declare const policyJournalColumns: {
|
|
25
|
+
readonly actor_id: "text";
|
|
26
|
+
readonly actor_kind: "text";
|
|
27
|
+
readonly error: "text";
|
|
28
|
+
readonly event_name: "text";
|
|
29
|
+
readonly fell_back_to: "json";
|
|
30
|
+
readonly op: "text";
|
|
31
|
+
readonly subject: "text";
|
|
32
|
+
};
|
|
33
|
+
type DrizzlePolicyAdapterOptions = {
|
|
34
|
+
config?: (kind: string, query: PolicyQuery) => Awaitable<unknown>;
|
|
35
|
+
/** Absent when the store has no journal table. Half an adapter is honest; a silent drop is not. */
|
|
36
|
+
journal?: (row: Record<string, unknown>) => Awaitable<unknown>;
|
|
37
|
+
rules: (filter: {
|
|
38
|
+
status: string;
|
|
39
|
+
}) => Awaitable<readonly PolicyRuleRow[]>;
|
|
40
|
+
};
|
|
41
|
+
declare const createDrizzlePolicyAdapter: (options: DrizzlePolicyAdapterOptions) => PolicyAdapter;
|
|
42
|
+
|
|
43
|
+
export { type DrizzlePolicyAdapterOptions, createDrizzlePolicyAdapter, policyJournalColumns, policyRuleColumns };
|