@zimic/interceptor 0.16.0-canary.5 → 0.16.0-canary.6

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/README.md CHANGED
@@ -149,7 +149,6 @@ Check our [getting started guide](https://github.com/zimicjs/zimic/wiki/getting
149
149
  const interceptor = createHttpInterceptor<Schema>({
150
150
  type: 'local',
151
151
  baseURL: 'http://localhost:3000',
152
- saveRequests: true, // Allow access to `handler.requests`
153
152
  });
154
153
  ```
155
154
 
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.16.0-canary.5";
20
+ var version = "0.16.0-canary.6";
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","createInterceptorServer","exitEvent","yargs","hideBin"],"mappings":";;;;;;;;;;;;;;;;;;;AAgBE,IAAW,OAAA,GAAA,iBAAA;;;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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MAAA,CAAO,WAAa,EAAA;AAAA,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;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 intercepting and mocking\",\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.16.0-canary.5\",\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 -v FORCE_COLOR=1 -- 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 },\n \"dependencies\": {\n \"@whatwg-node/server\": \"0.10.1\",\n \"chalk\": \"4.1.2\",\n \"execa\": \"9.5.2\",\n \"isomorphic-ws\": \"5.0.0\",\n \"msw\": \"2.7.3\",\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.10\",\n \"@types/ws\": \"^8.18.0\",\n \"@types/yargs\": \"^17.0.33\",\n \"@vitest/browser\": \"^3.0.8\",\n \"@vitest/coverage-istanbul\": \"^3.0.8\",\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.22.0\",\n \"playwright\": \"^1.51.0\",\n \"tsup\": \"^8.4.0\",\n \"typescript\": \"^5.8.2\",\n \"vitest\": \"^3.0.8\"\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, createInterceptorServer } 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 = createInterceptorServer({\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.hostname}:${server.port}`);\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","createInterceptorServer","exitEvent","yargs","hideBin"],"mappings":";;;;;;;;;;;;;;;;;;;AAgBE,IAAW,OAAA,GAAA,iBAAA;;;AChBN,IAAM,wBAA2B,GAAA,sBAAA;;;ACQxC,IAAM,aAAA,GAAgBA,sBAAK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AO,WAAQ,GAAA,MAAA;;;AC3Ff,KAAK,WAAO,EAAA","file":"cli.js","sourcesContent":["{\n \"name\": \"@zimic/interceptor\",\n \"description\": \"TypeScript-first HTTP intercepting and mocking\",\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.16.0-canary.6\",\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 -v FORCE_COLOR=1 -- 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 },\n \"dependencies\": {\n \"@whatwg-node/server\": \"0.10.1\",\n \"chalk\": \"4.1.2\",\n \"execa\": \"9.5.2\",\n \"isomorphic-ws\": \"5.0.0\",\n \"msw\": \"2.7.3\",\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.10\",\n \"@types/ws\": \"^8.18.0\",\n \"@types/yargs\": \"^17.0.33\",\n \"@vitest/browser\": \"^3.0.8\",\n \"@vitest/coverage-istanbul\": \"^3.0.8\",\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.22.0\",\n \"playwright\": \"^1.51.0\",\n \"tsup\": \"^8.4.0\",\n \"typescript\": \"^5.8.2\",\n \"vitest\": \"^3.0.8\"\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, createInterceptorServer } 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 = createInterceptorServer({\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.hostname}:${server.port}`);\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.16.0-canary.5";
11
+ var version = "0.16.0-canary.6";
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,iBAAA;;;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,CAAA,eAAe,CAAC,CAAG,CAAA,CAAA,CAAA;AAC/E,EAAA,aAAA,CAAc,uCAAuC,CAAA;AACvD;AATe,MAAA,CAAA,8BAAA,EAAA,gCAAA,CAAA;AAWf,IAAO,YAAQ,GAAA,8BAAA;;;ACxBR,IAAM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AA,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 intercepting and mocking\",\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.16.0-canary.5\",\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 -v FORCE_COLOR=1 -- 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 },\n \"dependencies\": {\n \"@whatwg-node/server\": \"0.10.1\",\n \"chalk\": \"4.1.2\",\n \"execa\": \"9.5.2\",\n \"isomorphic-ws\": \"5.0.0\",\n \"msw\": \"2.7.3\",\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.10\",\n \"@types/ws\": \"^8.18.0\",\n \"@types/yargs\": \"^17.0.33\",\n \"@vitest/browser\": \"^3.0.8\",\n \"@vitest/coverage-istanbul\": \"^3.0.8\",\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.22.0\",\n \"playwright\": \"^1.51.0\",\n \"tsup\": \"^8.4.0\",\n \"typescript\": \"^5.8.2\",\n \"vitest\": \"^3.0.8\"\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, createInterceptorServer } 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 = createInterceptorServer({\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.hostname}:${server.port}`);\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,iBAAA;;;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,CAAA,eAAe,CAA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,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 intercepting and mocking\",\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.16.0-canary.6\",\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 -v FORCE_COLOR=1 -- 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 },\n \"dependencies\": {\n \"@whatwg-node/server\": \"0.10.1\",\n \"chalk\": \"4.1.2\",\n \"execa\": \"9.5.2\",\n \"isomorphic-ws\": \"5.0.0\",\n \"msw\": \"2.7.3\",\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.10\",\n \"@types/ws\": \"^8.18.0\",\n \"@types/yargs\": \"^17.0.33\",\n \"@vitest/browser\": \"^3.0.8\",\n \"@vitest/coverage-istanbul\": \"^3.0.8\",\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.22.0\",\n \"playwright\": \"^1.51.0\",\n \"tsup\": \"^8.4.0\",\n \"typescript\": \"^5.8.2\",\n \"vitest\": \"^3.0.8\"\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, createInterceptorServer } 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 = createInterceptorServer({\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.hostname}:${server.port}`);\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, HttpRequest, HttpHeaders, HttpRequestHeadersSchema, InferPathParams, HttpSearchParams, HttpRequestSearchParamsSchema, HttpRequestBodySchema, HttpStatusCode, HttpResponseSchema, HttpHeadersInit, HttpResponse, HttpResponseHeadersSchema, HttpResponseBodySchema, HttpSchema, HttpSchemaMethod, HttpSchemaPath, HttpHeadersSchema, HttpSearchParamsSchema, HttpBody, HttpFormData, HttpResponseSchemaStatusCode, HttpMethod, LiteralHttpSchemaPathFromNonLiteral } from '@zimic/http';
1
+ import { HttpMethodSchema, HttpRequest, HttpHeaders, HttpRequestHeadersSchema, InferPathParams, HttpSearchParams, HttpRequestSearchParamsSchema, HttpRequestBodySchema, HttpStatusCode, HttpResponseSchema, HttpHeadersInit, HttpResponse, HttpResponseHeadersSchema, HttpResponseBodySchema, HttpSchema, HttpBody, HttpSchemaMethod, HttpSchemaPath, HttpHeadersSchema, HttpSearchParamsSchema, HttpFormData, HttpResponseSchemaStatusCode, HttpMethod, LiteralHttpSchemaPathFromNonLiteral } from '@zimic/http';
2
2
 
3
3
  /**
4
4
  * Error thrown when a value is not valid JSON. HTTP interceptors might throw this error when trying to parse the body
@@ -151,97 +151,6 @@ interface InterceptedHttpInterceptorRequest<Path extends string, MethodSchema ex
151
151
  response: StatusCode extends [never] ? never : HttpInterceptorResponse<MethodSchema, StatusCode>;
152
152
  }
153
153
 
154
- type PartialHttpHeadersOrSchema<Schema extends HttpHeadersSchema> = IfNever<Schema, never, Partial<Schema> | HttpHeaders<Partial<Schema>> | HttpHeaders<Schema>>;
155
- /**
156
- * A static headers restriction to match intercepted requests.
157
- *
158
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
159
- */
160
- type HttpRequestHandlerHeadersStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = PartialHttpHeadersOrSchema<HttpRequestHeadersSchema<Default<Schema[Path][Method]>>>;
161
- type PartialHttpSearchParamsOrSchema<Schema extends HttpSearchParamsSchema> = IfNever<Schema, never, Partial<Schema> | HttpSearchParams<Partial<Schema>> | HttpSearchParams<Schema>>;
162
- /**
163
- * A static search params restriction to match intercepted requests.
164
- *
165
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
166
- */
167
- type HttpRequestHandlerSearchParamsStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = PartialHttpSearchParamsOrSchema<HttpRequestSearchParamsSchema<Default<Schema[Path][Method]>>>;
168
- 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>;
169
- /**
170
- * A static body restriction to match intercepted requests.
171
- *
172
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
173
- */
174
- type HttpRequestHandlerBodyStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = PartialBodyOrSchema<HttpRequestBodySchema<Default<Schema[Path][Method]>>>;
175
- /**
176
- * A static restriction to match intercepted requests.
177
- *
178
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
179
- */
180
- interface HttpRequestHandlerStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> {
181
- /**
182
- * A set of headers that the intercepted request must contain to match the handler. If exact is `true`, the request
183
- * must contain exactly these headers and no others.
184
- */
185
- headers?: HttpRequestHandlerHeadersStaticRestriction<Schema, Method, Path>;
186
- /**
187
- * A set of search params that the intercepted request must contain to match the handler. If exact is `true`, the
188
- * request must contain exactly these search params and no others.
189
- */
190
- searchParams?: HttpRequestHandlerSearchParamsStaticRestriction<Schema, Method, Path>;
191
- /**
192
- * The body that the intercepted request must contain to match the handler. If exact is `true`, the request must
193
- * contain exactly this body and no other.
194
- */
195
- body?: HttpRequestHandlerBodyStaticRestriction<Schema, Method, Path>;
196
- /**
197
- * If `true`, the request must contain **exactly** the headers, search params, and body declared in this restriction.
198
- * Otherwise, the request must contain **at least** them.
199
- */
200
- exact?: boolean;
201
- }
202
- /**
203
- * A computed restriction to match intercepted requests.
204
- *
205
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
206
- */
207
- type HttpRequestHandlerComputedRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = (request: HttpInterceptorRequest<Path, Default<Schema[Path][Method]>>) => PossiblePromise<boolean>;
208
- /**
209
- * A restriction to match intercepted requests.
210
- *
211
- * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
212
- */
213
- type HttpRequestHandlerRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = HttpRequestHandlerStaticRestriction<Schema, Method, Path> | HttpRequestHandlerComputedRestriction<Schema, Method, Path>;
214
- interface RestrictionDiff<Value> {
215
- expected: Value;
216
- received: Value;
217
- }
218
- interface RestrictionDiffs {
219
- computed?: RestrictionDiff<boolean>;
220
- headers?: RestrictionDiff<HttpHeaders<never>>;
221
- searchParams?: RestrictionDiff<HttpSearchParams<never>>;
222
- body?: RestrictionDiff<unknown>;
223
- }
224
- interface UnmatchedHttpInterceptorRequestGroup {
225
- request: HttpInterceptorRequest<string, never>;
226
- diff: RestrictionDiffs;
227
- }
228
-
229
- declare class TimesDeclarationPointer extends Error {
230
- constructor(minNumberOfRequests: number, maxNumberOfRequests?: number);
231
- }
232
-
233
- interface TimesCheckErrorOptions {
234
- requestLimits: Range<number>;
235
- numberOfMatchedRequests: number;
236
- declarationPointer: TimesDeclarationPointer | undefined;
237
- unmatchedRequestGroups: UnmatchedHttpInterceptorRequestGroup[];
238
- hasRestrictions: boolean;
239
- hasSavedRequests: boolean;
240
- }
241
- declare class TimesCheckError extends TypeError {
242
- constructor(options: TimesCheckErrorOptions);
243
- }
244
-
245
154
  type UnhandledHttpInterceptorRequestMethodSchema = HttpSchema.Method<{
246
155
  request: {
247
156
  headers: Record<string, string>;
@@ -351,20 +260,12 @@ interface SharedHttpInterceptorOptions {
351
260
  */
352
261
  baseURL: string;
353
262
  /**
354
- * Whether {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httprequesthandler request handlers}
355
- * should save their intercepted requests in memory and make them accessible through
356
- * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerrequests `handler.requests`}.
357
- *
358
- * **Important**: If `saveRequests` is true, make sure to regularly clear the interceptor to avoid that the requests
359
- * accumulate in memory. A common practice is to call
360
- * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorclear `interceptor.clear()`}
361
- * after each test.
263
+ * Configures if the intercepted requests are saved and how they are handled.
362
264
  *
363
- * @default false
364
265
  * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests Saving intercepted requests}
365
266
  * @see {@link https://github.com/zimicjs/zimic/wiki/guides‐testing‐interceptor Testing}
366
267
  */
367
- saveRequests?: boolean;
268
+ requestSaving?: Partial<HttpInterceptorRequestSaving>;
368
269
  }
369
270
  /**
370
271
  * The options to create a
@@ -408,6 +309,81 @@ interface RemoteHttpInterceptorOptions extends SharedHttpInterceptorOptions {
408
309
  */
409
310
  type HttpInterceptorOptions = LocalHttpInterceptorOptions | RemoteHttpInterceptorOptions;
410
311
 
312
+ type PartialHttpHeadersOrSchema<Schema extends HttpHeadersSchema> = IfNever<Schema, never, Partial<Schema> | HttpHeaders<Partial<Schema>> | HttpHeaders<Schema>>;
313
+ /**
314
+ * A static headers restriction to match intercepted requests.
315
+ *
316
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
317
+ */
318
+ type HttpRequestHandlerHeadersStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = PartialHttpHeadersOrSchema<HttpRequestHeadersSchema<Default<Schema[Path][Method]>>>;
319
+ type PartialHttpSearchParamsOrSchema<Schema extends HttpSearchParamsSchema> = IfNever<Schema, never, Partial<Schema> | HttpSearchParams<Partial<Schema>> | HttpSearchParams<Schema>>;
320
+ /**
321
+ * A static search params restriction to match intercepted requests.
322
+ *
323
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
324
+ */
325
+ type HttpRequestHandlerSearchParamsStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = PartialHttpSearchParamsOrSchema<HttpRequestSearchParamsSchema<Default<Schema[Path][Method]>>>;
326
+ 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>;
327
+ /**
328
+ * A static body restriction to match intercepted requests.
329
+ *
330
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
331
+ */
332
+ type HttpRequestHandlerBodyStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = PartialBodyOrSchema<HttpRequestBodySchema<Default<Schema[Path][Method]>>>;
333
+ /**
334
+ * A static restriction to match intercepted requests.
335
+ *
336
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
337
+ */
338
+ interface HttpRequestHandlerStaticRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> {
339
+ /**
340
+ * A set of headers that the intercepted request must contain to match the handler. If exact is `true`, the request
341
+ * must contain exactly these headers and no others.
342
+ */
343
+ headers?: HttpRequestHandlerHeadersStaticRestriction<Schema, Method, Path>;
344
+ /**
345
+ * A set of search params that the intercepted request must contain to match the handler. If exact is `true`, the
346
+ * request must contain exactly these search params and no others.
347
+ */
348
+ searchParams?: HttpRequestHandlerSearchParamsStaticRestriction<Schema, Method, Path>;
349
+ /**
350
+ * The body that the intercepted request must contain to match the handler. If exact is `true`, the request must
351
+ * contain exactly this body and no other.
352
+ */
353
+ body?: HttpRequestHandlerBodyStaticRestriction<Schema, Method, Path>;
354
+ /**
355
+ * If `true`, the request must contain **exactly** the headers, search params, and body declared in this restriction.
356
+ * Otherwise, the request must contain **at least** them.
357
+ */
358
+ exact?: boolean;
359
+ }
360
+ /**
361
+ * A computed restriction to match intercepted requests.
362
+ *
363
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
364
+ */
365
+ type HttpRequestHandlerComputedRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = (request: HttpInterceptorRequest<Path, Default<Schema[Path][Method]>>) => PossiblePromise<boolean>;
366
+ /**
367
+ * A restriction to match intercepted requests.
368
+ *
369
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction `handler.with()` API reference}
370
+ */
371
+ type HttpRequestHandlerRestriction<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>> = HttpRequestHandlerStaticRestriction<Schema, Method, Path> | HttpRequestHandlerComputedRestriction<Schema, Method, Path>;
372
+ interface RestrictionDiff<Value> {
373
+ expected: Value;
374
+ received: Value;
375
+ }
376
+ interface RestrictionDiffs {
377
+ computed?: RestrictionDiff<boolean>;
378
+ headers?: RestrictionDiff<HttpHeaders<never>>;
379
+ searchParams?: RestrictionDiff<HttpSearchParams<never>>;
380
+ body?: RestrictionDiff<unknown>;
381
+ }
382
+ interface UnmatchedHttpInterceptorRequestGroup {
383
+ request: HttpInterceptorRequest<string, never>;
384
+ diff: RestrictionDiffs;
385
+ }
386
+
411
387
  /**
412
388
  * An HTTP request handler to declare responses for intercepted requests.
413
389
  *
@@ -512,8 +488,9 @@ interface LocalHttpRequestHandler<Schema extends HttpSchema, Method extends Http
512
488
  * that was not satisfied.
513
489
  *
514
490
  * When
515
- * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#createhttpinterceptoroptions `saveRequests: true`}
516
- * is enabled in your interceptor, the `TimesCheckError` errors will also list each unmatched request with diff of the
491
+ * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests
492
+ * `requestSaving.enabled`} is
493
+ * `true` in your interceptor, the `TimesCheckError` errors will also list each unmatched request with diff of the
517
494
  * expected and received data. This is useful for debugging requests that did not match a handler with
518
495
  * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction restrictions}.
519
496
  *
@@ -541,11 +518,14 @@ interface LocalHttpRequestHandler<Schema extends HttpSchema, Method extends Http
541
518
  * The intercepted requests that matched this handler, along with the responses returned to each of them. This is
542
519
  * useful for testing that the correct requests were made by your application.
543
520
  *
544
- * **Important**: This method can only be used if `saveRequests` was set to `true` when creating the interceptor. See
521
+ * **Important**: This method can only be used if
522
+ * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests
523
+ * `requestSaving.enabled`} is
524
+ * `true` in the interceptor. See
545
525
  * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests Saving intercepted requests}
546
526
  * for more information.
547
527
  *
548
- * @throws {DisabledRequestSavingError} If the interceptor was not created with `saveRequests: true`.
528
+ * @throws {DisabledRequestSavingError} If the interceptor has `requestSaving.enabled: false`.
549
529
  * @readonly
550
530
  * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerrequests `handler.requests` API reference}
551
531
  */
@@ -627,8 +607,9 @@ interface SyncedRemoteHttpRequestHandler<Schema extends HttpSchema, Method exten
627
607
  * that was not satisfied.
628
608
  *
629
609
  * When
630
- * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#createhttpinterceptoroptions `saveRequests: true`}
631
- * is enabled in your interceptor, the `TimesCheckError` errors will also list each unmatched request with diff of the
610
+ * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests
611
+ * `requestSaving.enabled`} is
612
+ * true in your interceptor, the `TimesCheckError` errors will also list each unmatched request with diff of the
632
613
  * expected and received data. This is useful for debugging requests that did not match a handler with
633
614
  * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction restrictions}.
634
615
  *
@@ -656,11 +637,14 @@ interface SyncedRemoteHttpRequestHandler<Schema extends HttpSchema, Method exten
656
637
  * The intercepted requests that matched this handler, along with the responses returned to each of them. This is
657
638
  * useful for testing that the correct requests were made by your application.
658
639
  *
659
- * **Important**: This method can only be used if `saveRequests` was set to `true` when creating the interceptor. See
640
+ * **Important**: This method can only be used if
641
+ * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests
642
+ * `requestSaving.enabled`} is
643
+ * `true` in the interceptor. See
660
644
  * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests Saving intercepted requests}
661
645
  * for more information.
662
646
  *
663
- * @throws {DisabledRequestSavingError} If the interceptor was not created with `saveRequests: true`.
647
+ * @throws {DisabledRequestSavingError} If the interceptor has `requestSaving.enabled: false`.
664
648
  * @readonly
665
649
  * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerrequests `handler.requests` API reference}
666
650
  */
@@ -709,6 +693,43 @@ type RemoteHttpRequestHandler<Schema extends HttpSchema, Method extends HttpSche
709
693
  type SyncHttpInterceptorMethodHandler<Schema extends HttpSchema, Method extends HttpMethod> = Method extends HttpSchemaMethod<Schema> ? <Path extends HttpSchemaPath.NonLiteral<Schema, Method>>(path: Path) => LocalHttpRequestHandler<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>> : (path: never) => LocalHttpRequestHandler<any, any, never>;
710
694
  type AsyncHttpInterceptorMethodHandler<Schema extends HttpSchema, Method extends HttpMethod> = Method extends HttpSchemaMethod<Schema> ? <Path extends HttpSchemaPath.NonLiteral<Schema, Method>>(path: Path) => RemoteHttpRequestHandler<Schema, Method, LiteralHttpSchemaPathFromNonLiteral<Schema, Method, Path>> : (path: never) => RemoteHttpRequestHandler<any, any, never>;
711
695
 
696
+ /**
697
+ * Configures if the intercepted requests are saved and how they are handled.
698
+ *
699
+ * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests Saving intercepted requests}
700
+ * @see {@link https://github.com/zimicjs/zimic/wiki/guides‐testing‐interceptor Testing}
701
+ */
702
+ interface HttpInterceptorRequestSaving {
703
+ /**
704
+ * Whether {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httprequesthandler request handlers}
705
+ * should save their intercepted requests in memory and make them accessible through
706
+ * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerrequests `handler.requests`}.
707
+ *
708
+ * If you are using
709
+ * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorchecktimes `interceptor.checkTimes()`}
710
+ * or
711
+ * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerchecktimes `handler.checkTimes()`}
712
+ * during tests, consider enabling this option to get more detailed information in `TimesCheckError` errors.
713
+ *
714
+ * **Important**: If `requestSaving.enabled` is `true`, make sure to regularly clear the interceptor to avoid requests
715
+ * accumulating in memory. A common practice is to call
716
+ * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorclear `interceptor.clear()`}
717
+ * after each test.
718
+ *
719
+ * @default process.env.NODE_ENV === 'test'
720
+ */
721
+ enabled: boolean;
722
+ /**
723
+ * The safe number of requests to save in memory before logging warnings in the console. If `requestSaving.enabled` is
724
+ * `true` and the interceptor is not regularly cleared with
725
+ * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorclear `interceptor.clear()`},
726
+ * the requests may accumulate in memory and cause performance issues. This option does not limit the number of
727
+ * requests saved in memory, only when to log warnings.
728
+ *
729
+ * @default 1000
730
+ */
731
+ safeLimit: number;
732
+ }
712
733
  /**
713
734
  * An interceptor to handle HTTP requests and return mock responses. The methods, paths, status codes, parameters, and
714
735
  * responses are statically-typed based on the provided service schema.
@@ -723,20 +744,12 @@ interface HttpInterceptor<_Schema extends HttpSchema> {
723
744
  */
724
745
  baseURL: string;
725
746
  /**
726
- * Whether {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httprequesthandler request handlers}
727
- * should save their intercepted requests in memory and make them accessible through
728
- * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerrequests `handler.requests`}.
747
+ * Configures if the intercepted requests are saved and how they are handled.
729
748
  *
730
- * **Important**: If `saveRequests` is true, make sure to regularly clear the interceptor to avoid that the requests
731
- * accumulate in memory. A common practice is to call
732
- * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorclear `interceptor.clear()`}
733
- * after each test.
734
- *
735
- * @default process.env.NODE_ENV === 'test'
736
749
  * @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests Saving intercepted requests}
737
750
  * @see {@link https://github.com/zimicjs/zimic/wiki/guides‐testing‐interceptor Testing}
738
751
  */
739
- saveRequests: boolean;
752
+ requestSaving: HttpInterceptorRequestSaving;
740
753
  /**
741
754
  * The platform the interceptor is running on.
742
755
  *
@@ -784,8 +797,9 @@ interface HttpInterceptor<_Schema extends HttpSchema> {
784
797
  * of each test.
785
798
  *
786
799
  * When
787
- * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#createhttpinterceptoroptions `saveRequests: true`}
788
- * is enabled in your interceptor, the `TimesCheckError` errors will also list each unmatched request with diff of the
800
+ * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests
801
+ * `requestSaving.enabled`} is
802
+ * `true` in your interceptor, the `TimesCheckError` errors will also list each unmatched request with diff of the
789
803
  * expected and received data. This is useful for debugging requests that did not match a handler with
790
804
  * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerwithrestriction restrictions}.
791
805
  *
@@ -1241,6 +1255,22 @@ interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpIntercept
1241
1255
  clear: () => Promise<void>;
1242
1256
  }
1243
1257
 
1258
+ declare class TimesDeclarationPointer extends Error {
1259
+ constructor(minNumberOfRequests: number, maxNumberOfRequests?: number);
1260
+ }
1261
+
1262
+ interface TimesCheckErrorOptions {
1263
+ requestLimits: Range<number>;
1264
+ numberOfMatchedRequests: number;
1265
+ declarationPointer: TimesDeclarationPointer | undefined;
1266
+ unmatchedRequestGroups: UnmatchedHttpInterceptorRequestGroup[];
1267
+ hasRestrictions: boolean;
1268
+ requestSaving: HttpInterceptorRequestSaving;
1269
+ }
1270
+ declare class TimesCheckError extends TypeError {
1271
+ constructor(options: TimesCheckErrorOptions);
1272
+ }
1273
+
1244
1274
  /**
1245
1275
  * Infers the schema of an
1246
1276
  * {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httpinterceptor `HttpInterceptor`}.