Skip to content

Commit

Permalink
feat: 兼容 AuthCredential 实现
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengxs2018 committed Dec 23, 2023
1 parent 1109cd5 commit edb5c52
Show file tree
Hide file tree
Showing 11 changed files with 371 additions and 43 deletions.
4 changes: 2 additions & 2 deletions packages/dingtalk-auth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zhengxs/dingtalk-auth",
"version": "0.0.1-beta.0",
"version": "0.0.1-beta.1",
"description": "",
"keywords": [
"dingtalk",
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions packages/dingtalk-auth/review/dingtalk-auth.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export class CorpAuthCredential extends TokenSessionCredential<CorpAuthGetTokenP
// (undocumented)
authCorpId?: string;
// (undocumented)
get clientId(): string | undefined;
// (undocumented)
get clientSecret(): string | undefined;
// (undocumented)
protected request(params: CorpAuthGetTokenParams): Promise<TokenResponse>;
// (undocumented)
suiteKey?: string;
Expand Down
8 changes: 8 additions & 0 deletions packages/dingtalk-auth/src/credentials/CorpAuthCredential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ export class CorpAuthCredential extends TokenSessionCredential<CorpAuthGetTokenP
this.suiteTicket = suiteTicket;
}

get clientId(): string | undefined {
return this.suiteKey;
}

get clientSecret(): string | undefined {
return this.suiteSecret;
}

protected override request(params: CorpAuthGetTokenParams): Promise<TokenResponse> {
const {
suiteKey = this.suiteKey,
Expand Down
2 changes: 1 addition & 1 deletion packages/dingtalk-event-hubs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zhengxs/dingtalk-event-hubs",
"version": "0.0.1-beta.0",
"version": "0.0.1-beta.1",
"description": "",
"keywords": [
"dingtalk",
Expand Down
176 changes: 176 additions & 0 deletions packages/dingtalk-event-hubs/review/dingtalk-event-hubs.api.md
Original file line number Diff line number Diff line change
@@ -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<HttpLinkOptions>): Promise<string>;

// @public (undocumented)
export type EffectCleanup = () => void;

// @public (undocumented)
export interface GraphAPIResponse {
// (undocumented)
response: {
statusLine?: {
code?: number;
reasonPhrase?: string;
};
headers?: Record<string, string>;
body?: string;
};
}

// @public (undocumented)
export class HttpLink {
constructor(options: HttpLinkOptions);
// (undocumented)
protected client: IdentityClient<AuthCredential | CorpAuthCredential>;
// (undocumented)
create(): Promise<string>;
// (undocumented)
protected credential: AuthCredential | CorpAuthCredential;
// (undocumented)
protected subscriptions: OperationOption[];
// (undocumented)
protected ua: string;
}

// @public (undocumented)
export interface HttpLinkOptions extends ConnectionParamsOptions {
// (undocumented)
client?: IdentityClient<AuthCredential | CorpAuthCredential>;
// (undocumented)
credential?: AuthCredential | CorpAuthCredential;
}

// @public (undocumented)
export class HubConnection {
constructor(options: HubConnectionOptions, webSocketImpl?: typeof globalThis.WebSocket);
// (undocumented)
protected buildMessage(id: string, payload: NonNullable<unknown>): 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<unknown>): void;
// (undocumented)
start(): Promise<void>;
// (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<AuthCredential>, 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<unknown> & 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<string, string>;
data: string;
};

// (No @packageDocumentation comment for this package)
```
10 changes: 5 additions & 5 deletions packages/dingtalk-event-hubs/src/HttpLink.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -17,13 +17,13 @@ const defaultConnectionParams: ConnectionParamsOptions = {
};

export interface HttpLinkOptions extends ConnectionParamsOptions {
client?: IdentityClient<AuthCredential>;
credential?: AuthCredential;
client?: IdentityClient<AuthCredential | CorpAuthCredential>;
credential?: AuthCredential | CorpAuthCredential;
}

export class HttpLink {
protected client: IdentityClient<AuthCredential>;
protected credential: AuthCredential;
protected client: IdentityClient<AuthCredential | CorpAuthCredential>;
protected credential: AuthCredential | CorpAuthCredential;

protected ua: string;
protected subscriptions: OperationOption[];
Expand Down
4 changes: 2 additions & 2 deletions packages/dingtalk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zhengxs/dingtalk",
"version": "0.0.1-beta.1",
"version": "0.0.1-beta.2",
"description": "",
"keywords": [
"dingtalk"
Expand Down Expand Up @@ -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",
Expand Down
108 changes: 108 additions & 0 deletions packages/dingtalk/review/dingtalk.api.md
Original file line number Diff line number Diff line change
@@ -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<DingtalkCredential> {
// (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<DingtalkCredential>;

export { InternalServerError };

export { NotFoundError };

export { PermissionDeniedError };

export { RateLimitError };

export { UnprocessableEntityError };

// (No @packageDocumentation comment for this package)
```
8 changes: 5 additions & 3 deletions packages/dingtalk/src/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -17,10 +17,12 @@ import {

import * as API from './resources';

export type DingtalkOptions = IdentityClientOptions<AuthCredential>;
export type DingtalkCredential = AuthCredential | CorpAuthCredential;

export type DingtalkOptions = IdentityClientOptions<DingtalkCredential>;

// TODO: 支持 CorpAuthCredential 第三方应用
export class Dingtalk extends IdentityClient<AuthCredential> {
export class Dingtalk extends IdentityClient<DingtalkCredential> {
robots = new API.Robots(this);

files: API.Files = new API.Files(this);
Expand Down
Loading

0 comments on commit edb5c52

Please sign in to comment.