@rustedcompiler/frappe-hooks
Version:
Reusable HTTP hooks for React and Frappe
93 lines • 3.42 kB
JavaScript
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FrappeClient = void 0;
exports.getInstanceManager = getInstanceManager;
exports.getUtils = getUtils;
__exportStar(require("./lib/provider/FrappeProvider"), exports);
__exportStar(require("./hooks/useDocuments"), exports);
__exportStar(require("./hooks/useDocument"), exports);
__exportStar(require("./hooks/useAuth"), exports);
class FrappeClient {
constructor(options) {
this.tokenProvided = false;
this.baseUrl = null;
this.initialized = false;
this.updatedTimeStamp = Date.now();
if (options.token) {
this.tokenProvided = true;
}
this.baseUrl = options.baseURL.replace(/\/$/, '');
// this.axiosInstance = axios.create({
// baseURL: options.baseURL.replace(/\/$/, ''),
// withCredentials: true,
// headers: {
// ...(options.token && { Authorization: `token ${options.token}` }),
// },
// })
this.initialized = true;
FrappeClient.options.baseURL = options.baseURL;
FrappeClient.options.token = options.token;
}
static getInstance(options) {
if (!FrappeClient.instance) {
if (options == undefined) {
if (FrappeClient.options.baseURL !== '') {
if (FrappeClient.options.baseURL == "") {
throw new Error("Server URL not provided");
}
}
}
else {
if (options.baseURL !== '') {
if (options.baseURL == "") {
throw new Error("Server URL not provided");
}
}
}
FrappeClient.instance = new FrappeClient({ baseURL: FrappeClient.options.baseURL, token: FrappeClient.options.token });
}
return FrappeClient.instance;
}
getBaseUrl() {
return this.baseUrl;
}
getInitialized() {
return this.initialized;
}
setUpdated() {
console.log(this.updatedTimeStamp, "up");
this.updatedTimeStamp = Date.now();
console.log(this.updatedTimeStamp, "up down");
}
getUpdated() {
return this.updatedTimeStamp;
}
}
exports.FrappeClient = FrappeClient;
FrappeClient.options = { baseURL: "", token: "" };
function getInstanceManager() {
return FrappeClient.getInstance();
}
function getUtils() {
const client = FrappeClient.getInstance();
const initialized = client.getUpdated();
const baseUrl = client?.getBaseUrl();
return {
initialized, setUpdate: client?.setUpdated?.bind(client), baseUrl
};
}
//# sourceMappingURL=index.js.map
;