@flowrunner/cli 0.1.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 (460) hide show
  1. package/README.md +148 -0
  2. package/ai-docs/instructions/service-code-format/01-service-structure.md +180 -0
  3. package/ai-docs/instructions/service-code-format/02-zod-types.md +260 -0
  4. package/ai-docs/instructions/service-code-format/03-parameters.md +193 -0
  5. package/ai-docs/instructions/service-code-format/04-http-requests.md +257 -0
  6. package/ai-docs/instructions/service-code-format/05-dictionaries.md +103 -0
  7. package/ai-docs/instructions/service-code-format/06-oauth2.md +42 -0
  8. package/ai-docs/instructions/service-code-format/07-actions.md +171 -0
  9. package/ai-docs/instructions/service-code-format/08-polling-triggers.md +54 -0
  10. package/ai-docs/instructions/service-code-format/09-realtime-triggers.md +269 -0
  11. package/ai-docs/instructions/service-code-format/10-files-api.md +148 -0
  12. package/ai-docs/instructions/service-code-format/11-output-model.md +142 -0
  13. package/ai-docs/instructions/service-code-format/12-service-readme.md +69 -0
  14. package/ai-docs/instructions/service-code-format/13-runtime-contracts.md +193 -0
  15. package/ai-docs/instructions/service-code-format/14-reference-service.md +341 -0
  16. package/ai-docs/instructions/service-code-format/15-unit-tests.md +361 -0
  17. package/ai-docs/instructions/service-code-format/16-gotchas.md +201 -0
  18. package/ai-docs/instructions/service-code-format/17-client-certificates.md +162 -0
  19. package/ai-docs/instructions/service-code-format/18-test-recipes.md +160 -0
  20. package/ai-docs/instructions/service-code-format/README.md +120 -0
  21. package/ai-docs/providers/claude/agents/flowrunner-service-code-engineer.md +139 -0
  22. package/ai-docs/providers/claude/agents/flowrunner-service-test-engineer.md +497 -0
  23. package/ai-docs/providers/claude/main-orchestrator-segment.md +51 -0
  24. package/bin/flowrunner.js +66 -0
  25. package/bin/resolve-local.js +98 -0
  26. package/dist/cli.js +10972 -0
  27. package/dist/cli.js.map +7 -0
  28. package/dist/index.d.ts +2 -0
  29. package/dist/index.js +10131 -0
  30. package/dist/index.js.map +7 -0
  31. package/dist/types/flow-extension-runner/src/common/config.d.ts +12 -0
  32. package/dist/types/flow-extension-runner/src/common/constants.d.ts +9 -0
  33. package/dist/types/flow-extension-runner/src/common/context-files.d.ts +107 -0
  34. package/dist/types/flow-extension-runner/src/common/context.d.ts +6 -0
  35. package/dist/types/flow-extension-runner/src/common/types.d.ts +11 -0
  36. package/dist/types/flow-extension-runner/src/errors/base.d.ts +17 -0
  37. package/dist/types/flow-extension-runner/src/errors/codes.d.ts +17 -0
  38. package/dist/types/flow-extension-runner/src/errors/errors.d.ts +48 -0
  39. package/dist/types/flow-extension-runner/src/errors/index.d.ts +3 -0
  40. package/dist/types/flow-extension-runner/src/global.d.ts +34 -0
  41. package/dist/types/flow-extension-runner/src/index.d.ts +15 -0
  42. package/dist/types/flow-extension-runner/src/namespace.d.ts +3 -0
  43. package/dist/types/flow-extension-runner/src/v1/config.d.ts +3 -0
  44. package/dist/types/flow-extension-runner/src/v1/constants.d.ts +4 -0
  45. package/dist/types/flow-extension-runner/src/v1/index.d.ts +11 -0
  46. package/dist/types/flow-extension-runner/src/v1/namespace.d.ts +9 -0
  47. package/dist/types/flow-extension-runner/src/v1/service.d.ts +29 -0
  48. package/dist/types/flow-extension-runner/src/v1/types.d.ts +13 -0
  49. package/dist/types/flow-extension-runner/src/v2/actions/action-method.d.ts +34 -0
  50. package/dist/types/flow-extension-runner/src/v2/context/execution-context.d.ts +25 -0
  51. package/dist/types/flow-extension-runner/src/v2/context/logger.d.ts +2 -0
  52. package/dist/types/flow-extension-runner/src/v2/context/method-input.d.ts +27 -0
  53. package/dist/types/flow-extension-runner/src/v2/context/proxies.d.ts +1 -0
  54. package/dist/types/flow-extension-runner/src/v2/create-extension.d.ts +2 -0
  55. package/dist/types/flow-extension-runner/src/v2/crypto.d.ts +6 -0
  56. package/dist/types/flow-extension-runner/src/v2/dictionaries/dictionary-method.d.ts +24 -0
  57. package/dist/types/flow-extension-runner/src/v2/dictionaries/payload-schema.d.ts +10 -0
  58. package/dist/types/flow-extension-runner/src/v2/extension.d.ts +51 -0
  59. package/dist/types/flow-extension-runner/src/v2/index.d.ts +39 -0
  60. package/dist/types/flow-extension-runner/src/v2/loaders/loader-method.d.ts +31 -0
  61. package/dist/types/flow-extension-runner/src/v2/loaders/loader-owner.d.ts +17 -0
  62. package/dist/types/flow-extension-runner/src/v2/loaders/payload-schema.d.ts +3 -0
  63. package/dist/types/flow-extension-runner/src/v2/method.d.ts +22 -0
  64. package/dist/types/flow-extension-runner/src/v2/model/field-mapper.d.ts +10 -0
  65. package/dist/types/flow-extension-runner/src/v2/model/method-model.d.ts +3 -0
  66. package/dist/types/flow-extension-runner/src/v2/model/model-types.d.ts +70 -0
  67. package/dist/types/flow-extension-runner/src/v2/model/params-model.d.ts +16 -0
  68. package/dist/types/flow-extension-runner/src/v2/oauth/method-names.d.ts +5 -0
  69. package/dist/types/flow-extension-runner/src/v2/oauth/oauth2.d.ts +9 -0
  70. package/dist/types/flow-extension-runner/src/v2/oauth/system-params.d.ts +6 -0
  71. package/dist/types/flow-extension-runner/src/v2/oauth/types.d.ts +54 -0
  72. package/dist/types/flow-extension-runner/src/v2/params/config-params.d.ts +14 -0
  73. package/dist/types/flow-extension-runner/src/v2/params/files-options.d.ts +58 -0
  74. package/dist/types/flow-extension-runner/src/v2/params/index.d.ts +19 -0
  75. package/dist/types/flow-extension-runner/src/v2/params/json/checks.d.ts +26 -0
  76. package/dist/types/flow-extension-runner/src/v2/params/json/decode.d.ts +24 -0
  77. package/dist/types/flow-extension-runner/src/v2/params/json/encode.d.ts +20 -0
  78. package/dist/types/flow-extension-runner/src/v2/params/json/types.d.ts +86 -0
  79. package/dist/types/flow-extension-runner/src/v2/params/json/values.d.ts +5 -0
  80. package/dist/types/flow-extension-runner/src/v2/params/method-params.d.ts +17 -0
  81. package/dist/types/flow-extension-runner/src/v2/params/params.d.ts +26 -0
  82. package/dist/types/flow-extension-runner/src/v2/params/schema/assert-object-schema.d.ts +6 -0
  83. package/dist/types/flow-extension-runner/src/v2/params/schema/assert-supported-schema.d.ts +8 -0
  84. package/dist/types/flow-extension-runner/src/v2/params/schema/coerce.d.ts +54 -0
  85. package/dist/types/flow-extension-runner/src/v2/params/schema/dates.d.ts +40 -0
  86. package/dist/types/flow-extension-runner/src/v2/params/schema/defaults.d.ts +36 -0
  87. package/dist/types/flow-extension-runner/src/v2/params/schema/field-plan.d.ts +33 -0
  88. package/dist/types/flow-extension-runner/src/v2/params/schema/introspect.d.ts +58 -0
  89. package/dist/types/flow-extension-runner/src/v2/params/schema/labels.d.ts +3 -0
  90. package/dist/types/flow-extension-runner/src/v2/params/schema/messages.d.ts +16 -0
  91. package/dist/types/flow-extension-runner/src/v2/params/schema/normalize.d.ts +8 -0
  92. package/dist/types/flow-extension-runner/src/v2/params/schema/parse.d.ts +7 -0
  93. package/dist/types/flow-extension-runner/src/v2/params/types.d.ts +29 -0
  94. package/dist/types/flow-extension-runner/src/v2/params/widget-types.d.ts +40 -0
  95. package/dist/types/flow-extension-runner/src/v2/params/zod.d.ts +86 -0
  96. package/dist/types/flow-extension-runner/src/v2/path.d.ts +1 -0
  97. package/dist/types/flow-extension-runner/src/v2/polling-triggers/mechanisms.d.ts +19 -0
  98. package/dist/types/flow-extension-runner/src/v2/polling-triggers/method-names.d.ts +1 -0
  99. package/dist/types/flow-extension-runner/src/v2/polling-triggers/polling-triggers.d.ts +11 -0
  100. package/dist/types/flow-extension-runner/src/v2/polling-triggers/system-params.d.ts +7 -0
  101. package/dist/types/flow-extension-runner/src/v2/polling-triggers/trigger-method.d.ts +25 -0
  102. package/dist/types/flow-extension-runner/src/v2/polling-triggers/types.d.ts +46 -0
  103. package/dist/types/flow-extension-runner/src/v2/realtime-triggers/method-names.d.ts +7 -0
  104. package/dist/types/flow-extension-runner/src/v2/realtime-triggers/realtime-setup.d.ts +10 -0
  105. package/dist/types/flow-extension-runner/src/v2/realtime-triggers/system-params.d.ts +29 -0
  106. package/dist/types/flow-extension-runner/src/v2/realtime-triggers/trigger-method.d.ts +33 -0
  107. package/dist/types/flow-extension-runner/src/v2/realtime-triggers/types.d.ts +147 -0
  108. package/dist/types/flow-extension-runner/src/v2/realtime-triggers/verify.d.ts +2 -0
  109. package/dist/types/flow-extension-runner/src/v2/registry.d.ts +20 -0
  110. package/dist/types/flow-extension-runner/src/v2/result.d.ts +13 -0
  111. package/dist/types/flow-extension-runner/src/v2/system-method.d.ts +41 -0
  112. package/dist/types/flow-extension-runner/src/v2/types.d.ts +126 -0
  113. package/dist/types/jsdoc-parser/src/custom-type-defs/files.d.ts +2 -0
  114. package/dist/types/jsdoc-parser/src/index.d.ts +2 -0
  115. package/dist/types/jsdoc-parser/src/lib.d.ts +42 -0
  116. package/dist/types/jsdoc-parser/src/types.d.ts +2 -0
  117. package/dist/types/packages/cli/src/api/console-client.d.ts +69 -0
  118. package/dist/types/packages/cli/src/constants/index.d.ts +5 -0
  119. package/dist/types/packages/cli/src/constants/packaging.d.ts +7 -0
  120. package/dist/types/packages/cli/src/constants/project.d.ts +9 -0
  121. package/dist/types/packages/cli/src/constants/providers.d.ts +30 -0
  122. package/dist/types/packages/cli/src/constants/server.d.ts +29 -0
  123. package/dist/types/packages/cli/src/constants/testing.d.ts +32 -0
  124. package/dist/types/packages/cli/src/errors.d.ts +131 -0
  125. package/dist/types/packages/cli/src/index.d.ts +29 -0
  126. package/dist/types/packages/cli/src/operations/deploy/discover-services.d.ts +26 -0
  127. package/dist/types/packages/cli/src/operations/deploy/hash.d.ts +1 -0
  128. package/dist/types/packages/cli/src/operations/deploy/index.d.ts +94 -0
  129. package/dist/types/packages/cli/src/operations/deploy/public-files.d.ts +20 -0
  130. package/dist/types/packages/cli/src/operations/deploy/select.d.ts +9 -0
  131. package/dist/types/packages/cli/src/operations/deploy/zip.d.ts +1 -0
  132. package/dist/types/packages/cli/src/operations/init/answers.d.ts +35 -0
  133. package/dist/types/packages/cli/src/operations/init/create-service.d.ts +39 -0
  134. package/dist/types/packages/cli/src/operations/init/index.d.ts +79 -0
  135. package/dist/types/packages/cli/src/operations/init/testing.d.ts +13 -0
  136. package/dist/types/packages/cli/src/operations/init-claude/index.d.ts +40 -0
  137. package/dist/types/packages/cli/src/operations/init-claude/segment.d.ts +25 -0
  138. package/dist/types/packages/cli/src/operations/login.d.ts +38 -0
  139. package/dist/types/packages/cli/src/operations/logout.d.ts +19 -0
  140. package/dist/types/packages/cli/src/operations/pull/extract.d.ts +23 -0
  141. package/dist/types/packages/cli/src/operations/pull/index.d.ts +87 -0
  142. package/dist/types/packages/cli/src/operations/server-target.d.ts +14 -0
  143. package/dist/types/packages/cli/src/operations/types.d.ts +20 -0
  144. package/dist/types/packages/cli/src/operations/use-server.d.ts +17 -0
  145. package/dist/types/packages/cli/src/project/auth.d.ts +41 -0
  146. package/dist/types/packages/cli/src/project/config.d.ts +31 -0
  147. package/dist/types/packages/cli/src/project/token.d.ts +5 -0
  148. package/dist/types/packages/cli/src/server/index.d.ts +14 -0
  149. package/dist/types/packages/cli/src/server/pages.d.ts +2 -0
  150. package/dist/types/packages/cli/src/server/routes/callback.d.ts +6 -0
  151. package/dist/types/packages/cli/src/server/types.d.ts +12 -0
  152. package/dist/types/packages/cli/src/templates/index.d.ts +8 -0
  153. package/dist/types/packages/cli/src/templates/manifest.d.ts +97 -0
  154. package/dist/types/packages/cli/src/templates/package-root.d.ts +3 -0
  155. package/dist/types/packages/cli/src/templates/paths.d.ts +3 -0
  156. package/dist/types/packages/cli/src/templates/registry.d.ts +13 -0
  157. package/dist/types/packages/cli/src/templates/render.d.ts +13 -0
  158. package/dist/types/packages/cli/src/templates/scaffold.d.ts +25 -0
  159. package/dist/types/packages/cli/src/utils/invocation.d.ts +28 -0
  160. package/dist/types/packages/cli/src/utils/open-browser.d.ts +2 -0
  161. package/dist/types/shared/src/constants/ai-agent-tools.d.ts +20 -0
  162. package/dist/types/shared/src/constants/ai.d.ts +11 -0
  163. package/dist/types/shared/src/constants/api-keys.d.ts +1 -0
  164. package/dist/types/shared/src/constants/app.d.ts +58 -0
  165. package/dist/types/shared/src/constants/billing.d.ts +16 -0
  166. package/dist/types/shared/src/constants/compliances.d.ts +3 -0
  167. package/dist/types/shared/src/constants/data-types.d.ts +26 -0
  168. package/dist/types/shared/src/constants/error-codes.d.ts +16 -0
  169. package/dist/types/shared/src/constants/flow.d.ts +12 -0
  170. package/dist/types/shared/src/constants/index.d.ts +16 -0
  171. package/dist/types/shared/src/constants/knowledge-base.d.ts +13 -0
  172. package/dist/types/shared/src/constants/notification-types.d.ts +985 -0
  173. package/dist/types/shared/src/constants/notifications.d.ts +10 -0
  174. package/dist/types/shared/src/constants/patterns.d.ts +28 -0
  175. package/dist/types/shared/src/constants/retry-policy.d.ts +30 -0
  176. package/dist/types/shared/src/constants/severity.d.ts +9 -0
  177. package/dist/types/shared/src/constants/shared-extensions-search.d.ts +6 -0
  178. package/dist/types/shared/src/constants/shared-extensions.d.ts +35 -0
  179. package/dist/types/shared/src/constants/zod.d.ts +2 -0
  180. package/dist/types/shared/src/errors/api.d.ts +4 -0
  181. package/dist/types/shared/src/errors/base.d.ts +38 -0
  182. package/dist/types/shared/src/errors/common.d.ts +39 -0
  183. package/dist/types/shared/src/errors/index.d.ts +13 -0
  184. package/dist/types/shared/src/errors/k8s.d.ts +4 -0
  185. package/dist/types/shared/src/errors/message.d.ts +48 -0
  186. package/dist/types/shared/src/errors/open-search.d.ts +4 -0
  187. package/dist/types/shared/src/errors/s3.d.ts +11 -0
  188. package/dist/types/shared/src/extensions/zod.d.ts +25 -0
  189. package/dist/types/shared/src/scheme/account/dto.d.ts +60 -0
  190. package/dist/types/shared/src/scheme/account/index.d.ts +1 -0
  191. package/dist/types/shared/src/scheme/ai-agent-tools/dto.d.ts +69 -0
  192. package/dist/types/shared/src/scheme/ai-agent-tools/index.d.ts +2 -0
  193. package/dist/types/shared/src/scheme/ai-agent-tools/parameters.d.ts +7 -0
  194. package/dist/types/shared/src/scheme/ai-router/dto.d.ts +23 -0
  195. package/dist/types/shared/src/scheme/ai-router/index.d.ts +2 -0
  196. package/dist/types/shared/src/scheme/api-keys/dto.d.ts +28 -0
  197. package/dist/types/shared/src/scheme/api-keys/index.d.ts +2 -0
  198. package/dist/types/shared/src/scheme/app/index.d.ts +1 -0
  199. package/dist/types/shared/src/scheme/app/java.dto.d.ts +6 -0
  200. package/dist/types/shared/src/scheme/billing/index.d.ts +1 -0
  201. package/dist/types/shared/src/scheme/billing/java.dto.d.ts +163 -0
  202. package/dist/types/shared/src/scheme/crm/billing.d.ts +149 -0
  203. package/dist/types/shared/src/scheme/crm/dto.d.ts +212 -0
  204. package/dist/types/shared/src/scheme/crm/index.d.ts +3 -0
  205. package/dist/types/shared/src/scheme/data-types/index.d.ts +1 -0
  206. package/dist/types/shared/src/scheme/data-types/java.dto.d.ts +23 -0
  207. package/dist/types/shared/src/scheme/dynamic-forms/dto.d.ts +30 -0
  208. package/dist/types/shared/src/scheme/dynamic-forms/index.d.ts +2 -0
  209. package/dist/types/shared/src/scheme/extensions/index.d.ts +1 -0
  210. package/dist/types/shared/src/scheme/extensions/params-to-zod.d.ts +14 -0
  211. package/dist/types/shared/src/scheme/flowrunner/custom-elements.d.ts +368 -0
  212. package/dist/types/shared/src/scheme/flowrunner/index.d.ts +3 -0
  213. package/dist/types/shared/src/scheme/flowrunner/java.dto.d.ts +628 -0
  214. package/dist/types/shared/src/scheme/index.d.ts +19 -0
  215. package/dist/types/shared/src/scheme/integration-connection/dto.d.ts +81 -0
  216. package/dist/types/shared/src/scheme/integration-connection/index.d.ts +2 -0
  217. package/dist/types/shared/src/scheme/knowledge-base/dto.d.ts +540 -0
  218. package/dist/types/shared/src/scheme/knowledge-base/index.d.ts +2 -0
  219. package/dist/types/shared/src/scheme/mcp-oauth/dto.d.ts +7 -0
  220. package/dist/types/shared/src/scheme/mcp-oauth/index.d.ts +2 -0
  221. package/dist/types/shared/src/scheme/notifications/dto.d.ts +111 -0
  222. package/dist/types/shared/src/scheme/notifications/index.d.ts +3 -0
  223. package/dist/types/shared/src/scheme/notifications/rest.d.ts +148 -0
  224. package/dist/types/shared/src/scheme/properties/account.d.ts +3 -0
  225. package/dist/types/shared/src/scheme/properties/app.d.ts +5 -0
  226. package/dist/types/shared/src/scheme/properties/billing.d.ts +12 -0
  227. package/dist/types/shared/src/scheme/properties/common.d.ts +2 -0
  228. package/dist/types/shared/src/scheme/properties/db.d.ts +8 -0
  229. package/dist/types/shared/src/scheme/properties/flow-extensions.d.ts +7 -0
  230. package/dist/types/shared/src/scheme/properties/index.d.ts +7 -0
  231. package/dist/types/shared/src/scheme/remote-mcp-server/dto.d.ts +278 -0
  232. package/dist/types/shared/src/scheme/remote-mcp-server/index.d.ts +2 -0
  233. package/dist/types/shared/src/scheme/shared-extensions/base.d.ts +56 -0
  234. package/dist/types/shared/src/scheme/shared-extensions/config.d.ts +96 -0
  235. package/dist/types/shared/src/scheme/shared-extensions/custom-extensions.d.ts +485 -0
  236. package/dist/types/shared/src/scheme/shared-extensions/extension.d.ts +387 -0
  237. package/dist/types/shared/src/scheme/shared-extensions/flow-extensions.d.ts +64 -0
  238. package/dist/types/shared/src/scheme/shared-extensions/index.d.ts +15 -0
  239. package/dist/types/shared/src/scheme/shared-extensions/light.d.ts +38 -0
  240. package/dist/types/shared/src/scheme/shared-extensions/logs.d.ts +21 -0
  241. package/dist/types/shared/src/scheme/shared-extensions/methods.d.ts +80 -0
  242. package/dist/types/shared/src/scheme/shared-extensions/params-schema.d.ts +47 -0
  243. package/dist/types/shared/src/scheme/shared-extensions/popular-pool.d.ts +11 -0
  244. package/dist/types/shared/src/scheme/shared-extensions/resolve.d.ts +364 -0
  245. package/dist/types/shared/src/scheme/shared-extensions/rest.d.ts +9 -0
  246. package/dist/types/shared/src/scheme/shared-extensions/search.d.ts +177 -0
  247. package/dist/types/shared/src/scheme/shared-extensions/service-identity.d.ts +10 -0
  248. package/dist/types/shared/src/scheme/shared-extensions/service-info.d.ts +15 -0
  249. package/dist/types/shared/src/scheme/workspace/dto.d.ts +40 -0
  250. package/dist/types/shared/src/scheme/workspace/index.d.ts +1 -0
  251. package/dist/types/shared/src/utils/object.d.ts +8 -0
  252. package/dist/types/shared/src/utils/uuid.d.ts +5 -0
  253. package/dist/types/shared/src/utils/versions.d.ts +4 -0
  254. package/dist/types/types/backendless-request.d.ts +40 -0
  255. package/package.json +66 -0
  256. package/project-files/jest.config.js +38 -0
  257. package/project-files/jest.setup.js +24 -0
  258. package/project-files/sandbox/files-mock.js +654 -0
  259. package/project-files/sandbox/index.js +32 -0
  260. package/project-files/sandbox/nock-mock.js +600 -0
  261. package/project-files/sandbox/service.js +145 -0
  262. package/runtime/index.d.ts +2 -0
  263. package/runtime/index.js +5665 -0
  264. package/runtime/index.js.map +7 -0
  265. package/runtime/types/flow-extension-runner/src/common/config.d.ts +12 -0
  266. package/runtime/types/flow-extension-runner/src/common/constants.d.ts +9 -0
  267. package/runtime/types/flow-extension-runner/src/common/context-files.d.ts +107 -0
  268. package/runtime/types/flow-extension-runner/src/common/context.d.ts +6 -0
  269. package/runtime/types/flow-extension-runner/src/common/types.d.ts +11 -0
  270. package/runtime/types/flow-extension-runner/src/errors/base.d.ts +17 -0
  271. package/runtime/types/flow-extension-runner/src/errors/codes.d.ts +17 -0
  272. package/runtime/types/flow-extension-runner/src/errors/errors.d.ts +48 -0
  273. package/runtime/types/flow-extension-runner/src/errors/index.d.ts +3 -0
  274. package/runtime/types/flow-extension-runner/src/global.d.ts +34 -0
  275. package/runtime/types/flow-extension-runner/src/index.d.ts +15 -0
  276. package/runtime/types/flow-extension-runner/src/namespace.d.ts +3 -0
  277. package/runtime/types/flow-extension-runner/src/v1/config.d.ts +3 -0
  278. package/runtime/types/flow-extension-runner/src/v1/constants.d.ts +4 -0
  279. package/runtime/types/flow-extension-runner/src/v1/index.d.ts +11 -0
  280. package/runtime/types/flow-extension-runner/src/v1/namespace.d.ts +9 -0
  281. package/runtime/types/flow-extension-runner/src/v1/service.d.ts +29 -0
  282. package/runtime/types/flow-extension-runner/src/v1/types.d.ts +13 -0
  283. package/runtime/types/flow-extension-runner/src/v2/actions/action-method.d.ts +34 -0
  284. package/runtime/types/flow-extension-runner/src/v2/context/execution-context.d.ts +25 -0
  285. package/runtime/types/flow-extension-runner/src/v2/context/logger.d.ts +2 -0
  286. package/runtime/types/flow-extension-runner/src/v2/context/method-input.d.ts +27 -0
  287. package/runtime/types/flow-extension-runner/src/v2/context/proxies.d.ts +1 -0
  288. package/runtime/types/flow-extension-runner/src/v2/create-extension.d.ts +2 -0
  289. package/runtime/types/flow-extension-runner/src/v2/crypto.d.ts +6 -0
  290. package/runtime/types/flow-extension-runner/src/v2/dictionaries/dictionary-method.d.ts +24 -0
  291. package/runtime/types/flow-extension-runner/src/v2/dictionaries/payload-schema.d.ts +10 -0
  292. package/runtime/types/flow-extension-runner/src/v2/extension.d.ts +51 -0
  293. package/runtime/types/flow-extension-runner/src/v2/index.d.ts +39 -0
  294. package/runtime/types/flow-extension-runner/src/v2/loaders/loader-method.d.ts +31 -0
  295. package/runtime/types/flow-extension-runner/src/v2/loaders/loader-owner.d.ts +17 -0
  296. package/runtime/types/flow-extension-runner/src/v2/loaders/payload-schema.d.ts +3 -0
  297. package/runtime/types/flow-extension-runner/src/v2/method.d.ts +22 -0
  298. package/runtime/types/flow-extension-runner/src/v2/model/field-mapper.d.ts +10 -0
  299. package/runtime/types/flow-extension-runner/src/v2/model/method-model.d.ts +3 -0
  300. package/runtime/types/flow-extension-runner/src/v2/model/model-types.d.ts +70 -0
  301. package/runtime/types/flow-extension-runner/src/v2/model/params-model.d.ts +16 -0
  302. package/runtime/types/flow-extension-runner/src/v2/oauth/method-names.d.ts +5 -0
  303. package/runtime/types/flow-extension-runner/src/v2/oauth/oauth2.d.ts +9 -0
  304. package/runtime/types/flow-extension-runner/src/v2/oauth/system-params.d.ts +6 -0
  305. package/runtime/types/flow-extension-runner/src/v2/oauth/types.d.ts +54 -0
  306. package/runtime/types/flow-extension-runner/src/v2/params/config-params.d.ts +14 -0
  307. package/runtime/types/flow-extension-runner/src/v2/params/files-options.d.ts +58 -0
  308. package/runtime/types/flow-extension-runner/src/v2/params/index.d.ts +19 -0
  309. package/runtime/types/flow-extension-runner/src/v2/params/json/checks.d.ts +26 -0
  310. package/runtime/types/flow-extension-runner/src/v2/params/json/decode.d.ts +24 -0
  311. package/runtime/types/flow-extension-runner/src/v2/params/json/encode.d.ts +20 -0
  312. package/runtime/types/flow-extension-runner/src/v2/params/json/types.d.ts +86 -0
  313. package/runtime/types/flow-extension-runner/src/v2/params/json/values.d.ts +5 -0
  314. package/runtime/types/flow-extension-runner/src/v2/params/method-params.d.ts +17 -0
  315. package/runtime/types/flow-extension-runner/src/v2/params/params.d.ts +26 -0
  316. package/runtime/types/flow-extension-runner/src/v2/params/schema/assert-object-schema.d.ts +6 -0
  317. package/runtime/types/flow-extension-runner/src/v2/params/schema/assert-supported-schema.d.ts +8 -0
  318. package/runtime/types/flow-extension-runner/src/v2/params/schema/coerce.d.ts +54 -0
  319. package/runtime/types/flow-extension-runner/src/v2/params/schema/dates.d.ts +40 -0
  320. package/runtime/types/flow-extension-runner/src/v2/params/schema/defaults.d.ts +36 -0
  321. package/runtime/types/flow-extension-runner/src/v2/params/schema/field-plan.d.ts +33 -0
  322. package/runtime/types/flow-extension-runner/src/v2/params/schema/introspect.d.ts +58 -0
  323. package/runtime/types/flow-extension-runner/src/v2/params/schema/labels.d.ts +3 -0
  324. package/runtime/types/flow-extension-runner/src/v2/params/schema/messages.d.ts +16 -0
  325. package/runtime/types/flow-extension-runner/src/v2/params/schema/normalize.d.ts +8 -0
  326. package/runtime/types/flow-extension-runner/src/v2/params/schema/parse.d.ts +7 -0
  327. package/runtime/types/flow-extension-runner/src/v2/params/types.d.ts +29 -0
  328. package/runtime/types/flow-extension-runner/src/v2/params/widget-types.d.ts +40 -0
  329. package/runtime/types/flow-extension-runner/src/v2/params/zod.d.ts +86 -0
  330. package/runtime/types/flow-extension-runner/src/v2/path.d.ts +1 -0
  331. package/runtime/types/flow-extension-runner/src/v2/polling-triggers/mechanisms.d.ts +19 -0
  332. package/runtime/types/flow-extension-runner/src/v2/polling-triggers/method-names.d.ts +1 -0
  333. package/runtime/types/flow-extension-runner/src/v2/polling-triggers/polling-triggers.d.ts +11 -0
  334. package/runtime/types/flow-extension-runner/src/v2/polling-triggers/system-params.d.ts +7 -0
  335. package/runtime/types/flow-extension-runner/src/v2/polling-triggers/trigger-method.d.ts +25 -0
  336. package/runtime/types/flow-extension-runner/src/v2/polling-triggers/types.d.ts +46 -0
  337. package/runtime/types/flow-extension-runner/src/v2/realtime-triggers/method-names.d.ts +7 -0
  338. package/runtime/types/flow-extension-runner/src/v2/realtime-triggers/realtime-setup.d.ts +10 -0
  339. package/runtime/types/flow-extension-runner/src/v2/realtime-triggers/system-params.d.ts +29 -0
  340. package/runtime/types/flow-extension-runner/src/v2/realtime-triggers/trigger-method.d.ts +33 -0
  341. package/runtime/types/flow-extension-runner/src/v2/realtime-triggers/types.d.ts +147 -0
  342. package/runtime/types/flow-extension-runner/src/v2/realtime-triggers/verify.d.ts +2 -0
  343. package/runtime/types/flow-extension-runner/src/v2/registry.d.ts +20 -0
  344. package/runtime/types/flow-extension-runner/src/v2/result.d.ts +13 -0
  345. package/runtime/types/flow-extension-runner/src/v2/system-method.d.ts +41 -0
  346. package/runtime/types/flow-extension-runner/src/v2/types.d.ts +126 -0
  347. package/runtime/types/jsdoc-parser/src/custom-type-defs/files.d.ts +2 -0
  348. package/runtime/types/jsdoc-parser/src/index.d.ts +2 -0
  349. package/runtime/types/jsdoc-parser/src/lib.d.ts +42 -0
  350. package/runtime/types/jsdoc-parser/src/types.d.ts +2 -0
  351. package/runtime/types/packages/cli/src/runtime/index.d.ts +5 -0
  352. package/runtime/types/shared/src/constants/ai-agent-tools.d.ts +20 -0
  353. package/runtime/types/shared/src/constants/ai.d.ts +11 -0
  354. package/runtime/types/shared/src/constants/api-keys.d.ts +1 -0
  355. package/runtime/types/shared/src/constants/app.d.ts +58 -0
  356. package/runtime/types/shared/src/constants/billing.d.ts +16 -0
  357. package/runtime/types/shared/src/constants/compliances.d.ts +3 -0
  358. package/runtime/types/shared/src/constants/data-types.d.ts +26 -0
  359. package/runtime/types/shared/src/constants/error-codes.d.ts +16 -0
  360. package/runtime/types/shared/src/constants/flow.d.ts +12 -0
  361. package/runtime/types/shared/src/constants/index.d.ts +16 -0
  362. package/runtime/types/shared/src/constants/knowledge-base.d.ts +13 -0
  363. package/runtime/types/shared/src/constants/notification-types.d.ts +985 -0
  364. package/runtime/types/shared/src/constants/notifications.d.ts +10 -0
  365. package/runtime/types/shared/src/constants/patterns.d.ts +28 -0
  366. package/runtime/types/shared/src/constants/retry-policy.d.ts +30 -0
  367. package/runtime/types/shared/src/constants/severity.d.ts +9 -0
  368. package/runtime/types/shared/src/constants/shared-extensions-search.d.ts +6 -0
  369. package/runtime/types/shared/src/constants/shared-extensions.d.ts +35 -0
  370. package/runtime/types/shared/src/constants/zod.d.ts +2 -0
  371. package/runtime/types/shared/src/errors/api.d.ts +4 -0
  372. package/runtime/types/shared/src/errors/base.d.ts +38 -0
  373. package/runtime/types/shared/src/errors/common.d.ts +39 -0
  374. package/runtime/types/shared/src/errors/index.d.ts +13 -0
  375. package/runtime/types/shared/src/errors/k8s.d.ts +4 -0
  376. package/runtime/types/shared/src/errors/message.d.ts +48 -0
  377. package/runtime/types/shared/src/errors/open-search.d.ts +4 -0
  378. package/runtime/types/shared/src/errors/s3.d.ts +11 -0
  379. package/runtime/types/shared/src/extensions/zod.d.ts +25 -0
  380. package/runtime/types/shared/src/scheme/account/dto.d.ts +60 -0
  381. package/runtime/types/shared/src/scheme/account/index.d.ts +1 -0
  382. package/runtime/types/shared/src/scheme/ai-agent-tools/dto.d.ts +69 -0
  383. package/runtime/types/shared/src/scheme/ai-agent-tools/index.d.ts +2 -0
  384. package/runtime/types/shared/src/scheme/ai-agent-tools/parameters.d.ts +7 -0
  385. package/runtime/types/shared/src/scheme/ai-router/dto.d.ts +23 -0
  386. package/runtime/types/shared/src/scheme/ai-router/index.d.ts +2 -0
  387. package/runtime/types/shared/src/scheme/api-keys/dto.d.ts +28 -0
  388. package/runtime/types/shared/src/scheme/api-keys/index.d.ts +2 -0
  389. package/runtime/types/shared/src/scheme/app/index.d.ts +1 -0
  390. package/runtime/types/shared/src/scheme/app/java.dto.d.ts +6 -0
  391. package/runtime/types/shared/src/scheme/billing/index.d.ts +1 -0
  392. package/runtime/types/shared/src/scheme/billing/java.dto.d.ts +163 -0
  393. package/runtime/types/shared/src/scheme/crm/billing.d.ts +149 -0
  394. package/runtime/types/shared/src/scheme/crm/dto.d.ts +212 -0
  395. package/runtime/types/shared/src/scheme/crm/index.d.ts +3 -0
  396. package/runtime/types/shared/src/scheme/data-types/index.d.ts +1 -0
  397. package/runtime/types/shared/src/scheme/data-types/java.dto.d.ts +23 -0
  398. package/runtime/types/shared/src/scheme/dynamic-forms/dto.d.ts +30 -0
  399. package/runtime/types/shared/src/scheme/dynamic-forms/index.d.ts +2 -0
  400. package/runtime/types/shared/src/scheme/extensions/index.d.ts +1 -0
  401. package/runtime/types/shared/src/scheme/extensions/params-to-zod.d.ts +14 -0
  402. package/runtime/types/shared/src/scheme/flowrunner/custom-elements.d.ts +368 -0
  403. package/runtime/types/shared/src/scheme/flowrunner/index.d.ts +3 -0
  404. package/runtime/types/shared/src/scheme/flowrunner/java.dto.d.ts +628 -0
  405. package/runtime/types/shared/src/scheme/index.d.ts +19 -0
  406. package/runtime/types/shared/src/scheme/integration-connection/dto.d.ts +81 -0
  407. package/runtime/types/shared/src/scheme/integration-connection/index.d.ts +2 -0
  408. package/runtime/types/shared/src/scheme/knowledge-base/dto.d.ts +540 -0
  409. package/runtime/types/shared/src/scheme/knowledge-base/index.d.ts +2 -0
  410. package/runtime/types/shared/src/scheme/mcp-oauth/dto.d.ts +7 -0
  411. package/runtime/types/shared/src/scheme/mcp-oauth/index.d.ts +2 -0
  412. package/runtime/types/shared/src/scheme/notifications/dto.d.ts +111 -0
  413. package/runtime/types/shared/src/scheme/notifications/index.d.ts +3 -0
  414. package/runtime/types/shared/src/scheme/notifications/rest.d.ts +148 -0
  415. package/runtime/types/shared/src/scheme/properties/account.d.ts +3 -0
  416. package/runtime/types/shared/src/scheme/properties/app.d.ts +5 -0
  417. package/runtime/types/shared/src/scheme/properties/billing.d.ts +12 -0
  418. package/runtime/types/shared/src/scheme/properties/common.d.ts +2 -0
  419. package/runtime/types/shared/src/scheme/properties/db.d.ts +8 -0
  420. package/runtime/types/shared/src/scheme/properties/flow-extensions.d.ts +7 -0
  421. package/runtime/types/shared/src/scheme/properties/index.d.ts +7 -0
  422. package/runtime/types/shared/src/scheme/remote-mcp-server/dto.d.ts +278 -0
  423. package/runtime/types/shared/src/scheme/remote-mcp-server/index.d.ts +2 -0
  424. package/runtime/types/shared/src/scheme/shared-extensions/base.d.ts +56 -0
  425. package/runtime/types/shared/src/scheme/shared-extensions/config.d.ts +96 -0
  426. package/runtime/types/shared/src/scheme/shared-extensions/custom-extensions.d.ts +485 -0
  427. package/runtime/types/shared/src/scheme/shared-extensions/extension.d.ts +387 -0
  428. package/runtime/types/shared/src/scheme/shared-extensions/flow-extensions.d.ts +64 -0
  429. package/runtime/types/shared/src/scheme/shared-extensions/index.d.ts +15 -0
  430. package/runtime/types/shared/src/scheme/shared-extensions/light.d.ts +38 -0
  431. package/runtime/types/shared/src/scheme/shared-extensions/logs.d.ts +21 -0
  432. package/runtime/types/shared/src/scheme/shared-extensions/methods.d.ts +80 -0
  433. package/runtime/types/shared/src/scheme/shared-extensions/params-schema.d.ts +47 -0
  434. package/runtime/types/shared/src/scheme/shared-extensions/popular-pool.d.ts +11 -0
  435. package/runtime/types/shared/src/scheme/shared-extensions/resolve.d.ts +364 -0
  436. package/runtime/types/shared/src/scheme/shared-extensions/rest.d.ts +9 -0
  437. package/runtime/types/shared/src/scheme/shared-extensions/search.d.ts +177 -0
  438. package/runtime/types/shared/src/scheme/shared-extensions/service-identity.d.ts +10 -0
  439. package/runtime/types/shared/src/scheme/shared-extensions/service-info.d.ts +15 -0
  440. package/runtime/types/shared/src/scheme/workspace/dto.d.ts +40 -0
  441. package/runtime/types/shared/src/scheme/workspace/index.d.ts +1 -0
  442. package/runtime/types/shared/src/utils/object.d.ts +8 -0
  443. package/runtime/types/shared/src/utils/uuid.d.ts +5 -0
  444. package/runtime/types/shared/src/utils/versions.d.ts +4 -0
  445. package/runtime/types/types/backendless-request.d.ts +40 -0
  446. package/templates/blank/files/README.md +28 -0
  447. package/templates/blank/files/package.json +8 -0
  448. package/templates/blank/files/public/icon.svg +5 -0
  449. package/templates/blank/files/src/index.js +130 -0
  450. package/templates/blank/template.json +61 -0
  451. package/templates/demo-todo-list/files/README.md +54 -0
  452. package/templates/demo-todo-list/files/package.json +8 -0
  453. package/templates/demo-todo-list/files/public/icon.svg +8 -0
  454. package/templates/demo-todo-list/files/src/index.js +590 -0
  455. package/templates/demo-todo-list/template.json +44 -0
  456. package/templates/qa-test/files/README.md +88 -0
  457. package/templates/qa-test/files/package.json +8 -0
  458. package/templates/qa-test/files/public/icon.svg +8 -0
  459. package/templates/qa-test/files/src/index.js +755 -0
  460. package/templates/qa-test/template.json +62 -0
@@ -0,0 +1,600 @@
1
+ 'use strict'
2
+
3
+ /**
4
+ * Wire-level mock for `Flowrunner.Request`, backed by nock.
5
+ *
6
+ * Services get the REAL `Flowrunner.Request` from `flowrunner-cli/runtime`, so the only place left
7
+ * to intercept is the HTTP layer — which is what nock does. Every recorded field below is therefore
8
+ * read off the wire; nothing here knows about the Request chain.
9
+ *
10
+ * Setup responses:
11
+ * mock.onGet('https://api.example.com/items').reply({ items: [] })
12
+ * mock.onPost('https://api.example.com/items').reply({ id: '123' })
13
+ * mock.onPost('https://api.example.com/items').reply({ error: 'nope' }, 422)
14
+ * mock.onPut('https://api.example.com/items/1').replyWith(call => ({ echoed: call.body }))
15
+ * mock.onDelete('https://api.example.com/items/1').replyWithError({ code: 1 }, 409)
16
+ * mock.onGet('https://api.example.com/items').replyWithNetworkError('ECONNRESET')
17
+ * mock.on('propfind', 'https://dav.example.com/dir').reply('<xml/>')
18
+ *
19
+ * `onAny(url)` / `onAny()` also exist and are BANNED in new suites: every method under test calls a
20
+ * known URL, so a catch-all only hides a wrong one.
21
+ *
22
+ * Inspect calls:
23
+ * mock.history // [{ method, url, canonicalUrl, fullUrl, headers, query, body, formData,
24
+ * // contentType, contentLength, timeout }]
25
+ *
26
+ * ── Lifecycle ──
27
+ * `createNockMock()` in `beforeAll`, `dispose()` in `afterAll` — the second half is not optional.
28
+ * nock patches the shared `http` module when it activates, and jest gives every test file its own
29
+ * module registry (so its own copy of nock) but ONE `http`. A suite that never disposes leaves its
30
+ * activation stacked on `http` for the rest of the worker, and the layers corrupt each other:
31
+ * request bodies that silently vanish, wrappers left pointing into a torn-down realm throwing
32
+ * `Cannot convert undefined or null to object` with an empty stack. That is why suites pass alone
33
+ * and fail in a full run. `dispose()` calls `nock.restore()` once the last mock is gone, which
34
+ * leaves `http` exactly as it was found.
35
+ *
36
+ * ── What the wire flattens ──
37
+ * - `query` values are re-typed by shape (see `parseQuery`), because a query string carries no
38
+ * types. `{ limit: 100 }` survives the round trip; a string that looks like a number does not.
39
+ * - `headers` keys are re-cased by `normalizeHeaders`, because Node's http client lowercases
40
+ * them. `X-Token` survives the round trip; `X-API-KEY` comes back as `X-Api-Key`.
41
+ */
42
+
43
+ const http = require('http')
44
+ const nock = require('nock')
45
+ const queryString = require('query-string')
46
+
47
+ /** Live mocks for THIS test file, oldest first. The newest one with a matching handler wins. */
48
+ const liveMocks = []
49
+
50
+ /** Methods that currently have a catch-all interceptor registered. */
51
+ const interceptedMethods = new Set()
52
+
53
+ /** Catch-alls installed up front; anything else is installed on demand by `on(method, url)`. */
54
+ const STANDARD_METHODS = ['get', 'post', 'put', 'patch', 'delete', 'head', 'options']
55
+
56
+ const DEFAULT_PORTS = { 'http:': '80', 'https:': '443' }
57
+
58
+ /** Status `replyWithError` uses when a test does not name one. */
59
+ const DEFAULT_ERROR_STATUS = 400
60
+
61
+ /**
62
+ * Carries `req.setTimeout(ms)` through to the recorded call. The value never reaches the socket and
63
+ * nock does not hand the reply callback the ClientRequest the caller saw, so a header is the only
64
+ * way it survives. Stripped from the recorded headers again by `normalizeHeaders`.
65
+ */
66
+ const TIMEOUT_HEADER = 'x-flowrunner-sandbox-timeout'
67
+
68
+ /**
69
+ * Headers Node's http client and `backendless-request` add on the way out. The service never set
70
+ * them, so recording them would make every whole-object `toEqual` on `headers` fail.
71
+ */
72
+ const TRANSPORT_HEADERS = new Set([
73
+ 'connection',
74
+ 'content-length',
75
+ 'host',
76
+ 'transfer-encoding',
77
+ ])
78
+
79
+ /**
80
+ * Records `req.setTimeout(ms)` on the request as a header, so `buildRecord` can read it back.
81
+ *
82
+ * The value never reaches the socket, so the wire cannot show it. Patched on the PROTOTYPE, once,
83
+ * and never removed: the replacement closes over nothing but the original core function and a
84
+ * string constant, so — unlike a wrapper closing over module state — it stays valid after the realm
85
+ * that installed it is torn down.
86
+ *
87
+ * It has to be Node's REAL `ClientRequest` prototype. Requiring nock replaces `http.ClientRequest`
88
+ * with a subclass of it, while the requests nock hands out are still instances of the real class,
89
+ * so a patch applied to `http.ClientRequest.prototype` after nock loads never runs.
90
+ */
91
+ const clientRequestProto = Object.getPrototypeOf(http.ClientRequest.prototype) === http.OutgoingMessage.prototype
92
+ ? http.ClientRequest.prototype
93
+ : Object.getPrototypeOf(http.ClientRequest.prototype)
94
+
95
+ const originalSetTimeout = clientRequestProto.setTimeout
96
+
97
+ function recordTimeout(ms, handler) {
98
+ // Recorded only while a mock is live, so a request made outside one never carries the marker. The
99
+ // flag lives on the shared `http` module, NOT in a module variable: jest gives each
100
+ // test file its own realm but one `http`, so whichever realm installs this patch first owns the
101
+ // closure for the whole worker and must not read that realm's own state.
102
+ if (http.__flowrunnerSandboxMocking && !this.headersSent) {
103
+ try {
104
+ this.setHeader(TIMEOUT_HEADER, String(ms))
105
+ } catch (ignored) {
106
+ // Headers already flushed — the timeout simply goes unrecorded.
107
+ }
108
+ }
109
+
110
+ return originalSetTimeout.call(this, ms, handler)
111
+ }
112
+
113
+ recordTimeout.__flowrunnerSandbox = true
114
+
115
+ if (!clientRequestProto.setTimeout.__flowrunnerSandbox) {
116
+ clientRequestProto.setTimeout = recordTimeout
117
+ }
118
+
119
+ /**
120
+ * Reduces a URL to the two forms a handler can be matched against: without its query string and
121
+ * with it. Default ports are dropped so `https://x.test:443/a` and `https://x.test/a` are one URL.
122
+ *
123
+ * @param {string} urlString
124
+ * @returns {{ base: string, full: string, search: string }|null} null when the input is not a URL.
125
+ */
126
+ function canonicalize(urlString) {
127
+ let url
128
+
129
+ try {
130
+ url = new URL(urlString)
131
+ } catch (error) {
132
+ return null
133
+ }
134
+
135
+ const port = url.port && url.port !== DEFAULT_PORTS[url.protocol] ? `:${ url.port }` : ''
136
+ const base = `${ url.protocol }//${ url.hostname }${ port }${ url.pathname }`
137
+
138
+ return { base, full: base + url.search, search: url.search }
139
+ }
140
+
141
+ /**
142
+ * @param {string|RegExp|undefined} handlerUrl - undefined matches every URL.
143
+ * @param {{ url: string, canonicalUrl: string, fullUrl: string }} record
144
+ */
145
+ function urlMatches(handlerUrl, record) {
146
+ if (handlerUrl === undefined || handlerUrl === null) {
147
+ return true
148
+ }
149
+
150
+ if (handlerUrl instanceof RegExp) {
151
+ return handlerUrl.test(record.fullUrl) || handlerUrl.test(record.canonicalUrl)
152
+ }
153
+
154
+ const handler = canonicalize(handlerUrl)
155
+
156
+ if (!handler) {
157
+ return handlerUrl === record.url || handlerUrl === record.fullUrl
158
+ }
159
+
160
+ // A handler registered WITH a query string only matches that exact query; one registered without
161
+ // matches whatever query the service ended up adding via `.query()`.
162
+ return handler.search ? handler.full === record.fullUrl : handler.base === record.canonicalUrl
163
+ }
164
+
165
+ /**
166
+ * Turns a query string into the `{ name: value }` shape tests assert against.
167
+ *
168
+ * A query string is untyped, so `parseNumbers`/`parseBooleans` put back the JS types the service
169
+ * passed to `.query()` — `?limit=100&flag=true` reads as `{ limit: 100, flag: true }`. The inference
170
+ * is by shape, not by intent, so a value that only LOOKS numeric or boolean comes back coerced: an
171
+ * id sent as the string `'123'` reads as `123`, and a zero-padded `'007'` reads as `7`. Assert those
172
+ * with the coerced value.
173
+ *
174
+ * A parameter repeated in the query becomes an array (`arrayFormat: 'none'`, the default).
175
+ */
176
+ function parseQuery(search) {
177
+ // Spread into a plain object: query-string returns a null-prototype one, which reads the same
178
+ // under `toEqual` but not under `toStrictEqual`.
179
+ return { ...queryString.parse(search, { parseNumbers: true, parseBooleans: true }) }
180
+ }
181
+
182
+ /**
183
+ * Rebuilds the header object a service actually set, out of what came off the wire.
184
+ *
185
+ * Two things happen to headers between `.set()` and the socket: `backendless-request` lowercases
186
+ * every name, and Node adds its own transport headers. Both are undone here — transport headers are
187
+ * dropped, and each remaining name is upper-cased at the start of every hyphen-separated segment,
188
+ * which is the conventional HTTP spelling (`x-token` → `X-Token`, `content-type` → `Content-Type`).
189
+ *
190
+ * The original casing is gone by the time nock sees the request, so this RE-DERIVES it rather than
191
+ * restoring it. Conventional names round-trip exactly; a service that shouted its header
192
+ * (`X-API-KEY`) or wrote it in camelCase (`apiKey`) gets the conventional spelling back instead
193
+ * (`X-Api-Key`, `Apikey`).
194
+ *
195
+ * @param {object} rawHeaders - Lowercased headers as nock recorded them.
196
+ * @returns {object} A new object; the input is left alone.
197
+ */
198
+ function normalizeHeaders(rawHeaders) {
199
+ const headers = {}
200
+
201
+ for (const [name, value] of Object.entries(rawHeaders || {})) {
202
+ const lower = name.toLowerCase()
203
+
204
+ // The harness's own marker must never look like something the service set.
205
+ if (TRANSPORT_HEADERS.has(lower) || lower === TIMEOUT_HEADER) {
206
+ continue
207
+ }
208
+
209
+ const normalized = name
210
+ .split('-')
211
+ .map(segment => segment.charAt(0).toUpperCase() + segment.slice(1))
212
+ .join('-')
213
+
214
+ headers[normalized] = value
215
+ }
216
+
217
+ return headers
218
+ }
219
+
220
+ /**
221
+ * The multipart body as text, whatever encoding nock handed it over in.
222
+ *
223
+ * nock stringifies the request body for the reply callback, and a body that is not valid UTF-8 — which
224
+ * is exactly what a multipart upload carrying binary bytes is — arrives HEX-ENCODED. Left as-is the
225
+ * boundary is invisible in it, `parseFormData` finds no parts, and a binary upload reads as
226
+ * `{ _fields: [] }`: "the service sent nothing", which is indistinguishable from a genuinely empty
227
+ * body and is the one thing a multipart test exists to tell apart.
228
+ *
229
+ * Decoded only when the decoded form actually contains the boundary, so a text upload — or a body that
230
+ * merely happens to look like hex — is handed back untouched.
231
+ */
232
+ function multipartText(rawBody, boundary) {
233
+ const text = Buffer.isBuffer(rawBody) ? rawBody.toString('binary') : String(rawBody)
234
+
235
+ if (text.includes(boundary) || !/^(?:[0-9a-f]{2})+$/i.test(text)) {
236
+ return text
237
+ }
238
+
239
+ const decoded = Buffer.from(text, 'hex').toString('binary')
240
+
241
+ return decoded.includes(boundary) ? decoded : text
242
+ }
243
+
244
+ /**
245
+ * Rebuilds the `{ _fields: [{ name, value, filename, contentType }] }` shape a FormData body had
246
+ * before it was serialized, by parsing the multipart body off the wire.
247
+ */
248
+ function parseFormData(rawBody, contentType) {
249
+ const boundaryMatch = /boundary=(?:"([^"]+)"|([^;\s]+))/i.exec(contentType || '')
250
+
251
+ if (!boundaryMatch) {
252
+ return undefined
253
+ }
254
+
255
+ const boundary = `--${ boundaryMatch[1] || boundaryMatch[2] }`
256
+ const fields = []
257
+
258
+ for (const part of multipartText(rawBody, boundary).split(boundary)) {
259
+ const section = part.replace(/^\r\n/, '')
260
+ const headerEnd = section.indexOf('\r\n\r\n')
261
+
262
+ if (!section || section.startsWith('--') || headerEnd === -1) {
263
+ continue
264
+ }
265
+
266
+ const headers = section.slice(0, headerEnd)
267
+ const name = /\bname="([^"]*)"/i.exec(headers)
268
+ const filename = /\bfilename="([^"]*)"/i.exec(headers)
269
+ // The per-part Content-Type. Recorded because it is the only thing that tells an upload's MIME
270
+ // type apart from the default, and a service picks it deliberately (usually from the extension).
271
+ const partType = /^content-type:\s*(.+)$/im.exec(headers)
272
+ const value = section.slice(headerEnd + 4).replace(/\r\n$/, '')
273
+
274
+ fields.push({
275
+ name: name ? name[1] : undefined,
276
+ // A part carrying a filename is a file upload, and the service appended it as a Buffer. Hand
277
+ // one back so `Buffer.isBuffer(field.value)` still holds. (Text parts stay strings.)
278
+ value : filename ? Buffer.from(value, 'binary') : value,
279
+ filename : filename ? filename[1] : undefined,
280
+ contentType: partType ? partType[1].trim() : undefined,
281
+ })
282
+ }
283
+
284
+ return { _fields: fields }
285
+ }
286
+
287
+ /**
288
+ * nock hands the body over already JSON-parsed when the content type says JSON, and as a string
289
+ * otherwise. Normalize the leftovers: an empty body reads as "no body at all".
290
+ */
291
+ function parseBody(rawBody, contentType) {
292
+ if (rawBody === undefined || rawBody === null || rawBody === '') {
293
+ return undefined
294
+ }
295
+
296
+ if (typeof rawBody !== 'string') {
297
+ return rawBody
298
+ }
299
+
300
+ // `a=1&b=two` is the wire form of `{ a: '1', b: 'two' }` — decode it back, the same way a JSON
301
+ // body comes back as an object rather than its serialized text. Values stay STRINGS here, unlike
302
+ // query params: form bodies overwhelmingly carry ids and flags the service already stringified,
303
+ // and re-typing them turned `company_id: '142'` into `142`.
304
+ if (String(contentType || '').startsWith('application/x-www-form-urlencoded')) {
305
+ return { ...queryString.parse(rawBody) }
306
+ }
307
+
308
+ try {
309
+ return JSON.parse(rawBody)
310
+ } catch (error) {
311
+ return rawBody
312
+ }
313
+ }
314
+
315
+ /** Builds one history entry from nock's interceptor context. */
316
+ function buildRecord(req, uri, rawBody) {
317
+ const options = req.options || {}
318
+ const headers = req.headers || {}
319
+ const parsed = canonicalize(`${ options.proto }://${ options.host }${ uri }`) || { base: uri, full: uri }
320
+ const contentType = headers['content-type']
321
+ const formData = contentType && contentType.includes('multipart/form-data')
322
+ ? parseFormData(rawBody, contentType)
323
+ : undefined
324
+
325
+ return {
326
+ method: String(req.method || '').toLowerCase(),
327
+ // `url` and `canonicalUrl` hold the same string. Both are recorded because suites assert either
328
+ // one, and only `canonicalUrl` is contractually the normalized form.
329
+ url : parsed.base,
330
+ canonicalUrl: parsed.base,
331
+ fullUrl : parsed.full,
332
+ headers : normalizeHeaders(headers),
333
+ query : parseQuery(parsed.full.slice(parsed.base.length)),
334
+ body : formData ? undefined : parseBody(rawBody, contentType),
335
+ formData,
336
+ contentType,
337
+ // Transport details kept OFF `headers` on purpose: many suites assert the whole header object
338
+ // with `toEqual`, and a service never sets these itself.
339
+ contentLength: headers['content-length'] !== undefined ? Number(headers['content-length']) : undefined,
340
+ timeout : headers[TIMEOUT_HEADER] !== undefined ? Number(headers[TIMEOUT_HEADER]) : undefined,
341
+ }
342
+ }
343
+
344
+ /**
345
+ * nock only emits Error instances — handing it a plain object makes the request hang silently — so
346
+ * `replyWithError({ message, body })` has to be reconstituted into a real Error carrying those props.
347
+ */
348
+ function toError(error) {
349
+ if (error instanceof Error) {
350
+ return error
351
+ }
352
+
353
+ if (typeof error === 'string') {
354
+ return new Error(error)
355
+ }
356
+
357
+ return Object.assign(new Error((error && error.message) || 'Request failed'), error)
358
+ }
359
+
360
+ /**
361
+ * Handler precedence, applied across every live mock, newest mock first:
362
+ * exact method+url → method+any url → any method+url → any method+any url, first registered wins
363
+ * within a tier.
364
+ *
365
+ * nock's own routing is not used for this: its precedence follows scope registration order, so a
366
+ * broad `onAny()` fallback would shadow a specific handler registered after it.
367
+ */
368
+ function resolveHandler(record) {
369
+ for (let i = liveMocks.length - 1; i >= 0; i--) {
370
+ const handler = liveMocks[i].findHandler(record)
371
+
372
+ if (handler) {
373
+ return { mock: liveMocks[i], handler }
374
+ }
375
+ }
376
+
377
+ return { mock: liveMocks[liveMocks.length - 1], handler: null }
378
+ }
379
+
380
+ /**
381
+ * The single reply callback behind every catch-all interceptor. `this` is nock's interceptor
382
+ * context, so it must stay a function declaration.
383
+ */
384
+ function dispatch(uri, rawBody, callback) {
385
+ const record = buildRecord(this.req, uri, rawBody)
386
+ const { mock, handler } = resolveHandler(record)
387
+
388
+ if (!mock) {
389
+ return callback(new Error(`No request mock is active for ${ record.method.toUpperCase() } ${ record.url }`))
390
+ }
391
+
392
+ mock.history.push(record)
393
+
394
+ // No handler registered: resolve with null rather than failing the request.
395
+ if (!handler) {
396
+ return callback(null, [200, null])
397
+ }
398
+
399
+ if (handler.error) {
400
+ return callback(toError(handler.error))
401
+ }
402
+
403
+ let response
404
+
405
+ try {
406
+ response = typeof handler.response === 'function' ? handler.response(record) : handler.response
407
+ } catch (error) {
408
+ // A `replyWith` callback that throws synchronously — the idiom retry tests use to fail the
409
+ // first attempt.
410
+ return callback(toError(error))
411
+ }
412
+
413
+ Promise.resolve(response).then(
414
+ value => callback(null, [handler.status, value === undefined ? null : value, handler.headers]),
415
+ error => callback(toError(error)),
416
+ )
417
+ }
418
+
419
+ /** Registers the persisted catch-all for one HTTP method, once. */
420
+ function installCatchAll(method) {
421
+ if (interceptedMethods.has(method)) {
422
+ return
423
+ }
424
+
425
+ // `dispose()` deactivates nock so it stops patching `http`; a later mock in the same file has to
426
+ // put it back.
427
+ if (!nock.isActive()) {
428
+ nock.activate()
429
+ }
430
+
431
+ nock(/.*/)
432
+ .persist()
433
+ .intercept(/.*/, method.toUpperCase())
434
+ .query(() => true)
435
+ .reply(dispatch)
436
+
437
+ interceptedMethods.add(method)
438
+ }
439
+
440
+ function createNockMock() {
441
+ const history = []
442
+ const handlers = []
443
+
444
+ const state = {
445
+ history,
446
+
447
+ findHandler(record) {
448
+ return (
449
+ handlers.find(h => h.url !== undefined && h.method === record.method && urlMatches(h.url, record)) ||
450
+ handlers.find(h => h.url === undefined && h.method === record.method) ||
451
+ handlers.find(h => h.url !== undefined && h.method === 'any' && urlMatches(h.url, record)) ||
452
+ handlers.find(h => h.url === undefined && h.method === 'any')
453
+ )
454
+ },
455
+ }
456
+
457
+ function createReplyBuilder(method, url) {
458
+ if (method !== 'any') {
459
+ installCatchAll(method)
460
+ }
461
+
462
+ return {
463
+ /**
464
+ * @param {*} response - The resolved value, or a function/promise producing it.
465
+ * @param {number} [status] - HTTP status; anything outside 2xx makes the request reject.
466
+ * @param {object} [headers] - Response headers, for APIs that signal through them.
467
+ */
468
+ reply(response, status = 200, headers = undefined) {
469
+ handlers.push({ method, url, response, status, headers })
470
+
471
+ return api
472
+ },
473
+
474
+ /**
475
+ * Answers with an error RESPONSE — a real status code and body, the way the API would.
476
+ *
477
+ * .replyWithError('Invalid Account or Auth', 401) // body: { message: '…' }
478
+ * .replyWithError({ errors: [ 'Invalid Account' ] }, 401)
479
+ * .replyWithError('server error') // status defaults to 400
480
+ *
481
+ * For a failure with no response at all — a dropped connection, a reset socket — use
482
+ * `replyWithNetworkError` instead; those are a different branch in service code than a 500.
483
+ *
484
+ * A single OBJECT argument with no status keeps the older reading: it becomes a client-side
485
+ * Error the request rejects with. Most existing call sites mean it that way, and the two
486
+ * readings are indistinguishable from the argument alone — so an object body MUST carry its
487
+ * status explicitly. A string never needs one.
488
+ *
489
+ * @param {string|object|Error} body - Response body; a string becomes `{ message: body }`.
490
+ * @param {number} [status] - HTTP status. Required for an object body.
491
+ */
492
+ replyWithError(body, status) {
493
+ if (status === undefined && (body instanceof Error || (body !== null && typeof body === 'object'))) {
494
+ handlers.push({ method, url, error: body })
495
+
496
+ return api
497
+ }
498
+
499
+ handlers.push({
500
+ method,
501
+ url,
502
+ response: typeof body === 'string' || body === null || body === undefined
503
+ ? { message: body === null || body === undefined ? 'Request failed' : body }
504
+ : body,
505
+ status : status === undefined ? DEFAULT_ERROR_STATUS : status,
506
+ })
507
+
508
+ return api
509
+ },
510
+
511
+ /**
512
+ * Fails the request at the transport layer: no status, no body, nothing came back.
513
+ *
514
+ * This is what a service sees when the connection is refused, reset or times out, and it is a
515
+ * genuinely different path from an error response — `error.status` is undefined and
516
+ * `error.code` carries the syscall name.
517
+ *
518
+ * .replyWithNetworkError('ECONNRESET')
519
+ * .replyWithNetworkError('socket hang up')
520
+ *
521
+ * @param {string} [code] - A syscall code (`ECONNRESET`, `ETIMEDOUT`, …) or a free-text
522
+ * reason. A syscall-shaped value is set on `error.code` as well as the message.
523
+ */
524
+ replyWithNetworkError(code = 'ECONNRESET') {
525
+ const error = new Error(code)
526
+
527
+ if (/^E[A-Z_]+$/.test(code)) {
528
+ error.code = code
529
+ }
530
+
531
+ handlers.push({ method, url, error })
532
+
533
+ return api
534
+ },
535
+
536
+ /** @param {(call: object) => *} fn - Receives the history entry, returns the response. */
537
+ replyWith(fn) {
538
+ handlers.push({ method, url, response: fn, status: 200 })
539
+
540
+ return api
541
+ },
542
+ }
543
+ }
544
+
545
+ const api = {
546
+ history,
547
+
548
+ /** `onGet`, `onPost`, … `onAny` are generated below; `on()` covers anything non-standard. */
549
+ on(method, url) {
550
+ return createReplyBuilder(String(method).toLowerCase(), url)
551
+ },
552
+
553
+ /** Drops recorded calls and registered handlers, keeping the mock itself active. */
554
+ reset() {
555
+ history.length = 0
556
+ handlers.length = 0
557
+ },
558
+
559
+ /**
560
+ * Drops registered handlers but keeps the recorded calls. For suites whose own `replyWith()`
561
+ * helper re-arms the transport mid-test: the first matching handler wins, so a stale one
562
+ * registered earlier in the same test would shadow the new reply.
563
+ */
564
+ resetHandlers() {
565
+ handlers.length = 0
566
+ },
567
+
568
+ /** Removes this mock and, once none are left, un-patches `http`. See "Lifecycle" above. */
569
+ dispose() {
570
+ api.reset()
571
+
572
+ const index = liveMocks.indexOf(state)
573
+
574
+ if (index !== -1) {
575
+ liveMocks.splice(index, 1)
576
+ }
577
+
578
+ if (!liveMocks.length) {
579
+ nock.cleanAll()
580
+ nock.restore()
581
+ interceptedMethods.clear()
582
+ http.__flowrunnerSandboxMocking = false
583
+ }
584
+ },
585
+ }
586
+
587
+ for (const method of [...STANDARD_METHODS, 'any']) {
588
+ api[`on${ method.charAt(0).toUpperCase() }${ method.slice(1) }`] = url => createReplyBuilder(method, url)
589
+ }
590
+
591
+ liveMocks.push(state)
592
+ http.__flowrunnerSandboxMocking = true
593
+ STANDARD_METHODS.forEach(installCatchAll)
594
+
595
+ return api
596
+ }
597
+
598
+ module.exports = {
599
+ createNockMock: createNockMock,
600
+ }