@scalar/pre-post-request-scripts 0.3.17 → 0.4.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.
Files changed (124) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/components/ScriptEditor.vue.d.ts.map +1 -0
  3. package/dist/components/ScriptEditor.vue.js +7 -0
  4. package/dist/components/ScriptEditor.vue.js.map +1 -0
  5. package/dist/{plugins/post-response-scripts/components/PostResponseScripts → components}/ScriptEditor.vue.script.js +1 -1
  6. package/dist/components/ScriptEditor.vue.script.js.map +1 -0
  7. package/dist/index.d.ts +1 -3
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +3 -3
  10. package/dist/libs/execute-scripts/build-sandbox-context.d.ts +15 -0
  11. package/dist/libs/execute-scripts/build-sandbox-context.d.ts.map +1 -0
  12. package/dist/libs/execute-scripts/build-sandbox-context.js +29 -0
  13. package/dist/libs/execute-scripts/build-sandbox-context.js.map +1 -0
  14. package/dist/libs/execute-scripts/execute-post-response-script.d.ts +3 -0
  15. package/dist/libs/execute-scripts/execute-post-response-script.d.ts.map +1 -1
  16. package/dist/libs/execute-scripts/execute-post-response-script.js +9 -4
  17. package/dist/libs/execute-scripts/execute-post-response-script.js.map +1 -1
  18. package/dist/libs/execute-scripts/execute-pre-request-script.d.ts +14 -0
  19. package/dist/libs/execute-scripts/execute-pre-request-script.d.ts.map +1 -0
  20. package/dist/libs/execute-scripts/execute-pre-request-script.js +26 -0
  21. package/dist/libs/execute-scripts/execute-pre-request-script.js.map +1 -0
  22. package/dist/libs/execute-scripts/index.d.ts +1 -0
  23. package/dist/libs/execute-scripts/index.d.ts.map +1 -1
  24. package/dist/libs/execute-scripts/postman-adapter/request-factory-adapter.d.ts +16 -0
  25. package/dist/libs/execute-scripts/postman-adapter/request-factory-adapter.d.ts.map +1 -0
  26. package/dist/libs/execute-scripts/postman-adapter/request-factory-adapter.js +95 -0
  27. package/dist/libs/execute-scripts/postman-adapter/request-factory-adapter.js.map +1 -0
  28. package/dist/libs/execute-scripts/postman-adapter/sandbox-adapter.d.ts +16 -0
  29. package/dist/libs/execute-scripts/postman-adapter/sandbox-adapter.d.ts.map +1 -0
  30. package/dist/libs/execute-scripts/{postman-sandbox-adapter.js → postman-adapter/sandbox-adapter.js} +43 -8
  31. package/dist/libs/execute-scripts/postman-adapter/sandbox-adapter.js.map +1 -0
  32. package/dist/libs/execute-scripts/variables-store.d.ts +22 -0
  33. package/dist/libs/execute-scripts/variables-store.d.ts.map +1 -0
  34. package/dist/libs/execute-scripts/variables-store.js +36 -0
  35. package/dist/libs/execute-scripts/variables-store.js.map +1 -0
  36. package/dist/plugins/index.d.ts +2 -0
  37. package/dist/plugins/index.d.ts.map +1 -0
  38. package/dist/plugins/index.js +2 -0
  39. package/dist/plugins/request-scripts/components/ExampleScripts.vue.d.ts.map +1 -0
  40. package/dist/plugins/{post-response-scripts/components/PostResponseScripts → request-scripts/components}/ExampleScripts.vue.js +1 -1
  41. package/dist/plugins/request-scripts/components/ExampleScripts.vue.js.map +1 -0
  42. package/dist/plugins/{post-response-scripts/components/PostResponseScripts → request-scripts/components}/ExampleScripts.vue.script.js +2 -2
  43. package/dist/plugins/request-scripts/components/ExampleScripts.vue.script.js.map +1 -0
  44. package/dist/plugins/{post-response-scripts/components/PostResponseScripts/PostResponseScripts.vue.d.ts → request-scripts/components/ScriptsSection.vue.d.ts} +3 -3
  45. package/dist/plugins/request-scripts/components/ScriptsSection.vue.d.ts.map +1 -0
  46. package/dist/plugins/request-scripts/components/ScriptsSection.vue.js +7 -0
  47. package/dist/plugins/request-scripts/components/ScriptsSection.vue.js.map +1 -0
  48. package/dist/plugins/request-scripts/components/ScriptsSection.vue.script.js +59 -0
  49. package/dist/plugins/request-scripts/components/ScriptsSection.vue.script.js.map +1 -0
  50. package/dist/plugins/{post-response-scripts → request-scripts}/components/TestResults/TestResultIndicator.vue.d.ts +1 -1
  51. package/dist/plugins/request-scripts/components/TestResults/TestResultIndicator.vue.d.ts.map +1 -0
  52. package/dist/plugins/{post-response-scripts → request-scripts}/components/TestResults/TestResultIndicator.vue.js +1 -1
  53. package/dist/plugins/request-scripts/components/TestResults/TestResultIndicator.vue.js.map +1 -0
  54. package/dist/plugins/{post-response-scripts → request-scripts}/components/TestResults/TestResultIndicator.vue.script.js +1 -1
  55. package/dist/plugins/request-scripts/components/TestResults/TestResultIndicator.vue.script.js.map +1 -0
  56. package/dist/plugins/{post-response-scripts → request-scripts}/components/TestResults/TestResultItem.vue.d.ts +1 -1
  57. package/dist/plugins/request-scripts/components/TestResults/TestResultItem.vue.d.ts.map +1 -0
  58. package/dist/plugins/{post-response-scripts → request-scripts}/components/TestResults/TestResultItem.vue.js +1 -1
  59. package/dist/plugins/request-scripts/components/TestResults/TestResultItem.vue.js.map +1 -0
  60. package/dist/plugins/{post-response-scripts → request-scripts}/components/TestResults/TestResultItem.vue.script.js +1 -1
  61. package/dist/plugins/request-scripts/components/TestResults/TestResultItem.vue.script.js.map +1 -0
  62. package/dist/plugins/{post-response-scripts → request-scripts}/components/TestResults/TestResults.vue.d.ts +1 -1
  63. package/dist/plugins/request-scripts/components/TestResults/TestResults.vue.d.ts.map +1 -0
  64. package/dist/plugins/{post-response-scripts → request-scripts}/components/TestResults/TestResults.vue.js +1 -1
  65. package/dist/plugins/request-scripts/components/TestResults/TestResults.vue.js.map +1 -0
  66. package/dist/plugins/{post-response-scripts → request-scripts}/components/TestResults/TestResults.vue.script.js +1 -1
  67. package/dist/plugins/request-scripts/components/TestResults/TestResults.vue.script.js.map +1 -0
  68. package/dist/plugins/{post-response-scripts → request-scripts}/components/TestResults/TestSummary.vue.d.ts +1 -1
  69. package/dist/plugins/request-scripts/components/TestResults/TestSummary.vue.d.ts.map +1 -0
  70. package/dist/plugins/{post-response-scripts → request-scripts}/components/TestResults/TestSummary.vue.js +1 -1
  71. package/dist/plugins/request-scripts/components/TestResults/TestSummary.vue.js.map +1 -0
  72. package/dist/plugins/{post-response-scripts → request-scripts}/components/TestResults/TestSummary.vue.script.js +1 -1
  73. package/dist/plugins/request-scripts/components/TestResults/TestSummary.vue.script.js.map +1 -0
  74. package/dist/plugins/request-scripts/components/TestResults/index.d.ts.map +1 -0
  75. package/dist/plugins/request-scripts/request-scripts-plugin.d.ts +13 -0
  76. package/dist/plugins/request-scripts/request-scripts-plugin.d.ts.map +1 -0
  77. package/dist/plugins/request-scripts/request-scripts-plugin.js +55 -0
  78. package/dist/plugins/request-scripts/request-scripts-plugin.js.map +1 -0
  79. package/package.json +12 -25
  80. package/dist/_virtual/_plugin-vue_export-helper.js +0 -8
  81. package/dist/libs/execute-scripts/index.js +0 -2
  82. package/dist/libs/execute-scripts/postman-sandbox-adapter.d.ts +0 -9
  83. package/dist/libs/execute-scripts/postman-sandbox-adapter.d.ts.map +0 -1
  84. package/dist/libs/execute-scripts/postman-sandbox-adapter.js.map +0 -1
  85. package/dist/plugins/post-response-scripts/components/PostResponseScripts/ExampleScripts.vue.d.ts.map +0 -1
  86. package/dist/plugins/post-response-scripts/components/PostResponseScripts/ExampleScripts.vue.js.map +0 -1
  87. package/dist/plugins/post-response-scripts/components/PostResponseScripts/ExampleScripts.vue.script.js.map +0 -1
  88. package/dist/plugins/post-response-scripts/components/PostResponseScripts/PostResponseScripts.vue.d.ts.map +0 -1
  89. package/dist/plugins/post-response-scripts/components/PostResponseScripts/PostResponseScripts.vue.js +0 -7
  90. package/dist/plugins/post-response-scripts/components/PostResponseScripts/PostResponseScripts.vue.js.map +0 -1
  91. package/dist/plugins/post-response-scripts/components/PostResponseScripts/PostResponseScripts.vue.script.js +0 -49
  92. package/dist/plugins/post-response-scripts/components/PostResponseScripts/PostResponseScripts.vue.script.js.map +0 -1
  93. package/dist/plugins/post-response-scripts/components/PostResponseScripts/ScriptEditor.vue.d.ts.map +0 -1
  94. package/dist/plugins/post-response-scripts/components/PostResponseScripts/ScriptEditor.vue.js +0 -9
  95. package/dist/plugins/post-response-scripts/components/PostResponseScripts/ScriptEditor.vue.js.map +0 -1
  96. package/dist/plugins/post-response-scripts/components/PostResponseScripts/ScriptEditor.vue.script.js.map +0 -1
  97. package/dist/plugins/post-response-scripts/components/PostResponseScripts/index.d.ts +0 -2
  98. package/dist/plugins/post-response-scripts/components/PostResponseScripts/index.d.ts.map +0 -1
  99. package/dist/plugins/post-response-scripts/components/PostResponseScripts/index.js +0 -2
  100. package/dist/plugins/post-response-scripts/components/TestResults/TestResultIndicator.vue.d.ts.map +0 -1
  101. package/dist/plugins/post-response-scripts/components/TestResults/TestResultIndicator.vue.js.map +0 -1
  102. package/dist/plugins/post-response-scripts/components/TestResults/TestResultIndicator.vue.script.js.map +0 -1
  103. package/dist/plugins/post-response-scripts/components/TestResults/TestResultItem.vue.d.ts.map +0 -1
  104. package/dist/plugins/post-response-scripts/components/TestResults/TestResultItem.vue.js.map +0 -1
  105. package/dist/plugins/post-response-scripts/components/TestResults/TestResultItem.vue.script.js.map +0 -1
  106. package/dist/plugins/post-response-scripts/components/TestResults/TestResults.vue.d.ts.map +0 -1
  107. package/dist/plugins/post-response-scripts/components/TestResults/TestResults.vue.js.map +0 -1
  108. package/dist/plugins/post-response-scripts/components/TestResults/TestResults.vue.script.js.map +0 -1
  109. package/dist/plugins/post-response-scripts/components/TestResults/TestSummary.vue.d.ts.map +0 -1
  110. package/dist/plugins/post-response-scripts/components/TestResults/TestSummary.vue.js.map +0 -1
  111. package/dist/plugins/post-response-scripts/components/TestResults/TestSummary.vue.script.js.map +0 -1
  112. package/dist/plugins/post-response-scripts/components/TestResults/index.d.ts.map +0 -1
  113. package/dist/plugins/post-response-scripts/components/TestResults/index.js +0 -2
  114. package/dist/plugins/post-response-scripts/index.d.ts +0 -2
  115. package/dist/plugins/post-response-scripts/index.d.ts.map +0 -1
  116. package/dist/plugins/post-response-scripts/index.js +0 -2
  117. package/dist/plugins/post-response-scripts/post-response-scripts-plugin.d.ts +0 -6
  118. package/dist/plugins/post-response-scripts/post-response-scripts-plugin.d.ts.map +0 -1
  119. package/dist/plugins/post-response-scripts/post-response-scripts-plugin.js +0 -61
  120. package/dist/plugins/post-response-scripts/post-response-scripts-plugin.js.map +0 -1
  121. package/dist/style.css +0 -64
  122. /package/dist/{plugins/post-response-scripts/components/PostResponseScripts → components}/ScriptEditor.vue.d.ts +0 -0
  123. /package/dist/plugins/{post-response-scripts/components/PostResponseScripts → request-scripts/components}/ExampleScripts.vue.d.ts +0 -0
  124. /package/dist/plugins/{post-response-scripts → request-scripts}/components/TestResults/index.d.ts +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @scalar/scripts
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#8695](https://github.com/scalar/scalar/pull/8695): feat: support post request scripts
8
+
9
+ ## 0.3.18
10
+
3
11
  ## 0.3.17
4
12
 
5
13
  ## 0.3.16
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ScriptEditor.vue.d.ts","sourceRoot":"","sources":["../../src/components/ScriptEditor.vue"],"names":[],"mappings":"AA0CA,KAAK,WAAW,GAAG;IACjB,UAAU,EAAE,MAAM,CAAA;CACnB,CAAC;AAmDF,QAAA,MAAM,YAAY;;;;kFAGhB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
@@ -0,0 +1,7 @@
1
+ import ScriptEditor_vue_vue_type_script_setup_true_lang_default from "./ScriptEditor.vue.script.js";
2
+ //#region src/components/ScriptEditor.vue
3
+ var ScriptEditor_default = ScriptEditor_vue_vue_type_script_setup_true_lang_default;
4
+ //#endregion
5
+ export { ScriptEditor_default as default };
6
+
7
+ //# sourceMappingURL=ScriptEditor.vue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ScriptEditor.vue.js","names":[],"sources":["../../src/components/ScriptEditor.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { javascript } from '@codemirror/lang-javascript'\nimport { useCodeMirror } from '@scalar/use-codemirror'\nimport { ref, toRef } from 'vue'\n\nconst props = defineProps<{\n modelValue: string\n}>()\n\nconst emit = defineEmits<{\n (e: 'update:modelValue', value: string): void\n}>()\n\nconst codeMirrorRef = ref<HTMLDivElement | null>(null)\n\nuseCodeMirror({\n codeMirrorRef,\n content: toRef(() => props.modelValue),\n language: undefined,\n // We want to use some custom configuration for the syntax highlighting.\n extensions: [javascript()],\n lineNumbers: true,\n onChange: (value) => {\n emit('update:modelValue', value)\n },\n})\n</script>\n\n<template>\n <div class=\"script-editor text-sm\">\n <div\n ref=\"codeMirrorRef\"\n class=\"editor-container\" />\n </div>\n</template>\n"],"mappings":""}
@@ -1,7 +1,7 @@
1
1
  import { createElementBlock, createElementVNode, defineComponent, openBlock, ref, toRef } from "vue";
2
2
  import { javascript } from "@codemirror/lang-javascript";
3
3
  import { useCodeMirror } from "@scalar/use-codemirror";
4
- //#region src/plugins/post-response-scripts/components/PostResponseScripts/ScriptEditor.vue?vue&type=script&setup=true&lang.ts
4
+ //#region src/components/ScriptEditor.vue?vue&type=script&setup=true&lang.ts
5
5
  var _hoisted_1 = { class: "script-editor text-sm" };
6
6
  var ScriptEditor_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
7
7
  __name: "ScriptEditor",
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ScriptEditor.vue.script.js","names":[],"sources":["../../src/components/ScriptEditor.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { javascript } from '@codemirror/lang-javascript'\nimport { useCodeMirror } from '@scalar/use-codemirror'\nimport { ref, toRef } from 'vue'\n\nconst props = defineProps<{\n modelValue: string\n}>()\n\nconst emit = defineEmits<{\n (e: 'update:modelValue', value: string): void\n}>()\n\nconst codeMirrorRef = ref<HTMLDivElement | null>(null)\n\nuseCodeMirror({\n codeMirrorRef,\n content: toRef(() => props.modelValue),\n language: undefined,\n // We want to use some custom configuration for the syntax highlighting.\n extensions: [javascript()],\n lineNumbers: true,\n onChange: (value) => {\n emit('update:modelValue', value)\n },\n})\n</script>\n\n<template>\n <div class=\"script-editor text-sm\">\n <div\n ref=\"codeMirrorRef\"\n class=\"editor-container\" />\n </div>\n</template>\n"],"mappings":";;;;;;;;;;EAKA,MAAM,QAAQ;EAId,MAAM,OAAO;EAIb,MAAM,gBAAgB,IAA2B,KAAI;AAErD,gBAAc;GACZ;GACA,SAAS,YAAY,MAAM,WAAW;GACtC,UAAU,KAAA;GAEV,YAAY,CAAC,YAAY,CAAC;GAC1B,aAAa;GACb,WAAW,UAAU;AACnB,SAAK,qBAAqB,MAAK;;GAElC,CAAA;;uBAIC,mBAIM,OAJN,YAIM,CAHJ,mBAE6B,OAAA;aADvB;IAAJ,KAAI;IACJ,OAAM"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,2 @@
1
- export { ViewLayoutCollapse } from './components/ViewLayout';
2
- export { postResponseScriptsPlugin } from './plugins/post-response-scripts/index.js';
3
- export { postResponseScriptsPluginV2 } from './plugins/post-response-scripts/post-response-scripts-plugin.js';
1
+ export { executePostResponseScript, executePreRequestScript } from './libs/execute-scripts';
4
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAA;AAC3E,OAAO,EAAE,2BAA2B,EAAE,MAAM,8DAA8D,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAA"}
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import ViewLayoutCollapse_default from "./components/ViewLayout/ViewLayoutCollapse.vue.js";
2
- import { postResponseScriptsPlugin, postResponseScriptsPluginV2 } from "./plugins/post-response-scripts/post-response-scripts-plugin.js";
3
- export { ViewLayoutCollapse_default as ViewLayoutCollapse, postResponseScriptsPlugin, postResponseScriptsPluginV2 };
1
+ import { executePostResponseScript } from "./libs/execute-scripts/execute-post-response-script.js";
2
+ import { executePreRequestScript } from "./libs/execute-scripts/execute-pre-request-script.js";
3
+ export { executePostResponseScript, executePreRequestScript };
@@ -0,0 +1,15 @@
1
+ import type { VariablesStore } from '@scalar/workspace-store/request-example';
2
+ import { VariableScope } from 'postman-collection';
3
+ /**
4
+ * Builds the Postman sandbox context object for variables (globals, environment,
5
+ * collection, data, _variables) from a VariablesStore. Used so pm.variables.get/set
6
+ * and precedence match Postman behavior.
7
+ */
8
+ export declare function buildSandboxContextFromStore(store: VariablesStore): {
9
+ globals: VariableScope;
10
+ collectionVariables: VariableScope;
11
+ environment: VariableScope;
12
+ data: Record<string, string>;
13
+ _variables: VariableScope;
14
+ };
15
+ //# sourceMappingURL=build-sandbox-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-sandbox-context.d.ts","sourceRoot":"","sources":["../../../src/libs/execute-scripts/build-sandbox-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,cAAc,EAAE,MAAM,yCAAyC,CAAA;AAC5F,OAAO,EAAgB,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAgBhE;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,cAAc,GAAG;IACnE,OAAO,EAAE,aAAa,CAAA;IACtB,mBAAmB,EAAE,aAAa,CAAA;IAClC,WAAW,EAAE,aAAa,CAAA;IAC1B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC5B,UAAU,EAAE,aAAa,CAAA;CAC1B,CASA"}
@@ -0,0 +1,29 @@
1
+ import { getVariableScopesFromStore } from "./variables-store.js";
2
+ import { VariableList, VariableScope } from "postman-collection";
3
+ //#region src/libs/execute-scripts/build-sandbox-context.ts
4
+ function toVariableList(entries) {
5
+ if (entries.length === 0) return new VariableList(null, []);
6
+ return new VariableList(null, entries.map((e) => ({
7
+ key: e.key,
8
+ value: e.value
9
+ })));
10
+ }
11
+ /**
12
+ * Builds the Postman sandbox context object for variables (globals, environment,
13
+ * collection, data, _variables) from a VariablesStore. Used so pm.variables.get/set
14
+ * and precedence match Postman behavior.
15
+ */
16
+ function buildSandboxContextFromStore(store) {
17
+ const scopes = getVariableScopesFromStore(store);
18
+ return {
19
+ globals: new VariableScope(toVariableList(scopes.globals)),
20
+ collectionVariables: new VariableScope(toVariableList(scopes.collectionVariables)),
21
+ environment: new VariableScope(toVariableList(scopes.environment)),
22
+ data: scopes.data,
23
+ _variables: new VariableScope(toVariableList(scopes.local))
24
+ };
25
+ }
26
+ //#endregion
27
+ export { buildSandboxContextFromStore };
28
+
29
+ //# sourceMappingURL=build-sandbox-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-sandbox-context.js","names":[],"sources":["../../../src/libs/execute-scripts/build-sandbox-context.ts"],"sourcesContent":["import type { VariableEntry, VariablesStore } from '@scalar/workspace-store/request-example'\nimport { VariableList, VariableScope } from 'postman-collection'\n\nimport { getVariableScopesFromStore } from './variables-store'\n\nfunction toVariableList(entries: VariableEntry[]): VariableList {\n if (entries.length === 0) {\n // @ts-expect-error - VariableList constructor expects a Property<PropertyDefinition>\n return new VariableList(null, [])\n }\n return new VariableList(\n // @ts-expect-error - VariableList constructor expects a Property<PropertyDefinition>\n null,\n entries.map((e) => ({ key: e.key, value: e.value })),\n )\n}\n\n/**\n * Builds the Postman sandbox context object for variables (globals, environment,\n * collection, data, _variables) from a VariablesStore. Used so pm.variables.get/set\n * and precedence match Postman behavior.\n */\nexport function buildSandboxContextFromStore(store: VariablesStore): {\n globals: VariableScope\n collectionVariables: VariableScope\n environment: VariableScope\n data: Record<string, string>\n _variables: VariableScope\n} {\n const scopes = getVariableScopesFromStore(store)\n return {\n globals: new VariableScope(toVariableList(scopes.globals)),\n collectionVariables: new VariableScope(toVariableList(scopes.collectionVariables)),\n environment: new VariableScope(toVariableList(scopes.environment)),\n data: scopes.data,\n _variables: new VariableScope(toVariableList(scopes.local)),\n }\n}\n"],"mappings":";;;AAKA,SAAS,eAAe,SAAwC;AAC9D,KAAI,QAAQ,WAAW,EAErB,QAAO,IAAI,aAAa,MAAM,EAAE,CAAC;AAEnC,QAAO,IAAI,aAET,MACA,QAAQ,KAAK,OAAO;EAAE,KAAK,EAAE;EAAK,OAAO,EAAE;EAAO,EAAE,CACrD;;;;;;;AAQH,SAAgB,6BAA6B,OAM3C;CACA,MAAM,SAAS,2BAA2B,MAAM;AAChD,QAAO;EACL,SAAS,IAAI,cAAc,eAAe,OAAO,QAAQ,CAAC;EAC1D,qBAAqB,IAAI,cAAc,eAAe,OAAO,oBAAoB,CAAC;EAClF,aAAa,IAAI,cAAc,eAAe,OAAO,YAAY,CAAC;EAClE,MAAM,OAAO;EACb,YAAY,IAAI,cAAc,eAAe,OAAO,MAAM,CAAC;EAC5D"}
@@ -1,3 +1,4 @@
1
+ import type { RequestFactory, VariablesStore } from '@scalar/workspace-store/request-example';
1
2
  export type TestResult = {
2
3
  title: string;
3
4
  passed: boolean;
@@ -6,7 +7,9 @@ export type TestResult = {
6
7
  status: 'pending' | 'passed' | 'failed';
7
8
  };
8
9
  export declare const executePostResponseScript: (script: string | undefined, data: {
10
+ requestBuilder: RequestFactory;
9
11
  response: Response;
10
12
  onTestResultsUpdate?: ((results: TestResult[]) => void) | undefined;
13
+ variablesStore?: VariablesStore;
11
14
  }) => Promise<void>;
12
15
  //# sourceMappingURL=execute-post-response-script.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"execute-post-response-script.d.ts","sourceRoot":"","sources":["../../../src/libs/execute-scripts/execute-post-response-script.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,UAAU,GAAG;IACvB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,OAAO,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAA;CACxC,CAAA;AAED,eAAO,MAAM,yBAAyB,GACpC,QAAQ,MAAM,GAAG,SAAS,EAC1B,MAAM;IACJ,QAAQ,EAAE,QAAQ,CAAA;IAClB,mBAAmB,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,IAAI,CAAC,GAAG,SAAS,CAAA;CACpE,KACA,OAAO,CAAC,IAAI,CAUd,CAAA"}
1
+ {"version":3,"file":"execute-post-response-script.d.ts","sourceRoot":"","sources":["../../../src/libs/execute-scripts/execute-post-response-script.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAA;AAK7F,MAAM,MAAM,UAAU,GAAG;IACvB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,OAAO,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAA;CACxC,CAAA;AAED,eAAO,MAAM,yBAAyB,GACpC,QAAQ,MAAM,GAAG,SAAS,EAC1B,MAAM;IACJ,cAAc,EAAE,cAAc,CAAA;IAC9B,QAAQ,EAAE,QAAQ,CAAA;IAClB,mBAAmB,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,IAAI,CAAC,GAAG,SAAS,CAAA;IACnE,cAAc,CAAC,EAAE,cAAc,CAAA;CAChC,KACA,OAAO,CAAC,IAAI,CAed,CAAA"}
@@ -1,13 +1,18 @@
1
1
  import { createConsoleContext } from "./context/console.js";
2
- import { executeInPostmanSandbox } from "./postman-sandbox-adapter.js";
2
+ import { executeInPostmanSandbox } from "./postman-adapter/sandbox-adapter.js";
3
3
  //#region src/libs/execute-scripts/execute-post-response-script.ts
4
4
  var executePostResponseScript = async (script, data) => {
5
5
  if (!script) return;
6
6
  await executeInPostmanSandbox({
7
7
  script,
8
- response: data.response,
9
- onTestResultsUpdate: data.onTestResultsUpdate,
10
- scriptConsole: createConsoleContext()
8
+ type: "post-response",
9
+ context: {
10
+ requestBuilder: data.requestBuilder,
11
+ response: data.response,
12
+ scriptConsole: createConsoleContext(),
13
+ variablesStore: data.variablesStore
14
+ },
15
+ onTestResultsUpdate: data.onTestResultsUpdate
11
16
  });
12
17
  };
13
18
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"execute-post-response-script.js","names":[],"sources":["../../../src/libs/execute-scripts/execute-post-response-script.ts"],"sourcesContent":["import { createConsoleContext } from './context/console'\nimport { executeInPostmanSandbox } from './postman-sandbox-adapter'\n\nexport type TestResult = {\n title: string\n passed: boolean\n duration: number\n error?: string\n status: 'pending' | 'passed' | 'failed'\n}\n\nexport const executePostResponseScript = async (\n script: string | undefined,\n data: {\n response: Response\n onTestResultsUpdate?: ((results: TestResult[]) => void) | undefined\n },\n): Promise<void> => {\n if (!script) {\n return\n }\n await executeInPostmanSandbox({\n script,\n response: data.response,\n onTestResultsUpdate: data.onTestResultsUpdate,\n scriptConsole: createConsoleContext(),\n })\n}\n"],"mappings":";;;AAWA,IAAa,4BAA4B,OACvC,QACA,SAIkB;AAClB,KAAI,CAAC,OACH;AAEF,OAAM,wBAAwB;EAC5B;EACA,UAAU,KAAK;EACf,qBAAqB,KAAK;EAC1B,eAAe,sBAAsB;EACtC,CAAC"}
1
+ {"version":3,"file":"execute-post-response-script.js","names":[],"sources":["../../../src/libs/execute-scripts/execute-post-response-script.ts"],"sourcesContent":["import type { RequestFactory, VariablesStore } from '@scalar/workspace-store/request-example'\n\nimport { createConsoleContext } from './context/console'\nimport { executeInPostmanSandbox } from './postman-adapter/sandbox-adapter'\n\nexport type TestResult = {\n title: string\n passed: boolean\n duration: number\n error?: string\n status: 'pending' | 'passed' | 'failed'\n}\n\nexport const executePostResponseScript = async (\n script: string | undefined,\n data: {\n requestBuilder: RequestFactory\n response: Response\n onTestResultsUpdate?: ((results: TestResult[]) => void) | undefined\n variablesStore?: VariablesStore\n },\n): Promise<void> => {\n if (!script) {\n return\n }\n await executeInPostmanSandbox({\n script,\n type: 'post-response',\n context: {\n requestBuilder: data.requestBuilder,\n response: data.response,\n scriptConsole: createConsoleContext(),\n variablesStore: data.variablesStore,\n },\n onTestResultsUpdate: data.onTestResultsUpdate,\n })\n}\n"],"mappings":";;;AAaA,IAAa,4BAA4B,OACvC,QACA,SAMkB;AAClB,KAAI,CAAC,OACH;AAEF,OAAM,wBAAwB;EAC5B;EACA,MAAM;EACN,SAAS;GACP,gBAAgB,KAAK;GACrB,UAAU,KAAK;GACf,eAAe,sBAAsB;GACrC,gBAAgB,KAAK;GACtB;EACD,qBAAqB,KAAK;EAC3B,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { RequestFactory, VariablesStore } from '@scalar/workspace-store/request-example';
2
+ import type { TestResult } from '../../libs/execute-scripts';
3
+ /**
4
+ * Runs the pre-request script in the Postman sandbox with a Postman-shaped
5
+ * `pm.request` built from {@link RequestFactory}. Header and method changes from
6
+ * the script are merged back from the sandbox execution result (the in-memory
7
+ * Postman `Request` on the host is not updated). Variable changes use the store.
8
+ */
9
+ export declare const executePreRequestScript: (script: string | undefined, data: {
10
+ requestBuilder: RequestFactory;
11
+ variablesStore?: VariablesStore;
12
+ onTestResultsUpdate?: ((results: TestResult[]) => void) | undefined;
13
+ }) => Promise<void>;
14
+ //# sourceMappingURL=execute-pre-request-script.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute-pre-request-script.d.ts","sourceRoot":"","sources":["../../../src/libs/execute-scripts/execute-pre-request-script.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAA;AAE7F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAKxD;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,GAClC,QAAQ,MAAM,GAAG,SAAS,EAC1B,MAAM;IACJ,cAAc,EAAE,cAAc,CAAA;IAC9B,cAAc,CAAC,EAAE,cAAc,CAAA;IAC/B,mBAAmB,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,IAAI,CAAC,GAAG,SAAS,CAAA;CACpE,KACA,OAAO,CAAC,IAAI,CAcd,CAAA"}
@@ -0,0 +1,26 @@
1
+ import { createConsoleContext } from "./context/console.js";
2
+ import { executeInPostmanSandbox } from "./postman-adapter/sandbox-adapter.js";
3
+ //#region src/libs/execute-scripts/execute-pre-request-script.ts
4
+ /**
5
+ * Runs the pre-request script in the Postman sandbox with a Postman-shaped
6
+ * `pm.request` built from {@link RequestFactory}. Header and method changes from
7
+ * the script are merged back from the sandbox execution result (the in-memory
8
+ * Postman `Request` on the host is not updated). Variable changes use the store.
9
+ */
10
+ var executePreRequestScript = async (script, data) => {
11
+ if (!script) return;
12
+ await executeInPostmanSandbox({
13
+ script,
14
+ type: "pre-request",
15
+ context: {
16
+ scriptConsole: createConsoleContext(),
17
+ requestBuilder: data.requestBuilder,
18
+ variablesStore: data.variablesStore
19
+ },
20
+ onTestResultsUpdate: data.onTestResultsUpdate
21
+ });
22
+ };
23
+ //#endregion
24
+ export { executePreRequestScript };
25
+
26
+ //# sourceMappingURL=execute-pre-request-script.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute-pre-request-script.js","names":[],"sources":["../../../src/libs/execute-scripts/execute-pre-request-script.ts"],"sourcesContent":["import type { RequestFactory, VariablesStore } from '@scalar/workspace-store/request-example'\n\nimport type { TestResult } from '@/libs/execute-scripts'\n\nimport { createConsoleContext } from './context/console'\nimport { executeInPostmanSandbox } from './postman-adapter/sandbox-adapter'\n\n/**\n * Runs the pre-request script in the Postman sandbox with a Postman-shaped\n * `pm.request` built from {@link RequestFactory}. Header and method changes from\n * the script are merged back from the sandbox execution result (the in-memory\n * Postman `Request` on the host is not updated). Variable changes use the store.\n */\nexport const executePreRequestScript = async (\n script: string | undefined,\n data: {\n requestBuilder: RequestFactory\n variablesStore?: VariablesStore\n onTestResultsUpdate?: ((results: TestResult[]) => void) | undefined\n },\n): Promise<void> => {\n if (!script) {\n return\n }\n await executeInPostmanSandbox({\n script,\n type: 'pre-request',\n context: {\n scriptConsole: createConsoleContext(),\n requestBuilder: data.requestBuilder,\n variablesStore: data.variablesStore,\n },\n onTestResultsUpdate: data.onTestResultsUpdate,\n })\n}\n"],"mappings":";;;;;;;;;AAaA,IAAa,0BAA0B,OACrC,QACA,SAKkB;AAClB,KAAI,CAAC,OACH;AAEF,OAAM,wBAAwB;EAC5B;EACA,MAAM;EACN,SAAS;GACP,eAAe,sBAAsB;GACrC,gBAAgB,KAAK;GACrB,gBAAgB,KAAK;GACtB;EACD,qBAAqB,KAAK;EAC3B,CAAC"}
@@ -1,2 +1,3 @@
1
1
  export { type TestResult, executePostResponseScript } from './execute-post-response-script.js';
2
+ export { executePreRequestScript } from './execute-pre-request-script.js';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/libs/execute-scripts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/libs/execute-scripts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;AAC3F,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAA"}
@@ -0,0 +1,16 @@
1
+ import type { RequestFactory } from '@scalar/workspace-store/request-example';
2
+ import { Request as PostmanRequest } from 'postman-collection';
3
+ /**
4
+ * Builds a Postman Collection {@link PostmanRequest} from a workspace-store
5
+ * {@link RequestFactory} so `pm.request` in the sandbox matches Postman’s shape
6
+ * (method, url, headers, body) as closely as practical.
7
+ *
8
+ * @see https://learning.postman.com/docs/tests-and-scripts/write-scripts/postman-sandbox-reference/pm-request/
9
+ */
10
+ export declare const createPostmanRequestFromFactory: (factory: RequestFactory) => PostmanRequest;
11
+ /**
12
+ * Applies a Postman request definition (e.g. `execution.request` from the sandbox callback after IPC)
13
+ * onto a {@link RequestFactory}. Header and method are copied; URL is not synced to the factory.
14
+ */
15
+ export declare const syncPlainPostmanRequestToRequestFactory: (definition: unknown, factory: RequestFactory) => void;
16
+ //# sourceMappingURL=request-factory-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-factory-adapter.d.ts","sourceRoot":"","sources":["../../../../src/libs/execute-scripts/postman-adapter/request-factory-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAA;AAC7E,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAiE9D;;;;;;GAMG;AACH,eAAO,MAAM,+BAA+B,GAAI,SAAS,cAAc,KAAG,cAiBzE,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,uCAAuC,GAAI,YAAY,OAAO,EAAE,SAAS,cAAc,KAAG,IAUtG,CAAA"}
@@ -0,0 +1,95 @@
1
+ import { Request } from "postman-collection";
2
+ //#region src/libs/execute-scripts/postman-adapter/request-factory-adapter.ts
3
+ var assertSupported = (condition, message) => {
4
+ console.assert(condition, `[Scalar Postman adapter] ${message}`);
5
+ };
6
+ /**
7
+ * Maps Scalar {@link RequestFactory} body data into a Postman Collection request
8
+ * body definition for the sandbox (`pm.request.body`).
9
+ *
10
+ * File/Blob parts are not supported in script context; raw non-string bodies are
11
+ * treated as empty with a console assertion.
12
+ */
13
+ var buildPostmanBodyDefinition = (body) => {
14
+ if (!body) return;
15
+ if (body.mode === "raw") {
16
+ if (typeof body.value === "string") return {
17
+ mode: "raw",
18
+ raw: body.value
19
+ };
20
+ assertSupported(false, "raw body must be a string for pm.request; File/Blob is not supported");
21
+ return {
22
+ mode: "raw",
23
+ raw: ""
24
+ };
25
+ }
26
+ if (body.mode === "urlencoded") return {
27
+ mode: "urlencoded",
28
+ urlencoded: body.value.map(({ key, value }) => ({
29
+ key,
30
+ value
31
+ }))
32
+ };
33
+ if (body.mode === "formdata") {
34
+ if (body.value.filter((item) => item.type !== "text").length > 0) assertSupported(false, "formdata file/blob parts are not supported in pm.request.body for scripts");
35
+ return {
36
+ mode: "formdata",
37
+ formdata: body.value.filter((item) => item.type === "text").map(({ key, value }) => ({
38
+ key,
39
+ type: "text",
40
+ value
41
+ }))
42
+ };
43
+ }
44
+ };
45
+ /**
46
+ * Builds a Postman Collection {@link PostmanRequest} from a workspace-store
47
+ * {@link RequestFactory} so `pm.request` in the sandbox matches Postman’s shape
48
+ * (method, url, headers, body) as closely as practical.
49
+ *
50
+ * @see https://learning.postman.com/docs/tests-and-scripts/write-scripts/postman-sandbox-reference/pm-request/
51
+ */
52
+ var createPostmanRequestFromFactory = (factory) => {
53
+ const headerList = [];
54
+ factory.headers.forEach((value, key) => {
55
+ headerList.push({
56
+ key,
57
+ value
58
+ });
59
+ });
60
+ const bodyDef = buildPostmanBodyDefinition(factory.body);
61
+ return new Request({
62
+ url: factory.baseUrl + factory.path.raw,
63
+ method: factory.method,
64
+ header: headerList,
65
+ body: bodyDef
66
+ });
67
+ };
68
+ /**
69
+ * Applies a Postman request definition (e.g. `execution.request` from the sandbox callback after IPC)
70
+ * onto a {@link RequestFactory}. Header and method are copied; URL is not synced to the factory.
71
+ */
72
+ var syncPlainPostmanRequestToRequestFactory = (definition, factory) => {
73
+ if (definition === null || definition === void 0 || typeof definition !== "object") return;
74
+ try {
75
+ syncPostmanRequestToRequestFactory(new Request(definition), factory);
76
+ } catch {}
77
+ };
78
+ /** Copies header and method from a live {@link PostmanRequest} onto {@link RequestFactory}. */
79
+ var syncPostmanRequestToRequestFactory = (postmanRequest, factory) => {
80
+ const method = postmanRequest.method;
81
+ if (typeof method === "string" && method.length > 0) factory.method = method.toUpperCase();
82
+ const nextHeaders = new Headers();
83
+ postmanRequest.headers?.each((header) => {
84
+ if (header.disabled) return;
85
+ const key = header.key;
86
+ if (key)
87
+ /** `Headers.set` drops prior values for the same name; Postman `headers.add` keeps multiple entries. */
88
+ nextHeaders.append(key, header.value ?? "");
89
+ });
90
+ factory.headers = nextHeaders;
91
+ };
92
+ //#endregion
93
+ export { createPostmanRequestFromFactory, syncPlainPostmanRequestToRequestFactory };
94
+
95
+ //# sourceMappingURL=request-factory-adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-factory-adapter.js","names":[],"sources":["../../../../src/libs/execute-scripts/postman-adapter/request-factory-adapter.ts"],"sourcesContent":["import type { RequestFactory } from '@scalar/workspace-store/request-example'\nimport { Request as PostmanRequest } from 'postman-collection'\n\nconst assertSupported = (condition: boolean, message: string): void => {\n console.assert(condition, `[Scalar Postman adapter] ${message}`)\n}\n\n/**\n * Maps Scalar {@link RequestFactory} body data into a Postman Collection request\n * body definition for the sandbox (`pm.request.body`).\n *\n * File/Blob parts are not supported in script context; raw non-string bodies are\n * treated as empty with a console assertion.\n */\nconst buildPostmanBodyDefinition = (\n body: RequestFactory['body'],\n):\n | {\n mode: string\n raw?: string\n urlencoded?: { key: string; value: string }[]\n formdata?: { key: string; type: string; value: string }[]\n }\n | undefined => {\n if (!body) {\n return undefined\n }\n\n if (body.mode === 'raw') {\n if (typeof body.value === 'string') {\n return { mode: 'raw', raw: body.value }\n }\n assertSupported(false, 'raw body must be a string for pm.request; File/Blob is not supported')\n return { mode: 'raw', raw: '' }\n }\n\n if (body.mode === 'urlencoded') {\n return {\n mode: 'urlencoded',\n urlencoded: body.value.map(({ key, value }) => ({\n key,\n value,\n })),\n }\n }\n\n if (body.mode === 'formdata') {\n const unsupported = body.value.filter((item) => item.type !== 'text')\n if (unsupported.length > 0) {\n assertSupported(false, 'formdata file/blob parts are not supported in pm.request.body for scripts')\n }\n return {\n mode: 'formdata',\n formdata: body.value\n .filter((item): item is { type: 'text'; key: string; value: string } => item.type === 'text')\n .map(({ key, value }) => ({\n key,\n type: 'text',\n value,\n })),\n }\n }\n\n return undefined\n}\n\n/**\n * Builds a Postman Collection {@link PostmanRequest} from a workspace-store\n * {@link RequestFactory} so `pm.request` in the sandbox matches Postman’s shape\n * (method, url, headers, body) as closely as practical.\n *\n * @see https://learning.postman.com/docs/tests-and-scripts/write-scripts/postman-sandbox-reference/pm-request/\n */\nexport const createPostmanRequestFromFactory = (factory: RequestFactory): PostmanRequest => {\n const headerList: { key: string; value: string }[] = []\n factory.headers.forEach((value, key) => {\n headerList.push({\n key,\n value: value,\n })\n })\n\n const bodyDef = buildPostmanBodyDefinition(factory.body)\n\n return new PostmanRequest({\n url: factory.baseUrl + factory.path.raw,\n method: factory.method,\n header: headerList,\n body: bodyDef,\n })\n}\n\n/**\n * Applies a Postman request definition (e.g. `execution.request` from the sandbox callback after IPC)\n * onto a {@link RequestFactory}. Header and method are copied; URL is not synced to the factory.\n */\nexport const syncPlainPostmanRequestToRequestFactory = (definition: unknown, factory: RequestFactory): void => {\n if (definition === null || definition === undefined || typeof definition !== 'object') {\n return\n }\n try {\n const reconstructed = new PostmanRequest(definition as ConstructorParameters<typeof PostmanRequest>[0])\n syncPostmanRequestToRequestFactory(reconstructed, factory)\n } catch {\n /** Malformed payload after teleport; leave factory unchanged. */\n }\n}\n\n/** Copies header and method from a live {@link PostmanRequest} onto {@link RequestFactory}. */\nconst syncPostmanRequestToRequestFactory = (postmanRequest: PostmanRequest, factory: RequestFactory): void => {\n const method = postmanRequest.method\n if (typeof method === 'string' && method.length > 0) {\n factory.method = method.toUpperCase()\n }\n\n const nextHeaders = new Headers()\n postmanRequest.headers?.each((header) => {\n if (header.disabled) {\n return\n }\n const key = header.key\n if (key) {\n /** `Headers.set` drops prior values for the same name; Postman `headers.add` keeps multiple entries. */\n nextHeaders.append(key, header.value ?? '')\n }\n })\n factory.headers = nextHeaders\n}\n"],"mappings":";;AAGA,IAAM,mBAAmB,WAAoB,YAA0B;AACrE,SAAQ,OAAO,WAAW,4BAA4B,UAAU;;;;;;;;;AAUlE,IAAM,8BACJ,SAQe;AACf,KAAI,CAAC,KACH;AAGF,KAAI,KAAK,SAAS,OAAO;AACvB,MAAI,OAAO,KAAK,UAAU,SACxB,QAAO;GAAE,MAAM;GAAO,KAAK,KAAK;GAAO;AAEzC,kBAAgB,OAAO,uEAAuE;AAC9F,SAAO;GAAE,MAAM;GAAO,KAAK;GAAI;;AAGjC,KAAI,KAAK,SAAS,aAChB,QAAO;EACL,MAAM;EACN,YAAY,KAAK,MAAM,KAAK,EAAE,KAAK,aAAa;GAC9C;GACA;GACD,EAAE;EACJ;AAGH,KAAI,KAAK,SAAS,YAAY;AAE5B,MADoB,KAAK,MAAM,QAAQ,SAAS,KAAK,SAAS,OAAO,CACrD,SAAS,EACvB,iBAAgB,OAAO,4EAA4E;AAErG,SAAO;GACL,MAAM;GACN,UAAU,KAAK,MACZ,QAAQ,SAA+D,KAAK,SAAS,OAAO,CAC5F,KAAK,EAAE,KAAK,aAAa;IACxB;IACA,MAAM;IACN;IACD,EAAE;GACN;;;;;;;;;;AAaL,IAAa,mCAAmC,YAA4C;CAC1F,MAAM,aAA+C,EAAE;AACvD,SAAQ,QAAQ,SAAS,OAAO,QAAQ;AACtC,aAAW,KAAK;GACd;GACO;GACR,CAAC;GACF;CAEF,MAAM,UAAU,2BAA2B,QAAQ,KAAK;AAExD,QAAO,IAAI,QAAe;EACxB,KAAK,QAAQ,UAAU,QAAQ,KAAK;EACpC,QAAQ,QAAQ;EAChB,QAAQ;EACR,MAAM;EACP,CAAC;;;;;;AAOJ,IAAa,2CAA2C,YAAqB,YAAkC;AAC7G,KAAI,eAAe,QAAQ,eAAe,KAAA,KAAa,OAAO,eAAe,SAC3E;AAEF,KAAI;AAEF,qCADsB,IAAI,QAAe,WAA8D,EACrD,QAAQ;SACpD;;;AAMV,IAAM,sCAAsC,gBAAgC,YAAkC;CAC5G,MAAM,SAAS,eAAe;AAC9B,KAAI,OAAO,WAAW,YAAY,OAAO,SAAS,EAChD,SAAQ,SAAS,OAAO,aAAa;CAGvC,MAAM,cAAc,IAAI,SAAS;AACjC,gBAAe,SAAS,MAAM,WAAW;AACvC,MAAI,OAAO,SACT;EAEF,MAAM,MAAM,OAAO;AACnB,MAAI;;AAEF,cAAY,OAAO,KAAK,OAAO,SAAS,GAAG;GAE7C;AACF,SAAQ,UAAU"}
@@ -0,0 +1,16 @@
1
+ import type { RequestFactory, VariablesStore } from '@scalar/workspace-store/request-example';
2
+ import type { ConsoleContext } from '../context/console.js';
3
+ import type { TestResult } from '../execute-post-response-script.js';
4
+ export declare const executeInPostmanSandbox: ({ script, type, context: { requestBuilder, response, variablesStore, scriptConsole }, onTestResultsUpdate, }: {
5
+ script: string;
6
+ type: "pre-request" | "post-response";
7
+ context: {
8
+ /** Postman Collection request for `pm.request` (not the browser Fetch API Request). */
9
+ requestBuilder?: RequestFactory;
10
+ response?: Response;
11
+ variablesStore?: VariablesStore;
12
+ scriptConsole: ConsoleContext;
13
+ };
14
+ onTestResultsUpdate?: ((results: TestResult[]) => void) | undefined;
15
+ }) => Promise<VariablesStore | undefined>;
16
+ //# sourceMappingURL=sandbox-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox-adapter.d.ts","sourceRoot":"","sources":["../../../../src/libs/execute-scripts/postman-adapter/sandbox-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAA;AAK7F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAA;AAmEjE,eAAO,MAAM,uBAAuB,GAAU,8GAK3C;IACD,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,aAAa,GAAG,eAAe,CAAA;IACrC,OAAO,EAAE;QACP,uFAAuF;QACvF,cAAc,CAAC,EAAE,cAAc,CAAA;QAC/B,QAAQ,CAAC,EAAE,QAAQ,CAAA;QACnB,cAAc,CAAC,EAAE,cAAc,CAAA;QAC/B,aAAa,EAAE,cAAc,CAAA;KAC9B,CAAA;IACD,mBAAmB,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,IAAI,CAAC,GAAG,SAAS,CAAA;CACpE,KAAG,OAAO,CAAC,cAAc,GAAG,SAAS,CAmHrC,CAAA"}
@@ -1,5 +1,8 @@
1
+ import { toVariableEntries } from "../variables-store.js";
2
+ import { buildSandboxContextFromStore } from "../build-sandbox-context.js";
3
+ import { createPostmanRequestFromFactory, syncPlainPostmanRequestToRequestFactory } from "./request-factory-adapter.js";
1
4
  import Sandbox from "postman-sandbox";
2
- //#region src/libs/execute-scripts/postman-sandbox-adapter.ts
5
+ //#region src/libs/execute-scripts/postman-adapter/sandbox-adapter.ts
3
6
  var toPostmanResponse = async (response) => {
4
7
  const responseText = await response.text();
5
8
  const responseBytes = Array.from(new TextEncoder().encode(responseText));
@@ -45,7 +48,7 @@ var upsertTestResult = (testResults, assertion, duration) => {
45
48
  }
46
49
  testResults[existingResultIndex] = nextResult;
47
50
  };
48
- var executeInPostmanSandbox = async ({ script, response, onTestResultsUpdate, scriptConsole }) => {
51
+ var executeInPostmanSandbox = async ({ script, type, context: { requestBuilder, response, variablesStore, scriptConsole }, onTestResultsUpdate }) => {
49
52
  const testResults = [];
50
53
  let lastAssertionTime = 0;
51
54
  let scriptExecutionStartedAt = 0;
@@ -58,27 +61,58 @@ var executeInPostmanSandbox = async ({ script, response, onTestResultsUpdate, sc
58
61
  });
59
62
  onTestResultsUpdate?.([...testResults]);
60
63
  };
64
+ const variablesContext = variablesStore ? buildSandboxContextFromStore(variablesStore) : void 0;
61
65
  const handleConsole = (_cursor, level, ...args) => {
62
66
  (scriptConsole[level] ?? scriptConsole.log)(...args);
63
67
  };
64
68
  try {
65
69
  sandboxContext.on("execution.assertion", handleAssertion);
66
70
  sandboxContext.on("console", handleConsole);
67
- const postmanResponse = await toPostmanResponse(response);
71
+ const postmanRequest = requestBuilder ? createPostmanRequestFromFactory(requestBuilder) : void 0;
72
+ const postmanResponse = response ? await toPostmanResponse(response) : void 0;
68
73
  scriptExecutionStartedAt = performance.now();
69
74
  lastAssertionTime = scriptExecutionStartedAt;
75
+ /**
76
+ * Lodash `_.has(context, 'response')` is true even when the value is `undefined`,
77
+ * which makes the sandbox run `new Response(undefined)` and breaks `pm.request`.
78
+ * Only set keys that are actually present.
79
+ */
80
+ const context = { ...variablesContext ?? {} };
81
+ if (postmanRequest !== void 0) context.request = postmanRequest;
82
+ if (postmanResponse !== void 0) context.response = postmanResponse;
83
+ /** Pre-request scripts must use the prerequest listener so pm.globals / pm.environment / collection mutations appear on ExecutionResult. */
84
+ const listen = type === "pre-request" ? "prerequest" : "test";
70
85
  await new Promise((resolve) => {
71
86
  sandboxContext.execute({
72
- listen: "test",
87
+ listen,
73
88
  script: { exec: [script] }
74
89
  }, {
75
90
  disableLegacyAPIs: true,
76
- context: { response: postmanResponse }
77
- }, (error) => {
91
+ context
92
+ }, (error, execution) => {
93
+ if (variablesStore && execution) {
94
+ if (execution._variables?.values) {
95
+ const localVariables = toVariableEntries(execution._variables.values);
96
+ variablesStore.setLocalVariables(localVariables);
97
+ }
98
+ if (execution.collectionVariables?.values) {
99
+ const collectionVariables = toVariableEntries(execution.collectionVariables.values);
100
+ variablesStore.setCollectionVariables?.(collectionVariables);
101
+ }
102
+ if (execution.globals?.values) {
103
+ const globals = toVariableEntries(execution.globals.values);
104
+ variablesStore.setGlobals?.(globals);
105
+ }
106
+ if (execution.environment?.values) {
107
+ const environmentVariables = toVariableEntries(execution.environment.values);
108
+ variablesStore.setEnvironment?.(environmentVariables);
109
+ }
110
+ }
111
+ if (!error && type === "pre-request" && requestBuilder && execution?.request !== void 0) syncPlainPostmanRequestToRequestFactory(execution.request, requestBuilder);
78
112
  if (error) {
79
113
  const duration = Number((performance.now() - scriptExecutionStartedAt).toFixed(2));
80
114
  const errorMessage = toErrorMessage(error);
81
- scriptConsole.error(`[Post-Response Script] Error (${duration}ms):`, errorMessage);
115
+ scriptConsole.error(`[${type.toUpperCase()} Script] Error (${duration}ms):`, errorMessage);
82
116
  testResults.push({
83
117
  title: "Script Execution",
84
118
  passed: false,
@@ -96,8 +130,9 @@ var executeInPostmanSandbox = async ({ script, response, onTestResultsUpdate, sc
96
130
  sandboxContext.off("console", handleConsole);
97
131
  sandboxContext.dispose();
98
132
  }
133
+ return variablesStore;
99
134
  };
100
135
  //#endregion
101
136
  export { executeInPostmanSandbox };
102
137
 
103
- //# sourceMappingURL=postman-sandbox-adapter.js.map
138
+ //# sourceMappingURL=sandbox-adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox-adapter.js","names":[],"sources":["../../../../src/libs/execute-scripts/postman-adapter/sandbox-adapter.ts"],"sourcesContent":["import type { RequestFactory, VariablesStore } from '@scalar/workspace-store/request-example'\nimport type { ExecutionResult, SandboxContext } from 'postman-sandbox'\nimport Sandbox from 'postman-sandbox'\n\nimport { buildSandboxContextFromStore } from '../build-sandbox-context'\nimport type { ConsoleContext } from '../context/console'\nimport type { TestResult } from '../execute-post-response-script'\nimport { toVariableEntries } from '../variables-store'\nimport { createPostmanRequestFromFactory, syncPlainPostmanRequestToRequestFactory } from './request-factory-adapter'\n\ntype AssertionEvent = {\n name: string\n index: number\n passed: boolean\n skipped: boolean\n error: { message?: string } | null\n}\n\nconst toPostmanResponse = async (response: Response) => {\n const responseText = await response.text()\n const responseBytes = Array.from(new TextEncoder().encode(responseText))\n\n return {\n code: response.status,\n status: response.statusText || String(response.status),\n header: Array.from(response.headers.entries()).map(([key, value]) => ({ key, value })),\n stream: {\n type: 'Buffer',\n data: responseBytes,\n },\n }\n}\n\nconst createContext = (): Promise<SandboxContext> =>\n new Promise((resolve, reject) => {\n Sandbox.createContext((error: unknown, context: SandboxContext) => {\n if (error) {\n reject(error)\n return\n }\n\n resolve(context)\n })\n })\n\nconst toErrorMessage = (error: unknown): string => {\n if (error && typeof error === 'object' && 'message' in error && typeof error.message === 'string') {\n return error.message\n }\n\n return String(error)\n}\n\nconst upsertTestResult = (testResults: TestResult[], assertion: AssertionEvent, duration: number): void => {\n const title = assertion.name || `Assertion ${assertion.index + 1}`\n\n const nextResult: TestResult = {\n title,\n passed: assertion.passed,\n duration,\n error: assertion.error?.message,\n status: assertion.passed ? 'passed' : 'failed',\n }\n\n const existingResultIndex = testResults.findIndex((result) => result.title === title)\n if (existingResultIndex === -1) {\n testResults.push(nextResult)\n return\n }\n\n testResults[existingResultIndex] = nextResult\n}\n\nexport const executeInPostmanSandbox = async ({\n script,\n type,\n context: { requestBuilder, response, variablesStore, scriptConsole },\n onTestResultsUpdate,\n}: {\n script: string\n type: 'pre-request' | 'post-response'\n context: {\n /** Postman Collection request for `pm.request` (not the browser Fetch API Request). */\n requestBuilder?: RequestFactory\n response?: Response\n variablesStore?: VariablesStore\n scriptConsole: ConsoleContext\n }\n onTestResultsUpdate?: ((results: TestResult[]) => void) | undefined\n}): Promise<VariablesStore | undefined> => {\n const testResults: TestResult[] = []\n let lastAssertionTime = 0\n let scriptExecutionStartedAt = 0\n const sandboxContext = await createContext()\n\n const handleAssertion = (_cursor: unknown, assertions: AssertionEvent[]) => {\n assertions.forEach((assertion) => {\n const duration = Number((performance.now() - lastAssertionTime).toFixed(2))\n lastAssertionTime = performance.now()\n upsertTestResult(testResults, assertion, duration)\n })\n onTestResultsUpdate?.([...testResults])\n }\n\n const variablesContext = variablesStore ? buildSandboxContextFromStore(variablesStore) : undefined\n\n const handleConsole = (_cursor: unknown, level: keyof ConsoleContext, ...args: unknown[]) => {\n const consoleMethod = scriptConsole[level] ?? scriptConsole.log\n ;(consoleMethod as (...params: unknown[]) => void)(...args)\n }\n\n try {\n sandboxContext.on('execution.assertion', handleAssertion)\n sandboxContext.on('console', handleConsole)\n\n const postmanRequest = requestBuilder ? createPostmanRequestFromFactory(requestBuilder) : undefined\n const postmanResponse = response ? await toPostmanResponse(response) : undefined\n\n scriptExecutionStartedAt = performance.now()\n lastAssertionTime = scriptExecutionStartedAt\n\n /**\n * Lodash `_.has(context, 'response')` is true even when the value is `undefined`,\n * which makes the sandbox run `new Response(undefined)` and breaks `pm.request`.\n * Only set keys that are actually present.\n */\n const context: Record<string, unknown> = {\n ...(variablesContext ?? {}),\n }\n\n // We need to pass the postman request to the sandbox so it can be mutated by the script.\n if (postmanRequest !== undefined) {\n context.request = postmanRequest\n }\n // We need to pass the postman response to the sandbox so it can be used by the script.\n if (postmanResponse !== undefined) {\n context.response = postmanResponse\n }\n\n /** Pre-request scripts must use the prerequest listener so pm.globals / pm.environment / collection mutations appear on ExecutionResult. */\n const listen = type === 'pre-request' ? 'prerequest' : 'test'\n\n await new Promise<void>((resolve) => {\n sandboxContext.execute(\n {\n listen,\n script: {\n exec: [script],\n },\n },\n {\n disableLegacyAPIs: true,\n context,\n },\n (error: unknown, execution?: ExecutionResult) => {\n if (variablesStore && execution) {\n if (execution._variables?.values) {\n const localVariables = toVariableEntries(execution._variables.values)\n variablesStore.setLocalVariables(localVariables)\n }\n if (execution.collectionVariables?.values) {\n const collectionVariables = toVariableEntries(execution.collectionVariables.values)\n variablesStore.setCollectionVariables?.(collectionVariables)\n }\n if (execution.globals?.values) {\n const globals = toVariableEntries(execution.globals.values)\n variablesStore.setGlobals?.(globals)\n }\n if (execution.environment?.values) {\n const environmentVariables = toVariableEntries(execution.environment.values)\n variablesStore.setEnvironment?.(environmentVariables)\n }\n }\n\n if (!error && type === 'pre-request' && requestBuilder && execution?.request !== undefined) {\n syncPlainPostmanRequestToRequestFactory(execution.request, requestBuilder)\n }\n if (error) {\n const duration = Number((performance.now() - scriptExecutionStartedAt).toFixed(2))\n const errorMessage = toErrorMessage(error)\n\n scriptConsole.error(`[${type.toUpperCase()} Script] Error (${duration}ms):`, errorMessage)\n\n testResults.push({\n title: 'Script Execution',\n passed: false,\n duration,\n error: errorMessage,\n status: 'failed',\n })\n onTestResultsUpdate?.([...testResults])\n }\n\n resolve()\n },\n )\n })\n } finally {\n sandboxContext.off('execution.assertion', handleAssertion)\n sandboxContext.off('console', handleConsole)\n sandboxContext.dispose()\n }\n\n return variablesStore\n}\n"],"mappings":"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"}
@@ -0,0 +1,22 @@
1
+ import type { VariableEntry, VariablesStore } from '@scalar/workspace-store/request-example';
2
+ /**
3
+ * Converts a VariablesStore into key-value arrays per scope for building
4
+ * the Postman sandbox context (e.g. with postman-collection VariableScope).
5
+ */
6
+ export declare function getVariableScopesFromStore(store: VariablesStore): {
7
+ environment: VariableEntry[];
8
+ globals: VariableEntry[];
9
+ collectionVariables: VariableEntry[];
10
+ data: Record<string, string>;
11
+ local: VariableEntry[];
12
+ };
13
+ /**
14
+ * Parses the sandbox execution result’s _variables (array of { key, value, type })
15
+ * into a key-value record and calls store.setLocalVariables.
16
+ */
17
+ export declare const toVariableEntries: (values: Array<{
18
+ key: string;
19
+ value: string;
20
+ type?: string;
21
+ }> | undefined) => VariableEntry[];
22
+ //# sourceMappingURL=variables-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"variables-store.d.ts","sourceRoot":"","sources":["../../../src/libs/execute-scripts/variables-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAA;AAS5F;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,cAAc,GAAG;IACjE,WAAW,EAAE,aAAa,EAAE,CAAA;IAC5B,OAAO,EAAE,aAAa,EAAE,CAAA;IACxB,mBAAmB,EAAE,aAAa,EAAE,CAAA;IACpC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC5B,KAAK,EAAE,aAAa,EAAE,CAAA;CACvB,CAQA;AAED;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAC5B,QAAQ,KAAK,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,SAAS,KACvE,aAAa,EAKf,CAAA"}
@@ -0,0 +1,36 @@
1
+ //#region src/libs/execute-scripts/variables-store.ts
2
+ function toKeyValueArray(input) {
3
+ if (Array.isArray(input)) return input;
4
+ return Object.entries(input).map(([key, value]) => ({
5
+ key,
6
+ value
7
+ }));
8
+ }
9
+ /**
10
+ * Converts a VariablesStore into key-value arrays per scope for building
11
+ * the Postman sandbox context (e.g. with postman-collection VariableScope).
12
+ */
13
+ function getVariableScopesFromStore(store) {
14
+ return {
15
+ environment: toKeyValueArray(store.getEnvironment()),
16
+ globals: toKeyValueArray(store.getGlobals()),
17
+ collectionVariables: toKeyValueArray(store.getCollectionVariables()),
18
+ data: store.getData(),
19
+ local: toKeyValueArray(store.getLocalVariables())
20
+ };
21
+ }
22
+ /**
23
+ * Parses the sandbox execution result’s _variables (array of { key, value, type })
24
+ * into a key-value record and calls store.setLocalVariables.
25
+ */
26
+ var toVariableEntries = (values) => {
27
+ if (!values?.length) return [];
28
+ return values.map((v) => ({
29
+ key: v.key,
30
+ value: v.value
31
+ }));
32
+ };
33
+ //#endregion
34
+ export { getVariableScopesFromStore, toVariableEntries };
35
+
36
+ //# sourceMappingURL=variables-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"variables-store.js","names":[],"sources":["../../../src/libs/execute-scripts/variables-store.ts"],"sourcesContent":["import type { VariableEntry, VariablesStore } from '@scalar/workspace-store/request-example'\n\nfunction toKeyValueArray(input: VariableEntry[] | Record<string, string>): VariableEntry[] {\n if (Array.isArray(input)) {\n return input\n }\n return Object.entries(input).map(([key, value]) => ({ key, value }))\n}\n\n/**\n * Converts a VariablesStore into key-value arrays per scope for building\n * the Postman sandbox context (e.g. with postman-collection VariableScope).\n */\nexport function getVariableScopesFromStore(store: VariablesStore): {\n environment: VariableEntry[]\n globals: VariableEntry[]\n collectionVariables: VariableEntry[]\n data: Record<string, string>\n local: VariableEntry[]\n} {\n return {\n environment: toKeyValueArray(store.getEnvironment()),\n globals: toKeyValueArray(store.getGlobals()),\n collectionVariables: toKeyValueArray(store.getCollectionVariables()),\n data: store.getData(),\n local: toKeyValueArray(store.getLocalVariables()),\n }\n}\n\n/**\n * Parses the sandbox execution result’s _variables (array of { key, value, type })\n * into a key-value record and calls store.setLocalVariables.\n */\nexport const toVariableEntries = (\n values: Array<{ key: string; value: string; type?: string }> | undefined,\n): VariableEntry[] => {\n if (!values?.length) {\n return []\n }\n return values.map((v) => ({ key: v.key, value: v.value }))\n}\n"],"mappings":";AAEA,SAAS,gBAAgB,OAAkE;AACzF,KAAI,MAAM,QAAQ,MAAM,CACtB,QAAO;AAET,QAAO,OAAO,QAAQ,MAAM,CAAC,KAAK,CAAC,KAAK,YAAY;EAAE;EAAK;EAAO,EAAE;;;;;;AAOtE,SAAgB,2BAA2B,OAMzC;AACA,QAAO;EACL,aAAa,gBAAgB,MAAM,gBAAgB,CAAC;EACpD,SAAS,gBAAgB,MAAM,YAAY,CAAC;EAC5C,qBAAqB,gBAAgB,MAAM,wBAAwB,CAAC;EACpE,MAAM,MAAM,SAAS;EACrB,OAAO,gBAAgB,MAAM,mBAAmB,CAAC;EAClD;;;;;;AAOH,IAAa,qBACX,WACoB;AACpB,KAAI,CAAC,QAAQ,OACX,QAAO,EAAE;AAEX,QAAO,OAAO,KAAK,OAAO;EAAE,KAAK,EAAE;EAAK,OAAO,EAAE;EAAO,EAAE"}
@@ -0,0 +1,2 @@
1
+ export { requestScriptsPlugin } from './request-scripts/request-scripts-plugin.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAA"}
@@ -0,0 +1,2 @@
1
+ import { requestScriptsPlugin } from "./request-scripts/request-scripts-plugin.js";
2
+ export { requestScriptsPlugin };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExampleScripts.vue.d.ts","sourceRoot":"","sources":["../../../../src/plugins/request-scripts/components/ExampleScripts.vue"],"names":[],"mappings":"AA0CA,KAAK,WAAW,GAAG;IACjB,UAAU,EAAE,MAAM,CAAA;CACnB,CAAC;AA6EF,QAAA,MAAM,YAAY;;;;kFAGhB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
@@ -1,5 +1,5 @@
1
1
  import ExampleScripts_vue_vue_type_script_setup_true_lang_default from "./ExampleScripts.vue.script.js";
2
- //#region src/plugins/post-response-scripts/components/PostResponseScripts/ExampleScripts.vue
2
+ //#region src/plugins/request-scripts/components/ExampleScripts.vue
3
3
  var ExampleScripts_default = ExampleScripts_vue_vue_type_script_setup_true_lang_default;
4
4
  //#endregion
5
5
  export { ExampleScripts_default as default };