返回 AiToEarn
auth.interface.ts
1 import type { AccountType, Locale } from '@yikart/common'
2 import type { AuthCallbackResponseType, GenerateAuthUrlInput, PlatformSelectableAccount } from '../platforms/platforms.interface'
3 import { ChannelAuthSessionStatus } from '@yikart/common'
4
5 export enum ChannelAuthSessionFlow {
6 AccountAuth = 'account-auth',
7 }
8
9 export interface ChannelAuthSessionBase {
10 flow?: ChannelAuthSessionFlow
11 id: string
12 platform: AccountType
13 redirectUri?: string
14 authExtras?: Record<string, unknown>
15 status: ChannelAuthSessionStatus
16 errorCode?: number
17 expiresAt?: Date
18 createdAt: Date
19 }
20
21 export interface StartAuthInput {
22 userId: string
23 platform: AccountType
24 callbackUrl?: string
25 redirectUri?: string
26 groupId?: string
27 userAgent?: string
28 deviceType?: GenerateAuthUrlInput['deviceType']
29 }
30
31 export interface StartAuthResult {
32 url: string
33 expiresAt: Date
34 authInstructions?: Record<Locale, string>
35 }
36
37 export interface StartAuthSessionResult extends StartAuthResult {
38 sessionId: string
39 }
40
41 export interface AuthSession extends ChannelAuthSessionBase {
42 flow?: ChannelAuthSessionFlow.AccountAuth
43 userId: string
44 callbackUrl?: string
45 groupId: string
46 rootCredentialId?: string
47 selectableAccounts?: PlatformSelectableAccount[]
48 accountId?: string
49 accountIds?: string[]
50 accounts?: ConnectedSelectableAccount[]
51 }
52
53 export interface SelectableAccountView {
54 platform: AccountType
55 platformUid: string
56 account?: string
57 displayName: string
58 avatarUrl?: string
59 parentPlatformUid?: string
60 }
61
62 export interface SelectedAccountIdentity {
63 platformUid: string
64 account?: string
65 }
66
67 export interface EmptyAccountHintView {
68 title: string
69 description: string
70 action?: {
71 label: string
72 url: string
73 }
74 }
75
76 export interface AuthViewFields {
77 platformDisplayName: string
78 platformLogoUrl: string
79 callbackUrl?: string
80 redirectUri?: string
81 emptyAccountHint?: EmptyAccountHintView
82 }
83
84 export interface AuthCallbackResult extends Partial<AuthViewFields> {
85 accountId?: string
86 requiresSelection?: boolean
87 accounts?: SelectableAccountView[]
88 connectedAccounts?: ConnectedSelectableAccount[]
89 callbackResponseType?: AuthCallbackResponseType
90 }
91
92 export interface ConnectedSelectableAccount {
93 accountId: string
94 platform: AccountType
95 platformUid: string
96 account?: string
97 displayName: string
98 avatarUrl?: string
99 }
100
101 export interface ConnectSelectableAccountsResult {
102 accountIds: string[]
103 accounts: ConnectedSelectableAccount[]
104 platformDisplayName: string
105 platformLogoUrl: string
106 callbackUrl?: string
107 redirectUri?: string
108 }
109
110 export interface AuthSessionResult {
111 sessionId: string
112 status: ChannelAuthSessionStatus
113 requiresSelection: boolean
114 errorCode?: number
115 expiresAt?: Date
116 accountId?: string
117 accountIds?: string[]
118 accounts?: ConnectedSelectableAccount[]
119 selectableAccounts?: SelectableAccountView[]
120 }
121
121 lines TYPESCRIPT