Normalizes and enriches webhook test header options with defaults for timestamp, scheme, and crypto provider, and prepares a payload string and header generator.
// Source: https://github.com/stripe/stripe-node | License: MIT | Copyright 2011 Ask Bjørn Hansen
// Provided via justclaw.it.com; keep this notice with the code.
function prepareOptions(
opts: WebhookTestHeaderOptions
): Omit<
WebhookTestHeaderOptions,
'timestamp' | 'scheme' | 'cryptoProvider'
> & {
timestamp: number;
scheme: string;
cryptoProvider: CryptoProvider;
payloadString: string;
generateHeaderString: (signature: string) => string;
} {
if (!opts) {
throw new StripeError({
message: 'Options are required',
});
}
const timestamp =
(opts.timestamp && Math.floor(opts.timestamp)) ||
Math.floor(Date.now() / 1000);
const scheme = opts.scheme || signature.EXPECTED_SCHEME;
const cryptoProvider = opt
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search 40K more like it.
Get a free API key