const { WebAclMiddleware, CacherMiddleware } = require('@semapps/webacl'); const CONFIG = require('./config/config'); Error.stackTraceLimit = Infinity; const cacherConfig = CONFIG.REDIS_CACHE_URL ? { type: 'Redis', options: { prefix: 'action', ttl: 2592000, redis: CONFIG.REDIS_CACHE_URL } } : undefined; const SkipOrphanBlankNodesCleanupMiddleware = () => ({ name: 'SkipOrphanBlankNodesCleanupMiddleware', localAction: (next, action) => { if (action.name === 'triplestore.deleteOrphanBlankNodes') { return async () => {}; } return next; } }); // ActivityPods app services mark internal calls with isSystemCall, but the SDK // triplestore layer needs an explicit webId='system' to bypass pod-side WAC. const SystemCallWebIdMiddleware = () => ({ name: 'SystemCallWebIdMiddleware', localAction: (next, action) => { return async ctx => { if (ctx.meta?.isSystemCall && !ctx.params?.webId) { ctx.params.webId = 'system'; } return next(ctx); }; } }); module.exports = { middlewares: [ SkipOrphanBlankNodesCleanupMiddleware(), SystemCallWebIdMiddleware(), // As in the reference apps: the cacher before the WebACL middleware, which checks the read // rights of every `ldp.resource.get` and gives each resource created in the main dataset the // rights its container prescribes (the app actor and its public key readable by anyone, say). CacherMiddleware(cacherConfig), WebAclMiddleware({ baseUrl: CONFIG.HOME_URL }) ], logger: { type: 'Console', options: { formatter: 'short', level: 'info' } }, retryPolicy: { enabled: true, retries: 0, delay: 100, maxDelay: 30000, factor: 2, check: err => err && !!err.retryable } };