@xeplr/cli 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -2
- package/lib/generate/index.js +3 -1
- package/lib/plan.js +1 -0
- package/lib/questions.js +2 -1
- package/package.json +1 -1
- package/templates/README.md +3 -1
- package/templates/api/README.md +2 -1
- package/templates/api/development.env.tpl +1 -0
- package/templates/api/env.required.js +4 -0
- package/templates/api/package.json +3 -1
- package/templates/api/production.env.example +1 -0
- package/templates/api/workflow.js +26 -2
package/README.md
CHANGED
|
@@ -47,7 +47,9 @@ Already working, with nothing to wire up:
|
|
|
47
47
|
screen, a function that decides, or the end. Walked at `/journey/<key>`, and
|
|
48
48
|
resumable. Run by `@xeplr/workflow-api` **inside the API**, in a database of
|
|
49
49
|
its own (`<name>_workflow`, created on first start) — nothing extra to start.
|
|
50
|
-
|
|
50
|
+
Its clock is `@xeplr/jobs`, started with it in a database of its own
|
|
51
|
+
(`<name>_jobs`): schedules and timed work (a Wait box running out, a
|
|
52
|
+
reminder) run as jobs. It follows the app's tenancy (none, or the levels you chose) and never creates
|
|
51
53
|
companies or workspaces of its own. Approvals (another person's turn) are not
|
|
52
54
|
part of it.
|
|
53
55
|
- **A phone app** — `mobile/` (Expo): the same app drawn natively on Android and iOS — every form added to the menu, its list, add / edit, its buttons and the journeys — with no screen code of its own: it draws what the server holds (`@xeplr/ui-factory/native`, `@xeplr/ui-account/native`). Try it with Expo Go, build an APK with `npm run build:apk`. An app whose data is split by company asks for the company first, on the phone as on the web.
|
|
@@ -252,7 +254,12 @@ an app keeps its tables apart, and creates the database on first start), with
|
|
|
252
254
|
`tenantTables: false` so it follows the app's tenancy rather than creating
|
|
253
255
|
`companies` / `workspaces`, and `access: true` so each flows route checks the
|
|
254
256
|
caller's permissions, which its `migrations-auth` grants (loaded through
|
|
255
|
-
`XEPLR_AUTH_MIGRATIONS`).
|
|
257
|
+
`XEPLR_AUTH_MIGRATIONS`). Its clock is `@xeplr/jobs` (`api/workflow.js`): the
|
|
258
|
+
engine runs no timer, so `workflow.js` registers the engine's `jobActions`,
|
|
259
|
+
starts jobs in their own database (`DB_JOBS`, `<name>_jobs`, from jobs'
|
|
260
|
+
`requiredEnv`, `init({ migrate: true })`), passes `keepSchedule` and `startJob`
|
|
261
|
+
to `registerWorkflow`, and starts the jobs scheduler. The app has no jobs
|
|
262
|
+
screens; the jobs only run. The designer is `@xeplr/ui-factory`'s
|
|
256
263
|
`FlowDesignerPage`; the paid canvas designer (X-Flow) is not part of a
|
|
257
264
|
generated app.
|
|
258
265
|
|
package/lib/generate/index.js
CHANGED
|
@@ -32,6 +32,7 @@ function substitutions(answers) {
|
|
|
32
32
|
__DB_API__: answers.databases.api,
|
|
33
33
|
__DB_AUTH__: answers.databases.auth,
|
|
34
34
|
__DB_WORKFLOW__: answers.databases.workflow,
|
|
35
|
+
__DB_JOBS__: answers.databases.jobs,
|
|
35
36
|
__PREFIX__: answers.prefix,
|
|
36
37
|
__UI_PORT__: String(answers.ports.ui),
|
|
37
38
|
__AUTH_PORT__: String(answers.ports.auth),
|
|
@@ -55,7 +56,7 @@ function flowsSubstitutions(answers) {
|
|
|
55
56
|
return {
|
|
56
57
|
__WF_README__: flowsReadme(answers),
|
|
57
58
|
__WF_CLAUDE__: [
|
|
58
|
-
'**Flows** — forms one after another, run by `@xeplr/workflow-api` INSIDE this API (bin/www starts it, workflow.js) in a database of its own (`DB_WORKFLOW`). Design them in Configure UI → Flows, never in code: a flow is data, reached through `/api/workflow/flows`, and walked at `/journey/<key>`. After a step, a flow goes to a screen, lets one of the app\'s `decide` functions choose, or finishes. Workflow follows this app\'s tenancy — it never creates companies or workspaces of its own.',
|
|
59
|
+
'**Flows** — forms one after another, run by `@xeplr/workflow-api` INSIDE this API (bin/www starts it, workflow.js) in a database of its own (`DB_WORKFLOW`). Design them in Configure UI → Flows, never in code: a flow is data, reached through `/api/workflow/flows`, and walked at `/journey/<key>`. After a step, a flow goes to a screen, lets one of the app\'s `decide` functions choose, or finishes. Workflow follows this app\'s tenancy — it never creates companies or workspaces of its own. Its clock is `@xeplr/jobs`, started in the same place, in a database of its own (`DB_JOBS`): a flow\'s timed work — a Wait box running out, a reminder, a scheduled start — is a job; never add a timer of your own.',
|
|
59
60
|
'',
|
|
60
61
|
'**Functions** — the code around a form\'s records lives in `api/functions/`, registered with `@xeplr/actions` under the event it is for, and is picked BY NAME: the screen\'s own events (`beforeLoad`, `beforeSave`, `afterSave`, `beforeDelete`, `onError`) in its `events` or the form designer\'s **Server rules** (nothing selected); a flow step\'s `decide`; and its controls\' — `button` (a button\'s `action`), `buttonOptions` (a popup checklist\'s `optionsFrom`), `listRows` (a list\'s `rowsFrom`), `rowDetails` (a column\'s `details`), `recordDetails` (`detailsFrom`), `feedEntries` (`entriesFrom`), `suggest` (`suggestFrom`). There are no SERVER hook files — the browser\'s front-end hooks are the page\'s (`Edit<Form>.jsx`). A screen naming a function nobody registered is refused at publish. The full table, with what each gets and returns and where the designer picks it, is in `BUILDING.md`.',
|
|
61
62
|
''
|
|
@@ -182,6 +183,7 @@ function flowsReadme(answers) {
|
|
|
182
183
|
? 'this app\'s — flows and runs belong to the ' + tenancy.map(function (l) { return l.label.toLowerCase(); }).join(' and ') + ' chosen after signing in, checked by the same membership gate as everything else.'
|
|
183
184
|
: 'none, like the rest of this app — flows belong to the whole app.') + ' Workflow never creates companies or workspaces of its own. |',
|
|
184
185
|
'| **Permissions** | each route checks the caller\'s (`List flows`, `Start flow run`, `Publish flow`…), granted by `@xeplr/workflow-api`\'s `migrations-auth`, which `XEPLR_AUTH_MIGRATIONS` loads. |',
|
|
186
|
+
'| **Its clock** | `@xeplr/jobs`, started with it, in a database of its own, `DB_JOBS` (`' + answers.databases.jobs + '`), created and migrated on first start. Workflow runs no timer: a flow on a schedule is a job, and everything that falls due with time — a Wait box running out, a reminder or an escalation, a run whose process died — is one system job, every minute. There are no jobs screens in this app; the jobs only run. |',
|
|
185
187
|
'',
|
|
186
188
|
'## Functions — your code, picked by name',
|
|
187
189
|
'',
|
package/lib/plan.js
CHANGED
|
@@ -19,6 +19,7 @@ function describe(answers) {
|
|
|
19
19
|
L.push(' ' + answers.databases.auth + ' accounts, roles, permissions');
|
|
20
20
|
L.push(' ' + answers.databases.api + ' your own data');
|
|
21
21
|
L.push(' ' + answers.databases.workflow + ' flows and their runs');
|
|
22
|
+
L.push(' ' + answers.databases.jobs + ' flows\' schedules and timed work');
|
|
22
23
|
L.push('');
|
|
23
24
|
L.push(' You will sign in as ' + answers.admin.email + '.');
|
|
24
25
|
L.push('');
|
package/lib/questions.js
CHANGED
|
@@ -32,7 +32,8 @@ function databaseNames(name) {
|
|
|
32
32
|
var base = name.replace(/-/g, '_');
|
|
33
33
|
// Workflow gets a database of its own: a sub-product embedded in an app is
|
|
34
34
|
// given its own store, never a share of the app's (see the API's workflow.js).
|
|
35
|
-
|
|
35
|
+
// So do the jobs that are its clock: its schedules and its due work.
|
|
36
|
+
return { auth: base + '_auth', api: base + '_api', workflow: base + '_workflow', jobs: base + '_jobs' };
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
// ── tenancy ──────────────────────────────────────────────────────────────
|
package/package.json
CHANGED
package/templates/README.md
CHANGED
|
@@ -24,7 +24,9 @@ cd ui && npm run dev # the app http://localhost:__UI_PORT_
|
|
|
24
24
|
Open http://localhost:__UI_PORT__ and sign in as `__ADMIN_EMAIL__`.
|
|
25
25
|
|
|
26
26
|
Flows (`@xeplr/workflow-api`) run **inside the API**, in a database of their
|
|
27
|
-
own that the API creates on first start — nothing else to start.
|
|
27
|
+
own that the API creates on first start — nothing else to start. Their clock,
|
|
28
|
+
`@xeplr/jobs` (schedules, Wait boxes running out, reminders), starts with them,
|
|
29
|
+
in a database of its own (`DB_JOBS`), also created on first start.
|
|
28
30
|
|
|
29
31
|
## Where each address goes
|
|
30
32
|
|
package/templates/api/README.md
CHANGED
|
@@ -26,7 +26,7 @@ The API (`@xeplr/base-apis`) and the sign-in service (`@xeplr/auth`), with this
|
|
|
26
26
|
| `routes/access.js` | who may design and publish forms (Super Admin) |
|
|
27
27
|
| `screens/` | the forms this app ships with: per form, its spec, list and edit screens, server functions and model — registered in `screens/index.js` |
|
|
28
28
|
| `functions/` | this app's functions — the code screens' events and flows' `decide` pick by name — registered with `@xeplr/actions` by event, loaded at startup |
|
|
29
|
-
| `workflow.js` | flows: `@xeplr/workflow-api` started inside this API, in its own database (`DB_WORKFLOW`) |
|
|
29
|
+
| `workflow.js` | flows: `@xeplr/workflow-api` started inside this API, in its own database (`DB_WORKFLOW`), with its clock — `@xeplr/jobs`' scheduler, in a database of its own (`DB_JOBS`): a flow's schedules and timed work run as jobs, never on a timer of the app's own |
|
|
30
30
|
| `data/` | `XEPLR_DATA_DIR` in development: every file the app keeps, a folder per company — what people attach through a form's **file** field is in `<company>/screens/`. Never committed, and never served: a file comes back only through the API's own route, which checks the caller the way reading a record does |
|
|
31
31
|
| `migrations/` | hand-written SQL for tables no form owns |
|
|
32
32
|
| `migrations-auth/` | this app's rows in the sign-in database — menus (by key), permissions |
|
|
@@ -40,6 +40,7 @@ The API (`@xeplr/base-apis`) and the sign-in service (`@xeplr/auth`), with this
|
|
|
40
40
|
| `XEPLR_DATA_DIR` | **required, absolute, existing**: where every file the app keeps lives, a folder per company (`<root>/__NAME__/<company>/…`). Generated as `api/data`; on a server, somewhere backed up |
|
|
41
41
|
| `__PREFIX___CONNECTION`, `AUTH_DB_CONNECTION_INFO_ENCRYPTED` | the database, encrypted — `npm run db:encrypt` |
|
|
42
42
|
| `DB_API`, `AUTH_DB_NAME` | the two database names — never guessed |
|
|
43
|
+
| `DB_WORKFLOW`, `DB_JOBS` | flows' database, and the jobs that are their clock — named by `@xeplr/workflow-api` and `@xeplr/jobs`, created and migrated on first start, never guessed |
|
|
43
44
|
| `AUTH_SUPER_ADMIN_EMAIL` / `_PASSWORD` | the first account — created once, when the sign-in database is first set up |
|
|
44
45
|
| `AUTH_TENANT_HEADER` | `none`: one set of roles for everyone. A multi-tenant app names its company header (e.g. `x-company-id`), so a role made inside a company belongs to it |
|
|
45
46
|
| `AUTH_ACTIVATION_URL`, `AUTH_INVITE_URL`, `AUTH_RESET_URL` | the UI pages the emailed links open; the token is appended. The reset address is never taken from the request |
|
|
@@ -36,4 +36,8 @@ module.exports = [
|
|
|
36
36
|
// Flows' own database (DB_WORKFLOW) — workflow is embedded in this API but
|
|
37
37
|
// keeps its tables apart from yours. The library names it.
|
|
38
38
|
...require('@xeplr/workflow-api').embedRequiredEnv,
|
|
39
|
+
|
|
40
|
+
// Flows' clock (DB_JOBS): a flow's schedules and timed work run as jobs of
|
|
41
|
+
// @xeplr/jobs, in a database of their own. The library names it.
|
|
42
|
+
...require('@xeplr/jobs').requiredEnv,
|
|
39
43
|
];
|
|
@@ -28,7 +28,9 @@
|
|
|
28
28
|
"multer": "^2.0.2",
|
|
29
29
|
"nodemailer": "^10.0.2",
|
|
30
30
|
"@xeplr/actions": "^2.2.1",
|
|
31
|
-
"@xeplr/workflow-api": "^
|
|
31
|
+
"@xeplr/workflow-api": "^3.0.0",
|
|
32
|
+
"@xeplr/workflow-engine": "^5.0.0",
|
|
33
|
+
"@xeplr/jobs": "^3.1.0"
|
|
32
34
|
},
|
|
33
35
|
"devDependencies": {
|
|
34
36
|
"dotenv-cli": "^8.0.0",
|
|
@@ -4,6 +4,11 @@
|
|
|
4
4
|
// sub-product embedded in an app gets a store of its own.
|
|
5
5
|
// Created and migrated on first start, with the same
|
|
6
6
|
// server login as the app (__PREFIX___CONNECTION).
|
|
7
|
+
// ITS CLOCK @xeplr/jobs, in a database of its own (DB_JOBS), also
|
|
8
|
+
// created and migrated on first start. Workflow runs no
|
|
9
|
+
// timer: a flow on a schedule is a job, and its timed work
|
|
10
|
+
// — a Wait box running out, a reminder, a run whose
|
|
11
|
+
// process died — is one system job, every minute.
|
|
7
12
|
// THIS APP'S it registers no tenancy of its own: flows and runs are
|
|
8
13
|
// TENANCY filtered by the levels this app registered (or none),
|
|
9
14
|
// behind this app's membership gate.
|
|
@@ -14,9 +19,24 @@
|
|
|
14
19
|
// A flow's "let a function decide" picks one of this app's functions
|
|
15
20
|
// (functions/), the same registry the screens' events use.
|
|
16
21
|
var { registerWorkflow } = require('@xeplr/workflow-api');
|
|
22
|
+
var engine = require('@xeplr/workflow-engine');
|
|
23
|
+
var jobs = require('@xeplr/jobs');
|
|
17
24
|
|
|
18
|
-
/** Creates and migrates workflow's
|
|
25
|
+
/** Creates and migrates workflow's and its jobs' databases, starts the clock, and returns the router — already gated. */
|
|
19
26
|
module.exports = async function startWorkflow(memberGate) {
|
|
27
|
+
// What a job runs to start a scheduled flow, and to do the due work.
|
|
28
|
+
engine.jobActions.forEach(function (a) { jobs.registerAction(a); });
|
|
29
|
+
await jobs.init({
|
|
30
|
+
database: process.env.DB_JOBS,
|
|
31
|
+
connection: process.env.__PREFIX___CONNECTION,
|
|
32
|
+
connectionName: 'jobs',
|
|
33
|
+
migrate: true,
|
|
34
|
+
// Only what workflow needs: no other actions offered to a job.
|
|
35
|
+
defaultActions: false,
|
|
36
|
+
// A finished job resumes the step that started it.
|
|
37
|
+
onFinish: function (report) { return engine.jobFinished(report); }
|
|
38
|
+
});
|
|
39
|
+
|
|
20
40
|
var workflow = await registerWorkflow({
|
|
21
41
|
applicationId: '__NAME__',
|
|
22
42
|
db: {
|
|
@@ -26,7 +46,11 @@ module.exports = async function startWorkflow(memberGate) {
|
|
|
26
46
|
},
|
|
27
47
|
tenantTables: false,
|
|
28
48
|
access: true,
|
|
29
|
-
mtMembershipGate: memberGate
|
|
49
|
+
mtMembershipGate: memberGate,
|
|
50
|
+
startJob: function (jobId, body) { return jobs.trigger(jobId, body, { triggerType: 'workflow' }); },
|
|
51
|
+
keepSchedule: jobs.keepSchedule
|
|
30
52
|
});
|
|
53
|
+
|
|
54
|
+
jobs.startScheduler();
|
|
31
55
|
return workflow.router;
|
|
32
56
|
};
|