Skip to content

Commit

Permalink
feat: remove backwards compatibility with older Kanka API versions
Browse files Browse the repository at this point in the history
BREAKING CHANGE: If you have a self hosted version of kanka make sure to update to the latest version.
  • Loading branch information
Steven Weingärtner committed Nov 11, 2023
1 parent e636af3 commit 2a0a415
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/api/KankaApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
KankaApiAbility,
KankaApiCampaign,
KankaApiCharacter,
KankaApiChildEntity,
KankaApiCreature,
KankaApiEntity,
KankaApiEntityId,
Expand All @@ -26,15 +25,6 @@ import RateLimiter from './RateLimiter';
export default class KankaApi {
#fetcher: KankaFetcher;

// eslint-disable-next-line @typescript-eslint/naming-convention
private ensureBackwardsCompatibility<T>(entity: T): T {
// Kanka 1.x
return {
...entity,
posts: (entity as KankaApiChildEntity).posts ?? (entity as KankaApiChildEntity).posts,
};
}

public constructor(baseUrl = 'https://api.kanka.io/1.0') {
this.#fetcher = new KankaFetcher(baseUrl);
}
Expand Down Expand Up @@ -79,7 +69,7 @@ export default class KankaApi {
public async getCharacter(campaignId: KankaApiId, id: KankaApiId): Promise<KankaApiCharacter> {
type Result = KankaApiResult<KankaApiCharacter>;
const result = await this.#fetcher.fetch<Result>(`campaigns/${String(campaignId)}/characters/${String(id)}?related=1`);
return this.ensureBackwardsCompatibility(result.data);
return result.data;
}

public async getAllCharacters(campaignId: KankaApiId): Promise<KankaApiCharacter[]> {
Expand Down Expand Up @@ -328,7 +318,7 @@ export default class KankaApi {
const fullUrl: string = url.includes('?') ? `${url}&${query}` : `${url}?${query}`;
// eslint-disable-next-line no-await-in-loop
const result = await this.#fetcher.fetch<KankaApiListResult<T>>(fullUrl);
data.push(...result.data.map(entity => this.ensureBackwardsCompatibility(entity)));
data.push(...result.data);
url = result.links.next;
}

Expand Down

0 comments on commit 2a0a415

Please sign in to comment.