@wabot-dev/framework 0.3.0 → 0.4.0-beta.1
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/dist/src/addon/async/pg/PgJobRepository.js +50 -2
- package/dist/src/addon/auth/api-key/PgApiKeyRepository.js +5 -0
- package/dist/src/addon/auth/jwt/PgJwtRefreshTokenRepository.js +7 -2
- package/dist/src/addon/chat-bot/pg/PgChatMemory.js +5 -0
- package/dist/src/addon/chat-bot/pg/PgChatRepository.js +5 -0
- package/dist/src/addon/chat-controller/whatsapp/PgWhatsAppRepository.js +5 -0
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppReceiverByWabotProxy.js +1 -0
- package/dist/src/core/lock/Locker.js +7 -0
- package/dist/src/feature/async/@command.js +3 -3
- package/dist/src/feature/async/@commandHandler.js +3 -3
- package/dist/src/feature/async/Async.js +21 -14
- package/dist/src/feature/async/{CommandMetadataStore.js → AsyncMetadataStore.js} +27 -5
- package/dist/src/feature/async/Job.js +92 -2
- package/dist/src/feature/async/JobExecutor.js +62 -0
- package/dist/src/feature/async/JobRepository.js +9 -0
- package/dist/src/feature/async/JobRunner.js +17 -6
- package/dist/src/feature/async/JobScheduler.js +80 -0
- package/dist/src/feature/async/JobWatchdog.js +74 -0
- package/dist/src/feature/async/runCommandHandlers.js +19 -25
- package/dist/src/feature/chat-controller/runChatControllers.js +1 -1
- package/dist/src/feature/pg/PgCrudRepository.js +7 -1
- package/dist/src/feature/pg/PgLock.js +20 -0
- package/dist/src/feature/pg/PgLockKey.js +68 -0
- package/dist/src/feature/pg/PgRepositoryBase.js +40 -27
- package/dist/src/feature/pg/pgStorage.js +16 -0
- package/dist/src/feature/pg/withPgClient.js +45 -0
- package/dist/src/feature/pg/withPgTransaction.js +45 -0
- package/dist/src/index.d.ts +239 -99
- package/dist/src/index.js +8 -4
- package/package.json +7 -5
- package/dist/src/feature/async/Command.js +0 -9
- package/dist/src/feature/async/JobsEventsHub.js +0 -36
package/dist/src/index.d.ts
CHANGED
|
@@ -7,48 +7,55 @@ import InterceptionOptions from 'tsyringe/dist/typings/types/interceptor-options
|
|
|
7
7
|
import { Server } from 'http';
|
|
8
8
|
import { Express, Request, Response } from 'express';
|
|
9
9
|
import * as big_js from 'big.js';
|
|
10
|
-
import { Pool } from 'pg';
|
|
10
|
+
import { Pool, PoolClient } from 'pg';
|
|
11
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
11
12
|
import { Server as Server$1, Socket } from 'socket.io';
|
|
12
13
|
import { Algorithm } from 'jsonwebtoken';
|
|
13
14
|
import { Socket as Socket$1 } from 'socket.io-client';
|
|
14
15
|
|
|
15
|
-
type
|
|
16
|
-
type IStorableData = {
|
|
17
|
-
[key: string]: IPrimitive | IPrimitive[] | IStorableData | IStorableData[];
|
|
18
|
-
};
|
|
19
|
-
declare class Storable<D extends IStorableData> {
|
|
20
|
-
protected data: D;
|
|
21
|
-
constructor(data: D);
|
|
22
|
-
}
|
|
16
|
+
type IStorablePrimitive = null | number | string | boolean | undefined;
|
|
23
17
|
|
|
24
|
-
|
|
18
|
+
type IStorableType<T> = T extends IStorablePrimitive ? T : T extends (...args: any[]) => any ? never : T extends Array<infer U> ? Array<IStorableType<U>> : T extends object ? {
|
|
19
|
+
[K in keyof T]: IStorableType<T[K]>;
|
|
20
|
+
} : never;
|
|
21
|
+
|
|
22
|
+
declare class Auth<D> {
|
|
25
23
|
private authInfo;
|
|
26
24
|
private overrided;
|
|
27
|
-
require(): D
|
|
28
|
-
assign(authInfo: D): void;
|
|
29
|
-
override(authInfo: D): void;
|
|
25
|
+
require(): IStorableType<D>;
|
|
26
|
+
assign(authInfo: IStorableType<D>): void;
|
|
27
|
+
override(authInfo: IStorableType<D>): void;
|
|
30
28
|
clear(): void;
|
|
31
29
|
isAssigned(): boolean;
|
|
32
30
|
wasOverrided(): boolean;
|
|
33
31
|
}
|
|
34
32
|
|
|
35
|
-
|
|
33
|
+
type IStorableData<O extends object> = {
|
|
34
|
+
[K in keyof O]: IStorableType<O[K]>;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
declare class Storable<D extends object> {
|
|
38
|
+
protected data: IStorableData<D>;
|
|
39
|
+
constructor(data: IStorableData<D>);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface IEntityData {
|
|
36
43
|
id?: string;
|
|
37
44
|
createdAt?: number | null;
|
|
38
45
|
discardedAt?: number | null;
|
|
39
46
|
}
|
|
40
47
|
declare class Entity<D extends IEntityData> extends Storable<D> {
|
|
41
|
-
get id():
|
|
48
|
+
get id(): NonNullable<IStorableType<D["id"]>>;
|
|
42
49
|
/**
|
|
43
50
|
* @deprecated use id
|
|
44
51
|
*/
|
|
45
|
-
getId():
|
|
52
|
+
getId(): NonNullable<IStorableType<D["id"]>>;
|
|
46
53
|
get createdAt(): Date;
|
|
47
54
|
/**
|
|
48
55
|
* @deprecated use createdAt
|
|
49
56
|
*/
|
|
50
57
|
getCreatedAt(): Date;
|
|
51
|
-
update(newData: Omit<D, 'id' | 'createdAt' | 'discardedAt'
|
|
58
|
+
update(newData: Partial<Omit<D, 'id' | 'createdAt' | 'discardedAt'>>): void;
|
|
52
59
|
wasCreated(): boolean;
|
|
53
60
|
validate(): void;
|
|
54
61
|
}
|
|
@@ -334,62 +341,117 @@ declare class DescriptionMetadataStore {
|
|
|
334
341
|
getModelDescriptions(model: IConstructor<any>): IDescriptionMetadata[];
|
|
335
342
|
}
|
|
336
343
|
|
|
337
|
-
interface
|
|
338
|
-
|
|
344
|
+
interface ILockKey {
|
|
345
|
+
run<T>(fn: () => Promise<T>): Promise<T>;
|
|
346
|
+
tryRun<T>(fn: () => Promise<T>): Promise<T | undefined>;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
interface ILocker {
|
|
350
|
+
withKey(key: string | number): ILockKey;
|
|
351
|
+
}
|
|
352
|
+
declare class Locker implements ILocker {
|
|
353
|
+
withKey(key: string | number): ILockKey;
|
|
339
354
|
}
|
|
340
|
-
declare function command(config?: ICommandConfig): (target: IConstructor<any>) => void;
|
|
341
355
|
|
|
342
|
-
|
|
343
|
-
|
|
356
|
+
interface ICommandConfig {
|
|
357
|
+
name: string;
|
|
344
358
|
}
|
|
359
|
+
declare function command<O extends object>(config: ICommandConfig | string): (target: IConstructor<IStorableData<O>>) => void;
|
|
345
360
|
|
|
346
|
-
interface ICommandHandler<C extends
|
|
361
|
+
interface ICommandHandler<C extends object> {
|
|
347
362
|
handle(command: C): void | Promise<void>;
|
|
348
363
|
}
|
|
349
364
|
|
|
350
|
-
interface ICommandHandlerConfig<C extends
|
|
351
|
-
command: IConstructor<C
|
|
365
|
+
interface ICommandHandlerConfig<C extends object> {
|
|
366
|
+
command: IConstructor<IStorableData<C>>;
|
|
367
|
+
}
|
|
368
|
+
declare function commandHandler<C extends object>(config: ICommandHandlerConfig<C> | IConstructor<IStorableData<C>>): (target: IConstructor<ICommandHandler<C>>) => void;
|
|
369
|
+
|
|
370
|
+
interface ICronHandler {
|
|
371
|
+
handle(): void | Promise<void>;
|
|
372
|
+
handleError?(e: any): void | Promise<void>;
|
|
352
373
|
}
|
|
353
|
-
declare function commandHandler<C extends Command<any>>(config: ICommandHandlerConfig<C>): (target: IConstructor<ICommandHandler<C>>) => void;
|
|
354
374
|
|
|
355
|
-
|
|
375
|
+
interface ICronJobScheduleConfig {
|
|
376
|
+
name: string;
|
|
377
|
+
commandName: string;
|
|
378
|
+
cron: string;
|
|
379
|
+
enabled: boolean;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
interface ICronMetadata {
|
|
383
|
+
handlerConstructor: IConstructor<ICronHandler>;
|
|
384
|
+
config: ICronJobScheduleConfig;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
declare class AsyncMetadataStore {
|
|
356
388
|
private handlersMap;
|
|
357
389
|
private handlersInverseMap;
|
|
358
390
|
private commandsMap;
|
|
359
391
|
private commandsInverseMap;
|
|
360
|
-
|
|
361
|
-
|
|
392
|
+
private cronsMap;
|
|
393
|
+
registerCron(cron: IConstructor<ICronHandler>, config: ICronJobScheduleConfig): void;
|
|
394
|
+
requireCronMetadata(cron: IConstructor<ICronHandler>): ICronMetadata[];
|
|
395
|
+
registerCommand(command: IConstructor<any>, commandName: string): void;
|
|
396
|
+
registerCommandHandler<C extends object>(command: IConstructor<IStorableData<C>>, handlerConstructor: IConstructor<ICommandHandler<C>>): void;
|
|
362
397
|
getHandlerForCommandName(commandName: string): IConstructor<ICommandHandler<any>> | null;
|
|
363
398
|
getCommandNameForHandler(handlerConstructor: IConstructor<ICommandHandler<any>>): string | null;
|
|
364
|
-
|
|
365
|
-
|
|
399
|
+
requireCommandNameForHandler(handlerConstructor: IConstructor<ICommandHandler<any>>): string;
|
|
400
|
+
getCommandName(command: IConstructor<any>): string | null;
|
|
401
|
+
getCommandForCommandName(commandName: string): IConstructor<any> | null;
|
|
366
402
|
}
|
|
367
403
|
|
|
368
404
|
interface IJobData extends IEntityData {
|
|
369
405
|
commandName: string;
|
|
370
406
|
commandData: any;
|
|
407
|
+
scheduledAt?: number;
|
|
371
408
|
startedAt?: number;
|
|
372
409
|
successAt?: number;
|
|
373
410
|
failedAt?: number;
|
|
374
411
|
retryAt?: number;
|
|
412
|
+
reintentsDelaysInSeconds?: number[];
|
|
413
|
+
intentNumber?: number;
|
|
375
414
|
error?: {
|
|
415
|
+
time: number;
|
|
376
416
|
message: string;
|
|
377
417
|
stack?: string;
|
|
378
418
|
info?: any;
|
|
379
419
|
};
|
|
420
|
+
aceptableRunningTimeSeconds?: number;
|
|
421
|
+
stuckRetryAttempts?: number;
|
|
380
422
|
}
|
|
381
423
|
declare class Job extends Entity<IJobData> {
|
|
382
424
|
get commandName(): string;
|
|
425
|
+
get commandData(): any;
|
|
426
|
+
get reintentsDelaysInSeconds(): number[] | undefined;
|
|
427
|
+
get aceptableRunningTimeSeconds(): number | undefined;
|
|
428
|
+
get stuckRetryAttempts(): number | undefined;
|
|
429
|
+
get runningSeconds(): number;
|
|
430
|
+
get successAt(): Date | null;
|
|
431
|
+
get failedAt(): Date | null;
|
|
432
|
+
get scheduledAt(): Date | null;
|
|
433
|
+
get intentNumber(): number;
|
|
434
|
+
wasSuccess(): boolean;
|
|
435
|
+
wasFailed(): boolean;
|
|
383
436
|
hasFinished(): boolean;
|
|
437
|
+
isRunning(): boolean;
|
|
438
|
+
isScheduleReady(): boolean;
|
|
439
|
+
isStuck(): boolean;
|
|
384
440
|
setAsStarted(): void;
|
|
385
441
|
setAsSuccess(): void;
|
|
386
442
|
setAsFailed(error: Error): void;
|
|
443
|
+
recover(): void;
|
|
387
444
|
}
|
|
388
445
|
|
|
389
446
|
interface IJobRepository extends ICrudRepository<Job> {
|
|
447
|
+
findPendingForRunFrom(date: Date, limit: number): Promise<Job[]>;
|
|
448
|
+
findRunningJobs(): Promise<Job[]>;
|
|
449
|
+
countRunningByCommand(commandName: string): Promise<number>;
|
|
390
450
|
}
|
|
391
451
|
|
|
392
452
|
declare class JobRepository implements IJobRepository {
|
|
453
|
+
findRunningJobs(): Promise<Job[]>;
|
|
454
|
+
findPendingForRunFrom(date: Date, limit: number): Promise<Job[]>;
|
|
393
455
|
find(id: string): Promise<Job | null>;
|
|
394
456
|
findOrThrow(id: string): Promise<Job>;
|
|
395
457
|
findByIds(ids: string[]): Promise<Job[]>;
|
|
@@ -397,39 +459,60 @@ declare class JobRepository implements IJobRepository {
|
|
|
397
459
|
create(item: Job): Promise<void>;
|
|
398
460
|
update(item: Job): Promise<void>;
|
|
399
461
|
delete(item: Job): Promise<void>;
|
|
462
|
+
countRunningByCommand(commandName: string): Promise<number>;
|
|
400
463
|
}
|
|
401
464
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
465
|
+
declare class JobRunner {
|
|
466
|
+
private jobRepository;
|
|
467
|
+
private handlerContainer;
|
|
468
|
+
private logger;
|
|
469
|
+
constructor(jobRepository: JobRepository, handlerContainer: AsyncMetadataStore);
|
|
470
|
+
run(job: Job): Promise<void>;
|
|
405
471
|
}
|
|
406
|
-
|
|
407
|
-
declare class
|
|
472
|
+
|
|
473
|
+
declare class JobExecutor {
|
|
474
|
+
private locker;
|
|
475
|
+
private runner;
|
|
476
|
+
private repo;
|
|
477
|
+
private env;
|
|
478
|
+
private activeJobs;
|
|
408
479
|
private logger;
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
480
|
+
constructor(locker: Locker, runner: JobRunner, repo: JobRepository, env: Env);
|
|
481
|
+
remainingSlots(): number;
|
|
482
|
+
execute(job: Job): Promise<void>;
|
|
483
|
+
private tryAcquire;
|
|
484
|
+
private release;
|
|
412
485
|
}
|
|
413
486
|
|
|
414
|
-
declare class
|
|
415
|
-
private
|
|
416
|
-
private
|
|
417
|
-
private
|
|
418
|
-
|
|
419
|
-
|
|
487
|
+
declare class JobScheduler {
|
|
488
|
+
private locker;
|
|
489
|
+
private repo;
|
|
490
|
+
private executor;
|
|
491
|
+
private env;
|
|
492
|
+
private timeout?;
|
|
493
|
+
private logger;
|
|
494
|
+
private commands;
|
|
495
|
+
private running;
|
|
496
|
+
constructor(locker: Locker, repo: JobRepository, executor: JobExecutor, env: Env);
|
|
497
|
+
start(commands: string[]): void;
|
|
498
|
+
stop(commands: string[]): void;
|
|
499
|
+
tryExecuteNow(job: Job): void;
|
|
500
|
+
private tick;
|
|
420
501
|
}
|
|
421
502
|
|
|
422
|
-
declare class
|
|
503
|
+
declare class Async {
|
|
423
504
|
private jobRepository;
|
|
424
|
-
private
|
|
425
|
-
private
|
|
426
|
-
constructor(jobRepository: JobRepository,
|
|
427
|
-
|
|
505
|
+
private metadataStore;
|
|
506
|
+
private jobScheduler;
|
|
507
|
+
constructor(jobRepository: JobRepository, metadataStore: AsyncMetadataStore, jobScheduler: JobScheduler);
|
|
508
|
+
runCommand<T>(ctor: IConstructor<T>, data: IValidateInputShape<T>): Promise<Job>;
|
|
428
509
|
}
|
|
429
510
|
|
|
430
|
-
declare function
|
|
511
|
+
declare function runCommandHandlers(handlers: IConstructor<ICommandHandler<any>>[]): void;
|
|
512
|
+
declare function stopCommandHandlers(handlers: IConstructor<ICommandHandler<any>>[]): void;
|
|
431
513
|
|
|
432
|
-
interface IChatConnection
|
|
514
|
+
interface IChatConnection {
|
|
515
|
+
chatType: 'GROUP' | 'PRIVATE';
|
|
433
516
|
channelName: string;
|
|
434
517
|
id: string;
|
|
435
518
|
}
|
|
@@ -444,7 +527,11 @@ declare class Chat extends Entity<IChatData> {
|
|
|
444
527
|
constructor(data: IChatData);
|
|
445
528
|
isPrivate(): boolean;
|
|
446
529
|
isGroup(): boolean;
|
|
447
|
-
get connections():
|
|
530
|
+
get connections(): {
|
|
531
|
+
chatType: "GROUP" | "PRIVATE";
|
|
532
|
+
channelName: string;
|
|
533
|
+
id: string;
|
|
534
|
+
}[];
|
|
448
535
|
hasConnection(connection: IChatConnection): boolean;
|
|
449
536
|
private validatePrivateChat;
|
|
450
537
|
private validateGroupChat;
|
|
@@ -582,13 +669,13 @@ declare class MindsetOperator implements IMindset {
|
|
|
582
669
|
functionErrorToString(error: any): Promise<string>;
|
|
583
670
|
}
|
|
584
671
|
|
|
585
|
-
interface IChatMessagesPublicImage
|
|
672
|
+
interface IChatMessagesPublicImage {
|
|
586
673
|
name?: string;
|
|
587
674
|
publicUrl: string;
|
|
588
675
|
base64Url?: undefined;
|
|
589
676
|
mimeType: string;
|
|
590
677
|
}
|
|
591
|
-
interface IChatMessagesPrivateImage
|
|
678
|
+
interface IChatMessagesPrivateImage {
|
|
592
679
|
name?: string;
|
|
593
680
|
publicUrl?: undefined;
|
|
594
681
|
base64Url: string;
|
|
@@ -596,14 +683,14 @@ interface IChatMessagesPrivateImage extends IStorableData {
|
|
|
596
683
|
}
|
|
597
684
|
type IChatMessageImage = IChatMessagesPrivateImage | IChatMessagesPublicImage;
|
|
598
685
|
|
|
599
|
-
interface IChatMessage
|
|
686
|
+
interface IChatMessage {
|
|
600
687
|
senderId?: string;
|
|
601
688
|
senderName?: string;
|
|
602
689
|
text?: string;
|
|
603
690
|
images?: IChatMessageImage[];
|
|
604
691
|
}
|
|
605
692
|
|
|
606
|
-
interface IFunctionCall
|
|
693
|
+
interface IFunctionCall {
|
|
607
694
|
id: string;
|
|
608
695
|
name: string;
|
|
609
696
|
arguments?: string;
|
|
@@ -614,13 +701,19 @@ declare const chatItemTypeOptions: readonly ["botMessage", "humanMessage", "func
|
|
|
614
701
|
type IBotMessageItem = {
|
|
615
702
|
type: 'botMessage';
|
|
616
703
|
botMessage: IChatMessage;
|
|
704
|
+
humanMessage?: undefined;
|
|
705
|
+
functionCall?: undefined;
|
|
617
706
|
};
|
|
618
707
|
type IHumanMessageItem = {
|
|
619
708
|
type: 'humanMessage';
|
|
709
|
+
botMessage?: undefined;
|
|
620
710
|
humanMessage: IChatMessage;
|
|
711
|
+
functionCall?: undefined;
|
|
621
712
|
};
|
|
622
713
|
type IFunctionCallItem = {
|
|
623
714
|
type: 'functionCall';
|
|
715
|
+
botMessage?: undefined;
|
|
716
|
+
humanMessage?: undefined;
|
|
624
717
|
functionCall: IFunctionCall;
|
|
625
718
|
};
|
|
626
719
|
type IChatItem = IBotMessageItem | IHumanMessageItem | IFunctionCallItem;
|
|
@@ -657,7 +750,7 @@ declare class ChatItem extends Entity<IChatItemData> {
|
|
|
657
750
|
get botMessage(): IChatMessage;
|
|
658
751
|
get functionCall(): IFunctionCall;
|
|
659
752
|
setFunctionResult(result: string): void;
|
|
660
|
-
getData(): IChatItemData
|
|
753
|
+
getData(): IStorableData<IChatItemData>;
|
|
661
754
|
}
|
|
662
755
|
|
|
663
756
|
interface IChatMemory {
|
|
@@ -761,7 +854,7 @@ declare class ChatResolver {
|
|
|
761
854
|
|
|
762
855
|
interface IMessageContext extends IReceivedMessage {
|
|
763
856
|
chat: Chat;
|
|
764
|
-
authInfo?:
|
|
857
|
+
authInfo?: object;
|
|
765
858
|
}
|
|
766
859
|
|
|
767
860
|
declare function runChatControllers(controllers: IConstructor<any>[]): void;
|
|
@@ -784,13 +877,12 @@ declare class ExpressProvider {
|
|
|
784
877
|
private createExpress;
|
|
785
878
|
}
|
|
786
879
|
|
|
787
|
-
interface IMoneyData
|
|
880
|
+
interface IMoneyData {
|
|
788
881
|
amount: string;
|
|
789
882
|
currency: string;
|
|
790
883
|
}
|
|
791
884
|
declare class Money extends Storable<IMoneyData> {
|
|
792
885
|
getData(): {
|
|
793
|
-
[key: string]: IPrimitive | IStorableData | IPrimitive[] | IStorableData[];
|
|
794
886
|
amount: string;
|
|
795
887
|
currency: string;
|
|
796
888
|
};
|
|
@@ -828,14 +920,15 @@ type IPgRepositoryConfig<P extends Entity<IEntityData>> = {
|
|
|
828
920
|
declare class PgRepositoryBase<P extends Entity<IEntityData>> {
|
|
829
921
|
protected pool: Pool;
|
|
830
922
|
protected config: IPgRepositoryConfig<any>;
|
|
831
|
-
private
|
|
923
|
+
private tableIsReady;
|
|
832
924
|
protected schema: string;
|
|
833
925
|
protected table: string;
|
|
834
926
|
protected columnsList: string[];
|
|
835
|
-
protected columnsAndTypes: string;
|
|
927
|
+
protected columnsAndTypes: string[];
|
|
836
928
|
protected columns: string;
|
|
837
929
|
protected vars: string;
|
|
838
930
|
protected updates: string;
|
|
931
|
+
private logger;
|
|
839
932
|
addColumns: {
|
|
840
933
|
[columns: string]: {
|
|
841
934
|
type: string;
|
|
@@ -846,9 +939,8 @@ declare class PgRepositoryBase<P extends Entity<IEntityData>> {
|
|
|
846
939
|
protected values(item: P): (string | number | boolean | Date | null)[];
|
|
847
940
|
protected exec(sql: string, values: any[]): Promise<void>;
|
|
848
941
|
protected query(sql: string, values: any[]): Promise<P[]>;
|
|
849
|
-
protected
|
|
850
|
-
protected
|
|
851
|
-
protected ensureColumns(): Promise<void>;
|
|
942
|
+
protected ensureTable(client: PoolClient): Promise<void>;
|
|
943
|
+
protected ensureColumns(client: PoolClient): Promise<void>;
|
|
852
944
|
}
|
|
853
945
|
|
|
854
946
|
declare class PgCrudRepository<P extends Entity<IEntityData>> extends PgRepositoryBase<P> implements ICrudRepository<P> {
|
|
@@ -863,6 +955,44 @@ declare class PgCrudRepository<P extends Entity<IEntityData>> extends PgReposito
|
|
|
863
955
|
delete(item: P): Promise<void>;
|
|
864
956
|
}
|
|
865
957
|
|
|
958
|
+
declare class PgLocker implements ILocker {
|
|
959
|
+
private readonly pool;
|
|
960
|
+
constructor(pool: Pool);
|
|
961
|
+
withKey(key: string | number): ILockKey;
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
declare class PgLockKey implements ILockKey {
|
|
965
|
+
private readonly key;
|
|
966
|
+
private pool;
|
|
967
|
+
readonly value: bigint;
|
|
968
|
+
private logger;
|
|
969
|
+
constructor(key: string | number, pool: Pool);
|
|
970
|
+
run<T>(fn: () => Promise<T>): Promise<T>;
|
|
971
|
+
tryRun<T>(fn: () => Promise<T>): Promise<T | undefined>;
|
|
972
|
+
toString(): string;
|
|
973
|
+
private static hashString;
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
type ClientMap = Map<Pool, PoolClient>;
|
|
977
|
+
declare const pgStorage: AsyncLocalStorage<ClientMap>;
|
|
978
|
+
/**
|
|
979
|
+
* Get or initialize the client map for the current async context
|
|
980
|
+
*/
|
|
981
|
+
declare function getClientMap(): ClientMap;
|
|
982
|
+
|
|
983
|
+
/**
|
|
984
|
+
* Runs a function with a shared Postgres client for the given pool.
|
|
985
|
+
* Reuses the client if already present in the async context.
|
|
986
|
+
*/
|
|
987
|
+
declare function withPgClient<T>(pool: Pool, fn: (client: PoolClient) => Promise<T>): Promise<T>;
|
|
988
|
+
/**
|
|
989
|
+
* Get the current shared client for a pool.
|
|
990
|
+
* Falls back to the pool itself if no shared client exists.
|
|
991
|
+
*/
|
|
992
|
+
declare function getPgClient(pool: Pool): PoolClient | Pool;
|
|
993
|
+
|
|
994
|
+
declare function withPgTransaction<T>(pool: Pool, fn: (client: PoolClient) => Promise<T>): Promise<T>;
|
|
995
|
+
|
|
866
996
|
interface IEndPointConfig {
|
|
867
997
|
path?: string;
|
|
868
998
|
disableJsonParser?: boolean;
|
|
@@ -998,57 +1128,62 @@ declare function runSocketControllers(controllers: IConstructor<any>[]): void;
|
|
|
998
1128
|
|
|
999
1129
|
declare class PgJobRepository extends PgCrudRepository<Job> implements IJobRepository {
|
|
1000
1130
|
constructor(pool: Pool);
|
|
1131
|
+
findPendingForRunFrom(date: Date, limit: number): Promise<Job[]>;
|
|
1132
|
+
findRunningJobs(): Promise<Job[]>;
|
|
1133
|
+
countRunningByCommand(commandName: string): Promise<number>;
|
|
1001
1134
|
}
|
|
1002
1135
|
|
|
1003
1136
|
declare function apiKeyHandshakeGuard(): (target: IConstructor<any>) => void;
|
|
1004
1137
|
|
|
1005
1138
|
declare function apiKeyGuard(): (target: object, propertyKey: string | symbol) => void;
|
|
1006
1139
|
|
|
1007
|
-
interface IApiKeyData<A extends
|
|
1140
|
+
interface IApiKeyData<A extends object> extends IEntityData {
|
|
1008
1141
|
secretHash?: string;
|
|
1009
1142
|
metadata?: Record<string, string>;
|
|
1010
1143
|
authInfo: A;
|
|
1011
1144
|
name: string;
|
|
1012
1145
|
}
|
|
1013
|
-
declare class ApiKey<A extends
|
|
1146
|
+
declare class ApiKey<A extends object> extends Entity<IApiKeyData<A>> {
|
|
1014
1147
|
static PREFIX: string;
|
|
1015
1148
|
static hashSecret(secret: string): string;
|
|
1016
|
-
get authInfo(): A
|
|
1017
|
-
get metadata():
|
|
1149
|
+
get authInfo(): IStorableType<A>;
|
|
1150
|
+
get metadata(): {
|
|
1151
|
+
[x: string]: string;
|
|
1152
|
+
};
|
|
1018
1153
|
get name(): string;
|
|
1019
|
-
setAuthInfo(authInfo: A): void;
|
|
1154
|
+
setAuthInfo(authInfo: IStorableType<A>): void;
|
|
1020
1155
|
generateSecret(): string;
|
|
1021
1156
|
isValidSecret(secret: string): boolean;
|
|
1022
1157
|
validateSecret(secret: string): void;
|
|
1023
1158
|
}
|
|
1024
1159
|
|
|
1025
|
-
interface IApiKeyRepository<A extends
|
|
1160
|
+
interface IApiKeyRepository<A extends object> {
|
|
1026
1161
|
find(id: string): Promise<ApiKey<A> | null>;
|
|
1027
1162
|
findOrThrow(id: string): Promise<ApiKey<A>>;
|
|
1028
1163
|
findByMetadata(metadata: Record<string, string>): Promise<ApiKey<A>[]>;
|
|
1029
1164
|
create(item: ApiKey<A>): Promise<void>;
|
|
1030
1165
|
generate(req: IGenerateApiKeyReq<A>): Promise<IGenerateApiKeyRes<A>>;
|
|
1031
1166
|
findBySecret(secret: string): Promise<ApiKey<A> | null>;
|
|
1032
|
-
findAndValidate(secret: string): Promise<A
|
|
1167
|
+
findAndValidate(secret: string): Promise<IStorableType<A>>;
|
|
1033
1168
|
}
|
|
1034
|
-
interface IGenerateApiKeyReq<A extends
|
|
1169
|
+
interface IGenerateApiKeyReq<A extends object> {
|
|
1035
1170
|
name: string;
|
|
1036
1171
|
metadata?: Record<string, string>;
|
|
1037
|
-
authInfo: A
|
|
1172
|
+
authInfo: IStorableType<A>;
|
|
1038
1173
|
}
|
|
1039
|
-
interface IGenerateApiKeyRes<A extends
|
|
1174
|
+
interface IGenerateApiKeyRes<A extends object> {
|
|
1040
1175
|
apiKey: ApiKey<A>;
|
|
1041
1176
|
secret: string;
|
|
1042
1177
|
}
|
|
1043
1178
|
|
|
1044
|
-
declare class ApiKeyRepository<A extends
|
|
1179
|
+
declare class ApiKeyRepository<A extends object> implements IApiKeyRepository<A> {
|
|
1045
1180
|
find(id: string): Promise<ApiKey<A> | null>;
|
|
1046
1181
|
findOrThrow(id: string): Promise<ApiKey<A>>;
|
|
1047
1182
|
findByMetadata(metadata: Record<string, string>): Promise<ApiKey<A>[]>;
|
|
1048
1183
|
create(item: ApiKey<A>): Promise<void>;
|
|
1049
1184
|
generate(req: IGenerateApiKeyReq<A>): Promise<IGenerateApiKeyRes<A>>;
|
|
1050
1185
|
findBySecret(secret: string): Promise<ApiKey<A> | null>;
|
|
1051
|
-
findAndValidate(secret: string): Promise<A
|
|
1186
|
+
findAndValidate(secret: string): Promise<IStorableType<A>>;
|
|
1052
1187
|
}
|
|
1053
1188
|
|
|
1054
1189
|
declare class ApiKeyHandshakeGuardMiddleware implements IHandshakeMiddleware {
|
|
@@ -1065,23 +1200,23 @@ declare class ApiKeyGuardMiddleware implements IMiddleware {
|
|
|
1065
1200
|
handle(req: Request, res: Response, container: DependencyContainer$1): Promise<void>;
|
|
1066
1201
|
}
|
|
1067
1202
|
|
|
1068
|
-
declare class PgApiKeyRepository<A extends
|
|
1203
|
+
declare class PgApiKeyRepository<A extends object> extends PgCrudRepository<ApiKey<A>> implements IApiKeyRepository<A> {
|
|
1069
1204
|
constructor(pool: Pool);
|
|
1070
|
-
findAndValidate(secret: string): Promise<A
|
|
1205
|
+
findAndValidate(secret: string): Promise<IStorableType<A>>;
|
|
1071
1206
|
findBySecret(secret: string): Promise<ApiKey<A> | null>;
|
|
1072
1207
|
findByMetadata(metadata: Record<string, string>): Promise<ApiKey<A>[]>;
|
|
1073
1208
|
generate(req: IGenerateApiKeyReq<A>): Promise<IGenerateApiKeyRes<A>>;
|
|
1074
1209
|
}
|
|
1075
1210
|
|
|
1076
|
-
interface IRemoteApiKeyFetcher<A extends
|
|
1077
|
-
fetchAuthInfoBySecret: (secret: string) => Promise<A | null>;
|
|
1211
|
+
interface IRemoteApiKeyFetcher<A extends object> {
|
|
1212
|
+
fetchAuthInfoBySecret: (secret: string) => Promise<IStorableType<A> | null>;
|
|
1078
1213
|
}
|
|
1079
|
-
declare class RemoteApiKeyRepository<A extends
|
|
1214
|
+
declare class RemoteApiKeyRepository<A extends object> implements IApiKeyRepository<A> {
|
|
1080
1215
|
private fetcher;
|
|
1081
1216
|
private cacheSeconds;
|
|
1082
1217
|
private cacheBySecret;
|
|
1083
1218
|
constructor(fetcher: IRemoteApiKeyFetcher<A>, cacheSeconds: number);
|
|
1084
|
-
findAndValidate(secret: string): Promise<A
|
|
1219
|
+
findAndValidate(secret: string): Promise<IStorableType<A>>;
|
|
1085
1220
|
find(id: string): Promise<ApiKey<A> | null>;
|
|
1086
1221
|
findOrThrow(id: string): Promise<ApiKey<A>>;
|
|
1087
1222
|
findBySecret(secret: string): Promise<ApiKey<A> | null>;
|
|
@@ -1094,18 +1229,20 @@ declare function jwtHandshakeGuard(): (target: IConstructor<any>) => void;
|
|
|
1094
1229
|
|
|
1095
1230
|
declare function jwtGuard(): (target: object, propertyKey: string | symbol) => void;
|
|
1096
1231
|
|
|
1097
|
-
interface IJwtRefreshTokenData<A extends
|
|
1232
|
+
interface IJwtRefreshTokenData<A extends object> extends IEntityData {
|
|
1098
1233
|
secretHash?: string;
|
|
1099
1234
|
metadata?: Record<string, string>;
|
|
1100
1235
|
authInfo: A;
|
|
1101
1236
|
expirationTime: number;
|
|
1102
1237
|
revokedAt?: number;
|
|
1103
1238
|
}
|
|
1104
|
-
declare class JwtRefreshToken<A extends
|
|
1239
|
+
declare class JwtRefreshToken<A extends object> extends Entity<IJwtRefreshTokenData<A>> {
|
|
1105
1240
|
static PREFIX: string;
|
|
1106
1241
|
static hashSecret(secret: string): string;
|
|
1107
|
-
get authInfo(): A
|
|
1108
|
-
get metadata():
|
|
1242
|
+
get authInfo(): IStorableType<A>;
|
|
1243
|
+
get metadata(): {
|
|
1244
|
+
[x: string]: string;
|
|
1245
|
+
};
|
|
1109
1246
|
get expirationTime(): Date;
|
|
1110
1247
|
isExpired(): boolean;
|
|
1111
1248
|
revoke(): void;
|
|
@@ -1116,8 +1253,8 @@ declare class JwtRefreshToken<A extends IStorableData> extends Entity<IJwtRefres
|
|
|
1116
1253
|
validateToken(secret: string): void;
|
|
1117
1254
|
}
|
|
1118
1255
|
|
|
1119
|
-
interface IJwtRefreshTokenRepository<D extends
|
|
1120
|
-
findAndValidate(secret: string): Promise<D
|
|
1256
|
+
interface IJwtRefreshTokenRepository<D extends object> extends ICrudRepository<JwtRefreshToken<D>> {
|
|
1257
|
+
findAndValidate(secret: string): Promise<IStorableType<D>>;
|
|
1121
1258
|
findByMetadata(metadata: Record<string, string>): Promise<JwtRefreshToken<D>[]>;
|
|
1122
1259
|
}
|
|
1123
1260
|
|
|
@@ -1144,12 +1281,12 @@ declare class JwtSigner {
|
|
|
1144
1281
|
private config;
|
|
1145
1282
|
private mapper;
|
|
1146
1283
|
constructor(config: JwtConfig, mapper: Mapper);
|
|
1147
|
-
signAccessToken<D extends
|
|
1284
|
+
signAccessToken<D extends object>(info: IStorableType<D> | JwtRefreshToken<any>): Promise<JwtTokenDto>;
|
|
1148
1285
|
}
|
|
1149
1286
|
|
|
1150
|
-
declare class JwtRefreshTokenRepository<D extends
|
|
1287
|
+
declare class JwtRefreshTokenRepository<D extends object> implements IJwtRefreshTokenRepository<D> {
|
|
1151
1288
|
findByMetadata(metadata: Record<string, string>): Promise<JwtRefreshToken<D>[]>;
|
|
1152
|
-
findAndValidate(secret: string): Promise<D
|
|
1289
|
+
findAndValidate(secret: string): Promise<IStorableType<D>>;
|
|
1153
1290
|
find(id: string): Promise<JwtRefreshToken<D> | null>;
|
|
1154
1291
|
findOrThrow(id: string): Promise<JwtRefreshToken<D>>;
|
|
1155
1292
|
findByIds(ids: string[]): Promise<JwtRefreshToken<D>[]>;
|
|
@@ -1183,9 +1320,9 @@ declare class JwtGuardMiddleware implements IMiddleware {
|
|
|
1183
1320
|
handle(req: Request, res: Response, container: DependencyContainer$1): Promise<void>;
|
|
1184
1321
|
}
|
|
1185
1322
|
|
|
1186
|
-
declare class PgJwtRefreshTokenRepository<D extends
|
|
1323
|
+
declare class PgJwtRefreshTokenRepository<D extends object> extends PgCrudRepository<JwtRefreshToken<D>> implements IJwtRefreshTokenRepository<D> {
|
|
1187
1324
|
constructor(pool: Pool);
|
|
1188
|
-
findAndValidate(secret: string): Promise<D
|
|
1325
|
+
findAndValidate(secret: string): Promise<IStorableType<D>>;
|
|
1189
1326
|
findBySecret(secret: string): Promise<JwtRefreshToken<D> | null>;
|
|
1190
1327
|
findByMetadata(metadata: Record<string, string>): Promise<JwtRefreshToken<D>[]>;
|
|
1191
1328
|
}
|
|
@@ -1357,11 +1494,11 @@ declare class WhatsappChannelConfig implements IWhatsappChannelConfig {
|
|
|
1357
1494
|
|
|
1358
1495
|
declare function whatsApp(config: string | IWhatsappChannelConfig): (target: object, propertyKey: string | symbol) => void;
|
|
1359
1496
|
|
|
1360
|
-
interface IWhatsAppBusinessNumber
|
|
1497
|
+
interface IWhatsAppBusinessNumber {
|
|
1361
1498
|
id: string;
|
|
1362
1499
|
number: string;
|
|
1363
1500
|
}
|
|
1364
|
-
interface IWhatsAppBusinessAccount
|
|
1501
|
+
interface IWhatsAppBusinessAccount {
|
|
1365
1502
|
id: string;
|
|
1366
1503
|
}
|
|
1367
1504
|
interface IWhatsAppData extends IEntityData {
|
|
@@ -1377,7 +1514,10 @@ declare class WhatsApp extends Entity<IWhatsAppData> {
|
|
|
1377
1514
|
getSlug(): string;
|
|
1378
1515
|
getBusinessAccount(): IWhatsAppBusinessAccount;
|
|
1379
1516
|
getAppSecret(): string;
|
|
1380
|
-
getBusinessNumbers():
|
|
1517
|
+
getBusinessNumbers(): {
|
|
1518
|
+
id: string;
|
|
1519
|
+
number: string;
|
|
1520
|
+
}[];
|
|
1381
1521
|
getAccessToken(): string;
|
|
1382
1522
|
hasBusinessNumber(number: string): boolean;
|
|
1383
1523
|
getBussinessNumber(number: string): IWhatsAppBusinessNumber | null;
|
|
@@ -1645,4 +1785,4 @@ declare function HtmlModule(options: IHtmlModuleOptions): {
|
|
|
1645
1785
|
new (): {};
|
|
1646
1786
|
};
|
|
1647
1787
|
|
|
1648
|
-
export { AnthropicChatAdapter, ApiKey, ApiKeyGuardMiddleware, ApiKeyHandshakeGuardMiddleware, ApiKeyRepository, Async, Auth, Chat, ChatAdapter, ChatBot, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver,
|
|
1788
|
+
export { AnthropicChatAdapter, ApiKey, ApiKeyGuardMiddleware, ApiKeyHandshakeGuardMiddleware, ApiKeyRepository, Async, AsyncMetadataStore, Auth, Chat, ChatAdapter, ChatBot, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, type ClientMap, CmdChannel, Container, ControllerMetadataStore, CustomError, DeepSeekChatAdapter, DescriptionMetadataStore, EXPRESS_REQ, EXPRESS_RES, Entity, Env, EnvWhatsAppRepository, ExpressProvider, GoogleChatAdapter, type GoogleChatAdapterV2Options, HtmlModule, HttpServerProvider, type IApiKeyData, type IApiKeyRepository, type IArrayValidationError, type IArrayValidationResult, type IBotMessageItem, type IChannelMessage, type IChannelMetadata, type IChatAdapter, type IChatAdapterNextItemsReq, type IChatAdapterNextItemsRes, type IChatBot, type IChatBotMetadata, type IChatChannel, type IChatConnection, type IChatControllerMetadata, type IChatData, type IChatItem, type IChatItemData, type IChatItemType, type IChatMemory, type IChatMessage, type IChatRepository, type IChatType, type ICommandConfig, type ICommandHandler, type ICommandHandlerConfig, type IConstructor, type ICrudRepository, type ICustomErrorData, type IDescriptionMetadata, type IEndPointConfig, type IEndPointMetadata, type IEntityData, type IEnvType, type IFunctionCall, type IFunctionCallItem, type IGenerateApiKeyReq, type IGenerateApiKeyRes, type IGetWhatsAppTemplateRequest, type IHandshakeMiddleware, type IHandshakeMiddlewareMetadata, type IHtmlModuleOptions, type IHumanMessageItem, type IJobData, type IJobRepository, type IJwtRefreshTokenData, type IJwtRefreshTokenRepository, type ILanguageModelUsage, type IListenWhatsAppMessageRequest, type ILockKey, type ILocker, type IMessageContext, type IMiddleware, type IMiddlewareMetadata, type IMindset, type IMindsetConfig, type IMindsetIdentity, type IMindsetLlm, type IMindsetMetadata, type IMindsetModuleConfig, type IMindsetModuleMetadata, type IMindsetTool, type IMindsetToolParameter, type IModelValidationError, type IModelValidationResult, type IModelValidatorsInfo, type IMoneyData, type IPersistentData, type IPgRepositoryConfig, type IPropertyValidatorInfo, type IReceivedMessage, type IRemoteApiKeyFetcher, type IRestControllerConfig, type IRestControllerMetadata, type ISendWhatsAppRequest, type ISendWhatsAppTemplateRequest, type ISocketChannelConfig, type ISocketChannelReceivedMessage, type ISocketControllerConfig, type ISocketControllerMetadata, type ISocketEventConfig, type ISocketEventMetadata, type IStorableData, type ITelegramChannelConfig, type IValidateArrayOptions, type IValidateArrayOptionsWithItemsValidators, type IValidateInputShape, type IValidateIsInOptions, type IValidateIsRecordOptions, type IValidateMaxOptions, type IValidateMinOptions, type IValidationError, type IValidationResult, type IValidator, type IValidatorMetadata, type IWhatsAppBusinessAccount, type IWhatsAppBusinessNumber, type IWhatsAppCloudContact, type IWhatsAppCloudMessage, type IWhatsAppCloudMessageMetadata, type IWhatsAppCloudTemplate, type IWhatsAppCloudTemplateComponent, type IWhatsAppCloudTemplateMessage, type IWhatsAppCloudTemplateParameter, type IWhatsAppCloudTemplateResponse, type IWhatsAppCloudWebhookPayload, type IWhatsAppData, type IWhatsAppMessageListener, type IWhatsAppProxyListenMessageEventData, type IWhatsAppProxyListenMessageEventReq, type IWhatsAppProxyMessage, type IWhatsAppProxyMessageContent, type IWhatsAppProxyMessageEventReq, type IWhatsAppProxySendMessageEventReq, type IWhatsAppRepository, type IWhatsAppSenderOptions, type IWhatsappChannelConfig, type IchatControllerConfig, Job, JobRepository, JobRunner, Jwt, JwtAccessAndRefreshTokenDto, JwtConfig, JwtGuardMiddleware, JwtHandshakeGuardMiddleware, JwtRefreshToken, JwtRefreshTokenRepository, JwtSigner, JwtTokenDto, Lifecycle, Locker, Logger, Mapper, Mindset, MindsetMetadataStore, MindsetOperator, Money, MoneyDto, OpenaiChatAdapter, Password, type PasswordHashOptions, Persistent, PgApiKeyRepository, PgChatMemory, PgChatRepository, PgCrudRepository, PgJobRepository, PgJwtRefreshTokenRepository, PgLockKey, PgLocker, PgRepositoryBase, PgWhatsAppRepository, RamChatMemory, RamChatRepository, Random, RemoteApiKeyRepository, RestControllerMetadataStore, RestRequest, SocketChannel, SocketChannelConfig, SocketChannelReceivedMessage, SocketControllerMetadataStore, SocketServerProvider, Storable, TelegramChannel, TelegramChannelConfig, ValidationMetadataStore, WHATSAPP_MESSAGE_EVENT, WHATSAPP_PROXY_LISTEN_MESSAGE_EVENT, WHATSAPP_PROXY_SEND_MESSAGE_EVENT, WabotChatAdapter, WhatsApp, WhatsAppChannel, WhatsAppReceiver, WhatsAppReceiverByCloudApi, WhatsAppReceiverByWabotProxy, WhatsAppRepository, WhatsAppSender, WhatsAppSenderByCloudApi, WhatsAppSenderByWabotProxy, WhatsAppWabotProxyConnection, WhatsappChannelConfig, apiKeyGuard, apiKeyHandshakeGuard, chatBot, chatController, chatItemTypeOptions, cmd, command, commandHandler, container, description, getClientMap, getPgClient, handshakeMiddlewares, inject, injectable, isArray, isBoolean, isDate, isIn, isModel, isNotEmpty, isNumber, isOptional, isPresent, isRecord, isString, jwtGuard, jwtHandshakeGuard, max, middleware, min, mindset, mindsetModule, modelInfo, onDelete, onGet, onPost, onPut, onSocketEvent, pgStorage, readJsonFromFile, restController, runChatControllers, runCommandHandlers, runRestControllers, runSocketControllers, scoped, singleton, socket, socketController, stopCommandHandlers, telegram, validateAndTransform, validateArray, validateIsBoolean, validateIsDate, validateIsIn, validateIsNotEmpty, validateIsNumber, validateIsPresent, validateIsRecord, validateIsString, validateMax, validateMin, validateModel, whatsApp, withPgClient, withPgTransaction, writeJsonToFile };
|