@open-core/identity 1.0.0 → 1.2.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/README.md +54 -658
- package/dist/entities/account.entity.js +1 -2
- package/dist/entities/role.entity.js +1 -2
- package/dist/events/identity.events.js +1 -2
- package/dist/index.js +33 -73
- package/dist/repositories/account.repository.d.ts +4 -4
- package/dist/repositories/account.repository.js +2 -6
- package/dist/repositories/role.repository.d.ts +4 -4
- package/dist/repositories/role.repository.js +2 -6
- package/dist/services/account.service.js +12 -15
- package/dist/services/auth/api-auth.provider.js +7 -10
- package/dist/services/auth/credentials-auth.provider.js +8 -44
- package/dist/services/auth/local-auth.provider.js +7 -10
- package/dist/services/cache/memory-cache.service.js +4 -7
- package/dist/services/identity-auth.provider.js +7 -10
- package/dist/services/identity-principal.provider.js +12 -15
- package/dist/services/principal/api-principal.provider.js +9 -12
- package/dist/services/principal/local-principal.provider.js +12 -15
- package/dist/services/role.service.js +6 -9
- package/dist/setup.js +25 -28
- package/dist/types/auth.types.js +1 -2
- package/dist/types/index.js +1 -2
- package/package.json +13 -8
- package/migrations/001_accounts_table.sql +0 -16
- package/migrations/002_roles_table.sql +0 -21
- package/migrations/003_alter_accounts_add_role.sql +0 -24
- package/migrations/004_rename_uuid_to_linked_id.sql +0 -12
- package/migrations/005_add_password_hash.sql +0 -7
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,59 +1,20 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
36
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.setupIdentity = exports.Identity = void 0;
|
|
40
1
|
// Imports for namespace
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
2
|
+
import * as Setup from "./setup";
|
|
3
|
+
import * as AccountRepo from "./repositories/account.repository";
|
|
4
|
+
import * as RoleRepo from "./repositories/role.repository";
|
|
5
|
+
import * as AcctService from "./services/account.service";
|
|
6
|
+
import * as RService from "./services/role.service";
|
|
7
|
+
import * as CacheService from "./services/cache/memory-cache.service";
|
|
8
|
+
import * as LocalAuth from "./services/auth/local-auth.provider";
|
|
9
|
+
import * as CredentialsAuth from "./services/auth/credentials-auth.provider";
|
|
10
|
+
import * as ApiAuth from "./services/auth/api-auth.provider";
|
|
11
|
+
import * as LocalPrincipal from "./services/principal/local-principal.provider";
|
|
12
|
+
import * as ApiPrincipal from "./services/principal/api-principal.provider";
|
|
13
|
+
import * as AuthProvider from "./services/identity-auth.provider";
|
|
14
|
+
import * as PrincipalProvider from "./services/identity-principal.provider";
|
|
54
15
|
// Namespace for organized exports
|
|
55
16
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
56
|
-
var Identity;
|
|
17
|
+
export var Identity;
|
|
57
18
|
(function (Identity) {
|
|
58
19
|
// Setup
|
|
59
20
|
Identity.setup = Setup.setupIdentity;
|
|
@@ -74,27 +35,26 @@ var Identity;
|
|
|
74
35
|
// Legacy providers (for backward compatibility)
|
|
75
36
|
Identity.IdentityAuthProvider = AuthProvider.IdentityAuthProvider;
|
|
76
37
|
Identity.IdentityPrincipalProvider = PrincipalProvider.IdentityPrincipalProvider;
|
|
77
|
-
})(Identity || (
|
|
38
|
+
})(Identity || (Identity = {}));
|
|
78
39
|
// Top-level exports for backward compatibility
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
__exportStar(require("./services/cache/memory-cache.service"), exports);
|
|
40
|
+
export { setupIdentity } from "./setup";
|
|
41
|
+
export * from "./entities/account.entity";
|
|
42
|
+
export * from "./entities/role.entity";
|
|
43
|
+
export * from "./repositories/account.repository";
|
|
44
|
+
export * from "./repositories/role.repository";
|
|
45
|
+
export * from "./services/account.service";
|
|
46
|
+
export * from "./services/role.service";
|
|
47
|
+
export * from "./services/cache/memory-cache.service";
|
|
88
48
|
// Auth providers
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
49
|
+
export * from "./services/auth/local-auth.provider";
|
|
50
|
+
export * from "./services/auth/credentials-auth.provider";
|
|
51
|
+
export * from "./services/auth/api-auth.provider";
|
|
92
52
|
// Principal providers
|
|
93
|
-
|
|
94
|
-
|
|
53
|
+
export * from "./services/principal/local-principal.provider";
|
|
54
|
+
export * from "./services/principal/api-principal.provider";
|
|
95
55
|
// Legacy providers
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
56
|
+
export * from "./services/identity-auth.provider";
|
|
57
|
+
export * from "./services/identity-principal.provider";
|
|
58
|
+
export * from "./events/identity.events";
|
|
59
|
+
export * from "./types";
|
|
60
|
+
export * from "./types/auth.types";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Repository, type DatabaseContract } from "@open-core/framework/server";
|
|
2
2
|
import type { Account } from "../entities/account.entity";
|
|
3
3
|
import type { Role } from "../entities/role.entity";
|
|
4
4
|
import type { CreateAccountInput, IdentifierType } from "../types";
|
|
@@ -21,10 +21,10 @@ interface AccountRow {
|
|
|
21
21
|
/**
|
|
22
22
|
* Repository for the accounts table.
|
|
23
23
|
*/
|
|
24
|
-
export declare class AccountRepository extends
|
|
25
|
-
protected readonly db:
|
|
24
|
+
export declare class AccountRepository extends Repository<Account> {
|
|
25
|
+
protected readonly db: DatabaseContract;
|
|
26
26
|
protected tableName: string;
|
|
27
|
-
constructor(db:
|
|
27
|
+
constructor(db: DatabaseContract);
|
|
28
28
|
findByLinkedId(linkedId: string): Promise<Account | null>;
|
|
29
29
|
findByIdentifier(type: IdentifierType, value: string): Promise<Account | null>;
|
|
30
30
|
createAccount(input: CreateAccountInput): Promise<Account>;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AccountRepository = void 0;
|
|
4
|
-
const framework_1 = require("@open-core/framework");
|
|
1
|
+
import { Repository } from "@open-core/framework/server";
|
|
5
2
|
/**
|
|
6
3
|
* Repository for the accounts table.
|
|
7
4
|
*/
|
|
8
|
-
class AccountRepository extends
|
|
5
|
+
export class AccountRepository extends Repository {
|
|
9
6
|
constructor(db) {
|
|
10
7
|
super(db);
|
|
11
8
|
this.db = db;
|
|
@@ -182,4 +179,3 @@ class AccountRepository extends framework_1.Server.Repository {
|
|
|
182
179
|
}
|
|
183
180
|
}
|
|
184
181
|
}
|
|
185
|
-
exports.AccountRepository = AccountRepository;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Repository, type DatabaseContract } from "@open-core/framework/server";
|
|
2
2
|
import type { Role } from "../entities/role.entity";
|
|
3
3
|
interface RoleRow {
|
|
4
4
|
id?: number;
|
|
@@ -13,10 +13,10 @@ interface RoleRow {
|
|
|
13
13
|
* Repository for the roles table.
|
|
14
14
|
* Manages CRUD operations for roles with custom queries for defaults and names.
|
|
15
15
|
*/
|
|
16
|
-
export declare class RoleRepository extends
|
|
17
|
-
protected readonly db:
|
|
16
|
+
export declare class RoleRepository extends Repository<Role> {
|
|
17
|
+
protected readonly db: DatabaseContract;
|
|
18
18
|
protected tableName: string;
|
|
19
|
-
constructor(db:
|
|
19
|
+
constructor(db: DatabaseContract);
|
|
20
20
|
/**
|
|
21
21
|
* Find a role by its internal name.
|
|
22
22
|
*
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RoleRepository = void 0;
|
|
4
|
-
const framework_1 = require("@open-core/framework");
|
|
1
|
+
import { Repository } from "@open-core/framework/server";
|
|
5
2
|
/**
|
|
6
3
|
* Repository for the roles table.
|
|
7
4
|
* Manages CRUD operations for roles with custom queries for defaults and names.
|
|
8
5
|
*/
|
|
9
|
-
class RoleRepository extends
|
|
6
|
+
export class RoleRepository extends Repository {
|
|
10
7
|
constructor(db) {
|
|
11
8
|
super(db);
|
|
12
9
|
this.db = db;
|
|
@@ -76,4 +73,3 @@ class RoleRepository extends framework_1.Server.Repository {
|
|
|
76
73
|
};
|
|
77
74
|
}
|
|
78
75
|
}
|
|
79
|
-
exports.RoleRepository = RoleRepository;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -8,13 +7,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const account_repository_1 = require("../repositories/account.repository");
|
|
17
|
-
const role_service_1 = require("./role.service");
|
|
10
|
+
import { injectable } from "tsyringe";
|
|
11
|
+
import { Server } from "@open-core/framework";
|
|
12
|
+
import { randomUUID } from "crypto";
|
|
13
|
+
import { AccountRepository } from "../repositories/account.repository";
|
|
14
|
+
import { RoleService } from "./role.service";
|
|
18
15
|
let AccountService = class AccountService {
|
|
19
16
|
constructor(repo, roleService, config) {
|
|
20
17
|
this.repo = repo;
|
|
@@ -39,7 +36,7 @@ let AccountService = class AccountService {
|
|
|
39
36
|
const defaultRole = await this.roleService.getDefaultRole();
|
|
40
37
|
// Auto-generate linkedId by default (UUID format for local accounts)
|
|
41
38
|
const created = await this.repo.createAccount({
|
|
42
|
-
linkedId:
|
|
39
|
+
linkedId: randomUUID(),
|
|
43
40
|
externalSource: "local",
|
|
44
41
|
license: identifiers.license ?? null,
|
|
45
42
|
discord: identifiers.discord ?? null,
|
|
@@ -189,7 +186,7 @@ let AccountService = class AccountService {
|
|
|
189
186
|
// Note: This creates an account without password_hash field
|
|
190
187
|
// You'll need to add password_hash to Account entity and migration 005
|
|
191
188
|
return this.repo.createAccount({
|
|
192
|
-
linkedId:
|
|
189
|
+
linkedId: randomUUID(),
|
|
193
190
|
externalSource: "credentials",
|
|
194
191
|
username: input.username,
|
|
195
192
|
license: input.identifiers.license ?? null,
|
|
@@ -199,9 +196,9 @@ let AccountService = class AccountService {
|
|
|
199
196
|
});
|
|
200
197
|
}
|
|
201
198
|
};
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
(
|
|
205
|
-
|
|
206
|
-
role_service_1.RoleService, framework_1.Server.ConfigService])
|
|
199
|
+
AccountService = __decorate([
|
|
200
|
+
injectable(),
|
|
201
|
+
__metadata("design:paramtypes", [AccountRepository,
|
|
202
|
+
RoleService, Server.ConfigService])
|
|
207
203
|
], AccountService);
|
|
204
|
+
export { AccountService };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -8,11 +7,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const framework_1 = require("@open-core/framework");
|
|
15
|
-
const memory_cache_service_1 = require("../cache/memory-cache.service");
|
|
10
|
+
import { injectable } from "tsyringe";
|
|
11
|
+
import { Server } from "@open-core/framework";
|
|
12
|
+
import { MemoryCacheService } from "../cache/memory-cache.service";
|
|
16
13
|
/**
|
|
17
14
|
* API-based authentication provider that delegates auth to external API.
|
|
18
15
|
* Does NOT require local database (uses memory cache only).
|
|
@@ -127,8 +124,8 @@ let ApiAuthProvider = class ApiAuthProvider {
|
|
|
127
124
|
}
|
|
128
125
|
}
|
|
129
126
|
};
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
(
|
|
133
|
-
__metadata("design:paramtypes", [framework_1.Server.ConfigService, framework_1.Server.HttpService, memory_cache_service_1.MemoryCacheService])
|
|
127
|
+
ApiAuthProvider = __decorate([
|
|
128
|
+
injectable(),
|
|
129
|
+
__metadata("design:paramtypes", [Server.ConfigService, Server.HttpService, MemoryCacheService])
|
|
134
130
|
], ApiAuthProvider);
|
|
131
|
+
export { ApiAuthProvider };
|
|
@@ -1,52 +1,16 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
6
|
};
|
|
24
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
-
var ownKeys = function(o) {
|
|
26
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
-
var ar = [];
|
|
28
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
-
return ar;
|
|
30
|
-
};
|
|
31
|
-
return ownKeys(o);
|
|
32
|
-
};
|
|
33
|
-
return function (mod) {
|
|
34
|
-
if (mod && mod.__esModule) return mod;
|
|
35
|
-
var result = {};
|
|
36
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
-
__setModuleDefault(result, mod);
|
|
38
|
-
return result;
|
|
39
|
-
};
|
|
40
|
-
})();
|
|
41
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
9
|
};
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const bcrypt = __importStar(require("bcrypt"));
|
|
49
|
-
const account_service_1 = require("../account.service");
|
|
10
|
+
import { injectable } from "tsyringe";
|
|
11
|
+
import { Server } from "@open-core/framework";
|
|
12
|
+
import * as bcrypt from "bcrypt";
|
|
13
|
+
import { AccountService } from "../account.service";
|
|
50
14
|
/**
|
|
51
15
|
* Credentials-based authentication provider using username/password.
|
|
52
16
|
* Requires password_hash column in accounts table (migration 005).
|
|
@@ -207,8 +171,8 @@ let CredentialsAuthProvider = class CredentialsAuthProvider {
|
|
|
207
171
|
return result;
|
|
208
172
|
}
|
|
209
173
|
};
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
(
|
|
213
|
-
__metadata("design:paramtypes", [account_service_1.AccountService, framework_1.Server.ConfigService])
|
|
174
|
+
CredentialsAuthProvider = __decorate([
|
|
175
|
+
injectable(),
|
|
176
|
+
__metadata("design:paramtypes", [AccountService, Server.ConfigService])
|
|
214
177
|
], CredentialsAuthProvider);
|
|
178
|
+
export { CredentialsAuthProvider };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -8,11 +7,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const framework_1 = require("@open-core/framework");
|
|
15
|
-
const account_service_1 = require("../account.service");
|
|
10
|
+
import { injectable } from "tsyringe";
|
|
11
|
+
import { Server } from "@open-core/framework";
|
|
12
|
+
import { AccountService } from "../account.service";
|
|
16
13
|
/**
|
|
17
14
|
* Local authentication provider that auto-creates accounts based on FiveM identifiers.
|
|
18
15
|
* This is the default/traditional authentication method for FiveM servers.
|
|
@@ -128,8 +125,8 @@ let LocalAuthProvider = class LocalAuthProvider {
|
|
|
128
125
|
return result;
|
|
129
126
|
}
|
|
130
127
|
};
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
(
|
|
134
|
-
__metadata("design:paramtypes", [account_service_1.AccountService, framework_1.Server.ConfigService])
|
|
128
|
+
LocalAuthProvider = __decorate([
|
|
129
|
+
injectable(),
|
|
130
|
+
__metadata("design:paramtypes", [AccountService, Server.ConfigService])
|
|
135
131
|
], LocalAuthProvider);
|
|
132
|
+
export { LocalAuthProvider };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -8,9 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
exports.MemoryCacheService = void 0;
|
|
13
|
-
const tsyringe_1 = require("tsyringe");
|
|
10
|
+
import { injectable } from "tsyringe";
|
|
14
11
|
/**
|
|
15
12
|
* Simple in-memory cache with TTL support.
|
|
16
13
|
* Used to cache API responses and reduce external calls.
|
|
@@ -101,8 +98,8 @@ let MemoryCacheService = class MemoryCacheService {
|
|
|
101
98
|
}
|
|
102
99
|
}
|
|
103
100
|
};
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
(0, tsyringe_1.injectable)(),
|
|
101
|
+
MemoryCacheService = __decorate([
|
|
102
|
+
injectable(),
|
|
107
103
|
__metadata("design:paramtypes", [])
|
|
108
104
|
], MemoryCacheService);
|
|
105
|
+
export { MemoryCacheService };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -8,11 +7,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const framework_1 = require("@open-core/framework");
|
|
15
|
-
const account_service_1 = require("./account.service");
|
|
10
|
+
import { injectable } from "tsyringe";
|
|
11
|
+
import { Server } from "@open-core/framework";
|
|
12
|
+
import { AccountService } from "./account.service";
|
|
16
13
|
let IdentityAuthProvider = class IdentityAuthProvider {
|
|
17
14
|
constructor(accounts, config) {
|
|
18
15
|
this.accounts = accounts;
|
|
@@ -118,8 +115,8 @@ let IdentityAuthProvider = class IdentityAuthProvider {
|
|
|
118
115
|
return result;
|
|
119
116
|
}
|
|
120
117
|
};
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
(
|
|
124
|
-
__metadata("design:paramtypes", [account_service_1.AccountService, framework_1.Server.ConfigService])
|
|
118
|
+
IdentityAuthProvider = __decorate([
|
|
119
|
+
injectable(),
|
|
120
|
+
__metadata("design:paramtypes", [AccountService, Server.ConfigService])
|
|
125
121
|
], IdentityAuthProvider);
|
|
122
|
+
export { IdentityAuthProvider };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -8,12 +7,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const account_service_1 = require("./account.service");
|
|
16
|
-
const account_repository_1 = require("../repositories/account.repository");
|
|
10
|
+
import { injectable } from "tsyringe";
|
|
11
|
+
import { Utils } from "@open-core/framework";
|
|
12
|
+
import { AccountService } from "./account.service";
|
|
13
|
+
import { AccountRepository } from "../repositories/account.repository";
|
|
17
14
|
let IdentityPrincipalProvider = class IdentityPrincipalProvider {
|
|
18
15
|
constructor(accounts, repo) {
|
|
19
16
|
this.accounts = accounts;
|
|
@@ -22,11 +19,11 @@ let IdentityPrincipalProvider = class IdentityPrincipalProvider {
|
|
|
22
19
|
async getPrincipal(player) {
|
|
23
20
|
const linked = player.accountID;
|
|
24
21
|
if (!linked) {
|
|
25
|
-
throw new
|
|
22
|
+
throw new Utils.AppError("UNAUTHORIZED", "Player is not authenticated (no linked account)", "server");
|
|
26
23
|
}
|
|
27
24
|
const result = await this.repo.findByLinkedIdWithRole(String(linked));
|
|
28
25
|
if (!result) {
|
|
29
|
-
throw new
|
|
26
|
+
throw new Utils.AppError("UNAUTHORIZED", "Linked account not found", "server");
|
|
30
27
|
}
|
|
31
28
|
const { account, role } = result;
|
|
32
29
|
if (this.accounts.isBanExpired(account)) {
|
|
@@ -34,7 +31,7 @@ let IdentityPrincipalProvider = class IdentityPrincipalProvider {
|
|
|
34
31
|
account.banned = false;
|
|
35
32
|
}
|
|
36
33
|
if (account.banned) {
|
|
37
|
-
throw new
|
|
34
|
+
throw new Utils.AppError("PERMISSION_DENIED", "Account is banned", "server", {
|
|
38
35
|
banReason: account.banReason,
|
|
39
36
|
banExpires: account.banExpires,
|
|
40
37
|
});
|
|
@@ -96,9 +93,9 @@ let IdentityPrincipalProvider = class IdentityPrincipalProvider {
|
|
|
96
93
|
return Array.from(base);
|
|
97
94
|
}
|
|
98
95
|
};
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
(
|
|
102
|
-
|
|
103
|
-
account_repository_1.AccountRepository])
|
|
96
|
+
IdentityPrincipalProvider = __decorate([
|
|
97
|
+
injectable(),
|
|
98
|
+
__metadata("design:paramtypes", [AccountService,
|
|
99
|
+
AccountRepository])
|
|
104
100
|
], IdentityPrincipalProvider);
|
|
101
|
+
export { IdentityPrincipalProvider };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -8,11 +7,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const framework_1 = require("@open-core/framework");
|
|
15
|
-
const memory_cache_service_1 = require("../cache/memory-cache.service");
|
|
10
|
+
import { injectable } from "tsyringe";
|
|
11
|
+
import { Server, Utils } from "@open-core/framework";
|
|
12
|
+
import { MemoryCacheService } from "../cache/memory-cache.service";
|
|
16
13
|
/**
|
|
17
14
|
* API-based principal provider that fetches permissions from external API.
|
|
18
15
|
* Does NOT require local database (uses memory cache only).
|
|
@@ -46,7 +43,7 @@ let ApiPrincipalProvider = class ApiPrincipalProvider {
|
|
|
46
43
|
async getPrincipal(player) {
|
|
47
44
|
const linked = player.accountID;
|
|
48
45
|
if (!linked) {
|
|
49
|
-
throw new
|
|
46
|
+
throw new Utils.AppError("UNAUTHORIZED", "Player is not authenticated (no linked account)", "server");
|
|
50
47
|
}
|
|
51
48
|
// Check cache first
|
|
52
49
|
const cacheKey = `principal:${linked}`;
|
|
@@ -82,7 +79,7 @@ let ApiPrincipalProvider = class ApiPrincipalProvider {
|
|
|
82
79
|
meta: {},
|
|
83
80
|
};
|
|
84
81
|
}
|
|
85
|
-
throw new
|
|
82
|
+
throw new Utils.AppError("UNAUTHORIZED", `Failed to fetch principal from API: ${error instanceof Error ? error.message : "Unknown error"}`, "server");
|
|
86
83
|
}
|
|
87
84
|
}
|
|
88
85
|
async refreshPrincipal(player) {
|
|
@@ -134,8 +131,8 @@ let ApiPrincipalProvider = class ApiPrincipalProvider {
|
|
|
134
131
|
}
|
|
135
132
|
}
|
|
136
133
|
};
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
(
|
|
140
|
-
__metadata("design:paramtypes", [framework_1.Server.ConfigService, framework_1.Server.HttpService, memory_cache_service_1.MemoryCacheService])
|
|
134
|
+
ApiPrincipalProvider = __decorate([
|
|
135
|
+
injectable(),
|
|
136
|
+
__metadata("design:paramtypes", [Server.ConfigService, Server.HttpService, MemoryCacheService])
|
|
141
137
|
], ApiPrincipalProvider);
|
|
138
|
+
export { ApiPrincipalProvider };
|