UNPKG

azion

Version:

Azion Packages for Edge Computing.

1,720 lines 285 kB
import { create as qt, all as St } from "mathjs"; import Pt from "ajv-errors"; import $t from "ajv-keywords"; import Rt from "ajv"; const Xe = "https://ai.azion.com/copilot/chat/completions", xt = async (a, s) => { const t = await fetch(Xe, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Token ${a}` }, body: JSON.stringify(s) }); if (!t.ok) throw new Error(`HTTP error! status: ${t.status}`); return t.json(); }, It = async function* (a, s) { const t = await fetch(Xe, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Token ${a}` }, body: JSON.stringify(s) }); if (!t.ok) throw new Error(`HTTP error! status: ${t.status}`); const e = t.body?.getReader(); if (!e) throw new Error("Response body is not readable"); const r = new TextDecoder(); let i = ""; for (; ; ) { const { done: n, value: o } = await e.read(); if (n) break; i += r.decode(o, { stream: !0 }); const d = i.split(` `); i = d.pop() || ""; for (const l of d) if (l.startsWith("data: ")) { const p = l.slice(6); if (p === "[DONE]") return; yield JSON.parse(p); } } }, Ot = process.env.AZION_DEBUG && process.env.AZION_DEBUG === "true", Lt = (a) => a ?? process.env.AZION_TOKEN ?? "", Ct = (a) => a ?? !!Ot, Nt = async (a, s, t) => { try { const e = await xt(a, { ...s, stream: !1 }); return t?.debug && console.log("AI Chat Response:", e), { data: e, error: null }; } catch (e) { return t?.debug && console.error("Error in AI chat:", e), { data: null, error: e instanceof Error ? e : new Error("Unknown error occurred") }; } }, Dt = async function* (a, s, t) { try { const e = It(a, { ...s, stream: !0 }); for await (const r of e) t?.debug && console.log("AI Stream Chunk:", r), yield { data: r, error: null }; } catch (e) { t?.debug && console.error("Error in AI stream chat:", e), yield { data: null, error: e instanceof Error ? e : new Error("Unknown error occurred") }; } }, Bt = (a) => { const s = Lt(a?.token), t = Ct(a?.options?.debug); return { chat: (e, r) => Nt(s, e, { ...a?.options, ...r, debug: t }), streamChat: (e, r) => Dt(s, e, { ...a?.options, ...r, debug: t }) }; }, Ft = process.env.AZION_DEBUG && process.env.AZION_DEBUG === "true", m = (a) => a ?? process.env.AZION_TOKEN ?? "", c = (a) => a ?? !!Ft, $ = (a, s, t) => { let e; if (a && typeof a == "object") { const r = Object.keys(a)[0]; if (r && typeof a[r] == "string") e = a[r]; else if ("detail" in a && typeof a.detail == "string") e = a.detail; else if ("message" in a && typeof a.message == "string") e = a.message; else if ("error" in a) { if (typeof a.error == "string") e = a.error; else if (typeof a.error == "object" && a.error !== null) { const i = Object.keys(a.error)[0]; i && typeof a.error[i] == "string" ? e = a.error[i] : "message" in a.error && typeof a.error.message == "string" && (e = a.error.message); } } } else typeof a == "string" && (e = a); return { message: e || t, operation: s }; }; async function u(a, s, t, e = !0) { const r = await fetch(a, s); if (!r.ok) { const i = `HTTP error! Status: ${r.status} - ${r.statusText}`; throw t && console.log(`Error in fetch: ${i}`), new Error(i); } if (e) { const i = r.headers.get("content-type"); if (!i || !i.includes("application/json")) { const d = `Expected JSON response, but got: ${await r.text()}`; throw t && console.log(`Error in fetch: ${d}`), new Error(d); } return await r.json(); } else return await r.text(); } const C = "https://api.azionapi.net/edge_applications", zt = async (a, s, t, e) => { try { const { page: r = 1, page_size: i = 10, sort: n, order: o } = t || {}, d = new URLSearchParams(); return r && d.append("page", String(r)), i && d.append("page_size", String(i)), n && d.append("sort", n), o && d.append("order", o), await u( `${C}/${s}/cache_settings${d.toString() ? `?${d.toString()}` : ""}`, { method: "GET", headers: { Accept: "application/json; version=3", Authorization: `Token ${a}` } }, e ); } catch (r) { throw e && console.error("Error getting cache settings:", r), r; } }, kt = async (a, s, t, e) => { try { return await u( `${C}/${s}/cache_settings/${t}`, { method: "GET", headers: { Accept: "application/json; version=3", Authorization: `Token ${a}` } }, e ); } catch (r) { throw e && console.error("Error getting cache setting by ID:", r), r; } }, Gt = async (a, s, t, e) => { try { return await u( `${C}/${s}/cache_settings`, { method: "POST", headers: { Accept: "application/json; version=3", "Content-Type": "application/json", Authorization: `Token ${a}` }, body: JSON.stringify(t) }, e ); } catch (r) { throw e && console.error("Error creating cache setting:", r), r; } }, Ut = async (a, s, t, e, r) => { try { return await u( `${C}/${s}/cache_settings/${t}`, { method: "PATCH", headers: { Accept: "application/json; version=3", "Content-Type": "application/json", Authorization: `Token ${a}` }, body: JSON.stringify(e) }, r ); } catch (i) { throw r && console.error("Error updating cache setting:", i), i; } }, Ht = async (a, s, t, e) => { try { return await u( `${C}/${s}/cache_settings/${t}`, { method: "DELETE", headers: { Accept: "application/json; version=3", Authorization: `Token ${a}` } }, e ); } catch (r) { throw e && console.error("Error deleting cache setting:", r), r; } }, N = async (a, s, t, e) => { try { return { data: (await Gt(m(a), s, t, c(e?.debug))).results }; } catch (r) { return { error: { message: r instanceof Error ? r.message : "Failed to create cache setting", operation: "create cache setting" } }; } }, D = async (a, s, t, e) => { try { return { data: (await kt(m(a), s, t, c(e?.debug))).results }; } catch (r) { return { error: { message: r instanceof Error ? r.message : "Failed to get cache setting", operation: "get cache setting" } }; } }, B = async (a, s, t, e) => { try { const r = await zt(m(a), s, t, c(e?.debug)), i = r.results.map((n) => ({ ...n })); return { data: { count: r.count, total_pages: r.total_pages, schema_version: r.schema_version, links: r.links, results: i // results do tipo AzionCacheSetting[] } }; } catch (r) { return { error: { message: r instanceof Error ? r.message : "Failed to get cache settings", operation: "get cache settings" } }; } }, F = async (a, s, t, e, r) => { try { return { data: (await Ut( m(a), s, t, e, c(r?.debug) )).results }; } catch (i) { return { error: { message: i instanceof Error ? i.message : "Failed to update cache setting", operation: "update cache setting" } }; } }, z = async (a, s, t, e) => { try { return await Ht(m(a), s, t, c(e?.debug)), { data: void 0 }; } catch (r) { return { error: { message: r instanceof Error ? r.message : "Failed to delete cache setting", operation: "delete cache setting" } }; } }, k = "https://api.azionapi.net/edge_applications", Vt = async (a, s, t, e) => { try { const { page: r = 1, page_size: i = 10, sort: n, order: o } = t || {}, d = new URLSearchParams(); return r && d.append("page", String(r)), i && d.append("page_size", String(i)), n && d.append("sort", n), o && d.append("order", o), await u( `${k}/${s}/device_groups${d.toString() ? `?${d.toString()}` : ""}`, { method: "GET", headers: { Accept: "application/json; version=3", Authorization: `Token ${a}` } }, e ); } catch (r) { throw e && console.error("Error getting device groups:", r), r; } }, Wt = async (a, s, t, e) => { try { return await u( `${k}/${s}/device_groups/${t}`, { method: "GET", headers: { Accept: "application/json; version=3", Authorization: `Token ${a}` } }, e ); } catch (r) { throw e && console.error("Error getting device group by ID:", r), r; } }, Kt = async (a, s, t, e) => { try { return await u( `${k}/${s}/device_groups`, { method: "POST", headers: { Accept: "application/json; version=3", "Content-Type": "application/json", Authorization: `Token ${a}` }, body: JSON.stringify(t) }, e ); } catch (r) { throw e && console.error("Error creating device group:", r), r; } }, Jt = async (a, s, t, e, r) => { try { return await u( `${k}/${s}/device_groups/${t}`, { method: "PATCH", headers: { Accept: "application/json; version=3", "Content-Type": "application/json", Authorization: `Token ${a}` }, body: JSON.stringify(e) }, r ); } catch (i) { throw r && console.error("Error updating device group:", i), i; } }, Qt = async (a, s, t, e) => { try { return await u( `${k}/${s}/device_groups/${t}`, { method: "DELETE", headers: { Accept: "application/json; version=3", Authorization: `Token ${a}` } }, e ); } catch (r) { throw e && console.error("Error deleting device group:", r), r; } }, G = async (a, s, t, e) => { try { const { results: r } = await Kt(m(a), s, t, c(e?.debug)); return { data: r }; } catch (r) { return { error: { message: r instanceof Error ? r.message : "Failed to create device group", operation: "create device group" } }; } }, U = async (a, s, t, e) => { try { return await Qt(m(a), s, t, c(e?.debug)), { data: void 0 }; } catch (r) { return { error: { message: r instanceof Error ? r.message : "Failed to delete device group", operation: "delete device group" } }; } }, H = async (a, s, t, e) => { try { const { results: r } = await Wt(m(a), s, t, c(e?.debug)); return { data: r }; } catch (r) { return { error: { message: r instanceof Error ? r.message : "Failed to get device group", operation: "get device group" } }; } }, V = async (a, s, t, e) => { try { return { data: await Vt(m(a), s, t, c(e?.debug)) }; } catch (r) { return { error: { message: r instanceof Error ? r.message : "Failed to get device groups", operation: "get device groups" } }; } }, W = async (a, s, t, e, r) => { try { const { results: i } = await Jt( m(a), s, t, e, c(r?.debug) ); return { data: i }; } catch (i) { return { error: { message: i instanceof Error ? i.message : "Failed to update device group", operation: "update device group" } }; } }, K = "https://api.azionapi.net/edge_applications", Zt = async (a, s, t, e) => { try { const { page: r = 1, page_size: i = 10, sort: n, order_by: o, filter: d } = t || {}, l = new URLSearchParams(); return r && l.append("page", String(r)), i && l.append("page_size", String(i)), n && l.append("sort", n), o && l.append("order_by", o), d && l.append("filter", d), await u( `${K}/${s}/functions_instances${l.toString() ? `?${l.toString()}` : ""}`, { method: "GET", headers: { Accept: "application/json; version=3", Authorization: `Token ${a}` } }, e ); } catch (r) { throw e && console.error("Error listing function instances:", r), r; } }, Yt = async (a, s, t, e) => { try { return await u( `${K}/${s}/functions_instances/${t}`, { method: "GET", headers: { Accept: "application/json; version=3", Authorization: `Token ${a}` } }, e ); } catch (r) { throw e && console.error("Error getting function instance by ID:", r), r; } }, Xt = async (a, s, t, e) => { try { const r = await u( `${K}/${s}/functions_instances`, { method: "POST", headers: { Accept: "application/json; version=3", "Content-Type": "application/json", Authorization: `Token ${a}` }, body: JSON.stringify(t) }, e ); return e && console.log("Response:", r), r; } catch (r) { throw e && console.error("Error creating function instance:", r), r; } }, er = async (a, s, t, e, r) => { try { return await u( `${K}/${s}/functions_instances/${t}`, { method: "PATCH", headers: { Accept: "application/json; version=3", "Content-Type": "application/json", Authorization: `Token ${a}` }, body: JSON.stringify(e) }, r ); } catch (i) { throw r && console.error("Error updating function instance:", i), i; } }, tr = async (a, s, t, e) => { try { return await u( `${K}/${s}/functions_instances/${t}`, { method: "DELETE", headers: { Accept: "application/json; version=3", Authorization: `Token ${a}` } }, e ); } catch (r) { throw e && console.error("Error deleting function instance:", r), r; } }, J = async (a, s, t, e) => { try { return { data: (await Xt( m(a), s, t, c(e?.debug) )).results }; } catch (r) { return { error: { message: r instanceof Error ? r.message : "Failed to create function instance", operation: "create function instance" } }; } }, Q = async (a, s, t, e) => { try { return await tr(m(a), s, t, c(e?.debug)), { data: void 0 }; } catch (r) { return { error: { message: r instanceof Error ? r.message : "Failed to delete function instance", operation: "delete function instance" } }; } }, Z = async (a, s, t, e) => { try { const { results: r } = await Yt( m(a), s, t, c(e?.debug) ); return { data: r }; } catch (r) { return { error: { message: r instanceof Error ? r.message : "Failed to get function instance", operation: "get function instance" } }; } }, Y = async (a, s, t, e) => { try { return { data: await Zt(m(a), s, t, c(e?.debug)) }; } catch (r) { return { error: { message: r instanceof Error ? r.message : "Failed to get function instances", operation: "get function instances" } }; } }, X = async (a, s, t, e, r) => { try { const { results: i } = await er( m(a), s, t, e, c(r?.debug) ); return { data: i }; } catch (i) { return { error: { message: i instanceof Error ? i.message : "Failed to update function instance", operation: "update function instance" } }; } }, ee = "https://api.azionapi.net/edge_applications", rr = async (a, s, t, e) => { try { const { page: r = 1, page_size: i = 10, sort: n, order: o, filter: d } = t || {}, l = new URLSearchParams(); r && l.append("page", String(r)), i && l.append("page_size", String(i)), n && l.append("sort", n), o && l.append("order", o), d && l.append("filter", d); const p = `${ee}/${s}/origins${l.toString() ? `?${l.toString()}` : ""}`; return e && (console.log("Request URL:", p), console.log("Request headers:", { Accept: "application/json; version=3", Authorization: `Token ${a}` })), await u( p, { method: "GET", headers: { Accept: "application/json; version=3", Authorization: `Token ${a}` } }, e ); } catch (r) { throw e && console.error("Error listing origins:", r), r; } }, ar = async (a, s, t, e) => { try { const r = `${ee}/${s}/origins/${t}`; return e && (console.log("Request URL:", r), console.log("Request headers:", { Accept: "application/json; version=3", Authorization: `Token ${a}` })), await u( r, { method: "GET", headers: { Accept: "application/json; version=3", Authorization: `Token ${a}` } }, e ); } catch (r) { throw e && console.error("Error getting origin by key:", r), r; } }, sr = async (a, s, t, e) => { try { const r = `${ee}/${s}/origins`; return e && (console.log("Request URL:", r), console.log("Request headers:", { Accept: "application/json; version=3", "Content-Type": "application/json", Authorization: `Token ${a}` }), console.log("Request body:", t)), await u( r, { method: "POST", headers: { Accept: "application/json; version=3", "Content-Type": "application/json", Authorization: `Token ${a}` }, body: JSON.stringify(t) }, e ); } catch (r) { throw e && console.error("Error creating origin:", r), r; } }, ir = async (a, s, t, e, r) => { try { const i = `${ee}/${s}/origins/${t}`; return r && (console.log("Request URL:", i), console.log("Request headers:", { Accept: "application/json; version=3", "Content-Type": "application/json", Authorization: `Token ${a}` }), console.log("Request body:", e)), await u( i, { method: "PATCH", headers: { Accept: "application/json; version=3", "Content-Type": "application/json", Authorization: `Token ${a}` }, body: JSON.stringify(e) }, r ); } catch (i) { throw r && console.error("Error updating origin:", i), i; } }, nr = async (a, s, t, e) => { try { const r = `${ee}/${s}/origins/${t}`; return e && (console.log("Request URL:", r), console.log("Request headers:", { Accept: "application/json; version=3", Authorization: `Token ${a}` })), await u( r, { method: "DELETE", headers: { Accept: "application/json; version=3", Authorization: `Token ${a}` } }, e ); } catch (r) { throw e && console.error("Error deleting origin:", r), r; } }, te = async (a, s, t, e) => { try { const { results: r } = await sr(a, s, t, c(e?.debug)); return { data: r }; } catch (r) { return { error: { message: r instanceof Error ? r.message : "Failed to create origin", operation: "create origin" } }; } }, re = async (a, s, t, e) => { try { return await nr(a, s, t, c(e?.debug)), { data: void 0 }; } catch (r) { return { error: { message: r instanceof Error ? r.message : "Failed to delete origin", operation: "delete origin" } }; } }, ae = async (a, s, t, e) => { try { const { results: r } = await ar(a, s, t, c(e?.debug)); return { data: r }; } catch (r) { return { error: { message: r instanceof Error ? r.message : "Failed to get origin", operation: "get origin" } }; } }, se = async (a, s, t, e) => { try { return { data: await rr(a, s, t, c(e?.debug)) }; } catch (r) { return { error: { message: r instanceof Error ? r.message : "Failed to get origins", operation: "get origins" } }; } }, ie = async (a, s, t, e, r) => { try { const { results: i } = await ir(a, s, t, e, c(r?.debug)); return { data: i }; } catch (i) { return { error: { message: i instanceof Error ? i.message : "Failed to update origin", operation: "update origin" } }; } }, ne = "https://api.azionapi.net/edge_applications", or = async (a, s, t, e, r) => { try { const { page: i = 1, page_size: n = 10, sort: o, order: d } = e || {}, l = new URLSearchParams(); i && l.append("page", String(i)), n && l.append("page_size", String(n)), o && l.append("sort", o), d && l.append("order", d); const p = `${ne}/${s}/rules_engine/${t}/rules${l.toString() ? `?${l.toString()}` : ""}`; return r && (console.log("Request URL:", p), console.log("Request headers:", { Accept: "application/json; version=3", Authorization: `Token ${a}` })), await u( p, { method: "GET", headers: { Accept: "application/json; version=3", Authorization: `Token ${a}` } }, r ); } catch (i) { throw r && console.error("Error listing rules:", i), i; } }, cr = async (a, s, t, e, r) => { try { const i = `${ne}/${s}/rules_engine/${t}/rules/${e}`; return r && (console.log("Request URL:", i), console.log("Request headers:", { Accept: "application/json; version=3", Authorization: `Token ${a}` })), await u( i, { method: "GET", headers: { Accept: "application/json; version=3", Authorization: `Token ${a}` } }, r ); } catch (i) { throw r && console.error("Error getting rule by ID:", i), i; } }, dr = async (a, s, t, e, r) => { try { const i = `${ne}/${s}/rules_engine/${t}/rules`; return r && (console.log("Request URL:", i), console.log("Request headers:", { Accept: "application/json; version=3", "Content-Type": "application/json", Authorization: `Token ${a}` }), console.log("Request body:", e)), await u( i, { method: "POST", headers: { Accept: "application/json; version=3", "Content-Type": "application/json", Authorization: `Token ${a}` }, body: JSON.stringify(e) }, r ); } catch (i) { throw r && console.error("Error creating rule:", i), i; } }, lr = async (a, s, t, e, r, i) => { try { const n = `${ne}/${s}/rules_engine/${t}/rules/${e}`; return i && (console.log("Request URL:", n), console.log("Request headers:", { Accept: "application/json; version=3", "Content-Type": "application/json", Authorization: `Token ${a}` }), console.log("Request body:", r)), await u( n, { method: "PATCH", headers: { Accept: "application/json; version=3", "Content-Type": "application/json", Authorization: `Token ${a}` }, body: JSON.stringify(r) }, i ); } catch (n) { throw i && console.error("Error updating rule:", n), n; } }, ur = async (a, s, t, e, r) => { try { const i = `${ne}/${s}/rules_engine/${t}/rules/${e}`; r && (console.log("Request URL:", i), console.log("Request headers:", { Accept: "application/json; version=3", Authorization: `Token ${a}` })), await u( i, { method: "DELETE", headers: { Accept: "application/json; version=3", Authorization: `Token ${a}` } }, r ); } catch (i) { throw r && console.error("Error deleting rule:", i), i; } }, _ = async (a, s, t, e, r) => { try { const { results: i } = await dr(m(a), s, t, e, c(r?.debug)); return { data: i }; } catch (i) { return { error: { message: i instanceof Error ? i.message : "Failed to create rule", operation: "create rule" } }; } }, v = async (a, s, t, e, r) => { try { const { results: i } = await cr(m(a), s, t, e, c(r?.debug)); return { data: i }; } catch (i) { return { error: { message: i instanceof Error ? i.message : "Failed to get rule", operation: "get rule" } }; } }, w = async (a, s, t, e, r) => { try { return { data: await or(m(a), s, t, e, c(r?.debug)) }; } catch (i) { return { error: { message: i instanceof Error ? i.message : "Failed to get rules", operation: "get rules" } }; } }, T = async (a, s, t, e, r, i) => { try { const { results: n } = await lr( m(a), s, t, e, r, c(i?.debug) ); return { data: n }; } catch (n) { return { error: { message: n instanceof Error ? n.message : "Failed to update rule", operation: "update rule" } }; } }, M = async (a, s, t, e, r) => { try { return await ur(m(a), s, t, e, c(r?.debug)), { data: void 0 }; } catch (i) { return { error: { message: i instanceof Error ? i.message : "Failed to delete rule", operation: "delete rule" } }; } }, R = "https://api.azionapi.net/edge_applications", pr = async (a, s, t) => { try { const { order_by: e = "name", sort: r = "asc", page: i = 1, page_size: n = 10 } = s || {}, o = new URLSearchParams({ order_by: e, sort: r, page: String(i), page_size: String(n) }); return await u( `${R}?${o.toString()}`, { method: "GET", headers: { Accept: "application/json; version=3", Authorization: `Token ${a}` } }, t ); } catch (e) { throw t && console.error("Error getting all applications:", e), e; } }, gr = async (a, s, t) => { try { return await u( `${R}/${s}`, { method: "GET", headers: { Accept: "application/json; version=3", Authorization: `Token ${a}` } }, t ); } catch (e) { throw t && console.error("Error getting application by ID:", e), e; } }, mr = async (a, s, t) => { try { return await u( R, { method: "POST", headers: { Accept: "application/json; version=3", "Content-Type": "application/json", Authorization: `Token ${a}` }, body: JSON.stringify(s) }, t ); } catch (e) { throw t && console.error("Error creating application:", e), e; } }, hr = async (a, s, t, e) => { try { return await u( `${R}/${s}`, { method: "PUT", headers: { Accept: "application/json; version=3", "Content-Type": "application/json", Authorization: `Token ${a}` }, body: JSON.stringify(t) }, e ); } catch (r) { throw e && console.error("Error updating application:", r), r; } }, br = async (a, s, t, e) => { try { return await u( `${R}/${s}`, { method: "PATCH", headers: { Accept: "application/json; version=3", "Content-Type": "application/json", Authorization: `Token ${a}` }, body: JSON.stringify(t) }, e ); } catch (r) { throw e && console.error("Error patching application:", r), r; } }, fr = async (a, s, t) => { try { return await u( `${R}/${s}`, { method: "DELETE", headers: { Accept: "application/json; version=3", Authorization: `Token ${a}` } }, t ); } catch (e) { throw t && console.error("Error deleting application:", e), e; } }, yr = async (a, s, t) => { const e = await mr(m(a), s, c(t?.debug)); if (!e || !e.results) return { error: $(e, "post application", "Failed to post application") }; const r = e.results?.id; return { data: { ...e.results, cache: { createCacheSetting: (n) => N(a, r, n.data, { ...t, debug: c(t?.debug) }), getCacheSetting: (n) => D(a, r, n.cacheSettingId, { ...t, debug: c(t?.debug) }), getCacheSettings: (n) => B(a, r, n.params, { ...t, debug: c(t?.debug) }), updateCacheSetting: (n) => F(a, r, n.cacheSettingId, n.data, { ...t, debug: c(t?.debug) }), deleteCacheSetting: (n) => z(a, r, n.cacheSettingId, { ...t, debug: c(t?.debug) }) }, origins: { createOrigin: (n) => te(a, r, n.data, { ...t, debug: c(t?.debug) }), getOrigin: (n) => ae(a, r, n.originKey, { ...t, debug: c(t?.debug) }), getOrigins: (n) => se(a, r, n.params, { ...t, debug: c(t?.debug) }), updateOrigin: (n) => ie(a, r, n.originKey, n.data, { ...t, debug: c(t?.debug) }), deleteOrigin: (n) => re(a, r, n.originKey, { ...t, debug: c(t?.debug) }) }, rules: { request: { createRule: (n) => _(a, r, "request", n.data, { ...t, debug: c(t?.debug) }), getRule: (n) => v(a, r, "request", n.ruleId, { ...t, debug: c(t?.debug) }), getRules: (n) => w(a, r, "request", n.params, { ...t, debug: c(t?.debug) }), updateRule: (n) => T(a, r, "request", n.ruleId, n.data, { ...t, debug: c(t?.debug) }), deleteRule: (n) => M(a, r, "request", n.ruleId, { ...t, debug: c(t?.debug) }) }, response: { createRule: (n) => _(a, r, "response", n.data, { ...t, debug: c(t?.debug) }), getRule: (n) => v(a, r, "response", n.ruleId, { ...t, debug: c(t?.debug) }), getRules: (n) => w(a, r, "response", n.params, { ...t, debug: c(t?.debug) }), updateRule: (n) => T(a, r, "response", n.ruleId, n.data, { ...t, debug: c(t?.debug) }), deleteRule: (n) => M(a, r, "response", n.ruleId, { ...t, debug: c(t?.debug) }) } }, devices: { createDeviceGroup: (n) => G(a, r, n.data, { ...t, debug: c(t?.debug) }), getDeviceGroup: (n) => H(a, r, n.deviceGroupId, { ...t, debug: c(t?.debug) }), getDeviceGroups: (n) => V(a, r, n.params, { ...t, debug: c(t?.debug) }), updateDeviceGroup: (n) => W(a, r, n.deviceGroupId, n.data, { ...t, debug: c(t?.debug) }), deleteDeviceGroup: (n) => U(a, r, n.deviceGroupId, { ...t, debug: c(t?.debug) }) }, functions: { createFunctionInstance: (n) => J(a, r, n.data, { ...t, debug: c(t?.debug) }), getFunctionInstance: (n) => Z(a, r, n.functionInstanceId, { ...t, debug: c(t?.debug) }), getFunctionInstances: (n) => Y(a, r, n.params, { ...t, debug: c(t?.debug) }), updateFunctionInstance: (n) => X(a, r, n.functionInstanceId, n.data, { ...t, debug: c(t?.debug) }), deleteFunctionInstance: (n) => Q(a, r, n.functionInstanceId, { ...t, debug: c(t?.debug) }) } } }; }, _r = async (a, s, t) => { const e = await gr(m(a), s, c(t?.debug)); if (!e || !e.results) return { error: $(e, "get application", "Failed to get application") }; const r = e.results.id; return { data: { ...e.results, cache: { createCacheSetting: (n) => N(a, r, n.data, { ...t, debug: c(t?.debug) }), getCacheSetting: (n) => D(a, r, n.cacheSettingId, { ...t, debug: c(t?.debug) }), getCacheSettings: (n) => B(a, r, n.params, { ...t, debug: c(t?.debug) }), updateCacheSetting: (n) => F(a, r, n.cacheSettingId, n.data, { ...t, debug: c(t?.debug) }), deleteCacheSetting: (n) => z(a, r, n.cacheSettingId, { ...t, debug: c(t?.debug) }) }, origins: { createOrigin: (n) => te(a, r, n.data, { ...t, debug: c(t?.debug) }), getOrigin: (n) => ae(a, r, n.originKey, { ...t, debug: c(t?.debug) }), getOrigins: (n) => se(a, r, n.params, { ...t, debug: c(t?.debug) }), updateOrigin: (n) => ie(a, r, n.originKey, n.data, { ...t, debug: c(t?.debug) }), deleteOrigin: (n) => re(a, r, n.originKey, { ...t, debug: c(t?.debug) }) }, rules: { request: { createRule: (n) => _(a, r, "request", n.data, { ...t, debug: c(t?.debug) }), getRule: (n) => v(a, r, "request", n.ruleId, { ...t, debug: c(t?.debug) }), getRules: (n) => w(a, r, "request", n.params, { ...t, debug: c(t?.debug) }), updateRule: (n) => T(a, r, "request", n.ruleId, n.data, { ...t, debug: c(t?.debug) }), deleteRule: (n) => M(a, r, "request", n.ruleId, { ...t, debug: c(t?.debug) }) }, response: { createRule: (n) => _(a, r, "response", n.data, { ...t, debug: c(t?.debug) }), getRule: (n) => v(a, r, "response", n.ruleId, { ...t, debug: c(t?.debug) }), getRules: (n) => w(a, r, "response", n.params, { ...t, debug: c(t?.debug) }), updateRule: (n) => T(a, r, "response", n.ruleId, n.data, { ...t, debug: c(t?.debug) }), deleteRule: (n) => M(a, r, "response", n.ruleId, { ...t, debug: c(t?.debug) }) } }, devices: { createDeviceGroup: (n) => G(a, r, n.data, { ...t, debug: c(t?.debug) }), getDeviceGroup: (n) => H(a, r, n.deviceGroupId, { ...t, debug: c(t?.debug) }), getDeviceGroups: (n) => V(a, r, n.params, { ...t, debug: c(t?.debug) }), updateDeviceGroup: (n) => W(a, r, n.deviceGroupId, n.data, { ...t, debug: c(t?.debug) }), deleteDeviceGroup: (n) => U(a, r, n.deviceGroupId, { ...t, debug: c(t?.debug) }) }, functions: { createFunctionInstance: (n) => J(a, r, n.data, { ...t, debug: c(t?.debug) }), getFunctionInstance: (n) => Z(a, r, n.functionInstanceId, { ...t, debug: c(t?.debug) }), getFunctionInstances: (n) => Y(a, r, n.params, { ...t, debug: c(t?.debug) }), updateFunctionInstance: (n) => X(a, r, n.functionInstanceId, n.data, { ...t, debug: c(t?.debug) }), deleteFunctionInstance: (n) => Q(a, r, n.functionInstanceId, { ...t, debug: c(t?.debug) }) } } }; }, vr = async (a, s, t) => { const e = await pr(m(a), s, c(t?.debug)); if (!e || !e.results) return { error: $(e, "get applications", "Failed to get applications") }; const r = e.results.map((i) => { const n = i.id; return { ...i, cache: { createCacheSetting: (o) => N(a, n, o.data, { ...t, debug: c(t?.debug) }), getCacheSetting: (o) => D(a, n, o.cacheSettingId, { ...t, debug: c(t?.debug) }), getCacheSettings: (o) => B(a, n, o.params, { ...t, debug: c(t?.debug) }), updateCacheSetting: (o) => F(a, n, o.cacheSettingId, o.data, { ...t, debug: c(t?.debug) }), deleteCacheSetting: (o) => z(a, n, o.cacheSettingId, { ...t, debug: c(t?.debug) }) }, origins: { createOrigin: (o) => te(a, n, o.data, { ...t, debug: c(t?.debug) }), getOrigin: (o) => ae(a, n, o.originKey, { ...t, debug: c(t?.debug) }), getOrigins: (o) => se(a, n, o.params, { ...t, debug: c(t?.debug) }), updateOrigin: (o) => ie(a, n, o.originKey, o.data, { ...t, debug: c(t?.debug) }), deleteOrigin: (o) => re(a, n, o.originKey, { ...t, debug: c(t?.debug) }) }, rules: { request: { createRule: (o) => _(a, n, "request", o.data, { ...t, debug: c(t?.debug) }), getRule: (o) => v(a, n, "request", o.ruleId, { ...t, debug: c(t?.debug) }), getRules: (o) => w(a, n, "request", o.params, { ...t, debug: c(t?.debug) }), updateRule: (o) => T(a, n, "request", o.ruleId, o.data, { ...t, debug: c(t?.debug) }), deleteRule: (o) => M(a, n, "request", o.ruleId, { ...t, debug: c(t?.debug) }) }, response: { createRule: (o) => _(a, n, "response", o.data, { ...t, debug: c(t?.debug) }), getRule: (o) => v(a, n, "response", o.ruleId, { ...t, debug: c(t?.debug) }), getRules: (o) => w(a, n, "response", o.params, { ...t, debug: c(t?.debug) }), updateRule: (o) => T(a, n, "response", o.ruleId, o.data, { ...t, debug: c(t?.debug) }), deleteRule: (o) => M(a, n, "response", o.ruleId, { ...t, debug: c(t?.debug) }) } }, devices: { createDeviceGroup: (o) => G(a, n, o.data, { ...t, debug: c(t?.debug) }), getDeviceGroup: (o) => H(a, n, o.deviceGroupId, { ...t, debug: c(t?.debug) }), getDeviceGroups: (o) => V(a, n, o.params, { ...t, debug: c(t?.debug) }), updateDeviceGroup: (o) => W(a, n, o.deviceGroupId, o.data, { ...t, debug: c(t?.debug) }), deleteDeviceGroup: (o) => U(a, n, o.deviceGroupId, { ...t, debug: c(t?.debug) }) }, functions: { createFunctionInstance: (o) => J(a, n, o.data, { ...t, debug: c(t?.debug) }), getFunctionInstance: (o) => Z(a, n, o.functionInstanceId, { ...t, debug: c(t?.debug) }), getFunctionInstances: (o) => Y(a, n, o.params, { ...t, debug: c(t?.debug) }), updateFunctionInstance: (o) => X(a, n, o.functionInstanceId, o.data, { ...t, debug: c(t?.debug) }), deleteFunctionInstance: (o) => Q(a, n, o.functionInstanceId, { ...t, debug: c(t?.debug) }) } }; }); return { data: { ...e, results: r } }; }, wr = async (a, s, t, e) => { const r = await hr( m(a), s, t, c(e?.debug) ); if (!r || !r.results) return { error: $(r, "put application", "Failed to put application") }; const i = r.results.id; return { data: { ...r.results, cache: { createCacheSetting: (o) => N(a, i, o.data, { ...e, debug: c(e?.debug) }), getCacheSetting: (o) => D(a, i, o.cacheSettingId, { ...e, debug: c(e?.debug) }), getCacheSettings: (o) => B(a, i, o.params, { ...e, debug: c(e?.debug) }), updateCacheSetting: (o) => F(a, i, o.cacheSettingId, o.data, { ...e, debug: c(e?.debug) }), deleteCacheSetting: (o) => z(a, i, o.cacheSettingId, { ...e, debug: c(e?.debug) }) }, origins: { createOrigin: (o) => te(a, i, o.data, { ...e, debug: c(e?.debug) }), getOrigin: (o) => ae(a, i, o.originKey, { ...e, debug: c(e?.debug) }), getOrigins: (o) => se(a, i, o.params, { ...e, debug: c(e?.debug) }), updateOrigin: (o) => ie(a, i, o.originKey, o.data, { ...e, debug: c(e?.debug) }), deleteOrigin: (o) => re(a, i, o.originKey, { ...e, debug: c(e?.debug) }) }, rules: { request: { createRule: (o) => _(a, i, "request", o.data, { ...e, debug: c(e?.debug) }), getRule: (o) => v(a, i, "request", o.ruleId, { ...e, debug: c(e?.debug) }), getRules: (o) => w(a, i, "request", o.params, { ...e, debug: c(e?.debug) }), updateRule: (o) => T(a, i, "request", o.ruleId, o.data, { ...e, debug: c(e?.debug) }), deleteRule: (o) => M(a, i, "request", o.ruleId, { ...e, debug: c(e?.debug) }) }, response: { createRule: (o) => _(a, i, "response", o.data, { ...e, debug: c(e?.debug) }), getRule: (o) => v(a, i, "response", o.ruleId, { ...e, debug: c(e?.debug) }), getRules: (o) => w(a, i, "response", o.params, { ...e, debug: c(e?.debug) }), updateRule: (o) => T(a, i, "response", o.ruleId, o.data, { ...e, debug: c(e?.debug) }), deleteRule: (o) => M(a, i, "response", o.ruleId, { ...e, debug: c(e?.debug) }) } }, devices: { createDeviceGroup: (o) => G(a, i, o.data, { ...e, debug: c(e?.debug) }), getDeviceGroup: (o) => H(a, i, o.deviceGroupId, { ...e, debug: c(e?.debug) }), getDeviceGroups: (o) => V(a, i, o.params, { ...e, debug: c(e?.debug) }), updateDeviceGroup: (o) => W(a, i, o.deviceGroupId, o.data, { ...e, debug: c(e?.debug) }), deleteDeviceGroup: (o) => U(a, i, o.deviceGroupId, { ...e, debug: c(e?.debug) }) }, functions: { createFunctionInstance: (o) => J(a, i, o.data, { ...e, debug: c(e?.debug) }), getFunctionInstance: (o) => Z(a, i, o.functionInstanceId, { ...e, debug: c(e?.debug) }), getFunctionInstances: (o) => Y(a, i, o.params, { ...e, debug: c(e?.debug) }), updateFunctionInstance: (o) => X(a, i, o.functionInstanceId, o.data, { ...e, debug: c(e?.debug) }), deleteFunctionInstance: (o) => Q(a, i, o.functionInstanceId, { ...e, debug: c(e?.debug) }) } } }; }, Tr = async (a, s, t, e) => { const r = await br( m(a), s, t, c(e?.debug) ); if (!r || !r.results) return { error: $(r, "patch application", "Failed to patch application") }; const i = r.results.id; return { data: { ...r.results, cache: { createCacheSetting: (o) => N(a, i, o.data, { ...e, debug: c(e?.debug) }), getCacheSetting: (o) => D(a, i, o.cacheSettingId, { ...e, debug: c(e?.debug) }), getCacheSettings: (o) => B(a, i, o.params, { ...e, debug: c(e?.debug) }), updateCacheSetting: (o) => F(a, i, o.cacheSettingId, o.data, { ...e, debug: c(e?.debug) }), deleteCacheSetting: (o) => z(a, i, o.cacheSettingId, { ...e, debug: c(e?.debug) }) }, origins: { createOrigin: (o) => te(a, i, o.data, { ...e, debug: c(e?.debug) }), getOrigin: (o) => ae(a, i, o.originKey, { ...e, debug: c(e?.debug) }), getOrigins: (o) => se(a, i, o.params, { ...e, debug: c(e?.debug) }), updateOrigin: (o) => ie(a, i, o.originKey, o.data, { ...e, debug: c(e?.debug) }), deleteOrigin: (o) => re(a, i, o.originKey, { ...e, debug: c(e?.debug) }) }, rules: { request: { createRule: (o) => _(a, i, "request", o.data, { ...e, debug: c(e?.debug) }), getRule: (o) => v(a, i, "request", o.ruleId, { ...e, debug: c(e?.debug) }), getRules: (o) => w(a, i, "request", o.params, { ...e, debug: c(e?.debug) }), updateRule: (o) => T(a, i, "request", o.ruleId, o.data, { ...e, debug: c(e?.debug) }), deleteRule: (o) => M(a, i, "request", o.ruleId, { ...e, debug: c(e?.debug) }) }, response: { createRule: (o) => _(a, i, "response", o.data, { ...e, debug: c(e?.debug) }), getRule: (o) => v(a, i, "response", o.ruleId, { ...e, debug: c(e?.debug) }), getRules: (o) => w(a, i, "response", o.params, { ...e, debug: c(e?.debug) }), updateRule: (o) => T(a, i, "response", o.ruleId, o.data, { ...e, debug: c(e?.debug) }), deleteRule: (o) => M(a, i, "response", o.ruleId, { ...e, debug: c(e?.debug) }) } }, devices: { createDeviceGroup: (o) => G(a, i, o.data, { ...e, debug: c(e?.debug) }), getDeviceGroup: (o) => H(a, i, o.deviceGroupId, { ...e, debug: c(e?.debug) }), getDeviceGroups: (o) => V(a, i, o.params, { ...e, debug: c(e?.debug) }), updateDeviceGroup: (o) => W(a, i, o.deviceGroupId, o.data, { ...e, debug: c(e?.debug) }), deleteDeviceGroup: (o) => U(a, i, o.deviceGroupId, { ...e, debug: c(e?.debug) }) }, functions: { createFunctionInstance: (o) => J(a, i, o.data, { ...e, debug: c(e?.debug) }), getFunctionInstance: (o) => Z(a, i, o.functionInstanceId, { ...e, debug: c(e?.debug) }), getFunctionInstances: (o) => Y(a, i, o.params, { ...e, debug: c(e?.debug) }), updateFunctionInstance: (o) => X(a, i, o.functionInstanceId, o.data, { ...e, debug: c(e?.debug) }), deleteFunctionInstance: (o) => Q(a, i, o.functionInstanceId, { ...e, debug: c(e?.debug) }) } } }; }, Mr = async (a, s, t) => { try { return await fr(m(a), s, c(t?.debug)), { data: void 0 }; } catch (e) { return { error: $(e, "delete application", "Failed to delete application") }; } }, jr = (a) => { const s = m(a?.token), t = c(a?.options?.debug); return { createApplication: async ({ data: r }) => yr(s, r, { ...a, debug: t }), deleteApplication: async ({ applicationId: r, options: i }) => Mr(s, r, { ...a?.options, ...i, debug: c(a?.options?.debug ?? i?.debug) }), getApplication: async ({ applicationId: r, options: i }) => _r(s, r, { ...a?.options, ...i, debug: c(a?.options?.debug ?? i?.debug) }), getApplications: async ({ params: r, options: i }) => vr(s, r, { ...a?.options, ...i, debug: c(i?.debug) }), putApplication: async ({ applicationId: r, data: i, options: n }) => wr(s, r, i, { ...a?.options, ...n, debug: c(n?.debug) }), patchApplication: async ({ applicationId: r, data: i, options: n }) => Tr(s, r, i, { ...a?.options, ...n, debug: c(n?.debug) }) }; }, et = [ "args", "device_group", "domain", "geoip_city", "geoip_city_continent_code", "geoip_city_country_code", "geoip_city_country_name", "geoip_continent_code", "geoip_country_code", "geoip_country_name", "geoip_region", "geoip_region_name", "host", "remote_addr", "remote_port", "remote_user", "request", "request_body", "request_method", "request_uri", "scheme", "uri" ], Ar = ["server_addr", "server_port"], Er = [ "ssl_client_fingerprint", "ssl_client_escaped_cert", "ssl_client_s_dn", "ssl_client_s_dn_parsed", "ssl_client_cert", "ssl_client_i_dn", "ssl_client_serial", "ssl_client_v_end", "ssl_client_v_remain", "ssl_client_v_start", "ssl_client_verify" ], qr = [ "sent_http_name", "status", "tcpinfo_rtt", "upstream_addr", "upstream_status" ], Sr = ["cookie_time_offset", "encode_base64"], tt = [...et, ...Ar, ...Er], rt = [...et, ...qr], O = [ "is_equal", "is_not_equal", "starts_with", "does_not_start_with", "matches", "does_not_match" ], L = ["exists", "does_not_exist"], Oe = ["if", "and", "or"], Pr = [.../* @__PURE__ */ new Set([...tt, ...rt])], $r = [ "deny", "drop", "set_rate_limit", "set_waf_ruleset", "run_function", "set_custom_response" ], Le = ["second", "minute"], Ce = ["clientIp", "global"], ye = ["learning", "blocking"], I = [ "header_accept", "header_accept_encoding", "header_accept_language", "header_cookie", "header_origin", "header_referer", "header_user_agent", "host", "network", "request_args", "request_method", "request_uri", "scheme", "client_certificate_validation", "ssl_verification_status" ], Qe = ["if", "and", "or"], at = ["ip_cidr", "asn", "countries"], Rr = ["2021-Q3"], Ne = [ "is_equal", "is_not_equal", "starts_with", "does_not_start_with", "matches", "does_not_match", "exists", "does_not_exist", "is_in_list", "is_not_in_list" ], xr = ["if", "and", "or"], Ir = ["http,https", "http"], Or = ["", "tls_1_0", "tls_1_1", "tls_1_2", "tls_1_3"], Lr = [ "all", "TLSv1.2_2018", "TLSv1.2_2019", "TLSv1.2_2021", "TLSv1.3_2022" ], Cr = [80, 8008, 8080], Nr = [443, 8443, 9440, 9441, 9442, 9443], Dr = ["honor", "override", "no-cache"], Br = ["honor", "override"], Fr = ["ignore", "all", "allowlist", "denylist"], zr = ["ignore", "all", "allowlist", "denylist"], kr = ["ignore", "allowlist"], Gr = ["options", "post"], Ur = ["nearest-region", "us-east-1", "br-east-1"], Hr = ["webpack", "esbuild"], Vr = ["read_only", "read_write", "restricted"], st = [ "deny", "no_content", "deliver", "finish_request_phase", "forward_cookies", "optimize_images", "bypass_cache", "enable_gzip", "redirect_http_to_https" ], it = ["redirect_to_301", "redirect_to_302", "rewrite_request"], nt = ["run_function", "set_cache_policy", "set_connector", "set_origin"], ot = [ "add_request_header", "add_response_header", "filter_request_header", "filter_response_header" ], ct = [ "add_request_cookie", "filter_request_cookie", "set_cookie", "filter_response_cookie" ], dt = ["", "tls_1_0", "tls_1_1", "tls_1_2", "tls_1_3"], lt = ["enforce", "permissive"], ut = ["http1", "http2", "http3"], pt = ["http", "storage", "live_ingest"], gt = ["both", "force_ipv4"], mt = ["preserve", "force_https", "force_http"], ht = ["http1_1"], bt = ["round_robin", "least_conn", "ip_hash"], ft = ["aws4_hmac_sha256"], yt = [ "default", "400", "401", "403", "404", "405", "406", "408", "409", "410", "411", "414", "415", "416", "426", "429", "431", "500", "501", "502", "503", "504", "505" ], Wr = ["page_connector"], Kr = { type: "object", properties: { name: { type: "string", minLength: 1, maxLength: 250, pattern: ".*", errorMessage: "The 'name' field must be a string between 1 and 250 characters." }, type: { type: "string", enum: at, e