(context: RequestAndContextAndOptionalResponse)
| 532 | } |
| 533 | |
| 534 | const tryToExecuteScript = async (context: RequestAndContextAndOptionalResponse) => { |
| 535 | const { |
| 536 | script, |
| 537 | request, |
| 538 | environment, |
| 539 | timelinePath, |
| 540 | baseEnvironment, |
| 541 | clientCertificates, |
| 542 | cookieJar, |
| 543 | response, |
| 544 | globals, |
| 545 | baseGlobals, |
| 546 | userUploadEnvironment, |
| 547 | iteration, |
| 548 | iterationCount, |
| 549 | ancestors, |
| 550 | eventName, |
| 551 | execution, |
| 552 | transientVariables, |
| 553 | runtime, |
| 554 | parentFolders, |
| 555 | settings, |
| 556 | sensitiveValueCollector, |
| 557 | } = context; |
| 558 | invariant(script, 'script must be provided'); |
| 559 | |
| 560 | // location is the complete path of a request, including project, collection and folder(if have). |
| 561 | const requestLocation = ancestors |
| 562 | .filter( |
| 563 | doc => |
| 564 | isRequest(doc) || isRequestGroup(doc) || models.workspace.isWorkspace(doc) || models.project.isProject(doc), |
| 565 | ) |
| 566 | .reverse() |
| 567 | .map(doc => doc.name); |
| 568 | let vault; |
| 569 | if (globals && models.environment.vaultEnvironmentPath in globals.data && settings.enableVaultInScripts) { |
| 570 | // decrypt and set vault in insomnia sdk if necessary. |
| 571 | // the decrypted secrets must stay out of `globals.data`: that object is written back to the |
| 572 | // database by `savePatchesMadeByScript` once the script returns, so storing plaintext there |
| 573 | // would permanently replace the stored ciphertext. |
| 574 | vault = await maskOrDecryptVaultDataIfNecessary({ |
| 575 | vaultEnvironmentData: globals.data[models.environment.vaultEnvironmentPath], |
| 576 | renderPurpose: 'script', |
| 577 | sensitiveValueCollector, |
| 578 | }); |
| 579 | } |
| 580 | |
| 581 | try { |
| 582 | const output = await getRuntime().network.runScript({ |
| 583 | script, |
| 584 | context: { |
| 585 | request, |
| 586 | timelinePath, |
| 587 | timeout: settings.timeout, |
| 588 | // if the selected environment points to the base environment |
| 589 | // script operations on the environment will be applied on the base environment |
| 590 | environment: { |
| 591 | id: environment._id, |
no test coverage detected