@pegasimed.com/pegasi-sail-connect-shared 0.2.0-dev.2 → 0.2.0-dev.4
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 +57 -19
- package/dist/capabilities/catalog-data.d.ts +275 -259
- package/dist/capabilities/catalog-data.d.ts.map +1 -1
- package/dist/capabilities/catalog-data.js +276 -259
- package/dist/capabilities/catalog-data.js.map +1 -1
- package/dist/capabilities/migration-data.d.ts +56 -165
- package/dist/capabilities/migration-data.d.ts.map +1 -1
- package/dist/capabilities/migration-data.js +31 -119
- package/dist/capabilities/migration-data.js.map +1 -1
- package/dist/capabilities/migration.d.ts +20 -20
- package/dist/capabilities/migration.d.ts.map +1 -1
- package/dist/capabilities/migration.js +22 -34
- package/dist/capabilities/migration.js.map +1 -1
- package/dist/capabilities/types.d.ts +3 -2
- package/dist/capabilities/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/scripts/check-service-keys.mjs +30 -7
|
@@ -13,10 +13,12 @@
|
|
|
13
13
|
// - "drift": the literal has the shape `servicio:recurso:acción` (three
|
|
14
14
|
// segments of the catalog grammar) but is not a catalog key; or it is a
|
|
15
15
|
// key-shaped literal with `*` anywhere in a segment (`patient:dom*:read`,
|
|
16
|
-
// `patient:**:read`, `*:*:*`), a two-segment `servicio:*`
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
// an
|
|
16
|
+
// `patient:**:read`, `*:*:*`), a two-segment `servicio:*` whose first
|
|
17
|
+
// segment is a catalog service or the namespace of an old key of
|
|
18
|
+
// PERMISSION_MIGRATION (`patient:*`, `meetings:*`, `access-api:*`,
|
|
19
|
+
// `users:*`), or an old key with `*`. A literal with `*` is always drift,
|
|
20
|
+
// before "old": there are no wildcard grants, every grant is an explicit
|
|
21
|
+
// catalog key, and since 0.2.0-dev.4 every stored wildcard is quarantined.
|
|
20
22
|
//
|
|
21
23
|
// Keys built at run time (template literals with substitutions,
|
|
22
24
|
// concatenations) are not visible here: the authorization helper of the
|
|
@@ -57,12 +59,14 @@ const WILDCARD_SEGMENT = "[a-z*][a-z0-9*]*(?:-[a-z0-9*]+)*";
|
|
|
57
59
|
/** Three key-shaped segments with `*` allowed anywhere in them. */
|
|
58
60
|
export const WILDCARD_KEY_SHAPE = new RegExp(`^${WILDCARD_SEGMENT}:${WILDCARD_SEGMENT}:${WILDCARD_SEGMENT}$`);
|
|
59
61
|
const TWO_SEGMENT_WILDCARD = new RegExp(`^(${SEGMENT}):${WILDCARD_SEGMENT}$`);
|
|
62
|
+
const NAMESPACE = new RegExp(`^${SEGMENT}$`);
|
|
60
63
|
|
|
61
64
|
/**
|
|
62
65
|
* True for a literal with `*` that has the shape of a key: three segments
|
|
63
66
|
* with `*` anywhere, or two segments (`servicio:*`, `servicio:recu*`) whose
|
|
64
|
-
* first segment is
|
|
65
|
-
*
|
|
67
|
+
* first segment is in `services` (scanFiles passes wildcardNamespaces: the
|
|
68
|
+
* catalog services and the old key namespaces). Other text with `*` (a MIME
|
|
69
|
+
* type, a glob, `image:*` of no service) is not a permission.
|
|
66
70
|
*/
|
|
67
71
|
export function isWildcardKeyLiteral(text, services) {
|
|
68
72
|
if (!text.includes("*")) {
|
|
@@ -129,6 +133,25 @@ export function collectStringLiterals(sourceText, fileName) {
|
|
|
129
133
|
return literals;
|
|
130
134
|
}
|
|
131
135
|
|
|
136
|
+
/**
|
|
137
|
+
* First segments whose two-segment `servicio:*` is a wildcard grant: the
|
|
138
|
+
* catalog services and the namespaces of the old keys of PERMISSION_MIGRATION.
|
|
139
|
+
* Since 0.2.0-dev.4 no wildcard is an old key (all are quarantined), so an old
|
|
140
|
+
* service name such as `access-api` (of `access-api:*`) comes from the old
|
|
141
|
+
* keys of its namespace (`access-api:write`...).
|
|
142
|
+
*/
|
|
143
|
+
export function wildcardNamespaces(catalog) {
|
|
144
|
+
const namespaces = new Set(catalog.services ?? []);
|
|
145
|
+
for (const old of catalog.oldKeys) {
|
|
146
|
+
const separator = old.indexOf(":");
|
|
147
|
+
const namespace = separator > 0 ? old.slice(0, separator).toLowerCase() : "";
|
|
148
|
+
if (NAMESPACE.test(namespace)) {
|
|
149
|
+
namespaces.add(namespace);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return namespaces;
|
|
153
|
+
}
|
|
154
|
+
|
|
132
155
|
/**
|
|
133
156
|
* Findings of the literals of the given source files. `catalog` supplies
|
|
134
157
|
* `findUnknownPermissionKeys`, the old keys of PERMISSION_MIGRATION and the
|
|
@@ -136,7 +159,7 @@ export function collectStringLiterals(sourceText, fileName) {
|
|
|
136
159
|
*/
|
|
137
160
|
export function scanFiles(files, catalog, { root = cwd() } = {}) {
|
|
138
161
|
const oldKeys = new Set(catalog.oldKeys);
|
|
139
|
-
const services =
|
|
162
|
+
const services = wildcardNamespaces(catalog);
|
|
140
163
|
const findings = [];
|
|
141
164
|
let allowed = 0;
|
|
142
165
|
for (const file of files) {
|