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.
- package/package.json +2 -2
- package/src/fastify/error-codes.js +2 -4
- package/src/fastify/error-handlers/with-error-handling.js +5 -6
- package/src/http/HttpError.js +10 -29
- package/src/http/http.js +2 -3
- package/tests/fastify/error-handler.unit.test.js +3 -11
- package/tests/fastify/error-handlers/with-error-handling.test.js +3 -6
- package/tests/http/HttpError.unit.test.js +13 -17
- package/tsconfig.json +3 -1
- package/types/core/combine-unique-arrays.d.ts +1 -1
- package/types/core/index.d.ts +9 -9
- package/types/core/normalize-array-operators.d.ts +1 -1
- package/types/core/normalize-min-max.d.ts +16 -10
- package/types/core/normalize-phone-number.d.ts +30 -24
- package/types/core/normalize-premitives-types-or-default.d.ts +17 -4
- package/types/core/normalize-to-array.d.ts +1 -1
- package/types/core/otp-generators.d.ts +22 -18
- package/types/core/regex-utils.d.ts +1 -1
- package/types/core/sanitize-objects.d.ts +13 -4
- package/types/crypto/crypto.d.ts +31 -18
- package/types/crypto/encryption.d.ts +14 -6
- package/types/crypto/index.d.ts +2 -2
- package/types/fastify/error-codes.d.ts +11 -16
- package/types/fastify/error-handlers/with-error-handling.d.ts +26 -15
- package/types/fastify/index.d.ts +2 -2
- package/types/http/HttpError.d.ts +67 -76
- package/types/http/http-method.d.ts +6 -6
- package/types/http/http.d.ts +58 -34
- package/types/http/index.d.ts +4 -4
- package/types/http/responseType.d.ts +6 -6
- package/types/ids/generators.d.ts +28 -28
- package/types/ids/index.d.ts +2 -2
- package/types/ids/prefixes.d.ts +54 -54
- package/types/index.d.ts +11 -11
- package/types/logger/get-logger.d.ts +23 -21
- package/types/logger/index.d.ts +1 -1
- package/types/mailer/index.d.ts +2 -2
- package/types/mailer/mailer.service.d.ts +29 -19
- package/types/mailer/transport.factory.d.ts +43 -43
- package/types/mongodb/connect.d.ts +12 -7
- package/types/mongodb/dsl-to-mongo.d.ts +2 -1
- package/types/mongodb/index.d.ts +5 -5
- package/types/mongodb/initialize-mongodb.d.ts +18 -13
- package/types/mongodb/paginate.d.ts +23 -13
- package/types/mongodb/validate-mongo-uri.d.ts +1 -1
- package/types/rabbit-mq/index.d.ts +1 -1
- package/types/rabbit-mq/rabbit-mq.d.ts +62 -37
- package/types/templates/index.d.ts +1 -1
- package/types/templates/template-loader.d.ts +7 -3
- package/types/util/context.d.ts +53 -53
- package/types/util/index.d.ts +6 -6
- package/types/util/mask-sensitive.d.ts +14 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "core-services-sdk",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.38",
|
|
4
4
|
"main": "src/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"test": "vitest run --coverage",
|
|
11
11
|
"format": "prettier --write .",
|
|
12
12
|
"bump": "node ./scripts/bump-version.js",
|
|
13
|
-
"build:types": "tsc --
|
|
13
|
+
"build:types": "tsc --project tsconfig.json && prettier --write ."
|
|
14
14
|
},
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
|
@@ -5,14 +5,12 @@ import httpStatus from 'http-status'
|
|
|
5
5
|
* Useful as a fallback error descriptor for unhandled or unexpected failures.
|
|
6
6
|
*
|
|
7
7
|
* @typedef {Object} GeneralError
|
|
8
|
-
* @property {number}
|
|
9
|
-
* @property {string} httpStatusText - The human-readable status text ("Internal Server Error").
|
|
8
|
+
* @property {number} status - The HTTP status code (500).
|
|
10
9
|
* @property {string} code - An application-specific error code in the format "GENERAL.<StatusText>".
|
|
11
10
|
*/
|
|
12
11
|
|
|
13
12
|
/** @type {GeneralError} */
|
|
14
13
|
export const GENERAL_ERROR = {
|
|
15
|
-
|
|
16
|
-
httpStatusText: httpStatus[httpStatus.INTERNAL_SERVER_ERROR],
|
|
14
|
+
status: httpStatus.INTERNAL_SERVER_ERROR,
|
|
17
15
|
code: `GENERAL.${httpStatus[httpStatus.INTERNAL_SERVER_ERROR]}`,
|
|
18
16
|
}
|
|
@@ -48,8 +48,8 @@ export const withErrorHandlingReply =
|
|
|
48
48
|
try {
|
|
49
49
|
return await withErrorHandling(log, defaultError)(funcToInvoke)
|
|
50
50
|
} catch (error) {
|
|
51
|
-
const { code,
|
|
52
|
-
reply.status(
|
|
51
|
+
const { code, status } = error
|
|
52
|
+
reply.status(status).send({ code })
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
|
|
@@ -81,12 +81,11 @@ export const replyOnErrorOnly =
|
|
|
81
81
|
errorMerged.stack = error.stack
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
const exposed =
|
|
85
|
-
errorMerged.message ?? errorMerged.code ?? GENERAL_ERROR.httpStatusText
|
|
84
|
+
const exposed = errorMerged.message ?? errorMerged.code
|
|
86
85
|
|
|
87
86
|
const status =
|
|
88
|
-
errorMerged.
|
|
89
|
-
? errorMerged.
|
|
87
|
+
errorMerged.status && errorMerged.status in httpStatus
|
|
88
|
+
? errorMerged.status
|
|
90
89
|
: httpStatus.INTERNAL_SERVER_ERROR
|
|
91
90
|
|
|
92
91
|
reply.status(status).send({ error: exposed })
|
package/src/http/HttpError.js
CHANGED
|
@@ -15,13 +15,7 @@ export class HttpError extends Error {
|
|
|
15
15
|
* @type {number | undefined}
|
|
16
16
|
* HTTP status code associated with the error (e.g., 400, 500).
|
|
17
17
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @type {string | undefined}
|
|
22
|
-
* Human-readable HTTP status text (e.g., "Bad Request").
|
|
23
|
-
*/
|
|
24
|
-
httpStatusText
|
|
18
|
+
status
|
|
25
19
|
|
|
26
20
|
/**
|
|
27
21
|
* @type {object | undefined}
|
|
@@ -35,24 +29,16 @@ export class HttpError extends Error {
|
|
|
35
29
|
* @param {Object} [error] - Optional error object.
|
|
36
30
|
* @param {string | number} [error.code] - Application-specific error code.
|
|
37
31
|
* @param {string} [error.message] - Custom error message.
|
|
38
|
-
* @param {number} [error.
|
|
39
|
-
* @param {string} [error.httpStatusText] - Optional human-readable HTTP status text.
|
|
32
|
+
* @param {number} [error.status] - HTTP status code (e.g., 404, 500).
|
|
40
33
|
* @param {object} [error.extendInfo] - Optional extended metadata for diagnostics.
|
|
41
34
|
*/
|
|
42
35
|
constructor(error = {}) {
|
|
43
|
-
const { code,
|
|
36
|
+
const { code, status, message, extendInfo } = error
|
|
44
37
|
|
|
45
|
-
super(
|
|
46
|
-
message ||
|
|
47
|
-
(httpStatusCode && httpStatus[httpStatusCode]) ||
|
|
48
|
-
code ||
|
|
49
|
-
'Unknown error',
|
|
50
|
-
)
|
|
38
|
+
super(message || (status && httpStatus[status]) || code || 'Unknown error')
|
|
51
39
|
|
|
52
40
|
this.code = code
|
|
53
|
-
this.
|
|
54
|
-
this.httpStatusText =
|
|
55
|
-
httpStatusText || (httpStatusCode && httpStatus[httpStatusCode])
|
|
41
|
+
this.status = status
|
|
56
42
|
this.extendInfo = extendInfo
|
|
57
43
|
|
|
58
44
|
if (typeof Error.captureStackTrace === 'function') {
|
|
@@ -81,8 +67,7 @@ export class HttpError extends Error {
|
|
|
81
67
|
instance &&
|
|
82
68
|
typeof instance === 'object' &&
|
|
83
69
|
'message' in instance &&
|
|
84
|
-
'
|
|
85
|
-
'httpStatusText' in instance
|
|
70
|
+
'status' in instance
|
|
86
71
|
)
|
|
87
72
|
}
|
|
88
73
|
|
|
@@ -92,8 +77,7 @@ export class HttpError extends Error {
|
|
|
92
77
|
* @returns {{
|
|
93
78
|
* code: string | number | undefined,
|
|
94
79
|
* message: string,
|
|
95
|
-
*
|
|
96
|
-
* httpStatusText: string | undefined,
|
|
80
|
+
* status: number | undefined,
|
|
97
81
|
* extendInfo?: object
|
|
98
82
|
* }}
|
|
99
83
|
*/
|
|
@@ -101,8 +85,7 @@ export class HttpError extends Error {
|
|
|
101
85
|
return {
|
|
102
86
|
code: this.code,
|
|
103
87
|
message: this.message,
|
|
104
|
-
|
|
105
|
-
httpStatusText: this.httpStatusText,
|
|
88
|
+
status: this.status,
|
|
106
89
|
...(this.extendInfo ? { extendInfo: this.extendInfo } : {}),
|
|
107
90
|
}
|
|
108
91
|
}
|
|
@@ -118,8 +101,7 @@ export class HttpError extends Error {
|
|
|
118
101
|
error instanceof HttpError ||
|
|
119
102
|
(error &&
|
|
120
103
|
typeof error === 'object' &&
|
|
121
|
-
'
|
|
122
|
-
'httpStatusText' in error &&
|
|
104
|
+
'status' in error &&
|
|
123
105
|
'toJSON' in error)
|
|
124
106
|
)
|
|
125
107
|
}
|
|
@@ -138,8 +120,7 @@ export class HttpError extends Error {
|
|
|
138
120
|
const httpError = new HttpError({
|
|
139
121
|
code: 'UNHANDLED_ERROR',
|
|
140
122
|
message: error.message || 'An unexpected error occurred',
|
|
141
|
-
|
|
142
|
-
httpStatusText: httpStatus[httpStatus.INTERNAL_SERVER_ERROR],
|
|
123
|
+
status: httpStatus.INTERNAL_SERVER_ERROR,
|
|
143
124
|
})
|
|
144
125
|
|
|
145
126
|
httpError.stack = error.stack
|
package/src/http/http.js
CHANGED
|
@@ -36,11 +36,10 @@ const isOkStatus = ({ status }) =>
|
|
|
36
36
|
const checkStatus = async (response) => {
|
|
37
37
|
if (!isOkStatus(response)) {
|
|
38
38
|
const text = await response.text()
|
|
39
|
-
const { status
|
|
39
|
+
const { status } = response
|
|
40
40
|
throw new HttpError({
|
|
41
|
+
status,
|
|
41
42
|
code: status,
|
|
42
|
-
httpStatusCode: status,
|
|
43
|
-
httpStatusText: statusText,
|
|
44
43
|
extendInfo: { text },
|
|
45
44
|
})
|
|
46
45
|
}
|
|
@@ -5,13 +5,7 @@ import { GENERAL_ERROR } from '../../src/fastify/error-codes.js'
|
|
|
5
5
|
|
|
6
6
|
describe('GENERAL_ERROR', () => {
|
|
7
7
|
it('should have correct status code', () => {
|
|
8
|
-
expect(GENERAL_ERROR.
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
it('should have correct status text', () => {
|
|
12
|
-
expect(GENERAL_ERROR.httpStatusText).toBe(
|
|
13
|
-
httpStatus[httpStatus.INTERNAL_SERVER_ERROR],
|
|
14
|
-
)
|
|
8
|
+
expect(GENERAL_ERROR.status).toBe(httpStatus.INTERNAL_SERVER_ERROR)
|
|
15
9
|
})
|
|
16
10
|
|
|
17
11
|
it('should have correct code format', () => {
|
|
@@ -22,15 +16,13 @@ describe('GENERAL_ERROR', () => {
|
|
|
22
16
|
})
|
|
23
17
|
|
|
24
18
|
it('should have all required properties and types', () => {
|
|
25
|
-
expect(typeof GENERAL_ERROR.
|
|
26
|
-
expect(typeof GENERAL_ERROR.httpStatusText).toBe('string')
|
|
19
|
+
expect(typeof GENERAL_ERROR.status).toBe('number')
|
|
27
20
|
expect(typeof GENERAL_ERROR.code).toBe('string')
|
|
28
21
|
})
|
|
29
22
|
|
|
30
23
|
it('should match full expected structure', () => {
|
|
31
24
|
const expected = {
|
|
32
|
-
|
|
33
|
-
httpStatusText: 'Internal Server Error',
|
|
25
|
+
status: httpStatus.INTERNAL_SERVER_ERROR,
|
|
34
26
|
code: 'GENERAL.Internal Server Error',
|
|
35
27
|
}
|
|
36
28
|
|
|
@@ -25,7 +25,7 @@ describe('withErrorHandling', () => {
|
|
|
25
25
|
it('should rethrow HttpError', async () => {
|
|
26
26
|
const err = new HttpError({
|
|
27
27
|
message: 'Bad',
|
|
28
|
-
|
|
28
|
+
status: httpStatus.BAD_REQUEST,
|
|
29
29
|
})
|
|
30
30
|
const fn = vi.fn().mockRejectedValue(err)
|
|
31
31
|
|
|
@@ -65,8 +65,7 @@ describe('withErrorHandlingReply', () => {
|
|
|
65
65
|
const err = new HttpError({
|
|
66
66
|
message: 'not found',
|
|
67
67
|
code: 'NOT_FOUND',
|
|
68
|
-
|
|
69
|
-
httpStatusText: httpStatus[httpStatus.NOT_FOUND],
|
|
68
|
+
status: httpStatus.NOT_FOUND,
|
|
70
69
|
})
|
|
71
70
|
|
|
72
71
|
const fn = vi.fn().mockRejectedValue(err)
|
|
@@ -75,7 +74,6 @@ describe('withErrorHandlingReply', () => {
|
|
|
75
74
|
expect(reply.status).toHaveBeenCalledWith(httpStatus.NOT_FOUND)
|
|
76
75
|
expect(reply.send).toHaveBeenCalledWith({
|
|
77
76
|
code: 'NOT_FOUND',
|
|
78
|
-
httpStatusText: 'Not Found',
|
|
79
77
|
})
|
|
80
78
|
})
|
|
81
79
|
})
|
|
@@ -112,8 +110,7 @@ describe('replyOnErrorOnly', () => {
|
|
|
112
110
|
const err = new HttpError({
|
|
113
111
|
message: 'forbidden',
|
|
114
112
|
code: 'NO_ACCESS',
|
|
115
|
-
|
|
116
|
-
httpStatusText: httpStatus[httpStatus.FORBIDDEN],
|
|
113
|
+
status: httpStatus.FORBIDDEN,
|
|
117
114
|
})
|
|
118
115
|
|
|
119
116
|
const fn = vi.fn().mockRejectedValue(err)
|
|
@@ -8,26 +8,24 @@ describe('HttpError', () => {
|
|
|
8
8
|
const error = new HttpError({
|
|
9
9
|
code: 'INVALID_INPUT',
|
|
10
10
|
message: 'Invalid input provided',
|
|
11
|
-
|
|
11
|
+
status: httpStatus.BAD_REQUEST,
|
|
12
12
|
extendInfo: { field: 'email', reason: 'missing' },
|
|
13
13
|
})
|
|
14
14
|
|
|
15
15
|
expect(error).toBeInstanceOf(HttpError)
|
|
16
16
|
expect(error.message).toBe('Invalid input provided')
|
|
17
17
|
expect(error.code).toBe('INVALID_INPUT')
|
|
18
|
-
expect(error.
|
|
19
|
-
expect(error.httpStatusText).toBe(httpStatus[400])
|
|
18
|
+
expect(error.status).toBe(httpStatus.BAD_REQUEST)
|
|
20
19
|
expect(error.extendInfo).toEqual({ field: 'email', reason: 'missing' })
|
|
21
20
|
})
|
|
22
21
|
|
|
23
22
|
it('should fallback to default message from status if message is missing', () => {
|
|
24
23
|
const error = new HttpError({
|
|
25
24
|
code: 'BAD_REQUEST',
|
|
26
|
-
|
|
25
|
+
status: httpStatus.BAD_REQUEST,
|
|
27
26
|
})
|
|
28
27
|
|
|
29
|
-
expect(error.message).toBe(httpStatus[
|
|
30
|
-
expect(error.httpStatusText).toBe(httpStatus[400])
|
|
28
|
+
expect(error.message).toBe(httpStatus[httpStatus.BAD_REQUEST])
|
|
31
29
|
expect(error.extendInfo).toBeUndefined()
|
|
32
30
|
})
|
|
33
31
|
|
|
@@ -35,7 +33,7 @@ describe('HttpError', () => {
|
|
|
35
33
|
const error = new HttpError({ code: 'ERROR_CODE_ONLY' })
|
|
36
34
|
|
|
37
35
|
expect(error.message).toBe('ERROR_CODE_ONLY')
|
|
38
|
-
expect(error.
|
|
36
|
+
expect(error.status).toBeUndefined()
|
|
39
37
|
expect(error.extendInfo).toBeUndefined()
|
|
40
38
|
})
|
|
41
39
|
|
|
@@ -50,14 +48,13 @@ describe('HttpError', () => {
|
|
|
50
48
|
const error = new HttpError({
|
|
51
49
|
code: 'NOT_FOUND',
|
|
52
50
|
message: 'Resource not found',
|
|
53
|
-
|
|
51
|
+
status: httpStatus.NOT_FOUND,
|
|
54
52
|
})
|
|
55
53
|
|
|
56
54
|
expect(error.toJSON()).toEqual({
|
|
57
55
|
code: 'NOT_FOUND',
|
|
58
56
|
message: 'Resource not found',
|
|
59
|
-
|
|
60
|
-
httpStatusText: httpStatus[404],
|
|
57
|
+
status: httpStatus.NOT_FOUND,
|
|
61
58
|
})
|
|
62
59
|
})
|
|
63
60
|
|
|
@@ -65,15 +62,14 @@ describe('HttpError', () => {
|
|
|
65
62
|
const error = new HttpError({
|
|
66
63
|
code: 'NOT_FOUND',
|
|
67
64
|
message: 'Resource not found',
|
|
68
|
-
|
|
65
|
+
status: httpStatus.NOT_FOUND,
|
|
69
66
|
extendInfo: { resource: 'user', id: 123 },
|
|
70
67
|
})
|
|
71
68
|
|
|
72
69
|
expect(error.toJSON()).toEqual({
|
|
73
70
|
code: 'NOT_FOUND',
|
|
74
71
|
message: 'Resource not found',
|
|
75
|
-
|
|
76
|
-
httpStatusText: httpStatus[404],
|
|
72
|
+
status: httpStatus.NOT_FOUND,
|
|
77
73
|
extendInfo: { resource: 'user', id: 123 },
|
|
78
74
|
})
|
|
79
75
|
})
|
|
@@ -81,7 +77,7 @@ describe('HttpError', () => {
|
|
|
81
77
|
it('should detect instance using isHttpError', () => {
|
|
82
78
|
const error = new HttpError({
|
|
83
79
|
code: 'TEST',
|
|
84
|
-
|
|
80
|
+
status: httpStatus.INTERNAL_SERVER_ERROR,
|
|
85
81
|
})
|
|
86
82
|
|
|
87
83
|
expect(HttpError.isHttpError(error)).toBe(true)
|
|
@@ -91,7 +87,7 @@ describe('HttpError', () => {
|
|
|
91
87
|
it('FromError should return same instance if already HttpError', () => {
|
|
92
88
|
const original = new HttpError({
|
|
93
89
|
code: 'ALREADY_HTTP',
|
|
94
|
-
|
|
90
|
+
status: httpStatus.UNAUTHORIZED,
|
|
95
91
|
})
|
|
96
92
|
const result = HttpError.FromError(original)
|
|
97
93
|
|
|
@@ -105,8 +101,8 @@ describe('HttpError', () => {
|
|
|
105
101
|
expect(httpError).toBeInstanceOf(HttpError)
|
|
106
102
|
expect(httpError.message).toBe('Boom!')
|
|
107
103
|
expect(httpError.code).toBe('UNHANDLED_ERROR')
|
|
108
|
-
expect(httpError.
|
|
109
|
-
|
|
104
|
+
expect(httpError.status).toBe(httpStatus.INTERNAL_SERVER_ERROR)
|
|
105
|
+
|
|
110
106
|
expect(httpError.extendInfo).toBeUndefined()
|
|
111
107
|
})
|
|
112
108
|
})
|
package/tsconfig.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export function combineUniqueArrays(...lists: Array<any>[]): Array<any
|
|
1
|
+
export function combineUniqueArrays(...lists: Array<any>[]): Array<any>
|
package/types/core/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
1
|
+
export * from './regex-utils.js'
|
|
2
|
+
export * from './otp-generators.js'
|
|
3
|
+
export * from './sanitize-objects.js'
|
|
4
|
+
export * from './normalize-min-max.js'
|
|
5
|
+
export * from './normalize-to-array.js'
|
|
6
|
+
export * from './combine-unique-arrays.js'
|
|
7
|
+
export * from './normalize-phone-number.js'
|
|
8
|
+
export * from './normalize-array-operators.js'
|
|
9
|
+
export * from './normalize-premitives-types-or-default.js'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export function normalizeOperators(obj: any): any
|
|
1
|
+
export function normalizeOperators(obj: any): any
|
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
export function normalizeMinMax(
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
1
|
+
export function normalizeMinMax(
|
|
2
|
+
defaultMinMax: {
|
|
3
|
+
min: number
|
|
4
|
+
max: number
|
|
5
|
+
},
|
|
6
|
+
valuesMinMax:
|
|
7
|
+
| {
|
|
8
|
+
min?: number
|
|
9
|
+
max?: number
|
|
10
|
+
}
|
|
11
|
+
| null
|
|
12
|
+
| undefined,
|
|
13
|
+
): {
|
|
14
|
+
min: number
|
|
15
|
+
max: number
|
|
16
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Resolve libphonenumber regardless of interop shape */
|
|
2
|
-
export function getLib(): any
|
|
3
|
-
export function phoneUtil(): any
|
|
2
|
+
export function getLib(): any
|
|
3
|
+
export function phoneUtil(): any
|
|
4
4
|
/**
|
|
5
5
|
* Parse & validate an international number (must start with '+').
|
|
6
6
|
* @param {string} input
|
|
@@ -8,12 +8,12 @@ export function phoneUtil(): any;
|
|
|
8
8
|
* @throws {Error} If the number is invalid
|
|
9
9
|
*/
|
|
10
10
|
export function normalizePhoneOrThrowIntl(input: string): {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
11
|
+
e164: string
|
|
12
|
+
national: string
|
|
13
|
+
international: string
|
|
14
|
+
regionCode: string | undefined
|
|
15
|
+
type: number
|
|
16
|
+
}
|
|
17
17
|
/**
|
|
18
18
|
* Parse & validate a national number using a region hint.
|
|
19
19
|
* @param {string} input
|
|
@@ -21,13 +21,16 @@ export function normalizePhoneOrThrowIntl(input: string): {
|
|
|
21
21
|
* @returns {{e164:string,national:string,international:string,regionCode:string|undefined,type:number}}
|
|
22
22
|
* @throws {Error} If the number is invalid
|
|
23
23
|
*/
|
|
24
|
-
export function normalizePhoneOrThrowWithRegion(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
export function normalizePhoneOrThrowWithRegion(
|
|
25
|
+
input: string,
|
|
26
|
+
defaultRegion: string,
|
|
27
|
+
): {
|
|
28
|
+
e164: string
|
|
29
|
+
national: string
|
|
30
|
+
international: string
|
|
31
|
+
regionCode: string | undefined
|
|
32
|
+
type: number
|
|
33
|
+
}
|
|
31
34
|
/**
|
|
32
35
|
* Smart normalization:
|
|
33
36
|
* - If input starts with '+', parse as international.
|
|
@@ -37,12 +40,15 @@ export function normalizePhoneOrThrowWithRegion(input: string, defaultRegion: st
|
|
|
37
40
|
* @returns {{e164:string,national:string,international:string,regionCode:string|undefined,type:number}}
|
|
38
41
|
* @throws {Error} If invalid or defaultRegion is missing for non-international input
|
|
39
42
|
*/
|
|
40
|
-
export function normalizePhoneOrThrow(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
export function normalizePhoneOrThrow(
|
|
44
|
+
input: string,
|
|
45
|
+
opts?: {
|
|
46
|
+
defaultRegion?: string
|
|
47
|
+
},
|
|
48
|
+
): {
|
|
49
|
+
e164: string
|
|
50
|
+
national: string
|
|
51
|
+
international: string
|
|
52
|
+
regionCode: string | undefined
|
|
53
|
+
type: number
|
|
54
|
+
}
|
|
@@ -53,7 +53,11 @@
|
|
|
53
53
|
* {}
|
|
54
54
|
* )
|
|
55
55
|
*/
|
|
56
|
-
export function normalizeOrDefault<T>(
|
|
56
|
+
export function normalizeOrDefault<T>(
|
|
57
|
+
value: any,
|
|
58
|
+
isValid: (v: any) => boolean,
|
|
59
|
+
defaultValue: T,
|
|
60
|
+
): T
|
|
57
61
|
/**
|
|
58
62
|
* Normalize a value to a non-empty, trimmed string; otherwise return a default (also trimmed).
|
|
59
63
|
*
|
|
@@ -93,7 +97,10 @@ export function normalizeOrDefault<T>(value: any, isValid: (v: any) => boolean,
|
|
|
93
97
|
* normalizeStringOrDefault(42, 'user-roles-management:edit')
|
|
94
98
|
* // → 'user-roles-management:edit'
|
|
95
99
|
*/
|
|
96
|
-
export function normalizeStringOrDefault(
|
|
100
|
+
export function normalizeStringOrDefault(
|
|
101
|
+
value: any,
|
|
102
|
+
defaultValue: string,
|
|
103
|
+
): string
|
|
97
104
|
/**
|
|
98
105
|
* Normalize a value to a valid number (with safe string coercion); otherwise return a default.
|
|
99
106
|
*
|
|
@@ -131,7 +138,10 @@ export function normalizeStringOrDefault(value: any, defaultValue: string): stri
|
|
|
131
138
|
* normalizeNumberOrDefault(NaN, 7) // → 7
|
|
132
139
|
* normalizeNumberOrDefault({}, 7) // → 7
|
|
133
140
|
*/
|
|
134
|
-
export function normalizeNumberOrDefault(
|
|
141
|
+
export function normalizeNumberOrDefault(
|
|
142
|
+
value: any,
|
|
143
|
+
defaultValue: number,
|
|
144
|
+
): number
|
|
135
145
|
/**
|
|
136
146
|
* Normalize a value to a boolean (with "true"/"false" string support); otherwise return a default.
|
|
137
147
|
*
|
|
@@ -169,4 +179,7 @@ export function normalizeNumberOrDefault(value: any, defaultValue: number): numb
|
|
|
169
179
|
* normalizeBooleanOrDefault('yes', false) // → false (rejected → default)
|
|
170
180
|
* normalizeBooleanOrDefault(1, true) // → true (rejected → default)
|
|
171
181
|
*/
|
|
172
|
-
export function normalizeBooleanOrDefault(
|
|
182
|
+
export function normalizeBooleanOrDefault(
|
|
183
|
+
value: any,
|
|
184
|
+
defaultValue: boolean,
|
|
185
|
+
): boolean
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export function normalizeToArray(value: any): string[]
|
|
1
|
+
export function normalizeToArray(value: any): string[]
|
|
@@ -11,46 +11,50 @@
|
|
|
11
11
|
* @throws {Error} If charset is provided and is not a non-empty string.
|
|
12
12
|
* @throws {Error} If the type is invalid and no valid charset is provided.
|
|
13
13
|
*/
|
|
14
|
-
export function generateCode({
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
14
|
+
export function generateCode({
|
|
15
|
+
length,
|
|
16
|
+
type,
|
|
17
|
+
charset,
|
|
18
|
+
}?: {
|
|
19
|
+
length?: number
|
|
20
|
+
type?: string
|
|
21
|
+
charset?: string
|
|
22
|
+
}): string
|
|
19
23
|
/**
|
|
20
24
|
* Generates an OTP code using alphabetic characters (both lowercase and uppercase).
|
|
21
25
|
*
|
|
22
26
|
* @param {number} [length=4] - The desired length of the code.
|
|
23
27
|
* @returns {string} The generated code.
|
|
24
28
|
*/
|
|
25
|
-
export function generateCodeAlpha(length?: number): string
|
|
29
|
+
export function generateCodeAlpha(length?: number): string
|
|
26
30
|
/**
|
|
27
31
|
* Generates an OTP code using only numeric digits (0-9).
|
|
28
32
|
*
|
|
29
33
|
* @param {number} [length=4] - The desired length of the code.
|
|
30
34
|
* @returns {string} The generated code.
|
|
31
35
|
*/
|
|
32
|
-
export function generateCodeDigits(length?: number): string
|
|
36
|
+
export function generateCodeDigits(length?: number): string
|
|
33
37
|
/**
|
|
34
38
|
* Generates an OTP code using alphabetic characters and digits.
|
|
35
39
|
*
|
|
36
40
|
* @param {number} [length=4] - The desired length of the code.
|
|
37
41
|
* @returns {string} The generated code.
|
|
38
42
|
*/
|
|
39
|
-
export function generateCodeAlphaNumeric(length?: number): string
|
|
43
|
+
export function generateCodeAlphaNumeric(length?: number): string
|
|
40
44
|
/**
|
|
41
45
|
* Generates an OTP code using alphabetic characters, digits, and symbols.
|
|
42
46
|
*
|
|
43
47
|
* @param {number} [length=4] - The desired length of the code.
|
|
44
48
|
* @returns {string} The generated code.
|
|
45
49
|
*/
|
|
46
|
-
export function generateCodeAlphaNumericSymbols(length?: number): string
|
|
50
|
+
export function generateCodeAlphaNumericSymbols(length?: number): string
|
|
47
51
|
export const OTP_GENERATOR_TYPES: Readonly<{
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
52
|
+
any: 'any'
|
|
53
|
+
alpha: 'alpha'
|
|
54
|
+
numeric: 'numeric'
|
|
55
|
+
symbols: 'symbols'
|
|
56
|
+
alphaLower: 'alphaLower'
|
|
57
|
+
alphaUpper: 'alphaUpper'
|
|
58
|
+
alphanumeric: 'alphanumeric'
|
|
59
|
+
alphanumericSymbols: 'alphanumericSymbols'
|
|
60
|
+
}>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export function isValidRegex(pattern: string | RegExp): boolean
|
|
1
|
+
export function isValidRegex(pattern: string | RegExp): boolean
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
export function sanitizeObject(
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export function sanitizeObject(
|
|
2
|
+
obj: any,
|
|
3
|
+
filter: (entry: [string, any]) => boolean,
|
|
4
|
+
): any
|
|
5
|
+
export function sanitizeUndefinedFields(obj: any): any
|
|
6
|
+
export function sanitizeObjectAllowProps(
|
|
7
|
+
obj: any,
|
|
8
|
+
allowedFields?: string[],
|
|
9
|
+
): any
|
|
10
|
+
export function sanitizeObjectDisallowProps(
|
|
11
|
+
obj: any,
|
|
12
|
+
disallowedFields?: string[],
|
|
13
|
+
): any
|