diff --git a/CHANGELOG.md b/CHANGELOG.md index fc5f483..05d221c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Added * [#72](https://github.com/shlinkio/shlink-js-sdk/issues/72) Add support for Shlink 4.0.0 + * Add support to list and set short URL redirect conditions. * Add `type` param to `ShlinkApiClient.getOrphanVisits`. ### Changed diff --git a/src/api-contract/ShlinkApiClient.ts b/src/api-contract/ShlinkApiClient.ts index bf5d13a..70fe5c5 100644 --- a/src/api-contract/ShlinkApiClient.ts +++ b/src/api-contract/ShlinkApiClient.ts @@ -8,6 +8,8 @@ import type { ShlinkHealth, ShlinkMercureInfo, ShlinkOrphanVisitsParams, + ShlinkRedirectRulesList, + ShlinkSetRedirectRulesData, ShlinkShortUrl, ShlinkShortUrlsList, ShlinkShortUrlsListParams, @@ -36,6 +38,16 @@ export type ShlinkApiClient = { data: ShlinkEditShortUrlData, ): Promise; + // Short URL redirect rules + + getShortUrlRedirectRules(shortCode: string, domain?: string | null): Promise; + + setShortUrlRedirectRules( + shortCode: string, + domain: string | null | undefined, + data: ShlinkSetRedirectRulesData, + ): Promise; + // Visits getVisitsOverview(): Promise; diff --git a/src/api-contract/types.ts b/src/api-contract/types.ts index 49a1c49..00b813c 100644 --- a/src/api-contract/types.ts +++ b/src/api-contract/types.ts @@ -224,3 +224,29 @@ export type ShlinkShortUrlsListParams = { excludeMaxVisitsReached?: boolean; excludePastValidUntil?: boolean; }; + +export type ShlinkRedirectConditionType = 'device' | 'language' | 'query-param'; + +export type ShlinkRedirectCondition = { + type: ShlinkRedirectConditionType; + matchKey: string | null; + matchValue: string; +}; + +export type ShlinkRedirectRuleData = { + longUrl: string; + conditions: ShlinkRedirectCondition[]; +}; + +export type ShlinkRedirectRule = ShlinkRedirectRuleData & { + priority: number; +}; + +export type ShlinkRedirectRulesList = { + defaultLongUrl: string; + redirectRules: ShlinkRedirectRule[]; +}; + +export type ShlinkSetRedirectRulesData = { + redirectRules: ShlinkRedirectRuleData[]; +}; diff --git a/src/api/ShlinkApiClient.ts b/src/api/ShlinkApiClient.ts index 5f77646..f74ab3c 100644 --- a/src/api/ShlinkApiClient.ts +++ b/src/api/ShlinkApiClient.ts @@ -9,6 +9,8 @@ import type { ShlinkHealth, ShlinkMercureInfo, ShlinkOrphanVisitsParams, + ShlinkRedirectRulesList, + ShlinkSetRedirectRulesData, ShlinkShortUrl, ShlinkShortUrlsList, ShlinkShortUrlsListParams, @@ -88,6 +90,24 @@ export class ShlinkApiClient implements BaseShlinkApiClient { ); } + // Short URL redirect rules + + public async getShortUrlRedirectRules(shortCode: string, domain?: string | null): Promise { + return this.performRequest( + { url: `/short-urls/${shortCode}/redirect-rules`, method: 'GET', query: { domain } }, + ); + } + + public async setShortUrlRedirectRules( + shortCode: string, + domain: string | null | undefined, + data: ShlinkSetRedirectRulesData, + ): Promise { + return this.performRequest( + { url: `/short-urls/${shortCode}/redirect-rules`, method: 'POST', query: { domain }, body: data }, + ); + } + // Visits public async getVisitsOverview(): Promise {