core-services-sdk 1.3.20 → 1.3.21
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/.eslintrc.json +14 -0
- package/.vscode/settings.json +6 -1
- package/eslint.config.js +21 -0
- package/package.json +12 -4
- package/scripts/bump-version.js +68 -0
- package/src/core/normalize-phone-number.js +7 -4
- package/src/core/regex-utils.js +6 -2
- package/src/http/http.js +6 -2
- package/src/mongodb/validate-mongo-uri.js +1 -1
- package/src/rabbit-mq/rabbit-mq.js +3 -1
- package/tests/http/http-method.unit.test.js +1 -1
- package/tests/ids/prefixes.unit.test.js +1 -1
- package/tests/templates/template-loader.unit.test.js +0 -4
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"env": {
|
|
3
|
+
"es2021": true,
|
|
4
|
+
"node": true
|
|
5
|
+
},
|
|
6
|
+
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
|
|
7
|
+
"plugins": ["prettier"],
|
|
8
|
+
"rules": {
|
|
9
|
+
"prettier/prettier": "error",
|
|
10
|
+
"no-unused-vars": "warn",
|
|
11
|
+
"no-console": "off"
|
|
12
|
+
},
|
|
13
|
+
"ignores": ["node_modules", "dist", ".next"]
|
|
14
|
+
}
|
package/.vscode/settings.json
CHANGED
|
@@ -12,5 +12,10 @@
|
|
|
12
12
|
},
|
|
13
13
|
"javascript.preferences.importModuleSpecifierEnding": "js",
|
|
14
14
|
"js/ts.implicitProjectConfig.checkJs": true,
|
|
15
|
-
"javascript.validate.enable": true
|
|
15
|
+
"javascript.validate.enable": true,
|
|
16
|
+
"eslint.validate": ["javascript"],
|
|
17
|
+
|
|
18
|
+
"editor.codeActionsOnSave": {
|
|
19
|
+
"source.fixAll.eslint": true
|
|
20
|
+
}
|
|
16
21
|
}
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import eslintPluginPrettier from 'eslint-plugin-prettier'
|
|
2
|
+
|
|
3
|
+
/** @type {import("eslint").Linter.FlatConfig} */
|
|
4
|
+
export default [
|
|
5
|
+
{
|
|
6
|
+
files: ['**/*.js'],
|
|
7
|
+
languageOptions: {
|
|
8
|
+
sourceType: 'module',
|
|
9
|
+
ecmaVersion: 'latest',
|
|
10
|
+
},
|
|
11
|
+
plugins: {
|
|
12
|
+
prettier: eslintPluginPrettier,
|
|
13
|
+
},
|
|
14
|
+
rules: {
|
|
15
|
+
'no-console': 'off',
|
|
16
|
+
'no-unused-vars': 'warn',
|
|
17
|
+
'curly': ['error', 'all'],
|
|
18
|
+
'prettier/prettier': 'error',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
]
|
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "core-services-sdk",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.21",
|
|
4
4
|
"main": "src/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"
|
|
7
|
+
"lint": "eslint .",
|
|
8
|
+
"lint:fix": "eslint . --fix",
|
|
9
|
+
"test": "vitest run --coverage",
|
|
10
|
+
"format": "prettier --write .",
|
|
11
|
+
"bump": "node ./scripts/bump-version.js"
|
|
8
12
|
},
|
|
9
13
|
"repository": {
|
|
10
14
|
"type": "git",
|
|
@@ -37,6 +41,10 @@
|
|
|
37
41
|
"@vitest/coverage-v8": "^3.2.4",
|
|
38
42
|
"path": "^0.12.7",
|
|
39
43
|
"url": "^0.11.4",
|
|
40
|
-
"vitest": "^3.2.4"
|
|
44
|
+
"vitest": "^3.2.4",
|
|
45
|
+
"eslint": "^9.30.0",
|
|
46
|
+
"eslint-config-prettier": "^10.1.5",
|
|
47
|
+
"eslint-plugin-prettier": "^5.5.1",
|
|
48
|
+
"prettier": "^3.6.2"
|
|
41
49
|
}
|
|
42
|
-
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import { execSync } from 'child_process'
|
|
4
|
+
|
|
5
|
+
const type = process.argv[2] // "major" | "minor" | "patch" | "-major" | "-minor" | "-patch"
|
|
6
|
+
|
|
7
|
+
if (!['major', 'minor', 'patch', '-major', '-minor', '-patch'].includes(type)) {
|
|
8
|
+
console.error(`Usage: npm run bump <major|minor|patch|-major|-minor|-patch>`)
|
|
9
|
+
process.exit(1)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const pkgPath = path.resolve(process.cwd(), 'package.json')
|
|
13
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
|
|
14
|
+
|
|
15
|
+
let [major, minor, patch] = pkg.version.split('.').map(Number)
|
|
16
|
+
|
|
17
|
+
const bump = () => {
|
|
18
|
+
switch (type) {
|
|
19
|
+
case 'major':
|
|
20
|
+
return [major + 1, 0, 0]
|
|
21
|
+
case 'minor':
|
|
22
|
+
return [major, minor + 1, 0]
|
|
23
|
+
case 'patch':
|
|
24
|
+
return [major, minor, patch + 1]
|
|
25
|
+
case '-major':
|
|
26
|
+
if (major === 0) {
|
|
27
|
+
throw new Error('Cannot decrement major below 0')
|
|
28
|
+
}
|
|
29
|
+
return [major - 1, 0, 0]
|
|
30
|
+
case '-minor':
|
|
31
|
+
if (minor === 0) {
|
|
32
|
+
if (major === 0) {
|
|
33
|
+
throw new Error('Cannot decrement minor below 0.0')
|
|
34
|
+
}
|
|
35
|
+
return [major - 1, 0, 0]
|
|
36
|
+
}
|
|
37
|
+
return [major, minor - 1, 0]
|
|
38
|
+
case '-patch':
|
|
39
|
+
if (patch === 0) {
|
|
40
|
+
if (minor === 0) {
|
|
41
|
+
if (major === 0) {
|
|
42
|
+
throw new Error('Cannot decrement below 0.0.0')
|
|
43
|
+
}
|
|
44
|
+
return [major - 1, 0, 0]
|
|
45
|
+
}
|
|
46
|
+
return [major, minor - 1, 0]
|
|
47
|
+
}
|
|
48
|
+
return [major, minor, patch - 1]
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const [newMajor, newMinor, newPatch] = bump()
|
|
53
|
+
const newVersion = `${newMajor}.${newMinor}.${newPatch}`
|
|
54
|
+
|
|
55
|
+
pkg.version = newVersion
|
|
56
|
+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
|
|
57
|
+
|
|
58
|
+
console.log(`✔ Updated version to ${newVersion}`)
|
|
59
|
+
|
|
60
|
+
// update package-lock.json if exists
|
|
61
|
+
if (fs.existsSync('./package-lock.json')) {
|
|
62
|
+
try {
|
|
63
|
+
execSync('npm install --package-lock-only', { stdio: 'inherit' })
|
|
64
|
+
console.log('✔ package-lock.json updated')
|
|
65
|
+
} catch (err) {
|
|
66
|
+
console.error('Failed to update package-lock.json', err)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -7,10 +7,9 @@ import * as raw from 'google-libphonenumber'
|
|
|
7
7
|
export function getLib() {
|
|
8
8
|
// Prefer direct (CJS-style or ESM w/ named), else default
|
|
9
9
|
// e.g. raw.PhoneNumberUtil OR raw.default.PhoneNumberUtil
|
|
10
|
-
// eslint-disable-next-line no-unused-vars
|
|
11
10
|
/** @type {any} */
|
|
12
11
|
const anyRaw = raw
|
|
13
|
-
const lib = anyRaw.PhoneNumberUtil ? anyRaw : anyRaw.default ?? anyRaw
|
|
12
|
+
const lib = anyRaw.PhoneNumberUtil ? anyRaw : (anyRaw.default ?? anyRaw)
|
|
14
13
|
|
|
15
14
|
if (!lib || !lib.PhoneNumberUtil || !lib.PhoneNumberFormat) {
|
|
16
15
|
throw new Error('google-libphonenumber failed to load (exports not found)')
|
|
@@ -71,7 +70,9 @@ export function normalizePhoneOrThrowIntl(input) {
|
|
|
71
70
|
try {
|
|
72
71
|
const util = phoneUtil()
|
|
73
72
|
const parsed = util.parseAndKeepRawInput(clean(input))
|
|
74
|
-
if (!util.isValidNumber(parsed))
|
|
73
|
+
if (!util.isValidNumber(parsed)) {
|
|
74
|
+
throw new Error('Phone number failed validation')
|
|
75
|
+
}
|
|
75
76
|
return toResult(parsed)
|
|
76
77
|
} catch (e) {
|
|
77
78
|
const err = new Error('Invalid phone number')
|
|
@@ -91,7 +92,9 @@ export function normalizePhoneOrThrowWithRegion(input, defaultRegion) {
|
|
|
91
92
|
try {
|
|
92
93
|
const util = phoneUtil()
|
|
93
94
|
const parsed = util.parseAndKeepRawInput(clean(input), defaultRegion)
|
|
94
|
-
if (!util.isValidNumber(parsed))
|
|
95
|
+
if (!util.isValidNumber(parsed)) {
|
|
96
|
+
throw new Error('Phone number failed validation')
|
|
97
|
+
}
|
|
95
98
|
return toResult(parsed)
|
|
96
99
|
} catch (e) {
|
|
97
100
|
const err = new Error('Invalid phone number')
|
package/src/core/regex-utils.js
CHANGED
|
@@ -16,8 +16,12 @@
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
export const isValidRegex = (pattern) => {
|
|
19
|
-
if (pattern instanceof RegExp)
|
|
20
|
-
|
|
19
|
+
if (pattern instanceof RegExp) {
|
|
20
|
+
return true
|
|
21
|
+
}
|
|
22
|
+
if (typeof pattern !== 'string') {
|
|
23
|
+
return false
|
|
24
|
+
}
|
|
21
25
|
try {
|
|
22
26
|
new RegExp(pattern)
|
|
23
27
|
return true
|
package/src/http/http.js
CHANGED
|
@@ -83,7 +83,9 @@ const tryGetJsonResponse = async (response) => {
|
|
|
83
83
|
jsonText = await getTextResponse(response)
|
|
84
84
|
return tryConvertJsonResponse(jsonText)
|
|
85
85
|
} catch (error) {
|
|
86
|
-
if (!jsonText)
|
|
86
|
+
if (!jsonText) {
|
|
87
|
+
throw error
|
|
88
|
+
}
|
|
87
89
|
return jsonText
|
|
88
90
|
}
|
|
89
91
|
}
|
|
@@ -100,7 +102,9 @@ const tryGetXmlResponse = async (response) => {
|
|
|
100
102
|
xmlText = await getTextResponse(response)
|
|
101
103
|
return await parseStringPromise(xmlText)
|
|
102
104
|
} catch (error) {
|
|
103
|
-
if (!xmlText)
|
|
105
|
+
if (!xmlText) {
|
|
106
|
+
throw error
|
|
107
|
+
}
|
|
104
108
|
return xmlText
|
|
105
109
|
}
|
|
106
110
|
}
|
|
@@ -75,7 +75,9 @@ export const subscribeToQueue = async ({
|
|
|
75
75
|
!!prefetch && (await channel.prefetch(prefetch))
|
|
76
76
|
|
|
77
77
|
channel.consume(queue, async (msgInfo) => {
|
|
78
|
-
if (!msgInfo)
|
|
78
|
+
if (!msgInfo) {
|
|
79
|
+
return
|
|
80
|
+
}
|
|
79
81
|
|
|
80
82
|
try {
|
|
81
83
|
const { msgId, data } = parseMessage(msgInfo)
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import dot from 'dot'
|
|
2
1
|
import * as fs from 'fs/promises'
|
|
3
2
|
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
4
3
|
|
|
@@ -7,9 +6,6 @@ import { loadTemplates } from '../../src/templates/template-loader.js'
|
|
|
7
6
|
vi.mock('fs/promises')
|
|
8
7
|
|
|
9
8
|
describe('loadTemplates', () => {
|
|
10
|
-
// @ts-ignore
|
|
11
|
-
const mockCompile = vi.spyOn(dot, 'compile')
|
|
12
|
-
|
|
13
9
|
beforeEach(() => {
|
|
14
10
|
vi.resetAllMocks()
|
|
15
11
|
})
|