@medusajs/user 0.0.2 → 0.0.3-next-20240321131229
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.
|
File without changes
|
|
@@ -19,6 +19,7 @@ export default class InviteService<TEntity extends Invite = Invite> extends Invi
|
|
|
19
19
|
refreshInviteTokens(inviteIds: string[], context?: Context): Promise<TEntity[]>;
|
|
20
20
|
validateInviteToken(token: string, context?: Context): Promise<TEntity>;
|
|
21
21
|
private generateToken;
|
|
22
|
+
private getValidDuration;
|
|
22
23
|
private validateToken;
|
|
23
24
|
}
|
|
24
25
|
export {};
|
package/dist/services/invite.js
CHANGED
|
@@ -40,7 +40,7 @@ const utils_1 = require("@medusajs/utils");
|
|
|
40
40
|
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
41
41
|
const _models_1 = require("../models");
|
|
42
42
|
// 1 day
|
|
43
|
-
const DEFAULT_VALID_INVITE_DURATION = 60 * 60 * 24;
|
|
43
|
+
const DEFAULT_VALID_INVITE_DURATION = 60 * 60 * 24 * 1000;
|
|
44
44
|
class InviteService extends utils_1.ModulesSdkUtils.internalModuleServiceFactory(_models_1.Invite) {
|
|
45
45
|
constructor(container) {
|
|
46
46
|
super(container);
|
|
@@ -60,8 +60,7 @@ class InviteService extends utils_1.ModulesSdkUtils.internalModuleServiceFactory
|
|
|
60
60
|
async create(data, context = {}) {
|
|
61
61
|
const data_ = Array.isArray(data) ? data : [data];
|
|
62
62
|
const invites = await super.create(data_, context);
|
|
63
|
-
const expiresIn =
|
|
64
|
-
DEFAULT_VALID_INVITE_DURATION;
|
|
63
|
+
const expiresIn = this.getValidDuration();
|
|
65
64
|
const updates = invites.map((invite) => {
|
|
66
65
|
return {
|
|
67
66
|
id: invite.id,
|
|
@@ -79,8 +78,7 @@ class InviteService extends utils_1.ModulesSdkUtils.internalModuleServiceFactory
|
|
|
79
78
|
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `The following invites do not exist: ${missing.join(", ")}`);
|
|
80
79
|
}
|
|
81
80
|
}
|
|
82
|
-
const expiresIn =
|
|
83
|
-
DEFAULT_VALID_INVITE_DURATION;
|
|
81
|
+
const expiresIn = this.getValidDuration();
|
|
84
82
|
const updates = invites.map((invite) => {
|
|
85
83
|
return {
|
|
86
84
|
id: invite.id,
|
|
@@ -100,16 +98,19 @@ class InviteService extends utils_1.ModulesSdkUtils.internalModuleServiceFactory
|
|
|
100
98
|
}
|
|
101
99
|
generateToken(data) {
|
|
102
100
|
const jwtSecret = this.getOption("jwt_secret");
|
|
103
|
-
const expiresIn =
|
|
104
|
-
DEFAULT_VALID_INVITE_DURATION;
|
|
101
|
+
const expiresIn = this.getValidDuration() / 1000;
|
|
105
102
|
if (!jwtSecret) {
|
|
106
103
|
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "No jwt_secret was provided in the UserModule's options. Please add one.");
|
|
107
104
|
}
|
|
108
105
|
return jsonwebtoken_1.default.sign(data, jwtSecret, {
|
|
109
|
-
expiresIn,
|
|
110
106
|
jwtid: crypto.randomUUID(),
|
|
107
|
+
expiresIn,
|
|
111
108
|
});
|
|
112
109
|
}
|
|
110
|
+
getValidDuration() {
|
|
111
|
+
return (parseInt(this.getOption("valid_duration")) ||
|
|
112
|
+
DEFAULT_VALID_INVITE_DURATION);
|
|
113
|
+
}
|
|
113
114
|
validateToken(data) {
|
|
114
115
|
const jwtSecret = this.getOption("jwt_secret");
|
|
115
116
|
if (!jwtSecret) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medusajs/user",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3-next-20240321131229",
|
|
4
4
|
"description": "Medusa Users module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@mikro-orm/cli": "5.9.7",
|
|
41
41
|
"cross-env": "^5.2.1",
|
|
42
42
|
"jest": "^29.6.3",
|
|
43
|
-
"medusa-test-utils": "
|
|
43
|
+
"medusa-test-utils": "1.1.43-next-20240321131229",
|
|
44
44
|
"rimraf": "^3.0.2",
|
|
45
45
|
"ts-jest": "^29.1.1",
|
|
46
46
|
"ts-node": "^10.9.1",
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
"typescript": "^5.1.6"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@medusajs/modules-sdk": "
|
|
52
|
-
"@medusajs/types": "
|
|
53
|
-
"@medusajs/utils": "
|
|
51
|
+
"@medusajs/modules-sdk": "1.12.10-next-20240321131229",
|
|
52
|
+
"@medusajs/types": "1.12.0-next-20240321131229",
|
|
53
|
+
"@medusajs/utils": "1.11.8-next-20240321131229",
|
|
54
54
|
"@mikro-orm/core": "5.9.7",
|
|
55
55
|
"@mikro-orm/migrations": "5.9.7",
|
|
56
56
|
"@mikro-orm/postgresql": "5.9.7",
|