tunli 0.0.27 → 0.2.0
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/CHANGELOG.md +45 -0
- package/README.md +158 -67
- package/bin/tunli +4 -5
- package/dist/api-client/ApiClient.d.ts +18 -0
- package/dist/api-client/ApiClient.d.ts.map +1 -0
- package/dist/api-client/ApiClient.js +100 -0
- package/dist/api-client/ApiClient.js.map +1 -0
- package/dist/api-client/types.d.ts +26 -0
- package/dist/api-client/types.d.ts.map +1 -0
- package/dist/api-client/types.js +2 -0
- package/dist/api-client/types.js.map +1 -0
- package/dist/api-client/utils.d.ts +4 -0
- package/dist/api-client/utils.d.ts.map +1 -0
- package/dist/api-client/utils.js +13 -0
- package/dist/api-client/utils.js.map +1 -0
- package/dist/cli-app/AppEventEmitter.d.ts +57 -0
- package/dist/cli-app/AppEventEmitter.d.ts.map +1 -0
- package/dist/cli-app/AppEventEmitter.js +11 -0
- package/dist/cli-app/AppEventEmitter.js.map +1 -0
- package/dist/cli-app/Dashboard.d.ts +4 -0
- package/dist/cli-app/Dashboard.d.ts.map +1 -0
- package/dist/cli-app/Dashboard.js +241 -0
- package/dist/cli-app/Dashboard.js.map +1 -0
- package/dist/cli-app/LiveLog.d.ts +4 -0
- package/dist/cli-app/LiveLog.d.ts.map +1 -0
- package/dist/cli-app/LiveLog.js +28 -0
- package/dist/cli-app/LiveLog.js.map +1 -0
- package/dist/cli-app/types.d.ts +10 -0
- package/dist/cli-app/types.d.ts.map +1 -0
- package/dist/cli-app/types.js +2 -0
- package/dist/cli-app/types.js.map +1 -0
- package/dist/cli-app/versionCheck.d.ts +4 -0
- package/dist/cli-app/versionCheck.d.ts.map +1 -0
- package/dist/cli-app/versionCheck.js +46 -0
- package/dist/cli-app/versionCheck.js.map +1 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +75 -0
- package/dist/client.js.map +1 -0
- package/dist/commander/Argument.d.ts +19 -0
- package/dist/commander/Argument.d.ts.map +1 -0
- package/dist/commander/Argument.js +25 -0
- package/dist/commander/Argument.js.map +1 -0
- package/dist/commander/Command.d.ts +23 -0
- package/dist/commander/Command.d.ts.map +1 -0
- package/dist/commander/Command.js +159 -0
- package/dist/commander/Command.js.map +1 -0
- package/dist/commander/InvalidArgumentError.d.ts +5 -0
- package/dist/commander/InvalidArgumentError.d.ts.map +1 -0
- package/dist/commander/InvalidArgumentError.js +8 -0
- package/dist/commander/InvalidArgumentError.js.map +1 -0
- package/dist/commander/Option.d.ts +15 -0
- package/dist/commander/Option.d.ts.map +1 -0
- package/dist/commander/Option.js +43 -0
- package/dist/commander/Option.js.map +1 -0
- package/dist/commander/index.d.ts +7 -0
- package/dist/commander/index.d.ts.map +1 -0
- package/dist/commander/index.js +5 -0
- package/dist/commander/index.js.map +1 -0
- package/dist/commander/types.d.ts +2 -0
- package/dist/commander/types.d.ts.map +1 -0
- package/dist/commander/types.js +2 -0
- package/dist/commander/types.js.map +1 -0
- package/dist/commands/CommandAuth/CommandAuth.d.ts +4 -0
- package/dist/commands/CommandAuth/CommandAuth.d.ts.map +1 -0
- package/dist/commands/CommandAuth/CommandAuth.js +24 -0
- package/dist/commands/CommandAuth/CommandAuth.js.map +1 -0
- package/dist/commands/CommandConfig/CommandConfig.d.ts +4 -0
- package/dist/commands/CommandConfig/CommandConfig.d.ts.map +1 -0
- package/dist/commands/CommandConfig/CommandConfig.js +37 -0
- package/dist/commands/CommandConfig/CommandConfig.js.map +1 -0
- package/dist/commands/CommandConfig/sub-commands/configDeleteCommand.d.ts +4 -0
- package/dist/commands/CommandConfig/sub-commands/configDeleteCommand.d.ts.map +1 -0
- package/dist/commands/CommandConfig/sub-commands/configDeleteCommand.js +20 -0
- package/dist/commands/CommandConfig/sub-commands/configDeleteCommand.js.map +1 -0
- package/dist/commands/CommandConfig/sub-commands/configGetCommand.d.ts +5 -0
- package/dist/commands/CommandConfig/sub-commands/configGetCommand.d.ts.map +1 -0
- package/dist/commands/CommandConfig/sub-commands/configGetCommand.js +23 -0
- package/dist/commands/CommandConfig/sub-commands/configGetCommand.js.map +1 -0
- package/dist/commands/CommandConfig/sub-commands/configSetCommand.d.ts +4 -0
- package/dist/commands/CommandConfig/sub-commands/configSetCommand.d.ts.map +1 -0
- package/dist/commands/CommandConfig/sub-commands/configSetCommand.js +69 -0
- package/dist/commands/CommandConfig/sub-commands/configSetCommand.js.map +1 -0
- package/dist/commands/CommandConfig/types.d.ts +6 -0
- package/dist/commands/CommandConfig/types.d.ts.map +1 -0
- package/dist/commands/CommandConfig/types.js +2 -0
- package/dist/commands/CommandConfig/types.js.map +1 -0
- package/dist/commands/CommandConfig/utils/preparePrimaryOptions.d.ts +3 -0
- package/dist/commands/CommandConfig/utils/preparePrimaryOptions.d.ts.map +1 -0
- package/dist/commands/CommandConfig/utils/preparePrimaryOptions.js +8 -0
- package/dist/commands/CommandConfig/utils/preparePrimaryOptions.js.map +1 -0
- package/dist/commands/CommandConfig/utils/resolveConfig.d.ts +8 -0
- package/dist/commands/CommandConfig/utils/resolveConfig.d.ts.map +1 -0
- package/dist/commands/CommandConfig/utils/resolveConfig.js +33 -0
- package/dist/commands/CommandConfig/utils/resolveConfig.js.map +1 -0
- package/dist/commands/CommandConfig/utils/sharedOptions.d.ts +3 -0
- package/dist/commands/CommandConfig/utils/sharedOptions.d.ts.map +1 -0
- package/dist/commands/CommandConfig/utils/sharedOptions.js +14 -0
- package/dist/commands/CommandConfig/utils/sharedOptions.js.map +1 -0
- package/dist/commands/CommandDaemon/CommandDaemon.d.ts +4 -0
- package/dist/commands/CommandDaemon/CommandDaemon.d.ts.map +1 -0
- package/dist/commands/CommandDaemon/CommandDaemon.js +57 -0
- package/dist/commands/CommandDaemon/CommandDaemon.js.map +1 -0
- package/dist/commands/CommandDashboard/CommandDashboard.d.ts +4 -0
- package/dist/commands/CommandDashboard/CommandDashboard.d.ts.map +1 -0
- package/dist/commands/CommandDashboard/CommandDashboard.js +54 -0
- package/dist/commands/CommandDashboard/CommandDashboard.js.map +1 -0
- package/dist/commands/CommandHTTP/CommandHttp.d.ts +4 -0
- package/dist/commands/CommandHTTP/CommandHttp.d.ts.map +1 -0
- package/dist/commands/CommandHTTP/CommandHttp.js +50 -0
- package/dist/commands/CommandHTTP/CommandHttp.js.map +1 -0
- package/dist/commands/CommandInit/CommandInit.d.ts +4 -0
- package/dist/commands/CommandInit/CommandInit.d.ts.map +1 -0
- package/dist/commands/CommandInit/CommandInit.js +36 -0
- package/dist/commands/CommandInit/CommandInit.js.map +1 -0
- package/dist/commands/CommandList/CommandList.d.ts +4 -0
- package/dist/commands/CommandList/CommandList.d.ts.map +1 -0
- package/dist/commands/CommandList/CommandList.js +54 -0
- package/dist/commands/CommandList/CommandList.js.map +1 -0
- package/dist/commands/CommandLogs/CommandLogs.d.ts +4 -0
- package/dist/commands/CommandLogs/CommandLogs.d.ts.map +1 -0
- package/dist/commands/CommandLogs/CommandLogs.js +33 -0
- package/dist/commands/CommandLogs/CommandLogs.js.map +1 -0
- package/dist/commands/CommandProfile/CommandProfile.d.ts +5 -0
- package/dist/commands/CommandProfile/CommandProfile.d.ts.map +1 -0
- package/dist/commands/CommandProfile/CommandProfile.js +64 -0
- package/dist/commands/CommandProfile/CommandProfile.js.map +1 -0
- package/dist/commands/CommandRegister/CommandRegister.d.ts +4 -0
- package/dist/commands/CommandRegister/CommandRegister.d.ts.map +1 -0
- package/dist/commands/CommandRegister/CommandRegister.js +43 -0
- package/dist/commands/CommandRegister/CommandRegister.js.map +1 -0
- package/dist/commands/CommandRestart/CommandRestart.d.ts +4 -0
- package/dist/commands/CommandRestart/CommandRestart.d.ts.map +1 -0
- package/dist/commands/CommandRestart/CommandRestart.js +62 -0
- package/dist/commands/CommandRestart/CommandRestart.js.map +1 -0
- package/dist/commands/CommandServer/CommandServer.d.ts +4 -0
- package/dist/commands/CommandServer/CommandServer.d.ts.map +1 -0
- package/dist/commands/CommandServer/CommandServer.js +24 -0
- package/dist/commands/CommandServer/CommandServer.js.map +1 -0
- package/dist/commands/CommandStop/CommandStop.d.ts +4 -0
- package/dist/commands/CommandStop/CommandStop.d.ts.map +1 -0
- package/dist/commands/CommandStop/CommandStop.js +25 -0
- package/dist/commands/CommandStop/CommandStop.js.map +1 -0
- package/dist/commands/CommandUpdate/CommandUpdate.d.ts +4 -0
- package/dist/commands/CommandUpdate/CommandUpdate.d.ts.map +1 -0
- package/dist/commands/CommandUpdate/CommandUpdate.js +38 -0
- package/dist/commands/CommandUpdate/CommandUpdate.js.map +1 -0
- package/dist/commands/CommandUseProfile/CommandUseProfile.d.ts +4 -0
- package/dist/commands/CommandUseProfile/CommandUseProfile.d.ts.map +1 -0
- package/dist/commands/CommandUseProfile/CommandUseProfile.js +63 -0
- package/dist/commands/CommandUseProfile/CommandUseProfile.js.map +1 -0
- package/dist/commands/helper/Help.d.ts +4 -0
- package/dist/commands/helper/Help.d.ts.map +1 -0
- package/dist/commands/helper/Help.js +134 -0
- package/dist/commands/helper/Help.js.map +1 -0
- package/dist/commands/helper/Parser.d.ts +55 -0
- package/dist/commands/helper/Parser.d.ts.map +1 -0
- package/dist/commands/helper/Parser.js +280 -0
- package/dist/commands/helper/Parser.js.map +1 -0
- package/dist/commands/shared/allowDenyCidrCommand.d.ts +3 -0
- package/dist/commands/shared/allowDenyCidrCommand.d.ts.map +1 -0
- package/dist/commands/shared/allowDenyCidrCommand.js +10 -0
- package/dist/commands/shared/allowDenyCidrCommand.js.map +1 -0
- package/dist/commands/shared/configServersCommand.d.ts +4 -0
- package/dist/commands/shared/configServersCommand.d.ts.map +1 -0
- package/dist/commands/shared/configServersCommand.js +19 -0
- package/dist/commands/shared/configServersCommand.js.map +1 -0
- package/dist/commands/utils.d.ts +3 -0
- package/dist/commands/utils.d.ts.map +1 -0
- package/dist/commands/utils.js +17 -0
- package/dist/commands/utils.js.map +1 -0
- package/dist/config/ParsedConfig.d.ts +31 -0
- package/dist/config/ParsedConfig.d.ts.map +1 -0
- package/dist/config/ParsedConfig.js +116 -0
- package/dist/config/ParsedConfig.js.map +1 -0
- package/dist/config/ParsedGlobalConfig.d.ts +5 -0
- package/dist/config/ParsedGlobalConfig.d.ts.map +1 -0
- package/dist/config/ParsedGlobalConfig.js +7 -0
- package/dist/config/ParsedGlobalConfig.js.map +1 -0
- package/dist/config/ParsedLocalConfig.d.ts +5 -0
- package/dist/config/ParsedLocalConfig.d.ts.map +1 -0
- package/dist/config/ParsedLocalConfig.js +7 -0
- package/dist/config/ParsedLocalConfig.js.map +1 -0
- package/dist/config/ParsedProfileConfig.d.ts +46 -0
- package/dist/config/ParsedProfileConfig.d.ts.map +1 -0
- package/dist/config/ParsedProfileConfig.js +120 -0
- package/dist/config/ParsedProfileConfig.js.map +1 -0
- package/dist/config/ParsedServerConfig.d.ts +20 -0
- package/dist/config/ParsedServerConfig.d.ts.map +1 -0
- package/dist/config/ParsedServerConfig.js +55 -0
- package/dist/config/ParsedServerConfig.js.map +1 -0
- package/dist/config/TempProfileConfig.d.ts +8 -0
- package/dist/config/TempProfileConfig.d.ts.map +1 -0
- package/dist/config/TempProfileConfig.js +13 -0
- package/dist/config/TempProfileConfig.js.map +1 -0
- package/dist/config/utils.d.ts +2 -0
- package/dist/config/utils.d.ts.map +1 -0
- package/dist/config/utils.js +8 -0
- package/dist/config/utils.js.map +1 -0
- package/dist/config/validations/validateProfileConfig.d.ts +4 -0
- package/dist/config/validations/validateProfileConfig.d.ts.map +1 -0
- package/dist/config/validations/validateProfileConfig.js +76 -0
- package/dist/config/validations/validateProfileConfig.js.map +1 -0
- package/dist/core/FS/utils.d.ts +12 -0
- package/dist/core/FS/utils.d.ts.map +1 -0
- package/dist/core/FS/utils.js +55 -0
- package/dist/core/FS/utils.js.map +1 -0
- package/dist/daemon/DaemonClient.d.ts +16 -0
- package/dist/daemon/DaemonClient.d.ts.map +1 -0
- package/dist/daemon/DaemonClient.js +158 -0
- package/dist/daemon/DaemonClient.js.map +1 -0
- package/dist/daemon/DaemonServer.d.ts +8 -0
- package/dist/daemon/DaemonServer.d.ts.map +1 -0
- package/dist/daemon/DaemonServer.js +201 -0
- package/dist/daemon/DaemonServer.js.map +1 -0
- package/dist/daemon/protocol.d.ts +101 -0
- package/dist/daemon/protocol.d.ts.map +1 -0
- package/dist/daemon/protocol.js +2 -0
- package/dist/daemon/protocol.js.map +1 -0
- package/dist/daemon-main.d.ts +2 -0
- package/dist/daemon-main.d.ts.map +1 -0
- package/dist/daemon-main.js +13 -0
- package/dist/daemon-main.js.map +1 -0
- package/dist/launcher-main.d.ts +2 -0
- package/dist/launcher-main.d.ts.map +1 -0
- package/dist/launcher-main.js +57 -0
- package/dist/launcher-main.js.map +1 -0
- package/dist/lib/Flow/applyUpdate.d.ts +3 -0
- package/dist/lib/Flow/applyUpdate.d.ts.map +1 -0
- package/dist/lib/Flow/applyUpdate.js +34 -0
- package/dist/lib/Flow/applyUpdate.js.map +1 -0
- package/dist/lib/Flow/downloadBinaryUpdate.d.ts +3 -0
- package/dist/lib/Flow/downloadBinaryUpdate.d.ts.map +1 -0
- package/dist/lib/Flow/downloadBinaryUpdate.js +54 -0
- package/dist/lib/Flow/downloadBinaryUpdate.js.map +1 -0
- package/dist/lib/Flow/getLatestVersion.d.ts +2 -0
- package/dist/lib/Flow/getLatestVersion.d.ts.map +1 -0
- package/dist/lib/Flow/getLatestVersion.js +13 -0
- package/dist/lib/Flow/getLatestVersion.js.map +1 -0
- package/dist/lib/defs.d.ts +18 -0
- package/dist/lib/defs.d.ts.map +1 -0
- package/dist/lib/defs.js +33 -0
- package/dist/lib/defs.js.map +1 -0
- package/dist/logger/logger.d.ts +6 -0
- package/dist/logger/logger.d.ts.map +1 -0
- package/dist/logger/logger.js +34 -0
- package/dist/logger/logger.js.map +1 -0
- package/dist/output-formats/colors.d.ts +7 -0
- package/dist/output-formats/colors.d.ts.map +1 -0
- package/dist/output-formats/colors.js +8 -0
- package/dist/output-formats/colors.js.map +1 -0
- package/dist/output-formats/formatConfig.d.ts +3 -0
- package/dist/output-formats/formatConfig.d.ts.map +1 -0
- package/dist/output-formats/formatConfig.js +59 -0
- package/dist/output-formats/formatConfig.js.map +1 -0
- package/dist/output-formats/formatConfigPath.d.ts +4 -0
- package/dist/output-formats/formatConfigPath.d.ts.map +1 -0
- package/dist/output-formats/formatConfigPath.js +7 -0
- package/dist/output-formats/formatConfigPath.js.map +1 -0
- package/dist/output-formats/formatPath.d.ts +2 -0
- package/dist/output-formats/formatPath.d.ts.map +1 -0
- package/dist/output-formats/formatPath.js +6 -0
- package/dist/output-formats/formatPath.js.map +1 -0
- package/dist/output-formats/formatProfile.d.ts +3 -0
- package/dist/output-formats/formatProfile.d.ts.map +1 -0
- package/dist/output-formats/formatProfile.js +35 -0
- package/dist/output-formats/formatProfile.js.map +1 -0
- package/dist/output-formats/formatProfilesShort.d.ts +3 -0
- package/dist/output-formats/formatProfilesShort.d.ts.map +1 -0
- package/dist/output-formats/formatProfilesShort.js +19 -0
- package/dist/output-formats/formatProfilesShort.js.map +1 -0
- package/dist/output-formats/formatSaveResult.d.ts +4 -0
- package/dist/output-formats/formatSaveResult.d.ts.map +1 -0
- package/dist/output-formats/formatSaveResult.js +7 -0
- package/dist/output-formats/formatSaveResult.js.map +1 -0
- package/dist/output-formats/table.d.ts +8 -0
- package/dist/output-formats/table.d.ts.map +1 -0
- package/dist/output-formats/table.js +15 -0
- package/dist/output-formats/table.js.map +1 -0
- package/dist/package-json/packageJson.d.ts +6 -0
- package/dist/package-json/packageJson.d.ts.map +1 -0
- package/dist/package-json/packageJson.js +12 -0
- package/dist/package-json/packageJson.js.map +1 -0
- package/dist/proxy/Proxy.d.ts +6 -0
- package/dist/proxy/Proxy.d.ts.map +1 -0
- package/dist/proxy/Proxy.js +203 -0
- package/dist/proxy/Proxy.js.map +1 -0
- package/dist/sea-main.d.ts +2 -0
- package/dist/sea-main.d.ts.map +1 -0
- package/dist/sea-main.js +20 -0
- package/dist/sea-main.js.map +1 -0
- package/dist/types/types.d.ts +55 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/types.js +2 -0
- package/dist/types/types.js.map +1 -0
- package/dist/utils/arrayFunctions.d.ts +24 -0
- package/dist/utils/arrayFunctions.d.ts.map +1 -0
- package/dist/utils/arrayFunctions.js +43 -0
- package/dist/utils/arrayFunctions.js.map +1 -0
- package/dist/utils/assertFunctions.d.ts +7 -0
- package/dist/utils/assertFunctions.d.ts.map +1 -0
- package/dist/utils/assertFunctions.js +20 -0
- package/dist/utils/assertFunctions.js.map +1 -0
- package/dist/utils/checkFunctions.d.ts +34 -0
- package/dist/utils/checkFunctions.d.ts.map +1 -0
- package/dist/utils/checkFunctions.js +87 -0
- package/dist/utils/checkFunctions.js.map +1 -0
- package/dist/utils/cliFunctions.d.ts +10 -0
- package/dist/utils/cliFunctions.d.ts.map +1 -0
- package/dist/utils/cliFunctions.js +68 -0
- package/dist/utils/cliFunctions.js.map +1 -0
- package/dist/utils/hashFunctions.d.ts +10 -0
- package/dist/utils/hashFunctions.d.ts.map +1 -0
- package/dist/utils/hashFunctions.js +11 -0
- package/dist/utils/hashFunctions.js.map +1 -0
- package/dist/utils/npmFunctions.d.ts +3 -0
- package/dist/utils/npmFunctions.d.ts.map +1 -0
- package/dist/utils/npmFunctions.js +28 -0
- package/dist/utils/npmFunctions.js.map +1 -0
- package/dist/utils/stringFunctions.d.ts +12 -0
- package/dist/utils/stringFunctions.d.ts.map +1 -0
- package/dist/utils/stringFunctions.js +37 -0
- package/dist/utils/stringFunctions.js.map +1 -0
- package/package.json +39 -16
- package/client.js +0 -33
- package/src/cli-app/Dashboard.js +0 -220
- package/src/cli-app/Screen/FullScreenModal.js +0 -63
- package/src/cli-app/Screen.js +0 -140
- package/src/cli-app/elements/ElementNode.js +0 -97
- package/src/cli-app/elements/Line.js +0 -21
- package/src/cli-app/elements/List/List.js +0 -227
- package/src/cli-app/elements/List/ListCell.js +0 -83
- package/src/cli-app/elements/List/ListColumn.js +0 -52
- package/src/cli-app/elements/List/ListRow.js +0 -118
- package/src/cli-app/elements/Row.js +0 -38
- package/src/cli-app/helper/utils.js +0 -42
- package/src/commands/Action/addDelValuesAction.js +0 -56
- package/src/commands/CommandAuth.js +0 -32
- package/src/commands/CommandClearAll.js +0 -27
- package/src/commands/CommandConfig.js +0 -59
- package/src/commands/CommandHTTP.js +0 -192
- package/src/commands/CommandInvite.js +0 -38
- package/src/commands/CommandRefresh.js +0 -35
- package/src/commands/CommandRegister.js +0 -48
- package/src/commands/Option/DeleteOption.js +0 -6
- package/src/commands/Option/ProfileListOption.js +0 -65
- package/src/commands/Option/SelectConfigOption.js +0 -52
- package/src/commands/SubCommand/AllowDenyCidrCommand.js +0 -28
- package/src/commands/SubCommand/HostCommand.js +0 -22
- package/src/commands/SubCommand/PortCommand.js +0 -20
- package/src/commands/SubCommand/ProtocolCommand.js +0 -21
- package/src/commands/helper/AliasResolver.js +0 -13
- package/src/commands/helper/BindArgs.js +0 -53
- package/src/commands/helper/SharedArg.js +0 -32
- package/src/commands/utils.js +0 -96
- package/src/config/ConfigAbstract.js +0 -353
- package/src/config/ConfigManager.js +0 -70
- package/src/config/GlobalConfig.js +0 -14
- package/src/config/GlobalLocalShardConfigAbstract.js +0 -98
- package/src/config/LocalConfig.js +0 -7
- package/src/config/PropertyConfig.js +0 -122
- package/src/config/SystemConfig.js +0 -31
- package/src/core/FS/utils.js +0 -60
- package/src/core/Ref.js +0 -70
- package/src/lib/Flow/getCurrentIp.js +0 -18
- package/src/lib/Flow/getLatestVersion.js +0 -13
- package/src/lib/Flow/proxyUrl.js +0 -35
- package/src/lib/Flow/validateAuthToken.js +0 -19
- package/src/lib/HttpClient.js +0 -61
- package/src/lib/Proxy.js +0 -42
- package/src/lib/defs.js +0 -13
- package/src/net/IPV4.js +0 -139
- package/src/net/http/IncomingMessage.js +0 -92
- package/src/net/http/ServerResponse.js +0 -126
- package/src/net/http/TunliRequest.js +0 -1
- package/src/net/http/TunliResponse.js +0 -1
- package/src/net/http/TunnelRequest.js +0 -229
- package/src/net/http/TunnelResponse.js +0 -119
- package/src/tunnel-client/TunnelClient.js +0 -144
- package/src/utils/arrayFunctions.js +0 -45
- package/src/utils/checkFunctions.js +0 -182
- package/src/utils/cliFunctions.js +0 -63
- package/src/utils/createRequest.js +0 -12
- package/src/utils/hashFunctions.js +0 -9
- package/src/utils/httpFunction.js +0 -23
- package/src/utils/npmFunctions.js +0 -27
- package/src/utils/stringFunctions.js +0 -59
- package/types/index.d.ts +0 -119
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import {Ref} from "#src/core/Ref";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Class representing a shared argument, extending Ref.
|
|
5
|
-
*/
|
|
6
|
-
class SharedArg extends Ref {
|
|
7
|
-
/**
|
|
8
|
-
* Create a SharedArg instance.
|
|
9
|
-
* @param {*} value - The initial value for the shared argument.
|
|
10
|
-
*/
|
|
11
|
-
constructor(value) {
|
|
12
|
-
super(value)
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Create a new SharedArg instance.
|
|
18
|
-
* @param {*} value - The initial value for the shared argument.
|
|
19
|
-
* @returns {SharedArg} - The created SharedArg instance.
|
|
20
|
-
*/
|
|
21
|
-
export const sharedArg = (value) => {
|
|
22
|
-
return new SharedArg(value)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Check if a value is an instance of SharedArg.
|
|
27
|
-
* @param {SharedArg|*} value - The value to check.
|
|
28
|
-
* @returns {boolean} - True if the value is an instance of SharedArg, false otherwise.
|
|
29
|
-
*/
|
|
30
|
-
export const isSharedArg = (value) => {
|
|
31
|
-
return value instanceof SharedArg
|
|
32
|
-
}
|
package/src/commands/utils.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import {Command} from "commander";
|
|
2
|
-
import {checkIpV4Cidr} from "#src/utils/checkFunctions";
|
|
3
|
-
|
|
4
|
-
export const validateArrayArguments = (validationCallback) => {
|
|
5
|
-
|
|
6
|
-
return (value, previous) => {
|
|
7
|
-
const ref = {value}
|
|
8
|
-
validationCallback(ref)
|
|
9
|
-
previous ??= []
|
|
10
|
-
previous.push(ref.value)
|
|
11
|
-
return previous
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
export const validateIpV4 = (ref) => {
|
|
15
|
-
ref.value = checkIpV4Cidr(ref.value)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const extendedUsages = []
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @param {Command} program
|
|
22
|
-
* @param {Command} command
|
|
23
|
-
*/
|
|
24
|
-
export const extendUsage = (program, command) => {
|
|
25
|
-
|
|
26
|
-
extendedUsages.push({program, command})
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export const addUsage = (program) => {
|
|
31
|
-
|
|
32
|
-
const help = program.createHelp()
|
|
33
|
-
|
|
34
|
-
for (const {program, command} of extendedUsages) {
|
|
35
|
-
const usage = help.commandUsage(command)
|
|
36
|
-
const before = program.usage()
|
|
37
|
-
program.usage(before + "\n" + ''.padEnd(7, ' ') + usage)
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Add examples to the command help text.
|
|
43
|
-
* @param {Command} program - The commander program instance.
|
|
44
|
-
*/
|
|
45
|
-
export const addExamples = (program) => {
|
|
46
|
-
|
|
47
|
-
const usage = program.usage()
|
|
48
|
-
program.usage('')
|
|
49
|
-
|
|
50
|
-
const maxRowLength = {
|
|
51
|
-
length: 0
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const rows = [].slice.call(program.helpInformation().split("\n").map(x => {
|
|
55
|
-
x = x.trim()
|
|
56
|
-
const rowLength = x.length
|
|
57
|
-
if (rowLength > maxRowLength.length) {
|
|
58
|
-
maxRowLength.length = rowLength
|
|
59
|
-
maxRowLength.row = x
|
|
60
|
-
}
|
|
61
|
-
return x
|
|
62
|
-
}).filter(Boolean), 2)
|
|
63
|
-
program.usage(usage)
|
|
64
|
-
|
|
65
|
-
const maxWhitespaceLength = {
|
|
66
|
-
length: 0
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
for (const match of maxRowLength.row.matchAll(/(\s)+/g)) {
|
|
70
|
-
const whiteSpacesCount = match[0].length
|
|
71
|
-
if (whiteSpacesCount > maxWhitespaceLength.length) {
|
|
72
|
-
maxWhitespaceLength.length = whiteSpacesCount
|
|
73
|
-
maxWhitespaceLength.index = match.index
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const padLength = maxWhitespaceLength.index + maxWhitespaceLength.length - 6
|
|
78
|
-
program.addHelpText('after', "\nExamples:")
|
|
79
|
-
|
|
80
|
-
for (const {example, description} of examples) {
|
|
81
|
-
const whitespaces = ''.padStart(padLength - example.length, ' ')
|
|
82
|
-
program.addHelpText('after', ` tunli ${example}${whitespaces}${description}`)
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Adds an example to the list of examples.
|
|
88
|
-
* @param {string} example - The example command.
|
|
89
|
-
* @param {string} description - The description of the example.
|
|
90
|
-
*/
|
|
91
|
-
export const addExample = (example, description) => {
|
|
92
|
-
examples.push({
|
|
93
|
-
example, description
|
|
94
|
-
})
|
|
95
|
-
}
|
|
96
|
-
const examples = []
|
|
@@ -1,353 +0,0 @@
|
|
|
1
|
-
import {existsSync, readFileSync, writeFileSync} from "fs"
|
|
2
|
-
import {dirname} from 'path'
|
|
3
|
-
import {ensureDirectoryExists} from "#src/core/FS/utils";
|
|
4
|
-
import {PropertyConfig} from "#src/config/PropertyConfig";
|
|
5
|
-
|
|
6
|
-
const callerStack = new Map()
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Mark a value with a caller reference.
|
|
10
|
-
* @param {Object} callee - The caller object.
|
|
11
|
-
* @param {*} value - The value to be marked.
|
|
12
|
-
* @returns {*} - The marked value.
|
|
13
|
-
*/
|
|
14
|
-
const caller = (callee, value) => {
|
|
15
|
-
value = {value}
|
|
16
|
-
callerStack.set(value, callee)
|
|
17
|
-
return value
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Check if a value is marked with a caller reference.
|
|
22
|
-
* @param {*} value - The value to check.
|
|
23
|
-
* @returns {boolean} - True if the value is marked, false otherwise.
|
|
24
|
-
*/
|
|
25
|
-
const isCaller = (value) => {
|
|
26
|
-
return callerStack.has(value)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Retrieve the caller reference for a value.
|
|
31
|
-
* @param {*} value - The value with the caller reference.
|
|
32
|
-
* @returns {Object} - The caller object.
|
|
33
|
-
*/
|
|
34
|
-
const callee = (value) => {
|
|
35
|
-
return callerStack.get(value)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export const VISIBILITY_PRIVATE = 0
|
|
39
|
-
export const VISIBILITY_PUBLIC = 1
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Abstract class representing the basic configuration functionality.
|
|
43
|
-
* @implements {AppConfig}
|
|
44
|
-
*/
|
|
45
|
-
export class ConfigAbstract {
|
|
46
|
-
/**
|
|
47
|
-
* Configuration data.
|
|
48
|
-
* @type {Object}
|
|
49
|
-
* @private
|
|
50
|
-
*/
|
|
51
|
-
#data = {}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Profile and system configuration data.
|
|
55
|
-
* @type {Object}
|
|
56
|
-
* @private
|
|
57
|
-
*/
|
|
58
|
-
#profileData = {
|
|
59
|
-
profile: {}, system: {},
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Path to the configuration file.
|
|
64
|
-
* @type {string}
|
|
65
|
-
* @private
|
|
66
|
-
*/
|
|
67
|
-
#path
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Fallback configuration instance.
|
|
71
|
-
* @type {ConfigAbstract}
|
|
72
|
-
* @private
|
|
73
|
-
*/
|
|
74
|
-
#fallbackConfig
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Defined properties.
|
|
78
|
-
* @type {Array<string>}
|
|
79
|
-
* @private
|
|
80
|
-
*/
|
|
81
|
-
#definedProperties = []
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Property configuration.
|
|
85
|
-
* @type {Object<string, PropertyConfig>}
|
|
86
|
-
* @private
|
|
87
|
-
*/
|
|
88
|
-
#propertyConfig
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Defined properties with inheritance.
|
|
92
|
-
* @type {Array<string>}
|
|
93
|
-
* @private
|
|
94
|
-
*/
|
|
95
|
-
#definedWithInheritProperties
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Active profile name.
|
|
99
|
-
* @type {string}
|
|
100
|
-
* @private
|
|
101
|
-
*/
|
|
102
|
-
#activeProfile = 'default'
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Create a ConfigAbstract instance.
|
|
106
|
-
* @param {Object} prefillData - Initial data to prefill the configuration.
|
|
107
|
-
* @param {string} path - The path to the configuration file.
|
|
108
|
-
* @param {ConfigAbstract} [fallbackConfig] - The fallback configuration.
|
|
109
|
-
*/
|
|
110
|
-
constructor(prefillData = {}, path, fallbackConfig) {
|
|
111
|
-
this.#profileData = prefillData
|
|
112
|
-
this.#profileData.profile ??= {}
|
|
113
|
-
this.#profileData.system ??= {}
|
|
114
|
-
this.#path = path
|
|
115
|
-
this.#fallbackConfig = fallbackConfig
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Get the fallback configuration.
|
|
120
|
-
* @return {ConfigAbstract}
|
|
121
|
-
*/
|
|
122
|
-
get fallbackConfig() {
|
|
123
|
-
return this.#fallbackConfig
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Get the profile data.
|
|
128
|
-
* @return {profileConfig}
|
|
129
|
-
*/
|
|
130
|
-
get profileData() {
|
|
131
|
-
return this.#profileData
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Get the configuration path.
|
|
136
|
-
* @return {string}
|
|
137
|
-
*/
|
|
138
|
-
get configPath() {
|
|
139
|
-
return this.#path
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
get profile() {
|
|
143
|
-
return this.#activeProfile
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* @return {string[]}
|
|
148
|
-
*/
|
|
149
|
-
get profiles() {
|
|
150
|
-
return Object.keys(this.#profileData.profile)
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
exists() {
|
|
154
|
-
return existsSync(this.#path)
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Prepare the configuration by defining properties.
|
|
159
|
-
* @param {{[p: string]: PropertyConfig}} propertyConfig - The configuration properties.
|
|
160
|
-
*/
|
|
161
|
-
prepare(propertyConfig = {}) {
|
|
162
|
-
this.#propertyConfig = propertyConfig
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Define a property.
|
|
166
|
-
* @param {string} name - The name of the property.
|
|
167
|
-
* @param {PropertyConfig} propertyConfig - The configuration of the property.
|
|
168
|
-
*/
|
|
169
|
-
const defineProperty = (name, propertyConfig) => {
|
|
170
|
-
|
|
171
|
-
let {writeable, visibility, type, defaultValue} = propertyConfig
|
|
172
|
-
|
|
173
|
-
this.#definedProperties.push(name)
|
|
174
|
-
const attributes = {
|
|
175
|
-
get: () => {
|
|
176
|
-
return this.#data[name] ?? this.#fallbackConfig?.[name] ?? defaultValue
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
if (writeable) {
|
|
181
|
-
/**
|
|
182
|
-
* Set the value of the property.
|
|
183
|
-
* This method checks if the value is marked with a caller reference
|
|
184
|
-
* and handles the writeable state accordingly. If the property is
|
|
185
|
-
* not writeable, an error is thrown. The value is also validated
|
|
186
|
-
* if a validation function is provided. Finally, the validated
|
|
187
|
-
* value is stored in the configuration data.
|
|
188
|
-
*
|
|
189
|
-
* @param {*} value - The value to set.
|
|
190
|
-
* @throws {Error} If the property is not writeable.
|
|
191
|
-
*/
|
|
192
|
-
attributes.set = (value) => {
|
|
193
|
-
if (isCaller(value)) {
|
|
194
|
-
const writer = callee(value)
|
|
195
|
-
if (writeable && writeable !== true) {
|
|
196
|
-
writeable = writer instanceof writeable
|
|
197
|
-
}
|
|
198
|
-
value = value.value
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
if (!writeable) {
|
|
202
|
-
throw new Error(`property ${name} is not writeable`)
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
if (propertyConfig.validate) {
|
|
206
|
-
value = propertyConfig.validate(value)
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
this.#data[name] = value
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
Object.defineProperty(this, name, attributes)
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
for (const [name, setting] of Object.entries(propertyConfig)) {
|
|
217
|
-
defineProperty(name, setting)
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
this.#definedWithInheritProperties = Array.from(new Set([
|
|
221
|
-
...this.#definedProperties,
|
|
222
|
-
...(this.#fallbackConfig?.#definedWithInheritProperties ?? [])
|
|
223
|
-
]))
|
|
224
|
-
|
|
225
|
-
for (const name of this.#fallbackConfig?.#definedWithInheritProperties ?? []) {
|
|
226
|
-
if (this.#definedProperties.includes(name)) {
|
|
227
|
-
continue
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
Object.defineProperty(this, name, {
|
|
231
|
-
get: () => {
|
|
232
|
-
return this.#fallbackConfig[name]
|
|
233
|
-
},
|
|
234
|
-
set: (value) => {
|
|
235
|
-
if (!isCaller(value)) {
|
|
236
|
-
value = caller(this, value)
|
|
237
|
-
}
|
|
238
|
-
this.#fallbackConfig[name] = value
|
|
239
|
-
}
|
|
240
|
-
})
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Check if a property is public.
|
|
246
|
-
* @param {string} key - The property key.
|
|
247
|
-
* @returns {boolean} - True if the property is public, false otherwise.
|
|
248
|
-
*/
|
|
249
|
-
isPublic(key) {
|
|
250
|
-
return this.#propertyConfig[key]?.visibility === VISIBILITY_PUBLIC
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Save the configuration to the file system.
|
|
255
|
-
* @returns {ConfigAbstract} - The instance of the configuration.
|
|
256
|
-
*/
|
|
257
|
-
save() {
|
|
258
|
-
ensureDirectoryExists(dirname(this.#path))
|
|
259
|
-
console.log(this.#path)
|
|
260
|
-
const isGlobal = this.constructor.name === 'GlobalConfig'
|
|
261
|
-
const isSystem = this.constructor.name === 'SystemConfig'
|
|
262
|
-
|
|
263
|
-
if (!isGlobal && !isSystem) {
|
|
264
|
-
delete this.#profileData.system
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
writeFileSync(this.#path, JSON.stringify(this.#profileData, null, 2) + "\n")
|
|
268
|
-
return this
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* @param {{[p:string]: any}} value
|
|
273
|
-
* @return {ConfigAbstract}
|
|
274
|
-
*/
|
|
275
|
-
update(value) {
|
|
276
|
-
ensureDirectoryExists(dirname(this.#path))
|
|
277
|
-
|
|
278
|
-
const isSystem = this.#data === this.#profileData.system
|
|
279
|
-
const profileData = JSON.parse(readFileSync(this.#path, 'utf-8'))
|
|
280
|
-
profileData.system ??= {}
|
|
281
|
-
profileData.profile ??= {}
|
|
282
|
-
profileData.profile[this.profile] ??= {}
|
|
283
|
-
|
|
284
|
-
const updateData = isSystem ? profileData.system : profileData.profile[this.profile]
|
|
285
|
-
|
|
286
|
-
for (const [k, v] of Object.entries(value)) {
|
|
287
|
-
updateData[k] = v
|
|
288
|
-
this[k] = v
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
writeFileSync(this.#path, JSON.stringify(profileData, null, 2) + "\n")
|
|
292
|
-
return this
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* Use the system configuration.
|
|
297
|
-
* @returns {ConfigAbstract} - The instance of the configuration.
|
|
298
|
-
*/
|
|
299
|
-
useSystem() {
|
|
300
|
-
this.#data = this.#profileData.system
|
|
301
|
-
return this
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* Use a specific profile configuration.
|
|
306
|
-
* @param {string} profile - The profile name.
|
|
307
|
-
* @returns {ConfigAbstract} - The instance of the configuration.
|
|
308
|
-
*/
|
|
309
|
-
use(profile) {
|
|
310
|
-
this.#profileData.profile[profile] ??= {}
|
|
311
|
-
this.#data = this.#profileData.profile[profile]
|
|
312
|
-
this.#activeProfile = profile
|
|
313
|
-
return this
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* Delete a property from the configuration.
|
|
318
|
-
* @param {string} key - The property key.
|
|
319
|
-
* @returns {ConfigAbstract} - The instance of the configuration.
|
|
320
|
-
*/
|
|
321
|
-
del(key) {
|
|
322
|
-
this.#data[key] = undefined
|
|
323
|
-
return this
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
* Copy the current profile to a new profile.
|
|
328
|
-
* @param {string} profile - The new profile name.
|
|
329
|
-
* @returns {ConfigAbstract} - The instance of the configuration.
|
|
330
|
-
*/
|
|
331
|
-
copyCurrentProfileTo(profile) {
|
|
332
|
-
this.#profileData.profile[profile] = {...this.#data}
|
|
333
|
-
return this
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
/**
|
|
337
|
-
* Dump the configuration properties.
|
|
338
|
-
* @returns {Object} - The dumped properties.
|
|
339
|
-
*/
|
|
340
|
-
dump() {
|
|
341
|
-
return Object.fromEntries(this.#definedProperties.map(x => {
|
|
342
|
-
let t = this[x]
|
|
343
|
-
if (Array.isArray(t)) {
|
|
344
|
-
if (t.length) {
|
|
345
|
-
t = t.join(', ')
|
|
346
|
-
} else {
|
|
347
|
-
t = undefined
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
return [x, t]
|
|
351
|
-
}))
|
|
352
|
-
}
|
|
353
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import {resolve} from "path";
|
|
2
|
-
import {CONFIG_DIR_NAME, CONFIG_FILENAME, GLOBAL_CONFIG_DIR} from "#lib/defs";
|
|
3
|
-
import {readJsonFile, searchDirInDirectoryTree} from "#src/core/FS/utils";
|
|
4
|
-
import {existsSync} from "fs";
|
|
5
|
-
|
|
6
|
-
import {GlobalConfig} from "#src/config/GlobalConfig";
|
|
7
|
-
import {SystemConfig} from "#src/config/SystemConfig";
|
|
8
|
-
import {LocalConfig} from "#src/config/LocalConfig";
|
|
9
|
-
|
|
10
|
-
const LOCAL_CONFIG_DIR = resolve(process.cwd(), CONFIG_DIR_NAME)
|
|
11
|
-
export const WORKDIR_CONFIG_DIR = resolve(process.cwd(), CONFIG_DIR_NAME)
|
|
12
|
-
|
|
13
|
-
const searchConfigInDirectoryTree = () => {
|
|
14
|
-
return searchDirInDirectoryTree(CONFIG_DIR_NAME, undefined, [GLOBAL_CONFIG_DIR])
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export class ConfigManager {
|
|
18
|
-
|
|
19
|
-
static loadLocalOnly(profile = 'default', searchInDirectoryTree = true) {
|
|
20
|
-
profile = normalizeProfileAlias(profile)
|
|
21
|
-
|
|
22
|
-
let configDirectory
|
|
23
|
-
if (searchInDirectoryTree) {
|
|
24
|
-
configDirectory = searchConfigInDirectoryTree() ?? LOCAL_CONFIG_DIR
|
|
25
|
-
} else {
|
|
26
|
-
configDirectory = LOCAL_CONFIG_DIR
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const configFilePath = resolve(configDirectory, CONFIG_FILENAME);
|
|
30
|
-
const data = existsSync(configFilePath) ? readJsonFile(configFilePath) : {}
|
|
31
|
-
|
|
32
|
-
return new LocalConfig(data, configFilePath).use(profile)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
static loadCombined(profile = 'default') {
|
|
36
|
-
profile = normalizeProfileAlias(profile)
|
|
37
|
-
|
|
38
|
-
const globalConfig = ConfigManager.loadGlobalOnly()
|
|
39
|
-
const localConfigDirectory = searchConfigInDirectoryTree() ?? LOCAL_CONFIG_DIR
|
|
40
|
-
|
|
41
|
-
const localConfigFilePath = resolve(localConfigDirectory, CONFIG_FILENAME);
|
|
42
|
-
const localExists = existsSync(localConfigFilePath)
|
|
43
|
-
|
|
44
|
-
if (localExists) {
|
|
45
|
-
return new LocalConfig(readJsonFile(localConfigFilePath), localConfigFilePath, globalConfig).use(profile)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return globalConfig.use(profile)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
static loadSystem() {
|
|
52
|
-
const configFilePath = resolve(GLOBAL_CONFIG_DIR, CONFIG_FILENAME);
|
|
53
|
-
const data = existsSync(configFilePath) ? readJsonFile(configFilePath) : {}
|
|
54
|
-
return new SystemConfig(data)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
static loadGlobalOnly(profile = 'default') {
|
|
58
|
-
profile = normalizeProfileAlias(profile)
|
|
59
|
-
const configFilePath = resolve(GLOBAL_CONFIG_DIR, CONFIG_FILENAME);
|
|
60
|
-
const data = existsSync(configFilePath) ? readJsonFile(configFilePath) : {}
|
|
61
|
-
return new GlobalConfig(data).use(profile)
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const normalizeProfileAlias = (profileAlias) => {
|
|
66
|
-
if (typeof profileAlias === 'string' && profileAlias.startsWith('@')) {
|
|
67
|
-
profileAlias = profileAlias.toString().substring(1)
|
|
68
|
-
}
|
|
69
|
-
return profileAlias.toLowerCase()
|
|
70
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import {GLOBAL_CONFIG_DIR} from "#lib/defs";
|
|
2
|
-
import {resolve} from "path";
|
|
3
|
-
import {GlobalLocalShardConfigAbstract} from "#src/config/GlobalLocalShardConfigAbstract";
|
|
4
|
-
import {SystemConfig} from "#src/config/SystemConfig";
|
|
5
|
-
|
|
6
|
-
export class GlobalConfig extends GlobalLocalShardConfigAbstract {
|
|
7
|
-
|
|
8
|
-
constructor(data) {
|
|
9
|
-
const alias = 'default'
|
|
10
|
-
const configFilePath = resolve(GLOBAL_CONFIG_DIR, `${alias}.json`);
|
|
11
|
-
|
|
12
|
-
super({}, data, configFilePath, new SystemConfig(data));
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import {checkHost, checkInArray, checkIpV4Cidr, checkMd5, checkPort, checkUrl} from "#src/utils/checkFunctions";
|
|
2
|
-
import {ConfigAbstract, VISIBILITY_PUBLIC} from "#src/config/ConfigAbstract";
|
|
3
|
-
import {property} from "#src/config/PropertyConfig";
|
|
4
|
-
import {ConfigManager} from "#src/config/ConfigManager";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Abstract class for managing global and local shard configurations.
|
|
8
|
-
* Extends the ConfigAbstract class to include properties specific to network configuration.
|
|
9
|
-
*/
|
|
10
|
-
export class GlobalLocalShardConfigAbstract extends ConfigAbstract {
|
|
11
|
-
|
|
12
|
-
#config = {
|
|
13
|
-
|
|
14
|
-
allowCidr: property({
|
|
15
|
-
visibility: VISIBILITY_PUBLIC,
|
|
16
|
-
writeable: true,
|
|
17
|
-
type: Array,
|
|
18
|
-
defaultValue: [],
|
|
19
|
-
validate(val) {
|
|
20
|
-
return val.map(checkIpV4Cidr)
|
|
21
|
-
}
|
|
22
|
-
}),
|
|
23
|
-
proxyURLs: property({
|
|
24
|
-
defaultValue: {},
|
|
25
|
-
visibility: VISIBILITY_PUBLIC,
|
|
26
|
-
writeable: true,
|
|
27
|
-
type: Array,
|
|
28
|
-
validate(val) {
|
|
29
|
-
const final = {}
|
|
30
|
-
for (const [hash, proxyURL] of Object.entries(val)) {
|
|
31
|
-
final[checkMd5(hash)] = checkUrl(proxyURL)
|
|
32
|
-
}
|
|
33
|
-
return final
|
|
34
|
-
}
|
|
35
|
-
}),
|
|
36
|
-
proxyURL: property({
|
|
37
|
-
visibility: VISIBILITY_PUBLIC,
|
|
38
|
-
writeable: true,
|
|
39
|
-
type: String,
|
|
40
|
-
validate(val) {
|
|
41
|
-
if (!val) {
|
|
42
|
-
return
|
|
43
|
-
}
|
|
44
|
-
return checkUrl(val)
|
|
45
|
-
}
|
|
46
|
-
}),
|
|
47
|
-
denyCidr: property({
|
|
48
|
-
visibility: VISIBILITY_PUBLIC,
|
|
49
|
-
writeable: true,
|
|
50
|
-
type: Array,
|
|
51
|
-
defaultValue: [],
|
|
52
|
-
validate(val) {
|
|
53
|
-
return val.map(checkIpV4Cidr)
|
|
54
|
-
}
|
|
55
|
-
}),
|
|
56
|
-
port: property({
|
|
57
|
-
visibility: VISIBILITY_PUBLIC,
|
|
58
|
-
writeable: true,
|
|
59
|
-
type: Number,
|
|
60
|
-
defaultValue: 80,
|
|
61
|
-
validate(val) {
|
|
62
|
-
return checkPort(val)
|
|
63
|
-
}
|
|
64
|
-
}),
|
|
65
|
-
host: property({
|
|
66
|
-
visibility: VISIBILITY_PUBLIC,
|
|
67
|
-
writeable: true,
|
|
68
|
-
type: String,
|
|
69
|
-
defaultValue: '127.0.0.1',
|
|
70
|
-
validate(val) {
|
|
71
|
-
return checkHost(val)
|
|
72
|
-
}
|
|
73
|
-
}),
|
|
74
|
-
protocol: property({
|
|
75
|
-
visibility: VISIBILITY_PUBLIC,
|
|
76
|
-
writeable: true,
|
|
77
|
-
type: String,
|
|
78
|
-
defaultValue: 'http',
|
|
79
|
-
validate(val) {
|
|
80
|
-
return checkInArray(val, ['http', 'https'])
|
|
81
|
-
}
|
|
82
|
-
}),
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Create a GlobalLocalShardConfigAbstract.
|
|
87
|
-
* @param {Object} additionalConfig - Additional configuration properties to be merged with the default config.
|
|
88
|
-
* @param {Object} prefillData - Initial data to prefill the configuration.
|
|
89
|
-
* @param {string} path - The path to the configuration file.
|
|
90
|
-
* @param {ConfigAbstract} fallbackConfig - The fallback configuration to be used when specific data is not available.
|
|
91
|
-
*/
|
|
92
|
-
constructor(additionalConfig = {}, prefillData = {}, path, fallbackConfig) {
|
|
93
|
-
fallbackConfig ??= ConfigManager.loadSystem()
|
|
94
|
-
super(prefillData, path, fallbackConfig)
|
|
95
|
-
this.prepare({...this.#config, ...additionalConfig})
|
|
96
|
-
this.use('default')
|
|
97
|
-
}
|
|
98
|
-
}
|