SPB Git

Repository Public

insight.tsx 9.3 KB 121 lines tsx

1/**2 * =============================================================================3 *                  SP BOUCHER | INFRASTRUCTURE & AUTOMATION4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : MacLustr SMS Gateway8 * File             : dashboard/src/pages/insight.tsx9 * Module           : pages10 * Repository       : https://git.spboucher.ai/maclustr-sms11 * Project Website  : https://sms.spboucher.ai12 * Created          : 2026-11-3013 * Last Modified    : 2026-11-3014 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: admin@spboucher.ai23 * Technical Contact: dev@spboucher.ai24 * Security/Admin   : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License          : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142import { useState } from "react"43import { useData } from "../api.ts"44import { fmtTime, Page, secs, Table, Tile } from "../ui.tsx"4546export function Analytics() {47  const { data: a } = useData<any>("/api/admin/analytics", ["messages"])48  if (!a) return <Page title="Analytics"><div className="empty">Chargement…</div></Page>49  const days: any[] = a.days, max = Math.max(1, ...days.map(d => Math.max(d.outbound_created ?? 0, d.inbound ?? 0)))50  const t = a.totals51  return <Page title="Analytics" sub={`Du ${a.from} au ${a.to}`}>52    <div className="grid">53      <Tile k="SMS demandés" v={t.outbound_created ?? 0} s={`${t.outbound_segments ?? 0} segment(s)`} /><Tile k="Remis au réseau" v={t.submitted ?? 0} /><Tile k="Livraisons confirmées" v={t.delivered ?? 0} />54      <Tile k="Échecs" v={(t.failed ?? 0) + (t.expired ?? 0)} tone={(t.failed ?? 0) + (t.expired ?? 0) ? "bad" : undefined} s={`dont ${t.expired ?? 0} expiré(s)`} /><Tile k="Issues inconnues" v={t.unknown ?? 0} tone={t.unknown ? "warn" : undefined} /><Tile k="SMS reçus" v={t.inbound ?? 0} />55      <Tile k="Latence médiane" v={secs(a.latency.submit_p50_s)} s={`p95 ${secs(a.latency.submit_p95_s)}`} /><Tile k="Délai de livraison médian" v={secs(a.latency.delivery_p50_s)} s="après remise au réseau" />56    </div>57    <h2>Volume par jour</h2>58    <div className="panel">{days.length ? <>59      <div className="bars">{days.map(d => <div className="col" key={d.day} title={`${d.day} : ${d.outbound_created ?? 0} envoyé(s), ${d.inbound ?? 0} reçu(s), ${d.failed ?? 0} échec(s)`} style={{ flexDirection: "row", alignItems: "flex-end", gap: 1 }}>60        <i style={{ height: `${((d.outbound_created ?? 0) / max) * 100}%`, flex: 1 }} /><i className="in" style={{ height: `${((d.inbound ?? 0) / max) * 100}%`, flex: 1 }} /></div>)}</div>61      <div className="row" style={{ justifyContent: "space-between" }}><div className="legend"><span><span className="dot" style={{ background: "var(--text)" }} />Envoyés</span><span><span className="dot ok" />Reçus</span></div><div className="legend mono">{days[0].day} → {days[days.length - 1].day} · max {max}</div></div>62    </> : <div className="empty">Aucune activité sur la période.</div>}</div>63    <div className="cols">64      <div><h2>Par application</h2><Table head={["Application", "SMS demandés"]} empty="Aucune donnée." rows={a.by_application.map((r: any) => <tr key={r.name}><td>{r.name}</td><td className="num">{r.value}</td></tr>)} /></div>65      <div><h2>Codes d'erreur</h2><Table head={["Code", "Occurrences"]} empty="Aucune erreur sur la période." rows={a.errors.map((r: any) => <tr key={r.code}><td className="mono">{r.code}</td><td className="num">{r.n}</td></tr>)} /></div>66    </div>67    <h2>Par SIM</h2>68    <Table head={["SIM", "Envoyés", "Reçus"]} empty="Aucune donnée." rows={[...new Set(a.by_sim.map((r: any) => r.sim_id))].map((id: any) => <tr key={id}><td className="mono">{id}</td>69      <td className="num">{a.by_sim.find((r: any) => r.sim_id === id && r.metric === "outbound_created")?.value ?? 0}</td><td className="num">{a.by_sim.find((r: any) => r.sim_id === id && r.metric === "inbound")?.value ?? 0}</td></tr>)} />70  </Page>71}7273export function AuditLogs() {74  const [action, setAction] = useState("")75  const { data } = useData<any>(`/api/admin/audit-logs?limit=200${action ? `&action=${encodeURIComponent(action)}` : ""}`, ["settings", "devices"])76  return <Page title="Audit Logs" sub="Journal des actions d'administration. Aucun contenu de SMS n'y figure.">77    <div className="filters"><select value={action} onChange={e => setAction(e.target.value)}><option value="">Toutes les actions</option>{["admin", "api_key", "application", "device", "sim", "pairing_code", "kill_switch", "settings", "webhook", "message", "consent", "allowed_recipients", "opt_outs", "passkey", "android"].map(p => <option key={p} value={p}>{p}.*</option>)}</select></div>78    <Table head={["Date", "Acteur", "Action", "Cible", "Détail", "Adresse"]} empty="Journal vide."79      rows={data?.data.map((l: any) => <tr key={l.id}><td className="nowrap muted">{fmtTime(l.at)}</td><td>{l.actor ?? "—"} <span className="faint">({l.actor_type})</span></td><td className="mono">{l.action}</td><td className="mono faint">{l.target_id ?? ""}</td>80        <td><div className="clip mono faint" title={JSON.stringify(l.detail)}>{Object.keys(l.detail).length ? JSON.stringify(l.detail) : ""}</div></td><td className="mono faint">{l.ip ?? ""}</td></tr>)} />81  </Page>82}8384const CURL = `curl -X POST https://sms.spboucher.ai/v1/messages \\85  -H "Authorization: Bearer $MACLUSTR_SMS_API_KEY" \\86  -H "Content-Type: application/json" \\87  -H "Idempotency-Key: $(uuidgen)" \\88  -d '{ "to": "+14185550123", "text": "Message envoyé depuis MacLustr." }'`89const PY = `from maclustr_sms import MacLustrSMS9091sms = MacLustrSMS(api_key=os.environ["MACLUSTR_SMS_API_KEY"])92result = sms.send(to="+14185550123", text="Notification MacLustr")93print(result.status)`94const TS = `const sms = new MacLustrSMS({ apiKey: process.env.MACLUSTR_SMS_API_KEY })95await sms.send({ to: "+14185550123", text: "Notification MacLustr" })`96const SW = `let sms = MacLustrSMS(apiKey: apiKey)97try await sms.send(to: "+14185550123", text: "Notification MacLustr")`9899export function Documentation() {100  const { data: spec } = useData<any>("/v1/openapi.json", [])101  const ops = spec ? Object.entries<any>(spec.paths).flatMap(([p, m]) => Object.entries<any>(m).map(([method, o]) => ({ p, method: method.toUpperCase(), o }))) : []102  return <Page title="Documentation" sub="API REST v1 — https://sms.spboucher.ai/v1" actions={<a className="btn" href="/v1/openapi.json" target="_blank" rel="noreferrer">OpenAPI 3.1 (JSON)</a>}>103    <div className="panel"><p style={{ marginTop: 0 }}>Authentification : <code>Authorization: Bearer mlsk_…</code> (une clé par application, créée dans <em>API Keys</em>). Erreurs : <code>{'{ "error": { "code", "message" } }'}</code>. Listes paginées : <code>{"{ data, has_more, next_cursor }"}</code>.</p><pre>{CURL}</pre></div>104    <h2>Points d'entrée</h2>105    <Table head={["Méthode", "Chemin", "Fonction", "Scope"]} empty="" rows={spec ? ops.map(x => <tr key={x.method + x.p}><td className="mono">{x.method}</td><td className="mono">{x.p}</td><td>{x.o.summary}</td><td className="mono faint">{x.o["x-required-scope"] ?? "public"}</td></tr>) : null} />106    <h2>Cycle de vie d'un message</h2>107    <div className="panel"><pre style={{ margin: 0 }}>{`held ─(approbation)→ queued → dispatched → accepted → submitting → submitted → delivered108issues alternatives : failed · expired · cancelled · unknown`}</pre>109      <p className="muted" style={{ marginBottom: 0 }}><code>submitted</code> = accepté par le modem du téléphone ; <code>delivered</code> = rapport de livraison de l'opérateur (pas toujours disponible). <code>unknown</code> = interruption pendant la remise au modem : le message n'est <strong>jamais</strong> renvoyé automatiquement. Utilisez toujours <code>Idempotency-Key</code> pour vos réessais.</p></div>110    <h2>SDK</h2>111    <div className="cols"><div className="panel"><strong>Python</strong><pre>{PY}</pre></div><div className="panel"><strong>TypeScript</strong><pre>{TS}</pre><strong>Swift</strong><pre>{SW}</pre></div></div>112    <h2>CLI</h2>113    <div className="panel"><pre style={{ margin: 0 }}>{`maclustr-sms status114maclustr-sms devices list        maclustr-sms sims list115maclustr-sms send --to "+14185550123" --text "Bonjour depuis MacLustr"116maclustr-sms inbox               maclustr-sms queue117maclustr-sms doctor              # ajouter --json pour une sortie exploitable par un agent`}</pre></div>118    <p className="faint">Guides complets dans le dépôt : <code>docs/API_REFERENCE.md</code>, <code>docs/WEBHOOKS.md</code>, <code>docs/SDK_GUIDE.md</code>, <code>docs/SECURITY.md</code>.</p>119  </Page>120}121
Files main
Menu

Theme