breaking: move shared HTTP utils to the framework (#9402)
Fixes: FRMW-2728, FRMW-2729 After this PR gets merged the following middleware will be exported from the `@medusajs/framework/http` import path. - applyParamsAsFilters - clearFiltersByKey - applyDefaultFilters - setContext - getQueryConfig - httpCompression - maybeApplyLinkFilter - refetchEntities - unlessPath - validateBody - validateQuery Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
This commit is contained in:
@@ -25,7 +25,10 @@ import {
|
||||
installNextjsStarter,
|
||||
startNextjsStarter,
|
||||
} from "../utils/nextjs-utils.js"
|
||||
import { getNodeVersion, MIN_SUPPORTED_NODE_VERSION } from "../utils/node-version.js"
|
||||
import {
|
||||
getNodeVersion,
|
||||
MIN_SUPPORTED_NODE_VERSION,
|
||||
} from "../utils/node-version.js"
|
||||
|
||||
const slugify = slugifyType.default
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { EOL } from "os"
|
||||
import pg from "pg"
|
||||
import postgresClient, { DEFAULT_HOST, DEFAULT_PORT } from "./postgres-client.js"
|
||||
import postgresClient, {
|
||||
DEFAULT_HOST,
|
||||
DEFAULT_PORT,
|
||||
} from "./postgres-client.js"
|
||||
import inquirer from "inquirer"
|
||||
import logMessage from "./log-message.js"
|
||||
import formatConnectionString from "./format-connection-string.js"
|
||||
@@ -16,8 +19,13 @@ export default async function createDb({ client, db }: CreateDbOptions) {
|
||||
await client.query(`CREATE DATABASE "${db}"`)
|
||||
}
|
||||
|
||||
async function doesDbExist (client: pg.Client, dbName: string): Promise<boolean> {
|
||||
const result = await client.query(`SELECT datname FROM pg_catalog.pg_database WHERE datname='${dbName}';`)
|
||||
async function doesDbExist(
|
||||
client: pg.Client,
|
||||
dbName: string
|
||||
): Promise<boolean> {
|
||||
const result = await client.query(
|
||||
`SELECT datname FROM pg_catalog.pg_database WHERE datname='${dbName}';`
|
||||
)
|
||||
|
||||
return !!result.rowCount
|
||||
}
|
||||
@@ -75,14 +83,14 @@ async function getForDbName({
|
||||
|
||||
const defaultConnectionOptions = {
|
||||
host: DEFAULT_HOST,
|
||||
port: DEFAULT_PORT
|
||||
port: DEFAULT_PORT,
|
||||
}
|
||||
|
||||
try {
|
||||
client = await postgresClient({
|
||||
user: postgresUsername,
|
||||
password: postgresPassword,
|
||||
...defaultConnectionOptions
|
||||
...defaultConnectionOptions,
|
||||
})
|
||||
} catch (e) {
|
||||
if (verbose) {
|
||||
@@ -129,7 +137,7 @@ async function getForDbName({
|
||||
user: postgresUsername,
|
||||
password: postgresPassword,
|
||||
database: userDbName,
|
||||
...defaultConnectionOptions
|
||||
...defaultConnectionOptions,
|
||||
})
|
||||
} catch (e) {
|
||||
logMessage({
|
||||
@@ -148,7 +156,9 @@ async function getForDbName({
|
||||
message: `A database already exists with the name ${dbName}, please enter a name for the database:`,
|
||||
default: dbName,
|
||||
validate: (input) => {
|
||||
return typeof input === "string" && input.length > 0 && input !== dbName
|
||||
return (
|
||||
typeof input === "string" && input.length > 0 && input !== dbName
|
||||
)
|
||||
},
|
||||
},
|
||||
])
|
||||
@@ -167,7 +177,7 @@ async function getForDbName({
|
||||
return {
|
||||
client,
|
||||
dbConnectionString,
|
||||
dbName
|
||||
dbName,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ const facts = [
|
||||
"The event bus module is responsible for triggering events and relaying them to subscribers.",
|
||||
"The cache module is responsible for caching data that requires heavy computation.",
|
||||
"A workflow is a series of steps that are defined once and executed anywhere. Workflows are created under the src/workflows directory.",
|
||||
"A workflow's steps can be retried or rolled back in case of an error."
|
||||
"A workflow's steps can be retried or rolled back in case of an error.",
|
||||
]
|
||||
|
||||
export const getFact = () => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import inquirer from "inquirer"
|
||||
import { exec } from "child_process"
|
||||
import execute from "./execute.js"
|
||||
import { FactBoxOptions, displayFactBox } from "./facts.js"
|
||||
import { displayFactBox, FactBoxOptions } from "./facts.js"
|
||||
import fs from "fs"
|
||||
import path from "path"
|
||||
import { customAlphabet } from "nanoid"
|
||||
@@ -37,7 +37,7 @@ export async function installNextjsStarter({
|
||||
abortController,
|
||||
factBoxOptions,
|
||||
verbose = false,
|
||||
processManager
|
||||
processManager,
|
||||
}: InstallOptions): Promise<string> {
|
||||
factBoxOptions.interval = displayFactBox({
|
||||
...factBoxOptions,
|
||||
@@ -72,7 +72,7 @@ export async function installNextjsStarter({
|
||||
)
|
||||
const execOptions = {
|
||||
signal: abortController?.signal,
|
||||
cwd: nextjsDirectory
|
||||
cwd: nextjsDirectory,
|
||||
}
|
||||
await processManager.runProcess({
|
||||
process: async () => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export function getNodeVersion(): number {
|
||||
const [major] = process.versions.node.split('.').map(Number)
|
||||
const [major] = process.versions.node.split(".").map(Number)
|
||||
|
||||
return major
|
||||
}
|
||||
|
||||
export const MIN_SUPPORTED_NODE_VERSION = 20
|
||||
export const MIN_SUPPORTED_NODE_VERSION = 20
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import pg from "pg"
|
||||
|
||||
const { Client } = pg
|
||||
|
||||
export const DEFAULT_HOST = "localhost"
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/utils": "1.11.9",
|
||||
"@types/express": "^4.17.17",
|
||||
"chalk": "^4.0.0",
|
||||
"configstore": "5.0.1",
|
||||
"dotenv": "^16.4.5",
|
||||
|
||||
@@ -22,10 +22,7 @@ import reporter from "../reporter"
|
||||
import { getPackageManager, setPackageManager } from "../util/package-manager"
|
||||
import { PanicId } from "../reporter/panic-handler"
|
||||
import { clearProject } from "../util/clear-project"
|
||||
import {
|
||||
getNodeVersion,
|
||||
MIN_SUPPORTED_NODE_VERSION,
|
||||
} from "@medusajs/utils"
|
||||
import { getNodeVersion, MIN_SUPPORTED_NODE_VERSION } from "@medusajs/utils"
|
||||
|
||||
const removeUndefined = (obj) => {
|
||||
return Object.fromEntries(
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
const signalExit = require(`signal-exit`);
|
||||
const signalExit = require(`signal-exit`)
|
||||
|
||||
const cleanupTasks = new Set();
|
||||
const cleanupTasks = new Set()
|
||||
|
||||
exports.registerCleanupTask = (taskFn) => {
|
||||
cleanupTasks.add(taskFn);
|
||||
cleanupTasks.add(taskFn)
|
||||
return () => {
|
||||
const result = taskFn();
|
||||
cleanupTasks.delete(taskFn);
|
||||
return result;
|
||||
};
|
||||
};
|
||||
const result = taskFn()
|
||||
cleanupTasks.delete(taskFn)
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
signalExit(() => {
|
||||
if (cleanupTasks.size) {
|
||||
console.log(`Process exitted in middle of publishing - cleaning up`);
|
||||
cleanupTasks.forEach((taskFn) => taskFn());
|
||||
console.log(`Process exitted in middle of publishing - cleaning up`)
|
||||
cleanupTasks.forEach((taskFn) => taskFn())
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
@@ -15,7 +15,7 @@ const getDependantPackages = ({
|
||||
packagesToPublish.add(packageName)
|
||||
const dependants = depTree[packageName]
|
||||
if (dependants) {
|
||||
dependants.forEach(dependant =>
|
||||
dependants.forEach((dependant) =>
|
||||
getDependantPackages({
|
||||
packageName: dependant,
|
||||
depTree,
|
||||
|
||||
@@ -5,7 +5,7 @@ const defaultSpawnArgs = {
|
||||
stdio: `inherit`,
|
||||
}
|
||||
|
||||
exports.setDefaultSpawnStdio = stdio => {
|
||||
exports.setDefaultSpawnStdio = (stdio) => {
|
||||
defaultSpawnArgs.stdio = stdio
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
exports.getVersionInfo = () => {
|
||||
const { version: devCliVersion } = require(`../../package.json`);
|
||||
return `Medusa Dev CLI version: ${devCliVersion}`;
|
||||
};
|
||||
const { version: devCliVersion } = require(`../../package.json`)
|
||||
return `Medusa Dev CLI version: ${devCliVersion}`
|
||||
}
|
||||
|
||||
@@ -10,13 +10,23 @@ import execa from "execa"
|
||||
|
||||
/**
|
||||
* OAS output directory
|
||||
*
|
||||
*
|
||||
* @privateRemarks
|
||||
* This should be the only directory OAS is loaded from for Medusa V2.
|
||||
* For now, we only use it if the --v2 flag it passed to the CLI tool.
|
||||
*/
|
||||
const oasOutputPath = path.resolve(
|
||||
__dirname, "..", "..", "..", "..", "..", "..", "www", "utils", "generated", "oas-output"
|
||||
__dirname,
|
||||
"..",
|
||||
"..",
|
||||
"..",
|
||||
"..",
|
||||
"..",
|
||||
"..",
|
||||
"www",
|
||||
"utils",
|
||||
"generated",
|
||||
"oas-output"
|
||||
)
|
||||
const basePath = path.resolve(__dirname, `../../`)
|
||||
|
||||
@@ -128,7 +138,13 @@ describe("command oas", () => {
|
||||
|
||||
beforeAll(async () => {
|
||||
const outDir = path.resolve(tmpDir, uid())
|
||||
await runCLI("oas", ["--type", "combined", "--out-dir", outDir, "--local"])
|
||||
await runCLI("oas", [
|
||||
"--type",
|
||||
"combined",
|
||||
"--out-dir",
|
||||
outDir,
|
||||
"--local",
|
||||
])
|
||||
const generatedFilePath = path.resolve(outDir, "combined.oas.json")
|
||||
oas = (await readJson(generatedFilePath)) as OpenAPIObject
|
||||
})
|
||||
@@ -227,7 +243,7 @@ describe("command oas", () => {
|
||||
outDir,
|
||||
"--paths",
|
||||
additionalPath,
|
||||
"--local"
|
||||
"--local",
|
||||
])
|
||||
const generatedFilePath = path.resolve(outDir, "store.oas.json")
|
||||
oas = (await readJson(generatedFilePath)) as OpenAPIObject
|
||||
@@ -363,7 +379,7 @@ components:
|
||||
outDir,
|
||||
"--base",
|
||||
filePath,
|
||||
"--local"
|
||||
"--local",
|
||||
])
|
||||
const generatedFilePath = path.resolve(outDir, "store.oas.json")
|
||||
oas = (await readJson(generatedFilePath)) as OpenAPIObject
|
||||
@@ -473,7 +489,7 @@ components:
|
||||
const routes = Object.keys(oas.paths)
|
||||
expect(routes.includes("/admin/products")).toBeTruthy()
|
||||
expect(routes.includes("/store/products")).toBeFalsy()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("public OAS with base", () => {
|
||||
@@ -579,7 +595,7 @@ components:
|
||||
])
|
||||
const generatedFilePath = path.resolve(outDir, "store.oas.json")
|
||||
oas = (await readJson(generatedFilePath)) as OpenAPIObject
|
||||
})
|
||||
})
|
||||
|
||||
it("should add new path to existing paths", async () => {
|
||||
const routes = Object.keys(oas.paths)
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { PreviewDocsOptions, previewDocs } from "@redocly/cli/lib/commands/preview-docs"
|
||||
import {
|
||||
previewDocs,
|
||||
PreviewDocsOptions,
|
||||
} from "@redocly/cli/lib/commands/preview-docs"
|
||||
import { commandWrapper } from "@redocly/cli/lib/wrapper"
|
||||
import { Command, Option, OptionValues } from "commander"
|
||||
import execa from "execa"
|
||||
@@ -12,7 +15,12 @@ import {
|
||||
} from "./utils/circular-patch-utils"
|
||||
import { getTmpDirectory, isFile } from "./utils/fs-utils"
|
||||
import { readJson } from "./utils/json-utils"
|
||||
import { jsonObjectToYamlString, readYaml, writeYaml, writeYamlFromJson } from "./utils/yaml-utils"
|
||||
import {
|
||||
jsonObjectToYamlString,
|
||||
readYaml,
|
||||
writeYaml,
|
||||
writeYamlFromJson,
|
||||
} from "./utils/yaml-utils"
|
||||
import yargs from "yargs"
|
||||
|
||||
/**
|
||||
@@ -64,7 +72,7 @@ export const commandOptions: Option[] = [
|
||||
new Option(
|
||||
"--main-file-name <mainFileName>",
|
||||
"The name of the main YAML file."
|
||||
).default("openapi.yaml")
|
||||
).default("openapi.yaml"),
|
||||
]
|
||||
|
||||
export function getCommand(): Command {
|
||||
@@ -140,7 +148,10 @@ export async function execute(cliParams: OptionValues): Promise<void> {
|
||||
if (dryRun) {
|
||||
console.log(`⚫️ Dry run - no files generated`)
|
||||
// check out possible changes in redocly config
|
||||
await execa("git", ["checkout", path.join(basePath, "redocly", "redocly-config.yaml")])
|
||||
await execa("git", [
|
||||
"checkout",
|
||||
path.join(basePath, "redocly", "redocly-config.yaml"),
|
||||
])
|
||||
return
|
||||
}
|
||||
if (shouldPreview) {
|
||||
@@ -150,7 +161,10 @@ export async function execute(cliParams: OptionValues): Promise<void> {
|
||||
if (shouldSplit) {
|
||||
await generateReference(srcFileSanitized, outDir)
|
||||
} else {
|
||||
await writeYaml(path.join(outDir, finalOASFile), await fs.readFile(srcFileSanitized, "utf8"))
|
||||
await writeYaml(
|
||||
path.join(outDir, finalOASFile),
|
||||
await fs.readFile(srcFileSanitized, "utf8")
|
||||
)
|
||||
}
|
||||
if (shouldBuildHTML) {
|
||||
const outHTMLFile = path.resolve(outDir, "index.html")
|
||||
@@ -236,17 +250,31 @@ const fixCirclularReferences = async (srcFile: string): Promise<void> => {
|
||||
${hint}
|
||||
###
|
||||
`
|
||||
const redoclyConfigPath = path.join(basePath, "redocly", "redocly-config.yaml")
|
||||
const originalContent = await readYaml(redoclyConfigPath) as CircularReferenceConfig
|
||||
const redoclyConfigPath = path.join(
|
||||
basePath,
|
||||
"redocly",
|
||||
"redocly-config.yaml"
|
||||
)
|
||||
const originalContent = (await readYaml(
|
||||
redoclyConfigPath
|
||||
)) as CircularReferenceConfig
|
||||
Object.keys(recommendation).forEach((recKey) => {
|
||||
originalContent.decorators["medusa/circular-patch"].schemas[recKey] = [
|
||||
...(originalContent.decorators["medusa/circular-patch"].schemas[recKey] || []),
|
||||
...recommendation[recKey]
|
||||
...(originalContent.decorators["medusa/circular-patch"].schemas[
|
||||
recKey
|
||||
] || []),
|
||||
...recommendation[recKey],
|
||||
]
|
||||
})
|
||||
|
||||
await writeYaml(redoclyConfigPath, jsonObjectToYamlString(originalContent))
|
||||
console.log(`🟡 Added the following unhandled circular references to redocly-config.ts:` + hintMessage)
|
||||
await writeYaml(
|
||||
redoclyConfigPath,
|
||||
jsonObjectToYamlString(originalContent)
|
||||
)
|
||||
console.log(
|
||||
`🟡 Added the following unhandled circular references to redocly-config.ts:` +
|
||||
hintMessage
|
||||
)
|
||||
}
|
||||
}
|
||||
console.log(`🟢 All circular references are handled`)
|
||||
|
||||
@@ -15,9 +15,7 @@ import { isFile } from "./utils/fs-utils"
|
||||
* Constants
|
||||
*/
|
||||
// Medusa core package directory
|
||||
const medusaPackagePath = path.dirname(
|
||||
require.resolve("@medusajs/medusa")
|
||||
)
|
||||
const medusaPackagePath = path.dirname(require.resolve("@medusajs/medusa"))
|
||||
const basePath = path.resolve(__dirname, "../")
|
||||
|
||||
/**
|
||||
@@ -48,7 +46,7 @@ export const commandOptions: Option[] = [
|
||||
new Option(
|
||||
"--local",
|
||||
"Generate OAS from local files rather than public OAS. This is useful for generating references in the Medusa monorepo."
|
||||
)
|
||||
),
|
||||
]
|
||||
|
||||
export function getCommand() {
|
||||
@@ -105,11 +103,17 @@ export async function execute(cliParams: OptionValues) {
|
||||
console.log(`🟣 Generating OAS - ${apiType}`)
|
||||
|
||||
if (apiType === "combined") {
|
||||
const adminOAS = !local ? await getPublicOas("admin") : await getOASFromCodebase("admin")
|
||||
const storeOAS = !local ? await getPublicOas("store") : await getOASFromCodebase("store")
|
||||
const adminOAS = !local
|
||||
? await getPublicOas("admin")
|
||||
: await getOASFromCodebase("admin")
|
||||
const storeOAS = !local
|
||||
? await getPublicOas("store")
|
||||
: await getOASFromCodebase("store")
|
||||
oas = await combineOAS(adminOAS, storeOAS)
|
||||
} else {
|
||||
oas = !local ? await getPublicOas(apiType) : await getOASFromCodebase(apiType)
|
||||
oas = !local
|
||||
? await getPublicOas(apiType)
|
||||
: await getOASFromCodebase(apiType)
|
||||
}
|
||||
|
||||
if (additionalPaths.length || baseFile) {
|
||||
@@ -133,14 +137,21 @@ export async function execute(cliParams: OptionValues) {
|
||||
/**
|
||||
* Methods
|
||||
*/
|
||||
async function getOASFromCodebase(
|
||||
apiType: ApiType
|
||||
): Promise<OpenAPIObject> {
|
||||
async function getOASFromCodebase(apiType: ApiType): Promise<OpenAPIObject> {
|
||||
/**
|
||||
* OAS output directory
|
||||
*/
|
||||
const oasOutputPath = path.resolve(
|
||||
__dirname, "..", "..", "..", "..", "..", "www", "utils", "generated", "oas-output"
|
||||
__dirname,
|
||||
"..",
|
||||
"..",
|
||||
"..",
|
||||
"..",
|
||||
"..",
|
||||
"www",
|
||||
"utils",
|
||||
"generated",
|
||||
"oas-output"
|
||||
)
|
||||
const gen = await swaggerInline(
|
||||
[
|
||||
@@ -158,11 +169,9 @@ async function getOASFromCodebase(
|
||||
return (await OpenAPIParser.parse(JSON.parse(gen))) as OpenAPIObject
|
||||
}
|
||||
|
||||
async function getPublicOas(
|
||||
apiType: ApiType,
|
||||
) {
|
||||
async function getPublicOas(apiType: ApiType) {
|
||||
const url = `https://docs.medusajs.com/v2/api/api/download/${apiType}`
|
||||
return await OpenAPIParser.parse(url) as OpenAPIObject
|
||||
return (await OpenAPIParser.parse(url)) as OpenAPIObject
|
||||
}
|
||||
|
||||
async function getOASFromPaths(
|
||||
|
||||
@@ -8,4 +8,4 @@ type CircularReferenceConfig = {
|
||||
schemas: CircularReferenceSchema
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { access, lstat, mkdtemp } from "fs/promises"
|
||||
import path from "path"
|
||||
import { sep } from "path"
|
||||
import path, { sep } from "path"
|
||||
import { tmpdir } from "os"
|
||||
|
||||
export async function isFile(filePath: string): Promise<boolean> {
|
||||
|
||||
@@ -6,11 +6,17 @@ export const readYaml = async (filePath): Promise<unknown> => {
|
||||
return yaml.load(yamlString)
|
||||
}
|
||||
|
||||
export const writeYaml = async (filePath: string, yamlContent: string): Promise<void> => {
|
||||
export const writeYaml = async (
|
||||
filePath: string,
|
||||
yamlContent: string
|
||||
): Promise<void> => {
|
||||
await fs.writeFile(filePath, yamlContent, "utf8")
|
||||
}
|
||||
|
||||
export const writeYamlFromJson = async (filePath, jsonObject): Promise<void> => {
|
||||
export const writeYamlFromJson = async (
|
||||
filePath,
|
||||
jsonObject
|
||||
): Promise<void> => {
|
||||
const yamlString = yaml.dump(jsonObject)
|
||||
await fs.writeFile(filePath, yamlString, "utf8")
|
||||
}
|
||||
|
||||
@@ -4,4 +4,3 @@ export * from "./link-sales-channels-to-publishable-key"
|
||||
export * from "./revoke-api-keys"
|
||||
export * from "./update-api-keys"
|
||||
export * from "./validate-sales-channel-exists"
|
||||
|
||||
|
||||
@@ -3,4 +3,3 @@ export * from "./delete-api-keys"
|
||||
export * from "./link-sales-channels-to-publishable-key"
|
||||
export * from "./revoke-api-keys"
|
||||
export * from "./update-api-keys"
|
||||
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
export * from "./steps"
|
||||
export * from "./workflows"
|
||||
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
export * from "./steps"
|
||||
export * from "./workflows"
|
||||
|
||||
|
||||
@@ -28,4 +28,3 @@ export * from "./update-line-items"
|
||||
export * from "./validate-cart-payments"
|
||||
export * from "./validate-cart-shipping-options"
|
||||
export * from "./validate-variant-prices"
|
||||
|
||||
|
||||
@@ -83,7 +83,8 @@ export const updateTaxLinesWorkflow = createWorkflow(
|
||||
transform({ input, cart }, (data) => ({
|
||||
cart: data.cart,
|
||||
items: data.input.items || data.cart.items,
|
||||
shipping_methods: data.input.shipping_methods || data.cart.shipping_methods,
|
||||
shipping_methods:
|
||||
data.input.shipping_methods || data.cart.shipping_methods,
|
||||
force_tax_calculation: data.input.force_tax_calculation,
|
||||
}))
|
||||
)
|
||||
|
||||
@@ -6,4 +6,3 @@ export * from "./delete-customers"
|
||||
export * from "./remove-customer-account"
|
||||
export * from "./update-addresses"
|
||||
export * from "./update-customers"
|
||||
|
||||
|
||||
@@ -15,4 +15,3 @@ export * from "./update-fulfillment"
|
||||
export * from "./update-shipping-profiles"
|
||||
export * from "./upsert-shipping-options"
|
||||
export * from "./validate-shipment"
|
||||
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
export * from "./capture-payment"
|
||||
export * from "./refund-payment"
|
||||
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
export * from "./steps"
|
||||
export * from "./workflows"
|
||||
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
export * from "./steps"
|
||||
export * from "./workflows"
|
||||
|
||||
|
||||
@@ -3,4 +3,3 @@ export * from "./create-users"
|
||||
export * from "./delete-users"
|
||||
export * from "./remove-user-account"
|
||||
export * from "./update-users"
|
||||
|
||||
|
||||
@@ -59,7 +59,6 @@
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@swc/core": "^1.7.28",
|
||||
"@swc/jest": "^0.2.36",
|
||||
"@types/express": "^4.17.17",
|
||||
"@types/jsonwebtoken": "^8.5.9",
|
||||
"awilix": "^8.0.1",
|
||||
"ioredis": "^5.4.1",
|
||||
@@ -78,6 +77,7 @@
|
||||
"@medusajs/utils": "^1.11.9",
|
||||
"@medusajs/workflows-sdk": "^0.1.6",
|
||||
"@opentelemetry/api": "^1.9.0",
|
||||
"@types/express": "^4.17.17",
|
||||
"connect-redis": "5.2.0",
|
||||
"cookie-parser": "^1.4.6",
|
||||
"cors": "^2.8.5",
|
||||
|
||||
@@ -1,18 +1,13 @@
|
||||
import { createMedusaContainer } from "@medusajs/utils"
|
||||
import { AwilixContainer, ResolveOptions } from "awilix"
|
||||
import { TransformObjectMethodToAsync } from "@medusajs/types";
|
||||
|
||||
/**
|
||||
* The following interface acts as a bucket that other modules or the
|
||||
* utils package can fill using declaration merging
|
||||
*/
|
||||
export interface ModuleImplementations {}
|
||||
import { ModuleImplementations } from "@medusajs/types"
|
||||
|
||||
/**
|
||||
* The Medusa Container extends [Awilix](https://github.com/jeffijoe/awilix) to
|
||||
* provide dependency injection functionalities.
|
||||
*/
|
||||
export type MedusaContainer<Cradle extends object = TransformObjectMethodToAsync<ModuleImplementations>> =
|
||||
// export type MedusaContainer<Cradle extends object = TransformObjectMethodToAsync<ModuleImplementations>> =
|
||||
export type MedusaContainer<Cradle extends object = ModuleImplementations> =
|
||||
Omit<AwilixContainer, "resolve"> & {
|
||||
resolve<K extends keyof Cradle>(
|
||||
key: K,
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
import zod from "zod"
|
||||
import { MedusaError } from "@medusajs/framework/utils"
|
||||
import { createLinkBody } from "../validators"
|
||||
import { validateAndTransformBody } from "../validate-body"
|
||||
import { MedusaRequest, MedusaResponse } from "../../../types/routing"
|
||||
import { MedusaError } from "@medusajs/utils"
|
||||
import { validateAndTransformBody } from "../utils/validate-body"
|
||||
import { MedusaRequest, MedusaResponse } from "../types"
|
||||
|
||||
const createLinkBody = () => {
|
||||
return zod.object({
|
||||
add: zod.array(zod.string()).optional(),
|
||||
remove: zod.array(zod.string()).optional(),
|
||||
})
|
||||
}
|
||||
|
||||
describe("validateAndTransformBody", () => {
|
||||
afterEach(() => {
|
||||
@@ -1,8 +1,57 @@
|
||||
import { MedusaError } from "@medusajs/framework/utils"
|
||||
import { NextFunction, Request, Response } from "express"
|
||||
import z from "zod"
|
||||
import { MedusaError } from "@medusajs/utils"
|
||||
import { validateAndTransformQuery } from "../utils/validate-query"
|
||||
import { MedusaRequest, MedusaResponse, MedusaNextFunction } from "../types"
|
||||
|
||||
import { createFindParams } from "../validators"
|
||||
import { validateAndTransformQuery } from "../validate-query"
|
||||
export const createSelectParams = () => {
|
||||
return z.object({
|
||||
fields: z.string().optional(),
|
||||
})
|
||||
}
|
||||
|
||||
const createFindParams = ({
|
||||
offset,
|
||||
limit,
|
||||
order,
|
||||
}: {
|
||||
offset?: number
|
||||
limit?: number
|
||||
order?: string
|
||||
} = {}) => {
|
||||
const selectParams = createSelectParams()
|
||||
|
||||
return selectParams.merge(
|
||||
z.object({
|
||||
offset: z.preprocess(
|
||||
(val) => {
|
||||
if (val && typeof val === "string") {
|
||||
return parseInt(val)
|
||||
}
|
||||
return val
|
||||
},
|
||||
z
|
||||
.number()
|
||||
.optional()
|
||||
.default(offset ?? 0)
|
||||
),
|
||||
limit: z.preprocess(
|
||||
(val) => {
|
||||
if (val && typeof val === "string") {
|
||||
return parseInt(val)
|
||||
}
|
||||
return val
|
||||
},
|
||||
z
|
||||
.number()
|
||||
.optional()
|
||||
.default(limit ?? 20)
|
||||
),
|
||||
order: order
|
||||
? z.string().optional().default(order)
|
||||
: z.string().optional(),
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
describe("validateAndTransformQuery", () => {
|
||||
afterEach(() => {
|
||||
@@ -12,9 +61,9 @@ describe("validateAndTransformQuery", () => {
|
||||
it("should transform the input query", async () => {
|
||||
let mockRequest = {
|
||||
query: {},
|
||||
} as Request
|
||||
const mockResponse = {} as Response
|
||||
const nextFunction: NextFunction = jest.fn()
|
||||
} as MedusaRequest
|
||||
const mockResponse = {} as MedusaResponse
|
||||
const nextFunction: MedusaNextFunction = jest.fn()
|
||||
|
||||
const expectations = ({
|
||||
offset,
|
||||
@@ -104,15 +153,13 @@ describe("validateAndTransformQuery", () => {
|
||||
inputOrder: undefined,
|
||||
})
|
||||
|
||||
//////////////////////////////
|
||||
|
||||
mockRequest = {
|
||||
query: {
|
||||
limit: "10",
|
||||
offset: "5",
|
||||
order: "created_at",
|
||||
},
|
||||
} as unknown as Request
|
||||
} as unknown as MedusaRequest
|
||||
|
||||
middleware = validateAndTransformQuery(createFindParams(), queryConfig)
|
||||
|
||||
@@ -125,15 +172,13 @@ describe("validateAndTransformQuery", () => {
|
||||
transformedOrder: { created_at: "ASC" },
|
||||
})
|
||||
|
||||
//////////////////////////////
|
||||
|
||||
mockRequest = {
|
||||
query: {
|
||||
limit: "10",
|
||||
offset: "5",
|
||||
order: "created_at",
|
||||
},
|
||||
} as unknown as Request
|
||||
} as unknown as MedusaRequest
|
||||
|
||||
queryConfig = {
|
||||
defaults: [
|
||||
@@ -166,9 +211,9 @@ describe("validateAndTransformQuery", () => {
|
||||
query: {
|
||||
fields: "id",
|
||||
},
|
||||
} as unknown as Request
|
||||
const mockResponse = {} as Response
|
||||
const nextFunction: NextFunction = jest.fn()
|
||||
} as unknown as MedusaRequest
|
||||
const mockResponse = {} as MedusaResponse
|
||||
const nextFunction: MedusaNextFunction = jest.fn()
|
||||
|
||||
let queryConfig: any = {
|
||||
defaultFields: [
|
||||
@@ -200,13 +245,11 @@ describe("validateAndTransformQuery", () => {
|
||||
})
|
||||
)
|
||||
|
||||
//////////////////////////////
|
||||
|
||||
mockRequest = {
|
||||
query: {
|
||||
fields: "+test_prop,-prop-test-something",
|
||||
},
|
||||
} as unknown as Request
|
||||
} as unknown as MedusaRequest
|
||||
|
||||
queryConfig = {
|
||||
defaultFields: [
|
||||
@@ -249,13 +292,11 @@ describe("validateAndTransformQuery", () => {
|
||||
})
|
||||
)
|
||||
|
||||
//////////////////////////////
|
||||
|
||||
mockRequest = {
|
||||
query: {
|
||||
fields: "+test_prop,-updated_at",
|
||||
},
|
||||
} as unknown as Request
|
||||
} as unknown as MedusaRequest
|
||||
|
||||
queryConfig = {
|
||||
defaults: [
|
||||
@@ -296,9 +337,9 @@ describe("validateAndTransformQuery", () => {
|
||||
query: {
|
||||
fields: "*product.variants,+product.id",
|
||||
},
|
||||
} as unknown as Request
|
||||
const mockResponse = {} as Response
|
||||
const nextFunction: NextFunction = jest.fn()
|
||||
} as unknown as MedusaRequest
|
||||
const mockResponse = {} as MedusaResponse
|
||||
const nextFunction: MedusaNextFunction = jest.fn()
|
||||
|
||||
let queryConfig: any = {
|
||||
defaults: [
|
||||
@@ -367,13 +408,11 @@ describe("validateAndTransformQuery", () => {
|
||||
})
|
||||
)
|
||||
|
||||
//////////////////////////////
|
||||
|
||||
mockRequest = {
|
||||
query: {
|
||||
fields: "store.name",
|
||||
},
|
||||
} as unknown as Request
|
||||
} as unknown as MedusaRequest
|
||||
|
||||
queryConfig = {
|
||||
defaultFields: [
|
||||
@@ -423,9 +462,9 @@ describe("validateAndTransformQuery", () => {
|
||||
query: {
|
||||
fields: "+test_prop",
|
||||
},
|
||||
} as unknown as Request
|
||||
const mockResponse = {} as Response
|
||||
const nextFunction: NextFunction = jest.fn()
|
||||
} as unknown as MedusaRequest
|
||||
const mockResponse = {} as MedusaResponse
|
||||
const nextFunction: MedusaNextFunction = jest.fn()
|
||||
|
||||
let queryConfig: any = {
|
||||
defaultFields: [
|
||||
@@ -468,13 +507,11 @@ describe("validateAndTransformQuery", () => {
|
||||
)
|
||||
)
|
||||
|
||||
//////////////////////////////
|
||||
|
||||
mockRequest = {
|
||||
query: {
|
||||
fields: "product",
|
||||
},
|
||||
} as unknown as Request
|
||||
} as unknown as MedusaRequest
|
||||
|
||||
queryConfig = {
|
||||
defaultFields: [
|
||||
@@ -517,13 +554,11 @@ describe("validateAndTransformQuery", () => {
|
||||
)
|
||||
)
|
||||
|
||||
//////////////////////////////
|
||||
|
||||
mockRequest = {
|
||||
query: {
|
||||
fields: "store",
|
||||
},
|
||||
} as unknown as Request
|
||||
} as unknown as MedusaRequest
|
||||
|
||||
queryConfig = {
|
||||
defaultFields: [
|
||||
@@ -562,13 +597,11 @@ describe("validateAndTransformQuery", () => {
|
||||
)
|
||||
)
|
||||
|
||||
//////////////////////////////
|
||||
|
||||
mockRequest = {
|
||||
query: {
|
||||
fields: "*product",
|
||||
},
|
||||
} as unknown as Request
|
||||
} as unknown as MedusaRequest
|
||||
|
||||
queryConfig = {
|
||||
defaults: [
|
||||
@@ -605,13 +638,11 @@ describe("validateAndTransformQuery", () => {
|
||||
)
|
||||
)
|
||||
|
||||
//////////////////////////////
|
||||
|
||||
mockRequest = {
|
||||
query: {
|
||||
fields: "*product.variants",
|
||||
},
|
||||
} as unknown as Request
|
||||
} as unknown as MedusaRequest
|
||||
|
||||
queryConfig = {
|
||||
defaults: [
|
||||
@@ -649,13 +680,11 @@ describe("validateAndTransformQuery", () => {
|
||||
)
|
||||
)
|
||||
|
||||
//////////////////////////////
|
||||
|
||||
mockRequest = {
|
||||
query: {
|
||||
fields: "*product",
|
||||
},
|
||||
} as unknown as Request
|
||||
} as unknown as MedusaRequest
|
||||
|
||||
queryConfig = {
|
||||
defaults: [
|
||||
@@ -2,4 +2,11 @@ export * from "./express-loader"
|
||||
export * from "./router"
|
||||
export * from "./types"
|
||||
export * from "./middlewares"
|
||||
export * from "./utils/http-compression"
|
||||
export * from "./utils/validate-body"
|
||||
export * from "./utils/validate-query"
|
||||
export * from "./utils/get-query-config"
|
||||
export * from "./utils/define-middlewares"
|
||||
export * from "./utils/maybe-apply-link-filter"
|
||||
export * from "./utils/refetch-entities"
|
||||
export * from "./utils/unless-path"
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { isObject, isPresent } from "@medusajs/framework/utils"
|
||||
import { NextFunction } from "express"
|
||||
import { MedusaRequest } from "../../../../types/routing"
|
||||
import { isObject, isPresent } from "@medusajs/utils"
|
||||
import { MedusaNextFunction, MedusaRequest } from "../types"
|
||||
|
||||
export function applyDefaultFilters<TFilter extends object>(
|
||||
filtersToApply: TFilter
|
||||
) {
|
||||
return async (req: MedusaRequest, _, next: NextFunction) => {
|
||||
return async (req: MedusaRequest, _, next: MedusaNextFunction) => {
|
||||
for (const [filter, filterValue] of Object.entries(filtersToApply)) {
|
||||
let valueToApply = filterValue
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { MedusaNextFunction, MedusaRequest } from "../types"
|
||||
|
||||
export function applyParamsAsFilters(mappings: { [param: string]: string }) {
|
||||
return async (req: MedusaRequest, _, next: MedusaNextFunction) => {
|
||||
for (const [param, paramValue] of Object.entries(req.params)) {
|
||||
if (mappings[param]) {
|
||||
req.filterableFields[mappings[param]] = paramValue
|
||||
}
|
||||
}
|
||||
|
||||
return next()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { MedusaNextFunction, MedusaRequest } from "../types"
|
||||
|
||||
export function clearFiltersByKey(keys: string[]) {
|
||||
return async (req: MedusaRequest, _, next: MedusaNextFunction) => {
|
||||
keys.forEach((key) => {
|
||||
delete req.filterableFields[key]
|
||||
})
|
||||
|
||||
return next()
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
import { Query } from "@medusajs/types"
|
||||
import {
|
||||
ApiKeyType,
|
||||
ContainerRegistrationKeys,
|
||||
@@ -31,7 +30,7 @@ export async function ensurePublishableApiKeyMiddleware(
|
||||
}
|
||||
|
||||
let apiKey
|
||||
const query: Query = req.scope.resolve(ContainerRegistrationKeys.QUERY)
|
||||
const query = req.scope.resolve(ContainerRegistrationKeys.QUERY)
|
||||
|
||||
try {
|
||||
const { data } = await query.graph(
|
||||
|
||||
@@ -3,7 +3,6 @@ import { NextFunction, Response } from "express"
|
||||
import { ContainerRegistrationKeys, MedusaError } from "@medusajs/utils"
|
||||
import { formatException } from "./exception-formatter"
|
||||
import { MedusaRequest } from "../types"
|
||||
import { logger as logger_ } from "../../logger"
|
||||
|
||||
const QUERY_RUNNER_RELEASED = "QueryRunnerAlreadyReleasedError"
|
||||
const TRANSACTION_STARTED = "TransactionAlreadyStartedError"
|
||||
@@ -20,9 +19,7 @@ export function errorHandler() {
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) => {
|
||||
const logger: typeof logger_ = req.scope.resolve(
|
||||
ContainerRegistrationKeys.LOGGER
|
||||
)
|
||||
const logger = req.scope.resolve(ContainerRegistrationKeys.LOGGER)
|
||||
|
||||
err = formatException(err)
|
||||
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
export * from "./authenticate-middleware"
|
||||
export * from "./error-handler"
|
||||
export * from "./exception-formatter"
|
||||
export * from "./apply-default-filters"
|
||||
export * from "./apply-params-as-filters"
|
||||
export * from "./clear-filters-by-key"
|
||||
export * from "./set-context"
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { NextFunction } from "express"
|
||||
import { MedusaRequest } from "../../../../types/routing"
|
||||
import { MedusaNextFunction, MedusaRequest } from "../types"
|
||||
|
||||
export function setContext(context: Record<string, any>) {
|
||||
return async (req: MedusaRequest, _, next: NextFunction) => {
|
||||
return async (req: MedusaRequest, _, next: MedusaNextFunction) => {
|
||||
const ctx: Record<string, any> = { ...(req.context || {}) }
|
||||
|
||||
for (const [contextKey, contextValue] of Object.entries(context || {})) {
|
||||
@@ -1,17 +1,13 @@
|
||||
import type { NextFunction, Request, Response } from "express"
|
||||
import { ZodObject } from "zod"
|
||||
|
||||
import { MedusaPricingContext, RequestQueryFields } from "@medusajs/types"
|
||||
import {
|
||||
FindConfig,
|
||||
MedusaPricingContext,
|
||||
RequestQueryFields,
|
||||
} from "@medusajs/types"
|
||||
import { MedusaContainer } from "../container"
|
||||
|
||||
export interface FindConfig<Entity> {
|
||||
select?: (keyof Entity)[]
|
||||
skip?: number
|
||||
take?: number
|
||||
relations?: string[]
|
||||
order?: { [K: string]: "ASC" | "DESC" }
|
||||
}
|
||||
|
||||
/**
|
||||
* List of all the supported HTTP methods
|
||||
*/
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import { RequestQueryFields } from "@medusajs/framework/types"
|
||||
import { pick } from "lodash"
|
||||
import { RequestQueryFields, FindConfig, QueryConfig } from "@medusajs/types"
|
||||
import {
|
||||
getSetDifference,
|
||||
isDefined,
|
||||
isPresent,
|
||||
MedusaError,
|
||||
getSetDifference,
|
||||
stringToSelectRelationObject,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { pick } from "lodash"
|
||||
import { FindConfig, QueryConfig } from "../types/common"
|
||||
} from "@medusajs/utils"
|
||||
|
||||
export function pickByConfig<TModel>(
|
||||
obj: TModel | TModel[],
|
||||
@@ -1,12 +1,17 @@
|
||||
import {
|
||||
HttpCompressionOptions,
|
||||
ProjectConfigOptions,
|
||||
} from "@medusajs/framework/types"
|
||||
import compression from "compression"
|
||||
import { Request, Response } from "express"
|
||||
import type { ConfigModule } from "@medusajs/types"
|
||||
import { ContainerRegistrationKeys } from "@medusajs/utils"
|
||||
|
||||
export function shouldCompressResponse(req: Request, res: Response) {
|
||||
const { projectConfig } = req.scope.resolve("configModule")
|
||||
import { HttpCompressionOptions, ProjectConfigOptions } from "../../config"
|
||||
import type { MedusaRequest, MedusaResponse } from "../types"
|
||||
|
||||
export function shouldCompressResponse(
|
||||
req: MedusaRequest,
|
||||
res: MedusaResponse
|
||||
) {
|
||||
const { projectConfig } = req.scope.resolve<ConfigModule>(
|
||||
ContainerRegistrationKeys.CONFIG_MODULE
|
||||
)
|
||||
const { enabled } = compressionOptions(projectConfig)
|
||||
|
||||
if (!enabled) {
|
||||
@@ -2,9 +2,8 @@ import {
|
||||
arrayIntersection,
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { NextFunction } from "express"
|
||||
import { MedusaRequest } from "../../types/routing"
|
||||
} from "@medusajs/utils"
|
||||
import { MedusaNextFunction, MedusaRequest } from "../types"
|
||||
|
||||
export function maybeApplyLinkFilter({
|
||||
entryPoint,
|
||||
@@ -12,7 +11,11 @@ export function maybeApplyLinkFilter({
|
||||
filterableField,
|
||||
filterByField = "id",
|
||||
}) {
|
||||
return async function linkFilter(req: MedusaRequest, _, next: NextFunction) {
|
||||
return async function linkFilter(
|
||||
req: MedusaRequest,
|
||||
_,
|
||||
next: MedusaNextFunction
|
||||
) {
|
||||
const filterableFields = req.filterableFields
|
||||
|
||||
if (!filterableFields?.[filterableField]) {
|
||||
@@ -1,10 +1,10 @@
|
||||
import { MedusaContainer } from "@medusajs/framework/types"
|
||||
import { MedusaContainer } from "@medusajs/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
isString,
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { MedusaRequest } from "../../types/routing"
|
||||
} from "@medusajs/utils"
|
||||
import { MedusaRequest } from "../types"
|
||||
|
||||
export const refetchEntities = async (
|
||||
entryPoint: string,
|
||||
22
packages/core/framework/src/http/utils/unless-path.ts
Normal file
22
packages/core/framework/src/http/utils/unless-path.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import {
|
||||
MedusaNextFunction,
|
||||
MedusaRequest,
|
||||
MedusaResponse,
|
||||
MiddlewareFunction,
|
||||
} from "../types"
|
||||
|
||||
/**
|
||||
* Due to how our route loader works, where we load all middlewares before routes, ambiguous routes * end up having all middlewares on different routes executed before the route handler is.
|
||||
*/
|
||||
/**
|
||||
* This function allows us to skip middlewares for particular routes, so we can temporarily solve * * this without completely breaking the route loader for everyone.
|
||||
*/
|
||||
export const unlessPath =
|
||||
(onPath: RegExp, middleware: MiddlewareFunction) =>
|
||||
(req: MedusaRequest, res: MedusaResponse, next: MedusaNextFunction) => {
|
||||
if (onPath.test(req.path)) {
|
||||
return next()
|
||||
} else {
|
||||
return middleware(req, res, next)
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { NextFunction } from "express"
|
||||
import { z } from "zod"
|
||||
import { MedusaRequest, MedusaResponse } from "../../types/routing"
|
||||
import { zodValidator } from "./zod-helper"
|
||||
import { NextFunction } from "express"
|
||||
import { MedusaRequest, MedusaResponse } from "../types"
|
||||
import { zodValidator } from "../../zod/zod-helpers"
|
||||
|
||||
export function validateAndTransformBody(
|
||||
zodSchema:
|
||||
@@ -1,19 +1,12 @@
|
||||
import {
|
||||
BaseEntity,
|
||||
QueryConfig,
|
||||
RequestQueryFields,
|
||||
} from "@medusajs/framework/types"
|
||||
import { NextFunction } from "express"
|
||||
import { omit } from "lodash"
|
||||
import { z } from "zod"
|
||||
import { MedusaRequest, MedusaResponse } from "../../types/routing"
|
||||
import { removeUndefinedProperties } from "../../utils"
|
||||
import {
|
||||
prepareListQuery,
|
||||
prepareRetrieveQuery,
|
||||
} from "../../utils/get-query-config"
|
||||
import { zodValidator } from "./zod-helper"
|
||||
import { MedusaError } from "@medusajs/framework/utils"
|
||||
import { omit } from "lodash"
|
||||
import { NextFunction } from "express"
|
||||
import { removeUndefinedProperties, MedusaError } from "@medusajs/utils"
|
||||
import { BaseEntity, QueryConfig, RequestQueryFields } from "@medusajs/types"
|
||||
|
||||
import { zodValidator } from "../../zod/zod-helpers"
|
||||
import { MedusaRequest, MedusaResponse } from "../types"
|
||||
import { prepareListQuery, prepareRetrieveQuery } from "./get-query-config"
|
||||
|
||||
/**
|
||||
* Normalize an input query, especially from array like query params to an array type
|
||||
@@ -10,6 +10,7 @@ export * from "./medusa-app-loader"
|
||||
export * from "./subscribers"
|
||||
export * from "./workflows"
|
||||
export * from "./telemetry"
|
||||
export * from "./zod"
|
||||
|
||||
export const MEDUSA_CLI_PATH = require.resolve("@medusajs/medusa-cli")
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
export * from './job-loader'
|
||||
export * from "./job-loader"
|
||||
|
||||
@@ -33,6 +33,7 @@ import {
|
||||
container as mainContainer,
|
||||
MedusaContainer,
|
||||
} from "./container"
|
||||
import type { Knex } from "@mikro-orm/knex"
|
||||
|
||||
export class MedusaAppLoader {
|
||||
/**
|
||||
@@ -106,9 +107,9 @@ export class MedusaAppLoader {
|
||||
|
||||
protected prepareSharedResourcesAndDeps() {
|
||||
const injectedDependencies = {
|
||||
[ContainerRegistrationKeys.PG_CONNECTION]: this.#container.resolve(
|
||||
ContainerRegistrationKeys.PG_CONNECTION
|
||||
),
|
||||
[ContainerRegistrationKeys.PG_CONNECTION]: this.#container.resolve<
|
||||
Knex<any>
|
||||
>(ContainerRegistrationKeys.PG_CONNECTION),
|
||||
[ContainerRegistrationKeys.LOGGER]: this.#container.resolve(
|
||||
ContainerRegistrationKeys.LOGGER
|
||||
),
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/**
|
||||
* Custom wrapper on top of MikroORM CLI to override the issue
|
||||
* they have when importing TypeScript files.
|
||||
*
|
||||
*
|
||||
* They have hardcoded the module system of TypeScript to CommonJS
|
||||
* and that makes it impossible to use any other module system
|
||||
* like Node16 or NodeNext and so on.
|
||||
*
|
||||
*
|
||||
* With this wrapper, we monkey patch the code responsible for register
|
||||
* ts-node and then boot their CLI. Since, the code footprint is
|
||||
* small, we should be okay with managing this wrapper.
|
||||
@@ -51,7 +51,6 @@ require("@jercle/yargonaut")
|
||||
.style("yellow", "required")
|
||||
.helpStyle("green")
|
||||
.errorsStyle("red")
|
||||
|
||||
;(async () => {
|
||||
const argv = await CLIConfigurator.configure()
|
||||
const args = await argv.parse(process.argv.slice(2))
|
||||
|
||||
@@ -1 +1 @@
|
||||
export * from "@medusajs/workflows-sdk/composer"
|
||||
export * from "@medusajs/workflows-sdk/composer"
|
||||
|
||||
1
packages/core/framework/src/zod/index.ts
Normal file
1
packages/core/framework/src/zod/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./zod-helpers"
|
||||
@@ -1,3 +1,6 @@
|
||||
{
|
||||
"extends": "../../../_tsconfig.base.json"
|
||||
"extends": "../../../_tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "./src"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,9 +59,12 @@ export class Upload {
|
||||
}
|
||||
|
||||
async delete(id: string, headers?: ClientHeaders) {
|
||||
return this.client.fetch<HttpTypes.AdminFileDeleteResponse>(`/admin/uploads/${id}`, {
|
||||
method: "DELETE",
|
||||
headers,
|
||||
})
|
||||
return this.client.fetch<HttpTypes.AdminFileDeleteResponse>(
|
||||
`/admin/uploads/${id}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
headers,
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,12 +204,13 @@ export class Store {
|
||||
lineItemId: string,
|
||||
headers?: ClientHeaders
|
||||
) => {
|
||||
return this.client.fetch<
|
||||
HttpTypes.StoreLineItemDeleteResponse
|
||||
>(`/store/carts/${cartId}/line-items/${lineItemId}`, {
|
||||
method: "DELETE",
|
||||
headers,
|
||||
})
|
||||
return this.client.fetch<HttpTypes.StoreLineItemDeleteResponse>(
|
||||
`/store/carts/${cartId}/line-items/${lineItemId}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
headers,
|
||||
}
|
||||
)
|
||||
},
|
||||
addShippingMethod: async (
|
||||
cartId: string,
|
||||
@@ -432,12 +433,13 @@ export class Store {
|
||||
)
|
||||
},
|
||||
deleteAddress: async (addressId: string, headers?: ClientHeaders) => {
|
||||
return this.client.fetch<
|
||||
HttpTypes.StoreCustomerAddressDeleteResponse
|
||||
>(`/store/customers/me/addresses/${addressId}`, {
|
||||
method: "DELETE",
|
||||
headers,
|
||||
})
|
||||
return this.client.fetch<HttpTypes.StoreCustomerAddressDeleteResponse>(
|
||||
`/store/customers/me/addresses/${addressId}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
headers,
|
||||
}
|
||||
)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
export * from "./module-loader"
|
||||
export * from "./module-provider-loader"
|
||||
export * from "./register-modules"
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
AuthIdentityDTO,
|
||||
AuthenticationInput,
|
||||
AuthenticationResponse,
|
||||
AuthIdentityDTO,
|
||||
} from "./common"
|
||||
|
||||
// This interface currently won't allow for linking multiple providers to a single auth entity. That flow is more complex and not supported yet.
|
||||
|
||||
@@ -2,9 +2,9 @@ import { FindConfig } from "../common"
|
||||
import { IModuleService } from "../modules-sdk"
|
||||
import { Context } from "../shared-context"
|
||||
import {
|
||||
AuthIdentityDTO,
|
||||
AuthenticationInput,
|
||||
AuthenticationResponse,
|
||||
AuthIdentityDTO,
|
||||
CreateAuthIdentityDTO,
|
||||
CreateProviderIdentityDTO,
|
||||
FilterableAuthIdentityProps,
|
||||
|
||||
@@ -32,8 +32,8 @@ import {
|
||||
CreateShippingMethodForSingleCartDTO,
|
||||
CreateShippingMethodTaxLineDTO,
|
||||
UpdateAddressDTO,
|
||||
UpdateCartDTO,
|
||||
UpdateCartDataDTO,
|
||||
UpdateCartDTO,
|
||||
UpdateLineItemDTO,
|
||||
UpdateLineItemTaxLineDTO,
|
||||
UpdateLineItemWithSelectorDTO,
|
||||
|
||||
@@ -306,9 +306,31 @@ export type RawRounding = {
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export type QueryConfig<TEntity extends BaseEntity> = {
|
||||
export type QueryConfig<TEntity> = {
|
||||
/**
|
||||
* Default fields and relations to return
|
||||
*/
|
||||
defaults?: (keyof TEntity | string)[]
|
||||
allowed?: (keyof TEntity | string)[]
|
||||
/**
|
||||
* @deprecated Use `defaults` instead
|
||||
*/
|
||||
defaultFields?: (keyof TEntity | string)[]
|
||||
/**
|
||||
* @deprecated Use `defaultFields` instead and the relations will be inferred
|
||||
*/
|
||||
defaultRelations?: string[]
|
||||
/**
|
||||
* Fields and relations that are allowed to be requested
|
||||
*/
|
||||
allowed?: string[]
|
||||
/**
|
||||
* @deprecated Use `allowed` instead
|
||||
*/
|
||||
allowedFields?: string[]
|
||||
/**
|
||||
* @deprecated Use `allowedFields` instead and the relations will be inferred
|
||||
*/
|
||||
allowedRelations?: string[]
|
||||
defaultLimit?: number
|
||||
isList?: boolean
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@ import { MedusaContainer } from "./medusa-container"
|
||||
export type ExecArgs = {
|
||||
container: MedusaContainer
|
||||
args: string[]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import stream from "stream"
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
*
|
||||
* Details of a file upload's result.
|
||||
*/
|
||||
export type FileServiceUploadResult = {
|
||||
@@ -19,7 +19,7 @@ export type FileServiceUploadResult = {
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
*
|
||||
* The relevant details to upload a file through a stream.
|
||||
*/
|
||||
export type FileServiceGetUploadStreamResult = {
|
||||
@@ -44,7 +44,7 @@ export type FileServiceGetUploadStreamResult = {
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
*
|
||||
* The details of a file to retrieve.
|
||||
*/
|
||||
export type GetUploadedFileType = {
|
||||
@@ -61,7 +61,7 @@ export type GetUploadedFileType = {
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
*
|
||||
* The details of the file to remove.
|
||||
*/
|
||||
export type DeleteFileType = {
|
||||
@@ -75,7 +75,7 @@ export type DeleteFileType = {
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
*
|
||||
* The details of the file being uploaded through a stream.
|
||||
*/
|
||||
export type UploadStreamDescriptorType = {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export type FulfillmentOption = {
|
||||
/**
|
||||
* The option's ID.
|
||||
*
|
||||
*
|
||||
* @example express
|
||||
*/
|
||||
id: string
|
||||
|
||||
@@ -22,4 +22,4 @@ export type AdminApiKeyListResponse = PaginatedResponse<{
|
||||
api_keys: AdminApiKey[]
|
||||
}>
|
||||
|
||||
export type AdminApiKeyDeleteResponse = DeleteResponse<"api_key">
|
||||
export type AdminApiKeyDeleteResponse = DeleteResponse<"api_key">
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
export * from "./payloads"
|
||||
export * from "./queries"
|
||||
export * from "./responses"
|
||||
|
||||
|
||||
@@ -26,4 +26,4 @@ export interface AdminCampaignResponse {
|
||||
campaign: AdminCampaign
|
||||
}
|
||||
|
||||
export type AdminCampaignDeleteResponse = DeleteResponse<"campaign">
|
||||
export type AdminCampaignDeleteResponse = DeleteResponse<"campaign">
|
||||
|
||||
@@ -20,7 +20,8 @@ export interface StoreCart extends Omit<BaseCart, "items"> {
|
||||
payment_collection?: StorePaymentCollection
|
||||
region?: StoreRegion
|
||||
}
|
||||
export interface StoreCartLineItem extends Omit<BaseCartLineItem, "product" | "variant" | "cart"> {
|
||||
export interface StoreCartLineItem
|
||||
extends Omit<BaseCartLineItem, "product" | "variant" | "cart"> {
|
||||
product?: StoreProduct
|
||||
variant?: StoreProductVariant
|
||||
cart: StoreCart
|
||||
@@ -39,4 +40,4 @@ export interface StoreCartShippingMethod extends BaseCartShippingMethod {
|
||||
adjustments?: (BaseShippingMethodAdjustment & {
|
||||
shipping_method: StoreCartShippingMethod
|
||||
})[]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export * from "./entities"
|
||||
export * from "./payloads"
|
||||
export * from "./responses"
|
||||
export * from "./responses"
|
||||
|
||||
@@ -94,4 +94,4 @@ export interface StoreAddAddress {
|
||||
* Holds custom data in key-value pairs.
|
||||
*/
|
||||
metadata?: Record<string, unknown> | null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,17 +6,22 @@ export interface StoreCartResponse {
|
||||
cart: StoreCart
|
||||
}
|
||||
|
||||
export type StoreCompleteCartResponse = {
|
||||
type: "cart"
|
||||
cart: StoreCart
|
||||
error: {
|
||||
message: string
|
||||
name: string
|
||||
type: string
|
||||
}
|
||||
} | {
|
||||
type: "order"
|
||||
order: StoreOrder
|
||||
}
|
||||
export type StoreCompleteCartResponse =
|
||||
| {
|
||||
type: "cart"
|
||||
cart: StoreCart
|
||||
error: {
|
||||
message: string
|
||||
name: string
|
||||
type: string
|
||||
}
|
||||
}
|
||||
| {
|
||||
type: "order"
|
||||
order: StoreOrder
|
||||
}
|
||||
|
||||
export type StoreLineItemDeleteResponse = DeleteResponseWithParent<"line-item", StoreCart>
|
||||
export type StoreLineItemDeleteResponse = DeleteResponseWithParent<
|
||||
"line-item",
|
||||
StoreCart
|
||||
>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export * from "./entities"
|
||||
export * from "./queries"
|
||||
export * from "./responses"
|
||||
export * from "./responses"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { OperatorMap } from "../../../dal";
|
||||
import { BaseCollectionListParams } from "../common";
|
||||
import { OperatorMap } from "../../../dal"
|
||||
import { BaseCollectionListParams } from "../common"
|
||||
|
||||
export interface StoreCollectionFilters extends Omit<BaseCollectionListParams, "id"> {
|
||||
export interface StoreCollectionFilters
|
||||
extends Omit<BaseCollectionListParams, "id"> {
|
||||
deleted_at?: OperatorMap<string>
|
||||
}
|
||||
|
||||
@@ -15,14 +15,15 @@ export type DeleteResponse<TObject extends string> = {
|
||||
deleted: boolean
|
||||
}
|
||||
|
||||
export type DeleteResponseWithParent<TObject extends string, TParent = {}> =
|
||||
DeleteResponse<TObject> &
|
||||
{
|
||||
/**
|
||||
* The parent resource of the item that was deleted, if applicable.
|
||||
*/
|
||||
parent?: TParent
|
||||
}
|
||||
export type DeleteResponseWithParent<
|
||||
TObject extends string,
|
||||
TParent = {}
|
||||
> = DeleteResponse<TObject> & {
|
||||
/**
|
||||
* The parent resource of the item that was deleted, if applicable.
|
||||
*/
|
||||
parent?: TParent
|
||||
}
|
||||
|
||||
export type PaginatedResponse<T> = {
|
||||
limit: number
|
||||
@@ -38,4 +39,4 @@ export type BatchResponse<T> = {
|
||||
object: string
|
||||
deleted: boolean
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export * from "./admin"
|
||||
export * from "./common"
|
||||
export * from "./store"
|
||||
export * from "./store"
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import { BaseCurrency } from "../common";
|
||||
import { BaseCurrency } from "../common"
|
||||
|
||||
export interface StoreCurrency extends BaseCurrency {}
|
||||
export interface StoreCurrency extends BaseCurrency {}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export * from "./entities"
|
||||
export * from "./queries"
|
||||
export * from "./responses"
|
||||
export * from "./responses"
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { BaseFilterable } from "../../../dal";
|
||||
import { FindParams } from "../../common";
|
||||
import { BaseFilterable } from "../../../dal"
|
||||
import { FindParams } from "../../common"
|
||||
|
||||
export interface StoreGetCurrencyListParams extends
|
||||
FindParams, BaseFilterable<StoreGetCurrencyListParams> {
|
||||
q?: string
|
||||
code?: string | string[]
|
||||
}
|
||||
export interface StoreGetCurrencyListParams
|
||||
extends FindParams,
|
||||
BaseFilterable<StoreGetCurrencyListParams> {
|
||||
q?: string
|
||||
code?: string | string[]
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { PaginatedResponse } from "../../common";
|
||||
import { StoreCurrency } from "./entities";
|
||||
import { PaginatedResponse } from "../../common"
|
||||
import { StoreCurrency } from "./entities"
|
||||
|
||||
export interface StoreCurrencyResponse {
|
||||
currency: StoreCurrency
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export * from "./entities"
|
||||
export * from "./payloads"
|
||||
export * from "./queries"
|
||||
export * from "./responses"
|
||||
export * from "./responses"
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
export * from "./admin";
|
||||
|
||||
export * from "./admin"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export * from "./entities"
|
||||
export * from "./payloads"
|
||||
export * from "./queries"
|
||||
export * from "./responses"
|
||||
export * from "./responses"
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import { DeleteResponse, DeleteResponseWithParent, PaginatedResponse } from "../../common"
|
||||
import {
|
||||
DeleteResponse,
|
||||
DeleteResponseWithParent,
|
||||
PaginatedResponse,
|
||||
} from "../../common"
|
||||
import { AdminCustomer, AdminCustomerAddress } from "./entities"
|
||||
|
||||
export interface AdminCustomerResponse {
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import {
|
||||
BaseCustomer,
|
||||
BaseCustomerAddress,
|
||||
} from "../common"
|
||||
import { BaseCustomer, BaseCustomerAddress } from "../common"
|
||||
|
||||
export interface StoreCustomer extends Omit<BaseCustomer, "created_by"> {
|
||||
addresses: StoreCustomerAddress[]
|
||||
}
|
||||
export interface StoreCustomerAddress extends BaseCustomerAddress {}
|
||||
export interface StoreCustomerAddress extends BaseCustomerAddress {}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export * from "./entities"
|
||||
export * from "./payloads"
|
||||
export * from "./queries"
|
||||
export * from "./responses"
|
||||
export * from "./responses"
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import {
|
||||
BaseCustomerAddressFilters,
|
||||
BaseCustomerFilters,
|
||||
} from "../common"
|
||||
import { BaseCustomerAddressFilters, BaseCustomerFilters } from "../common"
|
||||
|
||||
export interface StoreCustomerFilters extends BaseCustomerFilters {}
|
||||
export interface StoreCustomerAddressFilters
|
||||
extends BaseCustomerAddressFilters {}
|
||||
extends BaseCustomerAddressFilters {}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { DeleteResponseWithParent, PaginatedResponse } from "../../common";
|
||||
import { StoreCustomer, StoreCustomerAddress } from "./entities";
|
||||
import { DeleteResponseWithParent, PaginatedResponse } from "../../common"
|
||||
import { StoreCustomer, StoreCustomerAddress } from "./entities"
|
||||
|
||||
export interface StoreCustomerResponse {
|
||||
customer: StoreCustomer
|
||||
@@ -12,4 +12,7 @@ export interface StoreCustomerAddressResponse {
|
||||
export interface StoreCustomerAddressListResponse
|
||||
extends PaginatedResponse<{ addresses: StoreCustomerAddress[] }> {}
|
||||
|
||||
export type StoreCustomerAddressDeleteResponse = DeleteResponseWithParent<"address", StoreCustomer>
|
||||
export type StoreCustomerAddressDeleteResponse = DeleteResponseWithParent<
|
||||
"address",
|
||||
StoreCustomer
|
||||
>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import { BaseExchange } from "../common";
|
||||
import { BaseExchange } from "../common"
|
||||
|
||||
export interface AdminExchange extends BaseExchange {}
|
||||
export interface AdminExchange extends BaseExchange {}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { OperatorMap } from "../../dal"
|
||||
import { FindParams } from "../common"
|
||||
import { BaseOrder, BaseOrderShippingMethod, BaseOrderTransaction } from "../order/common"
|
||||
import {
|
||||
BaseOrder,
|
||||
BaseOrderShippingMethod,
|
||||
BaseOrderTransaction,
|
||||
} from "../order/common"
|
||||
import { AdminReturn, AdminReturnItem } from "../return"
|
||||
|
||||
export interface BaseExchangeItem {
|
||||
|
||||
@@ -1 +1 @@
|
||||
export * from "./admin"
|
||||
export * from "./admin"
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import { BaseFile } from "../common"
|
||||
|
||||
export interface AdminFile extends BaseFile {}
|
||||
export interface AdminFile extends BaseFile {}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export * from "./entities"
|
||||
export * from "./payloads"
|
||||
export * from "./responses"
|
||||
export * from "./responses"
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import { BaseUploadFile } from "../common";
|
||||
import { BaseUploadFile } from "../common"
|
||||
|
||||
export type AdminUploadFile = BaseUploadFile
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { DeleteResponse } from "../../common";
|
||||
import { AdminFile } from "./entities";
|
||||
import { DeleteResponse } from "../../common"
|
||||
import { AdminFile } from "./entities"
|
||||
|
||||
export interface AdminFileResponse {
|
||||
file: AdminFile
|
||||
@@ -9,4 +9,4 @@ export interface AdminFileListResponse {
|
||||
files: AdminFile[]
|
||||
}
|
||||
|
||||
export type AdminFileDeleteResponse = DeleteResponse<"file">
|
||||
export type AdminFileDeleteResponse = DeleteResponse<"file">
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import { BaseFulfillmentProvider } from "../common";
|
||||
import { BaseFulfillmentProvider } from "../common"
|
||||
|
||||
export interface AdminFulfillmentProvider extends BaseFulfillmentProvider {}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export interface BaseFulfillmentProvider {
|
||||
id: string
|
||||
is_enabled: boolean
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user