itlab-internal-services 2.16.3 → 2.16.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/classes/fetch-options/liked-by-options.class.d.ts +1 -3
- package/dist/classes/fetch-options/liked-by-options.class.js +1 -3
- package/dist/classes/task-manager.class.d.ts +22 -18
- package/dist/classes/task-manager.class.js +28 -24
- package/dist/middleware/http-logging.middleware.js +1 -11
- package/dist/modules/services/base-http.service.js +1 -1
- package/dist/modules/services/providers/accounts.service.js +12 -2
- package/dist/modules/services/providers/notification/notification.service.js +1 -1
- package/dist/pipes/restricted-fields.pipe.js +2 -0
- package/dist/swagger/remove-public-route-auth.plugin.js +0 -1
- package/package.json +1 -1
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
export declare function LikedByOptions<TBase extends new (...args: any[]) => any>(Base: TBase
|
|
2
|
-
requiredPermissions?: string[];
|
|
3
|
-
}): {
|
|
1
|
+
export declare function LikedByOptions<TBase extends new (...args: any[]) => any>(Base: TBase): {
|
|
4
2
|
new (...args: any[]): {
|
|
5
3
|
[x: string]: any;
|
|
6
4
|
includeLikedBy?: boolean;
|
|
@@ -12,16 +12,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.LikedByOptions = LikedByOptions;
|
|
13
13
|
const swagger_1 = require("@nestjs/swagger");
|
|
14
14
|
const class_validator_1 = require("class-validator");
|
|
15
|
-
const pipes_1 = require("../../pipes");
|
|
16
15
|
const transform_1 = require("../../transform");
|
|
17
|
-
function LikedByOptions(Base
|
|
16
|
+
function LikedByOptions(Base) {
|
|
18
17
|
class LikedByOptions extends Base {
|
|
19
18
|
}
|
|
20
19
|
__decorate([
|
|
21
20
|
(0, swagger_1.ApiPropertyOptional)({}),
|
|
22
21
|
(0, transform_1.BooleanTransform)(),
|
|
23
22
|
(0, class_validator_1.IsOptional)(),
|
|
24
|
-
(0, pipes_1.Restricted)(options === null || options === void 0 ? void 0 : options.requiredPermissions),
|
|
25
23
|
__metadata("design:type", Boolean)
|
|
26
24
|
], LikedByOptions.prototype, "includeLikedBy", void 0);
|
|
27
25
|
return LikedByOptions;
|
|
@@ -24,7 +24,7 @@ export declare class TaskManager {
|
|
|
24
24
|
* @param accountsService Service responsible for fetching users
|
|
25
25
|
* @returns Map of userId -> user
|
|
26
26
|
*/
|
|
27
|
-
static fetchAndMapUsers(userIdGroups: string[][], accountsService: AccountsService): Promise<
|
|
27
|
+
static fetchAndMapUsers(userIdGroups: string[][], accountsService: AccountsService): Promise<FetchMap<User>>;
|
|
28
28
|
/**
|
|
29
29
|
* Fetches all users for the given ID groups and returns a mapping.
|
|
30
30
|
* Ensures each user is fetched only once.
|
|
@@ -32,23 +32,7 @@ export declare class TaskManager {
|
|
|
32
32
|
* @param accountsService Service responsible for fetching users
|
|
33
33
|
* @returns Map of userId -> user
|
|
34
34
|
*/
|
|
35
|
-
static fetchAndMapAccounts(accountIdGroups: string[][], accountsService: AccountsService): Promise<
|
|
36
|
-
/**
|
|
37
|
-
* Maps an array of IDs to user objects using a userMap.
|
|
38
|
-
* Filters out any IDs that don’t have a corresponding user.
|
|
39
|
-
* @param userIds Array of user IDs to map
|
|
40
|
-
* @param userMap Map of userId -> user object
|
|
41
|
-
* @returns Array of user objects
|
|
42
|
-
*/
|
|
43
|
-
static mapIdsToUsers(userIds: string[], userMap: Map<string, User>): User[];
|
|
44
|
-
/**
|
|
45
|
-
* Maps an array of IDs to user objects using a userMap.
|
|
46
|
-
* Filters out any IDs that don’t have a corresponding user.
|
|
47
|
-
* @param accountIds Array of user IDs to map
|
|
48
|
-
* @param accountMap Map of userId -> user object
|
|
49
|
-
* @returns Array of user objects
|
|
50
|
-
*/
|
|
51
|
-
static mapIdsToAccounts(accountIds: string[], accountMap: Map<string, Account>): Account[];
|
|
35
|
+
static fetchAndMapAccounts(accountIdGroups: string[][], accountsService: AccountsService): Promise<FetchMap<Account>>;
|
|
52
36
|
/**
|
|
53
37
|
* Adds a new asynchronous task to the queue.
|
|
54
38
|
*
|
|
@@ -69,3 +53,23 @@ export declare class TaskManager {
|
|
|
69
53
|
*/
|
|
70
54
|
clear(): void;
|
|
71
55
|
}
|
|
56
|
+
declare class FetchMap<T extends User | Account> {
|
|
57
|
+
private readonly map;
|
|
58
|
+
constructor(items?: T[]);
|
|
59
|
+
/**
|
|
60
|
+
* Maps a single ID to an user/account object using a user/account Map.
|
|
61
|
+
* @param id ID of user/account to map
|
|
62
|
+
* @param map Map of id -> user/account object
|
|
63
|
+
* @returns user/account object
|
|
64
|
+
*/
|
|
65
|
+
get(id: string): T;
|
|
66
|
+
/**
|
|
67
|
+
* Maps an array of IDs to user/account objects using a user/account Map.
|
|
68
|
+
* Filters out any IDs that don’t have a corresponding entity.
|
|
69
|
+
* @param ids Array of user/account IDs to map
|
|
70
|
+
* @param map Map of id -> user/account object
|
|
71
|
+
* @returns Array of user/account objects
|
|
72
|
+
*/
|
|
73
|
+
getMultiple(ids: string[]): T[];
|
|
74
|
+
}
|
|
75
|
+
export {};
|
|
@@ -31,11 +31,11 @@ class TaskManager {
|
|
|
31
31
|
// Collect all unique user IDs across all groups
|
|
32
32
|
const uniqueUserIds = new Set(userIdGroups.flat());
|
|
33
33
|
if (uniqueUserIds.size === 0)
|
|
34
|
-
return new
|
|
34
|
+
return new FetchMap();
|
|
35
35
|
// Fetch all users once
|
|
36
36
|
const userCollection = await accountsService.getUserCollection(Array.from(uniqueUserIds));
|
|
37
37
|
// Build a map for quick lookup
|
|
38
|
-
return new
|
|
38
|
+
return new FetchMap(userCollection);
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
41
|
* Fetches all users for the given ID groups and returns a mapping.
|
|
@@ -48,31 +48,11 @@ class TaskManager {
|
|
|
48
48
|
// Collect all unique user IDs across all groups
|
|
49
49
|
const uniqueAccountIds = new Set(accountIdGroups.flat());
|
|
50
50
|
if (uniqueAccountIds.size === 0)
|
|
51
|
-
return new
|
|
51
|
+
return new FetchMap();
|
|
52
52
|
// Fetch all users once
|
|
53
53
|
const accountCollection = await accountsService.getAccountCollection(Array.from(uniqueAccountIds));
|
|
54
54
|
// Build a map for quick lookup
|
|
55
|
-
return new
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Maps an array of IDs to user objects using a userMap.
|
|
59
|
-
* Filters out any IDs that don’t have a corresponding user.
|
|
60
|
-
* @param userIds Array of user IDs to map
|
|
61
|
-
* @param userMap Map of userId -> user object
|
|
62
|
-
* @returns Array of user objects
|
|
63
|
-
*/
|
|
64
|
-
static mapIdsToUsers(userIds, userMap) {
|
|
65
|
-
return userIds.map((userId) => userMap.get(userId)).filter(Boolean);
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Maps an array of IDs to user objects using a userMap.
|
|
69
|
-
* Filters out any IDs that don’t have a corresponding user.
|
|
70
|
-
* @param accountIds Array of user IDs to map
|
|
71
|
-
* @param accountMap Map of userId -> user object
|
|
72
|
-
* @returns Array of user objects
|
|
73
|
-
*/
|
|
74
|
-
static mapIdsToAccounts(accountIds, accountMap) {
|
|
75
|
-
return accountIds.map((accountId) => accountMap.get(accountId)).filter(Boolean);
|
|
55
|
+
return new FetchMap(accountCollection);
|
|
76
56
|
}
|
|
77
57
|
/**
|
|
78
58
|
* Adds a new asynchronous task to the queue.
|
|
@@ -101,3 +81,27 @@ class TaskManager {
|
|
|
101
81
|
}
|
|
102
82
|
}
|
|
103
83
|
exports.TaskManager = TaskManager;
|
|
84
|
+
class FetchMap {
|
|
85
|
+
constructor(items = []) {
|
|
86
|
+
this.map = new Map(items.map((item) => [item.id, item]));
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Maps a single ID to an user/account object using a user/account Map.
|
|
90
|
+
* @param id ID of user/account to map
|
|
91
|
+
* @param map Map of id -> user/account object
|
|
92
|
+
* @returns user/account object
|
|
93
|
+
*/
|
|
94
|
+
get(id) {
|
|
95
|
+
return this.map.get(id);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Maps an array of IDs to user/account objects using a user/account Map.
|
|
99
|
+
* Filters out any IDs that don’t have a corresponding entity.
|
|
100
|
+
* @param ids Array of user/account IDs to map
|
|
101
|
+
* @param map Map of id -> user/account object
|
|
102
|
+
* @returns Array of user/account objects
|
|
103
|
+
*/
|
|
104
|
+
getMultiple(ids) {
|
|
105
|
+
return ids.map((id) => this.map.get(id)).filter(Boolean);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -33,17 +33,7 @@ const HttpLoggingMiddleware = (req, res, next) => {
|
|
|
33
33
|
next();
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
// ensuring accurate status information
|
|
38
|
-
res.on('finish', () => {
|
|
39
|
-
const { statusCode, statusMessage } = res;
|
|
40
|
-
// Construct a standardized log message
|
|
41
|
-
const logMessage = `${method} ${url} - ${statusCode} (${statusMessage})`;
|
|
42
|
-
// Client errors (4xx) are logged at warn level for visibility
|
|
43
|
-
// All other responses use standard log level
|
|
44
|
-
const logLevel = statusCode >= 400 && statusCode < 500 ? 'warn' : 'log';
|
|
45
|
-
logger[logLevel](logMessage);
|
|
46
|
-
});
|
|
36
|
+
logger.log(`Handle ${method} ${url}`);
|
|
47
37
|
// Continue to next middleware or request handler
|
|
48
38
|
next();
|
|
49
39
|
};
|
|
@@ -49,7 +49,7 @@ class BaseHttpService {
|
|
|
49
49
|
// Attach request interceptor for consistent logging of all outgoing requests.
|
|
50
50
|
this.client.interceptors.request.use((config) => {
|
|
51
51
|
var _a;
|
|
52
|
-
this.logger.log(
|
|
52
|
+
this.logger.log(`${(_a = config.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()} ${config.url}`);
|
|
53
53
|
return config;
|
|
54
54
|
});
|
|
55
55
|
}
|
|
@@ -15,9 +15,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.AccountsService = void 0;
|
|
16
16
|
const common_1 = require("@nestjs/common");
|
|
17
17
|
const config_1 = require("@nestjs/config");
|
|
18
|
+
const itlab_functions_1 = require("itlab-functions");
|
|
18
19
|
const authentication_1 = require("../../authentication");
|
|
19
20
|
const base_http_service_1 = require("../base-http.service");
|
|
20
21
|
const base_urls_1 = require("../base-urls");
|
|
22
|
+
const chunkSize = 100;
|
|
21
23
|
/**
|
|
22
24
|
* AccountsService
|
|
23
25
|
*
|
|
@@ -57,7 +59,11 @@ let AccountsService = class AccountsService extends base_http_service_1.BaseHttp
|
|
|
57
59
|
async getAccountCollection(accountIds) {
|
|
58
60
|
if (accountIds.length === 0)
|
|
59
61
|
return [];
|
|
60
|
-
|
|
62
|
+
const chunkedAccountIds = (0, itlab_functions_1.createChunks)(accountIds, chunkSize);
|
|
63
|
+
const chunkedAccounts = chunkedAccountIds.map((accountIds) => {
|
|
64
|
+
return this.fetchResourceCollection(`internal/accounts`, { params: { ids: accountIds } });
|
|
65
|
+
});
|
|
66
|
+
return (await Promise.all(chunkedAccounts)).flat();
|
|
61
67
|
}
|
|
62
68
|
/**
|
|
63
69
|
* Retrieves a single user entry derived from an account.
|
|
@@ -77,7 +83,11 @@ let AccountsService = class AccountsService extends base_http_service_1.BaseHttp
|
|
|
77
83
|
async getUserCollection(userIds) {
|
|
78
84
|
if (userIds.length === 0)
|
|
79
85
|
return [];
|
|
80
|
-
|
|
86
|
+
const chunkedUserIds = (0, itlab_functions_1.createChunks)(userIds, chunkSize);
|
|
87
|
+
const chunkedUsers = chunkedUserIds.map((userIds) => {
|
|
88
|
+
return this.fetchResourceCollection(`internal/users`, { params: { ids: userIds } });
|
|
89
|
+
});
|
|
90
|
+
return (await Promise.all(chunkedUsers)).flat();
|
|
81
91
|
}
|
|
82
92
|
};
|
|
83
93
|
exports.AccountsService = AccountsService;
|
|
@@ -108,7 +108,7 @@ let NotificationService = NotificationService_1 = class NotificationService exte
|
|
|
108
108
|
this.logger.error('Cannot unschedule notification: Resource type not provided.');
|
|
109
109
|
return;
|
|
110
110
|
}
|
|
111
|
-
const endpoint = `internal
|
|
111
|
+
const endpoint = `internal/${this.options.resource}/${resourceId}`;
|
|
112
112
|
this.logger.log(`Unscheduling notification for ${this.options.resource} (${resourceId})`);
|
|
113
113
|
this.client
|
|
114
114
|
.delete(endpoint)
|
|
@@ -66,6 +66,8 @@ let RestrictedFieldsPipe = class RestrictedFieldsPipe {
|
|
|
66
66
|
// Determine the permissions available to this account
|
|
67
67
|
const grantedPerms = (_b = (_a = this.request.account) === null || _a === void 0 ? void 0 : _a.perms) !== null && _b !== void 0 ? _b : [];
|
|
68
68
|
const restrictions = this.reflector.get(RESTRICTED_METADATA_KEY, (_c = metadata.metatype) === null || _c === void 0 ? void 0 : _c.prototype);
|
|
69
|
+
if (!(0, class_validator_1.isObject)(restrictions))
|
|
70
|
+
return value;
|
|
69
71
|
for (const [propertyKey, requiredPerms] of Object.entries(restrictions)) {
|
|
70
72
|
if (requiredPerms.length && !(0, itlab_functions_1.hasSomePermission)(requiredPerms, grantedPerms)) {
|
|
71
73
|
delete value[propertyKey];
|