(context: RequestAndContextAndOptionalResponse)
| 487 | } |
| 488 | |
| 489 | const tryToExecuteScript = async (context: RequestAndContextAndOptionalResponse) => { |
| 490 | const { |
| 491 | script, |
| 492 | request, |
| 493 | environment, |
| 494 | timelinePath, |
| 495 | baseEnvironment, |
| 496 | clientCertificates, |
| 497 | cookieJar, |
| 498 | response, |
| 499 | globals, |
| 500 | baseGlobals, |
| 501 | userUploadEnvironment, |
| 502 | iteration, |
| 503 | iterationCount, |
| 504 | ancestors, |
| 505 | eventName, |
| 506 | execution, |
| 507 | transientVariables, |
| 508 | runtime, |
| 509 | parentFolders, |
| 510 | settings, |
| 511 | sensitiveValueCollector, |
| 512 | } = context; |
| 513 | invariant(script, 'script must be provided'); |
| 514 | |
| 515 | // location is the complete path of a request, including project, collection and folder(if have). |
| 516 | const requestLocation = ancestors |
| 517 | .filter( |
| 518 | doc => |
| 519 | isRequest(doc) || isRequestGroup(doc) || models.workspace.isWorkspace(doc) || models.project.isProject(doc), |
| 520 | ) |
| 521 | .reverse() |
| 522 | .map(doc => doc.name); |
| 523 | let vault; |
| 524 | if (globals && models.environment.vaultEnvironmentPath in globals.data && settings.enableVaultInScripts) { |
| 525 | // decrypt and set vault in insomnia sdk if necessary. |
| 526 | // the decrypted secrets must stay out of `globals.data`: that object is written back to the |
| 527 | // database by `savePatchesMadeByScript` once the script returns, so storing plaintext there |
| 528 | // would permanently replace the stored ciphertext. |
| 529 | vault = await maskOrDecryptVaultDataIfNecessary({ |
| 530 | vaultEnvironmentData: globals.data[models.environment.vaultEnvironmentPath], |
| 531 | renderPurpose: 'script', |
| 532 | sensitiveValueCollector, |
| 533 | }); |
| 534 | } |
| 535 | |
| 536 | try { |
| 537 | const output = await getRuntime().network.runScript({ |
| 538 | script, |
| 539 | context: { |
| 540 | request, |
| 541 | timelinePath, |
| 542 | timeout: settings.timeout, |
| 543 | // if the selected environment points to the base environment |
| 544 | // script operations on the environment will be applied on the base environment |
| 545 | environment: { |
| 546 | id: environment._id, |
no test coverage detected