-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathfeed-service.ts
More file actions
222 lines (199 loc) · 5.85 KB
/
Copy pathfeed-service.ts
File metadata and controls
222 lines (199 loc) · 5.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
/**
* IFeedService - Feed/Chatter Service Contract
*
* Defines the interface for Feed/Chatter operations in ObjectStack.
* Covers feed CRUD, emoji reactions, and record subscriptions.
* Concrete implementations (in-memory, database-backed, etc.)
* should implement this interface.
*
* Follows Dependency Inversion Principle - plugins depend on this interface,
* not on concrete feed service implementations.
*
* Aligned with CoreServiceName 'feed' in core-services.zod.ts.
*/
import type { FeedItem, Reaction } from '../data/feed.zod';
import type { RecordSubscription } from '../data/subscription.zod';
// ==========================================
// Feed Item Types
// ==========================================
/**
* Input for creating a new feed item.
*/
export interface CreateFeedItemInput {
/** Object name (e.g., "account") */
object: string;
/** Record ID */
recordId: string;
/** Feed item type */
type: string;
/** Actor information */
actor: {
type: 'user' | 'system' | 'service' | 'automation';
id: string;
name?: string;
avatarUrl?: string;
};
/** Rich text body (Markdown) */
body?: string;
/** @mentions */
mentions?: Array<{
type: 'user' | 'team' | 'record';
id: string;
name: string;
offset: number;
length: number;
}>;
/** Field changes (for field_change type) */
changes?: Array<{
field: string;
fieldLabel?: string;
oldValue?: unknown;
newValue?: unknown;
oldDisplayValue?: string;
newDisplayValue?: string;
}>;
/** Parent feed item ID for threaded replies */
parentId?: string;
/** Visibility level */
visibility?: 'public' | 'internal' | 'private';
}
/**
* Input for updating an existing feed item.
*/
export interface UpdateFeedItemInput {
/** Updated body text */
body?: string;
/** Updated mentions */
mentions?: Array<{
type: 'user' | 'team' | 'record';
id: string;
name: string;
offset: number;
length: number;
}>;
/** Updated visibility */
visibility?: 'public' | 'internal' | 'private';
}
/**
* Options for listing feed items.
*/
export interface ListFeedOptions {
/** Object name */
object: string;
/** Record ID */
recordId: string;
/** Filter mode */
filter?: 'all' | 'comments_only' | 'changes_only' | 'tasks_only';
/** Maximum items to return */
limit?: number;
/** Cursor for pagination */
cursor?: string;
}
/**
* Paginated feed list result.
*/
export interface FeedListResult {
/** Feed items in reverse chronological order */
items: FeedItem[];
/** Total feed items matching filter */
total?: number;
/** Cursor for next page */
nextCursor?: string;
/** Whether more items are available */
hasMore: boolean;
}
// ==========================================
// Subscription Types
// ==========================================
/**
* Input for subscribing to record notifications.
*/
export interface SubscribeInput {
/** Object name */
object: string;
/** Record ID */
recordId: string;
/** Subscribing user ID */
userId: string;
/** Event types to subscribe to */
events?: Array<'comment' | 'mention' | 'field_change' | 'task' | 'approval' | 'all'>;
/** Notification channels */
channels?: Array<'in_app' | 'email' | 'push' | 'slack'>;
}
// ==========================================
// Service Interface
// ==========================================
export interface IFeedService {
// ---- Feed CRUD ----
/**
* List feed items for a record.
* @param options - Filter and pagination options
* @returns Paginated list of feed items
*/
listFeed(options: ListFeedOptions): Promise<FeedListResult>;
/**
* Create a new feed item.
* @param input - Feed item data
* @returns The created feed item
*/
createFeedItem(input: CreateFeedItemInput): Promise<FeedItem>;
/**
* Update an existing feed item (e.g., edit a comment).
* @param feedId - Feed item ID
* @param input - Updated fields
* @returns The updated feed item
*/
updateFeedItem(feedId: string, input: UpdateFeedItemInput): Promise<FeedItem>;
/**
* Delete a feed item.
* @param feedId - Feed item ID
*/
deleteFeedItem(feedId: string): Promise<void>;
/**
* Get a single feed item by ID.
* @param feedId - Feed item ID
* @returns The feed item, or null if not found
*/
getFeedItem(feedId: string): Promise<FeedItem | null>;
// ---- Reactions ----
/**
* Add an emoji reaction to a feed item.
* @param feedId - Feed item ID
* @param emoji - Emoji character or shortcode
* @param userId - User adding the reaction
* @returns Updated reactions list
*/
addReaction(feedId: string, emoji: string, userId: string): Promise<Reaction[]>;
/**
* Remove an emoji reaction from a feed item.
* @param feedId - Feed item ID
* @param emoji - Emoji character or shortcode
* @param userId - User removing the reaction
* @returns Updated reactions list
*/
removeReaction(feedId: string, emoji: string, userId: string): Promise<Reaction[]>;
// ---- Subscriptions ----
/**
* Subscribe to record-level notifications.
* @param input - Subscription details
* @returns The created or updated subscription
*/
subscribe(input: SubscribeInput): Promise<RecordSubscription>;
/**
* Unsubscribe from record notifications.
* @param object - Object name
* @param recordId - Record ID
* @param userId - User ID
* @returns Whether the user was unsubscribed
*/
unsubscribe(object: string, recordId: string, userId: string): Promise<boolean>;
/**
* Get a user's subscription for a record.
* @param object - Object name
* @param recordId - Record ID
* @param userId - User ID
* @returns The subscription, or null if not subscribed
*/
getSubscription(object: string, recordId: string, userId: string): Promise<RecordSubscription | null>;
}