Catalyst / admin/Bid-Sentinel 14.8 GB / 57.8 GB 40.0 GB free
Help Sign in

admin / Bid-Sentinel

public

Bid Scrape and Tracking Application with AI Capability

Code Issues Pull requests Pipelines Packages Security Insights Wiki Settings
Bid-Sentinel / bid-sentinel-v2 / frontend / src / api / client.js 12116 B · main
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
import axios from "axios";

// Defaults to the same-origin "/api" path, which nginx reverse-proxies to the
// backend (see frontend/nginx.conf). This works whether the app is opened on the
// Docker host or any remote machine. Override with VITE_API_BASE_URL only if you
// run the frontend dev server separately (e.g. "http://localhost:8000").
const BASE_URL = import.meta.env.VITE_API_BASE_URL || "/api";
const TOKEN_KEY = "ctt_token";

export const tokenStore = {
  get: () => localStorage.getItem(TOKEN_KEY),
  set: (t) => localStorage.setItem(TOKEN_KEY, t),
  clear: () => localStorage.removeItem(TOKEN_KEY),
};

const api = axios.create({ baseURL: BASE_URL });

// Attach the JWT to every request (persistent session via localStorage).
api.interceptors.request.use((config) => {
  const token = tokenStore.get();
  if (token) config.headers.Authorization = `Bearer ${token}`;
  return config;
});

// On 401, clear the stale token and bounce to login.
api.interceptors.response.use(
  (res) => res,
  (error) => {
    if (error.response?.status === 401) {
      tokenStore.clear();
      if (window.location.pathname !== "/login") {
        window.location.assign("/login");
      }
    }
    return Promise.reject(error);
  }
);

// --- Auth -----------------------------------------------------------------
export async function getSetupStatus() {
  const { data } = await api.get("/auth/setup-status");
  return data; // { needs_setup: boolean }
}

export async function setupAdmin({ email, full_name, password }) {
  const { data } = await api.post("/auth/setup", { email, full_name, password });
  tokenStore.set(data.access_token);
  return data;
}

export async function login(email, password) {
  // OAuth2PasswordRequestForm expects form-encoded username/password.
  const form = new URLSearchParams();
  form.append("username", email);
  form.append("password", password);
  const { data } = await api.post("/auth/login", form, {
    headers: { "Content-Type": "application/x-www-form-urlencoded" },
  });
  tokenStore.set(data.access_token);
  return data;
}

export async function fetchMe() {
  const { data } = await api.get("/auth/me");
  return data;
}

// --- Tenders --------------------------------------------------------------
export async function fetchTenders(params = {}) {
  const { data } = await api.get("/tenders", { params });
  return data;
}

export async function createTender(payload) {
  const { data } = await api.post("/tenders", payload);
  return data;
}

export async function updateTender(tenderId, payload) {
  const { data } = await api.patch(`/tenders/${tenderId}`, payload);
  return data;
}

export async function deleteTender(tenderId) {
  const { data } = await api.delete(`/tenders/${tenderId}`);
  return data; // { batch_id }
}

export async function bulkDeleteTenders(ids) {
  const { data } = await api.post("/tenders/bulk-delete", { ids });
  return data; // { deleted, suppressed, batch_id }
}

export async function undoDelete(batchId) {
  const { data } = await api.post(`/tenders/undo/${batchId}`);
  return data; // { restored }
}

export async function updateBidStatus(tenderId, bidStatus) {
  const { data } = await api.patch(`/tenders/${tenderId}/status`, {
    bid_status: bidStatus,
  });
  return data;
}

export async function updateOutcome(tenderId, outcome) {
  const { data } = await api.patch(`/tenders/${tenderId}/outcome`, { outcome });
  return data;
}

export async function fetchComments(tenderId) {
  const { data } = await api.get(`/tenders/${tenderId}/comments`);
  return data;
}

export async function addComment(tenderId, body) {
  const { data } = await api.post(`/tenders/${tenderId}/comments`, { body });
  return data;
}

export async function deleteComment(tenderId, commentId) {
  await api.delete(`/tenders/${tenderId}/comments/${commentId}`);
}

// --- Audit trail (admin) --------------------------------------------------
export async function fetchAudit(limit = 200) {
  const { data } = await api.get("/audit", { params: { limit } });
  return data;
}

export async function triggerScrape() {
  const { data } = await api.post("/tenders/scrape");
  return data;
}

// --- Users (admin / RBAC) -------------------------------------------------
export async function fetchUsers() {
  const { data } = await api.get("/users");
  return data;
}

export async function createUser(payload) {
  const { data } = await api.post("/users", payload);
  return data;
}

export async function updateUser(id, payload) {
  const { data } = await api.patch(`/users/${id}`, payload);
  return data;
}

export async function deleteUser(id) {
  await api.delete(`/users/${id}`);
}

// --- Portals --------------------------------------------------------------
export async function fetchPortals() {
  const { data } = await api.get("/config/portals");
  return data;
}

export async function setPortalEnabled(key, enabled) {
  const { data } = await api.patch(`/config/portals/${key}`, { enabled });
  return data;
}

export async function addPortal({ name, url, scope }) {
  const { data } = await api.post("/config/portals", { name, url, scope });
  return data;
}

export async function deletePortal(key) {
  await api.delete(`/config/portals/${key}`);
}

// --- Keywords -------------------------------------------------------------
export async function fetchKeywords() {
  const { data } = await api.get("/config/keywords");
  return data; // { builtin: [...], custom: [{id, keyword}] }
}

export async function addKeyword(keyword) {
  const { data } = await api.post("/config/keywords", { keyword });
  return data;
}

export async function deleteKeyword(id) {
  await api.delete(`/config/keywords/${id}`);
}

// --- CPV codes (scrape criteria) ------------------------------------------
export async function fetchCpvCodes() {
  const { data } = await api.get("/config/cpv");
  return data; // [{id, code, description}]
}

export async function addCpvCode({ code, description }) {
  const { data } = await api.post("/config/cpv", { code, description });
  return data;
}

export async function setCpvEnabled(id, enabled) {
  const { data } = await api.patch(`/config/cpv/${id}`, { enabled });
  return data;
}

export async function deleteCpvCode(id) {
  await api.delete(`/config/cpv/${id}`);
}

export async function fetchCpvStrict() {
  const { data } = await api.get("/config/cpv-strict");
  return data; // { strict }
}

export async function setCpvStrict(strict) {
  const { data } = await api.patch("/config/cpv-strict", { strict });
  return data;
}

// --- Tune-out list (negative filter) --------------------------------------
export async function fetchTuneOuts() {
  const { data } = await api.get("/config/tuneout");
  return data; // [{id, term}]
}

export async function addTuneOut(term) {
  const { data } = await api.post("/config/tuneout", { term });
  return data; // { term: {id, term}, removed }
}

export async function deleteTuneOut(id) {
  await api.delete(`/config/tuneout/${id}`);
}

// --- Schedule -------------------------------------------------------------
export async function fetchSchedule() {
  const { data } = await api.get("/config/schedule");
  return data; // { timezone, slots: [...], next_run }
}

export async function addScheduleSlots(days, times) {
  const { data } = await api.post("/config/schedule", { days, times });
  return data;
}

export async function toggleScheduleSlot(id, enabled) {
  const { data } = await api.patch(`/config/schedule/${id}`, { enabled });
  return data;
}

export async function deleteScheduleSlot(id) {
  await api.delete(`/config/schedule/${id}`);
}

// --- Capability profile & analysis (deterministic, non-AI) ----------------
export async function fetchCapabilities() {
  const { data } = await api.get("/config/capabilities");
  return data; // { terms: [{id, term}] }
}

export async function addCapability(term) {
  const { data } = await api.post("/config/capabilities", { term });
  return data;
}

export async function deleteCapability(id) {
  await api.delete(`/config/capabilities/${id}`);
}

export async function uploadCapabilityDoc(file) {
  const form = new FormData();
  form.append("file", file);
  const { data } = await api.post("/config/capabilities/upload", form, {
    headers: { "Content-Type": "multipart/form-data" },
  });
  return data; // { filename, extracted_chars, suggested, detected_certs }
}

export async function fetchCertLexicon() {
  const { data } = await api.get("/config/certs");
  return data; // string[]
}

export async function recomputeAnalysis() {
  const { data } = await api.post("/config/recompute");
  return data; // { updated, message }
}

// --- AI bolt-on -----------------------------------------------------------
export async function fetchAiConfig() {
  const { data } = await api.get("/config/ai");
  return data; // { enabled, available, model }
}

export async function setAiEnabled(enabled) {
  const { data } = await api.patch("/config/ai", { enabled });
  return data;
}

// --- Accreditations held --------------------------------------------------
export async function fetchAccreditations() {
  const { data } = await api.get("/config/accreditations");
  return data;
}
export async function addAccreditation(name) {
  const { data } = await api.post("/config/accreditations", { name });
  return data;
}
export async function deleteAccreditation(id) {
  await api.delete(`/config/accreditations/${id}`);
}

// --- Intelligence (analyst) -----------------------------------------------
export async function fetchIntelSummary() {
  const { data } = await api.get("/intelligence/summary");
  return data;
}
export async function fetchCapabilityGaps() {
  const { data } = await api.get("/intelligence/capability-gaps");
  return data;
}
export async function fetchCertGaps() {
  const { data } = await api.get("/intelligence/cert-gaps");
  return data;
}
export async function fetchBuyers() {
  const { data } = await api.get("/intelligence/buyers");
  return data;
}
export async function fetchWinLoss() {
  const { data } = await api.get("/intelligence/winloss");
  return data;
}
export async function fetchTrends() {
  const { data } = await api.get("/intelligence/trends");
  return data;
}
export async function fetchAngles(useAi = false) {
  const { data } = await api.get("/intelligence/angles", { params: { use_ai: useAi } });
  return data;
}
export async function fetchIntelReportBlob(useAi = false) {
  const resp = await api.get("/intelligence/report.pdf", {
    params: { use_ai: useAi },
    responseType: "blob",
  });
  return new Blob([resp.data], { type: "application/pdf" });
}

export async function downloadIntelReport(useAi = false) {
  const blob = await fetchIntelReportBlob(useAi);
  triggerDownload(blob, "bid-sentinel-intelligence.pdf");
}

// --- Management summary report --------------------------------------------
export async function fetchManagementSummaryBlob() {
  const resp = await api.get("/intelligence/management-summary.pdf", {
    responseType: "blob",
  });
  return new Blob([resp.data], { type: "application/pdf" });
}

export async function downloadManagementSummary() {
  const blob = await fetchManagementSummaryBlob();
  triggerDownload(blob, "bid-sentinel-management-summary.pdf");
}

function triggerDownload(blob, filename) {
  const url = URL.createObjectURL(blob);
  const a = document.createElement("a");
  a.href = url;
  a.download = filename;
  document.body.appendChild(a);
  a.click();
  document.body.removeChild(a);
  URL.revokeObjectURL(url);
}

// --- Email me this --------------------------------------------------------
export async function fetchEmailStatus() {
  const { data } = await api.get("/email/status");
  return data; // { available }
}

export async function emailReport(blob, filename, subject) {
  const form = new FormData();
  form.append("file", blob, filename);
  form.append("subject", subject || "Bid Sentinel report");
  const { data } = await api.post("/email/report", form, {
    headers: { "Content-Type": "multipart/form-data" },
  });
  return data; // { sent, to }
}

export default api;