core-services-sdk 1.3.36 → 1.3.38

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 (52) hide show
  1. package/package.json +2 -2
  2. package/src/fastify/error-codes.js +2 -4
  3. package/src/fastify/error-handlers/with-error-handling.js +5 -6
  4. package/src/http/HttpError.js +10 -29
  5. package/src/http/http.js +2 -3
  6. package/tests/fastify/error-handler.unit.test.js +3 -11
  7. package/tests/fastify/error-handlers/with-error-handling.test.js +3 -6
  8. package/tests/http/HttpError.unit.test.js +13 -17
  9. package/tsconfig.json +3 -1
  10. package/types/core/combine-unique-arrays.d.ts +1 -1
  11. package/types/core/index.d.ts +9 -9
  12. package/types/core/normalize-array-operators.d.ts +1 -1
  13. package/types/core/normalize-min-max.d.ts +16 -10
  14. package/types/core/normalize-phone-number.d.ts +30 -24
  15. package/types/core/normalize-premitives-types-or-default.d.ts +17 -4
  16. package/types/core/normalize-to-array.d.ts +1 -1
  17. package/types/core/otp-generators.d.ts +22 -18
  18. package/types/core/regex-utils.d.ts +1 -1
  19. package/types/core/sanitize-objects.d.ts +13 -4
  20. package/types/crypto/crypto.d.ts +31 -18
  21. package/types/crypto/encryption.d.ts +14 -6
  22. package/types/crypto/index.d.ts +2 -2
  23. package/types/fastify/error-codes.d.ts +11 -16
  24. package/types/fastify/error-handlers/with-error-handling.d.ts +26 -15
  25. package/types/fastify/index.d.ts +2 -2
  26. package/types/http/HttpError.d.ts +67 -76
  27. package/types/http/http-method.d.ts +6 -6
  28. package/types/http/http.d.ts +58 -34
  29. package/types/http/index.d.ts +4 -4
  30. package/types/http/responseType.d.ts +6 -6
  31. package/types/ids/generators.d.ts +28 -28
  32. package/types/ids/index.d.ts +2 -2
  33. package/types/ids/prefixes.d.ts +54 -54
  34. package/types/index.d.ts +11 -11
  35. package/types/logger/get-logger.d.ts +23 -21
  36. package/types/logger/index.d.ts +1 -1
  37. package/types/mailer/index.d.ts +2 -2
  38. package/types/mailer/mailer.service.d.ts +29 -19
  39. package/types/mailer/transport.factory.d.ts +43 -43
  40. package/types/mongodb/connect.d.ts +12 -7
  41. package/types/mongodb/dsl-to-mongo.d.ts +2 -1
  42. package/types/mongodb/index.d.ts +5 -5
  43. package/types/mongodb/initialize-mongodb.d.ts +18 -13
  44. package/types/mongodb/paginate.d.ts +23 -13
  45. package/types/mongodb/validate-mongo-uri.d.ts +1 -1
  46. package/types/rabbit-mq/index.d.ts +1 -1
  47. package/types/rabbit-mq/rabbit-mq.d.ts +62 -37
  48. package/types/templates/index.d.ts +1 -1
  49. package/types/templates/template-loader.d.ts +7 -3
  50. package/types/util/context.d.ts +53 -53
  51. package/types/util/index.d.ts +6 -6
  52. package/types/util/mask-sensitive.d.ts +14 -2
package/types/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- export * from "./core/index.js";
2
- export * from "./crypto/index.js";
3
- export * from "./fastify/index.js";
4
- export * from "./http/index.js";
5
- export * from "./ids/index.js";
6
- export * from "./mongodb/index.js";
7
- export * from "./logger/index.js";
8
- export * from "./mailer/index.js";
9
- export * from "./rabbit-mq/index.js";
10
- export * from "./templates/index.js";
11
- export * from "./util/index.js";
1
+ export * from './core/index.js'
2
+ export * from './crypto/index.js'
3
+ export * from './fastify/index.js'
4
+ export * from './http/index.js'
5
+ export * from './ids/index.js'
6
+ export * from './mongodb/index.js'
7
+ export * from './logger/index.js'
8
+ export * from './mailer/index.js'
9
+ export * from './rabbit-mq/index.js'
10
+ export * from './templates/index.js'
11
+ export * from './util/index.js'
@@ -1,23 +1,25 @@
1
- export function getLogger(option: true | any | undefined): import("pino").Logger | typeof dummyLogger;
1
+ export function getLogger(
2
+ option: true | any | undefined,
3
+ ): import('pino').Logger | typeof dummyLogger
2
4
  declare namespace dummyLogger {
3
- function info(): void;
4
- function warn(): void;
5
- function trace(): void;
6
- function debug(): void;
7
- function error(): void;
8
- function fatal(): void;
9
- function levels(): void;
10
- function silent(): void;
11
- function child(): {
12
- info: () => void;
13
- warn: () => void;
14
- trace: () => void;
15
- debug: () => void;
16
- error: () => void;
17
- fatal: () => void;
18
- levels: () => void;
19
- silent: () => void;
20
- child(): /*elided*/ any;
21
- };
5
+ function info(): void
6
+ function warn(): void
7
+ function trace(): void
8
+ function debug(): void
9
+ function error(): void
10
+ function fatal(): void
11
+ function levels(): void
12
+ function silent(): void
13
+ function child(): {
14
+ info: () => void
15
+ warn: () => void
16
+ trace: () => void
17
+ debug: () => void
18
+ error: () => void
19
+ fatal: () => void
20
+ levels: () => void
21
+ silent: () => void
22
+ child(): /*elided*/ any
23
+ }
22
24
  }
23
- export {};
25
+ export {}
@@ -1 +1 @@
1
- export * from "./get-logger.js";
1
+ export * from './get-logger.js'
@@ -1,2 +1,2 @@
1
- export function initMailer(config: any): Mailer;
2
- import { Mailer } from './mailer.service.js';
1
+ export function initMailer(config: any): Mailer
2
+ import { Mailer } from './mailer.service.js'
@@ -1,21 +1,31 @@
1
1
  export class Mailer {
2
- /**
3
- * @param {object} transporter - Nodemailer transporter instance
4
- */
5
- constructor(transporter: object);
6
- transporter: any;
7
- /**
8
- * Send an email
9
- */
10
- send({ to, subject, html, text, from, cc, bcc, replyTo, attachments }: {
11
- to: any;
12
- subject: any;
13
- html: any;
14
- text: any;
15
- from: any;
16
- cc: any;
17
- bcc: any;
18
- replyTo: any;
19
- attachments: any;
20
- }): Promise<any>;
2
+ /**
3
+ * @param {object} transporter - Nodemailer transporter instance
4
+ */
5
+ constructor(transporter: object)
6
+ transporter: any
7
+ /**
8
+ * Send an email
9
+ */
10
+ send({
11
+ to,
12
+ subject,
13
+ html,
14
+ text,
15
+ from,
16
+ cc,
17
+ bcc,
18
+ replyTo,
19
+ attachments,
20
+ }: {
21
+ to: any
22
+ subject: any
23
+ html: any
24
+ text: any
25
+ from: any
26
+ cc: any
27
+ bcc: any
28
+ replyTo: any
29
+ attachments: any
30
+ }): Promise<any>
21
31
  }
@@ -2,47 +2,47 @@
2
2
  * Factory for creating email transporters based on configuration.
3
3
  */
4
4
  export class TransportFactory {
5
- /**
6
- * Create a Nodemailer transporter
7
- *
8
- * @param {object} config - Transport configuration object
9
- * @param {'smtp' | 'gmail' | 'sendgrid' | 'ses'} config.type - Type of email transport
10
- *
11
- * For type 'smtp':
12
- * @param {string} config.host - SMTP server host
13
- * @param {number} config.port - SMTP server port
14
- * @param {boolean} config.secure - Use TLS
15
- * @param {{ user: string, pass: string }} config.auth - SMTP auth credentials
16
- *
17
- * For type 'gmail':
18
- * @param {{ user: string, pass: string }} config.auth - Gmail credentials
19
- *
20
- * For type 'sendgrid':
21
- * @param {string} config.apiKey - SendGrid API key
22
- *
23
- * For type 'ses':
24
- * @param {string} config.accessKeyId - AWS access key
25
- * @param {string} config.secretAccessKey - AWS secret
26
- * @param {string} config.region - AWS region
27
- *
28
- * @returns {import('nodemailer').Transporter | typeof import('@sendgrid/mail')}
29
- */
30
- static create(config: {
31
- type: "smtp" | "gmail" | "sendgrid" | "ses";
32
- host: string;
33
- port: number;
34
- secure: boolean;
35
- auth: {
36
- user: string;
37
- pass: string;
38
- };
39
- auth: {
40
- user: string;
41
- pass: string;
42
- };
43
- apiKey: string;
44
- accessKeyId: string;
45
- secretAccessKey: string;
46
- region: string;
47
- }): any | typeof import("@sendgrid/mail");
5
+ /**
6
+ * Create a Nodemailer transporter
7
+ *
8
+ * @param {object} config - Transport configuration object
9
+ * @param {'smtp' | 'gmail' | 'sendgrid' | 'ses'} config.type - Type of email transport
10
+ *
11
+ * For type 'smtp':
12
+ * @param {string} config.host - SMTP server host
13
+ * @param {number} config.port - SMTP server port
14
+ * @param {boolean} config.secure - Use TLS
15
+ * @param {{ user: string, pass: string }} config.auth - SMTP auth credentials
16
+ *
17
+ * For type 'gmail':
18
+ * @param {{ user: string, pass: string }} config.auth - Gmail credentials
19
+ *
20
+ * For type 'sendgrid':
21
+ * @param {string} config.apiKey - SendGrid API key
22
+ *
23
+ * For type 'ses':
24
+ * @param {string} config.accessKeyId - AWS access key
25
+ * @param {string} config.secretAccessKey - AWS secret
26
+ * @param {string} config.region - AWS region
27
+ *
28
+ * @returns {import('nodemailer').Transporter | typeof import('@sendgrid/mail')}
29
+ */
30
+ static create(config: {
31
+ type: 'smtp' | 'gmail' | 'sendgrid' | 'ses'
32
+ host: string
33
+ port: number
34
+ secure: boolean
35
+ auth: {
36
+ user: string
37
+ pass: string
38
+ }
39
+ auth: {
40
+ user: string
41
+ pass: string
42
+ }
43
+ apiKey: string
44
+ accessKeyId: string
45
+ secretAccessKey: string
46
+ region: string
47
+ }): any | typeof import('@sendgrid/mail')
48
48
  }
@@ -1,7 +1,12 @@
1
- export function mongoConnect({ uri, serverApi, timeout, retries, }: {
2
- uri: string;
3
- serverApi?: object;
4
- timeout?: number;
5
- retries?: number;
6
- }): Promise<MongoClient>;
7
- import { MongoClient } from 'mongodb';
1
+ export function mongoConnect({
2
+ uri,
3
+ serverApi,
4
+ timeout,
5
+ retries,
6
+ }: {
7
+ uri: string
8
+ serverApi?: object
9
+ timeout?: number
10
+ retries?: number
11
+ }): Promise<MongoClient>
12
+ import { MongoClient } from 'mongodb'
@@ -4,4 +4,5 @@
4
4
  * @param {Record<string, any>} query - normalized DSL query
5
5
  * @returns {Record<string, any>} - MongoDB query object
6
6
  */
7
- export function toMongo(query?: Record<string, any>): Record<string, any>;
7
+ export function toMongo(query?: Record<string, any>): Record<string, any>
8
+ export function castIsoDates(obj: any): any
@@ -1,5 +1,5 @@
1
- export * from "./connect.js";
2
- export * from "./paginate.js";
3
- export * from "./dsl-to-mongo.js";
4
- export * from "./initialize-mongodb.js";
5
- export * from "./validate-mongo-uri.js";
1
+ export * from './connect.js'
2
+ export * from './paginate.js'
3
+ export * from './dsl-to-mongo.js'
4
+ export * from './initialize-mongodb.js'
5
+ export * from './validate-mongo-uri.js'
@@ -1,13 +1,18 @@
1
- export function initializeMongoDb({ config, collectionNames }: {
2
- config: {
3
- uri: string;
4
- options: {
5
- dbName: string;
6
- };
7
- };
8
- collectionNames: Record<string, string>;
9
- }): Promise<Record<string, import("mongodb").Collection> & {
10
- withTransaction: <T>(action: ({
11
- session: import("mongodb").ClientSession;
12
- })) => Promise<T>;
13
- }>;
1
+ export function initializeMongoDb({
2
+ config,
3
+ collectionNames,
4
+ }: {
5
+ config: {
6
+ uri: string
7
+ options: {
8
+ dbName: string
9
+ }
10
+ }
11
+ collectionNames: Record<string, string>
12
+ }): Promise<
13
+ Record<string, import('mongodb').Collection> & {
14
+ withTransaction: <T>(action: {
15
+ session: import('mongodb').ClientSession
16
+ }) => Promise<T>
17
+ }
18
+ >
@@ -9,16 +9,26 @@
9
9
  * @param {'asc'|'desc'} [options.order='asc']
10
10
  * @param {number} [options.limit=10]
11
11
  */
12
- export function paginate(collection: import("mongodb").Collection, { limit, projection, filter, cursor, order, cursorField, }?: {
13
- filter?: any;
14
- cursorField?: string;
15
- cursor?: string | Date | ObjectId;
16
- order?: "asc" | "desc";
17
- limit?: number;
18
- }): Promise<{
19
- order: "desc" | "asc";
20
- list: import("mongodb").WithId<import("bson").Document>[];
21
- previous: any;
22
- next: any;
23
- }>;
24
- import { ObjectId } from 'mongodb';
12
+ export function paginate(
13
+ collection: import('mongodb').Collection,
14
+ {
15
+ limit,
16
+ projection,
17
+ filter,
18
+ cursor,
19
+ order,
20
+ cursorField,
21
+ }?: {
22
+ filter?: any
23
+ cursorField?: string
24
+ cursor?: string | Date | ObjectId
25
+ order?: 'asc' | 'desc'
26
+ limit?: number
27
+ },
28
+ ): Promise<{
29
+ order: 'asc' | 'desc'
30
+ list: import('mongodb').WithId<import('bson').Document>[]
31
+ previous: any
32
+ next: any
33
+ }>
34
+ import { ObjectId } from 'mongodb'
@@ -12,4 +12,4 @@
12
12
  * isValidMongoUri('http://localhost') // false
13
13
  * isValidMongoUri('') // false
14
14
  */
15
- export function isValidMongoUri(uri: string): boolean;
15
+ export function isValidMongoUri(uri: string): boolean
@@ -1 +1 @@
1
- export * from "./rabbit-mq.js";
1
+ export * from './rabbit-mq.js'
@@ -1,40 +1,65 @@
1
- export function connectQueueService({ host, log }: {
2
- host: string;
3
- log: import("pino").Logger;
4
- }): Promise<amqp.Connection>;
5
- export function createChannel({ host, log }: {
6
- host: string;
7
- log: import("pino").Logger;
8
- }): Promise<amqp.Channel>;
9
- export function subscribeToQueue({ log, queue, channel, prefetch, onReceive, nackOnError, }: {
10
- channel: any;
11
- queue: string;
12
- onReceive: (data: any, correlationId?: string) => Promise<void>;
13
- log: import("pino").Logger;
14
- nackOnError?: boolean;
15
- prefetch?: number;
16
- }): Promise<void>;
17
- export function initializeQueue({ host, log }: {
18
- host: string;
19
- log: import("pino").Logger;
1
+ export function connectQueueService({
2
+ host,
3
+ log,
4
+ }: {
5
+ host: string
6
+ log: import('pino').Logger
7
+ }): Promise<amqp.Connection>
8
+ export function createChannel({
9
+ host,
10
+ log,
11
+ }: {
12
+ host: string
13
+ log: import('pino').Logger
20
14
  }): Promise<{
21
- publish: (queue: string, data: any, correlationId?: string) => Promise<boolean>;
22
- subscribe: (options: {
23
- queue: string;
24
- onReceive: (data: any, correlationId?: string) => Promise<void>;
25
- nackOnError?: boolean;
26
- }) => Promise<void>;
27
- channel: amqp.Channel;
28
- }>;
15
+ channel: amqp.Channel
16
+ connection: amqp.Connection
17
+ }>
18
+ export function subscribeToQueue({
19
+ log,
20
+ queue,
21
+ channel,
22
+ prefetch,
23
+ onReceive,
24
+ nackOnError,
25
+ }: {
26
+ channel: any
27
+ queue: string
28
+ onReceive: (data: any, correlationId?: string) => Promise<void>
29
+ log: import('pino').Logger
30
+ nackOnError?: boolean
31
+ prefetch?: number
32
+ }): Promise<string>
33
+ export function initializeQueue({
34
+ host,
35
+ log,
36
+ }: {
37
+ host: string
38
+ log: import('pino').Logger
39
+ }): Promise<{
40
+ publish: (
41
+ queue: string,
42
+ data: any,
43
+ correlationId?: string,
44
+ ) => Promise<boolean>
45
+ subscribe: (options: {
46
+ queue: string
47
+ onReceive: (data: any, correlationId?: string) => Promise<void>
48
+ nackOnError?: boolean
49
+ }) => Promise<string>
50
+ channel: amqp.Channel
51
+ connection: amqp.Connection
52
+ close: () => Promise<void>
53
+ }>
29
54
  export function rabbitUriFromEnv(env: {
30
- RABBIT_HOST: string;
31
- RABBIT_PORT: string | number;
32
- RABBIT_USERNAME: string;
33
- RABBIT_PASSWORD: string;
34
- RABBIT_PROTOCOL?: string;
35
- }): string;
55
+ RABBIT_HOST: string
56
+ RABBIT_PORT: string | number
57
+ RABBIT_USERNAME: string
58
+ RABBIT_PASSWORD: string
59
+ RABBIT_PROTOCOL?: string
60
+ }): string
36
61
  export type Log = {
37
- info: (obj: any, msg?: string) => void;
38
- error: (obj: any, msg?: string) => void;
39
- debug: (obj: any, msg?: string) => void;
40
- };
62
+ info: (obj: any, msg?: string) => void
63
+ error: (obj: any, msg?: string) => void
64
+ debug: (obj: any, msg?: string) => void
65
+ }
@@ -1 +1 @@
1
- export * from "./template-loader.js";
1
+ export * from './template-loader.js'
@@ -1,3 +1,7 @@
1
- export function isItFile(filePathOrString: string): Promise<boolean>;
2
- export function getTemplateContent(maybeFilePathOrString: string): Promise<string>;
3
- export function loadTemplates(templateSet: Record<string, string>): Promise<Record<string, (params: Record<string, any>) => string>>;
1
+ export function isItFile(filePathOrString: string): Promise<boolean>
2
+ export function getTemplateContent(
3
+ maybeFilePathOrString: string,
4
+ ): Promise<string>
5
+ export function loadTemplates(
6
+ templateSet: Record<string, string>,
7
+ ): Promise<Record<string, (params: Record<string, any>) => string>>
@@ -1,55 +1,55 @@
1
1
  export namespace Context {
2
- /**
3
- * Run a callback within a given context store.
4
- * Everything `await`ed or invoked inside this callback will have access
5
- * to the provided store via {@link Context.get}, {@link Context.set}, or {@link Context.all}.
6
- *
7
- * @template T
8
- * @param {Record<string, any>} store
9
- * @param {() => T} callback - Function to execute inside the context.
10
- * @returns {T} The return value of the callback (sync or async).
11
- *
12
- * @example
13
- * Context.run(
14
- * { correlationId: 'abc123' },
15
- * async () => {
16
- * console.log(Context.get('correlationId')) // "abc123"
17
- * }
18
- * )
19
- */
20
- function run<T>(store: Record<string, any>, callback: () => T): T;
21
- /**
22
- * Retrieve a single value from the current async context store.
23
- *
24
- * @template T
25
- * @param {string} key - The key of the value to retrieve.
26
- * @returns {T|undefined} The stored value, or `undefined` if no store exists or key not found.
27
- *
28
- * @example
29
- * const userId = Context.get('userId')
30
- */
31
- function get<T>(key: string): T | undefined;
32
- /**
33
- * Set a single key-value pair in the current async context store.
34
- * If there is no active store (i.e. outside of a {@link Context.run}),
35
- * this function does nothing.
36
- *
37
- * @param {string} key - The key under which to store the value.
38
- * @param {any} value - The value to store.
39
- *
40
- * @example
41
- * Context.set('tenantId', 'tnt_1234')
42
- */
43
- function set(key: string, value: any): void;
44
- /**
45
- * Get the entire store object for the current async context.
46
- *
47
- * @returns {Record<string, any>} The current store object,
48
- * or an empty object if no store exists.
49
- *
50
- * @example
51
- * const all = Context.all()
52
- * console.log(all) // { correlationId: 'abc123', userId: 'usr_789' }
53
- */
54
- function all(): Record<string, any>;
2
+ /**
3
+ * Run a callback within a given context store.
4
+ * Everything `await`ed or invoked inside this callback will have access
5
+ * to the provided store via {@link Context.get}, {@link Context.set}, or {@link Context.all}.
6
+ *
7
+ * @template T
8
+ * @param {Record<string, any>} store
9
+ * @param {() => T} callback - Function to execute inside the context.
10
+ * @returns {T} The return value of the callback (sync or async).
11
+ *
12
+ * @example
13
+ * Context.run(
14
+ * { correlationId: 'abc123' },
15
+ * async () => {
16
+ * console.log(Context.get('correlationId')) // "abc123"
17
+ * }
18
+ * )
19
+ */
20
+ function run<T>(store: Record<string, any>, callback: () => T): T
21
+ /**
22
+ * Retrieve a single value from the current async context store.
23
+ *
24
+ * @template T
25
+ * @param {string} key - The key of the value to retrieve.
26
+ * @returns {T|undefined} The stored value, or `undefined` if no store exists or key not found.
27
+ *
28
+ * @example
29
+ * const userId = Context.get('userId')
30
+ */
31
+ function get<T>(key: string): T | undefined
32
+ /**
33
+ * Set a single key-value pair in the current async context store.
34
+ * If there is no active store (i.e. outside of a {@link Context.run}),
35
+ * this function does nothing.
36
+ *
37
+ * @param {string} key - The key under which to store the value.
38
+ * @param {any} value - The value to store.
39
+ *
40
+ * @example
41
+ * Context.set('tenantId', 'tnt_1234')
42
+ */
43
+ function set(key: string, value: any): void
44
+ /**
45
+ * Get the entire store object for the current async context.
46
+ *
47
+ * @returns {Record<string, any>} The current store object,
48
+ * or an empty object if no store exists.
49
+ *
50
+ * @example
51
+ * const all = Context.all()
52
+ * console.log(all) // { correlationId: 'abc123', userId: 'usr_789' }
53
+ */
54
+ function all(): Record<string, any>
55
55
  }
@@ -1,8 +1,8 @@
1
1
  export namespace util {
2
- export { mask };
3
- export { maskSingle };
2
+ export { mask }
3
+ export { maskSingle }
4
4
  }
5
- export { Context } from "./context.js";
6
- import { mask } from './mask-sensitive.js';
7
- import { maskSingle } from './mask-sensitive.js';
8
- export { mask, maskSingle };
5
+ export { Context } from './context.js'
6
+ import { mask } from './mask-sensitive.js'
7
+ import { maskSingle } from './mask-sensitive.js'
8
+ export { mask, maskSingle }
@@ -1,2 +1,14 @@
1
- export function maskSingle(value: string | number | boolean | null | undefined, fill?: string, maskLen?: number, left?: number, right?: number): string;
2
- export function mask(value: string | number | boolean | any[] | any | null | undefined, fill?: string, maskLen?: number, left?: number, right?: number): string | any[] | any;
1
+ export function maskSingle(
2
+ value: string | number | boolean | null | undefined,
3
+ fill?: string,
4
+ maskLen?: number,
5
+ left?: number,
6
+ right?: number,
7
+ ): string
8
+ export function mask(
9
+ value: string | number | boolean | any[] | any | null | undefined,
10
+ fill?: string,
11
+ maskLen?: number,
12
+ left?: number,
13
+ right?: number,
14
+ ): string | any[] | any