@ccci/micro-server 1.1.14 → 1.1.15

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.
Files changed (38) hide show
  1. package/dist/decorators/Endpoints.d.ts +16 -0
  2. package/dist/index.d.ts +34 -0
  3. package/dist/test/BaseControllerHelper.unit.test.d.ts +2 -0
  4. package/dist/test/Uploader.integration.test.d.ts +2 -0
  5. package/dist/types/ApplicationOptionType.d.ts +39 -0
  6. package/dist/types/AttachmentMetadataTypes.d.ts +23 -0
  7. package/dist/types/BaseControllerTypes.d.ts +42 -0
  8. package/dist/types/BaseModelTypes.d.ts +41 -0
  9. package/dist/types/BaseRouterTypes.d.ts +9 -0
  10. package/dist/types/BaseSocketType.d.ts +6 -0
  11. package/dist/types/BrokerType.d.ts +13 -0
  12. package/dist/types/NotificationTypes.d.ts +9 -0
  13. package/dist/types/RedisTypes.d.ts +48 -0
  14. package/dist/types/UploadedFileType.d.ts +68 -0
  15. package/dist/utils/ApplicationServer.d.ts +30 -0
  16. package/dist/utils/BaseAuthenticatorModel.d.ts +7 -0
  17. package/dist/utils/BaseConsumer.d.ts +44 -0
  18. package/dist/utils/BaseController.d.ts +97 -0
  19. package/dist/utils/BaseControllerHelper.d.ts +27 -0
  20. package/dist/utils/BaseKafka.d.ts +37 -0
  21. package/dist/utils/BaseModel.d.ts +44 -0
  22. package/dist/utils/BaseProducer.d.ts +42 -0
  23. package/dist/utils/BaseRouter.d.ts +91 -0
  24. package/dist/utils/BaseSocketHandler.d.ts +34 -0
  25. package/dist/utils/DatabaseConnector.d.ts +26 -0
  26. package/dist/utils/ErrorHandler.d.ts +5 -0
  27. package/dist/utils/IBaseModel.d.ts +9 -0
  28. package/dist/utils/Logger.d.ts +8 -0
  29. package/dist/utils/Mailer.d.ts +23 -0
  30. package/dist/utils/Mixins.d.ts +71 -0
  31. package/dist/utils/PushNotifier.d.ts +19 -0
  32. package/dist/utils/RouterFactory.d.ts +12 -0
  33. package/dist/utils/ServeKafka.d.ts +16 -0
  34. package/dist/utils/TokenGenerator.d.ts +11 -0
  35. package/dist/utils/Uploader.d.ts +126 -0
  36. package/dist/utils/WebSocketServer.d.ts +27 -0
  37. package/dist/utils/uploader-s3.d.ts +67 -0
  38. package/package.json +1 -1
@@ -0,0 +1,16 @@
1
+ export declare const endpoint: (target: any, methodName: string, descriptor: PropertyDescriptor) => void;
2
+ export declare const PublicAccess: <T extends {
3
+ new (...args: any[]): {};
4
+ }>(constructor: T) => {
5
+ new (...args: any[]): {
6
+ grantPublicAccess: boolean;
7
+ };
8
+ } & T;
9
+ export declare const PrivateAccess: <T extends {
10
+ new (...args: any[]): {};
11
+ }>(constructor: T) => {
12
+ new (...args: any[]): {
13
+ grantPublicAccess: boolean;
14
+ };
15
+ } & T;
16
+ //# sourceMappingURL=Endpoints.d.ts.map
@@ -0,0 +1,34 @@
1
+ export type { RequestQuery, QueryOptions, ResponseType, IncludeType, CommonType } from './types/BaseControllerTypes';
2
+ export type { AttachmentMetadataType } from './types/AttachmentMetadataTypes';
3
+ export type { ApplicationOptionType } from './types/ApplicationOptionType';
4
+ export { default as ApplicationServer } from './utils/ApplicationServer';
5
+ export { default as RouterFactory } from './utils/RouterFactory';
6
+ export { default as BaseRouter } from './utils/BaseRouter';
7
+ export { default as BaseController } from './utils/BaseController';
8
+ export { ConstructQuery, ResponseHelper, ErrorResponseHandler, } from './utils/BaseControllerHelper';
9
+ export { default as IBaseModel } from './utils/IBaseModel';
10
+ export { default as BaseModel } from './utils/BaseModel';
11
+ export { default as ErrorHandler } from './utils/ErrorHandler';
12
+ export { generate, verify, decode } from './utils/TokenGenerator';
13
+ export { default as DatabaseConnector } from './utils/DatabaseConnector';
14
+ export { default as Logger } from './utils/Logger';
15
+ export { default as WebSocketServer } from './utils/WebSocketServer';
16
+ export { default as BaseSocketHandler } from './utils/BaseSocketHandler';
17
+ export type { WebSocketData } from './types/BaseSocketType';
18
+ export type { UploadedFileType } from './types/UploadedFileType';
19
+ export { default as Uploader } from './utils/Uploader';
20
+ export { default as Mailer } from './utils/Mailer';
21
+ export { default as UploaderS3 } from './utils/uploader-s3';
22
+ export { default as Sequelize } from 'sequelize';
23
+ export * from './utils/Mixins';
24
+ export type { NotificationType, NotificationOptions } from './types/NotificationTypes';
25
+ export { default as PushNotifier } from './utils/PushNotifier';
26
+ export { PublicAccess, PrivateAccess, endpoint } from './decorators/Endpoints';
27
+ export { BaseConsumer } from './utils/BaseConsumer';
28
+ export { BaseProducer } from './utils/BaseProducer';
29
+ export { BaseKafka } from './utils/BaseKafka';
30
+ export { ServeKafka } from './utils/ServeKafka';
31
+ export type { MessageHandler, MessageType, PublishType } from './types/BrokerType';
32
+ export { default as BaseAuthenticatorModel } from './utils/BaseAuthenticatorModel';
33
+ export { BaseRedis, BaseRedisCore, BaseRedisCrud, BaseRedisIndexing } from './utils/BaseRedis/index';
34
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=BaseControllerHelper.unit.test.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Uploader.integration.test.d.ts.map
@@ -0,0 +1,39 @@
1
+ export type ApplicationOptionType = {
2
+ routeContext?: string;
3
+ configDir?: string;
4
+ modelDir?: string;
5
+ controllerDir?: string;
6
+ routeDir?: string;
7
+ enableDb?: boolean;
8
+ enableRoutes?: boolean;
9
+ websocketPort?: number;
10
+ websocketDir?: string;
11
+ enableRedis?: boolean;
12
+ enableMinio?: boolean;
13
+ enableKafka?: boolean;
14
+ enableS3?: boolean;
15
+ enableWebSocket?: boolean;
16
+ enableFirebase?: boolean;
17
+ enableEmail?: boolean;
18
+ clientId?: string;
19
+ brokers?: string[];
20
+ consumersPath?: string;
21
+ producersPath?: string;
22
+ minioHost?: string;
23
+ minioPort?: number;
24
+ minioAccessKey?: string;
25
+ minioSecretKey?: string;
26
+ minioUseSSL?: boolean;
27
+ smtpService?: string;
28
+ smtpHost?: string;
29
+ smtpUser?: string;
30
+ smtpPassword?: string;
31
+ enablePushNotifications?: boolean;
32
+ s3ForcePathStyle?: boolean;
33
+ s3Endpoint?: string;
34
+ s3region?: string;
35
+ s3AccessKeyId?: string;
36
+ s3SecretAccessKey?: string;
37
+ appVersion?: string;
38
+ };
39
+ //# sourceMappingURL=ApplicationOptionType.d.ts.map
@@ -0,0 +1,23 @@
1
+ export type AttachmentMetadataType = {
2
+ Bucket?: string;
3
+ Etag?: string;
4
+ Key?: string;
5
+ Location?: string;
6
+ MimeType?: string;
7
+ Thumbnail?: string;
8
+ isHls?: boolean;
9
+ };
10
+ export type DeleteObjectRequest = {
11
+ Bucket: string;
12
+ Key: string;
13
+ MFA?: string;
14
+ VersionId?: string;
15
+ RequestPayer?: 'requester';
16
+ BypassGovernanceRetention?: boolean;
17
+ ExpectedBucketOwner?: string;
18
+ IfMatch?: string;
19
+ IfMatchLastModifiedTime?: Date;
20
+ IfMatchSize?: number;
21
+ };
22
+ export declare const mimeTypes: Record<string, string>;
23
+ //# sourceMappingURL=AttachmentMetadataTypes.d.ts.map
@@ -0,0 +1,42 @@
1
+ import { Order, WhereOptions } from "sequelize";
2
+ export type RequestQuery = {
3
+ search?: string;
4
+ limit?: number;
5
+ page?: number;
6
+ includes?: string;
7
+ fields?: string;
8
+ paranoid?: string;
9
+ sort?: string;
10
+ paginate?: string;
11
+ date_range?: string;
12
+ others?: any;
13
+ scan?: string;
14
+ groupBy?: string;
15
+ };
16
+ export type QueryOptions = {
17
+ where?: WhereOptions<any>;
18
+ limit?: number;
19
+ offset?: number;
20
+ attributes?: Array<string>;
21
+ order?: Order;
22
+ paranoid?: boolean;
23
+ includes?: Array<string | IncludeType>;
24
+ };
25
+ export type ResponseType = {
26
+ success: boolean;
27
+ error?: number;
28
+ statusCode?: number;
29
+ errorMessage?: string;
30
+ errorDescription?: string;
31
+ response?: object;
32
+ version?: string;
33
+ errors?: string[];
34
+ };
35
+ export type IncludeType = {
36
+ association?: string;
37
+ include?: Array<IncludeType>;
38
+ };
39
+ export type CommonType = {
40
+ [x: string | symbol]: any;
41
+ };
42
+ //# sourceMappingURL=BaseControllerTypes.d.ts.map
@@ -0,0 +1,41 @@
1
+ export declare enum FindTypeEnum {
2
+ FIND_ALL = "findAndCountAll",
3
+ FIND_PK = "findByPk",
4
+ FIND_ONE = "findOne",
5
+ COUNT = "count"
6
+ }
7
+ export type IncludesType = {
8
+ path?: string;
9
+ association?: AssociationType;
10
+ };
11
+ export type AssociationType = {
12
+ include: Array<string> | Array<object>;
13
+ association?: string;
14
+ where?: object;
15
+ };
16
+ export type QueryType = {
17
+ where?: object;
18
+ limit?: number;
19
+ offset?: number;
20
+ select?: object;
21
+ order?: object;
22
+ attributes?: object;
23
+ returning?: boolean;
24
+ raw?: boolean;
25
+ nest?: boolean;
26
+ distinct?: string;
27
+ include?: object;
28
+ };
29
+ export type RequestUserType = {
30
+ id?: number;
31
+ email?: string;
32
+ clientSecret?: string;
33
+ };
34
+ export type ModelOptions = {
35
+ tableName: string;
36
+ schema?: string;
37
+ paranoid?: boolean;
38
+ defaultAttributes?: boolean;
39
+ comment?: string;
40
+ };
41
+ //# sourceMappingURL=BaseModelTypes.d.ts.map
@@ -0,0 +1,9 @@
1
+ import { Request, Response, NextFunction } from 'express';
2
+ import { ResponseType } from './BaseControllerTypes';
3
+ export type Mappings = {
4
+ path: string;
5
+ method: string;
6
+ function: (req: Request, res: Response, next: NextFunction) => Promise<void | ResponseType>;
7
+ middleware?: (req: Request, res: Response, next: NextFunction) => Promise<void>;
8
+ };
9
+ //# sourceMappingURL=BaseRouterTypes.d.ts.map
@@ -0,0 +1,6 @@
1
+ export type WebSocketData = {
2
+ userId?: number;
3
+ channel?: string;
4
+ room?: string;
5
+ };
6
+ //# sourceMappingURL=BaseSocketType.d.ts.map
@@ -0,0 +1,13 @@
1
+ export type PublishType = {
2
+ topic: string;
3
+ headers?: Record<string, string>;
4
+ event: string;
5
+ message: Record<string, any>;
6
+ };
7
+ export type MessageType = {
8
+ headers?: Record<string, string>;
9
+ event: string;
10
+ data: any;
11
+ };
12
+ export type MessageHandler = (message: MessageType) => Promise<void>;
13
+ //# sourceMappingURL=BrokerType.d.ts.map
@@ -0,0 +1,9 @@
1
+ export type NotificationType = {
2
+ title: string;
3
+ body: string;
4
+ imageUrl?: string;
5
+ };
6
+ export type NotificationOptions = {
7
+ isBroadcast?: Boolean;
8
+ };
9
+ //# sourceMappingURL=NotificationTypes.d.ts.map
@@ -0,0 +1,48 @@
1
+ import { RediSearchSchema } from "redis";
2
+ export interface QueryOptions {
3
+ page?: number;
4
+ limit?: number;
5
+ sort?: string;
6
+ withCount?: boolean;
7
+ paginate?: boolean;
8
+ search?: string;
9
+ }
10
+ export type RediSearchFieldValue = string | number | boolean | Date | null | undefined | Array<string | number | boolean>;
11
+ export interface RediSearchCreateOptions {
12
+ ON?: "HASH" | "JSON";
13
+ PREFIX?: string | string[];
14
+ FILTER?: string;
15
+ LANGUAGE?: string;
16
+ LANGUAGE_FIELD?: string;
17
+ SCORE?: number;
18
+ SCORE_FIELD?: string;
19
+ MAXTEXTFIELDS?: boolean;
20
+ TEMPORARY?: number;
21
+ NOOFFSETS?: boolean;
22
+ NOHL?: boolean;
23
+ NOFIELDS?: boolean;
24
+ NOFREQS?: boolean;
25
+ SKIPINITIALSCAN?: boolean;
26
+ STOPWORDS?: string[] | "OFF";
27
+ }
28
+ export interface RediSearchIndexConfig<T = unknown> {
29
+ indexKey: string;
30
+ schema: RediSearchSchema;
31
+ options?: RediSearchCreateOptions;
32
+ fields?: (item: T, score: number) => Record<string, RediSearchFieldValue>;
33
+ }
34
+ export interface RediSearchQueryConfig {
35
+ indexKey: string;
36
+ query?: string;
37
+ sortBy?: string;
38
+ returnFields?: string[];
39
+ dialect?: number;
40
+ }
41
+ export interface RedisResult<T> {
42
+ rows: T[];
43
+ count?: number;
44
+ page: number;
45
+ limit: number;
46
+ hasNextPage: boolean;
47
+ }
48
+ //# sourceMappingURL=RedisTypes.d.ts.map
@@ -0,0 +1,68 @@
1
+ export type UploadedFileType = {
2
+ etag?: string;
3
+ path?: string;
4
+ bucket?: string;
5
+ directory?: string;
6
+ objectName?: string;
7
+ mimeType?: string;
8
+ location?: string;
9
+ filesize?: number;
10
+ };
11
+ export type InitUpload = {
12
+ uploadId: string;
13
+ minioUploadId: string;
14
+ pathName: string;
15
+ message: string;
16
+ };
17
+ export type UploadPartConfig = {
18
+ bucketName: string;
19
+ objectName: string;
20
+ uploadID: string;
21
+ partNumber: number;
22
+ headers: unknown;
23
+ };
24
+ export type UploadSession = {
25
+ bucket: string;
26
+ uploadId: string;
27
+ fileName: string;
28
+ objectName: string;
29
+ minioUploadId: string;
30
+ parts: Array<{
31
+ part: number;
32
+ etag: string;
33
+ }>;
34
+ metadata?: Record<string, string>;
35
+ createdAt: Date;
36
+ };
37
+ export type UploadChunk = {
38
+ uploadId: string;
39
+ chunkNumber: number;
40
+ etag: string;
41
+ key: string;
42
+ part: number;
43
+ uploadedPart: number;
44
+ message: string;
45
+ };
46
+ export type CompleteUploadResult = {
47
+ etag: {
48
+ versionId: string;
49
+ etag: string;
50
+ };
51
+ path: string;
52
+ bucket: string;
53
+ location: string;
54
+ fileSize: number;
55
+ mimeType: string;
56
+ objectName: string;
57
+ };
58
+ export type UploadTypes = {
59
+ bucket: string;
60
+ objectKey: string;
61
+ objectName: string;
62
+ };
63
+ export type UploadPart = {
64
+ etag: string;
65
+ key: string;
66
+ part: number;
67
+ };
68
+ //# sourceMappingURL=UploadedFileType.d.ts.map
@@ -0,0 +1,30 @@
1
+ import { Application } from 'express';
2
+ import Mailer from './Mailer';
3
+ import BaseSocketHandler from './BaseSocketHandler';
4
+ import { ApplicationOptionType } from '../types/ApplicationOptionType';
5
+ /**
6
+ * Application Sever class
7
+ */
8
+ export default class ApplicationServer {
9
+ static app: Application;
10
+ static mailer: Mailer;
11
+ static socketHandlers: Array<{
12
+ path: string;
13
+ handler: BaseSocketHandler;
14
+ }>;
15
+ /**
16
+ * Initializes the application server
17
+ * @param {number} port port for the micro service
18
+ * @param {ApplicationOptionType} options additional server configuration
19
+ * @param {Array<String>} sync models to be sync to the database
20
+ *
21
+ */
22
+ static bootstrap(port: number, options?: ApplicationOptionType, sync?: Array<string> | Boolean): Promise<void>;
23
+ static getInstance(): Application;
24
+ static getWebsocketHandlers(): Array<{
25
+ path: string;
26
+ handler: any;
27
+ }>;
28
+ static getMailer(): Mailer;
29
+ }
30
+ //# sourceMappingURL=ApplicationServer.d.ts.map
@@ -0,0 +1,7 @@
1
+ import BaseModel from "./BaseModel";
2
+ export default class BaseAuthenticatorModel extends BaseModel {
3
+ password?: string;
4
+ authenticate(password: string): boolean;
5
+ updatePassword(password?: string): string | undefined;
6
+ }
7
+ //# sourceMappingURL=BaseAuthenticatorModel.d.ts.map
@@ -0,0 +1,44 @@
1
+ import { ConsumerRunConfig, type Consumer, type ConsumerConfig } from "kafkajs";
2
+ import { BaseKafka } from "./BaseKafka";
3
+ import type { MessageHandler } from "../types/BrokerType";
4
+ /**
5
+ * BaseConsumer class provides basic functionality for consuming messages from a Kafka topic.
6
+ * It manages the connection, subscription, and message handling logic for Kafka consumers.
7
+ */
8
+ export declare class BaseConsumer {
9
+ consumer: Consumer | null;
10
+ private kafka;
11
+ /**
12
+ * Creates an instance of BaseConsumer using a BaseKafka instance.
13
+ *
14
+ * @param {BaseKafka} baseKafka - The instance of the BaseKafka class which provides access to the Kafka client.
15
+ */
16
+ constructor(baseKafka: BaseKafka);
17
+ /**
18
+ * Connects the consumer to the Kafka cluster with the specified group ID and optional consumer configuration.
19
+ * If the consumer is already connected, it logs a message and does nothing.
20
+ *
21
+ * @param {string} groupId - The consumer group ID to join.
22
+ * @param {ConsumerConfig} [config] - Optional additional configuration for the consumer.
23
+ * @returns {Promise<void>} - A promise that resolves once the consumer is connected.
24
+ */
25
+ connect(groupId: string, config?: ConsumerConfig): Promise<void>;
26
+ /**
27
+ * Disconnects the consumer from the Kafka cluster.
28
+ * If the consumer is already disconnected, it logs a message and does nothing.
29
+ *
30
+ * @returns {Promise<void>} - A promise that resolves once the consumer is disconnected.
31
+ */
32
+ disconnect(): Promise<void>;
33
+ /**
34
+ * Subscribes the consumer to a Kafka topic and starts processing messages from the topic.
35
+ * The consumer runs the provided message handler for each received message.
36
+ *
37
+ * @param {string} topic - The Kafka topic to subscribe to.
38
+ * @param {MessageHandler} messageHandler - A function to handle the processed messages.
39
+ * @returns {Promise<void>} - A promise that resolves once the consumer has successfully subscribed and started processing messages.
40
+ * @throws {Error} - Throws an error if the consumer is not connected before subscribing.
41
+ */
42
+ subscribe(topic: string, messageHandler: MessageHandler, consumerRunConfig?: ConsumerRunConfig): Promise<void>;
43
+ }
44
+ //# sourceMappingURL=BaseConsumer.d.ts.map
@@ -0,0 +1,97 @@
1
+ import { Request, Response, NextFunction } from 'express';
2
+ import { ResponseType } from '../types/BaseControllerTypes';
3
+ export default class BaseController {
4
+ protected _model: import("sequelize").ModelCtor<import("sequelize").Model<any, any>> | undefined;
5
+ _modelName: string | undefined;
6
+ protected broadcastOnCreate: boolean;
7
+ protected broadcastOnUpdate: boolean;
8
+ protected broadcastOnDelete: boolean;
9
+ constructor(model?: string);
10
+ /**
11
+ * Find all the rows matching your query, within a specified offset / limit,
12
+ * and get the total number of rows matching your query.
13
+ * -- added distinct:true
14
+ * ```js
15
+ * Controller.find(req, res, next)
16
+ * ```
17
+ * @param req
18
+ * @param res
19
+ * @param next
20
+ */
21
+ find(req: Request, res: Response, next?: NextFunction): Promise<ResponseType>;
22
+ /**
23
+ * Search for a single instance by its primary key.
24
+ * This applies LIMIT 1, so the listener will always be called with a single instance.
25
+ * @param req
26
+ * @param res
27
+ * @param next
28
+ */
29
+ findById(req: Request, res: Response, next?: NextFunction): Promise<ResponseType>;
30
+ /**
31
+ *
32
+ * @param req
33
+ * @param res
34
+ * @param next
35
+ */
36
+ create(req: Request, res: Response, next?: NextFunction): Promise<ResponseType>;
37
+ /**
38
+ * Update multiple instances that match the where options. The promise returns an array with one or two elements. The first element is always the number of affected rows, while the second element is the actual affected rows (only supported in postgres and mssql with options.returning true.)
39
+ * @param req
40
+ * @param res
41
+ * @param next
42
+ */
43
+ update(req: Request, res: Response, next?: NextFunction): Promise<ResponseType>;
44
+ /**
45
+ * Delete multiple instances, or set their deletedAt timestamp to the current time if paranoid is enabled.
46
+ * @param req
47
+ * @param res
48
+ * @param next
49
+ */
50
+ delete(req: Request, res: Response, next?: NextFunction): Promise<ResponseType>;
51
+ /**
52
+ * Find all the rows matching your query, within a specified offset / limit,
53
+ * and get the total number of rows matching your query.
54
+ * ```js
55
+ * Controller.find(req, res, next)
56
+ * ```
57
+ * @param req
58
+ * @param res
59
+ * @param next
60
+ */
61
+ archives(req: Request, res: Response, next?: NextFunction): Promise<ResponseType>;
62
+ restore(req: Request, res: Response, next?: NextFunction): Promise<ResponseType>;
63
+ /**
64
+ * count total number of records
65
+ * @param req
66
+ * @param res
67
+ * @param next
68
+ * @returns
69
+ */
70
+ count(req: Request, res: Response, next?: NextFunction): Promise<{
71
+ count: number;
72
+ }>;
73
+ /**
74
+ * Return a basic statistics based on the query and group provided.
75
+ * ```js
76
+ * Controller.find(req, res, next)
77
+ * ```
78
+ * @param req
79
+ * @param res
80
+ * @param next
81
+ */
82
+ stats(req: Request, res: Response, next?: NextFunction): Promise<any>;
83
+ /**
84
+ * ###############################################################
85
+ * ###################### LIFE CYCLE HOOKS #######################
86
+ * ###############################################################
87
+ */
88
+ beforeCreate(req: Request): Promise<void>;
89
+ afterCreate(req: Request, rec: any): Promise<void>;
90
+ beforeUpdate(req: Request): Promise<void>;
91
+ afterUpdate(req: Request, rec: any, orig: any): Promise<void>;
92
+ beforeDelete(req: Request): Promise<void>;
93
+ afterDelete(req: Request, rec: any): Promise<void>;
94
+ beforeFind(req: Request): Promise<void>;
95
+ afterFind(req: Request): Promise<void>;
96
+ }
97
+ //# sourceMappingURL=BaseController.d.ts.map
@@ -0,0 +1,27 @@
1
+ import { BaseError, UniqueConstraintError } from "sequelize";
2
+ import { RequestQuery, QueryOptions, ResponseType } from "../types/BaseControllerTypes";
3
+ /**
4
+ * Constructs a Sequelize query object based on the provided request query.
5
+ * This function dynamically builds the `where` clause, allows for sorting,
6
+ * pagination, field selection, and includes related models.
7
+ *
8
+ * @param {RequestQuery} query - The incoming request query parameters.
9
+ * @returns {QueryOptions} - Returns a Sequelize query options object to be used for querying the database.
10
+ */
11
+ export declare function ConstructQuery(query: RequestQuery): QueryOptions;
12
+ /**
13
+ * A helper function to structure a successful response.
14
+ *
15
+ * @param {any} response - Data to include in the response.
16
+ * @returns {ResponseType} - An object with success status and response data.
17
+ */
18
+ export declare function ResponseHelper(response?: any): ResponseType;
19
+ /**
20
+ * Handles errors and constructs an error response based on the type of error (Sequelize, database, or validation).
21
+ *
22
+ * @param {UniqueConstraintError | BaseError | Error | any} error - The error encountered during execution.
23
+ * @returns {ResponseType} - Returns a structured error response with error codes and messages.
24
+ */
25
+ export declare function ErrorResponseHandler(error: UniqueConstraintError | BaseError | Error | any): ResponseType;
26
+ export { ResponseType };
27
+ //# sourceMappingURL=BaseControllerHelper.d.ts.map
@@ -0,0 +1,37 @@
1
+ import { Kafka, type KafkaConfig } from "kafkajs";
2
+ /**
3
+ * BaseKafka class provides basic functionality for interacting with a Kafka cluster.
4
+ * It allows creating Kafka topics and fetching the Kafka instance for producing/consuming messages.
5
+ */
6
+ export declare class BaseKafka {
7
+ private kafka;
8
+ private consumerPath;
9
+ private producerPath;
10
+ /**
11
+ * Creates an instance of BaseKafka with the provided Kafka configuration.
12
+ *
13
+ * @param {KafkaConfig} config - Kafka configuration object containing client settings.
14
+ */
15
+ constructor(config: KafkaConfig);
16
+ /**
17
+ * Returns the Kafka instance to be used for producing and consuming messages.
18
+ *
19
+ * @returns {Kafka} - Kafka instance.
20
+ */
21
+ getKafka(): Kafka;
22
+ /**
23
+ * Creates Kafka topics if they don't already exist.
24
+ *
25
+ * This method checks if the specified topics exist, and if not, it creates them with the given
26
+ * number of partitions and replication factor.
27
+ *
28
+ * @param {Array<{ topic: string; partitions: number; replicationFactor: number }>} topics - List of topics to be created with their partitions and replication factor.
29
+ * @returns {Promise<void>} - A promise that resolves once the topics are created (or skipped if they already exist).
30
+ */
31
+ createTopics(topics: {
32
+ topic: string;
33
+ partitions: number;
34
+ replicationFactor: number;
35
+ }[]): Promise<void>;
36
+ }
37
+ //# sourceMappingURL=BaseKafka.d.ts.map
@@ -0,0 +1,44 @@
1
+ import { DataTypes, Model } from 'sequelize';
2
+ import type { ModelAttributes } from "sequelize";
3
+ import type IBaseModel from './IBaseModel';
4
+ import { ModelOptions } from '../types/BaseModelTypes';
5
+ export default class BaseModel extends Model implements IBaseModel {
6
+ id?: number;
7
+ /**
8
+ * Sets common model attributes
9
+ * @returns
10
+ */
11
+ static getCommonAttributes(defaultAttributes: boolean): {
12
+ createdById: {
13
+ type: DataTypes.IntegerDataType;
14
+ comment: string;
15
+ };
16
+ updatedById: {
17
+ type: DataTypes.IntegerDataType;
18
+ comment: string;
19
+ };
20
+ isActive: {
21
+ type: DataTypes.AbstractDataType;
22
+ comment: string;
23
+ allowNull: boolean;
24
+ defaultValue: boolean;
25
+ };
26
+ } | null;
27
+ static getCommonAssociations(): void;
28
+ /**
29
+ *
30
+ * @param {ModelAttributes} fields table columns
31
+ * @param {string} tableName name of the table
32
+ * @param {string} schema this will overwrite the default schema
33
+ * @param {boolean} paranoid paranoid option. defaults to true
34
+ * @param {boolean} defaultAttributes need to inherit default attributes. defaults to true
35
+ */
36
+ static initialize(fields: ModelAttributes, tableName: string, schema?: string, paranoid?: boolean, defaultAttributes?: boolean, comment?: string): void;
37
+ /**
38
+ *
39
+ * @param {ModelAttributes} fields table columns
40
+ * @param {string} options Model Options
41
+ */
42
+ static initialize(fields: ModelAttributes, options: ModelOptions): void;
43
+ }
44
+ //# sourceMappingURL=BaseModel.d.ts.map
@@ -0,0 +1,42 @@
1
+ import { type ProducerConfig } from "kafkajs";
2
+ import { BaseKafka } from "./BaseKafka";
3
+ import type { PublishType } from "../types/BrokerType";
4
+ /**
5
+ * BaseProducer class provides basic functionality for producing messages to a Kafka topic.
6
+ * It manages the connection, disconnection, and message publishing logic for Kafka producers.
7
+ */
8
+ export declare class BaseProducer {
9
+ private producer;
10
+ private kafka;
11
+ /**
12
+ * Creates an instance of BaseProducer using a BaseKafka instance.
13
+ *
14
+ * @param {BaseKafka} baseKafka - The instance of the BaseKafka class which provides access to the Kafka client.
15
+ */
16
+ constructor(baseKafka: BaseKafka);
17
+ /**
18
+ * Connects the producer to the Kafka cluster with the specified optional configuration.
19
+ * If the producer is already connected, it logs a message and does nothing.
20
+ *
21
+ * @param {ProducerConfig} [config] - Optional additional configuration for the producer.
22
+ * @returns {Promise<void>} - A promise that resolves once the producer is connected.
23
+ */
24
+ connect(config?: ProducerConfig): Promise<void>;
25
+ /**
26
+ * Disconnects the producer from the Kafka cluster.
27
+ * If the producer is already disconnected, it logs a message and does nothing.
28
+ *
29
+ * @returns {Promise<void>} - A promise that resolves once the producer is disconnected.
30
+ */
31
+ disconnect(): Promise<void>;
32
+ /**
33
+ * Publishes a message to a Kafka topic.
34
+ * If the producer is not connected, it throws an error.
35
+ *
36
+ * @param {PublishType} data - The data to publish, including the topic, event, headers, and message content.
37
+ * @returns {Promise<boolean>} - A promise that resolves to true if the message was successfully sent, false otherwise.
38
+ * @throws {Error} - Throws an error if the producer is not connected.
39
+ */
40
+ publish(data: PublishType): Promise<boolean>;
41
+ }
42
+ //# sourceMappingURL=BaseProducer.d.ts.map
@@ -0,0 +1,91 @@
1
+ import { Request, Response, NextFunction, Router } from 'express';
2
+ import BaseController from './BaseController';
3
+ import { Mappings } from '../types/BaseRouterTypes';
4
+ export default class BaseRouter<T extends BaseController> {
5
+ grantPublicAccess: boolean;
6
+ controller: T;
7
+ /**
8
+ *
9
+ * @param {Controller} controller
10
+ */
11
+ constructor(controller: T);
12
+ /**
13
+ * @description GET route
14
+ * @param {Request} req
15
+ * @param {Response} res
16
+ * @param {NextFunction} next
17
+ */
18
+ get(req: Request, res: Response, next: NextFunction): Promise<void>;
19
+ /**
20
+ * @description GET ARCHIVES route
21
+ * @param {Request} req
22
+ * @param {Response} res
23
+ * @param {NextFunction} next
24
+ */
25
+ archives(req: Request, res: Response, next: NextFunction): Promise<void>;
26
+ /**
27
+ * @description POST route
28
+ * @param {Request} req
29
+ * @param {Response} res
30
+ * @param {NextFunction} next
31
+ */
32
+ post(req: Request, res: Response, next: NextFunction): Promise<void>;
33
+ /**
34
+ * @description GET route (/:id)
35
+ * @param {HttpRequest} req
36
+ * @param {HttpResponse} res
37
+ * @param {*} next
38
+ */
39
+ getId(req: Request, res: Response, next: NextFunction): Promise<void>;
40
+ /**
41
+ * @description PUT route (/:id)
42
+ * @param {HttpRequest} req
43
+ * @param {HttpResponse} res
44
+ * @param {*} next
45
+ */
46
+ update(req: Request, res: Response, next: NextFunction): Promise<void>;
47
+ /**
48
+ *
49
+ * @param req
50
+ * @param res
51
+ * @param next
52
+ */
53
+ delete(req: Request, res: Response, next: NextFunction): Promise<void>;
54
+ /**
55
+ *
56
+ * @param req
57
+ * @param res
58
+ * @param next
59
+ */
60
+ restore(req: Request, res: Response, next: NextFunction): Promise<void>;
61
+ /**
62
+ * /count route
63
+ * @param req
64
+ * @param res
65
+ * @param next
66
+ */
67
+ count(req: Request, res: Response, next: NextFunction): Promise<void>;
68
+ /**
69
+ * /stats get count by group
70
+ * @param req
71
+ * @param res
72
+ * @param next
73
+ */
74
+ stats(req: Request, res: Response, next: NextFunction): Promise<void>;
75
+ /**
76
+ * @description default mappings that will be inherited across all router class
77
+ * @returns {Array} mappings
78
+ */
79
+ getMapping: () => Mappings[];
80
+ /**
81
+ * @description additional mappings placeholder, designed to be overriden
82
+ * @returns {Array} mappings
83
+ */
84
+ getAdditionalMapping: () => Mappings[];
85
+ /**
86
+ * @description create the express router
87
+ * @returns {Router} router
88
+ */
89
+ getRoutes(): Router;
90
+ }
91
+ //# sourceMappingURL=BaseRouter.d.ts.map
@@ -0,0 +1,34 @@
1
+ import type { Server, ServerWebSocket } from 'bun';
2
+ export default class BaseSocketHandler {
3
+ static channel: string;
4
+ static server: Server;
5
+ static websocket: ServerWebSocket;
6
+ /**
7
+ *
8
+ * @param req {Request}
9
+ * @param server {Server}
10
+ * @returns
11
+ */
12
+ upgrade(req: Request, server: Server): Promise<void>;
13
+ /**
14
+ *
15
+ * @param ws {ServerWebSocket}
16
+ * @param message {String}
17
+ */
18
+ accept(ws: ServerWebSocket, message: string): Promise<void>;
19
+ /**
20
+ *
21
+ * @param ws {ServerWebSocket}
22
+ */
23
+ connect(ws: ServerWebSocket): Promise<void>;
24
+ /**
25
+ *
26
+ * @param ws {ServerWebSocket}
27
+ * @param code {number}
28
+ * @param reason {reason}
29
+ */
30
+ disconnect(ws: ServerWebSocket, code: number, reason: string): Promise<void>;
31
+ getInstance(): ServerWebSocket;
32
+ static parse(url: String): any;
33
+ }
34
+ //# sourceMappingURL=BaseSocketHandler.d.ts.map
@@ -0,0 +1,26 @@
1
+ import { Model, ModelStatic, Sequelize } from "sequelize";
2
+ export default class DatabaseConnector {
3
+ private static connections;
4
+ private static connection;
5
+ private static rootDir;
6
+ constructor(path: string);
7
+ /**
8
+ * Initializes the database connection
9
+ * @param path
10
+ */
11
+ static init(): Promise<Array<Sequelize>>;
12
+ static checkConnection(connection: Sequelize): Promise<void>;
13
+ /**
14
+ *
15
+ * @param path root dir (__dirname)
16
+ */
17
+ initializeModels(): Promise<void>;
18
+ getConnections(): Array<Sequelize>;
19
+ static getConnection(): Sequelize;
20
+ connect(connection: Sequelize): Promise<void>;
21
+ static getModel(modelName: string): ModelStatic<Model>;
22
+ static sync(modelName: string, force?: boolean, alter?: boolean): Promise<void>;
23
+ static syncAll(force?: boolean, alter?: boolean): Promise<void>;
24
+ static disconnect(): void;
25
+ }
26
+ //# sourceMappingURL=DatabaseConnector.d.ts.map
@@ -0,0 +1,5 @@
1
+ export default class ErrorHandler extends Error {
2
+ statusCode: number | undefined;
3
+ constructor(message?: string, statusCode?: number);
4
+ }
5
+ //# sourceMappingURL=ErrorHandler.d.ts.map
@@ -0,0 +1,9 @@
1
+ export default interface IBaseModel {
2
+ id?: number;
3
+ createdById?: number;
4
+ updatedById?: number;
5
+ createdAt?: Date;
6
+ updatedAt?: Date;
7
+ _search?: string;
8
+ }
9
+ //# sourceMappingURL=IBaseModel.d.ts.map
@@ -0,0 +1,8 @@
1
+ export default class Logger {
2
+ static info(message: string, details?: any): void;
3
+ static error(error: Error): void;
4
+ static warn(message: string): void;
5
+ static debug(message: string, details?: any): void;
6
+ static table(data: object[]): void;
7
+ }
8
+ //# sourceMappingURL=Logger.d.ts.map
@@ -0,0 +1,23 @@
1
+ import { ApplicationOptionType } from '..';
2
+ interface MailInterface {
3
+ from?: string;
4
+ to: string | string[];
5
+ cc?: string | string[];
6
+ bcc?: string | string[];
7
+ subject: string;
8
+ text?: string;
9
+ html: string;
10
+ }
11
+ export default class Mailer {
12
+ private static instance;
13
+ private transporter;
14
+ private sender;
15
+ private LOCAL_DIR;
16
+ static getInstance(): Mailer;
17
+ connect(options: ApplicationOptionType): Promise<void>;
18
+ hasValidConfig(options: ApplicationOptionType): boolean;
19
+ sendMail(options: MailInterface, template?: string, values?: any): Promise<void>;
20
+ findTemplate(name: string): Promise<unknown>;
21
+ }
22
+ export {};
23
+ //# sourceMappingURL=Mailer.d.ts.map
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Retrieves the MIME type for a given file name based on its extension.
3
+ * @param fileName - The name of the file to extract the MIME type for.
4
+ * @returns The MIME type if found, or null if not found.
5
+ */
6
+ export declare const getMimeType: (fileName: string) => string | null;
7
+ /**
8
+ * Extracts numeric IDs from a string in the format [Name:ID].
9
+ * @param input - The input string containing IDs in the format [Name:ID].
10
+ * @returns An array of extracted numeric IDs.
11
+ */
12
+ export declare const extractIds: (input: string) => number[];
13
+ /**
14
+ * Decrypts an encoded string using a salt.
15
+ * @param salt - The salt used for decryption.
16
+ * @param encoded - The encoded string to decrypt.
17
+ * @returns The decrypted string.
18
+ */
19
+ export declare const decrypt: (salt: string, encoded: string) => string;
20
+ /**
21
+ * Encrypts a plain text string using a salt.
22
+ * @param salt - The salt used for encryption.
23
+ * @param text - The plain text string to encrypt.
24
+ * @returns The encrypted string in hexadecimal format.
25
+ */
26
+ export declare const encrypt: (salt: string, text: string) => string;
27
+ /**
28
+ * Returns the start and end dates of the current week.
29
+ * The week starts on Monday (00:00:00.000) and ends on Sunday (23:59:59.999).
30
+ *
31
+ * @returns An object containing:
32
+ * - `startOfWeek`: Date representing the beginning of the current week (Monday at midnight).
33
+ * - `endOfWeek`: Date representing the end of the current week (Sunday at 23:59:59.999).
34
+ */
35
+ export declare const getCurrentWeek: () => {
36
+ startOfWeek: Date;
37
+ endOfWeek: Date;
38
+ };
39
+ /**
40
+ * Consumes a readable stream and aggregates all data chunks into a single Buffer.
41
+ * * @param {stream.Readable} res - The incoming data stream.
42
+ * @returns {Promise<Buffer>} A promise that resolves to the complete binary data.
43
+ */
44
+ export declare function readAsBuffer(res: any): Promise<Buffer>;
45
+ /**
46
+ * Reads an HTTP response body in its entirety and converts it to a string.
47
+ * Useful for parsing XML error messages or small metadata responses.
48
+ * * @param {http.IncomingMessage} res - The HTTP response object.
49
+ * @returns {Promise<string>} The body content decoded as a string.
50
+ */
51
+ export declare function readAsString(res: any): Promise<string>;
52
+ /**
53
+ * Parses an XML string into a JavaScript object using fast-xml-parser.
54
+ * * @throws {S3XmlError} If the XML contains an <Error> tag, it throws the error body.
55
+ */
56
+ export declare const parseXml: (xml: string) => any;
57
+ /**
58
+ * Specifically extracts the CopyPartResult from an S3 XML response.
59
+ * Used during multipart copy operations or part uploads that return XML.
60
+ */
61
+ export declare const uploadPartParser: (xml: string) => any;
62
+ /**
63
+ * Removes various encodings of double quotes from the start and end of an ETag.
64
+ * * @description
65
+ * S3-compatible storage often returns ETags wrapped in literal quotes or
66
+ * HTML entities. This regex-based sanitizer ensures only the raw hash remains.
67
+ * @param {string} [etag=''] - The raw ETag string from headers or XML.
68
+ * @returns {string} The cleaned ETag.
69
+ */
70
+ export declare const sanitizeETag: (etag: string) => string;
71
+ //# sourceMappingURL=Mixins.d.ts.map
@@ -0,0 +1,19 @@
1
+ import type { NotificationType, NotificationOptions } from '../types/NotificationTypes';
2
+ import admin from 'firebase-admin';
3
+ import { BatchResponse } from 'firebase-admin/lib/messaging/messaging-api';
4
+ export default class PushNotifier {
5
+ static FirebaseAdmin: typeof admin;
6
+ static instance: number;
7
+ private static rootDir;
8
+ constructor(path: string);
9
+ /**
10
+ * Initiate sending push notifications
11
+ * @param tokens firebase user tokens
12
+ * @param message message to send
13
+ * @param metadata
14
+ * @param options
15
+ */
16
+ static sendNotifications(tokens: Array<string>, message: NotificationType, metadata?: any, options?: NotificationOptions): Promise<BatchResponse | undefined>;
17
+ static sendNotification(token: string, message: NotificationType, metadata?: any, options?: NotificationOptions): Promise<string | undefined>;
18
+ }
19
+ //# sourceMappingURL=PushNotifier.d.ts.map
@@ -0,0 +1,12 @@
1
+ import { Application, Request, Response, NextFunction } from 'express';
2
+ export default class RouterFactory {
3
+ /**
4
+ *
5
+ * @param app express application instance
6
+ * @param pathName root path of the application
7
+ * @param folderName path of the routers (default: routes)
8
+ */
9
+ static init(app: Application, pathName: string, folderName?: string, context?: string): Promise<void>;
10
+ static authenticate(req: Request, res: Response, next: NextFunction, grantPublicAccess?: boolean): Response<any, Record<string, any>> | undefined;
11
+ }
12
+ //# sourceMappingURL=RouterFactory.d.ts.map
@@ -0,0 +1,16 @@
1
+ import type { KafkaConfig } from "kafkajs";
2
+ export declare class ServeKafka {
3
+ private consumerPath;
4
+ private producerPath;
5
+ private config;
6
+ constructor(config: KafkaConfig, consumerPath?: string, producerPath?: string);
7
+ /**
8
+ * Starts all consumers by dynamically importing and initializing consumer classes.
9
+ */
10
+ startConsumers(): Promise<void>;
11
+ /**
12
+ * Starts all producers by dynamically importing and initializing producer classes.
13
+ */
14
+ startProducers(): Promise<void>;
15
+ }
16
+ //# sourceMappingURL=ServeKafka.d.ts.map
@@ -0,0 +1,11 @@
1
+ import { Request } from 'express';
2
+ import { RequestUserType } from '../types/BaseModelTypes';
3
+ /**
4
+ * generate jwt token from the payload
5
+ * @param payload
6
+ * @returns
7
+ */
8
+ export declare function generate(payload: object): string;
9
+ export declare function verify(token: string, secret?: string): RequestUserType;
10
+ export declare function decode(val: string | Request): RequestUserType;
11
+ //# sourceMappingURL=TokenGenerator.d.ts.map
@@ -0,0 +1,126 @@
1
+ import { UploadedFile } from 'express-fileupload';
2
+ import * as minio from 'minio';
3
+ import { ApplicationOptionType } from '..';
4
+ import { UploadedFileType, InitUpload, UploadChunk, CompleteUploadResult, UploadTypes, UploadPart } from '../types/UploadedFileType';
5
+ import { RemoveOptions } from 'minio';
6
+ export default class Uploader {
7
+ static client: minio.Client;
8
+ static clientEndpoint: string;
9
+ constructor();
10
+ /**
11
+ * Initializes the minIO client instance
12
+ */
13
+ static init(options: ApplicationOptionType): Promise<void>;
14
+ /**
15
+ * checks .env variables if properly configured
16
+ */
17
+ static hasValidConfig(options: ApplicationOptionType): boolean;
18
+ /**
19
+ *
20
+ * @param bucket {string} The bucket name in minIO
21
+ * @param dir {string} The directory where the files are stored
22
+ * @param uploads {Array<UploadedFile> | UploadedFile} file(s) to be uploaded
23
+ * @returns
24
+ */
25
+ static upload(bucket: string, dir: string, uploads: Array<UploadedFile> | UploadedFile): Promise<Array<UploadedFileType> | UploadedFileType>;
26
+ /**
27
+ *
28
+ * @param bucket {string} bucket name
29
+ * @param file {string} file directory
30
+ */
31
+ preview(bucket: string, file: string): Promise<void>;
32
+ static delete(bucketName: string, objectName: string, removeOpts?: RemoveOptions): Promise<void>;
33
+ /**
34
+ * Permanently cancels all pending multipart uploads within a specified S3/MinIO bucket.
35
+ * @description
36
+ * This is a cleanup utility. Incomplete multipart uploads occupy storage space but are not visible as objects. This method iterates through the bucket's "incomplete" stream and issues an abort command for each. Use this to recover storage or clear stuck uploads after a service interruption.
37
+ * @param {string} bucketName - The unique identifier of the target MinIO bucket.
38
+ * @returns {Promise<void>} Resolves when the stream has finished processing all abort requests.
39
+ * @throws {Error} If the bucket is inaccessible or the list operation fails.
40
+ * @example
41
+ * await Uploader.clearAllMultipartUploads('temp-uploads');
42
+ */
43
+ static clearAllMultipartUploads(bucketName: string): Promise<void>;
44
+ /**
45
+ * Starts a new multipart upload session and registers it in the local session cache.
46
+ * @description
47
+ * This method performs two actions:
48
+ * 1. Requests a new Multipart Upload ID from the MinIO/S3 server.
49
+ * 2. Initializes an internal tracking session in `uploadSessions` for part management.
50
+ * @param {string} bucket - Target bucket name.
51
+ * @param {string} fileName - The final destination filename/path.
52
+ * @param {Record<string, string>} [metadata={}] - Key-value pairs for S3 metadata.
53
+ * - Standard headers: `Content-Type`, `Cache-Control`, etc.
54
+ * - Custom tags: Use `X-Amz-meta-` prefix for custom attributes.
55
+ * @returns {Promise<InitUpload>}
56
+ * Returns the internal session ID and the provider's upload ID.
57
+ * @throws {Error} If the connection to MinIO fails or the bucket does not exist.
58
+ */
59
+ static initiateUpload(bucket: string, fileName: string, metadata?: Record<string, string>): Promise<InitUpload>;
60
+ /**
61
+ * Processes and uploads a single data part to an active multipart session.
62
+ * @description
63
+ * This method normalizes various input formats (Buffer, string, or Uint8Array) into a binary Buffer, dispatches the upload to MinIO via `uploadPart`, and updates the internal session state with the returned ETag.
64
+ * @param {string} uploadSessionId - The internal UUID generated during `initiateUpload`.
65
+ * @param {number} chunkNumber - The 1-based index of the part.
66
+ * @param {Buffer | string | Uint8Array} chunkData - The raw binary data or encoded string.
67
+ * @returns {Promise<UploadChunk>} Returns metadata about the uploaded part, including:
68
+ * - `etag`: The S3 identifier for this specific part (required for completion).
69
+ * - `uploadedPart`: The total count of parts successfully tracked in this session so far.
70
+ */
71
+ static uploadChunk(uploadSessionId: string, chunkNumber: number, chunkData: Buffer | string | Uint8Array): Promise<UploadChunk>;
72
+ /**
73
+ * Finalizes the multipart upload by assembling all uploaded parts into a single object.
74
+ * @description
75
+ * This method performs the final handshake with MinIO/S3. It:
76
+ * 1. Retrieves and sorts the accumulated ETags by part number (mandatory for S3 compliance).
77
+ * 2. Signals the storage server to merge the data parts.
78
+ * 3. Extracts file metadata (size, mime-type) from the session.
79
+ * 4. Purges the internal `uploadSessions` cache to prevent memory leaks.
80
+ * @param {string} uploadSessionId - The internal tracking ID of the session to be closed.
81
+ * @returns {Promise<Object>} A curated result object containing:
82
+ * - `etag`: The final entity tag for the completed object.
83
+ * - `location`: The public/internal URL of the uploaded file.
84
+ * - `fileSize`: Parsed size from the 'X-Amz-meta-filesize' metadata.
85
+ * @throws {Error} If parts are missing, the session is not found, or S3 assembly fails.
86
+ */
87
+ static completeUpload(uploadSessionId: string): Promise<CompleteUploadResult>;
88
+ /**
89
+ * Streams an object from storage directly to an HTTP response.
90
+ * @description
91
+ * Fetches object metadata (stat) to populate necessary download headers before
92
+ * piping the data stream to the client. This avoids loading the entire file
93
+ * into memory, making it efficient for large file transfers.
94
+ * * @param {Response} res - The Express/Node.js response object.
95
+ * @param {UploadTypes} options - Configuration object containing:
96
+ * - `bucket`: Target bucket name.
97
+ * - `objectKey`: The internal storage path (e.g., 'stream/123').
98
+ * - `objectName`: The "friendly" filename for the user's browser.
99
+ * @returns {Promise<void>} Resolves once the stream has been successfully piped.
100
+ * @throws {Error} If the object does not exist or metadata cannot be retrieved.
101
+ */
102
+ static streamDownload(res: any, { bucket, objectKey, objectName }: UploadTypes): Promise<void>;
103
+ /**
104
+ * Executes a low-level Multipart Upload Part request.
105
+ * * @description
106
+ * This is a custom wrapper around the S3/MinIO PUT Object Part API. It manually constructs the query parameters and headers required for a part upload. Crucially, it handles inconsistent server responses by attempting to extract the ETag from both the response XML body and the HTTP headers.
107
+ * @param {Object} partConfig - Configuration for the specific part.
108
+ * @param {string} partConfig.bucketName - Target bucket.
109
+ * @param {string} partConfig.objectName - The internal path/key of the object.
110
+ * @param {string} partConfig.uploadID - The ID generated by `initiateNewMultipartUpload`.
111
+ * @param {number} partConfig.partNumber - 1-based index of the part.
112
+ * @param {unknown} partConfig.headers - HTTP headers (e.g., Content-Length, Content-MD5).
113
+ * @param {any} [payload] - The binary data buffer for this part.
114
+ * @returns {Promise<UploadPart>}
115
+ * Returns a sanitized ETag required for the final `completeUpload` call.
116
+ * @throws {Error} If no ETag is found in the response or the network request fails.
117
+ */
118
+ static uploadPart: (partConfig: {
119
+ bucketName: string;
120
+ objectName: string;
121
+ uploadID: string;
122
+ partNumber: number;
123
+ headers: unknown;
124
+ }, payload?: any) => Promise<UploadPart>;
125
+ }
126
+ //# sourceMappingURL=Uploader.d.ts.map
@@ -0,0 +1,27 @@
1
+ import { ServerWebSocket } from 'bun';
2
+ import BaseSocketHandler from './BaseSocketHandler';
3
+ export default class WebSocketServer {
4
+ static socketHandlers: Array<{
5
+ path: string;
6
+ handler: BaseSocketHandler;
7
+ }>;
8
+ static init(port: number | undefined, dir: string, folder?: string): Array<{
9
+ path: string;
10
+ handler: BaseSocketHandler;
11
+ }>;
12
+ /**
13
+ *
14
+ * @returns
15
+ */
16
+ static getSocketHandlers(): Array<{
17
+ path: string;
18
+ handler: BaseSocketHandler;
19
+ }>;
20
+ /**
21
+ *
22
+ * @param path
23
+ * @returns
24
+ */
25
+ static getHandler(path: string): ServerWebSocket | null;
26
+ }
27
+ //# sourceMappingURL=WebSocketServer.d.ts.map
@@ -0,0 +1,67 @@
1
+ import { ApplicationOptionType } from "../types/ApplicationOptionType";
2
+ import { S3, DeleteObjectRequest } from "@aws-sdk/client-s3";
3
+ import { AttachmentMetadataType } from "../types/AttachmentMetadataTypes";
4
+ export default class UploaderS3 {
5
+ static client: S3;
6
+ static uploadSessions: Record<string, string>;
7
+ /**
8
+ * Initializes the S3 client instance
9
+ */
10
+ static init(options: ApplicationOptionType): Promise<void>;
11
+ /**
12
+ * Validates configuration options
13
+ */
14
+ static hasValidConfig(options: ApplicationOptionType): boolean;
15
+ /**
16
+ * Lists all available S3 buckets
17
+ */
18
+ static listBuckets(): Promise<void>;
19
+ /**
20
+ * Starts a new multipart upload session
21
+ * @param bucketName S3 bucket name
22
+ * @param key Key for the object in S3
23
+ */
24
+ static startMultipartUpload(bucketName: string, key: string): Promise<string>;
25
+ /**
26
+ * Uploads a file part to S3
27
+ * @param bucketName S3 bucket name
28
+ * @param key Key for the object in S3
29
+ * @param uploadId Multipart upload session ID
30
+ * @param partNumber Part number for the upload
31
+ * @param chunk Chunk of the file to upload
32
+ */
33
+ static uploadPart(bucketName: string, key: string, uploadId: string, partNumber: number, chunk: Buffer): Promise<string | null>;
34
+ /**
35
+ * Completes a multipart upload
36
+ * @param bucketName S3 bucket name
37
+ * @param key Key for the object in S3
38
+ * @param uploadId Multipart upload session ID
39
+ * @param parts List of uploaded parts
40
+ */
41
+ static completeMultipartUpload(bucketName: string, key: string, uploadId: string, parts: {
42
+ PartNumber: number;
43
+ ETag: string;
44
+ }[]): Promise<AttachmentMetadataType>;
45
+ /**
46
+ * Aborts a multipart upload
47
+ * @param bucketName S3 bucket name
48
+ * @param key Key for the object in S3
49
+ * @param uploadId Multipart upload session ID
50
+ */
51
+ static abortMultipartUpload(bucketName: string, key: string, uploadId: string): Promise<void>;
52
+ /**
53
+ * Directly uploads a file to S3 without chunking
54
+ * @param bucketName S3 bucket name
55
+ * @param key Key for the object in S3
56
+ * @param fileContent The content of the file to upload
57
+ * @param contentType The MIME type of the file
58
+ */
59
+ static uploadFile(bucketName: string, key: string, fileContent: Buffer | Uint8Array | Blob | string, contentType: string): Promise<AttachmentMetadataType>;
60
+ /**
61
+ * Deletes all incomplete multipart uploads in the specified bucket
62
+ * @param bucketName S3 bucket name
63
+ */
64
+ static deleteIncompleteUploads(bucketName: string): Promise<void>;
65
+ static deleteFile(request: DeleteObjectRequest): Promise<void>;
66
+ }
67
+ //# sourceMappingURL=uploader-s3.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ccci/micro-server",
3
- "version": "1.1.14",
3
+ "version": "1.1.15",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",