@stuntman/client
Version:
Stuntman - HTTP proxy / mock API client
84 lines • 4.34 kB
TypeScript
import type * as Stuntman from '@stuntman/shared';
type KeyValueMatcher = string | RegExp | {
key: string;
value?: string | RegExp;
};
type ObjectValueMatcher = string | RegExp | number | boolean | null;
type ObjectKeyValueMatcher = {
key: string;
value?: ObjectValueMatcher;
};
type GQLRequestMatcher = {
operationName?: string | RegExp;
variables?: ObjectKeyValueMatcher[];
query?: string | RegExp;
type?: 'query' | 'mutation';
methodName?: Stuntman.HttpMethod | RegExp;
};
type MatchBuilderVariables = {
filter?: string | RegExp;
hostname?: string | RegExp;
pathname?: string | RegExp;
port?: number | string | RegExp;
searchParams?: KeyValueMatcher[];
headers?: KeyValueMatcher[];
bodyText?: string | RegExp | null;
bodyJson?: ObjectKeyValueMatcher[];
bodyGql?: GQLRequestMatcher;
jwt?: ObjectKeyValueMatcher[];
};
declare class RuleBuilderBaseBase {
protected rule: Stuntman.SerializableRule;
protected _matchBuilderVariables: MatchBuilderVariables;
constructor(rule?: Stuntman.SerializableRule, _matchBuilderVariables?: MatchBuilderVariables);
}
declare class RuleBuilderBase extends RuleBuilderBaseBase {
limitedUse(hitCount: number): this;
singleUse(): this;
storeTraffic(): this;
disabled(): void;
}
declare class RuleBuilder extends RuleBuilderBase {
raisePriority(by?: number): this;
decreasePriority(by?: number): this;
customTtl(ttlSeconds: number): this;
customId(id: string): this;
onRequestTo(filter: string | RegExp): RuleBuilderInitialized;
onRequestToHostname(hostname: string | RegExp): RuleBuilderInitialized;
onRequestToPathname(pathname: string | RegExp): RuleBuilderInitialized;
onRequestToPort(port: string | number | RegExp): RuleBuilderInitialized;
onAnyRequest(): RuleBuilderInitialized;
}
declare class RuleBuilderRequestInitialized extends RuleBuilderBase {
modifyResponse(modifyFunction: Stuntman.ResponseManipulationFn | Stuntman.RemotableFunction<Stuntman.ResponseManipulationFn>, localVariables?: Stuntman.LocalVariables): Stuntman.SerializableRule;
}
declare class RuleBuilderInitialized extends RuleBuilderRequestInitialized {
withHostname(hostname: string | RegExp): this;
withPathname(pathname: string | RegExp): this;
withPort(port: number | string | RegExp): this;
withSearchParam(key: string | RegExp): RuleBuilderInitialized;
withSearchParam(key: string, value?: string | RegExp): RuleBuilderInitialized;
withSearchParams(params: KeyValueMatcher[]): RuleBuilderInitialized;
withHeader(key: string | RegExp): RuleBuilderInitialized;
withHeader(key: string, value?: string | RegExp): RuleBuilderInitialized;
withHeaders(...headers: KeyValueMatcher[]): RuleBuilderInitialized;
withBodyText(includes: string): RuleBuilderInitialized;
withBodyText(matches: RegExp): RuleBuilderInitialized;
withoutBody(): RuleBuilderInitialized;
withJwt(hasKey: string): RuleBuilderInitialized;
withJwt(hasKey: string, withValue: ObjectValueMatcher): RuleBuilderInitialized;
withJwt(matches: ObjectKeyValueMatcher): RuleBuilderInitialized;
withBodyJson(hasKey: string): RuleBuilderInitialized;
withBodyJson(hasKey: string, withValue: ObjectValueMatcher): RuleBuilderInitialized;
withBodyJson(matches: ObjectKeyValueMatcher): RuleBuilderInitialized;
withBodyGql(gqlMatcher: GQLRequestMatcher): RuleBuilderInitialized;
proxyPass(): Stuntman.SerializableRule;
mockResponse(staticResponse: Stuntman.Response): Stuntman.SerializableRule;
mockResponse(generationFunction: Stuntman.RemotableFunction<Stuntman.ResponseGenerationFn>): Stuntman.SerializableRule;
mockResponse(localFn: Stuntman.ResponseGenerationFn, localVariables?: Stuntman.LocalVariables): Stuntman.SerializableRule;
modifyRequest(modifyFunction: Stuntman.RequestManipulationFn | Stuntman.RemotableFunction<Stuntman.RequestManipulationFn>, localVariables?: Stuntman.LocalVariables): RuleBuilderRequestInitialized;
modifyResponse(modifyFunction: Stuntman.ResponseManipulationFn | Stuntman.RemotableFunction<Stuntman.ResponseManipulationFn>, localVariables?: Stuntman.LocalVariables): Stuntman.SerializableRule;
}
export declare const ruleBuilder: () => RuleBuilder;
export {};
//# sourceMappingURL=ruleBuilder.d.ts.map