@pegasimed.com/pegasi-sail-connect-shared 0.1.0-dev.0 → 0.2.0-dev.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 +398 -125
- package/dist/authorization/index.d.ts +3 -0
- package/dist/authorization/index.d.ts.map +1 -0
- package/dist/authorization/index.js +3 -0
- package/dist/authorization/index.js.map +1 -0
- package/dist/authorization/internal-authorization.d.ts +105 -0
- package/dist/authorization/internal-authorization.d.ts.map +1 -0
- package/dist/authorization/internal-authorization.js +287 -0
- package/dist/authorization/internal-authorization.js.map +1 -0
- package/dist/capabilities/catalog-data.d.ts +3917 -0
- package/dist/capabilities/catalog-data.d.ts.map +1 -0
- package/dist/capabilities/catalog-data.js +4244 -0
- package/dist/capabilities/catalog-data.js.map +1 -0
- package/dist/capabilities/catalog.d.ts +38 -0
- package/dist/capabilities/catalog.d.ts.map +1 -0
- package/dist/capabilities/catalog.js +91 -0
- package/dist/capabilities/catalog.js.map +1 -0
- package/dist/capabilities/index.d.ts +8 -0
- package/dist/capabilities/index.d.ts.map +1 -0
- package/dist/capabilities/index.js +8 -0
- package/dist/capabilities/index.js.map +1 -0
- package/dist/capabilities/list.d.ts +46 -0
- package/dist/capabilities/list.d.ts.map +1 -0
- package/dist/capabilities/list.js +80 -0
- package/dist/capabilities/list.js.map +1 -0
- package/dist/capabilities/match.d.ts +42 -0
- package/dist/capabilities/match.d.ts.map +1 -0
- package/dist/capabilities/match.js +139 -0
- package/dist/capabilities/match.js.map +1 -0
- package/dist/capabilities/migration-data.d.ts +2424 -0
- package/dist/capabilities/migration-data.d.ts.map +1 -0
- package/dist/capabilities/migration-data.js +2646 -0
- package/dist/capabilities/migration-data.js.map +1 -0
- package/dist/capabilities/migration.d.ts +176 -0
- package/dist/capabilities/migration.d.ts.map +1 -0
- package/dist/capabilities/migration.js +209 -0
- package/dist/capabilities/migration.js.map +1 -0
- package/dist/capabilities/types.d.ts +124 -0
- package/dist/capabilities/types.d.ts.map +1 -0
- package/dist/capabilities/types.js +2 -0
- package/dist/capabilities/types.js.map +1 -0
- package/dist/capabilities/validate.d.ts +19 -0
- package/dist/capabilities/validate.d.ts.map +1 -0
- package/dist/capabilities/validate.js +235 -0
- package/dist/capabilities/validate.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/package.json +111 -102
- package/scripts/check-service-keys.mjs +250 -0
- package/scripts/lint-phi.mjs +266 -266
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { getCapability } from "./catalog.js";
|
|
2
|
+
import { appendOwn, ownDataValue, readList } from "./list.js";
|
|
3
|
+
/**
|
|
4
|
+
* Thrown by the assert helpers. It carries only the required keys, never the
|
|
5
|
+
* caller's granted permissions, so it is safe to log and to map to a 403.
|
|
6
|
+
*/
|
|
7
|
+
export class PermissionDeniedError extends Error {
|
|
8
|
+
code = "permission_denied";
|
|
9
|
+
required;
|
|
10
|
+
mode;
|
|
11
|
+
constructor(required, mode) {
|
|
12
|
+
super(`Permission denied: requires ${mode === "any" ? "any of" : "all of"} [${required.join(", ")}].`);
|
|
13
|
+
this.name = "PermissionDeniedError";
|
|
14
|
+
this.required = Object.freeze([...required]);
|
|
15
|
+
this.mode = mode;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
// Exact membership: only the granted key equal to the required one counts.
|
|
19
|
+
// granted is a plain copy (readList): no iterator of the input runs here.
|
|
20
|
+
function includesKey(granted, key) {
|
|
21
|
+
for (let index = 0; index < granted.length; index += 1) {
|
|
22
|
+
if (granted[index] === key) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
// Plain copy of the granted list, or undefined when it is not a readable array.
|
|
29
|
+
function readGranted(granted) {
|
|
30
|
+
const read = readList(granted);
|
|
31
|
+
return read.status === "ok" ? read.items : undefined;
|
|
32
|
+
}
|
|
33
|
+
function satisfies(granted, required) {
|
|
34
|
+
try {
|
|
35
|
+
const target = typeof required === "string" ? getCapability(required) : undefined;
|
|
36
|
+
return target !== undefined && includesKey(granted, target.key);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* True when the granted permissions contain the required key, exactly: there
|
|
44
|
+
* are no wildcard grants, so nothing but the key itself satisfies it (a value
|
|
45
|
+
* with `*`, an old key or a prefix grants nothing). Comparison is
|
|
46
|
+
* case-sensitive. The granted list is copied by index (its iterator and
|
|
47
|
+
* methods never run); a list that is not an array, is longer than
|
|
48
|
+
* MAX_LIST_LENGTH or throws when read grants nothing. Never throws. A required
|
|
49
|
+
* value that is not a catalog key is never satisfied.
|
|
50
|
+
*/
|
|
51
|
+
export function matchPermission(granted, required) {
|
|
52
|
+
const items = readGranted(granted);
|
|
53
|
+
return items !== undefined && satisfies(items, required);
|
|
54
|
+
}
|
|
55
|
+
function readRequired(required) {
|
|
56
|
+
const read = readList(required);
|
|
57
|
+
const keys = [];
|
|
58
|
+
let allStrings = true;
|
|
59
|
+
for (let index = 0; index < read.items.length; index += 1) {
|
|
60
|
+
const key = read.items[index];
|
|
61
|
+
if (typeof key === "string") {
|
|
62
|
+
appendOwn(keys, key);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
allStrings = false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return { keys, readable: read.status === "ok", allStrings };
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* True when at least one required key is granted (exact membership). Fails
|
|
72
|
+
* closed: an empty list, or an unreadable granted or required list, is never
|
|
73
|
+
* satisfied; a non-string element of a readable required list is simply never
|
|
74
|
+
* satisfied.
|
|
75
|
+
*/
|
|
76
|
+
export function hasAnyPermission(granted, required) {
|
|
77
|
+
const { keys, readable } = readRequired(required);
|
|
78
|
+
const items = readGranted(granted);
|
|
79
|
+
if (!readable || items === undefined) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
for (let index = 0; index < keys.length; index += 1) {
|
|
83
|
+
if (satisfies(items, keys[index])) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* True when every required key is granted (exact membership). Fails closed:
|
|
91
|
+
* an empty or unreadable list, or one with a non-string element, is never
|
|
92
|
+
* satisfied.
|
|
93
|
+
*/
|
|
94
|
+
export function hasAllPermissions(granted, required) {
|
|
95
|
+
const { keys, readable, allStrings } = readRequired(required);
|
|
96
|
+
const items = readGranted(granted);
|
|
97
|
+
if (!readable || !allStrings || keys.length === 0 || items === undefined) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
for (let index = 0; index < keys.length; index += 1) {
|
|
101
|
+
if (!satisfies(items, keys[index])) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
function requiredList(required) {
|
|
108
|
+
return readRequired(required).keys;
|
|
109
|
+
}
|
|
110
|
+
// Only the context's own data property counts: an inherited `permissions`
|
|
111
|
+
// (for example a polluted Object.prototype) or a getter grants nothing.
|
|
112
|
+
function permissionsOf(ctx) {
|
|
113
|
+
try {
|
|
114
|
+
if (typeof ctx !== "object" || ctx === null) {
|
|
115
|
+
return [];
|
|
116
|
+
}
|
|
117
|
+
const permissions = ownDataValue(ctx, "permissions");
|
|
118
|
+
return Array.isArray(permissions) ? permissions : [];
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
export function assertPermission(ctx, required) {
|
|
125
|
+
if (!matchPermission(permissionsOf(ctx), required)) {
|
|
126
|
+
throw new PermissionDeniedError(requiredList([required]), "all");
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
export function assertAnyPermission(ctx, required) {
|
|
130
|
+
if (!hasAnyPermission(permissionsOf(ctx), required)) {
|
|
131
|
+
throw new PermissionDeniedError(requiredList(required), "any");
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
export function assertAllPermissions(ctx, required) {
|
|
135
|
+
if (!hasAllPermissions(permissionsOf(ctx), required)) {
|
|
136
|
+
throw new PermissionDeniedError(requiredList(required), "all");
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=match.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match.js","sourceRoot":"","sources":["../../src/capabilities/match.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAO9D;;;GAGG;AACH,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IACrC,IAAI,GAAG,mBAAmB,CAAC;IAC3B,QAAQ,CAA2B;IACnC,IAAI,CAAgB;IAE7B,YAAY,QAAkC,EAAE,IAAmB;QACjE,KAAK,CAAC,+BAA+B,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACvG,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;QACpC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC;QAC7C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAED,2EAA2E;AAC3E,0EAA0E;AAC1E,SAAS,WAAW,CAAC,OAA2B,EAAE,GAAW;IAC3D,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,EAAE,KAAK,IAAI,C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