@medusajs/user 0.0.4 → 1.0.0-rc-20241001083650

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. package/dist/index.d.ts +6 -5
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +6 -21
  4. package/dist/index.js.map +1 -0
  5. package/dist/migrations/Migration20240214033943.d.ts +1 -0
  6. package/dist/migrations/Migration20240214033943.d.ts.map +1 -0
  7. package/dist/migrations/Migration20240214033943.js +2 -1
  8. package/dist/migrations/Migration20240214033943.js.map +1 -0
  9. package/dist/migrations/Migration20240703095850.d.ts +6 -0
  10. package/dist/migrations/Migration20240703095850.d.ts.map +1 -0
  11. package/dist/migrations/Migration20240703095850.js +17 -0
  12. package/dist/migrations/Migration20240703095850.js.map +1 -0
  13. package/dist/models/index.d.ts +1 -0
  14. package/dist/models/index.d.ts.map +1 -0
  15. package/dist/models/index.js +1 -0
  16. package/dist/models/index.js.map +1 -0
  17. package/dist/models/invite.d.ts +3 -2
  18. package/dist/models/invite.d.ts.map +1 -0
  19. package/dist/models/invite.js +2 -1
  20. package/dist/models/invite.js.map +1 -0
  21. package/dist/models/user.d.ts +3 -2
  22. package/dist/models/user.d.ts.map +1 -0
  23. package/dist/models/user.js +5 -6
  24. package/dist/models/user.js.map +1 -0
  25. package/dist/services/index.d.ts +1 -1
  26. package/dist/services/index.d.ts.map +1 -0
  27. package/dist/services/index.js +2 -3
  28. package/dist/services/index.js.map +1 -0
  29. package/dist/services/user-module.d.ts +21 -16
  30. package/dist/services/user-module.d.ts.map +1 -0
  31. package/dist/services/user-module.js +106 -59
  32. package/dist/services/user-module.js.map +1 -0
  33. package/dist/tsconfig.tsbuildinfo +1 -0
  34. package/dist/types/index.d.ts +2 -1
  35. package/dist/types/index.d.ts.map +1 -0
  36. package/dist/types/index.js +1 -0
  37. package/dist/types/index.js.map +1 -0
  38. package/dist/types/services/index.d.ts +1 -0
  39. package/dist/types/services/index.d.ts.map +1 -0
  40. package/dist/types/services/index.js +1 -0
  41. package/dist/types/services/index.js.map +1 -0
  42. package/dist/types/services/invite.d.ts +1 -0
  43. package/dist/types/services/invite.d.ts.map +1 -0
  44. package/dist/types/services/invite.js +1 -0
  45. package/dist/types/services/invite.js.map +1 -0
  46. package/package.json +22 -21
  47. package/dist/initialize/index.d.ts +0 -3
  48. package/dist/initialize/index.js +0 -16
  49. package/dist/joiner-config.d.ts +0 -8
  50. package/dist/joiner-config.js +0 -38
  51. package/dist/loaders/connection.d.ts +0 -4
  52. package/dist/loaders/connection.js +0 -41
  53. package/dist/loaders/container.d.ts +0 -2
  54. package/dist/loaders/container.js +0 -34
  55. package/dist/loaders/index.d.ts +0 -2
  56. package/dist/loaders/index.js +0 -18
  57. package/dist/module-definition.d.ts +0 -4
  58. package/dist/module-definition.js +0 -50
  59. package/dist/repositories/index.d.ts +0 -1
  60. package/dist/repositories/index.js +0 -5
  61. package/dist/scripts/bin/run-seed.d.ts +0 -3
  62. package/dist/scripts/bin/run-seed.js +0 -38
  63. package/dist/scripts/seed.d.ts +0 -4
  64. package/dist/scripts/seed.js +0 -54
  65. package/dist/services/invite.d.ts +0 -25
  66. package/dist/services/invite.js +0 -140
@@ -1,140 +0,0 @@
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 __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
- 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
- return c > 3 && r && Object.defineProperty(target, key, r), r;
23
- };
24
- var __importStar = (this && this.__importStar) || function (mod) {
25
- if (mod && mod.__esModule) return mod;
26
- var result = {};
27
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
- __setModuleDefault(result, mod);
29
- return result;
30
- };
31
- var __metadata = (this && this.__metadata) || function (k, v) {
32
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
33
- };
34
- var __importDefault = (this && this.__importDefault) || function (mod) {
35
- return (mod && mod.__esModule) ? mod : { "default": mod };
36
- };
37
- Object.defineProperty(exports, "__esModule", { value: true });
38
- const crypto = __importStar(require("crypto"));
39
- const utils_1 = require("@medusajs/utils");
40
- const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
41
- const _models_1 = require("../models");
42
- // 1 day
43
- const DEFAULT_VALID_INVITE_DURATION = 60 * 60 * 24 * 1000;
44
- class InviteService extends utils_1.ModulesSdkUtils.internalModuleServiceFactory(_models_1.Invite) {
45
- constructor(container) {
46
- super(container);
47
- this.inviteRepository_ = container.inviteRepository;
48
- }
49
- withModuleOptions(options) {
50
- const service = new InviteService(this.__container__);
51
- service.options_ = options;
52
- return service;
53
- }
54
- getOption(key) {
55
- if (!this.options_) {
56
- throw new utils_1.MedusaError(utils_1.MedusaError.Types.UNEXPECTED_STATE, `Options are not configured for InviteService, call "withModuleOptions" and provide options`);
57
- }
58
- return this.options_[key];
59
- }
60
- async create(data, context = {}) {
61
- const data_ = Array.isArray(data) ? data : [data];
62
- const invites = await super.create(data_, context);
63
- const expiresIn = this.getValidDuration();
64
- const updates = invites.map((invite) => {
65
- return {
66
- id: invite.id,
67
- expires_at: new Date().setMilliseconds(new Date().getMilliseconds() + expiresIn),
68
- token: this.generateToken({ id: invite.id }),
69
- };
70
- });
71
- return await super.update(updates, context);
72
- }
73
- async refreshInviteTokens(inviteIds, context = {}) {
74
- const [invites, count] = await super.listAndCount({ id: inviteIds }, {}, context);
75
- if (count !== inviteIds.length) {
76
- const missing = (0, utils_1.arrayDifference)(inviteIds, invites.map((invite) => invite.id));
77
- if (missing.length > 0) {
78
- throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `The following invites do not exist: ${missing.join(", ")}`);
79
- }
80
- }
81
- const expiresIn = this.getValidDuration();
82
- const updates = invites.map((invite) => {
83
- return {
84
- id: invite.id,
85
- expires_at: new Date().setMilliseconds(new Date().getMilliseconds() + expiresIn),
86
- token: this.generateToken({ id: invite.id }),
87
- };
88
- });
89
- return await super.update(updates, context);
90
- }
91
- async validateInviteToken(token, context) {
92
- const decoded = this.validateToken(token);
93
- const invite = await super.retrieve(decoded.payload.id, {}, context);
94
- if (invite.expires_at < new Date()) {
95
- throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "The invite has expired");
96
- }
97
- return invite;
98
- }
99
- generateToken(data) {
100
- const jwtSecret = this.getOption("jwt_secret");
101
- const expiresIn = this.getValidDuration() / 1000;
102
- if (!jwtSecret) {
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.");
104
- }
105
- return jsonwebtoken_1.default.sign(data, jwtSecret, {
106
- jwtid: crypto.randomUUID(),
107
- expiresIn,
108
- });
109
- }
110
- getValidDuration() {
111
- return (parseInt(this.getOption("valid_duration")) ||
112
- DEFAULT_VALID_INVITE_DURATION);
113
- }
114
- validateToken(data) {
115
- const jwtSecret = this.getOption("jwt_secret");
116
- if (!jwtSecret) {
117
- throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "No jwt_secret was provided in the UserModule's options. Please add one.");
118
- }
119
- return jsonwebtoken_1.default.verify(data, jwtSecret, { complete: true });
120
- }
121
- }
122
- exports.default = InviteService;
123
- __decorate([
124
- (0, utils_1.InjectTransactionManager)("inviteRepository_"),
125
- __metadata("design:type", Function),
126
- __metadata("design:paramtypes", [Object, Object]),
127
- __metadata("design:returntype", Promise)
128
- ], InviteService.prototype, "create", null);
129
- __decorate([
130
- (0, utils_1.InjectTransactionManager)("inviteRepository_"),
131
- __metadata("design:type", Function),
132
- __metadata("design:paramtypes", [Array, Object]),
133
- __metadata("design:returntype", Promise)
134
- ], InviteService.prototype, "refreshInviteTokens", null);
135
- __decorate([
136
- (0, utils_1.InjectTransactionManager)("inviteRepository_"),
137
- __metadata("design:type", Function),
138
- __metadata("design:paramtypes", [String, Object]),
139
- __metadata("design:returntype", Promise)
140
- ], InviteService.prototype, "validateInviteToken", null);