@lakutata/core 1.0.30 → 1.0.35
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/build/Application.d.ts +1 -0
- package/build/Application.js +5 -7
- package/build/Application.js.map +1 -1
- package/build/ApplicationManagement.js.map +1 -1
- package/build/base/BaseObject.js +1 -1
- package/build/base/BaseObject.js.map +1 -1
- package/build/base/Container.js +2 -2
- package/build/base/Container.js.map +1 -1
- package/build/base/ValidatorClass.d.ts +1 -0
- package/build/base/ValidatorClass.js +70 -53
- package/build/base/ValidatorClass.js.map +1 -1
- package/build/base/abstracts/Module.js +8 -8
- package/build/base/abstracts/Module.js.map +1 -1
- package/build/base/abstracts/Workflow.js +1 -1
- package/build/base/abstracts/Workflow.js.map +1 -1
- package/build/base/process/ProcessManager.js +2 -3
- package/build/base/process/ProcessManager.js.map +1 -1
- package/build/base/thread/ThreadManager.js +2 -3
- package/build/base/thread/ThreadManager.js.map +1 -1
- package/build/decorators/MethodValidation.js.map +1 -1
- package/build/interfaces/ShellJsInterfaces.d.ts +162 -0
- package/build/interfaces/ShellJsInterfaces.js +3 -0
- package/build/interfaces/ShellJsInterfaces.js.map +1 -0
- package/build/lib/minified/ShellJs.d.ts +2 -0
- package/build/lib/minified/ShellJs.js +3699 -0
- package/build/lib/minified/ShellJs.js.map +1 -0
- package/build/lib/multipleRunner/lib/Process.js +3 -3
- package/build/lib/multipleRunner/lib/Process.js.map +1 -1
- package/build/lib/multipleRunner/lib/Thread.js +4 -4
- package/build/lib/multipleRunner/lib/Thread.js.map +1 -1
- package/build/lib/multipleRunner/lib/cores/IsElectron.js +1 -2
- package/build/lib/multipleRunner/lib/cores/IsElectron.js.map +1 -1
- package/build/plugins/Crypto.js +2 -2
- package/build/plugins/Crypto.js.map +1 -1
- package/build/plugins/Formatter.js +1 -1
- package/build/plugins/Formatter.js.map +1 -1
- package/build/plugins/HttpRequest.js +8 -8
- package/build/plugins/HttpRequest.js.map +1 -1
- package/build/plugins/Logger.js +12 -7
- package/build/plugins/Logger.js.map +1 -1
- package/build/plugins/MessagePack.d.ts +1 -0
- package/build/plugins/MessagePack.js +2 -2
- package/build/plugins/MessagePack.js.map +1 -1
- package/build/plugins/Security.js +24 -24
- package/build/plugins/Security.js.map +1 -1
- package/build/plugins/Shell.d.ts +39 -0
- package/build/plugins/Shell.js +58 -0
- package/build/plugins/Shell.js.map +1 -0
- package/build/utils/Delay.js +1 -1
- package/build/utils/Delay.js.map +1 -1
- package/build/utils/Timeout.js +1 -1
- package/build/utils/Timeout.js.map +1 -1
- package/build/utils/ValidDataUrl.d.ts +1 -0
- package/build/utils/ValidDataUrl.js +8 -0
- package/build/utils/ValidDataUrl.js.map +1 -0
- package/package.json +16 -20
- package/src/Application.ts +5 -11
- package/src/ApplicationManagement.ts +1 -1
- package/src/base/ValidatorClass.ts +44 -7
- package/src/base/abstracts/Exception.ts +1 -1
- package/src/decorators/MethodValidation.ts +6 -6
- package/src/interfaces/ShellJsInterfaces.ts +858 -0
- package/src/lib/minified/ShellJs.js +1 -0
- package/src/plugins/Crypto.ts +3 -3
- package/src/plugins/Logger.ts +8 -3
- package/src/plugins/Shell.ts +371 -0
- package/src/tests/Main.spec.ts +2 -1
- package/src/utils/ValidDataUrl.ts +8 -0
- package/tsconfig.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Timeout.js","sourceRoot":"","sources":["../../src/utils/Timeout.ts"],"names":[],"mappings":";;;;;;AAAA,0DAAgC;AAEhC,qEAA+D;AASxD,KAAK,UAAU,OAAO,CAAI,CAAa,EAAE,YAAoB,EAAE,iBAA+D;IACpI,OAAO,mBAAQ,
|
|
1
|
+
{"version":3,"file":"Timeout.js","sourceRoot":"","sources":["../../src/utils/Timeout.ts"],"names":[],"mappings":";;;;;;AAAA,0DAAgC;AAEhC,qEAA+D;AASxD,KAAK,UAAU,OAAO,CAAI,CAAa,EAAE,YAAoB,EAAE,iBAA+D;IACpI,OAAO,IAAA,mBAAQ,EAAC,CAAC,EAAE,YAAY,EAAE,KAAK,IAAI,EAAE;QAC3C,IAAI,iBAAiB,EAAE;YACtB,QAAQ,OAAO,iBAAiB,EAAE;gBACjC,KAAK,UAAU;oBACd,OAAO,CAAC,MAAM,iBAAiB,EAAE,CAAQ,CAAA;gBAC1C,KAAK,QAAQ;oBACZ,MAAM,IAAI,mCAAgB,CAAC,iBAAiB,CAAC,CAAA;gBAC9C,KAAK,QAAQ;oBACZ,MAAM,iBAAiB,CAAA;aACxB;SACD;aAAM;YACN,MAAM,IAAI,mCAAgB,CAAC,2BAA2B,YAAY,eAAe,CAAC,CAAA;SAClF;IACF,CAAC,CAAC,CAAA;AACH,CAAC;AAfD,0BAeC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function validDataUrl(candidate: string): boolean;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validDataUrl = void 0;
|
|
4
|
+
function validDataUrl(candidate) {
|
|
5
|
+
return /^data:([a-z]+\/[a-z0-9-+.]+(;[a-z0-9-.!#$%*+.{}|~`]+=[a-z0-9-.!#$%*+.{}()|~`]+)*)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@\/?%\s<>]*?)$/i.test(candidate);
|
|
6
|
+
}
|
|
7
|
+
exports.validDataUrl = validDataUrl;
|
|
8
|
+
//# sourceMappingURL=ValidDataUrl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValidDataUrl.js","sourceRoot":"","sources":["../../src/utils/ValidDataUrl.ts"],"names":[],"mappings":";;;AAKA,SAAgB,YAAY,CAAC,SAAiB;IAC7C,OAAO,uIAAuI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;AAC/J,CAAC;AAFD,oCAEC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lakutata/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.35",
|
|
4
4
|
"description": "Lakutata Framework Core",
|
|
5
5
|
"main": "./build/Core.js",
|
|
6
6
|
"types": "./build/Core.d.ts",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"rebuild": "npm run clean && npm run build",
|
|
12
12
|
"prepare": "npm run compile",
|
|
13
13
|
"compile": "npm run rebuild && shx rm -rf ./build/tests/*",
|
|
14
|
-
"test": "
|
|
14
|
+
"test": "node -r ./node_modules/ts-node/register src/tests/*.spec.ts"
|
|
15
15
|
},
|
|
16
16
|
"publishConfig": {
|
|
17
17
|
"access": "public",
|
|
@@ -53,10 +53,10 @@
|
|
|
53
53
|
"author": "alex.ma",
|
|
54
54
|
"license": "MIT",
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@thiagodelgado111/yup-phone": "^0.0.2",
|
|
57
56
|
"bcryptjs": "^2.4.3",
|
|
58
57
|
"crypto-js": "^4.1.1",
|
|
59
|
-
"
|
|
58
|
+
"google-libphonenumber": "^3.2.25",
|
|
59
|
+
"inversify": "^6.0.1",
|
|
60
60
|
"is-ssh": "^1.3.3",
|
|
61
61
|
"json-helpers": "^5.1.4",
|
|
62
62
|
"json5": "^2.2.0",
|
|
@@ -66,43 +66,39 @@
|
|
|
66
66
|
"moment": "^2.29.1",
|
|
67
67
|
"moment-timezone": "^0.5.34",
|
|
68
68
|
"msgpack5": "^5.3.2",
|
|
69
|
-
"needle": "^
|
|
69
|
+
"needle": "^3.0.0",
|
|
70
70
|
"node-rsa": "^1.1.1",
|
|
71
71
|
"p-timeout": "^4.1.0",
|
|
72
72
|
"pupa": "^2.1.1",
|
|
73
73
|
"random": "^3.0.6",
|
|
74
74
|
"reflect-metadata": "^0.1.13",
|
|
75
75
|
"string-random": "^0.1.3",
|
|
76
|
-
"valid-data-url": "^3.0.1",
|
|
77
76
|
"winston": "^3.3.3",
|
|
78
|
-
"winston-transport": "^4.4.
|
|
77
|
+
"winston-transport": "^4.4.1",
|
|
79
78
|
"yup": "^0.32.11"
|
|
80
79
|
},
|
|
81
80
|
"devDependencies": {
|
|
82
81
|
"@types/bcryptjs": "^2.4.2",
|
|
83
|
-
"@types/chai": "^4.2.14",
|
|
84
82
|
"@types/crypto-js": "^4.0.2",
|
|
83
|
+
"@types/google-libphonenumber": "^7.4.23",
|
|
85
84
|
"@types/is-ssh": "^1.3.0",
|
|
86
85
|
"@types/lodash.mapvalues": "^4.6.6",
|
|
87
86
|
"@types/merge-deep": "^3.0.0",
|
|
88
|
-
"@types/
|
|
89
|
-
"@types/msgpack5": "^3.4.1",
|
|
87
|
+
"@types/msgpack5": "^3.4.2",
|
|
90
88
|
"@types/needle": "^2.5.2",
|
|
91
|
-
"@types/node": "^
|
|
89
|
+
"@types/node": "^16.11.7",
|
|
92
90
|
"@types/node-rsa": "^1.1.0",
|
|
93
91
|
"@types/valid-data-url": "^2.0.0",
|
|
94
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
95
|
-
"@typescript-eslint/parser": "^
|
|
96
|
-
"
|
|
97
|
-
"eslint": "^7.28.0",
|
|
92
|
+
"@typescript-eslint/eslint-plugin": "^5.7.0",
|
|
93
|
+
"@typescript-eslint/parser": "^5.7.0",
|
|
94
|
+
"eslint": "^7.32.0",
|
|
98
95
|
"eslint-config-standard": "^16.0.3",
|
|
99
|
-
"eslint-plugin-import": "^2.
|
|
96
|
+
"eslint-plugin-import": "^2.25.3",
|
|
100
97
|
"eslint-plugin-node": "^11.1.0",
|
|
101
|
-
"eslint-plugin-promise": "^5.
|
|
102
|
-
"mocha": "^8.4.0",
|
|
98
|
+
"eslint-plugin-promise": "^5.2.0",
|
|
103
99
|
"shx": "^0.3.3",
|
|
104
|
-
"ts-node": "^
|
|
105
|
-
"typescript": "^4.
|
|
100
|
+
"ts-node": "^10.4.0",
|
|
101
|
+
"typescript": "^4.5.4"
|
|
106
102
|
},
|
|
107
103
|
"engines": {
|
|
108
104
|
"node": ">=12.22.1"
|
package/src/Application.ts
CHANGED
|
@@ -10,10 +10,10 @@ import {MessagePack} from './plugins/MessagePack'
|
|
|
10
10
|
import {JSON} from './plugins/JSON'
|
|
11
11
|
import {TWorkflowsConfig} from './types/TWorkflowsConfig'
|
|
12
12
|
import {Logger} from './plugins/Logger'
|
|
13
|
-
import {format} from 'winston'
|
|
14
13
|
import {TProcessesConfig} from './types/TProcessesConfig'
|
|
15
14
|
import {TThreadsConfig} from './types/TThreadsConfig'
|
|
16
15
|
import momentTimezone from 'moment-timezone'
|
|
16
|
+
import {Shell} from './plugins/Shell'
|
|
17
17
|
|
|
18
18
|
export class Application extends Module {
|
|
19
19
|
/**
|
|
@@ -65,6 +65,9 @@ export class Application extends Module {
|
|
|
65
65
|
{
|
|
66
66
|
class: JSON
|
|
67
67
|
},
|
|
68
|
+
{
|
|
69
|
+
class: Shell
|
|
70
|
+
},
|
|
68
71
|
{
|
|
69
72
|
class: Formatter,
|
|
70
73
|
dateFormat: 'YYYY-MM-DD HH:mm:ss'
|
|
@@ -77,16 +80,6 @@ export class Application extends Module {
|
|
|
77
80
|
appId: process.env.appId,
|
|
78
81
|
appName: process.env.appName
|
|
79
82
|
},
|
|
80
|
-
console: {
|
|
81
|
-
silent: false,
|
|
82
|
-
format: format.combine(
|
|
83
|
-
format.timestamp({format: 'YYYY-MM-DD HH:mm:ss'}),
|
|
84
|
-
format.colorize(),
|
|
85
|
-
format.printf(packet => {
|
|
86
|
-
return `${packet.timestamp} ${packet.level}: ${packet.message}`
|
|
87
|
-
})
|
|
88
|
-
)
|
|
89
|
-
},
|
|
90
83
|
transports: []
|
|
91
84
|
}
|
|
92
85
|
]
|
|
@@ -163,6 +156,7 @@ export class Application extends Module {
|
|
|
163
156
|
* @param {string} tz
|
|
164
157
|
*/
|
|
165
158
|
public setTimezone(tz: string) {
|
|
159
|
+
process.env.TZ = tz
|
|
166
160
|
this.tz = tz
|
|
167
161
|
}
|
|
168
162
|
|
|
@@ -25,7 +25,7 @@ export async function createApp(config: IApplicationConfig): Promise<Application
|
|
|
25
25
|
await coreContainer.initialize()
|
|
26
26
|
return coreContainer.getModule(Application)
|
|
27
27
|
} catch (e) {
|
|
28
|
-
throw new FatalException(e.message)
|
|
28
|
+
throw new FatalException((e as Error).message)
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -25,11 +25,11 @@ import {OptionalArraySchema} from 'yup/lib/array'
|
|
|
25
25
|
import Reference, {ReferenceOptions} from 'yup/lib/Reference'
|
|
26
26
|
import mapValues from 'lodash/mapValues'
|
|
27
27
|
import {ValidationException} from '../exceptions/ValidationException'
|
|
28
|
-
import phoneValidationMethod, {YUP_METHOD as PHONE_METHOD} from '@thiagodelgado111/yup-phone'
|
|
29
28
|
import isSsh from 'is-ssh'
|
|
30
|
-
import validDataUrl from 'valid-data-url'
|
|
31
29
|
import {MixedSchema} from 'yup/lib/mixed'
|
|
32
30
|
import {BaseObject} from './BaseObject'
|
|
31
|
+
import gPhoneNumber from 'google-libphonenumber'
|
|
32
|
+
import {validDataUrl} from '../utils/ValidDataUrl'
|
|
33
33
|
|
|
34
34
|
declare module 'yup' {
|
|
35
35
|
interface StringSchema {
|
|
@@ -44,13 +44,15 @@ declare module 'yup' {
|
|
|
44
44
|
dataUrl(): StringSchema
|
|
45
45
|
|
|
46
46
|
url(option?: { acceptParams?: boolean; protocol?: string[] | string; blackHostnameList?: string[]; whiteHostnameList?: string[] }): StringSchema
|
|
47
|
+
|
|
48
|
+
phone(countryCode?: string, strict?: boolean): StringSchema
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
interface ObjectSchema<TShape extends ObjectShape, TContext extends AnyObject = AnyObject, TIn extends Maybe<TypeOfShape<TShape>> = TypeOfShape<TShape>, TOut extends Maybe<AssertsShape<TShape>> = AssertsShape<TShape> | Optionals<TIn>> extends BaseSchema<TIn, TContext, TOut> {
|
|
50
52
|
structure(valueSchema: AnySchema): OptionalObjectSchema<TShape, Record<string, any>, TypeOfShape<TShape>>
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
|
-
|
|
55
|
+
const PHONE_METHOD = 'phone'
|
|
54
56
|
const IPV4_METHOD = 'ipv4'
|
|
55
57
|
const IPV6_METHOD = 'ipv6'
|
|
56
58
|
const IP_ALL_METHOD = 'ip'
|
|
@@ -515,7 +517,42 @@ export class ValidatorClass extends BaseObject {
|
|
|
515
517
|
|
|
516
518
|
constructor() {
|
|
517
519
|
super()
|
|
518
|
-
addMethod(string, PHONE_METHOD,
|
|
520
|
+
addMethod(string, PHONE_METHOD, function (this: StringSchema, countryCode?: string, strict: boolean = false) {
|
|
521
|
+
const phoneUtil = gPhoneNumber.PhoneNumberUtil.getInstance()
|
|
522
|
+
const CLDR_REGION_CODE_SIZE = 2
|
|
523
|
+
const isValidCountryCode = (countryCode: any): boolean => typeof countryCode === 'string' && countryCode.length === CLDR_REGION_CODE_SIZE
|
|
524
|
+
const errMsg = isValidCountryCode(countryCode)
|
|
525
|
+
? `\${path} must be a valid phone number for region ${countryCode}`
|
|
526
|
+
: '${path} must be a valid phone number.'
|
|
527
|
+
|
|
528
|
+
return this.test(<any>{
|
|
529
|
+
name: PHONE_METHOD,
|
|
530
|
+
message: errMsg,
|
|
531
|
+
test(value: string) {
|
|
532
|
+
if (this.schema._nullable && value === null) {
|
|
533
|
+
return this.resolve(true)
|
|
534
|
+
}
|
|
535
|
+
if (!isValidCountryCode(countryCode)) {
|
|
536
|
+
countryCode = 'US'
|
|
537
|
+
strict = false
|
|
538
|
+
}
|
|
539
|
+
let isValid
|
|
540
|
+
try {
|
|
541
|
+
const phoneNumber = phoneUtil.parseAndKeepRawInput(value, countryCode)
|
|
542
|
+
if (!phoneUtil.isPossibleNumber(phoneNumber)) {
|
|
543
|
+
return false
|
|
544
|
+
}
|
|
545
|
+
const regionCodeFromPhoneNumber = phoneUtil.getRegionCodeForNumber(phoneNumber)
|
|
546
|
+
isValid = strict
|
|
547
|
+
? phoneUtil.isValidNumberForRegion(phoneNumber, countryCode)
|
|
548
|
+
: phoneUtil.isValidNumberForRegion(phoneNumber, regionCodeFromPhoneNumber)
|
|
549
|
+
} catch (error) {
|
|
550
|
+
isValid = false
|
|
551
|
+
}
|
|
552
|
+
return this.resolve(isValid)
|
|
553
|
+
}
|
|
554
|
+
})
|
|
555
|
+
})
|
|
519
556
|
addMethod(string, IPV4_METHOD, function (this: StringSchema, message = 'Invalid IP address') {
|
|
520
557
|
return this.matches(/(^(\d{1,3}\.){3}(\d{1,3})$)/, {
|
|
521
558
|
message,
|
|
@@ -668,7 +705,7 @@ export class ValidatorClass extends BaseObject {
|
|
|
668
705
|
try {
|
|
669
706
|
return await schema.validate(data, {strict: true})
|
|
670
707
|
} catch (e) {
|
|
671
|
-
throw this.generateException(ValidationException,e.message)
|
|
708
|
+
throw this.generateException(ValidationException, (e as Error).message)
|
|
672
709
|
}
|
|
673
710
|
}
|
|
674
711
|
|
|
@@ -682,7 +719,7 @@ export class ValidatorClass extends BaseObject {
|
|
|
682
719
|
try {
|
|
683
720
|
return schema.validateSync(data, {strict: true})
|
|
684
721
|
} catch (e) {
|
|
685
|
-
throw this.generateException(ValidationException,e.message)
|
|
722
|
+
throw this.generateException(ValidationException, (e as Error).message)
|
|
686
723
|
}
|
|
687
724
|
}
|
|
688
725
|
|
|
@@ -705,4 +742,4 @@ export class ValidatorClass extends BaseObject {
|
|
|
705
742
|
public isValidSync<SchemaType extends AnySchema, DataType = any>(schema: SchemaType, data: DataType): boolean {
|
|
706
743
|
return schema.isValidSync(data, {strict: true})
|
|
707
744
|
}
|
|
708
|
-
}
|
|
745
|
+
}
|
|
@@ -26,7 +26,7 @@ export const Return = (returnSchema: AnySchema, options: { strict?: boolean, str
|
|
|
26
26
|
const methodResult = returnSchema.validateSync(originalAsyncMethodResult, options)
|
|
27
27
|
resolve(methodResult)
|
|
28
28
|
} catch (e) {
|
|
29
|
-
reject(new InvalidMethodReturnException(e.message))
|
|
29
|
+
reject(new InvalidMethodReturnException((e as Error).message))
|
|
30
30
|
}
|
|
31
31
|
}).catch(reject)
|
|
32
32
|
})
|
|
@@ -35,9 +35,9 @@ export const Return = (returnSchema: AnySchema, options: { strict?: boolean, str
|
|
|
35
35
|
return returnSchema.validateSync(originalMethodResult, options)
|
|
36
36
|
} catch (e) {
|
|
37
37
|
if (target['generateException']) {
|
|
38
|
-
throw target['generateException'](InvalidMethodReturnException, e.message)
|
|
38
|
+
throw target['generateException'](InvalidMethodReturnException, (e as Error).message)
|
|
39
39
|
} else {
|
|
40
|
-
throw new InvalidMethodReturnException(e.message)
|
|
40
|
+
throw new InvalidMethodReturnException((e as Error).message)
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -68,13 +68,13 @@ export const Accept = (argumentSchemas: AnySchema | AnySchema[], options: { stri
|
|
|
68
68
|
}
|
|
69
69
|
} catch (e) {
|
|
70
70
|
if (target['generateException']) {
|
|
71
|
-
throw target['generateException'](InvalidMethodAcceptException, e.message)
|
|
71
|
+
throw target['generateException'](InvalidMethodAcceptException, (e as Error).message)
|
|
72
72
|
} else {
|
|
73
|
-
throw new InvalidMethodAcceptException(e.message)
|
|
73
|
+
throw new InvalidMethodAcceptException((e as Error).message)
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
return originalMethod.apply(this, args)
|
|
77
77
|
}
|
|
78
78
|
return descriptor
|
|
79
79
|
}
|
|
80
|
-
}
|
|
80
|
+
}
|