Skip to content

Commit 18da9ed

Browse files
hifaizskclaude
andauthored
feat: [CHA-2563] add retention policy endpoints (#1713)
## Ticket - https://linear.app/stream/issue/CHA-2563/retention-policy-for-existing-customers ## Summary Adds server-side SDK methods for the retention policy CRUD endpoints: - **`setRetentionPolicy(policy, maxAgeHours)`** — creates or updates a retention policy (`old-messages` or `inactive-channels`) with a max age between 24–43800 hours - **`deleteRetentionPolicy(policy)`** — removes a retention policy - **`getRetentionPolicy()`** — lists all retention policies configured for the app - **`getRetentionPolicyRuns(options?)`** — queries retention cleanup run history with support for `filter_conditions`, `sort`, and cursor-based pagination All endpoints are server-side only and require initializing the client with a secret. New types added: `RetentionPolicy`, `RetentionPolicyConfig`, `RetentionRunStats`, `RetentionRunResponse`, and request/response types for each endpoint. ## Checklist - [x] Types added to `src/types.ts` - [x] Methods added to `src/client.ts` - [x] TypeScript compilation passes - [x] Prettier formatting passes - [ ] The changed code has been covered with unit tests - [ ] API endpoints are covered with client tests 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 99349e7 commit 18da9ed

File tree

3 files changed

+376
-0
lines changed

3 files changed

+376
-0
lines changed

src/client.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ import type {
8383
DeleteChannelsResponse,
8484
DeleteCommandResponse,
8585
DeleteMessageOptions,
86+
DeleteRetentionPolicyResponse,
8687
DeleteUserOptions,
8788
Device,
8889
DeviceIdentifier,
@@ -118,6 +119,9 @@ import type {
118119
GetPollAPIResponse,
119120
GetPollOptionAPIResponse,
120121
GetRateLimitsResponse,
122+
GetRetentionPolicyResponse,
123+
GetRetentionPolicyRunsOptions,
124+
GetRetentionPolicyRunsResponse,
121125
GetThreadAPIResponse,
122126
GetThreadOptions,
123127
GetUnreadCountAPIResponse,
@@ -205,6 +209,7 @@ import type {
205209
SegmentTargetsResponse,
206210
SegmentType,
207211
SendFileAPIResponse,
212+
SetRetentionPolicyResponse,
208213
SharedLocationResponse,
209214
SortParam,
210215
StreamChatOptions,
@@ -4986,4 +4991,62 @@ export class StreamChat {
49864991
},
49874992
);
49884993
}
4994+
4995+
/**
4996+
* setRetentionPolicy - Creates or updates a retention policy for the app.
4997+
* Server-side only.
4998+
*
4999+
* @param {string} policy The policy type ('old-messages' or 'inactive-channels')
5000+
* @param {number} maxAgeHours Max age in hours (24-43800)
5001+
* @returns {Promise<SetRetentionPolicyResponse>}
5002+
*/
5003+
async setRetentionPolicy(policy: string, maxAgeHours: number) {
5004+
this.validateServerSideAuth();
5005+
return await this.post<SetRetentionPolicyResponse>(
5006+
this.baseURL + '/retention_policy',
5007+
{ policy, max_age_hours: maxAgeHours },
5008+
);
5009+
}
5010+
5011+
/**
5012+
* deleteRetentionPolicy - Deletes a retention policy for the app.
5013+
* Server-side only.
5014+
*
5015+
* @param {string} policy The policy type ('old-messages' or 'inactive-channels')
5016+
* @returns {Promise<DeleteRetentionPolicyResponse>}
5017+
*/
5018+
async deleteRetentionPolicy(policy: string) {
5019+
this.validateServerSideAuth();
5020+
return await this.post<DeleteRetentionPolicyResponse>(
5021+
this.baseURL + '/retention_policy/delete',
5022+
{ policy },
5023+
);
5024+
}
5025+
5026+
/**
5027+
* getRetentionPolicy - Returns all retention policies configured for the app.
5028+
* Server-side only.
5029+
*
5030+
* @returns {Promise<GetRetentionPolicyResponse>}
5031+
*/
5032+
async getRetentionPolicy() {
5033+
this.validateServerSideAuth();
5034+
return await this.get<GetRetentionPolicyResponse>(this.baseURL + '/retention_policy');
5035+
}
5036+
5037+
/**
5038+
* getRetentionPolicyRuns - Returns filtered and sorted retention cleanup run history.
5039+
* Supports filter_conditions on 'policy' and 'date' fields.
5040+
* Server-side only.
5041+
*
5042+
* @param {GetRetentionPolicyRunsOptions} options Filter, sort, and pagination options
5043+
* @returns {Promise<GetRetentionPolicyRunsResponse>}
5044+
*/
5045+
async getRetentionPolicyRuns(options: GetRetentionPolicyRunsOptions = {}) {
5046+
this.validateServerSideAuth();
5047+
return await this.post<GetRetentionPolicyRunsResponse>(
5048+
this.baseURL + '/retention_policy/runs',
5049+
options,
5050+
);
5051+
}
49895052
}

src/types.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4891,3 +4891,50 @@ export type QueryTeamUsageStatsResponse = APIResponse & {
48914891
/** Cursor for pagination to fetch next page */
48924892
next?: string;
48934893
};
4894+
4895+
export type RetentionPolicyConfig = {
4896+
max_age_hours: number;
4897+
};
4898+
4899+
export type RetentionPolicy = {
4900+
app_pk: number;
4901+
policy: string;
4902+
config: RetentionPolicyConfig;
4903+
enabled_at: string;
4904+
};
4905+
4906+
export type SetRetentionPolicyResponse = APIResponse & {
4907+
policy: RetentionPolicy;
4908+
};
4909+
4910+
export type DeleteRetentionPolicyResponse = APIResponse;
4911+
4912+
export type GetRetentionPolicyResponse = APIResponse & {
4913+
policies: RetentionPolicy[];
4914+
};
4915+
4916+
export type RetentionRunStats = {
4917+
channels_deleted?: number;
4918+
messages_deleted?: number;
4919+
};
4920+
4921+
export type RetentionRunResponse = {
4922+
app_pk: number;
4923+
policy: string;
4924+
date: string;
4925+
stats: RetentionRunStats;
4926+
};
4927+
4928+
export type GetRetentionPolicyRunsOptions = {
4929+
filter_conditions?: Record<string, unknown>;
4930+
sort?: Array<{ field: string; direction: 1 | -1 }>;
4931+
next?: string;
4932+
prev?: string;
4933+
limit?: number;
4934+
};
4935+
4936+
export type GetRetentionPolicyRunsResponse = APIResponse & {
4937+
runs: RetentionRunResponse[];
4938+
next?: string;
4939+
prev?: string;
4940+
};

0 commit comments

Comments
 (0)