@xrystal/core 3.28.3 → 3.37.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.
- package/README.md +2331 -21
- package/package.json +66 -24
- package/tsconfig.base.json +15 -0
- package/x/bin/commands/create.mjs +136 -0
- package/x/bin/commands/doctor.mjs +149 -0
- package/x/bin/commands/hooks.mjs +55 -0
- package/x/bin/commands/project.mjs +126 -0
- package/x/bin/commands/release.mjs +66 -0
- package/x/bin/commands/sync-toolchain.mjs +43 -0
- package/x/bin/commands/tmp.mjs +57 -0
- package/x/bin/constants/index.mjs +6 -0
- package/x/bin/helpers/.generated/.generated-from +1 -0
- package/x/bin/helpers/.generated/tmp-schema.mjs +192 -0
- package/x/bin/helpers/banner.mjs +80 -0
- package/x/bin/helpers/build-config.mjs +342 -0
- package/x/bin/helpers/cli-help.mjs +164 -0
- package/x/bin/helpers/cli-identity.mjs +17 -0
- package/x/bin/helpers/create-target.mjs +35 -0
- package/{bin → x/bin}/helpers/index.mjs +44 -1
- package/x/bin/helpers/project-artifacts.mjs +140 -0
- package/x/bin/helpers/project-root.mjs +70 -0
- package/x/bin/helpers/runtime-info.mjs +172 -0
- package/x/bin/helpers/tmp-config.mjs +67 -0
- package/x/bin/helpers/tmp-layout.mjs +281 -0
- package/x/bin/helpers/tmp-schema.mjs +9 -0
- package/x/bin/helpers/toolchain-config.mjs +233 -0
- package/x/bin/main-cli.js +80 -0
- package/x/bin/paths.mjs +14 -0
- package/x/bin/scripts/clean-source-types.mjs +19 -0
- package/x/bin/scripts/fix-dist-imports.mjs +80 -0
- package/x/bin/scripts/install-git-hooks.mjs +86 -0
- package/x/bin/scripts/minify-dist.mjs +50 -0
- package/x/bin/scripts/prepare-npm-publish.mjs +49 -0
- package/x/bin/scripts/release-prepare.mjs +56 -0
- package/x/bin/scripts/tag.mjs +17 -0
- package/x/bin/scripts/unpublish-leaked-versions.mjs +62 -0
- package/x/bin/scripts/verify-npm-pack.mjs +45 -0
- package/x/bin/scripts/verify-version-bump.mjs +27 -0
- package/x/bin/scripts/version-check.mjs +370 -0
- package/x/dist/index.d.ts +3 -0
- package/x/dist/index.js +1 -0
- package/{source → x/dist}/loader/clients/index.d.ts +2 -1
- package/x/dist/loader/clients/index.js +1 -0
- package/{source → x/dist}/loader/configs/index.d.ts +3 -2
- package/x/dist/loader/configs/index.js +1 -0
- package/x/dist/loader/controller/index.d.ts +69 -0
- package/x/dist/loader/controller/index.js +1 -0
- package/x/dist/loader/dto/index.d.ts +39 -0
- package/x/dist/loader/dto/index.js +1 -0
- package/{source → x/dist}/loader/events/index.d.ts +1 -1
- package/x/dist/loader/events/index.js +1 -0
- package/{source → x/dist}/loader/index.d.ts +2 -1
- package/x/dist/loader/index.js +1 -0
- package/{source → x/dist}/loader/kafka/index.d.ts +6 -3
- package/x/dist/loader/kafka/index.js +1 -0
- package/{source → x/dist}/loader/localizations/index.d.ts +4 -3
- package/x/dist/loader/localizations/index.js +1 -0
- package/{source → x/dist}/loader/logger/index.d.ts +10 -7
- package/x/dist/loader/logger/index.js +2 -0
- package/x/dist/loader/service/index.js +1 -0
- package/{source → x/dist}/loader/system/index.d.ts +4 -3
- package/x/dist/loader/system/index.js +1 -0
- package/{source → x/dist}/project/index.d.ts +2 -2
- package/x/dist/project/index.js +1 -0
- package/x/dist/utils/constants/defaults.json +44 -0
- package/x/dist/utils/constants/index.d.ts +27 -0
- package/x/dist/utils/constants/index.js +1 -0
- package/x/dist/utils/helpers/configs/index.js +1 -0
- package/x/dist/utils/helpers/context/controller-store.d.ts +51 -0
- package/x/dist/utils/helpers/context/controller-store.js +1 -0
- package/x/dist/utils/helpers/context/index.d.ts +18 -0
- package/x/dist/utils/helpers/context/index.js +1 -0
- package/{source → x/dist}/utils/helpers/core/index.d.ts +8 -6
- package/x/dist/utils/helpers/core/index.js +1 -0
- package/x/dist/utils/helpers/core/paths.d.ts +2 -0
- package/x/dist/utils/helpers/core/paths.js +1 -0
- package/x/dist/utils/helpers/core/tmp-layout.d.ts +45 -0
- package/x/dist/utils/helpers/core/tmp-layout.js +1 -0
- package/{source → x/dist}/utils/helpers/date/index.d.ts +1 -1
- package/x/dist/utils/helpers/date/index.js +1 -0
- package/x/dist/utils/helpers/dispatch/index.d.ts +9 -0
- package/x/dist/utils/helpers/dispatch/index.js +1 -0
- package/x/dist/utils/helpers/dto/index.d.ts +10 -0
- package/x/dist/utils/helpers/dto/index.js +1 -0
- package/x/dist/utils/helpers/filters/index.js +1 -0
- package/x/dist/utils/helpers/framework/index.d.ts +3 -0
- package/x/dist/utils/helpers/framework/index.js +1 -0
- package/x/dist/utils/helpers/handlers/adapters.d.ts +10 -0
- package/x/dist/utils/helpers/handlers/adapters.js +1 -0
- package/x/dist/utils/helpers/handlers/execute.d.ts +5 -0
- package/x/dist/utils/helpers/handlers/execute.js +1 -0
- package/x/dist/utils/helpers/handlers/index.d.ts +18 -0
- package/x/dist/utils/helpers/handlers/index.js +1 -0
- package/x/dist/utils/helpers/hash/crypto.js +1 -0
- package/x/dist/utils/helpers/id/index.js +1 -0
- package/x/dist/utils/helpers/index.d.ts +26 -0
- package/x/dist/utils/helpers/index.js +1 -0
- package/x/dist/utils/helpers/ip/index.js +1 -0
- package/x/dist/utils/helpers/is/index.js +1 -0
- package/{source → x/dist}/utils/helpers/locales/index.d.ts +1 -0
- package/x/dist/utils/helpers/locales/index.js +1 -0
- package/x/dist/utils/helpers/math/index.js +1 -0
- package/x/dist/utils/helpers/middleware/index.d.ts +19 -0
- package/x/dist/utils/helpers/middleware/index.js +1 -0
- package/x/dist/utils/helpers/objects/index.js +1 -0
- package/x/dist/utils/helpers/path/index.js +1 -0
- package/x/dist/utils/helpers/protocol/index.d.ts +20 -0
- package/x/dist/utils/helpers/protocol/index.js +1 -0
- package/x/dist/utils/helpers/protocol/options.d.ts +6 -0
- package/x/dist/utils/helpers/protocol/options.js +1 -0
- package/x/dist/utils/helpers/regex/checkSpecialRegexControl.js +1 -0
- package/x/dist/utils/helpers/runtime/dto-access.d.ts +3 -0
- package/x/dist/utils/helpers/runtime/dto-access.js +1 -0
- package/x/dist/utils/helpers/runtime/dto-types.d.ts +19 -0
- package/x/dist/utils/helpers/runtime/dto-types.js +1 -0
- package/x/dist/utils/helpers/runtime/index.d.ts +3 -0
- package/x/dist/utils/helpers/runtime/index.js +1 -0
- package/x/dist/utils/helpers/runtime/shutdown.d.ts +3 -0
- package/x/dist/utils/helpers/runtime/shutdown.js +1 -0
- package/x/dist/utils/helpers/state/index.d.ts +59 -0
- package/x/dist/utils/helpers/state/index.js +1 -0
- package/x/dist/utils/helpers/state/props-from-tmp.d.ts +9 -0
- package/x/dist/utils/helpers/state/props-from-tmp.js +1 -0
- package/x/dist/utils/helpers/state/request-key-guard.d.ts +3 -0
- package/x/dist/utils/helpers/state/request-key-guard.js +1 -0
- package/x/dist/utils/helpers/state/scopes.d.ts +21 -0
- package/x/dist/utils/helpers/state/scopes.js +1 -0
- package/x/dist/utils/helpers/string/index.js +1 -0
- package/x/dist/utils/helpers/tests/tmp-schema.test.js +1 -0
- package/{source/utils/models/types/index.js → x/dist/utils/helpers/tests/tmp-watch.test.d.ts} +0 -1
- package/x/dist/utils/helpers/tests/tmp-watch.test.js +1 -0
- package/x/dist/utils/helpers/timer/index.js +1 -0
- package/x/dist/utils/helpers/tmp/index.d.ts +5 -0
- package/x/dist/utils/helpers/tmp/index.js +1 -0
- package/x/dist/utils/helpers/tmp/loader-tmp-sync.d.ts +4 -0
- package/x/dist/utils/helpers/tmp/loader-tmp-sync.js +1 -0
- package/x/dist/utils/helpers/tmp/runtime-tmp.d.ts +9 -0
- package/x/dist/utils/helpers/tmp/runtime-tmp.js +1 -0
- package/x/dist/utils/helpers/tmp/tmp-loader.d.ts +7 -0
- package/x/dist/utils/helpers/tmp/tmp-loader.js +1 -0
- package/x/dist/utils/helpers/tmp/tmp-schema.d.ts +47 -0
- package/x/dist/utils/helpers/tmp/tmp-schema.js +1 -0
- package/x/dist/utils/helpers/tmp/tmp-watch.d.ts +1 -0
- package/x/dist/utils/helpers/tmp/tmp-watch.js +1 -0
- package/x/dist/utils/helpers/validates/index.js +1 -0
- package/x/dist/utils/index.d.ts +3 -0
- package/x/dist/utils/index.js +1 -0
- package/x/dist/utils/models/classes/class.clients.js +1 -0
- package/x/dist/utils/models/classes/class.interfaces.js +1 -0
- package/x/dist/utils/models/classes/class.service-locator.js +1 -0
- package/{source → x/dist}/utils/models/classes/class.tmp-file-loader.d.ts +3 -2
- package/x/dist/utils/models/classes/class.tmp-file-loader.js +1 -0
- package/x/dist/utils/models/classes/class.x.js +1 -0
- package/{source → x/dist}/utils/models/enums/index.d.ts +14 -1
- package/x/dist/utils/models/enums/index.js +1 -0
- package/x/dist/utils/models/index.d.ts +9 -0
- package/x/dist/utils/models/index.js +1 -0
- package/x/dist/utils/models/types/index.d.ts +5 -0
- package/x/dist/utils/models/types/index.js +1 -0
- package/x/dist/utils/package-root.d.ts +2 -0
- package/x/dist/utils/package-root.js +1 -0
- package/x/tmp.yml +48 -17
- package/bin/constants/index.mjs +0 -17
- package/bin/main-cli.js +0 -131
- package/source/index.js +0 -6
- package/source/loader/clients/index.js +0 -18
- package/source/loader/configs/index.js +0 -81
- package/source/loader/controller/index.d.ts +0 -129
- package/source/loader/controller/index.js +0 -327
- package/source/loader/events/index.js +0 -44
- package/source/loader/index.js +0 -10
- package/source/loader/kafka/index.js +0 -122
- package/source/loader/localizations/index.js +0 -40
- package/source/loader/logger/index.js +0 -183
- package/source/loader/service/index.js +0 -7
- package/source/loader/system/index.js +0 -19
- package/source/project/index.js +0 -66
- package/source/utils/constants/index.d.ts +0 -10
- package/source/utils/constants/index.js +0 -11
- package/source/utils/helpers/configs/index.js +0 -1
- package/source/utils/helpers/core/index.js +0 -105
- package/source/utils/helpers/date/index.js +0 -48
- package/source/utils/helpers/filters/index.js +0 -44
- package/source/utils/helpers/hash/crypto.js +0 -22
- package/source/utils/helpers/id/index.js +0 -24
- package/source/utils/helpers/index.d.ts +0 -17
- package/source/utils/helpers/index.js +0 -17
- package/source/utils/helpers/ip/index.js +0 -21
- package/source/utils/helpers/is/index.js +0 -35
- package/source/utils/helpers/locales/index.js +0 -63
- package/source/utils/helpers/math/index.js +0 -14
- package/source/utils/helpers/middlewares/index.d.ts +0 -1
- package/source/utils/helpers/middlewares/index.js +0 -26
- package/source/utils/helpers/objects/index.js +0 -55
- package/source/utils/helpers/path/index.js +0 -4
- package/source/utils/helpers/regex/checkSpecialRegexControl.js +0 -3
- package/source/utils/helpers/string/index.js +0 -9
- package/source/utils/helpers/timer/index.js +0 -5
- package/source/utils/helpers/validates/index.js +0 -20
- package/source/utils/index.d.ts +0 -3
- package/source/utils/index.js +0 -3
- package/source/utils/models/classes/class.clients.js +0 -142
- package/source/utils/models/classes/class.dtos.d.ts +0 -47
- package/source/utils/models/classes/class.dtos.js +0 -36
- package/source/utils/models/classes/class.interfaces.js +0 -10
- package/source/utils/models/classes/class.response.d.ts +0 -17
- package/source/utils/models/classes/class.response.js +0 -35
- package/source/utils/models/classes/class.service-locator.js +0 -16
- package/source/utils/models/classes/class.tmp-file-loader.js +0 -38
- package/source/utils/models/classes/class.x.js +0 -179
- package/source/utils/models/enums/index.js +0 -133
- package/source/utils/models/index.d.ts +0 -11
- package/source/utils/models/index.js +0 -11
- package/source/utils/models/types/index.d.ts +0 -3
- /package/{source → x/dist}/loader/service/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/configs/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/filters/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/hash/crypto.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/id/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/ip/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/is/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/math/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/objects/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/path/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/regex/checkSpecialRegexControl.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/string/index.d.ts +0 -0
- /package/{source/index.d.ts → x/dist/utils/helpers/tests/tmp-schema.test.d.ts} +0 -0
- /package/{source → x/dist}/utils/helpers/timer/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/validates/index.d.ts +0 -0
- /package/{source → x/dist}/utils/models/classes/class.clients.d.ts +0 -0
- /package/{source → x/dist}/utils/models/classes/class.interfaces.d.ts +0 -0
- /package/{source → x/dist}/utils/models/classes/class.service-locator.d.ts +0 -0
- /package/{source → x/dist}/utils/models/classes/class.x.d.ts +0 -0
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
const f = (...args) => args.filter(item => item && typeof item === 'string' && item.trim() !== '').join(' ').trim();
|
|
2
|
-
export const coreMessages = {
|
|
3
|
-
'successfully': (p = '', e = '', t) => `${f(p, e)} ${t && t('responseMessage.successfully')}.`.trim(),
|
|
4
|
-
'unsuccessful': (p = '', e = '', t) => `${f(p, e)} ${t && t('responseMessage.unsuccessful')}.`.trim(),
|
|
5
|
-
'notFound': (p = '', e = '', t) => `${f(p, e)} ${t && t('responseMessage.notFound')}.`.trim(),
|
|
6
|
-
'notMatch': (p = '', e = '', t) => `${f(p, e)} ${t && t('responseMessage.notMatch')}.`.trim(),
|
|
7
|
-
'notUse': (p = '', e = '', t) => `${f(p, e)} ${t && t('responseMessage.notUse')}.`.trim(),
|
|
8
|
-
'invalid': (p = '', e = '', t) => `${f(p, e)} ${t && t('responseMessage.invalid')}.`.trim(),
|
|
9
|
-
'checked': (p = '', e = '', t) => `${f(p, e)} ${t && t('responseMessage.checked')}.`.trim(),
|
|
10
|
-
'process': (p = '', e = '', t) => `${f(p, e)} ${t && t('responseMessage.process')}.`.trim(),
|
|
11
|
-
'missingData': (p = '', e = '', t) => `${f(p, e)} ${t && t('responseMessage.missingData')}.`.trim(),
|
|
12
|
-
'allreadyHave': (p = '', e = '', t) => `${f(p, e)} ${t && t('responseMessage.allreadyHave')}.`.trim(),
|
|
13
|
-
'wrongFormat': (p = '', e = '', t) => `${f(p, e)} ${t && t('responseMessage.wrongFormat')}.`.trim(),
|
|
14
|
-
'externalApiError': (p = '', e = '', t) => `${f(p, e)}, ${t && t('responseMessage.externalApiError')}.`.trim(),
|
|
15
|
-
'unauthorizedUrl': (p = '', e = '', t) => `${f(p, e)}, ${t && t('responseMessage.unauthorizedUrl')}.`.trim(),
|
|
16
|
-
'endpointNotWorking': (endpoint = '', t) => `${endpoint}, ${t && t('responseMessage.endpointNotWorking')}.`.trim(),
|
|
17
|
-
'schemaMissingDataChecks': (t) => `${t && t('responseMessage.schemaMissingDataChecks')}.`.trim(),
|
|
18
|
-
'schemaInvalidDataChecks': (t) => `${t && t('responseMessage.schemaInvalidDataChecks')}.`.trim(),
|
|
19
|
-
'schemaUnknowErrorChecks': (a, b, t) => `${t && t('responseMessage.schemaUnknowErrorChecks')}. ${a}. ${t('responseMessage.schemaErrorExtraExplanation')}: ${b}`.trim(),
|
|
20
|
-
'schemaUnknowErrorLogic': (a, b, t) => `${t && t('responseMessage.schemaUnknowErrorLogic')}. ${a}. ${t('responseMessage.schemaErrorExtraExplanation')}: ${b}`.trim(),
|
|
21
|
-
'schemaUnknowErrorResponse': (a, b, t) => `${t && t('responseMessage.schemaUnknowErrorLogic')}. ${a}. ${t('responseMessage.schemaErrorExtraExplanation')}: ${b}`.trim(),
|
|
22
|
-
'schemaUnknowErrorMain': (a, b, t) => `${t && t('responseMessage.schemaUnknowErrorMain')}. ${a}. ${t('responseMessage.schemaErrorExtraExplanation')}: ${b}`.trim(),
|
|
23
|
-
'dbQueryError': (p = '', e = '', t) => `${t && t('responseMessage.dbQueryError')}. ${f(p, e)}`.trim(),
|
|
24
|
-
'unknowError': (p = '', e = '', t) => `${t && t('responseMessage.unknowError')}. ${f(p, e)}`.trim(),
|
|
25
|
-
'serverError': (p = '', e = '', t) => `${t && t('responseMessage.serverError')}. ${f(p, e)}`.trim(),
|
|
26
|
-
'emailWelcomeTemplateTitle': (t) => `${t && t('responseMessage.emailWelcomeTemplateTitle')}`.trim(),
|
|
27
|
-
'emailWelcomeTemplateExplanation': (t) => `${t && t('responseMessage.emailWelcomeTemplateExplanation')}.`.trim(),
|
|
28
|
-
'emailForgotPasswordTemplateTitle': (t) => `${t && t('responseMessage.emailForgotPasswordTemplateTitle')}`.trim(),
|
|
29
|
-
'emailForgotPasswordTemplateExplanation': (t) => `${t && t('responseMessage.emailForgotPasswordTemplateExplanation')}.`.trim(),
|
|
30
|
-
'allRightsReserved': (e1 = '', e2 = '', t) => `${f(e1, e2)}, ${t && t('responseMessage.allRightsReserved')}.`.trim(),
|
|
31
|
-
'emailButtonText': (t) => `${t && t('responseMessage.emailButtonText')}.`.trim(),
|
|
32
|
-
'emailIgnoreText': (t) => `${t && t('responseMessage.emailIgnoreText')}.`.trim(),
|
|
33
|
-
'welcomeMessage': (username = '', t) => `@${username} - ${t && t('responseMessage.welcome')}.`.trim(),
|
|
34
|
-
'userIsBlocked': (extra1 = '', t) => `${extra1}, ${t && t('responseMessage.userIsBlocked')}.`.trim(),
|
|
35
|
-
'passwordChangeCode': (username = '', t) => `@${username} - ${t && t('responseMessage.passwordChangeCode')}.`.trim(),
|
|
36
|
-
'notEnoughWalletBalance': (m = '', c = '', t) => `${f(m, c)}, ${t && t('responseMessage.notEnoughWalletBalance')}.`.trim(),
|
|
37
|
-
'openAuthConsumerOverhang': (p1 = '', p2 = '', t) => `${f(p1, p2)}, ${t && t('responseMessage.openAuthConsumerOverhang')}.`.trim(),
|
|
38
|
-
'thirdPartySystemOverhang': (p1 = '', p2 = '', t) => `${f(p1, p2)}, ${t && t('responseMessage.thirdPartySystems')}.`.trim(),
|
|
39
|
-
'deviceOverhang': (p1 = '', p2 = '', t) => `${f(p1, p2)}, ${t && t('responseMessage.deviceOverhang')}.`.trim(),
|
|
40
|
-
'provisionOverhang': (m = '', c = '', t) => `${f(m, c)}, ${t && t('responseMessage.provisionOverhang')}.`.trim(),
|
|
41
|
-
'balanceOverhang': (m = '', c = '', t) => `${f(m, c)}, ${t && t('responseMessage.balanceOverhang')}.`.trim(),
|
|
42
|
-
'debtOverhang': (m = '', c = '', t) => `${f(m, c)}, ${t && t('responseMessage.debtOverhang')}.`.trim(),
|
|
43
|
-
'shipmentNotAccepted': (v1 = '', v2 = '', t) => `${t && t('responseMessage.shipmentNotAccepted')}. ${f(v1, v2)}`.trim(),
|
|
44
|
-
'optionsMethod': (m = '', t) => `${t && t('responseMessage.optionsMethod')}. ${m}`.trim(),
|
|
45
|
-
'notAllowedCORS': (m = '', t) => `${t && t('responseMessage.notAllowedCORS')}. ${m}`.trim(),
|
|
46
|
-
'missingCRSFToken': (t) => `${t && t('responseMessage.missingCSRFToken')}.`.trim(),
|
|
47
|
-
'invalidCRSFToken': (t) => `${t && t('responseMessage.invalidCSRFToken')}.`.trim(),
|
|
48
|
-
'tooManyRequest': (t) => `${t && t('responseMessage.tooManyRequest')}.`.trim(),
|
|
49
|
-
'endpointNotFound': (t) => `${t && t('responseMessage.endpointNotFound')}.`.trim(),
|
|
50
|
-
'roleAccess': (error = '', t) => `${t && t('responseMessage.roleAccess')}. ${error}`.trim(),
|
|
51
|
-
'authenticationRequiredTokenExpired': (t) => `${t && t('responseMessage.authenticationRequiredTokenExpired')}.`.trim(),
|
|
52
|
-
'authenticationRequired': (t) => `${t && t('responseMessage.authenticationRequired')}.`.trim(),
|
|
53
|
-
};
|
|
54
|
-
export const responseMessageHelper = new Proxy(coreMessages, {
|
|
55
|
-
get(target, prop) {
|
|
56
|
-
if (prop in target)
|
|
57
|
-
return target[prop];
|
|
58
|
-
const local = globalThis.__LOCAL_MESSAGES__;
|
|
59
|
-
if (local && prop in local)
|
|
60
|
-
return local[prop];
|
|
61
|
-
return (p = '', e = '', t) => `${f(p, e)} ${prop}.`.trim();
|
|
62
|
-
}
|
|
63
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export function calcPercentace(value, percentage) {
|
|
2
|
-
if (typeof value !== "number" || typeof percentage !== "number") {
|
|
3
|
-
throw new Error("Değerler sayısal olmalıdır.");
|
|
4
|
-
}
|
|
5
|
-
return (value * percentage) / 100;
|
|
6
|
-
}
|
|
7
|
-
export function bankersRounding(value, decimals = 2) {
|
|
8
|
-
const factor = Math.pow(10, decimals);
|
|
9
|
-
const rounded = Math.round(value * factor);
|
|
10
|
-
const isHalf = (value * factor) % 1 === 0.5;
|
|
11
|
-
return isHalf && rounded % 2 !== 0
|
|
12
|
-
? (rounded - 1) / factor
|
|
13
|
-
: rounded / factor;
|
|
14
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const toExpress: (action: () => Promise<any>) => (req: any, res: any, next: any) => Promise<any>;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { controllerContextStorage } from "source/loader/controller";
|
|
2
|
-
import { ProtocolEnum } from "source/utils/models";
|
|
3
|
-
// => Use case - app.post('/example', toExpress(() => exampleCtrl.example()))
|
|
4
|
-
export const toExpress = (action) => async (req, res, next) => {
|
|
5
|
-
try {
|
|
6
|
-
const result = await controllerContextStorage.run({
|
|
7
|
-
req,
|
|
8
|
-
res,
|
|
9
|
-
protocol: ProtocolEnum.HTTP,
|
|
10
|
-
metadata: { locals: res.locals || {} }
|
|
11
|
-
}, action);
|
|
12
|
-
if (result instanceof Response) {
|
|
13
|
-
res.status(result.status);
|
|
14
|
-
result.headers.forEach((v, k) => res.setHeader(k, v));
|
|
15
|
-
const contentType = result.headers.get('content-type') || '';
|
|
16
|
-
if (contentType.includes('application/json') || contentType.includes('text/')) {
|
|
17
|
-
return res.send(await result.text());
|
|
18
|
-
}
|
|
19
|
-
return res.send(Buffer.from(await result.arrayBuffer()));
|
|
20
|
-
}
|
|
21
|
-
return res.send(result);
|
|
22
|
-
}
|
|
23
|
-
catch (e) {
|
|
24
|
-
next(e);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
export function pickProps(obj, props) {
|
|
2
|
-
if (!obj) {
|
|
3
|
-
return {};
|
|
4
|
-
}
|
|
5
|
-
const negativeProps = new Set();
|
|
6
|
-
const positiveProps = new Set();
|
|
7
|
-
for (const p of props) {
|
|
8
|
-
if (typeof p === 'string' && p.startsWith('-')) {
|
|
9
|
-
negativeProps.add(p.substring(1));
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
12
|
-
positiveProps.add(p);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function getNestedValue(o, path) {
|
|
16
|
-
return path.reduce((acc, key) => (acc && acc[key] !== undefined ? acc[key] : undefined), o);
|
|
17
|
-
}
|
|
18
|
-
function setNestedValue(o, path, value) {
|
|
19
|
-
let current = o;
|
|
20
|
-
for (let i = 0; i < path.length - 1; i++) {
|
|
21
|
-
if (!(path[i] in current))
|
|
22
|
-
current[path[i]] = {};
|
|
23
|
-
current = current[path[i]];
|
|
24
|
-
}
|
|
25
|
-
current[path[path.length - 1]] = value;
|
|
26
|
-
}
|
|
27
|
-
if (negativeProps.size > 0) {
|
|
28
|
-
const result = {};
|
|
29
|
-
function recurse(currentObj, currentPath = [], resObj) {
|
|
30
|
-
for (const key in currentObj) {
|
|
31
|
-
const fullPath = [...currentPath, key].join('.');
|
|
32
|
-
if (!Array.from(negativeProps).some(neg => fullPath === neg || fullPath.startsWith(neg + '.'))) {
|
|
33
|
-
if (typeof currentObj[key] === 'object' && currentObj[key] !== null && !Array.isArray(currentObj[key])) {
|
|
34
|
-
resObj[key] = {};
|
|
35
|
-
recurse(currentObj[key], [...currentPath, key], resObj[key]);
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
resObj[key] = currentObj[key];
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
recurse(obj, [], result);
|
|
44
|
-
return result;
|
|
45
|
-
}
|
|
46
|
-
const result = {};
|
|
47
|
-
for (const p of positiveProps) {
|
|
48
|
-
const path = p.split('.');
|
|
49
|
-
const value = getNestedValue(obj, path);
|
|
50
|
-
if (value !== undefined) {
|
|
51
|
-
setNestedValue(result, path, value);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return result;
|
|
55
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export const validateScopes = ({ scopes, permissions, resources }) => {
|
|
2
|
-
const parsedScopes = scopes.split(' ');
|
|
3
|
-
function dublicateControl(parsedScopes) {
|
|
4
|
-
const uniqueScopes = new Set(parsedScopes);
|
|
5
|
-
if (uniqueScopes.size !== parsedScopes.length) {
|
|
6
|
-
return true;
|
|
7
|
-
}
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
if (dublicateControl(parsedScopes)) {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
const isInvalid = parsedScopes.some((scope) => {
|
|
14
|
-
const [resource, permission] = scope.split(':');
|
|
15
|
-
const isValidResource = resources.includes(resource);
|
|
16
|
-
const isValidPermission = permissions.includes(permission);
|
|
17
|
-
return !isValidResource || !isValidPermission;
|
|
18
|
-
});
|
|
19
|
-
return !isInvalid;
|
|
20
|
-
};
|
package/source/utils/index.d.ts
DELETED
package/source/utils/index.js
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { createHash, createHmac } from 'node:crypto';
|
|
2
|
-
import { Configs, Logger } from '../../../loader';
|
|
3
|
-
import { LoggerLayerEnum, x } from '../../index';
|
|
4
|
-
export class ClientStore {
|
|
5
|
-
static _store = {};
|
|
6
|
-
static get(clientName) { return this._store[clientName] || {}; }
|
|
7
|
-
static set(clientName, data) {
|
|
8
|
-
this._store[clientName] = { ...this._store[clientName], ...data };
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
export class Client {
|
|
12
|
-
logger = x.get(Logger);
|
|
13
|
-
configs = x.get(Configs);
|
|
14
|
-
clientName;
|
|
15
|
-
baseURL;
|
|
16
|
-
version = null;
|
|
17
|
-
timeout = 15000;
|
|
18
|
-
debug;
|
|
19
|
-
authConfigs;
|
|
20
|
-
breaker = {
|
|
21
|
-
failures: 0,
|
|
22
|
-
lastFailure: 0,
|
|
23
|
-
state: 'CLOSED',
|
|
24
|
-
threshold: 5,
|
|
25
|
-
cooldown: 30000
|
|
26
|
-
};
|
|
27
|
-
constructor({ clientName, baseURL, version, timeout, auth, debug }) {
|
|
28
|
-
this.clientName = clientName;
|
|
29
|
-
this.baseURL = baseURL;
|
|
30
|
-
this.version = version || null;
|
|
31
|
-
this.authConfigs = auth;
|
|
32
|
-
this.timeout = timeout || 15000;
|
|
33
|
-
const configDebug = Number(this.configs.all.debug) >= LoggerLayerEnum.DEBUG;
|
|
34
|
-
this.debug = debug ?? configDebug;
|
|
35
|
-
if (auth?.token)
|
|
36
|
-
ClientStore.set(clientName, { accessToken: auth.token });
|
|
37
|
-
}
|
|
38
|
-
resolvePath(obj, path) {
|
|
39
|
-
return path.split('.').reduce((prev, curr) => prev ? prev[curr] : undefined, obj);
|
|
40
|
-
}
|
|
41
|
-
static cryptoHashGenerate = ({ algorithm, input, digest = 'hex' }) => {
|
|
42
|
-
return createHash(algorithm).update(input).digest(digest);
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
export class BaseApiClient extends Client {
|
|
46
|
-
constructor(config) { super(config); }
|
|
47
|
-
async request(path, options = {}) {
|
|
48
|
-
if (this.breaker.state === 'OPEN') {
|
|
49
|
-
if (Date.now() - this.breaker.lastFailure > this.breaker.cooldown) {
|
|
50
|
-
this.breaker.state = 'HALF_OPEN';
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
throw new Error(`[CircuitBreaker] ${this.clientName} is OPEN`);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
const maxRetries = options.retries ?? 3;
|
|
57
|
-
let attempt = 0;
|
|
58
|
-
while (attempt < maxRetries) {
|
|
59
|
-
try {
|
|
60
|
-
const response = await this._execute(path, { ...options });
|
|
61
|
-
if (response.ok || response.status === 401) {
|
|
62
|
-
this.breaker.failures = 0;
|
|
63
|
-
this.breaker.state = 'CLOSED';
|
|
64
|
-
return response;
|
|
65
|
-
}
|
|
66
|
-
if ([502, 503, 504].includes(response.status)) {
|
|
67
|
-
throw new Error(`Server Error: ${response.status}`);
|
|
68
|
-
}
|
|
69
|
-
return response;
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
72
|
-
attempt++;
|
|
73
|
-
this.breaker.failures++;
|
|
74
|
-
this.breaker.lastFailure = Date.now();
|
|
75
|
-
if (this.breaker.failures >= this.breaker.threshold)
|
|
76
|
-
this.breaker.state = 'OPEN';
|
|
77
|
-
if (attempt >= maxRetries)
|
|
78
|
-
throw error;
|
|
79
|
-
const backoff = Math.pow(2, attempt) * 500;
|
|
80
|
-
await new Promise(res => setTimeout(res, backoff));
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
throw new Error(`${this.clientName} failed after ${maxRetries} attempts`);
|
|
84
|
-
}
|
|
85
|
-
async _execute(path, options) {
|
|
86
|
-
const base = this.baseURL.replace(/\/$/, '');
|
|
87
|
-
const activeVersion = options.version !== undefined ? options.version : this.version;
|
|
88
|
-
const ver = activeVersion ? `/${activeVersion.replace(/^\//, '')}` : '';
|
|
89
|
-
const url = `${base}${ver}${path}`;
|
|
90
|
-
const store = Logger.storage.getStore();
|
|
91
|
-
const correlationId = store?.get('correlationId');
|
|
92
|
-
const headers = new Headers(options.headers || {});
|
|
93
|
-
const isUrlEncoded = options.body instanceof URLSearchParams;
|
|
94
|
-
const isFormData = options.body instanceof FormData;
|
|
95
|
-
if (!isUrlEncoded && !isFormData) {
|
|
96
|
-
headers.set('Content-Type', 'application/json');
|
|
97
|
-
}
|
|
98
|
-
if (correlationId)
|
|
99
|
-
headers.set('x-correlation-id', correlationId);
|
|
100
|
-
const systemSecret = this.configs.all.internalSecret || process.env.INTERNAL_SECRET;
|
|
101
|
-
if (systemSecret) {
|
|
102
|
-
const timestamp = Date.now().toString();
|
|
103
|
-
const signature = createHmac('sha256', systemSecret)
|
|
104
|
-
.update(timestamp + this.clientName)
|
|
105
|
-
.digest('hex');
|
|
106
|
-
headers.set('x-internal-signature', signature);
|
|
107
|
-
headers.set('x-internal-timestamp', timestamp);
|
|
108
|
-
headers.set('x-internal-client', this.clientName);
|
|
109
|
-
}
|
|
110
|
-
const isDebugMode = options.debug ?? this.debug;
|
|
111
|
-
const { version, retries, debug, ...fetchOptions } = options;
|
|
112
|
-
let processedBody = fetchOptions.body;
|
|
113
|
-
if (processedBody && typeof processedBody === 'object' && !isUrlEncoded && !isFormData) {
|
|
114
|
-
processedBody = JSON.stringify(processedBody);
|
|
115
|
-
}
|
|
116
|
-
if (isDebugMode) {
|
|
117
|
-
const logData = {
|
|
118
|
-
method: fetchOptions.method || 'GET',
|
|
119
|
-
url,
|
|
120
|
-
body: processedBody && typeof processedBody === 'string' ? JSON.parse(processedBody) : processedBody
|
|
121
|
-
};
|
|
122
|
-
console.log(`[DEBUG] ${this.clientName}`, logData);
|
|
123
|
-
this.logger.winston.info(`${this.clientName} Request`, logData);
|
|
124
|
-
}
|
|
125
|
-
const controller = new AbortController();
|
|
126
|
-
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
127
|
-
try {
|
|
128
|
-
const response = await fetch(url, {
|
|
129
|
-
...fetchOptions,
|
|
130
|
-
body: processedBody,
|
|
131
|
-
headers,
|
|
132
|
-
signal: controller.signal
|
|
133
|
-
});
|
|
134
|
-
clearTimeout(timeoutId);
|
|
135
|
-
return response;
|
|
136
|
-
}
|
|
137
|
-
catch (error) {
|
|
138
|
-
clearTimeout(timeoutId);
|
|
139
|
-
throw error;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { NodeEnvEnum } from "../enums";
|
|
2
|
-
export interface ILogDTO {
|
|
3
|
-
level: string;
|
|
4
|
-
service: string;
|
|
5
|
-
message: string;
|
|
6
|
-
payload?: Record<string, any>;
|
|
7
|
-
code: string | number;
|
|
8
|
-
timestamp: string;
|
|
9
|
-
id?: string | number;
|
|
10
|
-
env: NodeEnvEnum;
|
|
11
|
-
}
|
|
12
|
-
export declare class LogDTO {
|
|
13
|
-
static getSchema({ level, service, message, payload, code, timestamp, id, env }: ILogDTO): {
|
|
14
|
-
level: string;
|
|
15
|
-
service: string;
|
|
16
|
-
message: string;
|
|
17
|
-
payload: Record<string, any>;
|
|
18
|
-
code: string | number;
|
|
19
|
-
timestamp: string;
|
|
20
|
-
id: string | number;
|
|
21
|
-
env: NodeEnvEnum;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
export interface IMetadata<E = any> {
|
|
25
|
-
source: string;
|
|
26
|
-
eventType: string;
|
|
27
|
-
timestamp: number;
|
|
28
|
-
correlationId: string;
|
|
29
|
-
userId?: string;
|
|
30
|
-
extraData?: E;
|
|
31
|
-
}
|
|
32
|
-
export interface IMessageInput<P = any, E = any> {
|
|
33
|
-
metadata: {
|
|
34
|
-
source: string;
|
|
35
|
-
eventType: string;
|
|
36
|
-
userId?: string;
|
|
37
|
-
correlationId?: string;
|
|
38
|
-
extraData?: E;
|
|
39
|
-
};
|
|
40
|
-
payload: P;
|
|
41
|
-
}
|
|
42
|
-
export declare class QueueDTO {
|
|
43
|
-
static getSchema<P, E>(input: IMessageInput<P, E>): {
|
|
44
|
-
metadata: IMetadata<E>;
|
|
45
|
-
payload: P;
|
|
46
|
-
};
|
|
47
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export class LogDTO {
|
|
2
|
-
static getSchema({ level, service, message, payload, code, timestamp, id, env }) {
|
|
3
|
-
if (!level || !service || !message || !timestamp || !env) {
|
|
4
|
-
throw new Error("Missing data other data required!");
|
|
5
|
-
}
|
|
6
|
-
return {
|
|
7
|
-
level,
|
|
8
|
-
service,
|
|
9
|
-
message,
|
|
10
|
-
payload,
|
|
11
|
-
code,
|
|
12
|
-
timestamp,
|
|
13
|
-
id,
|
|
14
|
-
env
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
export class QueueDTO {
|
|
19
|
-
static getSchema(input) {
|
|
20
|
-
if (!input.metadata.source || !input.metadata.eventType) {
|
|
21
|
-
throw new Error("Source and eventType are required inside metadata");
|
|
22
|
-
}
|
|
23
|
-
const finalMetadata = {
|
|
24
|
-
source: input.metadata.source,
|
|
25
|
-
eventType: input.metadata.eventType,
|
|
26
|
-
timestamp: Date.now(),
|
|
27
|
-
correlationId: input.metadata.correlationId || Math.random().toString(36).substring(7),
|
|
28
|
-
userId: input.metadata.userId,
|
|
29
|
-
extraData: input.metadata.extraData
|
|
30
|
-
};
|
|
31
|
-
return {
|
|
32
|
-
metadata: finalMetadata,
|
|
33
|
-
payload: input.payload
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export interface PayloadSchemaInterface {
|
|
2
|
-
status: boolean;
|
|
3
|
-
message: string;
|
|
4
|
-
payload?: any;
|
|
5
|
-
code?: number;
|
|
6
|
-
[key: string]: any;
|
|
7
|
-
}
|
|
8
|
-
export declare class ResponseSchema {
|
|
9
|
-
status: boolean;
|
|
10
|
-
message: string;
|
|
11
|
-
payload: any;
|
|
12
|
-
code: number;
|
|
13
|
-
constructor({ status, message, payload, code }: PayloadSchemaInterface);
|
|
14
|
-
validData(): any;
|
|
15
|
-
statusCodeGenerator(): number;
|
|
16
|
-
get getResponse(): any;
|
|
17
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export class ResponseSchema {
|
|
2
|
-
status;
|
|
3
|
-
message;
|
|
4
|
-
payload;
|
|
5
|
-
code;
|
|
6
|
-
constructor({ status = false, message = '', payload = null, code = 0 }) {
|
|
7
|
-
this.status = status;
|
|
8
|
-
this.message = message;
|
|
9
|
-
this.payload = payload;
|
|
10
|
-
this.code = code;
|
|
11
|
-
}
|
|
12
|
-
validData() {
|
|
13
|
-
return this.payload;
|
|
14
|
-
}
|
|
15
|
-
statusCodeGenerator() {
|
|
16
|
-
if (this.status === false) {
|
|
17
|
-
if (this.code !== 0 && this.code !== 1) {
|
|
18
|
-
return Number(this.code);
|
|
19
|
-
}
|
|
20
|
-
return 1;
|
|
21
|
-
}
|
|
22
|
-
return 0;
|
|
23
|
-
}
|
|
24
|
-
get getResponse() {
|
|
25
|
-
const response = {
|
|
26
|
-
status: this.status,
|
|
27
|
-
message: this.message
|
|
28
|
-
};
|
|
29
|
-
if (this.payload !== null && this.payload !== undefined) {
|
|
30
|
-
response.payload = this.validData();
|
|
31
|
-
}
|
|
32
|
-
response.code = this.statusCodeGenerator();
|
|
33
|
-
return response;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// => // X Service Locator
|
|
2
|
-
export class Locator {
|
|
3
|
-
_context = new Map();
|
|
4
|
-
constructor({}) {
|
|
5
|
-
}
|
|
6
|
-
set = ({ service, reference, args }) => {
|
|
7
|
-
this._context.set(service, new reference(...(args || [])));
|
|
8
|
-
};
|
|
9
|
-
get = (service) => {
|
|
10
|
-
if (!this._context.has(service)) {
|
|
11
|
-
throw new Error(`${service} not found in context.`);
|
|
12
|
-
}
|
|
13
|
-
return this._context.get(service);
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
export default new Locator({});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from "node:events";
|
|
2
|
-
import { resolve } from "node:path";
|
|
3
|
-
import { readFileSync, watchFile } from "node:fs";
|
|
4
|
-
import { parse } from "yaml";
|
|
5
|
-
import { resolveObjWithHandlebars } from "../../helpers";
|
|
6
|
-
export class TmpFileLoader extends EventEmitter {
|
|
7
|
-
#tmpFileJson = {};
|
|
8
|
-
#filePath;
|
|
9
|
-
constructor({ filePath }) {
|
|
10
|
-
super();
|
|
11
|
-
this.#filePath = resolve(filePath);
|
|
12
|
-
this.#loadSync();
|
|
13
|
-
this.#initWatcher();
|
|
14
|
-
}
|
|
15
|
-
#loadSync() {
|
|
16
|
-
try {
|
|
17
|
-
const content = readFileSync(this.#filePath, "utf8");
|
|
18
|
-
this.#tmpFileJson = parse(content);
|
|
19
|
-
this.emit("reload", this.#tmpFileJson);
|
|
20
|
-
}
|
|
21
|
-
catch (err) {
|
|
22
|
-
console.error(`[TmpFileLoader] Error: ${err}`);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
#initWatcher() {
|
|
26
|
-
watchFile(this.#filePath, { interval: 500 }, (curr, prev) => {
|
|
27
|
-
if (curr.mtimeMs !== prev.mtimeMs) {
|
|
28
|
-
this.#loadSync();
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
getResolvedTmpFile() {
|
|
33
|
-
const data = Object.keys(this.#tmpFileJson).length > 0
|
|
34
|
-
? this.#tmpFileJson
|
|
35
|
-
: (this.#loadSync(), this.#tmpFileJson);
|
|
36
|
-
return resolveObjWithHandlebars(data, data);
|
|
37
|
-
}
|
|
38
|
-
}
|