Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow type param to be passed to getOrphanVisits() #76

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]
### Added
* *Nothing*
* [#72](https://github.com/shlinkio/shlink-js-sdk/issues/72) Add support for Shlink 4.0.0

* Add `type` param to `ShlinkApiClient.getOrphanVisits`.

### Changed
* Update dependencies.
Expand Down
3 changes: 2 additions & 1 deletion src/api-contract/ShlinkApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
ShlinkEditShortUrlData,
ShlinkHealth,
ShlinkMercureInfo,
ShlinkOrphanVisitsParams,
ShlinkShortUrl,
ShlinkShortUrlsList,
ShlinkShortUrlsListParams,
Expand Down Expand Up @@ -45,7 +46,7 @@ export type ShlinkApiClient = {

getDomainVisits(domain: string, params?: ShlinkVisitsParams): Promise<ShlinkVisitsList>;

getOrphanVisits(params?: ShlinkVisitsParams): Promise<ShlinkVisitsList>;
getOrphanVisits(params?: ShlinkOrphanVisitsParams): Promise<ShlinkVisitsList>;

getNonOrphanVisits(params?: ShlinkVisitsParams): Promise<ShlinkVisitsList>;

Expand Down
5 changes: 5 additions & 0 deletions src/api-contract/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ export type ShlinkShortUrlVisitsParams = ShlinkVisitsParams & {
domain?: string | null;
};

export type ShlinkOrphanVisitsParams = ShlinkVisitsParams & {
/** Ignored by Shlink older than v4.0.0 */
type?: ShlinkOrphanVisitType;
};

export type ShlinkDomainRedirects = {
baseUrlRedirect: string | null;
regular404Redirect: string | null;
Expand Down
23 changes: 11 additions & 12 deletions src/api/ShlinkApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
ShlinkEditShortUrlData,
ShlinkHealth,
ShlinkMercureInfo,
ShlinkOrphanVisitsParams,
ShlinkShortUrl,
ShlinkShortUrlsList,
ShlinkShortUrlsListParams,
Expand Down Expand Up @@ -94,29 +95,27 @@ export class ShlinkApiClient implements BaseShlinkApiClient {
}

public async getShortUrlVisits(shortCode: string, params?: ShlinkShortUrlVisitsParams): Promise<ShlinkVisitsList> {
return this.performRequest<{ visits: ShlinkVisitsList }>({ url: `/short-urls/${shortCode}/visits`, query: params })
.then(({ visits }) => visits);
return this.performVisitsRequest({ url: `/short-urls/${shortCode}/visits`, query: params });
}

public async getTagVisits(tag: string, params?: ShlinkVisitsParams): Promise<ShlinkVisitsList> {
return this.performRequest<{ visits: ShlinkVisitsList }>({ url: `/tags/${tag}/visits`, query: params })
.then(({ visits }) => visits);
return this.performVisitsRequest({ url: `/tags/${tag}/visits`, query: params });
}

public async getDomainVisits(domain: string, params?: ShlinkVisitsParams): Promise<ShlinkVisitsList> {
return this.performRequest<{ visits: ShlinkVisitsList }>({ url: `/domains/${domain}/visits`, query: params })
.then(({ visits }) => visits);
return this.performVisitsRequest({ url: `/domains/${domain}/visits`, query: params });
}

public async getOrphanVisits(params?: ShlinkVisitsParams): Promise<ShlinkVisitsList> {
return this.performRequest<{ visits: ShlinkVisitsList }>({ url: '/visits/orphan', query: params }).then(
({ visits }) => visits,
);
public async getOrphanVisits(params?: ShlinkOrphanVisitsParams): Promise<ShlinkVisitsList> {
return this.performVisitsRequest({ url: '/visits/orphan', query: params });
}

public async getNonOrphanVisits(params?: ShlinkVisitsParams): Promise<ShlinkVisitsList> {
return this.performRequest<{ visits: ShlinkVisitsList }>({ url: '/visits/non-orphan', query: params })
.then(({ visits }) => visits);
return this.performVisitsRequest({ url: '/visits/non-orphan', query: params });
}

private async performVisitsRequest(options: ShlinkRequestOptions): Promise<ShlinkVisitsList> {
return this.performRequest<{ visits: ShlinkVisitsList }>(options).then(({ visits }) => visits);
}

public async deleteShortUrlVisits(shortCode: string, domain?: string | null): Promise<ShlinkDeleteVisitsResult> {
Expand Down