chore: payment auto capture + remove enum from utils (#7513)
What: - handles payments session that are auto captured - removes all the enums from `@medusajs/types` - move all `@medusajs/types` to devDependencies
This commit is contained in:
@@ -29,7 +29,7 @@ export const validateCartPaymentsStep = createStep(
|
||||
]
|
||||
|
||||
const paymentsToProcess = paymentCollection.payment_sessions?.filter((ps) =>
|
||||
processablePaymentStatuses.includes(ps.status)
|
||||
processablePaymentStatuses.includes(ps.status as PaymentSessionStatus)
|
||||
)
|
||||
|
||||
if (!paymentsToProcess?.length) {
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
"author": "Medusa",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@medusajs/types": "^1.11.16",
|
||||
"cross-env": "^5.2.1",
|
||||
"jest": "^29.6.3",
|
||||
"msw": "^2.3.0",
|
||||
@@ -28,7 +29,6 @@
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/types": "^1.11.16",
|
||||
"qs": "^6.12.1"
|
||||
},
|
||||
"scripts": {
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
"author": "Medusa",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@medusajs/types": "^1.11.16",
|
||||
"cross-env": "^5.2.1",
|
||||
"jest": "^29.6.3",
|
||||
"rimraf": "^5.0.1",
|
||||
@@ -30,7 +31,6 @@
|
||||
"@graphql-tools/merge": "^9.0.0",
|
||||
"@graphql-tools/schema": "^10.0.0",
|
||||
"@medusajs/orchestration": "^0.5.7",
|
||||
"@medusajs/types": "^1.11.16",
|
||||
"@medusajs/utils": "^1.11.9",
|
||||
"awilix": "^8.0.0",
|
||||
"graphql": "^16.6.0",
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
import {
|
||||
MODULE_RESOURCE_TYPE,
|
||||
MODULE_SCOPE,
|
||||
ModuleDefinition,
|
||||
} from "@medusajs/types"
|
||||
|
||||
import { ModuleDefinition } from "@medusajs/types"
|
||||
import { upperCaseFirst } from "@medusajs/utils"
|
||||
import { MODULE_RESOURCE_TYPE, MODULE_SCOPE } from "./types"
|
||||
|
||||
export enum LinkModuleUtils {
|
||||
REMOTE_QUERY = "remoteQuery",
|
||||
|
||||
@@ -5,3 +5,4 @@ export * from "./medusa-app"
|
||||
export * from "./medusa-module"
|
||||
export * from "./remote-link"
|
||||
export * from "./remote-query"
|
||||
export * from "./types"
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import {
|
||||
InternalModuleDeclaration,
|
||||
MODULE_RESOURCE_TYPE,
|
||||
MODULE_SCOPE,
|
||||
} from "@medusajs/types"
|
||||
import { InternalModuleDeclaration } from "@medusajs/types"
|
||||
import { MODULE_RESOURCE_TYPE, MODULE_SCOPE } from "../../types"
|
||||
|
||||
import { MedusaModule } from "../../medusa-module"
|
||||
import { asValue } from "awilix"
|
||||
import { MedusaModule } from "../../medusa-module"
|
||||
|
||||
const mockRegisterMedusaModule = jest.fn().mockImplementation(() => {
|
||||
return {
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import {
|
||||
MODULE_RESOURCE_TYPE,
|
||||
MODULE_SCOPE,
|
||||
ModuleResolution,
|
||||
} from "@medusajs/types"
|
||||
import { ModuleResolution } from "@medusajs/types"
|
||||
import { createMedusaContainer } from "@medusajs/utils"
|
||||
import { MODULE_RESOURCE_TYPE, MODULE_SCOPE } from "../../types"
|
||||
import { moduleLoader } from "../module-loader"
|
||||
|
||||
const logger = {
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
import {
|
||||
InternalModuleDeclaration,
|
||||
MODULE_RESOURCE_TYPE,
|
||||
MODULE_SCOPE,
|
||||
ModuleDefinition,
|
||||
} from "@medusajs/types"
|
||||
import { InternalModuleDeclaration, ModuleDefinition } from "@medusajs/types"
|
||||
import { ModulesDefinition } from "../../definitions"
|
||||
import { MODULE_RESOURCE_TYPE, MODULE_SCOPE } from "../../types"
|
||||
import { registerMedusaModule } from "../register-modules"
|
||||
|
||||
const RESOLVED_PACKAGE = "@medusajs/test-service-resolved"
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import {
|
||||
Logger,
|
||||
MedusaContainer,
|
||||
MODULE_SCOPE,
|
||||
ModuleResolution,
|
||||
} from "@medusajs/types"
|
||||
|
||||
import { Logger, MedusaContainer, ModuleResolution } from "@medusajs/types"
|
||||
import { asValue } from "awilix"
|
||||
import { EOL } from "os"
|
||||
import { MODULE_SCOPE } from "../types"
|
||||
import { loadInternalModule } from "./utils"
|
||||
|
||||
export const moduleLoader = async ({
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
import {
|
||||
ExternalModuleDeclaration,
|
||||
InternalModuleDeclaration,
|
||||
MODULE_RESOURCE_TYPE,
|
||||
MODULE_SCOPE,
|
||||
ModuleDefinition,
|
||||
ModuleExports,
|
||||
ModuleResolution,
|
||||
} from "@medusajs/types"
|
||||
|
||||
import { isObject, isString } from "@medusajs/utils"
|
||||
import resolveCwd from "resolve-cwd"
|
||||
import { ModulesDefinition } from "../definitions"
|
||||
import { MODULE_RESOURCE_TYPE, MODULE_SCOPE } from "../types"
|
||||
|
||||
export const registerMedusaModule = (
|
||||
moduleKey: string,
|
||||
|
||||
@@ -3,21 +3,21 @@ import {
|
||||
InternalModuleDeclaration,
|
||||
Logger,
|
||||
MedusaContainer,
|
||||
MODULE_RESOURCE_TYPE,
|
||||
ModuleExports,
|
||||
ModuleLoaderFunction,
|
||||
ModuleResolution,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
createMedusaContainer,
|
||||
MedusaModuleType,
|
||||
ModulesSdkUtils,
|
||||
createMedusaContainer,
|
||||
} from "@medusajs/utils"
|
||||
import { asFunction, asValue } from "awilix"
|
||||
import { statSync } from "fs"
|
||||
import { readdir } from "fs/promises"
|
||||
import { join, resolve } from "path"
|
||||
import { MODULE_RESOURCE_TYPE } from "../../types"
|
||||
|
||||
type ModuleResource = {
|
||||
services: Function[]
|
||||
|
||||
@@ -6,8 +6,6 @@ import {
|
||||
InternalModuleDeclaration,
|
||||
LoadedModule,
|
||||
MedusaContainer,
|
||||
MODULE_RESOURCE_TYPE,
|
||||
MODULE_SCOPE,
|
||||
ModuleDefinition,
|
||||
ModuleExports,
|
||||
ModuleJoinerConfig,
|
||||
@@ -18,10 +16,10 @@ import {
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
ModulesSdkUtils,
|
||||
createMedusaContainer,
|
||||
isObject,
|
||||
isString,
|
||||
ModulesSdkUtils,
|
||||
promiseAll,
|
||||
} from "@medusajs/utils"
|
||||
import { asValue } from "awilix"
|
||||
@@ -33,6 +31,7 @@ import {
|
||||
import { MedusaModule } from "./medusa-module"
|
||||
import { RemoteLink } from "./remote-link"
|
||||
import { RemoteQuery } from "./remote-query"
|
||||
import { MODULE_RESOURCE_TYPE, MODULE_SCOPE } from "./types"
|
||||
import { cleanGraphQLSchema } from "./utils"
|
||||
|
||||
const LinkModulePackage = MODULE_PACKAGE_NAMES[Modules.LINK]
|
||||
|
||||
@@ -5,8 +5,6 @@ import {
|
||||
LinkModuleDefinition,
|
||||
LoadedModule,
|
||||
MedusaContainer,
|
||||
MODULE_RESOURCE_TYPE,
|
||||
MODULE_SCOPE,
|
||||
ModuleBootstrapDeclaration,
|
||||
ModuleDefinition,
|
||||
ModuleExports,
|
||||
@@ -19,15 +17,15 @@ import {
|
||||
simpleHash,
|
||||
stringifyCircular,
|
||||
} from "@medusajs/utils"
|
||||
import { asValue } from "awilix"
|
||||
import { EOL } from "os"
|
||||
import {
|
||||
moduleLoader,
|
||||
registerMedusaLinkModule,
|
||||
registerMedusaModule,
|
||||
} from "./loaders"
|
||||
|
||||
import { asValue } from "awilix"
|
||||
import { loadModuleMigrations } from "./loaders/utils"
|
||||
import { MODULE_RESOURCE_TYPE, MODULE_SCOPE } from "./types"
|
||||
|
||||
const logger: any = {
|
||||
log: (a) => console.log(a),
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
export enum MODULE_SCOPE {
|
||||
INTERNAL = "internal",
|
||||
EXTERNAL = "external",
|
||||
}
|
||||
|
||||
export enum MODULE_RESOURCE_TYPE {
|
||||
SHARED = "shared",
|
||||
ISOLATED = "isolated",
|
||||
}
|
||||
@@ -104,14 +104,9 @@ export type FilterQuery<T = any, Prev extends number = 3> = Prev extends never
|
||||
: never
|
||||
}
|
||||
|
||||
declare enum QueryOrder {
|
||||
ASC = "ASC",
|
||||
DESC = "DESC",
|
||||
asc = "asc",
|
||||
desc = "desc",
|
||||
}
|
||||
declare type QueryOrder = "ASC" | "DESC" | "asc" | "desc"
|
||||
|
||||
type QueryOrderKeysFlat = QueryOrder | 1 | -1 | keyof typeof QueryOrder
|
||||
type QueryOrderKeysFlat = QueryOrder | 1 | -1
|
||||
type QueryOrderKeys<T> = QueryOrderKeysFlat | QueryOrderMap<T>
|
||||
type QueryOrderMap<T> = {
|
||||
[K in keyof T as ExcludeFunctions<T, K>]?: QueryOrderKeys<
|
||||
|
||||
@@ -24,16 +24,6 @@ export type LogLevel =
|
||||
| "migration"
|
||||
export type LoggerOptions = boolean | "all" | LogLevel[]
|
||||
|
||||
export enum MODULE_SCOPE {
|
||||
INTERNAL = "internal",
|
||||
EXTERNAL = "external",
|
||||
}
|
||||
|
||||
export enum MODULE_RESOURCE_TYPE {
|
||||
SHARED = "shared",
|
||||
ISOLATED = "isolated",
|
||||
}
|
||||
|
||||
export type CustomModuleDefinition = {
|
||||
key?: string
|
||||
registrationName?: string
|
||||
@@ -43,8 +33,8 @@ export type CustomModuleDefinition = {
|
||||
}
|
||||
|
||||
export type InternalModuleDeclaration = {
|
||||
scope: MODULE_SCOPE.INTERNAL
|
||||
resources: MODULE_RESOURCE_TYPE
|
||||
scope: "internal"
|
||||
resources: "shared" | "isolated"
|
||||
dependencies?: string[]
|
||||
definition?: CustomModuleDefinition // That represent the definition of the module, such as the one we have for the medusa supported modules. This property is used for custom made modules.
|
||||
resolve?: string | ModuleExports
|
||||
@@ -61,7 +51,7 @@ export type InternalModuleDeclaration = {
|
||||
}
|
||||
|
||||
export type ExternalModuleDeclaration = {
|
||||
scope: MODULE_SCOPE.EXTERNAL
|
||||
scope: "external"
|
||||
definition?: CustomModuleDefinition // That represent the definition of the module, such as the one we have for the medusa supported modules. This property is used for custom made modules.
|
||||
server?: {
|
||||
type: "http"
|
||||
|
||||
@@ -2,69 +2,21 @@ import { BaseFilterable } from "../dal"
|
||||
import { OperatorMap } from "../dal/utils"
|
||||
import { BigNumberValue } from "../totals"
|
||||
/* ********** PAYMENT COLLECTION ********** */
|
||||
/**
|
||||
* @enum
|
||||
*
|
||||
* The payment collection's status.
|
||||
*/
|
||||
export enum PaymentCollectionStatus {
|
||||
/**
|
||||
* The payment collection isn't paid.
|
||||
*/
|
||||
NOT_PAID = "not_paid",
|
||||
|
||||
/**
|
||||
* The payment sessions in the payment collection are await authorization.
|
||||
*/
|
||||
AWAITING = "awaiting",
|
||||
export type PaymentCollectionStatus =
|
||||
| "not_paid"
|
||||
| "awaiting"
|
||||
| "authorized"
|
||||
| "partially_authorized"
|
||||
| "canceled"
|
||||
|
||||
/**
|
||||
* The payment sessions in the payment collection are authorized.
|
||||
*/
|
||||
AUTHORIZED = "authorized",
|
||||
|
||||
/**
|
||||
* Some of the payments in the payment collection are authorized.
|
||||
*/
|
||||
PARTIALLY_AUTHORIZED = "partially_authorized",
|
||||
|
||||
/**
|
||||
* The payments in the payment collection are canceled.
|
||||
*/
|
||||
CANCELED = "canceled",
|
||||
}
|
||||
|
||||
/**
|
||||
* @enum
|
||||
*
|
||||
* The status of a payment session.
|
||||
*/
|
||||
export enum PaymentSessionStatus {
|
||||
/**
|
||||
* The payment is authorized.
|
||||
*/
|
||||
AUTHORIZED = "authorized",
|
||||
|
||||
/**
|
||||
* The payment is pending.
|
||||
*/
|
||||
PENDING = "pending",
|
||||
|
||||
/**
|
||||
* The payment requires an action.
|
||||
*/
|
||||
REQUIRES_MORE = "requires_more",
|
||||
|
||||
/**
|
||||
* An error occurred while processing the payment.
|
||||
*/
|
||||
ERROR = "error",
|
||||
|
||||
/**
|
||||
* The payment is canceled.
|
||||
*/
|
||||
CANCELED = "canceled",
|
||||
}
|
||||
export type PaymentSessionStatus =
|
||||
| "authorized"
|
||||
| "captured"
|
||||
| "pending"
|
||||
| "requires_more"
|
||||
| "error"
|
||||
| "canceled"
|
||||
|
||||
/**
|
||||
* The payment collection details.
|
||||
|
||||
@@ -17,27 +17,11 @@ export type PaymentCustomerDTO = Partial<CustomerDTO>
|
||||
/**
|
||||
* Normalized events from payment provider to internal payment module events.
|
||||
*/
|
||||
export enum PaymentActions {
|
||||
/**
|
||||
* Payment session has been authorized and there are available funds for capture.
|
||||
*/
|
||||
AUTHORIZED = "authorized",
|
||||
|
||||
/**
|
||||
* Payment was successful and the mount is captured.
|
||||
*/
|
||||
SUCCESSFUL = "captured",
|
||||
|
||||
/**
|
||||
* Payment failed.
|
||||
*/
|
||||
FAILED = "failed",
|
||||
|
||||
/**
|
||||
* Received an event that is not processable.
|
||||
*/
|
||||
NOT_SUPPORTED = "not_supported",
|
||||
}
|
||||
export type PaymentActions =
|
||||
| "authorized"
|
||||
| "captured"
|
||||
| "failed"
|
||||
| "not_supported"
|
||||
|
||||
/**
|
||||
* @interface
|
||||
@@ -217,7 +201,7 @@ export type WebhookActionResult =
|
||||
/**
|
||||
* Received an event that is not processable.
|
||||
*/
|
||||
action: PaymentActions.NOT_SUPPORTED
|
||||
action: "not_supported"
|
||||
}
|
||||
| {
|
||||
/**
|
||||
|
||||
@@ -12,32 +12,17 @@ import { RuleTypeDTO } from "./rule-type"
|
||||
*
|
||||
* The price list's status.
|
||||
*/
|
||||
export enum PriceListStatus {
|
||||
/**
|
||||
* The price list is enabled and its prices can be used.
|
||||
*/
|
||||
ACTIVE = "active",
|
||||
/**
|
||||
* The price list is disabled, meaning its prices can't be used yet.
|
||||
*/
|
||||
DRAFT = "draft",
|
||||
}
|
||||
export type PriceListStatus = "active" | "draft"
|
||||
|
||||
/**
|
||||
* @enum
|
||||
*
|
||||
* The price list's type.
|
||||
* "sale" - The price list's prices are used for a sale.
|
||||
* "override" - The price list's prices override original prices. This affects the calculated price of associated price sets.
|
||||
*/
|
||||
export enum PriceListType {
|
||||
/**
|
||||
* The price list's prices are used for a sale.
|
||||
*/
|
||||
SALE = "sale",
|
||||
/**
|
||||
* The price list's prices override original prices. This affects the calculated price of associated price sets.
|
||||
*/
|
||||
OVERRIDE = "override",
|
||||
}
|
||||
|
||||
export type PriceListType = "sale" | "override"
|
||||
|
||||
/**
|
||||
* @interface
|
||||
|
||||
@@ -4,12 +4,7 @@ import { OperatorMap } from "../dal/utils"
|
||||
/**
|
||||
* @enum
|
||||
*/
|
||||
export enum ProductStatus {
|
||||
DRAFT = "draft",
|
||||
PROPOSED = "proposed",
|
||||
PUBLISHED = "published",
|
||||
REJECTED = "rejected",
|
||||
}
|
||||
export type ProductStatus = "draft" | "proposed" | "published" | "rejected"
|
||||
|
||||
/**
|
||||
* @interface
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
"author": "Medusa",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@medusajs/types": "^1.11.16",
|
||||
"@types/express": "^4.17.17",
|
||||
"cross-env": "^5.2.1",
|
||||
"express": "^4.18.2",
|
||||
@@ -30,7 +31,6 @@
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/types": "^1.11.16",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { MODULE_RESOURCE_TYPE } from "@medusajs/types"
|
||||
|
||||
export function shouldForceTransaction(target: any): boolean {
|
||||
return target.moduleDeclaration?.resources === MODULE_RESOURCE_TYPE.ISOLATED
|
||||
return target.moduleDeclaration?.resources === "isolated"
|
||||
}
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
import {
|
||||
Logger,
|
||||
MedusaContainer,
|
||||
MODULE_RESOURCE_TYPE,
|
||||
MODULE_SCOPE,
|
||||
ModulesSdkTypes,
|
||||
} from "@medusajs/types"
|
||||
import { Logger, MedusaContainer, ModulesSdkTypes } from "@medusajs/types"
|
||||
import { PostgreSqlDriver, SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { asValue } from "awilix"
|
||||
import { ContainerRegistrationKeys, MedusaError } from "../../common"
|
||||
@@ -60,8 +54,8 @@ export async function mikroOrmConnectionLoader({
|
||||
}
|
||||
|
||||
if (
|
||||
moduleDeclaration?.scope === MODULE_SCOPE.INTERNAL &&
|
||||
moduleDeclaration.resources === MODULE_RESOURCE_TYPE.SHARED
|
||||
moduleDeclaration?.scope === "internal" &&
|
||||
moduleDeclaration.resources === "shared"
|
||||
) {
|
||||
const shouldSwallowError = true
|
||||
const dbConfig = loadDatabaseConfig(
|
||||
|
||||
@@ -8,6 +8,10 @@ export enum PaymentSessionStatus {
|
||||
* The payment is authorized.
|
||||
*/
|
||||
AUTHORIZED = "authorized",
|
||||
/**
|
||||
* The payment is captured.
|
||||
*/
|
||||
CAPTURED = "captured",
|
||||
/**
|
||||
* The payment is pending.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user