@xrystal/core 3.2.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 (76) hide show
  1. package/README.md +1 -0
  2. package/bin/constants/index.mjs +14 -0
  3. package/bin/helpers/index.mjs +83 -0
  4. package/bin/main-cli.js +179 -0
  5. package/package.json +113 -0
  6. package/source/index.d.ts +2 -0
  7. package/source/index.js +8 -0
  8. package/source/loader/configs/index.d.ts +13 -0
  9. package/source/loader/configs/index.js +17 -0
  10. package/source/loader/events/index.d.ts +6 -0
  11. package/source/loader/events/index.js +25 -0
  12. package/source/loader/index.d.ts +6 -0
  13. package/source/loader/index.js +6 -0
  14. package/source/loader/localizations/index.d.ts +14 -0
  15. package/source/loader/localizations/index.js +32 -0
  16. package/source/loader/logger/index.d.ts +22 -0
  17. package/source/loader/logger/index.js +130 -0
  18. package/source/loader/system/index.d.ts +8 -0
  19. package/source/loader/system/index.js +14 -0
  20. package/source/project/index.d.ts +7 -0
  21. package/source/project/index.js +94 -0
  22. package/source/utils/constants/index.d.ts +8 -0
  23. package/source/utils/constants/index.js +10 -0
  24. package/source/utils/helpers/date/index.d.ts +16 -0
  25. package/source/utils/helpers/date/index.js +48 -0
  26. package/source/utils/helpers/filters/index.d.ts +17 -0
  27. package/source/utils/helpers/filters/index.js +44 -0
  28. package/source/utils/helpers/hash/crypto.d.ts +3 -0
  29. package/source/utils/helpers/hash/crypto.js +22 -0
  30. package/source/utils/helpers/id/index.d.ts +13 -0
  31. package/source/utils/helpers/id/index.js +24 -0
  32. package/source/utils/helpers/index.d.ts +16 -0
  33. package/source/utils/helpers/index.js +16 -0
  34. package/source/utils/helpers/ip/index.d.ts +1 -0
  35. package/source/utils/helpers/ip/index.js +3 -0
  36. package/source/utils/helpers/is/index.d.ts +11 -0
  37. package/source/utils/helpers/is/index.js +35 -0
  38. package/source/utils/helpers/locales/index.d.ts +52 -0
  39. package/source/utils/helpers/locales/index.js +161 -0
  40. package/source/utils/helpers/locales copy/index.d.ts +52 -0
  41. package/source/utils/helpers/locales copy/index.js +161 -0
  42. package/source/utils/helpers/math/index.d.ts +2 -0
  43. package/source/utils/helpers/math/index.js +14 -0
  44. package/source/utils/helpers/objects/index.d.ts +1 -0
  45. package/source/utils/helpers/objects/index.js +55 -0
  46. package/source/utils/helpers/path/index.d.ts +2 -0
  47. package/source/utils/helpers/path/index.js +4 -0
  48. package/source/utils/helpers/regex/checkSpecialRegexControl.d.ts +1 -0
  49. package/source/utils/helpers/regex/checkSpecialRegexControl.js +3 -0
  50. package/source/utils/helpers/string/index.d.ts +1 -0
  51. package/source/utils/helpers/string/index.js +9 -0
  52. package/source/utils/helpers/timer/index.d.ts +3 -0
  53. package/source/utils/helpers/timer/index.js +5 -0
  54. package/source/utils/helpers/tmp/index.d.ts +8 -0
  55. package/source/utils/helpers/tmp/index.js +109 -0
  56. package/source/utils/helpers/validates/index.d.ts +5 -0
  57. package/source/utils/helpers/validates/index.js +20 -0
  58. package/source/utils/index.d.ts +3 -0
  59. package/source/utils/index.js +3 -0
  60. package/source/utils/models/classes/class.controller.d.ts +121 -0
  61. package/source/utils/models/classes/class.controller.js +421 -0
  62. package/source/utils/models/classes/class.response.d.ts +17 -0
  63. package/source/utils/models/classes/class.response.js +37 -0
  64. package/source/utils/models/classes/class.services.d.ts +129 -0
  65. package/source/utils/models/classes/class.services.js +344 -0
  66. package/source/utils/models/classes/class.tmp-file-loader.d.ts +11 -0
  67. package/source/utils/models/classes/class.tmp-file-loader.js +38 -0
  68. package/source/utils/models/classes/class.x.d.ts +12 -0
  69. package/source/utils/models/classes/class.x.js +16 -0
  70. package/source/utils/models/enums/index.d.ts +116 -0
  71. package/source/utils/models/enums/index.js +132 -0
  72. package/source/utils/models/index.d.ts +8 -0
  73. package/source/utils/models/index.js +8 -0
  74. package/source/utils/models/types/index.d.ts +3 -0
  75. package/source/utils/models/types/index.js +2 -0
  76. package/x/tmp.yml +26 -0
package/README.md ADDED
@@ -0,0 +1 @@
1
+ ## **DOCUMENT**
@@ -0,0 +1,14 @@
1
+ import path from 'path'
2
+
3
+ import { __filename, __dirname } from '../helpers/index.mjs'
4
+
5
+ export const packageName = 'tmp-project-tool'
6
+
7
+ export const tmpFileDefaultMainFolderName = 'x'
8
+ export const tmpFileDefaultName = 'tmp'
9
+ export const tmpFileDefaultExt = '.yml'
10
+
11
+ export const defaultTmpFilePath = path.resolve(__dirname(__filename(import.meta.url)), `../../${tmpFileDefaultMainFolderName}/${tmpFileDefaultName}.yml`)
12
+ export const defaultOwnerTmpFilePath = path.resolve(`./${tmpFileDefaultMainFolderName}/${tmpFileDefaultName}.yml`)
13
+
14
+ export const templateRepoUri = 'https://github.com/xdloper/xastral-general-project-tmp.git'
@@ -0,0 +1,83 @@
1
+ import path from 'path'
2
+ import fs from 'fs'
3
+ import url, { fileURLToPath } from 'url'
4
+ import Handlebars from 'handlebars'
5
+
6
+ export function __filename(fileUrl) {
7
+ return fileURLToPath(fileUrl)
8
+ }
9
+
10
+ export function __dirname(__filename) {
11
+ return path.dirname(__filename)
12
+ }
13
+
14
+ export function findFileRecursively(
15
+ startDir,
16
+ baseName,
17
+ extName = '',
18
+ excludedDirs = ['node_modules', '.git']
19
+ ) {
20
+ if (typeof startDir !== 'string' || !fs.existsSync(startDir)) {
21
+ return null
22
+ }
23
+
24
+ const targetName = baseName + (extName.startsWith('.') ? extName : (extName ? `.${extName}` : ''))
25
+
26
+ try {
27
+ const entries = fs.readdirSync(startDir, { withFileTypes: true })
28
+
29
+ for (const entry of entries) {
30
+ const fullPath = path.join(startDir, entry.name)
31
+
32
+ if (entry.isFile()) {
33
+
34
+ if (!extName) {
35
+ const entryExt = path.extname(entry.name)
36
+ const entryBase = path.basename(entry.name, entryExt)
37
+
38
+ if (entryBase === baseName) {
39
+ return fullPath
40
+ }
41
+ } else {
42
+ if (entry.name === targetName) {
43
+ return fullPath
44
+ }
45
+ }
46
+ }
47
+
48
+ if (entry.isDirectory()) {
49
+ const isHiddenOrExcluded = entry.name.startsWith('.') || excludedDirs.includes(entry.name)
50
+
51
+ if (isHiddenOrExcluded) {
52
+ continue
53
+ }
54
+
55
+ const foundPath = findFileRecursively(fullPath, baseName, extName, excludedDirs)
56
+
57
+ if (foundPath) {
58
+ return foundPath
59
+ }
60
+ }
61
+ }
62
+
63
+ return null
64
+ } catch (error) {
65
+ if (error.code === 'EACCES') {
66
+ return null
67
+ }
68
+
69
+ return null
70
+ }
71
+ }
72
+
73
+ export function resolveObjWithHandlebars(obj, context) {
74
+ if (typeof obj === "string") {
75
+ const compileResult = Handlebars.compile(obj)
76
+ return compileResult(context)
77
+ } else if (typeof obj === "object" && obj !== null) {
78
+ for (const key in obj) {
79
+ obj[key] = resolveObjWithHandlebars(obj[key], context)
80
+ }
81
+ }
82
+ return obj
83
+ }
@@ -0,0 +1,179 @@
1
+ #!/usr/bin/env node
2
+ import { execSync } from 'child_process'
3
+ import fs from 'fs'
4
+ import path from 'path'
5
+ import yaml from 'yaml'
6
+ import { Command } from 'commander'
7
+ import chalk from 'chalk'
8
+ import ora from 'ora'
9
+
10
+ import { defaultOwnerTmpFilePath, defaultTmpFilePath, packageName, templateRepoUri, tmpFileDefaultExt, tmpFileDefaultMainFolderName, tmpFileDefaultName } from './constants/index.mjs'
11
+ import { findFileRecursively, resolveObjWithHandlebars } from './helpers/index.mjs'
12
+
13
+ let cli = null
14
+
15
+ let ownerTmpFilePath = null
16
+ let ownerTmpFile = null
17
+
18
+ let parsedTmpObject = null
19
+ let resolvedTmpObject = null
20
+
21
+ let projectMainFolderPath = null
22
+
23
+ try {
24
+ cli = new Command()
25
+
26
+ try {
27
+ ownerTmpFilePath = findFileRecursively('.', tmpFileDefaultName, tmpFileDefaultExt)
28
+
29
+ if(!ownerTmpFilePath){
30
+ const tmpFilePathBuffer = fs.readFileSync(defaultTmpFilePath)
31
+
32
+ fs.mkdirSync(path.resolve(tmpFileDefaultMainFolderName), {recursive:true})
33
+
34
+ fs.writeFileSync(defaultOwnerTmpFilePath, tmpFilePathBuffer)
35
+
36
+ ownerTmpFilePath = defaultOwnerTmpFilePath
37
+ }
38
+
39
+ ownerTmpFile = fs.readFileSync(ownerTmpFilePath)
40
+
41
+ if(!ownerTmpFile){
42
+ throw new Error(`${tmpFileDefaultName} File not read.`)
43
+ }
44
+
45
+ parsedTmpObject = yaml.parse(ownerTmpFile.toString())
46
+
47
+ resolvedTmpObject = resolveObjWithHandlebars(parsedTmpObject, parsedTmpObject)
48
+
49
+ projectMainFolderPath = path.resolve(resolvedTmpObject.configs.mainFolderPath)
50
+
51
+ if(!fs.existsSync(path.resolve(projectMainFolderPath))){
52
+ fs.mkdirSync(path.resolve(projectMainFolderPath))
53
+ }
54
+
55
+ } catch (error) {
56
+ console.error(`${packageName} Error:`, error?.message)
57
+ }
58
+
59
+ cli
60
+ .command('webpack')
61
+ .action(function (pathOption, options) {
62
+ if(resolvedTmpFile.configs.worker === 'development'){
63
+ exec(
64
+ `node --loader ts-node/esm node_modules/tmp-project-tool/node_modules/webpack-dev-server/bin/webpack-dev-server --config ${
65
+ path.resolve(resolvedTmpFile.configs.webpack.location.worker[resolvedTmpFile.configs.worker])
66
+ }`, {cwd: path.resolve()}, (error, stdout, stderr) => {
67
+
68
+ if (error) {
69
+ console.error(`error: ${error.message}`)
70
+ return
71
+ }
72
+
73
+ if (stderr) {
74
+ console.error(`stderr: ${stderr}`)
75
+ return
76
+ }
77
+
78
+ console.log(`stdout: ${stdout}`)
79
+ })
80
+ }else{
81
+ exec(
82
+ `node --loader ts-node/esm node_modules/tmp-project-tool/node_modules/webpack-cli/bin/cli.js --config ${
83
+ path.resolve(resolvedTmpFile.configs.webpack.location.worker[resolvedTmpFile.configs.worker])
84
+ }`, {cwd: path.resolve()}, (error, stdout, stderr) => {
85
+
86
+ if (error) {
87
+ console.error(error, stderr)
88
+ return
89
+ }
90
+
91
+ if (stderr) {
92
+ console.error(`stderr: ${stderr}`)
93
+ return
94
+ }
95
+
96
+ console.log(`stdout: ${stdout}`)
97
+ })
98
+ }
99
+ })
100
+
101
+ /*
102
+ exec(`node --loader ts-node/esm ./${packagePathname}/src/index.ts ${options.config ? `--config ${options.config}` : ''}` , (error, stdout, stderr) => {
103
+ if (error) {
104
+ console.error(`error: ${error.message}`)
105
+ return
106
+ }
107
+
108
+ if (stderr) {
109
+ console.error(`stderr: ${stderr}`)
110
+ return
111
+ }
112
+
113
+ console.log(`stdout: ${stdout}`)
114
+ })
115
+ */
116
+
117
+ cli
118
+ .command('create <project-name>')
119
+ .description('Clone template from GitHub (Private/Public)')
120
+ .action(async (projectName) => {
121
+ const targetPath = path.join(process.cwd(), projectName)
122
+
123
+ // 1. Klasör Kontrolü
124
+ if (fs.existsSync(targetPath)) {
125
+ console.log(chalk.red(`❌ Error: '${projectName}' folder already exists!`))
126
+ process.exit(1)
127
+ }
128
+
129
+ const repoURL = templateRepoUri
130
+
131
+ const spinner = ora('Cloning template from GitHub...').start()
132
+
133
+ try {
134
+ execSync(`git clone --depth 1 ${repoURL} "${targetPath}"`, {
135
+ stdio: 'ignore'
136
+ })
137
+
138
+ const gitFolder = path.join(targetPath, '.git')
139
+ if (fs.existsSync(gitFolder)) {
140
+ fs.rmSync(gitFolder, { recursive: true, force: true })
141
+ }
142
+
143
+ spinner.succeed(chalk.green('Template cloned successfully!'))
144
+
145
+ console.log(chalk.blue(`\n📦 Dependencies loading... (${projectName})`))
146
+
147
+ execSync('npm install', {
148
+ cwd: targetPath,
149
+ stdio: 'inherit'
150
+ })
151
+
152
+ console.log(chalk.green('\n✅ Project Ready!'))
153
+ console.log(chalk.white(`\nStart Project:\n`))
154
+ console.log(chalk.cyan(` cd ${projectName}`))
155
+ console.log(chalk.cyan(` npm run dev`))
156
+
157
+ } catch (err) {
158
+ spinner.fail(chalk.red('Failed to clone or install!'))
159
+
160
+ console.error(chalk.red('\nPossible reasons:'))
161
+ console.error(chalk.yellow('1. You might not have access to this private repo.'))
162
+ console.error(chalk.yellow('2. Git is not installed or configured on this machine.'))
163
+ console.error(chalk.red(`\nError details: ${err.message}`))
164
+
165
+ if (fs.existsSync(targetPath)) {
166
+ fs.rmSync(targetPath, { recursive: true, force: true })
167
+ }
168
+ }
169
+ })
170
+
171
+ cli.parse(process.argv)
172
+ } catch (error) {
173
+ console.error(`x cli:${error?.message}`)
174
+ }
175
+
176
+ process.on('uncaughtException', (error) => {
177
+ console.error('Uncaught Exception:', error.message)
178
+ process.exit(1)
179
+ })
package/package.json ADDED
@@ -0,0 +1,113 @@
1
+ {
2
+ "name": "@xrystal/core",
3
+ "version": "3.2.3",
4
+ "description": "Project core for xrystal",
5
+ "publishConfig": {
6
+ "access": "public",
7
+ "registry": "https://registry.npmjs.org/"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/xdloper/-xrystal-core.git"
12
+ },
13
+ "files": [
14
+ "source",
15
+ "bin",
16
+ "x",
17
+ "README.md"
18
+ ],
19
+ "main": "source/index.ts",
20
+ "types": "./index.d.ts",
21
+ "exports": {
22
+ ".": {
23
+ "types": "./source/index.d.ts",
24
+ "import": "./source/index.js",
25
+ "require": "./source/index.js"
26
+ },
27
+ "./*": {
28
+ "types": "./source/*.d.ts",
29
+ "import": "./source/*.js"
30
+ }
31
+ },
32
+ "type": "module",
33
+ "bin": {
34
+ "tmp": "./bin/main-cli.js"
35
+ },
36
+ "scripts": {
37
+ "dev": "tsx watch --env-file=../infrastructer/x/environments/.global.env --env-file=../infrastructer/x/environments/.dev.env --include \"./source/**/*.ts\" --include \"./x\" --exclude node_modules --exclude x/ts-build source/index.ts",
38
+ "lint": "eslint .",
39
+ "build": "./node_modules/.bin/tsc",
40
+ "start": "node ./x/ts-build/index.js",
41
+ "webpack-dev": "node --loader ts-node/esm node_modules/webpack-dev-server/bin/webpack-dev-server --config ./x/webpack/webpack.config.dev.ts",
42
+ "webpack-prod": "node --loader ts-node/esm node_modules/webpack-cli/bin/cli.js --config ./x/webpack/webpack.config.prod.ts"
43
+ },
44
+ "dependencies": {
45
+ "@babel/cli": "^7.21.0",
46
+ "@babel/core": "^7.21.4",
47
+ "@babel/preset-env": "^7.21.4",
48
+ "@babel/preset-react": "^7.18.6",
49
+ "@types/bcrypt": "^5.0.2",
50
+ "@types/webpack": "^5.28.3",
51
+ "@types/webpack-dev-server": "^4.7.2",
52
+ "@types/webpack-merge": "^5.0.0",
53
+ "@types/webpack-node-externals": "^3.0.4",
54
+ "@types/yaml": "^1.9.7",
55
+ "axios": "^1.13.2",
56
+ "babel-loader": "^9.1.2",
57
+ "chalk": "^5.6.2",
58
+ "clean-webpack-plugin": "^4.0.0",
59
+ "commander": "^13.0.0",
60
+ "copy-webpack-plugin": "^11.0.0",
61
+ "css-loader": "^6.7.3",
62
+ "dotenv": "^16.3.1",
63
+ "ejs": "^3.1.9",
64
+ "ejs-compiled-loader": "^3.1.0",
65
+ "ejs-loader": "^0.5.0",
66
+ "ejs-webpack-loader": "^2.2.2",
67
+ "file-loader": "^6.2.0",
68
+ "handlebars": "^4.7.8",
69
+ "handlebars-loader": "^1.7.3",
70
+ "html-loader": "^4.2.0",
71
+ "html-webpack-plugin": "^5.6.0",
72
+ "i18next": "^25.6.3",
73
+ "i18next-fs-backend": "^2.6.1",
74
+ "i18next-http-middleware": "^3.8.2",
75
+ "jquery": "^3.7.1",
76
+ "kafkajs": "^2.2.4",
77
+ "logform": "^2.7.0",
78
+ "mini-css-extract-plugin": "^2.9.0",
79
+ "minimist": "^1.2.8",
80
+ "moment-timezone": "^0.6.0",
81
+ "nodemailer": "^7.0.11",
82
+ "nodemailer-express-handlebars": "^7.0.0",
83
+ "ora": "^9.0.0",
84
+ "postcss-loader": "^7.2.4",
85
+ "react": "^18.2.0",
86
+ "react-dom": "^18.2.0",
87
+ "sass": "^1.62.0",
88
+ "sass-loader": "^13.2.2",
89
+ "soap": "^1.6.0",
90
+ "ts-loader": "^8.0.0",
91
+ "url-loader": "^4.1.1",
92
+ "webpack-dev-server": "^4.13.3",
93
+ "webpack-merge": "^6.0.1",
94
+ "webpack-node-externals": "^3.0.0",
95
+ "winston": "^3.19.0",
96
+ "winston-daily-rotate-file": "^5.0.0",
97
+ "winston-mongodb": "^7.0.1",
98
+ "yaml": "^2.5.0"
99
+ },
100
+ "author": "y.yasir.k",
101
+ "license": "ISC",
102
+ "devDependencies": {
103
+ "@types/minimist": "^1.2.5",
104
+ "@types/nodemailer": "^7.0.4",
105
+ "@types/nodemailer-express-handlebars": "^4.0.6",
106
+ "ts-node": "^10.9.2",
107
+ "tsconfig-paths": "^4.2.0",
108
+ "tsx": "^4.21.0",
109
+ "typescript": "^5.5.3",
110
+ "webpack": "^5.104.1",
111
+ "webpack-cli": "^6.0.1"
112
+ }
113
+ }
@@ -0,0 +1,2 @@
1
+ declare let tmp: any;
2
+ export default tmp;
@@ -0,0 +1,8 @@
1
+ import coreLoader from "./project/index.js";
2
+ let tmp;
3
+ // => tmp project tool => xrystal
4
+ await (async () => {
5
+ tmp = await coreLoader();
6
+ })();
7
+ //
8
+ export default tmp;
@@ -0,0 +1,13 @@
1
+ import SystemService from '../system/index';
2
+ export default class ConfigsService {
3
+ protected _globalEnvFileName: string;
4
+ protected _systemService: SystemService;
5
+ static tmpFolderPath: string;
6
+ private _envLoadPath;
7
+ load: ({ tmpFolderPath, systemService, envLoadPath, globalEnvFileName }: {
8
+ tmpFolderPath: string;
9
+ systemService: SystemService;
10
+ envLoadPath: string;
11
+ globalEnvFileName?: string | null;
12
+ }) => any;
13
+ }
@@ -0,0 +1,17 @@
1
+ export default class ConfigsService {
2
+ _globalEnvFileName = 'global';
3
+ _systemService;
4
+ static tmpFolderPath;
5
+ _envLoadPath = '';
6
+ load = ({ tmpFolderPath, systemService, envLoadPath, globalEnvFileName }) => {
7
+ ConfigsService.tmpFolderPath = tmpFolderPath;
8
+ this._systemService = systemService;
9
+ this._envLoadPath = `${envLoadPath}`;
10
+ /*
11
+ this._dynamicEnvLoader({
12
+ nodeEnv
13
+ globalEnvFileName
14
+ })
15
+ */
16
+ };
17
+ }
@@ -0,0 +1,6 @@
1
+ export default class EventsService {
2
+ private logger;
3
+ load: ({}: {}) => any;
4
+ private _globalLoader;
5
+ get global(): any;
6
+ }
@@ -0,0 +1,25 @@
1
+ import LoggersLoader from '../logger/index';
2
+ import { x, LoggerLayerEnum } from '../../utils/index';
3
+ export default class EventsService {
4
+ logger = x.get(LoggersLoader);
5
+ load = ({}) => {
6
+ this._globalLoader();
7
+ };
8
+ _globalLoader = () => {
9
+ process.on("uncaughtException", (exception) => {
10
+ this.logger.winston.log({
11
+ level: LoggerLayerEnum[LoggerLayerEnum.CRITICAL].toLowerCase(),
12
+ message: `UncaughtException: ${exception}`,
13
+ });
14
+ });
15
+ process.on("unhandledRejection", (exception) => {
16
+ this.logger.winston.log({
17
+ level: LoggerLayerEnum[LoggerLayerEnum.CRITICAL].toLowerCase(),
18
+ message: `UnhandledRejection: ${exception}`,
19
+ });
20
+ });
21
+ };
22
+ get global() {
23
+ return this._globalLoader();
24
+ }
25
+ }
@@ -0,0 +1,6 @@
1
+ import SystemService from "./system";
2
+ import ConfigsService from "./configs";
3
+ import LoggerService from "./logger";
4
+ import EventsService from "./events";
5
+ import LocalizationsService from "./localizations";
6
+ export { SystemService, ConfigsService, LoggerService, EventsService, LocalizationsService };
@@ -0,0 +1,6 @@
1
+ import SystemService from "./system";
2
+ import ConfigsService from "./configs";
3
+ import LoggerService from "./logger";
4
+ import EventsService from "./events";
5
+ import LocalizationsService from "./localizations";
6
+ export { SystemService, ConfigsService, LoggerService, EventsService, LocalizationsService };
@@ -0,0 +1,14 @@
1
+ export default class LocalizationsService {
2
+ _instance: any;
3
+ load: ({ loadPath, fallbackLang, preloadLang, }: {
4
+ loadPath: string;
5
+ fallbackLang: string;
6
+ preloadLang: string;
7
+ }) => any;
8
+ i18next: ({ loadPath, fallbackLang, preloadLang, }: {
9
+ loadPath?: string;
10
+ fallbackLang?: string;
11
+ preloadLang?: any;
12
+ }) => any;
13
+ get instance(): any;
14
+ }
@@ -0,0 +1,32 @@
1
+ import i18next from "i18next";
2
+ import Backend from 'i18next-fs-backend';
3
+ import * as middleware from 'i18next-http-middleware';
4
+ export default class LocalizationsService {
5
+ _instance = null;
6
+ load = ({ loadPath, fallbackLang, preloadLang, }) => {
7
+ this.i18next({
8
+ loadPath,
9
+ fallbackLang,
10
+ preloadLang,
11
+ });
12
+ };
13
+ i18next = ({ loadPath, fallbackLang, preloadLang, }) => {
14
+ if (this._instance) {
15
+ return this._instance;
16
+ }
17
+ i18next
18
+ .use(Backend)
19
+ .use(middleware.LanguageDetector)
20
+ .init({
21
+ fallbackLng: fallbackLang,
22
+ preload: preloadLang,
23
+ backend: { loadPath: `${loadPath}/{{lng}}.json` }
24
+ });
25
+ if (i18next)
26
+ this._instance = i18next;
27
+ return i18next;
28
+ };
29
+ get instance() {
30
+ return this._instance;
31
+ }
32
+ }
@@ -0,0 +1,22 @@
1
+ import winston from 'winston';
2
+ import 'winston-daily-rotate-file';
3
+ interface CustomLogger extends winston.Logger {
4
+ critical: winston.LeveledLogMethod;
5
+ }
6
+ export default class LoggerService {
7
+ private serviceName;
8
+ private environment;
9
+ private kafkaProducer;
10
+ private kafkaTopic;
11
+ private isKafkaReady;
12
+ private getConsoleFormat;
13
+ winston: CustomLogger;
14
+ constructor();
15
+ load: (config: any) => Promise<void>;
16
+ winstonLoader: ({ loadPath, loggerLevel }: {
17
+ loadPath: string;
18
+ loggerLevel: string;
19
+ }) => CustomLogger;
20
+ private logToKafka;
21
+ }
22
+ export {};