@medusajs/user 0.0.4 → 1.0.0-rc-20241003153304

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 +27 -26
  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
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { moduleDefinition, revertMigration, runMigrations } from "./module-definition";
2
- export default moduleDefinition;
3
- export { revertMigration, runMigrations };
4
- export * from "./initialize";
5
- export * from "./loaders";
1
+ import { UserModuleService } from "./services";
2
+ declare const _default: import("@medusajs/types").ModuleExports<typeof UserModuleService> & {
3
+ linkable: Record<string, any>;
4
+ };
5
+ export default _default;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;;;;AAG7C,wBAEE"}
package/dist/index.js CHANGED
@@ -1,23 +1,8 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.runMigrations = exports.revertMigration = void 0;
18
- const module_definition_1 = require("./module-definition");
19
- Object.defineProperty(exports, "revertMigration", { enumerable: true, get: function () { return module_definition_1.revertMigration; } });
20
- Object.defineProperty(exports, "runMigrations", { enumerable: true, get: function () { return module_definition_1.runMigrations; } });
21
- exports.default = module_definition_1.moduleDefinition;
22
- __exportStar(require("./initialize"), exports);
23
- __exportStar(require("./loaders"), exports);
3
+ const _services_1 = require("./services");
4
+ const utils_1 = require("@medusajs/framework/utils");
5
+ exports.default = (0, utils_1.Module)(utils_1.Modules.USER, {
6
+ service: _services_1.UserModuleService,
7
+ });
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,yCAA6C;AAC7C,qDAA2D;AAE3D,kBAAe,IAAA,cAAM,EAAC,eAAO,CAAC,IAAI,EAAE;IAClC,OAAO,EAAE,6BAAiB;CAC3B,CAAC,CAAA"}
@@ -3,3 +3,4 @@ export declare class Migration20240214033943 extends Migration {
3
3
  up(): Promise<void>;
4
4
  down(): Promise<void>;
5
5
  }
6
+ //# sourceMappingURL=Migration20240214033943.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Migration20240214033943.d.ts","sourceRoot":"","sources":["../../src/migrations/Migration20240214033943.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEjD,qBAAa,uBAAwB,SAAQ,SAAS;IAC9C,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;IA2CnB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAK5B"}
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Migration20240214033943 = void 0;
4
- const utils_1 = require("@medusajs/utils");
4
+ const utils_1 = require("@medusajs/framework/utils");
5
5
  const migrations_1 = require("@mikro-orm/migrations");
6
6
  class Migration20240214033943 extends migrations_1.Migration {
7
7
  async up() {
@@ -22,3 +22,4 @@ class Migration20240214033943 extends migrations_1.Migration {
22
22
  }
23
23
  }
24
24
  exports.Migration20240214033943 = Migration20240214033943;
25
+ //# sourceMappingURL=Migration20240214033943.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Migration20240214033943.js","sourceRoot":"","sources":["../../src/migrations/Migration20240214033943.ts"],"names":[],"mappings":";;;AAAA,qDAAwF;AACxF,sDAAiD;AAEjD,MAAa,uBAAwB,SAAQ,sBAAS;IACpD,KAAK,CAAC,EAAE;QACN,IAAI,CAAC,MAAM,CACT,4XAA4X,CAC7X,CAAA;QACD,IAAI,CAAC,MAAM,CACT,sEAAsE,CACvE,CAAA;QAED,IAAI,CAAC,MAAM,CACT,IAAA,oDAA4C,EAC1C,QAAQ,EACR,CAAC,YAAY,CAAC,EACd,eAAe,CAChB,CACF,CAAA;QAED,IAAI,CAAC,MAAM,CACT,oGAAoG,CACrG,CAAA;QAED,IAAI,CAAC,MAAM,CACT,6FAA6F,CAC9F,CAAA;QACD,IAAI,CAAC,MAAM,CACT,2GAA2G,CAC5G,CAAA;QAED,IAAI,CAAC,MAAM,CACT,0VAA0V,CAC3V,CAAA;QAED,IAAI,CAAC,MAAM,CACT,qEAAqE,CACtE,CAAA;QAED,IAAI,CAAC,MAAM,CACT,yFAAyF,CAC1F,CAAA;QACD,IAAI,CAAC,MAAM,CACT,uGAAuG,CACxG,CAAA;IACH,CAAC;IAED,KAAK,CAAC,IAAI;QACR,IAAI,CAAC,MAAM,CAAC,wCAAwC,CAAC,CAAA;QAErD,IAAI,CAAC,MAAM,CAAC,sCAAsC,CAAC,CAAA;IACrD,CAAC;CACF;AAjDD,0DAiDC"}
@@ -0,0 +1,6 @@
1
+ import { Migration } from "@mikro-orm/migrations";
2
+ export declare class Migration20240703095850 extends Migration {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }
6
+ //# sourceMappingURL=Migration20240703095850.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Migration20240703095850.d.ts","sourceRoot":"","sources":["../../src/migrations/Migration20240703095850.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEjD,qBAAa,uBAAwB,SAAQ,SAAS;IAC9C,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;IAYnB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAK5B"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Migration20240703095850 = void 0;
4
+ const migrations_1 = require("@mikro-orm/migrations");
5
+ class Migration20240703095850 extends migrations_1.Migration {
6
+ async up() {
7
+ this.addSql('drop index if exists "IDX_user_email";');
8
+ this.addSql('CREATE UNIQUE INDEX "IDX_user_email" ON "user" (email) WHERE deleted_at IS NULL;');
9
+ // Adding this log here as the point of failure is not in this function, but bundled up when running all pending migration
10
+ console.info(`Note: If the index "IDX_user_email" fails to create, then delete any existing users with duplicate emails before retrying the migration.`);
11
+ }
12
+ async down() {
13
+ this.addSql('CREATE INDEX IF NOT EXISTS "IDX_user_email" ON "user" (email) WHERE deleted_at IS NULL;');
14
+ }
15
+ }
16
+ exports.Migration20240703095850 = Migration20240703095850;
17
+ //# sourceMappingURL=Migration20240703095850.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Migration20240703095850.js","sourceRoot":"","sources":["../../src/migrations/Migration20240703095850.ts"],"names":[],"mappings":";;;AAAA,sDAAiD;AAEjD,MAAa,uBAAwB,SAAQ,sBAAS;IACpD,KAAK,CAAC,EAAE;QACN,IAAI,CAAC,MAAM,CAAC,wCAAwC,CAAC,CAAA;QAErD,IAAI,CAAC,MAAM,CACT,kFAAkF,CACnF,CAAA;QACD,0HAA0H;QAC1H,OAAO,CAAC,IAAI,CACV,0IAA0I,CAC3I,CAAA;IACH,CAAC;IAED,KAAK,CAAC,IAAI;QACR,IAAI,CAAC,MAAM,CACT,yFAAyF,CAC1F,CAAA;IACH,CAAC;CACF;AAlBD,0DAkBC"}
@@ -1,2 +1,3 @@
1
1
  export { default as User } from "./user";
2
2
  export { default as Invite } from "./invite";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,QAAQ,CAAA;AACxC,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAA"}
@@ -8,3 +8,4 @@ var user_1 = require("./user");
8
8
  Object.defineProperty(exports, "User", { enumerable: true, get: function () { return __importDefault(user_1).default; } });
9
9
  var invite_1 = require("./invite");
10
10
  Object.defineProperty(exports, "Invite", { enumerable: true, get: function () { return __importDefault(invite_1).default; } });
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":";;;;;;AAAA,+BAAwC;AAA/B,6GAAA,OAAO,OAAQ;AACxB,mCAA4C;AAAnC,iHAAA,OAAO,OAAU"}
@@ -1,6 +1,6 @@
1
1
  import { OptionalProps } from "@mikro-orm/core";
2
- import { DAL } from "@medusajs/types";
3
- type OptionalFields = "metadata" | "accepted" | DAL.SoftDeletableEntityDateColumns;
2
+ import { DAL } from "@medusajs/framework/types";
3
+ type OptionalFields = "metadata" | "accepted" | DAL.SoftDeletableModelDateColumns;
4
4
  export default class Invite {
5
5
  [OptionalProps]: OptionalFields;
6
6
  id: string;
@@ -16,3 +16,4 @@ export default class Invite {
16
16
  beforeCreate(): void;
17
17
  }
18
18
  export {};
19
+ //# sourceMappingURL=invite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invite.d.ts","sourceRoot":"","sources":["../../src/models/invite.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,aAAa,EAGd,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAA;AAiC/C,KAAK,cAAc,GACf,UAAU,GACV,UAAU,GACV,GAAG,CAAC,6BAA6B,CAAA;AAGrC,MAAM,CAAC,OAAO,OAAO,MAAM;IACzB,CAAC,aAAa,CAAC,EAAE,cAAc,CAAA;IAG/B,EAAE,EAAE,MAAM,CAAA;IAQV,KAAK,EAAE,MAAM,CAAA;IAGb,QAAQ,EAAE,OAAO,CAAQ;IAOzB,KAAK,EAAE,MAAM,CAAA;IAGb,UAAU,EAAE,IAAI,CAAA;IAGhB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAO;IAO/C,UAAU,EAAE,IAAI,CAAA;IAQhB,UAAU,EAAE,IAAI,CAAA;IAOhB,UAAU,EAAE,IAAI,GAAG,IAAI,CAAO;IAG9B,MAAM;IAKN,YAAY;CAGb"}
@@ -10,7 +10,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const core_1 = require("@mikro-orm/core");
13
- const utils_1 = require("@medusajs/utils");
13
+ const utils_1 = require("@medusajs/framework/utils");
14
14
  const inviteEmailIndexName = "IDX_invite_email";
15
15
  const inviteEmailIndexStatement = (0, utils_1.createPsqlIndexStatementHelper)({
16
16
  name: inviteEmailIndexName,
@@ -121,3 +121,4 @@ Invite = __decorate([
121
121
  (0, core_1.Filter)(utils_1.DALUtils.mikroOrmSoftDeletableFilterOptions)
122
122
  ], Invite);
123
123
  exports.default = Invite;
124
+ //# sourceMappingURL=invite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invite.js","sourceRoot":"","sources":["../../src/models/invite.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,0CASwB;AAGxB,qDAKkC;AAElC,MAAM,oBAAoB,GAAG,kBAAkB,CAAA;AAC/C,MAAM,yBAAyB,GAAG,IAAA,sCAA8B,EAAC;IAC/D,IAAI,EAAE,oBAAoB;IAC1B,SAAS,EAAE,QAAQ;IACnB,OAAO,EAAE,OAAO;IAChB,KAAK,EAAE,oBAAoB;IAC3B,MAAM,EAAE,IAAI;CACb,CAAC,CAAC,UAAU,CAAA;AAEb,MAAM,oBAAoB,GAAG,kBAAkB,CAAA;AAC/C,MAAM,yBAAyB,GAAG,IAAA,sCAA8B,EAAC;IAC/D,IAAI,EAAE,oBAAoB;IAC1B,SAAS,EAAE,QAAQ;IACnB,OAAO,EAAE,OAAO;IAChB,KAAK,EAAE,oBAAoB;CAC5B,CAAC,CAAC,UAAU,CAAA;AAEb,MAAM,wBAAwB,GAAG,uBAAuB,CAAA;AACxD,MAAM,6BAA6B,GAAG,IAAA,sCAA8B,EAAC;IACnE,IAAI,EAAE,wBAAwB;IAC9B,SAAS,EAAE,QAAQ;IACnB,OAAO,EAAE,YAAY;IACrB,KAAK,EAAE,wBAAwB;CAChC,CAAC,CAAC,UAAU,CAAA;AAQE,IAAM,MAAM,GAAZ,MAAM,MAAM;IAAZ;QAeb,aAAQ,GAAY,KAAK,CAAA;QAazB,aAAQ,GAAmC,IAAI,CAAA;QAsB/C,eAAU,GAAgB,IAAI,CAAA;IAWhC,CAAC;IARC,MAAM;QACJ,IAAI,CAAC,EAAE,GAAG,IAAA,wBA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AE,OAAO;KACpB,CAAC;8BACU,IAAI;0CAAA;AAOhB;IALC,IAAA,YAAK,EAAC;QACL,IAAI,EAAE,wBAAwB;QAC9B,UAAU,EAAE,6BAA6B;KAC1C,CAAC;IACD,IAAA,eAAQ,EAAC,EAAE,UAAU,EAAE,aAAa,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;0CAC1B;AAG9B;IADC,IAAA,aAAM,GAAE;;;;oCAGR;AAGD;IADC,IAAA,mBAAY,GAAE;;;;0CAGd;AA5DkB,MAAM;IAF1B,IAAA,aAAM,EAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;IAC/B,IAAA,aAAM,EAAC,gBAAQ,CAAC,kCAAkC,CAAC;GAC/B,MAAM,CA6D1B;kBA7DoB,MAAM"}
@@ -1,6 +1,6 @@
1
1
  import { OptionalProps } from "@mikro-orm/core";
2
- import { DAL } from "@medusajs/types";
3
- type OptionalFields = "first_name" | "last_name" | "metadata" | "avatar_url" | DAL.SoftDeletableEntityDateColumns;
2
+ import { DAL } from "@medusajs/framework/types";
3
+ type OptionalFields = "first_name" | "last_name" | "metadata" | "avatar_url" | DAL.SoftDeletableModelDateColumns;
4
4
  export default class User {
5
5
  [OptionalProps]?: OptionalFields;
6
6
  id: string;
@@ -16,3 +16,4 @@ export default class User {
16
16
  onInit(): void;
17
17
  }
18
18
  export {};
19
+ //# sourceMappingURL=user.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../src/models/user.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,aAAa,EAGd,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAA;AAyB/C,KAAK,cAAc,GACf,YAAY,GACZ,WAAW,GACX,UAAU,GACV,YAAY,GACZ,GAAG,CAAC,6BAA6B,CAAA;AAIrC,MAAM,CAAC,OAAO,OAAO,IAAI;IACvB,CAAC,aAAa,CAAC,CAAC,EAAE,cAAc,CAAA;IAGhC,EAAE,EAAG,MAAM,CAAA;IAIX,UAAU,EAAE,MAAM,GAAG,IAAI,CAAO;IAIhC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAO;IAK/B,KAAK,EAAE,MAAM,CAAA;IAGb,UAAU,EAAE,MAAM,GAAG,IAAI,CAAO;IAGhC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAO;IAO/C,UAAU,EAAE,IAAI,CAAA;IAQhB,UAAU,EAAE,IAAI,CAAA;IAOhB,UAAU,CAAC,EAAE,IAAI,GAAG,IAAI,CAAO;IAG/B,QAAQ;IAKR,MAAM;CAGP"}
@@ -10,14 +10,15 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const core_1 = require("@mikro-orm/core");
13
- const utils_1 = require("@medusajs/utils");
13
+ const utils_1 = require("@medusajs/framework/utils");
14
14
  const userEmailIndexName = "IDX_user_email";
15
15
  const userEmailIndexStatement = (0, utils_1.createPsqlIndexStatementHelper)({
16
16
  name: userEmailIndexName,
17
+ unique: true,
17
18
  tableName: "user",
18
19
  columns: "email",
19
20
  where: "deleted_at IS NULL",
20
- }).expression;
21
+ });
21
22
  const userDeletedAtIndexName = "IDX_user_deleted_at";
22
23
  const userDeletedAtIndexStatement = (0, utils_1.createPsqlIndexStatementHelper)({
23
24
  name: userDeletedAtIndexName,
@@ -55,10 +56,7 @@ __decorate([
55
56
  __metadata("design:type", Object)
56
57
  ], User.prototype, "last_name", void 0);
57
58
  __decorate([
58
- (0, core_1.Index)({
59
- name: userEmailIndexName,
60
- expression: userEmailIndexStatement,
61
- }),
59
+ userEmailIndexStatement.MikroORMIndex(),
62
60
  (0, utils_1.Searchable)(),
63
61
  (0, core_1.Property)({ columnType: "text" }),
64
62
  __metadata("design:type", String)
@@ -113,3 +111,4 @@ User = __decorate([
113
111
  (0, core_1.Filter)(utils_1.DALUtils.mikroOrmSoftDeletableFilterOptions)
114
112
  ], User);
115
113
  exports.default = User;
114
+ //# sourceMappingURL=user.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.js","sourceRoot":"","sources":["../../src/models/user.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,0CASwB;AAGxB,qDAKkC;AAElC,MAAM,kBAAkB,GAAG,gBAAgB,CAAA;AAC3C,MAAM,uBAAuB,GAAG,IAAA,sCAA8B,EAAC;IAC7D,IAAI,EAAE,kBAAkB;IACxB,MAAM,EAAE,IAAI;IACZ,SAAS,EAAE,MAAM;IACjB,OAAO,EAAE,OAAO;IAChB,KAAK,EAAE,oBAAoB;CAC5B,CAAC,CAAA;AAEF,MAAM,sBAAsB,GAAG,qBAAqB,CAAA;AACpD,MAAM,2BAA2B,GAAG,IAAA,sCAA8B,EAAC;IACjE,IAAI,EAAE,sBAAsB;IAC5B,SAAS,EAAE,MAAM;IACjB,OAAO,EAAE,YAAY;IACrB,KAAK,EAAE,wBAAwB;CAChC,CAAC,CAAC,UAAU,CAAA;AAWE,IAAM,IAAI,GAAV,MAAM,IAAI;IAAV;QAQb,eAAU,GAAkB,IAAI,CAAA;QAIhC,cAAS,GAAkB,IAAI,CAAA;QAQ/B,eAAU,GAAkB,IAAI,CAAA;QAGhC,aAAQ,GAAmC,IAAI,CAAA;QAsB/C,eAAU,GAAiB,IAAI,CAAA;IAWjC,CAAC;IARC,QAAQ;QACN,IAAI,CAAC,EAAE,GAAG,IAAA,wBAAgB,EAAC,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;IAC7C,CAAC;IAGD,MAAM;QACJ,IAAI,CAAC,EAAE,GAAG,IAAA,wBAAgB,EAAC,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;IAC7C,CAAC;CACF,CAAA;AApDC;IADC,IAAA,iBAAU,EAAC,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;;gCACxB;AAIX;IAFC,IAAA,kBAAU,GAAE;IACZ,IAA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A,aAAM,GAAE;IACR,IAAA,aAAM,EAAC,gBAAQ,CAAC,kCAAkC,CAAC;GAC/B,IAAI,CAwDxB;kBAxDoB,IAAI"}
@@ -1,2 +1,2 @@
1
1
  export { default as UserModuleService } from "./user-module";
2
- export { default as InviteService } from "./invite";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,eAAe,CAAA"}
@@ -3,8 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.InviteService = exports.UserModuleService = void 0;
6
+ exports.UserModuleService = void 0;
7
7
  var user_module_1 = require("./user-module");
8
8
  Object.defineProperty(exports, "UserModuleService", { enumerable: true, get: function () { return __importDefault(user_module_1).default; } });
9
- var invite_1 = require("./invite");
10
- Object.defineProperty(exports, "InviteService", { enumerable: true, get: function () { return __importDefault(invite_1).default; } });
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;;;;AAAA,6CAA4D;AAAnD,iIAAA,OAAO,OAAqB"}
@@ -1,36 +1,41 @@
1
- import { Context, DAL, InternalModuleDeclaration, ModuleJoinerConfig, UserTypes, ModulesSdkTypes, IEventBusModuleService } from "@medusajs/types";
2
- import { ModulesSdkUtils } from "@medusajs/utils";
1
+ import { Context, DAL, InternalModuleDeclaration, ModulesSdkTypes, UserTypes } from "@medusajs/framework/types";
3
2
  import { Invite, User } from "../models";
4
- import InviteService from "./invite";
5
3
  type InjectedDependencies = {
6
4
  baseRepository: DAL.RepositoryService;
7
- userService: ModulesSdkTypes.InternalModuleService<any>;
8
- inviteService: InviteService<any>;
9
- eventBusModuleService: IEventBusModuleService;
5
+ userService: ModulesSdkTypes.IMedusaInternalService<any>;
6
+ inviteService: ModulesSdkTypes.IMedusaInternalService<any>;
10
7
  };
11
- declare const UserModuleService_base: new (container: InjectedDependencies) => ModulesSdkUtils.AbstractModuleService<InjectedDependencies, UserTypes.UserDTO, {
8
+ declare const UserModuleService_base: import("@medusajs/framework/utils").MedusaServiceReturnType<{
9
+ User: {
10
+ dto: UserTypes.UserDTO;
11
+ };
12
12
  Invite: {
13
13
  dto: UserTypes.InviteDTO;
14
14
  };
15
15
  }>;
16
- export default class UserModuleService<TUser extends User = User, TInvite extends Invite = Invite> extends UserModuleService_base implements UserTypes.IUserModuleService {
16
+ export default class UserModuleService extends UserModuleService_base implements UserTypes.IUserModuleService {
17
17
  protected readonly moduleDeclaration: InternalModuleDeclaration;
18
- __joinerConfig(): ModuleJoinerConfig;
19
18
  protected baseRepository_: DAL.RepositoryService;
20
- protected readonly userService_: ModulesSdkTypes.InternalModuleService<TUser>;
21
- protected readonly inviteService_: InviteService<TInvite>;
19
+ protected readonly userService_: ModulesSdkTypes.IMedusaInternalService<User>;
20
+ protected readonly inviteService_: ModulesSdkTypes.IMedusaInternalService<Invite>;
21
+ protected readonly config: {
22
+ jwtSecret: string;
23
+ expiresIn: number;
24
+ };
22
25
  constructor({ userService, inviteService, baseRepository }: InjectedDependencies, moduleDeclaration: InternalModuleDeclaration);
23
26
  validateInviteToken(token: string, sharedContext?: Context): Promise<UserTypes.InviteDTO>;
24
27
  refreshInviteTokens(inviteIds: string[], sharedContext?: Context): Promise<UserTypes.InviteDTO[]>;
25
- refreshInviteTokens_(inviteIds: string[], sharedContext?: Context): Promise<TInvite[]>;
26
- create(data: UserTypes.CreateUserDTO[], sharedContext?: Context): Promise<UserTypes.UserDTO[]>;
27
- create(data: UserTypes.CreateUserDTO, sharedContext?: Context): Promise<UserTypes.UserDTO>;
28
- update(data: UserTypes.UpdateUserDTO[], sharedContext?: Context): Promise<UserTypes.UserDTO[]>;
29
- update(data: UserTypes.UpdateUserDTO, sharedContext?: Context): Promise<UserTypes.UserDTO>;
28
+ refreshInviteTokens_(inviteIds: string[], sharedContext?: Context): Promise<Invite[]>;
29
+ createUsers(data: UserTypes.CreateUserDTO[], sharedContext?: Context): Promise<UserTypes.UserDTO[]>;
30
+ createUsers(data: UserTypes.CreateUserDTO, sharedContext?: Context): Promise<UserTypes.UserDTO>;
31
+ updateUsers(data: UserTypes.UpdateUserDTO[], sharedContext?: Context): Promise<UserTypes.UserDTO[]>;
32
+ updateUsers(data: UserTypes.UpdateUserDTO, sharedContext?: Context): Promise<UserTypes.UserDTO>;
30
33
  createInvites(data: UserTypes.CreateInviteDTO[], sharedContext?: Context): Promise<UserTypes.InviteDTO[]>;
31
34
  createInvites(data: UserTypes.CreateInviteDTO, sharedContext?: Context): Promise<UserTypes.InviteDTO>;
32
35
  private createInvites_;
33
36
  updateInvites(data: UserTypes.UpdateInviteDTO[], sharedContext?: Context): Promise<UserTypes.InviteDTO[]>;
34
37
  updateInvites(data: UserTypes.UpdateInviteDTO, sharedContext?: Context): Promise<UserTypes.InviteDTO>;
38
+ private generateToken;
35
39
  }
36
40
  export {};
41
+ //# sourceMappingURL=user-module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user-module.d.ts","sourceRoot":"","sources":["../../src/services/user-module.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,GAAG,EACH,yBAAyB,EACzB,eAAe,EACf,SAAS,EACV,MAAM,2BAA2B,CAAA;AAelC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAEtC,KAAK,oBAAoB,GAAG;IAC1B,cAAc,EAAE,GAAG,CAAC,iBAAiB,CAAA;IACrC,WAAW,EAAE,eAAe,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAA;IACxD,aAAa,EAAE,eAAe,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAA;CAC3D,CAAA;;UAMS;QACJ,GAAG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W,CACT,IAAI,EAAE,SAAS,CAAC,aAAa,EAAE,EAC/B,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;IAC/B,WAAW,CACT,IAAI,EAAE,SAAS,CAAC,aAAa,EAC7B,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC;IAiC7B,aAAa,CACX,IAAI,EAAE,SAAS,CAAC,eAAe,EAAE,EACjC,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC;IACjC,aAAa,CACX,IAAI,EAAE,SAAS,CAAC,eAAe,EAC/B,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC;YA4CjB,cAAc;IAyC5B,aAAa,CACX,IAAI,EAAE,SAAS,CAAC,eAAe,EAAE,EACjC,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC;IACjC,aAAa,CACX,IAAI,EAAE,SAAS,CAAC,eAAe,EAC/B,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC;IAmC/B,OAAO,CAAC,aAAa;CAOtB"}
@@ -11,25 +11,40 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  return function (target, key) { decorator(target, key, paramIndex); }
13
13
  };
14
+ var __importDefault = (this && this.__importDefault) || function (mod) {
15
+ return (mod && mod.__esModule) ? mod : { "default": mod };
16
+ };
14
17
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const utils_1 = require("@medusajs/utils");
16
- const joiner_config_1 = require("../joiner-config");
18
+ const utils_1 = require("@medusajs/framework/utils");
19
+ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
20
+ const node_crypto_1 = __importDefault(require("node:crypto"));
17
21
  const _models_1 = require("../models");
18
- const generateMethodForModels = [_models_1.Invite];
19
- class UserModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFactory(_models_1.User, generateMethodForModels, joiner_config_1.entityNameToLinkableKeysMap) {
20
- __joinerConfig() {
21
- return joiner_config_1.joinerConfig;
22
- }
22
+ // 1 day
23
+ const DEFAULT_VALID_INVITE_DURATION = 60 * 60 * 24 * 1000;
24
+ class UserModuleService extends (0, utils_1.MedusaService)({ User: _models_1.User, Invite: _models_1.Invite }) {
23
25
  constructor({ userService, inviteService, baseRepository }, moduleDeclaration) {
24
26
  // @ts-ignore
25
27
  super(...arguments);
26
28
  this.moduleDeclaration = moduleDeclaration;
27
29
  this.baseRepository_ = baseRepository;
28
30
  this.userService_ = userService;
29
- this.inviteService_ = inviteService.withModuleOptions(this.moduleDeclaration);
31
+ this.inviteService_ = inviteService;
32
+ this.config = {
33
+ jwtSecret: moduleDeclaration["jwt_secret"],
34
+ expiresIn: parseInt(moduleDeclaration["valid_duration"]) ||
35
+ DEFAULT_VALID_INVITE_DURATION,
36
+ };
37
+ if (!this.config.jwtSecret) {
38
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "No jwt_secret was provided in the UserModule's options. Please add one.");
39
+ }
30
40
  }
31
41
  async validateInviteToken(token, sharedContext = {}) {
32
- const invite = await this.inviteService_.validateInviteToken(token, sharedContext);
42
+ const jwtSecret = this.moduleDeclaration["jwt_secret"];
43
+ const decoded = jsonwebtoken_1.default.verify(token, jwtSecret, { complete: true });
44
+ const invite = await this.inviteService_.retrieve(decoded.payload.id, {}, sharedContext);
45
+ if (invite.expires_at < new Date()) {
46
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "The invite has expired");
47
+ }
33
48
  return await this.baseRepository_.serialize(invite, {
34
49
  populate: true,
35
50
  });
@@ -37,12 +52,11 @@ class UserModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFac
37
52
  async refreshInviteTokens(inviteIds, sharedContext = {}) {
38
53
  const invites = await this.refreshInviteTokens_(inviteIds, sharedContext);
39
54
  sharedContext.messageAggregator?.saveRawMessageData(invites.map((invite) => ({
40
- eventName: utils_1.UserEvents.invite_token_generated,
41
- metadata: {
42
- service: this.constructor.name,
43
- action: "token_generated",
44
- object: "invite",
45
- },
55
+ eventName: utils_1.UserEvents.INVITE_TOKEN_GENERATED,
56
+ source: this.constructor.name,
57
+ action: "token_generated",
58
+ object: "invite",
59
+ context: sharedContext,
46
60
  data: { id: invite.id },
47
61
  })));
48
62
  return await this.baseRepository_.serialize(invites, {
@@ -50,38 +64,50 @@ class UserModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFac
50
64
  });
51
65
  }
52
66
  async refreshInviteTokens_(inviteIds, sharedContext = {}) {
53
- return await this.inviteService_.refreshInviteTokens(inviteIds, sharedContext);
67
+ const [invites, count] = await this.inviteService_.listAndCount({ id: inviteIds }, {}, sharedContext);
68
+ if (count !== inviteIds.length) {
69
+ const missing = (0, utils_1.arrayDifference)(inviteIds, invites.map((invite) => invite.id));
70
+ if (missing.length > 0) {
71
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `The following invites do not exist: ${missing.join(", ")}`);
72
+ }
73
+ }
74
+ const updates = invites.map((invite) => {
75
+ return {
76
+ id: invite.id,
77
+ expires_at: new Date().setMilliseconds(new Date().getMilliseconds() + this.config.expiresIn),
78
+ token: this.generateToken({ id: invite.id, email: invite.email }),
79
+ };
80
+ });
81
+ return await this.inviteService_.update(updates, sharedContext);
54
82
  }
55
- async create(data, sharedContext = {}) {
83
+ async createUsers(data, sharedContext = {}) {
56
84
  const input = Array.isArray(data) ? data : [data];
57
85
  const users = await this.userService_.create(input, sharedContext);
58
86
  const serializedUsers = await this.baseRepository_.serialize(users, {
59
87
  populate: true,
60
88
  });
61
89
  sharedContext.messageAggregator?.saveRawMessageData(users.map((user) => ({
62
- eventName: utils_1.UserEvents.created,
63
- metadata: {
64
- service: this.constructor.name,
65
- action: utils_1.CommonEvents.CREATED,
66
- object: "user",
67
- },
90
+ eventName: utils_1.UserEvents.USER_CREATED,
91
+ source: this.constructor.name,
92
+ action: utils_1.CommonEvents.CREATED,
93
+ object: "user",
94
+ context: sharedContext,
68
95
  data: { id: user.id },
69
96
  })));
70
97
  return Array.isArray(data) ? serializedUsers : serializedUsers[0];
71
98
  }
72
- async update(data, sharedContext = {}) {
99
+ async updateUsers(data, sharedContext = {}) {
73
100
  const input = Array.isArray(data) ? data : [data];
74
101
  const updatedUsers = await this.userService_.update(input, sharedContext);
75
102
  const serializedUsers = await this.baseRepository_.serialize(updatedUsers, {
76
103
  populate: true,
77
104
  });
78
105
  sharedContext.messageAggregator?.saveRawMessageData(updatedUsers.map((user) => ({
79
- eventName: utils_1.UserEvents.updated,
80
- metadata: {
81
- service: this.constructor.name,
82
- action: utils_1.CommonEvents.UPDATED,
83
- object: "user",
84
- },
106
+ eventName: utils_1.UserEvents.USER_UPDATED,
107
+ source: this.constructor.name,
108
+ action: utils_1.CommonEvents.UPDATED,
109
+ object: "user",
110
+ context: sharedContext,
85
111
  data: { id: user.id },
86
112
  })));
87
113
  return Array.isArray(data) ? serializedUsers : serializedUsers[0];
@@ -93,26 +119,32 @@ class UserModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFac
93
119
  populate: true,
94
120
  });
95
121
  sharedContext.messageAggregator?.saveRawMessageData(invites.map((invite) => ({
96
- eventName: utils_1.UserEvents.invite_created,
97
- metadata: {
98
- service: this.constructor.name,
99
- action: utils_1.CommonEvents.CREATED,
100
- object: "invite",
101
- },
122
+ eventName: utils_1.UserEvents.INVITE_CREATED,
123
+ source: this.constructor.name,
124
+ action: utils_1.CommonEvents.CREATED,
125
+ object: "invite",
126
+ context: sharedContext,
102
127
  data: { id: invite.id },
103
128
  })));
104
129
  sharedContext.messageAggregator?.saveRawMessageData(invites.map((invite) => ({
105
- eventName: utils_1.UserEvents.invite_token_generated,
106
- metadata: {
107
- service: this.constructor.name,
108
- action: "token_generated",
109
- object: "invite",
110
- },
130
+ eventName: utils_1.UserEvents.INVITE_TOKEN_GENERATED,
131
+ source: this.constructor.name,
132
+ action: "token_generated",
133
+ object: "invite",
134
+ context: sharedContext,
111
135
  data: { id: invite.id },
112
136
  })));
113
137
  return Array.isArray(data) ? serializedInvites : serializedInvites[0];
114
138
  }
115
139
  async createInvites_(data, sharedContext = {}) {
140
+ const alreadyExistingUsers = await this.listUsers({
141
+ email: data.map((d) => d.email),
142
+ });
143
+ if (alreadyExistingUsers.length) {
144
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `User account for following email(s) already exist: ${alreadyExistingUsers
145
+ .map((u) => u.email)
146
+ .join(", ")}`);
147
+ }
116
148
  const toCreate = data.map((invite) => {
117
149
  return {
118
150
  ...invite,
@@ -120,7 +152,15 @@ class UserModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFac
120
152
  token: "placeholder",
121
153
  };
122
154
  });
123
- return await this.inviteService_.create(toCreate, sharedContext);
155
+ const created = await this.inviteService_.create(toCreate, sharedContext);
156
+ const updates = created.map((invite) => {
157
+ return {
158
+ id: invite.id,
159
+ expires_at: new Date().setMilliseconds(new Date().getMilliseconds() + this.config.expiresIn),
160
+ token: this.generateToken({ id: invite.id, email: invite.email }),
161
+ };
162
+ });
163
+ return await this.inviteService_.update(updates, sharedContext);
124
164
  }
125
165
  async updateInvites(data, sharedContext = {}) {
126
166
  const input = Array.isArray(data) ? data : [data];
@@ -129,27 +169,33 @@ class UserModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFac
129
169
  populate: true,
130
170
  });
131
171
  sharedContext.messageAggregator?.saveRawMessageData(serializedInvites.map((invite) => ({
132
- eventName: utils_1.UserEvents.invite_updated,
133
- metadata: {
134
- service: this.constructor.name,
135
- action: utils_1.CommonEvents.UPDATED,
136
- object: "invite",
137
- },
172
+ eventName: utils_1.UserEvents.INVITE_UPDATED,
173
+ source: this.constructor.name,
174
+ action: utils_1.CommonEvents.UPDATED,
175
+ object: "invite",
176
+ context: sharedContext,
138
177
  data: { id: invite.id },
139
178
  })));
140
179
  return Array.isArray(data) ? serializedInvites : serializedInvites[0];
141
180
  }
181
+ generateToken(data) {
182
+ const jwtSecret = this.moduleDeclaration["jwt_secret"];
183
+ return jsonwebtoken_1.default.sign(data, jwtSecret, {
184
+ jwtid: node_crypto_1.default.randomUUID(),
185
+ expiresIn: this.config.expiresIn,
186
+ });
187
+ }
142
188
  }
143
189
  exports.default = UserModuleService;
144
190
  __decorate([
145
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
191
+ (0, utils_1.InjectTransactionManager)(),
146
192
  __param(1, (0, utils_1.MedusaContext)()),
147
193
  __metadata("design:type", Function),
148
194
  __metadata("design:paramtypes", [String, Object]),
149
195
  __metadata("design:returntype", Promise)
150
196
  ], UserModuleService.prototype, "validateInviteToken", null);
151
197
  __decorate([
152
- (0, utils_1.InjectManager)("baseRepository_"),
198
+ (0, utils_1.InjectManager)(),
153
199
  (0, utils_1.EmitEvents)(),
154
200
  __param(1, (0, utils_1.MedusaContext)()),
155
201
  __metadata("design:type", Function),
@@ -157,30 +203,30 @@ __decorate([
157
203
  __metadata("design:returntype", Promise)
158
204
  ], UserModuleService.prototype, "refreshInviteTokens", null);
159
205
  __decorate([
160
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
206
+ (0, utils_1.InjectTransactionManager)(),
161
207
  __param(1, (0, utils_1.MedusaContext)()),
162
208
  __metadata("design:type", Function),
163
209
  __metadata("design:paramtypes", [Array, Object]),
164
210
  __metadata("design:returntype", Promise)
165
211
  ], UserModuleService.prototype, "refreshInviteTokens_", null);
166
212
  __decorate([
167
- (0, utils_1.InjectManager)("baseRepository_"),
213
+ (0, utils_1.InjectManager)(),
168
214
  (0, utils_1.EmitEvents)(),
169
215
  __param(1, (0, utils_1.MedusaContext)()),
170
216
  __metadata("design:type", Function),
171
217
  __metadata("design:paramtypes", [Object, Object]),
172
218
  __metadata("design:returntype", Promise)
173
- ], UserModuleService.prototype, "create", null);
219
+ ], UserModuleService.prototype, "createUsers", null);
174
220
  __decorate([
175
- (0, utils_1.InjectManager)("baseRepository_"),
221
+ (0, utils_1.InjectManager)(),
176
222
  (0, utils_1.EmitEvents)(),
177
223
  __param(1, (0, utils_1.MedusaContext)()),
178
224
  __metadata("design:type", Function),
179
225
  __metadata("design:paramtypes", [Object, Object]),
180
226
  __metadata("design:returntype", Promise)
181
- ], UserModuleService.prototype, "update", null);
227
+ ], UserModuleService.prototype, "updateUsers", null);
182
228
  __decorate([
183
- (0, utils_1.InjectManager)("baseRepository_"),
229
+ (0, utils_1.InjectManager)(),
184
230
  (0, utils_1.EmitEvents)(),
185
231
  __param(1, (0, utils_1.MedusaContext)()),
186
232
  __metadata("design:type", Function),
@@ -188,17 +234,18 @@ __decorate([
188
234
  __metadata("design:returntype", Promise)
189
235
  ], UserModuleService.prototype, "createInvites", null);
190
236
  __decorate([
191
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
237
+ (0, utils_1.InjectTransactionManager)(),
192
238
  __param(1, (0, utils_1.MedusaContext)()),
193
239
  __metadata("design:type", Function),
194
240
  __metadata("design:paramtypes", [Array, Object]),
195
241
  __metadata("design:returntype", Promise)
196
242
  ], UserModuleService.prototype, "createInvites_", null);
197
243
  __decorate([
198
- (0, utils_1.InjectManager)("baseRepository_"),
244
+ (0, utils_1.InjectManager)(),
199
245
  (0, utils_1.EmitEvents)(),
200
246
  __param(1, (0, utils_1.MedusaContext)()),
201
247
  __metadata("design:type", Function),
202
248
  __metadata("design:paramtypes", [Object, Object]),
203
249
  __metadata("design:returntype", Promise)
204
250
  ], UserModuleService.prototype, "updateInvites", null);
251
+ //# sourceMappingURL=user-module.js.map