@bapp/auto-api-client
Version:
Client to consume BAPP auto API, based on content types with type inference
161 lines (160 loc) • 3.39 kB
JavaScript
var k = Object.defineProperty;
var m = (n, t, e) => t in n ? k(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
var u = (n, t, e) => m(n, typeof t != "symbol" ? t + "" : t, e);
import h from "axios";
import { mergeConfigs as a } from "./utils.js";
class R {
constructor(t = {}) {
u(this, "axiosInstance");
const { host: e = "https://panel.bapp.ro/api", axiosInstance: s } = t;
this.axiosInstance = s ?? h.create({ baseURL: e });
}
async _makeRequest(t, e, s = {}) {
const { filter: i, config: p, axiosConfig: c } = s, { appSlug: r = "account", tenantId: d } = p ?? {}, o = {
"x-tenant-id": d
};
r && (o["x-app-slug"] = r);
const g = a(c, {
method: t,
url: e,
headers: o,
params: i
});
return (await this.axiosInstance.request(g)).data;
}
// User
getMe(t = {}) {
return this.runTask(
"bapp_framework.me",
void 0,
a(t, { config: { appSlug: "" } })
);
}
// App
getApp(t, e = {}) {
return this.runTask(
"bapp_framework.getapp",
void 0,
a(e, { config: { appSlug: t } })
);
}
// Entity
getEntityListIntrospect(t, e = {}) {
return this.runTask(
"bapp_framework.listintrospect",
void 0,
a(e, { filter: { ct: t } })
);
}
getEntityDetailIntrospect(t, e, s = {}) {
return this.runTask(
"bapp_framework.detailintrospect",
void 0,
a(s, { filter: { ct: t, pk: e } })
);
}
listEntities(t, e = {}) {
return this._makeRequest(
"GET",
`/content-type/${t}/`,
e
);
}
getEntity(t, e, s = {}) {
return this._makeRequest(
"GET",
`/content-type/${t}/${e}/`,
s
);
}
createEntity(t, e = void 0, s = {}) {
return this._makeRequest(
"post",
`/content-type/${t}/`,
a(s, {
axiosConfig: {
data: e
}
})
);
}
updateEntity(t, e, s = void 0, i = {}) {
return this._makeRequest(
"put",
`/content-type/${t}/${e}/`,
a(i, {
data: s
})
);
}
updatePartialEntity(t, e, s = void 0, i = {}) {
return this._makeRequest(
"patch",
`/content-type/${t}/${e}/`,
a(i, {
axiosConfig: {
data: s
}
})
);
}
deleteEntity(t, e, s = {}) {
return this._makeRequest(
"delete",
`/content-type/${t}/${e}/`,
s
);
}
// Tasks
listTasks(t = {}) {
return this._makeRequest("get", "/tasks", t);
}
detailTask(t, e = {}) {
return this._makeRequest("options", `/tasks/${t}`, e);
}
runTask(t, e = void 0, s = {}) {
const i = e == null ? "GET" : "POST";
return this._makeRequest(
i,
`/tasks/${t}`,
a(s, {
axiosConfig: {
data: e
}
})
);
}
// Widgets
listWidgets(t = {}) {
return this._makeRequest("get", "/widgets", t);
}
detailWidget(t, e = {}) {
return this._makeRequest(
"get",
"/widgets",
a(e, {
filter: {
code: t
}
})
);
}
renderWidget(t, e = void 0, s = {}) {
return this._makeRequest(
"post",
"/widgets",
a(s, {
axiosConfig: {
data: {
code: t,
payload: e
}
}
})
);
}
}
export {
R as BappAutoApi,
R as default
};