feat: Flatten the provider config for all modules (#7930)
This commit is contained in:
@@ -11,17 +11,15 @@ import * as providers from "../providers"
|
||||
import { PaymentProviderService } from "@services"
|
||||
|
||||
const registrationFn = async (klass, container, pluginOptions) => {
|
||||
Object.entries(pluginOptions.config || []).map(([name, config]) => {
|
||||
const key = `pp_${klass.PROVIDER}_${name}`
|
||||
const key = `pp_${klass.PROVIDER}_${pluginOptions.id}`
|
||||
|
||||
container.register({
|
||||
[key]: asFunction((cradle) => new klass(cradle, config), {
|
||||
lifetime: klass.LIFE_TIME || Lifetime.SINGLETON,
|
||||
}),
|
||||
})
|
||||
|
||||
container.registerAdd("payment_providers", asValue(key))
|
||||
container.register({
|
||||
[key]: asFunction((cradle) => new klass(cradle, pluginOptions.options), {
|
||||
lifetime: klass.LIFE_TIME || Lifetime.SINGLETON,
|
||||
}),
|
||||
})
|
||||
|
||||
container.registerAdd("payment_providers", asValue(key))
|
||||
}
|
||||
|
||||
export default async ({
|
||||
@@ -35,7 +33,7 @@ export default async ({
|
||||
>): Promise<void> => {
|
||||
// Local providers
|
||||
for (const provider of Object.values(providers)) {
|
||||
await registrationFn(provider, container, { config: { default: {} } })
|
||||
await registrationFn(provider, container, { id: "default" })
|
||||
}
|
||||
|
||||
await moduleProviderLoader({
|
||||
|
||||
@@ -17,11 +17,13 @@ export type PaymentModuleOptions = Partial<ModuleServiceInitializeOptions> & {
|
||||
* The module provider to be registered
|
||||
*/
|
||||
resolve: string | ModuleProviderExports
|
||||
options: {
|
||||
/**
|
||||
* key value pair of the provider name and the configuration to be passed to the provider constructor
|
||||
*/
|
||||
config: Record<string, unknown>
|
||||
}
|
||||
/**
|
||||
* The id of the provider
|
||||
*/
|
||||
id: string
|
||||
/**
|
||||
* key value pair of the configuration to be passed to the provider constructor
|
||||
*/
|
||||
options?: Record<string, unknown>
|
||||
}[]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user