Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(): Update module provider retrieval error message and type #10138

Merged
merged 7 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/wet-ears-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@medusajs/auth": patch
"@medusajs/fulfillment": patch
"@medusajs/locking": patch
"@medusajs/notification": patch
"@medusajs/payment": patch
---

chore(): Update module provider retrieval error message and type
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ moduleIntegrationTestRunner({

expect(err).toEqual({
success: false,
error: "Could not find a auth provider with id: facebook",
error:
"\n Unable to retrieve the auth provider with id: facebook\n Please make sure that the provider is registered in the container and it is configured correctly in your project configuration file.\n ",
})
})

Expand Down
2 changes: 2 additions & 0 deletions packages/modules/auth/src/services/auth-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Context,
DAL,
InternalModuleDeclaration,
Logger,
ModuleJoinerConfig,
ModulesSdkTypes,
} from "@medusajs/framework/types"
Expand All @@ -24,6 +25,7 @@ type InjectedDependencies = {
authIdentityService: ModulesSdkTypes.IMedusaInternalService<any>
providerIdentityService: ModulesSdkTypes.IMedusaInternalService<any>
authProviderService: AuthProviderService
logger?: Logger
}
export default class AuthModuleService
extends MedusaService<{
Expand Down
17 changes: 12 additions & 5 deletions packages/modules/auth/src/services/auth-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,26 @@ import {
AuthenticationResponse,
AuthIdentityProviderService,
AuthTypes,
Logger,
} from "@medusajs/framework/types"
import { MedusaError } from "@medusajs/framework/utils"
import { AuthProviderRegistrationPrefix } from "@types"

type InjectedDependencies = {
[
key: `${typeof AuthProviderRegistrationPrefix}${string}`
]: AuthTypes.IAuthProvider
logger?: Logger
}

export default class AuthProviderService {
protected dependencies: InjectedDependencies
#logger: Logger

constructor(container: InjectedDependencies) {
this.dependencies = container
this.#logger = container["logger"]
? container.logger
: (console as unknown as Logger)
}

protected retrieveProviderRegistration(
Expand All @@ -26,10 +31,12 @@ export default class AuthProviderService {
try {
return this.dependencies[`${AuthProviderRegistrationPrefix}${providerId}`]
} catch (err) {
throw new MedusaError(
MedusaError.Types.NOT_FOUND,
`Could not find a auth provider with id: ${providerId}`
)
const errMessage = `
Unable to retrieve the auth provider with id: ${providerId}
Please make sure that the provider is registered in the container and it is configured correctly in your project configuration file.
`
this.#logger.error(errMessage)
throw new Error(errMessage)
olivermrbl marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
FulfillmentTypes,
IFulfillmentModuleService,
InternalModuleDeclaration,
Logger,
ModuleJoinerConfig,
ModulesSdkTypes,
ShippingOptionDTO,
Expand Down Expand Up @@ -76,6 +77,7 @@ type InjectedDependencies = {
shippingOptionTypeService: ModulesSdkTypes.IMedusaInternalService<any>
fulfillmentProviderService: FulfillmentProviderService
fulfillmentService: ModulesSdkTypes.IMedusaInternalService<any>
logger?: Logger
}

export default class FulfillmentModuleService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
DAL,
FulfillmentTypes,
IFulfillmentProvider,
Logger,
} from "@medusajs/framework/types"
import {
MedusaError,
Expand All @@ -12,6 +13,7 @@ import {
import { FulfillmentProvider } from "@models"

type InjectedDependencies = {
logger?: Logger
fulfillmentProviderRepository: DAL.RepositoryService
[key: `fp_${string}`]: FulfillmentTypes.IFulfillmentProvider
}
Expand All @@ -22,11 +24,15 @@ export default class FulfillmentProviderService extends ModulesSdkUtils.MedusaIn
FulfillmentProvider
) {
protected readonly fulfillmentProviderRepository_: DAL.RepositoryService
#logger: Logger

constructor(container: InjectedDependencies) {
super(container)
this.fulfillmentProviderRepository_ =
container.fulfillmentProviderRepository
this.#logger = container["logger"]
? container.logger
: (console as unknown as Logger)
}

static getRegistrationIdentifier(
Expand All @@ -48,10 +54,12 @@ export default class FulfillmentProviderService extends ModulesSdkUtils.MedusaIn
try {
return this.__container__[`fp_${providerId}`]
} catch (err) {
throw new MedusaError(
MedusaError.Types.NOT_FOUND,
`Could not find a fulfillment provider with id: ${providerId}`
)
const errMessage = `
Unable to retrieve the fulfillment provider with id: ${providerId}
Please make sure that the provider is registered in the container and it is configured correctly in your project configuration file.
`
this.#logger.error(errMessage)
throw new Error(errMessage)
olivermrbl marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/modules/locking/src/services/locking-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
Context,
ILockingModule,
InternalModuleDeclaration,
Logger,
} from "@medusajs/types"
import { EntityManager } from "@mikro-orm/core"
import { LockingDefaultProvider } from "@types"
Expand All @@ -10,6 +11,7 @@ import LockingProviderService from "./locking-provider"
type InjectedDependencies = {
manager: EntityManager
lockingProviderService: LockingProviderService
logger?: Logger
[LockingDefaultProvider]: string
}

Expand Down
21 changes: 16 additions & 5 deletions packages/modules/locking/src/services/locking-provider.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import { Constructor, ILockingProvider } from "@medusajs/framework/types"
import {
Constructor,
ILockingProvider,
Logger,
} from "@medusajs/framework/types"
import { MedusaError } from "@medusajs/framework/utils"
import { LockingProviderRegistrationPrefix } from "../types"

type InjectedDependencies = {
[key: `lp_${string}`]: ILockingProvider
logger?: Logger
}

export default class LockingProviderService {
protected __container__: InjectedDependencies
#logger: Logger

constructor(container: InjectedDependencies) {
this.__container__ = container
this.#logger = container["logger"]
? container.logger
: (console as unknown as Logger)
}

static getRegistrationIdentifier(
Expand All @@ -31,10 +40,12 @@ export default class LockingProviderService {
`${LockingProviderRegistrationPrefix}${providerId}`
]
} catch (err) {
throw new MedusaError(
MedusaError.Types.NOT_FOUND,
`Could not find a locking provider with id: ${providerId}`
)
const errMessage = `
Unable to retrieve the locking provider with id: ${providerId}
Please make sure that the provider is registered in the container and it is configured correctly in your project configuration file.
`
this.#logger.error(errMessage)
throw new Error(errMessage)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
InferEntityType,
INotificationModuleService,
InternalModuleDeclaration,
Logger,
ModulesSdkTypes,
NotificationTypes,
} from "@medusajs/framework/types"
Expand All @@ -22,6 +23,7 @@ import { eventBuilders } from "@utils"
import NotificationProviderService from "./notification-provider"

type InjectedDependencies = {
logger?: Logger
baseRepository: DAL.RepositoryService
notificationService: ModulesSdkTypes.IMedusaInternalService<
typeof Notification
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import {
DAL,
InferEntityType,
Logger,
NotificationTypes,
} from "@medusajs/framework/types"
import { MedusaError, ModulesSdkUtils } from "@medusajs/framework/utils"
import { ModulesSdkUtils } from "@medusajs/framework/utils"
import { NotificationProvider } from "@models"
import { NotificationProviderRegistrationPrefix } from "@types"

type InjectedDependencies = {
logger?: Logger
notificationProviderRepository: DAL.RepositoryService<
InferEntityType<typeof NotificationProvider>
>
Expand All @@ -25,7 +27,11 @@ export default class NotificationProviderService extends ModulesSdkUtils.MedusaI
protected readonly notificationProviderRepository_: DAL.RepositoryService<
InferEntityType<typeof NotificationProvider>
>

// We can store the providers in a memory since they can only be registered on startup and not changed during runtime

#logger: Logger

protected providersCache: Map<
string,
InferEntityType<typeof NotificationProvider>
Expand All @@ -35,6 +41,9 @@ export default class NotificationProviderService extends ModulesSdkUtils.MedusaI
super(container)
this.notificationProviderRepository_ =
container.notificationProviderRepository
this.#logger = container["logger"]
? container.logger
: (console as unknown as Logger)
}

protected retrieveProviderRegistration(
Expand All @@ -45,10 +54,12 @@ export default class NotificationProviderService extends ModulesSdkUtils.MedusaI
`${NotificationProviderRegistrationPrefix}${providerId}`
]
} catch (err) {
throw new MedusaError(
MedusaError.Types.NOT_FOUND,
`Could not find a notification provider with id: ${providerId}`
)
const errMessage = `
Unable to retrieve the notification provider with id: ${providerId}
Please make sure that the provider is registered in the container and it is configured correctly in your project configuration file.
`
this.#logger.error(errMessage)
throw new Error(errMessage)
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/modules/payment/src/services/payment-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
FindConfig,
InternalModuleDeclaration,
IPaymentModuleService,
Logger,
ModuleJoinerConfig,
ModulesSdkTypes,
PaymentCollectionDTO,
Expand Down Expand Up @@ -54,6 +55,7 @@ import { joinerConfig } from "../joiner-config"
import PaymentProviderService from "./payment-provider"

type InjectedDependencies = {
logger?: Logger
baseRepository: DAL.RepositoryService
paymentService: ModulesSdkTypes.IMedusaInternalService<any>
captureService: ModulesSdkTypes.IMedusaInternalService<any>
Expand Down
21 changes: 17 additions & 4 deletions packages/modules/payment/src/services/payment-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
CreatePaymentProviderSession,
DAL,
IPaymentProvider,
Logger,
PaymentProviderAuthorizeResponse,
PaymentProviderDataInput,
PaymentProviderError,
Expand All @@ -21,21 +22,33 @@ import { PaymentProvider } from "@models"
import { EOL } from "os"

type InjectedDependencies = {
logger?: Logger
paymentProviderRepository: DAL.RepositoryService
[key: `pp_${string}`]: IPaymentProvider
}

export default class PaymentProviderService extends ModulesSdkUtils.MedusaInternalService<InjectedDependencies>(
PaymentProvider
) {
#logger: Logger

constructor(container: InjectedDependencies) {
super(container)
this.#logger = container["logger"]
? container.logger
: (console as unknown as Logger)
}

retrieveProvider(providerId: string): IPaymentProvider {
try {
return this.__container__[providerId] as IPaymentProvider
} catch (e) {
throw new MedusaError(
MedusaError.Types.NOT_FOUND,
`Could not find a payment provider with id: ${providerId}`
)
const errMessage = `
Unable to retrieve the payment provider with id: ${providerId}
Please make sure that the provider is registered in the container and it is configured correctly in your project configuration file.
`
this.#logger.error(errMessage)
throw new Error(errMessage)
}
}

Expand Down
Loading