'use strict'; /* * TEMPLATE module pack for the MOCK Fusion-style app (NOT Oracle software). Folders starting with "_" are skipped by the loader. * Copy to mock-app/modules// (lower-case id, e.g. "hcm"), rename, fill in. Contract: ../README.md. * Rules: synthetic data only (ZZ- / "(MOCK)" names), no secrets, every business rule marked ASSUMED in a comment. */ const express = require('express'); const R = require('../../core/registry'); const U = require('../../core/ui'); const { AppError } = require('../../core/errors'); const ID = 'xyz'; // pack id = folder name = tests/cases// = automation/src/modules// // ---- state (normally store.js): reset() must restore the full seed; the shell calls it on /api/test/reset. let db; function reset() { db = { things: [{ id: 'T-1', name: 'ZZ Thing (MOCK)', status: 'NEW' }] }; } reset(); const PERSONAS = { xyz_user: { label: 'XYZ User (MOCK)', bus: ['US1'] } }; // keys = persona ids used by the Automation login(); labels must be unique const can = (role) => role === 'xyz_user'; // ---- REST facade (normally rest.js): mounted under the shared Fusion-style REST base; describe() is served by the shell from `schemas`. const fx = express.Router(); fx.get('/xyzThings', U.wrap((req, role) => { if (!can(role)) throw new AppError(403, 'FORBIDDEN', 'Not authorized.'); return { items: db.things, count: db.things.length, hasMore: false }; })); module.exports = { id: ID, name: 'Template module (rename)', idPrefix: 'XYZ', // case-ID prefix: XYZ-- personas: PERSONAS, // Tasks panel links: [label, href, allowed(role)]. Always gate on R.inModule so personas shared with other packs only see what they should. tasks: [['Manage Things', '/xyz/things', (r) => R.inModule(r, ID) && can(r)]], // Scheduled-process parameters (union across packs). Same name in two packs = one field; first pack (alphabetical) wins, // except select options, which are merged. Reuse existing names (ledger, businessUnit, ...) with the same label/default. processParams: [{ name: 'thing', label: 'Thing' }], // Scheduled processes: run(role, params, proc) does the work synchronously; set proc.log; throw AppError for ERROR status. processes: [{ name: 'Process Things (MOCK)', roles: ['xyz_user'], run: (role, p, proc) => { db.things.forEach((t) => { t.status = 'DONE'; }); proc.log = `${db.things.length} thing(s) processed; 0 errors.`; } }], // REST describe() shapes: [attribute, type, mandatory?] (hand-authored, UNVERIFIED). schemas: { xyzThings: [['ThingId', 'string'], ['Name', 'string', true], ['Status', 'string']] }, // Optional: worklist: (role) => [{ docNumber, docType, kind, amount, href }], journals: { roles, batches() }. reset, mount({ app, rest }) { app.use(rest, fx); app.get('/xyz/things', U.page((req, role) => U.layout(req, role, 'Manage Things', U.table('Things', ['Name', 'Status'], db.things.map((t) => U.tr([U.esc(t.name), U.esc(t.status)])))), ID)); }, };