1- import jwtDecode from " jwt-decode" ;
2- import inquirer from " inquirer" ;
3- import ora from " ora" ;
1+ import jwtDecode from ' jwt-decode' ;
2+ import inquirer from ' inquirer' ;
3+ import ora from ' ora' ;
44
5- import api from " ./api.js" ;
6- import { error , log } from " ../helpers.js" ;
7- import { doLogin } from " ../login.js" ;
8- import { updateConfig } from " ../config.js" ;
5+ import api from ' ./api.js' ;
6+ import { error , log } from ' ../helpers.js' ;
7+ import { doLogin } from ' ../login.js' ;
8+ import { updateConfig } from ' ../config.js' ;
99
1010let token = null ;
1111let tokenExpiresAt = null ;
@@ -37,15 +37,15 @@ function setTokenExpiresAt() {
3737 const decoded = jwtDecode ( token ) ;
3838 tokenExpiresAt = new Date ( decoded . exp * 1000 ) ;
3939 } catch ( e ) {
40- console . warn ( " Could not decode token, is it a JWT?" ) ;
40+ console . warn ( ' Could not decode token, is it a JWT?' ) ;
4141 }
4242 }
4343}
4444
4545async function checkCorrectOrganisation ( orgUuid , opts , currentOrganisation ) {
4646 let organisationUuid = orgUuid ;
4747 if ( ! organisationUuid ) {
48- const permChecker = ora ( " Checking campaign permissions..." ) . start ( ) ;
48+ const permChecker = ora ( ' Checking campaign permissions...' ) . start ( ) ;
4949 try {
5050 const campaignUuid = opts . campaigns [ 0 ] ;
5151 const campaign = await api ( {
@@ -58,7 +58,7 @@ async function checkCorrectOrganisation(orgUuid, opts, currentOrganisation) {
5858 } catch ( e ) {
5959 error ( e , permChecker ) ;
6060 console . error (
61- " Could not retrieve the campaign. Are you switched into the correct organisation?"
61+ ' Could not retrieve the campaign. Are you switched into the correct organisation?'
6262 ) ;
6363
6464 // A bit hacky, but saves a lot of conditional code all over or
@@ -69,28 +69,28 @@ async function checkCorrectOrganisation(orgUuid, opts, currentOrganisation) {
6969
7070 if ( organisationUuid ) {
7171 const authData = await api ( {
72- path : " /authenticate" ,
72+ path : ' /authenticate' ,
7373 } ) ;
7474 if ( authData . organisationUuid !== organisationUuid ) {
7575 log (
7676 `This configuration is for organisation ${ organisationUuid } but you are currently in organisation ${ authData . organisationUuid } ` ,
77- " white"
77+ ' white'
7878 ) ;
7979 const response = await inquirer . prompt ( [
8080 {
81- type : " confirm" ,
82- name : " confirm" ,
81+ type : ' confirm' ,
82+ name : ' confirm' ,
8383 message : `Would you like to switch your account to ${ organisationUuid } now?` ,
8484 } ,
8585 ] ) ;
8686 if ( response . confirm ) {
8787 const loader = ora (
88- " Switching to correct organisation ..."
88+ ' Switching to correct organisation ...'
8989 ) . start ( ) ;
9090 try {
9191 await api ( {
9292 path : `/users/${ authData . userUuid } /move` ,
93- method : " PUT" ,
93+ method : ' PUT' ,
9494 json : {
9595 data : {
9696 organisationUuid,
@@ -109,8 +109,8 @@ async function checkCorrectOrganisation(orgUuid, opts, currentOrganisation) {
109109
110110export async function login ( body , opts = { } ) {
111111 return await api ( {
112- path : " /login" ,
113- method : " POST" ,
112+ path : ' /login' ,
113+ method : ' POST' ,
114114 json : body ,
115115 } ) ;
116116}
@@ -126,8 +126,7 @@ export async function getToken(program, opts, warnEarly) {
126126 }
127127 if ( isTokenExpired ( warnEarly ) ) {
128128 ( { token } = await doLogin (
129- program ,
130- "Your token has expired, please login again"
129+ 'Your token has expired, please login again'
131130 ) ) ;
132131 setTokenExpiresAt ( ) ;
133132 await updateConfig ( { token } ) ;
0 commit comments