Skip to content

Commit e3d6814

Browse files
committed
Linting fixes
1 parent 45c4d7a commit e3d6814

File tree

2 files changed

+60
-59
lines changed

2 files changed

+60
-59
lines changed

src/Oauth.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,7 @@ export async function pollOauthSession(config: AuthenticationConfig, sessionId:
128128
}
129129
}
130130

131-
export async function getAccessToken(
132-
config: AuthenticationConfig,
133-
code: string,
134-
codeVerifier: string,
135-
): Promise<Token> {
131+
export async function getAccessToken(config: AuthenticationConfig, code: string, codeVerifier: string): Promise<Token> {
136132
if (!config.domain) {
137133
throw new Error('No domain provided!');
138134
}

src/index.ts

Lines changed: 59 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,26 @@ import {
77
pollOauthSession,
88
getAccessToken,
99
getRefreshToken,
10-
revokeToken
10+
revokeToken,
1111
} from './Oauth';
1212

1313
const DOMAIN_WINDOW_DEFAULT_URL = 'https://dev.frontify.test/finder';
1414
const POPUP_DEFAULT_TITLE = 'Authorize Frontify';
1515
const POPUP_STATE = {
16-
open: false
17-
}
16+
open: false,
17+
};
1818

1919
let popup: Popup;
2020

2121
export async function authorize(
2222
configuration: AuthenticationConfig,
23-
popupConfiguration?: PopupConfiguration
24-
): Promise<Token | void>{
25-
23+
popupConfiguration?: PopupConfiguration,
24+
): Promise<Token | void> {
2625
if (POPUP_STATE.open) {
2726
logMessage('warning', {
2827
code: 'ERR_POPUP_OPEN',
29-
message: 'Popup already open!'
30-
})
28+
message: 'Popup already open!',
29+
});
3130
throw new Error('Popup already open!');
3231
}
3332

@@ -44,29 +43,33 @@ export async function authorize(
4443
POPUP_STATE.open = true;
4544

4645
if (!configuration.domain) {
47-
return openDomainPopUp(configuration, popup).then((res) => {
48-
POPUP_STATE.open = false;
49-
if (res) {
50-
return res;
51-
}
52-
}).catch(() => {
53-
delete(configuration.domain);
54-
logMessage('error', {
55-
code: 'ERR_AUTH_SKIPPED',
56-
message: 'Domain not inserted!'
46+
return openDomainPopUp(configuration, popup)
47+
.then((res) => {
48+
POPUP_STATE.open = false;
49+
if (res) {
50+
return res;
51+
}
52+
})
53+
.catch(() => {
54+
delete configuration.domain;
55+
logMessage('error', {
56+
code: 'ERR_AUTH_SKIPPED',
57+
message: 'Domain not inserted!',
58+
});
59+
throw new Error('Domain not inserted!');
5760
});
58-
throw new Error('Domain not inserted!');
59-
});
6061
} else {
61-
return authenticate(configuration, popup).then((res) => {
62-
POPUP_STATE.open = false;
63-
if (res) {
64-
return res;
65-
}
66-
}).catch((error) => {
67-
POPUP_STATE.open = false;
68-
throw new Error(error);
69-
});
62+
return authenticate(configuration, popup)
63+
.then((res) => {
64+
POPUP_STATE.open = false;
65+
if (res) {
66+
return res;
67+
}
68+
})
69+
.catch((error) => {
70+
POPUP_STATE.open = false;
71+
throw new Error(error);
72+
});
7073
}
7174
}
7275

@@ -75,7 +78,7 @@ export async function refresh(token: Token): Promise<Token> {
7578
}
7679

7780
export async function revoke(token: Token): Promise<Token> {
78-
await revokeToken(token.bearerToken.domain, token.bearerToken.accessToken)
81+
await revokeToken(token.bearerToken.domain, token.bearerToken.accessToken);
7982
return token;
8083
}
8184

@@ -87,10 +90,10 @@ async function authenticate(configuration: AuthenticationConfig, popUp: Popup):
8790
return getAccessToken(configuration, authorizationCode, codeVerifier);
8891
} catch (error) {
8992
const errorMessage = `Error generating session. Make sure that the inserted domain is a valid and secure Frontify instance.`;
90-
popUp.popUp?.postMessage({domainError: errorMessage}, '*');
93+
popUp.popUp?.postMessage({ domainError: errorMessage }, '*');
9194
logMessage('error', {
9295
code: 'ERR_AUTH_FAILED',
93-
message: errorMessage
96+
message: errorMessage,
9497
});
9598
throw new Error(errorMessage);
9699
}
@@ -101,7 +104,7 @@ function openDomainPopUp(configuration: AuthenticationConfig, popUp: Popup): Pro
101104

102105
logMessage('warning', {
103106
code: 'WARN_DOMAIN_OPEN',
104-
message: 'Popup window opened!'
107+
message: 'Popup window opened!',
105108
});
106109

107110
return new Promise((resolve, reject) => {
@@ -111,22 +114,24 @@ function openDomainPopUp(configuration: AuthenticationConfig, popUp: Popup): Pro
111114
reject();
112115
logMessage('error', {
113116
code: 'ERR_DOMAIN_TIMEOUT',
114-
message: 'Popup window timeout!'
115-
})
117+
message: 'Popup window timeout!',
118+
});
116119
}, 5 * 60 * 1000);
117120

118121
popUp.onDomain(() => {
119122
clearTimeout(timeout);
120123
configuration.domain = popup.getDomain();
121-
authenticate(configuration, popup).then((result) => {
122-
resolve(result);
123-
}).catch((error) => {
124-
throw new Error(error ?? 'Could not verify instance!');
125-
});
124+
authenticate(configuration, popup)
125+
.then((result) => {
126+
resolve(result);
127+
})
128+
.catch((error) => {
129+
throw new Error(error ?? 'Could not verify instance!');
130+
});
126131
logMessage('warning', {
127132
code: 'WARN_DOMAIN_SELECT',
128-
message: 'Domain input submitted!'
129-
})
133+
message: 'Domain input submitted!',
134+
});
130135
});
131136

132137
popUp.onAborted(() => {
@@ -136,8 +141,8 @@ function openDomainPopUp(configuration: AuthenticationConfig, popUp: Popup): Pro
136141
reject();
137142
logMessage('warning', {
138143
code: 'WARN_DOMAIN_CLOSED',
139-
message: 'Popup window closed!'
140-
})
144+
message: 'Popup window closed!',
145+
});
141146
});
142147
});
143148
}
@@ -147,7 +152,7 @@ function openAuthPopUp(url: string, popUp: Popup): Promise<void> {
147152

148153
logMessage('warning', {
149154
code: 'WARN_DOMAIN_OPEN',
150-
message: 'Popup window opened!'
155+
message: 'Popup window opened!',
151156
});
152157

153158
return new Promise((resolve, reject) => {
@@ -157,8 +162,8 @@ function openAuthPopUp(url: string, popUp: Popup): Promise<void> {
157162
reject();
158163
logMessage('error', {
159164
code: 'ERR_DOMAIN_TIMEOUT',
160-
message: 'Popup window timeout!'
161-
})
165+
message: 'Popup window timeout!',
166+
});
162167
}, 5 * 60 * 1000);
163168

164169
popUp.onAborted(() => {
@@ -168,8 +173,8 @@ function openAuthPopUp(url: string, popUp: Popup): Promise<void> {
168173
reject();
169174
logMessage('warning', {
170175
code: 'WARN_DOMAIN_CLOSED',
171-
message: 'Popup window closed!'
172-
})
176+
message: 'Popup window closed!',
177+
});
173178
});
174179

175180
popUp.onSuccess(() => {
@@ -179,8 +184,8 @@ function openAuthPopUp(url: string, popUp: Popup): Promise<void> {
179184
resolve();
180185
logMessage('warning', {
181186
code: 'WARN_AUTH_SUCCESS',
182-
message: 'Auth success!'
183-
})
187+
message: 'Auth success!',
188+
});
184189
});
185190

186191
popUp.onCancelled(() => {
@@ -190,12 +195,12 @@ function openAuthPopUp(url: string, popUp: Popup): Promise<void> {
190195
reject();
191196
logMessage('warning', {
192197
code: 'WARN_AUTH_CANCELLED',
193-
message: 'Auth cancelled!'
194-
})
198+
message: 'Auth cancelled!',
199+
});
195200
});
196201
});
197202
}
198203

199204
function createPopUp(configuration: PopupConfiguration): Popup {
200205
return new Popup(configuration ?? {});
201-
}
206+
}

0 commit comments

Comments
 (0)