@ccci/micro-server 1.0.168 → 1.0.170

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 (35) hide show
  1. package/dist/decorators/Endpoints.d.ts +12 -0
  2. package/dist/index.js +27 -3
  3. package/dist/types/ApplicationOptionType.d.ts +36 -0
  4. package/dist/types/AttachmentMetadataTypes.d.ts +9 -0
  5. package/dist/types/BaseControllerTypes.d.ts +42 -0
  6. package/dist/types/BaseModelTypes.d.ts +33 -0
  7. package/dist/types/BaseRouterTypes.d.ts +9 -0
  8. package/dist/types/BaseSocketType.d.ts +6 -0
  9. package/dist/types/BrokerType.d.ts +13 -0
  10. package/dist/types/NotificationTypes.d.ts +9 -0
  11. package/dist/types/UploadedFileType.d.ts +9 -0
  12. package/dist/utils/ApplicationServer.d.ts +27 -0
  13. package/dist/utils/BaseAuthenticatorModel.d.ts +7 -0
  14. package/dist/utils/BaseConsumer.d.ts +44 -0
  15. package/dist/utils/BaseController.d.ts +96 -0
  16. package/dist/utils/BaseControllerHelper.d.ts +27 -0
  17. package/dist/utils/BaseKafka.d.ts +37 -0
  18. package/dist/utils/BaseModel.d.ts +37 -0
  19. package/dist/utils/BaseProducer.d.ts +42 -0
  20. package/dist/utils/BaseRouter.d.ts +91 -0
  21. package/dist/utils/BaseSocketHandler.d.ts +37 -0
  22. package/dist/utils/DatabaseConnector.d.ts +26 -0
  23. package/dist/utils/ErrorHandler.d.ts +5 -0
  24. package/dist/utils/IBaseModel.d.ts +9 -0
  25. package/dist/utils/Logger.d.ts +7 -0
  26. package/dist/utils/Mailer.d.ts +23 -0
  27. package/dist/utils/Mixins.d.ts +39 -0
  28. package/dist/utils/PushNotifier.d.ts +19 -0
  29. package/dist/utils/RouterFactory.d.ts +12 -0
  30. package/dist/utils/ServeKafka.d.ts +16 -0
  31. package/dist/utils/TokenGenerator.d.ts +11 -0
  32. package/dist/utils/Uploader.d.ts +31 -0
  33. package/dist/utils/WebSocketServer.d.ts +29 -0
  34. package/dist/utils/uploader-s3.d.ts +67 -0
  35. package/package.json +1 -1
@@ -0,0 +1,12 @@
1
+ export declare const endpoint: (target: any, methodName: string, descriptor: PropertyDescriptor) => void;
2
+ export declare const PublicAccess: <T extends new (...args: any[]) => {}>(constructor: T) => {
3
+ new (...args: any[]): {
4
+ grantPublicAccess: boolean;
5
+ };
6
+ } & T;
7
+ export declare const PrivateAccess: <T extends new (...args: any[]) => {}>(constructor: T) => {
8
+ new (...args: any[]): {
9
+ grantPublicAccess: boolean;
10
+ };
11
+ } & T;
12
+ //# sourceMappingURL=Endpoints.d.ts.map
package/dist/index.js CHANGED
@@ -297575,7 +297575,8 @@ function ConstructQuery(query) {
297575
297575
  let where2 = {};
297576
297576
  const pairs = query.search.split(",");
297577
297577
  pairs.forEach((field) => {
297578
- if (field.indexOf("|") > -1) {
297578
+ if (field.indexOf("$") > -1) {
297579
+ } else if (field.indexOf("|") > -1) {
297579
297580
  if (!where2.hasOwnProperty(Op.or))
297580
297581
  where2[Op.or] = [];
297581
297582
  let orFields = field.split("|");
@@ -297648,7 +297649,29 @@ function ConstructQuery(query) {
297648
297649
  }
297649
297650
  if (query.includes) {
297650
297651
  let data = query.includes.split(",");
297651
- let includes = data.filter((el) => el.indexOf(".") == -1);
297652
+ let includes = [];
297653
+ let toplevel = data.filter((el) => el.indexOf(".") == -1);
297654
+ toplevel.forEach((top) => {
297655
+ let association = { association: top };
297656
+ if (query.search) {
297657
+ const queries = query.search.split(",");
297658
+ Logger.info(`queries: ${JSON.stringify(queries)}`);
297659
+ let injectable = queries.find((q) => q.indexOf("$") > -1 && q.indexOf(top) > -1);
297660
+ Logger.info(`injectable: ${JSON.stringify(injectable)}`);
297661
+ if (injectable) {
297662
+ injectable = injectable.replaceAll("$", "");
297663
+ let nested2 = injectable.split(".");
297664
+ Logger.info(`nested: ${JSON.stringify(nested2)}`);
297665
+ let pair = nested2[1].split(":");
297666
+ Logger.info(`pair: ${JSON.stringify(pair)}`);
297667
+ let associationkey = pair[0];
297668
+ Logger.info(`associationkey: ${JSON.stringify(associationkey)}`);
297669
+ association.where = { associationkey: pair[1] };
297670
+ Logger.info(`association.where: ${JSON.stringify(association.where)}`);
297671
+ }
297672
+ }
297673
+ includes.push(association);
297674
+ });
297652
297675
  let nested = data.filter((el) => el.indexOf(".") > -1);
297653
297676
  nested.forEach((nest) => {
297654
297677
  let keypair = nest.split(".");
@@ -297663,6 +297686,7 @@ function ConstructQuery(query) {
297663
297686
  }
297664
297687
  includes.push(temp);
297665
297688
  });
297689
+ Logger.info(`INCLUDES: ${JSON.stringify(includes)}`);
297666
297690
  options.includes = includes;
297667
297691
  }
297668
297692
  if (query.paranoid) {
@@ -297772,7 +297796,7 @@ class BaseController {
297772
297796
  try {
297773
297797
  let query = req.query;
297774
297798
  let options = ConstructQuery(query);
297775
- Logger.info(`WHERE CLAUSE: ${options.where}`);
297799
+ Logger.info(`WHERE CLAUSE: ${JSON.stringify(options.where)}`);
297776
297800
  let response4 = null;
297777
297801
  if (!response4) {
297778
297802
  response4 = await this._model?.findAndCountAll({
@@ -0,0 +1,36 @@
1
+ export type ApplicationOptionType = {
2
+ routeContext?: string;
3
+ configDir?: string;
4
+ modelDir?: string;
5
+ controllerDir?: string;
6
+ routeDir?: string;
7
+ websocketPort?: number;
8
+ websocketDir?: string;
9
+ enableRedis?: boolean;
10
+ enableMinio?: boolean;
11
+ enableKafka?: boolean;
12
+ enableS3?: boolean;
13
+ enableWebSocket?: boolean;
14
+ enableFirebase?: boolean;
15
+ enableEmail?: boolean;
16
+ clientId?: string;
17
+ brokers?: string[];
18
+ consumersPath?: string;
19
+ producersPath?: string;
20
+ minioHost?: string;
21
+ minioPort?: number;
22
+ minioAccessKey?: string;
23
+ minioSecretKey?: string;
24
+ minioUseSSL?: boolean;
25
+ smtpService?: string;
26
+ smtpHost?: string;
27
+ smtpUser?: string;
28
+ smtpPassword?: string;
29
+ enablePushNotifications?: boolean;
30
+ s3ForcePathStyle?: boolean;
31
+ s3Endpoint?: string;
32
+ s3region?: string;
33
+ s3AccessKeyId?: string;
34
+ s3SecretAccessKey?: string;
35
+ };
36
+ //# sourceMappingURL=ApplicationOptionType.d.ts.map
@@ -0,0 +1,9 @@
1
+ export type AttachmentMetadataType = {
2
+ Bucket?: string;
3
+ Etag?: string;
4
+ Key?: string;
5
+ Location?: string;
6
+ MimeType?: string;
7
+ };
8
+ export declare const mimeTypes: Record<string, string>;
9
+ //# 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,33 @@
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
+ };
33
+ //# 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,9 @@
1
+ export type UploadedFileType = {
2
+ etag?: string;
3
+ path?: string;
4
+ bucket?: string;
5
+ directory?: string;
6
+ objectName?: string;
7
+ mimeType?: string;
8
+ };
9
+ //# sourceMappingURL=UploadedFileType.d.ts.map
@@ -0,0 +1,27 @@
1
+ import { Application } from 'express';
2
+ import BaseSocketHandler from './BaseSocketHandler';
3
+ import { ApplicationOptionType } from '@/types/ApplicationOptionType';
4
+ /**
5
+ * Application Sever class
6
+ */
7
+ export default class ApplicationServer {
8
+ static app: Application;
9
+ static socketHandlers: Array<{
10
+ path: string;
11
+ handler: BaseSocketHandler;
12
+ }>;
13
+ /**
14
+ * Initializes the application server
15
+ * @param {number} port port for the micro service
16
+ * @param {ApplicationOptionType} options additional server configuration
17
+ * @param {Array<String>} sync models to be sync to the database
18
+ *
19
+ */
20
+ static bootstrap(port: number, options?: ApplicationOptionType, sync?: Array<string> | Boolean): Promise<void>;
21
+ static getInstance(): Application;
22
+ static getWebsocketHandlers(): Array<{
23
+ path: string;
24
+ handler: any;
25
+ }>;
26
+ }
27
+ //# 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 { 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
+ private consumer;
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): Promise<void>;
43
+ }
44
+ //# sourceMappingURL=BaseConsumer.d.ts.map
@@ -0,0 +1,96 @@
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
+ * ```js
14
+ * Controller.find(req, res, next)
15
+ * ```
16
+ * @param req
17
+ * @param res
18
+ * @param next
19
+ */
20
+ find(req: Request, res: Response, next?: NextFunction): Promise<ResponseType>;
21
+ /**
22
+ * Search for a single instance by its primary key.
23
+ * This applies LIMIT 1, so the listener will always be called with a single instance.
24
+ * @param req
25
+ * @param res
26
+ * @param next
27
+ */
28
+ findById(req: Request, res: Response, next?: NextFunction): Promise<ResponseType>;
29
+ /**
30
+ *
31
+ * @param req
32
+ * @param res
33
+ * @param next
34
+ */
35
+ create(req: Request, res: Response, next?: NextFunction): Promise<ResponseType>;
36
+ /**
37
+ * 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.)
38
+ * @param req
39
+ * @param res
40
+ * @param next
41
+ */
42
+ update(req: Request, res: Response, next?: NextFunction): Promise<ResponseType>;
43
+ /**
44
+ * Delete multiple instances, or set their deletedAt timestamp to the current time if paranoid is enabled.
45
+ * @param req
46
+ * @param res
47
+ * @param next
48
+ */
49
+ delete(req: Request, res: Response, next?: NextFunction): Promise<ResponseType>;
50
+ /**
51
+ * Find all the rows matching your query, within a specified offset / limit,
52
+ * and get the total number of rows matching your query.
53
+ * ```js
54
+ * Controller.find(req, res, next)
55
+ * ```
56
+ * @param req
57
+ * @param res
58
+ * @param next
59
+ */
60
+ archives(req: Request, res: Response, next?: NextFunction): Promise<ResponseType>;
61
+ restore(req: Request, res: Response, next?: NextFunction): Promise<ResponseType>;
62
+ /**
63
+ * count total number of records
64
+ * @param req
65
+ * @param res
66
+ * @param next
67
+ * @returns
68
+ */
69
+ count(req: Request, res: Response, next?: NextFunction): Promise<{
70
+ count: number;
71
+ }>;
72
+ /**
73
+ * Return a basic statistics based on the query and group provided.
74
+ * ```js
75
+ * Controller.find(req, res, next)
76
+ * ```
77
+ * @param req
78
+ * @param res
79
+ * @param next
80
+ */
81
+ stats(req: Request, res: Response, next?: NextFunction): Promise<any>;
82
+ /**
83
+ * ###############################################################
84
+ * ###################### LIFE CYCLE HOOKS #######################
85
+ * ###############################################################
86
+ */
87
+ beforeCreate(req: Request): Promise<void>;
88
+ afterCreate(req: Request, rec: any): Promise<void>;
89
+ beforeUpdate(req: Request): Promise<void>;
90
+ afterUpdate(req: Request, rec: any, orig: any): Promise<void>;
91
+ beforeDelete(req: Request): Promise<void>;
92
+ afterDelete(req: Request, rec: any): Promise<void>;
93
+ beforeFind(req: Request): Promise<void>;
94
+ afterFind(req: Request): Promise<void>;
95
+ }
96
+ //# 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,37 @@
1
+ import { DataTypes, Model } from 'sequelize';
2
+ import type { ModelAttributes } from "sequelize";
3
+ import type IBaseModel from './IBaseModel';
4
+ export default class BaseModel extends Model implements IBaseModel {
5
+ id?: number;
6
+ /**
7
+ * Sets common model attributes
8
+ * @returns
9
+ */
10
+ static getCommonAttributes(defaultAttributes: boolean): {
11
+ createdById: {
12
+ type: DataTypes.IntegerDataType;
13
+ comment: string;
14
+ };
15
+ updatedById: {
16
+ type: DataTypes.IntegerDataType;
17
+ comment: string;
18
+ };
19
+ isActive: {
20
+ type: DataTypes.AbstractDataType;
21
+ comment: string;
22
+ allowNull: boolean;
23
+ defaultValue: boolean;
24
+ };
25
+ } | null;
26
+ static getCommonAssociations(): void;
27
+ /**
28
+ *
29
+ * @param {ModelAttributes} fields table columns
30
+ * @param {string} tableName name of the table
31
+ * @param {string} schema this will overwrite the default schema
32
+ * @param {boolean} paranoid paranoid option. defaults to true
33
+ * @param {boolean} defaultAttributes need to inherit default attributes. defaults to true
34
+ */
35
+ static initialize(fields: ModelAttributes, tableName: string, schema?: string, paranoid?: boolean, defaultAttributes?: boolean): void;
36
+ }
37
+ //# 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,37 @@
1
+ /// <reference types="bun-types" />
2
+ /// <reference types="node" />
3
+ /// <reference types="bun-types" />
4
+ import type { Server, ServerWebSocket } from 'bun';
5
+ export default class BaseSocketHandler {
6
+ static channel: string;
7
+ static server: Server;
8
+ static websocket: ServerWebSocket;
9
+ /**
10
+ *
11
+ * @param req {Request}
12
+ * @param server {Server}
13
+ * @returns
14
+ */
15
+ upgrade(req: Request, server: Server): Promise<void>;
16
+ /**
17
+ *
18
+ * @param ws {ServerWebSocket}
19
+ * @param message {String}
20
+ */
21
+ accept(ws: ServerWebSocket, message: string): Promise<void>;
22
+ /**
23
+ *
24
+ * @param ws {ServerWebSocket}
25
+ */
26
+ connect(ws: ServerWebSocket): Promise<void>;
27
+ /**
28
+ *
29
+ * @param ws {ServerWebSocket}
30
+ * @param code {number}
31
+ * @param reason {reason}
32
+ */
33
+ disconnect(ws: ServerWebSocket, code: number, reason: string): Promise<void>;
34
+ getInstance(): ServerWebSocket;
35
+ static parse(url: String): any;
36
+ }
37
+ //# 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): Promise<void>;
23
+ static syncAll(force?: 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,7 @@
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
+ }
7
+ //# 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,39 @@
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
+ //# 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): RequestUserType;
10
+ export declare function decode(val: string | Request): RequestUserType;
11
+ //# sourceMappingURL=TokenGenerator.d.ts.map
@@ -0,0 +1,31 @@
1
+ import { UploadedFile } from 'express-fileupload';
2
+ import * as minio from 'minio';
3
+ import { ApplicationOptionType } from '..';
4
+ import { UploadedFileType } from '@/types/UploadedFileType';
5
+ export default class Uploader {
6
+ static client: minio.Client;
7
+ constructor();
8
+ /**
9
+ * Initializes the minIO client instance
10
+ */
11
+ static init(options: ApplicationOptionType): Promise<void>;
12
+ /**
13
+ * checks .env variables if properly configured
14
+ */
15
+ static hasValidConfig(options: ApplicationOptionType): boolean;
16
+ /**
17
+ *
18
+ * @param bucket {string} The bucket name in minIO
19
+ * @param dir {string} The directory where the files are stored
20
+ * @param uploads {Array<UploadedFile> | UploadedFile} file(s) to be uploaded
21
+ * @returns
22
+ */
23
+ static upload(bucket: string, dir: string, uploads: Array<UploadedFile> | UploadedFile): Promise<Array<UploadedFileType>>;
24
+ /**
25
+ *
26
+ * @param bucket {string} bucket name
27
+ * @param file {string} file directory
28
+ */
29
+ preview(bucket: string, file: string): Promise<void>;
30
+ }
31
+ //# sourceMappingURL=Uploader.d.ts.map
@@ -0,0 +1,29 @@
1
+ /// <reference types="bun-types" />
2
+ /// <reference types="bun-types" />
3
+ import { ServerWebSocket } from 'bun';
4
+ import BaseSocketHandler from './BaseSocketHandler';
5
+ export default class WebSocketServer {
6
+ static socketHandlers: Array<{
7
+ path: string;
8
+ handler: BaseSocketHandler;
9
+ }>;
10
+ static init(port: number | undefined, dir: string, folder?: string): Array<{
11
+ path: string;
12
+ handler: BaseSocketHandler;
13
+ }>;
14
+ /**
15
+ *
16
+ * @returns
17
+ */
18
+ static getSocketHandlers(): Array<{
19
+ path: string;
20
+ handler: BaseSocketHandler;
21
+ }>;
22
+ /**
23
+ *
24
+ * @param path
25
+ * @returns
26
+ */
27
+ static getHandler(path: string): ServerWebSocket | null;
28
+ }
29
+ //# sourceMappingURL=WebSocketServer.d.ts.map
@@ -0,0 +1,67 @@
1
+ /// <reference types="node" />
2
+ import { ApplicationOptionType } from "@/types/ApplicationOptionType";
3
+ import { S3 } from "@aws-sdk/client-s3";
4
+ import { AttachmentMetadataType } from "@/types/AttachmentMetadataTypes";
5
+ export default class UploaderS3 {
6
+ static client: S3;
7
+ static uploadSessions: Record<string, string>;
8
+ /**
9
+ * Initializes the S3 client instance
10
+ */
11
+ static init(options: ApplicationOptionType): Promise<void>;
12
+ /**
13
+ * Validates configuration options
14
+ */
15
+ static hasValidConfig(options: ApplicationOptionType): boolean;
16
+ /**
17
+ * Lists all available S3 buckets
18
+ */
19
+ static listBuckets(): Promise<void>;
20
+ /**
21
+ * Starts a new multipart upload session
22
+ * @param bucketName S3 bucket name
23
+ * @param key Key for the object in S3
24
+ */
25
+ static startMultipartUpload(bucketName: string, key: string): Promise<string>;
26
+ /**
27
+ * Uploads a file part to S3
28
+ * @param bucketName S3 bucket name
29
+ * @param key Key for the object in S3
30
+ * @param uploadId Multipart upload session ID
31
+ * @param partNumber Part number for the upload
32
+ * @param chunk Chunk of the file to upload
33
+ */
34
+ static uploadPart(bucketName: string, key: string, uploadId: string, partNumber: number, chunk: Buffer): Promise<string | null>;
35
+ /**
36
+ * Completes a multipart upload
37
+ * @param bucketName S3 bucket name
38
+ * @param key Key for the object in S3
39
+ * @param uploadId Multipart upload session ID
40
+ * @param parts List of uploaded parts
41
+ */
42
+ static completeMultipartUpload(bucketName: string, key: string, uploadId: string, parts: {
43
+ PartNumber: number;
44
+ ETag: string;
45
+ }[]): Promise<AttachmentMetadataType>;
46
+ /**
47
+ * Aborts a multipart upload
48
+ * @param bucketName S3 bucket name
49
+ * @param key Key for the object in S3
50
+ * @param uploadId Multipart upload session ID
51
+ */
52
+ static abortMultipartUpload(bucketName: string, key: string, uploadId: string): Promise<void>;
53
+ /**
54
+ * Directly uploads a file to S3 without chunking
55
+ * @param bucketName S3 bucket name
56
+ * @param key Key for the object in S3
57
+ * @param fileContent The content of the file to upload
58
+ * @param contentType The MIME type of the file
59
+ */
60
+ static uploadFile(bucketName: string, key: string, fileContent: Buffer | Uint8Array | Blob | string, contentType: string): Promise<AttachmentMetadataType>;
61
+ /**
62
+ * Deletes all incomplete multipart uploads in the specified bucket
63
+ * @param bucketName S3 bucket name
64
+ */
65
+ static deleteIncompleteUploads(bucketName: string): 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.0.168",
3
+ "version": "1.0.170",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",