@glodon-aiot/agent-cli-sdk
Version:
aiot agent client js sdk
42 lines (41 loc) • 1.36 kB
JavaScript
var d = Object.defineProperty, h = Object.defineProperties;
var x = Object.getOwnPropertyDescriptors;
var s = Object.getOwnPropertySymbols;
var E = Object.prototype.hasOwnProperty, S = Object.prototype.propertyIsEnumerable;
var a = (t, e, r) => e in t ? d(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, p = (t, e) => {
for (var r in e || (e = {}))
E.call(e, r) && a(t, r, e[r]);
if (s)
for (var r of s(e))
S.call(e, r) && a(t, r, e[r]);
return t;
}, f = (t, e) => h(t, x(e));
import I from "axios";
import { isExpired as $ } from "../utils.mjs";
import { CVForceApi as C } from "@glodon-aiot/apis";
function w(t, e, r) {
const m = (o) => {
var i;
return e && ($(e) && r(403, "aiotToken is timeout"), o.headers = (i = o.headers) != null ? i : {}, o.headers = f(p({}, o.headers), {
Authorization: e ? `Bearer ${e}` : ""
})), o;
};
function u(o, i = !0) {
const n = `${t}${o}`, c = I.create({
baseURL: n
});
return i && c.interceptors.request.use(m), c;
}
const A = (o, i) => {
o === 401 && r(o, "aiotToken is invalid");
}, g = (o, i) => {
console.log("onAppStatusError", o, i), o !== 10001 && o !== 10215 && r(o, i);
}, v = u("/data/v1");
return new C(v, {
onHttpStatusError: A,
onAppStatusError: g
});
}
export {
w as getCVForceService
};