New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@medusajs/modules-sdk

Package Overview
Dependencies
Maintainers
2
Versions
3119
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@medusajs/modules-sdk - npm Package Compare versions

Comparing version 1.8.8-snapshot-20230609171755 to 1.8.8-snapshot-20230612123033

6

dist/definitions.d.ts

@@ -6,3 +6,4 @@ import { ModuleDefinition } from "@medusajs/types";

INVENTORY = "inventoryService",
CACHE = "cacheService"
CACHE = "cacheService",
PRODUCT = "productModuleService"
}

@@ -13,2 +14,5 @@ export declare const ModulesDefinition: {

export declare const MODULE_DEFINITIONS: ModuleDefinition[];
export declare const MODULE_PACKAGE_NAMES: {
productModuleService: string;
};
export default MODULE_DEFINITIONS;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MODULE_DEFINITIONS = exports.ModulesDefinition = exports.Modules = void 0;
exports.MODULE_PACKAGE_NAMES = exports.MODULE_DEFINITIONS = exports.ModulesDefinition = exports.Modules = void 0;
const types_1 = require("@medusajs/types");

@@ -11,2 +11,3 @@ var Modules;

Modules["CACHE"] = "cacheService";
Modules["PRODUCT"] = "productModuleService";
})(Modules = exports.Modules || (exports.Modules = {}));

@@ -65,5 +66,20 @@ exports.ModulesDefinition = {

},
[Modules.PRODUCT]: {
key: Modules.PRODUCT,
registrationName: Modules.PRODUCT,
defaultPackage: false,
label: "ProductModuleService",
isRequired: false,
canOverride: true,
dependencies: [],
defaultModuleDeclaration: {
scope: types_1.MODULE_SCOPE.EXTERNAL,
},
},
};
exports.MODULE_DEFINITIONS = Object.values(exports.ModulesDefinition);
exports.MODULE_PACKAGE_NAMES = {
[Modules.PRODUCT]: "@medusajs/product",
};
exports.default = exports.MODULE_DEFINITIONS;
//# sourceMappingURL=definitions.js.map

10

dist/loaders/module-loader.js

@@ -11,5 +11,9 @@ "use strict";

async function loadModule(container, resolution, logger) {
const registrationName = resolution.definition.registrationName;
const modDefinition = resolution.definition;
const registrationName = modDefinition.registrationName;
const { scope, resources } = resolution.moduleDeclaration ?? {};
if (scope === types_1.MODULE_SCOPE.EXTERNAL) {
const canSkip = !resolution.resolutionPath &&
!modDefinition.isRequired &&
!modDefinition.defaultPackage;
if (scope === types_1.MODULE_SCOPE.EXTERNAL && !canSkip) {
// TODO: implement external Resolvers

@@ -31,3 +35,3 @@ // return loadExternalModule(...)

}
if (!resolution.resolutionPath) {
if (resolution.resolutionPath === false) {
container.register({

@@ -34,0 +38,0 @@ [registrationName]: (0, awilix_1.asValue)(undefined),

@@ -1,3 +0,3 @@

import { ExternalModuleDeclaration, InternalModuleDeclaration, ModuleResolution } from "@medusajs/types";
import { ExternalModuleDeclaration, InternalModuleDeclaration, ModuleExports, ModuleResolution } from "@medusajs/types";
export declare const registerModules: (modules?: Record<string, false | string | Partial<InternalModuleDeclaration | ExternalModuleDeclaration>>) => Record<string, ModuleResolution>;
export declare const registerMedusaModule: (moduleKey: string, moduleDeclaration: InternalModuleDeclaration | ExternalModuleDeclaration) => Record<string, ModuleResolution>;
export declare const registerMedusaModule: (moduleKey: string, moduleDeclaration: InternalModuleDeclaration | ExternalModuleDeclaration, moduleExports?: ModuleExports) => Record<string, ModuleResolution>;

@@ -8,2 +8,3 @@ "use strict";

const types_1 = require("@medusajs/types");
const utils_1 = require("@medusajs/utils");
const resolve_cwd_1 = __importDefault(require("resolve-cwd"));

@@ -16,6 +17,9 @@ const definitions_1 = __importDefault(require("../definitions"));

const customConfig = projectModules[definition.key];
const isObj = typeof customConfig === "object";
const canSkip = !customConfig && !definition.isRequired && !definition.defaultPackage;
const isObj = (0, utils_1.isObject)(customConfig);
if (isObj && customConfig.scope === types_1.MODULE_SCOPE.EXTERNAL) {
// TODO: getExternalModuleResolution(...)
throw new Error("External Modules are not supported yet.");
if (!canSkip) {
throw new Error("External Modules are not supported yet.");
}
}

@@ -27,3 +31,3 @@ moduleResolutions[definition.key] = getInternalModuleResolution(definition, customConfig);

exports.registerModules = registerModules;
const registerMedusaModule = (moduleKey, moduleDeclaration) => {
const registerMedusaModule = (moduleKey, moduleDeclaration, moduleExports) => {
const moduleResolutions = {};

@@ -38,3 +42,3 @@ for (const definition of definitions_1.default) {

}
moduleResolutions[definition.key] = getInternalModuleResolution(definition, moduleDeclaration);
moduleResolutions[definition.key] = getInternalModuleResolution(definition, moduleDeclaration, moduleExports);
}

@@ -44,3 +48,3 @@ return moduleResolutions;

exports.registerMedusaModule = registerMedusaModule;
function getInternalModuleResolution(definition, moduleConfig) {
function getInternalModuleResolution(definition, moduleConfig, moduleExports) {
if (typeof moduleConfig === "boolean") {

@@ -64,3 +68,7 @@ if (!moduleConfig && definition.isRequired) {

if (definition.canOverride && (isString || (isObj && moduleConfig.resolve))) {
resolutionPath = (0, resolve_cwd_1.default)(isString ? moduleConfig : moduleConfig.resolve);
resolutionPath = !moduleExports
? (0, resolve_cwd_1.default)(isString ? moduleConfig : moduleConfig.resolve)
: // Explicitly assign an empty string, later, we will check if the value is exactly false.
// This allows to continue the module loading while using the module exports instead of re importing the module itself during the process.
"";
}

@@ -79,2 +87,3 @@ const moduleDeclaration = isObj ? moduleConfig : {};

},
moduleExports,
options: isObj ? moduleConfig.options ?? {} : {},

@@ -81,0 +90,0 @@ };

@@ -30,3 +30,2 @@ "use strict";

const awilix_1 = require("awilix");
const medusa_telemetry_1 = require("medusa-telemetry");
async function loadInternalModule(container, resolution, logger) {

@@ -37,3 +36,9 @@ const registrationName = resolution.definition.registrationName;

try {
loadedModule = (await Promise.resolve().then(() => __importStar(require(resolution.resolutionPath)))).default;
// When loading manually, we pass the exports to be loaded, meaning that we do not need to import the package to find
// the exports. This is useful when a package export an initialize function which will bootstrap itself and therefore
// does not need to import the package that is currently being loaded as it would create a
// circular reference.
loadedModule =
resolution.moduleExports ??
(await Promise.resolve().then(() => __importStar(require(resolution.resolutionPath)))).default;
}

@@ -103,6 +108,2 @@ catch (error) {

});
(0, medusa_telemetry_1.trackInstallation)({
module: resolution.definition.key,
resolution: resolution.resolutionPath,
}, "module");
}

@@ -109,0 +110,0 @@ exports.loadInternalModule = loadInternalModule;

@@ -1,5 +0,6 @@

import { ExternalModuleDeclaration, InternalModuleDeclaration } from "@medusajs/types";
import { ExternalModuleDeclaration, InternalModuleDeclaration, ModuleExports } from "@medusajs/types";
export declare class MedusaModule {
private static instances_;
static bootstrap(moduleKey: string, defaultPath: string, declaration?: InternalModuleDeclaration | ExternalModuleDeclaration, injectedDependencies?: Record<string, any>): Promise<{
static clearInstances(): void;
static bootstrap(moduleKey: string, defaultPath: string, declaration?: InternalModuleDeclaration | ExternalModuleDeclaration, moduleExports?: ModuleExports, injectedDependencies?: Record<string, any>): Promise<{
[key: string]: any;

@@ -6,0 +7,0 @@ }>;

@@ -16,5 +16,9 @@ "use strict";

class MedusaModule {
static async bootstrap(moduleKey, defaultPath, declaration, injectedDependencies) {
if (MedusaModule.instances_.has(moduleKey)) {
return MedusaModule.instances_.get(moduleKey);
static clearInstances() {
MedusaModule.instances_.clear();
}
static async bootstrap(moduleKey, defaultPath, declaration, moduleExports, injectedDependencies) {
const hashKey = (0, utils_1.simpleHash)((0, utils_1.stringifyCircular)({ moduleKey, defaultPath, declaration }));
if (MedusaModule.instances_.has(hashKey)) {
return MedusaModule.instances_.get(hashKey);
}

@@ -36,4 +40,8 @@ let modDeclaration = declaration;

}
const moduleResolutions = (0, loaders_1.registerMedusaModule)(moduleKey, modDeclaration);
await (0, loaders_1.moduleLoader)({ container, moduleResolutions, logger });
const moduleResolutions = (0, loaders_1.registerMedusaModule)(moduleKey, modDeclaration, moduleExports);
await (0, loaders_1.moduleLoader)({
container,
moduleResolutions,
logger,
});
const services = {};

@@ -45,3 +53,3 @@ for (const resolution of Object.values(moduleResolutions)) {

}
MedusaModule.instances_.set(moduleKey, services);
MedusaModule.instances_.set(hashKey, services);
return services;

@@ -48,0 +56,0 @@ }

{
"name": "@medusajs/modules-sdk",
"version": "1.8.8-snapshot-20230609171755",
"version": "1.8.8-snapshot-20230612123033",
"description": "SDK for medusa modules",

@@ -26,7 +26,5 @@ "main": "dist/index.js",

"dependencies": {
"@medusajs/types": "1.8.8-snapshot-20230609171755",
"@medusajs/utils": "1.9.0",
"@medusajs/types": "1.8.8-snapshot-20230612123033",
"@medusajs/utils": "1.9.1-snapshot-20230612123033",
"awilix": "^8.0.0",
"glob": "7.1.6",
"medusa-telemetry": "^0.0.16",
"resolve-cwd": "^3.0.0"

@@ -37,4 +35,5 @@ },

"build": "tsc --build",
"test": "jest"
"test": "jest",
"watch": "tsc --build --watch"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc