feat: region payment providers management workflows/api (#6864)

This commit is contained in:
Adrien de Peretti
2024-04-04 20:41:34 +02:00
committed by GitHub
parent 12fcb655cd
commit e944a627f0
48 changed files with 1033 additions and 89 deletions

View File

@@ -13,4 +13,5 @@ export * as SearchUtils from "./search"
export * as ShippingProfileUtils from "./shipping"
export * as UserUtils from "./user"
export * as InventoryUtils from "./inventory"
export * as LinkUtils from "./link"
export * as ApiKeyUtils from "./api-key"

View File

@@ -48,6 +48,57 @@ describe("remoteQueryObjectFromString", function () {
"url",
"metadata",
],
isServiceAccess: false,
tags: {
fields: ["id", "created_at", "updated_at", "deleted_at", "value"],
},
options: {
fields: [
"id",
"created_at",
"updated_at",
"deleted_at",
"title",
"product_id",
"metadata",
],
values: {
fields: [
"id",
"created_at",
"updated_at",
"deleted_at",
"value",
"option_id",
"variant_id",
"metadata",
],
},
},
},
})
})
it("should return a remote query object using service entry point", function () {
const output = remoteQueryObjectFromString({
service: "product",
variables: {},
fields,
})
expect(output).toEqual({
product: {
__args: {},
fields: [
"id",
"created_at",
"updated_at",
"deleted_at",
"url",
"metadata",
],
isServiceAccess: true,
tags: {
fields: ["id", "created_at", "updated_at", "deleted_at", "value"],
},

View File

@@ -1,8 +1,6 @@
/**
* Convert a string fields array to a remote query object
* @param entryPoint
* @param variables
* @param fields
* @param config - The configuration object
*
* @example
* const fields = [
@@ -83,28 +81,41 @@
* // },
* // }
*/
export function remoteQueryObjectFromString({
entryPoint,
variables,
fields,
}: {
entryPoint: string
variables?: any
fields: string[]
}): object {
export function remoteQueryObjectFromString(
config:
| {
entryPoint: string
variables?: any
fields: string[]
}
| {
service: string
variables?: any
fields: string[]
}
): object {
const { entryPoint, service, variables, fields } = {
...config,
entryPoint: "entryPoint" in config ? config.entryPoint : undefined,
service: "service" in config ? config.service : undefined,
}
const entryKey = (entryPoint ?? service) as string
const remoteJoinerConfig: object = {
[entryPoint]: {
[entryKey]: {
fields: [],
isServiceAccess: !!service, // specifies if the entry point is a service
},
}
if (variables) {
remoteJoinerConfig[entryPoint]["__args"] = variables
remoteJoinerConfig[entryKey]["__args"] = variables
}
for (const field of fields) {
if (!field.includes(".")) {
remoteJoinerConfig[entryPoint]["fields"].push(field)
remoteJoinerConfig[entryKey]["fields"].push(field)
continue
}
@@ -114,7 +125,7 @@ export function remoteQueryObjectFromString({
const deepConfigRef = fieldSegments.reduce((acc, curr) => {
acc[curr] ??= {}
return acc[curr]
}, remoteJoinerConfig[entryPoint])
}, remoteJoinerConfig[entryKey])
deepConfigRef["fields"] ??= []
deepConfigRef["fields"].push(fieldProperty)

View File

@@ -22,5 +22,6 @@ export * from "./totals"
export * from "./totals/big-number"
export * from "./user"
export * from "./api-key"
export * from "./link"
export const MedusaModuleType = Symbol.for("MedusaModule")

View File

@@ -0,0 +1,9 @@
import { lowerCaseFirst, toPascalCase } from "../common"
export const composeLinkName = (...args) => {
return lowerCaseFirst(toPascalCase(composeTableName(...args.concat("link"))))
}
export const composeTableName = (...args) => {
return args.map((name) => name.replace(/(_id|Service)$/gi, "")).join("_")
}

View File

@@ -0,0 +1,2 @@
export * from "./links"
export * from "./compose-link-name"

View File

@@ -0,0 +1,79 @@
import { Modules } from "../modules-sdk"
import { composeLinkName } from "./compose-link-name"
export const LINKS = {
ProductVariantInventoryItem: composeLinkName(
Modules.PRODUCT,
"variant_id",
Modules.INVENTORY,
"inventory_item_id"
),
ProductVariantPriceSet: composeLinkName(
Modules.PRODUCT,
"variant_id",
Modules.PRICING,
"price_set_id"
),
ShippingOptionPriceSet: composeLinkName(
Modules.FULFILLMENT,
"shipping_option_id",
Modules.PRICING,
"price_set_id"
),
CartPaymentCollection: composeLinkName(
Modules.CART,
"cart_id",
Modules.PAYMENT,
"payment_collection_id"
),
RegionPaymentProvider: composeLinkName(
Modules.REGION,
"region_id",
Modules.PAYMENT,
"payment_provider_id"
),
CartPromotion: composeLinkName(
Modules.CART,
"cart_id",
Modules.PROMOTION,
"promotion_id"
),
SalesChannelLocation: composeLinkName(
Modules.SALES_CHANNEL,
"sales_channel_id",
Modules.STOCK_LOCATION,
"location_id"
),
FulfillmentSetLocation: composeLinkName(
Modules.FULFILLMENT,
"fulfillment_set_id",
Modules.STOCK_LOCATION,
"location_id"
),
PublishableApiKeySalesChannel: composeLinkName(
Modules.API_KEY,
"api_key_id",
Modules.SALES_CHANNEL,
"sales_channel_id"
),
ProductSalesChannel: composeLinkName(
Modules.PRODUCT,
"product_id",
Modules.SALES_CHANNEL,
"sales_channel_id"
),
// Internal services
ProductShippingProfile: composeLinkName(
Modules.PRODUCT,
"variant_id",
"shippingProfileService",
"profile_id"
),
OrderSalesChannel: composeLinkName(
"orderService",
"order_id",
Modules.SALES_CHANNEL,
"sales_channel_id"
),
}

View File

@@ -0,0 +1,24 @@
export enum Modules {
AUTH = "auth",
CACHE = "cacheService",
CART = "cart",
CUSTOMER = "customer",
EVENT_BUS = "eventBus",
INVENTORY = "inventoryService",
LINK = "linkModules",
PAYMENT = "payment",
PRICING = "pricingService",
PRODUCT = "productService",
PROMOTION = "promotion",
SALES_CHANNEL = "salesChannel",
TAX = "tax",
FULFILLMENT = "fulfillment",
STOCK_LOCATION = "stockLocationService",
USER = "user",
WORKFLOW_ENGINE = "workflows",
REGION = "region",
ORDER = "order",
API_KEY = "apiKey",
STORE = "store",
CURRENCY = "currency",
}

View File

@@ -8,3 +8,4 @@ export * from "./create-pg-connection"
export * from "./migration-scripts"
export * from "./internal-module-service-factory"
export * from "./abstract-module-service-factory"
export * from "./definition"