Files
wekan/models/lib/importSourceShape.js
T
Lauri Ojansivu dffbafd30f Import and export Rocket.Chat and Fizzy.
Rocket.Chat: "Download my data" as JSON (channels.json and a message file
per room, with its assets), one room's .json, and the .zip Rocket.Chat's
CSV importer reads are imported for Board View / Chat - a room is a card,
its messages the comments. A board exports as that CSV importer .zip:
users.csv, channels.csv and a messages.csv per card.

Fizzy (37signals): its account export (data/<table>/<id>.json and
storage/) and personal data export (<number>.json per card) are imported -
boards become swimlanes, columns lists between Maybe?, Not now and Done,
with tags, assignees, steps, comments, golden and files. A board exports as
the account export Fizzy's account import reads, every row with every
column its import requires, ids as base36 UUIDv7.

Both formats are read and written from their projects' source code, with
tests, documentation and the import instruction in every language. Low
confidence translations include chr, ay, bm, bua, bo, cv, csb, ak, bi, ace,
ba, gn, gv, iu, kl, ig, kok, nah, qu, kw, lld, nap, rm, om, ks, tlh, tig,
rup, sah, se, ss, sm, to, tpi, dz, ee, ff, fj, fo, uz-AR, ve, ve-PP, vo,
wal, wa, wo, zgh, ve-CC, wa-RR, wuu-Hans, yi, xh and yo.

Thanks to xet7 !
2026-11-20 20:29:01 +02:00

66 lines
5.1 KiB
JavaScript

// Shape validation before creating a board. Unknown/empty objects must not
// report a successful import which silently contains no source records.
export function validateImportSourceShape(source, value) {
const arrayAt = (object, key) => object && Array.isArray(object[key]);
let valid = false;
switch (source) {
case 'wekan': case 'trello': valid = arrayAt(value, 'cards') && arrayAt(value, 'lists'); break;
case 'kanboard': valid = arrayAt(value, 'tasks'); break;
case 'jira': valid = arrayAt(value, 'issues'); break;
case 'github': case 'gitlab': case 'gitea': case 'forgejo':
valid = Array.isArray(value) || arrayAt(value, 'issues'); break;
case 'deck': valid = arrayAt(value, 'stacks') || arrayAt(value?.board, 'stacks'); break;
case 'openproject': valid = Array.isArray(value) || arrayAt(value, 'elements') || arrayAt(value?._embedded, 'elements'); break;
case 'asana': valid = Array.isArray(value) || arrayAt(value, 'data'); break;
case 'zenkit': valid = Array.isArray(value) || arrayAt(value, 'items')
|| (arrayAt(value, 'elements') && (arrayAt(value, 'entries') || arrayAt(value, 'listEntries'))); break;
case 'tasksorg': valid = arrayAt(value?.data, 'tasks'); break;
case 'csv': valid = Array.isArray(value) && value.length > 0 && value.every(Array.isArray); break;
case 'taiga': valid = arrayAt(value, 'user_stories'); break;
case 'kanri': valid = arrayAt(value, 'columns') || arrayAt(value, 'boards'); break;
// What server/apiImport.js fetches (models/lib/apiImport/<key>.js).
case 'planka': valid = Boolean(value?.planka?.item) && typeof value.planka.included === 'object'; break;
case 'mstodo': case 'googletasks': valid = arrayAt(value, 'lists'); break;
case 'kanbanflow': valid = Boolean(value?.board) && arrayAt(value, 'tasks'); break;
case 'basecamp': valid = Boolean(value?.project) && (arrayAt(value, 'cardTables') || arrayAt(value, 'todolists')); break;
case 'googlekeep': valid = arrayAt(value, 'notes'); break;
// Vikunja: the export .zip as { zipBase64 }, or the text of its data.json.
// Notion: the Markdown & CSV export .zip as { zipBase64 }, or one database CSV.
case 'notion':
case 'vikunja': valid = (typeof value?.zipBase64 === 'string' && value.zipBase64.length > 0)
|| typeof value?.zipFile === 'string'
|| (typeof value === 'string' && value.trim().length > 0); break;
// Plane: the export .zip as { zipBase64 }, a workbook as { xlsxBase64 },
// or the text of a JSON or CSV export file.
case 'plane': valid = (typeof value?.zipBase64 === 'string' && value.zipBase64.length > 0)
|| typeof value?.zipFile === 'string'
|| (typeof value?.xlsxBase64 === 'string' && value.xlsxBase64.length > 0)
|| (typeof value === 'string' && value.trim().length > 0); break;
case 'excel': case 'planner': case 'monday': case 'wrike': case 'teamwork': case 'businessmap': valid = typeof value?.excelBase64 === 'string' && value.excelBase64.length > 0; break;
case 'markdown': case 'todotxt': case 'taskwarrior': case 'focalboard': case 'todoist': case 'meistertask': case 'obsidian': case 'linear': case 'ticktick': case 'clickup': case 'nullboard': case 'pivotal': case 'redmine': case 'superproductivity': case 'quire': case 'orgmode': valid = typeof value === 'string' && value.trim().length > 0; break;
case 'leo': valid = typeof value === 'string' && /<leo_file[\s>]/.test(value); break;
// Mail, calendar, chat and note exports (models/lib/mailFormat.js,
// icalendarFormat.js, chatExportFormats.js, enexFormat.js,
// googleTakeoutFormat.js).
case 'mail': valid = (typeof value === 'string' && value.trim().length > 0) || typeof value?.mboxFile === 'string'; break;
case 'whatsapp': valid = typeof value === 'string' && value.trim().length > 0; break;
case 'ical': valid = typeof value === 'string' && /BEGIN:VCALENDAR/i.test(value); break;
case 'mattermost': valid = (typeof value === 'string' && /"type"\s*:\s*"version"/.test(value))
|| (Array.isArray(value?.jsonLines) && value.jsonLines.some(line => line && line.type === 'version')); break;
// Rocket.Chat and Fizzy: an export .zip, or the text of one room's or
// card's .json.
case 'fizzy':
case 'rocketchat': valid = (typeof value?.zipBase64 === 'string' && value.zipBase64.length > 0)
|| typeof value?.zipFile === 'string'
|| (typeof value === 'string' && value.trim().length > 0); break;
case 'evernote': valid = typeof value === 'string' && /<en-export[\s>]/.test(value); break;
case 'telegram': valid = arrayAt(value, 'messages') || arrayAt(value?.chats, 'list'); break;
case 'discord': valid = (Array.isArray(value) ? value : [value]).every(e => e && e.channel && Array.isArray(e.messages)); break;
// A .zip sent in the call, or one streamed to the local disk (zipFile).
case 'slack': case 'googletakeout': valid = (typeof value?.zipBase64 === 'string' && value.zipBase64.length > 0)
|| typeof value?.zipFile === 'string'; break;
case 'opml': valid = typeof value === 'string' && /<opml[\s>]/.test(value); break;
}
if (!valid) throw new Error(`Invalid ${source} import document shape`);
}