@holocronlab/botruntime-chat 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +8 -0
- package/README.md +64 -0
- package/dist/client.d.ts +363 -0
- package/dist/consts.d.ts +1 -0
- package/dist/errors.d.ts +20 -0
- package/dist/event-emitter.d.ts +10 -0
- package/dist/eventsource.d.ts +32 -0
- package/dist/gen/client/errors.d.ts +229 -0
- package/dist/gen/client/index.d.ts +77 -0
- package/dist/gen/client/models.d.ts +212 -0
- package/dist/gen/client/operations/addParticipant.d.ts +55 -0
- package/dist/gen/client/operations/createConversation.d.ts +39 -0
- package/dist/gen/client/operations/createEvent.d.ts +55 -0
- package/dist/gen/client/operations/createMessage.d.ts +294 -0
- package/dist/gen/client/operations/createUser.d.ts +66 -0
- package/dist/gen/client/operations/deleteConversation.d.ts +22 -0
- package/dist/gen/client/operations/deleteMessage.d.ts +22 -0
- package/dist/gen/client/operations/deleteUser.d.ts +21 -0
- package/dist/gen/client/operations/getConversation.d.ts +36 -0
- package/dist/gen/client/operations/getEvent.d.ts +46 -0
- package/dist/gen/client/operations/getMessage.d.ts +167 -0
- package/dist/gen/client/operations/getOrCreateConversation.d.ts +39 -0
- package/dist/gen/client/operations/getOrCreateUser.d.ts +62 -0
- package/dist/gen/client/operations/getParticipant.d.ts +52 -0
- package/dist/gen/client/operations/getUser.d.ts +50 -0
- package/dist/gen/client/operations/listConversations.d.ts +42 -0
- package/dist/gen/client/operations/listMessages.d.ts +171 -0
- package/dist/gen/client/operations/listParticipants.d.ts +55 -0
- package/dist/gen/client/operations/listenConversation.d.ts +22 -0
- package/dist/gen/client/operations/removeParticipant.d.ts +23 -0
- package/dist/gen/client/operations/updateUser.d.ts +62 -0
- package/dist/gen/client/to-axios.d.ts +16 -0
- package/dist/gen/signals/eventCreated.j.d.ts +3 -0
- package/dist/gen/signals/eventCreated.t.d.ts +28 -0
- package/dist/gen/signals/eventCreated.z.d.ts +47 -0
- package/dist/gen/signals/index.d.ts +924 -0
- package/dist/gen/signals/messageCreated.j.d.ts +3 -0
- package/dist/gen/signals/messageCreated.t.d.ts +149 -0
- package/dist/gen/signals/messageCreated.z.d.ts +780 -0
- package/dist/gen/signals/messageDeleted.j.d.ts +3 -0
- package/dist/gen/signals/messageDeleted.t.d.ts +8 -0
- package/dist/gen/signals/messageDeleted.z.d.ts +32 -0
- package/dist/gen/signals/participantAdded.j.d.ts +3 -0
- package/dist/gen/signals/participantAdded.t.d.ts +7 -0
- package/dist/gen/signals/participantAdded.z.d.ts +27 -0
- package/dist/gen/signals/participantRemoved.j.d.ts +3 -0
- package/dist/gen/signals/participantRemoved.t.d.ts +7 -0
- package/dist/gen/signals/participantRemoved.z.d.ts +27 -0
- package/dist/index.cjs +1660 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.mjs +138836 -0
- package/dist/index.mjs.map +7 -0
- package/dist/jsonwebtoken.d.ts +3 -0
- package/dist/listing.d.ts +16 -0
- package/dist/signal-listener.d.ts +51 -0
- package/dist/types.d.ts +41 -0
- package/dist/watchdog.d.ts +11 -0
- package/package.json +35 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type PageLister<R> = (t: {
|
|
2
|
+
nextToken?: string;
|
|
3
|
+
}) => Promise<{
|
|
4
|
+
items: R[];
|
|
5
|
+
meta: {
|
|
6
|
+
nextToken?: string;
|
|
7
|
+
};
|
|
8
|
+
}>;
|
|
9
|
+
export declare class AsyncCollection<T> {
|
|
10
|
+
private _list;
|
|
11
|
+
constructor(_list: PageLister<T>);
|
|
12
|
+
[Symbol.asyncIterator](): AsyncGenerator<Awaited<T>, void, unknown>;
|
|
13
|
+
collect(props?: {
|
|
14
|
+
limit?: number;
|
|
15
|
+
}): Promise<T[]>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { EventEmitter } from './event-emitter';
|
|
2
|
+
import { EventSourceEmitter } from './eventsource';
|
|
3
|
+
import { Types } from './gen/signals';
|
|
4
|
+
import { WatchDog } from './watchdog';
|
|
5
|
+
type _Signals = Types & {
|
|
6
|
+
unknown: {
|
|
7
|
+
type: 'unknown';
|
|
8
|
+
data: unknown;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
type SignalListenerState = {
|
|
12
|
+
status: 'disconnected';
|
|
13
|
+
} | {
|
|
14
|
+
status: 'connecting';
|
|
15
|
+
connectionPromise: Promise<EventSourceEmitter>;
|
|
16
|
+
} | {
|
|
17
|
+
status: 'connected';
|
|
18
|
+
source: EventSourceEmitter;
|
|
19
|
+
watchdog: WatchDog;
|
|
20
|
+
};
|
|
21
|
+
export type Signals = {
|
|
22
|
+
[K in keyof _Signals as _Signals[K]['type']]: _Signals[K]['data'];
|
|
23
|
+
};
|
|
24
|
+
type Events = Signals & {
|
|
25
|
+
error: Error;
|
|
26
|
+
};
|
|
27
|
+
export type SignalListenerStatus = SignalListenerState['status'];
|
|
28
|
+
export type SignalListenerProps = {
|
|
29
|
+
url: string;
|
|
30
|
+
userKey: string;
|
|
31
|
+
conversationId: string;
|
|
32
|
+
debug: boolean;
|
|
33
|
+
};
|
|
34
|
+
export declare class SignalListener extends EventEmitter<Events> {
|
|
35
|
+
private _props;
|
|
36
|
+
private _state;
|
|
37
|
+
private constructor();
|
|
38
|
+
static listen: (props: SignalListenerProps) => Promise<SignalListener>;
|
|
39
|
+
get status(): SignalListenerStatus;
|
|
40
|
+
readonly connect: () => Promise<void>;
|
|
41
|
+
readonly disconnect: () => Promise<void>;
|
|
42
|
+
private _connect;
|
|
43
|
+
private _disconnectSync;
|
|
44
|
+
private _handleMessage;
|
|
45
|
+
private _handleError;
|
|
46
|
+
private _parseSignal;
|
|
47
|
+
private _safeJsonParse;
|
|
48
|
+
private _toError;
|
|
49
|
+
private _debug;
|
|
50
|
+
}
|
|
51
|
+
export {};
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Client as AutoGeneratedClient, User } from './gen/client';
|
|
2
|
+
export type { Message, Conversation, User, Event } from './gen/client';
|
|
3
|
+
type AsyncFunction = (...args: any[]) => Promise<any>;
|
|
4
|
+
type Simplify<T> = T extends (...args: infer A) => infer R ? (...args: Simplify<A>) => Simplify<R> : T extends Buffer ? Buffer : T extends Promise<infer R> ? Promise<Simplify<R>> : T extends object ? T extends infer O ? {
|
|
5
|
+
[K in keyof O]: Simplify<O[K]>;
|
|
6
|
+
} : never : T;
|
|
7
|
+
export type Headers = Record<string, string>;
|
|
8
|
+
type CommonClientProps = {
|
|
9
|
+
timeout?: number;
|
|
10
|
+
headers?: Headers;
|
|
11
|
+
debug?: boolean;
|
|
12
|
+
};
|
|
13
|
+
type ApiUrlClientProps = CommonClientProps & {
|
|
14
|
+
apiUrl: string;
|
|
15
|
+
};
|
|
16
|
+
type WebhookIdClientProps = CommonClientProps & {
|
|
17
|
+
webhookId: string;
|
|
18
|
+
baseApiUrl?: string;
|
|
19
|
+
};
|
|
20
|
+
export type ClientProps = ApiUrlClientProps | WebhookIdClientProps;
|
|
21
|
+
export type ConnectProps = ClientProps & {
|
|
22
|
+
encryptionKey?: string;
|
|
23
|
+
userKey?: string;
|
|
24
|
+
userId?: string;
|
|
25
|
+
};
|
|
26
|
+
export type ClientOperation = Simplify<keyof {
|
|
27
|
+
[K in keyof AutoGeneratedClient as AutoGeneratedClient[K] extends AsyncFunction ? K : never]: null;
|
|
28
|
+
}>;
|
|
29
|
+
export type ClientRequests = {
|
|
30
|
+
[K in ClientOperation]: Parameters<AutoGeneratedClient[K]>[0];
|
|
31
|
+
};
|
|
32
|
+
export type ClientResponses = {
|
|
33
|
+
[K in ClientOperation]: Simplify<Awaited<ReturnType<AutoGeneratedClient[K]>>>;
|
|
34
|
+
};
|
|
35
|
+
export type AuthenticatedOperation = Exclude<ClientOperation, 'createUser' | 'getOrCreateUser'>;
|
|
36
|
+
export type AuthenticatedClientRequests = Simplify<{
|
|
37
|
+
[K in AuthenticatedOperation]: Omit<ClientRequests[K], 'x-user-key'>;
|
|
38
|
+
}>;
|
|
39
|
+
export type AuthenticatedUser = Simplify<User & {
|
|
40
|
+
key: string;
|
|
41
|
+
}>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class WatchDog {
|
|
2
|
+
private _ms;
|
|
3
|
+
private _listeners;
|
|
4
|
+
private _handle;
|
|
5
|
+
private constructor();
|
|
6
|
+
static init: (ms: number) => WatchDog;
|
|
7
|
+
reset(): void;
|
|
8
|
+
on(_type: 'error', listener: (error: Error) => void): void;
|
|
9
|
+
close(): void;
|
|
10
|
+
private _emitError;
|
|
11
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@holocronlab/botruntime-chat",
|
|
3
|
+
"version": "0.5.5",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public",
|
|
6
|
+
"registry": "https://registry.npmjs.org"
|
|
7
|
+
},
|
|
8
|
+
"description": "Chat API client used by the brt CLI (vendored dist of the upstream chat client, MIT).",
|
|
9
|
+
"main": "./dist/index.cjs",
|
|
10
|
+
"module": "./dist/index.mjs",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"LICENSE"
|
|
16
|
+
],
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/HolocronLab/botruntime-packages",
|
|
20
|
+
"directory": "packages/botruntime-chat"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"axios": "1.2.5",
|
|
24
|
+
"browser-or-node": "^2.1.1",
|
|
25
|
+
"event-source-polyfill": "^1.0.31",
|
|
26
|
+
"eventsource": "^2.0.2",
|
|
27
|
+
"jsonwebtoken": "^9.0.2",
|
|
28
|
+
"qs": "^6.11.0",
|
|
29
|
+
"verror": "^1.10.1",
|
|
30
|
+
"zod": "^3.21.4"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=18.0.0"
|
|
34
|
+
}
|
|
35
|
+
}
|