twilio / twilio-flex-token-validator

Flex JWE Token Validator
MIT License
17 stars 12 forks source link

[BUG] Cannot find namespace 'Twilio' #26

Open katafractari opened 3 years ago

katafractari commented 3 years ago

Description

I have a Typescript project (NestJS) in which in want to use twilio-flex-token-validator. I get a compile time error Cannot find namespace 'Twilio' after I import it in the project.

Versions

package version
twilio-flex-token-validator 1.5.4
node 15.0.1
npm 7.0.3
typescript 3.7.4

Steps to Reproduce

  1. npm i -S twilio-flex-token-validator
  2. Import package with import * as twilio from 'twilio'
  3. Get the following error
    
    node_modules/twilio-flex-token-validator/dist/index.d.ts:9:55 - error TS2503: Cannot find namespace 'Twilio'.

9 export declare type Callback = (error: any, response: Twilio.Response) => void;

ktalebian commented 3 years ago

@katafractari this package is intended to be used with Twilio Functions - Twilio is a global variable available in the Twilio Functions runtime environment.

Are you trying to use this within your Typescript server app?

ktalebian commented 3 years ago

I'm changing the tag as this is not a bug per se but rather a new feature.

katafractari commented 3 years ago

@ktalebian Yes, I'm trying to use the validator(token: string, accountSid: string, authToken: string): Promise<object> within a Node/Typescript server project. I tagged this ticket as a bug because the README.md states that this package can be used in an existing Node application.

I need to validate Twilio Flex JWT in my API project because that's how we authenticate requests coming from our Twilio Flex Plugin. My current workaround is to declare the Twilio namescape in my custom typings.d.ts file.

ktalebian commented 3 years ago

@katafractari sorry about the delay; I made this PR https://github.com/twilio/twilio-flex-token-validator/pull/27/files to address the problem

ktalebian commented 3 years ago

@katafractari would you mind giving v1.5.5 a try and see if that fixes your problem?

katafractari commented 3 years ago

@ktalebian I bumped the version to 1.5.5 and removed Twilio namespace declaration from my typings.d.ts, which did not produces any errors. Thanks for the fix!