Skip to content

Commit 86d9695

Browse files
committed
Assertions implemented everywhere
1 parent 42557fa commit 86d9695

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/index.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { APIManager, SquareCloudAPIError } from './APIManager';
22
import { Application } from './structures/Application';
33
import { FullUser, User } from './structures/User';
4+
import { validateString } from './Assertions';
45

56
export class SquareCloudAPI {
67
static apiInfo = {
@@ -16,9 +17,7 @@ export class SquareCloudAPI {
1617
* @param apiKey - Your API Token (you can get it at [SquareCloud Dashboard](https://squarecloud.app/dashboard))
1718
*/
1819
constructor(apiKey: string) {
19-
if (typeof apiKey !== 'string') {
20-
throw new TypeError('apiKey must be a string. Got ' + typeof apiKey);
21-
}
20+
validateString(apiKey);
2221

2322
this.apiManager = new APIManager(apiKey);
2423
}
@@ -29,11 +28,9 @@ export class SquareCloudAPI {
2928
* @param userId - The user id, if not provided it will get your own information
3029
*/
3130
async getUser(userId?: string): Promise<User> {
32-
if (userId && typeof userId !== 'string') {
33-
throw new TypeError('userId must be a string. Got ' + typeof userId);
34-
}
31+
validateString(userId);
3532

36-
const userData = (await this.apiManager.user(userId));
33+
const userData = await this.apiManager.user(userId);
3734
const hasAccess = userData.user.email !== 'Access denied';
3835

3936
return new (hasAccess ? FullUser : User)(this.apiManager, userData);
@@ -45,11 +42,9 @@ export class SquareCloudAPI {
4542
* @param appId - The application id, you must own the application
4643
*/
4744
async getApplication(appId: string): Promise<Application> {
48-
if (typeof appId !== 'string') {
49-
throw new TypeError('appId must be a string. Got ' + typeof appId);
50-
}
45+
validateString(appId);
5146

52-
const { applications } = (await this.apiManager.user());
47+
const { applications } = await this.apiManager.user();
5348
const appData = applications.find((app) => app.id === appId);
5449

5550
if (!appData) {

0 commit comments

Comments
 (0)