@mostajs/rbac 2.3.5 → 2.4.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/dist/repositories/account.repository.d.ts +14 -0
- package/dist/repositories/account.repository.d.ts.map +1 -1
- package/dist/repositories/account.repository.js +19 -0
- package/dist/repositories/account.repository.js.map +1 -1
- package/dist/schemas/account.schema.d.ts.map +1 -1
- package/dist/schemas/account.schema.js +22 -2
- package/dist/schemas/account.schema.js.map +1 -1
- package/package.json +1 -1
|
@@ -7,5 +7,19 @@ export declare class AccountRepository extends BaseRepository<AccountDTO> {
|
|
|
7
7
|
findByOwner(userId: string): Promise<AccountDTO | null>;
|
|
8
8
|
/** Find the unique system account by type — useful for the 'trial' shared playground */
|
|
9
9
|
findByType(type: string): Promise<AccountDTO | null>;
|
|
10
|
+
/** Find direct children of a parent account (1 level). */
|
|
11
|
+
findChildren(parentId: string): Promise<AccountDTO[]>;
|
|
12
|
+
/**
|
|
13
|
+
* Expand a parent account ID into the set of "tenant accounts" :
|
|
14
|
+
* the parent itself + all its direct children. Used by the row-level
|
|
15
|
+
* scoping middleware (mosta-net) to filter account-scoped entities.
|
|
16
|
+
*
|
|
17
|
+
* Returns an array of account IDs.
|
|
18
|
+
*
|
|
19
|
+
* Note : 1 niveau seulement pour l'instant. Si on adopte une vraie
|
|
20
|
+
* récursivité (forêt profonde), implémenter un CTE récursif (postgres
|
|
21
|
+
* `WITH RECURSIVE`) ou itérer ici.
|
|
22
|
+
*/
|
|
23
|
+
expandTenant(parentId: string): Promise<string[]>;
|
|
10
24
|
}
|
|
11
25
|
//# sourceMappingURL=account.repository.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account.repository.d.ts","sourceRoot":"","sources":["../../repositories/account.repository.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAE7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAEhD,qBAAa,iBAAkB,SAAQ,cAAc,CAAC,UAAU,CAAC;gBACnD,OAAO,EAAE,QAAQ;IAI7B,6DAA6D;IACvD,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAI7D,wFAAwF;IAClF,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"account.repository.d.ts","sourceRoot":"","sources":["../../repositories/account.repository.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAE7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAEhD,qBAAa,iBAAkB,SAAQ,cAAc,CAAC,UAAU,CAAC;gBACnD,OAAO,EAAE,QAAQ;IAI7B,6DAA6D;IACvD,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAI7D,wFAAwF;IAClF,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAI1D,0DAA0D;IACpD,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAI3D;;;;;;;;;;OAUG;IACG,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAIxD"}
|
|
@@ -14,5 +14,24 @@ export class AccountRepository extends BaseRepository {
|
|
|
14
14
|
async findByType(type) {
|
|
15
15
|
return this.findOne({ type });
|
|
16
16
|
}
|
|
17
|
+
/** Find direct children of a parent account (1 level). */
|
|
18
|
+
async findChildren(parentId) {
|
|
19
|
+
return this.findAll({ parent: parentId });
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Expand a parent account ID into the set of "tenant accounts" :
|
|
23
|
+
* the parent itself + all its direct children. Used by the row-level
|
|
24
|
+
* scoping middleware (mosta-net) to filter account-scoped entities.
|
|
25
|
+
*
|
|
26
|
+
* Returns an array of account IDs.
|
|
27
|
+
*
|
|
28
|
+
* Note : 1 niveau seulement pour l'instant. Si on adopte une vraie
|
|
29
|
+
* récursivité (forêt profonde), implémenter un CTE récursif (postgres
|
|
30
|
+
* `WITH RECURSIVE`) ou itérer ici.
|
|
31
|
+
*/
|
|
32
|
+
async expandTenant(parentId) {
|
|
33
|
+
const children = await this.findChildren(parentId);
|
|
34
|
+
return [parentId, ...children.map((c) => c.id)];
|
|
35
|
+
}
|
|
17
36
|
}
|
|
18
37
|
//# sourceMappingURL=account.repository.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account.repository.js","sourceRoot":"","sources":["../../repositories/account.repository.ts"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,wCAAwC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAIzD,MAAM,OAAO,iBAAkB,SAAQ,cAA0B;IAC/D,YAAY,OAAiB;QAC3B,KAAK,CAAC,aAAa,EAAE,OAAO,CAAC,CAAA;IAC/B,CAAC;IAED,6DAA6D;IAC7D,KAAK,CAAC,WAAW,CAAC,MAAc;QAC9B,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAA;IACxC,CAAC;IAED,wFAAwF;IACxF,KAAK,CAAC,UAAU,CAAC,IAAY;QAC3B,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,CAAA;IAC/B,CAAC;CACF"}
|
|
1
|
+
{"version":3,"file":"account.repository.js","sourceRoot":"","sources":["../../repositories/account.repository.ts"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,wCAAwC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAIzD,MAAM,OAAO,iBAAkB,SAAQ,cAA0B;IAC/D,YAAY,OAAiB;QAC3B,KAAK,CAAC,aAAa,EAAE,OAAO,CAAC,CAAA;IAC/B,CAAC;IAED,6DAA6D;IAC7D,KAAK,CAAC,WAAW,CAAC,MAAc;QAC9B,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAA;IACxC,CAAC;IAED,wFAAwF;IACxF,KAAK,CAAC,UAAU,CAAC,IAAY;QAC3B,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,CAAA;IAC/B,CAAC;IAED,0DAA0D;IAC1D,KAAK,CAAC,YAAY,CAAC,QAAgB;QACjC,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAS,CAAC,CAAA;IAClD,CAAC;IAED;;;;;;;;;;OAUG;IACH,KAAK,CAAC,YAAY,CAAC,QAAgB;QACjC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAA;QAClD,OAAO,CAAC,QAAQ,EAAE,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IACtD,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account.schema.d.ts","sourceRoot":"","sources":["../../schemas/account.schema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"account.schema.d.ts","sourceRoot":"","sources":["../../schemas/account.schema.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAEhD,eAAO,MAAM,aAAa,EAAE,YAyB3B,CAAA"}
|
|
@@ -1,7 +1,25 @@
|
|
|
1
1
|
// @mostajs/rbac — Account Entity Schema
|
|
2
|
-
//
|
|
2
|
+
//
|
|
3
|
+
// Multi-tenant container référencé comme target:'Account' par ApiKey, Project,
|
|
3
4
|
// Subscription, Invoice, UsageLog (across mosta-api-keys, mosta-project-life,
|
|
4
5
|
// mosta-subscriptions-plan).
|
|
6
|
+
//
|
|
7
|
+
// Hiérarchie (depuis 2.4.0, modèle β multi-tenant) :
|
|
8
|
+
// - `parent` (nullable many-to-one Account → Account) permet de modéliser
|
|
9
|
+
// une forêt de comptes : un Account 'portal' (octocloud-amia) en racine,
|
|
10
|
+
// les Accounts 'personal' des users qui s'inscrivent ont parent=portal.
|
|
11
|
+
// - Les modules consomateurs (mosta-net Octonet) utilisent ce parent comme
|
|
12
|
+
// frontière de cloisonnement : une apikey rattachée à un portal Account
|
|
13
|
+
// voit uniquement les données dont l'`account` ∈ {portal} ∪ {children
|
|
14
|
+
// de portal}.
|
|
15
|
+
//
|
|
16
|
+
// Types existants :
|
|
17
|
+
// - personal : compte personnel d'un user
|
|
18
|
+
// - organization : équipe/société (futur)
|
|
19
|
+
// - trial : sandbox transient (T1 /try)
|
|
20
|
+
// - system : compte système (public-demo, services internes)
|
|
21
|
+
// - portal : tenant racine d'un octocloud (ajouté en 2.4.0)
|
|
22
|
+
//
|
|
5
23
|
// Author: Dr Hamid MADANI drmdh@msn.com
|
|
6
24
|
export const AccountSchema = {
|
|
7
25
|
name: 'Account',
|
|
@@ -9,7 +27,7 @@ export const AccountSchema = {
|
|
|
9
27
|
timestamps: true,
|
|
10
28
|
fields: {
|
|
11
29
|
name: { type: 'string', required: true, trim: true },
|
|
12
|
-
type: { type: 'string', enum: ['personal', 'organization', 'trial', 'system'], default: 'personal' },
|
|
30
|
+
type: { type: 'string', enum: ['personal', 'organization', 'trial', 'system', 'portal'], default: 'personal' },
|
|
13
31
|
plan: { type: 'string', default: 'free' },
|
|
14
32
|
status: { type: 'string', enum: ['active', 'suspended', 'deleted'], default: 'active' },
|
|
15
33
|
stripeCustomerId: { type: 'string' },
|
|
@@ -17,11 +35,13 @@ export const AccountSchema = {
|
|
|
17
35
|
},
|
|
18
36
|
relations: {
|
|
19
37
|
owner: { type: 'many-to-one', target: 'User', required: true },
|
|
38
|
+
parent: { type: 'many-to-one', target: 'Account', required: false },
|
|
20
39
|
members: { type: 'many-to-many', target: 'User', through: 'account_members' },
|
|
21
40
|
},
|
|
22
41
|
indexes: [
|
|
23
42
|
{ fields: { type: 'asc' } },
|
|
24
43
|
{ fields: { status: 'asc' } },
|
|
44
|
+
{ fields: { parent: 'asc' } },
|
|
25
45
|
],
|
|
26
46
|
};
|
|
27
47
|
//# sourceMappingURL=account.schema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account.schema.js","sourceRoot":"","sources":["../../schemas/account.schema.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,
|
|
1
|
+
{"version":3,"file":"account.schema.js","sourceRoot":"","sources":["../../schemas/account.schema.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,EAAE;AACF,+EAA+E;AAC/E,8EAA8E;AAC9E,6BAA6B;AAC7B,EAAE;AACF,qDAAqD;AACrD,4EAA4E;AAC5E,6EAA6E;AAC7E,4EAA4E;AAC5E,6EAA6E;AAC7E,4EAA4E;AAC5E,0EAA0E;AAC1E,kBAAkB;AAClB,EAAE;AACF,oBAAoB;AACpB,gDAAgD;AAChD,4CAA4C;AAC5C,iDAAiD;AACjD,qEAAqE;AACrE,oEAAoE;AACpE,EAAE;AACF,wCAAwC;AAIxC,MAAM,CAAC,MAAM,aAAa,GAAiB;IACzC,IAAI,EAAE,SAAS;IACf,UAAU,EAAE,UAAU;IACtB,UAAU,EAAE,IAAI;IAEhB,MAAM,EAAE;QACN,IAAI,EAAc,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,IA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