octoparse-cli 0.1.14
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 +271 -0
- package/RUNTIME_SECURITY_NOTICE.txt +41 -0
- package/SECURITY.md +24 -0
- package/dist/cli/args.js +34 -0
- package/dist/cli/help.js +214 -0
- package/dist/cli/output.js +39 -0
- package/dist/commands/auth.js +283 -0
- package/dist/commands/capabilities.js +118 -0
- package/dist/commands/cloud.js +241 -0
- package/dist/commands/data.js +220 -0
- package/dist/commands/doctor.js +73 -0
- package/dist/commands/env.js +63 -0
- package/dist/commands/local.js +251 -0
- package/dist/commands/run.js +622 -0
- package/dist/commands/runs.js +171 -0
- package/dist/commands/task.js +101 -0
- package/dist/index.js +133 -0
- package/dist/runtime/account-capabilities.js +71 -0
- package/dist/runtime/api-client.js +290 -0
- package/dist/runtime/artifacts.js +33 -0
- package/dist/runtime/auth.js +94 -0
- package/dist/runtime/bridge-hub.js +173 -0
- package/dist/runtime/client-headers.js +23 -0
- package/dist/runtime/cloud-data.js +75 -0
- package/dist/runtime/config.js +48 -0
- package/dist/runtime/data-exporter.js +267 -0
- package/dist/runtime/engine-host.js +449 -0
- package/dist/runtime/local-runs.js +92 -0
- package/dist/runtime/naming.js +13 -0
- package/dist/runtime/run-control.js +363 -0
- package/dist/runtime/run-services.js +380 -0
- package/dist/runtime/security-notice.js +78 -0
- package/dist/runtime/task-definition-provider.js +282 -0
- package/dist/types.js +4 -0
- package/examples/minimal-task.json +6 -0
- package/examples/navigate-example-task.json +6 -0
- package/node_modules/@octopus/bpmn/index.js +3 -0
- package/node_modules/@octopus/bpmn/lib/Context.js +245 -0
- package/node_modules/@octopus/bpmn/lib/Definition.js +258 -0
- package/node_modules/@octopus/bpmn/lib/Engine.js +275 -0
- package/node_modules/@octopus/bpmn/lib/PrematureStopError.js +7 -0
- package/node_modules/@octopus/bpmn/lib/activities/Activity.js +202 -0
- package/node_modules/@octopus/bpmn/lib/activities/BaseProcess.js +308 -0
- package/node_modules/@octopus/bpmn/lib/activities/BaseTask.js +145 -0
- package/node_modules/@octopus/bpmn/lib/activities/BoundaryEvent.js +12 -0
- package/node_modules/@octopus/bpmn/lib/activities/Dummy.js +10 -0
- package/node_modules/@octopus/bpmn/lib/activities/EventDefinition.js +99 -0
- package/node_modules/@octopus/bpmn/lib/activities/Flow.js +52 -0
- package/node_modules/@octopus/bpmn/lib/activities/Form.js +67 -0
- package/node_modules/@octopus/bpmn/lib/activities/InputOutput.js +53 -0
- package/node_modules/@octopus/bpmn/lib/activities/IntermediateCatchEvent.js +12 -0
- package/node_modules/@octopus/bpmn/lib/activities/MessageFlow.js +19 -0
- package/node_modules/@octopus/bpmn/lib/activities/MultiInstanceLoopCharacteristics.js +160 -0
- package/node_modules/@octopus/bpmn/lib/activities/Properties.js +27 -0
- package/node_modules/@octopus/bpmn/lib/activities/SequenceFlow.js +56 -0
- package/node_modules/@octopus/bpmn/lib/activities/ServiceConnector.js +71 -0
- package/node_modules/@octopus/bpmn/lib/context-helper.js +198 -0
- package/node_modules/@octopus/bpmn/lib/events/EndEvent.js +22 -0
- package/node_modules/@octopus/bpmn/lib/events/ErrorEvent.js +41 -0
- package/node_modules/@octopus/bpmn/lib/events/MessageEvent.js +19 -0
- package/node_modules/@octopus/bpmn/lib/events/StartEvent.js +55 -0
- package/node_modules/@octopus/bpmn/lib/events/TimerEvent.js +75 -0
- package/node_modules/@octopus/bpmn/lib/expressions.js +41 -0
- package/node_modules/@octopus/bpmn/lib/gateways/ExclusiveGateway.js +86 -0
- package/node_modules/@octopus/bpmn/lib/gateways/InclusiveGateway.js +56 -0
- package/node_modules/@octopus/bpmn/lib/gateways/ParallelGateway.js +195 -0
- package/node_modules/@octopus/bpmn/lib/getPropertyValue.js +83 -0
- package/node_modules/@octopus/bpmn/lib/index.js +6 -0
- package/node_modules/@octopus/bpmn/lib/mapper.js +55 -0
- package/node_modules/@octopus/bpmn/lib/parameter.js +119 -0
- package/node_modules/@octopus/bpmn/lib/script-helper.js +45 -0
- package/node_modules/@octopus/bpmn/lib/tasks/ManualTask.js +31 -0
- package/node_modules/@octopus/bpmn/lib/tasks/ReceiveTask.js +31 -0
- package/node_modules/@octopus/bpmn/lib/tasks/ScriptTask.js +35 -0
- package/node_modules/@octopus/bpmn/lib/tasks/SendTask.js +16 -0
- package/node_modules/@octopus/bpmn/lib/tasks/ServiceTask.js +68 -0
- package/node_modules/@octopus/bpmn/lib/tasks/SubProcess.js +17 -0
- package/node_modules/@octopus/bpmn/lib/tasks/Task.js +16 -0
- package/node_modules/@octopus/bpmn/lib/tasks/UserTask.js +47 -0
- package/node_modules/@octopus/bpmn/lib/transformer.js +13 -0
- package/node_modules/@octopus/bpmn/lib/validation.js +111 -0
- package/node_modules/@octopus/bpmn/package.json +17 -0
- package/node_modules/@octopus/bpmn/types/bpmn.d.ts +85 -0
- package/node_modules/@octopus/engine/README.md +370 -0
- package/node_modules/@octopus/engine/dist/actions/BackPreWebPageAction.d.ts +4 -0
- package/node_modules/@octopus/engine/dist/actions/BackPreWebPageAction.js +1 -0
- package/node_modules/@octopus/engine/dist/actions/BaseAction.d.ts +339 -0
- package/node_modules/@octopus/engine/dist/actions/BaseAction.js +1559 -0
- package/node_modules/@octopus/engine/dist/actions/BranchAction.d.ts +9 -0
- package/node_modules/@octopus/engine/dist/actions/BranchAction.js +1 -0
- package/node_modules/@octopus/engine/dist/actions/ClickAction.d.ts +22 -0
- package/node_modules/@octopus/engine/dist/actions/ClickAction.js +1 -0
- package/node_modules/@octopus/engine/dist/actions/ConditionAction.d.ts +4 -0
- package/node_modules/@octopus/engine/dist/actions/ConditionAction.js +1 -0
- package/node_modules/@octopus/engine/dist/actions/EmptyAction.d.ts +4 -0
- package/node_modules/@octopus/engine/dist/actions/EmptyAction.js +12 -0
- package/node_modules/@octopus/engine/dist/actions/EnterCaptchaAction.d.ts +28 -0
- package/node_modules/@octopus/engine/dist/actions/EnterCaptchaAction.js +1 -0
- package/node_modules/@octopus/engine/dist/actions/EnterTextAction.d.ts +20 -0
- package/node_modules/@octopus/engine/dist/actions/EnterTextAction.js +1 -0
- package/node_modules/@octopus/engine/dist/actions/ExtractDataAction.d.ts +40 -0
- package/node_modules/@octopus/engine/dist/actions/ExtractDataAction.js +1 -0
- package/node_modules/@octopus/engine/dist/actions/LoopAction.d.ts +41 -0
- package/node_modules/@octopus/engine/dist/actions/LoopAction.js +526 -0
- package/node_modules/@octopus/engine/dist/actions/LoopStartAction.d.ts +47 -0
- package/node_modules/@octopus/engine/dist/actions/LoopStartAction.js +607 -0
- package/node_modules/@octopus/engine/dist/actions/MouseOverAction.d.ts +8 -0
- package/node_modules/@octopus/engine/dist/actions/MouseOverAction.js +34 -0
- package/node_modules/@octopus/engine/dist/actions/NavigateAction.d.ts +38 -0
- package/node_modules/@octopus/engine/dist/actions/NavigateAction.js +535 -0
- package/node_modules/@octopus/engine/dist/actions/SwitchComboAction.d.ts +13 -0
- package/node_modules/@octopus/engine/dist/actions/SwitchComboAction.js +69 -0
- package/node_modules/@octopus/engine/dist/browser.d.ts +17 -0
- package/node_modules/@octopus/engine/dist/browser.js +157 -0
- package/node_modules/@octopus/engine/dist/browserProxy.d.ts +90 -0
- package/node_modules/@octopus/engine/dist/browserProxy.js +1 -0
- package/node_modules/@octopus/engine/dist/configs/BaseConfig.d.ts +20 -0
- package/node_modules/@octopus/engine/dist/configs/BaseConfig.js +88 -0
- package/node_modules/@octopus/engine/dist/configs/BranchConfig.d.ts +7 -0
- package/node_modules/@octopus/engine/dist/configs/BranchConfig.js +1 -0
- package/node_modules/@octopus/engine/dist/configs/ClickConfig.d.ts +36 -0
- package/node_modules/@octopus/engine/dist/configs/ClickConfig.js +65 -0
- package/node_modules/@octopus/engine/dist/configs/EnterCaptchaConfig.d.ts +19 -0
- package/node_modules/@octopus/engine/dist/configs/EnterCaptchaConfig.js +25 -0
- package/node_modules/@octopus/engine/dist/configs/EnterTextConfig.d.ts +24 -0
- package/node_modules/@octopus/engine/dist/configs/EnterTextConfig.js +36 -0
- package/node_modules/@octopus/engine/dist/configs/ExtractDataConfig.d.ts +12 -0
- package/node_modules/@octopus/engine/dist/configs/ExtractDataConfig.js +1 -0
- package/node_modules/@octopus/engine/dist/configs/LoopConfig.d.ts +25 -0
- package/node_modules/@octopus/engine/dist/configs/LoopConfig.js +40 -0
- package/node_modules/@octopus/engine/dist/configs/LoopStartConfig.d.ts +4 -0
- package/node_modules/@octopus/engine/dist/configs/LoopStartConfig.js +12 -0
- package/node_modules/@octopus/engine/dist/configs/MouseOverConfig.d.ts +8 -0
- package/node_modules/@octopus/engine/dist/configs/MouseOverConfig.js +15 -0
- package/node_modules/@octopus/engine/dist/configs/NavigateConfig.d.ts +41 -0
- package/node_modules/@octopus/engine/dist/configs/NavigateConfig.js +121 -0
- package/node_modules/@octopus/engine/dist/configs/SwitchComboConfig.d.ts +8 -0
- package/node_modules/@octopus/engine/dist/configs/SwitchComboConfig.js +15 -0
- package/node_modules/@octopus/engine/dist/enums/index.d.ts +419 -0
- package/node_modules/@octopus/engine/dist/enums/index.js +314 -0
- package/node_modules/@octopus/engine/dist/extension/BrowserWebSocketTransport-D_zAGZMQ.js +1 -0
- package/node_modules/@octopus/engine/dist/extension/LaunchOptions-DxvePrV4.js +6 -0
- package/node_modules/@octopus/engine/dist/extension/NodeWebSocketTransport-BTgRVB7Z.js +6 -0
- package/node_modules/@octopus/engine/dist/extension/background.js +396 -0
- package/node_modules/@octopus/engine/dist/extension/bidi-C_GIZ8Uz.js +131 -0
- package/node_modules/@octopus/engine/dist/extension/manifest.json +27 -0
- package/node_modules/@octopus/engine/dist/extension/src/content/anti-detection.js +1 -0
- package/node_modules/@octopus/engine/dist/extension-bridge/BaseExtensionBridge.d.ts +21 -0
- package/node_modules/@octopus/engine/dist/extension-bridge/BaseExtensionBridge.js +117 -0
- package/node_modules/@octopus/engine/dist/extension-bridge/SessionExtensionBridge.d.ts +17 -0
- package/node_modules/@octopus/engine/dist/extension-bridge/SessionExtensionBridge.js +29 -0
- package/node_modules/@octopus/engine/dist/extension-bridge/index.d.ts +2 -0
- package/node_modules/@octopus/engine/dist/extension-bridge/index.js +5 -0
- package/node_modules/@octopus/engine/dist/extension-bridge/types.d.ts +159 -0
- package/node_modules/@octopus/engine/dist/extension-bridge/types.js +5 -0
- package/node_modules/@octopus/engine/dist/extensions/ublock-origin/uBlock0.chromium.tar.xz +0 -0
- package/node_modules/@octopus/engine/dist/extensions/ublock-origin-lite/uBOLite.chromium.tar.xz +0 -0
- package/node_modules/@octopus/engine/dist/index.d.ts +169 -0
- package/node_modules/@octopus/engine/dist/index.js +1 -0
- package/node_modules/@octopus/engine/dist/models/actionItem.d.ts +16 -0
- package/node_modules/@octopus/engine/dist/models/actionItem.js +15 -0
- package/node_modules/@octopus/engine/dist/models/conditionCheckArgs.d.ts +11 -0
- package/node_modules/@octopus/engine/dist/models/conditionCheckArgs.js +11 -0
- package/node_modules/@octopus/engine/dist/models/customizeCookie.d.ts +14 -0
- package/node_modules/@octopus/engine/dist/models/customizeCookie.js +6 -0
- package/node_modules/@octopus/engine/dist/models/downloadFileConfig.d.ts +17 -0
- package/node_modules/@octopus/engine/dist/models/downloadFileConfig.js +26 -0
- package/node_modules/@octopus/engine/dist/models/elementNotFoundArgs.d.ts +8 -0
- package/node_modules/@octopus/engine/dist/models/elementNotFoundArgs.js +12 -0
- package/node_modules/@octopus/engine/dist/models/elementNotFoundError.d.ts +2 -0
- package/node_modules/@octopus/engine/dist/models/elementNotFoundError.js +6 -0
- package/node_modules/@octopus/engine/dist/models/extractItem.d.ts +37 -0
- package/node_modules/@octopus/engine/dist/models/extractItem.js +35 -0
- package/node_modules/@octopus/engine/dist/models/extractTemplate.d.ts +11 -0
- package/node_modules/@octopus/engine/dist/models/extractTemplate.js +48 -0
- package/node_modules/@octopus/engine/dist/models/extractTextItem.d.ts +10 -0
- package/node_modules/@octopus/engine/dist/models/extractTextItem.js +17 -0
- package/node_modules/@octopus/engine/dist/models/globalConfig.d.ts +5 -0
- package/node_modules/@octopus/engine/dist/models/globalConfig.js +1 -0
- package/node_modules/@octopus/engine/dist/models/httpHeader.d.ts +4 -0
- package/node_modules/@octopus/engine/dist/models/httpHeader.js +10 -0
- package/node_modules/@octopus/engine/dist/models/operation.d.ts +27 -0
- package/node_modules/@octopus/engine/dist/models/operation.js +242 -0
- package/node_modules/@octopus/engine/dist/models/retryCondition.d.ts +7 -0
- package/node_modules/@octopus/engine/dist/models/retryCondition.js +10 -0
- package/node_modules/@octopus/engine/dist/models/task.d.ts +89 -0
- package/node_modules/@octopus/engine/dist/models/task.js +120 -0
- package/node_modules/@octopus/engine/dist/models/trigger.d.ts +66 -0
- package/node_modules/@octopus/engine/dist/models/trigger.js +117 -0
- package/node_modules/@octopus/engine/dist/package.json +26 -0
- package/node_modules/@octopus/engine/dist/public-types.d.ts +13 -0
- package/node_modules/@octopus/engine/dist/public-types.js +2 -0
- package/node_modules/@octopus/engine/dist/settings.d.ts +41 -0
- package/node_modules/@octopus/engine/dist/settings.js +20 -0
- package/node_modules/@octopus/engine/dist/solvers/captcha/ClickCaptchaSolver.d.ts +6 -0
- package/node_modules/@octopus/engine/dist/solvers/captcha/ClickCaptchaSolver.js +1 -0
- package/node_modules/@octopus/engine/dist/solvers/captcha/HCaptchaSolver.d.ts +4 -0
- package/node_modules/@octopus/engine/dist/solvers/captcha/HCaptchaSolver.js +73 -0
- package/node_modules/@octopus/engine/dist/solvers/captcha/ImageCaptchaSolver.d.ts +2 -0
- package/node_modules/@octopus/engine/dist/solvers/captcha/ImageCaptchaSolver.js +74 -0
- package/node_modules/@octopus/engine/dist/solvers/captcha/RecaptchaSolver.d.ts +9 -0
- package/node_modules/@octopus/engine/dist/solvers/captcha/RecaptchaSolver.js +371 -0
- package/node_modules/@octopus/engine/dist/solvers/captcha/SliderCaptchaSolver.d.ts +6 -0
- package/node_modules/@octopus/engine/dist/solvers/captcha/SliderCaptchaSolver.js +184 -0
- package/node_modules/@octopus/engine/dist/solvers/captcha/SlidingTrajectory.d.ts +50 -0
- package/node_modules/@octopus/engine/dist/solvers/captcha/SlidingTrajectory.js +125 -0
- package/node_modules/@octopus/engine/dist/solvers/captcha/types.d.ts +68 -0
- package/node_modules/@octopus/engine/dist/solvers/captcha/types.js +34 -0
- package/node_modules/@octopus/engine/dist/solvers/captcha/utils.d.ts +2 -0
- package/node_modules/@octopus/engine/dist/solvers/captcha/utils.js +15 -0
- package/node_modules/@octopus/engine/dist/translator/actionFactory.d.ts +6 -0
- package/node_modules/@octopus/engine/dist/translator/actionFactory.js +1 -0
- package/node_modules/@octopus/engine/dist/translator/activityTypeEnum.d.ts +22 -0
- package/node_modules/@octopus/engine/dist/translator/activityTypeEnum.js +1 -0
- package/node_modules/@octopus/engine/dist/translator/backPreWebPageAction.d.ts +5 -0
- package/node_modules/@octopus/engine/dist/translator/backPreWebPageAction.js +1 -0
- package/node_modules/@octopus/engine/dist/translator/baseAction.d.ts +31 -0
- package/node_modules/@octopus/engine/dist/translator/baseAction.js +1 -0
- package/node_modules/@octopus/engine/dist/translator/breakActivity.d.ts +5 -0
- package/node_modules/@octopus/engine/dist/translator/breakActivity.js +1 -0
- package/node_modules/@octopus/engine/dist/translator/clickAction.d.ts +5 -0
- package/node_modules/@octopus/engine/dist/translator/clickAction.js +1 -0
- package/node_modules/@octopus/engine/dist/translator/completeWF.d.ts +5 -0
- package/node_modules/@octopus/engine/dist/translator/completeWF.js +1 -0
- package/node_modules/@octopus/engine/dist/translator/conditionAction.d.ts +6 -0
- package/node_modules/@octopus/engine/dist/translator/conditionAction.js +1 -0
- package/node_modules/@octopus/engine/dist/translator/emptyAction.d.ts +5 -0
- package/node_modules/@octopus/engine/dist/translator/emptyAction.js +1 -0
- package/node_modules/@octopus/engine/dist/translator/enterCapachaAction.d.ts +5 -0
- package/node_modules/@octopus/engine/dist/translator/enterCapachaAction.js +1 -0
- package/node_modules/@octopus/engine/dist/translator/enterTextAction.d.ts +5 -0
- package/node_modules/@octopus/engine/dist/translator/enterTextAction.js +1 -0
- package/node_modules/@octopus/engine/dist/translator/extractDataAction.d.ts +13 -0
- package/node_modules/@octopus/engine/dist/translator/extractDataAction.js +1 -0
- package/node_modules/@octopus/engine/dist/translator/loopAction.d.ts +5 -0
- package/node_modules/@octopus/engine/dist/translator/loopAction.js +1 -0
- package/node_modules/@octopus/engine/dist/translator/mouseOverAction.d.ts +5 -0
- package/node_modules/@octopus/engine/dist/translator/mouseOverAction.js +19 -0
- package/node_modules/@octopus/engine/dist/translator/navigateAction.d.ts +5 -0
- package/node_modules/@octopus/engine/dist/translator/navigateAction.js +117 -0
- package/node_modules/@octopus/engine/dist/translator/rootAction.d.ts +6 -0
- package/node_modules/@octopus/engine/dist/translator/rootAction.js +80 -0
- package/node_modules/@octopus/engine/dist/translator/switchCombo2Action.d.ts +5 -0
- package/node_modules/@octopus/engine/dist/translator/switchCombo2Action.js +19 -0
- package/node_modules/@octopus/engine/dist/translator/translator.d.ts +1 -0
- package/node_modules/@octopus/engine/dist/translator/translator.js +36 -0
- package/node_modules/@octopus/engine/dist/type.d.ts +25 -0
- package/node_modules/@octopus/engine/dist/type.js +2 -0
- package/node_modules/@octopus/engine/dist/types/browser.d.ts +191 -0
- package/node_modules/@octopus/engine/dist/types/browser.js +1 -0
- package/node_modules/@octopus/engine/dist/types/browserManager.d.ts +41 -0
- package/node_modules/@octopus/engine/dist/types/browserManager.js +1 -0
- package/node_modules/@octopus/engine/dist/types/index.d.ts +40 -0
- package/node_modules/@octopus/engine/dist/types/index.js +2 -0
- package/node_modules/@octopus/engine/dist/types/plugin.d.ts +29 -0
- package/node_modules/@octopus/engine/dist/types/plugin.js +2 -0
- package/node_modules/@octopus/engine/dist/utils/AsyncEmitter.d.ts +15 -0
- package/node_modules/@octopus/engine/dist/utils/AsyncEmitter.js +1 -0
- package/node_modules/@octopus/engine/dist/utils/DataStore.d.ts +58 -0
- package/node_modules/@octopus/engine/dist/utils/DataStore.js +1 -0
- package/node_modules/@octopus/engine/dist/utils/DateTimeFormatHelper.d.ts +22 -0
- package/node_modules/@octopus/engine/dist/utils/DateTimeFormatHelper.js +173 -0
- package/node_modules/@octopus/engine/dist/utils/FileDownloader.d.ts +108 -0
- package/node_modules/@octopus/engine/dist/utils/FileDownloader.js +1 -0
- package/node_modules/@octopus/engine/dist/utils/HttpRequester.d.ts +43 -0
- package/node_modules/@octopus/engine/dist/utils/HttpRequester.js +174 -0
- package/node_modules/@octopus/engine/dist/utils/JsonParser.d.ts +95 -0
- package/node_modules/@octopus/engine/dist/utils/JsonParser.js +439 -0
- package/node_modules/@octopus/engine/dist/utils/Operations.d.ts +27 -0
- package/node_modules/@octopus/engine/dist/utils/Operations.js +115 -0
- package/node_modules/@octopus/engine/dist/utils/index.d.ts +28 -0
- package/node_modules/@octopus/engine/dist/utils/index.js +356 -0
- package/node_modules/@octopus/engine/package.json +58 -0
- package/package.json +79 -0
- package/schemas/capabilities-v1.schema.json +234 -0
- package/schemas/detached-bootstrap-v1.schema.json +42 -0
- package/schemas/json-envelope-v1.schema.json +39 -0
- package/schemas/run-event-v1.schema.json +47 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { chmod, mkdir, readFile, unlink, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { dirname, join } from 'node:path';
|
|
5
|
+
export function configFilePath() {
|
|
6
|
+
return join(homedir(), '.octoparse', 'config.json');
|
|
7
|
+
}
|
|
8
|
+
export async function readCliConfig() {
|
|
9
|
+
const filePath = configFilePath();
|
|
10
|
+
let raw = '';
|
|
11
|
+
try {
|
|
12
|
+
raw = await readFile(filePath, 'utf8');
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return {};
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
const parsed = JSON.parse(raw);
|
|
19
|
+
return {
|
|
20
|
+
apiBaseUrl: typeof parsed.apiBaseUrl === 'string' ? parsed.apiBaseUrl : undefined,
|
|
21
|
+
apiEnv: typeof parsed.apiEnv === 'string' ? parsed.apiEnv : undefined,
|
|
22
|
+
updatedAt: typeof parsed.updatedAt === 'string' ? parsed.updatedAt : undefined
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return {};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export async function saveCliConfig(config) {
|
|
30
|
+
const filePath = configFilePath();
|
|
31
|
+
const existing = await readCliConfig();
|
|
32
|
+
const next = {
|
|
33
|
+
...existing,
|
|
34
|
+
...config,
|
|
35
|
+
updatedAt: new Date().toISOString()
|
|
36
|
+
};
|
|
37
|
+
await mkdir(dirname(filePath), { recursive: true, mode: 0o700 });
|
|
38
|
+
await writeFile(filePath, `${JSON.stringify(next, null, 2)}\n`, { encoding: 'utf8', mode: 0o600 });
|
|
39
|
+
await chmod(filePath, 0o600).catch(() => undefined);
|
|
40
|
+
return next;
|
|
41
|
+
}
|
|
42
|
+
export async function removeCliConfig() {
|
|
43
|
+
const filePath = configFilePath();
|
|
44
|
+
if (!existsSync(filePath))
|
|
45
|
+
return false;
|
|
46
|
+
await unlink(filePath);
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { basename, dirname, extname, join, resolve } from 'node:path';
|
|
4
|
+
const INTERNAL_EXPORT_FIELDS = new Set(['#', '#text', '$id', '$isSaved']);
|
|
5
|
+
export async function exportRowsToFile(rows, targetFile, format) {
|
|
6
|
+
const file = resolveAvailableFile(targetFile);
|
|
7
|
+
await mkdir(dirname(file), { recursive: true });
|
|
8
|
+
const exportRows = rows.map(toPublicExportRow);
|
|
9
|
+
const content = formatRows(exportRows, format);
|
|
10
|
+
await writeFile(file, content);
|
|
11
|
+
return { file, format, rows: rows.length };
|
|
12
|
+
}
|
|
13
|
+
export function normalizeDataExportFormat(format, targetFile) {
|
|
14
|
+
const value = (format ?? (targetFile ? formatFromFile(targetFile) : undefined) ?? 'xlsx').toLowerCase();
|
|
15
|
+
if (value === 'excel')
|
|
16
|
+
return 'xlsx';
|
|
17
|
+
if (value === 'xlsx' || value === 'csv' || value === 'html' || value === 'json' || value === 'xml')
|
|
18
|
+
return value;
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
function formatFromFile(targetFile) {
|
|
22
|
+
const lower = targetFile.toLowerCase();
|
|
23
|
+
if (lower.endsWith('.xlsx'))
|
|
24
|
+
return 'xlsx';
|
|
25
|
+
if (lower.endsWith('.csv'))
|
|
26
|
+
return 'csv';
|
|
27
|
+
if (lower.endsWith('.html') || lower.endsWith('.htm'))
|
|
28
|
+
return 'html';
|
|
29
|
+
if (lower.endsWith('.json'))
|
|
30
|
+
return 'json';
|
|
31
|
+
if (lower.endsWith('.xml'))
|
|
32
|
+
return 'xml';
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
function resolveAvailableFile(targetFile) {
|
|
36
|
+
const file = resolve(targetFile);
|
|
37
|
+
if (!existsSync(file))
|
|
38
|
+
return file;
|
|
39
|
+
const dir = dirname(file);
|
|
40
|
+
const ext = extname(file);
|
|
41
|
+
const name = basename(file, ext);
|
|
42
|
+
for (let index = 1; index < Number.MAX_SAFE_INTEGER; index += 1) {
|
|
43
|
+
const candidate = join(dir, `${name} (${index})${ext}`);
|
|
44
|
+
if (!existsSync(candidate))
|
|
45
|
+
return candidate;
|
|
46
|
+
}
|
|
47
|
+
return file;
|
|
48
|
+
}
|
|
49
|
+
function formatRows(rows, format) {
|
|
50
|
+
if (format === 'xlsx')
|
|
51
|
+
return toXlsx(rows);
|
|
52
|
+
if (format === 'csv')
|
|
53
|
+
return toCsv(rows);
|
|
54
|
+
if (format === 'html')
|
|
55
|
+
return toHtml(rows);
|
|
56
|
+
if (format === 'json')
|
|
57
|
+
return `${JSON.stringify(rows, null, 2)}\n`;
|
|
58
|
+
return toXml(rows);
|
|
59
|
+
}
|
|
60
|
+
function headersOf(rows) {
|
|
61
|
+
return [...new Set(rows.flatMap((row) => Object.keys(row).filter((key) => !isInternalExportField(key))))];
|
|
62
|
+
}
|
|
63
|
+
function isInternalExportField(key) {
|
|
64
|
+
return INTERNAL_EXPORT_FIELDS.has(key);
|
|
65
|
+
}
|
|
66
|
+
function toPublicExportRow(row) {
|
|
67
|
+
const result = {};
|
|
68
|
+
for (const [key, value] of Object.entries(row)) {
|
|
69
|
+
if (!isInternalExportField(key))
|
|
70
|
+
result[key] = value;
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
function toCsv(rows) {
|
|
75
|
+
const headers = headersOf(rows);
|
|
76
|
+
if (!headers.length)
|
|
77
|
+
return '';
|
|
78
|
+
const lines = [
|
|
79
|
+
headers.map(csvCell).join(','),
|
|
80
|
+
...rows.map((row) => headers.map((header) => csvCell(row[header])).join(','))
|
|
81
|
+
];
|
|
82
|
+
return `${lines.join('\n')}\n`;
|
|
83
|
+
}
|
|
84
|
+
function csvCell(value) {
|
|
85
|
+
if (value === null || value === undefined)
|
|
86
|
+
return '';
|
|
87
|
+
const text = primitiveText(value);
|
|
88
|
+
return /[",\n\r]/.test(text) ? `"${text.replace(/"/g, '""')}"` : text;
|
|
89
|
+
}
|
|
90
|
+
function toHtml(rows) {
|
|
91
|
+
const headers = headersOf(rows);
|
|
92
|
+
const head = headers.map((header) => `<th>${escapeHtml(header)}</th>`).join('');
|
|
93
|
+
const body = rows.map((row) => {
|
|
94
|
+
const cells = headers.map((header) => `<td>${escapeHtml(primitiveText(row[header]))}</td>`).join('');
|
|
95
|
+
return `<tr>${cells}</tr>`;
|
|
96
|
+
}).join('\n');
|
|
97
|
+
return `<!doctype html>
|
|
98
|
+
<html>
|
|
99
|
+
<head>
|
|
100
|
+
<meta charset="utf-8">
|
|
101
|
+
<title>Octopus Export</title>
|
|
102
|
+
</head>
|
|
103
|
+
<body>
|
|
104
|
+
<table>
|
|
105
|
+
<thead><tr>${head}</tr></thead>
|
|
106
|
+
<tbody>
|
|
107
|
+
${body}
|
|
108
|
+
</tbody>
|
|
109
|
+
</table>
|
|
110
|
+
</body>
|
|
111
|
+
</html>
|
|
112
|
+
`;
|
|
113
|
+
}
|
|
114
|
+
function toXml(rows) {
|
|
115
|
+
const lines = ['<?xml version="1.0" encoding="UTF-8"?>', '<rows>'];
|
|
116
|
+
for (const row of rows) {
|
|
117
|
+
lines.push(' <row>');
|
|
118
|
+
for (const [key, value] of Object.entries(row)) {
|
|
119
|
+
lines.push(` <field name="${escapeXmlAttribute(key)}">${escapeXml(primitiveText(value))}</field>`);
|
|
120
|
+
}
|
|
121
|
+
lines.push(' </row>');
|
|
122
|
+
}
|
|
123
|
+
lines.push('</rows>');
|
|
124
|
+
return `${lines.join('\n')}\n`;
|
|
125
|
+
}
|
|
126
|
+
function toXlsx(rows) {
|
|
127
|
+
const headers = headersOf(rows);
|
|
128
|
+
const sheetRows = [headers, ...rows.map((row) => headers.map((header) => row[header]))];
|
|
129
|
+
const sheetData = sheetRows.map((row, rowIndex) => {
|
|
130
|
+
const cells = row.map((value, colIndex) => {
|
|
131
|
+
const ref = `${columnName(colIndex + 1)}${rowIndex + 1}`;
|
|
132
|
+
return `<c r="${ref}" t="inlineStr"><is><t>${escapeXml(primitiveText(value))}</t></is></c>`;
|
|
133
|
+
}).join('');
|
|
134
|
+
return `<row r="${rowIndex + 1}">${cells}</row>`;
|
|
135
|
+
}).join('');
|
|
136
|
+
return createZip([
|
|
137
|
+
['[Content_Types].xml', `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
138
|
+
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
|
|
139
|
+
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
|
|
140
|
+
<Default Extension="xml" ContentType="application/xml"/>
|
|
141
|
+
<Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/>
|
|
142
|
+
<Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>
|
|
143
|
+
</Types>`],
|
|
144
|
+
['_rels/.rels', `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
145
|
+
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
|
146
|
+
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/>
|
|
147
|
+
</Relationships>`],
|
|
148
|
+
['xl/workbook.xml', `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
149
|
+
<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
|
|
150
|
+
<sheets>
|
|
151
|
+
<sheet name="Sheet1" sheetId="1" r:id="rId1"/>
|
|
152
|
+
</sheets>
|
|
153
|
+
</workbook>`],
|
|
154
|
+
['xl/_rels/workbook.xml.rels', `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
155
|
+
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
|
156
|
+
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/>
|
|
157
|
+
</Relationships>`],
|
|
158
|
+
['xl/worksheets/sheet1.xml', `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
159
|
+
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
|
|
160
|
+
<sheetData>${sheetData}</sheetData>
|
|
161
|
+
</worksheet>`]
|
|
162
|
+
]);
|
|
163
|
+
}
|
|
164
|
+
function columnName(index) {
|
|
165
|
+
let name = '';
|
|
166
|
+
let current = index;
|
|
167
|
+
while (current > 0) {
|
|
168
|
+
const modulo = (current - 1) % 26;
|
|
169
|
+
name = String.fromCharCode(65 + modulo) + name;
|
|
170
|
+
current = Math.floor((current - modulo) / 26);
|
|
171
|
+
}
|
|
172
|
+
return name;
|
|
173
|
+
}
|
|
174
|
+
function primitiveText(value) {
|
|
175
|
+
if (value === null || value === undefined)
|
|
176
|
+
return '';
|
|
177
|
+
if (typeof value === 'string')
|
|
178
|
+
return value;
|
|
179
|
+
if (typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint')
|
|
180
|
+
return String(value);
|
|
181
|
+
return JSON.stringify(value);
|
|
182
|
+
}
|
|
183
|
+
function escapeHtml(value) {
|
|
184
|
+
return value
|
|
185
|
+
.replace(/&/g, '&')
|
|
186
|
+
.replace(/</g, '<')
|
|
187
|
+
.replace(/>/g, '>')
|
|
188
|
+
.replace(/"/g, '"')
|
|
189
|
+
.replace(/'/g, ''');
|
|
190
|
+
}
|
|
191
|
+
function escapeXml(value) {
|
|
192
|
+
return value
|
|
193
|
+
.replace(/&/g, '&')
|
|
194
|
+
.replace(/</g, '<')
|
|
195
|
+
.replace(/>/g, '>');
|
|
196
|
+
}
|
|
197
|
+
function escapeXmlAttribute(value) {
|
|
198
|
+
return escapeXml(value).replace(/"/g, '"');
|
|
199
|
+
}
|
|
200
|
+
function createZip(files) {
|
|
201
|
+
const localParts = [];
|
|
202
|
+
const centralParts = [];
|
|
203
|
+
let offset = 0;
|
|
204
|
+
for (const [name, content] of files) {
|
|
205
|
+
const nameBuffer = Buffer.from(name);
|
|
206
|
+
const data = Buffer.isBuffer(content) ? content : Buffer.from(content);
|
|
207
|
+
const crc = crc32(data);
|
|
208
|
+
const localHeader = Buffer.alloc(30);
|
|
209
|
+
localHeader.writeUInt32LE(0x04034b50, 0);
|
|
210
|
+
localHeader.writeUInt16LE(20, 4);
|
|
211
|
+
localHeader.writeUInt16LE(0x0800, 6);
|
|
212
|
+
localHeader.writeUInt16LE(0, 8);
|
|
213
|
+
localHeader.writeUInt16LE(0, 10);
|
|
214
|
+
localHeader.writeUInt16LE(0, 12);
|
|
215
|
+
localHeader.writeUInt32LE(crc, 14);
|
|
216
|
+
localHeader.writeUInt32LE(data.length, 18);
|
|
217
|
+
localHeader.writeUInt32LE(data.length, 22);
|
|
218
|
+
localHeader.writeUInt16LE(nameBuffer.length, 26);
|
|
219
|
+
localHeader.writeUInt16LE(0, 28);
|
|
220
|
+
localParts.push(localHeader, nameBuffer, data);
|
|
221
|
+
const centralHeader = Buffer.alloc(46);
|
|
222
|
+
centralHeader.writeUInt32LE(0x02014b50, 0);
|
|
223
|
+
centralHeader.writeUInt16LE(20, 4);
|
|
224
|
+
centralHeader.writeUInt16LE(20, 6);
|
|
225
|
+
centralHeader.writeUInt16LE(0x0800, 8);
|
|
226
|
+
centralHeader.writeUInt16LE(0, 10);
|
|
227
|
+
centralHeader.writeUInt16LE(0, 12);
|
|
228
|
+
centralHeader.writeUInt16LE(0, 14);
|
|
229
|
+
centralHeader.writeUInt32LE(crc, 16);
|
|
230
|
+
centralHeader.writeUInt32LE(data.length, 20);
|
|
231
|
+
centralHeader.writeUInt32LE(data.length, 24);
|
|
232
|
+
centralHeader.writeUInt16LE(nameBuffer.length, 28);
|
|
233
|
+
centralHeader.writeUInt16LE(0, 30);
|
|
234
|
+
centralHeader.writeUInt16LE(0, 32);
|
|
235
|
+
centralHeader.writeUInt16LE(0, 34);
|
|
236
|
+
centralHeader.writeUInt16LE(0, 36);
|
|
237
|
+
centralHeader.writeUInt32LE(0, 38);
|
|
238
|
+
centralHeader.writeUInt32LE(offset, 42);
|
|
239
|
+
centralParts.push(centralHeader, nameBuffer);
|
|
240
|
+
offset += localHeader.length + nameBuffer.length + data.length;
|
|
241
|
+
}
|
|
242
|
+
const central = Buffer.concat(centralParts);
|
|
243
|
+
const end = Buffer.alloc(22);
|
|
244
|
+
end.writeUInt32LE(0x06054b50, 0);
|
|
245
|
+
end.writeUInt16LE(0, 4);
|
|
246
|
+
end.writeUInt16LE(0, 6);
|
|
247
|
+
end.writeUInt16LE(files.length, 8);
|
|
248
|
+
end.writeUInt16LE(files.length, 10);
|
|
249
|
+
end.writeUInt32LE(central.length, 12);
|
|
250
|
+
end.writeUInt32LE(offset, 16);
|
|
251
|
+
end.writeUInt16LE(0, 20);
|
|
252
|
+
return Buffer.concat([...localParts, central, end]);
|
|
253
|
+
}
|
|
254
|
+
const CRC_TABLE = new Uint32Array(256).map((_value, index) => {
|
|
255
|
+
let crc = index;
|
|
256
|
+
for (let bit = 0; bit < 8; bit += 1) {
|
|
257
|
+
crc = (crc & 1) ? (0xedb88320 ^ (crc >>> 1)) : (crc >>> 1);
|
|
258
|
+
}
|
|
259
|
+
return crc >>> 0;
|
|
260
|
+
});
|
|
261
|
+
function crc32(data) {
|
|
262
|
+
let crc = 0xffffffff;
|
|
263
|
+
for (const byte of data) {
|
|
264
|
+
crc = CRC_TABLE[(crc ^ byte) & 0xff] ^ (crc >>> 8);
|
|
265
|
+
}
|
|
266
|
+
return (crc ^ 0xffffffff) >>> 0;
|
|
267
|
+
}
|