import { CustomerAccountUIExtensionError } from './errors.mjs';

/**
 * Returns the full API object that was passed in to your extension when it was created.
 * Depending on the extension target, this object can contain different properties.
 */
function useApi() {
  const api = globalThis === null || globalThis === void 0 ? void 0 : globalThis.shopify;
  if (api == null) {
    throw new CustomerAccountUIExtensionError('You can only call this hook when running as a customer account UI extension.');
  }
  return api;
}

/**
 * Returns the full API object that was passed in to your extension when it was created.
 * Depending on the extension target, this object can contain different properties.
 *
 * > Caution: This is deprecated, use `useApi` instead.
 *
 * @deprecated This is deprecated, use `useApi` instead.
 */
function useExtensionApi() {
  return useApi();
}

export { useApi, useExtensionApi };
