@inobeta/api 0.5.0 → 0.7.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/auth/auth.plugin.d.ts.map +1 -1
- package/dist/auth/auth.plugin.js +5 -4
- package/dist/auth/auth.plugin.js.map +1 -1
- package/dist/auth/auth.types.d.ts +0 -2
- package/dist/auth/auth.types.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/users/users.gql.d.ts +4 -11
- package/dist/users/users.gql.d.ts.map +1 -1
- package/dist/users/users.gql.js +6 -5
- package/dist/users/users.gql.js.map +1 -1
- package/dist/users/users.plugin.d.ts.map +1 -1
- package/dist/users/users.plugin.js +17 -16
- package/dist/users/users.plugin.js.map +1 -1
- package/dist/users/users.service.d.ts +45 -42
- package/dist/users/users.service.d.ts.map +1 -1
- package/dist/users/users.service.js +171 -166
- package/dist/users/users.service.js.map +1 -1
- package/dist/users/users.types.d.ts +5 -63
- package/dist/users/users.types.d.ts.map +1 -1
- package/dist/utils/date-utility.d.ts +2 -0
- package/dist/utils/date-utility.d.ts.map +1 -0
- package/dist/utils/date-utility.js +31 -0
- package/dist/utils/date-utility.js.map +1 -0
- package/dist/utils/email.d.ts +26 -0
- package/dist/utils/email.d.ts.map +1 -0
- package/dist/utils/email.js +56 -0
- package/dist/utils/email.js.map +1 -0
- package/dist/utils/http-utils.d.ts +3 -0
- package/dist/utils/http-utils.d.ts.map +1 -0
- package/dist/utils/http-utils.js +18 -0
- package/dist/utils/http-utils.js.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +20 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +7 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.plugin.d.ts","sourceRoot":"","sources":["../../src/auth/auth.plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,KAAK,EACR,iBAAiB,EAGpB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"auth.plugin.d.ts","sourceRoot":"","sources":["../../src/auth/auth.plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,KAAK,EACR,iBAAiB,EAGpB,MAAM,cAAc,CAAC;AAItB,wBAAgB,gBAAgB,CAC5B,OAAO,EAAE,iBAAiB,GAC3B,kBAAkB,CAiEpB"}
|
package/dist/auth/auth.plugin.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createAuthPlugin = void 0;
|
|
4
4
|
const auth_service_1 = require("./auth.service");
|
|
5
|
+
const http_utils_1 = require("../utils/http-utils");
|
|
5
6
|
function createAuthPlugin(options) {
|
|
6
7
|
const plugin = async (server) => {
|
|
7
8
|
server.route({
|
|
@@ -22,13 +23,13 @@ function createAuthPlugin(options) {
|
|
|
22
23
|
})
|
|
23
24
|
});
|
|
24
25
|
if (!tokens) {
|
|
25
|
-
return
|
|
26
|
+
return (0, http_utils_1.httpResponse)(reply, 401, "Invalid credentials");
|
|
26
27
|
}
|
|
27
28
|
return tokens;
|
|
28
29
|
}
|
|
29
30
|
catch (error) {
|
|
30
31
|
console.error("Login error", error);
|
|
31
|
-
return
|
|
32
|
+
return (0, http_utils_1.httpResponse)(reply, 500, "Internal server error");
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
});
|
|
@@ -49,13 +50,13 @@ function createAuthPlugin(options) {
|
|
|
49
50
|
})
|
|
50
51
|
});
|
|
51
52
|
if (!tokens) {
|
|
52
|
-
return
|
|
53
|
+
return (0, http_utils_1.httpResponse)(reply, 401, "Invalid credentials");
|
|
53
54
|
}
|
|
54
55
|
return tokens;
|
|
55
56
|
}
|
|
56
57
|
catch (error) {
|
|
57
58
|
console.error("Refresh token error", error);
|
|
58
|
-
return
|
|
59
|
+
return (0, http_utils_1.httpResponse)(reply, 500, "Internal server error");
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
62
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.plugin.js","sourceRoot":"","sources":["../../src/auth/auth.plugin.ts"],"names":[],"mappings":";;;AAMA,iDAA+C;
|
|
1
|
+
{"version":3,"file":"auth.plugin.js","sourceRoot":"","sources":["../../src/auth/auth.plugin.ts"],"names":[],"mappings":";;;AAMA,iDAA+C;AAC/C,oDAAmD;AAEnD,SAAgB,gBAAgB,CAC5B,OAA0B;IAE1B,MAAM,MAAM,GAAuB,KAAK,EAAE,MAAM,EAAE,EAAE;QAChD,MAAM,CAAC,KAAK,CAAsB;YAC9B,MAAM,EAAE,MAAM;YACd,GAAG,EAAE,WAAW;YAChB,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE;gBAC9B,IAAI;oBACA,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;oBAE5C,MAAM,MAAM,GAAG,MAAM,IAAA,4BAAa,EAAC;wBAC/B,OAAO,EAAE,OAAO,CAAC,OAAO;wBACxB,IAAI,EAAE,OAAO,CAAC,IAAI;wBAClB,QAAQ,EAAE,IAAI,eAAe,CAAC;4BAC1B,SAAS,EAAE,OAAO,CAAC,QAAQ;4BAC3B,aAAa,EAAE,OAAO,CAAC,YAAY;4BACnC,UAAU,EAAE,UAAU;4BACtB,QAAQ;4BACR,QAAQ;yBACX,CAAC;qBACL,CAAC,CAAC;oBAEH,IAAI,CAAC,MAAM,EAAE;wBACT,OAAO,IAAA,yBAAY,EAAC,KAAK,EAAE,GAAG,EAAE,qBAAqB,CAAC,CAAC;qBAC1D;oBAED,OAAO,MAAM,CAAC;iBACjB;gBAAC,OAAO,KA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
|
export interface AuthPluginOptions {
|
|
4
3
|
authUrl: string;
|
|
5
4
|
clientId: string;
|
|
6
5
|
clientSecret: string;
|
|
7
6
|
knex: Knex;
|
|
8
|
-
httpResponse: (reply: FastifyReply, statusCode: number, message: string) => unknown;
|
|
9
7
|
}
|
|
10
8
|
export interface LoginBody {
|
|
11
9
|
username: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.types.d.ts","sourceRoot":"","sources":["../../src/auth/auth.types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth.types.d.ts","sourceRoot":"","sources":["../../src/auth/auth.types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAEjC,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,IAAI,CAAC;CACZ;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,qBAAqB;IACpC,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./auth"), exports);
|
|
18
18
|
__exportStar(require("./users"), exports);
|
|
19
|
+
__exportStar(require("./utils"), exports);
|
|
19
20
|
__exportStar(require("./plugins/auth-jwt"), exports);
|
|
20
21
|
__exportStar(require("./plugins/keycloak-admin"), exports);
|
|
21
22
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,0CAAwB;AACxB,qDAAmC;AACnC,2DAAyC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,0CAAwB;AACxB,0CAAwB;AACxB,qDAAmC;AACnC,2DAAyC"}
|
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import type { FastifyInstance } from "fastify";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
getUsers(authHeader?: string): Promise<User[]>;
|
|
6
|
-
getUserByEmail(email: string, authHeader?: string): Promise<unknown>;
|
|
7
|
-
getUserById(id: string, authHeader?: string): Promise<unknown>;
|
|
8
|
-
};
|
|
9
|
-
path: string;
|
|
10
|
-
graphiql: boolean;
|
|
2
|
+
export interface RegisterUserGraphQLOptions {
|
|
3
|
+
path?: string;
|
|
4
|
+
graphiql?: boolean;
|
|
11
5
|
}
|
|
12
|
-
export declare function registerUserGraphQL(server: FastifyInstance, options
|
|
13
|
-
export {};
|
|
6
|
+
export declare function registerUserGraphQL(server: FastifyInstance, options?: RegisterUserGraphQLOptions): Promise<void>;
|
|
14
7
|
//# sourceMappingURL=users.gql.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"users.gql.d.ts","sourceRoot":"","sources":["../../src/users/users.gql.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"users.gql.d.ts","sourceRoot":"","sources":["../../src/users/users.gql.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAK/C,MAAM,WAAW,0BAA0B;IACvC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,wBAAsB,mBAAmB,CACrC,MAAM,EAAE,eAAe,EACvB,OAAO,CAAC,EAAE,0BAA0B,iBA2DvC"}
|
package/dist/users/users.gql.js
CHANGED
|
@@ -5,27 +5,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.registerUserGraphQL = void 0;
|
|
7
7
|
const mercurius_1 = __importDefault(require("mercurius"));
|
|
8
|
+
const users_service_1 = require("./users.service");
|
|
8
9
|
const users_schema_1 = require("./users.schema");
|
|
9
10
|
async function registerUserGraphQL(server, options) {
|
|
10
11
|
const resolvers = {
|
|
11
12
|
Query: {
|
|
12
13
|
users: async (_, args, context) => {
|
|
13
|
-
let users = (await
|
|
14
|
+
let users = (await (0, users_service_1.getUsers)(server, context.reply.request.headers.authorization)).filter((user) => (args.enabled === undefined || user.enabled === args.enabled) &&
|
|
14
15
|
(args.email === undefined || user.email === args.email));
|
|
15
16
|
if (args.orderBy?.length) {
|
|
16
17
|
users = [...users].sort(buildUserComparator(args.orderBy));
|
|
17
18
|
}
|
|
18
19
|
return users;
|
|
19
20
|
},
|
|
20
|
-
userByEmail: async (_, args, context) =>
|
|
21
|
-
user: async (_, args, context) =>
|
|
21
|
+
userByEmail: async (_, args, context) => (0, users_service_1.getUserByEmail)(server, args.email, context.reply.request.headers.authorization),
|
|
22
|
+
user: async (_, args, context) => (0, users_service_1.getUserById)(server, args.params.id, context.reply.request.headers.authorization)
|
|
22
23
|
}
|
|
23
24
|
};
|
|
24
25
|
await server.register(mercurius_1.default, {
|
|
25
26
|
schema: users_schema_1.userGraphqlSchema,
|
|
26
27
|
resolvers,
|
|
27
|
-
path: options
|
|
28
|
-
graphiql: options
|
|
28
|
+
path: options?.path ?? "/graphql",
|
|
29
|
+
graphiql: options?.graphiql ?? true
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
32
|
exports.registerUserGraphQL = registerUserGraphQL;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"users.gql.js","sourceRoot":"","sources":["../../src/users/users.gql.ts"],"names":[],"mappings":";;;;;;AAAA,0DAAkC;
|
|
1
|
+
{"version":3,"file":"users.gql.js","sourceRoot":"","sources":["../../src/users/users.gql.ts"],"names":[],"mappings":";;;;;;AAAA,0DAAkC;AAElC,mDAAwE;AAExE,iDAAmD;AAO5C,KAAK,UAAU,mBAAmB,CACrC,MAAuB,EACvB,OAAoC;IAEpC,MAAM,SAAS,GAAG;QACd,KAAK,EAAE;YACH,KAAK,EAAE,KAAK,EACR,CAAU,EACV,IAIC,EACD,OAAY,EACd,EAAE;gBACA,IAAI,KAAK,GAAG,CAAC,MAAM,IAAA,wBAAQ,EACvB,MAAM,EACN,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,CAC9C,CAAC,CAAC,MAAM,CACL,CAA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,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAErD,IAAI,MAAM,GAAG,EAAE,CAAC;YAChB,IAAI,MAAM,GAAG,EAAE,CAAC;YAEhB,QAAQ,IAAI,CAAC,GAAG,EAAE;gBACd,KAAK,OAAO;oBACR,MAAM,GAAG,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;oBACvB,MAAM,GAAG,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;oBACvB,MAAM;gBACV,KAAK,WAAW;oBACZ,MAAM,GAAG,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC;oBAC3B,MAAM,GAAG,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC;oBAC3B,MAAM;gBACV,KAAK,UAAU;oBACX,MAAM,GAAG,CAAC,CAAC,QAAQ,IAAI,EAAE,CAAC;oBAC1B,MAAM,GAAG,CAAC,CAAC,QAAQ,IAAI,EAAE,CAAC;oBAC1B,MAAM;aACb;YAED,MAAM,GAAG,GAAG,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE,SAAS,EAAE;gBAChD,WAAW,EAAE,MAAM;aACtB,CAAC,CAAC;YAEH,IAAI,GAAG,KAAK,CAAC,EAAE;gBACX,OAAO,GAAG,GAAG,SAAS,CAAC;aAC1B;SACJ;QAED,OAAO,CAAC,CAAC;IACb,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"users.plugin.d.ts","sourceRoot":"","sources":["../../src/users/users.plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"users.plugin.d.ts","sourceRoot":"","sources":["../../src/users/users.plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAUlD,OAAO,KAAK,EAKR,kBAAkB,EACrB,MAAM,eAAe,CAAC;AAGvB,wBAAgB,iBAAiB,CAC7B,OAAO,EAAE,kBAAkB,GAC5B,kBAAkB,CAoGpB"}
|
|
@@ -3,13 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createUsersPlugin = void 0;
|
|
4
4
|
const users_service_1 = require("./users.service");
|
|
5
5
|
const users_gql_1 = require("./users.gql");
|
|
6
|
+
const http_utils_1 = require("../utils/http-utils");
|
|
6
7
|
function createUsersPlugin(options) {
|
|
7
8
|
const plugin = async (server) => {
|
|
8
|
-
const service = (0, users_service_1.createUsersService)({
|
|
9
|
-
keycloak: options.keycloak,
|
|
10
|
-
auth: options.auth,
|
|
11
|
-
authConfig: options.authConfig
|
|
12
|
-
});
|
|
13
9
|
const prefix = options.prefix ?? "/v1";
|
|
14
10
|
server.route({
|
|
15
11
|
method: "GET",
|
|
@@ -17,7 +13,7 @@ function createUsersPlugin(options) {
|
|
|
17
13
|
config: {
|
|
18
14
|
capabilityRequested: "users.db_select"
|
|
19
15
|
},
|
|
20
|
-
handler: async (request) =>
|
|
16
|
+
handler: async (request) => (0, users_service_1.getUsers)(server, request.headers.authorization)
|
|
21
17
|
});
|
|
22
18
|
server.route({
|
|
23
19
|
method: "GET",
|
|
@@ -25,7 +21,7 @@ function createUsersPlugin(options) {
|
|
|
25
21
|
config: {
|
|
26
22
|
capabilityRequested: "users.db_select"
|
|
27
23
|
},
|
|
28
|
-
handler: async (request) =>
|
|
24
|
+
handler: async (request) => (0, users_service_1.getUserById)(server, request.params.id, request.headers.authorization)
|
|
29
25
|
});
|
|
30
26
|
server.route({
|
|
31
27
|
method: "PUT",
|
|
@@ -33,7 +29,7 @@ function createUsersPlugin(options) {
|
|
|
33
29
|
config: {
|
|
34
30
|
capabilityRequested: "users.db_update"
|
|
35
31
|
},
|
|
36
|
-
handler:
|
|
32
|
+
handler: (0, users_service_1.updateUser)(server)
|
|
37
33
|
});
|
|
38
34
|
server.route({
|
|
39
35
|
method: "DELETE",
|
|
@@ -41,7 +37,7 @@ function createUsersPlugin(options) {
|
|
|
41
37
|
config: {
|
|
42
38
|
capabilityRequested: "users.db_update"
|
|
43
39
|
},
|
|
44
|
-
handler:
|
|
40
|
+
handler: (0, users_service_1.deleteUser)(server)
|
|
45
41
|
});
|
|
46
42
|
server.route({
|
|
47
43
|
method: "POST",
|
|
@@ -50,9 +46,12 @@ function createUsersPlugin(options) {
|
|
|
50
46
|
capabilityRequested: "me.password-change"
|
|
51
47
|
},
|
|
52
48
|
handler: async (request, reply) => {
|
|
53
|
-
const result = await
|
|
49
|
+
const result = await (0, users_service_1.changeOwnPassword)(server, options.authConfig)({
|
|
50
|
+
headers: request.headers,
|
|
51
|
+
body: request.body
|
|
52
|
+
});
|
|
54
53
|
if (!result.ok) {
|
|
55
|
-
return
|
|
54
|
+
return (0, http_utils_1.httpResponse)(reply, result.statusCode, result.message);
|
|
56
55
|
}
|
|
57
56
|
return {
|
|
58
57
|
errors: false,
|
|
@@ -67,9 +66,12 @@ function createUsersPlugin(options) {
|
|
|
67
66
|
capabilityRequested: "users.password-change"
|
|
68
67
|
},
|
|
69
68
|
handler: async (request, reply) => {
|
|
70
|
-
const result = await
|
|
69
|
+
const result = await (0, users_service_1.changeUserPassword)(server)({
|
|
70
|
+
params: request.params,
|
|
71
|
+
body: request.body
|
|
72
|
+
});
|
|
71
73
|
if (!result.ok) {
|
|
72
|
-
return
|
|
74
|
+
return (0, http_utils_1.httpResponse)(reply, result.statusCode, result.message);
|
|
73
75
|
}
|
|
74
76
|
return {
|
|
75
77
|
errors: false,
|
|
@@ -79,9 +81,8 @@ function createUsersPlugin(options) {
|
|
|
79
81
|
});
|
|
80
82
|
if (options.graphql?.enabled) {
|
|
81
83
|
await (0, users_gql_1.registerUserGraphQL)(server, {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
graphiql: options.graphql.graphiql ?? true
|
|
84
|
+
path: options.graphql.path,
|
|
85
|
+
graphiql: options.graphql.graphiql
|
|
85
86
|
});
|
|
86
87
|
}
|
|
87
88
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"users.plugin.js","sourceRoot":"","sources":["../../src/users/users.plugin.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"users.plugin.js","sourceRoot":"","sources":["../../src/users/users.plugin.ts"],"names":[],"mappings":";;;AACA,mDAOyB;AACzB,2CAAkD;AAQlD,oDAAmD;AAEnD,SAAgB,iBAAiB,CAC7B,OAA2B;IAE3B,MAAM,MAAM,GAAuB,KAAK,EAAE,MAAM,EAAE,EAAE;QAChD,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,KAAK,CAAC;QAEvC,MAAM,CAAC,KAAK,CAAC;YACT,MAAM,EAAE,KAAK;YACb,GAAG,EAAE,GAAG,MAAM,QAAQ;YACtB,MAAM,EAAE;gBACJ,mBAAmB,EAAE,iBAAiB;aACzC;YACD,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,CACvB,IAAA,wBAAQ,EAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC;SACtD,CAAC,CAAC;QAEH,MAAM,CAAC,KAAK,CAAmB;YAC3B,MAAM,EAAE,KAAK;YACb,GAAG,EAAE,GAAG,MAAM,YAAY;YAC1B,MAAM,EAAE;gBACJ,mBAAmB,EAAE,iBAAiB;aACzC;YACD,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,CACvB,IAAA,2BAAW,EAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC;SAC5E,CAAC,CAAC;QAEH,MAAM,CAAC,KAAK,CAAkB;YAC1B,MAAM,EAAE,KAAK;YACb,GAAG,EAAE,GAAG,MAAM,YAAY;YAC1B,MAAM,EAAE;gBACJ,mBAAmB,EAAE,iBAAiB;aACzC;YACD,OAAO,EAAE,IAAA,0BAAU,EAAC,MAAM,CAAC;SAC9B,CAAC,CAAC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,CAAC;gBAEH,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE;oBACZ,OAAO,IAAA,yBAAY,EAAC,KAAK,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;iBACjE;gBAED,OAAO;oBACH,MAAM,EAAE,KAAK;oBACb,OAAO,EAAE,+BAA+B;iBAC3C,CAAC;YACN,CAAC;SACJ,CAAC,CAAC;QAEH,IAAI,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE;YAC1B,MAAM,IAAA,+BAAmB,EAAC,MAAM,EAAE;gBAC9B,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI;gBAC1B,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,QAAQ;aACrC,CAAC,CAAC;SACN;IACL,CAAC,CAAC;IAEF,OAAO,MAAM,CAAC;AAClB,CAAC;AAtGD,8CAsGC"}
|
|
@@ -1,44 +1,47 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import type { FastifyInstance } from "fastify";
|
|
2
|
+
import type { ChangeOwnPasswordRoute, ChangeUserPasswordRoute, UpdateUserRoute, User, UserDetailed, UsersAuthConfig } from "./users.types";
|
|
3
|
+
export declare const getUsers: (server: FastifyInstance, authHeader?: string) => Promise<User[]>;
|
|
4
|
+
export declare const getUserById: (server: FastifyInstance, id: string, authHeader?: string) => Promise<UserDetailed | null>;
|
|
5
|
+
export declare const getUserByEmail: (server: FastifyInstance, email: string, authHeader?: string) => Promise<UserDetailed | null>;
|
|
6
|
+
export declare const updateUser: (server: FastifyInstance) => (request: {
|
|
7
|
+
params: UpdateUserRoute["Params"];
|
|
8
|
+
body: UpdateUserRoute["Body"];
|
|
9
|
+
}) => Promise<{
|
|
10
|
+
errors: boolean;
|
|
11
|
+
message: string;
|
|
12
|
+
}>;
|
|
13
|
+
export declare const deleteUser: (server: FastifyInstance) => (request: {
|
|
14
|
+
params: {
|
|
15
|
+
id: string;
|
|
9
16
|
};
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
statusCode: number;
|
|
41
|
-
message: string;
|
|
42
|
-
}>;
|
|
43
|
-
};
|
|
17
|
+
}) => Promise<{
|
|
18
|
+
errors: boolean;
|
|
19
|
+
message: string;
|
|
20
|
+
}>;
|
|
21
|
+
export declare const changeOwnPassword: (server: FastifyInstance, authConfig: UsersAuthConfig) => (request: {
|
|
22
|
+
headers: {
|
|
23
|
+
authorization?: string;
|
|
24
|
+
};
|
|
25
|
+
body: ChangeOwnPasswordRoute["Body"];
|
|
26
|
+
}) => Promise<{
|
|
27
|
+
ok: false;
|
|
28
|
+
statusCode: number;
|
|
29
|
+
message: string;
|
|
30
|
+
} | {
|
|
31
|
+
ok: true;
|
|
32
|
+
statusCode?: undefined;
|
|
33
|
+
message?: undefined;
|
|
34
|
+
}>;
|
|
35
|
+
export declare const changeUserPassword: (server: FastifyInstance) => (request: {
|
|
36
|
+
params: ChangeUserPasswordRoute["Params"];
|
|
37
|
+
body: ChangeUserPasswordRoute["Body"];
|
|
38
|
+
}) => Promise<{
|
|
39
|
+
ok: true;
|
|
40
|
+
statusCode?: undefined;
|
|
41
|
+
message?: undefined;
|
|
42
|
+
} | {
|
|
43
|
+
ok: false;
|
|
44
|
+
statusCode: number;
|
|
45
|
+
message: string;
|
|
46
|
+
}>;
|
|
44
47
|
//# sourceMappingURL=users.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"users.service.d.ts","sourceRoot":"","sources":["../../src/users/users.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"users.service.d.ts","sourceRoot":"","sources":["../../src/users/users.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAG/C,OAAO,KAAK,EACR,sBAAsB,EACtB,uBAAuB,EACvB,eAAe,EACf,IAAI,EACJ,YAAY,EACZ,eAAe,EAClB,MAAM,eAAe,CAAC;AAEvB,eAAO,MAAM,QAAQ,WACT,eAAe,eACV,MAAM,KACpB,QAAQ,IAAI,EAAE,CAQhB,CAAC;AAEF,eAAO,MAAM,WAAW,WACZ,eAAe,MACnB,MAAM,eACG,MAAM,KACpB,QAAQ,YAAY,GAAG,IAAI,CAqB7B,CAAC;AAEF,eAAO,MAAM,cAAc,WACf,eAAe,SAChB,MAAM,eACA,MAAM,KACpB,QAAQ,YAAY,GAAG,IAAI,CAsB7B,CAAC;AAEF,eAAO,MAAM,UAAU,WACV,eAAe,eAEP;IACL,MAAM,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAC;IAClC,IAAI,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;CACjC;;;EA2DJ,CAAC;AAEV,eAAO,MAAM,UAAU,WACV,eAAe,eACJ;IAAE,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE;;;EAgBzC,CAAC;AAEV,eAAO,MAAM,iBAAiB,WACjB,eAAe,cAAc,eAAe,eACjC;IACZ,OAAO,EAAE;QAAE,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACpC,IAAI,EAAE,sBAAsB,CAAC,MAAM,CAAC,CAAC;CACxC;;;;;;;;EAiDA,CAAC;AAEV,eAAO,MAAM,kBAAkB,WAClB,eAAe,eACJ;IACZ,MAAM,EAAE,uBAAuB,CAAC,QAAQ,CAAC,CAAC;IAC1C,IAAI,EAAE,uBAAuB,CAAC,MAAM,CAAC,CAAC;CACzC;;;;;;;;EA2BA,CAAC"}
|
|
@@ -1,187 +1,192 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.changeUserPassword = exports.changeOwnPassword = exports.deleteUser = exports.updateUser = exports.getUserByEmail = exports.getUserById = exports.getUsers = void 0;
|
|
4
4
|
const auth_service_1 = require("../auth/auth.service");
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return [];
|
|
10
|
-
}
|
|
11
|
-
return (await keycloak.users.find());
|
|
5
|
+
const getUsers = async (server, authHeader) => {
|
|
6
|
+
const allowed = await server.auth.hasCapability("users.db_select", authHeader);
|
|
7
|
+
if (!allowed) {
|
|
8
|
+
return [];
|
|
12
9
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
const rm = await keycloak.users.listRealmRoleMappings({
|
|
22
|
-
id,
|
|
23
|
-
realm: keycloak.realmName
|
|
24
|
-
});
|
|
25
|
-
user.realmRoles = rm.map((r) => r.name).filter(Boolean);
|
|
26
|
-
return user;
|
|
10
|
+
return (await server.kc.users.find());
|
|
11
|
+
};
|
|
12
|
+
exports.getUsers = getUsers;
|
|
13
|
+
const getUserById = async (server, id, authHeader) => {
|
|
14
|
+
const allowed = await server.auth.hasCapability("users.db_select", authHeader);
|
|
15
|
+
if (!allowed) {
|
|
16
|
+
return null;
|
|
27
17
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
const users = (await keycloak.users.find());
|
|
33
|
-
const user = users.find((u) => u.email?.toLowerCase() === email.toLowerCase());
|
|
34
|
-
if (!user?.id) {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
const rm = await keycloak.users.listRealmRoleMappings({
|
|
38
|
-
id: user.id,
|
|
39
|
-
realm: keycloak.realmName
|
|
40
|
-
});
|
|
41
|
-
user.realmRoles = rm.map((r) => r.name).filter(Boolean);
|
|
42
|
-
return user;
|
|
18
|
+
const user = (await server.kc.users.findOne({ id }));
|
|
19
|
+
if (!user?.id) {
|
|
20
|
+
return null;
|
|
43
21
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
{
|
|
57
|
-
type: "password",
|
|
58
|
-
value: body.password,
|
|
59
|
-
temporary: false
|
|
60
|
-
}
|
|
61
|
-
];
|
|
62
|
-
const created = await keycloak.users.create({
|
|
63
|
-
...userData,
|
|
64
|
-
realm: keycloak.realmName
|
|
65
|
-
});
|
|
66
|
-
const allRoles = await keycloak.roles.find();
|
|
67
|
-
const hasuraRole = allRoles.find((role) => role.name === "authenticated-user");
|
|
68
|
-
const userRole = allRoles.find((role) => role.name === "user");
|
|
69
|
-
if (userRole && hasuraRole) {
|
|
70
|
-
await keycloak.users.addRealmRoleMappings({
|
|
71
|
-
id: created.id,
|
|
72
|
-
roles: [
|
|
73
|
-
{ id: hasuraRole.id, name: hasuraRole.name },
|
|
74
|
-
{ id: userRole.id, name: userRole.name }
|
|
75
|
-
],
|
|
76
|
-
realm: keycloak.realmName
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
await keycloak.users.update({ id }, userData);
|
|
82
|
-
}
|
|
83
|
-
return {
|
|
84
|
-
errors: false,
|
|
85
|
-
message: "User updated successfully"
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
catch (e) {
|
|
89
|
-
return {
|
|
90
|
-
errors: true,
|
|
91
|
-
message: e instanceof Error ? e.message : "Internal server error"
|
|
92
|
-
};
|
|
93
|
-
}
|
|
22
|
+
const roleMappings = await server.kc.users.listRealmRoleMappings({
|
|
23
|
+
id,
|
|
24
|
+
realm: server.kc.realmName
|
|
25
|
+
});
|
|
26
|
+
user.realmRoles = roleMappings.map((r) => r.name).filter(Boolean);
|
|
27
|
+
return user;
|
|
28
|
+
};
|
|
29
|
+
exports.getUserById = getUserById;
|
|
30
|
+
const getUserByEmail = async (server, email, authHeader) => {
|
|
31
|
+
const allowed = await server.auth.hasCapability("users.db_select", authHeader);
|
|
32
|
+
if (!allowed) {
|
|
33
|
+
return null;
|
|
94
34
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
errors: false,
|
|
100
|
-
message: "User deleted successfully"
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
catch (e) {
|
|
104
|
-
return {
|
|
105
|
-
errors: true,
|
|
106
|
-
message: e instanceof Error ? e.message : "Internal server error"
|
|
107
|
-
};
|
|
108
|
-
}
|
|
35
|
+
const users = (await server.kc.users.find());
|
|
36
|
+
const user = users.find((u) => u.email?.toLowerCase() === email.toLowerCase());
|
|
37
|
+
if (!user?.id) {
|
|
38
|
+
return null;
|
|
109
39
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
message: "Current password is incorrect"
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
await keycloak.users.resetPassword({
|
|
137
|
-
id: userId,
|
|
138
|
-
realm: keycloak.realmName,
|
|
139
|
-
credential: {
|
|
40
|
+
const roleMappings = await server.kc.users.listRealmRoleMappings({
|
|
41
|
+
id: user.id,
|
|
42
|
+
realm: server.kc.realmName
|
|
43
|
+
});
|
|
44
|
+
user.realmRoles = roleMappings.map((r) => r.name).filter(Boolean);
|
|
45
|
+
return user;
|
|
46
|
+
};
|
|
47
|
+
exports.getUserByEmail = getUserByEmail;
|
|
48
|
+
const updateUser = (server) => async (request) => {
|
|
49
|
+
try {
|
|
50
|
+
const { id } = request.params;
|
|
51
|
+
const body = request.body;
|
|
52
|
+
const userData = {
|
|
53
|
+
firstName: body.firstName,
|
|
54
|
+
lastName: body.lastName,
|
|
55
|
+
email: body.email,
|
|
56
|
+
username: body.email,
|
|
57
|
+
enabled: body.enabled,
|
|
58
|
+
emailVerified: true
|
|
59
|
+
};
|
|
60
|
+
if (id === "new") {
|
|
61
|
+
userData.credentials = [
|
|
62
|
+
{
|
|
140
63
|
type: "password",
|
|
141
|
-
value:
|
|
64
|
+
value: body.password,
|
|
142
65
|
temporary: false
|
|
143
66
|
}
|
|
67
|
+
];
|
|
68
|
+
const created = await server.kc.users.create({
|
|
69
|
+
...userData,
|
|
70
|
+
realm: server.kc.realmName
|
|
144
71
|
});
|
|
145
|
-
|
|
72
|
+
const allRoles = await server.kc.roles.find();
|
|
73
|
+
const hasuraRole = allRoles.find((role) => role.name === "authenticated-user");
|
|
74
|
+
const userRole = allRoles.find((role) => role.name === "user");
|
|
75
|
+
if (userRole && hasuraRole) {
|
|
76
|
+
await server.kc.users.addRealmRoleMappings({
|
|
77
|
+
id: created.id,
|
|
78
|
+
roles: [
|
|
79
|
+
{ id: hasuraRole.id, name: hasuraRole.name },
|
|
80
|
+
{ id: userRole.id, name: userRole.name }
|
|
81
|
+
],
|
|
82
|
+
realm: server.kc.realmName
|
|
83
|
+
});
|
|
84
|
+
}
|
|
146
85
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
ok: false,
|
|
150
|
-
statusCode: 500,
|
|
151
|
-
message: "Internal server error"
|
|
152
|
-
};
|
|
86
|
+
else {
|
|
87
|
+
await server.kc.users.update({ id }, userData);
|
|
153
88
|
}
|
|
89
|
+
return {
|
|
90
|
+
errors: false,
|
|
91
|
+
message: "User updated successfully"
|
|
92
|
+
};
|
|
154
93
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
94
|
+
catch (e) {
|
|
95
|
+
return {
|
|
96
|
+
errors: true,
|
|
97
|
+
message: e instanceof Error ? e.message : "Internal server error"
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
exports.updateUser = updateUser;
|
|
102
|
+
const deleteUser = (server) => async (request) => {
|
|
103
|
+
try {
|
|
104
|
+
const { id } = request.params;
|
|
105
|
+
await server.kc.users.del({ id });
|
|
106
|
+
return {
|
|
107
|
+
errors: false,
|
|
108
|
+
message: "User deleted successfully"
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
catch (e) {
|
|
112
|
+
return {
|
|
113
|
+
errors: true,
|
|
114
|
+
message: e instanceof Error ? e.message : "Internal server error"
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
exports.deleteUser = deleteUser;
|
|
119
|
+
const changeOwnPassword = (server, authConfig) => async (request) => {
|
|
120
|
+
try {
|
|
121
|
+
const decoded = server.auth.getDecodedToken(request.headers.authorization);
|
|
122
|
+
const userId = decoded?.sub ?? "";
|
|
123
|
+
const { currentPassword, newPassword } = request.body;
|
|
124
|
+
const tokens = await (0, auth_service_1.kcTokenHandle)({
|
|
125
|
+
authUrl: authConfig.authUrl,
|
|
126
|
+
formData: new URLSearchParams({
|
|
127
|
+
client_id: authConfig.clientId,
|
|
128
|
+
client_secret: authConfig.clientSecret,
|
|
129
|
+
grant_type: "password",
|
|
130
|
+
username: decoded?.preferred_username ?? "",
|
|
131
|
+
password: currentPassword
|
|
132
|
+
}),
|
|
133
|
+
withSessionStorage: false
|
|
134
|
+
});
|
|
135
|
+
if (!tokens) {
|
|
169
136
|
return {
|
|
170
137
|
ok: false,
|
|
171
|
-
statusCode:
|
|
172
|
-
message: "
|
|
138
|
+
statusCode: 400,
|
|
139
|
+
message: "Current password is incorrect"
|
|
173
140
|
};
|
|
174
141
|
}
|
|
142
|
+
await server.kc.users.resetPassword({
|
|
143
|
+
id: userId,
|
|
144
|
+
realm: server.kc.realmName,
|
|
145
|
+
credential: {
|
|
146
|
+
type: "password",
|
|
147
|
+
value: newPassword,
|
|
148
|
+
temporary: false
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
return {
|
|
152
|
+
ok: true
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
catch (e) {
|
|
156
|
+
console.error("Password change error", e);
|
|
157
|
+
return {
|
|
158
|
+
ok: false,
|
|
159
|
+
statusCode: 500,
|
|
160
|
+
message: "Internal server error"
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
exports.changeOwnPassword = changeOwnPassword;
|
|
165
|
+
const changeUserPassword = (server) => async (request) => {
|
|
166
|
+
try {
|
|
167
|
+
const { id: userId } = request.params;
|
|
168
|
+
const { password } = request.body;
|
|
169
|
+
await server.kc.users.resetPassword({
|
|
170
|
+
id: userId,
|
|
171
|
+
realm: server.kc.realmName,
|
|
172
|
+
credential: {
|
|
173
|
+
type: "password",
|
|
174
|
+
value: password,
|
|
175
|
+
temporary: false
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
return {
|
|
179
|
+
ok: true
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
catch (e) {
|
|
183
|
+
console.error("Password change error", e);
|
|
184
|
+
return {
|
|
185
|
+
ok: false,
|
|
186
|
+
statusCode: 500,
|
|
187
|
+
message: "Internal server error"
|
|
188
|
+
};
|
|
175
189
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
getUserById,
|
|
179
|
-
getUserByEmail,
|
|
180
|
-
saveUser,
|
|
181
|
-
deleteUser,
|
|
182
|
-
changeOwnPassword,
|
|
183
|
-
changeUserPassword
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
exports.createUsersService = createUsersService;
|
|
190
|
+
};
|
|
191
|
+
exports.changeUserPassword = changeUserPassword;
|
|
187
192
|
//# sourceMappingURL=users.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"users.service.js","sourceRoot":"","sources":["../../src/users/users.service.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"users.service.js","sourceRoot":"","sources":["../../src/users/users.service.ts"],"names":[],"mappings":";;;AAEA,uDAAqD;AAU9C,MAAM,QAAQ,GAAG,KAAK,EACzB,MAAuB,EACvB,UAAmB,EACJ,EAAE;IACjB,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC;IAE/E,IAAI,CAAC,OAAO,EAAE;QACV,OAAO,EAAE,CAAC;KACb;IAED,OAAO,CAAC,MAAM,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAW,CAAC;AACpD,CAAC,CAAC;AAXW,QAAA,QAAQ,YAWnB;AAEK,MAAM,WAAW,GAAG,KAAK,EAC5B,MAAuB,EACvB,EAAU,EACV,UAAmB,EACS,EAAE;IAC9B,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC;IAE/E,IAAI,CAAC,OAAO,EAAE;QACV,OAAO,IAAI,CAAC;KACf;IAED,MAAM,IAAI,GAAG,CAAC,MAAM,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAgB,CAAC;IAEpE,IAAI,CAAC,IAAI,EA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|
|
@@ -42,70 +41,13 @@ export type UserOrderByInput = {
|
|
|
42
41
|
key: UserOrderField;
|
|
43
42
|
direction?: SortDirection;
|
|
44
43
|
};
|
|
45
|
-
export interface
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
export interface UsersAuthConfig {
|
|
45
|
+
authUrl: string;
|
|
46
|
+
clientId: string;
|
|
47
|
+
clientSecret: string;
|
|
49
48
|
}
|
|
50
|
-
export interface AuthAdapter {
|
|
51
|
-
hasCapability(capability: string, authHeader?: string): boolean;
|
|
52
|
-
getDecodedToken(authHeader?: string): DecodedToken | null;
|
|
53
|
-
}
|
|
54
|
-
export interface KeycloakRole {
|
|
55
|
-
id?: string;
|
|
56
|
-
name?: string;
|
|
57
|
-
}
|
|
58
|
-
export interface KeycloakUserApi {
|
|
59
|
-
find(): Promise<unknown[]>;
|
|
60
|
-
findOne(params: {
|
|
61
|
-
id: string;
|
|
62
|
-
}): Promise<unknown | null>;
|
|
63
|
-
create(data: Record<string, unknown>): Promise<{
|
|
64
|
-
id: string;
|
|
65
|
-
}>;
|
|
66
|
-
update(params: {
|
|
67
|
-
id: string;
|
|
68
|
-
}, data: Record<string, unknown>): Promise<void>;
|
|
69
|
-
del(params: {
|
|
70
|
-
id: string;
|
|
71
|
-
}): Promise<void>;
|
|
72
|
-
resetPassword(params: {
|
|
73
|
-
id: string;
|
|
74
|
-
realm: string;
|
|
75
|
-
credential: {
|
|
76
|
-
type: string;
|
|
77
|
-
value: string;
|
|
78
|
-
temporary: boolean;
|
|
79
|
-
};
|
|
80
|
-
}): Promise<void>;
|
|
81
|
-
listRealmRoleMappings(params: {
|
|
82
|
-
id: string;
|
|
83
|
-
realm: string;
|
|
84
|
-
}): Promise<KeycloakRole[]>;
|
|
85
|
-
addRealmRoleMappings(params: {
|
|
86
|
-
id: string;
|
|
87
|
-
realm: string;
|
|
88
|
-
roles: KeycloakRole[];
|
|
89
|
-
}): Promise<void>;
|
|
90
|
-
}
|
|
91
|
-
export interface KeycloakRolesApi {
|
|
92
|
-
find(): Promise<KeycloakRole[]>;
|
|
93
|
-
}
|
|
94
|
-
export interface KeycloakAdapter {
|
|
95
|
-
realmName: string;
|
|
96
|
-
users: KeycloakUserApi;
|
|
97
|
-
roles: KeycloakRolesApi;
|
|
98
|
-
}
|
|
99
|
-
export type HttpResponseHandler = (reply: FastifyReply, statusCode: number, message: string) => unknown;
|
|
100
49
|
export interface UsersPluginOptions {
|
|
101
|
-
|
|
102
|
-
auth: AuthAdapter;
|
|
103
|
-
httpResponse: HttpResponseHandler;
|
|
104
|
-
authConfig: {
|
|
105
|
-
authUrl: string;
|
|
106
|
-
clientId: string;
|
|
107
|
-
clientSecret: string;
|
|
108
|
-
};
|
|
50
|
+
authConfig: UsersAuthConfig;
|
|
109
51
|
graphql?: {
|
|
110
52
|
enabled?: boolean;
|
|
111
53
|
path?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"users.types.d.ts","sourceRoot":"","sources":["../../src/users/users.types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"users.types.d.ts","sourceRoot":"","sources":["../../src/users/users.types.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,gBAAgB,GAAG;IAC3B,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,gBAAgB,GAAG;IACrD,IAAI,EAAE;QACF,QAAQ,EAAE,MAAM,CAAC;KACpB,CAAC;CACL,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACjC,IAAI,EAAE;QACF,eAAe,EAAE,MAAM,CAAC;QACxB,WAAW,EAAE,MAAM,CAAC;KACvB,CAAC;CACL,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,gBAAgB,GAAG;IAC7C,IAAI,EAAE;QACF,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,KAAK,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I,EAAE,MAAM,UAenD"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dateFormat = void 0;
|
|
4
|
+
function dateFormat(date, fstr) {
|
|
5
|
+
return fstr.replace(/%[YmdHMS]/g, (m) => {
|
|
6
|
+
let c = 0;
|
|
7
|
+
switch (m) {
|
|
8
|
+
case '%Y': return date.getFullYear().toString(); // no leading zeros required
|
|
9
|
+
case '%m':
|
|
10
|
+
c = 1 + date.getMonth();
|
|
11
|
+
break;
|
|
12
|
+
case '%d':
|
|
13
|
+
c = date.getDate();
|
|
14
|
+
break;
|
|
15
|
+
case '%H':
|
|
16
|
+
c = date.getHours();
|
|
17
|
+
break;
|
|
18
|
+
case '%M':
|
|
19
|
+
c = date.getMinutes();
|
|
20
|
+
break;
|
|
21
|
+
case '%S':
|
|
22
|
+
c = date.getSeconds();
|
|
23
|
+
break;
|
|
24
|
+
default: return m.slice(1); // unknown code, remove %
|
|
25
|
+
}
|
|
26
|
+
// add leading zero if required
|
|
27
|
+
return c.toString().padStart(2, '0');
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
exports.dateFormat = dateFormat;
|
|
31
|
+
//# sourceMappingURL=date-utility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-utility.js","sourceRoot":"","sources":["../../src/utils/date-utility.ts"],"names":[],"mappings":";;;AAAA,SAAgB,UAAU,CAAE,IAAU,EAAE,IAAY;IAClD,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC,EAAE,EAAE;QACtC,IAAI,CAAC,GAAG,CAAC,CAAA;QACT,QAAQ,CAAC,EAAE;YACT,KAAK,IAAI,CAAC,CAAC,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,QAAQ,EAAE,CAAA,CAAC,4BAA4B;YAC5E,KAAK,IAAI;gBAAE,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;gBAAC,MAAK;YACzC,KAAK,IAAI;gBAAE,CAAC,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;gBAAC,MAAK;YACpC,KAAK,IAAI;gBAAE,CAAC,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;gBAAC,MAAK;YACrC,KAAK,IAAI;gBAAE,CAAC,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;gBAAC,MAAK;YACvC,KAAK,IAAI;gBAAE,CAAC,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;gBAAC,MAAK;YACvC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA,CAAC,yBAAyB;SACrD;QACD,+BAA+B;QAC/B,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IACtC,CAAC,CAAC,CAAA;AACJ,CAAC;AAfD,gCAeC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface EmailConfig {
|
|
2
|
+
smtp: {
|
|
3
|
+
host: string;
|
|
4
|
+
port: number;
|
|
5
|
+
secure: boolean;
|
|
6
|
+
auth: {
|
|
7
|
+
user: string;
|
|
8
|
+
pass: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
data: {
|
|
12
|
+
from: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export declare const sendEmail: (params: EmailParams, emailConfig: EmailConfig) => Promise<boolean>;
|
|
16
|
+
export type EmailParams = {
|
|
17
|
+
to: string;
|
|
18
|
+
subject: string;
|
|
19
|
+
html: string;
|
|
20
|
+
attachments?: {
|
|
21
|
+
filename: string;
|
|
22
|
+
path: string;
|
|
23
|
+
contentType: string;
|
|
24
|
+
}[];
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=email.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email.d.ts","sourceRoot":"","sources":["../../src/utils/email.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,OAAO,CAAC;QAChB,IAAI,EAAE;YACJ,IAAI,EAAE,MAAM,CAAC;YACb,IAAI,EAAE,MAAM,CAAC;SACd,CAAC;KACH,CAAC;IACF,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH;AAED,eAAO,MAAM,SAAS,WAAY,WAAW,eAAe,WAAW,KAAG,QAAQ,OAAO,CA4BxF,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CACxE,CAAA"}
|
|
@@ -0,0 +1,56 @@
|
|
|
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 (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.sendEmail = void 0;
|
|
27
|
+
const nodemailer = __importStar(require("nodemailer"));
|
|
28
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
29
|
+
const sendEmail = (params, emailConfig) => {
|
|
30
|
+
// create reusable transporter object using the default SMTP transport
|
|
31
|
+
const transporter = nodemailer.createTransport(emailConfig.smtp);
|
|
32
|
+
const defaultData = emailConfig.data;
|
|
33
|
+
console.log(params.html);
|
|
34
|
+
const mailOptions = {
|
|
35
|
+
from: defaultData.from,
|
|
36
|
+
to: params.to,
|
|
37
|
+
subject: params.subject,
|
|
38
|
+
html: params.html,
|
|
39
|
+
attachments: params.attachments
|
|
40
|
+
};
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
transporter.sendMail(mailOptions, (error, info) => {
|
|
43
|
+
if (error && process.env.NODE_ENV === 'production') {
|
|
44
|
+
console.log(error);
|
|
45
|
+
reject(error.message);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
console.log('Message sent: %s', info?.messageId);
|
|
49
|
+
// Preview only available when sending through an Ethereal account
|
|
50
|
+
console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
|
|
51
|
+
resolve(true);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
exports.sendEmail = sendEmail;
|
|
56
|
+
//# sourceMappingURL=email.js.map
|
|
@@ -0,0 +1 @@
|
|
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f,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AA5BY,QAAA,SAAS,aA4BrB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-utils.d.ts","sourceRoot":"","sources":["../../src/utils/http-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAUtC,wBAAgB,YAAY,CAAC,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,QAMpF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.httpResponse = void 0;
|
|
4
|
+
const errorCodes = {
|
|
5
|
+
400: 'Bad Request',
|
|
6
|
+
401: 'Unauthorized',
|
|
7
|
+
403: 'Forbidden',
|
|
8
|
+
500: 'API Failure'
|
|
9
|
+
};
|
|
10
|
+
function httpResponse(reply, statusCode, message) {
|
|
11
|
+
reply.code(statusCode).send({
|
|
12
|
+
statusCode: statusCode,
|
|
13
|
+
error: errorCodes[statusCode] ?? statusCode,
|
|
14
|
+
message: message
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
exports.httpResponse = httpResponse;
|
|
18
|
+
//# sourceMappingURL=http-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-utils.js","sourceRoot":"","sources":["../../src/utils/http-utils.ts"],"names":[],"mappings":";;;AAEA,MAAM,UAAU,GAAG;IACf,GAAG,EAAE,aAAa;IAClB,GAAG,EAAE,cAAc;IACnB,GAAG,EAAE,WAAW;IAChB,GAAG,EAAE,aAAa;CACrB,CAAA;AAGD,SAAgB,YAAY,CAAC,KAAmB,EAAE,UAAkB,EAAE,OAAe;IACjF,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC;QACxB,UAAU,EAAE,UAAU;QACtB,KAAK,EAAE,UAAU,CAAC,UAAmC,CAAC,IAAI,UAAU;QACpE,OAAO,EAAE,OAAO;KACnB,CAAC,CAAA;AACN,CAAC;AAND,oCAMC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./date-utility"), exports);
|
|
18
|
+
__exportStar(require("./http-utils"), exports);
|
|
19
|
+
__exportStar(require("./email"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,+CAA6B;AAC7B,0CAAwB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inobeta/api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Shared backend library for Inobeta projects",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -26,21 +26,24 @@
|
|
|
26
26
|
"@keycloak/keycloak-admin-client": "^26.3.5",
|
|
27
27
|
"@types/jsonwebtoken": "^9.0.10",
|
|
28
28
|
"@types/node": "^25.5.0",
|
|
29
|
+
"@types/nodemailer": "^7.0.11",
|
|
29
30
|
"fastify": "^5.6.0",
|
|
30
31
|
"fastify-plugin": "^5.1.0",
|
|
31
32
|
"jsonwebtoken": "^9.0.3",
|
|
32
33
|
"knex": "^2.3.0",
|
|
33
34
|
"mercurius": "^16.8.0",
|
|
35
|
+
"nodemailer": "^6.7.2",
|
|
34
36
|
"rimraf": "^6.1.3",
|
|
35
37
|
"typescript": "^5.2.2"
|
|
36
38
|
},
|
|
37
39
|
"peerDependencies": {
|
|
40
|
+
"@keycloak/keycloak-admin-client": "^26.3.5",
|
|
38
41
|
"fastify": "^5.6.0",
|
|
42
|
+
"fastify-plugin": "^5.0.1",
|
|
43
|
+
"jsonwebtoken": "^9.0.0",
|
|
39
44
|
"knex": "^2.3.0",
|
|
40
45
|
"mercurius": "^16.0.0",
|
|
41
|
-
"
|
|
42
|
-
"fastify-plugin": "^5.0.1",
|
|
43
|
-
"jsonwebtoken": "^9.0.0"
|
|
46
|
+
"nodemailer": "^6.7.2"
|
|
44
47
|
},
|
|
45
48
|
"engines": {
|
|
46
49
|
"node": ">=20"
|