prici-io / prici

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

bug: nest guard has a type check problem with the SDK #39

Closed davidmeirlevy closed 6 months ago

davidmeirlevy commented 6 months ago

when coding:

 @Post("todos")
    @UseGuards(new IsAllowedGuard({
        // @ts-ignore
        sdk: priciSdk,
        errorMessage: "User is out of quota",
        getAccountId: (_) => "demo-account",
        getFieldId: (_) => featureId
    }))
    createTodo(@Body() body: any) {
        return this.appService.createTodo(body);
    }

without the ts-ignore - this code will never pass the build. the error is:

TS2739: Type PriciSdk is missing the following properties from type PriciSdk: #remult, #accountFields

those are js private properties, and it's literally the same class, so it's weird that it's not passing.

davidmeirlevy commented 6 months ago

@eladabramovich would you like to check this out?

eladabramovich commented 6 months ago

@davidmeirlevy yes, please assign it to me.

davidmeirlevy commented 6 months ago

Looks like it was fixed on your latest PR with the new nest implementation. @eladabramovich am just right?

eladabramovich commented 6 months ago

Edit: after messing with it a bit more and checking recent commit changes it looks like the root of the problem is from the auto-generated index.d.ts file but I haven't dug deep enough yet to understand how to fix it.

It's definitely less of an issue now that the sdk property is optional but if you explicitly create a second PriciSdk instance and pass it in the guard then it will still happen. From what I observed until now, it seems that it is somehow related to the module resolution. When I changed PriciSdk import in isAllowed.guard.ts from ../index to @prici/sdk it resolved the problem but the build failed on a different issue