import {
  __glob
} from "./chunk-YPSWSI3M.js";

// src/authorize.ts
var authorize = (client, token) => {
  if (typeof token === "string") {
    client.defaults.headers.common.authorization = `Bearer ${token}`;
  } else {
    client.interceptors.request.use(async (config) => {
      const resolved = await token();
      config.headers.authorization = `Bearer ${resolved}`;
      return config;
    });
  }
  return client;
};

// import("./docs/**/*") in src/help.ts
var globImport_docs = __glob({
  "./docs/README.json": () => import("./README-7R2JR652.js"),
  "./docs/_index.json": () => import("./_index-CLT2KTVS.js"),
  "./docs/access-token.json": () => import("./access-token-GSQZLDXR.js"),
  "./docs/address-suggestions.json": () => import("./address-suggestions-74244BAJ.js"),
  "./docs/address.json": () => import("./address-QVJUGMOG.js"),
  "./docs/ai-agents.json": () => import("./ai-agents-IZWFEUSH.js"),
  "./docs/app.json": () => import("./app-5KSVSKDU.js"),
  "./docs/audit-logs.json": () => import("./audit-logs-5VXHOQ7S.js"),
  "./docs/automation.json": () => import("./automation-GFNNLSIN.js"),
  "./docs/billing.json": () => import("./billing-IPALEAG2.js"),
  "./docs/blueprint-manifest.json": () => import("./blueprint-manifest-ELK4SGN7.js"),
  "./docs/consent.json": () => import("./consent-NNYHF2N4.js"),
  "./docs/customer-portal.json": () => import("./customer-portal-Y3GLUVMW.js"),
  "./docs/dashboard.json": () => import("./dashboard-UTPGXFW5.js"),
  "./docs/data-governance.json": () => import("./data-governance-36Y33JVG.js"),
  "./docs/deduplication.json": () => import("./deduplication-G2ZY4NMX.js"),
  "./docs/design.json": () => import("./design-WL4AZIGX.js"),
  "./docs/document.json": () => import("./document-CY2A2OE7.js"),
  "./docs/email-settings.json": () => import("./email-settings-CKFJU4WZ.js"),
  "./docs/email-template.json": () => import("./email-template-WYROV3UG.js"),
  "./docs/entity-mapping.json": () => import("./entity-mapping-7J3IAGKQ.js"),
  "./docs/entity.json": () => import("./entity-CK76MXVN.js"),
  "./docs/environments.json": () => import("./environments-E3X6NYGX.js"),
  "./docs/erp-integration.json": () => import("./erp-integration-SBQJ6HEG.js"),
  "./docs/event-catalog.json": () => import("./event-catalog-D7VJ7WRS.js"),
  "./docs/file.json": () => import("./file-XSN3NAVZ.js"),
  "./docs/iban.json": () => import("./iban-LDKYDVQV.js"),
  "./docs/integration-toolkit.json": () => import("./integration-toolkit-FRPFOYT2.js"),
  "./docs/journey.json": () => import("./journey-KDR5EU3W.js"),
  "./docs/kanban.json": () => import("./kanban-PMG5TXE5.js"),
  "./docs/message.json": () => import("./message-HCA2KSH6.js"),
  "./docs/metering.json": () => import("./metering-KOSCPPKB.js"),
  "./docs/notes.json": () => import("./notes-3AO5GXIT.js"),
  "./docs/notification.json": () => import("./notification-VWDZRSFZ.js"),
  "./docs/organization.json": () => import("./organization-ZERPH2IH.js"),
  "./docs/partner-directory.json": () => import("./partner-directory-THI7JEXK.js"),
  "./docs/permissions.json": () => import("./permissions-X3SJVSPC.js"),
  "./docs/pricing-tier.json": () => import("./pricing-tier-VUOFK5Q7.js"),
  "./docs/pricing.json": () => import("./pricing-C65DTZSX.js"),
  "./docs/purpose.json": () => import("./purpose-RBRV3AQZ.js"),
  "./docs/sandbox.json": () => import("./sandbox-L2SOOGGR.js"),
  "./docs/sharing.json": () => import("./sharing-MNDABPL7.js"),
  "./docs/submission.json": () => import("./submission-7BISSPO6.js"),
  "./docs/targeting.json": () => import("./targeting-GEJTJN5Z.js"),
  "./docs/template-variables.json": () => import("./template-variables-6CLOG67C.js"),
  "./docs/user.json": () => import("./user-EIEOI3OG.js"),
  "./docs/validation-rules.json": () => import("./validation-rules-P6F5P73P.js"),
  "./docs/webhooks.json": () => import("./webhooks-RTOU3MS5.js"),
  "./docs/workflow-definition.json": () => import("./workflow-definition-GNAKDNG7.js"),
  "./docs/workflow.json": () => import("./workflow-G7VFCXY7.js")
});

// src/help.ts
var kebabCase = (str) => str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
var resolveDoc = async (filename) => {
  try {
    const mod = await globImport_docs(`./docs/${filename}`);
    return mod.default ?? mod;
  } catch {
    return `No documentation found for "${filename}". Run help() to see available APIs.`;
  }
};
var help = async (apiName) => {
  return resolveDoc(apiName ? `${kebabCase(apiName)}.json` : "README.json");
};

// import("./definitions/**/*.json") in src/openapi.ts
var globImport_definitions_json = __glob({
  "./definitions/access-token-runtime.json": () => import("./access-token-runtime-KCKGT4O7.js"),
  "./definitions/access-token.json": () => import("./access-token-2O6ULCCN.js"),
  "./definitions/address-runtime.json": () => import("./address-runtime-YFCNBJBW.js"),
  "./definitions/address-suggestions-runtime.json": () => import("./address-suggestions-runtime-NIMC2J32.js"),
  "./definitions/address-suggestions.json": () => import("./address-suggestions-BYUTV7OU.js"),
  "./definitions/address.json": () => import("./address-IJF4N2UV.js"),
  "./definitions/ai-agents-runtime.json": () => import("./ai-agents-runtime-25YRUJHI.js"),
  "./definitions/ai-agents.json": () => import("./ai-agents-PKCHKKJS.js"),
  "./definitions/app-runtime.json": () => import("./app-runtime-U7RGV7KT.js"),
  "./definitions/app.json": () => import("./app-VJW2KKWE.js"),
  "./definitions/audit-logs-runtime.json": () => import("./audit-logs-runtime-76R6WRAB.js"),
  "./definitions/audit-logs.json": () => import("./audit-logs-F2NHDISQ.js"),
  "./definitions/automation-runtime.json": () => import("./automation-runtime-VP4M7Z4R.js"),
  "./definitions/automation.json": () => import("./automation-WEVRW77F.js"),
  "./definitions/billing-runtime.json": () => import("./billing-runtime-C6BMGWCX.js"),
  "./definitions/billing.json": () => import("./billing-ASWY7HC3.js"),
  "./definitions/blueprint-manifest-runtime.json": () => import("./blueprint-manifest-runtime-E2FN43TB.js"),
  "./definitions/blueprint-manifest.json": () => import("./blueprint-manifest-UGGYWGRZ.js"),
  "./definitions/consent-runtime.json": () => import("./consent-runtime-OAPXBJH2.js"),
  "./definitions/consent.json": () => import("./consent-7MNRAINV.js"),
  "./definitions/customer-portal-runtime.json": () => import("./customer-portal-runtime-374XJ6LB.js"),
  "./definitions/customer-portal.json": () => import("./customer-portal-L5DEQEGC.js"),
  "./definitions/dashboard-runtime.json": () => import("./dashboard-runtime-PSKSGLCF.js"),
  "./definitions/dashboard.json": () => import("./dashboard-UDL26RGG.js"),
  "./definitions/data-governance-runtime.json": () => import("./data-governance-runtime-LITKCNSG.js"),
  "./definitions/data-governance.json": () => import("./data-governance-PLS5TJ7Z.js"),
  "./definitions/deduplication-runtime.json": () => import("./deduplication-runtime-VL4R2VIG.js"),
  "./definitions/deduplication.json": () => import("./deduplication-RKLRTNZU.js"),
  "./definitions/design-runtime.json": () => import("./design-runtime-QMJM4FAF.js"),
  "./definitions/design.json": () => import("./design-VLRA2WGV.js"),
  "./definitions/document-runtime.json": () => import("./document-runtime-GFEBGNMS.js"),
  "./definitions/document.json": () => import("./document-SEZ45XAO.js"),
  "./definitions/email-settings-runtime.json": () => import("./email-settings-runtime-EGIJ2AVQ.js"),
  "./definitions/email-settings.json": () => import("./email-settings-QGCIUWLC.js"),
  "./definitions/email-template-runtime.json": () => import("./email-template-runtime-QBB64BJQ.js"),
  "./definitions/email-template.json": () => import("./email-template-346NDG4D.js"),
  "./definitions/entity-mapping-runtime.json": () => import("./entity-mapping-runtime-HCOJM6DV.js"),
  "./definitions/entity-mapping.json": () => import("./entity-mapping-UOGYYCZH.js"),
  "./definitions/entity-runtime.json": () => import("./entity-runtime-D4DV5XRM.js"),
  "./definitions/entity.json": () => import("./entity-HSCBRIOS.js"),
  "./definitions/environments-runtime.json": () => import("./environments-runtime-BPR47PW7.js"),
  "./definitions/environments.json": () => import("./environments-VCREW73K.js"),
  "./definitions/erp-integration-runtime.json": () => import("./erp-integration-runtime-BHHWMG4O.js"),
  "./definitions/erp-integration.json": () => import("./erp-integration-735KQ73W.js"),
  "./definitions/event-catalog-runtime.json": () => import("./event-catalog-runtime-6FA3SCRI.js"),
  "./definitions/event-catalog.json": () => import("./event-catalog-ZUFXLY7B.js"),
  "./definitions/file-runtime.json": () => import("./file-runtime-B6AAGZQF.js"),
  "./definitions/file.json": () => import("./file-EJJBQEQI.js"),
  "./definitions/iban-runtime.json": () => import("./iban-runtime-EVXLFPPP.js"),
  "./definitions/iban.json": () => import("./iban-HXFDAF4I.js"),
  "./definitions/integration-toolkit-runtime.json": () => import("./integration-toolkit-runtime-LYHFVIRW.js"),
  "./definitions/journey-runtime.json": () => import("./journey-runtime-YXIAOTMD.js"),
  "./definitions/journey.json": () => import("./journey-KW3ZFQAL.js"),
  "./definitions/kanban-runtime.json": () => import("./kanban-runtime-R6EWHBFS.js"),
  "./definitions/kanban.json": () => import("./kanban-QXQEQIF4.js"),
  "./definitions/message-runtime.json": () => import("./message-runtime-XDCFFLYK.js"),
  "./definitions/message.json": () => import("./message-M62W3KP2.js"),
  "./definitions/metering-runtime.json": () => import("./metering-runtime-NJ6NEUMB.js"),
  "./definitions/metering.json": () => import("./metering-W3TA6ZUQ.js"),
  "./definitions/notes-runtime.json": () => import("./notes-runtime-CVNAVKPP.js"),
  "./definitions/notes.json": () => import("./notes-4LVCGLBE.js"),
  "./definitions/notification-runtime.json": () => import("./notification-runtime-KREP32YP.js"),
  "./definitions/notification.json": () => import("./notification-MJQGIBM7.js"),
  "./definitions/organization-runtime.json": () => import("./organization-runtime-P3WZ2BBU.js"),
  "./definitions/organization.json": () => import("./organization-U5HPX627.js"),
  "./definitions/partner-directory-runtime.json": () => import("./partner-directory-runtime-GNVT7U7R.js"),
  "./definitions/partner-directory.json": () => import("./partner-directory-XJ7KI7EX.js"),
  "./definitions/permissions-runtime.json": () => import("./permissions-runtime-D74HOCVO.js"),
  "./definitions/permissions.json": () => import("./permissions-SGPGANEP.js"),
  "./definitions/pricing-runtime.json": () => import("./pricing-runtime-JRR4FWFI.js"),
  "./definitions/pricing-tier-runtime.json": () => import("./pricing-tier-runtime-LEGBNNLA.js"),
  "./definitions/pricing-tier.json": () => import("./pricing-tier-36WV4P4X.js"),
  "./definitions/pricing.json": () => import("./pricing-3RNPCUR6.js"),
  "./definitions/purpose-runtime.json": () => import("./purpose-runtime-V5X5ESZV.js"),
  "./definitions/purpose.json": () => import("./purpose-QFQ4W255.js"),
  "./definitions/sandbox-runtime.json": () => import("./sandbox-runtime-4MLOMFPK.js"),
  "./definitions/sandbox.json": () => import("./sandbox-O2NWMZGJ.js"),
  "./definitions/sharing-runtime.json": () => import("./sharing-runtime-OZGIZWL3.js"),
  "./definitions/sharing.json": () => import("./sharing-KEWK5LNG.js"),
  "./definitions/submission-runtime.json": () => import("./submission-runtime-JPHKPQ77.js"),
  "./definitions/submission.json": () => import("./submission-MWJU4L32.js"),
  "./definitions/targeting-runtime.json": () => import("./targeting-runtime-M2VSTKFT.js"),
  "./definitions/targeting.json": () => import("./targeting-RB7LBQMX.js"),
  "./definitions/template-variables-runtime.json": () => import("./template-variables-runtime-62U3ZY5P.js"),
  "./definitions/template-variables.json": () => import("./template-variables-XLIW4GY6.js"),
  "./definitions/user-runtime.json": () => import("./user-runtime-U4HYUWJU.js"),
  "./definitions/user.json": () => import("./user-O4JDAIRO.js"),
  "./definitions/validation-rules-runtime.json": () => import("./validation-rules-runtime-6MRCS5X2.js"),
  "./definitions/validation-rules.json": () => import("./validation-rules-GCI64B57.js"),
  "./definitions/webhooks-runtime.json": () => import("./webhooks-runtime-XCQYIGQK.js"),
  "./definitions/webhooks.json": () => import("./webhooks-XXLU2KWP.js"),
  "./definitions/workflow-definition-runtime.json": () => import("./workflow-definition-runtime-OVXRSE34.js"),
  "./definitions/workflow-definition.json": () => import("./workflow-definition-VFYWBQQ3.js"),
  "./definitions/workflow-runtime.json": () => import("./workflow-runtime-DNTQDYPQ.js"),
  "./definitions/workflow.json": () => import("./workflow-VLNZNE3S.js")
});

// src/openapi.ts
var kebabCase2 = (str) => str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
var openapi = async (apiName) => {
  const mod = await globImport_definitions_json(`./definitions/${kebabCase2(apiName)}.json`);
  return mod.default ?? mod;
};

// src/compact.ts
var L = { p: "path", q: "query", h: "header", c: "cookie" };
var ep = (p) => {
  const r = { name: p[0], in: L[p[1]] };
  let i = 2;
  if (typeof p[i] === "boolean") {
    if (p[i]) r.required = true;
    i++;
  }
  if (typeof p[i] === "string") {
    r.style = p[i];
    i++;
  }
  if (typeof p[i] === "boolean") {
    r.explode = p[i];
    i++;
  }
  return r;
};
var mp = (ps) => ps.map((p) => p.length === 1 ? { $ref: `#/components/parameters/${p[0]}` } : ep(p));
var expand = (c) => {
  const paths = {};
  for (const [id, m, p, ps, b] of c.o) {
    const op = { operationId: id, responses: {} };
    if (ps?.length) op.parameters = mp(ps);
    if (b) op.requestBody = { content: { "application/json": {} } };
    if (!paths[p]) paths[p] = {};
    paths[p][m] = op;
  }
  if (c.pp)
    for (const [p, ps] of Object.entries(c.pp)) {
      if (!paths[p]) paths[p] = {};
      paths[p].parameters = mp(ps);
    }
  const doc = {
    openapi: c.v || "3.0.2",
    info: { title: "", version: "" },
    paths,
    servers: c.s ? [{ url: c.s, ...c.sv ? { variables: c.sv } : {} }] : []
  };
  if (c.cp) {
    const params = {};
    for (const [k, v] of Object.entries(c.cp)) params[k] = ep(v);
    doc.components = { parameters: params };
  }
  return doc;
};

// src/client-factory.ts
import OpenAPIClientAxios from "openapi-client-axios";
var createApiClient = (params) => {
  const { definition, token, headers, apiName } = params;
  const api = new OpenAPIClientAxios({ definition, quick: true });
  const client = api.initSync();
  if (headers && Object.keys(headers).length > 0) {
    client.defaults.headers.common = {
      ...client.defaults.headers.common ?? {},
      ...headers
    };
  }
  if (token) {
    authorize(client, token);
  }
  if (apiName) {
    client.help = () => help(apiName);
    client.openapi = () => openapi(apiName);
  }
  return client;
};

// src/proxy.ts
var createApiHandle = (params) => {
  const { resolveClient, createClient } = params;
  return new Proxy({}, {
    get(_, prop) {
      if (prop === "getClient") {
        return () => resolveClient();
      }
      if (prop === "createClient") {
        return () => createClient();
      }
      if (prop === "then" || prop === "catch" || prop === "finally") {
        return void 0;
      }
      return (...args) => {
        const client = resolveClient();
        const method = client[prop];
        if (typeof method === "function") {
          return method.apply(client, args);
        }
        return method;
      };
    }
  });
};

export {
  authorize,
  help,
  openapi,
  expand,
  createApiClient,
  createApiHandle
};
