@integration-app/sdk
Advanced tools
Comparing version 0.2.3 to 0.2.4
@@ -38,3 +38,2 @@ import { ConnectionsQuery, FindConnectionsResponse } from './connections'; | ||
constructor(options: IntegrationAppClientOptions); | ||
private isJWTToken; | ||
init(options: IntegrationAppClientOptions): void; | ||
@@ -41,0 +40,0 @@ findIntegratedApps(): Promise<any>; |
@@ -30,22 +30,5 @@ "use strict"; | ||
} | ||
isJWTToken(token) { | ||
if (typeof token !== 'string') | ||
return false; | ||
const splittedToken = token.split('.'); | ||
if (splittedToken.length !== 3) | ||
return false; | ||
let tokenHeaderDecoded; | ||
try { | ||
tokenHeaderDecoded = JSON.parse(atob(splittedToken[0])); | ||
} | ||
catch { | ||
return false; | ||
} | ||
return (typeof tokenHeaderDecoded.typ === 'string' && | ||
tokenHeaderDecoded.typ.toLowerCase() === 'jwt'); | ||
} | ||
init(options) { | ||
if (options.accessToken !== undefined && | ||
!this.isJWTToken(options.accessToken)) | ||
throw new Error('Access token should be a valid JWT token'); | ||
if (options.accessToken !== undefined) | ||
throw new Error('accessToken was not provided'); | ||
this.initialized = true; | ||
@@ -52,0 +35,0 @@ this.apiUri = options.apiUri || DEFAULT_API_URI; |
{ | ||
"name": "@integration-app/sdk", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "JavaScript SDK for Integration.app", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -61,27 +61,5 @@ import Pusher, { Channel } from 'pusher-js' | ||
private isJWTToken(token: any) { | ||
if (typeof token !== 'string') return false | ||
const splittedToken = token.split('.') | ||
if (splittedToken.length !== 3) return false | ||
let tokenHeaderDecoded | ||
try { | ||
tokenHeaderDecoded = JSON.parse(atob(splittedToken[0])) | ||
} catch { | ||
return false | ||
} | ||
return ( | ||
typeof tokenHeaderDecoded.typ === 'string' && | ||
tokenHeaderDecoded.typ.toLowerCase() === 'jwt' | ||
) | ||
} | ||
public init(options: IntegrationAppClientOptions) { | ||
if ( | ||
options.accessToken !== undefined && | ||
!this.isJWTToken(options.accessToken) | ||
) | ||
throw new Error('Access token should be a valid JWT token') | ||
if (options.accessToken !== undefined) | ||
throw new Error('accessToken was not provided') | ||
@@ -88,0 +66,0 @@ this.initialized = true |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
2466916
28686