@zimic/interceptor 0.14.0-canary.20 → 0.14.0-canary.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -17,7 +17,7 @@ var filesystem__default = /*#__PURE__*/_interopDefault(filesystem);
17
17
  var path__default = /*#__PURE__*/_interopDefault(path);
18
18
 
19
19
  // package.json
20
- var version = "0.14.0-canary.20";
20
+ var version = "0.14.0-canary.22";
21
21
 
22
22
  // src/cli/browser/shared/constants.ts
23
23
  var SERVICE_WORKER_FILE_NAME = "mockServiceWorker.js";
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../package.json","../src/cli/browser/shared/constants.ts","../src/cli/browser/init.ts","../src/utils/processes.ts","../src/cli/server/start.ts","../src/cli/cli.ts","../src/cli/index.ts"],"names":["path","__require","filesystem","logWithPrefix","chalk","__name","createCachedDynamicImport_default","interceptorServer","exitEvent","yargs","hideBin"],"mappings":";;;;;;;;;;;;;;;;;;;AAgBE,IAAW,OAAA,GAAA,kBAAA;;;AChBN,IAAM,wBAA2B,GAAA,sBAAA;;;ACQxC,IAAM,aAAA,GAAgBA,sBAAK,IAAK,CAAAC,0BAAA,CAAQ,QAAQ,KAAK,CAAA,EAAG,IAAM,EAAA,IAAA,EAAM,IAAI,CAAA;AACjE,IAAM,wBAA2B,GAAAD,qBAAA,CAAK,IAAK,CAAA,aAAA,EAAe,OAAO,wBAAwB,CAAA;AAMhG,eAAe,8BAAA,CAA+B,EAAE,eAAA,EAAoD,EAAA;AAClG,EAAM,MAAA,uBAAA,GAA0BA,qBAAK,CAAA,OAAA,CAAQ,eAAe,CAAA;AAC5D,EAAA,MAAME,4BAAW,KAAM,CAAA,uBAAA,EAAyB,EAAE,SAAA,EAAW,MAAM,CAAA;AAEnE,EAAA,MAAM,eAAkB,GAAAF,qBAAA,CAAK,IAAK,CAAA,uBAAA,EAAyB,wBAAwB,CAAA;AACnF,EAAM,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,wMAAA;AAAA,QAGF,KAAO,EAAA;AAAA,OACR,CAAA;AAAA,MACL,OAAO,YAAiB,KAAA;AACtB,QAAA,MAAM,iBAAiB,YAAa,CAAA,CAAA,CAAE,EAAG,CAAA,CAAC,GAAG,QAAS,EAAA;AACtD,QAAM,MAAA,uBAAA,GAA0B,YAAa,CAAA,CAAA,CAAE,KAAM,CAAA,CAAC,CAAE,CAAA,GAAA,CAAI,CAAC,QAAA,KAAa,QAAS,CAAA,QAAA,EAAU,CAAA;AAE7F,QAAA,MAAM,aAAuB,CAAA;AAAA,UAC3B,UAAU,YAAa,CAAA,QAAA;AAAA,UACvB,MAAM,YAAa,CAAA,IAAA;AAAA,UACnB,WAAW,YAAa,CAAA,SAAA;AAAA,UACxB,sBAAsB,YAAa,CAAA,oBAAA;AAAA,UACnC,SAAS,cACL,GAAA;AAAA,YACE,OAAA,EAAS,eAAe,QAAS,EAAA;AAAA,YACjC,SAAW,EAAA;AAAA,WAEb,GAAA;AAAA,SACL,CAAA;AAAA;AACH;AACF,IAGD,KAAM,EAAA;AACX;AApFeJ,uBAAA,CAAA,MAAA,EAAA,QAAA,CAAA;AAsFf,IAAO,WAAQ,GAAA,MAAA;;;AC3Ff,KAAK,WAAO,EAAA","file":"cli.js","sourcesContent":["{\n \"name\": \"@zimic/interceptor\",\n \"description\": \"TypeScript-first HTTP request mocking and interceptor\",\n \"keywords\": [\n \"zimic\",\n \"typescript\",\n \"types\",\n \"typegen\",\n \"validation\",\n \"inference\",\n \"http\",\n \"interceptor\",\n \"mock\",\n \"api\",\n \"static\"\n ],\n \"version\": \"0.14.0-canary.20\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/zimicjs/zimic.git\",\n \"directory\": \"packages/zimic-interceptor\"\n },\n \"author\": {\n \"name\": \"Diego Aquino\",\n \"url\": \"https://github.com/diego-aquino\"\n },\n \"private\": false,\n \"publishConfig\": {\n \"access\": \"public\",\n \"provenance\": true\n },\n \"engines\": {\n \"node\": \">=18.13.0\"\n },\n \"license\": \"MIT\",\n \"files\": [\n \"package.json\",\n \"README.md\",\n \"LICENSE.md\",\n \"src\",\n \"!src/**/tests\",\n \"!src/**/__tests__\",\n \"!src/**/*.test.ts\",\n \"dist\",\n \"index.d.ts\",\n \"http.d.ts\",\n \"server.d.ts\"\n ],\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"types\": \"index.d.ts\",\n \"bin\": {\n \"zimic-interceptor\": \"./dist/cli.js\"\n },\n \"exports\": {\n \".\": {\n \"types\": \"./index.d.ts\",\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\",\n \"default\": \"./dist/index.js\"\n },\n \"./http\": {\n \"types\": \"./http.d.ts\",\n \"import\": \"./dist/http.mjs\",\n \"require\": \"./dist/http.js\",\n \"default\": \"./dist/http.js\"\n },\n \"./server\": {\n \"types\": \"./server.d.ts\",\n \"import\": \"./dist/server.mjs\",\n \"require\": \"./dist/server.js\",\n \"default\": \"./dist/server.js\"\n },\n \"./package.json\": \"./package.json\"\n },\n \"scripts\": {\n \"dev\": \"tsup --watch\",\n \"cli\": \"node ./dist/cli.js\",\n \"build\": \"tsup\",\n \"lint\": \"eslint --cache --no-error-on-unmatched-pattern --no-warn-ignored --fix\",\n \"lint:turbo\": \"pnpm lint . --max-warnings 0\",\n \"style\": \"prettier --log-level warn --ignore-unknown --no-error-on-unmatched-pattern --cache\",\n \"style:check\": \"pnpm style --check\",\n \"style:format\": \"pnpm style --write\",\n \"test\": \"dotenv -v NODE_ENV=test -- vitest\",\n \"test:turbo\": \"dotenv -v CI=true -- pnpm run test run --coverage\",\n \"types:check\": \"tsc --noEmit\",\n \"deps:install-playwright\": \"playwright install chromium\",\n \"deps:init-msw\": \"msw init ./public --no-save\",\n \"deps:init\": \"pnpm deps:install-playwright && pnpm deps:init-msw\",\n \"postinstall\": \"node -e \\\"try{require('./dist/scripts/postinstall')}catch(error){console.error(error)}\\\"\",\n \"prepublish:patch-relative-paths\": \"sed -E -i 's/\\\\]\\\\(\\\\.\\\\/([^\\\\)]+)\\\\)/](..\\\\/..\\\\/\\\\1)/g;s/\\\"\\\\.\\\\/([^\\\"]+)\\\"/\\\"..\\\\/..\\\\/\\\\1\\\"/g'\",\n \"prepublishOnly\": \"cp ../../README.md ../../LICENSE.md . && pnpm prepublish:patch-relative-paths README.md\"\n },\n \"dependencies\": {\n \"@whatwg-node/server\": \"0.9.68\",\n \"@zimic/utils\": \"workspace:*\",\n \"chalk\": \"4.1.2\",\n \"execa\": \"9.5.2\",\n \"isomorphic-ws\": \"5.0.0\",\n \"msw\": \"2.7.1\",\n \"ws\": \"8.18.1\",\n \"yargs\": \"17.7.2\"\n },\n \"optionalDependencies\": {\n \"bufferutil\": \"4.0.9\"\n },\n \"devDependencies\": {\n \"@types/node\": \"^22.13.5\",\n \"@types/ws\": \"^8.5.14\",\n \"@types/yargs\": \"^17.0.33\",\n \"@vitest/browser\": \"^3.0.6\",\n \"@vitest/coverage-istanbul\": \"^3.0.6\",\n \"@zimic/eslint-config-node\": \"workspace:*\",\n \"@zimic/lint-staged-config\": \"workspace:*\",\n \"@zimic/tsconfig\": \"workspace:*\",\n \"dotenv-cli\": \"^8.0.0\",\n \"eslint\": \"^9.21.0\",\n \"playwright\": \"^1.50.1\",\n \"tsup\": \"^8.3.6\",\n \"typescript\": \"^5.7.3\",\n \"vitest\": \"^3.0.6\"\n },\n \"peerDependencies\": {\n \"@zimic/http\": \"^0.1.0 || ^0.1.0-canary.0\",\n \"typescript\": \">=4.8.0\"\n },\n \"peerDependenciesMeta\": {\n \"typescript\": {\n \"optional\": true\n }\n }\n}\n","export const SERVICE_WORKER_FILE_NAME = 'mockServiceWorker.js';\n","import chalk from 'chalk';\nimport filesystem from 'fs/promises';\nimport path from 'path';\n\nimport { logWithPrefix } from '@/utils/console';\n\nimport { SERVICE_WORKER_FILE_NAME } from './shared/constants';\n\nconst MSW_ROOT_PATH = path.join(require.resolve('msw'), '..', '..', '..');\nexport const MOCK_SERVICE_WORKER_PATH = path.join(MSW_ROOT_PATH, 'lib', SERVICE_WORKER_FILE_NAME);\n\ninterface BrowserServiceWorkerInitOptions {\n publicDirectory: string;\n}\n\nasync function initializeBrowserServiceWorker({ publicDirectory }: BrowserServiceWorkerInitOptions) {\n const absolutePublicDirectory = path.resolve(publicDirectory);\n await filesystem.mkdir(absolutePublicDirectory, { recursive: true });\n\n const destinationPath = path.join(absolutePublicDirectory, SERVICE_WORKER_FILE_NAME);\n await filesystem.copyFile(MOCK_SERVICE_WORKER_PATH, destinationPath);\n\n logWithPrefix(`Service worker script saved to ${chalk.green(destinationPath)}!`);\n logWithPrefix('You can now use browser interceptors!');\n}\n\nexport default initializeBrowserServiceWorker;\n","import createCachedDynamicImport from '@zimic/utils/import/createCachedDynamicImport';\n\nexport const PROCESS_EXIT_EVENTS = Object.freeze([\n 'beforeExit',\n 'uncaughtExceptionMonitor',\n 'SIGINT',\n 'SIGTERM',\n 'SIGHUP',\n 'SIGBREAK',\n] as const);\n\nexport type ProcessExitEvent = (typeof PROCESS_EXIT_EVENTS)[number];\n\n// Having an undefined exit code means that the process will already exit with the default exit code.\nexport const PROCESS_EXIT_CODE_BY_EXIT_EVENT: Record<string, number | undefined> = {\n beforeExit: undefined,\n uncaughtExceptionMonitor: undefined,\n SIGINT: 130,\n SIGTERM: 143,\n SIGHUP: 129,\n SIGBREAK: 131,\n} satisfies Record<ProcessExitEvent, number | undefined>;\n\nexport const importExeca = createCachedDynamicImport(() => import('execa'));\n\ninterface CommandErrorOptions {\n command?: string[];\n exitCode?: number;\n signal?: NodeJS.Signals;\n originalMessage?: string;\n}\n\nexport class CommandError extends Error {\n static readonly DEFAULT_EXIT_CODE = 1;\n\n readonly command: string[];\n readonly exitCode: number;\n readonly signal?: NodeJS.Signals;\n\n constructor(executable: string, options: CommandErrorOptions) {\n const message = CommandError.createMessage(executable, options);\n super(message);\n\n this.name = 'CommandError';\n this.command = options.command ?? [executable];\n this.exitCode = this.getExitCode(options);\n this.signal = options.signal;\n }\n\n private getExitCode(options: CommandErrorOptions): number {\n const existingExitCode = options.exitCode;\n const exitCodeInferredFromSignal =\n options.signal === undefined ? undefined : PROCESS_EXIT_CODE_BY_EXIT_EVENT[options.signal];\n\n return existingExitCode ?? exitCodeInferredFromSignal ?? CommandError.DEFAULT_EXIT_CODE;\n }\n\n private static createMessage(command: string, options: CommandErrorOptions) {\n const suffix = options.originalMessage ? `: ${options.originalMessage}` : '';\n\n if (options.exitCode === undefined && options.signal === undefined) {\n return `Command '${command}' failed${suffix}`;\n }\n\n const prefix = `Command '${command}' exited `;\n const infix = options.exitCode === undefined ? `after signal ${options.signal}` : `with code ${options.exitCode}`;\n\n return `${prefix}${infix}${suffix}`;\n }\n}\n\nexport async function runCommand(command: string, commandArguments: string[]) {\n const { execa: $, ExecaError } = await importExeca();\n\n try {\n await $(command, commandArguments, { stdio: 'inherit' });\n } catch (error) {\n /* istanbul ignore if -- @preserve\n * This is a safeguard if the error is not an ExecaError. It is not expected to run. */\n if (!(error instanceof ExecaError)) {\n throw error;\n }\n\n const commandError = new CommandError(command, {\n command: [command, ...commandArguments],\n exitCode: error.exitCode,\n signal: error.signal,\n originalMessage: error.originalMessage,\n });\n\n throw commandError;\n }\n}\n","import { InterceptorServer, interceptorServer } from '@/server';\nimport { InterceptorServerOptions } from '@/server/types/options';\nimport { logWithPrefix } from '@/utils/console';\nimport {\n CommandError,\n PROCESS_EXIT_CODE_BY_EXIT_EVENT,\n PROCESS_EXIT_EVENTS,\n ProcessExitEvent,\n runCommand,\n} from '@/utils/processes';\n\ninterface InterceptorServerStartOptions extends InterceptorServerOptions {\n ephemeral: boolean;\n onReady?: {\n command: string;\n arguments: string[];\n };\n}\n\nexport let serverSingleton: InterceptorServer | undefined;\n\nasync function startInterceptorServer({\n hostname,\n port,\n ephemeral,\n logUnhandledRequests,\n onReady,\n}: InterceptorServerStartOptions) {\n const server = interceptorServer.create({\n hostname,\n port,\n logUnhandledRequests,\n });\n\n async function handleExitEvent(exitEvent: ProcessExitEvent | undefined) {\n await server.stop();\n\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n for (const { exitEvent, exitHandler } of exitHandlerGroups) {\n process.off(exitEvent, exitHandler);\n }\n\n const exitCode = exitEvent ? PROCESS_EXIT_CODE_BY_EXIT_EVENT[exitEvent] : undefined;\n if (exitCode !== undefined) {\n process.exit(exitCode);\n }\n }\n\n const exitHandlerGroups = PROCESS_EXIT_EVENTS.map((exitEvent) => ({\n exitEvent,\n exitHandler: handleExitEvent.bind(null, exitEvent),\n }));\n\n for (const { exitEvent, exitHandler } of exitHandlerGroups) {\n process.on(exitEvent, exitHandler);\n }\n\n serverSingleton = server;\n\n await server.start();\n\n logWithPrefix(`${ephemeral ? 'Ephemeral s' : 'S'}erver is running on ${server.httpURL()}`);\n\n if (onReady) {\n try {\n await runCommand(onReady.command, onReady.arguments);\n } catch (error) {\n console.error(error);\n\n /* istanbul ignore if -- @preserve\n * A CommandError is always expected here. */\n if (!(error instanceof CommandError)) {\n throw error;\n }\n\n process.exit(error.exitCode);\n }\n }\n\n if (ephemeral) {\n await handleExitEvent(undefined);\n process.exit(0);\n }\n}\n\nexport default startInterceptorServer;\n","import yargs from 'yargs';\nimport { hideBin } from 'yargs/helpers';\n\nimport { version } from '@@/package.json';\n\nimport initializeBrowserServiceWorker from './browser/init';\nimport startInterceptorServer from './server/start';\n\nasync function runCLI() {\n await yargs(hideBin(process.argv))\n .scriptName('zimic-interceptor')\n .version(version)\n .showHelpOnFail(false)\n .strict()\n\n .command('browser', 'Manage your browser mock configuration', (yargs) =>\n yargs.demandCommand().command(\n 'init <publicDirectory>',\n 'Initialize the browser service worker configuration.',\n (yargs) =>\n yargs.positional('publicDirectory', {\n type: 'string',\n description: 'The path to the public directory of your application.',\n demandOption: true,\n }),\n async (cliArguments) => {\n await initializeBrowserServiceWorker({\n publicDirectory: cliArguments.publicDirectory,\n });\n },\n ),\n )\n\n .command('server', 'Manage interceptor servers', (yargs) =>\n yargs.demandCommand().command(\n 'start [-- onReady]',\n 'Start an interceptor server.',\n (yargs) =>\n yargs\n .positional('onReady', {\n description: 'A command to run when the server is ready to accept connections.',\n type: 'string',\n })\n .option('hostname', {\n type: 'string',\n description: 'The hostname to start the server on.',\n alias: 'h',\n default: 'localhost',\n })\n .option('port', {\n type: 'number',\n description: 'The port to start the server on.',\n alias: 'p',\n })\n .option('ephemeral', {\n type: 'boolean',\n description:\n 'Whether the server should stop automatically after the on-ready command finishes. ' +\n 'If no on-ready command is provided and ephemeral is true, the server will stop immediately after ' +\n 'starting.',\n alias: 'e',\n default: false,\n })\n .option('log-unhandled-requests', {\n type: 'boolean',\n description:\n 'Whether to log a warning when no interceptors were found for the base URL of a request. ' +\n 'If an interceptor was matched, the logging behavior for that base URL is configured in the ' +\n 'interceptor itself.',\n alias: 'l',\n }),\n async (cliArguments) => {\n const onReadyCommand = cliArguments._.at(2)?.toString();\n const onReadyCommandArguments = cliArguments._.slice(3).map((argument) => argument.toString());\n\n await startInterceptorServer({\n hostname: cliArguments.hostname,\n port: cliArguments.port,\n ephemeral: cliArguments.ephemeral,\n logUnhandledRequests: cliArguments.logUnhandledRequests,\n onReady: onReadyCommand\n ? {\n command: onReadyCommand.toString(),\n arguments: onReadyCommandArguments,\n }\n : undefined,\n });\n },\n ),\n )\n\n .parse();\n}\n\nexport default runCLI;\n","#!/usr/bin/env node\nimport runCLI from './cli';\n\nvoid runCLI();\n"]}
1
+ {"version":3,"sources":["../package.json","../src/cli/browser/shared/constants.ts","../src/cli/browser/init.ts","../src/utils/processes.ts","../src/cli/server/start.ts","../src/cli/cli.ts","../src/cli/index.ts"],"names":["path","__require","filesystem","logWithPrefix","chalk","__name","createCachedDynamicImport_default","interceptorServer","exitEvent","yargs","hideBin"],"mappings":";;;;;;;;;;;;;;;;;;;AAgBE,IAAW,OAAA,GAAA,kBAAA;;;AChBN,IAAM,wBAA2B,GAAA,sBAAA;;;ACQxC,IAAM,aAAA,GAAgBA,sBAAK,IAAK,CAAAC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,EAAA","file":"cli.js","sourcesContent":["{\n \"name\": \"@zimic/interceptor\",\n \"description\": \"TypeScript-first HTTP request mocking and interceptor\",\n \"keywords\": [\n \"zimic\",\n \"typescript\",\n \"types\",\n \"typegen\",\n \"validation\",\n \"inference\",\n \"http\",\n \"interceptor\",\n \"mock\",\n \"api\",\n \"static\"\n ],\n \"version\": \"0.14.0-canary.22\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/zimicjs/zimic.git\",\n \"directory\": \"packages/zimic-interceptor\"\n },\n \"author\": {\n \"name\": \"Diego Aquino\",\n \"url\": \"https://github.com/diego-aquino\"\n },\n \"private\": false,\n \"publishConfig\": {\n \"access\": \"public\",\n \"provenance\": true\n },\n \"engines\": {\n \"node\": \">=18.13.0\"\n },\n \"license\": \"MIT\",\n \"files\": [\n \"package.json\",\n \"README.md\",\n \"LICENSE.md\",\n \"src\",\n \"!src/**/tests\",\n \"!src/**/__tests__\",\n \"!src/**/*.test.ts\",\n \"dist\",\n \"index.d.ts\",\n \"http.d.ts\",\n \"server.d.ts\"\n ],\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"types\": \"index.d.ts\",\n \"bin\": {\n \"zimic-interceptor\": \"./dist/cli.js\"\n },\n \"exports\": {\n \".\": {\n \"types\": \"./index.d.ts\",\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\",\n \"default\": \"./dist/index.js\"\n },\n \"./http\": {\n \"types\": \"./http.d.ts\",\n \"import\": \"./dist/http.mjs\",\n \"require\": \"./dist/http.js\",\n \"default\": \"./dist/http.js\"\n },\n \"./server\": {\n \"types\": \"./server.d.ts\",\n \"import\": \"./dist/server.mjs\",\n \"require\": \"./dist/server.js\",\n \"default\": \"./dist/server.js\"\n },\n \"./package.json\": \"./package.json\"\n },\n \"scripts\": {\n \"dev\": \"tsup --watch\",\n \"cli\": \"node ./dist/cli.js\",\n \"build\": \"tsup\",\n \"lint\": \"eslint --cache --no-error-on-unmatched-pattern --no-warn-ignored --fix\",\n \"lint:turbo\": \"pnpm lint . --max-warnings 0\",\n \"style\": \"prettier --log-level warn --ignore-unknown --no-error-on-unmatched-pattern --cache\",\n \"style:check\": \"pnpm style --check\",\n \"style:format\": \"pnpm style --write\",\n \"test\": \"dotenv -v NODE_ENV=test -- vitest\",\n \"test:turbo\": \"dotenv -v CI=true -- pnpm run test run --coverage\",\n \"types:check\": \"tsc --noEmit\",\n \"deps:install-playwright\": \"playwright install chromium\",\n \"deps:init-msw\": \"msw init ./public --no-save\",\n \"deps:init\": \"pnpm deps:install-playwright && pnpm deps:init-msw\",\n \"postinstall\": \"node -e \\\"try{require('./dist/scripts/postinstall')}catch(error){console.error(error)}\\\"\",\n \"prepublish:patch-relative-paths\": \"sed -E -i 's/\\\\]\\\\(\\\\.\\\\/([^\\\\)]+)\\\\)/](..\\\\/..\\\\/\\\\1)/g;s/\\\"\\\\.\\\\/([^\\\"]+)\\\"/\\\"..\\\\/..\\\\/\\\\1\\\"/g'\",\n \"prepublishOnly\": \"cp ../../README.md ../../LICENSE.md . && pnpm prepublish:patch-relative-paths README.md\"\n },\n \"dependencies\": {\n \"@whatwg-node/server\": \"0.9.68\",\n \"chalk\": \"4.1.2\",\n \"execa\": \"9.5.2\",\n \"isomorphic-ws\": \"5.0.0\",\n \"msw\": \"2.7.1\",\n \"ws\": \"8.18.1\",\n \"yargs\": \"17.7.2\"\n },\n \"optionalDependencies\": {\n \"bufferutil\": \"4.0.9\"\n },\n \"devDependencies\": {\n \"@types/node\": \"^22.13.5\",\n \"@types/ws\": \"^8.5.14\",\n \"@types/yargs\": \"^17.0.33\",\n \"@vitest/browser\": \"^3.0.6\",\n \"@vitest/coverage-istanbul\": \"^3.0.6\",\n \"@zimic/eslint-config-node\": \"workspace:*\",\n \"@zimic/lint-staged-config\": \"workspace:*\",\n \"@zimic/tsconfig\": \"workspace:*\",\n \"@zimic/utils\": \"workspace:*\",\n \"dotenv-cli\": \"^8.0.0\",\n \"eslint\": \"^9.21.0\",\n \"playwright\": \"^1.50.1\",\n \"tsup\": \"^8.3.6\",\n \"typescript\": \"^5.7.3\",\n \"vitest\": \"^3.0.6\"\n },\n \"peerDependencies\": {\n \"@zimic/http\": \"^0.1.0 || ^0.1.0-canary.0\",\n \"typescript\": \">=4.8.0\"\n },\n \"peerDependenciesMeta\": {\n \"typescript\": {\n \"optional\": true\n }\n }\n}\n","export const SERVICE_WORKER_FILE_NAME = 'mockServiceWorker.js';\n","import chalk from 'chalk';\nimport filesystem from 'fs/promises';\nimport path from 'path';\n\nimport { logWithPrefix } from '@/utils/console';\n\nimport { SERVICE_WORKER_FILE_NAME } from './shared/constants';\n\nconst MSW_ROOT_PATH = path.join(require.resolve('msw'), '..', '..', '..');\nexport const MOCK_SERVICE_WORKER_PATH = path.join(MSW_ROOT_PATH, 'lib', SERVICE_WORKER_FILE_NAME);\n\ninterface BrowserServiceWorkerInitOptions {\n publicDirectory: string;\n}\n\nasync function initializeBrowserServiceWorker({ publicDirectory }: BrowserServiceWorkerInitOptions) {\n const absolutePublicDirectory = path.resolve(publicDirectory);\n await filesystem.mkdir(absolutePublicDirectory, { recursive: true });\n\n const destinationPath = path.join(absolutePublicDirectory, SERVICE_WORKER_FILE_NAME);\n await filesystem.copyFile(MOCK_SERVICE_WORKER_PATH, destinationPath);\n\n logWithPrefix(`Service worker script saved to ${chalk.green(destinationPath)}!`);\n logWithPrefix('You can now use browser interceptors!');\n}\n\nexport default initializeBrowserServiceWorker;\n","import createCachedDynamicImport from '@zimic/utils/import/createCachedDynamicImport';\n\nexport const PROCESS_EXIT_EVENTS = Object.freeze([\n 'beforeExit',\n 'uncaughtExceptionMonitor',\n 'SIGINT',\n 'SIGTERM',\n 'SIGHUP',\n 'SIGBREAK',\n] as const);\n\nexport type ProcessExitEvent = (typeof PROCESS_EXIT_EVENTS)[number];\n\n// Having an undefined exit code means that the process will already exit with the default exit code.\nexport const PROCESS_EXIT_CODE_BY_EXIT_EVENT: Record<string, number | undefined> = {\n beforeExit: undefined,\n uncaughtExceptionMonitor: undefined,\n SIGINT: 130,\n SIGTERM: 143,\n SIGHUP: 129,\n SIGBREAK: 131,\n} satisfies Record<ProcessExitEvent, number | undefined>;\n\nexport const importExeca = createCachedDynamicImport(() => import('execa'));\n\ninterface CommandErrorOptions {\n command?: string[];\n exitCode?: number;\n signal?: NodeJS.Signals;\n originalMessage?: string;\n}\n\nexport class CommandError extends Error {\n static readonly DEFAULT_EXIT_CODE = 1;\n\n readonly command: string[];\n readonly exitCode: number;\n readonly signal?: NodeJS.Signals;\n\n constructor(executable: string, options: CommandErrorOptions) {\n const message = CommandError.createMessage(executable, options);\n super(message);\n\n this.name = 'CommandError';\n this.command = options.command ?? [executable];\n this.exitCode = this.getExitCode(options);\n this.signal = options.signal;\n }\n\n private getExitCode(options: CommandErrorOptions): number {\n const existingExitCode = options.exitCode;\n const exitCodeInferredFromSignal =\n options.signal === undefined ? undefined : PROCESS_EXIT_CODE_BY_EXIT_EVENT[options.signal];\n\n return existingExitCode ?? exitCodeInferredFromSignal ?? CommandError.DEFAULT_EXIT_CODE;\n }\n\n private static createMessage(command: string, options: CommandErrorOptions) {\n const suffix = options.originalMessage ? `: ${options.originalMessage}` : '';\n\n if (options.exitCode === undefined && options.signal === undefined) {\n return `Command '${command}' failed${suffix}`;\n }\n\n const prefix = `Command '${command}' exited `;\n const infix = options.exitCode === undefined ? `after signal ${options.signal}` : `with code ${options.exitCode}`;\n\n return `${prefix}${infix}${suffix}`;\n }\n}\n\nexport async function runCommand(command: string, commandArguments: string[]) {\n const { execa: $, ExecaError } = await importExeca();\n\n try {\n await $(command, commandArguments, { stdio: 'inherit' });\n } catch (error) {\n /* istanbul ignore if -- @preserve\n * This is a safeguard if the error is not an ExecaError. It is not expected to run. */\n if (!(error instanceof ExecaError)) {\n throw error;\n }\n\n const commandError = new CommandError(command, {\n command: [command, ...commandArguments],\n exitCode: error.exitCode,\n signal: error.signal,\n originalMessage: error.originalMessage,\n });\n\n throw commandError;\n }\n}\n","import { InterceptorServer, interceptorServer } from '@/server';\nimport { InterceptorServerOptions } from '@/server/types/options';\nimport { logWithPrefix } from '@/utils/console';\nimport {\n CommandError,\n PROCESS_EXIT_CODE_BY_EXIT_EVENT,\n PROCESS_EXIT_EVENTS,\n ProcessExitEvent,\n runCommand,\n} from '@/utils/processes';\n\ninterface InterceptorServerStartOptions extends InterceptorServerOptions {\n ephemeral: boolean;\n onReady?: {\n command: string;\n arguments: string[];\n };\n}\n\nexport let serverSingleton: InterceptorServer | undefined;\n\nasync function startInterceptorServer({\n hostname,\n port,\n ephemeral,\n logUnhandledRequests,\n onReady,\n}: InterceptorServerStartOptions) {\n const server = interceptorServer.create({\n hostname,\n port,\n logUnhandledRequests,\n });\n\n async function handleExitEvent(exitEvent: ProcessExitEvent | undefined) {\n await server.stop();\n\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n for (const { exitEvent, exitHandler } of exitHandlerGroups) {\n process.off(exitEvent, exitHandler);\n }\n\n const exitCode = exitEvent ? PROCESS_EXIT_CODE_BY_EXIT_EVENT[exitEvent] : undefined;\n if (exitCode !== undefined) {\n process.exit(exitCode);\n }\n }\n\n const exitHandlerGroups = PROCESS_EXIT_EVENTS.map((exitEvent) => ({\n exitEvent,\n exitHandler: handleExitEvent.bind(null, exitEvent),\n }));\n\n for (const { exitEvent, exitHandler } of exitHandlerGroups) {\n process.on(exitEvent, exitHandler);\n }\n\n serverSingleton = server;\n\n await server.start();\n\n logWithPrefix(`${ephemeral ? 'Ephemeral s' : 'S'}erver is running on ${server.httpURL()}`);\n\n if (onReady) {\n try {\n await runCommand(onReady.command, onReady.arguments);\n } catch (error) {\n console.error(error);\n\n /* istanbul ignore if -- @preserve\n * A CommandError is always expected here. */\n if (!(error instanceof CommandError)) {\n throw error;\n }\n\n process.exit(error.exitCode);\n }\n }\n\n if (ephemeral) {\n await handleExitEvent(undefined);\n process.exit(0);\n }\n}\n\nexport default startInterceptorServer;\n","import yargs from 'yargs';\nimport { hideBin } from 'yargs/helpers';\n\nimport { version } from '@@/package.json';\n\nimport initializeBrowserServiceWorker from './browser/init';\nimport startInterceptorServer from './server/start';\n\nasync function runCLI() {\n await yargs(hideBin(process.argv))\n .scriptName('zimic-interceptor')\n .version(version)\n .showHelpOnFail(false)\n .strict()\n\n .command('browser', 'Manage your browser mock configuration', (yargs) =>\n yargs.demandCommand().command(\n 'init <publicDirectory>',\n 'Initialize the browser service worker configuration.',\n (yargs) =>\n yargs.positional('publicDirectory', {\n type: 'string',\n description: 'The path to the public directory of your application.',\n demandOption: true,\n }),\n async (cliArguments) => {\n await initializeBrowserServiceWorker({\n publicDirectory: cliArguments.publicDirectory,\n });\n },\n ),\n )\n\n .command('server', 'Manage interceptor servers', (yargs) =>\n yargs.demandCommand().command(\n 'start [-- onReady]',\n 'Start an interceptor server.',\n (yargs) =>\n yargs\n .positional('onReady', {\n description: 'A command to run when the server is ready to accept connections.',\n type: 'string',\n })\n .option('hostname', {\n type: 'string',\n description: 'The hostname to start the server on.',\n alias: 'h',\n default: 'localhost',\n })\n .option('port', {\n type: 'number',\n description: 'The port to start the server on.',\n alias: 'p',\n })\n .option('ephemeral', {\n type: 'boolean',\n description:\n 'Whether the server should stop automatically after the on-ready command finishes. ' +\n 'If no on-ready command is provided and ephemeral is true, the server will stop immediately after ' +\n 'starting.',\n alias: 'e',\n default: false,\n })\n .option('log-unhandled-requests', {\n type: 'boolean',\n description:\n 'Whether to log a warning when no interceptors were found for the base URL of a request. ' +\n 'If an interceptor was matched, the logging behavior for that base URL is configured in the ' +\n 'interceptor itself.',\n alias: 'l',\n }),\n async (cliArguments) => {\n const onReadyCommand = cliArguments._.at(2)?.toString();\n const onReadyCommandArguments = cliArguments._.slice(3).map((argument) => argument.toString());\n\n await startInterceptorServer({\n hostname: cliArguments.hostname,\n port: cliArguments.port,\n ephemeral: cliArguments.ephemeral,\n logUnhandledRequests: cliArguments.logUnhandledRequests,\n onReady: onReadyCommand\n ? {\n command: onReadyCommand.toString(),\n arguments: onReadyCommandArguments,\n }\n : undefined,\n });\n },\n ),\n )\n\n .parse();\n}\n\nexport default runCLI;\n","#!/usr/bin/env node\nimport runCLI from './cli';\n\nvoid runCLI();\n"]}
package/dist/cli.mjs CHANGED
@@ -8,7 +8,7 @@ import filesystem from 'fs/promises';
8
8
  import path from 'path';
9
9
 
10
10
  // package.json
11
- var version = "0.14.0-canary.20";
11
+ var version = "0.14.0-canary.22";
12
12
 
13
13
  // src/cli/browser/shared/constants.ts
14
14
  var SERVICE_WORKER_FILE_NAME = "mockServiceWorker.js";
package/dist/cli.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../package.json","../src/cli/browser/shared/constants.ts","../src/cli/browser/init.ts","../src/utils/processes.ts","../src/cli/server/start.ts","../src/cli/cli.ts","../src/cli/index.ts"],"names":["exitEvent","yargs"],"mappings":";;;;;;;;;;AAgBE,IAAW,OAAA,GAAA,kBAAA;;;AChBN,IAAM,wBAA2B,GAAA,sBAAA;;;ACQxC,IAAM,aAAA,GAAgB,KAAK,IAAK,CAAA,SAAA,CAAQ,QAAQ,KAAK,CAAA,EAAG,IAAM,EAAA,IAAA,EAAM,IAAI,CAAA;AACjE,IAAM,wBAA2B,GAAA,IAAA,CAAK,IAAK,CAAA,aAAA,EAAe,OAAO,wBAAwB,CAAA;AAMhG,eAAe,8BAAA,CAA+B,EAAE,eAAA,EAAoD,EAAA;AAClG,EAAM,MAAA,uBAAA,GAA0B,IAAK,CAAA,OAAA,CAAQ,eAAe,CAAA;AAC5D,EAAA,MAAM,WAAW,KAAM,CAAA,uBAAA,EAAyB,EAAE,SAAA,EAAW,MAAM,CAAA;AAEnE,EAAA,MAAM,eAAkB,GAAA,IAAA,CAAK,IAAK,CAAA,uBAAA,EAAyB,wBAAwB,CAAA;AACnF,EAAM,MAAA,UAAA,CAAW,QAAS,CAAA,wBAAA,EAA0B,eAAe,CAAA;AAEnE,EAAA,aAAA,CAAc,CAAkC,+BAAA,EAAA,KAAA,CAAM,KAAM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AAG,QAAS,EAAA;AACtD,QAAM,MAAA,uBAAA,GAA0B,YAAa,CAAA,CAAA,CAAE,KAAM,CAAA,CAAC,CAAE,CAAA,GAAA,CAAI,CAAC,QAAA,KAAa,QAAS,CAAA,QAAA,EAAU,CAAA;AAE7F,QAAA,MAAM,aAAuB,CAAA;AAAA,UAC3B,UAAU,YAAa,CAAA,QAAA;AAAA,UACvB,MAAM,YAAa,CAAA,IAAA;AAAA,UACnB,WAAW,YAAa,CAAA,SAAA;AAAA,UACxB,sBAAsB,YAAa,CAAA,oBAAA;AAAA,UACnC,SAAS,cACL,GAAA;AAAA,YACE,OAAA,EAAS,eAAe,QAAS,EAAA;AAAA,YACjC,SAAW,EAAA;AAAA,WAEb,GAAA;AAAA,SACL,CAAA;AAAA;AACH;AACF,IAGD,KAAM,EAAA;AACX;AApFe,MAAA,CAAA,MAAA,EAAA,QAAA,CAAA;AAsFf,IAAO,WAAQ,GAAA,MAAA;;;AC3Ff,KAAK,WAAO,EAAA","file":"cli.mjs","sourcesContent":["{\n \"name\": \"@zimic/interceptor\",\n \"description\": \"TypeScript-first HTTP request mocking and interceptor\",\n \"keywords\": [\n \"zimic\",\n \"typescript\",\n \"types\",\n \"typegen\",\n \"validation\",\n \"inference\",\n \"http\",\n \"interceptor\",\n \"mock\",\n \"api\",\n \"static\"\n ],\n \"version\": \"0.14.0-canary.20\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/zimicjs/zimic.git\",\n \"directory\": \"packages/zimic-interceptor\"\n },\n \"author\": {\n \"name\": \"Diego Aquino\",\n \"url\": \"https://github.com/diego-aquino\"\n },\n \"private\": false,\n \"publishConfig\": {\n \"access\": \"public\",\n \"provenance\": true\n },\n \"engines\": {\n \"node\": \">=18.13.0\"\n },\n \"license\": \"MIT\",\n \"files\": [\n \"package.json\",\n \"README.md\",\n \"LICENSE.md\",\n \"src\",\n \"!src/**/tests\",\n \"!src/**/__tests__\",\n \"!src/**/*.test.ts\",\n \"dist\",\n \"index.d.ts\",\n \"http.d.ts\",\n \"server.d.ts\"\n ],\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"types\": \"index.d.ts\",\n \"bin\": {\n \"zimic-interceptor\": \"./dist/cli.js\"\n },\n \"exports\": {\n \".\": {\n \"types\": \"./index.d.ts\",\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\",\n \"default\": \"./dist/index.js\"\n },\n \"./http\": {\n \"types\": \"./http.d.ts\",\n \"import\": \"./dist/http.mjs\",\n \"require\": \"./dist/http.js\",\n \"default\": \"./dist/http.js\"\n },\n \"./server\": {\n \"types\": \"./server.d.ts\",\n \"import\": \"./dist/server.mjs\",\n \"require\": \"./dist/server.js\",\n \"default\": \"./dist/server.js\"\n },\n \"./package.json\": \"./package.json\"\n },\n \"scripts\": {\n \"dev\": \"tsup --watch\",\n \"cli\": \"node ./dist/cli.js\",\n \"build\": \"tsup\",\n \"lint\": \"eslint --cache --no-error-on-unmatched-pattern --no-warn-ignored --fix\",\n \"lint:turbo\": \"pnpm lint . --max-warnings 0\",\n \"style\": \"prettier --log-level warn --ignore-unknown --no-error-on-unmatched-pattern --cache\",\n \"style:check\": \"pnpm style --check\",\n \"style:format\": \"pnpm style --write\",\n \"test\": \"dotenv -v NODE_ENV=test -- vitest\",\n \"test:turbo\": \"dotenv -v CI=true -- pnpm run test run --coverage\",\n \"types:check\": \"tsc --noEmit\",\n \"deps:install-playwright\": \"playwright install chromium\",\n \"deps:init-msw\": \"msw init ./public --no-save\",\n \"deps:init\": \"pnpm deps:install-playwright && pnpm deps:init-msw\",\n \"postinstall\": \"node -e \\\"try{require('./dist/scripts/postinstall')}catch(error){console.error(error)}\\\"\",\n \"prepublish:patch-relative-paths\": \"sed -E -i 's/\\\\]\\\\(\\\\.\\\\/([^\\\\)]+)\\\\)/](..\\\\/..\\\\/\\\\1)/g;s/\\\"\\\\.\\\\/([^\\\"]+)\\\"/\\\"..\\\\/..\\\\/\\\\1\\\"/g'\",\n \"prepublishOnly\": \"cp ../../README.md ../../LICENSE.md . && pnpm prepublish:patch-relative-paths README.md\"\n },\n \"dependencies\": {\n \"@whatwg-node/server\": \"0.9.68\",\n \"@zimic/utils\": \"workspace:*\",\n \"chalk\": \"4.1.2\",\n \"execa\": \"9.5.2\",\n \"isomorphic-ws\": \"5.0.0\",\n \"msw\": \"2.7.1\",\n \"ws\": \"8.18.1\",\n \"yargs\": \"17.7.2\"\n },\n \"optionalDependencies\": {\n \"bufferutil\": \"4.0.9\"\n },\n \"devDependencies\": {\n \"@types/node\": \"^22.13.5\",\n \"@types/ws\": \"^8.5.14\",\n \"@types/yargs\": \"^17.0.33\",\n \"@vitest/browser\": \"^3.0.6\",\n \"@vitest/coverage-istanbul\": \"^3.0.6\",\n \"@zimic/eslint-config-node\": \"workspace:*\",\n \"@zimic/lint-staged-config\": \"workspace:*\",\n \"@zimic/tsconfig\": \"workspace:*\",\n \"dotenv-cli\": \"^8.0.0\",\n \"eslint\": \"^9.21.0\",\n \"playwright\": \"^1.50.1\",\n \"tsup\": \"^8.3.6\",\n \"typescript\": \"^5.7.3\",\n \"vitest\": \"^3.0.6\"\n },\n \"peerDependencies\": {\n \"@zimic/http\": \"^0.1.0 || ^0.1.0-canary.0\",\n \"typescript\": \">=4.8.0\"\n },\n \"peerDependenciesMeta\": {\n \"typescript\": {\n \"optional\": true\n }\n }\n}\n","export const SERVICE_WORKER_FILE_NAME = 'mockServiceWorker.js';\n","import chalk from 'chalk';\nimport filesystem from 'fs/promises';\nimport path from 'path';\n\nimport { logWithPrefix } from '@/utils/console';\n\nimport { SERVICE_WORKER_FILE_NAME } from './shared/constants';\n\nconst MSW_ROOT_PATH = path.join(require.resolve('msw'), '..', '..', '..');\nexport const MOCK_SERVICE_WORKER_PATH = path.join(MSW_ROOT_PATH, 'lib', SERVICE_WORKER_FILE_NAME);\n\ninterface BrowserServiceWorkerInitOptions {\n publicDirectory: string;\n}\n\nasync function initializeBrowserServiceWorker({ publicDirectory }: BrowserServiceWorkerInitOptions) {\n const absolutePublicDirectory = path.resolve(publicDirectory);\n await filesystem.mkdir(absolutePublicDirectory, { recursive: true });\n\n const destinationPath = path.join(absolutePublicDirectory, SERVICE_WORKER_FILE_NAME);\n await filesystem.copyFile(MOCK_SERVICE_WORKER_PATH, destinationPath);\n\n logWithPrefix(`Service worker script saved to ${chalk.green(destinationPath)}!`);\n logWithPrefix('You can now use browser interceptors!');\n}\n\nexport default initializeBrowserServiceWorker;\n","import createCachedDynamicImport from '@zimic/utils/import/createCachedDynamicImport';\n\nexport const PROCESS_EXIT_EVENTS = Object.freeze([\n 'beforeExit',\n 'uncaughtExceptionMonitor',\n 'SIGINT',\n 'SIGTERM',\n 'SIGHUP',\n 'SIGBREAK',\n] as const);\n\nexport type ProcessExitEvent = (typeof PROCESS_EXIT_EVENTS)[number];\n\n// Having an undefined exit code means that the process will already exit with the default exit code.\nexport const PROCESS_EXIT_CODE_BY_EXIT_EVENT: Record<string, number | undefined> = {\n beforeExit: undefined,\n uncaughtExceptionMonitor: undefined,\n SIGINT: 130,\n SIGTERM: 143,\n SIGHUP: 129,\n SIGBREAK: 131,\n} satisfies Record<ProcessExitEvent, number | undefined>;\n\nexport const importExeca = createCachedDynamicImport(() => import('execa'));\n\ninterface CommandErrorOptions {\n command?: string[];\n exitCode?: number;\n signal?: NodeJS.Signals;\n originalMessage?: string;\n}\n\nexport class CommandError extends Error {\n static readonly DEFAULT_EXIT_CODE = 1;\n\n readonly command: string[];\n readonly exitCode: number;\n readonly signal?: NodeJS.Signals;\n\n constructor(executable: string, options: CommandErrorOptions) {\n const message = CommandError.createMessage(executable, options);\n super(message);\n\n this.name = 'CommandError';\n this.command = options.command ?? [executable];\n this.exitCode = this.getExitCode(options);\n this.signal = options.signal;\n }\n\n private getExitCode(options: CommandErrorOptions): number {\n const existingExitCode = options.exitCode;\n const exitCodeInferredFromSignal =\n options.signal === undefined ? undefined : PROCESS_EXIT_CODE_BY_EXIT_EVENT[options.signal];\n\n return existingExitCode ?? exitCodeInferredFromSignal ?? CommandError.DEFAULT_EXIT_CODE;\n }\n\n private static createMessage(command: string, options: CommandErrorOptions) {\n const suffix = options.originalMessage ? `: ${options.originalMessage}` : '';\n\n if (options.exitCode === undefined && options.signal === undefined) {\n return `Command '${command}' failed${suffix}`;\n }\n\n const prefix = `Command '${command}' exited `;\n const infix = options.exitCode === undefined ? `after signal ${options.signal}` : `with code ${options.exitCode}`;\n\n return `${prefix}${infix}${suffix}`;\n }\n}\n\nexport async function runCommand(command: string, commandArguments: string[]) {\n const { execa: $, ExecaError } = await importExeca();\n\n try {\n await $(command, commandArguments, { stdio: 'inherit' });\n } catch (error) {\n /* istanbul ignore if -- @preserve\n * This is a safeguard if the error is not an ExecaError. It is not expected to run. */\n if (!(error instanceof ExecaError)) {\n throw error;\n }\n\n const commandError = new CommandError(command, {\n command: [command, ...commandArguments],\n exitCode: error.exitCode,\n signal: error.signal,\n originalMessage: error.originalMessage,\n });\n\n throw commandError;\n }\n}\n","import { InterceptorServer, interceptorServer } from '@/server';\nimport { InterceptorServerOptions } from '@/server/types/options';\nimport { logWithPrefix } from '@/utils/console';\nimport {\n CommandError,\n PROCESS_EXIT_CODE_BY_EXIT_EVENT,\n PROCESS_EXIT_EVENTS,\n ProcessExitEvent,\n runCommand,\n} from '@/utils/processes';\n\ninterface InterceptorServerStartOptions extends InterceptorServerOptions {\n ephemeral: boolean;\n onReady?: {\n command: string;\n arguments: string[];\n };\n}\n\nexport let serverSingleton: InterceptorServer | undefined;\n\nasync function startInterceptorServer({\n hostname,\n port,\n ephemeral,\n logUnhandledRequests,\n onReady,\n}: InterceptorServerStartOptions) {\n const server = interceptorServer.create({\n hostname,\n port,\n logUnhandledRequests,\n });\n\n async function handleExitEvent(exitEvent: ProcessExitEvent | undefined) {\n await server.stop();\n\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n for (const { exitEvent, exitHandler } of exitHandlerGroups) {\n process.off(exitEvent, exitHandler);\n }\n\n const exitCode = exitEvent ? PROCESS_EXIT_CODE_BY_EXIT_EVENT[exitEvent] : undefined;\n if (exitCode !== undefined) {\n process.exit(exitCode);\n }\n }\n\n const exitHandlerGroups = PROCESS_EXIT_EVENTS.map((exitEvent) => ({\n exitEvent,\n exitHandler: handleExitEvent.bind(null, exitEvent),\n }));\n\n for (const { exitEvent, exitHandler } of exitHandlerGroups) {\n process.on(exitEvent, exitHandler);\n }\n\n serverSingleton = server;\n\n await server.start();\n\n logWithPrefix(`${ephemeral ? 'Ephemeral s' : 'S'}erver is running on ${server.httpURL()}`);\n\n if (onReady) {\n try {\n await runCommand(onReady.command, onReady.arguments);\n } catch (error) {\n console.error(error);\n\n /* istanbul ignore if -- @preserve\n * A CommandError is always expected here. */\n if (!(error instanceof CommandError)) {\n throw error;\n }\n\n process.exit(error.exitCode);\n }\n }\n\n if (ephemeral) {\n await handleExitEvent(undefined);\n process.exit(0);\n }\n}\n\nexport default startInterceptorServer;\n","import yargs from 'yargs';\nimport { hideBin } from 'yargs/helpers';\n\nimport { version } from '@@/package.json';\n\nimport initializeBrowserServiceWorker from './browser/init';\nimport startInterceptorServer from './server/start';\n\nasync function runCLI() {\n await yargs(hideBin(process.argv))\n .scriptName('zimic-interceptor')\n .version(version)\n .showHelpOnFail(false)\n .strict()\n\n .command('browser', 'Manage your browser mock configuration', (yargs) =>\n yargs.demandCommand().command(\n 'init <publicDirectory>',\n 'Initialize the browser service worker configuration.',\n (yargs) =>\n yargs.positional('publicDirectory', {\n type: 'string',\n description: 'The path to the public directory of your application.',\n demandOption: true,\n }),\n async (cliArguments) => {\n await initializeBrowserServiceWorker({\n publicDirectory: cliArguments.publicDirectory,\n });\n },\n ),\n )\n\n .command('server', 'Manage interceptor servers', (yargs) =>\n yargs.demandCommand().command(\n 'start [-- onReady]',\n 'Start an interceptor server.',\n (yargs) =>\n yargs\n .positional('onReady', {\n description: 'A command to run when the server is ready to accept connections.',\n type: 'string',\n })\n .option('hostname', {\n type: 'string',\n description: 'The hostname to start the server on.',\n alias: 'h',\n default: 'localhost',\n })\n .option('port', {\n type: 'number',\n description: 'The port to start the server on.',\n alias: 'p',\n })\n .option('ephemeral', {\n type: 'boolean',\n description:\n 'Whether the server should stop automatically after the on-ready command finishes. ' +\n 'If no on-ready command is provided and ephemeral is true, the server will stop immediately after ' +\n 'starting.',\n alias: 'e',\n default: false,\n })\n .option('log-unhandled-requests', {\n type: 'boolean',\n description:\n 'Whether to log a warning when no interceptors were found for the base URL of a request. ' +\n 'If an interceptor was matched, the logging behavior for that base URL is configured in the ' +\n 'interceptor itself.',\n alias: 'l',\n }),\n async (cliArguments) => {\n const onReadyCommand = cliArguments._.at(2)?.toString();\n const onReadyCommandArguments = cliArguments._.slice(3).map((argument) => argument.toString());\n\n await startInterceptorServer({\n hostname: cliArguments.hostname,\n port: cliArguments.port,\n ephemeral: cliArguments.ephemeral,\n logUnhandledRequests: cliArguments.logUnhandledRequests,\n onReady: onReadyCommand\n ? {\n command: onReadyCommand.toString(),\n arguments: onReadyCommandArguments,\n }\n : undefined,\n });\n },\n ),\n )\n\n .parse();\n}\n\nexport default runCLI;\n","#!/usr/bin/env node\nimport runCLI from './cli';\n\nvoid runCLI();\n"]}
1
+ {"version":3,"sources":["../package.json","../src/cli/browser/shared/constants.ts","../src/cli/browser/init.ts","../src/utils/processes.ts","../src/cli/server/start.ts","../src/cli/cli.ts","../src/cli/index.ts"],"names":["exitEvent","yargs"],"mappings":";;;;;;;;;;AAgBE,IAAW,OAAA,GAAA,kBAAA;;;AChBN,IAAM,wBAA2B,GAAA,sBAAA;;;ACQxC,IAAM,aAAA,GAAgB,KAAK,IAAK,CAAA,SAAA,CAAQ,QAAQ,KAAK,CAAA,EAAG,IAAM,EAAA,IAAA,EAAM,IAAI,CAAA;AACjE,IAAM,wBAA2B,GAAA,IAAA,CAAK,IAAK,CAAA,aAAA,EAAe,OAAO,wBAAwB,CAAA;AAMhG,eAAe,8BAAA,CAA+B,EAAE,eAAA,EAAoD,EAAA;AAClG,EAAM,M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,QACnB,IAAM,EAAA,SAAA;AAAA,QACN,WACE,EAAA,8LAAA;AAAA,QAGF,KAAO,EAAA,GAAA;AAAA,QACP,OAAS,EAAA;AAAA,OACV,CACA,CAAA,MAAA,CAAO,wBAA0B,EAAA;AAAA,QAChC,IAAM,EAAA,SAAA;AAAA,QACN,WACE,EAAA,wMAAA;AAAA,QAGF,KAAO,EAAA;AAAA,OACR,CAAA;AAAA,MACL,OAAO,YAAiB,KAAA;AACtB,QAAA,MAAM,iBAAiB,YAAa,CAAA,CAAA,CAAE,EAAG,CAAA,CAAC,GAAG,QAAS,EAAA;AACtD,QAAM,MAAA,uBAAA,GAA0B,YAAa,CAAA,CAAA,CAAE,KAAM,CAAA,CAAC,CAAE,CAAA,GAAA,CAAI,CAAC,QAAA,KAAa,QAAS,CAAA,QAAA,EAAU,CAAA;AAE7F,QAAA,MAAM,aAAuB,CAAA;AAAA,UAC3B,UAAU,YAAa,CAAA,QAAA;AAAA,UACvB,MAAM,YAAa,CAAA,IAAA;AAAA,UACnB,WAAW,YAAa,CAAA,SAAA;AAAA,UACxB,sBAAsB,YAAa,CAAA,oBAAA;AAAA,UACnC,SAAS,cACL,GAAA;AAAA,YACE,OAAA,EAAS,eAAe,QAAS,EAAA;AAAA,YACjC,SAAW,EAAA;AAAA,WAEb,GAAA;AAAA,SACL,CAAA;AAAA;AACH;AACF,IAGD,KAAM,EAAA;AACX;AApFe,MAAA,CAAA,MAAA,EAAA,QAAA,CAAA;AAsFf,IAAO,WAAQ,GAAA,MAAA;;;AC3Ff,KAAK,WAAO,EAAA","file":"cli.mjs","sourcesContent":["{\n \"name\": \"@zimic/interceptor\",\n \"description\": \"TypeScript-first HTTP request mocking and interceptor\",\n \"keywords\": [\n \"zimic\",\n \"typescript\",\n \"types\",\n \"typegen\",\n \"validation\",\n \"inference\",\n \"http\",\n \"interceptor\",\n \"mock\",\n \"api\",\n \"static\"\n ],\n \"version\": \"0.14.0-canary.22\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/zimicjs/zimic.git\",\n \"directory\": \"packages/zimic-interceptor\"\n },\n \"author\": {\n \"name\": \"Diego Aquino\",\n \"url\": \"https://github.com/diego-aquino\"\n },\n \"private\": false,\n \"publishConfig\": {\n \"access\": \"public\",\n \"provenance\": true\n },\n \"engines\": {\n \"node\": \">=18.13.0\"\n },\n \"license\": \"MIT\",\n \"files\": [\n \"package.json\",\n \"README.md\",\n \"LICENSE.md\",\n \"src\",\n \"!src/**/tests\",\n \"!src/**/__tests__\",\n \"!src/**/*.test.ts\",\n \"dist\",\n \"index.d.ts\",\n \"http.d.ts\",\n \"server.d.ts\"\n ],\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"types\": \"index.d.ts\",\n \"bin\": {\n \"zimic-interceptor\": \"./dist/cli.js\"\n },\n \"exports\": {\n \".\": {\n \"types\": \"./index.d.ts\",\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\",\n \"default\": \"./dist/index.js\"\n },\n \"./http\": {\n \"types\": \"./http.d.ts\",\n \"import\": \"./dist/http.mjs\",\n \"require\": \"./dist/http.js\",\n \"default\": \"./dist/http.js\"\n },\n \"./server\": {\n \"types\": \"./server.d.ts\",\n \"import\": \"./dist/server.mjs\",\n \"require\": \"./dist/server.js\",\n \"default\": \"./dist/server.js\"\n },\n \"./package.json\": \"./package.json\"\n },\n \"scripts\": {\n \"dev\": \"tsup --watch\",\n \"cli\": \"node ./dist/cli.js\",\n \"build\": \"tsup\",\n \"lint\": \"eslint --cache --no-error-on-unmatched-pattern --no-warn-ignored --fix\",\n \"lint:turbo\": \"pnpm lint . --max-warnings 0\",\n \"style\": \"prettier --log-level warn --ignore-unknown --no-error-on-unmatched-pattern --cache\",\n \"style:check\": \"pnpm style --check\",\n \"style:format\": \"pnpm style --write\",\n \"test\": \"dotenv -v NODE_ENV=test -- vitest\",\n \"test:turbo\": \"dotenv -v CI=true -- pnpm run test run --coverage\",\n \"types:check\": \"tsc --noEmit\",\n \"deps:install-playwright\": \"playwright install chromium\",\n \"deps:init-msw\": \"msw init ./public --no-save\",\n \"deps:init\": \"pnpm deps:install-playwright && pnpm deps:init-msw\",\n \"postinstall\": \"node -e \\\"try{require('./dist/scripts/postinstall')}catch(error){console.error(error)}\\\"\",\n \"prepublish:patch-relative-paths\": \"sed -E -i 's/\\\\]\\\\(\\\\.\\\\/([^\\\\)]+)\\\\)/](..\\\\/..\\\\/\\\\1)/g;s/\\\"\\\\.\\\\/([^\\\"]+)\\\"/\\\"..\\\\/..\\\\/\\\\1\\\"/g'\",\n \"prepublishOnly\": \"cp ../../README.md ../../LICENSE.md . && pnpm prepublish:patch-relative-paths README.md\"\n },\n \"dependencies\": {\n \"@whatwg-node/server\": \"0.9.68\",\n \"chalk\": \"4.1.2\",\n \"execa\": \"9.5.2\",\n \"isomorphic-ws\": \"5.0.0\",\n \"msw\": \"2.7.1\",\n \"ws\": \"8.18.1\",\n \"yargs\": \"17.7.2\"\n },\n \"optionalDependencies\": {\n \"bufferutil\": \"4.0.9\"\n },\n \"devDependencies\": {\n \"@types/node\": \"^22.13.5\",\n \"@types/ws\": \"^8.5.14\",\n \"@types/yargs\": \"^17.0.33\",\n \"@vitest/browser\": \"^3.0.6\",\n \"@vitest/coverage-istanbul\": \"^3.0.6\",\n \"@zimic/eslint-config-node\": \"workspace:*\",\n \"@zimic/lint-staged-config\": \"workspace:*\",\n \"@zimic/tsconfig\": \"workspace:*\",\n \"@zimic/utils\": \"workspace:*\",\n \"dotenv-cli\": \"^8.0.0\",\n \"eslint\": \"^9.21.0\",\n \"playwright\": \"^1.50.1\",\n \"tsup\": \"^8.3.6\",\n \"typescript\": \"^5.7.3\",\n \"vitest\": \"^3.0.6\"\n },\n \"peerDependencies\": {\n \"@zimic/http\": \"^0.1.0 || ^0.1.0-canary.0\",\n \"typescript\": \">=4.8.0\"\n },\n \"peerDependenciesMeta\": {\n \"typescript\": {\n \"optional\": true\n }\n }\n}\n","export const SERVICE_WORKER_FILE_NAME = 'mockServiceWorker.js';\n","import chalk from 'chalk';\nimport filesystem from 'fs/promises';\nimport path from 'path';\n\nimport { logWithPrefix } from '@/utils/console';\n\nimport { SERVICE_WORKER_FILE_NAME } from './shared/constants';\n\nconst MSW_ROOT_PATH = path.join(require.resolve('msw'), '..', '..', '..');\nexport const MOCK_SERVICE_WORKER_PATH = path.join(MSW_ROOT_PATH, 'lib', SERVICE_WORKER_FILE_NAME);\n\ninterface BrowserServiceWorkerInitOptions {\n publicDirectory: string;\n}\n\nasync function initializeBrowserServiceWorker({ publicDirectory }: BrowserServiceWorkerInitOptions) {\n const absolutePublicDirectory = path.resolve(publicDirectory);\n await filesystem.mkdir(absolutePublicDirectory, { recursive: true });\n\n const destinationPath = path.join(absolutePublicDirectory, SERVICE_WORKER_FILE_NAME);\n await filesystem.copyFile(MOCK_SERVICE_WORKER_PATH, destinationPath);\n\n logWithPrefix(`Service worker script saved to ${chalk.green(destinationPath)}!`);\n logWithPrefix('You can now use browser interceptors!');\n}\n\nexport default initializeBrowserServiceWorker;\n","import createCachedDynamicImport from '@zimic/utils/import/createCachedDynamicImport';\n\nexport const PROCESS_EXIT_EVENTS = Object.freeze([\n 'beforeExit',\n 'uncaughtExceptionMonitor',\n 'SIGINT',\n 'SIGTERM',\n 'SIGHUP',\n 'SIGBREAK',\n] as const);\n\nexport type ProcessExitEvent = (typeof PROCESS_EXIT_EVENTS)[number];\n\n// Having an undefined exit code means that the process will already exit with the default exit code.\nexport const PROCESS_EXIT_CODE_BY_EXIT_EVENT: Record<string, number | undefined> = {\n beforeExit: undefined,\n uncaughtExceptionMonitor: undefined,\n SIGINT: 130,\n SIGTERM: 143,\n SIGHUP: 129,\n SIGBREAK: 131,\n} satisfies Record<ProcessExitEvent, number | undefined>;\n\nexport const importExeca = createCachedDynamicImport(() => import('execa'));\n\ninterface CommandErrorOptions {\n command?: string[];\n exitCode?: number;\n signal?: NodeJS.Signals;\n originalMessage?: string;\n}\n\nexport class CommandError extends Error {\n static readonly DEFAULT_EXIT_CODE = 1;\n\n readonly command: string[];\n readonly exitCode: number;\n readonly signal?: NodeJS.Signals;\n\n constructor(executable: string, options: CommandErrorOptions) {\n const message = CommandError.createMessage(executable, options);\n super(message);\n\n this.name = 'CommandError';\n this.command = options.command ?? [executable];\n this.exitCode = this.getExitCode(options);\n this.signal = options.signal;\n }\n\n private getExitCode(options: CommandErrorOptions): number {\n const existingExitCode = options.exitCode;\n const exitCodeInferredFromSignal =\n options.signal === undefined ? undefined : PROCESS_EXIT_CODE_BY_EXIT_EVENT[options.signal];\n\n return existingExitCode ?? exitCodeInferredFromSignal ?? CommandError.DEFAULT_EXIT_CODE;\n }\n\n private static createMessage(command: string, options: CommandErrorOptions) {\n const suffix = options.originalMessage ? `: ${options.originalMessage}` : '';\n\n if (options.exitCode === undefined && options.signal === undefined) {\n return `Command '${command}' failed${suffix}`;\n }\n\n const prefix = `Command '${command}' exited `;\n const infix = options.exitCode === undefined ? `after signal ${options.signal}` : `with code ${options.exitCode}`;\n\n return `${prefix}${infix}${suffix}`;\n }\n}\n\nexport async function runCommand(command: string, commandArguments: string[]) {\n const { execa: $, ExecaError } = await importExeca();\n\n try {\n await $(command, commandArguments, { stdio: 'inherit' });\n } catch (error) {\n /* istanbul ignore if -- @preserve\n * This is a safeguard if the error is not an ExecaError. It is not expected to run. */\n if (!(error instanceof ExecaError)) {\n throw error;\n }\n\n const commandError = new CommandError(command, {\n command: [command, ...commandArguments],\n exitCode: error.exitCode,\n signal: error.signal,\n originalMessage: error.originalMessage,\n });\n\n throw commandError;\n }\n}\n","import { InterceptorServer, interceptorServer } from '@/server';\nimport { InterceptorServerOptions } from '@/server/types/options';\nimport { logWithPrefix } from '@/utils/console';\nimport {\n CommandError,\n PROCESS_EXIT_CODE_BY_EXIT_EVENT,\n PROCESS_EXIT_EVENTS,\n ProcessExitEvent,\n runCommand,\n} from '@/utils/processes';\n\ninterface InterceptorServerStartOptions extends InterceptorServerOptions {\n ephemeral: boolean;\n onReady?: {\n command: string;\n arguments: string[];\n };\n}\n\nexport let serverSingleton: InterceptorServer | undefined;\n\nasync function startInterceptorServer({\n hostname,\n port,\n ephemeral,\n logUnhandledRequests,\n onReady,\n}: InterceptorServerStartOptions) {\n const server = interceptorServer.create({\n hostname,\n port,\n logUnhandledRequests,\n });\n\n async function handleExitEvent(exitEvent: ProcessExitEvent | undefined) {\n await server.stop();\n\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n for (const { exitEvent, exitHandler } of exitHandlerGroups) {\n process.off(exitEvent, exitHandler);\n }\n\n const exitCode = exitEvent ? PROCESS_EXIT_CODE_BY_EXIT_EVENT[exitEvent] : undefined;\n if (exitCode !== undefined) {\n process.exit(exitCode);\n }\n }\n\n const exitHandlerGroups = PROCESS_EXIT_EVENTS.map((exitEvent) => ({\n exitEvent,\n exitHandler: handleExitEvent.bind(null, exitEvent),\n }));\n\n for (const { exitEvent, exitHandler } of exitHandlerGroups) {\n process.on(exitEvent, exitHandler);\n }\n\n serverSingleton = server;\n\n await server.start();\n\n logWithPrefix(`${ephemeral ? 'Ephemeral s' : 'S'}erver is running on ${server.httpURL()}`);\n\n if (onReady) {\n try {\n await runCommand(onReady.command, onReady.arguments);\n } catch (error) {\n console.error(error);\n\n /* istanbul ignore if -- @preserve\n * A CommandError is always expected here. */\n if (!(error instanceof CommandError)) {\n throw error;\n }\n\n process.exit(error.exitCode);\n }\n }\n\n if (ephemeral) {\n await handleExitEvent(undefined);\n process.exit(0);\n }\n}\n\nexport default startInterceptorServer;\n","import yargs from 'yargs';\nimport { hideBin } from 'yargs/helpers';\n\nimport { version } from '@@/package.json';\n\nimport initializeBrowserServiceWorker from './browser/init';\nimport startInterceptorServer from './server/start';\n\nasync function runCLI() {\n await yargs(hideBin(process.argv))\n .scriptName('zimic-interceptor')\n .version(version)\n .showHelpOnFail(false)\n .strict()\n\n .command('browser', 'Manage your browser mock configuration', (yargs) =>\n yargs.demandCommand().command(\n 'init <publicDirectory>',\n 'Initialize the browser service worker configuration.',\n (yargs) =>\n yargs.positional('publicDirectory', {\n type: 'string',\n description: 'The path to the public directory of your application.',\n demandOption: true,\n }),\n async (cliArguments) => {\n await initializeBrowserServiceWorker({\n publicDirectory: cliArguments.publicDirectory,\n });\n },\n ),\n )\n\n .command('server', 'Manage interceptor servers', (yargs) =>\n yargs.demandCommand().command(\n 'start [-- onReady]',\n 'Start an interceptor server.',\n (yargs) =>\n yargs\n .positional('onReady', {\n description: 'A command to run when the server is ready to accept connections.',\n type: 'string',\n })\n .option('hostname', {\n type: 'string',\n description: 'The hostname to start the server on.',\n alias: 'h',\n default: 'localhost',\n })\n .option('port', {\n type: 'number',\n description: 'The port to start the server on.',\n alias: 'p',\n })\n .option('ephemeral', {\n type: 'boolean',\n description:\n 'Whether the server should stop automatically after the on-ready command finishes. ' +\n 'If no on-ready command is provided and ephemeral is true, the server will stop immediately after ' +\n 'starting.',\n alias: 'e',\n default: false,\n })\n .option('log-unhandled-requests', {\n type: 'boolean',\n description:\n 'Whether to log a warning when no interceptors were found for the base URL of a request. ' +\n 'If an interceptor was matched, the logging behavior for that base URL is configured in the ' +\n 'interceptor itself.',\n alias: 'l',\n }),\n async (cliArguments) => {\n const onReadyCommand = cliArguments._.at(2)?.toString();\n const onReadyCommandArguments = cliArguments._.slice(3).map((argument) => argument.toString());\n\n await startInterceptorServer({\n hostname: cliArguments.hostname,\n port: cliArguments.port,\n ephemeral: cliArguments.ephemeral,\n logUnhandledRequests: cliArguments.logUnhandledRequests,\n onReady: onReadyCommand\n ? {\n command: onReadyCommand.toString(),\n arguments: onReadyCommandArguments,\n }\n : undefined,\n });\n },\n ),\n )\n\n .parse();\n}\n\nexport default runCLI;\n","#!/usr/bin/env node\nimport runCLI from './cli';\n\nvoid runCLI();\n"]}
package/dist/http.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { HttpMethodSchema, HttpStatusCode, HttpRequest, HttpHeaders, HttpRequestHeadersSchema, InferPathParams, HttpSearchParams, HttpRequestSearchParamsSchema, HttpRequestBodySchema, HttpResponse, HttpResponseHeadersSchema, HttpResponseBodySchema, HttpResponseSchema, HttpHeadersInit, HttpSchema, HttpBody, HttpSchemaPath, HttpSchemaMethod, HttpHeadersSchema, HttpSearchParamsSchema, HttpFormData, HttpResponseSchemaStatusCode, HttpMethod, LiteralHttpSchemaPathFromNonLiteral } from '@zimic/http';
1
+ import { HttpMethodSchema, HttpStatusCode, HttpRequest, HttpHeaders, HttpRequestHeadersSchema, InferPathParams, HttpSearchParams, HttpRequestSearchParamsSchema, HttpRequestBodySchema, HttpResponse, HttpResponseHeadersSchema, HttpResponseBodySchema, HttpResponseSchema, HttpHeadersInit, HttpSchema, HttpBody, HttpSchemaMethod, HttpSchemaPath, HttpHeadersSchema, HttpSearchParamsSchema, HttpFormData, HttpResponseSchemaStatusCode, HttpMethod, LiteralHttpSchemaPathFromNonLiteral } from '@zimic/http';
2
2
  import { Default, PossiblePromise, ReplaceBy, IfNever, DeepPartial, Range } from '@zimic/utils/types';
3
3
 
4
4
  type HttpRequestHandlerResponseWithBody<ResponseSchema extends HttpResponseSchema> = unknown extends ResponseSchema['body'] ? {
@@ -237,42 +237,42 @@ type PartialHttpHeadersOrSchema<Schema extends HttpHeadersSchema> = IfNever<Sche
237
237
  *
238
238
  * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
239
239
  */
240
- type HttpRequestHandlerHeadersStaticRestriction<Schema extends HttpSchema, Path extends HttpSchemaPath<Schema, Method>, Method extends HttpSchemaMethod<Schema>> = PartialHttpHeadersOrSchema<HttpRequestHeadersSchema<Default<Schema[Path][Method]>>>;
240
+ type HttpRequestHandlerHeadersStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = PartialHttpHeadersOrSchema<HttpRequestHeadersSchema<Default<Schema[Path][Method]>>>;
241
241
  type PartialHttpSearchParamsOrSchema<Schema extends HttpSearchParamsSchema> = IfNever<Schema, never, Partial<Schema> | HttpSearchParams<Partial<Schema>> | HttpSearchParams<Schema>>;
242
242
  /**
243
243
  * A static search params restriction to match intercepted requests.
244
244
  *
245
245
  * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
246
246
  */
247
- type HttpRequestHandlerSearchParamsStaticRestriction<Schema extends HttpSchema, Path extends HttpSchemaPath<Schema, Method>, Method extends HttpSchemaMethod<Schema>> = PartialHttpSearchParamsOrSchema<HttpRequestSearchParamsSchema<Default<Schema[Path][Method]>>>;
247
+ type HttpRequestHandlerSearchParamsStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = PartialHttpSearchParamsOrSchema<HttpRequestSearchParamsSchema<Default<Schema[Path][Method]>>>;
248
248
  type PartialBodyOrSchema<Body extends HttpBody> = Body extends HttpFormData<infer Schema> ? HttpFormData<Partial<Schema>> | HttpFormData<Schema> : Body extends HttpSearchParams<infer Schema> ? HttpSearchParams<Partial<Schema>> | HttpSearchParams<Schema> : Body extends Blob ? Body : DeepPartial<Body>;
249
249
  /**
250
250
  * A static body restriction to match intercepted requests.
251
251
  *
252
252
  * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
253
253
  */
254
- type HttpRequestHandlerBodyStaticRestriction<Schema extends HttpSchema, Path extends HttpSchemaPath<Schema, Method>, Method extends HttpSchemaMethod<Schema>> = PartialBodyOrSchema<HttpRequestBodySchema<Default<Schema[Path][Method]>>>;
254
+ type HttpRequestHandlerBodyStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = PartialBodyOrSchema<HttpRequestBodySchema<Default<Schema[Path][Method]>>>;
255
255
  /**
256
256
  * A static restriction to match intercepted requests.
257
257
  *
258
258
  * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
259
259
  */
260
- interface HttpRequestHandlerStaticRestriction<Schema extends HttpSchema, Path extends HttpSchemaPath<Schema, Method>, Method extends HttpSchemaMethod<Schema>> {
260
+ interface HttpRequestHandlerStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> {
261
261
  /**
262
262
  * A set of headers that the intercepted request must contain to match the handler. If exact is `true`, the request
263
263
  * must contain exactly these headers and no others.
264
264
  */
265
- headers?: HttpRequestHandlerHeadersStaticRestriction<Schema, Path, Method>;
265
+ headers?: HttpRequestHandlerHeadersStaticRestriction<Schema, Method, Path>;
266
266
  /**
267
267
  * A set of search params that the intercepted request must contain to match the handler. If exact is `true`, the
268
268
  * request must contain exactly these search params and no others.
269
269
  */
270
- searchParams?: HttpRequestHandlerSearchParamsStaticRestriction<Schema, Path, Method>;
270
+ searchParams?: HttpRequestHandlerSearchParamsStaticRestriction<Schema, Method, Path>;
271
271
  /**
272
272
  * The body that the intercepted request must contain to match the handler. If exact is `true`, the request must
273
273
  * contain exactly this body and no other.
274
274
  */
275
- body?: HttpRequestHandlerBodyStaticRestriction<Schema, Path, Method>;
275
+ body?: HttpRequestHandlerBodyStaticRestriction<Schema, Method, Path>;
276
276
  /**
277
277
  * If `true`, the request must contain **exactly** the headers, search params, and body declared in this restriction.
278
278
  * Otherwise, the request must contain **at least** them.
@@ -290,7 +290,7 @@ type HttpRequestHandlerComputedRestriction<Schema extends HttpSchema, Method ext
290
290
  *
291
291
  * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
292
292
  */
293
- type HttpRequestHandlerRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = HttpRequestHandlerStaticRestriction<Schema, Path, Method> | HttpRequestHandlerComputedRestriction<Schema, Method, Path>;
293
+ type HttpRequestHandlerRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = HttpRequestHandlerStaticRestriction<Schema, Method, Path> | HttpRequestHandlerComputedRestriction<Schema, Method, Path>;
294
294
  interface RestrictionDiff<Value> {
295
295
  expected: Value;
296
296
  received: Value;
@@ -1104,9 +1104,9 @@ interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpIntercept
1104
1104
  * @throws {UnsupportedURLProtocolError} If the base URL protocol is not either `http` or `https`.
1105
1105
  * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httpinterceptorcreateoptions `httpInterceptor.create(options)` API reference}
1106
1106
  */
1107
- declare function createHttpInterceptor<Schema extends HttpSchema>(options: LocalHttpInterceptorOptions): LocalHttpInterceptor<HttpSchema<Schema>>;
1108
- declare function createHttpInterceptor<Schema extends HttpSchema>(options: RemoteHttpInterceptorOptions): RemoteHttpInterceptor<HttpSchema<Schema>>;
1109
- declare function createHttpInterceptor<Schema extends HttpSchema>(options: HttpInterceptorOptions): LocalHttpInterceptor<HttpSchema<Schema>> | RemoteHttpInterceptor<HttpSchema<Schema>>;
1107
+ declare function createHttpInterceptor<Schema extends HttpSchema>(options: LocalHttpInterceptorOptions): LocalHttpInterceptor<Schema>;
1108
+ declare function createHttpInterceptor<Schema extends HttpSchema>(options: RemoteHttpInterceptorOptions): RemoteHttpInterceptor<Schema>;
1109
+ declare function createHttpInterceptor<Schema extends HttpSchema>(options: HttpInterceptorOptions): LocalHttpInterceptor<Schema> | RemoteHttpInterceptor<Schema>;
1110
1110
 
1111
1111
  /** Default HTTP interceptor settings. */
1112
1112
  declare class HttpInterceptorNamespaceDefault {