figma-development-kit
Advanced tools
Comparing version 1.0.8 to 1.0.10
@@ -7,8 +7,7 @@ const storageKeyForAuthorizationCodeData = 'figma-authorization-code-data'; | ||
class FigmaApi { | ||
constructor(config) { | ||
if(!config) throw Error('config is required'); | ||
if(!config.clientId) throw Error('clientId is required'); | ||
if(!config.clientSecrete) throw Error('clientSecrete is required'); | ||
if(!config.redirectUri) throw Error('redirectUri is required'); | ||
this.config = config; | ||
constructor({clientId, clientSecrete, redirectUri}) { | ||
if(!clientId) throw Error('clientId is required'); | ||
if(!clientSecrete) throw Error('clientSecrete is required'); | ||
if(!redirectUri) throw Error('redirectUri is required'); | ||
this.config = {clientId, clientSecrete, redirectUri}; | ||
} | ||
@@ -18,3 +17,3 @@ | ||
/* if a token exists and hasn't expired, re-use it */ | ||
const existingTokenData = JSON.parse(localStorage.getItem(storageKeyForAccessTokenData)); | ||
const existingTokenData = JSON.parse(window.localStorage.getItem(storageKeyForAccessTokenData)); | ||
if (existingTokenData && existingTokenData.expireOnEpoch > Date.now()) { | ||
@@ -42,5 +41,5 @@ return existingTokenData.token; | ||
if (event.key === storageKeyForAuthorizationCodeData) { | ||
const {code, state} = JSON.parse(localStorage.getItem(storageKeyForAuthorizationCodeData)); | ||
const {code, state} = JSON.parse(window.localStorage.getItem(storageKeyForAuthorizationCodeData)); | ||
window.removeEventListener('storage', storageEventHandler); | ||
localStorage.removeItem(storageKeyForAuthorizationCodeData); | ||
window.localStorage.removeItem(storageKeyForAuthorizationCodeData); | ||
if (state !== trueState) { | ||
@@ -68,3 +67,3 @@ reject('STATE_MISMATCH'); | ||
storeAccessTokenData(accessTokenData) { | ||
localStorage.setItem(storageKeyForAccessTokenData, JSON.stringify(accessTokenData)); | ||
window.localStorage.setItem(storageKeyForAccessTokenData, JSON.stringify(accessTokenData)); | ||
return accessTokenData.token; | ||
@@ -71,0 +70,0 @@ } |
@@ -13,8 +13,7 @@ (function (global, factory) { | ||
class FigmaApi { | ||
constructor(config) { | ||
if(!config) throw Error('config is required'); | ||
if(!config.clientId) throw Error('clientId is required'); | ||
if(!config.clientSecrete) throw Error('clientSecrete is required'); | ||
if(!config.redirectUri) throw Error('redirectUri is required'); | ||
this.config = config; | ||
constructor({clientId, clientSecrete, redirectUri}) { | ||
if(!clientId) throw Error('clientId is required'); | ||
if(!clientSecrete) throw Error('clientSecrete is required'); | ||
if(!redirectUri) throw Error('redirectUri is required'); | ||
this.config = {clientId, clientSecrete, redirectUri}; | ||
} | ||
@@ -24,3 +23,3 @@ | ||
/* if a token exists and hasn't expired, re-use it */ | ||
const existingTokenData = JSON.parse(localStorage.getItem(storageKeyForAccessTokenData)); | ||
const existingTokenData = JSON.parse(window.localStorage.getItem(storageKeyForAccessTokenData)); | ||
if (existingTokenData && existingTokenData.expireOnEpoch > Date.now()) { | ||
@@ -48,5 +47,5 @@ return existingTokenData.token; | ||
if (event.key === storageKeyForAuthorizationCodeData) { | ||
const {code, state} = JSON.parse(localStorage.getItem(storageKeyForAuthorizationCodeData)); | ||
const {code, state} = JSON.parse(window.localStorage.getItem(storageKeyForAuthorizationCodeData)); | ||
window.removeEventListener('storage', storageEventHandler); | ||
localStorage.removeItem(storageKeyForAuthorizationCodeData); | ||
window.localStorage.removeItem(storageKeyForAuthorizationCodeData); | ||
if (state !== trueState) { | ||
@@ -74,3 +73,3 @@ reject('STATE_MISMATCH'); | ||
storeAccessTokenData(accessTokenData) { | ||
localStorage.setItem(storageKeyForAccessTokenData, JSON.stringify(accessTokenData)); | ||
window.localStorage.setItem(storageKeyForAccessTokenData, JSON.stringify(accessTokenData)); | ||
return accessTokenData.token; | ||
@@ -77,0 +76,0 @@ } |
{ | ||
"name": "figma-development-kit", | ||
"version": "1.0.8", | ||
"version": "1.0.10", | ||
"description": "A set of tools that augment the Figma API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -7,8 +7,7 @@ const storageKeyForAuthorizationCodeData = 'figma-authorization-code-data'; | ||
export class FigmaApi { | ||
constructor(config) { | ||
if(!config) throw Error('config is required'); | ||
if(!config.clientId) throw Error('clientId is required'); | ||
if(!config.clientSecrete) throw Error('clientSecrete is required'); | ||
if(!config.redirectUri) throw Error('redirectUri is required'); | ||
this.config = config; | ||
constructor({clientId, clientSecrete, redirectUri}) { | ||
if(!clientId) throw Error('clientId is required'); | ||
if(!clientSecrete) throw Error('clientSecrete is required'); | ||
if(!redirectUri) throw Error('redirectUri is required'); | ||
this.config = {clientId, clientSecrete, redirectUri}; | ||
} | ||
@@ -18,3 +17,3 @@ | ||
/* if a token exists and hasn't expired, re-use it */ | ||
const existingTokenData = JSON.parse(localStorage.getItem(storageKeyForAccessTokenData)); | ||
const existingTokenData = JSON.parse(window.localStorage.getItem(storageKeyForAccessTokenData)); | ||
if (existingTokenData && existingTokenData.expireOnEpoch > Date.now()) { | ||
@@ -42,5 +41,5 @@ return existingTokenData.token; | ||
if (event.key === storageKeyForAuthorizationCodeData) { | ||
const {code, state} = JSON.parse(localStorage.getItem(storageKeyForAuthorizationCodeData)); | ||
const {code, state} = JSON.parse(window.localStorage.getItem(storageKeyForAuthorizationCodeData)); | ||
window.removeEventListener('storage', storageEventHandler); | ||
localStorage.removeItem(storageKeyForAuthorizationCodeData); | ||
window.localStorage.removeItem(storageKeyForAuthorizationCodeData); | ||
if (state !== trueState) { | ||
@@ -68,5 +67,5 @@ reject('STATE_MISMATCH'); | ||
storeAccessTokenData(accessTokenData) { | ||
localStorage.setItem(storageKeyForAccessTokenData, JSON.stringify(accessTokenData)); | ||
window.localStorage.setItem(storageKeyForAccessTokenData, JSON.stringify(accessTokenData)); | ||
return accessTokenData.token; | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
14418
183