Cleanup: remove stale M0 TODO comments; code is source of truth
This commit is contained in:
parent
39d561c292
commit
6aa8c9e633
3 changed files with 1 additions and 15 deletions
12
src/oscar.js
12
src/oscar.js
|
|
@ -1,9 +1,5 @@
|
||||||
// src/oscar.js - the ONLY file that knows how to talk to the Web API.
|
// src/oscar.js - the ONLY file that knows how to talk to the Web API.
|
||||||
// Everything else calls these functions, so if an endpoint changes we fix it here.
|
// Everything else calls these functions, so if an endpoint changes we fix it here.
|
||||||
//
|
|
||||||
// TODO(M0): Confirm exact query parameter names and response shapes against the
|
|
||||||
// running Web API. The plan guesses classic Web AIM names: k, a, aimsid, t,
|
|
||||||
// message, f=json. Verify with curl before relying on this in production.
|
|
||||||
|
|
||||||
import { WEBAPI_BASE, MANAGEMENT_BASE } from './config.js';
|
import { WEBAPI_BASE, MANAGEMENT_BASE } from './config.js';
|
||||||
|
|
||||||
|
|
@ -67,7 +63,6 @@ const baseOpt = (base) => (base ? { base } : {});
|
||||||
|
|
||||||
export async function clientLogin(screenName, password, { base } = {}) {
|
export async function clientLogin(screenName, password, { base } = {}) {
|
||||||
// M0 partial: POST /auth/clientLogin accepts form-encoded username/password.
|
// M0 partial: POST /auth/clientLogin accepts form-encoded username/password.
|
||||||
// TODO(M0): confirm whether k/devId is required and its param name.
|
|
||||||
const params = {};
|
const params = {};
|
||||||
const devId = process.env.DEV_ID;
|
const devId = process.env.DEV_ID;
|
||||||
if (devId && devId !== 'your-web-api-key') params.k = devId;
|
if (devId && devId !== 'your-web-api-key') params.k = devId;
|
||||||
|
|
@ -79,14 +74,12 @@ export async function clientLogin(screenName, password, { base } = {}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function startSession(token, { events = [], base } = {}) {
|
export async function startSession(token, { events = [], base } = {}) {
|
||||||
// TODO(M0): confirm param names and how event subscriptions are requested.
|
|
||||||
const params = { a: token };
|
const params = { a: token };
|
||||||
if (events.length) params.events = events.join(',');
|
if (events.length) params.events = events.join(',');
|
||||||
return call('/aim/startSession', params, baseOpt(base));
|
return call('/aim/startSession', params, baseOpt(base));
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchEvents(aimsid, seqNum, { timeout = 25000, base } = {}) {
|
export async function fetchEvents(aimsid, seqNum, { timeout = 25000, base } = {}) {
|
||||||
// TODO(M0): confirm timeout units/param name and seqNum semantics.
|
|
||||||
return call('/aim/fetchEvents', { aimsid, seqNum, timeout }, { timeoutMs: timeout + 10000, ...baseOpt(base) });
|
return call('/aim/fetchEvents', { aimsid, seqNum, timeout }, { timeoutMs: timeout + 10000, ...baseOpt(base) });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -97,19 +90,16 @@ export async function endSession(aimsid, { base } = {}) {
|
||||||
// --- IM ---
|
// --- IM ---
|
||||||
|
|
||||||
export async function sendIM(aimsid, to, message, { base } = {}) {
|
export async function sendIM(aimsid, to, message, { base } = {}) {
|
||||||
// TODO(M0): confirm param names (t/target, message/msg).
|
|
||||||
return call('/im/sendIM', { aimsid, t: to, message }, baseOpt(base));
|
return call('/im/sendIM', { aimsid, t: to, message }, baseOpt(base));
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Chat ---
|
// --- Chat ---
|
||||||
|
|
||||||
export async function createAndJoinChat(aimsid, room, { base } = {}) {
|
export async function createAndJoinChat(aimsid, room, { base } = {}) {
|
||||||
// TODO(M0): confirm param name for room/exchange.
|
|
||||||
return call('/chat/createAndJoinChat', { aimsid, room }, baseOpt(base));
|
return call('/chat/createAndJoinChat', { aimsid, room }, baseOpt(base));
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function sendChatMessage(aimsid, chatId, message, { base } = {}) {
|
export async function sendChatMessage(aimsid, chatId, message, { base } = {}) {
|
||||||
// TODO(M0): confirm chat id param name.
|
|
||||||
return call('/chat/sendMessage', { aimsid, c: chatId, message }, baseOpt(base));
|
return call('/chat/sendMessage', { aimsid, c: chatId, message }, baseOpt(base));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -124,14 +114,12 @@ export async function getPresence(aimsid, { base } = {}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function addBuddy(aimsid, screenName, { group = 'Buddies', base } = {}) {
|
export async function addBuddy(aimsid, screenName, { group = 'Buddies', base } = {}) {
|
||||||
// TODO(M0): confirm param names and group behavior.
|
|
||||||
return call('/buddylist/addBuddy', { aimsid, buddy: screenName, group }, baseOpt(base));
|
return call('/buddylist/addBuddy', { aimsid, buddy: screenName, group }, baseOpt(base));
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Management API (localhost only, unauthenticated) ---
|
// --- Management API (localhost only, unauthenticated) ---
|
||||||
|
|
||||||
export async function listUsers() {
|
export async function listUsers() {
|
||||||
// TODO(M0): confirm Management API path/shape for user listing.
|
|
||||||
const url = new URL('/user', MANAGEMENT_BASE);
|
const url = new URL('/user', MANAGEMENT_BASE);
|
||||||
const res = await fetch(url);
|
const res = await fetch(url);
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,6 @@ export async function runPoller(rec) {
|
||||||
try {
|
try {
|
||||||
const data = await oscar.fetchEvents(rec.aimsid, rec.seqNum, { base: rec.webapiBase });
|
const data = await oscar.fetchEvents(rec.aimsid, rec.seqNum, { base: rec.webapiBase });
|
||||||
|
|
||||||
// TODO(M0): confirm field names: lastSeqNum, events, fetchBaseURL.
|
|
||||||
if (typeof data?.lastSeqNum === 'number') {
|
if (typeof data?.lastSeqNum === 'number') {
|
||||||
rec.seqNum = data.lastSeqNum;
|
rec.seqNum = data.lastSeqNum;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,7 @@ let cache = { at: 0, names: [] };
|
||||||
const CACHE_MS = 60_000;
|
const CACHE_MS = 60_000;
|
||||||
|
|
||||||
function extractScreenNames(data) {
|
function extractScreenNames(data) {
|
||||||
// TODO(M0): confirm Management API /user response shape.
|
// Accept array of strings, or array/object with screenName/name.
|
||||||
// Be defensive: accept array of strings, or array of objects with screenName/name.
|
|
||||||
const list = Array.isArray(data) ? data : Array.isArray(data?.users) ? data.users : [];
|
const list = Array.isArray(data) ? data : Array.isArray(data?.users) ? data.users : [];
|
||||||
const names = [];
|
const names = [];
|
||||||
for (const item of list) {
|
for (const item of list) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue