From edb5c523ec3ad3cdecc01394d85b380e053fe54d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E6=A3=AE?= Date: Sat, 23 Dec 2023 14:45:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=85=BC=E5=AE=B9=20AuthCredential=20?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/dingtalk-auth/package.json | 4 +- .../dingtalk-auth/review/dingtalk-auth.api.md | 4 + .../src/credentials/CorpAuthCredential.ts | 8 + packages/dingtalk-event-hubs/package.json | 2 +- .../review/dingtalk-event-hubs.api.md | 176 ++++++++++++++++++ packages/dingtalk-event-hubs/src/HttpLink.ts | 10 +- packages/dingtalk/package.json | 4 +- packages/dingtalk/review/dingtalk.api.md | 108 +++++++++++ packages/dingtalk/src/index.ts | 8 +- packages/wechaty-puppet-dingtalk/package.json | 4 +- .../review/wechaty-puppet-dingtalk.api.md | 86 ++++++--- 11 files changed, 371 insertions(+), 43 deletions(-) create mode 100644 packages/dingtalk-event-hubs/review/dingtalk-event-hubs.api.md create mode 100644 packages/dingtalk/review/dingtalk.api.md diff --git a/packages/dingtalk-auth/package.json b/packages/dingtalk-auth/package.json index 1ecadd2..8df7f03 100644 --- a/packages/dingtalk-auth/package.json +++ b/packages/dingtalk-auth/package.json @@ -1,6 +1,6 @@ { "name": "@zhengxs/dingtalk-auth", - "version": "0.0.1-beta.0", + "version": "0.0.1-beta.1", "description": "", "keywords": [ "dingtalk", @@ -30,7 +30,7 @@ "extract-api": "mkdirp ./review && api-extractor run --local" }, "dependencies": { - "@zhengxs/http": "^0.0.1-rc.5" + "@zhengxs/http": "^0.0.1-rc.6" }, "publishConfig": { "access": "public", diff --git a/packages/dingtalk-auth/review/dingtalk-auth.api.md b/packages/dingtalk-auth/review/dingtalk-auth.api.md index bc237db..921be2d 100644 --- a/packages/dingtalk-auth/review/dingtalk-auth.api.md +++ b/packages/dingtalk-auth/review/dingtalk-auth.api.md @@ -47,6 +47,10 @@ export class CorpAuthCredential extends TokenSessionCredential; // (undocumented) suiteKey?: string; diff --git a/packages/dingtalk-auth/src/credentials/CorpAuthCredential.ts b/packages/dingtalk-auth/src/credentials/CorpAuthCredential.ts index 1c63560..fa7e9b6 100644 --- a/packages/dingtalk-auth/src/credentials/CorpAuthCredential.ts +++ b/packages/dingtalk-auth/src/credentials/CorpAuthCredential.ts @@ -23,6 +23,14 @@ export class CorpAuthCredential extends TokenSessionCredential { const { suiteKey = this.suiteKey, diff --git a/packages/dingtalk-event-hubs/package.json b/packages/dingtalk-event-hubs/package.json index bedc409..f1b7883 100644 --- a/packages/dingtalk-event-hubs/package.json +++ b/packages/dingtalk-event-hubs/package.json @@ -1,6 +1,6 @@ { "name": "@zhengxs/dingtalk-event-hubs", - "version": "0.0.1-beta.0", + "version": "0.0.1-beta.1", "description": "", "keywords": [ "dingtalk", diff --git a/packages/dingtalk-event-hubs/review/dingtalk-event-hubs.api.md b/packages/dingtalk-event-hubs/review/dingtalk-event-hubs.api.md new file mode 100644 index 0000000..8bd273e --- /dev/null +++ b/packages/dingtalk-event-hubs/review/dingtalk-event-hubs.api.md @@ -0,0 +1,176 @@ +## API Report File for "@zhengxs/dingtalk-event-hubs" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts +import { AuthCredential } from '@zhengxs/dingtalk-auth'; +import { CorpAuthCredential } from '@zhengxs/dingtalk-auth'; +import { IdentityClient } from '@zhengxs/dingtalk-auth'; + +// @public (undocumented) +export type ConnectionParamsOptions = { + ua?: string; + subscriptions?: OperationOption[]; +}; + +// @public (undocumented) +export function createHttpLink({ client, credential, ...rest }: Required): Promise; + +// @public (undocumented) +export type EffectCleanup = () => void; + +// @public (undocumented) +export interface GraphAPIResponse { + // (undocumented) + response: { + statusLine?: { + code?: number; + reasonPhrase?: string; + }; + headers?: Record; + body?: string; + }; +} + +// @public (undocumented) +export class HttpLink { + constructor(options: HttpLinkOptions); + // (undocumented) + protected client: IdentityClient; + // (undocumented) + create(): Promise; + // (undocumented) + protected credential: AuthCredential | CorpAuthCredential; + // (undocumented) + protected subscriptions: OperationOption[]; + // (undocumented) + protected ua: string; +} + +// @public (undocumented) +export interface HttpLinkOptions extends ConnectionParamsOptions { + // (undocumented) + client?: IdentityClient; + // (undocumented) + credential?: AuthCredential | CorpAuthCredential; +} + +// @public (undocumented) +export class HubConnection { + constructor(options: HubConnectionOptions, webSocketImpl?: typeof globalThis.WebSocket); + // (undocumented) + protected buildMessage(id: string, payload: NonNullable): SendMessage; + // (undocumented) + close(isForced?: boolean, closedByUser?: boolean): void; + // (undocumented) + protected connect(): void; + emit(message: SendMessage): void; + // (undocumented) + protected httpLink?: HttpLink; + invoke(id: string, data: unknown): void; + // (undocumented) + on(eventName: string | symbol, listener: (...args: any[]) => void): () => void; + // (undocumented) + protected processCallbacks(event: ParsedEvent): void; + // (undocumented) + protected processReceivedData(receivedData: string): void; + // (undocumented) + protected processSystemEvent(event: ParsedEvent): void; + send(id: string, payload: NonNullable): void; + // (undocumented) + start(): Promise; + // (undocumented) + get status(): number; + // (undocumented) + protected url?: string; +} + +// @public (undocumented) +export class HubConnectionBuilder { + // (undocumented) + build(options?: HubConnectionOptions): HubConnection; + // (undocumented) + protected httpLink?: HttpLink; + // (undocumented) + protected url?: string; + // (undocumented) + withClient(client: IdentityClient, options?: ConnectionParamsOptions): HubConnectionBuilder; + // (undocumented) + withCredential(credential: AuthCredential, options?: ConnectionParamsOptions): HubConnectionBuilder; + // (undocumented) + withUrl(url: string): HubConnectionBuilder; +} + +// @public (undocumented) +export interface HubConnectionOptions { + // (undocumented) + httpLink?: HttpLink; + // (undocumented) + lazy?: boolean; + // (undocumented) + minTimeout?: number; + // (undocumented) + reconnect?: boolean; + // (undocumented) + reconnectionAttempts?: number; + // (undocumented) + timeout?: number; + // (undocumented) + url?: string; +} + +// @public (undocumented) +export interface Operation { + // (undocumented) + handler: Operation.Handler; + // (undocumented) + options: Operation.Option[]; +} + +// @public (undocumented) +export namespace Operation { + // (undocumented) + export type Handler = (event: ParsedEvent) => void; + // (undocumented) + export type Option = { + type: OperationType; + topic: (NonNullable & string) | '*'; + }; +} + +// @public (undocumented) +export type OperationOption = Operation.Option; + +// @public (undocumented) +export type OperationType = 'EVENT' | 'SYSTEM' | 'CALLBACK'; + +// @public (undocumented) +export type ParsedEvent = { + specVersion: string; + type: OperationType; + headers: { + appId: string; + connectionId: string; + IncomingType: string; + messageId: string; + time: string; + topic: string; + eventType?: string; + eventBornTime?: string; + eventId?: string; + eventCorpId?: string; + eventUnifiedAppId?: string; + }; + data: string; +}; + +// @public (undocumented) +export type SendMessage = { + code?: number; + message?: string; + headers: Record; + data: string; +}; + +// (No @packageDocumentation comment for this package) +``` diff --git a/packages/dingtalk-event-hubs/src/HttpLink.ts b/packages/dingtalk-event-hubs/src/HttpLink.ts index 6d6af26..08073d0 100644 --- a/packages/dingtalk-event-hubs/src/HttpLink.ts +++ b/packages/dingtalk-event-hubs/src/HttpLink.ts @@ -1,4 +1,4 @@ -import { AuthCredential, IdentityClient } from '@zhengxs/dingtalk-auth'; +import { AuthCredential, CorpAuthCredential, IdentityClient } from '@zhengxs/dingtalk-auth'; import type { ConnectionParamsOptions, OperationOption } from './types'; @@ -17,13 +17,13 @@ const defaultConnectionParams: ConnectionParamsOptions = { }; export interface HttpLinkOptions extends ConnectionParamsOptions { - client?: IdentityClient; - credential?: AuthCredential; + client?: IdentityClient; + credential?: AuthCredential | CorpAuthCredential; } export class HttpLink { - protected client: IdentityClient; - protected credential: AuthCredential; + protected client: IdentityClient; + protected credential: AuthCredential | CorpAuthCredential; protected ua: string; protected subscriptions: OperationOption[]; diff --git a/packages/dingtalk/package.json b/packages/dingtalk/package.json index 748df97..4c7c46b 100644 --- a/packages/dingtalk/package.json +++ b/packages/dingtalk/package.json @@ -1,6 +1,6 @@ { "name": "@zhengxs/dingtalk", - "version": "0.0.1-beta.1", + "version": "0.0.1-beta.2", "description": "", "keywords": [ "dingtalk" @@ -30,7 +30,7 @@ }, "dependencies": { "@zhengxs/dingtalk-auth": "workspace:^", - "@zhengxs/http": "^0.0.1-rc.5" + "@zhengxs/http": "^0.0.1-rc.6" }, "publishConfig": { "access": "public", diff --git a/packages/dingtalk/review/dingtalk.api.md b/packages/dingtalk/review/dingtalk.api.md new file mode 100644 index 0000000..25eb213 --- /dev/null +++ b/packages/dingtalk/review/dingtalk.api.md @@ -0,0 +1,108 @@ +## API Report File for "@zhengxs/dingtalk" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts +import { AuthCredential } from '@zhengxs/dingtalk-auth'; +import { CorpAuthCredential } from '@zhengxs/dingtalk-auth'; +import { IdentityClient } from '@zhengxs/dingtalk-auth'; +import { IdentityClientOptions } from '@zhengxs/dingtalk-auth'; +import { APIConnectionError } from '@zhengxs/http'; +import { APIConnectionTimeoutError } from '@zhengxs/http'; +import { APIError } from '@zhengxs/http'; +import { APIPromise } from '@zhengxs/http'; +import { APIUserAbortError } from '@zhengxs/http'; +import { AuthenticationError } from '@zhengxs/http'; +import { BadRequestError } from '@zhengxs/http'; +import { ConflictError } from '@zhengxs/http'; +import { HttpException as DingtalkError } from '@zhengxs/http'; +import { InternalServerError } from '@zhengxs/http'; +import { NotFoundError } from '@zhengxs/http'; +import { PermissionDeniedError } from '@zhengxs/http'; +import { RateLimitError } from '@zhengxs/http'; +import { RequestOptions } from '@zhengxs/http'; +import { UnprocessableEntityError } from '@zhengxs/http'; +import { Uploadable } from '@zhengxs/http'; + +export { APIConnectionError }; + +export { APIConnectionTimeoutError }; + +export { APIError }; + +export { APIUserAbortError }; + +export { AuthenticationError }; + +export { BadRequestError }; + +export { ConflictError }; + +// @public (undocumented) +class Dingtalk extends IdentityClient { + // (undocumented) + static APIConnectionError: typeof APIConnectionError; + // (undocumented) + static APIConnectionTimeoutError: typeof APIConnectionTimeoutError; + // (undocumented) + static APIError: typeof APIError; + // (undocumented) + static APIUserAbortError: typeof APIUserAbortError; + // (undocumented) + static AuthenticationError: typeof AuthenticationError; + // (undocumented) + static BadRequestError: typeof BadRequestError; + // (undocumented) + static ConflictError: typeof ConflictError; + // (undocumented) + static Dingtalk: typeof Dingtalk; + // (undocumented) + static DingtalkError: typeof DingtalkError; + // (undocumented) + files: API.Files; + // (undocumented) + static InternalServerError: typeof InternalServerError; + // (undocumented) + static NotFoundError: typeof NotFoundError; + // (undocumented) + static PermissionDeniedError: typeof PermissionDeniedError; + // (undocumented) + static RateLimitError: typeof RateLimitError; + // Warning: (ae-forgotten-export) The symbol "API" needs to be exported by the entry point index.d.ts + // + // (undocumented) + robots: API.Robots; + // (undocumented) + static UnprocessableEntityError: typeof UnprocessableEntityError; +} + +// @public (undocumented) +namespace Dingtalk { + // (undocumented) + type Files = API.Files; + // (undocumented) + type Robots = API.Robots; +} +export { Dingtalk }; +export default Dingtalk; + +// @public (undocumented) +export type DingtalkCredential = AuthCredential | CorpAuthCredential; + +export { DingtalkError }; + +// @public (undocumented) +export type DingtalkOptions = IdentityClientOptions; + +export { InternalServerError }; + +export { NotFoundError }; + +export { PermissionDeniedError }; + +export { RateLimitError }; + +export { UnprocessableEntityError }; + +// (No @packageDocumentation comment for this package) +``` diff --git a/packages/dingtalk/src/index.ts b/packages/dingtalk/src/index.ts index 4311c8e..a33929b 100644 --- a/packages/dingtalk/src/index.ts +++ b/packages/dingtalk/src/index.ts @@ -1,4 +1,4 @@ -import { AuthCredential, IdentityClient, type IdentityClientOptions } from '@zhengxs/dingtalk-auth'; +import { AuthCredential, CorpAuthCredential, IdentityClient, type IdentityClientOptions } from '@zhengxs/dingtalk-auth'; import { APIConnectionError, APIConnectionTimeoutError, @@ -17,10 +17,12 @@ import { import * as API from './resources'; -export type DingtalkOptions = IdentityClientOptions; +export type DingtalkCredential = AuthCredential | CorpAuthCredential; + +export type DingtalkOptions = IdentityClientOptions; // TODO: 支持 CorpAuthCredential 第三方应用 -export class Dingtalk extends IdentityClient { +export class Dingtalk extends IdentityClient { robots = new API.Robots(this); files: API.Files = new API.Files(this); diff --git a/packages/wechaty-puppet-dingtalk/package.json b/packages/wechaty-puppet-dingtalk/package.json index 76e68a4..8381594 100644 --- a/packages/wechaty-puppet-dingtalk/package.json +++ b/packages/wechaty-puppet-dingtalk/package.json @@ -1,6 +1,6 @@ { "name": "@zhengxs/wechaty-puppet-dingtalk", - "version": "0.0.1-beta.6", + "version": "0.0.1-beta.7", "description": "", "sideEffect": false, "main": "./dist/index.cjs", @@ -30,7 +30,7 @@ "@zhengxs/dingtalk": "workspace:^", "@zhengxs/dingtalk-auth": "workspace:^", "@zhengxs/dingtalk-event-hubs": "workspace:^", - "@zhengxs/http": "^0.0.1-rc.5", + "@zhengxs/http": "^0.0.1-rc.6", "agentkeepalive": "^4.5.0", "file-box": "^1.4.15", "form-data-encoder": "^4.0.2", diff --git a/packages/wechaty-puppet-dingtalk/review/wechaty-puppet-dingtalk.api.md b/packages/wechaty-puppet-dingtalk/review/wechaty-puppet-dingtalk.api.md index b18ce5e..9f5b26b 100644 --- a/packages/wechaty-puppet-dingtalk/review/wechaty-puppet-dingtalk.api.md +++ b/packages/wechaty-puppet-dingtalk/review/wechaty-puppet-dingtalk.api.md @@ -7,6 +7,7 @@ import { Dingtalk } from '@zhengxs/dingtalk'; import { AuthCredential } from '@zhengxs/dingtalk-auth'; import { HubConnection } from '@zhengxs/dingtalk-event-hubs'; import { FileBoxInterface } from 'file-box'; +import Keyv from 'keyv'; import * as PUPPET from 'wechaty-puppet'; // @public (undocumented) @@ -59,16 +60,28 @@ export interface DTAudioMessageRawPayload extends DTMessageRawPayloadBase { } // @public (undocumented) -export interface DTContactRawPayload extends DTSessionWebhookRawPayload { +export interface DTContactRawPayload { + avatar: string; corpId: string; id: string; name: string; + sessionWebhook: string; + sessionWebhookExpiredTime: number; staffId?: string; + type: DTContactType; } // @public (undocumented) export function dtContactToWechaty(_: PUPPET.Puppet, payload: DTContactRawPayload): Promise; +// @public (undocumented) +export enum DTContactType { + // (undocumented) + Robot = 1, + // (undocumented) + User = 2, +} + // @public (undocumented) export interface DTFileMessageRawPayload extends DTMessageRawPayloadBase { // (undocumented) @@ -186,23 +199,21 @@ export interface DTRichTextMessageRawPayload extends DTMessageRawPayloadBase { export function dtRoomMemberToWechaty(rawPayload: DTContactRawPayload): PUPPET.payloads.RoomMember; // @public (undocumented) -export interface DTRoomRawPayload extends DTSessionWebhookRawPayload { - // (undocumented) - conversationId: string; - // (undocumented) - conversationTitle?: string; - // (undocumented) - memberList: DTContactRawPayload[]; +export interface DTRoomRawPayload extends PUPPET.payloads.Room { + sessionWebhook: string; + sessionWebhookExpiredTime: number; } // @public (undocumented) export function dtRoomToWechaty(_: PUPPET.Puppet, payload: DTRoomRawPayload): Promise; -// @public (undocumented) +// @public export interface DTSessionWebhookRawPayload { - // (undocumented) + chatbotUserId: string; + conversationId: string; + msgId: string; + senderId: string; sessionWebhook: string; - // (undocumented) sessionWebhookExpiredTime: number; } @@ -268,11 +279,14 @@ export type FileMessagePayload = { }; }; +// @public +export type GetMediaDurationInSeconds = (fileBox: FileBoxInterface) => Promise; + // @public (undocumented) export type ImageMessagePayload = { - msgtype: 'picture'; + msgtype: 'image'; image: { - photoURL: string; + picURL: string; }; }; @@ -331,17 +345,23 @@ export enum MessageType { export class PuppetDingTalk extends PUPPET.Puppet { constructor(options?: PuppetDingTalkOptions); // (undocumented) - protected client: Dingtalk; - // (undocumented) - protected connection?: HubConnection; + protected _clearCacheAfterLogout: boolean; // (undocumented) - contactRawPayload(contactId: string): Promise; + contactRawPayload(contactId: string): Promise; // (undocumented) contactRawPayloadParser(rawPayload: DTContactRawPayload): Promise; // (undocumented) - protected contacts: Map; + protected _contactsStore: Keyv; + // (undocumented) + protected _dkClient: Dingtalk; + // (undocumented) + protected _dkConnection?: HubConnection; + // (undocumented) + protected _dkCredential: AuthCredential; // (undocumented) - protected credential: AuthCredential; + protected _getAudioDurationInSeconds: GetMediaDurationInSeconds; + // (undocumented) + protected _getVideoDurationInSeconds: GetMediaDurationInSeconds; // (undocumented) messageFile(messageId: string): Promise; // (undocumented) @@ -351,8 +371,6 @@ export class PuppetDingTalk extends PUPPET.Puppet { // (undocumented) messageRawPayloadParser(rawPayload: DTMessageRawPayload): Promise; // (undocumented) - protected messages: Map; - // (undocumented) messageSendFile(conversationId: string, fileBox: FileBoxInterface): Promise; // (undocumented) messageSendText( @@ -363,13 +381,15 @@ export class PuppetDingTalk extends PUPPET.Puppet { // (undocumented) messageSendUrl(conversationId: string, urlLinkPayload: PUPPET.payloads.UrlLink | MessagePayload): Promise; // (undocumented) + protected _messagesStore: Keyv; + // (undocumented) onStart(): Promise; // (undocumented) onStop(): Promise; // (undocumented) roomMemberList(roomId: string): Promise; // (undocumented) - roomMemberRawPayload(roomId: string, contactId: string): Promise; + roomMemberRawPayload(roomId: string, contactId: string): Promise; // (undocumented) roomMemberRawPayloadParser(rawPayload: DTContactRawPayload): Promise; // (undocumented) @@ -377,17 +397,27 @@ export class PuppetDingTalk extends PUPPET.Puppet { // (undocumented) roomRawPayloadParser(rawPayload: DTRoomRawPayload): Promise; // (undocumented) - protected rooms: Map; + protected _roomsStore: Keyv; + // (undocumented) + protected _sessionWebhooksStore: Keyv; + // (undocumented) + protected unstable_defaultGetAudioDurationInSeconds: GetMediaDurationInSeconds; + // (undocumented) + protected unstable_defaultGetVideoDurationInSeconds: GetMediaDurationInSeconds; } // @public (undocumented) export interface PuppetDingTalkOptions extends PUPPET.PuppetOptions { - // (undocumented) + clearCacheAfterLogout?: boolean; clientId?: string; - // (undocumented) clientSecret?: string; - // (undocumented) + contactsStore?: Keyv; credential?: AuthCredential; + getAudioDurationInSeconds?: GetMediaDurationInSeconds; + getVideoDurationInSeconds?: GetMediaDurationInSeconds; + messagesStore?: Keyv; + roomsStore?: Keyv; + sessionWebhooksStore?: Keyv; } // @public (undocumented) @@ -411,7 +441,7 @@ export class SayableSayer extends Sender { // @public (undocumented) export class Sender { - constructor(url: string, expiredTime: number); + constructor(url: string, expiredTime?: number); // (undocumented) protected expiredTime: number; // (undocumented) @@ -445,7 +475,7 @@ export type VideoMessagePayload = { picMediaId: string; videoMediaId: string; videoType: string; - duration: string; + duration: string | number; width?: string; height?: string; };