diff --git a/CHANGELOG.md b/CHANGELOG.md index e0dce3b..8796734 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org). +## [0.2.1] - 2024-01-20 +### Added +* Export different types for short URL visits params and other visits params. + +### Changed +* Export API contract as TypeScript types instead of interfaces. + +### Deprecated +* *Nothing* + +### Removed +* *Nothing* + +### Fixed +* *Nothing* + + ## [0.2.0] - 2023-10-27 ### Added * [#2](https://github.com/shlinkio/shlink-js-sdk/issues/2) Implement node.js `HttpClient`. @@ -18,6 +35,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Removed * *Nothing* +### Fixed +* *Nothing* + ### Fixed * *Nothing* diff --git a/docker-compose.yml b/docker-compose.yml index 190ad72..5b103c2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,7 @@ version: '3' services: shlink_js_sdk: container_name: shlink_js_sdk - image: node:20.5-alpine + image: node:20.11-alpine volumes: - ./:/shlink-js-sdk ports: diff --git a/src/api-contract/types.ts b/src/api-contract/types.ts index 5bc56ec..04b15e9 100644 --- a/src/api-contract/types.ts +++ b/src/api-contract/types.ts @@ -4,19 +4,19 @@ type Nullable = { [P in keyof T]: T[P] | null }; -export interface ShlinkDeviceLongUrls { +export type ShlinkDeviceLongUrls = { android?: OptionalString; ios?: OptionalString; desktop?: OptionalString; -} +}; -export interface ShlinkShortUrlMeta { +export type ShlinkShortUrlMeta = { validSince?: string; validUntil?: string; maxVisits?: number; -} +}; -export interface ShlinkShortUrl { +export type ShlinkShortUrl = { shortCode: string; shortUrl: string; longUrl: string; @@ -33,9 +33,9 @@ export interface ShlinkShortUrl { title?: string | null; crawlable?: boolean; forwardQuery?: boolean; -} +}; -export interface ShlinkEditShortUrlData { +export type ShlinkEditShortUrlData = { longUrl?: string; title?: string | null; tags?: string[]; @@ -48,9 +48,9 @@ export interface ShlinkEditShortUrlData { /** @deprecated To be removed in Shlink 4.0.0 */ validateUrl?: boolean; -} +}; -export interface ShlinkCreateShortUrlData extends Omit { +export type ShlinkCreateShortUrlData = Omit & { longUrl: string; customSlug?: string; shortCodeLength?: number; @@ -61,24 +61,24 @@ export interface ShlinkCreateShortUrlData extends Omit { +export type ShlinkEditDomainRedirects = Partial & { domain: string; -} +}; -export interface ShlinkDomain { +export type ShlinkDomain = { domain: string; isDefault: boolean; redirects: ShlinkDomainRedirects; -} +}; -export interface ShlinkDomainsResponse { +export type ShlinkDomainsResponse = { data: ShlinkDomain[]; defaultRedirects: ShlinkDomainRedirects; -} +}; export type TagsFilteringMode = 'all' | 'any'; @@ -201,7 +204,7 @@ export type ShlinkShortUrlsOrder = { dir?: 'ASC' | 'DESC'; }; -export interface ShlinkShortUrlsListParams { +export type ShlinkShortUrlsListParams = { page?: string; itemsPerPage?: number; searchTerm?: string; @@ -212,11 +215,11 @@ export interface ShlinkShortUrlsListParams { endDate?: string; excludeMaxVisitsReached?: boolean; excludePastValidUntil?: boolean; -} - -export interface ShlinkShortUrlsListNormalizedParams extends - Omit { - orderBy?: string; - excludeMaxVisitsReached?: 'true'; - excludePastValidUntil?: 'true'; -} +}; + +export type ShlinkShortUrlsListNormalizedParams = + Omit & { + orderBy?: string; + excludeMaxVisitsReached?: 'true'; + excludePastValidUntil?: 'true'; + }; diff --git a/src/api/ShlinkApiClient.ts b/src/api/ShlinkApiClient.ts index 90030ff..5b7fa64 100644 --- a/src/api/ShlinkApiClient.ts +++ b/src/api/ShlinkApiClient.ts @@ -10,7 +10,7 @@ import type { ShlinkMercureInfo, ShlinkShortUrl, ShlinkShortUrlsListParams, - ShlinkShortUrlsResponse, + ShlinkShortUrlsResponse, ShlinkShortUrlVisitsParams, ShlinkTags, ShlinkTagsResponse, ShlinkTagsStatsResponse, @@ -69,7 +69,7 @@ export class ShlinkApiClient implements BaseShlinkApiClient { return this.performRequest({ url: '/short-urls', method: 'POST', body }); } - public async getShortUrlVisits(shortCode: string, query?: ShlinkVisitsParams): Promise { + public async getShortUrlVisits(shortCode: string, query?: ShlinkShortUrlVisitsParams): Promise { return this.performRequest<{ visits: ShlinkVisits }>({ url: `/short-urls/${shortCode}/visits`, query }) .then(({ visits }) => visits); } @@ -81,17 +81,17 @@ export class ShlinkApiClient implements BaseShlinkApiClient { ); } - public async getTagVisits(tag: string, query?: Omit): Promise { + public async getTagVisits(tag: string, query?: ShlinkVisitsParams): Promise { return this.performRequest<{ visits: ShlinkVisits }>({ url: `/tags/${tag}/visits`, query }) .then(({ visits }) => visits); } - public async getDomainVisits(domain: string, query?: Omit): Promise { + public async getDomainVisits(domain: string, query?: ShlinkVisitsParams): Promise { return this.performRequest<{ visits: ShlinkVisits }>({ url: `/domains/${domain}/visits`, query }) .then(({ visits }) => visits); } - public async getOrphanVisits(query?: Omit): Promise { + public async getOrphanVisits(query?: ShlinkVisitsParams): Promise { return this.performRequest<{ visits: ShlinkVisits }>({ url: '/visits/orphan', query }).then(({ visits }) => visits); } @@ -99,7 +99,7 @@ export class ShlinkApiClient implements BaseShlinkApiClient { return this.performRequest({ method: 'DELETE', url: '/visits/orphan' }); } - public async getNonOrphanVisits(query?: Omit): Promise { + public async getNonOrphanVisits(query?: ShlinkVisitsParams): Promise { return this.performRequest<{ visits: ShlinkVisits }>({ url: '/visits/non-orphan', query }) .then(({ visits }) => visits); }