import { withAuthorizationPrefix } from "./with-authorization-prefix.js";
async function hook(callback, request, route, parameters) {
  const endpoint = request.endpoint.merge(
    route,
    parameters
  );
  const result = await callback();
  if (!result) {
    return request(endpoint);
  }
  const token = result.replace(/^(token|bearer) +/i, "");
  endpoint.headers.authorization = withAuthorizationPrefix(token);
  return request(endpoint);
}
export {
  hook
};
