refactor(modules-sdk): Align configuration and fixes (#9239)
* refactor(modules-sdk): Align configuration and fixes * typo * fix configuration
This commit is contained in:
1 parent
d0f1028820
commit
919d19095a
10 files changed
+88
-42
No files matched your search
@@ -1,15 +1,17 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
transform: {
|
transform: {
|
||||||
"^.+\\.[jt]s?$": [
|
"^.+\\.[jt]s$": [
|
||||||
"@swc/jest",
|
"@swc/jest",
|
||||||
{
|
{
|
||||||
jsc: {
|
jsc: {
|
||||||
parser: { syntax: "typescript", decorators: true },
|
parser: { syntax: "typescript", decorators: true },
|
||||||
transform: { decoratorMetadata: true },
|
transform: { decoratorMetadata: true },
|
||||||
|
target: "ES2021",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
testPathIgnorePatterns: [`dist/`, `node_modules/`],
|
||||||
testEnvironment: `node`,
|
testEnvironment: `node`,
|
||||||
moduleFileExtensions: [`js`, `ts`],
|
moduleFileExtensions: [`js`, `ts`],
|
||||||
}
|
}
|
||||||
@@ -3,28 +3,39 @@
|
|||||||
"version": "1.12.11",
|
"version": "1.12.11",
|
||||||
"description": "SDK for medusa modules",
|
"description": "SDK for medusa modules",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
"export": {
|
||||||
|
".": "./dist/index.js"
|
||||||
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/medusajs/medusa",
|
"url": "https://github.com/medusajs/medusa",
|
||||||
"directory": "packages/modules-sdk"
|
"directory": "packages/modules-sdk"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16"
|
"node": ">=20"
|
||||||
},
|
},
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"dist"
|
"dist",
|
||||||
|
"!dist/**/__tests__",
|
||||||
|
"!dist/**/__fixtures__",
|
||||||
|
"!dist/**/__mocks__"
|
||||||
],
|
],
|
||||||
"author": "Medusa",
|
"author": "Medusa",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
"scripts": {
|
||||||
|
"build": "rimraf dist && tsc --build",
|
||||||
|
"test": "jest --runInBand --bail --forceExit",
|
||||||
|
"watch": "tsc --build --watch"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@medusajs/types": "^1.11.16",
|
"@medusajs/types": "^1.11.16",
|
||||||
"cross-env": "^5.2.1",
|
"cross-env": "^5.2.1",
|
||||||
"jest": "^29.7.0",
|
"jest": "^29.7.0",
|
||||||
"rimraf": "^5.0.1",
|
"rimraf": "^5.0.1",
|
||||||
"typescript": "^5.1.6"
|
"typescript": "^5.6.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@graphql-codegen/cli": "^5.0.2",
|
"@graphql-codegen/cli": "^5.0.2",
|
||||||
@@ -39,10 +50,5 @@
|
|||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@mikro-orm/core": "5.9.7",
|
"@mikro-orm/core": "5.9.7",
|
||||||
"awilix": "^8.0.1"
|
"awilix": "^8.0.1"
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"build": "rimraf dist && tsc --build",
|
|
||||||
"test": "jest --runInBand --bail --forceExit",
|
|
||||||
"watch": "tsc --build --watch"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -129,7 +129,7 @@ describe("Medusa Modules", () => {
|
|||||||
} as InternalModuleDeclaration,
|
} as InternalModuleDeclaration,
|
||||||
})
|
})
|
||||||
|
|
||||||
const moduleB = await MedusaModule.bootstrap({
|
await MedusaModule.bootstrap({
|
||||||
moduleKey: "moduleKey",
|
moduleKey: "moduleKey",
|
||||||
defaultPath: "@path",
|
defaultPath: "@path",
|
||||||
declaration: {
|
declaration: {
|
||||||
@@ -146,7 +146,7 @@ describe("Medusa Modules", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("should return the module flagged as 'main' when multiple instances are available", async () => {
|
it("should return the module flagged as 'main' when multiple instances are available", async () => {
|
||||||
const moduleA = await MedusaModule.bootstrap({
|
await MedusaModule.bootstrap({
|
||||||
moduleKey: "moduleKey",
|
moduleKey: "moduleKey",
|
||||||
defaultPath: "@path",
|
defaultPath: "@path",
|
||||||
declaration: {
|
declaration: {
|
||||||
|
|||||||
@@ -2,11 +2,6 @@ import { createMedusaContainer } from "@medusajs/utils"
|
|||||||
import { asFunction, Lifetime } from "awilix"
|
import { asFunction, Lifetime } from "awilix"
|
||||||
import { moduleProviderLoader } from "../module-provider-loader"
|
import { moduleProviderLoader } from "../module-provider-loader"
|
||||||
|
|
||||||
const logger = {
|
|
||||||
warn: jest.fn(),
|
|
||||||
error: jest.fn(),
|
|
||||||
} as any
|
|
||||||
|
|
||||||
describe("modules loader", () => {
|
describe("modules loader", () => {
|
||||||
let container
|
let container
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ describe("load internal - load resources", () => {
|
|||||||
|
|
||||||
const generatedJoinerConfig = (
|
const generatedJoinerConfig = (
|
||||||
resources.moduleService.prototype as IModuleService
|
resources.moduleService.prototype as IModuleService
|
||||||
).__joinerConfig()
|
).__joinerConfig?.()!
|
||||||
|
|
||||||
expect(generatedJoinerConfig).toEqual(
|
expect(generatedJoinerConfig).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
@@ -141,7 +141,7 @@ describe("load internal - load resources", () => {
|
|||||||
|
|
||||||
const generatedJoinerConfig = (
|
const generatedJoinerConfig = (
|
||||||
resources.moduleService.prototype as IModuleService
|
resources.moduleService.prototype as IModuleService
|
||||||
).__joinerConfig()
|
).__joinerConfig?.()!
|
||||||
|
|
||||||
expect(generatedJoinerConfig).toEqual(
|
expect(generatedJoinerConfig).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
@@ -221,7 +221,7 @@ describe("load internal - load resources", () => {
|
|||||||
|
|
||||||
const generatedJoinerConfig = (
|
const generatedJoinerConfig = (
|
||||||
resources.moduleService.prototype as IModuleService
|
resources.moduleService.prototype as IModuleService
|
||||||
).__joinerConfig()
|
).__joinerConfig?.()!
|
||||||
|
|
||||||
expect(generatedJoinerConfig).toEqual({
|
expect(generatedJoinerConfig).toEqual({
|
||||||
serviceName: "module-without-joiner-config",
|
serviceName: "module-without-joiner-config",
|
||||||
@@ -296,7 +296,7 @@ describe("load internal - load resources", () => {
|
|||||||
|
|
||||||
const generatedJoinerConfig = (
|
const generatedJoinerConfig = (
|
||||||
resources.moduleService.prototype as IModuleService
|
resources.moduleService.prototype as IModuleService
|
||||||
).__joinerConfig()
|
).__joinerConfig?.()!
|
||||||
|
|
||||||
expect(generatedJoinerConfig).toEqual({
|
expect(generatedJoinerConfig).toEqual({
|
||||||
serviceName: "module-service",
|
serviceName: "module-service",
|
||||||
|
|||||||
@@ -472,8 +472,7 @@ export class RemoteLink {
|
|||||||
|
|
||||||
for (const link of allLinks) {
|
for (const link of allLinks) {
|
||||||
const service = this.getLinkModuleOrThrow(link)
|
const service = this.getLinkModuleOrThrow(link)
|
||||||
const { moduleA, moduleB, moduleBKey, primaryKeys } =
|
const { moduleA, moduleB } = this.getLinkDataConfig(link)
|
||||||
this.getLinkDataConfig(link)
|
|
||||||
|
|
||||||
if (!serviceLinks.has(service.__definition.key)) {
|
if (!serviceLinks.has(service.__definition.key)) {
|
||||||
serviceLinks.set(service.__definition.key, [])
|
serviceLinks.set(service.__definition.key, [])
|
||||||
|
|||||||
@@ -51,6 +51,16 @@ export type Product = {
|
|||||||
sales_channels_link?: Array<LinkProductSalesChannel>
|
sales_channels_link?: Array<LinkProductSalesChannel>
|
||||||
sales_channels?: Array<SalesChannel>
|
sales_channels?: Array<SalesChannel>
|
||||||
metadata?: Maybe<Scalars["JSON"]["output"]>
|
metadata?: Maybe<Scalars["JSON"]["output"]>
|
||||||
|
translation?: Maybe<ProductTranslation>
|
||||||
|
categories?: Array<ProductCategory>
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ProductTranslation = {
|
||||||
|
__typename?: "ProductTranslation"
|
||||||
|
id: Scalars["ID"]["output"]
|
||||||
|
title: Scalars["String"]["output"]
|
||||||
|
description: Scalars["String"]["output"]
|
||||||
|
product?: Maybe<Product>
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ProductVariant = {
|
export type ProductVariant = {
|
||||||
@@ -60,6 +70,16 @@ export type ProductVariant = {
|
|||||||
title: Scalars["String"]["output"]
|
title: Scalars["String"]["output"]
|
||||||
sku: Scalars["String"]["output"]
|
sku: Scalars["String"]["output"]
|
||||||
product?: Maybe<Product>
|
product?: Maybe<Product>
|
||||||
|
calculated_price?: Maybe<Scalars["JSON"]["output"]>
|
||||||
|
translation?: Maybe<ProductVariantTranslation>
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ProductVariantTranslation = {
|
||||||
|
__typename?: "ProductVariantTranslation"
|
||||||
|
id: Scalars["ID"]["output"]
|
||||||
|
title: Scalars["String"]["output"]
|
||||||
|
description: Scalars["String"]["output"]
|
||||||
|
variant?: Maybe<ProductVariant>
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ProductCategory = {
|
export type ProductCategory = {
|
||||||
@@ -67,6 +87,15 @@ export type ProductCategory = {
|
|||||||
id: Scalars["ID"]["output"]
|
id: Scalars["ID"]["output"]
|
||||||
handle: Scalars["String"]["output"]
|
handle: Scalars["String"]["output"]
|
||||||
title?: Maybe<Scalars["String"]["output"]>
|
title?: Maybe<Scalars["String"]["output"]>
|
||||||
|
translation?: Maybe<ProductCategoryTranslation>
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ProductCategoryTranslation = {
|
||||||
|
__typename?: "ProductCategoryTranslation"
|
||||||
|
id: Scalars["ID"]["output"]
|
||||||
|
title: Scalars["String"]["output"]
|
||||||
|
description: Scalars["String"]["output"]
|
||||||
|
category?: Maybe<ProductCategory>
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SalesChannel = {
|
export type SalesChannel = {
|
||||||
|
|||||||
@@ -107,7 +107,6 @@ describe("toRemoteQuery", () => {
|
|||||||
"description",
|
"description",
|
||||||
"variants.title",
|
"variants.title",
|
||||||
"variants.calculated_price",
|
"variants.calculated_price",
|
||||||
"variants.options.*",
|
|
||||||
],
|
],
|
||||||
filters: {
|
filters: {
|
||||||
variants: {
|
variants: {
|
||||||
@@ -150,9 +149,6 @@ describe("toRemoteQuery", () => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
__fields: ["title", "calculated_price"],
|
__fields: ["title", "calculated_price"],
|
||||||
options: {
|
|
||||||
__fields: ["*"],
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -172,22 +168,22 @@ describe("toRemoteQuery", () => {
|
|||||||
"id",
|
"id",
|
||||||
"title",
|
"title",
|
||||||
"description",
|
"description",
|
||||||
"product_translation.*",
|
"translation.*",
|
||||||
"categories.*",
|
"categories.*",
|
||||||
"categories.category_translation.*",
|
"categories.translation.*",
|
||||||
"variants.*",
|
"variants.*",
|
||||||
"variants.variant_translation.*",
|
"variants.translation.*",
|
||||||
],
|
],
|
||||||
filters: {
|
filters: {
|
||||||
id: "prod_01J742X0QPFW3R2ZFRTRC34FS8",
|
id: "prod_01J742X0QPFW3R2ZFRTRC34FS8",
|
||||||
},
|
},
|
||||||
context: {
|
context: {
|
||||||
product_translation: langContext,
|
translation: langContext,
|
||||||
categories: {
|
categories: {
|
||||||
category_translation: langContext,
|
translation: langContext,
|
||||||
},
|
},
|
||||||
variants: {
|
variants: {
|
||||||
variant_translation: langContext,
|
translation: langContext,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -202,7 +198,7 @@ describe("toRemoteQuery", () => {
|
|||||||
id: "prod_01J742X0QPFW3R2ZFRTRC34FS8",
|
id: "prod_01J742X0QPFW3R2ZFRTRC34FS8",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
product_translation: {
|
translation: {
|
||||||
__args: {
|
__args: {
|
||||||
context: {
|
context: {
|
||||||
context: {
|
context: {
|
||||||
@@ -213,7 +209,7 @@ describe("toRemoteQuery", () => {
|
|||||||
__fields: ["*"],
|
__fields: ["*"],
|
||||||
},
|
},
|
||||||
categories: {
|
categories: {
|
||||||
category_translation: {
|
translation: {
|
||||||
__args: {
|
__args: {
|
||||||
context: {
|
context: {
|
||||||
context: {
|
context: {
|
||||||
@@ -226,7 +222,7 @@ describe("toRemoteQuery", () => {
|
|||||||
__fields: ["*"],
|
__fields: ["*"],
|
||||||
},
|
},
|
||||||
variants: {
|
variants: {
|
||||||
variant_translation: {
|
translation: {
|
||||||
__args: {
|
__args: {
|
||||||
context: {
|
context: {
|
||||||
context: {
|
context: {
|
||||||
|
|||||||
@@ -8,22 +8,21 @@
|
|||||||
"declaration": true,
|
"declaration": true,
|
||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
|
"noUnusedLocals": true,
|
||||||
"emitDecoratorMetadata": true,
|
"emitDecoratorMetadata": true,
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"noImplicitReturns": true,
|
"noImplicitReturns": true,
|
||||||
"strictNullChecks": true,
|
"strictNullChecks": true,
|
||||||
"strictFunctionTypes": true,
|
"strictFunctionTypes": true,
|
||||||
"noImplicitThis": true,
|
"noImplicitThis": true,
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true
|
||||||
"downlevelIteration": true // to use ES5 specific tooling
|
|
||||||
},
|
},
|
||||||
"include": ["./src/**/*"],
|
"include": ["src"],
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"./dist/**/*",
|
"dist",
|
||||||
"./src/**/__tests__",
|
|
||||||
"./src/**/__mocks__",
|
|
||||||
"node_modules"
|
"node_modules"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -6252,7 +6252,7 @@ __metadata:
|
|||||||
jest: ^29.7.0
|
jest: ^29.7.0
|
||||||
resolve-cwd: ^3.0.0
|
resolve-cwd: ^3.0.0
|
||||||
rimraf: ^5.0.1
|
rimraf: ^5.0.1
|
||||||
typescript: ^5.1.6
|
typescript: ^5.6.2
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
"@mikro-orm/core": 5.9.7
|
"@mikro-orm/core": 5.9.7
|
||||||
awilix: ^8.0.1
|
awilix: ^8.0.1
|
||||||
@@ -32686,6 +32686,16 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"typescript@npm:^5.6.2":
|
||||||
|
version: 5.6.2
|
||||||
|
resolution: "typescript@npm:5.6.2"
|
||||||
|
bin:
|
||||||
|
tsc: bin/tsc
|
||||||
|
tsserver: bin/tsserver
|
||||||
|
checksum: 3ed8297a8c7c56b7fec282532503d1ac795239d06e7c4966b42d4330c6cf433a170b53bcf93a130a7f14ccc5235de5560df4f1045eb7f3550b46ebed16d3c5e5
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"typescript@patch:typescript@4.9.5#~builtin<compat/typescript>, typescript@patch:typescript@^4.1.3#~builtin<compat/typescript>":
|
"typescript@patch:typescript@4.9.5#~builtin<compat/typescript>, typescript@patch:typescript@^4.1.3#~builtin<compat/typescript>":
|
||||||
version: 4.9.5
|
version: 4.9.5
|
||||||
resolution: "typescript@patch:typescript@npm%3A4.9.5#~builtin<compat/typescript>::version=4.9.5&hash=7ad353"
|
resolution: "typescript@patch:typescript@npm%3A4.9.5#~builtin<compat/typescript>::version=4.9.5&hash=7ad353"
|
||||||
@@ -32746,6 +32756,16 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"typescript@patch:typescript@^5.6.2#~builtin<compat/typescript>":
|
||||||
|
version: 5.6.2
|
||||||
|
resolution: "typescript@patch:typescript@npm%3A5.6.2#~builtin<compat/typescript>::version=5.6.2&hash=7ad353"
|
||||||
|
bin:
|
||||||
|
tsc: bin/tsc
|
||||||
|
tsserver: bin/tsserver
|
||||||
|
checksum: e6c1662e4852e22fe4bbdca471dca3e3edc74f6f1df043135c44a18a7902037023ccb0abdfb754595ca9028df8920f2f8492c00fc3cbb4309079aae8b7de71cd
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"ua-parser-js@npm:^1.0.35":
|
"ua-parser-js@npm:^1.0.35":
|
||||||
version: 1.0.37
|
version: 1.0.37
|
||||||
resolution: "ua-parser-js@npm:1.0.37"
|
resolution: "ua-parser-js@npm:1.0.37"
|
||||||
|
|||||||
Reference in new issue
Block a user