Files
wekan/models/lib/apiImportServices.js
T
Lauri Ojansivu 01e88410cd Import and export Azure DevOps Boards, Microsoft Lists, Project, Outlook, Teams and OneNote.
Azure DevOps Boards: a query's "Export to CSV" is imported (Board Column or
State as lists, Board Lane as swimlanes, Title 1/2/3 tree levels as parent
cards, "Name <address>" people, regional dates, other columns as custom
fields), and a board exports as the CSV "Import from CSV" reads.

Microsoft Lists: a list's "Export to CSV" is imported (Status or Progress as
the lists, people, dates, tags, other columns as custom fields), and a board
exports as a CSV that "New list - From CSV" makes a list of.

Microsoft Project: the "XML Format" (MSPDI) plan is imported (summary tasks
as swimlanes, progress as lists, subtasks, resources, predecessors), read by
a small XML reader that never resolves a DTD or an entity, and a board
exports as a plan Project opens.

Outlook: .msg files are read without a library - the Compound File Binary
format (MS-CFB) and the message's properties (MS-OXMSG) - into the mail
import, threads and attachments included, alone or in a .zip with .eml
files; a board exports as .eml files Outlook opens. The reader was checked
against .msg files saved by Outlook.

Teams and OneNote: fetched from Microsoft Graph with the member's token
(chats and channels; notebooks with their pages' HTML, to-do boxes as a
checklist), or read from a file - Teams' personal export .tar, Graph chat
messages, and the files WeKan exports: Teams chats as Graph chat messages,
OneNote pages as Graph's create-page XHTML in a .zip.

All six are under the Microsoft heading of Import and Export, with tests,
negative tests, live tests for the two Graph imports, documentation and the
import instruction in every language. Low confidence translations include
ace, ak, ay, bm, bo, bua, chr, csb, cv, dz, ee, ff, fj, gn, gv, haw, ig, iu,
kl, ks, kok, kw, ht, hsb, fur, fo, ga, gd, ku, lld, nah, nap, rup, sah, sc,
scn, se, nd, nso, ss, om, rn, rw, sm, sn, qu, pap, lg, mg, mi, ny, so, mai,
sd, ps, or_IN, my, si, rm, la, lb, tig, tlh, uz-AR, ve, ve-PP, ve-CC, vo, wa,
wal, wo, zgh, to, tpi, wa-RR and ts.

Thanks to xet7 !
2026-11-21 01:33:59 +02:00

86 lines
4.3 KiB
JavaScript

'use strict';
// Import from a service's API (decided 2026-10-14): Planka, Microsoft To Do,
// Microsoft OneNote and Teams (2026-11-21), KanbanFlow, Basecamp, Google Tasks
// and Google Keep. The member types what the service needs; server/apiImport.js lists what can be imported and
// fetches the chosen one with those credentials - used for that request and
// never stored - and the import page then imports the fetched JSON like a
// pasted export, through the service's parser (models/lib/<key>ApiFormat.js)
// and the generalized importer, members step and all.
//
// Each service's client is models/lib/apiImport/<key>.js, plain Node:
// list(credentials, request) -> [{ id, name }] what can be imported
// fetch(credentials, id, request) -> the JSON its parser reads
// `request(url, { method, headers, body })` resolves to the parsed JSON body
// and rejects with an Error carrying `.status` on a non-2xx answer; the
// server passes one that goes through the SSRF guard
// (server/lib/apiImportRequest.js), tests a fake, and the live tests
// (releases/live-tests/<key>-import.mjs) plain fetch.
//
// fields: what the import page asks for, in order. `secret` fields are
// password inputs, cleared once sent. `url` is the service's address for a
// self-hosted one; a hosted service's address is fixed in its client.
const API_IMPORT_SERVICES = [
{ key: 'planka', name: 'Planka', fields: [
{ name: 'url', label: 'api-import-url', required: true },
{ name: 'username', label: 'api-import-username', required: true },
{ name: 'password', label: 'api-import-password', secret: true, required: true },
] },
{ key: 'mstodo', name: 'Microsoft To Do', fields: [
{ name: 'token', label: 'api-import-token', secret: true, required: true },
] },
{ key: 'onenote', name: 'Microsoft OneNote', fields: [
{ name: 'token', label: 'api-import-token', secret: true, required: true },
] },
{ key: 'teams', name: 'Microsoft Teams', fields: [
{ name: 'token', label: 'api-import-token', secret: true, required: true },
] },
{ key: 'kanbanflow', name: 'KanbanFlow', fields: [
{ name: 'token', label: 'api-import-token', secret: true, required: true },
] },
{ key: 'basecamp', name: 'Basecamp', fields: [
{ name: 'account', label: 'api-import-account', required: true },
{ name: 'token', label: 'api-import-token', secret: true, required: true },
] },
{ key: 'googletasks', name: 'Google Tasks', fields: [
{ name: 'token', label: 'api-import-token', secret: true, required: true },
] },
{ key: 'googlekeep', name: 'Google Keep', fields: [
{ name: 'token', label: 'api-import-token', secret: true, required: true },
] },
];
const MAX_FIELD_LENGTH = 4096;
const apiImportService = key => API_IMPORT_SERVICES.find(service => service.key === key) || null;
// The credentials a call may carry: the service's own fields, strings, each
// required one present. Throws on anything else, so a method never forwards
// an unexpected value to a client.
function cleanApiImportCredentials(key, input) {
const service = apiImportService(key);
if (!service) throw new Error('Unknown import service');
if (!input || typeof input !== 'object' || Array.isArray(input)) throw new Error('Credentials are required');
const allowed = new Set(service.fields.map(field => field.name));
for (const name of Object.keys(input)) if (!allowed.has(name)) throw new Error(`Unexpected credential field ${name}`);
const clean = {};
for (const field of service.fields) {
const value = input[field.name];
if (value === undefined || value === null || value === '') {
if (field.required) throw new Error(`${field.name} is required`);
continue;
}
if (typeof value !== 'string' || value.length > MAX_FIELD_LENGTH) throw new Error(`${field.name} is not valid`);
clean[field.name] = field.secret ? value : value.trim();
}
if (clean.url !== undefined) {
let parsed;
try { parsed = new URL(clean.url); } catch (error) { throw new Error('url is not valid'); }
if (!['https:', 'http:'].includes(parsed.protocol) || parsed.username || parsed.password) throw new Error('url is not valid');
clean.url = `${parsed.origin}${parsed.pathname.replace(/\/+$/, '')}`;
}
return clean;
}
module.exports = { API_IMPORT_SERVICES, MAX_FIELD_LENGTH, apiImportService, cleanApiImportCredentials };