feat: region payment providers management workflows/api (#6864)
This commit is contained in:
committed by
GitHub
parent
12fcb655cd
commit
e944a627f0
@@ -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"
|
||||
|
||||
@@ -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"],
|
||||
},
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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")
|
||||
|
||||
9
packages/utils/src/link/compose-link-name.ts
Normal file
9
packages/utils/src/link/compose-link-name.ts
Normal 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("_")
|
||||
}
|
||||
2
packages/utils/src/link/index.ts
Normal file
2
packages/utils/src/link/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./links"
|
||||
export * from "./compose-link-name"
|
||||
79
packages/utils/src/link/links.ts
Normal file
79
packages/utils/src/link/links.ts
Normal 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"
|
||||
),
|
||||
}
|
||||
24
packages/utils/src/modules-sdk/definition.ts
Normal file
24
packages/utils/src/modules-sdk/definition.ts
Normal 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",
|
||||
}
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user