@medusajs/user 0.0.4-snapshot-20240718073308 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.ts +5 -6
- package/dist/index.js +21 -5
- package/dist/initialize/index.d.ts +3 -0
- package/dist/initialize/index.js +16 -0
- package/dist/joiner-config.d.ts +8 -0
- package/dist/joiner-config.js +38 -0
- package/dist/loaders/connection.d.ts +4 -0
- package/dist/loaders/connection.js +41 -0
- package/dist/loaders/container.d.ts +2 -0
- package/dist/loaders/container.js +34 -0
- package/dist/loaders/index.d.ts +2 -0
- package/dist/loaders/index.js +18 -0
- package/dist/migrations/Migration20240214033943.d.ts +0 -1
- package/dist/models/index.d.ts +0 -1
- package/dist/models/invite.d.ts +1 -2
- package/dist/models/user.d.ts +1 -2
- package/dist/models/user.js +5 -3
- package/dist/module-definition.d.ts +4 -0
- package/dist/module-definition.js +50 -0
- package/dist/repositories/index.d.ts +1 -0
- package/dist/repositories/index.js +5 -0
- package/dist/scripts/bin/run-seed.d.ts +3 -0
- package/dist/scripts/bin/run-seed.js +38 -0
- package/dist/scripts/seed.d.ts +4 -0
- package/dist/scripts/seed.js +54 -0
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +3 -1
- package/dist/services/invite.d.ts +25 -0
- package/dist/services/invite.js +140 -0
- package/dist/services/user-module.d.ts +15 -21
- package/dist/services/user-module.js +50 -88
- package/dist/types/index.d.ts +0 -1
- package/dist/types/services/index.d.ts +0 -1
- package/dist/types/services/invite.d.ts +0 -1
- package/package.json +14 -10
- package/dist/index.d.ts.map +0 -1
- package/dist/migrations/Migration20240214033943.d.ts.map +0 -1
- package/dist/migrations/Migration20240703095850.d.ts +0 -6
- package/dist/migrations/Migration20240703095850.d.ts.map +0 -1
- package/dist/migrations/Migration20240703095850.js +0 -16
- package/dist/models/index.d.ts.map +0 -1
- package/dist/models/invite.d.ts.map +0 -1
- package/dist/models/user.d.ts.map +0 -1
- package/dist/services/index.d.ts.map +0 -1
- package/dist/services/user-module.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/services/index.d.ts.map +0 -1
- package/dist/types/services/invite.d.ts.map +0 -1
package/dist/index.d.ts
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
export
|
6
|
-
//# sourceMappingURL=index.d.ts.map
|
1
|
+
import { moduleDefinition, revertMigration, runMigrations } from "./module-definition";
|
2
|
+
export default moduleDefinition;
|
3
|
+
export { revertMigration, runMigrations };
|
4
|
+
export * from "./initialize";
|
5
|
+
export * from "./loaders";
|
package/dist/index.js
CHANGED
@@ -1,7 +1,23 @@
|
|
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
|
+
};
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
|
4
|
-
const
|
5
|
-
exports
|
6
|
-
|
7
|
-
|
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);
|
@@ -0,0 +1,3 @@
|
|
1
|
+
import { IUserModuleService, ModulesSdkTypes } from "@medusajs/types";
|
2
|
+
import { InitializeModuleInjectableDependencies } from "../types";
|
3
|
+
export declare const initialize: (options?: ModulesSdkTypes.ModuleBootstrapDeclaration | ModulesSdkTypes.ModuleServiceInitializeOptions | ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions, injectedDependencies?: InitializeModuleInjectableDependencies) => Promise<IUserModuleService>;
|
@@ -0,0 +1,16 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.initialize = void 0;
|
4
|
+
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
5
|
+
const module_definition_1 = require("../module-definition");
|
6
|
+
const initialize = async (options, injectedDependencies) => {
|
7
|
+
const loaded = await modules_sdk_1.MedusaModule.bootstrap({
|
8
|
+
moduleKey: modules_sdk_1.Modules.USER,
|
9
|
+
defaultPath: modules_sdk_1.MODULE_PACKAGE_NAMES[modules_sdk_1.Modules.USER],
|
10
|
+
declaration: options,
|
11
|
+
injectedDependencies,
|
12
|
+
moduleExports: module_definition_1.moduleDefinition,
|
13
|
+
});
|
14
|
+
return loaded[modules_sdk_1.Modules.USER];
|
15
|
+
};
|
16
|
+
exports.initialize = initialize;
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { MapToConfig } from "@medusajs/utils";
|
2
|
+
import { ModuleJoinerConfig } from "@medusajs/types";
|
3
|
+
export declare const LinkableKeys: {
|
4
|
+
user_id: string;
|
5
|
+
invite_id: string;
|
6
|
+
};
|
7
|
+
export declare const entityNameToLinkableKeysMap: MapToConfig;
|
8
|
+
export declare const joinerConfig: ModuleJoinerConfig;
|
@@ -0,0 +1,38 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.joinerConfig = exports.entityNameToLinkableKeysMap = exports.LinkableKeys = void 0;
|
4
|
+
const _models_1 = require("./models");
|
5
|
+
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
6
|
+
exports.LinkableKeys = {
|
7
|
+
user_id: _models_1.User.name,
|
8
|
+
invite_id: _models_1.Invite.name,
|
9
|
+
};
|
10
|
+
const entityLinkableKeysMap = {};
|
11
|
+
Object.entries(exports.LinkableKeys).forEach(([key, value]) => {
|
12
|
+
entityLinkableKeysMap[value] ?? (entityLinkableKeysMap[value] = []);
|
13
|
+
entityLinkableKeysMap[value].push({
|
14
|
+
mapTo: key,
|
15
|
+
valueFrom: key.split("_").pop(),
|
16
|
+
});
|
17
|
+
});
|
18
|
+
exports.entityNameToLinkableKeysMap = entityLinkableKeysMap;
|
19
|
+
exports.joinerConfig = {
|
20
|
+
serviceName: modules_sdk_1.Modules.USER,
|
21
|
+
primaryKeys: ["id"],
|
22
|
+
linkableKeys: exports.LinkableKeys,
|
23
|
+
alias: [
|
24
|
+
{
|
25
|
+
name: ["user", "users"],
|
26
|
+
args: {
|
27
|
+
entity: _models_1.User.name,
|
28
|
+
},
|
29
|
+
},
|
30
|
+
{
|
31
|
+
name: ["invite", "invites"],
|
32
|
+
args: {
|
33
|
+
entity: _models_1.Invite.name,
|
34
|
+
methodSuffix: "Invites",
|
35
|
+
},
|
36
|
+
},
|
37
|
+
],
|
38
|
+
};
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import { InternalModuleDeclaration, LoaderOptions } from "@medusajs/modules-sdk";
|
2
|
+
import { ModulesSdkTypes } from "@medusajs/types";
|
3
|
+
declare const _default: ({ options, container, logger, }: LoaderOptions<ModulesSdkTypes.ModuleServiceInitializeOptions | ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions>, moduleDeclaration?: InternalModuleDeclaration) => Promise<void>;
|
4
|
+
export default _default;
|
@@ -0,0 +1,41 @@
|
|
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
|
+
const UserModels = __importStar(require("../models"));
|
27
|
+
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
28
|
+
const utils_1 = require("@medusajs/utils");
|
29
|
+
exports.default = async ({ options, container, logger, }, moduleDeclaration) => {
|
30
|
+
const entities = Object.values(UserModels);
|
31
|
+
const pathToMigrations = __dirname + "/../migrations";
|
32
|
+
await utils_1.ModulesSdkUtils.mikroOrmConnectionLoader({
|
33
|
+
moduleName: modules_sdk_1.Modules.USER,
|
34
|
+
entities,
|
35
|
+
container,
|
36
|
+
options,
|
37
|
+
moduleDeclaration,
|
38
|
+
logger,
|
39
|
+
pathToMigrations,
|
40
|
+
});
|
41
|
+
};
|
@@ -0,0 +1,34 @@
|
|
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
|
+
const utils_1 = require("@medusajs/utils");
|
27
|
+
const ModuleModels = __importStar(require("../models"));
|
28
|
+
const ModuleRepositories = __importStar(require("../repositories"));
|
29
|
+
const ModuleServices = __importStar(require("../services"));
|
30
|
+
exports.default = utils_1.ModulesSdkUtils.moduleContainerLoaderFactory({
|
31
|
+
moduleModels: ModuleModels,
|
32
|
+
moduleRepositories: ModuleRepositories,
|
33
|
+
moduleServices: ModuleServices,
|
34
|
+
});
|
@@ -0,0 +1,18 @@
|
|
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("./connection"), exports);
|
18
|
+
__exportStar(require("./container"), exports);
|
package/dist/models/index.d.ts
CHANGED
package/dist/models/invite.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { OptionalProps } from "@mikro-orm/core";
|
2
2
|
import { DAL } from "@medusajs/types";
|
3
|
-
type OptionalFields = "metadata" | "accepted" | DAL.
|
3
|
+
type OptionalFields = "metadata" | "accepted" | DAL.SoftDeletableEntityDateColumns;
|
4
4
|
export default class Invite {
|
5
5
|
[OptionalProps]: OptionalFields;
|
6
6
|
id: string;
|
@@ -16,4 +16,3 @@ export default class Invite {
|
|
16
16
|
beforeCreate(): void;
|
17
17
|
}
|
18
18
|
export {};
|
19
|
-
//# sourceMappingURL=invite.d.ts.map
|
package/dist/models/user.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { OptionalProps } from "@mikro-orm/core";
|
2
2
|
import { DAL } from "@medusajs/types";
|
3
|
-
type OptionalFields = "first_name" | "last_name" | "metadata" | "avatar_url" | DAL.
|
3
|
+
type OptionalFields = "first_name" | "last_name" | "metadata" | "avatar_url" | DAL.SoftDeletableEntityDateColumns;
|
4
4
|
export default class User {
|
5
5
|
[OptionalProps]?: OptionalFields;
|
6
6
|
id: string;
|
@@ -16,4 +16,3 @@ export default class User {
|
|
16
16
|
onInit(): void;
|
17
17
|
}
|
18
18
|
export {};
|
19
|
-
//# sourceMappingURL=user.d.ts.map
|
package/dist/models/user.js
CHANGED
@@ -14,11 +14,10 @@ const utils_1 = require("@medusajs/utils");
|
|
14
14
|
const userEmailIndexName = "IDX_user_email";
|
15
15
|
const userEmailIndexStatement = (0, utils_1.createPsqlIndexStatementHelper)({
|
16
16
|
name: userEmailIndexName,
|
17
|
-
unique: true,
|
18
17
|
tableName: "user",
|
19
18
|
columns: "email",
|
20
19
|
where: "deleted_at IS NULL",
|
21
|
-
});
|
20
|
+
}).expression;
|
22
21
|
const userDeletedAtIndexName = "IDX_user_deleted_at";
|
23
22
|
const userDeletedAtIndexStatement = (0, utils_1.createPsqlIndexStatementHelper)({
|
24
23
|
name: userDeletedAtIndexName,
|
@@ -56,7 +55,10 @@ __decorate([
|
|
56
55
|
__metadata("design:type", Object)
|
57
56
|
], User.prototype, "last_name", void 0);
|
58
57
|
__decorate([
|
59
|
-
|
58
|
+
(0, core_1.Index)({
|
59
|
+
name: userEmailIndexName,
|
60
|
+
expression: userEmailIndexStatement,
|
61
|
+
}),
|
60
62
|
(0, utils_1.Searchable)(),
|
61
63
|
(0, core_1.Property)({ columnType: "text" }),
|
62
64
|
__metadata("design:type", String)
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import { ModuleExports } from "@medusajs/types";
|
2
|
+
export declare const runMigrations: ({ options, logger, }?: Pick<import("@medusajs/types").LoaderOptions<import("@medusajs/types").ModuleServiceInitializeOptions>, "options" | "logger"> | undefined) => Promise<void>;
|
3
|
+
export declare const revertMigration: ({ options, logger, }?: Pick<import("@medusajs/types").LoaderOptions<import("@medusajs/types").ModuleServiceInitializeOptions>, "options" | "logger"> | undefined) => Promise<void>;
|
4
|
+
export declare const moduleDefinition: ModuleExports;
|
@@ -0,0 +1,50 @@
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
|
+
};
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
+
exports.moduleDefinition = exports.revertMigration = exports.runMigrations = void 0;
|
30
|
+
const Models = __importStar(require("./models"));
|
31
|
+
const _services_1 = require("./services");
|
32
|
+
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
33
|
+
const utils_1 = require("@medusajs/utils");
|
34
|
+
const connection_1 = __importDefault(require("./loaders/connection"));
|
35
|
+
const container_1 = __importDefault(require("./loaders/container"));
|
36
|
+
const migrationScriptOptions = {
|
37
|
+
moduleName: modules_sdk_1.Modules.USER,
|
38
|
+
models: Models,
|
39
|
+
pathToMigrations: __dirname + "/migrations",
|
40
|
+
};
|
41
|
+
exports.runMigrations = utils_1.ModulesSdkUtils.buildMigrationScript(migrationScriptOptions);
|
42
|
+
exports.revertMigration = utils_1.ModulesSdkUtils.buildRevertMigrationScript(migrationScriptOptions);
|
43
|
+
const service = _services_1.UserModuleService;
|
44
|
+
const loaders = [container_1.default, connection_1.default];
|
45
|
+
exports.moduleDefinition = {
|
46
|
+
service,
|
47
|
+
loaders,
|
48
|
+
runMigrations: exports.runMigrations,
|
49
|
+
revertMigration: exports.revertMigration,
|
50
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export { MikroOrmBaseRepository as BaseRepository } from "@medusajs/utils";
|
@@ -0,0 +1,5 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.BaseRepository = void 0;
|
4
|
+
var utils_1 = require("@medusajs/utils");
|
5
|
+
Object.defineProperty(exports, "BaseRepository", { enumerable: true, get: function () { return utils_1.MikroOrmBaseRepository; } });
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
"use strict";
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
4
|
+
if (k2 === undefined) k2 = k;
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
8
|
+
}
|
9
|
+
Object.defineProperty(o, k2, desc);
|
10
|
+
}) : (function(o, m, k, k2) {
|
11
|
+
if (k2 === undefined) k2 = k;
|
12
|
+
o[k2] = m[k];
|
13
|
+
}));
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
16
|
+
}) : function(o, v) {
|
17
|
+
o["default"] = v;
|
18
|
+
});
|
19
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
20
|
+
if (mod && mod.__esModule) return mod;
|
21
|
+
var result = {};
|
22
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
23
|
+
__setModuleDefault(result, mod);
|
24
|
+
return result;
|
25
|
+
};
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
27
|
+
const os_1 = require("os");
|
28
|
+
const seed_1 = require("../seed");
|
29
|
+
const args = process.argv;
|
30
|
+
const path = args.pop();
|
31
|
+
exports.default = (async () => {
|
32
|
+
const { config } = await Promise.resolve().then(() => __importStar(require("dotenv")));
|
33
|
+
config();
|
34
|
+
if (!path) {
|
35
|
+
throw new Error(`filePath is required.${os_1.EOL}Example: medusa-user-seed <filePath>`);
|
36
|
+
}
|
37
|
+
await (0, seed_1.run)({ path });
|
38
|
+
})();
|
@@ -0,0 +1,54 @@
|
|
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.run = void 0;
|
27
|
+
const UserModels = __importStar(require("../models"));
|
28
|
+
const utils_1 = require("@medusajs/utils");
|
29
|
+
const os_1 = require("os");
|
30
|
+
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
31
|
+
const path_1 = require("path");
|
32
|
+
async function run({ options, logger, path, }) {
|
33
|
+
logger ?? (logger = console);
|
34
|
+
logger.info(`Loading seed data from ${path}...`);
|
35
|
+
const { userData } = await Promise.resolve(`${(0, path_1.resolve)(process.cwd(), path)}`).then(s => __importStar(require(s))).catch((e) => {
|
36
|
+
logger?.error(`Failed to load seed data from ${path}. Please, provide a relative path and check that you export the following: userData.${os_1.EOL}${e}`);
|
37
|
+
throw e;
|
38
|
+
});
|
39
|
+
const dbData = utils_1.ModulesSdkUtils.loadDatabaseConfig(modules_sdk_1.Modules.USER, options);
|
40
|
+
const entities = Object.values(UserModels);
|
41
|
+
const pathToMigrations = __dirname + "/../migrations";
|
42
|
+
const orm = await utils_1.DALUtils.mikroOrmCreateConnection(dbData, entities, pathToMigrations);
|
43
|
+
const manager = orm.em.fork();
|
44
|
+
try {
|
45
|
+
logger.info("Seeding user data..");
|
46
|
+
// TODO: implement user seed data
|
47
|
+
// await createUsers(manager, usersData)
|
48
|
+
}
|
49
|
+
catch (e) {
|
50
|
+
logger.error(`Failed to insert the seed data in the PostgreSQL database ${dbData.clientUrl}.${os_1.EOL}${e}`);
|
51
|
+
}
|
52
|
+
await orm.close(true);
|
53
|
+
}
|
54
|
+
exports.run = run;
|
package/dist/services/index.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
export { default as UserModuleService } from "./user-module";
|
2
|
-
|
2
|
+
export { default as InviteService } from "./invite";
|
package/dist/services/index.js
CHANGED
@@ -3,6 +3,8 @@ 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.UserModuleService = void 0;
|
6
|
+
exports.InviteService = 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; } });
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import { Context, DAL } from "@medusajs/types";
|
2
|
+
import { Invite } from "../models";
|
3
|
+
import { InviteServiceTypes } from "../types";
|
4
|
+
type InjectedDependencies = {
|
5
|
+
inviteRepository: DAL.RepositoryService;
|
6
|
+
};
|
7
|
+
declare const InviteService_base: new <TEntity_1 extends object = any>(container: InjectedDependencies) => import("@medusajs/types").InternalModuleService<TEntity_1, InjectedDependencies>;
|
8
|
+
export default class InviteService<TEntity extends Invite = Invite> extends InviteService_base<TEntity> {
|
9
|
+
protected readonly inviteRepository_: DAL.RepositoryService<TEntity>;
|
10
|
+
protected options_: {
|
11
|
+
jwt_secret: string;
|
12
|
+
valid_duration: number;
|
13
|
+
} | undefined;
|
14
|
+
constructor(container: InjectedDependencies);
|
15
|
+
withModuleOptions(options: any): InviteService<TEntity>;
|
16
|
+
private getOption;
|
17
|
+
create(data: InviteServiceTypes.CreateInviteDTO, context?: Context): Promise<TEntity>;
|
18
|
+
create(data: InviteServiceTypes.CreateInviteDTO[], context?: Context): Promise<TEntity[]>;
|
19
|
+
refreshInviteTokens(inviteIds: string[], context?: Context): Promise<TEntity[]>;
|
20
|
+
validateInviteToken(token: string, context?: Context): Promise<TEntity>;
|
21
|
+
private generateToken;
|
22
|
+
private getValidDuration;
|
23
|
+
private validateToken;
|
24
|
+
}
|
25
|
+
export {};
|
@@ -0,0 +1,140 @@
|
|
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);
|
@@ -1,42 +1,36 @@
|
|
1
|
-
import { Context, DAL,
|
1
|
+
import { Context, DAL, InternalModuleDeclaration, ModuleJoinerConfig, UserTypes, ModulesSdkTypes, IEventBusModuleService } from "@medusajs/types";
|
2
|
+
import { ModulesSdkUtils } from "@medusajs/utils";
|
2
3
|
import { Invite, User } from "../models";
|
4
|
+
import InviteService from "./invite";
|
3
5
|
type InjectedDependencies = {
|
4
6
|
baseRepository: DAL.RepositoryService;
|
5
|
-
userService: ModulesSdkTypes.
|
6
|
-
inviteService:
|
7
|
+
userService: ModulesSdkTypes.InternalModuleService<any>;
|
8
|
+
inviteService: InviteService<any>;
|
7
9
|
eventBusModuleService: IEventBusModuleService;
|
8
10
|
};
|
9
|
-
declare const UserModuleService_base:
|
10
|
-
User: {
|
11
|
-
dto: UserTypes.UserDTO;
|
12
|
-
};
|
11
|
+
declare const UserModuleService_base: new (container: InjectedDependencies) => ModulesSdkUtils.AbstractModuleService<InjectedDependencies, UserTypes.UserDTO, {
|
13
12
|
Invite: {
|
14
13
|
dto: UserTypes.InviteDTO;
|
15
14
|
};
|
16
15
|
}>;
|
17
|
-
export default class UserModuleService extends UserModuleService_base implements UserTypes.IUserModuleService {
|
16
|
+
export default class UserModuleService<TUser extends User = User, TInvite extends Invite = Invite> extends UserModuleService_base implements UserTypes.IUserModuleService {
|
18
17
|
protected readonly moduleDeclaration: InternalModuleDeclaration;
|
18
|
+
__joinerConfig(): ModuleJoinerConfig;
|
19
19
|
protected baseRepository_: DAL.RepositoryService;
|
20
|
-
protected readonly userService_: ModulesSdkTypes.
|
21
|
-
protected readonly inviteService_:
|
22
|
-
protected readonly config: {
|
23
|
-
jwtSecret: string;
|
24
|
-
expiresIn: number;
|
25
|
-
};
|
20
|
+
protected readonly userService_: ModulesSdkTypes.InternalModuleService<TUser>;
|
21
|
+
protected readonly inviteService_: InviteService<TInvite>;
|
26
22
|
constructor({ userService, inviteService, baseRepository }: InjectedDependencies, moduleDeclaration: InternalModuleDeclaration);
|
27
23
|
validateInviteToken(token: string, sharedContext?: Context): Promise<UserTypes.InviteDTO>;
|
28
24
|
refreshInviteTokens(inviteIds: string[], sharedContext?: Context): Promise<UserTypes.InviteDTO[]>;
|
29
|
-
refreshInviteTokens_(inviteIds: string[], sharedContext?: Context): Promise<
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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>;
|
34
30
|
createInvites(data: UserTypes.CreateInviteDTO[], sharedContext?: Context): Promise<UserTypes.InviteDTO[]>;
|
35
31
|
createInvites(data: UserTypes.CreateInviteDTO, sharedContext?: Context): Promise<UserTypes.InviteDTO>;
|
36
32
|
private createInvites_;
|
37
33
|
updateInvites(data: UserTypes.UpdateInviteDTO[], sharedContext?: Context): Promise<UserTypes.InviteDTO[]>;
|
38
34
|
updateInvites(data: UserTypes.UpdateInviteDTO, sharedContext?: Context): Promise<UserTypes.InviteDTO>;
|
39
|
-
private generateToken;
|
40
35
|
}
|
41
36
|
export {};
|
42
|
-
//# sourceMappingURL=user-module.d.ts.map
|
@@ -11,40 +11,25 @@ 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
|
-
};
|
17
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
18
15
|
const utils_1 = require("@medusajs/utils");
|
19
|
-
const
|
20
|
-
const node_crypto_1 = __importDefault(require("node:crypto"));
|
16
|
+
const joiner_config_1 = require("../joiner-config");
|
21
17
|
const _models_1 = require("../models");
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
+
}
|
25
23
|
constructor({ userService, inviteService, baseRepository }, moduleDeclaration) {
|
26
24
|
// @ts-ignore
|
27
25
|
super(...arguments);
|
28
26
|
this.moduleDeclaration = moduleDeclaration;
|
29
27
|
this.baseRepository_ = baseRepository;
|
30
28
|
this.userService_ = userService;
|
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
|
-
}
|
29
|
+
this.inviteService_ = inviteService.withModuleOptions(this.moduleDeclaration);
|
40
30
|
}
|
41
31
|
async validateInviteToken(token, sharedContext = {}) {
|
42
|
-
const
|
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
|
-
}
|
32
|
+
const invite = await this.inviteService_.validateInviteToken(token, sharedContext);
|
48
33
|
return await this.baseRepository_.serialize(invite, {
|
49
34
|
populate: true,
|
50
35
|
});
|
@@ -52,11 +37,12 @@ class UserModuleService extends (0, utils_1.MedusaService)({ User: _models_1.Use
|
|
52
37
|
async refreshInviteTokens(inviteIds, sharedContext = {}) {
|
53
38
|
const invites = await this.refreshInviteTokens_(inviteIds, sharedContext);
|
54
39
|
sharedContext.messageAggregator?.saveRawMessageData(invites.map((invite) => ({
|
55
|
-
eventName: utils_1.UserEvents.
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
40
|
+
eventName: utils_1.UserEvents.invite_token_generated,
|
41
|
+
metadata: {
|
42
|
+
service: this.constructor.name,
|
43
|
+
action: "token_generated",
|
44
|
+
object: "invite",
|
45
|
+
},
|
60
46
|
data: { id: invite.id },
|
61
47
|
})));
|
62
48
|
return await this.baseRepository_.serialize(invites, {
|
@@ -64,50 +50,38 @@ class UserModuleService extends (0, utils_1.MedusaService)({ User: _models_1.Use
|
|
64
50
|
});
|
65
51
|
}
|
66
52
|
async refreshInviteTokens_(inviteIds, sharedContext = {}) {
|
67
|
-
|
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 }),
|
79
|
-
};
|
80
|
-
});
|
81
|
-
return await this.inviteService_.update(updates, sharedContext);
|
53
|
+
return await this.inviteService_.refreshInviteTokens(inviteIds, sharedContext);
|
82
54
|
}
|
83
|
-
async
|
55
|
+
async create(data, sharedContext = {}) {
|
84
56
|
const input = Array.isArray(data) ? data : [data];
|
85
57
|
const users = await this.userService_.create(input, sharedContext);
|
86
58
|
const serializedUsers = await this.baseRepository_.serialize(users, {
|
87
59
|
populate: true,
|
88
60
|
});
|
89
61
|
sharedContext.messageAggregator?.saveRawMessageData(users.map((user) => ({
|
90
|
-
eventName: utils_1.UserEvents.
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
62
|
+
eventName: utils_1.UserEvents.created,
|
63
|
+
metadata: {
|
64
|
+
service: this.constructor.name,
|
65
|
+
action: utils_1.CommonEvents.CREATED,
|
66
|
+
object: "user",
|
67
|
+
},
|
95
68
|
data: { id: user.id },
|
96
69
|
})));
|
97
70
|
return Array.isArray(data) ? serializedUsers : serializedUsers[0];
|
98
71
|
}
|
99
|
-
async
|
72
|
+
async update(data, sharedContext = {}) {
|
100
73
|
const input = Array.isArray(data) ? data : [data];
|
101
74
|
const updatedUsers = await this.userService_.update(input, sharedContext);
|
102
75
|
const serializedUsers = await this.baseRepository_.serialize(updatedUsers, {
|
103
76
|
populate: true,
|
104
77
|
});
|
105
78
|
sharedContext.messageAggregator?.saveRawMessageData(updatedUsers.map((user) => ({
|
106
|
-
eventName: utils_1.UserEvents.
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
79
|
+
eventName: utils_1.UserEvents.updated,
|
80
|
+
metadata: {
|
81
|
+
service: this.constructor.name,
|
82
|
+
action: utils_1.CommonEvents.UPDATED,
|
83
|
+
object: "user",
|
84
|
+
},
|
111
85
|
data: { id: user.id },
|
112
86
|
})));
|
113
87
|
return Array.isArray(data) ? serializedUsers : serializedUsers[0];
|
@@ -119,19 +93,21 @@ class UserModuleService extends (0, utils_1.MedusaService)({ User: _models_1.Use
|
|
119
93
|
populate: true,
|
120
94
|
});
|
121
95
|
sharedContext.messageAggregator?.saveRawMessageData(invites.map((invite) => ({
|
122
|
-
eventName: utils_1.UserEvents.
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
96
|
+
eventName: utils_1.UserEvents.invite_created,
|
97
|
+
metadata: {
|
98
|
+
service: this.constructor.name,
|
99
|
+
action: utils_1.CommonEvents.CREATED,
|
100
|
+
object: "invite",
|
101
|
+
},
|
127
102
|
data: { id: invite.id },
|
128
103
|
})));
|
129
104
|
sharedContext.messageAggregator?.saveRawMessageData(invites.map((invite) => ({
|
130
|
-
eventName: utils_1.UserEvents.
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
105
|
+
eventName: utils_1.UserEvents.invite_token_generated,
|
106
|
+
metadata: {
|
107
|
+
service: this.constructor.name,
|
108
|
+
action: "token_generated",
|
109
|
+
object: "invite",
|
110
|
+
},
|
135
111
|
data: { id: invite.id },
|
136
112
|
})));
|
137
113
|
return Array.isArray(data) ? serializedInvites : serializedInvites[0];
|
@@ -144,15 +120,7 @@ class UserModuleService extends (0, utils_1.MedusaService)({ User: _models_1.Use
|
|
144
120
|
token: "placeholder",
|
145
121
|
};
|
146
122
|
});
|
147
|
-
|
148
|
-
const updates = created.map((invite) => {
|
149
|
-
return {
|
150
|
-
id: invite.id,
|
151
|
-
expires_at: new Date().setMilliseconds(new Date().getMilliseconds() + this.config.expiresIn),
|
152
|
-
token: this.generateToken({ id: invite.id }),
|
153
|
-
};
|
154
|
-
});
|
155
|
-
return await this.inviteService_.update(updates, sharedContext);
|
123
|
+
return await this.inviteService_.create(toCreate, sharedContext);
|
156
124
|
}
|
157
125
|
async updateInvites(data, sharedContext = {}) {
|
158
126
|
const input = Array.isArray(data) ? data : [data];
|
@@ -161,22 +129,16 @@ class UserModuleService extends (0, utils_1.MedusaService)({ User: _models_1.Use
|
|
161
129
|
populate: true,
|
162
130
|
});
|
163
131
|
sharedContext.messageAggregator?.saveRawMessageData(serializedInvites.map((invite) => ({
|
164
|
-
eventName: utils_1.UserEvents.
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
132
|
+
eventName: utils_1.UserEvents.invite_updated,
|
133
|
+
metadata: {
|
134
|
+
service: this.constructor.name,
|
135
|
+
action: utils_1.CommonEvents.UPDATED,
|
136
|
+
object: "invite",
|
137
|
+
},
|
169
138
|
data: { id: invite.id },
|
170
139
|
})));
|
171
140
|
return Array.isArray(data) ? serializedInvites : serializedInvites[0];
|
172
141
|
}
|
173
|
-
generateToken(data) {
|
174
|
-
const jwtSecret = this.moduleDeclaration["jwt_secret"];
|
175
|
-
return jsonwebtoken_1.default.sign(data, jwtSecret, {
|
176
|
-
jwtid: node_crypto_1.default.randomUUID(),
|
177
|
-
expiresIn: this.config.expiresIn,
|
178
|
-
});
|
179
|
-
}
|
180
142
|
}
|
181
143
|
exports.default = UserModuleService;
|
182
144
|
__decorate([
|
@@ -208,7 +170,7 @@ __decorate([
|
|
208
170
|
__metadata("design:type", Function),
|
209
171
|
__metadata("design:paramtypes", [Object, Object]),
|
210
172
|
__metadata("design:returntype", Promise)
|
211
|
-
], UserModuleService.prototype, "
|
173
|
+
], UserModuleService.prototype, "create", null);
|
212
174
|
__decorate([
|
213
175
|
(0, utils_1.InjectManager)("baseRepository_"),
|
214
176
|
(0, utils_1.EmitEvents)(),
|
@@ -216,7 +178,7 @@ __decorate([
|
|
216
178
|
__metadata("design:type", Function),
|
217
179
|
__metadata("design:paramtypes", [Object, Object]),
|
218
180
|
__metadata("design:returntype", Promise)
|
219
|
-
], UserModuleService.prototype, "
|
181
|
+
], UserModuleService.prototype, "update", null);
|
220
182
|
__decorate([
|
221
183
|
(0, utils_1.InjectManager)("baseRepository_"),
|
222
184
|
(0, utils_1.EmitEvents)(),
|
package/dist/types/index.d.ts
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@medusajs/user",
|
3
|
-
"version": "0.0.4
|
3
|
+
"version": "0.0.4",
|
4
4
|
"description": "Medusa Users module",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -8,7 +8,10 @@
|
|
8
8
|
"dist"
|
9
9
|
],
|
10
10
|
"engines": {
|
11
|
-
"node": ">=
|
11
|
+
"node": ">=16"
|
12
|
+
},
|
13
|
+
"bin": {
|
14
|
+
"medusa-user-seed": "dist/scripts/bin/run-seed.js"
|
12
15
|
},
|
13
16
|
"repository": {
|
14
17
|
"type": "git",
|
@@ -34,25 +37,26 @@
|
|
34
37
|
"orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm cache:clear"
|
35
38
|
},
|
36
39
|
"devDependencies": {
|
37
|
-
"@medusajs/modules-sdk": "1.13.0-snapshot-20240718073308",
|
38
|
-
"@medusajs/types": "1.12.0-snapshot-20240718073308",
|
39
40
|
"@mikro-orm/cli": "5.9.7",
|
40
|
-
"@swc/core": "^1.5.29",
|
41
|
-
"@swc/jest": "^0.2.36",
|
42
41
|
"cross-env": "^5.2.1",
|
43
|
-
"jest": "^29.
|
44
|
-
"medusa-test-utils": "1.1.45
|
42
|
+
"jest": "^29.6.3",
|
43
|
+
"medusa-test-utils": "^1.1.45",
|
45
44
|
"rimraf": "^3.0.2",
|
45
|
+
"ts-jest": "^29.1.1",
|
46
46
|
"ts-node": "^10.9.1",
|
47
47
|
"tsc-alias": "^1.8.6",
|
48
48
|
"typescript": "^5.1.6"
|
49
49
|
},
|
50
50
|
"dependencies": {
|
51
|
-
"@medusajs/
|
51
|
+
"@medusajs/modules-sdk": "^1.12.12",
|
52
|
+
"@medusajs/types": "^1.11.17",
|
53
|
+
"@medusajs/utils": "^1.11.10",
|
52
54
|
"@mikro-orm/core": "5.9.7",
|
53
55
|
"@mikro-orm/migrations": "5.9.7",
|
54
56
|
"@mikro-orm/postgresql": "5.9.7",
|
55
57
|
"awilix": "^8.0.0",
|
56
|
-
"
|
58
|
+
"dotenv": "^16.4.5",
|
59
|
+
"jsonwebtoken": "^9.0.2",
|
60
|
+
"knex": "2.4.2"
|
57
61
|
}
|
58
62
|
}
|
package/dist/index.d.ts.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;;;;AAG7C,wBAEE"}
|
@@ -1 +0,0 @@
|
|
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 +0,0 @@
|
|
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"}
|
@@ -1,16 +0,0 @@
|
|
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;
|
@@ -1 +0,0 @@
|
|
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"}
|
@@ -1 +0,0 @@
|
|
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,iBAAiB,CAAA;AAiCrC,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"}
|
@@ -1 +0,0 @@
|
|
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,iBAAiB,CAAA;AAyBrC,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"}
|
@@ -1 +0,0 @@
|
|
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"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"user-module.d.ts","sourceRoot":"","sources":["../../src/services/user-module.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,GAAG,EACH,sBAAsB,EACtB,yBAAyB,EACzB,eAAe,EACf,SAAS,EACV,MAAM,iBAAiB,CAAA;AAexB,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;IAC1D,qBAAqB,EAAE,sBAAsB,CAAA;CAC9C,CAAA;;UAMS;QACJ,GAAG,EAAE,UAAU,OAAO,CAAA;KACvB;YACO;QACN,GAAG,EAAE,UAAU,SAAS,CAAA;KACzB;;AAPL,MAAM,CAAC,OAAO,OAAO,iBACnB,SAAQ,sBAQR,YAAW,SAAS,CAAC,kBAAkB;IAUrC,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,yBAAyB;IARjE,SAAS,CAAC,eAAe,EAAE,GAAG,CAAC,iBAAiB,CAAA;IAEhD,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,eAAe,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAA;IAC7E,SAAS,CAAC,QAAQ,CAAC,cAAc,EAAE,eAAe,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAA;IACjF,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAA;gBAGjE,EAAE,WAAW,EAAE,aAAa,EAAE,cAAc,EAAE,EAAE,oBAAoB,EACjD,iBAAiB,EAAE,yBAAyB;IAwB3D,mBAAmB,CACvB,KAAK,EAAE,MAAM,EACI,aAAa,GAAE,OAAY,GAC3C,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC;IAwBzB,mBAAmB,CACvB,SAAS,EAAE,MAAM,EAAE,EACF,aAAa,GAAE,OAAY,GAC3C,OAAO,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC;IAuB3B,oBAAoB,CACxB,SAAS,EAAE,MAAM,EAAE,EACF,aAAa,GAAE,OAAY;IAoC9C,WAAW,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,WAAW,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;IA4B5B,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"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAExC,MAAM,MAAM,sCAAsC,GAAG;IACnD,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,cAAc,YAAY,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,kBAAkB,MAAM,UAAU,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"invite.d.ts","sourceRoot":"","sources":["../../../src/types/services/invite.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAA;CAC1C"}
|