@zimic/interceptor 0.15.0-canary.1 → 0.15.0-canary.3
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/{chunk-3O3YPVEG.mjs → chunk-6TSSHQW5.mjs} +50 -25
- package/dist/chunk-6TSSHQW5.mjs.map +1 -0
- package/dist/{chunk-CWBDZYUG.js → chunk-R2ROSKU4.js} +51 -25
- package/dist/chunk-R2ROSKU4.js.map +1 -0
- package/dist/cli.js +7 -7
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +3 -3
- package/dist/cli.mjs.map +1 -1
- package/dist/http.d.ts +84 -40
- package/dist/http.js +144 -83
- package/dist/http.js.map +1 -1
- package/dist/http.mjs +143 -83
- package/dist/http.mjs.map +1 -1
- package/dist/server.d.ts +17 -11
- package/dist/server.js +10 -6
- package/dist/server.mjs +1 -1
- package/package.json +12 -12
- package/src/cli/server/start.ts +1 -1
- package/src/http/index.ts +2 -14
- package/src/http/interceptor/HttpInterceptorClient.ts +51 -19
- package/src/http/interceptor/LocalHttpInterceptor.ts +27 -11
- package/src/http/interceptor/RemoteHttpInterceptor.ts +25 -10
- package/src/http/interceptor/errors/{NotStartedHttpInterceptorError.ts → NotRunningHttpInterceptorError.ts} +3 -3
- package/src/http/interceptor/errors/RunningHttpInterceptorError.ts +15 -0
- package/src/http/interceptor/types/options.ts +4 -6
- package/src/http/interceptor/types/public.ts +58 -20
- package/src/http/interceptorWorker/LocalHttpInterceptorWorker.ts +7 -6
- package/src/http/interceptorWorker/RemoteHttpInterceptorWorker.ts +8 -7
- package/src/http/requestHandler/HttpRequestHandlerClient.ts +4 -6
- package/src/http/requestHandler/types/public.ts +12 -6
- package/src/server/InterceptorServer.ts +28 -11
- package/src/server/constants.ts +1 -0
- package/src/server/errors/NotRunningInterceptorServerError.ts +10 -0
- package/src/server/errors/RunningInterceptorServerError.ts +13 -0
- package/src/server/index.ts +2 -1
- package/src/server/types/public.ts +6 -10
- package/src/webSocket/WebSocketHandler.ts +2 -2
- package/src/webSocket/errors/NotRunningWebSocketHandlerError.ts +8 -0
- package/dist/chunk-3O3YPVEG.mjs.map +0 -1
- package/dist/chunk-CWBDZYUG.js.map +0 -1
- package/src/server/errors/NotStartedInterceptorServerError.ts +0 -10
- package/src/webSocket/errors/NotStartedWebSocketHandlerError.ts +0 -8
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,CAA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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.15.0-canary.1\",\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 },\n \"dependencies\": {\n \"@whatwg-node/server\": \"0.9.70\",\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.8\",\n \"@types/ws\": \"^8.5.14\",\n \"@types/yargs\": \"^17.0.33\",\n \"@vitest/browser\": \"^3.0.7\",\n \"@vitest/coverage-istanbul\": \"^3.0.7\",\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.4.0\",\n \"typescript\": \"^5.8.2\",\n \"vitest\": \"^3.0.7\"\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,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,K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,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 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.15.0-canary.3\",\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 },\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, 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.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,
|
|
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
|
type Default<Type, IfEmpty = never> = [undefined | void] extends [Type] ? IfEmpty : Exclude<Type, undefined | void>;
|
|
4
4
|
type IfNever<Type, Yes, No = Type> = [Type] extends [never] ? Yes : No;
|
|
@@ -185,18 +185,16 @@ interface SharedHttpInterceptorOptions {
|
|
|
185
185
|
* {@link https://github.com/zimicjs/zimic/wiki/cli‐zimic‐server#zimic-server interceptor server}. It may include
|
|
186
186
|
* additional paths to differentiate between conflicting mocks.
|
|
187
187
|
*/
|
|
188
|
-
baseURL: string
|
|
188
|
+
baseURL: string;
|
|
189
189
|
/**
|
|
190
190
|
* Whether {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httprequesthandler request handlers}
|
|
191
191
|
* should save their intercepted requests in memory and make them accessible through
|
|
192
192
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerrequests `handler.requests`}.
|
|
193
193
|
*
|
|
194
|
-
* **Important**:
|
|
195
|
-
*
|
|
196
|
-
* to assert them in your tests, set this option to `true` and make sure to regularly clear the interceptor. A common
|
|
197
|
-
* practice is to call
|
|
194
|
+
* **Important**: If `saveRequests` is true, make sure to regularly clear the interceptor to avoid that the requests
|
|
195
|
+
* accumulate in memory. A common practice is to call
|
|
198
196
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorclear `interceptor.clear()`}
|
|
199
|
-
* after each test.
|
|
197
|
+
* after each test.
|
|
200
198
|
*
|
|
201
199
|
* @default false
|
|
202
200
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests Saving intercepted requests}
|
|
@@ -334,16 +332,18 @@ interface HttpRequestHandler<Schema extends HttpSchema, Method extends HttpSchem
|
|
|
334
332
|
/**
|
|
335
333
|
* The method that matches this handler.
|
|
336
334
|
*
|
|
335
|
+
* @readonly
|
|
337
336
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlermethod `handler.method` API reference}
|
|
338
337
|
*/
|
|
339
|
-
method: Method;
|
|
338
|
+
get method(): Method;
|
|
340
339
|
/**
|
|
341
340
|
* The path that matches this handler. The base URL of the interceptor is not included, but it is used when matching
|
|
342
341
|
* requests.
|
|
343
342
|
*
|
|
343
|
+
* @readonly
|
|
344
344
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerpath `handler.path` API reference}
|
|
345
345
|
*/
|
|
346
|
-
path: Path;
|
|
346
|
+
get path(): Path;
|
|
347
347
|
}
|
|
348
348
|
/**
|
|
349
349
|
* A local HTTP request handler to declare responses for intercepted requests. In a local handler, the mocking
|
|
@@ -356,7 +356,8 @@ interface HttpRequestHandler<Schema extends HttpSchema, Method extends HttpSchem
|
|
|
356
356
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httprequesthandler `HttpRequestHandler` API reference}
|
|
357
357
|
*/
|
|
358
358
|
interface LocalHttpRequestHandler<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>, StatusCode extends HttpStatusCode = never> extends HttpRequestHandler<Schema, Method, Path> {
|
|
359
|
-
readonly
|
|
359
|
+
/** @readonly */
|
|
360
|
+
get type(): 'local';
|
|
360
361
|
/**
|
|
361
362
|
* Declares a restriction to intercepted request matches. `headers`, `searchParams`, and `body` are supported to limit
|
|
362
363
|
* which requests will match the handler and receive the mock response. If multiple restrictions are declared, either
|
|
@@ -456,9 +457,10 @@ interface LocalHttpRequestHandler<Schema extends HttpSchema, Method extends Http
|
|
|
456
457
|
* for more information.
|
|
457
458
|
*
|
|
458
459
|
* @throws {DisabledRequestSavingError} If the interceptor was not created with `saveRequests: true`.
|
|
460
|
+
* @readonly
|
|
459
461
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerrequests `handler.requests` API reference}
|
|
460
462
|
*/
|
|
461
|
-
requests: readonly InterceptedHttpInterceptorRequest<Path, Default<Schema[Path][Method]>, StatusCode>[];
|
|
463
|
+
get requests(): readonly InterceptedHttpInterceptorRequest<Path, Default<Schema[Path][Method]>, StatusCode>[];
|
|
462
464
|
}
|
|
463
465
|
/**
|
|
464
466
|
* A synced remote HTTP request handler. When a remote handler is synced, it is guaranteed that all of the mocking
|
|
@@ -468,7 +470,8 @@ interface LocalHttpRequestHandler<Schema extends HttpSchema, Method extends Http
|
|
|
468
470
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httprequesthandler `HttpRequestHandler` API reference}
|
|
469
471
|
*/
|
|
470
472
|
interface SyncedRemoteHttpRequestHandler<Schema extends HttpSchema, Method extends HttpSchemaMethod<Schema>, Path extends HttpSchemaPath<Schema, Method>, StatusCode extends HttpStatusCode = never> extends HttpRequestHandler<Schema, Method, Path> {
|
|
471
|
-
readonly
|
|
473
|
+
/** @readonly */
|
|
474
|
+
get type(): 'remote';
|
|
472
475
|
/**
|
|
473
476
|
* Declares a restriction to intercepted request matches. `headers`, `searchParams`, and `body` are supported to limit
|
|
474
477
|
* which requests will match the handler and receive the mock response. If multiple restrictions are declared, either
|
|
@@ -569,9 +572,10 @@ interface SyncedRemoteHttpRequestHandler<Schema extends HttpSchema, Method exten
|
|
|
569
572
|
* for more information.
|
|
570
573
|
*
|
|
571
574
|
* @throws {DisabledRequestSavingError} If the interceptor was not created with `saveRequests: true`.
|
|
575
|
+
* @readonly
|
|
572
576
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerrequests `handler.requests` API reference}
|
|
573
577
|
*/
|
|
574
|
-
requests: readonly InterceptedHttpInterceptorRequest<Path, Default<Schema[Path][Method]>, StatusCode>[];
|
|
578
|
+
get requests(): readonly InterceptedHttpInterceptorRequest<Path, Default<Schema[Path][Method]>, StatusCode>[];
|
|
575
579
|
}
|
|
576
580
|
/**
|
|
577
581
|
* A pending remote HTTP request handler. When a remote handler is pending, it is not guaranteed that all of the mocking
|
|
@@ -629,18 +633,35 @@ interface HttpInterceptor<_Schema extends HttpSchema> {
|
|
|
629
633
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorbaseurl `interceptor.baseURL` API reference}
|
|
630
634
|
*/
|
|
631
635
|
baseURL: string;
|
|
636
|
+
/**
|
|
637
|
+
* Whether {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httprequesthandler request handlers}
|
|
638
|
+
* should save their intercepted requests in memory and make them accessible through
|
|
639
|
+
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-handlerrequests `handler.requests`}.
|
|
640
|
+
*
|
|
641
|
+
* **Important**: If `saveRequests` is true, make sure to regularly clear the interceptor to avoid that the requests
|
|
642
|
+
* accumulate in memory. A common practice is to call
|
|
643
|
+
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorclear `interceptor.clear()`}
|
|
644
|
+
* after each test.
|
|
645
|
+
*
|
|
646
|
+
* @default false
|
|
647
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#saving-requests Saving intercepted requests}
|
|
648
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/guides‐testing‐interceptor Testing}
|
|
649
|
+
*/
|
|
650
|
+
saveRequests: boolean;
|
|
632
651
|
/**
|
|
633
652
|
* The platform the interceptor is running on.
|
|
634
653
|
*
|
|
654
|
+
* @readonly
|
|
635
655
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorplatform `interceptor.platform` API reference}
|
|
636
656
|
*/
|
|
637
|
-
platform: HttpInterceptorPlatform | null;
|
|
657
|
+
get platform(): HttpInterceptorPlatform | null;
|
|
638
658
|
/**
|
|
639
659
|
* Whether the interceptor is currently running and ready to use.
|
|
640
660
|
*
|
|
661
|
+
* @readonly
|
|
641
662
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorisrunning `interceptor.isRunning` API reference}
|
|
642
663
|
*/
|
|
643
|
-
isRunning: boolean;
|
|
664
|
+
get isRunning(): boolean;
|
|
644
665
|
/**
|
|
645
666
|
* Starts the interceptor, allowing it to intercept HTTP requests.
|
|
646
667
|
*
|
|
@@ -692,7 +713,7 @@ interface HttpInterceptor<_Schema extends HttpSchema> {
|
|
|
692
713
|
*
|
|
693
714
|
* This method is useful to reset the interceptor mocks between tests.
|
|
694
715
|
*
|
|
695
|
-
* @throws {
|
|
716
|
+
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
696
717
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorclear `interceptor.clear()` API reference}
|
|
697
718
|
*/
|
|
698
719
|
clear: (() => void) | (() => Promise<void>);
|
|
@@ -707,7 +728,16 @@ interface HttpInterceptor<_Schema extends HttpSchema> {
|
|
|
707
728
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httpinterceptor `HttpInterceptor` API reference}
|
|
708
729
|
*/
|
|
709
730
|
interface LocalHttpInterceptor<Schema extends HttpSchema> extends HttpInterceptor<Schema> {
|
|
710
|
-
readonly
|
|
731
|
+
/** @readonly */
|
|
732
|
+
get type(): 'local';
|
|
733
|
+
/**
|
|
734
|
+
* The strategy to use for unhandled requests. If a request starts with the base URL of the interceptor, but no
|
|
735
|
+
* matching handler exists, this strategy will be used. If a function is provided, it will be called with the
|
|
736
|
+
* unhandled request.
|
|
737
|
+
*
|
|
738
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#unhandled-requests Unhandled requests}
|
|
739
|
+
*/
|
|
740
|
+
onUnhandledRequest: UnhandledRequestStrategy.Local | undefined;
|
|
711
741
|
/**
|
|
712
742
|
* Creates a GET
|
|
713
743
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httprequesthandler `HttpRequestHandler`} for
|
|
@@ -729,7 +759,7 @@ interface LocalHttpInterceptor<Schema extends HttpSchema> extends HttpIntercepto
|
|
|
729
759
|
* @returns A GET
|
|
730
760
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httprequesthandler `HttpRequestHandler`}
|
|
731
761
|
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
732
|
-
* @throws {
|
|
762
|
+
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
733
763
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptormethodpath `interceptor.<method>(path)` API reference}
|
|
734
764
|
*/
|
|
735
765
|
get: SyncHttpInterceptorMethodHandler<Schema, 'GET'>;
|
|
@@ -754,7 +784,7 @@ interface LocalHttpInterceptor<Schema extends HttpSchema> extends HttpIntercepto
|
|
|
754
784
|
* @returns A POST
|
|
755
785
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httprequesthandler `HttpRequestHandler`}
|
|
756
786
|
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
757
|
-
* @throws {
|
|
787
|
+
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
758
788
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptormethodpath `interceptor.<method>(path)` API reference}
|
|
759
789
|
*/
|
|
760
790
|
post: SyncHttpInterceptorMethodHandler<Schema, 'POST'>;
|
|
@@ -779,7 +809,7 @@ interface LocalHttpInterceptor<Schema extends HttpSchema> extends HttpIntercepto
|
|
|
779
809
|
* @returns A PATCH
|
|
780
810
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httprequesthandler `HttpRequestHandler`}
|
|
781
811
|
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
782
|
-
* @throws {
|
|
812
|
+
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
783
813
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptormethodpath `interceptor.<method>(path)` API reference}
|
|
784
814
|
*/
|
|
785
815
|
patch: SyncHttpInterceptorMethodHandler<Schema, 'PATCH'>;
|
|
@@ -804,7 +834,7 @@ interface LocalHttpInterceptor<Schema extends HttpSchema> extends HttpIntercepto
|
|
|
804
834
|
* @returns A PUT
|
|
805
835
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httprequesthandler `HttpRequestHandler`}
|
|
806
836
|
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
807
|
-
* @throws {
|
|
837
|
+
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
808
838
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptormethodpath `interceptor.<method>(path)` API reference}
|
|
809
839
|
*/
|
|
810
840
|
put: SyncHttpInterceptorMethodHandler<Schema, 'PUT'>;
|
|
@@ -829,7 +859,7 @@ interface LocalHttpInterceptor<Schema extends HttpSchema> extends HttpIntercepto
|
|
|
829
859
|
* @returns A DELETE
|
|
830
860
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httprequesthandler `HttpRequestHandler`}
|
|
831
861
|
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
832
|
-
* @throws {
|
|
862
|
+
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
833
863
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptormethodpath `interceptor.<method>(path)` API reference}
|
|
834
864
|
*/
|
|
835
865
|
delete: SyncHttpInterceptorMethodHandler<Schema, 'DELETE'>;
|
|
@@ -854,7 +884,7 @@ interface LocalHttpInterceptor<Schema extends HttpSchema> extends HttpIntercepto
|
|
|
854
884
|
* @returns A HEAD
|
|
855
885
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httprequesthandler `HttpRequestHandler`}
|
|
856
886
|
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
857
|
-
* @throws {
|
|
887
|
+
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
858
888
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptormethodpath `interceptor.<method>(path)` API reference}
|
|
859
889
|
*/
|
|
860
890
|
head: SyncHttpInterceptorMethodHandler<Schema, 'HEAD'>;
|
|
@@ -879,7 +909,7 @@ interface LocalHttpInterceptor<Schema extends HttpSchema> extends HttpIntercepto
|
|
|
879
909
|
* @returns An OPTIONS
|
|
880
910
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httprequesthandler `HttpRequestHandler`}
|
|
881
911
|
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
882
|
-
* @throws {
|
|
912
|
+
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
883
913
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptormethodpath `interceptor.<method>(path)` API reference}
|
|
884
914
|
*/
|
|
885
915
|
options: SyncHttpInterceptorMethodHandler<Schema, 'OPTIONS'>;
|
|
@@ -898,7 +928,16 @@ interface LocalHttpInterceptor<Schema extends HttpSchema> extends HttpIntercepto
|
|
|
898
928
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httpinterceptor `HttpInterceptor` API reference}
|
|
899
929
|
*/
|
|
900
930
|
interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpInterceptor<Schema> {
|
|
901
|
-
readonly
|
|
931
|
+
/** @readonly */
|
|
932
|
+
get type(): 'remote';
|
|
933
|
+
/**
|
|
934
|
+
* The strategy to use for unhandled requests. If a request starts with the base URL of the interceptor, but no
|
|
935
|
+
* matching handler exists, this strategy will be used. If a function is provided, it will be called with the
|
|
936
|
+
* unhandled request.
|
|
937
|
+
*
|
|
938
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#unhandled-requests Unhandled requests}
|
|
939
|
+
*/
|
|
940
|
+
onUnhandledRequest: UnhandledRequestStrategy.Remote | undefined;
|
|
902
941
|
/**
|
|
903
942
|
* Creates a GET
|
|
904
943
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httprequesthandler `HttpRequestHandler`} for
|
|
@@ -925,7 +964,7 @@ interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpIntercept
|
|
|
925
964
|
* @returns A GET
|
|
926
965
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httprequesthandler `HttpRequestHandler`}
|
|
927
966
|
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
928
|
-
* @throws {
|
|
967
|
+
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
929
968
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptormethodpath `interceptor.<method>(path)` API reference}
|
|
930
969
|
*/
|
|
931
970
|
get: AsyncHttpInterceptorMethodHandler<Schema, 'GET'>;
|
|
@@ -955,7 +994,7 @@ interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpIntercept
|
|
|
955
994
|
* @returns A POST
|
|
956
995
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httprequesthandler `HttpRequestHandler`}
|
|
957
996
|
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
958
|
-
* @throws {
|
|
997
|
+
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
959
998
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptormethodpath `interceptor.<method>(path)` API reference}
|
|
960
999
|
*/
|
|
961
1000
|
post: AsyncHttpInterceptorMethodHandler<Schema, 'POST'>;
|
|
@@ -985,7 +1024,7 @@ interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpIntercept
|
|
|
985
1024
|
* @returns A PATCH
|
|
986
1025
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httprequesthandler `HttpRequestHandler`}
|
|
987
1026
|
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
988
|
-
* @throws {
|
|
1027
|
+
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
989
1028
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptormethodpath `interceptor.<method>(path)` API reference}
|
|
990
1029
|
*/
|
|
991
1030
|
patch: AsyncHttpInterceptorMethodHandler<Schema, 'PATCH'>;
|
|
@@ -1015,7 +1054,7 @@ interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpIntercept
|
|
|
1015
1054
|
* @returns A PUT
|
|
1016
1055
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httprequesthandler `HttpRequestHandler`}
|
|
1017
1056
|
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
1018
|
-
* @throws {
|
|
1057
|
+
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
1019
1058
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptormethodpath `interceptor.<method>(path)` API reference}
|
|
1020
1059
|
*/
|
|
1021
1060
|
put: AsyncHttpInterceptorMethodHandler<Schema, 'PUT'>;
|
|
@@ -1045,7 +1084,7 @@ interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpIntercept
|
|
|
1045
1084
|
* @returns A DELETE
|
|
1046
1085
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httprequesthandler `HttpRequestHandler`}
|
|
1047
1086
|
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
1048
|
-
* @throws {
|
|
1087
|
+
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
1049
1088
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptormethodpath `interceptor.<method>(path)` API reference}
|
|
1050
1089
|
*/
|
|
1051
1090
|
delete: AsyncHttpInterceptorMethodHandler<Schema, 'DELETE'>;
|
|
@@ -1075,7 +1114,7 @@ interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpIntercept
|
|
|
1075
1114
|
* @returns A HEAD
|
|
1076
1115
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httprequesthandler `HttpRequestHandler`}
|
|
1077
1116
|
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
1078
|
-
* @throws {
|
|
1117
|
+
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
1079
1118
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptormethodpath `interceptor.<method>(path)` API reference}
|
|
1080
1119
|
*/
|
|
1081
1120
|
head: AsyncHttpInterceptorMethodHandler<Schema, 'HEAD'>;
|
|
@@ -1105,7 +1144,7 @@ interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpIntercept
|
|
|
1105
1144
|
* @returns An OPTIONS
|
|
1106
1145
|
* {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#httprequesthandler `HttpRequestHandler`}
|
|
1107
1146
|
* for the provided path. The path and method must be declared in the interceptor schema.
|
|
1108
|
-
* @throws {
|
|
1147
|
+
* @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
|
|
1109
1148
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptormethodpath `interceptor.<method>(path)` API reference}
|
|
1110
1149
|
*/
|
|
1111
1150
|
options: AsyncHttpInterceptorMethodHandler<Schema, 'OPTIONS'>;
|
|
@@ -1196,6 +1235,17 @@ declare class InvalidFormDataError extends SyntaxError {
|
|
|
1196
1235
|
constructor(value: string);
|
|
1197
1236
|
}
|
|
1198
1237
|
|
|
1238
|
+
/**
|
|
1239
|
+
* An error thrown when the interceptor is running and some operation requires it to be stopped first.
|
|
1240
|
+
*
|
|
1241
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorstart `interceptor.start()` API reference}
|
|
1242
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorstop `interceptor.stop()` API reference}
|
|
1243
|
+
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorisrunning `interceptor.isRunning` API reference}
|
|
1244
|
+
*/
|
|
1245
|
+
declare class RunningHttpInterceptorError extends Error {
|
|
1246
|
+
constructor(additionalMessage: string);
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1199
1249
|
/**
|
|
1200
1250
|
* An error thrown when the interceptor is not running and it's not possible to use the mocking utilities.
|
|
1201
1251
|
*
|
|
@@ -1203,7 +1253,7 @@ declare class InvalidFormDataError extends SyntaxError {
|
|
|
1203
1253
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorstop `interceptor.stop()` API reference}
|
|
1204
1254
|
* @see {@link https://github.com/zimicjs/zimic/wiki/api‐zimic‐interceptor‐http#http-interceptorisrunning `interceptor.isRunning` API reference}
|
|
1205
1255
|
*/
|
|
1206
|
-
declare class
|
|
1256
|
+
declare class NotRunningHttpInterceptorError extends Error {
|
|
1207
1257
|
constructor();
|
|
1208
1258
|
}
|
|
1209
1259
|
|
|
@@ -1287,12 +1337,6 @@ declare class TimesCheckError extends TypeError {
|
|
|
1287
1337
|
*/
|
|
1288
1338
|
type InferHttpInterceptorSchema<Interceptor> = Interceptor extends LocalHttpInterceptor<infer Schema> ? Schema : Interceptor extends RemoteHttpInterceptor<infer Schema> ? Schema : never;
|
|
1289
1339
|
|
|
1290
|
-
/**
|
|
1291
|
-
* @deprecated This type was renamed to {@link InterceptedHttpInterceptorRequest `InterceptedHttpInterceptorRequest`}.
|
|
1292
|
-
* Please use it instead.
|
|
1293
|
-
*/
|
|
1294
|
-
type TrackedHttpInterceptorRequest<Path extends string, MethodSchema extends HttpMethodSchema, StatusCode extends HttpStatusCode = never> = InterceptedHttpInterceptorRequest<Path, MethodSchema, StatusCode>;
|
|
1295
|
-
|
|
1296
1340
|
/**
|
|
1297
1341
|
* A namespace of interceptor resources for mocking HTTP requests.
|
|
1298
1342
|
*
|
|
@@ -1300,4 +1344,4 @@ type TrackedHttpInterceptorRequest<Path extends string, MethodSchema extends Htt
|
|
|
1300
1344
|
*/
|
|
1301
1345
|
declare const httpInterceptor: Readonly<HttpInterceptorNamespace>;
|
|
1302
1346
|
|
|
1303
|
-
export { DisabledRequestSavingError, type HttpInterceptor, HttpInterceptorNamespace, HttpInterceptorNamespaceDefault, type HttpInterceptorOptions, type HttpInterceptorPlatform, type HttpInterceptorRequest, type HttpInterceptorResponse, type HttpInterceptorType, type HttpRequestHandler, type HttpRequestHandlerBodyStaticRestriction, type HttpRequestHandlerComputedRestriction, type HttpRequestHandlerHeadersStaticRestriction, type HttpRequestHandlerResponseDeclaration, type HttpRequestHandlerResponseDeclarationFactory, type HttpRequestHandlerRestriction, type HttpRequestHandlerSearchParamsStaticRestriction, type HttpRequestHandlerStaticRestriction, type InferHttpInterceptorSchema, type InterceptedHttpInterceptorRequest, InvalidFormDataError, InvalidJSONError, type LocalHttpInterceptor, type LocalHttpInterceptorOptions, type LocalHttpRequestHandler,
|
|
1347
|
+
export { DisabledRequestSavingError, type HttpInterceptor, HttpInterceptorNamespace, HttpInterceptorNamespaceDefault, type HttpInterceptorOptions, type HttpInterceptorPlatform, type HttpInterceptorRequest, type HttpInterceptorResponse, type HttpInterceptorType, type HttpRequestHandler, type HttpRequestHandlerBodyStaticRestriction, type HttpRequestHandlerComputedRestriction, type HttpRequestHandlerHeadersStaticRestriction, type HttpRequestHandlerResponseDeclaration, type HttpRequestHandlerResponseDeclarationFactory, type HttpRequestHandlerRestriction, type HttpRequestHandlerSearchParamsStaticRestriction, type HttpRequestHandlerStaticRestriction, type InferHttpInterceptorSchema, type InterceptedHttpInterceptorRequest, InvalidFormDataError, InvalidJSONError, type LocalHttpInterceptor, type LocalHttpInterceptorOptions, type LocalHttpRequestHandler, NotRunningHttpInterceptorError, type PendingRemoteHttpRequestHandler, type RemoteHttpInterceptor, type RemoteHttpInterceptorOptions, type RemoteHttpRequestHandler, RunningHttpInterceptorError, type SyncedRemoteHttpRequestHandler, TimesCheckError, type UnhandledHttpInterceptorRequest, UnhandledRequestStrategy, UnknownHttpInterceptorPlatformError, UnknownHttpInterceptorTypeError, UnregisteredBrowserServiceWorkerError, httpInterceptor };
|