RJBULK-APP/diag.mjs

39 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

import PocketBase from "pocketbase";
const PB_URL = "http://pocketbase-zinlbpsext2ro0lgb2558vfy.169.239.180.130.sslip.io";
const pb = new PocketBase(PB_URL);
await pb.admins.authWithPassword("David.els1@outlook.com", "1234567890");
// Capture the actual HTTP request
const origSend = pb.send;
pb.send = function (path, options) {
console.log("===REQUEST===");
console.log("Path:", path);
console.log("Method:", options.method);
console.log("Body:", JSON.stringify(options.body, null, 2));
return origSend.call(this, path, options).then(r => {
console.log("===RESPONSE===");
console.log("Status:", r.status);
return r;
}).catch(e => {
console.log("===ERROR===");
console.log("Status:", e.status);
console.log("Data:", JSON.stringify(e.response?.data, null, 2));
throw e;
});
};
try { await pb.collections.delete("test_dbg"); } catch (e) {}
try {
const created = await pb.collections.create({
name: "test_dbg",
type: "base",
fields: [
{ name: "rel", type: "relation", options: { collectionId: "pbc_108570809", cascadeDelete: false, maxSelect: 1 } },
],
});
console.log("Created:", created.id);
await pb.collections.delete("test_dbg");
} catch (err) {
console.log("Failed");
}