pgkiln 0.31.0 → 0.36.0

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.
Files changed (131) hide show
  1. package/README.md +2 -2
  2. package/SECURITY.md +10 -0
  3. package/db/migrations/076_form_lost_update.sql +50 -0
  4. package/db/migrations/077_warn_unsaved.sql +41 -0
  5. package/db/migrations/078_url_region.sql +12 -0
  6. package/db/migrations/079_developer_toolbar.sql +53 -0
  7. package/db/migrations/080_search.sql +326 -0
  8. package/db/migrations/081_mail.sql +621 -0
  9. package/db/migrations/082_app_backups.sql +73 -0
  10. package/db/migrations/083_availability.sql +156 -0
  11. package/db/migrations/084_feedback.sql +46 -0
  12. package/db/migrations/085_page_behaviour.sql +65 -0
  13. package/db/migrations/086_data_settings.sql +599 -0
  14. package/db/migrations/087_login_page.sql +175 -0
  15. package/db/migrations/088_region_templates.sql +18 -0
  16. package/db/migrations/089_page_groups.sql +330 -0
  17. package/docs/apex-feature-parity.md +61 -39
  18. package/docs/guide/01-installation.md +1 -0
  19. package/docs/guide/03-builder.md +154 -4
  20. package/docs/guide/04-pages-and-regions.md +157 -3
  21. package/docs/guide/05-items.md +47 -0
  22. package/docs/guide/06-processing.md +210 -2
  23. package/docs/guide/07-dynamic-actions.md +60 -2
  24. package/docs/guide/08-security.md +56 -4
  25. package/docs/guide/09-reference.md +21 -0
  26. package/docs/guide/11-from-apex.md +9 -2
  27. package/docs/guide/12-development.md +40 -2
  28. package/docs/guide/14-globalization.md +15 -0
  29. package/docs/guide/15-extensions.md +1 -1
  30. package/docs/guide/17-mobile.md +3 -1
  31. package/docs/guide/18-cli.md +32 -1
  32. package/docs/guide/20-ai-agents.md +5 -2
  33. package/examples/hr/hr_50_search.sql +47 -0
  34. package/examples/hr/hr_51_mail.sql +70 -0
  35. package/examples/hr/hr_52_feedback.sql +15 -0
  36. package/examples/hr/hr_53_data_settings.sql +108 -0
  37. package/examples/hr/hr_54_region_templates.sql +67 -0
  38. package/examples/hr/hr_55_page_groups.sql +24 -0
  39. package/package.json +3 -1
  40. package/public/app.css +122 -3
  41. package/public/app.js +496 -13
  42. package/public/builder.css +22 -0
  43. package/public/builder.js +77 -0
  44. package/public/code-editor.css +3 -3
  45. package/public/sw.js +5 -3
  46. package/src/app.ts +10 -0
  47. package/src/appfiles.ts +13 -0
  48. package/src/automations.ts +12 -0
  49. package/src/builder/advisor.ts +68 -14
  50. package/src/builder/arrange.ts +2 -2
  51. package/src/builder/availability.ts +74 -0
  52. package/src/builder/backups.ts +134 -0
  53. package/src/builder/components.ts +123 -16
  54. package/src/builder/ddl-tools.ts +114 -0
  55. package/src/builder/designer.ts +35 -4
  56. package/src/builder/feedback.ts +82 -0
  57. package/src/builder/forms.ts +10 -5
  58. package/src/builder/home.ts +3 -0
  59. package/src/builder/locks.ts +15 -5
  60. package/src/builder/login-page.ts +82 -0
  61. package/src/builder/mail.ts +425 -0
  62. package/src/builder/newapp.ts +1 -1
  63. package/src/builder/region-help.ts +73 -0
  64. package/src/builder/region-settings.ts +19 -3
  65. package/src/builder/routes.ts +60 -5
  66. package/src/builder/search.ts +4 -4
  67. package/src/builder/shared.ts +3 -2
  68. package/src/builder/sql.ts +3 -0
  69. package/src/builder/ui.ts +9 -3
  70. package/src/cli/apps.ts +46 -5
  71. package/src/cli/main.ts +66 -5
  72. package/src/cli/mcp.ts +58 -4
  73. package/src/cli/replace.ts +40 -4
  74. package/src/ddl.ts +509 -0
  75. package/src/geocode.ts +44 -0
  76. package/src/i18n/ar.ts +56 -0
  77. package/src/i18n/cs.ts +56 -0
  78. package/src/i18n/da.ts +56 -0
  79. package/src/i18n/de.ts +56 -0
  80. package/src/i18n/el.ts +56 -0
  81. package/src/i18n/es.ts +56 -0
  82. package/src/i18n/fi.ts +56 -0
  83. package/src/i18n/fr.ts +56 -0
  84. package/src/i18n/he.ts +56 -0
  85. package/src/i18n/it.ts +56 -0
  86. package/src/i18n/ja.ts +56 -0
  87. package/src/i18n/ko.ts +56 -0
  88. package/src/i18n/nb.ts +56 -0
  89. package/src/i18n/pl.ts +56 -0
  90. package/src/i18n/pt.ts +56 -0
  91. package/src/i18n/ru.ts +56 -0
  92. package/src/i18n/sv.ts +56 -0
  93. package/src/i18n/tr.ts +56 -0
  94. package/src/i18n/uk.ts +56 -0
  95. package/src/i18n/zh.ts +56 -0
  96. package/src/i18n.ts +112 -0
  97. package/src/icons.ts +2 -1
  98. package/src/layout.ts +3 -2
  99. package/src/mail/mail.ts +148 -0
  100. package/src/mail/providers.ts +444 -0
  101. package/src/metadata.ts +34 -10
  102. package/src/runtime/ajax.ts +97 -0
  103. package/src/runtime/authz.ts +1 -1
  104. package/src/runtime/availability.ts +37 -0
  105. package/src/runtime/context.ts +46 -6
  106. package/src/runtime/data-export.ts +94 -0
  107. package/src/runtime/data-items.ts +194 -0
  108. package/src/runtime/devbar.ts +184 -0
  109. package/src/runtime/display-selector.ts +12 -4
  110. package/src/runtime/engine.ts +26 -1
  111. package/src/runtime/feedback.ts +128 -0
  112. package/src/runtime/grid.ts +170 -26
  113. package/src/runtime/items.ts +8 -0
  114. package/src/runtime/lists.ts +11 -1
  115. package/src/runtime/password-reset.ts +171 -0
  116. package/src/runtime/processes.ts +83 -2
  117. package/src/runtime/pwa.ts +7 -10
  118. package/src/runtime/regions.ts +41 -0
  119. package/src/runtime/render.ts +48 -7
  120. package/src/runtime/report-views.ts +4 -2
  121. package/src/runtime/report.ts +36 -22
  122. package/src/runtime/rest.ts +4 -0
  123. package/src/runtime/routes.ts +94 -37
  124. package/src/runtime/search.ts +252 -0
  125. package/src/runtime/signin.ts +80 -0
  126. package/src/runtime/url-region.ts +93 -0
  127. package/src/security.ts +11 -1
  128. package/src/server.ts +2 -0
  129. package/src/session.ts +8 -2
  130. package/src/static-version.ts +34 -0
  131. package/src/workingcopy.ts +2 -2
@@ -19,10 +19,11 @@ export interface Lookups {
19
19
  lists: string[];
20
20
  listEntries: { id: number; list_name: string; label: string }[];
21
21
  automations: string[];
22
+ pageGroups: string[];
22
23
  }
23
24
 
24
25
  export async function lookups(appId: number, pageId?: number): Promise<Lookups> {
25
- const [regions, pages, authz, nav, buildOptions, rest, lists, listEntries, automations] = await Promise.all([
26
+ const [regions, pages, authz, nav, buildOptions, rest, lists, listEntries, automations, pageGroups] = await Promise.all([
26
27
  pageId ? owner.query('select id, title, type from meta.region where page_id = $1 order by seq, id', [pageId]) : Promise.resolve({ rows: [] }),
27
28
  owner.query('select page_no, name from meta.page where app_id = $1 order by page_no', [appId]),
28
29
  owner.query('select name from meta.authz_scheme where app_id = $1 order by name', [appId]),
@@ -32,8 +33,9 @@ export async function lookups(appId: number, pageId?: number): Promise<Lookups>
32
33
  owner.query('select name from meta.list where app_id = $1 order by name', [appId]),
33
34
  owner.query('select id, list_name, label from meta.list_entry where app_id = $1 order by list_name, seq, id', [appId]),
34
35
  owner.query('select name from meta.automation where app_id = $1 order by name', [appId]),
36
+ owner.query('select name from meta.page_group where app_id = $1 order by name', [appId]),
35
37
  ]);
36
- return { regions: regions.rows, pages: pages.rows, authz: authz.rows.map((r) => r.name), nav: nav.rows, buildOptions: buildOptions.rows, restSources: rest.rows.map((r) => r.name), lists: lists.rows.map((r) => r.name), listEntries: listEntries.rows, automations: automations.rows.map((r) => r.name) };
38
+ return { regions: regions.rows, pages: pages.rows, authz: authz.rows.map((r) => r.name), nav: nav.rows, buildOptions: buildOptions.rows, restSources: rest.rows.map((r) => r.name), lists: lists.rows.map((r) => r.name), listEntries: listEntries.rows, automations: automations.rows.map((r) => r.name), pageGroups: pageGroups.rows.map((r) => r.name) };
37
39
  }
38
40
 
39
41
  /** Choices of a build option field: each option and its negation, plus a missing current value. */
@@ -74,14 +76,17 @@ export function iconPicker(id: string, name: string, label: string, current: str
74
76
  export function componentForm(spec: ComponentSpec, kind: string, row: any, lk: Lookups, action: string, s: Session, submit: string, opts: { id?: string } = {}) {
75
77
  const field = (f: Field) => {
76
78
  const v = row?.[f.name];
77
- const help = f.help ? html`<small class="help">${f.help}</small>` : '';
79
+ const own = row?.id ? f.helpBy?.(row) : null;
80
+ const help = own
81
+ ? html`<small class="help">${own.text}${own.url ? html` <a href="${own.url}" target="_blank" rel="noopener">Guide ▸</a>` : ''}</small>`
82
+ : f.help ? html`<small class="help">${f.help}</small>` : '';
78
83
  const id = `f_${kind}_${f.name}`;
79
84
  let control: Raw;
80
85
  const opts = (list: [string, string][]) =>
81
86
  html`<select id="${id}" name="${f.name}">${list.map(([val, label]) => html`<option value="${val}"${String(v ?? '') === val ? raw(' selected') : ''}>${label}</option>`)}</select>`;
82
87
  switch (f.kind) {
83
88
  case 'bool':
84
- return html`<div class="field"><span class="label" aria-hidden="true"></span><label class="check"><input type="checkbox" name="${f.name}" value="true"${v ? raw(' checked') : ''}> ${f.label}</label>${help}</div>`;
89
+ return html`<div class="field" data-prop="${f.name}"><span class="label" aria-hidden="true"></span><label class="check"><input type="checkbox" name="${f.name}" value="true"${v ? raw(' checked') : ''}> ${f.label}</label>${help}</div>`;
85
90
  case 'options': {
86
91
  const chosen: unknown[] = Array.isArray(v) ? v : [];
87
92
  return html`<fieldset class="field options-field"${f.wide ? raw(' data-wide') : ''}><legend class="label">${f.label}</legend>
@@ -156,7 +161,7 @@ export function componentForm(spec: ComponentSpec, kind: string, row: any, lk: L
156
161
  default:
157
162
  control = html`<input id="${id}" name="${f.name}" type="${f.kind === 'int' ? 'number' : 'text'}" value="${v ?? ''}">`;
158
163
  }
159
- return html`<div class="field"${f.wide ? raw(' data-wide') : ''}><label class="label" for="${id}">${f.label}</label>${control}${help}</div>`;
164
+ return html`<div class="field" data-prop="${f.name}"${f.wide ? raw(' data-wide') : ''}><label class="label" for="${id}">${f.label}</label>${control}${help}</div>`;
160
165
  };
161
166
  const groups = [...new Set(spec.fields.map((f) => f.group ?? ''))];
162
167
  return html`<form method="post" action="${action}" class="component-form"${opts.id ? html` id="${opts.id}"` : ''}>
@@ -219,6 +219,8 @@ export async function homeRoutes(app: FastifyInstance) {
219
219
  ${region('Export file', html`<form method="post" action="${BASE}/import">${csrf(s)}
220
220
  <div class="field" data-wide><label class="label" for="f_doc">Export JSON</label><textarea id="f_doc" name="doc" class="code" rows="14" required data-code="json"></textarea></div>
221
221
  ${input('alias', 'New alias (optional)', '', { help: 'Leave empty to keep the alias in the export.' })}
222
+ <div class="field"><label class="check"><input type="checkbox" name="check" value="true" checked> Check the application before importing</label>
223
+ <small class="help">The Advisor plans its SQL as the application's database role and checks its references before anything is saved: errors (a missing table, column or function, a wrong type, a missing grant) refuse the import.</small></div>
222
224
  <div class="buttons"><a class="btn" href="${BASE}">Cancel</a><button class="btn btn-hot">Import</button></div>
223
225
  </form>`)}
224
226
  </div>`;
@@ -285,6 +287,7 @@ export async function homeRoutes(app: FastifyInstance) {
285
287
  ${(await isAdmin(s.username)) ? card(`${BASE}/instance`, icon('settings'), 'Instance settings', 'Session length, sign-in throttling and the server\'s configuration (administrators).') : ''}
286
288
  ${(await isAdmin(s.username)) ? card(`${BASE}/workspaces`, icon('layers'), 'Workspaces', 'Groups of applications and their developers (administrators).') : ''}
287
289
  ${(await isAdmin(s.username)) ? card(`${BASE}/ai`, icon('bolt'), 'AI services', 'Claude and OpenAI for the applications: models, keys, limits and usage (administrators).') : ''}
290
+ ${(await isAdmin(s.username)) ? card(`${BASE}/mail`, icon('send'), 'Mail services', 'SMTP, Microsoft 365, Amazon SES, Resend, Postmark, SendGrid or Mailgun for the applications\' e-mail (administrators).') : ''}
288
291
  ${(await isAdmin(s.username)) ? card(`${BASE}/installation`, icon('history'), 'Installation', 'Version, install and upgrade runs, applied migrations (administrators).') : ''}
289
292
  </div>`;
290
293
  return send(reply, s, shell(s, 'Workspace utilities', [['App Builder', BASE], ['Workspace utilities']], main));
@@ -21,6 +21,8 @@ export interface Lock {
21
21
  locked_by: string;
22
22
  locked_at: string;
23
23
  note: string | null;
24
+ /** (083) not a developer's lock: the application's build status is Run only */
25
+ run_only?: boolean;
24
26
  }
25
27
 
26
28
  export const isAdmin = async (username: string | null | undefined) =>
@@ -31,7 +33,10 @@ export const appLocks = async (appId: number) =>
31
33
  (await owner.query<Lock>('select app_id, page_no, locked_by, locked_at::text, note from meta.builder_lock where app_id = $1 order by page_no', [appId])).rows;
32
34
 
33
35
  /** Builder POSTs that are allowed on a locked page or application (locking, unlocking, comments). */
34
- const EXEMPT = /^\/apps\/\d+\/(lock|unlock|comments(\/\d+\/delete)?)$/;
36
+ const EXEMPT = /^\/apps\/\d+\/(lock|unlock|comments(\/\d+\/delete)?|feedback\/\d+)$/;
37
+ /** (083) Builder POSTs allowed on a Run only application: its availability and build status, a backup, locks and comments. */
38
+ // (086) an existing application setting stays editable: settings are what an administrator changes after deployment
39
+ const RUN_ONLY_EXEMPT = /^\/apps\/\d+\/(availability|backups|backups\/settings|lock|unlock|comments(\/\d+\/delete)?|feedback\/\d+|shared\/app_setting\/\d+)$/;
35
40
 
36
41
  /** The application (and page) a builder URL under /apps/:id or /pages/:pid is about, or null. */
37
42
  export async function appOfPath(path: string): Promise<{ appId: number; pageNo: number | null; pageId: number | null } | null> {
@@ -50,10 +55,13 @@ export async function appOfPath(path: string): Promise<{ appId: number; pageNo:
50
55
  */
51
56
  export async function blockingLock(username: string, path: string): Promise<{ lock: Lock; appId: number; pageId: number | null } | null> {
52
57
  const rel = path.split('?')[0].slice(BASE.length);
53
- if (EXEMPT.test(rel)) return null;
54
58
  const target = await appOfPath(path);
55
59
  if (!target) return null;
56
60
  const { appId, pageNo, pageId } = target;
61
+ // (083) a Run only application refuses changes, whoever asks
62
+ if (!RUN_ONLY_EXEMPT.test(rel) && (await owner.one<{ ok: boolean }>(`select build_status = 'run_only' as ok from meta.app where id = $1`, [appId]))?.ok)
63
+ return { lock: { app_id: appId, page_no: 0, locked_by: '', locked_at: '', note: null, run_only: true }, appId, pageId };
64
+ if (EXEMPT.test(rel)) return null;
57
65
  const lock = await owner.one<Lock>(
58
66
  `select app_id, page_no, locked_by, locked_at::text, note from meta.builder_lock
59
67
  where app_id = $1 and (page_no = 0 or page_no = $2) and locked_by <> $3 order by page_no limit 1`,
@@ -62,12 +70,14 @@ export async function blockingLock(username: string, path: string): Promise<{ lo
62
70
  return lock ? { lock, appId, pageId } : null;
63
71
  }
64
72
 
65
- export const lockText = (l: Pick<Lock, 'page_no' | 'locked_by' | 'locked_at' | 'note'>) =>
66
- `${l.page_no ? `Page ${l.page_no}` : 'The application'} is locked by ${l.locked_by} since ${l.locked_at.slice(0, 16)}${l.note ? ` (${l.note})` : ''}.`;
73
+ export const lockText = (l: Pick<Lock, 'page_no' | 'locked_by' | 'locked_at' | 'note' | 'run_only'>) =>
74
+ l.run_only
75
+ ? 'The application is Run only (Availability → Build status).'
76
+ : `${l.page_no ? `Page ${l.page_no}` : 'The application'} is locked by ${l.locked_by} since ${l.locked_at.slice(0, 16)}${l.note ? ` (${l.note})` : ''}.`;
67
77
 
68
78
  /** Refuse a change to a locked page or application: a JSON error or a message on the page it came from. */
69
79
  export async function refuseLocked(req: Req, reply: FastifyReply, s: Session, hit: NonNullable<Awaited<ReturnType<typeof blockingLock>>>) {
70
- const message = `${lockText(hit.lock)} Changes are refused until it is unlocked.`;
80
+ const message = hit.lock.run_only ? `${lockText(hit.lock)} Set it back to Run and build to change it.` : `${lockText(hit.lock)} Changes are refused until it is unlocked.`;
71
81
  if (String(req.headers.accept ?? '').includes('application/json')) return reply.code(423).send({ ok: false, error: message });
72
82
  flash(s, message, 'error');
73
83
  return back(reply, s, hit.pageId ? `${BASE}/pages/${hit.pageId}` : `${BASE}/apps/${hit.appId}`);
@@ -0,0 +1,82 @@
1
+ import type { FastifyInstance } from 'fastify';
2
+ import { owner } from '../db.ts';
3
+ import { html, raw } from '../html.ts';
4
+ import { back, BASE, developer, flash, type Req } from './ui.ts';
5
+
6
+ // Application settings → Sign-in methods (migration 087): the application's
7
+ // own login page (APEX: the login page, usually 9999) and "Forgot password?".
8
+ // "Create login page" adds a minimal public page with a login region and
9
+ // makes it the login page.
10
+
11
+ interface AppRow {
12
+ id: number;
13
+ name: string;
14
+ authentication: string;
15
+ local_login: boolean;
16
+ login_page: number | null;
17
+ password_reset: boolean;
18
+ }
19
+
20
+ /** The fields in the settings form. */
21
+ export async function loginSettingsFields(a: AppRow) {
22
+ const pages = (await owner.query<{ page_no: number; name: string; requires_auth: boolean }>(
23
+ 'select page_no, name, requires_auth from meta.page where app_id = $1 order by page_no', [a.id],
24
+ )).rows;
25
+ const mail = await owner.one<{ service: string | null; enabled: boolean | null; from_address: string | null }>(
26
+ `select s.name as service, s.enabled, ams.from_address
27
+ from meta.app_mail_service ams join meta.mail_service s on s.id = ams.service_id where ams.app_id = $1`, [a.id],
28
+ );
29
+ const mailOk = !!(mail?.enabled && mail.from_address?.trim());
30
+ const opt = (v: string, label: string, cur: string) => html`<option value="${v}"${v === cur ? raw(' selected') : ''}>${label}</option>`;
31
+ const current = a.login_page ? String(a.login_page) : '';
32
+ return html`<div class="form-grid">
33
+ <div class="field"><label class="label" for="f_login_page">Login page</label>
34
+ <select id="f_login_page" name="login_page">${opt('', '- the built-in sign-in page -', current)}${pages.map((p) =>
35
+ opt(String(p.page_no), `${p.page_no} ${p.name}${p.requires_auth ? ' (requires sign-in: not usable)' : ''}`, current))}</select>
36
+ <small class="help">A page of the application with a <em>Login</em> region replaces the built-in sign-in page (APEX: the login page). It must not require authentication; with page template <em>Minimal</em> it has no header and navigation.
37
+ <button class="link-button" formaction="${BASE}/apps/${a.id}/login-page">Create a login page</button></small></div>
38
+ <div class="field"><span class="label" aria-hidden="true"></span><label class="check"><input type="checkbox" name="password_reset" value="true"${a.password_reset ? raw(' checked') : ''}> Offer "Forgot password?"</label>
39
+ <small class="help">Users with a password and an e-mail address in the user directory get a link to choose a new password (single-use, valid for 30 minutes).
40
+ ${mailOk
41
+ ? html`Sent through mail service ${mail!.service} as ${mail!.from_address}.`
42
+ : html`<strong>Not offered yet:</strong> the application needs an enabled mail service with a From address (Workspace utilities → Mail services).`}
43
+ Only for the user directory's own passwords: not for LDAP, single sign-on, database accounts or custom authentication.</small></div>
44
+ </div>`;
45
+ }
46
+
47
+ /** Save them (with the rest of the settings form). */
48
+ export async function saveLoginSettings(appId: string, b: Record<string, string | undefined>) {
49
+ const page = b.login_page?.trim() ? Number(b.login_page) : null;
50
+ if (page !== null && !(await owner.one('select 1 from meta.page where app_id = $1 and page_no = $2', [appId, page]))) throw new Error(`Login page: there is no page ${b.login_page}.`);
51
+ await owner.query('update meta.app set login_page = $2, password_reset = $3 where id = $1', [appId, page, b.password_reset === 'true']);
52
+ }
53
+
54
+ export async function loginPageRoutes(app: FastifyInstance) {
55
+ // Create a login page: page 9999 (or the next free number), public, minimal, with a login region
56
+ app.post(`${BASE}/apps/:id/login-page`, async (req: Req, reply) => {
57
+ const s = await developer(req, reply);
58
+ if (!s) return;
59
+ const a = await owner.one<{ id: number; name: string }>('select id, name from meta.app where id = $1', [req.params.id]);
60
+ if (!a) return reply.code(404).send('Not found');
61
+ try {
62
+ const { page, no } = await owner.tx(async (c) => {
63
+ const n = (await c.query<{ n: number }>(
64
+ `select case when not exists (select 1 from meta.page where app_id = $1 and page_no = 9999) then 9999
65
+ else (select max(page_no) + 1 from meta.page where app_id = $1) end as n`, [a.id],
66
+ )).rows[0].n;
67
+ const id = (await c.query<{ id: number }>(
68
+ `insert into meta.page (app_id, page_no, name, title, requires_auth, page_template) values ($1, $2, 'Login', $3, false, 'minimal') returning id`,
69
+ [a.id, n, a.name],
70
+ )).rows[0].id;
71
+ await c.query(`insert into meta.region (page_id, seq, title, type, template) values ($1, 10, $2, 'login', 'standard')`, [id, a.name]);
72
+ await c.query('update meta.app set login_page = $2, updated_at = now() where id = $1', [a.id, n]);
73
+ return { page: id, no: n };
74
+ });
75
+ flash(s, `Page ${no} "Login" created and made the login page. Add regions around the sign-in form in the Page Designer.`);
76
+ return back(reply, s, `${BASE}/pages/${page}`);
77
+ } catch (e) {
78
+ flash(s, (e as Error).message, 'error');
79
+ return back(reply, s, `${BASE}/apps/${req.params.id}/settings`);
80
+ }
81
+ });
82
+ }