prici-io / prici

manage plans and pricing for any SaaS application
https://prici.io
MIT License
37 stars 5 forks source link

enhancement: improve NestJs support #33

Closed eladabramovich closed 6 months ago

eladabramovich commented 6 months ago

Currently, when creating a new Prici SDK instance in a NestJs app the app does not know about the SDK instance in any way. This means that the SDK does not work in tandem with the Nest runtime. By abstracting the SDK instance in a custom module, the following could be achieved:

davidmeirlevy commented 6 months ago

Basically you want the SDK to be an injectable? and to have the guard as "given"?

sounds great. go for it ! 🚀

eladabramovich commented 6 months ago

You are correct about the SDK being injectable. Not sure about what you meant by "given" but basically, the SDK will be instantiated in a service that the new module will export and I will add an optional defaultErrorMessage property to PriciSDKOptions (for cases where the user wants one default message for all routes that is not "payment required").

With these 2 changes, the guard doesn't have any required options anymore and can be reduced to:

@UseGuards(IsAllowedGuard())

P.S I was able to implement the guard in a slightly different way that doesn't require invoking it with the new keyword