@pegasimed.com/pegasi-sail-connect-shared 0.2.0-dev.2 → 0.2.0-dev.20
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 +651 -27
- package/dist/authorization-testing.d.ts +229 -0
- package/dist/authorization-testing.d.ts.map +1 -0
- package/dist/authorization-testing.js +744 -0
- package/dist/authorization-testing.js.map +1 -0
- package/dist/capabilities/catalog-data.d.ts +2212 -336
- package/dist/capabilities/catalog-data.d.ts.map +1 -1
- package/dist/capabilities/catalog-data.js +2264 -317
- package/dist/capabilities/catalog-data.js.map +1 -1
- package/dist/capabilities/catalog.d.ts +1 -1
- package/dist/capabilities/catalog.d.ts.map +1 -1
- package/dist/capabilities/catalog.js +1 -1
- package/dist/capabilities/catalog.js.map +1 -1
- package/dist/capabilities/index.d.ts +4 -0
- package/dist/capabilities/index.d.ts.map +1 -1
- package/dist/capabilities/index.js +7 -0
- package/dist/capabilities/index.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 +9 -2
- package/dist/capabilities/types.d.ts.map +1 -1
- package/dist/capabilities/validate.d.ts +1 -1
- package/dist/capabilities/validate.d.ts.map +1 -1
- package/dist/capabilities/validate.js +9 -0
- package/dist/capabilities/validate.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/organization/index.d.ts +141 -0
- package/dist/organization/index.d.ts.map +1 -0
- package/dist/organization/index.js +93 -0
- package/dist/organization/index.js.map +1 -0
- package/package.json +9 -1
- package/scripts/check-service-keys.mjs +30 -7
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/** Organization kinds shared by attribute consumers; no kind grants attributes. */
|
|
2
|
+
export const ORGANIZATION_KINDS = Object.freeze([
|
|
3
|
+
"tenant", "hospital", "site", "department", "service", "unit",
|
|
4
|
+
"customer", "supplier", "manufacturer", "insurer"
|
|
5
|
+
]);
|
|
6
|
+
const clinicalKinds = Object.freeze([
|
|
7
|
+
"hospital", "site", "department", "service", "unit"
|
|
8
|
+
]);
|
|
9
|
+
const administrativeKinds = Object.freeze([
|
|
10
|
+
"tenant", ...clinicalKinds
|
|
11
|
+
]);
|
|
12
|
+
const noDependencies = Object.freeze([]);
|
|
13
|
+
// Labels: legacy snapshot 2026-06-14, except budgets (owner decision WP #1310).
|
|
14
|
+
// Descriptions express catalog intent, never proof of an implemented authorization guard.
|
|
15
|
+
const definitions = [
|
|
16
|
+
{ key: "board-host", family: "flow", label: "Anfitrión de comité", description: "Identifica organizaciones con agendas para comité médico y listado de citas.", allowedKinds: clinicalKinds },
|
|
17
|
+
{ key: "patient-admission", family: "flow", label: "Admisión de paciente", description: "Identifica organizaciones para admisión de pacientes y selección de agendas de admisión y destinos de traslado.", allowedKinds: clinicalKinds },
|
|
18
|
+
{ key: "patient-transfer", family: "flow", label: "Traslado de paciente", description: "Declara la intención de participar en traslados; no se acreditó un consumidor funcional de esta clave.", allowedKinds: clinicalKinds },
|
|
19
|
+
{ key: "schedule-appointment", family: "flow", label: "Agenda cita", description: "Identifica organizaciones con agendas para citas y actividades de cita del flujo de atención.", allowedKinds: clinicalKinds },
|
|
20
|
+
{ key: "schedule-procedure", family: "flow", label: "Agenda procedimiento", description: "Identifica organizaciones con agendas para procedimientos y sus actividades del flujo de atención.", allowedKinds: clinicalKinds },
|
|
21
|
+
{ key: "schedule-reception", family: "flow", label: "Agenda recepción", description: "Identifica organizaciones con agendas de recepción; es independiente de la capacidad física de una ubicación.", allowedKinds: clinicalKinds },
|
|
22
|
+
{ key: "accounts-payable", family: "administrative", label: "Cuentas por pagar", description: "Declara operación de cuentas por pagar; no se acreditó un control operativo basado en esta clave.", allowedKinds: administrativeKinds },
|
|
23
|
+
{ key: "accounts-receivable", family: "administrative", label: "Cuentas por cobrar", description: "Declara operación de cuentas por cobrar; no se acreditó un control operativo basado en esta clave.", allowedKinds: administrativeKinds },
|
|
24
|
+
{ key: "budgets", family: "administrative", label: "Presupuestos", description: "Declara operación de presupuestos de la organización; es independiente de la emisión fiscal y no acredita por sí sola autorización para cotizar.", allowedKinds: administrativeKinds },
|
|
25
|
+
{ key: "cases", family: "administrative", label: "Casos", description: "Identifica organizaciones operadoras de casos en recepción y admisión, con condiciones clínicas evaluadas por separado.", allowedKinds: administrativeKinds },
|
|
26
|
+
{ key: "coverages", family: "administrative", label: "Coberturas", description: "Declara operación de coberturas; no acredita que una contraparte aseguradora sea la organización operadora.", allowedKinds: administrativeKinds },
|
|
27
|
+
{ key: "fiscal-documents", family: "administrative", label: "Documentos fiscales", description: "Declara operación de documentos fiscales; no acredita por sí sola autorización para facturar o cotizar.", allowedKinds: administrativeKinds },
|
|
28
|
+
{ key: "inventory", family: "administrative", label: "Inventario", description: "Declara operación de inventario; permisos de usuario y pertenencia a almacenes se evalúan por separado.", allowedKinds: administrativeKinds },
|
|
29
|
+
{ key: "payments", family: "administrative", label: "Pagos", description: "Declara operación de pagos; no se acreditó un control operativo común basado en esta clave.", allowedKinds: administrativeKinds },
|
|
30
|
+
{ key: "professional-fees", family: "administrative", label: "Honorarios profesionales", description: "Declara operación de honorarios profesionales; no se acreditó un consumidor funcional de esta clave.", allowedKinds: administrativeKinds },
|
|
31
|
+
{ key: "treasury", family: "administrative", label: "Tesorería", description: "Declara operación de tesorería; los permisos de usuario siguen siendo una dimensión independiente.", allowedKinds: administrativeKinds }
|
|
32
|
+
];
|
|
33
|
+
/** All entries are active, but none are assigned by default. Deeply frozen. */
|
|
34
|
+
export const ORGANIZATION_ATTRIBUTE_CATALOG = Object.freeze(definitions.map((entry) => Object.freeze({ ...entry, status: "active", dependencies: noDependencies })));
|
|
35
|
+
/** Canonical ASCII lexicographic order, also used by normalizeOrganizationAttributes. */
|
|
36
|
+
export const ORGANIZATION_ATTRIBUTE_KEYS = Object.freeze(definitions.map((entry) => entry.key).sort());
|
|
37
|
+
export function isOrganizationKind(value) {
|
|
38
|
+
return typeof value === "string" && ORGANIZATION_KINDS.some((kind) => kind === value);
|
|
39
|
+
}
|
|
40
|
+
export function isOrganizationAttributeKey(value) {
|
|
41
|
+
return typeof value === "string" && ORGANIZATION_ATTRIBUTE_KEYS.some((key) => key === value);
|
|
42
|
+
}
|
|
43
|
+
export function getOrganizationAttribute(value) {
|
|
44
|
+
return ORGANIZATION_ATTRIBUTE_CATALOG.find((entry) => entry.key === value);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Validate the complete resulting set, including after a kind change.
|
|
48
|
+
* Accept only dense own data arrays bounded by the catalog size. No coercion,
|
|
49
|
+
* getters, aliases, silent deduplication, defaults or inherited attributes.
|
|
50
|
+
* Return the first stable error without echoing caller data. Never throws.
|
|
51
|
+
*/
|
|
52
|
+
export function validateOrganizationAttributes(kind, value) {
|
|
53
|
+
if (!isOrganizationKind(kind))
|
|
54
|
+
return { ok: false, code: "invalid-kind" };
|
|
55
|
+
try {
|
|
56
|
+
if (!Array.isArray(value))
|
|
57
|
+
return { ok: false, code: "invalid-list" };
|
|
58
|
+
const lengthDescriptor = Object.getOwnPropertyDescriptor(value, "length");
|
|
59
|
+
const length = lengthDescriptor?.value;
|
|
60
|
+
if (typeof length !== "number" || !Number.isInteger(length) || length < 0 || length > ORGANIZATION_ATTRIBUTE_KEYS.length) {
|
|
61
|
+
return { ok: false, code: "invalid-list" };
|
|
62
|
+
}
|
|
63
|
+
const attributes = [];
|
|
64
|
+
const seen = new Set();
|
|
65
|
+
for (let index = 0; index < length; index += 1) {
|
|
66
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, String(index));
|
|
67
|
+
if (!descriptor || !("value" in descriptor))
|
|
68
|
+
return { ok: false, code: "invalid-list", index };
|
|
69
|
+
const key = descriptor.value;
|
|
70
|
+
if (!isOrganizationAttributeKey(key))
|
|
71
|
+
return { ok: false, code: "unknown-attribute", index };
|
|
72
|
+
if (seen.has(key))
|
|
73
|
+
return { ok: false, code: "duplicate-attribute", index };
|
|
74
|
+
const definition = getOrganizationAttribute(key);
|
|
75
|
+
if (!definition.allowedKinds.includes(kind))
|
|
76
|
+
return { ok: false, code: "attribute-not-allowed", index };
|
|
77
|
+
seen.add(key);
|
|
78
|
+
attributes.push(key);
|
|
79
|
+
}
|
|
80
|
+
return { ok: true, attributes: Object.freeze(attributes) };
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return { ok: false, code: "invalid-list" };
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/** Validate first, then sort a fresh frozen array; never changes caller input. */
|
|
87
|
+
export function normalizeOrganizationAttributes(kind, value) {
|
|
88
|
+
const result = validateOrganizationAttributes(kind, value);
|
|
89
|
+
if (!result.ok)
|
|
90
|
+
return result;
|
|
91
|
+
return { ok: true, attributes: Object.freeze([...result.attributes].sort()) };
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/organization/index.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC9C,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM;IAC7D,UAAU,EAAE,UAAU,EAAE,cAAc,EAAE,SAAS;CACzC,CAAC,CAAC;AAMZ,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC;IAClC,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM;CACL,CAAC,CAAC;AAClD,MAAM,mBAAmB,GA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AwB,CAAC,GAAG,CAAE,CAAC;YAClD,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC;gBAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,uBAAuB,EAAE,KAAK,EAAE,CAAC;YACxG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACd,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;QACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;IAC7D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC;IAC7C,CAAC;AACH,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,+BAA+B,CAAC,IAAa,EAAE,KAAc;IAC3E,MAAM,MAAM,GAAG,8BAA8B,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC3D,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,OAAO,MAAM,CAAC;IAC9B,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;AAChF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pegasimed.com/pegasi-sail-connect-shared",
|
|
3
|
-
"version": "0.2.0-dev.
|
|
3
|
+
"version": "0.2.0-dev.20",
|
|
4
4
|
"description": "Versioned shared TypeScript helpers for PEGASI SAIL/CONNECT services.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -57,6 +57,14 @@
|
|
|
57
57
|
"./authorization": {
|
|
58
58
|
"types": "./dist/authorization/index.d.ts",
|
|
59
59
|
"import": "./dist/authorization/index.js"
|
|
60
|
+
},
|
|
61
|
+
"./authorization/testing": {
|
|
62
|
+
"types": "./dist/authorization-testing.d.ts",
|
|
63
|
+
"import": "./dist/authorization-testing.js"
|
|
64
|
+
},
|
|
65
|
+
"./organization": {
|
|
66
|
+
"types": "./dist/organization/index.d.ts",
|
|
67
|
+
"import": "./dist/organization/index.js"
|
|
60
68
|
}
|
|
61
69
|
},
|
|
62
70
|
"files": [
|
|
@@ -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) {
|