@ccci/micro-server 1.0.243 → 1.1.3

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 (36) hide show
  1. package/dist/decorators/Endpoints.d.ts +12 -0
  2. package/dist/index.d.ts +33 -0
  3. package/dist/index.js +300052 -0
  4. package/dist/types/ApplicationOptionType.d.ts +36 -0
  5. package/dist/types/AttachmentMetadataTypes.d.ts +23 -0
  6. package/dist/types/BaseControllerTypes.d.ts +42 -0
  7. package/dist/types/BaseModelTypes.d.ts +41 -0
  8. package/dist/types/BaseRouterTypes.d.ts +9 -0
  9. package/dist/types/BaseSocketType.d.ts +6 -0
  10. package/dist/types/BrokerType.d.ts +13 -0
  11. package/dist/types/NotificationTypes.d.ts +9 -0
  12. package/dist/types/UploadedFileType.d.ts +11 -0
  13. package/dist/utils/ApplicationServer.d.ts +30 -0
  14. package/dist/utils/BaseAuthenticatorModel.d.ts +7 -0
  15. package/dist/utils/BaseConsumer.d.ts +44 -0
  16. package/dist/utils/BaseController.d.ts +97 -0
  17. package/dist/utils/BaseControllerHelper.d.ts +27 -0
  18. package/dist/utils/BaseKafka.d.ts +37 -0
  19. package/dist/utils/BaseModel.d.ts +44 -0
  20. package/dist/utils/BaseProducer.d.ts +42 -0
  21. package/dist/utils/BaseRouter.d.ts +91 -0
  22. package/dist/utils/BaseSocketHandler.d.ts +37 -0
  23. package/dist/utils/DatabaseConnector.d.ts +26 -0
  24. package/dist/utils/ErrorHandler.d.ts +5 -0
  25. package/dist/utils/IBaseModel.d.ts +9 -0
  26. package/dist/utils/Logger.d.ts +8 -0
  27. package/dist/utils/Mailer.d.ts +23 -0
  28. package/dist/utils/Mixins.d.ts +39 -0
  29. package/dist/utils/PushNotifier.d.ts +19 -0
  30. package/dist/utils/RouterFactory.d.ts +12 -0
  31. package/dist/utils/ServeKafka.d.ts +16 -0
  32. package/dist/utils/TokenGenerator.d.ts +11 -0
  33. package/dist/utils/Uploader.d.ts +33 -0
  34. package/dist/utils/WebSocketServer.d.ts +29 -0
  35. package/dist/utils/uploader-s3.d.ts +68 -0
  36. package/package.json +1 -1
@@ -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,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, secret?: string): RequestUserType;
10
+ export declare function decode(val: string | Request): RequestUserType;
11
+ //# sourceMappingURL=TokenGenerator.d.ts.map
@@ -0,0 +1,33 @@
1
+ import { UploadedFile } from 'express-fileupload';
2
+ import * as minio from 'minio';
3
+ import { ApplicationOptionType } from '..';
4
+ import { UploadedFileType } from '@/types/UploadedFileType';
5
+ import { RemoveOptions } from 'minio';
6
+ export default class Uploader {
7
+ static client: minio.Client;
8
+ constructor();
9
+ /**
10
+ * Initializes the minIO client instance
11
+ */
12
+ static init(options: ApplicationOptionType): Promise<void>;
13
+ /**
14
+ * checks .env variables if properly configured
15
+ */
16
+ static hasValidConfig(options: ApplicationOptionType): boolean;
17
+ /**
18
+ *
19
+ * @param bucket {string} The bucket name in minIO
20
+ * @param dir {string} The directory where the files are stored
21
+ * @param uploads {Array<UploadedFile> | UploadedFile} file(s) to be uploaded
22
+ * @returns
23
+ */
24
+ static upload(bucket: string, dir: string, uploads: Array<UploadedFile> | UploadedFile): Promise<Array<UploadedFileType> | UploadedFileType>;
25
+ /**
26
+ *
27
+ * @param bucket {string} bucket name
28
+ * @param file {string} file directory
29
+ */
30
+ preview(bucket: string, file: string): Promise<void>;
31
+ static delete(bucketName: string, objectName: string, removeOpts?: RemoveOptions): Promise<void>;
32
+ }
33
+ //# 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,68 @@
1
+ /// <reference types="node" />
2
+ import { ApplicationOptionType } from "@/types/ApplicationOptionType";
3
+ import { S3, DeleteObjectRequest } 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
+ static deleteFile(request: DeleteObjectRequest): Promise<void>;
67
+ }
68
+ //# 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.243",
3
+ "version": "1.1.3",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",