chore: Update modules providers configuration with 'identifier' and 'PROVIDER' (#9636)

* chore: Update modules providers configuration with 'identifier' and 'PROVIDER'

* update check

* fix tests

* type

* normalize auth provider

* emailpass

* providers

---------

Co-authored-by: Carlos R. L. Rodrigues <rodrigolr@gmail.com>
Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2024-10-18 09:24:15 +02:00
1 parent 902ac12f73
commit 876d8072e7
22 files changed
+131 -67

No files matched your search

@@ -10,6 +10,8 @@ import {
} from "@medusajs/framework/utils"
export class AuthServiceFixtures extends AbstractAuthModuleProvider {
static identifier = "plaintextpass"
constructor() {
super(
{},
@@ -4,7 +4,10 @@ import {
ModuleProvider,
ModulesSdkTypes,
} from "@medusajs/framework/types"
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
import {
ContainerRegistrationKeys,
getProviderRegistrationKey,
} from "@medusajs/framework/utils"
import { LockingProviderService } from "@services"
import {
LockingDefaultProvider,
@@ -14,10 +17,20 @@ import {
import { Lifetime, aliasTo, asFunction, asValue } from "awilix"
import { InMemoryLockingProvider } from "../providers/in-memory"
const registrationFn = async (klass, container) => {
const registrationFn = async (klass, container, { id }) => {
const key = LockingProviderService.getRegistrationIdentifier(klass)
if (!id) {
throw new Error(`No "id" provided for provider ${key}`)
}
const regKey = getProviderRegistrationKey({
providerId: id,
providerIdentifier: key,
})
container.register({
[LockingProviderRegistrationPrefix + key]: aliasTo("__providers__" + key),
[LockingProviderRegistrationPrefix + key]: aliasTo(regKey),
})
container.registerAdd(LockingIdentifiersRegistrationName, asValue(key))
@@ -5,7 +5,7 @@ import {
ModuleProvider,
ModulesSdkTypes,
} from "@medusajs/framework/types"
import { Lifetime, asFunction, asValue } from "awilix"
import { asFunction, asValue, Lifetime } from "awilix"
import { MedusaError } from "@medusajs/framework/utils"
import { PaymentProviderService } from "@services"
@@ -14,14 +14,16 @@ import * as providers from "../providers"
const PROVIDER_REGISTRATION_KEY = "payment_providers"
const registrationFn = async (klass, container, pluginOptions) => {
if (!klass?.PROVIDER) {
if (!klass?.identifier) {
throw new MedusaError(
MedusaError.Types.INVALID_ARGUMENT,
`Trying to register a payment provider without a provider identifier.`
)
}
const key = `pp_${klass.PROVIDER}_${pluginOptions.id}`
const key = `pp_${klass.identifier}${
pluginOptions.id ? `_${pluginOptions.id}` : ""
}`
container.register({
[key]: asFunction((cradle) => new klass(cradle, pluginOptions.options), {
@@ -13,7 +13,6 @@ import {
export class SystemProviderService extends AbstractPaymentProvider {
static identifier = "system"
static PROVIDER = "system"
async getStatus(_): Promise<string> {
return "authorized"
@@ -20,6 +20,9 @@ type InjectedDependencies = {
interface LocalServiceConfig extends EmailPassAuthProviderOptions {}
export class EmailPassAuthService extends AbstractAuthModuleProvider {
static identifier = "emailpass"
static DISPLAY_NAME = "Email/Password Authentication"
protected config_: LocalServiceConfig
protected logger_: Logger
@@ -27,10 +30,8 @@ export class EmailPassAuthService extends AbstractAuthModuleProvider {
{ logger }: InjectedDependencies,
options: EmailPassAuthProviderOptions
) {
super(
{},
{ provider: "emailpass", displayName: "Email/Password Authentication" }
)
// @ts-ignore
super(...arguments)
this.config_ = options
this.logger_ = logger
}
@@ -18,6 +18,9 @@ interface LocalServiceConfig extends GithubAuthProviderOptions {}
// TODO: Add state param that is stored in Redis, to prevent CSRF attacks
export class GithubAuthService extends AbstractAuthModuleProvider {
static identifier = "github"
static DISPLAY_NAME = "Github Authentication"
protected config_: LocalServiceConfig
protected logger_: Logger
@@ -39,7 +42,8 @@ export class GithubAuthService extends AbstractAuthModuleProvider {
{ logger }: InjectedDependencies,
options: GithubAuthProviderOptions
) {
super({}, { provider: "github", displayName: "Github Authentication" })
// @ts-ignore
super(...arguments)
this.config_ = options
this.logger_ = logger
}
@@ -19,6 +19,9 @@ interface LocalServiceConfig extends GoogleAuthProviderOptions {}
// TODO: Add state param that is stored in Redis, to prevent CSRF attacks
export class GoogleAuthService extends AbstractAuthModuleProvider {
static identifier = "google"
static DISPLAY_NAME = "Google Authentication"
protected config_: LocalServiceConfig
protected logger_: Logger
@@ -40,7 +43,8 @@ export class GoogleAuthService extends AbstractAuthModuleProvider {
{ logger }: InjectedDependencies,
options: GoogleAuthProviderOptions
) {
super({}, { provider: "google", displayName: "Google Authentication" })
// @ts-ignore
super(...arguments)
this.config_ = options
this.logger_ = logger
}
@@ -1,7 +1,7 @@
import {
LocalNotificationServiceOptions,
Logger,
NotificationTypes,
LocalNotificationServiceOptions,
} from "@medusajs/framework/types"
import {
AbstractNotificationProviderService,
@@ -15,6 +15,7 @@ type InjectedDependencies = {
interface LocalServiceConfig {}
export class LocalNotificationService extends AbstractNotificationProviderService {
static identifier = "notification-local"
protected config_: LocalServiceConfig
protected logger_: Logger
@@ -19,6 +19,7 @@ interface SendgridServiceConfig {
}
export class SendgridNotificationService extends AbstractNotificationProviderService {
static identifier = "notification-sendgrid"
protected config_: SendgridServiceConfig
protected logger_: Logger
@@ -2,7 +2,7 @@ import StripeBase from "../core/stripe-base"
import { PaymentIntentOptions, PaymentProviderKeys } from "../types"
class BancontactProviderService extends StripeBase {
static PROVIDER = PaymentProviderKeys.BAN_CONTACT
static identifier = PaymentProviderKeys.BAN_CONTACT
constructor(_, options) {
super(_, options)
@@ -2,7 +2,7 @@ import StripeBase from "../core/stripe-base"
import { PaymentIntentOptions, PaymentProviderKeys } from "../types"
class BlikProviderService extends StripeBase {
static PROVIDER = PaymentProviderKeys.BLIK
static identifier = PaymentProviderKeys.BLIK
constructor(_, options) {
super(_, options)
@@ -2,7 +2,7 @@ import StripeBase from "../core/stripe-base"
import { PaymentIntentOptions, PaymentProviderKeys } from "../types"
class GiropayProviderService extends StripeBase {
static PROVIDER = PaymentProviderKeys.GIROPAY
static identifier = PaymentProviderKeys.GIROPAY
constructor(_, options) {
super(_, options)
@@ -2,7 +2,7 @@ import StripeBase from "../core/stripe-base"
import { PaymentIntentOptions, PaymentProviderKeys } from "../types"
class IdealProviderService extends StripeBase {
static PROVIDER = PaymentProviderKeys.IDEAL
static identifier = PaymentProviderKeys.IDEAL
constructor(_, options) {
super(_, options)
@@ -2,7 +2,7 @@ import StripeBase from "../core/stripe-base"
import { PaymentIntentOptions, PaymentProviderKeys } from "../types"
class StripeProviderService extends StripeBase {
static PROVIDER = PaymentProviderKeys.STRIPE
static identifier = PaymentProviderKeys.STRIPE
constructor(_, options) {
super(_, options)
@@ -2,7 +2,7 @@ import StripeBase from "../core/stripe-base"
import { PaymentIntentOptions, PaymentProviderKeys } from "../types"
class Przelewy24ProviderService extends StripeBase {
static PROVIDER = PaymentProviderKeys.PRZELEWY_24
static identifier = PaymentProviderKeys.PRZELEWY_24
constructor(_, options) {
super(_, options)