Skip to content

Commit

Permalink
fix: check api key before returning easybill client instance
Browse files Browse the repository at this point in the history
  • Loading branch information
kkhanhluu committed Oct 5, 2021
1 parent be499e5 commit 0dc63dc
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import { DocumentAPI } from './document/api';
export class EasybillClient {
private static instance: EasybillClient;

private apiKey: string;

public readonly customerAPI: CustomerAPI;

public readonly documentAPI: DocumentAPI;

private constructor(apiKey: string) {
const baseURL = 'https://api.easybill.de/rest/v1';

this.apiKey = apiKey;
this.customerAPI = new CustomerAPI(baseURL, apiKey);
this.documentAPI = new DocumentAPI(baseURL, apiKey);
}
Expand All @@ -19,6 +22,9 @@ export class EasybillClient {
if (!EasybillClient.instance) {
EasybillClient.instance = new EasybillClient(apiKey);
}
if (EasybillClient.instance.apiKey !== apiKey) {
throw new Error('Easybill client cannot have different api keys');
}
return EasybillClient.instance;
}
}
Expand Down

0 comments on commit 0dc63dc

Please sign in to comment.