Files
apxtri/dataprocess
phil c291a7982a Purge town-tribe schemas + move dataprocess to core (phases 1-2)
Phase 1 — town schemas → core:
- persons.json: reintegrate imgbase64_imgavatar + myapps (with $town refs)
- remove redundant wwws.json + stale persons.json town overrides
- move options.json to apxtri/schema (removed from skeleton)

Phase 2 — dataprocess → core:
- move eventscripts.js to apxtri/dataprocess (core default, README added)
- Events.js: per-instance override ({TOWN}/dataprocess) then core fallback
- remove dataprocess + options.json from skeleton
2026-08-14 05:31:39 +00:00
..

apxtri/dataprocess — Event / maintenance scripts

This directory hosts the core whitelisted scripts that run inside the apxtri process. Tribes trigger them through events (POST /api/apxtri/events/run) or they can be used for periodic cleanup/maintenance actions.

Location & resolution

Path Role
{NODEPATH}/apxtri/dataprocess/eventscripts.js Core default (this directory, versioned in the apxtri repository)
{NODEPATH}/{TOWN}/dataprocess/eventscripts.js Optional per-instance override (checked first by the events runner)

The events runner (models/Events.js, runEvent) loads the instance override when it exists, otherwise falls back to the core module. Keep the core module generic and safe.

Writing a script

Every script is a CommonJS module exporting named functions. Each function:

  • receives (params, ctx) where
    • params — the JSON parameters stored on the event (validated inside the function),
    • ctx — { tribe, event, alias } (tribe id, the event item, the requesting alias);
  • returns an object (serialized back to the caller);
  • must validate its own params before doing anything.

Example:

module.exports = {
  cleanOldRecords: function (params, ctx) {
    if (!params || typeof params.olderThanDays !== 'number') {
      throw new Error('invalid params: "olderThanDays" (number) is required');
    }
    // ... do the cleanup ...
    return { ok: true, removed: 0, tribe: ctx.tribe };
  },
};

Security

  • Only functions exported by the resolved eventscripts.js are callable from the events API.
  • Functions run in-process — keep them fast and side-effect-free unless intended.
  • Never execute arbitrary shell commands from a script.
  • Do not commit secrets or per-instance data in the core module.