@stuntman/client
Advanced tools
Comparing version 0.1.6 to 0.1.7
{ | ||
"name": "@stuntman/client", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "Stuntman - HTTP proxy / mock API client", | ||
@@ -58,5 +58,5 @@ "main": "dist/index.js", | ||
"build": "tsc", | ||
"lint": "prettier --check . && eslint . --ext ts", | ||
"lint:fix": "prettier --write ./{src,test} && eslint ./{src,test} --ext ts --fix" | ||
"lint": "prettier --check \"./{src,test}/**/*\" && eslint \"./{src,test}/**/*\"", | ||
"lint:fix": "prettier --write \"./{src,test}/**/*\" && eslint \"./{src,test}/**/*\" --fix" | ||
} | ||
} |
import serializeJavascript from 'serialize-javascript'; | ||
import { ClientError } from './clientError'; | ||
import { DEFAULT_API_PORT } from '@stuntman/shared'; | ||
import { stuntmanConfig } from '@stuntman/shared'; | ||
import type * as Stuntman from '@stuntman/shared'; | ||
type ClientOptions = { | ||
protocol?: 'http' | 'https'; | ||
host?: string; | ||
port?: number; | ||
timeout?: number; | ||
apiKey?: string; | ||
}; | ||
const SERIALIZE_JAVASCRIPT_OPTIONS: serializeJavascript.SerializeJSOptions = { | ||
@@ -100,3 +92,3 @@ unsafe: true, | ||
private options: ClientOptions; | ||
private options: Stuntman.ClientConfig; | ||
@@ -107,9 +99,7 @@ private get baseUrl() { | ||
constructor(options?: ClientOptions) { | ||
constructor(options?: Partial<Stuntman.ClientConfig>) { | ||
this.options = { | ||
...stuntmanConfig.client, | ||
...options, | ||
timeout: options?.timeout || 60000, | ||
host: options?.host || 'localhost', | ||
protocol: options?.protocol || 'http', | ||
port: options?.port || options?.protocol ? (options.protocol === 'https' ? 443 : 80) : DEFAULT_API_PORT, | ||
port: options?.port || options?.protocol ? (options.protocol === 'https' ? 443 : 80) : stuntmanConfig.client.port, | ||
}; | ||
@@ -116,0 +106,0 @@ } |
@@ -20,4 +20,6 @@ import { AppError } from '@stuntman/shared'; | ||
super(args); | ||
this.originalStack = args.stack; | ||
if (args.stack) { | ||
this.originalStack = args.stack; | ||
} | ||
} | ||
} |
@@ -62,6 +62,6 @@ import { v4 as uuidv4 } from 'uuid'; | ||
const [rawKey, ...rest] = path.split('.'); | ||
const key = rawKey.replace(arrayIndexerRegex, ''); | ||
const shouldBeArray = arrayIndexerRegex.test(rawKey); | ||
const key = (rawKey ?? '').replace(arrayIndexerRegex, ''); | ||
const shouldBeArray = rawKey ? arrayIndexerRegex.test(rawKey) : false; | ||
const arrayIndex = | ||
(arrayIndexerRegex.exec(rawKey)?.groups?.arrayIndex || '').length > 0 | ||
rawKey && (arrayIndexerRegex.exec(rawKey)?.groups?.arrayIndex || '').length > 0 | ||
? Number(arrayIndexerRegex.exec(rawKey)?.groups?.arrayIndex) | ||
@@ -86,7 +86,7 @@ : Number.NaN; | ||
: actualValue !== undefined; | ||
return { result, description: `${currentPath}` }; | ||
return { result, description: `${currentPath} === undefined` }; | ||
} | ||
if (!shouldBeArray) { | ||
const result = value instanceof RegExp ? value.test(actualValue) : value === actualValue; | ||
return { result, description: `${currentPath}` }; | ||
return { result, description: `${currentPath} === "${actualValue}"` }; | ||
} | ||
@@ -297,14 +297,13 @@ } | ||
} | ||
if (!matchBuilderVariables.bodyGql.variables) { | ||
return { result: true, description: `no variables to match` }; | ||
} | ||
for (const jsonMatcher of Array.isArray(matchBuilderVariables.bodyGql.variables) | ||
? matchBuilderVariables.bodyGql.variables | ||
: [matchBuilderVariables.bodyGql.variables]) { | ||
const matchObjectResult = matchObject(req.gqlBody.variables, jsonMatcher.key, jsonMatcher.value); | ||
if (!matchObjectResult.result) { | ||
return { | ||
result: false, | ||
description: `GQL variable ${jsonMatcher.key} != "${jsonMatcher.value}". Detail: ${matchObjectResult.description}`, | ||
}; | ||
if (matchBuilderVariables.bodyGql.variables) { | ||
for (const jsonMatcher of Array.isArray(matchBuilderVariables.bodyGql.variables) | ||
? matchBuilderVariables.bodyGql.variables | ||
: [matchBuilderVariables.bodyGql.variables]) { | ||
const matchObjectResult = matchObject(req.gqlBody.variables, jsonMatcher.key, jsonMatcher.value); | ||
if (!matchObjectResult.result) { | ||
return { | ||
result: false, | ||
description: `GQL variable ${jsonMatcher.key} != "${jsonMatcher.value}". Detail: ${matchObjectResult.description}`, | ||
}; | ||
} | ||
} | ||
@@ -538,3 +537,7 @@ } | ||
} | ||
this._matchBuilderVariables.bodyJson.push({ key: keyOrMatcher, value: withValue }); | ||
if (withValue === undefined) { | ||
this._matchBuilderVariables.bodyJson.push({ key: keyOrMatcher }); | ||
} else { | ||
this._matchBuilderVariables.bodyJson.push({ key: keyOrMatcher, value: withValue }); | ||
} | ||
return this; | ||
@@ -553,2 +556,5 @@ } | ||
withBodyGql(gqlMatcher: GQLRequestMatcher): RuleBuilderInitialized { | ||
if (this._matchBuilderVariables.bodyGql) { | ||
throw new Error('gqlMatcher already set'); | ||
} | ||
this._matchBuilderVariables.bodyGql = gqlMatcher; | ||
@@ -555,0 +561,0 @@ return this; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
0
41990
7
781