返回 AiToEarn
platforms.interface.ts
根目录 / project / aitoearn-backend / apps / aitoearn-server / src / core / channels / platforms / platforms.interface.ts
1 import type { AccountType, Locale, WorkStatus } from '@yikart/common'
2 import type { PublishRecordLinkStatus } from '@yikart/mongodb'
3 import type { Request, Response } from 'express'
4 import type { z } from 'zod'
5 import type { PlatformErrorCategory } from './platforms.exception'
6 import type { PublishMediaAdaptationOption } from './publish-media-adaptation.schema'
7 import type { PublishValidationIssue } from './publish.schema'
8
9 export enum CompletionStrategy {
10 Sync = 'sync',
11 Polling = 'polling',
12 MediaFinalize = 'media_finalize',
13 Webhook = 'webhook',
14 UserHandoff = 'user_handoff',
15 }
16
17 export enum AuthType {
18 OAuth2 = 'oauth2',
19 Browser = 'browser',
20 Plugin = 'plugin',
21 QrCode = 'qrcode',
22 }
23
24 export enum AuthCallbackResponseType {
25 Page = 'page',
26 Json = 'json',
27 }
28
29 export enum EditorType {
30 None = 'none',
31 Text = 'text',
32 Html = 'html',
33 }
34
35 export enum PublishContentMode {
36 // TODO: 等前端重构
37 // Text = 'text',
38 // ImageText = 'image_text',
39 Text = 'article2',
40 ImageText = 'article',
41 Video = 'video',
42 }
43
44 // ── Auth ──
45
46 export interface GenerateAuthUrlInput {
47 userId?: string
48 state: string
49 deviceType?: 'mobile' | 'desktop' | 'tablet' | 'unknown'
50 extras?: Record<string, unknown>
51 }
52
53 export interface GenerateAuthUrlResult {
54 url: string
55 state: string
56 redirectUri: string
57 extras?: Record<string, unknown>
58 }
59
60 export interface AuthCallbackInput {
61 callbackUrl?: string
62 query?: AuthCallbackQuery
63 body?: AuthCallbackBody
64 session: AuthCallbackSession
65 }
66
67 export interface AuthCallbackQuery {
68 code?: string
69 state?: string
70 error?: string
71 error_description?: string
72 token?: string
73 nickname?: string
74 avatar?: string
75 }
76
77 export interface AuthCallbackBody extends AuthCallbackQuery {
78 tickets?: Record<string, string>
79 }
80
81 export interface AuthCallbackSession {
82 id: string
83 authExtras?: Record<string, unknown>
84 }
85
86 export interface CredentialResult {
87 accessToken?: string
88 refreshToken?: string
89 expiresAt?: Date
90 scope?: string
91 tokenType?: string
92 platformUid?: string
93 profile?: PlatformAccountProfile
94 selectableAccounts?: PlatformSelectableAccount[]
95 callbackResponseType?: AuthCallbackResponseType
96 raw?: unknown
97 }
98
99 export interface CredentialContext {
100 accessToken: string
101 refreshToken?: string
102 expiresAt?: Date
103 scope?: string
104 platformUid?: string
105 account?: string
106 }
107
108 export interface PlatformAccountProfile {
109 platformUid: string
110 account?: string
111 displayName: string
112 avatarUrl?: string
113 email?: string
114 fansCount?: number
115 followingCount?: number
116 raw?: unknown
117 }
118
119 export interface PlatformSelectableAccount {
120 platform: AccountType
121 platformUid: string
122 account?: string
123 displayName: string
124 avatarUrl?: string
125 parentPlatformUid?: string
126 fansCount?: number
127 followingCount?: number
128 credential?: PlatformAccountCredentialSnapshot
129 profile?: Record<string, unknown>
130 raw?: unknown
131 }
132
133 export interface PlatformAccountCredentialSnapshot {
134 accessToken: string
135 refreshToken?: string
136 expiresAt?: Date
137 scope?: string
138 }
139
140 export interface RefreshCredentialInput {
141 accessToken: string
142 refreshToken?: string
143 }
144
145 export interface RevokeCredentialInput {
146 accessToken: string
147 refreshToken?: string
148 platformUid?: string
149 }
150
151 export interface RefreshAccountAccessInput {
152 rootAccessToken: string
153 rootRefreshToken?: string
154 platformUid: string
155 }
156
157 export interface AuthProvider {
158 generateAuthUrl: (input: GenerateAuthUrlInput) => Promise<GenerateAuthUrlResult>
159 exchangeCode: (input: AuthCallbackInput) => Promise<CredentialResult>
160 refresh: (input: RefreshCredentialInput) => Promise<CredentialResult>
161 revoke?: (input: RevokeCredentialInput) => Promise<void>
162 getProfile: (input: CredentialContext) => Promise<PlatformAccountProfile>
163 listSelectableAccounts?: (input: CredentialContext) => Promise<PlatformSelectableAccount[]>
164 refreshAccountAccess?: (input: RefreshAccountAccessInput) => Promise<PlatformSelectableAccount>
165 }
166
167 // ── Publish ──
168
169 export interface TopicCapability {
170 supported: boolean
171 nativeField?: boolean
172 maxCount?: number
173 maxTotalLength?: number
174 }
175
176 export interface PlatformMediaRules {
177 imageFormats?: string[]
178 videoFormats?: string[]
179 maxImageSize?: number
180 maxVideoSize?: number
181 minVideoDuration?: number
182 maxVideoDuration?: number
183 minImageWidth?: number
184 minImageHeight?: number
185 maxImageWidth?: number
186 maxImageHeight?: number
187 aspectRatio?: { min?: number, max?: number }
188 }
189
190 export interface PublishMediaInput {
191 url: string
192 metadata?: PublishMediaMetadata
193 options?: PublishMediaOptions
194 }
195
196 export interface PublishCoverInput {
197 url: string
198 metadata?: PublishMediaMetadata
199 options?: PublishMediaOptions
200 }
201
202 export interface PublishContentInput {
203 title?: string
204 body?: string
205 media: PublishMediaInput[]
206 cover?: PublishCoverInput
207 }
208
209 export interface PublishValidateInput<TOption = Record<string, unknown>> {
210 platform: AccountType
211 accountId: string
212 content: PublishContentInput
213 option?: TOption
214 }
215
216 export interface PublishValidationResult {
217 valid: boolean
218 issues?: PublishValidationIssue[]
219 }
220
221 export interface PublishNormalizeInput<TOption = Record<string, unknown>> {
222 platform: AccountType
223 accountId: string
224 content: PublishContentInput
225 option?: TOption
226 }
227
228 export interface NormalizedPublishTask<TOption = Record<string, unknown>> {
229 content: PublishContentInput
230 option?: TOption
231 mediaJobs?: PublishMediaJob[]
232 }
233
234 export interface PublishMediaJob {
235 mediaId: string
236 type: PublishMediaType
237 url: string
238 metadata?: PublishMediaMetadata
239 }
240
241 export enum PublishMediaType {
242 Image = 'image',
243 Video = 'video',
244 }
245
246 export interface PublishMediaMetadata {
247 type?: PublishMediaType
248 durationSec?: number
249 width?: number
250 height?: number
251 codec?: string
252 format?: string
253 sizeBytes?: number
254 }
255
256 export interface PublishMediaOptions {
257 adaptation?: PublishMediaAdaptationOption
258 }
259
260 export interface PublishPublishInput<TOption = Record<string, unknown>> {
261 taskId: string
262 platform: AccountType
263 accountId: string
264 content: PublishContentInput
265 option?: TOption
266 publishAt?: Date
267 credential: CredentialContext
268 /** 重试恢复时本地已记录的平台侧作品 ID */
269 platformWorkId?: string
270 /** 平台受理发布后立即持久化平台侧作品 ID,供重试时对账而不是重新发布 */
271 checkpointPlatformWorkId?: (platformWorkId: string) => Promise<void>
272 }
273
274 export interface PublishProviderResult<TDataOption = Record<string, unknown>> {
275 status: number
276 platformWorkId?: string
277 permalink?: string
278 shortLink?: string
279 errorMessage?: string
280 originalWorkLink?: string
281 workStatus?: WorkStatus
282 linkStatus?: PublishRecordLinkStatus
283 linkMeta?: Record<string, unknown>
284 userAction?: PublishUserAction
285 mediaJobs?: PublishMediaJob[]
286 dataOption?: TDataOption
287 }
288
289 export interface PublishUserAction {
290 schema?: string
291 shortLink?: string
292 expiresAt: Date
293 data?: Record<string, unknown>
294 }
295
296 export interface PublishFinalizeInput<TDataOption = Record<string, unknown>, TOption = Record<string, unknown>> {
297 taskId: string
298 platform: AccountType
299 platformWorkId: string
300 mediaJobs: PublishMediaJob[]
301 option?: TOption
302 dataOption?: TDataOption
303 credential: CredentialContext
304 }
305
306 export interface PublishVerifyInput<TDataOption = Record<string, unknown>, TOption = Record<string, unknown>> {
307 taskId: string
308 platform: AccountType
309 platformWorkId: string
310 option?: TOption
311 dataOption?: TDataOption
312 credential: CredentialContext
313 }
314
315 export interface PublishVerifyResult {
316 published: boolean
317 permalink?: string
318 platformWorkId?: string
319 linkStatus?: PublishRecordLinkStatus
320 linkMeta?: Record<string, unknown>
321 }
322
323 export interface PublishCancelInput {
324 taskId: string
325 platform: AccountType
326 platformWorkId: string
327 credential: CredentialContext
328 }
329
330 export interface PublishCancelResult {
331 canceled: boolean
332 }
333
334 export interface PublishUpdateInput<TOption = Record<string, unknown>> {
335 taskId: string
336 platform: AccountType
337 platformWorkId: string
338 content: PublishContentInput
339 option?: TOption
340 credential: CredentialContext
341 }
342
343 export interface PublishProvider<TOption = Record<string, unknown>, TDataOption = Record<string, unknown>> {
344 readonly platform: AccountType
345
346 validate: (input: PublishValidateInput<TOption>) => Promise<PublishValidationResult>
347 normalize: (input: PublishNormalizeInput<TOption>) => Promise<NormalizedPublishTask<TOption>>
348 publish: (input: PublishPublishInput<TOption>) => Promise<PublishProviderResult<TDataOption>>
349 resolveMediaRules?: (input: PublishValidateInput<TOption>) => PlatformMediaRules
350 finalize?: (input: PublishFinalizeInput<TDataOption, TOption>) => Promise<PublishProviderResult<TDataOption>>
351 verify?: (input: PublishVerifyInput<TDataOption, TOption>) => Promise<PublishVerifyResult>
352 cancel?: (input: PublishCancelInput) => Promise<PublishCancelResult>
353 update?: (input: PublishUpdateInput<TOption>) => Promise<PublishProviderResult<TDataOption>>
354 }
355
356 export enum PublishOptionValueType {
357 List = 'list',
358 Tree = 'tree',
359 }
360
361 export interface PublishOptionSource {
362 field: string
363 label: string
364 description?: string
365 valueType: PublishOptionValueType
366 requiresAccount: boolean
367 filterSchema?: z.ZodTypeAny
368 createSchema?: z.ZodTypeAny
369 }
370
371 export type PublishOptionFilterValue = string | number | boolean | Date | null | undefined
372 export type PublishOptionFilters = Record<string, PublishOptionFilterValue | PublishOptionFilterValue[]>
373 export type PublishOptionJsonSchemaView = z.core.JSONSchema.BaseSchema
374
375 export interface PublishOptionValuesInput {
376 userId: string
377 accountId: string
378 field: string
379 filters?: Record<string, unknown>
380 credential: CredentialContext
381 }
382
383 export interface PublishOptionValueItem {
384 value: string
385 label: string
386 description?: string
387 disabled?: boolean
388 children?: PublishOptionValueItem[]
389 extra?: Record<string, unknown>
390 }
391
392 export interface PublishOptionValuesResult {
393 field: string
394 valueType: PublishOptionValueType
395 items: PublishOptionValueItem[]
396 }
397
398 export interface PublishOptionCreateInput {
399 userId: string
400 accountId: string
401 field: string
402 data?: Record<string, unknown>
403 credential: CredentialContext
404 }
405
406 export interface PublishOptionCreateResult {
407 field: string
408 valueType: PublishOptionValueType
409 item: PublishOptionValueItem
410 }
411
412 export interface PublishOptionSourceProvider {
413 listSources: () => PublishOptionSource[]
414 getValues: (input: PublishOptionValuesInput) => Promise<PublishOptionValuesResult>
415 createValue?: (input: PublishOptionCreateInput) => Promise<PublishOptionCreateResult>
416 }
417
418 // ── Analytics ──
419
420 export interface ChannelSnapshotTime {
421 snapshotAt: Date
422 fetchedAt?: Date
423 periodStartAt?: Date
424 periodEndAt?: Date
425 }
426
427 export interface ChannelAccountProfileSnapshot {
428 displayName?: string
429 username?: string
430 avatarUrl?: string
431 accountType?: string
432 }
433
434 export interface ChannelAccountMetricsSnapshot {
435 fansCount?: number
436 followingCount?: number
437 workCount?: number
438 readCount?: number
439 viewCount?: number
440 impressionCount?: number
441 reachCount?: number
442 likeCount?: number
443 collectCount?: number
444 forwardCount?: number
445 commentCount?: number
446 clickCount?: number
447 engagementCount?: number
448 }
449
450 export interface ChannelWorkSnapshot {
451 id: string
452 url?: string
453 title?: string
454 description?: string
455 mediaType?: string
456 coverUrl?: string
457 publishedAt?: Date
458 status?: string
459 author?: string
460 }
461
462 export interface ChannelWorkMetricsSnapshot {
463 viewCount?: number
464 playCount?: number
465 impressionCount?: number
466 reachCount?: number
467 likeCount?: number
468 collectCount?: number
469 commentCount?: number
470 shareCount?: number
471 saveCount?: number
472 clickCount?: number
473 engagementCount?: number
474 watchTimeSeconds?: number
475 }
476
477 export interface ChannelAccountDataSnapshotPayload extends ChannelSnapshotTime {
478 platformUid?: string
479 profile?: ChannelAccountProfileSnapshot
480 metrics?: ChannelAccountMetricsSnapshot
481 extra?: Record<string, unknown>
482 rawResponse?: unknown
483 }
484
485 export interface ChannelWorkDataSnapshotPayload extends ChannelSnapshotTime {
486 platformWorkId?: string
487 work: ChannelWorkSnapshot
488 metrics?: ChannelWorkMetricsSnapshot
489 extra?: Record<string, unknown>
490 rawResponse?: unknown
491 }
492
493 export interface ChannelAccountAnalyticsResult {
494 snapshots: ChannelAccountDataSnapshotPayload[]
495 profile?: ChannelAccountProfileSnapshot
496 metrics?: ChannelAccountMetricsSnapshot
497 extra?: Record<string, unknown>
498 rawResponse?: unknown
499 }
500
501 export interface ChannelWorkAnalyticsResult {
502 snapshots: ChannelWorkDataSnapshotPayload[]
503 work?: ChannelWorkSnapshot
504 metrics?: ChannelWorkMetricsSnapshot
505 extra?: Record<string, unknown>
506 rawResponse?: unknown
507 }
508
509 export interface ChannelWorkDataResult<TExtra = Record<string, unknown>> {
510 snapshots: ChannelWorkDataSnapshotPayload[]
511 work?: ChannelWorkSnapshot
512 metrics?: ChannelWorkMetricsSnapshot
513 extra?: TExtra
514 rawResponse?: unknown
515 }
516
517 export enum ChannelPaginationMode {
518 Cursor = 'cursor',
519 Page = 'page',
520 None = 'none',
521 }
522
523 export enum ChannelPaginationDirection {
524 Next = 'next',
525 Previous = 'previous',
526 }
527
528 export interface ChannelPaginationInput {
529 cursor?: string
530 limit?: number
531 direction?: ChannelPaginationDirection
532 page?: number
533 pageSize?: number
534 }
535
536 export interface ChannelCursorPaginationResult {
537 mode: ChannelPaginationMode.Cursor
538 nextCursor?: string
539 previousCursor?: string
540 hasNext: boolean
541 hasPrevious: boolean
542 limit: number
543 }
544
545 export interface ChannelPagePaginationResult {
546 mode: ChannelPaginationMode.Page
547 page: number
548 pageSize: number
549 total?: number
550 hasNext: boolean
551 hasPrevious: boolean
552 }
553
554 export interface ChannelNonePaginationResult {
555 mode: ChannelPaginationMode.None
556 }
557
558 export type ChannelPaginationResult
559 = | ChannelCursorPaginationResult
560 | ChannelPagePaginationResult
561 | ChannelNonePaginationResult
562
563 export interface ChannelCursorPaginationMetadata {
564 mode: ChannelPaginationMode.Cursor
565 defaultLimit: number
566 maxLimit: number
567 supportsPrevious: boolean
568 }
569
570 export interface ChannelPagePaginationMetadata {
571 mode: ChannelPaginationMode.Page
572 defaultPageSize: number
573 maxPageSize: number
574 supportsTotal: boolean
575 }
576
577 export interface ChannelNonePaginationMetadata {
578 mode: ChannelPaginationMode.None
579 }
580
581 export type ChannelPaginationMetadata
582 = | ChannelCursorPaginationMetadata
583 | ChannelPagePaginationMetadata
584 | ChannelNonePaginationMetadata
585
586 export interface ChannelWorkListItem {
587 platformWorkId: string
588 contentMode: PublishContentMode
589 title?: string
590 description?: string
591 url?: string
592 coverUrl?: string
593 publishedAt?: Date
594 authorName?: string
595 authorPlatformUid?: string
596 status?: string
597 metrics?: ChannelWorkMetricsSnapshot
598 }
599
600 export interface ChannelWorkListResult {
601 items: ChannelWorkListItem[]
602 pagination: ChannelPaginationResult
603 }
604
605 export interface AnalyticsAccountInput {
606 accountId: string
607 platform: AccountType
608 credential: CredentialContext
609 since?: Date
610 until?: Date
611 }
612
613 export interface AnalyticsWorkInput {
614 accountId: string
615 platformWorkId: string
616 platform: AccountType
617 credential: CredentialContext
618 since?: Date
619 until?: Date
620 }
621
622 export interface AnalyticsProvider {
623 fetchAccountAnalytics: (input: AnalyticsAccountInput) => Promise<ChannelAccountAnalyticsResult>
624 fetchWorkAnalytics?: (input: AnalyticsWorkInput) => Promise<ChannelWorkAnalyticsResult>
625 }
626
627 // ── Engagement ──
628
629 export interface EngagementCommentInput {
630 accountId: string
631 platformWorkId: string
632 platform: AccountType
633 credential: CredentialContext
634 content: string
635 replyToId?: string
636 }
637
638 export interface EngagementLikeInput {
639 accountId: string
640 platformWorkId: string
641 platform: AccountType
642 credential: CredentialContext
643 }
644
645 export interface EngagementQuoteInput extends EngagementLikeInput {
646 content: string
647 }
648
649 export interface EngagementCommentActionInput {
650 accountId: string
651 commentId: string
652 platform: AccountType
653 credential: CredentialContext
654 }
655
656 export interface EngagementAccountActionInput {
657 accountId: string
658 targetPlatformUid: string
659 platform: AccountType
660 credential: CredentialContext
661 }
662
663 export enum ChannelEngagementActionType {
664 Comment = 'comment',
665 Reply = 'reply',
666 DeleteComment = 'delete_comment',
667 Like = 'like',
668 Unlike = 'unlike',
669 Repost = 'repost',
670 UndoRepost = 'undo_repost',
671 Quote = 'quote',
672 Bookmark = 'bookmark',
673 RemoveBookmark = 'remove_bookmark',
674 HideReply = 'hide_reply',
675 UnhideReply = 'unhide_reply',
676 Follow = 'follow',
677 Unfollow = 'unfollow',
678 }
679
680 export enum ChannelEngagementFunctionName {
681 DeleteComment = 'delete_comment',
682 Like = 'like',
683 Unlike = 'unlike',
684 Repost = 'repost',
685 UndoRepost = 'undo_repost',
686 Quote = 'quote',
687 Bookmark = 'bookmark',
688 RemoveBookmark = 'remove_bookmark',
689 HideReply = 'hide_reply',
690 UnhideReply = 'unhide_reply',
691 Follow = 'follow',
692 Unfollow = 'unfollow',
693 }
694
695 export enum ChannelEngagementTargetType {
696 Work = 'work',
697 Comment = 'comment',
698 Account = 'account',
699 }
700
701 export interface ChannelComment {
702 platformCommentId: string
703 platformWorkId?: string
704 parentCommentId?: string
705 authorName?: string
706 authorPlatformUid?: string
707 content: string
708 createdAt?: Date
709 likeCount?: number
710 replyCount?: number
711 }
712
713 export interface ChannelCommentListResult {
714 items: ChannelComment[]
715 pagination: ChannelPaginationResult
716 }
717
718 export interface ChannelEngagementActionResult {
719 actionType: ChannelEngagementActionType
720 targetType: ChannelEngagementTargetType
721 targetId: string
722 platformActionId?: string
723 success: boolean
724 createdAt?: Date
725 }
726
727 export interface EngagementProvider {
728 readonly commentPagination: ChannelPaginationMetadata
729 listComments?: (input: EngagementListInput) => Promise<ChannelCommentListResult>
730 createComment?: (input: EngagementCommentInput) => Promise<ChannelEngagementActionResult>
731 deleteComment?: (input: EngagementDeleteInput) => Promise<ChannelEngagementActionResult>
732 like?: (input: EngagementLikeInput) => Promise<ChannelEngagementActionResult>
733 unlike?: (input: EngagementLikeInput) => Promise<ChannelEngagementActionResult>
734 repost?: (input: EngagementLikeInput) => Promise<ChannelEngagementActionResult>
735 undoRepost?: (input: EngagementLikeInput) => Promise<ChannelEngagementActionResult>
736 quote?: (input: EngagementQuoteInput) => Promise<ChannelEngagementActionResult>
737 bookmark?: (input: EngagementLikeInput) => Promise<ChannelEngagementActionResult>
738 removeBookmark?: (input: EngagementLikeInput) => Promise<ChannelEngagementActionResult>
739 hideReply?: (input: EngagementCommentActionInput) => Promise<ChannelEngagementActionResult>
740 unhideReply?: (input: EngagementCommentActionInput) => Promise<ChannelEngagementActionResult>
741 follow?: (input: EngagementAccountActionInput) => Promise<ChannelEngagementActionResult>
742 unfollow?: (input: EngagementAccountActionInput) => Promise<ChannelEngagementActionResult>
743 }
744
745 export interface EngagementListInput {
746 accountId: string
747 platformWorkId: string
748 platform: AccountType
749 credential: CredentialContext
750 pagination: ChannelPaginationInput
751 }
752
753 export interface EngagementDeleteInput {
754 accountId: string
755 commentId: string
756 platform: AccountType
757 credential: CredentialContext
758 }
759
760 // ── Browse ──
761
762 export interface BrowseSearchInput {
763 accountId: string
764 platform: AccountType
765 credential: CredentialContext
766 query: string
767 cursor?: string
768 limit?: number
769 }
770
771 export interface BrowseDetailInput {
772 accountId: string
773 platformWorkId: string
774 platform: AccountType
775 credential: CredentialContext
776 }
777
778 export interface BrowseProvider {
779 search?: (input: BrowseSearchInput) => Promise<unknown>
780 getDetail?: (input: BrowseDetailInput) => Promise<unknown>
781 }
782
783 // ── Work ──
784
785 export interface WorkLinkInfoInput {
786 accountId?: string
787 platform: AccountType
788 credential?: CredentialContext
789 link: string
790 dataId?: string
791 }
792
793 export interface WorkDetailInput {
794 accountId: string
795 platformWorkId: string
796 platform: AccountType
797 credential: CredentialContext
798 }
799
800 export interface WorkOwnershipInput {
801 accountId: string
802 platformWorkId: string
803 platform: AccountType
804 credential: CredentialContext
805 }
806
807 export interface WorkListInput {
808 accountId: string
809 platform: AccountType
810 credential: CredentialContext
811 pagination: ChannelPaginationInput
812 }
813
814 export interface WorkProvider {
815 readonly listWorksPagination?: ChannelPaginationMetadata
816 requiresCredentialForLinkInfo?: boolean
817 listWorks?: (input: WorkListInput) => Promise<ChannelWorkListResult>
818 getLinkInfo?: (input: WorkLinkInfoInput) => Promise<ChannelWorkDataResult>
819 getDetail?: (input: WorkDetailInput) => Promise<ChannelWorkDataResult>
820 verifyOwnership?: (input: WorkOwnershipInput) => Promise<boolean>
821 }
822
823 // ── Webhook ──
824
825 export interface PlatformWebhookContext {
826 platform: AccountType
827 }
828
829 export interface PlatformWebhookHandler {
830 handle: (request: Request, response: Response, context: PlatformWebhookContext) => Promise<void>
831 }
832
833 export interface RawBodyRequest extends Request {
834 rawBody?: Buffer
835 }
836
837 // ── Metadata ──
838
839 export interface PlatformContentLimits {
840 modes: PublishContentMode[]
841 maxTitleLength?: number
842 maxBodyLength?: number
843 maxTotalTextLength?: number
844 maxMediaCount?: number
845 maxImages?: number
846 maxVideos?: number
847 }
848
849 export interface PlatformPublishPolicy {
850 completionStrategy: CompletionStrategy
851 scheduleByPlatform: boolean
852 updateSupported: boolean
853 }
854
855 export interface PlatformEmptyAccountHint {
856 title: Record<Locale, string>
857 description: Record<Locale, string>
858 action?: {
859 label: Record<Locale, string>
860 url: string
861 }
862 }
863
864 export enum ChannelWorkAnalyticsDataSource {
865 Official = 'official',
866 PostInsightCrawler = 'post_insight_crawler',
867 }
868
869 export interface PlatformWorkAnalyticsMetadata {
870 dataSources: ChannelWorkAnalyticsDataSource[]
871 }
872
873 export interface PlatformAnalyticsMetadata {
874 work?: PlatformWorkAnalyticsMetadata
875 }
876
877 export interface PlatformMetadata {
878 platform: AccountType
879 displayName: Record<Locale, string>
880 logoUrl: string
881 authType: AuthType
882 authInstructions?: Record<Locale, string>
883 emptyAccountHint?: PlatformEmptyAccountHint
884 editor: EditorType
885 contentLimits: PlatformContentLimits
886 mediaRules: PlatformMediaRules
887 topic: TopicCapability
888 publishPolicy?: PlatformPublishPolicy
889 optionSchema: z.ZodTypeAny
890 defaultOption?: Record<string, unknown>
891 analytics?: PlatformAnalyticsMetadata
892 }
893
894 export interface PlatformStaticMetadata extends Omit<PlatformMetadata, 'logoUrl'> {}
895
896 export interface PlatformAuthCapabilities {
897 supported: boolean
898 revoke: boolean
899 selectableAccounts: boolean
900 refreshAccountAccess: boolean
901 }
902
903 export interface PlatformPublishCapabilities {
904 supported: boolean
905 cancel: boolean
906 update: boolean
907 verify: boolean
908 finalize: boolean
909 scheduleByPlatform: boolean
910 optionSources: boolean
911 completionStrategy?: CompletionStrategy
912 }
913
914 export interface PlatformAnalyticsCapabilities {
915 account: boolean
916 work: boolean
917 }
918
919 export interface ChannelEngagementOperationParameters {
920 querySchema: PublishOptionJsonSchemaView
921 bodySchema?: PublishOptionJsonSchemaView
922 dataSchema?: PublishOptionJsonSchemaView
923 }
924
925 export interface PlatformEngagementCommentCapabilities {
926 list: {
927 supported: boolean
928 pagination: ChannelPaginationMetadata
929 parameters: ChannelEngagementOperationParameters
930 }
931 create: {
932 supported: boolean
933 parameters: ChannelEngagementOperationParameters
934 }
935 }
936
937 export interface PlatformEngagementFunctionCapabilities {
938 name: ChannelEngagementFunctionName
939 label: Record<Locale, string>
940 target: ChannelEngagementTargetType
941 parameters: Required<ChannelEngagementOperationParameters>
942 }
943
944 export interface PlatformEngagementCapabilities {
945 comments: PlatformEngagementCommentCapabilities
946 functions: PlatformEngagementFunctionCapabilities[]
947 }
948
949 export interface PlatformWorkCapabilities {
950 listWorks: boolean
951 listWorksPagination: ChannelPaginationMetadata
952 getLinkInfo: boolean
953 getDetail: boolean
954 verifyOwnership: boolean
955 }
956
957 export interface PlatformBrowseCapabilities {
958 search: boolean
959 getDetail: boolean
960 }
961
962 export interface PlatformWebhookCapabilities {
963 supported: boolean
964 }
965
966 export interface PlatformCapabilities {
967 auth: PlatformAuthCapabilities
968 publish: PlatformPublishCapabilities
969 analytics: PlatformAnalyticsCapabilities
970 engagement: PlatformEngagementCapabilities
971 work: PlatformWorkCapabilities
972 browse: PlatformBrowseCapabilities
973 webhook: PlatformWebhookCapabilities
974 }
975
976 export enum PlatformStatus {
977 Hidden = 'hidden',
978 Available = 'available',
979 Unavailable = 'unavailable',
980 ComingSoon = 'coming_soon',
981 }
982
983 export interface CachedPlatformMetadata extends Omit<PlatformMetadata, 'optionSchema'> {
984 status: PlatformStatus
985 capabilities: PlatformCapabilities
986 optionSchema: Record<string, unknown>
987 }
988
989 // ── Runtime Policy ──
990
991 export interface PlatformMediaPolicy {
992 imageConvertFormat?: string
993 maxImageWidth?: number
994 maxImageHeight?: number
995 imageQuality?: number
996 videoMaxDuration?: number
997 videoMaxBitrate?: number
998 generateCover?: boolean
999 }
1000
1001 export interface PlatformRetryPolicy {
1002 maxRetries?: number
1003 backoffMs?: number
1004 backoffMultiplier?: number
1005 }
1006
1007 export interface PlatformRuntimePolicy {
1008 concurrency?: number
1009 scheduleWindow?: number
1010 publishTimeout?: number
1011 userActionTimeout?: number
1012 finalizeTimeout?: number
1013 webhookTimeout?: number
1014 refreshWait?: number
1015 refreshBeforeExpiry?: number
1016 backgroundRefresh?: boolean
1017 media?: PlatformMediaPolicy
1018 retry?: PlatformRetryPolicy
1019 }
1020
1021 // ── Platform Integration ──
1022
1023 export interface PlatformIntegration<TOption = Record<string, unknown>, TDataOption = Record<string, unknown>> {
1024 readonly platform: AccountType
1025 readonly metadata: PlatformMetadata
1026 readonly status?: PlatformStatus
1027 readonly runtime: PlatformRuntimePolicy
1028 readonly auth?: AuthProvider
1029 readonly publish?: PublishProvider<TOption, TDataOption>
1030 readonly publishOptions?: PublishOptionSourceProvider
1031 readonly analytics?: AnalyticsProvider
1032 readonly engagement?: EngagementProvider
1033 readonly browse?: BrowseProvider
1034 readonly work?: WorkProvider
1035 readonly webhook?: PlatformWebhookHandler
1036 }
1037
1038 // ── Error ──
1039
1040 export interface PublishTaskError {
1041 category: PlatformErrorCategory
1042 code?: string
1043 message: string
1044 originalData?: unknown
1045 retryable: boolean
1046 occurredAt: Date
1047 }
1048
1048 lines TYPESCRIPT