@fiado/type-kit 3.65.0 → 3.66.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/_test_/unit/platformRbac/tenantTypes.test.ts +32 -0
- package/bin/platformRbac/index.d.ts +1 -0
- package/bin/platformRbac/index.js +10 -1
- package/bin/platformRbac/tenantTypes.d.ts +25 -0
- package/bin/platformRbac/tenantTypes.js +45 -0
- package/package.json +1 -1
- package/src/platformRbac/index.ts +5 -0
- package/src/platformRbac/tenantTypes.ts +49 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { TenantType, levelsOf, tableSuffixForLevel, scopeRankOrder } from '../../../src/platformRbac/tenantTypes';
|
|
2
|
+
import { PermissionScope } from '../../../src/platformRbac/enums/PermissionScope';
|
|
3
|
+
|
|
4
|
+
describe('tenantTypes', () => {
|
|
5
|
+
it('retail define RETAILER>STORE', () => {
|
|
6
|
+
expect(levelsOf(TenantType.RETAIL)).toEqual([PermissionScope.RETAILER, PermissionScope.STORE]);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it('scopeRankOrder = [PLATFORM, TENANT, RETAILER, STORE] (retail único tipo hoy)', () => {
|
|
10
|
+
expect(scopeRankOrder()).toEqual([
|
|
11
|
+
PermissionScope.PLATFORM,
|
|
12
|
+
PermissionScope.TENANT,
|
|
13
|
+
PermissionScope.RETAILER,
|
|
14
|
+
PermissionScope.STORE,
|
|
15
|
+
]);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('tableSuffixForLevel mapea cada nivel de retail a su sufijo de tabla', () => {
|
|
19
|
+
expect(tableSuffixForLevel(TenantType.RETAIL, PermissionScope.RETAILER)).toBe('SharedRetailer');
|
|
20
|
+
expect(tableSuffixForLevel(TenantType.RETAIL, PermissionScope.STORE)).toBe('SharedStore');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('tableSuffixForLevel devuelve undefined para un nivel no mapeado (PLATFORM/TENANT son fijos)', () => {
|
|
24
|
+
expect(tableSuffixForLevel(TenantType.RETAIL, PermissionScope.PLATFORM)).toBeUndefined();
|
|
25
|
+
expect(tableSuffixForLevel(TenantType.RETAIL, PermissionScope.TENANT)).toBeUndefined();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('scopeRankOrder no produce duplicados', () => {
|
|
29
|
+
const order = scopeRankOrder();
|
|
30
|
+
expect(new Set(order).size).toBe(order.length);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -23,3 +23,4 @@ export * from './dtos/AuthorizeRequest';
|
|
|
23
23
|
export * from './dtos/AuthorizeResponse';
|
|
24
24
|
export * from './dtos/CreateTenantRequest';
|
|
25
25
|
export type { CreateTenantResponse } from './dtos/CreateTenantResponse';
|
|
26
|
+
export { TenantType, TENANT_TYPES, levelsOf, tableSuffixForLevel, scopeRankOrder } from './tenantTypes';
|
|
@@ -23,7 +23,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
23
23
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.AuthorizeDenyReason = exports.PermissionCategory = exports.PermissionScope = exports.Permission = void 0;
|
|
26
|
+
exports.scopeRankOrder = exports.tableSuffixForLevel = exports.levelsOf = exports.TENANT_TYPES = exports.TenantType = exports.AuthorizeDenyReason = exports.PermissionCategory = exports.PermissionScope = exports.Permission = void 0;
|
|
27
27
|
var Permission_1 = require("./enums/Permission");
|
|
28
28
|
Object.defineProperty(exports, "Permission", { enumerable: true, get: function () { return Permission_1.Permission; } });
|
|
29
29
|
var PermissionScope_1 = require("./enums/PermissionScope");
|
|
@@ -54,3 +54,12 @@ __exportStar(require("./dtos/AuthorizeResponse"), exports);
|
|
|
54
54
|
// F-11 — onboarding de tenant (POST backoffice createTenant). CreateTenantRequest lleva
|
|
55
55
|
// decoradores class-validator → export de valor; CreateTenantResponse es interface → type-only.
|
|
56
56
|
__exportStar(require("./dtos/CreateTenantRequest"), exports);
|
|
57
|
+
// A1 — registro data-driven de tenant-types (niveles debajo de TENANT, por tipo).
|
|
58
|
+
// Consumido por ScopeValidationService._rank vía scopeRankOrder() y por los seeds.
|
|
59
|
+
// Accesible bajo el namespace PlatformRbac (el index raíz hace export * as PlatformRbac).
|
|
60
|
+
var tenantTypes_1 = require("./tenantTypes");
|
|
61
|
+
Object.defineProperty(exports, "TenantType", { enumerable: true, get: function () { return tenantTypes_1.TenantType; } });
|
|
62
|
+
Object.defineProperty(exports, "TENANT_TYPES", { enumerable: true, get: function () { return tenantTypes_1.TENANT_TYPES; } });
|
|
63
|
+
Object.defineProperty(exports, "levelsOf", { enumerable: true, get: function () { return tenantTypes_1.levelsOf; } });
|
|
64
|
+
Object.defineProperty(exports, "tableSuffixForLevel", { enumerable: true, get: function () { return tenantTypes_1.tableSuffixForLevel; } });
|
|
65
|
+
Object.defineProperty(exports, "scopeRankOrder", { enumerable: true, get: function () { return tenantTypes_1.scopeRankOrder; } });
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { PermissionScope } from './enums/PermissionScope';
|
|
2
|
+
/**
|
|
3
|
+
* Tipos de tenant soportados por el rbac-business. Cada tipo define su propia
|
|
4
|
+
* jerarquía de niveles DEBAJO de TENANT (data-driven). Hoy solo existe `retail`.
|
|
5
|
+
*/
|
|
6
|
+
export declare enum TenantType {
|
|
7
|
+
RETAIL = "retail"
|
|
8
|
+
}
|
|
9
|
+
interface TenantTypeDef {
|
|
10
|
+
displayName: string;
|
|
11
|
+
/** Niveles DEBAJO de TENANT, en orden jerárquico (más alto → más bajo). */
|
|
12
|
+
levels: PermissionScope[];
|
|
13
|
+
/** Sufijo de tabla DDB por nivel (el prefix del tenant se antepone en runtime). */
|
|
14
|
+
tableSuffix: Partial<Record<PermissionScope, string>>;
|
|
15
|
+
}
|
|
16
|
+
export declare const TENANT_TYPES: Record<TenantType, TenantTypeDef>;
|
|
17
|
+
export declare function levelsOf(type: TenantType): PermissionScope[];
|
|
18
|
+
export declare function tableSuffixForLevel(type: TenantType, level: PermissionScope): string | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Orden global de rank de scopes: PLATFORM, TENANT (fijos) + los niveles de cada tipo en orden.
|
|
21
|
+
* Las comparaciones de rank nunca cruzan tipos (un actor pertenece a un solo tenant de un solo tipo),
|
|
22
|
+
* así que un orden global concatenado es seguro. Sin duplicados.
|
|
23
|
+
*/
|
|
24
|
+
export declare function scopeRankOrder(): PermissionScope[];
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TENANT_TYPES = exports.TenantType = void 0;
|
|
4
|
+
exports.levelsOf = levelsOf;
|
|
5
|
+
exports.tableSuffixForLevel = tableSuffixForLevel;
|
|
6
|
+
exports.scopeRankOrder = scopeRankOrder;
|
|
7
|
+
const PermissionScope_1 = require("./enums/PermissionScope");
|
|
8
|
+
/**
|
|
9
|
+
* Tipos de tenant soportados por el rbac-business. Cada tipo define su propia
|
|
10
|
+
* jerarquía de niveles DEBAJO de TENANT (data-driven). Hoy solo existe `retail`.
|
|
11
|
+
*/
|
|
12
|
+
var TenantType;
|
|
13
|
+
(function (TenantType) {
|
|
14
|
+
TenantType["RETAIL"] = "retail";
|
|
15
|
+
})(TenantType || (exports.TenantType = TenantType = {}));
|
|
16
|
+
exports.TENANT_TYPES = {
|
|
17
|
+
[TenantType.RETAIL]: {
|
|
18
|
+
displayName: 'Retail',
|
|
19
|
+
levels: [PermissionScope_1.PermissionScope.RETAILER, PermissionScope_1.PermissionScope.STORE],
|
|
20
|
+
tableSuffix: {
|
|
21
|
+
[PermissionScope_1.PermissionScope.RETAILER]: 'SharedRetailer',
|
|
22
|
+
[PermissionScope_1.PermissionScope.STORE]: 'SharedStore',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
function levelsOf(type) {
|
|
27
|
+
return exports.TENANT_TYPES[type].levels;
|
|
28
|
+
}
|
|
29
|
+
function tableSuffixForLevel(type, level) {
|
|
30
|
+
return exports.TENANT_TYPES[type].tableSuffix[level];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Orden global de rank de scopes: PLATFORM, TENANT (fijos) + los niveles de cada tipo en orden.
|
|
34
|
+
* Las comparaciones de rank nunca cruzan tipos (un actor pertenece a un solo tenant de un solo tipo),
|
|
35
|
+
* así que un orden global concatenado es seguro. Sin duplicados.
|
|
36
|
+
*/
|
|
37
|
+
function scopeRankOrder() {
|
|
38
|
+
const order = [PermissionScope_1.PermissionScope.PLATFORM, PermissionScope_1.PermissionScope.TENANT];
|
|
39
|
+
for (const def of Object.values(exports.TENANT_TYPES)) {
|
|
40
|
+
for (const lvl of def.levels)
|
|
41
|
+
if (!order.includes(lvl))
|
|
42
|
+
order.push(lvl);
|
|
43
|
+
}
|
|
44
|
+
return order;
|
|
45
|
+
}
|
package/package.json
CHANGED
|
@@ -42,3 +42,8 @@ export * from './dtos/AuthorizeResponse';
|
|
|
42
42
|
// decoradores class-validator → export de valor; CreateTenantResponse es interface → type-only.
|
|
43
43
|
export * from './dtos/CreateTenantRequest';
|
|
44
44
|
export type { CreateTenantResponse } from './dtos/CreateTenantResponse';
|
|
45
|
+
|
|
46
|
+
// A1 — registro data-driven de tenant-types (niveles debajo de TENANT, por tipo).
|
|
47
|
+
// Consumido por ScopeValidationService._rank vía scopeRankOrder() y por los seeds.
|
|
48
|
+
// Accesible bajo el namespace PlatformRbac (el index raíz hace export * as PlatformRbac).
|
|
49
|
+
export { TenantType, TENANT_TYPES, levelsOf, tableSuffixForLevel, scopeRankOrder } from './tenantTypes';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { PermissionScope } from './enums/PermissionScope';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Tipos de tenant soportados por el rbac-business. Cada tipo define su propia
|
|
5
|
+
* jerarquía de niveles DEBAJO de TENANT (data-driven). Hoy solo existe `retail`.
|
|
6
|
+
*/
|
|
7
|
+
export enum TenantType {
|
|
8
|
+
RETAIL = 'retail',
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface TenantTypeDef {
|
|
12
|
+
displayName: string;
|
|
13
|
+
/** Niveles DEBAJO de TENANT, en orden jerárquico (más alto → más bajo). */
|
|
14
|
+
levels: PermissionScope[];
|
|
15
|
+
/** Sufijo de tabla DDB por nivel (el prefix del tenant se antepone en runtime). */
|
|
16
|
+
tableSuffix: Partial<Record<PermissionScope, string>>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const TENANT_TYPES: Record<TenantType, TenantTypeDef> = {
|
|
20
|
+
[TenantType.RETAIL]: {
|
|
21
|
+
displayName: 'Retail',
|
|
22
|
+
levels: [PermissionScope.RETAILER, PermissionScope.STORE],
|
|
23
|
+
tableSuffix: {
|
|
24
|
+
[PermissionScope.RETAILER]: 'SharedRetailer',
|
|
25
|
+
[PermissionScope.STORE]: 'SharedStore',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export function levelsOf(type: TenantType): PermissionScope[] {
|
|
31
|
+
return TENANT_TYPES[type].levels;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function tableSuffixForLevel(type: TenantType, level: PermissionScope): string | undefined {
|
|
35
|
+
return TENANT_TYPES[type].tableSuffix[level];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Orden global de rank de scopes: PLATFORM, TENANT (fijos) + los niveles de cada tipo en orden.
|
|
40
|
+
* Las comparaciones de rank nunca cruzan tipos (un actor pertenece a un solo tenant de un solo tipo),
|
|
41
|
+
* así que un orden global concatenado es seguro. Sin duplicados.
|
|
42
|
+
*/
|
|
43
|
+
export function scopeRankOrder(): PermissionScope[] {
|
|
44
|
+
const order: PermissionScope[] = [PermissionScope.PLATFORM, PermissionScope.TENANT];
|
|
45
|
+
for (const def of Object.values(TENANT_TYPES)) {
|
|
46
|
+
for (const lvl of def.levels) if (!order.includes(lvl)) order.push(lvl);
|
|
47
|
+
}
|
|
48
|
+
return order;
|
|
49
|
+
}
|