@open-core/identity 1.2.3 → 1.2.5
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/contracts.d.ts +23 -12
- package/dist/providers/auth/credentials-auth.provider.js +10 -8
- package/dist/providers/auth/local-auth.provider.js +7 -6
- package/dist/providers/principal/local-principal.provider.js +20 -12
- package/dist/services/account.service.d.ts +23 -6
- package/dist/services/account.service.js +26 -13
- package/dist/services/role.service.d.ts +13 -18
- package/dist/services/role.service.js +15 -33
- package/dist/types.d.ts +8 -14
- package/package.json +2 -1
package/dist/contracts.d.ts
CHANGED
|
@@ -33,10 +33,11 @@ export declare abstract class IdentityStore {
|
|
|
33
33
|
/**
|
|
34
34
|
* Persists a new identity account.
|
|
35
35
|
*
|
|
36
|
-
* @param data - Initial account properties.
|
|
36
|
+
* @param data - Initial account properties (ID is optional as it's usually handled by the store).
|
|
37
37
|
* @returns A promise resolving to the fully created account object.
|
|
38
38
|
*/
|
|
39
|
-
abstract create(data:
|
|
39
|
+
abstract create(data: Omit<IdentityAccount, "id"> & {
|
|
40
|
+
id?: string | number;
|
|
40
41
|
passwordHash?: string;
|
|
41
42
|
}): Promise<IdentityAccount>;
|
|
42
43
|
/**
|
|
@@ -45,7 +46,7 @@ export declare abstract class IdentityStore {
|
|
|
45
46
|
* @param id - The internal account ID.
|
|
46
47
|
* @param data - Partial object containing fields to update.
|
|
47
48
|
*/
|
|
48
|
-
abstract update(id: string, data: Partial<IdentityAccount
|
|
49
|
+
abstract update(id: string | number, data: Partial<Omit<IdentityAccount, "id">>): Promise<void>;
|
|
49
50
|
/**
|
|
50
51
|
* Prohibits or allows an account from connecting.
|
|
51
52
|
*
|
|
@@ -54,7 +55,7 @@ export declare abstract class IdentityStore {
|
|
|
54
55
|
* @param reason - Optional explanation for the ban.
|
|
55
56
|
* @param expiresAt - Optional expiration timestamp.
|
|
56
57
|
*/
|
|
57
|
-
abstract setBan(id: string, banned: boolean, reason?: string, expiresAt?: Date | null): Promise<void>;
|
|
58
|
+
abstract setBan(id: string | number, banned: boolean, reason?: string, expiresAt?: Date | null): Promise<void>;
|
|
58
59
|
}
|
|
59
60
|
/**
|
|
60
61
|
* Persistence contract for security roles.
|
|
@@ -66,12 +67,12 @@ export declare abstract class IdentityStore {
|
|
|
66
67
|
*/
|
|
67
68
|
export declare abstract class RoleStore {
|
|
68
69
|
/**
|
|
69
|
-
* Retrieves a role definition by its technical
|
|
70
|
+
* Retrieves a role definition by its technical identifier.
|
|
70
71
|
*
|
|
71
|
-
* @param
|
|
72
|
+
* @param id - Technical identifier (e.g., 'admin' or 1).
|
|
72
73
|
* @returns A promise resolving to the role or null if not found.
|
|
73
74
|
*/
|
|
74
|
-
abstract
|
|
75
|
+
abstract findById(id: string | number): Promise<IdentityRole | null>;
|
|
75
76
|
/**
|
|
76
77
|
* Resolves the default role for newly connected accounts.
|
|
77
78
|
*
|
|
@@ -79,15 +80,25 @@ export declare abstract class RoleStore {
|
|
|
79
80
|
*/
|
|
80
81
|
abstract getDefaultRole(): Promise<IdentityRole>;
|
|
81
82
|
/**
|
|
82
|
-
*
|
|
83
|
+
* Persists a new security role definition.
|
|
83
84
|
*
|
|
84
|
-
* @param role -
|
|
85
|
+
* @param role - Initial role properties. ID can be provided or left to the store.
|
|
86
|
+
* @returns A promise resolving to the fully created role object.
|
|
85
87
|
*/
|
|
86
|
-
abstract
|
|
88
|
+
abstract create(role: Omit<IdentityRole, "id"> & {
|
|
89
|
+
id?: string | number;
|
|
90
|
+
}): Promise<IdentityRole>;
|
|
91
|
+
/**
|
|
92
|
+
* Updates an existing role definition.
|
|
93
|
+
*
|
|
94
|
+
* @param id - Technical identifier of the role to update.
|
|
95
|
+
* @param role - Partial role object containing the fields to modify.
|
|
96
|
+
*/
|
|
97
|
+
abstract update(id: string | number, role: Partial<Omit<IdentityRole, "id">>): Promise<void>;
|
|
87
98
|
/**
|
|
88
99
|
* Removes a role from the system.
|
|
89
100
|
*
|
|
90
|
-
* @param
|
|
101
|
+
* @param id - Technical identifier of the role to delete.
|
|
91
102
|
*/
|
|
92
|
-
abstract delete(
|
|
103
|
+
abstract delete(id: string | number): Promise<void>;
|
|
93
104
|
}
|
|
@@ -12,7 +12,6 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
12
12
|
};
|
|
13
13
|
import { injectable, inject } from "tsyringe";
|
|
14
14
|
import { Server } from "@open-core/framework";
|
|
15
|
-
import { v4 as uuidv4 } from "uuid";
|
|
16
15
|
import { IDENTITY_OPTIONS } from "../../tokens";
|
|
17
16
|
import { IdentityStore } from "../../contracts";
|
|
18
17
|
import bcrypt from "bcryptjs";
|
|
@@ -68,8 +67,9 @@ let CredentialsAuthProvider = class CredentialsAuthProvider extends Server.AuthP
|
|
|
68
67
|
if (this.isBanned(account)) {
|
|
69
68
|
return { success: false, error: account.banReason ?? "Account is banned" };
|
|
70
69
|
}
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
const accountIdStr = String(account.id);
|
|
71
|
+
player.linkAccount(accountIdStr);
|
|
72
|
+
return { success: true, accountID: accountIdStr };
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
75
75
|
* Registers a new account with a username and password.
|
|
@@ -95,11 +95,13 @@ let CredentialsAuthProvider = class CredentialsAuthProvider extends Server.AuthP
|
|
|
95
95
|
username,
|
|
96
96
|
passwordHash,
|
|
97
97
|
identifier: primaryIdentifier,
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
roleId: this.options.principal.defaultRole || "user",
|
|
99
|
+
customPermissions: [],
|
|
100
|
+
isBanned: false,
|
|
100
101
|
});
|
|
101
|
-
|
|
102
|
-
|
|
102
|
+
const accountIdStr = String(account.id);
|
|
103
|
+
player.linkAccount(accountIdStr);
|
|
104
|
+
return { success: true, accountID: accountIdStr, isNewAccount: true };
|
|
103
105
|
}
|
|
104
106
|
/**
|
|
105
107
|
* Validates if the player's current linked account session is still active.
|
|
@@ -115,7 +117,7 @@ let CredentialsAuthProvider = class CredentialsAuthProvider extends Server.AuthP
|
|
|
115
117
|
if (!account || this.isBanned(account)) {
|
|
116
118
|
return { success: false, error: "Session invalid or account banned" };
|
|
117
119
|
}
|
|
118
|
-
return { success: true, accountID: account.
|
|
120
|
+
return { success: true, accountID: String(account.id) };
|
|
119
121
|
}
|
|
120
122
|
/**
|
|
121
123
|
* Performs logout logic for the player.
|
|
@@ -12,7 +12,6 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
12
12
|
};
|
|
13
13
|
import { injectable, inject } from "tsyringe";
|
|
14
14
|
import { Server } from "@open-core/framework";
|
|
15
|
-
import { v4 as uuidv4 } from "uuid";
|
|
16
15
|
import { IDENTITY_OPTIONS } from "../../tokens";
|
|
17
16
|
import { IdentityStore } from "../../contracts";
|
|
18
17
|
/**
|
|
@@ -85,7 +84,7 @@ let LocalAuthProvider = class LocalAuthProvider extends Server.AuthProviderContr
|
|
|
85
84
|
if (account.isBanned && (!account.banExpiresAt || account.banExpiresAt > new Date())) {
|
|
86
85
|
return { success: false, error: account.banReason ?? "Account is banned" };
|
|
87
86
|
}
|
|
88
|
-
return { success: true, accountID: account.
|
|
87
|
+
return { success: true, accountID: String(account.id) };
|
|
89
88
|
}
|
|
90
89
|
/**
|
|
91
90
|
* Clears the authentication state for a player.
|
|
@@ -115,8 +114,9 @@ let LocalAuthProvider = class LocalAuthProvider extends Server.AuthProviderContr
|
|
|
115
114
|
}
|
|
116
115
|
account = await this.store.create({
|
|
117
116
|
identifier: identifierValue,
|
|
118
|
-
|
|
119
|
-
|
|
117
|
+
roleId: "user",
|
|
118
|
+
customPermissions: [],
|
|
119
|
+
isBanned: false,
|
|
120
120
|
});
|
|
121
121
|
isNew = true;
|
|
122
122
|
}
|
|
@@ -131,8 +131,9 @@ let LocalAuthProvider = class LocalAuthProvider extends Server.AuthProviderContr
|
|
|
131
131
|
};
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
const accountIdStr = String(account.id);
|
|
135
|
+
player.linkAccount(accountIdStr);
|
|
136
|
+
return { success: true, accountID: accountIdStr, isNewAccount: isNew };
|
|
136
137
|
}
|
|
137
138
|
/**
|
|
138
139
|
* Internal implementation for API-based authentication strategy.
|
|
@@ -102,29 +102,37 @@ let IdentityPrincipalProvider = class IdentityPrincipalProvider extends Server.P
|
|
|
102
102
|
if (!account)
|
|
103
103
|
return null;
|
|
104
104
|
let role;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (
|
|
111
|
-
|
|
105
|
+
const roleId = account.roleId;
|
|
106
|
+
if (roleId !== undefined && roleId !== null && roleId !== "") {
|
|
107
|
+
if (this.options.principal.mode === "roles") {
|
|
108
|
+
role = this.options.principal.roles?.[roleId];
|
|
109
|
+
}
|
|
110
|
+
else if (this.roleStore) {
|
|
111
|
+
const dbRole = await this.roleStore.findById(roleId);
|
|
112
|
+
if (dbRole)
|
|
113
|
+
role = dbRole;
|
|
114
|
+
}
|
|
112
115
|
}
|
|
113
116
|
if (!role) {
|
|
114
|
-
const
|
|
115
|
-
|
|
117
|
+
const defaultRoleId = this.options.principal.defaultRole;
|
|
118
|
+
if (defaultRoleId !== undefined && defaultRoleId !== null && defaultRoleId !== "") {
|
|
119
|
+
role = this.options.principal.roles?.[defaultRoleId];
|
|
120
|
+
if (!role && this.roleStore && this.options.principal.mode === "db") {
|
|
121
|
+
role = await this.roleStore.getDefaultRole();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
116
124
|
}
|
|
117
125
|
if (!role)
|
|
118
126
|
return null;
|
|
119
127
|
const effectivePermissions = this.mergePermissions(role.permissions, account.customPermissions);
|
|
120
128
|
return {
|
|
121
|
-
id:
|
|
122
|
-
name: role.displayName || role.
|
|
129
|
+
id: linkedId,
|
|
130
|
+
name: role.displayName || String(role.id),
|
|
123
131
|
rank: role.rank,
|
|
124
132
|
permissions: effectivePermissions,
|
|
125
133
|
meta: {
|
|
126
134
|
accountId: account.id,
|
|
127
|
-
|
|
135
|
+
roleId: role.id,
|
|
128
136
|
},
|
|
129
137
|
};
|
|
130
138
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IdentityStore } from "../contracts";
|
|
2
|
-
import type { IdentityAccount
|
|
2
|
+
import type { IdentityAccount } from "../types";
|
|
3
3
|
/**
|
|
4
4
|
* High-level service for managing identity accounts and security policies.
|
|
5
5
|
*
|
|
@@ -11,8 +11,7 @@ import type { IdentityAccount, IdentityOptions } from "../types";
|
|
|
11
11
|
*/
|
|
12
12
|
export declare class AccountService {
|
|
13
13
|
private readonly store;
|
|
14
|
-
|
|
15
|
-
constructor(store: IdentityStore, options: IdentityOptions);
|
|
14
|
+
constructor(store: IdentityStore);
|
|
16
15
|
/**
|
|
17
16
|
* Retrieves an account by its unique numeric or internal ID.
|
|
18
17
|
*
|
|
@@ -27,13 +26,31 @@ export declare class AccountService {
|
|
|
27
26
|
* @returns A promise resolving to the account or null if not found.
|
|
28
27
|
*/
|
|
29
28
|
findByLinkedId(linkedId: string): Promise<IdentityAccount | null>;
|
|
29
|
+
/**
|
|
30
|
+
* Persists a new identity account.
|
|
31
|
+
*
|
|
32
|
+
* @param data - Initial account properties. ID can be provided or left to the store.
|
|
33
|
+
* @returns A promise resolving to the fully created account object.
|
|
34
|
+
*/
|
|
35
|
+
create(data: Omit<IdentityAccount, "id"> & {
|
|
36
|
+
id?: string | number;
|
|
37
|
+
passwordHash?: string;
|
|
38
|
+
}): Promise<IdentityAccount>;
|
|
39
|
+
/**
|
|
40
|
+
* Updates an existing account's metadata or status.
|
|
41
|
+
*
|
|
42
|
+
* @param id - The internal account ID.
|
|
43
|
+
* @param data - Partial object containing fields to update.
|
|
44
|
+
* @returns A promise that resolves when the update is complete.
|
|
45
|
+
*/
|
|
46
|
+
update(id: string | number, data: Partial<Omit<IdentityAccount, "id">>): Promise<void>;
|
|
30
47
|
/**
|
|
31
48
|
* Assigns a security role to an account.
|
|
32
49
|
*
|
|
33
|
-
* @param accountId - The
|
|
34
|
-
* @param
|
|
50
|
+
* @param accountId - The unique ID of the account.
|
|
51
|
+
* @param roleId - Technical identifier of the role to assign.
|
|
35
52
|
*/
|
|
36
|
-
assignRole(accountId: string,
|
|
53
|
+
assignRole(accountId: string | number, roleId: string | number): Promise<void>;
|
|
37
54
|
/**
|
|
38
55
|
* Grants a custom permission override to an account.
|
|
39
56
|
*
|
|
@@ -7,11 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
|
|
11
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
-
};
|
|
13
|
-
import { injectable, inject } from "tsyringe";
|
|
14
|
-
import { IDENTITY_OPTIONS } from "../tokens";
|
|
10
|
+
import { injectable } from "tsyringe";
|
|
15
11
|
import { IdentityStore } from "../contracts";
|
|
16
12
|
/**
|
|
17
13
|
* High-level service for managing identity accounts and security policies.
|
|
@@ -23,9 +19,8 @@ import { IdentityStore } from "../contracts";
|
|
|
23
19
|
* @injectable
|
|
24
20
|
*/
|
|
25
21
|
let AccountService = class AccountService {
|
|
26
|
-
constructor(store
|
|
22
|
+
constructor(store) {
|
|
27
23
|
this.store = store;
|
|
28
|
-
this.options = options;
|
|
29
24
|
}
|
|
30
25
|
/**
|
|
31
26
|
* Retrieves an account by its unique numeric or internal ID.
|
|
@@ -45,14 +40,33 @@ let AccountService = class AccountService {
|
|
|
45
40
|
async findByLinkedId(linkedId) {
|
|
46
41
|
return this.store.findByLinkedId(linkedId);
|
|
47
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Persists a new identity account.
|
|
45
|
+
*
|
|
46
|
+
* @param data - Initial account properties. ID can be provided or left to the store.
|
|
47
|
+
* @returns A promise resolving to the fully created account object.
|
|
48
|
+
*/
|
|
49
|
+
async create(data) {
|
|
50
|
+
return this.store.create(data);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Updates an existing account's metadata or status.
|
|
54
|
+
*
|
|
55
|
+
* @param id - The internal account ID.
|
|
56
|
+
* @param data - Partial object containing fields to update.
|
|
57
|
+
* @returns A promise that resolves when the update is complete.
|
|
58
|
+
*/
|
|
59
|
+
async update(id, data) {
|
|
60
|
+
await this.store.update(id, data);
|
|
61
|
+
}
|
|
48
62
|
/**
|
|
49
63
|
* Assigns a security role to an account.
|
|
50
64
|
*
|
|
51
|
-
* @param accountId - The
|
|
52
|
-
* @param
|
|
65
|
+
* @param accountId - The unique ID of the account.
|
|
66
|
+
* @param roleId - Technical identifier of the role to assign.
|
|
53
67
|
*/
|
|
54
|
-
async assignRole(accountId,
|
|
55
|
-
await this.
|
|
68
|
+
async assignRole(accountId, roleId) {
|
|
69
|
+
await this.update(accountId, { roleId });
|
|
56
70
|
}
|
|
57
71
|
/**
|
|
58
72
|
* Grants a custom permission override to an account.
|
|
@@ -115,7 +129,6 @@ let AccountService = class AccountService {
|
|
|
115
129
|
};
|
|
116
130
|
AccountService = __decorate([
|
|
117
131
|
injectable(),
|
|
118
|
-
|
|
119
|
-
__metadata("design:paramtypes", [IdentityStore, Object])
|
|
132
|
+
__metadata("design:paramtypes", [IdentityStore])
|
|
120
133
|
], AccountService);
|
|
121
134
|
export { AccountService };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RoleStore } from "../contracts";
|
|
2
|
-
import type {
|
|
2
|
+
import type { IdentityRole } from "../types";
|
|
3
3
|
/**
|
|
4
4
|
* High-level service for managing security roles and their associated permissions.
|
|
5
5
|
*
|
|
@@ -12,41 +12,36 @@ import type { IdentityOptions, IdentityRole } from "../types";
|
|
|
12
12
|
*/
|
|
13
13
|
export declare class RoleService {
|
|
14
14
|
private readonly store;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Initializes a new instance of the RoleService.
|
|
18
|
-
*
|
|
19
|
-
* @param store - Persistence layer for role definitions.
|
|
20
|
-
* @param options - Identity system configuration options.
|
|
21
|
-
*/
|
|
22
|
-
constructor(store: RoleStore, options: IdentityOptions);
|
|
15
|
+
constructor(store: RoleStore);
|
|
23
16
|
/**
|
|
24
17
|
* Persists a new security role definition.
|
|
25
18
|
*
|
|
26
|
-
* @param role - The
|
|
27
|
-
* @returns A promise
|
|
19
|
+
* @param role - The initial role properties (ID is optional).
|
|
20
|
+
* @returns A promise resolving to the created role.
|
|
28
21
|
*/
|
|
29
|
-
create(role: IdentityRole
|
|
22
|
+
create(role: Omit<IdentityRole, "id"> & {
|
|
23
|
+
id?: string | number;
|
|
24
|
+
}): Promise<IdentityRole>;
|
|
30
25
|
/**
|
|
31
26
|
* Updates an existing role's rank or permissions.
|
|
32
27
|
*
|
|
33
|
-
* @param
|
|
28
|
+
* @param id - The unique technical identifier of the role to update.
|
|
34
29
|
* @param data - Partial object containing the fields to modify.
|
|
35
30
|
* @returns A promise that resolves when the update is complete.
|
|
36
31
|
*/
|
|
37
|
-
update(
|
|
32
|
+
update(id: string | number, data: Partial<Omit<IdentityRole, "id">>): Promise<void>;
|
|
38
33
|
/**
|
|
39
34
|
* Permanently removes a role definition from the system.
|
|
40
35
|
*
|
|
41
|
-
* @param
|
|
36
|
+
* @param id - The technical identifier of the role to delete.
|
|
42
37
|
* @returns A promise that resolves when the role is deleted.
|
|
43
38
|
*/
|
|
44
|
-
delete(
|
|
39
|
+
delete(id: string | number): Promise<void>;
|
|
45
40
|
/**
|
|
46
41
|
* Retrieves the full list of permissions granted to a specific role.
|
|
47
42
|
*
|
|
48
|
-
* @param
|
|
43
|
+
* @param id - The technical identifier of the role.
|
|
49
44
|
* @returns A promise resolving to an array of permission strings.
|
|
50
45
|
*/
|
|
51
|
-
getPermissions(
|
|
46
|
+
getPermissions(id: string | number): Promise<string[]>;
|
|
52
47
|
}
|
|
@@ -7,11 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
|
|
11
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
-
};
|
|
13
|
-
import { injectable, inject } from "tsyringe";
|
|
14
|
-
import { IDENTITY_OPTIONS } from "../tokens";
|
|
10
|
+
import { injectable } from "tsyringe";
|
|
15
11
|
import { RoleStore } from "../contracts";
|
|
16
12
|
/**
|
|
17
13
|
* High-level service for managing security roles and their associated permissions.
|
|
@@ -24,64 +20,50 @@ import { RoleStore } from "../contracts";
|
|
|
24
20
|
* @injectable
|
|
25
21
|
*/
|
|
26
22
|
let RoleService = class RoleService {
|
|
27
|
-
|
|
28
|
-
* Initializes a new instance of the RoleService.
|
|
29
|
-
*
|
|
30
|
-
* @param store - Persistence layer for role definitions.
|
|
31
|
-
* @param options - Identity system configuration options.
|
|
32
|
-
*/
|
|
33
|
-
constructor(store, options) {
|
|
23
|
+
constructor(store) {
|
|
34
24
|
this.store = store;
|
|
35
|
-
this.options = options;
|
|
36
25
|
}
|
|
37
26
|
/**
|
|
38
27
|
* Persists a new security role definition.
|
|
39
28
|
*
|
|
40
|
-
* @param role - The
|
|
41
|
-
* @returns A promise
|
|
29
|
+
* @param role - The initial role properties (ID is optional).
|
|
30
|
+
* @returns A promise resolving to the created role.
|
|
42
31
|
*/
|
|
43
32
|
async create(role) {
|
|
44
|
-
|
|
33
|
+
return this.store.create(role);
|
|
45
34
|
}
|
|
46
35
|
/**
|
|
47
36
|
* Updates an existing role's rank or permissions.
|
|
48
37
|
*
|
|
49
|
-
* @param
|
|
38
|
+
* @param id - The unique technical identifier of the role to update.
|
|
50
39
|
* @param data - Partial object containing the fields to modify.
|
|
51
40
|
* @returns A promise that resolves when the update is complete.
|
|
52
41
|
*/
|
|
53
|
-
async update(
|
|
54
|
-
|
|
55
|
-
if (!existing)
|
|
56
|
-
return;
|
|
57
|
-
await this.store.save({
|
|
58
|
-
...existing,
|
|
59
|
-
...data,
|
|
60
|
-
});
|
|
42
|
+
async update(id, data) {
|
|
43
|
+
await this.store.update(id, data);
|
|
61
44
|
}
|
|
62
45
|
/**
|
|
63
46
|
* Permanently removes a role definition from the system.
|
|
64
47
|
*
|
|
65
|
-
* @param
|
|
48
|
+
* @param id - The technical identifier of the role to delete.
|
|
66
49
|
* @returns A promise that resolves when the role is deleted.
|
|
67
50
|
*/
|
|
68
|
-
async delete(
|
|
69
|
-
await this.store.delete(
|
|
51
|
+
async delete(id) {
|
|
52
|
+
await this.store.delete(id);
|
|
70
53
|
}
|
|
71
54
|
/**
|
|
72
55
|
* Retrieves the full list of permissions granted to a specific role.
|
|
73
56
|
*
|
|
74
|
-
* @param
|
|
57
|
+
* @param id - The technical identifier of the role.
|
|
75
58
|
* @returns A promise resolving to an array of permission strings.
|
|
76
59
|
*/
|
|
77
|
-
async getPermissions(
|
|
78
|
-
const role = await this.store.
|
|
60
|
+
async getPermissions(id) {
|
|
61
|
+
const role = await this.store.findById(id);
|
|
79
62
|
return role?.permissions || [];
|
|
80
63
|
}
|
|
81
64
|
};
|
|
82
65
|
RoleService = __decorate([
|
|
83
66
|
injectable(),
|
|
84
|
-
|
|
85
|
-
__metadata("design:paramtypes", [RoleStore, Object])
|
|
67
|
+
__metadata("design:paramtypes", [RoleStore])
|
|
86
68
|
], RoleService);
|
|
87
69
|
export { RoleService };
|
package/dist/types.d.ts
CHANGED
|
@@ -31,9 +31,9 @@ export type PrincipalMode = "roles" | "db" | "api";
|
|
|
31
31
|
*/
|
|
32
32
|
export interface IdentityRole {
|
|
33
33
|
/**
|
|
34
|
-
* Technical identifier for the role (e.g., 'admin',
|
|
34
|
+
* Technical identifier for the role (e.g., 'admin', 1, 'uuid').
|
|
35
35
|
*/
|
|
36
|
-
|
|
36
|
+
id: string | number;
|
|
37
37
|
/**
|
|
38
38
|
* Hierarchical weight.
|
|
39
39
|
*
|
|
@@ -93,12 +93,12 @@ export interface IdentityOptions {
|
|
|
93
93
|
*
|
|
94
94
|
* Required when mode is 'roles'.
|
|
95
95
|
*/
|
|
96
|
-
roles?: Record<string, IdentityRole>;
|
|
96
|
+
roles?: Record<string | number, IdentityRole>;
|
|
97
97
|
/**
|
|
98
|
-
* The
|
|
98
|
+
* The ID of the role assigned to newly created accounts.
|
|
99
99
|
* @defaultValue 'user'
|
|
100
100
|
*/
|
|
101
|
-
defaultRole?: string;
|
|
101
|
+
defaultRole?: string | number;
|
|
102
102
|
/**
|
|
103
103
|
* Time-to-live in milliseconds for cached principal data.
|
|
104
104
|
*
|
|
@@ -121,21 +121,15 @@ export interface IdentityAccount {
|
|
|
121
121
|
/**
|
|
122
122
|
* Internal unique database/store ID.
|
|
123
123
|
*/
|
|
124
|
-
id: string;
|
|
125
|
-
/**
|
|
126
|
-
* External stable ID used by the framework (linkedID).
|
|
127
|
-
*
|
|
128
|
-
* Usually a UUID or an external system ID.
|
|
129
|
-
*/
|
|
130
|
-
linkedId: string;
|
|
124
|
+
id: string | number;
|
|
131
125
|
/**
|
|
132
126
|
* Primary connection identifier (e.g., 'license:123...').
|
|
133
127
|
*/
|
|
134
128
|
identifier: string;
|
|
135
129
|
/**
|
|
136
|
-
* Current technical role
|
|
130
|
+
* Current technical role ID assigned to this account.
|
|
137
131
|
*/
|
|
138
|
-
|
|
132
|
+
roleId?: string | number;
|
|
139
133
|
/**
|
|
140
134
|
* Optional technical username for credentials-based authentication.
|
|
141
135
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-core/identity",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
4
4
|
"description": "Enterprise-grade identity, authentication, and authorization plugin for OpenCore Framework",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
16
|
"build": "tsc -p tsconfig.json",
|
|
17
|
+
"prepack": "npm run build",
|
|
17
18
|
"clean": "rimraf dist",
|
|
18
19
|
"lint": "eslint . --ext .ts",
|
|
19
20
|
"lint:fix": "eslint . --ext .ts --fix",
|