feat(feishu): show the linked app and change it after confirmation
The plugin page never showed which Feishu app the CLI uses, and once an app existed the app step never appeared again. The Host now reports the configured app id on every account state that has one, and linkApp replaces the configuration with the app the user creates or chooses on the Feishu page. The section shows the app id and offers Change app, which explains that the terminal's lark-cli changes too and that the user signs in again, then links an app after confirmation.
This commit is contained in:
1 parent
a5ee99d463
commit
5ac009977d
18 files changed
+147
-91
No files matched your search
@@ -382,7 +382,7 @@ Registers the CLI and skills, and owns the account operations the Plugins page d
|
||||
@Remote check(): FeishuOperationId
|
||||
|
||||
/**
|
||||
* Link an app through the CLI's setup page when none is configured; an existing app is kept.
|
||||
* Link an app through the CLI's setup page, replacing a configured app and its sign-ins.
|
||||
* @returns the operation identity.
|
||||
* @throws while another account operation runs.
|
||||
*/
|
||||
|
||||
@@ -382,7 +382,7 @@ Registers the CLI and skills, and owns the account operations the Plugins page d
|
||||
@Remote check(): FeishuOperationId
|
||||
|
||||
/**
|
||||
* Link an app through the CLI's setup page when none is configured; an existing app is kept.
|
||||
* Link an app through the CLI's setup page, replacing a configured app and its sign-ins.
|
||||
* @returns the operation identity.
|
||||
* @throws while another account operation runs.
|
||||
*/
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
en: d152484eb41ac6b4
|
||||
zh: 09388d293f9be9cb
|
||||
/deepseek-ai-dsh-client-ui-feishu/use-this-package:
|
||||
en: 02d9cabf78b7db73
|
||||
zh: 5d7c41619e5565bf
|
||||
en: 37df0d11443431c4
|
||||
zh: b2ecd48185b43539
|
||||
/deepseek-ai-dsh-client-ui-feishu/understand-the-implementation:
|
||||
en: 3599958abbfb2f52
|
||||
zh: 68eae79d08462831
|
||||
|
||||
@@ -32,6 +32,7 @@ Install the [Feishu plugin bundle](../../connector/feishu/README.md), which inse
|
||||
| Checking connection | None |
|
||||
| Not connected, no app | **Link Feishu app** opens the Feishu page where the user creates or chooses an app, then stops |
|
||||
| Not connected, app linked | **Sign in to Feishu** opens the Feishu authorization page |
|
||||
| Any state with a linked app | The section shows the app id; **Change app** asks for confirmation, then links an app again, which replaces the CLI's configuration for the terminal too and requires another sign-in |
|
||||
| Step 1: Link a Feishu app, or Step 2: Sign in to Feishu | The browser that clicked opens the step's Feishu page once; **Open Feishu page** opens it again, and **Cancel** ends the step |
|
||||
| Connected | **Sign out** asks for confirmation, then signs out the CLI's default account. When the last sign-in left permissions ungranted, the section says how many and offers **Grant more**, which signs in again |
|
||||
| Cannot confirm sign-in right now | **Retry** runs the connection again and keeps the existing setup and sign-in |
|
||||
|
||||
@@ -32,6 +32,7 @@ kind: "package-reference"
|
||||
| 正在检查连接 | 无 |
|
||||
| 未连接,没有应用 | **关联飞书应用**打开飞书页面,用户在其中新建或选择应用,完成后停下 |
|
||||
| 未连接,已关联应用 | **登录飞书账号**打开飞书授权页面 |
|
||||
| 任何已关联应用的状态 | 区块显示应用 id;**更换应用**确认后重新关联应用,这会一并替换终端使用的 CLI 配置,之后需要重新登录 |
|
||||
| 第 1 步:关联飞书应用,或第 2 步:登录飞书账号 | 点击的浏览器会把这一步的飞书页面打开一次;**打开飞书页面**再次打开,**取消**结束这一步 |
|
||||
| 已连接 | **退出登录**确认后退出 CLI 的默认账号。上次登录仍有权限未被授予时,区块说明数量并提供**补充授权**,它会重新登录 |
|
||||
| 暂时无法确认登录状态 | **重试**重新运行连接,保留现有配置和登录 |
|
||||
|
||||
@@ -31,7 +31,7 @@ const BADGE: Record<Phase, readonly [FeishuKey, TagTone] | undefined> = {
|
||||
export function FeishuConnectionSection(props: FaceProps): ReactNode {
|
||||
const { useFeishuConnection, check, linkApp, signIn, cancel, signOut, openAuthorization, retry, t } = props
|
||||
const snapshot = useFeishuConnection(value => value)
|
||||
const [confirming, setConfirming] = useState(false)
|
||||
const [confirming, setConfirming] = useState<'sign-out' | 'replace-app' | undefined>(undefined)
|
||||
const shown = presentConnection(snapshot)
|
||||
// Reopening a stopped stream is the one action that does not need the Host stream.
|
||||
const disabled = snapshot.busy || (!snapshot.linked && shown.phase !== 'stopped')
|
||||
@@ -49,7 +49,7 @@ export function FeishuConnectionSection(props: FaceProps): ReactNode {
|
||||
case 'stopped': actions.push(action('action.retry', retry)); detail = t('detail.stopped'); break
|
||||
case 'connected':
|
||||
if (shown.ungranted !== undefined) actions.push(action('action.grantMore', signIn))
|
||||
actions.push(action('action.signOut', () => { setConfirming(true) }))
|
||||
actions.push(action('action.signOut', () => { setConfirming('sign-out') }))
|
||||
detail = shown.userName === undefined ? t('detail.connected') : t('detail.connectedAs', { name: shown.userName })
|
||||
break
|
||||
case 'connecting':
|
||||
@@ -74,15 +74,28 @@ export function FeishuConnectionSection(props: FaceProps): ReactNode {
|
||||
{shown.phase === 'connected' && shown.ungranted !== undefined
|
||||
? <p className={css.detail}>{t('detail.ungranted', { count: shown.ungranted })}</p>
|
||||
: null}
|
||||
{'appId' in shown
|
||||
? <div className={css.status}>
|
||||
<span className={css.detail}>{t('app.linked', { id: shown.appId })}</span>
|
||||
<div className={css.actions}>{action('action.replaceApp', () => { setConfirming('replace-app') }, 'ghost')}</div>
|
||||
</div>
|
||||
: null}
|
||||
{'failed' in shown && shown.failed ? <p className={css.failure} role="alert">{t('failed')}</p> : null}
|
||||
<p className={css.hint}>{t('hint')}</p>
|
||||
<Modal open={confirming} title={t('signOut.title')} closeLabel={t('close')} onClose={() => { setConfirming(false) }}
|
||||
<Modal open={confirming === 'sign-out'} title={t('signOut.title')} closeLabel={t('close')} onClose={() => { setConfirming(undefined) }}
|
||||
footer={<>
|
||||
<Button variant="ghost" onClick={() => { setConfirming(false) }}>{t('action.cancel')}</Button>
|
||||
<Button variant="primary" data-modal-autofocus onClick={() => { setConfirming(false); signOut() }}>{t('action.signOut')}</Button>
|
||||
<Button variant="ghost" onClick={() => { setConfirming(undefined) }}>{t('action.cancel')}</Button>
|
||||
<Button variant="primary" data-modal-autofocus onClick={() => { setConfirming(undefined); signOut() }}>{t('action.signOut')}</Button>
|
||||
</>}>
|
||||
<p>{t('signOut.body')}</p>
|
||||
</Modal>
|
||||
<Modal open={confirming === 'replace-app'} title={t('replaceApp.title')} closeLabel={t('close')} onClose={() => { setConfirming(undefined) }}
|
||||
footer={<>
|
||||
<Button variant="ghost" onClick={() => { setConfirming(undefined) }}>{t('action.cancel')}</Button>
|
||||
<Button variant="primary" data-modal-autofocus onClick={() => { setConfirming(undefined); linkApp() }}>{t('action.replaceApp')}</Button>
|
||||
</>}>
|
||||
<p>{t('replaceApp.body')}</p>
|
||||
</Modal>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { Context } from '@deepseek-ai/cordis'
|
||||
import type { RemoteStream } from '@deepseek-ai/dsh-api-gateway/client'
|
||||
import { createSnapshotStore, type SnapshotStore } from '@deepseek-ai/dsh-client-store'
|
||||
import type { HostObservable } from '@deepseek-ai/dsh-client-ui-slots'
|
||||
import type { FeishuOperationId, FeishuState } from '@deepseek-ai/dsh-feishu-cli/types'
|
||||
import type { FeishuAppId, FeishuOperationId, FeishuState } from '@deepseek-ai/dsh-feishu-cli/types'
|
||||
import type { RemoteResult } from '@deepseek-ai/dsh-typert-protocol'
|
||||
import { assertNever } from '@deepseek-ai/dsh-util-values'
|
||||
|
||||
@@ -36,10 +36,12 @@ export type ConnectionStep = 'configuring' | 'authorizing' | 'connecting' | 'sig
|
||||
/** What the user sees about the connection, derived from the Host's view alone. */
|
||||
export type ConnectionPresentation =
|
||||
| { readonly phase: 'checking' | 'stopped' }
|
||||
| { readonly phase: 'disconnected'; readonly next: 'link-app' | 'sign-in'; readonly failed: boolean }
|
||||
| { readonly phase: 'unavailable'; readonly failed: boolean }
|
||||
| { readonly phase: 'disconnected'; readonly next: 'link-app'; readonly failed: boolean }
|
||||
| { readonly phase: 'disconnected'; readonly next: 'sign-in'; readonly appId: FeishuAppId; readonly failed: boolean }
|
||||
| { readonly phase: 'unavailable'; readonly appId: FeishuAppId; readonly failed: boolean }
|
||||
| {
|
||||
readonly phase: 'connected'
|
||||
readonly appId: FeishuAppId
|
||||
readonly userName: string | undefined
|
||||
/** Requested permissions the last sign-in did not grant. */
|
||||
readonly ungranted: number | undefined
|
||||
@@ -58,7 +60,7 @@ export interface ConnectionFace {
|
||||
hooks: { feishuConnection: HostObservable<ConnectionSnapshot> }
|
||||
/** Check the account again. */
|
||||
check(): void
|
||||
/** Link an app when none is configured. */
|
||||
/** Link an app, replacing a configured one after the page confirms it. */
|
||||
linkApp(): void
|
||||
/** Sign the linked app's user in. */
|
||||
signIn(): void
|
||||
@@ -105,10 +107,11 @@ export function presentConnection(snapshot: Pick<ConnectionSnapshot, 'feishu' |
|
||||
const account = state.account
|
||||
switch (account.state) {
|
||||
case 'unchecked': return { phase: 'checking' }
|
||||
case 'connected': return { phase: 'connected', userName: account.userName, ungranted: account.ungrantedPermissions, failed }
|
||||
case 'connected':
|
||||
return { phase: 'connected', appId: account.appId, userName: account.userName, ungranted: account.ungrantedPermissions, failed }
|
||||
case 'unconfigured': return { phase: 'disconnected', next: 'link-app', failed }
|
||||
case 'signed-out': return { phase: 'disconnected', next: 'sign-in', failed }
|
||||
case 'unverified': return { phase: 'unavailable', failed }
|
||||
case 'signed-out': return { phase: 'disconnected', next: 'sign-in', appId: account.appId, failed }
|
||||
case 'unverified': return { phase: 'unavailable', appId: account.appId, failed }
|
||||
/* v8 ignore next -- closed account state union */
|
||||
default: return assertNever(account)
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ export const zh = {
|
||||
'detail.configuring': '在打开的飞书页面中新建或选择应用,完成后回到这里登录。页面没有打开时,点击“打开飞书页面”。',
|
||||
'detail.authorizing': '在打开的飞书页面中确认授权,完成后回到这里查看结果。页面没有打开时,点击“打开飞书页面”。',
|
||||
hint: '飞书账号与这台电脑终端里的飞书 CLI 共用。',
|
||||
'app.linked': '飞书应用:{id}',
|
||||
failed: '操作未完成,请重试',
|
||||
'action.connect': '连接飞书',
|
||||
'action.linkApp': '关联飞书应用',
|
||||
@@ -34,6 +35,7 @@ export const zh = {
|
||||
'action.cancel': '取消',
|
||||
'action.grantMore': '补充授权',
|
||||
'action.signOut': '退出登录',
|
||||
'action.replaceApp': '更换应用',
|
||||
'action.retry': '重试',
|
||||
'badge.connected': '已连接',
|
||||
'badge.disconnected': '未连接',
|
||||
@@ -42,6 +44,8 @@ export const zh = {
|
||||
'badge.stopped': '未运行',
|
||||
'signOut.title': '退出飞书登录?',
|
||||
'signOut.body': '将退出飞书 CLI 的默认账号,这台电脑终端里的 lark-cli 也会一起退出。已关联的飞书应用会保留。',
|
||||
'replaceApp.title': '更换飞书应用?',
|
||||
'replaceApp.body': '将打开飞书页面,新建或选择一个应用。这台电脑上飞书 CLI 的配置会替换为这个应用,终端里的 lark-cli 也一样;更换后需要重新登录飞书账号。',
|
||||
'activation.title': '连接飞书账号',
|
||||
'activation.body': '飞书插件已开启。连接你的飞书账号后,就可以在对话中使用它。',
|
||||
'activation.later': '稍后',
|
||||
@@ -78,6 +82,7 @@ export const en: Record<FeishuKey, string> = {
|
||||
'detail.configuring': 'Create or choose an app on the Feishu page, then come back here to sign in. If the page did not open, select Open Feishu page.',
|
||||
'detail.authorizing': 'Confirm the authorization on the Feishu page, then come back here to see the result. If the page did not open, select Open Feishu page.',
|
||||
hint: 'The Feishu account is shared with the Feishu CLI in this computer\'s terminal.',
|
||||
'app.linked': 'Feishu app: {id}',
|
||||
failed: 'The action did not finish. Try again.',
|
||||
'action.connect': 'Connect Feishu',
|
||||
'action.linkApp': 'Link Feishu app',
|
||||
@@ -86,6 +91,7 @@ export const en: Record<FeishuKey, string> = {
|
||||
'action.cancel': 'Cancel',
|
||||
'action.grantMore': 'Grant more',
|
||||
'action.signOut': 'Sign out',
|
||||
'action.replaceApp': 'Change app',
|
||||
'action.retry': 'Retry',
|
||||
'badge.connected': 'Connected',
|
||||
'badge.disconnected': 'Not connected',
|
||||
@@ -94,6 +100,8 @@ export const en: Record<FeishuKey, string> = {
|
||||
'badge.stopped': 'Not running',
|
||||
'signOut.title': 'Sign out of Feishu?',
|
||||
'signOut.body': 'This signs out the Feishu CLI\'s default account, including lark-cli in this computer\'s terminal. The linked Feishu app is kept.',
|
||||
'replaceApp.title': 'Change the Feishu app?',
|
||||
'replaceApp.body': 'A Feishu page opens where you create or choose an app. The Feishu CLI on this computer, including lark-cli in its terminal, is then configured with that app only, and you sign in to Feishu again.',
|
||||
'activation.title': 'Connect your Feishu account',
|
||||
'activation.body': 'The Feishu plugin is on. Connect your Feishu account to use it in conversations.',
|
||||
'activation.later': 'Later',
|
||||
|
||||
@@ -11,11 +11,12 @@ import { zh } from '../src/client/locales.ts'
|
||||
import {
|
||||
FeishuConnectionActivation, FeishuConnectionBadge, FeishuConnectionSection, FeishuConnectionToast,
|
||||
} from '../src/client/FeishuConnection.tsx'
|
||||
import type { FeishuOperationId, FeishuState } from '@deepseek-ai/dsh-feishu-cli/types'
|
||||
import type { FeishuAppId, FeishuOperationId, FeishuState } from '@deepseek-ai/dsh-feishu-cli/types'
|
||||
|
||||
afterEach(cleanup)
|
||||
|
||||
const OP = 'op' as FeishuOperationId
|
||||
const APP = 'cli_a' as FeishuAppId
|
||||
|
||||
function fixture(feishu?: FeishuState) {
|
||||
const state = createSnapshotStore<ConnectionSnapshot>({ feishu, linked: true, stopped: false, busy: false, notice: undefined })
|
||||
@@ -43,27 +44,27 @@ it('offers the next step for each state', () => {
|
||||
b.set({ feishu: { account: { state: 'unconfigured' }, operation: { id: OP, kind: 'link-app', phase: 'configuring' } } })
|
||||
expect(screen.getByText(zh['step.configuring'])).toBeTruthy()
|
||||
expect(screen.queryByRole('button', { name: zh['action.open'] })).toBeNull()
|
||||
b.set({ feishu: { account: { state: 'signed-out' } } })
|
||||
b.set({ feishu: { account: { state: 'signed-out', appId: APP } } })
|
||||
expect(screen.getByText(zh['detail.signed-out'])).toBeTruthy()
|
||||
fireEvent.click(button(zh['action.signIn']))
|
||||
expect(b.face.signIn).toHaveBeenCalledOnce()
|
||||
|
||||
b.set({ feishu: { account: { state: 'signed-out' }, operation: { id: OP, kind: 'sign-in', phase: 'authorizing', authorizationUrl: 'https://x.feishu.cn' } } })
|
||||
b.set({ feishu: { account: { state: 'signed-out', appId: APP }, operation: { id: OP, kind: 'sign-in', phase: 'authorizing', authorizationUrl: 'https://x.feishu.cn' } } })
|
||||
expect(screen.getByText(zh['detail.authorizing'])).toBeTruthy()
|
||||
fireEvent.click(button(zh['action.open']))
|
||||
fireEvent.click(button(zh['action.cancel']))
|
||||
expect(b.face.openAuthorization).toHaveBeenCalledOnce()
|
||||
expect(b.face.cancel).toHaveBeenCalledOnce()
|
||||
|
||||
b.set({ feishu: { account: { state: 'signed-out' }, operation: { id: OP, kind: 'sign-out', phase: 'signing-out', authorizationUrl: 'https://x.feishu.cn' } } })
|
||||
b.set({ feishu: { account: { state: 'signed-out', appId: APP }, operation: { id: OP, kind: 'sign-out', phase: 'signing-out', authorizationUrl: 'https://x.feishu.cn' } } })
|
||||
expect(screen.getByText(zh['step.signing-out'])).toBeTruthy()
|
||||
expect(screen.queryByRole('button', { name: zh['action.cancel'] })).toBeNull()
|
||||
expect(document.querySelector('[data-feishu-connection="connecting"] p')?.textContent).toBe(zh.hint)
|
||||
|
||||
b.set({ feishu: { account: { state: 'signed-out' }, result: { id: OP, kind: 'sign-in', outcome: 'failed' } } })
|
||||
b.set({ feishu: { account: { state: 'signed-out', appId: APP }, result: { id: OP, kind: 'sign-in', outcome: 'failed' } } })
|
||||
expect(screen.getByRole('alert').textContent).toBe(zh.failed)
|
||||
|
||||
b.set({ feishu: { account: { state: 'unverified' } } })
|
||||
b.set({ feishu: { account: { state: 'unverified', appId: APP } } })
|
||||
expect(screen.getByText(zh['detail.unavailable'])).toBeTruthy()
|
||||
fireEvent.click(button(zh['action.retry']))
|
||||
expect(b.face.check).toHaveBeenCalledOnce()
|
||||
@@ -86,10 +87,10 @@ it('explains a stopped Host component and retries even while the stream is offli
|
||||
})
|
||||
|
||||
it('shows who is signed in and signs out only after confirmation', () => {
|
||||
const b = fixture({ account: { state: 'connected', userName: '张三' } })
|
||||
const b = fixture({ account: { state: 'connected', appId: APP, userName: '张三' } })
|
||||
render(<FeishuConnectionSection {...b.face} />)
|
||||
expect(screen.getByText(text('detail.connectedAs', { name: '张三' }))).toBeTruthy()
|
||||
b.set({ feishu: { account: { state: 'connected' } } })
|
||||
b.set({ feishu: { account: { state: 'connected', appId: APP } } })
|
||||
expect(screen.getByText(zh['detail.connected'])).toBeTruthy()
|
||||
fireEvent.click(button(zh['action.signOut']))
|
||||
expect(screen.getByText(zh['signOut.body'])).toBeTruthy()
|
||||
@@ -102,13 +103,30 @@ it('shows who is signed in and signs out only after confirmation', () => {
|
||||
expect(b.face.signOut).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
it('shows the linked app and changes it only after confirmation', () => {
|
||||
const b = fixture({ account: { state: 'unconfigured' } })
|
||||
render(<FeishuConnectionSection {...b.face} />)
|
||||
expect(screen.queryByRole('button', { name: zh['action.replaceApp'] })).toBeNull()
|
||||
b.set({ feishu: { account: { state: 'signed-out', appId: APP } } })
|
||||
expect(screen.getByText(text('app.linked', { id: 'cli_a' }))).toBeTruthy()
|
||||
fireEvent.click(button(zh['action.replaceApp']))
|
||||
expect(screen.getByText(zh['replaceApp.body'])).toBeTruthy()
|
||||
fireEvent.click(button(zh['action.cancel']))
|
||||
fireEvent.click(button(zh['action.replaceApp']))
|
||||
fireEvent.click(button(zh.close))
|
||||
expect(b.face.linkApp).not.toHaveBeenCalled()
|
||||
fireEvent.click(button(zh['action.replaceApp']))
|
||||
fireEvent.click(screen.getAllByRole('button', { name: zh['action.replaceApp'] }).at(-1)!)
|
||||
expect(b.face.linkApp).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
it('explains ungranted permissions and grants more through another sign-in', () => {
|
||||
const b = fixture({ account: { state: 'connected', userName: '张三', ungrantedPermissions: 4 } })
|
||||
const b = fixture({ account: { state: 'connected', appId: APP, userName: '张三', ungrantedPermissions: 4 } })
|
||||
render(<FeishuConnectionSection {...b.face} />)
|
||||
expect(screen.getByText(text('detail.ungranted', { count: '4' }))).toBeTruthy()
|
||||
fireEvent.click(button(zh['action.grantMore']))
|
||||
expect(b.face.signIn).toHaveBeenCalledOnce()
|
||||
b.set({ feishu: { account: { state: 'connected', userName: '张三' } } })
|
||||
b.set({ feishu: { account: { state: 'connected', appId: APP, userName: '张三' } } })
|
||||
expect(screen.queryByRole('button', { name: zh['action.grantMore'] })).toBeNull()
|
||||
})
|
||||
|
||||
@@ -122,17 +140,17 @@ it('disables actions while one is pending or the Host stream is offline', () =>
|
||||
})
|
||||
|
||||
it('tags only the enabled Feishu bundle', () => {
|
||||
const b = fixture({ account: { state: 'connected' } })
|
||||
const b = fixture({ account: { state: 'connected', appId: APP } })
|
||||
const pkg = (name: string, enabled = true): PluginPackageRef => ({ name, installed: true, availability: 'profile', official: false, enabled, rows: [] })
|
||||
const badge = (subject: PluginsSubject) =>
|
||||
<FeishuConnectionBadge {...{ ...b.face, subject } as ComponentProps<typeof FeishuConnectionBadge>} />
|
||||
const { rerender } = render(badge({ kind: 'bundle', pkg: pkg('@deepseek-ai/dsh-feishu') }))
|
||||
expect(screen.getByText(zh['badge.connected'])).toBeTruthy()
|
||||
b.set({ feishu: { account: { state: 'unverified' } } })
|
||||
b.set({ feishu: { account: { state: 'unverified', appId: APP } } })
|
||||
expect(screen.getByText(zh['badge.unavailable'])).toBeTruthy()
|
||||
b.set({ feishu: undefined })
|
||||
expect(document.body.textContent).toBe('')
|
||||
b.set({ feishu: { account: { state: 'signed-out' } } })
|
||||
b.set({ feishu: { account: { state: 'signed-out', appId: APP } } })
|
||||
rerender(badge({ kind: 'bundle', pkg: pkg('@deepseek-ai/dsh-feishu', false) }))
|
||||
expect(document.body.textContent).toBe('')
|
||||
rerender(badge({ kind: 'bundle', pkg: pkg('@acme/other') }))
|
||||
@@ -143,7 +161,7 @@ it('tags only the enabled Feishu bundle', () => {
|
||||
|
||||
it.each<[string, FeishuState, 'linkApp' | 'signIn']>([
|
||||
['links an app first', { account: { state: 'unconfigured' } }, 'linkApp'],
|
||||
['signs in to a linked app', { account: { state: 'signed-out' } }, 'signIn'],
|
||||
['signs in to a linked app', { account: { state: 'signed-out', appId: APP } }, 'signIn'],
|
||||
])('guides a newly enabled bundle to its next step: %s, and steps aside once connected', (_name, state, step) => {
|
||||
const b = fixture()
|
||||
const onDismiss = vi.fn(), onOpenDetails = vi.fn()
|
||||
@@ -155,7 +173,7 @@ it.each<[string, FeishuState, 'linkApp' | 'signIn']>([
|
||||
expect(onOpenDetails).toHaveBeenCalledOnce()
|
||||
expect(b.face[step]).toHaveBeenCalledOnce()
|
||||
expect(onDismiss).not.toHaveBeenCalled()
|
||||
b.set({ feishu: { account: { state: 'connected' } } })
|
||||
b.set({ feishu: { account: { state: 'connected', appId: APP } } })
|
||||
expect(onDismiss).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
|
||||
@@ -2,13 +2,14 @@
|
||||
/** The page derives the Feishu connection from the Host's view and drives account operations through its Remote. */
|
||||
import { Context } from '@deepseek-ai/cordis'
|
||||
import type { RemoteStreamOptions } from '@deepseek-ai/dsh-api-gateway/client'
|
||||
import type { FeishuOperationId, FeishuOperationState, FeishuState } from '@deepseek-ai/dsh-feishu-cli/types'
|
||||
import type { FeishuAppId, FeishuOperationId, FeishuOperationState, FeishuState } from '@deepseek-ai/dsh-feishu-cli/types'
|
||||
import { RemoteError } from '@deepseek-ai/dsh-typert-protocol'
|
||||
import { expect, it, onTestFinished, vi } from 'vitest'
|
||||
import { FeishuConnection, presentConnection, type ConnectionPresentation, type ConnectionStep } from '../src/client/connection.ts'
|
||||
|
||||
const OP = 'op-1' as FeishuOperationId
|
||||
const SIGNED_OUT: FeishuState = { account: { state: 'signed-out' } }
|
||||
const APP = 'cli_a' as FeishuAppId
|
||||
const SIGNED_OUT: FeishuState = { account: { state: 'signed-out', appId: APP } }
|
||||
|
||||
function operation(kind: FeishuOperationState['kind'], phase: FeishuOperationState['phase'], authorizationUrl?: string, id = OP): FeishuOperationState {
|
||||
return { id, kind, phase, ...authorizationUrl === undefined ? {} : { authorizationUrl } }
|
||||
@@ -23,11 +24,13 @@ it.each<[string, FeishuState | undefined, ReturnType<typeof presentConnection>]>
|
||||
['an unchecked account', { account: { state: 'unchecked' } }, { phase: 'checking' }],
|
||||
['a check', { ...SIGNED_OUT, operation: operation('check', 'checking') }, { phase: 'checking' }],
|
||||
['no app', { account: { state: 'unconfigured' } }, { phase: 'disconnected', next: 'link-app', failed: false }],
|
||||
['a linked app', SIGNED_OUT, { phase: 'disconnected', next: 'sign-in', failed: false }],
|
||||
['a failed sign-in', { ...SIGNED_OUT, result: { id: OP, kind: 'sign-in', outcome: 'failed' } }, { phase: 'disconnected', next: 'sign-in', failed: true }],
|
||||
['an unconfirmed sign-in', { account: { state: 'unverified' } }, { phase: 'unavailable', failed: false }],
|
||||
['a connection', { account: { state: 'connected', userName: '张三' } }, { phase: 'connected', userName: '张三', ungranted: undefined, failed: false }],
|
||||
['a partial connection', { account: { state: 'connected', ungrantedPermissions: 3 } }, { phase: 'connected', userName: undefined, ungranted: 3, failed: false }],
|
||||
['a linked app', SIGNED_OUT, { phase: 'disconnected', next: 'sign-in', appId: APP, failed: false }],
|
||||
['a failed sign-in', { ...SIGNED_OUT, result: { id: OP, kind: 'sign-in', outcome: 'failed' } }, { phase: 'disconnected', next: 'sign-in', appId: APP, failed: true }],
|
||||
['an unconfirmed sign-in', { account: { state: 'unverified', appId: APP } }, { phase: 'unavailable', appId: APP, failed: false }],
|
||||
['a connection', { account: { state: 'connected', appId: APP, userName: '张三' } },
|
||||
{ phase: 'connected', appId: APP, userName: '张三', ungranted: undefined, failed: false }],
|
||||
['a partial connection', { account: { state: 'connected', appId: APP, ungrantedPermissions: 3 } },
|
||||
{ phase: 'connected', appId: APP, userName: undefined, ungranted: 3, failed: false }],
|
||||
['app setup', { ...SIGNED_OUT, operation: operation('link-app', 'configuring', 'https://open.feishu.cn/x') }, connecting('configuring', 'https://open.feishu.cn/x', true)],
|
||||
['sign-in', { ...SIGNED_OUT, operation: operation('sign-in', 'authorizing') }, connecting('authorizing', undefined, true)],
|
||||
['an app link check', { ...SIGNED_OUT, operation: operation('link-app', 'checking') }, connecting('connecting', undefined, true)],
|
||||
@@ -129,9 +132,9 @@ it('opens each new link of an operation this browser started once, then reports
|
||||
expect(b.open.mock.calls.map(call => call[0])).toEqual(['https://open.feishu.cn/app', 'https://accounts.feishu.cn/device'])
|
||||
b.face.openAuthorization()
|
||||
expect(b.open).toHaveBeenCalledTimes(3)
|
||||
await b.publish({ account: { state: 'connected' }, result: { id: SIGN_IN, kind: 'sign-in', outcome: 'succeeded' } })
|
||||
await b.publish({ account: { state: 'connected', appId: APP }, result: { id: SIGN_IN, kind: 'sign-in', outcome: 'succeeded' } })
|
||||
expect(b.snapshot().notice).toEqual({ seq: 2, kind: 'connected' })
|
||||
await b.publish({ account: { state: 'connected' }, result: { id: SIGN_IN, kind: 'sign-in', outcome: 'succeeded' } })
|
||||
await b.publish({ account: { state: 'connected', appId: APP }, result: { id: SIGN_IN, kind: 'sign-in', outcome: 'succeeded' } })
|
||||
expect(b.snapshot().notice?.seq).toBe(2)
|
||||
b.face.dismissNotice()
|
||||
expect(b.snapshot().notice).toBeUndefined()
|
||||
@@ -142,13 +145,13 @@ it('reports a sign-in that left permissions ungranted', async () => {
|
||||
await b.publish(SIGNED_OUT)
|
||||
b.face.signIn()
|
||||
await settle(b)
|
||||
await b.publish({ account: { state: 'connected', ungrantedPermissions: 2 }, result: { id: OP, kind: 'sign-in', outcome: 'succeeded' } })
|
||||
await b.publish({ account: { state: 'connected', appId: APP, ungrantedPermissions: 2 }, result: { id: OP, kind: 'sign-in', outcome: 'succeeded' } })
|
||||
expect(b.snapshot().notice).toEqual({ seq: 1, kind: 'connected-partially' })
|
||||
})
|
||||
|
||||
it('checks again without a notice', async () => {
|
||||
const b = fixture()
|
||||
await b.publish({ account: { state: 'unverified' } })
|
||||
await b.publish({ account: { state: 'unverified', appId: APP } })
|
||||
b.face.check()
|
||||
await settle(b)
|
||||
expect(b.remote.check).toHaveBeenCalledOnce()
|
||||
@@ -181,15 +184,15 @@ it('starts before the first view and reports no notice for a failed sign-in', as
|
||||
|
||||
it('cancels only a cancellable operation and reports a finished sign-out', async () => {
|
||||
const b = fixture()
|
||||
await b.publish({ account: { state: 'connected' } })
|
||||
await b.publish({ account: { state: 'connected', appId: APP } })
|
||||
b.face.cancel()
|
||||
b.face.openAuthorization()
|
||||
b.face.signOut()
|
||||
await settle(b)
|
||||
await b.publish({ account: { state: 'connected' }, operation: operation('sign-out', 'signing-out') })
|
||||
await b.publish({ account: { state: 'connected', appId: APP }, operation: operation('sign-out', 'signing-out') })
|
||||
b.face.cancel()
|
||||
expect(b.remote.cancel).not.toHaveBeenCalled()
|
||||
await b.publish({ account: { state: 'signed-out' }, result: { id: OP, kind: 'sign-out', outcome: 'succeeded' } })
|
||||
await b.publish({ account: { state: 'signed-out', appId: APP }, result: { id: OP, kind: 'sign-out', outcome: 'succeeded' } })
|
||||
expect(b.snapshot().notice?.kind).toBe('signed-out')
|
||||
await b.publish({ ...SIGNED_OUT, operation: operation('sign-in', 'authorizing') })
|
||||
b.face.cancel()
|
||||
@@ -238,6 +241,6 @@ it('reopens a stopped Host stream on retry and ignores retry while the stream ru
|
||||
await vi.waitFor(() => { expect(b.streams).toHaveLength(2) })
|
||||
expect(b.streams[0]?.dispose).toHaveBeenCalled()
|
||||
expect(b.snapshot()).toMatchObject({ feishu: undefined, stopped: false })
|
||||
await b.publish({ account: { state: 'connected' } })
|
||||
expect(b.snapshot()).toMatchObject({ linked: true, stopped: false, feishu: { account: { state: 'connected' } } })
|
||||
await b.publish({ account: { state: 'connected', appId: APP } })
|
||||
expect(b.snapshot()).toMatchObject({ linked: true, stopped: false, feishu: { account: { state: 'connected', appId: APP } } })
|
||||
})
|
||||
@@ -24,8 +24,8 @@
|
||||
en: f0d233dd69bb21c7
|
||||
zh: 4aedc72d52cd0523
|
||||
/deepseek-ai-dsh-feishu-cli/use-this-package/account-operations:
|
||||
en: 716c1c7b4d477e7d
|
||||
zh: 9915465391457c58
|
||||
en: 080b49fc53d58e33
|
||||
zh: 7312f7d47e930e10
|
||||
/deepseek-ai-dsh-feishu-cli/use-this-package/configure:
|
||||
en: 2aa0db3a03b797f8
|
||||
zh: 6d63b0c12de0b97c
|
||||
|
||||
@@ -44,12 +44,12 @@ The `feishu` Remote serves the Plugins page. It runs at most one account operati
|
||||
|---|---|
|
||||
| `follow(signal)` | Streams the account, the operation in progress, and the last result; each new follower starts a check when no operation runs |
|
||||
| `check()` | Checks the account again; returns the operation id |
|
||||
| `linkApp()` | Runs `config init --new` when no app is configured and keeps an existing app; it does not sign in |
|
||||
| `linkApp()` | Runs `config init --new`, which replaces the CLI's default configuration, including its sign-ins and any other app, with the app the user creates or chooses; it does not sign in |
|
||||
| `signIn()` | Runs `auth login --json` for the linked app and checks that the same user is signed in |
|
||||
| `signOut()` | Runs `auth logout --json`, which also signs out the user's own terminal, then checks again |
|
||||
| `cancel(id)` | Cancels that operation and waits for its command to exit; a finished id is ignored |
|
||||
|
||||
A check runs `auth status --verify --json`. The account reads `connected` only when the CLI reports an available user that its server verified, `signed-out` when the user is missing, not configured, or needs a refresh, `unconfigured` when no app exists, and `unverified` otherwise, for example when verification cannot reach the server. Each link that `config init` prints and each device-authorization link that `auth login` reports is offered only when it is an HTTPS address on `feishu.cn` or `larksuite.com`. A sign-in that leaves requested permissions ungranted (`auth login` exits with code 3 and lists them as missing) still succeeds; the connected account then carries `ungrantedPermissions` for that user until a sign-in grants every permission, another user is signed in, or the user signs out. Results report succeeded, cancelled, or failed; native diagnostics stay on the Host.
|
||||
A check runs `auth status --verify --json`. The account reads `connected` only when the CLI reports an available user that its server verified, `signed-out` when the user is missing, not configured, or needs a refresh, `unconfigured` when no app exists, and `unverified` otherwise, for example when verification cannot reach the server. Every state except `unconfigured` carries the configured `appId`. Each link that `config init` prints and each device-authorization link that `auth login` reports is offered only when it is an HTTPS address on `feishu.cn` or `larksuite.com`. A sign-in that leaves requested permissions ungranted (`auth login` exits with code 3 and lists them as missing) still succeeds; the connected account then carries `ungrantedPermissions` for that user until a sign-in grants every permission, another user is signed in, or the user signs out. Results report succeeded, cancelled, or failed; native diagnostics stay on the Host.
|
||||
|
||||
### Configure
|
||||
|
||||
|
||||
@@ -44,12 +44,12 @@ kind: "package-reference"
|
||||
|---|---|
|
||||
| `follow(signal)` | 推送账号、进行中的操作和最近一次结果;没有操作运行时,每个新订阅者会触发一次检查 |
|
||||
| `check()` | 重新检查账号;返回操作 id |
|
||||
| `linkApp()` | 未配置应用时运行 `config init --new`,已有应用则保留;不会登录 |
|
||||
| `linkApp()` | 运行 `config init --new`,用用户新建或选择的应用替换 CLI 的默认配置,其中的登录和其他应用一并替换;不会登录 |
|
||||
| `signIn()` | 为已关联的应用运行 `auth login --json`,并确认登录的是同一个用户 |
|
||||
| `signOut()` | 运行 `auth logout --json`,同时退出用户自己终端里的登录,然后重新检查 |
|
||||
| `cancel(id)` | 取消该操作并等待其命令退出;已结束的 id 会被忽略 |
|
||||
|
||||
检查运行 `auth status --verify --json`。只有 CLI 报告用户可用且已被服务端核实时,账号才是 `connected`;用户缺失、未配置或需要刷新时为 `signed-out`;没有应用时为 `unconfigured`;其他情况为 `unverified`,例如核实时无法连到服务端。`config init` 打印的链接和 `auth login` 报告的设备授权链接,只有是 `feishu.cn` 或 `larksuite.com` 上的 HTTPS 地址时才会提供。登录后仍有申请的权限未被授予时(`auth login` 以退出码 3 结束并把它们列为缺失),登录仍算成功;此后已连接的账号会带上该用户的 `ungrantedPermissions`,直到某次登录授予了全部权限、换成其他用户登录或用户退出登录。结果分为成功、已取消和失败;原生诊断信息保留在 Host 上。
|
||||
检查运行 `auth status --verify --json`。只有 CLI 报告用户可用且已被服务端核实时,账号才是 `connected`;用户缺失、未配置或需要刷新时为 `signed-out`;没有应用时为 `unconfigured`;其他情况为 `unverified`,例如核实时无法连到服务端。除 `unconfigured` 外,每种状态都带有已配置的 `appId`。`config init` 打印的链接和 `auth login` 报告的设备授权链接,只有是 `feishu.cn` 或 `larksuite.com` 上的 HTTPS 地址时才会提供。登录后仍有申请的权限未被授予时(`auth login` 以退出码 3 结束并把它们列为缺失),登录仍算成功;此后已连接的账号会带上该用户的 `ungrantedPermissions`,直到某次登录授予了全部权限、换成其他用户登录或用户退出登录。结果分为成功、已取消和失败;原生诊断信息保留在 Host 上。
|
||||
|
||||
### 配置
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import { brandString } from '@deepseek-ai/dsh-brand'
|
||||
import z from 'zod'
|
||||
import { assertNever } from '@deepseek-ai/dsh-util-values'
|
||||
import { parseJson, type FeishuCli } from './cli.ts'
|
||||
import type { FeishuAccountState, FeishuOperationId, FeishuOperationResult, FeishuOperationState, FeishuState } from './types.ts'
|
||||
import type { FeishuAccountState, FeishuAppId, FeishuOperationId, FeishuOperationResult, FeishuOperationState, FeishuState } from './types.ts'
|
||||
|
||||
const NotConfigured = z.object({ ok: z.literal(false), error: z.object({ subtype: z.literal('not_configured') }) })
|
||||
const User = z.object({
|
||||
@@ -15,7 +15,7 @@ const User = z.object({
|
||||
userName: z.string().optional(),
|
||||
openId: z.string().optional(),
|
||||
})
|
||||
const Status = z.object({ identities: z.object({ user: User }) })
|
||||
const Status = z.object({ appId: z.string().min(1), identities: z.object({ user: User }) })
|
||||
const LoginLink = z.object({ event: z.literal('device_authorization'), verification_uri_complete: z.string() })
|
||||
const LoginComplete = z.object({ event: z.literal('authorization_complete'), user_open_id: z.string().min(1), missing: z.array(z.string()) })
|
||||
const CONFIG_LINK = /^\s*(https:\/\/\S+)\s*$/u
|
||||
@@ -159,9 +159,11 @@ export class FeishuAccount {
|
||||
}
|
||||
}
|
||||
|
||||
/** Link an app through the CLI's setup page when none is configured; sign-in is a separate operation. */
|
||||
/**
|
||||
* Link an app through the CLI's setup page; sign-in is a separate operation. An existing configuration,
|
||||
* including its sign-ins and any other app, is replaced by the app the user creates or chooses.
|
||||
*/
|
||||
private async linkApp(operation: Operation, signal: AbortSignal): Promise<void> {
|
||||
if ((await this.check(signal)).account.state !== 'unconfigured') return
|
||||
this.stage(operation, 'configuring')
|
||||
const setup = await this.cli.run(['config', 'init', '--new'], signal, {
|
||||
timeoutMs: this.limits.authorizationTimeoutMs,
|
||||
@@ -209,15 +211,18 @@ export class FeishuAccount {
|
||||
this.ungranted = undefined
|
||||
return { account: this.publish({ state: 'unconfigured' }) }
|
||||
}
|
||||
const user = Status.parse(parseJson(args, result.stdout)).identities.user
|
||||
const status = Status.parse(parseJson(args, result.stdout))
|
||||
const appId = brandString<FeishuAppId>(status.appId)
|
||||
const user = status.identities.user
|
||||
if (!user.available || user.verified !== true) {
|
||||
const signedOut = SIGNED_OUT.has(user.status)
|
||||
if (signedOut) this.ungranted = undefined
|
||||
return { account: this.publish({ state: signedOut ? 'signed-out' : 'unverified' }), openId: user.openId }
|
||||
return { account: this.publish({ state: signedOut ? 'signed-out' : 'unverified', appId }), openId: user.openId }
|
||||
}
|
||||
const ungranted = this.ungranted !== undefined && this.ungranted.openId === user.openId ? this.ungranted.count : undefined
|
||||
const account: FeishuAccountState = {
|
||||
state: 'connected',
|
||||
appId,
|
||||
...user.userName === undefined ? {} : { userName: user.userName },
|
||||
...ungranted === undefined ? {} : { ungrantedPermissions: ungranted },
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ export default class Feishu extends TypertRemoteService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Link an app through the CLI's setup page when none is configured; an existing app is kept.
|
||||
* Link an app through the CLI's setup page, replacing a configured app and its sign-ins.
|
||||
* @returns the operation identity.
|
||||
* @throws while another account operation runs.
|
||||
*/
|
||||
|
||||
@@ -5,11 +5,16 @@ import type { Branded } from '@deepseek-ai/dsh-brand'
|
||||
/** Identifies one Host-owned account operation across subscribers. */
|
||||
export type FeishuOperationId = Branded<'FeishuOperationId'>
|
||||
|
||||
/** The Feishu app the CLI's default configuration uses, as `auth status` reports it. */
|
||||
export type FeishuAppId = Branded<'FeishuAppId'>
|
||||
|
||||
/** The CLI's default account as the latest check observed it. */
|
||||
export type FeishuAccountState =
|
||||
| { readonly state: 'unchecked' | 'unconfigured' | 'signed-out' | 'unverified' }
|
||||
| { readonly state: 'unchecked' | 'unconfigured' }
|
||||
| { readonly state: 'signed-out' | 'unverified'; readonly appId: FeishuAppId }
|
||||
| {
|
||||
readonly state: 'connected'
|
||||
readonly appId: FeishuAppId
|
||||
readonly userName?: string
|
||||
/**
|
||||
* Requested permissions the last sign-in on this Host did not grant, which may await an administrator's
|
||||
|
||||
@@ -6,13 +6,14 @@ import * as ShellEnv from '@deepseek-ai/dsh-shell-env'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { FeishuAccount } from '../src/account.ts'
|
||||
import { FeishuCli } from '../src/cli.ts'
|
||||
import Feishu, { type FeishuOperationId, type FeishuState } from '../src/index.ts'
|
||||
import Feishu, { type FeishuAppId, type FeishuOperationId, type FeishuState } from '../src/index.ts'
|
||||
import { createBinDir, ScriptedSubprocess, type CliReply, type ScriptedProcess } from './harness.ts'
|
||||
|
||||
const LIMITS = { commandTimeoutMs: 5_000, authorizationTimeoutMs: 5_000, maxOutputBytes: 1_048_576 }
|
||||
const APP = 'cli_a' as FeishuAppId
|
||||
const STATUS = 'auth status --verify --json'
|
||||
const NOT_CONFIGURED: CliReply = { exitCode: 3, stderr: JSON.stringify({ ok: false, error: { type: 'config', subtype: 'not_configured', message: 'not configured' } }) }
|
||||
const status = (user: Record<string, unknown>): CliReply => ({ stdout: JSON.stringify({ appId: 'cli_a', identities: { user } }) })
|
||||
const status = (user: Record<string, unknown>): CliReply => ({ stdout: JSON.stringify({ appId: APP, identities: { user } }) })
|
||||
const CONNECTED = status({ status: 'ready', available: true, verified: true, userName: '张三', openId: 'ou_1' })
|
||||
const SIGNED_OUT = status({ status: 'missing', available: false })
|
||||
const LOGIN_LINK = JSON.stringify({ event: 'device_authorization', verification_uri_complete: 'https://accounts.feishu.cn/oauth/device?code=1' })
|
||||
@@ -66,11 +67,11 @@ describe('FeishuAccount', () => {
|
||||
|
||||
it.each<[string, CliReply, FeishuState['account']]>([
|
||||
['no app', NOT_CONFIGURED, { state: 'unconfigured' }],
|
||||
['a verified user', CONNECTED, { state: 'connected', userName: '张三' }],
|
||||
['a verified user without a name', status({ status: 'ready', available: true, verified: true }), { state: 'connected' }],
|
||||
['a missing user', SIGNED_OUT, { state: 'signed-out' }],
|
||||
['an expired user', status({ status: 'needs_refresh', available: true, verified: false }), { state: 'signed-out' }],
|
||||
['a failed verification', status({ status: 'verify_failed', available: true, verified: false }), { state: 'unverified' }],
|
||||
['a verified user', CONNECTED, { state: 'connected', appId: APP, userName: '张三' }],
|
||||
['a verified user without a name', status({ status: 'ready', available: true, verified: true }), { state: 'connected', appId: APP }],
|
||||
['a missing user', SIGNED_OUT, { state: 'signed-out', appId: APP }],
|
||||
['an expired user', status({ status: 'needs_refresh', available: true, verified: false }), { state: 'signed-out', appId: APP }],
|
||||
['a failed verification', status({ status: 'verify_failed', available: true, verified: false }), { state: 'unverified', appId: APP }],
|
||||
])('checks %s', async (_name, reply, expected) => {
|
||||
script[STATUS] = [reply]
|
||||
const id = account.start('check')
|
||||
@@ -88,7 +89,7 @@ describe('FeishuAccount', () => {
|
||||
})
|
||||
|
||||
it('links an app through its setup page, offers only a trusted link, and stops before sign-in', async () => {
|
||||
script[STATUS] = [NOT_CONFIGURED, SIGNED_OUT]
|
||||
script[STATUS] = [SIGNED_OUT]
|
||||
const setup = Promise.withResolvers<ScriptedProcess>()
|
||||
script['config init --new'] = (process) => { setup.resolve(process) }
|
||||
|
||||
@@ -99,14 +100,8 @@ describe('FeishuAccount', () => {
|
||||
await vi.waitFor(() => { expect(account.snapshot().operation).toMatchObject({ phase: 'configuring', authorizationUrl: 'https://open.feishu.cn/page/cli?x=2' }) })
|
||||
configuring.reply({})
|
||||
|
||||
expect(await settled(id)).toEqual({ account: { state: 'signed-out' }, result: { id, kind: 'link-app', outcome: 'succeeded' } })
|
||||
expect(commands()).toEqual([STATUS, 'config init --new', STATUS])
|
||||
})
|
||||
|
||||
it('keeps an app that is already linked', async () => {
|
||||
script[STATUS] = [SIGNED_OUT]
|
||||
expect((await settled(account.start('link-app'))).result?.outcome).toBe('succeeded')
|
||||
expect(commands()).toEqual([STATUS])
|
||||
expect(await settled(id)).toEqual({ account: { state: 'signed-out', appId: APP }, result: { id, kind: 'link-app', outcome: 'succeeded' } })
|
||||
expect(commands()).toEqual(['config init --new', STATUS])
|
||||
})
|
||||
|
||||
it('signs in through the authorization page and accepts a sign-in that leaves permissions ungranted', async () => {
|
||||
@@ -123,7 +118,7 @@ describe('FeishuAccount', () => {
|
||||
authorizing.reply({ stdout: login(['im:message']) + '\n', exitCode: 3 })
|
||||
|
||||
expect(await settled(id)).toEqual({
|
||||
account: { state: 'connected', userName: '张三', ungrantedPermissions: 1 },
|
||||
account: { state: 'connected', appId: APP, userName: '张三', ungrantedPermissions: 1 },
|
||||
result: { id, kind: 'sign-in', outcome: 'succeeded' },
|
||||
})
|
||||
expect(commands()).toEqual(['auth login --json', STATUS])
|
||||
@@ -136,14 +131,14 @@ describe('FeishuAccount', () => {
|
||||
script['auth logout --json'] = [{ stdout: '{"ok":true}' }]
|
||||
const account = async (kind: 'check' | 'sign-in' | 'sign-out') => (await settled(start(kind))).account
|
||||
|
||||
expect(await account('sign-in')).toEqual({ state: 'connected', userName: '张三', ungrantedPermissions: 2 })
|
||||
expect(await account('check')).toEqual({ state: 'connected', userName: '张三', ungrantedPermissions: 2 })
|
||||
expect(await account('check')).toEqual({ state: 'connected' })
|
||||
expect(await account('check')).toEqual({ state: 'connected', userName: '张三', ungrantedPermissions: 2 })
|
||||
expect(await account('sign-in')).toEqual({ state: 'connected', appId: APP, userName: '张三', ungrantedPermissions: 2 })
|
||||
expect(await account('check')).toEqual({ state: 'connected', appId: APP, userName: '张三', ungrantedPermissions: 2 })
|
||||
expect(await account('check')).toEqual({ state: 'connected', appId: APP })
|
||||
expect(await account('check')).toEqual({ state: 'connected', appId: APP, userName: '张三', ungrantedPermissions: 2 })
|
||||
script['auth login --json'] = [{ stdout: login(['im:message']) + '\n', exitCode: 3 }]
|
||||
expect(await account('sign-in')).toEqual({ state: 'connected', userName: '张三', ungrantedPermissions: 1 })
|
||||
expect(await account('sign-out')).toEqual({ state: 'signed-out' })
|
||||
expect(await account('check')).toEqual({ state: 'connected', userName: '张三' })
|
||||
expect(await account('sign-in')).toEqual({ state: 'connected', appId: APP, userName: '张三', ungrantedPermissions: 1 })
|
||||
expect(await account('sign-out')).toEqual({ state: 'signed-out', appId: APP })
|
||||
expect(await account('check')).toEqual({ state: 'connected', appId: APP, userName: '张三' })
|
||||
})
|
||||
|
||||
it('drops the ungranted count when the CLI has no app', async () => {
|
||||
@@ -151,12 +146,12 @@ describe('FeishuAccount', () => {
|
||||
script['auth login --json'] = [{ stdout: login(['im:message']) + '\n', exitCode: 3 }]
|
||||
expect((await settled(start('sign-in'))).account).toMatchObject({ ungrantedPermissions: 1 })
|
||||
expect((await settled(start('check'))).account).toEqual({ state: 'unconfigured' })
|
||||
expect((await settled(start('check'))).account).toEqual({ state: 'connected', userName: '张三' })
|
||||
expect((await settled(start('check'))).account).toEqual({ state: 'connected', appId: APP, userName: '张三' })
|
||||
})
|
||||
|
||||
it.each<[string, 'link-app' | 'sign-in', Record<string, CliReply[]>]>([
|
||||
['a failed app setup', 'link-app', { [STATUS]: [NOT_CONFIGURED], 'config init --new': [{ exitCode: 1 }] }],
|
||||
['an app setup that left no app', 'link-app', { [STATUS]: [NOT_CONFIGURED, NOT_CONFIGURED], 'config init --new': [{}] }],
|
||||
['a failed app setup', 'link-app', { 'config init --new': [{ exitCode: 1 }] }],
|
||||
['an app setup that left no app', 'link-app', { [STATUS]: [NOT_CONFIGURED], 'config init --new': [{}] }],
|
||||
['a sign-in without completion', 'sign-in', { 'auth login --json': [{ stdout: LOGIN_LINK + '\n' }] }],
|
||||
['a failed sign-in', 'sign-in', { 'auth login --json': [{ stdout: login() + '\n', exitCode: 1 }] }],
|
||||
['a partial sign-in that reports no missing permission', 'sign-in', { 'auth login --json': [{ stdout: login() + '\n', exitCode: 3 }] }],
|
||||
@@ -205,7 +200,7 @@ describe('FeishuAccount', () => {
|
||||
script['auth logout --json'] = [{ stdout: '{"ok":true}' }, { exitCode: 1 }]
|
||||
const id = account.start('sign-out')
|
||||
expect(account.snapshot().operation?.phase).toBe('signing-out')
|
||||
expect(await settled(id)).toEqual({ account: { state: 'signed-out' }, result: { id, kind: 'sign-out', outcome: 'succeeded' } })
|
||||
expect(await settled(id)).toEqual({ account: { state: 'signed-out', appId: APP }, result: { id, kind: 'sign-out', outcome: 'succeeded' } })
|
||||
expect((await settled(account.start('sign-out'))).result).toMatchObject({ kind: 'sign-out', outcome: 'failed' })
|
||||
})
|
||||
|
||||
|
||||
@@ -1171,7 +1171,7 @@ export const SERVICE_API: readonly ServiceApiEntry[] = [
|
||||
},
|
||||
{
|
||||
signature: '@Remote linkApp(): FeishuOperationId',
|
||||
description: 'Link an app through the CLI\'s setup page when none is configured; an existing app is kept.',
|
||||
description: 'Link an app through the CLI\'s setup page, replacing a configured app and its sign-ins.',
|
||||
parameters: [],
|
||||
returns: 'the operation identity.',
|
||||
throws: ['while another account operation runs.'],
|
||||
@@ -6185,7 +6185,11 @@ export const TYPE_API: readonly TypeApiEntry[] = [
|
||||
},
|
||||
{
|
||||
name: 'FeishuAccountState',
|
||||
declaration: 'export type FeishuAccountState = {\n readonly state: \'unchecked\' | \'unconfigured\' | \'signed-out\' | \'unverified\';\n} | {\n readonly state: \'connected\';\n readonly userName?: string;\n readonly ungrantedPermissions?: number;\n};',
|
||||
declaration: 'export type FeishuAccountState = {\n readonly state: \'unchecked\' | \'unconfigured\';\n} | {\n readonly state: \'signed-out\' | \'unverified\';\n readonly appId: FeishuAppId;\n} | {\n readonly state: \'connected\';\n readonly appId: FeishuAppId;\n readonly userName?: string;\n readonly ungrantedPermissions?: number;\n};',
|
||||
},
|
||||
{
|
||||
name: 'FeishuAppId',
|
||||
declaration: 'export type FeishuAppId = Branded<\'FeishuAppId\'>;',
|
||||
},
|
||||
{
|
||||
name: 'FeishuOperationId',
|
||||
|
||||
Reference in new issue
Block a user