// pkg/dist-src/auth.js
async function auth(callback) {
  const result = await callback();
  if (!result) {
    return {
      type: "unauthenticated"
    };
  }
  const token = result.replace(/^(token|bearer) +/i, "");
  const tokenType = token.split(/\./).length === 3 ? "app" : /^v\d+\./.test(token) ? "installation" : "oauth";
  return {
    type: "token",
    token,
    tokenType
  };
}

// pkg/dist-src/with-authorization-prefix.js
function withAuthorizationPrefix(token) {
  if (token.split(/\./).length === 3) {
    return `bearer ${token}`;
  }
  return `token ${token}`;
}

// pkg/dist-src/hook.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);
}

// pkg/dist-src/index.js
var createCallbackAuth = function createCallbackAuth2(options) {
  if (!options || !options.callback) {
    throw new Error(
      "[@octokit/auth-callback] No options.callback passed to createCallbackAuth"
    );
  }
  if (typeof options.callback !== "function") {
    throw new Error(
      "[@octokit/auth-callback] options.callback passed to createCallbackAuth is not a function"
    );
  }
  return Object.assign(auth.bind(null, options.callback), {
    hook: hook.bind(null, options.callback)
  });
};
export {
  createCallbackAuth
};
