dev.html 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>room_cal dev</title>
  5. <style>
  6. body { font-family: monospace; font-size: 13px; max-width: 860px; margin: 20px auto; padding: 0 16px; }
  7. h1 { font-size: 1.1em; margin-bottom: 16px; }
  8. h2 { font-size: 1em; border-bottom: 1px solid #bbb; padding-bottom: 2px; margin: 20px 0 8px; }
  9. .row { margin: 4px 0; display: flex; align-items: center; gap: 6px; }
  10. label.lbl { width: 110px; flex-shrink: 0; color: #555; }
  11. input[type=text], input[type=number], input[type=date], select {
  12. font-family: monospace; font-size: 12px; padding: 2px 4px; border: 1px solid #bbb;
  13. }
  14. input[type=date] { width: 130px; }
  15. input[type=number] { width: 90px; }
  16. input[type=text] { width: 160px; }
  17. select { padding: 2px; }
  18. button {
  19. font-family: monospace; font-size: 12px; cursor: pointer;
  20. padding: 2px 8px; border: 1px solid #888; background: #f0f0f0;
  21. }
  22. button:hover { background: #e0e0e0; }
  23. button.del { border-color: #c00; color: #c00; }
  24. button.del:hover { background: #fee; }
  25. .result {
  26. background: #f7f7f7; border: 1px solid #ddd; padding: 6px 8px;
  27. margin-top: 6px; white-space: pre-wrap; font-size: 12px;
  28. max-height: 280px; overflow: auto; display: none;
  29. }
  30. .result.show { display: block; }
  31. .result.err { border-color: #c00; background: #fff0f0; color: #900; }
  32. .cb-group { display: flex; gap: 12px; flex-wrap: wrap; }
  33. .cb-group label { width: auto; display: flex; align-items: center; gap: 3px; cursor: pointer; }
  34. .dash { color: #888; }
  35. #base-url { width: 240px; }
  36. .section-note { color: #888; font-size: 11px; margin-left: 4px; }
  37. </style>
  38. </head>
  39. <body>
  40. <h1>room_cal API dev</h1>
  41. <div class="row">
  42. <label class="lbl">base URL</label>
  43. <input id="base-url" type="text">
  44. </div>
  45. <!-- ── SYSTEM ───────────────────────────────────── -->
  46. <h2>System</h2>
  47. <div class="row">
  48. <button onclick="doReload()">POST /reload</button>
  49. <span class="section-note">flush in-memory CalDAV event caches</span>
  50. </div>
  51. <div class="result" id="res-reload"></div>
  52. <!-- ── HEALTH ───────────────────────────────────── -->
  53. <h2>Health</h2>
  54. <div class="row">
  55. <button onclick="doHealth()">GET /health</button>
  56. <span class="section-note">CalDAV connection (Docker probe, unauthenticated)</span>
  57. </div>
  58. <div class="result" id="res-health"></div>
  59. <div class="row" style="margin-top:4px">
  60. <button onclick="doStatus()">GET /status</button>
  61. <span class="section-note">full status including credential probes (authenticated)</span>
  62. </div>
  63. <div class="result" id="res-status"></div>
  64. <!-- ── SERVICES ───────────────────────────────────── -->
  65. <h2>Services</h2>
  66. <div class="row">
  67. <button onclick="doServices()">GET /services</button>
  68. </div>
  69. <div class="result" id="res-services"></div>
  70. <!-- ── CALC ──────────────────────────────────────── -->
  71. <h2>Calc</h2>
  72. <div class="row">
  73. <label class="lbl">transform</label>
  74. <select id="calc-transform">
  75. <option>net_to_list</option><option>list_to_net</option>
  76. <option>list_to_retail</option><option>retail_to_list</option>
  77. <option>net_to_retail</option><option>retail_to_net</option>
  78. </select>
  79. </div>
  80. <div class="row">
  81. <label class="lbl">service</label>
  82. <select id="calc-service"></select>
  83. </div>
  84. <div class="row">
  85. <label class="lbl">amount</label>
  86. <input id="calc-amount" type="number" value="100">
  87. <button onclick="doCalc()">GET</button>
  88. </div>
  89. <div class="result" id="res-calc"></div>
  90. <!-- ── PRICES ─────────────────────────────────────── -->
  91. <h2>Prices</h2>
  92. <div class="row">
  93. <label class="lbl">date</label>
  94. <input id="price-d1" type="date">
  95. <span class="dash">–</span>
  96. <input id="price-d2" type="date" title="end date for range (leave blank for single day)">
  97. <button onclick="doGetPrice()">GET</button>
  98. <button onclick="doPostPrice()">POST</button>
  99. <span class="section-note">POST uses start date only</span>
  100. </div>
  101. <div class="row">
  102. <label class="lbl">net value</label>
  103. <input id="price-value" type="number" step="0.01" placeholder="e.g. 120">
  104. </div>
  105. <div class="result" id="res-prices"></div>
  106. <!-- ── RESERVATIONS ───────────────────────────────── -->
  107. <h2>Reservations <span class="section-note">(read-only)</span></h2>
  108. <div class="row">
  109. <label class="lbl">date</label>
  110. <input id="rsv-d1" type="date">
  111. <span class="dash">–</span>
  112. <input id="rsv-d2" type="date" title="end date for range">
  113. <button onclick="doGetReservation()">GET</button>
  114. </div>
  115. <div class="result" id="res-reservations"></div>
  116. <!-- ── CLOSED ─────────────────────────────────────── -->
  117. <h2>Closed</h2>
  118. <div class="row">
  119. <label class="lbl">date</label>
  120. <input id="cls-d1" type="date">
  121. <span class="dash">–</span>
  122. <input id="cls-d2" type="date" title="end date for range">
  123. <button onclick="doGetClosed()">GET</button>
  124. <button onclick="doPostClosed()">POST</button>
  125. <button class="del" onclick="doDeleteClosed()">DELETE</button>
  126. <span class="section-note">POST/DELETE use start date only</span>
  127. </div>
  128. <div class="row">
  129. <label class="lbl">services</label>
  130. <div class="cb-group" id="closed-checks"></div>
  131. </div>
  132. <div class="result" id="res-closed"></div>
  133. <!-- ── DISCOUNTS ──────────────────────────────────── -->
  134. <h2>Discounts</h2>
  135. <div class="row">
  136. <label class="lbl">date</label>
  137. <input id="disc-d1" type="date">
  138. <span class="dash">–</span>
  139. <input id="disc-d2" type="date" title="end date for range">
  140. <button onclick="doGetDiscount()">GET</button>
  141. <button onclick="doPostDiscount()">POST</button>
  142. <button class="del" onclick="doDeleteDiscount()">DELETE</button>
  143. <span class="section-note">POST/DELETE use start date only</span>
  144. </div>
  145. <div class="row">
  146. <label class="lbl">type</label>
  147. <select id="disc-type"><option value="percent">percent</option><option value="flat">flat</option></select>
  148. <label class="lbl" style="width:auto;margin-left:8px">value</label>
  149. <input id="disc-value" type="number" step="0.01" placeholder="e.g. 10">
  150. </div>
  151. <div class="result" id="res-discounts"></div>
  152. <!-- ── WORKFLOWS ───────────────────────────────────── -->
  153. <h2>Workflows <span class="section-note">(awaits local write, backgrounds push)</span></h2>
  154. <div class="row">
  155. <label class="lbl">date</label>
  156. <input id="wf-d1" type="date">
  157. <span class="dash">–</span>
  158. <input id="wf-d2" type="date" title="end date for range workflows">
  159. </div>
  160. <div class="row">
  161. <label class="lbl">price</label>
  162. <input id="wf-price-value" type="number" step="0.01" placeholder="net value">
  163. <button onclick="doWfSetPrice()">POST /price</button>
  164. </div>
  165. <div class="row">
  166. <label class="lbl">discount</label>
  167. <select id="wf-disc-type"><option value="percent">percent</option><option value="flat">flat</option></select>
  168. <input id="wf-disc-value" type="number" step="0.01" placeholder="value" style="margin-left:4px">
  169. <button onclick="doWfSetDiscount()">POST /discount</button>
  170. <button class="del" onclick="doWfDeleteDiscount()">DELETE /discount</button>
  171. </div>
  172. <div class="row">
  173. <label class="lbl">closed</label>
  174. <div class="cb-group" id="wf-closed-checks"></div>
  175. <button onclick="doWfSetClosed()">POST /closed</button>
  176. <button class="del" onclick="doWfDeleteClosed()">DELETE /closed</button>
  177. </div>
  178. <div class="row">
  179. <label class="lbl">sync range</label>
  180. <button onclick="doWfReservations()">POST /reservations</button>
  181. <button onclick="doWfIcalFeeds()">POST /ical-feeds</button>
  182. <button onclick="doWfUserCal()">POST /user-cal</button>
  183. <span class="section-note">uses date range above</span>
  184. </div>
  185. <div class="result" id="res-workflows"></div>
  186. <!-- ── ACTIONS ────────────────────────────────────── -->
  187. <h2>Actions</h2>
  188. <div class="row">
  189. <label class="lbl">action</label>
  190. <select id="action-name" onchange="renderActionKwargs()">
  191. <option>fetch-reservations</option><option>fetch-closed</option>
  192. <option>fetch-user-cal</option><option>push-closed</option>
  193. <option>fetch-feed</option><option>fetch-prices</option>
  194. <option>push-prices</option><option>fill-prices</option>
  195. <option>apply-discounts</option><option>apply-rules</option>
  196. <option>local-refresh</option><option>diff</option>
  197. </select>
  198. </div>
  199. <div class="row">
  200. <label class="lbl">start date</label>
  201. <input id="action-d1" type="date">
  202. <span class="dash">–</span>
  203. <input id="action-d2" type="date" title="end date (optional)">
  204. </div>
  205. <div id="action-kwargs"></div>
  206. <div class="row">
  207. <button onclick="doAction()">POST</button>
  208. </div>
  209. <div class="result" id="res-actions"></div>
  210. <!-- ── CHAT ──────────────────────────────────────── -->
  211. <h2>Chat <span class="section-note">(service-specific messaging)</span></h2>
  212. <div class="row">
  213. <label class="lbl">service</label>
  214. <select id="chat-service"></select>
  215. </div>
  216. <div class="row">
  217. <label class="lbl">chat_id</label>
  218. <input id="chat-id" type="text" placeholder="thread / reservation id">
  219. <button onclick="doChatGet()">GET thread</button>
  220. </div>
  221. <div class="row">
  222. <label class="lbl">message</label>
  223. <input id="chat-body" type="text" placeholder="message text" style="width:260px">
  224. <button onclick="doChatPost()">POST send</button>
  225. </div>
  226. <div class="result" id="res-chat"></div>
  227. <!-- ── SMS ──────────────────────────────────────── -->
  228. <h2>SMS Challenge</h2>
  229. <div class="row">
  230. <label class="lbl">code</label>
  231. <input id="sms-code" type="text" placeholder="e.g. 123456" style="width:120px">
  232. <button onclick="doSmsPost()">POST /sms/code</button>
  233. <span class="section-note">deliver a code to whoever is polling</span>
  234. </div>
  235. <div class="row">
  236. <label class="lbl">timeout (s)</label>
  237. <input id="sms-timeout" type="number" value="30" style="width:60px">
  238. <button onclick="doSmsPoll()">GET /sms/code</button>
  239. <span class="section-note">long-poll — waits for a code to arrive</span>
  240. </div>
  241. <div class="result" id="res-sms"></div>
  242. <!-- ── CREDENTIALS ────────────────────────────────── -->
  243. <h2>Credentials</h2>
  244. <div class="row">
  245. <button onclick="doCredProbeAll()">GET /credentials</button>
  246. <span class="section-note">live session probe for all services</span>
  247. </div>
  248. <div class="result" id="res-cred-probe-all"></div>
  249. <div class="row" style="margin-top:8px">
  250. <label class="lbl">service</label>
  251. <select id="cred-service"></select>
  252. <button onclick="doCredProbe()">GET</button>
  253. <span class="section-note">probe single service</span>
  254. </div>
  255. <div class="result" id="res-cred-probe"></div>
  256. <div id="cred-fields" style="margin-top:8px">
  257. <div class="row cred-row">
  258. <label class="lbl" style="width:60px">key</label>
  259. <input class="cred-key" type="text" placeholder="e.g. token">
  260. <label class="lbl" style="width:40px">val</label>
  261. <input class="cred-val" type="text" placeholder="value" style="width:220px">
  262. <button onclick="addCredRow(this)">+</button>
  263. </div>
  264. </div>
  265. <div class="row" style="margin-top:6px">
  266. <button onclick="doCredPut()">PUT</button>
  267. </div>
  268. <div class="result" id="res-credentials"></div>
  269. <script>
  270. const API_BASE = '';
  271. document.getElementById('base-url').value = API_BASE;
  272. const ACTION_KWARGS = {
  273. 'fetch-feed': [['feed_name','text','feed name'],['title','text','event title (optional)']],
  274. 'fetch-prices': [['service','text','service key (optional)']],
  275. 'fill-prices': [['weekday','number','weekday net price'],['weekend','number','weekend net price']],
  276. 'apply-rules': [['pipeline_name','text','pipeline name']],
  277. };
  278. let servicesList = [];
  279. function base() {
  280. return document.getElementById('base-url').value.replace(/\/+$/, '');
  281. }
  282. async function api(method, path, body) {
  283. const opts = { method, headers: {} };
  284. if (body !== undefined) {
  285. opts.headers['Content-Type'] = 'application/json';
  286. opts.body = JSON.stringify(body);
  287. }
  288. try {
  289. const r = await fetch(base() + path, opts);
  290. if (r.status === 204) return { ok: true, status: 204, data: '204 No Content' };
  291. const text = await r.text();
  292. let data;
  293. try { data = JSON.parse(text); } catch { data = text; }
  294. return { ok: r.ok, status: r.status, data };
  295. } catch (e) {
  296. return { ok: false, status: 0, data: String(e) };
  297. }
  298. }
  299. function pending(id) {
  300. const el = document.getElementById(id);
  301. el.className = 'result show';
  302. el.textContent = '⋯';
  303. }
  304. function show(id, result) {
  305. const el = document.getElementById(id);
  306. el.className = 'result show' + (result.ok ? '' : ' err');
  307. const d = result.data;
  308. const body = typeof d === 'string' ? d : JSON.stringify(d, null, 2);
  309. el.textContent = result.ok ? body : `HTTP ${result.status}: ${body}`;
  310. }
  311. function dateArg(d1id, d2id) {
  312. const s = document.getElementById(d1id).value;
  313. const e = document.getElementById(d2id).value;
  314. if (!s) return null;
  315. return (e && e !== s) ? `${s}/${e}` : s;
  316. }
  317. // ── reload ──
  318. async function doReload() {
  319. pending('res-reload');
  320. show('res-reload', await api('POST', '/reload'));
  321. }
  322. // ── health ──
  323. async function doHealth() {
  324. pending('res-health');
  325. show('res-health', await api('GET', '/health'));
  326. }
  327. async function doStatus() {
  328. pending('res-status');
  329. show('res-status', await api('GET', '/status'));
  330. }
  331. // ── services ──
  332. async function doServices() {
  333. pending('res-services');
  334. const r = await api('GET', '/services');
  335. show('res-services', r);
  336. if (r.ok && Array.isArray(r.data)) {
  337. servicesList = r.data;
  338. populateDropdowns();
  339. renderClosedChecks();
  340. }
  341. }
  342. function populateDropdowns() {
  343. ['calc-service', 'cred-service', 'chat-service'].forEach(id => {
  344. const el = document.getElementById(id);
  345. const prev = el.value;
  346. el.innerHTML = servicesList.map(s =>
  347. `<option value="${s.key}">${s.key} — ${s.name}</option>`
  348. ).join('');
  349. if (prev) el.value = prev;
  350. });
  351. }
  352. function renderClosedChecks(checked = []) {
  353. ['closed-checks', 'wf-closed-checks'].forEach(groupId => {
  354. const el = document.getElementById(groupId);
  355. if (!el) return;
  356. el.innerHTML = servicesList.map(s =>
  357. `<label><input type="checkbox" value="${s.key}" id="${groupId}-${s.key}"${checked.includes(s.key) ? ' checked' : ''}> ${s.name}</label>`
  358. ).join('');
  359. });
  360. }
  361. function getCheckedServices() {
  362. return Array.from(document.querySelectorAll('#closed-checks input:checked')).map(c => c.value);
  363. }
  364. function getWfCheckedServices() {
  365. return Array.from(document.querySelectorAll('#wf-closed-checks input:checked')).map(c => c.value);
  366. }
  367. // ── calc ──
  368. async function doCalc() {
  369. const t = document.getElementById('calc-transform').value;
  370. const s = document.getElementById('calc-service').value;
  371. const a = document.getElementById('calc-amount').value;
  372. if (!s || !a) return;
  373. pending('res-calc');
  374. show('res-calc', await api('GET', `/calc/${t}?service=${encodeURIComponent(s)}&amount=${a}`));
  375. }
  376. // ── prices ──
  377. async function doGetPrice() {
  378. const d1 = document.getElementById('price-d1').value;
  379. const d2 = document.getElementById('price-d2').value || d1;
  380. if (!d1) return;
  381. pending('res-prices');
  382. const r = await api('GET', `/price/${d1}/${d2}`);
  383. show('res-prices', r);
  384. if (r.ok && r.data && r.data[d1] && r.data[d1].net !== undefined) {
  385. document.getElementById('price-value').value = r.data[d1].net;
  386. }
  387. }
  388. async function doPostPrice() {
  389. const d = document.getElementById('price-d1').value;
  390. if (!d) return;
  391. const v = document.getElementById('price-value').value;
  392. if (!v) return;
  393. pending('res-prices');
  394. show('res-prices', await api('POST', `/price/${d}`, { value: parseFloat(v) }));
  395. }
  396. // ── reservations ──
  397. async function doGetReservation() {
  398. const range = dateArg('rsv-d1', 'rsv-d2');
  399. if (!range) return;
  400. pending('res-reservations');
  401. show('res-reservations', await api('GET', `/reservation/${range}`));
  402. }
  403. // ── closed ──
  404. async function doGetClosed() {
  405. const range = dateArg('cls-d1', 'cls-d2');
  406. if (!range) return;
  407. pending('res-closed');
  408. const r = await api('GET', `/closed/${range}`);
  409. show('res-closed', r);
  410. if (r.ok && Array.isArray(r.data)) {
  411. renderClosedChecks(r.data);
  412. }
  413. }
  414. async function doPostClosed() {
  415. const d = document.getElementById('cls-d1').value;
  416. if (!d) return;
  417. pending('res-closed');
  418. show('res-closed', await api('POST', `/closed/${d}`, { services: getCheckedServices() }));
  419. }
  420. async function doDeleteClosed() {
  421. const d = document.getElementById('cls-d1').value;
  422. if (!d) return;
  423. pending('res-closed');
  424. show('res-closed', await api('DELETE', `/closed/${d}`));
  425. }
  426. // ── discounts ──
  427. async function doGetDiscount() {
  428. const range = dateArg('disc-d1', 'disc-d2');
  429. if (!range) return;
  430. pending('res-discounts');
  431. const r = await api('GET', `/discount/${range}`);
  432. show('res-discounts', r);
  433. if (r.ok && r.data && r.data.type) {
  434. document.getElementById('disc-type').value = r.data.type;
  435. document.getElementById('disc-value').value = r.data.value ?? '';
  436. }
  437. }
  438. async function doPostDiscount() {
  439. const d = document.getElementById('disc-d1').value;
  440. if (!d) return;
  441. const type = document.getElementById('disc-type').value;
  442. const value = document.getElementById('disc-value').value;
  443. if (!value) return;
  444. pending('res-discounts');
  445. show('res-discounts', await api('POST', `/discount/${d}`, { type, value: parseFloat(value) }));
  446. }
  447. async function doDeleteDiscount() {
  448. const d = document.getElementById('disc-d1').value;
  449. if (!d) return;
  450. pending('res-discounts');
  451. show('res-discounts', await api('DELETE', `/discount/${d}`));
  452. }
  453. // ── workflows ──
  454. async function doWfSetPrice() {
  455. const d = document.getElementById('wf-d1').value;
  456. if (!d) return;
  457. const v = document.getElementById('wf-price-value').value;
  458. if (!v) return;
  459. pending('res-workflows');
  460. show('res-workflows', await api('POST', `/workflow/price/${d}`, { value: parseFloat(v) }));
  461. }
  462. async function doWfSetDiscount() {
  463. const d = document.getElementById('wf-d1').value;
  464. if (!d) return;
  465. const type = document.getElementById('wf-disc-type').value;
  466. const value = document.getElementById('wf-disc-value').value;
  467. if (!value) return;
  468. pending('res-workflows');
  469. show('res-workflows', await api('POST', `/workflow/discount/${d}`, { type, value: parseFloat(value) }));
  470. }
  471. async function doWfDeleteDiscount() {
  472. const d = document.getElementById('wf-d1').value;
  473. if (!d) return;
  474. pending('res-workflows');
  475. show('res-workflows', await api('DELETE', `/workflow/discount/${d}`));
  476. }
  477. async function doWfSetClosed() {
  478. const d = document.getElementById('wf-d1').value;
  479. if (!d) return;
  480. pending('res-workflows');
  481. show('res-workflows', await api('POST', `/workflow/closed/${d}`, { services: getWfCheckedServices() }));
  482. }
  483. async function doWfDeleteClosed() {
  484. const d = document.getElementById('wf-d1').value;
  485. if (!d) return;
  486. pending('res-workflows');
  487. show('res-workflows', await api('DELETE', `/workflow/closed/${d}`));
  488. }
  489. function wfRange() {
  490. const d1 = document.getElementById('wf-d1').value;
  491. const d2 = document.getElementById('wf-d2').value || d1;
  492. return d1 ? { d1, d2 } : null;
  493. }
  494. async function doWfReservations() {
  495. const r = wfRange();
  496. if (!r) return;
  497. pending('res-workflows');
  498. show('res-workflows', await api('POST', `/workflow/reservations/${r.d1}/${r.d2}`));
  499. }
  500. async function doWfIcalFeeds() {
  501. const r = wfRange();
  502. if (!r) return;
  503. pending('res-workflows');
  504. show('res-workflows', await api('POST', `/workflow/ical-feeds/${r.d1}/${r.d2}`));
  505. }
  506. async function doWfUserCal() {
  507. const r = wfRange();
  508. if (!r) return;
  509. pending('res-workflows');
  510. show('res-workflows', await api('POST', `/workflow/user-cal/${r.d1}/${r.d2}`));
  511. }
  512. // ── actions ──
  513. function renderActionKwargs() {
  514. const action = document.getElementById('action-name').value;
  515. const kwargs = ACTION_KWARGS[action] || [];
  516. document.getElementById('action-kwargs').innerHTML = kwargs.map(([key, type, ph]) =>
  517. `<div class="row"><label class="lbl">${key}</label><input id="akw-${key}" type="${type}" placeholder="${ph}" style="width:200px"></div>`
  518. ).join('');
  519. }
  520. async function doAction() {
  521. const action = document.getElementById('action-name').value;
  522. const range = dateArg('action-d1', 'action-d2');
  523. if (!range) return;
  524. const kwargs = {};
  525. (ACTION_KWARGS[action] || []).forEach(([key]) => {
  526. const el = document.getElementById(`akw-${key}`);
  527. if (el && el.value) kwargs[key] = el.value;
  528. });
  529. pending('res-actions');
  530. show('res-actions', await api('POST', `/action/${action}/${range}`, kwargs));
  531. }
  532. // ── chat ──
  533. async function doChatGet() {
  534. const service = document.getElementById('chat-service').value;
  535. const chatId = document.getElementById('chat-id').value.trim();
  536. if (!service || !chatId) return;
  537. pending('res-chat');
  538. show('res-chat', await api('GET', `/chat/${service}/${chatId}`));
  539. }
  540. async function doChatPost() {
  541. const service = document.getElementById('chat-service').value;
  542. const chatId = document.getElementById('chat-id').value.trim();
  543. const body = document.getElementById('chat-body').value.trim();
  544. if (!service || !chatId || !body) return;
  545. pending('res-chat');
  546. show('res-chat', await api('POST', `/chat/${service}/${chatId}`, { body }));
  547. }
  548. // ── sms ──
  549. async function doSmsPost() {
  550. const code = document.getElementById('sms-code').value.trim();
  551. if (!code) return;
  552. pending('res-sms');
  553. show('res-sms', await api('POST', '/sms/code', { code }));
  554. }
  555. async function doSmsPoll() {
  556. const timeout = document.getElementById('sms-timeout').value || 30;
  557. pending('res-sms');
  558. show('res-sms', await api('GET', `/sms/code?timeout=${timeout}`));
  559. }
  560. // ── credentials ──
  561. async function doCredProbeAll() {
  562. pending('res-cred-probe-all');
  563. show('res-cred-probe-all', await api('GET', '/credentials'));
  564. }
  565. async function doCredProbe() {
  566. const service = document.getElementById('cred-service').value;
  567. if (!service) return;
  568. pending('res-cred-probe');
  569. show('res-cred-probe', await api('GET', `/credentials/${service}`));
  570. }
  571. function addCredRow(btn) {
  572. const row = document.createElement('div');
  573. row.className = 'row cred-row';
  574. row.innerHTML = `<label class="lbl" style="width:60px">key</label><input class="cred-key" type="text" placeholder="key"><label class="lbl" style="width:40px">val</label><input class="cred-val" type="text" placeholder="value" style="width:220px"><button onclick="this.parentElement.remove()">−</button>`;
  575. btn.closest('#cred-fields').appendChild(row);
  576. }
  577. async function doCredPut() {
  578. const service = document.getElementById('cred-service').value;
  579. if (!service) return;
  580. const creds = {};
  581. document.querySelectorAll('.cred-row').forEach(row => {
  582. const k = row.querySelector('.cred-key').value.trim();
  583. const v = row.querySelector('.cred-val').value;
  584. if (k) creds[k] = v;
  585. });
  586. pending('res-credentials');
  587. show('res-credentials', await api('PUT', `/credentials/${service}`, creds));
  588. }
  589. // ── init ──
  590. const today = new Date().toISOString().slice(0, 10);
  591. ['price-d1','rsv-d1','cls-d1','disc-d1','wf-d1','action-d1'].forEach(id => {
  592. document.getElementById(id).value = today;
  593. });
  594. const nextMonth = new Date(); nextMonth.setDate(nextMonth.getDate() + 30);
  595. document.getElementById('wf-d2').value = nextMonth.toISOString().slice(0, 10);
  596. renderActionKwargs();
  597. doServices();
  598. </script>
  599. </body>
  600. </html>